soma-core 2.0.0 → 2.1.0

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 (1103) hide show
  1. package/README.md +28 -19
  2. package/bin/codegen.cjs +191 -0
  3. package/bin/eject.cjs +25 -12
  4. package/bin/service-codegen.cjs +98 -0
  5. package/bin/soma-lsp.cjs +140 -23
  6. package/bin/soma-runtime.cjs +75 -0
  7. package/bin/soma-sync-runtime.cjs +130 -0
  8. package/bin/soma.cjs +200 -13
  9. package/bin/soma.ts +170 -0
  10. package/core/build/compiler/flat-page.ts +305 -0
  11. package/core/build/compiler/full-manifest-builder.ts +68 -27
  12. package/core/build/compiler/html-index.ts +169 -0
  13. package/core/build/compiler/page-assets.ts +30 -7
  14. package/core/build/compiler/page-base-resolver.ts +11 -0
  15. package/core/build/compiler/page-declaration-compiler.ts +264 -226
  16. package/core/build/compiler/rollup-plugin-soma.ts +7 -2
  17. package/core/build/compiler/soma-manifest-webpack-plugin.js +114 -229
  18. package/core/build/compiler/soma-precompile.js +3733 -1892
  19. package/core/build/compiler/soma-precompile.ts +15 -20
  20. package/core/build/compiler/soma-rspack-yaml-loader.js +4 -3
  21. package/core/build/compiler/soma-webpack-loader.js +8 -4
  22. package/core/build/compiler/vite-plugin-soma.ts +8 -8
  23. package/core/build/component/component-graph.ts +1 -1
  24. package/core/build/component-tree/artifact-codec.ts +9 -42
  25. package/core/build/component-tree/collection-binding-lowerer.ts +1 -1
  26. package/core/build/component-tree/definition-preparation.ts +4 -5
  27. package/core/build/component-tree/parser.ts +1 -1
  28. package/core/build/component-tree/registry-snapshot.ts +45 -10
  29. package/core/build/component-tree/source-preflight.ts +2 -90
  30. package/core/build/component-tree/structure-topology.ts +1 -1
  31. package/core/build/eject/plan-eject.ts +9 -11
  32. package/core/build/lsp/component-tree-service.ts +4 -1
  33. package/core/build/lsp/component-tree.cjs +1 -1
  34. package/core/build/lsp/cross-file-diagnostics.cjs +5 -21
  35. package/core/build/lsp/soma-declaration.cjs +45 -47
  36. package/core/build/lsp/std-completion.generated.json +26 -0
  37. package/core/build/lsp/ui-yaml-completion.cjs +25 -37
  38. package/core/client/a11y/a11y-config.ts +50 -0
  39. package/core/client/a11y/announcer.ts +140 -0
  40. package/core/client/a11y/dom-id.ts +31 -0
  41. package/core/client/a11y/index.ts +40 -0
  42. package/core/client/a11y/motion-hook.ts +48 -0
  43. package/core/client/a11y/motion.ts +95 -0
  44. package/core/client/base/SomaPageRootBase.ts +44 -2
  45. package/core/client/base/index.ts +10 -8
  46. package/core/client/behavior/adapter-collection.ts +65 -0
  47. package/core/client/behavior/adapter-popper.ts +60 -0
  48. package/core/client/behavior/aria-hide-outside.ts +144 -0
  49. package/core/client/behavior/css-escape.ts +51 -0
  50. package/core/client/behavior/focus-scope.ts +433 -0
  51. package/core/client/behavior/focus-traversal.ts +68 -0
  52. package/core/client/behavior/index.ts +109 -0
  53. package/core/client/behavior/layer-stack.ts +234 -0
  54. package/core/client/behavior/overlay-host/index.ts +192 -0
  55. package/core/client/behavior/overlay-host/port.ts +76 -0
  56. package/core/client/behavior/overlay-wiring.ts +186 -0
  57. package/core/client/behavior/port.ts +85 -0
  58. package/core/client/behavior/positioner.ts +32 -0
  59. package/core/client/behavior/presence.ts +197 -0
  60. package/core/client/behavior/zag/adapter-vanilla.ts +96 -0
  61. package/core/client/behavior/zag/layer-bridge.ts +51 -0
  62. package/core/client/behavior/zag/machine-host.ts +69 -0
  63. package/core/client/behavior/zag/machines.ts +52 -0
  64. package/core/client/compiler/manifest-compiler.ts +33 -70
  65. package/core/client/component/adapter/adapt.ts +79 -0
  66. package/core/client/component/adapter/index.ts +3 -0
  67. package/core/client/component/adapter/types.ts +37 -0
  68. package/core/client/component/adapter/web-component.ts +130 -0
  69. package/core/client/component/component-defaults.ts +1 -1
  70. package/core/client/component/component-definition.types.ts +27 -5
  71. package/core/client/component/component-expander.ts +24 -16
  72. package/core/client/component/component-manager.ts +245 -814
  73. package/core/client/component/component-pack.ts +58 -216
  74. package/core/client/component/component-registry.ts +53 -29
  75. package/core/client/component/projection-admission.ts +63 -0
  76. package/core/client/component/projection-registry.ts +653 -0
  77. package/core/client/component/projection.types.ts +48 -0
  78. package/core/client/component/region-unavailable.ts +37 -0
  79. package/core/client/component/scoped-adapter.ts +3 -3
  80. package/core/client/component/structure-adapter.ts +93 -8
  81. package/core/client/container/IContainerAdapter.ts +4 -3
  82. package/core/client/container/SomaContainerAdapter.ts +22 -123
  83. package/core/client/data/collection-payload.ts +2 -0
  84. package/core/client/data/data-object-resolver.ts +827 -330
  85. package/core/client/data/data-polling.ts +110 -0
  86. package/core/client/data/data-subscriptions.ts +98 -0
  87. package/core/client/data/data-write-actions.ts +118 -0
  88. package/core/client/data/envelope-failure.ts +48 -0
  89. package/core/client/data/format-config.ts +62 -0
  90. package/core/client/data/region-scope-port.ts +265 -0
  91. package/core/client/data/region-scope-views.ts +96 -0
  92. package/core/client/data/role-gate.ts +44 -0
  93. package/core/client/data/write-outcome-store.ts +101 -0
  94. package/core/client/data/write-outcome.ts +175 -0
  95. package/core/client/engine/asset-resolver.ts +12 -21
  96. package/core/client/engine/dom-renderer.ts +85 -460
  97. package/core/client/engine/event-engine.ts +349 -323
  98. package/core/client/engine/locale-text-binder.ts +168 -0
  99. package/core/client/engine/property-watcher.ts +18 -164
  100. package/core/client/engine/reactive-proxy.ts +23 -194
  101. package/core/client/engine/render-engine.ts +16 -118
  102. package/core/client/engine/row-range.ts +11 -0
  103. package/core/client/engine/runtime-builder.ts +10 -13
  104. package/core/client/engine/scope-resolver.ts +3 -3
  105. package/core/client/engine/soma-bootstrap.ts +1238 -323
  106. package/core/client/engine/step-runner.ts +90 -12
  107. package/core/client/engine/style-binder.ts +2 -162
  108. package/core/client/engine/timer-engine.ts +2 -1
  109. package/core/client/engines/chart/adapter-echarts.ts +144 -0
  110. package/core/client/engines/chart/echarts-subpaths.d.ts +3 -0
  111. package/core/client/engines/chart/index.ts +90 -0
  112. package/core/client/engines/chart/kind-modules.ts +74 -0
  113. package/core/client/engines/chart/port.ts +44 -0
  114. package/core/client/engines/diff/adapter-jsdiff.ts +35 -0
  115. package/core/client/engines/diff/index.ts +33 -0
  116. package/core/client/engines/diff/port.ts +26 -0
  117. package/core/client/engines/dnd/adapter-pragmatic.ts +159 -0
  118. package/core/client/engines/dnd/index.ts +67 -0
  119. package/core/client/engines/dnd/port.ts +45 -0
  120. package/core/client/engines/engine-adapters.ts +29 -0
  121. package/core/client/engines/load.ts +44 -0
  122. package/core/client/engines/qrcode/adapter-qrcode-generator.ts +52 -0
  123. package/core/client/engines/qrcode/index.ts +30 -0
  124. package/core/client/engines/qrcode/port.ts +27 -0
  125. package/core/client/engines/table/adapter-tanstack.ts +132 -0
  126. package/core/client/engines/table/index.ts +80 -0
  127. package/core/client/engines/table/port.ts +55 -0
  128. package/core/client/engines/temporal/adapter-polyfill.ts +158 -0
  129. package/core/client/engines/temporal/index.ts +84 -0
  130. package/core/client/engines/temporal/port.ts +53 -0
  131. package/core/client/engines/virtual/adapter-tanstack.ts +133 -0
  132. package/core/client/engines/virtual/index.ts +43 -0
  133. package/core/client/engines/virtual/port.ts +43 -0
  134. package/core/client/format/formatter.ts +32 -0
  135. package/core/client/format/index.ts +26 -0
  136. package/core/client/format/zoned.ts +10 -0
  137. package/core/client/host-bridge/index.ts +17 -0
  138. package/core/client/host-bridge/load-host-domain-class.ts +15 -4
  139. package/core/client/host-bridge/resolve-host-bootstrap.ts +63 -11
  140. package/core/client/host-bridge/soma-app-host.stub.ts +3 -0
  141. package/core/client/host-bridge/soma-bootstrap-from-app.ts +25 -0
  142. package/core/client/infra/auth/IAuthService.ts +18 -13
  143. package/core/client/infra/auth/TokenAuthService.ts +126 -112
  144. package/core/client/infra/config/SomaConfig.ts +16 -0
  145. package/core/client/infra/config/feature-flags.ts +28 -0
  146. package/core/client/infra/http/IHttpClient.ts +2 -0
  147. package/core/client/infra/http/SomaHttpService.ts +1 -0
  148. package/core/client/infra/i18n/II18n.ts +23 -6
  149. package/core/client/infra/i18n/builtin-locale.ts +31 -0
  150. package/core/client/infra/i18n/index.ts +4 -0
  151. package/core/client/infra/i18n/interpolate.ts +28 -0
  152. package/core/client/infra/i18n/locale-catalog.ts +233 -0
  153. package/core/client/infra/i18n/pack-locales.ts +117 -0
  154. package/core/client/infra/identity/identity-port.ts +178 -0
  155. package/core/client/infra/notify/DefaultNotifyService.ts +86 -31
  156. package/core/client/infra/notify/INotifyService.ts +2 -14
  157. package/core/client/infra/notify/notify-declaration.ts +37 -0
  158. package/core/client/infra/permission/SomaPermission.ts +58 -48
  159. package/core/client/infra/router/IRouter.ts +24 -19
  160. package/core/client/infra/router/SomaRouter.ts +78 -66
  161. package/core/client/keyboard/collection.ts +197 -0
  162. package/core/client/keyboard/compose-keys.ts +68 -0
  163. package/core/client/keyboard/cursor.ts +117 -0
  164. package/core/client/keyboard/delegate.ts +195 -0
  165. package/core/client/keyboard/ime.ts +8 -0
  166. package/core/client/keyboard/index.ts +73 -0
  167. package/core/client/keyboard/intents.ts +60 -0
  168. package/core/client/keyboard/matrix.ts +269 -0
  169. package/core/client/keyboard/submit.ts +30 -0
  170. package/core/client/keyboard/typeahead.ts +203 -0
  171. package/core/client/keyboard/wiring.ts +324 -0
  172. package/core/client/middleware/createPermissionMiddleware.ts +20 -11
  173. package/core/client/mount/domain-rule.ts +43 -0
  174. package/core/client/mount/index.ts +3 -0
  175. package/core/client/mount/mount-page.ts +163 -0
  176. package/core/client/mount/types.ts +93 -0
  177. package/core/client/observability/runtime-observer.ts +136 -0
  178. package/core/client/parser/annotation-extractor.ts +1 -1
  179. package/core/client/parser/confirm-spec.ts +139 -0
  180. package/core/client/parser/data-config-parser.ts +416 -217
  181. package/core/client/parser/duration.ts +2 -16
  182. package/core/client/parser/page-state-parser.ts +59 -64
  183. package/core/client/parser/pipeline-parser.ts +178 -236
  184. package/core/client/parser/style-config-parser.ts +15 -81
  185. package/core/client/parser/subscribe-parser.ts +83 -0
  186. package/core/client/parser/timer-parser.ts +1 -1
  187. package/core/client/parser/trigger-parser.ts +1 -1
  188. package/core/client/parser/ui-config-parser.ts +244 -243
  189. package/core/client/pipes/pipe-registry.ts +304 -76
  190. package/core/client/registry/declaration-renderer.ts +20 -8
  191. package/core/client/registry/page-lifecycle.ts +4 -4
  192. package/core/client/registry/remote-page.ts +4 -4
  193. package/core/client/render-ports/index.ts +18 -0
  194. package/core/client/render-ports/notify-renderer.ts +45 -0
  195. package/core/client/render-ports/region-fallback.ts +8 -0
  196. package/core/client/render-ports/scheduling/prompt-queue.ts +102 -0
  197. package/core/client/render-ports/scheduling/toast-scheduler.ts +253 -0
  198. package/core/client/runtime/SomaRuntimeServices.ts +180 -16
  199. package/core/client/runtime/SomaSnapshotStore.ts +100 -100
  200. package/core/client/runtime/nav-history.ts +147 -0
  201. package/core/client/runtime/nav-port.ts +68 -0
  202. package/core/client/runtime/shortcuts.ts +360 -0
  203. package/core/client/runtime/write-feedback.ts +71 -0
  204. package/core/client/runtime-entry.ts +29 -0
  205. package/core/client/scheduler/SomaScheduler.ts +13 -3
  206. package/core/client/scheduling/flush-scheduler.ts +100 -0
  207. package/core/client/scheduling/index.ts +22 -0
  208. package/core/client/scheduling/observer-pool.ts +109 -0
  209. package/core/client/security/attribute-presence.ts +1 -3
  210. package/core/client/security/html-sanitizer.ts +23 -1
  211. package/core/client/security/url-guard.ts +0 -0
  212. package/core/client/styles/compiled-styles.ts +47 -0
  213. package/core/client/styles/index.ts +10 -0
  214. package/core/client/styles/pack-styles.ts +169 -0
  215. package/core/client/styles/sheet-mount.ts +48 -0
  216. package/core/client/styles/style-features.ts +131 -0
  217. package/core/client/time/clock.ts +36 -0
  218. package/core/client/time/instant.ts +2 -0
  219. package/core/client/url-state/index.ts +15 -0
  220. package/core/client/url-state/page-tabs-controller.ts +47 -0
  221. package/core/client/url-state/state-query-binding.ts +114 -0
  222. package/core/client/url-state/url-state.ts +149 -0
  223. package/core/client/validation/async-check-registry.ts +129 -0
  224. package/core/client/validation/async-rules.ts +259 -0
  225. package/core/client/validation/contract-validator.ts +44 -5
  226. package/core/client/validation/field-rules.ts +49 -0
  227. package/core/client/validation/index.ts +53 -0
  228. package/core/client/validation/object-rules.ts +72 -0
  229. package/core/index.ts +290 -264
  230. package/core/inspect/check-product.ts +542 -0
  231. package/core/inspect/check-runtime.ts +865 -0
  232. package/core/inspect/runtime.ts +98 -0
  233. package/core/page-target/index.ts +9 -0
  234. package/core/page-target/provenance.ts +119 -0
  235. package/core/page-target/slug.ts +7 -0
  236. package/core/page-target/testing/index.ts +329 -0
  237. package/core/page-target/types.ts +279 -0
  238. package/core/predicates-entry.ts +43 -0
  239. package/core/server/api/load-host-service.ts +3 -0
  240. package/core/server/compile-port.ts +18 -0
  241. package/core/server/diagnostic-gate-entry.ts +14 -0
  242. package/core/server/engines/style/candidate-guard.ts +59 -0
  243. package/core/server/engines/style/index.ts +57 -0
  244. package/core/server/engines/style/port.ts +34 -0
  245. package/core/server/engines/style/tailwind-adapter.ts +68 -0
  246. package/core/server/host/content-security-policy.ts +3 -5
  247. package/core/server/host/host-assembly-entry.ts +24 -0
  248. package/core/server/host/host-assembly.ts +267 -0
  249. package/core/server/host/host-caller.ts +52 -0
  250. package/core/server/host/host-response-headers.ts +49 -0
  251. package/core/server/host/invoke-host-request-hook.ts +5 -0
  252. package/core/server/host/locale-yaml.ts +53 -0
  253. package/core/server/host/page-markup-config.ts +13 -0
  254. package/core/server/host/published-page-artifact-cache.ts +355 -124
  255. package/core/server/host/published-page-assets.ts +91 -46
  256. package/core/server/host/resolve-host-request-hook.ts +9 -10
  257. package/core/server/host/resolve-host-tree-context.ts +8 -28
  258. package/core/server/host/server-page-assets.ts +175 -57
  259. package/core/server/host/soma-page-compile.ts +57 -16
  260. package/core/server/host/source-packages.cjs +184 -0
  261. package/core/server/host/source-packages.ts +18 -126
  262. package/core/server/host/virtual-pages.ts +197 -0
  263. package/core/server/index.ts +12 -43
  264. package/core/server/node.ts +52 -0
  265. package/core/server/page-assets.ts +73 -0
  266. package/core/server/page-declaration.ts +83 -7
  267. package/core/server/registry/api-registry-store.ts +17 -28
  268. package/core/server/registry/asset-store.ts +17 -19
  269. package/core/server/registry/batch-publish.ts +38 -0
  270. package/core/server/registry/batch-stage.ts +130 -0
  271. package/core/server/registry/component-supply.ts +31 -0
  272. package/core/server/registry/declaration-precompiler.ts +48 -34
  273. package/core/server/registry/index.ts +78 -1
  274. package/core/server/registry/page-registry-repository.ts +484 -69
  275. package/core/server/registry/page-registry-store.ts +617 -108
  276. package/core/server/registry/publish-asset-pin.ts +22 -20
  277. package/core/server/registry/registry-file-lock.ts +16 -3
  278. package/core/server/registry/registry-subjects.ts +6 -6
  279. package/core/server/registry/registry-write-pipeline.ts +65 -1
  280. package/core/server/registry/request-body-limit.ts +3 -1
  281. package/core/server/registry/rollback-plan.ts +181 -0
  282. package/core/server/registry/services/index.ts +14 -1
  283. package/core/server/registry/services/pages/Get.ts +26 -4
  284. package/core/server/registry/services/pages/Register.ts +29 -7
  285. package/core/server/registry/services/pages/RegisterBatch.ts +68 -0
  286. package/core/server/registry/services/pages/Rollback.ts +14 -4
  287. package/core/server/registry/services/pages/Unregister.ts +2 -1
  288. package/core/server/registry/source/canonical.ts +57 -0
  289. package/core/server/registry/source/errors.ts +81 -0
  290. package/core/server/registry/source/index.ts +49 -0
  291. package/core/server/registry/source/ledger.ts +306 -0
  292. package/core/server/registry/source/snapshot.ts +29 -0
  293. package/core/server/registry/source/source-name.ts +48 -0
  294. package/core/server/registry/source/types.ts +106 -0
  295. package/core/server/registry/source/version-store.ts +349 -0
  296. package/core/server/registry/standard-product.ts +185 -0
  297. package/core/server/registry/validation/compile-gate.ts +39 -50
  298. package/core/server/registry/validation/cross-check.ts +18 -5
  299. package/core/server/registry/validation/declaration-safety-scan.ts +12 -10
  300. package/core/server/registry/validation/region-scopes.ts +50 -0
  301. package/core/server/runtime-space/access-gate.ts +206 -0
  302. package/core/server/runtime-space/advice-log.ts +67 -0
  303. package/core/server/runtime-space/artifact-evict.ts +15 -0
  304. package/core/server/runtime-space/bindings.ts +478 -0
  305. package/core/server/runtime-space/digest.ts +62 -0
  306. package/core/server/runtime-space/dynamic-pages.ts +379 -0
  307. package/core/server/runtime-space/errors.ts +96 -0
  308. package/core/server/runtime-space/gc.ts +116 -0
  309. package/core/server/runtime-space/index.ts +106 -0
  310. package/core/server/runtime-space/inject.ts +497 -0
  311. package/core/server/runtime-space/nav-catalog.ts +140 -0
  312. package/core/server/runtime-space/page-grants.ts +436 -0
  313. package/core/server/runtime-space/prewarm.ts +234 -0
  314. package/core/server/runtime-space/registry-cold-start.ts +69 -0
  315. package/core/server/runtime-space/resolve.ts +538 -0
  316. package/core/server/runtime-space/root.cjs +160 -0
  317. package/core/server/runtime-space/root.ts +26 -0
  318. package/core/server/runtime-space/static-source.ts +85 -0
  319. package/core/server/runtime-space/store.ts +253 -0
  320. package/core/server/runtime-space/submit-steps.ts +412 -0
  321. package/core/server/runtime-space/types.ts +314 -0
  322. package/core/shared/anchor-space.ts +48 -0
  323. package/core/shared/artifact-compatibility.ts +156 -0
  324. package/core/shared/behavior-machine-names.ts +8 -0
  325. package/core/shared/calc/coerce.ts +2 -29
  326. package/core/shared/calc/errors.ts +4 -7
  327. package/core/shared/calc/evaluator.ts +23 -11
  328. package/core/shared/calc/index.ts +3 -4
  329. package/core/shared/calc/lexer.ts +7 -12
  330. package/core/shared/calc/parser.ts +8 -19
  331. package/core/shared/calc/typer.ts +10 -23
  332. package/core/shared/component-tree-artifact.ts +81 -7
  333. package/core/shared/contract-a11y.ts +335 -0
  334. package/core/shared/contract-sections.ts +344 -0
  335. package/core/shared/core-diagnostic-codes.ts +208 -0
  336. package/core/shared/data-declaration-checks.ts +211 -0
  337. package/core/shared/date-parts.ts +2 -0
  338. package/core/shared/declaration-errors.ts +14 -0
  339. package/core/shared/declaration-keys.ts +36 -0
  340. package/core/shared/diagnostic-code-index-entry.ts +14 -0
  341. package/core/shared/diagnostic-gate.ts +139 -0
  342. package/core/shared/engines/engine-error.ts +33 -0
  343. package/core/shared/engines/style/style-engine.types.ts +28 -0
  344. package/core/shared/envelope-text-width.generated.d.mts +19 -0
  345. package/core/shared/envelope-text-width.generated.mjs +413 -0
  346. package/core/shared/fragments-section.ts +10 -0
  347. package/core/shared/generation-diagnostics.ts +58 -0
  348. package/core/shared/generation-error.ts +73 -0
  349. package/core/shared/hook-attributes.ts +159 -0
  350. package/core/shared/inert-data-element.ts +50 -0
  351. package/core/shared/nav-back.ts +120 -0
  352. package/core/shared/page-access-text.ts +7 -0
  353. package/core/shared/page-envelope-runtime.ts +88 -0
  354. package/core/shared/page-envelope.ts +618 -0
  355. package/core/shared/page-scopes.ts +83 -0
  356. package/core/shared/pipeline-error-codes-view.ts +30 -0
  357. package/core/shared/pipeline-limits-view.ts +27 -0
  358. package/core/shared/predicates/index.ts +85 -497
  359. package/core/shared/predicates/relative-window.ts +19 -0
  360. package/core/shared/published-page-route.ts +5 -14
  361. package/core/shared/region-scope-decl.ts +488 -0
  362. package/core/shared/registry-generated/compile-purposes.ts +53 -0
  363. package/core/shared/registry-generated/diagnostic-registry-index.ts +796 -0
  364. package/core/shared/registry-generated/diagnostic-registry.ts +5872 -0
  365. package/core/shared/registry-generated/error-codes.ts +137 -0
  366. package/core/shared/registry-generated/index.ts +13 -0
  367. package/core/shared/registry-generated/limits.ts +552 -0
  368. package/core/shared/registry-generated/platform-keys.ts +56 -0
  369. package/core/shared/registry-generated/region-scope.ts +823 -0
  370. package/core/shared/registry-generated/std-grammar-completion.ts +216 -0
  371. package/core/shared/registry-generated/std-grammar-views.ts +139 -0
  372. package/core/shared/registry-generated/std-grammar.ts +161 -0
  373. package/core/shared/rule-step.ts +2 -0
  374. package/core/shared/runtime-address.ts +244 -0
  375. package/core/shared/scope-decl.ts +77 -0
  376. package/core/shared/sha256.ts +108 -0
  377. package/core/shared/show-when.ts +77 -0
  378. package/core/shared/source-file-suffix.ts +8 -0
  379. package/core/shared/std-auth-scan.ts +158 -0
  380. package/core/shared/types/choice-confirm.types.ts +2 -0
  381. package/core/shared/types/compile-diagnostic.types.ts +42 -0
  382. package/core/shared/types/compile-port.types.ts +41 -0
  383. package/core/shared/types/component-contract.types.ts +145 -156
  384. package/core/shared/types/component-tree-artifact.types.ts +18 -2
  385. package/core/shared/types/component-tree.types.ts +17 -6
  386. package/core/shared/types/data-config.types.ts +182 -222
  387. package/core/shared/types/domain.types.ts +20 -5
  388. package/core/shared/types/engine.types.ts +2 -0
  389. package/core/shared/types/event.types.ts +78 -8
  390. package/core/shared/types/generation-error.types.ts +83 -0
  391. package/core/shared/types/host-assembly.types.ts +126 -0
  392. package/core/shared/types/locale.types.ts +46 -0
  393. package/core/shared/types/manifest.types.ts +2 -7
  394. package/core/shared/types/nav-context.types.ts +46 -0
  395. package/core/shared/types/nav.types.ts +57 -0
  396. package/core/shared/types/notify.types.ts +45 -0
  397. package/core/shared/types/observation.types.ts +76 -0
  398. package/core/shared/types/page-envelope.types.ts +125 -0
  399. package/core/shared/types/page-state.types.ts +21 -42
  400. package/core/shared/types/region-scope.types.ts +177 -0
  401. package/core/shared/types/registry-batch.types.ts +45 -0
  402. package/core/shared/types/shortcuts.types.ts +61 -0
  403. package/core/shared/types/source.types.ts +10 -0
  404. package/core/shared/types/style-config.types.ts +61 -82
  405. package/core/shared/types/temporal.types.ts +3 -0
  406. package/core/shared/types/ui-config.types.ts +80 -152
  407. package/core/shared/types/write-outcome-view.types.ts +24 -0
  408. package/core/shared/types/write-runtime.types.ts +10 -0
  409. package/core/shared/types/write.types.ts +86 -0
  410. package/dist/browser/runtime-bundle.manifest.json +938 -0
  411. package/dist/browser/soma-runtime.js +120260 -0
  412. package/dist/cli/soma.js +120 -456
  413. package/dist/core/adaptive-pure.cjs +41 -0
  414. package/dist/core/index.cjs +119695 -22484
  415. package/dist/core/theme-pure.cjs +38 -0
  416. package/dist/diagnostics/telemetry.cjs +2 -1
  417. package/dist/lsp/component-tree.cjs +6398 -8254
  418. package/dist/preview-export.cjs +3401 -0
  419. package/dist/types/build/compiler/flat-page.d.ts +52 -0
  420. package/dist/types/build/compiler/full-manifest-builder.d.ts +26 -1
  421. package/dist/types/build/compiler/html-index.d.ts +48 -0
  422. package/dist/types/build/compiler/page-assets.d.ts +11 -3
  423. package/dist/types/build/compiler/page-base-resolver.d.ts +5 -0
  424. package/dist/types/build/compiler/page-declaration-compiler.d.ts +97 -56
  425. package/dist/types/build/compiler/soma-precompile.d.ts +3 -3
  426. package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -2
  427. package/dist/types/build/component/component-graph.d.ts +1 -1
  428. package/dist/types/build/component-tree/artifact-codec.d.ts +5 -8
  429. package/dist/types/build/component-tree/registry-snapshot.d.ts +18 -0
  430. package/dist/types/build/component-tree/source-preflight.d.ts +4 -14
  431. package/dist/types/build/component-tree/structure-topology.d.ts +1 -1
  432. package/dist/types/build/eject/plan-eject.d.ts +0 -1
  433. package/dist/types/build/lsp/component-tree-service.d.ts +2 -0
  434. package/dist/types/client/a11y/a11y-config.d.ts +15 -0
  435. package/dist/types/client/a11y/announcer.d.ts +45 -0
  436. package/dist/types/client/a11y/dom-id.d.ts +4 -0
  437. package/dist/types/client/a11y/index.d.ts +5 -0
  438. package/dist/types/client/a11y/motion-hook.d.ts +13 -0
  439. package/dist/types/client/a11y/motion.d.ts +24 -0
  440. package/dist/types/client/base/SomaPageRootBase.d.ts +17 -2
  441. package/dist/types/client/base/index.d.ts +8 -8
  442. package/dist/types/client/behavior/adapter-collection.d.ts +39 -0
  443. package/dist/types/client/behavior/adapter-popper.d.ts +2 -0
  444. package/dist/types/client/behavior/aria-hide-outside.d.ts +13 -0
  445. package/dist/types/client/behavior/css-escape.d.ts +11 -0
  446. package/dist/types/client/behavior/focus-scope.d.ts +69 -0
  447. package/dist/types/client/behavior/focus-traversal.d.ts +3 -0
  448. package/dist/types/client/behavior/index.d.ts +17 -0
  449. package/dist/types/client/behavior/layer-stack.d.ts +39 -0
  450. package/dist/types/client/behavior/overlay-host/index.d.ts +5 -0
  451. package/dist/types/client/behavior/overlay-host/port.d.ts +55 -0
  452. package/dist/types/client/behavior/overlay-wiring.d.ts +59 -0
  453. package/dist/types/client/behavior/port.d.ts +79 -0
  454. package/dist/types/client/behavior/positioner.d.ts +2 -0
  455. package/dist/types/client/behavior/presence.d.ts +27 -0
  456. package/dist/types/client/behavior/zag/adapter-vanilla.d.ts +2 -0
  457. package/dist/types/client/behavior/zag/layer-bridge.d.ts +15 -0
  458. package/dist/types/client/behavior/zag/machine-host.d.ts +22 -0
  459. package/dist/types/client/behavior/zag/machines.d.ts +23 -0
  460. package/dist/types/client/compiler/manifest-compiler.d.ts +4 -14
  461. package/dist/types/client/component/adapter/adapt.d.ts +9 -0
  462. package/dist/types/client/component/adapter/index.d.ts +3 -0
  463. package/dist/types/client/component/adapter/types.d.ts +33 -0
  464. package/dist/types/client/component/adapter/web-component.d.ts +9 -0
  465. package/dist/types/client/component/component-definition.types.d.ts +23 -5
  466. package/dist/types/client/component/component-expander.d.ts +1 -12
  467. package/dist/types/client/component/component-manager.d.ts +39 -89
  468. package/dist/types/client/component/component-pack.d.ts +21 -54
  469. package/dist/types/client/component/component-registry.d.ts +5 -0
  470. package/dist/types/client/component/projection-admission.d.ts +5 -0
  471. package/dist/types/client/component/projection-registry.d.ts +6 -0
  472. package/dist/types/client/component/projection.types.d.ts +44 -0
  473. package/dist/types/client/component/region-unavailable.d.ts +10 -0
  474. package/dist/types/client/component/scoped-adapter.d.ts +2 -3
  475. package/dist/types/client/container/IContainerAdapter.d.ts +8 -3
  476. package/dist/types/client/container/SomaContainerAdapter.d.ts +7 -10
  477. package/dist/types/client/data/collection-payload.d.ts +1 -0
  478. package/dist/types/client/data/data-object-resolver.d.ts +231 -110
  479. package/dist/types/client/data/data-polling.d.ts +28 -0
  480. package/dist/types/client/data/data-subscriptions.d.ts +20 -0
  481. package/dist/types/client/data/data-write-actions.d.ts +9 -0
  482. package/dist/types/client/data/envelope-failure.d.ts +17 -0
  483. package/dist/types/client/data/format-config.d.ts +13 -0
  484. package/dist/types/client/data/region-scope-port.d.ts +34 -0
  485. package/dist/types/client/data/region-scope-views.d.ts +15 -0
  486. package/dist/types/client/data/role-gate.d.ts +10 -0
  487. package/dist/types/client/data/write-outcome-store.d.ts +23 -0
  488. package/dist/types/client/data/write-outcome.d.ts +48 -0
  489. package/dist/types/client/engine/asset-resolver.d.ts +2 -7
  490. package/dist/types/client/engine/dom-renderer.d.ts +5 -111
  491. package/dist/types/client/engine/event-engine.d.ts +52 -63
  492. package/dist/types/client/engine/locale-text-binder.d.ts +28 -0
  493. package/dist/types/client/engine/property-watcher.d.ts +1 -41
  494. package/dist/types/client/engine/reactive-proxy.d.ts +2 -42
  495. package/dist/types/client/engine/render-engine.d.ts +3 -54
  496. package/dist/types/client/engine/row-range.d.ts +1 -0
  497. package/dist/types/client/engine/runtime-builder.d.ts +7 -3
  498. package/dist/types/client/engine/soma-bootstrap.d.ts +314 -91
  499. package/dist/types/client/engine/step-runner.d.ts +20 -2
  500. package/dist/types/client/engine/style-binder.d.ts +2 -16
  501. package/dist/types/client/engines/chart/adapter-echarts.d.ts +6 -0
  502. package/dist/types/client/engines/chart/index.d.ts +8 -0
  503. package/dist/types/client/engines/chart/kind-modules.d.ts +8 -0
  504. package/dist/types/client/engines/chart/port.d.ts +46 -0
  505. package/dist/types/client/engines/diff/adapter-jsdiff.d.ts +6 -0
  506. package/dist/types/client/engines/diff/index.d.ts +8 -0
  507. package/dist/types/client/engines/diff/port.d.ts +16 -0
  508. package/dist/types/client/engines/dnd/adapter-pragmatic.d.ts +9 -0
  509. package/dist/types/client/engines/dnd/index.d.ts +6 -0
  510. package/dist/types/client/engines/dnd/port.d.ts +33 -0
  511. package/dist/types/client/engines/engine-adapters.d.ts +23 -0
  512. package/dist/types/client/engines/load.d.ts +11 -0
  513. package/dist/types/client/engines/qrcode/adapter-qrcode-generator.d.ts +6 -0
  514. package/dist/types/client/engines/qrcode/index.d.ts +8 -0
  515. package/dist/types/client/engines/qrcode/port.d.ts +16 -0
  516. package/dist/types/client/engines/table/adapter-tanstack.d.ts +6 -0
  517. package/dist/types/client/engines/table/index.d.ts +8 -0
  518. package/dist/types/client/engines/table/port.d.ts +51 -0
  519. package/dist/types/client/engines/temporal/adapter-polyfill.d.ts +6 -0
  520. package/dist/types/client/engines/temporal/index.d.ts +8 -0
  521. package/dist/types/client/engines/temporal/port.d.ts +41 -0
  522. package/dist/types/client/engines/virtual/adapter-tanstack.d.ts +9 -0
  523. package/dist/types/client/engines/virtual/index.d.ts +8 -0
  524. package/dist/types/client/engines/virtual/port.d.ts +33 -0
  525. package/dist/types/client/format/formatter.d.ts +3 -0
  526. package/dist/types/client/format/index.d.ts +2 -0
  527. package/dist/types/client/format/zoned.d.ts +1 -0
  528. package/dist/types/client/host-bridge/index.d.ts +3 -0
  529. package/dist/types/client/host-bridge/resolve-host-bootstrap.d.ts +7 -1
  530. package/dist/types/client/host-bridge/soma-app-host.stub.d.ts +3 -0
  531. package/dist/types/client/host-bridge/soma-bootstrap-from-app.d.ts +9 -0
  532. package/dist/types/client/infra/auth/IAuthService.d.ts +5 -0
  533. package/dist/types/client/infra/auth/TokenAuthService.d.ts +1 -0
  534. package/dist/types/client/infra/config/SomaConfig.d.ts +4 -0
  535. package/dist/types/client/infra/config/feature-flags.d.ts +10 -0
  536. package/dist/types/client/infra/http/IHttpClient.d.ts +4 -0
  537. package/dist/types/client/infra/i18n/II18n.d.ts +17 -1
  538. package/dist/types/client/infra/i18n/builtin-locale.d.ts +11 -0
  539. package/dist/types/client/infra/i18n/index.d.ts +1 -0
  540. package/dist/types/client/infra/i18n/interpolate.d.ts +12 -0
  541. package/dist/types/client/infra/i18n/locale-catalog.d.ts +71 -0
  542. package/dist/types/client/infra/i18n/pack-locales.d.ts +29 -0
  543. package/dist/types/client/infra/identity/identity-port.d.ts +54 -0
  544. package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +29 -7
  545. package/dist/types/client/infra/notify/INotifyService.d.ts +1 -12
  546. package/dist/types/client/infra/notify/notify-declaration.d.ts +10 -0
  547. package/dist/types/client/infra/permission/SomaPermission.d.ts +7 -0
  548. package/dist/types/client/infra/router/IRouter.d.ts +5 -1
  549. package/dist/types/client/infra/router/SomaRouter.d.ts +6 -2
  550. package/dist/types/client/keyboard/collection.d.ts +58 -0
  551. package/dist/types/client/keyboard/compose-keys.d.ts +24 -0
  552. package/dist/types/client/keyboard/cursor.d.ts +48 -0
  553. package/dist/types/client/keyboard/delegate.d.ts +48 -0
  554. package/dist/types/client/keyboard/ime.d.ts +2 -0
  555. package/dist/types/client/keyboard/index.d.ts +10 -0
  556. package/dist/types/client/keyboard/intents.d.ts +35 -0
  557. package/dist/types/client/keyboard/matrix.d.ts +29 -0
  558. package/dist/types/client/keyboard/submit.d.ts +7 -0
  559. package/dist/types/client/keyboard/typeahead.d.ts +28 -0
  560. package/dist/types/client/keyboard/wiring.d.ts +85 -0
  561. package/dist/types/client/middleware/createPermissionMiddleware.d.ts +5 -0
  562. package/dist/types/client/mount/domain-rule.d.ts +17 -0
  563. package/dist/types/client/mount/index.d.ts +3 -0
  564. package/dist/types/client/mount/mount-page.d.ts +11 -0
  565. package/dist/types/client/mount/types.d.ts +100 -0
  566. package/dist/types/client/observability/runtime-observer.d.ts +24 -0
  567. package/dist/types/client/parser/confirm-spec.d.ts +37 -0
  568. package/dist/types/client/parser/data-config-parser.d.ts +23 -17
  569. package/dist/types/client/parser/duration.d.ts +1 -1
  570. package/dist/types/client/parser/page-state-parser.d.ts +1 -6
  571. package/dist/types/client/parser/pipeline-parser.d.ts +7 -12
  572. package/dist/types/client/parser/style-config-parser.d.ts +2 -1
  573. package/dist/types/client/parser/subscribe-parser.d.ts +5 -0
  574. package/dist/types/client/parser/ui-config-parser.d.ts +26 -25
  575. package/dist/types/client/pipes/pipe-registry.d.ts +30 -40
  576. package/dist/types/client/registry/declaration-renderer.d.ts +11 -3
  577. package/dist/types/client/registry/page-lifecycle.d.ts +3 -3
  578. package/dist/types/client/registry/remote-page.d.ts +3 -3
  579. package/dist/types/client/render-ports/index.d.ts +15 -0
  580. package/dist/types/client/render-ports/notify-renderer.d.ts +55 -0
  581. package/dist/types/client/render-ports/region-fallback.d.ts +10 -0
  582. package/dist/types/client/render-ports/scheduling/prompt-queue.d.ts +19 -0
  583. package/dist/types/client/render-ports/scheduling/toast-scheduler.d.ts +60 -0
  584. package/dist/types/client/runtime/SomaRuntimeServices.d.ts +102 -5
  585. package/dist/types/client/runtime/nav-history.d.ts +31 -0
  586. package/dist/types/client/runtime/nav-port.d.ts +12 -0
  587. package/dist/types/client/runtime/shortcuts.d.ts +41 -0
  588. package/dist/types/client/runtime/write-feedback.d.ts +22 -0
  589. package/dist/types/client/runtime-entry.d.ts +13 -0
  590. package/dist/types/client/scheduler/SomaScheduler.d.ts +5 -0
  591. package/dist/types/client/scheduling/flush-scheduler.d.ts +13 -0
  592. package/dist/types/client/scheduling/index.d.ts +4 -0
  593. package/dist/types/client/scheduling/observer-pool.d.ts +15 -0
  594. package/dist/types/client/security/url-guard.d.ts +18 -0
  595. package/dist/types/client/styles/compiled-styles.d.ts +10 -0
  596. package/dist/types/client/styles/index.d.ts +3 -0
  597. package/dist/types/client/styles/pack-styles.d.ts +51 -0
  598. package/dist/types/client/styles/sheet-mount.d.ts +7 -0
  599. package/dist/types/client/styles/style-features.d.ts +26 -0
  600. package/dist/types/client/time/clock.d.ts +10 -0
  601. package/dist/types/client/time/instant.d.ts +1 -0
  602. package/dist/types/client/url-state/index.d.ts +6 -0
  603. package/dist/types/client/url-state/page-tabs-controller.d.ts +22 -0
  604. package/dist/types/client/url-state/state-query-binding.d.ts +22 -0
  605. package/dist/types/client/url-state/url-state.d.ts +47 -0
  606. package/dist/types/client/validation/async-check-registry.d.ts +41 -0
  607. package/dist/types/client/validation/async-rules.d.ts +81 -0
  608. package/dist/types/client/validation/contract-validator.d.ts +10 -0
  609. package/dist/types/client/validation/field-rules.d.ts +6 -0
  610. package/dist/types/client/validation/index.d.ts +5 -0
  611. package/dist/types/client/validation/object-rules.d.ts +22 -0
  612. package/dist/types/index.d.ts +97 -61
  613. package/dist/types/inspect/check-product.d.ts +123 -0
  614. package/dist/types/inspect/check-runtime.d.ts +19 -0
  615. package/dist/types/inspect/runtime.d.ts +39 -0
  616. package/dist/types/page-target/index.d.ts +3 -0
  617. package/dist/types/page-target/provenance.d.ts +20 -0
  618. package/dist/types/page-target/slug.d.ts +7 -0
  619. package/dist/types/page-target/testing/index.d.ts +55 -0
  620. package/dist/types/page-target/types.d.ts +260 -0
  621. package/dist/types/predicates-entry.d.ts +3 -0
  622. package/dist/types/server/compile-port.d.ts +13 -0
  623. package/dist/types/server/diagnostic-gate-entry.d.ts +3 -0
  624. package/dist/types/server/engines/style/candidate-guard.d.ts +14 -0
  625. package/dist/types/server/engines/style/index.d.ts +10 -0
  626. package/dist/types/server/engines/style/port.d.ts +8 -0
  627. package/dist/types/server/engines/style/tailwind-adapter.d.ts +6 -0
  628. package/dist/types/server/host/host-assembly-entry.d.ts +5 -0
  629. package/dist/types/server/host/host-assembly.d.ts +61 -0
  630. package/dist/types/server/host/host-caller.d.ts +10 -0
  631. package/dist/types/server/host/host-config-paths.d.cts +7 -0
  632. package/dist/types/server/host/host-response-headers.d.ts +16 -0
  633. package/dist/types/server/host/locale-yaml.d.ts +3 -0
  634. package/dist/types/server/host/page-markup-config.d.ts +6 -0
  635. package/dist/types/server/host/published-page-artifact-cache.d.ts +99 -22
  636. package/dist/types/server/host/published-page-assets.d.ts +75 -5
  637. package/dist/types/server/host/resolve-host-request-hook.d.ts +0 -4
  638. package/dist/types/server/host/resolve-host-tree-context.d.ts +1 -1
  639. package/dist/types/server/host/server-page-assets.d.ts +29 -3
  640. package/dist/types/server/host/soma-page-compile.d.ts +26 -4
  641. package/dist/types/server/host/source-packages.d.cts +23 -0
  642. package/dist/types/server/host/source-packages.d.ts +15 -2
  643. package/dist/types/server/host/virtual-pages.d.ts +33 -0
  644. package/dist/types/server/index.d.ts +7 -12
  645. package/dist/types/server/node.d.ts +16 -0
  646. package/dist/types/server/page-assets.d.ts +7 -0
  647. package/dist/types/server/page-declaration.d.ts +21 -6
  648. package/dist/types/server/registry/api-registry-store.d.ts +4 -7
  649. package/dist/types/server/registry/asset-store.d.ts +4 -7
  650. package/dist/types/server/registry/batch-publish.d.ts +12 -0
  651. package/dist/types/server/registry/batch-stage.d.ts +24 -0
  652. package/dist/types/server/registry/component-supply.d.ts +6 -0
  653. package/dist/types/server/registry/declaration-precompiler.d.ts +22 -8
  654. package/dist/types/server/registry/index.d.ts +12 -3
  655. package/dist/types/server/registry/page-registry-repository.d.ts +50 -4
  656. package/dist/types/server/registry/page-registry-store.d.ts +227 -33
  657. package/dist/types/server/registry/publish-asset-pin.d.ts +5 -4
  658. package/dist/types/server/registry/registry-file-lock.d.ts +5 -0
  659. package/dist/types/server/registry/registry-subjects.d.ts +2 -2
  660. package/dist/types/server/registry/registry-write-pipeline.d.ts +22 -0
  661. package/dist/types/server/registry/request-body-limit.d.ts +1 -1
  662. package/dist/types/server/registry/rollback-plan.d.ts +58 -0
  663. package/dist/types/server/registry/services/index.d.ts +5 -0
  664. package/dist/types/server/registry/services/pages/Register.d.ts +1 -1
  665. package/dist/types/server/registry/services/pages/RegisterBatch.d.ts +12 -0
  666. package/dist/types/server/registry/services/pages/Rollback.d.ts +4 -1
  667. package/dist/types/server/registry/source/canonical.d.ts +2 -0
  668. package/dist/types/server/registry/source/errors.d.ts +44 -0
  669. package/dist/types/server/registry/source/index.d.ts +7 -0
  670. package/dist/types/server/registry/source/ledger.d.ts +99 -0
  671. package/dist/types/server/registry/source/snapshot.d.ts +6 -0
  672. package/dist/types/server/registry/source/source-name.d.ts +20 -0
  673. package/dist/types/server/registry/source/types.d.ts +89 -0
  674. package/dist/types/server/registry/source/version-store.d.ts +58 -0
  675. package/dist/types/server/registry/standard-product.d.ts +78 -0
  676. package/dist/types/server/registry/validation/compile-gate.d.ts +12 -45
  677. package/dist/types/server/registry/validation/cross-check.d.ts +7 -0
  678. package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +0 -1
  679. package/dist/types/server/registry/validation/region-scopes.d.ts +10 -0
  680. package/dist/types/server/runtime-space/access-gate.d.ts +41 -0
  681. package/dist/types/server/runtime-space/advice-log.d.ts +18 -0
  682. package/dist/types/server/runtime-space/artifact-evict.d.ts +4 -0
  683. package/dist/types/server/runtime-space/bindings.d.ts +115 -0
  684. package/dist/types/server/runtime-space/digest.d.ts +19 -0
  685. package/dist/types/server/runtime-space/dynamic-pages.d.ts +120 -0
  686. package/dist/types/server/runtime-space/errors.d.ts +37 -0
  687. package/dist/types/server/runtime-space/gc.d.ts +6 -0
  688. package/dist/types/server/runtime-space/index.d.ts +19 -0
  689. package/dist/types/server/runtime-space/inject.d.ts +55 -0
  690. package/dist/types/server/runtime-space/nav-catalog.d.ts +33 -0
  691. package/dist/types/server/runtime-space/page-grants.d.ts +90 -0
  692. package/dist/types/server/runtime-space/prewarm.d.ts +60 -0
  693. package/dist/types/server/runtime-space/registry-cold-start.d.ts +4 -0
  694. package/dist/types/server/runtime-space/resolve.d.ts +35 -0
  695. package/dist/types/server/runtime-space/root.d.cts +65 -0
  696. package/dist/types/server/runtime-space/root.d.ts +16 -0
  697. package/dist/types/server/runtime-space/static-source.d.ts +8 -0
  698. package/dist/types/server/runtime-space/store.d.ts +63 -0
  699. package/dist/types/server/runtime-space/submit-steps.d.ts +116 -0
  700. package/dist/types/server/runtime-space/types.d.ts +255 -0
  701. package/dist/types/shared/anchor-space.d.ts +17 -0
  702. package/dist/types/shared/artifact-compatibility.d.ts +75 -0
  703. package/dist/types/shared/behavior-machine-names.d.ts +2 -0
  704. package/dist/types/shared/calc/coerce.d.ts +1 -4
  705. package/dist/types/shared/calc/lexer.d.ts +1 -2
  706. package/dist/types/shared/calc/parser.d.ts +1 -7
  707. package/dist/types/shared/calc/typer.d.ts +1 -6
  708. package/dist/types/shared/component-tree-artifact.d.ts +16 -2
  709. package/dist/types/shared/contract-a11y.d.ts +33 -0
  710. package/dist/types/shared/contract-sections.d.ts +50 -0
  711. package/dist/types/shared/core-diagnostic-codes.d.ts +28 -0
  712. package/dist/types/shared/data-declaration-checks.d.ts +71 -0
  713. package/dist/types/shared/date-parts.d.ts +1 -0
  714. package/dist/types/shared/declaration-errors.d.ts +12 -0
  715. package/dist/types/shared/declaration-keys.d.ts +9 -0
  716. package/dist/types/shared/diagnostic-code-index-entry.d.ts +5 -0
  717. package/dist/types/shared/diagnostic-gate.d.ts +60 -0
  718. package/dist/types/shared/engines/engine-error.d.ts +14 -0
  719. package/dist/types/shared/engines/style/style-engine.types.d.ts +22 -0
  720. package/dist/types/shared/fragments-section.d.ts +2 -0
  721. package/dist/types/shared/generation-diagnostics.d.ts +7 -0
  722. package/dist/types/shared/generation-error.d.ts +20 -0
  723. package/dist/types/shared/hook-attributes.d.ts +220 -0
  724. package/dist/types/shared/inert-data-element.d.ts +14 -0
  725. package/dist/types/shared/nav-back.d.ts +22 -0
  726. package/dist/types/shared/page-access-text.d.ts +4 -0
  727. package/dist/types/shared/page-envelope-runtime.d.ts +32 -0
  728. package/dist/types/shared/page-envelope.d.ts +61 -0
  729. package/dist/types/shared/page-scopes.d.ts +35 -0
  730. package/dist/types/shared/pipeline-error-codes-view.d.ts +11 -0
  731. package/dist/types/shared/pipeline-limits-view.d.ts +8 -0
  732. package/dist/types/shared/predicates/index.d.ts +24 -67
  733. package/dist/types/shared/predicates/relative-window.d.ts +1 -0
  734. package/dist/types/shared/published-page-route.d.ts +3 -5
  735. package/dist/types/shared/region-scope-decl.d.ts +121 -0
  736. package/dist/types/shared/registry-generated/compile-purposes.d.ts +37 -0
  737. package/dist/types/shared/registry-generated/diagnostic-registry-index.d.ts +2 -0
  738. package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +5011 -0
  739. package/dist/types/shared/registry-generated/error-codes.d.ts +115 -0
  740. package/dist/types/shared/registry-generated/index.d.ts +10 -0
  741. package/dist/types/shared/registry-generated/limits.d.ts +461 -0
  742. package/dist/types/shared/registry-generated/platform-keys.d.ts +42 -0
  743. package/dist/types/shared/registry-generated/region-scope.d.ts +511 -0
  744. package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +773 -0
  745. package/dist/types/shared/registry-generated/std-grammar-views.d.ts +203 -0
  746. package/dist/types/shared/registry-generated/std-grammar.d.ts +3515 -0
  747. package/dist/types/shared/rule-step.d.ts +1 -0
  748. package/dist/types/shared/runtime-address.d.ts +70 -0
  749. package/dist/types/shared/scope-decl.d.ts +15 -0
  750. package/dist/types/shared/sha256.d.ts +4 -0
  751. package/dist/types/shared/show-when.d.ts +21 -0
  752. package/dist/types/shared/source-file-suffix.d.ts +2 -0
  753. package/dist/types/shared/std-auth-scan.d.ts +45 -0
  754. package/dist/types/shared/types/choice-confirm.types.d.ts +1 -0
  755. package/dist/types/shared/types/compile-diagnostic.types.d.ts +34 -0
  756. package/dist/types/shared/types/compile-port.types.d.ts +30 -0
  757. package/dist/types/shared/types/component-contract.types.d.ts +134 -129
  758. package/dist/types/shared/types/component-tree-artifact.types.d.ts +16 -2
  759. package/dist/types/shared/types/component-tree.types.d.ts +15 -6
  760. package/dist/types/shared/types/data-config.types.d.ts +175 -191
  761. package/dist/types/shared/types/domain.types.d.ts +20 -5
  762. package/dist/types/shared/types/engine.types.d.ts +2 -0
  763. package/dist/types/shared/types/event.types.d.ts +59 -9
  764. package/dist/types/shared/types/generation-error.types.d.ts +28 -0
  765. package/dist/types/shared/types/host-assembly.types.d.ts +121 -0
  766. package/dist/types/shared/types/locale.types.d.ts +17 -0
  767. package/dist/types/shared/types/manifest.types.d.ts +2 -7
  768. package/dist/types/shared/types/nav-context.types.d.ts +41 -0
  769. package/dist/types/shared/types/nav.types.d.ts +53 -0
  770. package/dist/types/shared/types/notify.types.d.ts +37 -0
  771. package/dist/types/shared/types/observation.types.d.ts +72 -0
  772. package/dist/types/shared/types/page-envelope.types.d.ts +98 -0
  773. package/dist/types/shared/types/page-state.types.d.ts +17 -33
  774. package/dist/types/shared/types/region-scope.types.d.ts +150 -0
  775. package/dist/types/shared/types/registry-batch.types.d.ts +48 -0
  776. package/dist/types/shared/types/shortcuts.types.d.ts +67 -0
  777. package/dist/types/shared/types/source.types.d.ts +10 -0
  778. package/dist/types/shared/types/style-config.types.d.ts +0 -19
  779. package/dist/types/shared/types/temporal.types.d.ts +1 -0
  780. package/dist/types/shared/types/ui-config.types.d.ts +77 -148
  781. package/dist/types/shared/types/write-outcome-view.types.d.ts +19 -0
  782. package/dist/types/shared/types/write-runtime.types.d.ts +1 -0
  783. package/dist/types/shared/types/write.types.d.ts +70 -0
  784. package/global.d.ts +2 -10
  785. package/host-next/app/SomaPageClient.tsx +359 -0
  786. package/host-next/app/api/[...path]/route.ts +98 -0
  787. package/host-next/app/api/soma-registry/[...path]/route.ts +79 -0
  788. package/host-next/app/components/SomaPageForbidden.tsx +19 -0
  789. package/host-next/app/globals.css +177 -0
  790. package/host-next/app/page-access.ts +47 -0
  791. package/host-next/app/router-bridge.ts +42 -0
  792. package/host-next/app/soma/_shared/host-prepare.ts +33 -0
  793. package/host-next/app/soma/_shared/page-http.ts +86 -0
  794. package/host-next/app/soma/manifest/route.ts +98 -0
  795. package/host-next/app/soma/page/route.ts +36 -0
  796. package/host-next/app/soma-runtime/[...file]/route.ts +21 -0
  797. package/host-next/app/soma-runtime/_shared/static-file.ts +89 -0
  798. package/host-next/bin/host-next.cjs +59 -0
  799. package/host-next/instrumentation.ts +13 -0
  800. package/host-next/next-env.d.ts +7 -0
  801. package/host-next/next.config.js +382 -0
  802. package/host-next/proxy.ts +43 -0
  803. package/host-next/src/shell-routes.cjs +51 -0
  804. package/host-next/src/workspace.ts +543 -0
  805. package/package.json +238 -59
  806. package/tsconfig.json +4 -11
  807. package/app/SomaPageClient.tsx +0 -313
  808. package/app/api/[...path]/route.ts +0 -86
  809. package/app/api/soma-registry/[...path]/route.ts +0 -67
  810. package/app/globals.css +0 -126
  811. package/app/soma/manifest/route.ts +0 -43
  812. package/app/soma/page/route.ts +0 -44
  813. package/app/soma/page-object/route.ts +0 -159
  814. package/bin/component.cjs +0 -240
  815. package/bin/migrate.cjs +0 -432
  816. package/bin/soma-db.cjs +0 -13
  817. package/bin/soma-mock.mjs +0 -38
  818. package/bin/soma-sync.cjs +0 -3
  819. package/core/build/blocks/block-compile.ts +0 -373
  820. package/core/build/blocks/block-container.ts +0 -207
  821. package/core/build/blocks/block-loader.ts +0 -33
  822. package/core/build/blocks/html-index.ts +0 -120
  823. package/core/build/blocks/migrate-flat.ts +0 -463
  824. package/core/build/compiler/precompiled-manifest-loader.ts +0 -41
  825. package/core/build/component/pack-from-dir.ts +0 -58
  826. package/core/build/component/package-loader.ts +0 -358
  827. package/core/build/component-tree/binding-bridge.ts +0 -272
  828. package/core/build/component-tree/migration-files.ts +0 -214
  829. package/core/build/component-tree/migration.ts +0 -170
  830. package/core/build/component-tree/validator.ts +0 -318
  831. package/core/build/db/cli.ts +0 -10
  832. package/core/build/db/emit-entities.ts +0 -45
  833. package/core/build/db/emit-mappers.ts +0 -175
  834. package/core/build/db/emit-prisma-schema.ts +0 -92
  835. package/core/build/db/generate.ts +0 -166
  836. package/core/build/db/ir.ts +0 -75
  837. package/core/build/db/load-db-yaml.ts +0 -241
  838. package/core/build/eject/component-eject.ts +0 -480
  839. package/core/build/eject/component-upgrade.ts +0 -359
  840. package/core/build/layout/constraint-solver.ts +0 -350
  841. package/core/build/layout/css-emitter.ts +0 -135
  842. package/core/build/layout/page-layout.ts +0 -85
  843. package/core/build/ooui/artifact/artifact.types.ts +0 -275
  844. package/core/build/ooui/artifact/emit-artifact.ts +0 -269
  845. package/core/build/ooui/artifact/emit-html.ts +0 -204
  846. package/core/build/ooui/artifact/index.ts +0 -53
  847. package/core/build/ooui/artifact/spatial-tree.ts +0 -268
  848. package/core/build/ooui/artifact/utility-class.ts +0 -83
  849. package/core/build/ooui/composition/candidate.types.ts +0 -323
  850. package/core/build/ooui/composition/control-model.ts +0 -114
  851. package/core/build/ooui/composition/registry.ts +0 -520
  852. package/core/build/ooui/composition/select.ts +0 -232
  853. package/core/build/ooui/diagnostics/codes.ts +0 -230
  854. package/core/build/ooui/diagnostics/error.ts +0 -235
  855. package/core/build/ooui/diagnostics/format.ts +0 -106
  856. package/core/build/ooui/diagnostics/index.ts +0 -62
  857. package/core/build/ooui/diagnostics/issue.types.ts +0 -112
  858. package/core/build/ooui/engine-slot.ts +0 -184
  859. package/core/build/ooui/index.ts +0 -1427
  860. package/core/build/ooui/intent/derive-intent.ts +0 -450
  861. package/core/build/ooui/intent/field-rules.ts +0 -330
  862. package/core/build/ooui/intent/intent.types.ts +0 -476
  863. package/core/build/ooui/intent/verb-events.ts +0 -285
  864. package/core/build/ooui/page/budget.ts +0 -503
  865. package/core/build/ooui/page/compose-page.ts +0 -736
  866. package/core/build/ooui/page/index.ts +0 -66
  867. package/core/build/ooui/page/page.types.ts +0 -402
  868. package/core/build/ooui/page/region-row.ts +0 -241
  869. package/core/build/ooui/semantic/expand-page-surface.ts +0 -180
  870. package/core/build/ooui/semantic/kernel.types.ts +0 -187
  871. package/core/build/ooui/semantic/normalize.ts +0 -784
  872. package/core/build/ooui/semantic/origin.types.ts +0 -211
  873. package/core/build/ooui/semantic/role-alias.ts +0 -154
  874. package/core/build/ooui/semantic/shorthand.ts +0 -233
  875. package/core/build/ooui/semantic/surface.types.ts +0 -78
  876. package/core/build/ooui/semantic/validate-request.ts +0 -267
  877. package/core/build/ooui/spatial/emit-utility.ts +0 -480
  878. package/core/build/ooui/spatial/ir.types.ts +0 -443
  879. package/core/build/ooui/spatial/registry.ts +0 -565
  880. package/core/build/ooui/spatial/solve.ts +0 -769
  881. package/core/build/ooui/spatial/utility.types.ts +0 -242
  882. package/core/build/ooui/trace/index.ts +0 -40
  883. package/core/build/ooui/trace/render.ts +0 -190
  884. package/core/build/ooui/trace/source.types.ts +0 -69
  885. package/core/build/ooui/trace/trace.types.ts +0 -326
  886. package/core/build/pack/pack-init.ts +0 -270
  887. package/core/client/adaptive/flush-scheduler.ts +0 -96
  888. package/core/client/adaptive/hysteresis.ts +0 -56
  889. package/core/client/adaptive/index.ts +0 -23
  890. package/core/client/adaptive/observer-pool.ts +0 -204
  891. package/core/client/compiler/adaptive-compile.ts +0 -136
  892. package/core/client/component/ai-catalog.ts +0 -432
  893. package/core/client/component/catalog-examples.ts +0 -60
  894. package/core/client/component/contract-compat.ts +0 -161
  895. package/core/client/component/example-blocks.ts +0 -126
  896. package/core/client/component/keyboard-matrix.ts +0 -144
  897. package/core/client/component/pack-styles.ts +0 -152
  898. package/core/client/component/style-features.ts +0 -131
  899. package/core/client/component/theme-component-tokens.ts +0 -80
  900. package/core/client/component/verify-pack.ts +0 -429
  901. package/core/client/container/MiniProgramContainerAdapter.ts +0 -204
  902. package/core/client/container/ReactNativeContainerAdapter.ts +0 -203
  903. package/core/client/data/reaction-engine.ts +0 -176
  904. package/core/client/data/window-engine.ts +0 -477
  905. package/core/client/infra/i18n/DefaultI18n.ts +0 -29
  906. package/core/client/infra/notify/DomNotifyService.ts +0 -99
  907. package/core/client/infra/notify/INotifyTheme.ts +0 -22
  908. package/core/client/parser/adaptive-parser.ts +0 -264
  909. package/core/client/parser/blocks/namespace.ts +0 -207
  910. package/core/client/parser/blocks/page-parser.ts +0 -466
  911. package/core/client/parser/blocks/use-parser.ts +0 -646
  912. package/core/client/parser/layout-parser.ts +0 -158
  913. package/core/client/parser/reaction-parser.ts +0 -458
  914. package/core/client/parser/reaction-sugar.ts +0 -47
  915. package/core/client/parser/window-parser.ts +0 -294
  916. package/core/client/quality/SomaQualityRegistry.ts +0 -71
  917. package/core/client/runtime/serialize-page-state.ts +0 -152
  918. package/core/client/theme/harmony.ts +0 -429
  919. package/core/client/theme/scene-tokens.ts +0 -155
  920. package/core/client/theme/theme-axes.ts +0 -323
  921. package/core/client/theme/theme-engine.ts +0 -2390
  922. package/core/client/theme/tone-solver.ts +0 -119
  923. package/core/client/typography/typography-base.ts +0 -34
  924. package/core/server/headless/soma-headless-page.ts +0 -103
  925. package/core/server/host/page-response-mode.cjs +0 -96
  926. package/core/server/host/page-response-request.ts +0 -33
  927. package/core/server/host/request-origin.ts +0 -18
  928. package/core/server/host/soma-request-hook-host.stub.ts +0 -4
  929. package/core/server/infra/db/errors.ts +0 -11
  930. package/core/server/infra/db/mapper/PrismaSomaMapper.ts +0 -313
  931. package/core/server/infra/db/mapper/SomaBaseMapper.ts +0 -23
  932. package/core/server/infra/db/mapper/SomaMapperHooks.ts +0 -13
  933. package/core/server/infra/db/query/SomaQuery.ts +0 -149
  934. package/core/server/infra/db/service/SomaDbService.ts +0 -64
  935. package/core/server/infra/db/soma-db.ts +0 -120
  936. package/core/server/infra/db/types.ts +0 -21
  937. package/core/server/mock/node/catch-all.mjs +0 -35
  938. package/core/server/mock/node/cli.d.mts +0 -58
  939. package/core/server/mock/node/cli.mjs +0 -244
  940. package/core/server/mock/node/context.mjs +0 -167
  941. package/core/server/mock/node/environment-policy.mjs +0 -52
  942. package/core/server/mock/node/plugin-loader.mjs +0 -212
  943. package/core/server/mock/node/preload.mjs +0 -91
  944. package/core/server/mock/node/process-lifecycle.mjs +0 -236
  945. package/core/server/mock/node/public.d.mts +0 -110
  946. package/core/server/mock/node/public.mjs +0 -4
  947. package/core/server/mock/node/registry.mjs +0 -336
  948. package/core/server/mock/node/schema-generator.mjs +0 -1309
  949. package/core/server/mock/testing/host-harness.d.mts +0 -66
  950. package/core/server/mock/testing/host-harness.mjs +0 -276
  951. package/core/server/mock/testing/host-runtime.mjs +0 -48
  952. package/core/server/ooui.ts +0 -34
  953. package/core/shared/block-errors.ts +0 -11
  954. package/core/shared/component/derive-sample.ts +0 -290
  955. package/core/shared/component/field-lines.ts +0 -563
  956. package/core/shared/container-breakpoints.ts +0 -46
  957. package/core/shared/object-semantics.ts +0 -240
  958. package/core/shared/ooui-declaration.ts +0 -235
  959. package/core/shared/path-algebra.ts +0 -169
  960. package/core/shared/types/adaptive.types.ts +0 -109
  961. package/core/shared/types/layout-constraint.types.ts +0 -89
  962. package/core/shared/types/reaction.types.ts +0 -144
  963. package/core/shared/types/window.types.ts +0 -177
  964. package/dist/types/build/blocks/block-compile.d.ts +0 -52
  965. package/dist/types/build/blocks/block-container.d.ts +0 -40
  966. package/dist/types/build/blocks/block-loader.d.ts +0 -9
  967. package/dist/types/build/blocks/html-index.d.ts +0 -37
  968. package/dist/types/build/blocks/migrate-flat.d.ts +0 -49
  969. package/dist/types/build/compiler/precompiled-manifest-loader.d.ts +0 -5
  970. package/dist/types/build/component/pack-from-dir.d.ts +0 -17
  971. package/dist/types/build/component/package-loader.d.ts +0 -50
  972. package/dist/types/build/component-tree/binding-bridge.d.ts +0 -19
  973. package/dist/types/build/component-tree/migration-files.d.ts +0 -35
  974. package/dist/types/build/component-tree/migration.d.ts +0 -28
  975. package/dist/types/build/component-tree/validator.d.ts +0 -9
  976. package/dist/types/build/db/cli.d.ts +0 -2
  977. package/dist/types/build/db/emit-entities.d.ts +0 -5
  978. package/dist/types/build/db/emit-mappers.d.ts +0 -15
  979. package/dist/types/build/db/emit-prisma-schema.d.ts +0 -2
  980. package/dist/types/build/db/generate.d.ts +0 -7
  981. package/dist/types/build/db/ir.d.ts +0 -58
  982. package/dist/types/build/db/load-db-yaml.d.ts +0 -14
  983. package/dist/types/build/eject/component-eject.d.ts +0 -121
  984. package/dist/types/build/eject/component-upgrade.d.ts +0 -43
  985. package/dist/types/build/layout/constraint-solver.d.ts +0 -78
  986. package/dist/types/build/layout/css-emitter.d.ts +0 -18
  987. package/dist/types/build/layout/page-layout.d.ts +0 -24
  988. package/dist/types/build/ooui/artifact/artifact.types.d.ts +0 -180
  989. package/dist/types/build/ooui/artifact/emit-artifact.d.ts +0 -58
  990. package/dist/types/build/ooui/artifact/emit-html.d.ts +0 -53
  991. package/dist/types/build/ooui/artifact/index.d.ts +0 -5
  992. package/dist/types/build/ooui/artifact/spatial-tree.d.ts +0 -48
  993. package/dist/types/build/ooui/artifact/utility-class.d.ts +0 -46
  994. package/dist/types/build/ooui/composition/candidate.types.d.ts +0 -206
  995. package/dist/types/build/ooui/composition/control-model.d.ts +0 -37
  996. package/dist/types/build/ooui/composition/registry.d.ts +0 -66
  997. package/dist/types/build/ooui/composition/select.d.ts +0 -63
  998. package/dist/types/build/ooui/diagnostics/codes.d.ts +0 -28
  999. package/dist/types/build/ooui/diagnostics/error.d.ts +0 -135
  1000. package/dist/types/build/ooui/diagnostics/format.d.ts +0 -51
  1001. package/dist/types/build/ooui/diagnostics/index.d.ts +0 -25
  1002. package/dist/types/build/ooui/diagnostics/issue.types.d.ts +0 -56
  1003. package/dist/types/build/ooui/engine-slot.d.ts +0 -41
  1004. package/dist/types/build/ooui/index.d.ts +0 -286
  1005. package/dist/types/build/ooui/intent/derive-intent.d.ts +0 -32
  1006. package/dist/types/build/ooui/intent/field-rules.d.ts +0 -99
  1007. package/dist/types/build/ooui/intent/intent.types.d.ts +0 -318
  1008. package/dist/types/build/ooui/intent/verb-events.d.ts +0 -70
  1009. package/dist/types/build/ooui/page/budget.d.ts +0 -28
  1010. package/dist/types/build/ooui/page/compose-page.d.ts +0 -41
  1011. package/dist/types/build/ooui/page/index.d.ts +0 -4
  1012. package/dist/types/build/ooui/page/page.types.d.ts +0 -264
  1013. package/dist/types/build/ooui/page/region-row.d.ts +0 -16
  1014. package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +0 -33
  1015. package/dist/types/build/ooui/semantic/kernel.types.d.ts +0 -125
  1016. package/dist/types/build/ooui/semantic/normalize.d.ts +0 -45
  1017. package/dist/types/build/ooui/semantic/origin.types.d.ts +0 -95
  1018. package/dist/types/build/ooui/semantic/role-alias.d.ts +0 -35
  1019. package/dist/types/build/ooui/semantic/shorthand.d.ts +0 -60
  1020. package/dist/types/build/ooui/semantic/surface.types.d.ts +0 -16
  1021. package/dist/types/build/ooui/semantic/validate-request.d.ts +0 -19
  1022. package/dist/types/build/ooui/spatial/emit-utility.d.ts +0 -43
  1023. package/dist/types/build/ooui/spatial/ir.types.d.ts +0 -280
  1024. package/dist/types/build/ooui/spatial/registry.d.ts +0 -110
  1025. package/dist/types/build/ooui/spatial/solve.d.ts +0 -42
  1026. package/dist/types/build/ooui/spatial/utility.types.d.ts +0 -191
  1027. package/dist/types/build/ooui/trace/index.d.ts +0 -3
  1028. package/dist/types/build/ooui/trace/render.d.ts +0 -42
  1029. package/dist/types/build/ooui/trace/source.types.d.ts +0 -25
  1030. package/dist/types/build/ooui/trace/trace.types.d.ts +0 -143
  1031. package/dist/types/build/pack/pack-init.d.ts +0 -8
  1032. package/dist/types/client/adaptive/flush-scheduler.d.ts +0 -13
  1033. package/dist/types/client/adaptive/hysteresis.d.ts +0 -16
  1034. package/dist/types/client/adaptive/index.d.ts +0 -5
  1035. package/dist/types/client/adaptive/observer-pool.d.ts +0 -22
  1036. package/dist/types/client/compiler/adaptive-compile.d.ts +0 -26
  1037. package/dist/types/client/component/ai-catalog.d.ts +0 -122
  1038. package/dist/types/client/component/catalog-examples.d.ts +0 -18
  1039. package/dist/types/client/component/contract-compat.d.ts +0 -16
  1040. package/dist/types/client/component/example-blocks.d.ts +0 -7
  1041. package/dist/types/client/component/keyboard-matrix.d.ts +0 -24
  1042. package/dist/types/client/component/pack-styles.d.ts +0 -43
  1043. package/dist/types/client/component/style-features.d.ts +0 -26
  1044. package/dist/types/client/component/theme-component-tokens.d.ts +0 -17
  1045. package/dist/types/client/component/verify-pack.d.ts +0 -24
  1046. package/dist/types/client/container/MiniProgramContainerAdapter.d.ts +0 -52
  1047. package/dist/types/client/container/ReactNativeContainerAdapter.d.ts +0 -47
  1048. package/dist/types/client/data/reaction-engine.d.ts +0 -21
  1049. package/dist/types/client/data/window-engine.d.ts +0 -27
  1050. package/dist/types/client/infra/i18n/DefaultI18n.d.ts +0 -7
  1051. package/dist/types/client/infra/notify/DomNotifyService.d.ts +0 -17
  1052. package/dist/types/client/infra/notify/INotifyTheme.d.ts +0 -12
  1053. package/dist/types/client/parser/adaptive-parser.d.ts +0 -28
  1054. package/dist/types/client/parser/blocks/namespace.d.ts +0 -72
  1055. package/dist/types/client/parser/blocks/page-parser.d.ts +0 -30
  1056. package/dist/types/client/parser/blocks/use-parser.d.ts +0 -124
  1057. package/dist/types/client/parser/layout-parser.d.ts +0 -9
  1058. package/dist/types/client/parser/reaction-parser.d.ts +0 -16
  1059. package/dist/types/client/parser/reaction-sugar.d.ts +0 -13
  1060. package/dist/types/client/parser/window-parser.d.ts +0 -25
  1061. package/dist/types/client/quality/SomaQualityRegistry.d.ts +0 -31
  1062. package/dist/types/client/runtime/serialize-page-state.d.ts +0 -10
  1063. package/dist/types/client/theme/harmony.d.ts +0 -119
  1064. package/dist/types/client/theme/scene-tokens.d.ts +0 -41
  1065. package/dist/types/client/theme/theme-axes.d.ts +0 -174
  1066. package/dist/types/client/theme/theme-engine.d.ts +0 -119
  1067. package/dist/types/client/theme/tone-solver.d.ts +0 -51
  1068. package/dist/types/client/typography/typography-base.d.ts +0 -15
  1069. package/dist/types/server/headless/soma-headless-page.d.ts +0 -12
  1070. package/dist/types/server/host/page-response-request.d.ts +0 -8
  1071. package/dist/types/server/host/request-origin.d.ts +0 -1
  1072. package/dist/types/server/host/soma-request-hook-host.stub.d.ts +0 -2
  1073. package/dist/types/server/infra/db/errors.d.ts +0 -5
  1074. package/dist/types/server/infra/db/mapper/PrismaSomaMapper.d.ts +0 -77
  1075. package/dist/types/server/infra/db/mapper/SomaBaseMapper.d.ts +0 -20
  1076. package/dist/types/server/infra/db/mapper/SomaMapperHooks.d.ts +0 -12
  1077. package/dist/types/server/infra/db/query/SomaQuery.d.ts +0 -42
  1078. package/dist/types/server/infra/db/service/SomaDbService.d.ts +0 -24
  1079. package/dist/types/server/infra/db/soma-db.d.ts +0 -45
  1080. package/dist/types/server/infra/db/types.d.ts +0 -18
  1081. package/dist/types/server/ooui.d.ts +0 -18
  1082. package/dist/types/shared/block-errors.d.ts +0 -5
  1083. package/dist/types/shared/component/derive-sample.d.ts +0 -37
  1084. package/dist/types/shared/component/field-lines.d.ts +0 -19
  1085. package/dist/types/shared/container-breakpoints.d.ts +0 -42
  1086. package/dist/types/shared/object-semantics.d.ts +0 -42
  1087. package/dist/types/shared/ooui-declaration.d.ts +0 -135
  1088. package/dist/types/shared/path-algebra.d.ts +0 -56
  1089. package/dist/types/shared/types/adaptive.types.d.ts +0 -88
  1090. package/dist/types/shared/types/layout-constraint.types.d.ts +0 -53
  1091. package/dist/types/shared/types/reaction.types.d.ts +0 -115
  1092. package/dist/types/shared/types/window.types.d.ts +0 -171
  1093. package/next.config.js +0 -387
  1094. package/proxy.ts +0 -62
  1095. /package/{app → host-next/app}/[...path]/page.tsx +0 -0
  1096. /package/{app → host-next/app}/components/SomaHostPage.tsx +0 -0
  1097. /package/{app → host-next/app}/components/SomaHydrationShell.tsx +0 -0
  1098. /package/{app → host-next/app}/components/SomaPageClientBoundary.tsx +0 -0
  1099. /package/{app → host-next/app}/favicon.ico/route.ts +0 -0
  1100. /package/{app → host-next/app}/layout.tsx +0 -0
  1101. /package/{app → host-next/app}/page.tsx +0 -0
  1102. /package/{app → host-next/app}/soma/[...path]/route.ts +0 -0
  1103. /package/{app → host-next/app}/soma/route.ts +0 -0
