@esmx/router 3.0.0-rc.55 → 3.0.0-rc.57

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/dist/matcher.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import type { RouteConfig, RouteMatcher } from './types';
2
- export declare function createMatcher(routes: RouteConfig[]): RouteMatcher;
1
+ import type { RouteConfig, RouteMatcher, RouteParsedConfig } from './types';
2
+ export declare function createMatcher(routes: RouteConfig[], compiledRoutes?: RouteParsedConfig[]): RouteMatcher;
3
+ export declare function createRouteMatches(routes: RouteConfig[], base?: string): RouteParsedConfig[];
3
4
  export declare function joinPathname(pathname: string, base?: string): string;
package/dist/matcher.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { compile, match } from "path-to-regexp";
2
- export function createMatcher(routes) {
3
- const compiledRoutes = createRouteMatches(routes);
2
+ export function createMatcher(routes, compiledRoutes = createRouteMatches(routes)) {
4
3
  return (toURL, baseURL, cb) => {
5
4
  const matchPath = toURL.pathname.substring(baseURL.pathname.length - 1);
6
5
  const matches = [];
@@ -29,7 +28,7 @@ export function createMatcher(routes) {
29
28
  return { matches: Object.freeze(matches), params };
30
29
  };
31
30
  }
32
- function createRouteMatches(routes, base = "") {
31
+ export function createRouteMatches(routes, base = "") {
33
32
  return routes.map((route) => {
34
33
  const compilePath = joinPathname(route.path, base);
35
34
  return {
package/dist/options.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createMatcher } from "./matcher.mjs";
1
+ import { createMatcher, createRouteMatches } from "./matcher.mjs";
2
2
  import { RouterMode } from "./types.mjs";
3
3
  import { isBrowser } from "./util.mjs";
4
4
  function getBaseUrl(options) {
@@ -33,6 +33,7 @@ export function parsedOptions(options = {}) {
33
33
  var _a, _b, _c, _d, _e, _f;
34
34
  const base = getBaseUrl(options);
35
35
  const routes = (_a = options.routes) != null ? _a : [];
36
+ const compiledRoutes = createRouteMatches(routes);
36
37
  return Object.freeze({
37
38
  rootStyle: options.rootStyle || false,
38
39
  root: options.root || "",
@@ -45,7 +46,8 @@ export function parsedOptions(options = {}) {
45
46
  mode: isBrowser ? (_b = options.mode) != null ? _b : RouterMode.history : RouterMode.memory,
46
47
  routes,
47
48
  apps: typeof options.apps === "function" ? options.apps : Object.assign({}, options.apps),
48
- matcher: createMatcher(routes),
49
+ compiledRoutes,
50
+ matcher: createMatcher(routes, compiledRoutes),
49
51
  normalizeURL: (_c = options.normalizeURL) != null ? _c : (url) => url,
50
52
  fallback: (_d = options.fallback) != null ? _d : fallback,
51
53
  handleBackBoundary: (_e = options.handleBackBoundary) != null ? _e : () => {
package/dist/router.mjs CHANGED
@@ -213,8 +213,6 @@ export class Router {
213
213
  promiseResolve = resolve;
214
214
  });
215
215
  const router = new Router({
216
- ...this.options,
217
- mode: RouterMode.memory,
218
216
  rootStyle: {
219
217
  position: "fixed",
220
218
  top: "0",
@@ -227,6 +225,8 @@ export class Router {
227
225
  alignItems: "center",
228
226
  justifyContent: "center"
229
227
  },
228
+ ...this.options,
229
+ mode: RouterMode.memory,
230
230
  root: void 0,
231
231
  ...layerOptions.routerOptions,
232
232
  handleBackBoundary(router2) {
package/dist/types.d.ts CHANGED
@@ -194,13 +194,14 @@ export interface RouterOptions {
194
194
  apps?: RouterMicroApp;
195
195
  normalizeURL?: (to: URL, from: URL | null) => URL;
196
196
  fallback?: RouteHandleHook;
197
- rootStyle?: Partial<CSSStyleDeclaration> | false;
197
+ rootStyle?: Partial<CSSStyleDeclaration> | false | null;
198
198
  layer?: boolean;
199
199
  zIndex?: number;
200
200
  handleBackBoundary?: (router: Router) => void;
201
201
  handleLayerClose?: (router: Router, data?: any) => void;
202
202
  }
203
203
  export interface RouterParsedOptions extends Readonly<Required<RouterOptions>> {
204
+ readonly compiledRoutes: readonly RouteParsedConfig[];
204
205
  readonly matcher: RouteMatcher;
205
206
  }
206
207
  /**
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "template": "library",
4
4
  "scripts": {
5
5
  "lint:js": "biome check --write --no-errors-on-unmatched",
6
- "lint:css": "npm run lint:js",
6
+ "lint:css": "pnpm run lint:js",
7
7
  "lint:type": "tsc --noEmit",
8
8
  "test": "vitest run --pass-with-no-tests",
9
9
  "coverage": "vitest run --coverage --pass-with-no-tests",
@@ -35,11 +35,11 @@
35
35
  "@types/node": "^24.0.0",
36
36
  "@vitest/coverage-v8": "3.2.4",
37
37
  "happy-dom": "^18.0.1",
38
- "typescript": "5.8.3",
39
- "unbuild": "3.5.0",
38
+ "typescript": "5.9.2",
39
+ "unbuild": "3.6.0",
40
40
  "vitest": "3.2.4"
41
41
  },
42
- "version": "3.0.0-rc.55",
42
+ "version": "3.0.0-rc.57",
43
43
  "type": "module",
44
44
  "private": false,
45
45
  "exports": {
@@ -58,5 +58,5 @@
58
58
  "template",
59
59
  "public"
60
60
  ],
61
- "gitHead": "e7d0c88a376ad5bd3d88a48240e4ed4891c0b275"
61
+ "gitHead": "bb3fbfa6de4906b7e98bc387c3e1d8e0c3164ac7"
62
62
  }
package/src/matcher.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { compile, match } from 'path-to-regexp';
2
2
  import type { RouteConfig, RouteMatcher, RouteParsedConfig } from './types';
3
3
 
4
- export function createMatcher(routes: RouteConfig[]): RouteMatcher {
5
- const compiledRoutes = createRouteMatches(routes);
4
+ export function createMatcher(
5
+ routes: RouteConfig[],
6
+ compiledRoutes = createRouteMatches(routes)
7
+ ): RouteMatcher {
6
8
  return (
7
9
  toURL: URL,
8
10
  baseURL: URL,
@@ -42,7 +44,7 @@ export function createMatcher(routes: RouteConfig[]): RouteMatcher {
42
44
  };
43
45
  }
44
46
 
45
- function createRouteMatches(
47
+ export function createRouteMatches(
46
48
  routes: RouteConfig[],
47
49
  base = ''
48
50
  ): RouteParsedConfig[] {
package/src/options.ts CHANGED
@@ -1,12 +1,7 @@
1
- import { createMatcher } from './matcher';
1
+ import { createMatcher, createRouteMatches } from './matcher';
2
2
  import type { Router } from './router';
3
3
  import { RouterMode } from './types';
4
- import type {
5
- Route,
6
- RouteConfig,
7
- RouterOptions,
8
- RouterParsedOptions
9
- } from './types';
4
+ import type { Route, RouterOptions, RouterParsedOptions } from './types';
10
5
  import { isBrowser } from './util';
11
6
 
12
7
  /**
@@ -66,6 +61,7 @@ export function parsedOptions(
66
61
  ): RouterParsedOptions {
67
62
  const base = getBaseUrl(options);
68
63
  const routes = options.routes ?? [];
64
+ const compiledRoutes = createRouteMatches(routes);
69
65
  return Object.freeze<RouterParsedOptions>({
70
66
  rootStyle: options.rootStyle || false,
71
67
  root: options.root || '',
@@ -83,7 +79,8 @@ export function parsedOptions(
83
79
  typeof options.apps === 'function'
84
80
  ? options.apps
85
81
  : Object.assign({}, options.apps),
86
- matcher: createMatcher(routes),
82
+ compiledRoutes,
83
+ matcher: createMatcher(routes, compiledRoutes),
87
84
  normalizeURL: options.normalizeURL ?? ((url) => url),
88
85
  fallback: options.fallback ?? fallback,
89
86
  handleBackBoundary: options.handleBackBoundary ?? (() => {}),
package/src/router.ts CHANGED
@@ -244,8 +244,6 @@ export class Router {
244
244
  });
245
245
 
246
246
  const router = new Router({
247
- ...this.options,
248
- mode: RouterMode.memory,
249
247
  rootStyle: {
250
248
  position: 'fixed',
251
249
  top: '0',
@@ -258,6 +256,8 @@ export class Router {
258
256
  alignItems: 'center',
259
257
  justifyContent: 'center'
260
258
  },
259
+ ...this.options,
260
+ mode: RouterMode.memory,
261
261
  root: undefined,
262
262
  ...layerOptions.routerOptions,
263
263
  handleBackBoundary(router) {
package/src/types.ts CHANGED
@@ -267,7 +267,7 @@ export interface RouterOptions {
267
267
  normalizeURL?: (to: URL, from: URL | null) => URL;
268
268
  fallback?: RouteHandleHook;
269
269
 
270
- rootStyle?: Partial<CSSStyleDeclaration> | false;
270
+ rootStyle?: Partial<CSSStyleDeclaration> | false | null;
271
271
  layer?: boolean;
272
272
  zIndex?: number;
273
273
  handleBackBoundary?: (router: Router) => void;
@@ -275,6 +275,7 @@ export interface RouterOptions {
275
275
  }
276
276
 
277
277
  export interface RouterParsedOptions extends Readonly<Required<RouterOptions>> {
278
+ readonly compiledRoutes: readonly RouteParsedConfig[];
278
279
  readonly matcher: RouteMatcher;
279
280
  }
280
281