soma-core 1.4.0 → 1.4.2

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 (132) hide show
  1. package/README.md +1 -1
  2. package/core/build/blocks/block-compile.ts +31 -2
  3. package/core/build/blocks/block-container.ts +2 -11
  4. package/core/build/compiler/page-declaration-compiler.ts +30 -2
  5. package/core/build/compiler/soma-precompile.js +2053 -23
  6. package/core/build/component/component-graph.ts +208 -0
  7. package/core/build/component/package-loader.ts +32 -0
  8. package/core/build/eject/component-eject.ts +473 -0
  9. package/core/build/eject/component-upgrade.ts +359 -0
  10. package/core/build/layout/constraint-solver.ts +235 -0
  11. package/core/build/layout/css-emitter.ts +116 -0
  12. package/core/build/layout/page-layout.ts +85 -0
  13. package/core/build/pack/pack-init.ts +270 -0
  14. package/core/client/base/SomaHttpClient.ts +34 -1
  15. package/core/client/base/SomaPageRootBase.ts +61 -0
  16. package/core/client/component/ai-catalog.ts +121 -4
  17. package/core/client/component/component-defaults.ts +100 -0
  18. package/core/client/component/component-definition.types.ts +39 -0
  19. package/core/client/component/component-manager.ts +79 -4
  20. package/core/client/component/component-pack.ts +126 -2
  21. package/core/client/component/keyboard-matrix.ts +144 -0
  22. package/core/client/component/pack-styles.ts +59 -1
  23. package/core/client/component/style-features.ts +131 -0
  24. package/core/client/component/theme-component-tokens.ts +83 -0
  25. package/core/client/component/verify-pack.ts +120 -1
  26. package/core/client/container/SomaContainerAdapter.ts +6 -2
  27. package/core/client/data/data-object-resolver.ts +407 -4
  28. package/core/client/data/reaction-engine.ts +176 -0
  29. package/core/client/data/window-engine.ts +477 -0
  30. package/core/client/engine/event-engine.ts +98 -0
  31. package/core/client/engine/soma-bootstrap.ts +265 -5
  32. package/core/client/engine/step-runner.ts +134 -0
  33. package/core/client/infra/http/SomaHttpService.ts +2 -2
  34. package/core/client/parser/blocks/page-parser.ts +15 -1
  35. package/core/client/parser/blocks/use-parser.ts +5 -12
  36. package/core/client/parser/data-config-parser.ts +316 -8
  37. package/core/client/parser/duration.ts +16 -0
  38. package/core/client/parser/layout-parser.ts +157 -0
  39. package/core/client/parser/page-state-parser.ts +166 -0
  40. package/core/client/parser/pipeline-parser.ts +76 -1
  41. package/core/client/parser/reaction-parser.ts +459 -0
  42. package/core/client/parser/reaction-sugar.ts +47 -0
  43. package/core/client/parser/step-parser.ts +359 -0
  44. package/core/client/parser/ui-config-parser.ts +59 -0
  45. package/core/client/parser/window-parser.ts +294 -0
  46. package/core/client/theme/theme-engine.ts +102 -2
  47. package/core/index.ts +184 -0
  48. package/core/shared/block-errors.ts +11 -0
  49. package/core/shared/calc/coerce.ts +29 -0
  50. package/core/shared/calc/errors.ts +43 -0
  51. package/core/shared/calc/evaluator.ts +101 -0
  52. package/core/shared/calc/index.ts +12 -0
  53. package/core/shared/calc/lexer.ts +194 -0
  54. package/core/shared/calc/parser.ts +204 -0
  55. package/core/shared/calc/typer.ts +184 -0
  56. package/core/shared/component/derive-sample.ts +105 -0
  57. package/core/shared/component/field-lines.ts +473 -0
  58. package/core/shared/path-algebra.ts +169 -0
  59. package/core/shared/predicates/index.ts +527 -0
  60. package/core/shared/types/component-contract.types.ts +151 -9
  61. package/core/shared/types/data-config.types.ts +120 -1
  62. package/core/shared/types/domain.types.ts +13 -0
  63. package/core/shared/types/event.types.ts +22 -2
  64. package/core/shared/types/layout-constraint.types.ts +73 -0
  65. package/core/shared/types/page-state.types.ts +60 -0
  66. package/core/shared/types/reaction.types.ts +144 -0
  67. package/core/shared/types/step.types.ts +91 -0
  68. package/core/shared/types/ui-config.types.ts +18 -0
  69. package/core/shared/types/window.types.ts +177 -0
  70. package/dist/cli/soma.js +13 -1
  71. package/dist/core/index.cjs +5529 -631
  72. package/dist/types/build/blocks/block-container.d.ts +1 -6
  73. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
  74. package/dist/types/build/component/component-graph.d.ts +85 -0
  75. package/dist/types/build/eject/component-eject.d.ts +121 -0
  76. package/dist/types/build/eject/component-upgrade.d.ts +43 -0
  77. package/dist/types/build/layout/constraint-solver.d.ts +36 -0
  78. package/dist/types/build/layout/css-emitter.d.ts +18 -0
  79. package/dist/types/build/layout/page-layout.d.ts +24 -0
  80. package/dist/types/build/pack/pack-init.d.ts +8 -0
  81. package/dist/types/client/base/SomaHttpClient.d.ts +8 -0
  82. package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
  83. package/dist/types/client/component/ai-catalog.d.ts +33 -1
  84. package/dist/types/client/component/component-defaults.d.ts +15 -0
  85. package/dist/types/client/component/component-definition.types.d.ts +38 -0
  86. package/dist/types/client/component/component-manager.d.ts +36 -0
  87. package/dist/types/client/component/component-pack.d.ts +32 -2
  88. package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
  89. package/dist/types/client/component/pack-styles.d.ts +21 -0
  90. package/dist/types/client/component/style-features.d.ts +26 -0
  91. package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
  92. package/dist/types/client/component/verify-pack.d.ts +10 -0
  93. package/dist/types/client/data/data-object-resolver.d.ts +106 -1
  94. package/dist/types/client/data/reaction-engine.d.ts +21 -0
  95. package/dist/types/client/data/window-engine.d.ts +27 -0
  96. package/dist/types/client/engine/event-engine.d.ts +15 -0
  97. package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
  98. package/dist/types/client/engine/step-runner.d.ts +24 -0
  99. package/dist/types/client/parser/blocks/use-parser.d.ts +2 -2
  100. package/dist/types/client/parser/duration.d.ts +1 -0
  101. package/dist/types/client/parser/layout-parser.d.ts +9 -0
  102. package/dist/types/client/parser/page-state-parser.d.ts +32 -0
  103. package/dist/types/client/parser/reaction-parser.d.ts +16 -0
  104. package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
  105. package/dist/types/client/parser/step-parser.d.ts +23 -0
  106. package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
  107. package/dist/types/client/parser/window-parser.d.ts +25 -0
  108. package/dist/types/client/theme/theme-engine.d.ts +26 -0
  109. package/dist/types/index.d.ts +35 -2
  110. package/dist/types/shared/block-errors.d.ts +5 -0
  111. package/dist/types/shared/calc/coerce.d.ts +4 -0
  112. package/dist/types/shared/calc/errors.d.ts +14 -0
  113. package/dist/types/shared/calc/evaluator.d.ts +2 -0
  114. package/dist/types/shared/calc/index.d.ts +6 -0
  115. package/dist/types/shared/calc/lexer.d.ts +20 -0
  116. package/dist/types/shared/calc/parser.d.ts +49 -0
  117. package/dist/types/shared/calc/typer.d.ts +16 -0
  118. package/dist/types/shared/component/derive-sample.d.ts +23 -0
  119. package/dist/types/shared/component/field-lines.d.ts +19 -0
  120. package/dist/types/shared/path-algebra.d.ts +56 -0
  121. package/dist/types/shared/predicates/index.d.ts +79 -0
  122. package/dist/types/shared/types/component-contract.types.d.ts +134 -6
  123. package/dist/types/shared/types/data-config.types.d.ts +115 -1
  124. package/dist/types/shared/types/domain.types.d.ts +12 -0
  125. package/dist/types/shared/types/event.types.d.ts +8 -2
  126. package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
  127. package/dist/types/shared/types/page-state.types.d.ts +49 -0
  128. package/dist/types/shared/types/reaction.types.d.ts +115 -0
  129. package/dist/types/shared/types/step.types.d.ts +76 -0
  130. package/dist/types/shared/types/ui-config.types.d.ts +18 -0
  131. package/dist/types/shared/types/window.types.d.ts +171 -0
  132. package/package.json +3 -2
