@teyik0/furin 0.2.0-alpha.2 → 0.2.0-alpha.3

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.
Files changed (132) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +33 -33
  3. package/dist/adapter/bun.d.ts +3 -0
  4. package/dist/adapter/static.d.ts +3 -0
  5. package/dist/build/client.d.ts +25 -0
  6. package/dist/build/compile-entry.d.ts +9 -0
  7. package/dist/build/compile-entry.ts +109 -0
  8. package/dist/build/entry-template.d.ts +38 -0
  9. package/dist/build/entry-template.ts +156 -0
  10. package/dist/build/hydrate.d.ts +24 -0
  11. package/dist/build/index.d.ts +8 -0
  12. package/dist/build/index.js +8106 -0
  13. package/dist/build/route-types.d.ts +23 -0
  14. package/dist/build/scan-server.d.ts +8 -0
  15. package/dist/build/server-routes-entry.d.ts +13 -0
  16. package/dist/build/server-routes-entry.ts +36 -0
  17. package/dist/build/shared.d.ts +12 -0
  18. package/dist/build/ssg-cache.d.ts +4 -0
  19. package/dist/build/types.d.ts +80 -0
  20. package/dist/cli/config.d.ts +9 -0
  21. package/dist/cli/index.d.ts +2 -0
  22. package/dist/cli/index.js +8097 -0
  23. package/dist/client/boundaries.d.ts +117 -0
  24. package/dist/client/default-screens.d.ts +17 -0
  25. package/dist/client/link.d.ts +22 -0
  26. package/dist/client/link.js +4244 -0
  27. package/dist/client/router/boundary-tree.d.ts +26 -0
  28. package/dist/client/router/context.d.ts +8 -0
  29. package/dist/client/router/history.d.ts +9 -0
  30. package/dist/client/router/index.d.ts +11 -0
  31. package/dist/client/router/link-utils.d.ts +53 -0
  32. package/dist/client/router/navigation.d.ts +10 -0
  33. package/dist/client/router/provider.d.ts +4 -0
  34. package/dist/client/router/search/index.d.ts +18 -0
  35. package/dist/client/router/search-store.d.ts +21 -0
  36. package/dist/client/router/spa-response.d.ts +58 -0
  37. package/dist/client/router/types.d.ts +292 -0
  38. package/dist/client/server-error.d.ts +12 -0
  39. package/dist/client/sync.d.ts +25 -0
  40. package/dist/client.d.ts +243 -0
  41. package/dist/client.js +140 -0
  42. package/dist/config.d.ts +57 -0
  43. package/dist/config.js +29 -0
  44. package/dist/env.d.ts +50 -0
  45. package/dist/furin.d.ts +77 -0
  46. package/dist/furin.js +8693 -0
  47. package/dist/plugin/index.d.ts +20 -0
  48. package/dist/plugin/index.js +1500 -0
  49. package/dist/plugin/transform-client.d.ts +10 -0
  50. package/dist/server/auto-invalidate/index.d.ts +4 -0
  51. package/dist/server/auto-invalidate/plugin.d.ts +38 -0
  52. package/dist/server/auto-invalidate/registry.d.ts +9 -0
  53. package/dist/server/auto-invalidate/runtime.d.ts +9 -0
  54. package/dist/server/auto-invalidate/types.d.ts +12 -0
  55. package/dist/server/cache/dev-loader.d.ts +28 -0
  56. package/dist/server/cache/index.d.ts +10 -0
  57. package/dist/server/cache/invalidation.d.ts +12 -0
  58. package/dist/server/cache/isr-ssg.d.ts +26 -0
  59. package/dist/server/cache/isr.d.ts +6 -0
  60. package/dist/server/cache/registry.d.ts +5 -0
  61. package/dist/server/cache/route-cache.d.ts +26 -0
  62. package/dist/server/cache/ssg.d.ts +5 -0
  63. package/dist/server/context-logger.d.ts +28 -0
  64. package/dist/server/dev-inspector.d.ts +89 -0
  65. package/dist/server/dev-page-plugin.d.ts +112 -0
  66. package/dist/server/internal.d.ts +35 -0
  67. package/dist/server/internal.js +17 -0
  68. package/dist/server/lang-detect.d.ts +5 -0
  69. package/dist/server/render/assemble.d.ts +49 -0
  70. package/dist/server/render/element.d.ts +24 -0
  71. package/dist/server/render/index.d.ts +7 -0
  72. package/dist/server/render/index.ts +22 -0
  73. package/dist/server/render/isr.d.ts +4 -0
  74. package/dist/server/render/loaders.d.ts +64 -0
  75. package/dist/server/render/not-found.d.ts +6 -0
  76. package/dist/server/render/shell.d.ts +39 -0
  77. package/dist/server/render/shell.ts +202 -0
  78. package/dist/server/render/ssg.d.ts +9 -0
  79. package/dist/server/render/ssr.d.ts +108 -0
  80. package/dist/server/render/template.d.ts +6 -0
  81. package/dist/server/router/discovery.d.ts +16 -0
  82. package/dist/server/router/hmr.d.ts +65 -0
  83. package/dist/server/router/index.d.ts +6 -0
  84. package/dist/server/router/index.js +27 -0
  85. package/dist/server/router/index.ts +28 -0
  86. package/dist/server/router/patterns.d.ts +40 -0
  87. package/dist/server/router/plugin.d.ts +21 -0
  88. package/dist/server/router/schemas.d.ts +59 -0
  89. package/dist/server/router/types.d.ts +60 -0
  90. package/dist/server/runtime-env.d.ts +3 -0
  91. package/dist/server/runtime-env.js +10 -0
  92. package/dist/server/sync/config.d.ts +6 -0
  93. package/dist/server/sync/index.d.ts +4 -0
  94. package/dist/server/sync/plugin.d.ts +369 -0
  95. package/dist/server/sync/stream.d.ts +47 -0
  96. package/dist/shared/await.d.ts +67 -0
  97. package/dist/shared/deferred-ndjson.d.ts +32 -0
  98. package/dist/shared/digest.d.ts +16 -0
  99. package/dist/shared/error.d.ts +37 -0
  100. package/dist/shared/not-found.d.ts +19 -0
  101. package/dist/shared/search-params.d.ts +17 -0
  102. package/dist/shared/utils/ast-walk.d.ts +18 -0
  103. package/dist/shared/utils/index.d.ts +13 -0
  104. package/package.json +5 -5
  105. package/src/adapter/README.md +13 -13
  106. package/src/build/client.ts +152 -152
  107. package/src/build/compile-entry.ts +109 -109
  108. package/src/build/entry-template.ts +156 -156
  109. package/src/build/hydrate.ts +340 -337
  110. package/src/build/index.ts +152 -152
  111. package/src/build/route-types.ts +145 -145
  112. package/src/build/scan-server.ts +95 -95
  113. package/src/build/server-routes-entry.ts +36 -36
  114. package/src/build/shared.ts +80 -79
  115. package/src/build/ssg-cache.ts +32 -32
  116. package/src/build/types.ts +89 -89
  117. package/src/client/router/link-utils.ts +184 -177
  118. package/src/client/router/provider.tsx +804 -759
  119. package/src/client/router/types.ts +276 -271
  120. package/src/client/sync.ts +98 -0
  121. package/src/client.ts +369 -355
  122. package/src/furin.ts +465 -444
  123. package/src/server/auto-invalidate/runtime.ts +134 -133
  124. package/src/server/dev-page-plugin.ts +454 -449
  125. package/src/server/render/assemble.ts +160 -133
  126. package/src/server/render/isr.ts +323 -317
  127. package/src/server/render/ssr.ts +585 -583
  128. package/src/server/router/plugin.ts +384 -384
  129. package/src/server/sync/config.ts +29 -0
  130. package/src/server/sync/index.ts +14 -0
  131. package/src/server/sync/plugin.ts +108 -0
  132. package/src/server/sync/stream.ts +144 -0
