UNPKG

devexpress-reporting

Version:

DevExpress Reporting provides the capability to develop a reporting application to create and customize reports.

75 lines (74 loc) 2.88 kB
/** * DevExpress HTML/JS Reporting (viewer\internal\_pageLoader.js) * Version: 24.2.6 * Build date: Mar 18, 2025 * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * License: https://www.devexpress.com/Support/EULAs/universal.xml */ import { DxDeferred } from '@devexpress/analytics-core/analytics-internal-native'; import { PreloadedPagesOffset } from '../settings'; export class PageLoader { get pages() { return this._preview.pages || []; } _getNextStartingIndex(currentIndex) { return this.pages.find(page => page?.pageIndex > currentIndex && !page.imageSrc)?.pageIndex; } _getPagesToUpdate(startIndex, endIndex, currentPageIndex) { return this.pages.slice(startIndex, endIndex).filter(page => { if (currentPageIndex !== undefined) { return page.pageIndex !== currentPageIndex; } return !page.imageSrc; }); } _performPrefetch(pagesToUpdate, resolution, forcePng) { pagesToUpdate.forEach(page => this._preview.updatePage(page, resolution, forcePng)); } _scheduleNextPrefetch(currentIndex, pendingPages) { this._loadTimeout = setTimeout(() => { const startIndex = this._getNextStartingIndex(currentIndex); if (!startIndex) { this.reset(); return; } const promises = pendingPages.map(page => page.lastGetPageDeferred?.promise()).filter(x => !!x); DxDeferred.when(promises).done(() => { !this._disabled && this.prefetchPages(startIndex, startIndex + PreloadedPagesOffset(), undefined); }); }, 700); } constructor(_preview) { this._preview = _preview; this._defaultResolution = 0.25; this._requestCyclesLimit = 5; this._currentPrefetchCycle = 0; this._disabled = true; } prefetchPages(startIndex, endIndex, currentPageIndex) { this._disabled = false; let zoom = this._preview.originalZoom; let forcePng = false; if (currentPageIndex === undefined) { zoom = this._defaultResolution; this._currentPrefetchCycle++; forcePng = true; } if (startIndex > this.pages.length - 1 || this._currentPrefetchCycle >= this._requestCyclesLimit) { this.reset(); return; } const pendingPages = this._getPagesToUpdate(startIndex, endIndex, currentPageIndex); this._performPrefetch(pendingPages, zoom, forcePng); this._scheduleNextPrefetch(endIndex, pendingPages); } reset() { this._loadTimeout && clearTimeout(this._loadTimeout); this._loadTimeout = null; this._disabled = true; this._currentPrefetchCycle = 0; } isActive() { return !!this._loadTimeout; } }