export { bindViewToUrl, type UrlViewBindingOptions } from './view-binding.svelte.js'; /** * How {@link useUrlArrayParam} maps an array onto the URL: * - `repeat` — one entry per key: `?tag=a&tag=b` * - `csv` — a single delimited value: `?tag=a,b` */ export type UrlArrayStrategy = 'repeat' | 'csv'; /** Codec + seed for {@link useUrlParam} / {@link createUrlParam}. */ export type UrlParamOptions = { /** * Read the value out of the current search params. Return `null`/`undefined` * to signal "absent" — the getter then yields {@link initial}. */ parse: (sp: URLSearchParams) => T | null | undefined; /** * Encode the value into `URLSearchParams`. The keys it produces are the ones * the setter manages: on write they are cleared from the current URL and * replaced by this output, leaving every other param untouched. Emit no * entry for a key to remove it from the URL. */ serialize: (value: T) => URLSearchParams; /** Value the getter returns when {@link parse} yields `null`/`undefined`. */ initial: T; /** * Replace the current history entry instead of pushing a new one, so rapid * filter/pagination edits don't flood the back button. * @default true */ replaceState?: boolean; }; /** * Low-level escape hatch to update several params at once via `goto` (without a * full navigation). Starts from the current URL, applies `next`, and keeps * every unrelated param. * * Merge semantics per key in `next`: the key is first cleared, then re-applied * — a `URLSearchParams` re-appends all of its entries (repeated keys survive), * a record `set`s a scalar, `append`s each array element, and **removes** the * key entirely for a `null`/`undefined` value. * * @param next - Params to apply, as `URLSearchParams` or a plain record. A * record value of `null`/`undefined` deletes that key. * @param opts - `replaceState` (default `true`) — replace vs. push history. * @example * ```typescript * updateUrlSearchParams({ page: '1', tag: ['a', 'b'], filter: null }); * // ?page=1&tag=a&tag=b (any prior `filter` param is dropped) * ``` */ export declare function updateUrlSearchParams(next: URLSearchParams | Record, opts?: { replaceState?: boolean; }): void; /** * Non-reactive core of {@link useUrlParam}: builds the `get(sp)` / `set(value)` * pair without touching the `page` rune, so `get` can be evaluated against any * `URLSearchParams`. Prefer {@link useUrlParam} in components — this is the * escape hatch when you need to read against a snapshot other than the live * page URL (tests, a server `load`). * * `set` rewrites only the keys that `options.serialize` produces (clear + * re-append) and preserves the rest, then navigates with `goto` * (`replaceState`, `noScroll`, `keepFocus`). * * @param _key - Ignored — `options.parse`/`options.serialize` already close * over the key (see {@link useUrlArrayParam}); kept only for signature parity * with {@link useUrlParam}. * @param options - Parse/serialize codec, initial value, history behaviour. * @returns `{ get, set }` — `get(sp)` reads a value from the given params * (falling back to `initial`), `set(value)` writes it to the URL. */ export declare function createUrlParam(_key: string, options: UrlParamOptions): { readonly get: (sp: URLSearchParams) => T; readonly set: (next: T) => void; }; /** * Bind a typed value to a URL search param, reactively. The returned getter * reads through the `page` rune, so it re-evaluates whenever the URL changes; * the setter writes the value back via `goto` (no full navigation). * * SSR-safe: the getter only reads `page.url` (populated on the server), so the * initial render reflects the incoming URL. The setter calls the client-only * `goto` and is meant to run from event handlers/effects — never during SSR. * * Prerender-safe: SvelteKit forbids reading `url.searchParams` while * prerendering (the emitted HTML must not depend on a query string that will * not exist at request time). During `building` the getter therefore yields * {@link UrlParamOptions.initial} — "absent" is the truth for that render; * after hydration the client re-reads the real URL reactively. * * A **getter**, not a store, is returned on purpose: call it lazily inside * `$derived`/`$effect` and the read is tracked there. * * @typeParam T - The decoded value type. * @param key - Param key (forwarded to `createUrlParam` for signature parity; * the actual key handling lives in `options.parse`/`options.serialize`). * @param options - Parse/serialize codec, initial value, history behaviour. * @returns `[get, set]` — `get()` reads the live value, `set(value)` writes it. * @example * ```svelte * * * * ``` */ export declare function useUrlParam(key: string, options: UrlParamOptions): readonly [() => T, (next: T) => void]; /** * {@link useUrlParam} specialised for a `string[]`, with the encoding handled * for you. Reactive read + `goto`-based write, same as {@link useUrlParam}. * * The `csv` strategy drops empty segments on read (`?tag=` → `[]`) and writes * no param for an empty array, so an empty selection leaves the URL clean. * * @param key - The param key. * @param opts - `initial` seed, `strategy` (default `'repeat'`), and * `delimiter` for `csv` (default `','`). See {@link UrlArrayStrategy}. * @returns `[get, set]` — `get()` reads the current `string[]`, `set(values)` * writes it. * @example * ```typescript * const [tags, setTags] = useUrlArrayParam('tag', { initial: [] }); // ?tag=a&tag=b * const [cats, setCats] = useUrlArrayParam('cat', { initial: [], strategy: 'csv' }); // ?cat=a,b * ``` */ export declare function useUrlArrayParam(key: string, opts: { initial: string[]; strategy?: UrlArrayStrategy; delimiter?: string; }): readonly [() => string[], (next: string[]) => void];