agahi
Version:
Client-side engine that renders Markdown files as a docs site in the browser—no build step.
2 lines (1 loc) • 1.94 kB
JavaScript
!function(){"use strict";!function(e,n){void 0===n&&(n={});var t=n.insertAt;if("undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===t&&o.firstChild?o.insertBefore(i,o.firstChild):o.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}("#img-preview-overlay {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background: rgba(0, 0, 0, 0.85);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 9999;\n}\n\n#img-preview-overlay img {\n max-width: 90%;\n max-height: 90%;\n transition: transform 0.3s ease;\n -webkit-user-select: none;\n -moz-user-select: none;\n user-select: none;\n cursor: zoom-in;\n}\n\n#img-preview-overlay.zoomed img {\n cursor: zoom-out;\n}\n\n#img-preview-overlay:not(.zoomed) {\n cursor: default;\n}\n"),document.addEventListener("agahi:ready",(()=>{const e=document.getElementById("md");if(!e)return;if(!document.getElementById("img-preview-overlay")){const e=document.createElement("div");e.id="img-preview-overlay",e.innerHTML='<img id="preview-img" src="" alt="Preview" />',document.body.appendChild(e)}const n=document.getElementById("img-preview-overlay"),t=document.getElementById("preview-img");let o=!1;new MutationObserver((()=>{e.querySelectorAll("img:not([data-zoom-bound])").forEach((e=>{e.dataset.zoomBound=!0,e.style.cursor="zoom-in",e.addEventListener("click",(()=>{t.src=e.src,n.style.display="flex",o=!1,t.style.transform="scale(1)",n.style.cursor="zoom-in"}))}))})).observe(e,{childList:!0,subtree:!0}),t.addEventListener("click",(e=>{e.stopPropagation(),o=!o,t.style.transform=`scale(${o?2:1})`,n.classList.toggle("zoomed",o)})),n.addEventListener("click",(()=>n.style.display="none")),document.addEventListener("keydown",(e=>{"Escape"===e.key&&(n.style.display="none")}))}))}();