import { __values } from "tslib";
var ModuleManager = /** @class */ (function () {
    function ModuleManager() {
    }
    ModuleManager.register = function () {
        var e_1, _a;
        var modules = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            modules[_i] = arguments[_i];
        }
        try {
            for (var modules_1 = __values(modules), modules_1_1 = modules_1.next(); !modules_1_1.done; modules_1_1 = modules_1.next()) {
                var mod = modules_1_1.value;
                if (mod.register) {
                    mod.register();
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (modules_1_1 && !modules_1_1.done && (_a = modules_1.return)) _a.call(modules_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        RegisterElementHelper.force();
    };
    return ModuleManager;
}());
export { ModuleManager };
var RegisterElementHelper = /** @class */ (function () {
    function RegisterElementHelper() {
    }
    RegisterElementHelper.registerElement = function (tagName, cons) {
        RegisterElementHelper._queue.push(function () {
            if (window.customElements) {
                window.customElements.define(tagName, cons);
            }
            else {
                document.registerElement(tagName, cons);
            }
        });
        RegisterElementHelper.queueUpdate();
    };
    RegisterElementHelper.queueUpdate = function () {
        this._timerId = window.setTimeout(function () { return RegisterElementHelper.doUpdate(); }, 0);
    };
    RegisterElementHelper.force = function () {
        if (this._timerId >= 0) {
            window.clearTimeout(this._timerId);
            this._timerId = -1;
        }
        this.doUpdate();
    };
    RegisterElementHelper.doUpdate = function () {
        this._timerId = -1;
        this._updateQueued = false;
        while (RegisterElementHelper._queue.length > 0) {
            var ele = RegisterElementHelper._queue.shift();
            ele();
        }
    };
    RegisterElementHelper._queue = [];
    RegisterElementHelper._updateQueued = false;
    RegisterElementHelper._timerId = -1;
    return RegisterElementHelper;
}());
export { RegisterElementHelper };
