Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.

This commit is contained in:
becarta
2025-05-23 12:43:00 +02:00
parent f40db0f5c9
commit a544759a3b
11127 changed files with 1647032 additions and 0 deletions

36
node_modules/astro/dist/transitions/events.d.ts generated vendored Normal file
View File

@@ -0,0 +1,36 @@
import type { Direction, NavigationTypeString } from './types.js';
export declare const TRANSITION_BEFORE_PREPARATION = "astro:before-preparation";
export declare const TRANSITION_AFTER_PREPARATION = "astro:after-preparation";
export declare const TRANSITION_BEFORE_SWAP = "astro:before-swap";
export declare const TRANSITION_AFTER_SWAP = "astro:after-swap";
export declare const TRANSITION_PAGE_LOAD = "astro:page-load";
type Events = typeof TRANSITION_AFTER_PREPARATION | typeof TRANSITION_AFTER_SWAP | typeof TRANSITION_PAGE_LOAD;
export declare const triggerEvent: (name: Events) => boolean;
export declare const onPageLoad: () => boolean;
declare class BeforeEvent extends Event {
readonly from: URL;
to: URL;
direction: Direction | string;
readonly navigationType: NavigationTypeString;
readonly sourceElement: Element | undefined;
readonly info: any;
newDocument: Document;
readonly signal: AbortSignal;
constructor(type: string, eventInitDict: EventInit | undefined, from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, newDocument: Document, signal: AbortSignal);
}
export declare const isTransitionBeforePreparationEvent: (value: any) => value is TransitionBeforePreparationEvent;
export declare class TransitionBeforePreparationEvent extends BeforeEvent {
formData: FormData | undefined;
loader: () => Promise<void>;
constructor(from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, newDocument: Document, signal: AbortSignal, formData: FormData | undefined, loader: (event: TransitionBeforePreparationEvent) => Promise<void>);
}
export declare const isTransitionBeforeSwapEvent: (value: any) => value is TransitionBeforeSwapEvent;
export declare class TransitionBeforeSwapEvent extends BeforeEvent {
readonly direction: Direction | string;
readonly viewTransition: ViewTransition;
swap: () => void;
constructor(afterPreparation: BeforeEvent, viewTransition: ViewTransition);
}
export declare function doPreparation(from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, signal: AbortSignal, formData: FormData | undefined, defaultLoader: (event: TransitionBeforePreparationEvent) => Promise<void>): Promise<TransitionBeforePreparationEvent>;
export declare function doSwap(afterPreparation: BeforeEvent, viewTransition: ViewTransition): TransitionBeforeSwapEvent;
export {};

138
node_modules/astro/dist/transitions/events.js generated vendored Normal file
View File

