soma-core 1.5.0 → 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.
@@ -103,7 +103,20 @@ export function emitLayoutCss(plan: SomaLayoutPlan, options: EmitOptions): strin
103
103
  return lines.join('\n');
104
104
  };
105
105
 
106
- const blocks: string[] = [containerRule, ruleFor(0)];
106
+ // 交叉轴是缺省的 stretch 时,并排的宿主已被拉到行高,但宿主里的组件根节点仍按内容高——
107
+ // 两张卡并排一高一矮,矮的下面空出一截(2026-09-14 实测:生成页授权面板 116px 对聊天台 352px)。
108
+ // 让非 hug 子项的宿主变成纵向 flex、组件根节点吃满剩余高度,并排表面即等高。
109
+ // hug 子项(按钮、徽标)不拉伸:把一枚按钮拉成整行高是错的。显式声明了交叉轴对齐时尊重作者。
110
+ const stretchCross = align === undefined || ALIGN_CROSS[align] === undefined;
111
+ const fillTargets = stretchCross
112
+ ? Object.entries(plan.constraint.nodes).filter(([, node]) => node.sizing !== 'hug').map(([name]) => selectorOf(name))
113
+ : [];
114
+ const fillRule = fillTargets.length === 0
115
+ ? null
116
+ : `${fillTargets.join(',\n')} { display: flex; flex-direction: column; }\n`
117
+ + `${fillTargets.map((selector) => `${selector} > *`).join(',\n')} { flex: 1 1 auto; }`;
118
+
119
+ const blocks: string[] = [containerRule, ...(fillRule === null ? [] : [fillRule]), ruleFor(0)];
107
120
  for (let index = 1; index < plan.solutions.length; index += 1) {
108
121
  const [, rem] = CONTAINER_STEPS[index];
109
122
  const body = ruleFor(index);
@@ -71,9 +71,14 @@ export class SomaComponentExpander {
71
71
  this.scopeAnchors(host, scopeId);
72
72
 
73
73
  // 4. 插槽投影:出口替换为页面内容(页面锚点保持 data-soma-id,归页面作用域)
74
- const outlets = Array.from(
75
- host.querySelectorAll<HTMLElement>(`[${SOMA_SLOT_OUTLET_ATTR}]`),
76
- );
74
+ // A composite component may place another slotted component in its own
75
+ // template. `querySelectorAll` does not cross HTMLTemplateElement
76
+ // boundaries, so only looking at the live DOM misses the child's outlet;
77
+ // the parent slot is then reported as an unknown slot even though the
78
+ // child is the intended projection target (for example ThemeScope).
79
+ // Walk template contents as well, while keeping the actual projection
80
+ // order stable for multiple outlets.
81
+ const outlets = this.collectSlotOutlets(host);
77
82
  for (const outlet of outlets) {
78
83
  const slotName = outlet.getAttribute(SOMA_SLOT_OUTLET_ATTR)!;
79
84
  const content = slotContent.get(slotName);
@@ -116,4 +121,14 @@ export class SomaComponentExpander {
116
121
  this.scopeAnchors(tpl.content, scopeId);
117
122
  });
118
123
  }
124
+
125
+ private collectSlotOutlets(root: ParentNode): HTMLElement[] {
126
+ const outlets = Array.from(
127
+ root.querySelectorAll<HTMLElement>(`[${SOMA_SLOT_OUTLET_ATTR}]`),
128
+ );
129
+ for (const template of Array.from(root.querySelectorAll<HTMLTemplateElement>('template'))) {
130
+ outlets.push(...this.collectSlotOutlets(template.content));
131
+ }
132
+ return outlets;
133
+ }
119
134
  }
@@ -139,6 +139,10 @@ export class SomaComponentManager {
139
139
  }
140
140
  const def = this.registry.get(name);
141
141
  this.expander.expand(host, def);
