soma-core 1.4.2 → 1.5.1

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 (216) 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 +431 -26
  9. package/core/build/component/component-graph.ts +28 -105
  10. package/core/build/component/package-loader.ts +18 -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 +29 -10
  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/client/component/component-expander.ts +18 -3
  58. package/core/client/component/component-manager.ts +4 -0
  59. package/core/client/component/example-blocks.ts +1 -7
  60. package/core/client/component/theme-component-tokens.ts +12 -15
  61. package/core/client/component/verify-pack.ts +43 -0
  62. package/core/client/data/data-object-resolver.ts +27 -8
  63. package/core/client/diagnostics/telemetry-context.ts +0 -4
  64. package/core/client/engine/asset-resolver.ts +0 -1
  65. package/core/client/engine/event-engine.ts +7 -3
  66. package/core/client/engine/soma-bootstrap.ts +292 -34
  67. package/core/client/engine/style-binder.ts +0 -1
  68. package/core/client/infra/http/IHttpClient.ts +0 -6
  69. package/core/client/infra/http/SomaHttpService.ts +4 -1
  70. package/core/client/infra/notify/DomNotifyService.ts +1 -1
  71. package/core/client/infra/router/router-path.ts +0 -6
  72. package/core/client/parser/annotation-extractor.ts +1 -1
  73. package/core/client/parser/blocks/namespace.ts +30 -5
  74. package/core/client/parser/blocks/page-parser.ts +44 -1
  75. package/core/client/parser/blocks/use-parser.ts +266 -46
  76. package/core/client/parser/data-config-parser.ts +71 -3
  77. package/core/client/parser/layout-parser.ts +4 -3
  78. package/core/client/parser/reaction-parser.ts +0 -1
  79. package/core/client/parser/ui-config-parser.ts +212 -74
  80. package/core/client/theme/scene-tokens.ts +9 -3
  81. package/core/client/theme/theme-axes.ts +74 -16
  82. package/core/client/theme/theme-engine.ts +341 -70
  83. package/core/client/theme/tone-solver.ts +9 -8
  84. package/core/index.ts +24 -5
  85. package/core/server/api/load-host-service.ts +8 -2
  86. package/core/server/declaration-safety.ts +11 -0
  87. package/core/server/host/page-response-request.ts +0 -2
  88. package/core/server/host/published-page-artifact-cache.ts +244 -0
  89. package/core/server/host/published-page-assets.ts +44 -5
  90. package/core/server/mock/node/cli.mjs +0 -1
  91. package/core/server/mock/node/schema-generator.mjs +0 -1
  92. package/core/server/ooui.ts +34 -0
  93. package/core/server/page-assets.ts +8 -0
  94. package/core/server/page-declaration.ts +18 -0
  95. package/core/server/registry/asset-store.ts +327 -0
  96. package/core/server/registry/declaration-precompiler.ts +49 -6
  97. package/core/server/registry/index.ts +47 -1
  98. package/core/server/registry/page-registry-repository.ts +6 -2
  99. package/core/server/registry/page-registry-store.ts +133 -19
  100. package/core/server/registry/publish-asset-pin.ts +557 -0
  101. package/core/server/registry/services/pages/List.ts +15 -3
  102. package/core/server/registry/validation/compile-gate.ts +180 -8
  103. package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
  104. package/core/shared/component/derive-sample.ts +201 -16
  105. package/core/shared/component/field-lines.ts +98 -8
  106. package/core/shared/container-breakpoints.ts +46 -0
  107. package/core/shared/object-semantics.ts +240 -0
  108. package/core/shared/ooui-declaration.ts +235 -0
  109. package/core/shared/types/component-contract.types.ts +7 -6
  110. package/core/shared/types/data-config.types.ts +95 -0
  111. package/core/shared/types/domain.types.ts +0 -24
  112. package/core/shared/types/engine.types.ts +0 -5
  113. package/core/shared/types/layout-constraint.types.ts +16 -0
  114. package/core/shared/types/ui-config.types.ts +163 -13
  115. package/dist/cli/soma.js +24 -11
  116. package/dist/core/index.cjs +1829 -1028
  117. package/dist/types/build/blocks/block-compile.d.ts +16 -1
  118. package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
  119. package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
  120. package/dist/types/build/compiler/route-builder.d.ts +0 -1
  121. package/dist/types/build/component/component-graph.d.ts +17 -53
  122. package/dist/types/build/component/package-loader.d.ts +8 -1
  123. package/dist/types/build/layout/constraint-solver.d.ts +46 -4
  124. package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
  125. package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
  126. package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
  127. package/dist/types/build/ooui/artifact/index.d.ts +5 -0
  128. package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
  129. package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
  130. package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
  131. package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
  132. package/dist/types/build/ooui/composition/registry.d.ts +66 -0
  133. package/dist/types/build/ooui/composition/select.d.ts +63 -0
  134. package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
  135. package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
  136. package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
  137. package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
  138. package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
  139. package/dist/types/build/ooui/engine-slot.d.ts +41 -0
  140. package/dist/types/build/ooui/index.d.ts +286 -0
  141. package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
  142. package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
  143. package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
  144. package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
  145. package/dist/types/build/ooui/page/budget.d.ts +28 -0
  146. package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
  147. package/dist/types/build/ooui/page/index.d.ts +4 -0
  148. package/dist/types/build/ooui/page/page.types.d.ts +264 -0
  149. package/dist/types/build/ooui/page/region-row.d.ts +16 -0
  150. package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
  151. package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
  152. package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
  153. package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
  154. package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
  155. package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
  156. package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
  157. package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
  158. package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
  159. package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
  160. package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
  161. package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
  162. package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
  163. package/dist/types/build/ooui/trace/index.d.ts +3 -0
  164. package/dist/types/build/ooui/trace/render.d.ts +42 -0
  165. package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
  166. package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
  167. package/dist/types/client/component/component-expander.d.ts +1 -0
  168. package/dist/types/client/component/example-blocks.d.ts +0 -2
  169. package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
  170. package/dist/types/client/data/data-object-resolver.d.ts +10 -2
  171. package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
  172. package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
  173. package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
  174. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  175. package/dist/types/client/infra/router/router-path.d.ts +0 -2
  176. package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
  177. package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
  178. package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
  179. package/dist/types/client/parser/data-config-parser.d.ts +13 -0
  180. package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
  181. package/dist/types/client/theme/scene-tokens.d.ts +9 -3
  182. package/dist/types/client/theme/theme-axes.d.ts +64 -1
  183. package/dist/types/client/theme/theme-engine.d.ts +13 -8
  184. package/dist/types/client/theme/tone-solver.d.ts +9 -5
  185. package/dist/types/index.d.ts +4 -6
  186. package/dist/types/server/declaration-safety.d.ts +7 -0
  187. package/dist/types/server/host/page-response-request.d.ts +0 -1
  188. package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
  189. package/dist/types/server/ooui.d.ts +18 -0
  190. package/dist/types/server/page-assets.d.ts +7 -0
  191. package/dist/types/server/page-declaration.d.ts +14 -0
  192. package/dist/types/server/registry/asset-store.d.ts +112 -0
  193. package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
  194. package/dist/types/server/registry/index.d.ts +3 -1
  195. package/dist/types/server/registry/page-registry-store.d.ts +57 -4
  196. package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
  197. package/dist/types/server/registry/services/pages/List.d.ts +9 -3
  198. package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
  199. package/dist/types/shared/component/derive-sample.d.ts +14 -0
  200. package/dist/types/shared/container-breakpoints.d.ts +42 -0
  201. package/dist/types/shared/object-semantics.d.ts +42 -0
  202. package/dist/types/shared/ooui-declaration.d.ts +135 -0
  203. package/dist/types/shared/types/component-contract.types.d.ts +7 -6
  204. package/dist/types/shared/types/data-config.types.d.ts +86 -0
  205. package/dist/types/shared/types/domain.types.d.ts +0 -21
  206. package/dist/types/shared/types/engine.types.d.ts +0 -4
  207. package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
  208. package/dist/types/shared/types/ui-config.types.d.ts +157 -12
  209. package/next.config.js +106 -13
  210. package/package.json +29 -2
  211. package/core/client/host-bridge/index.ts +0 -27
  212. package/core/client/parser/yaml-loader.ts +0 -36
  213. package/core/shared/manifest/manifest-contract.ts +0 -12
  214. package/dist/types/client/host-bridge/index.d.ts +0 -9
  215. package/dist/types/client/parser/yaml-loader.d.ts +0 -21
  216. package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
