soma-kit 0.1.13 → 0.1.14

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 (174) hide show
  1. package/package.json +3 -3
  2. package/spec/generated/kit-app.schema.json +14 -0
  3. package/spec/generated/kit-page.schema.json +25 -0
  4. package/spec/kit-grammar.json +178 -27
  5. package/spec/kit-grammar.schema.json +1 -3
  6. package/src/app/app-config.ts +10 -4
  7. package/src/app/index.ts +13 -1
  8. package/src/app/kit-view-context.ts +19 -2
  9. package/src/app/server-pages.ts +5 -1
  10. package/src/app/server.ts +15 -5
  11. package/src/base/button.ts +5 -3
  12. package/src/base/end-edge.ts +14 -2
  13. package/src/base/gap-value.ts +24 -4
  14. package/src/base/illustrations.ts +2 -1
  15. package/src/base/index.ts +5 -0
  16. package/src/base/menu-button.ts +10 -23
  17. package/src/base/popover.ts +5 -4
  18. package/src/base/segmented.ts +14 -4
  19. package/src/base/shared.ts +11 -13
  20. package/src/base/state-panel.ts +34 -13
  21. package/src/base/tag.ts +18 -13
  22. package/src/base/text.ts +1 -1
  23. package/src/base/upload.ts +5 -4
  24. package/src/biz/approval-desk/shell.ts +8 -7
  25. package/src/biz/auth-panel/shell.ts +5 -4
  26. package/src/biz/category-crud/compile.ts +3 -2
  27. package/src/biz/category-crud/shell.ts +4 -3
  28. package/src/biz/checkout-page/shell.ts +9 -8
  29. package/src/biz/compose.ts +2 -2
  30. package/src/biz/data-components.ts +4 -0
  31. package/src/biz/import-wizard/shell.ts +12 -10
  32. package/src/biz/landing-page/shell.ts +2 -2
  33. package/src/biz/master-sub/compile.ts +114 -15
  34. package/src/biz/master-sub/detail-head.ts +61 -0
  35. package/src/biz/master-sub/index.ts +3 -2
  36. package/src/biz/master-sub/shell.ts +95 -63
  37. package/src/biz/multi-board/compile.ts +164 -9
  38. package/src/biz/multi-board/composition.ts +58 -0
  39. package/src/biz/multi-board/index.ts +1 -1
  40. package/src/biz/multi-board/prose-fold.ts +143 -0
  41. package/src/biz/multi-board/shell.ts +91 -23
  42. package/src/biz/notification-center/shell.ts +6 -5
  43. package/src/biz/page-templates/domain-templates.ts +2 -2
  44. package/src/biz/page-templates/result-page/shell.ts +2 -2
  45. package/src/biz/page-templates/sign-in-page/shell.ts +14 -14
  46. package/src/biz/record-detail/shell.ts +8 -7
  47. package/src/biz/settings-center/shell.ts +8 -7
  48. package/src/biz/shared/compile-helpers.ts +82 -3
  49. package/src/biz/shared/overlay-compile.ts +46 -4
  50. package/src/biz/shared/overlay-shell.ts +8 -6
  51. package/src/biz/single-form/shell.ts +6 -4
  52. package/src/biz/standard-crud/compile.ts +14 -1
  53. package/src/biz/standard-crud/shell.ts +18 -27
  54. package/src/biz/standard-crud/summary.ts +40 -0
  55. package/src/biz/step-form/shell.ts +11 -9
  56. package/src/biz/types.ts +6 -1
  57. package/src/cli/layout-cli.ts +7 -7
  58. package/src/compile/access-gate-attach.ts +27 -0
  59. package/src/compile/compile-page.ts +15 -4
  60. package/src/compile/component-candidates.ts +2 -0
  61. package/src/compile/fragment.ts +11 -0
  62. package/src/compile/layout-lint/rules-composition.ts +55 -6
  63. package/src/compile/layout-lint/rules-form.ts +6 -7
  64. package/src/compile/layout-lint/rules-table.ts +98 -14
  65. package/src/compile/page-composition.ts +189 -0
  66. package/src/compile/parse.ts +4 -0
  67. package/src/compile/producer-fingerprint.ts +56 -0
  68. package/src/compile/styles.ts +11 -1
  69. package/src/compile/types.ts +3 -1
  70. package/src/data/access-gate.ts +112 -0
  71. package/src/data/amount-breakdown.ts +3 -1
  72. package/src/data/approval-flow.ts +4 -1
  73. package/src/data/assignment-picker.ts +9 -4
  74. package/src/data/async-result-panel.ts +1 -1
  75. package/src/data/calendar.ts +7 -2
  76. package/src/data/carousel.ts +2 -0
  77. package/src/data/chart.ts +609 -42
  78. package/src/data/checklist.ts +4 -1
  79. package/src/data/comment-thread.ts +2 -1
  80. package/src/data/confirm-dialog.ts +4 -10
  81. package/src/data/field-mapper.ts +4 -1
  82. package/src/data/flow-editor.ts +2 -1
  83. package/src/data/footer.ts +2 -0
  84. package/src/data/gantt.ts +187 -25
  85. package/src/data/hero.ts +2 -0
  86. package/src/data/index.ts +10 -3
  87. package/src/data/item-list.ts +10 -3
  88. package/src/data/kanban.ts +3 -1
  89. package/src/data/matrix.ts +391 -0
  90. package/src/data/menu.ts +23 -11
  91. package/src/data/mockup.ts +3 -3
  92. package/src/data/modal-dialog.ts +118 -18
  93. package/src/data/navbar.ts +3 -1
  94. package/src/data/notice-list.ts +52 -19
  95. package/src/data/object-form.ts +128 -112
  96. package/src/data/pager.ts +3 -2
  97. package/src/data/panel-head.ts +406 -0
  98. package/src/data/permission-matrix.ts +4 -1
  99. package/src/data/permission-tree.ts +6 -2
  100. package/src/data/pricing-table.ts +2 -1
  101. package/src/data/record-card.ts +18 -6
  102. package/src/data/resident.ts +8 -0
  103. package/src/data/row-editor.ts +2 -2
  104. package/src/data/rule-builder.ts +9 -4
  105. package/src/data/shape-util.ts +15 -14
  106. package/src/data/stat-group.ts +313 -69
  107. package/src/data/static-lazy.ts +4 -0
  108. package/src/data/static-registry.ts +6 -0
  109. package/src/data/survey.ts +4 -1
  110. package/src/data/system-switcher.ts +2 -1
  111. package/src/data/tour-guide.ts +2 -1
  112. package/src/data/transfer.ts +6 -2
  113. package/src/data/tree-table.ts +7 -5
  114. package/src/data/tree.ts +1 -1
  115. package/src/data/virtual-rows.ts +5 -4
  116. package/src/data/wrapped-candidates.ts +22 -1
  117. package/src/frames/index.ts +1 -0
  118. package/src/frames/list-summary.ts +100 -0
  119. package/src/frames/page-bar.ts +6 -14
  120. package/src/frames/shared.ts +20 -4
  121. package/src/frames/tabs-frame/shell.ts +8 -6
  122. package/src/frames/top-main-frame.ts +1 -1
  123. package/src/frames/types.ts +3 -1
  124. package/src/frames/workspace-frame/shell.ts +2 -2
  125. package/src/frames/workspace-frame/tab-scroll.ts +28 -0
  126. package/src/frames/workspace-frame/view.ts +41 -25
  127. package/src/generated/kit-grammar-runtime.ts +175 -28
  128. package/src/i18n/kit-text.ts +27 -0
  129. package/src/object-renderer/action-group.ts +139 -0
  130. package/src/object-renderer/action-more.ts +144 -0
  131. package/src/object-renderer/arrange.ts +49 -19
  132. package/src/object-renderer/candidates.ts +4 -0
  133. package/src/object-renderer/collection-parts.ts +34 -13
  134. package/src/object-renderer/collection-table.ts +133 -65
  135. package/src/object-renderer/collection.ts +72 -59
  136. package/src/object-renderer/defaults.ts +2 -5
  137. package/src/object-renderer/emit-object.ts +4 -0
  138. package/src/object-renderer/emit-static.ts +116 -63
  139. package/src/object-renderer/filter-plan.ts +84 -0
  140. package/src/object-renderer/index.ts +5 -0
  141. package/src/object-renderer/layout-facts.ts +9 -1
  142. package/src/object-renderer/layout-plan.ts +136 -43
  143. package/src/object-renderer/layout-plan.types.ts +42 -5
  144. package/src/object-renderer/parts.ts +7 -259
  145. package/src/object-renderer/render-object.ts +59 -46
  146. package/src/object-renderer/table-actions.ts +72 -40
  147. package/src/object-renderer/table-gap.ts +37 -0
  148. package/src/object-renderer/table-tools.ts +51 -20
  149. package/src/object-renderer/types.ts +7 -7
  150. package/src/recipes/container.ts +31 -0
  151. package/src/recipes/control.ts +57 -155
  152. package/src/recipes/emphasis.ts +56 -0
  153. package/src/recipes/frame-bleed.ts +33 -0
  154. package/src/recipes/index.ts +23 -0
  155. package/src/recipes/overlay.ts +46 -1
  156. package/src/recipes/placeholder.ts +20 -4
  157. package/src/recipes/rail-grid.ts +3 -0
  158. package/src/recipes/stat-state.ts +65 -0
  159. package/src/recipes/state.ts +12 -22
  160. package/src/recipes/status.ts +8 -0
  161. package/src/recipes/surface-edge.ts +16 -0
  162. package/src/recipes/table-gap.ts +80 -0
  163. package/src/recipes/table-native-edit.ts +242 -0
  164. package/src/recipes/table-row.ts +112 -6
  165. package/src/recipes/tabs.ts +49 -0
  166. package/src/recipes/title-row.ts +3 -3
  167. package/src/recipes/typography.ts +23 -42
  168. package/src/theme/kit-theme-text.ts +1 -1
  169. package/src/theme/kit-theme.css +13 -2
  170. package/src/theme/kit-theme.tpl +13 -2
  171. package/src/theme/nine-dim-structure.ts +77 -10
  172. package/src/theme/surface-layers.ts +6 -1
  173. package/src/theme/theme-tokens.ts +12 -5
  174. package/src/theme/typography.ts +21 -17