@@ -1,6 +1,8 @@
1
1
  // core/client/engine/soma-bootstrap.ts
2
2
  // 职责:生命周期编排(唯一职责)
3
3
 
4
+ import type { SomaRenderPorts } from '../render-ports';
5
+ import type { SomaEngineAdapters } from '../engines/engine-adapters';
4
6
  import { SomaContainerAdapter } from '../container/SomaContainerAdapter';
5
7
  import type { IContainerAdapter } from '../container/IContainerAdapter';
6
8
  import { SomaDiagnostics, type SomaDiagnosticsSnapshot } from '../diagnostics/SomaDiagnostics';
@@ -9,16 +11,22 @@ import { setActiveTelemetry, recordMetric } from '../diagnostics/telemetry-conte
9
11
  import { markBootPhase, maybeStartBootTimings } from '../diagnostics/boot-timings';
10
12
  import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
11
13
  import { SomaScheduler } from '../scheduler/SomaScheduler';
12
- import type { ParsedEvent } from '../../shared/types/event.types';
14
+ import type { ParsedEvent, SomaConfirmSpec } from '../../shared/types/event.types';
13
15
  import type { PropertyTrigger } from '../../shared/types/trigger.types';
14
16
  import type { ParsedTimer } from '../../shared/types/timer.types';
