import { Observable, type ObservableListener } from 'observavir'; import { type FullSpaRoute, type SpaRoute, type ValidHashBase, type ValidPathsBase, type ValidSearchBase } from './spa-route.js'; import { type SpaRouterParams } from './spa-router-params.js'; /** * A router for SPAs which allows listening to and setting the window's URL with type safety. * * @category Main */ export declare class SpaRouter { protected innerObservable: Observable>; /** * Removes the `SpaRouter`'s listener to global URL changes. This is used when `.destroy()` is * called. */ protected removeGlobalListener: () => void; protected sanitizationDepth: number; /** The params with which this `SpaRouter` was initially constructed. */ params: SpaRouterParams; constructor(params: Readonly>); /** Detect if the given route already includes the router's `basePath`. */ protected routeIncludesBasePath(route: Readonly>>): boolean; /** Reads the current route with the sanitizer so it's type safe. */ readCurrentRoute(): FullSpaRoute; /** Run the sanitizer this `SpaRouter` instance was initialized with on any given route. */ sanitizeRoute(rawRoute: Readonly): FullSpaRoute; /** Create a full URL href string from the given route (combined with the current route). */ createRouteUrl(newRoute: Readonly>>): { url: string; route: Required>; }; /** * Write a new route to the window URL after sanitization. If the sanitized new route equals the * current window URL, no update will occur. When an update _does_ occur, route listeners will * be fired. * * @returns Whether the route was set or not. */ setRoute(newRoute: Readonly>>, options?: Readonly<{ /** * If set to `true`, the current route will be _replaced_ with the new route. What this * means in practice is that users won't be able to hit the "back" button to go back to * the previous route. * * @default false */ replace?: boolean | undefined; /** * If set to true, the new route will be set even if it's equal to the current route. * * @default false */ force?: boolean | undefined; }>): boolean; /** * Sets the given route using the given `SpaRouter` only if the user's click event was for * direct navigation (rather than trying to open it in a new tab or right clicking on it). * * @returns Whether the route was routed to or not. */ setRouteOnDirectNavigation(newRoute: Readonly>>, mouseEvent: Readonly>): boolean; /** * Listen to route changes. * * @returns A callback to remove the listener. */ listen(fireImmediately: boolean, listener: ObservableListener>): () => boolean; /** * Removes a route listener. * * @returns `true` if the callback was removed. `false` if the callback was not removed (meaning * it was never added in the first place). */ removeListener(listener: ObservableListener>): boolean; /** Count how many route listeners have been attached. */ getListenerCount(): number; /** * Removes all listeners. Note that this does not undo the global URL event consolidation * performed by `consolidateGlobalUrlEvents`. */ destroy(): void; }