@@ -0,0 +1,242 @@
1
+ // 原生表格出口增强(table-native-edit.ts):补齐 KIT_TABLE_NATIVE_CLASS 表达不了的两类需求——
2
+ // 1. 单元格内放 kit 行内编辑控件(选择器 / 输入 / 开关 / 复选);
3
+ // 2. 跨列复合行(分组标题行 / 行下展开详情行 / 汇总行)。
4
+ // 取值全部来自既有令牌与真源:行高 = 主题结构规则 `table tbody td { height: var(--soma-table-row-height) }`(本文件不写任何高度)、
5
+ // 小号控件高 = 真源 kit-nine-dim.json#structure.smallControlHeightUnits(经 control 配方的 sm 档,本文件不重复写 h-*)。
6
+ //
7
+ // 【编辑单元格的对齐与行高规则】
8
+ // - 行高:编辑格只给 py-0.5,控件取 sm 档(24px,随密度同比走)远小于行高令牌(紧凑 32 / 标准 40 / 宽松更高),行高仍由令牌决定、不被控件撑高;
9
+ // 本配方类里没有任何 h-* / min-h-* / py-1 以上的类(测试断言)。控件垂直居中靠 td 的 align-middle。
10
+ // - 对齐:编辑列的单元格左右内边距统一 2px(px-0.5,恰好容下 2px 焦点环,避免被外壳 overflow-x-auto 裁切);
11
+ // 控件文字左缘 = 2px 格内边距 + 1px 控件边框 + 10px 控件内边距(sm 输入 px-2.5)= 13px。
12
+ // 同一列的只读文字(KIT_TABLE_NATIVE_EDIT_CLASS.textInset:border-s border-transparent ps-2.5 的行内块,同样 1 + 10)
13
+ // 与表头文字(head: true 的格 + 同一 textInset 包裹)也落在 13px,所以只读态与可编辑态左缘一致。
14
+ // 各控件 sm 档的水平内边距不同(输入 / 选择器 px-2.5 + 1px 边框;按钮 px-3,neutral 有 1px 描边、其余无描边且居中),
15
+ // 所以 kitTableNativeEditControlRecipe 按控件类型(field / button / button-flat)出对应内缩,三类控件的文字左缘都落在 13px。
16
+ // - 宽度:fill(缺省)= 控件随列宽(min-w-0 w-full,列宽由表格布局 / 表头定);content = 按内容(min-w-0 不撑破列)。
17
+
18
+ import { classCandidates } from '../base/class-candidates';
19
+ import { kitIconHtml } from '../base/icons';
20
+ import { mergeClass } from '../object-renderer/merge-class';
21
+ import { escapeHtml } from '../shared/escape';
22
+ import { KIT_TABLE_NATIVE_CLASS, kitTableNativeCellRecipe, type KitTableAlign } from './table-row';
23
+ import { kitTypographyRecipe } from './typography';
24
+
25
+ export const KIT_TABLE_NATIVE_EDIT_CLASS = Object.freeze({
26
+ /** 编辑列数据格:2px 左右内边距,垂直居中,不带任何高度类 */
27
+ cell: mergeClass('px-0.5 py-0.5 align-middle', kitTypographyRecipe('text')),
28
+ /** 编辑列表头格:与 cell 同内边距,排版同 KIT_TABLE_NATIVE_CLASS.headCell(表头文字另用 textInset 包裹以对齐控件文字) */
29
+ headCell: mergeClass('whitespace-nowrap px-0.5 py-0.5', kitTypographyRecipe('tableHead')),
30
+ /** 控件随列宽 */
31
+ controlFill: 'min-w-0 w-full',
32
+ /** 控件按内容 */
33
+ controlContent: 'min-w-0',
34
+ /** 只读 / 表头文字与控件文字左缘对齐的内缩(1px 透明边框 + 10px,等于 sm 输入控件的边框 + px-2.5) */
35
+ textInset: 'inline-block border-s border-transparent ps-2.5',
36
+ });
37
+
38
+ export type KitTableNativeEditWidth = 'fill' | 'content';
39
+
40
+ export interface KitTableNativeEditCellRecipeOptions {
41
+ /** 表头格(缺省数据格) */
42
+ head?: boolean;
43
+ align?: KitTableAlign;
44
+ numeric?: boolean;
45
+ }
46
+
47
+ /**
48
+ * 编辑列单元格类串(单元格里放 kit 控件、或同一列只读态):不撑高行、2px 内边距、对齐规则见文件头。
49
+ * 数值列缺省右对齐等宽数字(右对齐时控件应按内容宽并靠右,文字内缩规则只对左对齐列成立)。
50
+ */
51
+ export function kitTableNativeEditCellRecipe(options: KitTableNativeEditCellRecipeOptions = {}): string {
52
+ const numeric = Boolean(options.numeric);
53
+ const align: KitTableAlign = options.align ?? (numeric ? 'right' : 'left');
54
+ const base = options.head === true ? KIT_TABLE_NATIVE_EDIT_CLASS.headCell : KIT_TABLE_NATIVE_EDIT_CLASS.cell;
55
+ const alignCls = align === 'right' ? 'text-end' : align === 'center' ? 'text-center' : 'text-start';
56
+ return [base, alignCls, numeric ? KIT_TABLE_NATIVE_CLASS.cellNumeric : ''].filter(Boolean).join(' ');
57
+ }
58
+
59
+ /**
60
+ * 控件类型(决定文字左缘的内缩):
61
+ * - field:输入框 / 选择器 / 日期等单行字段(sm 档 px-2.5 + 1px 边框,文字左缘本来就在 13px,不需要额外类);
62
+ * - button:带描边的按钮(neutral;sm 档 px-3 居中,描边 1px):改左对齐并把左内边距收成 px-2.5 的 10px,文字左缘 = 2 + 1 + 10 = 13px;
63
+ * - button-flat:无描边的按钮(ghost / tonal / primary / danger;sm 档 px-3 居中):左对齐、左内边距 10px 外加 1px 透明起始边,文字左缘同为 13px。
64
+ */
65
+ export type KitTableNativeEditControlKind = 'field' | 'button' | 'button-flat';
66
+
67
+ const CONTROL_INSET: Readonly<Record<KitTableNativeEditControlKind, string>> = Object.freeze({
68
+ field: '',
69
+ button: 'justify-start ps-2.5',
70
+ 'button-flat': 'justify-start border-s border-transparent ps-2.5',
71
+ });
72
+
73
+ /**
74
+ * 放进编辑格的控件的宽度与对齐类(叠加在控件自己的 sm 档配方类之后):
75
+ * 宽度按 fill / content;`kind` 缺省 field,按钮类控件传 button / button-flat 以使文字左缘与只读文字、表头文字一致(见文件头)。
76
+ */
77
+ export function kitTableNativeEditControlRecipe(width: KitTableNativeEditWidth = 'fill', kind: KitTableNativeEditControlKind = 'field'): string {
78
+ const w = width === 'content' ? KIT_TABLE_NATIVE_EDIT_CLASS.controlContent : KIT_TABLE_NATIVE_EDIT_CLASS.controlFill;
79
+ return [w, CONTROL_INSET[kind]].filter(Boolean).join(' ');
80
+ }
81
+
82
+ // ---------------------------------------------------------------- 跨列复合行
83
+
84
+ export const KIT_TABLE_NATIVE_SPAN_CLASS = Object.freeze({
85
+ /** 分组标题行:tbody 的行分隔线由主题结构规则给;这里只留上方空白(pt-4)与辅助色小标题,无悬停 */
86
+ groupRow: '',
87
+ groupCell: mergeClass('pt-4 pb-1 px-2 ps-0 text-start', kitTypographyRecipe('tableGroup')),
88
+ /** 可折叠分组:折叠按钮(展开朝下、折叠朝起始侧,aria-expanded 驱动)与标题行(按钮 + 标题同一行) */
89
+ groupToggle: 'group/grp inline-flex shrink-0 items-center justify-center rounded-sm text-fg-muted hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
90
+ groupChevron: 'transition-transform -rotate-90 group-aria-expanded/grp:rotate-0',
91
+ groupHead: 'flex items-center gap-1',
92
+ /** 展开详情行:无行悬停;与父行相连靠起始侧 2px 分隔色竖线 + 下沉底色 + 缩进 */
93
+ detailRow: '',
94
+ detailCell: 'px-2 py-2 ps-4 border-s-2 border-border-divider bg-surface-sunken text-sm text-fg',
95
+ /** 汇总行:上缘加强分隔(border-border-strong),字重 600,无悬停 */
96
+ summaryRow: 'border-t border-border-strong font-semibold',
97
+ summaryCell: 'font-semibold',
98
+ /** 内层吸顶包裹:横向滚动时跨列行内容贴在可视区起始边,不随表格滚走 */
99
+ stickyInner: 'sticky start-0 w-fit max-w-full',
100
+ });
101
+
102
+ /** 跨列行的标记属性名(值 = group / detail / summary);主题结构规则 nine-dim-structure 的表格规则读它 */
103
+ export const KIT_TABLE_NATIVE_SPAN_ATTR = 'data-kit-span';
104
+ /** 可折叠分组:分组行标 data-kit-group="<id>",成员行标 data-kit-group-of="<id>",折叠按钮标 data-kit-group-toggle */
105
+ export const KIT_TABLE_NATIVE_GROUP_ATTR = 'data-kit-group';
106
+ export const KIT_TABLE_NATIVE_GROUP_OF_ATTR = 'data-kit-group-of';
107
+ export const KIT_TABLE_NATIVE_GROUP_TOGGLE_ATTR = 'data-kit-group-toggle';
108
+
109
+ /** 可折叠分组成员行的属性串(拼进 `<tr …>`):标所属分组,折叠态加 hidden */
110
+ export function kitTableNativeGroupMemberAttrs(groupId: string, collapsed = false): string {
111
+ return `${KIT_TABLE_NATIVE_GROUP_OF_ATTR}="${escapeHtml(groupId)}"${collapsed ? ' hidden' : ''}`;
112
+ }
113
+
114
+ /**
115
+ * 接上可折叠分组的点击(事件委托,挂一次;重画 innerHTML 后无需重接):点折叠按钮或分组标题行的空白处切换,
116
+ * 点标题行里的链接 / 按钮 / 输入不触发。切换只改 DOM 最小状态(aria-expanded、成员行 hidden),再调 onToggle 让调用方的展示对象记住折叠态。
117
+ * 返回解绑函数。
118
+ */
119
+ export function bindKitTableNativeGroups(root: Element, onToggle?: (groupId: string, collapsed: boolean) => void): () => void {
120
+ const handler = (ev: Event): void => {
121
+ const target = ev.target;
122
+ if (!(target instanceof Element)) return;
123
+ const row = target.closest(`[${KIT_TABLE_NATIVE_GROUP_ATTR}]`);
124
+ if (row === null || !root.contains(row)) return;
125
+ const toggle = row.querySelector(`[${KIT_TABLE_NATIVE_GROUP_TOGGLE_ATTR}]`);
126
+ const inner = target.closest('a, button, input, select, textarea, [role="button"]');
127
+ if (inner !== null && inner !== toggle && row.contains(inner)) return;
128
+ const groupId = row.getAttribute(KIT_TABLE_NATIVE_GROUP_ATTR) ?? '';
129
+ const collapsed = toggle?.getAttribute('aria-expanded') !== 'false';
130
+ toggle?.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
131
+ for (const member of Array.from(root.querySelectorAll(`[${KIT_TABLE_NATIVE_GROUP_OF_ATTR}]`))) {
132
+ if (member.getAttribute(KIT_TABLE_NATIVE_GROUP_OF_ATTR) === groupId) member.toggleAttribute('hidden', collapsed);
133
+ }
134
+ onToggle?.(groupId, collapsed);
135
+ };
136
+ root.addEventListener('click', handler);
137
+ return () => root.removeEventListener('click', handler);
138
+ }
139
+
140
+ export type KitTableNativeSpanKind = 'group' | 'detail' | 'summary';
141
+
142
+ export interface KitTableNativeSpanRowOptions {
143
+ kind: KitTableNativeSpanKind;
144
+ /** 跨列数(= 表格总列数,≥ 1) */
145
+ colSpan: number;
146
+ /** 内容 HTML(调用方已转义 / 已是组件宿主);group 的纯文本标题请先 escapeHtml 或用 label */
147
+ content?: string;
148
+ /** group 专用:纯文本标题(出口负责转义,与 content 二选一,label 优先) */
149
+ label?: string;
150
+ /** group:th 的 scope,缺省 colgroup(分组含多列语义用 colgroup,纵向行分组用 rowgroup) */
151
+ scope?: 'colgroup' | 'rowgroup';
152
+ /** detail:详情行元素 id,父行 `aria-controls` 指向它 */
153
+ id?: string;
154
+ /** detail:隐藏(父行折叠时),写 hidden 属性 */
155
+ hidden?: boolean;
156
+ /** 行上追加的 data 属性(如 data-soma-id),键值都会转义 */
157
+ attrs?: Readonly<Record<string, string>>;
158
+ /** 是否加吸顶内层包裹(缺省 true;表格不横向滚动、或行内容自己处理时可关) */
159
+ sticky?: boolean;
160
+ /**
161
+ * group 专用:分组可折叠。标题前出一个展开 / 折叠按钮(`aria-expanded`,键盘可达),点它(或点标题行空白处)折叠 / 展开该分组下的成员行;
162
+ * 成员行用 `kitTableNativeGroupMemberAttrs(groupId, collapsed)` 打标记,页面挂载后调一次 `bindKitTableNativeGroups(table)` 接上点击。
163
+ * 折叠态由调用方的展示对象持有(每次重画把 collapsed 传回来),出口只在 DOM 上保留最小状态(aria-expanded + 成员行 hidden),并经 onToggle 通知调用方。
164
+ */
165
+ collapsible?: { groupId: string; collapsed?: boolean; /** 按钮的读屏名(缺省取 label) */ toggleLabel?: string };
166
+ }
167
+
168
+ export function kitTableNativeSpanRowRecipe(kind: KitTableNativeSpanKind): { row: string; cell: string } {
169
+ if (kind === 'group') return { row: KIT_TABLE_NATIVE_SPAN_CLASS.groupRow, cell: KIT_TABLE_NATIVE_SPAN_CLASS.groupCell };
170
+ if (kind === 'detail') return { row: KIT_TABLE_NATIVE_SPAN_CLASS.detailRow, cell: KIT_TABLE_NATIVE_SPAN_CLASS.detailCell };
171
+ return {
172
+ row: KIT_TABLE_NATIVE_SPAN_CLASS.summaryRow,
173
+ cell: `${kitTableNativeCellRecipe({})} ${KIT_TABLE_NATIVE_SPAN_CLASS.summaryCell}`,
174
+ };
175
+ }
176
+
177
+ /**
178
+ * 汇总行的逐列单元格类(汇总需要按列对齐时,用逐列 `<td>` 而不是单个跨列格;行类用 `kitTableNativeSpanRowRecipe('summary').row`):
179
+ * 与数据格同配方 + 字重 600;数值列缺省右对齐等宽数字,与数据列同一对齐。
180
+ */
181
+ export function kitTableNativeSummaryCellRecipe(options: Omit<KitTableNativeCellRecipeOptionsLike, 'head'> = {}): string {
182
+ return `${kitTableNativeCellRecipe({ align: options.align, numeric: options.numeric })} ${KIT_TABLE_NATIVE_SPAN_CLASS.summaryCell}`;
183
+ }
184
+
185
+ interface KitTableNativeCellRecipeOptionsLike {
186
+ head?: boolean;
187
+ align?: KitTableAlign;
188
+ numeric?: boolean;
189
+ }
190
+
191
+ /**
192
+ * 父行与详情行的 ARIA 关联属性串(调用方接到父行的触发元素上):
193
+ * `aria-controls` 指向详情行 id,`aria-expanded` 反映展开态。详情行本身用 kitTableNativeSpanRowHtml({ kind: 'detail', id })。
194
+ */
195
+ export function kitTableNativeDisclosureAttrs(o: { controls: string; expanded: boolean }): string {
196
+ return `aria-controls="${escapeHtml(o.controls)}" aria-expanded="${o.expanded ? 'true' : 'false'}"`;
197
+ }
198
+
199
+ /**
200
+ * 跨列复合行 HTML(一行一格):
201
+ * - group:`<tr><th scope="colgroup|rowgroup" colspan>`,分组标题行;
202
+ * - detail:`<tr [id] [hidden]><td colspan>`,展开详情行(无悬停;与父行的 aria-controls / aria-expanded 由调用方用 kitTableNativeDisclosureAttrs 接);
203
+ * - summary:`<tr><td colspan>`,汇总行(需逐列对齐的汇总不用它,改用 kitTableNativeSummaryCellRecipe 写逐列格)。
204
+ * 内容默认包在 `sticky start-0` 内层里,横向滚动时不跑出可视区。
205
+ */
206
+ export function kitTableNativeSpanRowHtml(o: KitTableNativeSpanRowOptions): string {
207
+ const span = Number.isFinite(o.colSpan) && o.colSpan >= 1 ? Math.floor(o.colSpan) : 1;
208
+ const recipe = kitTableNativeSpanRowRecipe(o.kind);
209
+ const body = o.label !== undefined ? escapeHtml(o.label) : (o.content ?? '');
210
+ const inner = o.sticky === false ? body : `<div class="${KIT_TABLE_NATIVE_SPAN_CLASS.stickyInner}">${body}</div>`;
211
+ const extra = Object.entries(o.attrs ?? {})
212
+ .map(([k, v]) => ` ${escapeHtml(k)}="${escapeHtml(v)}"`)
213
+ .join('');
214
+ const rowCls = recipe.row === '' ? '' : ` class="${recipe.row}"`;
215
+ const idAttr = o.kind === 'detail' && o.id !== undefined && o.id !== '' ? ` id="${escapeHtml(o.id)}"` : '';
216
+ const hiddenAttr = o.kind === 'detail' && o.hidden === true ? ' hidden' : '';
217
+ // data-kit-span:跨列行标记,主题结构规则据它给例外(分组行的 th 不当表头;详情行存在时父行不画底线,与详情行相连)
218
+ const rowAttrs = `${idAttr}${hiddenAttr} ${KIT_TABLE_NATIVE_SPAN_ATTR}="${o.kind}"${extra}${rowCls}`;
219
+ if (o.kind === 'group') {
220
+ const scope = o.scope ?? 'colgroup';
221
+ const col = o.collapsible;
222
+ if (col !== undefined && col.groupId !== '') {
223
+ const collapsed = col.collapsed === true;
224
+ const name = col.toggleLabel ?? o.label ?? '';
225
+ const btn = `<button type="button" ${KIT_TABLE_NATIVE_GROUP_TOGGLE_ATTR} aria-expanded="${collapsed ? 'false' : 'true'}"${name !== '' ? ` aria-label="${escapeHtml(name)}"` : ''} class="${KIT_TABLE_NATIVE_SPAN_CLASS.groupToggle}">${kitIconHtml('chevron-down', 'xs', KIT_TABLE_NATIVE_SPAN_CLASS.groupChevron)}</button>`;
226
+ const head = `<div class="${KIT_TABLE_NATIVE_SPAN_CLASS.groupHead}">${btn}${body}</div>`;
227
+ const stickyHead = o.sticky === false ? head : `<div class="${KIT_TABLE_NATIVE_SPAN_CLASS.stickyInner}">${head}</div>`;
228
+ return `<tr${rowAttrs} ${KIT_TABLE_NATIVE_GROUP_ATTR}="${escapeHtml(col.groupId)}"><th scope="${scope}" colspan="${span}" class="${recipe.cell}">${stickyHead}</th></tr>`;
229
+ }
230
+ return `<tr${rowAttrs}><th scope="${scope}" colspan="${span}" class="${recipe.cell}">${inner}</th></tr>`;
231
+ }
232
+ return `<tr${rowAttrs}><td colspan="${span}" class="${recipe.cell}">${inner}</td></tr>`;
233
+ }
234
+
235
+ export const KIT_TABLE_NATIVE_EDIT_SPAN_CLASS_CANDIDATES: readonly string[] = classCandidates(
236
+ Object.values(KIT_TABLE_NATIVE_EDIT_CLASS),
237
+ Object.values(KIT_TABLE_NATIVE_SPAN_CLASS),
238
+ Object.values(CONTROL_INSET),
239
+ KIT_TABLE_NATIVE_CLASS.cellNumeric,
240
+ 'text-start text-end text-center',
241
+ kitTableNativeCellRecipe({}),
242
+ );
@@ -1,7 +1,12 @@
1
1
  // 表格行与单元格配方(table-row.ts):
