import { M as Metadata } from './client-plugins-Bz7W8EKI.mjs'; import { F as FarmClientPluginManager } from './lifecycle-De0vQG45.mjs'; import { F as FarmI18nClientSnapshot } from './types-CnH8DOqo.mjs'; import { F as FarmIslandStrategy } from './island-CfGru1MO.mjs'; import { F as FarmRouteRenderPlan } from './render-plan-ChTe_Abo.mjs'; type NavigationMetadata = (Metadata & Record) | undefined; /** * Farm.js SPA Router * * Provides client-side navigation without full page reloads. * Features: * - Prefetch on viewport intersection * - Prefetch on hover * - Page caching * - History API integration * - Scroll restoration */ interface PageData { props: Record; modulePath: string; loadingModulePath?: string | null; canonicalPath?: string; isClientComponent?: boolean; shouldHydrate?: boolean; islandStrategy?: FarmIslandStrategy | null; renderPlan?: FarmRouteRenderPlan; fragment?: { html: string; layoutPatterns: string[]; }; metadata?: NavigationMetadata; layoutModules?: string[]; routeSlots?: RouteSlotPageData[]; interception?: { from?: string; slots: string[]; }; i18n?: FarmI18nClientSnapshot; } interface RouteSlotPageData { name: string; ownerPattern: string; containerId: string; interception: boolean; fallback: boolean; modulePath: string; isClientComponent: boolean; shouldHydrate: boolean; props: Record; } interface RouterOptions { prefetchTimeout?: number; cacheMaxAge?: number; scrollRestoration?: boolean; shouldUseDocumentNavigation?: (pathname: string) => boolean; deploymentId?: string; } interface FarmNavigationBlockerContext { from: string; to: string; action: "push" | "replace" | "pop"; } type FarmNavigationBlocker = (context: FarmNavigationBlockerContext) => boolean | void | Promise; type FarmViewTransitionMode = boolean | "auto"; interface FarmNavigateOptions { replace?: boolean; scroll?: boolean; state?: unknown; viewTransition?: FarmViewTransitionMode; /** Re-fetch the current route even when its URL has not changed. */ refresh?: boolean; } interface FarmNavigationLocation { href: string; pathname: string; search: string; hash: string; } interface FarmNavigationState { state: "idle" | "loading"; pending: boolean; from: string | null; to: FarmNavigationLocation | null; action: FarmNavigationBlockerContext["action"] | null; startedAt: number | null; } type FarmNavigationListener = (state: FarmNavigationState) => void; declare class SPARouter { private cache; private prefetchingUrls; private observers; private prefetchTimers; private blockers; private unloadBlockers; private navigationListeners; private navigationState; private currentHistoryPath; private currentHistoryIndex; private suppressNextPopState; private navigationSequence; private activeNavigation?; private scrollElements; private options; private onNavigate?; private clientPlugins?; private readonly onPopState; private readonly onBeforeUnload; constructor(options?: RouterOptions); /** Remove global listeners. Intended for tests and teardown. */ destroy(): void; /** * Set the navigation handler that updates React */ setNavigationHandler(handler: (data: PageData) => Promise): void; /** * Connect Farm's browser plugin lifecycle to SPA navigation. */ setClientPluginManager(manager: FarmClientPluginManager): void; /** * Navigate to a new URL */ navigate(href: string, options?: FarmNavigateOptions): Promise; /** * Re-render the active route from the server while preserving the document, * shared layouts, client runtime, and browser history entry. */ refresh(options?: Omit): Promise; /** * Prefetch a URL */ prefetch(href: string): Promise; /** * Observe an element for viewport intersection (prefetch when visible) */ observeForPrefetch(element: HTMLAnchorElement): void; /** * Stop observing an element */ unobserveForPrefetch(element: HTMLAnchorElement): void; addBlocker(blocker: FarmNavigationBlocker, shouldBlockUnload?: () => boolean): () => void; getNavigationState(): FarmNavigationState; subscribeNavigation(listener: FarmNavigationListener): () => void; registerScrollElement(key: string, element: HTMLElement): () => void; pushState(state: unknown, href?: string): void; replaceState(state: unknown, href?: string): void; /** @internal Keep shallow URL-search writes inside the router's history bookkeeping. */ writeURLSearch(action: "push" | "replace", href: string): void; private commitNavigation; private runViewTransition; /** * Fetch page data from cache or server */ private fetchPageData; /** * Put the browser URL back on the rendered page after a blocked pop. When * both entries carry a Farm history index the traversal is reversed * exactly; otherwise the current path is pushed again, which restores the * address bar at the cost of one extra history entry. */ private revertBlockedPopState; /** * Handle browser back/forward navigation */ private handlePopState; /** * Check if URL is cached */ private isCached; /** * Check if URL is external */ private isExternalUrl; private shouldBlockNavigation; private evaluateBlockerForUnload; private shouldBlockUnload; private updateDocumentMetadata; private startNavigation; private isCurrentNavigation; private finishNavigation; private cancelActiveNavigation; private setNavigationState; private writePageState; /** * Save scroll position for a path */ private saveScrollPosition; /** * Restore the saved window scroll position for a path. */ private restoreWindowScroll; /** * Restore saved scroll positions for every registered scroll element. Keys * are hash-stripped (see getScrollElementStorageKey), so this runs regardless * of whether the destination URL carries a fragment. */ private restoreScrollElements; private restoreScrollElement; /** * Clear the page cache */ clearCache(): void; } declare function getRouter(): SPARouter; /** * Navigate to a URL using the SPA router */ declare function navigateTo(href: string, options?: FarmNavigateOptions): Promise; /** * Prefetch a URL */ declare function prefetch(href: string): Promise; declare function pushState(state: unknown, href?: string): void; declare function replaceState(state: unknown, href?: string): void; declare function readPageState(): TState | null; export { type FarmNavigationState as F, SPARouter as S, type FarmNavigateOptions as a, pushState as b, replaceState as c, type FarmNavigationBlocker as d, type FarmNavigationBlockerContext as e, type FarmNavigationListener as f, getRouter as g, type FarmNavigationLocation as h, type FarmViewTransitionMode as i, navigateTo as n, prefetch as p, readPageState as r };