@benjavicente/router-core 1.168.9

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 (380) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/bin/intent.js +25 -0
  4. package/dist/cjs/Matches.cjs +17 -0
  5. package/dist/cjs/Matches.cjs.map +1 -0
  6. package/dist/cjs/Matches.d.cts +139 -0
  7. package/dist/cjs/RouterProvider.d.cts +27 -0
  8. package/dist/cjs/config.cjs +11 -0
  9. package/dist/cjs/config.cjs.map +1 -0
  10. package/dist/cjs/config.d.cts +17 -0
  11. package/dist/cjs/defer.cjs +41 -0
  12. package/dist/cjs/defer.cjs.map +1 -0
  13. package/dist/cjs/defer.d.cts +37 -0
  14. package/dist/cjs/fileRoute.d.cts +24 -0
  15. package/dist/cjs/global.d.cts +7 -0
  16. package/dist/cjs/hash-scroll.cjs +20 -0
  17. package/dist/cjs/hash-scroll.cjs.map +1 -0
  18. package/dist/cjs/hash-scroll.d.cts +7 -0
  19. package/dist/cjs/history.d.cts +8 -0
  20. package/dist/cjs/index.cjs +96 -0
  21. package/dist/cjs/index.d.cts +53 -0
  22. package/dist/cjs/invariant.cjs +8 -0
  23. package/dist/cjs/invariant.cjs.map +1 -0
  24. package/dist/cjs/invariant.d.cts +1 -0
  25. package/dist/cjs/isServer/client.cjs +7 -0
  26. package/dist/cjs/isServer/client.cjs.map +1 -0
  27. package/dist/cjs/isServer/client.d.cts +1 -0
  28. package/dist/cjs/isServer/development.cjs +7 -0
  29. package/dist/cjs/isServer/development.cjs.map +1 -0
  30. package/dist/cjs/isServer/development.d.cts +1 -0
  31. package/dist/cjs/isServer/server.cjs +7 -0
  32. package/dist/cjs/isServer/server.cjs.map +1 -0
  33. package/dist/cjs/isServer/server.d.cts +1 -0
  34. package/dist/cjs/link.cjs +6 -0
  35. package/dist/cjs/link.cjs.map +1 -0
  36. package/dist/cjs/link.d.cts +221 -0
  37. package/dist/cjs/load-matches.cjs +659 -0
  38. package/dist/cjs/load-matches.cjs.map +1 -0
  39. package/dist/cjs/load-matches.d.cts +18 -0
  40. package/dist/cjs/location.d.cts +50 -0
  41. package/dist/cjs/lru-cache.cjs +70 -0
  42. package/dist/cjs/lru-cache.cjs.map +1 -0
  43. package/dist/cjs/lru-cache.d.cts +6 -0
  44. package/dist/cjs/manifest.cjs +18 -0
  45. package/dist/cjs/manifest.cjs.map +1 -0
  46. package/dist/cjs/manifest.d.cts +35 -0
  47. package/dist/cjs/new-process-route-tree.cjs +754 -0
  48. package/dist/cjs/new-process-route-tree.cjs.map +1 -0
  49. package/dist/cjs/new-process-route-tree.d.cts +236 -0
  50. package/dist/cjs/not-found.cjs +26 -0
  51. package/dist/cjs/not-found.cjs.map +1 -0
  52. package/dist/cjs/not-found.d.cts +32 -0
  53. package/dist/cjs/path.cjs +252 -0
  54. package/dist/cjs/path.cjs.map +1 -0
  55. package/dist/cjs/path.d.cts +56 -0
  56. package/dist/cjs/qss.cjs +70 -0
  57. package/dist/cjs/qss.cjs.map +1 -0
  58. package/dist/cjs/qss.d.cts +33 -0
  59. package/dist/cjs/redirect.cjs +56 -0
  60. package/dist/cjs/redirect.cjs.map +1 -0
  61. package/dist/cjs/redirect.d.cts +77 -0
  62. package/dist/cjs/rewrite.cjs +68 -0
  63. package/dist/cjs/rewrite.cjs.map +1 -0
  64. package/dist/cjs/rewrite.d.cts +30 -0
  65. package/dist/cjs/root.cjs +7 -0
  66. package/dist/cjs/root.cjs.map +1 -0
  67. package/dist/cjs/root.d.cts +3 -0
  68. package/dist/cjs/route.cjs +100 -0
  69. package/dist/cjs/route.cjs.map +1 -0
  70. package/dist/cjs/route.d.cts +552 -0
  71. package/dist/cjs/routeInfo.d.cts +54 -0
  72. package/dist/cjs/router.cjs +1173 -0
  73. package/dist/cjs/router.cjs.map +1 -0
  74. package/dist/cjs/router.d.cts +734 -0
  75. package/dist/cjs/scroll-restoration-inline.cjs +6 -0
  76. package/dist/cjs/scroll-restoration-inline.cjs.map +1 -0
  77. package/dist/cjs/scroll-restoration-inline.d.cts +6 -0
  78. package/dist/cjs/scroll-restoration-script/client.cjs +9 -0
  79. package/dist/cjs/scroll-restoration-script/client.cjs.map +1 -0
  80. package/dist/cjs/scroll-restoration-script/client.d.cts +2 -0
  81. package/dist/cjs/scroll-restoration-script/server.cjs +30 -0
  82. package/dist/cjs/scroll-restoration-script/server.cjs.map +1 -0
  83. package/dist/cjs/scroll-restoration-script/server.d.cts +2 -0
  84. package/dist/cjs/scroll-restoration.cjs +191 -0
  85. package/dist/cjs/scroll-restoration.cjs.map +1 -0
  86. package/dist/cjs/scroll-restoration.d.cts +38 -0
  87. package/dist/cjs/searchMiddleware.cjs +55 -0
  88. package/dist/cjs/searchMiddleware.cjs.map +1 -0
  89. package/dist/cjs/searchMiddleware.d.cts +25 -0
  90. package/dist/cjs/searchParams.cjs +65 -0
  91. package/dist/cjs/searchParams.cjs.map +1 -0
  92. package/dist/cjs/searchParams.d.cts +31 -0
  93. package/dist/cjs/ssr/client.cjs +7 -0
  94. package/dist/cjs/ssr/client.d.cts +6 -0
  95. package/dist/cjs/ssr/constants.cjs +8 -0
  96. package/dist/cjs/ssr/constants.cjs.map +1 -0
  97. package/dist/cjs/ssr/constants.d.cts +3 -0
  98. package/dist/cjs/ssr/createRequestHandler.cjs +44 -0
  99. package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -0
  100. package/dist/cjs/ssr/createRequestHandler.d.cts +9 -0
  101. package/dist/cjs/ssr/handlerCallback.cjs +8 -0
  102. package/dist/cjs/ssr/handlerCallback.cjs.map +1 -0
  103. package/dist/cjs/ssr/handlerCallback.d.cts +9 -0
  104. package/dist/cjs/ssr/headers.cjs +21 -0
  105. package/dist/cjs/ssr/headers.cjs.map +1 -0
  106. package/dist/cjs/ssr/headers.d.cts +3 -0
  107. package/dist/cjs/ssr/json.cjs +11 -0
  108. package/dist/cjs/ssr/json.cjs.map +1 -0
  109. package/dist/cjs/ssr/json.d.cts +10 -0
  110. package/dist/cjs/ssr/serializer/RawStream.cjs +287 -0
  111. package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -0
  112. package/dist/cjs/ssr/serializer/RawStream.d.cts +64 -0
  113. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs +32 -0
  114. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -0
  115. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.d.cts +9 -0
  116. package/dist/cjs/ssr/serializer/seroval-plugins.cjs +13 -0
  117. package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -0
  118. package/dist/cjs/ssr/serializer/seroval-plugins.d.cts +2 -0
  119. package/dist/cjs/ssr/serializer/transformer.cjs +53 -0
  120. package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -0
  121. package/dist/cjs/ssr/serializer/transformer.d.cts +91 -0
  122. package/dist/cjs/ssr/server.cjs +13 -0
  123. package/dist/cjs/ssr/server.d.cts +6 -0
  124. package/dist/cjs/ssr/ssr-client.cjs +183 -0
  125. package/dist/cjs/ssr/ssr-client.cjs.map +1 -0
  126. package/dist/cjs/ssr/ssr-client.d.cts +10 -0
  127. package/dist/cjs/ssr/ssr-match-id.cjs +12 -0
  128. package/dist/cjs/ssr/ssr-match-id.cjs.map +1 -0
  129. package/dist/cjs/ssr/ssr-match-id.d.cts +2 -0
  130. package/dist/cjs/ssr/ssr-server.cjs +279 -0
  131. package/dist/cjs/ssr/ssr-server.cjs.map +1 -0
  132. package/dist/cjs/ssr/ssr-server.d.cts +42 -0
  133. package/dist/cjs/ssr/transformStreamWithRouter.cjs +327 -0
  134. package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -0
  135. package/dist/cjs/ssr/transformStreamWithRouter.d.cts +11 -0
  136. package/dist/cjs/ssr/tsrScript.cjs +6 -0
  137. package/dist/cjs/ssr/tsrScript.cjs.map +1 -0
  138. package/dist/cjs/ssr/tsrScript.d.cts +1 -0
  139. package/dist/cjs/ssr/types.d.cts +30 -0
  140. package/dist/cjs/stores.cjs +148 -0
  141. package/dist/cjs/stores.cjs.map +1 -0
  142. package/dist/cjs/stores.d.cts +70 -0
  143. package/dist/cjs/structuralSharing.d.cts +4 -0
  144. package/dist/cjs/typePrimitives.d.cts +65 -0
  145. package/dist/cjs/useLoaderData.d.cts +5 -0
  146. package/dist/cjs/useLoaderDeps.d.cts +5 -0
  147. package/dist/cjs/useNavigate.d.cts +3 -0
  148. package/dist/cjs/useParams.d.cts +5 -0
  149. package/dist/cjs/useRouteContext.d.cts +9 -0
  150. package/dist/cjs/useSearch.d.cts +5 -0
  151. package/dist/cjs/utils.cjs +339 -0
  152. package/dist/cjs/utils.cjs.map +1 -0
  153. package/dist/cjs/utils.d.cts +178 -0
  154. package/dist/cjs/validators.d.cts +51 -0
  155. package/dist/esm/Matches.d.ts +139 -0
  156. package/dist/esm/Matches.js +17 -0
  157. package/dist/esm/Matches.js.map +1 -0
  158. package/dist/esm/RouterProvider.d.ts +27 -0
  159. package/dist/esm/config.d.ts +17 -0
  160. package/dist/esm/config.js +11 -0
  161. package/dist/esm/config.js.map +1 -0
  162. package/dist/esm/defer.d.ts +37 -0
  163. package/dist/esm/defer.js +40 -0
  164. package/dist/esm/defer.js.map +1 -0
  165. package/dist/esm/fileRoute.d.ts +24 -0
  166. package/dist/esm/global.d.ts +7 -0
  167. package/dist/esm/hash-scroll.d.ts +7 -0
  168. package/dist/esm/hash-scroll.js +20 -0
  169. package/dist/esm/hash-scroll.js.map +1 -0
  170. package/dist/esm/history.d.ts +8 -0
  171. package/dist/esm/index.d.ts +53 -0
  172. package/dist/esm/index.js +24 -0
  173. package/dist/esm/invariant.d.ts +1 -0
  174. package/dist/esm/invariant.js +8 -0
  175. package/dist/esm/invariant.js.map +1 -0
  176. package/dist/esm/isServer/client.d.ts +1 -0
  177. package/dist/esm/isServer/client.js +6 -0
  178. package/dist/esm/isServer/client.js.map +1 -0
  179. package/dist/esm/isServer/development.d.ts +1 -0
  180. package/dist/esm/isServer/development.js +6 -0
  181. package/dist/esm/isServer/development.js.map +1 -0
  182. package/dist/esm/isServer/server.d.ts +1 -0
  183. package/dist/esm/isServer/server.js +6 -0
  184. package/dist/esm/isServer/server.js.map +1 -0
  185. package/dist/esm/link.d.ts +221 -0
  186. package/dist/esm/link.js +6 -0
  187. package/dist/esm/link.js.map +1 -0
  188. package/dist/esm/load-matches.d.ts +18 -0
  189. package/dist/esm/load-matches.js +657 -0
  190. package/dist/esm/load-matches.js.map +1 -0
  191. package/dist/esm/location.d.ts +50 -0
  192. package/dist/esm/lru-cache.d.ts +6 -0
  193. package/dist/esm/lru-cache.js +70 -0
  194. package/dist/esm/lru-cache.js.map +1 -0
  195. package/dist/esm/manifest.d.ts +35 -0
  196. package/dist/esm/manifest.js +17 -0
  197. package/dist/esm/manifest.js.map +1 -0
  198. package/dist/esm/new-process-route-tree.d.ts +236 -0
  199. package/dist/esm/new-process-route-tree.js +749 -0
  200. package/dist/esm/new-process-route-tree.js.map +1 -0
  201. package/dist/esm/not-found.d.ts +32 -0
  202. package/dist/esm/not-found.js +25 -0
  203. package/dist/esm/not-found.js.map +1 -0
  204. package/dist/esm/path.d.ts +56 -0
  205. package/dist/esm/path.js +243 -0
  206. package/dist/esm/path.js.map +1 -0
  207. package/dist/esm/qss.d.ts +33 -0
  208. package/dist/esm/qss.js +69 -0
  209. package/dist/esm/qss.js.map +1 -0
  210. package/dist/esm/redirect.d.ts +77 -0
  211. package/dist/esm/redirect.js +53 -0
  212. package/dist/esm/redirect.js.map +1 -0
  213. package/dist/esm/rewrite.d.ts +30 -0
  214. package/dist/esm/rewrite.js +65 -0
  215. package/dist/esm/rewrite.js.map +1 -0
  216. package/dist/esm/root.d.ts +3 -0
  217. package/dist/esm/root.js +7 -0
  218. package/dist/esm/root.js.map +1 -0
  219. package/dist/esm/route.d.ts +552 -0
  220. package/dist/esm/route.js +98 -0
  221. package/dist/esm/route.js.map +1 -0
  222. package/dist/esm/routeInfo.d.ts +54 -0
  223. package/dist/esm/router.d.ts +734 -0
  224. package/dist/esm/router.js +1165 -0
  225. package/dist/esm/router.js.map +1 -0
  226. package/dist/esm/scroll-restoration-inline.d.ts +6 -0
  227. package/dist/esm/scroll-restoration-inline.js +6 -0
  228. package/dist/esm/scroll-restoration-inline.js.map +1 -0
  229. package/dist/esm/scroll-restoration-script/client.d.ts +2 -0
  230. package/dist/esm/scroll-restoration-script/client.js +8 -0
  231. package/dist/esm/scroll-restoration-script/client.js.map +1 -0
  232. package/dist/esm/scroll-restoration-script/server.d.ts +2 -0
  233. package/dist/esm/scroll-restoration-script/server.js +29 -0
  234. package/dist/esm/scroll-restoration-script/server.js.map +1 -0
  235. package/dist/esm/scroll-restoration.d.ts +38 -0
  236. package/dist/esm/scroll-restoration.js +187 -0
  237. package/dist/esm/scroll-restoration.js.map +1 -0
  238. package/dist/esm/searchMiddleware.d.ts +25 -0
  239. package/dist/esm/searchMiddleware.js +54 -0
  240. package/dist/esm/searchMiddleware.js.map +1 -0
  241. package/dist/esm/searchParams.d.ts +31 -0
  242. package/dist/esm/searchParams.js +62 -0
  243. package/dist/esm/searchParams.js.map +1 -0
  244. package/dist/esm/ssr/client.d.ts +6 -0
  245. package/dist/esm/ssr/client.js +4 -0
  246. package/dist/esm/ssr/constants.d.ts +3 -0
  247. package/dist/esm/ssr/constants.js +7 -0
  248. package/dist/esm/ssr/constants.js.map +1 -0
  249. package/dist/esm/ssr/createRequestHandler.d.ts +9 -0
  250. package/dist/esm/ssr/createRequestHandler.js +44 -0
  251. package/dist/esm/ssr/createRequestHandler.js.map +1 -0
  252. package/dist/esm/ssr/handlerCallback.d.ts +9 -0
  253. package/dist/esm/ssr/handlerCallback.js +8 -0
  254. package/dist/esm/ssr/handlerCallback.js.map +1 -0
  255. package/dist/esm/ssr/headers.d.ts +3 -0
  256. package/dist/esm/ssr/headers.js +21 -0
  257. package/dist/esm/ssr/headers.js.map +1 -0
  258. package/dist/esm/ssr/json.d.ts +10 -0
  259. package/dist/esm/ssr/json.js +11 -0
  260. package/dist/esm/ssr/json.js.map +1 -0
  261. package/dist/esm/ssr/serializer/RawStream.d.ts +64 -0
  262. package/dist/esm/ssr/serializer/RawStream.js +282 -0
  263. package/dist/esm/ssr/serializer/RawStream.js.map +1 -0
  264. package/dist/esm/ssr/serializer/ShallowErrorPlugin.d.ts +9 -0
  265. package/dist/esm/ssr/serializer/ShallowErrorPlugin.js +33 -0
  266. package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -0
  267. package/dist/esm/ssr/serializer/seroval-plugins.d.ts +2 -0
  268. package/dist/esm/ssr/serializer/seroval-plugins.js +13 -0
  269. package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -0
  270. package/dist/esm/ssr/serializer/transformer.d.ts +91 -0
  271. package/dist/esm/ssr/serializer/transformer.js +51 -0
  272. package/dist/esm/ssr/serializer/transformer.js.map +1 -0
  273. package/dist/esm/ssr/server.d.ts +6 -0
  274. package/dist/esm/ssr/server.js +5 -0
  275. package/dist/esm/ssr/ssr-client.d.ts +10 -0
  276. package/dist/esm/ssr/ssr-client.js +183 -0
  277. package/dist/esm/ssr/ssr-client.js.map +1 -0
  278. package/dist/esm/ssr/ssr-match-id.d.ts +2 -0
  279. package/dist/esm/ssr/ssr-match-id.js +11 -0
  280. package/dist/esm/ssr/ssr-match-id.js.map +1 -0
  281. package/dist/esm/ssr/ssr-server.d.ts +42 -0
  282. package/dist/esm/ssr/ssr-server.js +277 -0
  283. package/dist/esm/ssr/ssr-server.js.map +1 -0
  284. package/dist/esm/ssr/transformStreamWithRouter.d.ts +11 -0
  285. package/dist/esm/ssr/transformStreamWithRouter.js +325 -0
  286. package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -0
  287. package/dist/esm/ssr/tsrScript.d.ts +0 -0
  288. package/dist/esm/ssr/tsrScript.js +6 -0
  289. package/dist/esm/ssr/tsrScript.js.map +1 -0
  290. package/dist/esm/ssr/types.d.ts +30 -0
  291. package/dist/esm/stores.d.ts +70 -0
  292. package/dist/esm/stores.js +146 -0
  293. package/dist/esm/stores.js.map +1 -0
  294. package/dist/esm/structuralSharing.d.ts +4 -0
  295. package/dist/esm/typePrimitives.d.ts +65 -0
  296. package/dist/esm/useLoaderData.d.ts +5 -0
  297. package/dist/esm/useLoaderDeps.d.ts +5 -0
  298. package/dist/esm/useNavigate.d.ts +3 -0
  299. package/dist/esm/useParams.d.ts +5 -0
  300. package/dist/esm/useRouteContext.d.ts +9 -0
  301. package/dist/esm/useSearch.d.ts +5 -0
  302. package/dist/esm/utils.d.ts +178 -0
  303. package/dist/esm/utils.js +322 -0
  304. package/dist/esm/utils.js.map +1 -0
  305. package/dist/esm/validators.d.ts +51 -0
  306. package/package.json +200 -0
  307. package/skills/router-core/SKILL.md +139 -0
  308. package/skills/router-core/auth-and-guards/SKILL.md +458 -0
  309. package/skills/router-core/code-splitting/SKILL.md +322 -0
  310. package/skills/router-core/data-loading/SKILL.md +485 -0
  311. package/skills/router-core/navigation/SKILL.md +448 -0
  312. package/skills/router-core/not-found-and-errors/SKILL.md +435 -0
  313. package/skills/router-core/path-params/SKILL.md +382 -0
  314. package/skills/router-core/search-params/SKILL.md +349 -0
  315. package/skills/router-core/search-params/references/validation-patterns.md +379 -0
  316. package/skills/router-core/ssr/SKILL.md +437 -0
  317. package/skills/router-core/type-safety/SKILL.md +497 -0
  318. package/src/Matches.ts +291 -0
  319. package/src/RouterProvider.ts +47 -0
  320. package/src/config.ts +42 -0
  321. package/src/defer.ts +69 -0
  322. package/src/fileRoute.ts +164 -0
  323. package/src/global.ts +9 -0
  324. package/src/hash-scroll.ts +21 -0
  325. package/src/history.ts +9 -0
  326. package/src/index.ts +471 -0
  327. package/src/invariant.ts +3 -0
  328. package/src/isServer/client.ts +1 -0
  329. package/src/isServer/development.ts +2 -0
  330. package/src/isServer/server.ts +1 -0
  331. package/src/link.ts +704 -0
  332. package/src/load-matches.ts +1281 -0
  333. package/src/location.ts +51 -0
  334. package/src/lru-cache.ts +74 -0
  335. package/src/manifest.ts +68 -0
  336. package/src/new-process-route-tree.ts +1387 -0
  337. package/src/not-found.ts +41 -0
  338. package/src/path.ts +436 -0
  339. package/src/qss.ts +81 -0
  340. package/src/redirect.ts +179 -0
  341. package/src/rewrite.ts +93 -0
  342. package/src/root.ts +3 -0
  343. package/src/route.ts +2235 -0
  344. package/src/routeInfo.ts +235 -0
  345. package/src/router.ts +3207 -0
  346. package/src/scroll-restoration-inline.ts +81 -0
  347. package/src/scroll-restoration-script/client.ts +5 -0
  348. package/src/scroll-restoration-script/server.ts +64 -0
  349. package/src/scroll-restoration.ts +357 -0
  350. package/src/searchMiddleware.ts +76 -0
  351. package/src/searchParams.ts +90 -0
  352. package/src/ssr/client.ts +6 -0
  353. package/src/ssr/constants.ts +3 -0
  354. package/src/ssr/createRequestHandler.ts +98 -0
  355. package/src/ssr/handlerCallback.ts +15 -0
  356. package/src/ssr/headers.ts +40 -0
  357. package/src/ssr/json.ts +16 -0
  358. package/src/ssr/serializer/RawStream.ts +464 -0
  359. package/src/ssr/serializer/ShallowErrorPlugin.ts +43 -0
  360. package/src/ssr/serializer/seroval-plugins.ts +12 -0
  361. package/src/ssr/serializer/transformer.ts +312 -0
  362. package/src/ssr/server.ts +14 -0
  363. package/src/ssr/ssr-client.ts +313 -0
  364. package/src/ssr/ssr-match-id.ts +7 -0
  365. package/src/ssr/ssr-server.ts +425 -0
  366. package/src/ssr/transformStreamWithRouter.ts +493 -0
  367. package/src/ssr/tsrScript.ts +20 -0
  368. package/src/ssr/types.ts +41 -0
  369. package/src/stores.ts +342 -0
  370. package/src/structuralSharing.ts +7 -0
  371. package/src/typePrimitives.ts +181 -0
  372. package/src/useLoaderData.ts +20 -0
  373. package/src/useLoaderDeps.ts +13 -0
  374. package/src/useNavigate.ts +13 -0
  375. package/src/useParams.ts +20 -0
  376. package/src/useRouteContext.ts +39 -0
  377. package/src/useSearch.ts +20 -0
  378. package/src/utils.ts +708 -0
  379. package/src/validators.ts +121 -0
  380. package/src/vite-env.d.ts +4 -0
