soma-core 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +1 -1
  2. package/core/build/blocks/block-compile.ts +31 -2
  3. package/core/build/blocks/block-container.ts +2 -11
  4. package/core/build/compiler/page-declaration-compiler.ts +30 -2
  5. package/core/build/compiler/soma-precompile.js +2053 -23
  6. package/core/build/component/component-graph.ts +208 -0
  7. package/core/build/component/package-loader.ts +32 -0
  8. package/core/build/eject/component-eject.ts +473 -0
  9. package/core/build/eject/component-upgrade.ts +359 -0
  10. package/core/build/layout/constraint-solver.ts +235 -0
  11. package/core/build/layout/css-emitter.ts +116 -0
  12. package/core/build/layout/page-layout.ts +85 -0
  13. package/core/build/pack/pack-init.ts +270 -0
  14. package/core/client/base/SomaHttpClient.ts +34 -1
  15. package/core/client/base/SomaPageRootBase.ts +61 -0
  16. package/core/client/component/ai-catalog.ts +121 -4
  17. package/core/client/component/component-defaults.ts +100 -0
  18. package/core/client/component/component-definition.types.ts +39 -0
  19. package/core/client/component/component-manager.ts +79 -4
  20. package/core/client/component/component-pack.ts +126 -2
  21. package/core/client/component/keyboard-matrix.ts +144 -0
  22. package/core/client/component/pack-styles.ts +59 -1
  23. package/core/client/component/style-features.ts +131 -0
  24. package/core/client/component/theme-component-tokens.ts +83 -0
  25. package/core/client/component/verify-pack.ts +120 -1
  26. package/core/client/container/SomaContainerAdapter.ts +6 -2
  27. package/core/client/data/data-object-resolver.ts +407 -4
  28. package/core/client/data/reaction-engine.ts +176 -0
  29. package/core/client/data/window-engine.ts +477 -0
  30. package/core/client/engine/event-engine.ts +98 -0
  31. package/core/client/engine/soma-bootstrap.ts +265 -5
  32. package/core/client/engine/step-runner.ts +134 -0
  33. package/core/client/infra/http/SomaHttpService.ts +2 -2
  34. package/core/client/parser/blocks/page-parser.ts +15 -1
  35. package/core/client/parser/blocks/use-parser.ts +5 -12
  36. package/core/client/parser/data-config-parser.ts +316 -8
  37. package/core/client/parser/duration.ts +16 -0
  38. package/core/client/parser/layout-parser.ts +157 -0
  39. package/core/client/parser/page-state-parser.ts +166 -0
  40. package/core/client/parser/pipeline-parser.ts +76 -1
  41. package/core/client/parser/reaction-parser.ts +459 -0
  42. package/core/client/parser/reaction-sugar.ts +47 -0
  43. package/core/client/parser/step-parser.ts +359 -0
  44. package/core/client/parser/ui-config-parser.ts +59 -0
  45. package/core/client/parser/window-parser.ts +294 -0
  46. package/core/client/theme/theme-engine.ts +102 -2
  47. package/core/index.ts +184 -0
  48. package/core/shared/block-errors.ts +11 -0
  49. package/core/shared/calc/coerce.ts +29 -0
  50. package/core/shared/calc/errors.ts +43 -0
  51. package/core/shared/calc/evaluator.ts +101 -0
  52. package/core/shared/calc/index.ts +12 -0
  53. package/core/shared/calc/lexer.ts +194 -0
  54. package/core/shared/calc/parser.ts +204 -0
  55. package/core/shared/calc/typer.ts +184 -0
  56. package/core/shared/component/derive-sample.ts +105 -0
  57. package/core/shared/component/field-lines.ts +473 -0
  58. package/core/shared/path-algebra.ts +169 -0
  59. package/core/shared/predicates/index.ts +527 -0
  60. package/core/shared/types/component-contract.types.ts +151 -9
  61. package/core/shared/types/data-config.types.ts +120 -1
  62. package/core/shared/types/domain.types.ts +13 -0
  63. package/core/shared/types/event.types.ts +22 -2
  64. package/core/shared/types/layout-constraint.types.ts +73 -0
  65. package/core/shared/types/page-state.types.ts +60 -0
  66. package/core/shared/types/reaction.types.ts +144 -0
  67. package/core/shared/types/step.types.ts +91 -0
  68. package/core/shared/types/ui-config.types.ts +18 -0
  69. package/core/shared/types/window.types.ts +177 -0
  70. package/dist/cli/soma.js +13 -1
  71. package/dist/core/index.cjs +5529 -631
  72. package/dist/types/build/blocks/block-container.d.ts +1 -6
  73. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
  74. package/dist/types/build/component/component-graph.d.ts +85 -0
  75. package/dist/types/build/eject/component-eject.d.ts +121 -0
  76. package/dist/types/build/eject/component-upgrade.d.ts +43 -0
  77. package/dist/types/build/layout/constraint-solver.d.ts +36 -0
  78. package/dist/types/build/layout/css-emitter.d.ts +18 -0
  79. package/dist/types/build/layout/page-layout.d.ts +24 -0
  80. package/dist/types/build/pack/pack-init.d.ts +8 -0
  81. package/dist/types/client/base/SomaHttpClient.d.ts +8 -0
  82. package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
  83. package/dist/types/client/component/ai-catalog.d.ts +33 -1
  84. package/dist/types/client/component/component-defaults.d.ts +15 -0
  85. package/dist/types/client/component/component-definition.types.d.ts +38 -0
  86. package/dist/types/client/component/component-manager.d.ts +36 -0
  87. package/dist/types/client/component/component-pack.d.ts +32 -2
  88. package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
  89. package/dist/types/client/component/pack-styles.d.ts +21 -0
  90. package/dist/types/client/component/style-features.d.ts +26 -0
  91. package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
  92. package/dist/types/client/component/verify-pack.d.ts +10 -0
  93. package/dist/types/client/data/data-object-resolver.d.ts +106 -1
  94. package/dist/types/client/data/reaction-engine.d.ts +21 -0
  95. package/dist/types/client/data/window-engine.d.ts +27 -0
  96. package/dist/types/client/engine/event-engine.d.ts +15 -0
  97. package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
  98. package/dist/types/client/engine/step-runner.d.ts +24 -0
  99. package/dist/types/client/parser/blocks/use-parser.d.ts +2 -2
  100. package/dist/types/client/parser/duration.d.ts +1 -0
  101. package/dist/types/client/parser/layout-parser.d.ts +9 -0
  102. package/dist/types/client/parser/page-state-parser.d.ts +32 -0
  103. package/dist/types/client/parser/reaction-parser.d.ts +16 -0
  104. package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
  105. package/dist/types/client/parser/step-parser.d.ts +23 -0
  106. package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
  107. package/dist/types/client/parser/window-parser.d.ts +25 -0
  108. package/dist/types/client/theme/theme-engine.d.ts +26 -0
  109. package/dist/types/index.d.ts +35 -2
  110. package/dist/types/shared/block-errors.d.ts +5 -0
  111. package/dist/types/shared/calc/coerce.d.ts +4 -0
  112. package/dist/types/shared/calc/errors.d.ts +14 -0
  113. package/dist/types/shared/calc/evaluator.d.ts +2 -0
  114. package/dist/types/shared/calc/index.d.ts +6 -0
  115. package/dist/types/shared/calc/lexer.d.ts +20 -0
  116. package/dist/types/shared/calc/parser.d.ts +49 -0
  117. package/dist/types/shared/calc/typer.d.ts +16 -0
  118. package/dist/types/shared/component/derive-sample.d.ts +23 -0
  119. package/dist/types/shared/component/field-lines.d.ts +19 -0
  120. package/dist/types/shared/path-algebra.d.ts +56 -0
  121. package/dist/types/shared/predicates/index.d.ts +79 -0
  122. package/dist/types/shared/types/component-contract.types.d.ts +134 -6
  123. package/dist/types/shared/types/data-config.types.d.ts +115 -1
  124. package/dist/types/shared/types/domain.types.d.ts +12 -0
  125. package/dist/types/shared/types/event.types.d.ts +8 -2
  126. package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
  127. package/dist/types/shared/types/page-state.types.d.ts +49 -0
  128. package/dist/types/shared/types/reaction.types.d.ts +115 -0
  129. package/dist/types/shared/types/step.types.d.ts +76 -0
  130. package/dist/types/shared/types/ui-config.types.d.ts +18 -0
  131. package/dist/types/shared/types/window.types.d.ts +171 -0
  132. package/package.json +3 -2
