1import{i as P}from"./vendor-device.js";import{s as R,S as Y}from"./vendor-storage.js";import"./vendor-i18n.js";class K extends HTMLElement{cleanupFn=null;clickScrollTimeout=null;connectedCallback(){this.init()}disconnectedCallback(){this.cleanup()}init(){const m=document.querySelector(".progress-wrap");if(!m)return;const d=this.querySelector("#desktop-toc"),c=document.querySelector("#mobile-toc-bar"),E=m.querySelectorAll("h2").length;if(E<2){d&&(d.style.display="none"),c&&(c.style.display="none");return}const k=E>6?"h2":"h2, h3",u=Array.from(m.querySelectorAll(k));if(u.length===0){d&&(d.style.display="none"),c&&(c.style.display="none");return}u.forEach((e,t)=>{e.id||=`head-${t}`});let p=-1;const v=[],N=[],F=[],H=[],C=this.querySelector("#desktop-toc-lines"),w=this.querySelector("#desktop-toc-links"),M=this.querySelector("#desktop-toc-bar"),T=this.querySelector("#desktop-toc-panel"),B=this.querySelector("#desktop-toc-close-btn");if(C&&w&&d){C.innerHTML="",w.innerHTML="";const e=document.createDocumentFragment(),t=document.createDocumentFragment();let o=-1,n=null,r=null;u.forEach((s,h)=>{const g=s.textContent?.trim()||"",b=s.tagName.toLowerCase()==="h3";if(!b){const l=document.createElement("div");l.className="toc-line line-h2",l.setAttribute("aria-hidden","true"),e.appendChild(l),v.push(l),o=v.length-1}H.push(o);const a=document.createElement("a");if(a.className=`desktop-toc-item ${b?"toc-h3":"toc-h2"}`,a.href=`#${s.id}`,a.textContent=g,a.addEventListener("click",l=>{if(l.preventDefault(),!b&&r){const A=a.closest(".desktop-toc-group");A&&A.querySelector(".desktop-toc-subgroup")&&A.classList.toggle("is-expanded")}this.scrollToHeading(s,h,()=>{p=h,f(h)})}),b)n||(n=document.createElement("div"),n.className="desktop-toc-subgroup flex flex-col",r?r.appendChild(n):t.appendChild(n)),n.appendChild(a);else{const l=document.createElement("div");l.className="desktop-toc-group flex flex-col",l.appendChild(a),r=l,n=null,t.appendChild(l)}N.push(a)}),C.appendChild(e),w.appendChild(t),d.style.display="";const i=(s,h=!0)=>{if(!T)return;const g=s??!T.classList.contains("is-open");T.classList.toggle("is-open",g),T.setAttribute("aria-hidden",String(!g)),M?.setAttribute("aria-expanded",String(g)),h&&R.set(Y.TOC_OPEN_STATE,g?"1":"0")};R.get(Y.TOC_OPEN_STATE)==="1"&&i(!0,!1),M?.addEventListener("click",()=>i()),B?.addEventListener("click",s=>{s.stopPropagation(),i(!1)})}const O=c?.querySelector("#mobile-toc-drawer"),L=c?.querySelector(".mobile-toc-inner-list")||O,x=c?.querySelector("#mobile-toc-trigger");if(c&&L&&x){L.innerHTML="";const e=document.createDocumentFragment();u.forEach((o,n)=>{const r=o.textContent?.trim()||"",i=o.tagName.toLowerCase()==="h3",s=document.createElement("a");s.className=`mobile-toc-item ${i?"toc-h3":"toc-h2"}`,s.href=`#${o.id}`,s.textContent=r,s.addEventListener("click",h=>{h.preventDefault(),t(!1),this.scrollToHeading(o,n,()=>{p=n,f(n)})}),e.appendChild(s),F.push(s)}),L.appendChild(e),c.style.display="";const t=o=>{const n=o??!c.classList.contains("is-open");c.classList.toggle("is-open",n),x.setAttribute("aria-expanded",String(n)),O?.classList.toggle("hidden",!n)};x.addEventListener("click",()=>t())}let D=-999,I=-999;const f=e=>{if(P())I!==e&&(I=e,F.forEach((t,o)=>t.classList.toggle("active",o===e)));else if(D!==e){D=e;const t=e>=0?H[e]??-1:-1;v.forEach((o,n)=>o.classList.toggle("active",n===t)),N.forEach((o,n)=>{const r=n===e;if(o.classList.toggle("active",r),r){const i=o.closest(".desktop-toc-group");i&&(i.parentElement?.querySelectorAll(".desktop-toc-group.is-active-group").forEach(s=>{s!==i&&s.classList.remove("is-active-group")}),i.classList.add("is-active-group"))}})}},G=document.querySelector(".post-container")||m;let S=null,y=null,q=!1;const _=new Map,$=()=>{if(!q){p!==-1&&(p=-1,f(-1));return}let e=0;for(let t=0;t<u.length;t++){const o=u[t];o&&_.get(o)&&(e=t)}e!==p&&(p=e,f(e))};"IntersectionObserver"in window&&(y=new IntersectionObserver(e=>{for(const t of e)q=t.isIntersecting,q?$():(p=-1,f(-1))},{rootMargin:"-10% 0px -10% 0px"}),y.observe(G),S=new IntersectionObserver(e=>{for(const t of e){const o=t.target;_.set(o,t.isIntersecting||t.boundingClientRect.top<window.innerHeight*.45)}$()},{rootMargin:"0px 0px -55% 0px",threshold:0}
1),u.forEach(e=>S?.observe(e))),this.cleanupFn=()=>{S&&(S.disconnect(),S=null),y&&(y.disconnect(),y=null),this.clickScrollTimeout&&clearTimeout(this.clickScrollTimeout)};const W=window.Tana??={};W.toc={init:()=>this.init(),cleanup:()=>this.cleanup()}}scrollToHeading(m,d,c){const E=P()?60:90;window.scrollTo({top:m.getBoundingClientRect().top+window.scrollY-E,behavior:"smooth"});const k=()=>{c&&c()};"onscrollend"in window?window.addEventListener("scrollend",k,{once:!0}):(this.clickScrollTimeout&&clearTimeout(this.clickScrollTimeout),this.clickScrollTimeout=setTimeout(k,600))}cleanup(){this.cleanupFn&&(this.cleanupFn(),this.cleanupFn=null)}}customElements.get("tana-toc")||customElements.define("tana-toc",K);export{K as TanaToc};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.