@askrjs/askr 0.0.48 → 0.0.50

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 (401) hide show
  1. package/dist/benchmark.js +6 -6
  2. package/dist/benchmark.js.map +1 -1
  3. package/dist/boot/hydration.js +140 -0
  4. package/dist/boot/hydration.js.map +1 -0
  5. package/dist/boot/index.d.ts +3 -56
  6. package/dist/boot/index.d.ts.map +1 -1
  7. package/dist/boot/index.js +62 -410
  8. package/dist/boot/index.js.map +1 -1
  9. package/dist/boot/root-lifecycle.d.ts +15 -0
  10. package/dist/boot/root-lifecycle.d.ts.map +1 -0
  11. package/dist/boot/root-lifecycle.js +205 -0
  12. package/dist/boot/root-lifecycle.js.map +1 -0
  13. package/dist/boot/route-startup.js +45 -0
  14. package/dist/boot/route-startup.js.map +1 -0
  15. package/dist/boot/types.d.ts +62 -0
  16. package/dist/boot/types.d.ts.map +1 -0
  17. package/dist/common/component.d.ts +3 -1
  18. package/dist/common/component.d.ts.map +1 -1
  19. package/dist/common/jsx.d.ts +6 -2
  20. package/dist/common/jsx.d.ts.map +1 -1
  21. package/dist/common/jsx.js.map +1 -1
  22. package/dist/common/props.d.ts +1 -1
  23. package/dist/common/render-context.js +55 -0
  24. package/dist/common/render-context.js.map +1 -0
  25. package/dist/common/router.d.ts +5 -1
  26. package/dist/common/router.d.ts.map +1 -1
  27. package/dist/common/ssr.d.ts +1 -1
  28. package/dist/common/ssr.js.map +1 -1
  29. package/dist/common/vnode.d.ts +5 -4
  30. package/dist/common/vnode.d.ts.map +1 -1
  31. package/dist/common/vnode.js.map +1 -1
  32. package/dist/components/error-boundary.d.ts +1 -1
  33. package/dist/components/error-boundary.js +2 -1
  34. package/dist/components/error-boundary.js.map +1 -1
  35. package/dist/components/link.js.map +1 -1
  36. package/dist/control/for.js +2 -1
  37. package/dist/control/for.js.map +1 -1
  38. package/dist/data/data-runtime.d.ts +28 -0
  39. package/dist/data/data-runtime.d.ts.map +1 -0
  40. package/dist/data/data-runtime.js +114 -0
  41. package/dist/data/data-runtime.js.map +1 -0
  42. package/dist/data/index.d.ts +6 -142
  43. package/dist/data/index.js +5 -539
  44. package/dist/data/invalidation.d.ts +9 -0
  45. package/dist/data/invalidation.d.ts.map +1 -0
  46. package/dist/data/invalidation.js +27 -0
  47. package/dist/data/invalidation.js.map +1 -0
  48. package/dist/data/mutation-cell.d.ts +28 -0
  49. package/dist/data/mutation-cell.d.ts.map +1 -0
  50. package/dist/data/mutation-cell.js +132 -0
  51. package/dist/data/mutation-cell.js.map +1 -0
  52. package/dist/data/query-cell.d.ts +46 -0
  53. package/dist/data/query-cell.d.ts.map +1 -0
  54. package/dist/data/query-cell.js +290 -0
  55. package/dist/data/query-cell.js.map +1 -0
  56. package/dist/data/query-key.js +42 -0
  57. package/dist/data/query-key.js.map +1 -0
  58. package/dist/data/shared.js +20 -0
  59. package/dist/data/shared.js.map +1 -0
  60. package/dist/data/types.d.ts +161 -0
  61. package/dist/data/types.d.ts.map +1 -0
  62. package/dist/foundations/icon/icon.d.ts.map +1 -1
  63. package/dist/foundations/icon/icon.js.map +1 -1
  64. package/dist/foundations/structures/portal.d.ts +1 -1
  65. package/dist/foundations/structures/portal.d.ts.map +1 -1
  66. package/dist/foundations/structures/portal.js +2 -1
  67. package/dist/foundations/structures/portal.js.map +1 -1
  68. package/dist/fx/fx.d.ts +1 -1
  69. package/dist/fx/fx.js +5 -4
  70. package/dist/fx/fx.js.map +1 -1
  71. package/dist/fx/timing.d.ts.map +1 -1
  72. package/dist/fx/timing.js +10 -6
  73. package/dist/fx/timing.js.map +1 -1
  74. package/dist/index.d.ts +3 -2
  75. package/dist/index.js +4 -2
  76. package/dist/index.js.map +1 -1
  77. package/dist/jsx/index.d.ts +2 -1
  78. package/dist/jsx/index.js +3 -2
  79. package/dist/jsx/types.d.ts +3 -1
  80. package/dist/jsx/types.d.ts.map +1 -1
  81. package/dist/jsx/types.js +2 -1
  82. package/dist/jsx-dev-runtime.d.ts +2 -2
  83. package/dist/jsx-dev-runtime.d.ts.map +1 -1
  84. package/dist/jsx-dev-runtime.js.map +1 -1
  85. package/dist/jsx-runtime.d.ts +2 -2
  86. package/dist/jsx-runtime.d.ts.map +1 -1
  87. package/dist/jsx-runtime.js.map +1 -1
  88. package/dist/jsx-runtime2.d.ts +3 -2
  89. package/dist/jsx-runtime2.js +3 -2
  90. package/dist/renderer/attributes.js +231 -0
  91. package/dist/renderer/attributes.js.map +1 -0
  92. package/dist/renderer/boundaries.js +266 -0
  93. package/dist/renderer/boundaries.js.map +1 -0
  94. package/dist/renderer/child-shape.js +85 -0
  95. package/dist/renderer/child-shape.js.map +1 -0
  96. package/dist/renderer/children.js +3 -2
  97. package/dist/renderer/children.js.map +1 -1
  98. package/dist/renderer/cleanup.js +2 -1
  99. package/dist/renderer/cleanup.js.map +1 -1
  100. package/dist/renderer/component-host-cleanup.js +68 -0
  101. package/dist/renderer/component-host-cleanup.js.map +1 -0
  102. package/dist/renderer/component-host-instances.js +65 -0
  103. package/dist/renderer/component-host-instances.js.map +1 -0
  104. package/dist/renderer/component-host.js +247 -0
  105. package/dist/renderer/component-host.js.map +1 -0
  106. package/dist/renderer/dom-host.js +13 -0
  107. package/dist/renderer/dom-host.js.map +1 -0
  108. package/dist/renderer/dom-internal.js +185 -0
  109. package/dist/renderer/dom-internal.js.map +1 -0
  110. package/dist/renderer/dom.js +9 -2356
  111. package/dist/renderer/element-children.js +279 -0
  112. package/dist/renderer/element-children.js.map +1 -0
  113. package/dist/renderer/env.js +2 -1
  114. package/dist/renderer/error-boundary-dom.js +29 -0
  115. package/dist/renderer/error-boundary-dom.js.map +1 -0
  116. package/dist/renderer/evaluate-dom-range.js +85 -0
  117. package/dist/renderer/evaluate-dom-range.js.map +1 -0
  118. package/dist/renderer/evaluate-reconcile.js +281 -0
  119. package/dist/renderer/evaluate-reconcile.js.map +1 -0
  120. package/dist/renderer/evaluate.js +13 -399
  121. package/dist/renderer/evaluate.js.map +1 -1
  122. package/dist/renderer/fastpath.js +6 -5
  123. package/dist/renderer/fastpath.js.map +1 -1
  124. package/dist/renderer/for-commit-dom-map.js +83 -0
  125. package/dist/renderer/for-commit-dom-map.js.map +1 -0
  126. package/dist/renderer/for-commit-removal.js +36 -0
  127. package/dist/renderer/for-commit-removal.js.map +1 -0
  128. package/dist/renderer/for-commit-reorder.js +89 -0
  129. package/dist/renderer/for-commit-reorder.js.map +1 -0
  130. package/dist/renderer/for-commit.js +6 -188
  131. package/dist/renderer/for-commit.js.map +1 -1
  132. package/dist/renderer/index.js +28 -16
  133. package/dist/renderer/index.js.map +1 -1
  134. package/dist/renderer/keyed-children.js +32 -0
  135. package/dist/renderer/keyed-children.js.map +1 -0
  136. package/dist/renderer/keyed.js +2 -15
  137. package/dist/renderer/keyed.js.map +1 -1
  138. package/dist/renderer/namespaces.js +23 -0
  139. package/dist/renderer/namespaces.js.map +1 -0
  140. package/dist/renderer/prop-bindings.js +280 -0
  141. package/dist/renderer/prop-bindings.js.map +1 -0
  142. package/dist/renderer/reactive-child-dom.js +133 -0
  143. package/dist/renderer/reactive-child-dom.js.map +1 -0
  144. package/dist/renderer/reactive-child-sources.js +184 -0
  145. package/dist/renderer/reactive-child-sources.js.map +1 -0
  146. package/dist/renderer/reactive-children.js +294 -0
  147. package/dist/renderer/reactive-children.js.map +1 -0
  148. package/dist/renderer/reconcile-commit.js +38 -0
  149. package/dist/renderer/reconcile-commit.js.map +1 -0
  150. package/dist/renderer/reconcile-fastpaths.js +106 -0
  151. package/dist/renderer/reconcile-fastpaths.js.map +1 -0
  152. package/dist/renderer/reconcile-resolution.js +187 -0
  153. package/dist/renderer/reconcile-resolution.js.map +1 -0
  154. package/dist/renderer/reconcile.js +9 -371
  155. package/dist/renderer/reconcile.js.map +1 -1
  156. package/dist/renderer/retained-element-rollback.js +276 -0
  157. package/dist/renderer/retained-element-rollback.js.map +1 -0
  158. package/dist/renderer/stable-patch.js +82 -0
  159. package/dist/renderer/stable-patch.js.map +1 -0
  160. package/dist/renderer/static-reuse.js +96 -0
  161. package/dist/renderer/static-reuse.js.map +1 -0
  162. package/dist/renderer/types.js +2 -1
  163. package/dist/renderer/utils.js +4 -4
  164. package/dist/renderer/utils.js.map +1 -1
  165. package/dist/resources/index.d.ts +3 -2
  166. package/dist/resources/index.js +5 -2
  167. package/dist/router/access.js +36 -0
  168. package/dist/router/access.js.map +1 -0
  169. package/dist/router/activity.d.ts +10 -0
  170. package/dist/router/activity.d.ts.map +1 -0
  171. package/dist/router/activity.js +89 -0
  172. package/dist/router/activity.js.map +1 -0
  173. package/dist/router/authoring.d.ts +22 -0
  174. package/dist/router/authoring.d.ts.map +1 -0
  175. package/dist/router/authoring.js +198 -0
  176. package/dist/router/authoring.js.map +1 -0
  177. package/dist/router/index.d.ts +12 -4
  178. package/dist/router/index.js +10 -3
  179. package/dist/router/internal-types.d.ts +31 -0
  180. package/dist/router/internal-types.d.ts.map +1 -0
  181. package/dist/router/lazy.d.ts +19 -0
  182. package/dist/router/lazy.d.ts.map +1 -0
  183. package/dist/router/lazy.js +52 -0
  184. package/dist/router/lazy.js.map +1 -0
  185. package/dist/router/manifest.d.ts +10 -0
  186. package/dist/router/manifest.d.ts.map +1 -0
  187. package/dist/router/manifest.js +49 -0
  188. package/dist/router/manifest.js.map +1 -0
  189. package/dist/router/navigate.d.ts +4 -51
  190. package/dist/router/navigate.d.ts.map +1 -1
  191. package/dist/router/navigate.js +16 -459
  192. package/dist/router/navigate.js.map +1 -1
  193. package/dist/router/navigation-registry.d.ts +32 -0
  194. package/dist/router/navigation-registry.d.ts.map +1 -0
  195. package/dist/router/navigation-registry.js +105 -0
  196. package/dist/router/navigation-registry.js.map +1 -0
  197. package/dist/router/navigation-scroll.d.ts +14 -0
  198. package/dist/router/navigation-scroll.d.ts.map +1 -0
  199. package/dist/router/navigation-scroll.js +93 -0
  200. package/dist/router/navigation-scroll.js.map +1 -0
  201. package/dist/router/navigation-targets.d.ts +31 -0
  202. package/dist/router/navigation-targets.d.ts.map +1 -0
  203. package/dist/router/navigation-targets.js +253 -0
  204. package/dist/router/navigation-targets.js.map +1 -0
  205. package/dist/router/policy.d.ts +7 -1
  206. package/dist/router/policy.d.ts.map +1 -1
  207. package/dist/router/policy.js +27 -9
  208. package/dist/router/policy.js.map +1 -1
  209. package/dist/router/rendering.d.ts +10 -0
  210. package/dist/router/rendering.d.ts.map +1 -0
  211. package/dist/router/rendering.js +45 -0
  212. package/dist/router/rendering.js.map +1 -0
  213. package/dist/router/resolution.d.ts +17 -0
  214. package/dist/router/resolution.d.ts.map +1 -0
  215. package/dist/router/resolution.js +253 -0
  216. package/dist/router/resolution.js.map +1 -0
  217. package/dist/router/route-query.d.ts +17 -0
  218. package/dist/router/route-query.d.ts.map +1 -0
  219. package/dist/router/route-query.js +47 -0
  220. package/dist/router/route-query.js.map +1 -0
  221. package/dist/router/route.d.ts +8 -149
  222. package/dist/router/route.js +8 -854
  223. package/dist/router/store.d.ts +50 -0
  224. package/dist/router/store.d.ts.map +1 -0
  225. package/dist/router/store.js +171 -0
  226. package/dist/router/store.js.map +1 -0
  227. package/dist/runtime/access.js +45 -0
  228. package/dist/runtime/access.js.map +1 -0
  229. package/dist/runtime/child-scope.d.ts +1 -1
  230. package/dist/runtime/child-scope.js +4 -1
  231. package/dist/runtime/child-scope.js.map +1 -1
  232. package/dist/runtime/component-cleanup.d.ts +16 -0
  233. package/dist/runtime/component-cleanup.d.ts.map +1 -0
  234. package/dist/runtime/component-cleanup.js +70 -0
  235. package/dist/runtime/component-cleanup.js.map +1 -0
  236. package/dist/runtime/component-commit.js +165 -0
  237. package/dist/runtime/component-commit.js.map +1 -0
  238. package/dist/runtime/component-contracts.js +5 -0
  239. package/dist/runtime/component-facade.d.ts +5 -0
  240. package/dist/runtime/component-facade.js +4 -0
  241. package/dist/runtime/component-internal.d.ts +100 -0
  242. package/dist/runtime/component-internal.d.ts.map +1 -0
  243. package/dist/runtime/component-internal.js +219 -0
  244. package/dist/runtime/component-internal.js.map +1 -0
  245. package/dist/runtime/component-lifecycle.d.ts +49 -0
  246. package/dist/runtime/component-lifecycle.d.ts.map +1 -0
  247. package/dist/runtime/component-lifecycle.js +176 -0
  248. package/dist/runtime/component-lifecycle.js.map +1 -0
  249. package/dist/runtime/component-scope.d.ts +55 -0
  250. package/dist/runtime/component-scope.d.ts.map +1 -0
  251. package/dist/runtime/component-scope.js +154 -0
  252. package/dist/runtime/component-scope.js.map +1 -0
  253. package/dist/runtime/component.d.ts +4 -152
  254. package/dist/runtime/component.js +4 -692
  255. package/dist/runtime/context.d.ts +1 -1
  256. package/dist/runtime/context.js +6 -4
  257. package/dist/runtime/context.js.map +1 -1
  258. package/dist/runtime/control.d.ts +3 -3
  259. package/dist/runtime/control.js +2 -1
  260. package/dist/runtime/control.js.map +1 -1
  261. package/dist/runtime/derive.d.ts.map +1 -1
  262. package/dist/runtime/derive.js +6 -5
  263. package/dist/runtime/derive.js.map +1 -1
  264. package/dist/runtime/effect.d.ts +1 -1
  265. package/dist/runtime/effect.d.ts.map +1 -1
  266. package/dist/runtime/effect.js +2 -2
  267. package/dist/runtime/effect.js.map +1 -1
  268. package/dist/runtime/events.js +3 -3
  269. package/dist/runtime/events.js.map +1 -1
  270. package/dist/runtime/fastlane.js +13 -27
  271. package/dist/runtime/fastlane.js.map +1 -1
  272. package/dist/runtime/for-bench.d.ts +1 -1
  273. package/dist/runtime/for-bench.js +1 -4
  274. package/dist/runtime/for-bench.js.map +1 -1
  275. package/dist/runtime/for-internal.d.ts +43 -0
  276. package/dist/runtime/for-internal.d.ts.map +1 -0
  277. package/dist/runtime/for-internal.js +98 -0
  278. package/dist/runtime/for-internal.js.map +1 -0
  279. package/dist/runtime/for-reconcile.d.ts +8 -0
  280. package/dist/runtime/for-reconcile.d.ts.map +1 -0
  281. package/dist/runtime/for-reconcile.js +389 -0
  282. package/dist/runtime/for-reconcile.js.map +1 -0
  283. package/dist/runtime/for-scopes.d.ts +26 -0
  284. package/dist/runtime/for-scopes.d.ts.map +1 -0
  285. package/dist/runtime/for-scopes.js +160 -0
  286. package/dist/runtime/for-scopes.js.map +1 -0
  287. package/dist/runtime/for-signals.d.ts +30 -0
  288. package/dist/runtime/for-signals.d.ts.map +1 -0
  289. package/dist/runtime/for-signals.js +139 -0
  290. package/dist/runtime/for-signals.js.map +1 -0
  291. package/dist/runtime/for.d.ts +4 -66
  292. package/dist/runtime/for.js +5 -773
  293. package/dist/runtime/lifecycle-operations.d.ts +31 -0
  294. package/dist/runtime/lifecycle-operations.d.ts.map +1 -0
  295. package/dist/runtime/lifecycle-operations.js +195 -0
  296. package/dist/runtime/lifecycle-operations.js.map +1 -0
  297. package/dist/runtime/operations.d.ts +3 -40
  298. package/dist/runtime/operations.js +2 -357
  299. package/dist/runtime/readable.d.ts +2 -3
  300. package/dist/runtime/readable.d.ts.map +1 -1
  301. package/dist/runtime/readable.js +6 -5
  302. package/dist/runtime/readable.js.map +1 -1
  303. package/dist/runtime/resource-cell.js +2 -2
  304. package/dist/runtime/resource-cell.js.map +1 -1
  305. package/dist/runtime/resource-operation.d.ts +13 -0
  306. package/dist/runtime/resource-operation.d.ts.map +1 -0
  307. package/dist/runtime/resource-operation.js +170 -0
  308. package/dist/runtime/resource-operation.js.map +1 -0
  309. package/dist/runtime/runtime.d.ts +42 -0
  310. package/dist/runtime/runtime.d.ts.map +1 -0
  311. package/dist/runtime/runtime.js +59 -0
  312. package/dist/runtime/runtime.js.map +1 -0
  313. package/dist/runtime/scheduler.d.ts +5 -1
  314. package/dist/runtime/scheduler.d.ts.map +1 -1
  315. package/dist/runtime/scheduler.js +17 -17
  316. package/dist/runtime/scheduler.js.map +1 -1
  317. package/dist/runtime/selector.js +4 -3
  318. package/dist/runtime/selector.js.map +1 -1
  319. package/dist/runtime/snapshot-source.d.ts +1 -1
  320. package/dist/runtime/snapshot-source.js +1 -1
  321. package/dist/runtime/state.js +2 -1
  322. package/dist/runtime/state.js.map +1 -1
  323. package/dist/ssg/batch-render.js +2 -1
  324. package/dist/ssg/batch-render.js.map +1 -1
  325. package/dist/ssg/create-static-gen.d.ts +9 -3
  326. package/dist/ssg/create-static-gen.d.ts.map +1 -1
  327. package/dist/ssg/create-static-gen.js +12 -99
  328. package/dist/ssg/create-static-gen.js.map +1 -1
  329. package/dist/ssg/generation-plan.js +70 -0
  330. package/dist/ssg/generation-plan.js.map +1 -0
  331. package/dist/ssg/incremental-manifest.js +1 -1
  332. package/dist/ssg/static-routes.js +101 -0
  333. package/dist/ssg/static-routes.js.map +1 -0
  334. package/dist/ssg/types.d.ts +15 -7
  335. package/dist/ssg/types.d.ts.map +1 -1
  336. package/dist/ssr/boundaries.js +113 -0
  337. package/dist/ssr/boundaries.js.map +1 -0
  338. package/dist/ssr/component-runtime.js +111 -0
  339. package/dist/ssr/component-runtime.js.map +1 -0
  340. package/dist/ssr/context.d.ts +3 -1
  341. package/dist/ssr/context.d.ts.map +1 -1
  342. package/dist/ssr/context.js +9 -2
  343. package/dist/ssr/context.js.map +1 -1
  344. package/dist/ssr/errors.d.ts +2 -0
  345. package/dist/ssr/errors.js +11 -1
  346. package/dist/ssr/errors.js.map +1 -1
  347. package/dist/ssr/escape.js +3 -3
  348. package/dist/ssr/escape.js.map +1 -1
  349. package/dist/ssr/hydration-data.js +10 -0
  350. package/dist/ssr/hydration-data.js.map +1 -0
  351. package/dist/ssr/hydration-verify.d.ts +12 -0
  352. package/dist/ssr/hydration-verify.d.ts.map +1 -0
  353. package/dist/ssr/hydration-verify.js +144 -0
  354. package/dist/ssr/hydration-verify.js.map +1 -0
  355. package/dist/ssr/index-internal.d.ts +15 -0
  356. package/dist/ssr/index-internal.d.ts.map +1 -0
  357. package/dist/ssr/index-internal.js +19 -0
  358. package/dist/ssr/index-internal.js.map +1 -0
  359. package/dist/ssr/index.d.ts +5 -57
  360. package/dist/ssr/index.js +3 -738
  361. package/dist/ssr/render-keys.js +9 -32
  362. package/dist/ssr/render-keys.js.map +1 -1
  363. package/dist/ssr/render-resolved.d.ts +1 -1
  364. package/dist/ssr/render-resolved.d.ts.map +1 -1
  365. package/dist/ssr/render-resolved.js +4 -2
  366. package/dist/ssr/render-resolved.js.map +1 -1
  367. package/dist/ssr/render-sync.d.ts +21 -0
  368. package/dist/ssr/render-sync.d.ts.map +1 -0
  369. package/dist/ssr/render-sync.js +275 -0
  370. package/dist/ssr/render-sync.js.map +1 -0
  371. package/dist/ssr/route-policy-resolution.js +77 -0
  372. package/dist/ssr/route-policy-resolution.js.map +1 -0
  373. package/dist/ssr/route-render.d.ts +77 -0
  374. package/dist/ssr/route-render.d.ts.map +1 -0
  375. package/dist/ssr/route-render.js +119 -0
  376. package/dist/ssr/route-render.js.map +1 -0
  377. package/dist/ssr/sink.d.ts +26 -0
  378. package/dist/ssr/sink.d.ts.map +1 -0
  379. package/dist/ssr/types.d.ts +1 -0
  380. package/dist/ssr/types.d.ts.map +1 -1
  381. package/dist/ssr/verify-hydration.js.map +1 -1
  382. package/dist/testing/index.d.ts +1 -2
  383. package/dist/testing/index.d.ts.map +1 -1
  384. package/dist/testing/index.js +2 -1
  385. package/dist/testing/index.js.map +1 -1
  386. package/package.json +4 -3
  387. package/dist/data/index.d.ts.map +0 -1
  388. package/dist/data/index.js.map +0 -1
  389. package/dist/renderer/dom.js.map +0 -1
  390. package/dist/router/route.d.ts.map +0 -1
  391. package/dist/router/route.js.map +0 -1
  392. package/dist/runtime/component.d.ts.map +0 -1
  393. package/dist/runtime/component.js.map +0 -1
  394. package/dist/runtime/for.d.ts.map +0 -1
  395. package/dist/runtime/for.js.map +0 -1
  396. package/dist/runtime/operations.d.ts.map +0 -1
  397. package/dist/runtime/operations.js.map +0 -1
  398. package/dist/runtime/ssr-bridge.js +0 -24
  399. package/dist/runtime/ssr-bridge.js.map +0 -1
  400. package/dist/ssr/index.d.ts.map +0 -1
  401. package/dist/ssr/index.js.map +0 -1
