/*!
 * KoliBri - The accessible HTML-Standard
 */
import{a as e}from"./tslib.es6-QNbPBOk5.js";const t=5e3;function n(e){return new Promise(((n,o)=>{let i;const r=new MutationObserver((()=>{if(e.hasAttribute("data-themed")){if(i){clearTimeout(i)}r.disconnect();n()}}));r.observe(e,{attributes:true,attributeFilter:["data-themed"]});if(e.hasAttribute("data-themed")){r.disconnect();n();return}i=setTimeout((()=>{r.disconnect();o(new Error("Timeout waiting for data-themed attribute"))}),t)}))}const o=3;async function i(e,t){try{if(!e.hasAttribute("data-themed")){await n(e)}await t()}catch(e){throw new Error(`The interactive element inside the KoliBri web component could not be clicked. Try calling the click method on the web component after a short delay again.`)}}function r(e){if(!e)return false;const t=e.getBoundingClientRect();return t.width>0&&t.height>0}async function a(e){let t=0;do{if(e){e.click()}await new Promise((e=>requestAnimationFrame(e)));t++}while(!r(e)&&t<o)}const c=10;function s(e,t=2e3){return new Promise((n=>{let o=false;let i;let r;const a=()=>{if(o){return}o=true;clearTimeout(c);r===null||r===void 0?void 0:r();r=undefined;i===null||i===void 0?void 0:i.disconnect();n()};const c=setTimeout(a,t);if(typeof window!=="undefined"&&"onscrollend"in window){const t=t=>{const n=t.target;if(!(n instanceof Node)||!n.contains(e)){return}a()};document.addEventListener("scrollend",t,{capture:true});r=()=>{document.removeEventListener("scrollend",t,{capture:true})};return}if(typeof IntersectionObserver==="undefined"){a();return}i=new IntersectionObserver((e=>{if(e.some((e=>e.isIntersecting))){a()}}),{threshold:0});i.observe(e)}))}async function u(e,t){try{if(!e.hasAttribute("data-themed")){await n(e)}await t()}catch(e){throw new Error(`The interactive element inside the KoliBri web component could not be focused. Try calling the focus method on the web component after a short delay again.`)}}function d(e){const t=e.getRootNode();if(t instanceof ShadowRoot){return t.activeElement===e}return document.activeElement===e}const l={preventScroll:true};async function f(t,n){if(!t){return}const o=n!==null&&n!==void 0?n:{},{afterFocus:i}=o,r=e(o,["afterFocus"]);const a=n&&("behavior"in r||"block"in r||"inline"in r);let u=0;do{if(t){t.focus(l)}await new Promise((e=>requestAnimationFrame(e)));u++}while(!d(t)&&u<c);const f=d(t);if(a){const e=Object.assign(Object.assign({},r),{behavior:r.behavior});t.scrollIntoView(e)}if(i&&f){if(a&&r.behavior==="smooth"){await s(t)}i()}}export{i as a,a as b,u as d,f as s};
//# sourceMappingURL=element-focus-BQXzaLL9.js.map