2
2
  // 提供表格相关 data-kit-part 常量与单元格配方,数值列默认右对齐等宽数字(text-right tabular-nums)。
3
3
 
4
+ import { KIT_ARRANGE, textWidthEm } from 'soma-foundation/arrange';
5
+ import { arrangeColumns } from 'soma-foundation/arrange/table';
6
+ import { KIT_LAYOUT_SMELLS } from 'soma-foundation/kit-layout';
4
7
  import { classCandidates } from '../base/class-candidates';
8
+ import { mergeClass } from '../object-renderer/merge-class';
9
+ import { kitTypographyRecipe } from './typography';
5
10
 
6
11
  export const KIT_PART_TABLE = 'table' as const;
7
12
  export const KIT_PART_TABLE_ROW = 'table-row' as const;
@@ -36,9 +41,10 @@ export function kitTableCellRecipe(options: KitTableCellRecipeOptions = {}): str
36
41
  const align: KitTableAlign = options.align ?? (numeric ? 'right' : 'left');
37
42
  const isHeader = Boolean(options.header);
38
43
 
44
+ // 表头 / 单元格字阶取排版引擎的角色(tableHead / text),全仓单一来源
39
45
  const base = isHeader
40
- ? 'px-3 py-0.5 align-middle text-xs font-semibold text-fg-muted whitespace-nowrap'
41
- : 'px-3 py-0.5 align-middle text-sm text-fg';
46
+ ? mergeClass(mergeClass('px-3 py-0.5 align-middle', kitTypographyRecipe('tableHead')), 'whitespace-nowrap')
47
+ : mergeClass('px-3 py-0.5 align-middle', kitTypographyRecipe('text'));
42
48
  const alignCls = ALIGN_CLASS[align] ?? ALIGN_CLASS.left;