@@ -0,0 +1,138 @@
import { updateScrollPosition } from "./router.js";
import { swap } from "./swap-functions.js";
const TRANSITION_BEFORE_PREPARATION = "astro:before-preparation";
const TRANSITION_AFTER_PREPARATION = "astro:after-preparation";
const TRANSITION_BEFORE_SWAP = "astro:before-swap";
const TRANSITION_AFTER_SWAP = "astro:after-swap";
const TRANSITION_PAGE_LOAD = "astro:page-load";
const triggerEvent = (name) => document.dispatchEvent(new Event(name));
const onPageLoad = () => triggerEvent(TRANSITION_PAGE_LOAD);
class BeforeEvent extends Event {
from;
to;
direction;
navigationType;
sourceElement;
info;
newDocument;
signal;
constructor(type, eventInitDict, from, to, direction, navigationType, sourceElement, info, newDocument, signal) {
super(type, eventInitDict);
this.from = from;
this.to = to;
this.direction = direction;
this.navigationType = navigationType;
this.sourceElement = sourceElement;
this.info = info;
this.newDocument = newDocument;
this.signal = signal;
Object.defineProperties(this, {
from: { enumerable: true },
to: { enumerable: true, writable: true },
direction: { enumerable: true, writable: true },
navigationType: { enumerable: true },
sourceElement: { enumerable: true },
info: { enumerable: true },
newDocument: { enumerable: true, writable: true },
signal: { enumerable: true }
});
}
}
const isTransitionBeforePreparationEvent = (value) => value.type === TRANSITION_BEFORE_PREPARATION;
class TransitionBeforePreparationEvent extends BeforeEvent {
formData;
loader;
constructor(from, to, direction, navigationType, sourceElement, info, newDocument, signal, formData, loader) {
super(
TRANSITION_BEFORE_PREPARATION,
{ cancelable: true },
from,
to,
direction,
navigationType,
sourceElement,
info,
newDocument,
signal
);
this.formData = formData;
this.loader = loader.bind(this, this);
Object.defineProperties(this, {
formData: { enumerable: true },
loader: { enumerable: true, writable: true }
});
}
}
const isTransitionBeforeSwapEvent = (value) => value.type === TRANSITION_BEFORE_SWAP;
class TransitionBeforeSwapEvent extends BeforeEvent {
direction;
viewTransition;
swap;
constructor(afterPreparation, viewTransition) {
super(
TRANSITION_BEFORE_SWAP,
void 0,
afterPreparation.from,
afterPreparation.to,
afterPreparation.direction,
afterPreparation.navigationType,
afterPreparation.sourceElement,
afterPreparation.info,
afterPreparation.newDocument,
afterPreparation.signal
);
this.direction = afterPreparation.direction;
this.viewTransition = viewTransition;
this.swap = () => swap(this.newDocument);
Object.defineProperties(this, {
direction: { enumerable: true },
viewTransition: { enumerable: true },
swap: { enumerable: true, writable: true }
});
}
}
async function doPreparation(from, to, direction, navigationType, sourceElement, info, signal, formData, defaultLoader) {
const event = new TransitionBeforePreparationEvent(
from,
to,
direction,
navigationType,
sourceElement,
info,
window.document,
signal,
formData,
defaultLoader
);
if (document.dispatchEvent(event)) {
await event.loader();
if (!event.defaultPrevented) {
triggerEvent(TRANSITION_AFTER_PREPARATION);
if (event.navigationType !== "traverse") {
updateScrollPosition({ scrollX, scrollY });
}
}
}
return event;
}
function doSwap(afterPreparation, viewTransition) {
const event = new TransitionBeforeSwapEvent(afterPreparation, viewTransition);
document.dispatchEvent(event);
event.swap();
return event;
}
export {
TRANSITION_AFTER_PREPARATION,
TRANSITION_AFTER_SWAP,
TRANSITION_BEFORE_PREPARATION,
TRANSITION_BEFORE_SWAP,
TRANSITION_PAGE_LOAD,
TransitionBeforePreparationEvent,
TransitionBeforeSwapEvent,
doPreparation,
doSwap,
isTransitionBeforePreparationEvent,
isTransitionBeforeSwapEvent,
onPageLoad,
triggerEvent
};

8
node_modules/astro/dist/transitions/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
import type { TransitionDirectionalAnimations } from '../@types/astro.js';
export { createAnimationScope } from '../runtime/server/transition.js';
export declare function slide({ duration, }?: {
duration?: string | number;
}): TransitionDirectionalAnimations;
export declare function fade({ duration, }?: {
duration?: string | number;
}): TransitionDirectionalAnimations;

70
node_modules/astro/dist/transitions/index.js generated vendored Normal file
View File

@@ -0,0 +1,70 @@
import { createAnimationScope } from "../runtime/server/transition.js";
const EASE_IN_OUT_QUART = "cubic-bezier(0.76, 0, 0.24, 1)";
function slide({
duration
} = {}) {
return {
forwards: {
old: [
{
name: "astroFadeOut",
duration: duration ?? "90ms",
easing: EASE_IN_OUT_QUART,
fillMode: "both"
},
{
name: "astroSlideToLeft",
duration: duration ?? "220ms",
easing: EASE_IN_OUT_QUART,
fillMode: "both"
}
],
new: [
{
name: "astroFadeIn",
duration: duration ?? "210ms",
easing: EASE_IN_OUT_QUART,
delay: duration ? void 0 : "30ms",
fillMode: "both"
},
{
name: "astroSlideFromRight",
duration: duration ?? "220ms",
easing: EASE_IN_OUT_QUART,
fillMode: "both"
}
]
},
backwards: {
old: [{ name: "astroFadeOut" }, { name: "astroSlideToRight" }],
new: [{ name: "astroFadeIn" }, { name: "astroSlideFromLeft" }]
}
};
}
function fade({
duration
} = {}) {
const anim = {
old: {
name: "astroFadeOut",
duration: duration ?? 180,
easing: EASE_IN_OUT_QUART,
fillMode: "both"
},
new: {
name: "astroFadeIn",
duration: duration ?? 180,
easing: EASE_IN_OUT_QUART,
fillMode: "both"
}
};
return {
forwards: anim,
backwards: anim
};
}
export {
createAnimationScope,
fade,
slide
};

