@ecopages/core 0.2.0-alpha.2 → 0.2.0-alpha.21

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 (391) hide show
  1. package/CHANGELOG.md +26 -64
  2. package/README.md +212 -14
  3. package/package.json +116 -66
  4. package/src/adapters/README.md +39 -0
  5. package/src/adapters/abstract/application-adapter.d.ts +28 -2
  6. package/src/adapters/abstract/application-adapter.js +14 -2
  7. package/src/adapters/abstract/router-adapter.d.ts +1 -1
  8. package/src/adapters/abstract/server-adapter.d.ts +2 -2
  9. package/src/adapters/bun/client-bridge.d.ts +1 -1
  10. package/src/adapters/bun/create-app.d.ts +4 -12
  11. package/src/adapters/bun/create-app.js +4 -5
  12. package/src/adapters/bun/hmr-manager.d.ts +80 -21
  13. package/src/adapters/bun/hmr-manager.js +168 -62
  14. package/src/adapters/bun/index.d.ts +2 -3
  15. package/src/adapters/bun/index.js +3 -3
  16. package/src/adapters/bun/server-adapter.d.ts +5 -5
  17. package/src/adapters/bun/server-adapter.js +40 -34
  18. package/src/adapters/bun/server-lifecycle.d.ts +28 -17
  19. package/src/adapters/bun/server-lifecycle.js +34 -62
  20. package/src/{create-app.d.ts → adapters/create-app.d.ts} +9 -6
  21. package/src/{create-app.js → adapters/create-app.js} +4 -4
  22. package/src/adapters/index.d.ts +2 -6
  23. package/src/adapters/index.js +2 -8
  24. package/src/adapters/node/create-app.d.ts +6 -9
  25. package/src/adapters/node/create-app.js +12 -6
  26. package/src/adapters/node/node-client-bridge.d.ts +1 -1
  27. package/src/adapters/node/node-hmr-manager.d.ts +89 -18
  28. package/src/adapters/node/node-hmr-manager.js +185 -95
  29. package/src/adapters/node/server-adapter.d.ts +6 -35
  30. package/src/adapters/node/server-adapter.js +44 -105
  31. package/src/adapters/node/static-content-server.d.ts +37 -1
  32. package/src/adapters/node/static-content-server.js +29 -1
  33. package/src/adapters/shared/application-adapter.d.ts +1 -1
  34. package/src/{define-api-handler.d.ts → adapters/shared/define-api-handler.d.ts} +1 -1
  35. package/src/adapters/shared/explicit-static-route-matcher.d.ts +2 -2
  36. package/src/adapters/shared/explicit-static-route-matcher.js +4 -1
  37. package/src/adapters/shared/file-route-middleware-pipeline.d.ts +1 -1
  38. package/src/adapters/shared/file-route-middleware-pipeline.js +1 -0
  39. package/src/adapters/shared/fs-server-response-factory.d.ts +2 -2
  40. package/src/adapters/shared/fs-server-response-factory.js +1 -1
  41. package/src/adapters/shared/fs-server-response-matcher.d.ts +8 -12
  42. package/src/adapters/shared/fs-server-response-matcher.js +10 -18
  43. package/src/adapters/shared/hmr-entrypoint-registrar.d.ts +55 -0
  44. package/src/adapters/shared/hmr-entrypoint-registrar.js +87 -0
  45. package/src/adapters/shared/hmr-html-response.d.ts +22 -0
  46. package/src/adapters/shared/hmr-html-response.js +32 -0
  47. package/src/adapters/shared/render-context.d.ts +2 -1
  48. package/src/adapters/shared/render-context.js +6 -3
  49. package/src/adapters/shared/runtime-bootstrap.d.ts +38 -0
  50. package/src/adapters/shared/runtime-bootstrap.js +43 -0
  51. package/src/adapters/shared/server-adapter.d.ts +13 -3
  52. package/src/adapters/shared/server-adapter.js +42 -5
  53. package/src/adapters/shared/server-route-handler.d.ts +4 -4
  54. package/src/adapters/shared/server-route-handler.js +6 -15
  55. package/src/adapters/shared/server-static-builder.d.ts +38 -6
  56. package/src/adapters/shared/server-static-builder.js +64 -10
  57. package/src/build/README.md +107 -0
  58. package/src/build/build-adapter.d.ts +168 -3
  59. package/src/build/build-adapter.js +604 -16
  60. package/src/build/build-manifest.d.ts +27 -0
  61. package/src/build/build-manifest.js +30 -0
  62. package/src/build/dev-build-coordinator.d.ts +72 -0
  63. package/src/build/dev-build-coordinator.js +154 -0
  64. package/src/build/esbuild-build-adapter.d.ts +15 -6
  65. package/src/build/esbuild-build-adapter.js +189 -74
  66. package/src/build/runtime-build-executor.d.ts +14 -0
  67. package/src/build/runtime-build-executor.js +22 -0
  68. package/src/build/runtime-specifier-alias-plugin.d.ts +15 -0
  69. package/src/build/runtime-specifier-alias-plugin.js +35 -0
  70. package/src/build/runtime-specifier-aliases.d.ts +5 -0
  71. package/src/build/runtime-specifier-aliases.js +95 -0
  72. package/src/config/README.md +36 -0
  73. package/src/config/config-builder.d.ts +52 -27
  74. package/src/config/config-builder.js +260 -49
  75. package/src/{constants.d.ts → config/constants.d.ts} +13 -0
  76. package/src/{constants.js → config/constants.js} +4 -0
  77. package/src/declarations.d.ts +19 -14
  78. package/src/dev/sc-server.d.ts +1 -1
  79. package/src/dev/sc-server.js +1 -1
  80. package/src/eco/README.md +70 -16
  81. package/src/eco/eco.browser.d.ts +2 -0
  82. package/src/eco/eco.browser.js +83 -0
  83. package/src/eco/eco.js +32 -57
  84. package/src/eco/eco.types.d.ts +12 -4
  85. package/src/eco/eco.utils.d.ts +1 -40
  86. package/src/eco/eco.utils.js +5 -35
  87. package/src/eco/global-injector-map.d.ts +1 -1
  88. package/src/eco/lazy-injector-map.d.ts +1 -1
  89. package/src/hmr/README.md +26 -0
  90. package/src/hmr/client/hmr-runtime.d.ts +1 -6
  91. package/src/hmr/client/hmr-runtime.js +30 -7
  92. package/src/hmr/hmr-strategy.d.ts +16 -13
  93. package/src/hmr/hmr-strategy.js +22 -7
  94. package/src/hmr/hmr.postcss.test.e2e.d.ts +1 -0
  95. package/src/hmr/hmr.postcss.test.e2e.js +31 -0
  96. package/src/hmr/hmr.test.e2e.js +26 -33
  97. package/src/hmr/strategies/default-hmr-strategy.d.ts +2 -2
  98. package/src/hmr/strategies/default-hmr-strategy.js +1 -1
  99. package/src/hmr/strategies/js-hmr-strategy.d.ts +46 -43
  100. package/src/hmr/strategies/js-hmr-strategy.js +72 -73
  101. package/src/index.browser.d.ts +2 -2
  102. package/src/index.browser.js +1 -1
  103. package/src/index.d.ts +4 -3
  104. package/src/index.js +16 -5
  105. package/src/integrations/ghtml/ghtml-renderer.d.ts +7 -2
  106. package/src/integrations/ghtml/ghtml-renderer.js +33 -30
  107. package/src/integrations/ghtml/ghtml.constants.d.ts +1 -0
  108. package/src/integrations/ghtml/ghtml.constants.js +4 -0
  109. package/src/integrations/ghtml/ghtml.plugin.d.ts +2 -6
  110. package/src/integrations/ghtml/ghtml.plugin.js +3 -4
  111. package/src/plugins/README.md +35 -0
  112. package/src/plugins/alias-resolver-plugin.js +17 -3
  113. package/src/plugins/eco-component-meta-plugin.d.ts +14 -1
  114. package/src/plugins/eco-component-meta-plugin.js +27 -21
  115. package/src/plugins/foreign-jsx-override-plugin.d.ts +31 -0
  116. package/src/plugins/foreign-jsx-override-plugin.js +35 -0
  117. package/src/plugins/integration-plugin.d.ts +145 -28
  118. package/src/plugins/integration-plugin.js +109 -13
  119. package/src/plugins/processor.d.ts +15 -2
  120. package/src/plugins/processor.js +16 -2
  121. package/src/plugins/runtime-capability.d.ts +9 -0
  122. package/src/plugins/source-transform.d.ts +46 -0
  123. package/src/plugins/source-transform.js +71 -0
  124. package/src/route-renderer/GRAPH.md +64 -98
  125. package/src/route-renderer/README.md +67 -46
  126. package/src/route-renderer/orchestration/boundary-planning.service.d.ts +25 -0
  127. package/src/route-renderer/orchestration/boundary-planning.service.js +97 -0
  128. package/src/route-renderer/orchestration/component-render-context.d.ts +83 -0
  129. package/src/route-renderer/orchestration/component-render-context.js +147 -0
  130. package/src/route-renderer/orchestration/integration-renderer.d.ts +554 -0
  131. package/src/route-renderer/orchestration/integration-renderer.js +957 -0
  132. package/src/route-renderer/orchestration/queued-boundary-runtime.service.d.ts +89 -0
  133. package/src/route-renderer/orchestration/queued-boundary-runtime.service.js +155 -0
  134. package/src/route-renderer/orchestration/render-execution.service.d.ts +43 -0
  135. package/src/route-renderer/orchestration/render-execution.service.js +106 -0
  136. package/src/{eco/eco.utils.ts → route-renderer/orchestration/render-output.utils.d.ts} +10 -53
  137. package/src/route-renderer/orchestration/render-output.utils.js +65 -0
  138. package/src/route-renderer/{render-preparation.service.d.ts → orchestration/render-preparation.service.d.ts} +18 -10
  139. package/src/route-renderer/{render-preparation.service.js → orchestration/render-preparation.service.js} +115 -17
  140. package/src/route-renderer/orchestration/route-shell-composer.service.d.ts +50 -0
  141. package/src/route-renderer/orchestration/route-shell-composer.service.js +81 -0
  142. package/src/route-renderer/orchestration/template-serialization.d.ts +38 -0
  143. package/src/route-renderer/orchestration/template-serialization.js +45 -0
  144. package/src/route-renderer/{dependency-resolver.d.ts → page-loading/dependency-resolver.d.ts} +15 -4
  145. package/src/route-renderer/{dependency-resolver.js → page-loading/dependency-resolver.js} +28 -12
  146. package/src/route-renderer/page-loading/page-module-loader.d.ts +90 -0
  147. package/src/route-renderer/{page-module-loader.js → page-loading/page-module-loader.js} +39 -14
  148. package/src/route-renderer/route-renderer.d.ts +45 -4
  149. package/src/route-renderer/route-renderer.js +38 -3
  150. package/src/router/README.md +97 -0
  151. package/src/router/client/link-intent.d.ts +53 -0
  152. package/src/router/client/link-intent.js +34 -0
  153. package/src/router/client/link-intent.test.browser.d.ts +1 -0
  154. package/src/router/client/link-intent.test.browser.js +43 -0
  155. package/src/router/client/navigation-coordinator.d.ts +149 -0
  156. package/src/router/client/navigation-coordinator.js +215 -0
  157. package/src/router/{fs-router-scanner.d.ts → server/fs-router-scanner.d.ts} +3 -3
  158. package/src/router/{fs-router-scanner.js → server/fs-router-scanner.js} +14 -8
  159. package/src/router/{fs-router.d.ts → server/fs-router.d.ts} +1 -1
  160. package/src/router/{fs-router.js → server/fs-router.js} +1 -1
  161. package/src/services/README.md +29 -0
  162. package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +120 -0
  163. package/src/services/{asset-processing-service → assets/asset-processing-service}/asset-processing.service.js +91 -10
  164. package/src/services/{asset-processing-service → assets/asset-processing-service}/asset.factory.d.ts +1 -1
  165. package/src/services/{asset-processing-service → assets/asset-processing-service}/asset.factory.js +2 -2
  166. package/src/services/{asset-processing-service → assets/asset-processing-service}/assets.types.d.ts +2 -1
  167. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +55 -0
  168. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +48 -0
  169. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +20 -0
  170. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +41 -0
  171. package/src/services/assets/asset-processing-service/index.d.ts +5 -0
  172. package/src/services/assets/asset-processing-service/index.js +5 -0
  173. package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.interface.d.ts +2 -2
  174. package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.registry.d.ts +2 -2
  175. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-processor.d.ts +1 -1
  176. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-processor.js +9 -4
  177. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-script-processor.d.ts +5 -4
  178. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/base/base-script-processor.js +15 -23
  179. package/src/services/assets/asset-processing-service/processors/index.d.ts +5 -0
  180. package/src/services/assets/asset-processing-service/processors/index.js +5 -0
  181. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/content-script.processor.d.ts +2 -2
  182. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/content-script.processor.js +1 -1
  183. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/file-script.processor.d.ts +4 -3
  184. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/file-script.processor.js +16 -4
  185. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/node-module-script.processor.d.ts +3 -3
  186. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/script/node-module-script.processor.js +6 -5
  187. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/content-stylesheet.processor.d.ts +2 -2
  188. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/content-stylesheet.processor.js +1 -1
  189. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/file-stylesheet.processor.d.ts +2 -2
  190. package/src/services/{asset-processing-service → assets/asset-processing-service}/processors/stylesheet/file-stylesheet.processor.js +5 -2
  191. package/src/services/assets/browser-bundle.service.d.ts +32 -0
  192. package/src/services/assets/browser-bundle.service.js +33 -0
  193. package/src/services/{page-request-cache-coordinator.service.d.ts → cache/page-request-cache-coordinator.service.d.ts} +2 -2
  194. package/src/services/{page-request-cache-coordinator.service.js → cache/page-request-cache-coordinator.service.js} +3 -1
  195. package/src/services/html/html-rewriter-provider.service.d.ts +37 -0
  196. package/src/services/html/html-rewriter-provider.service.js +68 -0
  197. package/src/services/html/html-transformer.service.d.ts +77 -0
  198. package/src/services/html/html-transformer.service.js +215 -0
  199. package/src/services/invalidation/development-invalidation.service.d.ts +74 -0
  200. package/src/services/invalidation/development-invalidation.service.js +190 -0
  201. package/src/services/module-loading/app-module-loader.service.d.ts +28 -0
  202. package/src/services/module-loading/app-module-loader.service.js +35 -0
  203. package/src/services/module-loading/app-server-module-transpiler.service.d.ts +24 -0
  204. package/src/services/module-loading/app-server-module-transpiler.service.js +109 -0
  205. package/src/services/module-loading/host-module-loader-registry.d.ts +4 -0
  206. package/src/services/module-loading/host-module-loader-registry.js +15 -0
  207. package/src/services/module-loading/module-loading-types.d.ts +2 -0
  208. package/src/services/module-loading/node-bootstrap-plugin.d.ts +42 -0
  209. package/src/services/module-loading/node-bootstrap-plugin.js +204 -0
  210. package/src/services/module-loading/page-module-import.service.d.ts +76 -0
  211. package/src/services/module-loading/page-module-import.service.js +173 -0
  212. package/src/services/module-loading/server-module-transpiler.service.d.ts +72 -0
  213. package/src/services/module-loading/server-module-transpiler.service.js +64 -0
  214. package/src/services/runtime-state/dev-graph.service.d.ts +118 -0
  215. package/src/services/runtime-state/dev-graph.service.js +162 -0
  216. package/src/services/runtime-state/entrypoint-dependency-graph.service.d.ts +41 -0
  217. package/src/services/runtime-state/entrypoint-dependency-graph.service.js +85 -0
  218. package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +69 -0
  219. package/src/services/runtime-state/runtime-specifier-registry.service.js +37 -0
  220. package/src/services/runtime-state/server-invalidation-state.service.d.ts +26 -0
  221. package/src/services/runtime-state/server-invalidation-state.service.js +35 -0
  222. package/src/services/{schema-validation-service.d.ts → validation/schema-validation-service.d.ts} +1 -1
  223. package/src/static-site-generator/README.md +26 -0
  224. package/src/static-site-generator/static-site-generator.d.ts +50 -3
  225. package/src/static-site-generator/static-site-generator.js +71 -5
  226. package/src/{internal-types.d.ts → types/internal-types.d.ts} +53 -22
  227. package/src/types/internal-types.js +0 -0
  228. package/src/{public-types.d.ts → types/public-types.d.ts} +146 -21
  229. package/src/types/public-types.js +0 -0
  230. package/src/utils/html-escaping.d.ts +7 -0
  231. package/src/utils/html-escaping.js +6 -0
  232. package/src/utils/locals-utils.d.ts +1 -1
  233. package/src/utils/parse-cli-args.d.ts +4 -1
  234. package/src/utils/parse-cli-args.js +16 -1
  235. package/src/utils/resolve-work-dir.d.ts +11 -0
  236. package/src/utils/resolve-work-dir.js +31 -0
  237. package/src/watchers/project-watcher.d.ts +40 -24
  238. package/src/watchers/project-watcher.js +129 -92
  239. package/src/watchers/project-watcher.test-helpers.d.ts +2 -2
  240. package/src/watchers/project-watcher.test-helpers.js +1 -0
  241. package/src/adapters/abstract/application-adapter.ts +0 -337
  242. package/src/adapters/abstract/router-adapter.ts +0 -30
  243. package/src/adapters/abstract/server-adapter.ts +0 -79
  244. package/src/adapters/bun/client-bridge.ts +0 -62
  245. package/src/adapters/bun/create-app.ts +0 -189
  246. package/src/adapters/bun/define-api-handler.d.ts +0 -61
  247. package/src/adapters/bun/define-api-handler.ts +0 -114
  248. package/src/adapters/bun/hmr-manager.ts +0 -281
  249. package/src/adapters/bun/index.ts +0 -3
  250. package/src/adapters/bun/server-adapter.ts +0 -492
  251. package/src/adapters/bun/server-lifecycle.ts +0 -154
  252. package/src/adapters/index.ts +0 -6
  253. package/src/adapters/node/create-app.ts +0 -179
  254. package/src/adapters/node/index.d.ts +0 -4
  255. package/src/adapters/node/index.js +0 -8
  256. package/src/adapters/node/index.ts +0 -9
  257. package/src/adapters/node/node-client-bridge.ts +0 -79
  258. package/src/adapters/node/node-hmr-manager.ts +0 -271
  259. package/src/adapters/node/server-adapter.ts +0 -561
  260. package/src/adapters/node/static-content-server.ts +0 -203
  261. package/src/adapters/shared/api-response.ts +0 -104
  262. package/src/adapters/shared/application-adapter.ts +0 -199
  263. package/src/adapters/shared/explicit-static-route-matcher.ts +0 -134
  264. package/src/adapters/shared/file-route-middleware-pipeline.ts +0 -123
  265. package/src/adapters/shared/fs-server-response-factory.ts +0 -118
  266. package/src/adapters/shared/fs-server-response-matcher.ts +0 -198
  267. package/src/adapters/shared/render-context.ts +0 -105
  268. package/src/adapters/shared/server-adapter.ts +0 -442
  269. package/src/adapters/shared/server-route-handler.ts +0 -166
  270. package/src/adapters/shared/server-static-builder.ts +0 -82
  271. package/src/build/build-adapter.ts +0 -132
  272. package/src/build/build-types.ts +0 -83
  273. package/src/build/esbuild-build-adapter.ts +0 -510
  274. package/src/config/config-builder.ts +0 -474
  275. package/src/constants.ts +0 -39
  276. package/src/create-app.ts +0 -87
  277. package/src/define-api-handler.js +0 -15
  278. package/src/define-api-handler.ts +0 -66
  279. package/src/dev/sc-server.ts +0 -143
  280. package/src/eco/component-render-context.d.ts +0 -105
  281. package/src/eco/component-render-context.js +0 -77
  282. package/src/eco/component-render-context.ts +0 -202
  283. package/src/eco/eco.ts +0 -221
  284. package/src/eco/eco.types.ts +0 -202
  285. package/src/eco/global-injector-map.ts +0 -112
  286. package/src/eco/lazy-injector-map.ts +0 -120
  287. package/src/eco/module-dependencies.ts +0 -75
  288. package/src/errors/http-error.ts +0 -72
  289. package/src/errors/index.ts +0 -2
  290. package/src/errors/locals-access-error.ts +0 -7
  291. package/src/global/app-logger.ts +0 -4
  292. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-have-HMR-script-injected-in-page-1.png +0 -0
  293. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-load-fixture-app-page-1.png +0 -0
  294. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-WebSocket-Connection-should-connect-to-correct-HMR-endpoint-1.png +0 -0
  295. package/src/hmr/client/hmr-runtime.ts +0 -121
  296. package/src/hmr/hmr-strategy.ts +0 -172
  297. package/src/hmr/hmr.test.e2e.ts +0 -75
  298. package/src/hmr/strategies/default-hmr-strategy.ts +0 -60
  299. package/src/hmr/strategies/js-hmr-strategy.ts +0 -308
  300. package/src/index.browser.ts +0 -3
  301. package/src/index.ts +0 -5
  302. package/src/integrations/ghtml/ghtml-renderer.ts +0 -93
  303. package/src/integrations/ghtml/ghtml.plugin.ts +0 -32
  304. package/src/internal-types.ts +0 -212
  305. package/src/plugins/alias-resolver-plugin.ts +0 -45
  306. package/src/plugins/eco-component-meta-plugin.ts +0 -474
  307. package/src/plugins/integration-plugin.ts +0 -184
  308. package/src/plugins/processor.ts +0 -220
  309. package/src/public-types.ts +0 -1255
  310. package/src/route-renderer/component-graph-executor.d.ts +0 -32
  311. package/src/route-renderer/component-graph-executor.js +0 -31
  312. package/src/route-renderer/component-graph-executor.ts +0 -84
  313. package/src/route-renderer/component-graph.d.ts +0 -42
  314. package/src/route-renderer/component-graph.js +0 -72
  315. package/src/route-renderer/component-graph.ts +0 -159
  316. package/src/route-renderer/component-marker.d.ts +0 -52
  317. package/src/route-renderer/component-marker.js +0 -46
  318. package/src/route-renderer/component-marker.ts +0 -117
  319. package/src/route-renderer/dependency-resolver.ts +0 -596
  320. package/src/route-renderer/html-post-processing.service.d.ts +0 -40
  321. package/src/route-renderer/html-post-processing.service.js +0 -86
  322. package/src/route-renderer/html-post-processing.service.ts +0 -103
  323. package/src/route-renderer/integration-renderer.d.ts +0 -339
  324. package/src/route-renderer/integration-renderer.js +0 -526
  325. package/src/route-renderer/integration-renderer.ts +0 -696
  326. package/src/route-renderer/marker-graph-resolver.d.ts +0 -76
  327. package/src/route-renderer/marker-graph-resolver.js +0 -93
  328. package/src/route-renderer/marker-graph-resolver.ts +0 -153
  329. package/src/route-renderer/page-module-loader.d.ts +0 -61
  330. package/src/route-renderer/page-module-loader.ts +0 -153
  331. package/src/route-renderer/render-execution.service.d.ts +0 -69
  332. package/src/route-renderer/render-execution.service.js +0 -91
  333. package/src/route-renderer/render-execution.service.ts +0 -158
  334. package/src/route-renderer/render-preparation.service.ts +0 -358
  335. package/src/route-renderer/route-renderer.ts +0 -80
  336. package/src/router/fs-router-scanner.ts +0 -217
  337. package/src/router/fs-router.ts +0 -122
  338. package/src/services/asset-processing-service/asset-processing.service.d.ts +0 -41
  339. package/src/services/asset-processing-service/asset-processing.service.ts +0 -306
  340. package/src/services/asset-processing-service/asset.factory.ts +0 -105
  341. package/src/services/asset-processing-service/assets.types.ts +0 -112
  342. package/src/services/asset-processing-service/index.d.ts +0 -3
  343. package/src/services/asset-processing-service/index.js +0 -3
  344. package/src/services/asset-processing-service/index.ts +0 -3
  345. package/src/services/asset-processing-service/processor.interface.ts +0 -27
  346. package/src/services/asset-processing-service/processor.registry.ts +0 -18
  347. package/src/services/asset-processing-service/processors/base/base-processor.ts +0 -76
  348. package/src/services/asset-processing-service/processors/base/base-script-processor.ts +0 -105
  349. package/src/services/asset-processing-service/processors/index.d.ts +0 -5
  350. package/src/services/asset-processing-service/processors/index.js +0 -5
  351. package/src/services/asset-processing-service/processors/index.ts +0 -5
  352. package/src/services/asset-processing-service/processors/script/content-script.processor.ts +0 -66
  353. package/src/services/asset-processing-service/processors/script/file-script.processor.ts +0 -88
  354. package/src/services/asset-processing-service/processors/script/node-module-script.processor.ts +0 -84
  355. package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts +0 -27
  356. package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.ts +0 -77
  357. package/src/services/cache/cache.types.ts +0 -126
  358. package/src/services/cache/index.ts +0 -18
  359. package/src/services/cache/memory-cache-store.ts +0 -130
  360. package/src/services/cache/page-cache-service.ts +0 -202
  361. package/src/services/html-transformer.service.d.ts +0 -50
  362. package/src/services/html-transformer.service.js +0 -163
  363. package/src/services/html-transformer.service.ts +0 -217
  364. package/src/services/page-module-import.service.d.ts +0 -37
  365. package/src/services/page-module-import.service.js +0 -88
  366. package/src/services/page-module-import.service.ts +0 -129
  367. package/src/services/page-request-cache-coordinator.service.ts +0 -128
  368. package/src/services/schema-validation-service.ts +0 -204
  369. package/src/services/validation/standard-schema.types.ts +0 -68
  370. package/src/static-site-generator/static-site-generator.ts +0 -359
  371. package/src/utils/css.d.ts +0 -1
  372. package/src/utils/css.js +0 -7
  373. package/src/utils/css.ts +0 -5
  374. package/src/utils/deep-merge.ts +0 -47
  375. package/src/utils/hash.ts +0 -5
  376. package/src/utils/html.ts +0 -1
  377. package/src/utils/invariant.ts +0 -15
  378. package/src/utils/locals-utils.ts +0 -37
  379. package/src/utils/parse-cli-args.ts +0 -83
  380. package/src/utils/path-utils.module.ts +0 -14
  381. package/src/utils/runtime.ts +0 -44
  382. package/src/utils/server-utils.module.ts +0 -67
  383. package/src/watchers/project-watcher.test-helpers.ts +0 -40
  384. package/src/watchers/project-watcher.ts +0 -306
  385. /package/src/adapters/{bun → shared}/define-api-handler.js +0 -0
  386. /package/src/{internal-types.js → plugins/runtime-capability.js} +0 -0
  387. /package/src/services/{asset-processing-service → assets/asset-processing-service}/assets.types.js +0 -0
  388. /package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.interface.js +0 -0
  389. /package/src/services/{asset-processing-service → assets/asset-processing-service}/processor.registry.js +0 -0
  390. /package/src/{public-types.js → services/module-loading/module-loading-types.js} +0 -0
  391. /package/src/services/{schema-validation-service.js → validation/schema-validation-service.js} +0 -0
