/*!
 * KoliBri - The accessible HTML-Standard
 */
import { a as watchValidator, L as Log } from './prop.validators.js';

const escapeCssIdentifier = (value) => {
    var _a;
    if ((_a = globalThis.CSS) === null || _a === void 0 ? void 0 : _a.escape) {
        return globalThis.CSS.escape(value);
    }
    return value.replace(/[^a-zA-Z0-9_-]/g, '\\$&');
};
const resolveTargets = (host, value) => {
    const ids = (value !== null && value !== void 0 ? value : '').trim().split(/\s+/).filter(Boolean);
    if (!ids.length)
        return [];
    const root = host === null || host === void 0 ? void 0 : host.getRootNode();
    const getById = (id) => {
        if (root instanceof Document)
            return root.getElementById(id);
        if (root instanceof ShadowRoot)
            return root.querySelector(`#${escapeCssIdentifier(id)}`);
        return typeof document !== 'undefined' ? document.getElementById(id) : null;
    };
    return ids.map(getById).filter((el) => !!el);
};
const attachInternals = (host) => {
    const attach = host.attachInternals;
    if (!attach)
        return undefined;
    try {
        const internals = attach.call(host);
        return internals;
    }
    catch (_a) {
        return undefined;
    }
};

const validateAriaLabelledby = (component, host, internals, value) => {
    watchValidator(component, '_ariaLabelledby', (value) => typeof value === 'string' || typeof value === 'undefined', new Set(['string']), value);
    const elements = resolveTargets(host, value);
    if (internals) {
        try {
            internals.ariaLabelledByElements = elements;
        }
        catch (_a) {
        }
        Log.debug(['WebComponent internals', internals]);
    }
    return elements;
};

export { attachInternals as a, validateAriaLabelledby as v };
//# sourceMappingURL=aria-labelledby.js.map

//# sourceMappingURL=aria-labelledby.js.map