import { DirectiveParameters } from "../types" ; function intersectDirective ( { element , expression , evaluate , setState , } ) { const { options = { } } = evaluate ( expression ) ; let triggered = false ; const observer = new IntersectionObserver ( ( entries ) => { if ( options . once && triggered ) { return ; } const intersected = entries . some ( ( entry ) => { return entry . intersectionRatio > 0 ; } ) ; if ( ! intersected ) { return ; } triggered = true ; setState ( evaluate ( expression ) . state , { element } ) ; } , Object . assign ( { } , { rootMargin : "0px" , threshold : 1.0 , } , options ) ) ; observer . observe ( element ) ; } intersectDirective . skipEvaluation = true ; export default intersectDirective ;