@@ -1,854 +1,8 @@
1
- import { ELEMENT_TYPE, Fragment } from "../common/jsx.js";
2
- import { defineContext, readContext } from "../runtime/context.js";
3
- import { markReactivePropsDirtySource, markReadableDerivedSubscribersDirty, notifyReadableReaders, recordReadableRead } from "../runtime/readable.js";
4
- import { isPromiseLike } from "../common/promise.js";
5
- import { getCurrentComponentInstance } from "../runtime/component.js";
6
- import { ROUTE_ROOT_COMPONENT } from "../common/router-internal.js";
7
- import { computeRank, matchSegments, normalizeRouteSegmentName, parseSegments, splitPathSegments } from "./match.js";
8
- import { requireAuth, requireGuest, requirePermission, requireRole } from "./policy.js";
9
- import { buildRouteContext, buildRouteContextBase, deepFreeze, makeQuery, parseLocation } from "./route-context.js";
10
- import { getExecutionModel } from "../runtime/execution-model.js";
11
- import { getRenderContext } from "../ssr/context.js";
12
- import { syncRouteActivitySnapshot } from "../common/route-activity.js";
13
- //#region src/router/route.ts
14
- /**
15
- * Route definition, registration, and matching.
16
- *
17
- * Primary public authoring:
18
- * - `registerRoutes(() => { ... }, options?)`
19
- * - `group(options, () => { ... })`
20
- * - `page(path, Component, () => { ... })`
21
- * - `index(Component, options?)`
22
- * - `route(path, Component, options?)`
23
- * - `fallback(Component)`
24
- * - `Outlet()` for page child rendering
25
- * - `currentRoute()` for render-time access
26
- *
27
- */
28
- const routes = [];
29
- /** Normalized route records built by the declarative registration API. */
30
- const records = [];
31
- /** Active registration scope stack during module-load-time registration. */
32
- const registrationScopeStack = [];
33
- const registrationSessionStack = [];
34
- const namespaces = /* @__PURE__ */ new Set();
35
- let registrationLocked = false;
36
- let defaultRouteAuthOptions;
37
- let activeClientRouteAuthOptions;
38
- const HAS_ROUTES_KEY = Symbol.for("__ASKR_HAS_ROUTES__");
39
- function setHasRoutes(value) {
40
- try {
41
- const g = globalThis;
42
- g[HAS_ROUTES_KEY] = value;
43
- } catch {}
44
- }
45
- setHasRoutes(false);
46
- const routesByDepth = /* @__PURE__ */ new Map();
47
- /**
48
- * Parse route path depth
49
- */
50
- function getDepth(path) {
51
- const normalized = path.endsWith("/") && path !== "/" ? path.slice(0, -1) : path;
52
- return normalized === "/" ? 0 : normalized.split("/").filter(Boolean).length;
53
- }
54
- /** Pre-parsed segments for an externally supplied Route object. */
55
- const routeSegsCache = /* @__PURE__ */ new WeakMap();
56
- /** Pre-computed rank for an externally supplied Route object. */
57
- const routeRankCache = /* @__PURE__ */ new WeakMap();
58
- /** A rank-descending sorted copy of an external readonly Route array. */
59
- const sortedListCache = /* @__PURE__ */ new WeakMap();
60
- function cachedSegs(r) {
61
- let s = routeSegsCache.get(r);
62
- if (!s) {
63
- s = parseSegments(r.path);
64
- routeSegsCache.set(r, s);
65
- }
66
- return s;
67
- }
68
- function cachedRank(r) {
69
- let n = routeRankCache.get(r);
70
- if (n === void 0) {
71
- n = computeRank(cachedSegs(r));
72
- routeRankCache.set(r, n);
73
- }
74
- return n;
75
- }
76
- function cachedSortedList(routeList) {
77
- let sorted = sortedListCache.get(routeList);
78
- if (!sorted) {
79
- sorted = [...routeList].sort((a, b) => cachedRank(b) - cachedRank(a));
80
- sortedListCache.set(routeList, sorted);
81
- }
82
- return sorted;
83
- }
84
- let currentRouteSnapshot = buildRouteSnapshot("/", "", "");
85
- const currentRouteSource = (() => currentRouteSnapshot);
86
- currentRouteSource._readers = /* @__PURE__ */ new Map();
87
- let serverLocation = null;
88
- function setServerLocation(url) {
89
- serverLocation = url;
90
- if (url) {
91
- const parsed = parseLocation(url);
92
- syncRouteActivitySnapshot(parsed.pathname, computeMatchesFromRoutes(parsed.pathname, getActiveRoutes()));
93
- return;
94
- }
95
- syncRouteActivitySnapshot(currentRouteSnapshot.path, currentRouteSnapshot.matches);
96
- }
97
- function buildRouteSnapshot(pathname, search, hash) {
98
- const query = makeQuery(search);
99
- const matches = computeMatchesFromRoutes(pathname, getActiveRoutes());
100
- return Object.freeze({
101
- path: pathname,
102
- params: deepFreeze({ ...matches[0]?.params }),
103
- query,
104
- hash: hash || null,
105
- matches: Object.freeze(matches)
106
- });
107
- }
108
- function setCurrentRouteSnapshot(pathname, search, hash, activityMatches) {
109
- currentRouteSnapshot = buildRouteSnapshot(pathname, search, hash);
110
- syncRouteActivitySnapshot(pathname, activityMatches ?? currentRouteSnapshot.matches);
111
- const instance = getCurrentComponentInstance();
112
- markReadableDerivedSubscribersDirty(currentRouteSource);
113
- markReactivePropsDirtySource(currentRouteSource);
114
- notifyReadableReaders(currentRouteSource, instance);
115
- }
116
- function matchFallbackPrefix(pathname, fallbackPrefix) {
117
- const normalizedPath = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname;
118
- const normalizedPrefix = fallbackPrefix.endsWith("/") && fallbackPrefix !== "/" ? fallbackPrefix.slice(0, -1) : fallbackPrefix;
119
- if (normalizedPrefix === "/") {
120
- const urlParts = splitPathSegments(normalizedPath);
121
- return { "*": urlParts.length === 0 ? "/" : urlParts.length === 1 ? urlParts[0] : "/" + urlParts.join("/") };
122
- }
123
- if (normalizedPath !== normalizedPrefix && !normalizedPath.startsWith(`${normalizedPrefix}/`)) return null;
124
- const remainderParts = splitPathSegments(normalizedPath === normalizedPrefix ? "/" : normalizedPath.slice(normalizedPrefix.length));
125
- return { "*": remainderParts.length === 0 ? "/" : remainderParts.length === 1 ? remainderParts[0] : "/" + remainderParts.join("/") };
126
- }
127
- function computeMatchesFromRoutes(pathname, routesList) {
128
- const bestMatch = routesList === routes ? getMatchingRecord(pathname, records) : findBestResolvedRouteFromRoutes(pathname, routesList);
129
- if (!bestMatch) return [];
130
- return [{
131
- path: "route" in bestMatch ? bestMatch.route.path : bestMatch.record.path,
132
- params: deepFreeze({ ...bestMatch.params }),
133
- name: "route" in bestMatch ? bestMatch.route.name : void 0,
134
- namespace: "route" in bestMatch ? bestMatch.route.namespace : bestMatch.record.options.namespace
135
- }];
136
- }
137
- function computeMatchesFromRouteRecords(pathname, routeRecords) {
138
- const bestMatch = getMatchingRecord(pathname, routeRecords);
139
- if (!bestMatch) return [];
140
- return [{
141
- path: bestMatch.record.path,
142
- params: deepFreeze({ ...bestMatch.params }),
143
- namespace: bestMatch.record.options.namespace
144
- }];
145
- }
146
- function computeRouteActivityMatches(pathname, options = {}) {
147
- if (options.routes) return computeMatchesFromRoutes(pathname, options.routes);
148
- if (options.manifest) return computeMatchesFromRouteRecords(pathname, options.manifest.records);
149
- return computeMatchesFromRoutes(pathname, getActiveRoutes());
150
- }
151
- function findBestResolvedRouteFromRoutes(pathname, routeList) {
152
- const normalized = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname;
153
- const urlParts = splitPathSegments(normalized);
154
- const sorted = cachedSortedList(routeList);
155
- let bestRoute = null;
156
- let bestParams = {};
157
- let bestRank = -Infinity;
158
- for (const route of sorted) {
159
- if (route.fallbackPrefix) continue;
160
- const rank = cachedRank(route);
161
- if (rank < bestRank) break;
162
- if (bestRoute !== null && rank === bestRank) continue;
163
- const params = matchSegments(urlParts, cachedSegs(route));
164
- if (params !== null) {
165
- bestRoute = route;
166
- bestParams = params;
167
- bestRank = rank;
168
- }
169
- }
170
- if (bestRoute !== null) return {
171
- route: bestRoute,
172
- params: bestParams
173
- };
174
- let bestFallback = null;
175
- let bestFallbackParams = null;
176
- let bestPrefixLength = -1;
177
- for (const route of routeList) {
178
- const internalRoute = route;
179
- if (!internalRoute.fallbackPrefix) continue;
180
- const params = matchFallbackPrefix(normalized, internalRoute.fallbackPrefix);
181
- if (params === null) continue;
182
- if (internalRoute.fallbackPrefix.length > bestPrefixLength) {
183
- bestFallback = internalRoute;
184
- bestFallbackParams = params;
185
- bestPrefixLength = internalRoute.fallbackPrefix.length;
186
- }
187
- }
188
- return bestFallback && bestFallbackParams ? {
189
- route: bestFallback,
190
- params: bestFallbackParams
191
- } : null;
192
- }
193
- function getActiveRoutes() {
194
- return getRenderContext()?.routes ?? routes;
195
- }
196
- function getActiveRouteAuthOptions(override) {
197
- if (override) return override;
198
- return getRenderContext()?.routeAuth ?? activeClientRouteAuthOptions ?? defaultRouteAuthOptions;
199
- }
200
- function _setActiveRouteAuthOptions(auth) {
201
- activeClientRouteAuthOptions = auth;
202
- }
203
- function getCurrentRegistrationSession() {
204
- return registrationSessionStack[registrationSessionStack.length - 1] ?? { authConfigured: !!defaultRouteAuthOptions?.resolve };
205
- }
206
- function getCurrentAccessScopeState() {
207
- return registrationScopeStack[registrationScopeStack.length - 1]?.state ?? {
208
- guestOnly: false,
209
- authenticated: false
210
- };
211
- }
212
- function getCurrentLayoutChain() {
213
- const layoutChain = [];
214
- for (const scope of registrationScopeStack) if (scope.layout) layoutChain.push({ component: scope.layout });
215
- return layoutChain;
216
- }
217
- function getCurrentPageChain() {
218
- const pageChain = [];
219
- for (const scope of registrationScopeStack) if (scope.page) pageChain.push({ component: scope.page });
220
- return pageChain;
221
- }
222
- function hasActivePageScope() {
223
- return registrationScopeStack.some((scope) => !!scope.page);
224
- }
225
- function getCurrentPageScope() {
226
- for (let index = registrationScopeStack.length - 1; index >= 0; index -= 1) {
227
- const scope = registrationScopeStack[index];
228
- if (scope.kind === "page") return scope;
229
- }
230
- return null;
231
- }
232
- function getCurrentScopeKind() {
233
- return registrationScopeStack[registrationScopeStack.length - 1]?.kind ?? null;
234
- }
235
- function getCurrentPathPrefix() {
236
- return registrationScopeStack[registrationScopeStack.length - 1]?.pathPrefix ?? "";
237
- }
238
- function getCurrentInheritedPolicies() {
239
- const policies = [];
240
- for (const scope of registrationScopeStack) if (scope.policies.length > 0) policies.push(...scope.policies);
241
- return policies;
242
- }
243
- /**
244
- * Prevent route registrations after the app has started.
245
- * Enforced in production; tests may unlock explicitly.
246
- */
247
- function lockRouteRegistration() {
248
- registrationLocked = true;
249
- }
250
- function validateRoutePath(path) {
251
- if (!path.startsWith("/")) throw new Error(`Route path must begin with "/". Got: "${path}"`);
252
- if (/\/{2,}/.test(path)) throw new Error("Route path cannot contain consecutive slashes.");
253
- if (/:([^/{}]+)/.test(path)) {
254
- const suggested = path.replace(/:([^/{}]+)/g, "{$1}");
255
- throw new Error(`Route parameter syntax uses {name} interpolation, not :name. Use "${suggested}" instead of "${path}".`);
256
- }
257
- const segments = path.split("/").filter(Boolean);
258
- const seenParamNames = /* @__PURE__ */ new Set();
259
- for (let index = 0; index < segments.length; index++) {
260
- const segment = segments[index];
261
- if (segment === "*") continue;
262
- const hasOpenBrace = segment.includes("{");
263
- const hasCloseBrace = segment.includes("}");
264
- if (!hasOpenBrace && !hasCloseBrace) continue;
265
- if (!(segment.startsWith("{") && segment.endsWith("}"))) throw new Error("Route parameter segments must use complete {name} interpolation.");
266
- const rawParamName = normalizeRouteSegmentName(segment.slice(1, -1));
267
- const isSplat = rawParamName.startsWith("*");
268
- const paramName = isSplat ? normalizeRouteSegmentName(rawParamName.slice(1)) : rawParamName;
269
- if (!paramName) throw new Error(isSplat ? "Route splat parameter name cannot be empty." : "Route parameter name cannot be empty.");
270
- if (isSplat && paramName === "*") throw new Error("Route named splat parameter name cannot be \"*\".");
271
- if (isSplat && index !== segments.length - 1) throw new Error("Route named splat parameters must be the final segment.");
272
- if (seenParamNames.has(paramName)) throw new Error(`Route path cannot reuse duplicate parameter name "${paramName}".`);
273
- seenParamNames.add(paramName);
274
- }
275
- }
276
- function normalizeAbsoluteRoutePath(path) {
277
- if (!path || path === "/") return "/";
278
- return (path.endsWith("/") ? path.slice(0, -1) : path) || "/";
279
- }
280
- function joinRoutePaths(prefix, path) {
281
- const normalizedPrefix = normalizeAbsoluteRoutePath(prefix || "/");
282
- const normalizedPath = path.replace(/^\/+|\/+$/g, "");
283
- if (!normalizedPath) return normalizedPrefix;
284
- return normalizedPrefix === "/" ? `/${normalizedPath}` : `${normalizedPrefix}/${normalizedPath}`;
285
- }
286
- function resolvePageScopePath(path) {
287
- if (!path) throw new Error("page(path, Component, fn) requires a non-empty path.");
288
- if (path.startsWith("/")) {
289
- validateRoutePath(path);
290
- return normalizeAbsoluteRoutePath(path);
291
- }
292
- return joinRoutePaths(getCurrentPathPrefix(), path);
293
- }
294
- function resolveIndexPath() {
295
- return normalizeAbsoluteRoutePath(getCurrentPathPrefix() || "/");
296
- }
297
- function resolveRouteRegistrationPath(path) {
298
- if (path.startsWith("/")) {
299
- if (hasActivePageScope()) throw new Error(`Child route paths inside page() must be relative. Use "${path.slice(1)}" instead of "${path}".`);
300
- validateRoutePath(path);
301
- return normalizeAbsoluteRoutePath(path);
302
- }
303
- const prefix = getCurrentPathPrefix();
304
- if (!prefix) throw new Error(`Route path must begin with "/". Got: "${path}"`);
305
- return joinRoutePaths(prefix, path);
306
- }
307
- function insertRecordSorted(record) {
308
- let lo = 0;
309
- let hi = records.length;
310
- while (lo < hi) {
311
- const mid = lo + hi >>> 1;
312
- if (records[mid].rank >= record.rank) lo = mid + 1;
313
- else hi = mid;
314
- }
315
- records.splice(lo, 0, record);
316
- }
317
- function addRouteToStores(routeObj) {
318
- routes.push(routeObj);
319
- setHasRoutes(true);
320
- const depth = getDepth(routeObj.path);
321
- let depthRoutes = routesByDepth.get(depth);
322
- if (!depthRoutes) {
323
- depthRoutes = [];
324
- routesByDepth.set(depth, depthRoutes);
325
- }
326
- depthRoutes.push(routeObj);
327
- if (routeObj.namespace) namespaces.add(routeObj.namespace);
328
- }
329
- /** Promises from in-flight lazy() imports, drained by createSPA / hydrateSPA. */
330
- const pendingLazy = /* @__PURE__ */ new Set();
331
- const outletContext = defineContext(null);
332
- function Outlet() {
333
- return {
334
- $$typeof: ELEMENT_TYPE,
335
- type: Fragment,
336
- props: { children: readContext(outletContext) },
337
- key: null
338
- };
339
- }
340
- /**
341
- * Snapshot the current in-flight lazy() imports.
342
- * Boot uses this before clearing route state so manifest-based startup can
343
- * still await chunks that were kicked off during route module evaluation.
344
- */
345
- function _snapshotLazy() {
346
- return [...pendingLazy];
347
- }
348
- /**
349
- * Declare a code-split route component. The `import()` fires immediately at
350
- * module evaluation time (creating a bundler split point), and the resolved
351
- * chunk is guaranteed to be available before the app mounts — so the renderer
352
- * always receives a plain synchronous function.
353
- *
354
- * ```ts
355
- * registerRoutes(() => {
356
- * group({ layout: AppLayout }, () => {
357
- * route('/', lazy(() => import('./pages/landing')));
358
- * route('/dashboard', lazy(() => import('./pages/dashboard')));
359
- * });
360
- * });
361
- * ```
362
- *
363
- * The module must export the component as its **default** export:
364
- * ```ts
365
- * // pages/dashboard.tsx
366
- * export default function DashboardPage() { … }
367
- * ```
368
- */
369
- function lazy(factory) {
370
- let resolved = null;
371
- let loadError = null;
372
- const promise = factory().then((mod) => {
373
- resolved = typeof mod === "function" ? mod : mod.default;
374
- pendingLazy.delete(promise);
375
- }, (err) => {
376
- loadError = err;
377
- pendingLazy.delete(promise);
378
- });
379
- pendingLazy.add(promise);
380
- return ((params) => {
381
- if (loadError) throw loadError;
382
- if (!resolved) throw new Error("lazy() component used before it was resolved. Await createSPA() / hydrateSPA() to ensure all chunks load first.");
383
- return resolved(params);
384
- });
385
- }
386
- /**
387
- * Wait for all pending `lazy()` imports to settle.
388
- * Called automatically by `createSPA` / `hydrateSPA` before mounting.
389
- */
390
- function _drainLazy(additionalPending = []) {
391
- const combined = new Set([...additionalPending, ...pendingLazy]);
392
- if (combined.size === 0) return Promise.resolve();
393
- return Promise.allSettled(combined).then(() => void 0);
394
- }
395
- function group(options, fn) {
396
- pushGroupScope(options, fn);
397
- }
398
- function page(path, Component, optionsOrFn, maybeFn) {
399
- const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
400
- const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
401
- if (typeof Component !== "function") throw new Error("page(path, Component, fn) requires a component function as the second argument.");
402
- if (typeof fn !== "function") throw new Error("page(path, Component, fn) requires a route definition callback as the final argument.");
403
- pushPageScope(path, Component, options, fn);
404
- }
405
- function index(Component, options) {
406
- const pageScope = getCurrentPageScope();
407
- if (pageScope?.hasIndex) throw new Error("page() cannot declare multiple index routes.");
408
- if (pageScope) pageScope.hasIndex = true;
409
- registerRouteAtResolvedPath(resolveIndexPath(), Component, options);
410
- }
411
- function fallback(Component) {
412
- if (hasActivePageScope()) {
413
- if (getCurrentScopeKind() !== "page") throw new Error("fallback() inside page() must be declared directly in the page scope, not inside nested group().");
414
- registerRouteAtResolvedPath(`${getCurrentPathPrefix()}/*`, Component, void 0, {
415
- isFallback: true,
416
- fallbackPrefix: getCurrentPathPrefix()
417
- });
418
- return;
419
- }
420
- if (!registrationScopeStack.every((scope) => scope.policies.length === 0 && !scope.state.guestOnly && !scope.state.authenticated)) throw new Error("fallback() can only be registered at the root scope. Use route(\"/*\", Component) if you need compatibility behavior.");
421
- registerRouteAtResolvedPath("/*", Component, void 0, {
422
- isFallback: true,
423
- fallbackPrefix: "/"
424
- });
425
- }
426
- function pushRegistrationScope(scope, fn) {
427
- registrationScopeStack.push(scope);
428
- try {
429
- fn();
430
- } finally {
431
- registrationScopeStack.pop();
432
- }
433
- }
434
- function pushGroupScope(options, fn) {
435
- validateAccessMetadata(options, {
436
- authConfigured: getCurrentRegistrationSession().authConfigured,
437
- state: getCurrentAccessScopeState()
438
- });
439
- const policies = compileNodePolicies(options);
440
- pushRegistrationScope({
441
- kind: "group",
442
- pathPrefix: getCurrentPathPrefix(),
443
- layout: options.layout,
444
- policies,
445
- state: nextAccessScopeState(options, getCurrentAccessScopeState())
446
- }, fn);
447
- }
448
- function pushPageScope(path, Component, options, fn) {
449
- if (hasActivePageScope()) throw new Error("page() cannot be nested inside another page(). Use route() for child leaves or group() for inherited behavior inside the existing page scope.");
450
- validateAccessMetadata(options, {
451
- authConfigured: getCurrentRegistrationSession().authConfigured,
452
- state: getCurrentAccessScopeState()
453
- });
454
- const policies = compileNodePolicies(options);
455
- pushRegistrationScope({
456
- kind: "page",
457
- pathPrefix: resolvePageScopePath(path),
458
- page: Component,
459
- hasIndex: false,
460
- policies,
461
- state: nextAccessScopeState(options, getCurrentAccessScopeState())
462
- }, fn);
463
- }
464
- function hasBuiltInAuthMetadata(node) {
465
- return node.auth !== void 0 || !!node.role || !!node.permission;
466
- }
467
- function validateSameNodeAccessMetadata(node) {
468
- if (node.auth === "guest" && (!!node.role || !!node.permission)) throw new Error("Guest-only routes cannot be combined with role or permission requirements.");
469
- }
470
- function validateAccessMetadata(node, context) {
471
- validateSameNodeAccessMetadata(node);
472
- const requiresAuthenticated = node.auth === true || !!node.role || !!node.permission;
473
- if (node.auth === "guest" && (context.state.authenticated || !!node.role || !!node.permission)) throw new Error("Guest-only routes cannot be combined with authenticated access requirements.");
474
- if (context.state.guestOnly && requiresAuthenticated) throw new Error("Child routes cannot weaken a guest-only access scope with authenticated requirements.");
475
- if (hasBuiltInAuthMetadata(node) && !context.authConfigured) throw new Error("Routes using `auth`, `role`, or `permission` require `auth.resolve` in registerRoutes(...).");
476
- }
477
- function nextAccessScopeState(node, state) {
478
- const requiresAuthenticated = node.auth === true || !!node.role || !!node.permission;
479
- return {
480
- guestOnly: state.guestOnly || node.auth === "guest",
481
- authenticated: state.authenticated || requiresAuthenticated
482
- };
483
- }
484
- function compileNodePolicies(node) {
485
- validateSameNodeAccessMetadata(node);
486
- const compiled = [];
487
- if (node.auth === true) compiled.push(requireAuth());
488
- else if (node.auth === "guest") compiled.push(requireGuest());
489
- if (node.role) compiled.push(requireRole(node.role));
490
- if (node.permission) compiled.push(requirePermission(node.permission));
491
- if (node.policies?.length) compiled.push(...node.policies);
492
- return compiled;
493
- }
494
- function normalizeRouteOptions(options) {
495
- if (!options) return;
496
- const loader = options.loader;
497
- const policies = compileNodePolicies(options);
498
- if (!loader && !options.entries && policies.length === 0 && !options.title && !options.namespace && options.auth === void 0 && !options.role && !options.permission) return;
499
- return {
500
- ...loader ? { loader } : {},
501
- ...options.entries ? { entries: options.entries } : {},
502
- ...options.auth !== void 0 ? { auth: options.auth } : {},
503
- ...options.role ? { role: options.role } : {},
504
- ...options.permission ? { permission: options.permission } : {},
505
- ...policies.length > 0 ? { policies } : {},
506
- ...options.title ? { title: options.title } : {},
507
- ...options.namespace ? { namespace: options.namespace } : {}
508
- };
509
- }
510
- function applyPageChain(pageChain, params, content, deferComponents = false) {
511
- let nextContent = content;
512
- for (let i = pageChain.length - 1; i >= 0; i--) nextContent = outletContext.Scope({
513
- value: nextContent,
514
- children: deferComponents ? createRouteComponentVNode(pageChain[i].component, params) : pageChain[i].component(params)
515
- });
516
- return nextContent;
517
- }
518
- function createRouteComponentVNode(component, params, routeRoot = false) {
519
- return {
520
- $$typeof: ELEMENT_TYPE,
521
- type: component,
522
- props: params,
523
- key: null,
524
- ...routeRoot ? { [ROUTE_ROOT_COMPONENT]: true } : {}
525
- };
526
- }
527
- function createRouteHandler(component, pageChain, layoutChain, deferComponents = false) {
528
- return (params) => {
529
- let content = deferComponents ? createRouteComponentVNode(component, params, true) : component(params);
530
- content = applyPageChain(pageChain, params, content, deferComponents);
531
- for (let i = layoutChain.length - 1; i >= 0; i--) content = layoutChain[i].component({ children: content });
532
- return content;
533
- };
534
- }
535
- function getRenderHandler(record) {
536
- return record.renderHandler ?? createRouteHandler(record.component, record.pageChain, record.layoutChain, true);
537
- }
538
- function registerRouteAtResolvedPath(path, Component, options, metadata) {
539
- validateRoutePath(path);
540
- validateAccessMetadata(options ?? {}, {
541
- authConfigured: getCurrentRegistrationSession().authConfigured,
542
- state: getCurrentAccessScopeState()
543
- });
544
- const chain = getCurrentLayoutChain();
545
- const pageChain = getCurrentPageChain();
546
- const segments = parseSegments(path);
547
- const rank = computeRank(segments);
548
- const isFallback = metadata?.isFallback ?? path === "/*";
549
- const comp = Component;
550
- const normalizedOptions = normalizeRouteOptions(options);
551
- const policies = [...getCurrentInheritedPolicies(), ...normalizedOptions?.policies ?? []];
552
- const handler = createRouteHandler(comp, pageChain, chain);
553
- const renderHandler = createRouteHandler(comp, pageChain, chain, true);
554
- insertRecordSorted({
555
- path,
556
- component: comp,
557
- segments,
558
- rank,
559
- layoutChain: chain,
560
- pageChain,
561
- options: normalizedOptions ? {
562
- ...normalizedOptions,
563
- ...policies.length > 0 ? { policies } : {}
564
- } : policies.length > 0 ? { policies } : {},
565
- isFallback,
566
- handler,
567
- renderHandler,
568
- ...metadata?.fallbackPrefix ? { fallbackPrefix: metadata.fallbackPrefix } : {}
569
- });
570
- addRouteToStores({
571
- path,
572
- handler,
573
- namespace: normalizedOptions?.namespace ?? options?.namespace,
574
- ...metadata?.fallbackPrefix ? { fallbackPrefix: metadata.fallbackPrefix } : {}
575
- });
576
- }
577
- function registerRoutes(definition, options = {}) {
578
- defaultRouteAuthOptions = options.auth;
579
- registrationSessionStack.push({ authConfigured: !!options.auth?.resolve });
580
- try {
581
- definition();
582
- } finally {
583
- registrationSessionStack.pop();
584
- }
585
- }
586
- function readCurrentRouteSnapshot() {
587
- const instance = getCurrentComponentInstance();
588
- if (!instance) throw new Error("currentRoute() can only be called during component render execution. Call currentRoute() from inside your component function.");
589
- let pathname = "/";
590
- let search = "";
591
- let hash = "";
592
- const renderContext = getRenderContext();
593
- if (instance.ssr && renderContext?.url) {
594
- const parsed = parseLocation(renderContext.url);
595
- pathname = parsed.pathname;
596
- search = parsed.search;
597
- hash = parsed.hash;
598
- } else if (typeof window !== "undefined" && window.location) {
599
- pathname = window.location.pathname || "/";
600
- search = window.location.search || "";
601
- hash = window.location.hash || "";
602
- } else if (serverLocation) {
603
- const parsed = parseLocation(serverLocation);
604
- pathname = parsed.pathname;
605
- search = parsed.search;
606
- hash = parsed.hash;
607
- }
608
- const query = makeQuery(search);
609
- const matches = computeMatchesFromRoutes(pathname, getActiveRoutes());
610
- const instanceParams = instance.props;
611
- const params = deepFreeze({ ...Object.keys(instanceParams).length > 0 ? instanceParams : matches[0]?.params ?? {} });
612
- return Object.freeze({
613
- path: pathname,
614
- params,
615
- query,
616
- hash: hash || null,
617
- matches: Object.freeze(matches)
618
- });
619
- }
620
- function currentRoute() {
621
- const instance = getCurrentComponentInstance();
622
- if (!instance) throw new Error("currentRoute() can only be called during component render execution. Call currentRoute() from inside your component function.");
623
- if (typeof window === "undefined" || instance.ssr) return readCurrentRouteSnapshot();
624
- recordReadableRead(currentRouteSource);
625
- return readCurrentRouteSnapshot();
626
- }
627
- function syncCurrentRouteSnapshot(pathname, search, hash, activityMatches) {
628
- setCurrentRouteSnapshot(pathname, search, hash, activityMatches);
629
- }
630
- function route(path, Component, options) {
631
- if (typeof path === "undefined") throw new Error("route() is only for route registration. Use currentRoute() inside components.");
632
- if (getExecutionModel() === "islands") throw new Error("Routes are not supported with islands. Use createSPA (client) or createSSR (server) instead.");
633
- const currentInst = getCurrentComponentInstance();
634
- if (currentInst && currentInst.ssr) throw new Error("route() cannot be called during SSR rendering. Register routes at module load time instead.");
635
- if (registrationLocked) throw new Error("Route registration is locked after app startup. Register routes at module load time before calling createSPA or createSSR.");
636
- if (typeof Component !== "function") throw new Error("route(path, Component) requires a component function as the second argument. Passing JSX elements or VNodes directly is not supported.");
637
- registerRouteAtResolvedPath(resolveRouteRegistrationPath(path), Component, options);
638
- }
639
- /**
640
- * Return the normalized route manifest built from registered route definitions.
641
- *
642
- * Pass this to `createSPA`, `hydrateSPA`, or `renderToString` as the
643
- * authoritative routing input:
644
- *
645
- * ```ts
646
- * import { getManifest } from '@askrjs/askr/router';
647
- * await createSPA({ root: '#app', manifest: getManifest() });
648
- * ```
649
- */
650
- function getManifest() {
651
- return {
652
- records: [...records],
653
- ...defaultRouteAuthOptions ? { auth: defaultRouteAuthOptions } : {}
654
- };
655
- }
656
- /**
657
- * Internal: apply a pre-built manifest to the runtime stores without running
658
- * route() again. Called by createSPA / hydrateSPA when a manifest is passed.
659
- */
660
- function _applyManifest(manifest) {
661
- defaultRouteAuthOptions = manifest.auth;
662
- for (const record of manifest.records) {
663
- insertRecordSorted(record);
664
- addRouteToStores({
665
- path: record.path,
666
- handler: record.handler,
667
- namespace: record.options.namespace,
668
- ..."fallbackPrefix" in record && typeof record.fallbackPrefix === "string" ? { fallbackPrefix: record.fallbackPrefix } : {}
669
- });
670
- }
671
- }
672
- /**
673
- * Get all registered routes (flat list, insertion order).
674
- * Prefer `getManifest()` when metadata (loader, policies, entries) is needed.
675
- */
676
- function getRoutes() {
677
- return [...routes];
678
- }
679
- /** Clear all registered routes and records (testing / boot reset). */
680
- function clearRoutes() {
681
- routes.length = 0;
682
- records.length = 0;
683
- namespaces.clear();
684
- routesByDepth.clear();
685
- registrationScopeStack.length = 0;
686
- registrationSessionStack.length = 0;
687
- registrationLocked = false;
688
- defaultRouteAuthOptions = void 0;
689
- activeClientRouteAuthOptions = void 0;
690
- setHasRoutes(false);
691
- pendingLazy.clear();
692
- }
693
- function findBestScopedFallbackRecord(pathname, routeRecords) {
694
- let bestRecord = null;
695
- let bestParams = null;
696
- let bestPrefixLength = -1;
697
- for (const routeRecord of routeRecords) {
698
- const record = routeRecord;
699
- if (!record.fallbackPrefix) continue;
700
- const params = matchFallbackPrefix(pathname, record.fallbackPrefix);
701
- if (params === null) continue;
702
- if (record.fallbackPrefix.length > bestPrefixLength) {
703
- bestRecord = record;
704
- bestParams = params;
705
- bestPrefixLength = record.fallbackPrefix.length;
706
- }
707
- }
708
- return bestRecord && bestParams ? {
709
- record: bestRecord,
710
- params: bestParams
711
- } : null;
712
- }
713
- /**
714
- * Resolve a path to a route handler.
715
- *
716
- * Hot path: walks the module-level `records[]` array which is kept sorted by
717
- * rank descending at registration time — so the first `matchSegments` hit is
718
- * always the most specific match. No per-call allocations for the common
719
- * case of purely-static routes.
720
- */
721
- function resolveRoute(pathname) {
722
- const normalized = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname;
723
- const urlParts = splitPathSegments(normalized);
724
- for (const record of records) {
725
- if (record.fallbackPrefix) continue;
726
- const params = matchSegments(urlParts, record.segments);
727
- if (params !== null) return {
728
- handler: record.handler,
729
- params
730
- };
731
- }
732
- const fallbackMatch = findBestScopedFallbackRecord(normalized, records);
733
- return fallbackMatch ? {
734
- handler: fallbackMatch.record.handler,
735
- params: fallbackMatch.params
736
- } : null;
737
- }
738
- function getMatchingRecord(target, routeRecords) {
739
- const location = parseLocation(target);
740
- const normalized = location.pathname.endsWith("/") && location.pathname !== "/" ? location.pathname.slice(0, -1) : location.pathname;
741
- const urlParts = splitPathSegments(normalized);
742
- for (const record of routeRecords) {
743
- if (record.fallbackPrefix) continue;
744
- const params = matchSegments(urlParts, record.segments);
745
- if (params !== null) return {
746
- record,
747
- params
748
- };
749
- }
750
- return findBestScopedFallbackRecord(normalized, routeRecords);
751
- }
752
- function getRoutePolicies(options) {
753
- if (!options) return [];
754
- if (options.policies?.length) return options.policies;
755
- return compileNodePolicies(options);
756
- }
757
- function getDefaultRouteMode() {
758
- if (typeof window !== "undefined") return "spa";
759
- return "ssr";
760
- }
761
- function createRenderDataAwareHandler(handler, data) {
762
- return (params, context) => {
763
- const renderContext = getRenderContext();
764
- if (renderContext) renderContext.renderData = data ?? null;
765
- return handler(params, context);
766
- };
767
- }
768
- function buildRenderResult(record, params, mode) {
769
- const renderHandler = getRenderHandler(record);
770
- const loader = mode === "ssr" ? record.options?.loader : void 0;
771
- if (loader) {
772
- const loaded = loader({ params });
773
- const finalize = (data) => ({
774
- kind: "render",
775
- handler: createRenderDataAwareHandler(renderHandler, data),
776
- params
777
- });
778
- if (isPromiseLike(loaded)) return Promise.resolve(loaded).then((data) => finalize(data));
779
- return finalize(loaded);
780
- }
781
- return {
782
- kind: "render",
783
- handler: renderHandler,
784
- params
785
- };
786
- }
787
- function continueRoutePolicies(policies, context, record, params, startIndex = 0) {
788
- for (let index = startIndex; index < policies.length; index += 1) {
789
- const policyResult = policies[index](context);
790
- if (isPromiseLike(policyResult)) return Promise.resolve(policyResult).then((next) => {
791
- if (next.kind !== "allow") return next;
792
- return continueRoutePolicies(policies, context, record, params, index + 1);
793
- });
794
- if (policyResult.kind !== "allow") return policyResult;
795
- }
796
- return buildRenderResult(record, params, context.mode);
797
- }
798
- function resolveRouteRequest(target, options = {}) {
799
- const match = getMatchingRecord(target, options.manifest?.records ?? records);
800
- if (!match) return null;
801
- const { record, params } = match;
802
- const policies = getRoutePolicies(record.options);
803
- const mode = options.mode ?? getDefaultRouteMode();
804
- if (policies.length === 0) return buildRenderResult(record, params, mode);
805
- const signal = options.signal ?? getRenderContext()?.signal ?? new AbortController().signal;
806
- const auth = getActiveRouteAuthOptions(options.auth ?? options.manifest?.auth);
807
- const baseContext = buildRouteContextBase(target, params, {
808
- mode,
809
- signal
810
- });
811
- const finalize = (authState) => continueRoutePolicies(policies, buildRouteContext(target, params, {
812
- mode,
813
- signal,
814
- auth,
815
- session: authState.session,
816
- user: authState.user
817
- }), record, params);
818
- if (!auth?.resolve) return finalize({
819
- session: null,
820
- user: null
821
- });
822
- const authState = auth.resolve(baseContext);
823
- if (isPromiseLike(authState)) return Promise.resolve(authState).then((next) => finalize(next));
824
- return finalize(authState);
825
- }
826
- /**
827
- * Resolve a path against an explicit route list (e.g. an SSR per-render
828
- * context). When called with the global `routes` array this delegates to
829
- * the faster `resolveRoute` which uses pre-sorted `records[]`.
830
- *
831
- * For externally supplied lists the function:
832
- * 1. Builds a rank-sorted copy of the list on first call and caches it
833
- * in a WeakMap so subsequent resolutions against the same list pay
834
- * zero sort cost.
835
- * 2. Uses pre-parsed `ParsedSegment[]` from a WeakMap cache so no string
836
- * splitting or segment parsing occurs on the hot path.
837
- * 3. Uses a running-best with an early-exit once the sorted list reaches
838
- * a rank that cannot beat the current best match.
839
- */
840
- function resolveRouteFromRoutes(pathname, routeList) {
841
- if (routeList === routes) return resolveRoute(pathname);
842
- const match = findBestResolvedRouteFromRoutes(pathname, routeList);
843
- return match ? {
844
- handler: match.route.handler,
845
- params: match.params
846
- } : null;
847
- }
848
- function _resolveRouteMatchFromRoutes(pathname, routeList) {
849
- return findBestResolvedRouteFromRoutes(pathname, routeList);
850
- }
851
- //#endregion
852
- export { Outlet, _applyManifest, _drainLazy, _resolveRouteMatchFromRoutes, _setActiveRouteAuthOptions, _snapshotLazy, clearRoutes, computeRouteActivityMatches, currentRoute, fallback, getManifest, getRoutes, group, index, lazy, lockRouteRegistration, page, registerRoutes, resolveRouteFromRoutes, resolveRouteRequest, route, setServerLocation, syncCurrentRouteSnapshot };
853
-
854
- //# sourceMappingURL=route.js.map
1
+ import { Outlet } from "./rendering.js";
2
+ import { _setActiveRouteAuthOptions, getRoutes, hasRegisteredRoutes, lockRouteRegistration } from "./store.js";
3
+ import { fallback, group, index, page, registerRoutes, route } from "./authoring.js";
4
+ import { computeRouteActivityMatches, resolveRouteFromRoutes, resolveRouteRequest } from "./resolution.js";
5
+ import { currentRoute, setServerLocation, syncCurrentRouteSnapshot } from "./activity.js";
6
+ import { _drainLazy, _snapshotLazy, _snapshotRouteSourceLazy, lazy } from "./lazy.js";
7
+ import { _applyManifest, clearRoutes, createRouteRegistry, getManifest } from "./manifest.js";
8
+ export { Outlet, _applyManifest, _drainLazy, _setActiveRouteAuthOptions, _snapshotLazy, _snapshotRouteSourceLazy, clearRoutes, computeRouteActivityMatches, createRouteRegistry, currentRoute, fallback, getManifest, getRoutes, group, hasRegisteredRoutes, index, lazy, lockRouteRegistration, page, registerRoutes, resolveRouteFromRoutes, resolveRouteRequest, route, setServerLocation, syncCurrentRouteSnapshot };