const cache = new WeakMap();
function getRootNodes(from) {
    const result = [];
    let node = from;
    while (node) {
        if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && node.host) {
            result.push(node);
        }
        node = node.host || node.assignedSlot || node.parentNode;
    }
    result.push(document);
    return result;
}
export function addListeners(element, listener) {
    removeListeners(element);
    const nodes = getRootNodes(element);
    nodes.forEach((n) => n.addEventListener('scroll', listener, { capture: true, passive: true }));
    window.addEventListener('resize', listener, { capture: true, passive: true });
    cache.set(element, {
        nodes,
        listener,
    });
}
export function removeListeners(element) {
    const info = cache.get(element);
    if (!info) {
        return;
    }
    info.nodes.forEach((n) => n.removeEventListener('scroll', info.listener, { capture: true }));
    window.removeEventListener('resize', info.listener, { capture: true });
}
//# sourceMappingURL=ScrollHelper.js.map