soma-core 1.3.2 → 1.3.4

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 (281) hide show
  1. package/README.md +43 -0
  2. package/app/SomaPageClient.tsx +22 -68
  3. package/app/[...path]/page.tsx +7 -6
  4. package/app/api/[...path]/route.ts +3 -3
  5. package/app/api/soma-registry/[...path]/route.ts +67 -0
  6. package/app/components/SomaHostPage.tsx +3 -8
  7. package/app/components/SomaPageClientBoundary.tsx +13 -0
  8. package/app/layout.tsx +6 -1
  9. package/app/page.tsx +3 -3
  10. package/app/soma/manifest/route.ts +1 -0
  11. package/app/soma/page-object/route.ts +1 -1
  12. package/bin/soma-lsp.cjs +1 -4
  13. package/core/build/compiler/full-manifest-builder.ts +19 -23
  14. package/core/build/compiler/html-include-expander.ts +56 -0
  15. package/core/build/compiler/page-assets.ts +26 -0
  16. package/core/build/compiler/page-declaration-compiler.ts +85 -0
  17. package/core/build/compiler/rollup-plugin-soma.ts +4 -13
  18. package/core/build/compiler/route-builder.ts +0 -2
  19. package/core/build/compiler/rspack-plugin-soma.js +1 -10
  20. package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -9
  21. package/core/build/compiler/soma-precompile.js +3581 -2387
  22. package/core/build/compiler/soma-precompile.ts +44 -2
  23. package/core/build/compiler/soma-rspack-yaml-loader.js +5 -8
  24. package/core/build/compiler/soma-webpack-loader.js +6 -15
  25. package/core/build/compiler/vite-plugin-soma.ts +9 -21
  26. package/core/build/component/pack-from-dir.ts +58 -0
  27. package/core/build/component/package-loader.ts +281 -0
  28. package/core/build/eject/apply-eject.ts +133 -0
  29. package/core/build/eject/plan-eject.ts +133 -0
  30. package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
  31. package/core/build/lsp/extra-completion.cjs +14 -8
  32. package/core/build/lsp/lsp-navigation.cjs +50 -43
  33. package/core/build/lsp/soma-declaration.cjs +85 -0
  34. package/core/build/lsp/ui-yaml-completion.cjs +98 -104
  35. package/core/build/v2/block-compile.ts +200 -0
  36. package/core/build/v2/block-loader.ts +33 -0
  37. package/core/build/v2/html-index.ts +120 -0
  38. package/core/build/v2/migrate-v1.ts +370 -0
  39. package/core/build/v2/soma-file-loader.ts +216 -0
  40. package/core/client/adaptive/flush-scheduler.ts +96 -0
  41. package/core/client/adaptive/hysteresis.ts +56 -0
  42. package/core/client/adaptive/index.ts +23 -0
  43. package/core/client/adaptive/observer-pool.ts +90 -0
  44. package/core/client/base/SomaPageRootBase.ts +50 -0
  45. package/core/client/compiler/adaptive-compile.ts +136 -0
  46. package/core/client/compiler/manifest-compiler.ts +155 -27
  47. package/core/client/component/ai-catalog.ts +277 -0
  48. package/core/client/component/component-definition.types.ts +65 -0
  49. package/core/client/component/component-expander.ts +119 -0
  50. package/core/client/component/component-manager.ts +933 -0
  51. package/core/client/component/component-pack.ts +445 -0
  52. package/core/client/component/component-registry.ts +71 -0
  53. package/core/client/component/contract-compat.ts +132 -0
  54. package/core/client/component/example-v2.ts +132 -0
  55. package/core/client/component/pack-styles.ts +94 -0
  56. package/core/client/component/scoped-adapter.ts +85 -0
  57. package/core/client/component/verify-pack.ts +247 -0
  58. package/core/client/container/MiniProgramContainerAdapter.ts +15 -1
  59. package/core/client/container/ReactNativeContainerAdapter.ts +15 -1
  60. package/core/client/container/SomaContainerAdapter.ts +186 -180
  61. package/core/client/data/data-object-resolver.ts +417 -0
  62. package/core/client/diagnostics/SomaDiagnostics.ts +187 -186
  63. package/core/client/diagnostics/boot-timings.ts +152 -0
  64. package/core/client/engine/asset-resolver.ts +12 -2
  65. package/core/client/engine/dom-renderer.ts +249 -24
  66. package/core/client/engine/emit-event.ts +21 -0
  67. package/core/client/engine/event-engine.ts +34 -4
  68. package/core/client/engine/on-change-engine.ts +1 -1
  69. package/core/client/engine/property-watcher.ts +1 -1
  70. package/core/client/engine/reactive-proxy.ts +11 -10
  71. package/core/client/engine/render-engine.ts +39 -4
  72. package/core/client/engine/runtime-builder.ts +23 -0
  73. package/core/client/engine/soma-bootstrap.ts +380 -7
  74. package/core/client/engine/style-binder.ts +47 -1
  75. package/core/client/observability/error-reporter.ts +173 -0
  76. package/core/client/parser/adaptive-parser.ts +264 -0
  77. package/core/client/parser/data-config-parser.ts +396 -0
  78. package/core/client/parser/pipeline-parser.ts +15 -3
  79. package/core/client/parser/style-config-parser.ts +65 -2
  80. package/core/client/parser/ui-config-parser.ts +52 -3
  81. package/core/client/parser/v2/namespace.ts +182 -0
  82. package/core/client/parser/v2/page-parser.ts +359 -0
  83. package/core/client/parser/v2/use-parser.ts +412 -0
  84. package/core/client/parser/value-lang.ts +340 -0
  85. package/core/client/pipes/pipe-registry.ts +249 -0
  86. package/core/client/quality/SomaQualityRegistry.ts +3 -0
  87. package/core/client/registry/declaration-renderer.ts +161 -0
  88. package/core/client/registry/index.ts +28 -0
  89. package/core/client/registry/page-lifecycle.ts +171 -0
  90. package/core/client/registry/remote-page.ts +139 -0
  91. package/core/client/runtime/SomaRuntimeServices.ts +24 -0
  92. package/core/client/security/attribute-presence.ts +70 -0
  93. package/core/client/security/html-sanitizer.ts +113 -0
  94. package/core/client/security/url-guard.ts +0 -0
  95. package/core/client/theme/harmony.ts +307 -0
  96. package/core/client/theme/scene-tokens.ts +134 -0
  97. package/core/client/theme/theme-axes.ts +228 -0
  98. package/core/client/theme/theme-engine.ts +1196 -0
  99. package/core/client/theme/tone-solver.ts +118 -0
  100. package/core/client/typography/typography-base.ts +34 -0
  101. package/core/client/validation/contract-validator.ts +48 -5
  102. package/core/index.ts +262 -2
  103. package/core/server/api/IService.ts +18 -6
  104. package/core/server/api/load-host-service.ts +3 -3
  105. package/core/server/host/content-security-policy.ts +190 -0
  106. package/core/server/host/csp-nonce-metadata.ts +75 -0
  107. package/core/server/host/resolve-host-request-hook.ts +5 -0
  108. package/core/server/host/server-page-assets.ts +34 -7
  109. package/core/server/host/soma-page-compile.ts +33 -0
  110. package/core/server/index.ts +45 -1
  111. package/core/server/infra/cache/ServerFileCache.ts +1 -1
  112. package/core/server/mock/node/cli.mjs +2 -2
  113. package/core/server/registry/api-registry-store.ts +518 -0
  114. package/core/server/registry/conditional-object-store.ts +29 -0
  115. package/core/server/registry/declaration-precompiler.ts +99 -0
  116. package/core/server/registry/in-memory-conditional-object-store.ts +43 -0
  117. package/core/server/registry/index.ts +142 -0
  118. package/core/server/registry/page-registry-repository.ts +373 -0
  119. package/core/server/registry/page-registry-store.ts +932 -0
  120. package/core/server/registry/registry-error.ts +17 -0
  121. package/core/server/registry/registry-file-lock.ts +173 -0
  122. package/core/server/registry/registry-response.ts +71 -0
  123. package/core/server/registry/registry-subjects.ts +194 -0
  124. package/core/server/registry/registry-write-pipeline.ts +240 -0
  125. package/core/server/registry/request-body-limit.ts +99 -0
  126. package/core/server/registry/services/apis/Get.ts +25 -0
  127. package/core/server/registry/services/apis/List.ts +41 -0
  128. package/core/server/registry/services/apis/Register.ts +39 -0
  129. package/core/server/registry/services/apis/Unregister.ts +24 -0
  130. package/core/server/registry/services/index.ts +40 -0
  131. package/core/server/registry/services/pages/Get.ts +96 -0
  132. package/core/server/registry/services/pages/List.ts +53 -0
  133. package/core/server/registry/services/pages/Register.ts +49 -0
  134. package/core/server/registry/services/pages/Rollback.ts +36 -0
  135. package/core/server/registry/services/pages/Unregister.ts +23 -0
  136. package/core/server/registry/services/service-utils.ts +21 -0
  137. package/core/server/registry/validation/compile-gate.ts +54 -0
  138. package/core/server/registry/validation/component-existence.ts +55 -0
  139. package/core/server/registry/validation/credential-ban.ts +86 -0
  140. package/core/server/registry/validation/cross-check.ts +67 -0
  141. package/core/server/registry/validation/declaration-safety-scan.ts +102 -0
  142. package/core/shared/types/adaptive.types.ts +109 -0
  143. package/core/shared/types/component-contract.types.ts +120 -0
  144. package/core/shared/types/data-config.types.ts +105 -0
  145. package/core/shared/types/domain.types.ts +6 -0
  146. package/core/shared/types/engine.types.ts +41 -35
  147. package/core/shared/types/manifest.types.ts +55 -32
  148. package/core/shared/types/scope-manifest.types.ts +96 -0
  149. package/core/shared/types/style-config.types.ts +9 -0
  150. package/core/shared/types/ui-config.types.ts +118 -98
  151. package/dist/cli/soma.js +20 -5
  152. package/dist/core/index.cjs +7811 -1380
  153. package/dist/types/build/compiler/full-manifest-builder.d.ts +6 -2
  154. package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
  155. package/dist/types/build/compiler/page-assets.d.ts +3 -0
  156. package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
  157. package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -2
  158. package/dist/types/build/compiler/route-builder.d.ts +0 -1
  159. package/dist/types/build/compiler/soma-precompile.d.ts +17 -0
  160. package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -7
  161. package/dist/types/build/component/pack-from-dir.d.ts +17 -0
  162. package/dist/types/build/component/package-loader.d.ts +40 -0
  163. package/dist/types/build/eject/apply-eject.d.ts +22 -0
  164. package/dist/types/build/eject/plan-eject.d.ts +32 -0
  165. package/dist/types/build/v2/block-compile.d.ts +28 -0
  166. package/dist/types/build/v2/block-loader.d.ts +9 -0
  167. package/dist/types/build/v2/html-index.d.ts +37 -0
  168. package/dist/types/build/v2/migrate-v1.d.ts +32 -0
  169. package/dist/types/build/v2/soma-file-loader.d.ts +45 -0
  170. package/dist/types/client/adaptive/flush-scheduler.d.ts +13 -0
  171. package/dist/types/client/adaptive/hysteresis.d.ts +16 -0
  172. package/dist/types/client/adaptive/index.d.ts +5 -0
  173. package/dist/types/client/adaptive/observer-pool.d.ts +15 -0
  174. package/dist/types/client/base/SomaPageRootBase.d.ts +33 -0
  175. package/dist/types/client/compiler/adaptive-compile.d.ts +26 -0
  176. package/dist/types/client/compiler/manifest-compiler.d.ts +13 -2
  177. package/dist/types/client/component/ai-catalog.d.ts +73 -0
  178. package/dist/types/client/component/component-definition.types.d.ts +54 -0
  179. package/dist/types/client/component/component-expander.d.ts +25 -0
  180. package/dist/types/client/component/component-manager.d.ts +160 -0
  181. package/dist/types/client/component/component-pack.d.ts +110 -0
  182. package/dist/types/client/component/component-registry.d.ts +12 -0
  183. package/dist/types/client/component/contract-compat.d.ts +16 -0
  184. package/dist/types/client/component/example-v2.d.ts +9 -0
  185. package/dist/types/client/component/pack-styles.d.ts +22 -0
  186. package/dist/types/client/component/scoped-adapter.d.ts +18 -0
  187. package/dist/types/client/component/verify-pack.d.ts +14 -0
  188. package/dist/types/client/data/data-object-resolver.d.ts +71 -0
  189. package/dist/types/client/diagnostics/SomaDiagnostics.d.ts +2 -1
  190. package/dist/types/client/diagnostics/boot-timings.d.ts +30 -0
  191. package/dist/types/client/engine/asset-resolver.d.ts +7 -1
  192. package/dist/types/client/engine/dom-renderer.d.ts +51 -1
  193. package/dist/types/client/engine/emit-event.d.ts +6 -0
  194. package/dist/types/client/engine/event-engine.d.ts +6 -0
  195. package/dist/types/client/engine/render-engine.d.ts +25 -1
  196. package/dist/types/client/engine/runtime-builder.d.ts +7 -0
  197. package/dist/types/client/engine/soma-bootstrap.d.ts +118 -0
  198. package/dist/types/client/observability/error-reporter.d.ts +51 -0
  199. package/dist/types/client/parser/adaptive-parser.d.ts +28 -0
  200. package/dist/types/client/parser/data-config-parser.d.ts +34 -0
  201. package/dist/types/client/parser/pipeline-parser.d.ts +2 -0
  202. package/dist/types/client/parser/style-config-parser.d.ts +5 -3
  203. package/dist/types/client/parser/ui-config-parser.d.ts +22 -1
  204. package/dist/types/client/parser/v2/namespace.d.ts +52 -0
  205. package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
  206. package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
  207. package/dist/types/client/parser/value-lang.d.ts +63 -0
  208. package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
  209. package/dist/types/client/registry/declaration-renderer.d.ts +50 -0
  210. package/dist/types/client/registry/index.d.ts +10 -0
  211. package/dist/types/client/registry/page-lifecycle.d.ts +61 -0
  212. package/dist/types/client/registry/remote-page.d.ts +52 -0
  213. package/dist/types/client/runtime/SomaRuntimeServices.d.ts +16 -0
  214. package/dist/types/client/security/attribute-presence.d.ts +7 -0
  215. package/dist/types/client/security/html-sanitizer.d.ts +37 -0
  216. package/dist/types/client/security/url-guard.d.ts +11 -0
  217. package/dist/types/client/theme/harmony.d.ts +77 -0
  218. package/dist/types/client/theme/scene-tokens.d.ts +25 -0
  219. package/dist/types/client/theme/theme-axes.d.ts +81 -0
  220. package/dist/types/client/theme/theme-engine.d.ts +77 -0
  221. package/dist/types/client/theme/tone-solver.d.ts +47 -0
  222. package/dist/types/client/typography/typography-base.d.ts +15 -0
  223. package/dist/types/client/validation/contract-validator.d.ts +2 -0
  224. package/dist/types/index.d.ts +47 -2
  225. package/dist/types/server/api/IService.d.ts +18 -6
  226. package/dist/types/server/host/content-security-policy.d.ts +53 -0
  227. package/dist/types/server/host/csp-nonce-metadata.d.ts +32 -0
  228. package/dist/types/server/host/resolve-host-request-hook.d.ts +5 -0
  229. package/dist/types/server/host/server-page-assets.d.ts +2 -0
  230. package/dist/types/server/host/soma-page-compile.d.ts +7 -0
  231. package/dist/types/server/index.d.ts +6 -1
  232. package/dist/types/server/registry/api-registry-store.d.ts +141 -0
  233. package/dist/types/server/registry/conditional-object-store.d.ts +27 -0
  234. package/dist/types/server/registry/declaration-precompiler.d.ts +30 -0
  235. package/dist/types/server/registry/in-memory-conditional-object-store.d.ts +8 -0
  236. package/dist/types/server/registry/index.d.ts +29 -0
  237. package/dist/types/server/registry/page-registry-repository.d.ts +58 -0
  238. package/dist/types/server/registry/page-registry-store.d.ts +259 -0
  239. package/dist/types/server/registry/registry-error.d.ts +12 -0
  240. package/dist/types/server/registry/registry-file-lock.d.ts +20 -0
  241. package/dist/types/server/registry/registry-response.d.ts +18 -0
  242. package/dist/types/server/registry/registry-subjects.d.ts +59 -0
  243. package/dist/types/server/registry/registry-write-pipeline.d.ts +48 -0
  244. package/dist/types/server/registry/request-body-limit.d.ts +31 -0
  245. package/dist/types/server/registry/services/apis/Get.d.ts +10 -0
  246. package/dist/types/server/registry/services/apis/List.d.ts +10 -0
  247. package/dist/types/server/registry/services/apis/Register.d.ts +13 -0
  248. package/dist/types/server/registry/services/apis/Unregister.d.ts +12 -0
  249. package/dist/types/server/registry/services/index.d.ts +3 -0
  250. package/dist/types/server/registry/services/pages/Get.d.ts +10 -0
  251. package/dist/types/server/registry/services/pages/List.d.ts +13 -0
  252. package/dist/types/server/registry/services/pages/Register.d.ts +11 -0
  253. package/dist/types/server/registry/services/pages/Rollback.d.ts +9 -0
  254. package/dist/types/server/registry/services/pages/Unregister.d.ts +9 -0
  255. package/dist/types/server/registry/services/service-utils.d.ts +10 -0
  256. package/dist/types/server/registry/validation/compile-gate.d.ts +12 -0
  257. package/dist/types/server/registry/validation/component-existence.d.ts +14 -0
  258. package/dist/types/server/registry/validation/credential-ban.d.ts +15 -0
  259. package/dist/types/server/registry/validation/cross-check.d.ts +16 -0
  260. package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +15 -0
  261. package/dist/types/shared/types/adaptive.types.d.ts +88 -0
  262. package/dist/types/shared/types/component-contract.types.d.ts +78 -0
  263. package/dist/types/shared/types/data-config.types.d.ts +81 -0
  264. package/dist/types/shared/types/domain.types.d.ts +6 -0
  265. package/dist/types/shared/types/engine.types.d.ts +6 -0
  266. package/dist/types/shared/types/manifest.types.d.ts +23 -0
  267. package/dist/types/shared/types/scope-manifest.types.d.ts +82 -0
  268. package/dist/types/shared/types/style-config.types.d.ts +8 -0
  269. package/dist/types/shared/types/ui-config.types.d.ts +20 -0
  270. package/editor/vscode/package.json +1 -24
  271. package/global.d.ts +5 -11
  272. package/next.config.js +85 -28
  273. package/package.json +33 -11
  274. package/proxy.ts +62 -0
  275. package/tailwind.config.ts +0 -1
  276. package/core/build/lsp/event-yaml-completion.cjs +0 -106
  277. package/core/client/engine/theme-variables.ts +0 -37
  278. package/dist/tsconfig.types.tsbuildinfo +0 -1
  279. package/dist/types/client/engine/theme-variables.d.ts +0 -3
  280. package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
  281. package/middleware.ts +0 -33
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # soma-core
2
+
3
+ SOMA 运行时引擎:页面 = 四件套声明文件(html/_ui.yaml/_event.yaml/_style.yaml,另加可选
4
+ `data/<page>_data.yaml` 数据对象声明)+ 可选 Domain TS —— 声明即数据,落盘即渲染,零构建。
5
+
6
+ ## 当前能力(以代码为准)
7
+
8
+ - **编译管线**:ManifestCompiler 把四件套编译为运行时 Manifest;`soma-precompile` 预编译产物
9
+ 由 `verify:precompile` 闸门看守新鲜度(`core/build/`)。
10
+ - **渲染引擎 + 事件引擎**:Pipeline 四动词(`NAV_STATIC / NAV_ACTION / UI_REFRESH / UI_INTERACT`)
11
+ + triggers/timers + confirm 段;格式化管道;作用域清单树与增量刷新
12
+ (`core/client/engine`、`core/client/runtime`)。
13
+ - **组件运行时**:实例 = 迷你运行时(作用域隔离/props/emit 路由/插槽/自治生命周期),
14
+ `data-soma-component` 声明接入;文件态组件包由 `loadComponentPackFromDir(dir, { name, version })`
15
+ 完整装载定义、样式与 provenance,`loadComponentPackages` 仅保留为无样式定义表兼容入口。
16
+ - **数据对象层**:`*_data.yaml` 解析器(多接口 DAG 依赖编排/字段字典/类型双态映射/速记列/
17
+ mock 兜底),解析结果注入 `page.data`,支持 `reloadData`(`core/client/data`)。
18
+ - **主题引擎**:54+ 业界标准令牌;brand + palette 五轴 + scene 三项派生亮暗双套,
19
+ 语义分离与逐配对 WCAG AA 硬保障;省略新轴保持历史字节兼容,overrides 可精调
20
+ (`core/client/theme`)。
21
+ - **宿主与 CLI**:Next Host(`app/`,含静态 public/ 托管)+ `soma` CLI
22
+ (`dev/build/start/db generate|push`、mock 服务器、LSP、codegen,见 `bin/`)。
23
+
24
+ ## 文档索引(`doc/`)
25
+
26
+ - `SOMA.md` — 框架本体:四件套、Pipeline、Host 集成
27
+ - `soma DSL 语法全书.md` — 四件套 + data.yaml 全语法、绑定形态白名单、速记、管道、YAML 引号纪律
28
+ - `soma 运行时引擎详设.md` — 编译管线、组件运行时、作用域、emit 路由、services 白名单
29
+ - `soma 设计令牌与主题.md` — 令牌总表、派生算法、换肤协议
30
+ - `soma 数据对象层.md` — `*_data.yaml` 语法与解析器
31
+ - `soma DSL 语法全书.md` / `soma 作用域清单树.md` — 页面侧组件用法与运行时机制
32
+ - 其余:`SOMA-HOST-CLI.md`、`soma 渲染引擎.md`、`mock-data.md` 等
33
+
34
+ ## 测试
35
+
36
+ ```bash
37
+ npm test -w soma-core # vitest 631+ 用例 + mock 服务器 53(node --test)
38
+ npm run typecheck -w soma-core
39
+ npm run verify:precompile -w soma-core # 预编译产物新鲜度闸门
40
+ npm run verify:client-boundary -w soma-core
41
+ ```
42
+
43
+ 改解析器/编译器后:`npm run build:precompile` + `npm run build:types`,并重启 dev 服务器。
@@ -5,6 +5,7 @@ import { usePathname, useRouter, useSearchParams } from 'next/navigation';
5
5
  import { SomaHydrationShell } from './components/SomaHydrationShell';
