From 1843e5d469bf256795bc8b3383084902ff07ee3d Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Sat, 10 Jun 2023 22:05:24 +0200 Subject: [PATCH] #4062 - ViewportTracker should focus on block-like elements - Change viewport tracking from an exclude list to an include list. --- .../src/main/ts/src/util/ViewportTracker.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/inception/inception-js-api/src/main/ts/src/util/ViewportTracker.ts b/inception/inception-js-api/src/main/ts/src/util/ViewportTracker.ts index bc3442ac1f9..0893e79ceda 100644 --- a/inception/inception-js-api/src/main/ts/src/util/ViewportTracker.ts +++ b/inception/inception-js-api/src/main/ts/src/util/ViewportTracker.ts @@ -60,7 +60,11 @@ export class ViewportTracker { if (!style.display) { return false } - return !style.display.startsWith('inline') + + return style.display === 'block' || style.display === 'flex' || style.display === 'grid' || + style.display.includes('table') + + // return !style.display.startsWith('inline') && !style.display.includes('math') } private initializeElementTracking (element: Element): void { @@ -74,6 +78,10 @@ export class ViewportTracker { .filter(e => this.shouldTrack(e)) console.debug(`Found ${trackingCandidates.length} tracking candidates`) + // const displayStyles = new Set() + // trackingCandidates.map(e => getComputedStyle(e).display).forEach(e => displayStyles.add(e)) + // console.debug('Display styles found: ', displayStyles) + if (trackingCandidates.length > 0) { trackingCandidates = trackingCandidates.map(e => { if (!this.sectionSelector || e.matches(this.sectionSelector)) { @@ -109,8 +117,9 @@ export class ViewportTracker { entries.forEach(entry => { if (entry.isIntersecting) { + const sizeBefore = this._visibleElements.size this._visibleElements.add(entry.target) - visibleElementsAdded++ + if (sizeBefore < this._visibleElements.size) visibleElementsAdded++ } else { this._visibleElements.delete(entry.target) }