import ResizeObserver from 'resize-observer-polyfill';
class ResizeObserverController {
    constructor() {
        this.entries = [];
    }
    getInstance() {
        if (!this.instance) {
            this.instance = this.generateObserver();
        }
        return this.instance;
    }
    generateObserver() {
        return new ResizeObserver((entries) => {
            entries.forEach((entry, index) => {
                let callback = this.entries[index].callback;
                let args = this.entries[index].args;
                callback(entry, ...args);
            });
        });
    }
    removeEntry(entry) {
        this.entries = this.entries.filter((item) => {
            return item.el != entry;
        });
        this.getInstance().unobserve(entry);
    }
    addEntry(entry, callback, ...args) {
        this.entries = [...this.entries, { el: entry, callback: callback, args }];
        this.getInstance().observe(entry);
    }
}
export const ROController = new ResizeObserverController();
