soma-core 1.3.4 → 1.4.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 (74) hide show
  1. package/README.md +20 -7
  2. package/app/SomaPageClient.tsx +4 -4
  3. package/app/components/SomaHostPage.tsx +5 -5
  4. package/app/components/SomaHydrationShell.tsx +4 -7
  5. package/app/globals.css +126 -3
  6. package/app/soma/page/route.ts +17 -2
  7. package/core/build/{v2 → blocks}/block-compile.ts +17 -17
  8. package/core/build/{v2/soma-file-loader.ts → blocks/block-container.ts} +28 -28
  9. package/core/build/{v2 → blocks}/block-loader.ts +1 -1
  10. package/core/build/{v2 → blocks}/html-index.ts +1 -1
  11. package/core/build/{v2/migrate-v1.ts → blocks/migrate-flat.ts} +28 -28
  12. package/core/build/compiler/host-config-sync.cjs +2 -9
  13. package/core/build/compiler/page-declaration-compiler.ts +2 -2
  14. package/core/build/compiler/soma-manifest-webpack-plugin.js +1 -1
  15. package/core/build/compiler/soma-precompile.js +17 -17
  16. package/core/build/compiler/soma-precompile.ts +2 -2
  17. package/core/client/component/ai-catalog.ts +4 -4
  18. package/core/client/component/contract-compat.ts +32 -3
  19. package/core/client/component/{example-v2.ts → example-blocks.ts} +19 -19
  20. package/core/client/engine/soma-bootstrap.ts +21 -2
  21. package/core/client/engine/style-binder.ts +1 -1
  22. package/core/client/infra/notify/DomNotifyService.ts +2 -1
  23. package/core/client/infra/notify/INotifyTheme.ts +1 -1
  24. package/core/client/parser/{v2 → blocks}/namespace.ts +1 -1
  25. package/core/client/parser/{v2 → blocks}/page-parser.ts +16 -16
  26. package/core/client/parser/{v2 → blocks}/use-parser.ts +20 -14
  27. package/core/client/parser/style-config-parser.ts +7 -7
  28. package/core/client/parser/value-lang.ts +1 -1
  29. package/core/client/registry/index.ts +8 -0
  30. package/core/client/registry/page-lifecycle.ts +1 -1
  31. package/core/client/security/attribute-presence.ts +16 -1
  32. package/core/client/theme/theme-engine.ts +42 -14
  33. package/core/client/typography/typography-base.ts +1 -1
  34. package/core/index.ts +25 -13
  35. package/core/server/host/csp-nonce-metadata.ts +1 -1
  36. package/core/server/host/published-page-assets.ts +30 -0
  37. package/core/server/host/soma-page-compile.ts +1 -1
  38. package/core/server/index.ts +2 -2
  39. package/core/server/registry/page-registry-store.ts +1 -1
  40. package/core/shared/published-page-route.ts +61 -0
  41. package/core/shared/types/adaptive.types.ts +1 -1
  42. package/core/shared/types/data-config.types.ts +30 -2
  43. package/core/shared/types/scope-manifest.types.ts +11 -15
  44. package/core/shared/types/style-config.types.ts +4 -4
  45. package/dist/cli/soma.js +15 -2
  46. package/dist/core/index.cjs +171 -77
  47. package/dist/types/build/{v2 → blocks}/block-compile.d.ts +7 -7
  48. package/dist/types/build/{v2/soma-file-loader.d.ts → blocks/block-container.d.ts} +6 -6
  49. package/dist/types/build/{v2/migrate-v1.d.ts → blocks/migrate-flat.d.ts} +6 -6
  50. package/dist/types/client/component/contract-compat.d.ts +2 -2
  51. package/dist/types/client/component/example-blocks.d.ts +9 -0
  52. package/dist/types/client/infra/notify/DomNotifyService.d.ts +2 -1
  53. package/dist/types/client/infra/notify/INotifyTheme.d.ts +1 -1
  54. package/dist/types/client/parser/{v2 → blocks}/page-parser.d.ts +2 -2
  55. package/dist/types/client/parser/{v2 → blocks}/use-parser.d.ts +1 -1
  56. package/dist/types/client/parser/style-config-parser.d.ts +1 -1
  57. package/dist/types/client/registry/index.d.ts +1 -0
  58. package/dist/types/client/theme/theme-engine.d.ts +11 -0
  59. package/dist/types/index.d.ts +8 -7
  60. package/dist/types/server/host/published-page-assets.d.ts +20 -0
  61. package/dist/types/server/index.d.ts +1 -1
  62. package/dist/types/server/registry/page-registry-store.d.ts +1 -1
  63. package/dist/types/shared/published-page-route.d.ts +21 -0
  64. package/dist/types/shared/types/data-config.types.d.ts +18 -2
  65. package/dist/types/shared/types/scope-manifest.types.d.ts +11 -11
  66. package/dist/types/shared/types/style-config.types.d.ts +4 -4
  67. package/package.json +1 -6
  68. package/tsconfig.json +20 -7
  69. package/dist/types/client/component/example-v2.d.ts +0 -9
  70. package/postcss.config.js +0 -6
  71. package/tailwind.config.ts +0 -43
  72. /package/dist/types/build/{v2 → blocks}/block-loader.d.ts +0 -0
  73. /package/dist/types/build/{v2 → blocks}/html-index.d.ts +0 -0
  74. /package/dist/types/client/parser/{v2 → blocks}/namespace.d.ts +0 -0
