UNPKG

@xiee/utils

Version:

Miscellaneous tools and utilities to manipulate HTML pages

2 lines 703 B
(e=>{const t='a[href^="#"]',r=e.querySelector(`:is(#TableOfContents, #TOC):has(${t})`);if(!r)return;const n=r.querySelectorAll(t),o={};n.forEach((e=>o[e.getAttribute("href").replace("#","")]=e));const c=Object.keys(o);let s;const i=Array(c.length).fill(0),l=new IntersectionObserver((e=>e.forEach((e=>{const t=e.target.id,r=c.indexOf(t);if(r<0)return;i[r]=+e.isIntersecting;const n=i.indexOf(1);if(n>-1)s=c[n];else{if(!s||e.boundingClientRect.top<0)return;s=r>0?c[r-1]:void 0}for(const e in o)o[e].classList.toggle("active",e===s)}))));e.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach((e=>{1===e.nodeType&&o.hasOwnProperty(e.id)&&l.observe(e)}))})(document); //# sourceMappingURL=toc-highlight.min.js.map