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
@@ -6,6 +6,7 @@ import type { IContainerAdapter } from '../container/IContainerAdapter';
6
6
  import { SomaDiagnostics, type SomaDiagnosticsSnapshot } from '../diagnostics/SomaDiagnostics';
7
7
  import { SomaTelemetry } from '../diagnostics/SomaTelemetry';
8
8
  import { setActiveTelemetry, recordMetric } from '../diagnostics/telemetry-context';
9
+ import { markBootPhase, maybeStartBootTimings } from '../diagnostics/boot-timings';
9
10
  import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
10
11
  import { SomaScheduler } from '../scheduler/SomaScheduler';
11
12
  import type { ParsedEvent } from '../../shared/types/event.types';
@@ -13,6 +14,7 @@ import type { PropertyTrigger } from '../../shared/types/trigger.types';
13
14
  import type { ParsedTimer } from '../../shared/types/timer.types';
14
15
  import type { StyleConfig } from '../../shared/types/style-config.types';
15
16
  import type { UiConfig } from '../../shared/types/ui-config.types';
17
+ import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
16
18
  import type { SomaPageRoot } from '../../shared/types/domain.types';
17
19
  import { SomaSnapshotStore } from '../runtime/SomaSnapshotStore';
18
20
  import { SomaAssetResolver } from './asset-resolver';
@@ -29,8 +31,22 @@ import type { SomaOnChangeEngine } from './on-change-engine';
29
31
  import type { SomaTriggerEngine } from './trigger-engine';
30
32
  import type { SomaTimerEngine } from './timer-engine';
31
33
  import { createDefaultRuntimeServices } from '../runtime/SomaRuntimeServices';
32
- import { getBrowserUrlPath } from '../infra/router/router-path';
34
+ import { getBrowserUrlPath, readQueryParam } from '../infra/router/router-path';
35
+ import { parseDataYaml } from '../parser/data-config-parser';
36
+ import { SomaDataObjectResolver } from '../data/data-object-resolver';
37
+ import type { SomaDataConfig, SomaDataDicts } from '../../shared/types/data-config.types';
33
38
  import type { WatchCallback, WatcherOptions } from '../../shared/types/watcher.types';
39
+ import type { SomaComponentDefinition } from '../component/component-definition.types';
40
+ import { SomaComponentRegistry } from '../component/component-registry';
41
+ import { SomaComponentManager } from '../component/component-manager';
42
+ import { SomaPipeRegistry, type SomaPipeFn } from '../pipes/pipe-registry';
43
+ import { applyTheme, type SomaThemeInput } from '../theme/theme-engine';
44
+ import {
45
+ installSomaErrorReporter,
46
+ type SomaErrorEvent,
47
+ type SomaErrorReporterHandle,
48
+ type SomaPageIdentity,
49
+ } from '../observability/error-reporter';
34
50
 
35
51
  // ─── 类型定义 ──────────────────────────────────────────
36
52
 
