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
@@ -4,14 +4,30 @@
4
4
  import type {
5
5
  UiConfig,
6
6
  ShowMapping,
7
- ShowValue,
8
7
  NestedShowMapping,
9
8
  BindDeclaration,
10
9
  ExtendedShowValue,
11
- ParsedShowEntry,
10
+ SomaOouiRequestDeclaration,
11
+ SomaPageOouiArtifact,
12
12
  } from '../../shared/types/ui-config.types';
13
13
  import type { OnChangeRule } from '../../shared/types/watcher.types';
14
14
  import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
15
+ import {
16
+ SOMA_OOUI_ANCHOR_GRAMMAR,
17
+ SOMA_OOUI_ANCHOR_PATTERN,
18
+ SOMA_OOUI_BINDING_KEYS,
19
+ SOMA_OOUI_LAYOUT_KEYS,
20
+ SOMA_OOUI_REQUEST_KEYS,
21
+ SOMA_OOUI_SIZINGS,
22
+ findOouiBindingUnknownKey,
23
+ findOouiLayoutProblem,
24
+ isOouiBinding,
25
+ isOouiFocus,
26
+ isOouiLayout,
27
+ isOouiMap,
28
+ isOouiText,
29
+ type SomaOouiLayoutProblem,
30
+ } from '../../shared/ooui-declaration';
15
31
  import { parseAdaptiveConfig } from './adaptive-parser';
16
32
  import { parsePageState } from './page-state-parser';
17
33
  import { parseLayoutConstraint } from './layout-parser';
@@ -174,54 +190,6 @@ function isExtendedShowValue(value: any): boolean {
174
190
  return extendedKeys.some((key) => key in value);
175
191
  }
176
192
 
177
- /**
178
- * 拆分 show 键中的 `somaId@attr` 语法
179
- *
180
- * 示例:
181
- * - "title" → { somaId: "title" }
182
- * - "avatar@src" → { somaId: "avatar", attrName: "src" }
183
- * - "body@html" → { somaId: "body", attrName: "html" }
184
- *
185
- * @param key - show 映射的键
186
- * @param path - 当前路径(用于错误信息)
187
- * @returns 拆分后的 somaId 和可选的 attrName
188
- * @throws SomaUiConfigError 键格式不合法时抛出
189
- */
190
- function parseSomaKey(
191
- key: string,
192
- path: string,
193
- ): { somaId: string; attrName?: string } {
194
- if (!key) {
195
- throw new SomaUiConfigError(`show 键不能为空`, path);
196
- }
197
-
198
- const atIndex = key.indexOf('@');
199
-
200
- if (atIndex === -1) {
201
- // 普通 somaId,无属性绑定
202
- return { somaId: key };
203
- }
204
-
205
- const somaId = key.substring(0, atIndex);
206
- const attrName = key.substring(atIndex + 1);
207
-
208
- if (!somaId) {
209
- throw new SomaUiConfigError(
210
- `show 键 "${key}" 中 @ 前的 somaId 部分为空`,
211
- path,
212
- );
213
- }
214
-
215
- if (!attrName) {
216
- throw new SomaUiConfigError(
217
- `show 键 "${key}" 中 @ 后的属性名部分为空`,
218
- path,
219
- );
220
- }
221
-
222
- return { somaId, attrName };
223
- }
224
-
225
193
  // ─── show 映射解析 ────────────────────────────────────────────────────────────
226
194
 