9
node_modules/astro/dist/transitions/router.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import type { Fallback, Options } from './types.js';
export declare const updateScrollPosition: (positions: {
scrollX: number;
scrollY: number;
}) => void;
export declare const supportsViewTransitions: boolean;
export declare const transitionEnabledOnThisPage: () => boolean;
export declare function getFallback(): Fallback;
export declare function navigate(href: string, options?: Options): Promise<void>;

470
node_modules/astro/dist/transitions/router.js generated vendored Normal file
View File

@@ -0,0 +1,470 @@
import { TRANSITION_AFTER_SWAP, doPreparation, doSwap } from "./events.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();
for (const script of document.getElementsByTagName("script")) {
if (script.dataset.astroExec === "") continue;
const type = script.getAttribute("type");
if (type && type !== "module" && type !== "text/javascript") continue;
const newScript = document.createElement("script");
newScript.innerHTML = script.innerHTML;
for (const attr of script.attributes) {
if (attr.name === "src") {
const p = new Promise((r) => {
newScript.onload = newScript.onerror = r;
});
wait = wait.then(() => p);
}
newScript.setAttribute(attr.name, attr.value);
}
newScript.dataset.astroExec = "";
script.replaceWith(newScript);
}
return wait;
}
const moveToLocation = (to, from, options, pageTitleForBrowserHistory, historyState) => {
const intraPage = samePage(from, to);
const targetPageTitle = document.title;
document.title = pageTitleForBrowserHistory;
let scrolledToTop = false;
if (to.href !== location.href && !historyState) {
if (options.history === "replace") {
const current = history.state;
replaceState(
{
...options.state,
index: current.index,
scrollX: current.scrollX,
scrollY: current.scrollY
},
"",
to.href
);
} else {
pushState(
{ ...options.state, index: ++currentHistoryIndex, scrollX: 0, scrollY: 0 },
"",
to.href
);
}
}
document.title = targetPageTitle;
originalLocation = to;
if (!intraPage) {
scrollTo({ left: 0, top: 0, behavior: "instant" });
scrolledToTop = true;
}
if (historyState) {
scrollTo(historyState.scrollX, historyState.scrollY);
} else {
if (to.hash) {
history.scrollRestoration = "auto";
const savedState = history.state;
location.href = to.href;
if (!history.state) {
replaceState(savedState, "");
if (intraPage) {
window.dispatchEvent(new PopStateEvent("popstate"));
}
}
} else {
if (!scrolledToTop) {
scrollTo({ left: 0, top: 0, behavior: "instant" });
}
}
history.scrollRestoration = "manual";
}
};
function preloadStyleLinks(newDocument) {
const links = [];
for (const el of newDocument.querySelectorAll("head link[rel=stylesheet]")) {
if (!document.querySelector(
`[${PERSIST_ATTR}="${el.getAttribute(
PERSIST_ATTR
)}"], link[rel=stylesheet][href="${el.getAttribute("href")}"]`
)) {
const c = document.createElement("link");
c.setAttribute("rel", "preload");
c.setAttribute("as", "style");
c.setAttribute("href", el.getAttribute("href"));
links.push(
new Promise((resolve) => {
["load", "error"].forEach((evName) => c.addEventListener(evName, resolve));
document.head.append(c);
})
);
}
}
return links;
}
async function updateDOM(preparationEvent, options, currentTransition, historyState, fallback) {
async function animate(phase) {
function isInfinite(animation) {
const effect = animation.effect;
if (!effect || !(effect instanceof KeyframeEffect) || !effect.target) return false;
const style = window.getComputedStyle(effect.target, effect.pseudoElement);
return style.animationIterationCount === "infinite";
}
const currentAnimations = document.getAnimations();
document.documentElement.setAttribute(OLD_NEW_ATTR, phase);
const nextAnimations = document.getAnimations();
const newAnimations = nextAnimations.filter(
(a) => !currentAnimations.includes(a) && !isInfinite(a)
);
return Promise.allSettled(newAnimations.map((a) => a.finished));
}
if (fallback === "animate" && !currentTransition.transitionSkipped && !preparationEvent.signal.aborted) {
try {
await animate("old");
} catch {
}
}
const pageTitleForBrowserHistory = document.title;
const swapEvent = doSwap(preparationEvent, currentTransition.viewTransition);
moveToLocation(swapEvent.to, swapEvent.from, options, pageTitleForBrowserHistory, historyState);
triggerEvent(TRANSITION_AFTER_SWAP);
if (fallback === "animate") {
if (!currentTransition.transitionSkipped && !swapEvent.signal.aborted) {
animate("new").finally(() => currentTransition.viewTransitionFinished());
} else {
currentTransition.viewTransitionFinished();
}
}
}
function abortAndRecreateMostRecentNavigation() {
mostRecentNavigation?.controller.abort();
return mostRecentNavigation = {
controller: new AbortController()
};
}
async function transition(direction, from, to, options, historyState) {
const currentNavigation = abortAndRecreateMostRecentNavigation();
if (!transitionEnabledOnThisPage() || location.origin !== to.origin) {
if (currentNavigation === mostRecentNavigation) mostRecentNavigation = void 0;
location.href = to.href;
return;
}
const navigationType = historyState ? "traverse" : options.history === "replace" ? "replace" : "push";
if (navigationType !== "traverse") {
updateScrollPosition({ scrollX, scrollY });
}
if (samePage(from, to)) {
if (direction !== "back" && to.hash || direction === "back" && from.hash) {
moveToLocation(to, from, options, document.title, historyState);
if (currentNavigation === mostRecentNavigation) mostRecentNavigation = void 0;
return;
}
}
const prepEvent = await doPreparation(
from,
to,
direction,
navigationType,
options.sourceElement,
options.info,
currentNavigation.controller.signal,
options.formData,
defaultLoader
);
if (prepEvent.defaultPrevented || prepEvent.signal.aborted) {
if (currentNavigation === mostRecentNavigation) mostRecentNavigation = void 0;
if (!prepEvent.signal.aborted) {
location.href = to.href;
}
return;
}
async function defaultLoader(preparationEvent) {
const href = preparationEvent.to.href;
const init = { signal: preparationEvent.signal };
if (preparationEvent.formData) {
init.method = "POST";
const form = preparationEvent.sourceElement instanceof HTMLFormElement ? preparationEvent.sourceElement : preparationEvent.sourceElement instanceof HTMLElement && "form" in preparationEvent.sourceElement ? preparationEvent.sourceElement.form : preparationEvent.sourceElement?.closest("form");
init.body = form?.attributes.getNamedItem("enctype")?.value === "application/x-www-form-urlencoded" ? new URLSearchParams(preparationEvent.formData) : preparationEvent.formData;
}
const response = await fetchHTML(href, init);
if (response === null) {
preparationEvent.preventDefault();
return;
}
if (response.redirected) {
const redirectedTo = new URL(response.redirected);
if (redirectedTo.origin !== preparationEvent.to.origin) {
preparationEvent.preventDefault();
return;
}
preparationEvent.to = redirectedTo;
}
parser ??= new DOMParser();
preparationEvent.newDocument = parser.parseFromString(response.html, response.mediaType);
preparationEvent.newDocument.querySelectorAll("noscript").forEach((el) => el.remove());
if (!preparationEvent.newDocument.querySelector('[name="astro-view-transitions-enabled"]') && !preparationEvent.formData) {
preparationEvent.preventDefault();
return;
}
const links = preloadStyleLinks(preparationEvent.newDocument);
links.length && !preparationEvent.signal.aborted && await Promise.all(links);
if (import.meta.env.DEV && !preparationEvent.signal.aborted)
await prepareForClientOnlyComponents(
preparationEvent.newDocument,
preparationEvent.to,
preparationEvent.signal
);
}
async function abortAndRecreateMostRecentTransition() {
if (mostRecentTransition) {
if (mostRecentTransition.viewTransition) {
try {
mostRecentTransition.viewTransition.skipTransition();
} catch {
}
try {
await mostRecentTransition.viewTransition.updateCallbackDone;
} catch {
}
}
}
return mostRecentTransition = { transitionSkipped: false };
}
const currentTransition = await abortAndRecreateMostRecentTransition();
if (prepEvent.signal.aborted) {
if (currentNavigation === mostRecentNavigation) mostRecentNavigation = void 0;
return;
}
document.documentElement.setAttribute(DIRECTION_ATTR, prepEvent.direction);
if (supportsViewTransitions) {
currentTransition.viewTransition = document.startViewTransition(
async () => await updateDOM(prepEvent, options, currentTransition, historyState)
);
} else {
const updateDone = (async () => {
await Promise.resolve();
await updateDOM(prepEvent, options, currentTransition, historyState, getFallback());
return void 0;
})();
currentTransition.viewTransition = {
updateCallbackDone: updateDone,
// this is about correct
ready: updateDone,
// good enough
// Finished promise could have been done better: finished rejects iff updateDone does.
// Our simulation always resolves, never rejects.
finished: new Promise((r) => currentTransition.viewTransitionFinished = r),
// see end of updateDOM
skipTransition: () => {
currentTransition.transitionSkipped = true;
document.documentElement.removeAttribute(OLD_NEW_ATTR);
}
};
}
currentTransition.viewTransition?.updateCallbackDone.finally(async () => {
await runScripts();
onPageLoad();
announce();
});
currentTransition.viewTransition?.finished.finally(() => {
currentTransition.viewTransition = void 0;
if (currentTransition === mostRecentTransition) mostRecentTransition = void 0;
if (currentNavigation === mostRecentNavigation) mostRecentNavigation = void 0;
document.documentElement.removeAttribute(DIRECTION_ATTR);
document.documentElement.removeAttribute(OLD_NEW_ATTR);
});
try {
await currentTransition.viewTransition?.updateCallbackDone;
} catch (e) {
const err = e;
console.log("[astro]", err.name, err.message, err.stack);
}
}
let navigateOnServerWarned = false;
async function navigate(href, options) {
if (inBrowser === false) {
if (!navigateOnServerWarned) {
const warning = new Error(
"The view transitions client API was called during a server side render. This may be unintentional as the navigate() function is expected to be called in response to user interactions. Please make sure that your usage is correct."
);
warning.name = "Warning";
console.warn(warning);
navigateOnServerWarned = true;
}
return;
}
await transition("forward", originalLocation, new URL(href, location.href), options ?? {});
}
function onPopState(ev) {
if (!transitionEnabledOnThisPage() && ev.state) {
location.reload();
return;
}
if (ev.state === null) {
return;
}
const state = history.state;
const nextIndex = state.index;
const direction = nextIndex > currentHistoryIndex ? "forward" : "back";
currentHistoryIndex = nextIndex;
transition(direction, originalLocation, new URL(location.href), {}, state);
}
const onScrollEnd = () => {
if (history.state && (scrollX !== history.state.scrollX || scrollY !== history.state.scrollY)) {
updateScrollPosition({ scrollX, scrollY });
}
};
if (inBrowser) {
if (supportsViewTransitions || getFallback() !== "none") {
originalLocation = new URL(location.href);
addEventListener("popstate", onPopState);
addEventListener("load", onPageLoad);
if ("onscrollend" in window) addEventListener("scrollend", onScrollEnd);
else {
let intervalId, lastY, lastX, lastIndex;
const scrollInterval = () => {
if (lastIndex !== history.state?.index) {
clearInterval(intervalId);
intervalId = void 0;
return;
}
if (lastY === scrollY && lastX === scrollX) {
clearInterval(intervalId);
intervalId = void 0;
onScrollEnd();
return;
} else {
lastY = scrollY, lastX = scrollX;
}
};
addEventListener(
"scroll",
() => {
if (intervalId !== void 0) return;
lastIndex = history.state?.index, lastY = scrollY, lastX = scrollX;
intervalId = window.setInterval(scrollInterval, 50);
},
{ passive: true }
);
}
}
for (const script of document.getElementsByTagName("script")) {
script.dataset.astroExec = "";
}
}
async function prepareForClientOnlyComponents(newDocument, toLocation, signal) {
if (newDocument.body.querySelector(`astro-island[client='only']`)) {
const nextPage = document.createElement("iframe");
nextPage.src = toLocation.href;
nextPage.style.display = "none";
document.body.append(nextPage);
nextPage.contentWindow.console = Object.keys(console).reduce((acc, key) => {
acc[key] = () => {
};
return acc;
}, {});
await hydrationDone(nextPage);
const nextHead = nextPage.contentDocument?.head;
if (nextHead) {
const viteIds = [...nextHead.querySelectorAll(`style[${VITE_ID}]`)].map(
(style) => style.getAttribute(VITE_ID)
);
viteIds.forEach((id) => {
const style = nextHead.querySelector(`style[${VITE_ID}="${id}"]`);
if (style && !newDocument.head.querySelector(`style[${VITE_ID}="${id}"]`)) {
newDocument.head.appendChild(style.cloneNode(true));
}
});
}
async function hydrationDone(loadingPage) {
if (!signal.aborted) {
await new Promise(
(r) => loadingPage.contentWindow?.addEventListener("load", r, { once: true })
);
}
return new Promise(async (r) => {
for (let count = 0; count <= 20; ++count) {
if (signal.aborted) break;
if (!loadingPage.contentDocument.body.querySelector("astro-island[ssr]")) break;
await new Promise((r2) => setTimeout(r2, 50));
}
r();
});
}
}
}
export {
getFallback,
navigate,
supportsViewTransitions,
transitionEnabledOnThisPage,
updateScrollPosition
};

