soma-core 1.4.1 → 1.5.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 (221) hide show
  1. package/bin/component.cjs +240 -0
  2. package/bin/eject.cjs +174 -0
  3. package/bin/migrate.cjs +362 -0
  4. package/core/build/blocks/block-compile.ts +143 -17
  5. package/core/build/blocks/migrate-flat.ts +118 -25
  6. package/core/build/compiler/page-declaration-compiler.ts +149 -5
  7. package/core/build/compiler/route-builder.ts +0 -4
  8. package/core/build/compiler/soma-precompile.js +443 -30
  9. package/core/build/component/component-graph.ts +28 -105
  10. package/core/build/component/package-loader.ts +50 -4
  11. package/core/build/eject/component-eject.ts +8 -2
  12. package/core/build/layout/constraint-solver.ts +131 -16
  13. package/core/build/layout/css-emitter.ts +15 -9
  14. package/core/build/ooui/artifact/artifact.types.ts +275 -0
  15. package/core/build/ooui/artifact/emit-artifact.ts +269 -0
  16. package/core/build/ooui/artifact/emit-html.ts +204 -0
  17. package/core/build/ooui/artifact/index.ts +53 -0
  18. package/core/build/ooui/artifact/spatial-tree.ts +268 -0
  19. package/core/build/ooui/artifact/utility-class.ts +83 -0
  20. package/core/build/ooui/composition/candidate.types.ts +323 -0
  21. package/core/build/ooui/composition/control-model.ts +114 -0
  22. package/core/build/ooui/composition/registry.ts +520 -0
  23. package/core/build/ooui/composition/select.ts +232 -0
  24. package/core/build/ooui/diagnostics/codes.ts +230 -0
  25. package/core/build/ooui/diagnostics/error.ts +235 -0
  26. package/core/build/ooui/diagnostics/format.ts +106 -0
  27. package/core/build/ooui/diagnostics/index.ts +62 -0
  28. package/core/build/ooui/diagnostics/issue.types.ts +112 -0
  29. package/core/build/ooui/engine-slot.ts +184 -0
  30. package/core/build/ooui/index.ts +1427 -0
  31. package/core/build/ooui/intent/derive-intent.ts +450 -0
  32. package/core/build/ooui/intent/field-rules.ts +330 -0
  33. package/core/build/ooui/intent/intent.types.ts +476 -0
  34. package/core/build/ooui/intent/verb-events.ts +285 -0
  35. package/core/build/ooui/page/budget.ts +503 -0
  36. package/core/build/ooui/page/compose-page.ts +736 -0
  37. package/core/build/ooui/page/index.ts +66 -0
  38. package/core/build/ooui/page/page.types.ts +402 -0
  39. package/core/build/ooui/page/region-row.ts +241 -0
  40. package/core/build/ooui/semantic/expand-page-surface.ts +180 -0
  41. package/core/build/ooui/semantic/kernel.types.ts +187 -0
  42. package/core/build/ooui/semantic/normalize.ts +784 -0
  43. package/core/build/ooui/semantic/origin.types.ts +211 -0
  44. package/core/build/ooui/semantic/role-alias.ts +154 -0
  45. package/core/build/ooui/semantic/shorthand.ts +233 -0
  46. package/core/build/ooui/semantic/surface.types.ts +78 -0
  47. package/core/build/ooui/semantic/validate-request.ts +267 -0
  48. package/core/build/ooui/spatial/emit-utility.ts +480 -0
  49. package/core/build/ooui/spatial/ir.types.ts +443 -0
  50. package/core/build/ooui/spatial/registry.ts +565 -0
  51. package/core/build/ooui/spatial/solve.ts +769 -0
  52. package/core/build/ooui/spatial/utility.types.ts +242 -0
  53. package/core/build/ooui/trace/index.ts +40 -0
  54. package/core/build/ooui/trace/render.ts +190 -0
  55. package/core/build/ooui/trace/source.types.ts +69 -0
  56. package/core/build/ooui/trace/trace.types.ts +326 -0
  57. package/core/build/pack/pack-init.ts +19 -14
  58. package/core/client/base/SomaHttpClient.ts +34 -1
  59. package/core/client/component/ai-catalog.ts +42 -0
  60. package/core/client/component/example-blocks.ts +1 -7
  61. package/core/client/component/theme-component-tokens.ts +12 -15
  62. package/core/client/component/verify-pack.ts +120 -1
  63. package/core/client/container/SomaContainerAdapter.ts +6 -2
  64. package/core/client/data/data-object-resolver.ts +27 -8
  65. package/core/client/diagnostics/telemetry-context.ts +0 -4
  66. package/core/client/engine/asset-resolver.ts +0 -1
  67. package/core/client/engine/event-engine.ts +7 -3
  68. package/core/client/engine/soma-bootstrap.ts +292 -34
  69. package/core/client/engine/style-binder.ts +0 -1
  70. package/core/client/infra/http/IHttpClient.ts +0 -6
  71. package/core/client/infra/http/SomaHttpService.ts +5 -2
  72. package/core/client/infra/notify/DomNotifyService.ts +1 -1
  73. package/core/client/infra/router/router-path.ts +0 -6
  74. package/core/client/parser/annotation-extractor.ts +1 -1
  75. package/core/client/parser/blocks/namespace.ts +30 -5
  76. package/core/client/parser/blocks/page-parser.ts +44 -1
  77. package/core/client/parser/blocks/use-parser.ts +266 -46
  78. package/core/client/parser/data-config-parser.ts +71 -3
  79. package/core/client/parser/layout-parser.ts +4 -3
  80. package/core/client/parser/reaction-parser.ts +0 -1
  81. package/core/client/parser/ui-config-parser.ts +212 -74
  82. package/core/client/theme/scene-tokens.ts +9 -3
  83. package/core/client/theme/theme-axes.ts +74 -16
  84. package/core/client/theme/theme-engine.ts +280 -69
  85. package/core/client/theme/tone-solver.ts +9 -8
  86. package/core/index.ts +38 -3
  87. package/core/server/api/load-host-service.ts +8 -2
  88. package/core/server/declaration-safety.ts +11 -0
  89. package/core/server/host/page-response-request.ts +0 -2
  90. package/core/server/host/published-page-artifact-cache.ts +244 -0
  91. package/core/server/host/published-page-assets.ts +44 -5
  92. package/core/server/mock/node/cli.mjs +0 -1
  93. package/core/server/mock/node/schema-generator.mjs +0 -1
  94. package/core/server/ooui.ts +34 -0
  95. package/core/server/page-assets.ts +8 -0
  96. package/core/server/page-declaration.ts +18 -0
  97. package/core/server/registry/asset-store.ts +327 -0
  98. package/core/server/registry/declaration-precompiler.ts +49 -6
  99. package/core/server/registry/index.ts +47 -1
  100. package/core/server/registry/page-registry-repository.ts +6 -2
  101. package/core/server/registry/page-registry-store.ts +133 -19
  102. package/core/server/registry/publish-asset-pin.ts +557 -0
  103. package/core/server/registry/services/pages/List.ts +15 -3
  104. package/core/server/registry/validation/compile-gate.ts +180 -8
  105. package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
  106. package/core/shared/component/derive-sample.ts +290 -0
  107. package/core/shared/component/field-lines.ts +563 -0
  108. package/core/shared/container-breakpoints.ts +46 -0
  109. package/core/shared/object-semantics.ts +240 -0
  110. package/core/shared/ooui-declaration.ts +235 -0
  111. package/core/shared/types/component-contract.types.ts +30 -13
  112. package/core/shared/types/data-config.types.ts +95 -0
  113. package/core/shared/types/domain.types.ts +0 -24
  114. package/core/shared/types/engine.types.ts +0 -5
  115. package/core/shared/types/layout-constraint.types.ts +16 -0
  116. package/core/shared/types/ui-config.types.ts +163 -13
  117. package/dist/cli/soma.js +24 -11
  118. package/dist/core/index.cjs +2424 -1098
  119. package/dist/types/build/blocks/block-compile.d.ts +16 -1
  120. package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
  121. package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
  122. package/dist/types/build/compiler/route-builder.d.ts +0 -1
  123. package/dist/types/build/component/component-graph.d.ts +17 -53
  124. package/dist/types/build/component/package-loader.d.ts +8 -1
  125. package/dist/types/build/layout/constraint-solver.d.ts +46 -4
  126. package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
  127. package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
  128. package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
  129. package/dist/types/build/ooui/artifact/index.d.ts +5 -0
  130. package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
  131. package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
  132. package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
  133. package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
  134. package/dist/types/build/ooui/composition/registry.d.ts +66 -0
  135. package/dist/types/build/ooui/composition/select.d.ts +63 -0
  136. package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
  137. package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
  138. package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
  139. package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
  140. package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
  141. package/dist/types/build/ooui/engine-slot.d.ts +41 -0
  142. package/dist/types/build/ooui/index.d.ts +286 -0
  143. package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
  144. package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
  145. package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
  146. package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
  147. package/dist/types/build/ooui/page/budget.d.ts +28 -0
  148. package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
  149. package/dist/types/build/ooui/page/index.d.ts +4 -0
  150. package/dist/types/build/ooui/page/page.types.d.ts +264 -0
  151. package/dist/types/build/ooui/page/region-row.d.ts +16 -0
  152. package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
  153. package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
  154. package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
  155. package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
  156. package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
  157. package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
  158. package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
  159. package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
  160. package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
  161. package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
  162. package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
  163. package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
  164. package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
  165. package/dist/types/build/ooui/trace/index.d.ts +3 -0
  166. package/dist/types/build/ooui/trace/render.d.ts +42 -0
  167. package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
  168. package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
  169. package/dist/types/client/base/SomaHttpClient.d.ts +8 -0
  170. package/dist/types/client/component/ai-catalog.d.ts +9 -0
  171. package/dist/types/client/component/example-blocks.d.ts +0 -2
  172. package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
  173. package/dist/types/client/component/verify-pack.d.ts +10 -0
  174. package/dist/types/client/data/data-object-resolver.d.ts +10 -2
  175. package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
  176. package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
  177. package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
  178. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  179. package/dist/types/client/infra/router/router-path.d.ts +0 -2
  180. package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
  181. package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
  182. package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
  183. package/dist/types/client/parser/data-config-parser.d.ts +13 -0
  184. package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
  185. package/dist/types/client/theme/scene-tokens.d.ts +9 -3
  186. package/dist/types/client/theme/theme-axes.d.ts +64 -1
  187. package/dist/types/client/theme/theme-engine.d.ts +13 -8
  188. package/dist/types/client/theme/tone-solver.d.ts +9 -5
  189. package/dist/types/index.d.ts +6 -4
  190. package/dist/types/server/declaration-safety.d.ts +7 -0
  191. package/dist/types/server/host/page-response-request.d.ts +0 -1
  192. package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
  193. package/dist/types/server/ooui.d.ts +18 -0
  194. package/dist/types/server/page-assets.d.ts +7 -0
  195. package/dist/types/server/page-declaration.d.ts +14 -0
  196. package/dist/types/server/registry/asset-store.d.ts +112 -0
  197. package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
  198. package/dist/types/server/registry/index.d.ts +3 -1
  199. package/dist/types/server/registry/page-registry-store.d.ts +57 -4
  200. package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
  201. package/dist/types/server/registry/services/pages/List.d.ts +9 -3
  202. package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
  203. package/dist/types/shared/component/derive-sample.d.ts +37 -0
  204. package/dist/types/shared/component/field-lines.d.ts +19 -0
  205. package/dist/types/shared/container-breakpoints.d.ts +42 -0
  206. package/dist/types/shared/object-semantics.d.ts +42 -0
  207. package/dist/types/shared/ooui-declaration.d.ts +135 -0
  208. package/dist/types/shared/types/component-contract.types.d.ts +29 -12
  209. package/dist/types/shared/types/data-config.types.d.ts +86 -0
  210. package/dist/types/shared/types/domain.types.d.ts +0 -21
  211. package/dist/types/shared/types/engine.types.d.ts +0 -4
  212. package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
  213. package/dist/types/shared/types/ui-config.types.d.ts +157 -12
  214. package/next.config.js +106 -13
  215. package/package.json +28 -2
  216. package/core/client/host-bridge/index.ts +0 -27
  217. package/core/client/parser/yaml-loader.ts +0 -36
  218. package/core/shared/manifest/manifest-contract.ts +0 -12
  219. package/dist/types/client/host-bridge/index.d.ts +0 -9
  220. package/dist/types/client/parser/yaml-loader.d.ts +0 -21
  221. package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
