var k=Object.create;var E=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var B=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of C(t))!x.call(e,n)&&n!==o&&E(e,n,{get:()=>t[n],enumerable:!(i=M(t,n))||i.enumerable});return e};var f=(e,t,o)=>(o=e!=null?k(S(e)):{},B(t||!e||!e.__esModule?E(o,"default",{value:e,enumerable:!0}):o,e));var w=require("electron/renderer"),s=require("node:path"),c=require("node:fs"),p=require("node:url"),H=require("dompurify"),I=require("../../common/global");const N=import("marked-alert").then(e=>e.default),R=import("marked-gfm-heading-id").then(e=>e.gfmHeadingId);let h=import("marked").then(e=>e.marked);const y=document.URL;h=h.then(async e=>e.use((await R)(),(await N)()));const u=document.createElement("img");u.src="../../icons/symbols/menu.svg",u.id="menu-hamburger";const l=document.createElement("p");function L(e){if(e.split("#").length>1)return e.split("#")[1]}async function g(e,t){e.innerHTML=(0,H.sanitize)(await(await h).parse((0,c.readFileSync)(t).toString(),{async:!0}))}function T(e){const t=e.querySelector('a[href="https://github.com/SpacingBat3/WebCord"] > picture > img'),o=t?.parentNode??null,i=o?.parentElement??null;if(t===null||o===null||i===null)return;o.remove(),/\/sources\/assets\/web/.exec(t.src)?t.src=t.src.replace("/sources/assets/web",""):t.src=t.src.replace("/sources/assets","");const n=t.cloneNode();i.appendChild(n);for(const r of e.getElementsByTagName("img"))if(r.src.startsWith("https:")&&r.parentElement?.parentElement?.tagName==="P"){r.parentElement.parentElement.remove();break}}function v(e,t,o){for(const i of e.getElementsByTagName("a"))i.addEventListener("click",()=>{if(window.history.replaceState("","",(0,p.pathToFileURL)(o)),I.protocols.secure.includes(new URL(i.href).protocol))open(i.href);else if(i.href.startsWith(document.URL.replace(/#.*/,"")+"#")){const n=L(i.href);if(n!==void 0){const r=document.getElementById(n);r&&r.scrollIntoView({behavior:"smooth"})}}else if(/^file:\/\/.+(\.md|LICENSE)(#[a-z0-9-]+)?$/.exec(i.href)){let n=(0,p.fileURLToPath)(i.href);const r=L(i.href),m=l.innerHTML;l.innerText=(0,s.basename)(n),document.body.removeChild(t);let a;if((0,c.existsSync)(n))a=g(e,n),o=n;else{const d=(0,s.relative)(document.URL,i.href);if(n=(0,s.resolve)(o,d),!(0,c.existsSync)(n))return console.error("File '"+n+"' does not exists!"),document.body.appendChild(t),window.history.pushState("","",y),l.innerHTML=m,!1;a=g(e,n),o=n,console.log(d)}if(window.scroll(0,0),a.then(()=>v(e,t,o)).then(()=>T(e)),document.body.appendChild(t),r!==void 0){const d=document.getElementById(r);d&&d.scrollIntoView()}}return window.history.pushState("","",y),!1})}async function b(e,t,o){await g(e,t),v(e,o,t),T(e)}document.addEventListener("readystatechange",()=>{document.readyState==="interactive"&&w.ipcRenderer.invoke("documentation-load").then(async e=>{const t=document.createElement("header"),o=document.createElement("article"),i=document.createElement("div");o.appendChild(i),t.id="markdown-header",i.id="markdown-body",l.innerText=(0,s.basename)(e),t.appendChild(u),t.appendChild(l),await b(i,e,o),i.getElementsByTagName("sub")[0]?.parentElement?.remove(),document.body.appendChild(t),document.body.appendChild(o),u.addEventListener("click",()=>{let n,r=Promise.resolve();l.innerText.includes("Readme.md")?n={behavior:"smooth"}:(window.scroll(0,0),l.innerText=(0,s.basename)(e),r=b(i,e,o).then(()=>i.getElementsByTagName("sub")[0]?.parentElement?.remove()));let m="documentation";navigator.language==="pl"&&(m="dokumentacja-w-wi\u0119kszo\u015Bci-jeszcze-nie-przet\u0142umaczona"),r.then(()=>{const a=document.getElementById(m);a&&a.scrollIntoView(n)})})}).finally(()=>{w.ipcRenderer.send("documentation-show")}).catch(e=>{if(e instanceof Error)throw e;if(typeof e=="string")throw new Error(e);console.error(e)})});
