"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getByRemoteById = exports.getByRemoteOnce = exports.hasInLocal = exports.getInLocal = exports.register = exports.removeRemoteGlobalThis = exports.addRemoteGlobalThis = exports.getId = exports.setId = exports.remoteGlobalThisSet = exports.data = void 0;
exports.data = new Map();
let pipeId;
exports.remoteGlobalThisSet = new Set();
const SYMBOL_NAME = `__MOMETA_PIPE__`;
function setId(id) {
    pipeId = id;
}
exports.setId = setId;
function getId() {
    return pipeId;
}
exports.getId = getId;
function addRemoteGlobalThis(g) {
    exports.remoteGlobalThisSet.add(g);
}
exports.addRemoteGlobalThis = addRemoteGlobalThis;
function removeRemoteGlobalThis(g) {
    exports.remoteGlobalThisSet.delete(g);
}
exports.removeRemoteGlobalThis = removeRemoteGlobalThis;
function register(name, value) {
    exports.data.set(name, value);
    return () => {
        exports.data.delete(name);
    };
}
exports.register = register;
function getInLocal(name) {
    return exports.data.get(name);
}
exports.getInLocal = getInLocal;
function hasInLocal(name) {
    return exports.data.has(name);
}
exports.hasInLocal = hasInLocal;
function getByRemoteOnce(name) {
    for (const g of exports.remoteGlobalThisSet.values()) {
        if (g[SYMBOL_NAME] && g[SYMBOL_NAME].hasInLocal(name)) {
            return g[SYMBOL_NAME].getInLocal(name);
        }
    }
}
exports.getByRemoteOnce = getByRemoteOnce;
function getByRemoteById(name, id) {
    for (const g of exports.remoteGlobalThisSet.values()) {
        if (g[SYMBOL_NAME] && g[SYMBOL_NAME].getId() === id) {
            return g[SYMBOL_NAME].getInLocal(name);
        }
    }
}
exports.getByRemoteById = getByRemoteById;
const exps = {
    getId,
    getByRemoteById,
    getInLocal,
    getByRemoteOnce,
    setId,
    addRemoteGlobalThis,
    register,
    hasInLocal,
    remoteGlobalThisSet: exports.remoteGlobalThisSet,
    removeRemoteGlobalThis,
    data: exports.data
};
// console.log('globalThis[SYMBOL_NAME]', document.currentScript)
globalThis[SYMBOL_NAME] = exps;
//# sourceMappingURL=pipe.js.map