function b(e){let t=e.content,n=e.tocElement,l=e.titleElements,c=t.querySelector(n);if(c){let d=document.createElement("ul");d.id="list-toc-generated",c.appendChild(d);let m=0;for(var r=0;r<l.length;r++){let h=r+1,i=t.querySelectorAll(l[r]);i=Array.from(i).filter(o=>c.compareDocumentPosition(o)&4),i.forEach(o=>{o.classList.add("title-element"),o.setAttribute("data-title-level",h),m++,o.id==""&&(o.id="title-element-"+m)})}let p=t.querySelectorAll(".title-element");for(var r=0;r<p.length;r++){let i=p[r],o=document.createElement("li");o.classList.add("toc-element"),o.classList.add("toc-element-level-"+i.dataset.titleLevel);let s=i.classList;for(var a=0;a<s.length;a++)s[a]!="title-element"&&o.classList.add(s[a]);o.innerHTML='<a href="#'+i.id+'">'+i.innerHTML+"</a>",d.appendChild(o)}}}import{Previewer as E,registerHandlers as y,Handler as w}from"pagedjs";import"@fortawesome/fontawesome-free/js/all";var u=class extends w{constructor(t,n,l){super(t,n,l)}beforeParsed(t){b({content:t,tocElement:"#toc",titleElements:["h1","h2","h3","h4"]})}},L=async()=>{let e={auto:!0,before:void 0,after:void 0,content:void 0,stylesheets:void 0,renderTo:void 0,settings:void 0},t=new E(e);if(y(u),e.before&&await e.before(),e.auto!==!1){let n=await t.preview(e.content,e.stylesheets,e.renderTo)}e.after&&await e.after(done)};var f=class{constructor({configuration:t,notebook_info:n}){this._configuration=t,this._notebook_info=n}async process(){document.querySelectorAll("[data-nbprint-parent-id]").forEach(n=>{let l=n.getAttribute("data-nbprint-parent-id"),c=document.querySelector(`[data-nbprint-id="${l}"`);c&&c.appendChild(n)});let t=Array.from(document.querySelector("main").querySelectorAll("style")).filter(n=>!n.textContent.includes("@scope"));for(let n of t)document.head.appendChild(n)}async postprocess(){let t=new CustomEvent("nbprint-ready",{detail:{nbprint:this},bubbles:!0,cancelable:!0,composed:!1});document.dispatchEvent(t)}buildPagedJS(){return!this._configuration.debug}};function T(){let e=new f({configuration:window._nbprint_configuration,notebook_info:window._nbprint_notebook_info});return window.NBPRINT=e,console.debug("NBPrint Initialized!"),e}export{f as NBPrint,L as build,b as createToc,u as handlers,T as initializeNBPrint};
//# sourceMappingURL=index.js.map