@@ -14,7 +14,11 @@
14
14
  import type { SomaComponentDefinition } from './component-definition.types';
15
15
  import type { SomaComponentPack } from './component-pack';
16
16
  import { PACK_NAME_PATTERN } from './component-pack';
17
- import { findNestedMutableContractDefault } from '../../shared/types/component-contract.types';
17
+ import {
18
+ findNestedMutableContractDefault,
19
+ type SomaContractField,
20
+ } from '../../shared/types/component-contract.types';
21
+ import { deriveContractSample, hasRenderableSample } from '../../shared/component/derive-sample';
18
22
 
19
23
  const LAYERS = new Set(['atom', 'composite', 'solution', 'template', 'page', 'token']);
20
24
 
@@ -32,6 +36,16 @@ export interface VerifyPackOptions {
32
36
  * 换肤与 RTL 的正确性没有任何自动保障。
33
37
  */
34
38
  skipStyleChecks?: boolean;
39
+ /**
40
+ * 要求 solution 层组件带得出样张(REQ-012,默认开)。
41
+ *
42
+ * 没有示例值的业务组件在展示页上只有一个空壳,在视觉矩阵里量不出真实高度,
43
+ * 在 AI 那边只剩一句 desc——三处都不报错,所以要在这里拦。
44
+ * 存量组件用 samplePending 豁免,清单只减不增。
45
+ */
46
+ requireSamples?: boolean;
47
+ /** 样张待补清单(组件名):只减不增 */
48
+ samplePending?: readonly string[];
35
49
  }
