// import { h } from '@stencil/core';
const listeners = [];
const visible = [];
export const observer = new IntersectionObserver((entries, observer) => {
    entries.forEach((e) => {
        if (e.intersectionRatio > 0) {
            if (visible.indexOf(e.target) < 0) {
                visible.push(e.target);
            }
        }
        else {
            visible.splice(visible.indexOf(e.target), 1);
        }
    });
    listeners.forEach((l) => l({ entries, observer, visible }));
}, { threshold: [0, 1] });
export const addListener = (listener) => listeners.push(listener);
export const removeListener = (listener) => listeners.splice(listeners.indexOf(listener), 1);
export const observe = (el) => el && observer.observe(el);
