UNPKG

@opensig/opendesign

Version:

29 lines (28 loc) 667 B
import { useIntersectionObserver } from "./use-intersection-observer.mjs"; import { isFunction } from "../_utils/is.mjs"; let io = null; function useIntersectionObserverDirective({ listener, removeOnUnmounted }) { return { vIntersectionObserver: { beforeMount() { io = useIntersectionObserver(); }, mounted(el) { if (isFunction(listener)) { io == null ? void 0 : io.observe(el, listener); } }, unmounted(el) { if (listener && removeOnUnmounted) { io == null ? void 0 : io.unobserve(el, listener); } } } }; } export { useIntersectionObserverDirective };