43
49
  const numericCls = numeric || align === 'right' ? 'tabular-nums' : '';
44
50
 
@@ -53,11 +59,11 @@ export function kitTableCellRecipe(options: KitTableCellRecipeOptions = {}): str
53
59
  */
54
60
  export const KIT_TABLE_NATIVE_CLASS = Object.freeze({
55
61
  shell: 'overflow-x-auto',
56
- table: 'w-full text-sm text-fg',
62
+ table: mergeClass('w-full', kitTypographyRecipe('text')),
57
63
  headRow: '',
58
- headCell: 'whitespace-nowrap px-2 py-0.5 first:ps-0 last:pe-0 text-xs font-semibold text-fg-muted',
64
+ headCell: mergeClass('whitespace-nowrap px-2 py-0.5 first:ps-0 last:pe-0', kitTypographyRecipe('tableHead')),
59
65
  row: 'border-b border-border-divider last:border-b-0 transition-colors hover:bg-state-layer-row-hover',
60
- cell: 'px-2 py-0.5 first:ps-0 last:pe-0 align-middle text-sm text-fg',
66
+ cell: mergeClass('px-2 py-0.5 first:ps-0 last:pe-0 align-middle', kitTypographyRecipe('text')),
61
67
  cellNumeric: 'tabular-nums',
62
68
  });
