"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const _ids_1 = require("../../../../_ids");
const globalComponent_1 = require("../../../../globalComponent");
class SizeObserver extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['component', 'opt'],
            fo: [],
            i: [],
            o: ['width', 'height'],
        }, {
            input: {
                component: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_SIZE_OBSERVER);
    }
    async f({ component, opt }, done) {
        const { api: { document: { ResizeObserver }, }, } = this.__system;
        const observer_callback = (entries) => {
            const entry = entries[0];
            const { width, height } = entry.contentRect;
            this._output.width.push(width);
            this._output.height.push(height);
        };
        const observer = new ResizeObserver(observer_callback);
        this._observer = observer;
        const globalId = component.getGlobalId();
        const component_ = (await (0, globalComponent_1.firstGlobalComponentPromise)(this.__system, globalId));
        const leaf = component_.getFirstRootLeaf();
        const { $node } = leaf;
        this._observer.observe($node);
    }
    d() {
        if (this._observer) {
            this._observer.disconnect();
            this._observer = undefined;
        }
    }
}
exports.default = SizeObserver;
//# sourceMappingURL=index.js.map