View File

@@ -0,0 +1,19 @@
export type SavedFocus = {
activeElement: HTMLElement | null;
start?: number | null;
end?: number | null;
};
export declare function deselectScripts(doc: Document): void;
export declare function swapRootAttributes(doc: Document): void;
export declare function swapHeadElements(doc: Document): void;
export declare function swapBodyElement(newElement: Element, oldElement: Element): void;
export declare const saveFocus: () => (() => void);
export declare const restoreFocus: ({ activeElement, start, end }: SavedFocus) => void;
export declare const swapFunctions: {
deselectScripts: typeof deselectScripts;
swapRootAttributes: typeof swapRootAttributes;
swapHeadElements: typeof swapHeadElements;
swapBodyElement: typeof swapBodyElement;
saveFocus: () => (() => void);
};
export declare const swap: (doc: Document) => void;

116
node_modules/astro/dist/transitions/swap-functions.js generated vendored Normal file
View File

@@ -0,0 +1,116 @@
const PERSIST_ATTR = "data-astro-transition-persist";
function deselectScripts(doc) {
for (const s1 of document.scripts) {
for (const s2 of doc.scripts) {
if (
// Check if the script should be rerun regardless of it being the same
!s2.hasAttribute("data-astro-rerun") && // Inline
(!s1.src && s1.textContent === s2.textContent || // External
s1.src && s1.type === s2.type && s1.src === s2.src)
) {
s2.dataset.astroExec = "";
break;
}
}
}
}
function swapRootAttributes(doc) {
const html = document.documentElement;
const astroAttributes = [...html.attributes].filter(
({ name }) => (html.removeAttribute(name), name.startsWith("data-astro-"))
);
[...doc.documentElement.attributes, ...astroAttributes].forEach(
({ name, value }) => html.setAttribute(name, value)
);
}
function swapHeadElements(doc) {
for (const el of Array.from(document.head.children)) {
const newEl = persistedHeadElement(el, doc);
if (newEl) {
newEl.remove();
} else {
el.remove();
}
}
document.head.append(...doc.head.children);
}
function swapBodyElement(newElement, oldElement) {
oldElement.replaceWith(newElement);
for (const el of oldElement.querySelectorAll(`[${PERSIST_ATTR}]`)) {
const id = el.getAttribute(PERSIST_ATTR);
const newEl = newElement.querySelector(`[${PERSIST_ATTR}="${id}"]`);
if (newEl) {
newEl.replaceWith(el);
if (newEl.localName === "astro-island" && shouldCopyProps(el) && !isSameProps(el, newEl)) {
el.setAttribute("ssr", "");
el.setAttribute("props", newEl.getAttribute("props"));
}
}
}
}
const saveFocus = () => {
const activeElement = document.activeElement;
if (activeElement?.closest(`[${PERSIST_ATTR}]`)) {
if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {
const start = activeElement.selectionStart;
const end = activeElement.selectionEnd;
return () => restoreFocus({ activeElement, start, end });
}
return () => restoreFocus({ activeElement });
} else {
return () => restoreFocus({ activeElement: null });
}
};
const restoreFocus = ({ activeElement, start, end }) => {
if (activeElement) {
activeElement.focus();
if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {
if (typeof start === "number") activeElement.selectionStart = start;
if (typeof end === "number") activeElement.selectionEnd = end;
}
}
};
const persistedHeadElement = (el, newDoc) => {
const id = el.getAttribute(PERSIST_ATTR);
const newEl = id && newDoc.head.querySelector(`[${PERSIST_ATTR}="${id}"]`);
if (newEl) {
return newEl;
}
if (el.matches("link[rel=stylesheet]")) {
const href = el.getAttribute("href");
return newDoc.head.querySelector(`link[rel=stylesheet][href="${href}"]`);
}
return null;
};
const shouldCopyProps = (el) => {
const persistProps = el.dataset.astroTransitionPersistProps;
return persistProps == null || persistProps === "false";
};
const isSameProps = (oldEl, newEl) => {
return oldEl.getAttribute("props") === newEl.getAttribute("props");
};
const swapFunctions = {
deselectScripts,
swapRootAttributes,
swapHeadElements,
swapBodyElement,
saveFocus
};
const swap = (doc) => {
deselectScripts(doc);
swapRootAttributes(doc);
swapHeadElements(doc);
const restoreFocusFunction = saveFocus();
swapBodyElement(doc.body, document.body);
restoreFocusFunction();
};
export {
deselectScripts,
restoreFocus,
saveFocus,
swap,
swapBodyElement,
swapFunctions,
swapHeadElements,
swapRootAttributes
};

