import { observeIntersection as m } from "./observers.es.js";
import { Feature as w } from "../../../../../../../../motion-dom@12.38.0/node_modules/motion-dom/dist/es/render/Feature.es.js";
const l = {
  some: 0,
  all: 1
};
class g extends w {
  constructor() {
    super(...arguments), this.hasEnteredView = !1, this.isInView = !1;
  }
  startObserver() {
    var i;
    (i = this.stopObserver) == null || i.call(this);
    const { viewport: e = {} } = this.node.getProps(), { root: t, margin: r, amount: n = "some", once: p } = e, c = {
      root: t ? t.current : void 0,
      rootMargin: r,
      threshold: typeof n == "number" ? n : l[n]
    }, d = (a) => {
      const { isIntersecting: s } = a;
      if (this.isInView === s || (this.isInView = s, p && !s && this.hasEnteredView))
        return;
      s && (this.hasEnteredView = !0), this.node.animationState && this.node.animationState.setActive("whileInView", s);
      const { onViewportEnter: u, onViewportLeave: f } = this.node.getProps(), h = s ? u : f;
      h && h(a);
    };
    this.stopObserver = m(this.node.current, c, d);
  }
  mount() {
    this.startObserver();
  }
  update() {
    if (typeof IntersectionObserver > "u")
      return;
    const { props: e, prevProps: t } = this.node;
    ["amount", "margin", "root"].some(v(e, t)) && this.startObserver();
  }
  unmount() {
    var e;
    (e = this.stopObserver) == null || e.call(this), this.hasEnteredView = !1, this.isInView = !1;
  }
}
function v({ viewport: o = {} }, { viewport: e = {} } = {}) {
  return (t) => o[t] !== e[t];
}
export {
  g as InViewFeature
};
//# sourceMappingURL=index.es.js.map
