'use strict';

// import { h } from '@stencil/core';
const listeners = [];
const visible = [];
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] });
const addListener = (listener) => listeners.push(listener);
const removeListener = (listener) => listeners.splice(listeners.indexOf(listener), 1);
const observe = (el) => el && observer.observe(el);

const IntersectionHelper = /*#__PURE__*/Object.freeze({
  __proto__: null,
  observer: observer,
  addListener: addListener,
  removeListener: removeListener,
  observe: observe
});

exports.IntersectionHelper = IntersectionHelper;
exports.addListener = addListener;
exports.observe = observe;