63
69
 
@@ -76,13 +82,113 @@ export function kitTableNativeCellRecipe(options: KitTableNativeCellRecipeOption
76
82
  return [base, alignCls, numeric ? KIT_TABLE_NATIVE_CLASS.cellNumeric : ''].filter(Boolean).join(' ');
77
83
  }
78
84
 
85
+ /** 原生数据格左右内边距的间距刻度(与 `KIT_TABLE_NATIVE_CLASS.cell` 的 `px-2` 同值) */
86
+ const NATIVE_CELL_PAD_STEP = 2;
87
+ /** 末尾留白列(无内容):宽 100% 吃掉自动布局的全部余量,不带内边距 */
88
+ const NATIVE_SPACER_CLASS = 'w-full p-0';
89
+
90
+ /** 原生表格取列轨的一列事实(字段类型决定内容类,表头文案 / 枚举最长文案 / 长度上限修正理想宽) */
91
+ export interface KitTableNativeTrackColumn {
92
+ key: string;
93
+ /** 字段类型(text / id / enum / int / money / date …,同 kit 字段类型;缺省按文本) */
94
+ type?: string;
95
+ label: string;
96
+ /** 枚举 / 标签列的选项文案(取最长的修正理想宽) */
97
+ options?: readonly string[];
98
+ /** 声明的长度上限(字符) */
99
+ maxLen?: number;
100
+ /** 主列(吸收余量);缺省按引擎规则(第一个文本类列,没有则理想宽最大的列) */
101
+ main?: boolean;
102
+ }
103
+
104
+ export interface KitTableNativeTrack {
105
+ /** 每列的列轨类(与 columns 一一对应):表头格与数据格都加它。定宽列 `w-<理想> min-w-<最小>`,封顶的主列 `w-<封顶> min-w-<最小>`(余量进留白列),不封顶的主列(含长文本列)只 `min-w-<最小>`(`<table>` 的自动布局让它吸收余量);数值列后有额外间距时加 `pe-N` */
106
+ cellClass: readonly string[];
107
+ /** 每列 [最小, 理想, 最大](rem)与是否主列 */
108
+ columns: ReadonlyArray<{ key: string; min: number; ideal: number; max: number; grow: boolean; capRem: number | null; gapAfterRem: number }>;
109
+ /** `<table>` 的最小宽类(各列最小宽之和;容器放不下由 `KIT_TABLE_NATIVE_CLASS.shell` 横向滚动,标识列不被截成几个字符) */
110
+ tableMinClass: string;
111
+ /** 末尾留白列的类(排布引擎 spacer:主列封顶后余量落在最后一个数据列之后,表整体仍铺满);含长文本列的表为 ''(不需要留白列) */
112
+ spacerCellClass: string;
113
+ /** 本次用到的候选类(经 `declareKitUses(..., candidates)` 一并声明,否则按页裁剪样式时会被剔除) */
114
+ candidates: readonly string[];
115
+ }
116
+
117
+ /** 单元格值 → 内容样本文本(字符串 / 数字 / 带 text 的对象;其余不计) */
118
+ function cellSampleText(v: unknown): string {
119
+ if (typeof v === 'string') return v;
120
+ if (typeof v === 'number' || typeof v === 'bigint') return String(v);
121
+ if (v !== null && typeof v === 'object' && typeof (v as { text?: unknown }).text === 'string') return (v as { text: string }).text;
122
+ return '';
123
+ }
124
+
125
+ /**
126
+ * 原生表格取列轨:应用自画 `<table>` 时用它得到与 kit 自己的表格同一份列轨(排布引擎 `arrangeColumns`:
127
+ * 内容类 × 枚举文案 × 长度上限 × 表头文案 → [最小, 理想, 最大]),不在应用里估列宽。只产间距刻度类,不用方括号任意值。
128
+ * 第二参 `rows`(可选):应用只传行数据,出口从中取各列最长内容的字宽 / 字符数作内容样本——日期 / 状态类列的最小宽不低于最长内容(日期区间 `10-01 ~ 10-05` 不折行),
129
+ * 文本类列给引擎内容样本 contentEm(最长一格字宽,CJK 按 1em):最小宽与理想宽都不低于样本(至多到该类最大宽),主列不为省宽折行;样本不改列类型。
130
+ * 本出口与 kit 自己的列表表格同一个引擎(`arrangeColumns`)。被包含的次级小表(强调级 secondary 及以下的面板里的原生表)由结构 CSS 取内容宽、左对齐、表头带只与表同宽,不通栏。
131
+ */
132
+ export function kitTableNativeTrack(columns: readonly KitTableNativeTrackColumn[], rows?: readonly Record<string, unknown>[]): KitTableNativeTrack {
133
+ const font = KIT_LAYOUT_SMELLS.reference.bodyFontRem;
134
+ const idName = new RegExp(KIT_ARRANGE.columns.idNamePattern);
135
+ const step = KIT_ARRANGE.columns.track.stepRem;
136
+ const toStep = (rem: number): number => Math.ceil(Math.round((rem / step) * 1000) / 1000);
137
+ const solved = arrangeColumns({
138
+ fontRem: font,
139
+ columns: columns.map((c) => {
140
+ const textual = c.type === undefined || c.type === 'text';
141
+ // 内容样本:由出口从传入的行数据里取各列最长内容(字符数与字宽),应用只传行数据和列类型,不自己算列宽
142
+ const samples = (rows ?? []).map((r) => cellSampleText(r[c.key])).filter((t) => t !== '');
143
+ const sampleEm = samples.reduce((m, s) => Math.max(m, textWidthEm(s)), 0);
144
+ const optionEm = Math.max((c.options ?? []).reduce((m, o) => Math.max(m, textWidthEm(o)), 0), sampleEm);
145
+ const kind = KIT_ARRANGE.columns.typeClass as Readonly<Record<string, string>>;
146
+ const contentColumn = kind[c.type ?? 'text'] === 'status' || kind[c.type ?? 'text'] === 'date';
147
+ return {
148
+ key: c.key,
149
+ type: textual && idName.test(c.key) ? 'id' : (c.type ?? 'text'),
150
+ labelEm: textWidthEm(c.label),
151
+ ...(optionEm > 0 && (contentColumn || (c.options ?? []).length > 0) ? { optionEm } : {}),
152
+ // 文本类列的内容样本:最长一格的字宽(CJK 按 1em)——引擎据此把最小宽 / 理想宽取到样本(至多到该类最大宽),不为省宽折行
153
+ ...(!contentColumn && sampleEm > 0 ? { contentEm: sampleEm } : {}),
154
+ ...(c.maxLen !== undefined ? { maxLen: c.maxLen } : {}),
155
+ ...(c.main === true ? { main: true } : {}),
156
+ };
157
+ }),
158
+ });
159
+ let minUnits = 0;
160
+ // 引擎给的 [最小, 理想, 最大] 是内容宽;单元格 border-box 还要装下左右内边距(px-2),不加就会在刚好放下处折行(「本期新增接手」折成两行)
161
+ const PAD_UNITS = 2 * NATIVE_CELL_PAD_STEP;
162
+ const cellClass = solved.columns.map((c) => {
163
+ const min = toStep(c.min) + PAD_UNITS;
164
+ const gap = c.gapAfterRem > 0 ? toStep(c.gapAfterRem) : 0;
165
+ minUnits += min + gap;
166
+ // 数值列与其右侧左对齐文本列之间的额外间距:单元格右内边距 = 常规内边距 + 额外间距(原生单元格不吃外边距)
167
+ const pad = gap > 0 ? ` pe-${gap + NATIVE_CELL_PAD_STEP}` : '';
168
+ // 主列封顶(capRem):`<table>` 自动布局不认 max-w,封顶写成定宽(余量由留白列接走);没有封顶(含长文本列)的主列只 min-w、吸收余量
169
+ if (c.grow) return c.capRem === null ? `min-w-${min}${pad}` : `w-${Math.max(min, toStep(c.capRem) + PAD_UNITS)} min-w-${min}${pad}`;
170
+ return `w-${Math.max(min, toStep(c.ideal) + PAD_UNITS)} min-w-${min}${pad}`;
171
+ });
172
+ const tableMinClass = `min-w-${minUnits}`;
173
+ // 末尾留白列(引擎 spacer):在最后一个数据列之后追加一个 `<th aria-hidden>` / `<td aria-hidden>`(类 spacerCellClass,宽 100% 吃掉全部余量,不放内容);
174
+ // 表头底线与行分隔线穿过它,表整体仍 `width: 100%`;有操作列的应用把操作列放在留白列之后(贴尾侧)
175
+ const spacerCellClass = solved.spacer ? NATIVE_SPACER_CLASS : '';
176
+ return {
177
+ cellClass,
178
+ columns: solved.columns.map((c) => ({ key: c.key, min: c.min, ideal: c.ideal, max: c.max, grow: c.grow, capRem: c.capRem, gapAfterRem: c.gapAfterRem })),
179
+ tableMinClass,
180
+ spacerCellClass,
181
+ candidates: classCandidates(cellClass, tableMinClass, spacerCellClass),
182
+ };
183
+ }
184
+
79
185
  export const KIT_TABLE_NATIVE_CLASS_CANDIDATES: readonly string[] = classCandidates(
80
186
  Object.values(KIT_TABLE_NATIVE_CLASS),
81
187
  'text-start text-end text-center',
82
188
  );
