@askrjs/askr 0.0.48 → 0.0.49

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 (394) 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 +1 -1
  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 +2 -0
  80. package/dist/jsx/types.js +2 -1
  81. package/dist/jsx-runtime2.d.ts +2 -1
  82. package/dist/jsx-runtime2.js +3 -2
  83. package/dist/renderer/attributes.js +231 -0
  84. package/dist/renderer/attributes.js.map +1 -0
  85. package/dist/renderer/boundaries.js +266 -0
  86. package/dist/renderer/boundaries.js.map +1 -0
  87. package/dist/renderer/child-shape.js +85 -0
  88. package/dist/renderer/child-shape.js.map +1 -0
  89. package/dist/renderer/children.js +3 -2
  90. package/dist/renderer/children.js.map +1 -1
  91. package/dist/renderer/cleanup.js +2 -1
  92. package/dist/renderer/cleanup.js.map +1 -1
  93. package/dist/renderer/component-host-cleanup.js +68 -0
  94. package/dist/renderer/component-host-cleanup.js.map +1 -0
  95. package/dist/renderer/component-host-instances.js +65 -0
  96. package/dist/renderer/component-host-instances.js.map +1 -0
  97. package/dist/renderer/component-host.js +247 -0
  98. package/dist/renderer/component-host.js.map +1 -0
  99. package/dist/renderer/dom-host.js +13 -0
  100. package/dist/renderer/dom-host.js.map +1 -0
  101. package/dist/renderer/dom-internal.js +185 -0
  102. package/dist/renderer/dom-internal.js.map +1 -0
  103. package/dist/renderer/dom.js +9 -2356
  104. package/dist/renderer/element-children.js +279 -0
  105. package/dist/renderer/element-children.js.map +1 -0
  106. package/dist/renderer/env.js +2 -1
  107. package/dist/renderer/error-boundary-dom.js +29 -0
  108. package/dist/renderer/error-boundary-dom.js.map +1 -0
  109. package/dist/renderer/evaluate-dom-range.js +85 -0
  110. package/dist/renderer/evaluate-dom-range.js.map +1 -0
  111. package/dist/renderer/evaluate-reconcile.js +281 -0
  112. package/dist/renderer/evaluate-reconcile.js.map +1 -0
  113. package/dist/renderer/evaluate.js +13 -399
  114. package/dist/renderer/evaluate.js.map +1 -1
  115. package/dist/renderer/fastpath.js +6 -5
  116. package/dist/renderer/fastpath.js.map +1 -1
  117. package/dist/renderer/for-commit-dom-map.js +83 -0
  118. package/dist/renderer/for-commit-dom-map.js.map +1 -0
  119. package/dist/renderer/for-commit-removal.js +36 -0
  120. package/dist/renderer/for-commit-removal.js.map +1 -0
  121. package/dist/renderer/for-commit-reorder.js +89 -0
  122. package/dist/renderer/for-commit-reorder.js.map +1 -0
  123. package/dist/renderer/for-commit.js +6 -188
  124. package/dist/renderer/for-commit.js.map +1 -1
  125. package/dist/renderer/index.js +28 -16
  126. package/dist/renderer/index.js.map +1 -1
  127. package/dist/renderer/keyed-children.js +32 -0
  128. package/dist/renderer/keyed-children.js.map +1 -0
  129. package/dist/renderer/keyed.js +2 -15
  130. package/dist/renderer/keyed.js.map +1 -1
  131. package/dist/renderer/namespaces.js +23 -0
  132. package/dist/renderer/namespaces.js.map +1 -0
  133. package/dist/renderer/prop-bindings.js +280 -0
  134. package/dist/renderer/prop-bindings.js.map +1 -0
  135. package/dist/renderer/reactive-child-dom.js +133 -0
  136. package/dist/renderer/reactive-child-dom.js.map +1 -0
  137. package/dist/renderer/reactive-child-sources.js +184 -0
  138. package/dist/renderer/reactive-child-sources.js.map +1 -0
  139. package/dist/renderer/reactive-children.js +294 -0
  140. package/dist/renderer/reactive-children.js.map +1 -0
  141. package/dist/renderer/reconcile-commit.js +38 -0
  142. package/dist/renderer/reconcile-commit.js.map +1 -0
  143. package/dist/renderer/reconcile-fastpaths.js +106 -0
  144. package/dist/renderer/reconcile-fastpaths.js.map +1 -0
  145. package/dist/renderer/reconcile-resolution.js +187 -0
  146. package/dist/renderer/reconcile-resolution.js.map +1 -0
  147. package/dist/renderer/reconcile.js +9 -371
  148. package/dist/renderer/reconcile.js.map +1 -1
  149. package/dist/renderer/retained-element-rollback.js +276 -0
  150. package/dist/renderer/retained-element-rollback.js.map +1 -0
  151. package/dist/renderer/stable-patch.js +82 -0
  152. package/dist/renderer/stable-patch.js.map +1 -0
  153. package/dist/renderer/static-reuse.js +96 -0
  154. package/dist/renderer/static-reuse.js.map +1 -0
  155. package/dist/renderer/types.js +2 -1
  156. package/dist/renderer/utils.js +4 -4
  157. package/dist/renderer/utils.js.map +1 -1
  158. package/dist/resources/index.d.ts +3 -2
  159. package/dist/resources/index.js +5 -2
  160. package/dist/router/access.js +36 -0
  161. package/dist/router/access.js.map +1 -0
  162. package/dist/router/activity.d.ts +10 -0
  163. package/dist/router/activity.d.ts.map +1 -0
  164. package/dist/router/activity.js +89 -0
  165. package/dist/router/activity.js.map +1 -0
  166. package/dist/router/authoring.d.ts +22 -0
  167. package/dist/router/authoring.d.ts.map +1 -0
  168. package/dist/router/authoring.js +198 -0
  169. package/dist/router/authoring.js.map +1 -0
  170. package/dist/router/index.d.ts +12 -4
  171. package/dist/router/index.js +10 -3
  172. package/dist/router/internal-types.d.ts +31 -0
  173. package/dist/router/internal-types.d.ts.map +1 -0
  174. package/dist/router/lazy.d.ts +19 -0
  175. package/dist/router/lazy.d.ts.map +1 -0
  176. package/dist/router/lazy.js +52 -0
  177. package/dist/router/lazy.js.map +1 -0
  178. package/dist/router/manifest.d.ts +10 -0
  179. package/dist/router/manifest.d.ts.map +1 -0
  180. package/dist/router/manifest.js +49 -0
  181. package/dist/router/manifest.js.map +1 -0
  182. package/dist/router/navigate.d.ts +4 -51
  183. package/dist/router/navigate.d.ts.map +1 -1
  184. package/dist/router/navigate.js +16 -459
  185. package/dist/router/navigate.js.map +1 -1
  186. package/dist/router/navigation-registry.d.ts +32 -0
  187. package/dist/router/navigation-registry.d.ts.map +1 -0
  188. package/dist/router/navigation-registry.js +105 -0
  189. package/dist/router/navigation-registry.js.map +1 -0
  190. package/dist/router/navigation-scroll.d.ts +14 -0
  191. package/dist/router/navigation-scroll.d.ts.map +1 -0
  192. package/dist/router/navigation-scroll.js +93 -0
  193. package/dist/router/navigation-scroll.js.map +1 -0
  194. package/dist/router/navigation-targets.d.ts +31 -0
  195. package/dist/router/navigation-targets.d.ts.map +1 -0
  196. package/dist/router/navigation-targets.js +253 -0
  197. package/dist/router/navigation-targets.js.map +1 -0
  198. package/dist/router/policy.d.ts +7 -1
  199. package/dist/router/policy.d.ts.map +1 -1
  200. package/dist/router/policy.js +27 -9
  201. package/dist/router/policy.js.map +1 -1
  202. package/dist/router/rendering.d.ts +10 -0
  203. package/dist/router/rendering.d.ts.map +1 -0
  204. package/dist/router/rendering.js +45 -0
  205. package/dist/router/rendering.js.map +1 -0
  206. package/dist/router/resolution.d.ts +17 -0
  207. package/dist/router/resolution.d.ts.map +1 -0
  208. package/dist/router/resolution.js +253 -0
  209. package/dist/router/resolution.js.map +1 -0
  210. package/dist/router/route-query.d.ts +17 -0
  211. package/dist/router/route-query.d.ts.map +1 -0
  212. package/dist/router/route-query.js +47 -0
  213. package/dist/router/route-query.js.map +1 -0
  214. package/dist/router/route.d.ts +8 -149
  215. package/dist/router/route.js +8 -854
  216. package/dist/router/store.d.ts +50 -0
  217. package/dist/router/store.d.ts.map +1 -0
  218. package/dist/router/store.js +171 -0
  219. package/dist/router/store.js.map +1 -0
  220. package/dist/runtime/access.js +45 -0
  221. package/dist/runtime/access.js.map +1 -0
  222. package/dist/runtime/child-scope.d.ts +1 -1
  223. package/dist/runtime/child-scope.js +4 -1
  224. package/dist/runtime/child-scope.js.map +1 -1
  225. package/dist/runtime/component-cleanup.d.ts +16 -0
  226. package/dist/runtime/component-cleanup.d.ts.map +1 -0
  227. package/dist/runtime/component-cleanup.js +70 -0
  228. package/dist/runtime/component-cleanup.js.map +1 -0
  229. package/dist/runtime/component-commit.js +165 -0
  230. package/dist/runtime/component-commit.js.map +1 -0
  231. package/dist/runtime/component-contracts.js +5 -0
  232. package/dist/runtime/component-facade.d.ts +5 -0
  233. package/dist/runtime/component-facade.js +4 -0
  234. package/dist/runtime/component-internal.d.ts +100 -0
  235. package/dist/runtime/component-internal.d.ts.map +1 -0
  236. package/dist/runtime/component-internal.js +219 -0
  237. package/dist/runtime/component-internal.js.map +1 -0
  238. package/dist/runtime/component-lifecycle.d.ts +49 -0
  239. package/dist/runtime/component-lifecycle.d.ts.map +1 -0
  240. package/dist/runtime/component-lifecycle.js +176 -0
  241. package/dist/runtime/component-lifecycle.js.map +1 -0
  242. package/dist/runtime/component-scope.d.ts +55 -0
  243. package/dist/runtime/component-scope.d.ts.map +1 -0
  244. package/dist/runtime/component-scope.js +154 -0
  245. package/dist/runtime/component-scope.js.map +1 -0
  246. package/dist/runtime/component.d.ts +4 -152
  247. package/dist/runtime/component.js +4 -692
  248. package/dist/runtime/context.d.ts +1 -1
  249. package/dist/runtime/context.js +6 -4
  250. package/dist/runtime/context.js.map +1 -1
  251. package/dist/runtime/control.d.ts +3 -3
  252. package/dist/runtime/control.js +2 -1
  253. package/dist/runtime/control.js.map +1 -1
  254. package/dist/runtime/derive.d.ts.map +1 -1
  255. package/dist/runtime/derive.js +6 -5
  256. package/dist/runtime/derive.js.map +1 -1
  257. package/dist/runtime/effect.d.ts +1 -1
  258. package/dist/runtime/effect.d.ts.map +1 -1
  259. package/dist/runtime/effect.js +2 -2
  260. package/dist/runtime/effect.js.map +1 -1
  261. package/dist/runtime/events.js +3 -3
  262. package/dist/runtime/events.js.map +1 -1
  263. package/dist/runtime/fastlane.js +13 -27
  264. package/dist/runtime/fastlane.js.map +1 -1
  265. package/dist/runtime/for-bench.d.ts +1 -1
  266. package/dist/runtime/for-bench.js +1 -4
  267. package/dist/runtime/for-bench.js.map +1 -1
  268. package/dist/runtime/for-internal.d.ts +43 -0
  269. package/dist/runtime/for-internal.d.ts.map +1 -0
  270. package/dist/runtime/for-internal.js +98 -0
  271. package/dist/runtime/for-internal.js.map +1 -0
  272. package/dist/runtime/for-reconcile.d.ts +8 -0
  273. package/dist/runtime/for-reconcile.d.ts.map +1 -0
  274. package/dist/runtime/for-reconcile.js +389 -0
  275. package/dist/runtime/for-reconcile.js.map +1 -0
  276. package/dist/runtime/for-scopes.d.ts +26 -0
  277. package/dist/runtime/for-scopes.d.ts.map +1 -0
  278. package/dist/runtime/for-scopes.js +160 -0
  279. package/dist/runtime/for-scopes.js.map +1 -0
  280. package/dist/runtime/for-signals.d.ts +30 -0
  281. package/dist/runtime/for-signals.d.ts.map +1 -0
  282. package/dist/runtime/for-signals.js +139 -0
  283. package/dist/runtime/for-signals.js.map +1 -0
  284. package/dist/runtime/for.d.ts +4 -66
  285. package/dist/runtime/for.js +5 -773
  286. package/dist/runtime/lifecycle-operations.d.ts +31 -0
  287. package/dist/runtime/lifecycle-operations.d.ts.map +1 -0
  288. package/dist/runtime/lifecycle-operations.js +195 -0
  289. package/dist/runtime/lifecycle-operations.js.map +1 -0
  290. package/dist/runtime/operations.d.ts +3 -40
  291. package/dist/runtime/operations.js +2 -357
  292. package/dist/runtime/readable.d.ts +2 -3
  293. package/dist/runtime/readable.d.ts.map +1 -1
  294. package/dist/runtime/readable.js +6 -5
  295. package/dist/runtime/readable.js.map +1 -1
  296. package/dist/runtime/resource-cell.js +2 -2
  297. package/dist/runtime/resource-cell.js.map +1 -1
  298. package/dist/runtime/resource-operation.d.ts +13 -0
  299. package/dist/runtime/resource-operation.d.ts.map +1 -0
  300. package/dist/runtime/resource-operation.js +170 -0
  301. package/dist/runtime/resource-operation.js.map +1 -0
  302. package/dist/runtime/runtime.d.ts +42 -0
  303. package/dist/runtime/runtime.d.ts.map +1 -0
  304. package/dist/runtime/runtime.js +59 -0
  305. package/dist/runtime/runtime.js.map +1 -0
  306. package/dist/runtime/scheduler.d.ts +5 -1
  307. package/dist/runtime/scheduler.d.ts.map +1 -1
  308. package/dist/runtime/scheduler.js +17 -17
  309. package/dist/runtime/scheduler.js.map +1 -1
  310. package/dist/runtime/selector.js +4 -3
  311. package/dist/runtime/selector.js.map +1 -1
  312. package/dist/runtime/snapshot-source.d.ts +1 -1
  313. package/dist/runtime/snapshot-source.js +1 -1
  314. package/dist/runtime/state.js +2 -1
  315. package/dist/runtime/state.js.map +1 -1
  316. package/dist/ssg/batch-render.js +2 -1
  317. package/dist/ssg/batch-render.js.map +1 -1
  318. package/dist/ssg/create-static-gen.d.ts +9 -3
  319. package/dist/ssg/create-static-gen.d.ts.map +1 -1
  320. package/dist/ssg/create-static-gen.js +12 -99
  321. package/dist/ssg/create-static-gen.js.map +1 -1
  322. package/dist/ssg/generation-plan.js +70 -0
  323. package/dist/ssg/generation-plan.js.map +1 -0
  324. package/dist/ssg/incremental-manifest.js +1 -1
  325. package/dist/ssg/static-routes.js +101 -0
  326. package/dist/ssg/static-routes.js.map +1 -0
  327. package/dist/ssg/types.d.ts +15 -7
  328. package/dist/ssg/types.d.ts.map +1 -1
  329. package/dist/ssr/boundaries.js +113 -0
  330. package/dist/ssr/boundaries.js.map +1 -0
  331. package/dist/ssr/component-runtime.js +111 -0
  332. package/dist/ssr/component-runtime.js.map +1 -0
  333. package/dist/ssr/context.d.ts +3 -1
  334. package/dist/ssr/context.d.ts.map +1 -1
  335. package/dist/ssr/context.js +9 -2
  336. package/dist/ssr/context.js.map +1 -1
  337. package/dist/ssr/errors.d.ts +2 -0
  338. package/dist/ssr/errors.js +11 -1
  339. package/dist/ssr/errors.js.map +1 -1
  340. package/dist/ssr/escape.js +3 -3
  341. package/dist/ssr/escape.js.map +1 -1
  342. package/dist/ssr/hydration-data.js +10 -0
  343. package/dist/ssr/hydration-data.js.map +1 -0
  344. package/dist/ssr/hydration-verify.d.ts +12 -0
  345. package/dist/ssr/hydration-verify.d.ts.map +1 -0
  346. package/dist/ssr/hydration-verify.js +144 -0
  347. package/dist/ssr/hydration-verify.js.map +1 -0
  348. package/dist/ssr/index-internal.d.ts +15 -0
  349. package/dist/ssr/index-internal.d.ts.map +1 -0
  350. package/dist/ssr/index-internal.js +19 -0
  351. package/dist/ssr/index-internal.js.map +1 -0
  352. package/dist/ssr/index.d.ts +5 -57
  353. package/dist/ssr/index.js +3 -738
  354. package/dist/ssr/render-keys.js +9 -32
  355. package/dist/ssr/render-keys.js.map +1 -1
  356. package/dist/ssr/render-resolved.d.ts +1 -1
  357. package/dist/ssr/render-resolved.d.ts.map +1 -1
  358. package/dist/ssr/render-resolved.js +4 -2
  359. package/dist/ssr/render-resolved.js.map +1 -1
  360. package/dist/ssr/render-sync.d.ts +21 -0
  361. package/dist/ssr/render-sync.d.ts.map +1 -0
  362. package/dist/ssr/render-sync.js +275 -0
  363. package/dist/ssr/render-sync.js.map +1 -0
  364. package/dist/ssr/route-policy-resolution.js +77 -0
  365. package/dist/ssr/route-policy-resolution.js.map +1 -0
  366. package/dist/ssr/route-render.d.ts +77 -0
  367. package/dist/ssr/route-render.d.ts.map +1 -0
  368. package/dist/ssr/route-render.js +119 -0
  369. package/dist/ssr/route-render.js.map +1 -0
  370. package/dist/ssr/sink.d.ts +26 -0
  371. package/dist/ssr/sink.d.ts.map +1 -0
  372. package/dist/ssr/types.d.ts +1 -0
  373. package/dist/ssr/types.d.ts.map +1 -1
  374. package/dist/ssr/verify-hydration.js.map +1 -1
  375. package/dist/testing/index.d.ts +1 -2
  376. package/dist/testing/index.d.ts.map +1 -1
  377. package/dist/testing/index.js +2 -1
  378. package/dist/testing/index.js.map +1 -1
  379. package/package.json +4 -3
  380. package/dist/data/index.d.ts.map +0 -1
  381. package/dist/data/index.js.map +0 -1
  382. package/dist/renderer/dom.js.map +0 -1
  383. package/dist/router/route.d.ts.map +0 -1
  384. package/dist/router/route.js.map +0 -1
  385. package/dist/runtime/component.d.ts.map +0 -1
  386. package/dist/runtime/component.js.map +0 -1
  387. package/dist/runtime/for.d.ts.map +0 -1
  388. package/dist/runtime/for.js.map +0 -1
  389. package/dist/runtime/operations.d.ts.map +0 -1
  390. package/dist/runtime/operations.js.map +0 -1
  391. package/dist/runtime/ssr-bridge.js +0 -24
  392. package/dist/runtime/ssr-bridge.js.map +0 -1
  393. package/dist/ssr/index.d.ts.map +0 -1
  394. package/dist/ssr/index.js.map +0 -1