227
195
  /**
@@ -466,9 +434,203 @@ export function parseUiConfig(raw: any, options?: SomaUiConfigParseOptions): UiC
466
434
  config.layoutCss = raw.layout_css;
467
435
  }
468
436
 
437
+ // ooui(REQ-014):锚点 id → 一处演绎请求。这里只校验**声明形状**,
438
+ // 不演绎——演绎链住在 core/build/ooui/,运行时永远不该跑它。
439
+ // 对象名是否真的在 data: 段里、动词是否在八动词闭集里,都由构建期判
440
+ // (闭集常量住在引擎里,client import 不到;照抄一份必然漂)。
441
+ if ('ooui' in raw && raw.ooui !== undefined) {
442
+ config.ooui = parseOouiSection(raw.ooui);
443
+ }
444
+ // ooui_artifact:构建期演绎产物。运行时只从里面取样式表注入。
445
+ if ('ooui_artifact' in raw && raw.ooui_artifact !== undefined) {
446
+ config.oouiArtifact = parseOouiArtifact(raw.ooui_artifact);
447
+ }
448
+
469
449
  return config;
470
450
  }
471
451
 
452
+ // `ooui:` 的锚点文法、请求键闭集与形状判据住在 `shared/ooui-declaration.ts`:
453
+ // 构建期引擎(`core/build/ooui/`)用的是同一份,而 client 不许 import `core/build`。
454
+ // 此前这里各抄一份:锚点文法比页面组合层宽(`_list` 在这里放行、到那边才红),
455
+ // 键闭集收下了 `bound_to` / `layout` 却不搬进声明——能写、不报错、值被静默丢弃。
456
+ /**
457
+ * 演绎产物的注入键:`ooui:` + sha256 前 8 位。
458
+ *
459
+ * 收紧到内容哈希而不是"随便一个字符串",是因为 `pack-styles.ts` 的 `injectOnce`
460
+ * **没有内容冲突检测**(同键不同内容静默保留第一份)。放行一个语义名,
461
+ * SPA 内路由切页时就会拿上一页的 CSS 渲染这一页——不报错、不留痕。
462
+ */
463
+ const OOUI_CSS_KEY_PATTERN = /^ooui:[0-9a-f]{8}$/;
464
+
465
+ /**
466
+ * `ooui:` 段:`{ <锚点id>: { object, verb, focus?, through?, form?, bound_to?, layout? } }`
467
+ *
468
+ * 形状校验与构建期 `compilePageOoui` 的 `parseRequest` 用同一份键闭集与判据;
469
+ * 七个键**全部搬进声明**——`SomaOouiRequestDeclaration` 上有的字段,这里收下了就得交出去,
470
+ * 否则运行时读到的声明比作者写的少两项,而"少了"与"本来就没写"长得一模一样。
471
+ * 反过来也一样:`bound_to` 与 `layout` 这两个嵌套映射**只收闭集里的键**
472
+ * (`SOMA_OOUI_BINDING_KEYS` / `SOMA_OOUI_LAYOUT_KEYS`),`layout.sizing` 只收三档——
473
+ * 收下却不搬的键同样是"能写、不报错、值被静默丢弃"。
474
+ */
475
+ function parseOouiSection(raw: unknown): NonNullable<UiConfig['ooui']> {
476
+ if (!isOouiMap(raw)) {
477
+ throw new SomaUiConfigError(
478
+ 'ooui 必须是映射:{ <锚点id>: { object: <data 对象名>, verb: <动词> } }',
479
+ 'ooui',
480
+ );
481
+ }
482
+ const out: NonNullable<UiConfig['ooui']> = {};
483
+ for (const [anchor, spec] of Object.entries(raw)) {
484
+ const path = `ooui.${anchor}`;
485
+ if (!SOMA_OOUI_ANCHOR_PATTERN.test(anchor)) {
486
+ throw new SomaUiConfigError(
487
+ `ooui 的键必须是锚点 id(data-soma-id,${SOMA_OOUI_ANCHOR_GRAMMAR}),收到 "${anchor}"`,
488
+ path,
489
+ );
490
+ }
491
+ if (!isOouiMap(spec)) {
492
+ throw new SomaUiConfigError('演绎请求必须是映射(至少含 object 与 verb)', path);
493
+ }
494
+ for (const key of Object.keys(spec)) {
495
+ if (!(SOMA_OOUI_REQUEST_KEYS as readonly string[]).includes(key)) {
496
+ throw new SomaUiConfigError(
497
+ `演绎请求不支持键 "${key}"(可用:${SOMA_OOUI_REQUEST_KEYS.join(' / ')})`,
498
+ `${path}.${key}`,
499
+ );
500
+ }
501
+ }
502
+ const { object, verb, focus, through, form, bound_to: bound, layout } = spec;
503
+ if (!isOouiText(object)) {
504
+ throw new SomaUiConfigError('演绎请求缺少 object(页面 data: 段里的对象名)', `${path}.object`);
505
+ }
506
+ if (!isOouiText(verb)) {
507
+ throw new SomaUiConfigError('演绎请求缺少 verb(八动词之一)', `${path}.verb`);
508
+ }
509
+ const declaration: SomaOouiRequestDeclaration = { object, verb };
510
+ if (focus !== undefined) {
511
+ if (!isOouiFocus(focus)) {
512
+ // 空数组单独拦:`focus: []` 读起来像"不限",实际演绎出一个没有字段的界面——
513
+ // 框架在、标题在、空白在,是最像成功的失败。
514
+ throw new SomaUiConfigError('focus 必须是非空字段名数组(省略它才表示全部字段)', `${path}.focus`);
515
+ }
516
+ declaration.focus = [...focus];
517
+ }
518
+ if (through !== undefined) {
519
+ if (!isOouiText(through)) {
520
+ throw new SomaUiConfigError('through 必须是对象 relations 里的关系名', `${path}.through`);
521
+ }
522
+ declaration.through = through;
523
+ }
524
+ if (form !== undefined) {
525
+ if (!isOouiText(form)) {
526
+ throw new SomaUiConfigError('form 必须是形态名(逃生门,省略则由动词分派)', `${path}.form`);
527
+ }
528
+ declaration.form = form;
529
+ }
530
+ if (bound !== undefined) {
531
+ // 闭集之外的键先单独报:此前这里只取 region / as 两项、其余静默丢弃,
532
+ // 多写的那一项"能写、不报错、值没了"。键闭集与构建期同一份(SOMA_OOUI_BINDING_KEYS)。
533
+ const unknownKey = isOouiMap(bound) ? findOouiBindingUnknownKey(bound) : undefined;
534
+ if (unknownKey !== undefined) {
535
+ throw new SomaUiConfigError(
536
+ `bound_to 不支持键 "${unknownKey}"(可用:${SOMA_OOUI_BINDING_KEYS.join(' / ')})`
537
+ + '——联动只认源区域与语义事件两项,多写的键不会被任何一层读到',
538
+ `${path}.bound_to.${unknownKey}`,
539
+ );
540
+ }
541
+ if (!isOouiBinding(bound)) {
542
+ throw new SomaUiConfigError(
543
+ 'bound_to 必须是 { region, as } 两项俱全的映射(region 是另一个锚点名,as 是语义事件名)',
544
+ `${path}.bound_to`,
545
+ );
546
+ }
547
+ declaration.bound_to = { region: bound.region, as: bound.as };
548
+ }
549
+ if (layout !== undefined) {
550
+ if (!isOouiLayout(layout)) {
551
+ const problem = isOouiMap(layout) ? findOouiLayoutProblem(layout) : undefined;
552
+ throw new SomaUiConfigError(
553
+ oouiLayoutProblemMessage(layout, problem),
554
+ problem === undefined ? `${path}.layout` : `${path}.layout.${problem.key}`,
555
+ );
556
+ }
557
+ declaration.layout = layout;
558
+ }
559
+ out[anchor] = declaration;
560
+ }
561
+ return out;
562
+ }
563
+
564
+ /**
565
+ * `layout` 不合形状时的一行消息。判据在 `findOouiLayoutProblem`(与构建期同一份),
566
+ * 这里只管措辞:不是映射 / 闭集之外的键 / 值的原始类型不对 / sizing 不在三档里。
567
+ */
568
+ function oouiLayoutProblemMessage(layout: unknown, problem: SomaOouiLayoutProblem | undefined): string {
569
+ if (problem === undefined) return `layout 必须是映射(可用键:${SOMA_OOUI_LAYOUT_KEYS.join(' / ')})`;
570
+ if (problem.kind === 'unknown-key') {
571
+ return `layout 不支持键 "${problem.key}"(可用:${SOMA_OOUI_LAYOUT_KEYS.join(' / ')})`;
572
+ }
573
+ if (problem.kind === 'sizing-unknown') {
574
+ return `layout.sizing 只能是 ${SOMA_OOUI_SIZINGS.join(' / ')}`
575
+ + `(收到 ${JSON.stringify((layout as Record<string, unknown>).sizing)})`
576
+ + '——fixed 是"就这么宽",hug 是"内容多宽我多宽",fill 是"剩下的给我";省略即 fill';
577
+ }
578
+ return `layout.${problem.key} 必须是 ${problem.expected === 'number' ? '数字' : '字符串'}`;
579
+ }
580
+
581
+ /**
582
+ * `ooui_artifact:` 段:构建期产物,不手写。
583
+ *
584
+ * 这里**只校验运行时真正消费的那几个字段**(版本、区域名、样式表与它的注入键),
585
+ * `regions[].root` 那棵节点树原样收下:它是构建期的产物契约,运行时一个字段都不读。
586
+ * 在这里再写一遍深校验,等于把引擎的产物形状复制成第二份——
587
+ * 引擎加一个字段,这份忘了改,表现是"合法产物在运行时被判非法",
588
+ * 而两边的代码看着都对。
589
+ */
590
+ function parseOouiArtifact(raw: unknown): SomaPageOouiArtifact {
591
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
592
+ throw new SomaUiConfigError('ooui_artifact 必须是映射(构建期演绎产物,不手写)', 'ooui_artifact');
593
+ }
594
+ const entry = raw as Record<string, unknown>;
595
+ if (entry.version !== 1) {
596
+ throw new SomaUiConfigError(
597
+ `ooui_artifact.version 必须是 1,收到 ${JSON.stringify(entry.version)}`
598
+ + '——版本对不上的产物整份不可信,按旧字段名读出来的界面是谁都没设计过的样子',
599
+ 'ooui_artifact.version',
600
+ );
601
+ }
602
+ if (!Array.isArray(entry.regions)) {
603
+ throw new SomaUiConfigError('ooui_artifact.regions 必须是数组', 'ooui_artifact.regions');
604
+ }
605
+ for (const [index, region] of (entry.regions as unknown[]).entries()) {
606
+ if (!region || typeof region !== 'object' || Array.isArray(region)
607
+ || typeof (region as Record<string, unknown>).anchor !== 'string') {
608
+ throw new SomaUiConfigError('每个 region 必须是映射且带 anchor(锚点 id)', `ooui_artifact.regions[${index}]`);
609
+ }
610
+ }
611
+ const artifact: SomaPageOouiArtifact = {
612
+ version: 1,
613
+ regions: entry.regions as SomaPageOouiArtifact['regions'],
614
+ };
615
+ const hasCss = typeof entry.css === 'string' && entry.css.trim() !== '';
616
+ if (entry.css !== undefined && typeof entry.css !== 'string') {
617
+ throw new SomaUiConfigError('ooui_artifact.css 必须是字符串', 'ooui_artifact.css');
618
+ }
619
+ if (hasCss) {
620
+ const key = entry.css_key;
621
+ if (typeof key !== 'string' || !OOUI_CSS_KEY_PATTERN.test(key)) {
622
+ throw new SomaUiConfigError(
623
+ `ooui_artifact.css 存在时必须带内容哈希键 css_key(形如 ooui:0a1b2c3d),收到 ${JSON.stringify(key)}`
624
+ + '——样式注入没有内容冲突检测,语义名会让 SPA 路由切页时静默沿用上一页的 CSS',
625
+ 'ooui_artifact.css_key',
626
+ );
627
+ }
628
+ artifact.css = entry.css as string;
629
+ artifact.css_key = key;
630
+ }
631
+ return artifact;
632
+ }
633
+
472
634
  /** `layout:` 段:`{ <锚点id>: <约束> }`;锚点名必须是合法 somaId */