83
189
 
84
190
  export const KIT_TABLE_RECIPE_CLASS_CANDIDATES: readonly string[] = classCandidates(
85
- 'px-3 py-0.5 align-middle text-xs font-semibold text-fg-muted whitespace-nowrap text-sm tabular-nums',
191
+ kitTableCellRecipe({ header: true, numeric: true }),
86
192
  Object.values(ALIGN_CLASS),
87
193
  KIT_TABLE_NATIVE_CLASS_CANDIDATES,
88
194
  );
@@ -0,0 +1,49 @@
1
+ // 页签配方:全仓唯一的页签呈现(页内页签条 tabs-frame、分组页签 groupsAs: tabs、外壳页签条 workspace-frame 都用它,不再各写一套类串)。
2
+ //
3
+ // 下划线式:选中项 = 前景色 + 字重 600 + 主色 2px 下划线;未选中 = 次级色;悬停 = 状态层(选中项悬停不变色);键盘焦点 = 内缩焦点环。
4
+ // 页签高度取 design 真源 kit-limits#workspaceFrame.chrome.tabbarStep,可关闭页签的关闭钮占位取 chrome.tabCloseSlotStep(文字左内边距 = 占位宽,
5
+ // 文字在下划线内左右对称:关闭钮隐藏时占位仍在,不随悬停位移)。
6
+ //
7
+ // 两种承载形态同一套文字配方:
8
+ // · tab:下划线画在页签按钮自己身上(页内页签 / 分组页签,页签不含关闭钮);
9
+ // · row + label:下划线画在行容器上,按钮只管文字(外壳页签条:行里还有关闭钮 / 固定钮,下划线要罩住整行)。
10
+
11
+ import { KIT_WORKSPACE_FRAME_LIMITS } from 'soma-foundation/kit-limits';
12
+ import { classCandidates } from '../base/class-candidates';
13
+
14
+ const CHROME = KIT_WORKSPACE_FRAME_LIMITS.chrome;
15
+
16
+ /** 页签文字配方(色 / 字重 / 悬停状态层 / 焦点环):两种形态共用 */
17
+ const TEXT = 'cursor-pointer items-center text-sm font-medium text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg aria-selected:font-semibold aria-selected:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring';
18
+ const BOX = `inline-flex h-${CHROME.tabbarStep} rounded-t-md`;
19
+
20
+ export interface KitTabRecipe {
21
+ /** 页签条(tablist):底部一条细线,页签的下划线压在其上 */
22
+ readonly bar: string;
23
+ /** 页签按钮,下划线画在自己身上 */
24
+ readonly tab: string;
25
+ /** 页签按钮,仅文字(下划线在 row 上);可关闭时左内边距 = 关闭钮占位 */
26
+ readonly label: string;
27
+ readonly labelClosable: string;
28
+ /** 行容器(下划线载体):未选中 / 选中 */
29
+ readonly row: string;
30
+ readonly rowActive: string;
31
+ /** 可关闭页签的关闭钮占位宽类(w-N) */
32
+ readonly closeSlot: string;
33
+ }
34
+
35
+ export function kitTabRecipe(): KitTabRecipe {
36
+ return {
37
+ bar: 'flex flex-wrap gap-1 border-b border-border-subtle',
38
+ tab: `${BOX} -mb-px border-b-2 border-transparent px-4 ${TEXT} aria-selected:border-primary`,
39
+ label: `${BOX} px-4 ${TEXT}`,
40
+ labelClosable: `${BOX} ps-${CHROME.tabCloseSlotStep} pe-0 ${TEXT}`,
41
+ row: 'group/tab inline-flex shrink-0 items-center border-b-2 border-transparent transition-colors',
42
+ rowActive: 'group/tab relative inline-flex shrink-0 items-center border-b-2 border-primary',
43
+ closeSlot: `w-${CHROME.tabCloseSlotStep}`,
44
+ };
45
+ }
46
+
47
+ export const KIT_TAB_RECIPE_CLASS_CANDIDATES: readonly string[] = classCandidates(
48
+ Object.values(kitTabRecipe()),
49
+ );
@@ -4,10 +4,10 @@
4
4
 