@@ -24,6 +24,11 @@ export interface SomaUiConfigParseOptions {
24
24
  * 所以推迟的是报错时机,不是报错本身。
25
25
  */
26
26
  adaptiveVocabularyRequired?: boolean;
27
+ /**
28
+ * 已声明的数据对象名(`state.window` 切片只能指向它们)。
29
+ * 不给时跳过这一层校验——见 `state` 分支里的说明。
30
+ */
31
+ dataObjectNames?: readonly string[];
27
32
  }
28
33
  /**
29
34
  * 将 YAML 解析后的原始对象转换为类型安全的 UiConfig
@@ -0,0 +1,25 @@
1
+ import { type SomaWindowConfig } from '../../shared/types/window.types';
2
+ import type { SomaDataFieldConfig } from '../../shared/types/data-config.types';
3
+ export interface WindowParseInput {
4
+ raw: unknown;
5
+ fields: Record<string, SomaDataFieldConfig>;
6
+ path: string;
7
+ }
8
+ export interface WindowParseDeps {
9
+ fail(message: string, path: string): never;
10
+ }
11
+ export declare function parseWindow(input: WindowParseInput, deps: WindowParseDeps): SomaWindowConfig;
12
+ /**
13
+ * 字段字典的稳定哈希:字段名 + 类型 + 权限。
14
+ *
15
+ * 随每个请求下发,让后端能拒收「按一份它不认识的字典发来的意图」——这是本层唯一
16
+ * 对方结构上做不到的事(AG Grid 的列是函数,没有可哈希的字典)。
17
+ *
18
+ * 只取名/类型/权限三项:它们决定了**哪些意图是合法的**(能不能排序、能不能求和、
19
+ * 能不能进请求体)。`name` 这类展示位改了不该让后端拒收——那会把一次文案调整变成一次
20
+ * 前后端联合发布。字段先按名排序,声明顺序变化不改哈希,同理。
21
+ *
22
+ * 用 FNV-1a 而不是 sha256:这里要的是「字典变了没有」的指纹,不是抗碰撞的安全摘要,
23
+ * 而 `crypto.subtle` 是异步的——为一个同步的解析步骤引入异步是不划算的交换。
24
+ */
25
+ export declare function dictHash(fields: Record<string, SomaDataFieldConfig>): string;
@@ -29,6 +29,23 @@ export interface SomaThemeInput {
29
29
  * 缺省不给 = 行为与之前字节级一致(不影响任何既有预设)。
30
30
  */
31
31
  darkOverrides?: Record<string, string>;
32
+ /**
33
+ * 组件级令牌覆盖(REQ-009 M-1):组件名 → { 令牌名: 值 }。
34
+ *
35
+ * 这是三级令牌的第三级在主题输入侧的入口。它存在的理由:今天想只改 Button 的圆角,
36
+ * 只能改全局 `--soma-radius-control`,于是**所有 control 族**跟着变。
37
+ *
38
+ * 与 MUI 的 `theme.components.MuiX.styleOverrides.<slot>` 的关键差别:
39
+ * 这里能改的只有**组件自己在契约 `tokens` 段声明过的旋钮**,
40
+ * 而不是任意内部元素的任意 CSS 声明。组件内部结构仍然封闭
41
+ * (页面永不可寻址组件内部,`scopeAnchors()` 的既定边界)。
42
+ *
43
+ * 引擎不认识组件,所以这里只做展平;「组件名 / 令牌名是否存在」由装配层的
44
+ * `validateThemeComponentTokens` 在 bootstrap 期核对契约。
45
+ */
46
+ components?: Record<string, Record<string, string>>;
47
+ /** 组件令牌的暗色专属覆盖:与 `darkOverrides` 同一纪律,只并进 darkCssVars */
48
+ darkComponents?: Record<string, Record<string, string>>;
32
49
  }
