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