@@ -39,12 +55,21 @@ export interface SomaPageAssets {
39
55
  includes?: Record<string, string>;
40
56
  DomainClass: new () => SomaPageRoot;
41
57
 
42
- // ── 字符串模式(运行时解析,向后兼容) ──
58
+ // ── 编译后的运行时资产(源声明不得直接进入浏览器) ──
43
59
  uiYaml?: string;
60
+ /** 仅供构建/测试入口携带的外置声明块;mount 本身不读取。 */
61
+ declarationBlocks?: ReadonlyMap<string, string>;
44
62
  eventYaml?: string;
45
63
  styleYaml?: string;
46
64
  localeYaml?: string;
47
65
  appConfigYaml?: string;
66
+ /**
67
+ * 从统一声明编译出的数据对象运行时资产。
68
+ * 提供后 bootstrap 在首渲前解析声明、异步取数并注入 page.data,
69
+ * 完成后触发一次全量渲染;解析/取数失败不阻塞页面(data 保持空对象 + console.error)。
70
+ * 不提供时加载路径零变化。
71
+ */
72
+ dataYaml?: string;
48
73
 
49
74
  // ── 预编译模式(构建阶段已解析,运行时零开销) ──
50
75
  uiConfig?: UiConfig;
@@ -54,9 +79,48 @@ export interface SomaPageAssets {
54
79
  styleConfig?: StyleConfig;
55
80
  locale?: Record<string, unknown>;
56
81
  appConfig?: unknown;
82
+ /** 数据对象层声明的预编译形态(构建阶段已解析校验,优先于 dataYaml) */
83
+ dataConfig?: SomaDataConfig;
57
84
 
58
85
  /** Full router path including query string (e.g. /items/detail?id=1) */
59
86
  routerPath?: string;
87
+
88
+ /**
89
+ * 组件运行时定义(组件体系模块 7,可选)。
90
+ * 键为契约名;页面 HTML 中 data-soma-component 引用的组件必须在此提供。
91
+ * 不提供时组件能力整体旁路,页面走既有路径。
92
+ */
93
+ components?: Record<string, SomaComponentDefinition>;
94
+ }
95
+
96
+ /** 浏览器只用于拒绝源声明;不存在旧/新两套执行分派。 */
97
+ function isSomaDeclarationSource(value: string): boolean {
98
+ return value.split('\n').some((line) => {
99
+ const text = line.trim();
100
+ if (!text || text.startsWith('#')) return false;
101
+ return text === '{{';
102
+ });
103
+ }
104
+
105
+ /**
106
+ * 错误采集接线声明(可观测性,默认关闭)。
107
+ *
108
+ * 为什么放在 bootstrap 而不是让 Host 自己 install:采集器本身只会记"出了什么错",
109
+ * 记不住"这是哪个页面的哪个版本"——而页面身份只有挂载时点知道。挂在生命周期
110
+ * 编排器上,身份随挂载自动盖戳、随卸载自动摘监听,Host 不需要维护任何状态。
111
+ */
112
+ export interface SomaBootstrapErrorReporting {
113
+ /** 页面身份:错误归因到「页面名@版本」的唯一依据(声明态页面必须带 version) */
114
+ page: SomaPageIdentity;
115
+ /**
116
+ * 上报通道。缺省走 console.error 单行 JSON——宿主一行开启就先有数据,
117
+ * 等接了真通道(sendBeacon / 第三方 SDK)再替换,不必为"先看看"写胶水。
118
+ */
119
+ report?: (event: SomaErrorEvent) => void;
120
+ /** 同签名错误去重窗口(毫秒),透传采集器 */
121
+ dedupeWindowMs?: number;
122
+ /** 单页上报条数上限,透传采集器 */
123
+ maxEvents?: number;
60
124
  }
61
125
 
62
126
  export interface SomaBootstrapOptions {
@@ -65,6 +129,25 @@ export interface SomaBootstrapOptions {
65
129
  diagnostics?: SomaDiagnostics;
66
130
  telemetry?: SomaTelemetry;
67
131
  assetResolver?: SomaAssetResolver;
132
+ /**
133
+ * Host 级组件注册(组件体系模块 7)。
134
+ * 经 `@soma-host/bootstrap/soma-bootstrap.ts` 的 configureSomaBootstrap 注入,
135
+ * 对该 Host 的所有页面生效;页面资产 components 同名时覆盖 Host 级定义。
136
+ */
137
+ components?: Record<string, SomaComponentDefinition>;
138
+ /**
139
+ * Host 自定义格式化管道(模块 7 U4):{ 管道名: 纯函数 },与内置管道合并。
140
+ * 内置:money / tpl / date / percent / plural。
141
+ */
142
+ pipes?: Record<string, SomaPipeFn>;
143
+ /**
144
+ * 阶梯词汇注册位(F-09 / 契约 C5),与组件注册同点:
145
+ * `adaptiveVocabulary: createSomaUiAdaptiveVocabulary()`。
146
+ *
147
+ * core **不内置任何级语义**——语法归语言、词汇归组件。不注册而页面声明了
148
+ * `adaptive.ladder` 时按"词汇未知"快速失败,而不是静默忽略那些级。
149
+ */
150
+ adaptiveVocabulary?: SomaAdaptiveVocabulary;
68
151
  /** Render-engine middleware chain (opt-in) */
69
152
  renderMiddleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
70
153
  /**
@@ -72,6 +155,20 @@ export interface SomaBootstrapOptions {
72
155
  * Use `createPermissionMiddleware` when events declare `permission:code` in pipeline.
73
156
  */
74
157
  eventMiddleware?: SomaMiddlewareChain<SomaEventMiddlewareContext>;
158
+ /**
159
+ * 错误采集接线(默认关闭:不给就一个全局监听都不装)。
160
+ * 库不该擅自劫持 window 的错误钩子,是否采集由 Host 显式决定。
161
+ */
162
+ errorReporting?: SomaBootstrapErrorReporting;
163
+ // 主题不在此:无 theme / themeEngine。声明走 appConfig.theme,函数走 applyTheme(引擎内建)。
164
+ }
165
+
166
+ /**
167
+ * 缺省上报通道:单行 JSON 进 console.error。
168
+ * 单行 JSON 而不是人读叙述——服务端日志采集器 / jq 能直接聚合(日志规范 §5.2)。
169
+ */
170
+ function reportToConsole(event: SomaErrorEvent): void {
171
+ console.error(`[soma-core][可观测] ${JSON.stringify(event)}`);
75
172
  }
76
173
 
77
174
  export interface ParsedRuntimeAssets {
@@ -107,17 +204,38 @@ export class SomaBootstrap {
107
204
  private runtimeResolver: SomaScopeResolver | null = null;
108
205
  private proxy: SomaReactiveProxy | null = null;
109
206
  private domainInstance: SomaPageRoot | null = null;
207
+ private componentManager: SomaComponentManager | null = null;
208
+ private hostComponents: Record<string, SomaComponentDefinition> = {};
209
+ private pipeRegistry: SomaPipeRegistry;
210
+ /** 阶梯词汇表:Host 级注册,对该 Host 全部页面生效;未注册时恒为 undefined */
211
+ private readonly adaptiveVocabulary?: SomaAdaptiveVocabulary;
212
+ /** 数据对象层:当前页面的声明(无 *_data.yaml 时为 null,整条路径旁路) */
213
+ private dataConfig: SomaDataConfig | null = null;
214
+ /** 数据对象层:最近一次取数任务(whenDataReady 暴露给测试/调试) */
215
+ private dataReady: Promise<void> | null = null;
216
+ /** 数据对象层:字段字典产物(soma-ui 双态映射消费) */
217
+ private dataDicts: SomaDataDicts = {};
110
218
  private mounted = false;
111
219
  private diagnostics: SomaDiagnostics;
112
220
  private readonly telemetry: SomaTelemetry;
113
221
  private container: HTMLElement | null = null;
114
222
  private assets: SomaPageAssets | null = null;
223
+ /** 错误采集配置(null = 未开启,整条路径旁路) */
224
+ private readonly errorReporting: SomaBootstrapErrorReporting | null;
225
+ /** 错误采集句柄:mount 时装、cleanup 时摘,生命周期与页面严格同寿 */
226
+ private errorReporter: SomaErrorReporterHandle | null = null;
115
227
  constructor(options: SomaBootstrapOptions = {}) {
116
228
  this.adapter = options.adapter ?? new SomaContainerAdapter();
117
229
  this.scheduler = options.scheduler ?? new SomaScheduler();
118
230
  this.diagnostics = options.diagnostics ?? new SomaDiagnostics();
119
231
  this.telemetry = options.telemetry ?? new SomaTelemetry();
120
- this.assetResolver = options.assetResolver ?? new SomaAssetResolver();
232
+ this.adaptiveVocabulary = options.adaptiveVocabulary;
233
+ this.assetResolver = options.assetResolver
234
+ ?? new SomaAssetResolver(undefined, { adaptiveVocabulary: this.adaptiveVocabulary });
235
+ this.hostComponents = options.components ?? {};
236
+ this.pipeRegistry = new SomaPipeRegistry(options.pipes);
237
+ // 复制一份:身份会随 setErrorReportingPage 变,不该改到调用方手里的对象
238
+ this.errorReporting = options.errorReporting ? { ...options.errorReporting } : null;
121
239
 
122
240
  this.renderMiddleware = options.renderMiddleware ?? new SomaMiddlewareChain();
123
241
 
@@ -126,24 +244,47 @@ export class SomaBootstrap {
126
244
 
127
245
  async mount(container: HTMLElement, assets: SomaPageAssets): Promise<void> {
128
246
  const mountStarted = globalThis.performance?.now?.() ?? Date.now();
247
+ // 首屏三段打点:走到这里资产已经在手(宿主若在拉取前 startBootTimings,段一即覆盖网络耗时;
248
+ // 宿主直接带资产调 mount 时段一趋近 0,属实测事实而非误差)。默认未开启时这两行是两次布尔判断。
249
+ maybeStartBootTimings();
250
+ markBootPhase('assetsReady');
129
251
  setActiveTelemetry(this.telemetry);
252
+ // 采集器先于一切装上:挂载途中炸掉的错误同样要能归因到页面
253
+ this.setupErrorReporting();
130
254
  try {
131
255
  // 仅当未注入时才创建新的 diagnostics
132
256
  if (!this.mounted) {
133
257
  this.scheduler.setDiagnostics(this.diagnostics);
134
258
  }
135
259
  this.container = container;
260
+ // 源声明只允许在构建/服务端编译;浏览器 mount 只消费运行时资产。
261
+ if (assets.uiYaml && isSomaDeclarationSource(assets.uiYaml)) {
262
+ throw new Error(
263
+ '[SomaBootstrap] 收到未编译的 SOMA DSL 源声明。'
264
+ + '请先用 compilePageAssets(构建/测试)或 Host 页面编译入口生成运行时资产。',
265
+ );
266
+ }
136
267
  this.assets = { ...assets };
137
268
 
138
269
  // 1. 解析资产(委托给 AssetResolver)
139
- const parsed = this.assetResolver.resolve(assets);
270
+ const parsed = this.assetResolver.resolve(this.assets);
140
271
 
141
272
  // 2. 挂载 HTML
142
- this.adapter.mount(container, assets.html, assets.includes);
273
+ this.adapter.mount(container, this.assets.html, this.assets.includes);
274
+
275
+ // 2.5 组件展开(页面引擎构建前:模板注入、锚点作用域化、插槽投影)
276
+ this.setupComponentManager(container, this.assets, parsed.uiConfig);
277
+
278
+ // 2.6 主题派生与注入(app.config theme: { brand } 一行换装,缺省旁路)
279
+ this.applyHostTheme(parsed.appConfig);
143
280
 
144
281
  // 3. 创建领域实例并注入配置
145
282
  this.domainInstance = this.createDomainInstance(assets.DomainClass, parsed, assets.routerPath);
146
283
 
284
+ // 3.5 数据对象层(五件套可选件):首渲前解析声明并注入 reloadData 钩子;
285
+ // 声明非法只告警不阻断挂载(data 保持空对象)
286
+ this.prepareDataLayer(this.domainInstance, assets);
287
+
147
288
  // 4. 包装响应式代理
148
289
  this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
149
290
  this.domainInstance = this.proxy.wrap(this.domainInstance);
@@ -151,6 +292,10 @@ export class SomaBootstrap {
151
292
  // 5. 构建运行时(委托给 RuntimeBuilder)
152
293
  await this.buildRuntime(parsed);
153
294
 
295
+ // 5.5 数据对象层:异步取数(不阻塞首屏),完成后注入 page.data 并全量渲染
296
+ if (this.dataConfig) {
297
+ void this.loadDataObjects();
298
+ }
154
299
  if (typeof this.domainInstance.onMount === 'function') {
155
300
  await this.domainInstance.onMount();
156
301
  }
@@ -158,7 +303,9 @@ export class SomaBootstrap {
158
303
  this.mounted = true;
159
304
  recordMetric('bootstrap.mount', (globalThis.performance?.now?.() ?? Date.now()) - mountStarted);
160
305
  } catch (error) {
161
- console.error('[SomaBootstrap] Mount failed:', error);
306
+ console.error('[soma-core][引擎] 页面挂载失败:', error);
307
+ // 必须在 cleanup 之前上报:cleanup 会摘掉采集器
308
+ this.captureEngineError(error);
162
309
  this.cleanup();
163
310
  throw error;
164
311
  }
@@ -196,7 +343,19 @@ export class SomaBootstrap {
196
343
  }
197
344
 
198
345
  const parsed = this.assetResolver.resolve(merged);
346
+
347
+ // 旧页面的组件实例必须在 DOM 被换掉**之前**销毁。
348
+ // adapter.mount 是 `container.innerHTML = html`:跑完之后旧宿主已是游离节点,
349
+ // 此时才触发的 ctrl.onUnmount 里,归还焦点、解锁滚动、按 host 定位的
350
+ // portal/observer 清理全部静默落空(游离节点上 focus() 是 no-op,不报错);
351
+ // 更坏的是 `document.querySelector` 这类反查会**命中新页面的同名节点**,
352
+ // 清理动作落到刚挂上来的新 DOM 上——不报错,还误伤。
353
+ // setupComponentManager 里那次 destroy() 是防御性兜底,删这一行会把上述后果全部放回来。
354
+ this.componentManager?.destroy();
355
+ this.componentManager = null;
356
+
199
357
  this.adapter.mount(this.container, merged.html, merged.includes);
358
+ this.setupComponentManager(this.container, merged, parsed.uiConfig);
200
359
 
201
360
  if (overrides.DomainClass) {
202
361
  this.proxy?.dispose();
@@ -218,6 +377,12 @@ export class SomaBootstrap {
218
377
  await this.buildRuntime(parsed);
219
378
  this.startDeclarativeTimers();
220
379
 
380
+ // 数据对象层:hotSwap 后按合并资产重建声明并重取(无声明时零路径变化)
381
+ this.prepareDataLayer(this.domainInstance, merged);
382
+ if (this.dataConfig) {
383
+ void this.loadDataObjects();
384
+ }
385
+
221
386
  if (snapshotId !== null) {
222
387
  try {
223
388
  this.restoreSnapshot(snapshotId);
@@ -267,7 +432,8 @@ export class SomaBootstrap {
267
432
  this.domainInstance.onUnmount();
268
433
  }
269
434
  } catch (error) {
270
- console.error('[SomaBootstrap] onUnmount error:', error);
435
+ console.error('[soma-core][引擎] onUnmount 回调异常:', error);
436
+ this.captureEngineError(error);
271
437
  }
272
438
 
273
439
  this.cleanup();
@@ -324,6 +490,16 @@ export class SomaBootstrap {
324
490
  return this.renderEngine?.getRegisteredSomaIds() ?? [];
325
491
  }
326
492
 
493
+ /** 数据对象层字段字典产物(对象名 → 字段名 → 字典条目;无声明时为空对象) */
494
+ getDataDicts(): SomaDataDicts {
495
+ return this.dataDicts;
496
+ }
497
+
498
+ /** 等待当前数据对象取数任务完成(测试 / 调试;无声明时立即 resolve) */
499
+ whenDataReady(): Promise<void> {
500
+ return this.dataReady ?? Promise.resolve();
501
+ }
502
+
327
503
  /** 获取渲染引擎(测试 / 调试) */
328
504
  getRenderEngine(): SomaRenderEngine | null {
329
505
  return this.renderEngine;
@@ -337,8 +513,48 @@ export class SomaBootstrap {
337
513
  return this.renderEngine.watch(path, callback, options);
338
514
  }
339
515
 
516
+ /**
517
+ * 更新错误采集的页面身份。
518
+ * 声明态页面"发布新版本 → 原地重渲"时调用,后续错误立刻落在新版本上——
519
+ * 这一个调用就是"哪个版本引入的错误"这个问题的全部答案。
520
+ * 未开启采集时是安全的空操作。
521
+ */
522
+ setErrorReportingPage(page: SomaPageIdentity): void {
523
+ if (this.errorReporting) {
524
+ this.errorReporting.page = page;
525
+ }
526
+ this.errorReporter?.setPage(page);
527
+ }
528
+
340
529
  // ─── 私有方法 ──────────────────────────────────────────
341
530
 
531
+ /** 装(或复用)错误采集器;未配置时整条路径旁路,一个全局监听都不装 */
532
+ private setupErrorReporting(): void {
533
+ if (!this.errorReporting) {
534
+ return;
535
+ }
536
+ if (this.errorReporter) {
537
+ // 同一 bootstrap 重复 mount / hotSwap:只换身份,不重复挂全局监听
538
+ this.errorReporter.setPage(this.errorReporting.page);
539
+ return;
540
+ }
541
+ this.errorReporter = installSomaErrorReporter({
542
+ page: this.errorReporting.page,
543
+ report: this.errorReporting.report ?? reportToConsole,
544
+ dedupeWindowMs: this.errorReporting.dedupeWindowMs,
545
+ maxEvents: this.errorReporting.maxEvents,
546
+ });
547
+ }
548
+
549
+ /**
550
+ * 引擎自身捕获的异常进同一采集通道。
551
+ * 全局 error 监听抓不到这些——它们已经被引擎 catch 住了(页面不崩,但确实错了),
552
+ * 不显式补一条,可观测数据就会漏掉最该看的那类问题。
553
+ */
554
+ private captureEngineError(error: unknown): void {
555
+ this.errorReporter?.capture(error, 'runtime');
556
+ }
557
+
342
558
  private createDomainInstance(
343
559
  DomainClass: new () => SomaPageRoot,
344
560
  parsed: ParsedRuntimeAssets,
@@ -370,6 +586,133 @@ export class SomaBootstrap {
370
586
  return raw;
371
587
  }
372
588
 
589
+ // ─── 数据对象层(*_data.yaml,可选件) ─────────────────────
590
+
591
+ /**
592
+ * 首渲前解析数据对象声明并向 Domain 实例注入 reloadData 钩子。
593
+ * 无声明(dataConfig/dataYaml 均缺省)时整条路径旁路,加载零变化;
594
+ * 声明非法只 console.error,页面继续以空 data 挂载(不阻塞)。
595
+ */
596
+ private prepareDataLayer(instance: SomaPageRoot, assets: SomaPageAssets): void {
597
+ this.dataConfig = null;
598
+ this.dataReady = null;
599
+ this.dataDicts = {};
600
+
601
+ const hasDeclaration = assets.dataConfig !== undefined
602
+ || (typeof assets.dataYaml === 'string' && assets.dataYaml.trim() !== '');
603
+ if (!hasDeclaration) return;
604
+
605
+ try {
606
+ const config = assets.dataConfig ?? parseDataYaml(assets.dataYaml!);
607
+ if (Object.keys(config.objects).length === 0) return;
608
+ this.dataConfig = config;
609
+ } catch (error) {
610
+ console.error('[soma-core][数据] 数据对象声明解析失败(页面继续以空 data 挂载):', error);
611
+ this.captureEngineError(error);
612
+ return;
613
+ }
614
+
615
+ instance._reloadData = () => this.loadDataObjects();
616
+ }
617
+
618
+ /**
619
+ * 执行数据对象取数:解析完成后注入 page.data、缓存字段字典并触发一次全量渲染。
620
+ * 任何失败均不阻塞页面:data 置空对象 + console.error。
621
+ */
622
+ private loadDataObjects(): Promise<void> {
623
+ const instance = this.domainInstance;
624
+ const config = this.dataConfig;
625
+ const services = instance?._services;
626
+ if (!instance || !config || !services) {
627
+ return Promise.resolve();
628
+ }
629
+
630
+ // api 声明允许写全路径(如 /api/order/detail):与 http 服务 baseURL 重叠时去重,
631
+ // 避免拼出 /api/api/... 的双前缀
632
+ const baseURL = String(services.config.get('apiBaseUrl') ?? '/api');
633
+ const http = {
634
+ get: <T,>(url: string, requestConfig?: { params?: Record<string, string> }) =>
635
+ services.http.get<T>(
636
+ baseURL && baseURL !== '/' && url.startsWith(`${baseURL}/`) ? url.slice(baseURL.length) : url,
637
+ requestConfig,
638
+ ),
639
+ };
640
+
641
+ const task = Promise.resolve()
642
+ .then(() => {
643
+ const resolver = new SomaDataObjectResolver(config, {
644
+ http,
645
+ query: (key) => readQueryParam(key, services.router.getCurrentPath()),
646
+ page: () => this.domainInstance,
647
+ pipes: this.pipeRegistry,
648
+ locale: () => instance._locale as Record<string, unknown> | undefined,
649
+ });
650
+ return resolver.resolve();
651
+ })
652
+ .then((result) => {
653
+ if (this.domainInstance !== instance) return; // 页面已卸载/热换,丢弃过期结果
654
+ this.dataDicts = result.dicts;
655
+ this.domainInstance.data = result.objects;
656
+ this.renderEngine?.render();
657
+ })
658
+ .catch((error) => {
659
+ console.error('[soma-core][数据] 数据对象解析失败(data 保持空对象):', error);
660
+ this.captureEngineError(error);
661
+ if (this.domainInstance === instance) {
662
+ this.domainInstance.data = {};
663
+ this.renderEngine?.render();
664
+ }
665
+ });
666
+
667
+ this.dataReady = task;
668
+ return task;
669
+ }
670
+
671
+ /**
672
+ * 主题派生注入:app.config 声明 theme.brand 时全库换装;配置非法只告警不阻断挂载。
673
+ * 主题是引擎内建路径,不是 bootstrap 可注册能力。
674
+ */
675
+ private applyHostTheme(appConfig: unknown): void {
676
+ const theme = (appConfig as { theme?: SomaThemeInput } | undefined)?.theme;
677
+ if (!theme?.brand) {
678
+ return;
679
+ }
680
+ try {
681
+ applyTheme(theme);
682
+ } catch (error) {
683
+ console.error('[soma-core][主题] 主题派生失败(保持默认令牌):', error);
684
+ this.captureEngineError(error);
685
+ }
686
+ }
687
+
688
+ /** 组件管理器装配:无 components 资产时保持 null,组件能力整体旁路 */
689
+ private setupComponentManager(
690
+ container: HTMLElement,
691
+ assets: SomaPageAssets,
692
+ uiConfig: UiConfig,
693
+ ): void {
694
+ // 兜底销毁:真正的销毁时机由调用方负责(hotSwap 必须在 adapter.mount 之前销毁,
695
+ // 否则 onUnmount 拿到的是游离宿主)。这里保留是为了任何新调用方都不会漏销毁。
696
+ this.componentManager?.destroy();
697
+ this.componentManager = null;
698
+
699
+ // Host 级注册(构造选项)+ 页面级资产,页面同名覆盖
700
+ const defs = { ...this.hostComponents, ...(assets.components ?? {}) };
701
+ if (Object.keys(defs).length === 0) {
702
+ return;
703
+ }
704
+
705
+ const registry = new SomaComponentRegistry();
706
+ registry.registerAll(defs);
707
+ this.componentManager = new SomaComponentManager({
708
+ registry,
709
+ scheduler: this.scheduler,
710
+ diagnostics: this.diagnostics,
711
+ pipeRegistry: this.pipeRegistry,
712
+ });
713
+ this.componentManager.prepare(container, uiConfig);
714
+ }
715
+
373
716
  private async buildRuntime(parsed: ParsedRuntimeAssets): Promise<void> {
374
717
  if (!this.container || !this.domainInstance) return;
375
718
 
@@ -394,6 +737,8 @@ export class SomaBootstrap {
394
737
  diagnostics: this.diagnostics,
395
738
  renderMiddleware: this.renderMiddleware,
396
739
  eventMiddleware: this.eventMiddleware,
740
+ pipeRegistry: this.pipeRegistry,
741
+ adaptiveVocabulary: this.adaptiveVocabulary,
397
742
  });
398
743
 
399
744
  this.parsedTimers = parsed.timers;
@@ -406,6 +751,26 @@ export class SomaBootstrap {
406
751
  this.triggerEngine = runtime.triggerEngine;
407
752
  this.timerEngine = runtime.timerEngine;
408
753
 
754
+ // 组件实例挂载(页面引擎就绪后:emit 路由标记、props watch、行内钩子)
755
+ this.componentManager?.activate({
756
+ container: this.container,
757
+ renderEngine: runtime.renderEngine,
758
+ eventEngine: runtime.eventEngine,
759
+ resolver: runtime.resolver,
760
+ manifest: runtime.manifest,
761
+ services: this.domainInstance._services as unknown as Record<string, unknown> | undefined,
762
+ });
763
+
764
+ // 界面中途提交接线:Domain 在长任务里调 `this.publishUi()` 时,
765
+ // 把此刻积累的 patch 立刻上屏而不结束事件事务(见 SomaRuntimeServices.ui)
766
+ if (this.domainInstance?._services) {
767
+ this.domainInstance._services.ui = {
768
+ publish: async () => {
769
+ await runtime.renderEngine.publishInTransaction();
770
+ },
771
+ };
772
+ }
773
+
409
774
  this.proxy?.setOnChange((path, value, oldValue) => {
410
775
  this.renderEngine?.schedulePatch(path, value);
411
776
  this.styleBinder?.onPropertyChange(path, value);
@@ -447,6 +812,8 @@ export class SomaBootstrap {
447
812
  private cleanup(): void {
448
813
  this.scheduler.cancelAll('unmount');
449
814
  this.stopDeclarativeTimers();
815
+ this.componentManager?.destroy();
816
+ this.componentManager = null;
450
817
  this.proxy?.dispose();
451
818
  this.eventEngine?.destroy();
452
819
  this.renderEngine?.destroy();
@@ -458,6 +825,12 @@ export class SomaBootstrap {
458
825
  this.routerUnsubscribe?.();
459
826
  this.routerUnsubscribe = null;
460
827
 
828
+ this.errorReporter?.dispose();
829
+ this.errorReporter = null;
830
+
831
+ this.dataConfig = null;
832
+ this.dataReady = null;
833
+ this.dataDicts = {};
461
834
  this.eventEngine = null;
462
835
  this.renderEngine = null;
463
836
  this.styleBinder = null;
@@ -9,7 +9,53 @@ import type {
9
9
  StyleTransition,
10
10
  ThemeConfig,
11
11
  } from '../../shared/types/style-config.types';
12
- import { applyThemeVariables } from './theme-variables';
12
+
13
+ // ─── 内置主题令牌 ─────────────────────────────────────────────────────────────
14
+
15
+ /**
16
+ * `_style.yaml` 内置 dark / light 主题落到的 CSS 变量。
17
+ *
18
+ * 这里的变量名必须是**主题引擎词汇表里的名字**:此前用的
19
+ * `--soma-bg` / `--soma-fg` / `--soma-primary` 四个名字与引擎词汇不通,
20
+ * 全仓无人消费,等于换了主题什么也没发生(而 `--soma-border` 更糟——
21
+ * 它与引擎同名,主题一切就把引擎派生的边框色顶掉)。
22
+ * 对外语法不变,改的只是内部落到的令牌名。
23
+ */
24
+ const BUILTIN_THEME_VARS: Record<string, Record<string, string>> = {
25
+ dark: {
26
+ '--soma-bg-page': '#111827',
27
+ '--soma-text-primary': '#f9fafb',
28
+ '--soma-c-primary': '#60a5fa',
29
+ '--soma-border': '#374151',
30
+ },
31
+ light: {
32
+ '--soma-bg-page': '#ffffff',
33
+ '--soma-text-primary': '#111827',
34
+ '--soma-c-primary': '#3b82f6',
35
+ '--soma-border': '#e5e7eb',
36
+ },
37
+ };
38
+
39
+ /** _style.yaml 主题切换时注入 CSS 变量(样式类仍由 Tailwind 提供) */
40
+ function applyThemeVariables(
41
+ themeName: string | null,
42
+ themeConfig?: ThemeConfig,
43
+ root?: HTMLElement,
44
+ ): void {
45
+ const el = root ?? (typeof document !== 'undefined' ? document.documentElement : null);
46
+ if (!el) return;
47
+
48
+ const vars = !themeName
49
+ ? BUILTIN_THEME_VARS.light
50
+ : {
51
+ ...(BUILTIN_THEME_VARS[themeName] ?? {}),
52
+ ...(themeConfig?.vars ?? {}),
53
+ };
54
+
55
+ for (const [key, value] of Object.entries(vars)) {
56
+ el.style.setProperty(key, value);
57
+ }
58
+ }
13
59
 
14
60
  // ─── 内部类型 ─────────────────────────────────────────────────────────────────
15
61