"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Calculate active page based on scroll top and row size properties.
* This is useful of list with vertical-scrolled pagination.
*
* @param scrollTop
* @param rowHeight
* @param pageSize
* @param options
*
* @returns The page number (start from 1)
* @category pagination
* @module calculatePageByScrollTop
*/
var calculatePageByScrollTop = function (
/** The current scroll top */
scrollTop,
/** The height of each row */
rowHeight,
/** The number of rows on each page */
pageSize, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.startPage, startPage = _c === void 0 ? 1 : _c, _d = _b.pageBreakerHeight, pageBreakerHeight = _d === void 0 ? 0 : _d;
// Get toppest-visible row index
var topRowIndex = Math.ceil(scrollTop / rowHeight);
// Get number of page breaker(s)
var numPageBreaker = Math.floor(topRowIndex / pageSize);
// Recalculate topRowIndex with page breaker
var normTopRowIndex = Math.ceil((scrollTop - (numPageBreaker * pageBreakerHeight)) / rowHeight);
// Calculate page by page size
var calculatedPage = Math.ceil((normTopRowIndex + 1) / pageSize);
// Calculate relative page
var page = startPage - 1 + (calculatedPage < 1 ? 1 : calculatedPage);
// Return page
return page;
};
exports.default = calculatePageByScrollTop;
Source