import { M as MountResult } from './mount-Bo2qOx25.js'; import { ReadonlySignal } from '@preact/signals-core'; import './jsx-runtime.js'; import './bindings-CYwoJpQb.js'; /** The reactive current-route snapshot (`router.route.value`). */ interface RouteState { /** The matched pathname, base stripped (history mode) or the hash body (hash mode). Always starts with `/`. */ path: string; /** Path parameters from the matched pattern — `/users/:id` on `/users/7` → `{ id: '7' }`. */ params: Record; /** The parsed query string (`?a=1` → `URLSearchParams`). Empty when there is none. */ query: URLSearchParams; /** The raw location hash including `#` (history mode), or `''`. In hash mode the hash IS the route, so this is `''`. */ hash: string; } /** A route's view: receives the matched `params` and the full `route` snapshot, returns kerf content. */ type RouteComponent = (params: Record, route: RouteState) => MountResult; /** One route in the table. `path` is a pattern: `/`, `/users/:id`, `/files/*rest`, or `*` (catch-all). */ interface RouteDef { /** Pattern: static segments, `:param` captures, a trailing `*rest` wildcard, or `*` (matches anything — put last). */ path: string; /** The view rendered in the outlet when this route matches. */ component: RouteComponent; } /** Options for {@link navigate}. */ interface NavigateOptions { /** Replace the current history entry instead of pushing a new one. Default `false`. */ replace?: boolean; /** Arbitrary state stored on the history entry (readable via `history.state`). */ state?: unknown; } /** Options for {@link createRouter}. */ interface RouterOptions { /** The route table, tried in order; the first match wins. Include a `path: '*'` entry last for a fallback. */ routes: readonly RouteDef[]; /** * `'history'` (default) uses the real pathname (`/users/7`) via the History * API; `'hash'` keeps the route after `#` (`#/users/7`) for static hosts with * no server rewrite. */ mode?: 'history' | 'hash'; /** History mode only: a base path every route sits under (`/app`), stripped from `route.path` and prepended on navigation. */ base?: string; /** * Auto-intercept clicks on in-app `` links (same-origin, left-click, no * modifier keys / `target` / `download`) and route them instead of reloading. * Opt a single link out with `data-router-ignore` or `rel="external"`. Default * `true`; set `false` to wire navigation entirely yourself. */ interceptLinks?: boolean; } /** The handle {@link createRouter} returns. Holds no module-global state — it's a closure. */ interface RouterHandle { /** The reactive current route. Read `.value` (tracked) in a render / `computed` / `effect`. */ route: ReadonlySignal; /** Navigate to `path` (may include `?query` / `#hash`). Pushes history (or replaces, per options). */ navigate: (path: string, options?: NavigateOptions) => void; /** History back — `history.back()`. */ back: () => void; /** History forward — `history.forward()`. */ forward: () => void; /** * A reactive "is this path active?" — true when the current path equals * `pattern` or is nested under it (`match('/users')` is true on `/users/7`). * `match('/')` is exact (only true on `/`). Bind it for active-nav styling. */ match: (pattern: string) => ReadonlySignal; /** Convenience: a bound class signal — `className` while {@link match}`(pattern)` is active, else `''`. */ activeClass: (pattern: string, className: string) => ReadonlySignal; /** * The routed view. Call it inside a `mount()` render: it renders the matched * route's component in a keyed wrapper, so a route change swaps the page * wholesale (fresh DOM) while a param change updates it in place. */ outlet: () => MountResult; /** Tear down the popstate / link listeners. Idempotent. */ dispose: () => void; } /** * Create a router bound to the browser history. Reads the current location * immediately (so `route.value` is correct before first paint), installs a * `popstate` listener (+ `hashchange` in hash mode) and, unless disabled, a * single delegated link interceptor. See {@link RouterOptions} / {@link RouterHandle}. */ declare function createRouter(options: RouterOptions): RouterHandle; export { type NavigateOptions, type RouteComponent, type RouteDef, type RouteState, type RouterHandle, type RouterOptions, createRouter };