package/dist/ssr/index.js CHANGED
@@ -1,741 +1,6 @@
1
- import { __CONTROL_BOUNDARY__ } from "../common/control.js";
2
- import { __ERROR_BOUNDARY__ } from "../common/vnode.js";
3
- import { logger } from "../dev/logger.js";
4
- import { ELEMENT_TYPE, Fragment } from "../common/jsx.js";
5
- import { isPromiseLike } from "../common/promise.js";
6
- import { getPublicAttributeName } from "../common/attr-names.js";
7
- import { cleanupComponent, createComponentInstance, getCurrentComponentInstance, setCurrentComponentInstance } from "../runtime/component.js";
8
- import { evaluateForState } from "../runtime/for.js";
9
- import { evaluateCaseState, evaluateShowState } from "../runtime/control.js";
10
1
  import { SSRDataMissingError } from "../common/ssr-errors.js";
11
- import { VOID_ELEMENTS, escapeText, styleObjToCss } from "./escape.js";
12
- import { createRenderContext, getRenderContext, throwSSRDataMissing, withRenderContext } from "./context.js";
13
- import { _resolveRouteMatchFromRoutes, resolveRouteFromRoutes, resolveRouteRequest } from "../router/route.js";
14
- import "../jsx/index.js";
15
- import { DefaultPortal, disposeDefaultPortalScope } from "../foundations/structures/portal.js";
16
- import { SSR_RENDER_DATA_ATTR, renderDocument } from "../common/ssr.js";
17
- import { getCurrentRenderData, getNextKey, startRenderPhase, stopRenderPhase } from "./render-keys.js";
18
- import { installSSRBridge } from "../runtime/ssr-bridge.js";
19
- import { renderAttrs, renderAttrsDirect } from "./attrs.js";
2
+ import { resolveRequest } from "./route-render.js";
3
+ import { renderToStringSync } from "./render-sync.js";
20
4
  import { renderResolvedToStringSync } from "./render-resolved.js";