@@ -1,9 +1,5 @@
1
1
  import type { HtmlAnchorIndex } from './html-index';
2
- export declare class SomaBlockParseError extends Error {
3
- readonly blockId?: string | undefined;
4
- readonly line?: number | undefined;
5
- constructor(message: string, blockId?: string | undefined, line?: number | undefined);
6
- }
2
+ export { SomaBlockParseError } from '../../shared/block-errors';
7
3
  /** 页面壳块的固定 id */
8
4
  export declare const PAGE_BLOCK_ID = "page";
9
5
  export interface RawBlock {
@@ -42,4 +38,3 @@ export declare function parseSomaBlockContainer(uiYamlRaw: string): SomaBlockCon
42
38
  * 块挂在普通锚点上——不拦的话都表现为"这段声明没生效",而不报错。
43
39
  */
44
40
  export declare function loadSomaFile(input: SomaFileLoadInput): RawBlock[];
45
- export {};
@@ -27,6 +27,8 @@ export interface CompiledPageDeclaration {
27
27
  timers: ParsedTimer[];
28
28
  styleConfig?: StyleConfig;
29
29
  dataConfig?: SomaDataConfig;
30
+ /** `layout:` 段的构建期产物:只含容器查询 + flex(CL-2);没声明就没有 */
31
+ layoutCss?: string;
30
32
  runtimeAssets: SomaRuntimeDeclarationAssets;
31
33
  }
32
34
  /** 编译一整页 SOMA DSL 声明。旧页面形状与页面侧车在唯一入口直接拒绝。 */
@@ -0,0 +1,85 @@
1
+ import type { SomaComponentDefinition } from '../../client/component/component-definition.types';
2
+ export interface ComponentGraphNode {
3
+ name: string;
4
+ layer: string;
5
+ version: string;
6
+ /** 直接依赖(契约 `uses`) */
7
+ uses: string[];
8
+ /** 传递闭包(不含自身) */
9
+ closure: string[];
10
+ }
11
+ export interface ComponentGraph {
12
+ nodes: Record<string, ComponentGraphNode>;
13
+ /** 声明了却不存在的依赖:`组件名 → 缺失的依赖名[]` */
14
+ missing: Record<string, string[]>;
15
+ /** 依赖环:每条是一个完整回路 */
16
+ cycles: string[][];
17
+ }
18
+ /**
19
+ * 建图。
20
+ *
21
+ * 缺失依赖与环**不抛**,而是收进产物:这个函数同时服务于闸门与 CLI,
22
+ * 闸门要拿到全部问题一次报完(抛的话作者修一条跑一次,修十条跑十次),
23
+ * CLI 则要在有问题时也能给出一份"能拉的先拉上"的清单。判定归调用方。
24
+ */
25
+ export declare function buildComponentGraph(definitions: Record<string, SomaComponentDefinition>): ComponentGraph;
26
+ /**
27
+ * 按图拉齐:给一组组件名,返回它们加上全部传递依赖的名单(拓扑序)。
28
+ *
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
+ * 产出可寻址目录。
61
+ *
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 依赖表的对账。
76
+ *
77
+ * 两张表都在描述"这个组件还需要谁",所以它们必须一致。不对账的话,
78
+ * 一条只写在 CSS 表里的依赖会让 eject 少拉一个文件,而一条只写在契约里的依赖
79
+ * 会让页面少注一段样式——两种坏法都不报错,都只是长得不对。
80
+ */
81
+ export declare function reconcileCssDeps(graph: ComponentGraph, cssDeps: Record<string, readonly string[]>): Array<{
82
+ component: string;
83
+ onlyInCss: string[];
84
+ onlyInContract: string[];
85
+ }>;
@@ -0,0 +1,121 @@
1
+ export declare class ComponentEjectError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export interface ComponentEjectFile {
5
+ /** 相对目标目录的路径 */
6
+ path: string;
7
+ content: string;
8
+ }
9
+ export interface ComponentProvenance {
10
+ /** 来源包名 */
11
+ from: string;
12
+ /** 来源包版本 */
13
+ version: string;
14
+ /** 来源文件(相对 soma-ui 包根) */
15
+ source: string;
16
+ /** 来源文件内容的 sha256(diff 的比对基准) */
17
+ sha256: string;
18
+ }
19
+ export interface ComponentEjectPlan {
20
+ componentName: string;
21
+ files: ComponentEjectFile[];
22
+ provenance: ComponentProvenance;
23
+ /** 被改写的导入:内部相对路径 → 公开子路径 */
24
+ rewrittenImports: Array<{
25
+ from: string;
26
+ to: string;
27
+ }>;
28
+ /** 用到的 soma-ui 公开子路径(不复制,运行期从包里取) */
29
+ requiredShared: string[];
30
+ /**
31
+ * 契约声明的组件级依赖(REQ-010 F-46)。
32
+ *
33
+ * eject 只拉这一个组件的源码;依赖仍从 soma-ui 取。列出来是为了让作者知道
34
+ * **这份副本还牵着谁**——把 TreeSelect 拉走却不知道它要 Tree 的话,
35
+ * 页面上是一排无样式的折叠箭头,而且不报错。
36
+ */
37
+ requiredComponents: string[];
38
+ }
39
+ export interface ComponentEjectOptions {
40
+ /** 组件契约名(PascalCase) */
41
+ name: string;
42
+ /** 目标目录(宿主的组件包目录) */
43
+ to: string;
44
+ /** soma-ui 包根(含 package.json 与 src/) */
45
+ uiRoot: string;
46
+ }
47
+ /** PascalCase → kebab-case 文件名(DataTable → data-table) */
48
+ export declare function componentFileNameOf(name: string): string;
49
+ /**
50
+ * 规划一次组件固化:读源、改写导入、盖 provenance、加 overrides 声明。
51
+ * 纯计算 + 只读文件,不落盘——落盘是 applyComponentEject 的事(与页面 eject 同形)。
52
+ */
53
+ export declare function planComponentEject(options: ComponentEjectOptions): ComponentEjectPlan;
54
+ /**
55
+ * 从源码里读契约的 `uses`(REQ-010 F-46)。
56
+ *
57
+ * 用正则而不是把文件 import 进来求值:eject 是构建期工具,它面对的可能是一份
58
+ * **改坏了的**源码(宿主正在编辑),import 会直接抛在一个与 eject 无关的地方。
59
+ * 正则读不出来就当没有依赖——比整条命令挂掉好:拉少了作者看得见(页面缺一块),
60
+ * 而命令挂掉他连拉都拉不成。
61
+ */
62
+ export declare function readContractUses(source: string): string[];
63
+ /** 基线快照目录(相对目标包目录):与产物同级、单独一层,不会被当成组件源码注册 */
64
+ export declare const BASE_DIR = ".soma-eject-base";
65
+ export interface ApplyComponentEjectOptions {
66
+ /** 目标目录(宿主组件包目录) */
67
+ to: string;
68
+ force?: boolean;
69
+ }
70
+ export interface ComponentEjectResult {
71
+ written: string[];
72
+ skipped: string[];
73
+ }
74
+ /** 落盘。默认撞名即中止——宿主目录里的东西是人写的(与页面 eject 同一条默认值)。 */
75
+ export declare function applyComponentEject(plan: ComponentEjectPlan, options: ApplyComponentEjectOptions): ComponentEjectResult;
76
+ export interface ComponentDiffResult {
77
+ componentName: string;
78
+ changed: boolean;
79
+ /** 记在产物里的来源版本 */
80
+ ejectedFrom: ComponentProvenance;
81
+ /** 上游当前版本 */
82
+ currentVersion: string;
83
+ /** 上游当前内容的 sha256 */
84
+ currentSha256: string;
85
+ /** 是否找到了 eject 时落盘的基线;没有基线就出不了 diff,只能报"变了" */
86
+ hasBaseline?: boolean;
87
+ /** 统一 diff(changed 且有基线时给出) */
88
+ unified?: string;
89
+ }
90
+ /** 从 eject 产物的头部读回 provenance;读不到说明它不是 eject 产物 */
91
+ /**
92
+ * 剥掉 eject 产物的 provenance 头,返回 `{ header, body }`。
93
+ *
94
+ * 三方合并要用它:产物带头、基线不带,不剥的话那几行会被当成"宿主的插入",
95
+ * 与上游在同一位置的任何改动撞成冲突——而那是一次凭空的冲突。
96
+ */
97
+ export declare function splitProvenanceHeader(content: string): {
98
+ header: string;
99
+ body: string;
100
+ };
101
+ /**
102
+ * 把一份上游原文按 eject 的同一张表改写导入。
103
+ *
104
+ * 三方合并要把基线与上游都搬到"宿主坐标系"里:产物里的导入是改写过的,
105
+ * 而基线与上游是原始相对路径。不搬的话,每一条 import 都会被当成宿主的改动,
106
+ * 于是上游任何一次 import 调整都变成冲突。
107
+ */
108
+ export declare function rewriteImportsForHost(source: string): string;
109
+ export declare function readProvenance(content: string): ComponentProvenance | null;
110
+ /**
111
+ * 对比 eject 产物与上游当前源码。
112
+ *
113
+ * 比的是**上游的旧版与新版**(用产物里记的 sha256 判定上游是否动过),
114
+ * 不是「产物 vs 上游」——产物本来就该被宿主改,拿它去比只会满屏都是宿主自己的改动。
115
+ */
116
+ export declare function diffEjectedComponent(ejectedFile: string, uiRoot: string): ComponentDiffResult;
117
+ /**
118
+ * 极简统一 diff(LCS)。刻意不引第三方 diff 依赖:
119
+ * 供应链闸门要为每个新依赖负责,而这里要的只是「让人看见改了哪几行」。
120
+ */
121
+ export declare function renderUnifiedDiff(label: string, oldTag: string, newTag: string, oldText: string, newText: string): string;
@@ -0,0 +1,43 @@
1
+ import { type ComponentProvenance } from './component-eject';
2
+ export interface ComponentUpgradeOptions {
3
+ /** 宿主包里的产物文件 */
4
+ file: string;
5
+ /** soma-ui 源根 */
6
+ uiRoot: string;
7
+ /** 只看不写 */
8
+ dryRun?: boolean;
9
+ }
10
+ export interface ComponentUpgradeResult {
11
+ componentName: string;
12
+ /** 上游没动过:什么都不用做 */
13
+ upToDate: boolean;
14
+ /** 合并后的内容(dryRun 时也给) */
15
+ merged?: string;
16
+ /** 冲突块数;> 0 时基线**不**更新 */
17
+ conflicts: number;
18
+ /** 自动合进来的上游改动行数 */
19
+ applied: number;
20
+ ejectedFrom: ComponentProvenance;
21
+ currentVersion: string;
22
+ /** 供人复核的统一 diff(基线 → 上游新版) */
23
+ upstreamDiff?: string;
24
+ written: string[];
25
+ }
26
+ /** 三方合并的一块:要么是三边一致的公共段,要么是一处分歧 */
27
+ interface MergeChunk {
28
+ kind: 'common' | 'ours' | 'theirs' | 'conflict';
29
+ base: string[];
30
+ ours: string[];
31
+ theirs: string[];
32
+ }
33
+ export declare function upgradeEjectedComponent(options: ComponentUpgradeOptions): ComponentUpgradeResult;
34
+ /**
35
+ * 三方合并。
36
+ *
37
+ * 做法:先分别求 base↔ours 与 base↔theirs 的 LCS 对齐,再沿 base 的行号同步扫两边。
38
+ * 同一段 base 上只有一边改 → 取那一边;两边都改且内容不同 → 冲突。
39
+ *
40
+ * 刻意不引 diff3 库:算法本身二十行,而引一个依赖要为它的供应链负责。
41
+ */
42
+ export declare function threeWayMerge(base: string[], ours: string[], theirs: string[]): MergeChunk[];
43
+ export {};
@@ -0,0 +1,36 @@
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]>;
4
+ export declare class SomaLayoutConstraintError extends Error {
5
+ /** 打架的两条声明(CL-1 要求错误信息含冲突约束对) */
6
+ readonly conflict: readonly [string, string];
7
+ constructor(message: string, conflict: readonly [string, string]);
8
+ }
9
+ /**
10
+ * 长度字面量 → rem。
11
+ *
12
+ * 三种单位:`rem` 直取;`%` 与 `cqi` 都是"容器宽的百分比"(`cqi` 就是容器内联轴的 1%),
13
+ * 所以都按当前档的容器宽折算。折算而不是留到 CSS 里去算,是因为求解要在数上做——
14
+ * 留着符号的话,「min 有没有被违反」就成了一个运行期才知道答案的问题。
15
+ */
16
+ export declare function toRem(literal: string, containerRem: number, where: string): number;
17
+ /** 声明校验(CL-3):优先级四档、min ≤ max、fixed 必须给 width */
18
+ export declare function validateConstraint(constraint: SomaLayoutConstraint, path: string): void;
19
+ /**
20
+ * 单档求解。
21
+ *
22
+ * 算法(确定性,不迭代):
23
+ * 1. 每项先拿它的**基线**:fixed 取 width,fill 取 min(fill 的诉求是"多余的给我",
24
+ * 所以它从下界起步),hug 取 min 或 0;
25
+ * 2. 基线总和超过可用长度 → **按优先级从低到高压缩**,压到各自 min 为止;
26
+ * 3. 仍有富余 → 按优先级从低到高**分给 fill 项**(低优先级 = Content Hugging = 更愿意被拉大),
27
+ * 受各自 max 限制;
28
+ * 4. 压到全部 min 仍放不下 → 该档无解,交给 `wrap` 决定是换行还是报错。
29
+ *
30
+ * 第 2、3 步的优先级方向是相反的,这不是笔误:压缩时先动"不介意被压"的(低优先级),
31
+ * 拉伸时也先给"愿意被拉大"的(低优先级)。Auto Layout 的两个名字(Hugging /
32
+ * Compression Resistance)说的就是同一个数的两面。
33
+ */
34
+ export declare function solveStep(constraint: SomaLayoutConstraint, containerRem: number, breakpoint: string, path: string): SomaLayoutSolution;
35
+ /** 八档各解一次(CL-1) */
36
+ export declare function solveLayout(constraint: SomaLayoutConstraint, path: string): SomaLayoutPlan;
@@ -0,0 +1,18 @@
1
+ import { type SomaLayoutConstraintError } from './constraint-solver';
2
+ import type { SomaLayoutPlan } from '../../shared/types/layout-constraint.types';
3
+ export interface EmitOptions {
4
+ /** 组根选择器,如 `.soma-sidebar-pair` */
5
+ root: string;
6
+ /** 子项名 → 选择器;不给时按 `${root} > [data-soma-slot="<名>"]` */
7
+ selectorOf?(name: string): string;
8
+ }
9
+ /**
10
+ * 产出该组的全部 CSS。
11
+ *
12
+ * 结构:一条基线规则(最窄档的解)+ 每个更宽档一条容器查询。
13
+ * 基线取**最窄档**而不是最宽档:容器查询是 `min-width` 向上覆盖的,
14
+ * 基线必须是"什么查询都没命中时"的样子,也就是最窄的那一档。
15
+ * 取最宽档当基线的话,不支持容器查询的浏览器会拿到宽屏布局塞进窄容器。
16
+ */
17
+ export declare function emitLayoutCss(plan: SomaLayoutPlan, options: EmitOptions): string;
18
+ export type { SomaLayoutConstraintError };
@@ -0,0 +1,24 @@
1
+ import type { HtmlAnchorIndex } from '../blocks/html-index';
2
+ import type { SomaLayoutConstraint } from '../../shared/types/layout-constraint.types';
3
+ export declare class SomaPageLayoutError extends Error {
4
+ readonly path: string;
5
+ constructor(message: string, path: string);
6
+ }
7
+ export interface CompilePageLayoutInput {
8
+ /** 页面块直通的原文(或已解析的约束表;两种都收,解析是幂等的) */
9
+ raw: unknown;
10
+ htmlIndex: HtmlAnchorIndex;
11
+ /** 宿主类名:选择器前缀,避免同文档里两页同名锚点互相串样式 */
12
+ hostClass: string;
13
+ }
14
+ export interface CompiledPageLayout {
15
+ constraints: Record<string, SomaLayoutConstraint>;
16
+ css: string;
17
+ }
18
+ /**
19
+ * 编译整页的 `layout:` 段。
20
+ *
21
+ * 锚点与子项名都对着 HTML 锚点索引核:写错一个字母的表现是"某一行的布局
22
+ * 完全没生效",页面上看着只是排得松一点——只有在这里指名才有人发现。
23
+ */
24
+ export declare function compilePageLayout(input: CompilePageLayoutInput): CompiledPageLayout;
@@ -0,0 +1,8 @@
1
+ export interface PackInitFile {
2
+ path: string;
3
+ content: string;
4
+ }
5
+ export declare class PackInitError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ export declare function planPackInit(packName: string): PackInitFile[];
@@ -9,6 +9,14 @@ export interface SomaHttpClientConfig {
9
9
  /** Generic headers supplied by the host runtime, such as page context. */
10
10
  defaultHeaders?: Record<string, string> | (() => Record<string, string>);
11
11
  }
