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