@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,754 @@
1
+ const require_utils = require("./utils.cjs");
2
+ const require_invariant = require("./invariant.cjs");
3
+ const require_lru_cache = require("./lru-cache.cjs");
4
+ var SEGMENT_TYPE_INDEX = 4;
5
+ var SEGMENT_TYPE_PATHLESS = 5;
6
+ function getOpenAndCloseBraces(part) {
7
+ const openBrace = part.indexOf("{");
8
+ if (openBrace === -1) return null;
9
+ const closeBrace = part.indexOf("}", openBrace);
10
+ if (closeBrace === -1) return null;
11
+ if (openBrace + 1 >= part.length) return null;
12
+ return [openBrace, closeBrace];
13
+ }
14
+ /**
15
+ * Populates the `output` array with the parsed representation of the given `segment` string.
16
+ *
17
+ * Usage:
18
+ * ```ts
19
+ * let output
20
+ * let cursor = 0
21
+ * while (cursor < path.length) {
22
+ * output = parseSegment(path, cursor, output)
23
+ * const end = output[5]
24
+ * cursor = end + 1
25
+ * ```
26
+ *
27
+ * `output` is stored outside to avoid allocations during repeated calls. It doesn't need to be typed
28
+ * or initialized, it will be done automatically.
29
+ */
30
+ function parseSegment(path, start, output = new Uint16Array(6)) {
31
+ const next = path.indexOf("/", start);
32
+ const end = next === -1 ? path.length : next;
33
+ const part = path.substring(start, end);
34
+ if (!part || !part.includes("$")) {
35
+ output[0] = 0;
36
+ output[1] = start;
37
+ output[2] = start;
38
+ output[3] = end;
39
+ output[4] = end;
40
+ output[5] = end;
41
+ return output;
42
+ }
43
+ if (part === "$") {
44
+ const total = path.length;
45
+ output[0] = 2;
46
+ output[1] = start;
47
+ output[2] = start;
48
+ output[3] = total;
49
+ output[4] = total;
50
+ output[5] = total;
51
+ return output;
52
+ }
53
+ if (part.charCodeAt(0) === 36) {
54
+ output[0] = 1;
55
+ output[1] = start;
56
+ output[2] = start + 1;
57
+ output[3] = end;
58
+ output[4] = end;
59
+ output[5] = end;
60
+ return output;
61
+ }
62
+ const braces = getOpenAndCloseBraces(part);
63
+ if (braces) {
64
+ const [openBrace, closeBrace] = braces;
65
+ const firstChar = part.charCodeAt(openBrace + 1);
66
+ if (firstChar === 45) {
67
+ if (openBrace + 2 < part.length && part.charCodeAt(openBrace + 2) === 36) {
68
+ const paramStart = openBrace + 3;
69
+ const paramEnd = closeBrace;
70
+ if (paramStart < paramEnd) {
71
+ output[0] = 3;
72
+ output[1] = start + openBrace;
73
+ output[2] = start + paramStart;
74
+ output[3] = start + paramEnd;
75
+ output[4] = start + closeBrace + 1;
76
+ output[5] = end;
77
+ return output;
78
+ }
79
+ }
80
+ } else if (firstChar === 36) {
81
+ const dollarPos = openBrace + 1;
82
+ const afterDollar = openBrace + 2;
83
+ if (afterDollar === closeBrace) {
84
+ output[0] = 2;
85
+ output[1] = start + openBrace;
86
+ output[2] = start + dollarPos;
87
+ output[3] = start + afterDollar;
88
+ output[4] = start + closeBrace + 1;
89
+ output[5] = path.length;
90
+ return output;
91
+ }
92
+ output[0] = 1;
93
+ output[1] = start + openBrace;
94
+ output[2] = start + afterDollar;
95
+ output[3] = start + closeBrace;
96
+ output[4] = start + closeBrace + 1;
97
+ output[5] = end;
98
+ return output;
99
+ }
100
+ }
101
+ output[0] = 0;
102
+ output[1] = start;
103
+ output[2] = start;
104
+ output[3] = end;
105
+ output[4] = end;
106
+ output[5] = end;
107
+ return output;
108
+ }
109
+ /**
110
+ * Recursively parses the segments of the given route tree and populates a segment trie.
111
+ *
112
+ * @param data A reusable Uint16Array for parsing segments. (non important, we're just avoiding allocations)
113
+ * @param route The current route to parse.
114
+ * @param start The starting index for parsing within the route's full path.
115
+ * @param node The current segment node in the trie to populate.
116
+ * @param onRoute Callback invoked for each route processed.
117
+ */
118
+ function parseSegments(defaultCaseSensitive, data, route, start, node, depth, onRoute) {
119
+ onRoute?.(route);
120
+ let cursor = start;
121
+ {
122
+ const path = route.fullPath ?? route.from;
123
+ const length = path.length;
124
+ const caseSensitive = route.options?.caseSensitive ?? defaultCaseSensitive;
125
+ const skipOnParamError = !!(route.options?.params?.parse && route.options?.skipRouteOnParseError?.params);
126
+ while (cursor < length) {
127
+ const segment = parseSegment(path, cursor, data);
128
+ let nextNode;
129
+ const start = cursor;
130
+ const end = segment[5];
131
+ cursor = end + 1;
132
+ depth++;
133
+ switch (segment[0]) {
134
+ case 0: {
135
+ const value = path.substring(segment[2], segment[3]);
136
+ if (caseSensitive) {
137
+ const existingNode = node.static?.get(value);
138
+ if (existingNode) nextNode = existingNode;
139
+ else {
140
+ node.static ??= /* @__PURE__ */ new Map();
141
+ const next = createStaticNode(route.fullPath ?? route.from);
142
+ next.parent = node;
143
+ next.depth = depth;
144
+ nextNode = next;
145
+ node.static.set(value, next);
146
+ }
147
+ } else {
148
+ const name = value.toLowerCase();
149
+ const existingNode = node.staticInsensitive?.get(name);
150
+ if (existingNode) nextNode = existingNode;
151
+ else {
152
+ node.staticInsensitive ??= /* @__PURE__ */ new Map();
153
+ const next = createStaticNode(route.fullPath ?? route.from);
154
+ next.parent = node;
155
+ next.depth = depth;
156
+ nextNode = next;
157
+ node.staticInsensitive.set(name, next);
158
+ }
159
+ }
160
+ break;
161
+ }
162
+ case 1: {
163
+ const prefix_raw = path.substring(start, segment[1]);
164
+ const suffix_raw = path.substring(segment[4], end);
165
+ const actuallyCaseSensitive = caseSensitive && !!(prefix_raw || suffix_raw);
166
+ const prefix = !prefix_raw ? void 0 : actuallyCaseSensitive ? prefix_raw : prefix_raw.toLowerCase();
167
+ const suffix = !suffix_raw ? void 0 : actuallyCaseSensitive ? suffix_raw : suffix_raw.toLowerCase();
168
+ const existingNode = !skipOnParamError && node.dynamic?.find((s) => !s.skipOnParamError && s.caseSensitive === actuallyCaseSensitive && s.prefix === prefix && s.suffix === suffix);
169
+ if (existingNode) nextNode = existingNode;
170
+ else {
171
+ const next = createDynamicNode(1, route.fullPath ?? route.from, actuallyCaseSensitive, prefix, suffix);
172
+ nextNode = next;
173
+ next.depth = depth;
174
+ next.parent = node;
175
+ node.dynamic ??= [];
176
+ node.dynamic.push(next);
177
+ }
178
+ break;
179
+ }
180
+ case 3: {
181
+ const prefix_raw = path.substring(start, segment[1]);
182
+ const suffix_raw = path.substring(segment[4], end);
183
+ const actuallyCaseSensitive = caseSensitive && !!(prefix_raw || suffix_raw);
184
+ const prefix = !prefix_raw ? void 0 : actuallyCaseSensitive ? prefix_raw : prefix_raw.toLowerCase();
185
+ const suffix = !suffix_raw ? void 0 : actuallyCaseSensitive ? suffix_raw : suffix_raw.toLowerCase();
186
+ const existingNode = !skipOnParamError && node.optional?.find((s) => !s.skipOnParamError && s.caseSensitive === actuallyCaseSensitive && s.prefix === prefix && s.suffix === suffix);
187
+ if (existingNode) nextNode = existingNode;
188
+ else {
189
+ const next = createDynamicNode(3, route.fullPath ?? route.from, actuallyCaseSensitive, prefix, suffix);
190
+ nextNode = next;
191
+ next.parent = node;
192
+ next.depth = depth;
193
+ node.optional ??= [];
194
+ node.optional.push(next);
195
+ }
196
+ break;
197
+ }
198
+ case 2: {
199
+ const prefix_raw = path.substring(start, segment[1]);
200
+ const suffix_raw = path.substring(segment[4], end);
201
+ const actuallyCaseSensitive = caseSensitive && !!(prefix_raw || suffix_raw);
202
+ const prefix = !prefix_raw ? void 0 : actuallyCaseSensitive ? prefix_raw : prefix_raw.toLowerCase();
203
+ const suffix = !suffix_raw ? void 0 : actuallyCaseSensitive ? suffix_raw : suffix_raw.toLowerCase();
204
+ const next = createDynamicNode(2, route.fullPath ?? route.from, actuallyCaseSensitive, prefix, suffix);
205
+ nextNode = next;
206
+ next.parent = node;
207
+ next.depth = depth;
208
+ node.wildcard ??= [];
209
+ node.wildcard.push(next);
210
+ }
211
+ }
212
+ node = nextNode;
213
+ }
214
+ if (skipOnParamError && route.children && !route.isRoot && route.id && route.id.charCodeAt(route.id.lastIndexOf("/") + 1) === 95) {
215
+ const pathlessNode = createStaticNode(route.fullPath ?? route.from);
216
+ pathlessNode.kind = SEGMENT_TYPE_PATHLESS;
217
+ pathlessNode.parent = node;
218
+ depth++;
219
+ pathlessNode.depth = depth;
220
+ node.pathless ??= [];
221
+ node.pathless.push(pathlessNode);
222
+ node = pathlessNode;
223
+ }
224
+ const isLeaf = (route.path || !route.children) && !route.isRoot;
225
+ if (isLeaf && path.endsWith("/")) {
226
+ const indexNode = createStaticNode(route.fullPath ?? route.from);
227
+ indexNode.kind = SEGMENT_TYPE_INDEX;
228
+ indexNode.parent = node;
229
+ depth++;
230
+ indexNode.depth = depth;
231
+ node.index = indexNode;
232
+ node = indexNode;
233
+ }
234
+ node.parse = route.options?.params?.parse ?? null;
235
+ node.skipOnParamError = skipOnParamError;
236
+ node.parsingPriority = route.options?.skipRouteOnParseError?.priority ?? 0;
237
+ if (isLeaf && !node.route) {
238
+ node.route = route;
239
+ node.fullPath = route.fullPath ?? route.from;
240
+ }
241
+ }
242
+ if (route.children) for (const child of route.children) parseSegments(defaultCaseSensitive, data, child, cursor, node, depth, onRoute);
243
+ }
244
+ function sortDynamic(a, b) {
245
+ if (a.skipOnParamError && !b.skipOnParamError) return -1;
246
+ if (!a.skipOnParamError && b.skipOnParamError) return 1;
247
+ if (a.skipOnParamError && b.skipOnParamError && (a.parsingPriority || b.parsingPriority)) return b.parsingPriority - a.parsingPriority;
248
+ if (a.prefix && b.prefix && a.prefix !== b.prefix) {
249
+ if (a.prefix.startsWith(b.prefix)) return -1;
250
+ if (b.prefix.startsWith(a.prefix)) return 1;
251
+ }
252
+ if (a.suffix && b.suffix && a.suffix !== b.suffix) {
253
+ if (a.suffix.endsWith(b.suffix)) return -1;
254
+ if (b.suffix.endsWith(a.suffix)) return 1;
255
+ }
256
+ if (a.prefix && !b.prefix) return -1;
257
+ if (!a.prefix && b.prefix) return 1;
258
+ if (a.suffix && !b.suffix) return -1;
259
+ if (!a.suffix && b.suffix) return 1;
260
+ if (a.caseSensitive && !b.caseSensitive) return -1;
261
+ if (!a.caseSensitive && b.caseSensitive) return 1;
262
+ return 0;
263
+ }
264
+ function sortTreeNodes(node) {
265
+ if (node.pathless) for (const child of node.pathless) sortTreeNodes(child);
266
+ if (node.static) for (const child of node.static.values()) sortTreeNodes(child);
267
+ if (node.staticInsensitive) for (const child of node.staticInsensitive.values()) sortTreeNodes(child);
268
+ if (node.dynamic?.length) {
269
+ node.dynamic.sort(sortDynamic);
270
+ for (const child of node.dynamic) sortTreeNodes(child);
271
+ }
272
+ if (node.optional?.length) {
273
+ node.optional.sort(sortDynamic);
274
+ for (const child of node.optional) sortTreeNodes(child);
275
+ }
276
+ if (node.wildcard?.length) {
277
+ node.wildcard.sort(sortDynamic);
278
+ for (const child of node.wildcard) sortTreeNodes(child);
279
+ }
280
+ }
281
+ function createStaticNode(fullPath) {
282
+ return {
283
+ kind: 0,
284
+ depth: 0,
285
+ pathless: null,
286
+ index: null,
287
+ static: null,
288
+ staticInsensitive: null,
289
+ dynamic: null,
290
+ optional: null,
291
+ wildcard: null,
292
+ route: null,
293
+ fullPath,
294
+ parent: null,
295
+ parse: null,
296
+ skipOnParamError: false,
297
+ parsingPriority: 0
298
+ };
299
+ }
300
+ /**
301
+ * Keys must be declared in the same order as in `SegmentNode` type,
302
+ * to ensure they are represented as the same object class in the engine.
303
+ */
304
+ function createDynamicNode(kind, fullPath, caseSensitive, prefix, suffix) {
305
+ return {
306
+ kind,
307
+ depth: 0,
308
+ pathless: null,
309
+ index: null,
310
+ static: null,
311
+ staticInsensitive: null,
312
+ dynamic: null,
313
+ optional: null,
314
+ wildcard: null,
315
+ route: null,
316
+ fullPath,
317
+ parent: null,
318
+ parse: null,
319
+ skipOnParamError: false,
320
+ parsingPriority: 0,
321
+ caseSensitive,
322
+ prefix,
323
+ suffix
324
+ };
325
+ }
326
+ function processRouteMasks(routeList, processedTree) {
327
+ const segmentTree = createStaticNode("/");
328
+ const data = new Uint16Array(6);
329
+ for (const route of routeList) parseSegments(false, data, route, 1, segmentTree, 0);
330
+ sortTreeNodes(segmentTree);
331
+ processedTree.masksTree = segmentTree;
332
+ processedTree.flatCache = require_lru_cache.createLRUCache(1e3);
333
+ }
334
+ /**
335
+ * Take an arbitrary list of routes, create a tree from them (if it hasn't been created already), and match a path against it.
336
+ */
337
+ function findFlatMatch(path, processedTree) {
338
+ path ||= "/";
339
+ const cached = processedTree.flatCache.get(path);
340
+ if (cached) return cached;
341
+ const result = findMatch(path, processedTree.masksTree);
342
+ processedTree.flatCache.set(path, result);
343
+ return result;
344
+ }
345
+ /**
346
+ * @deprecated keep until v2 so that `router.matchRoute` can keep not caring about the actual route tree
347
+ */
348
+ function findSingleMatch(from, caseSensitive, fuzzy, path, processedTree) {
349
+ from ||= "/";
350
+ path ||= "/";
351
+ const key = caseSensitive ? `case\0${from}` : from;
352
+ let tree = processedTree.singleCache.get(key);
353
+ if (!tree) {
354
+ tree = createStaticNode("/");
355
+ parseSegments(caseSensitive, new Uint16Array(6), { from }, 1, tree, 0);
356
+ processedTree.singleCache.set(key, tree);
357
+ }
358
+ return findMatch(path, tree, fuzzy);
359
+ }
360
+ function findRouteMatch(path, processedTree, fuzzy = false) {
361
+ const key = fuzzy ? path : `nofuzz\0${path}`;
362
+ const cached = processedTree.matchCache.get(key);
363
+ if (cached !== void 0) return cached;
364
+ path ||= "/";
365
+ let result;
366
+ try {
367
+ result = findMatch(path, processedTree.segmentTree, fuzzy);
368
+ } catch (err) {
369
+ if (err instanceof URIError) result = null;
370
+ else throw err;
371
+ }
372
+ if (result) result.branch = buildRouteBranch(result.route);
373
+ processedTree.matchCache.set(key, result);
374
+ return result;
375
+ }
376
+ /** Trim trailing slashes (except preserving root '/'). */
377
+ function trimPathRight(path) {
378
+ return path === "/" ? path : path.replace(/\/{1,}$/, "");
379
+ }
380
+ /**
381
+ * Processes a route tree into a segment trie for efficient path matching.
382
+ * Also builds lookup maps for routes by ID and by trimmed full path.
383
+ */
384
+ function processRouteTree(routeTree, caseSensitive = false, initRoute) {
385
+ const segmentTree = createStaticNode(routeTree.fullPath);
386
+ const data = new Uint16Array(6);
387
+ const routesById = {};
388
+ const routesByPath = {};
389
+ let index = 0;
390
+ parseSegments(caseSensitive, data, routeTree, 1, segmentTree, 0, (route) => {
391
+ initRoute?.(route, index);
392
+ if (route.id in routesById) {
393
+ if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Duplicate routes found with id: ${String(route.id)}`);
394
+ require_invariant.invariant();
395
+ }
396
+ routesById[route.id] = route;
397
+ if (index !== 0 && route.path) {
398
+ const trimmedFullPath = trimPathRight(route.fullPath);
399
+ if (!routesByPath[trimmedFullPath] || route.fullPath.endsWith("/")) routesByPath[trimmedFullPath] = route;
400
+ }
401
+ index++;
402
+ });
403
+ sortTreeNodes(segmentTree);
404
+ return {
405
+ processedTree: {
406
+ segmentTree,
407
+ singleCache: require_lru_cache.createLRUCache(1e3),
408
+ matchCache: require_lru_cache.createLRUCache(1e3),
409
+ flatCache: null,
410
+ masksTree: null
411
+ },
412
+ routesById,
413
+ routesByPath
414
+ };
415
+ }
416
+ function findMatch(path, segmentTree, fuzzy = false) {
417
+ const parts = path.split("/");
418
+ const leaf = getNodeMatch(path, parts, segmentTree, fuzzy);
419
+ if (!leaf) return null;
420
+ const [rawParams] = extractParams(path, parts, leaf);
421
+ return {
422
+ route: leaf.node.route,
423
+ rawParams,
424
+ parsedParams: leaf.parsedParams
425
+ };
426
+ }
427
+ /**
428
+ * This function is "resumable":
429
+ * - the `leaf` input can contain `extract` and `rawParams` properties from a previous `extractParams` call
430
+ * - the returned `state` can be passed back as `extract` in a future call to continue extracting params from where we left off
431
+ *
432
+ * Inputs are *not* mutated.
433
+ */
434
+ function extractParams(path, parts, leaf) {
435
+ const list = buildBranch(leaf.node);
436
+ let nodeParts = null;
437
+ const rawParams = Object.create(null);
438
+ /** which segment of the path we're currently processing */
439
+ let partIndex = leaf.extract?.part ?? 0;
440
+ /** which node of the route tree branch we're currently processing */
441
+ let nodeIndex = leaf.extract?.node ?? 0;
442
+ /** index of the 1st character of the segment we're processing in the path string */
443
+ let pathIndex = leaf.extract?.path ?? 0;
444
+ /** which fullPath segment we're currently processing */
445
+ let segmentCount = leaf.extract?.segment ?? 0;
446
+ for (; nodeIndex < list.length; partIndex++, nodeIndex++, pathIndex++, segmentCount++) {
447
+ const node = list[nodeIndex];
448
+ if (node.kind === SEGMENT_TYPE_INDEX) break;
449
+ if (node.kind === SEGMENT_TYPE_PATHLESS) {
450
+ segmentCount--;
451
+ partIndex--;
452
+ pathIndex--;
453
+ continue;
454
+ }
455
+ const part = parts[partIndex];
456
+ const currentPathIndex = pathIndex;
457
+ if (part) pathIndex += part.length;
458
+ if (node.kind === 1) {
459
+ nodeParts ??= leaf.node.fullPath.split("/");
460
+ const nodePart = nodeParts[segmentCount];
461
+ const preLength = node.prefix?.length ?? 0;
462
+ if (nodePart.charCodeAt(preLength) === 123) {
463
+ const sufLength = node.suffix?.length ?? 0;
464
+ const name = nodePart.substring(preLength + 2, nodePart.length - sufLength - 1);
465
+ const value = part.substring(preLength, part.length - sufLength);
466
+ rawParams[name] = decodeURIComponent(value);
467
+ } else {
468
+ const name = nodePart.substring(1);
469
+ rawParams[name] = decodeURIComponent(part);
470
+ }
471
+ } else if (node.kind === 3) {
472
+ if (leaf.skipped & 1 << nodeIndex) {
473
+ partIndex--;
474
+ pathIndex = currentPathIndex - 1;
475
+ continue;
476
+ }
477
+ nodeParts ??= leaf.node.fullPath.split("/");
478
+ const nodePart = nodeParts[segmentCount];
479
+ const preLength = node.prefix?.length ?? 0;
480
+ const sufLength = node.suffix?.length ?? 0;
481
+ const name = nodePart.substring(preLength + 3, nodePart.length - sufLength - 1);
482
+ const value = node.suffix || node.prefix ? part.substring(preLength, part.length - sufLength) : part;
483
+ if (value) rawParams[name] = decodeURIComponent(value);
484
+ } else if (node.kind === 2) {
485
+ const n = node;
486
+ const value = path.substring(currentPathIndex + (n.prefix?.length ?? 0), path.length - (n.suffix?.length ?? 0));
487
+ const splat = decodeURIComponent(value);
488
+ rawParams["*"] = splat;
489
+ rawParams._splat = splat;
490
+ break;
491
+ }
492
+ }
493
+ if (leaf.rawParams) Object.assign(rawParams, leaf.rawParams);
494
+ return [rawParams, {
495
+ part: partIndex,
496
+ node: nodeIndex,
497
+ path: pathIndex,
498
+ segment: segmentCount
499
+ }];
500
+ }
501
+ function buildRouteBranch(route) {
502
+ const list = [route];
503
+ while (route.parentRoute) {
504
+ route = route.parentRoute;
505
+ list.push(route);
506
+ }
507
+ list.reverse();
508
+ return list;
509
+ }
510
+ function buildBranch(node) {
511
+ const list = Array(node.depth + 1);
512
+ do {
513
+ list[node.depth] = node;
514
+ node = node.parent;
515
+ } while (node);
516
+ return list;
517
+ }
518
+ function getNodeMatch(path, parts, segmentTree, fuzzy) {
519
+ if (path === "/" && segmentTree.index) return {
520
+ node: segmentTree.index,
521
+ skipped: 0
522
+ };
523
+ const trailingSlash = !require_utils.last(parts);
524
+ const pathIsIndex = trailingSlash && path !== "/";
525
+ const partsLength = parts.length - (trailingSlash ? 1 : 0);
526
+ const stack = [{
527
+ node: segmentTree,
528
+ index: 1,
529
+ skipped: 0,
530
+ depth: 1,
531
+ statics: 1,
532
+ dynamics: 0,
533
+ optionals: 0
534
+ }];
535
+ let wildcardMatch = null;
536
+ let bestFuzzy = null;
537
+ let bestMatch = null;
538
+ while (stack.length) {
539
+ const frame = stack.pop();
540
+ const { node, index, skipped, depth, statics, dynamics, optionals } = frame;
541
+ let { extract, rawParams, parsedParams } = frame;
542
+ if (node.skipOnParamError) {
543
+ if (!validateMatchParams(path, parts, frame)) continue;
544
+ rawParams = frame.rawParams;
545
+ extract = frame.extract;
546
+ parsedParams = frame.parsedParams;
547
+ }
548
+ if (fuzzy && node.route && node.kind !== SEGMENT_TYPE_INDEX && isFrameMoreSpecific(bestFuzzy, frame)) bestFuzzy = frame;
549
+ const isBeyondPath = index === partsLength;
550
+ if (isBeyondPath) {
551
+ if (node.route && !pathIsIndex && isFrameMoreSpecific(bestMatch, frame)) bestMatch = frame;
552
+ if (!node.optional && !node.wildcard && !node.index && !node.pathless) continue;
553
+ }
554
+ const part = isBeyondPath ? void 0 : parts[index];
555
+ let lowerPart;
556
+ if (isBeyondPath && node.index) {
557
+ const indexFrame = {
558
+ node: node.index,
559
+ index,
560
+ skipped,
561
+ depth: depth + 1,
562
+ statics,
563
+ dynamics,
564
+ optionals,
565
+ extract,
566
+ rawParams,
567
+ parsedParams
568
+ };
569
+ let indexValid = true;
570
+ if (node.index.skipOnParamError) {
571
+ if (!validateMatchParams(path, parts, indexFrame)) indexValid = false;
572
+ }
573
+ if (indexValid) {
574
+ if (statics === partsLength && !dynamics && !optionals && !skipped) return indexFrame;
575
+ if (isFrameMoreSpecific(bestMatch, indexFrame)) bestMatch = indexFrame;
576
+ }
577
+ }
578
+ if (node.wildcard && isFrameMoreSpecific(wildcardMatch, frame)) for (const segment of node.wildcard) {
579
+ const { prefix, suffix } = segment;
580
+ if (prefix) {
581
+ if (isBeyondPath) continue;
582
+ if (!(segment.caseSensitive ? part : lowerPart ??= part.toLowerCase()).startsWith(prefix)) continue;
583
+ }
584
+ if (suffix) {
585
+ if (isBeyondPath) continue;
586
+ const end = parts.slice(index).join("/").slice(-suffix.length);
587
+ if ((segment.caseSensitive ? end : end.toLowerCase()) !== suffix) continue;
588
+ }
589
+ const frame = {
590
+ node: segment,
591
+ index: partsLength,
592
+ skipped,
593
+ depth,
594
+ statics,
595
+ dynamics,
596
+ optionals,
597
+ extract,
598
+ rawParams,
599
+ parsedParams
600
+ };
601
+ if (segment.skipOnParamError) {
602
+ if (!validateMatchParams(path, parts, frame)) continue;
603
+ }
604
+ wildcardMatch = frame;
605
+ break;
606
+ }
607
+ if (node.optional) {
608
+ const nextSkipped = skipped | 1 << depth;
609
+ const nextDepth = depth + 1;
610
+ for (let i = node.optional.length - 1; i >= 0; i--) {
611
+ const segment = node.optional[i];
612
+ stack.push({
613
+ node: segment,
614
+ index,
615
+ skipped: nextSkipped,
616
+ depth: nextDepth,
617
+ statics,
618
+ dynamics,
619
+ optionals,
620
+ extract,
621
+ rawParams,
622
+ parsedParams
623
+ });
624
+ }
625
+ if (!isBeyondPath) for (let i = node.optional.length - 1; i >= 0; i--) {
626
+ const segment = node.optional[i];
627
+ const { prefix, suffix } = segment;
628
+ if (prefix || suffix) {
629
+ const casePart = segment.caseSensitive ? part : lowerPart ??= part.toLowerCase();
630
+ if (prefix && !casePart.startsWith(prefix)) continue;
631
+ if (suffix && !casePart.endsWith(suffix)) continue;
632
+ }
633
+ stack.push({
634
+ node: segment,
635
+ index: index + 1,
636
+ skipped,
637
+ depth: nextDepth,
638
+ statics,
639
+ dynamics,
640
+ optionals: optionals + 1,
641
+ extract,
642
+ rawParams,
643
+ parsedParams
644
+ });
645
+ }
646
+ }
647
+ if (!isBeyondPath && node.dynamic && part) for (let i = node.dynamic.length - 1; i >= 0; i--) {
648
+ const segment = node.dynamic[i];
649
+ const { prefix, suffix } = segment;
650
+ if (prefix || suffix) {
651
+ const casePart = segment.caseSensitive ? part : lowerPart ??= part.toLowerCase();
652
+ if (prefix && !casePart.startsWith(prefix)) continue;
653
+ if (suffix && !casePart.endsWith(suffix)) continue;
654
+ }
655
+ stack.push({
656
+ node: segment,
657
+ index: index + 1,
658
+ skipped,
659
+ depth: depth + 1,
660
+ statics,
661
+ dynamics: dynamics + 1,
662
+ optionals,
663
+ extract,
664
+ rawParams,
665
+ parsedParams
666
+ });
667
+ }
668
+ if (!isBeyondPath && node.staticInsensitive) {
669
+ const match = node.staticInsensitive.get(lowerPart ??= part.toLowerCase());
670
+ if (match) stack.push({
671
+ node: match,
672
+ index: index + 1,
673
+ skipped,
674
+ depth: depth + 1,
675
+ statics: statics + 1,
676
+ dynamics,
677
+ optionals,
678
+ extract,
679
+ rawParams,
680
+ parsedParams
681
+ });
682
+ }
683
+ if (!isBeyondPath && node.static) {
684
+ const match = node.static.get(part);
685
+ if (match) stack.push({
686
+ node: match,
687
+ index: index + 1,
688
+ skipped,
689
+ depth: depth + 1,
690
+ statics: statics + 1,
691
+ dynamics,
692
+ optionals,
693
+ extract,
694
+ rawParams,
695
+ parsedParams
696
+ });
697
+ }
698
+ if (node.pathless) {
699
+ const nextDepth = depth + 1;
700
+ for (let i = node.pathless.length - 1; i >= 0; i--) {
701
+ const segment = node.pathless[i];
702
+ stack.push({
703
+ node: segment,
704
+ index,
705
+ skipped,
706
+ depth: nextDepth,
707
+ statics,
708
+ dynamics,
709
+ optionals,
710
+ extract,
711
+ rawParams,
712
+ parsedParams
713
+ });
714
+ }
715
+ }
716
+ }
717
+ if (bestMatch && wildcardMatch) return isFrameMoreSpecific(wildcardMatch, bestMatch) ? bestMatch : wildcardMatch;
718
+ if (bestMatch) return bestMatch;
719
+ if (wildcardMatch) return wildcardMatch;
720
+ if (fuzzy && bestFuzzy) {
721
+ let sliceIndex = bestFuzzy.index;
722
+ for (let i = 0; i < bestFuzzy.index; i++) sliceIndex += parts[i].length;
723
+ const splat = sliceIndex === path.length ? "/" : path.slice(sliceIndex);
724
+ bestFuzzy.rawParams ??= Object.create(null);
725
+ bestFuzzy.rawParams["**"] = decodeURIComponent(splat);
726
+ return bestFuzzy;
727
+ }
728
+ return null;
729
+ }
730
+ function validateMatchParams(path, parts, frame) {
731
+ try {
732
+ const [rawParams, state] = extractParams(path, parts, frame);
733
+ frame.rawParams = rawParams;
734
+ frame.extract = state;
735
+ const parsed = frame.node.parse(rawParams);
736
+ frame.parsedParams = Object.assign(Object.create(null), frame.parsedParams, parsed);
737
+ return true;
738
+ } catch {
739
+ return null;
740
+ }
741
+ }
742
+ function isFrameMoreSpecific(prev, next) {
743
+ if (!prev) return true;
744
+ return next.statics > prev.statics || next.statics === prev.statics && (next.dynamics > prev.dynamics || next.dynamics === prev.dynamics && (next.optionals > prev.optionals || next.optionals === prev.optionals && ((next.node.kind === SEGMENT_TYPE_INDEX) > (prev.node.kind === SEGMENT_TYPE_INDEX) || next.node.kind === SEGMENT_TYPE_INDEX === (prev.node.kind === SEGMENT_TYPE_INDEX) && next.depth > prev.depth)));
745
+ }
746
+ //#endregion
747
+ exports.findFlatMatch = findFlatMatch;
748
+ exports.findRouteMatch = findRouteMatch;
749
+ exports.findSingleMatch = findSingleMatch;
750
+ exports.parseSegment = parseSegment;
751
+ exports.processRouteMasks = processRouteMasks;
752
+ exports.processRouteTree = processRouteTree;
753
+
754
+ //# sourceMappingURL=new-process-route-tree.cjs.map