import { action, makeObservable, observable } from 'mobx';
export class IntersectionObserverState {
    constructor() {
        this.intersectionRatio = 1;
        this.dispose = () => {
            this.observer?.disconnect();
        };
        makeObservable(this, {
            intersectionRatio: observable.ref,
        });
    }
    init({ root, target, rootMargin, }) {
        if (target == null || typeof IntersectionObserver === 'undefined') {
            return;
        }
        const observer = new IntersectionObserver(action(([{ intersectionRatio }]) => {
            this.intersectionRatio = intersectionRatio;
        }), {
            root,
            rootMargin,
        });
        observer.observe(target);
        this.observer = observer;
        return this.dispose;
    }
}
//# sourceMappingURL=IntersectionObserverState.js.map