"use strict";var t=require("./kd/tooltipLibrary.js");const e=/^input$|^select$|^textarea$|^a$|^button$/;function n(t,e){if(!t)return;if(t.nodeType===Node.ELEMENT_NODE){if(t.hasAttribute("inert"))return;if(function(t){return"IFRAME"===t.tagName||t instanceof HTMLIFrameElement}(t))return void(t.contentDocument?n(t.contentDocument,e):e&&e(t));if(e&&e(t),t.shadowRoot)return void n(t.shadowRoot,e);if("slot"===t.localName){const o=t.assignedNodes({flatten:!0});for(let t=0;t<o.length;t++)n(o[t],e);return}}let o=t.firstChild;for(;null!==o;)n(o,e),o=o.nextSibling}const o=["button","select","textarea","input"],r=["a","select","textarea","input","button","iframe","object","area","frame"];const i=t=>"tooltip"===t.getAttribute("role"),u=t=>t.classList.contains("ignore-autofocus"),c=e=>{const n="button"===e.tagName.toLowerCase(),o=e.getAttribute("aria-describedby"),r=!!o&&0===String(o).indexOf(t.BUBBLE_PREFIX);return n&&r},a=t=>{if(!t)return!1;return![i(t),c(t),u(t)].some(t=>!0===t)};exports.filterTooltips=function(t){return t&&Array.isArray(t)&&t.length>0?t.filter(a):[]},exports.findAllFocusableNodes=function(t){const o=[];return n(t,t=>{e.test(t.tagName.toLowerCase())&&o.push(t)}),o},exports.findAllTabbableElements=function(t){const e=[];return n(t,n=>{try{(function({element:t,rootContainer:e}){const n=t.localName;if("input"===n&&"hidden"===n.type)return!1;const i=t.getAttribute("tabindex");if("-1"===i)return!1;if(t.disabled&&o.includes(t.localName))return!1;const u="0"===i||0===t.tabIndex&&r.includes(t.localName);return u&&function(t){const{width:e,height:n}=t.getBoundingClientRect();return(e>0||n>0)&&"hidden"!==getComputedStyle(t).visibility}(t)&&function({element:t,rootContainer:e}){const n=e.getRootNode(),{ownerDocument:o}=t;let r=t.getRootNode();for(;r!==n&&r!==o;){const{host:t}=r;if("-1"===t.getAttribute("tabindex"))return!1;r=t&&t.getRootNode()}return!0}({element:t,rootContainer:e})})({element:n,rootContainer:t})&&e.push(n)}catch(t){}}),e},exports.getElementWithFocus=function(){let t=document.activeElement;for(;t;)if(t.shadowRoot){const e=t.shadowRoot.activeElement;if(!e)return t;t=e}else{if(!t.contentDocument)return t;{const e=t.contentDocument.activeElement;if(!e)return t;t=e}}},exports.returnFocusToElement=function(t){const e=document.body.contains(t);if(t){if(e)return t.focus(),!0;const n=function(t){let e=t;for(;e&&e.parentNode;){if(e.parentNode===document)return!0;e=e.parentNode instanceof DocumentFragment?e.parentNode.host:e.parentNode}return!1}(t);if(n)return t.focus(),!0}return!1};