@@ -1,89 +1,89 @@
1
- import type { BuildTarget, StaticExportConfig } from "../config";
2
- import type { ResolvedRoute } from "../server/router/index.ts";
3
-
4
- export interface BuildClientOptions {
5
- /**
6
- * Sub-path prefix for the deployment (e.g. "/furin" for GitHub Pages).
7
- * Passed through to the generated hydrate entry so SPA navigation uses
8
- * correct physical URLs. Pass "" for root deployments.
9
- */
10
- basePath: string;
11
- /** Inject the evlog client logger into the hydrate entry. Off by default. */
12
- clientLogging: boolean;
13
- outDir: string;
14
- pagesDir?: string;
15
- plugins?: Bun.BunPlugin[];
16
- /**
17
- * Public path prefix for all emitted JS/CSS chunks.
18
- * Pass "/_client/" for root deployments; override for basePath deployments,
19
- * e.g. "/furin/_client/".
20
- */
21
- publicPath: string;
22
- rootLayout: string;
23
- }
24
-
25
- export interface BuildRouteManifestEntry {
26
- hasLayout: boolean;
27
- hasStaticParams: boolean;
28
- mode: ResolvedRoute["mode"];
29
- pagePath: string;
30
- pattern: string;
31
- revalidate: number | null;
32
- }
33
-
34
- export interface TargetBuildManifest {
35
- buildId: string;
36
- clientDir: string | null;
37
- generatedAt: string;
38
- serverEntry: string | null;
39
- serverPath: string | null;
40
- targetDir: string;
41
- templatePath: string | null;
42
- }
43
-
44
- export type AnyTargetManifest = TargetBuildManifest | StaticTargetBuildManifest;
45
-
46
- export interface BuildManifest {
47
- generatedAt: string;
48
- pagesDir: string;
49
- rootDir: string;
50
- rootPath: string;
51
- routes: BuildRouteManifestEntry[];
52
- serverEntry: string | null;
53
- targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
54
- version: 1;
55
- }
56
-
57
- export interface BuildAppOptions {
58
- /** Inject the evlog client logger into the hydrate entry. Defaults to false. */
59
- clientLogging?: boolean;
60
- compile?: "server" | "embed";
61
- pagesDir?: string;
62
- plugins?: Bun.BunPlugin[];
63
- rootDir?: string;
64
- serverEntry?: string;
65
- /** Configuration for the `static` build target. */
66
- staticConfig?: StaticExportConfig;
67
- target: BuildTarget | "all";
68
- }
69
-
70
- /** Build manifest entry produced by the `static` adapter. */
71
- export interface StaticTargetBuildManifest {
72
- basePath: string;
73
- generatedAt: string;
74
- outDir: string;
75
- renderedRoutes: string[];
76
- skippedRoutes: string[];
77
- }
78
-
79
- export interface BuildAppResult {
80
- manifest: BuildManifest;
81
- targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
82
- }
83
-
84
- export type BunBuildAliasConfig = Bun.BuildConfig & {
85
- alias?: Record<string, string>;
86
- outfile?: string;
87
- packages?: "bundle" | "external";
88
- write?: boolean;
89
- };
1
+ import type { BuildTarget, StaticExportConfig } from "../config";
2
+ import type { ResolvedRoute } from "../server/router/index.ts";
3
+
4
+ export interface BuildClientOptions {
5
+ /**
6
+ * Sub-path prefix for the deployment (e.g. "/furin" for GitHub Pages).
7
+ * Passed through to the generated hydrate entry so SPA navigation uses
8
+ * correct physical URLs. Pass "" for root deployments.
9
+ */
10
+ basePath: string;
11
+ /** Inject the evlog client logger into the hydrate entry. Off by default. */
12
+ clientLogging: boolean;
13
+ outDir: string;
14
+ pagesDir?: string;
15
+ plugins?: Bun.BunPlugin[];
16
+ /**
17
+ * Public path prefix for all emitted JS/CSS chunks.
18
+ * Pass "/_client/" for root deployments; override for basePath deployments,
19
+ * e.g. "/furin/_client/".
20
+ */
21
+ publicPath: string;
22
+ rootLayout: string;
23
+ }
24
+
25
+ export interface BuildRouteManifestEntry {
26
+ hasLayout: boolean;
27
+ hasStaticParams: boolean;
28
+ mode: ResolvedRoute["mode"];
29
+ pagePath: string;
30
+ pattern: string;
31
+ revalidate: number | null;
32
+ }
33
+
34
+ export interface TargetBuildManifest {
35
+ buildId: string;
36
+ clientDir: string | null;
37
+ generatedAt: string;
38
+ serverEntry: string | null;
39
+ serverPath: string | null;
40
+ targetDir: string;
41
+ templatePath: string | null;
42
+ }
43
+
44
+ export type AnyTargetManifest = TargetBuildManifest | StaticTargetBuildManifest;
45
+
46
+ export interface BuildManifest {
47
+ generatedAt: string;
48
+ pagesDir: string;
49
+ rootDir: string;
50
+ rootPath: string;
51
+ routes: BuildRouteManifestEntry[];
52
+ serverEntry: string | null;
53
+ targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
54
+ version: 1;
55
+ }
56
+
57
+ export interface BuildAppOptions {
58
+ /** Inject the evlog client logger into the hydrate entry. Defaults to false. */
59
+ clientLogging?: boolean;
60
+ compile?: "server" | "embed";
61
+ pagesDir?: string;
62
+ plugins?: Bun.BunPlugin[];
63
+ rootDir?: string;
64
+ serverEntry?: string;
65
+ /** Configuration for the `static` build target. */
66
+ staticConfig?: StaticExportConfig;
67
+ target: BuildTarget | "all";
68
+ }
69
+
70
+ /** Build manifest entry produced by the `static` adapter. */
71
+ export interface StaticTargetBuildManifest {
72
+ basePath: string;
73
+ generatedAt: string;
74
+ outDir: string;
75
+ renderedRoutes: string[];
76
+ skippedRoutes: string[];
77
+ }
78
+
79
+ export interface BuildAppResult {
80
+ manifest: BuildManifest;
81
+ targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
82
+ }
83
+
84
+ export type BunBuildAliasConfig = Bun.BuildConfig & {
85
+ alias?: Record<string, string>;
86
+ outfile?: string;
87
+ packages?: "bundle" | "external";
88
+ write?: boolean;
89
+ };
@@ -1,177 +1,184 @@
1
- import { buildSearchParams, type SearchParamsInput } from "../../shared/search-params.ts";
2
- import type { CacheEntry } from "./types.ts";
3
-
4
- const HASH_FRAGMENT_RE = /#.*$/;
5
- /** Strips one or more trailing slashes — used by `buildDataEndpoint` in static mode. */
6
- export const TRAILING_SLASHES_RE = /\/+$/;
7
-
8
- /**
9
- * Builds a full href string from a pathname, optional search params, and optional hash.
10
- * Null/undefined search values are omitted.
11
- *
12
- * @internal Exported for unit testing only.
13
- */
14
- export function buildHref(
15
- to: string,
16
- search: SearchParamsInput | null | undefined,
17
- hash: string | undefined,
18
- searchDefaults?: SearchParamsInput
19
- ): string {
20
- let url = to;
21
- if (search && Object.keys(search).length > 0) {
22
- const params = buildSearchParams(search, searchDefaults);
23
- const qs = params.toString();
24
- if (qs) {
25
- url += `?${qs}`;
26
- }
27
- }
28
- if (hash) {
29
- url += `#${hash}`;
30
- }
31
- return url;
32
- }
33
-
34
- /**
35
- * Parses the `X-Furin-Revalidate` response header and calls `invalidate` for
36
- * each path entry. Header format: `"/path1,/path2:layout,/path3"`
37
- */
38
- export function applyRevalidateHeader(
39
- headers: Headers,
40
- invalidate: (path: string, type: "page" | "layout" | undefined) => void
41
- ): void {
42
- const headerValue = headers.get("x-furin-revalidate");
43
- if (!headerValue) {
44
- return;
45
- }
46
- for (const entry of headerValue.split(",")) {
47
- const trimmed = entry.trim();
48
- if (!trimmed) {
49
- continue;
50
- }
51
- if (trimmed.endsWith(":layout")) {
52
- invalidate(trimmed.slice(0, -":layout".length), "layout");
53
- } else {
54
- invalidate(trimmed, "page");
55
- }
56
- }
57
- }
58
-
59
- /**
60
- * Returns `true` when `currentPath` is targeted by at least one invalidation entry.
61
- *
62
- * @internal Exported for unit testing only.
63
- */
64
- export function shouldAutoRefreshPath(
65
- currentPath: string,
66
- invalidations: ReadonlyArray<{ path: string; type: "page" | "layout" }>
67
- ): boolean {
68
- const normalizedCurrent = currentPath.split("?")[0] ?? currentPath;
69
- return invalidations.some(({ path, type }) => {
70
- if (type === "page") {
71
- return path === normalizedCurrent;
72
- }
73
- const prefix = path === "/" || path.endsWith("/") ? path : `${path}/`;
74
- return normalizedCurrent === path || normalizedCurrent.startsWith(prefix);
75
- });
76
- }
77
-
78
- export function stripHashFromHref(href: string): string {
79
- return href.replace(HASH_FRAGMENT_RE, "");
80
- }
81
-
82
- /** Strips trailing slashes from a pathname or href. Root `/` is preserved.
83
- * Query strings and hashes are preserved and re-attached after normalization. */
84
- export function normalizeHref(href: string): string {
85
- const url = new URL(href, "http://localhost");
86
- let pathname = url.pathname;
87
- if (pathname !== "/") {
88
- pathname = pathname.replace(/\/+$/g, "");
89
- }
90
- return pathname + url.search + url.hash;
91
- }
92
-
93
- /** Strips a single trailing slash from a pathname. Root `/` and empty string are preserved. */
94
- export function normalizePath(path: string): string {
95
- if (path === "/" || path === "") {
96
- return path;
97
- }
98
- return path.endsWith("/") ? path.slice(0, -1) : path;
99
- }
100
-
101
- /** @internal Exported for unit testing only. */
102
- export function shouldRefetch(entry: CacheEntry): boolean {
103
- return Date.now() - entry.createdAt > entry.staleTime;
104
- }
105
-
106
- /**
107
- * Decides whether a native `<a>` click should be intercepted and converted
108
- * to an SPA navigation. Returns the logical href to navigate to, or `null`
109
- * when the browser should handle the click normally.
110
- *
111
- * @internal Exported for unit testing only.
112
- */
113
- export function shouldInterceptClick(
114
- anchor: { href: string; target: string; hasAttribute(name: string): boolean },
115
- event: { metaKey: boolean; ctrlKey: boolean; shiftKey: boolean; altKey: boolean },
116
- basePath: string,
117
- currentOrigin: string,
118
- currentPathname: string
119
- ): string | null {
120
- if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
121
- return null;
122
- }
123
-
124
- if (anchor.target && anchor.target !== "_self") {
125
- return null;
126
- }
127
-
128
- if (anchor.hasAttribute("download")) {
129
- return null;
130
- }
131
-
132
- const href = anchor.href;
133
- if (!href) {
134
- return null;
135
- }
136
-
137
- let url: URL;
138
- try {
139
- url = new URL(href, currentOrigin);
140
- } catch {
141
- return null;
142
- }
143
-
144
- if (url.origin !== currentOrigin) {
145
- return null;
146
- }
147
-
148
- // Hash-only navigation on the same page — let the browser handle scrolling.
149
- if (normalizePath(url.pathname) === normalizePath(currentPathname) && url.hash) {
150
- return null;
151
- }
152
-
153
- const logicalPath = normalizeHref(toLogical(url.pathname, basePath));
154
- const normalizedBase = normalizePath(basePath);
155
- const normalizedPathname = normalizePath(url.pathname);
156
- if (
157
- normalizedBase &&
158
- normalizedPathname !== normalizedBase &&
159
- !normalizedPathname.startsWith(`${normalizedBase}/`)
160
- ) {
161
- return null;
162
- }
163
- return logicalPath + url.search + url.hash;
164
- }
165
-
166
- /** Strips basePath prefix from a physical pathname, returning the logical path. */
167
- export function toLogical(physicalPathname: string, basePath: string): string {
168
- if (
169
- basePath &&
170
- physicalPathname.startsWith(basePath) &&
171
- // Require a path boundary after the prefix so "/furin" doesn't match "/furinity/foo"
172
- (physicalPathname.length === basePath.length || physicalPathname[basePath.length] === "/")
173
- ) {
174
- return physicalPathname.slice(basePath.length) || "/";
175
- }
176
- return physicalPathname;
177
- }
1
+ import { buildSearchParams, type SearchParamsInput } from "../../shared/search-params.ts";
2
+ import type { CacheEntry } from "./types.ts";
3
+
4
+ const HASH_FRAGMENT_RE = /#.*$/;
5
+ /** Strips one or more trailing slashes — used by `buildDataEndpoint` in static mode. */
6
+ export const TRAILING_SLASHES_RE = /\/+$/;
7
+
8
+ /**
9
+ * Builds a full href string from a pathname, optional search params, and optional hash.
10
+ * Null/undefined search values are omitted.
11
+ *
12
+ * @internal Exported for unit testing only.
13
+ */
14
+ export function buildHref(
15
+ to: string,
16
+ search: SearchParamsInput | null | undefined,
17
+ hash: string | undefined,
18
+ searchDefaults?: SearchParamsInput
19
+ ): string {
20
+ let url = to;
21
+ if (search && Object.keys(search).length > 0) {
22
+ const params = buildSearchParams(search, searchDefaults);
23
+ const qs = params.toString();
24
+ if (qs) {
25
+ url += `?${qs}`;
26
+ }
27
+ }
28
+ if (hash) {
29
+ url += `#${hash}`;
30
+ }
31
+ return url;
32
+ }
33
+
34
+ /**
35
+ * Parses the `X-Furin-Revalidate` response header and calls `invalidate` for
36
+ * each path entry. Header format: `"/path1,/path2:layout,/path3"`
37
+ */
38
+ export function applyRevalidateHeader(
39
+ headers: Headers,
40
+ invalidate: (path: string, type: "page" | "layout" | undefined) => void
41
+ ): void {
42
+ const headerValue = headers.get("x-furin-revalidate");
43
+ if (!headerValue) {
44
+ return;
45
+ }
46
+ applyRevalidateEntries(headerValue.split(","), invalidate);
47
+ }
48
+
49
+ export function applyRevalidateEntries(
50
+ entries: Iterable<string>,
51
+ invalidate: (path: string, type: "page" | "layout" | undefined) => void
52
+ ): void {
53
+ for (const entry of entries) {
54
+ const trimmed = entry.trim();
55
+ if (!trimmed) {
56
+ continue;
57
+ }
58
+ if (trimmed.endsWith(":layout")) {
59
+ invalidate(trimmed.slice(0, -":layout".length), "layout");
60
+ } else {
61
+ invalidate(trimmed, "page");
62
+ }
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Returns `true` when `currentPath` is targeted by at least one invalidation entry.
68
+ *
69
+ * @internal Exported for unit testing only.
70
+ */
71
+ export function shouldAutoRefreshPath(
72
+ currentPath: string,
73
+ invalidations: ReadonlyArray<{ path: string; type: "page" | "layout" }>
74
+ ): boolean {
75
+ const normalizedCurrent = currentPath.split("?")[0] ?? currentPath;
76
+ return invalidations.some(({ path, type }) => {
77
+ if (type === "page") {
78
+ return path === normalizedCurrent;
79
+ }
80
+ const prefix = path === "/" || path.endsWith("/") ? path : `${path}/`;
81
+ return normalizedCurrent === path || normalizedCurrent.startsWith(prefix);
82
+ });
83
+ }
84
+
85
+ export function stripHashFromHref(href: string): string {
86
+ return href.replace(HASH_FRAGMENT_RE, "");
87
+ }
88
+
89
+ /** Strips trailing slashes from a pathname or href. Root `/` is preserved.
90
+ * Query strings and hashes are preserved and re-attached after normalization. */
91
+ export function normalizeHref(href: string): string {
92
+ const url = new URL(href, "http://localhost");
93
+ let pathname = url.pathname;
94
+ if (pathname !== "/") {
95
+ pathname = pathname.replace(/\/+$/g, "");
96
+ }
97
+ return pathname + url.search + url.hash;
98
+ }
99
+
100
+ /** Strips a single trailing slash from a pathname. Root `/` and empty string are preserved. */
101
+ export function normalizePath(path: string): string {
102
+ if (path === "/" || path === "") {
103
+ return path;
104
+ }
105
+ return path.endsWith("/") ? path.slice(0, -1) : path;
106
+ }
107
+
108
+ /** @internal Exported for unit testing only. */
109
+ export function shouldRefetch(entry: CacheEntry): boolean {
110
+ return Date.now() - entry.createdAt > entry.staleTime;
111
+ }
112
+
113
+ /**
114
+ * Decides whether a native `<a>` click should be intercepted and converted
115
+ * to an SPA navigation. Returns the logical href to navigate to, or `null`
116
+ * when the browser should handle the click normally.
117
+ *
118
+ * @internal Exported for unit testing only.
119
+ */
120
+ export function shouldInterceptClick(
121
+ anchor: { href: string; target: string; hasAttribute(name: string): boolean },
122
+ event: { metaKey: boolean; ctrlKey: boolean; shiftKey: boolean; altKey: boolean },
123
+ basePath: string,
124
+ currentOrigin: string,
125
+ currentPathname: string
126
+ ): string | null {
127
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
128
+ return null;
129
+ }
130
+
131
+ if (anchor.target && anchor.target !== "_self") {
132
+ return null;
133
+ }
134
+
135
+ if (anchor.hasAttribute("download")) {
136
+ return null;
137
+ }
138
+
139
+ const href = anchor.href;
140
+ if (!href) {
141
+ return null;
142
+ }
143
+
144
+ let url: URL;
145
+ try {
146
+ url = new URL(href, currentOrigin);
147
+ } catch {
148
+ return null;
149
+ }
150
+
151
+ if (url.origin !== currentOrigin) {
152
+ return null;
153
+ }
154
+
155
+ // Hash-only navigation on the same page — let the browser handle scrolling.
156
+ if (normalizePath(url.pathname) === normalizePath(currentPathname) && url.hash) {
157
+ return null;
158
+ }
159
+
160
+ const logicalPath = normalizeHref(toLogical(url.pathname, basePath));
161
+ const normalizedBase = normalizePath(basePath);
162
+ const normalizedPathname = normalizePath(url.pathname);
163
+ if (
164
+ normalizedBase &&
165
+ normalizedPathname !== normalizedBase &&
166
+ !normalizedPathname.startsWith(`${normalizedBase}/`)
167
+ ) {
168
+ return null;
169
+ }
170
+ return logicalPath + url.search + url.hash;
171
+ }
172
+
173
+ /** Strips basePath prefix from a physical pathname, returning the logical path. */
174
+ export function toLogical(physicalPathname: string, basePath: string): string {
175
+ if (
176
+ basePath &&
177
+ physicalPathname.startsWith(basePath) &&
178
+ // Require a path boundary after the prefix so "/furin" doesn't match "/furinity/foo"
179
+ (physicalPathname.length === basePath.length || physicalPathname[basePath.length] === "/")
180
+ ) {
181
+ return physicalPathname.slice(basePath.length) || "/";
182
+ }
183
+ return physicalPathname;
184
+ }