all files / spreadsheet/actions/ virtual-scroll.js

77.76% Statements 402/517
63.74% Branches 167/262
96.77% Functions 30/31
77.78% Lines 399/513
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   120× 120× 120×   144× 144× 144× 144× 144× 144× 144× 144× 144× 120×   144× 144× 141×   141×         144× 144× 144×       144× 144× 144× 144× 144×               144×   144× 144×     144× 144× 144×                   144×     144×     144×     144× 144×   144× 143×   144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 142×     125× 125× 139× 139×   139×     285× 285× 259×             12× 12× 12× 12× 12× 10×                                                                                                                                                         13× 13× 13× 13× 148×     13×                                                                                                                                                                                             60×     209× 122×   87× 87× 87× 48× 48×   87× 15× 15×     63× 16× 16× 16× 16× 16× 16× 16× 16×     16× 16× 16×         16× 16× 16× 16×         47× 47× 47× 47× 47× 47×     45× 45× 45× 45×         104×   103× 103× 59× 58× 58× 58×             55× 51×         58× 51×           44×                     299× 299×           299×     241× 241×         248× 248×   24× 24× 24× 24× 24×                                                               120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120×   120× 120× 120× 120× 120× 120× 120× 120×   120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120×        
define(["require", "exports", "@syncfusion/ej2-base", "../common/index", "../common/index", "../common/index", "./../../workbook/index", "../../workbook/common/index"], function (require, exports, ej2_base_1, index_1, index_2, index_3, index_4, index_5) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var VirtualScroll = (function () {
        function VirtualScroll(parent) {
            this.scroll = [];
            this.parent = parent;
            this.addEventListener();
        }
        VirtualScroll.prototype.createVirtualElement = function (args) {
            var sheet = this.parent.getActiveSheet();
            var container = this.parent.getMainContent();
            this.content = this.parent.createElement('div', { className: 'e-virtualable' });
            this.content.appendChild(container.querySelector('.e-table'));
            container.appendChild(this.content);
            var vTrack = container.appendChild(this.parent.createElement('div', { className: 'e-virtualtrack' }));
            var height = 0;
            var width;
            if (this.parent.sheets.length > this.scroll.length) {
                this.initScroll();
            }
            var endIndex = this.parent.viewport.bottomIndex;
            if (sheet.rowCount > endIndex + 1 || sheet.usedRange.rowIndex > endIndex) {
                if (!this.parent.scrollSettings.isFinite && sheet.rowCount <= sheet.usedRange.rowIndex) {
                    this.parent.setSheetPropertyOnMute(sheet, 'rowCount', sheet.usedRange.rowIndex + 1);
                }
                this.setScrollCount(sheet.rowCount, 'row');
            }
            else {
                Eif (!this.parent.scrollSettings.isFinite) {
                    this.parent.setSheetPropertyOnMute(sheet, 'rowCount', endIndex + 1);
                }
                this.scroll[this.parent.activeSheetIndex].rowCount = sheet.rowCount;
            }
            var startIndex = this.parent.frozenRowCount(sheet);
            var indexes = index_5.getCellIndexes(sheet.topLeftCell);
            if (args.top) {
                height = args.top;
                Iif (sheet.frozenRows) {
                    height += index_4.getRowsHeight(sheet, indexes[0], startIndex - 1, true);
                }
                startIndex = index_5.getCellIndexes(sheet.paneTopLeftCell)[0];
            }
            height += index_4.getRowsHeight(sheet, startIndex, this.scroll[this.parent.activeSheetIndex].rowCount - 1, true);
            endIndex = this.parent.viewport.rightIndex;
            var size = 0;
            var frozenCol = this.parent.frozenColCount(sheet);
            Iif (args.left) {
                size = args.left;
                if (frozenCol) {
                    size += index_4.getColumnsWidth(sheet, indexes[1], frozenCol - 1, true);
                }
                startIndex = index_5.getCellIndexes(sheet.paneTopLeftCell)[1];
            }
            else {
                startIndex = frozenCol;
            }
            Eif (sheet.colCount > endIndex + 1 || sheet.usedRange.colIndex > endIndex) {
                Iif (!this.parent.scrollSettings.isFinite && sheet.colCount <= sheet.usedRange.colIndex) {
                    this.parent.setSheetPropertyOnMute(sheet, 'colCount', sheet.usedRange.colIndex + 1);
                }
                size += index_4.getColumnsWidth(sheet, startIndex, endIndex, true);
                this.setScrollCount(sheet.colCount, 'col');
                width = size + index_4.getColumnsWidth(sheet, endIndex + 1, this.scroll[this.parent.activeSheetIndex].colCount - 1, true);
            }
            else {
                if (!this.parent.scrollSettings.isFinite) {
                    this.parent.setSheetPropertyOnMute(sheet, 'colCount', endIndex + 1);
                }
                size += index_4.getColumnsWidth(sheet, startIndex, sheet.colCount - 1, true);
                this.scroll[this.parent.activeSheetIndex].colCount = sheet.colCount;
                width = size;
            }
            Iif (ej2_base_1.isNullOrUndefined(this.parent.viewport.leftIndex)) {
                this.parent.viewport.leftIndex = 0;
            }
            Iif (ej2_base_1.isNullOrUndefined(this.parent.viewport.topIndex)) {
                this.parent.viewport.topIndex = 0;
            }
            Iif (args.left) {
                size = index_4.getColumnsWidth(sheet, this.parent.viewport.leftIndex + frozenCol, endIndex, true);
            }
            Eif (ej2_base_1.isNullOrUndefined(this.translateX)) {
                this.translateX = 0;
            }
            if (ej2_base_1.isNullOrUndefined(this.translateY)) {
                this.translateY = 0;
            }
            container = this.parent.getRowHeaderContent();
            this.rowHeader = this.content.cloneNode();
            this.rowHeader.appendChild(container.querySelector('.e-table'));
            container.appendChild(this.rowHeader);
            var rowVTrack = container.appendChild(vTrack.cloneNode());
            this.rowHeader.style.transform = "translate(0px, " + this.translateY + "px)";
            container = this.parent.getColumnHeaderContent();
            this.colHeader = this.content.cloneNode();
            this.colHeader.appendChild(container.querySelector('.e-table'));
            container.appendChild(this.colHeader);
            var colVTrack = container.appendChild(vTrack.cloneNode());
            this.colHeader.style.width = size + "px";
            rowVTrack.style.height = height + "px";
            colVTrack.style.width = width + "px";
            this.colHeader.style.transform = "translate(" + this.translateX + "px, 0px)";
            this.content.style.transform = "translate(" + this.translateX + "px, " + this.translateY + "px)";
            this.content.style.width = size + "px";
            vTrack.style.height = height + "px";
            vTrack.style.width = width + "px";
            if (this.parent.allowScrolling) {
                this.parent.getScrollElement().appendChild(colVTrack.cloneNode(true));
            }
        };
        VirtualScroll.prototype.initScroll = function () {
            var i = 0;
            while (i < this.parent.sheets.length) {
                Eif (!this.scroll[i]) {
                    this.scroll.push({ rowCount: 0, colCount: 0 });
                }
                i++;
            }
        };
        VirtualScroll.prototype.setScrollCount = function (count, layout) {
            var activeSheetIdx = this.parent.activeSheetIndex;
            if (!this.scroll[activeSheetIdx][layout + 'Count'] || this.scroll[activeSheetIdx][layout + 'Count'] !== count) {
                this.scroll[activeSheetIdx][layout + 'Count'] = count;
            }
        };
        VirtualScroll.prototype.getRowAddress = function (indexes) {
            var sheet = this.parent.getActiveSheet();
            return index_5.getRangeAddress([indexes[0], sheet.frozenColumns ? index_5.getCellIndexes(sheet.topLeftCell)[1] : this.parent.viewport.leftIndex,
                indexes[1], this.parent.viewport.rightIndex]);
        };
        VirtualScroll.prototype.getColAddress = function (indexes) {
            var sheet = this.parent.getActiveSheet();
            return index_5.getRangeAddress([sheet.frozenRows ? index_5.getCellIndexes(sheet.topLeftCell)[0] : this.parent.viewport.topIndex, indexes[0],
                this.parent.viewport.bottomIndex, indexes[1]]);
        };
        VirtualScroll.prototype.updateScrollCount = function (idx, layout, threshold) {
            if (threshold === void 0) { threshold = idx; }
            var sheet = this.parent.getActiveSheet();
            var rowCount = idx + this.parent.viewport[layout + 'Count'] + 1 + threshold;
            var usedRangeCount = this.scroll[this.parent.activeSheetIndex][layout + 'Count'];
            if (rowCount < usedRangeCount) {
                if (sheet[layout + 'Count'] === usedRangeCount) {
                    return;
                }
                rowCount = usedRangeCount;
            }
            Eif (!this.parent.scrollSettings.isFinite) {
                this.parent.setSheetPropertyOnMute(sheet, layout + 'Count', rowCount);
            }
        };
        VirtualScroll.prototype.onVerticalScroll = function (args) {
            var idx = args.cur.idx;
            var height = args.cur.size;
            var prevIdx = args.prev.idx;
            var idxDiff = Math.abs(idx - prevIdx);
            var threshold = this.parent.getThreshold('row');
            Eif (idxDiff > Math.round(threshold / 2)) {
                var startIdx = void 0;
                var lastIdx = void 0;
                var prevTopIdx = void 0;
                var sheet = this.parent.getActiveSheet();
                if (idx <= threshold) {
                    Eif (!args.increase) {
                        Eif (this.translateY && prevIdx > threshold) {
                            this.translateY = 0;
                            var frozenCol = this.parent.frozenColCount(sheet);
                            var frozenRow = this.parent.frozenRowCount(sheet);
                            Eif (!args.preventScroll) {
                                var colIndex = frozenCol ? index_5.getCellIndexes(sheet.topLeftCell)[1] : this.parent.viewport.leftIndex;
                                var fIndexes = frozenCol ? [frozenRow, this.parent.viewport.leftIndex + frozenCol] : [];
                                if (idxDiff < this.parent.viewport.rowCount + threshold) {
                                    startIdx = index_2.skipHiddenIdx(sheet, frozenRow, true);
                                    Iif (startIdx < 0) {
                                        startIdx = frozenRow;
                                    }
                                    lastIdx = index_2.skipHiddenIdx(sheet, (this.parent.viewport.topIndex + frozenRow) - 1, false);
                                    this.parent.viewport.topIndex = index_2.skipHiddenIdx(sheet, startIdx - frozenRow, true);
                                    var hiddenCount = this.hiddenCount(startIdx, lastIdx);
                                    var skippedHiddenIdx = index_2.skipHiddenIdx(sheet, (this.parent.viewport.bottomIndex - ((lastIdx - startIdx + 1) - hiddenCount)), args.increase);
                                    this.parent.viewport.bottomIndex -= (((lastIdx - startIdx + 1) - hiddenCount) +
                                        (this.hiddenCount(skippedHiddenIdx, this.parent.viewport.bottomIndex)));
                                    this.parent.renderModule.refreshUI({
                                        colIndex: colIndex, rowIndex: startIdx, direction: 'last', refresh: 'RowPart',
                                        skipUpdateOnFirst: true, frozenIndexes: fIndexes
                                    }, this.getRowAddress([startIdx, index_2.skipHiddenIdx(sheet, lastIdx, false)]));
                                }
                                else {
                                    var prevColIndex = this.parent.viewport.leftIndex;
                                    this.parent.renderModule.refreshUI({ rowIndex: 0, colIndex: colIndex, refresh: 'Row', skipUpdateOnFirst: true,
                                        frozenIndexes: fIndexes, skipTranslate: true });
                                    Iif (frozenCol) {
                                        this.parent.viewport.leftIndex = prevColIndex;
                                    }
                                    this.translate({ refresh: 'Row' });
                                }
                                index_2.focus(this.parent.element);
                                idx = 0;
                            }
                            else {
                                this.parent.viewport.topIndex = prevIdx - (threshold - frozenRow);
                            }
                        }
                        this.updateScrollCount(threshold, 'row');
                    }
                }
                if (prevIdx < threshold) {
                    idxDiff = Math.abs(idx - threshold);
                }
                Iif (!args.increase && this.parent.scrollSettings.isFinite && this.parent.viewport.bottomIndex ===
                    index_2.skipHiddenIdx(sheet, sheet.rowCount - 1, false)) {
                    var thresholdIdx = this.parent.viewport.topIndex + index_4.getRangeIndexes(sheet.topLeftCell)[0] - 1;
                    if (idx > thresholdIdx) {
                        args.prev.idx = idx;
                        return;
                    }
                    idxDiff = thresholdIdx - idx;
                }
                if (idx > threshold) {
                    prevTopIdx = this.parent.viewport.topIndex;
                    this.parent.viewport.topIndex = idx - threshold;
                    Iif (args.increase && prevTopIdx > this.parent.viewport.topIndex) {
                        this.parent.viewport.topIndex = prevTopIdx;
                        return;
                    }
                    var frozenRow = this.parent.frozenRowCount(sheet);
                    if (!args.preventScroll) {
                        var frozenCol = this.parent.frozenColCount(sheet);
                        var colIndex = frozenCol ? index_5.getCellIndexes(sheet.topLeftCell)[1] : this.parent.viewport.leftIndex;
                        var frozenIndexes = [];
                        Iif (sheet.frozenColumns) {
                            frozenIndexes = [frozenRow, this.parent.viewport.leftIndex + frozenCol];
                        }
                        if (idxDiff < this.parent.viewport.rowCount + threshold) {
                            Eif (args.increase) {
                                startIdx = this.parent.viewport.bottomIndex + 1;
                                lastIdx = this.parent.viewport.bottomIndex + (this.parent.viewport.topIndex - prevTopIdx);
                                lastIdx -= this.hiddenCount(prevTopIdx, this.parent.viewport.topIndex - 1);
                                Iif (lastIdx <= this.parent.viewport.bottomIndex) {
                                    this.parent.viewport.topIndex = index_2.skipHiddenIdx(sheet, this.parent.viewport.topIndex, args.increase);
                                    this.setThresholdHeight(height, threshold, frozenRow);
                                    return;
                                }
                                var indexes = this.parent.skipHidden(startIdx, lastIdx, 'rows', false);
                                var finiteOffset = this.checkLastIdx(indexes[1], 'row');
                                startIdx = indexes[0];
                                lastIdx = finiteOffset.index;
                                this.parent.viewport.topIndex = index_2.skipHiddenIdx(sheet, this.parent.viewport.topIndex - finiteOffset.diff, !this.parent.scrollSettings.isFinite);
                                this.setThresholdHeight(height, idx - this.parent.viewport.topIndex, frozenRow, !!finiteOffset.diff);
                                this.parent.viewport.bottomIndex = lastIdx;
                                this.parent.renderModule.refreshUI({ colIndex: colIndex, rowIndex: startIdx, direction: 'first', refresh: 'RowPart',
                                    frozenIndexes: frozenIndexes }, this.getRowAddress([startIdx, lastIdx]));
                            }
                            else {
                                this.parent.viewport.topIndex = startIdx = index_2.skipHiddenIdx(sheet, this.parent.viewport.topIndex, false);
                                if (startIdx < 0) {
                                    this.parent.viewport.topIndex = startIdx = 0;
                                }
                                startIdx = index_2.skipHiddenIdx(sheet, startIdx + frozenRow, true);
                                lastIdx = index_2.skipHiddenIdx(sheet, prevTopIdx - 1, false);
                                if (lastIdx < 0 || lastIdx < startIdx) {
                                    this.parent.viewport.topIndex = prevTopIdx;
                                    return;
                                }
                                var hiddenCount = this.hiddenCount(startIdx, lastIdx);
                                this.parent.viewport.bottomIndex -= (((lastIdx - startIdx) + 1) - hiddenCount);
                                this.parent.viewport.bottomIndex = index_2.skipHiddenIdx(sheet, this.parent.viewport.bottomIndex, false);
                                startIdx = this.parent.skipHidden(startIdx, lastIdx)[0];
                                this.setThresholdHeight(height, idx - this.parent.viewport.topIndex, frozenRow);
                                this.parent.renderModule.refreshUI({ colIndex: colIndex, rowIndex: startIdx, direction: 'last', refresh: 'RowPart',
                                    frozenIndexes: frozenIndexes }, this.getRowAddress([startIdx, lastIdx]));
                            }
                        }
                        else {
                            prevTopIdx = this.parent.viewport.leftIndex;
                            this.parent.viewport.topIndex = index_2.skipHiddenIdx(sheet, this.parent.viewport.topIndex, false);
                            this.parent.renderModule.refreshUI({
                                rowIndex: this.parent.viewport.topIndex, colIndex: colIndex, refresh: 'Row',
                                frozenIndexes: frozenIndexes, skipTranslate: true
                            });
                            Iif (frozenCol) {
                                this.parent.viewport.leftIndex = prevTopIdx;
                            }
                            this.setThresholdHeight(height, idx - this.parent.viewport.topIndex, frozenRow);
                            this.translate({ refresh: 'Row' });
                        }
                        this.updateScrollCount(idx, 'row', threshold);
                        this.focusSheet();
                    }
                    else {
                        this.setThresholdHeight(height, threshold, frozenRow);
                        this.translate({ refresh: 'Row' });
                    }
                }
                args.prev.idx = idx;
            }
        };
        VirtualScroll.prototype.hiddenCount = function (startIdx, endIdx, layout) {
            if (layout === void 0) { layout = 'rows'; }
            var index = 0;
            var sheet = this.parent.getActiveSheet();
            for (var i = startIdx; i <= endIdx; i++) {
                if ((sheet[layout])[i] && (sheet[layout])[i].hidden) {
                    index++;
                }
            }
            return index;
        };
        VirtualScroll.prototype.checkLastIdx = function (idx, layout) {
            var diff = 0;
            Iif (this.parent.scrollSettings.isFinite) {
                var sheet = this.parent.getActiveSheet();
                var count = sheet[layout + 'Count'] - 1;
                if (idx > count) {
                    diff = idx - count;
                    idx = index_2.skipHiddenIdx(sheet, count, false);
                }
            }
            return { index: idx, diff: diff };
        };
        VirtualScroll.prototype.onHorizontalScroll = function (args) {
            var idx = args.cur.idx;
            var width = args.cur.size;
            var prevIdx = args.prev.idx;
            var idxDiff = Math.abs(idx - prevIdx);
            var threshold = this.parent.getThreshold('col');
            Eif (idxDiff > Math.round(threshold / 2)) {
                var startIdx = void 0;
                var endIdx = void 0;
                var prevLeftIdx = void 0;
                var sheet = this.parent.getActiveSheet();
                if (idx <= threshold) {
                    Eif (!args.increase) {
                        Eif (this.translateX && prevIdx > threshold) {
                            var frozenCol = this.parent.frozenColCount(sheet);
                            var frozenRow = this.parent.frozenRowCount(sheet);
                            this.translateX = 0;
                            this.parent.viewport.leftIndex = prevIdx - (threshold - frozenCol);
                            Eif (!args.preventScroll) {
                                var rowIndex = frozenRow ? index_5.getCellIndexes(sheet.topLeftCell)[0] : this.parent.viewport.topIndex;
                                var fIndexes = frozenRow ? [this.parent.viewport.topIndex + frozenRow, frozenCol] : [];
                                Eif (idxDiff < this.parent.viewport.colCount + threshold) {
                                    endIdx = this.parent.viewport.leftIndex - 1;
                                    startIdx = this.parent.skipHidden(frozenCol, endIdx, 'columns')[0];
                                    this.parent.viewport.leftIndex = index_2.skipHiddenIdx(sheet, startIdx - frozenCol, true);
                                    var hiddenCount = this.hiddenCount(startIdx, endIdx, 'columns');
                                    var skippedHiddenIdx = index_2.skipHiddenIdx(sheet, (this.parent.viewport.rightIndex - ((endIdx - startIdx + 1) - hiddenCount)), args.increase, 'columns');
                                    this.parent.viewport.rightIndex -= (((endIdx - startIdx + 1) - hiddenCount) +
                                        (this.hiddenCount(skippedHiddenIdx, this.parent.viewport.rightIndex, 'columns')));
                                    this.parent.renderModule.refreshUI({ rowIndex: rowIndex, colIndex: startIdx, direction: 'last', refresh: 'ColumnPart',
                                        skipUpdateOnFirst: true, frozenIndexes: fIndexes }, this.getColAddress([startIdx, index_2.skipHiddenIdx(sheet, endIdx, false, 'columns')]));
                                }
                                else {
                                    var prevRowIndex = this.parent.viewport.topIndex;
                                    this.parent.renderModule.refreshUI({ rowIndex: rowIndex, colIndex: 0, refresh: 'Column', skipUpdateOnFirst: true,
                                        frozenIndexes: fIndexes, skipTranslate: true });
                                    if (frozenRow) {
                                        this.parent.viewport.topIndex = prevRowIndex;
                                    }
                                    this.translate({ refresh: 'Column' });
                                }
                                index_2.focus(this.parent.element);
                            }
                        }
                        this.updateScrollCount(threshold, 'col');
                    }
                }
                if (prevIdx < threshold) {
                    idxDiff = Math.abs(idx - threshold);
                }
                Iif (!args.increase && this.parent.scrollSettings.isFinite && this.parent.viewport.rightIndex === sheet.colCount - 1) {
                    var thresholdIdx = this.parent.viewport.leftIndex + threshold;
                    thresholdIdx += this.hiddenCount(this.parent.viewport.leftIndex, thresholdIdx);
                    if (idx > thresholdIdx) {
                        args.prev.idx = idx;
                        return;
                    }
                    idxDiff = thresholdIdx - idx;
                }
                if (idx > threshold) {
                    prevLeftIdx = this.parent.viewport.leftIndex;
                    this.parent.viewport.leftIndex = idx - threshold;
                    Iif (args.increase && prevLeftIdx > this.parent.viewport.leftIndex) {
                        this.parent.viewport.leftIndex = prevLeftIdx;
                        return;
                    }
                    var frozenCol = this.parent.frozenColCount(sheet);
                    Eif (!args.preventScroll) {
                        var frozenRow = this.parent.frozenRowCount(sheet);
                        var rowIndex = frozenRow ? index_5.getCellIndexes(sheet.topLeftCell)[0] : this.parent.viewport.topIndex;
                        var frozenIndexes = [];
                        Iif (frozenRow) {
                            frozenIndexes = [frozenRow + this.parent.viewport.topIndex, frozenCol];
                        }
                        Eif (idxDiff < this.parent.viewport.colCount + threshold) {
                            Eif (args.increase) {
                                startIdx = this.parent.viewport.rightIndex + 1;
                                endIdx = this.parent.viewport.rightIndex + (this.parent.viewport.leftIndex - prevLeftIdx);
                                endIdx -= this.hiddenCount(prevLeftIdx, this.parent.viewport.leftIndex - 1, 'columns');
                                Iif (endIdx <= this.parent.viewport.rightIndex) {
                                    this.parent.viewport.leftIndex = index_2.skipHiddenIdx(sheet, this.parent.viewport.leftIndex, args.increase, 'columns');
                                    this.setThresholdWidth(width, threshold, frozenCol);
                                    return;
                                }
                                var indexes = this.parent.skipHidden(startIdx, endIdx, 'columns');
                                var finiteOffset = this.checkLastIdx(indexes[1], 'col');
                                startIdx = indexes[0];
                                endIdx = finiteOffset.index;
                                this.parent.viewport.leftIndex = index_2.skipHiddenIdx(sheet, this.parent.viewport.leftIndex - finiteOffset.diff, args.increase, 'columns');
                                this.setThresholdWidth(width, threshold, frozenCol);
                                this.parent.viewport.rightIndex = endIdx;
                                this.parent.renderModule.refreshUI({ rowIndex: rowIndex, colIndex: startIdx, direction: 'first', refresh: 'ColumnPart',
                                    frozenIndexes: frozenIndexes }, this.getColAddress([startIdx, endIdx]));
                            }
                            else {
                                startIdx = this.parent.viewport.leftIndex + frozenCol;
                                endIdx = startIdx + idxDiff - 1;
                                var hiddenCount = this.hiddenCount(startIdx, endIdx, 'columns');
                                var skippedHiddenIdx = index_2.skipHiddenIdx(sheet, (this.parent.viewport.rightIndex - ((endIdx - startIdx) - hiddenCount)), args.increase, 'columns');
                                this.parent.viewport.rightIndex -= ((idxDiff - hiddenCount) +
                                    (this.hiddenCount(skippedHiddenIdx, this.parent.viewport.rightIndex, 'columns')));
                                startIdx = this.parent.skipHidden(startIdx, endIdx, 'columns')[0];
                                this.parent.viewport.leftIndex = index_2.skipHiddenIdx(sheet, startIdx - frozenCol, true, 'columns');
                                this.setThresholdWidth(width, threshold, frozenCol);
                                this.parent.renderModule.refreshUI({ rowIndex: rowIndex, colIndex: startIdx, direction: 'last', refresh: 'ColumnPart',
                                    frozenIndexes: frozenIndexes }, this.getColAddress([startIdx, endIdx]));
                            }
                        }
                        else {
                            prevLeftIdx = this.parent.viewport.topIndex;
                            this.parent.renderModule.refreshUI({
                                rowIndex: rowIndex, colIndex: this.parent.viewport.leftIndex, refresh: 'Column', frozenIndexes: frozenIndexes,
                                skipTranslate: true
                            });
                            if (frozenRow) {
                                this.parent.viewport.topIndex = prevLeftIdx;
                            }
                            this.setThresholdWidth(width, threshold, frozenCol);
                            this.translate({ refresh: 'Column' });
                        }
                        this.updateScrollCount(idx, 'col', threshold);
                        this.focusSheet();
                    }
                    else {
                        this.setThresholdWidth(width, threshold, frozenCol);
                        this.translate({ refresh: 'Column' });
                    }
                }
                args.prev.idx = idx;
            }
        };
        VirtualScroll.prototype.focusSheet = function () {
            Eif (!document.activeElement.classList.contains('e-text-findNext-short') || !ej2_base_1.closest(document.activeElement, '#' + this.parent.element.id)) {
                index_2.focus(this.parent.element);
            }
        };
        VirtualScroll.prototype.setThresholdHeight = function (scrollHeight, threshold, frozenRow, endReached) {
            var sheet = this.parent.getActiveSheet();
            var start = this.parent.viewport.topIndex + frozenRow;
            var end;
            Iif (endReached) {
                var vTrack = this.parent.getMainContent().querySelector('.e-virtualtrack');
                if (vTrack) {
                    scrollHeight = parseInt(vTrack.style.height, 10);
                    end = this.parent.viewport.bottomIndex;
                }
                else {
                    this.translateY = index_4.getRowsHeight(sheet, 0, start - 1, true);
                    return;
                }
            }
            else {
                end = (start + threshold) - 1;
            }
            this.translateY = scrollHeight - index_4.getRowsHeight(sheet, start, end, true);
        };
        VirtualScroll.prototype.setThresholdWidth = function (scrollWidth, threshold, frozenCol) {
            var width = 0;
            var sheet = this.parent.getActiveSheet();
            for (var i = this.parent.viewport.leftIndex + frozenCol, len = i + threshold; i < len; i++) {
                width += index_4.getColumnWidth(sheet, i, null, true);
            }
            this.translateX = scrollWidth - width;
        };
        VirtualScroll.prototype.translate = function (args) {
            if (args.skipTranslate || !this.content) {
                return;
            }
            var translateX = this.translateX || 0;
            translateX = this.parent.enableRtl ? -translateX : translateX;
            if (args.refresh === 'Row' || args.refresh === 'RowPart') {
                this.content.style.transform = "translate(" + translateX + "px, " + this.translateY + "px)";
                this.rowHeader.style.transform = "translate(0px, " + this.translateY + "px)";
            }
            if (args.refresh === 'Column' || args.refresh === 'ColumnPart') {
                this.content.style.transform = "translate(" + translateX + "px, " + this.translateY + "px)";
                this.colHeader.style.transform = "translate(" + translateX + "px, 0px)";
            }
        };
        VirtualScroll.prototype.updateColumnWidth = function (args) {
            if (args.refresh === 'Column') {
                this.content.style.width = '';
                var sheet = this.parent.getActiveSheet();
                var width = index_4.getColumnsWidth(sheet, this.parent.viewport.leftIndex + this.parent.frozenColCount(sheet), this.parent.viewport.rightIndex, true);
                this.colHeader.style.width = width + 'px';
                this.content.style.width = width + 'px';
                Eif (!this.parent.scrollSettings.isFinite || args.isUpdate) {
                    var scroll_1 = this.parent.element.querySelector('.e-scroller .e-virtualtrack');
                    Iif (!scroll_1) {
                        return;
                    }
                    var scrollWidth = parseInt(scroll_1.style.width, 10);
                    var newWidth = width + this.translateX + this.parent.viewport.beforeFreezeWidth;
                    Iif (newWidth > scrollWidth) {
                        var diff = newWidth - scrollWidth;
                        scroll_1.style.width = scrollWidth + diff + 'px';
                    }
                    else {
                        var diff = scrollWidth - newWidth;
                        var vTrack = this.parent.getMainContent().getElementsByClassName('e-virtualtrack')[0];
                        Eif (scrollWidth - diff < parseInt(vTrack.style.width, 10)) {
                            scroll_1.style.width = vTrack.style.width;
                        }
                    }
                }
            }
            else Eif (!this.parent.scrollSettings.isFinite) {
                var vTrack = this.parent.getMainContent().getElementsByClassName('e-virtualtrack')[0];
                var vTrackHeight = parseInt(vTrack.style.height, 10);
                var height = this.content.getBoundingClientRect().height;
                var newHeight = height + this.translateY + this.parent.viewport.beforeFreezeHeight;
                if (newHeight > vTrackHeight) {
                    var diff = newHeight - vTrackHeight;
                    vTrack.style.height = vTrackHeight + diff + 'px';
                }
                else {
                    var diff = vTrackHeight - newHeight;
                    var hVTrack = this.parent.getRowHeaderContent().getElementsByClassName('e-virtualtrack')[0];
                    Eif (vTrackHeight - diff < parseInt(hVTrack.style.height, 10)) {
                        vTrack.style.height = hVTrack.style.height;
                    }
                }
            }
        };
        VirtualScroll.prototype.updateRowColCount = function (args) {
            if (!this.scroll.length) {
                return;
            }
            var sheet = this.parent.getActiveSheet();
            if (args.update === 'row') {
                if (args.index !== this.scroll[this.parent.activeSheetIndex].rowCount - 1) {
                    var height = this.getVTrackHeight('height');
                    var newHeight = height;
                    if (args.index >= this.scroll[this.parent.activeSheetIndex].rowCount) {
                        Eif (args.start === undefined) {
                            newHeight += index_4.getRowsHeight(sheet, this.scroll[this.parent.activeSheetIndex].rowCount, args.index, true);
                        }
                        else {
                            newHeight += index_4.getRowsHeight(sheet, args.start, args.end, true);
                        }
                    }
                    else {
                        if (args.start === undefined) {
                            newHeight -= index_4.getRowsHeight(sheet, args.index + 1, this.scroll[this.parent.activeSheetIndex].rowCount - 1, true);
                        }
                        else {
                            newHeight -= index_4.getRowsHeight(sheet, args.start, args.end, true);
                        }
                    }
                    if (!args.isDelete && newHeight < height) {
                        return;
                    }
                    this.scroll[this.parent.activeSheetIndex].rowCount = args.index + 1;
                    this.updateVTrack(this.rowHeader, newHeight, 'height');
                    if (this.scroll[this.parent.activeSheetIndex].rowCount > sheet.rowCount) {
                        this.parent.setSheetPropertyOnMute(sheet, 'rowCount', this.scroll[this.parent.activeSheetIndex].rowCount);
                    }
                }
            }
            else {
                Iif (args.index > this.scroll[this.parent.activeSheetIndex].colCount) {
                    var width = this.getVTrackHeight('width');
                    width += index_4.getColumnsWidth(sheet, this.scroll[this.parent.activeSheetIndex].colCount, args.index, true);
                    this.scroll[this.parent.activeSheetIndex].colCount = args.index + 1;
                    this.updateVTrack(this.colHeader, width, 'width');
                    if (this.scroll[this.parent.activeSheetIndex].colCount > sheet.colCount) {
                        this.parent.setSheetPropertyOnMute(sheet, 'colCount', this.scroll[this.parent.activeSheetIndex].colCount);
                    }
                }
            }
        };
        VirtualScroll.prototype.getVTrackHeight = function (str) {
            var height = this.content.nextElementSibling.style[str];
            Iif (height.includes('e+')) {
                height = height.split('px')[0];
                var heightArr = height.split('e+');
                return Number(heightArr[0]) * Math.pow(10, Number(heightArr[1]));
            }
            else {
                return parseFloat(height);
            }
        };
        VirtualScroll.prototype.updateVTrackHeight = function (args) {
            Eif (args.rowIdx < this.scroll[this.parent.activeSheetIndex].rowCount) {
                this.updateVTrack(this.rowHeader, this.getVTrackHeight('height') + args.threshold, 'height');
            }
        };
        VirtualScroll.prototype.updateVTrackWidth = function (args) {
            Eif (args.colIdx >= this.parent.viewport.leftIndex && args.colIdx <= this.parent.viewport.rightIndex) {
                var hdrVTrack = this.parent.getColumnHeaderContent().getElementsByClassName('e-virtualtrack')[0];
                hdrVTrack.style.width = parseFloat(hdrVTrack.style.width) + args.threshold + 'px';
                var cntVTrack = this.parent.getMainContent().getElementsByClassName('e-virtualtrack')[0];
                cntVTrack.style.width = parseFloat(cntVTrack.style.width) + args.threshold + 'px';
                var hdrColumn = this.parent.getColumnHeaderContent().getElementsByClassName('e-virtualable')[0];
                hdrColumn.style.width = parseFloat(hdrColumn.style.width) + args.threshold + 'px';
                var cntColumn = this.parent.getMainContent().getElementsByClassName('e-virtualable')[0];
                cntColumn.style.width = parseFloat(cntColumn.style.width) + args.threshold + 'px';
            }
        };
        VirtualScroll.prototype.updateVTrack = function (header, size, sizeStr) {
            header.nextElementSibling.style[sizeStr] = size + "px";
            this.content.nextElementSibling.style[sizeStr] = size + "px";
        };
        VirtualScroll.prototype.deInitProps = function () {
            this.parent.viewport.leftIndex = null;
            this.parent.viewport.topIndex = null;
            this.parent.viewport.bottomIndex = null;
            this.translateX = null;
            this.translateY = null;
        };
        VirtualScroll.prototype.updateScrollProps = function (args) {
            var _this = this;
            Iif (args === void 0) { args = { sheetIndex: 0, sheets: this.parent.sheets }; }
            if (this.scroll.length === 0) {
                this.initScroll();
            }
            else {
                args.sheets.forEach(function () { _this.scroll.splice(args.sheetIndex, 0, { rowCount: 0, colCount: 0 }); });
            }
        };
        VirtualScroll.prototype.sliceScrollProps = function (args) {
            if (ej2_base_1.isNullOrUndefined(args.sheetIndex)) {
                this.scroll.length = 0;
            }
            else {
                this.scroll.splice(args.sheetIndex, 1);
            }
        };
        VirtualScroll.prototype.updateTranslate = function (args) {
            if (args.height) {
                if (args.isRender) {
                    this.translateY -= args.height;
                }
                else {
                    var height = parseInt(this.parent.getMainContent().getElementsByClassName('e-virtualtrack')[0].style.height, 10);
                    if (args.isHide) {
                        this.updateVTrack(this.rowHeader, height - args.height, 'height');
                        this.setThresholdHeight(this.translateY, ((args.prevSize - 1) - this.parent.viewport.topIndex) + 1, this.parent.frozenRowCount(this.parent.getActiveSheet()));
                    }
                    else {
                        this.updateVTrack(this.rowHeader, height + args.height, 'height');
                        this.translateY = this.translateY + args.size;
                    }
                }
                this.translate({ refresh: 'Row' });
            }
            if (args.width) {
                this.translateX -= args.width;
                this.translate({ refresh: 'Column' });
            }
        };
        VirtualScroll.prototype.addEventListener = function () {
            this.parent.on(index_1.beforeContentLoaded, this.createVirtualElement, this);
            this.parent.on(index_1.beforeVirtualContentLoaded, this.translate, this);
            this.parent.on(index_1.virtualContentLoaded, this.updateColumnWidth, this);
            this.parent.on(index_2.updateTableWidth, this.updateColumnWidth, this);
            this.parent.on(index_3.onVerticalScroll, this.onVerticalScroll, this);
            this.parent.on(index_3.onHorizontalScroll, this.onHorizontalScroll, this);
            this.parent.on(index_5.updateRowColCount, this.updateRowColCount, this);
            this.parent.on(index_3.rowHeightChanged, this.updateVTrackHeight, this);
            this.parent.on(index_2.colWidthChanged, this.updateVTrackWidth, this);
            this.parent.on(index_3.deInitProperties, this.deInitProps, this);
            this.parent.on(index_5.sheetsDestroyed, this.sliceScrollProps, this);
            this.parent.on(index_5.sheetCreated, this.updateScrollProps, this);
            this.parent.on(index_2.updateTranslate, this.updateTranslate, this);
            this.parent.on(index_1.spreadsheetDestroyed, this.destroy, this);
        };
        VirtualScroll.prototype.destroy = function () {
            this.removeEventListener();
            this.rowHeader = null;
            this.colHeader = null;
            this.content = null;
            this.parent = null;
            this.scroll.length = 0;
            this.translateX = null;
            this.translateY = null;
        };
        VirtualScroll.prototype.removeEventListener = function () {
            this.parent.off(index_1.beforeContentLoaded, this.createVirtualElement);
            this.parent.off(index_1.beforeVirtualContentLoaded, this.translate);
            this.parent.off(index_1.virtualContentLoaded, this.updateColumnWidth);
            this.parent.off(index_2.updateTableWidth, this.updateColumnWidth);
            this.parent.off(index_3.onVerticalScroll, this.onVerticalScroll);
            this.parent.off(index_3.onHorizontalScroll, this.onHorizontalScroll);
            this.parent.off(index_5.updateRowColCount, this.updateRowColCount);
            this.parent.off(index_3.rowHeightChanged, this.updateVTrackHeight);
            this.parent.off(index_2.colWidthChanged, this.updateVTrackWidth);
            this.parent.off(index_5.sheetsDestroyed, this.sliceScrollProps);
            this.parent.off(index_5.sheetCreated, this.updateScrollProps);
            this.parent.off(index_2.updateTranslate, this.updateTranslate);
            this.parent.off(index_1.spreadsheetDestroyed, this.destroy);
        };
        return VirtualScroll;
    }());
    exports.VirtualScroll = VirtualScroll;
});