all files / pdfviewer/drawing/ tools.js

11.21% Statements 139/1240
1.14% Branches 11/967
18.18% Functions 18/99
11% Lines 136/1236
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "@syncfusion/ej2-drawings", "@syncfusion/ej2-drawings", "@syncfusion/ej2-drawings", "@syncfusion/ej2-drawings", "@syncfusion/ej2-drawings", "./selector", "./action", "./drawing-util", "@syncfusion/ej2-base", "./connector-util", "@syncfusion/ej2-base"], function (require, exports, ej2_drawings_1, ej2_drawings_2, ej2_drawings_3, ej2_drawings_4, ej2_drawings_5, selector_1, action_1, drawing_util_1, ej2_base_1, connector_util_1, ej2_base_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ToolBase = (function () {
        function ToolBase(pdfViewer, pdfViewerBase, protectChange) {
            if (protectChange === void 0) { protectChange = false; }
            this.commandHandler = null;
            this.inAction = false;
            this.pdfViewerBase = null;
            this.currentElement = null;
            this.blocked = false;
            this.isTooltipVisible = false;
            this.childTable = {};
            this.helper = undefined;
            this.undoElement = { annotations: [] };
            this.undoParentElement = { annotations: [] };
            this.commandHandler = pdfViewer;
            this.pdfViewerBase = pdfViewerBase;
        }
        ToolBase.prototype.startAction = function (currentElement) {
            this.currentElement = currentElement;
            this.inAction = true;
        };
        ToolBase.prototype.mouseDown = function (args) {
            this.currentElement = args.source;
            this.startPosition = this.currentPosition = this.prevPosition = args.position;
            this.isTooltipVisible = true;
            this.startAction(args.source);
        };
        ToolBase.prototype.mouseMove = function (args) {
            this.currentPosition = args.position;
            this.prevPageId = this.pdfViewerBase.activeElements.activePageID;
            return !this.blocked;
        };
        ToolBase.prototype.mouseUp = function (args) {
            this.currentPosition = args.position;
            this.isTooltipVisible = false;
            this.endAction();
            this.helper = null;
        };
        ToolBase.prototype.endAction = function () {
            if (this.commandHandler) {
                this.commandHandler.tool = '';
                if (this.helper) {
                    this.commandHandler.remove(this.helper);
                }
            }
            this.commandHandler = null;
            this.currentElement = null;
            this.currentPosition = null;
            this.inAction = false;
            this.blocked = false;
        };
        ToolBase.prototype.mouseWheel = function (args) {
            this.currentPosition = args.position;
        };
        ToolBase.prototype.mouseLeave = function (args) {
            this.mouseUp(args);
        };
        ToolBase.prototype.updateSize = function (shape, startPoint, endPoint, corner, initialBounds, angle, isMouseUp) {
            var zoom = this.commandHandler.viewerBase.getZoomFactor();
            var difx = this.currentPosition.x / zoom - this.startPosition.x / zoom;
            var dify = this.currentPosition.y / zoom - this.startPosition.y / zoom;
            var rotateAngle = (shape instanceof ej2_drawings_5.TextElement) ? angle : shape.rotateAngle;
            var matrix = ej2_drawings_4.identityMatrix();
            ej2_drawings_4.rotateMatrix(matrix, -rotateAngle, 0, 0);
            var deltaWidth = 0;
            var deltaHeight = 0;
            var diff;
            var width = (shape instanceof ej2_drawings_5.TextElement) ? shape.actualSize.width : shape.wrapper.bounds.width;
            var height = (shape instanceof ej2_drawings_5.TextElement) ? shape.actualSize.height : shape.wrapper.bounds.height;
            var obj = shape;
            if (!shape.formFieldAnnotationType) {
                if (!shape.annotName && !shape.shapeAnnotationType) {
                    if (shape) {
                        obj = shape.annotations[0];
                    }
                }
            }
            var annotationSettings = this.commandHandler.annotationModule ?
                this.commandHandler.annotationModule.findAnnotationSettings(obj) : {};
            var annotationMaxHeight = 0;
            var annotationMaxWidth = 0;
            var annotationMinHeight = 0;
            var annotationMinWidth = 0;
            if (annotationSettings.minWidth || annotationSettings.maxWidth || annotationSettings.minHeight || annotationSettings.maxHeight) {
                annotationMaxHeight = annotationSettings.maxHeight ? annotationSettings.maxHeight : 2000;
                annotationMaxWidth = annotationSettings.maxWidth ? annotationSettings.maxWidth : 2000;
                annotationMinHeight = annotationSettings.minHeight ? annotationSettings.minHeight : 0;
                annotationMinWidth = annotationSettings.minWidth ? annotationSettings.minWidth : 0;
            }
            var isAnnotationSet = false;
            if (annotationMinHeight || annotationMinWidth || annotationMaxHeight || annotationMaxWidth) {
                isAnnotationSet = true;
            }
            if (isAnnotationSet && isMouseUp) {
                var size = this.getPositions(corner, difx, dify);
                var newWidth = width + size.x;
                var newHeight = height + size.y;
                if (newHeight < annotationMinHeight) {
                    dify = annotationMinHeight - height;
                }
                else if (newHeight > annotationMaxHeight) {
                    dify = annotationMaxHeight - height;
                }
                if (newWidth < annotationMinWidth) {
                    difx = annotationMinWidth - width;
                }
                else if (newWidth > annotationMaxWidth) {
                    difx = annotationMaxWidth - width;
                }
            }
            switch (corner) {
                case 'ResizeWest':
                    diff = ej2_drawings_4.transformPointByMatrix(matrix, ({ x: difx, y: dify }));
                    difx = diff.x;
                    dify = diff.y;
                    deltaHeight = 1;
                    dify = 0;
                    if (isAnnotationSet) {
                        if (initialBounds.width - difx > annotationMaxWidth) {
                            difx = annotationMaxWidth - initialBounds.width;
                        }
                    }
                    deltaWidth = (initialBounds.width - difx) / width;
                    break;
                case 'ResizeEast':
                    diff = ej2_drawings_4.transformPointByMatrix(matrix, ({ x: difx, y: dify }));
                    difx = diff.x;
                    dify = diff.y;
                    dify = 0;
                    if (isAnnotationSet) {
                        if (initialBounds.width + difx > annotationMaxWidth) {
                            difx = annotationMaxWidth - initialBounds.width;
                        }
                    }
                    deltaWidth = (initialBounds.width + difx) / width;
                    deltaHeight = 1;
                    break;
                case 'ResizeNorth':
                    deltaWidth = 1;
                    diff = ej2_drawings_4.transformPointByMatrix(matrix, ({ x: difx, y: dify }));
                    difx = diff.x;
                    dify = diff.y;
                    if (isAnnotationSet) {
                        if (initialBounds.height - dify > annotationMaxHeight) {
                            dify = annotationMaxHeight - initialBounds.height;
                        }
                    }
                    deltaHeight = (initialBounds.height - dify) / height;
                    break;
                case 'ResizeSouth':
                    deltaWidth = 1;
                    diff = ej2_drawings_4.transformPointByMatrix(matrix, ({ x: difx, y: dify }));
                    difx = diff.x;
                    dify = diff.y;
                    if (isAnnotationSet) {
                        if (initialBounds.height + dify > annotationMaxHeight) {
                            dify = annotationMaxHeight - initialBounds.height;
                        }
                    }
                    deltaHeight = (initialBounds.height + dify) / height;
                    break;
                case 'ResizeNorthEast':
                    diff = ej2_drawings_4.transformPointByMatrix(matrix, ({ x: difx, y: dify }));
                    difx = diff.x;
                    dify = diff.y;
                    if (isAnnotationSet) {
                        if (initialBounds.width + difx > annotationMaxWidth) {
                            difx = annotationMaxWidth - initialBounds.width;
                        }
                        if (initialBounds.height - dify > annotationMaxHeight) {
                            dify = annotationMaxHeight - initialBounds.height;
                        }
                    }
                    deltaWidth = (initialBounds.width + difx) / width;
                    deltaHeight = (initialBounds.height - dify) / height;
                    break;
                case 'ResizeNorthWest':
                    diff = ej2_drawings_4.transformPointByMatrix(matrix, ({ x: difx, y: dify }));
                    difx = diff.x;
                    dify = diff.y;
                    if (isAnnotationSet) {
                        if (initialBounds.width - difx > annotationMaxWidth) {
                            difx = annotationMaxWidth - initialBounds.width;
                        }
                        if (initialBounds.height - dify > annotationMaxHeight) {
                            dify = annotationMaxHeight - initialBounds.height;
                        }
                    }
                    deltaWidth = (initialBounds.width - difx) / width;
                    deltaHeight = (initialBounds.height - dify) / height;
                    break;
                case 'ResizeSouthEast':
                    diff = ej2_drawings_4.transformPointByMatrix(matrix, ({ x: difx, y: dify }));
                    difx = diff.x;
                    dify = diff.y;
                    if (isAnnotationSet) {
                        if (initialBounds.width + difx > annotationMaxWidth) {
                            difx = annotationMaxWidth - initialBounds.width;
                        }
                        if (initialBounds.height + dify > annotationMaxHeight) {
                            dify = annotationMaxHeight - initialBounds.height;
                        }
                    }
                    deltaHeight = (initialBounds.height + dify) / height;
                    deltaWidth = (initialBounds.width + difx) / width;
                    break;
                case 'ResizeSouthWest':
                    diff = ej2_drawings_4.transformPointByMatrix(matrix, ({ x: difx, y: dify }));
                    difx = diff.x;
                    dify = diff.y;
                    if (isAnnotationSet) {
                        if (initialBounds.width - difx > annotationMaxWidth) {
                            difx = annotationMaxWidth - initialBounds.width;
                        }
                        if (initialBounds.height + dify > annotationMaxHeight) {
                            dify = annotationMaxHeight - initialBounds.height;
                        }
                    }
                    deltaWidth = (initialBounds.width - difx) / width;
                    deltaHeight = (initialBounds.height + dify) / height;
                    break;
            }
            return { width: deltaWidth, height: deltaHeight };
        };
        ToolBase.prototype.getPivot = function (corner) {
            switch (corner) {
                case 'ResizeWest':
                    return { x: 1, y: 0.5 };
                case 'ResizeEast':
                    return { x: 0, y: 0.5 };
                case 'ResizeNorth':
                    return { x: 0.5, y: 1 };
                case 'ResizeSouth':
                    return { x: 0.5, y: 0 };
                case 'ResizeNorthEast':
                    return { x: 0, y: 1 };
                case 'ResizeNorthWest':
                    return { x: 1, y: 1 };
                case 'ResizeSouthEast':
                    return { x: 0, y: 0 };
                case 'ResizeSouthWest':
                    return { x: 1, y: 0 };
            }
            return { x: 0.5, y: 0.5 };
        };
        ToolBase.prototype.getPositions = function (corner, x, y) {
            switch (corner) {
                case 'ResizeEast':
                    return { x: x, y: 0 };
                case 'ResizeSouthEast':
                    return { x: x, y: y };
                case 'ResizeSouth':
                    return { x: 0, y: y };
                case 'ResizeNorth':
                    return { x: 0, y: -y };
                case 'ResizeNorthEast':
                    return { x: x, y: -y };
                case 'ResizeNorthWest':
                    return { x: -x, y: -y };
                case 'ResizeWest':
                    return { x: -x, y: 0 };
                case 'ResizeSouthWest':
                    return { x: -x, y: y };
            }
            return { x: x, y: y };
        };
        return ToolBase;
    }());
    exports.ToolBase = ToolBase;
    var SelectTool = (function (_super) {
        __extends(SelectTool, _super);
        function SelectTool(commandHandler, base) {
            return _super.call(this, commandHandler, base, true) || this;
        }
        SelectTool.prototype.mouseDown = function (args) {
            this.inAction = true;
            this.mouseEventHelper(args);
            _super.prototype.mouseDown.call(this, args);
        };
        SelectTool.prototype.mouseEventHelper = function (args) {
            if (this.commandHandler && this.commandHandler.annotationModule) {
                this.commandHandler.annotationModule.overlappedCollections =
                    action_1.findActiveElement(args, this.pdfViewerBase, this.commandHandler, true);
            }
            var object = action_1.findActiveElement(args, this.pdfViewerBase, this.commandHandler);
            var isLock = false;
            if (object && object.shapeAnnotationType === 'StickyNotes') {
                if (object.annotationSettings && object.annotationSettings.isLock) {
                    if (this.commandHandler.annotationModule.checkAllowedInteractions('Select', object)) {
                        isLock = false;
                    }
                    else {
                        isLock = true;
                    }
                }
            }
            if (!isLock) {
                var currentSelctor = void 0;
                if (args.source && args.annotationSelectorSettings !== null) {
                    currentSelctor = args.source.annotationSelectorSettings;
                }
                else {
                    currentSelctor = '';
                }
                if (this.commandHandler) {
                    var selectedObject = this.commandHandler.selectedItems;
                    if (selectedObject) {
                        var annotation = selectedObject.annotations[0];
                        var formField = selectedObject.formFields[0];
                        var currentAnnot = this.commandHandler.selectedItems.annotations[0];
                        var currentSource = args.source;
                        if ((selectedObject.annotations.length) && args.info && !args.info.ctrlKey
                            && this.commandHandler.annotationModule &&
                            this.commandHandler.annotationModule.freeTextAnnotationModule.isInuptBoxInFocus === false) {
                            this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                        }
                        else if (args.info && args.info.ctrlKey && ((currentSource && currentSource.shapeAnnotationType === 'FreeText') || (currentAnnot && currentAnnot.shapeAnnotationType === 'FreeText'))) {
                            this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                        }
                        else if (ej2_base_1.isNullOrUndefined(object) && (this.commandHandler.annotationModule && !ej2_base_1.isNullOrUndefined(this.commandHandler.annotation.textMarkupAnnotationModule) && ej2_base_1.isNullOrUndefined(this.commandHandler.annotation.textMarkupAnnotationModule.currentTextMarkupAnnotation)) && this.commandHandler.formDesignerModule && !((currentSource && currentSource.shapeAnnotationType === 'FreeText') || (currentAnnot && (currentAnnot.shapeAnnotationType === 'FreeText' || currentAnnot.shapeAnnotationType === 'Image' || currentAnnot.shapeAnnotationType === 'StickyNotes')))) {
                            this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                        }
                        if (object) {
                            if ((ej2_base_1.isNullOrUndefined(formField) || (formField &&
                                formField.id !== object.id)) &&
                                !ej2_base_1.isNullOrUndefined(this.pdfViewerBase.isFreeTextSelected) && !this.pdfViewerBase.isFreeTextSelected) {
                                this.commandHandler.select([object.id], currentSelctor);
                                this.commandHandler.viewerBase.isAnnotationMouseDown = true;
                            }
                            this.pdfViewerBase.isFreeTextSelected = false;
                            this.commandHandler.viewerBase.isFormFieldMouseDown = true;
                        }
                        if (selectedObject.annotations.length === 0 && annotation && annotation.shapeAnnotationType !== 'HandWrittenSignature' && annotation.shapeAnnotationType !== 'SignatureText' && annotation.shapeAnnotationType !== 'SignatureImage' && annotation.shapeAnnotationType !== 'Path' && !annotation.formFieldAnnotationType) {
                            if (this.commandHandler.enableToolbar && ej2_base_2.Browser.isDevice && !this.commandHandler.enableDesktopMode) {
                                this.commandHandler.toolbarModule.showToolbar(true);
                            }
                            this.commandHandler.fireAnnotationUnSelect(annotation.annotName, annotation.pageIndex, annotation);
                        }
                        if (selectedObject.annotations.length === 0 && annotation && (annotation.shapeAnnotationType === 'HandWrittenSignature' || annotation.shapeAnnotationType === 'SignatureText' || annotation.shapeAnnotationType === 'SignatureImage' || annotation.shapeAnnotationType === 'Path' || annotation.signatureType)) {
                            this.commandHandler.fireSignatureUnselect(annotation.signatureName, annotation.pageIndex, annotation);
                        }
                        if (selectedObject.formFields.length === 0 && this.commandHandler.formDesignerModule &&
                            formField && formField.formFieldAnnotationType) {
                            var field = { name: formField.name, id: formField.id,
                                value: formField.value, fontFamily: formField.fontFamily, fontSize: formField.fontSize,
                                fontStyle: formField.fontStyle,
                                color: formField.color,
                                backgroundColor: formField.backgroundColor,
                                alignment: formField.alignment, isReadonly: formField.isReadOnly,
                                visibility: formField.visibility,
                                maxLength: formField.maxLength, isRequired: formField.isRequired,
                                isPrint: formField.isPrint, rotation: formField.rotation, tooltip: formField.tooltip,
                                options: formField.options, isChecked: formField.isChecked,
                                isSelected: formField.isSelected };
                            this.commandHandler.fireFormFieldUnselectEvent('formFieldUnselect', field, formField.pageIndex);
                        }
                        else if (this.pdfViewerBase.currentTarget && this.pdfViewerBase.currentTarget.id && this.commandHandler.formFields && event.type === 'mousedown') {
                            for (var i = 0; i < this.commandHandler.formFields.length; i++) {
                                var formField_1 = this.commandHandler.formFields[parseInt(i.toString(), 10)];
                                if (this.pdfViewerBase.currentTarget && this.pdfViewerBase.currentTarget.id === formField_1.id) {
                                    var field = {
                                        value: formField_1.value, fontFamily: formField_1.fontFamily, fontSize: formField_1.fontSize,
                                        fontStyle: formField_1.fontStyle, color: formField_1.color,
                                        backgroundColor: formField_1.backgroundColor, alignment: formField_1.alignment,
                                        isReadonly: formField_1.isReadonly, visibility: formField_1.visibility,
                                        maxLength: formField_1.maxLength, isRequired: formField_1.isRequired,
                                        isPrint: formField_1.isPrint, rotation: formField_1.rotateAngle,
                                        tooltip: formField_1.tooltip,
                                        options: formField_1.options, isChecked: formField_1.isChecked,
                                        isSelected: formField_1.isSelected
                                    };
                                    if (!object) {
                                        this.commandHandler.fireFocusOutFormField(field, formField_1.pageIndex);
                                        this.pdfViewerBase.currentTarget = null;
                                    }
                                    else {
                                        if (this.pdfViewerBase.currentTarget.id !== event.target.id && event.target.className !== 'e-pv-text-layer') {
                                            this.commandHandler.fireFocusOutFormField(field, formField_1.pageIndex);
                                            this.pdfViewerBase.currentTarget = null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        };
        SelectTool.prototype.mouseMove = function (args) {
            _super.prototype.mouseMove.call(this, args);
            return !this.blocked;
        };
        SelectTool.prototype.mouseUp = function (args) {
            this.mouseEventHelper(args);
            this.inAction = false;
            _super.prototype.mouseUp.call(this, args);
        };
        SelectTool.prototype.mouseLeave = function (args) {
            if (this.inAction) {
                this.mouseUp(args);
            }
        };
        return SelectTool;
    }(ToolBase));
    exports.SelectTool = SelectTool;
    var MoveTool = (function (_super) {
        __extends(MoveTool, _super);
        function MoveTool(commandHandler, base) {
            var _this = _super.call(this, commandHandler, base) || this;
            _this.currentTarget = null;
            _this.prevNode = null;
            return _this;
        }
        MoveTool.prototype.mouseDown = function (args) {
            _super.prototype.mouseDown.call(this, args);
            this.offset = { x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY };
            this.startPosition = args.position;
            var nodeMouseDown = drawing_util_1.cloneObject(args.source);
            this.redoElement = {
                bounds: {
                    x: nodeMouseDown.wrapper.offsetX, y: nodeMouseDown.wrapper.offsetY,
                    width: nodeMouseDown.wrapper.actualSize.width, height: nodeMouseDown.wrapper.actualSize.height
                }
            };
            if (drawing_util_1.isLineShapes(nodeMouseDown)) {
                this.redoElement.vertexPoints = nodeMouseDown.vertexPoints;
                this.redoElement.leaderHeight = nodeMouseDown.leaderHeight;
            }
            this.inAction = true;
        };
        MoveTool.prototype.mouseUp = function (args) {
            if (this.commandHandler && args.source) {
                this.checkisAnnotationMove(args);
                var isDragged = false;
                var currentSelctor = args.source.annotationSelectorSettings;
                this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                this.commandHandler.select([args.source.id], currentSelctor);
                if (this.pdfViewerBase.activeElements.activePageID === args.source.pageIndex) {
                    this.commandHandler.dragSelectedObjects(this.calculateMouseActionXDiff(args), this.calculateMouseActionYDiff(args), this.pdfViewerBase.activeElements.activePageID, currentSelctor, null);
                }
                if (args.source && (args.source.formFieldAnnotationType === 'Textbox' || args.source.formFieldAnnotationType === 'Checkbox'
                    || args.source.formFieldAnnotationType === 'RadioButton' || args.source.formFieldAnnotationType === 'ListBox'
                    || args.source.formFieldAnnotationType === 'SignatureField' || args.source.formFieldAnnotationType === 'InitialField' || args.source.formFieldAnnotationType === 'DropdownList'
                    || args.source.formFieldAnnotationType === 'PasswordField')) {
                    this.commandHandler.formDesignerModule.updateHTMLElement(args.source);
                }
                this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelctor);
                this.commandHandler.viewerBase.isAnnotationMouseMove = false;
                this.commandHandler.viewerBase.isFormFieldMouseMove = false;
                var newShapeObject = {
                    bounds: {
                        x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY,
                        width: args.source.wrapper.actualSize.width, height: args.source.wrapper.actualSize.height
                    }, modifiedDate: args.source.modifiedDate
                };
                if (drawing_util_1.isLineShapes(args.source)) {
                    newShapeObject.vertexPoints = args.source.vertexPoints;
                    newShapeObject.leaderHeight = args.source.leaderHeight;
                }
                if (args.target && args.target.formFieldAnnotationType) {
                    var node = args.target;
                    var field = {
                        value: node.value, fontFamily: node.fontFamily, fontSize: node.fontSize, fontStyle: node.fontStyle,
                        color: node.color, backgroundColor: node.backgroundColor,
                        borderColor: node.borderColor,
                        thickness: node.thickness, alignment: node.alignment,
                        isReadonly: node.isReadonly, visibility: node.visibility,
                        maxLength: node.maxLength, isRequired: node.isRequired, isPrint: node.isPrint,
                        rotation: node.rotateAngle, tooltip: node.tooltip, options: node.options,
                        isChecked: node.isChecked, isSelected: node.isSelected
                    };
                    var currentPosition = { X: args.source.wrapper.offsetX, Y: args.source.wrapper.offsetY,
                        Width: args.source.wrapper.actualSize.width, Height: args.source.wrapper.actualSize.height };
                    var previousPosition = { X: this.offset.x, Y: this.offset.y,
                        Width: args.source.wrapper.actualSize.width, Height: args.source.wrapper.actualSize.height };
                    this.commandHandler.fireFormFieldMoveEvent('formFieldMove', field, node.pageIndex, previousPosition, currentPosition);
                }
                if (!ej2_base_1.isNullOrUndefined(this.redoElement) && (this.redoElement.bounds.height !== newShapeObject.bounds.height ||
                    this.redoElement.bounds.width !== newShapeObject.bounds.width || this.redoElement.bounds.x !==
                    newShapeObject.bounds.x || this.redoElement.bounds.y !== newShapeObject.bounds.y)) {
                    isDragged = true;
                }
                if (this.commandHandler.annotation && isDragged) {
                    this.commandHandler.annotation.addAction(this.pageIndex, null, args.source, 'Drag', '', this.redoElement, newShapeObject);
                    this.commandHandler.annotation.stampAnnotationModule.updateSessionStorage(args.source, null, 'Drag');
                    this.commandHandler.annotation.stickyNotesAnnotationModule.updateStickyNotes(args.source, null);
                }
            }
            var shapeAnnotationType = this.commandHandler && this.commandHandler.selectedItems &&
                this.commandHandler.selectedItems.annotations && this.commandHandler.selectedItems.annotations.length > 0 ?
                this.commandHandler.selectedItems.annotations[0].shapeAnnotationType : null;
            if (shapeAnnotationType && shapeAnnotationType !== 'Image' && shapeAnnotationType !== 'SignatureImage') {
                _super.prototype.mouseUp.call(this, args);
            }
            else if (shapeAnnotationType === 'Image' || shapeAnnotationType === 'SignatureImage') {
                this.inAction = false;
            }
            else if (this.commandHandler && this.commandHandler.selectedItems && this.commandHandler.selectedItems.formFields &&
                this.commandHandler.selectedItems.formFields.length > 0) {
                _super.prototype.mouseUp.call(this, args);
            }
        };
        MoveTool.prototype.calculateMouseXDiff = function () {
            if (this.currentPosition && this.startPosition) {
                return this.currentPosition.x - this.startPosition.x;
            }
            else {
                return 0;
            }
        };
        MoveTool.prototype.calculateMouseYDiff = function () {
            if (this.currentPosition && this.startPosition) {
                return this.currentPosition.y - this.startPosition.y;
            }
            else {
                return 0;
            }
        };
        MoveTool.prototype.calculateMouseActionXDiff = function (args) {
            var x = this.calculateMouseXDiff() / this.commandHandler.viewerBase.getZoomFactor();
            if (this.offset) {
                var requiredX = this.offset.x + x;
                return requiredX - args.source.wrapper.offsetX;
            }
            else {
                return 0;
            }
        };
        MoveTool.prototype.calculateMouseActionYDiff = function (args) {
            var y = this.calculateMouseYDiff() / this.commandHandler.viewerBase.getZoomFactor();
            if (this.offset) {
                var requiredY = this.offset.y + y;
                return requiredY - args.source.wrapper.offsetY;
            }
            else {
                return 0;
            }
        };
        MoveTool.prototype.mouseMove = function (args, isStamp, isSkip) {
            _super.prototype.mouseMove.call(this, args);
            if (this.inAction) {
                this.currentPosition = args.position;
                this.currentTarget = args.target;
                var currentSelctor = args.source.annotationSelectorSettings;
                var x = this.calculateMouseXDiff() / this.commandHandler.viewerBase.getZoomFactor();
                var y = this.calculateMouseYDiff() / this.commandHandler.viewerBase.getZoomFactor();
                var requiredX = this.offset.x + x;
                var requiredY = this.offset.y + y;
                var diffX = this.calculateMouseActionXDiff(args);
                var diffY = this.calculateMouseActionYDiff(args);
                var selectedItem = this.commandHandler.selectedItems.annotations[0];
                var cobject = void 0;
                if (!this.helper) {
                    cobject = this.commandHandler.selectedItems.annotations.length > 0 ?
                        drawing_util_1.cloneObject(this.commandHandler.selectedItems.annotations[0]) :
                        drawing_util_1.cloneObject(this.commandHandler.selectedItems.formFields[0]);
                    if (cobject.wrapper) {
                        diffX = requiredX - cobject.wrapper.offsetX;
                        diffY = requiredY - cobject.wrapper.offsetY;
                        cobject.bounds = this.commandHandler.selectedItems.annotations.length > 0 ?
                            this.commandHandler.selectedItems.annotations[0].wrapper.bounds :
                            this.commandHandler.selectedItems.formFields[0].wrapper.bounds;
                    }
                    cobject.wrapper = undefined;
                    cobject.id = 'diagram_helper';
                    if (cobject.shapeAnnotationType === 'Stamp') {
                        cobject.strokeColor = '';
                        cobject.borderDashArray = '';
                        cobject.fillColor = 'transparent';
                        cobject.stampFillColor = 'transparent';
                        cobject.data = '';
                    }
                    else if (cobject.shapeAnnotationType === 'FreeText') {
                        cobject.strokeColor = 'blue';
                        cobject.fillColor = 'transparent';
                        cobject.thickness = 1;
                        cobject.opacity = 1;
                        cobject.dynamicText = '';
                    }
                    else if (cobject.shapeAnnotationType === 'SignatureText') {
                        cobject.strokeColor = 'red';
                        cobject.borderDashArray = '5,5';
                        cobject.fillColor = 'transparent';
                        cobject.thickness = 2;
                        cobject.opacity = 1;
                        cobject.data = '';
                    }
                    else {
                        cobject.strokeColor = 'red';
                        cobject.borderDashArray = '5,5';
                        cobject.fillColor = 'transparent';
                        cobject.thickness = 2;
                        cobject.opacity = 1;
                    }
                    if (cobject.enableShapeLabel === true) {
                        cobject.labelContent = '';
                    }
                    var shapeAnnotationType = cobject.shapeAnnotationType;
                    if (!isStamp && shapeAnnotationType !== 'Image' && shapeAnnotationType !== 'SignatureImage') {
                        this.helper = cobject = this.commandHandler.add(cobject);
                    }
                    else {
                        cobject = this.helper = args.source;
                    }
                    if (this.commandHandler.selectedItems.annotations.length > 0) {
                        this.commandHandler.selectedItems.annotations = [cobject];
                    }
                    else {
                        this.commandHandler.selectedItems.formFields = [cobject];
                    }
                }
                else {
                    diffX = requiredX - this.helper.wrapper.offsetX;
                    diffY = requiredY - this.helper.wrapper.offsetY;
                }
                if (this.helper && this.helper.shapeAnnotationType === 'Stamp') {
                    isStamp = true;
                }
                if (this.commandHandler.checkBoundaryConstraints(diffX, diffY, this.pdfViewerBase.activeElements.activePageID, this.helper.wrapper.bounds, isStamp, isSkip)) {
                    var shapeAnnotationType = this.helper.shapeAnnotationType;
                    if (this.helper && (shapeAnnotationType === 'Image' || shapeAnnotationType === 'SignatureImage')) {
                        this.checkisAnnotationMove(args);
                        var currentSelctor_1 = args.source.annotationSelectorSettings;
                        this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                        this.commandHandler.select([args.source.id], currentSelctor_1);
                        this.commandHandler.dragSelectedObjects(diffX, diffY, this.pdfViewerBase.activeElements.activePageID, currentSelctor_1, this.helper);
                        this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelctor_1);
                    }
                    else {
                        this.commandHandler.dragSelectedObjects(diffX, diffY, this.pdfViewerBase.activeElements.activePageID, currentSelctor, this.helper);
                    }
                    this.prevNode = this.helper;
                    this.prevPosition = this.currentPosition;
                }
                else {
                    this.currentPosition = this.prevPosition;
                }
                if (selectedItem && selectedItem.annotName) {
                    this.commandHandler.annotation.triggerAnnotationMove(selectedItem, true);
                }
            }
            return true;
        };
        MoveTool.prototype.mouseLeave = function (args) {
            var currentSelctor = args.source.annotationSelectorSettings;
            var requiredX = this.offset.x + this.calculateMouseXDiff();
            var requiredY = this.offset.y + this.calculateMouseYDiff();
            var diffX = requiredX - args.source.wrapper.offsetX;
            var diffY = requiredY - args.source.wrapper.offsetY;
            this.commandHandler.dragSelectedObjects(diffX, diffY, this.prevPageId, currentSelctor, null);
            this.commandHandler.renderSelector(this.prevPageId, currentSelctor);
            _super.prototype.mouseLeave.call(this, args);
        };
        MoveTool.prototype.endAction = function () {
            _super.prototype.endAction.call(this);
            this.currentTarget = null;
            this.prevPosition = null;
        };
        MoveTool.prototype.checkisAnnotationMove = function (args) {
            if (this.commandHandler.selectedItems && this.commandHandler.selectedItems.annotations &&
                this.commandHandler.selectedItems.annotations.length > 0) {
                if (this.commandHandler.selectedItems.annotations[0].annotName === args.source.annotName) {
                    this.commandHandler.viewerBase.isAnnotationMouseMove = true;
                }
            }
            else {
                this.commandHandler.viewerBase.isAnnotationMouseMove = false;
            }
            if (this.commandHandler.selectedItems && this.commandHandler.selectedItems.formFields &&
                this.commandHandler.selectedItems.formFields.length > 0) {
                if (this.commandHandler.selectedItems.formFields[0].name === args.source.name) {
                    this.commandHandler.viewerBase.isFormFieldMouseMove = true;
                }
            }
            else {
                this.commandHandler.viewerBase.isFormFieldMouseMove = false;
            }
        };
        return MoveTool;
    }(ToolBase));
    exports.MoveTool = MoveTool;
    var StampTool = (function (_super) {
        __extends(StampTool, _super);
        function StampTool() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        StampTool.prototype.mouseDown = function (args) {
            _super.prototype.mouseUp.call(this, args);
        };
        StampTool.prototype.mouseMove = function (args) {
            var newObject;
            if (!this.inAction) {
                var pageIndex = this.pdfViewerBase.activeElements.activePageID;
                this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                var nodeElement = this.commandHandler.annotation.stampAnnotationModule.moveStampElement(args.position.x, args.position.y, pageIndex);
                if (nodeElement.shapeAnnotationType === 'SignatureText') {
                    var textWidth = this.getTextWidth(nodeElement.data, nodeElement.fontSize, nodeElement.fontFamily);
                    var widthRatio = 1;
                    if (textWidth > nodeElement.bounds.width) {
                        widthRatio = nodeElement.bounds.width / textWidth;
                    }
                    nodeElement.fontSize = this.getFontSize(Math.floor((nodeElement.fontSize * widthRatio)));
                    var defaultFontSize = 32;
                    nodeElement.bounds.height = nodeElement.fontSize < defaultFontSize ? nodeElement.fontSize * 2 : nodeElement.bounds.height;
                    nodeElement.thickness = 0;
                }
                newObject = this.commandHandler.add(nodeElement);
                args.source = this.commandHandler.annotations[this.commandHandler.annotations.length - 1];
                args.sourceWrapper = args.source.wrapper;
                this.inAction = true;
                var currentSource = args.source;
                if (currentSource && (currentSource.shapeAnnotationType === 'HandWrittenSignature' || currentSource.shapeAnnotationType === 'SignatureText' || currentSource.shapeAnnotationType === 'SignatureImage')) {
                    this['offset'] = { x: args.source.wrapper.offsetX - (args.source.wrapper.bounds.width / 2), y: args.source.wrapper.offsetY - (args.source.wrapper.bounds.height / 2) };
                }
                else {
                    this['offset'] = { x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY };
                }
                this.startPosition = args.position;
                this.commandHandler.select([newObject.id]);
            }
            var currentSelctor = args.source.annotationSelectorSettings;
            _super.prototype.mouseMove.call(this, args, true, true);
            this.commandHandler.renderSelector(args.source.pageIndex, currentSelctor);
            return this.inAction;
        };
        StampTool.prototype.getTextWidth = function (text, font, fontFamily) {
            var canvas = document.createElement('canvas');
            var context = canvas.getContext('2d');
            var fontName;
            if (font) {
                fontName = font + 'px' + ' ' + fontFamily;
            }
            context.font = fontName || getComputedStyle(document.body).font;
            var textWidth = context.measureText(text).width;
            this.pdfViewerBase.releaseCanvas(canvas);
            return textWidth;
        };
        StampTool.prototype.getFontSize = function (fontSize) {
            return (fontSize % 2 === 0) ? fontSize : --fontSize;
        };
        return StampTool;
    }(MoveTool));
    exports.StampTool = StampTool;
    var InkDrawingTool = (function (_super) {
        __extends(InkDrawingTool, _super);
        function InkDrawingTool(commandHandler, base, sourceObject) {
            var _this = _super.call(this, commandHandler, base) || this;
            _this.sourceObject = sourceObject;
            return _this;
        }
        InkDrawingTool.prototype.mouseDown = function (args) {
            this.pdfViewerBase.disableTextSelectionMode();
            _super.prototype.mouseDown.call(this, args);
            this.inAction = true;
            var node = { currentPosition: this.currentPosition, prevPosition: this.prevPosition };
            this.commandHandler.annotation.inkAnnotationModule.drawInkInCanvas(node, this.pdfViewerBase.activeElements.activePageID);
        };
        InkDrawingTool.prototype.mouseMove = function (args) {
            _super.prototype.mouseMove.call(this, args);
            if (this.inAction) {
                var node = { currentPosition: this.currentPosition, prevPosition: this.pdfViewerBase.prevPosition };
                this.commandHandler.annotation.inkAnnotationModule.drawInkInCanvas(node, this.pdfViewerBase.activeElements.activePageID);
            }
            return this.inAction;
        };
        InkDrawingTool.prototype.mouseUp = function (args) {
            this.commandHandler.annotation.inkAnnotationModule.storePathData();
            return true;
        };
        InkDrawingTool.prototype.mouseLeave = function (args) {
        };
        InkDrawingTool.prototype.endAction = function () {
            _super.prototype.endAction.call(this);
        };
        return InkDrawingTool;
    }(ToolBase));
    exports.InkDrawingTool = InkDrawingTool;
    var ConnectTool = (function (_super) {
        __extends(ConnectTool, _super);
        function ConnectTool(commandHandler, base, endPoint) {
            var _this = _super.call(this, commandHandler, base, true) || this;
            _this.endPoint = endPoint;
            return _this;
        }
        ConnectTool.prototype.mouseDown = function (args) {
            this.inAction = true;
            this.undoElement = undefined;
            _super.prototype.mouseDown.call(this, args);
            var oldValue;
            var connectors;
            if (args.source && args.source.annotations) {
                oldValue = { x: this.prevPosition.x, y: this.prevPosition.y };
                connectors = args.source.annotations[0];
            }
            this.initialPosition = args.position;
            this.prevSource = this.commandHandler.selectedItems.annotations[0];
            var nodeElement = drawing_util_1.cloneObject(args.source);
            this.redoElement = {
                bounds: {
                    x: nodeElement.wrapper.offsetX, y: nodeElement.wrapper.offsetY,
                    width: nodeElement.wrapper.actualSize.width, height: nodeElement.wrapper.actualSize.height
                }
            };
            if (drawing_util_1.isLineShapes(nodeElement)) {
                this.redoElement.vertexPoints = nodeElement.vertexPoints;
                this.redoElement.leaderHeight = nodeElement.leaderHeight;
                if (nodeElement.measureType === 'Distance' || nodeElement.measureType === 'Perimeter' || nodeElement.measureType === 'Area' || nodeElement.measureType === 'Volume') {
                    this.redoElement.notes = nodeElement.notes;
                }
            }
            this.currentPosition = args.position;
        };
        ConnectTool.prototype.mouseUp = function (args) {
            if (this.commandHandler) {
                var node = this.commandHandler.selectedItems.annotations[0];
                var isResized = false;
                if (node) {
                    var annotationSettings = this.commandHandler.annotationModule.findAnnotationSettings(node);
                    var annotationMaxHeight = 0;
                    var annotationMaxWidth = 0;
                    var annotationMinHeight = 0;
                    var annotationMinWidth = 0;
                    if (annotationSettings.minWidth || annotationSettings.maxWidth || annotationSettings.minHeight ||
                        annotationSettings.maxHeight) {
                        annotationMaxHeight = annotationSettings.maxHeight ? annotationSettings.maxHeight : 2000;
                        annotationMaxWidth = annotationSettings.maxWidth ? annotationSettings.maxWidth : 2000;
                        annotationMinHeight = annotationSettings.minHeight ? annotationSettings.minHeight : 0;
                        annotationMinWidth = annotationSettings.minWidth ? annotationSettings.minWidth : 0;
                    }
                    if (node.vertexPoints.length > 3) {
                        var sizeObject = this.commandHandler.viewerBase.checkAnnotationWidth(node.vertexPoints);
                        var width = sizeObject.width;
                        var height = sizeObject.height;
                        if (annotationMinHeight || annotationMinWidth || annotationMaxHeight || annotationMaxWidth) {
                            if ((height > annotationMinHeight && height < annotationMaxHeight) ||
                                (width > annotationMinWidth && width < annotationMaxWidth)) {
                                this.commandHandler.nodePropertyChange(this.prevSource, { vertexPoints: node.vertexPoints, leaderHeight: node.leaderHeight });
                            }
                        }
                        else {
                            this.commandHandler.nodePropertyChange(this.prevSource, { vertexPoints: node.vertexPoints, leaderHeight: node.leaderHeight });
                        }
                    }
                    else {
                        if (annotationMinHeight || annotationMinWidth || annotationMaxHeight || annotationMaxWidth) {
                            if (node.shapeAnnotationType === 'Line' || node.shapeAnnotationType === 'Distance' || node.shapeAnnotationType === 'LineWidthArrowHead') {
                                var x = 0;
                                var y = 0;
                                if (node.vertexPoints[0].x > node.vertexPoints[1].x) {
                                    x = node.vertexPoints[0].x - node.vertexPoints[1].x;
                                }
                                else {
                                    x = node.vertexPoints[1].x - node.vertexPoints[0].x;
                                }
                                if (node.vertexPoints[0].y > node.vertexPoints[1].y) {
                                    y = node.vertexPoints[0].y - node.vertexPoints[1].y;
                                }
                                else {
                                    y = node.vertexPoints[1].y - node.vertexPoints[0].y;
                                }
                                var diff = (x > y) ? x : y;
                                if (diff < (annotationMaxHeight || annotationMaxWidth) && diff > (annotationMinHeight || annotationMinWidth)) {
                                    this.commandHandler.nodePropertyChange(this.prevSource, { vertexPoints: node.vertexPoints,
                                        leaderHeight: node.leaderHeight });
                                }
                            }
                            else {
                                this.commandHandler.nodePropertyChange(this.prevSource, { vertexPoints: node.vertexPoints, leaderHeight: node.leaderHeight });
                            }
                        }
                        else {
                            this.commandHandler.nodePropertyChange(this.prevSource, { vertexPoints: node.vertexPoints, leaderHeight: node.leaderHeight });
                        }
                    }
                    var currentSelctor = args.source.annotationSelectorSettings;
                    this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                    this.commandHandler.select([this.prevSource.id], currentSelctor);
                    this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelctor);
                    var newShapeElementObject = {
                        bounds: {
                            x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY,
                            width: args.source.wrapper.actualSize.width, height: args.source.wrapper.actualSize.height
                        }
                    };
                    if (node.measureType === 'Distance' || node.measureType === 'Perimeter' || node.measureType === 'Area' || node.measureType === 'Volume') {
                        this.commandHandler.annotation.updateCalibrateValues(this.commandHandler.selectedItems.annotations[0]);
                        newShapeElementObject.notes = args.source.notes;
                    }
                    if (drawing_util_1.isLineShapes(args.source)) {
                        newShapeElementObject.vertexPoints = args.source.vertexPoints;
                        newShapeElementObject.leaderHeight = args.source.leaderHeight;
                    }
                    if (this.redoElement.bounds.height !== newShapeElementObject.bounds.height ||
                        this.redoElement.bounds.width !== newShapeElementObject.bounds.width ||
                        this.redoElement.bounds.x !== newShapeElementObject.bounds.x || this.redoElement.bounds.y !==
                        newShapeElementObject.bounds.y) {
                        isResized = true;
                    }
                    if (isResized) {
                        this.commandHandler.annotation.addAction(this.pageIndex, null, this.prevSource, 'Resize', '', this.redoElement, newShapeElementObject);
                    }
                }
            }
            _super.prototype.mouseUp.call(this, args);
        };
        ConnectTool.prototype.mouseMove = function (args) {
            _super.prototype.mouseMove.call(this, args);
            var connector;
            this.currentPosition = args.position;
            if (this.currentPosition && this.prevPosition) {
                var diffX = this.currentPosition.x - this.prevPosition.x;
                var diffY = this.currentPosition.y - this.prevPosition.y;
                var newValue = void 0;
                var oldValue = void 0;
                if (args.source && args.source.annotations) {
                    newValue = {
                        x: this.currentPosition.x, y: this.currentPosition.y
                    };
                    oldValue = {
                        x: this.prevPosition.x, y: this.prevPosition.y
                    };
                    connector = args.source.annotations[0];
                }
                if (this.inAction && this.endPoint !== undefined && diffX !== 0 || diffY !== 0) {
                    if (!this.helper) {
                        var cloneShapebject = drawing_util_1.cloneObject(this.commandHandler.selectedItems.annotations[0]);
                        cloneShapebject.id = 'diagram_helper';
                        cloneShapebject.strokeColor = 'red';
                        cloneShapebject.borderDashArray = '5,5';
                        cloneShapebject.fillColor = 'transparent';
                        cloneShapebject.thickness = 2;
                        cloneShapebject.opacity = 1;
                        if (cloneShapebject.enableShapeLabel === true) {
                            cloneShapebject.labelContent = '';
                        }
                        this.helper = cloneShapebject = this.commandHandler.add(cloneShapebject);
                        this.commandHandler.selectedItems.annotations = [cloneShapebject];
                    }
                    var currentSelctor = args.source.annotationSelectorSettings;
                    this.blocked = !this.commandHandler.dragConnectorEnds(this.endPoint, this.helper, this.currentPosition, this.selectedSegment, args.target, null, currentSelctor);
                    this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelctor);
                }
            }
            this.prevPosition = this.currentPosition;
            return !this.blocked;
        };
        ConnectTool.prototype.mouseLeave = function (args) {
            this.mouseUp(args);
        };
        ConnectTool.prototype.endAction = function () {
            _super.prototype.endAction.call(this);
            this.prevPosition = null;
            this.endPoint = null;
        };
        return ConnectTool;
    }(ToolBase));
    exports.ConnectTool = ConnectTool;
    var ResizeTool = (function (_super) {
        __extends(ResizeTool, _super);
        function ResizeTool(commandHandler, base, corner) {
            var _this = _super.call(this, commandHandler, base, true) || this;
            _this.initialBounds = new ej2_drawings_3.Rect();
            _this.corner = corner;
            return _this;
        }
        ResizeTool.prototype.mouseDown = function (args) {
            _super.prototype.mouseDown.call(this, args);
            this.initialBounds.x = args.source.wrapper.offsetX;
            this.initialBounds.y = args.source.wrapper.offsetY;
            this.initialBounds.height = args.source.wrapper.actualSize.height;
            this.initialBounds.width = args.source.wrapper.actualSize.width;
            this.initialPosition = args.position;
            var node = drawing_util_1.cloneObject(args.source);
            this.redoElement = {
                bounds: {
                    x: node.wrapper.offsetX, y: node.wrapper.offsetY,
                    width: node.wrapper.actualSize.width, height: node.wrapper.actualSize.height
                }
            };
            if (drawing_util_1.isLineShapes(node)) {
                this.redoElement.vertexPoints = node.vertexPoints;
                this.redoElement.leaderHeight = node.leaderHeight;
            }
            if (node.measureType === 'Radius') {
                this.redoElement.notes = node.notes;
            }
            this.prevSource = this.commandHandler.selectedItems.annotations.length > 0 ?
                this.commandHandler.selectedItems.annotations[0] : this.commandHandler.selectedItems.formFields[0];
        };
        ResizeTool.prototype.mouseUp = function (args, isPreventHistory) {
            var object = args.source;
            var oldObject = drawing_util_1.cloneObject(args.source);
            var isResized = false;
            if (this.commandHandler && this.prevSource) {
                this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                this.commandHandler.viewerBase.isAnnotationSelect = true;
                this.commandHandler.viewerBase.isFormFieldSelect = true;
                this.commandHandler.select([this.prevSource.id], this.prevSource.annotationSelectorSettings);
                var deltaValues = this.updateSize(this.prevSource, this.currentPosition, this.initialPosition, this.corner, this.initialBounds, null, true);
                this.blocked = this.scaleObjects(deltaValues.width, deltaValues.height, this.corner, this.currentPosition, this.initialPosition, this.prevSource, args.info.ctrlKey);
                if (this.commandHandler.selectedItems && this.commandHandler.selectedItems.annotations &&
                    this.commandHandler.selectedItems.annotations[0] && this.commandHandler.selectedItems.annotations[0].shapeAnnotationType === 'Stamp') {
                    if (this.commandHandler.stampSettings.minHeight || this.commandHandler.stampSettings.minWidth) {
                        this.commandHandler.select([this.prevSource.id], this.prevSource.annotationSelectorSettings);
                    }
                }
                if (this.commandHandler.selectedItems.formFields.length > 0 && (this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'Textbox' || this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'Checkbox'
                    || this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'RadioButton' || this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'InitialField' || this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'SignatureField'
                    || this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'DropdownList' || this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'ListBox' || this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'PasswordField')) {
                    if (this.commandHandler.selectedItems.formFields[0].formFieldAnnotationType === 'SignatureField') {
                        this.commandHandler.selectedItems.formFields[0].signatureIndicatorSettings = this.commandHandler.selectedItems.formFields[0].signatureIndicatorSettings ? this.commandHandler.selectedItems.formFields[0].signatureIndicatorSettings : { opacity: 1, backgroundColor: 'rgba(255, 228, 133, 0.35)', width: 19, height: 10, fontSize: 10, text: null, color: 'black' };
                    }
                    this.commandHandler.formDesignerModule.updateHTMLElement(this.commandHandler.selectedItems.formFields[0]);
                }
                this.commandHandler.renderSelector(this.prevPageId, this.prevSource.annotationSelectorSettings);
                if (this.commandHandler.annotation && args.source.wrapper) {
                    var newObject = {
                        bounds: {
                            x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY,
                            width: args.source.wrapper.actualSize.width, height: args.source.wrapper.actualSize.height
                        }
                    };
                    if (drawing_util_1.isLineShapes(args.source)) {
                        newObject.vertexPoints = args.source.vertexPoints;
                        newObject.leaderHeight = args.source.leaderHeight;
                    }
                    if (this.redoElement.bounds.height !== newObject.bounds.height ||
                        this.redoElement.bounds.width !== newObject.bounds.width || this.redoElement.bounds.x !==
                        newObject.bounds.x || this.redoElement.bounds.y !== newObject.bounds.y) {
                        isResized = true;
                    }
                    if (this.prevSource.measureType === 'Radius' && isResized) {
                        newObject.notes = args.source.notes;
                        this.commandHandler.annotation.updateCalibrateValues(this.prevSource);
                    }
                    if (this.prevSource.shapeAnnotationType === 'SignatureText') {
                        var oldObjectWidth = (oldObject.bounds && oldObject.bounds.width) ? oldObject.bounds.width : oldObject.width;
                        var boundsRatio = newObject.bounds.width / oldObjectWidth;
                        newObject.fontSize = this.prevSource.wrapper.children[1].style.fontSize * boundsRatio;
                        if (args.target != null) {
                            args.target.fontSize = newObject.fontSize;
                            args.target.wrapper.children[1].style.fontSize = newObject.fontSize;
                            args.target.wrapper.children[1].horizontalAlignment = 'Center';
                            args.target.wrapper.children[1].verticalAlignment = 'Center';
                            args.target.wrapper.children[1].setOffsetWithRespectToBounds(0, 0, 'Absolute');
                            this.commandHandler.selectedItems.annotations[0].wrapper.children[1].style.fontSize = newObject.fontSize;
                            this.commandHandler.selectedItems.annotations[0].wrapper.children[1].horizontalAlignment = 'Center';
                            this.commandHandler.selectedItems.annotations[0].wrapper.children[1].verticalAlignment = 'Center';
                            this.commandHandler.selectedItems.annotations[0].wrapper.children[1].setOffsetWithRespectToBounds(0, 0, 'Absolute');
                            this.commandHandler.selectedItems.annotations[0].fontSize = newObject.fontSize;
                        }
                    }
                    if ((this.prevSource.shapeAnnotationType === 'SignatureText') && this.commandHandler.selectedItems.annotations && this.commandHandler.selectedItems.annotations.length > 0) {
                        this.commandHandler.nodePropertyChange(this.commandHandler.selectedItems.annotations[0], { fontSize: newObject.fontSize });
                    }
                    if (isResized) {
                        this.commandHandler.annotation.addAction(this.pageIndex, null, this.prevSource, 'Resize', '', this.redoElement, newObject);
                    }
                }
                if (args.target && args.target.formFieldAnnotationType) {
                    var node = args.target;
                    var field = { id: args.source.id, value: node.value, fontFamily: node.fontFamily,
                        fontSize: node.fontSize, fontStyle: node.fontStyle,
                        color: node.color, backgroundColor: node.backgroundColor,
                        alignment: node.alignment, isReadonly: node.isReadonly,
                        visibility: node.visibility,
                        maxLength: node.maxLength, isRequired: node.isRequired, isPrint: node.isPrint,
                        rotation: node.rotateAngle, tooltip: node.tooltip,
                        options: node.options, isChecked: node.isChecked, isSelected: node.isSelected };
                    var currentPosition = { X: args.source.wrapper.offsetX, Y: args.source.wrapper.offsetY,
                        Width: args.source.wrapper.actualSize.width, Height: args.source.wrapper.actualSize.height };
                    var previousPosition = { X: this.initialBounds.x, Y: this.initialBounds.y,
                        Width: this.initialBounds.width, Height: this.initialBounds.height };
                    this.commandHandler.fireFormFieldResizeEvent('formFieldResize', field, node.pageIndex, previousPosition, currentPosition);
                }
                if (this.commandHandler.annotation && this.commandHandler.annotation.stampAnnotationModule) {
                    this.commandHandler.annotation.stampAnnotationModule.updateSessionStorage(args.source, this.prevSource.id, 'Resize');
                }
            }
            _super.prototype.mouseUp.call(this, args);
            return !this.blocked;
        };
        ResizeTool.prototype.mouseMove = function (args) {
            _super.prototype.mouseMove.call(this, args);
            var object = args.source;
            this.currentPosition = args.position;
            var x = this.currentPosition.x - this.startPosition.x;
            var y = this.currentPosition.y - this.startPosition.y;
            x = x / this.commandHandler.viewerBase.getZoomFactor();
            y = y / this.commandHandler.viewerBase.getZoomFactor();
            var annotationElement = args.source;
            var size = this.getPoints(x, y);
            var width = annotationElement.width + size.x;
            var height = annotationElement.height + size.y;
            var obj = object;
            if (object && object.annotations) {
                obj = object.annotations[0];
            }
            var annotationSettings = this.commandHandler.annotationModule ?
                this.commandHandler.annotationModule.findAnnotationSettings(obj) : {};
            var annotationMaxHeight = 0;
            var annotationMaxWidth = 0;
            var annotationMinHeight = 0;
            var annotationMinWidth = 0;
            if (annotationSettings.minWidth || annotationSettings.maxWidth || annotationSettings.minHeight || annotationSettings.maxHeight) {
                annotationMaxHeight = annotationSettings.maxHeight ? annotationSettings.maxHeight : 2000;
                annotationMaxWidth = annotationSettings.maxWidth ? annotationSettings.maxWidth : 2000;
                annotationMinHeight = annotationSettings.minHeight ? annotationSettings.minHeight : 0;
                annotationMinWidth = annotationSettings.minWidth ? annotationSettings.minWidth : 0;
            }
            if (annotationMinHeight || annotationMinWidth || annotationMaxHeight || annotationMaxWidth) {
                if (height < annotationMinHeight) {
                    y = annotationMinHeight - annotationElement.height;
                }
                else if (height > annotationMaxHeight) {
                    y = annotationMaxHeight - annotationElement.height;
                }
                if (width < annotationMinWidth) {
                    x = annotationMinWidth - annotationElement.width;
                }
                else if (width > annotationMaxWidth) {
                    x = annotationMaxWidth - annotationElement.width;
                }
            }
            var changes = { x: x, y: y };
            if (this.currentElement.wrapper) {
                changes = ej2_drawings_2.rotatePoint(-this.currentElement.wrapper.rotateAngle, undefined, undefined, changes);
            }
            changes = this.getChanges(changes);
            this.commandHandler.renderSelector(this.prevPageId, this.prevSource.annotationSelectorSettings);
            if (!this.helper) {
                var cobject = this.commandHandler.selectedItems.annotations.length > 0 ?
                    drawing_util_1.cloneObject(this.commandHandler.selectedItems.annotations[0]) :
                    drawing_util_1.cloneObject(this.commandHandler.selectedItems.formFields[0]);
                cobject.id = 'diagram_helper';
                if (cobject.shapeAnnotationType === 'Stamp') {
                    cobject.strokeColor = '';
                    cobject.borderDashArray = '';
                    cobject.fillColor = 'transparent';
                    cobject.stampFillColor = 'transparent';
                    cobject.data = '';
                }
                else if (cobject.shapeAnnotationType === 'FreeText') {
                    cobject.strokeColor = 'blue';
                    cobject.fillColor = 'transparent';
                    cobject.thickness = 1;
                    cobject.opacity = 1;
                    cobject.dynamicText = '';
                }
                else {
                    cobject.bounds = this.commandHandler.selectedItems.annotations.length > 0 ?
                        this.commandHandler.selectedItems.annotations[0].wrapper.bounds :
                        this.commandHandler.selectedItems.formFields[0].wrapper.bounds;
                    cobject.strokeColor = 'red';
                    cobject.borderDashArray = '5,5';
                    cobject.fillColor = 'transparent';
                    cobject.thickness = 2;
                    cobject.opacity = 1;
                }
                if (cobject.enableShapeLabel === true) {
                    cobject.labelContent = '';
                }
                if (cobject.shapeAnnotationType === 'SignatureText') {
                    cobject.fillColor = 'transparent';
                    cobject.thickness = 1;
                    cobject.opacity = 1;
                    cobject.data = '';
                }
                this.helper = cobject = this.commandHandler.add(cobject);
                if (this.commandHandler.selectedItems.annotations.length > 0) {
                    this.commandHandler.selectedItems.annotations = [cobject];
                }
                else {
                    this.commandHandler.selectedItems.formFields = [cobject];
                }
            }
            var deltaValues = this.updateSize(this.helper, this.startPosition, this.currentPosition, this.corner, this.initialBounds);
            this.blocked = !(this.scaleObjects(deltaValues.width, deltaValues.height, this.corner, this.startPosition, this.currentPosition, this.helper, args.info.ctrlKey));
            this.prevPosition = this.currentPosition;
            return !this.blocked;
        };
        ResizeTool.prototype.mouseLeave = function (args) {
            this.mouseUp(args);
        };
        ResizeTool.prototype.getTooltipContent = function (pdfAnnotationBaseModel) {
            return 'W:' + Math.round(pdfAnnotationBaseModel.wrapper.bounds.width) + ' ' + 'H:' + Math.round(pdfAnnotationBaseModel.wrapper.bounds.height);
        };
        ResizeTool.prototype.getChanges = function (change) {
            switch (this.corner) {
                case 'ResizeEast':
                    return { x: change.x, y: 0 };
                case 'ResizeSouthEast':
                    return change;
                case 'ResizeSouth':
                    return { x: 0, y: change.y };
                case 'ResizeNorth':
                    return { x: 0, y: -change.y };
                case 'ResizeNorthEast':
                    return { x: change.x, y: -change.y };
                case 'ResizeNorthWest':
                    return { x: -change.x, y: -change.y };
                case 'ResizeWest':
                    return { x: -change.x, y: 0 };
                case 'ResizeSouthWest':
                    return { x: -change.x, y: change.y };
            }
            return change;
        };
        ResizeTool.prototype.getPoints = function (x, y) {
            switch (this.corner) {
                case 'ResizeEast':
                    return { x: x, y: 0 };
                case 'ResizeSouthEast':
                    return { x: x, y: y };
                case 'ResizeSouth':
                    return { x: 0, y: y };
                case 'ResizeNorth':
                    return { x: 0, y: -y };
                case 'ResizeNorthEast':
                    return { x: x, y: -y };
                case 'ResizeNorthWest':
                    return { x: -x, y: -y };
                case 'ResizeWest':
                    return { x: -x, y: 0 };
                case 'ResizeSouthWest':
                    return { x: -x, y: y };
            }
            return { x: x, y: y };
        };
        ResizeTool.prototype.scaleObjects = function (deltaWidth, deltaHeight, corner, startPoint, endPoint, source, isCtrlKeyPressed) {
            var annotationSettings = this.commandHandler.annotationModule ?
                this.commandHandler.annotationModule.findAnnotationSettings(source) : {};
            var annotationMaxHeight = 0;
            var annotationMaxWidth = 0;
            var annotationMinHeight = 0;
            var annotationMinWidth = 0;
            var x = this.currentPosition.x - this.startPosition.x;
            var y = this.currentPosition.y - this.startPosition.y;
            x = x / this.commandHandler.viewerBase.getZoomFactor();
            y = y / this.commandHandler.viewerBase.getZoomFactor();
            var annotationElement = source;
            var size = this.getPoints(x, y);
            var width = annotationElement.bounds.width + size.x;
            var height = annotationElement.bounds.height + size.y;
            if (annotationSettings.minWidth || annotationSettings.maxWidth || annotationSettings.minHeight || annotationSettings.maxHeight) {
                annotationMaxHeight = annotationSettings.maxHeight ? annotationSettings.maxHeight : 2000;
                annotationMaxWidth = annotationSettings.maxWidth ? annotationSettings.maxWidth : 2000;
                annotationMinHeight = annotationSettings.minHeight ? annotationSettings.minHeight : 0;
                annotationMinWidth = annotationSettings.minWidth ? annotationSettings.minWidth : 0;
            }
            if (source instanceof selector_1.Selector && source.annotations.length === 1 &&
                (source.annotations[0].shapeAnnotationType === 'Perimeter' || source.annotations[0].shapeAnnotationType === 'Radius' || source.shapeAnnotationType === 'Stamp')) {
                if (!(deltaHeight === 1 && deltaWidth === 1)) {
                    deltaHeight = deltaWidth = Math.max(deltaHeight === 1 ? 0 : deltaHeight, deltaWidth === 1 ? 0 : deltaWidth);
                }
                else if (startPoint !== endPoint) {
                    deltaHeight = deltaWidth = Math.max(deltaHeight, deltaWidth);
                }
                else {
                    deltaHeight = deltaWidth = 0;
                }
            }
            else if (source.shapeAnnotationType === 'Image' || (source.shapeAnnotationType === 'HandWrittenSignature' || source.shapeAnnotationType === 'SignatureText' || source.shapeAnnotationType === 'SignatureImage')) {
                if (!(deltaHeight === 1 && deltaWidth === 1)) {
                    if (isCtrlKeyPressed) {
                        if (width >= annotationMaxWidth && height < annotationMaxHeight) {
                            deltaHeight = Math.max(deltaHeight, deltaWidth);
                        }
                        if (height >= annotationMaxHeight && width < annotationMaxWidth) {
                            deltaWidth = Math.max(deltaHeight, deltaWidth);
                        }
                        if (width < annotationMaxWidth && height < annotationMaxHeight) {
                            deltaHeight = deltaWidth = Math.max(deltaHeight, deltaWidth);
                        }
                    }
                }
                if (!isCtrlKeyPressed) {
                    deltaHeight = deltaWidth = Math.max(deltaHeight, deltaWidth);
                }
            }
            else {
                if (source.shapeAnnotationType === 'Perimeter' || source.shapeAnnotationType === 'Radius'
                    || source.shapeAnnotationType === 'Stamp') {
                    if (source.shapeAnnotationType === 'Stamp') {
                        if (!annotationMaxHeight && !deltaHeight) {
                            deltaHeight = Math.max(deltaHeight === 1 ? 0 : deltaHeight);
                        }
                        if (!annotationMaxWidth && !deltaWidth) {
                            deltaWidth = Math.max(deltaWidth === 1 ? 0 : deltaWidth);
                        }
                    }
                    else {
                        if (!annotationMaxHeight || !annotationMaxWidth) {
                            if (!(deltaHeight === 1 && deltaWidth === 1)) {
                                deltaHeight = deltaWidth = Math.max(deltaHeight === 1 ? 0 : deltaHeight, deltaWidth === 1 ? 0 : deltaWidth);
                            }
                        }
                    }
                }
            }
            this.blocked = this.commandHandler.scaleSelectedItems(deltaWidth, deltaHeight, this.getPivot(this.corner));
            return this.blocked;
        };
        return ResizeTool;
    }(ToolBase));
    exports.ResizeTool = ResizeTool;
    var NodeDrawingTool = (function (_super) {
        __extends(NodeDrawingTool, _super);
        function NodeDrawingTool(commandHandler, base, sourceObject) {
            var _this = _super.call(this, commandHandler, base) || this;
            _this.sourceObject = sourceObject;
            return _this;
        }
        NodeDrawingTool.prototype.mouseDown = function (args) {
            if (!isNaN(this.pdfViewerBase.activeElements.activePageID) && event.target.className !== 'e-pv-page-container') {
                _super.prototype.mouseDown.call(this, args);
                this.inAction = true;
                var node = { bounds: { x: 100, y: 300, width: 100, height: 100 }, pageIndex: 0, strokeColor: 'red', thickness: 3 };
                node.id = ej2_drawings_1.randomId();
                this.sourceObject.pageIndex = node.pageIndex = this.pdfViewerBase.activeElements.activePageID || 0;
                this.sourceObject.enableShapeLabel = this.commandHandler.enableShapeLabel;
                this.pdfViewerBase.updateFreeTextProperties(this.sourceObject);
                this.isFormDesign = false;
                var formFieldElement = document.getElementById('FormField_helper_html_element');
                if (formFieldElement) {
                    formFieldElement.remove();
                }
                this.commandHandler.drawingObject = this.drawingObject =
                    this.commandHandler.add(this.sourceObject || node);
                if (this.drawingObject.formFieldAnnotationType === 'Textbox' || this.drawingObject.formFieldAnnotationType === 'SignatureField' || this.drawingObject.formFieldAnnotationType === 'InitialField' ||
                    this.drawingObject.formFieldAnnotationType === 'Checkbox' || this.drawingObject.formFieldAnnotationType === 'ListBox' || this.drawingObject.formFieldAnnotationType === 'RadioButton' ||
                    this.drawingObject.formFieldAnnotationType === 'DropdownList' || this.drawingObject.formFieldAnnotationType === 'PasswordField') {
                    this.inAction = false;
                    this.drawingObject.pageNumber = this.pdfViewerBase.getActivePage(true);
                    var bounds = this.commandHandler.formDesignerModule.
                        updateFormFieldInitialSize(this.drawingObject.wrapper.children[0], this.drawingObject.formFieldAnnotationType);
                    var pageIndex = this.drawingObject.pageIndex;
                    var page = this.pdfViewerBase.getElement('_pageDiv_' + pageIndex);
                    var pageWidth = page.clientWidth - bounds.width;
                    var pageHeight = page.clientHeight - bounds.height;
                    var left = page.offsetLeft;
                    var offsetX = void 0;
                    if (this.currentPosition.y >= pageHeight && event.target && event.target.parentElement && event.target.parentElement.classList.contains('foreign-object') && event.path) {
                        var targetParentRect = event.path[3].getBoundingClientRect();
                        offsetX = event.clientX - targetParentRect.left;
                    }
                    else if (ej2_base_1.isNullOrUndefined(event.path) && (this.drawingObject.formFieldAnnotationType === 'SignatureField' || this.drawingObject.formFieldAnnotationType === 'InitialField')) {
                        offsetX = this.currentPosition.x;
                    }
                    else {
                        offsetX = this.currentPosition.x - left;
                    }
                    var rect = void 0;
                    if (this.currentPosition.x >= pageWidth && this.currentPosition.y >= pageHeight) {
                        rect = { x: pageWidth, y: pageHeight, width: this.drawingObject.wrapper.children[0].width,
                            height: this.drawingObject.wrapper.children[0].height };
                    }
                    else if (this.currentPosition.x >= pageWidth) {
                        rect = { x: pageWidth, y: this.currentPosition.y, width: this.drawingObject.wrapper.children[0].width,
                            height: this.drawingObject.wrapper.children[0].height };
                    }
                    else if (this.currentPosition.y >= pageHeight) {
                        rect = { x: offsetX, y: pageHeight, width: this.drawingObject.wrapper.children[0].width,
                            height: this.drawingObject.wrapper.children[0].height };
                    }
                    else {
                        rect = { x: this.currentPosition.x, y: this.currentPosition.y, width: this.drawingObject.wrapper.children[0].width,
                            height: this.drawingObject.wrapper.children[0].height };
                    }
                    this.updateNodeDimension(this.drawingObject, rect);
                    this.drawingObject.bounds.x = this.drawingObject.bounds.x - (this.drawingObject.bounds.width / 2);
                    this.drawingObject.bounds.y = this.drawingObject.bounds.y - (this.drawingObject.bounds.height / 2);
                    this.commandHandler.formFieldCollection.push(this.drawingObject);
                    var drawingObject = this.drawingObject;
                    var formField = {
                        id: drawingObject.id, name: drawingObject.name, value: drawingObject.value,
                        type: drawingObject.formFieldAnnotationType, isReadOnly: drawingObject.isReadonly,
                        fontFamily: drawingObject.fontFamily,
                        fontSize: drawingObject.fontSize, fontStyle: drawingObject.fontStyle,
                        color: drawingObject.color, backgroundColor: drawingObject.backgroundColor,
                        alignment: drawingObject.alignment, visibility: drawingObject.visibility,
                        maxLength: drawingObject.maxLength, isRequired: drawingObject.isRequired,
                        isPrint: drawingObject.isPrint, isSelected: drawingObject.isSelected, isChecked: drawingObject.isChecked,
                        tooltip: drawingObject.tooltip, bounds: drawingObject.bounds,
                        thickness: drawingObject.thickness, borderColor: drawingObject.borderColor,
                        signatureIndicatorSettings: drawingObject.signatureIndicatorSettings, pageIndex: drawingObject.pageIndex,
                        pageNumber: drawingObject.pageNumber, isMultiline: drawingObject.isMultiline,
                        insertSpaces: drawingObject.insertSpaces, isTransparent: drawingObject.isTransparent,
                        rotateAngle: drawingObject.rotateAngle,
                        selectedIndex: drawingObject.selectedIndex, options: drawingObject.options ? drawingObject.options : [],
                        signatureType: drawingObject.signatureType, zIndex: drawingObject.zIndex, customData: drawingObject.customData ? drawingObject.customData : ''
                    };
                    this.commandHandler.formFieldCollections.push(formField);
                    this.commandHandler.formDesignerModule.drawHTMLContent(this.drawingObject.formFieldAnnotationType, this.drawingObject.wrapper.children[0], this.drawingObject, this.drawingObject.pageIndex, this.commandHandler);
                    this.commandHandler.select([this.commandHandler.drawingObject.id], this.commandHandler.annotationSelectorSettings);
                    if (this.commandHandler.annotation) {
                        this.commandHandler.annotation.addAction(this.pdfViewerBase.getActivePage(true), null, this.drawingObject, 'Addition', '', this.drawingObject, this.drawingObject);
                    }
                    this.endAction();
                    this.pdfViewerBase.tool = null;
                    this.pdfViewerBase.action = 'Select';
                    this.drawingObject = null;
                    this.pdfViewerBase.isMouseDown = false;
                    this.pdfViewerBase.pdfViewer.drawingObject = null;
                    this.isFormDesign = true;
                }
            }
        };
        NodeDrawingTool.prototype.mouseMove = function (args) {
            _super.prototype.mouseMove.call(this, args);
            if (this.inAction && ej2_drawings_1.Point.equals(this.currentPosition, this.prevPosition) === false) {
                this.dragging = true;
                var rect = ej2_drawings_3.Rect.toBounds([this.prevPosition, this.currentPosition]);
                if (!ej2_base_1.isNullOrUndefined(this.drawingObject)) {
                    this.updateNodeDimension(this.drawingObject, rect);
                    if (this.drawingObject.shapeAnnotationType === 'Radius') {
                        this.updateRadiusLinePosition(this.drawingObject.wrapper.children[1], this.drawingObject);
                    }
                }
            }
            return true;
        };
        NodeDrawingTool.prototype.mouseUp = function (args) {
            if (this.drawingObject && this.dragging) {
                this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                if (!ej2_base_1.isNullOrUndefined(args.source) && !ej2_base_1.isNullOrUndefined(args.source.annotationSelectorSettings)) {
                    this.commandHandler.select([this.drawingObject.id], args.source.annotationSelectorSettings);
                }
                var drawnAnnotation = this.commandHandler.selectedItems.annotations[0];
                if (!ej2_base_1.isNullOrUndefined(drawnAnnotation) && !ej2_base_1.isNullOrUndefined(drawnAnnotation.wrapper)) {
                    this.commandHandler.nodePropertyChange(drawnAnnotation, { bounds: { x: drawnAnnotation.wrapper.offsetX,
                            y: drawnAnnotation.wrapper.offsetY } });
                    this.commandHandler.annotation.updateCalibrateValues(this.drawingObject, true);
                    if (this.commandHandler && !this.isFormDesign) {
                        this.commandHandler.annotation.addAction(this.pageIndex, null, this.drawingObject, 'Addition', '', this.drawingObject, this.drawingObject);
                    }
                    this.dragging = false;
                    _super.prototype.mouseUp.call(this, args);
                    this.inAction = false;
                }
            }
            else {
                _super.prototype.mouseUp.call(this, args);
            }
            this.drawingObject = null;
        };
        NodeDrawingTool.prototype.endAction = function () {
            _super.prototype.endAction.call(this);
        };
        NodeDrawingTool.prototype.updateNodeDimension = function (obj, rect) {
            var zoom = this.commandHandler.viewerBase.getZoomFactor();
            if (!ej2_base_1.isNullOrUndefined(obj)) {
                obj.bounds.x = (rect.x / zoom) + rect.width / zoom;
                obj.bounds.y = (rect.y / zoom) + rect.height / zoom;
                obj.bounds.width = rect.width / zoom;
                obj.bounds.height = rect.height / zoom;
                var annotationSettings = this.commandHandler.annotationModule ?
                    this.commandHandler.annotationModule.findAnnotationSettings(obj) : {};
                var annotationMaxHeight = 0;
                var annotationMaxWidth = 0;
                if (annotationSettings.maxWidth || annotationSettings.maxHeight) {
                    annotationMaxHeight = annotationSettings.maxHeight ? annotationSettings.maxHeight : 2000;
                    annotationMaxWidth = annotationSettings.maxWidth ? annotationSettings.maxWidth : 2000;
                    if (obj.bounds.width > annotationMaxWidth) {
                        obj.bounds.width = annotationMaxWidth;
                    }
                    if (obj.bounds.height > annotationMaxHeight) {
                        obj.bounds.height = annotationMaxHeight;
                    }
                    if (obj.bounds.height <= annotationMaxHeight && obj.bounds.width <= annotationMaxWidth) {
                        this.commandHandler.nodePropertyChange(obj, { bounds: obj.bounds });
                    }
                }
                else {
                    this.commandHandler.nodePropertyChange(obj, { bounds: obj.bounds });
                }
            }
        };
        NodeDrawingTool.prototype.updateRadiusLinePosition = function (obj, node) {
            var trasPoint = { x: node.bounds.x + (node.bounds.width / 4), y: node.bounds.y };
            var center = { x: (node.bounds.x + (node.bounds.width / 2)), y: (node.bounds.y + (node.bounds.height / 2)) };
            var matrix = ej2_drawings_4.identityMatrix();
            ej2_drawings_4.rotateMatrix(matrix, node.rotateAngle, center.x, center.y);
            var rotatedPoint = ej2_drawings_4.transformPointByMatrix(matrix, trasPoint);
            var newPoint1 = { x: rotatedPoint.x, y: rotatedPoint.y };
            obj.offsetX = newPoint1.x;
            obj.offsetY = newPoint1.y;
            obj.width = node.bounds.width / 2;
            var annotationSettings = this.commandHandler.annotationModule.findAnnotationSettings(node);
            var annotationMaxWidth = 0;
            if (annotationSettings.maxWidth) {
                annotationMaxWidth = annotationSettings.maxWidth ? annotationSettings.maxWidth : 2000;
                if (node.bounds.width > annotationMaxWidth) {
                    node.bounds.width = annotationMaxWidth;
                    obj.width = node.bounds.width / 2;
                }
            }
            this.commandHandler.renderDrawing(undefined, node.pageIndex);
        };
        return NodeDrawingTool;
    }(ToolBase));
    exports.NodeDrawingTool = NodeDrawingTool;
    var PolygonDrawingTool = (function (_super) {
        __extends(PolygonDrawingTool, _super);
        function PolygonDrawingTool(commandHandler, base, action) {
            var _this = _super.call(this, commandHandler, base) || this;
            _this.action = action;
            return _this;
        }
        PolygonDrawingTool.prototype.mouseDown = function (args) {
            _super.prototype.mouseDown.call(this, args);
            this.inAction = true;
            if (!this.drawingObject) {
                this.startPoint = { x: this.startPosition.x, y: this.startPosition.y };
                var nodeAnnotElement = {
                    bounds: { x: this.currentPosition.x, y: this.currentPosition.y, width: 5, height: 5 },
                    vertexPoints: [{ x: this.startPoint.x / this.pdfViewerBase.getZoomFactor(),
                            y: this.startPoint.y / this.pdfViewerBase.getZoomFactor() },
                        { x: this.currentPosition.x / this.pdfViewerBase.getZoomFactor(),
                            y: this.currentPosition.y / this.pdfViewerBase.getZoomFactor() }],
                    shapeAnnotationType: 'Line', fillColor: this.commandHandler.drawingObject.fillColor,
                    strokeColor: this.commandHandler.drawingObject.strokeColor, pageIndex: this.pdfViewerBase.activeElements.activePageID,
                    notes: this.commandHandler.drawingObject.notes, thickness: this.commandHandler.drawingObject.thickness,
                    author: this.commandHandler.drawingObject.author,
                    subject: this.commandHandler.drawingObject.subject, borderDashArray: this.commandHandler.drawingObject.borderDashArray,
                    modifiedDate: this.commandHandler.drawingObject.modifiedDate, borderStyle: this.commandHandler.drawingObject.borderStyle,
                    measureType: this.commandHandler.drawingObject.measureType, enableShapeLabel: this.commandHandler.enableShapeLabel,
                    opacity: this.commandHandler.drawingObject.opacity
                };
                this.pdfViewerBase.updateFreeTextProperties(nodeAnnotElement);
                this.drawingObject = this.commandHandler.add(nodeAnnotElement);
            }
            else {
                var pt = void 0;
                var obj = (this.drawingObject);
                pt = obj.vertexPoints[obj.vertexPoints.length - 1];
                pt = { x: pt.x, y: pt.y };
                var lastPoint = this.drawingObject.vertexPoints[this.drawingObject.vertexPoints.length - 1];
                if (!(lastPoint.x === pt.x && lastPoint.x === pt.y)) {
                    this.drawingObject.vertexPoints.push(pt);
                }
                this.commandHandler.nodePropertyChange(obj, { vertexPoints: obj.vertexPoints });
            }
        };
        PolygonDrawingTool.prototype.mouseMove = function (args) {
            _super.prototype.mouseMove.call(this, args);
            if (this.inAction && ej2_drawings_1.Point.equals(this.currentPosition, this.prevPosition) === false) {
                this.dragging = true;
                var obj = (this.drawingObject);
                if (this.drawingObject && this.currentPosition) {
                    obj.vertexPoints[obj.vertexPoints.length - 1].x = this.currentPosition.x / this.pdfViewerBase.getZoomFactor();
                    obj.vertexPoints[obj.vertexPoints.length - 1].y = this.currentPosition.y / this.pdfViewerBase.getZoomFactor();
                    this.commandHandler.nodePropertyChange(obj, { vertexPoints: obj.vertexPoints });
                }
                if (obj.measureType === 'Perimeter') {
                    connector_util_1.updatePerimeterLabel(obj, obj.vertexPoints, this.commandHandler.annotation.measureAnnotationModule);
                }
            }
            return true;
        };
        PolygonDrawingTool.prototype.mouseUp = function (args, isDoubleClineck, isMouseLeave) {
            var needToDrawPolygon = false;
            _super.prototype.mouseMove.call(this, args);
            var currentSelector;
            if (args.source && args.annotationSelectorSettings !== null) {
                currentSelector = args.source.annotationSelectorSettings;
            }
            else {
                currentSelector = '';
            }
            if (this.drawingObject && this.drawingObject.vertexPoints.length === 2 && isDoubleClineck && isMouseLeave) {
                this.commandHandler.remove(this.drawingObject);
                needToDrawPolygon = true;
                this.endAction();
            }
            if (this.drawingObject && !needToDrawPolygon) {
                var bounds = new ej2_drawings_3.Rect(this.drawingObject.vertexPoints[this.drawingObject.vertexPoints.length - 1].x - 20, this.drawingObject.vertexPoints[this.drawingObject.vertexPoints.length - 1].y - 20, 40, 40);
                var point = { x: this.drawingObject.vertexPoints[0].x, y: this.drawingObject.vertexPoints[0].y };
                if ((bounds.containsPoint(point) || isDoubleClineck) && this.dragging) {
                    if (this.inAction) {
                        this.inAction = false;
                        if (this.drawingObject) {
                            if (!isMouseLeave) {
                                if (this.drawingObject.vertexPoints.length > 2 && !args.isTouchMode) {
                                    this.drawingObject.vertexPoints.splice(this.drawingObject.vertexPoints.length - 1, 1);
                                }
                            }
                            if (this.action === 'Polygon') {
                                if (!isMouseLeave) {
                                    this.drawingObject.vertexPoints[this.drawingObject.vertexPoints.length - 1] =
                                        this.drawingObject.vertexPoints[0];
                                }
                                else {
                                    this.drawingObject.vertexPoints[this.drawingObject.vertexPoints.length] =
                                        this.drawingObject.vertexPoints[0];
                                }
                                this.commandHandler.nodePropertyChange(this.drawingObject, { vertexPoints: this.drawingObject.vertexPoints });
                                var cobject = drawing_util_1.cloneObject(this.drawingObject);
                                cobject.shapeAnnotationType = 'Polygon';
                                cobject.bounds.width = cobject.wrapper.actualSize.width;
                                cobject.bounds.height = cobject.wrapper.actualSize.height;
                                cobject.bounds.x = this.drawingObject.wrapper.bounds.x;
                                cobject.bounds.y = this.drawingObject.wrapper.bounds.y;
                                this.commandHandler.add(cobject);
                                this.commandHandler.remove(this.drawingObject);
                                this.commandHandler.select([cobject.id], currentSelector);
                                var drawingObject = this.commandHandler.selectedItems.annotations[0];
                                if (drawingObject) {
                                    if (this.commandHandler.enableShapeAnnotation && (ej2_base_1.isNullOrUndefined(drawingObject.measureType) || drawingObject.measureType === '')) {
                                        this.commandHandler.annotation.shapeAnnotationModule.
                                            renderShapeAnnotations(drawingObject, drawingObject.pageIndex);
                                    }
                                    if (this.commandHandler.enableMeasureAnnotation && (drawingObject.measureType === 'Area' || drawingObject.measureType === 'Volume')) {
                                        if (drawingObject.measureType === 'Area') {
                                            drawingObject.notes = this.commandHandler.annotation.measureAnnotationModule.
                                                calculateArea(drawingObject.vertexPoints);
                                            this.commandHandler.annotation.stickyNotesAnnotationModule.
                                                addTextToComments(drawingObject.annotName, drawingObject.notes);
                                        }
                                        else if (drawingObject.measureType === 'Volume') {
                                            drawingObject.notes = this.commandHandler.annotation.measureAnnotationModule.
                                                calculateVolume(drawingObject.vertexPoints);
                                            this.commandHandler.annotation.stickyNotesAnnotationModule.
                                                addTextToComments(drawingObject.annotName, drawingObject.notes);
                                        }
                                        if (drawingObject.enableShapeLabel) {
                                            drawingObject.labelContent = drawingObject.notes;
                                            this.commandHandler.nodePropertyChange(drawingObject, { vertexPoints: drawingObject.vertexPoints,
                                                notes: drawingObject.notes });
                                        }
                                        this.commandHandler.annotation.measureAnnotationModule.
                                            renderMeasureShapeAnnotations(drawingObject, drawingObject.pageIndex);
                                    }
                                }
                            }
                            else {
                                if (!isMouseLeave) {
                                    if (isDoubleClineck) {
                                        this.drawingObject.vertexPoints.splice(this.drawingObject.vertexPoints.length - 1, 1);
                                    }
                                }
                                this.commandHandler.nodePropertyChange(this.drawingObject, {
                                    vertexPoints: this.drawingObject.vertexPoints,
                                    sourceDecoraterShapes: this.commandHandler.drawingObject.sourceDecoraterShapes,
                                    taregetDecoraterShapes: this.commandHandler.drawingObject.taregetDecoraterShapes
                                });
                                this.commandHandler.select([this.drawingObject.id], currentSelector);
                                if (this.commandHandler.enableMeasureAnnotation && this.drawingObject.measureType === 'Perimeter') {
                                    this.commandHandler.renderDrawing(null, this.drawingObject.pageIndex);
                                    this.drawingObject.notes =
                                        this.commandHandler.annotation.measureAnnotationModule.calculatePerimeter(this.drawingObject);
                                    if (this.drawingObject.enableShapeLabel) {
                                        this.drawingObject.labelContent = this.drawingObject.notes;
                                        this.commandHandler.nodePropertyChange(this.drawingObject, { vertexPoints: this.drawingObject.vertexPoints,
                                            notes: this.drawingObject.notes });
                                    }
                                    this.commandHandler.annotation.stickyNotesAnnotationModule.
                                        addTextToComments(this.drawingObject.annotName, this.drawingObject.notes);
                                    this.commandHandler.annotation.measureAnnotationModule.
                                        renderMeasureShapeAnnotations(this.drawingObject, this.drawingObject.pageIndex);
                                }
                            }
                            var annotationObject = this.commandHandler.selectedItems.annotations[0];
                            this.commandHandler.annotation.addAction(this.pageIndex, null, annotationObject, 'Addition', '', annotationObject, annotationObject);
                            this.drawingObject = null;
                        }
                    }
                    this.endAction();
                }
                else if (this.inAction && !this.dragging) {
                    this.commandHandler.remove(this.drawingObject);
                }
            }
        };
        PolygonDrawingTool.prototype.mouseLeave = function (args) {
            this.mouseUp(args, true, true);
        };
        PolygonDrawingTool.prototype.mouseWheel = function (args) {
            _super.prototype.mouseWheel.call(this, args);
            this.mouseMove(args);
        };
        PolygonDrawingTool.prototype.endAction = function () {
            this.inAction = false;
            this.drawingObject = null;
            this.commandHandler.tool = '';
        };
        return PolygonDrawingTool;
    }(ToolBase));
    exports.PolygonDrawingTool = PolygonDrawingTool;
    var LineTool = (function (_super) {
        __extends(LineTool, _super);
        function LineTool(commandHandler, base, endPoint, drawingObject) {
            var _this = _super.call(this, commandHandler, base, true) || this;
            _this.endPoint = endPoint;
            _this.drawingObject = drawingObject;
            return _this;
        }
        LineTool.prototype.mouseDown = function (args) {
            this.inAction = true;
            this.undoElement = undefined;
            _super.prototype.mouseDown.call(this, args);
            var oldPointValue;
            var connectorsShape;
            if (args.source && args.source.annotations) {
                oldPointValue = { x: this.prevPosition.x, y: this.prevPosition.y };
                connectorsShape = this.drawingObject;
            }
            this.initialPosition = args.position;
            this.prevSource = this.drawingObject;
            this.currentPosition = args.position;
            if (!this.drawingObject) {
                var measureModule = this.commandHandler.annotation.measureAnnotationModule;
                var annotationNode = {
                    vertexPoints: [{ x: this.startPosition.x / this.pdfViewerBase.getZoomFactor(),
                            y: this.startPosition.y / this.pdfViewerBase.getZoomFactor() },
                        { x: this.currentPosition.x / this.pdfViewerBase.getZoomFactor(),
                            y: this.currentPosition.y / this.pdfViewerBase.getZoomFactor() }],
                    bounds: { x: this.currentPosition.x, y: this.currentPosition.y, width: 5, height: 5 },
                    sourceDecoraterShapes: this.commandHandler.drawingObject.sourceDecoraterShapes,
                    taregetDecoraterShapes: this.commandHandler.drawingObject.taregetDecoraterShapes, measureType: 'Distance',
                    fillColor: this.commandHandler.drawingObject.fillColor, notes: this.commandHandler.drawingObject.notes,
                    strokeColor: this.commandHandler.drawingObject.strokeColor,
                    opacity: this.commandHandler.drawingObject.opacity, thickness: this.commandHandler.drawingObject.thickness,
                    borderDashArray: this.commandHandler.drawingObject.borderDashArray,
                    shapeAnnotationType: 'Distance', pageIndex: this.pdfViewerBase.activeElements.activePageID,
                    author: this.commandHandler.drawingObject.author, subject: this.commandHandler.drawingObject.subject,
                    enableShapeLabel: this.commandHandler.enableShapeLabel, leaderHeight: measureModule.leaderLength
                };
                this.pdfViewerBase.updateFreeTextProperties(annotationNode);
                this.drawingObject = this.commandHandler.add(annotationNode);
            }
            else if (!this.dragging) {
                var nodeAnnot = {
                    bounds: { x: this.currentPosition.x, y: this.currentPosition.y, width: 5, height: 5 },
                    vertexPoints: [{ x: this.startPosition.x / this.pdfViewerBase.getZoomFactor(),
                            y: this.startPosition.y / this.pdfViewerBase.getZoomFactor() },
                        { x: this.currentPosition.x / this.pdfViewerBase.getZoomFactor(),
                            y: this.currentPosition.y / this.pdfViewerBase.getZoomFactor() }],
                    shapeAnnotationType: this.drawingObject.shapeAnnotationType,
                    sourceDecoraterShapes: this.drawingObject.sourceDecoraterShapes,
                    taregetDecoraterShapes: this.drawingObject.taregetDecoraterShapes, fillColor: this.drawingObject.fillColor,
                    strokeColor: this.drawingObject.strokeColor, pageIndex: this.pdfViewerBase.activeElements.activePageID,
                    opacity: this.drawingObject.opacity || 1, borderDashArray: this.drawingObject.borderDashArray,
                    thickness: this.drawingObject.thickness,
                    modifiedDate: this.drawingObject.modifiedDate, author: this.drawingObject.author, subject: this.drawingObject.subject,
                    lineHeadEnd: this.drawingObject.lineHeadEnd, lineHeadStart: this.drawingObject.lineHeadStart,
                    measureType: this.commandHandler.drawingObject.measureType, enableShapeLabel: this.commandHandler.enableShapeLabel
                };
                this.pdfViewerBase.updateFreeTextProperties(nodeAnnot);
                this.drawingObject = this.commandHandler.add(nodeAnnot);
            }
        };
        LineTool.prototype.mouseUp = function (args) {
            if (this.dragging) {
                _super.prototype.mouseMove.call(this, args);
                if (this.commandHandler) {
                    var currentSelector = void 0;
                    if (args.source && args.annotationSelectorSettings !== null) {
                        currentSelector = args.source.annotationSelectorSettings;
                    }
                    else {
                        currentSelector = '';
                    }
                    var node = this.drawingObject;
                    this.commandHandler.nodePropertyChange(node, { vertexPoints: node.vertexPoints, leaderHeight: node.leaderHeight });
                    this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
                    this.commandHandler.select([node.id], currentSelector);
                    this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelector);
                }
                if (this.endPoint && this.endPoint.indexOf('ConnectorSegmentPoint') > -1 && this.dragging) {
                    this.commandHandler.annotation.updateCalibrateValues(this.drawingObject);
                    this.commandHandler.annotation.addAction(this.pageIndex, null, this.drawingObject, 'Addition', '', this.drawingObject, this.drawingObject);
                    this.drawingObject = null;
                    this.dragging = false;
                    _super.prototype.mouseUp.call(this, args);
                }
                if (this.drawingObject) {
                    this.endPoint = 'ConnectorSegmentPoint_1';
                }
            }
            else {
                if (this.drawingObject) {
                    this.commandHandler.remove(this.drawingObject);
                }
            }
        };
        LineTool.prototype.mouseMove = function (args) {
            _super.prototype.mouseMove.call(this, args);
            if (this.inAction && ej2_drawings_1.Point.equals(this.currentPosition, this.prevPosition) === false) {
                this.currentPosition = args.position;
                this.dragging = true;
                if (this.currentPosition && this.prevPosition) {
                    var diffX = this.currentPosition.x - this.prevPosition.x;
                    var diffY = this.currentPosition.y - this.prevPosition.y;
                    var currentSelector = void 0;
                    if (args.source && args.annotationSelectorSettings !== null) {
                        currentSelector = args.source.annotationSelectorSettings;
                    }
                    else {
                        currentSelector = '';
                    }
                    if (this.inAction && this.commandHandler && this.drawingObject &&
                        this.endPoint !== undefined && diffX !== 0 || diffY !== 0) {
                        this.blocked = !this.commandHandler.dragConnectorEnds(this.endPoint, this.drawingObject, this.currentPosition, this.selectedSegment, args.target, null, currentSelector);
                        this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelector);
                    }
                }
                this.prevPosition = this.currentPosition;
            }
            return !this.blocked;
        };
        LineTool.prototype.mouseLeave = function (args) {
            this.mouseUp(args);
        };
        LineTool.prototype.endAction = function () {
            _super.prototype.endAction.call(this);
            this.prevPosition = null;
            this.endPoint = null;
        };
        return LineTool;
    }(ToolBase));
    exports.LineTool = LineTool;
    var RotateTool = (function (_super) {
        __extends(RotateTool, _super);
        function RotateTool(commandHandler, base) {
            return _super.call(this, commandHandler, base, true) || this;
        }
        RotateTool.prototype.mouseDown = function (args) {
            var nodeMouseDown = drawing_util_1.cloneObject(args.source);
            this.undoElement = {
                bounds: {
                    x: nodeMouseDown.wrapper.offsetX, y: nodeMouseDown.wrapper.offsetY,
                    width: nodeMouseDown.wrapper.actualSize.width, height: nodeMouseDown.wrapper.actualSize.height
                }, rotateAngle: nodeMouseDown.rotateAngle
            };
            _super.prototype.mouseDown.call(this, args);
        };
        RotateTool.prototype.mouseUp = function (args) {
            var object = args.source;
            var newShapeObject;
            if (this.undoElement.rotateAngle !== object.wrapper.rotateAngle) {
                var currentSelector = args.source.annotations[0].annotationSelectorSettings;
                this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelector);
                newShapeObject = {
                    bounds: {
                        x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY,
                        width: args.source.wrapper.actualSize.width, height: args.source.wrapper.actualSize.height
                    }, rotateAngle: args.source.wrapper.rotateAngle
                };
            }
            this.commandHandler.annotation.addAction(this.pageIndex, null, args.source, 'Rotate', '', this.undoElement, newShapeObject);
            this.commandHandler.annotation.stampAnnotationModule.updateSessionStorage(args.source, null, 'Rotate');
            this.commandHandler.annotation.stickyNotesAnnotationModule.updateStickyNotes(args.source, null);
            _super.prototype.mouseUp.call(this, args);
        };
        RotateTool.prototype.mouseMove = function (args) {
            _super.prototype.mouseMove.call(this, args);
            var object = args.source;
            var currentSelector = args.source.annotations[0].annotationSelectorSettings;
            this.currentPosition = args.position;
            if (object.wrapper) {
                var refPoint = { x: object.wrapper.offsetX, y: object.wrapper.offsetY };
                var angle = ej2_drawings_1.Point.findAngle(refPoint, this.currentPosition) + 90;
                angle = (angle + 360) % 360;
                this.blocked = !(this.commandHandler.rotate(angle - object.wrapper.rotateAngle, currentSelector));
            }
            return !this.blocked;
        };
        RotateTool.prototype.getTooltipContent = function (node) {
            return Math.round((node.rotateAngle % 360)).toString() + '\xB0';
        };
        RotateTool.prototype.mouseLeave = function (args) {
            this.mouseUp(args);
        };
        RotateTool.prototype.endAction = function () {
            _super.prototype.endAction.call(this);
        };
        return RotateTool;
    }(ToolBase));
    exports.RotateTool = RotateTool;
});