/*!
 * Custom elements for Nanopore-Digital Web applications
 */
import './index-BM3Om9WE.js';

var NODE_TYPE;
(function (NODE_TYPE) {
    NODE_TYPE[NODE_TYPE["ElementNode"] = 1] = "ElementNode";
    NODE_TYPE[NODE_TYPE["TextNode"] = 3] = "TextNode";
    NODE_TYPE[NODE_TYPE["CommentNode"] = 8] = "CommentNode";
    NODE_TYPE[NODE_TYPE["DocumentNode"] = 9] = "DocumentNode";
    NODE_TYPE[NODE_TYPE["DocumentTypeNode"] = 10] = "DocumentTypeNode";
    NODE_TYPE[NODE_TYPE["DocumentFragment"] = 11] = "DocumentFragment";
})(NODE_TYPE || (NODE_TYPE = {}));
function closestElement(selector, base = this) {
    function __closestFrom(el) {
        if (!el || el === document || el === window)
            return null;
        if (el.assignedSlot)
            el = el.assignedSlot;
        const found = el.closest(selector);
        return found
            ? found
            : __closestFrom(el.getRootNode().host);
    }
    return __closestFrom(base);
}
function getDirectChildren(el, sel, elesOnly = true) {
    /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
    if (elesOnly === true) {
        try {
            sel = ':scope > ' + sel.split(',').join(', :scope >');
            return Array.from(el.querySelectorAll(sel));
        }
        catch (e) {
            console.error(e, 'an error. sad');
        }
    }
    const ret = [];
    Array.from(el.childNodes).forEach((e) => {
        if (!!e.matches &&
            e.matches(sel) &&
            (e.nodeName !== 'SLOT' || elesOnly !== 'slot')) {
            ret.push(e);
        }
        else if (e.nodeName === 'SLOT') {
            Array.from(e.assignedElements()).forEach((slottedEl) => {
                if (slottedEl.matches(sel))
                    ret.push(slottedEl);
            });
        }
        else if (!elesOnly)
            ret.push(e);
    });
    return ret;
}
function getOffset(element, parent) {
    if (!parent || !element)
        return { top: 0, left: 0 };
    return {
        top: element.getBoundingClientRect().top - parent.getBoundingClientRect().top,
        left: element.getBoundingClientRect().left -
            parent.getBoundingClientRect().left,
    };
}

export { getOffset as a, closestElement as c, getDirectChildren as g };
