all files / spreadsheet/renderer/ render.js

91.93% Statements 296/322
84.68% Branches 210/248
100% Functions 19/19
91.88% Lines 294/320
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   885× 885× 885×   885× 885× 885× 885×   885×     885×   885× 885× 880×       885×       885×             885×   885× 885× 885×   1177× 1177× 1177× 1177× 1177× 1177× 83× 83× 83×     83×       83×   83×     82×       1094×   1177× 1177× 1177× 1142× 1142× 55× 55×       35× 35× 35× 35× 35× 35× 35×   35× 35× 14×   35× 35×   35×       27×   35×   35× 14× 14×   14×         1177× 1177× 1177×   2017× 2017× 840×   2017× 2017× 2017× 2017× 2017× 2017× 1544× 1490× 1490× 1490× 1490× 1490× 25× 25×   1490× 183×     1307×   1490× 184×     1306×   1490×   1490× 1490× 1490×     1490× 1490× 1490× 1490× 1490× 24× 24× 24×         1490× 183×     1307×   1490×   1490× 1490× 1490×     1490× 1490× 1490× 1490× 1490× 26× 26× 26×           1490× 184×     1306×   1490× 183× 183×   183×   1490× 184× 184×   184×   1490× 1490× 1490× 1490× 1490×     54× 54×   54× 54× 54×     2017× 1177×   2017× 2017× 2017× 2017× 2016× 128×   1888× 1888×       1879× 1879× 1879× 1879×   1042× 1042×   181× 181× 181× 181× 181×     181×   183×       181×   424×       424×   49×       49×   1877×       2017×   1094× 1094× 1094× 78× 78× 11×       1016×   1016× 25×     1094× 85× 85×       1009×   1009× 12×       292× 290×     292× 292× 292×       292× 292× 292× 292× 292× 54×     892× 892× 892× 892× 892×                       892×         892× 892× 892×   892×   892× 892× 892× 892× 892×   1784× 1784× 1784×   14× 14×     36×                 885× 885× 885×   885× 885× 885× 885×   885×   885× 885× 885×   885× 885× 885×        
define(["require", "exports", "./index", "@syncfusion/ej2-base", "../../workbook/index", "../../workbook/index", "../common/index", "../common/index", "../common/index", "../common/index"], function (require, exports, index_1, ej2_base_1, index_2, index_3, index_4, index_5, index_6, index_7) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Render = (function () {
        function Render(parent) {
            this.parent = parent;
            this.addEventListener();
            this.instantiateRenderer();
        }
        Render.prototype.render = function () {
            this.parent.setProperties({ activeSheetIndex: this.parent.skipHiddenSheets(this.parent.activeSheetIndex) }, true);
            Eif (!this.parent.isMobileView()) {
                this.parent.notify(index_7.ribbon, null);
                this.parent.notify(index_7.formulaBar, null);
            }
            var sheetPanel = this.parent.createElement('div', {
                id: this.parent.element.id + '_sheet_panel', className: 'e-sheet-panel'
            });
            if (this.parent.enableRtl) {
                sheetPanel.classList.add('e-rtl');
            }
            this.parent.element.appendChild(sheetPanel);
            if (this.parent.showSheetTabs) {
                this.parent.notify(index_4.sheetTabs, null);
            }
            else {
                this.parent.notify(index_3.workbookFormulaOperation, { action: 'initSheetInfo' });
                this.parent.notify(index_3.workbookFormulaOperation, { action: 'initiateDefinedNames' });
            }
            Iif (this.parent.isMobileView()) {
                this.parent.notify(index_7.formulaBar, null);
                this.parent.notify(index_7.ribbon, null);
            }
            Iif (this.parent.password && (this.parent.password.length > 0 || this.parent.isProtected)) {
                this.parent.isProtected = true;
                if (this.parent.showSheetTabs) {
                    this.parent.element.querySelector('.e-add-sheet-tab').setAttribute('disabled', 'true');
                    this.parent.element.querySelector('.e-add-sheet-tab').classList.add('e-disabled');
                }
            }
            if (this.parent.selectionSettings.mode === 'None') {
                this.parent.allowAutoFill = false;
            }
            this.setSheetPanelSize();
            this.renderSheet(sheetPanel);
            this.checkTopLeftCell(!this.parent.refreshing);
        };
        Render.prototype.checkTopLeftCell = function (initLoad, isRefreshing, scrollTop, scrollLeft, preventModelCheck, openOptions) {
            var sheet = this.parent.getActiveSheet();
            this.parent.showSpinner();
            var isTopLeftCell = sheet.topLeftCell === 'A1';
            var indexes = index_3.getCellIndexes(sheet.topLeftCell);
            var isFreezeScrolled;
            if (sheet.topLeftCell !== sheet.paneTopLeftCell && (sheet.frozenRows || sheet.frozenColumns)) {
                var paneIndexes = index_3.getCellIndexes(sheet.paneTopLeftCell);
                isFreezeScrolled = this.parent.scrollSettings.enableVirtualization;
                isTopLeftCell = sheet.frozenRows && sheet.frozenColumns ? indexes[0] + sheet.frozenRows === paneIndexes[0] &&
                    indexes[1] + sheet.frozenColumns === paneIndexes[1] : (sheet.frozenRows ? indexes[0] + sheet.frozenRows === paneIndexes[0]
                    && indexes[1] === 0 : indexes[1] + sheet.frozenColumns === paneIndexes[1] && indexes[0] === 0);
                Iif (indexes[0] && paneIndexes[0] > indexes[0]) {
                    this.parent.viewport.beforeFreezeHeight = index_2.getRowsHeight(sheet, 0, indexes[0] - 1, true);
                }
                else {
                    this.parent.viewport.beforeFreezeHeight = 0;
                }
                if (indexes[1] && paneIndexes[1] > indexes[1]) {
                    this.parent.viewport.beforeFreezeWidth = index_2.getColumnsWidth(sheet, 0, indexes[1] - 1, true);
                }
                else {
                    this.parent.viewport.beforeFreezeWidth = 0;
                }
            }
            else {
                this.parent.viewport.beforeFreezeHeight = this.parent.viewport.beforeFreezeWidth = 0;
            }
            var frozenRow = this.parent.frozenRowCount(sheet);
            var frozenCol = this.parent.frozenColCount(sheet);
            if (!this.parent.scrollSettings.enableVirtualization || isTopLeftCell) {
                this.refreshUI({ rowIndex: indexes[0], colIndex: indexes[1], refresh: 'All' }, null, initLoad, isRefreshing, preventModelCheck, openOptions);
                if (isFreezeScrolled) {
                    this.parent.viewport.topIndex = index_3.skipHiddenIdx(sheet, frozenRow, true) - frozenRow;
                    this.parent.viewport.leftIndex = index_3.skipHiddenIdx(sheet, frozenCol, true, 'columns') - frozenCol;
                }
            }
            else {
                var pIndexes = sheet.paneTopLeftCell === sheet.topLeftCell ? indexes : index_3.getCellIndexes(sheet.paneTopLeftCell);
                var eventArgs = { preventScroll: true };
                eventArgs.scrollTop = scrollTop || (pIndexes[0] > frozenRow ? index_2.getRowsHeight(sheet, frozenRow, pIndexes[0] - 1, true) : 0);
                eventArgs.scrollLeft = scrollLeft || (pIndexes[1] > frozenCol ? index_2.getColumnsWidth(sheet, frozenCol, pIndexes[1] - 1, true) : 0);
                this.parent.notify(index_4.onContentScroll, eventArgs);
                var threshold = this.parent.getThreshold('row');
                var rowIndex = sheet.frozenRows ? indexes[0] : (indexes[0] > threshold ?
                    index_3.skipHiddenIdx(sheet, indexes[0] - threshold, true) : 0);
                var frozenIndexes = [];
                if (sheet.frozenRows) {
                    frozenIndexes.push(pIndexes[0] - threshold > frozenRow ? pIndexes[0] - threshold : frozenRow);
                }
                threshold = this.parent.getThreshold('col');
                var colIndex = sheet.frozenColumns ? indexes[1] :
                    (indexes[1] > threshold ? index_3.skipHiddenIdx(sheet, indexes[1] - threshold, true, 'columns') : 0);
                if (sheet.frozenColumns) {
                    Iif (!frozenIndexes.length) {
                        frozenIndexes.push(frozenRow);
                    }
                    frozenIndexes.push(pIndexes[1] - threshold > frozenCol ? pIndexes[1] - threshold : frozenCol);
                }
                else if (frozenIndexes.length) {
                    frozenIndexes.push(frozenCol);
                }
                this.refreshUI({ rowIndex: rowIndex, colIndex: colIndex, refresh: 'All', top: eventArgs.scrollTop, left: eventArgs.scrollLeft,
                    frozenIndexes: frozenIndexes }, null, initLoad, isRefreshing, preventModelCheck, openOptions);
                if (isFreezeScrolled) {
                    Eif (frozenRow && frozenIndexes[0] >= frozenRow) {
                        this.parent.viewport.topIndex = index_3.skipHiddenIdx(sheet, frozenIndexes[0], true) - frozenRow;
                    }
                    if (frozenCol && frozenIndexes[1] >= frozenCol) {
                        this.parent.viewport.leftIndex = index_3.skipHiddenIdx(sheet, frozenIndexes[1], true, 'columns') - frozenCol;
                    }
                }
            }
        };
        Render.prototype.renderSheet = function (panel) {
            if (panel === void 0) { panel = document.getElementById(this.parent.element.id + '_sheet_panel'); }
            panel.appendChild(this.parent.createElement('div', { className: 'e-sheet', id: this.parent.element.id + '_sheet', styles: 'background-color: #fff' }));
            this.parent.serviceLocator.getService('sheet').renderPanel();
        };
        Render.prototype.refreshUI = function (args, address, initLoad, isRefreshing, preventModelCheck, openOptions) {
            var _this = this;
            if (args.refresh !== 'All') {
                this.parent.showSpinner();
            }
            var sheetModule = this.parent.serviceLocator.getService('sheet');
            var sheet = this.parent.getActiveSheet();
            var sheetName = index_2.getSheetName(this.parent);
            var prevRowColCnt = { rowCount: sheet.rowCount, colCount: sheet.colCount };
            args.frozenIndexes = args.frozenIndexes ? args.frozenIndexes : [];
            if (!address) {
                if (this.parent.scrollSettings.enableVirtualization) {
                    var lastRow = args.rowIndex + this.parent.viewport.rowCount + (this.parent.getThreshold('row') * 2);
                    var lastCol = args.colIndex + this.parent.viewport.colCount + (this.parent.getThreshold('col') * 2);
                    var frozenRow = this.parent.frozenRowCount(sheet);
                    var frozenCol = this.parent.frozenColCount(sheet);
                    if (args.frozenIndexes.length) {
                        lastRow += (args.frozenIndexes[0] - frozenRow);
                        lastCol += (args.frozenIndexes[1] - frozenCol);
                    }
                    if (args.refresh === 'Row') {
                        lastRow += frozenRow;
                    }
                    else {
                        lastRow += sheet.frozenRows;
                    }
                    if (args.refresh === 'Column') {
                        lastCol += frozenCol;
                    }
                    else {
                        lastCol += sheet.frozenColumns;
                    }
                    var rowIdx = args.frozenIndexes[0] > frozenRow ? args.frozenIndexes[0] : args.rowIndex + (args.refresh === 'Row' ?
                        frozenRow : sheet.frozenRows);
                    var indexes = this.parent.skipHidden(rowIdx, lastRow, 'rows', false);
                    lastRow = indexes[1];
                    if (rowIdx !== indexes[0]) {
                        var topLeftCell = index_3.getCellIndexes(sheet.paneTopLeftCell);
                        if (topLeftCell[0] === rowIdx) {
                            this.parent.updateTopLeftCell(indexes[0] - frozenRow, topLeftCell[1], 'col');
                        }
                    }
                    indexes[0] -= frozenRow;
                    var count = sheet.rowCount - 1;
                    var diff = 0;
                    var startRow = args.rowIndex;
                    if (this.parent.scrollSettings.isFinite && lastRow > count) {
                        diff = lastRow - count;
                        lastRow = index_3.skipHiddenIdx(sheet, count, false);
                        if (indexes[0] + frozenRow > index_3.skipHiddenIdx(sheet, frozenRow, true)) {
                            var startIdx = args.rowIndex - diff;
                            startIdx = startIdx < 0 ? 0 : startIdx;
                            startIdx = this.decreaseHidden(startIdx, args.rowIndex - 1, frozenRow);
                            Eif (args.top && startIdx < args.rowIndex) {
                                this.parent.notify(index_4.updateTranslate, { height: index_2.getRowsHeight(sheet, startIdx + frozenRow, args.rowIndex - 1 + frozenRow, true),
                                    isRender: true });
                            }
                            this.parent.viewport.topIndex = indexes[0] = startIdx;
                            startRow = args.refresh === 'Row' ? startIdx : startRow;
                        }
                    }
                    if (args.refresh === 'Row') {
                        args.rowIndex = index_3.skipHiddenIdx(sheet, startRow + frozenRow, true) - frozenRow;
                    }
                    else {
                        startRow = args.rowIndex = frozenRow ? index_3.skipHiddenIdx(sheet, startRow, true) : indexes[0];
                    }
                    var colIdx = args.frozenIndexes[1] > frozenCol ? args.frozenIndexes[1] : args.colIndex + (args.refresh ===
                        'Column' ? frozenCol : sheet.frozenColumns);
                    indexes = this.parent.skipHidden(colIdx, lastCol, 'columns', false);
                    lastCol = indexes[1];
                    if (colIdx !== indexes[0]) {
                        var topLeftCell = index_3.getCellIndexes(sheet.paneTopLeftCell);
                        if (topLeftCell[1] === colIdx) {
                            this.parent.updateTopLeftCell(topLeftCell[0], indexes[0] - frozenCol, 'row');
                        }
                    }
                    indexes[0] -= frozenCol;
                    count = sheet.colCount - 1;
                    diff = 0;
                    var startCol = args.colIndex;
                    if (this.parent.scrollSettings.isFinite && lastCol > count) {
                        diff = lastCol - count;
                        lastCol = index_3.skipHiddenIdx(sheet, count, false, 'columns');
                        if (indexes[0] + frozenCol > index_3.skipHiddenIdx(sheet, frozenCol, true, 'columns')) {
                            var startIdx = args.colIndex - diff;
                            startIdx = startIdx > -1 ? startIdx : 0;
                            startIdx = this.decreaseHidden(startIdx, args.colIndex - 1, frozenCol, 'columns');
                            Iif (args.left && startIdx < args.colIndex) {
                                this.parent.notify(index_4.updateTranslate, { width: index_2.getColumnsWidth(sheet, startIdx + frozenCol, args.colIndex - 1 + frozenCol, true),
                                    isRender: true });
                            }
                            this.parent.viewport.leftIndex = indexes[0] = startIdx;
                            startCol = args.refresh === 'Column' ? startIdx : startCol;
                        }
                    }
                    if (args.refresh === 'Column') {
                        args.colIndex = index_3.skipHiddenIdx(sheet, startCol + frozenCol, true, 'columns') - frozenCol;
                    }
                    else {
                        startCol = args.colIndex = frozenCol ? index_3.skipHiddenIdx(sheet, startCol, true, 'columns') : indexes[0];
                    }
                    if (args.refresh === 'Row') {
                        startRow += frozenRow;
                        if (frozenRow) {
                            lastRow += index_3.getCellIndexes(sheet.topLeftCell)[0];
                        }
                        lastCol = this.parent.viewport.rightIndex;
                    }
                    if (args.refresh === 'Column') {
                        startCol += frozenCol;
                        if (frozenCol) {
                            lastCol += index_3.getCellIndexes(sheet.topLeftCell)[1];
                        }
                        lastRow = this.parent.viewport.bottomIndex;
                    }
                    this.parent.viewport.topIndex = args.rowIndex;
                    this.parent.viewport.bottomIndex = lastRow;
                    this.parent.viewport.leftIndex = args.colIndex;
                    this.parent.viewport.rightIndex = lastCol;
                    address = index_3.getCellAddress(startRow, startCol) + ":" + index_3.getCellAddress(lastRow, lastCol);
                }
                else {
                    Eif (args.refresh === 'All') {
                        this.updateTopLeftScrollPosition(ej2_base_1.extend(args, { sheet: sheet }));
                    }
                    this.parent.viewport.bottomIndex = sheet.rowCount - 1;
                    this.parent.viewport.rightIndex = sheet.colCount - 1;
                    address = index_3.getCellAddress(args.rowIndex, args.colIndex) + ":" + index_3.getCellAddress(this.parent.viewport.bottomIndex, this.parent.viewport.rightIndex);
                }
            }
            if (args.refresh === 'All') {
                this.parent.trigger(index_4.beforeDataBound, {});
            }
            var isOpen = this.parent.isOpen || this.parent.refreshing;
            index_7.setAriaOptions(this.parent.getMainContent(), { busy: true });
            var sheetsLen = this.parent.sheets.length;
            index_2.getData(this.parent, sheetName + "!" + address, null, null, args.frozenIndexes).then(function (values) {
                if (!_this.parent || sheetsLen < _this.parent.sheets.length) {
                    return;
                }
                var sheetIdx = _this.parent.sheets.indexOf(sheet);
                if (!preventModelCheck && (sheetIdx === -1 || sheetIdx !== _this.parent.activeSheetIndex)) {
                    Iif (sheetIdx > -1) {
                        _this.checkTopLeftCell();
                    }
                    return;
                }
                var indexes = [args.rowIndex, args.colIndex].concat(index_3.getCellIndexes(address.split(':')[1]));
                var isEdit;
                var arg;
                switch (args.refresh) {
                    case 'All':
                        sheetModule.renderTable({ cells: values, indexes: indexes, top: args.top, left: args.left, initLoad: initLoad, isRefreshing: isRefreshing, isOpen: isOpen, openOptions: openOptions });
                        break;
                    case 'Row':
                        sheetModule.refreshRowContent({ cells: values, indexes: indexes, skipUpdateOnFirst: args.skipUpdateOnFirst, prevRowColCnt: prevRowColCnt });
                        isEdit = false;
                        arg = { isEdit: isEdit };
                        _this.parent.notify(index_5.isFormulaBarEdit, arg);
                        Iif (arg.isEdit) {
                            _this.parent.notify(index_5.editOperation, { action: 'startEdit', refreshCurPos: false });
                        }
                        break;
                    case 'Column':
                        sheetModule.refreshColumnContent({
                            cells: values, indexes: indexes, skipUpdateOnFirst: args.skipUpdateOnFirst,
                            prevRowColCnt: prevRowColCnt, insertDelete: args.insertDelete
                        });
                        break;
                    case 'RowPart':
                        sheetModule.updateRowContent({
                            cells: values, indexes: indexes, direction: args.direction, skipUpdateOnFirst: args.skipUpdateOnFirst,
                            prevRowColCnt: prevRowColCnt
                        });
                        break;
                    case 'ColumnPart':
                        sheetModule.updateColContent({
                            cells: values, indexes: indexes, direction: args.direction, skipUpdateOnFirst: args.skipUpdateOnFirst,
                            prevRowColCnt: prevRowColCnt
                        });
                        break;
                }
                Iif (_this.parent && _this.parent.isReact) {
                    _this.parent['renderReactTemplates']();
                }
            });
            this.parent.notify(index_7.beforeVirtualContentLoaded, { refresh: args.refresh, skipTranslate: args.skipTranslate });
        };
        Render.prototype.updateTopLeftScrollPosition = function (args) {
            var topLeftCell = index_3.getCellIndexes(args.sheet.topLeftCell);
            var paneTopLeftCell = index_3.getCellIndexes(args.sheet.paneTopLeftCell);
            if (args.sheet.frozenRows) {
                var frozenRow = this.parent.frozenRowCount(args.sheet);
                if (paneTopLeftCell[0] > frozenRow) {
                    args.top = index_2.getRowsHeight(args.sheet, frozenRow, paneTopLeftCell[0] - 1, true);
                }
            }
            else {
                if (args.rowIndex) {
                    args.rowIndex = 0;
                }
                if (topLeftCell[0] !== 0) {
                    args.top = index_2.getRowsHeight(args.sheet, 0, topLeftCell[0] - 1, true);
                }
            }
            if (args.sheet.frozenColumns) {
                var frozenCol = this.parent.frozenColCount(args.sheet);
                if (paneTopLeftCell[1] > frozenCol) {
                    args.left = index_2.getColumnsWidth(args.sheet, frozenCol, paneTopLeftCell[1] - 1, true);
                }
            }
            else {
                if (args.colIndex) {
                    args.colIndex = 0;
                }
                if (topLeftCell[1] !== 0) {
                    args.left = index_2.getColumnsWidth(args.sheet, 0, topLeftCell[1] - 1, true);
                }
            }
        };
        Render.prototype.removeSheet = function () {
            if (document.getElementById(this.parent.element.id + '_sheet')) {
                ej2_base_1.remove(document.getElementById(this.parent.element.id + '_sheet'));
            }
        };
        Render.prototype.refreshSheet = function (isOpen, resize, focusEle, preventModelCheck, openOptions) {
            var scrollTop = 0;
            var scrollLeft = 0;
            if (resize) {
                var mainPanel = this.parent.element.getElementsByClassName('e-main-panel')[0];
                Eif (mainPanel) {
                    scrollTop = mainPanel.scrollTop;
                }
                var sheetContent = this.parent.getMainContent();
                Eif (sheetContent) {
                    scrollLeft = sheetContent.scrollLeft;
                }
            }
            this.removeSheet();
            this.renderSheet();
            this.parent.notify(index_4.deInitProperties, {});
            this.checkTopLeftCell(false, isOpen, scrollTop, scrollLeft, preventModelCheck, openOptions);
            if (focusEle) {
                index_6.focus(this.parent.element);
            }
        };
        Render.prototype.setSheetPanelSize = function (colMinWidth) {
            var panel = document.getElementById(this.parent.element.id + '_sheet_panel');
            var offset = this.parent.element.getBoundingClientRect();
            var height;
            this.parent.viewport.scaleY = this.parent.viewport.scaleX = 1;
            Iif (this.parent.enableScaling) {
                var offsetHeight = this.parent.element.offsetHeight;
                var scaleY = offsetHeight / offset.height;
                if (scaleY !== 1 && Math.abs(offsetHeight - offset.height) >= offsetHeight * 0.1) {
                    this.parent.viewport.scaleY = scaleY;
                }
                var offsetWidth = this.parent.element.offsetWidth;
                var scaleX = offsetWidth / offset.width;
                if (scaleX !== 1 && Math.abs(offsetWidth - offset.width) >= offsetWidth * 0.1) {
                    this.parent.viewport.scaleX = scaleX;
                }
            }
            Iif (this.parent.height === 'auto') {
                panel.style.height = '260px';
                height = 230;
            }
            else {
                height = (offset.height * this.parent.viewport.scaleY) - index_6.getSiblingsHeight(panel, null, this.parent.viewport.scaleY);
                panel.style.height = height + "px";
                height -= (32 / this.parent.viewport.scaleY);
            }
            if (colMinWidth !== undefined) {
                this.colMinWidth = colMinWidth;
            }
            this.parent.viewport.height = height;
            var width = offset.width * this.parent.viewport.scaleX;
            this.parent.viewport.width = width - (32 / this.parent.viewport.scaleX);
            this.parent.viewport.rowCount = this.roundValue(height, 20);
            this.parent.viewport.colCount = this.roundValue(width, this.colMinWidth || 64);
        };
        Render.prototype.roundValue = function (size, threshold) {
            var value = size / threshold;
            var roundedValue = Math.round(value);
            return Math.abs(value - roundedValue) < 0.5 ? roundedValue : roundedValue - 1;
        };
        Render.prototype.moveOrDuplicateSheetHandler = function (args) {
            this.parent.notify(index_6.refreshSheetTabs, null);
            if (args.refresh) {
                this.refreshSheet(args.isDuplicate);
            }
        };
        Render.prototype.decreaseHidden = function (startIdx, endIdx, freezeCount, layout) {
            if (layout === void 0) { layout = 'rows'; }
            startIdx += freezeCount;
            endIdx += freezeCount;
            var sheet = this.parent.getActiveSheet();
            for (var i = endIdx; i >= startIdx; i--) {
                Iif ((sheet["" + layout])[i] && (sheet["" + layout])[i].hidden) {
                    startIdx--;
                    if (startIdx < freezeCount) {
                        startIdx = index_3.skipHiddenIdx(sheet, freezeCount, true, layout);
                        break;
                    }
                }
            }
            return startIdx - freezeCount;
        };
        Render.prototype.instantiateRenderer = function () {
            this.parent.serviceLocator.register('cell', new index_1.CellRenderer(this.parent));
            this.parent.serviceLocator.register('row', new index_1.RowRenderer(this.parent));
            this.parent.serviceLocator.register('sheet', new index_1.SheetRender(this.parent));
        };
        Render.prototype.destroy = function () {
            this.removeEventListener();
            this.parent.serviceLocator.getService('row').destroy();
            this.parent.serviceLocator.getService('cell').destroy();
            if (this.colMinWidth) {
                this.colMinWidth = null;
            }
            this.parent = null;
        };
        Render.prototype.addEventListener = function () {
            this.parent.on(index_5.spreadsheetDestroyed, this.destroy, this);
            this.parent.on(index_3.moveOrDuplicateSheet, this.moveOrDuplicateSheetHandler, this);
            this.parent.on(index_6.getUpdatedScrollPosition, this.updateTopLeftScrollPosition, this);
        };
        Render.prototype.removeEventListener = function () {
            this.parent.off(index_5.spreadsheetDestroyed, this.destroy);
            this.parent.off(index_3.moveOrDuplicateSheet, this.moveOrDuplicateSheetHandler);
            this.parent.off(index_6.getUpdatedScrollPosition, this.updateTopLeftScrollPosition);
        };
        return Render;
    }());
    exports.Render = Render;
});