142
+ // 组合组件的子组件也必须在页面契约校验前展开。否则子组件模板
143
+ // 里的 data-soma-host 仍封在 template.content 中,页面会误报
144
+ // "缺少 data-soma-host 边界";实例挂载阶段再展开已经太晚。
145
+ this.expandNestedTemplates(host);
142
146
  this.staticDecls.push({
143
147
  host,
144
148
  instanceId,
@@ -331,6 +331,9 @@ function verifyStyleDiscipline(pack: SomaComponentPack): string[] {
331
331
  + '裸色值会让换肤对这个组件失效,而且不报错',
332
332
  );
333
333
  }
334
+ for (const problem of colorRolePairing(css)) {
335
+ issues.push(`[配色] ${label} ${problem}`);
336
+ }
334
337
  for (const property of physicalDirections(css)) {
335
338
  issues.push(
336
339
  `[RTL] ${label} 使用物理方向属性 ${property}——请改用逻辑属性`
@@ -342,6 +345,46 @@ function verifyStyleDiscipline(pack: SomaComponentPack): string[] {
342
345
  return issues;
343
346
  }
344
347
 
348
+ const TONE = '(primary|secondary|accent|neutral|info|success|warning|danger)';
349
+
350
+ /**
351
+ * 颜色角色配对:令牌化了仍可能不可读——配对错了同样"不报错但坏掉"。
352
+ *
353
+ * 与 soma-ui 自身的配色闸门同一套判据(《soma 视觉与空间规范》§11):
354
+ * ① `--soma-c-X` 是填充色,不能当文字色(46 套出厂预设下当字最差 1.01:1),彩色文字用 `-on-soft`;
355
+ * ② 实心底 `--soma-c-X` 上写了字色,就必须是同语气 `-fg`;
356
+ * ③ 淡底 `--soma-c-X-soft` 上写了字色,不能是 `--soma-c-X` 或 `-fg`(引擎只对 `-on-soft` 承诺 AA);
357
+ * ④ 渐变不跨语气(primary→accent 在功能配色下是蓝→橙,读起来像两种状态)。
358
+ * 只看同一条规则内的配对;字色压在祖先的底上这类跨规则关系静态看不到,不在准入线内。
359
+ */
360
+ function colorRolePairing(css: string): string[] {
361
+ const found = new Set<string>();
362
+ const flat = css.replace(/\/\*[\s\S]*?\*\//g, '');
363
+ for (const match of flat.matchAll(/([^{}@]+)\{([^{}]*)\}/g)) {
364
+ const selector = match[1].trim().slice(0, 60);
365
+ const body = match[2];
366
+ const color = /(?:^|;)\s*color\s*:\s*([^;]+)/.exec(body)?.[1]?.trim() ?? '';
367
+ const fillAsText = new RegExp(`^var\\(--soma-c-${TONE}\\s*[,)]`).exec(color);
368
+ if (fillAsText) {
369
+ found.add(`${selector} 把填充色 --soma-c-${fillAsText[1]} 当文字色——彩色文字用 var(--soma-c-${fillAsText[1]}-on-soft, 回退)`);
370
+ }
371
+ const solid = new RegExp(`background(?:-color)?\\s*:\\s*var\\(--soma-c-${TONE}\\s*[,)]`).exec(body);
372
+ if (solid && color && !/^(inherit|currentColor|transparent)$/.test(color)
373
+ && !new RegExp(`^var\\(--soma-(c-${solid[1]}-fg|ui-tone-fg)\\b`).test(color)) {
374
+ found.add(`${selector} 实心底 --soma-c-${solid[1]} 上的字色必须是 var(--soma-c-${solid[1]}-fg, 回退)`);
375
+ }
376
+ const soft = new RegExp(`background(?:-color)?\\s*:\\s*var\\(--soma-c-${TONE}-soft\\s*[,)]`).exec(body);
377
+ if (soft && new RegExp(`^var\\(--soma-c-${soft[1]}(-fg)?\\s*[,)]`).test(color)) {
378
+ found.add(`${selector} 淡底 --soma-c-${soft[1]}-soft 上的字色必须是 var(--soma-c-${soft[1]}-on-soft, 回退)`);
379
+ }
380
+ for (const gradient of body.matchAll(/gradient\(([^;]+)/g)) {
381
+ const tones = new Set([...gradient[1].matchAll(new RegExp(`--soma-c-${TONE}\\b`, 'g'))].map((item) => item[1]));
382
+ if (tones.size > 1) found.add(`${selector} 渐变混用了 ${[...tones].join(' / ')} 两种语气——同色相用 color-mix 调明度`);
383
+ }
384
+ }
385
+ return [...found];
386
+ }
387
+
345
388
  /** 收集裸色值:var(--x, #fff) 的回退位不算 */
346
389
  function nakedColors(css: string): string[] {
347
390
  const found = new Set<string>();
@@ -307,6 +307,61 @@ function enforceContrastPairs(vars: Record<string, string>): void {
307
307
  }
308
308
  }
309
309
 
310
+ // ─── 可读文字 × 中性表面:配色规格的令牌层保障 ─────────
311
+
312
+ /**
313
+ * 页面上**读得到的字**用的五枚文字令牌。弱化(muted)与次级(secondary)同样是要读的字——
314
+ * 卡片副标题、指标标签、定义列表 dt 全靠它们——AA 底线不因"弱化"降级。
315
+ * 禁用文字(text-disabled / control-fg-disabled)按 WCAG 1.4.3 豁免,不在此列。
316
+ */
317
+ const READABLE_TEXT_KEYS = [
318
+ '--soma-text-strong',
319
+ '--soma-text-primary',
320
+ '--soma-text-secondary',
321
+ '--soma-text-muted',
322
+ '--soma-text-link',
323
+ ] as const;
324
+
325
+ /** 文字令牌可能直接落上的五张中性表面;取最坏的那张求解(组件不必关心自己在哪张底上)。 */
326
+ const NEUTRAL_SURFACE_KEYS = [
327
+ '--soma-bg-page',
328
+ '--soma-bg-container',
329
+ '--soma-surface-card',
330
+ '--soma-bg-elevated',
331
+ '--soma-bg-hover',
332
+ ] as const;
333
+
334
+ const READABLE_TEXT_TARGET = 4.52;
335
+
336
+ /**
337
+ * 在**最终生效**的变量表上(overrides 合并之后)逐枚校正文字令牌:
338
+ * 对五张中性表面取最坏对比度,不达标就沿"远离表面"的方向按 0.02 明度步进,
339
+ * 停在刚好可读的最浅处——层级(strong > primary > secondary > muted)因此保留。
340
+ * 与 enforceContrastPairs 的区别:那边是实心语气底配黑白字,二选一即可;
341
+ * 这里是灰阶层级,直接换成黑/白会把四档墨色压成一档。
342
+ */
343
+ function enforceReadableText(vars: Record<string, string>): void {
344
+ const surfaces = NEUTRAL_SURFACE_KEYS
345
+ .map((key) => contrastColorToHex(vars[key] ?? ''))
346
+ .filter((hex): hex is string => hex !== null);
347
+ if (surfaces.length === 0) return;
348
+ const surfaceLum = Math.min(...surfaces.map((hex) => hexToOklch(hex).l));
349
+ for (const key of READABLE_TEXT_KEYS) {
350
+ let tone = contrastColorToHex(vars[key] ?? '');
351
+ if (!tone) continue;
352
+ const worst = (hex: string) => Math.min(...surfaces.map((surface) => contrastRatio(surface, hex)));
353
+ if (worst(tone) >= READABLE_TEXT_TARGET) continue;
354
+ const direction = hexToOklch(tone).l < surfaceLum ? -1 : 1;
355
+ for (let i = 0; i < 40 && worst(tone) < READABLE_TEXT_TARGET; i++) {
356
+ const cur = hexToOklch(tone);
357
+ const next = Math.max(0, Math.min(1, cur.l + direction * 0.02));
358
+ if (next === cur.l) break;
359
+ tone = oklchToHex({ ...cur, l: next });
360
+ }
361
+ vars[key] = tone;
362
+ }
363
+ }
364
+
310
365
  // ─── 淡底前景(-on-soft):AA 承诺覆盖到"淡底徽标"这一类配对 ─────────
311
366
 
312
367
  /** 有 `-soft` 淡底的八个语气;每个都配一枚 `-on-soft` 前景 */
@@ -419,7 +474,9 @@ function deriveOnSoftTokens(vars: Record<string, string>, dark: boolean): void {
419
474
  const backdropLuminance: number[] = [];
420
475
  for (const surface of surfaces) {
421
476
  const once = compositeOver(soft, surface);
422
- backdropLuminance.push(luminanceRgba(once), luminanceRgba(compositeOver(soft, once)));
477
+ // 素面本身也算一张底:`-on-soft` 是全库唯一的「彩色文字」令牌(配色规格 §11.2),
478
+ // 状态文案、选中项文字这类不带淡底的彩色字同样用它,AA 必须对素面同时成立
479
+ backdropLuminance.push(luminanceRgba(surface), luminanceRgba(once), luminanceRgba(compositeOver(soft, once)));
423
480
  }
424
481
  const worst = (hex: string) => {
425
482
  const fgLuminance = luminanceHex(hex);
@@ -1019,6 +1076,7 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
1019
1076
  textPrimary = oklchToHex({ ...cur, l: cur.l - 0.04 });
1020
1077
  }
1021
1078
 
1079
+
1022
1080
  // ── 材质令牌(REQ-006 G1)──────────────────────────────────────────────
1023
1081
  // 玻璃面是**半透明白 + 背后模糊**;高光边是它立体感的来源(少了边就成了糊面)。
1024
1082
  // 彩色投影取品牌色相:参照实现里投影是 rgba(37,99,235,.14) 而不是灰——
@@ -1280,6 +1338,8 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
1280
1338
  syncSoftWithOverrides(darkCssVars, darkMerged);
1281
1339
  enforceContrastPairs(cssVars);
1282
1340
  enforceContrastPairs(darkCssVars);
1341
+ enforceReadableText(cssVars);
1342
+ enforceReadableText(darkCssVars);
1283
1343
  // ⑥.2 淡底前景:必须在 overrides 之后算,AA 保障的是**最终生效**的那套底与那套色
1284
1344
  deriveOnSoftTokens(cssVars, false);
1285
1345
  deriveOnSoftTokens(darkCssVars, true);
package/core/index.ts CHANGED
@@ -362,7 +362,12 @@ export type { SomaHtmlSanitizer, SomaHtmlSanitizeResult } from './client/securit
362
362
  export type { SomaDiagnosticsSnapshot } from './client/diagnostics/SomaDiagnostics';
363
363
  export { matchGlobPath } from './client/engine/property-watcher';
364
364
  export { extractConfigFromDomainClass } from './client/parser/annotation-extractor';
365
- export { somaRollupPlugin } from './build/compiler/rollup-plugin-soma';
365
+ // Rollup is a build-time integration and must not be re-exported from the
366
+ // browser-facing root barrel. Keeping it here makes bundlers traverse the
367
+ // CJS precompiler (`soma-precompile.js`) while compiling every client that
368
+ // imports `soma-core`, which fails in a browser because `module` is absent.
369
+ // Consumers that need Rollup use the explicit `soma-core/compiler/rollup`
370
+ // entry instead.
366
371
  export { Page, Show, ShowList, Event } from './client/base/decorators';
367
372
  export { runAsync } from './client/base/runAsync';
368
373
  export type { AsyncStateHost } from './client/base/runAsync';
@@ -214,7 +214,6 @@ __export(index_exports, {
214
214
  setSomaHtmlSanitizer: () => setSomaHtmlSanitizer,
215
215
  somaEmits: () => somaEmits,
216
216
  somaFields: () => somaFields,
217
- somaRollupPlugin: () => somaRollupPlugin,
218
217
  somaSlots: () => somaSlots,
219
218
  startBootTimings: () => startBootTimings,
220
219
  themeRootAttributes: () => themeRootAttributes,
@@ -14321,9 +14320,7 @@ var SomaComponentExpander = class {
14321
14320
  }
14322
14321
  host.innerHTML = def.templateHtml;
14323
14322
  this.scopeAnchors(host, scopeId);
14324
- const outlets = Array.from(
14325
- host.querySelectorAll(`[${SOMA_SLOT_OUTLET_ATTR}]`)
14326
- );
14323
+ const outlets = this.collectSlotOutlets(host);
14327
14324
  for (const outlet of outlets) {
14328
14325
  const slotName = outlet.getAttribute(SOMA_SLOT_OUTLET_ATTR);
14329
14326
  const content = slotContent.get(slotName);
@@ -14361,6 +14358,15 @@ var SomaComponentExpander = class {
14361
14358
  this.scopeAnchors(tpl.content, scopeId);
14362
14359
  });
14363
14360
  }
14361
+ collectSlotOutlets(root) {
14362
+ const outlets = Array.from(
14363
+ root.querySelectorAll(`[${SOMA_SLOT_OUTLET_ATTR}]`)
14364
+ );
14365
+ for (const template of Array.from(root.querySelectorAll("template"))) {
14366
+ outlets.push(...this.collectSlotOutlets(template.content));
14367
+ }
14368
+ return outlets;
14369
+ }
14364
14370
  };
14365
14371
 
14366
14372
  // core/client/component/style-features.ts
@@ -14480,6 +14486,7 @@ var SomaComponentManager = class {
14480
14486
  }
14481
14487
  const def = this.registry.get(name);
14482
14488
  this.expander.expand(host, def);
14489
+ this.expandNestedTemplates(host);
14483
14490
  this.staticDecls.push({
14484
14491
  host,
14485
14492
  instanceId,
@@ -15640,6 +15647,40 @@ function enforceContrastPairs(vars) {
15640
15647
  vars[foregroundKey] = ["#000000", "#ffffff", "#111827"].sort((left, right) => contrastRatio(backgroundHex, right) - contrastRatio(backgroundHex, left))[0];
15641
15648
  }
15642
15649
  }
15650
+ var READABLE_TEXT_KEYS = [
15651
+ "--soma-text-strong",
15652
+ "--soma-text-primary",
15653
+ "--soma-text-secondary",
15654
+ "--soma-text-muted",
15655
+ "--soma-text-link"
15656
+ ];
15657
+ var NEUTRAL_SURFACE_KEYS = [
15658
+ "--soma-bg-page",
15659
+ "--soma-bg-container",
15660
+ "--soma-surface-card",
15661
+ "--soma-bg-elevated",
15662
+ "--soma-bg-hover"
15663
+ ];
15664
+ var READABLE_TEXT_TARGET = 4.52;
15665
+ function enforceReadableText(vars) {
15666
+ const surfaces = NEUTRAL_SURFACE_KEYS.map((key) => contrastColorToHex(vars[key] ?? "")).filter((hex) => hex !== null);
15667
+ if (surfaces.length === 0) return;
15668
+ const surfaceLum = Math.min(...surfaces.map((hex) => hexToOklch(hex).l));
15669
+ for (const key of READABLE_TEXT_KEYS) {
15670
+ let tone = contrastColorToHex(vars[key] ?? "");
15671
+ if (!tone) continue;
15672
+ const worst = (hex) => Math.min(...surfaces.map((surface) => contrastRatio(surface, hex)));
15673
+ if (worst(tone) >= READABLE_TEXT_TARGET) continue;
15674
+ const direction = hexToOklch(tone).l < surfaceLum ? -1 : 1;
15675
+ for (let i = 0; i < 40 && worst(tone) < READABLE_TEXT_TARGET; i++) {
15676
+ const cur = hexToOklch(tone);
15677
+ const next = Math.max(0, Math.min(1, cur.l + direction * 0.02));
15678
+ if (next === cur.l) break;
15679
+ tone = oklchToHex({ ...cur, l: next });
15680
+ }
15681
+ vars[key] = tone;
15682
+ }
15683
+ }
15643
15684
  var SOFT_TONES = ["primary", "secondary", "accent", "neutral", "info", "success", "warning", "danger"];
15644
15685
  var SOFT_AA_TARGET = 4.52;
15645
15686
  var SOFT_SURFACE_KEYS = [
@@ -15690,7 +15731,7 @@ function deriveOnSoftTokens(vars, dark) {
15690
15731
  const backdropLuminance = [];
15691
15732
  for (const surface of surfaces) {
15692
15733
  const once = compositeOver(soft, surface);
15693
- backdropLuminance.push(luminanceRgba(once), luminanceRgba(compositeOver(soft, once)));
15734
+ backdropLuminance.push(luminanceRgba(surface), luminanceRgba(once), luminanceRgba(compositeOver(soft, once)));
15694
15735
  }
15695
15736
  const worst = (hex) => {
15696
15737
  const fgLuminance = luminanceHex(hex);
@@ -16317,6 +16358,8 @@ function deriveTheme(input) {
16317
16358
  syncSoftWithOverrides(darkCssVars, darkMerged);
16318
16359
  enforceContrastPairs(cssVars);
16319
16360
  enforceContrastPairs(darkCssVars);
16361
+ enforceReadableText(cssVars);
16362
+ enforceReadableText(darkCssVars);
16320
16363
  deriveOnSoftTokens(cssVars, false);
16321
16364
  deriveOnSoftTokens(darkCssVars, true);
16322
16365
  const makeRescale = (tokens) => tokens?.["--soma-c-primary"] ? (primaryHex) => {
@@ -18797,181 +18840,6 @@ function rawTier(value, bounds) {
18797
18840
  return tier;
18798
18841
  }
18799
18842
 
18800
- // core/shared/block-errors.ts
18801
- var SomaBlockParseError = class extends Error {
18802
- constructor(message, blockId, line) {
18803
- const where = blockId ? `\uFF08\u5757: ${blockId}${line ? `\uFF0C\u7B2C ${line} \u884C` : ""}\uFF09` : "";
18804
- super(`[soma-core][\u5F15\u64CE] ${message}${where}`);
18805
- this.blockId = blockId;
18806
- this.line = line;
18807
- this.name = "SomaBlockParseError";
18808
- }
18809
- };
18810
-
18811
- // core/build/blocks/block-container.ts
18812
- var PAGE_BLOCK_ID = "page";
18813
- function stripSwitch(uiYamlRaw) {
18814
- const lines = uiYamlRaw.split("\n");
18815
- let openIndex = -1;
18816
- for (let i = 0; i < lines.length; i += 1) {
18817
- const text = lines[i].trim();
18818
- if (text === "" || text.startsWith("#")) continue;
18819
- if (text !== "{{") {
18820
- throw new SomaBlockParseError("\u5757\u58F0\u660E\u5FC5\u987B\u4EE5 `{{` \u5F00\u5173\u884C\u5F00\u5934");
18821
- }
18822
- openIndex = i;
18823
- break;
18824
- }
18825
- if (openIndex === -1) {
18826
- throw new SomaBlockParseError("\u6587\u4EF6\u4E3A\u7A7A\u6216\u53EA\u6709\u6CE8\u91CA\uFF0C\u627E\u4E0D\u5230 `{{` \u5F00\u5173\u884C");
18827
- }
18828
- let closeIndex = -1;
18829
- for (let i = lines.length - 1; i > openIndex; i -= 1) {
18830
- const text = lines[i].trim();
18831
- if (text === "") continue;
18832
- if (text !== "}}") {
18833
- throw new SomaBlockParseError("\u5757\u58F0\u660E\u5FC5\u987B\u4EE5 `}}` \u6536\u53E3\u884C\u7ED3\u5C3E\uFF08\u5F00\u5173\u6210\u5BF9\uFF0C\u6574\u6587\u4EF6\u4E00\u5BF9\uFF09");
18834
- }
18835
- closeIndex = i;
18836
- break;
18837
- }
18838
- if (closeIndex === -1) {
18839
- throw new SomaBlockParseError("`{{` \u5F00\u5173\u672A\u95ED\u5408\u2014\u2014\u7F3A\u5C11 `}}` \u6536\u53E3\u884C");
18840
- }
18841
- return {
18842
- inner: lines.slice(openIndex + 1, closeIndex).join("\n"),
18843
- offset: openIndex + 1
18844
- };
18845
- }
18846
- function parseSomaBlockContainer(uiYamlRaw) {
18847
- const { inner, offset } = stripSwitch(uiYamlRaw);
18848
- let doc;
18849
- try {
18850
- doc = yaml.load(inner);
18851
- } catch (error) {
18852
- throw new SomaBlockParseError(`YAML \u89E3\u6790\u5931\u8D25: ${error.message}`);
18853
- }
18854
- if (doc === null || doc === void 0) {
18855
- return { doc: {}, inner, offset };
18856
- }
18857
- if (typeof doc !== "object" || Array.isArray(doc)) {
18858
- throw new SomaBlockParseError("\u5F00\u5173\u5185\u5FC5\u987B\u662F\u5757\u6620\u5C04\uFF08\u9876\u5C42\u952E = \u5757 id\uFF09");
18859
- }
18860
- for (const [blockId, body] of Object.entries(doc)) {
18861
- if (body === null || body === void 0) {
18862
- throw new SomaBlockParseError("\u5757\u4F53\u4E3A\u7A7A\u2014\u2014\u4E0D\u9700\u8981\u58F0\u660E\u7684\u7EC4\u4EF6\u8BF7\u76F4\u63A5\u5220\u6389\u8FD9\u4E2A\u5757", blockId);
18863
- }
18864
- if (typeof body !== "object" || Array.isArray(body)) {
18865
- throw new SomaBlockParseError("\u5757\u4F53\u5FC5\u987B\u662F\u6620\u5C04\uFF08ui/data/event \u4E09\u6BB5\uFF09", blockId);
18866
- }
18867
- }
18868
- return { doc, inner, offset };
18869
- }
18870
- function loadSomaFile(input) {
18871
- const { doc, inner, offset } = parseSomaBlockContainer(input.uiYamlRaw);
18872
- if (Object.keys(doc).length === 0) return [];
18873
- const innerLines = inner.split("\n");
18874
- const lineOfKey = (key) => {
18875
- const index = innerLines.findIndex((line) => line.startsWith(`${key}:`));
18876
- return index === -1 ? offset : offset + index + 1;
18877
- };
18878
- const blocks = [];
18879
- const seen = /* @__PURE__ */ new Set();
18880
- for (const [blockId, body] of Object.entries(doc)) {
18881
- const line = lineOfKey(blockId);
18882
- assertBlockId(blockId, input.htmlIndex, line);
18883
- if (seen.has(blockId)) {
18884
- throw new SomaBlockParseError(`\u5757 "${blockId}" \u91CD\u590D\u58F0\u660E`, blockId, line);
18885
- }
18886
- if (body === null || body === void 0) {
18887
- throw new SomaBlockParseError("\u5757\u4F53\u4E3A\u7A7A\u2014\u2014\u4E0D\u9700\u8981\u58F0\u660E\u7684\u7EC4\u4EF6\u8BF7\u76F4\u63A5\u5220\u6389\u8FD9\u4E2A\u5757", blockId, line);
18888
- }
18889
- if (typeof body !== "object" || Array.isArray(body)) {
18890
- throw new SomaBlockParseError("\u5757\u4F53\u5FC5\u987B\u662F\u6620\u5C04\uFF08ui/data/event \u4E09\u6BB5\uFF09", blockId, line);
18891
- }
18892
- seen.add(blockId);
18893
- blocks.push({ blockId, body, line, source: "inline" });
18894
- }
18895
- for (const [blockId, raw2] of input.externalBlocks ?? /* @__PURE__ */ new Map()) {
18896
- assertBlockId(blockId, input.htmlIndex, 0);
18897
- if (seen.has(blockId)) {
18898
- throw new SomaBlockParseError(
18899
- `\u5757 "${blockId}" \u540C\u65F6\u5B58\u5728\u4E8E _ui.yaml \u4E0E blocks/${blockId}.yaml\u2014\u2014\u4E00\u4E2A\u5B9E\u4F8B\u53EA\u80FD\u6709\u4E00\u4E2A\u58F0\u660E\u5904`,
18900
- blockId
18901
- );
18902
- }
18903
- let body;
18904
- try {
18905
- body = yaml.load(raw2);
18906
- } catch (error) {
18907
- throw new SomaBlockParseError(
18908
- `\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u89E3\u6790\u5931\u8D25: ${error.message}`,
18909
- blockId
18910
- );
18911
- }
18912
- if (body === null || body === void 0) {
18913
- throw new SomaBlockParseError(`\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u4E3A\u7A7A`, blockId);
18914
- }
18915
- if (typeof body !== "object" || Array.isArray(body)) {
18916
- throw new SomaBlockParseError(`\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u5FC5\u987B\u662F\u6620\u5C04`, blockId);
18917
- }
18918
- seen.add(blockId);
18919
- blocks.push({ blockId, body, line: 1, source: "external" });
18920
- }
18921
- return blocks;
18922
- }
18923
- function assertBlockId(blockId, htmlIndex, line) {
18924
- if (blockId === PAGE_BLOCK_ID) return;
18925
- if (htmlIndex.instances.has(blockId)) return;
18926
- if (htmlIndex.anchors.has(blockId)) {
18927
- throw new SomaBlockParseError(
18928
- `"${blockId}" \u662F\u666E\u901A\u951A\u70B9\uFF0C\u4E0D\u80FD\u4F5C\u4E3A\u7EC4\u4EF6\u5757\u2014\u2014\u7EC4\u4EF6\u5757\u53EA\u80FD\u6302\u5728\u5E26 data-soma-component \u7684\u5B9E\u4F8B\u951A\u70B9\u4E0A\uFF1B\u666E\u901A\u951A\u70B9\u7684\u7ED1\u5B9A\u5199\u5728 page \u5757\u7684 ui: \u6BB5`,
18929
- blockId,
18930
- line
18931
- );
18932
- }
18933
- const known = [...htmlIndex.instances].slice(0, 8).join("\u3001");
18934
- throw new SomaBlockParseError(
18935
- `HTML \u91CC\u6CA1\u6709\u5B9E\u4F8B\u951A\u70B9 "${blockId}"${known ? `\uFF08\u73B0\u6709\u5B9E\u4F8B\uFF1A${known}\uFF09` : ""}`,
18936
- blockId,
18937
- line
18938
- );
18939
- }
18940
-
18941
- // core/build/compiler/soma-precompile.ts
18942
- function precompileUiModule(yamlStr) {
18943
- parseSomaBlockContainer(yamlStr);
18944
- return "null";
18945
- }
18946
- function precompileYaml(yamlStr) {
18947
- const obj = yaml.load(yamlStr);
18948
- return JSON.stringify(obj ?? {});
18949
- }
18950
-
18951
- // core/build/compiler/rollup-plugin-soma.ts
18952
- function somaRollupPlugin(options = {}) {
18953
- const uiSuffix = options.uiSuffix ?? "_ui.yaml";
18954
- return {
18955
- name: "rollup-plugin-soma",
18956
- transform(code, id) {
18957
- if (!id.endsWith(".yaml") && !id.endsWith(".yml")) {
18958
- return null;
18959
- }
18960
- try {
18961
- if (id.endsWith(uiSuffix)) {
18962
- return { code: `export default ${precompileUiModule(code)};`, map: { mappings: "" } };
18963
- }
18964
- if (/_((event)|(style)|(data))\.ya?ml$/.test(id)) {
18965
- throw new Error("\u9875\u9762\u4FA7\u8F66\u5DF2\u9000\u5F79\uFF1B\u4E8B\u4EF6\u3001\u6837\u5F0F\u72B6\u6001\u4E0E\u6570\u636E\u5BF9\u8C61\u5FC5\u987B\u5E76\u5165\u540C\u4E00\u4EFD SOMA DSL \u58F0\u660E");
18966
- }
18967
- return { code: `export default ${precompileYaml(code)};`, map: { mappings: "" } };
18968
- } catch (err) {
18969
- throw new Error(`[rollup-plugin-soma] Failed to compile ${id}: ${err}`);
18970
- }
18971
- }
18972
- };
18973
- }
18974
-
18975
18843
  // core/client/quality/SomaQualityRegistry.ts
18976
18844
  var SomaQualityRegistry = class _SomaQualityRegistry {
18977
18845
  static {
@@ -20277,6 +20145,9 @@ function verifyStyleDiscipline(pack) {
20277
20145
  `[\u989C\u8272] ${label} \u51FA\u73B0\u88F8\u8272\u503C ${color}\u2014\u2014\u989C\u8272\u53EA\u5141\u8BB8\u5728 var(--soma-*, \u56DE\u9000\u503C) \u7684\u56DE\u9000\u4F4D;\u88F8\u8272\u503C\u4F1A\u8BA9\u6362\u80A4\u5BF9\u8FD9\u4E2A\u7EC4\u4EF6\u5931\u6548,\u800C\u4E14\u4E0D\u62A5\u9519`
20278
20146
  );
20279
20147
  }
20148
+ for (const problem of colorRolePairing(css)) {
20149
+ issues.push(`[\u914D\u8272] ${label} ${problem}`);
20150
+ }
20280
20151
  for (const property of physicalDirections(css)) {
20281
20152
  issues.push(
20282
20153
  `[RTL] ${label} \u4F7F\u7528\u7269\u7406\u65B9\u5411\u5C5E\u6027 ${property}\u2014\u2014\u8BF7\u6539\u7528\u903B\u8F91\u5C5E\u6027(margin-inline-start / padding-inline-end / inset-inline-*);RTL \u4E0B\u7269\u7406\u65B9\u5411\u4F1A\u8BA9\u95F4\u8DDD\u8DD1\u5230\u53E6\u4E00\u8FB9,\u540C\u6837\u4E0D\u62A5\u9519\u3002\u786E\u5B9E\u5FC5\u8981\u5C31\u5728\u540C\u4E00\u884C\u5199 /* soma-allow-physical: \u7406\u7531 */`
@@ -20285,6 +20156,33 @@ function verifyStyleDiscipline(pack) {
20285
20156
  }
20286
20157
  return issues;
20287
20158
  }
20159
+ var TONE = "(primary|secondary|accent|neutral|info|success|warning|danger)";
20160
+ function colorRolePairing(css) {
20161
+ const found = /* @__PURE__ */ new Set();
20162
+ const flat = css.replace(/\/\*[\s\S]*?\*\//g, "");
20163
+ for (const match of flat.matchAll(/([^{}@]+)\{([^{}]*)\}/g)) {
20164
+ const selector = match[1].trim().slice(0, 60);
20165
+ const body = match[2];
20166
+ const color = /(?:^|;)\s*color\s*:\s*([^;]+)/.exec(body)?.[1]?.trim() ?? "";
20167
+ const fillAsText = new RegExp(`^var\\(--soma-c-${TONE}\\s*[,)]`).exec(color);
20168
+ if (fillAsText) {
20169
+ found.add(`${selector} \u628A\u586B\u5145\u8272 --soma-c-${fillAsText[1]} \u5F53\u6587\u5B57\u8272\u2014\u2014\u5F69\u8272\u6587\u5B57\u7528 var(--soma-c-${fillAsText[1]}-on-soft, \u56DE\u9000)`);
20170
+ }
20171
+ const solid = new RegExp(`background(?:-color)?\\s*:\\s*var\\(--soma-c-${TONE}\\s*[,)]`).exec(body);
20172
+ if (solid && color && !/^(inherit|currentColor|transparent)$/.test(color) && !new RegExp(`^var\\(--soma-(c-${solid[1]}-fg|ui-tone-fg)\\b`).test(color)) {
20173
+ found.add(`${selector} \u5B9E\u5FC3\u5E95 --soma-c-${solid[1]} \u4E0A\u7684\u5B57\u8272\u5FC5\u987B\u662F var(--soma-c-${solid[1]}-fg, \u56DE\u9000)`);
20174
+ }
20175
+ const soft = new RegExp(`background(?:-color)?\\s*:\\s*var\\(--soma-c-${TONE}-soft\\s*[,)]`).exec(body);
20176
+ if (soft && new RegExp(`^var\\(--soma-c-${soft[1]}(-fg)?\\s*[,)]`).test(color)) {
20177
+ found.add(`${selector} \u6DE1\u5E95 --soma-c-${soft[1]}-soft \u4E0A\u7684\u5B57\u8272\u5FC5\u987B\u662F var(--soma-c-${soft[1]}-on-soft, \u56DE\u9000)`);
20178
+ }
20179
+ for (const gradient of body.matchAll(/gradient\(([^;]+)/g)) {
20180
+ const tones = new Set([...gradient[1].matchAll(new RegExp(`--soma-c-${TONE}\\b`, "g"))].map((item) => item[1]));
20181
+ if (tones.size > 1) found.add(`${selector} \u6E10\u53D8\u6DF7\u7528\u4E86 ${[...tones].join(" / ")} \u4E24\u79CD\u8BED\u6C14\u2014\u2014\u540C\u8272\u76F8\u7528 color-mix \u8C03\u660E\u5EA6`);
20182
+ }
20183
+ }
20184
+ return [...found];
20185
+ }
20288
20186
  function nakedColors(css) {
20289
20187
  const found = /* @__PURE__ */ new Set();
20290
20188
  const stripped = css.replace(/var\(\s*--[\w-]+\s*(?:,[^()]*(?:\([^()]*\)[^()]*)*)?\)/g, " ");
@@ -20553,6 +20451,147 @@ function describeNode(node) {
20553
20451
  }
20554
20452
  }
20555
20453
 
20454
+ // core/shared/block-errors.ts
20455
+ var SomaBlockParseError = class extends Error {
20456
+ constructor(message, blockId, line) {
20457
+ const where = blockId ? `\uFF08\u5757: ${blockId}${line ? `\uFF0C\u7B2C ${line} \u884C` : ""}\uFF09` : "";
20458
+ super(`[soma-core][\u5F15\u64CE] ${message}${where}`);
20459
+ this.blockId = blockId;
20460
+ this.line = line;
20461
+ this.name = "SomaBlockParseError";
20462
+ }
20463
+ };
20464
+
20465
+ // core/build/blocks/block-container.ts
20466
+ var PAGE_BLOCK_ID = "page";
20467
+ function stripSwitch(uiYamlRaw) {
20468
+ const lines = uiYamlRaw.split("\n");
20469
+ let openIndex = -1;
20470
+ for (let i = 0; i < lines.length; i += 1) {
20471
+ const text = lines[i].trim();
20472
+ if (text === "" || text.startsWith("#")) continue;
20473
+ if (text !== "{{") {
20474
+ throw new SomaBlockParseError("\u5757\u58F0\u660E\u5FC5\u987B\u4EE5 `{{` \u5F00\u5173\u884C\u5F00\u5934");
20475
+ }
20476
+ openIndex = i;
20477
+ break;
20478
+ }
20479
+ if (openIndex === -1) {
20480
+ throw new SomaBlockParseError("\u6587\u4EF6\u4E3A\u7A7A\u6216\u53EA\u6709\u6CE8\u91CA\uFF0C\u627E\u4E0D\u5230 `{{` \u5F00\u5173\u884C");
20481
+ }
20482
+ let closeIndex = -1;
20483
+ for (let i = lines.length - 1; i > openIndex; i -= 1) {
20484
+ const text = lines[i].trim();
20485
+ if (text === "") continue;
20486
+ if (text !== "}}") {
20487
+ throw new SomaBlockParseError("\u5757\u58F0\u660E\u5FC5\u987B\u4EE5 `}}` \u6536\u53E3\u884C\u7ED3\u5C3E\uFF08\u5F00\u5173\u6210\u5BF9\uFF0C\u6574\u6587\u4EF6\u4E00\u5BF9\uFF09");
20488
+ }
20489
+ closeIndex = i;
20490
+ break;
20491
+ }
20492
+ if (closeIndex === -1) {
20493
+ throw new SomaBlockParseError("`{{` \u5F00\u5173\u672A\u95ED\u5408\u2014\u2014\u7F3A\u5C11 `}}` \u6536\u53E3\u884C");
20494
+ }
20495
+ return {
20496
+ inner: lines.slice(openIndex + 1, closeIndex).join("\n"),
20497
+ offset: openIndex + 1
20498
+ };
20499
+ }
20500
+ function parseSomaBlockContainer(uiYamlRaw) {
20501
+ const { inner, offset } = stripSwitch(uiYamlRaw);
20502
+ let doc;
20503
+ try {
20504
+ doc = yaml.load(inner);
20505
+ } catch (error) {
20506
+ throw new SomaBlockParseError(`YAML \u89E3\u6790\u5931\u8D25: ${error.message}`);
20507
+ }
20508
+ if (doc === null || doc === void 0) {
20509
+ return { doc: {}, inner, offset };
20510
+ }
20511
+ if (typeof doc !== "object" || Array.isArray(doc)) {
20512
+ throw new SomaBlockParseError("\u5F00\u5173\u5185\u5FC5\u987B\u662F\u5757\u6620\u5C04\uFF08\u9876\u5C42\u952E = \u5757 id\uFF09");
20513
+ }
20514
+ for (const [blockId, body] of Object.entries(doc)) {
20515
+ if (body === null || body === void 0) {
20516
+ throw new SomaBlockParseError("\u5757\u4F53\u4E3A\u7A7A\u2014\u2014\u4E0D\u9700\u8981\u58F0\u660E\u7684\u7EC4\u4EF6\u8BF7\u76F4\u63A5\u5220\u6389\u8FD9\u4E2A\u5757", blockId);
20517
+ }
20518
+ if (typeof body !== "object" || Array.isArray(body)) {
20519
+ throw new SomaBlockParseError("\u5757\u4F53\u5FC5\u987B\u662F\u6620\u5C04\uFF08ui/data/event \u4E09\u6BB5\uFF09", blockId);
20520
+ }
20521
+ }
20522
+ return { doc, inner, offset };
20523
+ }
20524
+ function loadSomaFile(input) {
20525
+ const { doc, inner, offset } = parseSomaBlockContainer(input.uiYamlRaw);
20526
+ if (Object.keys(doc).length === 0) return [];
20527
+ const innerLines = inner.split("\n");
20528
+ const lineOfKey = (key) => {
20529
+ const index = innerLines.findIndex((line) => line.startsWith(`${key}:`));
20530
+ return index === -1 ? offset : offset + index + 1;
20531
+ };
20532
+ const blocks = [];
20533
+ const seen = /* @__PURE__ */ new Set();
20534
+ for (const [blockId, body] of Object.entries(doc)) {
20535
+ const line = lineOfKey(blockId);
20536
+ assertBlockId(blockId, input.htmlIndex, line);
20537
+ if (seen.has(blockId)) {
20538
+ throw new SomaBlockParseError(`\u5757 "${blockId}" \u91CD\u590D\u58F0\u660E`, blockId, line);
20539
+ }
20540
+ if (body === null || body === void 0) {
20541
+ throw new SomaBlockParseError("\u5757\u4F53\u4E3A\u7A7A\u2014\u2014\u4E0D\u9700\u8981\u58F0\u660E\u7684\u7EC4\u4EF6\u8BF7\u76F4\u63A5\u5220\u6389\u8FD9\u4E2A\u5757", blockId, line);
20542
+ }
20543
+ if (typeof body !== "object" || Array.isArray(body)) {
20544
+ throw new SomaBlockParseError("\u5757\u4F53\u5FC5\u987B\u662F\u6620\u5C04\uFF08ui/data/event \u4E09\u6BB5\uFF09", blockId, line);
20545
+ }
20546
+ seen.add(blockId);
20547
+ blocks.push({ blockId, body, line, source: "inline" });
20548
+ }
20549
+ for (const [blockId, raw2] of input.externalBlocks ?? /* @__PURE__ */ new Map()) {
20550
+ assertBlockId(blockId, input.htmlIndex, 0);
20551
+ if (seen.has(blockId)) {
20552
+ throw new SomaBlockParseError(
20553
+ `\u5757 "${blockId}" \u540C\u65F6\u5B58\u5728\u4E8E _ui.yaml \u4E0E blocks/${blockId}.yaml\u2014\u2014\u4E00\u4E2A\u5B9E\u4F8B\u53EA\u80FD\u6709\u4E00\u4E2A\u58F0\u660E\u5904`,
20554
+ blockId
20555
+ );
20556
+ }
20557
+ let body;
20558
+ try {
20559
+ body = yaml.load(raw2);
20560
+ } catch (error) {
20561
+ throw new SomaBlockParseError(
20562
+ `\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u89E3\u6790\u5931\u8D25: ${error.message}`,
20563
+ blockId
20564
+ );
20565
+ }
20566
+ if (body === null || body === void 0) {
20567
+ throw new SomaBlockParseError(`\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u4E3A\u7A7A`, blockId);
20568
+ }
20569
+ if (typeof body !== "object" || Array.isArray(body)) {
20570
+ throw new SomaBlockParseError(`\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u5FC5\u987B\u662F\u6620\u5C04`, blockId);
20571
+ }
20572
+ seen.add(blockId);
20573
+ blocks.push({ blockId, body, line: 1, source: "external" });
20574
+ }
20575
+ return blocks;
20576
+ }
20577
+ function assertBlockId(blockId, htmlIndex, line) {
20578
+ if (blockId === PAGE_BLOCK_ID) return;
20579
+ if (htmlIndex.instances.has(blockId)) return;
20580
+ if (htmlIndex.anchors.has(blockId)) {
20581
+ throw new SomaBlockParseError(
20582
+ `"${blockId}" \u662F\u666E\u901A\u951A\u70B9\uFF0C\u4E0D\u80FD\u4F5C\u4E3A\u7EC4\u4EF6\u5757\u2014\u2014\u7EC4\u4EF6\u5757\u53EA\u80FD\u6302\u5728\u5E26 data-soma-component \u7684\u5B9E\u4F8B\u951A\u70B9\u4E0A\uFF1B\u666E\u901A\u951A\u70B9\u7684\u7ED1\u5B9A\u5199\u5728 page \u5757\u7684 ui: \u6BB5`,
20583
+ blockId,
20584
+ line
20585
+ );
20586
+ }
20587
+ const known = [...htmlIndex.instances].slice(0, 8).join("\u3001");
20588
+ throw new SomaBlockParseError(
20589
+ `HTML \u91CC\u6CA1\u6709\u5B9E\u4F8B\u951A\u70B9 "${blockId}"${known ? `\uFF08\u73B0\u6709\u5B9E\u4F8B\uFF1A${known}\uFF09` : ""}`,
20590
+ blockId,
20591
+ line
20592
+ );
20593
+ }
20594
+
20556
20595
  // core/build/blocks/html-index.ts
20557
20596
  var ANCHOR_RE = /data-soma-id=["']([^"']+)["']/g;
20558
20597
  var COMPONENT_NEAR_RE = /data-soma-component=["']([^"']+)["']/;
@@ -21766,7 +21805,6 @@ function findListShow(show, listAnchor) {
21766
21805
  setSomaHtmlSanitizer,
21767
21806
  somaEmits,
21768
21807
  somaFields,
21769
- somaRollupPlugin,
21770
21808
  somaSlots,
21771
21809
  startBootTimings,
21772
21810
  themeRootAttributes,
@@ -22,4 +22,5 @@ export declare class SomaComponentExpander {
22
22
  /** @returns 本次展开分配的 scopeId(宿主已展开时返回既有的那个) */
23
23
  expand(host: HTMLElement, def: SomaComponentDefinition): string;
24
24
  private scopeAnchors;
25
+ private collectSlotOutlets;
25
26
  }
@@ -76,7 +76,6 @@ export type { SomaHtmlSanitizer, SomaHtmlSanitizeResult } from './client/securit
76
76
  export type { SomaDiagnosticsSnapshot } from './client/diagnostics/SomaDiagnostics';
77
77
  export { matchGlobPath } from './client/engine/property-watcher';
78
78
  export { extractConfigFromDomainClass } from './client/parser/annotation-extractor';
79
- export { somaRollupPlugin } from './build/compiler/rollup-plugin-soma';
80
79
  export { Page, Show, ShowList, Event } from './client/base/decorators';
81
80
  export { runAsync } from './client/base/runAsync';
82
81
  export type { AsyncStateHost } from './client/base/runAsync';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soma-core",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime built on Next.js 16 App Router.",
5
5
  "keywords": [
6
6
  "soma",
@@ -55,6 +55,7 @@
55
55
  "./adaptive-vocabulary": "./core/shared/types/adaptive.types.ts",
56
56
  "./responsive-vocabulary": "./core/shared/container-breakpoints.ts",
57
57
  "./compiler/vite": "./core/build/compiler/vite-plugin-soma.ts",
58
+ "./compiler/rollup": "./core/build/compiler/rollup-plugin-soma.ts",
58
59
  "./compiler/precompile": "./core/build/compiler/soma-precompile.ts",
59
60
  "./compiler/webpack-loader": "./core/build/compiler/soma-webpack-loader.js",
60
61
  "./diagnostics": {