@diso.io/groutcho-core 0.0.0-stage → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @diso.io/groutcho-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Declarative, framework-agnostic router core: `URLPattern` matching, a redirect
4
+ engine with loop detection, and a pluggable history store. No DOM dependency in
5
+ the matching engine — only `createBrowserHistory` touches `window`.
6
+
7
+ ```bash
8
+ npm install @diso.io/groutcho-core
9
+ ```
10
+
11
+ ```ts
12
+ import { createRouter, createMemoryHistory } from '@diso.io/groutcho-core';
13
+
14
+ const store = createRouter({
15
+ routes: {
16
+ Home: { pattern: '/', page: 'Home' },
17
+ Show: { pattern: '/show/:title', page: 'Show' }
18
+ },
19
+ redirects: {
20
+ NotFound: (match) => (match ? false : 'NotFound')
21
+ }
22
+ // history: createMemoryHistory('/') // for SSR / tests / React Native
23
+ });
24
+
25
+ store.subscribe((match) => console.log(match.route?.name, match.params));
26
+ store.go('/show/hi');
27
+ ```
28
+
29
+ **Exports:** `createRouter`, `createBrowserHistory`, `createMemoryHistory`,
30
+ `Router`, `Route`, `MatchResult`, `logger`, and all types.
31
+
32
+ See the [groutcho family README](../README.md) for concepts and the hype, Lit and React
33
+ bindings.
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Route/query params. Values come from URLPattern matching (strings) or query
3
+ * string parsing (string, or string[] for repeated keys), and may be
4
+ * `undefined` for optional path params that weren't present in the URL.
5
+ */
6
+ type Params = Record<string, string | string[] | undefined>;
7
+ /**
8
+ * Opaque component reference. Core doesn't render anything — adapters (react,
9
+ * lit, etc.) interpret whatever the app stores under `page`, `layout`, and
10
+ * `errorPage`. Kept as `unknown` so core stays framework-agnostic.
11
+ */
12
+ type Component = unknown;
13
+ /**
14
+ * A route-defined title. Either a fixed string, or a function that derives one
15
+ * from the current match (e.g. `(m) => `Album: ${m.params.slug}``).
16
+ */
17
+ type TitleValue = string | ((match: MatchResult) => string);
18
+ /**
19
+ * Structured error surfaced through a match. Adapters populate this when a page
20
+ * render throws (see react/lit `<Outlet>` equivalents). `useError` / `onError`
21
+ * read it.
22
+ */
23
+ interface RouteError {
24
+ message: string;
25
+ cause?: unknown;
26
+ status?: number;
27
+ }
28
+ /** A route reference by name, optionally with params. */
29
+ interface RouteInput {
30
+ name: string;
31
+ params?: Params;
32
+ }
33
+ /**
34
+ * The object form of router input. Either a `url`, a `route` reference, or a
35
+ * name shorthand — plus any arbitrary "extra" keys that redirect logic can read
36
+ * (these are threaded through redirects but ignored by matching).
37
+ */
38
+ interface InputObject {
39
+ url?: string;
40
+ route?: RouteInput;
41
+ name?: string;
42
+ params?: Params;
43
+ [key: string]: unknown;
44
+ }
45
+ /** Anything accepted by `Router.match`/`go`: a string or an input object. */
46
+ type Input = string | InputObject;
47
+ /**
48
+ * What a redirect returns: a new input to follow, or a falsy value meaning
49
+ * "no redirect".
50
+ */
51
+ type RedirectResult = Input | false | null | undefined;
52
+ /** Per-route redirect: receives the current match, returns where to go (or false). */
53
+ type RouteRedirect = (match: MatchResult) => RedirectResult;
54
+ /**
55
+ * Global redirect test: receives the current match (or `false` when nothing
56
+ * matched, e.g. for a NotFound rule), returns where to go (or false).
57
+ */
58
+ type RedirectTest = (match: MatchResult | false) => RedirectResult;
59
+ interface RouteConfig {
60
+ /** Set automatically from the routes map key; may be provided directly too. */
61
+ name?: string;
62
+ /** URLPattern pathname pattern, e.g. `/show/:title` or `/optional/:opt?`. */
63
+ pattern: string;
64
+ /** Arbitrary payload associated with the route (component, handler, etc). */
65
+ page: Component;
66
+ /** Optional per-route redirect. */
67
+ redirect?: RouteRedirect;
68
+ /**
69
+ * Route title. String or `(match) => string`. When the router navigates to
70
+ * this route the store applies it via `setTitle`; adapters mirror it to
71
+ * `document.title`. Runtime overrides via `store.setTitle` (see React
72
+ * `useTitle`) win until the next navigation.
73
+ */
74
+ title?: TitleValue;
75
+ /**
76
+ * Layout component (or ordered chain, outermost first) wrapping `page`.
77
+ * Adapters render `layouts.reduceRight((child, L) => <L>{child}</L>, page)`.
78
+ * Sibling routes sharing the same layout component identity get instance
79
+ * persistence via the adapter's reconciliation.
80
+ */
81
+ layout?: Component;
82
+ /** Per-route error UI. Adapters render this when the page render throws. */
83
+ errorPage?: Component;
84
+ /** Arbitrary route metadata (e.g. `session`, `role`) readable by redirects. */
85
+ [key: string]: unknown;
86
+ }
87
+ interface RouterConfig {
88
+ routes: Record<string, RouteConfig>;
89
+ redirects?: Record<string, RedirectTest>;
90
+ max_redirects?: number;
91
+ /** Fallback error UI. Adapters use this when a route has no `errorPage`. */
92
+ errorPage?: Component;
93
+ }
94
+ export declare class Route {
95
+ #private;
96
+ name: string;
97
+ pattern: string;
98
+ page: unknown;
99
+ redirect?: RouteRedirect;
100
+ [key: string]: unknown;
101
+ constructor(config: RouteConfig);
102
+ /** Match against a url input or a route input. */
103
+ match(input: InputObject): MatchResult | false;
104
+ /**
105
+ * Test whether this route matches. A `/`-containing string is matched against
106
+ * the pattern; otherwise it's compared to the route name.
107
+ */
108
+ is(test: string): boolean;
109
+ /** Build a URL for this route from the given params. */
110
+ href(params?: Params): string;
111
+ }
112
+ interface MatchResultInit {
113
+ input: InputObject;
114
+ route?: Route | null;
115
+ url?: string | null;
116
+ params?: Params;
117
+ redirect?: boolean;
118
+ }
119
+ /**
120
+ * The result of a match: which route (if any) matched, the resolved params and
121
+ * url, whether it represents a redirect, and — for redirects — the `original`
122
+ * match that triggered it.
123
+ *
124
+ * `key` is populated by the store and increments on each successful navigation;
125
+ * it's useful as an effect-dependency when you want to run something on every
126
+ * nav even if the URL/params look the same.
127
+ *
128
+ * `error` is populated by adapters when a page render throws.
129
+ */
130
+ export declare class MatchResult {
131
+ input: InputObject;
132
+ route: Route | null;
133
+ params: Params;
134
+ redirect: boolean;
135
+ original: MatchResult | null;
136
+ url: string;
137
+ key: number;
138
+ error: RouteError | undefined;
139
+ constructor({ input, route, url, params, redirect }: MatchResultInit);
140
+ /** Mark this result as a redirect, recording the original match it came from. */
141
+ isRedirect({ original }: {
142
+ original: MatchResult | false;
143
+ }): void;
144
+ }
145
+ interface RedirectEntry {
146
+ name: string;
147
+ test: RedirectTest;
148
+ }
149
+ export declare class Router {
150
+ #private;
151
+ routes: Route[];
152
+ redirects: RedirectEntry[];
153
+ max_redirects: number;
154
+ constructor({ routes, redirects, max_redirects }: RouterConfig);
155
+ addRoutes(routes: Record<string, RouteConfig>): void;
156
+ /** Lookup a route by name. Throws if none is registered under that name. */
157
+ get(name: string): Route;
158
+ /** Find a route by arbitrary field equality. Returns undefined when none match. */
159
+ find(query: Record<string, unknown>): Route | undefined;
160
+ /**
161
+ * Match input against the routes, following any redirects.
162
+ * Returns the resolved (possibly redirect) MatchResult.
163
+ */
164
+ match(input: Input): MatchResult;
165
+ normalizeInput(input: Input): InputObject;
166
+ /**
167
+ * Resolve an input. Kept as an alias for {@link match} so `Router` can be used
168
+ * directly in tests without going through a store. The store's `go` (in
169
+ * history.ts) is what apps use — it updates history and notifies listeners.
170
+ */
171
+ go(input: Input): MatchResult;
172
+ }
173
+ /**
174
+ * Pluggable history/location seam. The core never touches `window` directly —
175
+ * only `createBrowserHistory` does — so the matching engine and store run in any
176
+ * JS runtime (browser, Node, workers, React Native) with an appropriate history.
177
+ */
178
+ interface History {
179
+ /** Current location as a root-relative url (pathname + search + hash). */
180
+ location(): string;
181
+ /** Navigate, pushing a new entry. */
182
+ push(url: string): void;
183
+ /** Navigate, replacing the current entry (used for redirects). */
184
+ replace(url: string): void;
185
+ /** Go back one entry in the history stack. */
186
+ back(): void;
187
+ /** Go forward one entry in the history stack. */
188
+ forward(): void;
189
+ /** Subscribe to external location changes (e.g. back/forward). Returns an unsubscribe. */
190
+ subscribe(listener: () => void): () => void;
191
+ }
192
+ /** Browser history backed by `window.location` + `popstate`. */
193
+ export declare function createBrowserHistory(): History;
194
+ /** In-memory history for SSR, tests, and non-DOM runtimes. */
195
+ export declare function createMemoryHistory(initial?: string): History;
196
+ interface RouterStoreConfig extends RouterConfig {
197
+ /** History implementation. Defaults to browser when a DOM is present, else memory. */
198
+ history?: History;
199
+ }
200
+ /** Snapshot listener (React's `useSyncExternalStore` shape). Fires with the new match. */
201
+ type StoreListener = (match: MatchResult) => void;
202
+ /** Fires on each successful nav with both the previous and the new match. */
203
+ type GoListener = (prev: MatchResult, current: MatchResult) => void;
204
+ /** Fires when the title changes (from a nav or an explicit `setTitle`). */
205
+ type TitleListener = (title: string) => void;
206
+ /** Fires when an error is set on the current match (typically from an adapter). */
207
+ type ErrorListener = (error: RouteError | undefined) => void;
208
+ /**
209
+ * A framework-agnostic router store: wraps a `Router` + a `History`, keeps a
210
+ * current snapshot in sync with the location, and exposes subscribe/getSnapshot
211
+ * for React `useSyncExternalStore` plus richer channels (`onGo`, `onTitle`,
212
+ * `onError`) that adapters wire to effects.
213
+ *
214
+ * Naming: the router action is `go` everywhere. Subscriptions to that action
215
+ * are `onGo`. Never `navigate`.
216
+ */
217
+ interface GoOptions {
218
+ /** Replace the current history entry instead of pushing a new one. */
219
+ replace?: boolean;
220
+ }
221
+ interface RouterStore {
222
+ readonly router: Router;
223
+ readonly history: History;
224
+ /** Fallback error UI (from config). Adapters use this when a route has no `errorPage`. */
225
+ readonly errorPage: Component;
226
+ /** Match without navigating. */
227
+ match(input: Input): MatchResult;
228
+ /**
229
+ * Navigate to input, updating history and notifying subscribers. Pass
230
+ * `{ replace: true }` to overwrite the current history entry (useful for
231
+ * search-param edits that shouldn't add a back button entry).
232
+ */
233
+ go(input: Input, options?: GoOptions): MatchResult;
234
+ /** Shortcut for `router.get(name)` — look up a route by name. */
235
+ get(name: string): Route;
236
+ /** Current resolved match for the location. */
237
+ getSnapshot: () => MatchResult;
238
+ /** Subscribe to snapshot changes. Returns an unsubscribe. */
239
+ subscribe: (listener: StoreListener) => () => void;
240
+ /**
241
+ * Subscribe to nav events. Fires with `(prev, current)` after each
242
+ * successful navigation. Returns an unsubscribe.
243
+ */
244
+ onGo(listener: GoListener): () => void;
245
+ /** Current title string. Recomputed from `match.route.title` on each nav. */
246
+ readonly title: string;
247
+ /** Set the title (fires `onTitle`; overrides route title until next nav). */
248
+ setTitle(title: string): void;
249
+ onTitle(listener: TitleListener): () => void;
250
+ /** Set an error on the current match (fires `onError`). Called by adapters. */
251
+ setError(error: RouteError | undefined): void;
252
+ onError(listener: ErrorListener): () => void;
253
+ /** Detach from history and drop all subscribers. */
254
+ destroy(): void;
255
+ }
256
+ export declare function createRouter(config: RouterStoreConfig): RouterStore;
257
+ export declare const logger: {
258
+ enable(on?: boolean): void;
259
+ readonly enabled: boolean;
260
+ debug(...args: unknown[]): void;
261
+ info(...args: unknown[]): void;
262
+ warn(...args: unknown[]): void;
263
+ error(...args: unknown[]): void;
264
+ };
265
+ export type { Component, ErrorListener, GoListener, GoOptions, History, Input, InputObject, MatchResultInit, Params, RedirectResult, RedirectTest, RouteConfig, RouteError, RouteInput, RouteRedirect, RouterConfig, RouterStore, RouterStoreConfig, StoreListener, TitleListener, TitleValue };
266
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/Route.ts","../src/MatchResult.ts","../src/Router.ts","../src/history.ts","../src/logger.ts"],"mappings":";;;;;KAOY,SAAS;;;;;;KAOT;;;;;KAMA,wBAAwB,OAAO;;;;;;UAO1B;EAChB;EACA;EACA;;;UAIgB;EAChB;EACA,SAAS;;;;;;;UAQO;EAChB;EACA,QAAQ;EACR;EACA,SAAS;GACR;;;KAIU,iBAAiB;;;;;KAMjB,iBAAiB;;KAGjB,iBAAiB,OAAO,gBAAgB;;;;;KAMxC,gBAAgB,OAAO,wBAAwB;UAE1C;;EAEhB;;EAEA;;EAEA,MAAM;;EAEN,WAAW;;;;;;;EAOX,QAAQ;;;;;;;EAOR,SAAS;;EAET,YAAY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;wBASe,aAAa,QAAQ,oBAAoB;qBCnL5C;EACZ,OAAM;WAGF;EAGJ,SAAK;EAGL,QAAI;EAGJ,QAAI;EAGJ,SAAK"}
package/dist/index.js ADDED
@@ -0,0 +1,645 @@
1
+ import { URLPattern } from "urlpattern-polyfill";
2
+ // src/logger.ts
3
+ let enabled = false;
4
+ try {
5
+ const debug = typeof process !== "undefined" ? process.env?.DEBUG : void 0;
6
+ enabled = !!debug && /(^|,|\s)groutcho(,|\s|$|:|\*)/.test(debug);
7
+ } catch {
8
+ enabled = false;
9
+ }
10
+ const logger = {
11
+ enable(on = true) {
12
+ enabled = on;
13
+ },
14
+ get enabled() {
15
+ return enabled;
16
+ },
17
+ debug(...args) {
18
+ if (enabled) console.debug("[groutcho]", ...args);
19
+ },
20
+ info(...args) {
21
+ if (enabled) console.info("[groutcho]", ...args);
22
+ },
23
+ warn(...args) {
24
+ if (enabled) console.warn("[groutcho]", ...args);
25
+ },
26
+ error(...args) {
27
+ if (enabled) console.error("[groutcho]", ...args);
28
+ }
29
+ };
30
+ // src/MatchResult.ts
31
+ /**
32
+ * The result of a match: which route (if any) matched, the resolved params and
33
+ * url, whether it represents a redirect, and — for redirects — the `original`
34
+ * match that triggered it.
35
+ *
36
+ * `key` is populated by the store and increments on each successful navigation;
37
+ * it's useful as an effect-dependency when you want to run something on every
38
+ * nav even if the URL/params look the same.
39
+ *
40
+ * `error` is populated by adapters when a page render throws.
41
+ */
42
+ var MatchResult = class {
43
+ input;
44
+ route;
45
+ params;
46
+ redirect;
47
+ original;
48
+ url;
49
+ key;
50
+ error;
51
+ constructor({ input, route = null, url = null, params = {}, redirect = false }) {
52
+ this.input = input;
53
+ this.route = route;
54
+ this.params = params;
55
+ this.redirect = redirect;
56
+ this.original = null;
57
+ this.key = 0;
58
+ this.error = void 0;
59
+ if (url != null) this.url = url;
60
+ else if (route) this.url = route.href(params);
61
+ else throw new Error("MatchResult requires either a url or a route");
62
+ }
63
+ /** Mark this result as a redirect, recording the original match it came from. */
64
+ isRedirect({ original }) {
65
+ this.redirect = true;
66
+ this.original = original || null;
67
+ }
68
+ };
69
+ // src/pattern.ts
70
+ const URLPatternImpl = globalThis.URLPattern ?? URLPattern;
71
+ const IDENT = "[A-Za-z_$][A-Za-z0-9_$]*";
72
+ const TOKEN = new RegExp(`:(${IDENT})([?+*])?`, "g");
73
+ const SLASH_TOKEN = new RegExp(`/:(${IDENT})([?*])`, "g");
74
+ /** The companion array-accessor key for a repeat param (`path` -> `pathArray`). */
75
+ function arrayKey(name) {
76
+ return `${name}Array`;
77
+ }
78
+ function makeMatcher(pattern) {
79
+ return new URLPatternImpl({ pathname: pattern });
80
+ }
81
+ /** Test whether a pathname matches the matcher. */
82
+ function testPath(matcher, pathname) {
83
+ return matcher.test({ pathname });
84
+ }
85
+ /** Exec a pathname against the matcher, returning its named groups or null. */
86
+ function matchPath(matcher, pathname) {
87
+ const result = matcher.exec({ pathname });
88
+ return result ? result.pathname.groups : null;
89
+ }
90
+ /** Parse the named params declared by a pattern, in order. */
91
+ function patternParamNames(pattern) {
92
+ const keys = [];
93
+ for (const match of pattern.matchAll(TOKEN)) {
94
+ const modifier = match[2];
95
+ keys.push({
96
+ name: match[1] ?? "",
97
+ optional: modifier === "?" || modifier === "*",
98
+ repeat: modifier === "+" || modifier === "*"
99
+ });
100
+ }
101
+ return keys;
102
+ }
103
+ function isEmpty(value) {
104
+ return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
105
+ }
106
+ /** Encode a single path segment. */
107
+ function encodeSingle(value) {
108
+ return encodeURIComponent(String(value));
109
+ }
110
+ /**
111
+ * Encode a value into a path fragment. Repeat params accept an array of segments
112
+ * or a pre-joined `a/b/c` string; either way each segment is encoded and joined
113
+ * with `/`.
114
+ */
115
+ function encodeValue(value, repeat) {
116
+ if (!repeat) return encodeSingle(value);
117
+ return (Array.isArray(value) ? value : String(value).split("/")).map(encodeSingle).join("/");
118
+ }
119
+ /**
120
+ * Reverse-router: build a concrete path from a pattern + params. URLPattern can
121
+ * match but not build, so we compile `:name` tokens ourselves. Optional/repeat
122
+ * tokens (with their leading slash) are dropped when the param is absent.
123
+ * Repeat params read either `name` or its `nameArray` companion.
124
+ */
125
+ function compilePath(pattern, params) {
126
+ const consumed = /* @__PURE__ */ new Set();
127
+ function take(name, repeat) {
128
+ consumed.add(name);
129
+ if (repeat) {
130
+ consumed.add(arrayKey(name));
131
+ return params[name] !== void 0 ? params[name] : params[arrayKey(name)];
132
+ }
133
+ return params[name];
134
+ }
135
+ let path = pattern.replace(SLASH_TOKEN, (_all, name, modifier) => {
136
+ const repeat = modifier === "*";
137
+ const value = take(name, repeat);
138
+ if (isEmpty(value)) return "";
139
+ return `/${encodeValue(value, repeat)}`;
140
+ });
141
+ path = path.replace(TOKEN, (_all, name, modifier) => {
142
+ const repeat = modifier === "+";
143
+ const value = take(name, repeat);
144
+ if (isEmpty(value)) {
145
+ if (modifier === "?" || modifier === "*") return "";
146
+ throw new Error(`Missing required param "${name}" for pattern "${pattern}"`);
147
+ }
148
+ return encodeValue(value, repeat);
149
+ });
150
+ return {
151
+ path,
152
+ consumed
153
+ };
154
+ }
155
+ // src/Route.ts
156
+ const REQUIRED_PARAMS = [
157
+ "name",
158
+ "pattern",
159
+ "page"
160
+ ];
161
+ const RESERVED_PARAMS = [
162
+ "is",
163
+ "match",
164
+ "href"
165
+ ];
166
+ /** Convert a URLSearchParams into params, arraying repeated keys. */
167
+ function searchToParams(search) {
168
+ const params = {};
169
+ for (const key of new Set(search.keys())) {
170
+ const all = search.getAll(key);
171
+ params[key] = all.length > 1 ? all : all[0];
172
+ }
173
+ return params;
174
+ }
175
+ var Route = class {
176
+ name;
177
+ pattern;
178
+ page;
179
+ redirect;
180
+ #matcher;
181
+ #paramKeys;
182
+ constructor(config) {
183
+ for (const param of REQUIRED_PARAMS) if (!(param in config)) throw new Error(`Missing route param ${param}`);
184
+ for (const [key, value] of Object.entries(config)) {
185
+ if (RESERVED_PARAMS.includes(key)) throw new Error(`Invalid route param ${key}`);
186
+ this[key] = value;
187
+ }
188
+ this.#matcher = makeMatcher(this.pattern);
189
+ this.#paramKeys = patternParamNames(this.pattern);
190
+ }
191
+ /** Match against a url input or a route input. */
192
+ match(input) {
193
+ return input.url ? this.#matchUrl(input) : this.#matchRoute(input);
194
+ }
195
+ /**
196
+ * Test whether this route matches. A `/`-containing string is matched against
197
+ * the pattern; otherwise it's compared to the route name.
198
+ */
199
+ is(test) {
200
+ if (test.indexOf("/") !== -1) return testPath(this.#matcher, new URL(test, "http://x/").pathname);
201
+ return this.name === test;
202
+ }
203
+ /** Build a URL for this route from the given params. */
204
+ href(params = {}) {
205
+ const { path, consumed } = compilePath(this.pattern, params);
206
+ const query = new URLSearchParams();
207
+ for (const [key, value] of Object.entries(params)) {
208
+ if (consumed.has(key) || value === void 0 || value === null) continue;
209
+ if (Array.isArray(value)) for (const item of value) query.append(key, String(item));
210
+ else query.append(key, String(value));
211
+ }
212
+ const qs = query.toString();
213
+ return qs ? `${path}?${qs}` : path;
214
+ }
215
+ #matchUrl(input) {
216
+ const url = input.url;
217
+ const parsed = new URL(url, "http://x/");
218
+ const groups = matchPath(this.#matcher, parsed.pathname);
219
+ if (!groups) return false;
220
+ const routeParams = this.#groupParams(groups);
221
+ const queryParams = searchToParams(parsed.searchParams);
222
+ const params = {
223
+ ...routeParams,
224
+ ...queryParams
225
+ };
226
+ return new MatchResult({
227
+ route: this,
228
+ input,
229
+ params
230
+ });
231
+ }
232
+ #matchRoute(input) {
233
+ const route = input.route;
234
+ if (!route || route.name !== this.name) return false;
235
+ const params = route.params ?? {};
236
+ if (!this.#paramKeys.filter((key) => !key.optional).every((key) => key.name in params || key.repeat && arrayKey(key.name) in params)) return false;
237
+ return new MatchResult({
238
+ route: this,
239
+ input,
240
+ params
241
+ });
242
+ }
243
+ #groupParams(groups) {
244
+ const params = {};
245
+ for (const { name, optional, repeat } of this.#paramKeys) {
246
+ const raw = groups[name];
247
+ const defined = raw !== void 0 && raw !== "";
248
+ if (repeat) {
249
+ if (defined) {
250
+ const segments = raw.split("/").map((segment) => decodeURIComponent(segment));
251
+ params[name] = segments.join("/");
252
+ params[arrayKey(name)] = segments;
253
+ } else if (!optional) {
254
+ params[name] = raw;
255
+ params[arrayKey(name)] = [];
256
+ }
257
+ } else if (defined) params[name] = decodeURIComponent(raw);
258
+ else if (!optional) params[name] = raw;
259
+ }
260
+ return params;
261
+ }
262
+ };
263
+ // src/Router.ts
264
+ function omit(obj, keys) {
265
+ const out = {};
266
+ for (const [key, value] of Object.entries(obj)) if (!keys.includes(key)) out[key] = value;
267
+ return out;
268
+ }
269
+ var Router = class {
270
+ routes = [];
271
+ redirects = [];
272
+ max_redirects;
273
+ constructor({ routes, redirects = {}, max_redirects = 10 }) {
274
+ this.max_redirects = max_redirects;
275
+ this.addRoutes(routes);
276
+ for (const [name, test] of Object.entries(redirects)) this.redirects.push({
277
+ name,
278
+ test
279
+ });
280
+ logger.debug("Constructed router", this);
281
+ }
282
+ addRoutes(routes) {
283
+ for (const [name, config] of Object.entries(routes)) {
284
+ config.name = name;
285
+ const route = new Route(config);
286
+ logger.debug("Adding route", route);
287
+ this.routes.push(route);
288
+ }
289
+ }
290
+ /** Lookup a route by name. Throws if none is registered under that name. */
291
+ get(name) {
292
+ const route = this.find({ name });
293
+ if (!route) {
294
+ const msg = `No route named ${name}`;
295
+ logger.error(msg);
296
+ throw new Error(msg);
297
+ }
298
+ return route;
299
+ }
300
+ /** Find a route by arbitrary field equality. Returns undefined when none match. */
301
+ find(query) {
302
+ return this.routes.find((route) => Object.entries(query).every(([key, value]) => route[key] === value));
303
+ }
304
+ /**
305
+ * Match input against the routes, following any redirects.
306
+ * Returns the resolved (possibly redirect) MatchResult.
307
+ */
308
+ match(input) {
309
+ const normalized = this.normalizeInput(input);
310
+ const extra = omit(normalized, ["route", "url"]);
311
+ const original = this.#match(normalized);
312
+ const redirect = this.#checkRedirects({
313
+ original,
314
+ extra
315
+ });
316
+ logger.debug("match", {
317
+ input: normalized,
318
+ original,
319
+ redirect
320
+ });
321
+ if (redirect) {
322
+ redirect.isRedirect({ original });
323
+ return redirect;
324
+ }
325
+ return original;
326
+ }
327
+ normalizeInput(input) {
328
+ if (typeof input === "string") {
329
+ if (input.indexOf("/") !== -1) return { url: input };
330
+ return { route: { name: input } };
331
+ }
332
+ if (input !== null && typeof input === "object") {
333
+ if (input.name) return { route: input };
334
+ return input;
335
+ }
336
+ const error = /* @__PURE__ */ new Error("Invalid input");
337
+ error.input = input;
338
+ throw error;
339
+ }
340
+ /**
341
+ * Resolve an input. Kept as an alias for {@link match} so `Router` can be used
342
+ * directly in tests without going through a store. The store's `go` (in
343
+ * history.ts) is what apps use — it updates history and notifies listeners.
344
+ */
345
+ go(input) {
346
+ return this.match(input);
347
+ }
348
+ #match(input) {
349
+ logger.debug("Attempting to match route", input);
350
+ const { url } = input;
351
+ if (url && /^https?:\/\//.test(url)) return new MatchResult({
352
+ redirect: true,
353
+ input,
354
+ url
355
+ });
356
+ let match = false;
357
+ for (const route of this.routes) {
358
+ match = route.match(input);
359
+ if (match) break;
360
+ }
361
+ return match;
362
+ }
363
+ #checkRedirects(args) {
364
+ const { original, extra } = args;
365
+ let { previous = null, current = null, num_redirects = 0, history = [] } = args;
366
+ logger.debug("Checking redirects", {
367
+ original,
368
+ extra,
369
+ previous,
370
+ current,
371
+ num_redirects,
372
+ history
373
+ });
374
+ const { max_redirects } = this;
375
+ if (num_redirects >= max_redirects) {
376
+ const msg = `Number of redirects exceeded max_redirects (${max_redirects})`;
377
+ logger.error(msg);
378
+ throw new Error(msg);
379
+ }
380
+ const deepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
381
+ if (current && previous) {
382
+ const sameRoute = current.route === previous.route;
383
+ const sameParams = deepEqual(current.params, previous.params);
384
+ if (sameRoute && sameParams) {
385
+ logger.debug("Route is same as previous", {
386
+ current,
387
+ previous
388
+ });
389
+ return previous;
390
+ }
391
+ }
392
+ if (!current) {
393
+ current = original;
394
+ history = [original];
395
+ }
396
+ const matched = current === false ? null : current;
397
+ if (matched?.redirect) return matched;
398
+ let next = false;
399
+ if (matched?.route?.redirect) next = matched.route.redirect(matched);
400
+ if (!next) for (const { test } of this.redirects) {
401
+ next = test(current);
402
+ if (next) break;
403
+ }
404
+ if (next) {
405
+ logger.debug("Got redirect", {
406
+ current,
407
+ next
408
+ });
409
+ previous = current;
410
+ const normalizedNext = this.normalizeInput(next);
411
+ current = this.#match({
412
+ ...normalizedNext,
413
+ ...extra
414
+ });
415
+ if (!current) {
416
+ const error = /* @__PURE__ */ new Error("No match for redirect result");
417
+ error.redirect = normalizedNext;
418
+ throw error;
419
+ }
420
+ history.push(current);
421
+ num_redirects++;
422
+ return this.#checkRedirects({
423
+ original,
424
+ previous,
425
+ current,
426
+ num_redirects,
427
+ history,
428
+ extra
429
+ });
430
+ }
431
+ if (num_redirects > 0) return current;
432
+ return false;
433
+ }
434
+ };
435
+ // src/history.ts
436
+ function isExternal(url) {
437
+ return /^[a-z][a-z0-9+.-]*:\/\//i.test(url);
438
+ }
439
+ /** Browser history backed by `window.location` + `popstate`. */
440
+ function createBrowserHistory() {
441
+ const listeners = /* @__PURE__ */ new Set();
442
+ const notify = () => {
443
+ for (const listener of listeners) listener();
444
+ };
445
+ return {
446
+ location() {
447
+ const { pathname, search, hash } = window.location;
448
+ return `${pathname}${search}${hash}`;
449
+ },
450
+ push(url) {
451
+ window.history.pushState({}, "", url);
452
+ notify();
453
+ },
454
+ replace(url) {
455
+ window.history.replaceState({}, "", url);
456
+ },
457
+ back() {
458
+ window.history.back();
459
+ },
460
+ forward() {
461
+ window.history.forward();
462
+ },
463
+ subscribe(listener) {
464
+ if (listeners.size === 0) window.addEventListener("popstate", notify);
465
+ listeners.add(listener);
466
+ return () => {
467
+ listeners.delete(listener);
468
+ if (listeners.size === 0) window.removeEventListener("popstate", notify);
469
+ };
470
+ }
471
+ };
472
+ }
473
+ /** In-memory history for SSR, tests, and non-DOM runtimes. */
474
+ function createMemoryHistory(initial = "/") {
475
+ const stack = [initial];
476
+ let index = 0;
477
+ const listeners = /* @__PURE__ */ new Set();
478
+ const emit = () => {
479
+ for (const listener of listeners) listener();
480
+ };
481
+ return {
482
+ location() {
483
+ return stack[index] ?? "/";
484
+ },
485
+ push(url) {
486
+ stack.length = index + 1;
487
+ stack.push(url);
488
+ index += 1;
489
+ emit();
490
+ },
491
+ replace(url) {
492
+ stack[index] = url;
493
+ },
494
+ back() {
495
+ if (index > 0) {
496
+ index -= 1;
497
+ emit();
498
+ }
499
+ },
500
+ forward() {
501
+ if (index < stack.length - 1) {
502
+ index += 1;
503
+ emit();
504
+ }
505
+ },
506
+ subscribe(listener) {
507
+ listeners.add(listener);
508
+ return () => {
509
+ listeners.delete(listener);
510
+ };
511
+ }
512
+ };
513
+ }
514
+ function defaultHistory() {
515
+ return typeof window !== "undefined" && !!window.history && !!window.location ? createBrowserHistory() : createMemoryHistory();
516
+ }
517
+ function resolveTitle(match) {
518
+ const raw = match.route?.title;
519
+ if (raw === void 0) return "";
520
+ return typeof raw === "function" ? raw(match) : raw;
521
+ }
522
+ function createRouter(config) {
523
+ const { history = defaultHistory(), errorPage, ...routerConfig } = config;
524
+ const router = new Router(routerConfig);
525
+ const snapshotListeners = /* @__PURE__ */ new Set();
526
+ const goListeners = /* @__PURE__ */ new Set();
527
+ const titleListeners = /* @__PURE__ */ new Set();
528
+ const errorListeners = /* @__PURE__ */ new Set();
529
+ let keySeq = 0;
530
+ function stamp(match) {
531
+ keySeq += 1;
532
+ match.key = keySeq;
533
+ return match;
534
+ }
535
+ function resolve(url) {
536
+ const match = router.match({ url });
537
+ if (match?.redirect && match.url && !isExternal(match.url) && match.url !== url) history.replace(match.url);
538
+ return stamp(match);
539
+ }
540
+ let snapshot = resolve(history.location());
541
+ let title = resolveTitle(snapshot);
542
+ function emitSnapshot(prev) {
543
+ for (const listener of snapshotListeners) listener(snapshot);
544
+ for (const listener of goListeners) listener(prev, snapshot);
545
+ }
546
+ function emitTitle() {
547
+ for (const listener of titleListeners) listener(title);
548
+ }
549
+ function emitError() {
550
+ for (const listener of errorListeners) listener(snapshot.error);
551
+ }
552
+ function applyRouteTitle() {
553
+ const next = resolveTitle(snapshot);
554
+ if (next !== title) {
555
+ title = next;
556
+ emitTitle();
557
+ }
558
+ }
559
+ function refresh() {
560
+ const prev = snapshot;
561
+ snapshot = resolve(history.location());
562
+ applyRouteTitle();
563
+ emitSnapshot(prev);
564
+ }
565
+ const unsubscribeHistory = history.subscribe(refresh);
566
+ return {
567
+ router,
568
+ history,
569
+ errorPage,
570
+ match: (input) => router.match(input),
571
+ go(input, options) {
572
+ const prev = snapshot;
573
+ const match = router.go(input);
574
+ if (match.url && !isExternal(match.url)) {
575
+ if (options?.replace) {
576
+ history.replace(match.url);
577
+ snapshot = stamp(match);
578
+ applyRouteTitle();
579
+ emitSnapshot(prev);
580
+ return snapshot;
581
+ }
582
+ history.push(match.url);
583
+ return snapshot;
584
+ }
585
+ if (match.url) {
586
+ snapshot = stamp(match);
587
+ applyRouteTitle();
588
+ emitSnapshot(prev);
589
+ }
590
+ return match;
591
+ },
592
+ get: (name) => router.get(name),
593
+ getSnapshot: () => snapshot,
594
+ subscribe(listener) {
595
+ snapshotListeners.add(listener);
596
+ return () => {
597
+ snapshotListeners.delete(listener);
598
+ };
599
+ },
600
+ onGo(listener) {
601
+ goListeners.add(listener);
602
+ return () => {
603
+ goListeners.delete(listener);
604
+ };
605
+ },
606
+ get title() {
607
+ return title;
608
+ },
609
+ setTitle(next) {
610
+ if (next !== title) {
611
+ title = next;
612
+ emitTitle();
613
+ }
614
+ },
615
+ onTitle(listener) {
616
+ titleListeners.add(listener);
617
+ return () => {
618
+ titleListeners.delete(listener);
619
+ };
620
+ },
621
+ setError(next) {
622
+ if (next !== snapshot.error) {
623
+ snapshot = Object.assign(Object.create(Object.getPrototypeOf(snapshot)), snapshot, { error: next });
624
+ emitError();
625
+ for (const listener of snapshotListeners) listener(snapshot);
626
+ }
627
+ },
628
+ onError(listener) {
629
+ errorListeners.add(listener);
630
+ return () => {
631
+ errorListeners.delete(listener);
632
+ };
633
+ },
634
+ destroy() {
635
+ unsubscribeHistory();
636
+ snapshotListeners.clear();
637
+ goListeners.clear();
638
+ titleListeners.clear();
639
+ errorListeners.clear();
640
+ }
641
+ };
642
+ }
643
+ export { MatchResult, Route, Router, createBrowserHistory, createMemoryHistory, createRouter, logger };
644
+
645
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["URLPatternPolyfill"],"sources":["../src/logger.ts","../src/MatchResult.ts","../src/pattern.ts","../src/Route.ts","../src/Router.ts","../src/history.ts"],"sourcesContent":["// Tiny zero-dependency debug logger. Silent by default; enable with\n// `logger.enable()` or by setting DEBUG=groutcho in a Node environment.\n\n// Ambient declaration so TS doesn't require @types/node in this framework-\n// agnostic package. The runtime `typeof` guard is what keeps this safe.\ndeclare const process: { env?: Record<string, string | undefined> } | undefined;\n\nlet enabled = false;\ntry {\n\tconst debug = typeof process !== \"undefined\" ? process.env?.DEBUG : undefined;\n\tenabled = !!debug && /(^|,|\\s)groutcho(,|\\s|$|:|\\*)/.test(debug);\n} catch {\n\tenabled = false;\n}\n\nexport const logger = {\n\tenable(on = true): void {\n\t\tenabled = on;\n\t},\n\tget enabled(): boolean {\n\t\treturn enabled;\n\t},\n\tdebug(...args: unknown[]): void {\n\t\tif (enabled) console.debug(\"[groutcho]\", ...args);\n\t},\n\tinfo(...args: unknown[]): void {\n\t\tif (enabled) console.info(\"[groutcho]\", ...args);\n\t},\n\twarn(...args: unknown[]): void {\n\t\tif (enabled) console.warn(\"[groutcho]\", ...args);\n\t},\n\terror(...args: unknown[]): void {\n\t\tif (enabled) console.error(\"[groutcho]\", ...args);\n\t},\n};\n\nexport default logger;\n","import type { Route } from \"./Route\";\nimport type { InputObject, Params, RouteError } from \"./types\";\n\nexport interface MatchResultInit {\n\tinput: InputObject;\n\troute?: Route | null;\n\turl?: string | null;\n\tparams?: Params;\n\tredirect?: boolean;\n}\n\n/**\n * The result of a match: which route (if any) matched, the resolved params and\n * url, whether it represents a redirect, and — for redirects — the `original`\n * match that triggered it.\n *\n * `key` is populated by the store and increments on each successful navigation;\n * it's useful as an effect-dependency when you want to run something on every\n * nav even if the URL/params look the same.\n *\n * `error` is populated by adapters when a page render throws.\n */\nexport class MatchResult {\n\tinput: InputObject;\n\troute: Route | null;\n\tparams: Params;\n\tredirect: boolean;\n\toriginal: MatchResult | null;\n\turl: string;\n\tkey: number;\n\terror: RouteError | undefined;\n\n\tconstructor({\n\t\tinput,\n\t\troute = null,\n\t\turl = null,\n\t\tparams = {},\n\t\tredirect = false,\n\t}: MatchResultInit) {\n\t\tthis.input = input;\n\t\tthis.route = route;\n\t\tthis.params = params;\n\t\tthis.redirect = redirect;\n\t\tthis.original = null;\n\t\tthis.key = 0;\n\t\tthis.error = undefined;\n\t\tif (url != null) {\n\t\t\tthis.url = url;\n\t\t} else if (route) {\n\t\t\tthis.url = route.href(params);\n\t\t} else {\n\t\t\tthrow new Error(\"MatchResult requires either a url or a route\");\n\t\t}\n\t}\n\n\t/** Mark this result as a redirect, recording the original match it came from. */\n\tisRedirect({ original }: { original: MatchResult | false }): void {\n\t\tthis.redirect = true;\n\t\tthis.original = original || null;\n\t}\n}\n","import { URLPattern as URLPatternPolyfill } from \"urlpattern-polyfill\";\n\nimport type { Params } from \"./types\";\n\n// Prefer a native URLPattern when the runtime provides one (browsers, Node >= 24),\n// otherwise fall back to the pure-JS polyfill. Resolved once at module load.\nconst URLPatternImpl: typeof URLPatternPolyfill =\n\t(globalThis as { URLPattern?: typeof URLPatternPolyfill }).URLPattern ??\n\tURLPatternPolyfill;\n\nexport type Matcher = InstanceType<typeof URLPatternImpl>;\n\n/** Named param descriptor parsed from a pattern's `:name` token + modifier. */\nexport interface ParamKey {\n\tname: string;\n\t/** `?` (optional single) or `*` (zero-or-more) — may be absent from the url. */\n\toptional: boolean;\n\t/** `+` (one-or-more) or `*` (zero-or-more) — spans multiple path segments. */\n\trepeat: boolean;\n}\n\n// Matches `:name` with an optional `?` / `+` / `*` modifier (URLPattern group\n// syntax we support for reverse routing). Ident chars mirror URLPattern's rules.\nconst IDENT = \"[A-Za-z_$][A-Za-z0-9_$]*\";\nconst TOKEN = new RegExp(`:(${IDENT})([?+*])?`, \"g\");\n// A repeatable/optional token together with its preceding slash: `/…:name?` etc.\nconst SLASH_TOKEN = new RegExp(`/:(${IDENT})([?*])`, \"g\");\n\n/** The companion array-accessor key for a repeat param (`path` -> `pathArray`). */\nexport function arrayKey(name: string): string {\n\treturn `${name}Array`;\n}\n\nexport function makeMatcher(pattern: string): Matcher {\n\treturn new URLPatternImpl({ pathname: pattern });\n}\n\n/** Test whether a pathname matches the matcher. */\nexport function testPath(matcher: Matcher, pathname: string): boolean {\n\treturn matcher.test({ pathname });\n}\n\n/** Exec a pathname against the matcher, returning its named groups or null. */\nexport function matchPath(\n\tmatcher: Matcher,\n\tpathname: string,\n): Record<string, string | undefined> | null {\n\tconst result = matcher.exec({ pathname });\n\treturn result ? result.pathname.groups : null;\n}\n\n/** Parse the named params declared by a pattern, in order. */\nexport function patternParamNames(pattern: string): ParamKey[] {\n\tconst keys: ParamKey[] = [];\n\tfor (const match of pattern.matchAll(TOKEN)) {\n\t\tconst modifier = match[2];\n\t\tkeys.push({\n\t\t\tname: match[1] ?? \"\",\n\t\t\toptional: modifier === \"?\" || modifier === \"*\",\n\t\t\trepeat: modifier === \"+\" || modifier === \"*\",\n\t\t});\n\t}\n\treturn keys;\n}\n\nfunction isEmpty(value: unknown): boolean {\n\treturn (\n\t\tvalue === undefined ||\n\t\tvalue === null ||\n\t\tvalue === \"\" ||\n\t\t(Array.isArray(value) && value.length === 0)\n\t);\n}\n\n/** Encode a single path segment. */\nfunction encodeSingle(value: unknown): string {\n\treturn encodeURIComponent(String(value));\n}\n\n/**\n * Encode a value into a path fragment. Repeat params accept an array of segments\n * or a pre-joined `a/b/c` string; either way each segment is encoded and joined\n * with `/`.\n */\nfunction encodeValue(value: unknown, repeat: boolean): string {\n\tif (!repeat) {\n\t\treturn encodeSingle(value);\n\t}\n\tconst segments = Array.isArray(value) ? value : String(value).split(\"/\");\n\treturn segments.map(encodeSingle).join(\"/\");\n}\n\nexport interface CompiledPath {\n\tpath: string;\n\t/** Names of params consumed by the path (the rest belong in the query). */\n\tconsumed: Set<string>;\n}\n\n/**\n * Reverse-router: build a concrete path from a pattern + params. URLPattern can\n * match but not build, so we compile `:name` tokens ourselves. Optional/repeat\n * tokens (with their leading slash) are dropped when the param is absent.\n * Repeat params read either `name` or its `nameArray` companion.\n */\nexport function compilePath(pattern: string, params: Params): CompiledPath {\n\tconst consumed = new Set<string>();\n\n\tfunction take(name: string, repeat: boolean): unknown {\n\t\tconsumed.add(name);\n\t\tif (repeat) {\n\t\t\tconsumed.add(arrayKey(name));\n\t\t\treturn params[name] !== undefined ? params[name] : params[arrayKey(name)];\n\t\t}\n\t\treturn params[name];\n\t}\n\n\t// Optional segments first, consuming the preceding slash: `/optional/:opt?`,\n\t// `/files/:path*`. `?` is a single optional; `*` is an optional repeat.\n\tlet path = pattern.replace(\n\t\tSLASH_TOKEN,\n\t\t(_all, name: string, modifier: string) => {\n\t\t\tconst repeat = modifier === \"*\";\n\t\t\tconst value = take(name, repeat);\n\t\t\tif (isEmpty(value)) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t\treturn `/${encodeValue(value, repeat)}`;\n\t\t},\n\t);\n\n\t// Remaining required tokens: `:name` and one-or-more `:name+`.\n\tpath = path.replace(TOKEN, (_all, name: string, modifier?: string) => {\n\t\tconst repeat = modifier === \"+\";\n\t\tconst value = take(name, repeat);\n\t\tif (isEmpty(value)) {\n\t\t\tif (modifier === \"?\" || modifier === \"*\") {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t\tthrow new Error(\n\t\t\t\t`Missing required param \"${name}\" for pattern \"${pattern}\"`,\n\t\t\t);\n\t\t}\n\t\treturn encodeValue(value, repeat);\n\t});\n\n\treturn { path, consumed };\n}\n","import { MatchResult } from \"./MatchResult\";\nimport {\n\tarrayKey,\n\tcompilePath,\n\ttype Matcher,\n\tmakeMatcher,\n\tmatchPath,\n\ttype ParamKey,\n\tpatternParamNames,\n\ttestPath,\n} from \"./pattern\";\nimport type { InputObject, Params, RouteConfig, RouteRedirect } from \"./types\";\n\nconst REQUIRED_PARAMS = [\"name\", \"pattern\", \"page\"] as const;\nconst RESERVED_PARAMS = [\"is\", \"match\", \"href\"];\n\n/** Convert a URLSearchParams into params, arraying repeated keys. */\nfunction searchToParams(search: URLSearchParams): Params {\n\tconst params: Params = {};\n\tfor (const key of new Set(search.keys())) {\n\t\tconst all = search.getAll(key);\n\t\tparams[key] = all.length > 1 ? all : all[0];\n\t}\n\treturn params;\n}\n\nexport class Route {\n\tname!: string;\n\tpattern!: string;\n\tpage: unknown;\n\tredirect?: RouteRedirect;\n\t// Arbitrary route metadata (e.g. `session`, `role`) copied from config.\n\t[key: string]: unknown;\n\n\t#matcher: Matcher;\n\t#paramKeys: ParamKey[];\n\n\tconstructor(config: RouteConfig) {\n\t\tfor (const param of REQUIRED_PARAMS) {\n\t\t\tif (!(param in config)) {\n\t\t\t\tthrow new Error(`Missing route param ${param}`);\n\t\t\t}\n\t\t}\n\n\t\t// Copy all config onto the route, guarding against clobbering methods.\n\t\tfor (const [key, value] of Object.entries(config)) {\n\t\t\tif (RESERVED_PARAMS.includes(key)) {\n\t\t\t\tthrow new Error(`Invalid route param ${key}`);\n\t\t\t}\n\t\t\t(this as Record<string, unknown>)[key] = value;\n\t\t}\n\n\t\tthis.#matcher = makeMatcher(this.pattern);\n\t\tthis.#paramKeys = patternParamNames(this.pattern);\n\t}\n\n\t/** Match against a url input or a route input. */\n\tmatch(input: InputObject): MatchResult | false {\n\t\treturn input.url ? this.#matchUrl(input) : this.#matchRoute(input);\n\t}\n\n\t/**\n\t * Test whether this route matches. A `/`-containing string is matched against\n\t * the pattern; otherwise it's compared to the route name.\n\t */\n\tis(test: string): boolean {\n\t\tif (test.indexOf(\"/\") !== -1) {\n\t\t\treturn testPath(this.#matcher, new URL(test, \"http://x/\").pathname);\n\t\t}\n\t\treturn this.name === test;\n\t}\n\n\t/** Build a URL for this route from the given params. */\n\thref(params: Params = {}): string {\n\t\tconst { path, consumed } = compilePath(this.pattern, params);\n\t\tconst query = new URLSearchParams();\n\t\tfor (const [key, value] of Object.entries(params)) {\n\t\t\tif (consumed.has(key) || value === undefined || value === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tquery.append(key, String(item));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tquery.append(key, String(value));\n\t\t\t}\n\t\t}\n\t\tconst qs = query.toString();\n\t\treturn qs ? `${path}?${qs}` : path;\n\t}\n\n\t#matchUrl(input: InputObject): MatchResult | false {\n\t\tconst url = input.url as string;\n\t\tconst parsed = new URL(url, \"http://x/\");\n\t\tconst groups = matchPath(this.#matcher, parsed.pathname);\n\t\tif (!groups) {\n\t\t\treturn false;\n\t\t}\n\t\tconst routeParams = this.#groupParams(groups);\n\t\tconst queryParams = searchToParams(parsed.searchParams);\n\t\tconst params = { ...routeParams, ...queryParams };\n\t\treturn new MatchResult({ route: this, input, params });\n\t}\n\n\t// Matches if the name matches and all required (non-optional) params present.\n\t#matchRoute(input: InputObject): MatchResult | false {\n\t\tconst route = input.route;\n\t\tif (!route || route.name !== this.name) {\n\t\t\treturn false;\n\t\t}\n\t\tconst params = route.params ?? {};\n\t\t// A required param is present if its name is set — or, for a repeat param,\n\t\t// either its name or its `nameArray` accessor.\n\t\tconst hasAll = this.#paramKeys\n\t\t\t.filter((key) => !key.optional)\n\t\t\t.every(\n\t\t\t\t(key) =>\n\t\t\t\t\tkey.name in params || (key.repeat && arrayKey(key.name) in params),\n\t\t\t);\n\t\tif (!hasAll) {\n\t\t\treturn false;\n\t\t}\n\t\treturn new MatchResult({ route: this, input, params });\n\t}\n\n\t#groupParams(groups: Record<string, string | undefined>): Params {\n\t\tconst params: Params = {};\n\t\tfor (const { name, optional, repeat } of this.#paramKeys) {\n\t\t\tconst raw = groups[name];\n\t\t\tconst defined = raw !== undefined && raw !== \"\";\n\t\t\tif (repeat) {\n\t\t\t\t// Repeat params span multiple segments. Expose both the raw joined\n\t\t\t\t// string (`path`) and the split, decoded segments (`pathArray`).\n\t\t\t\tif (defined) {\n\t\t\t\t\tconst segments = raw\n\t\t\t\t\t\t.split(\"/\")\n\t\t\t\t\t\t.map((segment) => decodeURIComponent(segment));\n\t\t\t\t\tparams[name] = segments.join(\"/\");\n\t\t\t\t\tparams[arrayKey(name)] = segments;\n\t\t\t\t} else if (!optional) {\n\t\t\t\t\tparams[name] = raw;\n\t\t\t\t\tparams[arrayKey(name)] = [];\n\t\t\t\t}\n\t\t\t} else if (defined) {\n\t\t\t\tparams[name] = decodeURIComponent(raw);\n\t\t\t} else if (!optional) {\n\t\t\t\tparams[name] = raw;\n\t\t\t}\n\t\t}\n\t\treturn params;\n\t}\n}\n","import { logger } from \"./logger\";\nimport { MatchResult } from \"./MatchResult\";\nimport { Route } from \"./Route\";\nimport type {\n\tInput,\n\tInputObject,\n\tRedirectResult,\n\tRedirectTest,\n\tRouteConfig,\n\tRouterConfig,\n} from \"./types\";\n\nfunction omit(\n\tobj: Record<string, unknown>,\n\tkeys: string[],\n): Record<string, unknown> {\n\tconst out: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(obj)) {\n\t\tif (!keys.includes(key)) {\n\t\t\tout[key] = value;\n\t\t}\n\t}\n\treturn out;\n}\n\ninterface RedirectEntry {\n\tname: string;\n\ttest: RedirectTest;\n}\n\ninterface CheckRedirectsArgs {\n\toriginal: MatchResult | false;\n\textra: Record<string, unknown>;\n\tprevious?: MatchResult | false | null;\n\tcurrent?: MatchResult | false | null;\n\tnum_redirects?: number;\n\thistory?: Array<MatchResult | false>;\n}\n\nexport class Router {\n\troutes: Route[] = [];\n\tredirects: RedirectEntry[] = [];\n\tmax_redirects: number;\n\n\tconstructor({ routes, redirects = {}, max_redirects = 10 }: RouterConfig) {\n\t\tthis.max_redirects = max_redirects;\n\t\tthis.addRoutes(routes);\n\t\tfor (const [name, test] of Object.entries(redirects)) {\n\t\t\tthis.redirects.push({ name, test });\n\t\t}\n\t\tlogger.debug(\"Constructed router\", this);\n\t}\n\n\taddRoutes(routes: Record<string, RouteConfig>): void {\n\t\tfor (const [name, config] of Object.entries(routes)) {\n\t\t\tconfig.name = name;\n\t\t\tconst route = new Route(config);\n\t\t\tlogger.debug(\"Adding route\", route);\n\t\t\tthis.routes.push(route);\n\t\t}\n\t}\n\n\t/** Lookup a route by name. Throws if none is registered under that name. */\n\tget(name: string): Route {\n\t\tconst route = this.find({ name });\n\t\tif (!route) {\n\t\t\tconst msg = `No route named ${name}`;\n\t\t\tlogger.error(msg);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t\treturn route;\n\t}\n\n\t/** Find a route by arbitrary field equality. Returns undefined when none match. */\n\tfind(query: Record<string, unknown>): Route | undefined {\n\t\treturn this.routes.find((route) =>\n\t\t\tObject.entries(query).every(\n\t\t\t\t([key, value]) => (route as Record<string, unknown>)[key] === value,\n\t\t\t),\n\t\t);\n\t}\n\n\t/**\n\t * Match input against the routes, following any redirects.\n\t * Returns the resolved (possibly redirect) MatchResult.\n\t */\n\tmatch(input: Input): MatchResult {\n\t\tconst normalized = this.normalizeInput(input);\n\t\tconst extra = omit(normalized, [\"route\", \"url\"]);\n\t\tconst original = this.#match(normalized);\n\t\tconst redirect = this.#checkRedirects({ original, extra });\n\t\tlogger.debug(\"match\", { input: normalized, original, redirect });\n\t\tif (redirect) {\n\t\t\tredirect.isRedirect({ original });\n\t\t\treturn redirect;\n\t\t}\n\t\t// With no redirect, return the original match. When nothing matched and no\n\t\t// NotFound-style rule is configured this is `false`; callers that want a\n\t\t// guaranteed match should add such a rule.\n\t\treturn original as MatchResult;\n\t}\n\n\tnormalizeInput(input: Input): InputObject {\n\t\tif (typeof input === \"string\") {\n\t\t\tif (input.indexOf(\"/\") !== -1) {\n\t\t\t\treturn { url: input };\n\t\t\t}\n\t\t\treturn { route: { name: input } };\n\t\t}\n\t\tif (input !== null && typeof input === \"object\") {\n\t\t\tif (input.name) {\n\t\t\t\treturn { route: input as { name: string } };\n\t\t\t}\n\t\t\treturn input;\n\t\t}\n\t\tconst error = new Error(\"Invalid input\") as Error & { input?: unknown };\n\t\terror.input = input;\n\t\tthrow error;\n\t}\n\n\t/**\n\t * Resolve an input. Kept as an alias for {@link match} so `Router` can be used\n\t * directly in tests without going through a store. The store's `go` (in\n\t * history.ts) is what apps use — it updates history and notifies listeners.\n\t */\n\tgo(input: Input): MatchResult {\n\t\treturn this.match(input);\n\t}\n\n\t#match(input: InputObject): MatchResult | false {\n\t\tlogger.debug(\"Attempting to match route\", input);\n\t\tconst { url } = input;\n\t\t// A full external url is treated as a redirect out of the app.\n\t\tif (url && /^https?:\\/\\//.test(url)) {\n\t\t\treturn new MatchResult({ redirect: true, input, url });\n\t\t}\n\n\t\tlet match: MatchResult | false = false;\n\t\tfor (const route of this.routes) {\n\t\t\tmatch = route.match(input);\n\t\t\tif (match) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn match;\n\t}\n\n\t#checkRedirects(args: CheckRedirectsArgs): MatchResult | false {\n\t\tconst { original, extra } = args;\n\t\tlet {\n\t\t\tprevious = null,\n\t\t\tcurrent = null,\n\t\t\tnum_redirects = 0,\n\t\t\thistory = [],\n\t\t} = args;\n\t\tlogger.debug(\"Checking redirects\", {\n\t\t\toriginal,\n\t\t\textra,\n\t\t\tprevious,\n\t\t\tcurrent,\n\t\t\tnum_redirects,\n\t\t\thistory,\n\t\t});\n\n\t\tconst { max_redirects } = this;\n\t\tif (num_redirects >= max_redirects) {\n\t\t\tconst msg = `Number of redirects exceeded max_redirects (${max_redirects})`;\n\t\t\tlogger.error(msg);\n\t\t\tthrow new Error(msg);\n\t\t}\n\n\t\tconst deepEqual = (a: unknown, b: unknown): boolean =>\n\t\t\tJSON.stringify(a) === JSON.stringify(b);\n\n\t\t// If current is the same route+params as previous, we've looped — stop.\n\t\tif (current && previous) {\n\t\t\tconst sameRoute = current.route === previous.route;\n\t\t\tconst sameParams = deepEqual(current.params, previous.params);\n\t\t\tif (sameRoute && sameParams) {\n\t\t\t\tlogger.debug(\"Route is same as previous\", { current, previous });\n\t\t\t\treturn previous;\n\t\t\t}\n\t\t}\n\n\t\tif (!current) {\n\t\t\tcurrent = original;\n\t\t\thistory = [original];\n\t\t}\n\n\t\t// `current` may be `false` (no match); narrow to null so chaining is legal.\n\t\tconst matched = current === false ? null : current;\n\t\tif (matched?.redirect) {\n\t\t\treturn matched;\n\t\t}\n\n\t\tlet next: RedirectResult = false;\n\t\tif (matched?.route?.redirect) {\n\t\t\tnext = matched.route.redirect(matched);\n\t\t}\n\n\t\tif (!next) {\n\t\t\tfor (const { test } of this.redirects) {\n\t\t\t\tnext = test(current);\n\t\t\t\tif (next) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (next) {\n\t\t\tlogger.debug(\"Got redirect\", { current, next });\n\t\t\tprevious = current;\n\t\t\tconst normalizedNext = this.normalizeInput(next as Input);\n\t\t\tcurrent = this.#match({ ...normalizedNext, ...extra });\n\t\t\tif (!current) {\n\t\t\t\tconst error = new Error(\"No match for redirect result\") as Error & {\n\t\t\t\t\tredirect?: unknown;\n\t\t\t\t};\n\t\t\t\terror.redirect = normalizedNext;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\thistory.push(current);\n\t\t\tnum_redirects++;\n\t\t\treturn this.#checkRedirects({\n\t\t\t\toriginal,\n\t\t\t\tprevious,\n\t\t\t\tcurrent,\n\t\t\t\tnum_redirects,\n\t\t\t\thistory,\n\t\t\t\textra,\n\t\t\t});\n\t\t}\n\n\t\tif (num_redirects > 0) {\n\t\t\treturn current;\n\t\t}\n\t\treturn false;\n\t}\n}\n","import type { MatchResult } from \"./MatchResult\";\nimport type { Route } from \"./Route\";\nimport { Router } from \"./Router\";\nimport type {\n\tComponent,\n\tInput,\n\tRouteError,\n\tRouterConfig,\n\tTitleValue,\n} from \"./types\";\n\n/**\n * Pluggable history/location seam. The core never touches `window` directly —\n * only `createBrowserHistory` does — so the matching engine and store run in any\n * JS runtime (browser, Node, workers, React Native) with an appropriate history.\n */\nexport interface History {\n\t/** Current location as a root-relative url (pathname + search + hash). */\n\tlocation(): string;\n\t/** Navigate, pushing a new entry. */\n\tpush(url: string): void;\n\t/** Navigate, replacing the current entry (used for redirects). */\n\treplace(url: string): void;\n\t/** Go back one entry in the history stack. */\n\tback(): void;\n\t/** Go forward one entry in the history stack. */\n\tforward(): void;\n\t/** Subscribe to external location changes (e.g. back/forward). Returns an unsubscribe. */\n\tsubscribe(listener: () => void): () => void;\n}\n\nfunction isExternal(url: string): boolean {\n\treturn /^[a-z][a-z0-9+.-]*:\\/\\//i.test(url);\n}\n\n/** Browser history backed by `window.location` + `popstate`. */\nexport function createBrowserHistory(): History {\n\tconst listeners = new Set<() => void>();\n\tconst notify = (): void => {\n\t\tfor (const listener of listeners) listener();\n\t};\n\treturn {\n\t\tlocation() {\n\t\t\tconst { pathname, search, hash } = window.location;\n\t\t\treturn `${pathname}${search}${hash}`;\n\t\t},\n\t\tpush(url) {\n\t\t\t// pushState does not fire popstate, so notify subscribers ourselves.\n\t\t\twindow.history.pushState({}, \"\", url);\n\t\t\tnotify();\n\t\t},\n\t\treplace(url) {\n\t\t\t// replace is used for redirect reflection — silent, to avoid re-resolving.\n\t\t\twindow.history.replaceState({}, \"\", url);\n\t\t},\n\t\tback() {\n\t\t\twindow.history.back();\n\t\t},\n\t\tforward() {\n\t\t\twindow.history.forward();\n\t\t},\n\t\tsubscribe(listener) {\n\t\t\tif (listeners.size === 0) {\n\t\t\t\twindow.addEventListener(\"popstate\", notify);\n\t\t\t}\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener);\n\t\t\t\tif (listeners.size === 0) {\n\t\t\t\t\twindow.removeEventListener(\"popstate\", notify);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t};\n}\n\n/** In-memory history for SSR, tests, and non-DOM runtimes. */\nexport function createMemoryHistory(initial = \"/\"): History {\n\tconst stack: string[] = [initial];\n\tlet index = 0;\n\tconst listeners = new Set<() => void>();\n\tconst emit = (): void => {\n\t\tfor (const listener of listeners) listener();\n\t};\n\treturn {\n\t\tlocation() {\n\t\t\treturn stack[index] ?? \"/\";\n\t\t},\n\t\tpush(url) {\n\t\t\tstack.length = index + 1;\n\t\t\tstack.push(url);\n\t\t\tindex += 1;\n\t\t\temit();\n\t\t},\n\t\treplace(url) {\n\t\t\tstack[index] = url;\n\t\t},\n\t\tback() {\n\t\t\tif (index > 0) {\n\t\t\t\tindex -= 1;\n\t\t\t\temit();\n\t\t\t}\n\t\t},\n\t\tforward() {\n\t\t\tif (index < stack.length - 1) {\n\t\t\t\tindex += 1;\n\t\t\t\temit();\n\t\t\t}\n\t\t},\n\t\tsubscribe(listener) {\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener);\n\t\t\t};\n\t\t},\n\t};\n}\n\nfunction defaultHistory(): History {\n\tconst hasDom =\n\t\ttypeof window !== \"undefined\" && !!window.history && !!window.location;\n\treturn hasDom ? createBrowserHistory() : createMemoryHistory();\n}\n\nexport interface RouterStoreConfig extends RouterConfig {\n\t/** History implementation. Defaults to browser when a DOM is present, else memory. */\n\thistory?: History;\n}\n\n/** Snapshot listener (React's `useSyncExternalStore` shape). Fires with the new match. */\nexport type StoreListener = (match: MatchResult) => void;\n/** Fires on each successful nav with both the previous and the new match. */\nexport type GoListener = (prev: MatchResult, current: MatchResult) => void;\n/** Fires when the title changes (from a nav or an explicit `setTitle`). */\nexport type TitleListener = (title: string) => void;\n/** Fires when an error is set on the current match (typically from an adapter). */\nexport type ErrorListener = (error: RouteError | undefined) => void;\n\n/**\n * A framework-agnostic router store: wraps a `Router` + a `History`, keeps a\n * current snapshot in sync with the location, and exposes subscribe/getSnapshot\n * for React `useSyncExternalStore` plus richer channels (`onGo`, `onTitle`,\n * `onError`) that adapters wire to effects.\n *\n * Naming: the router action is `go` everywhere. Subscriptions to that action\n * are `onGo`. Never `navigate`.\n */\nexport interface GoOptions {\n\t/** Replace the current history entry instead of pushing a new one. */\n\treplace?: boolean;\n}\n\nexport interface RouterStore {\n\treadonly router: Router;\n\treadonly history: History;\n\t/** Fallback error UI (from config). Adapters use this when a route has no `errorPage`. */\n\treadonly errorPage: Component;\n\t/** Match without navigating. */\n\tmatch(input: Input): MatchResult;\n\t/**\n\t * Navigate to input, updating history and notifying subscribers. Pass\n\t * `{ replace: true }` to overwrite the current history entry (useful for\n\t * search-param edits that shouldn't add a back button entry).\n\t */\n\tgo(input: Input, options?: GoOptions): MatchResult;\n\t/** Shortcut for `router.get(name)` — look up a route by name. */\n\tget(name: string): Route;\n\t/** Current resolved match for the location. */\n\tgetSnapshot: () => MatchResult;\n\t/** Subscribe to snapshot changes. Returns an unsubscribe. */\n\tsubscribe: (listener: StoreListener) => () => void;\n\t/**\n\t * Subscribe to nav events. Fires with `(prev, current)` after each\n\t * successful navigation. Returns an unsubscribe.\n\t */\n\tonGo(listener: GoListener): () => void;\n\t/** Current title string. Recomputed from `match.route.title` on each nav. */\n\treadonly title: string;\n\t/** Set the title (fires `onTitle`; overrides route title until next nav). */\n\tsetTitle(title: string): void;\n\tonTitle(listener: TitleListener): () => void;\n\t/** Set an error on the current match (fires `onError`). Called by adapters. */\n\tsetError(error: RouteError | undefined): void;\n\tonError(listener: ErrorListener): () => void;\n\t/** Detach from history and drop all subscribers. */\n\tdestroy(): void;\n}\n\nfunction resolveTitle(match: MatchResult): string {\n\tconst raw = match.route?.title as TitleValue | undefined;\n\tif (raw === undefined) return \"\";\n\treturn typeof raw === \"function\" ? raw(match) : raw;\n}\n\nexport function createRouter(config: RouterStoreConfig): RouterStore {\n\tconst { history = defaultHistory(), errorPage, ...routerConfig } = config;\n\tconst router = new Router(routerConfig);\n\n\tconst snapshotListeners = new Set<StoreListener>();\n\tconst goListeners = new Set<GoListener>();\n\tconst titleListeners = new Set<TitleListener>();\n\tconst errorListeners = new Set<ErrorListener>();\n\n\tlet keySeq = 0;\n\n\tfunction stamp(match: MatchResult): MatchResult {\n\t\tkeySeq += 1;\n\t\tmatch.key = keySeq;\n\t\treturn match;\n\t}\n\n\tfunction resolve(url: string): MatchResult {\n\t\tconst match = router.match({ url });\n\t\t// Reflect an in-app redirect target in the address bar without a new entry.\n\t\tif (\n\t\t\tmatch?.redirect &&\n\t\t\tmatch.url &&\n\t\t\t!isExternal(match.url) &&\n\t\t\tmatch.url !== url\n\t\t) {\n\t\t\thistory.replace(match.url);\n\t\t}\n\t\treturn stamp(match);\n\t}\n\n\tlet snapshot = resolve(history.location());\n\tlet title = resolveTitle(snapshot);\n\n\tfunction emitSnapshot(prev: MatchResult): void {\n\t\tfor (const listener of snapshotListeners) listener(snapshot);\n\t\tfor (const listener of goListeners) listener(prev, snapshot);\n\t}\n\n\tfunction emitTitle(): void {\n\t\tfor (const listener of titleListeners) listener(title);\n\t}\n\n\tfunction emitError(): void {\n\t\tfor (const listener of errorListeners) listener(snapshot.error);\n\t}\n\n\tfunction applyRouteTitle(): void {\n\t\tconst next = resolveTitle(snapshot);\n\t\tif (next !== title) {\n\t\t\ttitle = next;\n\t\t\temitTitle();\n\t\t}\n\t}\n\n\tfunction refresh(): void {\n\t\tconst prev = snapshot;\n\t\tsnapshot = resolve(history.location());\n\t\tapplyRouteTitle();\n\t\temitSnapshot(prev);\n\t}\n\n\tconst unsubscribeHistory = history.subscribe(refresh);\n\n\tconst store: RouterStore = {\n\t\trouter,\n\t\thistory,\n\t\terrorPage,\n\t\tmatch: (input) => router.match(input),\n\t\tgo(input, options) {\n\t\t\tconst prev = snapshot;\n\t\t\tconst match = router.go(input);\n\t\t\tif (match.url && !isExternal(match.url)) {\n\t\t\t\tif (options?.replace) {\n\t\t\t\t\t// history.replace is silent; drive snapshot + emit ourselves.\n\t\t\t\t\thistory.replace(match.url);\n\t\t\t\t\tsnapshot = stamp(match);\n\t\t\t\t\tapplyRouteTitle();\n\t\t\t\t\temitSnapshot(prev);\n\t\t\t\t\treturn snapshot;\n\t\t\t\t}\n\t\t\t\t// Route through history; its notification drives snapshot + emit once\n\t\t\t\t// (refresh() will stamp the new match with a fresh key). Return the\n\t\t\t\t// resulting snapshot so callers see the same object subscribers do.\n\t\t\t\thistory.push(match.url);\n\t\t\t\treturn snapshot;\n\t\t\t}\n\t\t\tif (match.url) {\n\t\t\t\t// External url: don't pushState cross-origin; record + notify directly.\n\t\t\t\tsnapshot = stamp(match);\n\t\t\t\tapplyRouteTitle();\n\t\t\t\temitSnapshot(prev);\n\t\t\t}\n\t\t\treturn match;\n\t\t},\n\t\tget: (name) => router.get(name),\n\t\tgetSnapshot: () => snapshot,\n\t\tsubscribe(listener) {\n\t\t\tsnapshotListeners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tsnapshotListeners.delete(listener);\n\t\t\t};\n\t\t},\n\t\tonGo(listener) {\n\t\t\tgoListeners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tgoListeners.delete(listener);\n\t\t\t};\n\t\t},\n\t\tget title() {\n\t\t\treturn title;\n\t\t},\n\t\tsetTitle(next) {\n\t\t\tif (next !== title) {\n\t\t\t\ttitle = next;\n\t\t\t\temitTitle();\n\t\t\t}\n\t\t},\n\t\tonTitle(listener) {\n\t\t\ttitleListeners.add(listener);\n\t\t\treturn () => {\n\t\t\t\ttitleListeners.delete(listener);\n\t\t\t};\n\t\t},\n\t\tsetError(next) {\n\t\t\tif (next !== snapshot.error) {\n\t\t\t\t// Produce a new snapshot object so `useSyncExternalStore`-shaped\n\t\t\t\t// subscribers see a reference change and re-render. Preserve the\n\t\t\t\t// MatchResult prototype for consumers doing `instanceof` checks.\n\t\t\t\tconst updated = Object.assign(\n\t\t\t\t\tObject.create(Object.getPrototypeOf(snapshot)),\n\t\t\t\t\tsnapshot,\n\t\t\t\t\t{ error: next },\n\t\t\t\t);\n\t\t\t\tsnapshot = updated;\n\t\t\t\temitError();\n\t\t\t\tfor (const listener of snapshotListeners) listener(snapshot);\n\t\t\t}\n\t\t},\n\t\tonError(listener) {\n\t\t\terrorListeners.add(listener);\n\t\t\treturn () => {\n\t\t\t\terrorListeners.delete(listener);\n\t\t\t};\n\t\t},\n\t\tdestroy() {\n\t\t\tunsubscribeHistory();\n\t\t\tsnapshotListeners.clear();\n\t\t\tgoListeners.clear();\n\t\t\ttitleListeners.clear();\n\t\t\terrorListeners.clear();\n\t\t},\n\t};\n\n\treturn store;\n}\n"],"mappings":";;AAOA,IAAI,UAAU;AACd,IAAI;CACH,MAAM,QAAQ,OAAO,YAAY,cAAc,QAAQ,KAAK,QAAQ,KAAA;CACpE,UAAU,CAAC,CAAC,SAAS,gCAAgC,KAAK,KAAK;AAChE,QAAQ;CACP,UAAU;AACX;AAEA,MAAa,SAAS;CACrB,OAAO,KAAK,MAAY;EACvB,UAAU;CACX;CACA,IAAI,UAAmB;EACtB,OAAO;CACR;CACA,MAAM,GAAG,MAAuB;EAC/B,IAAI,SAAS,QAAQ,MAAM,cAAc,GAAG,IAAI;CACjD;CACA,KAAK,GAAG,MAAuB;EAC9B,IAAI,SAAS,QAAQ,KAAK,cAAc,GAAG,IAAI;CAChD;CACA,KAAK,GAAG,MAAuB;EAC9B,IAAI,SAAS,QAAQ,KAAK,cAAc,GAAG,IAAI;CAChD;CACA,MAAM,GAAG,MAAuB;EAC/B,IAAI,SAAS,QAAQ,MAAM,cAAc,GAAG,IAAI;CACjD;AACD;;;;;;;;;;;;;ACZA,IAAa,cAAb,MAAyB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,EACX,OACA,QAAQ,MACR,MAAM,MACN,SAAS,CAAC,GACV,WAAW,SACQ;EACnB,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,SAAS;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gB,OAAO,OACtB,OAAO,OAAO,OAAO,eAAe,QAAQ,CAAC,GAC7C,UACA,EAAE,OAAO,KAAK,CAEE;IACjB,UAAU;IACV,KAAK,MAAM,YAAY,mBAAmB,SAAS,QAAQ;GAC5D;EACD;EACA,QAAQ,UAAU;GACjB,eAAe,IAAI,QAAQ;GAC3B,aAAa;IACZ,eAAe,OAAO,QAAQ;GAC/B;EACD;EACA,UAAU;GACT,mBAAmB;GACnB,kBAAkB,MAAM;GACxB,YAAY,MAAM;GAClB,eAAe,MAAM;GACrB,eAAe,MAAM;EACtB;CAGU;AACZ"}
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@diso.io/groutcho-core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Declarative, framework-agnostic router with a URLPattern matching core and pluggable history",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "author": {
8
+ "name": "Stephen Handley",
9
+ "email": "stephen@hello10.com",
10
+ "url": "https://hello10.com"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/Hello10/groutcho.git",
15
+ "directory": "packages/groutcho/core"
16
+ },
17
+ "keywords": [
18
+ "router",
19
+ "routing",
20
+ "urlpattern",
21
+ "isomorphic",
22
+ "history"
23
+ ],
24
+ "sideEffects": false,
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "main": "./dist/index.js",
35
+ "module": "./dist/index.js",
36
+ "types": "./dist/index.d.ts",
37
+ "dependencies": {
38
+ "urlpattern-polyfill": "^10.1.0"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "build": "vp pack",
45
+ "dev": "vp pack --watch",
46
+ "test": "vp test"
47
+ }
6
48
  }