// src/resources/js/scrollfx/ScrollEngine.js

class ScrollEngine {
    constructor() {
        this.triggers = new Set();
        this.viewportHeight = window.innerHeight;
        this._loop = this._loop.bind(this);

        window.addEventListener('resize', () => {
            this.viewportHeight = window.innerHeight;
        });

        requestAnimationFrame(this._loop);
    }

    register(trigger) {
        this.triggers.add(trigger);
    }

    unregister(trigger) {
        this.triggers.delete(trigger);
    }

    clear() {
        this.triggers.clear();
    }

    _loop() {
        this.triggers.forEach(trigger => {
            trigger.update(this.viewportHeight);
        });
        requestAnimationFrame(this._loop);
    }
}

export default new ScrollEngine();