473
635
  function parseLayoutSection(raw: unknown): NonNullable<UiConfig['layout']> {
474
636
  if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
@@ -490,27 +652,3 @@ function parseLayoutSection(raw: unknown): NonNullable<UiConfig['layout']> {
490
652
  }
491
653
  return out;
492
654
  }
493
-
494
- /**
495
- * 解析 show 键中的 somaId@attr 语法
496
- *
497
- * 遍历 ShowMapping 中的所有键,将 `somaId@attr` 拆分为 somaId + attrName。
498
- * 用于引擎在绑定时判断是设置 textContent 还是 setAttribute。
499
- *
500
- * @param show - 已解析的 ShowMapping
501
- * @returns ParsedShowEntry 数组
502
- */
503
- export function parseShowKeys(show: ShowMapping): ParsedShowEntry[] {
504
- const entries: ParsedShowEntry[] = [];
505
-
506
- for (const [key, value] of Object.entries(show)) {
507
- const { somaId, attrName } = parseSomaKey(key, key);
508
- const entry: ParsedShowEntry = { somaId, value };
509
- if (attrName) {
510
- entry.attrName = attrName;
511
- }
512
- entries.push(entry);
513
- }
514
-
515
- return entries;
516
- }
@@ -43,8 +43,9 @@ const AMBIENT_DURATION = '12s';
43
43
  /**
44
44
  * S5:不含颜色的场景结构参数。
45
45
  *
46
- * 玻璃三档的 rgba 从引擎主体迁到这里(值一个没改)——它们是材质的结构属性,
47
- * 与 field/material 轴同族,散在派生链中间只会让人以为它们是色板的一部分。
46
+ * 玻璃三档的 rgba 与它同族、住在下面的 `glassTokens`(值一个没改,引擎主体的亮/暗两处
47
+ * 都经它取值)——它们是材质的结构属性,与 field/material 轴同族,
48
+ * 散在派生链中间只会让人以为它们是色板的一部分。
48
49
  */