12
+ /**
13
+ * 从错误响应正文里提炼一句可读文案。
14
+ *
15
+ * 服务端精心写的结构化错误(`{ ok: false, error: "未知组件:X" }`)才是调用方要的信息,
16
+ * 只留 statusText 等于把它整条丢掉。正文也可能是 HTML 错误页或空串,
17
+ * 因此 JSON 解析必须容错——解析失败只是"没有结构化字段",不该把请求变成另一种崩法。
18
+ */
19
+ export declare function describeHttpErrorBody(body: string, statusText: string): string;
12
20
  /**
13
21
  * SomaHttpClient — API 请求封装
14
22
  *
@@ -1,4 +1,5 @@
1
1
  import type { SomaPageRoot, SomaAppConfig } from '../../shared/types/domain.types';
2
+ import type { SomaPageState, SomaPageStateConfig } from '../../shared/types/page-state.types';
2
3
  import type { SomaRuntimeServices } from '../runtime/SomaRuntimeServices';
3
4
  /**
4
5
  * SomaPageRootBase — 页面聚合根基类
@@ -37,7 +38,34 @@ export declare abstract class SomaPageRootBase implements SomaPageRoot {
37
38
  data: Record<string, unknown>;
38
39
  /** 由 bootstrap 注入的数据对象重取钩子(无 *_data.yaml 声明时保持未定义) */
