all files / editor-manager/plugin/ ms-word-clean-up.js

93.87% Statements 674/718
88.94% Branches 402/452
100% Functions 42/42
93.87% Lines 674/718
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106   1892×                 1892×               1892×             1892×         1892× 1892×   1892×   1892×   1892× 1892× 1892× 1892× 1892×   1892× 1892×   1747× 1747×   163× 163× 163× 163× 163× 163× 163× 163× 163× 163× 163× 163× 163× 163×   68× 68× 68× 68×   43×   68× 68× 68× 68× 68× 68× 68× 68× 68× 68× 68× 68×   68×     95×   95×     163× 163×         136× 136×                 68× 68× 5844×       109×                 73× 73× 73× 40×                   40×   73× 73× 73× 73× 73× 73× 20× 40× 40×   20× 20×                         20× 20× 38×     35×     30× 30×   35×     38×   20× 20× 32×       73× 73× 5540×               80271× 80271× 80271× 80271×     80271× 80271× 80271× 80271× 80271× 321084× 321078×             240807×     20× 20× 20× 20× 20× 20× 20× 10×     10× 10× 10× 10× 10× 10× 10× 10× 10×                                               20×   25× 25× 25×   68× 68× 1555×     69× 69× 3995×         123× 123× 123×   123×             264× 264×     141×     123×   264×   361× 361× 50×   361× 361× 1083× 1083× 1083× 1083× 1083×   361× 361×   765× 765× 756×   756×       61×     695×         765×   73× 73× 571×   569×   71×   68× 68× 874×   61×   874× 874×     874×     704× 704× 695×         68× 68× 68× 50× 49×     50× 50× 50× 50× 1452×   50× 50× 50× 50× 50× 50× 1452× 72× 72×   1380× 688×   692× 94×     598×   764× 1332× 30×   1302× 1302× 835× 835× 4826×         835× 834× 4824× 4824× 1753× 1753×       835× 835×     467× 467×     764×   50× 50× 150× 66× 66× 46× 46× 17× 17× 136× 34×     14× 14× 14×                     50× 50× 3068× 3068× 3068× 11792× 5267×     3068×     50× 1452× 1452× 1452× 15872× 3983×       50×   50× 50× 1239× 1239× 1239× 1239× 1239× 1239× 1239× 1239× 1541×     50×   361× 361× 361×   68× 68× 68× 68× 5844×   1228× 1228×   4616×       296×     296×   4616×       91×   4616× 1893×     296×     1597×       68× 25×   68×   43× 43× 43× 43× 43× 43× 43× 43× 410× 117× 117× 117×   293×   293× 293× 291×       293× 293× 293× 293× 293× 293×           293× 293× 293× 293× 293× 293× 293× 293× 293× 293× 57× 57× 57× 25× 19× 19×                           293× 187×   293× 293× 293×   293× 293× 293×   293× 293× 293× 293×   293×             43× 43× 293× 293× 1886× 117× 136×   117× 136×   117×     293× 293× 293× 117×       293× 293× 144× 144×     19× 19×     11× 11×   19× 19×     83× 83×       149×   48× 48×   18× 18×   83× 83×     293×   117× 117× 117× 117× 117× 117× 117× 117× 293× 293× 293× 683× 184× 184×     293×       293× 293× 293×     122× 122× 122× 122× 122× 122× 117×       122×   171×   105×   105× 105×                                         66× 52× 38× 50× 50× 50×   12×   50×   38× 38× 38×     14×                     14×               25× 25× 11×                                             20×     293× 293× 293× 293× 293× 293× 25×     117×   293× 293× 293×             293× 293× 293× 293×   293× 293× 293× 293× 293× 293×     293× 293× 293× 293× 293× 293×       293×   68× 68× 46× 331× 318×       68× 68× 17× 48×         68× 68× 13× 13× 13× 13× 13×         68× 68× 13× 13× 18×   13×     163× 163× 122× 122× 122× 122× 39× 45× 39×         124×           1747×        
define(["require", "exports", "../../common/constant", "@syncfusion/ej2-base", "../base/constant", "./insert-methods"], function (require, exports, EVENTS, ej2_base_1, constant_1, insert_methods_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var MsWordPaste = (function () {
        function MsWordPaste(parent) {
            this.olData = [
                'decimal',
                'decimal-leading-zero',
                'lower-alpha',
                'lower-roman',
                'upper-alpha',
                'upper-roman',
                'lower-greek'
            ];
            this.ulData = [
                'disc',
                'square',
                'circle',
                'disc',
                'square',
                'circle'
            ];
            this.ignorableNodes = ['A', 'APPLET', 'B', 'BLOCKQUOTE', 'BR',
                'BUTTON', 'CENTER', 'CODE', 'COL', 'COLGROUP', 'DD', 'DEL', 'DFN', 'DIR', 'DIV',
                'DL', 'DT', 'EM', 'FIELDSET', 'FONT', 'FORM', 'FRAME', 'FRAMESET', 'H1', 'H2',
                'H3', 'H4', 'H5', 'H6', 'HR', 'I', 'IMG', 'IFRAME', 'INPUT', 'INS', 'LABEL',
                'LI', 'OL', 'OPTION', 'P', 'PARAM', 'PRE', 'Q', 'S', 'SELECT', 'SPAN', 'STRIKE',
                'STRONG', 'SUB', 'SUP', 'TABLE', 'TBODY', 'TD', 'TEXTAREA', 'TFOOT', 'TH',
                'THEAD', 'TITLE', 'TR', 'TT', 'U', 'UL'];
            this.blockNode = ['div', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
                'address', 'blockquote', 'button', 'center', 'dd', 'dir', 'dl', 'dt', 'fieldset',
                'frameset', 'hr', 'iframe', 'isindex', 'li', 'map', 'menu', 'noframes', 'noscript',
                'object', 'ol', 'pre', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul',
                'header', 'article', 'nav', 'footer', 'section', 'aside', 'main', 'figure', 'figcaption'];
            this.borderStyle = ['border-top', 'border-right', 'border-bottom', 'border-left'];
            this.upperRomanNumber = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX',
                'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX'];
            this.lowerRomanNumber = ['i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix',
                'x', 'xi', 'xii', 'xiii', 'xiv', 'xv', 'xvi', 'xvii', 'xviii', 'xix', 'xx'];
            this.lowerGreekNumber = ['α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η', 'θ', 'ι', 'κ', 'λ',
                'μ', 'ν', 'ξ', 'ο', 'π', 'ρ', 'σ', 'τ', 'υ', 'φ', 'χ', 'ψ', 'ω'];
            this.removableElements = ['o:p', 'style', 'w:sdt'];
            this.listContents = [];
            this.cropImageDimensions = [];
            this.parent = parent;
            this.addEventListener();
        }
        MsWordPaste.prototype.addEventListener = function () {
            this.parent.observer.on(EVENTS.MS_WORD_CLEANUP_PLUGIN, this.wordCleanup, this);
            this.parent.observer.on(EVENTS.INTERNAL_DESTROY, this.destroy, this);
        };
        MsWordPaste.prototype.removeEventListener = function () {
            this.parent.observer.off(EVENTS.MS_WORD_CLEANUP_PLUGIN, this.wordCleanup);
            this.parent.observer.off(EVENTS.INTERNAL_DESTROY, this.destroy);
        };
        MsWordPaste.prototype.wordCleanup = function (e) {
            var wordPasteStyleConfig = !ej2_base_1.isNullOrUndefined(e.allowedStylePropertiesArray) ? e.allowedStylePropertiesArray : [];
            var listNodes = [];
            var tempHTMLContent = e.args.clipboardData.getData('text/HTML');
            var rtfData = e.args.clipboardData.getData('text/rtf');
            var elm = ej2_base_1.createElement('p');
            elm.setAttribute('id', 'MSWord-Content');
            elm.innerHTML = tempHTMLContent;
            this.addDoubleBr(elm);
            var patern = /class='?Mso|style='[^ ]*\bmso-/i;
            var patern2 = /class="?Mso|style="[^ ]*\bmso-/i;
            var patern3 = /(class="?Mso|class='?Mso|class="?Xl|class='?Xl|class=Xl|style="[^"]*\bmso-|style='[^']*\bmso-|w:WordDocument)/gi;
            var pattern4 = /style='mso-width-source:/i;
            var source = this.findSource(elm);
            if (patern.test(tempHTMLContent) || patern2.test(tempHTMLContent) || patern3.test(tempHTMLContent) ||
                pattern4.test(tempHTMLContent)) {
                tempHTMLContent = tempHTMLContent.replace(/<img[^>]+>/i, '');
                this.addListClass(elm);
                listNodes = this.cleanUp(elm, listNodes);
                if (!ej2_base_1.isNullOrUndefined(listNodes[0]) && listNodes[0].parentElement.tagName !== 'UL' &&
                    listNodes[0].parentElement.tagName !== 'OL') {
                    this.listConverter(listNodes);
                }
                this.imageConversion(elm, rtfData);
                this.cleanList(elm, 'UL');
                this.cleanList(elm, 'OL');
                this.styleCorrection(elm, wordPasteStyleConfig);
                this.removingComments(elm);
                this.removeUnwantedElements(elm);
                this.removeEmptyElements(elm);
                this.removeEmptyAnchorTag(elm);
                this.breakLineAddition(elm);
                this.processMargin(elm);
                this.removeClassName(elm);
                if (pattern4.test(tempHTMLContent)) {
                    this.addTableBorderClass(elm);
                }
                e.callBack(elm.innerHTML, this.cropImageDimensions, source);
            }
            else {
                if (source === constant_1.PASTE_SOURCE[2]) {
                    this.handleOneNoteContent(elm);
                }
                e.callBack(elm.innerHTML, null, source);
            }
        };
        MsWordPaste.prototype.addDoubleBr = function (elm) {
            var newline = elm.querySelector('.Apple-interchange-newline');
            if (!ej2_base_1.isNullOrUndefined(newline) && ej2_base_1.Browser.userAgent.indexOf('Chrome') !== -1 && newline.parentElement.nodeName === 'P' && elm !== newline.parentElement) {
                for (var i = 0; i < elm.childNodes.length; i++) {
                    var node = elm.childNodes[i];
                    if (node.nodeType === Node.COMMENT_NODE && node.nodeValue.includes('StartFragment')) {
                        var newElement = document.createElement('p');
                        newElement.innerHTML = '<br>';
                        var cssText = newline.parentElement.style.cssText;
                        var currentStyle = newElement.getAttribute('style') || '';
                        var newStyle = currentStyle + cssText;
                        newElement.setAttribute('style', newStyle);
                        elm.insertBefore(newElement, node.nextSibling);
                        ej2_base_1.detach(newline);
                        break;
                    }
                }
            }
        };
        MsWordPaste.prototype.cleanList = function (elm, listTag) {
            var replacableElem = elm.querySelectorAll(listTag + ' div');
            for (var j = replacableElem.length - 1; j >= 0; j--) {
                var parentElem = replacableElem[j].parentNode;
                while (replacableElem[j].firstChild) {
                    parentElem.insertBefore(replacableElem[j].firstChild, replacableElem[j]);
                }
                var closestListElem = this.findClosestListElem(replacableElem[j]);
                Eif (closestListElem) {
                    this.insertAfter(replacableElem[j], closestListElem);
                }
            }
        };
        MsWordPaste.prototype.insertAfter = function (newNode, referenceNode) {
            referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
        };
        MsWordPaste.prototype.findClosestListElem = function (listElem) {
            var closestListElem;
            while (!ej2_base_1.isNullOrUndefined(listElem)) {
                listElem = !ej2_base_1.isNullOrUndefined(listElem.closest('ul')) && listElem.tagName !== 'UL' ?
                    listElem.closest('ul') : (listElem.tagName !== 'OL' ? listElem.closest('ol') : null);
                closestListElem = !ej2_base_1.isNullOrUndefined(listElem) ? listElem : closestListElem;
            }
            return closestListElem;
        };
        MsWordPaste.prototype.addListClass = function (elm) {
            var allNodes = elm.querySelectorAll('*');
            for (var index = 0; index < allNodes.length; index++) {
                if (!ej2_base_1.isNullOrUndefined(allNodes[index].getAttribute('style')) && allNodes[index].getAttribute('style').replace(/ /g, '').replace('\n', '').indexOf('mso-list:l') >= 0 &&
                    allNodes[index].className.toLowerCase().indexOf('msolistparagraph') === -1 &&
                    allNodes[index].tagName.charAt(0) !== 'H' && allNodes[index].tagName !== 'LI' &&
                    allNodes[index].tagName !== 'OL' && allNodes[index].tagName !== 'UL') {
                    allNodes[index].classList.add('msolistparagraph');
                }
            }
        };
        MsWordPaste.prototype.addTableBorderClass = function (elm) {
            var allTableElm = elm.querySelectorAll('table');
            var hasTableBorder = false;
            for (var i = 0; i < allTableElm.length; i++) {
                for (var j = 0; j < this.borderStyle.length; j++) {
                    Eif (allTableElm[i].innerHTML.indexOf(this.borderStyle[j]) >= 0) {
                        hasTableBorder = true;
                        break;
                    }
                }
                Eif (hasTableBorder) {
                    allTableElm[i].classList.add('e-rte-table-border');
                    hasTableBorder = false;
                }
            }
        };
        MsWordPaste.prototype.imageConversion = function (elm, rtfData) {
            this.checkVShape(elm);
            var imgElem = elm.querySelectorAll('img');
            for (var i = 0; i < imgElem.length; i++) {
                if (!ej2_base_1.isNullOrUndefined(imgElem[i].getAttribute('v:shapes')) &&
                    imgElem[i].getAttribute('v:shapes').indexOf('Picture') < 0 &&
                    imgElem[i].getAttribute('v:shapes').indexOf('圖片') < 0 &&
                    imgElem[i].getAttribute('v:shapes').indexOf('Grafik') < 0 &&
                    imgElem[i].getAttribute('v:shapes').toLowerCase().indexOf('image') < 0 &&
                    imgElem[i].getAttribute('v:shapes').indexOf('Graphic') < 0 &&
                    imgElem[i].getAttribute('v:shapes').indexOf('_x0000_s') < 0 &&
                    imgElem[i].getAttribute('v:shapes').indexOf('_x0000_i') < 0 &&
                    imgElem[i].getAttribute('v:shapes').indexOf('img1') < 0) {
                    imgElem[i].classList.add('e-rte-image-unsupported');
                }
                imgElem[i].removeAttribute('v:shapes');
            }
            imgElem = elm.querySelectorAll('img');
            var imgSrc = [];
            var base64Src = [];
            var imgName = [];
            var linkRegex = new RegExp(/([^\S]|^)(((https?\:\/\/)|(www\.)|(blob\:))(\S+))/gi);
            if (imgElem.length > 0) {
                for (var i = 0; i < imgElem.length; i++) {
                    imgSrc.push(imgElem[i].getAttribute('src'));
                    imgName.push(imgElem[i].getAttribute('src').split('/')[imgElem[i].getAttribute('src').split('/').length - 1].split('.')[0]);
                }
                var hexValue = this.hexConversion(rtfData);
                for (var i = 0; i < hexValue.length; i++) {
                    base64Src.push({
                        base64Data: !ej2_base_1.isNullOrUndefined(hexValue[i].hex) ? this.convertToBase64(hexValue[i]) : null,
                        isCroppedImage: hexValue[i].isCroppedImage
                    });
                    if (hexValue[i].isCroppedImage) {
                        this.cropImageDimensions.push({
                            goalWidth: hexValue[i].goalWidth,
                            goalHeight: hexValue[i].goalHeight,
                            cropLength: hexValue[i].cropLength,
                            cropTop: hexValue[i].cropTop,
                            cropR: hexValue[i].cropR,
                            cropB: hexValue[i].cropB
                        });
                    }
                }
                imgElem = elm.querySelectorAll('img:not(.e-rte-image-unsupported');
                for (var i = 0; i < imgElem.length; i++) {
                    if (imgSrc[i].match(linkRegex)) {
                        imgElem[i].setAttribute('src', imgSrc[i]);
                    }
                    else {
                        if (!ej2_base_1.isNullOrUndefined(base64Src[i]) && !ej2_base_1.isNullOrUndefined(base64Src[i].base64Data)) {
                            imgElem[i].setAttribute('src', base64Src[i].base64Data);
                        }
                        else {
                            imgElem[i].removeAttribute('src');
                            imgElem[i].classList.add('e-rte-image-unsupported');
                        }
                        if (!ej2_base_1.isNullOrUndefined(base64Src[i]) && base64Src[i].isCroppedImage) {
                            imgElem[i].classList.add('e-img-cropped');
                        }
                    }
                    imgElem[i].setAttribute('id', 'msWordImg-' + imgName[i]);
                }
                imgElem = elm.querySelectorAll('.e-rte-image-unsupported');
                for (var i = 0; i < imgElem.length; i++) {
                    imgElem[i].removeAttribute('src');
                }
            }
        };
        MsWordPaste.prototype.checkVShape = function (elm) {
            var allNodes = elm.querySelectorAll('*');
            for (var i = 0; i < allNodes.length; i++) {
                switch (allNodes[i].nodeName) {
                    case 'V:SHAPETYPE':
                        ej2_base_1.detach(allNodes[i]);
                        break;
                    case 'V:SHAPE':
                        Eif (allNodes[i].firstElementChild.nodeName === 'V:IMAGEDATA') {
                            var src = allNodes[i].firstElementChild.getAttribute('src');
                            var imgElement = ej2_base_1.createElement('img');
                            imgElement.setAttribute('src', src);
                            allNodes[i].parentElement.insertBefore(imgElement, allNodes[i]);
                            ej2_base_1.detach(allNodes[i]);
                        }
                        break;
                }
            }
        };
        MsWordPaste.prototype.convertToBase64 = function (hexValue) {
            var byteArr = this.conHexStringToBytes(hexValue.hex);
            var base64String = this.conBytesToBase64(byteArr);
            var base64 = hexValue.type ? 'data:' + hexValue.type + ';base64,' + base64String : null;
            return base64;
        };
        MsWordPaste.prototype.conBytesToBase64 = function (byteArr) {
            var base64Str = '';
            var base64Char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
            var byteArrLen = byteArr.length;
            for (var i = 0; i < byteArrLen; i += 3) {
                var array3 = byteArr.slice(i, i + 3);
                var array3length = array3.length;
                var array4 = [];
                if (array3length < 3) {
                    for (var j = array3length; j < 3; j++) {
                        array3[j] = 0;
                    }
                }
                array4[0] = (array3[0] & 0xFC) >> 2;
                array4[1] = ((array3[0] & 0x03) << 4) | (array3[1] >> 4);
                array4[2] = ((array3[1] & 0x0F) << 2) | ((array3[2] & 0xC0) >> 6);
                array4[3] = array3[2] & 0x3F;
                for (var j = 0; j < 4; j++) {
                    if (j <= array3length) {
                        base64Str += base64Char.charAt(array4[j]);
                    }
                    else {
                        base64Str += '=';
                    }
                }
            }
            return base64Str;
        };
        MsWordPaste.prototype.conHexStringToBytes = function (hex) {
            var byteArr = [];
            var byteArrLen = hex.length / 2;
            for (var i = 0; i < byteArrLen; i++) {
                byteArr.push(parseInt(hex.substr(i * 2, 2), 16));
            }
            return byteArr;
        };
        MsWordPaste.prototype.hexConversion = function (rtfData) {
            var regExp = RegExp;
            var picHead = new regExp('\\{\\\\pict[\\s\\S]+?\\\\bliptag-?\\d+(\\\\blipupi-?\\d+)?(\\{\\\\\\*\\\\blipuid\\s?[\\da-fA-F]+)?[\\s\\}]*?');
            var pic = new regExp('(?:(' + picHead.source + '))([\\da-fA-F\\s]+)\\}', 'g');
            var fullImg = rtfData.match(pic);
            var imgType;
            var result = [];
            if (!ej2_base_1.isNullOrUndefined(fullImg)) {
                for (var i = 0; i < fullImg.length; i++) {
                    Iif (fullImg[i].indexOf('fIsBullet') !== -1 && fullImg[i].indexOf('wzName') === -1) {
                        continue;
                    }
                    var isCroppedImage = false;
                    var goalWidth = 0;
                    var goalHeight = 0;
                    var cropLength = 0;
                    var cropTop = 0;
                    var cropR = 0;
                    var cropB = 0;
                    Eif (picHead.test(fullImg[i])) {
                        if (fullImg[i].indexOf('\\pngblip') !== -1) {
                            imgType = 'image/png';
                        }
                        else if (fullImg[i].indexOf('\\jpegblip') !== -1) {
                            imgType = 'image/jpeg';
                        }
                        else Iif (fullImg[i].indexOf('\\emfblip') !== -1) {
                            imgType = null;
                        }
                        else {
                            continue;
                        }
                        isCroppedImage = ((this.extractCropValue('cropl', fullImg[i]) > 0 &&
                            this.extractCropValue('cropt', fullImg[i]) > 0) ||
                            this.extractCropValue('cropr', fullImg[i]) > 0 ||
                            this.extractCropValue('cropb', fullImg[i])) ? true : false;
                        if (isCroppedImage) {
                            goalWidth = this.extractCropValue('wgoal', fullImg[i]);
                            goalHeight = this.extractCropValue('hgoal', fullImg[i]);
                            cropLength = this.extractCropValue('cropl', fullImg[i]);
                            cropTop = this.extractCropValue('cropt', fullImg[i]);
                            cropR = this.extractCropValue('cropr', fullImg[i]);
                            cropB = this.extractCropValue('cropb', fullImg[i]);
                        }
                        result.push({
                            hex: imgType ? fullImg[i].replace(picHead, '').replace(/[^\da-fA-F]/g, '') : null,
                            type: imgType,
                            isCroppedImage: isCroppedImage,
                            goalWidth: goalWidth,
                            goalHeight: goalHeight,
                            cropLength: cropLength,
                            cropTop: cropTop,
                            cropR: cropR,
                            cropB: cropB
                        });
                    }
                }
            }
            return result;
        };
        MsWordPaste.prototype.extractCropValue = function (crop, rtfData) {
            var regExp = RegExp;
            var result = new regExp('\\\\pic' + crop + '(\\-?\\d+)\\\\').exec(rtfData.replace(/\r\n\\/g, '\\').replace(/\n/g, '\\'))[1];
            return parseInt(result, 10);
        };
        MsWordPaste.prototype.removeClassName = function (elm) {
            var elmWithClass = elm.querySelectorAll('*[class]:not(.e-img-cropped):not(.e-rte-image-unsupported)');
            for (var i = 0; i < elmWithClass.length; i++) {
                elmWithClass[i].removeAttribute('class');
            }
        };
        MsWordPaste.prototype.breakLineAddition = function (elm) {
            var allElements = elm.querySelectorAll('*');
            for (var i = 0; i < allElements.length; i++) {
                if (allElements[i].children.length === 0 && allElements[i].innerHTML === '&nbsp;' &&
                    (allElements[i].innerHTML === '&nbsp;' && !allElements[i].closest('li')) &&
                    !allElements[i].closest('td') && (allElements[i].nodeName !== 'SPAN' ||
                    allElements[i].nodeName === 'SPAN' && (ej2_base_1.isNullOrUndefined(allElements[i].previousElementSibling) &&
                        ej2_base_1.isNullOrUndefined(allElements[i].nextElementSibling)))) {
                    var detachableElement = this.findDetachElem(allElements[i]);
                    var brElement = ej2_base_1.createElement('br');
                    var hasNbsp = detachableElement.textContent.length > 0 && detachableElement.textContent.match(/\u00a0/g)
                        && detachableElement.textContent.match(/\u00a0/g).length > 0;
                    Iif (!hasNbsp && !ej2_base_1.isNullOrUndefined(detachableElement.parentElement)) {
                        detachableElement.parentElement.insertBefore(brElement, detachableElement);
                        ej2_base_1.detach(detachableElement);
                    }
                }
            }
        };
        MsWordPaste.prototype.findDetachElem = function (element) {
            var removableElement;
            if (!ej2_base_1.isNullOrUndefined(element.parentElement) &&
                element.parentElement.textContent.trim() === '' && element.parentElement.tagName !== 'TD' &&
                ej2_base_1.isNullOrUndefined(element.parentElement.querySelector('img'))) {
                removableElement = this.findDetachElem(element.parentElement);
            }
            else {
                removableElement = element;
            }
            return removableElement;
        };
        MsWordPaste.prototype.removeUnwantedElements = function (elm) {
            var styleElm = elm.querySelector('style');
            if (!ej2_base_1.isNullOrUndefined(styleElm)) {
                ej2_base_1.detach(styleElm);
            }
            var innerElement = elm.innerHTML;
            for (var i = 0; i < this.removableElements.length; i++) {
                var regExp = RegExp;
                var regExpStartElem = new regExp('<' + this.removableElements[i] + '\\s*[^>]*>', 'g');
                var regExpEndElem = new regExp('</' + this.removableElements[i] + '>', 'g');
                innerElement = innerElement.replace(regExpStartElem, '');
                innerElement = innerElement.replace(regExpEndElem, '');
            }
            elm.innerHTML = innerElement;
            elm.querySelectorAll(':empty');
        };
        MsWordPaste.prototype.findDetachEmptyElem = function (element) {
            var removableElement;
            if (!ej2_base_1.isNullOrUndefined(element.parentElement)) {
                var hasNbsp = element.parentElement.textContent.length > 0 && element.parentElement.textContent.match(/\u00a0/g)
                    && element.parentElement.textContent.match(/\u00a0/g).length > 0;
                if (!hasNbsp && element.parentElement.textContent.trim() === '' &&
                    element.parentElement.getAttribute('id') !== 'MSWord-Content' &&
                    !(this.hasParentWithClass(element, 'MsoListParagraph')) &&
                    ej2_base_1.isNullOrUndefined(element.parentElement.querySelector('img'))) {
                    removableElement = this.findDetachEmptyElem(element.parentElement);
                }
                else {
                    removableElement = element;
                }
            }
            else {
                removableElement = null;
            }
            return removableElement;
        };
        MsWordPaste.prototype.hasParentWithClass = function (element, className) {
            var currentParentElem = element.parentElement;
            while (!ej2_base_1.isNullOrUndefined(currentParentElem)) {
                if (currentParentElem.classList.contains(className)) {
                    return true;
                }
                currentParentElem = currentParentElem.parentElement;
            }
            return false;
        };
        MsWordPaste.prototype.removeEmptyElements = function (element) {
            var emptyElements = element.querySelectorAll(':empty');
            for (var i = 0; i < emptyElements.length; i++) {
                if (!ej2_base_1.isNullOrUndefined(emptyElements[i].closest('td')) &&
                    !ej2_base_1.isNullOrUndefined(emptyElements[i].closest('td').querySelector('.MsoNormal'))) {
                    emptyElements[i].innerHTML = '-';
                }
                var lineWithDiv = true;
                if (emptyElements[i].tagName === 'DIV') {
                    lineWithDiv = emptyElements[i].style.borderBottom === 'none' ||
                        emptyElements[i].style.borderBottom === '' ? true : false;
                }
                if (emptyElements[i].tagName !== 'IMG' && emptyElements[i].tagName !== 'BR' &&
                    emptyElements[i].tagName !== 'IFRAME' && emptyElements[i].tagName !== 'TD' &&
                    emptyElements[i].tagName !== 'HR' && lineWithDiv) {
                    var detachableElement = this.findDetachEmptyElem(emptyElements[i]);
                    if (!ej2_base_1.isNullOrUndefined(detachableElement)) {
                        ej2_base_1.detach(detachableElement);
                    }
                }
            }
        };
        MsWordPaste.prototype.styleCorrection = function (elm, wordPasteStyleConfig) {
            var styleElement = elm.querySelectorAll('style');
            var styles = [];
            if (styleElement.length > 0) {
                if (!ej2_base_1.isNullOrUndefined(styleElement[0].innerHTML.match(/[\S ]+\s+{[\s\S]+?}/gi))) {
                    styles = styleElement[0].innerHTML.match(/[\S ]+\s+{[\s\S]+?}/gi);
                }
                else Eif (styleElement.length > 1) {
                    styles = styleElement[1].innerHTML.match(/[\S ]+\s+{[\s\S]+?}/gi);
                }
                var styleClassObject_1 = !ej2_base_1.isNullOrUndefined(styles) ? this.findStyleObject(styles) : null;
                Eif (!ej2_base_1.isNullOrUndefined(styleClassObject_1)) {
                    var keys = Object.keys(styleClassObject_1);
                    var values = keys.map(function (key) {
                        return styleClassObject_1["" + key];
                    });
                    values = this.removeUnwantedStyle(values, wordPasteStyleConfig);
                    this.filterStyles(elm, wordPasteStyleConfig);
                    var resultElem = void 0;
                    var fromClass = false;
                    var regex = /^(p|div|li)\.(1|10|11)$/;
                    for (var i = 0; i < keys.length; i++) {
                        if (keys[i].split('.')[0] === '') {
                            resultElem = elm.getElementsByClassName(keys[i].split('.')[1]);
                            fromClass = true;
                        }
                        else if ((keys[i].split('.').length === 1 && keys[i].split('.')[0].indexOf('@') >= 0) || (regex.test(keys[i]))) {
                            continue;
                        }
                        else if (keys[i].split('.').length === 1 && keys[i].split('.')[0].indexOf('@') < 0) {
                            resultElem = elm.getElementsByTagName(keys[i]);
                        }
                        else {
                            resultElem = elm.querySelectorAll(keys[i]);
                        }
                        for (var j = 0; j < resultElem.length; j++) {
                            if (resultElem[j].closest('li') && keys[i] === 'p') {
                                continue;
                            }
                            var styleProperty = resultElem[j].getAttribute('style');
                            if (!ej2_base_1.isNullOrUndefined(styleProperty) && styleProperty.trim() !== '') {
                                var valueSplit = values[i].split(';');
                                for (var q = 0; q < valueSplit.length; q++) {
                                    Iif (valueSplit[q].split(':')[0] === 'border' && valueSplit[q].split(':')[1] === 'none') {
                                        valueSplit.splice(q, 1);
                                        q--;
                                    }
                                }
                                if (!fromClass) {
                                    for (var k = 0; k < valueSplit.length; k++) {
                                        var propertyName = valueSplit[k].split(':')[0];
                                        if (styleProperty.includes(propertyName + ':')) {
                                            valueSplit.splice(k, 1);
                                            k--;
                                        }
                                    }
                                }
                                var changedValue = valueSplit.join(';') + ';' + styleProperty;
                                resultElem[j].setAttribute('style', changedValue);
                            }
                            else {
                                values[i] = values[i].replace(/text-indent:-(.*?)(?=;|$)/gm, '');
                                resultElem[j].setAttribute('style', values[i]);
                            }
                        }
                        fromClass = false;
                    }
                    var listClass = ['MsoListParagraphCxSpFirst', 'MsoListParagraphCxSpMiddle', 'MsoListParagraphCxSpLast'];
                    for (var i = 0; i < listClass.length; i++) {
                        if (keys.indexOf('li.' + listClass[i]) > -1) {
                            var olULElems = elm.querySelectorAll('ol.' + listClass[i] + ', ul.' + listClass[i]);
                            for (var j = 0; j < olULElems.length; j++) {
                                var styleProperty = olULElems[j].getAttribute('style');
                                if (!ej2_base_1.isNullOrUndefined(styleProperty) && styleProperty.trim() !== '' && olULElems[j].style.marginLeft !== '') {
                                    var valueSplit = values[keys.indexOf('li.' + listClass[i])].split(';');
                                    for (var k = 0; k < valueSplit.length; k++) {
                                        if ('margin-left'.indexOf(valueSplit[k].split(':')[0]) >= 0) {
                                            if (!ej2_base_1.isNullOrUndefined(valueSplit[k].split(':')[1]) &&
                                                valueSplit[k].split(':')[1].indexOf('in') >= 0 &&
                                                olULElems[j].style.marginLeft.indexOf('in') >= 0) {
                                                var classStyle = parseFloat(valueSplit[k].split(':')[1].split('in')[0]);
                                                var inlineStyle = parseFloat(olULElems[j].style.marginLeft.split('in')[0]);
                                                olULElems[j].style.marginLeft = (inlineStyle - classStyle) + 'in';
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        };
        MsWordPaste.prototype.filterStyles = function (elm, wordPasteStyleConfig) {
            var elmWithStyles = elm.querySelectorAll('*[style]');
            for (var i = 0; i < elmWithStyles.length; i++) {
                var elemStyleProperty = elmWithStyles[i].getAttribute('style').split(';');
                var styleValue = '';
                for (var j = 0; j < elemStyleProperty.length; j++) {
                    if (wordPasteStyleConfig.indexOf(elemStyleProperty[j].split(':')[0].trim()) >= 0) {
                        styleValue += elemStyleProperty[j] + ';';
                    }
                }
                elmWithStyles[i].setAttribute('style', styleValue);
            }
        };
        MsWordPaste.prototype.removeUnwantedStyle = function (values, wordPasteStyleConfig) {
            for (var i = 0; i < values.length; i++) {
                var styleValues = values[i].split(';');
                values[i] = '';
                for (var j = 0; j < styleValues.length; j++) {
                    if (wordPasteStyleConfig.indexOf(styleValues[j].split(':')[0]) >= 0) {
                        values[i] += styleValues[j] + ';';
                    }
                }
            }
            return values;
        };
        MsWordPaste.prototype.findStyleObject = function (styles) {
            var styleClassObject = {};
            for (var i = 0; i < styles.length; i++) {
                var tempStyle = styles[i];
                var classNameCollection = tempStyle.replace(/([\S ]+\s+){[\s\S]+?}/gi, '$1');
                var stylesCollection = tempStyle.replace(/[\S ]+\s+{([\s\S]+?)}/gi, '$1');
                classNameCollection = classNameCollection.replace(/^[\s]|[\s]$/gm, '');
                stylesCollection = stylesCollection.replace(/^[\s]|[\s]$/gm, '');
                classNameCollection = classNameCollection.replace(/\n|\r|\n\r/g, '');
                stylesCollection = stylesCollection.replace(/\n|\r|\n\r/g, '');
                for (var classNames = classNameCollection.split(', '), j = 0; j < classNames.length; j++) {
                    styleClassObject[classNames[j]] = stylesCollection;
                }
            }
            return styleClassObject;
        };
        MsWordPaste.prototype.removingComments = function (elm) {
            var innerElement = elm.innerHTML;
            innerElement = innerElement.replace(/<!--[\s\S]*?-->/g, '');
            elm.innerHTML = innerElement;
        };
        MsWordPaste.prototype.cleanUp = function (node, listNodes) {
            var tempCleaner = [];
            var prevflagState;
            var allNodes = node.querySelectorAll('*');
            for (var index = 0; index < allNodes.length; index++) {
                if (this.ignorableNodes.indexOf(allNodes[index].nodeName) === -1 ||
                    (allNodes[index].nodeType === 3 && allNodes[index].textContent.trim() === '')) {
                    tempCleaner.push(allNodes[index]);
                    continue;
                }
                else if (allNodes[index].className &&
                    allNodes[index].className.toLowerCase().indexOf('msolistparagraph') !== -1 &&
                    !ej2_base_1.isNullOrUndefined(allNodes[index].getAttribute('style')) &&
                    allNodes[index].getAttribute('style').indexOf('mso-list:') >= 0) {
                    if (allNodes[index].className.indexOf('MsoListParagraphCxSpFirst') >= 0 && listNodes.length > 0 &&
                        listNodes[listNodes.length - 1] !== null) {
                        listNodes.push(null);
                    }
                    listNodes.push(allNodes[index]);
                }
                if (prevflagState && (this.blockNode.indexOf(allNodes[index].nodeName.toLowerCase()) !== -1) &&
                    !(allNodes[index].className &&
                        allNodes[index].className.toLowerCase().indexOf('msolistparagraph') !== -1 && !ej2_base_1.isNullOrUndefined(allNodes[index].getAttribute('style')) &&
                        allNodes[index].getAttribute('style').indexOf('mso-list:') >= 0)) {
                    listNodes.push(null);
                }
                if (this.blockNode.indexOf(allNodes[index].nodeName.toLowerCase()) !== -1) {
                    if (allNodes[index].className &&
                        allNodes[index].className.toLowerCase().indexOf('msolistparagraph') !== -1 && !ej2_base_1.isNullOrUndefined(allNodes[index].getAttribute('style')) &&
                        allNodes[index].getAttribute('style').indexOf('mso-list:') >= 0) {
                        prevflagState = true;
                    }
                    else {
                        prevflagState = false;
                    }
                }
            }
            if (listNodes.length && (listNodes[listNodes.length - 1] !== null)) {
                listNodes.push(null);
            }
            return listNodes;
        };
        MsWordPaste.prototype.listConverter = function (listNodes) {
            var level;
            var data = [];
            var listFormatOverride;
            var collection = [];
            var content = '';
            var stNode;
            var currentListStyle = '';
            for (var i = 0; i < listNodes.length; i++) {
                if (listNodes[i] === null) {
                    data.push({ content: this.makeConversion(collection), node: listNodes[i - 1] });
                    collection = [];
                    continue;
                }
                if (listNodes[i].getAttribute('style') && listNodes[i].getAttribute('style').indexOf('mso-outline-level') !== -1) {
                    listNodes[i].setAttribute('style', listNodes[i].getAttribute('style').replace('mso-outline-level', 'mso-outline'));
                }
                content = listNodes[i].getAttribute('style');
                if (content && content.indexOf('level') !== -1) {
                    level = parseInt(content.charAt(content.indexOf('level') + 5), null);
                }
                else {
                    level = 1;
                }
                Eif (content && content.indexOf('mso-list:') !== -1) {
                    var msoListValue = void 0;
                    Eif (content.match(/mso-list:[^;]+;?/)) {
                        var changedContent = content.replace(new RegExp('\\n', 'g'), '').split(' ').join('');
                        msoListValue = changedContent.match(/mso-list:[^;]+;?/)[0].split(':l');
                        listFormatOverride = ej2_base_1.isNullOrUndefined(msoListValue) ? null : parseInt(msoListValue[1].split('level')[0], 10);
                    }
                    else {
                        listFormatOverride = null;
                    }
                }
                this.listContents = [];
                this.getListContent(listNodes[i]);
                var type = void 0;
                var listStyleType = void 0;
                var startAttr = void 0;
                var styleMarginLeft = void 0;
                Eif (!ej2_base_1.isNullOrUndefined(this.listContents[0])) {
                    type = this.listContents[0].trim().length > 1 ? 'ol' : 'ul';
                    listStyleType = this.getlistStyleType(this.listContents[0], type);
                    if (type === 'ol' && (i === 0 || listNodes[i - 1] === null)) {
                        var startString = this.listContents[0].split('.')[0];
                        var listTypes = ['A', 'a', 'I', 'i', 'α', '1', '01', '1-'];
                        if (listTypes.indexOf(startString) === -1) {
                            if (listStyleType === 'decimal') {
                                Eif (!isNaN(parseInt(startString, 10))) {
                                    startAttr = parseInt(startString, 10);
                                }
                            }
                            else if (listStyleType === 'decimal-leading-zero') {
                                Eif (!isNaN(parseInt(startString, 10))) {
                                    startAttr = parseInt(startString, 10);
                                }
                            }
                            else if (listStyleType === 'upper-alpha') {
                                startAttr = (startString.split('.')[0].charCodeAt(0) - 64);
                            }
                            else if (listStyleType === 'lower-alpha') {
                                startAttr = (startString.split('.')[0].charCodeAt(0) - 96);
                            }
                            else if (listStyleType === 'upper-roman') {
                                startAttr = this.upperRomanNumber.indexOf(this.listContents[0].split('.')[0]) + 1;
                            }
                            else Eif (listStyleType === 'lower-roman') {
                                startAttr = this.lowerRomanNumber.indexOf(this.listContents[0].split('.')[0]) + 1;
                            }
                            else if (listStyleType === 'lower-greek') {
                                startAttr = this.lowerGreekNumber.indexOf(this.listContents[0].split('.')[0]) + 1;
                            }
                        }
                    }
                    if (listNodes[i].style.marginLeft !== '') {
                        styleMarginLeft = listNodes[i].style.marginLeft;
                    }
                    var tempNode = [];
                    for (var j = 1; j < this.listContents.length; j++) {
                        tempNode.push(this.listContents[j]);
                    }
                    var currentClassName = void 0;
                    Eif (!ej2_base_1.isNullOrUndefined(listNodes[i].className)) {
                        currentClassName = listNodes[i].className;
                    }
                    Eif (!ej2_base_1.isNullOrUndefined(listNodes[i].getAttribute('style'))) {
                        listNodes[i].setAttribute('style', listNodes[i].getAttribute('style').replace('text-align:start;', ''));
                        listNodes[i].style.textIndent = '';
                        currentListStyle = listNodes[i].getAttribute('style');
                    }
                    collection.push({
                        listType: type, content: tempNode, nestedLevel: level,
                        listFormatOverride: listFormatOverride, class: currentClassName,
                        listStyle: currentListStyle, listStyleTypeName: listStyleType, start: startAttr, styleMarginLeft: styleMarginLeft
                    });
                }
            }
            stNode = listNodes.shift();
            while (stNode) {
                var elemColl = [];
                for (var temp1 = 0; temp1 < data.length; temp1++) {
                    if (data[temp1].node === stNode) {
                        for (var index = 0; index < data[temp1].content.childNodes.length; index++) {
                            elemColl.push(data[temp1].content.childNodes[index]);
                        }
                        for (var index = 0; index < elemColl.length; index++) {
                            stNode.parentElement.insertBefore(elemColl[index], stNode);
                        }
                        break;
                    }
                }
                stNode.remove();
                stNode = listNodes.shift();
                if (!stNode) {
                    stNode = listNodes.shift();
                }
            }
        };
        MsWordPaste.prototype.getlistStyleType = function (listContent, type) {
            var currentListClass;
            if (type === 'ol') {
                var charCode = listContent.split('.')[0].charCodeAt(0);
                switch (true) {
                    case this.upperRomanNumber.indexOf(listContent.split('.')[0]) > -1:
                        currentListClass = 'upper-roman';
                        break;
                    case this.lowerRomanNumber.indexOf(listContent.split('.')[0]) > -1:
                        currentListClass = 'lower-roman';
                        break;
                    case this.lowerGreekNumber.indexOf(listContent.split('.')[0]) > -1:
                        currentListClass = 'lower-greek';
                        break;
                    case (charCode > 64 && charCode < 91):
                        currentListClass = 'upper-alpha';
                        break;
                    case (charCode > 96 && charCode < 123):
                        currentListClass = 'lower-alpha';
                        break;
                    case (listContent.split('.')[0].length > 1 && listContent.split('.')[0][0] === '0' && !isNaN(Number(listContent.split('.')[0]))):
                        currentListClass = 'decimal-leading-zero';
                        break;
                    default:
                        currentListClass = 'decimal';
                        break;
                }
            }
            else {
                switch (listContent.split('.')[0]) {
                    case 'o':
                        currentListClass = 'circle';
                        break;
                    case '§':
                        currentListClass = 'square';
                        break;
                    default:
                        currentListClass = 'disc';
                        break;
                }
            }
            return currentListClass;
        };
        MsWordPaste.prototype.makeConversion = function (collection) {
            var root = ej2_base_1.createElement('div');
            var temp;
            var pLevel = 1;
            var prevList;
            var listCount = 0;
            var elem;
            var lfo = collection[0].listFormatOverride;
            for (var index = 0; index < collection.length; index++) {
                var listClass = ['MsoListParagraphCxSpFirst', 'MsoListParagraphCxSpMiddle', 'MsoListParagraphCxSpLast'];
                var isNormalList = false;
                for (var i = 0; i < listClass.length; i++) {
                    if (listClass[i].indexOf(collection[index].class) >= 0) {
                        isNormalList = true;
                        break;
                    }
                }
                if (!ej2_base_1.isNullOrUndefined(prevList) && index !== 0 &&
                    collection[index - 1].listType !== collection[index].listType &&
                    !isNormalList) {
                    prevList = null;
                }
                var pElement = ej2_base_1.createElement('p', { className: 'MsoNoSpacing' });
                pElement.innerHTML = collection[index].content.join(' ');
                if ((collection[index].nestedLevel === 1) &&
                    (listCount === 0 || lfo !== collection[index].listFormatOverride) &&
                    collection[index].content) {
                    root.appendChild(temp = ej2_base_1.createElement(collection[index].listType, { className: collection[index].class }));
                    prevList = ej2_base_1.createElement('li');
                    prevList.appendChild(pElement);
                    temp.appendChild(prevList);
                    temp.setAttribute('level', collection[index].nestedLevel.toString());
                    if (collection[index].class !== 'msolistparagraph') {
                        temp.style.marginLeft = collection[index].styleMarginLeft;
                    }
                    else {
                        ej2_base_1.addClass([temp], 'marginLeftIgnore');
                    }
                    temp.style.listStyleType = collection[index].listStyleTypeName;
                }
                else if (collection[index].nestedLevel === pLevel &&
                    lfo === collection[index].listFormatOverride) {
                    Eif (!ej2_base_1.isNullOrUndefined(prevList) && !ej2_base_1.isNullOrUndefined(prevList.parentElement)
                        && prevList.parentElement.tagName.toLowerCase() === collection[index].listType) {
                        prevList.parentElement.appendChild(prevList = ej2_base_1.createElement('li'));
                        prevList.appendChild(pElement);
                    }
                    else if (ej2_base_1.isNullOrUndefined(prevList)) {
                        temp = ej2_base_1.createElement(collection[index].listType);
                        temp.style.listStyleType = collection[index].listStyleTypeName;
                        prevList = ej2_base_1.createElement('li');
                        prevList.appendChild(pElement);
                        temp.appendChild(prevList);
                        temp.setAttribute('level', collection[index].nestedLevel.toString());
                        root.appendChild(temp);
                    }
                    else {
                        temp = ej2_base_1.createElement(collection[index].listType);
                        temp.style.listStyleType = collection[index].listStyleTypeName;
                        prevList.parentElement.parentElement.appendChild(temp);
                        prevList = ej2_base_1.createElement('li');
                        prevList.appendChild(pElement);
                        temp.appendChild(prevList);
                        temp.setAttribute('level', collection[index].nestedLevel.toString());
                    }
                }
                else if (collection[index].nestedLevel > pLevel) {
                    if (!ej2_base_1.isNullOrUndefined(prevList)) {
                        for (var j = 0; j < collection[index].nestedLevel - pLevel; j++) {
                            prevList.appendChild(temp = ej2_base_1.createElement(collection[index].listType));
                            prevList = ej2_base_1.createElement('li');
                            if (j !== collection[index].nestedLevel - pLevel - 1 &&
                                collection[index].nestedLevel - pLevel > 1) {
                                prevList.style.listStyleType = 'none';
                            }
                            temp.appendChild(prevList);
                        }
                        prevList.appendChild(pElement);
                        temp.setAttribute('level', collection[index].nestedLevel.toString());
                        temp.style.listStyleType = collection[index].listStyleTypeName;
                    }
                    else {
                        if (collection[index].nestedLevel > pLevel && isNormalList) {
                            var initialNode = ej2_base_1.createElement(collection[index].listType);
                            prevList = ej2_base_1.createElement('li');
                            initialNode.appendChild(prevList);
                            initialNode.style.listStyleType = 'none';
                            for (var j = 0; j < collection[index].nestedLevel - 1; j++) {
                                prevList.appendChild(temp = ej2_base_1.createElement(collection[index].listType));
                                prevList = ej2_base_1.createElement('li');
                                temp.appendChild(prevList);
                                temp.style.listStyleType = 'none';
                            }
                            prevList.appendChild(pElement);
                            root.appendChild(initialNode);
                            temp.setAttribute('level', collection[index].nestedLevel.toString());
                            temp.style.listStyleType = collection[index].listStyleTypeName;
                        }
                        else {
                            root.appendChild(temp = ej2_base_1.createElement(collection[index].listType));
                            prevList = ej2_base_1.createElement('li');
                            prevList.appendChild(pElement);
                            temp.appendChild(prevList);
                            temp.setAttribute('level', collection[index].nestedLevel.toString());
                            Eif (collection[index].class !== 'msolistparagraph') {
                                temp.style.marginLeft = collection[index].styleMarginLeft;
                            }
                            else {
                                ej2_base_1.addClass([temp], 'marginLeftIgnore');
                            }
                            temp.style.listStyleType = collection[index].listStyleTypeName;
                        }
                    }
                }
                else if (collection[index].nestedLevel === 1) {
                    Eif (root.lastChild.tagName.toLowerCase() === collection[index].listType) {
                        temp = root.lastChild;
                    }
                    else {
                        root.appendChild(temp = ej2_base_1.createElement(collection[index].listType));
                        temp.style.listStyleType = collection[index].listStyleTypeName;
                    }
                    prevList = ej2_base_1.createElement('li');
                    prevList.appendChild(pElement);
                    temp.appendChild(prevList);
                    temp.setAttribute('level', collection[index].nestedLevel.toString());
                }
                else {
                    elem = prevList;
                    while (elem.parentElement) {
                        elem = elem.parentElement;
                        if (elem.attributes.getNamedItem('level')) {
                            if (parseInt(elem.attributes.getNamedItem('level').textContent, 10) === collection[index].nestedLevel &&
                                lfo === collection[index].listFormatOverride) {
                                prevList = ej2_base_1.createElement('li');
                                prevList.appendChild(pElement);
                                elem.appendChild(prevList);
                                break;
                            }
                            else Iif (parseInt(elem.attributes.getNamedItem('level').textContent, null) === collection[index].nestedLevel &&
                                lfo !== collection[index].listFormatOverride) {
                                temp = ej2_base_1.createElement(collection[index].listType);
                                prevList = ej2_base_1.createElement('li');
                                temp.appendChild(prevList);
                                if (collection[index].nestedLevel > 1) {
                                    for (var k = 0; k < collection[index].nestedLevel - 1; k++) {
                                        prevList.appendChild(temp = ej2_base_1.createElement(collection[index].listType));
                                        prevList = ej2_base_1.createElement('li');
                                        temp.appendChild(prevList);
                                        temp.style.listStyleType = 'none';
                                    }
                                }
                                prevList.appendChild(pElement);
                                elem.appendChild(temp);
                                temp.setAttribute('level', collection[index].nestedLevel.toString());
                                temp.style.listStyleType = collection[index].listStyleTypeName;
                                break;
                            }
                            else if (collection[index].nestedLevel > parseInt(elem.attributes.getNamedItem('level').textContent, 10)) {
                                elem.appendChild(temp = ej2_base_1.createElement(collection[index].listType));
                                prevList = ej2_base_1.createElement('li');
                                prevList.appendChild(pElement);
                                temp.appendChild(prevList);
                                temp.setAttribute('level', collection[index].nestedLevel.toString());
                                temp.style.listStyleType = collection[index].listStyleTypeName;
                                break;
                            }
                        }
                        continue;
                    }
                }
                prevList.setAttribute('class', collection[index].class);
                prevList.setAttribute('style', (!ej2_base_1.isNullOrUndefined(collection[index].listStyle) ? collection[index].listStyle : ''));
                pLevel = collection[index].nestedLevel;
                lfo = collection[index].listFormatOverride;
                listCount++;
                if (!ej2_base_1.isNullOrUndefined(collection[index].start && collection[index].start !== 1 && collection[index].listType === 'ol')) {
                    temp.setAttribute('start', collection[index].start.toString());
                }
            }
            return root;
        };
        MsWordPaste.prototype.getListContent = function (elem) {
            var pushContent = '';
            var firstChild = elem.firstElementChild;
            Iif (firstChild.textContent.trim() === '' && !ej2_base_1.isNullOrUndefined(firstChild.firstElementChild) &&
                firstChild.firstElementChild.nodeName === 'IMG') {
                pushContent = elem.innerHTML.trim();
                this.listContents.push('');
                this.listContents.push(pushContent);
            }
            else {
                Eif (firstChild.childNodes.length > 0) {
                    var listIgnoreTag = firstChild.querySelectorAll('[style*="mso-list"]');
                    for (var i = 0; i < listIgnoreTag.length; i++) {
                        listIgnoreTag[i].setAttribute('style', listIgnoreTag[i].getAttribute('style').replace(/\n/g, ''));
                    }
                    var listOrderCleanup = firstChild.querySelector('span[style*="mso-list"]');
                    Eif (listOrderCleanup) {
                        var style = listOrderCleanup.getAttribute('style');
                        Eif (style) {
                            style = style.replace(/\s*:\s*/g, ':');
                            listOrderCleanup.setAttribute('style', style);
                        }
                    }
                    var listOrder = firstChild.querySelector('span[style="mso-list:Ignore"]');
                    Eif (!ej2_base_1.isNullOrUndefined(listOrder)) {
                        this.listContents.push(listOrder.textContent.trim());
                        ej2_base_1.detach(listOrder);
                        this.removingComments(elem);
                        this.removeUnwantedElements(elem);
                    }
                }
            }
            this.listContents.push(elem.innerHTML);
        };
        MsWordPaste.prototype.processMargin = function (element) {
            var liChildren = element.querySelectorAll('li');
            if (liChildren.length > 0) {
                for (var i = 0; i < liChildren.length; i++) {
                    if (!ej2_base_1.isNullOrUndefined((liChildren[i]).style.marginLeft) && !liChildren[i].parentElement.classList.contains('marginLeftIgnore')) {
                        (liChildren[i]).style.marginLeft = '';
                    }
                }
            }
            var tableChildren = element.querySelectorAll('table');
            if (tableChildren.length > 0) {
                for (var i = 0; i < tableChildren.length; i++) {
                    if (!ej2_base_1.isNullOrUndefined((tableChildren[i]).style.marginLeft) &&
                        (tableChildren[i]).style.marginLeft.indexOf('-') >= 0) {
                        (tableChildren[i]).style.marginLeft = '';
                    }
                }
            }
            var ignoredNode = element.querySelectorAll('.marginLeftIgnore li');
            if (ignoredNode.length > 0) {
                for (var i = 0; i < ignoredNode.length; i++) {
                    Eif (!ej2_base_1.isNullOrUndefined((ignoredNode[i]).style.marginLeft) && (ignoredNode[i]).style.marginLeft !== '') {
                        var marginLeft = (ignoredNode[i]).style.marginLeft;
                        var marginLeftValue = parseFloat(marginLeft.split('in')[0]);
                        var result = marginLeftValue - 0.5;
                        (ignoredNode[i]).style.marginLeft = result.toString() + 'in';
                    }
                }
            }
        };
        MsWordPaste.prototype.removeEmptyAnchorTag = function (element) {
            var removableElement = element.querySelectorAll('a:not([href])');
            for (var j = removableElement.length - 1; j >= 0; j--) {
                var parentElem = removableElement[j].parentNode;
                while (removableElement[j].firstChild) {
                    parentElem.insertBefore(removableElement[j].firstChild, removableElement[j]);
                }
                parentElem.removeChild(removableElement[j]);
            }
        };
        MsWordPaste.prototype.findSource = function (element) {
            var metaNodes = element.querySelectorAll('meta');
            for (var i = 0; i < metaNodes.length; i++) {
                var metaNode = metaNodes[i];
                var content = metaNode.getAttribute('content');
                var name_1 = metaNode.getAttribute('name');
                if (name_1 && name_1.toLowerCase().indexOf('generator') >= 0 && content && content.toLowerCase().indexOf('microsoft') >= 0) {
                    for (var j = 0; j < constant_1.PASTE_SOURCE.length; j++) {
                        if (content.toLowerCase().indexOf(constant_1.PASTE_SOURCE[j]) >= 0) {
                            return constant_1.PASTE_SOURCE[j];
                        }
                    }
                }
            }
            return 'html';
        };
        MsWordPaste.prototype.handleOneNoteContent = function (element) {
            var allListElements = element.querySelectorAll('ul, ol');
            Eif (allListElements.length > 0) {
                for (var i = 0; i < allListElements.length; i++) {
                    var currentList = allListElements[i];
                    Eif (currentList.querySelectorAll('li').length === 0 && currentList.childNodes.length > 0) {
                        insert_methods_1.InsertMethods.unwrap(currentList);
                    }
                }
            }
        };
        MsWordPaste.prototype.destroy = function () {
            this.removeEventListener();
        };
        return MsWordPaste;
    }());
    exports.MsWordPaste = MsWordPaste;
});