33
50
  export interface SomaThemeMeta {
34
51
  /** 本次派生实际生效的轴位(含缺省回落)——诊断与测试的观测面 */
@@ -37,6 +54,8 @@ export interface SomaThemeMeta {
37
54
  readonly separationApplied: boolean;
38
55
  /** 被推开的语气 */
39
56
  readonly pushed: readonly SomaToneName[];
57
+ /** 本次写出的组件级令牌变量名(M-1)——快照与闸门的观测面 */
58
+ readonly componentTokens: readonly string[];
40
59
  }
41
60
  export interface SomaDerivedTheme {
42
61
  /** 品牌色阶 50~950(11 档 hex) */
@@ -63,6 +82,13 @@ export declare function hexToOklch(hex: string): Oklch;
63
82
  export declare function oklchToHex(color: Oklch): string;
64
83
  export declare function contrastRatio(hexA: string, hexB: string): number;
65
84
  export declare function deriveTheme(input: SomaThemeInput): SomaDerivedTheme;
85
+ /**
86
+ * 引擎会写出的令牌名全集(静态令牌 + 派生令牌),不跑派生。
87
+ *
88
+ * 给 soma-ui 的 `token-existence-lint` 用:契约 `tokens.default` 引用的语义令牌
89
+ * 必须真的存在,否则组件令牌指向一个空变量,回退值一路生效而没人发现。
90
+ */
91
+ export declare function listThemeTokenNames(): readonly string[];
66
92
  /**
67
93
  * 派生结果 → 根元素属性。
68
94
  *
@@ -9,6 +9,8 @@ export type { SomaPageAssets, SomaBootstrapOptions, SomaBootstrapErrorReporting,
9
9
  export { SomaComponentRegistry } from './client/component/component-registry';
10
10
  export { SomaComponentManager } from './client/component/component-manager';
11
11
  export { generateAiCatalog, buildCatalogEntry } from './client/component/ai-catalog';
12
+ export { deriveKeyboardMatrix, renderKeyboardMatrixLine, SOMA_KEYBOARD_INTENTS, } from './client/component/keyboard-matrix';
13
+ export type { SomaKeyboardIntent, SomaKeyboardMatrixRow } from './client/component/keyboard-matrix';
12
14
  export type { SomaAiCatalog, SomaAiCatalogEntry, GenerateAiCatalogOptions, } from './client/component/ai-catalog';
13
15
  export { SomaPipeRegistry, defaultPipeRegistry } from './client/pipes/pipe-registry';
14
16
  export type { SomaPipeFn, SomaPipeContext } from './client/pipes/pipe-registry';
@@ -16,8 +18,35 @@ export { SomaDataObjectResolver, SomaDataCycleError, isSomaMockEnabled, } from '
16
18
  export type { SomaDataHttpLike, SomaDataResolverOptions, SomaDataResolveResult, } from './client/data/data-object-resolver';
17
19
  export { parseDataConfig, parseDataYaml, parseDataRef, normalizeDataPipeValue, SomaDataConfigError, } from './client/parser/data-config-parser';
18
20
  export type { SomaDataRef } from './client/parser/data-config-parser';
19
- export type { SomaDataConfig, SomaDataObjectConfig, SomaDataSourceConfig, SomaDataFieldConfig, SomaDataFieldRule, SomaDataFieldOption, SomaDataFieldType, SomaDataFieldPermission, SomaDataDicts, } from './shared/types/data-config.types';
21
+ export type { SomaDataConfig, SomaDataObjectConfig, SomaDataSourceConfig, SomaDataFieldConfig, SomaDataFieldRule, SomaDataFieldOption, SomaDataFieldType, SomaDataFieldPermission, SomaDataDicts, SomaDataWriteConfig, SomaDataWriteEndpoint, SomaDataSubmitResult, SomaDataPort, } from './shared/types/data-config.types';
20
22
  export { SOMA_DATA_FIELD_TYPES, SOMA_DATA_FIELD_TYPE_ALIASES, } from './shared/types/data-config.types';
23
+ export { SOMA_FIELD_PREDICATE_OPS, evaluatePredicate, validatePredicate, validateNamedPredicates, collectPredicateFields, } from './shared/predicates';
24
+ export type { SomaFieldPredicateOp, SomaFieldCondition, SomaFieldPredicateRef, SomaFieldPredicateAllOf, SomaFieldPredicateAnyOf, SomaFieldPredicateNoneOf, SomaFieldPredicate, SomaNamedPredicates, SomaPredicateValidateOptions, } from './shared/predicates';
25
+ export { parseCalc, collectCalcRefs, inferCalcType, assertCalcResultType, evaluateCalc, SomaCalcSyntaxError, SomaCalcTypeError, CALC_FUNCTIONS, } from './shared/calc';
26
+ export type { CalcAst, CalcType, CalcTypeContext, CalcSpan } from './shared/calc';
27
+ export { parseReactions } from './client/parser/reaction-parser';
28
+ export { compileFieldSugar } from './client/parser/reaction-sugar';
29
+ export type { SomaSugarField } from './client/parser/reaction-sugar';
30
+ export { runReactions, explainField } from './client/data/reaction-engine';
31
+ export { parseWindow, dictHash } from './client/parser/window-parser';
32
+ export { createWindow } from './client/data/window-engine';
33
+ export { parseSteps } from './client/parser/step-parser';
34
+ export type { StepParseInput, StepParseDeps } from './client/parser/step-parser';
35
+ export { runSteps } from './client/engine/step-runner';
36
+ export { parsePageState, parseStateValue, encodePageState, decodePageState, } from './client/parser/page-state-parser';
37
+ export { isListPath, parseListPath, expandListPath, readListPath, validateListPath, SomaPathError, } from './shared/path-algebra';
38
+ export type { SomaListPath, SomaPathSelector } from './shared/path-algebra';
39
+ export { parseLayoutConstraint } from './client/parser/layout-parser';
40
+ export { SOMA_LAYOUT_PRIORITIES, SOMA_LAYOUT_ALIGNS } from './shared/types/layout-constraint.types';
41
+ export type { SomaSizing, SomaPriority, SomaWrap, SomaAlign, SomaLayoutNodeConstraint, SomaLayoutConstraint, SomaLayoutSolution, SomaLayoutPlan, } from './shared/types/layout-constraint.types';
42
+ export type { SomaPageState, SomaPageStateConfig, SomaWindowStateSlice, SomaColumnStateSlice, } from './shared/types/page-state.types';
43
+ export type { StepRunContext, StepRunResult } from './client/engine/step-runner';
44
+ export type { SomaStep, SomaDoStep, SomaSwitchStep, SomaParallelStep, SomaForEachStep, SomaStepOnError, SomaStepSlot, SomaCompiledStep, SomaStepGraph, } from './shared/types/step.types';
45
+ export type { SomaWindowHttpLike, SomaWindowDeps } from './client/data/window-engine';
46
+ export { SOMA_AGGREGATE_FNS, SOMA_SELECT_ALL_MODES } from './shared/types/window.types';
47
+ export type { SomaFilterNode, SomaWindowSort, SomaAggregateFn, SomaWindowAggregate, SomaSelectAllMode, SomaWindowSelection, SomaWindowBlockConfig, SomaWindowConfig, SomaWindowRequest, SomaWindowResponse, SomaWindowRequestPatch, SomaWindowHandle, SomaTransaction, } from './shared/types/window.types';
48
+ export { SOMA_REACTION_PHASES, SOMA_FIELD_DISPLAYS, SOMA_FIELD_PATTERNS, SOMA_REACTION_FORM_KEY, } from './shared/types/reaction.types';
49
+ export type { SomaReactionPhase, SomaFieldDisplay, SomaFieldPattern, SomaFieldValuePatch, SomaFieldStatePatch, SomaFormStatePatch, SomaReactionConfig, SomaCompiledReaction, SomaFieldProvenance, SomaReactionGraph, SomaReactionResult, } from './shared/types/reaction.types';
21
50
  export { deriveTheme, applyTheme, contrastRatio, THEME_SWITCHING_CLASS, } from './client/theme/theme-engine';
22
51
  export type { SomaThemeInput, SomaDerivedTheme, SomaThemeMeta } from './client/theme/theme-engine';
23
52
  export { themeRootAttributes } from './client/theme/theme-engine';
@@ -30,8 +59,12 @@ export type { SomaAdaptiveProfile, SomaAdaptiveConfig, SomaAdaptiveLevel, SomaAd
30
59
  export { createAdaptiveObserverPool, scheduleAdaptiveFlush, resolveTierWithHysteresis, SOMA_DEFAULT_HYSTERESIS, } from './client/adaptive/index';
31
60
  export type { SomaAdaptiveObserverPool, SomaAdaptiveSize, SomaAdaptiveSizeCallback, SomaAdaptiveTask, } from './client/adaptive/index';
32
61
  export type { SomaComponentDefinition, SomaComponentControllerContext, SomaComponentControllerFactory, } from './client/component/component-definition.types';
33
- export type { SomaComponentContract, SomaComponentLayer, SomaGeometryFamily, SomaContractProp, SomaContractEmit, SomaContractSlot, } from './shared/types/component-contract.types';
62
+ export type { SomaComponentContract, SomaComponentLayer, SomaGeometryFamily, SomaContractField, SomaContractProp, SomaContractEmit, SomaContractSlot, SomaContractKeyboard, SomaContractOverlay, SomaContractToken, } from './shared/types/component-contract.types';
34
63
  export { findNestedMutableContractDefault } from './shared/types/component-contract.types';
64
+ export { parseFieldLines, parseEmitLines, parseSlotLines, renderFieldLines, somaFields, somaEmits, somaSlots, SomaFieldLinesError, } from './shared/component/field-lines';
65
+ export { deriveContractSample, deriveFieldSample, hasRenderableSample, } from './shared/component/derive-sample';
66
+ export type { DeriveSampleResult, SampleGap } from './shared/component/derive-sample';
67
+ export { componentTokenPrefix, componentTokenVar, COMPONENT_TOKEN_KEY_PATTERN, } from './shared/types/component-contract.types';
35
68
  export { createDefaultRuntimeServices } from './client/runtime/SomaRuntimeServices';
36
69
  export type { SomaRuntimeServices } from './client/runtime/SomaRuntimeServices';
37
70
  export { SomaDiagnostics } from './client/diagnostics/SomaDiagnostics';
@@ -0,0 +1,5 @@
1
+ export declare class SomaBlockParseError extends Error {
2
+ readonly blockId?: string | undefined;
3
+ readonly line?: number | undefined;
4
+ constructor(message: string, blockId?: string | undefined, line?: number | undefined);
5
+ }
@@ -0,0 +1,4 @@
1
+ /** 数值/日期归一:能当数用就返回数,否则 null */
2
+ export declare function ordinalOf(value: unknown): number | null;
3
+ /** 文本化:null/undefined → 空串(CONCAT 与等值比较共用) */
4
+ export declare function textOf(value: unknown): string;
@@ -0,0 +1,14 @@
1
+ /** 源串里的字符区间 [起, 止),用于错误定位 */
2
+ export type CalcSpan = readonly [number, number];
3
+ export declare class SomaCalcSyntaxError extends Error {
4
+ readonly pos: CalcSpan;
5
+ /** 出错处附近的原文片段(供报错时回显) */
6
+ readonly near: string;
7
+ constructor(message: string, source: string, pos: CalcSpan);
8
+ }
9
+ export declare class SomaCalcTypeError extends Error {
10
+ readonly pos: CalcSpan;
11
+ readonly expected: string;
12
+ readonly actual: string;
13
+ constructor(message: string, source: string, pos: CalcSpan, expected: string, actual: string);
14
+ }
@@ -0,0 +1,2 @@
1
+ import type { CalcAst } from './parser';
2
+ export declare function evaluateCalc(ast: CalcAst, values: Record<string, unknown>): unknown;
@@ -0,0 +1,6 @@
1
+ export { SomaCalcSyntaxError, SomaCalcTypeError, type CalcSpan } from './errors';
2
+ export { tokenize, parseDateLiteral, CALC_FUNCTIONS, type CalcToken, type CalcTokenKind, type CalcFunctionName } from './lexer';
3
+ export { parseCalc, collectCalcRefs, type CalcAst, type CalcBinaryOp } from './parser';
4
+ export { inferCalcType, assertCalcResultType, type CalcType, type CalcTypeContext } from './typer';
5
+ export { evaluateCalc } from './evaluator';
6
+ export { ordinalOf, textOf } from './coerce';
@@ -0,0 +1,20 @@
1
+ import { type CalcSpan } from './errors';
2
+ export type CalcTokenKind = 'number' | 'string' | 'date' | 'bool' | 'ref' | 'ident' | 'op' | 'lparen' | 'rparen' | 'comma' | 'eof';
3
+ export interface CalcToken {
4
+ kind: CalcTokenKind;
5
+ /** number → 数值;string → 已去引号去转义的文本;date → UTC 毫秒;bool → 布尔;
6
+ * ref → 字段名;ident → 函数名;op → 运算符原文 */
7
+ value: string | number | boolean;
8
+ pos: CalcSpan;
9
+ }
10
+ /** 六个函数名——封闭集。新增必须走需求文档,不许在这里顺手加 */
11
+ export declare const CALC_FUNCTIONS: readonly ["IF", "MIN", "MAX", "ROUND", "CONCAT", "ABS"];
12
+ export type CalcFunctionName = typeof CALC_FUNCTIONS[number];
13
+ export declare function tokenize(source: string): CalcToken[];
14
+ /**
15
+ * 日期字面量 → UTC 毫秒。
16
+ *
17
+ * 用 `Date.UTC` 而不是 `Date.parse`:后者对无时区的串在各引擎上曾有本地/UTC 之争,
18
+ * 而派生列的日期比较必须在任何机器上给同一个答案。
19
+ */
20
+ export declare function parseDateLiteral(text: string): number | null;
@@ -0,0 +1,49 @@
1
+ import { type CalcSpan } from './errors';
2
+ import { type CalcFunctionName } from './lexer';
3
+ export type CalcBinaryOp = '+' | '-' | '*' | '/' | '>' | '>=' | '<' | '<=' | '==' | '!=';
4
+ export type CalcAst = {
5
+ k: 'num';
6
+ v: number;
7
+ pos: CalcSpan;
8
+ } | {
9
+ k: 'str';
10
+ v: string;
11
+ pos: CalcSpan;
12
+ } | {
13
+ k: 'date';
14
+ v: number;
15
+ pos: CalcSpan;
16
+ } | {
17
+ k: 'bool';
18
+ v: boolean;
19
+ pos: CalcSpan;
20
+ } | {
21
+ k: 'ref';
22
+ name: string;
23
+ pos: CalcSpan;
24
+ } | {
25
+ k: 'un';
26
+ op: '-';
27
+ arg: CalcAst;
28
+ pos: CalcSpan;
29
+ } | {
30
+ k: 'bin';
31
+ op: CalcBinaryOp;
32
+ left: CalcAst;
33
+ right: CalcAst;
34
+ pos: CalcSpan;
35
+ } | {
36
+ k: 'call';
37
+ fn: CalcFunctionName;
38
+ args: CalcAst[];
39
+ pos: CalcSpan;
40
+ };
41
+ export declare function parseCalc(source: string): CalcAst;
42
+ /**
43
+ * 收集表达式引用的字段名(去重、首次出现序)。
44
+ *
45
+ * 这是 RG 反应图建 DAG 的原料之一:`total: { calc: "[amount] - [discount]" }`
46
+ * 的入边就是 `amount` 与 `discount`。Formily / amis 的依赖靠运行时收集,
47
+ * 所以它们建不出这张图——这个函数是那条结构性差异的落点。
48
+ */
49
+ export declare function collectCalcRefs(ast: CalcAst): string[];
@@ -0,0 +1,16 @@
1
+ import type { CalcAst } from './parser';
2
+ export type CalcType = 'number' | 'text' | 'bool' | 'date';
3
+ export interface CalcTypeContext {
4
+ /** 字段名 → 字典里的 `type`(缺省视为 text,与字典本身的缺省一致) */
5
+ fieldTypes: Readonly<Record<string, string | undefined>>;
6
+ /** 原始表达式串,仅用于错误定位 */
7
+ source: string;
8
+ }
9
+ export declare function inferCalcType(ast: CalcAst, ctx: CalcTypeContext): CalcType;
10
+ /**
11
+ * 与字段声明的 `type` 对账。
12
+ *
13
+ * 单独一个函数而不是塞进 `infer`:解析器可能被用在「只想知道类型」的场合
14
+ * (如 DW 的派生列预览),那时还没有目标字段。
15
+ */
16
+ export declare function assertCalcResultType(result: CalcType, declaredFieldType: string | undefined, ctx: CalcTypeContext, ast: CalcAst): void;
@@ -0,0 +1,23 @@
1
+ import type { SomaComponentContract, SomaContractField } from '../types/component-contract.types';
2
+ export interface SampleGap {
3
+ /** 缺口路径,如 `order.items[].sku_id` */
4
+ path: string;
5
+ reason: string;
6
+ }
7
+ export interface DeriveSampleResult {
8
+ /** 可直接喂给组件的 props */
9
+ props: Record<string, unknown>;
10
+ /** 必填却既无 example 也无 default 的字段 */
11
+ gaps: SampleGap[];
12
+ }
13
+ /** 从契约派生一份样张 props */
14
+ export declare function deriveContractSample(contract: SomaComponentContract): DeriveSampleResult;
15
+ /** 单个字段的样张值(组件内部或工具按需调用) */
16
+ export declare function deriveFieldSample(field: SomaContractField): unknown;
17
+ /**
18
+ * 这份契约够不够渲染一张有内容的样张。
19
+ *
20
+ * 判据是「至少有一个 prop 写了 example,或有嵌套字段写了 example」——
21
+ * 全靠 default 派生出来的是空态,展示页放上去只有一个空壳。
22
+ */
23
+ export declare function hasRenderableSample(contract: SomaComponentContract): boolean;
@@ -0,0 +1,19 @@
1
+ import type { SomaContractEmit, SomaContractField, SomaContractProp, SomaContractSlot } from '../types/component-contract.types';
2
+ export declare class SomaFieldLinesError extends Error {
3
+ readonly line: number;
4
+ constructor(message: string, line: number);
5
+ }
6
+ /** props 文本块 → 契约 props */
7
+ export declare function parseFieldLines(text: string): Record<string, SomaContractProp>;
8
+ /** emits 文本块 → 契约 emits。事件行是 `名: 描述`,下一级是载荷行 `名: 类型, 描述` */
9
+ export declare function parseEmitLines(text: string): Record<string, SomaContractEmit>;
10
+ /** slots 文本块 → 契约 slots。插槽行是 `名: 描述, 必填`(必填可省) */
11
+ export declare function parseSlotLines(text: string): Record<string, SomaContractSlot>;
12
+ /** 契约 props(或任意字段表)→ 字段行文本块 */
13
+ export declare function renderFieldLines(fields: Record<string, SomaContractField>): string;
14
+ /** TS 组件里写同一段文本:`props: somaFields\`…\`` */
15
+ export declare function somaFields(strings: TemplateStringsArray, ...values: unknown[]): Record<string, SomaContractProp>;
16
+ /** TS 组件里写事件文本块 */
17
+ export declare function somaEmits(strings: TemplateStringsArray, ...values: unknown[]): Record<string, SomaContractEmit>;
18
+ /** TS 组件里写插槽文本块 */
19
+ export declare function somaSlots(strings: TemplateStringsArray, ...values: unknown[]): Record<string, SomaContractSlot>;
@@ -0,0 +1,56 @@
1
+ /** 三种形态的判别式 */
2
+ export type SomaPathSelector = {
3
+ kind: 'each';
4
+ } | {
5
+ kind: 'self';
6
+ } | {
7
+ kind: 'offset';
8
+ delta: number;
9
+ };
10
+ export interface SomaListPath {
11
+ /** 列表字段名(`items`) */
12
+ list: string;
13
+ selector: SomaPathSelector;
14
+ /** 项内字段名(`discount`);支持多级 `a.b` */
15
+ field: string;
16
+ /** 原样保留,报错时回指作者写的那串 */
17
+ source: string;
18
+ }
19
+ /** 一个引用是不是列表路径(不是的话按普通顶层字段处理) */
20
+ export declare function isListPath(reference: string): boolean;
21
+ export declare class SomaPathError extends Error {
22
+ constructor(message: string);
23
+ }
24
+ export declare function parseListPath(reference: string): SomaListPath;
25
+ /**
26
+ * 展开成逐项的具体路径。
27
+ *
28
+ * `count` 是运行期的项数——展开发生在**每次求值前**而不是解析期:
29
+ * 项数会变(用户增删行),而解析期展开出来的模板会立刻过期。
30
+ * 解析期做的是**校验**(列表字段在不在字典里、项内字段在不在 `item_fields` 里),
31
+ * 那部分才是静态的。
32
+ *
33
+ * 越界的偏移(最后一项的 `[+1]`)产出 `null` 而不是抛:
34
+ * 「最后一段没有下一段」是正常的数据形态,不是错误。调用方按"读不到值"处理。
35
+ */
36
+ export declare function expandListPath(path: SomaListPath, count: number, currentIndex?: number): Array<{
37
+ index: number;
38
+ path: string;
39
+ } | null>;
40
+ /**
41
+ * 从一份值里读列表路径指向的值。
42
+ *
43
+ * 读不到一律 `null`(不抛、不返回 undefined):反应图的求值面对的是**半填的表单**,
44
+ * 缺值是常态。抛的话,一个还没填到的明细行会炸掉整张表的联动。
45
+ */
46
+ export declare function readListPath(values: Record<string, unknown>, path: SomaListPath, index: number): unknown;
47
+ /**
48
+ * 声明期校验:列表字段在不在字典里、它是不是 list、项内字段在不在 `item_fields` 里。
49
+ *
50
+ * 这三条是静态的,所以必须在声明期查完——留到运行期的话,一个拼错的项内字段名
51
+ * 只会让那条联动**永远不成立**,而"永远不成立"和"条件确实没满足"看不出区别。
52
+ */
53
+ export declare function validateListPath(path: SomaListPath, fields: Record<string, {
54
+ type?: string;
55
+ item_fields?: unknown;
56
+ }>): string[];
@@ -0,0 +1,79 @@
1
+ /** 十二个具名算子——封闭集合,不接受任何其他取值 */
2
+ export declare const SOMA_FIELD_PREDICATE_OPS: readonly ["eq", "ne", "in", "not_in", "empty", "not_empty", "gt", "gte", "lt", "lte", "between", "matches", "starts_with", "ends_with", "contains"];
3
+ export type SomaFieldPredicateOp = typeof SOMA_FIELD_PREDICATE_OPS[number];
4
+ /** 单条件:某个字段的当前值满足某个算子 */
5
+ export interface SomaFieldCondition {
6
+ /** 被观察字段的 key(必须是同一层里真实存在的字段) */
7
+ field: string;
8
+ op: SomaFieldPredicateOp;
9
+ /**
10
+ * eq/ne/gt/gte/lt/lte 的比较值;in/not_in 的候选数组;between 的 [低, 高](闭区间);
11
+ * matches 的正则源串(不带斜杠与 flag);empty/not_empty 不用
12
+ */
13
+ value?: unknown;
14
+ /**
15
+ * 深取路径:字段值是对象时读它的子键。只允许 `a.b.c` 与 `a[0].b` 两种写法——
16
+ * 它是 JSONPath 的一个极小子集,刻意不支持通配与过滤(那些属于查询语言)。
17
+ */
18
+ path?: string;
19
+ }
20
+ /** 引用一条具名谓词(在 `predicates:` 表里声明过的名字) */
21
+ export interface SomaFieldPredicateRef {
22
+ ref: string;
23
+ }
24
+ /** 全部成立 */
25
+ export interface SomaFieldPredicateAllOf {
26
+ all_of: SomaFieldPredicate[];
27
+ }
28
+ /** 任一成立 */
29
+ export interface SomaFieldPredicateAnyOf {
30
+ any_of: SomaFieldPredicate[];
31
+ }
32
+ /** 全部不成立(取反) */
33
+ export interface SomaFieldPredicateNoneOf {
34
+ none_of: SomaFieldPredicate[];
35
+ }
36
+ export type SomaFieldPredicate = SomaFieldCondition | SomaFieldPredicateRef | SomaFieldPredicateAllOf | SomaFieldPredicateAnyOf | SomaFieldPredicateNoneOf;
37
+ /** 具名谓词表:名字 → 谓词。声明一次,到处 `{ ref: 名字 }` */
38
+ export type SomaNamedPredicates = Readonly<Record<string, SomaFieldPredicate>>;
39
+ /** 校验期可选上下文 */
40
+ export interface SomaPredicateValidateOptions {
41
+ /** 字段名 → 字段类型(来自字典 `type`);给了就做算子 × 类型配对 */
42
+ fieldTypes?: Readonly<Record<string, string | undefined>>;
43
+ /** 具名谓词表;给了才允许 `{ ref }`,且会一并校验被引用的谓词 */
44
+ named?: SomaNamedPredicates;
45
+ }
46
+ /**
47
+ * 谓词求值。
48
+ *
49
+ * `values` 是**同一层**的值对象:顶层字段传整张表的 values,`item_fields` 的谓词传那一项
50
+ * 自己的对象。`named` 是具名谓词表;`{ ref }` 在这里解析。
51
+ *
52
+ * 环保护:具名谓词互相引用成环时(校验期本该拦下,但运行期不能指望它)按「不成立」处理,
53
+ * 绝不无限递归——一个写错的声明不该把页面挂死。
54
+ */
55
+ export declare function evaluatePredicate(predicate: SomaFieldPredicate | null | undefined, values: Record<string, unknown>, named?: SomaNamedPredicates): boolean;
56
+ /**
57
+ * 谓词静态校验:返回问题清单(空数组 = 通过)。
58
+ *
59
+ * @param fieldKeys 同一层里合法的字段名全集
60
+ * @param path 问题定位用的声明路径(如 `fields[2].visible_when`)
61
+ * @param options 可选:字段类型表(做算子配对)与具名谓词表(允许并校验 `ref`)
62
+ *
63
+ * 调用方拿到非空清单时的正确处置是「当作不成立 + `console.warn` 点名」——
64
+ * 让一个写错的联动声明**看得见**,而不是让字段悄悄消失。
65
+ */
66
+ export declare function validatePredicate(predicate: unknown, fieldKeys: readonly string[], path: string, options?: SomaPredicateValidateOptions): string[];
67
+ /**
68
+ * 具名谓词表整体校验:每一条都合法、彼此不成环。
69
+ * 表单在挂载时调一次;问题清单非空时 `console.warn` 点名并把有问题的那几条当作不成立。
70
+ */
71
+ export declare function validateNamedPredicates(named: unknown, fieldKeys: readonly string[], fieldTypes?: Readonly<Record<string, string | undefined>>): string[];
72
+ /**
73
+ * 收集一条谓词直接或经 ref 间接依赖的全部字段名(去重、声明序)。
74
+ *
75
+ * 这是反应图(REQ-010 S1)建 DAG 的原料:知道「这条反应看哪些字段」,
76
+ * 才能在编译期排出求值顺序、检出环、并回答「改这个字段会牵动哪些反应」。
77
+ * amis / Formily 的依赖是运行时收集的,所以做不到这一步。
78
+ */
79
+ export declare function collectPredicateFields(predicate: SomaFieldPredicate | null | undefined, named?: SomaNamedPredicates): string[];
@@ -8,15 +8,33 @@ export type SomaComponentLayer = 'atom' | 'composite' | 'solution' | 'template';
8
8
  */
9
9
  export type SomaGeometryFamily = 'control' | 'surface' | 'message' | 'data' | 'overlay' | 'layout' | 'display';
10
10
  export type SomaContractPropType = 'number' | 'string' | 'boolean' | 'enum' | 'object' | 'array';
11
- export interface SomaContractProp {
11
+ /**
12
+ * 字段(REQ-012)。
13
+ *
14
+ * prop、对象里的字段、数组元素、事件载荷是同一种东西,所以只有这一个形状,递归到底:
15
+ * `type: object` 用 `fields` 继续描述,`type: array` 用 `items` 描述元素。
16
+ *
17
+ * 为什么要 `example` 而不是靠 `default`:规则 C4 要求可选 prop 有默认值,而默认值按
18
+ * C4a 必须是空串 / 空数组这类浅结构——拿它渲染出来的永远是空态。展示页、视觉矩阵与
19
+ * AI 需要的是「这个字段真实长什么样」,那是另一个值,必须另有一处写。
20
+ */
21
+ export interface SomaContractField {
12
22
  type: SomaContractPropType;
23
+ desc?: string;
13
24
  required?: boolean;
14
25
  /** 非 required 的 prop 必须有默认值(契约规则 C4:零 props 可渲染) */
15
26
  default?: unknown;
16
- desc?: string;
27
+ /** 示例值(REQ-012):样张与展示页的数据来源;不参与运行时,只被派生与目录消费 */
28
+ example?: unknown;
17
29
  /** type === 'enum' 时的取值集合 */
18
30
  values?: (string | number)[];
19
- /** 绑定模式:oneway(默认)| model(双向,一个组件最多一个) */
31
+ /** type === 'object' 时的子字段(REQ-012) */
32
+ fields?: Record<string, SomaContractField>;
33
+ /** type === 'array' 时的元素形状(REQ-012) */
34
+ items?: SomaContractField;
35
+ }
36
+ export interface SomaContractProp extends SomaContractField {
37
+ /** 绑定模式:oneway(默认)| model(双向,一个组件最多一个)。只在 prop 一层有意义 */
20
38
  mode?: 'oneway' | 'model';
21
39
  }
22
40
  /**
@@ -29,9 +47,7 @@ export interface SomaContractProp {
29
47
  * 返回相对 default 的首个违规路径;`null` 表示最外层浅拷贝已足够隔离。
30
48
  */
31
49
  export declare function findNestedMutableContractDefault(value: unknown): string | null;
32
- export interface SomaContractEmitPayloadField {
33
- type: SomaContractPropType;
34
- desc?: string;
50
+ export interface SomaContractEmitPayloadField extends SomaContractField {
35
51
  }
36
52
  export interface SomaContractEmit {
37
53
  payload?: Record<string, SomaContractEmitPayloadField>;
@@ -41,6 +57,22 @@ export interface SomaContractSlot {
41
57
  desc?: string;
42
58
  required?: boolean;
43
59
  }
60
+ /**
61
+ * 组件级令牌(三级令牌的第三级,REQ-009 M-1)。
62
+ *
63
+ * 为什么是「组件自己声明旋钮」而不是 MUI 的 `styleOverrides.<slot>`:
64
+ * 后者要求 Host 知道组件内部结构,而 `scopeAnchors()` 刻意让页面永不可寻址组件内部。
65
+ * 组件声明可调令牌 = 组件自己承诺「这几个值可以被外面改,改了不会散架」,
66
+ * 内部结构仍然封闭。
67
+ *
68
+ * `default` 必须形如 `var(--soma-…)`:组件令牌是语义令牌的**别名与收窄**,
69
+ * 不是新的真源。写裸值等于在组件里开一个绕过主题的后门。
70
+ */
71
+ export interface SomaContractToken {
72
+ /** 必须引用语义令牌:var(--soma-…),可带回退值 */
73
+ default: string;
74
+ desc: string;
75
+ }
44
76
  /**
45
77
  * AI 目录段(契约规范第 11 章):AI 生成页面前查表选组件的依据。
46
78
  * when_to_use / example 为目录质量线;when_not_to_use 用于同族组件消歧。
@@ -64,6 +96,11 @@ export interface SomaComponentContract {
64
96
  props?: Record<string, SomaContractProp>;
65
97
  emits?: Record<string, SomaContractEmit>;
66
98
  slots?: Record<string, SomaContractSlot>;
99
+ /**
100
+ * 组件级令牌:key 为 kebab-case,装配期写出 `--soma-<组件名 kebab>-<key>`。
101
+ * 主题输入的 `components.<组件名>.<key>` 覆盖它,`ThemeScope` 可按子树覆盖。
102
+ */
103
+ tokens?: Record<string, SomaContractToken>;
67
104
  ai?: SomaContractAiSection;
68
105
  /**
69
106
  * 声明式覆盖:本组件有意替换该包里的同名组件(值为被覆盖组件的来源包名,如 'soma-ui')。
@@ -75,4 +112,95 @@ export interface SomaComponentContract {
75
112
  * 未声明的跨包撞名一律抛错——写出来的覆盖是设计决定,猜出来的覆盖是事故。
76
113
  */
77
114
  overrides?: string;
115
+ /**
116
+ * 依赖的其它组件(REQ-010 F-46):PascalCase 契约名数组。
117
+ *
118
+ * 两件事靠它:
119
+ * ① **按图拉齐**——`soma pack init` / eject 一个 TreeSelect 时能知道它还要 Tree,
120
+ * 而不是等页面渲染出一堆没样式的节点才发现(这条曾真实发生过:
121
+ * `COMPONENT_CSS_DEPS` 少写一条 `TreeSelect: ['Tree']`,页面上是无样式的折叠箭头);
122
+ * ② **可寻址目录**——`registry.json` 的每一项带版本、哈希与依赖,
123
+ * 于是"我这份是从哪一版来的、它还需要谁"两个问题都有答案。
124
+ * shadcn 的 registry 两个都没有。
125
+ *
126
+ * 只登记**契约级**依赖(模板里真的嵌了那个组件、或 CSS 分片依赖它),
127
+ * 不登记共享资产(`shared/*` 由构建图自然带上,写进来只会重复一份且会漂)。
128
+ */
129
+ uses?: string[];
130
+ /**
131
+ * 浮层行为契约(REQ-010 F-41 / F-42)。
132
+ *
133
+ * 声明而不是各组件自写:十几个浮层组件里的"点外面关不关""Esc 关不关"
134
+ * "退场动画放完再卸载"此前各有一份实现,而它们的差异只在某个具体组件上暴露
135
+ * (某个下拉点外面不关、某个抽屉 Esc 无效)。收成契约之后,
136
+ * 引擎按声明接线,组件不再碰这些代码。
137
+ */
138
+ overlay?: SomaContractOverlay;
139
+ /**
140
+ * 键盘契约(REQ-010 F-43)。
141
+ *
142
+ * 声明这是个什么布局(列表 / 网格 / 树),引擎据此挑键盘委托并接上方向键。
143
+ * 组件因此删掉自写的方向键分支——六个组件曾各写一套,最后一行按 ↓ 的行为各不相同。
144
+ * 另一个收益:**键盘矩阵能自动进目录**,AI 与业务开发者不必读源码才知道按键表。
145
+ */
146
+ keyboard?: SomaContractKeyboard;
147
+ }
148
+ /** 浮层行为的封闭词汇 */
149
+ export interface SomaContractOverlay {
150
+ /** 浮层类型:决定默认的模态性与回焦策略 */
151
+ kind: 'popup' | 'modal' | 'non_modal' | 'toast';
152
+ /**
153
+ * Esc 的行为。`defer` 表示交给外层——嵌套浮层里,内层已经处理过就不该再传。
154
+ * 显式三档而不是布尔:`false` 与 `defer` 的差别正是"吞掉"与"让出去"。
155
+ */
156
+ escape_key_behavior?: 'close' | 'none' | 'defer';
157
+ /** 点外面关不关;`ignore` 用于必须显式操作才能关的对话框 */
158
+ outside_press_behavior?: 'close' | 'ignore';
159
+ /** 退场动画放完再卸载(F-42):不挂起的话,关闭动画根本看不见 */
160
+ presence?: boolean;
161
+ /** 打开时把外部标 aria-hidden(F-44);模态默认真 */
162
+ hide_outside?: boolean;
163
+ /** 关闭后把焦点还给触发者;默认真 */
164
+ restore_focus?: boolean;
165
+ }
166
+ /** 键盘导航的封闭词汇 */
167
+ export interface SomaContractKeyboard {
168
+ /** 布局形态:决定挑哪个键盘委托 */
169
+ layout: 'list' | 'grid' | 'tree' | 'none';
170
+ /** 网格列数;`layout: grid` 时必填(DOM 上看不出来,猜错就跳到无关格子) */
171
+ columns?: number;
172
+ /** 到边之后回绕还是停住 */
173
+ wrap?: boolean;
174
+ /** 首字母跳转 */
175
+ typeahead?: boolean;
176
+ /** 焦点模型:漫游 tabindex 还是 aria-activedescendant */
177
+ focus_model?: 'roving' | 'activedescendant';
178
+ /** 选中随焦点移动(单选列表的常见形态) */
179
+ selection_follows_focus?: boolean;
180
+ /**
181
+ * 主轴方向:横向时 ←/→ 走上一项/下一项(tablist、菜单栏),RTL 下自动换向;
182
+ * 缺省纵向(↑/↓);`both` 是 APG 单选组的形态——两轴都走同一条链
183
+ * (排成一行还是一列只是 CSS 的事,键盘用户不该先猜方向)。网格两轴各有语义,本项无意义。
184
+ */
185
+ orientation?: 'horizontal' | 'vertical' | 'both';
186
+ /**
187
+ * 空格的语义:`activate`(与 Enter 同义,单选列表 / 树 / 选项卡)、
188
+ * `toggle_select`(勾选当前项而不确认,多选 listbox / 穿梭框)或
189
+ * `none`(这个键不归本组件——触发器是原生 button 的下拉就属这种:
190
+ * Space 是按钮自己的"按下",抢过来会变成"选中一项的同时又把面板重新打开")。缺省 `activate`。
191
+ * 显式三档而不是从别的字段推:Space 在多选列表里按成"确认"会把用户刚勾的东西直接提交出去,
192
+ * 而在按钮触发的下拉里按成"确认"会和浏览器的按钮语义打架。
193
+ */
194
+ space?: 'activate' | 'toggle_select' | 'none';
195
+ /**
196
+ * 组件特有的按键(引擎矩阵之外):按键 → 说明。例如 Tabs 的 `Delete: 关闭当前项`、
197
+ * Tree 的 `Alt+方向键: 搬运节点`。**只进目录,不由引擎接线**——组件自己处理,
198
+ * 但键盘表必须完整:读目录的人(与 AI)不该只看到一半的按键。
199
+ */
200
+ extra?: Record<string, string>;
78
201
  }
202
+ /** PascalCase 组件名 → 令牌前缀用的 kebab-case(DataTable → data-table) */
203
+ export declare function componentTokenPrefix(name: string): string;
204
+ /** 组件令牌的 CSS 变量名:Button + radius → --soma-button-radius */
205
+ export declare function componentTokenVar(componentName: string, tokenKey: string): string;
206
+ export declare const COMPONENT_TOKEN_KEY_PATTERN: RegExp;