39
40
  _reloadData?: () => Promise<void>;
41
+ /**
42
+ * 页面态(REQ-010 F-37):排序 / 过滤 / 选择 / 列显隐与列序 / 密度 / 展开。
43
+ *
44
+ * 分享链接、用户偏好、审计回放共用这一份结构。它以**非枚举**属性挂载——
45
+ * 与 `data` 同一理由:页面状态快照与序列化不该把它算进业务字段。
46
+ */
47
+ _pageState: SomaPageState | null;
48
+ /** 由 bootstrap 注入:`state:` 段的声明(没声明时为 null) */
49
+ _pageStateConfig?: SomaPageStateConfig | null;
50
+ /** 状态变化的订阅者(组件与 Host 都可以听) */
51
+ private _stateListeners?;
40
52
  constructor();
53
+ /**
54
+ * 当前页面态。没声明 `state:` 段时返回 null——**不是空对象**:
55
+ * 空对象会让调用方以为「有状态,只是都是缺省」,于是把它序列化进分享链接,
56
+ * 而链接打开后什么都恢复不了。null 说的是「这一页没有可序列化的状态」。
57
+ */
58
+ getState(): SomaPageState | null;
59
+ /**
60
+ * 整份替换页面态并通知订阅者。
61
+ *
62
+ * 整份替换而不是深合并:合并语义在「选择态从三行变成零行」这类清空操作上
63
+ * 是表达不出来的(少写一个键与写一个空数组在合并下是同一件事)。
64
+ * 要改一块就先 `getState()` 拿全份、改完再交回来——那是显式的。
65
+ */
66
+ setState(next: SomaPageState): void;
67
+ /** 订阅页面态变化;返回退订函数 */
68
+ onStateUpdated(listener: (state: SomaPageState) => void): () => void;
41
69
  /**
42
70
  * 重新执行数据对象取数(Domain 可在业务动作后调用刷新 page.data)。
43
71
  * 页面未声明数据对象时为空操作。
@@ -1,4 +1,4 @@
1
- import type { SomaComponentContract, SomaGeometryFamily } from '../../shared/types/component-contract.types';
1
+ import { type SomaComponentContract, type SomaContractKeyboard, type SomaContractOverlay, type SomaGeometryFamily } from '../../shared/types/component-contract.types';
2
2
  import type { SomaComponentDefinition } from './component-definition.types';
3
3
  export interface SomaAiCatalogEntry {
4
4
  name: string;
@@ -30,12 +30,44 @@ export interface SomaAiCatalogEntry {
30
30
  required: boolean;
31
31
  desc: string;
32
32
  }>;
33
+ /**
34
+ * 键盘契约(REQ-011 / IK-2)。
35
+ *
36
+ * 这里**只存契约**:逐键矩阵是 `deriveKeyboardMatrix(contract)` 的返回值,
37
+ * 那一行紧凑键盘表是 `renderKeyboardMatrixLine(contract)` 的返回值——两者都是渲染,
38
+ * 存进来等于把同一个真值抄成三份,而这一轮要治的正是这种抄写。
39
+ * 人与模型读到的键盘表在 markdown 那一侧(检索喂给模型的就是它);
40
+ * 需要逐键结构的程序自己调那个函数(与 soma-ui 接线、闸门读的是同一个)。
41
+ */
42
+ keyboard?: {
43
+ contract: SomaContractKeyboard;
44
+ };
45
+ /** 浮层行为契约(声明了才有) */
46
+ overlay?: SomaContractOverlay;
47
+ /** 契约级依赖(F-46):装这个还要装什么 */
48
+ uses?: string[];
49
+ /** 组件级令牌(M-1):这个组件开放的可调旋钮及其 CSS 变量名 */
50
+ tokens?: Array<{
51
+ name: string;
52
+ cssVar: string;
53
+ default: string;
54
+ desc: string;
55
+ }>;
33
56
  ai?: {
34
57
  whenToUse: string;
35
58
  whenNotToUse?: string;
36
59
  example: string;
37
60
  antiPatterns?: string[];
38
61
  };
