class ResizeListener {
    constructor(element, callback) {
        this.observer = null;
        this._disposed = false;
        this._targets = [];
        this.makeListener();
        this._element = element;
        this.add(element, callback);
    }
    isDisposed() {
        return this._disposed;
    }
    dispose() {
        if (!this._disposed) {
            this._disposed = true;
            this.remove(this._element);
        }
    }
    makeListener() {
        if (typeof ResizeObserver == "undefined")
            throw "Resize Observer non è definito. Si prega di utilizzare un browser vero";
        this.observer = new ResizeObserver((entries) => {
            for (let i = 0; i < entries.length; ++i)
                for (let t = 0; t < this._targets.length; ++t)
                    if (this._targets[t].target === entries[i].target)
                        this._targets[t].callback();
        });
    }
    add(target, callback) {
        this.observer.observe(target, { box: "content-box" });
        this._targets.push({ target, callback });
    }
    remove(target) {
        this.observer.unobserve(target);
        this._targets.splice(this._targets.findIndex(t => t.target === target), 1);
    }
}

/**
 * Generated bundle index. Do not edit.
 */

export { ResizeListener };
//# sourceMappingURL=esfaenza-core-helpers.mjs.map