5
5
  import { KIT_CLASS_DEFAULTS } from '../object-renderer/defaults';
6
6
  import { escapeHtml } from '../shared/escape';
7
- import { KIT_PART_TITLE_SECTION } from './typography';
7
+ import { KIT_PART_TITLE_SECTION, kitTypographyRecipe } from './typography';
8
8
 
9
- /** 面板标题文字类(分区标题档:真源 fontScale.roleTokens.titleSectionPx 16 / 600 / 正文色,轻微负字距只对拉丁与数字,汉字归零由结构 CSS 的 :lang 规则担保) */
10
- export const KIT_PANEL_TITLE_CLASS = 'text-title-section font-title tracking-heading text-fg';
9
+ /** 面板标题文字类(分区标题档:真源 fontScale.roleTokens.titleSectionPx 16 / 600 / 正文色,轻微负字距只对拉丁与数字,汉字归零由结构 CSS 的 :lang 规则担保;取排版引擎的 sectionTitle 角色) */
10
+ export const KIT_PANEL_TITLE_CLASS = kitTypographyRecipe('sectionTitle');
11
11
 
12
12
  export interface KitPanelTitleRowOptions {
13
13
  title: string;
@@ -1,11 +1,15 @@
1
- // 文字角色配方(typography.ts):吸收 KIT_TYPOGRAPHY 并对齐九维字阶与字重令牌:
1
+ // 文字角色配方(typography.ts):排版与字阶引擎(E3)的 kit 出口。
2
+ //
3
+ // 角色 → 字号档 / 字重 / 字距 / 墨色 / 数字等宽的取值表在 soma-design/spec/pipeline/kit-type.json(字号像素在九维真源 fontScale),
4
+ // 求解在 soma-foundation/kit-type;本文件只把角色投影成类串,不写任何 text-* / font-* / tracking-* 字面。
5
+ // 页面标题、区块标题、浮层标题、表头、指标数字、正文、辅助等字阶一律经 kitTypographyRecipe(role) 取类串,
6
+ // 不再在组件里手写 `text-base font-semibold text-fg` 这类组合(原约 20 个文件手写,数值与令牌两套已迁入)。
2
7
  // - 页面标题(pageTitle):text-title-page / font-title / tracking-tight
3
- // - 弹窗标题(dialogTitle):text-title-dialog / font-title / tracking-heading
4
- // - 区块标题(sectionTitle):text-title-section / font-title / tracking-heading
8
+ // - 弹窗标题(dialogTitle)、区块标题(sectionTitle):text-title-dialog | text-title-section / font-title / tracking-heading
5
9
  // - 指标大数字(statValue):text-stat-value / font-title / tracking-tight / tabular-nums
6
- // - 正文(body):text-sm
7
- // - 辅助说明(caption):text-xs
10
+ // - 表头(tableHead):全仓单一来源(sm / 600 / 弱化色,D6)
8
11
 
12
+ import { KIT_TYPE, typePartOf, typeRoleRecipe } from 'soma-foundation/kit-type';
9
13
  import { classCandidates } from '../base/class-candidates';
10
14
 
11
15
  export const KIT_PART_TITLE_PAGE = 'title-page' as const;
@@ -19,53 +23,30 @@ export type KitTypographyPart =
19
23
  | typeof KIT_PART_TITLE_DIALOG
20
24
  | typeof KIT_PART_STAT_VALUE;
21
25
 
22
- export type KitTypographyRecipeRole =
23
- | 'pageTitle'
24
- | 'dialogTitle'
25
- | 'sectionTitle'
26
- | 'statValue'
27
- | 'body'
28
- | 'bodyStrong'
29
- | 'caption'
30
- | 'muted'
31
- | 'code'
32
- | 'label';
26
+ /** 字阶角色(闭集 = 真源 kit-type.json 的 roles 键)。 */
27
+ export type KitTypographyRecipeRole = keyof typeof KIT_TYPE.roles;
33
28
 
34
- export const KIT_TYPOGRAPHY_RECIPE_MAP: Readonly<Record<KitTypographyRecipeRole, string>> = Object.freeze({
35
- pageTitle: 'text-title-page font-title tracking-tight text-fg',
36
- dialogTitle: 'text-title-dialog font-title tracking-heading text-fg',
37
- sectionTitle: 'text-title-section font-title tracking-heading text-fg',
38
- statValue: 'text-stat-value font-title tracking-tight text-fg tabular-nums',
39
- body: 'text-sm font-normal text-fg',
40
- bodyStrong: 'text-sm font-semibold text-fg',
41
- caption: 'text-xs font-normal text-fg-subtle',
42
- muted: 'text-sm font-normal text-fg-muted',
43
- code: 'font-mono text-xs text-fg bg-surface-sunken px-1.5 py-0.5 rounded-sm',
44
- label: 'text-xs font-normal text-fg',
45
- });
29
+ const ROLE_IDS = Object.keys(KIT_TYPE.roles) as KitTypographyRecipeRole[];
46
30
 
47
- const ROLE_TO_PART: Readonly<Partial<Record<KitTypographyRecipeRole, KitTypographyPart>>> = Object.freeze({
48
- pageTitle: KIT_PART_TITLE_PAGE,
49
- sectionTitle: KIT_PART_TITLE_SECTION,
50
- dialogTitle: KIT_PART_TITLE_DIALOG,
51
- statValue: KIT_PART_STAT_VALUE,
52
- });
31
+ /** 字阶角色 → 类串(全部角色;类串取自 kit-type 引擎)。 */
32
+ export const KIT_TYPOGRAPHY_RECIPE_MAP: Readonly<Record<KitTypographyRecipeRole, string>> = Object.freeze(
33
+ Object.fromEntries(ROLE_IDS.map((r) => [r, typeRoleRecipe(r)])) as Record<KitTypographyRecipeRole, string>,
34
+ );
53
35
 
54
36
  /**
55
37
  * 根据文字角色获取对应的 data-kit-part 标识(仅标题与指标大数字携带专属 part,普通正文返回 undefined)。
56
38
  */
57
39
  export function kitTypographyPartOf(role: KitTypographyRecipeRole): KitTypographyPart | undefined {
58
- return ROLE_TO_PART[role];
40
+ return (typePartOf(role) ?? undefined) as KitTypographyPart | undefined;
59
41
  }
60
42
 
61
43
  /**
62
- * 文字角色配方纯函数:按规则卡角色返回标准 Tailwind 字号、字重、字距与文本色类串。
44
+ * 文字角色配方纯函数:按角色返回标准 Tailwind 字号、字重、字距与文本色类串(唯一出口)。
63
45
  */
64
46
  export function kitTypographyRecipe(role: KitTypographyRecipeRole = 'body'): string {
65
47
  return KIT_TYPOGRAPHY_RECIPE_MAP[role] ?? KIT_TYPOGRAPHY_RECIPE_MAP.body;
66
48
  }
67
49
 
68
-
69
50
  export type KitFieldEmphasis = 'strong' | 'muted';
70
51
 
71
52
  /**
@@ -81,15 +62,15 @@ export const KIT_FIELD_EMPHASIS_CLASSES: Readonly<Record<KitFieldEmphasis, strin
81
62
  muted: kitFieldEmphasisRecipe('muted'),
82
63
  });
83
64
 
84
- /** 涨跌标(KitDelta)三档尺寸的数字文字:中等字重 + 等宽数字;颜色由调用方按涨跌语气另给 */
65
+ /** 涨跌标(KitDelta)三档尺寸的数字文字:中等字重 + 等宽数字(字阶取自引擎角色 deltaSm / deltaMd / deltaLg);颜色由调用方按涨跌语气另给 */
85
66
  export const KIT_DELTA_TEXT: Readonly<Record<'sm' | 'md' | 'lg', string>> = Object.freeze({
86
- sm: 'inline-flex items-center gap-0.5 text-xs font-medium tabular-nums',
87
- md: 'inline-flex items-center gap-0.5 text-sm font-medium tabular-nums',
88
- lg: 'inline-flex items-center gap-1 text-base font-medium tabular-nums',
67
+ sm: `inline-flex items-center gap-0.5 ${typeRoleRecipe('deltaSm')}`,
68
+ md: `inline-flex items-center gap-0.5 ${typeRoleRecipe('deltaMd')}`,
69
+ lg: `inline-flex items-center gap-1 ${typeRoleRecipe('deltaLg')}`,
89
70
  });
90
71
 
91
72
  /** 就地错误提示行(字段下方的校验报错):小号字 + 危险语气的 on-soft 文字色 */
92
- export const KIT_ERROR_TEXT = 'm-0 text-xs font-normal text-danger-on-soft';
73
+ export const KIT_ERROR_TEXT = `m-0 ${typeRoleRecipe('errorText')}`;
93
74
 
94
75
  export const KIT_TYPOGRAPHY_RECIPE_CLASS_CANDIDATES: readonly string[] = classCandidates(
95
76
  KIT_ERROR_TEXT,