soma-core 1.3.3 → 1.3.5

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 (112) hide show
  1. package/README.md +7 -6
  2. package/app/SomaPageClient.tsx +2 -72
  3. package/app/soma/page/route.ts +17 -2
  4. package/bin/soma-lsp.cjs +1 -4
  5. package/core/build/compiler/full-manifest-builder.ts +17 -26
  6. package/core/build/compiler/html-include-expander.ts +56 -0
  7. package/core/build/compiler/page-assets.ts +26 -0
  8. package/core/build/compiler/page-declaration-compiler.ts +85 -0
  9. package/core/build/compiler/rollup-plugin-soma.ts +4 -19
  10. package/core/build/compiler/route-builder.ts +0 -2
  11. package/core/build/compiler/rspack-plugin-soma.js +1 -10
  12. package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -13
  13. package/core/build/compiler/soma-precompile.js +74 -0
  14. package/core/build/compiler/soma-precompile.ts +13 -0
  15. package/core/build/compiler/soma-rspack-yaml-loader.js +5 -11
  16. package/core/build/compiler/soma-webpack-loader.js +6 -21
  17. package/core/build/compiler/vite-plugin-soma.ts +9 -31
  18. package/core/build/component/pack-from-dir.ts +58 -0
  19. package/core/build/component/package-loader.ts +158 -12
  20. package/core/build/eject/plan-eject.ts +15 -21
  21. package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
  22. package/core/build/lsp/extra-completion.cjs +14 -8
  23. package/core/build/lsp/lsp-navigation.cjs +50 -43
  24. package/core/build/lsp/soma-declaration.cjs +85 -0
  25. package/core/build/lsp/ui-yaml-completion.cjs +98 -104
  26. package/core/build/v2/block-compile.ts +200 -0
  27. package/core/build/v2/block-loader.ts +33 -0
  28. package/core/build/v2/html-index.ts +120 -0
  29. package/core/build/v2/migrate-v1.ts +370 -0
  30. package/core/build/v2/soma-file-loader.ts +216 -0
  31. package/core/client/component/ai-catalog.ts +15 -0
  32. package/core/client/component/component-pack.ts +205 -31
  33. package/core/client/component/contract-compat.ts +132 -0
  34. package/core/client/component/example-v2.ts +132 -0
  35. package/core/client/engine/dom-renderer.ts +14 -8
  36. package/core/client/engine/reactive-proxy.ts +8 -7
  37. package/core/client/engine/soma-bootstrap.ts +23 -5
  38. package/core/client/parser/v2/namespace.ts +182 -0
  39. package/core/client/parser/v2/page-parser.ts +359 -0
  40. package/core/client/parser/v2/use-parser.ts +412 -0
  41. package/core/client/parser/value-lang.ts +340 -0
  42. package/core/client/pipes/pipe-registry.ts +1 -1
  43. package/core/client/registry/declaration-renderer.ts +17 -15
  44. package/core/client/registry/page-lifecycle.ts +1 -1
  45. package/core/client/security/attribute-presence.ts +16 -1
  46. package/core/client/theme/harmony.ts +307 -0
  47. package/core/client/theme/scene-tokens.ts +134 -0
  48. package/core/client/theme/theme-axes.ts +228 -0
  49. package/core/client/theme/theme-engine.ts +333 -73
  50. package/core/client/theme/tone-solver.ts +118 -0
  51. package/core/index.ts +74 -2
  52. package/core/server/host/published-page-assets.ts +35 -0
  53. package/core/server/host/server-page-assets.ts +33 -16
  54. package/core/server/host/soma-page-compile.ts +33 -0
  55. package/core/server/index.ts +15 -0
  56. package/core/server/registry/declaration-precompiler.ts +24 -54
  57. package/core/server/registry/page-registry-store.ts +39 -10
  58. package/core/server/registry/services/pages/Get.ts +19 -9
  59. package/core/server/registry/validation/compile-gate.ts +14 -31
  60. package/core/server/registry/validation/cross-check.ts +7 -17
  61. package/core/server/registry/validation/declaration-safety-scan.ts +2 -2
  62. package/core/shared/types/component-contract.types.ts +10 -0
  63. package/dist/core/index.cjs +2144 -155
  64. package/dist/types/build/compiler/full-manifest-builder.d.ts +4 -4
  65. package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
  66. package/dist/types/build/compiler/page-assets.d.ts +3 -0
  67. package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
  68. package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -3
  69. package/dist/types/build/compiler/route-builder.d.ts +0 -1
  70. package/dist/types/build/compiler/soma-precompile.d.ts +8 -0
  71. package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -10
  72. package/dist/types/build/component/pack-from-dir.d.ts +17 -0
  73. package/dist/types/build/component/package-loader.d.ts +33 -2
  74. package/dist/types/build/v2/block-compile.d.ts +28 -0
  75. package/dist/types/build/v2/block-loader.d.ts +9 -0
  76. package/dist/types/build/v2/html-index.d.ts +37 -0
  77. package/dist/types/build/v2/migrate-v1.d.ts +32 -0
  78. package/dist/types/build/v2/soma-file-loader.d.ts +45 -0
  79. package/dist/types/client/component/component-pack.d.ts +23 -3
  80. package/dist/types/client/component/contract-compat.d.ts +16 -0
  81. package/dist/types/client/component/example-v2.d.ts +9 -0
  82. package/dist/types/client/engine/dom-renderer.d.ts +2 -0
  83. package/dist/types/client/engine/soma-bootstrap.d.ts +3 -1
  84. package/dist/types/client/parser/v2/namespace.d.ts +52 -0
  85. package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
  86. package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
  87. package/dist/types/client/parser/value-lang.d.ts +63 -0
  88. package/dist/types/client/registry/declaration-renderer.d.ts +1 -2
  89. package/dist/types/client/theme/harmony.d.ts +77 -0
  90. package/dist/types/client/theme/scene-tokens.d.ts +25 -0
  91. package/dist/types/client/theme/theme-axes.d.ts +81 -0
  92. package/dist/types/client/theme/theme-engine.d.ts +29 -1
  93. package/dist/types/client/theme/tone-solver.d.ts +47 -0
  94. package/dist/types/index.d.ts +13 -2
  95. package/dist/types/server/host/published-page-assets.d.ts +19 -0
  96. package/dist/types/server/host/server-page-assets.d.ts +1 -4
  97. package/dist/types/server/host/soma-page-compile.d.ts +7 -0
  98. package/dist/types/server/index.d.ts +3 -1
  99. package/dist/types/server/registry/declaration-precompiler.d.ts +3 -3
  100. package/dist/types/server/registry/page-registry-store.d.ts +5 -5
  101. package/dist/types/server/registry/validation/compile-gate.d.ts +2 -0
  102. package/dist/types/server/registry/validation/cross-check.d.ts +4 -4
  103. package/dist/types/shared/types/component-contract.types.d.ts +10 -0
  104. package/editor/vscode/package.json +1 -24
  105. package/global.d.ts +1 -11
  106. package/next.config.js +32 -50
  107. package/package.json +3 -2
  108. package/tailwind.config.ts +0 -1
  109. package/tsconfig.json +20 -7
  110. package/core/build/lsp/event-yaml-completion.cjs +0 -106
  111. package/core/client/host-bridge/empty-host/data/README.md +0 -17
  112. package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  Locale: () => Locale,
36
36
  MiniProgramContainerAdapter: () => MiniProgramContainerAdapter,
37
37
  PACK_NAME_PATTERN: () => PACK_NAME_PATTERN,
38
+ PAGE_BLOCK_ID: () => PAGE_BLOCK_ID,
38
39
  Page: () => Page,
39
40
  ReactNativeContainerAdapter: () => ReactNativeContainerAdapter,
40
41
  SOMA_ADAPTIVE_MAX_LADDER: () => SOMA_ADAPTIVE_MAX_LADDER,