@@ -0,0 +1,1173 @@
1
+ const require_utils = require("./utils.cjs");
2
+ const require_lru_cache = require("./lru-cache.cjs");
3
+ const require_new_process_route_tree = require("./new-process-route-tree.cjs");
4
+ const require_path = require("./path.cjs");
5
+ const require_not_found = require("./not-found.cjs");
6
+ const require_scroll_restoration = require("./scroll-restoration.cjs");
7
+ const require_searchParams = require("./searchParams.cjs");
8
+ const require_root = require("./root.cjs");
9
+ const require_redirect = require("./redirect.cjs");
10
+ const require_load_matches = require("./load-matches.cjs");
11
+ const require_rewrite = require("./rewrite.cjs");
12
+ const require_stores = require("./stores.cjs");
13
+ let _benjavicente_history = require("@benjavicente/history");
14
+ let _benjavicente_router_core_isServer = require("@benjavicente/router-core/isServer");
15
+ //#region src/router.ts
16
+ /**
17
+ * Convert an unknown error into a minimal, serializable object.
18
+ * Includes name and message (and stack in development).
19
+ */
20
+ function defaultSerializeError(err) {
21
+ if (err instanceof Error) {
22
+ const obj = {
23
+ name: err.name,
24
+ message: err.message
25
+ };
26
+ if (process.env.NODE_ENV === "development") obj.stack = err.stack;
27
+ return obj;
28
+ }
29
+ return { data: err };
30
+ }
31
+ /** Options for configuring trailing-slash behavior. */
32
+ var trailingSlashOptions = {
33
+ always: "always",
34
+ never: "never",
35
+ preserve: "preserve"
36
+ };
37
+ /**
38
+ * Compute whether path, href or hash changed between previous and current
39
+ * resolved locations.
40
+ */
41
+ function getLocationChangeInfo(location, resolvedLocation) {
42
+ const fromLocation = resolvedLocation;
43
+ const toLocation = location;
44
+ return {
45
+ fromLocation,
46
+ toLocation,
47
+ pathChanged: fromLocation?.pathname !== toLocation.pathname,
48
+ hrefChanged: fromLocation?.href !== toLocation.href,
49
+ hashChanged: fromLocation?.hash !== toLocation.hash
50
+ };
51
+ }
52
+ /**
53
+ * Core, framework-agnostic router engine that powers TanStack Router.
54
+ *
55
+ * Provides navigation, matching, loading, preloading, caching and event APIs
56
+ * used by framework adapters (React/Solid). Prefer framework helpers like
57
+ * `createRouter` in app code.
58
+ *
59
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/RouterType
60
+ */
61
+ var RouterCore = class {
62
+ /**
63
+ * @deprecated Use the `createRouter` function instead
64
+ */
65
+ constructor(options, getStoreConfig) {
66
+ this.tempLocationKey = `${Math.round(Math.random() * 1e7)}`;
67
+ this.resetNextScroll = true;
68
+ this.shouldViewTransition = void 0;
69
+ this.isViewTransitionTypesSupported = void 0;
70
+ this.subscribers = /* @__PURE__ */ new Set();
71
+ this.isScrollRestoring = false;
72
+ this.isScrollRestorationSetup = false;
73
+ this.startTransition = (fn) => fn();
74
+ this.update = (newOptions) => {
75
+ if (process.env.NODE_ENV !== "production") {
76
+ if (newOptions.notFoundRoute) console.warn("The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info.");
77
+ }
78
+ const prevOptions = this.options;
79
+ const prevBasepath = this.basepath ?? prevOptions?.basepath ?? "/";
80
+ const basepathWasUnset = this.basepath === void 0;
81
+ const prevRewriteOption = prevOptions?.rewrite;
82
+ this.options = {
83
+ ...prevOptions,
84
+ ...newOptions
85
+ };
86
+ this.isServer = this.options.isServer ?? typeof document === "undefined";
87
+ this.protocolAllowlist = new Set(this.options.protocolAllowlist);
88
+ if (this.options.pathParamsAllowedCharacters) this.pathParamsDecoder = require_path.compileDecodeCharMap(this.options.pathParamsAllowedCharacters);
89
+ if (!this.history || this.options.history && this.options.history !== this.history) if (!this.options.history) {
90
+ if (typeof window !== "undefined") this.history = (0, _benjavicente_history.createBrowserHistory)();
91
+ } else this.history = this.options.history;
92
+ this.origin = this.options.origin;
93
+ if (!this.origin) {
94
+ const win = globalThis.window;
95
+ if (win && win.origin && win.origin !== "null") this.origin = win.origin;
96
+ else this.origin = "http://localhost";
97
+ }
98
+ if (this.history) this.updateLatestLocation();
99
+ if (this.options.routeTree !== this.routeTree) {
100
+ this.routeTree = this.options.routeTree;
101
+ let processRouteTreeResult;
102
+ if ((_benjavicente_router_core_isServer.isServer ?? this.isServer) && process.env.NODE_ENV !== "development" && globalThis.__TSR_CACHE__ && globalThis.__TSR_CACHE__.routeTree === this.routeTree) {
103
+ const cached = globalThis.__TSR_CACHE__;
104
+ this.resolvePathCache = cached.resolvePathCache;
105
+ processRouteTreeResult = cached.processRouteTreeResult;
106
+ } else {
107
+ this.resolvePathCache = require_lru_cache.createLRUCache(1e3);
108
+ processRouteTreeResult = this.buildRouteTree();
109
+ if ((_benjavicente_router_core_isServer.isServer ?? this.isServer) && process.env.NODE_ENV !== "development" && globalThis.__TSR_CACHE__ === void 0) globalThis.__TSR_CACHE__ = {
110
+ routeTree: this.routeTree,
111
+ processRouteTreeResult,
112
+ resolvePathCache: this.resolvePathCache
113
+ };
114
+ }
115
+ this.setRoutes(processRouteTreeResult);
116
+ }
117
+ if (!this.stores && this.latestLocation) {
118
+ const config = this.getStoreConfig(this);
119
+ this.batch = config.batch;
120
+ this.stores = require_stores.createRouterStores(getInitialRouterState(this.latestLocation), config);
121
+ if (!(_benjavicente_router_core_isServer.isServer ?? this.isServer)) require_scroll_restoration.setupScrollRestoration(this);
122
+ }
123
+ let needsLocationUpdate = false;
124
+ const nextBasepath = this.options.basepath ?? "/";
125
+ const nextRewriteOption = this.options.rewrite;
126
+ if (basepathWasUnset || prevBasepath !== nextBasepath || prevRewriteOption !== nextRewriteOption) {
127
+ this.basepath = nextBasepath;
128
+ const rewrites = [];
129
+ const trimmed = require_path.trimPath(nextBasepath);
130
+ if (trimmed && trimmed !== "/") rewrites.push(require_rewrite.rewriteBasepath({ basepath: nextBasepath }));
131
+ if (nextRewriteOption) rewrites.push(nextRewriteOption);
132
+ this.rewrite = rewrites.length === 0 ? void 0 : rewrites.length === 1 ? rewrites[0] : require_rewrite.composeRewrites(rewrites);
133
+ if (this.history) this.updateLatestLocation();
134
+ needsLocationUpdate = true;
135
+ }
136
+ if (needsLocationUpdate && this.stores) this.stores.location.setState(() => this.latestLocation);
137
+ if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") this.isViewTransitionTypesSupported = window.CSS.supports("selector(:active-view-transition-type(a)");
138
+ };
139
+ this.updateLatestLocation = () => {
140
+ this.latestLocation = this.parseLocation(this.history.location, this.latestLocation);
141
+ };
142
+ this.buildRouteTree = () => {
143
+ const result = require_new_process_route_tree.processRouteTree(this.routeTree, this.options.caseSensitive, (route, i) => {
144
+ route.init({ originalIndex: i });
145
+ });
146
+ if (this.options.routeMasks) require_new_process_route_tree.processRouteMasks(this.options.routeMasks, result.processedTree);
147
+ return result;
148
+ };
149
+ this.subscribe = (eventType, fn) => {
150
+ const listener = {
151
+ eventType,
152
+ fn
153
+ };
154
+ this.subscribers.add(listener);
155
+ return () => {
156
+ this.subscribers.delete(listener);
157
+ };
158
+ };
159
+ this.emit = (routerEvent) => {
160
+ this.subscribers.forEach((listener) => {
161
+ if (listener.eventType === routerEvent.type) listener.fn(routerEvent);
162
+ });
163
+ };
164
+ this.parseLocation = (locationToParse, previousLocation) => {
165
+ const parse = ({ pathname, search, hash, href, state }) => {
166
+ if (!this.rewrite && !/[ \x00-\x1f\x7f\u0080-\uffff]/.test(pathname)) {
167
+ const parsedSearch = this.options.parseSearch(search);
168
+ const searchStr = this.options.stringifySearch(parsedSearch);
169
+ return {
170
+ href: pathname + searchStr + hash,
171
+ publicHref: pathname + searchStr + hash,
172
+ pathname: require_utils.decodePath(pathname).path,
173
+ external: false,
174
+ searchStr,
175
+ search: require_utils.nullReplaceEqualDeep(previousLocation?.search, parsedSearch),
176
+ hash: require_utils.decodePath(hash.slice(1)).path,
177
+ state: require_utils.replaceEqualDeep(previousLocation?.state, state)
178
+ };
179
+ }
180
+ const fullUrl = new URL(href, this.origin);
181
+ const url = require_rewrite.executeRewriteInput(this.rewrite, fullUrl);
182
+ const parsedSearch = this.options.parseSearch(url.search);
183
+ const searchStr = this.options.stringifySearch(parsedSearch);
184
+ url.search = searchStr;
185
+ return {
186
+ href: url.href.replace(url.origin, ""),
187
+ publicHref: href,
188
+ pathname: require_utils.decodePath(url.pathname).path,
189
+ external: !!this.rewrite && url.origin !== this.origin,
190
+ searchStr,
191
+ search: require_utils.nullReplaceEqualDeep(previousLocation?.search, parsedSearch),
192
+ hash: require_utils.decodePath(url.hash.slice(1)).path,
193
+ state: require_utils.replaceEqualDeep(previousLocation?.state, state)
194
+ };
195
+ };
196
+ const location = parse(locationToParse);
197
+ const { __tempLocation, __tempKey } = location.state;
198
+ if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
199
+ const parsedTempLocation = parse(__tempLocation);
200
+ parsedTempLocation.state.key = location.state.key;
201
+ parsedTempLocation.state.__TSR_key = location.state.__TSR_key;
202
+ delete parsedTempLocation.state.__tempLocation;
203
+ return {
204
+ ...parsedTempLocation,
205
+ maskedLocation: location
206
+ };
207
+ }
208
+ return location;
209
+ };
210
+ this.resolvePathWithBase = (from, path) => {
211
+ return require_path.resolvePath({
212
+ base: from,
213
+ to: require_path.cleanPath(path),
214
+ trailingSlash: this.options.trailingSlash,
215
+ cache: this.resolvePathCache
216
+ });
217
+ };
218
+ this.matchRoutes = (pathnameOrNext, locationSearchOrOpts, opts) => {
219
+ if (typeof pathnameOrNext === "string") return this.matchRoutesInternal({
220
+ pathname: pathnameOrNext,
221
+ search: locationSearchOrOpts
222
+ }, opts);
223
+ return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
224
+ };
225
+ this.getMatchedRoutes = (pathname) => {
226
+ return getMatchedRoutes({
227
+ pathname,
228
+ routesById: this.routesById,
229
+ processedTree: this.processedTree
230
+ });
231
+ };
232
+ this.cancelMatch = (id) => {
233
+ const match = this.getMatch(id);
234
+ if (!match) return;
235
+ match.abortController.abort();
236
+ clearTimeout(match._nonReactive.pendingTimeout);
237
+ match._nonReactive.pendingTimeout = void 0;
238
+ };
239
+ this.cancelMatches = () => {
240
+ this.stores.pendingMatchesId.state.forEach((matchId) => {
241
+ this.cancelMatch(matchId);
242
+ });
243
+ this.stores.matchesId.state.forEach((matchId) => {
244
+ if (this.stores.pendingMatchStoresById.has(matchId)) return;
245
+ const match = this.stores.activeMatchStoresById.get(matchId)?.state;
246
+ if (!match) return;
247
+ if (match.status === "pending" || match.isFetching === "loader") this.cancelMatch(matchId);
248
+ });
249
+ };
250
+ this.buildLocation = (opts) => {
251
+ const build = (dest = {}) => {
252
+ const currentLocation = dest._fromLocation || this.pendingBuiltLocation || this.latestLocation;
253
+ const lightweightResult = this.matchRoutesLightweight(currentLocation);
254
+ if (dest.from && process.env.NODE_ENV !== "production" && dest._isNavigate) {
255
+ const allFromMatches = this.getMatchedRoutes(dest.from).matchedRoutes;
256
+ const matchedFrom = require_utils.findLast(lightweightResult.matchedRoutes, (d) => {
257
+ return comparePaths(d.fullPath, dest.from);
258
+ });
259
+ const matchedCurrent = require_utils.findLast(allFromMatches, (d) => {
260
+ return comparePaths(d.fullPath, lightweightResult.fullPath);
261
+ });
262
+ if (!matchedFrom && !matchedCurrent) console.warn(`Could not find match for from: ${dest.from}`);
263
+ }
264
+ const defaultedFromPath = dest.unsafeRelative === "path" ? currentLocation.pathname : dest.from ?? lightweightResult.fullPath;
265
+ const fromPath = this.resolvePathWithBase(defaultedFromPath, ".");
266
+ const fromSearch = lightweightResult.search;
267
+ const fromParams = Object.assign(Object.create(null), lightweightResult.params);
268
+ const nextTo = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
269
+ const nextParams = dest.params === false || dest.params === null ? Object.create(null) : (dest.params ?? true) === true ? fromParams : Object.assign(fromParams, require_utils.functionalUpdate(dest.params, fromParams));
270
+ const destMatchResult = this.getMatchedRoutes(nextTo);
271
+ let destRoutes = destMatchResult.matchedRoutes;
272
+ if ((!destMatchResult.foundRoute || destMatchResult.foundRoute.path !== "/" && destMatchResult.routeParams["**"]) && this.options.notFoundRoute) destRoutes = [...destRoutes, this.options.notFoundRoute];
273
+ if (Object.keys(nextParams).length > 0) for (const route of destRoutes) {
274
+ const fn = route.options.params?.stringify ?? route.options.stringifyParams;
275
+ if (fn) try {
276
+ Object.assign(nextParams, fn(nextParams));
277
+ } catch {}
278
+ }
279
+ const nextPathname = opts.leaveParams ? nextTo : require_utils.decodePath(require_path.interpolatePath({
280
+ path: nextTo,
281
+ params: nextParams,
282
+ decoder: this.pathParamsDecoder,
283
+ server: this.isServer
284
+ }).interpolatedPath).path;
285
+ let nextSearch = fromSearch;
286
+ if (opts._includeValidateSearch && this.options.search?.strict) {
287
+ const validatedSearch = {};
288
+ destRoutes.forEach((route) => {
289
+ if (route.options.validateSearch) try {
290
+ Object.assign(validatedSearch, validateSearch(route.options.validateSearch, {
291
+ ...validatedSearch,
292
+ ...nextSearch
293
+ }));
294
+ } catch {}
295
+ });
296
+ nextSearch = validatedSearch;
297
+ }
298
+ nextSearch = applySearchMiddleware({
299
+ search: nextSearch,
300
+ dest,
301
+ destRoutes,
302
+ _includeValidateSearch: opts._includeValidateSearch
303
+ });
304
+ nextSearch = require_utils.nullReplaceEqualDeep(fromSearch, nextSearch);
305
+ const searchStr = this.options.stringifySearch(nextSearch);
306
+ const hash = dest.hash === true ? currentLocation.hash : dest.hash ? require_utils.functionalUpdate(dest.hash, currentLocation.hash) : void 0;
307
+ const hashStr = hash ? `#${hash}` : "";
308
+ let nextState = dest.state === true ? currentLocation.state : dest.state ? require_utils.functionalUpdate(dest.state, currentLocation.state) : {};
309
+ nextState = require_utils.replaceEqualDeep(currentLocation.state, nextState);
310
+ const fullPath = `${nextPathname}${searchStr}${hashStr}`;
311
+ let href;
312
+ let publicHref;
313
+ let external = false;
314
+ if (this.rewrite) {
315
+ const url = new URL(fullPath, this.origin);
316
+ const rewrittenUrl = require_rewrite.executeRewriteOutput(this.rewrite, url);
317
+ href = url.href.replace(url.origin, "");
318
+ if (rewrittenUrl.origin !== this.origin) {
319
+ publicHref = rewrittenUrl.href;
320
+ external = true;
321
+ } else publicHref = rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash;
322
+ } else {
323
+ href = require_utils.encodePathLikeUrl(fullPath);
324
+ publicHref = href;
325
+ }
326
+ return {
327
+ publicHref,
328
+ href,
329
+ pathname: nextPathname,
330
+ search: nextSearch,
331
+ searchStr,
332
+ state: nextState,
333
+ hash: hash ?? "",
334
+ external,
335
+ unmaskOnReload: dest.unmaskOnReload
336
+ };
337
+ };
338
+ const buildWithMatches = (dest = {}, maskedDest) => {
339
+ const next = build(dest);
340
+ let maskedNext = maskedDest ? build(maskedDest) : void 0;
341
+ if (!maskedNext) {
342
+ const params = Object.create(null);
343
+ if (this.options.routeMasks) {
344
+ const match = require_new_process_route_tree.findFlatMatch(next.pathname, this.processedTree);
345
+ if (match) {
346
+ Object.assign(params, match.rawParams);
347
+ const { from: _from, params: maskParams, ...maskProps } = match.route;
348
+ const nextParams = maskParams === false || maskParams === null ? Object.create(null) : (maskParams ?? true) === true ? params : Object.assign(params, require_utils.functionalUpdate(maskParams, params));
349
+ maskedDest = {
350
+ from: opts.from,
351
+ ...maskProps,
352
+ params: nextParams
353
+ };
354
+ maskedNext = build(maskedDest);
355
+ }
356
+ }
357
+ }
358
+ if (maskedNext) next.maskedLocation = maskedNext;
359
+ return next;
360
+ };
361
+ if (opts.mask) return buildWithMatches(opts, {
362
+ from: opts.from,
363
+ ...opts.mask
364
+ });
365
+ return buildWithMatches(opts);
366
+ };
367
+ this.commitLocation = async ({ viewTransition, ignoreBlocker, ...next }) => {
368
+ const isSameState = () => {
369
+ const ignoredProps = [
370
+ "key",
371
+ "__TSR_key",
372
+ "__TSR_index",
373
+ "__hashScrollIntoViewOptions"
374
+ ];
375
+ ignoredProps.forEach((prop) => {
376
+ next.state[prop] = this.latestLocation.state[prop];
377
+ });
378
+ const isEqual = require_utils.deepEqual(next.state, this.latestLocation.state);
379
+ ignoredProps.forEach((prop) => {
380
+ delete next.state[prop];
381
+ });
382
+ return isEqual;
383
+ };
384
+ const isSameUrl = require_path.trimPathRight(this.latestLocation.href) === require_path.trimPathRight(next.href);
385
+ let previousCommitPromise = this.commitLocationPromise;
386
+ this.commitLocationPromise = require_utils.createControlledPromise(() => {
387
+ previousCommitPromise?.resolve();
388
+ previousCommitPromise = void 0;
389
+ });
390
+ if (isSameUrl && isSameState()) this.load();
391
+ else {
392
+ let { maskedLocation, hashScrollIntoView, ...nextHistory } = next;
393
+ if (maskedLocation) {
394
+ nextHistory = {
395
+ ...maskedLocation,
396
+ state: {
397
+ ...maskedLocation.state,
398
+ __tempKey: void 0,
399
+ __tempLocation: {
400
+ ...nextHistory,
401
+ search: nextHistory.searchStr,
402
+ state: {
403
+ ...nextHistory.state,
404
+ __tempKey: void 0,
405
+ __tempLocation: void 0,
406
+ __TSR_key: void 0,
407
+ key: void 0
408
+ }
409
+ }
410
+ }
411
+ };
412
+ if (nextHistory.unmaskOnReload ?? this.options.unmaskOnReload ?? false) nextHistory.state.__tempKey = this.tempLocationKey;
413
+ }
414
+ nextHistory.state.__hashScrollIntoViewOptions = hashScrollIntoView ?? this.options.defaultHashScrollIntoView ?? true;
415
+ this.shouldViewTransition = viewTransition;
416
+ this.history[next.replace ? "replace" : "push"](nextHistory.publicHref, nextHistory.state, { ignoreBlocker });
417
+ }
418
+ this.resetNextScroll = next.resetScroll ?? true;
419
+ if (!this.history.subscribers.size) this.load();
420
+ return this.commitLocationPromise;
421
+ };
422
+ this.buildAndCommitLocation = ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest } = {}) => {
423
+ if (href) {
424
+ const currentIndex = this.history.location.state.__TSR_index;
425
+ const parsed = (0, _benjavicente_history.parseHref)(href, { __TSR_index: replace ? currentIndex : currentIndex + 1 });
426
+ const hrefUrl = new URL(parsed.pathname, this.origin);
427
+ rest.to = require_rewrite.executeRewriteInput(this.rewrite, hrefUrl).pathname;
428
+ rest.search = this.options.parseSearch(parsed.search);
429
+ rest.hash = parsed.hash.slice(1);
430
+ }
431
+ const location = this.buildLocation({
432
+ ...rest,
433
+ _includeValidateSearch: true
434
+ });
435
+ this.pendingBuiltLocation = location;
436
+ const commitPromise = this.commitLocation({
437
+ ...location,
438
+ viewTransition,
439
+ replace,
440
+ resetScroll,
441
+ hashScrollIntoView,
442
+ ignoreBlocker
443
+ });
444
+ Promise.resolve().then(() => {
445
+ if (this.pendingBuiltLocation === location) this.pendingBuiltLocation = void 0;
446
+ });
447
+ return commitPromise;
448
+ };
449
+ this.navigate = async ({ to, reloadDocument, href, publicHref, ...rest }) => {
450
+ let hrefIsUrl = false;
451
+ if (href) try {
452
+ new URL(`${href}`);
453
+ hrefIsUrl = true;
454
+ } catch {}
455
+ if (hrefIsUrl && !reloadDocument) reloadDocument = true;
456
+ if (reloadDocument) {
457
+ if (to !== void 0 || !href) {
458
+ const location = this.buildLocation({
459
+ to,
460
+ ...rest
461
+ });
462
+ href = href ?? location.publicHref;
463
+ publicHref = publicHref ?? location.publicHref;
464
+ }
465
+ const reloadHref = !hrefIsUrl && publicHref ? publicHref : href;
466
+ if (require_utils.isDangerousProtocol(reloadHref, this.protocolAllowlist)) {
467
+ if (process.env.NODE_ENV !== "production") console.warn(`Blocked navigation to dangerous protocol: ${reloadHref}`);
468
+ return Promise.resolve();
469
+ }
470
+ if (!rest.ignoreBlocker) {
471
+ const blockers = this.history.getBlockers?.() ?? [];
472
+ for (const blocker of blockers) if (blocker?.blockerFn) {
473
+ if (await blocker.blockerFn({
474
+ currentLocation: this.latestLocation,
475
+ nextLocation: this.latestLocation,
476
+ action: "PUSH"
477
+ })) return Promise.resolve();
478
+ }
479
+ }
480
+ if (rest.replace) window.location.replace(reloadHref);
481
+ else window.location.href = reloadHref;
482
+ return Promise.resolve();
483
+ }
484
+ return this.buildAndCommitLocation({
485
+ ...rest,
486
+ href,
487
+ to,
488
+ _isNavigate: true
489
+ });
490
+ };
491
+ this.beforeLoad = () => {
492
+ this.cancelMatches();
493
+ this.updateLatestLocation();
494
+ if (_benjavicente_router_core_isServer.isServer ?? this.isServer) {
495
+ const nextLocation = this.buildLocation({
496
+ to: this.latestLocation.pathname,
497
+ search: true,
498
+ params: true,
499
+ hash: true,
500
+ state: true,
501
+ _includeValidateSearch: true
502
+ });
503
+ if (this.latestLocation.publicHref !== nextLocation.publicHref) {
504
+ const href = this.getParsedLocationHref(nextLocation);
505
+ if (nextLocation.external) throw require_redirect.redirect({ href });
506
+ else throw require_redirect.redirect({
507
+ href,
508
+ _builtLocation: nextLocation
509
+ });
510
+ }
511
+ }
512
+ const pendingMatches = this.matchRoutes(this.latestLocation);
513
+ const nextCachedMatches = this.stores.cachedMatchesSnapshot.state.filter((d) => !pendingMatches.some((e) => e.id === d.id));
514
+ this.batch(() => {
515
+ this.stores.status.setState(() => "pending");
516
+ this.stores.statusCode.setState(() => 200);
517
+ this.stores.isLoading.setState(() => true);
518
+ this.stores.location.setState(() => this.latestLocation);
519
+ this.stores.setPendingMatches(pendingMatches);
520
+ this.stores.setCachedMatches(nextCachedMatches);
521
+ });
522
+ };
523
+ this.load = async (opts) => {
524
+ let redirect;
525
+ let notFound;
526
+ let loadPromise;
527
+ const previousLocation = this.stores.resolvedLocation.state ?? this.stores.location.state;
528
+ loadPromise = new Promise((resolve) => {
529
+ this.startTransition(async () => {
530
+ try {
531
+ this.beforeLoad();
532
+ const next = this.latestLocation;
533
+ const prevLocation = this.stores.resolvedLocation.state;
534
+ const locationChangeInfo = getLocationChangeInfo(next, prevLocation);
535
+ if (!this.stores.redirect.state) this.emit({
536
+ type: "onBeforeNavigate",
537
+ ...locationChangeInfo
538
+ });
539
+ this.emit({
540
+ type: "onBeforeLoad",
541
+ ...locationChangeInfo
542
+ });
543
+ await require_load_matches.loadMatches({
544
+ router: this,
545
+ sync: opts?.sync,
546
+ forceStaleReload: previousLocation.href === next.href,
547
+ matches: this.stores.pendingMatchesSnapshot.state,
548
+ location: next,
549
+ updateMatch: this.updateMatch,
550
+ onReady: async () => {
551
+ this.startTransition(() => {
552
+ this.startViewTransition(async () => {
553
+ let exitingMatches = null;
554
+ let hookExitingMatches = null;
555
+ let hookEnteringMatches = null;
556
+ let hookStayingMatches = null;
557
+ this.batch(() => {
558
+ const pendingMatches = this.stores.pendingMatchesSnapshot.state;
559
+ const mountPending = pendingMatches.length;
560
+ const currentMatches = this.stores.activeMatchesSnapshot.state;
561
+ exitingMatches = mountPending ? currentMatches.filter((match) => !this.stores.pendingMatchStoresById.has(match.id)) : null;
562
+ const pendingRouteIds = /* @__PURE__ */ new Set();
563
+ for (const s of this.stores.pendingMatchStoresById.values()) if (s.routeId) pendingRouteIds.add(s.routeId);
564
+ const activeRouteIds = /* @__PURE__ */ new Set();
565
+ for (const s of this.stores.activeMatchStoresById.values()) if (s.routeId) activeRouteIds.add(s.routeId);
566
+ hookExitingMatches = mountPending ? currentMatches.filter((match) => !pendingRouteIds.has(match.routeId)) : null;
567
+ hookEnteringMatches = mountPending ? pendingMatches.filter((match) => !activeRouteIds.has(match.routeId)) : null;
568
+ hookStayingMatches = mountPending ? pendingMatches.filter((match) => activeRouteIds.has(match.routeId)) : currentMatches;
569
+ this.stores.isLoading.setState(() => false);
570
+ this.stores.loadedAt.setState(() => Date.now());
571
+ /**
572
+ * When committing new matches, cache any exiting matches that are still usable.
573
+ * Routes that resolved with `status: 'error'` or `status: 'notFound'` are
574
+ * deliberately excluded from `cachedMatches` so that subsequent invalidations
575
+ * or reloads re-run their loaders instead of reusing the failed/not-found data.
576
+ */
577
+ if (mountPending) {
578
+ this.stores.setActiveMatches(pendingMatches);
579
+ this.stores.setPendingMatches([]);
580
+ this.stores.setCachedMatches([...this.stores.cachedMatchesSnapshot.state, ...exitingMatches.filter((d) => d.status !== "error" && d.status !== "notFound" && d.status !== "redirected")]);
581
+ this.clearExpiredCache();
582
+ }
583
+ });
584
+ for (const [matches, hook] of [
585
+ [hookExitingMatches, "onLeave"],
586
+ [hookEnteringMatches, "onEnter"],
587
+ [hookStayingMatches, "onStay"]
588
+ ]) {
589
+ if (!matches) continue;
590
+ for (const match of matches) this.looseRoutesById[match.routeId].options[hook]?.(match);
591
+ }
592
+ });
593
+ });
594
+ }
595
+ });
596
+ } catch (err) {
597
+ if (require_redirect.isRedirect(err)) {
598
+ redirect = err;
599
+ if (!(_benjavicente_router_core_isServer.isServer ?? this.isServer)) this.navigate({
600
+ ...redirect.options,
601
+ replace: true,
602
+ ignoreBlocker: true
603
+ });
604
+ } else if (require_not_found.isNotFound(err)) notFound = err;
605
+ const nextStatusCode = redirect ? redirect.status : notFound ? 404 : this.stores.activeMatchesSnapshot.state.some((d) => d.status === "error") ? 500 : 200;
606
+ this.batch(() => {
607
+ this.stores.statusCode.setState(() => nextStatusCode);
608
+ this.stores.redirect.setState(() => redirect);
609
+ });
610
+ }
611
+ if (this.latestLoadPromise === loadPromise) {
612
+ this.commitLocationPromise?.resolve();
613
+ this.latestLoadPromise = void 0;
614
+ this.commitLocationPromise = void 0;
615
+ }
616
+ resolve();
617
+ });
618
+ });
619
+ this.latestLoadPromise = loadPromise;
620
+ await loadPromise;
621
+ while (this.latestLoadPromise && loadPromise !== this.latestLoadPromise) await this.latestLoadPromise;
622
+ let newStatusCode = void 0;
623
+ if (this.hasNotFoundMatch()) newStatusCode = 404;
624
+ else if (this.stores.activeMatchesSnapshot.state.some((d) => d.status === "error")) newStatusCode = 500;
625
+ if (newStatusCode !== void 0) this.stores.statusCode.setState(() => newStatusCode);
626
+ };
627
+ this.startViewTransition = (fn) => {
628
+ const shouldViewTransition = this.shouldViewTransition ?? this.options.defaultViewTransition;
629
+ this.shouldViewTransition = void 0;
630
+ if (shouldViewTransition && typeof document !== "undefined" && "startViewTransition" in document && typeof document.startViewTransition === "function") {
631
+ let startViewTransitionParams;
632
+ if (typeof shouldViewTransition === "object" && this.isViewTransitionTypesSupported) {
633
+ const next = this.latestLocation;
634
+ const prevLocation = this.stores.resolvedLocation.state;
635
+ const resolvedViewTransitionTypes = typeof shouldViewTransition.types === "function" ? shouldViewTransition.types(getLocationChangeInfo(next, prevLocation)) : shouldViewTransition.types;
636
+ if (resolvedViewTransitionTypes === false) {
637
+ fn();
638
+ return;
639
+ }
640
+ startViewTransitionParams = {
641
+ update: fn,
642
+ types: resolvedViewTransitionTypes
643
+ };
644
+ } else startViewTransitionParams = fn;
645
+ document.startViewTransition(startViewTransitionParams);
646
+ } else fn();
647
+ };
648
+ this.updateMatch = (id, updater) => {
649
+ this.startTransition(() => {
650
+ const pendingMatch = this.stores.pendingMatchStoresById.get(id);
651
+ if (pendingMatch) {
652
+ pendingMatch.setState(updater);
653
+ return;
654
+ }
655
+ const activeMatch = this.stores.activeMatchStoresById.get(id);
656
+ if (activeMatch) {
657
+ activeMatch.setState(updater);
658
+ return;
659
+ }
660
+ const cachedMatch = this.stores.cachedMatchStoresById.get(id);
661
+ if (cachedMatch) {
662
+ const next = updater(cachedMatch.state);
663
+ if (next.status === "redirected") {
664
+ if (this.stores.cachedMatchStoresById.delete(id)) this.stores.cachedMatchesId.setState((prev) => prev.filter((matchId) => matchId !== id));
665
+ } else cachedMatch.setState(() => next);
666
+ }
667
+ });
668
+ };
669
+ this.getMatch = (matchId) => {
670
+ return this.stores.cachedMatchStoresById.get(matchId)?.state ?? this.stores.pendingMatchStoresById.get(matchId)?.state ?? this.stores.activeMatchStoresById.get(matchId)?.state;
671
+ };
672
+ this.invalidate = (opts) => {
673
+ const invalidate = (d) => {
674
+ if (opts?.filter?.(d) ?? true) return {
675
+ ...d,
676
+ invalid: true,
677
+ ...opts?.forcePending || d.status === "error" || d.status === "notFound" ? {
678
+ status: "pending",
679
+ error: void 0
680
+ } : void 0
681
+ };
682
+ return d;
683
+ };
684
+ this.batch(() => {
685
+ this.stores.setActiveMatches(this.stores.activeMatchesSnapshot.state.map(invalidate));
686
+ this.stores.setCachedMatches(this.stores.cachedMatchesSnapshot.state.map(invalidate));
687
+ this.stores.setPendingMatches(this.stores.pendingMatchesSnapshot.state.map(invalidate));
688
+ });
689
+ this.shouldViewTransition = false;
690
+ return this.load({ sync: opts?.sync });
691
+ };
692
+ this.getParsedLocationHref = (location) => {
693
+ return location.publicHref || "/";
694
+ };
695
+ this.resolveRedirect = (redirect) => {
696
+ const locationHeader = redirect.headers.get("Location");
697
+ if (!redirect.options.href || redirect.options._builtLocation) {
698
+ const location = redirect.options._builtLocation ?? this.buildLocation(redirect.options);
699
+ const href = this.getParsedLocationHref(location);
700
+ redirect.options.href = href;
701
+ redirect.headers.set("Location", href);
702
+ } else if (locationHeader) try {
703
+ const url = new URL(locationHeader);
704
+ if (this.origin && url.origin === this.origin) {
705
+ const href = url.pathname + url.search + url.hash;
706
+ redirect.options.href = href;
707
+ redirect.headers.set("Location", href);
708
+ }
709
+ } catch {}
710
+ if (redirect.options.href && !redirect.options._builtLocation && require_utils.isDangerousProtocol(redirect.options.href, this.protocolAllowlist)) throw new Error(process.env.NODE_ENV !== "production" ? `Redirect blocked: unsafe protocol in href "${redirect.options.href}". Allowed protocols: ${Array.from(this.protocolAllowlist).join(", ")}.` : "Redirect blocked: unsafe protocol");
711
+ if (!redirect.headers.get("Location")) redirect.headers.set("Location", redirect.options.href);
712
+ return redirect;
713
+ };
714
+ this.clearCache = (opts) => {
715
+ const filter = opts?.filter;
716
+ if (filter !== void 0) this.stores.setCachedMatches(this.stores.cachedMatchesSnapshot.state.filter((m) => !filter(m)));
717
+ else this.stores.setCachedMatches([]);
718
+ };
719
+ this.clearExpiredCache = () => {
720
+ const now = Date.now();
721
+ const filter = (d) => {
722
+ const route = this.looseRoutesById[d.routeId];
723
+ if (!route.options.loader) return true;
724
+ const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 300 * 1e3;
725
+ if (d.status === "error") return true;
726
+ return now - d.updatedAt >= gcTime;
727
+ };
728
+ this.clearCache({ filter });
729
+ };
730
+ this.loadRouteChunk = require_load_matches.loadRouteChunk;
731
+ this.preloadRoute = async (opts) => {
732
+ const next = opts._builtLocation ?? this.buildLocation(opts);
733
+ let matches = this.matchRoutes(next, {
734
+ throwOnError: true,
735
+ preload: true,
736
+ dest: opts
737
+ });
738
+ const activeMatchIds = new Set([...this.stores.matchesId.state, ...this.stores.pendingMatchesId.state]);
739
+ const loadedMatchIds = new Set([...activeMatchIds, ...this.stores.cachedMatchesId.state]);
740
+ const matchesToCache = matches.filter((match) => !loadedMatchIds.has(match.id));
741
+ if (matchesToCache.length) {
742
+ const cachedMatches = this.stores.cachedMatchesSnapshot.state;
743
+ this.stores.setCachedMatches([...cachedMatches, ...matchesToCache]);
744
+ }
745
+ try {
746
+ matches = await require_load_matches.loadMatches({
747
+ router: this,
748
+ matches,
749
+ location: next,
750
+ preload: true,
751
+ updateMatch: (id, updater) => {
752
+ if (activeMatchIds.has(id)) matches = matches.map((d) => d.id === id ? updater(d) : d);
753
+ else this.updateMatch(id, updater);
754
+ }
755
+ });
756
+ return matches;
757
+ } catch (err) {
758
+ if (require_redirect.isRedirect(err)) {
759
+ if (err.options.reloadDocument) return;
760
+ return await this.preloadRoute({
761
+ ...err.options,
762
+ _fromLocation: next
763
+ });
764
+ }
765
+ if (!require_not_found.isNotFound(err)) console.error(err);
766
+ return;
767
+ }
768
+ };
769
+ this.matchRoute = (location, opts) => {
770
+ const matchLocation = {
771
+ ...location,
772
+ to: location.to ? this.resolvePathWithBase(location.from || "", location.to) : void 0,
773
+ params: location.params || {},
774
+ leaveParams: true
775
+ };
776
+ const next = this.buildLocation(matchLocation);
777
+ if (opts?.pending && this.stores.status.state !== "pending") return false;
778
+ const baseLocation = (opts?.pending === void 0 ? !this.stores.isLoading.state : opts.pending) ? this.latestLocation : this.stores.resolvedLocation.state || this.stores.location.state;
779
+ const match = require_new_process_route_tree.findSingleMatch(next.pathname, opts?.caseSensitive ?? false, opts?.fuzzy ?? false, baseLocation.pathname, this.processedTree);
780
+ if (!match) return false;
781
+ if (location.params) {
782
+ if (!require_utils.deepEqual(match.rawParams, location.params, { partial: true })) return false;
783
+ }
784
+ if (opts?.includeSearch ?? true) return require_utils.deepEqual(baseLocation.search, next.search, { partial: true }) ? match.rawParams : false;
785
+ return match.rawParams;
786
+ };
787
+ this.hasNotFoundMatch = () => {
788
+ return this.stores.activeMatchesSnapshot.state.some((d) => d.status === "notFound" || d.globalNotFound);
789
+ };
790
+ this.getStoreConfig = getStoreConfig;
791
+ this.update({
792
+ defaultPreloadDelay: 50,
793
+ defaultPendingMs: 1e3,
794
+ defaultPendingMinMs: 500,
795
+ context: void 0,
796
+ ...options,
797
+ caseSensitive: options.caseSensitive ?? false,
798
+ notFoundMode: options.notFoundMode ?? "fuzzy",
799
+ stringifySearch: options.stringifySearch ?? require_searchParams.defaultStringifySearch,
800
+ parseSearch: options.parseSearch ?? require_searchParams.defaultParseSearch,
801
+ protocolAllowlist: options.protocolAllowlist ?? require_utils.DEFAULT_PROTOCOL_ALLOWLIST
802
+ });
803
+ if (typeof document !== "undefined") self.__TSR_ROUTER__ = this;
804
+ }
805
+ isShell() {
806
+ return !!this.options.isShell;
807
+ }
808
+ isPrerendering() {
809
+ return !!this.options.isPrerendering;
810
+ }
811
+ get state() {
812
+ return this.stores.__store.state;
813
+ }
814
+ setRoutes({ routesById, routesByPath, processedTree }) {
815
+ this.routesById = routesById;
816
+ this.routesByPath = routesByPath;
817
+ this.processedTree = processedTree;
818
+ const notFoundRoute = this.options.notFoundRoute;
819
+ if (notFoundRoute) {
820
+ notFoundRoute.init({ originalIndex: 99999999999 });
821
+ this.routesById[notFoundRoute.id] = notFoundRoute;
822
+ }
823
+ }
824
+ get looseRoutesById() {
825
+ return this.routesById;
826
+ }
827
+ getParentContext(parentMatch) {
828
+ return !parentMatch?.id ? this.options.context ?? void 0 : parentMatch.context ?? this.options.context ?? void 0;
829
+ }
830
+ matchRoutesInternal(next, opts) {
831
+ const matchedRoutesResult = this.getMatchedRoutes(next.pathname);
832
+ const { foundRoute, routeParams, parsedParams } = matchedRoutesResult;
833
+ let { matchedRoutes } = matchedRoutesResult;
834
+ let isGlobalNotFound = false;
835
+ if (foundRoute ? foundRoute.path !== "/" && routeParams["**"] : require_path.trimPathRight(next.pathname)) if (this.options.notFoundRoute) matchedRoutes = [...matchedRoutes, this.options.notFoundRoute];
836
+ else isGlobalNotFound = true;
837
+ const globalNotFoundRouteId = isGlobalNotFound ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes) : void 0;
838
+ const matches = new Array(matchedRoutes.length);
839
+ const previousActiveMatchesByRouteId = /* @__PURE__ */ new Map();
840
+ for (const store of this.stores.activeMatchStoresById.values()) if (store.routeId) previousActiveMatchesByRouteId.set(store.routeId, store.state);
841
+ for (let index = 0; index < matchedRoutes.length; index++) {
842
+ const route = matchedRoutes[index];
843
+ const parentMatch = matches[index - 1];
844
+ let preMatchSearch;
845
+ let strictMatchSearch;
846
+ let searchError;
847
+ {
848
+ const parentSearch = parentMatch?.search ?? next.search;
849
+ const parentStrictSearch = parentMatch?._strictSearch ?? void 0;
850
+ try {
851
+ const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? void 0;
852
+ preMatchSearch = {
853
+ ...parentSearch,
854
+ ...strictSearch
855
+ };
856
+ strictMatchSearch = {
857
+ ...parentStrictSearch,
858
+ ...strictSearch
859
+ };
860
+ searchError = void 0;
861
+ } catch (err) {
862
+ let searchParamError = err;
863
+ if (!(err instanceof SearchParamError)) searchParamError = new SearchParamError(err.message, { cause: err });
864
+ if (opts?.throwOnError) throw searchParamError;
865
+ preMatchSearch = parentSearch;
866
+ strictMatchSearch = {};
867
+ searchError = searchParamError;
868
+ }
869
+ }
870
+ const loaderDeps = route.options.loaderDeps?.({ search: preMatchSearch }) ?? "";
871
+ const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
872
+ const { interpolatedPath, usedParams } = require_path.interpolatePath({
873
+ path: route.fullPath,
874
+ params: routeParams,
875
+ decoder: this.pathParamsDecoder,
876
+ server: this.isServer
877
+ });
878
+ const matchId = route.id + interpolatedPath + loaderDepsHash;
879
+ const existingMatch = this.getMatch(matchId);
880
+ const previousMatch = previousActiveMatchesByRouteId.get(route.id);
881
+ const strictParams = existingMatch?._strictParams ?? usedParams;
882
+ let paramsError = void 0;
883
+ if (!existingMatch) try {
884
+ extractStrictParams(route, usedParams, parsedParams, strictParams);
885
+ } catch (err) {
886
+ if (require_not_found.isNotFound(err) || require_redirect.isRedirect(err)) paramsError = err;
887
+ else paramsError = new PathParamError(err.message, { cause: err });
888
+ if (opts?.throwOnError) throw paramsError;
889
+ }
890
+ Object.assign(routeParams, strictParams);
891
+ const cause = previousMatch ? "stay" : "enter";
892
+ let match;
893
+ if (existingMatch) match = {
894
+ ...existingMatch,
895
+ cause,
896
+ params: previousMatch?.params ?? routeParams,
897
+ _strictParams: strictParams,
898
+ search: previousMatch ? require_utils.nullReplaceEqualDeep(previousMatch.search, preMatchSearch) : require_utils.nullReplaceEqualDeep(existingMatch.search, preMatchSearch),
899
+ _strictSearch: strictMatchSearch
900
+ };
901
+ else {
902
+ const status = route.options.loader || route.options.beforeLoad || route.lazyFn || require_load_matches.routeNeedsPreload(route) ? "pending" : "success";
903
+ match = {
904
+ id: matchId,
905
+ ssr: _benjavicente_router_core_isServer.isServer ?? this.isServer ? void 0 : route.options.ssr,
906
+ index,
907
+ routeId: route.id,
908
+ params: previousMatch?.params ?? routeParams,
909
+ _strictParams: strictParams,
910
+ pathname: interpolatedPath,
911
+ updatedAt: Date.now(),
912
+ search: previousMatch ? require_utils.nullReplaceEqualDeep(previousMatch.search, preMatchSearch) : preMatchSearch,
913
+ _strictSearch: strictMatchSearch,
914
+ searchError: void 0,
915
+ status,
916
+ isFetching: false,
917
+ error: void 0,
918
+ paramsError,
919
+ __routeContext: void 0,
920
+ _nonReactive: { loadPromise: require_utils.createControlledPromise() },
921
+ __beforeLoadContext: void 0,
922
+ context: {},
923
+ abortController: new AbortController(),
924
+ fetchCount: 0,
925
+ cause,
926
+ loaderDeps: previousMatch ? require_utils.replaceEqualDeep(previousMatch.loaderDeps, loaderDeps) : loaderDeps,
927
+ invalid: false,
928
+ preload: false,
929
+ links: void 0,
930
+ scripts: void 0,
931
+ headScripts: void 0,
932
+ meta: void 0,
933
+ staticData: route.options.staticData || {},
934
+ fullPath: route.fullPath
935
+ };
936
+ }
937
+ if (!opts?.preload) match.globalNotFound = globalNotFoundRouteId === route.id;
938
+ match.searchError = searchError;
939
+ const parentContext = this.getParentContext(parentMatch);
940
+ match.context = {
941
+ ...parentContext,
942
+ ...match.__routeContext,
943
+ ...match.__beforeLoadContext
944
+ };
945
+ matches[index] = match;
946
+ }
947
+ for (let index = 0; index < matches.length; index++) {
948
+ const match = matches[index];
949
+ const route = this.looseRoutesById[match.routeId];
950
+ const existingMatch = this.getMatch(match.id);
951
+ const previousMatch = previousActiveMatchesByRouteId.get(match.routeId);
952
+ match.params = previousMatch ? require_utils.nullReplaceEqualDeep(previousMatch.params, routeParams) : routeParams;
953
+ if (!existingMatch) {
954
+ const parentMatch = matches[index - 1];
955
+ const parentContext = this.getParentContext(parentMatch);
956
+ if (route.options.context) {
957
+ const contextFnContext = {
958
+ deps: match.loaderDeps,
959
+ params: match.params,
960
+ context: parentContext ?? {},
961
+ location: next,
962
+ navigate: (opts) => this.navigate({
963
+ ...opts,
964
+ _fromLocation: next
965
+ }),
966
+ buildLocation: this.buildLocation,
967
+ cause: match.cause,
968
+ abortController: match.abortController,
969
+ preload: !!match.preload,
970
+ matches,
971
+ routeId: route.id
972
+ };
973
+ match.__routeContext = route.options.context(contextFnContext) ?? void 0;
974
+ }
975
+ match.context = {
976
+ ...parentContext,
977
+ ...match.__routeContext,
978
+ ...match.__beforeLoadContext
979
+ };
980
+ }
981
+ }
982
+ return matches;
983
+ }
984
+ /**
985
+ * Lightweight route matching for buildLocation.
986
+ * Only computes fullPath, accumulated search, and params - skipping expensive
987
+ * operations like AbortController, ControlledPromise, loaderDeps, and full match objects.
988
+ */
989
+ matchRoutesLightweight(location) {
990
+ const { matchedRoutes, routeParams, parsedParams } = this.getMatchedRoutes(location.pathname);
991
+ const lastRoute = require_utils.last(matchedRoutes);
992
+ const accumulatedSearch = { ...location.search };
993
+ for (const route of matchedRoutes) try {
994
+ Object.assign(accumulatedSearch, validateSearch(route.options.validateSearch, accumulatedSearch));
995
+ } catch {}
996
+ const lastStateMatchId = require_utils.last(this.stores.matchesId.state);
997
+ const lastStateMatch = lastStateMatchId && this.stores.activeMatchStoresById.get(lastStateMatchId)?.state;
998
+ const canReuseParams = lastStateMatch && lastStateMatch.routeId === lastRoute.id && lastStateMatch.pathname === location.pathname;
999
+ let params;
1000
+ if (canReuseParams) params = lastStateMatch.params;
1001
+ else {
1002
+ const strictParams = Object.assign(Object.create(null), routeParams);
1003
+ for (const route of matchedRoutes) try {
1004
+ extractStrictParams(route, routeParams, parsedParams ?? {}, strictParams);
1005
+ } catch {}
1006
+ params = strictParams;
1007
+ }
1008
+ return {
1009
+ matchedRoutes,
1010
+ fullPath: lastRoute.fullPath,
1011
+ search: accumulatedSearch,
1012
+ params
1013
+ };
1014
+ }
1015
+ };
1016
+ /** Error thrown when search parameter validation fails. */
1017
+ var SearchParamError = class extends Error {};
1018
+ /** Error thrown when path parameter parsing/validation fails. */
1019
+ var PathParamError = class extends Error {};
1020
+ var normalize = (str) => str.endsWith("/") && str.length > 1 ? str.slice(0, -1) : str;
1021
+ function comparePaths(a, b) {
1022
+ return normalize(a) === normalize(b);
1023
+ }
1024
+ /**
1025
+ * Lazily import a module function and forward arguments to it, retaining
1026
+ * parameter and return types for the selected export key.
1027
+ */
1028
+ function lazyFn(fn, key) {
1029
+ return async (...args) => {
1030
+ return (await fn())[key || "default"](...args);
1031
+ };
1032
+ }
1033
+ /** Create an initial RouterState from a parsed location. */
1034
+ function getInitialRouterState(location) {
1035
+ return {
1036
+ loadedAt: 0,
1037
+ isLoading: false,
1038
+ isTransitioning: false,
1039
+ status: "idle",
1040
+ resolvedLocation: void 0,
1041
+ location,
1042
+ matches: [],
1043
+ statusCode: 200
1044
+ };
1045
+ }
1046
+ function validateSearch(validateSearch, input) {
1047
+ if (validateSearch == null) return {};
1048
+ if ("~standard" in validateSearch) {
1049
+ const result = validateSearch["~standard"].validate(input);
1050
+ if (result instanceof Promise) throw new SearchParamError("Async validation not supported");
1051
+ if (result.issues) throw new SearchParamError(JSON.stringify(result.issues, void 0, 2), { cause: result });
1052
+ return result.value;
1053
+ }
1054
+ if ("parse" in validateSearch) return validateSearch.parse(input);
1055
+ if (typeof validateSearch === "function") return validateSearch(input);
1056
+ return {};
1057
+ }
1058
+ /**
1059
+ * Build the matched route chain and extract params for a pathname.
1060
+ * Falls back to the root route if no specific route is found.
1061
+ */
1062
+ function getMatchedRoutes({ pathname, routesById, processedTree }) {
1063
+ const routeParams = Object.create(null);
1064
+ const trimmedPath = require_path.trimPathRight(pathname);
1065
+ let foundRoute = void 0;
1066
+ let parsedParams = void 0;
1067
+ const match = require_new_process_route_tree.findRouteMatch(trimmedPath, processedTree, true);
1068
+ if (match) {
1069
+ foundRoute = match.route;
1070
+ Object.assign(routeParams, match.rawParams);
1071
+ parsedParams = Object.assign(Object.create(null), match.parsedParams);
1072
+ }
1073
+ return {
1074
+ matchedRoutes: match?.branch || [routesById["__root__"]],
1075
+ routeParams,
1076
+ foundRoute,
1077
+ parsedParams
1078
+ };
1079
+ }
1080
+ /**
1081
+ * TODO: once caches are persisted across requests on the server,
1082
+ * we can cache the built middleware chain using `last(destRoutes)` as the key
1083
+ */
1084
+ function applySearchMiddleware({ search, dest, destRoutes, _includeValidateSearch }) {
1085
+ return buildMiddlewareChain(destRoutes)(search, dest, _includeValidateSearch ?? false);
1086
+ }
1087
+ function buildMiddlewareChain(destRoutes) {
1088
+ const context = {
1089
+ dest: null,
1090
+ _includeValidateSearch: false,
1091
+ middlewares: []
1092
+ };
1093
+ for (const route of destRoutes) {
1094
+ if ("search" in route.options) {
1095
+ if (route.options.search?.middlewares) context.middlewares.push(...route.options.search.middlewares);
1096
+ } else if (route.options.preSearchFilters || route.options.postSearchFilters) {
1097
+ const legacyMiddleware = ({ search, next }) => {
1098
+ let nextSearch = search;
1099
+ if ("preSearchFilters" in route.options && route.options.preSearchFilters) nextSearch = route.options.preSearchFilters.reduce((prev, next) => next(prev), search);
1100
+ const result = next(nextSearch);
1101
+ if ("postSearchFilters" in route.options && route.options.postSearchFilters) return route.options.postSearchFilters.reduce((prev, next) => next(prev), result);
1102
+ return result;
1103
+ };
1104
+ context.middlewares.push(legacyMiddleware);
1105
+ }
1106
+ if (route.options.validateSearch) {
1107
+ const validate = ({ search, next }) => {
1108
+ const result = next(search);
1109
+ if (!context._includeValidateSearch) return result;
1110
+ try {
1111
+ return {
1112
+ ...result,
1113
+ ...validateSearch(route.options.validateSearch, result) ?? void 0
1114
+ };
1115
+ } catch {
1116
+ return result;
1117
+ }
1118
+ };
1119
+ context.middlewares.push(validate);
1120
+ }
1121
+ }
1122
+ const final = ({ search }) => {
1123
+ const dest = context.dest;
1124
+ if (!dest.search) return {};
1125
+ if (dest.search === true) return search;
1126
+ return require_utils.functionalUpdate(dest.search, search);
1127
+ };
1128
+ context.middlewares.push(final);
1129
+ const applyNext = (index, currentSearch, middlewares) => {
1130
+ if (index >= middlewares.length) return currentSearch;
1131
+ const middleware = middlewares[index];
1132
+ const next = (newSearch) => {
1133
+ return applyNext(index + 1, newSearch, middlewares);
1134
+ };
1135
+ return middleware({
1136
+ search: currentSearch,
1137
+ next
1138
+ });
1139
+ };
1140
+ return function middleware(search, dest, _includeValidateSearch) {
1141
+ context.dest = dest;
1142
+ context._includeValidateSearch = _includeValidateSearch;
1143
+ return applyNext(0, search, context.middlewares);
1144
+ };
1145
+ }
1146
+ function findGlobalNotFoundRouteId(notFoundMode, routes) {
1147
+ if (notFoundMode !== "root") for (let i = routes.length - 1; i >= 0; i--) {
1148
+ const route = routes[i];
1149
+ if (route.children) return route.id;
1150
+ }
1151
+ return require_root.rootRouteId;
1152
+ }
1153
+ function extractStrictParams(route, referenceParams, parsedParams, accumulatedParams) {
1154
+ const parseParams = route.options.params?.parse ?? route.options.parseParams;
1155
+ if (parseParams) if (route.options.skipRouteOnParseError) {
1156
+ for (const key in referenceParams) if (key in parsedParams) accumulatedParams[key] = parsedParams[key];
1157
+ } else {
1158
+ const result = parseParams(accumulatedParams);
1159
+ Object.assign(accumulatedParams, result);
1160
+ }
1161
+ }
1162
+ //#endregion
1163
+ exports.PathParamError = PathParamError;
1164
+ exports.RouterCore = RouterCore;
1165
+ exports.SearchParamError = SearchParamError;
1166
+ exports.defaultSerializeError = defaultSerializeError;
1167
+ exports.getInitialRouterState = getInitialRouterState;
1168
+ exports.getLocationChangeInfo = getLocationChangeInfo;
1169
+ exports.getMatchedRoutes = getMatchedRoutes;
1170
+ exports.lazyFn = lazyFn;
1171
+ exports.trailingSlashOptions = trailingSlashOptions;
1172
+
1173
+ //# sourceMappingURL=router.cjs.map