@@ -1,11 +1,11 @@
1
- // v2 解析 · page 块(REQ-005 F2)。
1
+ // 块解析 · page 块(REQ-005 F2)。
2
2
  //
3
- // **产出目标是 v1 等价的 UiConfig**——这是两级编译架构的关键:
4
- // v2 只是更好写的书写层,编译后交给既有引擎,运行时零新增、零感知。
3
+ // **产出目标是 平铺等价的 UiConfig**——这是两级编译架构的关键:
4
+ // 块声明只是更好写的书写层,编译后交给既有引擎,运行时零新增、零感知。
5
5
  //
6
6
  // 两处形状转换:
7
7
  // 平铺 → 嵌套:`锚点.when` / `锚点.class` 后缀键合并成一个 ExtendedShowValue;
8
- // each → bind:`each: 路径 as 变量 [by 路径]` 还原成 v1 的 NestedShowMapping。
8
+ // each → bind:`each: 路径 as 变量 [by 路径]` 还原成 平铺的 NestedShowMapping。
9
9
  //
10
10
  // 唯一的缩进理由是列表作用域——when 组与插槽内容一律平铺,
11
11
  // 因为编译器手里有 HTML,结构不需要 YAML 再复述一遍。
@@ -18,17 +18,17 @@ import type {
18
18
  UiConfig,
19
19
  } from '../../../shared/types/ui-config.types';
20
20
  import type { OnChangeRule } from '../../../shared/types/watcher.types';
21
- import { SomaV2ParseError } from '../../../build/v2/soma-file-loader';
21
+ import { SomaBlockParseError } from '../../../build/blocks/block-container';
22
22
  import { buildBlockScope, expandPath, type BlockScope } from './namespace';
23
23
 
24
24
  const PAGE_KEYS = new Set([
25
25
  'domain', 'locale', 'ui', 'watch', 'event', 'data', 'adaptive', 'alias',
26
- // initProps:引擎启动前写入的初始值(v1 UiConfig 同名字段的直通)。
26
+ // initProps:引擎启动前写入的初始值(平铺 UiConfig 同名字段的直通)。
27
27
  //
28
- // v2 是照**手写页面**设计的——那里文案住 HTML、初值住 Domain,声明里不需要它。
29
- // 但 v2 产的是 v1 等价物,而生成链的页面把字面文案内联在 initProps 里
28
+ // 块声明是照**手写页面**设计的——那里文案住 HTML、初值住 Domain,声明里不需要它。
29
+ // 但块声明产的是平铺等价物,而生成链的页面把字面文案内联在 initProps 里
30
30
  // (模型出的是组织意图,没有 Domain 可写)。少了这个键,AI 产的页面
31
- // 就永远迈不过 v2 的门槛——不是"用不上 v2",是"表达不了"。
31
+ // 就永远迈不过块声明的门槛——不是"用不上块声明",是"表达不了"。
32
32
  'initProps',
33
33
  ]);
34
34
  /** 后缀键:平铺书写的高级绑定 */
@@ -36,9 +36,9 @@ const SUFFIXES = ['when', 'model', 'class'] as const;
36
36
  type Suffix = (typeof SUFFIXES)[number];
37
37
 
