var e=`_top`,t=class extends HTMLElement{_current=this.querySelector(`a[aria-current="true"]`);minH=parseInt(this.dataset.minH||`2`,10);maxH=parseInt(this.dataset.maxH||`3`,10);tocHeadingSelector=`h1#${e},:where(${[...Array.from({length:1+this.maxH-this.minH}).map((e,t)=>`h${this.minH+t}`)].join()})[id]`;set current(e){e!==this._current&&(this._current&&this._current.removeAttribute(`aria-current`),e.setAttribute(`aria-current`,`true`),this._current=e)}onIdle=e=>(window.requestIdleCallback||(e=>setTimeout(e,1)))(e);constructor(){super(),this.onIdle(()=>this.init())}init=()=>{let t=[...this.querySelectorAll(`a`)],n=e=>e.matches(this.tocHeadingSelector),r=t=>{if(!t)return null;let i=t;for(;t;){if(t.matches(`.sl-markdown-content, main > *`))return document.getElementById(e);if(n(t))return t;let i=t.querySelector(this.tocHeadingSelector);if(i)return i;for(t=t.previousElementSibling;t?.lastElementChild;)t=t.lastElementChild;let a=r(t);if(a)return a}return r(i.parentElement)},i=e=>{for(let{isIntersecting:n,target:i}of e){if(!n)continue;let e=r(i);if(!e)continue;let a=t.find(t=>t.hash===`#`+encodeURIComponent(e.id));if(a){this.current=a;break}}},a=document.querySelectorAll([`main :where(${this.tocHeadingSelector})`,`main :where(${this.tocHeadingSelector}, .sl-heading-wrapper) ~ *:not(:has(${this.tocHeadingSelector}))`,`main .sl-markdown-content > *:not(:has(${this.tocHeadingSelector}))`,`main > *:not(:has(${this.tocHeadingSelector}))`].join()),o,s=()=>{o||(o=new IntersectionObserver(i,{rootMargin:this.getRootMargin()}),a.forEach(e=>o.observe(e)))};s();let c;window.addEventListener(`resize`,()=>{o&&=(o.disconnect(),void 0),clearTimeout(c),c=setTimeout(()=>this.onIdle(s),200)})};getRootMargin(){let e=(document.querySelector(`header`)?.getBoundingClientRect().height||0)+(this.querySelector(`summary`)?.getBoundingClientRect().height||0)+32;return`-${e}px 0% ${e+53-document.documentElement.clientHeight}px`}};customElements.define(`starlight-toc`,t);export{t};