// import { CSS_UTILITY } from './resources';
// import { guid } from './guid';
/** Determines if element contains text */
const hasText = (element) => element.textContent.trim() !== '';
// export const getElementProp = (element: Element, prop: string, fallbackValue: any): any => {
//   const closest = element.closest(`[${prop}]`);
//   return closest ? closest.getAttribute(prop) : fallbackValue;
// };
const getRootNode = (element) => element.getRootNode();
const getHost = (root) => root.host || null;
// // Queries an element's rootNode and any ancestor rootNodes.
// // based on https://stackoverflow.com/q/54520554/194216
// export const queryElementsRoots = <T extends Element = Element>(element: Element, selector: string): T[] => {
//   // Gets the rootNode and any ancestor rootNodes (shadowRoot or document) of an element and queries them for a selector.
//   const queryFromAll = <T extends Element = Element>(element: Element, allResults: T[]): T[] => {
//     if (!element) return allResults;
//     if ((element as Slottable).assignedSlot) element = (element as Slottable).assignedSlot;
//     const rootNode = getRootNode(element);
//     const results = [...rootNode.querySelectorAll(selector)] as T[];
//     const uniqueResults = results.filter((result) => !allResults.includes(result));
//     allResults = [...allResults, ...uniqueResults];
//     const host = getHost(rootNode);
//     return host ? queryFromAll(host, allResults) : allResults;
//   };
//   return queryFromAll(element, []);
// };
// Queries element's rootNode and ancestor rootNodes.
// Based on https://stackoverflow.com/q/54520554/194216
const queryElementRoots = (element, selector) => {
  // Gets the rootNode and any ancestor rootNodes (shadowRoot or document) of an element and queries them for a selector.
  const queryFrom = (element) => {
    if (!element)
      return null;
    if (element.assignedSlot)
      element = element.assignedSlot;
    const rootNode = getRootNode(element);
    const found = rootNode.querySelector(selector);
    const host = getHost(rootNode);
    return found ? found : host ? queryFrom(host) : null;
  };
  return queryFrom(element);
};
const closestElementCrossShadowBoundary = (element, selector) => {
  // based on https://stackoverflow.com/q/54520554/194216
  const closestFrom = (element) => element ? element.closest(selector) || closestFrom(getHost(getRootNode(element))) : null;
  return closestFrom(element);
};

const getLabelText = (element) => { var _a; return hasText(element) ? element.textContent : ((_a = document.querySelector(`label[for="${element.id}"]`)) === null || _a === void 0 ? void 0 : _a.textContent) || ''; };
const guid = () => [2, 1, 1, 1, 3]
  .map((count) => {
  let out = '';
  for (let i = 0; i < count; i++) {
    out += (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  }
  return out;
})
  .join('-');
const mapGet = (key, obj, fallback = 'default') => obj[key] || obj[fallback] || undefined;

export { guid as a, closestElementCrossShadowBoundary as c, getLabelText as g, hasText as h, mapGet as m, queryElementRoots as q };

//# sourceMappingURL=utils-5982bee2.js.map