@@ -6,8 +6,23 @@ export interface CompiledSomaBlocks {
6
6
  ui: UiConfig;
7
7
  /** 平铺等价事件声明(DOM 事件 + timers/triggers + 组件 emit 路由) */
8
8
  event: Record<string, unknown>;
9
- /** 数据对象声明(页面级 + 各块私有,已带全局身份) */
9
+ /**
10
+ * 数据对象声明——**核心层**,形状即数据对象层(`data-config-parser`)的输入:
11
+ * 页面级对象用声明名,各块私有对象用扁平名 `块id__名`。
12
+ */
10
13
  data: Record<string, unknown>;
14
+ /**
15
+ * 表层对象声明(REQ-014 §38.5 断线 ②):人写形态,**尚未展开**。
16
+ *
17
+ * 不在这里展开是有意的:展开点只准有一个
18
+ * (`build/ooui/semantic/normalize.ts`,§2.3 判据 3)。本模块住在
19
+ * `core/build/blocks/`,把展开器搬进来等于给它开第二个入口,
20
+ * 而两处对 `enum(a|b|c)` 的空格与转义处理必然分叉——表现是
21
+ * "同一份 YAML 在预览里三个候选、在发布产物里两个",两边各自都跑得出来。
22
+ *
23
+ * 展开与并入 `data` 由 `compilePageDeclaration` 做一次。没写就没有这个字段。
24
+ */
25
+ surface?: Record<string, unknown>;
11
26
  /** 各组件块的 AST(供生成器族与诊断消费) */
12
27
  blocks: ReadonlyMap<string, UseBlockAst>;
13
28
  htmlIndex: HtmlAnchorIndex;
@@ -5,6 +5,14 @@ export interface FlatPageFiles {
5
5
  styleYaml?: Record<string, unknown>;
6
6
  dataYaml?: Record<string, unknown>;
7
7
  }
8
+ /** 平铺侧车(`_ui.yaml` 之外的三件) */
9
+ export type FlatSidecar = 'eventYaml' | 'styleYaml' | 'dataYaml';
10
+ /**
11
+ * 一份侧车的去留:
12
+ * migrated —— 内容**完整**并进了块声明(或本来就没有内容),可以删;
13
+ * manual —— 有迁移器没迁的内容(明细在 report.manual),**不许删**。
14
+ */
15
+ export type SidecarDisposition = 'migrated' | 'manual';
8
16
  export interface MigrationReport {
9
17
  /** 逐条变换记录(可读,用于 review 迁移结果) */
10
18
  changes: string[];
@@ -17,6 +25,15 @@ export interface MigrationResult {
17
25
  /** 结构形态(便于测试与等价比对) */
18
26
  blocks: Record<string, unknown>;
19
27
  report: MigrationReport;
28
+ /**
29
+ * 每份给了的侧车的去留(没给的不出现)。`soma migrate --write` 只删 migrated 的,
30
+ * 有 manual 的页整页不写盘。
31
+ *
32
+ * 这张表存在的理由:曾经 `--write` 不分青红皂白删 `_style.yaml`——而迁移器
33
+ * 从来不迁它的 base / states / transitions,那些内容只在人工清单里提了一句,
34
+ * 文件就没了。「迁没迁完」只有迁移器自己知道,所以由它给出,调用方不猜。
35
+ */
36
+ sidecars: Partial<Record<FlatSidecar, SidecarDisposition>>;
20
37
  }
21
38
  /** 把一页平铺声明迁移为块结构 */
22
39
  export declare function migrateFlatToBlocks(files: FlatPageFiles): MigrationResult;
@@ -4,6 +4,7 @@ import type { PropertyTrigger } from '../../shared/types/trigger.types';
4
4
  import type { StyleConfig } from '../../shared/types/style-config.types';
5
5
  import type { ParsedTimer } from '../../shared/types/timer.types';
6
6
  import type { UiConfig } from '../../shared/types/ui-config.types';
7
+ import { type SomaEnvironment, type SomaOouiEngine, type SomaTrace } from '../ooui';
7
8
  export interface SomaPageDeclarationInput {
8
9
  html: string;
9
10
  uiYaml: string;
@@ -13,6 +14,24 @@ export interface SomaPageDeclarationInput {
13
14
  externalBlocks?: ReadonlyMap<string, string>;
14
15
  /** 与浏览器运行时一致的共享 HTML 片段;仅在构建锚点校验前展开。 */
15
16
  includes?: Readonly<Record<string, string>>;
17
+ /**
18
+ * OOUI 演绎引擎(REQ-014)。由**宿主**装配。
19
+ *
20
+ * 它不能由本模块自己造:候选表与空间词汇住在组件库(soma-ui / 业务包),
21
+ * 而 core 不许 import 它们(`verify-ooui-dep-graph` 的 `CORE-IMPORTS-UI`)。
22
+ *
23
+ * 缺省不传时回落到**进程级槽位**(`../ooui/engine-slot`)——本函数在生产上有八个
24
+ * 调用点分属五个进程,其中六个住在 core 里面,没有任何办法自己拿到 soma-ui 的词汇。
25
+ * 要求每一层调用方都开一个 `ooui` 口子一路透传,代价是"任何一层忘了透传都不报错",
26
+ * 而"这条路没透传"与"这页没写 ooui"在错误消息里长得一模一样。
27
+ * 显式传参优先于槽位,供单测与"同进程要用两份不同词表"的场景使用。
28
+ *
29
+ * 两处都取不到 = 本次编译不具备演绎能力;页面若声明了 `ooui:` 段,**当场拒收**,
30
+ * 不静默跳过——静默跳过的表现是"发布成功但那一块永远是空的"。
31
+ */
32
+ ooui?: SomaOouiEngine;
33
+ /** 演绎环境(可用宽度档、已装配组件清单)。缺省 = 不限宽、不筛候选 */
34
+ oouiEnv?: SomaEnvironment;
16
35
  }
17
36
  export interface SomaRuntimeDeclarationAssets {
18
37
  uiYaml: string;
@@ -29,6 +48,33 @@ export interface CompiledPageDeclaration {
29
48
  dataConfig?: SomaDataConfig;
30
49
  /** `layout:` 段的构建期产物:只含容器查询 + flex(CL-2);没声明就没有 */
31
50
  layoutCss?: string;
51
+ /** `ooui:` 段的构建期演绎产物(REQ-014);没声明就没有 */
52
+ oouiArtifact?: UiConfig['oouiArtifact'];
53
+ /**
54
+ * `objects:` 段的**来历台账**(REQ-014 §38.5 断线 ②):哪些值是作者写的、
55
+ * 哪些是系统按默认补的、哪些是按规则猜的。没写 `objects:` 就没有。
56
+ *
57
+ * **编译期诊断,不进 `runtimeAssets`。** 进产物的话每次取页都要多传一份
58
+ * 只有人会读的东西,而它对渲染没有任何影响;更要紧的是它会让内容寻址把
59
+ * "报告措辞改了一个字"当成一次产物变更。
60
+ *
61
+ * 消费方是发布闸门与 soma-ai 的自修复回路:有了它,
62
+ * `OOUI-SEM-EDIT-ALL-READONLY` 才能从"你写错了"升级成
63
+ * "**我按默认补的** permission: r,你需要显式写 w"——同一条错误,
64
+ * 两种修法,指向两个人(§34.2)。
65
+ */
66
+ oouiOrigins?: readonly SomaTrace[];
67
+ /**
68
+ * `ooui:` 段**页面这一层**的推导链(REQ-014 §5):空间预算的决策(每个区域按什么约束分宽、
69
+ * sizing / gap / wrap 取了缺省、预算 CSS 落在哪个区域行上或为什么没发)与演绎之后那一遍联动裁决(每条 `bound_to` 依据哪个动词、
70
+ * 哪种控制模型成立,带不带 caveat)。没写 `ooui:` 就没有。
71
+ *
72
+ * 与 `oouiOrigins` 同一条纪律:**编译期诊断,不进 `runtimeAssets`**,产物一个字节都不变。
73
+ * 此前这两项推导算完就被丢掉,报告说得出"这个组件为什么被选中",
74
+ * 说不出"这个区域为什么只分到这么宽"、"这条联动凭什么成立"——
75
+ * 而 §5 的原话是"没有 trace 的推导不允许进主路径"。
76
+ */
77
+ oouiPageTraces?: readonly SomaTrace[];
32
78
  runtimeAssets: SomaRuntimeDeclarationAssets;
33
79
  }
34
80
  /** 编译一整页 SOMA DSL 声明。旧页面形状与页面侧车在唯一入口直接拒绝。 */
@@ -8,4 +8,3 @@ export interface SomaRouteEntry {
8
8
  * shared/ 和 system/ 目录下的文件被排除(非页面文件)。
9
9
  */
10
10
  export declare function buildRouteTable(htmlFiles: string[]): SomaRouteEntry[];
11
- export declare function precompileRouteTable(htmlFiles: string[]): string;
@@ -18,65 +18,29 @@ export interface ComponentGraph {
18
18
  /**
19
19
  * 建图。
20
20
  *
21
- * 缺失依赖与环**不抛**,而是收进产物:这个函数同时服务于闸门与 CLI,
22
- * 闸门要拿到全部问题一次报完(抛的话作者修一条跑一次,修十条跑十次),
23
- * CLI 则要在有问题时也能给出一份"能拉的先拉上"的清单。判定归调用方。
21
+ * 缺失依赖与环**不抛**,而是收进产物:闸门要拿到全部问题一次报完
22
+ * (抛的话作者修一条跑一次,修十条跑十次)。判定归调用方。
24
23
  */
25
24
  export declare function buildComponentGraph(definitions: Record<string, SomaComponentDefinition>): ComponentGraph;
26
25
  /**
27
- * 按图拉齐:给一组组件名,返回它们加上全部传递依赖的名单(拓扑序)。
26
+ * 契约 `uses` 与 CSS 依赖表的对账。**两个方向的含义不同,判据不对称。**
28
27
  *
29
- * 拓扑序而不是字母序:注册组件时被依赖的要先在册,否则合成期查注册表会落空。
30
- */
31
- export declare function resolveWithDependencies(graph: ComponentGraph, wanted: readonly string[]): string[];
32
- /** `registry.json` 的一项 */
33
- export interface ComponentRegistryEntry {
34
- name: string;
35
- layer: string;
36
- /** 契约版本(破坏性变更升 major) */
37
- version: string;
38
- /** 源码内容哈希:回答"我这份是不是官方那一份" */
39
- sha256: string;
40
- /** 直接依赖 */
41
- uses: string[];
42
- /** 传递依赖(拉齐时按它一次拉全) */
43
- requires: string[];
44
- /** 源文件相对路径(eject / upgrade 的取源位置) */
45
- source: string;
46
- description: string;
47
- }
48
- export interface ComponentRegistryManifest {
49
- /** 目录格式版本:读的人据此判断自己认不认得这份文件 */
50
- schema: 1;
51
- /** 产出这份目录的包与版本 */
52
- pack: {
53
- name: string;
54
- version: string;
55
- };
56
- generatedFrom: string;
57
- components: ComponentRegistryEntry[];
58
- }
59
- /**
60
- * 产出可寻址目录。
28
+ * 头一版这里写的是"两张表必须一致",接线实测之后发现那个前提是错的
29
+ * (11 条不一致里 10 条属于合法的那个方向):
61
30
  *
62
- * 与 shadcn registry 的差别就是这三列:`version` / `sha256` / `requires`。
63
- * 少了它们,一份被复制出去的组件就永久脱离了升级链路——
64
- * 而"脱离了"这件事本身也是看不出来的。
65
- */
66
- export declare function buildRegistryManifest(definitions: Record<string, SomaComponentDefinition>, options: {
67
- packName: string;
68
- packVersion: string;
69
- /** 组件名 → 源码相对路径 */
70
- sourceOf(name: string): string;
71
- /** 组件名 → 源码内容哈希 */
72
- hashOf(name: string): string;
73
- }): ComponentRegistryManifest;
74
- /**
75
- * 契约 `uses` 与 CSS 依赖表的对账。
31
+ * · **`onlyInCss`(CSS 表有、契约没有)= 缺陷。**
32
+ * 借样式而不建实例的组件(如 `HelpConsole` 内联写 `class="soma-accordion"`)
33
+ * 必须在契约 `uses` 里登记那个被借的组件,否则 `soma component eject`
34
+ * 少拉一个源文件,副本里那一块**没有样式**——渲染正常、控制台一行都没有。
35
+ * `COMPONENT_CSS_DEPS` 少写一条 `TreeSelect: ['Tree']` 那次就是这条。
36
+ *
37
+ * · **`onlyInContract`(契约有、CSS 表没有)= 正常,不是缺陷。**
38
+ * 父组件在模板里嵌了子组件的**真实例**时,子实例挂载时自己注样式,
39
+ * 父不需要 CSS 依赖。反而登记了会让子组件的样式在它没被渲染时也被注入。
76
40
  *
77
- * 两张表都在描述"这个组件还需要谁",所以它们必须一致。不对账的话,
78
- * 一条只写在 CSS 表里的依赖会让 eject 少拉一个文件,而一条只写在契约里的依赖
79
- * 会让页面少注一段样式——两种坏法都不报错,都只是长得不对。
41
+ * 所以本函数**两个方向都报**(它是报告器,不是裁决者),
42
+ * 由调用方按上面的语义决定哪一侧是硬红。判据在
43
+ * `soma-ui/tests/component-css-deps.test.ts`。
80
44
  */
81
45
  export declare function reconcileCssDeps(graph: ComponentGraph, cssDeps: Record<string, readonly string[]>): Array<{
82
46
  component: string;
@@ -1,7 +1,14 @@
1
1
  import type { SomaComponentDefinition } from '../../client/component/component-definition.types';
2
2
  export declare class SomaComponentPackageError extends Error {
3
3
  readonly packageDir: string;
4
- constructor(message: string, packageDir: string);
4
+ /**
5
+ * `options.cause`:包一层解析器原错误时带上它。消息里只留得下原错误的 message,
6
+ * 带 `line` / `blockId` / `path` 的结构化错误(SomaFieldLinesError、SomaDataConfigError…)
7
+ * 与原始栈只有经 `cause` 才传得到调用方——不带就在这一层蒸发。
8
+ */
9
+ constructor(message: string, packageDir: string, options?: {
10
+ cause?: unknown;
11
+ });
5
12
  }
6
13
  /** 扫描期的软问题:不阻断装载,但必须让人看见(都是"不报错但坏掉"的前兆) */
7
14
  export interface PackScanWarning {
@@ -1,6 +1,13 @@
1
1
  import { type SomaLayoutConstraint, type SomaLayoutPlan, type SomaLayoutSolution } from '../../shared/types/layout-constraint.types';
2
- /** 容器断点八档(rem)。与 soma-ui 的 `responsive-constants` 同源同值 */
3
- export declare const CONTAINER_STEPS: ReadonlyArray<readonly [string, number]>;
2
+ /**
3
+ * 容器断点八档(rem)。**真源在 `core/shared/container-breakpoints.ts`**——
4
+ * 此处只重导出,保住既有 import 路径不变。
5
+ *
6
+ * 此前这里是一份字面量,与 soma-ui 的 `responsive-constants` 靠注释
7
+ * "同源同值"手工对齐(还有第三份在视觉矩阵脚本里)。三份都对不上时零报错,
8
+ * 表现是求解出的 CSS 与组件 CSS 在不同宽度上折断。
9
+ */
10
+ export { CONTAINER_STEPS } from '../../shared/container-breakpoints';
4
11
  export declare class SomaLayoutConstraintError extends Error {
5
12
  /** 打架的两条声明(CL-1 要求错误信息含冲突约束对) */
6
13
  readonly conflict: readonly [string, string];
@@ -14,8 +21,39 @@ export declare class SomaLayoutConstraintError extends Error {
14
21
  * 留着符号的话,「min 有没有被违反」就成了一个运行期才知道答案的问题。
15
22
  */
16
23
  export declare function toRem(literal: string, containerRem: number, where: string): number;
17
- /** 声明校验(CL-3):优先级四档、min ≤ max、fixed 必须给 width */
24
+ /**
25
+ * 声明校验(CL-3):优先级四档、min ≤ max、fixed 必须给 width。
26
+ *
27
+ * OOUI 空间层逐字复用本函数。富余分配的退化配置(`validateFillSurplus`)**不在这里**——
28
+ * 那条只挂在手写 `layout:` 的入口上,原因见它的注释。
29
+ */
18
30
  export declare function validateConstraint(constraint: SomaLayoutConstraint, path: string): void;
31
+ /**
32
+ * 富余分配的退化配置:一个 fill 项在每一档都分不到宽度。手写 `layout:` 的入口(`solveLayout`)调用。
33
+ *
34
+ * 成因在 `solveStep` 的步 1 与步 3:fill 从 min 起步(没写就是 0);富余按优先级从低到高分给
35
+ * fill 项、每项受自己的 max 限制。没写 max 的 fill 项余量是 ∞,它所在的那一档优先级就把富余
36
+ * **全部**拿走(余量为 ∞ 时分出去的就是全部剩余),更高优先级的 fill 项一点也分不到。
37
+ *
38
+ * 判定:同一组里,存在 fill 项 A 满足 max 缺省(= ∞),同时存在另一个 fill 项 B 满足
39
+ * `B.priority > A.priority`(没写按 500)且 B 没写 min(或 min 为 0)。此时 B 在每一个
40
+ * 不换行的档上都停在 0rem;产物里它是 `flex: 1 1 0rem`,容器宽恰好落在某一档上时没有宽度,
41
+ * 落在两档之间时又和 A 平分那段档间余量(两者 flex-grow 都是 1),看上去时有时无。
42
+ * 这种配置没有一种说得通的读法。
43
+ *
44
+ * 点名的 A 取「max 缺省的 fill 项里优先级最低的那个」(拿走富余的正是它所在的那一档;
45
+ * 同优先级取书写序第一个),B 取书写序里第一个符合条件的。min 写法非法时不算 0——
46
+ * 让 `toRem` 在求解时报它自己那条更准的错,这里不抢。
47
+ *
48
+ * **为什么不放进 `validateConstraint`**:OOUI 空间层(`build/ooui/spatial/solve.ts`)逐字复用
49
+ * `validateConstraint`,而页面区域预算(`build/ooui/page/budget.ts`)会给没写 layout 的区域
50
+ * 补缺省 `{ sizing: 'fill' }`——正好是一个 max = ∞、priority 500 的 A。作者只给另一个区域写
51
+ * `layout: { priority: 750 }` 就凑成这一对;这里的错误翻译到空间层是 `OOUI-SPA-UNSATISFIABLE`,
52
+ * 修法里「给低优先级项写 max」指向的是一个作者根本没写过 layout 的区域。
53
+ * 所以那一侧另拦:页面预算(`build/ooui/page/budget.ts` 的 `assertNoStarvedRegion`)调用本函数取
54
+ * 冲突对,再翻译成它自己的 `OOUI-SPA-BUDGET-STARVED`,修法只指向作者写过 layout 的区域——判据仍只有这一份。
55
+ */
56
+ export declare function validateFillSurplus(constraint: SomaLayoutConstraint, path: string): void;
19
57
  /**
20
58
  * 单档求解。
21
59
  *
@@ -32,5 +70,9 @@ export declare function validateConstraint(constraint: SomaLayoutConstraint, pat
32
70
  * Compression Resistance)说的就是同一个数的两面。
33
71
  */
34
72
  export declare function solveStep(constraint: SomaLayoutConstraint, containerRem: number, breakpoint: string, path: string): SomaLayoutSolution;
35
- /** 八档各解一次(CL-1) */
73
+ /**
74
+ * 八档各解一次(CL-1)。这是手写 `layout:` 段的求解入口(`page-layout.ts` 调用):
75
+ * 声明校验之外再核一条富余分配的退化配置(`validateFillSurplus`)。
76
+ * OOUI 空间层不经这里(它直接用 `validateConstraint` + `solveStep`)。
77
+ */
36
78
  export declare function solveLayout(constraint: SomaLayoutConstraint, path: string): SomaLayoutPlan;
@@ -0,0 +1,180 @@
1
+ import type { SomaOouiIssue } from '../diagnostics';
2
+ import { SomaOouiError } from '../diagnostics';
3
+ import type { SomaSource } from '../trace/source.types';
4
+ import type { SomaTrace } from '../trace/trace.types';
5
+ import type { SomaSpatialDecision, SomaSpatialNode, SomaSpatialPlan } from '../spatial/ir.types';
6
+ import type { SomaUtilityStylesheet } from '../spatial/utility.types';
7
+ import type { SomaOouiNode } from '../../../shared/types/ui-config.types';
8
+ export type { SomaSpatialNode, SomaSpatialPlan, SomaUtilityStylesheet, SomaOouiNode, SomaSource, SomaTrace };
9
+ /**
10
+ * 本层的一条推导记录。**这不是新形状,是 `SomaSpatialDecision` 的别名。**
11
+ *
12
+ * 两层的"决策记录"字段逐字相同(path / conclusion / rule / origin / src)。
13
+ * 复写一份的代价见 `../trace/source.types.ts` 头注释:TypeScript 是结构类型的,
14
+ * 两份一样时互相可赋值,**没有任何东西会红**,直到有人给其中一份加了字段,
15
+ * 另一份的构造点仍然编译通过,而错误消息里那一段在一半路径上默默消失。
16
+ * trace 层落地后**两个别名仍然保留**:决策记录是结构化消费面,`SomaTrace` 是读出形态,
17
+ * 两者由 `decisionTrace(decision, layer, parent)` 唯一连接(见 `../spatial/ir.types.ts`)。
18
+ */
19
+ export type SomaArtifactDecision = SomaSpatialDecision;
20
+ /**
21
+ * 事件路由的落点(架构 §16.3 + §24.1)。
22
+ *
23
+ * 组件 emit 名是组件库的私事,语义事件名是体系的公事;翻译表(`eventMap`)由**构件层**
24
+ * 提供,已经挂在 `SomaOouiNode.events` 上。本层只负责把它落成**数据**:
25
+ * 落成数据而不是属性,是 §24.1 那句"引擎不产生任何内联事件处理器"的可执行形态。
26
+ *
27
+ * `selector` 与 `node` 两个都留:前者给运行时接线,后者给诊断回答"这条路由是哪个节点产的"。
28
+ * 只留 selector 的话,一旦选择器策略变了(锚点改名、宿主前缀),
29
+ * 已发布产物里的路由就再也追不回源节点。
30
+ */
31
+ export interface SomaEventConfig {
32
+ /** 产生这条路由的构件节点路径,如 `detail` / `detail.amount` */
33
+ readonly node: string;
34
+ /** 事件源元素的 CSS 选择器 */
35
+ readonly selector: string;
36
+ /** 事件源元素的锚点 id(`data-soma-id`) */
37
+ readonly anchor: string;
38
+ /** 组件契约名 */
39
+ readonly component: string;
40
+ /** 组件 emit 名(组件库的词汇) */
41
+ readonly emit: string;
42
+ /** 语义事件名(体系的词汇),一个 emit 可承担多个 */
43
+ readonly kinds: readonly string[];
44
+ }
45
+ /**
46
+ * 一个字段的绑定描述。
47
+ *
48
+ * **它不是 props**。产物层拿不到组件契约(契约住在构件层的候选表里,回看两层是
49
+ * `SKIP-BACK`),因此这里**绝不编造 prop 名**——写一个 `data_object: order` 出去,
50
+ * 组件契约里若叫 `object` 或 `rows`,表现是"组件渲染出来了但永远是空的",
51
+ * 而空数据与"接口还没回来"长得一模一样。
52
+ * 这里只给**事实**:哪个字段、取值路径、演绎出的呈现形态与承载组件。
53
+ * 把它翻成某个组件的 props 是宿主/运行时的活,那一侧看得见契约。
54
+ */
55
+ export interface SomaFieldBinding {
56
+ /** 字段键(对象 `fields` 的键) */
57
+ readonly field: string;
58
+ /** 运行时取值路径,`<scope>.<field>` */
59
+ readonly path: string;
60
+ /** 演绎出的交互形态 */
61
+ readonly form: string;
62
+ /** `display` 形态的呈现细分 */
63
+ readonly variant?: string;
64
+ /** 承载这个字段的组件契约名;`#text` 表示纯文本节点 */
65
+ readonly component: string;
66
+ /** 组件所在层 */
67
+ readonly layer: string;
68
+ /** 业务显示名。**缺省回退字段键**,不编造(§24.2:引擎不产生任何面向用户的文案) */
69
+ readonly label: string;
70
+ /** 命中的规则名——"为什么是这个形态" */
71
+ readonly rule: string;
72
+ }
73
+ /**
74
+ * 数据绑定(架构 §3.5 的 `SomaBindingConfig`)。
75
+ *
76
+ * `scope` 是运行时作用域别名(`_ui.yaml` 里 `bind: { var: page }` 的那个 `var`)。
77
+ * 它**由调用方给**,缺省取对象名:产物层猜一个别名出来的话,猜错的表现是
78
+ * "绑定路径指向一个不存在的作用域",而运行时对取不到的路径的处理是渲染空串。
79
+ */
80
+ export interface SomaBindingConfig {
81
+ /** 数据对象名(页面 `data:` 段的键) */
82
+ readonly object: string;
83
+ /** 运行时作用域别名 */
84
+ readonly scope: string;
85
+ /** 根组件实例的锚点 id;根是纯文本节点时同样有 */
86
+ readonly rootAnchor: string;
87
+ /** 根组件契约名 */
88
+ readonly rootComponent: string;
89
+ /** 根组件的控制模型:`autonomous` 自己取数,`controlled` 靠喂 */
90
+ readonly controlModel: string;
91
+ /** 逐字段的绑定描述,按字段键在意图树中的顺序 */
92
+ readonly fields: readonly SomaFieldBinding[];
93
+ }
94
+ /**
95
+ * 可执行资产(架构 §3.5)。**纯数据**:无函数、无 Map/Set、无循环引用,可 `yaml.dump`。
96
+ *
97
+ * `selectorProvenance` 是本层的**核心字段**,不是附赠的调试信息:
98
+ * 它既是"编译器确切知道自己产出了什么"的那份清单(零扫描收集),
99
+ * 也是 class 存在性闸门的数据基础——产物里每个 class 都必须在它里面。
100
+ */
101
+ export interface SomaArtifact {
102
+ /** DOM 结构。**不含任何内联事件处理器**(§24.1) */
103
+ readonly html: string;
104
+ /** 全部样式:布局解的容器查询 + 原子类规则。两段以空行分隔,不含尾换行 */
105
+ readonly css: string;
106
+ readonly bindings: SomaBindingConfig;
107
+ readonly events: readonly SomaEventConfig[];
108
+ /**
109
+ * **每个选择器 → 产生它的节点路径**(架构 §3.5)。
110
+ *
111
+ * 键含两类:原子类选择器(`.soma-pad-5`)与元素选择器
112
+ * (`[data-soma-node="…"]` / `[data-soma-id="…"]`)。
113
+ * 值是构件树里的节点路径,回答"这条选择器是谁产的"。
114
+ */
115
+ readonly selectorProvenance: Readonly<Record<string, string>>;
116
+ /** 产出的原子类候选串,升序去重。喂给空间层的 `emitUtilityStylesheet` 的就是它 */
117
+ readonly classes: readonly string[];
118
+ /** 本层做了什么决定 */
119
+ readonly decisions: readonly SomaArtifactDecision[];
120
+ /**
121
+ * 本次演绎的完整推导链(架构 §5)。**上游各层的记录 + 本层的记录**,
122
+ * 每一条的 `parent` 一路上溯到语义层的那句对象声明。
123
+ *
124
+ * 为什么不是"只放本层的":§5 的硬要求是"能从一个 CSS 规则一路回溯到某句对象声明",
125
+ * 而字段级的构件选择(`detail.amount` 选中 PriceText)在本层的链条上够不着——
126
+ * 它挂在字段的意图 trace 下,不在区域根这一条上。只放本层的话,
127
+ * 报告能解释"这个区域"却解释不了"这个字段",而缺的那半在产物里看不出来。
128
+ *
129
+ * 必须**原样可 `JSON.stringify`**:`compile-gate.ts` 会做一次 JSON 往返,
130
+ * 带函数或循环引用时它会静默丢掉整条链。`SomaTrace` 是纯数据,
131
+ * `parent` 构成链不构成环(`traceDefects` 查这件事)。
132
+ */
133
+ readonly trace: readonly SomaTrace[];
134
+ /** 规模数字:成功输出要带上,防"产出了一份空 HTML 也叫绿" */
135
+ readonly stats: {
136
+ readonly elements: number;
137
+ readonly classes: number;
138
+ readonly selectors: number;
139
+ readonly fields: number;
140
+ readonly events: number;
141
+ };
142
+ }
143
+ /**
144
+ * 产物层错误。**已收敛为横切层 `SomaOouiError` 的窄化子类**(架构 §20.1),
145
+ * 照 `SomaSpatialError` 的先例:只收窄 `layer`、只改 `name`,不复写 message 拼装。
146
+ *
147
+ * `code` 是公开契约(§20.2),全量登记在 `../diagnostics/codes.ts`;
148
+ * 未登记的码由 `tests/unit/ooui/diagnostics/error-codes.test.ts` 的闸门拒收,不会静默通过。
149
+ */
150
+ export declare class SomaArtifactError extends SomaOouiError {
151
+ readonly layer: 'artifact';
152
+ constructor(input: {
153
+ code: string;
154
+ situation: string;
155
+ problem: string;
156
+ remedy: string;
157
+ src?: SomaSource;
158
+ issues?: readonly SomaOouiIssue[];
159
+ });
160
+ }
161
+ /**
162
+ * 一条选择器 → 产生它的那条推导链(没有则 `undefined`)。
163
+ *
164
+ * 走的是 `selectorProvenance`(零扫描收集的那份"我产出了什么"清单):
165
+ * 选择器 → 节点路径 → 该路径上的 trace。**不做前缀猜测**——
166
+ * 猜出来的那条链会指向一个近似的节点,而近似的因果比没有因果更坏:
167
+ * 它看起来像答案,读者会照着它去改一句不相干的声明。
168
+ *
169
+ * 同一路径上通常有好几条(每层各留了一条):**取层级最深的那一条,同层取最早的**。
170
+ * 为什么不是"取最后一条":最后一条是**追加顺序**上的最后,而追加顺序取决于
171
+ * 本层今天恰好按什么次序记决策——上游多记一条无关决策,这个函数的答案就换了人,
172
+ * 而换了的那次没有任何断言会红。层级 + 层首是**因果**上的定义,不随书写顺序变。
173
+ */
174
+ export declare function traceForSelector(artifact: SomaArtifact, selector: string): SomaTrace | undefined;
175
+ /**
176
+ * 一条选择器的推导链,**根在前**(语义层在第 0 位)。回溯不到时返回空数组。
177
+ *
178
+ * 闸门与测试用它断言"链条上溯到了语义层";给人读的报告用 `renderTrace`。
179
+ */
180
+ export declare function traceChainForSelector(artifact: SomaArtifact, selector: string): SomaTrace[];
@@ -0,0 +1,58 @@
1
+ import type { SomaOouiNode } from '../../../shared/types/ui-config.types';
2
+ import type { SomaSpatialPlan } from '../spatial/ir.types';
3
+ import type { SomaTrace } from '../trace/trace.types';
4
+ import type { SomaUtilityStylesheet } from '../spatial/utility.types';
5
+ import { type SomaArtifact } from './artifact.types';
6
+ import type { SpatialTreeResult } from './spatial-tree';
7
+ export interface EmitArtifactInput {
8
+ /** 构件层产物:界面节点树的根 */
9
+ readonly node: SomaOouiNode;
10
+ /** 区域路径(= 页面 `ooui:` 段的锚点名) */
11
+ readonly region: string;
12
+ /** 数据对象名(页面 `data:` 段的键) */
13
+ readonly object: string;
14
+ /**
15
+ * 运行时作用域别名(`_ui.yaml` 里 `bind: { var: … }` 的那个)。
16
+ * 缺省取对象名——**猜一个出来的话**,猜错的表现是绑定路径指向不存在的作用域,
17
+ * 而运行时对取不到的路径的处理是渲染空串。
18
+ */
19
+ readonly scope?: string;
20
+ /**
21
+ * 字段键 → 业务显示名。由**编排层**从对象字典(`SomaField.name`)带下来。
22
+ *
23
+ * 为什么不是本层自己去取:对象声明住在语义层,回看四层是 `SKIP-BACK`;
24
+ * 而构件层的产物 `SomaOouiNode` 上**没有显示名字段**(见本批 findings)。
25
+ * 缺省回退字段键,不编造文案(§24.2:引擎自己不产生任何面向用户的文案)。
26
+ */
27
+ readonly labels?: Readonly<Record<string, string>>;
28
+ /** `spatialTreeFromNode()` 的产物 */
29
+ readonly tree: SpatialTreeResult;
30
+ /** `solveSpatial()` 的产物,由编排层算好交进来 */
31
+ readonly plan: SomaSpatialPlan;
32
+ /** `emitUtilityStylesheet()` 的产物,由编排层算好交进来 */
33
+ readonly stylesheet: SomaUtilityStylesheet;
34
+ /**
35
+ * 上游各层(语义 / 意图 / 构件 / 空间)已经产出的 trace,**原样并进产物**。
36
+ *
37
+ * 本层**不替上游转**:空间层的决策记录由空间层自己的 `spatialTraces()` 转,
38
+ * 这里再转一份的话,两份会在某次改动后漂开,而它们同时躺在同一个 `trace` 数组里,
39
+ * 读者不知道该信哪一份——比少一份更坏。
40
+ */
41
+ readonly trace?: readonly SomaTrace[];
42
+ /**
43
+ * 上游链尾(通常是空间层的层首 trace)。本层每一条 trace 的 `parent` 挂在它下面。
44
+ *
45
+ * 与 `trace` 分成两个字段而不是"取数组最后一条":数组是**并进产物**的全部记录,
46
+ * 它的最后一条是谁取决于上游的书写顺序;而 parent 是**因果**上的上一跳。
47
+ * 用书写顺序去代替因果,链条在上游多记一条无关决策的那天就会静默接错。
48
+ */
49
+ readonly parent?: SomaTrace;
50
+ }
51
+ /**
52
+ * 组装产物。
53
+ *
54
+ * 三段固定顺序:发射 DOM → 收绑定与事件 → 过闸门。
55
+ * 闸门放在最后而不是散在中间,是为了让"产出了什么"与"产出的合不合法"
56
+ * 是两件可以分别看的事——闸门自己也因此可以被单独调用(`verifyArtifactHtml`)。
57
+ */
58
+ export declare function emitArtifact(input: EmitArtifactInput): SomaArtifact;
@@ -0,0 +1,53 @@
1
+ /** 属性值转义。**每一个进 HTML 的动态值都要过它**,没有例外 */
2
+ export declare function escapeAttribute(value: string): string;
3
+ /** 文本内容转义。引号在文本位置无害,但一起转不会错,少一套判据 */
4
+ export declare function escapeText(value: string): string;
5
+ export interface EmitHtmlInput {
6
+ /** 区域路径(= 页面 `ooui:` 段的锚点名),`selectorProvenance` 的值就是它 */
7
+ readonly region: string;
8
+ /** 区域外壳的节点 id */
9
+ readonly shellId: string;
10
+ /** 根构件实例的锚点 id */
11
+ readonly rootAnchor: string;
12
+ /** 外壳挂的原子类候选串 */
13
+ readonly shellClasses: readonly string[];
14
+ /** 根构件契约名;`#text` 表示纯文本节点 */
15
+ readonly rootComponent: string;
16
+ }
17
+ export interface EmitHtmlResult {
18
+ readonly html: string;
19
+ /** 选择器 → 产生它的节点路径。类选择器与元素选择器都在里面 */
20
+ readonly selectorProvenance: Record<string, string>;
21
+ /** 产出的原子类候选串,升序去重 */
22
+ readonly classes: string[];
23
+ /** 元素个数。规模数字,防"产出了一份空 HTML 也叫绿" */
24
+ readonly elements: number;
25
+ }
26
+ /**
27
+ * 发射一个区域的 DOM。
28
+ *
29
+ * 缩进固定两格、属性顺序固定、类名按书写序原样输出:
30
+ * 同一份输入必然产出同一份字节(§19.3 幂等,内容寻址的前提)。
31
+ * **类名不在这里排序**——级联序由发射端按 `utility.order` 决定(空间层),
32
+ * 在 class 属性里再排一次是第二份排序判据。
33
+ */
34
+ export declare function emitRegionHtml(input: EmitHtmlInput): EmitHtmlResult;
35
+ export interface VerifyArtifactHtmlInput {
36
+ readonly html: string;
37
+ readonly selectorProvenance: Readonly<Record<string, string>>;
38
+ /** 样式表真正发射出来的类名(`SomaUtilityStylesheet.classNames`) */
39
+ readonly emittedClassNames: readonly string[];
40
+ /** 出错时指哪个区域 */
41
+ readonly region: string;
42
+ }
43
+ /**
44
+ * 产物闸门。**单独导出**是给上游闸门与测试用的:
45
+ * 它必须能对着一份"外面拿来的 HTML"跑,否则"引擎不产生内联处理器"这句话
46
+ * 就只是一句没人验证过的话。
47
+ *
48
+ * 三条判据,任何一条不过都当场抛(铁律二:失败必须在编译期且可解释):
49
+ * ① HTML 里的每个 class 都在 `selectorProvenance` 里(零扫描收集的兑现);
50
+ * ② `selectorProvenance` 里的每个类选择器都有对应的 CSS 规则(不产死类名);
51
+ * ③ 没有任何内联事件处理器属性(§24.1)。
52
+ */
53
+ export declare function verifyArtifactHtml(input: VerifyArtifactHtmlInput): void;
@@ -0,0 +1,5 @@
1
+ export { SomaArtifactError, traceChainForSelector, traceForSelector, type SomaArtifact, type SomaArtifactDecision, type SomaBindingConfig, type SomaEventConfig, type SomaFieldBinding, type SomaTrace, } from './artifact.types';
2
+ export { SOMA_ARTIFACT_SPACE_ROOTS, SOMA_ARTIFACT_SPACE_STEPS, utilityClass, utilityClasses, type SomaArtifactSpaceRoot, type SomaArtifactSpaceStep, type SomaArtifactUtility, } from './utility-class';
3
+ export { ROOT_SUFFIX, SHELL_SUFFIX, SOMA_ARTIFACT_REQUIRED_ROOTS, spatialTreeFromNode, type SpatialTreeOptions, type SpatialTreeResult, } from './spatial-tree';
4
+ export { emitRegionHtml, escapeAttribute, escapeText, verifyArtifactHtml, type EmitHtmlInput, type EmitHtmlResult, type VerifyArtifactHtmlInput, } from './emit-html';
5
+ export { emitArtifact, type EmitArtifactInput } from './emit-artifact';
@@ -0,0 +1,48 @@
1
+ import type { SomaOouiNode } from '../../../shared/types/ui-config.types';
2
+ import type { SomaSpatialNode } from '../spatial/ir.types';
3
+ import { type SomaArtifactDecision } from './artifact.types';
4
+ /** 区域外壳节点的 id 后缀。壳不参与绑定,故不带 `data-soma-id` */
5
+ export declare const SHELL_SUFFIX = "-shell";
6
+ /** 根组件实例的 id 后缀。它带 `data-soma-id`,是绑定与挂载的落点 */
7
+ export declare const ROOT_SUFFIX = "-root";
8
+ /** 本层配方真正引用到的 root 名,升序去重。**由配方表派生**,不手写——手写的那份会撒谎 */
9
+ export declare const SOMA_ARTIFACT_REQUIRED_ROOTS: readonly string[];
10
+ export interface SpatialTreeOptions {
11
+ /**
12
+ * 区域锚点名:页面 HTML 里**已经存在**的那个 `data-soma-id`。
13
+ * 产出的节点 id 以它为前缀,所以它必须合文法。
14
+ */
15
+ region: string;
16
+ /**
17
+ * 整页已占用的锚点 id。给了就核对,不给则**不核**——
18
+ * 不核这件事本身会记进 `decisions`,不会假装核过了。
19
+ */
20
+ reservedAnchors?: ReadonlySet<string>;
21
+ }
22
+ export interface SpatialTreeResult {
23
+ /** 交给 `solveSpatial()` 的 IR 树 */
24
+ readonly tree: SomaSpatialNode;
25
+ /** 节点 id → 构件树里的节点路径。`selectorProvenance` 的元素选择器那一半由它来 */
26
+ readonly nodePaths: Readonly<Record<string, string>>;
27
+ /** 区域外壳的节点 id(只带 `data-soma-node`,不参与绑定) */
28
+ readonly shellId: string;
29
+ /** 根组件实例的锚点 id(带 `data-soma-id`,绑定与挂载的落点) */
30
+ readonly rootAnchor: string;
31
+ /** 外壳挂上的原子类候选串,书写序 */
32
+ readonly shellClasses: readonly string[];
33
+ readonly decisions: readonly SomaArtifactDecision[];
34
+ }
35
+ /**
36
+ * 构件树 → IR 树。
37
+ *
38
+ * 产出的形状恒为「区域外壳(block 组) > 根构件(组件 / 叶子)」两层:
39
+ * · 外壳是 block 轴组 —— 它发 `display:flex` + `flex-direction:column` +
40
+ * `container-type:inline-size`(由空间层的 `emitBlockCss` 发,本层不自己拼 CSS);
41
+ * · 根构件是**求解边界**:`#text` 落成 `leaf`,其余落成 `component`。
42
+ *
43
+ * 为什么外壳的 `gap` 走原子类而不是 `SomaSpatialGroupNode.gap`:
44
+ * 后者收的是**长度字面量**(`'1rem'`),那是一个绕开令牌表的魔数入口;
45
+ * `soma-gap-4` 查的是 `--soma-space-4`。同一件事只能有一个入口,
46
+ * 而必须是查表的那个(架构 §3.5 硬约束一)。
47
+ */
48
+ export declare function spatialTreeFromNode(node: SomaOouiNode, options: SpatialTreeOptions): SpatialTreeResult;