let absoluteBasePath,relativeBasePath,relativePathname,webpageContainer,documentContainer,viewContent,leftSidebar,rightSidebar,sidebarCollapseIcons,sidebarGutters,sidebars,sidebarDefaultWidth,sidebarTargetWidth,contentTargetWidth,themeToggle,searchInput,fileTree,outlineTree,fileTreeItems,outlineTreeItems,canvasWrapper,canvas,canvasNodes,canvasBackground,canvasBackgroundPattern,focusedCanvasNode,loadingIcon,documentType,embedType,customType,deviceSize,lastScreenWidth,loadedURL=new URL(window.location.href),isOffline=!1,collapseIconUp=["m7 15 5 5 5-5","m7 9 5-5 5 5"],collapseIconDown=["m7 20 5-5 5 5","m7 4 5 5 5-5"],isTouchDevice=isTouchCapable(),fullyInitialized=!1;async function initGlobalObjects(){"file:"!=window.location.protocol&&await loadIncludes(),loadingIcon=document.createElement("div"),loadingIcon.classList.add("loading-icon"),document.body.appendChild(loadingIcon),loadingIcon.innerHTML="
",webpageContainer=document.querySelector(".webpage-container"),documentContainer=document.querySelector(".document-container"),leftSidebar=document.querySelector(".sidebar-left"),rightSidebar=document.querySelector(".sidebar-right"),fileTree=document.querySelector(".file-tree"),outlineTree=document.querySelector(".outline-tree"),fileTreeItems=Array.from(document.querySelectorAll(".tree-container.file-tree .tree-item")),sidebars=[],sidebarGutters=[],sidebarCollapseIcons=[],leftSidebar&&rightSidebar&&(sidebarCollapseIcons=Array.from(document.querySelectorAll(".sidebar-collapse-icon")),sidebarGutters=[sidebarCollapseIcons[0].parentElement,sidebarCollapseIcons[1].parentElement],sidebars=[sidebarGutters[0].parentElement,sidebarGutters[1].parentElement]),themeToggle=document.querySelector(".theme-toggle-input")}async function initializePage(){focusedCanvasNode=null,canvasWrapper=document.querySelector(".canvas-wrapper")??canvasWrapper,canvas=document.querySelector(".canvas")??canvas;let e=document.querySelectorAll(".canvas-node");canvasNodes=e.length>0?e:canvasNodes,canvasBackground=document.querySelector(".canvas-background")??canvasBackground,canvasBackgroundPattern=document.querySelector(".canvas-background pattern")??canvasBackgroundPattern,viewContent=document.querySelector(".document-container > .view-content")??document.querySelector(".document-container > .markdown-preview-view")??viewContent,outlineTreeItems=Array.from(document.querySelectorAll(".tree-container.outline-tree .tree-item")),fullyInitialized||("file:"==window.location.protocol&&initializeForFileProtocol(),await initGlobalObjects(),initializeDocumentTypes(document),setupSidebars(),setupThemeToggle(),await setupSearch(),setupRootPath(document),sidebarDefaultWidth=await getComputedPixelValue("--sidebar-width"),contentTargetWidth=.9*await getComputedPixelValue("--line-width"),window.addEventListener("resize",(()=>onResize())),onResize()),setTimeout((()=>documentContainer.classList.remove("hide"))),!rightSidebar||"video"!=embedType&&"embed"!=embedType&&"excalidraw"!=customType&&"kanban"!=customType&&"canvas"!=documentType?rightSidebar&&rightSidebar.temporarilyCollapsed&&rightSidebar.collapsed&&(rightSidebar.collapse(!1),rightSidebar.temporarilyCollapsed=!1):rightSidebar.collapsed||rightSidebar.temporaryCollapse(),parseURLParams(),relativePathname=getVaultRelativePath(loadedURL.href)}function initializePageEvents(e){e&&(setupHeaders(e),setupTrees(e),setupLists(e),setupCallouts(e),setupCheckboxes(e),setupCanvas(e),setupCodeblocks(e),setupLinks(e),setupScroll(e))}function initializeDocumentTypes(e){e.querySelector(".document-container > .markdown-preview-view")?documentType="markdown":e.querySelector(".canvas-wrapper")?documentType="canvas":(documentType="custom",e.querySelector(".kanban-plugin")?customType="kanban":e.querySelector(".excalidraw-plugin")&&(customType="excalidraw"))}function initializeForFileProtocol(){let e=document.querySelector(".graph-view-placeholder");e&&(console.log("Running locally, skipping graph view initialization and hiding graph."),e.style.display="none",e.previousElementSibling.style.display="none")}function onEndResize(){document.body.classList.toggle("resizing",!1)}function onStartResize(){document.body.classList.toggle("resizing",!0)}window.onload=async function(){await initializePage(),initializePageEvents(document),setActiveDocument(loadedURL,!0,!1,!1),fullyInitialized=!0},window.onpopstate=function(e){if(e.preventDefault(),e.stopPropagation(),document.body.classList.contains("floating-sidebars")&&(!leftSidebar.collapsed||!rightSidebar.collapsed))return leftSidebar.collapse(!0),void rightSidebar.collapse(!0);loadDocument(getURLPath(),!1,!0),console.log("Popped state: "+getURLPath())};let checkStillResizingTimeout,isResizing=!1;function onResize(e=!1){function t(e,t){let o=window.innerWidth;return o>e&&oe&&o=t)}function o(e){let t=window.innerWidth;return t>e&&null==lastScreenWidth||t>e&&lastScreenWidthe}isResizing||(onStartResize(),isResizing=!0),o(contentTargetWidth+2*sidebarDefaultWidth)||o(1025)?(deviceSize="large-screen",document.body.classList.toggle("floating-sidebars",!1),document.body.classList.toggle("is-large-screen",!0),document.body.classList.toggle("is-small-screen",!1),document.body.classList.toggle("is-tablet",!1),document.body.classList.toggle("is-phone",!1),sidebars.forEach((function(e){e.collapse(!1)})),sidebarGutters.forEach((function(e){e.collapse(!1)}))):t(1*(contentTargetWidth+sidebarDefaultWidth),contentTargetWidth+2*sidebarDefaultWidth)||t(769,1024)?(deviceSize="small screen",document.body.classList.toggle("floating-sidebars",!1),document.body.classList.toggle("is-large-screen",!1),document.body.classList.toggle("is-small-screen",!0),document.body.classList.toggle("is-tablet",!1),document.body.classList.toggle("is-phone",!1),sidebarGutters.forEach((function(e){e.collapse(!1)})),leftSidebar&&rightSidebar&&!leftSidebar.collapsed&&rightSidebar.collapse(!0)):t(2*sidebarDefaultWidth,1*(contentTargetWidth+sidebarDefaultWidth))||t(481,768)?(deviceSize="tablet",document.body.classList.toggle("floating-sidebars",!0),document.body.classList.toggle("is-large-screen",!1),document.body.classList.toggle("is-small-screen",!1),document.body.classList.toggle("is-tablet",!0),document.body.classList.toggle("is-phone",!1),sidebarGutters.forEach((function(e){e.collapse(!1)})),leftSidebar&&rightSidebar&&!leftSidebar.collapsed&&rightSidebar.collapse(!0),leftSidebar&&!fullyInitialized&&leftSidebar.collapse(!0)):(n(2*sidebarDefaultWidth)||n(480))&&(deviceSize="phone",document.body.classList.toggle("floating-sidebars",!0),document.body.classList.toggle("is-large-screen",!1),document.body.classList.toggle("is-small-screen",!1),document.body.classList.toggle("is-tablet",!1),document.body.classList.toggle("is-phone",!0),sidebars.forEach((function(e){e.collapse(!0)})),sidebarGutters.forEach((function(e){e.collapse(!1)}))),lastScreenWidth=window.innerWidth,null!=checkStillResizingTimeout&&clearTimeout(checkStillResizingTimeout);let i=window.innerWidth;checkStillResizingTimeout=setTimeout((function(){window.innerWidth==i&&(checkStillResizingTimeout=void 0,isResizing=!1,onEndResize())}),200)}function clamp(e,t,o){return Math.min(Math.max(e,t),o)}async function delay(e){return new Promise((t=>setTimeout(t,e)))}async function waitUntil(e,t=100,o=2e3){return new Promise((n=>{let i=0,a=setTimeout((()=>{clearInterval(i),n()}),o);i=setInterval((()=>{e()&&(clearInterval(i),clearTimeout(a),n())}),t)}))}function getElBounds(e){let t=e.getBoundingClientRect(),o=t.x,n=t.y,i=t.width,a=t.height;return{x:o,y:n,width:i,height:a,minX:o,minY:n,maxX:o+i,maxY:n+a,centerX:t.x+t.width/2,centerY:t.y+t.height/2}}async function getComputedPixelValue(e){const t=document.createElement("div");document.body.appendChild(t),t.style.position="absolute",t.style.width=`var(${e})`,await new Promise((e=>setTimeout(e,10)));const o=window.getComputedStyle(t).width;return t.remove(),parseFloat(o)}function getPointerPosition(e){let t=e.touches?Array.from(e.touches):[];return{x:t.length>0?t.reduce(((e,t)=>e+t.clientX),0)/e.touches.length:e.clientX,y:t.length>0?t.reduce(((e,t)=>e+t.clientY),0)/e.touches.length:e.clientY}}function getTouchPosition(e){return{x:e.clientX,y:e.clientY}}function getAllChildrenRecursive(e){let t=[];for(let o=0;o0||navigator.msMaxTouchPoints>0}function downloadBlob(e,t="file.txt"){if(window.navigator&&window.navigator.msSaveOrOpenBlob)return window.navigator.msSaveOrOpenBlob(e);const o=window.URL.createObjectURL(e),n=document.createElement("a");n.href=o,n.download=t,n.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window})),setTimeout((()=>{window.URL.revokeObjectURL(o),n.remove()}),100)}function extentionToTag(e){return["png","jpg","jpeg","svg","gif","bmp","ico"].includes(e)?"img":["mp4","mov","avi","webm","mpeg"].includes(e)?"video":["mp3","wav","ogg","aac"].includes(e)?"audio":["pdf"].includes(e)?"embed":void 0}let slideUp=(e,t=500)=>{e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.boxSizing="border-box",e.style.height=e.offsetHeight+"px",e.offsetHeight,e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,window.setTimeout((async()=>{e.style.display="none",e.style.removeProperty("height"),e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property")}),t)},slideUpAll=(e,t=500)=>{e.forEach((async e=>{e&&(e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.boxSizing="border-box",e.style.height=e.offsetHeight+"px",e.offsetHeight,e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0)})),window.setTimeout((async()=>{e.forEach((async e=>{e&&(e.style.display="none",e.style.removeProperty("height"),e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property"))}))}),t)},slideDown=(e,t=500)=>{e.style.removeProperty("display");let o=window.getComputedStyle(e).display;"none"===o&&(o="block"),e.style.display=o;let n=e.offsetHeight;e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,e.offsetHeight,e.style.boxSizing="border-box",e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.height=n+"px",e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),window.setTimeout((async()=>{e.style.removeProperty("height"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property")}),t)},slideDownAll=(e,t=500)=>{e.forEach((async e=>{if(!e)return;e.style.removeProperty("display");let o=window.getComputedStyle(e).display;"none"===o&&(o="block"),e.style.display=o;let n=e.offsetHeight;e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,e.offsetHeight,e.style.boxSizing="border-box",e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.height=n+"px",e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom")})),window.setTimeout((async()=>{e.forEach((async e=>{e&&(e.style.removeProperty("height"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property"))}))}),t)};var slideToggle=(e,t=500)=>"none"===window.getComputedStyle(e).display?slideDown(e,t):slideUp(e,t),slideToggleAll=(e,t=500)=>"none"===window.getComputedStyle(e[0]).display?slideDownAll(e,t):slideUpAll(e,t);function getURLExtention(e){return e.split(".").pop().split("?")[0].split("#")[0].toLowerCase().trim()}let transferDocument=document.implementation.createHTMLDocument(),loading=!1;async function loadDocument(e,t,o){if(e=decodeURI(e),loading)return void console.log("Already loading document.");loading=!0;let n=new URL(e,absoluteBasePath);if(relativePathname=getVaultRelativePath(n.href),console.log("Loading document: ",n.pathname),n.pathname==loadedURL?.pathname)return console.log("Document already loaded."),loadedURL=n,setActiveDocument(loadedURL,!1,!1),await initializePage(),void(loading=!1);loadedURL=n;let i,a=loadedURL.pathname;await showLoading(!0);try{i=await fetch(a)}catch(e){return window.location.assign(a),void(loading=!1)}if(i.ok){setActiveDocument(loadedURL,o,t);let n=getURLExtention(e);if("/"==n&&(n="html"),documentType="none",embedType="none",customType="none","html"==n){let e=(await i.text()).replaceAll("","").replaceAll("","").replaceAll("","");transferDocument.write(e),setupRootPath(transferDocument),initializeDocumentTypes(transferDocument);let t=transferDocument.querySelector(".document-container");documentContainer.innerHTML=t.innerHTML;let o=transferDocument.querySelector(".outline-tree");outlineTree&&o&&(outlineTree.innerHTML=o.innerHTML),document.title=transferDocument.title,transferDocument.close()}else if(documentType="embed",embedType=extentionToTag(n),null!=embedType){let t=document.createElement(embedType);t.controls=!0,t.src=e,t.style.maxWidth="100%","embed"==embedType&&(t.style.width="100%",t.style.height="100%"),t.style.objectFit="contain",viewContent.innerHTML="",viewContent.setAttribute("class","view-content embed"),viewContent.appendChild(t),document.querySelector(".outline-tree")&&(document.querySelector(".outline-tree").innerHTML=""),document.title=e.split("/").pop()}else{downloadBlob(await i.blob(),e.split("/").pop())}await initializePage(),initializePageEvents(documentContainer),initializePageEvents(outlineTree)}else pageNotFound(viewContent);await showLoading(!1),loading=!1}function setActiveDocument(e,t,o,n=!0){let i=getVaultRelativePath(e.href),a=decodeURI(i).split("#")[0].split("?")[0].replace('"','\\"').replace("'","\\'");"/"!=a&&""!=a||(a="index.html");let l=document.querySelector(".file-tree .tree-item.mod-active"),s=document.querySelector(`.file-tree .tree-item:has(>.tree-link[href^="${a}"])`);if(s&&!s.isEqualNode(l)&&(l?.classList.remove("mod-active"),s.classList.add("mod-active"),t&&scrollIntoView(s,{block:"center",inline:"nearest"},n)),"undefined"!=typeof graphData&&window.graphRenderer){let e=graphData?.paths.findIndex((function(e){return e.endsWith(a)}))??-1;e>=0&&(window.graphRenderer.activeNode=e)}console.log("Active document: "+o),o&&"file:"!=window.location.protocol&&(window.history.pushState({path:i},"",i),console.log("Pushed state: "+i))}function parseURLParams(){const e=loadedURL.searchParams.get("mark"),t=loadedURL.searchParams.get("query"),o=decodeURI(loadedURL.hash);if(e&&searchCurrentDocument(e),t&&search(t),o){const e=document.getElementById(o.substring(1));e?scrollIntoView(e,{behavior:"smooth",block:"start"}):console.log("Heading not found: "+o)}}async function showLoading(e){if(documentContainer.style.transitionDuration="",loadingIcon.classList.toggle("show",e),documentContainer.classList.toggle("hide",e),e){let e=getViewBounds();loadingIcon.style.left=e.centerX-loadingIcon.offsetWidth/2+"px",loadingIcon.style.top=e.centerY-loadingIcon.offsetHeight/2+"px","phone"==deviceSize&&leftSidebar.collapse(!0)}await delay(200)}function pageNotFound(e){e.innerHTML="\n\t
\n\t\t
\n\t\t\t

Page Not Found

\n\t\t
\n\t
\n\t",document.querySelector(".outline-tree")&&(document.querySelector(".outline-tree").innerHTML=""),console.log("Page not found: "+absoluteBasePath+loadedURL.pathname);let t=getURLRootPath(absoluteBasePath+loadedURL.pathname);relativeBasePath=t,document.querySelector("base").href=t,document.title="Page Not Found"}function setupRootPath(e){let t=e.getElementById("root-path");if(!t)return;let o=t.getAttribute("root-path"),n=document.createElement("base");n.href=o,console.log("Setting root path: "+o),document.querySelector("base").replaceWith(n),document.querySelector("#root-path").setAttribute("root-path",o),relativeBasePath=o,absoluteBasePath=new URL(o,window.location.href).href}function getURLPath(e=window.location.pathname){return null==absoluteBasePath&&setupRootPath(document),e.replace(absoluteBasePath,"")}function getURLRootPath(e=window.location.pathname){let t=getURLPath(e).split("/"),o="";for(let e=0;ee+t.offsetHeight),0);e.markdownPreviewSizer.style.minHeight=t+"px"}}if(i.style.height=a+"px",t||"canvas"!=documentType||e.show(!0),e.collapsed=t,n)return i.style.transitionDuration="0s",e.classList.toggle("is-collapsed",t),i.style.height="",i.style.transitionDuration="",void l();let s=getComputedStyle(i).transitionDuration;s=s.endsWith("s")?parseFloat(s):s.endsWith("ms")?parseFloat(s)/1e3:0;let r=Math.min(s*Math.sqrt(a)/16,.5);i.style.transitionDuration=`${r}s`,i.style.height=t?"0px":a+"px",e.classList.toggle("is-animating",!0),e.classList.toggle("is-collapsed",t),e.markdownPreviewSizer.closest(".markdown-embed")&&l(t?0:void 0),setTimeout((function(){i.style.transitionDuration="",t||(i.style.height=""),e.classList.toggle("is-animating",!1),l()}),1e3*r)}function toggleTreeHeaderOpen(e,t=!0){e.collapse(!e.collapsed,t)}function hideHeader(e){if(e.forceShown)return;if(e.classList.contains("is-hidden")||e.classList.contains("is-collapsed"))return;if("none"==getComputedStyle(e).display)return;let t=e.offsetHeight;e.classList.toggle("is-hidden",!0),0!=t&&(e.style.height=t+"px"),e.style.visibility="hidden"}function showHeader(e,t=!0,o=!1,n=!1){if(n&&(e.forceShown=!0),t){let t=e.parentHeader;isHeadingWrapper(t)&&t.show(!0,!1,n)}if(o){e.querySelectorAll(".heading-wrapper").forEach((function(e){e.show(!1,!0,n)}))}e.classList.contains("is-hidden")&&!e.classList.contains("is-collapsed")&&(e.classList.toggle("is-hidden",!1),e.style.height="",e.style.visibility="")}function setupTrees(e){e.querySelectorAll(".collapse-tree-button").forEach((function(e){e.treeRoot=e.closest(".tree-container"),e.icon=e.firstChild,e.icon.innerHTML="",e.setIcon=function(t){e.icon.children[0].setAttribute("d",t?collapseIconUp[0]:collapseIconDown[0]),e.icon.children[1].setAttribute("d",t?collapseIconUp[1]:collapseIconDown[1])},e.collapse=function(t){setTreeCollapsedAll(e.treeRoot.classList.contains("file-tree")?fileTreeItems:outlineTreeItems,t),e.setIcon(t),e.collapsed=t},e.toggleCollapse=function(){e.collapse(!e.collapsed)},e.toggleState=function(t){void 0===t&&(t=!e.collapsed),e.collapsed=t,e.setIcon(t)},e.addEventListener("click",(function(t){return t.preventDefault(),t.stopPropagation(),e.toggleCollapse(),!1})),(e.treeRoot.classList.contains("file-tree")?fileTreeItems:outlineTreeItems).some((e=>!e.classList.contains("is-collapsed")&&e.classList.contains("mod-collapsible")))&&e.toggleState(!1)}));let t=Array.from(e.querySelectorAll(".tree-container.file-tree .tree-item:has(.collapse-icon) > .tree-link")),o=Array.from(e.querySelectorAll(".tree-container.outline-tree .tree-item:has(.collapse-icon) > .tree-link .collapse-icon")),n=Array.from(t).concat(Array.from(o));for(let e of n){let t=e?.closest(".tree-item");t&&e&&e?.addEventListener("click",(function(e){e.preventDefault(),e.stopPropagation(),toggleTreeCollapsed(t)}))}}async function setTreeCollapsed(e,t,o=!0,n=!0){if(e.classList.contains("mod-collapsible")||(e=e.closest(".mod-collapsible")),!e||!e.classList.contains("mod-collapsible"))return;if(e.classList.contains("is-collapsed")==t)return;if(n){let t=e.parentElement.closest(".mod-collapsible");t&&await setTreeCollapsed(t,!1,o,n)}let i=e.querySelector(".tree-item-children");if(t)e.classList.add("is-collapsed"),o?slideUp(i,100):i.style.display="none";else{e.classList.remove("is-collapsed"),o?slideDown(i,100):i.style.display="";let t=e.closest(".tree-container");if(t){let e=t.querySelector(".collapse-tree-button");e&&e.toggleState(!1)}}}async function setTreeCollapsedAll(e,t,o=!0){let n=[];e.forEach((async e=>{if(!e||!e.classList.contains("mod-collapsible"))return;let o=e.querySelector(".tree-item-children");t?e.classList.add("is-collapsed"):e.classList.remove("is-collapsed"),n.push(o)})),t?o?slideUpAll(n,100):n.forEach((async e=>{e&&(e.style.display="none")})):o?slideDownAll(n,100):n.forEach((async e=>{e&&(e.style.display="")}))}function toggleTreeCollapsed(e){(e=e.closest(".tree-item"))&&setTreeCollapsed(e,!e.classList.contains("is-collapsed"))}function toggleTreeCollapsedAll(e){e&&setTreeCollapsedAll(e,!e[0].classList.contains("is-collapsed"))}function getFileTreeItemFromPath(e){return document.querySelector(`.file-tree .tree-item:has(> .tree-link[href^="${e}"])`)}async function filterFileTree(e,t,o,n=!0){n&&await setTreeCollapsedAll(fileTreeItems,!1,!1);let i=Array.from(document.querySelectorAll(".file-tree .tree-item:not(.filtered-out)"));for await(let l of i)l.classList.add("filtered-out");await removeTreeHintLabels();for(let s=0;s0){let p=d.querySelector(".tree-link").appendChild(document.createElement("div"));function a(e,t){if(""==(e=e.trim()))return;let o=document.createElement("a");o.classList.add("tree-hint-label"),o.classList.add("internal-link"),o.textContent=e,o.href=decodeURI(t).replaceAll(" ","_"),p.appendChild(o)}p.classList.add("tree-hint-container");for(let h of c)a(h,r+"#"+h);setupLinks(p)}}}}async function clearFileTreeFilter(e=!0){await removeTreeHintLabels();let t=document.querySelectorAll(".file-tree .filtered-out");for await(let e of t)e.classList.remove("filtered-out");let o=document.querySelectorAll(".file-tree .tree-link[href*='?mark=']");for await(let e of o){let t=e.href.split("?")[0];t=getVaultRelativePath(t),e.href=t}e&&await setTreeCollapsedAll(fileTreeItems,!0,!1)}async function removeTreeHintLabels(){let e=document.querySelectorAll(".tree-hint-container");for await(let t of e)t.remove()}function sortFileTreeDocuments(e){let t=Array.from(document.querySelectorAll(".file-tree .tree-item.mod-tree-file:not(.filtered-out)"));t.sort(e);for(let e=1;e=0;i--){let e=o[i];if(t.parentElement==e.parentElement){e.after(t),n=!0;break}}n||t.parentElement.prepend(t)}}function sortFileTree(e){let t=Array.from(document.querySelectorAll(".file-tree .tree-item.mod-tree-file:not(.filtered-out)"));t.sort(e);for(let e=1;e=0;i--){let e=o[i];if(t.parentElement==e.parentElement){e.after(t),n=!0;break}}n||t.parentElement.prepend(t)}}function sortFileTreeAlphabetically(e=!1){sortFileTree((function(t,o){const n=t.querySelector(".tree-item-title"),i=o.querySelector(".tree-item-title");if(!n||!i)return 0;const a=n.textContent.toLowerCase(),l=i.textContent.toLowerCase();return a.localeCompare(l,void 0,{numeric:!0})*(e?-1:1)}))}function setupLists(e){let t=Array.from(e.querySelectorAll(".list-collapse-indicator"));for(let e=0;e1)&&(1==e.button||0==e.button||t.length>0)){let n=getPointerPosition(e),i=!1,a=0,l=t.length,s=function(t){let s=t.touches??[],r=getPointerPosition(t);l!=s.length&&(n=r,l=s.length);let c=r.x-n.x,d=r.y-n.y;if((1==e.button||1==s.length)&&focusedCanvasNode){let e=Math.abs(c)>Math.abs(1.5*d),t=Math.abs(d)>Math.abs(1.5*c),n=focusedCanvasNode.querySelector(".markdown-preview-sizer");if(n){let i=n.scrollHeight>n.parentElement.clientHeight+1,a=n.scrollWidth>n.parentElement.clientWidth+1;o=!(!(e&&a||t&&i)||!(window?.navigator?.platform?.startsWith("Win")??1))}}if(0==e.button&&focusedCanvasNode&&""!=focusedCanvasNode.querySelector(".canvas-node-content").textContent.trim()&&(o=!0),o||(translateCanvas(c,d),n=r),2==s.length){let e=getPointerPosition(t,!1),o=getTouchPosition(t.touches[0]),n=getTouchPosition(t.touches[1]),l=Math.sqrt(Math.pow(o.x-n.x,2)+Math.pow(o.y-n.y,2));i||(i=!0,a=l),scaleCanvasAroundPoint(1+(l-a)/a,e.x,e.y),a=l}},r=function(e){document.body.removeEventListener("mousemove",s),document.body.removeEventListener("mouseup",r),document.body.removeEventListener("mouseenter",c),document.body.removeEventListener("touchmove",s),document.body.removeEventListener("touchend",r),document.body.removeEventListener("touchcancel",r),o=!1},c=function(e){1!=e.buttons&&4!=e.buttons&&r(e)};document.body.addEventListener("mousemove",s),document.body.addEventListener("mouseup",r),document.body.addEventListener("mouseenter",c),document.body.addEventListener("touchmove",s),document.body.addEventListener("touchend",r),document.body.addEventListener("touchcancel",r)}}let i=0,a=0;canvasWrapper.addEventListener("mousemove",(function(e){let t=getPointerPosition(e);i=t.x,a=t.y}));let l=1,s=0,r=!1;canvasWrapper.addEventListener("wheel",(function(e){if(focusedCanvasNode){let e=focusedCanvasNode.querySelector(".markdown-preview-sizer");if(e&&e.scrollHeight>e.parentElement.clientHeight)return}if(e.preventDefault(),e.stopPropagation(),r){let t=1;t-=e.deltaY/700*t,t=clamp(t,.1,10);let o=getViewBounds();scaleCanvasAroundPoint(t,o.centerX,o.centerY)}else{let t=0==s;s-=e.deltaY/200;const o=.14*l;s=clamp(s,-o,o),t&&requestAnimationFrame(m)}}));let c=0,d=0,u=0;function m(e){if(c=e-d,0==d&&(c=30),d=e,u=.05*c+.95*u,u>50)return console.log("Scrolling too slow, turning on instant scroll"),void(r=!0);let t=l;l+=s*(c/1e3)*30,l=clamp(l,.1,10);getViewBounds();scaleCanvasAroundPoint(l/t,i,a),s*=.4,Math.abs(s)<.01?(s=0,d=0):requestAnimationFrame(m)}setTimeout(fitViewToCanvas,300)}function getViewBounds(){let e=viewContent.getBoundingClientRect(),t=e.x,o=e.y,n=e.x+e.width,i=e.y+e.height;return{x:t,y:o,width:n-t,height:i-o,minX:t,minY:o,maxX:n,maxY:i,centerX:e.x+e.width/2,centerY:e.y+e.height/2}}function getNodesBounds(){let e=1/0,t=1/0,o=-1/0,n=-1/0;canvasNodes.forEach((function(i){let a=i.getBoundingClientRect();a.xo&&(o=a.x+a.width),a.y+a.height>n&&(n=a.y+a.height)}));let i=o-e,a=n-t;return{x:e,y:t,width:i,height:a,minX:e,minY:t,maxX:o,maxY:n,centerX:e+i/2,centerY:t+a/2}}function getCanvasBounds(){let e=canvas.getBoundingClientRect(),t=e.x,o=e.y,n=e.width,i=e.height;return{x:t,y:o,width:n,height:i,minX:t,minY:o,maxX:t+n,maxY:o+i,centerX:e.x+e.width/2,centerY:e.y+e.height/2}}function scaleCanvasAroundPoint(e,t,o){let n=getCanvasBounds(),i=t-n.x,a=o-n.y,l=t-(n.x+i*e),s=o-(n.y+a*e);return scaleCanvas(e),translateCanvas(l,s),{x:l,y:s}}function scaleCanvas(e){let t=Math.max(e*canvas.style.scale,.001);canvas.style.scale=t,canvasWrapper.style.setProperty("--zoom-multiplier",1/Math.sqrt(t))}function translateCanvas(e,t){let o=canvas.style.translate,n=o.split(" "),i=n.length>0?parseFloat(o.split(" ")[0].trim()):0,a=n.length>1?parseFloat(o.split(" ")[1].trim()):i;canvas.style.translate=`${i+e}px ${a+t}px`}function setViewCenter(e,t){let o=getViewBounds();translateCanvas(o.centerX-e,o.centerY-t)}function getCanvasTranslation(){let e=canvas.style.translate,t=e.split(" "),o=t.length>0?parseFloat(e.split(" ")[0].trim()):0;return{x:o,y:t.length>1?parseFloat(e.split(" ")[1].trim()):o}}function scaleCanvasBackground(e){let t=e*canvasBackgroundPattern.getAttribute("width"),o=e*canvasBackgroundPattern.getAttribute("height");canvasBackgroundPattern.setAttribute("width",t),canvasBackgroundPattern.setAttribute("height",o)}function translateCanvasBackground(e,t){canvasBackgroundPattern.setAttribute("x",e+canvasBackgroundPattern.getAttribute("x")),canvasBackgroundPattern.setAttribute("y",t+canvasBackgroundPattern.getAttribute("y"))}function fitViewToNode(e){let t=getElBounds(e),o=getViewBounds(),n=getCanvasBounds(),i=.8*Math.min(o.width/t.width,o.height/t.height),a=n.x,l=n.y,s=a+(t.centerX-a)*i,r=l+(t.centerY-l)*i,c=o.centerX-s,d=o.centerY-r;t=getElBounds(e),canvas.style.transition="scale 0.5s cubic-bezier(0.5, -0.1, 0.5, 1.1), translate 0.5s cubic-bezier(0.5, -0.1, 0.5, 1.1)",scaleCanvas(i),translateCanvas(c,d),setTimeout((function(){canvas.style.transition=""}),550)}function fitViewToCanvas(){let e=getNodesBounds(),t=getViewBounds(),o=getCanvasBounds(),n=.8*Math.min(t.width/e.width,t.height/e.height),i=o.x,a=o.y,l=i+(e.centerX-i)*n,s=a+(e.centerY-a)*n,r=t.centerX-l,c=t.centerY-s;canvas.style.transition="scale 0.5s cubic-bezier(0.5, -0.1, 0.5, 1.1), translate 0.5s cubic-bezier(0.5, -0.1, 0.5, 1.1)",scaleCanvas(n),translateCanvas(r,c),setTimeout((function(){canvas.style.transition=""}),550)}function setupCallouts(e){e.querySelectorAll(".callout.is-collapsible .callout-title").forEach((function(e){e.addEventListener("click",(function(){var t=this.parentElement;t.classList.toggle("is-collapsed"),e.querySelector(".callout-fold").classList.toggle("is-collapsed"),slideToggle(t.querySelector(".callout-content"),100)}))}))}function setupCheckboxes(e){e.querySelectorAll(".task-list-item-checkbox").forEach((function(e){e.addEventListener("click",(function(){var e=this.parentElement;e.classList.toggle("is-checked"),e.setAttribute("data-task",e.classList.contains("is-checked")?"x":" ")}))})),e.querySelectorAll('.plugin-tasks-list-item input[type="checkbox"]').forEach((function(e){e.checked=e.parentElement.classList.contains("is-checked")})),e.querySelectorAll(".kanban-plugin__item.is-complete").forEach((function(e){e.querySelector('input[type="checkbox"]').checked=!0}))}function setupCodeblocks(e){e.querySelectorAll(".copy-code-button").forEach((function(t){t.addEventListener("click",(function(){var t=this.parentElement.querySelector("code").textContent;navigator.clipboard.writeText(t),this.textContent="Copied!",setTimeout((function(){e.querySelectorAll(".copy-code-button").forEach((function(e){e.textContent="Copy"}))}),2e3)}))}))}function setupLinks(e){e.querySelectorAll(".internal-link, a.tag, .tree-link, .footnote-link").forEach((function(e){e.addEventListener("click",(function(t){let o=e.getAttribute("href");if(t.preventDefault(),t.stopPropagation(),!o)return void console.log("No target found for link");let n=relativePathname.split("#")[0].split("?")[0];(o.startsWith("#")||o.startsWith("?"))&&(o=n+o),loadDocument(o,!0,!e.classList.contains("tree-link"))}))}))}function setupSidebars(){rightSidebar&&leftSidebar&&(sidebarCollapseIcons[0].otherIcon=sidebarCollapseIcons[1],sidebarCollapseIcons[1].otherIcon=sidebarCollapseIcons[0],sidebarCollapseIcons[0].gutter=sidebarGutters[0],sidebarCollapseIcons[1].gutter=sidebarGutters[1],sidebarCollapseIcons[0].sidebar=sidebars[0],sidebarCollapseIcons[1].sidebar=sidebars[1],sidebarGutters[0].otherGutter=sidebarGutters[1],sidebarGutters[1].otherGutter=sidebarGutters[0],sidebarGutters[0].collapseIcon=sidebarCollapseIcons[0],sidebarGutters[1].collapseIcon=sidebarCollapseIcons[1],sidebars[0].otherSidebar=sidebars[1],sidebars[1].otherSidebar=sidebars[0],sidebars[0].gutter=sidebarGutters[0],sidebars[1].gutter=sidebarGutters[1],sidebars.forEach((function(e){e.collapsed=e.classList.contains("is-collapsed"),e.collapse=function(t=!0){if(!t&&this.temporarilyCollapsed&&"large-screen"==deviceSize&&this.gutter.collapse(!0),!t&&document.body.classList.contains("floating-sidebars")){document.body.addEventListener("click",(function t(o){o.target.closest(".sidebar")||(e.collapse(!0),document.body.removeEventListener("click",t))}))}"phone"==deviceSize&&(t||e.otherSidebar.fullCollapse(!0,!0),t&&e.gutter.otherGutter.collapse(!1,!0)),"tablet"==deviceSize&&(t||e.otherSidebar.collapse(!0)),this.classList.toggle("is-collapsed",t),this.collapsed=t},e.temporaryCollapse=function(e=!0){this.temporarilyCollapsed=!0,this.collapse(!0),this.gutter.collapse(!1),this.collapsed=e},e.fullCollapse=function(e=!0,t=!1){this.collapse(e),this.gutter.collapse(!0,t),this.collapsed=e},e.toggleCollapse=function(){this.collapse(!this.collapsed)},e.toggleFullCollapse=function(){this.fullCollapse(!this.collapsed)}})),sidebarGutters.forEach((function(e){e.collapsed=e.classList.contains("is-collapsed"),e.collapse=function(e,t=!1){t&&(this.classList.toggle("is-collapsed",e),this.collapsed=e)},e.toggleCollapse=function(){this.collapse(!this.collapsed)}})),sidebarCollapseIcons.forEach((function(e){e.addEventListener("click",(function(t){t.stopPropagation(),e.sidebar.toggleCollapse()}))})),isMobile()||setupSidebarResize())}function setupSidebarResize(){let e=document.querySelector(".sidebar-left .sidebar-handle"),t=document.querySelector(".sidebar-right .sidebar-handle");if(!e||!t)return;let o=null,n=15*parseFloat(getComputedStyle(e.parentElement).fontSize),i=n/4,a=localStorage.getItem("sidebar-right-width"),l=localStorage.getItem("sidebar-left-width");function s(e){if(!o)return;var t=o.classList.contains("sidebar-left")?e.clientX:window.innerWidth-e.clientX,a=`min(max(${t}px, 15em), 40vw)`;tn&&(o.style.transitionDuration="0s"))}function r(e){o=e.target.closest(".sidebar"),o.classList.add("is-resizing"),document.addEventListener("pointermove",s),document.addEventListener("pointerup",(function(){document.removeEventListener("pointermove",s);var e=getComputedStyle(o).getPropertyValue("--sidebar-width");let t=o.classList.contains("sidebar-left");localStorage.setItem(t?"sidebar-left-width":"sidebar-right-width",e),o.classList.remove("is-resizing"),o.style.removeProperty("transition-duration")}))}function c(e){let t=e.target.closest(".sidebar");if(t){t.style.removeProperty("transition-duration"),t.style.removeProperty("--sidebar-width");let e=t.classList.contains("sidebar-left");localStorage.removeItem(e?"sidebar-left-width":"sidebar-right-width")}}a&&document.querySelector(".sidebar-right").style.setProperty("--sidebar-width",a),l&&document.querySelector(".sidebar-left").style.setProperty("--sidebar-width",l),e.addEventListener("pointerdown",r),t.addEventListener("pointerdown",r),e.addEventListener("dblclick",c),t.addEventListener("dblclick",c)}function getSidebarWidthProp(){return getComputedPixelValue("--sidebar-width")}function setupThemeToggle(){function e(e,t=!1){if(themeToggle.checked=e,t){var o=document.body.style.transition;document.body.style.transition="none"}!themeToggle.classList.contains("is-checked")&&e?themeToggle.classList.add("is-checked"):themeToggle.classList.contains("is-checked")&&!e&&themeToggle.classList.remove("is-checked"),e?(document.body.classList.contains("theme-dark")&&document.body.classList.remove("theme-dark"),document.body.classList.contains("theme-light")||document.body.classList.add("theme-light")):(document.body.classList.contains("theme-light")&&document.body.classList.remove("theme-light"),document.body.classList.contains("theme-dark")||document.body.classList.add("theme-dark")),t&&setTimeout((function(){document.body.style.transition=o}),100),localStorage.setItem("theme",e?"light":"dark")}themeToggle&&(null!=localStorage.getItem("theme")&&e("light"==localStorage.getItem("theme")),document.body.classList.contains("theme-light")?e(!0):e(!1),document.querySelector(".theme-toggle-input")?.addEventListener("change",(t=>{let o=!("light"==localStorage.getItem("theme"));console.log("Theme toggle changed to: "+o),e(o)})))}let index,searchResults,flashElement=null,flashAnimation=null;function scrollIntoView(e,t,o=!0){setTreeCollapsed(e,!1,o);flashElement&&(flashElement.remove(),flashAnimation.cancel()),flashElement=document.createElement("div"),flashElement.classList.add("scroll-highlight"),e.appendChild(flashElement),t?flashElement.scrollIntoView({behavior:o?"smooth":"auto",...t}):flashElement.scrollIntoView({behavior:o?"smooth":"auto"});var n=e.style.position;e.style.position="relative",flashAnimation=flashElement.animate([{opacity:0},{opacity:.8},{opacity:.8},{opacity:.8},{opacity:.8},{opacity:.8},{opacity:0}],{duration:1500,iterations:1,delay:300}),flashAnimation.onfinish=function(){flashElement.remove(),e.style.position=n}}function setupScroll(e){if("canvas"!=documentType)return;let t=Array.from(e.querySelectorAll(".markdown-preview-view")),o=0,n=0;t.forEach((async function(e){console.log("Setting up markdown view");let t=Array.from(e.querySelectorAll(".heading-wrapper"));e.updateVisibleWindowMarkdown=function(o=!0,i=!0){let a=e.getBoundingClientRect();n=Math.min(.1*a.height,150);let l=a.top-n,s=a.bottom+n;async function r(e){let t=e?.getBoundingClientRect();if(!t)return;let n=t.tops&&t.bottom>s;n&&o?e.hide():!n&&i&&e.show()}for(let e=0;en/3&&e.updateVisibleWindowMarkdown(!1,!0),o=e.scrollTop}))})),setInterval((async function(){t.length>0&&(t[o].updateVisibleWindowMarkdown(),o=(o+1)%t.length)}),200)}function setupExcalidraw(e){e.querySelectorAll(".excalidraw-svg svg").forEach((function(e){let t=e.querySelector("rect").getAttribute("fill")>"#7F7F7F";e.classList.add(t?"light":"dark")}))}async function setupSearch(){if(isFileProtocol)return;if(searchInput=document.querySelector('input[type="search"]'),!searchInput)return;const e=await fetch("lib/search-index.json"),t=await e.text();index=MiniSearch.loadJSON(t,{fields:["title","path","tags","headers"]});document.querySelector(".search-input-clear-button").addEventListener("click",(e=>{search("")})),searchInput.addEventListener("input",(e=>{const t=e.target.value??"";startsWithAny(t,["#","tag:","title:","name:","header:","H:"])?searchInput.style.color="var(--text-accent)":searchInput.style.color="",search(t)})),searchResults=document.createElement("div"),searchResults.setAttribute("id","search-results")}async function search(e){searchInput.value=e;let t=["title","content","tags","headers","path"];if(e.startsWith("#")&&(t=["tags","headers"]),e.startsWith("tag:")&&(e=e.substring(e.indexOf(":")+1),t=["tags"]),startsWithAny(e,["title:","name:"])&&(e=e.substring(e.indexOf(":")+1),t=["title"]),startsWithAny(e,["header:","H:"])&&(e=e.substring(e.indexOf(":")+1),t=["headers"]),startsWithAny(e,["path:"])&&(e=e.substring(e.indexOf(":")+1),t=["path"]),e.length>=1){const o=index.search(e,{prefix:!0,fuzzy:.3,boost:{title:4,headers:3,tags:2,path:1},fields:t});let n=[],i=[];for(let t of o){if((t.score<.33*o[0].score||n.length>12)&&n.length>3||t.score<.1*o[0].score)break;n.push(t.path);let a=[],l=!1;for(match in t.match){if(t.match[match].includes("headers"))for(let o of t.headers)if(o.toLowerCase().includes(match.toLowerCase())&&(a.push(o),e.toLowerCase()!=match.toLowerCase())){l=!0;break}if(l)break}i.push(a)}if(document.querySelector(".file-tree"))filterFileTree(n,i,e).then((()=>sortFileTreeDocuments(((e,t)=>{if(!e||!t)return 0;let o=getVaultRelativePath(e.firstChild.href),i=getVaultRelativePath(t.firstChild.href);return n.findIndex((e=>o.startsWith(e)))-n.findIndex((e=>i.startsWith(e)))}))));else{const t=document.createElement("div");o.slice(0,10).forEach((o=>{const n=document.createElement("div");n.classList.add("search-result");const i=document.createElement("a");i.classList.add("tree-link");const a=o.path+"?mark="+encodeURIComponent(e);i.setAttribute("href",a),i.appendChild(document.createTextNode(o.title)),n.appendChild(i),t.append(n)})),searchResults.replaceChildren(t),searchInput.parentElement.after(searchResults),initializePageEvents(searchResults)}}else searchResults&&searchResults.parentElement&&searchResults.parentNode.removeChild(searchResults),clearCurrentDocumentSearch(),fileTree&&clearFileTreeFilter().then((()=>sortFileTreeAlphabetically()))}function startsWithAny(e,t){for(let o=0;o{const o=t.nodeValue,n=o.replace(new RegExp(e,"gi"),(e=>`${e}`));if(n!==o){const e=document.createElement("div");e.innerHTML=n;Array.from(e.childNodes).forEach((e=>{e.nodeType!=Node.TEXT_NODE&&e.setAttribute("class","search-mark"),t.parentNode.insertBefore(e,t)})),t.parentNode.removeChild(t)}}));let t=document.querySelector(".search-mark");setTimeout((()=>{t&&scrollIntoView(t,{behavior:"smooth",block:"start"})}),500)}function clearCurrentDocumentSearch(){document.querySelectorAll(".search-mark").forEach((e=>{e.outerHTML=e.innerHTML}))}function getTextNodes(e){const t=[],o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1);let n;for(;n=o.nextNode();)t.push(n);return t}