62
+ /**
63
+ * 字段行原文(REQ-012):对象 / 数组 prop 的逐字段形状与示例。
64
+ *
65
+ * 只在契约真写了嵌套形状或示例时出现——否则它与上面的 props 表逐字重复。
66
+ * 目录直接打印它,不另生成第二张字段表:作者写的和读者读到的是同一份东西。
67
+ */
68
+ spec?: string;
69
+ /** 派生样张(REQ-012):展示页与视觉矩阵喂给组件的那份 props */
70
+ sample?: Record<string, unknown>;
39
71
  }
40
72
  /**
41
73
  * 旧组件契约的迁移归族。
@@ -0,0 +1,15 @@
1
+ import type { SomaComponentDefinition } from './component-definition.types';
2
+ export declare class SomaComponentDefaultsError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export type SomaComponentDefaults = Record<string, Record<string, unknown>>;
6
+ /**
7
+ * bootstrap 期校验 Host 默认 props。
8
+ *
9
+ * 四类拒绝,每一类都在拒绝"猜":
10
+ * 未知组件名 → 多半是拼错或组件改名,静默忽略会让人以为默认生效了;
11
+ * 未知 prop → 同上;
12
+ * 枚举外取值 → 组件按未知值渲染的行为没有定义;
13
+ * required prop → 必填项由页面负责,用默认值填等于把"忘了传"变成静默的错数据。
14
+ */
15
+ export declare function validateComponentDefaults(defaults: SomaComponentDefaults | undefined, components: Record<string, SomaComponentDefinition>): void;
@@ -27,6 +27,38 @@ export interface SomaComponentControllerContext {
27
27
  * 实例销毁时调用 onUnmount(清理订阅/定时器)。
28
28
  */
29
29
  export type SomaComponentControllerFactory = (ctx: SomaComponentControllerContext) => Record<string, unknown>;
30
+ /**
31
+ * 特性分片(REQ-009 M-3):按 prop 装配的 CSS。
32
+ *
33
+ * 既有的 `styles.components` 是「按组件」装配——组件一实例化就付全部 CSS。
34
+ * DataTable 的核心分片已经贴着 7,600 上限,而排队的表格特性有五个
35
+ * (单元格类型 / 批量动作条 / 列筛选 / 展开行 / 列设置),每个 600~1,500 字节。
36
+ * 抬上限只装得下一个,下一个又要重开辩论;正确的杠杆是再细一档:
37
+ * **用到这个特性的页面才为它付钱**。
38
+ *
39
+ * 注入顺序恒定「组件分片 → 特性分片(声明序)」。这与「单组件提共享是注入顺序炸弹」
40
+ * 不冲突:特性分片只属于一个组件,永远排在它自己的分片之后,无跨组件顺序依赖。
41
+ */
42
+ /**
43
+ * 特性开关。两种写法:
44
+ * · `when: 'close_guard'` —— boolean 真值 / array 非空即启用;
45
+ * · `when: { prop: 'list_type', equals: ['picture', 'picture-card'] }` ——
46
+ * enum 取到指定值之一才启用。
47
+ *
48
+ * 第二种是 REQ-009 施工中补的:首批两个消费者(Upload 的 `list_type`、
49
+ * DataTable 的单元格类型)都卡在同一处——真正决定"要不要这段样式"的是一个**枚举值**,
50
+ * 而不是某个布尔开关。只有布尔一种写法时,它们只能退而按一个恒为真的数组 prop 开门,
51
+ * 结果是所有页面都付这笔钱,机制等于白建。
52
+ */
53
+ export type SomaStyleFeatureWhen = string | {
54
+ prop: string;
55
+ equals: readonly (string | number | boolean)[];
56
+ };
57
+ export interface SomaComponentStyleFeature {
58
+ css: string;
59
+ /** 开关:prop 名(boolean/array),或 { prop, equals } 的枚举取值门控 */
60
+ when: SomaStyleFeatureWhen;
61
+ }
30
62
  export interface SomaComponentDefinition {
31
63
  contract: SomaComponentContract;
32
64
  /**
@@ -49,6 +81,12 @@ export interface SomaComponentDefinition {
49
81
  * 未声明的服务不注入。不声明本字段 = 非自治组件,ctx.services 为 undefined。
50
82
  */
51
83
  services?: string[];
84
+ /**
85
+ * 按 prop 装配的样式分片(M-3)。键为特性名,注入 key 为 `feature:<组件>#<特性>`。
86
+ * `when` 指向的 prop 首次为真值(数组非空)时注入一次,不回收——
87
+ * CSS 回收会让「关掉再打开」出现无样式帧,代价大于收益。
88
+ */
89
+ styleFeatures?: Record<string, SomaComponentStyleFeature>;
52
90
  }
53
91
  /** 保留键:实例作用域根上暴露控制器的字段名,契约禁止同名 prop */
54
92
  export declare const SOMA_COMPONENT_CTRL_KEY = "ctrl";
@@ -7,6 +7,8 @@ import type { SomaRuntimeManifest } from '../../shared/types/manifest.types';
7
7
  import type { UiConfig } from '../../shared/types/ui-config.types';
8
8
  import type { SomaComponentDefinition } from './component-definition.types';
9
9
  import { SomaComponentRegistry } from './component-registry';
10
+ import type { SomaComponentDefaults } from './component-defaults';
11
+ import type { PackStyleOptions } from './pack-styles';
10
12
  /** 页面运行时接入点(activate 入参) */
11
13
  export interface SomaComponentPageRuntime {
12
14
  container: HTMLElement;
@@ -23,12 +25,22 @@ export interface SomaComponentManagerOptions {
23
25
  diagnostics?: SomaDiagnostics;
24
26
  /** 格式化管道注册表(实例内部绑定同样可用管道) */
25
27
  pipeRegistry?: import('../pipes/pipe-registry').SomaPipeRegistry;
28
+ /**
29
+ * Host 级默认 props(M-2):组件名 → { prop: 默认值 }。
30
+ * 优先级:页面声明 > 本表 > 契约 default。合法性由 bootstrap 期的
31
+ * validateComponentDefaults 保证,这里只做取值。
32
+ */
33
+ componentDefaults?: SomaComponentDefaults;
34
+ /** 特性分片注入用的 CSP nonce(M-3) */
35
+ styleOptions?: PackStyleOptions;
26
36
  }
27
37
  export declare class SomaComponentManager {
28
38
  private readonly registry;
29
39
  private readonly scheduler?;
30
40
  private readonly diagnostics?;
31
41
  private readonly pipeRegistry?;
42
+ private readonly componentDefaults?;
43
+ private readonly styleOptions?;
32
44
  private readonly expander;
33
45
  private staticDecls;
34
46
  private propsIndex;
@@ -47,6 +59,17 @@ export declare class SomaComponentManager {
47
59
  * 注册 prop 源路径 watch、装配行内组件钩子。
48
60
  */
49
61
  activate(page: SomaComponentPageRuntime): void;
62
+ /**
63
+ * 让全部存活实例重算一遍派生视图。
64
+ *
65
+ * 为什么需要它:数据对象层是**异步**取数的(首屏不阻塞),而自治组件在取数完成前
66
+ * 就已经挂载。页面侧的 `renderEngine.render()` 重渲的是页面模板,进不到组件实例
67
+ * 自己的渲染引擎——于是一个 `data_object` 形态的 FormConsole 在数据到达后
68
+ * 仍然显示着它挂载那一刻看到的空字典:一张空表单,没有任何报错。
69
+ *
70
+ * 组件的 ctrl 派生 getter 本来就是幂等的纯读,重算一遍是安全的。
71
+ */
72
+ refreshAll(): void;
50
73
  destroy(): void;
51
74
  /**
52
75
  * 一段渲染产物离开 DOM:销毁其中的全部组件实例(含嵌套的孙实例)。
@@ -95,6 +118,8 @@ export declare class SomaComponentManager {
95
118
  private markEmitRoutes;
96
119
  private createPageReader;
97
120
  /** 行作用域读取:与 dom-renderer.resolveShowValue 同语义 */
121
+ /** 该组件的 Host 级默认 props(M-2);没有就返回 undefined,走原路径 */
122
+ private defaultsFor;
98
123
  private createRowReader;
99
124
  /** 静态实例的 prop 源路径 watch:源变更 → 重解析 → 实例更新 */
100
125
  private registerPropWatches;
@@ -107,6 +132,8 @@ interface SomaComponentInstanceOptions {
107
132
  scheduler?: SomaScheduler;
108
133
  diagnostics?: SomaDiagnostics;
109
134
  pipeRegistry?: import('../pipes/pipe-registry').SomaPipeRegistry;
135
+ /** 特性分片注入选项(M-3) */
136
+ styleOptions?: PackStyleOptions;
110
137
  services?: Record<string, unknown>;
111
138
  dispatchEmit: (emitName: string, payload: unknown) => void;
112
139
  registry: SomaComponentRegistry;
@@ -137,6 +164,7 @@ export declare class SomaComponentInstance {
137
164
  */
138
165
  private readonly staticChildren;
139
166
  private readonly mountChild;
167
+ private readonly styleOptions?;
140
168
  constructor(options: SomaComponentInstanceOptions);
141
169
  /**
142
170
  * 整树重渲 + 把新的 props 推给模板里静态嵌套的子组件。
@@ -146,6 +174,14 @@ export declare class SomaComponentInstance {
146
174
  * 分开写迟早会有人新加一处 `renderEngine.render()` 却忘了刷子组件——
147
175
  * 那种漏法不报错、只是子组件停在旧值,是最难查的一类。
148
176
  */
177
+ /**
178
+ * 外部触发的重算(数据对象取数完成等):与 props 下行走同一条重渲路径,
179
+ * 另外通知 ctrl「你读的那份外部数据换了」。
180
+ *
181
+ * 光重渲不够:重渲只让派生 getter 重算,而回填这类**副作用**(把刚到的记录摊进
182
+ * 表单模型)没有任何 getter 会做。缺这一声通知,表单的字段会出现、值却是空的。
183
+ */
184
+ refresh(): void;
149
185
  private rerender;
150
186
  /** props 下行更新:浅合并后整树重渲(ctrl 派生 getter 自然重算) */
151
187
  setProps(next: Record<string, unknown>): void;