15
17
  import type { StyleConfig } from '../../shared/types/style-config.types';
16
- import type { UiConfig } from '../../shared/types/ui-config.types';
17
- import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
18
- import type { SomaPageRoot } from '../../shared/types/domain.types';
18
+ import type { SomaCompiledStyle, UiConfig } from '../../shared/types/ui-config.types';
19
+ import type { SomaPageRoot as SharedPageRoot } from '../../shared/types/domain.types';
20
+ import type { SomaRuntimeServices } from '../runtime/SomaRuntimeServices';
21
+
22
+ import { createClock } from '../time/clock';
23
+ import type { SomaClockPort } from '../../shared/types/temporal.types';
24
+
25
+ /** 引擎内部视角的页面根:`_services` 是完整的运行期服务表(shared 层只认最小接口,AD-65 / C-int) */
26
+ type SomaPageRoot = SharedPageRoot<SomaRuntimeServices>;
19
27
  import { SomaSnapshotStore } from '../runtime/SomaSnapshotStore';
20
28
  import { SomaAssetResolver } from './asset-resolver';
21
- import type { SomaEventMiddlewareContext } from './event-engine';
29
+ import type { SomaEventMiddlewareContext, SomaScopeEventHandler } from './event-engine';
22
30
  import { SomaReactiveProxy } from './reactive-proxy';
23
31
  import type { SomaRenderEngine, SomaRenderMiddlewareContext } from './render-engine';
24
32
  import type { SomaEventEngine } from './event-engine';
@@ -31,27 +39,55 @@ import type { SomaOnChangeEngine } from './on-change-engine';
31
39
  import type { SomaTriggerEngine } from './trigger-engine';
32
40
  import type { SomaTimerEngine } from './timer-engine';
33
41
  import { createDefaultRuntimeServices } from '../runtime/SomaRuntimeServices';
42
+ import type { SomaIdentityProvider } from '../infra/identity/identity-port';
34
43
  import { getBrowserUrlPath, readQueryParam } from '../infra/router/router-path';
35
44
  import { parseDataYaml } from '../parser/data-config-parser';
36
- import { SomaDataObjectResolver, createSomaDataPort } from '../data/data-object-resolver';
45
+ import { createDataWriteActions } from '../data/data-write-actions';
46
+ import { SomaDataObjectResolver } from '../data/data-object-resolver';
47
+ import { attachDataSubscriptions, type SomaDataSubscriptionHandle } from '../data/data-subscriptions';
48
+ import { attachDataPolling, type SomaDataPollingHandle } from '../data/data-polling';
49
+ import { createWriteOutcomeStore, type SomaWriteOutcomeStore } from '../data/write-outcome-store';
37
50
  import type { SomaDataPort } from '../../shared/types/data-config.types';
38
51
  import type { SomaDataConfig, SomaDataDicts } from '../../shared/types/data-config.types';
39
52
  import type { WatchCallback, WatcherOptions } from '../../shared/types/watcher.types';
40
53
  import type { SomaStepGraph } from '../../shared/types/step.types';
41
54
  import type { SomaPageState, SomaPageStateConfig } from '../../shared/types/page-state.types';
42
55
  import { decodePageState, encodePageState, parseStateValue } from '../parser/page-state-parser';
43
- import { injectStyleOnce } from '../component/pack-styles';
56
+ import { injectStyleOnce } from '../styles/pack-styles';
57
+ import { installCompiledStyles } from '../styles/compiled-styles';
58
+ import { SomaUiConfigError } from '../parser/ui-config-parser';
59
+ import { SomaLocaleCatalog, type SomaLocaleMissingEvent } from '../infra/i18n/locale-catalog';
60
+ import { SOMA_BUILTIN_LOCALE } from '../infra/i18n/builtin-locale';
61
+ import { createLocaleTextBinder, type SomaLocaleTextBinder } from './locale-text-binder';
62
+ import { createRegionScopeStore } from '../data/region-scope-port';
63
+ import type { SomaShortcutRegistry } from '../../shared/types/write-runtime.types';
64
+ import { createShortcutRegistry, shortcutsDesign } from '../runtime/shortcuts';
65
+ import { bindRegionScopeViews } from '../data/region-scope-views';
66
+ import { checkPageScopes, scopeIssueDiagnostics } from '../../shared/region-scope-decl';
67
+ import { formatGenerationError } from '../../shared/generation-error';
68
+ import type { SomaAuthOption } from '../data/role-gate';
69
+ import { isLocaleBundle, type SomaLocaleBundle } from '../../shared/types/locale.types';
70
+ import { coreDiagnostic } from '../../shared/core-diagnostic-codes';
71
+ import { SOMA_COMPONENT_ATTR, SOMA_CORE_HOOK_ATTRIBUTES, SOMA_FRAGMENT_ATTR, SOMA_HOST_ATTR, SOMA_ID_ATTR, SOMA_OPAQUE_ATTRIBUTE_REGISTRY, SOMA_REPEAT_TEMPLATE_ATTR, SOMA_ROLE_ATTR, SOMA_SLOT_ATTR } from '../../shared/hook-attributes';
72
+
73
+ import {
74
+ createRuntimeObserver,
75
+ NOOP_OBSERVATION_CHANNEL,
76
+ type SomaRuntimeObserver,
77
+ } from '../observability/runtime-observer';
78
+ import type { RuntimeObservation } from '../../shared/types/observation.types';
44
79
  import type { SomaComponentDefinition } from '../component/component-definition.types';
45
80
  import { SomaComponentRegistry } from '../component/component-registry';
46
- import { SomaComponentManager, warnSubscriptionsWithoutComponents } from '../component/component-manager';
81
+ import { SomaComponentManager } from '../component/component-manager';
82
+ import { applyDegradedRegions } from '../component/region-unavailable';
83
+ import { SOMA_ANCHOR_SITE_PAGE, anchorDuplicateMessage, anchorSiteOfFragment } from '../../shared/anchor-space';
84
+ import { SomaLocaleOnlyPageRoot } from '../base/SomaLocaleOnlyPageRoot';
47
85
  import {
48
86
  validateComponentDefaults,
49
87
  type SomaComponentDefaults,
50
88
  } from '../component/component-defaults';