36
50
 
37
51
  /**
@@ -59,8 +73,12 @@ export function verifyComponentPack(
59
73
  issues.push('[包] 一个组件都没有');
60
74
  }
61
75
 
76
+ const pending = new Set(options.samplePending ?? []);
62
77
  for (const [key, definition] of Object.entries(pack.components)) {
63
78
  issues.push(...verifyDefinition(key, definition));
79
+ if (options.requireSamples !== false && !pending.has(key)) {
80
+ issues.push(...verifySample(key, definition));
81
+ }
64
82
  }
65
83
  issues.push(...verifyStyleRegistration(pack));
66
84
  if (!options.skipStyleChecks) {
@@ -121,6 +139,7 @@ function verifyDefinition(key: string, definition: SomaComponentDefinition): str
121
139
  `[契约] ${label} 的 prop "${propName}" default.${nestedMutablePath} 是嵌套可变默认值——运行时只隔离最外层(规则 C4a)`,
122
140
  );
123
141
  }
142
+ issues.push(...verifyFieldTree(label, propName, prop as unknown as SomaContractField));
124
143
  }
125
144
 
126
145
  const ai = contract.ai as Record<string, unknown> | undefined;
@@ -163,6 +182,106 @@ function verifyDefinition(key: string, definition: SomaComponentDefinition): str
163
182
  return issues;
164
183
  }
165
184
 
185
+ /**
186
+ * 字段树自检(REQ-012)。
187
+ *
188
+ * 查的都是「不报错但坏掉」:示例值类型对不上会静默渲染成错误形状;
189
+ * object 没写 fields 等于形状没描述,展示页与 AI 拿不到任何东西。
190
+ */
191
+ function verifyFieldTree(label: string, path: string, field: SomaContractField): string[] {
192
+ const issues: string[] = [];
193
+ if (!field || typeof field !== 'object') return issues;
194
+
195
+ if (field.type === 'object' && field.fields === undefined && field.example === undefined) {
196
+ issues.push(
197
+ `[字段] ${label} 的 "${path}" 是 object 却既没有 fields 也没有 example——`
198
+ + '对象的形状必须写出来,否则展示页与 AI 只能猜',
199
+ );
200
+ }
201
+ if (field.type === 'array' && field.items === undefined && field.example === undefined) {
202
+ issues.push(
203
+ `[字段] ${label} 的 "${path}" 是 array 却既没有 items 也没有 example——`
204
+ + '元素形状必须写出来',
205
+ );
206
+ }
207
+ if (field.type === 'enum' && (!field.values || field.values.length === 0)) {
208
+ issues.push(`[字段] ${label} 的 "${path}" 是 enum 却没有 values`);
209
+ }
210
+ if (field.example !== undefined) {
211
+ const mismatch = exampleTypeMismatch(field.example, field);
212
+ if (mismatch) issues.push(`[字段] ${label} 的 "${path}" 示例值${mismatch}`);
213
+ }
214
+ if (field.required === true && field.default !== undefined) {
215
+ issues.push(`[字段] ${label} 的 "${path}" 同时是必填与有默认值——二选一`);
216
+ }
217
+
218
+ for (const [name, child] of Object.entries(field.fields ?? {})) {
219
+ issues.push(...verifyFieldTree(label, `${path}.${name}`, child));
220
+ }
221
+ if (field.items) {
222
+ issues.push(...verifyFieldTree(label, `${path}[]`, field.items));
223
+ }
224
+ return issues;
225
+ }
226
+
227
+ /** 示例值与字段类型对不上时返回中文原因,对得上返回 null */
228
+ function exampleTypeMismatch(value: unknown, field: SomaContractField): string | null {
229
+ switch (field.type) {
230
+ case 'string':
231
+ return typeof value === 'string' ? null : `应该是字符串,实际是 ${typeName(value)}`;
232
+ case 'number':
233
+ return typeof value === 'number' ? null : `应该是数字,实际是 ${typeName(value)}`;
234
+ case 'boolean':
235
+ return typeof value === 'boolean' ? null : `应该是布尔,实际是 ${typeName(value)}`;
236
+ case 'array':
237
+ return Array.isArray(value) ? null : `应该是数组,实际是 ${typeName(value)}`;
238
+ case 'object':
239
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
240
+ ? null
241
+ : `应该是对象,实际是 ${typeName(value)}`;
242
+ case 'enum': {
243
+ const values = field.values ?? [];
244
+ if (values.length === 0) return null;
245
+ return values.includes(value as string | number)
246
+ ? null
247
+ : `不在取值集合里(${values.join(' | ')})`;
248
+ }
249
+ default:
250
+ return null;
251
+ }
252
+ }
253
+
254
+ function typeName(value: unknown): string {
255
+ if (value === null) return 'null';
256
+ if (Array.isArray(value)) return '数组';
257
+ const names: Record<string, string> = {
258
+ string: '字符串',
259
+ number: '数字',
260
+ boolean: '布尔',
261
+ object: '对象',
262
+ };
263
+ return names[typeof value] ?? typeof value;
264
+ }
265
+
266
+ /** solution 层必须派生得出一份有内容的样张 */
267
+ function verifySample(key: string, definition: SomaComponentDefinition): string[] {
268
+ const contract = definition?.contract;
269
+ if (!contract || contract.layer !== 'solution') return [];
270
+
271
+ const issues: string[] = [];
272
+ if (!hasRenderableSample(contract)) {
273
+ issues.push(
274
+ `[样张] 组件 ${key} 的 props 一个 example 都没有——`
275
+ + '展示页只会渲染出一个空壳,视觉矩阵量不出真实高度,AI 也看不到数据形状(REQ-012)',
276
+ );
277
+ return issues;
278
+ }
279
+ for (const gap of deriveContractSample(contract).gaps) {
280
+ issues.push(`[样张] 组件 ${key} 的 "${gap.path}":${gap.reason}`);
281
+ }
282
+ return issues;
283
+ }
284
+
166
285
  /** 样式登记的键必须是本包真的提供的组件/分片 */