@@ -1,22 +1,36 @@
1
- import { invariant } from "../utils/invariant.js";
2
- import { PageModuleImportService } from "../services/page-module-import.service.js";
1
+ import { invariant } from "../../utils/invariant.js";
2
+ import { getAppModuleLoader } from "../../services/module-loading/app-server-module-transpiler.service.js";
3
+ import { resolveInternalExecutionDir } from "../../utils/resolve-work-dir.js";
3
4
  class PageModuleLoaderService {
5
+ appModuleLoader;
6
+ appConfig;
7
+ runtimeOrigin;
8
+ /**
9
+ * Creates the page-module loader for one app/runtime instance.
10
+ *
11
+ * @param appConfig Finalized app config that owns build and invalidation state.
12
+ * @param runtimeOrigin Runtime origin exposed to page data hooks.
13
+ */
4
14
  constructor(appConfig, runtimeOrigin) {
5
15
  this.appConfig = appConfig;
6
16
  this.runtimeOrigin = runtimeOrigin;
7
- this.pageModuleImportService = new PageModuleImportService();
17
+ this.appModuleLoader = getAppModuleLoader(appConfig);
8
18
  }
9
- pageModuleImportService;
10
19
  /**
11
- * Imports a page module from source.
12
- * Uses direct dynamic import in Bun and transpile+import fallback for other runtimes.
20
+ * Imports one page module through the shared server-side module loading path.
21
+ *
22
+ * @remarks
23
+ * The underlying transpiler keeps Bun and Node aligned on one framework-owned
24
+ * loading contract even though the runtime-specific execution transport differs.
13
25
  */
14
- async importPageFile(file) {
26
+ async importPageFile(file, options) {
15
27
  try {
16
- return await this.pageModuleImportService.importModule({
28
+ return await this.appModuleLoader.importModule({
17
29
  filePath: file,
18
30
  rootDir: this.appConfig.rootDir,
19
- outdir: `${this.appConfig.absolutePaths.distDir}/.server-modules`,
31
+ outdir: `${resolveInternalExecutionDir(this.appConfig)}/.server-modules`,
32
+ bypassCache: options?.bypassCache,
33
+ cacheScope: options?.cacheScope,
20
34
  transpileErrorMessage: (details) => `Error transpiling page file: ${details}`,
21
35
  noOutputMessage: (targetFilePath) => `No transpiled output generated for page: ${targetFilePath}`
22
36
  });
@@ -25,8 +39,11 @@ class PageModuleLoaderService {
25
39
  }
26
40
  }
27
41
  /**
28
- * Executes `getStaticProps` with Ecopages runtime context.
29
- * Returns an empty props object when no static props function is defined.
42
+ * Executes the page's static-props hook with Ecopages runtime context.
43
+ *
44
+ * @remarks
45
+ * Pages without a static-props hook still return a normalized empty props
46
+ * object so downstream render preparation does not branch on hook presence.
30
47
  */
31
48
  async getStaticPropsForPage(options) {
32
49
  const { getStaticProps, params } = options;
@@ -42,8 +59,11 @@ class PageModuleLoaderService {
42
59
  };
43
60
  }
44
61
  /**
45
- * Builds final page metadata using app-level defaults as a baseline.
46
- * If `getMetadata` exists, its result overlays defaults so page-level fields take precedence.
62
+ * Builds the final page metadata object for one render request.
63
+ *
64
+ * @remarks
65
+ * App-level default metadata forms the baseline, then page-level metadata is
66
+ * overlaid so route-specific fields win without dropping global defaults.
47
67
  */
48
68
  async getMetadataPropsForPage(options) {
49
69
  const { getMetadata, context } = options;
@@ -79,7 +99,12 @@ class PageModuleLoaderService {
79
99
  };
80
100
  }
81
101
  /**
82
- * Resolves render-time page data in order: static props first, then metadata derived from those props.
102
+ * Resolves the page data needed by the render pipeline.
103
+ *
104
+ * @remarks
105
+ * Static props are resolved first because page metadata may depend on those
106
+ * props. This preserves the same ordering whether data hooks are declared as
107
+ * component statics or module exports.
83
108
  */
84
109
  async resolvePageData(options) {
85
110
  const { props } = await this.getStaticPropsForPage({
@@ -1,26 +1,67 @@
1
- import type { EcoPagesAppConfig } from '../internal-types.js';
1
+ import type { EcoPagesAppConfig } from '../types/internal-types.js';
2
2
  import type { IntegrationPlugin } from '../plugins/integration-plugin.js';
3
- import type { RouteRenderResult, RouteRendererOptions } from '../public-types.js';
4
- import type { IntegrationRenderer } from './integration-renderer.js';
3
+ import type { EcoPageFile, RouteRenderResult, RouteRendererOptions } from '../types/public-types.js';
4
+ import type { IntegrationRenderer, RouteModuleLoadOptions } from './orchestration/integration-renderer.js';
5
+ /**
6
+ * Thin wrapper around one initialized integration renderer.
7
+ *
8
+ * @remarks
9
+ * This type exists so higher-level routing code can ask for a route renderer
10
+ * without depending on the full integration plugin lifecycle. It delegates all
11
+ * real work to the integration-specific renderer selected by the factory.
12
+ */
5
13
  export declare class RouteRenderer {
6
14
  private renderer;
15
+ /**
16
+ * Creates a route renderer bound to one integration renderer instance.
17
+ */
7
18
  constructor(renderer: IntegrationRenderer);
19
+ /**
20
+ * Executes the render pipeline for one matched route.
21
+ */
8
22
  createRoute(options: RouteRendererOptions): Promise<RouteRenderResult>;
23
+ /**
24
+ * Loads the route module through the owning integration renderer.
25
+ */
26
+ loadPageModule(filePath: string, options?: RouteModuleLoadOptions): Promise<EcoPageFile>;
9
27
  }
28
+ /**
29
+ * Selects and caches integration renderers for route files and explicit views.
30
+ *
31
+ * @remarks
32
+ * The factory owns the policy that maps a route file or explicit integration
33
+ * name to one initialized integration renderer. Renderer instances are cached by
34
+ * integration name so repeated requests do not rebuild renderer state.
35
+ */
10
36
  export declare class RouteRendererFactory {
11
37
  private appConfig;
12
38
  runtimeOrigin: string;
39
+ private rendererModules?;
13
40
  private rendererCache;
14
- constructor({ appConfig, runtimeOrigin }: {
41
+ /**
42
+ * Creates the route-renderer factory for one app/runtime instance.
43
+ */
44
+ constructor({ appConfig, rendererModules, runtimeOrigin, }: {
15
45
  appConfig: EcoPagesAppConfig;
46
+ rendererModules?: unknown;
16
47
  runtimeOrigin: string;
17
48
  });
49
+ /**
50
+ * Returns a route renderer for the supplied route file.
51
+ */
18
52
  createRenderer(filePath: string): RouteRenderer;
19
53
  /**
20
54
  * Get an integration renderer by its name.
21
55
  * Used for explicit routing where views specify their integration via __eco.integration.
22
56
  */
23
57
  getRendererByIntegration(integrationName: string): IntegrationRenderer | null;
58
+ /**
59
+ * Resolves the integration plugin that owns a given route file.
60
+ */
24
61
  getIntegrationPlugin(filePath: string): IntegrationPlugin;
62
+ /**
63
+ * Returns the cached renderer engine for the file's owning integration,
64
+ * creating it on first use.
65
+ */
25
66
  private getRouteRendererEngine;
26
67
  }
@@ -2,21 +2,45 @@ import { invariant } from "../utils/invariant.js";
2
2
  import { PathUtils } from "../utils/path-utils.module.js";
3
3
  class RouteRenderer {
4
4
  renderer;
5
+ /**
6
+ * Creates a route renderer bound to one integration renderer instance.
7
+ */
5
8
  constructor(renderer) {
6
9
  this.renderer = renderer;
7
10
  }
11
+ /**
12
+ * Executes the render pipeline for one matched route.
13
+ */
8
14
  async createRoute(options) {
9
15
  return this.renderer.execute(options);
10
16
  }
17
+ /**
18
+ * Loads the route module through the owning integration renderer.
19
+ */
20
+ async loadPageModule(filePath, options) {
21
+ return this.renderer.loadPageModule(filePath, options);
22
+ }
11
23
  }
12
24
  class RouteRendererFactory {
13
25
  appConfig;
14
26
  runtimeOrigin;
27
+ rendererModules;
15
28
  rendererCache = /* @__PURE__ */ new Map();
16
- constructor({ appConfig, runtimeOrigin }) {
29
+ /**
30
+ * Creates the route-renderer factory for one app/runtime instance.
31
+ */
32
+ constructor({
33
+ appConfig,
34
+ rendererModules,
35
+ runtimeOrigin
36
+ }) {
17
37
  this.appConfig = appConfig;
38
+ this.rendererModules = rendererModules;
18
39
  this.runtimeOrigin = runtimeOrigin;
19
40
  }
41
+ /**
42
+ * Returns a route renderer for the supplied route file.
43
+ */
20
44
  createRenderer(filePath) {
21
45
  const integrationRenderer = this.getRouteRendererEngine(filePath);
22
46
  invariant(!!integrationRenderer, `No integration renderer found for file: ${filePath}`);
@@ -35,10 +59,15 @@ class RouteRendererFactory {
35
59
  if (cached) {
36
60
  return cached;
37
61
  }
38
- const renderer = integrationPlugin.initializeRenderer();
62
+ const renderer = integrationPlugin.initializeRenderer({
63
+ rendererModules: this.rendererModules
64
+ });
39
65
  this.rendererCache.set(integrationName, renderer);
40
66
  return renderer;
41
67
  }
68
+ /**
69
+ * Resolves the integration plugin that owns a given route file.
70
+ */
42
71
  getIntegrationPlugin(filePath) {
43
72
  const templateExtension = PathUtils.getEcoTemplateExtension(filePath);
44
73
  const isIntegrationPlugin = (plugin) => {
@@ -51,13 +80,19 @@ class RouteRendererFactory {
51
80
  );
52
81
  return integrationPlugin;
53
82
  }
83
+ /**
84
+ * Returns the cached renderer engine for the file's owning integration,
85
+ * creating it on first use.
86
+ */
54
87
  getRouteRendererEngine(filePath) {
55
88
  const integrationPlugin = this.getIntegrationPlugin(filePath);
56
89
  const cached = this.rendererCache.get(integrationPlugin.name);
57
90
  if (cached) {
58
91
  return cached;
59
92
  }
60
- const renderer = integrationPlugin.initializeRenderer();
93
+ const renderer = integrationPlugin.initializeRenderer({
94
+ rendererModules: this.rendererModules
95
+ });
61
96
  this.rendererCache.set(integrationPlugin.name, renderer);
62
97
  return renderer;
63
98
  }
@@ -0,0 +1,97 @@
1
+ # Router Layer
2
+
3
+ This directory contains route discovery, matching, and browser-side navigation infrastructure.
4
+
5
+ ## Purpose
6
+
7
+ The router layer determines what route is being handled and how the client runtime coordinates navigation.
8
+
9
+ It is responsible for:
10
+
11
+ - filesystem route scanning and classification (`exact`, `dynamic`, `catch-all`)
12
+ - matching incoming request URLs to discovered routes
13
+ - server-side static-path expansion for dynamic routes
14
+ - client-side navigation ownership and cross-runtime handoff
15
+ - keeping route discovery separate from rendering execution
16
+
17
+ ## Directory Structure
18
+
19
+ ```
20
+ router/
21
+ ├── server/ # Server-side route scanning and matching
22
+ │ ├── fs-router-scanner.ts # Scans the filesystem and classifies routes
23
+ │ └── fs-router.ts # Matches request URLs to discovered routes
24
+ └── client/ # Browser-side navigation coordination
25
+ ├── navigation-coordinator.ts # Singleton runtime coordinator
26
+ └── link-intent.ts # Shared anchor detection and intent recovery helpers
27
+ ```
28
+
29
+ ## `server/`
30
+
31
+ ### `FSRouterScanner`
32
+
33
+ Walks the pages directory and builds a `Routes` map keyed by route pathname.
34
+
35
+ File patterns determine route kind:
36
+
37
+ | Pattern | Kind | Example |
38
+ | --------------- | ----------- | ----------------- |
39
+ | `page.tsx` | `exact` | `/about` |
40
+ | `[slug].tsx` | `dynamic` | `/blog/[slug]` |
41
+ | `[...slug].tsx` | `catch-all` | `/docs/[...slug]` |
42
+
43
+ For `dynamic` routes, the scanner checks whether the page module exports `getStaticPaths`. If present, every returned path is expanded into a concrete `exact`-style route at scan time. In build mode, both `getStaticPaths` and `getStaticProps` are required or an invariant is thrown.
44
+
45
+ Catch-all routes are registered but skipped during static generation with a warning.
46
+
47
+ ### `FSRouter`
48
+
49
+ Holds the scanned `Routes` map and exposes a `match(requestUrl)` method used by adapters.
50
+
51
+ Match priority:
52
+
53
+ 1. `exact` — the pathname must equal the route pathname exactly.
54
+ 2. `dynamic` — the clean (bracket-stripped) prefix must appear in the pathname, and the segment counts must match.
55
+ 3. `catch-all` — the clean prefix must appear in the pathname.
56
+
57
+ Additional helpers:
58
+
59
+ - `getDynamicParams(route, pathname)` — extracts named and spread parameters from a matched dynamic or catch-all route.
60
+ - `getSearchParams(url)` — converts `URLSearchParams` to a plain object.
61
+ - `setOnReload(cb)` / `reload()` — re-scans routes and fires an optional callback, used during development HMR.
62
+
63
+ ## `client/`
64
+
65
+ ### Navigation Coordinator (`navigation-coordinator.ts`)
66
+
67
+ A singleton browser-side runtime stored on `window.__ECO_PAGES__.navigation`.
68
+
69
+ Access it with:
70
+
71
+ ```ts
72
+ import { getEcoNavigationRuntime } from '@ecopages/core/router/client/navigation-coordinator';
73
+ const runtime = getEcoNavigationRuntime();
74
+ ```
75
+
76
+ The coordinator is framework-agnostic. Browser runtimes (e.g. `browser-router`, `react-router`) register themselves and the coordinator arbitrates:
77
+
78
+ - **Ownership** — which runtime currently drives SPA navigation (`claimOwnership`, `releaseOwnership`, `setOwner`).
79
+ - **Document owner marker** — an HTML attribute (`data-eco-document-owner`) written into rendered markup so the coordinator can `adoptDocumentOwner` on the incoming page.
80
+ - **Navigation transactions** — each navigation begins a transaction with an `AbortSignal`; superseded navigations are automatically cancelled.
81
+ - **Cross-runtime handoff** — `requestHandoff` passes a pre-fetched `Document` to the target runtime without tearing down the current page prematurely.
82
+ - **Reload** — `reloadCurrentPage` delegates to whichever runtime currently owns the document.
83
+ - **Events** — `subscribe` lets runtimes react to `owner-change` and `registration-change` events.
84
+
85
+ ### Link Intent (`link-intent.ts`)
86
+
87
+ Shared helpers for locating anchors and recovering stale navigation intent.
88
+
89
+ - `getAnchorFromNavigationEvent(event, linkSelector)` — finds the nearest matching anchor in the event's composed path, including across Shadow DOM boundaries.
90
+ - `recoverPendingNavigationHref(intent, hasInFlightNavigation, now, maxAgeMs?)` — resolves a previously captured pointer or hover target when the DOM changes before the click lands. Intents expire after `maxAgeMs` (default 1000 ms).
91
+
92
+ ## Relationship To Rendering
93
+
94
+ The router layer answers **which route should run**.
95
+ The route-renderer layer answers **how that route gets rendered**.
96
+
97
+ Keeping those seams separate avoids mixing route ownership, module loading, and component orchestration into one service.
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Shared client-side navigation intent helpers.
3
+ *
4
+ * Browser runtimes use the same low-level mechanics to:
5
+ * - locate the anchor associated with a click, pointer, or hover event,
6
+ * - persist the last valid pointer or hover target while a navigation is in flight,
7
+ * - recover the final intended href when the DOM changes before the click lands.
8
+ *
9
+ * Keeping those mechanics here lets browser-router and react-router share one
10
+ * implementation while preserving their router-specific interception rules.
11
+ *
12
+ * @module
13
+ */
14
+ /**
15
+ * Timestamped navigation intent captured from pointer or hover activity.
16
+ */
17
+ export type EcoPendingNavigationIntent = {
18
+ href: string;
19
+ timestamp: number;
20
+ };
21
+ /**
22
+ * Finds the nearest matching anchor within an event's composed path.
23
+ *
24
+ * This works across Shadow DOM boundaries, which is required for delegated
25
+ * navigation handling when links are rendered inside custom elements.
26
+ *
27
+ * @param event - Pointer or mouse event being inspected.
28
+ * @param linkSelector - Selector that identifies navigable anchors.
29
+ * @returns The matched anchor element, or `null` when no matching anchor exists.
30
+ */
31
+ export declare function getAnchorFromNavigationEvent(
32
+ event: MouseEvent | PointerEvent,
33
+ linkSelector: string,
34
+ ): HTMLAnchorElement | null;
35
+ /**
36
+ * Resolves a previously captured intent while a navigation is still in flight.
37
+ *
38
+ * Pending intents expire quickly because they are only meant to bridge the gap
39
+ * between pointer or hover capture and the later click event when the DOM or
40
+ * active runtime changes during a rapid navigation sequence.
41
+ *
42
+ * @param intent - Previously captured pointer or hover intent.
43
+ * @param hasInFlightNavigation - Whether a router navigation is still active.
44
+ * @param now - Current monotonic timestamp, usually from `performance.now()`.
45
+ * @param maxAgeMs - Maximum allowed age for the recovered intent.
46
+ * @returns The intended href when still valid, otherwise `null`.
47
+ */
48
+ export declare function recoverPendingNavigationHref(
49
+ intent: EcoPendingNavigationIntent | null,
50
+ hasInFlightNavigation: boolean,
51
+ now: number,
52
+ maxAgeMs?: number,
53
+ ): string | null;
@@ -0,0 +1,34 @@
1
+ function getAnchorFromNavigationEvent(event, linkSelector) {
2
+ const eventTarget = event.target;
3
+ if (eventTarget instanceof HTMLAnchorElement && eventTarget.matches(linkSelector)) {
4
+ return eventTarget;
5
+ }
6
+ if (eventTarget instanceof Element) {
7
+ const closestAnchor = eventTarget.closest(linkSelector);
8
+ if (closestAnchor instanceof HTMLAnchorElement) {
9
+ return closestAnchor;
10
+ }
11
+ }
12
+ if (eventTarget instanceof Text) {
13
+ const parentAnchor = eventTarget.parentElement?.closest(linkSelector);
14
+ if (parentAnchor instanceof HTMLAnchorElement) {
15
+ return parentAnchor;
16
+ }
17
+ }
18
+ return event.composedPath().find(
19
+ (target) => target instanceof HTMLAnchorElement && target.matches(linkSelector)
20
+ );
21
+ }
22
+ function recoverPendingNavigationHref(intent, hasInFlightNavigation, now, maxAgeMs = 1e3) {
23
+ if (!intent || !hasInFlightNavigation) {
24
+ return null;
25
+ }
26
+ if (now - intent.timestamp > maxAgeMs) {
27
+ return null;
28
+ }
29
+ return intent.href;
30
+ }
31
+ export {
32
+ getAnchorFromNavigationEvent,
33
+ recoverPendingNavigationHref
34
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { getAnchorFromNavigationEvent, recoverPendingNavigationHref } from "./link-intent.js";
3
+ describe("getAnchorFromNavigationEvent", () => {
4
+ it("returns the anchor when the event target is a text node inside it", () => {
5
+ const anchor = document.createElement("a");
6
+ anchor.href = "/fast";
7
+ anchor.setAttribute("data-eco-link", "true");
8
+ const textNode = document.createTextNode("fast-link");
9
+ anchor.append(textNode);
10
+ document.body.append(anchor);
11
+ const event = new MouseEvent("click", { bubbles: true, cancelable: true, composed: true });
12
+ Object.defineProperty(event, "target", {
13
+ configurable: true,
14
+ value: textNode
15
+ });
16
+ expect(getAnchorFromNavigationEvent(event, "a[data-eco-link]")).toBe(anchor);
17
+ });
18
+ it("returns the closest matching anchor for nested element targets", () => {
19
+ const anchor = document.createElement("a");
20
+ anchor.href = "/fast";
21
+ anchor.setAttribute("data-eco-link", "true");
22
+ const span = document.createElement("span");
23
+ span.textContent = "fast-link";
24
+ anchor.append(span);
25
+ document.body.append(anchor);
26
+ const event = new MouseEvent("click", { bubbles: true, cancelable: true, composed: true });
27
+ Object.defineProperty(event, "target", {
28
+ configurable: true,
29
+ value: span
30
+ });
31
+ expect(getAnchorFromNavigationEvent(event, "a[data-eco-link]")).toBe(anchor);
32
+ });
33
+ });
34
+ describe("recoverPendingNavigationHref", () => {
35
+ it("returns null for stale or missing pending intent state", () => {
36
+ expect(recoverPendingNavigationHref(null, true, 10)).toBeNull();
37
+ expect(recoverPendingNavigationHref({ href: "/fast", timestamp: 0 }, false, 10)).toBeNull();
38
+ expect(recoverPendingNavigationHref({ href: "/fast", timestamp: 0 }, true, 2e3, 1e3)).toBeNull();
39
+ });
40
+ it("returns the captured href while a navigation is still in flight", () => {
41
+ expect(recoverPendingNavigationHref({ href: "/fast", timestamp: 10 }, true, 20, 1e3)).toBe("/fast");
42
+ });
43
+ });
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Shared browser-side navigation coordinator.
3
+ *
4
+ * This module is the client runtime contract used by browser-router,
5
+ * react-router, and HMR code to coordinate ownership, cross-runtime handoff,
6
+ * current-page reloads, and stale-navigation cancellation.
7
+ *
8
+ * The coordinator stays framework-agnostic: browser runtimes register their
9
+ * capabilities here, and the coordinator arbitrates which runtime currently
10
+ * owns the document and which navigation transaction is still current.
11
+ *
12
+ * @module
13
+ */
14
+ /** Logical owner name for a browser navigation runtime. */
15
+ export type EcoNavigationOwner = 'none' | 'browser-router' | 'react-router' | (string & {});
16
+ /** HTML attribute used to persist the rendered document owner across navigations. */
17
+ export declare const ECO_DOCUMENT_OWNER_ATTRIBUTE = "data-eco-document-owner";
18
+ /** High-level navigation direction understood by browser runtimes. */
19
+ export type EcoNavigationDirection = 'forward' | 'back' | 'replace';
20
+ /** Navigation request sent between browser runtimes. */
21
+ export type EcoNavigationRequest = {
22
+ href: string;
23
+ direction?: EcoNavigationDirection;
24
+ source?: EcoNavigationOwner;
25
+ };
26
+ /** Navigation handoff request that includes a pre-fetched document. */
27
+ export type EcoNavigationHandoffRequest = EcoNavigationRequest & {
28
+ finalHref?: string;
29
+ targetOwner: EcoNavigationOwner;
30
+ document: Document;
31
+ html?: string;
32
+ /**
33
+ * Reports whether the source runtime's original navigation has already been
34
+ * superseded.
35
+ *
36
+ * Target runtimes use this to ignore handoff work that arrives after a newer
37
+ * navigation has already claimed ownership.
38
+ */
39
+ isStaleSourceNavigation?: () => boolean;
40
+ };
41
+ /** Request to reload the current page through the active runtime. */
42
+ export type EcoReloadRequest = {
43
+ clearCache?: boolean;
44
+ source?: EcoNavigationOwner;
45
+ };
46
+ /** Snapshot of the coordinator's current runtime ownership state. */
47
+ export type EcoNavigationOwnerState = {
48
+ owner: EcoNavigationOwner;
49
+ canHandleSpaNavigation: boolean;
50
+ };
51
+ /**
52
+ * Coordinator-managed navigation transaction.
53
+ *
54
+ * Runtimes use this to determine whether async work has become stale and to
55
+ * cancel or complete the active navigation sequence.
56
+ */
57
+ export type EcoNavigationTransaction = {
58
+ id: number;
59
+ signal: AbortSignal;
60
+ isCurrent: () => boolean;
61
+ cancel: () => void;
62
+ complete: () => void;
63
+ };
64
+ export type EcoNavigationRuntimeEvent = {
65
+ type: 'owner-change';
66
+ owner: EcoNavigationOwner;
67
+ previousOwner: EcoNavigationOwner;
68
+ reason: 'set' | 'claim' | 'release' | 'document' | 'unregister';
69
+ } | {
70
+ type: 'registration-change';
71
+ owner: EcoNavigationOwner;
72
+ status: 'registered' | 'unregistered';
73
+ };
74
+ export type EcoNavigationRuntimeListener = (event: EcoNavigationRuntimeEvent) => void;
75
+ export type EcoNavigationRuntimeRegistration = {
76
+ owner: EcoNavigationOwner;
77
+ navigate?: (request: EcoNavigationRequest) => Promise<boolean | void>;
78
+ handoffNavigation?: (request: EcoNavigationHandoffRequest) => Promise<boolean | void>;
79
+ reloadCurrentPage?: (request?: EcoReloadRequest) => Promise<void>;
80
+ /**
81
+ * Releases runtime-owned client state before another runtime commits a new
82
+ * document.
83
+ *
84
+ * This hook intentionally does not run as part of `requestHandoff()`. The
85
+ * accepting runtime decides when cleanup is safe so cross-runtime handoffs do
86
+ * not blank the current page before the incoming document is ready.
87
+ */
88
+ cleanupBeforeHandoff?: () => void | Promise<void>;
89
+ };
90
+ /** Public browser-side navigation coordinator interface. */
91
+ export interface EcoNavigationRuntime {
92
+ /** Returns the currently active runtime owner and whether it can handle SPA navigation. */
93
+ getOwnerState(): EcoNavigationOwnerState;
94
+ /** Starts a new navigation transaction, invalidating the previously active one. */
95
+ beginNavigationTransaction(): EcoNavigationTransaction;
96
+ /** Reports whether a navigation transaction is still in flight. */
97
+ hasPendingNavigationTransaction(): boolean;
98
+ /** Cancels the active navigation transaction, if one exists. */
99
+ cancelCurrentNavigationTransaction(): void;
100
+ /** Forces the current owner value without checking registrations. */
101
+ setOwner(owner: EcoNavigationOwner): void;
102
+ /** Claims ownership for a runtime that is ready to drive SPA navigation. */
103
+ claimOwnership(owner: EcoNavigationOwner): void;
104
+ /** Releases ownership when the given runtime no longer controls the document. */
105
+ releaseOwnership(owner: EcoNavigationOwner): void;
106
+ /** Resolves document ownership from the rendered owner marker or fallback. */
107
+ resolveDocumentOwner(doc: Document, fallbackOwner?: EcoNavigationOwner): EcoNavigationOwner;
108
+ /** Reads and adopts the rendered document owner as the active runtime owner. */
109
+ adoptDocumentOwner(doc: Document, fallbackOwner?: EcoNavigationOwner): EcoNavigationOwner;
110
+ /** Returns whether the active owner is some runtime other than the given owner. */
111
+ isOwnedByAnotherRuntime(owner: EcoNavigationOwner): boolean;
112
+ /** Subscribes to ownership and registration change events. */
113
+ subscribe(listener: EcoNavigationRuntimeListener): () => void;
114
+ /** Registers a runtime implementation with the coordinator. */
115
+ register(runtime: EcoNavigationRuntimeRegistration): () => void;
116
+ /** Requests navigation through another eligible registered runtime. */
117
+ requestNavigation(request: EcoNavigationRequest): Promise<boolean>;
118
+ /**
119
+ * Hands a pre-fetched document to the target runtime.
120
+ *
121
+ * The coordinator delegates the document but does not clean up the current
122
+ * owner first. Cleanup timing belongs to the accepting runtime so a stale or
123
+ * superseded handoff cannot tear down the current page prematurely.
124
+ */
125
+ requestHandoff(request: EcoNavigationHandoffRequest): Promise<boolean>;
126
+ /** Requests the active runtime to reload the current page. */
127
+ reloadCurrentPage(request?: EcoReloadRequest): Promise<boolean>;
128
+ /** Runs a target runtime's cleanup hook before handoff. */
129
+ cleanupOwner(owner: EcoNavigationOwner): Promise<void>;
130
+ /** Runs cleanup for whichever runtime currently owns the document. */
131
+ cleanupCurrentOwner(): Promise<void>;
132
+ }
133
+ /**
134
+ * Reads the explicit browser document owner marker from a rendered HTML document.
135
+ *
136
+ * Documents without a marker return `null`, allowing runtimes to fall back to
137
+ * their local default behavior without scanning hydration scripts.
138
+ */
139
+ export declare function getEcoDocumentOwner(doc: Document): EcoNavigationOwner | null;
140
+ /**
141
+ * Returns the singleton browser-side navigation coordinator.
142
+ *
143
+ * The coordinator centralizes ownership, handoff, and current-page reload
144
+ * requests across browser runtimes through one internal protocol.
145
+ *
146
+ * @param windowObject - Window-like object that stores the singleton runtime.
147
+ * @returns The shared browser navigation coordinator.
148
+ */
149
+ export declare function getEcoNavigationRuntime(windowObject?: Window & typeof globalThis): EcoNavigationRuntime;