21
- import { StreamSink, StringSink } from "./sink.js";
22
- //#region src/ssr/index.ts
23
- const __SSR_DEBUG = process.env.ASKR_SSR_DEBUG === "1" || process.env.ASKR_SSR_DEBUG === "true";
24
- function isSSRAttrEventHandler(key) {
25
- return key.length >= 3 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key.charCodeAt(2) >= 65 && key.charCodeAt(2) <= 90;
26
- }
27
- function inheritRenderableKey(source, result) {
28
- const inheritedKey = source.key;
29
- if (inheritedKey === void 0 || inheritedKey === null) return result;
30
- if (!result || typeof result !== "object" || !("type" in result)) return result;
31
- const resultVNode = result;
32
- if (resultVNode.key === void 0 || resultVNode.key === null) resultVNode.key = inheritedKey;
33
- if (typeof resultVNode.type === "string") {
34
- if (!resultVNode.props) resultVNode.props = {};
35
- if (resultVNode.props["data-key"] === void 0) resultVNode.props["data-key"] = String(inheritedKey);
36
- }
37
- return result;
38
- }
39
- installSSRBridge({
40
- getCurrentSSRContext: getRenderContext,
41
- throwSSRDataMissing,
42
- getCurrentRenderData,
43
- getNextKey
44
- });
45
- const __ssrGuardStack = [];
46
- function pushSSRStrictPurityGuard() {
47
- __ssrGuardStack.push({
48
- random: Reflect.get(Math, "random"),
49
- now: Reflect.get(Date, "now")
50
- });
51
- Reflect.set(Math, "random", () => {
52
- throw new Error("SSR Strict Purity: Math.random is not allowed during synchronous SSR. Use the provided `ssr` context RNG instead.");
53
- });
54
- Reflect.set(Date, "now", () => {
55
- throw new Error("SSR Strict Purity: Date.now is not allowed during synchronous SSR. Pass timestamps explicitly or use deterministic helpers.");
56
- });
57
- }
58
- function popSSRStrictPurityGuard() {
59
- const prev = __ssrGuardStack.pop();
60
- if (prev) {
61
- Reflect.set(Math, "random", prev.random);
62
- Reflect.set(Date, "now", prev.now);
63
- }
64
- }
65
- /**
66
- * Synchronous rendering helpers (used for strictly synchronous SSR)
67
- */
68
- function renderRenderableSync(value, ctx) {
69
- if (typeof value === "string") return escapeText(value);
70
- if (typeof value === "number") return escapeText(String(value));
71
- if (value === null || value === void 0 || value === false) return "";
72
- if (Array.isArray(value)) return renderChildrenSync(value, ctx);
73
- if (value && typeof value === "object" && "type" in value) return renderNodeSync(value, ctx);
74
- return "";
75
- }
76
- function renderChildSync(child, ctx) {
77
- return renderRenderableSync(child, ctx);
78
- }
79
- function renderRenderableSyncToSink(value, sink, ctx) {
80
- if (value === null || value === void 0 || value === false) return;
81
- if (typeof value === "string") {
82
- sink.write(escapeText(value));
83
- return;
84
- }
85
- if (typeof value === "number") {
86
- sink.write(escapeText(String(value)));
87
- return;
88
- }
89
- if (Array.isArray(value)) {
90
- renderChildrenSyncToSink(value, sink, ctx);
91
- return;
92
- }
93
- if (value && typeof value === "object" && "type" in value) renderNodeSyncToSink(value, sink, ctx);
94
- }
95
- function renderChildSyncToSink(child, sink, ctx) {
96
- renderRenderableSyncToSink(child, sink, ctx);
97
- }
98
- function serializeHydrationRenderData(data) {
99
- if (!data || Object.keys(data).length === 0) return "";
100
- return `<script type="application/json" ${SSR_RENDER_DATA_ATTR}="true">${JSON.stringify(data).replace(/</g, "\\u003C").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029")}<\/script>`;
101
- }
102
- function renderChildrenSync(children, ctx) {
103
- if (!children || !Array.isArray(children) || children.length === 0) return "";
104
- if (children.length === 1) return renderChildSync(children[0], ctx);
105
- if (children.length <= 8) {
106
- let result = "";
107
- for (const child of children) result += renderChildSync(child, ctx);
108
- return result;
109
- }
110
- return Array.from({ length: children.length }, (_, index) => renderChildSync(children[index], ctx)).join("");
111
- }
112
- function normalizeRenderableChildren(value) {
113
- if (value === null || value === void 0 || value === false) return [];
114
- return Array.isArray(value) ? value : [value];
115
- }
116
- function getErrorBoundaryState(node) {
117
- return node.__instance?.errorBoundaryState ?? null;
118
- }
119
- function createDefaultErrorBoundaryFallbackVNode(error) {
120
- const message = error instanceof Error ? error.stack || error.message || error.name : typeof error === "string" ? error : (() => {
121
- try {
122
- return JSON.stringify(error);
123
- } catch {
124
- return String(error);
125
- }
126
- })();
127
- return {
128
- $$typeof: ELEMENT_TYPE,
129
- type: "div",
130
- props: {
131
- role: "alert",
132
- "data-askr-error-boundary": "true",
133
- style: {
134
- boxSizing: "border-box",
135
- padding: "1rem",
136
- border: "1px solid currentColor",
137
- borderRadius: "0.75rem",
138
- display: "grid",
139
- gap: "0.75rem",
140
- maxWidth: "100%"
141
- },
142
- children: [
143
- {
144
- $$typeof: ELEMENT_TYPE,
145
- type: "strong",
146
- props: { children: ["Something went wrong while rendering this view."] }
147
- },
148
- {
149
- $$typeof: ELEMENT_TYPE,
150
- type: "p",
151
- props: {
152
- style: { margin: "0" },
153
- children: ["The app recovered into a visible fallback so the error is not hidden in the console."]
154
- }
155
- },
156
- {
157
- $$typeof: ELEMENT_TYPE,
158
- type: "details",
159
- props: {
160
- open: true,
161
- children: [{
162
- $$typeof: ELEMENT_TYPE,
163
- type: "summary",
164
- props: { children: ["Error details"] }
165
- }, {
166
- $$typeof: ELEMENT_TYPE,
167
- type: "pre",
168
- props: {
169
- style: {
170
- margin: "0",
171
- whiteSpace: "pre-wrap",
172
- wordBreak: "break-word"
173
- },
174
- children: [message]
175
- }
176
- }]
177
- }
178
- }
179
- ]
180
- },
181
- key: null
182
- };
183
- }
184
- function resolveErrorBoundaryFallbackNode(fallback, error, reset) {
185
- return typeof fallback === "function" ? fallback(error, reset) : fallback !== void 0 ? fallback : createDefaultErrorBoundaryFallbackVNode(error);
186
- }
187
- function renderErrorBoundaryFallbackValue(fallback, error, reset, ctx) {
188
- const nextValue = resolveErrorBoundaryFallbackNode(fallback, error, reset);
189
- return Array.isArray(nextValue) ? renderChildrenSync(normalizeRenderableChildren(nextValue), ctx) : renderChildSync(nextValue, ctx);
190
- }
191
- function renderErrorBoundaryFallbackValueToSink(fallback, error, reset, sink, ctx) {
192
- sink.write(renderErrorBoundaryFallbackValue(fallback, error, reset, ctx));
193
- }
194
- function getControlBoundaryState(node) {
195
- const boundaryNode = node;
196
- return boundaryNode._controlState ?? boundaryNode._forState ?? null;
197
- }
198
- function evaluateControlBoundaryChildren(node) {
199
- if (node.type !== __CONTROL_BOUNDARY__) return;
200
- const controlState = getControlBoundaryState(node);
201
- if (!controlState) return [];
202
- if (controlState.kind === "for") return evaluateForState(controlState);
203
- if (controlState.kind === "show") return evaluateShowState(controlState);
204
- return evaluateCaseState(controlState);
205
- }
206
- function renderChildrenSyncToSink(children, sink, ctx) {
207
- if (!children || !Array.isArray(children) || children.length === 0) return;
208
- if (children.length >= 32) {
209
- for (let i = 0; i < children.length; i++) renderRenderableSyncToSink(children[i], sink, ctx);
210
- return;
211
- }
212
- for (let i = 0; i < children.length; i++) renderChildSyncToSink(children[i], sink, ctx);
213
- }
214
- function sinkWrite2(sink, a, b) {
215
- if (typeof sink.write2 === "function") {
216
- sink.write2(a, b);
217
- return;
218
- }
219
- sink.write(a);
220
- sink.write(b);
221
- }
222
- function sinkWrite3(sink, a, b, c) {
223
- if (typeof sink.write3 === "function") {
224
- sink.write3(a, b, c);
225
- return;
226
- }
227
- sink.write(a);
228
- sink.write(b);
229
- sink.write(c);
230
- }
231
- /**
232
- * Render a VNode synchronously. Throws if an async component is encountered.
233
- */
234
- function renderNodeSync(node, ctx) {
235
- const { type, props } = node;
236
- /* istanbul ignore if - dev-only debug */
237
- if (__SSR_DEBUG) try {
238
- logger.warn("[SSR] renderNodeSync type:", typeof type, type);
239
- } catch {}
240
- if (typeof type === "function") return renderRenderableSync(inheritRenderableKey(node, executeComponentSync(type, props, ctx)), ctx);
241
- if (typeof type === "symbol") {
242
- if (type === Fragment) {
243
- const childrenArr = getRenderableChildren(node);
244
- /* istanbul ignore if - dev-only debug */
245
- if (__SSR_DEBUG) try {
246
- logger.warn("[SSR] fragment children length:", childrenArr?.length);
247
- } catch {}
248
- return renderChildrenSync(childrenArr, ctx);
249
- }
250
- if (type === __CONTROL_BOUNDARY__) return renderChildrenSync(evaluateControlBoundaryChildren(node), ctx);
251
- if (type === __ERROR_BOUNDARY__) {
252
- const boundaryState = getErrorBoundaryState(node);
253
- const fallback = props?.fallback;
254
- const reset = () => {
255
- const state = node.__instance?.errorBoundaryState;
256
- if (state) {
257
- state.error = null;
258
- state.notified = false;
259
- }
260
- };
261
- if (boundaryState?.error != null) return renderErrorBoundaryFallbackValue(fallback, boundaryState.error, reset, ctx);
262
- try {
263
- return renderChildrenSync(normalizeRenderableChildren(props?.children), ctx);
264
- } catch (error) {
265
- if (boundaryState) {
266
- boundaryState.error = error;
267
- boundaryState.notified = true;
268
- }
269
- logger.error("[Askr] ErrorBoundary caught render error:", error);
270
- return renderErrorBoundaryFallbackValue(fallback, error, reset, ctx);
271
- }
272
- }
273
- throw new Error(`renderNodeSync: unsupported VNode symbol type: ${String(type)}`);
274
- }
275
- const typeStr = type;
276
- if (VOID_ELEMENTS.has(typeStr)) return `<${typeStr}${renderAttrs(props)} />`;
277
- const maybeDangerous = props?.dangerouslySetInnerHTML;
278
- if (maybeDangerous !== void 0 && maybeDangerous !== null) {
279
- const { attrs, dangerousHtml } = renderAttrs(props, { returnDangerousHtml: true });
280
- if (dangerousHtml !== void 0) return `<${typeStr}${attrs}>${dangerousHtml}</${typeStr}>`;
281
- return `<${typeStr}${attrs}>${renderChildrenSync(getRenderableChildren(node), ctx)}</${typeStr}>`;
282
- }
283
- return `<${typeStr}${renderAttrs(props)}>${renderChildrenSync(getRenderableChildren(node), ctx)}</${typeStr}>`;
284
- }
285
- function renderNodeSyncToSink(node, sink, ctx) {
286
- const { type, props } = node;
287
- if (typeof type === "function") {
288
- renderRenderableSyncToSink(inheritRenderableKey(node, executeComponentSync(type, props, ctx)), sink, ctx);
289
- return;
290
- }
291
- if (typeof type === "symbol") {
292
- if (type === Fragment) {
293
- renderChildrenSyncToSink(getRenderableChildren(node), sink, ctx);
294
- return;
295
- }
296
- if (type === __CONTROL_BOUNDARY__) {
297
- renderChildrenSyncToSink(evaluateControlBoundaryChildren(node), sink, ctx);
298
- return;
299
- }
300
- if (type === __ERROR_BOUNDARY__) {
301
- const boundaryState = getErrorBoundaryState(node);
302
- const fallback = props?.fallback;
303
- const reset = () => {
304
- const state = node.__instance?.errorBoundaryState;
305
- if (state) {
306
- state.error = null;
307
- state.notified = false;
308
- }
309
- };
310
- if (boundaryState?.error != null) {
311
- renderErrorBoundaryFallbackValueToSink(fallback, boundaryState.error, reset, sink, ctx);
312
- return;
313
- }
314
- try {
315
- renderChildrenSyncToSink(normalizeRenderableChildren(props?.children), sink, ctx);
316
- } catch (error) {
317
- if (boundaryState) {
318
- boundaryState.error = error;
319
- boundaryState.notified = true;
320
- }
321
- logger.error("[Askr] ErrorBoundary caught render error:", error);
322
- renderErrorBoundaryFallbackValueToSink(fallback, error, reset, sink, ctx);
323
- }
324
- return;
325
- }
326
- throw new Error(`renderNodeSyncToSink: unsupported VNode symbol type: ${String(type)}`);
327
- }
328
- const typeStr = type;
329
- if (VOID_ELEMENTS.has(typeStr)) {
330
- sinkWrite2(sink, "<", typeStr);
331
- renderAttrsDirect(props, sink);
332
- sink.write(" />");
333
- return;
334
- }
335
- const maybeDangerous = props ? props?.dangerouslySetInnerHTML : void 0;
336
- if (maybeDangerous !== void 0 && maybeDangerous !== null) {
337
- const dangerousHtml = typeof maybeDangerous === "object" && "__html" in maybeDangerous ? String(maybeDangerous.__html) : void 0;
338
- sinkWrite2(sink, "<", typeStr);
339
- renderAttrsDirect(props, sink);
340
- sink.write(">");
341
- if (dangerousHtml !== void 0) sink.write(dangerousHtml);
342
- else renderChildrenSyncToSink(getRenderableChildren(node), sink, ctx);
343
- sinkWrite3(sink, "</", typeStr, ">");
344
- return;
345
- }
346
- const children = getRenderableChildren(node);
347
- if (!children || Array.isArray(children) && children.length === 0) {
348
- sinkWrite2(sink, "<", typeStr);
349
- renderAttrsDirect(props, sink);
350
- sink.write(">");
351
- sinkWrite3(sink, "</", typeStr, ">");
352
- return;
353
- }
354
- if (Array.isArray(children) && children.length === 1) {
355
- const only = children[0];
356
- if (typeof only === "string") {
357
- const content = escapeText(only);
358
- sinkWrite2(sink, "<", typeStr);
359
- renderAttrsDirect(props, sink);
360
- sink.write(">");
361
- sink.write(content);
362
- sinkWrite3(sink, "</", typeStr, ">");
363
- return;
364
- }
365
- if (typeof only === "number") {
366
- const content = escapeText(String(only));
367
- sinkWrite2(sink, "<", typeStr);
368
- renderAttrsDirect(props, sink);
369
- sink.write(">");
370
- sink.write(content);
371
- sinkWrite3(sink, "</", typeStr, ">");
372
- return;
373
- }
374
- }
375
- sinkWrite2(sink, "<", typeStr);
376
- renderAttrsDirect(props, sink);
377
- sink.write(">");
378
- renderChildrenSyncToSink(children, sink, ctx);
379
- sinkWrite3(sink, "</", typeStr, ">");
380
- }
381
- /**
382
- * Execute a component function (synchronously or async) and return VNode
383
- */
384
- /**
385
- * Execute a component synchronously inside a render-only context.
386
- * This must not create or reuse runtime ComponentInstance objects. We pass
387
- * the render context explicitly as `context.ssr` in the second argument so
388
- * components can opt-in to deterministic randomness/time via the provided RNG.
389
- */
390
- function executeComponentSync(component, props, ctx) {
391
- try {
392
- pushSSRStrictPurityGuard();
393
- const prev = getCurrentComponentInstance();
394
- const temp = createComponentInstance("ssr-temp", component, props || {}, null);
395
- temp.ssr = true;
396
- temp.portalScope = temp;
397
- ctx.ssrCleanupFns.push(() => {
398
- let cleanupError = null;
399
- try {
400
- cleanupComponent(temp);
401
- } catch (error) {
402
- cleanupError = error;
403
- }
404
- try {
405
- disposeDefaultPortalScope(temp);
406
- } catch (error) {
407
- if (cleanupError) throw new AggregateError([cleanupError, error], "SSR temporary owner cleanup failed");
408
- throw error;
409
- }
410
- if (cleanupError) throw cleanupError;
411
- });
412
- setCurrentComponentInstance(temp);
413
- try {
414
- const result = component(props || {}, { ssr: ctx });
415
- if (isPromiseLike(result)) throwSSRDataMissing();
416
- if (typeof result === "string" || typeof result === "number" || typeof result === "boolean" || result === null || result === void 0) {
417
- const inner = result === null || result === void 0 || result === false ? "" : String(result);
418
- return {
419
- $$typeof: ELEMENT_TYPE,
420
- type: Fragment,
421
- props: { children: inner ? [inner] : [] }
422
- };
423
- }
424
- return result;
425
- } finally {
426
- setCurrentComponentInstance(prev);
427
- }
428
- } finally {
429
- popSSRStrictPurityGuard();
430
- }
431
- }
432
- function disposeSSRTemporaryOwners(ctx) {
433
- const cleanupFns = ctx.ssrCleanupFns;
434
- ctx.ssrCleanupFns = [];
435
- const cleanupErrors = [];
436
- for (let index = cleanupFns.length - 1; index >= 0; index -= 1) try {
437
- cleanupFns[index]();
438
- } catch (error) {
439
- cleanupErrors.push(error);
440
- }
441
- if (cleanupErrors.length === 1) throw cleanupErrors[0];
442
- if (cleanupErrors.length > 1) throw new AggregateError(cleanupErrors, "SSR temporary owner cleanup failed");
443
- }
444
- function wrapWithDefaultPortal(out) {
445
- if (isPromiseLike(out)) throwSSRDataMissing();
446
- const portalVNode = {
447
- $$typeof: ELEMENT_TYPE,
448
- type: DefaultPortal,
449
- props: {},
450
- key: "__default_portal"
451
- };
452
- if (out == null) return {
453
- $$typeof: ELEMENT_TYPE,
454
- type: Fragment,
455
- props: { children: [portalVNode] }
456
- };
457
- return {
458
- $$typeof: ELEMENT_TYPE,
459
- type: Fragment,
460
- props: { children: [out, portalVNode] }
461
- };
462
- }
463
- function renderSyncComponentRoot(component, props, ctx) {
464
- const wrapped = (p, c) => wrapWithDefaultPortal(component(p ?? {}, c));
465
- return executeComponentSync(wrapped, props || {}, ctx);
466
- }
467
- function getRenderableChildren(node) {
468
- if (Array.isArray(node.children)) return node.children;
469
- if (Array.isArray(node.props?.children)) return node.props.children;
470
- if (node.props?.children !== void 0 && node.props.children !== null && node.props.children !== false) return [node.props.children];
471
- }
472
- function flushPendingText(state) {
473
- if (state.pendingText.length === 0) return true;
474
- if (!state.current || state.current.nodeType !== Node.TEXT_NODE) return false;
475
- if (state.current.textContent !== state.pendingText) return false;
476
- state.current = state.current.nextSibling;
477
- state.pendingText = "";
478
- return true;
479
- }
480
- function verifyRenderedAttrs(element, props) {
481
- const matchedAttrs = /* @__PURE__ */ new Set();
482
- let dangerousHtml;
483
- if (!props || typeof props !== "object") return {
484
- matched: element.attributes.length === 0,
485
- dangerousHtml
486
- };
487
- const propsObj = props;
488
- for (const key in propsObj) {
489
- const value = propsObj[key];
490
- if (key === "children" || key === "key" || key === "ref" || key === "dangerouslySetInnerHTML") {
491
- if (key === "dangerouslySetInnerHTML" && value && typeof value === "object" && "__html" in value) dangerousHtml = String(value.__html);
492
- continue;
493
- }
494
- if (isSSRAttrEventHandler(key) || key.charCodeAt(0) === 95) continue;
495
- const attrName = key === "class" ? "class" : getPublicAttributeName(key);
496
- if (attrName === "style") {
497
- const css = typeof value === "string" ? value : styleObjToCss(value);
498
- if (!css) continue;
499
- if (element.getAttribute("style") !== css) return { matched: false };
500
- matchedAttrs.add("style");
501
- continue;
502
- }
503
- if (value === true) {
504
- if (!element.hasAttribute(attrName)) return { matched: false };
505
- matchedAttrs.add(attrName);
506
- continue;
507
- }
508
- if (value === false || value === null || value === void 0) continue;
509
- const stringValue = String(value);
510
- if (element.getAttribute(attrName) !== stringValue) return { matched: false };
511
- matchedAttrs.add(attrName);
512
- }
513
- if (element.attributes.length !== matchedAttrs.size) return { matched: false };
514
- return {
515
- matched: true,
516
- dangerousHtml
517
- };
518
- }
519
- function verifyExpectedNode(node, state, ctx) {
520
- if (node === null || node === void 0 || node === false) return true;
521
- if (typeof node === "string" || typeof node === "number") {
522
- state.pendingText += String(node);
523
- return true;
524
- }
525
- if (Array.isArray(node)) return verifyExpectedChildren(node, state, ctx);
526
- if (!node || typeof node !== "object" || !("type" in node)) return true;
527
- const vnode = node;
528
- const { type, props } = vnode;
529
- if (typeof type === "function") return verifyRenderableNode(inheritRenderableKey(vnode, executeComponentSync(type, props, ctx)), state, ctx);
530
- if (typeof type === "symbol") {
531
- if (type === __CONTROL_BOUNDARY__) {
532
- const children = evaluateControlBoundaryChildren(vnode);
533
- if (!children || children.length === 0) return true;
534
- for (let index = 0; index < children.length; index += 1) if (!verifyExpectedNode(children[index], state, ctx)) return false;
535
- return true;
536
- }
537
- if (type === __ERROR_BOUNDARY__) {
538
- const boundaryState = getErrorBoundaryState(vnode);
539
- const fallback = props?.fallback;
540
- const reset = () => {
541
- const stateRef = vnode.__instance?.errorBoundaryState;
542
- if (stateRef) {
543
- stateRef.error = null;
544
- stateRef.notified = false;
545
- }
546
- };
547
- const snapshot = {
548
- current: state.current,
549
- pendingText: state.pendingText
550
- };
551
- if (boundaryState?.error != null) return verifyRenderableNode(resolveErrorBoundaryFallbackNode(fallback, boundaryState.error, reset), state, ctx);
552
- try {
553
- if (verifyExpectedChildren(normalizeRenderableChildren(props?.children), state, ctx)) return true;
554
- } catch (error) {
555
- if (boundaryState) {
556
- boundaryState.error = error;
557
- boundaryState.notified = true;
558
- }
559
- }
560
- state.current = snapshot.current;
561
- state.pendingText = snapshot.pendingText;
562
- return verifyRenderableNode(resolveErrorBoundaryFallbackNode(fallback, boundaryState?.error ?? /* @__PURE__ */ new Error("ErrorBoundary render failed"), reset), state, ctx);
563
- }
564
- if (type !== Fragment) throw new Error(`verifyHydrationSyncForUrl: unsupported VNode symbol type: ${String(type)}`);
565
- const children = getRenderableChildren(vnode);
566
- if (!children || children.length === 0) return true;
567
- for (let index = 0; index < children.length; index += 1) if (!verifyExpectedNode(children[index], state, ctx)) return false;
568
- return true;
569
- }
570
- if (!flushPendingText(state)) return false;
571
- if (!state.current || state.current.nodeType !== Node.ELEMENT_NODE) return false;
572
- const actualElement = state.current;
573
- if (actualElement.tagName.toLowerCase() !== String(type).toLowerCase()) return false;
574
- const attrMatch = verifyRenderedAttrs(actualElement, props);
575
- if (!attrMatch.matched) return false;
576
- if (VOID_ELEMENTS.has(String(type))) {
577
- if (actualElement.firstChild !== null) return false;
578
- state.current = actualElement.nextSibling;
579
- return true;
580
- }
581
- if (attrMatch.dangerousHtml !== void 0) {
582
- if (actualElement.innerHTML !== attrMatch.dangerousHtml) return false;
583
- state.current = actualElement.nextSibling;
584
- return true;
585
- }
586
- const childState = {
587
- current: actualElement.firstChild,
588
- pendingText: ""
589
- };
590
- const children = getRenderableChildren(vnode);
591
- if (children && children.length > 0) {
592
- for (let index = 0; index < children.length; index += 1) if (!verifyExpectedNode(children[index], childState, ctx)) return false;
593
- }
594
- if (!flushPendingText(childState) || childState.current !== null) return false;
595
- state.current = actualElement.nextSibling;
596
- return true;
597
- }
598
- function verifyExpectedChildren(children, state, ctx) {
599
- if (!children || children.length === 0) return true;
600
- for (let index = 0; index < children.length; index += 1) if (!verifyExpectedNode(children[index], state, ctx)) return false;
601
- return true;
602
- }
603
- function verifyRenderableNode(value, state, ctx) {
604
- return Array.isArray(value) ? verifyExpectedChildren(normalizeRenderableChildren(value), state, ctx) : verifyExpectedNode(value, state, ctx);
605
- }
606
- /**
607
- * Single synchronous SSR entrypoint: render a component to an HTML string.
608
- * This is strictly synchronous and deterministic. Optionally provide a seed
609
- * for deterministic randomness via `options.seed`.
610
- */
611
- function renderToStringSync(component, props, options) {
612
- const ctx = createRenderContext(options?.seed ?? 12345, { data: options?.data });
613
- return withRenderContext(ctx, () => {
614
- startRenderPhase(options?.data ?? null);
615
- try {
616
- const node = renderSyncComponentRoot(component, props || {}, ctx);
617
- if (!node) throw new Error("renderToStringSync: wrapped component returned empty");
618
- const sink = new StringSink();
619
- renderNodeSyncToSink(node, sink, ctx);
620
- sink.write(serializeHydrationRenderData(options?.data));
621
- sink.end();
622
- return sink.toString();
623
- } finally {
624
- try {
625
- stopRenderPhase();
626
- } finally {
627
- disposeSSRTemporaryOwners(ctx);
628
- }
629
- }
630
- });
631
- }
632
- async function resolveRequest(opts) {
633
- const { url, manifest, routes, auth, signal } = opts;
634
- if (manifest) return await resolveRouteRequest(url, {
635
- manifest,
636
- mode: "ssr",
637
- auth,
638
- signal
639
- });
640
- if (!routes) throw new Error("resolveRequest requires a route manifest or route table.");
641
- const resolved = resolveRouteFromRoutes(new URL(url, "http://localhost").pathname, routes);
642
- if (!resolved) return null;
643
- return {
644
- kind: "render",
645
- handler: resolved.handler,
646
- params: resolved.params
647
- };
648
- }
649
- function resolveSSRRouteRender(opts) {
650
- const { url, routes, seed = 12345, data, document } = opts;
651
- const routeTable = routes.map((route) => ({ ...route }));
652
- const requestUrl = new URL(url, "http://localhost");
653
- const matched = _resolveRouteMatchFromRoutes(requestUrl.pathname, routeTable);
654
- if (!matched) throw new Error(`SSR: no route found for url: ${url}`);
655
- const ctx = createRenderContext(seed, {
656
- url,
657
- data,
658
- params: matched.params,
659
- routes: routeTable
660
- });
661
- return {
662
- url,
663
- requestUrl,
664
- route: matched.route,
665
- params: matched.params,
666
- seed,
667
- data,
668
- ctx,
669
- document
670
- };
671
- }
672
- function buildDocumentRenderArgs(resolved, appHtml) {
673
- return {
674
- appHtml,
675
- context: {
676
- mode: "ssr",
677
- url: resolved.url,
678
- pathname: resolved.requestUrl.pathname,
679
- search: resolved.requestUrl.search,
680
- hash: resolved.requestUrl.hash,
681
- params: resolved.params,
682
- data: resolved.data,
683
- seed: resolved.seed,
684
- route: {
685
- path: resolved.route.path,
686
- namespace: resolved.route.namespace
687
- }
688
- }
689
- };
690
- }
691
- function renderResolvedRouteAppToSink(resolved, sink) {
692
- const { ctx, data, route, params } = resolved;
693
- withRenderContext(ctx, () => {
694
- startRenderPhase(data || null);
695
- try {
696
- renderRenderableSyncToSink(executeComponentSync(route.handler, params, ctx), sink, ctx);
697
- sink.write(serializeHydrationRenderData(data));
698
- } finally {
699
- try {
700
- stopRenderPhase();
701
- } finally {
702
- disposeSSRTemporaryOwners(ctx);
703
- }
704
- }
705
- });
706
- }
707
- function renderToString(arg) {
708
- if (typeof arg === "function") return renderToStringSync(arg);
709
- const opts = arg;
710
- const sink = new StringSink();
711
- renderToSinkInternal({
712
- ...opts,
713
- sink
714
- });
715
- sink.end();
716
- return sink.toString();
717
- }
718
- function renderToStream(opts) {
719
- const sink = new StreamSink(opts.onChunk, opts.onComplete);
720
- renderToSinkInternal({
721
- ...opts,
722
- sink
723
- });
724
- sink.end();
725
- }
726
- function renderToSinkInternal(opts) {
727
- const { sink, ...renderOptions } = opts;
728
- const resolved = resolveSSRRouteRender(renderOptions);
729
- if (!resolved.document) {
730
- renderResolvedRouteAppToSink(resolved, sink);
731
- return;
732
- }
733
- const appSink = new StringSink();
734
- renderResolvedRouteAppToSink(resolved, appSink);
735
- appSink.end();
736
- sink.write(renderDocument(resolved.document, buildDocumentRenderArgs(resolved, appSink.toString()), "renderToString()/renderToStream()"));
737
- }
738
- //#endregion
5
+ import { renderToStream, renderToString } from "./index-internal.js";
739
6
  export { SSRDataMissingError, renderResolvedToStringSync, renderToStream, renderToString, renderToStringSync, resolveRequest };
740
-
741
- //# sourceMappingURL=index.js.map