51
- import { validateStyleFeatures } from '../component/style-features';
89
+ import { validateStyleFeatures } from '../styles/style-features';
52
90
  import { SomaPipeRegistry, type SomaPipeFn } from '../pipes/pipe-registry';
53
- import { applyTheme, type SomaThemeInput } from '../theme/theme-engine';
54
- import { validateThemeComponentTokens } from '../component/theme-component-tokens';
55
91
  import {
56
92
  installSomaErrorReporter,
57
93
  type SomaErrorEvent,
@@ -60,22 +96,44 @@ import {
60
96
  } from '../observability/error-reporter';
61
97
 
62
98
  // ─── 类型定义 ──────────────────────────────────────────
99
+ import { createFormatter, type SomaFormatter } from '../format';
100
+ import { parseFormatAppConfig, type SomaFormatDefaults } from '../data/format-config';
101
+ import { registerComponentPackLocales, validatePackLocales, type PackWithLocales } from '../infra/i18n/pack-locales';
63
102
  import { assertRuntimeArtifact } from '../../shared/component-tree-artifact';
103
+ import { checkArtifactRuntimeCompatibility, supplyFromDefinitions } from '../../shared/artifact-compatibility';
64
104
  import { SomaComponentTreeError } from '../../shared/component-tree-errors';
65
105
  import type { ComponentTreeRuntimeEnvelope } from '../../shared/types/component-tree-artifact.types';
106
+ import { createUrlStatePort } from '../url-state/url-state';
107
+ import { bindStateQuery } from '../url-state/state-query-binding';
108
+ import { queryBindingsFromContract } from '../../shared/page-envelope-runtime';
109
+ import type { SomaEnvelopeQuerySpec } from '../../shared/types/page-envelope.types';
110
+ import type { SomaNavView } from '../../shared/types/nav.types';
111
+ import { createNavStore } from '../runtime/nav-port';
112
+ import { installMotionHook } from '../a11y/motion-hook';
113
+ import { createNavHistory, type SomaNavHistory } from '../runtime/nav-history';
114
+ import type { SomaNavHistoryPort } from '../../shared/types/nav-context.types';
115
+ import { parseA11yAppConfig } from '../a11y/a11y-config';
116
+ import {
117
+ createAsyncCheckService,
118
+ findUnregisteredAsyncChecks,
119
+ unregisteredAsyncCheckError,
120
+ type SomaAsyncCheckTable,
121
+ type SomaValidationService,
122
+ } from '../validation/async-check-registry';
66
123
 
67
124
  export interface SomaPageAssets extends ComponentTreeRuntimeEnvelope {
68
125
  html: string;
69
126
  includes?: Record<string, string>;
70
- DomainClass: new () => SomaPageRoot;
127
+ /**
128
+ * 页面根类。可省(06e AD-CORE-19):无业务类的页面缺省实例化 `SomaLocaleOnlyPageRoot`(空页面根,只承载
129
+ * `_locale` / `_config` / `_services` / `data`)。
130
+ */
131
+ DomainClass?: new () => SharedPageRoot;
71
132
 
72
133
  // ── 编译后的运行时资产(源声明不得直接进入浏览器) ──
73
134
  uiYaml?: string;
74
- /** 仅供构建/测试入口携带的外置声明块;mount 本身不读取。 */
75
- declarationBlocks?: ReadonlyMap<string, string>;
76
135
  eventYaml?: string;
77
136
  styleYaml?: string;
78
- localeYaml?: string;
79
137
  appConfigYaml?: string;
80
138
  /**
81
139
  * 从统一声明编译出的数据对象运行时资产。
@@ -91,14 +149,40 @@ export interface SomaPageAssets extends ComponentTreeRuntimeEnvelope {
91
149
  triggerConfig?: PropertyTrigger[];
92
150
  timerConfig?: ParsedTimer[];
93
151
  styleConfig?: StyleConfig;
94
- locale?: Record<string, unknown>;
152
+ /**
153
+ * 多语言词表(KC2,`format: 'soma.locale-bundle'`);只认词表信封(空对象 = 无词表)。
154
+ * 运行期按当前显示语言渲染文案,切换不重编、不换产物(`setLocale`)。
155
+ * 与注入载荷同名同形:可给词表文本(YAML 字符串,运行期解析)或已解析对象。
156
+ */
157
+ locale?: string | SomaLocaleBundle | Record<string, unknown>;
158
+ /** 应用配置;不携带 `theme` 段(编译器消费后剥离),core 不按具名段访问(KI-6) */
95
159
  appConfig?: unknown;
160
+ /**
161
+ * 页面编译样式片(KC2 `compiledStyles`,KC12 序 2):core 按数组顺序逐片注入,逐字节、不改写、不排序。
162
+ * 作用域与层序是产出方义务;首片为层序声明。
163
+ */
164
+ compiledStyles?: readonly SomaCompiledStyle[];
165
+ /**
166
+ * 暗色首帧载体(KC2 `colorScheme`):只由服务端页面外壳读取并输出 `<meta name="color-scheme">`,
167
+ * 浏览器端 core 不写任何 DOM / 样式属性(KI-2)。
168
+ */
169
+ colorScheme?: 'light dark' | 'light' | 'dark';
96
170
  /** 数据对象层声明的预编译形态(构建阶段已解析校验,优先于 dataYaml) */
97
171
  dataConfig?: SomaDataConfig;
98
172
 
99
173
  /** Full router path including query string (e.g. /items/detail?id=1) */
100
174
  routerPath?: string;
101
175
 
176
+ // ── 页面信封的运行期上下文(E3 / E4;由取页响应带来,缺省则页面没有这些东西) ──
177
+ /** 地址参数(按信封 `params` 类型还原,`int` 是 number):装为只读的 `page.params`;空对象不装 */
178
+ pageParams?: Readonly<Record<string, string | number>>;
179
+ /** 信封 `query` 契约还原出的初始值:装为 `page.query`(没有契约不装) */
180
+ pageQuery?: Readonly<Record<string, string | number | boolean | null>>;
181
+ /** 信封 `query` 契约:`page.query.<名>` ⇄ 地址栏双向同步,与 `state.query` 合并 */
182
+ queryContract?: Readonly<Record<string, SomaEnvelopeQuerySpec>>;
183
+ /** 随页下发的导航目录(已按请求身份裁剪):换入 `services.nav` */
184
+ nav?: SomaNavView;
185
+
102
186
  /**
103
187
  * 组件运行时定义(组件体系模块 7,可选)。
104
188
  * 键为契约名;页面 HTML 中 data-soma-component 引用的组件必须在此提供。
@@ -107,21 +191,90 @@ export interface SomaPageAssets extends ComponentTreeRuntimeEnvelope {
107
191
  components?: Record<string, SomaComponentDefinition>;
108
192
  }
109
193
 
194
+ const COMPONENT_ATTR_RE = /data-soma-component\s*=\s*\\?["']([A-Za-z][A-Za-z0-9_-]*)\\?["']/g;
195
+
196
+ /** 页面标注:`data-soma-needs="A B"` 显式点名本页要用的按需组件(组件模板里的可选行模板据此补载) */
197
+ const COMPONENT_NEEDS_RE = /data-soma-needs\s*=\s*\\?["']([A-Za-z0-9_ -]+)\\?["']/g;
198
+ /** 可选行模板:带 `data-soma-on-demand` 的 `<template>` 里的组件引用不参与定义模板的补载闭包 */
199
+ const ON_DEMAND_TEMPLATE_RE = /<template\b[^>]*\bdata-soma-on-demand\b[^>]*>[\s\S]*?<\/template>/g;
200
+
201
+ /** 文本里 `data-soma-component="名"` 引用到的组件名,加上 `data-soma-needs` 点名的组件 */
202
+ function componentNamesIn(text: unknown): string[] {
203
+ if (typeof text !== 'string' || text === '') return [];
204
+ const names = [...text.matchAll(COMPONENT_ATTR_RE)].map((m) => m[1]!);
205
+ for (const m of text.matchAll(COMPONENT_NEEDS_RE)) names.push(...m[1]!.split(/\s+/).filter((n) => n !== ''));
206
+ return names;
207
+ }
208
+
209
+ /** 组件定义模板引用到的组件名:跳过可选行模板,由页面的 `data-soma-needs` 触发 */
210
+ function componentNamesInDefinition(templateHtml: unknown): string[] {
211
+ if (typeof templateHtml !== 'string') return [];
212
+ return componentNamesIn(templateHtml.replace(ON_DEMAND_TEMPLATE_RE, ''));
213
+ }
214
+
215
+ /** 一份页面资产引用到的组件名:HTML、声明(源文本或已解析配置)、产物 componentRefs */
216
+ function referencedComponentNames(assets: SomaPageAssets): string[] {
217
+ const names = new Set<string>(componentNamesIn(assets.html));
218
+ for (const text of [assets.uiYaml, assets.eventYaml, ...Object.values(assets.includes ?? {})]) for (const n of componentNamesIn(text)) names.add(n);
219
+ if (assets.uiConfig !== undefined) {
220
+ try { for (const n of componentNamesIn(JSON.stringify(assets.uiConfig))) names.add(n); } catch { /* 含环的配置不扫 */ }
221
+ }
222
+ for (const ref of assets.artifact?.componentRefs ?? []) names.add(ref.name);
223
+ return [...names];
224
+ }
225
+
226
+ /**
227
+ * 按页面引用补载按需组件,返回补齐后的组件表(不改入参):命中 `lazy` 且 `hostComponents` / 页面级组件里没有的才加载,
228
+ * 加载出的模板里引用的组件继续扫描到闭包补齐。给不经 `SomaBootstrap.mount` 就要先做装配期校验的入口(如生成页预览)用;
229
+ * 与 `SomaBootstrap` 内部补载规则一致(契约名须与登记名一致)。
230
+ */
231
+ export async function loadLazyComponentsFor(
232
+ assets: SomaPageAssets,
233
+ hostComponents: Record<string, SomaComponentDefinition>,
234
+ lazy: Readonly<Record<string, () => Promise<SomaComponentDefinition>>> | undefined,
235
+ ): Promise<Record<string, SomaComponentDefinition>> {
236
+ const table: Record<string, SomaComponentDefinition> = { ...hostComponents };
237
+ if (lazy === undefined || Object.keys(lazy).length === 0) return table;
238
+ const pageComponents = assets.components ?? {};
239
+ const seen = new Set<string>();
240
+ const queue = referencedComponentNames(assets);
241
+ while (queue.length > 0) {
242
+ const name = queue.pop()!;
243
+ if (seen.has(name)) continue;
244
+ seen.add(name);
245
+ if (Object.hasOwn(table, name) || Object.hasOwn(pageComponents, name)) continue;
246
+ const make = Object.hasOwn(lazy, name) ? lazy[name] : undefined;
247
+ if (make === undefined) continue;
248
+ const def = await make();
249
+ if (def?.contract?.name !== name) {
250
+ throw new Error(`[soma-core][组件] 按需组件 "${name}" 的工厂返回的定义契约名为 "${String(def?.contract?.name)}",与登记名不一致`);
251
+ }
252
+ table[name] = def;
253
+ queue.push(...componentNamesInDefinition(def.templateHtml));
254
+ }
255
+ return table;
256
+ }
257
+
110
258
  /** Validate before mutating the current DOM or instantiating any business Domain. */
111
259
  export function assertPageRuntimeAssets(assets: SomaPageAssets, hostComponents: Record<string, SomaComponentDefinition>): void {
112
260
  assertRuntimeArtifact(assets);
113
261
  if (assets.uiYaml && isSomaDeclarationSource(assets.uiYaml)) {
114
- throw new Error('[soma-core][引擎] 收到未编译的 SOMA DSL 源声明,请先在服务端编译。');
262
+ throw new Error('[SomaBootstrap] 收到未编译的 SOMA DSL 源声明,请先在服务端编译。');
115
263
  }
116
264
  if (assets.sourceMarkup === 'component-tree') {
117
- for (const ref of assets.artifact!.componentRefs) {
118
- const definition = assets.components?.[ref.name] ?? hostComponents[ref.name];
119
- if (!definition || definition.contractDigest !== ref.contractDigest || definition.structureDigest !== ref.structureDigest) {
120
- throw new SomaComponentTreeError({
121
- code: 'CT-ARTIFACT-CAPABILITY', phase: 'artifact', sourceId: '<runtime-assets>', nodePath: 'componentRefs',
122
- fixHint: '客户端组件供货缺失或契约/结构摘要与资产不一致;请同步部署服务端与客户端供货。',
123
- });
124
- }
265
+ // 组件供货摘要比对:与服务端回滚 / 路径访问是同一个判据函数(2.16a,KI-27 / KI-28)
266
+ const supply = supplyFromDefinitions({ ...hostComponents, ...(assets.components ?? {}) });
267
+ const verdict = checkArtifactRuntimeCompatibility({
268
+ sourceMarkup: 'component-tree',
269
+ format: assets.artifact!.format,
270
+ capabilities: assets.artifact!.capabilities,
271
+ componentRefs: assets.artifact!.componentRefs,
272
+ }, supply);
273
+ if (!verdict.compatible) {
274
+ throw new SomaComponentTreeError({
275
+ code: verdict.code, phase: 'artifact', sourceId: '<runtime-assets>', nodePath: 'componentRefs',
276
+ fixHint: '客户端组件供货缺失或契约/结构摘要与资产不一致;请同步部署服务端与客户端供货。',
277
+ });
125
278
  }
126
279
  const objectConfig = assets.uiConfig !== undefined && assets.eventConfig !== undefined;
127
280
  const yamlConfig = typeof assets.uiYaml === 'string' && assets.uiYaml.trim() !== ''
@@ -156,13 +309,13 @@ export function assertPageRuntimeAssets(assets: SomaPageAssets, hostComponents:
156
309
  });
157
310
  }
158
311
  if (assets.sourceMarkup === 'component-tree') {
159
- if (element.hasAttribute('data-soma-component')) {
160
- const symbol = element.getAttribute('data-soma-id') ?? '';
312
+ if (element.hasAttribute(SOMA_COMPONENT_ATTR)) {
313
+ const symbol = element.getAttribute(SOMA_ID_ATTR) ?? '';
161
314
  if (!symbol || treeHosts.has(symbol)) invalidPlan();
162
315
  treeHosts.set(symbol, element);
163
316
  }
164
- if (element.hasAttribute('data-soma-repeat-template')) {
165
- const symbol = element.getAttribute('data-soma-repeat-template') ?? '';
317
+ if (element.hasAttribute(SOMA_REPEAT_TEMPLATE_ATTR)) {
318
+ const symbol = element.getAttribute(SOMA_REPEAT_TEMPLATE_ATTR) ?? '';
166
319
  if (!symbol || !isHtmlTemplateElement(element) || treeTemplates.has(symbol)) invalidPlan();
167
320
  treeTemplates.set(symbol, element);
168
321
  }
@@ -175,10 +328,10 @@ export function assertPageRuntimeAssets(assets: SomaPageAssets, hostComponents:
175
328
  }
176
329
  if (assets.sourceMarkup === 'component-tree') {
177
330
  if (treeHosts.size !== assets.artifact!.structurePlan.length || treeTemplates.size !== assets.artifact!.repeatPlans.length
178
- || probe.content.children.length !== 1 || !probe.content.firstElementChild?.hasAttribute('data-soma-host')) invalidPlan();
331
+ || probe.content.children.length !== 1 || !probe.content.firstElementChild?.hasAttribute(SOMA_HOST_ATTR)) invalidPlan();
179
332
  for (const plan of assets.artifact!.structurePlan) {
180
333
  const host = treeHosts.get(plan.instanceSymbol);
181
- if (!host || host.getAttribute('data-soma-component') !== plan.componentName
334
+ if (!host || host.getAttribute(SOMA_COMPONENT_ATTR) !== plan.componentName
182
335
  || host.localName !== plan.hostTag || host.namespaceURI !== 'http://www.w3.org/1999/xhtml') invalidPlan();
183
336
  }
184
337
  const repeats = assets.artifact!.repeatPlans;
@@ -186,7 +339,7 @@ export function assertPageRuntimeAssets(assets: SomaPageAssets, hostComponents:
186
339
  let parent: Node | null = element.parentNode;
187
340
  while (parent) {
188
341
  const template = templateParents.get(parent);
189
- if (template?.hasAttribute('data-soma-repeat-template')) return template.getAttribute('data-soma-repeat-template')!;
342
+ if (template?.hasAttribute(SOMA_REPEAT_TEMPLATE_ATTR)) return template.getAttribute(SOMA_REPEAT_TEMPLATE_ATTR)!;
190
343
  parent = template ? template.parentNode : parent.parentNode;
191
344
  }
192
345
  return undefined;
@@ -199,8 +352,8 @@ export function assertPageRuntimeAssets(assets: SomaPageAssets, hostComponents:
199
352
  const ownerPlan = assets.artifact!.structurePlan.find(item => item.instanceSymbol === plan.consumerOwner.instanceSymbol);
200
353
  const slotPlan = ownerPlan?.slotPlans.find(item => item.name === plan.consumerOwner.slotName);
201
354
  if (!template || !slot || !owner || slot.parentElement !== owner
202
- || slot.getAttribute('data-soma-slot') !== plan.consumerOwner.slotName
203
- || template.getAttribute('data-soma-role') !== 'item'
355
+ || slot.getAttribute(SOMA_SLOT_ATTR) !== plan.consumerOwner.slotName
356
+ || template.getAttribute(SOMA_ROLE_ATTR) !== 'item'
204
357
  || slot.content.children.length !== 1 || slot.content.firstElementChild !== template
205
358
  || slotPlan?.kind !== 'collection' || slotPlan.layoutRootKey !== plan.consumerOwner.layoutRootKey
206
359
  || slotPlan.rowContainer !== plan.consumerOwner.rowContainer
@@ -224,88 +377,105 @@ function isHtmlTemplateElement(element: Element): element is HTMLTemplateElement
224
377
  && 'content' in element && (element as HTMLTemplateElement).content?.nodeType === 11;
225
378
  }
226
379
 
227
- /** 浏览器只用于拒绝源声明;不存在旧/新两套执行分派。 */
380
+ /**
381
+ * 浏览器只用于拒绝源声明;不存在旧/新两套执行分派。
382
+ * 源声明的形状是「第一条有效行(跳过空行与注释)就是 `{{` 开关行」(与块容器 `stripSwitch` 同一判据)。
383
+ * 只看第一条有效行:编译产物的 YAML 折叠长字符串(`>-`)后,内部可能恰有一行缩进的 `{{`(文案键表达式的开头),那不是源声明。
384
+ */
228
385
  function isSomaDeclarationSource(value: string): boolean {
229
- return value.split('\n').some((line) => {
386
+ for (const line of value.split('\n')) {
230
387
  const text = line.trim();
231
- if (!text || text.startsWith('#')) return false;
388
+ if (!text || text.startsWith('#')) continue;
232
389
  return text === '{{';
233
- });
390
+ }
391
+ return false;
234
392
  }
235
393
 
236
394
  // ─────────────────────────────────────────────────────────────────────
237
- // OOUI 演绎产物的注入面(REQ-014 最后一公里)
395
+ // 编译产物 HTML 片段的注入面(载体 `fragments.regions`)
238
396
  //
239
397
  // 这三个常量与两个函数是**运行时那道结构闸门**的全部判据。它们刻意做成模块级
240
398
  // 纯函数:闸门必须能对着"外面拿来的一份 html"单独跑,否则"引擎不产生内联事件
241
399
  // 处理器"这句话在运行时这一侧就只是一句没人验证过的话
242
- // (构建期那一侧是 `core/build/ooui/artifact/emit-html.ts` 的 `verifyArtifactHtml`)。
400
+ // (构建期那一侧是方言编译器自己的产物校验)。
243
401
  // ─────────────────────────────────────────────────────────────────────
244
402
 
245
403
  /**
246
- * 演绎区域已注入的标记。值是这份 html 的**内容指纹**,不是布尔。
404
+ * 片段已注入的标记(`data-soma-fragment`)。值是这份 html 的**内容指纹**,不是布尔。
247
405
  *
248
406
  * 布尔标记的坏法:同一个锚点换了一份产物会被当成"已经注入过了"而跳过,
249
407
  * 页面继续显示上一版 DOM——渲染正常、内容是旧的、控制台一行都没有。
250
408
  * 与产物侧 `css_key` 用内容哈希是同一条理由,只是这一侧的作用域是单个锚点。
251
409
  */
252
- export const SOMA_OOUI_REGION_ATTR = 'data-soma-ooui';
410
+ export const SOMA_FRAGMENT_HOST_ATTR = SOMA_FRAGMENT_ATTR;
253
411
 
254
412
  /**
255
- * 产物 DOM 的标签允许集。**这就是 `emitRegionHtml` 今天产出的全集**
256
- * (区域外壳恒为 `div`,根构件是组件时 `div`、是纯文本节点时 `span`)。
413
+ * 产物 DOM 的标签允许集。**这就是编译产物今天产出的全集**:区域与
414
+ * 实例用 `div`,带子组件内容的 slot 出口由 `template[data-soma-slot]` 惰性承载。
257
415
  *
258
- * 为什么是允许集不是禁用集:产物只有两种标签,禁用集只挡得住今天想得到的那几样,
259
- * 而允许集把"想不到的那些"一并挡住。代价是发射器加新标签时这里会红——
260
- * 那正是要的:红在写下的那天,而不是在某份被改过的资产送进 innerHTML 的那天。
416
+ * 为什么是允许集不是禁用集:允许集把"想不到的那些"一并挡住。代价是编译产物加新标签时
417
+ * 这里会红——红在写下的那天,而不是在某份被改过的资产送进 innerHTML 的那天。
261
418
  */
262
- export const SOMA_OOUI_ALLOWED_TAGS: ReadonlySet<string> = new Set(['DIV', 'SPAN']);
419
+ export const SOMA_FRAGMENT_ALLOWED_TAGS: ReadonlySet<string> = new Set(['DIV', 'TEMPLATE']);
263
420
 
264
421
  /**
265
422
  * 产物 DOM 的属性允许集(HTML 解析器会把属性名小写化,所以只写小写)。
266
423
  *
267
- * `on*`、`src`/`href` 这类属性一个都不在里面——引擎从不产出它们
268
- * (事件走 `eventConfig`,不进 DOM 属性;架构 §24.1),所以它们出现在这里
269
- * 只有一个含义:这份产物不是编译器产的。
424
+ * 由 `shared/hook-attributes` 登记表派生,不手抄:登记表里标 `inArtifact` 的钩子属性,
425
+ * 加不透明属性登记(`data-soma-instance`),再加两个通用属性 `class`、`hidden`。
426
+ * `on*`、`src`/`href`、`style` 等都不在里面——事件走 event 配置,样式走 class 与页面样式片,不进内联属性。
427
+ * 旧钩子名(`data-soma-when` / `data-soma-node` 等)不在其内,按闭集外属性拒收。
270
428
  */
271
- export const SOMA_OOUI_ALLOWED_ATTRS: ReadonlySet<string> = new Set([
272
- 'class', 'data-soma-node', 'data-soma-id', 'data-soma-component',
429
+ export const SOMA_FRAGMENT_ALLOWED_ATTRS: ReadonlySet<string> = new Set([
430
+ 'class',
431
+ 'hidden',
432
+ ...SOMA_OPAQUE_ATTRIBUTE_REGISTRY.attributes,
433
+ ...SOMA_CORE_HOOK_ATTRIBUTES.filter((entry) => 'inArtifact' in entry && entry.inArtifact === true).map((entry) => entry.name),
273
434
  ]);
274
435
 
275
436
  /**
276
437
  * 结构闸门:返回 `null` 表示这份 DOM 就是产物该有的样子,否则返回违规描述。
277
438
  *
278
439
  * 三条判据:
279
- * ① 顶层恰好一个元素(`emitRegionHtml` 恒产出单个区域外壳)。
280
- * 不查这条的话,一份"外壳 + 一段裸文本"的产物会被照单全收,
281
- * 而多出来的那段文本在页面上只是多了一行字。
282
- * ② 每个元素的标签在允许集内;
440
+ * ① 顶层恰好一个元素(编译产物恒为单个区域外壳);
441
+ * ② 每个元素(包括 `template.content` 中的元素)的标签在允许集内;
283
442
  * ③ 每个属性名在允许集内。
284
443
  */
285
- export function findOouiDomOffence(fragment: DocumentFragment): string | null {
444
+ export function findFragmentDomOffence(fragment: DocumentFragment): string | null {
286
445
  const roots = fragment.children;
287
446
  if (roots.length !== 1) {
288
447
  return `顶层元素有 ${roots.length} 个,产物恒为单个区域外壳`;
289
448
  }
290
449
  for (const node of Array.from(fragment.childNodes)) {
291
- // 元素之外的顶层节点(裸文本、注释)一律拒收。发射器只产出一个外壳元素,
450
+ // 元素之外的顶层节点(裸文本、注释)一律拒收。编译产物只有一个外壳元素,
292
451
  // 多出来的那一段在页面上只是"莫名其妙多了一行字"——没人会把它报成 bug。
293
452
  // 纯空白放行:YAML 的块标量可能带一个尾换行,那不是内容。
294
453
  if (node.nodeType !== 1 && (node.textContent ?? '').trim() !== '') {
295
454
  return `顶层混有元素以外的节点(nodeType ${node.nodeType})`;
296
455
  }
297
456
  }
298
- for (const element of Array.from(fragment.querySelectorAll('*'))) {
299
- if (!SOMA_OOUI_ALLOWED_TAGS.has(element.tagName)) {
300
- return `标签 <${element.tagName.toLowerCase()}>`;
301
- }
302
- for (const attribute of Array.from(element.attributes)) {
303
- if (!SOMA_OOUI_ALLOWED_ATTRS.has(attribute.name)) {
457
+ // querySelectorAll('*') 不进入 HTMLTemplateElement.content;slot 出口虽惰性,
458
+ // 内容仍会被组件投影搬入活动 DOM,因此必须沿同一棵发射树递归执行完整允许集。
459
+ const inspect = (parent: ParentNode): string | null => {
460
+ for (const node of Array.from(parent.childNodes)) {
461
+ if (node.nodeType !== 1) continue;
462
+ const element = node as Element;
463
+ if (!SOMA_FRAGMENT_ALLOWED_TAGS.has(element.tagName)) {
464
+ return `标签 <${element.tagName.toLowerCase()}>`;
465
+ }
466
+ for (const attribute of Array.from(element.attributes)) {
467
+ if (SOMA_FRAGMENT_ALLOWED_ATTRS.has(attribute.name)) continue;
304
468
  return `属性 ${attribute.name}`;
305
469
  }
470
+ const children = element.tagName === 'TEMPLATE'
471
+ ? (element as HTMLTemplateElement).content
472
+ : element;
473
+ const offence = inspect(children);
474
+ if (offence !== null) return offence;
306
475
  }
307
- }
308
- return null;
476
+ return null;
477
+ };
478
+ return inspect(fragment);
309
479
  }
310
480
 
311
481
  /**
@@ -316,7 +486,7 @@ export function findOouiDomOffence(fragment: DocumentFragment): string | null {
316
486
  * 而 `crypto.subtle.digest` 是异步的,为一次同步的"变没变"判断引入异步
317
487
  * 会把注入挪到组件展开之后(见 mount 的 2.4 与 2.5 的顺序)。
318
488
  */
319
- export function oouiHtmlFingerprint(html: string): string {
489
+ export function fragmentHtmlFingerprint(html: string): string {
320
490
  let hash = 0x811c9dc5;
321
491
  for (let index = 0; index < html.length; index += 1) {
322
492
  hash ^= html.charCodeAt(index);
@@ -358,6 +528,14 @@ export interface SomaBootstrapOptions {
358
528
  * 对该 Host 的所有页面生效;页面资产 components 同名时覆盖 Host 级定义。
359
529
  */
360
530
  components?: Record<string, SomaComponentDefinition>;
531
+ /**
532
+ * Host 级按需组件(通用的异步组件定义能力):组件名 → 返回定义的异步工厂。
533
+ * 页面挂载 / 热替换前,core 只扫描本页引用到的组件名(HTML、声明里的 `data-soma-component`、产物 componentRefs),
534
+ * 命中本表且 `components` 里没有的才调用工厂(同名只调一次,结果缓存);加载出的定义模板里再引用的组件名同样递归补载。
535
+ * 工厂返回定义的契约名必须等于登记名,否则抛错。运行期才由代码动态创建的组件不在扫描范围,须放进 `components` 常驻。
536
+ * 与 `components` 同名时以 `components` 为准。
537
+ */
538
+ lazyComponents?: Readonly<Record<string, () => Promise<SomaComponentDefinition>>>;
361
539
  /**
362
540
  * Host 级默认 props(REQ-009 M-2):组件名 → { prop: 默认值 }。
363
541
  * 「本站所有表格都要 size: sm」这类站点级口径的落点,
@@ -378,19 +556,46 @@ export interface SomaBootstrapOptions {
378
556
  * 对不上就抛。留到运行期才发现的话,那是用户点了按钮之后什么都没发生。
379
557
  */
380
558
  actions?: Record<string, (payload: Record<string, unknown>) => Promise<unknown> | unknown>;
559
+ /**
560
+ * 异步字段检查器注册表(C6-c):`{ 检查器名: 检查器 }`,应用经 `browserMount().asyncChecks` 交入。
561
+ * 字段规则 `rules[].async` 写的就是这里的名字;装配期对着这张表核对页面引用,缺登记抛 `CORE-ASYNC-CHECK-UNREGISTERED`,
562
+ * 表形状非法抛 `CORE-ASYNC-CHECK-TABLE`。组件在契约 `services` 声明 `validation`,经 `ctx.services.validation.asyncCheck(name)` 取用。
563
+ */
564
+ asyncChecks?: SomaAsyncCheckTable;
381
565
  /**
382
566
  * Host 自定义格式化管道(模块 7 U4):{ 管道名: 纯函数 },与内置管道合并。
383
567
  * 内置:money / tpl / date / percent / plural。
384
568
  */
385
569
  pipes?: Record<string, SomaPipeFn>;
386
570
  /**
387
- * 阶梯词汇注册位(F-09 / 契约 C5),与组件注册同点:
388
- * `adaptiveVocabulary: createSomaUiAdaptiveVocabulary()`。
389
- *
390
- * core **不内置任何级语义**——语法归语言、词汇归组件。不注册而页面声明了
391
- * `adaptive.ladder` 时按"词汇未知"快速失败,而不是静默忽略那些级。
571
+ * 角色集来源(KC13 `auth`):Host 经 soma-ui 入口取自身份上下文。给出时角色判定(动作可用性、`permission:`
572
+ * 管道、命令动作)一律走默认拒绝的角色门——读不到 / 非字符串数组即无角色。请求不附带任何 core 生成的身份字段。
573
+ */
574
+ auth?: SomaAuthOption;
575
+ /**
576
+ * 当前用户身份来源(K8):返回 `{ id, team, … }` 快照,每次现读。`services.identity` 与查询里的 `$user.id` / `$user.team`、
577
+ * 偏好的「用户」维度都取自它;core 不从 token 反解身份。不给 = 什么字段都不提供。
578
+ */
579
+ identity?: SomaIdentityProvider;
580
+ /**
581
+ * 时间源(C19 `SomaClockPort`,C-int 接线):解析器的 `now`(生命周期派生)与无偏移日期时间的时区都取它。
582
+ * 不给 = 系统时间 + 应用配置 `format.time_zone`(缺省 UTC)。
392
583
  */
393
- adaptiveVocabulary?: SomaAdaptiveVocabulary;
584
+ clock?: SomaClockPort;
585
+ /** 宿主路由端口(C48,K53):`services.navHistory` 的跳转经它;不给退化为浏览器历史 */
586
+ navHistory?: SomaNavHistoryPort;
587
+ /**
588
+ * 快捷键注册中心(C56 K81):bootstrap 持有的唯一一份,`services.shortcuts` 直通;不给则自建(modKey 取 `shortcutsModKey`,序列间隔读 design)。
589
+ */
590
+ shortcuts?: SomaShortcutRegistry;
591
+ /** 本平台 mod 对应的物理修饰键(mac 传 meta);自建注册中心时用 */
592
+ shortcutsModKey?: 'ctrl' | 'meta';
593
+ /** UI 体系注入的渲染端口(notify 等);缺省全部无头(只记录),soma-ui / soma-lite 入口各给一份 */
594
+ renderPorts?: SomaRenderPorts;
595
+ /** 引擎端口的适配器替换(样式 / 行为 / 表格 / 图表 / 拖放等);未给的槽位用各端口缺省适配器,装配由 UI 体系入口完成 */
596
+ engines?: Partial<SomaEngineAdapters>;
597
+ /** 多语言:初始显示语言与内置受控词表覆盖(KC13 / 2.2a);缺省取词表的应用缺省语言与 core 内置词表 */
598
+ locale?: SomaLocaleOptions;
394
599
  /** Render-engine middleware chain (opt-in) */
395
600
  renderMiddleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
396
601
  /**
@@ -403,7 +608,25 @@ export interface SomaBootstrapOptions {
403
608
  * 库不该擅自劫持 window 的错误钩子,是否采集由 Host 显式决定。
404
609
  */
405
610
  errorReporting?: SomaBootstrapErrorReporting;
406
- // 主题不在此:无 theme / themeEngine。声明走 appConfig.theme,函数走 applyTheme(引擎内建)。
611
+ /**
612
+ * 运行期观测(M03,KC13 / KC18):缺省关闭。显式 `true` 才采集并在浏览器挂 `window.__somaObserve`;
613
+ * 关闭时 `window.__somaObserve === undefined`,组件的 `services.observation` 为空操作通道。
614
+ * 采集只读,不改 DOM(KI-22)。
615
+ */
616
+ observe?: boolean;
617
+ // 主题不在此:core 不认识主题(无 theme / themeEngine / appConfig.theme);主题由编译期进 compiledStyles。
618
+ }
619
+
620
+ export interface SomaLocaleOptions {
621
+ /** 初始显示语言(Host 取应用 `app.locale` 给出);缺省 = 词表的应用缺省语言 */
622
+ readonly initial?: string;
623
+ /** Host 覆盖 / 补语言的内置受控词表;产物中同键词条优先 */
624
+ readonly builtin?: SomaLocaleBundle;
625
+ /**
626
+ * 组件包词条(S5,K1 ②):`composeComponentPacks(...).locales`(或任何 `{ name, locales }` 列表),
627
+ * 构造期经 `registerComponentPackLocales` 按序登记进文案目录——后面的包优先;优先级 应用词表 > 包词条 > 内置受控词表。
628
+ */
629
+ readonly packs?: readonly PackWithLocales[];
407
630
  }
408
631
 
409
632
  /**
@@ -420,7 +643,7 @@ export interface ParsedRuntimeAssets {
420
643
  triggers: PropertyTrigger[];
421
644
  timers: ParsedTimer[];
422
645
  styleConfig?: StyleConfig;
423
- locale: Record<string, unknown>;
646
+ locale: SomaLocaleBundle | Record<string, unknown>;
424
647
  appConfig: unknown;
425
648
  }
426
649
 
@@ -435,6 +658,8 @@ export class SomaBootstrap {
435
658
  private readonly renderMiddleware: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
436
659
  private readonly eventMiddleware: SomaMiddlewareChain<SomaEventMiddlewareContext>;
437
660
  private routerUnsubscribe: (() => void) | null = null;
661
+ /** WP3b-C 页面钩子(`state.query` 绑定、`data-soma-motion`)的卸载函数;每次 buildRuntime 重装 */
662
+ private pageHookDisposers: Array<() => void> = [];
438
663
 
439
664
  private renderEngine: SomaRenderEngine | null = null;
440
665
  private eventEngine: SomaEventEngine | null = null;
@@ -449,24 +674,58 @@ export class SomaBootstrap {
449
674
  private domainInstance: SomaPageRoot | null = null;
450
675
  private componentManager: SomaComponentManager | null = null;
451
676
  private hostComponents: Record<string, SomaComponentDefinition> = {};
677
+ private lazyComponents: Readonly<Record<string, () => Promise<SomaComponentDefinition>>> = {};
678
+ private lazyLoading = new Map<string, Promise<SomaComponentDefinition>>();
452
679
  private componentDefaults?: SomaComponentDefaults;
453
680
  /**
454
681
  * 当前页的数据对象解析器(写通道 §8.4 的真身)。
455
682
  * 它在 loadDataObjects 里被换掉——每次重取都是一个新解析器。
456
683
  */
457
684
  private dataResolver: SomaDataObjectResolver | null = null;
685
+ private dataLoadEpoch = 0;
686
+ private dataOwnerEpoch = 0;
687
+ /** 写入结果存储:与 bootstrap 同寿(字段错误、冲突、乐观叠层),`services.data.writeOutcome` 读它 */
688
+ private readonly writeOutcomeStore: SomaWriteOutcomeStore = createWriteOutcomeStore();
689
+ /** 快捷键注册中心(C-r18):唯一一份,`services.shortcuts` 直通 */
690
+ private shortcutsInstance!: SomaShortcutRegistry;
458
691
  private componentStyleNonce?: string | null;
459
692
  private pipeRegistry: SomaPipeRegistry;
460
- /** 阶梯词汇表:Host 级注册,对该 Host 全部页面生效;未注册时恒为 undefined */
461
- private readonly adaptiveVocabulary?: SomaAdaptiveVocabulary;
462
- /** 数据对象层:当前页面的声明(无 *_data.yaml 时为 null,整条路径旁路) */
693
+ /** 多语言文案目录(跨挂载同一个实例,挂载时 reset 再装词表):`services.i18n` 就是它 */
694
+ private readonly localeCatalog: SomaLocaleCatalog;
695
+ private readonly localeOptions: SomaLocaleOptions;
696
+ /** 文案位登记(`{{ t('键') }}`):切换显示语言只重渲这些位 */
697
+ private readonly localeBinder: SomaLocaleTextBinder = createLocaleTextBinder();
698
+ private stopLocaleObserver: (() => void) | null = null;
699
+ /** 用户 / Host 最近一次选定的显示语言:热替换换词表后据此恢复 */
700
+ private preferredLocale: string | undefined;
701
+ /** 最近一次解析出的页面词表(`_locale` 绑定表在切换语言时由它重算) */
702
+ private lastLocale: SomaLocaleBundle | Record<string, unknown> = {};
703
+ /** 角色集来源(KC13 auth) */
704
+ private readonly authOption?: SomaAuthOption;
705
+ /** 身份来源(K8):每个页面根的 services 装配时交给 createDefaultRuntimeServices */
706
+ private readonly identityOption?: SomaIdentityProvider;
707
+ private readonly clockOption?: SomaClockPort;
708
+ private derivedClock: { readonly zone: string | undefined; readonly clock: SomaClockPort } | null = null;
709
+ /** 返回栈(C48):bootstrap 持有的唯一一份,每个页面根的 services.navHistory 都是它 */
710
+ private readonly navHistoryInstance: SomaNavHistory;
711
+ /** 渲染端口(notify 等) */
712
+ private readonly renderPorts?: SomaRenderPorts;
713
+ /** 引擎端口适配器替换(未给的槽位 = 缺省适配器);各端口 `create<X>Port` 经它取替换项 */
714
+ readonly engines: Readonly<Partial<SomaEngineAdapters>>;
715
+ /** 数据对象层:当前页面的声明(无 `data:` 声明时为 null,整条路径旁路) */
463
716
  private dataConfig: SomaDataConfig | null = null;
717
+ /** 数据变更订阅(REQ-019 D-5):随数据声明接线,随数据归属换代断开 */
718
+ private dataSubscriptions: SomaDataSubscriptionHandle | null = null;
719
+ /** 对象级轮询(`poll:`):随数据声明接线,随数据归属换代 / 卸载清理 */
720
+ private dataPolling: SomaDataPollingHandle | null = null;
464
721
  /** 数据对象层:最近一次取数任务(whenDataReady 暴露给测试/调试) */
465
722
  private dataReady: Promise<void> | null = null;
466
723
  /** 数据对象层:字段字典产物(soma-ui 双态映射消费) */
467
724
  private dataDicts: SomaDataDicts = {};
468
725
  private mounted = false;
469
726
  private diagnostics: SomaDiagnostics;
727
+ private readonly observeEnabled: boolean;
728
+ private observer: SomaRuntimeObserver | null = null;
470
729
  private readonly telemetry: SomaTelemetry;
471
730
  private container: HTMLElement | null = null;
472
731
  private assets: SomaPageAssets | null = null;
@@ -476,22 +735,64 @@ export class SomaBootstrap {
476
735
  private errorReporter: SomaErrorReporterHandle | null = null;
477
736
  /** 具名动作注册表(AO-3);构造期定下,运行中不换 */
478
737
  private readonly namedActions: Record<string, (payload: Record<string, unknown>) => Promise<unknown> | unknown>;
738
+ /** 异步字段检查器登记(`services.validation`):构造期复制并验形状,页面生命周期内不变 */
739
+ private readonly validationService: SomaValidationService;
740
+ /**
741
+ * 区域协调作用域 store(`services.region`):每个 bootstrap 一份(实例字段,不是模块单例——
742
+ * 预览 + 主页两个 bootstrap 互不可见);每次挂载 / 热替换 `install` 本页声明,cleanup 清空。
743
+ * 组件手里的旧句柄靠 store 内的代次失效,不会写进新页面的状态。
744
+ */
745
+ private readonly regionScopes = createRegionScopeStore();
746
+ /** 区域协调的视图绑定(切片镜像 + 显隐门)的解除函数;每次建运行时重绑 */
747
+ private regionViewsOff: (() => void) | null = null;
748
+ /** 本页组件注册表(契约 a11y 段交页面校验器做地标检查);无组件时为 null */
749
+ private componentRegistry: SomaComponentRegistry | null = null;
750
+ /** 导航目录仓(`services.nav` 的只读端口由它出;取页 / 客户端导航后 `replace`) */
751
+ private readonly navStore = createNavStore();
752
+ /** 应用配置 `format:` 的解析缓存(按原值身份;热替换换了 appConfig 时重解) */
753
+ private formatDefaultsCache: { readonly raw: unknown; readonly value: SomaFormatDefaults } | null = null;
479
754
 
480
755
  constructor(options: SomaBootstrapOptions = {}) {
481
756
  this.adapter = options.adapter ?? new SomaContainerAdapter();
482
757
  this.scheduler = options.scheduler ?? new SomaScheduler();
483
758
  this.diagnostics = options.diagnostics ?? new SomaDiagnostics();
759
+ this.observeEnabled = options.observe === true;
484
760
  this.telemetry = options.telemetry ?? new SomaTelemetry();
485
- this.adaptiveVocabulary = options.adaptiveVocabulary;
486
- this.assetResolver = options.assetResolver
487
- ?? new SomaAssetResolver(undefined, { adaptiveVocabulary: this.adaptiveVocabulary });
488
- this.hostComponents = options.components ?? {};
761
+ this.authOption = options.auth;
762
+ this.identityOption = options.identity;
763
+ this.clockOption = options.clock;
764
+ this.navHistoryInstance = createNavHistory(options.navHistory ? { port: options.navHistory } : {});
765
+ // 快捷键注册中心(唯一一份,跨页面共享)
766
+ this.shortcutsInstance = options.shortcuts ?? createShortcutRegistry({
767
+ ...(options.shortcutsModKey !== undefined ? { modKey: options.shortcutsModKey } : {}),
768
+ ...(shortcutsDesign()?.sequenceTimeoutMs !== undefined ? { sequenceTimeoutMs: shortcutsDesign()!.sequenceTimeoutMs } : {}),
769
+ });
770
+ this.renderPorts = options.renderPorts;
771
+ this.engines = options.engines ?? {};
772
+ this.localeOptions = options.locale ?? {};
773
+ this.preferredLocale = this.localeOptions.initial;
774
+ this.localeCatalog = new SomaLocaleCatalog({
775
+ builtin: this.localeOptions.builtin ?? SOMA_BUILTIN_LOCALE,
776
+ onMissing: (event) => this.reportLocaleMissing(event),
777
+ });
778
+ // 组件包词条(S5):目录跨挂载同一个实例,构造期登记一次即对本 bootstrap 的全部页面生效;
779
+ // 形状越界(CORE-LOCALE-PACK-*)在这里拒收——没经 composeComponentPacks 的列表也过同一判据
780
+ this.registerPackLocales(this.localeOptions.packs);
781
+ this.assetResolver = options.assetResolver ?? new SomaAssetResolver();
782
+ this.lazyComponents = options.lazyComponents ?? {};
783
+ // 有按需组件时复制一份,补载的定义只进本 bootstrap 的表,不改到调用方手里的对象
784
+ this.hostComponents = options.lazyComponents !== undefined ? { ...(options.components ?? {}) } : (options.components ?? {});
489
785
  this.componentDefaults = options.componentDefaults;
490
786
  this.componentStyleNonce = options.componentStyleNonce ?? null;
491
787
  // 复制一份:注册表在页面生命周期内不该被调用方改到(换掉的后果是
492
788
  // "解析期查过、运行期又不在了",而那条路径只有抛异常一个出口)
493
789
  this.namedActions = { ...(options.actions ?? {}) };
790
+ this.validationService = createAsyncCheckService(options.asyncChecks);
494
791
  this.pipeRegistry = new SomaPipeRegistry(options.pipes);
792
+ // 内置管道(money / date / percent / plural)读当前显示语言走 Intl
793
+ this.pipeRegistry.setLocaleProvider(() => this.localeCatalog.currentLocale());
794
+ // 应用配置 `format.time_zone`(WP3b-A,K1 ①):管道缺省时区;每次求值现读(热替换换配置后立即生效)
795
+ this.pipeRegistry.setFormatDefaults(() => this.formatDefaults());
495
796
  // 复制一份:身份会随 setErrorReportingPage 变,不该改到调用方手里的对象
496
797
  this.errorReporting = options.errorReporting ? { ...options.errorReporting } : null;
497
798
 
@@ -501,6 +802,10 @@ export class SomaBootstrap {
501
802
  }
502
803
 
503
804
  async mount(container: HTMLElement, assets: SomaPageAssets): Promise<void> {
805
+ const ownerEpoch = ++this.dataOwnerEpoch;
806
+ const assertCurrentMount = (): void => {
807
+ if (ownerEpoch !== this.dataOwnerEpoch) throw new DOMException('页面初始化已被卸载或替换', 'AbortError');
808
+ };
504
809
  const mountStarted = globalThis.performance?.now?.() ?? Date.now();
505
810
  // 首屏三段打点:走到这里资产已经在手(宿主若在拉取前 startBootTimings,段一即覆盖网络耗时;
506
811
  // 宿主直接带资产调 mount 时段一趋近 0,属实测事实而非误差)。默认未开启时这两行是两次布尔判断。
@@ -515,11 +820,14 @@ export class SomaBootstrap {
515
820
  this.scheduler.setDiagnostics(this.diagnostics);
516
821
  }
517
822
  this.container = container;
823
+ this.setupObserver(container);
824
+ await this.ensureLazyComponents(assets);
825
+ assertCurrentMount();
518
826
  assertPageRuntimeAssets(assets, this.hostComponents);
519
827
  // 源声明只允许在构建/服务端编译;浏览器 mount 只消费运行时资产。
520
828
  if (assets.uiYaml && isSomaDeclarationSource(assets.uiYaml)) {
521
829
  throw new Error(
522
- '[soma-core][引擎] 收到未编译的 SOMA DSL 源声明。'
830
+ '[SomaBootstrap] 收到未编译的 SOMA DSL 源声明。'
523
831
  + '请先用 compilePageAssets(构建/测试)或 Host 页面编译入口生成运行时资产。',
524
832
  );
525
833
  }
@@ -528,52 +836,65 @@ export class SomaBootstrap {
528
836
  // 1. 解析资产(委托给 AssetResolver)
529
837
  const parsed = this.assetResolver.resolve(this.assets);
530
838
 
839
+ // 1.5 文案目录:词表信封装入,定当前显示语言(挂载选项 locale.initial,缺省取词表的缺省语言)
840
+ this.loadLocale(parsed.locale);
841
+
531
842
  // 2. 挂载 HTML
532
843
  this.adapter.mount(container, this.assets.html, this.assets.includes);
533
844
 
845
+ // 2.1 页面编译样式片(KC12 序 2)与构建期产物样式(序 3 layout、序 4 片段样式):按固定序先于组件分片(序 6)
846
+ // 进入文档,层序才稳定。运行时只搬运,不代算。
847
+ this.installPageStyles(this.assets, parsed.uiConfig);
848
+
534
849
  // 2.4 演绎产物的 DOM 落点(REQ-014 最后一公里)。
535
850
  // **必须在 2.5 之前**:演绎出的根构件带 `data-soma-component`,
536
851
  // 而组件展开是一次性扫描 `container.querySelectorAll('[data-soma-component]')`。
537
852
  // 插在它之后的话,演绎出来的组件不会被展开——DOM 在、锚点在、
538
853
  // `data-soma-component` 属性也在,只是那个组件的模板永远不注入,
539
854
  // 页面上就是一个空 div,没有异常也没有日志。
540
- this.installOouiHtml(container, parsed.uiConfig);
855
+ this.installFragmentHtml(container, parsed.uiConfig);
856
+
857
+ // 2.4.1 区域协调作用域:声明对页面实例对账(区域内实例必须由页面 HTML 直接声明)后装入 store。
858
+ // 在组件展开之前:此刻容器里还是未展开的页面 HTML,复合组件模板里的子实例不在其中。
859
+ this.installRegionScopes(container, parsed.uiConfig, parsed.eventConfig);
541
860
 
542
861
  // 2.5 组件展开(页面引擎构建前:模板注入、锚点作用域化、插槽投影)
543
862
  this.setupComponentManager(container, this.assets, parsed.uiConfig);
544
863
 
545
- // 2.6 主题派生与注入(app.config theme: { brand } 一行换装,缺省旁路)
546
- this.applyHostTheme(parsed.appConfig);
864
+ // 2.6 文案位登记并按当前显示语言首次渲染(组件展开之后:模板里的 `{{ t() }}` 都已落进文档)
865
+ this.bindLocaleSlots(container);
547
866
 
548
867
  // 3. 创建领域实例并注入配置
549
- this.domainInstance = this.createDomainInstance(assets.DomainClass, parsed, assets.routerPath);
868
+ this.domainInstance = this.createDomainInstance(assets.DomainClass ?? SomaLocaleOnlyPageRoot, parsed, assets.routerPath, assets);
550
869
 
551
870
  // 3.5 数据对象层(五件套可选件):首渲前解析声明并注入 reloadData 钩子;
552
871
  // 声明非法只告警不阻断挂载(data 保持空对象)
553
872
  this.prepareDataLayer(this.domainInstance, assets);
554
873
 
555
874
  // 4. 包装响应式代理
556
- // 第三参(数组变异守卫)这里**故意不传**:传 false 会把开发期也一起关掉,
557
- // 而这条告警正是写页面时唯一能发现"就地 push 不触发更新"的提示。
558
- // 该开还是该关交给 SomaReactiveProxy 的默认值按环境判定(isSomaArrayGuardEnabled)——
559
- // 生产包里是关的,`npm run dev` 与 `globalThis.SOMA_DEV_GUARD = true` 时照旧报。
560
875
  this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
561
876
  this.domainInstance = this.proxy.wrap(this.domainInstance);
562
877
 
563
- // 5. 构建运行时(委托给 RuntimeBuilder)
564
- await this.buildRuntime(parsed);
565
-
566
- // 5.5 数据对象层:异步取数(不阻塞首屏),完成后注入 page.data 并全量渲染
878
+ // 数据 resolver 先于自治组件 onMount 建立;首轮取数仍异步,不阻塞首屏。
567
879
  if (this.dataConfig) {
568
880
  void this.loadDataObjects();
569
881
  }
882
+
883
+ // 5. 构建运行时(委托给 RuntimeBuilder)
884
+ await this.buildRuntime(parsed);
885
+ assertCurrentMount();
570
886
  if (typeof this.domainInstance.onMount === 'function') {
571
887
  await this.domainInstance.onMount();
572
888
  }
889
+ assertCurrentMount();
890
+ await this.componentManager?.whenInitialized();
891
+ assertCurrentMount();
573
892
  this.startDeclarativeTimers();
574
893
  this.mounted = true;
575
894
  recordMetric('bootstrap.mount', (globalThis.performance?.now?.() ?? Date.now()) - mountStarted);
576
895
  } catch (error) {
896
+ // 旧挂载已被卸载或新挂载替代时,不能用旧失败清场当前页面。
897
+ if (ownerEpoch !== this.dataOwnerEpoch) throw error;
577
898
  console.error('[soma-core][引擎] 页面挂载失败:', error);
578
899
  // 必须在 cleanup 之前上报:cleanup 会摘掉采集器
579
900
  this.captureEngineError(error);
@@ -587,18 +908,18 @@ export class SomaBootstrap {
587
908
  options?: { resetDiagnostics?: boolean; preserveState?: boolean },
588
909
  ): Promise<void> {
589
910
  if (!this.mounted || !this.container || !this.assets || !this.domainInstance) {
590
- throw new Error('[soma-core][引擎] Cannot hotSwap before mount');
911
+ throw new Error('[SomaBootstrap] Cannot hotSwap before mount');
591
912
  }
592
913
 
593
914
  const savedLocale =
594
- overrides.localeYaml !== undefined && this.domainInstance._locale
915
+ overrides.locale !== undefined && this.domainInstance._locale
595
916
  ? { ...this.domainInstance._locale }
596
917
  : null;
597
918
 
598
919
  const snapshotId = options?.preserveState
599
920
  ? this.snapshotStore.capture(
600
921
  this.domainInstance,
601
- overrides.localeYaml !== undefined ? { exclude: ['_locale'] } : undefined,
922
+ overrides.locale !== undefined ? { exclude: ['_locale'] } : undefined,
602
923
  )
603
924
  : null;
604
925
 
@@ -628,6 +949,7 @@ export class SomaBootstrap {
628
949
  }
629
950
  }
630
951
  }
952
+ await this.ensureLazyComponents(merged);
631
953
  assertPageRuntimeAssets(merged, this.hostComponents);
632
954
 
633
955
  if (options?.resetDiagnostics) {
@@ -636,6 +958,11 @@ export class SomaBootstrap {
636
958
  }
637
959
 
638
960
  const parsed = this.assetResolver.resolve(merged);
961
+ // 应用配置 `format:` 先验后换:越界即抛 CORE-FORMAT-CONFIG(与装配期同一判据),此时页面还没动
962
+ const nextFormat = parsed.appConfig && typeof parsed.appConfig === 'object'
963
+ ? (parsed.appConfig as Record<string, unknown>).format
964
+ : undefined;
965
+ parseFormatAppConfig(nextFormat);
639
966
 
640
967
  // 旧页面的组件实例必须在 DOM 被换掉**之前**销毁。
641
968
  // adapter.mount 是 `container.innerHTML = html`:跑完之后旧宿主已是游离节点,
@@ -646,39 +973,47 @@ export class SomaBootstrap {
646
973
  // setupComponentManager 里那次 destroy() 是防御性兜底,删这一行会把上述后果全部放回来。
647
974
  this.componentManager?.destroy();
648
975
  this.componentManager = null;
976
+ this.dataOwnerEpoch += 1;
977
+ this.invalidateDataResolver();
649
978
 
979
+ this.releaseLocaleSlots();
980
+ if (overrides.locale !== undefined) this.loadLocale(parsed.locale);
650
981
  this.adapter.mount(this.container, merged.html, merged.includes);
651
- // 与 mount 同序:演绎 DOM 先落,组件展开后扫。热替换换的是整份 innerHTML,
982
+ // 与 mount 同序:样式先入、演绎 DOM 再落、作用域声明装入,组件展开最后扫。热替换换的是整份 innerHTML,
652
983
  // 上一版的区域连同它的已注入标记一起没了,所以这里必然是一次真注入。
653
- this.installOouiHtml(this.container, parsed.uiConfig);
984
+ this.installPageStyles(merged, parsed.uiConfig);
985
+ this.installFragmentHtml(this.container, parsed.uiConfig);
986
+ this.installRegionScopes(this.container, parsed.uiConfig, parsed.eventConfig);
654
987
  this.setupComponentManager(this.container, merged, parsed.uiConfig);
988
+ this.bindLocaleSlots(this.container);
655
989
 
656
990
  if (overrides.DomainClass) {
657
991
  this.proxy?.dispose();
658
- const raw = this.createDomainInstance(merged.DomainClass, parsed, merged.routerPath);
659
- // 与 mount 第 4 步同一口径:守卫开关交给默认值按环境判定,这里不传死
992
+ const raw = this.createDomainInstance(merged.DomainClass ?? SomaLocaleOnlyPageRoot, parsed, merged.routerPath, merged);
660
993
  this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
661
994
  this.domainInstance = this.proxy.wrap(raw);
662
995
  } else {
663
- if (!options?.preserveState || overrides.localeYaml !== undefined) {
664
- this.domainInstance._locale = parsed.locale as Record<string, string>;
665
- this.domainInstance._services?.i18n.loadContent(parsed.locale as Record<string, string>);
996
+ if (!options?.preserveState || overrides.locale !== undefined) {
997
+ // 词表已在 loadLocale 装入文案目录;`_locale` 是当前显示语言的词条表
998
+ this.domainInstance._locale = this.localeTable(parsed.locale);
666
999
  }
667
1000
  if (parsed.appConfig) {
668
1001
  this.domainInstance._config = parsed.appConfig as any;
669
1002
  }
670
1003
  applyLocaleMetadata(this.domainInstance);
1004
+ // `format:` 的读取点是服务里的配置(装配期装入、config.load 只合并不删键),所以这里整段换掉;
1005
+ // 不换的话热替换后占位 / 时区 / 周起始仍是旧值(缓存按原值身份,新旧值不同即重解)
1006
+ this.domainInstance._services?.config.set('format', nextFormat);
671
1007
  }
672
1008
 
673
1009
  this.assets = merged;
674
- await this.buildRuntime(parsed);
675
- this.startDeclarativeTimers();
676
-
677
- // 数据对象层:hotSwap 后按合并资产重建声明并重取(无声明时零路径变化)
1010
+ // 新组件取得端口前先替换数据声明;旧端口不能取得新页面的数据写能力。
678
1011
  this.prepareDataLayer(this.domainInstance, merged);
679
1012
  if (this.dataConfig) {
680
1013
  void this.loadDataObjects();
681
1014
  }
1015
+ await this.buildRuntime(parsed);
1016
+ this.startDeclarativeTimers();
682
1017
 
683
1018
  if (snapshotId !== null) {
684
1019
  try {
@@ -687,7 +1022,7 @@ export class SomaBootstrap {
687
1022
  /* snapshot 与新区划不兼容时忽略 */
688
1023
  }
689
1024
  if (savedLocale) {
690
- this.domainInstance._locale = { ...savedLocale, ...parsed.locale } as Record<string, string>;
1025
+ this.domainInstance._locale = { ...savedLocale, ...this.localeTable(parsed.locale) } as Record<string, string>;
691
1026
  applyLocaleMetadata(this.domainInstance);
692
1027
  this.renderEngine?.render();
693
1028
  }
@@ -696,14 +1031,14 @@ export class SomaBootstrap {
696
1031
 
697
1032
  captureSnapshot(options?: { exclude?: string[] }): number {
698
1033
  if (!this.domainInstance) {
699
- throw new Error('[soma-core][引擎] Cannot capture snapshot before mount');
1034
+ throw new Error('[SomaBootstrap] Cannot capture snapshot before mount');
700
1035
  }
701
1036
  return this.snapshotStore.capture(this.domainInstance, options);
702
1037
  }
703
1038
 
704
1039
  restoreSnapshot(snapshotId: number): void {
705
1040
  if (!this.domainInstance) {
706
- throw new Error('[soma-core][引擎] Cannot restore snapshot before mount');
1041
+ throw new Error('[SomaBootstrap] Cannot restore snapshot before mount');
707
1042
  }
708
1043
  this.snapshotStore.restore(snapshotId, this.domainInstance);
709
1044
  this.renderEngine?.render();
@@ -711,7 +1046,7 @@ export class SomaBootstrap {
711
1046
 
712
1047
  batch(fn: () => void): void {
713
1048
  if (!this.proxy) {
714
- throw new Error('[soma-core][引擎] Cannot batch before mount');
1049
+ throw new Error('[SomaBootstrap] Cannot batch before mount');
715
1050
  }
716
1051
  this.proxy.beginBatch();
717
1052
  try {
@@ -722,7 +1057,7 @@ export class SomaBootstrap {
722
1057
  }
723
1058
 
724
1059
  async unmount(): Promise<void> {
725
- if (!this.mounted) return;
1060
+ if (!this.mounted && this.container === null) return;
726
1061
 
727
1062
  try {
728
1063
  if (this.domainInstance && typeof this.domainInstance.onUnmount === 'function') {
@@ -744,16 +1079,46 @@ export class SomaBootstrap {
744
1079
  return this.telemetry.snapshot();
745
1080
  }
746
1081
 
747
- getAvailableThemes(): string[] {
748
- return this.styleBinder?.getAvailableThemes() ?? [];
749
- }
750
-
751
1082
  getStyleBinder(): SomaStyleBinder | null {
752
1083
  return this.styleBinder;
753
1084
  }
754
1085
 
755
- switchTheme(themeName: string | null): void {
756
- this.styleBinder?.switchTheme(themeName);
1086
+ /**
1087
+ * 切换显示语言(2.2a,00e Q-163):只改当前语言并按词表重渲文案位(文本节点与属性位),
1088
+ * 不重编、不换产物、不重建 DOM 结构、不改类名;状态、草稿、窗口、焦点保留。
1089
+ * 语言不在词表内:记 `CORE-LOCALE-UNKNOWN` 诊断、保持当前语言、不抛。
1090
+ */
1091
+ setLocale(locale: string): void {
1092
+ if (!this.localeCatalog.setCurrentLocale(locale)) {
1093
+ const diagnostic = coreDiagnostic({
1094
+ code: 'CORE-LOCALE-UNKNOWN',
1095
+ severity: 'warning',
1096
+ situation: '切换显示语言',
1097
+ problem: `词表里没有语言 "${locale}"`,
1098
+ remedy: `确认语言标识与应用 locales 一致;已保持当前语言 "${this.localeCatalog.currentLocale()}"`,
1099
+ });
1100
+ this.diagnostics.recordValidation('warning', `[${diagnostic.code}] ${diagnostic.problem}。${diagnostic.remedy}。`);
1101
+ return;
1102
+ }
1103
+ this.refreshLocaleSurface();
1104
+ }
1105
+
1106
+ /** 当前显示语言(只读) */
1107
+ currentLocale(): string {
1108
+ return this.localeCatalog.currentLocale();
1109
+ }
1110
+
1111
+ /**
1112
+ * 运行出口专用:注入额外语言词表(伪本地化等测试语言)。不进根导出(AD-CORE-08)。
1113
+ * 之后可对该语言调 `setLocale`。
1114
+ */
1115
+ registerLocaleDictionary(locale: string, dictionary: Readonly<Record<string, string>>): void {
1116
+ this.localeCatalog.registerLocale(locale, dictionary);
1117
+ }
1118
+
1119
+ /** 编译端口每发起一次调用,同进程 Host / 测试替身调用本方法计入观测 `compileCalls`(未开观测时空操作) */
1120
+ noteCompileCall(): void {
1121
+ this.observer?.countCompileCall();
757
1122
  }
758
1123
 
759
1124
  /** 获取当前挂载的业务实例(测试 / 调试) */
@@ -767,15 +1132,19 @@ export class SomaBootstrap {
767
1132
 
768
1133
  isSettled(): boolean {
769
1134
  return this.isInitialized()
1135
+ && (this.componentManager?.isInitialized() ?? true)
770
1136
  && this.scheduler.isSettled()
771
1137
  && (this.domainInstance?._services?.http.pendingCount() ?? 0) === 0;
772
1138
  }
773
1139
 
774
1140
  async whenSettled(): Promise<void> {
775
- await this.scheduler.whenSettled();
776
- while (this.isInitialized() && (this.domainInstance?._services?.http.pendingCount() ?? 0) > 0) {
777
- await new Promise<void>((resolve) => setTimeout(resolve, 0));
778
- }
1141
+ do {
1142
+ await this.componentManager?.whenInitialized();
1143
+ await this.scheduler.whenSettled();
1144
+ while (this.isInitialized() && (this.domainInstance?._services?.http.pendingCount() ?? 0) > 0) {
1145
+ await new Promise<void>((resolve) => setTimeout(resolve, 0));
1146
+ }
1147
+ } while (this.isInitialized() && !this.isSettled());
779
1148
  }
780
1149
 
781
1150
  getDomainValue(path: string): unknown {
@@ -805,7 +1174,7 @@ export class SomaBootstrap {
805
1174
  /** 监听属性变更(委托 RenderEngine.watch) */
806
1175
  watch(path: string, callback: WatchCallback, options?: WatcherOptions): () => void {
807
1176
  if (!this.renderEngine) {
808
- throw new Error('[soma-core][引擎] Cannot watch before mount');
1177
+ throw new Error('[SomaBootstrap] Cannot watch before mount');
809
1178
  }
810
1179
  return this.renderEngine.watch(path, callback, options);
811
1180
  }
@@ -843,22 +1212,34 @@ export class SomaBootstrap {
843
1212
  });
844
1213
  }
845
1214
 
1215
+ /** 未登记的异步检查器:诊断走可观察通道,不抛(降级口径见 async-check-registry.ts 头注) */
1216
+ private reportUnregisteredAsyncChecks(objects: Parameters<typeof findUnregisteredAsyncChecks>[0]): void {
1217
+ const missing = findUnregisteredAsyncChecks(objects, this.validationService);
1218
+ if (missing.length === 0) return;
1219
+ const error = unregisteredAsyncCheckError(missing, this.validationService);
1220
+ console.error('[soma-core][引擎] 异步检查器未注册(只有引用它的规则不可用,页面其余部分照常):', error);
1221
+ this.captureEngineError(error);
1222
+ }
1223
+
846
1224
  /**
847
1225
  * 引擎自身捕获的异常进同一采集通道。
848
1226
  * 全局 error 监听抓不到这些——它们已经被引擎 catch 住了(页面不崩,但确实错了),
849
1227
  * 不显式补一条,可观测数据就会漏掉最该看的那类问题。
850
1228
  */
851
1229
  private captureEngineError(error: unknown): void {
1230
+ const code = (error as { code?: unknown } | null)?.code;
1231
+ this.observer?.recordError({ code: typeof code === 'string' ? code : 'CORE-RUNTIME-ERROR' });
852
1232
  this.errorReporter?.capture(error, 'runtime');
853
1233
  }
854
1234
 
855
1235
  private createDomainInstance(
856
- DomainClass: new () => SomaPageRoot,
1236
+ DomainClass: new () => SharedPageRoot,
857
1237
  parsed: ParsedRuntimeAssets,
858
1238
  routerPath?: string,
1239
+ routeAssets?: SomaPageAssets,
859
1240
  ): SomaPageRoot {
860
- const raw = new DomainClass();
861
- raw._locale = parsed.locale as Record<string, string>;
1241
+ const raw = new DomainClass() as SomaPageRoot;
1242
+ raw._locale = this.localeTable(parsed.locale);
862
1243
  if (parsed.appConfig) {
863
1244
  raw._config = parsed.appConfig as any;
864
1245
  }
@@ -866,9 +1247,23 @@ export class SomaBootstrap {
866
1247
 
867
1248
  raw._services = createDefaultRuntimeServices({
868
1249
  appConfig: parsed.appConfig,
869
- locale: parsed.locale,
1250
+ // 文案目录是 bootstrap 的(跨挂载同一个实例,词表已在 loadLocale 装入):services.i18n 就是它
1251
+ catalog: this.localeCatalog,
870
1252
  initialPath: routerPath ?? getBrowserUrlPath(),
1253
+ auth: this.authOption,
1254
+ ...(this.identityOption ? { identity: this.identityOption } : {}),
1255
+ navHistory: this.navHistoryInstance,
1256
+ renderPorts: this.renderPorts,
1257
+ engines: this.engines,
1258
+ engineTelemetry: this.telemetry,
1259
+ shortcuts: this.shortcutsInstance,
871
1260
  });
1261
+ raw._services.observation = this.observer ?? NOOP_OBSERVATION_CHANNEL;
1262
+ raw._services.nav = this.navStore.port;
1263
+ if (routeAssets !== undefined) {
1264
+ this.navStore.replace(routeAssets.nav);
1265
+ this.seedRouteContext(raw, routeAssets);
1266
+ }
872
1267
 
873
1268
  this.wireRouter(raw);
874
1269
 
@@ -883,7 +1278,52 @@ export class SomaBootstrap {
883
1278
  return raw;
884
1279
  }
885
1280
 
886
- // ─── 数据对象层(*_data.yaml,可选件) ─────────────────────
1281
+ /**
1282
+ * 把取页响应带来的地址参数与查询值装进页面根(E3,姊妹稿 §4.8):`page.params` 冻结(只读,写入被拒;
1283
+ * 声明面的写入已在编译期拒收),`page.query` 是可写的普通对象(回写地址栏由 `installDeclaredPageHooks` 的绑定负责)。
1284
+ * 没有参数 / 没有查询契约就什么也不装,不去占页面根上同名的成员。
1285
+ */
1286
+ private seedRouteContext(raw: SomaPageRoot, assets: SomaPageAssets): void {
1287
+ const target = raw as unknown as Record<string, unknown>;
1288
+ if (assets.pageParams !== undefined && Object.keys(assets.pageParams).length > 0) {
1289
+ target.params = Object.freeze({ ...assets.pageParams });
1290
+ }
1291
+ if (assets.queryContract !== undefined && Object.keys(assets.queryContract).length > 0) {
1292
+ target.query = { ...(assets.pageQuery ?? {}) };
1293
+ }
1294
+ }
1295
+
1296
+ /**
1297
+ * 同一页面模式下的客户端导航(E3):只换地址参数 / 查询值 / 导航目录,不重载页面、不重建运行时。
1298
+ * `page.params` 整体换成新的冻结对象,依赖它的数据对象按「依赖值变化即重取」的现有规则重取。
1299
+ * 返回是否生效(没有已挂载的页面时为 false,调用方应整页重挂)。
1300
+ */
1301
+ updateRouteContext(next: {
1302
+ readonly params?: Readonly<Record<string, string | number>>;
1303
+ readonly query?: Readonly<Record<string, string | number | boolean | null>>;
1304
+ readonly nav?: SomaNavView;
1305
+ }): boolean {
1306
+ const instance = this.domainInstance as unknown as Record<string, unknown> | null;
1307
+ if (instance === null || this.assets === null) return false;
1308
+ if (next.nav !== undefined) {
1309
+ this.navStore.replace(next.nav);
1310
+ this.assets = { ...this.assets, nav: next.nav };
1311
+ }
1312
+ if (next.params !== undefined) {
1313
+ // 页面根上原本没装 params 且新的也是空:不去占页面根上同名成员(与 seedRouteContext 同一规则)
1314
+ if (instance.params !== undefined || Object.keys(next.params).length > 0) {
1315
+ instance.params = Object.freeze({ ...next.params });
1316
+ }
1317
+ this.assets = { ...this.assets, pageParams: next.params };
1318
+ }
1319
+ if (next.query !== undefined && this.assets.queryContract !== undefined) {
1320
+ instance.query = { ...next.query };
1321
+ this.assets = { ...this.assets, pageQuery: next.query };
1322
+ }
1323
+ return true;
1324
+ }
1325
+
1326
+ // ─── 数据对象层(page 块 `data:`,Soma Data) ─────────────────────
887
1327
 
888
1328
  /**
889
1329
  * 首渲前解析数据对象声明并向 Domain 实例注入 reloadData 钩子。
@@ -891,25 +1331,59 @@ export class SomaBootstrap {
891
1331
  * 声明非法只 console.error,页面继续以空 data 挂载(不阻塞)。
892
1332
  */
893
1333
  private prepareDataLayer(instance: SomaPageRoot, assets: SomaPageAssets): void {
1334
+ this.invalidateDataResolver();
1335
+ this.disposeDataSubscriptions();
894
1336
  this.dataConfig = null;
895
1337
  this.dataReady = null;
896
1338
  this.dataDicts = {};
1339
+ instance._reloadData = undefined;
1340
+ instance.data = {};
897
1341
 
898
1342
  const hasDeclaration = assets.dataConfig !== undefined
899
1343
  || (typeof assets.dataYaml === 'string' && assets.dataYaml.trim() !== '');
900
1344
  if (!hasDeclaration) return;
901
1345
 
1346
+ const owner = this.dataOwnerEpoch;
902
1347
  try {
903
1348
  const config = assets.dataConfig ?? parseDataYaml(assets.dataYaml!);
904
1349
  if (Object.keys(config.objects).length === 0) return;
1350
+ // 字段规则 rules[].async 引用的检查器名:与具名动作同一时机核对。缺登记只让引用它的规则不可用(AD-45):
1351
+ // 报 CORE-ASYNC-CHECK-UNREGISTERED 诊断(captureEngineError + console),其余数据对象、字段、规则照常挂载
1352
+ this.reportUnregisteredAsyncChecks(config.objects);
905
1353
  this.dataConfig = config;
1354
+ // 数据变更订阅(REQ-019 D-5):后端在频道上推"哪些数据变了",按声明刷新;realtime 没配地址时静默不接
1355
+ if (config.subscribe && config.subscribe.length > 0) {
1356
+ this.dataSubscriptions = attachDataSubscriptions({
1357
+ subscriptions: config.subscribe,
1358
+ realtime: instance._services?.realtime,
1359
+ refresh: (names) => this.refreshDataObjects(owner, names),
1360
+ onError: (error) => this.captureEngineError(error),
1361
+ });
1362
+ }
1363
+ // 对象级轮询:声明了 poll 的对象,只要数据里还有命中 while 的记录就按 every 秒重取
1364
+ const polls = Object.values(config.objects)
1365
+ .filter((decl) => decl.poll !== undefined)
1366
+ .map((decl) => ({ name: decl.name, poll: decl.poll! }));
1367
+ if (polls.length > 0) {
1368
+ this.dataPolling = attachDataPolling({
1369
+ polls,
1370
+ read: (name) => this.dataResolver?.getObject(name),
1371
+ refresh: async (name) => {
1372
+ await this.refreshDataObjects(owner, [name]);
1373
+ if (owner !== this.dataOwnerEpoch) return;
1374
+ this.renderEngine?.render();
1375
+ this.componentManager?.refreshAll();
1376
+ },
1377
+ onError: (error) => this.captureEngineError(error),
1378
+ });
1379
+ }
906
1380
  } catch (error) {
907
1381
  console.error('[soma-core][数据] 数据对象声明解析失败(页面继续以空 data 挂载):', error);
908
1382
  this.captureEngineError(error);
909
1383
  return;
910
1384
  }
911
1385
 
912
- instance._reloadData = () => this.loadDataObjects();
1386
+ instance._reloadData = () => owner === this.dataOwnerEpoch ? this.loadDataObjects() : Promise.resolve();
913
1387
  }
914
1388
 
915
1389
  /**
@@ -923,6 +1397,9 @@ export class SomaBootstrap {
923
1397
  if (!instance || !config || !services) {
924
1398
  return Promise.resolve();
925
1399
  }
1400
+ this.invalidateDataResolver();
1401
+ const epoch = this.dataLoadEpoch;
1402
+ const isCurrent = (): boolean => epoch === this.dataLoadEpoch && this.domainInstance === instance;
926
1403
 
927
1404
  // api 声明允许写全路径(如 /api/order/detail):与 http 服务 baseURL 重叠时去重,
928
1405
  // 避免拼出 /api/api/... 的双前缀
@@ -943,42 +1420,56 @@ export class SomaBootstrap {
943
1420
  post: writeVerb('post'),
944
1421
  put: writeVerb('put'),
945
1422
  patch: writeVerb('patch'),
1423
+ // 删除(S-X1:write.delete 与 method: DELETE 的命令动作):此前这里漏接,Host 的 http 有 delete 也报「不支持」
1424
+ delete: typeof (services.http as unknown as Record<string, unknown>).delete === 'function'
1425
+ ? <T,>(url: string) => services.http.delete<T>(strip(url))
1426
+ : undefined,
946
1427
  };
947
1428
 
1429
+ if (!isCurrent()) return Promise.resolve();
1430
+ const resolver = new SomaDataObjectResolver(config, {
1431
+ http,
1432
+ query: (key) => readQueryParam(key, services.router.getCurrentPath()),
1433
+ page: () => this.domainInstance,
1434
+ pipes: this.pipeRegistry,
1435
+ locale: () => instance._locale as Record<string, unknown> | undefined,
1436
+ identity: services.identity,
1437
+ onFetch: this.observer ? (entry) => this.observer?.recordFetch(entry) : undefined,
1438
+ onReload: (objects) => {
1439
+ if (!isCurrent() || this.dataResolver !== resolver) return;
1440
+ instance.data = objects;
1441
+ this.renderEngine?.render();
1442
+ this.componentManager?.refreshAll();
1443
+ },
1444
+ // 401 / 403 → CORE-DATA-FORBIDDEN、外键批取失败 → CORE-DATA-RELATION:进诊断簿(不含角色值与键值)
1445
+ onDiagnostic: (diagnostic) => this.diagnostics.recordValidation(
1446
+ diagnostic.severity === 'error' ? 'error' : 'warning',
1447
+ `[${diagnostic.code}] ${diagnostic.situation}:${diagnostic.problem}。${diagnostic.remedy}`,
1448
+ ),
1449
+ });
1450
+ // 解析器换新:组件手里的 data 端口是稳定壳,调用时才取当前解析器(见 buildComponentServices)
1451
+ this.dataResolver = resolver;
1452
+
948
1453
  const task = Promise.resolve()
949
- .then(() => {
950
- const resolver = new SomaDataObjectResolver(config, {
951
- http,
952
- query: (key) => readQueryParam(key, services.router.getCurrentPath()),
953
- page: () => this.domainInstance,
954
- pipes: this.pipeRegistry,
955
- locale: () => instance._locale as Record<string, unknown> | undefined,
956
- });
957
- // 解析器换新:组件手里的 data 端口是稳定壳,调用时才取当前解析器(见 buildComponentServices)
958
- this.dataResolver = resolver;
959
- // 窗口是**自己会动**的:滚动触发取数、取数完成换行,这些都不经过页面的
960
- // 事件通道。不接这一下,滚动之后行取回来了但一帧都不重渲。
961
- resolver.setWindowChangeHandler(() => {
962
- this.renderEngine?.render();
963
- this.componentManager?.refreshAll();
964
- });
965
- return resolver.resolve();
966
- })
967
- .then((result) => {
968
- if (this.domainInstance !== instance) return; // 页面已卸载/热换,丢弃过期结果
1454
+ .then(async () => {
1455
+ if (!isCurrent() || this.dataResolver !== resolver) return;
1456
+ const result = await resolver.resolve();
1457
+ if (!isCurrent() || this.dataResolver !== resolver) return;
969
1458
  this.dataDicts = result.dicts;
970
- this.domainInstance.data = result.objects;
1459
+ instance.data = result.objects;
971
1460
  this.renderEngine?.render();
972
1461
  // 自治组件有自己的渲染引擎,页面重渲进不去。数据对象刚刚才到,
973
- // 而它们(FormConsole 的字典与回填、DetailConsole 的字段…)在挂载那一刻
1462
+ // 而它们(表单组件的字典与回填、详情组件的字段…)在挂载那一刻
974
1463
  // 读到的是空字典——不推这一下,它们会一直显示挂载时的空表单。
975
1464
  this.componentManager?.refreshAll();
1465
+ this.dataPolling?.arm();
976
1466
  })
977
1467
  .catch((error) => {
1468
+ if (!isCurrent()) return;
978
1469
  console.error('[soma-core][数据] 数据对象解析失败(data 保持空对象):', error);
979
1470
  this.captureEngineError(error);
980
- if (this.domainInstance === instance) {
981
- this.domainInstance.data = {};
1471
+ if (isCurrent()) {
1472
+ instance.data = {};
982
1473
  this.renderEngine?.render();
983
1474
  }
984
1475
  });
@@ -987,58 +1478,6 @@ export class SomaBootstrap {
987
1478
  return task;
988
1479
  }
989
1480
 
990
- /**
991
- * 主题派生注入:app.config 声明 theme.brand 时全库换装;配置非法只告警不阻断挂载。
992
- * 主题是引擎内建路径,不是 bootstrap 可注册能力。
993
- */
994
- private applyHostTheme(appConfig: unknown): void {
995
- const theme = (appConfig as { theme?: SomaThemeInput } | undefined)?.theme;
996
- if (!theme?.brand) {
997
- return;
998
- }
999
- this.reconcileThemeComponentTokens(theme);
1000
- try {
1001
- applyTheme(theme);
1002
- } catch (error) {
1003
- console.error('[soma-core][主题] 主题派生失败(保持默认令牌):', error);
1004
- this.captureEngineError(error);
1005
- }
1006
- }
1007
-
1008
- /**
1009
- * 组件令牌对账(REQ-009 M-1):`components: { Buton: { radius: … } }` 这样一个
1010
- * 拼写错误,不对账时的表现是**"改了没反应"**——变量确实写进了 :root,
1011
- * 只是没有任何组件读它。这类错误的排查成本远高于报错。
1012
- *
1013
- * 判据住在 `component/theme-component-tokens.ts`,而它此前**一个调用者都没有**
1014
- * (由 `verify:reachable` 查出)。这里是全仓唯一同时持有「主题输入」与
1015
- * 「这一页实际可用的组件表」的地方,所以对账只能发生在这一点上。
1016
- *
1017
- * 两条边界:
1018
- * · **只告警、不阻断换装**。主题是 app 级、全部页面共享的,组件表却是逐页的;
1019
- * 曾经对账与 applyTheme 同在一个 try 里,一条对不上就把整份品牌主题一起丢掉
1020
- * (全页回落默认令牌 + 一条"主题派生失败"),与"一个令牌没人读"的后果不成比例。
1021
- * · **组件表 = Host 级 + 页面级**,与 setupComponentManager 实际装配的那张表同一口径
1022
- * (页面同名胜出)。只看 Host 级的话,只在页面资产里注册的组件会被误报成未知组件。
1023
- * 拿不到组件表时(纯预览场景)按设计跳过,不猜。
1024
- */
1025
- private reconcileThemeComponentTokens(theme: SomaThemeInput): void {
1026
- // 只读查找视图,不是组件包合成——重名裁决与告警在 setupComponentManager 里已经做过
1027
- const components = { ...this.hostComponents, ...(this.assets?.components ?? {}) };
1028
- if (Object.keys(components).length === 0) {
1029
- return;
1030
- }
1031
- const issues = validateThemeComponentTokens(theme, components);
1032
- if (issues.length === 0) {
1033
- return;
1034
- }
1035
- const message = `主题的组件令牌段有 ${issues.length} 处对不上组件契约`
1036
- + '(主题照常生效;这些令牌会写进 :root,但当前页没有组件读它们):'
1037
- + `\n${issues.map((issue) => ` · ${issue}`).join('\n')}`;
1038
- console.warn(`[soma-core][主题] ${message}`);
1039
- this.diagnostics.recordValidation('warning', `[主题组件令牌] ${message}`);
1040
- }
1041
-
1042
1481
  /**
1043
1482
  * 组件可见的服务表:页面运行时服务 + data 端口(M-5)。
1044
1483
  *
@@ -1052,46 +1491,131 @@ export class SomaBootstrap {
1052
1491
  // 端口必须是**稳定壳**:组件实例在 activate 时就把 services 抓在手里,
1053
1492
  // 而数据解析器要到 loadDataObjects 之后才存在,且每次重取都换一个新的。
1054
1493
  // 直接注入解析器的话,组件会永久持有第一个(甚至是 null)。
1055
- return { ...base, data: this.createStableDataPort() };
1494
+ return {
1495
+ ...base,
1496
+ data: this.createStableDataPort(),
1497
+ observation: this.observer ?? NOOP_OBSERVATION_CHANNEL,
1498
+ // 异步字段检查器:按名取用应用登记的检查器(组件须在契约 services 声明 validation)
1499
+ validation: this.validationService,
1500
+ // 区域协调:`(scopeId, instanceId) => 端口`,组件管理器按调用实例包成 `(scopeId) => 端口`(filterServices)
1501
+ region: (scopeId: string, instanceId: string) => this.regionScopes.port(scopeId, instanceId),
1502
+ // 格式化器工厂:每次调用读当前显示语言(切换语言后下次取到新语言);缺省语言取应用缺省语言,
1503
+ // 占位与缺省时区取应用配置 `format:`(K1 ①;未配置时占位空串、时区随运行环境)
1504
+ format: () => this.createPageFormatter(),
1505
+ };
1506
+ }
1507
+
1508
+ /** 组件包词条登记(S5):先过形状判据,再按序登记进文案目录(后面的包优先) */
1509
+ private registerPackLocales(packs: readonly PackWithLocales[] | undefined): void {
1510
+ if (packs === undefined || packs.length === 0) return;
1511
+ const issues = packs.flatMap((pack) => pack.locales === undefined
1512
+ ? []
1513
+ : validatePackLocales(pack.locales, `locale.packs[${pack.name}].locales`));
1514
+ if (issues.length > 0) {
1515
+ throw new Error(
1516
+ `[SomaBootstrap] 组件包词条非法:\n${issues.map((issue) => ` · [${issue.code}] ${issue.message}`).join('\n')}`,
1517
+ );
1518
+ }
1519
+ registerComponentPackLocales(this.localeCatalog, packs);
1520
+ }
1521
+
1522
+ /**
1523
+ * 应用配置 `format:`(placeholder / time_zone / week_start)的当前值。装配期已在 createDefaultRuntimeServices
1524
+ * 校验过(越界即 CORE-FORMAT-CONFIG),这里按原值身份缓存;没有页面实例时为空缺省。
1525
+ */
1526
+ private clock(): SomaClockPort {
1527
+ if (this.clockOption !== undefined) return this.clockOption;
1528
+ const zone = this.formatDefaults().timeZone;
1529
+ if (this.derivedClock !== null && this.derivedClock.zone === zone) return this.derivedClock.clock;
1530
+ let clock: SomaClockPort;
1531
+ try {
1532
+ clock = createClock(zone === undefined ? {} : { timeZone: zone });
1533
+ } catch {
1534
+ clock = createClock(); // 时区非法:format 配置自己已报,这里退回 UTC,不让取数链抛
1535
+ }
1536
+ this.derivedClock = { zone, clock };
1537
+ return clock;
1538
+ }
1539
+
1540
+ private formatDefaults(): SomaFormatDefaults {
1541
+ const raw = this.domainInstance?._services?.config.get('format');
1542
+ if (this.formatDefaultsCache !== null && this.formatDefaultsCache.raw === raw) return this.formatDefaultsCache.value;
1543
+ let value: SomaFormatDefaults;
1544
+ try {
1545
+ value = parseFormatAppConfig(raw);
1546
+ } catch (error) {
1547
+ // 装配期没拦住(如热替换途中配置被改坏):不让每次渲染都抛,记一次诊断后按空缺省
1548
+ console.error('[soma-core][引擎] 应用配置 format: 非法,按缺省处理:', error);
1549
+ value = {};
1550
+ }
1551
+ this.formatDefaultsCache = { raw, value };
1552
+ return value;
1553
+ }
1554
+
1555
+ /** 页面格式化器:当前显示语言 + 应用缺省语言 + 应用配置 `format:` 的占位与时区 */
1556
+ private createPageFormatter(): SomaFormatter {
1557
+ const defaults = this.formatDefaults();
1558
+ return createFormatter({
1559
+ locale: this.localeCatalog.currentLocale(),
1560
+ fallbackLocale: this.localeCatalog.applicationDefaultLocale(),
1561
+ placeholder: defaults.placeholder ?? '',
1562
+ ...(defaults.timeZone !== undefined ? { timeZone: defaults.timeZone } : {}),
1563
+ });
1056
1564
  }
1057
1565
 
1058
1566
  /**
1059
- * 约束布局产物注入(REQ-011 接线 / CL-4)。
1567
+ * 页面样式的统一装载点(KC12 序 2 → 序 4):编译样式片、约束布局产物、区域产物样式表。
1060
1568
  *
1061
- * 运行时只认 `layout_css`——构建期解好的 CSS——按宿主类名注入一次。
1062
- * 收到的若是 `layout` 声明本身而没有产物,说明这页没走 `compilePageDeclaration`
1063
- * (直接把源 YAML 喂给了浏览器)。这里**不**代为求解:求解器在 core/build/,
1064
- * 进 client 就等于把「运行期零求解」这条结构性承诺撤回去。只把这件事说出来。
1569
+ * 运行时只认**产物**,逐字节注入,不改写、不排序、不补层、不解释内容;方言声明键(如 `layout`)
1570
+ * 没有产物只告警一次、不代算(KI-8:求解与演绎只在构建期 / 编译端口里发生,运行时零求解)。
1571
+ * 位置固定在组件分片(序 6)之前,级联顺序才稳定。
1065
1572
  */
1066
- private installLayoutCss(uiConfig: UiConfig): void {
1067
- if (uiConfig.layoutCss) {
1068
- injectStyleOnce(
1069
- `layout:${uiConfig.bind.obj}`,
1070
- uiConfig.layoutCss,
1071
- { nonce: this.componentStyleNonce ?? null },
1072
- );
1073
- return;
1573
+ private installPageStyles(assets: SomaPageAssets, uiConfig: UiConfig): void {
1574
+ const options = { nonce: this.componentStyleNonce ?? null };
1575
+ // 序 2:编译样式片(首片为层序声明,产出方义务)
1576
+ installCompiledStyles(assets.compiledStyles, options);
1577
+ // 序 3:约束布局产物,键内容寻址 `layout:<摘要>`(同键不同内容不会静默保留旧页)
1578
+ if (uiConfig.layoutCss !== undefined) {
1579
+ if (typeof uiConfig.layoutCss !== 'string') {
1580
+ throw new SomaUiConfigError('layoutCss 必须是字符串(CORE-STYLE-INVALID)', 'layoutCss');
1581
+ }
1582
+ injectStyleOnce(`layout:${fragmentHtmlFingerprint(uiConfig.layoutCss)}`, uiConfig.layoutCss, options);
1074
1583
  }
1075
- if (uiConfig.layout && Object.keys(uiConfig.layout).length > 0) {
1076
- console.warn(
1077
- `[soma-core][布局] 页面 "${uiConfig.bind.obj}" 声明了 layout: 段但没有构建期产物(layout_css)——`
1078
- + '声明未经 compilePageDeclaration 求解,本页不会产生任何布局样式。'
1079
- + '求解只在构建期发生(Registry 发布 / Host 预编译),运行时不代算。',
1080
- );
1584
+ // 序 4:片段载体样式表,键为产物自带的内容哈希 `<前缀>:<8hex>`(键值是数据,core 不解释)
1585
+ const artifact = uiConfig.fragments;
1586
+ if (artifact?.css && artifact.css_key) {
1587
+ injectStyleOnce(artifact.css_key, artifact.css, options);
1081
1588
  }
1589
+ this.warnUncompiledLayout(assets, uiConfig);
1082
1590
  }
1083
1591
 
1084
1592
  /**
1085
- * OOUI 演绎产物的 DOM 落点(REQ-014 最后一公里)。
1593
+ * 编译期声明键(`layout`)到了运行期却没有对应产物:说明这页没走编译。只告警,不代算(CORE-HOOK-UNCOMPILED)。
1594
+ */
1595
+ private warnUncompiledLayout(assets: SomaPageAssets, uiConfig: UiConfig): void {
1596
+ const declared = uiConfig as unknown as Readonly<Record<string, unknown>>;
1597
+ const layout = declared.layout ?? (typeof assets.uiYaml === "string" && /(?:^|\n)\s*layout\s*:/m.test(assets.uiYaml) ? true : undefined);
1598
+ if (layout !== undefined && layout !== null && (typeof layout !== "object" || Object.keys(layout as object).length > 0)) {
1599
+ if (uiConfig.layoutCss === undefined) {
1600
+ const message = `页面 "${uiConfig.bind?.obj ?? ""}" 的 layout: 声明没有构建期产物`
1601
+ + "——声明未经编译,本页不会产生对应界面或样式。求解与演绎只在构建期(Registry 发布 / Host 预编译)发生,运行时不代算。";
1602
+ console.warn(`[soma-core][引擎] [CORE-HOOK-UNCOMPILED] ${message}`);
1603
+ this.diagnostics.recordValidation("warning", `[CORE-HOOK-UNCOMPILED] ${message}`);
1604
+ }
1605
+ }
1606
+ }
1607
+
1608
+ /**
1609
+ * 编译产物片段的 DOM 落点。
1086
1610
  *
1087
1611
  * ── 为什么"没有这一步"是一种静默失败 ─────────────────────────────
1088
- * 在它之前,整条演绎链止于 `deduce()` 的返回值:六层全绿、`ooui_artifact`
1612
+ * 在它之前,整条演绎链止于 `deduce()` 的返回值:六层全绿、`fragments`
1089
1613
  * 在资产里、样式表也注入了,**页面上什么都没有**。而"锚点空着"与
1090
1614
  * "这块本来就没写内容"在浏览器里长得一模一样——没有异常、没有日志、
1091
1615
  * 截图里也分不开。这是最像成功的那种失败,所以落点必须有断言守着。
1092
1616
  *
1093
1617
  * ── 运行时收到产物就用,收到声明就拒绝代算 ───────────────────────
1094
- * 与 `installLayoutCss` / `installOouiArtifact` 同一条范式:本方法**只搬运**。
1618
+ * 与 `installLayoutCss` / `installFragmentHtml` 同一条范式:本方法**只搬运**。
1095
1619
  * 它不认识形态、不认识候选表、不认识组件契约——那些词汇住在 soma-ui,
1096
1620
  * 浏览器手里根本没有,代算出来的只会是一份猜的界面。
1097
1621
  *
@@ -1103,23 +1627,32 @@ export class SomaBootstrap {
1103
1627
  * `<script>` 虽然不执行,`<img onerror=…>` 却会立刻执行。所以注入前必须再核一道——
1104
1628
  * 这是纵深防御的最后一层,不因门口补齐而省掉。
1105
1629
  *
1106
- * 核的方式是**允许集**不是禁用集:`emitRegionHtml` 今天只产出
1107
- * `div` / `span` 两种标签与四个 `class` / `data-soma-*` 属性,
1108
- * 把这个全集写死,任何多出来的东西一律拒收。禁用集在这种两标签的产物上
1109
- * 严格更差——它只挡得住今天想得到的那几样。发射器哪天真加了新标签,
1110
- * 这里会**当场红**(而不是静默放行),红在写下的那天,这正是要的。
1630
+ * 核的方式是**允许集**不是禁用集:编译产物的 slot 出口会发射
1631
+ * `template[data-soma-slot]`,其余区域结构用 `div`;属性限于实例钩子、
1632
+ * 显隐门、slot 与 class。把这个全集写死,任何多出来的东西一律拒收。
1633
+ * 编译产物哪天真加了新形状,这里会**当场红**(而不是静默放行),红在写下的那天。
1111
1634
  *
1112
1635
  * 解析走 `<template>`:template 的内容是**惰性的**——不加载图片、不跑脚本,
1113
1636
  * 所以"先解析再检查"这个顺序本身不会触发任何东西。检查通过之后才搬进文档。
1114
1637
  */
1115
- private installOouiHtml(container: HTMLElement, uiConfig: UiConfig): void {
1116
- const artifact = uiConfig.oouiArtifact;
1117
- if (!artifact || artifact.regions.length === 0) return;
1638
+ private installFragmentHtml(container: HTMLElement, uiConfig: UiConfig): void {
1639
+ const artifact = uiConfig.fragments;
1640
+ if (!artifact || (artifact.regions.length === 0 && (artifact.degradedRegions?.length ?? 0) === 0)) return;
1118
1641
 
1642
+ const findSlotAnchor = (root: ParentNode, id: string): HTMLElement | null => {
1643
+ for (const anchor of root.querySelectorAll<HTMLElement>('[data-soma-id]')) {
1644
+ if (anchor.getAttribute(SOMA_ID_ATTR) === id) return anchor;
1645
+ }
1646
+ for (const slot of root.querySelectorAll<HTMLTemplateElement>('template[data-soma-slot]')) {
1647
+ const anchor = findSlotAnchor(slot.content, id);
1648
+ if (anchor) return anchor;
1649
+ }
1650
+ return null;
1651
+ };
1119
1652
  const doc = container.ownerDocument ?? (globalThis as { document?: Document }).document ?? null;
1120
1653
  if (!doc || typeof doc.createElement !== 'function') {
1121
1654
  // 非 DOM 容器(小程序 / RN 桥)。**说出来**:静默跳过的表现是
1122
- // "这个平台上演绎区域永远是空的",而那与"这页没写 ooui"分不开。
1655
+ // "这个平台上演绎区域永远是空的",而那与"这页没写片段"分不开。
1123
1656
  console.warn(
1124
1657
  `[soma-core][演绎] 页面 "${uiConfig.bind.obj}" 有 ${artifact.regions.length} 个演绎区域,`
1125
1658
  + '但当前容器没有 document,演绎 DOM 无法落地——'
@@ -1128,10 +1661,18 @@ export class SomaBootstrap {
1128
1661
  return;
1129
1662
  }
1130
1663
 
1664
+ // 访问期降级(KC15「降级产物」):产物带 degradedRegions 时按锚点写不可用标记,与装载期拒收同一渲染
1665
+ const degraded = artifact.degradedRegions ?? [];
1666
+ if (degraded.length > 0) {
1667
+ applyDegradedRegions(container, degraded, this.renderPorts?.regionFallback, this.localeCatalog);
1668
+ }
1669
+ const degradedAnchors = new Set(degraded.map((entry) => entry.anchor));
1670
+
1131
1671
  for (const region of artifact.regions) {
1132
- const host = this.adapter.findAnchor(container, region.anchor);
1672
+ if (degradedAnchors.has(region.anchor)) continue;
1673
+ const host = this.adapter.findAnchor(container, region.anchor) ?? findSlotAnchor(container, region.anchor);
1133
1674
  if (!host) {
1134
- // 构建期已对着锚点索引核过(`OOUI-SEM-ANCHOR-UNKNOWN`),这里还找不到,
1675
+ // 构建期已对着锚点索引核过(锚点未知的编译诊断),这里还找不到,
1135
1676
  // 说明 html 与 _ui.yaml 这两份资产不是同一次编译的产物。
1136
1677
  console.warn(
1137
1678
  `[soma-core][演绎] 演绎区域 "${region.anchor}" 在页面 HTML 里找不到锚点(data-soma-id)——`
@@ -1144,7 +1685,7 @@ export class SomaBootstrap {
1144
1685
  if (html.trim() === '') {
1145
1686
  console.warn(
1146
1687
  `[soma-core][演绎] 演绎区域 "${region.anchor}" 的产物里没有 html——`
1147
- + '这是一份旧格式(或手写)的 ooui_artifact。重新跑一次构建期编译'
1688
+ + '这是一份旧格式(或手写)的 fragments 载体。重新跑一次构建期编译'
1148
1689
  + '(compilePageDeclaration)即可,运行时不代为演绎。',
1149
1690
  );
1150
1691
  continue;
@@ -1154,65 +1695,71 @@ export class SomaBootstrap {
1154
1695
  // 按布尔标记的话,同一个锚点换了一份产物会被当成"已经注入过了"而跳过,
1155
1696
  // 表现是页面继续显示上一版的 DOM——渲染正常、内容是旧的、控制台一行都没有。
1156
1697
  // 与 `css_key` 用内容哈希是同一条理由,只是这一侧的作用域是单个锚点。
1157
- const fingerprint = oouiHtmlFingerprint(html);
1158
- if (host.getAttribute(SOMA_OOUI_REGION_ATTR) === fingerprint) continue;
1698
+ const fingerprint = fragmentHtmlFingerprint(html);
1699
+ if (host.getAttribute(SOMA_FRAGMENT_HOST_ATTR) === fingerprint) continue;
1159
1700
 
1160
1701
  const template = doc.createElement('template');
1161
1702
  // template 内容惰性:解析这一步不会加载资源、不会执行任何东西。
1162
1703
  template.innerHTML = html;
1163
- const offence = findOouiDomOffence(template.content);
1704
+ const offence = findFragmentDomOffence(template.content);
1164
1705
  if (offence !== null) {
1165
1706
  console.error(
1166
1707
  `[soma-core][演绎] 演绎区域 "${region.anchor}" 的产物 DOM 不在允许集内(${offence}),已拒绝注入。`
1167
1708
  + '产物随 _ui.yaml 走,而那份资产可以被手写、被改:发布期的注入面扫描虽然也扫 YAML 面,'
1168
1709
  + '但它只守"写进声明仓库"这个入口,绕过 Registry 的构建与发布后改资产都不经过它。'
1169
1710
  + '所以注入前这道结构闸门是最后一关——放行一次就等于把 innerHTML 交了出去。'
1170
- + '正常产物只含 div/span 与 class/data-soma-node/data-soma-id/data-soma-component。'
1171
- + '若这是发射器新加的合法形状,请同步 soma-bootstrap.ts 的 SOMA_OOUI_ALLOWED_TAGS / _ATTRS;'
1172
- + '否则请重新跑一次 compilePageDeclaration 生成产物,不要手写 ooui_artifact。',
1711
+ + '正常产物只含 div 与 template[data-soma-slot],以及 class、实例/显隐钩子属性。'
1712
+ + '若这是编译产物新加的合法形状,请同步 soma-bootstrap.ts 的 SOMA_FRAGMENT_ALLOWED_TAGS,属性则在 shared/hook-attributes 登记(inArtifact);'
1713
+ + '否则请重新跑一次 compilePageDeclaration 生成产物,不要手写 fragments 载体。',
1173
1714
  );
1174
1715
  continue;
1175
1716
  }
1176
1717
 
1718
+ // 统一寻址(AD-49):片段里的 data-soma-id 与页面(含其他已注入片段)合成一个 id 空间,重名拒绝注入。
1719
+ // 宿主现有子树即将被整块换掉,所以不计入「页面已有」。
1720
+ const clash = this.fragmentIdClashes(container, host, template.content);
1721
+ if (clash.length > 0) {
1722
+ const message = anchorDuplicateMessage(clash[0]!, [SOMA_ANCHOR_SITE_PAGE, anchorSiteOfFragment(region.anchor)])
1723
+ + (clash.length > 1 ? `(另有 ${clash.length - 1} 个重名 id)` : '');
1724
+ console.error(`[soma-core][演绎] 演绎区域 "${region.anchor}" 已拒绝注入:${message}`);
1725
+ this.diagnostics.recordValidation('error', message);
1726
+ continue;
1727
+ }
1728
+
1177
1729
  // 整块换掉而不是追加:锚点是产物的落点,重复挂载不该叠出两份 DOM。
1178
1730
  while (host.firstChild) host.removeChild(host.firstChild);
1179
1731
  host.appendChild(template.content);
1180
- host.setAttribute(SOMA_OOUI_REGION_ATTR, fingerprint);
1732
+ host.setAttribute(SOMA_FRAGMENT_HOST_ATTR, fingerprint);
1733
+ this.observer?.recordActivation({ kind: 'region', name: region.anchor, region: region.anchor });
1181
1734
  }
1182
1735
  }
1183
1736
 
1184
- /**
1185
- * OOUI 演绎产物注入(REQ-014 接线)。
1186
- *
1187
- * 与 `installLayoutCss` 逐点同构:运行时只认**产物**,收到声明本身只告警。
1188
- * 演绎链住在 core/build/ooui/,进 client 就等于把「运行期零演绎」这条
1189
- * 结构性承诺撤回去——而且浏览器手里根本没有候选表与组件契约,
1190
- * 代算出来的只会是一份猜的界面。
1191
- *
1192
- * 注入键用产物自带的**内容哈希**(`ooui:<sha256 前 8 位>`),不用页面名:
1193
- * `injectStyleOnce` 没有内容冲突检测(同键不同内容静默保留第一份),
1194
- * 按页面名命名的话,SPA 内路由切到同名不同产物的页面会继续用上一页的 CSS,
1195
- * 页面看着渲染正常、间距全错、控制台一行都没有。
1196
- * 位置紧接 `installLayoutCss`——都在组件实例挂载**之前**,级联顺序才稳定。
1197
- */
1198
- private installOouiArtifact(uiConfig: UiConfig): void {
1199
- const artifact = uiConfig.oouiArtifact;
1200
- if (artifact?.css && artifact.css_key) {
1201
- injectStyleOnce(
1202
- artifact.css_key,
1203
- artifact.css,
1204
- { nonce: this.componentStyleNonce ?? null },
1205
- );
1206
- return;
1737
+ /** 片段内容里与「页面其余部分」或片段自身重名的 data-soma-id(去重,保序);页面其余部分 = 容器去掉宿主现有子树 */
1738
+ private fragmentIdClashes(container: ParentNode, host: HTMLElement, fragment: ParentNode): string[] {
1739
+ const count = (scope: ParentNode, into: Map<string, number>): void => {
1740
+ for (const el of scope.querySelectorAll<HTMLElement>(`[${SOMA_ID_ATTR}]`)) {
1741
+ const id = el.getAttribute(SOMA_ID_ATTR);
1742
+ if (id) into.set(id, (into.get(id) ?? 0) + 1);
1743
+ }
1744
+ for (const slot of scope.querySelectorAll<HTMLTemplateElement>(`template[${SOMA_SLOT_ATTR}]`)) count(slot.content, into);
1745
+ };
1746
+ const page = new Map<string, number>();
1747
+ count(container, page);
1748
+ const replaced = new Map<string, number>();
1749
+ for (const child of Array.from(host.children)) {
1750
+ const own = child.getAttribute(SOMA_ID_ATTR);
1751
+ if (own) replaced.set(own, (replaced.get(own) ?? 0) + 1);
1752
+ count(child, replaced);
1753
+ if (child.hasAttribute(SOMA_SLOT_ATTR) && (child as HTMLTemplateElement).content) count((child as HTMLTemplateElement).content, replaced);
1207
1754
  }
1208
- if (artifact) return; // 有产物、只是这一版没有样式表(空间层未参与):正常,不吭声
1209
- if (uiConfig.ooui && Object.keys(uiConfig.ooui).length > 0) {
1210
- console.warn(
1211
- `[soma-core][演绎] 页面 "${uiConfig.bind.obj}" 声明了 ooui: 段但没有构建期产物(ooui_artifact)——`
1212
- + '声明未经 compilePageDeclaration 演绎,本页不会产生任何演绎界面。'
1213
- + '演绎只在构建期发生(Registry 发布 / Host 预编译),运行时不代算。',
1214
- );
1755
+ const incoming = new Map<string, number>();
1756
+ count(fragment, incoming);
1757
+ const clashes: string[] = [];
1758
+ for (const [id, times] of incoming) {
1759
+ const outside = (page.get(id) ?? 0) - (replaced.get(id) ?? 0);
1760
+ if (times > 1 || outside > 0) clashes.push(id);
1215
1761
  }
1762
+ return clashes;
1216
1763
  }
1217
1764
 
1218
1765
  /**
@@ -1265,9 +1812,8 @@ export class SomaBootstrap {
1265
1812
  if (config.url === true) {
1266
1813
  instance.onStateUpdated?.((next: SomaPageState) => {
1267
1814
  try {
1268
- const url = new URL(globalThis.location?.href ?? 'http://localhost/');
1269
- url.searchParams.set('s', encodePageState(next));
1270
- globalThis.history?.replaceState?.(null, '', url.toString());
1815
+ // 经 url-state 端口 replace(保留原 history.state:会话历史(REQ-019 S-1)靠它认出"这一项是本会话压的")
1816
+ createUrlStatePort().patch({ s: encodePageState(next) }, 'replace');
1271
1817
  } catch {
1272
1818
  /* 非浏览器环境(SSR / 测试):状态仍在内存里,只是不落 URL */
1273
1819
  }
@@ -1275,6 +1821,45 @@ export class SomaBootstrap {
1275
1821
  }
1276
1822
  }
1277
1823
 
1824
+ /**
1825
+ * 声明面钩子(WP3b-C):`state.query` 命名查询参数 ⇄ 页面路径(S6),应用配置 `a11y.motion` → 容器根
1826
+ * `data-soma-motion`(S7)。实现全在 `url-state/state-query-binding` 与 `a11y/motion-hook`,这里只接线。
1827
+ */
1828
+ private installDeclaredPageHooks(config: SomaPageStateConfig | undefined): void {
1829
+ this.disposeDeclaredPageHooks();
1830
+ const container = this.container;
1831
+ const services = this.domainInstance?._services;
1832
+ if (container && services) {
1833
+ const a11y = parseA11yAppConfig(services.config.get('a11y'));
1834
+ const hook = installMotionHook(container, a11y.motion);
1835
+ this.pageHookDisposers.push(() => hook.dispose());
1836
+ }
1837
+ const resolver = this.runtimeResolver;
1838
+ const watcher = this.propertyWatcher;
1839
+ // 信封 `query` 契约与 `state.query` 合并成一张绑定表(信封的 mode 优先,姊妹稿 §2.4)
1840
+ const queryBindings = queryBindingsFromContract(this.assets?.queryContract, config?.query);
1841
+ if (Object.keys(queryBindings).length > 0 && resolver && watcher) {
1842
+ const dispose = bindStateQuery(
1843
+ queryBindings,
1844
+ {
1845
+ read: (path) => resolver.readFromRoot(resolver.resolvePath(path)),
1846
+ write: (path, value) => { resolver.writeToRoot(path, value); this.renderEngine?.render(); },
1847
+ // 盯顶层段(前缀匹配)再重读整条路径:父对象整体替换(`page.filter = {...}`)也要同步
1848
+ watch: (path, onChange) => {
1849
+ const resolved = resolver.resolvePath(path);
1850
+ return watcher.watch(resolved.split('.')[0], () => onChange(resolver.readFromRoot(resolved)));
1851
+ },
1852
+ },
1853
+ createUrlStatePort(),
1854
+ );
1855
+ this.pageHookDisposers.push(dispose);
1856
+ }
1857
+ }
1858
+
1859
+ private disposeDeclaredPageHooks(): void {
1860
+ for (const dispose of this.pageHookDisposers.splice(0)) dispose();
1861
+ }
1862
+
1278
1863
  /** 当前路由路径;无 router 时回落 location */
1279
1864
  private routerPath(): string {
1280
1865
  const router = this.domainInstance?._services?.router;
@@ -1287,10 +1872,19 @@ export class SomaBootstrap {
1287
1872
  * 为什么在装配期查而不是运行期:运行期查的话,一个拼错的动作名要等到用户
1288
1873
  * 点了那个按钮才暴露,而暴露的形式是"点了没反应"——最难报障也最难复现的一种。
1289
1874
  */
1290
- private assertNamedActionsResolvable(events: readonly ParsedEvent[]): void {
1875
+ private assertNamedActionsResolvable(
1876
+ events: readonly ParsedEvent[],
1877
+ domain: SomaPageRoot | null = this.domainInstance,
1878
+ builtinActions: Readonly<Record<string, unknown>> | null = null,
1879
+ ): void {
1291
1880
  const missing = new Map<string, string[]>();
1292
- const check = (name: string, where: string): void => {
1293
- if (name === '' || this.namedActions[name] !== undefined) return;
1881
+ // 单条 `ACTION | 名字`(非编排)找不到应用具名动作时退到页面 Domain 同名方法(K1 ⑥,与 event-engine 同一查找序);
1882
+ // 编排步骤里的 `do: ACTION | 名字` 只认应用具名动作(step-runner 不回落 Domain)
1883
+ const domainHas = (name: string): boolean =>
1884
+ domain !== null && typeof (domain as unknown as Record<string, unknown>)[name] === 'function';
1885
+ const check = (name: string, where: string, allowDomain = false): void => {
1886
+ if (name === '' || Object.hasOwn(this.namedActions, name) || (builtinActions !== null && Object.hasOwn(builtinActions, name))) return;
1887
+ if (allowDomain && domainHas(name)) return;
1294
1888
  const list = missing.get(name) ?? [];
1295
1889
  list.push(where);
1296
1890
  missing.set(name, list);
@@ -1309,7 +1903,7 @@ export class SomaBootstrap {
1309
1903
  };
1310
1904
  for (const event of events) {
1311
1905
  const where = `${event.somaId}.${event.domEvent}`;
1312
- if (event.type === 'ACTION') check(String(event.funcPath ?? ''), where);
1906
+ if (event.type === 'ACTION') check(String(event.funcPath ?? ''), where, event.steps === undefined);
1313
1907
  if (event.steps) walkSteps(event.steps.steps, where);
1314
1908
  }
1315
1909
  if (missing.size === 0) return;
@@ -1318,9 +1912,10 @@ export class SomaBootstrap {
1318
1912
  .map(([name, wheres]) => ` "${name}" —— 用在 ${wheres.join('、')}`)
1319
1913
  .join('\n');
1320
1914
  throw new Error(
1321
- `[soma-core][引擎] 页面用到了未注册的具名动作:\n${lines}\n`
1915
+ `[SomaBootstrap] 页面用到了未注册的具名动作:\n${lines}\n`
1322
1916
  + ` 已注册:${known}\n`
1323
- + ' 在 configureSomaBootstrap 的 options.actions 里登记它们。'
1917
+ + ' 在 configureSomaBootstrap 的 options.actions(应用 browserMount.actions)里登记它们;'
1918
+ + '单条 ACTION 也可以是页面 Domain 的同名方法(编排步骤里的 ACTION 只认登记表)。'
1324
1919
  + '具名动作是 custom(script) 的替代:实现在 Host 代码里、有名字、可审计。',
1325
1920
  );
1326
1921
  }
@@ -1328,9 +1923,62 @@ export class SomaBootstrap {
1328
1923
  /**
1329
1924
  * 稳定的 data 端口壳:每次调用现取当前解析器(解析器暂缺时的兜底住在 createSomaDataPort 里,
1330
1925
  * 与端口的方法面同一处——测试守的就是这里注入的那一个端口)。
1926
+ *
1927
+ * 生成业务组件的单点命令 `command` / `commandBatch`(REQ-020 F-022 / R-039)走的也是这里的解析器取值函数:
1928
+ * 取值带数据归属代次,上一页(或热替换前)的组件手里的旧端口拿到的是 null,命令以失败结果返回,
1929
+ * 不会在新页面的数据上执行。所以转发就是这一个取值函数,不另写一份方法面。
1331
1930
  */
1332
1931
  private createStableDataPort(): SomaDataPort {
1333
- return createSomaDataPort(() => this.dataResolver);
1932
+ const owner = this.dataOwnerEpoch;
1933
+ const current = (): SomaDataObjectResolver | null => owner === this.dataOwnerEpoch ? this.dataResolver : null;
1934
+ const notReady = (action: string): { ok: false; message: string } => ({
1935
+ ok: false,
1936
+ message: `数据对象尚未就绪,无法${action}(本页可能没有在页面块声明 data:)`,
1937
+ });
1938
+ const port = {
1939
+ getObject: (name: string) => current()?.getObject(name),
1940
+ getObjectStatus: (name: string) => current()?.getObjectStatus(name),
1941
+ getDict: (name: string) => current()?.getDict(name) ?? {},
1942
+ submit: async (name: string, model: Record<string, unknown>, mode: 'create' | 'update', options?: Parameters<SomaDataObjectResolver['submit']>[3]) => {
1943
+ const resolver = current();
1944
+ if (!resolver) return notReady(`提交 "${name}"`);
1945
+ const result = await resolver.submit(name, model, mode, options);
1946
+ this.dataPolling?.arm(); // 写入后的重取可能带来新的进行中记录
1947
+ return result;
1948
+ },
1949
+ remove: async (name: string, target: Parameters<SomaDataObjectResolver['remove']>[1]) => {
1950
+ const resolver = current();
1951
+ return resolver ? resolver.remove(name, target) : notReady(`删除 "${name}" 的记录`);
1952
+ },
1953
+ reload: async (names?: readonly string[]) => {
1954
+ await current()?.reload(names === undefined ? undefined : [...names]);
1955
+ this.dataPolling?.arm();
1956
+ },
1957
+ validate: (name: string, model: Record<string, unknown>, trigger?: Parameters<SomaDataObjectResolver['validate']>[2]) =>
1958
+ current()?.validate(name, model, trigger) ?? {},
1959
+ writeOutcome: (scope: string) => this.writeOutcomeStore.get(scope),
1960
+ onWriteOutcome: (listener: (scope: string) => void) => this.writeOutcomeStore.subscribe(listener),
1961
+ clearWriteOptimistic: (scope: string, key?: string) => this.writeOutcomeStore.clearOptimistic(scope, key),
1962
+ clearOutcome: (scope: string) => this.writeOutcomeStore.clear(scope),
1963
+ };
1964
+ return port as unknown as SomaDataPort;
1965
+ }
1966
+
1967
+ /** 推送失效 → 刷新:对象 reload(依赖它的下游随 DAG 一起重取) */
1968
+ private async refreshDataObjects(owner: number, names: readonly string[]): Promise<void> {
1969
+ if (owner !== this.dataOwnerEpoch) return;
1970
+ const resolver = this.dataResolver;
1971
+ const config = this.dataConfig;
1972
+ if (!resolver || !config) return;
1973
+ const reload = names.filter((name) => config.objects[name] !== undefined);
1974
+ if (reload.length > 0) await resolver.reload(reload);
1975
+ }
1976
+
1977
+ private disposeDataSubscriptions(): void {
1978
+ this.dataSubscriptions?.dispose();
1979
+ this.dataSubscriptions = null;
1980
+ this.dataPolling?.dispose();
1981
+ this.dataPolling = null;
1334
1982
  }
1335
1983
 
1336
1984
  /** 组件管理器装配:无 components 资产时保持 null,组件能力整体旁路 */
@@ -1344,6 +1992,64 @@ export class SomaBootstrap {
1344
1992
  this.componentManager?.destroy();
1345
1993
  this.componentManager = null;
1346
1994
 
1995
+ // 一个定义都没有时组件能力整体旁路(既有行为)。
1996
+ const registry = this.buildComponentRegistry(assets);
1997
+ this.componentRegistry = registry;
1998
+ if (registry === null || registry.names().length === 0) {
1999
+ return;
2000
+ }
2001
+ this.componentManager = new SomaComponentManager({
2002
+ registry,
2003
+ scheduler: this.scheduler,
2004
+ diagnostics: this.diagnostics,
2005
+ pipeRegistry: this.pipeRegistry,
2006
+ componentDefaults: this.componentDefaults,
2007
+ styleOptions: { nonce: this.componentStyleNonce ?? null },
2008
+ treeArtifact: assets.artifact,
2009
+ observer: this.observer ?? undefined,
2010
+ i18n: this.localeCatalog,
2011
+ ...this.confirmGradedOption(),
2012
+ });
2013
+ this.componentManager.prepare(container, uiConfig);
2014
+ }
2015
+
2016
+ /**
2017
+ * 本页组件注册表:Host 级 + 页面级定义,过两道装配期闸门(REQ-009 P0)。一个定义都没有时返回 null。
2018
+ */
2019
+ /**
2020
+ * 按需组件补载:扫描本页引用到的组件名,命中 `lazyComponents` 且尚未在表里的才加载;
2021
+ * 加载出的定义模板里引用的组件名继续扫描,直到闭包补齐。
2022
+ */
2023
+ private async ensureLazyComponents(assets: SomaPageAssets): Promise<void> {
2024
+ if (Object.keys(this.lazyComponents).length === 0) return;
2025
+ const pageComponents = assets.components ?? {};
2026
+ const seen = new Set<string>();
2027
+ const queue = referencedComponentNames(assets);
2028
+ while (queue.length > 0) {
2029
+ const name = queue.pop()!;
2030
+ if (seen.has(name)) continue;
2031
+ seen.add(name);
2032
+ if (Object.hasOwn(this.hostComponents, name) || Object.hasOwn(pageComponents, name)) continue;
2033
+ const make = Object.hasOwn(this.lazyComponents, name) ? this.lazyComponents[name] : undefined;
2034
+ if (make === undefined) continue;
2035
+ let loading = this.lazyLoading.get(name);
2036
+ if (loading === undefined) {
2037
+ loading = make().then((def) => {
2038
+ if (def?.contract?.name !== name) {
2039
+ throw new Error(`[soma-core][组件] 按需组件 "${name}" 的工厂返回的定义契约名为 "${String(def?.contract?.name)}",与登记名不一致`);
2040
+ }
2041
+ return def;
2042
+ });
2043
+ this.lazyLoading.set(name, loading);
2044
+ loading.catch(() => { this.lazyLoading.delete(name); });
2045
+ }
2046
+ const def = await loading;
2047
+ this.hostComponents[name] = def;
2048
+ queue.push(...componentNamesInDefinition(def.templateHtml));
2049
+ }
2050
+ }
2051
+
2052
+ private buildComponentRegistry(assets: SomaPageAssets): SomaComponentRegistry | null {
1347
2053
  // Host 级注册(构造选项)+ 页面级资产。
1348
2054
  //
1349
2055
  // 页面同名仍然胜出(既有行为,不改),但**不再静默**:组件包体系为重名建了三道闸门
@@ -1366,10 +2072,7 @@ export class SomaBootstrap {
1366
2072
  }
1367
2073
  const defs = { ...this.hostComponents, ...pageComponents };
1368
2074
  if (Object.keys(defs).length === 0) {
1369
- // 一个组件都没有的页面不建管理器(展开、注册表、行钩子全是用不上的开销)。
1370
- // 管理器顺带做的那件事不能跟着一起没有:没走上 emit 路由的事件名告警由
1371
- // buildRuntime 里的 warnSubscriptionsWithoutComponents 单独补(见那里的注释)。
1372
- return;
2075
+ return null;
1373
2076
  }
1374
2077
 
1375
2078
  // 两道装配期闸门(REQ-009 P0):都在首屏之前跑,坏声明不进渲染。
@@ -1384,16 +2087,120 @@ export class SomaBootstrap {
1384
2087
 
1385
2088
  const registry = new SomaComponentRegistry();
1386
2089
  registry.registerAll(defs);
1387
- this.componentManager = new SomaComponentManager({
1388
- registry,
1389
- scheduler: this.scheduler,
1390
- diagnostics: this.diagnostics,
1391
- pipeRegistry: this.pipeRegistry,
1392
- componentDefaults: this.componentDefaults,
1393
- styleOptions: { nonce: this.componentStyleNonce ?? null },
1394
- treeArtifact: assets.artifact,
2090
+ return registry;
2091
+ }
2092
+
2093
+ /**
2094
+ * 区域协调作用域的装入(页面级 `scopes:`;`fragments.scopes` 在解析期已并入 `uiConfig.scopes`)。
2095
+ *
2096
+ * 先对账再装:声明自洽、点名的部件都是页面 HTML 直接声明的组件实例、实例 props 的 `region` 字面量与
2097
+ * `SCOPE` 路由点名的作用域都已声明(共享判据 `checkPageScopes`,构建期用同一份)。对不上记 error 诊断、
2098
+ * 控制台报一次,但仍装入——写权按声明核,没登记为 owner / 路径写者的实例一律写不进去,失败方向是拒绝而不是放行。
2099
+ * 无声明的页面 store 保持空,`services.region(...)` 一律取到 null。
2100
+ */
2101
+ private installRegionScopes(container: HTMLElement, uiConfig: UiConfig, events: readonly ParsedEvent[]): void {
2102
+ const scopes = uiConfig.scopes ?? uiConfig.fragments?.scopes;
2103
+ this.regionScopes.install(scopes ?? []);
2104
+ const issues = checkPageScopes({
2105
+ scopes,
2106
+ instances: this.collectPageInstanceIds(container),
2107
+ show: uiConfig.show,
2108
+ events,
2109
+ hooks: this.collectPageHookIds(container),
1395
2110
  });
1396
- this.componentManager.prepare(container, uiConfig);
2111
+ if (issues.length === 0) return;
2112
+ for (const diagnostic of scopeIssueDiagnostics(issues, { code: 'ERR-RUN-001', layer: 'run', file: uiConfig.bind.obj })) {
2113
+ const message = formatGenerationError(diagnostic);
2114
+ console.error(`[soma-core][引擎] ${message}`);
2115
+ this.diagnostics.recordValidation('error', message);
2116
+ }
2117
+ }
2118
+
2119
+ /** 页面 DOM 里全部带 `data-soma-id` 的元素的钩子 id(含 `<template data-soma-slot>` 内容;显隐门的落点集合) */
2120
+ private collectPageHookIds(root: ParentNode): Set<string> {
2121
+ const ids = new Set<string>();
2122
+ const walk = (scope: ParentNode): void => {
2123
+ for (const host of scope.querySelectorAll<HTMLElement>(`[${SOMA_ID_ATTR}]`)) {
2124
+ const id = host.getAttribute(SOMA_ID_ATTR);
2125
+ if (id) ids.add(id);
2126
+ }
2127
+ for (const slot of scope.querySelectorAll<HTMLTemplateElement>(`template[${SOMA_SLOT_ATTR}], template[${SOMA_ROLE_ATTR}]`)) walk(slot.content);
2128
+ };
2129
+ walk(root);
2130
+ return ids;
2131
+ }
2132
+
2133
+ /**
2134
+ * 区域协调的视图绑定:切片镜像写进页面状态(宿主片段里没有 `scope:` 段的组件的 prop 绑定读它),
2135
+ * 显隐门切换元素 `hidden`。在运行时与组件展开都就绪之后建;每次建运行时先解旧绑定再绑新的。
2136
+ */
2137
+ private bindRegionViews(uiConfig: UiConfig): void {
2138
+ this.regionViewsOff?.();
2139
+ this.regionViewsOff = null;
2140
+ const scopes = uiConfig.scopes ?? uiConfig.fragments?.scopes;
2141
+ const resolver = this.runtimeResolver;
2142
+ if (!this.container || !resolver || !scopes || !scopes.some((decl) => (decl.mirrors?.length ?? 0) > 0 || (decl.gates?.length ?? 0) > 0)) return;
2143
+ this.regionViewsOff = bindRegionScopeViews({
2144
+ store: this.regionScopes,
2145
+ decls: scopes,
2146
+ container: this.container,
2147
+ writeState: (path, value) => resolver.writeToRoot(path, value),
2148
+ });
2149
+ }
2150
+
2151
+ /** 页面 DOM 里直接声明的组件实例 id(含 `<template data-soma-slot>` 内容;复合组件定义模板里的子实例不在其中) */
2152
+ private collectPageInstanceIds(root: ParentNode): Set<string> {
2153
+ const ids = new Set<string>();
2154
+ const walk = (scope: ParentNode): void => {
2155
+ for (const host of scope.querySelectorAll<HTMLElement>(`[${SOMA_COMPONENT_ATTR}]`)) {
2156
+ const id = host.getAttribute(SOMA_ID_ATTR);
2157
+ if (id) ids.add(id);
2158
+ }
2159
+ for (const slot of scope.querySelectorAll<HTMLTemplateElement>(`template[${SOMA_SLOT_ATTR}], template[${SOMA_ROLE_ATTR}]`)) walk(slot.content);
2160
+ };
2161
+ walk(root);
2162
+ return ids;
2163
+ }
2164
+
2165
+ /**
2166
+ * 事件类型 `SCOPE` 的执行器:路由发起的切片写 / 窗口重取 / 语义事件。
2167
+ * 写权按发出事件的实例 id 核(与组件端口同一套规则);没有当页数据层时数据类落点报错而不静默。
2168
+ */
2169
+ private createScopeEventHandler(): SomaScopeEventHandler {
2170
+ return async (spec, { writer, payload }) => {
2171
+ switch (spec.verb) {
2172
+ case 'set':
2173
+ this.regionScopes.routeSet(spec, writer, payload);
2174
+ return;
2175
+ case 'semantic':
2176
+ this.regionScopes.emitSemantic(spec.scope, spec.semantic ?? '', payload);
2177
+ return;
2178
+ case 'session-focus':
2179
+ throw new Error(`SCOPE | session-focus | ${spec.scope}:当前不支持`);
2180
+ case 'window-reload': {
2181
+ const resolver = this.dataResolver;
2182
+ if (!resolver) throw new Error(`SCOPE | window-reload | ${spec.scope}:页面没有数据层`);
2183
+ const object = this.regionScopes.declOf(spec.scope)?.object;
2184
+ await resolver.reload(object === undefined ? undefined : [object]);
2185
+ return;
2186
+ }
2187
+ }
2188
+ };
2189
+ }
2190
+
2191
+ /**
2192
+ * 分级确认执行口(R-23),页面级与组件内事件引擎共用同一份:
2193
+ * 只有注入了通知渲染端口才把 typed / consent 交出去;否则引擎回落 plain。
2194
+ */
2195
+ private confirmGradedOption(): { confirmGraded?: (spec: SomaConfirmSpec) => boolean | Promise<boolean> } {
2196
+ if (!this.renderPorts?.notify) return {};
2197
+ return {
2198
+ confirmGraded: (spec: SomaConfirmSpec) => {
2199
+ const notify = this.domainInstance?._services?.notify;
2200
+ // 应用没开 notify.toast 时服务无渲染器(无头恒真):不能让 typed / consent 被它放行,回落 plain
2201
+ return notify?.hasRenderer ? notify.confirm(spec) : this.adapter.confirm(spec.text);
2202
+ },
2203
+ };
1397
2204
  }
1398
2205
 
1399
2206
  private async buildRuntime(parsed: ParsedRuntimeAssets): Promise<void> {
@@ -1410,6 +2217,8 @@ export class SomaBootstrap {
1410
2217
  const runtime = this.runtimeBuilder.build({
1411
2218
  container: this.container,
1412
2219
  adapter: this.adapter,
2220
+ // 分级确认(R-23):只有注入了通知渲染端口才把 typed / consent 交出去;否则引擎回落 plain
2221
+ ...this.confirmGradedOption(),
1413
2222
  uiConfig: parsed.uiConfig,
1414
2223
  eventConfig: parsed.eventConfig,
1415
2224
  triggers: parsed.triggers,
@@ -1421,8 +2230,11 @@ export class SomaBootstrap {
1421
2230
  renderMiddleware: this.renderMiddleware,
1422
2231
  eventMiddleware: this.eventMiddleware,
1423
2232
  pipeRegistry: this.pipeRegistry,
1424
- adaptiveVocabulary: this.adaptiveVocabulary,
1425
2233
  repeatPlans: this.assets?.artifact?.repeatPlans,
2234
+ // 契约 a11y 段 → 页面期地标检查(同页同 landmark 多实例须各有名且不重名);无组件时不检查
2235
+ ...(this.componentRegistry !== null
2236
+ ? { contractA11yOf: (name: string) => this.componentRegistry?.contractA11yOf(name) }
2237
+ : {}),
1426
2238
  });
1427
2239
 
1428
2240
  this.parsedTimers = parsed.timers;
@@ -1431,31 +2243,31 @@ export class SomaBootstrap {
1431
2243
  this.eventEngine = runtime.eventEngine;
1432
2244
  // 具名动作下发 + 装配期对账(AO-3)
1433
2245
  this.eventEngine.setNamedActions(this.namedActions);
1434
- this.assertNamedActionsResolvable(parsed.eventConfig);
2246
+ // MV-EVT-2:写入事件(data.submit / data.orderMove)由 core 内置动作执行并把结构化结果写回数据层
2247
+ const writeEngine = this.eventEngine;
2248
+ const builtinActions = createDataWriteActions({ resolver: () => this.dataResolver, store: this.writeOutcomeStore });
2249
+ writeEngine.setBuiltinActions(builtinActions);
2250
+ this.eventEngine.setScopeHandler(this.createScopeEventHandler());
2251
+ this.eventEngine.setRoleGate((roles) => this.domainInstance?._services?.permission?.hasAnyRole([...roles]) === true);
2252
+ this.assertNamedActionsResolvable(parsed.eventConfig, this.domainInstance, builtinActions);
1435
2253
  this.installPageState(parsed.uiConfig.state);
1436
- this.installLayoutCss(parsed.uiConfig);
1437
- this.installOouiArtifact(parsed.uiConfig);
2254
+ this.bindRegionViews(parsed.uiConfig);
1438
2255
  this.styleBinder = runtime.styleBinder;
1439
2256
  this.propertyWatcher = runtime.propertyWatcher;
2257
+ this.installDeclaredPageHooks(parsed.uiConfig.state);
1440
2258
  this.onChangeEngine = runtime.onChangeEngine;
1441
2259
  this.triggerEngine = runtime.triggerEngine;
1442
2260
  this.timerEngine = runtime.timerEngine;
1443
2261
 
1444
2262
  // 组件实例挂载(页面引擎就绪后:emit 路由标记、props watch、行内钩子)
1445
- if (this.componentManager) {
1446
- this.componentManager.activate({
1447
- container: this.container,
1448
- renderEngine: runtime.renderEngine,
1449
- eventEngine: runtime.eventEngine,
1450
- resolver: runtime.resolver,
1451
- manifest: runtime.manifest,
1452
- services: this.buildComponentServices(),
1453
- });
1454
- } else {
1455
- // 没有注册任何组件的页面:管理器不建,但它顺带做的事件名告警要补上——
1456
- // 否则 `card.reach_limit` 这种笔误在这类页面全程静默(解析期那条只认 33 个 DOM 专有名字)。
1457
- warnSubscriptionsWithoutComponents(runtime.manifest, this.container);
1458
- }
2263
+ this.componentManager?.activate({
2264
+ container: this.container,
2265
+ renderEngine: runtime.renderEngine,
2266
+ eventEngine: runtime.eventEngine,
2267
+ resolver: runtime.resolver,
2268
+ manifest: runtime.manifest,
2269
+ services: this.buildComponentServices(),
2270
+ });
1459
2271
 
1460
2272
  // 界面中途提交接线:Domain 在长任务里调 `this.publishUi()` 时,
1461
2273
  // 把此刻积累的 patch 立刻上屏而不结束事件事务(见 SomaRuntimeServices.ui)
@@ -1495,17 +2307,110 @@ export class SomaBootstrap {
1495
2307
  }
1496
2308
  }
1497
2309
 
2310
+
2311
+ // ─── 多语言(2.2a:词表 → 当前显示语言 → 文案位) ─────────────────
2312
+
2313
+ /** 词表装入文案目录(先清上一页的)并定当前显示语言:用户选定的 > 挂载选项 initial > 词表缺省语言 */
2314
+ private loadLocale(locale: SomaLocaleBundle | Record<string, unknown>): void {
2315
+ this.lastLocale = locale;
2316
+ this.localeCatalog.reset();
2317
+ this.localeCatalog.loadBundle(locale as SomaLocaleBundle | Record<string, string>);
2318
+ if (this.preferredLocale !== undefined) this.localeCatalog.setCurrentLocale(this.preferredLocale);
2319
+ }
2320
+
2321
+ /** 页面 `_locale` 绑定表(`page._locale.<键>`):词表信封取当前显示语言的词条;无词表为空表 */
2322
+ private localeTable(locale: SomaLocaleBundle | Record<string, unknown>): Record<string, string> {
2323
+ return isLocaleBundle(locale) ? this.localeCatalog.dictionary() : {};
2324
+ }
2325
+
2326
+ /** 缺词条回退上报(ERR-LOCALE-001,soma-ui 码表;不抛、不中断渲染) */
2327
+ private reportLocaleMissing(event: SomaLocaleMissingEvent): void {
2328
+ this.diagnostics.recordValidation(
2329
+ 'warning',
2330
+ `[ERR-LOCALE-001] 语言 "${event.locale}" 缺词条 "${event.key}",`
2331
+ + (event.fellBackTo === null ? '已返回键名。' : `已回退到 "${event.fellBackTo}"。`),
2332
+ );
2333
+ }
2334
+
2335
+ /** 文案位登记并首次渲染;之后新增的节点(组件展开、行克隆)由观察器自动登记 */
2336
+ private bindLocaleSlots(container: HTMLElement): void {
2337
+ this.stopLocaleObserver?.();
2338
+ this.localeBinder.collect(container);
2339
+ this.localeBinder.rerender(this.localeCatalog);
2340
+ this.stopLocaleObserver = this.localeBinder.observe(container, this.localeCatalog);
2341
+ }
2342
+
2343
+ private releaseLocaleSlots(): void {
2344
+ this.stopLocaleObserver?.();
2345
+ this.stopLocaleObserver = null;
2346
+ if (this.container) this.localeBinder.release(this.container);
2347
+ }
2348
+
2349
+ /** 切换显示语言后只重渲文案:文案位 + `_locale` 绑定表;不建 / 删节点、不改类名 */
2350
+ private refreshLocaleSurface(): void {
2351
+ this.preferredLocale = this.localeCatalog.currentLocale();
2352
+ this.localeBinder.rerender(this.localeCatalog);
2353
+ if (this.domainInstance && isLocaleBundle(this.lastLocale)) {
2354
+ this.domainInstance._locale = this.localeTable(this.lastLocale);
2355
+ applyLocaleMetadata(this.domainInstance);
2356
+ this.renderEngine?.render();
2357
+ this.componentManager?.refreshAll();
2358
+ }
2359
+ }
2360
+
1498
2361
  private wireRouter(raw: SomaPageRoot): void {
1499
2362
  const services = raw._services;
1500
2363
  if (!services) return;
1501
2364
 
1502
2365
  this.routerUnsubscribe?.();
1503
- this.adapter.setNavigateHandler?.((url) => {
1504
- void services.router.navigate(url);
2366
+ this.adapter.setNavigateHandler?.((url, options) => {
2367
+ void services.router.navigate(url, options?.replace === true ? { replace: true } : undefined);
1505
2368
  });
1506
2369
  }
1507
2370
 
2371
+ /** 只读观测快照;未开启观测返回 null(inspect/runtime 的 observe 据此抛可辨认错误) */
2372
+ readObservation(): RuntimeObservation | null {
2373
+ return this.observer ? this.observer.snapshot() : null;
2374
+ }
2375
+
2376
+ /** `observe: true` 时创建采集器并安装浏览器全局(getter:每次读取最新快照);关闭时什么都不做 */
2377
+ private setupObserver(container: HTMLElement): void {
2378
+ if (!this.observeEnabled || this.observer !== null) return;
2379
+ this.observer = createRuntimeObserver(container, this.diagnostics);
2380
+ if (typeof window !== 'undefined') {
2381
+ Object.defineProperty(window, '__somaObserve', {
2382
+ configurable: true,
2383
+ enumerable: false,
2384
+ get: () => this.observer?.snapshot(),
2385
+ });
2386
+ // 测试 / 浏览器自动化切换显示语言的入口:同样只在观测开启时安装(生产不暴露)
2387
+ Object.defineProperty(window, '__somaSetLocale', {
2388
+ configurable: true,
2389
+ enumerable: false,
2390
+ value: (locale: string) => this.setLocale(locale),
2391
+ });
2392
+ }
2393
+ }
2394
+
2395
+ private teardownObserver(): void {
2396
+ this.observer?.dispose();
2397
+ this.observer = null;
2398
+ if (typeof window !== 'undefined' && Object.getOwnPropertyDescriptor(window, '__somaObserve')) {
2399
+ delete (window as unknown as { __somaObserve?: unknown }).__somaObserve;
2400
+ }
2401
+ if (typeof window !== 'undefined' && Object.getOwnPropertyDescriptor(window, '__somaSetLocale')) {
2402
+ delete (window as unknown as { __somaSetLocale?: unknown }).__somaSetLocale;
2403
+ }
2404
+ }
2405
+
1508
2406
  private cleanup(): void {
2407
+ this.teardownObserver();
2408
+ this.releaseLocaleSlots();
2409
+ this.regionViewsOff?.();
2410
+ this.regionViewsOff = null;
2411
+ this.regionScopes.clear();
2412
+ this.dataOwnerEpoch += 1;
2413
+ this.invalidateDataResolver();
1509
2414
  this.scheduler.cancelAll('unmount');
1510
2415
  this.stopDeclarativeTimers();
1511
2416
  this.componentManager?.destroy();
@@ -1520,10 +2425,14 @@ export class SomaBootstrap {
1520
2425
 
1521
2426
  this.routerUnsubscribe?.();
1522
2427
  this.routerUnsubscribe = null;
2428
+ this.componentRegistry = null;
2429
+ this.formatDefaultsCache = null;
2430
+ this.disposeDeclaredPageHooks();
1523
2431
 
1524
2432
  this.errorReporter?.dispose();
1525
2433
  this.errorReporter = null;
1526
2434
 
2435
+ this.disposeDataSubscriptions();
1527
2436
  this.dataConfig = null;
1528
2437
  this.dataReady = null;
1529
2438
  this.dataDicts = {};
@@ -1543,4 +2452,10 @@ export class SomaBootstrap {
1543
2452
  this.assets = null;
1544
2453
  setActiveTelemetry(null);
1545
2454
  }
2455
+
2456
+ private invalidateDataResolver(): void {
2457
+ this.dataLoadEpoch += 1;
2458
+ this.dataResolver?.dispose();
2459
+ this.dataResolver = null;
2460
+ }
1546
2461
  }