white-label-router 5.0.0 → 6.0.0

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.
@@ -0,0 +1,19 @@
1
+ # Package manager support
2
+
3
+ `white-label-router` supports npm, Yarn, and pnpm consumers.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install white-label-router
9
+ yarn add white-label-router
10
+ pnpm add white-label-router
11
+ ```
12
+
13
+ CI packs the real distributable artifact and installs that same artifact with all three package managers before exercising the public Router API.
14
+
15
+ ## Repository development
16
+
17
+ The committed `package-lock.json` remains the repository's canonical dependency lockfile and npm remains the maintenance/audit path used by the primary CI job. Yarn and pnpm compatibility does not require committing `yarn.lock` or `pnpm-lock.yaml`.
18
+
19
+ Nested project scripts use Node's `--run` support so `npm test`, `yarn test`, and `pnpm test` do not depend on another package manager to invoke child scripts.
package/README.md CHANGED
@@ -138,13 +138,13 @@ router.routes = {
138
138
  };
139
139
  ```
140
140
 
141
- `secure()` must return exactly `true` to allow navigation. On a successful route change, the previous route's `destroy()` runs before the next route's `initialize()`.
141
+ `secure()` must return exactly `true` to allow navigation. Router validates the destination guard and runnable view behavior before tearing down the current route. On a successful route change, the previous route's `destroy()` then runs before the next route's `initialize()`.
142
142
 
143
143
  ## Matching
144
144
 
145
145
  Routes match complete path boundaries. `/products` matches `/products` and `/products/42`, but not `/products-old`.
146
146
 
147
- When multiple route prefixes match, Router selects the **longest matching route**, so specific routes win without depending on object insertion order:
147
+ When multiple route prefixes match, Router selects the **longest matching route**, so specific routes win without depending on object insertion order. Only own route-table properties participate in matching:
148
148
 
149
149
  ```js
150
150
  router.routes = {
@@ -171,7 +171,7 @@ Routes receive the configured `scope` and a location object:
171
171
  }
172
172
  ```
173
173
 
174
- `data.url` contains path segments after the matched prefix, `data.query` contains parsed query values, and `data.mediator` contains navigation data supplied programmatically or through the mediator. Values are URI-decoded with standard WHATWG URL APIs; applications must still validate untrusted values.
174
+ `data.url` contains path segments after the matched prefix, `data.query` contains parsed query values, and `data.mediator` contains navigation data supplied programmatically or through `CustomEvent.detail`. Values are URI-decoded with standard WHATWG URL APIs; applications must still validate untrusted values.
175
175
 
176
176
  ## Programmatic navigation
177
177
 