38
38
  export interface PageBlockAst {
39
- /** v1 等价 UiConfig:直接交既有编译管线 */
39
+ /** 平铺等价 UiConfig:直接交既有编译管线 */
40
40
  ui: UiConfig;
41
- /** 事件段原文(交 pipeline-parser,形状与 v1 _event.yaml 一致) */
41
+ /** 事件段原文(交 pipeline-parser,形状与平铺 _event.yaml 一致) */
42
42
  eventRaw: Record<string, unknown>;
43
43
  /** 数据段原文(页面级共享对象,交数据对象层) */
44
44
  dataRaw?: Record<string, unknown>;
@@ -58,7 +58,7 @@ export interface ParsePageInput {
58
58
  export function parsePageBlock(input: ParsePageInput): PageBlockAst {
59
59
  const { body } = input;
60
60
  const fail = (message: string): never => {
61
- throw new SomaV2ParseError(message, 'page');
61
+ throw new SomaBlockParseError(message, 'page');
62
62
  };
63
63
 
64
64
  for (const key of Object.keys(body)) {
@@ -101,7 +101,7 @@ export function parsePageBlock(input: ParsePageInput): PageBlockAst {
101
101
  if (typeof uiRaw !== 'object' || Array.isArray(uiRaw)) fail('ui 段必须是映射');
102
102
  parseShowLevel(uiRaw, show, scope, input, 'page');
103
103
 
104
- // ── watch 段:v1 onChange 换位 ─────────────────────────────────────────
104
+ // ── watch 段:平铺 onChange 换位 ─────────────────────────────────────────
105
105
  const bind: BindDeclaration = { obj: String(domain), var: 'page' };
106
106
  const watch = body.watch;
107
107
  if (watch !== undefined) {
@@ -155,7 +155,7 @@ function parseShowLevel(
155
155
  where: string,
156
156
  ): void {
157
157
  const fail = (message: string): never => {
158
- throw new SomaV2ParseError(message, 'page');
158
+ throw new SomaBlockParseError(message, 'page');
159
159
  };
160
160
 
161
161
  for (const [key, value] of Object.entries(raw)) {
@@ -217,7 +217,7 @@ function isEachBlock(value: unknown): boolean {
217
217
  && typeof (value as Record<string, unknown>).each === 'string';
218
218
  }
219
219
 
220
- /** `each: 路径 as 变量 [by 路径] [key 字段]` → v1 NestedShowMapping */
220
+ /** `each: 路径 as 变量 [by 路径] [key 字段]` → 平铺 NestedShowMapping */
221
221
  function parseEachBlock(
222
222
  block: Record<string, unknown>,
223
223
  scope: BlockScope,
@@ -225,7 +225,7 @@ function parseEachBlock(
225
225
  anchor: string,
226
226
  ): ShowValue {
227
227
  const fail = (message: string): never => {
228
- throw new SomaV2ParseError(message, 'page');
228
+ throw new SomaBlockParseError(message, 'page');
229
229
  };
230
230
  const raw = String(block.each);
231
231
  const match = /^(\S+)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)(?:\s+by\s+(\S+))?(?:\s+key\s+(\S+))?$/.exec(raw.trim());
@@ -1,14 +1,18 @@
1
- // v2 解析 · 组件块(REQ-005 F3)。
1
+ // 块解析 · 组件块(REQ-005 F3)。
2
2
  //
3
3
  // 一个实例 = 一个块,块体是该组件的**全部**:data(三通道 + 字段字典)、
4
4
  // ui(props / Row 体系)、event(actions 定义 + on 路由)。
5
5
  // 不自包含就是耦合——复杂场景一来三处拼装,复杂度没有地方搬进业务组件。
6
6
  //
7
- // 产出仍是 v1 等价物:props 进 UiConfig.show 的 ExtendedShowValue.props,
7
+ // 产出仍是 平铺等价物:props 进 UiConfig.show 的 ExtendedShowValue.props,
8
8
  // emit 路由进事件清单。soma-core 运行时对"块"一无所知,也不需要知道。
9
9
 
10
10
  import type { ExtendedShowValue } from '../../../shared/types/ui-config.types';
11
- import { SomaV2ParseError } from '../../../build/v2/soma-file-loader';
11
+ import { SomaBlockParseError } from '../../../build/blocks/block-container';
12
+ import {
13
+ SOMA_DATA_FIELD_TYPES,
14
+ SOMA_DATA_FIELD_TYPE_ALIASES,
15
+ } from '../../../shared/types/data-config.types';
12
16
  import {
13
17
  buildBlockScope,
14
18
  expandPath,
@@ -23,11 +27,10 @@ const ACTION_KEYS = new Set([
23
27
  'label', 'handler', 'change', 'confirm', 'permission', 'tone', 'when', 'disabled_reason',
24
28
  ]);
25
29
  const FIELD_KEYS = new Set(['name', 'type', 'values', 'permission', 'rules']);
26
- const FIELD_TYPES = new Set([
27
- 'text', 'int', 'number', 'money', 'date', 'enum', 'bool', 'percent',
28
- // progress 与 percent 同数据两种读法:前者出进度条,后者出文字(见 soma-ui 类型渲染表)
29
- 'progress',
30
- ]);
30
+ // 字段类型不在这里再抄一份:唯一真源是 shared/types/data-config.types.ts 的
31
+ // SomaDataFieldType。此前这里手写了一套 9 型,与数据对象层的 11 型已经漂开——
32
+ // `type: url` 在块声明里被拒收,`type: percent` 能过解析器却在 soma-ui 侧没有映射。
33
+ const FIELD_TYPES = new Set(SOMA_DATA_FIELD_TYPES);
31
34
 
32
35
  export interface DataObjectDecl {
33
36
  localName: string;
@@ -78,7 +81,7 @@ export interface UseBlockAst {
78
81
  /** emit 路由:emit 名 → Pipeline 表达式 */
79
82
  emitRoutes: Record<string, string>;
80
83
  scope: BlockScope;
81
- /** 供 v1 编译管线消费的 props 形态 */
84
+ /** 供既有编译管线消费的 props 形态 */
82
85
  toShowValue(): ExtendedShowValue;
83
86
  }
84
87
 
@@ -94,7 +97,7 @@ export interface ParseUseInput {
94
97
  export function parseUseBlock(input: ParseUseInput): UseBlockAst {
95
98
  const { blockId, body } = input;
96
99
  const fail = (message: string): never => {
97
- throw new SomaV2ParseError(message, blockId);
100
+ throw new SomaBlockParseError(message, blockId);
98
101
  };
99
102
 
100
103
  for (const key of Object.keys(body)) {
@@ -255,10 +258,13 @@ function parseField(
255
258
  fail(`字段 ${objectName}.${fieldName} 不支持键 "${key}"(可用:${[...FIELD_KEYS].join('/')})`);
256
259
  }
257
260
  }
258
- const type = String(field.type ?? '');
259
- if (!FIELD_TYPES.has(type)) {
261
+ const declaredType = String(field.type ?? '');
262
+ // 别名归一(number → float):两边都有存量声明,所以两种拼写都收,
263
+ // 但产物里只留规范名,下游不必再判第二种写法
264
+ const type = SOMA_DATA_FIELD_TYPE_ALIASES[declaredType] ?? declaredType;
265
+ if (!FIELD_TYPES.has(declaredType)) {
260
266
  fail(
261
- `字段 ${objectName}.${fieldName} 的 type "${type}" 非法`
267
+ `字段 ${objectName}.${fieldName} 的 type "${declaredType}" 非法`
262
268
  + `(封闭集:${[...FIELD_TYPES].join('/')})`,
263
269
  );
264
270
  }
@@ -356,7 +362,7 @@ function parseEventSection(
356
362
  return { actions, emitRoutes };
357
363
  }
358
364
 
359
- /** funcPath 不含点 → 自动补 page.(v1 onChange 既有先例) */
365
+ /** funcPath 不含点 → 自动补 page.(平铺 onChange 既有先例) */
360
366
  function withPageDefault(funcPath: string): string {
361
367
  return funcPath.includes('.') ? funcPath : `page.${funcPath}`;
362
368
  }
@@ -41,8 +41,8 @@ const VALID_TRIGGERS = new Set<TransitionTrigger>([
41
41
  * 解析层是页面进入运行时的**唯一必经通道**。代价是 breaking(存量违规页面报错),
42
42
  * 这是本需求记名接受的唯一破坏点。
43
43
  *
44
- * `\b` 词边界锚定是防误伤的关键:没有它,`border-gray-100` 会被 `order-` 命中,
45
- * `pointer-events-none` 会被 `p-` 逼近。锚定后二者都安全。
44
+ * `\b` 词边界锚定是防误伤的关键:没有它,普通业务类名可能被 utility 命名片段误判。
45
+ * 这里仅拦截常见的物理布局命名,不要求宿主使用任何特定 CSS 工具链。
46
46
  */
47
47
  const LAYOUT_CLASS_PATTERN =
48
48
  /\b(?:flex|grid|absolute|fixed|sticky|w-|h-|min-w-|max-w-|p[xytblre]?-|m[xytblre]?-|gap-|inset-|left-|right-|top-|bottom-|translate-|order-|col-|row-)\S*/;
@@ -120,7 +120,7 @@ function parseBase(raw: unknown, path: string): Record<string, string> {
120
120
  validateSomaId(somaId, `${path}.${somaId}`);
121
121
  if (typeof classes !== 'string') {
122
122
  throw new SomaStyleConfigError(
123
- `base 的值必须是 Tailwind 类名字符串,当前值: ${JSON.stringify(classes)}`,
123
+ `base 的值必须是 CSS 类名字符串,当前值: ${JSON.stringify(classes)}`,
124
124
  `${path}.${somaId}`,
125
125
  );
126
126
  }
@@ -167,7 +167,7 @@ function parseStateRule(raw: unknown, path: string): StyleStateRule {
167
167
  // apply
168
168
  if (!obj.apply || typeof obj.apply !== 'string') {
169
169
  throw new SomaStyleConfigError(
170
- `apply 必须是非空 Tailwind 类名字符串,当前值: ${JSON.stringify(obj.apply)}`,
170
+ `apply 必须是非空 CSS 类名字符串,当前值: ${JSON.stringify(obj.apply)}`,
171
171
  path,
172
172
  );
173
173
  }
@@ -228,7 +228,7 @@ function parseTransition(raw: unknown, somaId: string, path: string): StyleTrans
228
228
  // apply
229
229
  if (!obj.apply || typeof obj.apply !== 'string') {
230
230
  throw new SomaStyleConfigError(
231
- `apply 必须是非空 Tailwind 类名字符串,当前值: ${JSON.stringify(obj.apply)}`,
231
+ `apply 必须是非空 CSS 类名字符串,当前值: ${JSON.stringify(obj.apply)}`,
232
232
  path,
233
233
  );
234
234
  }
@@ -334,7 +334,7 @@ function parseTheme(raw: unknown, themeName: string, path: string): ThemeConfig
334
334
  // 直铺的 somaId → 类名覆盖
335
335
  if (typeof value !== 'string') {
336
336
  throw new SomaStyleConfigError(
337
- `主题基础覆盖的值必须是 Tailwind 类名字符串,当前值: ${JSON.stringify(value)}`,
337
+ `主题基础覆盖的值必须是 CSS 类名字符串,当前值: ${JSON.stringify(value)}`,
338
338
  `${path}.${key}`,
339
339
  );
340
340
  }
@@ -369,7 +369,7 @@ function parseThemes(raw: unknown, path: string): Record<string, ThemeConfig> {
369
369
  *
370
370
  * 校验规则:
371
371
  * - host 必须是非空字符串
372
- * - base 的值必须是纯 Tailwind 类名字符串
372
+ * - base 的值必须是纯 CSS 类名字符串;core 不解析也不编译具体类名
373
373
  * - states 的 condition 必须是纯属性路径,value 必须是基础类型
374
374
  * - transitions 的 trigger 必须是有效枚举值
375
375
  * - base / themes 命中布局类模式即失败;states / transitions 放行显隐对(F-06)
@@ -1,4 +1,4 @@
1
- // 值语言(DSL v2 · REQ-005 F4):全体系唯一的一条值规则。
1
+ // 值语言(块声明 · REQ-005 F4):全体系唯一的一条值规则。
2
2
  //
3
3
  // 值 := 段 ( "|" 管道调用 )*
4
4
  // 段 := 路径 | 数字 | 算术表达式(路径 · 数字 · + - * / · 括号 · 一元负号)
@@ -26,3 +26,11 @@ export {
26
26
  type PublishedPageRecord,
27
27
  type RenderPublishedPageOptions,
28
28
  } from './remote-page';
29
+ export {
30
+ PUBLISHED_PAGE_SLUG_PATTERN,
31
+ RESERVED_PUBLISHED_PAGE_SLUGS,
32
+ isPublishedPageSlug,
33
+ normalizePublishedPageSlug,
34
+ publishedPagePath,
35
+ publishedPageSlugFromPath,
36
+ } from '../../shared/published-page-route';
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // 为什么要有它:平台已经能"把声明变成页面",但**谁在管这些页面的死活**先前没人管——
4
4
  // 每个应用自己拿着句柄、自己记哪个槽位挂了什么、自己保证切走时卸干净。
5
- // ai-demo `/my-space` 就是手写这套簿记的样子:能跑,但每个应用都要重写一遍,
5
+ // 既有 Host 页面曾手写这套簿记:能跑,但每个应用都要重写一遍,
6
6
  // 而写漏一次 destroy 在 2GB 机器上就是内存不还。
7
7
  //
8
8
  // 边界(和注册中心分得很清):
@@ -55,10 +55,25 @@ const ABSENT_WHEN_EMPTY_ARIA = new Set([
55
55
  'aria-invalid',
56
56
  ]);
57
57
 
58
+ /**
59
+ * 空值会触发无意义资源请求的 URL 属性。
60
+ *
61
+ * 浏览器把 img/iframe 的 src="" 解释成当前文档 URL,既可能重复请求页面,
62
+ * 也会产生 resource error;srcset/poster 的空值同样不表达任何资源。
63
+ * 它们与 alt="" 这类有明确语义的内容属性不同,空值应等价于属性缺省。
64
+ */
65
+ const ABSENT_WHEN_EMPTY_RESOURCE = new Set([
66
+ 'src',
67
+ 'srcset',
68
+ 'poster',
69
+ ]);
70
+
58
71
  /** 空串是否意味着「删除该属性」 */
59
72
  export function isAbsentWhenEmpty(attrName: string): boolean {
60
73
  const name = attrName.toLowerCase();
61
- return BOOLEAN_ATTRS.has(name) || ABSENT_WHEN_EMPTY_ARIA.has(name);
74
+ return BOOLEAN_ATTRS.has(name)
75
+ || ABSENT_WHEN_EMPTY_ARIA.has(name)
76
+ || ABSENT_WHEN_EMPTY_RESOURCE.has(name);
62
77
  }
63
78
 
64
79
  /**
@@ -54,6 +54,17 @@ export interface SomaThemeInput {
54
54
  dark?: boolean;
55
55
  /** 逐令牌精调通道:最后合并进 cssVars 与 darkCssVars,优先级最高(亮暗同时生效) */
56
56
  overrides?: Record<string, string>;
57
+ /**
58
+ * 暗色专属精调:只并进 darkCssVars,在 `overrides` **之后**合并(同键胜出)。
59
+ *
60
+ * 为什么需要它:`overrides` 一份表同时盖亮暗两套,等于「一个令牌只能有一个值」。
61
+ * 后果不是理论问题——`soma-ui/src/daisy-presets.ts` 里 daisyLight / daisyDark 因此
62
+ * 被迫拆成两套完整独立预设,而 `ThemeScope` 的 `mode: 'system'` 只认一个预设名,
63
+ * 于是 35 套 daisy 主题的跟随系统亮暗**全部失效**。
64
+ *
65
+ * 缺省不给 = 行为与之前字节级一致(不影响任何既有预设)。
66
+ */
67
+ darkOverrides?: Record<string, string>;
57
68
  }
58
69
 
59
70
  export interface SomaThemeMeta {
@@ -1007,13 +1018,22 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
1007
1018
  };
1008
1019
 
1009
1020
  // ⑥ 用户逐令牌精调通道:最后合并;语义色背景保留,低于 AA 的配对前景随后自动校正
1021
+ //
1022
+ // 亮暗分列:`overrides` 是两套共用的基线,`darkOverrides` 只盖暗色且排在它之后。
1023
+ // 不给 darkOverrides 时 darkMerged === input.overrides,行为与分列之前完全一致。
1024
+ const darkMerged = input.darkOverrides
1025
+ ? { ...input.overrides, ...input.darkOverrides }
1026
+ : input.overrides;
1010
1027
  if (input.overrides) {
1011
1028
  Object.assign(cssVars, input.overrides);
1012
- Object.assign(darkCssVars, input.overrides);
1029
+ }
1030
+ if (darkMerged) {
1031
+ Object.assign(darkCssVars, darkMerged);
1013
1032
  }
1014
1033
  // ⑥.1 淡底跟随实心色的覆盖(否则 daisy 那 35 套预设的徽标底与字来自两个色系)
1034
+ // 暗色侧要吃合并后的表,否则 darkOverrides 换掉的实心色配不上淡底
1015
1035
  syncSoftWithOverrides(cssVars, input.overrides);
1016
- syncSoftWithOverrides(darkCssVars, input.overrides);
1036
+ syncSoftWithOverrides(darkCssVars, darkMerged);
1017
1037
  enforceContrastPairs(cssVars);
1018
1038
  enforceContrastPairs(darkCssVars);
1019
1039
  // ⑥.2 淡底前景:必须在 overrides 之后算,AA 保障的是**最终生效**的那套底与那套色
@@ -1022,20 +1042,28 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
1022
1042
 
1023
1043
  // S7′ 场景颜色:与 ⑥.1/⑥.2 同一条纪律——吃最终变量表,不吃派生中途的值
1024
1044
  /** 主色被 overrides 换过时按新主色重建色阶——光球才不会与表面分属两个色系 */
1025
- const rescale = input.overrides?.['--soma-c-primary']
1026
- ? (primaryHex: string): Record<string, string> => {
1027
- const p = hexToOklch(primaryHex);
1028
- const rebuilt: Record<string, string> = {};
1029
- STEPS.forEach((step, i) => {
1030
- rebuilt[step] = oklchToHex({
1031
- l: LIGHTNESS[i], c: Math.max(p.c, 0.02) * CHROMA_CURVE[i], h: p.h,
1045
+ const makeRescale = (
1046
+ tokens: Record<string, string> | undefined,
1047
+ ): ((primaryHex: string) => Record<string, string>) | null => (
1048
+ tokens?.['--soma-c-primary']
1049
+ ? (primaryHex: string): Record<string, string> => {
1050
+ const p = hexToOklch(primaryHex);
1051
+ const rebuilt: Record<string, string> = {};
1052
+ STEPS.forEach((step, i) => {
1053
+ rebuilt[step] = oklchToHex({
1054
+ l: LIGHTNESS[i], c: Math.max(p.c, 0.02) * CHROMA_CURVE[i], h: p.h,
1055
+ });
1032
1056
  });
1033
- });
1034
- return rebuilt;
1035
- }
1036
- : null;
1057
+ return rebuilt;
1058
+ }
1059
+ : null
1060
+ );
1061
+ // 亮暗各按自己那套最终 overrides 判定要不要重建色阶:
1062
+ // 只在 darkOverrides 里换主色时,亮色侧不该跟着重建。
1063
+ const rescale = makeRescale(input.overrides);
1064
+ const darkRescale = makeRescale(darkMerged);
1037
1065
  Object.assign(cssVars, sceneColorTokens(cssVars, axes, params.fieldAlphas, hexWithAlpha, scale, rescale));
1038
- Object.assign(darkCssVars, sceneColorTokens(darkCssVars, axes, params.fieldAlphas, hexWithAlpha, scale, rescale));
1066
+ Object.assign(darkCssVars, sceneColorTokens(darkCssVars, axes, params.fieldAlphas, hexWithAlpha, scale, darkRescale));
1039
1067
 
1040
1068
  return {
1041
1069
  scale,
@@ -1,6 +1,6 @@
1
1
  // core/client/typography/typography-base.ts — 中文排版基线(F-05 / 契约 C2)
2
2
  //
3
- // 归属理由(arch/契约与边界.md §1):不用组件库的纯声明页面也应具备中文排版基线,
3
+ // 归属理由(soma-core/doc/空间体系契约与边界.md §1):不用组件库的纯声明页面也应具备中文排版基线,
4
4
  // 所以它是地基能力而不是组件资产。soma-ui 基座**引用而不复制**这个常量——
5
5
  // 复制即产生第二份事实,G6 同源门判红。
6
6
  //
package/core/index.ts CHANGED
@@ -58,6 +58,12 @@ export type {
58
58
  SomaDataFieldPermission,
59
59
  SomaDataDicts,
60
60
  } from './shared/types/data-config.types';
61
+ // 字段类型的唯一真源(值导出):块解析器与 soma-ui 的双态映射表都消费它,
62
+ // 消费方不得再手抄一份清单——四份手写副本里漏改一份,就是「一处合法、一处静默按 text 渲染」。
63
+ export {
64
+ SOMA_DATA_FIELD_TYPES,
65
+ SOMA_DATA_FIELD_TYPE_ALIASES,
66
+ } from './shared/types/data-config.types';
61
67
  export {
62
68
  deriveTheme,
63
69
  applyTheme,
@@ -235,6 +241,12 @@ export {
235
241
  type RegisterDeclarationOptions,
236
242
  type RenderPublishedPageOptions,
237
243
  type SomaPageLifecycleOptions,
244
+ PUBLISHED_PAGE_SLUG_PATTERN,
245
+ RESERVED_PUBLISHED_PAGE_SLUGS,
246
+ isPublishedPageSlug,
247
+ normalizePublishedPageSlug,
248
+ publishedPagePath,
249
+ publishedPageSlugFromPath,
238
250
  } from './client/registry/index';
239
251
 
240
252
  // 组件包(业务拓展组件库):合成、查重、目录、自检。
@@ -252,8 +264,8 @@ export {
252
264
  } from './client/component/component-pack';
253
265
  export { verifyComponentPack, type VerifyPackOptions } from './client/component/verify-pack';
254
266
 
255
- // 值语言(DSL v2 · REQ-005 F4):算术六词元 + 管道链的唯一值规则。
256
- // 规格见 doc/需求/REQ-005-DSL体验强化/UI业务组件DSL规格书.md §7;
267
+ // 值语言(REQ-005 F4):算术六词元 + 管道链的唯一值规则。
268
+ // 规格见 soma-core/doc/soma DSL 语法全书 v2.md §7;
257
269
  // v2 其余部件未施工前,本模块可被 v1 路径独立复用(纯函数、无依赖)。
258
270
  export {
259
271
  parseValueSegment,
@@ -272,35 +284,35 @@ export {
272
284
  // SOMA DSL 容器与块装载(外置块发现在 soma-core/server)。
273
285
  export {
274
286
  loadSomaFile,
275
- SomaV2ParseError,
287
+ SomaBlockParseError,
276
288
  PAGE_BLOCK_ID,
277
289
  type RawBlock,
278
290
  type SomaFileLoadInput,
279
- } from './build/v2/soma-file-loader';
291
+ } from './build/blocks/block-container';
280
292
  export {
281
293
  buildHtmlAnchorIndex,
282
294
  type HtmlAnchorIndex,
283
295
  type HtmlAnchorInfo,
284
- } from './build/v2/html-index';
285
- // 资产级入口:拿着原始 v2 声明的一方(服务端装载层/测试替身/预览器)先编译,
296
+ } from './build/blocks/html-index';
297
+ // 资产级入口:拿着原始块声明的一方(服务端装载层/测试替身/预览器)先编译,
286
298
  // 再把 v1 等价产物交给 mount——运行时只认 v1(两级编译、单一运行时)。
287
299
  export { compilePageAssets } from './build/compiler/page-assets';
288
300
  export {
289
- compileSomaV2,
290
- type CompiledSomaV2,
291
- type CompileSomaV2Input,
292
- } from './build/v2/block-compile';
301
+ compileSomaBlocks,
302
+ type CompiledSomaBlocks,
303
+ type CompileSomaBlocksInput,
304
+ } from './build/blocks/block-compile';
293
305
  export {
294
306
  parsePageBlock,
295
307
  type PageBlockAst,
296
- } from './client/parser/v2/page-parser';
308
+ } from './client/parser/blocks/page-parser';
297
309
  export {
298
310
  parseUseBlock,
299
311
  type UseBlockAst,
300
312
  type DataObjectDecl,
301
313
  type FieldDecl,
302
314
  type ActionDecl,
303
- } from './client/parser/v2/use-parser';
315
+ } from './client/parser/blocks/use-parser';
304
316
  export {
305
317
  buildBlockScope,
306
318
  resolvePath,
@@ -309,7 +321,7 @@ export {
309
321
  scopeHasVar,
310
322
  SomaScopeError,
311
323
  type BlockScope,
312
- } from './client/parser/v2/namespace';
324
+ } from './client/parser/blocks/namespace';
313
325
  export {
314
326
  checkOverrideCompat,
315
327
  type ContractCompatIssue,
@@ -6,7 +6,7 @@
6
6
  // 阶段直接给它打 nonce,所以必须留一个客户端读得到的落点——`<meta name="csp-nonce">`。
7
7
  //
8
8
  // 为什么单独成模块而不是写死在 app/layout.tsx 里:
9
- // 1. 官方 Host 的 layout 会 `import './globals.css'`(走 tailwind/postcss),把逻辑关在
9
+ // 1. 官方 Host 的 layout 会 `import './globals.css'`,把逻辑关在
10
10
  // 里面就没法单测;
11
11
  // 2. 自己写 layout 的宿主也需要这段能力,抄一遍就会抄漏「CSP 关时别读请求头」这条。
12
12
 
@@ -0,0 +1,30 @@
1
+ // 发布页路径接线:Registry canonical 声明 → 服务端内存编译 → Host 运行时资产。
2
+
3
+ import { compilePageDeclaration } from '../../build/compiler/page-declaration-compiler';
4
+ import { publishedPageSlugFromPath } from '../../shared/published-page-route';
5
+ import { getPageRegistryRepository } from '../registry/page-registry-repository';
6
+
7
+ /** Registry `myworkspace` 的正式地址是 `/myworkspace`;兼容读取旧 `/pages/myworkspace`。 */
8
+ export const registryPageNameFromPath = publishedPageSlugFromPath;
9
+
10
+ /** Registry 声明只在服务端编译,浏览器收到的仍是既有运行时资产。 */
11
+ export async function loadPublishedRegistryPageAssets(pagePath: string) {
12
+ const name = registryPageNameFromPath(pagePath);
13
+ if (!name) return null;
14
+
15
+ const record = await getPageRegistryRepository().get(name);
16
+ const compiled = compilePageDeclaration(record.declaration);
17
+ return {
18
+ base: record.name,
19
+ sourceType: 'registry' as const,
20
+ sourcePackage: null,
21
+ html: record.declaration.html,
22
+ ui: compiled.runtimeAssets.uiYaml,
23
+ event: compiled.runtimeAssets.eventYaml,
24
+ styleYaml: '',
25
+ ...(compiled.runtimeAssets.dataYaml ? { dataYaml: compiled.runtimeAssets.dataYaml } : {}),
26
+ localeYaml: '',
27
+ appConfigYaml: '',
28
+ registryPage: { name: record.name, version: record.version },
29
+ };
30
+ }
@@ -1,7 +1,7 @@
1
1
  // SOMA DSL 页面接入运行路径:源声明只在服务端编译,浏览器只消费运行时资产。
2
2
 
3
3
  import { compilePageDeclaration } from '../../build/compiler/page-declaration-compiler';
4
- import { loadExternalBlocks } from '../../build/v2/block-loader';
4
+ import { loadExternalBlocks } from '../../build/blocks/block-loader';
5
5
 
6
6
  export interface SomaPageCompileResult {
7
7
  ui: string;
@@ -70,12 +70,12 @@ export {
70
70
  type LoadPackFromDirOptions,
71
71
  } from '../build/component/pack-from-dir';
72
72
 
73
- // DSL v2 容器(REQ-005):开关探测、HTML 锚点索引、块装载、外置块发现。
73
+ // 块声明容器(REQ-005):开关探测、HTML 锚点索引、块装载、外置块发现。
74
74
  // 用 node:fs 的只有 block-loader,其余纯函数(可在浏览器侧复用)。
75
75
  export {
76
76
  loadExternalBlocks,
77
77
  blocksDirOf,
78
- } from '../build/v2/block-loader';
78
+ } from '../build/blocks/block-loader';
79
79
 
80
80
  export {
81
81
  setSomaDb,
@@ -47,7 +47,7 @@ export const PAGE_APP_PATTERN = /^[a-z0-9-]{1,32}$/;
47
47
  * notes 塞满一样会撑爆响应。
48
48
  *
49
49
  * 128KiB 这个数的依据(实测,2026-08-12):
50
- * - 仓库里**最大的真实声明**是 ai-demo 的 gallery 页(html 13,826 + ui 4,407 + event 1,805)
50
+ * - 历史基线中**最大的真实 Host 声明**是 gallery 页(html 13,826 + ui 4,407 + event 1,805)
51
51
  * = 20,038 字节。128KiB / 20,038 ≈ 6.5×,即人手写得最复杂的整站页面还能再翻 6.5 倍。
52
52
  * - 声明仓库里 119 份 AI 生成版本的实测分布:中位 1,777 / p90 2,305 / 最大 2,995 字节,
53
53
  * 离上限有 43 倍余量——正常生成永远撞不到这条线。
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Registry 发布页的公开 URL 契约。
3
+ *
4
+ * 页面名就是根路径 slug:Registry `myworkspace` 对应 `/myworkspace`。
5
+ * `/pages/<name>` 仅保留为存量链接兼容入口,新发布结果不再生成该前缀。
6
+ */
7
+
8
+ export const PUBLISHED_PAGE_SLUG_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
9
+
10
+ /** Next/SOMA 内部入口不能被 Registry 根路径页面占用。 */
11
+ export const RESERVED_PUBLISHED_PAGE_SLUGS = new Set([
12
+ 'api',
13
+ 'soma',
14
+ 'pages',
15
+ 'workbench',
16
+ '_next',
17
+ ]);
18
+
19
+ export function isPublishedPageSlug(value: unknown): value is string {
20
+ return typeof value === 'string'
21
+ && PUBLISHED_PAGE_SLUG_PATTERN.test(value)
22
+ && !RESERVED_PUBLISHED_PAGE_SLUGS.has(value);
23
+ }
24
+
25
+ /**
26
+ * 归一化模型或用户给出的候选路径。只做机械变换,不擅自翻译中文;
27
+ * 语义翻译由生成模型负责,调用方可在 null 时提供确定性兜底。
28
+ */
29
+ export function normalizePublishedPageSlug(value: unknown): string | null {
30
+ if (typeof value !== 'string') return null;
31
+ const normalized = value
32
+ .trim()
33
+ .toLowerCase()
34
+ .replace(/^\/+|\/+$/g, '')
35
+ .replace(/[\s_]+/g, '-')
36
+ .replace(/[^a-z0-9-]/g, '')
37
+ .replace(/-+/g, '-')
38
+ .replace(/^-|-$/g, '')
39
+ .slice(0, 64)
40
+ .replace(/-$/g, '');
41
+ return isPublishedPageSlug(normalized) ? normalized : null;
42
+ }
43
+
44
+ export function publishedPagePath(slug: string): string {
45
+ if (!isPublishedPageSlug(slug)) {
46
+ throw new Error(`Invalid published page slug: ${slug}`);
47
+ }
48
+ return `/${slug}`;
49
+ }
50
+
51
+ /**
52
+ * 根路径是正式入口;旧 `/pages/<name>` 继续可读,避免已分享链接立即失效。
53
+ * 只接受单段路径,子路径仍交给 Host 文件页处理。
54
+ */
55
+ export function publishedPageSlugFromPath(pagePath: string): string | null {
56
+ const legacy = pagePath.match(/^\/pages\/([^/]+)$/)?.[1];
57
+ if (legacy && isPublishedPageSlug(legacy)) return legacy;
58
+
59
+ const root = pagePath.match(/^\/([^/]+)$/)?.[1];
60
+ return root && isPublishedPageSlug(root) ? root : null;
61
+ }
@@ -1,6 +1,6 @@
1
1
  // core/shared/types/adaptive.types.ts — 降级阶梯声明类型与词汇注册契约(F-07 / F-09)
2
2
  //
3
- // 边界(arch/契约与边界.md C4 C5 与禁止边 2):
3
+ // 边界(soma-core/doc/空间体系契约与边界.md C4 C5 与禁止边 2):
4
4
  // 语法归语言(core),级语义词汇归组件(soma-ui)。
5
5
  // 本文件只定义"形状",不定义任何级的含义——core 不内置、也不 import 任何级语义;
6
6
  // 词汇一律由宿主 bootstrap 注入。这是"core 对几何档位零认知"不变量在类型层的落点。