167
286
  function verifyStyleRegistration(pack: SomaComponentPack): string[] {
168
287
  const issues: string[] = [];
@@ -170,8 +170,8 @@ export class SomaContainerAdapter implements IContainerAdapter {
170
170
  return globalThis.performance?.now?.() ?? Date.now();
171
171
  }
172
172
 
173
- private resolveIncludes(container: HTMLElement, includes: Record<string, string>): void {
174
- const elements = container.querySelectorAll<HTMLElement>('[data-soma-include]');
173
+ private resolveIncludes(root: ParentNode, includes: Record<string, string>): void {
174
+ const elements = root.querySelectorAll<HTMLElement>('[data-soma-include]');
175
175
  for (const element of elements) {
176
176
  const includePath = element.getAttribute('data-soma-include');
177
177
  if (!includePath || !includes[includePath]) {
@@ -182,5 +182,9 @@ export class SomaContainerAdapter implements IContainerAdapter {
182
182
  element.removeAttribute('data-soma-include');
183
183
  this.resolveIncludes(element, includes);
184
184
  }
185
+
186
+ for (const template of root.querySelectorAll<HTMLTemplateElement>('template')) {
187
+ this.resolveIncludes(template.content, includes);
188
+ }
185
189
  }
186
190
  }
@@ -806,15 +806,34 @@ export class SomaDataObjectResolver {
806
806
  * 把解析器包成注入给自治组件的 data 端口(§8.4)。
807
807
  *
808
808
  * 为什么是包一层而不是直接注入解析器:解析器还有 resolve / 内部拓扑等大量能力,
809
- * 组件不该看得见。端口是刻意收窄的四个方法——读态、字典、提交、重取。
809
+ * 组件不该看得见。端口是刻意收窄的六个方法——读态、字典、反应图、窗口、提交、重取。
810
+ *
811
+ * 收的是**取当前解析器的函数**,不是解析器本身:组件实例在 activate 时就把端口抓在手里,
812
+ * 而解析器要到 loadDataObjects 之后才存在、且每次重取都换一个新的——直接收解析器,
813
+ * 组件会永久持有第一个(甚至是 null)。解析器暂缺时每个方法各有一个不抛的兜底:
814
+ * 组件在数据对象就绪之前调它是正常时序,不是错误。
815
+ *
816
+ * soma-bootstrap 注入给组件的就是这一个端口(`createStableDataPort`)——
817
+ * 「只暴露六个方法」的测试守的因此正是实际注入的那一面,而不是一份平行的抄本。
810
818
  */
811
- export function createSomaDataPort(resolver: SomaDataObjectResolver): SomaDataPort {
819
+ export function createSomaDataPort(
820
+ currentResolver: () => SomaDataObjectResolver | null | undefined,
821
+ ): SomaDataPort {
822
+ const noResolver = (action: string): SomaDataSubmitResult => ({
823
+ ok: false,
824
+ message: `数据对象尚未就绪,无法${action}(本页可能没有声明 *_data.yaml)`,
825
+ });
812
826
  return {
813
- getObject: (name) => resolver.getObject(name),
814
- getDict: (name) => resolver.getDict(name),
815
- getReactions: (name) => resolver.getReactions(name),
816
- window: (name) => resolver.window(name),
817
- submit: (name, model, mode) => resolver.submit(name, model, mode),
818
- reload: (names) => resolver.reload(names),
827
+ getObject: (name) => currentResolver()?.getObject(name),
828
+ getDict: (name) => currentResolver()?.getDict(name) ?? {},
829
+ getReactions: (name) => currentResolver()?.getReactions(name) ?? null,
830
+ window: (name) => currentResolver()?.window(name) ?? null,
831
+ submit: async (name, model, mode) => {
832
+ const resolver = currentResolver();
833
+ return resolver ? resolver.submit(name, model, mode) : noResolver(`提交 "${name}"`);
834
+ },
835
+ reload: async (names) => {
836
+ await currentResolver()?.reload(names);
837
+ },
819
838
  };
820
839
  }
@@ -6,10 +6,6 @@ export function setActiveTelemetry(telemetry: SomaTelemetry | null): void {
6
6
  active = telemetry;
7
7
  }
8
8
 
9
- export function getActiveTelemetry(): SomaTelemetry | null {
10
- return active;
11
- }
12
-
13
9
  export function recordMetric(name: string, value: number, unit = 'ms'): void {
14
10
  active?.record(name, value, unit);
15
11
  }
@@ -8,7 +8,6 @@ import { parseEventConfig } from '../parser/pipeline-parser';
8
8
  import { splitEventConfigRaw } from '../parser/trigger-parser';
9
9
  import { parseStyleConfig } from '../parser/style-config-parser';
10
10
  import { parseUiConfig } from '../parser/ui-config-parser';
11
- import type { PropertyTrigger } from '../../shared/types/trigger.types';
12
11
  import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
13
12
  import { extractConfigFromDomainClass } from '../parser/annotation-extractor';
14
13
  import { hasPageMetadata } from '../base/decorators/Page';
@@ -134,16 +134,20 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
134
134
  start: EventTarget | null,
135
135
  domEvent?: Event,
136
136
  ): { element: HTMLElement; config: SomaCompiledEvent } | null {
137
- let el: HTMLElement | null = start instanceof HTMLElement ? start : null;
137
+ // 起点可能是 SVG 图元(桑基 / 和弦 / 旭日的 <path>)。SVGElement 不是 HTMLElement——
138
+ // 这里曾一律当成 null,SVG 锚点上的点击与按键被整条静默吞掉,图表"可交互"只在契约里成立。
139
+ // 沿 parentElement 向上找锚点对任何 Element 都成立;交给下游仍按 HTMLElement 类型传,
140
+ // 下游只用 getAttribute / parentElement / tagName / focus / dataset,SVGElement 同样具备。
141
+ let el: Element | null = start instanceof Element ? start : null;
138
142
  while (el && el !== this.container) {
139
- const somaId = this.adapter.getAnchorId(el);
143
+ const somaId = this.adapter.getAnchorId(el as HTMLElement);
140
144
  if (somaId) {
141
145
  const indexed = this.manifest.eventIndex.get(`${eventType}:${somaId}`);
142
146
  // 多按键候选:同一锚点绑了 ↑↓←→/Enter/Esc 时按 event.key 挑那一条
143
147
  const config = this.pickKeyVariant(indexed, domEvent);
144
148
  // emit 路由不响应冒泡 DOM 事件(如组件内部 input 冒泡的 change)
145
149
  if (config && !config.emitRoute) {
146
- return { element: el, config };
150
+ return { element: el as HTMLElement, config };
147
151
  }
148
152
  }
149
153
  el = el.parentElement;
@@ -33,11 +33,8 @@ import type { SomaTimerEngine } from './timer-engine';
33
33
  import { createDefaultRuntimeServices } from '../runtime/SomaRuntimeServices';
34
34
  import { getBrowserUrlPath, readQueryParam } from '../infra/router/router-path';
35
35
  import { parseDataYaml } from '../parser/data-config-parser';
36
- import { SomaDataObjectResolver } from '../data/data-object-resolver';
37
- import type {
38
- SomaDataPort,
39
- SomaDataSubmitResult,
40
- } from '../../shared/types/data-config.types';
36
+ import { SomaDataObjectResolver, createSomaDataPort } from '../data/data-object-resolver';
37
+ import type { SomaDataPort } from '../../shared/types/data-config.types';
41
38
  import type { SomaDataConfig, SomaDataDicts } from '../../shared/types/data-config.types';
42
39
  import type { WatchCallback, WatcherOptions } from '../../shared/types/watcher.types';
43
40
  import type { SomaStepGraph } from '../../shared/types/step.types';
@@ -54,6 +51,7 @@ import {
54
51
  import { validateStyleFeatures } from '../component/style-features';
55
52
  import { SomaPipeRegistry, type SomaPipeFn } from '../pipes/pipe-registry';
56
53
  import { applyTheme, type SomaThemeInput } from '../theme/theme-engine';
54
+ import { validateThemeComponentTokens } from '../component/theme-component-tokens';
57
55
  import {
58
56
  installSomaErrorReporter,
59
57
  type SomaErrorEvent,
@@ -115,6 +113,98 @@ function isSomaDeclarationSource(value: string): boolean {
115
113
  });
116
114
  }
117
115
 
116
+ // ─────────────────────────────────────────────────────────────────────
117
+ // OOUI 演绎产物的注入面(REQ-014 最后一公里)
118
+ //
119
+ // 这三个常量与两个函数是**运行时那道结构闸门**的全部判据。它们刻意做成模块级
120
+ // 纯函数:闸门必须能对着"外面拿来的一份 html"单独跑,否则"引擎不产生内联事件
121
+ // 处理器"这句话在运行时这一侧就只是一句没人验证过的话
122
+ // (构建期那一侧是 `core/build/ooui/artifact/emit-html.ts` 的 `verifyArtifactHtml`)。
123
+ // ─────────────────────────────────────────────────────────────────────
124
+
125
+ /**
126
+ * 演绎区域已注入的标记。值是这份 html 的**内容指纹**,不是布尔。
127
+ *
128
+ * 布尔标记的坏法:同一个锚点换了一份产物会被当成"已经注入过了"而跳过,
129
+ * 页面继续显示上一版 DOM——渲染正常、内容是旧的、控制台一行都没有。
130
+ * 与产物侧 `css_key` 用内容哈希是同一条理由,只是这一侧的作用域是单个锚点。
131
+ */
132
+ export const SOMA_OOUI_REGION_ATTR = 'data-soma-ooui';
133
+
134
+ /**
135
+ * 产物 DOM 的标签允许集。**这就是 `emitRegionHtml` 今天产出的全集**
136
+ * (区域外壳恒为 `div`,根构件是组件时 `div`、是纯文本节点时 `span`)。
137
+ *
138
+ * 为什么是允许集不是禁用集:产物只有两种标签,禁用集只挡得住今天想得到的那几样,
139
+ * 而允许集把"想不到的那些"一并挡住。代价是发射器加新标签时这里会红——
140
+ * 那正是要的:红在写下的那天,而不是在某份被改过的资产送进 innerHTML 的那天。
141
+ */
142
+ export const SOMA_OOUI_ALLOWED_TAGS: ReadonlySet<string> = new Set(['DIV', 'SPAN']);
143
+
144
+ /**
145
+ * 产物 DOM 的属性允许集(HTML 解析器会把属性名小写化,所以只写小写)。
146
+ *
147
+ * `on*`、`src`/`href` 这类属性一个都不在里面——引擎从不产出它们
148
+ * (事件走 `eventConfig`,不进 DOM 属性;架构 §24.1),所以它们出现在这里
149
+ * 只有一个含义:这份产物不是编译器产的。
150
+ */
151
+ export const SOMA_OOUI_ALLOWED_ATTRS: ReadonlySet<string> = new Set([
152
+ 'class', 'data-soma-node', 'data-soma-id', 'data-soma-component',
153
+ ]);
154
+
155
+ /**
156
+ * 结构闸门:返回 `null` 表示这份 DOM 就是产物该有的样子,否则返回违规描述。
157
+ *
158
+ * 三条判据:
159
+ * ① 顶层恰好一个元素(`emitRegionHtml` 恒产出单个区域外壳)。
160
+ * 不查这条的话,一份"外壳 + 一段裸文本"的产物会被照单全收,
161
+ * 而多出来的那段文本在页面上只是多了一行字。
162
+ * ② 每个元素的标签在允许集内;
163
+ * ③ 每个属性名在允许集内。
164
+ */
165
+ export function findOouiDomOffence(fragment: DocumentFragment): string | null {
166
+ const roots = fragment.children;
167
+ if (roots.length !== 1) {
168
+ return `顶层元素有 ${roots.length} 个,产物恒为单个区域外壳`;
169
+ }
170
+ for (const node of Array.from(fragment.childNodes)) {
171
+ // 元素之外的顶层节点(裸文本、注释)一律拒收。发射器只产出一个外壳元素,
172
+ // 多出来的那一段在页面上只是"莫名其妙多了一行字"——没人会把它报成 bug。
173
+ // 纯空白放行:YAML 的块标量可能带一个尾换行,那不是内容。
174
+ if (node.nodeType !== 1 && (node.textContent ?? '').trim() !== '') {
175
+ return `顶层混有元素以外的节点(nodeType ${node.nodeType})`;
176
+ }
177
+ }
178
+ for (const element of Array.from(fragment.querySelectorAll('*'))) {
179
+ if (!SOMA_OOUI_ALLOWED_TAGS.has(element.tagName)) {
180
+ return `标签 <${element.tagName.toLowerCase()}>`;
181
+ }
182
+ for (const attribute of Array.from(element.attributes)) {
183
+ if (!SOMA_OOUI_ALLOWED_ATTRS.has(attribute.name)) {
184
+ return `属性 ${attribute.name}`;
185
+ }
186
+ }
187
+ }
188
+ return null;
189
+ }
190
+
191
+ /**
192
+ * 产物 html 的内容指纹(FNV-1a 32 位,8 位十六进制)。
193
+ *
194
+ * **不是安全边界**,只回答"这个锚点上挂的还是不是同一份产物"——
195
+ * 安全由上面那道结构闸门负责。所以这里不用 sha256:浏览器侧拿不到 node:crypto,
196
+ * 而 `crypto.subtle.digest` 是异步的,为一次同步的"变没变"判断引入异步
197
+ * 会把注入挪到组件展开之后(见 mount 的 2.4 与 2.5 的顺序)。
198
+ */
199
+ export function oouiHtmlFingerprint(html: string): string {
200
+ let hash = 0x811c9dc5;
201
+ for (let index = 0; index < html.length; index += 1) {
202
+ hash ^= html.charCodeAt(index);
203
+ hash = Math.imul(hash, 0x01000193);
204
+ }
205
+ return (hash >>> 0).toString(16).padStart(8, '0');
206
+ }
207
+
118
208
  /**
119
209
  * 错误采集接线声明(可观测性,默认关闭)。
120
210
  *
@@ -320,6 +410,14 @@ export class SomaBootstrap {
320
410
  // 2. 挂载 HTML
321
411
  this.adapter.mount(container, this.assets.html, this.assets.includes);
322
412
 
413
+ // 2.4 演绎产物的 DOM 落点(REQ-014 最后一公里)。
414
+ // **必须在 2.5 之前**:演绎出的根构件带 `data-soma-component`,
415
+ // 而组件展开是一次性扫描 `container.querySelectorAll('[data-soma-component]')`。
416
+ // 插在它之后的话,演绎出来的组件不会被展开——DOM 在、锚点在、
417
+ // `data-soma-component` 属性也在,只是那个组件的模板永远不注入,
418
+ // 页面上就是一个空 div,没有异常也没有日志。
419
+ this.installOouiHtml(container, parsed.uiConfig);
420
+
323
421
  // 2.5 组件展开(页面引擎构建前:模板注入、锚点作用域化、插槽投影)
324
422
  this.setupComponentManager(container, this.assets, parsed.uiConfig);
325
423
 
@@ -403,6 +501,9 @@ export class SomaBootstrap {
403
501
  this.componentManager = null;
404
502
 
405
503
  this.adapter.mount(this.container, merged.html, merged.includes);
504
+ // 与 mount 同序:演绎 DOM 先落,组件展开后扫。热替换换的是整份 innerHTML,
505
+ // 上一版的区域连同它的已注入标记一起没了,所以这里必然是一次真注入。
506
+ this.installOouiHtml(this.container, parsed.uiConfig);
406
507
  this.setupComponentManager(this.container, merged, parsed.uiConfig);
407
508
 
408
509
  if (overrides.DomainClass) {
@@ -747,6 +848,7 @@ export class SomaBootstrap {
747
848
  if (!theme?.brand) {
748
849
  return;
749
850
  }
851
+ this.reconcileThemeComponentTokens(theme);
750
852
  try {
751
853
  applyTheme(theme);
752
854
  } catch (error) {
@@ -755,6 +857,40 @@ export class SomaBootstrap {
755
857
  }
756
858
  }
757
859
 
860
+ /**
861
+ * 组件令牌对账(REQ-009 M-1):`components: { Buton: { radius: … } }` 这样一个
862
+ * 拼写错误,不对账时的表现是**"改了没反应"**——变量确实写进了 :root,
863
+ * 只是没有任何组件读它。这类错误的排查成本远高于报错。
864
+ *
865
+ * 判据住在 `component/theme-component-tokens.ts`,而它此前**一个调用者都没有**
866
+ * (由 `verify:reachable` 查出)。这里是全仓唯一同时持有「主题输入」与
867
+ * 「这一页实际可用的组件表」的地方,所以对账只能发生在这一点上。
868
+ *
869
+ * 两条边界:
870
+ * · **只告警、不阻断换装**。主题是 app 级、全部页面共享的,组件表却是逐页的;
871
+ * 曾经对账与 applyTheme 同在一个 try 里,一条对不上就把整份品牌主题一起丢掉
872
+ * (全页回落默认令牌 + 一条"主题派生失败"),与"一个令牌没人读"的后果不成比例。
873
+ * · **组件表 = Host 级 + 页面级**,与 setupComponentManager 实际装配的那张表同一口径
874
+ * (页面同名胜出)。只看 Host 级的话,只在页面资产里注册的组件会被误报成未知组件。
875
+ * 拿不到组件表时(纯预览场景)按设计跳过,不猜。
876
+ */
877
+ private reconcileThemeComponentTokens(theme: SomaThemeInput): void {
878
+ // 只读查找视图,不是组件包合成——重名裁决与告警在 setupComponentManager 里已经做过
879
+ const components = { ...this.hostComponents, ...(this.assets?.components ?? {}) };
880
+ if (Object.keys(components).length === 0) {
881
+ return;
882
+ }
883
+ const issues = validateThemeComponentTokens(theme, components);
884
+ if (issues.length === 0) {
885
+ return;
886
+ }
887
+ const message = `主题的组件令牌段有 ${issues.length} 处对不上组件契约`
888
+ + '(主题照常生效;这些令牌会写进 :root,但当前页没有组件读它们):'
889
+ + `\n${issues.map((issue) => ` · ${issue}`).join('\n')}`;
890
+ console.warn(`[soma-core][主题] ${message}`);
891
+ this.diagnostics.recordValidation('warning', `[主题组件令牌] ${message}`);
892
+ }
893
+
758
894
  /**
759
895
  * 组件可见的服务表:页面运行时服务 + data 端口(M-5)。
760
896
  *
@@ -771,17 +907,6 @@ export class SomaBootstrap {
771
907
  return { ...base, data: this.createStableDataPort() };
772
908
  }
773
909
 
774
- /**
775
- * 页面态装配(REQ-010 F-37)。
776
- *
777
- * 三个来源按优先级取:**URL > initial_state > 空**。
778
- * URL 在最前是因为它是"用户此刻明确要求看到的那一屏"(分享链接、书签、回退按钮),
779
- * 而 `initial_state` 只是作者写的缺省。反过来的话,分享链接打开后会被缺省覆盖,
780
- * 而那正是分享链接唯一的用途。
781
- *
782
- * 版本对不上的 URL 状态整份丢弃并 warn 一次:恢复一份旧结构的状态会让界面进入
783
- * 一个谁都没设计过的样子,而那种坏法是静默的(列还在、但顺序是乱的)。
784
- */
785
910
  /**
786
911
  * 约束布局产物注入(REQ-011 接线 / CL-4)。
787
912
  *
@@ -808,6 +933,151 @@ export class SomaBootstrap {
808
933
  }
809
934
  }
810
935
 
936
+ /**
937
+ * OOUI 演绎产物的 DOM 落点(REQ-014 最后一公里)。
938
+ *
939
+ * ── 为什么"没有这一步"是一种静默失败 ─────────────────────────────
940
+ * 在它之前,整条演绎链止于 `deduce()` 的返回值:六层全绿、`ooui_artifact`
941
+ * 在资产里、样式表也注入了,**页面上什么都没有**。而"锚点空着"与
942
+ * "这块本来就没写内容"在浏览器里长得一模一样——没有异常、没有日志、
943
+ * 截图里也分不开。这是最像成功的那种失败,所以落点必须有断言守着。
944
+ *
945
+ * ── 运行时收到产物就用,收到声明就拒绝代算 ───────────────────────
946
+ * 与 `installLayoutCss` / `installOouiArtifact` 同一条范式:本方法**只搬运**。
947
+ * 它不认识形态、不认识候选表、不认识组件契约——那些词汇住在 soma-ui,
948
+ * 浏览器手里根本没有,代算出来的只会是一份猜的界面。
949
+ *
950
+ * ── 为什么"引擎生成的"不等于"可信的"(架构 §24.1)───────────────
951
+ * 这串 html 随 `_ui.yaml` 走。发布期的注入面静态扫描(`declaration-safety-scan.ts`)
952
+ * 如今对 YAML 面也跑 html 那四条判据(禁用标签 / on\* 处理器 / srcdoc / 伪协议),
953
+ * 门口已经拦得住一份被改过的 `_ui.yaml`。但门口只守 Registry 这一条写路径:
954
+ * 文件态 Host 的资产、预览器直接喂进来的资产都不经过它;而 innerHTML 插入的
955
+ * `<script>` 虽然不执行,`<img onerror=…>` 却会立刻执行。所以注入前必须再核一道——
956
+ * 这是纵深防御的最后一层,不因门口补齐而省掉。
957
+ *
958
+ * 核的方式是**允许集**不是禁用集:`emitRegionHtml` 今天只产出
959
+ * `div` / `span` 两种标签与四个 `class` / `data-soma-*` 属性,
960
+ * 把这个全集写死,任何多出来的东西一律拒收。禁用集在这种两标签的产物上
961
+ * 严格更差——它只挡得住今天想得到的那几样。发射器哪天真加了新标签,
962
+ * 这里会**当场红**(而不是静默放行),红在写下的那天,这正是要的。
963
+ *
964
+ * 解析走 `<template>`:template 的内容是**惰性的**——不加载图片、不跑脚本,
965
+ * 所以"先解析再检查"这个顺序本身不会触发任何东西。检查通过之后才搬进文档。
966
+ */
967
+ private installOouiHtml(container: HTMLElement, uiConfig: UiConfig): void {
968
+ const artifact = uiConfig.oouiArtifact;
969
+ if (!artifact || artifact.regions.length === 0) return;
970
+
971
+ const doc = container.ownerDocument ?? (globalThis as { document?: Document }).document ?? null;
972
+ if (!doc || typeof doc.createElement !== 'function') {
973
+ // 非 DOM 容器(小程序 / RN 桥)。**说出来**:静默跳过的表现是
974
+ // "这个平台上演绎区域永远是空的",而那与"这页没写 ooui"分不开。
975
+ console.warn(
976
+ `[soma-core][演绎] 页面 "${uiConfig.bind.obj}" 有 ${artifact.regions.length} 个演绎区域,`
977
+ + '但当前容器没有 document,演绎 DOM 无法落地——'
978
+ + '演绎产物今天只支持 Web 容器(DOM 由 <template> 惰性解析后搬入)。',
979
+ );
980
+ return;
981
+ }
982
+
983
+ for (const region of artifact.regions) {
984
+ const host = this.adapter.findAnchor(container, region.anchor);
985
+ if (!host) {
986
+ // 构建期已对着锚点索引核过(`OOUI-SEM-ANCHOR-UNKNOWN`),这里还找不到,
987
+ // 说明 html 与 _ui.yaml 这两份资产不是同一次编译的产物。
988
+ console.warn(
989
+ `[soma-core][演绎] 演绎区域 "${region.anchor}" 在页面 HTML 里找不到锚点(data-soma-id)——`
990
+ + 'html 与 _ui.yaml 不是同一次编译的产物。这一块不会有任何内容。',
991
+ );
992
+ continue;
993
+ }
994
+
995
+ const html = typeof region.html === 'string' ? region.html : '';
996
+ if (html.trim() === '') {
997
+ console.warn(
998
+ `[soma-core][演绎] 演绎区域 "${region.anchor}" 的产物里没有 html——`
999
+ + '这是一份旧格式(或手写)的 ooui_artifact。重新跑一次构建期编译'
1000
+ + '(compilePageDeclaration)即可,运行时不代为演绎。',
1001
+ );
1002
+ continue;
1003
+ }
1004
+
1005
+ // 已注入且内容没变 → 什么都不做。标记值是**内容指纹**而不是 "1":
1006
+ // 按布尔标记的话,同一个锚点换了一份产物会被当成"已经注入过了"而跳过,
1007
+ // 表现是页面继续显示上一版的 DOM——渲染正常、内容是旧的、控制台一行都没有。
1008
+ // 与 `css_key` 用内容哈希是同一条理由,只是这一侧的作用域是单个锚点。
1009
+ const fingerprint = oouiHtmlFingerprint(html);
1010
+ if (host.getAttribute(SOMA_OOUI_REGION_ATTR) === fingerprint) continue;
1011
+
1012
+ const template = doc.createElement('template');
1013
+ // template 内容惰性:解析这一步不会加载资源、不会执行任何东西。
1014
+ template.innerHTML = html;
1015
+ const offence = findOouiDomOffence(template.content);
1016
+ if (offence !== null) {
1017
+ console.error(
1018
+ `[soma-core][演绎] 演绎区域 "${region.anchor}" 的产物 DOM 不在允许集内(${offence}),已拒绝注入。`
1019
+ + '产物随 _ui.yaml 走,而那份资产可以被手写、被改:发布期的注入面扫描虽然也扫 YAML 面,'
1020
+ + '但它只守"写进声明仓库"这个入口,绕过 Registry 的构建与发布后改资产都不经过它。'
1021
+ + '所以注入前这道结构闸门是最后一关——放行一次就等于把 innerHTML 交了出去。'
1022
+ + '正常产物只含 div/span 与 class/data-soma-node/data-soma-id/data-soma-component。'
1023
+ + '若这是发射器新加的合法形状,请同步 soma-bootstrap.ts 的 SOMA_OOUI_ALLOWED_TAGS / _ATTRS;'
1024
+ + '否则请重新跑一次 compilePageDeclaration 生成产物,不要手写 ooui_artifact。',
1025
+ );
1026
+ continue;
1027
+ }
1028
+
1029
+ // 整块换掉而不是追加:锚点是产物的落点,重复挂载不该叠出两份 DOM。
1030
+ while (host.firstChild) host.removeChild(host.firstChild);
1031
+ host.appendChild(template.content);
1032
+ host.setAttribute(SOMA_OOUI_REGION_ATTR, fingerprint);
1033
+ }
1034
+ }
1035
+
1036
+ /**
1037
+ * OOUI 演绎产物注入(REQ-014 接线)。
1038
+ *
1039
+ * 与 `installLayoutCss` 逐点同构:运行时只认**产物**,收到声明本身只告警。
1040
+ * 演绎链住在 core/build/ooui/,进 client 就等于把「运行期零演绎」这条
1041
+ * 结构性承诺撤回去——而且浏览器手里根本没有候选表与组件契约,
1042
+ * 代算出来的只会是一份猜的界面。
1043
+ *
1044
+ * 注入键用产物自带的**内容哈希**(`ooui:<sha256 前 8 位>`),不用页面名:
1045
+ * `injectStyleOnce` 没有内容冲突检测(同键不同内容静默保留第一份),
1046
+ * 按页面名命名的话,SPA 内路由切到同名不同产物的页面会继续用上一页的 CSS,
1047
+ * 页面看着渲染正常、间距全错、控制台一行都没有。
1048
+ * 位置紧接 `installLayoutCss`——都在组件实例挂载**之前**,级联顺序才稳定。
1049
+ */
1050
+ private installOouiArtifact(uiConfig: UiConfig): void {
1051
+ const artifact = uiConfig.oouiArtifact;
1052
+ if (artifact?.css && artifact.css_key) {
1053
+ injectStyleOnce(
1054
+ artifact.css_key,
1055
+ artifact.css,
1056
+ { nonce: this.componentStyleNonce ?? null },
1057
+ );
1058
+ return;
1059
+ }
1060
+ if (artifact) return; // 有产物、只是这一版没有样式表(空间层未参与):正常,不吭声
1061
+ if (uiConfig.ooui && Object.keys(uiConfig.ooui).length > 0) {
1062
+ console.warn(
1063
+ `[soma-core][演绎] 页面 "${uiConfig.bind.obj}" 声明了 ooui: 段但没有构建期产物(ooui_artifact)——`
1064
+ + '声明未经 compilePageDeclaration 演绎,本页不会产生任何演绎界面。'
1065
+ + '演绎只在构建期发生(Registry 发布 / Host 预编译),运行时不代算。',
1066
+ );
1067
+ }
1068
+ }
1069
+
1070
+ /**
1071
+ * 页面态装配(REQ-010 F-37)。
1072
+ *
1073
+ * 三个来源按优先级取:**URL > initial_state > 空**。
1074
+ * URL 在最前是因为它是"用户此刻明确要求看到的那一屏"(分享链接、书签、回退按钮),
1075
+ * 而 `initial_state` 只是作者写的缺省。反过来的话,分享链接打开后会被缺省覆盖,
1076
+ * 而那正是分享链接唯一的用途。
1077
+ *
1078
+ * 版本对不上的 URL 状态整份丢弃并 warn 一次:恢复一份旧结构的状态会让界面进入
1079
+ * 一个谁都没设计过的样子,而那种坏法是静默的(列还在、但顺序是乱的)。
1080
+ */
811
1081
  private installPageState(config: SomaPageStateConfig | undefined): void {
812
1082
  const instance = this.domainInstance;
813
1083
  if (!instance) return;
@@ -907,25 +1177,12 @@ export class SomaBootstrap {
907
1177
  );
908
1178
  }
909
1179
 
910
- /** 稳定的 data 端口壳:每次调用现取当前解析器 */
1180
+ /**
1181
+ * 稳定的 data 端口壳:每次调用现取当前解析器(解析器暂缺时的兜底住在 createSomaDataPort 里,
1182
+ * 与端口的方法面同一处——测试守的就是这里注入的那一个端口)。
1183
+ */
911
1184
  private createStableDataPort(): SomaDataPort {
912
- const noResolver = (action: string): SomaDataSubmitResult => ({
913
- ok: false,
914
- message: `数据对象尚未就绪,无法${action}(本页可能没有声明 *_data.yaml)`,
915
- });
916
- return {
917
- getObject: (name) => this.dataResolver?.getObject(name),
918
- getDict: (name) => this.dataResolver?.getDict(name) ?? {},
919
- getReactions: (name) => this.dataResolver?.getReactions(name) ?? null,
920
- window: (name) => this.dataResolver?.window(name) ?? null,
921
- submit: async (name, model, mode) =>
922
- this.dataResolver
923
- ? this.dataResolver.submit(name, model, mode)
924
- : noResolver(`提交 "${name}"`),
925
- reload: async (names) => {
926
- await this.dataResolver?.reload(names);
927
- },
928
- };
1185
+ return createSomaDataPort(() => this.dataResolver);
929
1186
  }
930
1187
 
931
1188
  /** 组件管理器装配:无 components 资产时保持 null,组件能力整体旁路 */
@@ -1024,6 +1281,7 @@ export class SomaBootstrap {
1024
1281
  this.assertNamedActionsResolvable(parsed.eventConfig);
1025
1282
  this.installPageState(parsed.uiConfig.state);
1026
1283
  this.installLayoutCss(parsed.uiConfig);
1284
+ this.installOouiArtifact(parsed.uiConfig);
1027
1285
  this.styleBinder = runtime.styleBinder;
1028
1286
  this.propertyWatcher = runtime.propertyWatcher;
1029
1287
  this.onChangeEngine = runtime.onChangeEngine;