@@ -185,11 +185,13 @@ const result = router.navigate('/products/42', {
185
185
 
186
186
  In browsers, successful navigation updates history unless the call represents `popstate`. On servers it dispatches without History API effects.
187
187
 
188
+ Rejected navigation is atomic from Router's perspective: cross-origin browser URLs, failed guards, and routes without runnable view behavior return `false` without destroying the current route, pushing browser history, or replacing the last successful `url`, selected route, or location payload.
189
+
188
190
  Calling `navigate()` without a URL dispatches the current browser URL. In a non-browser runtime the safe default is `/`; server applications should normally supply the request URL explicitly.
189
191
 
190
192
  ## Mediator integration
191
193
 
192
- Assign any EventEmitter-compatible mediator that provides `on()` and `removeListener()`:
194
+ Assign any standards-based event target that provides `addEventListener()` and `removeEventListener()`. `white-label-mediator` is the first-party implementation:
193
195
 
194
196
  ```js
195
197
  import Mediator from 'white-label-mediator';
@@ -200,23 +202,27 @@ const router = new Router();
200
202
  router.mediator = mediator;
201
203
  router.initialize();
202
204
 
203
- mediator.emit('router:navigate', {
204
- url: '/account',
205
- reason: 'Session refreshed'
206
- });
205
+ mediator.dispatchEvent(new CustomEvent('router:navigate', {
206
+ detail: {
207
+ url: '/account',
208
+ reason: 'Session refreshed'
209
+ }
210
+ }));
207
211
  ```
208
212
 
209
- The complete event object becomes `location.data.mediator`. `destroy()` removes listeners owned by Router. Repeated listener initialization is idempotent.
213
+ The `CustomEvent.detail` value becomes `location.data.mediator`. `destroy()` removes the listener owned by Router. Repeated listener initialization is idempotent. Reassigning `router.mediator` while listeners are active removes `router:navigate` from the previous mediator before subscribing to the replacement.
214
+
215
+ Router does not import or require `white-label-mediator`; the integration is structural so another compatible EventTarget can be used instead.
210
216
 
211
217
  ## Public API
212
218
 
213
219
  | Member | Behavior | Returns |
214
220
  | --- | --- | --- |
215
- | `routes` | Ordered route table of functions or lifecycle route objects. | Configuration property; not a method. |
221
+ | `routes` | Route table of functions or lifecycle route objects; matching uses the longest own path prefix, not insertion order. | Configuration property; not a method. |
216
222
  | `scope` | Application scope passed to route callbacks. | Configuration property; not a method. |
217
- | `mediator` | Optional EventEmitter-compatible source for `router:navigate`. | Configuration property; not a method. |
223
+ | `mediator` | Optional EventTarget-compatible source for `router:navigate`; active subscriptions move when this property changes. | Configuration property; not a method. |
218
224
  | `initialize(url?)` | Dispatch the browser URL or an explicit server URL and attach applicable listeners. | The same `Router` instance. |
219
- | `navigate(url?, data?, isPopState?)` | Match and run a route; update browser history when appropriate. | The same `Router` instance on success; `false` for cross-origin browser URLs, rejected guards, or routes without runnable view behavior. |
225
+ | `navigate(url?, data?, isPopState?)` | Match and run a route; update browser history when appropriate. Rejected navigation preserves the current route state. | The same `Router` instance on success; `false` for cross-origin browser URLs, rejected guards, or routes without runnable view behavior. |
220
226
  | `addListeners()` | Attach browser and optional mediator listeners once. | The same `Router` instance. |
221
227
  | `removeListeners()` | Release listeners owned by this router. | The same `Router` instance. |
222
228
  | `destroy()` | Release routing listeners. | The same `Router` instance after cleanup. |
@@ -244,7 +250,7 @@ The default focus selector is `main h1`. Set `focus: false` for an in-page refin
244
250
 
245
251
  ## Browser history behavior
246
252
 
247
- Initialization dispatches the current URL without adding a duplicate history entry. Back/forward navigation reads `window.location`—including path, query, and hash—even when history state is null or belongs to another application. History state is not treated as the authoritative URL.
253
+ Initialization dispatches the current URL without adding a duplicate history entry. Back/forward navigation reads `window.location`—including path, query, and hash—even when history state is null or belongs to another application. History state is not treated as the authoritative URL. Rejected navigation does not add a history entry.
248
254
 
249
255
  ## TypeScript
250
256
 
@@ -274,10 +280,10 @@ npm run audit
274
280
  npm pack --dry-run
275
281
  ```
276
282
 
277
- Tests cover browser behavior, DOM-free server routing, and parity of the shared route contract. Coverage enforces 100% statements, branches, functions, and lines per implementation file. CI builds authored source, uploads generated artifacts for inspection, audits dependencies, packs the package, and verifies the packed public API across npm, Yarn, and pnpm.
283
+ Tests cover browser behavior, DOM-free server routing, atomic rejected navigation, mediator reassignment, and parity of the shared route contract. Coverage enforces 100% statements, branches, functions, and lines per implementation file. CI verifies both the documented Node 22.18 minimum and the primary Node 24 line, builds authored source, audits dependencies, packs the package, and verifies the packed public API across npm, Yarn, and pnpm.
278
284
 
279
285
  Edit `src/*.ts` and regenerate `dist`; do not edit generated files directly.
280
286
 
281
287
  ## Design boundary
282
288
 
283
- Router owns URL-to-intent translation. It intentionally does not own application state, rendering, data loading, authentication policy, or server infrastructure. Real links and server URLs remain the foundation; Router enhances them instead of replacing them.
289
+ Router owns URL-to-intent translation. It intentionally does not own application state, rendering, data loading, authentication policy, or server infrastructure. Real links and server URLs remain the foundation; Router enhances them instead of replacing them.
package/dist/index.d.ts CHANGED
@@ -24,10 +24,10 @@ interface RouteObject {
24
24
  };
25
25
  }
26
26
  type Route = RouteHandler | RouteObject;
27
- /** Minimal event-bus contract required by the router. */
27
+ /** Minimal standards-based event target contract required by the router. */
28
28
  interface NavigationMediator {
29
- on(event: string, callback: (data?: NavigationData) => unknown): unknown;
30
- removeListener(event: string, callback: (data?: NavigationData) => unknown): unknown;
29
+ addEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
30
+ removeEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
31
31
  }
32
32
  /** History API router that also dispatches request URLs in non-browser runtimes. */
33
33
  declare class Router {
@@ -37,14 +37,18 @@ declare class Router {
37
37
  scope: Element | null;
38
38
  previousRoute: string | null;
39
39
  pageTitle: string | null;
40
- mediator: NavigationMediator | false;
41
40
  boundPushStateClick: (event: MouseEvent) => unknown;
42
41
  boundPopState: (event: PopStateEvent) => unknown;
43
- boundMediatorNavigate: (data?: NavigationData) => unknown;
42
+ boundMediatorNavigate: EventListener;
44
43
  listenersInitialized: boolean;
45
44
  locationData: LocationData;
45
+ private currentMediator;
46
+ private boundMediator;
46
47
  /** Create an instance with its own state and listener references. */
47
48
  constructor();
49
+ get mediator(): NavigationMediator | false;
50
+ /** Move an active router:navigate subscription when the mediator changes. */
51
+ set mediator(value: NavigationMediator | false);
48
52
  /** True when browser navigation APIs are available. */
49
53
  private isBrowserRuntime;
50
54
  /** Stable base URL for WHATWG URL parsing in browser and server runtimes. */
@@ -53,6 +57,8 @@ declare class Router {
53
57
  private getCurrentUrl;
54
58
  /** Normalize browser navigation to a same-origin path, query, and hash. */
55
59
  private normalizeBrowserUrl;
60
+ /** Return whether a selected route has runnable view behavior. */
61
+ private isRunnableRoute;
56
62
  /**
57
63
  * Start this instance and return it for lifecycle chaining.
58
64
  * In a browser the URL is optional and defaults to window.location. On a server pass the request URL.
package/dist/index.js CHANGED
@@ -7,12 +7,13 @@ class Router {
7
7
  scope;
8
8
  previousRoute;
9
9
  pageTitle;
10
- mediator;
11
10
  boundPushStateClick;
12
11
  boundPopState;
13
12
  boundMediatorNavigate;
14
13
  listenersInitialized;
15
14
  locationData = { url: '', data: { url: [], mediator: undefined, query: {} } };
15
+ currentMediator = false;
16
+ boundMediator = false;
16
17
  /** Create an instance with its own state and listener references. */
17
18
  constructor() {
18
19
  this.routes = {
@@ -28,14 +29,30 @@ class Router {
28
29
  this.scope = null;
29
30
  this.previousRoute = null;
30
31
  this.pageTitle = null;
31
- this.mediator = false;
32
32
  this.boundPushStateClick = this.eventPushStateClick.bind(this);
33
33
  this.boundPopState = this.eventPopState.bind(this);
34
- this.boundMediatorNavigate = (data = {}) => {
34
+ this.boundMediatorNavigate = (event) => {
35
+ const data = event.detail ?? {};
35
36
  this.navigate(data.url, data, false);
36
37
  };
37
38
  this.listenersInitialized = false;
38
39
  }
40
+ get mediator() { return this.currentMediator; }
41
+ /** Move an active router:navigate subscription when the mediator changes. */
42
+ set mediator(value) {
43
+ if (value === this.currentMediator) {
44
+ return;
45
+ }
46
+ if (this.listenersInitialized && this.boundMediator) {
47
+ this.boundMediator.removeEventListener('router:navigate', this.boundMediatorNavigate);
48
+ this.boundMediator = false;
49
+ }
50
+ this.currentMediator = value;
51
+ if (this.listenersInitialized && value) {
52
+ value.addEventListener('router:navigate', this.boundMediatorNavigate);
53
+ this.boundMediator = value;
54
+ }
55
+ }
39
56
  /** True when browser navigation APIs are available. */
40
57
  isBrowserRuntime() {
41
58
  return typeof window !== 'undefined' && typeof document !== 'undefined';
@@ -62,6 +79,11 @@ class Router {
62
79
  }
63
80
  return `${parsedUrl.pathname}${parsedUrl.search}${parsedUrl.hash}`;
64
81
  }
82
+ /** Return whether a selected route has runnable view behavior. */
83
+ isRunnableRoute(route) {
84
+ return typeof route === 'function' || typeof route.view === 'function' ||
85
+ Boolean(route.view && typeof route.view.initialize === 'function');
86
+ }
65
87
  /**
66
88
  * Start this instance and return it for lifecycle chaining.
67
89
  * In a browser the URL is optional and defaults to window.location. On a server pass the request URL.
@@ -81,8 +103,9 @@ class Router {
81
103
  document.addEventListener('click', this.boundPushStateClick);
82
104
  window.addEventListener('popstate', this.boundPopState);
83
105
  }
84
- if (this.mediator) {
85
- this.mediator.on('router:navigate', this.boundMediatorNavigate);
106
+ if (this.currentMediator) {
107
+ this.currentMediator.addEventListener('router:navigate', this.boundMediatorNavigate);
108
+ this.boundMediator = this.currentMediator;
86
109
  }
87
110
  this.listenersInitialized = true;
88
111
  return this;
@@ -101,8 +124,9 @@ class Router {
101
124
  document.removeEventListener('click', this.boundPushStateClick);
102
125
  window.removeEventListener('popstate', this.boundPopState);
103
126
  }
104
- if (this.mediator) {
105
- this.mediator.removeListener('router:navigate', this.boundMediatorNavigate);
127
+ if (this.boundMediator) {
128
+ this.boundMediator.removeEventListener('router:navigate', this.boundMediatorNavigate);
129
+ this.boundMediator = false;
106
130
  }
107
131
  this.listenersInitialized = false;
108
132
  return this;
@@ -130,8 +154,7 @@ class Router {
130
154
  return true;
131
155
  }
132
156
  e.preventDefault();
133
- this.url = `${location.pathname}${location.search}${location.hash}`;
134
- this.navigate(undefined, {}, false);
157
+ this.navigate(`${location.pathname}${location.search}${location.hash}`, {}, false);
135
158
  return this;
136
159
  }
137
160
  /** Restore browser history state without adding a new history entry. */
@@ -195,6 +218,9 @@ class Router {
195
218
  }
196
219
  /** Select a route, enforce its guard, transition view lifecycles, and update browser history when available. */
197
220
  navigate(url, mediatorData, isPopState = false) {
221
+ const previousUrl = this.url;
222
+ const previousSelectedRoute = this.route;
223
+ const previousLocationData = this.locationData;
198
224
  if (url !== undefined) {
199
225
  this.url = url;
200
226
  }
@@ -203,12 +229,13 @@ class Router {
203
229
  }
204
230
  const normalizedUrl = this.normalizeBrowserUrl(this.url);
205
231
  if (normalizedUrl === null) {
232
+ this.url = previousUrl;
206
233
  return false;
207
234
  }
208
235
  this.url = normalizedUrl;
209
236
  this.route = null;
210
237
  const pathname = new URL(this.url, this.getOrigin()).pathname;
211
- for (const route in this.routes) {
238
+ for (const route of Object.keys(this.routes)) {
212
239
  if (route === 'defaultRoute' || (pathname !== route && !pathname.startsWith(`${route}/`))) {
213
240
  continue;
214
241
  }
@@ -222,7 +249,11 @@ class Router {
222
249
  }
223
250
  if (this.route) {
224
251
  const selected = this.routes[this.route];
225
- if (typeof selected !== 'function' && selected.secure && selected.secure(this.scope, this.locationData) !== true) {
252
+ if ((typeof selected !== 'function' && selected.secure && selected.secure(this.scope, this.locationData) !== true) ||
253
+ !this.isRunnableRoute(selected)) {
254
+ this.url = previousUrl;
255
+ this.route = previousSelectedRoute;
256
+ this.locationData = previousLocationData;
226
257
  return false;
227
258
  }
228
259
  const previous = this.previousRoute ? this.routes[this.previousRoute] : undefined;
@@ -235,11 +266,8 @@ class Router {
235
266
  else if (typeof selected.view === 'function') {
236
267
  selected.view(this.scope, this.locationData);
237
268
  }
238
- else if (selected.view && typeof selected.view.initialize === 'function') {
239
- selected.view.initialize(this.scope, this.locationData);
240
- }
241
269
  else {
242
- return false;
270
+ selected.view.initialize(this.scope, this.locationData);
243
271
  }
244
272
  this.applyPageContext(selected);
245
273
  this.previousRoute = this.route;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"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AE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC5C,CAAC;iBAAM,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBAC7C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YACjD,CAAC;iBAAM,IAAI,QAAQ,CAAC,IAAI,IAAI,OAAO,QAAQ,CAAC,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;gBACzE,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC5D,CAAC;iBAAM,CAAC;gBACJ,OAAO,KAAK,CAAC;YACjB,CAAC;YACD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YAChC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE,CAAC;YACzC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AASD,iBAAS,MAAM,CAAC","sourcesContent":["/** Navigation payload, including caller-defined metadata. */\ninterface NavigationData {url?: string; [key: string]: unknown}\n/** URL-derived values supplied to route handlers. */\ninterface LocationData {url: string; data: {url: string[]; mediator: NavigationData | undefined; query: Record<string, string>}}\ntype RouteHandler = (scope: Element | null, location: LocationData) => unknown;\n/** An object route can own a function or a view lifecycle. */\ninterface RouteObject {title?: string; focus?: string | false; secure?: RouteHandler; view?: RouteHandler | {initialize?: RouteHandler; destroy?: RouteHandler}}\ntype Route = RouteHandler | RouteObject;\n/** Minimal event-bus contract required by the router. */\ninterface NavigationMediator {\n on(event: string, callback: (data?: NavigationData) => unknown): unknown;\n removeListener(event: string, callback: (data?: NavigationData) => unknown): unknown;\n}\n/** History API router that also dispatches request URLs in non-browser runtimes. */\nclass Router {\n routes: Record<string, Route>;\n url: string;\n route: string | null;\n scope: Element | null;\n previousRoute: string | null;\n pageTitle: string | null;\n mediator: NavigationMediator | false;\n boundPushStateClick: (event: MouseEvent) => unknown;\n boundPopState: (event: PopStateEvent) => unknown;\n boundMediatorNavigate: (data?: NavigationData) => unknown;\n listenersInitialized: boolean;\n locationData: LocationData = {url: '', data: {url: [], mediator: undefined, query: {}}};\n\n /** Create an instance with its own state and listener references. */\n constructor() {\n this.routes = {\n defaultRoute: {\n view: {\n initialize: () => true,\n destroy: () => true\n }\n }\n };\n this.url = '';\n this.route = null;\n this.scope = null;\n this.previousRoute = null;\n this.pageTitle = null;\n this.mediator = false;\n this.boundPushStateClick = this.eventPushStateClick.bind(this);\n this.boundPopState = this.eventPopState.bind(this);\n this.boundMediatorNavigate = (data = {}) => {\n this.navigate(data.url, data, false);\n };\n this.listenersInitialized = false;\n }\n\n /** True when browser navigation APIs are available. */\n private isBrowserRuntime() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n }\n\n /** Stable base URL for WHATWG URL parsing in browser and server runtimes. */\n private getOrigin() {\n return this.isBrowserRuntime() ? window.location.origin : 'http://white-label.invalid';\n }\n\n /** Read the authoritative browser URL, or retain the supplied server URL. */\n private getCurrentUrl() {\n if (!this.isBrowserRuntime()) {return this.url || '/';}\n return window.location.pathname + window.location.search + (window.location.hash || '');\n }\n\n /** Normalize browser navigation to a same-origin path, query, and hash. */\n private normalizeBrowserUrl(url: string) {\n if (!this.isBrowserRuntime()) {return url;}\n const parsedUrl = new URL(url || '/', window.location.href || `${window.location.origin}/`);\n if (parsedUrl.origin !== window.location.origin) {return null;}\n return `${parsedUrl.pathname}${parsedUrl.search}${parsedUrl.hash}`;\n }\n\n /**\n * Start this instance and return it for lifecycle chaining.\n * In a browser the URL is optional and defaults to window.location. On a server pass the request URL.\n */\n initialize(url?: string) {\n this.url = url ?? this.getCurrentUrl();\n this.addListeners();\n this.navigate(undefined, {}, true);\n return this;\n }\n\n /** Register browser and optional mediator handlers once. */\n addListeners() {\n if (this.listenersInitialized) {return this;}\n if (this.isBrowserRuntime()) {\n document.addEventListener('click', this.boundPushStateClick);\n window.addEventListener('popstate', this.boundPopState);\n }\n if (this.mediator) {this.mediator.on('router:navigate', this.boundMediatorNavigate);}\n this.listenersInitialized = true;\n return this;\n }\n\n /** Release owned state and listeners so the instance can leave the application lifecycle. */\n destroy() {\n this.removeListeners();\n return this;\n }\n\n /** Release listeners owned by this instance; subclasses may extend the lifecycle hook. */\n removeListeners() {\n if (!this.listenersInitialized) {return this;}\n if (this.isBrowserRuntime()) {\n document.removeEventListener('click', this.boundPushStateClick);\n window.removeEventListener('popstate', this.boundPopState);\n }\n if (this.mediator) {this.mediator.removeListener('router:navigate', this.boundMediatorNavigate);}\n this.listenersInitialized = false;\n return this;\n }\n\n /** Intercept eligible same-origin push-state links while preserving normal browser actions. */\n eventPushStateClick(e: MouseEvent) {\n if (typeof window === 'undefined') {return true;}\n if (e.defaultPrevented || (e.button !== undefined && e.button !== 0) || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {\n return true;\n }\n const eventTarget = e.target as Element | null;\n const source = eventTarget && (typeof eventTarget.closest === 'function' ? eventTarget : eventTarget.parentElement);\n const anchor = source && typeof source.closest === 'function' ? source.closest('a[href][data-pushstate]') : null;\n if (!anchor) {return true;}\n const target = anchor.getAttribute('target');\n if (anchor.hasAttribute('download') || (target && target.toLowerCase() !== '_self')) {return true;}\n const location = new URL(anchor.getAttribute('href') || '', window.location.href || `${window.location.origin}/`);\n if (location.origin !== window.location.origin) {return true;}\n e.preventDefault();\n this.url = `${location.pathname}${location.search}${location.hash}`;\n this.navigate(undefined, {}, false);\n return this;\n }\n\n /** Restore browser history state without adding a new history entry. */\n eventPopState() {\n if (typeof window === 'undefined') {return this;}\n this.url = this.getCurrentUrl();\n this.navigate(undefined, {}, true);\n return this;\n }\n\n /** Decode URL query parameters, keeping the last value for duplicate keys. */\n parseQueryString(queryString: string) {\n return Object.fromEntries(new URLSearchParams(queryString));\n }\n\n /** Build decoded path, query, and mediator data for the selected route. */\n setLocationData(mediatorData?: NavigationData) {\n const parsedUrl = new URL(this.url || '/', this.getOrigin());\n const matchedRoute = this.route && this.route !== 'defaultRoute' ? this.route : '';\n this.locationData = {\n url: this.url,\n data: {url: [], mediator: mediatorData, query: {}}\n };\n this.locationData.data.url = parsedUrl.pathname\n .slice(matchedRoute.length)\n .split('/')\n .filter(Boolean)\n .map((fragment) => {\n try {return decodeURIComponent(fragment);} catch (_error) {return fragment;}\n });\n this.locationData.data.query = this.parseQueryString(parsedUrl.search);\n }\n\n /** Update page context after a route renders. DOM effects are browser-only. */\n applyPageContext(route: Route) {\n if (typeof route === 'function') {\n this.pageTitle = null;\n return this;\n }\n this.pageTitle = typeof route.title === 'string' ? route.title : null;\n if (!this.isBrowserRuntime()) {return this;}\n if (this.pageTitle) {document.title = this.pageTitle;}\n if (route.focus !== false) {\n const target = document.querySelector<HTMLElement>(route.focus || 'main h1');\n if (target) {\n if (!target.hasAttribute('tabindex')) {target.setAttribute('tabindex', '-1');}\n target.focus();\n }\n }\n return this;\n }\n\n /** Select a route, enforce its guard, transition view lifecycles, and update browser history when available. */\n navigate(url?: string, mediatorData?: NavigationData, isPopState = false) {\n if (url !== undefined) {this.url = url;}\n if (!this.url) {this.url = this.getCurrentUrl();}\n const normalizedUrl = this.normalizeBrowserUrl(this.url);\n if (normalizedUrl === null) {return false;}\n this.url = normalizedUrl;\n this.route = null;\n const pathname = new URL(this.url, this.getOrigin()).pathname;\n for (const route in this.routes) {\n if (route === 'defaultRoute' || (pathname !== route && !pathname.startsWith(`${route}/`))) {continue;}\n if (!this.route || route.length > this.route.length) {this.route = route;}\n }\n this.setLocationData(mediatorData);\n if (!this.route && this.routes.defaultRoute) {this.route = 'defaultRoute';}\n if (this.route) {\n const selected = this.routes[this.route]!;\n if (typeof selected !== 'function' && selected.secure && selected.secure(this.scope, this.locationData) !== true) {\n return false;\n }\n const previous = this.previousRoute ? this.routes[this.previousRoute] : undefined;\n if (previous && typeof previous !== 'function' && typeof previous.view === 'object' && previous.view.destroy) {\n previous.view.destroy(this.scope, this.locationData);\n }\n if (typeof selected === 'function') {\n selected(this.scope, this.locationData);\n } else if (typeof selected.view === 'function') {\n selected.view(this.scope, this.locationData);\n } else if (selected.view && typeof selected.view.initialize === 'function') {\n selected.view.initialize(this.scope, this.locationData);\n } else {\n return false;\n }\n this.applyPageContext(selected);\n this.previousRoute = this.route;\n }\n if (!isPopState && this.isBrowserRuntime()) {\n window.history.pushState(this.url, this.pageTitle || '', this.url);\n }\n return this;\n }\n}\n\n/** Public route configuration and navigation payload types. */\nnamespace Router {\n export type Handler = RouteHandler;\n export type Route = RouteHandler | RouteObject;\n export type Location = LocationData;\n export type Navigation = NavigationData;\n}\nexport = Router;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAaA,oFAAoF;AACpF,MAAM,MAAM;IACR,MAAM,CAAwB;IAC9B,GAAG,CAAS;IACZ,KAAK,CAAgB;IACrB,KAAK,CAAiB;IACtB,aAAa,CAAgB;IAC7B,SAAS,CAAgB;IACzB,mBAAmB,CAAiC;IACpD,aAAa,CAAoC;IACjD,qBAAqB,CAAgB;IACrC,oBAAoB,CAAU;IAC9B,YAAY,GAAiB,EAAC,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAC,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAC,EAAC,CAAC;IAChF,eAAe,GAA+B,KAAK,CAAC;IACpD,aAAa,GAA+B,KAAK,CAAC;IAE1D,qEAAqE;IACrE;QACI,IAAI,CAAC,MAAM,GAAG;YACV,YAAY,EAAE;gBACV,IAAI,EAAE;oBACF,UAAU,EAAE,GAA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AAK,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE,CAAC;YACzC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AASD,iBAAS,MAAM,CAAC","sourcesContent":["/** Navigation payload, including caller-defined metadata. */\ninterface NavigationData {url?: string; [key: string]: unknown}\n/** URL-derived values supplied to route handlers. */\ninterface LocationData {url: string; data: {url: string[]; mediator: NavigationData | undefined; query: Record<string, string>}}\ntype RouteHandler = (scope: Element | null, location: LocationData) => unknown;\n/** An object route can own a function or a view lifecycle. */\ninterface RouteObject {title?: string; focus?: string | false; secure?: RouteHandler; view?: RouteHandler | {initialize?: RouteHandler; destroy?: RouteHandler}}\ntype Route = RouteHandler | RouteObject;\n/** Minimal standards-based event target contract required by the router. */\ninterface NavigationMediator {\n addEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n removeEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;\n}\n/** History API router that also dispatches request URLs in non-browser runtimes. */\nclass Router {\n routes: Record<string, Route>;\n url: string;\n route: string | null;\n scope: Element | null;\n previousRoute: string | null;\n pageTitle: string | null;\n boundPushStateClick: (event: MouseEvent) => unknown;\n boundPopState: (event: PopStateEvent) => unknown;\n boundMediatorNavigate: EventListener;\n listenersInitialized: boolean;\n locationData: LocationData = {url: '', data: {url: [], mediator: undefined, query: {}}};\n private currentMediator: NavigationMediator | false = false;\n private boundMediator: NavigationMediator | false = false;\n\n /** Create an instance with its own state and listener references. */\n constructor() {\n this.routes = {\n defaultRoute: {\n view: {\n initialize: () => true,\n destroy: () => true\n }\n }\n };\n this.url = '';\n this.route = null;\n this.scope = null;\n this.previousRoute = null;\n this.pageTitle = null;\n this.boundPushStateClick = this.eventPushStateClick.bind(this);\n this.boundPopState = this.eventPopState.bind(this);\n this.boundMediatorNavigate = (event: Event) => {\n const data = (event as CustomEvent<NavigationData | undefined>).detail ?? {};\n this.navigate(data.url, data, false);\n };\n this.listenersInitialized = false;\n }\n\n get mediator(): NavigationMediator | false {return this.currentMediator;}\n\n /** Move an active router:navigate subscription when the mediator changes. */\n set mediator(value: NavigationMediator | false) {\n if (value === this.currentMediator) {return;}\n if (this.listenersInitialized && this.boundMediator) {\n this.boundMediator.removeEventListener('router:navigate', this.boundMediatorNavigate);\n this.boundMediator = false;\n }\n this.currentMediator = value;\n if (this.listenersInitialized && value) {\n value.addEventListener('router:navigate', this.boundMediatorNavigate);\n this.boundMediator = value;\n }\n }\n\n /** True when browser navigation APIs are available. */\n private isBrowserRuntime() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n }\n\n /** Stable base URL for WHATWG URL parsing in browser and server runtimes. */\n private getOrigin() {\n return this.isBrowserRuntime() ? window.location.origin : 'http://white-label.invalid';\n }\n\n /** Read the authoritative browser URL, or retain the supplied server URL. */\n private getCurrentUrl() {\n if (!this.isBrowserRuntime()) {return this.url || '/';}\n return window.location.pathname + window.location.search + (window.location.hash || '');\n }\n\n /** Normalize browser navigation to a same-origin path, query, and hash. */\n private normalizeBrowserUrl(url: string) {\n if (!this.isBrowserRuntime()) {return url;}\n const parsedUrl = new URL(url || '/', window.location.href || `${window.location.origin}/`);\n if (parsedUrl.origin !== window.location.origin) {return null;}\n return `${parsedUrl.pathname}${parsedUrl.search}${parsedUrl.hash}`;\n }\n\n /** Return whether a selected route has runnable view behavior. */\n private isRunnableRoute(route: Route): boolean {\n return typeof route === 'function' || typeof route.view === 'function' ||\n Boolean(route.view && typeof route.view.initialize === 'function');\n }\n\n /**\n * Start this instance and return it for lifecycle chaining.\n * In a browser the URL is optional and defaults to window.location. On a server pass the request URL.\n */\n initialize(url?: string) {\n this.url = url ?? this.getCurrentUrl();\n this.addListeners();\n this.navigate(undefined, {}, true);\n return this;\n }\n\n /** Register browser and optional mediator handlers once. */\n addListeners() {\n if (this.listenersInitialized) {return this;}\n if (this.isBrowserRuntime()) {\n document.addEventListener('click', this.boundPushStateClick);\n window.addEventListener('popstate', this.boundPopState);\n }\n if (this.currentMediator) {\n this.currentMediator.addEventListener('router:navigate', this.boundMediatorNavigate);\n this.boundMediator = this.currentMediator;\n }\n this.listenersInitialized = true;\n return this;\n }\n\n /** Release owned state and listeners so the instance can leave the application lifecycle. */\n destroy() {\n this.removeListeners();\n return this;\n }\n\n /** Release listeners owned by this instance; subclasses may extend the lifecycle hook. */\n removeListeners() {\n if (!this.listenersInitialized) {return this;}\n if (this.isBrowserRuntime()) {\n document.removeEventListener('click', this.boundPushStateClick);\n window.removeEventListener('popstate', this.boundPopState);\n }\n if (this.boundMediator) {\n this.boundMediator.removeEventListener('router:navigate', this.boundMediatorNavigate);\n this.boundMediator = false;\n }\n this.listenersInitialized = false;\n return this;\n }\n\n /** Intercept eligible same-origin push-state links while preserving normal browser actions. */\n eventPushStateClick(e: MouseEvent) {\n if (typeof window === 'undefined') {return true;}\n if (e.defaultPrevented || (e.button !== undefined && e.button !== 0) || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {\n return true;\n }\n const eventTarget = e.target as Element | null;\n const source = eventTarget && (typeof eventTarget.closest === 'function' ? eventTarget : eventTarget.parentElement);\n const anchor = source && typeof source.closest === 'function' ? source.closest('a[href][data-pushstate]') : null;\n if (!anchor) {return true;}\n const target = anchor.getAttribute('target');\n if (anchor.hasAttribute('download') || (target && target.toLowerCase() !== '_self')) {return true;}\n const location = new URL(anchor.getAttribute('href') || '', window.location.href || `${window.location.origin}/`);\n if (location.origin !== window.location.origin) {return true;}\n e.preventDefault();\n this.navigate(`${location.pathname}${location.search}${location.hash}`, {}, false);\n return this;\n }\n\n /** Restore browser history state without adding a new history entry. */\n eventPopState() {\n if (typeof window === 'undefined') {return this;}\n this.url = this.getCurrentUrl();\n this.navigate(undefined, {}, true);\n return this;\n }\n\n /** Decode URL query parameters, keeping the last value for duplicate keys. */\n parseQueryString(queryString: string) {\n return Object.fromEntries(new URLSearchParams(queryString));\n }\n\n /** Build decoded path, query, and mediator data for the selected route. */\n setLocationData(mediatorData?: NavigationData) {\n const parsedUrl = new URL(this.url || '/', this.getOrigin());\n const matchedRoute = this.route && this.route !== 'defaultRoute' ? this.route : '';\n this.locationData = {\n url: this.url,\n data: {url: [], mediator: mediatorData, query: {}}\n };\n this.locationData.data.url = parsedUrl.pathname\n .slice(matchedRoute.length)\n .split('/')\n .filter(Boolean)\n .map((fragment) => {\n try {return decodeURIComponent(fragment);} catch (_error) {return fragment;}\n });\n this.locationData.data.query = this.parseQueryString(parsedUrl.search);\n }\n\n /** Update page context after a route renders. DOM effects are browser-only. */\n applyPageContext(route: Route) {\n if (typeof route === 'function') {\n this.pageTitle = null;\n return this;\n }\n this.pageTitle = typeof route.title === 'string' ? route.title : null;\n if (!this.isBrowserRuntime()) {return this;}\n if (this.pageTitle) {document.title = this.pageTitle;}\n if (route.focus !== false) {\n const target = document.querySelector<HTMLElement>(route.focus || 'main h1');\n if (target) {\n if (!target.hasAttribute('tabindex')) {target.setAttribute('tabindex', '-1');}\n target.focus();\n }\n }\n return this;\n }\n\n /** Select a route, enforce its guard, transition view lifecycles, and update browser history when available. */\n navigate(url?: string, mediatorData?: NavigationData, isPopState = false) {\n const previousUrl = this.url;\n const previousSelectedRoute = this.route;\n const previousLocationData = this.locationData;\n if (url !== undefined) {this.url = url;}\n if (!this.url) {this.url = this.getCurrentUrl();}\n const normalizedUrl = this.normalizeBrowserUrl(this.url);\n if (normalizedUrl === null) {\n this.url = previousUrl;\n return false;\n }\n this.url = normalizedUrl;\n this.route = null;\n const pathname = new URL(this.url, this.getOrigin()).pathname;\n for (const route of Object.keys(this.routes)) {\n if (route === 'defaultRoute' || (pathname !== route && !pathname.startsWith(`${route}/`))) {continue;}\n if (!this.route || route.length > this.route.length) {this.route = route;}\n }\n this.setLocationData(mediatorData);\n if (!this.route && this.routes.defaultRoute) {this.route = 'defaultRoute';}\n if (this.route) {\n const selected = this.routes[this.route]!;\n if ((typeof selected !== 'function' && selected.secure && selected.secure(this.scope, this.locationData) !== true) ||\n !this.isRunnableRoute(selected)) {\n this.url = previousUrl;\n this.route = previousSelectedRoute;\n this.locationData = previousLocationData;\n return false;\n }\n const previous = this.previousRoute ? this.routes[this.previousRoute] : undefined;\n if (previous && typeof previous !== 'function' && typeof previous.view === 'object' && previous.view.destroy) {\n previous.view.destroy(this.scope, this.locationData);\n }\n if (typeof selected === 'function') {\n selected(this.scope, this.locationData);\n } else if (typeof selected.view === 'function') {\n selected.view(this.scope, this.locationData);\n } else {\n selected.view!.initialize!(this.scope, this.locationData);\n }\n this.applyPageContext(selected);\n this.previousRoute = this.route;\n }\n if (!isPopState && this.isBrowserRuntime()) {\n window.history.pushState(this.url, this.pageTitle || '', this.url);\n }\n return this;\n }\n}\n\n/** Public route configuration and navigation payload types. */\nnamespace Router {\n export type Handler = RouteHandler;\n export type Route = RouteHandler | RouteObject;\n export type Location = LocationData;\n export type Navigation = NavigationData;\n}\nexport = Router;\n"]}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "white-label-router",
3
- "version": "5.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "Framework-independent TypeScript router for browser, server, and request-scoped Node.js functions with progressive enhancement, guards, and accessible navigation.",
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",
9
- "README.md"
9
+ "README.md",
10
+ "PACKAGE_MANAGERS.md"
10
11
  ],
11
12
  "engines": {
12
13
  "node": "^22.18.0 || >=24.11.0"