49
50
  export function sceneStructureTokens(axes: SomaResolvedAxes): Record<string, string> {
50
51
  const signal = axes.palette.semantics === 'immersive'
@@ -65,7 +66,12 @@ export function sceneStructureTokens(axes: SomaResolvedAxes): Record<string, str
65
66
  };
66
67
  }
67
68
 
68
- /** 暗色下的玻璃:半透明**黑**而不是白——白玻璃压在深底上会变成发光板 */
69
+ /**
70
+ * 玻璃三档(面 / 强面 / 弱面)。theme-engine 的亮、暗两套变量表都从这里取,值只此一份。
71
+ *
72
+ * 暗色下仍是白,但 alpha 只有 4%~10%(亮色 52%~88%)——高 alpha 的白玻璃压在深底上
73
+ * 会变成一块发光板,层级反而糊掉。
74
+ */
69
75
  export function glassTokens(dark: boolean): Record<string, string> {
70
76
  return dark
71
77
  ? {
@@ -6,9 +6,9 @@
6
6
  // 不会散进派生链的十几个算式里。
7
7
  //
8
8
  // 缺省列即现状:全部轴省略时解析出的参数,必须让派生结果与 REQ-007 之前
9
- // 字节级一致(theme-snapshot 闸门盯着这条)。其中 CONTRAST_TARGETS.standard
10
- // 的数值是**逆算**出来的——把现状 l=0.60/0.58/0.72 三个字面常量的实测对比度
11
- // 反填进表,这样"从目标对比度解出明度"与"直接写死明度"在缺省档殊途同归。
9
+ // 字节级一致(theme-snapshot 闸门盯着这条)。CONTRAST_TARGETS.standard 的
10
+ // toneOnPage 因此取在**全部语气种子的结构下界之下**——缺省档一个语气都不推,
11
+ // 这条线只在派生出病态低反差时才兜底。取值推导见该常量上方的复算链。
12
12
 
13
13
  // ─── 轴词元(封闭集,与《主题属性设计》§4 逐字一致) ─────────────────
14
14
 
@@ -75,7 +75,7 @@ export interface SomaAxisParams {
75
75
  readonly chromaMul: number;
76
76
  readonly targets: SomaContrastTargets;
77
77
  readonly darkTargets: SomaContrastTargets;
78
- /** contrast:soft 的粉彩明度带;null = 不约束(现状) */
78
+ /** contrast:soft 的粉彩明度带(**亮色侧专用**);null = 不约束 */
79
79
  readonly softLightnessBand: readonly [number, number] | null;
80
80
  /** 环境光三团的 alpha;null = flat(产 transparent) */
81
81
  readonly fieldAlphas: readonly [number, number, number] | null;
@@ -116,25 +116,83 @@ const CHROMA_MUL: Record<SomaChroma, number> = {
116
116
  /**
117
117
  * 目标对比度组(Leonardo 路线:明度是解出来的,不是写死的)。
118
118
  *
119
- * standard 一列**逆算自现状**:现状三个语义色常量 l=0.60/0.58/0.72 落在
120
- * `--soma-bg-page`(亮档 0.965)上的实测对比度约 4.0;fgOnTone 4.5 是既有
121
- * `enforceContrastPairs` 的硬保障值;textOnPage 4.5 是既有 ④.2 的保障值。
122
- * 三个数都不是新定的口径,是把现状口径写成了参数。
119
+ * ── 三个目标分属两层 ────────────────────────────────────────────────
120
+ * fgOnTone / textOnPage **硬保障**:AA 底线,用户关不掉
121
+ * (《soma 设计令牌与主题》§10.3 原则 4「硬保障不是输入」)。
122
+ * toneOnPage **气质目标**:语气实心底相对页面底有多沉。尽力而为,
123
+ * 被硬保障顶掉不报错;与粉彩带冲突时带让位(记 meta.bandBroken)。
124
+ *
125
+ * ── toneOnPage 三档怎么定的(下一个人照这条链复算) ──────────────────
126
+ *
127
+ * 1) 页面底的相对亮度(OKLab 对灰阶恒有 Y = L³):
128
+ * 亮档 `--soma-bg-page` = gray(0.965) → Y = 0.8986
129
+ * 暗档 `--soma-bg-page` = gray(0.18) → Y = 0.005832
130
+ * → 亮档 toneOnPage = 0.9486 / (Y_tone + 0.05)
131
+ * 暗档 toneOnPage = (Y_tone + 0.05) / 0.055832
132
+ * 彩色的 Y 由 OKLab 逆变换算:
133
+ * Y = -0.040794·l'³ + 1.112492·m'³ - 0.071718·s'³
134
+ * l' = L + 0.3963378a + 0.2158038b
135
+ * m' = L - 0.1055613a - 0.0638542b
136
+ * s' = L - 0.0894842a - 1.2914855b (a = c·cos h,b = c·sin h)
137
+ *
138
+ * 2) 求解器检查的是**种子**(banded / separatedL 之后、AA 之前),所以下界由
139
+ * 各语气的种子明度**上限**决定;明度越高(亮档)离页面底越近,对比度越低:
140
+ *
141
+ * 语气 亮档种子明度上限 该明度全色域最差 toneOnPage
142
+ * accent min(0.78, …) = 0.78 1.666 ← 亮档绑定项
143
+ * secondary min(0.72, …) = 0.72 2.08
144
+ * warning 0.72 2.27
145
+ * success 0.58(分离最多上推到 0.72) 2.15
146
+ * danger 0.60(分离最多上推到 0.74) 2.24
147
+ * info 0.60(固定) 3.48
148
+ *
149
+ * 暗档绑定项是 secondary:暗色种子 = min(0.78, 亮色成品 L + 0.08),
150
+ * 而亮色 secondary 的 L ≥ 0.45(0.45 处白字实测 7.5,AA 用不到推),
151
+ * 故暗档种子下限 0.53 → 该明度全色域最差 3.084。
152
+ * 暗色四个语义色常量(0.68/0.66/0.76/0.68)实测 6.2~8.8,不是绑定项。
153
+ *
154
+ * 3) 三档各取在谁之下:
155
+ * standard 1.6 / 3.0 取在**结构下界** 1.666 / 3.084 之下 ——
156
+ * 缺省档因此对任何品牌的正常派生都"一个语气都不推",
157
+ * 产出与接线前逐字节一致(theme-snapshot 闸门看守)。
158
+ * 它不是空转:分离闸把某个语气上推到 0.86 一带时
159
+ * (实测可掉到 1.27),这条线会把它压回可见范围。
160
+ * soft 1.2 / 2.8 亮档取在**粉彩带上界** L=0.86 处的最差值 1.271 之下,
161
+ * 带 [0.70, 0.86] 因此全区间达标、不会被目标顶穿。
162
+ * 柔光 = 语气浅、对页面底反差小,所以 soft 的目标**低于**
163
+ * standard,而不是高于——把它调高会让 soft 比 standard 还跳。
164
+ * 暗档不传带(见 softLightnessBand 的说明),2.8 是纯下界。
165
+ * strong 5.5 / 5.0 显式切换档,改变观感是预期内的。实算:fgOnTone 7.0 会把
166
+ * 走 AA 求解的五个语气推到 Y ≤ 0.10(toneOnPage 顺带 ≈6.3),
167
+ * 5.5 精确绑住**亮档唯一不过 AA 循环的 danger**(fg 恒白);
168
+ * 暗档 5.0 绑住**没有 AA 循环的 secondary/accent**
169
+ * (今天实测只有 3.1~3.8)。两个目标各管一半,覆盖完整。
170
+ *
171
+ * fgOnTone 4.5 是既有 `enforceContrastPairs` 的硬保障值;textOnPage 4.5 是既有 ④.2
172
+ * 的保障值;strong 的 7.0 是 AAA。这三个数不是新口径。
173
+ *
174
+ * 导出是为了让验收用例读真值而不是抄一份数字(与 SEPARATION_THRESHOLD 同一条纪律)。
123
175
  */
124
- const CONTRAST_TARGETS: Record<SomaContrast, SomaContrastTargets> = {
125
- soft: { toneOnPage: 3.2, fgOnTone: 4.5, textOnPage: 4.5 },
126
- standard: { toneOnPage: 4.0, fgOnTone: 4.5, textOnPage: 4.5 },
176
+ export const CONTRAST_TARGETS: Record<SomaContrast, SomaContrastTargets> = {
177
+ soft: { toneOnPage: 1.2, fgOnTone: 4.5, textOnPage: 4.5 },
178
+ standard: { toneOnPage: 1.6, fgOnTone: 4.5, textOnPage: 4.5 },
127
179
  strong: { toneOnPage: 5.5, fgOnTone: 7.0, textOnPage: 7.0 },
128
180
  };
129
181
 
130
- /** 暗色目标:底更深,语气底对底的对比要求相应放宽一档(与现状 ⑤ 的观感一致) */
131
- const DARK_CONTRAST_TARGETS: Record<SomaContrast, SomaContrastTargets> = {
132
- soft: { toneOnPage: 3.0, fgOnTone: 4.5, textOnPage: 4.5 },
133
- standard: { toneOnPage: 3.6, fgOnTone: 4.5, textOnPage: 4.5 },
182
+ /** 暗色目标:页面底 Y=0.005832,方向相反(语气越亮反差越大)。推导同上 */
183
+ export const DARK_CONTRAST_TARGETS: Record<SomaContrast, SomaContrastTargets> = {
184
+ soft: { toneOnPage: 2.8, fgOnTone: 4.5, textOnPage: 4.5 },
185
+ standard: { toneOnPage: 3.0, fgOnTone: 4.5, textOnPage: 4.5 },
134
186
  strong: { toneOnPage: 5.0, fgOnTone: 7.0, textOnPage: 7.0 },
135
187
  };
136
188
 
137
- /** contrast:soft 的粉彩明度带(对标原型八色的 L 0.66–0.88) */
189
+ /**
190
+ * contrast:soft 的粉彩明度带(对标原型八色的 L 0.66–0.88)。
191
+ *
192
+ * **只作用于亮色**:柔光 = 语气浅、对浅色页面底反差小。同一条带落到暗色语气
193
+ * (0.66~0.76)上会把它们推**亮**、反差反而更大,与这一档的语义相反——
194
+ * 所以暗色侧的求解恒传 null(见 theme-engine 的 S2 调用点)。
195
+ */
138
196
  const SOFT_LIGHTNESS_BAND: readonly [number, number] = [0.70, 0.86];
139
197
 
140
198
  /**