// SvelteKit `onNavigate` helper — wraps client-side navigation in the // browser's View Transitions API so route changes cross-fade cleanly and // shared-element transitions (Fleet card → Server detail hero) morph. // // Chromium ships the API today; Firefox and Safari fall through to a plain // navigation — same behavior as before, just without the transition. // Structural type — accepts whatever SvelteKit passes to onNavigate without // coupling to a specific @sveltejs/kit version's type name. type NavigationLike = { complete: Promise }; export function enableViewTransitions(navigation: NavigationLike): Promise | void { // Feature-detect without a custom Document extension — the DOM lib type // varies between TS versions, and any narrowing has to survive both. const start = (document as unknown as { startViewTransition?: (cb: () => void | Promise) => unknown; }).startViewTransition; if (typeof start !== 'function') return; return new Promise((resolve) => { start.call(document, async () => { resolve(); await navigation.complete; }); }); }