6
6
  import type { SomaBootstrap as SomaBootstrapType, SomaPageAssets } from '../core/client/engine/soma-bootstrap';
7
7
  import { loadHostDomainClass } from '../core/client/host-bridge/load-host-domain-class';
8
+ import { maybeStartBootTimings, readBootTimings } from '../core/client/diagnostics/boot-timings';
8
9
 
9
10
  const isDev = process.env.NODE_ENV !== 'production';
10
11
 
@@ -39,6 +40,7 @@ type PagePayload = {
39
40
  ui: string;
40
41
  event: string;
41
42
  styleYaml?: string;
43
+ dataYaml?: string;
42
44
  includes?: Record<string, string>;
43
45
  localeYaml: string;
44
46
  appConfigYaml: string;
@@ -46,31 +48,12 @@ type PagePayload = {
46
48
 
47
49
  type PrecompiledAssets = Pick<
48
50
  SomaPageAssets,
49
- 'uiConfig' | 'eventConfig' | 'triggerConfig' | 'timerConfig' | 'styleConfig' | 'locale' | 'appConfig'
51
+ 'uiConfig' | 'eventConfig' | 'triggerConfig' | 'timerConfig' | 'styleConfig' | 'locale' | 'appConfig' | 'dataConfig'
50
52
  >;
51
53
 
52
- function normalizeEventBundle(raw: unknown): {
53
- events: PrecompiledAssets['eventConfig'];
54
- triggers: NonNullable<PrecompiledAssets['triggerConfig']>;
55
- timers: NonNullable<PrecompiledAssets['timerConfig']>;
56
- } {
57
- if (Array.isArray(raw)) {
58
- return { events: raw, triggers: [], timers: [] };
59
- }
60
- if (raw && typeof raw === 'object' && 'events' in raw) {
61
- const bundle = raw as { events?: unknown; triggers?: unknown; timers?: unknown };
62
- return {
63
- events: (bundle.events ?? []) as NonNullable<PrecompiledAssets['eventConfig']>,
64
- triggers: (bundle.triggers ?? []) as NonNullable<PrecompiledAssets['triggerConfig']>,
65
- timers: (bundle.timers ?? []) as NonNullable<PrecompiledAssets['timerConfig']>,
66
- };
67
- }
68
- return { events: [], triggers: [], timers: [] };
69
- }
70
-
71
54
  const pageAssetCache = new Map<string, PagePayload>();
72
55
 
73
- async function loadPrecompiledFromManifest(base: string, path: string): Promise<PrecompiledAssets | null> {
56
+ async function loadPrecompiledFromManifest(path: string): Promise<PrecompiledAssets | null> {
74
57
  try {
75
58
  const res = await fetch(`/soma/manifest?path=${encodeURIComponent(path)}`);
76
59
  if (!res.ok) return null;
@@ -83,51 +66,7 @@ async function loadPrecompiledFromManifest(base: string, path: string): Promise<
83
66
  styleConfig: data.styleConfig,
84
67
  locale: data.locale ?? {},
85
68
  appConfig: data.appConfig ?? null,
86
- };
87
- } catch {
88
- return null;
89
- }
90
- }
91
-
92
- async function loadPrecompiledAssets(base: string, urlPath = `/${base}`): Promise<PrecompiledAssets | null> {
93
- try {
94
- const [uiMod, eventMod, styleMod, localeMod, configMod] = await Promise.all([
95
- import(
96
- /* webpackInclude: /\/ui\/.*_ui\.yaml$/ */
97
- `@soma-host/ui/${base}_ui.yaml`
98
- ).catch(() => null),
99
- import(
100
- /* webpackInclude: /\/event\/.*_event\.yaml$/ */
101
- `@soma-host/event/${base}_event.yaml`
102
- ).catch(() => null),
103
- import(
104
- /* webpackInclude: /\/ui\/.*_style\.yaml$/ */
105
- `@soma-host/ui/${base}_style.yaml`
106
- ).catch(() => null),
107
- import(
108
- /* webpackInclude: /\/config\/locale\.yaml$/ */
109
- '@soma-host/config/locale.yaml'
110
- ).catch(() => null),
111
- import(
112
- /* webpackInclude: /\/config\/app\.config\.yaml$/ */
113
- '@soma-host/config/app.config.yaml'
114
- ).catch(() => null),
115
- ]);
116
-
117
- if (!uiMod?.default || !eventMod?.default) {
118
- return null;
119
- }
120
-
121
- const eventBundle = normalizeEventBundle(eventMod.default);
122
-
123
- return {
124
- uiConfig: uiMod.default,
125
- eventConfig: eventBundle.events,
126
- triggerConfig: eventBundle.triggers,
127
- timerConfig: eventBundle.timers,
128
- styleConfig: styleMod?.default ?? undefined,
129
- locale: (localeMod?.default ?? {}) as Record<string, unknown>,
130
- appConfig: configMod?.default ?? null,
69
+ dataConfig: data.dataConfig ?? undefined,
131
70
  };
132
71
  } catch {
133
72
  return null;
@@ -186,6 +125,14 @@ function SomaPageRenderer({
186
125
  isSettled: () => bs.isSettled(),
187
126
  getDomainValue: (path: string) => bs.getDomainValue(path),
188
127
  getRegisteredSomaIds: () => bs.getRegisteredSomaIds(),
128
+ // 只读 CSP nonce 链:响应头 nonce → meta → 运行期注入的样式元素。
129
+ // 浏览器插入后会抹掉 nonce 内容属性,这里读 IDL 属性。
130
+ getCspNonceChain: () => ({
131
+ meta: document.querySelector('meta[name="csp-nonce"]')?.getAttribute('content')?.trim() ?? '',
132
+ styles: Array.from(document.head.querySelectorAll('style'))
133
+ .map((style) => (style as HTMLStyleElement).nonce ?? '')
134
+ .filter(Boolean),
135
+ }),
189
136
  };
190
137
  window.__SOMA_READY__ = bs.isInitialized();
191
138
  }
@@ -218,6 +165,8 @@ function SomaPageRenderer({
218
165
  getDiagnosticsSnapshot: () => bs.getDiagnosticsSnapshot(),
219
166
  getTelemetrySnapshot: () => bs.getTelemetrySnapshot(),
220
167
  getAvailableThemes: () => bs.getAvailableThemes(),
168
+ // 首屏三段:E2E/手工排查从这里读,不必自己去翻 performance 时间线
169
+ getBootTimings: () => readBootTimings(),
221
170
  getDomainInstance: () => bs.getDomainInstance(),
222
171
  captureSnapshot: () => bs.captureSnapshot(),
223
172
  restoreSnapshot: (id: number) => bs.restoreSnapshot(id),
@@ -228,6 +177,9 @@ function SomaPageRenderer({
228
177
 
229
178
  const run = async () => {
230
179
  try {
180
+ // 首屏三段打点的起点:放在页面资产拉取之前,段一才量得到网络那一截。
181
+ // 未开启(globalThis.__SOMA_BOOT_TIMINGS__ 未置真)时只是一次布尔判断。
182
+ maybeStartBootTimings();
231
183
  setError(null);
232
184
  setMounting(true);
233
185
 
@@ -244,8 +196,7 @@ function SomaPageRenderer({
244
196
  const routeAssets = { routerPath };
245
197
 
246
198
  if (!isDev) {
247
- const fromManifest = await loadPrecompiledFromManifest(base, pagePath);
248
- const precompiled = fromManifest ?? await loadPrecompiledAssets(base, pagePath);
199
+ const precompiled = await loadPrecompiledFromManifest(pagePath);
249
200
  if (precompiled) {
250
201
  await mountInto(
251
202
  DomainClass,
@@ -267,6 +218,7 @@ function SomaPageRenderer({
267
218
  uiYaml: cached.ui,
268
219
  eventYaml: cached.event,
269
220
  styleYaml: cached.styleYaml,
221
+ dataYaml: cached.dataYaml,
270
222
  localeYaml: cached.localeYaml ?? '',
271
223
  appConfigYaml: cached.appConfigYaml ?? '',
272
224
  ...routeAssets,
@@ -282,6 +234,7 @@ function SomaPageRenderer({
282
234
  ui: data.ui,
283
235
  event: data.event,
284
236
  styleYaml: data.styleYaml ?? '',
237
+ dataYaml: typeof data.dataYaml === 'string' ? data.dataYaml : undefined,
285
238
  includes: data.includes,
286
239
  localeYaml: data.localeYaml ?? '',
287
240
  appConfigYaml: data.appConfigYaml ?? '',
@@ -295,6 +248,7 @@ function SomaPageRenderer({
295
248
  uiYaml: payload.ui,
296
249
  eventYaml: payload.event,
297
250
  styleYaml: payload.styleYaml,
251
+ dataYaml: payload.dataYaml,
298
252
  localeYaml: payload.localeYaml ?? '',
299
253
  appConfigYaml: payload.appConfigYaml ?? '',
300
254
  ...routeAssets,
@@ -1,21 +1,22 @@
1
1
  import { SomaHostPage, type SomaPageSearchParams } from '../components/SomaHostPage';
2
2
  import { notFound } from 'next/navigation';
3
3
 
4
- export default function SomaCatchAllPage({
4
+ export default async function SomaCatchAllPage({
5
5
  params,
6
6
  searchParams,
7
7
  }: {
8
- params: { path: string[] };
9
- searchParams?: SomaPageSearchParams;
8
+ params: Promise<{ path: string[] }>;
9
+ searchParams?: Promise<SomaPageSearchParams>;
10
10
  }) {
11
- const lastSegment = params.path.at(-1) ?? '';
11
+ const resolvedParams = await params;
12
+ const lastSegment = resolvedParams.path.at(-1) ?? '';
12
13
  if (/\.[a-zA-Z0-9]+$/.test(lastSegment) && !/\.html$/i.test(lastSegment)) {
13
14
  notFound();
14
15
  }
15
16
  return (
16
17
  <SomaHostPage
17
- pathname={`/${params.path.join('/')}`}
18
- searchParams={searchParams}
18
+ pathname={`/${resolvedParams.path.join('/')}`}
19
+ searchParams={await searchParams}
19
20
  />
20
21
  );
21
22
  }
@@ -12,9 +12,9 @@ function createHandler(method: HttpMethod) {
12
12
 
13
13
  return async function handler(
14
14
  req: NextRequest,
15
- { params }: { params: { path: string[] } },
15
+ { params }: { params: Promise<{ path: string[] }> },
16
16
  ): Promise<Response> {
17
- const segments = params.path || [];
17
+ const segments = (await params).path || [];
18
18
 
19
19
  const rejected = await invokeHostRequestHook(req, {
20
20
  kind: 'api',
@@ -57,7 +57,7 @@ function createHandler(method: HttpMethod) {
57
57
  return await handlerFn.call(service, req);
58
58
  } catch (e: unknown) {
59
59
  const message = e instanceof Error ? e.message : String(e);
60
- console.error(`[soma-api] ${method} /api/${segments.join('/')}:`, message);
60
+ console.error(`[soma-core][接口] ${method} /api/${segments.join('/')}:`, message);
61
61
  return Response.json(
62
62
  { error: message || 'Internal server error' },
63
63
  { status: 500 },
@@ -0,0 +1,67 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { randomUUID } from 'node:crypto';
3
+ import type { IService } from '../../../../core/server/api/IService';
4
+ import { resolveRegistryService } from '../../../../core/server/registry/services/index';
5
+ import { invokeHostRequestHook } from '../../../../core/server/host/invoke-host-request-hook';
6
+
7
+ // 注册中心内置端点(/api/soma-registry/*)。
8
+ // 比通用宿主服务路由(/api/[...path])更具体,Next 自动优先匹配——core 自带,宿主零接线。
9
+ // 鉴权分两层:宿主请求钩子先跑(应用决定谁可管理),端点内的主体鉴权再跑(平台底线)。
10
+
11
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
12
+
13
+ function createHandler(method: HttpMethod) {
14
+ const methodKey = method.toLowerCase() as keyof IService;
15
+
16
+ return async function handler(
17
+ req: NextRequest,
18
+ { params }: { params: Promise<{ path: string[] }> },
19
+ ): Promise<Response> {
20
+ const segments = (await params).path || [];
21
+
22
+ const rejected = await invokeHostRequestHook(req, {
23
+ kind: 'api',
24
+ path: req.nextUrl.pathname,
25
+ });
26
+ if (rejected) {
27
+ return rejected;
28
+ }
29
+
30
+ const service = resolveRegistryService(segments);
31
+ if (!service) {
32
+ return Response.json(
33
+ { error: `API not found: /api/soma-registry/${segments.join('/')}` },
34
+ { status: 404 },
35
+ );
36
+ }
37
+
38
+ const handlerFn = service[methodKey];
39
+ if (typeof handlerFn !== 'function') {
40
+ return Response.json(
41
+ { error: `Method ${method} not allowed: /api/soma-registry/${segments.join('/')}` },
42
+ { status: 405 },
43
+ );
44
+ }
45
+
46
+ try {
47
+ return await handlerFn.call(service, req);
48
+ } catch (e: unknown) {
49
+ // 未预期异常:细节只进服务端日志,回给调用方的只有事件号(不泄漏路径与部署形态)
50
+ const eventId = randomUUID().slice(0, 8);
51
+ console.error(
52
+ `[soma-core][注册中心] 事件 ${eventId} 未处理异常 ${method} /api/soma-registry/${segments.join('/')}:`,
53
+ e instanceof Error ? (e.stack ?? e.message) : String(e),
54
+ );
55
+ return Response.json(
56
+ { error: `服务器内部错误(事件 ${eventId},详情见服务端日志)` },
57
+ { status: 500 },
58
+ );
59
+ }
60
+ };
61
+ }
62
+
63
+ export const GET = createHandler('GET');
64
+ export const POST = createHandler('POST');
65
+ export const PUT = createHandler('PUT');
66
+ export const PATCH = createHandler('PATCH');
67
+ export const DELETE = createHandler('DELETE');
@@ -1,14 +1,9 @@
1
- import dynamic from 'next/dynamic';
2
1
  import { headers } from 'next/headers';
3
2
  import { redirect } from 'next/navigation';
4
3
  import { Suspense } from 'react';
5
4
  import { invokeHostRequestHook } from '../../core/server/host/invoke-host-request-hook';
6
5
  import { SomaHydrationShell } from './SomaHydrationShell';
7
-
8
- const SomaPageClient = dynamic(() => import('../SomaPageClient'), {
9
- ssr: false,
10
- loading: () => <SomaHydrationShell />,
11
- });
6
+ import { SomaPageClientBoundary } from './SomaPageClientBoundary';
12
7
 
13
8
  export type SomaPageSearchParams = Record<string, string | string[] | undefined>;
14
9
 
@@ -83,7 +78,7 @@ export async function SomaHostPage({
83
78
  pathname: string;
84
79
  searchParams?: SomaPageSearchParams;
85
80
  }) {
86
- const incomingHeaders = headers();
81
+ const incomingHeaders = await headers();
87
82
  const requestHeaders = new Headers();
88
83
  incomingHeaders.forEach((value, key) => requestHeaders.set(key, value));
89
84
 
@@ -127,7 +122,7 @@ export async function SomaHostPage({
127
122
 
128
123
  return (
129
124
  <Suspense fallback={<SomaHydrationShell />}>
130
- <SomaPageClient />
125
+ <SomaPageClientBoundary />
131
126
  </Suspense>
132
127
  );
133
128
  }
@@ -0,0 +1,13 @@
1
+ 'use client';
2
+
3
+ import dynamic from 'next/dynamic';
4
+ import { SomaHydrationShell } from './SomaHydrationShell';
5
+
6
+ const SomaPageClient = dynamic(() => import('../SomaPageClient'), {
7
+ ssr: false,
8
+ loading: () => <SomaHydrationShell />,
9
+ });
10
+
11
+ export function SomaPageClientBoundary() {
12
+ return <SomaPageClient />;
13
+ }
package/app/layout.tsx CHANGED
@@ -1,11 +1,16 @@
1
+ import { headers } from 'next/headers';
1
2
  import './globals.css';
2
3
  import { readHostAppDisplayName } from '../core/server/host/app-config-composer';
4
+ import { somaCspNonceMetadataAsync } from '../core/server/host/csp-nonce-metadata';
3
5
 
4
- export function generateMetadata() {
6
+ export async function generateMetadata() {
5
7
  const displayName = readHostAppDisplayName();
6
8
  return {
7
9
  title: displayName || 'SOMA',
8
10
  description: displayName || 'SOMA declarative UI runtime',
11
+ // CSP 开启时透出 `<meta name="csp-nonce">`,供 soma-ui 的运行期 `<style>` 注入器取用
12
+ // (作业单 D-5)。CSP 关(缺省)时展开的是空对象,headers() 也不会被调用,静态渲染不受影响。
13
+ ...await somaCspNonceMetadataAsync(() => headers()),
9
14
  };
10
15
  }
11
16
 
package/app/page.tsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import { SomaHostPage, type SomaPageSearchParams } from './components/SomaHostPage';
2
2
 
3
- export default function SomaRootPage({
3
+ export default async function SomaRootPage({
4
4
  searchParams,
5
5
  }: {
6
- searchParams?: SomaPageSearchParams;
6
+ searchParams?: Promise<SomaPageSearchParams>;
7
7
  }) {
8
- return <SomaHostPage pathname="/" searchParams={searchParams} />;
8
+ return <SomaHostPage pathname="/" searchParams={await searchParams} />;
9
9
  }
@@ -29,6 +29,7 @@ export async function GET(request: Request): Promise<Response> {
29
29
  triggers: page.triggers,
30
30
  timers: page.timers ?? [],
31
31
  styleConfig: page.styleConfig,
32
+ dataConfig: page.dataConfig,
32
33
  locale: manifest.locale,
33
34
  appConfig: page.appConfig ?? manifest.appConfig,
34
35
  manifestVersion: '1.0.0',
@@ -34,7 +34,7 @@ function errorResponse(error: unknown, pagePath: string): Response {
34
34
  : 'SOMA_HEADLESS_PAGE_FAILED';
35
35
  const message = error instanceof Error ? error.message : String(error);
36
36
  if (status >= 500) {
37
- console.error('[soma-headless] ' + pagePath + ': ' + message);
37
+ console.error('[soma-core][无头渲染] ' + pagePath + ': ' + message);
38
38
  }
39
39
  return Response.json(
40
40
  {
package/bin/soma-lsp.cjs CHANGED
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * SOMA Language Server — 跨文件锚点诊断(html ↔ ui ↔ event)
3
+ * SOMA Language Server — HTML ↔ 唯一 SOMA DSL 声明诊断与导航
4
4
  */
5
5
  const fs = require('node:fs');
6
6
  const path = require('node:path');
7
7
  const { lintAnchorConsistency } = require('../core/build/lsp/cross-file-diagnostics.cjs');
8
8
  const { getUiYamlCompletions } = require('../core/build/lsp/ui-yaml-completion.cjs');
9
- const { getEventYamlCompletions } = require('../core/build/lsp/event-yaml-completion.cjs');
10
9
  const { getHover, getDefinition } = require('../core/build/lsp/lsp-navigation.cjs');
11
10
  const { getLocaleYamlCompletions, getHtmlAnchorCompletions } = require('../core/build/lsp/extra-completion.cjs');
12
11
 
@@ -126,8 +125,6 @@ function handleMessage(msg) {
126
125
  if (resolved) {
127
126
  if (fileName.endsWith('_ui.yaml')) {
128
127
  items = getUiYamlCompletions(resolved, uri, text, pos);
129
- } else if (fileName.endsWith('_event.yaml')) {
130
- items = getEventYamlCompletions(resolved, uri, text, pos);
131
128
  } else if (fileName === 'locale.yaml') {
132
129
  items = getLocaleYamlCompletions(resolved, uri, text, pos);
133
130
  } else if (fileName.endsWith('.html')) {
@@ -6,9 +6,8 @@ import type { ParsedEvent } from '../../shared/types/event.types';
6
6
  import type { PropertyTrigger } from '../../shared/types/trigger.types';
7
7
  import type { ParsedTimer } from '../../shared/types/timer.types';
8
8
  import type { StyleConfig } from '../../shared/types/style-config.types';
9
- import { compileUiConfig, compileStyleConfig, precompileYaml } from '@core/build/compiler/soma-precompile';
10
- import { parseEventConfig } from '../../client/parser/pipeline-parser';
11
- import { splitEventConfigRaw } from '../../client/parser/trigger-parser';
9
+ import type { SomaDataConfig } from '../../shared/types/data-config.types';
10
+ import { compilePageDeclaration } from './page-declaration-compiler';
12
11
  import { buildRouteTable, type SomaRouteEntry } from './route-builder';
13
12
  import yaml from 'js-yaml';
14
13
  import {
@@ -16,18 +15,6 @@ import {
16
15
  parseAppConfigYaml,
17
16
  } from '../../server/host/app-config-composer';
18
17
 
19
- function compileEventBundle(eventYaml: string) {
20
- if (!eventYaml.trim()) {
21
- return { events: [], triggers: [] as PropertyTrigger[], timers: [] as ParsedTimer[] };
22
- }
23
- const { eventsRaw, triggers, timers } = splitEventConfigRaw(yaml.load(eventYaml));
24
- return {
25
- events: parseEventConfig(eventsRaw as any),
26
- triggers,
27
- timers,
28
- };
29
- }
30
-
31
18
  export interface SomaPrecompiledPage {
32
19
  path: string;
33
20
  uiConfig: UiConfig;
@@ -36,6 +23,8 @@ export interface SomaPrecompiledPage {
36
23
  timers: ParsedTimer[];
37
24
  styleConfig?: StyleConfig;
38
25
  appConfig?: unknown;
26
+ /** 从统一声明编译出的数据对象资产。 */
27
+ dataConfig?: SomaDataConfig;
39
28
  }
40
29
 
41
30
  export interface SomaPrecompiledManifest {
@@ -55,10 +44,11 @@ export function precompileAll(inputs: {
55
44
  appConfigYaml: string;
56
45
  pages: Array<{
57
46
  path: string;
47
+ html: string;
58
48
  uiYaml: string;
59
- eventYaml: string;
60
- styleYaml?: string;
61
49
  appConfigYaml?: string;
50
+ externalBlocks?: ReadonlyMap<string, string>;
51
+ includes?: Readonly<Record<string, string>>;
62
52
  }>;
63
53
  }): SomaPrecompiledManifest {
64
54
  const hostAppConfig = parseAppConfigYaml(inputs.appConfigYaml);
@@ -67,14 +57,20 @@ export function precompileAll(inputs: {
67
57
  locale: (yaml.load(inputs.localeYaml) as Record<string, unknown>) || {},
68
58
  appConfig: hostAppConfig,
69
59
  pages: inputs.pages.map(p => {
70
- const eventBundle = compileEventBundle(p.eventYaml);
60
+ const page = compilePageDeclaration({
61
+ html: p.html,
62
+ uiYaml: p.uiYaml,
63
+ ...(p.externalBlocks ? { externalBlocks: p.externalBlocks } : {}),
64
+ ...(p.includes ? { includes: p.includes } : {}),
65
+ });
71
66
  return {
72
67
  path: p.path,
73
- uiConfig: compileUiConfig(p.uiYaml),
74
- eventConfig: eventBundle.events,
75
- triggers: eventBundle.triggers,
76
- timers: eventBundle.timers,
77
- styleConfig: p.styleYaml ? compileStyleConfig(p.styleYaml) : undefined,
68
+ uiConfig: page.uiConfig,
69
+ eventConfig: page.eventConfig,
70
+ triggers: page.triggers,
71
+ timers: page.timers,
72
+ styleConfig: page.styleConfig,
73
+ dataConfig: page.dataConfig,
78
74
  appConfig: p.appConfigYaml
79
75
  ? mergeSourcePackageAppConfig(parseAppConfigYaml(p.appConfigYaml), hostAppConfig)
80
76
  : undefined,
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 构建期 HTML include 展开。
3
+ *
4
+ * 浏览器运行时会由 SomaContainerAdapter 把 data-soma-include 的片段填入占位元素。
5
+ * 单文件 DSL 在构建期校验 data-soma-id 时也必须看到同一棵 DOM;否则共享 Shell
6
+ * 里的锚点会被误报为不存在。这里仅按调用方已经收集好的 include 名称表查找,绝不
7
+ * 从声明值拼接或读取文件路径。
8
+ */
9
+ export class SomaHtmlIncludeError extends Error {
10
+ constructor(message: string) {
11
+ super(`[soma-core][HTML include] ${message}`);
12
+ this.name = 'SomaHtmlIncludeError';
13
+ }
14
+ }
15
+
16
+ const INCLUDE_ATTRIBUTE = /\sdata-soma-include\s*=\s*(["'])([^"']+)\1/i;
17
+ const OPEN_TAG = /<([A-Za-z][A-Za-z0-9:-]*)(\s[^<>]*?)?>/g;
18
+
19
+ /**
20
+ * 返回供声明编译器做锚点校验的逻辑 HTML。
21
+ *
22
+ * include 容器本身保留,行为与运行时的 element.innerHTML = fragment 一致;目前
23
+ * Shell 的 include 占位节点均为空。嵌套 include 递归展开并检查循环,缺失片段
24
+ * 显式失败,避免运行时出现静默空壳而构建误通过。
25
+ */
26
+ export function expandSomaHtmlIncludes(
27
+ html: string,
28
+ includes: Readonly<Record<string, string>> | undefined,
29
+ ): string {
30
+ if (!includes || Object.keys(includes).length === 0 || !html.includes('data-soma-include')) {
31
+ return html;
32
+ }
33
+
34
+ const expand = (source: string, chain: readonly string[]): string => source.replace(
35
+ OPEN_TAG,
36
+ (full, tagName: string, attributes: string | undefined) => {
37
+ const rawAttributes = attributes ?? '';
38
+ const matched = INCLUDE_ATTRIBUTE.exec(rawAttributes);
39
+ if (!matched) return full;
40
+
41
+ const includeName = matched[2];
42
+ if (!Object.prototype.hasOwnProperty.call(includes, includeName)) {
43
+ throw new SomaHtmlIncludeError(`找不到共享片段 "${includeName}"`);
44
+ }
45
+ if (chain.includes(includeName)) {
46
+ throw new SomaHtmlIncludeError(`检测到循环引用:${[...chain, includeName].join(' -> ')}`);
47
+ }
48
+
49
+ const withoutInclude = rawAttributes.replace(INCLUDE_ATTRIBUTE, '');
50
+ const expandedFragment = expand(includes[includeName], [...chain, includeName]);
51
+ return `<${tagName}${withoutInclude}>${expandedFragment}`;
52
+ },
53
+ );
54
+
55
+ return expand(html, []);
56
+ }
@@ -0,0 +1,26 @@
1
+ // 测试替身与预览器使用的页面级编译入口。生产 Host 走同一个 compilePageDeclaration。
2
+
3
+ import type { SomaPageAssets } from '../../client/engine/soma-bootstrap';
4
+ import { compilePageDeclaration } from './page-declaration-compiler';
5
+
6
+ /** 把 SOMA DSL 源声明编译成客户端挂载所需的运行时资产。 */
7
+ export function compilePageAssets(assets: SomaPageAssets): SomaPageAssets {
8
+ const compiled = compilePageDeclaration({
9
+ html: assets.html ?? '',
10
+ uiYaml: assets.uiYaml ?? '',
11
+ ...(assets.eventYaml ? { eventYaml: assets.eventYaml } : {}),
12
+ ...(assets.styleYaml ? { styleYaml: assets.styleYaml } : {}),
13
+ ...(assets.dataYaml ? { dataYaml: assets.dataYaml } : {}),
14
+ ...(assets.declarationBlocks ? { externalBlocks: assets.declarationBlocks } : {}),
15
+ });
16
+
17
+ return {
18
+ ...assets,
19
+ uiYaml: compiled.runtimeAssets.uiYaml,
20
+ eventYaml: compiled.runtimeAssets.eventYaml,
21
+ styleYaml: '',
22
+ ...(compiled.runtimeAssets.dataYaml
23
+ ? { dataYaml: compiled.runtimeAssets.dataYaml }
24
+ : { dataYaml: undefined }),
25
+ };
26
+ }