import { doPreparation, doSwap, TRANSITION_AFTER_SWAP } from "./events.js"; import { detectScriptExecuted } from "./swap-functions.js"; const inBrowser = import.meta.env.SSR === false; const pushState = inBrowser && history.pushState.bind(history); const replaceState = inBrowser && history.replaceState.bind(history); const updateScrollPosition = (positions) => { if (history.state) { history.scrollRestoration = "manual"; replaceState({ ...history.state, ...positions }, ""); } }; const supportsViewTransitions = inBrowser && !!document.startViewTransition; const transitionEnabledOnThisPage = () => inBrowser && !!document.querySelector('[name="astro-view-transitions-enabled"]'); const samePage = (thisLocation, otherLocation) => thisLocation.pathname === otherLocation.pathname && thisLocation.search === otherLocation.search; let mostRecentNavigation; let mostRecentTransition; let originalLocation; const triggerEvent = (name) => document.dispatchEvent(new Event(name)); const onPageLoad = () => triggerEvent("astro:page-load"); const announce = () => { let div = document.createElement("div"); div.setAttribute("aria-live", "assertive"); div.setAttribute("aria-atomic", "true"); div.className = "astro-route-announcer"; document.body.append(div); setTimeout( () => { let title = document.title || document.querySelector("h1")?.textContent || location.pathname; div.textContent = title; }, // Much thought went into this magic number; the gist is that screen readers // need to see that the element changed and might not do so if it happens // too quickly. 60 ); }; const PERSIST_ATTR = "data-astro-transition-persist"; const DIRECTION_ATTR = "data-astro-transition"; const OLD_NEW_ATTR = "data-astro-transition-fallback"; const VITE_ID = "data-vite-dev-id"; let parser; let currentHistoryIndex = 0; if (inBrowser) { if (history.state) { currentHistoryIndex = history.state.index; scrollTo({ left: history.state.scrollX, top: history.state.scrollY }); } else if (transitionEnabledOnThisPage()) { replaceState({ index: currentHistoryIndex, scrollX, scrollY }, ""); history.scrollRestoration = "manual"; } } async function fetchHTML(href, init) { try { const res = await fetch(href, init); const contentType = res.headers.get("content-type") ?? ""; const mediaType = contentType.split(";", 1)[0].trim(); if (mediaType !== "text/html" && mediaType !== "application/xhtml+xml") { return null; } const html = await res.text(); return { html, redirected: res.redirected ? res.url : void 0, mediaType }; } catch { return null; } } function getFallback() { const el = document.querySelector('[name="astro-view-transitions-fallback"]'); if (el) { return el.getAttribute("content"); } return "animate"; } function runScripts() { let wait = Promise.resolve(); let needsWaitForInlineModuleScript = false; for (const script of document.getElementsByTagName("script")) { script.dataset.astroExec === void 0 && script.getAttribute("type") === "module" && (needsWaitForInlineModuleScript = script.getAttribute("src") === null); } needsWaitForInlineModuleScript && document.body.insertAdjacentHTML( "beforeend", `