@@ -64,8 +65,11 @@ __export(index_exports, {
64
65
  SomaPipeRegistry: () => SomaPipeRegistry,
65
66
  SomaQualityRegistry: () => SomaQualityRegistry,
66
67
  SomaRealtimeService: () => SomaRealtimeService,
68
+ SomaScopeError: () => SomaScopeError,
67
69
  SomaTelemetry: () => SomaTelemetry,
70
+ SomaV2ParseError: () => SomaV2ParseError,
68
71
  SomaValidator: () => SomaValidator,
72
+ SomaValueLangError: () => SomaValueLangError,
69
73
  SseRealtimeTransport: () => SseRealtimeTransport,
70
74
  THEME_SWITCHING_CLASS: () => THEME_SWITCHING_CLASS,
71
75
  TYPOGRAPHY_BASE_CSS: () => TYPOGRAPHY_BASE_CSS,
@@ -74,8 +78,13 @@ __export(index_exports, {
74
78
  applyLocaleMetadata: () => applyLocaleMetadata,
75
79
  applyTheme: () => applyTheme,
76
80
  attachPackStyles: () => attachPackStyles,
81
+ buildBlockScope: () => buildBlockScope,
77
82
  buildCatalogEntry: () => buildCatalogEntry,
83
+ buildHtmlAnchorIndex: () => buildHtmlAnchorIndex,
84
+ checkOverrideCompat: () => checkOverrideCompat,
78
85
  compileAdaptive: () => compileAdaptive,
86
+ compilePageAssets: () => compilePageAssets,
87
+ compileSomaV2: () => compileSomaV2,
79
88
  composeComponentPacks: () => composeComponentPacks,
80
89
  contrastRatio: () => contrastRatio,
81
90
  createAdaptiveObserverPool: () => createAdaptiveObserverPool,
@@ -87,8 +96,11 @@ __export(index_exports, {
87
96
  createSomaPageLifecycle: () => createSomaPageLifecycle,
88
97
  defaultPipeRegistry: () => defaultPipeRegistry,
89
98
  deriveTheme: () => deriveTheme,
99
+ describeNode: () => describeNode,
90
100
  ensurePackBaseStyles: () => ensurePackBaseStyles,
91
101
  escapeSomaHtml: () => escapeSomaHtml,
102
+ evaluateValueNode: () => evaluateValueNode,
103
+ expandPath: () => expandPath,
92
104
  extractConfigFromDomainClass: () => extractConfigFromDomainClass,
93
105
  findNestedMutableContractDefault: () => findNestedMutableContractDefault,
94
106
  findSomaDomainLoader: () => findSomaDomainLoader,
@@ -102,10 +114,13 @@ __export(index_exports, {
102
114
  hasBlockedScheme: () => hasBlockedScheme,
103
115
  hasPageMetadata: () => hasPageMetadata,
104
116
  installSomaErrorReporter: () => installSomaErrorReporter,
117
+ isArithSegment: () => isArithSegment,
105
118
  isBootTimingsEnabled: () => isBootTimingsEnabled,
106
119
  isEventHandlerAttribute: () => isEventHandlerAttribute,
120
+ isPlainPath: () => isPlainPath,
107
121
  isSomaMockEnabled: () => isSomaMockEnabled,
108
122
  loadSomaDomainModuleFromRegistry: () => loadSomaDomainModuleFromRegistry,
123
+ loadSomaFile: () => loadSomaFile,
109
124
  markBootPhase: () => markBootPhase,
110
125
  matchGlobPath: () => matchGlobPath,
111
126
  maybeStartBootTimings: () => maybeStartBootTimings,
@@ -114,22 +129,29 @@ __export(index_exports, {
114
129
  parseDataConfig: () => parseDataConfig,
115
130
  parseDataRef: () => parseDataRef,
116
131
  parseDataYaml: () => parseDataYaml,
132
+ parsePageBlock: () => parsePageBlock,
133
+ parseUseBlock: () => parseUseBlock,
134
+ parseValueSegment: () => parseValueSegment,
117
135
  readBootTimings: () => readBootTimings,
118
136
  recordMetric: () => recordMetric,
119
137
  renderPublishedPage: () => renderPublishedPage,
120
138
  resetBootTimings: () => resetBootTimings,
121
139
  resetPackStyleInjection: () => resetPackStyleInjection,
140
+ resolveApiRef: () => resolveApiRef,
122
141
  resolveHostBootstrapOptions: () => resolveHostBootstrapOptions,
142
+ resolvePath: () => resolvePath,
123
143
  resolveSomaHtmlSanitizer: () => resolveSomaHtmlSanitizer,
124
144
  resolveTierWithHysteresis: () => resolveTierWithHysteresis,
125
145
  runAsync: () => runAsync,
126
146
  sanitizeAttributeWrite: () => sanitizeAttributeWrite,
127
147
  sanitizeSomaHtml: () => sanitizeSomaHtml,
128
148
  scheduleAdaptiveFlush: () => scheduleAdaptiveFlush,
149
+ scopeHasVar: () => scopeHasVar,
129
150
  setActiveTelemetry: () => setActiveTelemetry,
130
151
  setSomaHtmlSanitizer: () => setSomaHtmlSanitizer,
131
152
  somaRollupPlugin: () => somaRollupPlugin,
132
153
  startBootTimings: () => startBootTimings,
154
+ themeRootAttributes: () => themeRootAttributes,
133
155
  verifyComponentPack: () => verifyComponentPack
134
156
  });
135
157
  module.exports = __toCommonJS(index_exports);
@@ -736,9 +758,14 @@ var ABSENT_WHEN_EMPTY_ARIA = /* @__PURE__ */ new Set([
736
758
  // 表单控件在非错误态下写空串等于凭空宣告"这个字段填错了"。
737
759
  "aria-invalid"
738
760
  ]);
761
+ var ABSENT_WHEN_EMPTY_RESOURCE = /* @__PURE__ */ new Set([
762
+ "src",
763
+ "srcset",
764
+ "poster"
765
+ ]);
739
766
  function isAbsentWhenEmpty(attrName) {
740
767
  const name = attrName.toLowerCase();
741
- return BOOLEAN_ATTRS.has(name) || ABSENT_WHEN_EMPTY_ARIA.has(name);
768
+ return BOOLEAN_ATTRS.has(name) || ABSENT_WHEN_EMPTY_ARIA.has(name) || ABSENT_WHEN_EMPTY_RESOURCE.has(name);
742
769
  }
743
770
  function shouldRemoveAttribute(attrName, value) {
744
771
  return value === "" && isAbsentWhenEmpty(attrName);
@@ -4466,7 +4493,7 @@ function requireDumper() {
4466
4493
  }
4467
4494
  }
4468
4495
  }
4469
- function dump2(input, options) {
4496
+ function dump22(input, options) {
4470
4497
  options = options || {};
4471
4498
  const state2 = new State(options);
4472
4499
  if (!state2.noRefs) getDuplicateReferences(input, state2);
@@ -4477,7 +4504,7 @@ function requireDumper() {
4477
4504
  if (writeNode(state2, 0, value, true, true)) return state2.dump + "\n";
4478
4505
  return "";
4479
4506
  }
4480
- dumper.dump = dump2;
4507
+ dumper.dump = dump22;
4481
4508
  return dumper;
4482
4509
  }
4483
4510
  var hasRequiredJsYaml;
@@ -5865,8 +5892,8 @@ var SomaReactiveProxy = class {
5865
5892
  const self = this;
5866
5893
  return {
5867
5894
  get(target, prop, receiver) {
5868
- if (typeof prop === "symbol") return Reflect.get(target, prop, target);
5869
- const value = Reflect.get(target, prop, target);
5895
+ if (typeof prop === "symbol") return Reflect.get(target, prop, receiver);
5896
+ const value = Reflect.get(target, prop, receiver);
5870
5897
  if (prop === "_services" || prop === "_config") {
5871
5898
  return value;
5872
5899
  }
@@ -5889,14 +5916,15 @@ var SomaReactiveProxy = class {
5889
5916
  }
5890
5917
  return value;
5891
5918
  },
5892
- set(target, prop, value) {
5919
+ set(target, prop, value, receiver) {
5893
5920
  const key = String(prop);
5894
5921
  const path = basePath ? `${basePath}.${key}` : key;
5895
- const oldValue = target[prop];
5922
+ const oldValue = Reflect.get(target, prop, receiver);
5896
5923
  if (oldValue != null && typeof oldValue === "object") {
5897
5924
  self.childProxyCache.delete(oldValue);
5898
5925
  }
5899
- target[prop] = value;
5926
+ const assigned = Reflect.set(target, prop, value, receiver);
5927
+ if (!assigned) return false;
5900
5928
  try {
5901
5929
  self.diagnostics?.recordMutation(path, value);
5902
5930
  if (self.batchDepth > 0) {
@@ -7238,6 +7266,15 @@ var SomaDomRenderer = class {
7238
7266
  setModelWriteBack(fn) {
7239
7267
  this.modelWriteBack = fn;
7240
7268
  }
7269
+ /** 模型回写必须在绑定表创建时附着,不能依赖首帧渲染是否走到该项。 */
7270
+ ensureModelListener(element, dataPath) {
7271
+ if (!this.adapter || !this.modelWriteBack || this.modelListeners.has(element)) return;
7272
+ this.modelListeners.add(element);
7273
+ const writeModel = () => this.modelWriteBack?.(dataPath, this.adapter.getValue(element));
7274
+ for (const eventType of ["input", "change", "blur"]) {
7275
+ this.adapter.listen(element, eventType, writeModel, this.modelAbort.signal);
7276
+ }
7277
+ }
7241
7278
  bindEntry(binding, container) {
7242
7279
  if (!this.adapter) {
7243
7280
  return null;
@@ -7262,6 +7299,9 @@ var SomaDomRenderer = class {
7262
7299
  pipes: binding.pipes
7263
7300
  };
7264
7301
  entry.compiledRender = this.compileRenderFn(entry);
7302
+ if (entry.type === "model") {
7303
+ this.ensureModelListener(entry.element, entry.dataPath);
7304
+ }
7265
7305
  return entry;
7266
7306
  }
7267
7307
  /**
@@ -7309,7 +7349,6 @@ var SomaDomRenderer = class {
7309
7349
  const modelAdapter = adapter;
7310
7350
  const modelListeners = this.modelListeners;
7311
7351
  const modelWriteBack = this.modelWriteBack;
7312
- const modelAbort = this.modelAbort;
7313
7352
  const dataPath = entry.dataPath;
7314
7353
  const self = this;
7315
7354
  return (v) => {
@@ -7318,13 +7357,7 @@ var SomaDomRenderer = class {
7318
7357
  modelAdapter.setValue(modelEl, strValue);
7319
7358
  }
7320
7359
  if (modelWriteBack && !modelListeners.has(modelEl)) {
7321
- modelListeners.add(modelEl);
7322
- const writeModel = () => {
7323
- modelWriteBack(dataPath, modelAdapter.getValue(modelEl));
7324
- };
7325
- for (const eventType of ["input", "change", "blur"]) {
7326
- modelAdapter.listen(modelEl, eventType, writeModel, modelAbort.signal);
7327
- }
7360
+ self.ensureModelListener(modelEl, dataPath);
7328
7361
  }
7329
7362
  };
7330
7363
  }
@@ -11294,6 +11327,292 @@ function isNested(value) {
11294
11327
  return typeof value === "object" && value !== null && "bind" in value && "show" in value;
11295
11328
  }
11296
11329
 
11330
+ // core/client/theme/theme-axes.ts
11331
+ var SomaThemeAxisError = class extends Error {
11332
+ constructor(message) {
11333
+ super(`[soma-core][\u4E3B\u9898] ${message}`);
11334
+ this.name = "SomaThemeAxisError";
11335
+ }
11336
+ };
11337
+ var HARMONY_K = {
11338
+ functional: 0,
11339
+ analogous: 0.72,
11340
+ monochrome: 1,
11341
+ complementary: 0.72
11342
+ };
11343
+ var CHROMA_MUL = {
11344
+ muted: 0.6,
11345
+ balanced: 1,
11346
+ vivid: 1.35
11347
+ };
11348
+ var CONTRAST_TARGETS = {
11349
+ soft: { toneOnPage: 3.2, fgOnTone: 4.5, textOnPage: 4.5 },
11350
+ standard: { toneOnPage: 4, fgOnTone: 4.5, textOnPage: 4.5 },
11351
+ strong: { toneOnPage: 5.5, fgOnTone: 7, textOnPage: 7 }
11352
+ };
11353
+ var DARK_CONTRAST_TARGETS = {
11354
+ soft: { toneOnPage: 3, fgOnTone: 4.5, textOnPage: 4.5 },
11355
+ standard: { toneOnPage: 3.6, fgOnTone: 4.5, textOnPage: 4.5 },
11356
+ strong: { toneOnPage: 5, fgOnTone: 7, textOnPage: 7 }
11357
+ };
11358
+ var SOFT_LIGHTNESS_BAND = [0.7, 0.86];
11359
+ var FIELD_ALPHAS = {
11360
+ tinted: [0.18, 0.12, 0.1],
11361
+ aurora: [0.42, 0.28, 0.26]
11362
+ };
11363
+ var INTENSITY_MUL = {
11364
+ whisper: 0.45,
11365
+ soft: 1,
11366
+ bold: 1.35
11367
+ };
11368
+ var HEX_SHAPE = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
11369
+ var MAX_ACCENTS = 3;
11370
+ function resolveAxes(input) {
11371
+ const p = input.palette ?? {};
11372
+ const s = input.scene ?? {};
11373
+ const accents = p.accents ?? [];
11374
+ if (accents.length > MAX_ACCENTS) {
11375
+ throw new SomaThemeAxisError(
11376
+ `accents \u6700\u591A ${MAX_ACCENTS} \u4E2A\uFF08\u4F9D\u6B21\u9501 secondary/accent/info \u7684\u8272\u76F8\u951A\uFF09\uFF0C\u6536\u5230 ${accents.length} \u4E2A\u3002\u8981\u7CBE\u8C03\u66F4\u591A\u989C\u8272\u8BF7\u8D70 overrides \u9010\u4EE4\u724C\u901A\u9053\u3002`
11377
+ );
11378
+ }
11379
+ for (const hex of accents) {
11380
+ if (!HEX_SHAPE.test(hex)) {
11381
+ throw new SomaThemeAxisError(`accents \u91CC\u7684 "${hex}" \u4E0D\u662F\u5408\u6CD5\u989C\u8272\uFF08#rgb \u6216 #rrggbb\uFF09`);
11382
+ }
11383
+ }
11384
+ const axes = {
11385
+ palette: {
11386
+ harmony: p.harmony ?? "functional",
11387
+ semantics: p.semantics ?? "faithful",
11388
+ chroma: p.chroma ?? "balanced",
11389
+ contrast: p.contrast ?? "standard",
11390
+ accents
11391
+ },
11392
+ scene: {
11393
+ // 缺省是 aurora/soft 而不是 flat:**今天的引擎产出的就是这一档的值**
11394
+ // (G1 的 `hexWithAlpha(scale300, .42)` 等三行),缺省若给 flat 就等于
11395
+ // 把存量页面的 .soma-ambient 类清零——那是破坏,不是收编。
11396
+ // flat 因此是一个**显式的退出档**:主题明说"这一页不要场"。
11397
+ field: s.field ?? "aurora",
11398
+ intensity: s.intensity ?? "soft",
11399
+ material: s.material ?? "solid"
11400
+ }
11401
+ };
11402
+ const { harmony, chroma, contrast, field, intensity, semantics } = {
11403
+ ...axes.palette,
11404
+ ...axes.scene
11405
+ };
11406
+ const alphas = field === "flat" ? null : FIELD_ALPHAS[field].map((a) => a * INTENSITY_MUL[intensity]);
11407
+ return {
11408
+ axes,
11409
+ params: {
11410
+ harmonyK: HARMONY_K[harmony],
11411
+ accentComplement: harmony === "complementary",
11412
+ chromaMul: CHROMA_MUL[chroma],
11413
+ targets: CONTRAST_TARGETS[contrast],
11414
+ darkTargets: DARK_CONTRAST_TARGETS[contrast],
11415
+ softLightnessBand: contrast === "soft" ? SOFT_LIGHTNESS_BAND : null,
11416
+ fieldAlphas: alphas,
11417
+ glassEnabled: axes.scene.material === "glass",
11418
+ signalEnabled: semantics === "immersive"
11419
+ }
11420
+ };
11421
+ }
11422
+
11423
+ // core/client/theme/harmony.ts
11424
+ var FUNCTIONAL_HUES = { info: 230, success: 150, warning: 75, danger: 27 };
11425
+ var EXPRESSIVE_OFFSETS = { secondary: 48, accent: 160 };
11426
+ var SEPARATION_THRESHOLD = { hue: 30, lightness: 0.12 };
11427
+ var SEMANTIC_ZONES = {
11428
+ danger: [12, 45],
11429
+ warning: [58, 100],
11430
+ success: [125, 178]
11431
+ };
11432
+ var PUSH_MARGIN = 1.15;
11433
+ var TINTED_MIN_SEPARATION = 40;
11434
+ var PUSH_STEP = 6;
11435
+ var PUSH_MAX = 16;
11436
+ var LADDER_BANDWIDTH = 120;
11437
+ function angDiff(a, b) {
11438
+ let d = (a - b) % 360;
11439
+ if (d > 180) d -= 360;
11440
+ if (d <= -180) d += 360;
11441
+ return d;
11442
+ }
11443
+ function norm(h) {
11444
+ return (h % 360 + 360) % 360;
11445
+ }
11446
+ function compress(hue, brandHue, k) {
11447
+ return norm(brandHue + angDiff(hue, brandHue) * (1 - k));
11448
+ }
11449
+ function resolveHueAnchors(brandHue, axes, params, accentHues = []) {
11450
+ const { harmonyK, accentComplement } = params;
11451
+ const { semantics } = axes.palette;
11452
+ const secondarySeed = norm(brandHue + EXPRESSIVE_OFFSETS.secondary);
11453
+ const accentSeed = accentComplement ? norm(brandHue + 180) : norm(brandHue + EXPRESSIVE_OFFSETS.accent);
11454
+ const tones = {
11455
+ primary: brandHue,
11456
+ secondary: accentHues[0] ?? compress(secondarySeed, brandHue, harmonyK),
11457
+ accent: accentHues[1] ?? (accentComplement ? accentSeed : compress(accentSeed, brandHue, harmonyK)),
11458
+ info: accentHues[2] ?? compress(FUNCTIONAL_HUES.info, brandHue, harmonyK),
11459
+ success: semanticHue(FUNCTIONAL_HUES.success, brandHue, harmonyK, semantics),
11460
+ warning: semanticHue(FUNCTIONAL_HUES.warning, brandHue, harmonyK, semantics),
11461
+ danger: semanticHue(FUNCTIONAL_HUES.danger, brandHue, harmonyK, semantics)
11462
+ };
11463
+ const bandwidth = hueBandwidth(Object.values(tones));
11464
+ return {
11465
+ tones,
11466
+ chart: chartAnchors(brandHue, bandwidth),
11467
+ chartLightnessLadder: bandwidth < LADDER_BANDWIDTH
11468
+ };
11469
+ }
11470
+ function semanticHue(functional, brandHue, k, semantics) {
11471
+ if (semantics === "faithful") return functional;
11472
+ const compressed = compress(functional, brandHue, k);
11473
+ if (semantics === "immersive") return compressed;
11474
+ const gap = Math.abs(angDiff(compressed, brandHue));
11475
+ if (gap >= TINTED_MIN_SEPARATION) return compressed;
11476
+ const away = angDiff(compressed, brandHue) >= 0 ? 1 : -1;
11477
+ return norm(brandHue + away * TINTED_MIN_SEPARATION);
11478
+ }
11479
+ function hueBandwidth(hues) {
11480
+ const sorted = [...hues].map(norm).sort((a, b) => a - b);
11481
+ if (sorted.length <= 1) return 0;
11482
+ let widestGap = sorted[0] + 360 - sorted[sorted.length - 1];
11483
+ for (let i = 1; i < sorted.length; i += 1) {
11484
+ widestGap = Math.max(widestGap, sorted[i] - sorted[i - 1]);
11485
+ }
11486
+ return 360 - widestGap;
11487
+ }
11488
+ function chartAnchors(brandHue, bandwidth) {
11489
+ const span = bandwidth < 1 ? 0 : Math.min(bandwidth, 360);
11490
+ const start = norm(brandHue - span / 2);
11491
+ return Array.from({ length: 8 }, (_, i) => norm(start + span * i / 8));
11492
+ }
11493
+ function applySeparationGuard(anchors, brandHue, brandLightness, toneLightness, semantics) {
11494
+ if (semantics === "immersive") {
11495
+ return { anchors, applied: false, pushed: [], lightnessSeparation: {} };
11496
+ }
11497
+ const pushed = [];
11498
+ const lightnessSeparation = {};
11499
+ const tones = { ...anchors.tones };
11500
+ for (const tone of ["success", "warning", "danger"]) {
11501
+ const hueGap = Math.abs(angDiff(tones[tone], brandHue));
11502
+ const lightGap = Math.abs((toneLightness[tone] ?? 0) - brandLightness);
11503
+ const hueBar = SEPARATION_THRESHOLD.hue * PUSH_MARGIN;
11504
+ const lightBar = SEPARATION_THRESHOLD.lightness * PUSH_MARGIN;
11505
+ if (hueGap >= hueBar || lightGap >= lightBar) continue;
11506
+ const siblings = ["success", "warning", "danger"].filter((other) => other !== tone).map((other) => tones[other]);
11507
+ const scoreOf = (hue) => Math.min(
11508
+ Math.abs(angDiff(hue, brandHue)),
11509
+ ...siblings.map((sibling) => Math.abs(angDiff(hue, sibling)))
11510
+ );
11511
+ const [zoneLow, zoneHigh] = SEMANTIC_ZONES[tone];
11512
+ const inZone = (hue) => {
11513
+ const h = norm(hue);
11514
+ return zoneLow <= zoneHigh ? h >= zoneLow && h <= zoneHigh : h >= zoneLow || h <= zoneHigh;
11515
+ };
11516
+ const target = SEPARATION_THRESHOLD.hue * PUSH_MARGIN;
11517
+ const candidateFor = (direction) => {
11518
+ let hue = tones[tone];
11519
+ for (let i = 0; i < PUSH_MAX; i += 1) {
11520
+ if (Math.abs(angDiff(hue, brandHue)) >= target) return hue;
11521
+ const next = norm(hue + direction * PUSH_STEP);
11522
+ if (!inZone(next)) return null;
11523
+ hue = next;
11524
+ }
11525
+ return Math.abs(angDiff(hue, brandHue)) >= target ? hue : null;
11526
+ };
11527
+ const candidates = [candidateFor(1), candidateFor(-1)].filter((hue) => hue !== null);
11528
+ if (candidates.length === 0) {
11529
+ const direction = (toneLightness[tone] ?? 0) >= brandLightness ? 1 : -1;
11530
+ lightnessSeparation[tone] = { direction, minGap: SEPARATION_THRESHOLD.lightness };
11531
+ pushed.push(tone);
11532
+ continue;
11533
+ }
11534
+ candidates.sort((a, b) => scoreOf(b) - scoreOf(a));
11535
+ tones[tone] = candidates[0];
11536
+ pushed.push(tone);
11537
+ }
11538
+ if (pushed.length === 0) {
11539
+ return { anchors, applied: false, pushed: [], lightnessSeparation: {} };
11540
+ }
11541
+ const bandwidth = hueBandwidth(Object.values(tones));
11542
+ return {
11543
+ anchors: {
11544
+ tones,
11545
+ chart: chartAnchors(brandHue, bandwidth),
11546
+ chartLightnessLadder: bandwidth < LADDER_BANDWIDTH
11547
+ },
11548
+ applied: true,
11549
+ pushed,
11550
+ lightnessSeparation
11551
+ };
11552
+ }
11553
+
11554
+ // core/client/theme/tone-solver.ts
11555
+ var MAX_SOLVE_ITER = 16;
11556
+ var STEP = 0.04;
11557
+ function ensureContrast(bg, deps, minRatio = 4.5, maxIter = MAX_SOLVE_ITER, forceDirection) {
11558
+ let current = bg;
11559
+ let fg = deps.bestFg(current);
11560
+ for (let i = 0; i < maxIter && deps.contrastRatio(current, fg) < minRatio; i += 1) {
11561
+ const cur = deps.hexToOklch(current);
11562
+ const lighten = forceDirection ? forceDirection === "lighten" : cur.l > 0.55;
11563
+ current = deps.oklchToHex({ ...cur, l: lighten ? cur.l + STEP : cur.l - STEP });
11564
+ fg = deps.bestFg(current);
11565
+ }
11566
+ return { bg: current, fg };
11567
+ }
11568
+
11569
+ // core/client/theme/scene-tokens.ts
11570
+ var SIGNAL_IDLE = {
11571
+ "--soma-signal-edge": "none",
11572
+ "--soma-signal-glow": "none",
11573
+ "--soma-signal-pulse-duration": "0s",
11574
+ "--soma-signal-pulse-duration-calm": "0s",
11575
+ "--soma-signal-edge-duration": "0s"
11576
+ };
11577
+ var SIGNAL_DURATIONS = { urgent: "2.8s", calm: "4.9s", edge: "2.4s" };
11578
+ var AMBIENT_DURATION = "12s";
11579
+ function sceneStructureTokens(axes) {
11580
+ const signal = axes.palette.semantics === "immersive" ? {
11581
+ ...SIGNAL_IDLE,
11582
+ "--soma-signal-pulse-duration": SIGNAL_DURATIONS.urgent,
11583
+ "--soma-signal-pulse-duration-calm": SIGNAL_DURATIONS.calm,
11584
+ "--soma-signal-edge-duration": SIGNAL_DURATIONS.edge
11585
+ } : { ...SIGNAL_IDLE };
11586
+ return {
11587
+ // 环境光球时长:motion 轴(soma-ui recipe)会覆盖它——
11588
+ // `motion: 'none'` 的主题里光球因此自动静止,与 prefers-reduced-motion
11589
+ // 走同一条退化路径,一份实现两个触发源
11590
+ "--soma-ambient-duration": AMBIENT_DURATION,
11591
+ ...signal
11592
+ };
11593
+ }
11594
+ function sceneColorTokens(finalVars, axes, alphas, hexWithAlpha2, scale, rescale) {
11595
+ const out = {};
11596
+ if (!alphas) {
11597
+ out["--soma-ambient-1"] = "transparent";
11598
+ out["--soma-ambient-2"] = "transparent";
11599
+ out["--soma-ambient-3"] = "transparent";
11600
+ } else {
11601
+ const effective = rescale ? rescale(finalVars["--soma-c-primary"]) : scale;
11602
+ const seeds = [effective["300"], effective["500"], effective["400"]];
11603
+ seeds.forEach((seed, i) => {
11604
+ out[`--soma-ambient-${i + 1}`] = seed ? hexWithAlpha2(seed, alphas[i]) : "transparent";
11605
+ });
11606
+ }
11607
+ const tint = finalVars["--soma-c-primary"] ?? "#4f8cff";
11608
+ out["--soma-signal-tint"] = tint;
11609
+ if (axes.palette.semantics === "immersive") {
11610
+ out["--soma-signal-glow"] = `0 0 0 6px ${hexWithAlpha2(tint, 0.25)}`;
11611
+ out["--soma-signal-edge"] = `linear-gradient(90deg, transparent, ${hexWithAlpha2(tint, 0.86)}, transparent)`;
11612
+ }
11613
+ return out;
11614
+ }
11615
+
11297
11616
  // core/client/theme/theme-engine.ts
11298
11617
  function srgbToLinear(c) {
11299
11618
  return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
@@ -11518,15 +11837,24 @@ function deriveOnSoftTokens(vars, dark) {
11518
11837
  if (onSoftMemo.size >= ON_SOFT_MEMO_LIMIT) onSoftMemo.clear();
11519
11838
  onSoftMemo.set(memoKey, SOFT_TONES.map((tone) => vars[`--soma-c-${tone}-on-soft`]));
11520
11839
  }
11521
- function chartSeries(hue, chroma, lightness) {
11522
- const offsets = [0, 200, 130, 45, 275, 95, 320, 165];
11840
+ function chartSeries(hue, chroma, lightness, anchors) {
11523
11841
  const vars = {};
11524
- offsets.forEach((offset, index) => {
11525
- vars[`--soma-chart-${index + 1}`] = oklchToHex({
11526
- l: lightness,
11527
- c: chroma,
11528
- h: (hue + offset) % 360
11842
+ if (anchors?.chartLightnessLadder) {
11843
+ const span = 0.34;
11844
+ const start = lightness - span / 2;
11845
+ anchors.chart.forEach((h, index) => {
11846
+ vars[`--soma-chart-${index + 1}`] = oklchToHex({
11847
+ l: Math.max(0.28, Math.min(0.88, start + span * index / 7)),
11848
+ c: chroma,
11849
+ h
11850
+ });
11529
11851
  });
11852
+ return vars;
11853
+ }
11854
+ const offsets = [0, 200, 130, 45, 275, 95, 320, 165];
11855
+ const hues = anchors && anchors.chart.length === 8 ? anchors.chart : offsets.map((offset) => (hue + offset) % 360);
11856
+ hues.forEach((h, index) => {
11857
+ vars[`--soma-chart-${index + 1}`] = oklchToHex({ l: lightness, c: chroma, h });
11530
11858
  });
11531
11859
  return vars;
11532
11860
  }
@@ -11583,6 +11911,16 @@ var STATIC_TOKENS = {
11583
11911
  // 圆角:记名**不 rem 化**。圆角是描边级光学属性,跟着字号缩放会失真;
11584
11912
  // `9999px` 是"胶囊"的语义值,缩放它没有意义。阴影偏移与 1px 描边同理。
11585
11913
  // (radius-control/overlay 仍单列在语义组)
11914
+ // 材质档(REQ-006 G1):玻璃拟态需要的几何与模糊量。
11915
+ // 与既有 radius 同理不 rem 化——它们是描边级光学属性。
11916
+ "--soma-radius-plush": "22px",
11917
+ // 玻璃面的"厚实"圆角(参照实测 22~26px)
11918
+ "--soma-surface-blur": "18px",
11919
+ // backdrop-filter 模糊半径
11920
+ "--soma-surface-saturate": "140%",
11921
+ // 模糊同时提饱和,避免背景透上来发灰
11922
+ "--soma-lift-hover": "translateY(-2px)",
11923
+ // 悬停位移量(reduced-motion 下由组件退化)
11586
11924
  "--soma-radius-none": "0px",
11587
11925
  "--soma-radius-sm": "4px",
11588
11926
  "--soma-radius-md": "8px",
@@ -11617,8 +11955,11 @@ var STATIC_TOKENS = {
11617
11955
  var STEPS = ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "950"];
11618
11956
  var LIGHTNESS = [0.985, 0.955, 0.91, 0.85, 0.78, 0.7, 0.62, 0.54, 0.46, 0.38, 0.3];
11619
11957
  var CHROMA_CURVE = [0.14, 0.28, 0.48, 0.68, 0.85, 1, 1, 0.92, 0.8, 0.66, 0.52];
11958
+ var SOLVER_DEPS = { oklchToHex, hexToOklch, contrastRatio, bestFg };
11620
11959
  function deriveTheme(input) {
11621
11960
  const brand = hexToOklch(input.brand);
11961
+ const { axes, params } = resolveAxes(input);
11962
+ const accentHues = axes.palette.accents.map((hex) => hexToOklch(hex).h);
11622
11963
  const brandSlot = nearestIndex(LIGHTNESS, brand.l);
11623
11964
  const scale = {};
11624
11965
  STEPS.forEach((step, i) => {
@@ -11631,75 +11972,128 @@ function deriveTheme(input) {
11631
11972
  const primary = scale[STEPS[primaryIdx]];
11632
11973
  const hover = oklchToHex({ ...hexToOklch(primary), l: hexToOklch(primary).l - 0.06 });
11633
11974
  const active2 = oklchToHex({ ...hexToOklch(primary), l: hexToOklch(primary).l - 0.11 });
11634
- let ensuredPrimary = primary;
11635
- let fg = bestFg(ensuredPrimary);
11636
- for (let i = 0; i < 16 && contrastRatio(ensuredPrimary, fg) < 4.5; i++) {
11637
- const cur = hexToOklch(ensuredPrimary);
11638
- ensuredPrimary = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11639
- fg = bestFg(ensuredPrimary);
11640
- }
11641
- const danger = oklchToHex({ l: 0.6, c: Math.max(brand.c, 0.12) * 0.95, h: 27 });
11642
- const success = oklchToHex({ l: 0.58, c: Math.max(brand.c, 0.12) * 0.85, h: 150 });
11643
- const warning = oklchToHex({ l: 0.72, c: Math.max(brand.c, 0.12) * 0.9, h: 75 });
11644
- let info = oklchToHex({ l: 0.6, c: Math.max(brand.c, 0.12) * 0.9, h: 230 });
11645
- let infoFg = bestFg(info);
11646
- for (let i = 0; i < 16 && contrastRatio(info, infoFg) < 4.5; i++) {
11647
- const cur = hexToOklch(info);
11648
- info = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11649
- infoFg = bestFg(info);
11650
- }
11975
+ const primarySolved = ensureContrast(primary, SOLVER_DEPS, params.targets.fgOnTone);
11976
+ const ensuredPrimary = primarySolved.bg;
11977
+ const fg = primarySolved.fg;
11978
+ const anchors0 = resolveHueAnchors(brand.h, axes, params, accentHues);
11979
+ const toneChroma = (mul) => Math.max(brand.c, 0.12) * mul * params.chromaMul;
11980
+ const banded = (l) => {
11981
+ const band = params.softLightnessBand;
11982
+ return band ? Math.min(band[1], Math.max(band[0], l)) : l;
11983
+ };
11984
+ const solveSemantics = (hues) => {
11985
+ const dangerHex = oklchToHex({ l: banded(0.6), c: toneChroma(0.95), h: hues.danger });
11986
+ return {
11987
+ danger: { bg: dangerHex, fg: "#ffffff", l: banded(0.6) },
11988
+ success: ensureContrast(oklchToHex({ l: banded(0.58), c: toneChroma(0.85), h: hues.success }), SOLVER_DEPS),
11989
+ warning: ensureContrast(oklchToHex({ l: banded(0.72), c: toneChroma(0.9), h: hues.warning }), SOLVER_DEPS)
11990
+ };
11991
+ };
11992
+ const firstPass = solveSemantics(anchors0.tones);
11993
+ const primaryFinal = hexToOklch(ensuredPrimary);
11994
+ const guard = applySeparationGuard(
11995
+ anchors0,
11996
+ primaryFinal.h,
11997
+ primaryFinal.l,
11998
+ {
11999
+ primary: primaryFinal.l,
12000
+ secondary: primaryFinal.l,
12001
+ accent: primaryFinal.l,
12002
+ info: 0.6,
12003
+ success: hexToOklch(firstPass.success.bg).l,
12004
+ warning: hexToOklch(firstPass.warning.bg).l,
12005
+ danger: firstPass.danger.l
12006
+ },
12007
+ axes.palette.semantics
12008
+ );
12009
+ const anchors = guard.anchors;
12010
+ const chartAnchorsOrNull = axes.palette.harmony === "functional" ? void 0 : anchors;
12011
+ const separatedL = (tone, base) => {
12012
+ const need = guard.lightnessSeparation[tone];
12013
+ if (!need) return base;
12014
+ const target = brand.l + need.direction * need.minGap * 1.15;
12015
+ return need.direction > 0 ? Math.max(base, target) : Math.min(base, target);
12016
+ };
12017
+ const clampSeparatedHex = (tone, hex) => {
12018
+ const need = guard.lightnessSeparation[tone];
12019
+ if (!need) return hex;
12020
+ const current = hexToOklch(hex);
12021
+ const floor = primaryFinal.l + need.direction * need.minGap * 1.15;
12022
+ const clamped = need.direction > 0 ? Math.max(current.l, floor) : Math.min(current.l, floor);
12023
+ return Math.abs(clamped - current.l) < 1e-6 ? hex : oklchToHex({ ...current, l: clamped });
12024
+ };
12025
+ const solveDir = (tone) => {
12026
+ const need = guard.lightnessSeparation[tone];
12027
+ return need ? need.direction > 0 ? "lighten" : "darken" : void 0;
12028
+ };
12029
+ const dangerSeed = oklchToHex({ l: separatedL("danger", banded(0.6)), c: toneChroma(0.95), h: anchors.tones.danger });
12030
+ const danger = clampSeparatedHex("danger", dangerSeed);
12031
+ const success = oklchToHex({ l: separatedL("success", banded(0.58)), c: toneChroma(0.85), h: anchors.tones.success });
12032
+ const warning = oklchToHex({ l: separatedL("warning", banded(0.72)), c: toneChroma(0.9), h: anchors.tones.warning });
12033
+ void firstPass;
12034
+ const infoSolved = ensureContrast(
12035
+ oklchToHex({ l: banded(0.6), c: toneChroma(0.9), h: anchors.tones.info }),
12036
+ SOLVER_DEPS
12037
+ );
12038
+ const info = infoSolved.bg;
12039
+ const infoFg = infoSolved.fg;
11651
12040
  const ensureBrandTone = (seed) => {
11652
- let bg = oklchToHex(seed);
11653
- let toneFg = bestFg(bg);
11654
- for (let i = 0; i < 16 && contrastRatio(bg, toneFg) < 4.5; i++) {
11655
- const cur = hexToOklch(bg);
11656
- bg = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11657
- toneFg = bestFg(bg);
11658
- }
11659
- return { bg, fg: toneFg, soft: hexWithAlpha(bg, 0.12) };
12041
+ const solved = ensureContrast(oklchToHex(seed), SOLVER_DEPS);
12042
+ return { bg: solved.bg, fg: solved.fg, soft: hexWithAlpha(solved.bg, 0.12) };
11660
12043
  };
11661
12044
  const secondaryTone = ensureBrandTone({
11662
- l: Math.min(0.72, Math.max(0.45, brand.l + 0.04)),
11663
- c: Math.max(brand.c, 0.1) * 0.9,
11664
- h: (brand.h + 48) % 360
12045
+ l: banded(Math.min(0.72, Math.max(0.45, brand.l + 0.04))),
12046
+ c: Math.max(brand.c, 0.1) * 0.9 * params.chromaMul,
12047
+ h: anchors.tones.secondary
11665
12048
  });
11666
12049
  const accentTone = ensureBrandTone({
11667
- l: Math.min(0.78, Math.max(0.48, brand.l + 0.08)),
11668
- c: Math.max(brand.c, 0.1) * 0.85,
11669
- h: (brand.h + 160) % 360
12050
+ l: banded(Math.min(0.78, Math.max(0.48, brand.l + 0.08))),
12051
+ c: Math.max(brand.c, 0.1) * 0.85 * params.chromaMul,
12052
+ h: anchors.tones.accent
11670
12053
  });
11671
12054
  const neutralTone = ensureBrandTone({
11672
12055
  l: 0.18,
11673
12056
  c: grayChroma * 1.4,
11674
12057
  h: grayHue
11675
12058
  });
11676
- const successFg = (() => {
11677
- let bg = success;
11678
- let fg2 = bestFg(bg);
11679
- for (let i = 0; i < 16 && contrastRatio(bg, fg2) < 4.5; i++) {
11680
- const cur = hexToOklch(bg);
11681
- bg = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11682
- fg2 = bestFg(bg);
11683
- }
11684
- return { bg, fg: fg2 };
11685
- })();
11686
- const warningFg = (() => {
11687
- let bg = warning;
11688
- let fg2 = bestFg(bg);
11689
- for (let i = 0; i < 16 && contrastRatio(bg, fg2) < 4.5; i++) {
11690
- const cur = hexToOklch(bg);
11691
- bg = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11692
- fg2 = bestFg(bg);
11693
- }
11694
- return { bg, fg: fg2 };
11695
- })();
12059
+ const clampSeparated = (tone, solved) => {
12060
+ const need = guard.lightnessSeparation[tone];
12061
+ if (!need) return solved;
12062
+ const current = hexToOklch(solved.bg);
12063
+ const floor = primaryFinal.l + need.direction * need.minGap * 1.15;
12064
+ const clamped = need.direction > 0 ? Math.max(current.l, floor) : Math.min(current.l, floor);
12065
+ if (Math.abs(clamped - current.l) < 1e-6) return solved;
12066
+ const bg = oklchToHex({ ...current, l: clamped });
12067
+ return { bg, fg: bestFg(bg) };
12068
+ };
12069
+ const successFg = clampSeparated(
12070
+ "success",
12071
+ ensureContrast(success, SOLVER_DEPS, params.targets.fgOnTone, void 0, solveDir("success"))
12072
+ );
12073
+ const warningFg = clampSeparated(
12074
+ "warning",
12075
+ ensureContrast(warning, SOLVER_DEPS, params.targets.fgOnTone, void 0, solveDir("warning"))
12076
+ );
11696
12077
  const bgPage = gray(0.965);
11697
12078
  let textPrimary = gray(0.25);
11698
- for (let i = 0; i < 16 && contrastRatio(bgPage, textPrimary) < 4.5; i++) {
12079
+ for (let i = 0; i < 16 && contrastRatio(bgPage, textPrimary) < params.targets.textOnPage; i++) {
11699
12080
  const cur = hexToOklch(textPrimary);
11700
12081
  textPrimary = oklchToHex({ ...cur, l: cur.l - 0.04 });
11701
12082
  }
12083
+ const glassShadow = hexWithAlpha(scale["500"], 0.14);
12084
+ const glassShadowSoft = hexWithAlpha(scale["500"], 0.09);
11702
12085
  const cssVars = {
12086
+ // 玻璃材质:面/强面/高光边/彩色投影
12087
+ "--soma-surface-glass": "rgba(255, 255, 255, 0.72)",
12088
+ "--soma-surface-glass-strong": "rgba(255, 255, 255, 0.88)",
12089
+ "--soma-surface-glass-weak": "rgba(255, 255, 255, 0.52)",
12090
+ "--soma-edge-highlight": "rgba(255, 255, 255, 0.72)",
12091
+ "--soma-shadow-tinted": `0 24px 70px ${glassShadow}`,
12092
+ "--soma-shadow-tinted-soft": `0 16px 36px ${glassShadowSoft}`,
12093
+ // 环境光(--soma-ambient-1/2/3)不在这里产:它取自**最终生效**的色板,
12094
+ // 必须排在 ⑥ 的 overrides 之后(S7′),否则 daisy × aurora 会出现
12095
+ // "表面一个色系、光球另一个色系"——与 ⑥.1 修过的是同一类病
12096
+ ...sceneStructureTokens(axes),
11703
12097
  "--soma-c-primary": ensuredPrimary,
11704
12098
  "--soma-c-primary-hover": hover,
11705
12099
  "--soma-c-primary-active": active2,
@@ -11763,7 +12157,7 @@ function deriveTheme(input) {
11763
12157
  "--soma-shadow-overlay": "0 20px 40px rgba(0, 0, 0, 0.2)",
11764
12158
  "--soma-marquee-duration": "18s",
11765
12159
  // 图表序列色板:亮色下压暗一档,保证在白底上足够沉稳
11766
- ...chartSeries(brand.h, Math.max(brand.c, 0.12), 0.62)
12160
+ ...chartSeries(brand.h, Math.max(brand.c, 0.12), 0.62, chartAnchorsOrNull)
11767
12161
  };
11768
12162
  STEPS.forEach((step) => {
11769
12163
  cssVars[`--soma-brand-${step}`] = scale[step];
@@ -11771,19 +12165,32 @@ function deriveTheme(input) {
11771
12165
  const darkPrimaryIdx = Math.max(3, primaryIdx - 1);
11772
12166
  let darkPrimary = scale[STEPS[darkPrimaryIdx]];
11773
12167
  let darkFg = bestFg(darkPrimary);
11774
- for (let i = 0; i < 16 && contrastRatio(darkPrimary, darkFg) < 4.5; i++) {
12168
+ for (let i = 0; i < 16 && contrastRatio(darkPrimary, darkFg) < params.darkTargets.fgOnTone; i++) {
11775
12169
  const cur = hexToOklch(darkPrimary);
11776
12170
  darkPrimary = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11777
12171
  darkFg = bestFg(darkPrimary);
11778
12172
  }
11779
12173
  const darkHover = oklchToHex({ ...hexToOklch(darkPrimary), l: hexToOklch(darkPrimary).l + 0.05 });
11780
- const darkDanger = oklchToHex({ l: 0.68, c: Math.max(brand.c, 0.12) * 0.9, h: 27 });
11781
- const darkSuccess = oklchToHex({ l: 0.66, c: Math.max(brand.c, 0.12) * 0.8, h: 150 });
11782
- const darkWarning = oklchToHex({ l: 0.76, c: Math.max(brand.c, 0.12) * 0.85, h: 75 });
12174
+ const darkToneHues = axes.palette.harmony === "functional" && axes.palette.semantics === "faithful" && axes.palette.chroma === "balanced" && axes.palette.accents.length === 0 ? FUNCTIONAL_HUES : anchors.tones;
12175
+ const darkDanger = oklchToHex({
12176
+ l: 0.68,
12177
+ c: Math.max(brand.c, 0.12) * 0.9 * params.chromaMul,
12178
+ h: darkToneHues.danger
12179
+ });
12180
+ const darkSuccess = oklchToHex({
12181
+ l: 0.66,
12182
+ c: Math.max(brand.c, 0.12) * 0.8 * params.chromaMul,
12183
+ h: darkToneHues.success
12184
+ });
12185
+ const darkWarning = oklchToHex({
12186
+ l: 0.76,
12187
+ c: Math.max(brand.c, 0.12) * 0.85 * params.chromaMul,
12188
+ h: darkToneHues.warning
12189
+ });
11783
12190
  const darkSuccessEnsured = (() => {
11784
12191
  let bg = darkSuccess;
11785
12192
  let fg2 = bestFg(bg);
11786
- for (let i = 0; i < 16 && contrastRatio(bg, fg2) < 4.5; i++) {
12193
+ for (let i = 0; i < 16 && contrastRatio(bg, fg2) < params.darkTargets.fgOnTone; i++) {
11787
12194
  const cur = hexToOklch(bg);
11788
12195
  bg = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11789
12196
  fg2 = bestFg(bg);
@@ -11793,23 +12200,27 @@ function deriveTheme(input) {
11793
12200
  const darkWarningEnsured = (() => {
11794
12201
  let bg = darkWarning;
11795
12202
  let fg2 = bestFg(bg);
11796
- for (let i = 0; i < 16 && contrastRatio(bg, fg2) < 4.5; i++) {
12203
+ for (let i = 0; i < 16 && contrastRatio(bg, fg2) < params.darkTargets.fgOnTone; i++) {
11797
12204
  const cur = hexToOklch(bg);
11798
12205
  bg = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11799
12206
  fg2 = bestFg(bg);
11800
12207
  }
11801
12208
  return { bg, fg: fg2 };
11802
12209
  })();
11803
- let darkInfo = oklchToHex({ l: 0.68, c: Math.max(brand.c, 0.12) * 0.85, h: 230 });
12210
+ let darkInfo = oklchToHex({
12211
+ l: 0.68,
12212
+ c: Math.max(brand.c, 0.12) * 0.85 * params.chromaMul,
12213
+ h: darkToneHues.info
12214
+ });
11804
12215
  let darkInfoFg = bestFg(darkInfo);
11805
- for (let i = 0; i < 16 && contrastRatio(darkInfo, darkInfoFg) < 4.5; i++) {
12216
+ for (let i = 0; i < 16 && contrastRatio(darkInfo, darkInfoFg) < params.darkTargets.fgOnTone; i++) {
11806
12217
  const cur = hexToOklch(darkInfo);
11807
12218
  darkInfo = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
11808
12219
  darkInfoFg = bestFg(darkInfo);
11809
12220
  }
11810
12221
  const darkBgPage = gray(0.18);
11811
12222
  let darkTextPrimary = gray(0.92);
11812
- for (let i = 0; i < 16 && contrastRatio(darkBgPage, darkTextPrimary) < 4.5; i++) {
12223
+ for (let i = 0; i < 16 && contrastRatio(darkBgPage, darkTextPrimary) < params.darkTargets.textOnPage; i++) {
11813
12224
  const cur = hexToOklch(darkTextPrimary);
11814
12225
  darkTextPrimary = oklchToHex({ ...cur, l: cur.l + 0.04 });
11815
12226
  }
@@ -11851,6 +12262,14 @@ function deriveTheme(input) {
11851
12262
  "--soma-c-info-soft": hexWithAlpha(darkInfo, 0.16),
11852
12263
  // 暗色下的阴影:亮色那套 rgba(0,0,0,.06~.16) 落在深底上等于不存在,
11853
12264
  // 层级会整个塌掉。加深并加大扩散,让浮层仍然"浮"得起来
12265
+ // 暗色玻璃:半透明**黑**而不是白——白玻璃落在深底上会变成一块发光的板,
12266
+ // 层级反而糊掉。高光边同理减弱,只留一线。
12267
+ "--soma-surface-glass": "rgba(255, 255, 255, 0.06)",
12268
+ "--soma-surface-glass-strong": "rgba(255, 255, 255, 0.1)",
12269
+ "--soma-surface-glass-weak": "rgba(255, 255, 255, 0.04)",
12270
+ "--soma-edge-highlight": "rgba(255, 255, 255, 0.12)",
12271
+ "--soma-shadow-tinted": "0 24px 70px rgba(0, 0, 0, 0.55)",
12272
+ "--soma-shadow-tinted-soft": "0 16px 36px rgba(0, 0, 0, 0.45)",
11854
12273
  "--soma-shadow-sm": "0 1px 2px rgba(0, 0, 0, 0.5)",
11855
12274
  "--soma-shadow-md": "0 6px 16px rgba(0, 0, 0, 0.55)",
11856
12275
  "--soma-shadow-lg": "0 16px 40px rgba(0, 0, 0, 0.6)",
@@ -11860,7 +12279,7 @@ function deriveTheme(input) {
11860
12279
  "--soma-text-secondary": gray(0.72),
11861
12280
  "--soma-text-disabled": gray(0.45),
11862
12281
  // 图表序列色板(暗色):提亮一档,深底上才看得清;色相与亮色一一对应,换模式不会"换了一张图"
11863
- ...chartSeries(brand.h, Math.max(brand.c, 0.12), 0.72),
12282
+ ...chartSeries(brand.h, Math.max(brand.c, 0.12), 0.72, chartAnchorsOrNull),
11864
12283
  "--soma-text-inverse": gray(0.2),
11865
12284
  "--soma-text-link": darkPrimary,
11866
12285
  "--soma-text-link-hover": darkHover,
@@ -11886,6 +12305,20 @@ function deriveTheme(input) {
11886
12305
  enforceContrastPairs(darkCssVars);
11887
12306
  deriveOnSoftTokens(cssVars, false);
11888
12307
  deriveOnSoftTokens(darkCssVars, true);
12308
+ const rescale = input.overrides?.["--soma-c-primary"] ? (primaryHex) => {
12309
+ const p = hexToOklch(primaryHex);
12310
+ const rebuilt = {};
12311
+ STEPS.forEach((step, i) => {
12312
+ rebuilt[step] = oklchToHex({
12313
+ l: LIGHTNESS[i],
12314
+ c: Math.max(p.c, 0.02) * CHROMA_CURVE[i],
12315
+ h: p.h
12316
+ });
12317
+ });
12318
+ return rebuilt;
12319
+ } : null;
12320
+ Object.assign(cssVars, sceneColorTokens(cssVars, axes, params.fieldAlphas, hexWithAlpha, scale, rescale));
12321
+ Object.assign(darkCssVars, sceneColorTokens(darkCssVars, axes, params.fieldAlphas, hexWithAlpha, scale, rescale));
11889
12322
  return {
11890
12323
  scale,
11891
12324
  cssVars,
@@ -11893,7 +12326,14 @@ function deriveTheme(input) {
11893
12326
  contrast: {
11894
12327
  primaryFg: contrastRatio(cssVars["--soma-c-primary"], cssVars["--soma-c-primary-fg"]),
11895
12328
  darkPrimaryFg: contrastRatio(darkCssVars["--soma-c-primary"], darkCssVars["--soma-c-primary-fg"])
11896
- }
12329
+ },
12330
+ meta: { axes, separationApplied: guard.applied, pushed: guard.pushed }
12331
+ };
12332
+ }
12333
+ function themeRootAttributes(theme) {
12334
+ return {
12335
+ "data-soma-semantics": theme.meta.axes.palette.semantics,
12336
+ "data-soma-field": theme.meta.axes.scene.field
11897
12337
  };
11898
12338
  }
11899
12339
  function nearestIndex(ladder, value) {
@@ -11920,6 +12360,9 @@ function applyTheme(input, root) {
11920
12360
  el.classList.add(THEME_SWITCHING_CLASS);
11921
12361
  try {
11922
12362
  writeTokensBatch(el, input.dark ? theme.darkCssVars : theme.cssVars);
12363
+ for (const [name, value] of Object.entries(themeRootAttributes(theme))) {
12364
+ el.setAttribute(name, value);
12365
+ }
11923
12366
  } finally {
11924
12367
  scheduleThemeTransitionRelease(el);
11925
12368
  }
@@ -12056,6 +12499,13 @@ function installSomaErrorReporter(options) {
12056
12499
  }
12057
12500
 
12058
12501
  // core/client/engine/soma-bootstrap.ts
12502
+ function isSomaDeclarationSource(value) {
12503
+ return value.split("\n").some((line) => {
12504
+ const text = line.trim();
12505
+ if (!text || text.startsWith("#")) return false;
12506
+ return text === "{{";
12507
+ });
12508
+ }
12059
12509
  function reportToConsole(event) {
12060
12510
  console.error(`[soma-core][\u53EF\u89C2\u6D4B] ${JSON.stringify(event)}`);
12061
12511
  }
@@ -12111,10 +12561,15 @@ var SomaBootstrap = class {
12111
12561
  this.scheduler.setDiagnostics(this.diagnostics);
12112
12562
  }
12113
12563
  this.container = container;
12564
+ if (assets.uiYaml && isSomaDeclarationSource(assets.uiYaml)) {
12565
+ throw new Error(
12566
+ "[SomaBootstrap] \u6536\u5230\u672A\u7F16\u8BD1\u7684 SOMA DSL \u6E90\u58F0\u660E\u3002\u8BF7\u5148\u7528 compilePageAssets\uFF08\u6784\u5EFA/\u6D4B\u8BD5\uFF09\u6216 Host \u9875\u9762\u7F16\u8BD1\u5165\u53E3\u751F\u6210\u8FD0\u884C\u65F6\u8D44\u4EA7\u3002"
12567
+ );
12568
+ }
12114
12569
  this.assets = { ...assets };
12115
- const parsed = this.assetResolver.resolve(assets);
12116
- this.adapter.mount(container, assets.html, assets.includes);
12117
- this.setupComponentManager(container, assets, parsed.uiConfig);
12570
+ const parsed = this.assetResolver.resolve(this.assets);
12571
+ this.adapter.mount(container, this.assets.html, this.assets.includes);
12572
+ this.setupComponentManager(container, this.assets, parsed.uiConfig);
12118
12573
  this.applyHostTheme(parsed.appConfig);
12119
12574
  this.domainInstance = this.createDomainInstance(assets.DomainClass, parsed, assets.routerPath);
12120
12575
  this.prepareDataLayer(this.domainInstance, assets);
@@ -12565,6 +13020,65 @@ var SomaBootstrap = class {
12565
13020
  }
12566
13021
  };
12567
13022
 
13023
+ // core/client/component/example-v2.ts
13024
+ var UI_PREFIX = "ui:";
13025
+ var EVENT_PREFIX = "event:";
13026
+ function balancedSlice(text, start) {
13027
+ let depth = 1;
13028
+ for (let i = start; i < text.length; i += 1) {
13029
+ const ch = text[i];
13030
+ if (ch === "{" || ch === "[") depth += 1;
13031
+ else if (ch === "}" || ch === "]") {
13032
+ depth -= 1;
13033
+ if (depth === 0) return text.slice(start, i).trim();
13034
+ }
13035
+ }
13036
+ return null;
13037
+ }
13038
+ function lineAfter(lines, prefix) {
13039
+ const hit = lines.find((line) => line.trimStart().startsWith(prefix));
13040
+ return hit ? hit.trimStart().slice(prefix.length).trim() : null;
13041
+ }
13042
+ function parseV1Example(example) {
13043
+ const lines = example.split("\n");
13044
+ const ui = lineAfter(lines, UI_PREFIX);
13045
+ if (!ui) return null;
13046
+ const head = /^([A-Za-z_][\w-]*)\s*:\s*\{\s*props\s*:\s*\{/.exec(ui);
13047
+ if (!head) return null;
13048
+ const [, anchor] = head;
13049
+ const propsBody = balancedSlice(ui, head[0].length);
13050
+ if (propsBody === null) return null;
13051
+ const emits = [];
13052
+ const event = lineAfter(lines, EVENT_PREFIX);
13053
+ if (event && !event.startsWith("\uFF08") && event !== "") {
13054
+ const at = event.indexOf(":");
13055
+ if (at > 0) {
13056
+ const key = event.slice(0, at).trim();
13057
+ const expr = event.slice(at + 1).trim();
13058
+ const dot = key.indexOf(".");
13059
+ if (dot > 0 && key.slice(0, dot) === anchor) {
13060
+ emits.push([key.slice(dot + 1), expr]);
13061
+ }
13062
+ }
13063
+ }
13064
+ return { anchor, propsBody: propsBody.trim(), emits };
13065
+ }
13066
+ function deriveV2Example(componentName, example) {
13067
+ const parsed = parseV1Example(example);
13068
+ if (!parsed) return null;
13069
+ const lines = [
13070
+ `${parsed.anchor}:`,
13071
+ ` component: ${componentName}`,
13072
+ " ui: { \u2026\u540C\u4E0A props\u2026 }"
13073
+ ];
13074
+ if (parsed.emits.length > 0) {
13075
+ lines.push(" event:");
13076
+ lines.push(" on:");
13077
+ for (const [name, expr] of parsed.emits) lines.push(` ${name}: ${expr}`);
13078
+ }
13079
+ return lines.join("\n");
13080
+ }
13081
+
12568
13082
  // core/client/component/ai-catalog.ts
12569
13083
  function inferGeometryFamily(contract) {
12570
13084
  const name = contract.name;
@@ -12714,6 +13228,14 @@ function renderMarkdown(entries, conventions) {
12714
13228
  lines.push("```");
12715
13229
  lines.push(entry.ai.example.trimEnd());
12716
13230
  lines.push("```");
13231
+ const v2 = deriveV2Example(entry.name, entry.ai.example);
13232
+ if (v2) {
13233
+ lines.push("");
13234
+ lines.push("v2\uFF08html \u540C\u4E0A\uFF0C_ui.yaml \u6539\u5757\u58F0\u660E\uFF09\uFF1A");
13235
+ lines.push("```");
13236
+ lines.push(v2);
13237
+ lines.push("```");
13238
+ }
12717
13239
  }
12718
13240
  if (entry.ai?.antiPatterns?.length) {
12719
13241
  lines.push("");
@@ -12864,25 +13386,149 @@ function rawTier(value, bounds) {
12864
13386
  return tier;
12865
13387
  }
12866
13388
 
12867
- // core/build/compiler/soma-precompile.ts
12868
- var PRECOMPILE_PARSE_OPTIONS = { adaptiveVocabularyRequired: false };
12869
- function precompileUiYaml(yamlStr) {
12870
- const raw = yaml.load(yamlStr);
12871
- const uiConfig = parseUiConfig(raw, PRECOMPILE_PARSE_OPTIONS);
12872
- return JSON.stringify(uiConfig);
12873
- }
12874
- function precompileEventYaml(yamlStr) {
12875
- const raw = yamlStr.trim() ? yaml.load(yamlStr) : {};
12876
- const compiled = compileEventConfigFromRaw(raw);
12877
- return JSON.stringify(compiled);
12878
- }
12879
- function precompileStyleYaml(yamlStr) {
12880
- const raw = yaml.load(yamlStr);
12881
- if (!raw) {
12882
- return "undefined";
13389
+ // core/build/v2/soma-file-loader.ts
13390
+ var SomaV2ParseError = class extends Error {
13391
+ constructor(message, blockId, line) {
13392
+ const where = blockId ? `\uFF08\u5757: ${blockId}${line ? `\uFF0C\u7B2C ${line} \u884C` : ""}\uFF09` : "";
13393
+ super(`[soma-core][\u5F15\u64CE] ${message}${where}`);
13394
+ this.blockId = blockId;
13395
+ this.line = line;
13396
+ this.name = "SomaV2ParseError";
13397
+ }
13398
+ };
13399
+ var PAGE_BLOCK_ID = "page";
13400
+ function stripSwitch(uiYamlRaw) {
13401
+ const lines = uiYamlRaw.split("\n");
13402
+ let openIndex = -1;
13403
+ for (let i = 0; i < lines.length; i += 1) {
13404
+ const text = lines[i].trim();
13405
+ if (text === "" || text.startsWith("#")) continue;
13406
+ if (text !== "{{") {
13407
+ throw new SomaV2ParseError("v2 \u58F0\u660E\u5FC5\u987B\u4EE5 `{{` \u5F00\u5173\u884C\u5F00\u5934");
13408
+ }
13409
+ openIndex = i;
13410
+ break;
13411
+ }
13412
+ if (openIndex === -1) {
13413
+ throw new SomaV2ParseError("\u6587\u4EF6\u4E3A\u7A7A\u6216\u53EA\u6709\u6CE8\u91CA\uFF0C\u627E\u4E0D\u5230 `{{` \u5F00\u5173\u884C");
13414
+ }
13415
+ let closeIndex = -1;
13416
+ for (let i = lines.length - 1; i > openIndex; i -= 1) {
13417
+ const text = lines[i].trim();
13418
+ if (text === "") continue;
13419
+ if (text !== "}}") {
13420
+ throw new SomaV2ParseError("v2 \u58F0\u660E\u5FC5\u987B\u4EE5 `}}` \u6536\u53E3\u884C\u7ED3\u5C3E\uFF08\u5F00\u5173\u6210\u5BF9\uFF0C\u6574\u6587\u4EF6\u4E00\u5BF9\uFF09");
13421
+ }
13422
+ closeIndex = i;
13423
+ break;
13424
+ }
13425
+ if (closeIndex === -1) {
13426
+ throw new SomaV2ParseError("`{{` \u5F00\u5173\u672A\u95ED\u5408\u2014\u2014\u7F3A\u5C11 `}}` \u6536\u53E3\u884C");
13427
+ }
13428
+ return {
13429
+ inner: lines.slice(openIndex + 1, closeIndex).join("\n"),
13430
+ offset: openIndex + 1
13431
+ };
13432
+ }
13433
+ function parseSomaV2Container(uiYamlRaw) {
13434
+ const { inner, offset } = stripSwitch(uiYamlRaw);
13435
+ let doc;
13436
+ try {
13437
+ doc = yaml.load(inner);
13438
+ } catch (error) {
13439
+ throw new SomaV2ParseError(`YAML \u89E3\u6790\u5931\u8D25: ${error.message}`);
13440
+ }
13441
+ if (doc === null || doc === void 0) {
13442
+ return { doc: {}, inner, offset };
13443
+ }
13444
+ if (typeof doc !== "object" || Array.isArray(doc)) {
13445
+ throw new SomaV2ParseError("\u5F00\u5173\u5185\u5FC5\u987B\u662F\u5757\u6620\u5C04\uFF08\u9876\u5C42\u952E = \u5757 id\uFF09");
13446
+ }
13447
+ for (const [blockId, body] of Object.entries(doc)) {
13448
+ if (body === null || body === void 0) {
13449
+ throw new SomaV2ParseError("\u5757\u4F53\u4E3A\u7A7A\u2014\u2014\u4E0D\u9700\u8981\u58F0\u660E\u7684\u7EC4\u4EF6\u8BF7\u76F4\u63A5\u5220\u6389\u8FD9\u4E2A\u5757", blockId);
13450
+ }
13451
+ if (typeof body !== "object" || Array.isArray(body)) {
13452
+ throw new SomaV2ParseError("\u5757\u4F53\u5FC5\u987B\u662F\u6620\u5C04\uFF08ui/data/event \u4E09\u6BB5\uFF09", blockId);
13453
+ }
13454
+ }
13455
+ return { doc, inner, offset };
13456
+ }
13457
+ function loadSomaFile(input) {
13458
+ const { doc, inner, offset } = parseSomaV2Container(input.uiYamlRaw);
13459
+ if (Object.keys(doc).length === 0) return [];
13460
+ const innerLines = inner.split("\n");
13461
+ const lineOfKey = (key) => {
13462
+ const index = innerLines.findIndex((line) => line.startsWith(`${key}:`));
13463
+ return index === -1 ? offset : offset + index + 1;
13464
+ };
13465
+ const blocks = [];
13466
+ const seen = /* @__PURE__ */ new Set();
13467
+ for (const [blockId, body] of Object.entries(doc)) {
13468
+ const line = lineOfKey(blockId);
13469
+ assertBlockId(blockId, input.htmlIndex, line);
13470
+ if (seen.has(blockId)) {
13471
+ throw new SomaV2ParseError(`\u5757 "${blockId}" \u91CD\u590D\u58F0\u660E`, blockId, line);
13472
+ }
13473
+ if (body === null || body === void 0) {
13474
+ throw new SomaV2ParseError("\u5757\u4F53\u4E3A\u7A7A\u2014\u2014\u4E0D\u9700\u8981\u58F0\u660E\u7684\u7EC4\u4EF6\u8BF7\u76F4\u63A5\u5220\u6389\u8FD9\u4E2A\u5757", blockId, line);
13475
+ }
13476
+ if (typeof body !== "object" || Array.isArray(body)) {
13477
+ throw new SomaV2ParseError("\u5757\u4F53\u5FC5\u987B\u662F\u6620\u5C04\uFF08ui/data/event \u4E09\u6BB5\uFF09", blockId, line);
13478
+ }
13479
+ seen.add(blockId);
13480
+ blocks.push({ blockId, body, line, source: "inline" });
13481
+ }
13482
+ for (const [blockId, raw] of input.externalBlocks ?? /* @__PURE__ */ new Map()) {
13483
+ assertBlockId(blockId, input.htmlIndex, 0);
13484
+ if (seen.has(blockId)) {
13485
+ throw new SomaV2ParseError(
13486
+ `\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`,
13487
+ blockId
13488
+ );
13489
+ }
13490
+ let body;
13491
+ try {
13492
+ body = yaml.load(raw);
13493
+ } catch (error) {
13494
+ throw new SomaV2ParseError(
13495
+ `\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u89E3\u6790\u5931\u8D25: ${error.message}`,
13496
+ blockId
13497
+ );
13498
+ }
13499
+ if (body === null || body === void 0) {
13500
+ throw new SomaV2ParseError(`\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u4E3A\u7A7A`, blockId);
13501
+ }
13502
+ if (typeof body !== "object" || Array.isArray(body)) {
13503
+ throw new SomaV2ParseError(`\u5916\u7F6E\u5757 blocks/${blockId}.yaml \u5FC5\u987B\u662F\u6620\u5C04`, blockId);
13504
+ }
13505
+ seen.add(blockId);
13506
+ blocks.push({ blockId, body, line: 1, source: "external" });
13507
+ }
13508
+ return blocks;
13509
+ }
13510
+ function assertBlockId(blockId, htmlIndex, line) {
13511
+ if (blockId === PAGE_BLOCK_ID) return;
13512
+ if (htmlIndex.instances.has(blockId)) return;
13513
+ if (htmlIndex.anchors.has(blockId)) {
13514
+ throw new SomaV2ParseError(
13515
+ `"${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`,
13516
+ blockId,
13517
+ line
13518
+ );
12883
13519
  }
12884
- const styleConfig = parseStyleConfig(raw);
12885
- return JSON.stringify(styleConfig);
13520
+ const known = [...htmlIndex.instances].slice(0, 8).join("\u3001");
13521
+ throw new SomaV2ParseError(
13522
+ `HTML \u91CC\u6CA1\u6709\u5B9E\u4F8B\u951A\u70B9 "${blockId}"${known ? `\uFF08\u73B0\u6709\u5B9E\u4F8B\uFF1A${known}\uFF09` : ""}`,
13523
+ blockId,
13524
+ line
13525
+ );
13526
+ }
13527
+
13528
+ // core/build/compiler/soma-precompile.ts
13529
+ function precompileUiModule(yamlStr) {
13530
+ parseSomaV2Container(yamlStr);
13531
+ return "null";
12886
13532
  }
12887
13533
  function compileEventConfigFromRaw(raw) {
12888
13534
  const { eventsRaw, triggers, timers } = splitEventConfigRaw(raw);
@@ -12898,9 +13544,6 @@ function compileDataConfig(yamlStr) {
12898
13544
  }
12899
13545
  return parseDataConfig(yaml.load(yamlStr));
12900
13546
  }
12901
- function precompileDataYaml(yamlStr) {
12902
- return JSON.stringify(compileDataConfig(yamlStr));
12903
- }
12904
13547
  function precompileYaml(yamlStr) {
12905
13548
  const obj = yaml.load(yamlStr);
12906
13549
  return JSON.stringify(obj ?? {});
@@ -12909,9 +13552,6 @@ function precompileYaml(yamlStr) {
12909
13552
  // core/build/compiler/rollup-plugin-soma.ts
12910
13553
  function somaRollupPlugin(options = {}) {
12911
13554
  const uiSuffix = options.uiSuffix ?? "_ui.yaml";
12912
- const eventSuffix = options.eventSuffix ?? "_event.yaml";
12913
- const styleSuffix = options.styleSuffix ?? "_style.yaml";
12914
- const dataSuffix = options.dataSuffix ?? "_data.yaml";
12915
13555
  return {
12916
13556
  name: "rollup-plugin-soma",
12917
13557
  transform(code, id) {
@@ -12920,16 +13560,10 @@ function somaRollupPlugin(options = {}) {
12920
13560
  }
12921
13561
  try {
12922
13562
  if (id.endsWith(uiSuffix)) {
12923
- return { code: `export default ${precompileUiYaml(code)};`, map: { mappings: "" } };
12924
- }
12925
- if (id.endsWith(eventSuffix)) {
12926
- return { code: `export default ${precompileEventYaml(code)};`, map: { mappings: "" } };
13563
+ return { code: `export default ${precompileUiModule(code)};`, map: { mappings: "" } };
12927
13564
  }
12928
- if (id.endsWith(styleSuffix)) {
12929
- return { code: `export default ${precompileStyleYaml(code)};`, map: { mappings: "" } };
12930
- }
12931
- if (id.endsWith(dataSuffix)) {
12932
- return { code: `export default ${precompileDataYaml(code)};`, map: { mappings: "" } };
13565
+ if (/_((event)|(style)|(data))\.ya?ml$/.test(id)) {
13566
+ 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");
12933
13567
  }
12934
13568
  return { code: `export default ${precompileYaml(code)};`, map: { mappings: "" } };
12935
13569
  } catch (err) {
@@ -13386,19 +14020,23 @@ function createGeneratedPagePreview(target, components, options = {}) {
13386
14020
  } : {}
13387
14021
  });
13388
14022
  const usable = compiled !== void 0 && compiled.uiConfig !== void 0 && compiled.eventConfig !== void 0;
14023
+ if (!usable) {
14024
+ throw new Error(
14025
+ "[soma-core][\u58F0\u660E\u6E32\u67D3] \u7F3A\u5C11\u5B8C\u6574\u7684\u670D\u52A1\u7AEF\u7F16\u8BD1\u4EA7\u7269\u3002\u6D4F\u89C8\u5668\u4E0D\u89E3\u6790 SOMA DSL \u6E90\u58F0\u660E\uFF1B\u8BF7\u7531\u751F\u6210/\u6CE8\u518C\u670D\u52A1\u8FD4\u56DE compiled \u8D44\u4EA7\u3002"
14026
+ );
14027
+ }
13389
14028
  await next.mount(container, {
13390
14029
  html: decl.html,
13391
- uiYaml: decl.uiYaml,
13392
- eventYaml: decl.eventYaml ?? "",
13393
- styleYaml: decl.styleYaml,
14030
+ uiYaml: "",
14031
+ eventYaml: "",
14032
+ styleYaml: "",
13394
14033
  DomainClass: getPreviewPageRoot(),
13395
- ...usable ? {
13396
- uiConfig: compiled.uiConfig,
13397
- eventConfig: compiled.eventConfig,
13398
- triggerConfig: compiled.triggerConfig,
13399
- timerConfig: compiled.timerConfig,
13400
- ...compiled.styleConfig !== void 0 ? { styleConfig: compiled.styleConfig } : {}
13401
- } : {}
14034
+ uiConfig: compiled.uiConfig,
14035
+ eventConfig: compiled.eventConfig,
14036
+ triggerConfig: compiled.triggerConfig,
14037
+ timerConfig: compiled.timerConfig,
14038
+ ...compiled.styleConfig !== void 0 ? { styleConfig: compiled.styleConfig } : {},
14039
+ ...compiled.dataConfig !== void 0 ? { dataConfig: compiled.dataConfig } : {}
13402
14040
  });
13403
14041
  bootstrap = next;
13404
14042
  },
@@ -13609,6 +14247,79 @@ function ensurePackBaseStyles(composed, options = {}) {
13609
14247
  });
13610
14248
  }
13611
14249
 
14250
+ // core/client/component/contract-compat.ts
14251
+ function checkOverrideCompat(winner, base) {
14252
+ const issues = [];
14253
+ const winnerProps = winner.props ?? {};
14254
+ const baseProps = base.props ?? {};
14255
+ for (const [name, baseProp] of Object.entries(baseProps)) {
14256
+ const winnerProp = winnerProps[name];
14257
+ if (!winnerProp) {
14258
+ issues.push({
14259
+ kind: "prop-missing",
14260
+ member: name,
14261
+ detail: `\u7F3A\u5C11 prop "${name}"\uFF08${describeProp(baseProp)}\uFF09\u2014\u2014\u5B58\u91CF\u9875\u9762\u4ECD\u4F1A\u4F20\u5B83\uFF0C\u8986\u76D6\u540E\u8FD9\u4E2A\u503C\u65E0\u5904\u53EF\u53BB`
14262
+ });
14263
+ continue;
14264
+ }
14265
+ if (winnerProp.type !== baseProp.type) {
14266
+ issues.push({
14267
+ kind: "prop-type-changed",
14268
+ member: name,
14269
+ detail: `prop "${name}" \u7684 type \u4ECE "${baseProp.type}" \u53D8\u6210 "${winnerProp.type}"\u2014\u2014\u9875\u9762\u4F20\u4E0B\u6765\u7684\u503C\u5F62\u72B6\u4E0D\u53D8\uFF0C\u8BFB\u6CD5\u5374\u53D8\u4E86`
14270
+ });
14271
+ continue;
14272
+ }
14273
+ if (winnerProp.required === true && baseProp.required !== true) {
14274
+ issues.push({
14275
+ kind: "prop-required-tightened",
14276
+ member: name,
14277
+ detail: `prop "${name}" \u4ECE\u53EF\u9009\u6536\u7D27\u4E3A\u5FC5\u586B\u2014\u2014\u5B58\u91CF\u9875\u9762\u6CA1\u4F20\u5B83\u7684\u5730\u65B9\u4F1A\u7F3A\u5FC5\u586B`
14278
+ });
14279
+ continue;
14280
+ }
14281
+ if (baseProp.required !== true && !sameDefault(winnerProp.default, baseProp.default)) {
14282
+ issues.push({
14283
+ kind: "prop-default-diverged",
14284
+ member: name,
14285
+ detail: `\u53EF\u9009 prop "${name}" \u7684 default \u4ECE ${formatValue(baseProp.default)} \u53D8\u6210 ${formatValue(winnerProp.default)}\u2014\u2014\u7ED3\u6784\u517C\u5BB9\u4F46\u884C\u4E3A\u4F1A\u9759\u9ED8\u6539\u53D8\uFF1A\u5B58\u91CF\u9875\u9762\u6CA1\u4F20\u8FD9\u4E2A prop \u7684\u5730\u65B9\uFF0C\u6E32\u67D3\u7ED3\u679C\u76F4\u63A5\u8DDF\u7740\u53D8`
14286
+ });
14287
+ }
14288
+ }
14289
+ const baseEmits = Object.keys(base.emits ?? {});
14290
+ const winnerEmits = new Set(Object.keys(winner.emits ?? {}));
14291
+ for (const name of baseEmits) {
14292
+ if (!winnerEmits.has(name)) {
14293
+ issues.push({
14294
+ kind: "emit-missing",
14295
+ member: name,
14296
+ detail: `\u7F3A\u5C11 emit "${name}"\u2014\u2014\u5B58\u91CF\u9875\u9762\u7684 _event.yaml \u4ECD\u8BA2\u9605\u7740\u5B83\uFF0C\u8986\u76D6\u540E\u70B9\u4E86\u6CA1\u53CD\u5E94`
14297
+ });
14298
+ }
14299
+ }
14300
+ return issues;
14301
+ }
14302
+ function sameDefault(a, b) {
14303
+ if (a === b) return true;
14304
+ if (a === void 0 || b === void 0) return false;
14305
+ try {
14306
+ return JSON.stringify(a) === JSON.stringify(b);
14307
+ } catch {
14308
+ return false;
14309
+ }
14310
+ }
14311
+ function describeProp(prop) {
14312
+ return prop.required === true ? `${prop.type}\uFF0C\u5FC5\u586B` : `${prop.type}\uFF0C\u53EF\u9009`;
14313
+ }
14314
+ function formatValue(value) {
14315
+ if (value === void 0) return "\u672A\u8BBE\u7F6E";
14316
+ try {
14317
+ return JSON.stringify(value) ?? String(value);
14318
+ } catch {
14319
+ return String(value);
14320
+ }
14321
+ }
14322
+
13612
14323
  // core/client/component/component-pack.ts
13613
14324
  var PACK_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
13614
14325
  var ComponentPackError = class extends Error {
@@ -13654,33 +14365,52 @@ function composeComponentPacks(packs, options = {}) {
13654
14365
  );
13655
14366
  }
13656
14367
  }
14368
+ const { table: overrideTable, source: overrideSource } = resolveOverrideTable(packs, allowOverride);
14369
+ const versionOf = new Map(packs.map((pack) => [pack.name, pack.version]));
14370
+ const providers = /* @__PURE__ */ new Map();
13657
14371
  for (const pack of packs) {
13658
14372
  for (const [name, definition] of Object.entries(pack.components)) {
13659
- const previous = provenance[name];
13660
- if (previous === void 0) {
13661
- components[name] = definition;
13662
- provenance[name] = pack.name;
13663
- continue;
13664
- }
13665
- const winner = allowOverride[name];
13666
- if (winner === void 0) {
13667
- throw new ComponentPackError(
13668
- `\u7EC4\u4EF6\u540D\u51B2\u7A81\uFF1A"${name}" \u540C\u65F6\u6765\u81EA\u5305 "${previous}" \u4E0E "${pack.name}"\u3002
14373
+ const list = providers.get(name) ?? [];
14374
+ list.push({ pack: pack.name, definition });
14375
+ providers.set(name, list);
14376
+ }
14377
+ }
14378
+ for (const [name, list] of providers) {
14379
+ if (list.length === 1) {
14380
+ components[name] = list[0].definition;
14381
+ provenance[name] = list[0].pack;
14382
+ continue;
14383
+ }
14384
+ const winnerName = overrideTable[name];
14385
+ if (winnerName === void 0) {
14386
+ const [first, second] = list;
14387
+ throw new ComponentPackError(
14388
+ `\u7EC4\u4EF6\u540D\u51B2\u7A81\uFF1A"${name}" \u540C\u65F6\u6765\u81EA\u5305 ${list.map((item) => `"${item.pack}"`).join(" \u4E0E ")}\u3002
13669
14389
  \u5408\u6210\u9ED8\u8BA4\u62D2\u7EDD\u91CD\u540D\u2014\u2014\u9759\u9ED8\u8986\u76D6\u4F1A\u8BA9"\u9875\u9762\u7528\u7684\u662F\u54EA\u4E2A\u7EC4\u4EF6"\u53EA\u80FD\u9760\u987A\u5E8F\u731C\u3002
13670
- \u786E\u5B9E\u8981\u8986\u76D6\u5C31\u663E\u5F0F\u58F0\u660E\uFF1AcomposeComponentPacks(..., { allowOverride: { ${name}: '\u5305\u540D' } })`
13671
- );
13672
- }
13673
- const record = overrides[name] ?? { winner, shadowed: [] };
13674
- if (pack.name === winner) {
13675
- components[name] = definition;
13676
- if (!record.shadowed.includes(previous)) record.shadowed.push(previous);
13677
- } else {
13678
- if (!record.shadowed.includes(pack.name)) record.shadowed.push(pack.name);
13679
- }
13680
- provenance[name] = winner;
13681
- overrides[name] = record;
14390
+ \u786E\u5B9E\u8981\u8986\u76D6\uFF0C\u4E24\u6761\u5199\u6CD5\u4E8C\u9009\u4E00\uFF1A
14391
+ \u2460 \u5728\u8986\u76D6\u65B9\u7684\u5951\u7EA6\u91CC\u58F0\u660E\uFF1Aoverrides: '${first.pack}'\uFF08\u610F\u56FE\u4E0E\u7EC4\u4EF6\u540C\u5904\uFF0C\u63A8\u8350\uFF09
14392
+ \u2461 \u5728\u5BBF\u4E3B bootstrap \u91CC\u88C1\u51B3\uFF1AcomposeComponentPacks(..., { allowOverride: { ${name}: '${second.pack}' } })`
14393
+ );
14394
+ }
14395
+ const winner = list.find((item) => item.pack === winnerName);
14396
+ if (!winner) {
14397
+ throw new ComponentPackError(
14398
+ `"${name}" \u7684\u8986\u76D6\u88C1\u51B3\u6307\u5411\u5305 "${winnerName}"\uFF0C\u4F46\u8BE5\u5305\u6CA1\u6709\u63D0\u4F9B\u8FD9\u4E2A\u7EC4\u4EF6`
14399
+ );
13682
14400
  }
14401
+ const shadowed = list.filter((item) => item.pack !== winnerName);
14402
+ for (const loser of shadowed) {
14403
+ assertOverrideCompat(name, winnerName, loser.pack, winner.definition, loser.definition);
14404
+ }
14405
+ components[name] = winner.definition;
14406
+ provenance[name] = winnerName;
14407
+ overrides[name] = {
14408
+ winner: winnerName,
14409
+ shadowed: shadowed.map((item) => item.pack),
14410
+ source: overrideSource[name] ?? "allowOverride"
14411
+ };
13683
14412
  }
14413
+ reportOverrides(overrides, versionOf, options.onOverride);
13684
14414
  const composed = {
13685
14415
  components,
13686
14416
  provenance,
@@ -13694,6 +14424,86 @@ function composeComponentPacks(packs, options = {}) {
13694
14424
  components: attachPackStyles(composed, { nonce: options.styleNonce ?? null })
13695
14425
  };
13696
14426
  }
14427
+ function resolveOverrideTable(packs, allowOverride) {
14428
+ const table = {};
14429
+ const source = {};
14430
+ const packByName = new Map(packs.map((pack) => [pack.name, pack]));
14431
+ for (const pack of packs) {
14432
+ for (const [name, definition] of Object.entries(pack.components)) {
14433
+ const target = definition?.contract?.overrides;
14434
+ if (!target) continue;
14435
+ if (target === pack.name) {
14436
+ throw new ComponentPackError(
14437
+ `\u5305 "${pack.name}" \u7684\u7EC4\u4EF6 "${name}" \u58F0\u660E overrides: "${target}" \u6307\u5411\u81EA\u5DF1\u2014\u2014\u8986\u76D6\u662F\u8DE8\u5305\u7684\u4E8B\uFF0C\u540C\u5305\u5185\u91CD\u540D\u8BF7\u76F4\u63A5\u6539\u540D`
14438
+ );
14439
+ }
14440
+ const targetPack = packByName.get(target);
14441
+ if (!targetPack) {
14442
+ throw new ComponentPackError(
14443
+ `\u7EC4\u4EF6 "${name}"\uFF08\u6765\u81EA\u5305 "${pack.name}"\uFF09\u58F0\u660E overrides: "${target}"\uFF0C\u4F46\u5305 "${target}" \u4E0D\u5728\u672C\u6B21\u5408\u6210\u91CC\u3002
14444
+ \u58F0\u660E\u5931\u6548\u591A\u534A\u610F\u5473\u7740\u5305\u540D\u5199\u9519\u6216\u8BE5\u5305\u6CA1\u88AB\u5F15\u5165\u2014\u2014\u9759\u9ED8\u5FFD\u7565\u4F1A\u8BA9\u4F60\u4EE5\u4E3A\u8986\u76D6\u751F\u6548\u4E86`
14445
+ );
14446
+ }
14447
+ if (!(name in targetPack.components)) {
14448
+ throw new ComponentPackError(
14449
+ `\u7EC4\u4EF6 "${name}"\uFF08\u6765\u81EA\u5305 "${pack.name}"\uFF09\u58F0\u660E overrides: "${target}"\uFF0C\u4F46\u5305 "${target}" \u91CC\u6CA1\u6709\u53EB "${name}" \u7684\u7EC4\u4EF6\u3002
14450
+ \u591A\u534A\u662F\u88AB\u8986\u76D6\u7684\u7EC4\u4EF6\u6539\u4E86\u540D\u2014\u2014\u8BF7\u5BF9\u9F50\u7EC4\u4EF6\u540D\uFF0C\u6216\u5220\u6389\u8FD9\u6761 overrides \u58F0\u660E`
14451
+ );
14452
+ }
14453
+ const existing = table[name];
14454
+ if (existing !== void 0 && existing !== pack.name) {
14455
+ if (allowOverride[name] === void 0) {
14456
+ throw new ComponentPackError(
14457
+ `\u7EC4\u4EF6 "${name}" \u6709\u4E24\u4E2A\u8986\u76D6\u8005\uFF1A\u5305 "${existing}" \u4E0E\u5305 "${pack.name}" \u90FD\u58F0\u660E\u8981\u8986\u76D6\u5B83\u3002
14458
+ \u5E73\u53F0\u4E0D\u66FF\u4F60\u9009\u8FB9\u2014\u2014\u8BF7\u5728\u5BBF\u4E3B bootstrap \u91CC\u88C1\u51B3\uFF1A
14459
+ composeComponentPacks(..., { allowOverride: { ${name}: '\u5305\u540D' } })`
14460
+ );
14461
+ }
14462
+ continue;
14463
+ }
14464
+ table[name] = pack.name;
14465
+ source[name] = "contract";
14466
+ }
14467
+ }
14468
+ for (const [name, winner] of Object.entries(allowOverride)) {
14469
+ table[name] = winner;
14470
+ source[name] = "allowOverride";
14471
+ }
14472
+ return { table, source };
14473
+ }
14474
+ function assertOverrideCompat(name, winnerPack, loserPack, winnerDefinition, loserDefinition) {
14475
+ const winnerContract = winnerDefinition?.contract;
14476
+ const loserContract = loserDefinition?.contract;
14477
+ if (!winnerContract || !loserContract) return;
14478
+ const issues = checkOverrideCompat(winnerContract, loserContract);
14479
+ if (issues.length === 0) return;
14480
+ throw new ComponentPackError(
14481
+ `\u5305 "${winnerPack}" \u7684 "${name}" \u8986\u76D6\u5305 "${loserPack}" \u7684\u540C\u540D\u7EC4\u4EF6\uFF0C\u4F46\u5951\u7EA6\u4E0D\u517C\u5BB9\uFF1A
14482
+ ${issues.map((issue) => ` \xB7 ${issue.detail}`).join("\n")}
14483
+ \u5B58\u91CF\u9875\u9762\u662F\u5BF9\u7740\u88AB\u8986\u76D6\u8005\u7684\u5951\u7EA6\u5199\u7684\u2014\u2014\u8986\u76D6\u8005\u5FC5\u987B\u6536\u5F97\u4E0B\u5B83\u4EEC\u4F20\u7684 props\u3001\u53D1\u5F97\u51FA\u5B83\u4EEC\u8BA2\u9605\u7684 emit\u3002
14484
+ \uFF08\u95F8\u95E8\u53EA\u4FDD\u8BC1\u7ED3\u6784\u517C\u5BB9\uFF0C\u4E0D\u4FDD\u8BC1\u884C\u4E3A\u7B49\u4EF7\uFF1A\u6E32\u67D3\u7EC6\u8282\u4ECD\u9700\u4F60\u81EA\u5DF1\u7684\u6D4B\u8BD5\u515C\u5E95\uFF09`
14485
+ );
14486
+ }
14487
+ function reportOverrides(overrides, versionOf, onOverride) {
14488
+ for (const [name, record] of Object.entries(overrides)) {
14489
+ const event = {
14490
+ name,
14491
+ winner: record.winner,
14492
+ winnerVersion: versionOf.get(record.winner) ?? "?",
14493
+ shadowed: record.shadowed.map((pack) => ({ pack, version: versionOf.get(pack) ?? "?" })),
14494
+ source: record.source
14495
+ };
14496
+ if (onOverride) {
14497
+ onOverride(event);
14498
+ continue;
14499
+ }
14500
+ const shadowed = event.shadowed.map((item) => `${item.pack}@${item.version}`).join("\u3001");
14501
+ const via = event.source === "contract" ? "\u5951\u7EA6\u58F0\u660E" : "allowOverride";
14502
+ console.info(
14503
+ `[soma-core][\u7EC4\u4EF6] ${name}: ${event.winner}@${event.winnerVersion} \u8986\u76D6 ${shadowed}\uFF08${via}\uFF09`
14504
+ );
14505
+ }
14506
+ }
13697
14507
  function composeStyles(packs, provenance) {
13698
14508
  const components = {};
13699
14509
  const shared = {};
@@ -13932,6 +14742,1163 @@ function physicalDirections(css) {
13932
14742
  }
13933
14743
  return [...found];
13934
14744
  }
14745
+
14746
+ // core/client/parser/value-lang.ts
14747
+ var SomaValueLangError = class extends Error {
14748
+ constructor(message, raw) {
14749
+ super(`[soma-core][\u5F15\u64CE] ${message}\uFF08\u503C: "${raw}"\uFF09`);
14750
+ this.raw = raw;
14751
+ this.name = "SomaValueLangError";
14752
+ }
14753
+ };
14754
+ var ARITH_HINT = /[+\-*/()]/;
14755
+ var FORBIDDEN = /(>=|<=|==|!=|&&|\|\||[<>?])/;
14756
+ var PATH_SHAPE = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)*$/;
14757
+ function tokenize(raw, source) {
14758
+ const tokens = [];
14759
+ let i = 0;
14760
+ while (i < raw.length) {
14761
+ const ch = raw[i];
14762
+ if (ch === " " || ch === " ") {
14763
+ i += 1;
14764
+ continue;
14765
+ }
14766
+ if (ch === "(" || ch === ")") {
14767
+ tokens.push({ t: ch });
14768
+ i += 1;
14769
+ continue;
14770
+ }
14771
+ if (ch === "+" || ch === "-" || ch === "*" || ch === "/") {
14772
+ tokens.push({ t: "op", v: ch });
14773
+ i += 1;
14774
+ continue;
14775
+ }
14776
+ if (/[0-9]/.test(ch)) {
14777
+ let j = i;
14778
+ while (j < raw.length && /[0-9.]/.test(raw[j])) j += 1;
14779
+ const text = raw.slice(i, j);
14780
+ const value = Number(text);
14781
+ if (!Number.isFinite(value)) {
14782
+ throw new SomaValueLangError(`\u6570\u5B57\u5B57\u9762\u91CF\u975E\u6CD5: "${text}"`, source);
14783
+ }
14784
+ tokens.push({ t: "num", v: value });
14785
+ i = j;
14786
+ continue;
14787
+ }
14788
+ if (/[A-Za-z_]/.test(ch)) {
14789
+ let j = i;
14790
+ while (j < raw.length && /[A-Za-z0-9_.]/.test(raw[j])) j += 1;
14791
+ tokens.push({ t: "id", v: raw.slice(i, j) });
14792
+ i = j;
14793
+ continue;
14794
+ }
14795
+ throw new SomaValueLangError(
14796
+ `\u65E0\u6CD5\u8BC6\u522B\u7684\u5B57\u7B26 "${ch}"\u2014\u2014\u7B97\u672F\u53EA\u652F\u6301\u8DEF\u5F84\u3001\u6570\u5B57\u3001+ - * / \u4E0E\u62EC\u53F7`,
14797
+ source
14798
+ );
14799
+ }
14800
+ return tokens;
14801
+ }
14802
+ var Parser = class {
14803
+ constructor(tokens, source, hasVar, paths) {
14804
+ this.tokens = tokens;
14805
+ this.source = source;
14806
+ this.hasVar = hasVar;
14807
+ this.paths = paths;
14808
+ this.pos = 0;
14809
+ }
14810
+ parse() {
14811
+ const node = this.expression();
14812
+ if (this.pos < this.tokens.length) {
14813
+ throw new SomaValueLangError("\u7B97\u672F\u8868\u8FBE\u5F0F\u6709\u591A\u4F59\u8BCD\u5143\uFF08\u62EC\u53F7\u662F\u5426\u914D\u5BF9\uFF1F\uFF09", this.source);
14814
+ }
14815
+ return node;
14816
+ }
14817
+ /** 表达式 := 项 { ("+"|"-") 项 } */
14818
+ expression() {
14819
+ let left = this.term();
14820
+ for (; ; ) {
14821
+ const token = this.tokens[this.pos];
14822
+ if (token?.t === "op" && (token.v === "+" || token.v === "-")) {
14823
+ this.pos += 1;
14824
+ left = { kind: "arith", op: token.v, left, right: this.term() };
14825
+ continue;
14826
+ }
14827
+ return left;
14828
+ }
14829
+ }
14830
+ /** 项 := 因子 { ("*"|"/") 因子 } */
14831
+ term() {
14832
+ let left = this.factor();
14833
+ for (; ; ) {
14834
+ const token = this.tokens[this.pos];
14835
+ if (token?.t === "op" && (token.v === "*" || token.v === "/")) {
14836
+ this.pos += 1;
14837
+ left = { kind: "arith", op: token.v, left, right: this.factor() };
14838
+ continue;
14839
+ }
14840
+ return left;
14841
+ }
14842
+ }
14843
+ /** 因子 := 路径 | 数字 | "(" 表达式 ")" | "-" 因子 */
14844
+ factor() {
14845
+ const token = this.tokens[this.pos];
14846
+ if (!token) {
14847
+ throw new SomaValueLangError("\u7B97\u672F\u8868\u8FBE\u5F0F\u4E0D\u5B8C\u6574\uFF08\u7F3A\u5C11\u8FD0\u7B97\u6570\uFF09", this.source);
14848
+ }
14849
+ if (token.t === "op" && token.v === "-") {
14850
+ this.pos += 1;
14851
+ return { kind: "neg", operand: this.factor() };
14852
+ }
14853
+ if (token.t === "num") {
14854
+ this.pos += 1;
14855
+ return { kind: "lit", value: token.v };
14856
+ }
14857
+ if (token.t === "id") {
14858
+ this.pos += 1;
14859
+ return this.pathNode(token.v);
14860
+ }
14861
+ if (token.t === "(") {
14862
+ this.pos += 1;
14863
+ const inner = this.expression();
14864
+ if (this.tokens[this.pos]?.t !== ")") {
14865
+ throw new SomaValueLangError("\u62EC\u53F7\u672A\u95ED\u5408", this.source);
14866
+ }
14867
+ this.pos += 1;
14868
+ return inner;
14869
+ }
14870
+ throw new SomaValueLangError("\u7B97\u672F\u8868\u8FBE\u5F0F\u4E2D\u51FA\u73B0\u610F\u5916\u8BCD\u5143", this.source);
14871
+ }
14872
+ pathNode(text) {
14873
+ if (text === "true" || text === "false") {
14874
+ return { kind: "lit", value: text === "true" };
14875
+ }
14876
+ const head = text.split(".")[0];
14877
+ if (!this.hasVar(head)) {
14878
+ throw new SomaValueLangError(
14879
+ `\u8DEF\u5F84 "${text}" \u7684\u9996\u6BB5 "${head}" \u4E0D\u5728\u5F53\u524D\u4F5C\u7528\u57DF\u2014\u2014\u7B97\u672F\u53EA\u63A5\u53D7\u7ED1\u5B9A\u8DEF\u5F84\u4E0E\u6570\u5B57`,
14880
+ this.source
14881
+ );
14882
+ }
14883
+ this.paths.push(text);
14884
+ return { kind: "path", path: text };
14885
+ }
14886
+ };
14887
+ function isArithSegment(segment) {
14888
+ return ARITH_HINT.test(segment);
14889
+ }
14890
+ function parseValueSegment(segment, hasVar, position = "display", source = segment) {
14891
+ const raw = segment.trim();
14892
+ if (!raw) {
14893
+ throw new SomaValueLangError("\u503C\u6BB5\u4E3A\u7A7A", source);
14894
+ }
14895
+ const forbidden = raw.match(FORBIDDEN);
14896
+ if (forbidden) {
14897
+ throw new SomaValueLangError(
14898
+ `\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 "${forbidden[0]}"\u2014\u2014\u6BD4\u8F83\u4E0E\u5E03\u5C14\u8FD0\u7B97\u4E0D\u8FDB DSL\uFF0C\u5224\u65AD\u5199\u8FDB Domain\uFF08\u663E\u9690\u7528 when + ! \u524D\u7F00\uFF0C\u591A\u5206\u652F\u7528 match \u7BA1\u9053\u6216\u7EC4\u4EF6\u591A\u6001\uFF09`,
14899
+ source
14900
+ );
14901
+ }
14902
+ if (!isArithSegment(raw)) {
14903
+ if (/^-?\d+(\.\d+)?$/.test(raw)) {
14904
+ return { node: { kind: "lit", value: Number(raw) }, paths: [] };
14905
+ }
14906
+ if (raw === "true" || raw === "false") {
14907
+ return { node: { kind: "lit", value: raw === "true" }, paths: [] };
14908
+ }
14909
+ const head = raw.split(/[.\s]/)[0];
14910
+ if (hasVar(head)) {
14911
+ if (!PATH_SHAPE.test(raw)) {
14912
+ throw new SomaValueLangError(
14913
+ `\u8DEF\u5F84 "${raw}" \u542B\u975E\u6CD5\u5B57\u7B26\u2014\u2014\u8DEF\u5F84\u53EA\u5141\u8BB8\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u4E0E\u70B9\uFF08\u82E5\u672C\u610F\u662F\u5B57\u9762\u91CF\u6587\u6848\uFF0C\u8BF7\u6362\u4E00\u4E2A\u4E0D\u4EE5\u4F5C\u7528\u57DF\u53D8\u91CF\u5F00\u5934\u7684\u5199\u6CD5\u6216\u52A0\u5F15\u53F7\uFF09`,
14914
+ source
14915
+ );
14916
+ }
14917
+ return { node: { kind: "path", path: raw }, paths: [raw] };
14918
+ }
14919
+ return { node: { kind: "lit", value: raw }, paths: [] };
14920
+ }
14921
+ if (position !== "display") {
14922
+ throw new SomaValueLangError(
14923
+ `\u7B97\u672F\u53EA\u5141\u8BB8\u51FA\u73B0\u5728\u5C55\u793A\u503C\u4F4D\uFF0C\u5F53\u524D\u4F4D\u7F6E\u662F ${position}\u2014\u2014\u7B97\u51FA\u6765\u7684\u503C\u4E0D\u9A71\u52A8\u884C\u4E3A\uFF0C\u4E1A\u52A1\u5224\u65AD\u7559\u5728 Domain`,
14924
+ source
14925
+ );
14926
+ }
14927
+ const paths = [];
14928
+ const node = new Parser(tokenize(raw, source), source, hasVar, paths).parse();
14929
+ return { node, paths };
14930
+ }
14931
+ function isPlainPath(node) {
14932
+ return node.kind === "path";
14933
+ }
14934
+ function evaluateValueNode(node, read, options = {}) {
14935
+ switch (node.kind) {
14936
+ case "lit":
14937
+ return node.value;
14938
+ case "path":
14939
+ return read(node.path);
14940
+ case "neg": {
14941
+ const operand = toNumber(evaluateValueNode(node.operand, read, options), node, options);
14942
+ return operand === null ? null : -operand;
14943
+ }
14944
+ case "arith": {
14945
+ const left = toNumber(evaluateValueNode(node.left, read, options), node, options);
14946
+ const right = toNumber(evaluateValueNode(node.right, read, options), node, options);
14947
+ if (left === null || right === null) return null;
14948
+ if (node.op === "/" && right === 0) {
14949
+ if (options.dev) {
14950
+ throw new SomaValueLangError("\u9664\u6570\u4E3A 0", describeNode(node));
14951
+ }
14952
+ return null;
14953
+ }
14954
+ switch (node.op) {
14955
+ case "+":
14956
+ return left + right;
14957
+ case "-":
14958
+ return left - right;
14959
+ case "*":
14960
+ return left * right;
14961
+ case "/":
14962
+ return left / right;
14963
+ }
14964
+ }
14965
+ }
14966
+ return null;
14967
+ }
14968
+ function toNumber(value, node, options) {
14969
+ if (typeof value === "number" && Number.isFinite(value)) return value;
14970
+ if (typeof value === "string" && value.trim() !== "") {
14971
+ const parsed = Number(value);
14972
+ if (Number.isFinite(parsed)) return parsed;
14973
+ }
14974
+ if (options.dev) {
14975
+ throw new SomaValueLangError(
14976
+ `\u7B97\u672F\u8FD0\u7B97\u6570\u4E0D\u662F\u6570\u503C: ${JSON.stringify(value)}`,
14977
+ describeNode(node)
14978
+ );
14979
+ }
14980
+ return null;
14981
+ }
14982
+ function describeNode(node) {
14983
+ switch (node.kind) {
14984
+ case "lit":
14985
+ return String(node.value);
14986
+ case "path":
14987
+ return node.path;
14988
+ case "neg":
14989
+ return `-${describeNode(node.operand)}`;
14990
+ case "arith":
14991
+ return `${describeNode(node.left)} ${node.op} ${describeNode(node.right)}`;
14992
+ }
14993
+ }
14994
+
14995
+ // core/build/v2/html-index.ts
14996
+ var ANCHOR_RE = /data-soma-id=["']([^"']+)["']/g;
14997
+ var COMPONENT_NEAR_RE = /data-soma-component=["']([^"']+)["']/;
14998
+ var HOST_RE = /data-soma-host=["']([^"']+)["']/;
14999
+ var TEMPLATE_OPEN_RE = /<template[^>]*data-soma-role=["']([^"']+)["'][^>]*>/gi;
15000
+ function buildHtmlAnchorIndex(html) {
15001
+ const anchors = /* @__PURE__ */ new Map();
15002
+ const instances = /* @__PURE__ */ new Set();
15003
+ const duplicates = [];
15004
+ const templateRanges = [];
15005
+ for (const match of html.matchAll(TEMPLATE_OPEN_RE)) {
15006
+ const start = match.index ?? 0;
15007
+ const closeIndex = html.indexOf("</template>", start);
15008
+ templateRanges.push({
15009
+ start,
15010
+ end: closeIndex === -1 ? html.length : closeIndex,
15011
+ role: match[1]
15012
+ });
15013
+ }
15014
+ const lineAt = (index) => html.slice(0, index).split("\n").length;
15015
+ const roleAt = (index) => templateRanges.find((range) => index > range.start && index < range.end)?.role;
15016
+ const ownerListAt = (index) => {
15017
+ const range = templateRanges.find((r) => index > r.start && index < r.end);
15018
+ if (!range) return void 0;
15019
+ const before = html.slice(0, range.start);
15020
+ const matches = [...before.matchAll(/<[a-zA-Z][^>]*data-soma-id=["']([^"']+)["'][^>]*>/g)];
15021
+ return matches.length > 0 ? matches[matches.length - 1][1] : void 0;
15022
+ };
15023
+ const tagRe = /<[a-zA-Z][^>]*>/g;
15024
+ for (const tagMatch of html.matchAll(tagRe)) {
15025
+ const tag = tagMatch[0];
15026
+ const tagIndex = tagMatch.index ?? 0;
15027
+ ANCHOR_RE.lastIndex = 0;
15028
+ const idMatch = ANCHOR_RE.exec(tag);
15029
+ if (!idMatch) continue;
15030
+ const somaId = idMatch[1];
15031
+ if (anchors.has(somaId)) {
15032
+ if (!duplicates.includes(somaId)) duplicates.push(somaId);
15033
+ continue;
15034
+ }
15035
+ const componentMatch = COMPONENT_NEAR_RE.exec(tag);
15036
+ const role = roleAt(tagIndex);
15037
+ const owner = role !== void 0 ? ownerListAt(tagIndex) : void 0;
15038
+ const info = {
15039
+ somaId,
15040
+ line: lineAt(tagIndex),
15041
+ inRowTemplate: role !== void 0,
15042
+ ...role ? { rowRole: role } : {},
15043
+ ...owner ? { ownerList: owner } : {},
15044
+ ...componentMatch ? { component: componentMatch[1] } : {}
15045
+ };
15046
+ anchors.set(somaId, info);
15047
+ if (componentMatch) instances.add(somaId);
15048
+ }
15049
+ const hostMatch = HOST_RE.exec(html);
15050
+ return {
15051
+ anchors,
15052
+ instances,
15053
+ duplicates,
15054
+ ...hostMatch ? { host: hostMatch[1] } : {}
15055
+ };
15056
+ }
15057
+
15058
+ // core/client/parser/v2/namespace.ts
15059
+ var SomaScopeError = class extends Error {
15060
+ constructor(message, blockId) {
15061
+ super(`[soma-core][\u5F15\u64CE] ${message}\uFF08\u5757: ${blockId}\uFF09`);
15062
+ this.blockId = blockId;
15063
+ this.name = "SomaScopeError";
15064
+ }
15065
+ };
15066
+ var RESERVED = /* @__PURE__ */ new Set(["page", "p", "ctrl"]);
15067
+ var NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
15068
+ function buildBlockScope(input) {
15069
+ const blockId = input.blockId;
15070
+ const dataNames = new Set(input.dataNames ?? []);
15071
+ const rowVars = new Set(input.rowVars ?? []);
15072
+ const aliases = /* @__PURE__ */ new Map();
15073
+ for (const name of dataNames) {
15074
+ if (RESERVED.has(name)) {
15075
+ throw new SomaScopeError(`data \u5BF9\u8C61\u540D "${name}" \u662F\u4FDD\u7559\u540D\uFF08page/p/ctrl\uFF09`, blockId);
15076
+ }
15077
+ if (!NAME_RE.test(name)) {
15078
+ throw new SomaScopeError(`data \u5BF9\u8C61\u540D "${name}" \u975E\u6CD5\uFF08\u5B57\u6BCD\u5F00\u5934\uFF0C\u5B57\u6BCD\u6570\u5B57\u4E0B\u5212\u7EBF\uFF09`, blockId);
15079
+ }
15080
+ if (rowVars.has(name)) {
15081
+ throw new SomaScopeError(
15082
+ `data \u5BF9\u8C61\u540D "${name}" \u4E0E\u884C\u53D8\u91CF\u540C\u540D\u2014\u2014\u540C\u4E00\u4E2A\u540D\u5B57\u4E24\u79CD\u542B\u4E49\uFF0C\u89E3\u6790\u65F6\u65E0\u6CD5\u5224\u5B9A`,
15083
+ blockId
15084
+ );
15085
+ }
15086
+ }
15087
+ for (const [name, raw] of Object.entries(input.aliasRaw ?? {})) {
15088
+ if (typeof raw !== "string" || raw.trim() === "") {
15089
+ throw new SomaScopeError(`alias "${name}" \u7684\u503C\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`, blockId);
15090
+ }
15091
+ if (!NAME_RE.test(name)) {
15092
+ throw new SomaScopeError(`alias \u540D "${name}" \u975E\u6CD5\uFF08\u5B57\u6BCD\u5F00\u5934\uFF0C\u5B57\u6BCD\u6570\u5B57\u4E0B\u5212\u7EBF\uFF09`, blockId);
15093
+ }
15094
+ if (RESERVED.has(name) || dataNames.has(name) || rowVars.has(name)) {
15095
+ throw new SomaScopeError(
15096
+ `alias "${name}" \u906E\u853D\u4E86\u5DF2\u6709\u540D\u5B57\uFF08\u4FDD\u7559\u540D/data \u5BF9\u8C61/\u884C\u53D8\u91CF\uFF09\u2014\u2014\u522B\u540D\u4E0D\u5F97\u6539\u53D8\u65E2\u6709\u540D\u5B57\u7684\u542B\u4E49`,
15097
+ blockId
15098
+ );
15099
+ }
15100
+ const target = raw.trim();
15101
+ const kind = target.startsWith("/") ? "api" : "path";
15102
+ if (kind === "path") {
15103
+ const head = target.split(".")[0];
15104
+ if (aliases.has(head)) {
15105
+ throw new SomaScopeError(
15106
+ `alias "${name}" \u6307\u5411\u53E6\u4E00\u4E2A\u522B\u540D "${head}"\u2014\u2014\u522B\u540D\u4E0D\u5F97\u9012\u5F52\uFF08\u5C55\u5F00\u987A\u5E8F\u4F1A\u53D8\u6210\u9690\u85CF\u89C4\u5219\uFF09`,
15107
+ blockId
15108
+ );
15109
+ }
15110
+ }
15111
+ aliases.set(name, { kind, target });
15112
+ }
15113
+ return { blockId, dataNames, aliases, rowVars, pageVar: "page" };
15114
+ }
15115
+ function resolvePath(raw, scope) {
15116
+ const text = raw.trim();
15117
+ if (text === "") return { kind: "literal" };
15118
+ const segments = text.split(".");
15119
+ const head = segments[0];
15120
+ const alias = scope.aliases.get(head);
15121
+ if (alias?.kind === "path") {
15122
+ const expanded = [alias.target, ...segments.slice(1)].join(".");
15123
+ return resolvePath(expanded, { ...scope, aliases: /* @__PURE__ */ new Map() });
15124
+ }
15125
+ const inData = scope.dataNames.has(head);
15126
+ const inRow = scope.rowVars.has(head);
15127
+ const isPage = head === scope.pageVar;
15128
+ const hits = [inData, inRow, isPage].filter(Boolean).length;
15129
+ if (hits > 1) {
15130
+ const candidates = [
15131
+ inData ? `data \u5BF9\u8C61 ${scope.blockId}.${head}` : "",
15132
+ inRow ? `\u884C\u53D8\u91CF ${head}` : "",
15133
+ isPage ? "\u9875\u9762\u53D8\u91CF page" : ""
15134
+ ].filter(Boolean);
15135
+ throw new SomaScopeError(
15136
+ `\u540D\u5B57 "${head}" \u6709\u6B67\u4E49\uFF0C\u540C\u65F6\u5339\u914D ${candidates.join(" / ")}\u2014\u2014\u8BF7\u6539\u540D\u4EE5\u6D88\u9664\u6B67\u4E49`,
15137
+ scope.blockId
15138
+ );
15139
+ }
15140
+ if (inData) {
15141
+ return { kind: "data", full: [`${scope.blockId}.${head}`, ...segments.slice(1)].join(".") };
15142
+ }
15143
+ if (inRow) return { kind: "row", full: text };
15144
+ if (isPage) return { kind: "page", full: text };
15145
+ return { kind: "literal" };
15146
+ }
15147
+ function resolveApiRef(raw, scope) {
15148
+ const text = raw.trim();
15149
+ const alias = scope.aliases.get(text);
15150
+ if (alias) {
15151
+ if (alias.kind !== "api") {
15152
+ throw new SomaScopeError(
15153
+ `"${text}" \u662F\u8DEF\u5F84\u522B\u540D\uFF0C\u4E0D\u80FD\u7528\u5728 api \u4F4D\uFF08API \u522B\u540D\u7684\u503C\u987B\u4EE5 / \u5F00\u5934\uFF09`,
15154
+ scope.blockId
15155
+ );
15156
+ }
15157
+ return alias.target;
15158
+ }
15159
+ return text;
15160
+ }
15161
+ function scopeHasVar(scope) {
15162
+ return (segment) => {
15163
+ const alias = scope.aliases.get(segment);
15164
+ if (alias?.kind === "path") return true;
15165
+ return scope.dataNames.has(segment) || scope.rowVars.has(segment) || segment === scope.pageVar;
15166
+ };
15167
+ }
15168
+ function expandPath(raw, scope) {
15169
+ const resolved = resolvePath(raw, scope);
15170
+ return resolved.kind === "literal" ? raw.trim() : resolved.full;
15171
+ }
15172
+
15173
+ // core/client/parser/v2/page-parser.ts
15174
+ var PAGE_KEYS = /* @__PURE__ */ new Set([
15175
+ "domain",
15176
+ "locale",
15177
+ "ui",
15178
+ "watch",
15179
+ "event",
15180
+ "data",
15181
+ "adaptive",
15182
+ "alias",
15183
+ // initProps:引擎启动前写入的初始值(v1 UiConfig 同名字段的直通)。
15184
+ //
15185
+ // v2 是照**手写页面**设计的——那里文案住 HTML、初值住 Domain,声明里不需要它。
15186
+ // 但 v2 产的是 v1 等价物,而生成链的页面把字面文案内联在 initProps 里
15187
+ // (模型出的是组织意图,没有 Domain 可写)。少了这个键,AI 产的页面
15188
+ // 就永远迈不过 v2 的门槛——不是"用不上 v2",是"表达不了"。
15189
+ "initProps"
15190
+ ]);
15191
+ var SUFFIXES = ["when", "model", "class"];
15192
+ function parsePageBlock(input) {
15193
+ const { body } = input;
15194
+ const fail = (message) => {
15195
+ throw new SomaV2ParseError(message, "page");
15196
+ };
15197
+ for (const key of Object.keys(body)) {
15198
+ if (!PAGE_KEYS.has(key)) {
15199
+ fail(`page \u5757\u4E0D\u652F\u6301\u952E "${key}"\uFF08\u53EF\u7528\uFF1A${[...PAGE_KEYS].join("/")}\uFF09`);
15200
+ }
15201
+ }
15202
+ const domain = body.domain;
15203
+ if (typeof domain !== "string" || domain.trim() === "") {
15204
+ fail("page \u5757\u7F3A\u5C11 domain\uFF08\u9875\u9762 Domain \u7C7B\u540D\uFF0C\u5FC5\u586B\uFF09");
15205
+ }
15206
+ const scope = buildBlockScope({
15207
+ blockId: "page",
15208
+ dataNames: Object.keys(body.data ?? {}),
15209
+ aliasRaw: body.alias
15210
+ });
15211
+ const show = {};
15212
+ const locale = body.locale;
15213
+ if (locale !== void 0) {
15214
+ if (!Array.isArray(locale)) fail("locale \u5FC5\u987B\u662F\u540D\u5355\u6570\u7EC4");
15215
+ for (const item of locale) {
15216
+ const key = String(item);
15217
+ if (!input.anchors.has(key)) {
15218
+ fail(`locale \u540D\u5355\u91CC\u7684 "${key}" \u5728 HTML \u4E2D\u6CA1\u6709\u5BF9\u5E94\u951A\u70B9`);
15219
+ }
15220
+ if (input.localeKeys && !input.localeKeys.has(key)) {
15221
+ fail(`locale \u540D\u5355\u91CC\u7684 "${key}" \u5728\u8BCD\u5178\u4E2D\u6CA1\u6709\u5BF9\u5E94\u952E`);
15222
+ }
15223
+ show[key] = `page._locale.${key}`;
15224
+ }
15225
+ }
15226
+ const uiRaw = body.ui ?? {};
15227
+ if (typeof uiRaw !== "object" || Array.isArray(uiRaw)) fail("ui \u6BB5\u5FC5\u987B\u662F\u6620\u5C04");
15228
+ parseShowLevel(uiRaw, show, scope, input, "page");
15229
+ const bind = { obj: String(domain), var: "page" };
15230
+ const watch = body.watch;
15231
+ if (watch !== void 0) {
15232
+ if (!Array.isArray(watch)) fail("watch \u5FC5\u987B\u662F\u6570\u7EC4");
15233
+ const rules = [];
15234
+ for (const item of watch) {
15235
+ if (!item || typeof item !== "object") fail("watch \u9879\u5FC5\u987B\u662F\u6620\u5C04");
15236
+ const path = item.path;
15237
+ const call = item.call;
15238
+ if (typeof path !== "string" || path.trim() === "") fail("watch \u9879\u7F3A\u5C11 path");
15239
+ if (typeof call !== "string" || call.trim() === "") fail("watch \u9879\u7F3A\u5C11 call");
15240
+ const rule = {
15241
+ condition: expandPath(String(path), scope),
15242
+ callback: String(call).includes(".") ? String(call) : `page.${call}`
15243
+ };
15244
+ if (typeof item.debounce === "number") rule.debounce = item.debounce;
15245
+ if (typeof item.refresh === "boolean") rule.refresh = item.refresh;
15246
+ rules.push(rule);
15247
+ }
15248
+ if (rules.length > 0) bind.onChange = rules;
15249
+ }
15250
+ const ui = { bind, show };
15251
+ if (body.initProps !== void 0) {
15252
+ if (body.initProps === null || typeof body.initProps !== "object" || Array.isArray(body.initProps)) {
15253
+ fail("initProps \u5FC5\u987B\u662F\u6620\u5C04\uFF08\u952E\u4E3A var \u522B\u540D\u8DEF\u5F84\uFF0C\u5982 page.title\uFF09");
15254
+ }
15255
+ ui.initProps = body.initProps;
15256
+ }
15257
+ if (body.adaptive !== void 0) {
15258
+ ui.adaptive = body.adaptive;
15259
+ }
15260
+ const eventRaw = normalizeEventSection(body.event, input, fail);
15261
+ return {
15262
+ ui,
15263
+ eventRaw,
15264
+ ...body.data ? { dataRaw: body.data } : {},
15265
+ scope
15266
+ };
15267
+ }
15268
+ function parseShowLevel(raw, target, scope, input, where) {
15269
+ const fail = (message) => {
15270
+ throw new SomaV2ParseError(message, "page");
15271
+ };
15272
+ for (const [key, value] of Object.entries(raw)) {
15273
+ if (key === "each") continue;
15274
+ const { anchor, suffix, attr } = splitKey(key);
15275
+ if (input.instances.has(anchor)) {
15276
+ fail(
15277
+ `"${anchor}" \u662F\u7EC4\u4EF6\u5B9E\u4F8B\u951A\u70B9\uFF0C\u4E0D\u80FD\u5199\u5728 page \u5757\u7684 ui \u6BB5\u2014\u2014\u7EC4\u4EF6\u7684\u4E00\u5207\u58F0\u660E\u4F4F\u5728\u5B83\u81EA\u5DF1\u7684\u5757\u91CC\uFF08\u9876\u5C42\u5199 ${anchor}:\uFF09`
15278
+ );
15279
+ }
15280
+ if (!input.anchors.has(anchor)) {
15281
+ fail(`${where} \u7684 ui \u5F15\u7528\u4E86 HTML \u4E2D\u4E0D\u5B58\u5728\u7684\u951A\u70B9 "${anchor}"`);
15282
+ }
15283
+ if (isEachBlock(value)) {
15284
+ target[anchor] = parseEachBlock(value, scope, input, anchor);
15285
+ continue;
15286
+ }
15287
+ if (suffix) {
15288
+ const existing2 = asExtended(target[anchor]);
15289
+ applySuffix(existing2, suffix, value, scope, fail);
15290
+ target[anchor] = existing2;
15291
+ continue;
15292
+ }
15293
+ if (attr) {
15294
+ if (value !== null && typeof value === "object") {
15295
+ fail(`"${key}" \u7684\u5C5E\u6027\u7ED1\u5B9A\u503C\u5FC5\u987B\u662F\u6807\u91CF\u8DEF\u5F84\uFF0C\u4E0D\u80FD\u5199\u6620\u5C04\u6216\u6570\u7EC4`);
15296
+ }
15297
+ target[`${anchor}@${attr}`] = expandValue(value, scope, fail);
15298
+ continue;
15299
+ }
15300
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
15301
+ fail(
15302
+ `"${key}" \u7684\u503C\u662F\u6620\u5C04\uFF0C\u4F46 ui \u6BB5\u53EA\u5141\u8BB8\u5E73\u94FA\u5199\u6CD5\uFF08\u663E\u9690\u7528 \u951A\u70B9.when\u3001\u6761\u4EF6\u7C7B\u7528 \u951A\u70B9.class\u3001\u5217\u8868\u7528 each\uFF09`
15303
+ );
15304
+ }
15305
+ const expanded = expandValue(value, scope, fail);
15306
+ const existing = target[anchor];
15307
+ if (existing !== void 0 && typeof existing === "object" && !Array.isArray(existing)) {
15308
+ existing.text = expanded;
15309
+ } else {
15310
+ target[anchor] = expanded;
15311
+ }
15312
+ }
15313
+ }
15314
+ function isEachBlock(value) {
15315
+ return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.each === "string";
15316
+ }
15317
+ function parseEachBlock(block, scope, input, anchor) {
15318
+ const fail = (message) => {
15319
+ throw new SomaV2ParseError(message, "page");
15320
+ };
15321
+ const raw = String(block.each);
15322
+ const match = /^(\S+)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)(?:\s+by\s+(\S+))?(?:\s+key\s+(\S+))?$/.exec(raw.trim());
15323
+ if (!match) {
15324
+ fail(`each \u8BED\u6CD5\u9519\u8BEF: "${raw}"\uFF08\u5E94\u4E3A each: \u8DEF\u5F84 as \u53D8\u91CF [by \u8DEF\u5F84] [key \u5B57\u6BB5]\uFF09`);
15325
+ }
15326
+ const [, sourcePath, rowVar, byPath] = match;
15327
+ const bind = {
15328
+ obj: expandPath(sourcePath, scope),
15329
+ var: rowVar
15330
+ };
15331
+ if (byPath) bind.role_by = byPath;
15332
+ const rowScope = {
15333
+ ...scope,
15334
+ rowVars: /* @__PURE__ */ new Set([...scope.rowVars, rowVar])
15335
+ };
15336
+ const childShow = {};
15337
+ const nested = {};
15338
+ for (const [key, value] of Object.entries(block)) {
15339
+ if (key === "each") continue;
15340
+ nested[key] = value;
15341
+ }
15342
+ parseShowLevel(nested, childShow, rowScope, input, `\u5217\u8868 ${anchor}`);
15343
+ return { bind, show: childShow };
15344
+ }
15345
+ function splitKey(key) {
15346
+ const atIndex = key.indexOf("@");
15347
+ if (atIndex > 0) {
15348
+ return { anchor: key.slice(0, atIndex), attr: key.slice(atIndex + 1) };
15349
+ }
15350
+ const dotIndex = key.lastIndexOf(".");
15351
+ if (dotIndex > 0) {
15352
+ const tail = key.slice(dotIndex + 1);
15353
+ if (SUFFIXES.includes(tail)) {
15354
+ return { anchor: key.slice(0, dotIndex), suffix: tail };
15355
+ }
15356
+ }
15357
+ return { anchor: key };
15358
+ }
15359
+ function asExtended(current) {
15360
+ if (current === void 0) return {};
15361
+ if (typeof current === "string") return { text: current };
15362
+ return current;
15363
+ }
15364
+ function applySuffix(target, suffix, value, scope, fail) {
15365
+ if (suffix === "class") {
15366
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
15367
+ fail(".class \u7684\u503C\u5FC5\u987B\u662F { \u7C7B\u540D: \u6761\u4EF6\u8DEF\u5F84 } \u6620\u5C04");
15368
+ }
15369
+ const map2 = {};
15370
+ for (const [cls, cond] of Object.entries(value)) {
15371
+ map2[cls] = expandCondition(String(cond), scope);
15372
+ }
15373
+ target.class = map2;
15374
+ return;
15375
+ }
15376
+ if (suffix === "when") {
15377
+ target.when = expandCondition(String(value), scope);
15378
+ return;
15379
+ }
15380
+ target.model = expandPath(String(value), scope);
15381
+ }
15382
+ function expandCondition(raw, scope) {
15383
+ const text = raw.trim();
15384
+ const negated = text.startsWith("!");
15385
+ const bare = negated ? text.slice(1).trim() : text;
15386
+ return `${negated ? "!" : ""}${expandPath(bare, scope)}`;
15387
+ }
15388
+ function expandValue(value, scope, fail) {
15389
+ if (value === null || value === void 0) fail("\u7ED1\u5B9A\u503C\u4E0D\u80FD\u4E3A\u7A7A");
15390
+ if (typeof value !== "string") return String(value);
15391
+ const segments = String(value).split(/\s+\|\s+/);
15392
+ segments[0] = expandPath(segments[0], scope);
15393
+ return segments.join(" | ");
15394
+ }
15395
+ function normalizeEventSection(raw, input, fail) {
15396
+ if (raw === void 0) return {};
15397
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
15398
+ fail("event \u6BB5\u5FC5\u987B\u662F\u6620\u5C04\uFF08\u5B50\u952E on / timers / triggers\uFF09");
15399
+ }
15400
+ const section = raw;
15401
+ for (const key of Object.keys(section)) {
15402
+ if (!["on", "timers", "triggers"].includes(key)) {
15403
+ fail(`page \u5757\u7684 event \u6BB5\u4E0D\u652F\u6301\u5B50\u952E "${key}"\uFF08\u53EF\u7528\uFF1Aon / timers / triggers\uFF09`);
15404
+ }
15405
+ }
15406
+ const on = section.on ?? {};
15407
+ if (typeof on !== "object" || Array.isArray(on)) fail("event.on \u5FC5\u987B\u662F\u6620\u5C04");
15408
+ for (const key of Object.keys(on)) {
15409
+ const anchor = key.split(".")[0];
15410
+ if (input.instances.has(anchor)) {
15411
+ fail(
15412
+ `"${key}" \u7684\u951A\u70B9 "${anchor}" \u662F\u7EC4\u4EF6\u5B9E\u4F8B\u2014\u2014\u7EC4\u4EF6\u4E8B\u4EF6\uFF08emit \u8DEF\u7531\uFF09\u4F4F\u5728\u8BE5\u7EC4\u4EF6\u5757\u7684 event.on \u6BB5\uFF0Cpage \u5757\u7684 event \u53EA\u9762\u5411 DOM \u4E8B\u4EF6`
15413
+ );
15414
+ }
15415
+ }
15416
+ const result = { ...on };
15417
+ if (section.timers !== void 0) result.timers = section.timers;
15418
+ if (section.triggers !== void 0) result.triggers = section.triggers;
15419
+ return result;
15420
+ }
15421
+
15422
+ // core/client/parser/v2/use-parser.ts
15423
+ var BLOCK_KEYS = /* @__PURE__ */ new Set(["component", "alias", "when", "data", "ui", "event"]);
15424
+ var DATA_OBJECT_KEYS = /* @__PURE__ */ new Set(["from", "save", "refresh", "reload_on", "fields"]);
15425
+ var EVENT_KEYS = /* @__PURE__ */ new Set(["actions", "on"]);
15426
+ var ACTION_KEYS = /* @__PURE__ */ new Set([
15427
+ "label",
15428
+ "handler",
15429
+ "change",
15430
+ "confirm",
15431
+ "permission",
15432
+ "tone",
15433
+ "when",
15434
+ "disabled_reason"
15435
+ ]);
15436
+ var FIELD_KEYS = /* @__PURE__ */ new Set(["name", "type", "values", "permission", "rules"]);
15437
+ var FIELD_TYPES = /* @__PURE__ */ new Set([
15438
+ "text",
15439
+ "int",
15440
+ "number",
15441
+ "money",
15442
+ "date",
15443
+ "enum",
15444
+ "bool",
15445
+ "percent",
15446
+ // progress 与 percent 同数据两种读法:前者出进度条,后者出文字(见 soma-ui 类型渲染表)
15447
+ "progress"
15448
+ ]);
15449
+ function parseUseBlock(input) {
15450
+ const { blockId, body } = input;
15451
+ const fail = (message) => {
15452
+ throw new SomaV2ParseError(message, blockId);
15453
+ };
15454
+ for (const key of Object.keys(body)) {
15455
+ if (!BLOCK_KEYS.has(key)) {
15456
+ fail(`\u7EC4\u4EF6\u5757\u4E0D\u652F\u6301\u952E "${key}"\uFF08\u53EF\u7528\uFF1A${[...BLOCK_KEYS].join("/")}\uFF09`);
15457
+ }
15458
+ }
15459
+ const component = body.component === void 0 ? void 0 : String(body.component);
15460
+ if (component && input.htmlComponent && component !== input.htmlComponent) {
15461
+ fail(
15462
+ `component \u58F0\u660E\u4E3A "${component}"\uFF0C\u4F46 HTML \u91CC\u662F "${input.htmlComponent}"\u2014\u2014\u4E24\u5904\u5FC5\u987B\u4E00\u81F4\uFF08\u6539\u4E86\u4E00\u5904\u5FD8\u4E86\u53E6\u4E00\u5904\u65F6\uFF0C\u9875\u9762\u6E32\u67D3\u7684\u662F\u54EA\u4E2A\u53EA\u80FD\u9760\u731C\uFF09`
15463
+ );
15464
+ }
15465
+ const dataRaw = body.data ?? {};
15466
+ if (typeof dataRaw !== "object" || Array.isArray(dataRaw)) fail("data \u6BB5\u5FC5\u987B\u662F\u6620\u5C04");
15467
+ const scope = buildBlockScope({
15468
+ blockId,
15469
+ dataNames: Object.keys(dataRaw),
15470
+ aliasRaw: body.alias,
15471
+ rowVars: input.rowVars
15472
+ });
15473
+ const { actions, emitRoutes } = parseEventSection(body.event, blockId, scope, fail);
15474
+ const dataObjects = [];
15475
+ const dataImports = [];
15476
+ for (const [localName, raw] of Object.entries(dataRaw)) {
15477
+ if (typeof raw === "string") {
15478
+ dataImports.push({ localName, targetPath: expandPath(raw, { ...scope, dataNames: /* @__PURE__ */ new Set() }) });
15479
+ continue;
15480
+ }
15481
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
15482
+ fail(`data.${localName} \u5FC5\u987B\u662F\u6620\u5C04\uFF08\u58F0\u660E\uFF09\u6216\u5B57\u7B26\u4E32\u8DEF\u5F84\uFF08\u5F15\u5165\uFF09`);
15483
+ }
15484
+ dataObjects.push(parseDataObject(localName, raw, blockId, scope, actions, fail));
15485
+ }
15486
+ const uiRaw = body.ui ?? {};
15487
+ if (typeof uiRaw !== "object" || Array.isArray(uiRaw)) fail("ui \u6BB5\u5FC5\u987B\u662F\u6620\u5C04");
15488
+ const when = body.when === void 0 ? void 0 : expandCondition2(String(body.when), scope);
15489
+ const ast = {
15490
+ blockId,
15491
+ ...component ? { component } : {},
15492
+ ...when ? { when } : {},
15493
+ dataObjects,
15494
+ dataImports,
15495
+ uiRaw: expandUiPaths(uiRaw, scope),
15496
+ actions,
15497
+ emitRoutes,
15498
+ scope,
15499
+ toShowValue() {
15500
+ const value = { props: this.uiRaw };
15501
+ if (this.when) value.when = this.when;
15502
+ return value;
15503
+ }
15504
+ };
15505
+ return ast;
15506
+ }
15507
+ function parseDataObject(localName, raw, blockId, scope, actions, fail) {
15508
+ for (const key of Object.keys(raw)) {
15509
+ if (!DATA_OBJECT_KEYS.has(key)) {
15510
+ fail(`data.${localName} \u4E0D\u652F\u6301\u952E "${key}"\uFF08\u53EF\u7528\uFF1A${[...DATA_OBJECT_KEYS].join("/")}\uFF09`);
15511
+ }
15512
+ }
15513
+ const decl = { localName, fullName: `${blockId}.${localName}` };
15514
+ const from = raw.from;
15515
+ if (from !== void 0) {
15516
+ if (typeof from !== "object" || Array.isArray(from)) fail(`data.${localName}.from \u5FC5\u987B\u662F\u6620\u5C04`);
15517
+ const api = from.api;
15518
+ if (typeof api !== "string" || api.trim() === "") fail(`data.${localName}.from \u7F3A\u5C11 api`);
15519
+ const params = {};
15520
+ for (const [key, value] of Object.entries(from.params ?? {})) {
15521
+ params[key] = expandPath(String(value), scope);
15522
+ }
15523
+ decl.from = { api: resolveApiRef(String(api), scope), params };
15524
+ }
15525
+ const save = raw.save;
15526
+ if (save !== void 0) {
15527
+ if (typeof save !== "object" || Array.isArray(save)) fail(`data.${localName}.save \u5FC5\u987B\u662F\u6620\u5C04`);
15528
+ const api = save.api;
15529
+ const trigger = save.trigger;
15530
+ if (typeof api !== "string" || api.trim() === "") fail(`data.${localName}.save \u7F3A\u5C11 api`);
15531
+ if (typeof trigger !== "string" || trigger.trim() === "") {
15532
+ fail(`data.${localName}.save \u7F3A\u5C11 trigger\uFF08\u7531\u54EA\u4E2A\u52A8\u4F5C\u89E6\u53D1\u56DE\u5199\uFF09`);
15533
+ }
15534
+ if (!actions.has(String(trigger))) {
15535
+ const known = [...actions.keys()].join("/") || "\uFF08\u672C\u5757\u672A\u5B9A\u4E49\u4EFB\u4F55\u52A8\u4F5C\uFF09";
15536
+ fail(
15537
+ `data.${localName}.save.trigger \u6307\u5411\u672A\u5B9A\u4E49\u7684\u52A8\u4F5C "${trigger}"\u2014\u2014\u8BF7\u5728 event.actions \u91CC\u5B9A\u4E49\u5B83\uFF08\u73B0\u6709\uFF1A${known}\uFF09`
15538
+ );
15539
+ }
15540
+ decl.save = {
15541
+ api: resolveApiRef(String(api), scope),
15542
+ method: String(save.method ?? "POST").toUpperCase(),
15543
+ trigger: String(trigger),
15544
+ ...save.key !== void 0 ? { key: String(save.key) } : {},
15545
+ ...Array.isArray(save.fields) ? { fields: save.fields.map(String) } : {}
15546
+ };
15547
+ }
15548
+ if (raw.refresh !== void 0) decl.refreshMs = parseDuration(String(raw.refresh), localName, fail);
15549
+ if (raw.reload_on !== void 0) {
15550
+ if (!Array.isArray(raw.reload_on)) fail(`data.${localName}.reload_on \u5FC5\u987B\u662F\u6570\u7EC4`);
15551
+ decl.reloadOn = raw.reload_on.map((item) => expandPath(String(item), scope));
15552
+ }
15553
+ if (raw.fields !== void 0) {
15554
+ const fieldsRaw = raw.fields;
15555
+ if (typeof fieldsRaw !== "object" || Array.isArray(fieldsRaw)) {
15556
+ fail(`data.${localName}.fields \u5FC5\u987B\u662F\u6620\u5C04`);
15557
+ }
15558
+ const fields = {};
15559
+ for (const [fieldName, fieldRaw] of Object.entries(fieldsRaw)) {
15560
+ fields[fieldName] = parseField2(localName, fieldName, fieldRaw, fail);
15561
+ }
15562
+ decl.fields = fields;
15563
+ }
15564
+ return decl;
15565
+ }
15566
+ function parseField2(objectName, fieldName, raw, fail) {
15567
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
15568
+ fail(`\u5B57\u6BB5\u5B57\u5178 ${objectName}.${fieldName} \u5FC5\u987B\u662F\u6620\u5C04`);
15569
+ }
15570
+ const field = raw;
15571
+ for (const key of Object.keys(field)) {
15572
+ if (!FIELD_KEYS.has(key)) {
15573
+ fail(`\u5B57\u6BB5 ${objectName}.${fieldName} \u4E0D\u652F\u6301\u952E "${key}"\uFF08\u53EF\u7528\uFF1A${[...FIELD_KEYS].join("/")}\uFF09`);
15574
+ }
15575
+ }
15576
+ const type2 = String(field.type ?? "");
15577
+ if (!FIELD_TYPES.has(type2)) {
15578
+ fail(
15579
+ `\u5B57\u6BB5 ${objectName}.${fieldName} \u7684 type "${type2}" \u975E\u6CD5\uFF08\u5C01\u95ED\u96C6\uFF1A${[...FIELD_TYPES].join("/")}\uFF09`
15580
+ );
15581
+ }
15582
+ if (type2 === "enum") {
15583
+ const values = field.values;
15584
+ if (values === null || typeof values !== "object" || Array.isArray(values) || Object.keys(values).length === 0) {
15585
+ fail(`\u5B57\u6BB5 ${objectName}.${fieldName} \u662F enum\uFF0C\u5FC5\u987B\u63D0\u4F9B\u975E\u7A7A values \u6620\u5C04\uFF08\u5B83\u540C\u65F6\u662F\u7FFB\u8BD1\u8868\u4E0E\u9009\u9879\u8868\uFF09`);
15586
+ }
15587
+ }
15588
+ const permission = field.permission === void 0 ? "r" : String(field.permission);
15589
+ if (permission !== "r" && permission !== "w") {
15590
+ fail(`\u5B57\u6BB5 ${objectName}.${fieldName} \u7684 permission \u53EA\u80FD\u662F r \u6216 w`);
15591
+ }
15592
+ if (field.rules !== void 0 && !Array.isArray(field.rules)) {
15593
+ fail(`\u5B57\u6BB5 ${objectName}.${fieldName} \u7684 rules \u5FC5\u987B\u662F\u6570\u7EC4`);
15594
+ }
15595
+ return {
15596
+ type: type2,
15597
+ permission,
15598
+ ...field.name !== void 0 ? { name: String(field.name) } : {},
15599
+ ...field.values ? { values: field.values } : {},
15600
+ ...field.rules ? { rules: field.rules } : {}
15601
+ };
15602
+ }
15603
+ function parseDuration(raw, where, fail) {
15604
+ const match = /^(\d+(?:\.\d+)?)(ms|s|m)$/.exec(raw.trim());
15605
+ if (!match) {
15606
+ fail(`${where} \u7684\u65F6\u957F "${raw}" \u975E\u6CD5\u2014\u2014\u5F62\u5982 500ms / 30s / 5m\uFF08\u5355\u4F4D\u5FC5\u586B\uFF0C\u4E0D\u731C\uFF09`);
15607
+ }
15608
+ const value = Number(match[1]);
15609
+ const unit = match[2];
15610
+ return unit === "ms" ? value : unit === "s" ? value * 1e3 : value * 6e4;
15611
+ }
15612
+ function parseEventSection(raw, blockId, scope, fail) {
15613
+ const actions = /* @__PURE__ */ new Map();
15614
+ const emitRoutes = {};
15615
+ if (raw === void 0) return { actions, emitRoutes };
15616
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
15617
+ fail("event \u6BB5\u5FC5\u987B\u662F\u6620\u5C04\uFF08\u5B50\u952E actions / on\uFF09");
15618
+ }
15619
+ const section = raw;
15620
+ for (const key of Object.keys(section)) {
15621
+ if (!EVENT_KEYS.has(key)) {
15622
+ fail(`event \u6BB5\u4E0D\u652F\u6301\u5B50\u952E "${key}"\uFF08\u53EF\u7528\uFF1Aactions / on\uFF09\u2014\u2014\u5B9A\u4E49\u4E0E\u8DEF\u7531\u5206\u5F00\u4F4F\uFF0C\u4E0D\u9760\u503C\u5F62\u72B6\u731C`);
15623
+ }
15624
+ }
15625
+ for (const [id, actionRaw] of Object.entries(section.actions ?? {})) {
15626
+ if (actionRaw === null || typeof actionRaw !== "object" || Array.isArray(actionRaw)) {
15627
+ fail(`event.actions.${id} \u5FC5\u987B\u662F\u6620\u5C04`);
15628
+ }
15629
+ const action = actionRaw;
15630
+ for (const key of Object.keys(action)) {
15631
+ if (!ACTION_KEYS.has(key)) {
15632
+ fail(`\u52A8\u4F5C ${id} \u4E0D\u652F\u6301\u5B57\u6BB5 "${key}"\uFF08\u53EF\u7528\uFF1A${[...ACTION_KEYS].join("/")}\uFF09`);
15633
+ }
15634
+ }
15635
+ if (action.label === void 0) fail(`\u52A8\u4F5C ${id} \u7F3A\u5C11 label`);
15636
+ actions.set(id, {
15637
+ id,
15638
+ label: String(action.label),
15639
+ ...action.handler !== void 0 ? { handler: withPageDefault(String(action.handler)) } : {},
15640
+ ...action.change !== void 0 ? { change: withPageDefault(String(action.change)) } : {},
15641
+ ...action.confirm !== void 0 ? { confirm: String(action.confirm) } : {},
15642
+ ...action.permission !== void 0 ? { permission: String(action.permission) } : {},
15643
+ ...action.tone !== void 0 ? { tone: String(action.tone) } : {},
15644
+ ...action.when !== void 0 ? { when: expandCondition2(String(action.when), scope) } : {},
15645
+ ...action.disabled_reason !== void 0 ? { disabled_reason: expandPath(String(action.disabled_reason), scope) } : {}
15646
+ });
15647
+ }
15648
+ for (const [emitName, expr] of Object.entries(section.on ?? {})) {
15649
+ if (emitName.includes(".")) {
15650
+ fail(
15651
+ `event.on \u7684\u952E "${emitName}" \u542B\u70B9\u53F7\u2014\u2014\u7EC4\u4EF6\u5757\u53EA\u8BA2\u9605\u672C\u5B9E\u4F8B\u7684\u5951\u7EA6 emit\uFF08\u76F4\u63A5\u5199 emit \u540D\uFF09\uFF0CDOM \u4E8B\u4EF6\u5199\u5728 page \u5757\u7684 event.on`
15652
+ );
15653
+ }
15654
+ emitRoutes[emitName] = withPageDefaultInPipeline(String(expr));
15655
+ }
15656
+ return { actions, emitRoutes };
15657
+ }
15658
+ function withPageDefault(funcPath) {
15659
+ return funcPath.includes(".") ? funcPath : `page.${funcPath}`;
15660
+ }
15661
+ function withPageDefaultInPipeline(expr) {
15662
+ const parts = expr.split("|").map((part) => part.trim());
15663
+ const verb = parts[0];
15664
+ const handlerIndex = verb === "UI_INTERACT" ? 2 : verb === "NAV_STATIC" ? -1 : ["UI_REFRESH", "NAV_ACTION"].includes(verb) ? 1 : 0;
15665
+ if (handlerIndex >= 0 && parts[handlerIndex] && /^[A-Za-z_][A-Za-z0-9_]*$/.test(parts[handlerIndex])) {
15666
+ parts[handlerIndex] = `page.${parts[handlerIndex]}`;
15667
+ }
15668
+ return parts.reduce(
15669
+ (result, part, index) => index === 0 ? part : `${result} |${part ? ` ${part}` : ""}`,
15670
+ ""
15671
+ );
15672
+ }
15673
+ function expandCondition2(raw, scope) {
15674
+ const text = raw.trim();
15675
+ const negated = text.startsWith("!");
15676
+ const bare = negated ? text.slice(1).trim() : text;
15677
+ return `${negated ? "!" : ""}${expandPath(bare, scope)}`;
15678
+ }
15679
+ function expandUiPaths(value, scope) {
15680
+ const walk = (node) => {
15681
+ if (typeof node === "string") {
15682
+ const segments = node.split(/\s+\|\s+/);
15683
+ segments[0] = expandPath(segments[0], scope);
15684
+ return segments.join(" | ");
15685
+ }
15686
+ if (Array.isArray(node)) return node.map(walk);
15687
+ if (node !== null && typeof node === "object") {
15688
+ const out = {};
15689
+ for (const [key, child] of Object.entries(node)) {
15690
+ out[key] = walk(child);
15691
+ }
15692
+ return out;
15693
+ }
15694
+ return node;
15695
+ };
15696
+ return walk(value);
15697
+ }
15698
+
15699
+ // core/build/v2/block-compile.ts
15700
+ function compileSomaV2(input) {
15701
+ const htmlIndex = buildHtmlAnchorIndex(input.html);
15702
+ if (htmlIndex.duplicates.length > 0) {
15703
+ throw new SomaV2ParseError(
15704
+ `HTML \u951A\u70B9\u91CD\u590D\uFF1A${htmlIndex.duplicates.join("\u3001")}\u2014\u2014\u9875\u9762\u5185 data-soma-id \u5FC5\u987B\u552F\u4E00`
15705
+ );
15706
+ }
15707
+ const rawBlocks = loadSomaFile({
15708
+ uiYamlRaw: input.uiYamlRaw,
15709
+ htmlIndex,
15710
+ ...input.externalBlocks ? { externalBlocks: input.externalBlocks } : {}
15711
+ });
15712
+ const pageRaw = rawBlocks.find((block) => block.blockId === PAGE_BLOCK_ID);
15713
+ if (!pageRaw) {
15714
+ throw new SomaV2ParseError("\u7F3A\u5C11 page \u5757\uFF08\u9875\u9762\u5FC5\u987B\u58F0\u660E domain\uFF09");
15715
+ }
15716
+ const anchors = new Set(htmlIndex.anchors.keys());
15717
+ const page = parsePageBlock({
15718
+ body: pageRaw.body,
15719
+ anchors,
15720
+ instances: htmlIndex.instances,
15721
+ ...input.localeKeys ? { localeKeys: input.localeKeys } : {}
15722
+ });
15723
+ const ui = page.ui;
15724
+ const event = { ...page.eventRaw };
15725
+ const data = {};
15726
+ for (const [name, decl] of Object.entries(page.dataRaw ?? {})) {
15727
+ data[name] = decl;
15728
+ }
15729
+ const blocks = /* @__PURE__ */ new Map();
15730
+ for (const raw of rawBlocks) {
15731
+ if (raw.blockId === PAGE_BLOCK_ID) continue;
15732
+ const info = htmlIndex.anchors.get(raw.blockId);
15733
+ const ast = parseUseBlock({
15734
+ blockId: raw.blockId,
15735
+ body: raw.body,
15736
+ ...info?.component ? { htmlComponent: info.component } : {},
15737
+ rowVars: rowVarsFor(raw.blockId, htmlIndex, ui)
15738
+ });
15739
+ blocks.set(raw.blockId, ast);
15740
+ attachInstance(ui, raw.blockId, ast, htmlIndex);
15741
+ for (const [emitName, expr] of Object.entries(ast.emitRoutes)) {
15742
+ event[`${raw.blockId}.${emitName}`] = expr;
15743
+ }
15744
+ for (const object of ast.dataObjects) {
15745
+ data[object.fullName] = {
15746
+ ...object.from ? { from: object.from } : {},
15747
+ ...object.save ? { save: object.save } : {},
15748
+ ...object.refreshMs !== void 0 ? { refreshMs: object.refreshMs } : {},
15749
+ ...object.reloadOn ? { reloadOn: object.reloadOn } : {},
15750
+ ...object.fields ? { fields: object.fields } : {}
15751
+ };
15752
+ }
15753
+ }
15754
+ return { ui, event, data, blocks, htmlIndex };
15755
+ }
15756
+ function rowVarsFor(blockId, htmlIndex, ui) {
15757
+ const info = htmlIndex.anchors.get(blockId);
15758
+ if (!info?.inRowTemplate || !info.ownerList) return [];
15759
+ const chain = [];
15760
+ const walk = (show, ancestors) => {
15761
+ for (const [key, value] of Object.entries(show)) {
15762
+ if (value === null || typeof value !== "object") continue;
15763
+ const node = value;
15764
+ const nextAncestors = node.bind?.var ? [...ancestors, node.bind.var] : ancestors;
15765
+ if (key === info.ownerList && node.bind?.var) {
15766
+ chain.push(...nextAncestors);
15767
+ return true;
15768
+ }
15769
+ if (node.show && walk(node.show, nextAncestors)) return true;
15770
+ }
15771
+ return false;
15772
+ };
15773
+ walk(ui.show, []);
15774
+ return chain;
15775
+ }
15776
+ function attachInstance(ui, blockId, ast, htmlIndex) {
15777
+ const value = ast.toShowValue();
15778
+ const info = htmlIndex.anchors.get(blockId);
15779
+ if (!info?.inRowTemplate) {
15780
+ ui.show[blockId] = value;
15781
+ return;
15782
+ }
15783
+ const owner = info.ownerList;
15784
+ if (!owner) {
15785
+ throw new SomaV2ParseError(
15786
+ `\u5B9E\u4F8B "${blockId}" \u4F4D\u4E8E\u884C\u6A21\u677F\u5185\uFF0C\u4F46 HTML \u91CC\u627E\u4E0D\u5230\u5B83\u6240\u5C5E\u7684\u5217\u8868\u951A\u70B9`,
15787
+ blockId
15788
+ );
15789
+ }
15790
+ const target = findListShow(ui.show, owner);
15791
+ if (!target) {
15792
+ throw new SomaV2ParseError(
15793
+ `\u5B9E\u4F8B "${blockId}" \u5C5E\u4E8E\u5217\u8868 "${owner}"\uFF0C\u4F46 page \u5757\u6CA1\u6709\u4E3A\u8BE5\u5217\u8868\u58F0\u660E each \u4F5C\u7528\u57DF`,
15794
+ blockId
15795
+ );
15796
+ }
15797
+ target[blockId] = value;
15798
+ }
15799
+ function findListShow(show, listAnchor) {
15800
+ for (const [key, node] of Object.entries(show)) {
15801
+ if (node === null || typeof node !== "object") continue;
15802
+ const nested = node;
15803
+ if (key === listAnchor && nested.bind && nested.show) return nested.show;
15804
+ if (nested.show) {
15805
+ const found = findListShow(nested.show, listAnchor);
15806
+ if (found) return found;
15807
+ }
15808
+ }
15809
+ return void 0;
15810
+ }
15811
+
15812
+ // core/build/compiler/html-include-expander.ts
15813
+ var SomaHtmlIncludeError = class extends Error {
15814
+ constructor(message) {
15815
+ super(`[soma-core][HTML include] ${message}`);
15816
+ this.name = "SomaHtmlIncludeError";
15817
+ }
15818
+ };
15819
+ var INCLUDE_ATTRIBUTE = /\sdata-soma-include\s*=\s*(["'])([^"']+)\1/i;
15820
+ var OPEN_TAG = /<([A-Za-z][A-Za-z0-9:-]*)(\s[^<>]*?)?>/g;
15821
+ function expandSomaHtmlIncludes(html, includes) {
15822
+ if (!includes || Object.keys(includes).length === 0 || !html.includes("data-soma-include")) {
15823
+ return html;
15824
+ }
15825
+ const expand = (source, chain) => source.replace(
15826
+ OPEN_TAG,
15827
+ (full, tagName, attributes) => {
15828
+ const rawAttributes = attributes ?? "";
15829
+ const matched = INCLUDE_ATTRIBUTE.exec(rawAttributes);
15830
+ if (!matched) return full;
15831
+ const includeName = matched[2];
15832
+ if (!Object.prototype.hasOwnProperty.call(includes, includeName)) {
15833
+ throw new SomaHtmlIncludeError(`\u627E\u4E0D\u5230\u5171\u4EAB\u7247\u6BB5 "${includeName}"`);
15834
+ }
15835
+ if (chain.includes(includeName)) {
15836
+ throw new SomaHtmlIncludeError(`\u68C0\u6D4B\u5230\u5FAA\u73AF\u5F15\u7528\uFF1A${[...chain, includeName].join(" -> ")}`);
15837
+ }
15838
+ const withoutInclude = rawAttributes.replace(INCLUDE_ATTRIBUTE, "");
15839
+ const expandedFragment = expand(includes[includeName], [...chain, includeName]);
15840
+ return `<${tagName}${withoutInclude}>${expandedFragment}`;
15841
+ }
15842
+ );
15843
+ return expand(html, []);
15844
+ }
15845
+
15846
+ // core/build/compiler/page-declaration-compiler.ts
15847
+ var dump2 = (value) => yaml.dump(value, { lineWidth: 120, noRefs: true, quotingType: '"' });
15848
+ function compilePageDeclaration(input) {
15849
+ const eventYaml = input.eventYaml ?? "";
15850
+ const styleYaml = input.styleYaml ?? "";
15851
+ const dataYaml = input.dataYaml ?? "";
15852
+ const sidecars = [
15853
+ eventYaml.trim() ? "eventYaml / *_event.yaml" : "",
15854
+ styleYaml.trim() ? "styleYaml / *_style.yaml" : "",
15855
+ dataYaml.trim() ? "dataYaml / *_data.yaml" : ""
15856
+ ].filter(Boolean);
15857
+ if (sidecars.length > 0) {
15858
+ throw new Error(
15859
+ `[soma-core][SOMA DSL] \u9875\u9762\u4FA7\u8F66\u5DF2\u9000\u5F79\uFF1A${sidecars.join("\u3001")}\u3002\u4E8B\u4EF6\u3001\u6837\u5F0F\u72B6\u6001\u4E0E\u6570\u636E\u5BF9\u8C61\u5FC5\u987B\u5199\u8FDB\u540C\u4E00\u4EFD SOMA DSL \u58F0\u660E\u3002`
15860
+ );
15861
+ }
15862
+ const compiled = compileSomaV2({
15863
+ html: expandSomaHtmlIncludes(input.html, input.includes),
15864
+ uiYamlRaw: input.uiYaml,
15865
+ ...input.externalBlocks ? { externalBlocks: input.externalBlocks } : {}
15866
+ });
15867
+ const eventBundle = compileEventConfigFromRaw(compiled.event);
15868
+ const embeddedDataYaml = Object.keys(compiled.data).length > 0 ? dump2({ data: compiled.data }) : "";
15869
+ return {
15870
+ uiConfig: compiled.ui,
15871
+ eventConfig: eventBundle.events,
15872
+ triggers: eventBundle.triggers,
15873
+ timers: eventBundle.timers,
15874
+ ...embeddedDataYaml ? { dataConfig: compileDataConfig(embeddedDataYaml) } : {},
15875
+ runtimeAssets: {
15876
+ uiYaml: dump2(compiled.ui),
15877
+ eventYaml: Object.keys(compiled.event).length > 0 ? dump2(compiled.event) : "",
15878
+ styleYaml: "",
15879
+ ...embeddedDataYaml ? { dataYaml: embeddedDataYaml } : {}
15880
+ }
15881
+ };
15882
+ }
15883
+
15884
+ // core/build/compiler/page-assets.ts
15885
+ function compilePageAssets(assets) {
15886
+ const compiled = compilePageDeclaration({
15887
+ html: assets.html ?? "",
15888
+ uiYaml: assets.uiYaml ?? "",
15889
+ ...assets.eventYaml ? { eventYaml: assets.eventYaml } : {},
15890
+ ...assets.styleYaml ? { styleYaml: assets.styleYaml } : {},
15891
+ ...assets.dataYaml ? { dataYaml: assets.dataYaml } : {},
15892
+ ...assets.declarationBlocks ? { externalBlocks: assets.declarationBlocks } : {}
15893
+ });
15894
+ return {
15895
+ ...assets,
15896
+ uiYaml: compiled.runtimeAssets.uiYaml,
15897
+ eventYaml: compiled.runtimeAssets.eventYaml,
15898
+ styleYaml: "",
15899
+ ...compiled.runtimeAssets.dataYaml ? { dataYaml: compiled.runtimeAssets.dataYaml } : { dataYaml: void 0 }
15900
+ };
15901
+ }
13935
15902
  // Annotate the CommonJS export names for ESM import in node:
13936
15903
  0 && (module.exports = {
13937
15904
  ComponentPackError,
@@ -13939,6 +15906,7 @@ function physicalDirections(css) {
13939
15906
  Locale,
13940
15907
  MiniProgramContainerAdapter,
13941
15908
  PACK_NAME_PATTERN,
15909
+ PAGE_BLOCK_ID,
13942
15910
  Page,
13943
15911
  ReactNativeContainerAdapter,
13944
15912
  SOMA_ADAPTIVE_MAX_LADDER,
@@ -13968,8 +15936,11 @@ function physicalDirections(css) {
13968
15936
  SomaPipeRegistry,
13969
15937
  SomaQualityRegistry,
13970
15938
  SomaRealtimeService,
15939
+ SomaScopeError,
13971
15940
  SomaTelemetry,
15941
+ SomaV2ParseError,
13972
15942
  SomaValidator,
15943
+ SomaValueLangError,
13973
15944
  SseRealtimeTransport,
13974
15945
  THEME_SWITCHING_CLASS,
13975
15946
  TYPOGRAPHY_BASE_CSS,
@@ -13978,8 +15949,13 @@ function physicalDirections(css) {
13978
15949
  applyLocaleMetadata,
13979
15950
  applyTheme,
13980
15951
  attachPackStyles,
15952
+ buildBlockScope,
13981
15953
  buildCatalogEntry,
15954
+ buildHtmlAnchorIndex,
15955
+ checkOverrideCompat,
13982
15956
  compileAdaptive,
15957
+ compilePageAssets,
15958
+ compileSomaV2,
13983
15959
  composeComponentPacks,
13984
15960
  contrastRatio,
13985
15961
  createAdaptiveObserverPool,
@@ -13991,8 +15967,11 @@ function physicalDirections(css) {
13991
15967
  createSomaPageLifecycle,
13992
15968
  defaultPipeRegistry,
13993
15969
  deriveTheme,
15970
+ describeNode,
13994
15971
  ensurePackBaseStyles,
13995
15972
  escapeSomaHtml,
15973
+ evaluateValueNode,
15974
+ expandPath,
13996
15975
  extractConfigFromDomainClass,
13997
15976
  findNestedMutableContractDefault,
13998
15977
  findSomaDomainLoader,
@@ -14006,10 +15985,13 @@ function physicalDirections(css) {
14006
15985
  hasBlockedScheme,
14007
15986
  hasPageMetadata,
14008
15987
  installSomaErrorReporter,
15988
+ isArithSegment,
14009
15989
  isBootTimingsEnabled,
14010
15990
  isEventHandlerAttribute,
15991
+ isPlainPath,
14011
15992
  isSomaMockEnabled,
14012
15993
  loadSomaDomainModuleFromRegistry,
15994
+ loadSomaFile,
14013
15995
  markBootPhase,
14014
15996
  matchGlobPath,
14015
15997
  maybeStartBootTimings,
@@ -14018,21 +16000,28 @@ function physicalDirections(css) {
14018
16000
  parseDataConfig,
14019
16001
  parseDataRef,
14020
16002
  parseDataYaml,
16003
+ parsePageBlock,
16004
+ parseUseBlock,
16005
+ parseValueSegment,
14021
16006
  readBootTimings,
14022
16007
  recordMetric,
14023
16008
  renderPublishedPage,
14024
16009
  resetBootTimings,
14025
16010
  resetPackStyleInjection,
16011
+ resolveApiRef,
14026
16012
  resolveHostBootstrapOptions,
16013
+ resolvePath,
14027
16014
  resolveSomaHtmlSanitizer,
14028
16015
  resolveTierWithHysteresis,
14029
16016
  runAsync,
14030
16017
  sanitizeAttributeWrite,
14031
16018
  sanitizeSomaHtml,
14032
16019
  scheduleAdaptiveFlush,
16020
+ scopeHasVar,
14033
16021
  setActiveTelemetry,
14034
16022
  setSomaHtmlSanitizer,
14035
16023
  somaRollupPlugin,
14036
16024
  startBootTimings,
16025
+ themeRootAttributes,
14037
16026
  verifyComponentPack
14038
16027
  });