full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -32,5 +32,5 @@ export declare class TransitionBeforeSwapEvent extends BeforeEvent {
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 declare function doSwap(afterPreparation: BeforeEvent, viewTransition: ViewTransition, afterDispatch?: () => Promise<void>): Promise<TransitionBeforeSwapEvent>;
export {};

View File

@@ -115,9 +115,12 @@ async function doPreparation(from, to, direction, navigationType, sourceElement,
}
return event;
}
function doSwap(afterPreparation, viewTransition) {
async function doSwap(afterPreparation, viewTransition, afterDispatch) {
const event = new TransitionBeforeSwapEvent(afterPreparation, viewTransition);
document.dispatchEvent(event);
if (afterDispatch) {
await afterDispatch();
}
event.swap();
return event;
}

View File

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

View File

@@ -1,4 +1,5 @@
import { TRANSITION_AFTER_SWAP, doPreparation, doSwap } from "./events.js";
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);
@@ -75,6 +76,14 @@ function getFallback() {
}
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",
`<script type="module" src="data:application/javascript,"/>`
);
for (const script of document.getElementsByTagName("script")) {
if (script.dataset.astroExec === "") continue;
const type = script.getAttribute("type");
@@ -186,14 +195,20 @@ async function updateDOM(preparationEvent, options, currentTransition, historySt
);
return Promise.allSettled(newAnimations.map((a) => a.finished));
}
if (fallback === "animate" && !currentTransition.transitionSkipped && !preparationEvent.signal.aborted) {
try {
await animate("old");
} catch {
const animateFallbackOld = async () => {
if (fallback === "animate" && !currentTransition.transitionSkipped && !preparationEvent.signal.aborted) {
try {
await animate("old");
} catch {
}
}
}
};
const pageTitleForBrowserHistory = document.title;
const swapEvent = doSwap(preparationEvent, currentTransition.viewTransition);
const swapEvent = await doSwap(
preparationEvent,
currentTransition.viewTransition,
animateFallbackOld
);
moveToLocation(swapEvent.to, swapEvent.from, options, pageTitleForBrowserHistory, historyState);
triggerEvent(TRANSITION_AFTER_SWAP);
if (fallback === "animate") {
@@ -252,7 +267,7 @@ async function transition(direction, from, to, options, historyState) {
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;
init.body = from !== void 0 && Reflect.get(HTMLFormElement.prototype, "attributes", form).getNamedItem("enctype")?.value === "application/x-www-form-urlencoded" ? new URLSearchParams(preparationEvent.formData) : preparationEvent.formData;
}
const response = await fetchHTML(href, init);
if (response === null) {
@@ -326,7 +341,9 @@ async function transition(direction, from, to, options, historyState) {
skipTransition: () => {
currentTransition.transitionSkipped = true;
document.documentElement.removeAttribute(OLD_NEW_ATTR);
}
},
types: /* @__PURE__ */ new Set()
// empty by default
};
}
currentTransition.viewTransition?.updateCallbackDone.finally(async () => {
@@ -417,6 +434,7 @@ if (inBrowser) {
}
}
for (const script of document.getElementsByTagName("script")) {
detectScriptExecuted(script);
script.dataset.astroExec = "";
}
}

View File

@@ -3,8 +3,9 @@ export type SavedFocus = {
start?: number | null;
end?: number | null;
};
export declare function detectScriptExecuted(script: HTMLScriptElement): boolean;
export declare function deselectScripts(doc: Document): void;
export declare function swapRootAttributes(doc: Document): void;
export declare function swapRootAttributes(newDoc: Document): void;
export declare function swapHeadElements(doc: Document): void;
export declare function swapBodyElement(newElement: Element, oldElement: Element): void;
export declare const saveFocus: () => (() => void);

View File

@@ -1,26 +1,30 @@
const PERSIST_ATTR = "data-astro-transition-persist";
const NON_OVERRIDABLE_ASTRO_ATTRS = ["data-astro-transition", "data-astro-transition-fallback"];
const scriptsAlreadyRan = /* @__PURE__ */ new Set();
function detectScriptExecuted(script) {
const key = script.src ? new URL(script.src, location.href).href : script.textContent;
if (scriptsAlreadyRan.has(key)) return true;
scriptsAlreadyRan.add(key);
return false;
}
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;
}
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") && // Check if the script has already been executed
detectScriptExecuted(s2)
) {
s2.dataset.astroExec = "";
}
}
}
function swapRootAttributes(doc) {
const html = document.documentElement;
const astroAttributes = [...html.attributes].filter(
({ name }) => (html.removeAttribute(name), name.startsWith("data-astro-"))
function swapRootAttributes(newDoc) {
const currentRoot = document.documentElement;
const nonOverridableAstroAttributes = [...currentRoot.attributes].filter(
({ name }) => (currentRoot.removeAttribute(name), NON_OVERRIDABLE_ASTRO_ATTRS.includes(name))
);
[...doc.documentElement.attributes, ...astroAttributes].forEach(
({ name, value }) => html.setAttribute(name, value)
[...newDoc.documentElement.attributes, ...nonOverridableAstroAttributes].forEach(
({ name, value }) => currentRoot.setAttribute(name, value)
);
}
function swapHeadElements(doc) {
@@ -106,6 +110,7 @@ const swap = (doc) => {
};
export {
deselectScripts,
detectScriptExecuted,
restoreFocus,
saveFocus,
swap,

View File

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

View File

@@ -22,27 +22,34 @@ function astroTransitions({ settings }) {
},
load(id) {
if (id === resolvedVirtualModuleId) {
return `
export * from "astro/virtual-modules/transitions.js";
export { default as ViewTransitions } from "astro/components/ViewTransitions.astro";
`;
return {
code: `
export * from "astro/virtual-modules/transitions.js";
export {
default as ViewTransitions,
default as ClientRouter
} from "astro/components/ClientRouter.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";
`;
return {
code: `
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")) {
if (id.includes("ClientRouter.astro") && id.endsWith(".ts")) {
const prefetchDisabled = settings.config.prefetch === false;
return code.replace("__PREFETCH_DISABLED__", JSON.stringify(prefetchDisabled));
}