import { DeviceDetector } from '../../esl-utils/environment/device-detector' ; import { ESLImage } from './esl-image' ; let iObserver ; /** ESL Image lazy loading IntersectionObserver instance */ export function getIObserver ( ) { if ( ! iObserver ) { iObserver = new IntersectionObserver ( function ( entries ) { entries . forEach ( handleViewport ) ; } , { threshold : [ 0.01 ] , rootMargin : DeviceDetector . isMobile ? '250px' : '500px' } ) ; } return iObserver ; } function handleViewport ( entry ) { const { target : image } = entry ; if ( ! ( image instanceof ESLImage ) ) return ; if ( entry . isIntersecting || entry . intersectionRatio > 0 ) { image . triggerLoad ( ) ; } }