Skip to content

Commit

Permalink
#4062 - ViewportTracker should focus on block-like elements
Browse files Browse the repository at this point in the history
- Change viewport tracking from an exclude list to an include list.
  • Loading branch information
reckart committed Jun 10, 2023
1 parent d42c7b7 commit 1843e5d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions inception/inception-js-api/src/main/ts/src/util/ViewportTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -74,6 +78,10 @@ export class ViewportTracker {
.filter(e => this.shouldTrack(e))
console.debug(`Found ${trackingCandidates.length} tracking candidates`)

// const displayStyles = new Set<string>()
// 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)) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 1843e5d

Please sign in to comment.