10
node_modules/astro/dist/transitions/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
export type Fallback = 'none' | 'animate' | 'swap';
export type Direction = 'forward' | 'back';
export type NavigationTypeString = 'push' | 'replace' | 'traverse';
export type Options = {
history?: 'auto' | 'push' | 'replace';
info?: any;
state?: any;
formData?: FormData;
sourceElement?: Element;
};

0
node_modules/astro/dist/transitions/types.js generated vendored Normal file
View File

View File

@@ -0,0 +1,5 @@
import type * as vite from 'vite';
import type { AstroSettings } from '../@types/astro.js';
export default function astroTransitions({ settings }: {
settings: AstroSettings;
}): vite.Plugin;

View File

@@ -0,0 +1,54 @@
const virtualModuleId = "astro:transitions";
const resolvedVirtualModuleId = "\0" + virtualModuleId;
const virtualClientModuleId = "astro:transitions/client";
const resolvedVirtualClientModuleId = "\0" + virtualClientModuleId;
function astroTransitions({ settings }) {
return {
name: "astro:transitions",
config() {
return {
optimizeDeps: {
include: ["astro > cssesc"]
}
};
},
async resolveId(id) {
if (id === virtualModuleId) {
return resolvedVirtualModuleId;
}
if (id === virtualClientModuleId) {
return resolvedVirtualClientModuleId;
}
},
load(id) {
if (id === resolvedVirtualModuleId) {
return `
export * from "astro/virtual-modules/transitions.js";
export { default as ViewTransitions } from "astro/components/ViewTransitions.astro";
`;
}
if (id === resolvedVirtualClientModuleId) {
return `
export { navigate, supportsViewTransitions, transitionEnabledOnThisPage } from "astro/virtual-modules/transitions-router.js";
export * from "astro/virtual-modules/transitions-types.js";
export {
TRANSITION_BEFORE_PREPARATION, isTransitionBeforePreparationEvent, TransitionBeforePreparationEvent,
TRANSITION_AFTER_PREPARATION,
TRANSITION_BEFORE_SWAP, isTransitionBeforeSwapEvent, TransitionBeforeSwapEvent,
TRANSITION_AFTER_SWAP, TRANSITION_PAGE_LOAD
} from "astro/virtual-modules/transitions-events.js";
export { swapFunctions } from "astro/virtual-modules/transitions-swap-functions.js";
`;
}
},
transform(code, id) {
if (id.includes("ViewTransitions.astro") && id.endsWith(".ts")) {
const prefetchDisabled = settings.config.prefetch === false;
return code.replace("__PREFETCH_DISABLED__", JSON.stringify(prefetchDisabled));
}
}
};
}
export {
astroTransitions as default
};