soma-kit 0.1.12 → 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 (300) hide show
  1. package/README.md +5 -4
  2. package/bin/soma-kit.mjs +31 -1
  3. package/bin/soma.mjs +0 -0
  4. package/package.json +5 -4
  5. package/spec/generated/kit-app.schema.json +172 -4
  6. package/spec/generated/kit-page.schema.json +164 -5
  7. package/spec/kit-grammar.json +598 -96
  8. package/spec/kit-grammar.schema.json +12 -6
  9. package/src/app/app-config.ts +92 -8
  10. package/src/app/component-gate.ts +271 -13
  11. package/src/app/define-kit-app.ts +2 -2
  12. package/src/app/define-kit-view.ts +9 -5
  13. package/src/app/dev-diagnostic.ts +5 -0
  14. package/src/app/index.ts +29 -5
  15. package/src/app/kit-view-context.ts +181 -15
  16. package/src/app/render-ports.ts +18 -0
  17. package/src/app/server-pages.ts +8 -2
  18. package/src/app/server.ts +55 -8
  19. package/src/app/theme-runtime.ts +4 -0
  20. package/src/base/action-busy.ts +101 -4
  21. package/src/base/action-slots.ts +13 -2
  22. package/src/base/anchored-layer.ts +50 -0
  23. package/src/base/button.ts +62 -15
  24. package/src/base/check-core.ts +8 -0
  25. package/src/base/checkbox.ts +2 -1
  26. package/src/base/choice.ts +21 -2
  27. package/src/base/color-picker.ts +10 -5
  28. package/src/base/command-palette.ts +1 -1
  29. package/src/base/context-menu.ts +10 -7
  30. package/src/base/date-range.ts +7 -7
  31. package/src/base/date.ts +55 -16
  32. package/src/base/delta.ts +72 -0
  33. package/src/base/end-edge.ts +61 -0
  34. package/src/base/fab.ts +1 -1
  35. package/src/base/gap-value.ts +168 -0
  36. package/src/base/hint-tips.ts +170 -0
  37. package/src/base/icons.ts +8 -0
  38. package/src/base/illustrations.ts +95 -0
  39. package/src/base/index.ts +32 -9
  40. package/src/base/listbox-core.ts +6 -5
  41. package/src/base/loading-gate.ts +140 -87
  42. package/src/base/mentions.ts +2 -1
  43. package/src/base/menu-button.ts +16 -18
  44. package/src/base/menu-core.ts +37 -8
  45. package/src/base/motion/hover-3d.ts +1 -1
  46. package/src/base/motion/marquee.ts +1 -1
  47. package/src/base/otp.ts +5 -4
  48. package/src/base/overlay-runtime.ts +235 -0
  49. package/src/base/popover.ts +10 -9
  50. package/src/base/popup.ts +67 -8
  51. package/src/base/portal-core.ts +4 -0
  52. package/src/base/qty-stepper.ts +5 -5
  53. package/src/base/radio.ts +2 -1
  54. package/src/base/range.ts +19 -2
  55. package/src/base/rating.ts +11 -6
  56. package/src/base/reason-tip.ts +150 -0
  57. package/src/base/segmented.ts +36 -24
  58. package/src/base/shared.ts +180 -36
  59. package/src/base/state-panel.ts +367 -0
  60. package/src/base/status-tone.ts +27 -0
  61. package/src/base/sticky-edge.ts +116 -0
  62. package/src/base/swap.ts +6 -6
  63. package/src/base/switch.ts +10 -5
  64. package/src/base/tag-input.ts +6 -6
  65. package/src/base/tag.ts +76 -41
  66. package/src/base/text.ts +43 -14
  67. package/src/base/time-picker.ts +7 -5
  68. package/src/base/tree-select.ts +6 -4
  69. package/src/base/trend-tone.ts +9 -0
  70. package/src/base/upload.ts +15 -9
  71. package/src/base/view-transition.ts +77 -0
  72. package/src/biz/approval-desk/shell.ts +15 -11
  73. package/src/biz/auth-panel/shell.ts +9 -7
  74. package/src/biz/category-crud/compile.ts +5 -4
  75. package/src/biz/category-crud/shell.ts +5 -3
  76. package/src/biz/checkout-page/compile.ts +2 -1
  77. package/src/biz/checkout-page/shell.ts +10 -8
  78. package/src/biz/compose.ts +2 -2
  79. package/src/biz/data-components.ts +4 -0
  80. package/src/biz/import-wizard/shell.ts +13 -10
  81. package/src/biz/landing-page/shell.ts +2 -2
  82. package/src/biz/link/hub.ts +23 -5
  83. package/src/biz/link/shared.ts +23 -12
  84. package/src/biz/master-sub/compile.ts +207 -16
  85. package/src/biz/master-sub/detail-head.ts +61 -0
  86. package/src/biz/master-sub/index.ts +7 -3
  87. package/src/biz/master-sub/shell.ts +133 -24
  88. package/src/biz/multi-board/compile.ts +167 -9
  89. package/src/biz/multi-board/composition.ts +58 -0
  90. package/src/biz/multi-board/index.ts +1 -1
  91. package/src/biz/multi-board/prose-fold.ts +143 -0
  92. package/src/biz/multi-board/shell.ts +94 -23
  93. package/src/biz/notification-center/shell.ts +10 -7
  94. package/src/biz/page-templates/domain-templates.ts +2 -2
  95. package/src/biz/page-templates/result-page/shell.ts +4 -3
  96. package/src/biz/page-templates/sign-in-page/shell.ts +16 -16
  97. package/src/biz/record-detail/compile.ts +2 -2
  98. package/src/biz/record-detail/shell.ts +13 -10
  99. package/src/biz/settings-center/compile.ts +2 -1
  100. package/src/biz/settings-center/shell.ts +12 -9
  101. package/src/biz/shared/action-host.ts +6 -0
  102. package/src/biz/shared/compile-helpers.ts +97 -0
  103. package/src/biz/shared/coordinator.ts +7 -30
  104. package/src/biz/shared/index.ts +5 -0
  105. package/src/biz/shared/object-aliases.ts +154 -0
  106. package/src/biz/shared/overlay-compile.ts +281 -0
  107. package/src/biz/shared/overlay-shell.ts +142 -11
  108. package/src/biz/shared/pipes.ts +11 -5
  109. package/src/biz/shared/remove-wire.ts +4 -19
  110. package/src/biz/shared/runtime-hub.ts +10 -0
  111. package/src/biz/single-form/compile.ts +3 -2
  112. package/src/biz/single-form/shell.ts +9 -6
  113. package/src/biz/standard-crud/compile.ts +36 -161
  114. package/src/biz/standard-crud/shell.ts +23 -60
  115. package/src/biz/standard-crud/summary.ts +40 -0
  116. package/src/biz/step-form/shell.ts +15 -13
  117. package/src/biz/types.ts +6 -1
  118. package/src/cli/kit-cli.ts +138 -13
  119. package/src/cli/kit-init.ts +6 -1
  120. package/src/cli/layout-cli.ts +167 -0
  121. package/src/cli/migrate/index.ts +10 -0
  122. package/src/cli/migrate/migrate.ts +248 -0
  123. package/src/cli/migrate/text-utils.ts +306 -0
  124. package/src/cli/migrate/theme-map.ts +104 -0
  125. package/src/cli/migrate/ts-rules.ts +235 -0
  126. package/src/cli/migrate/types.ts +95 -0
  127. package/src/cli/migrate/view-skeleton.ts +159 -0
  128. package/src/cli/migrate/yaml-report.ts +376 -0
  129. package/src/cli/migrate/yaml-rules.ts +465 -0
  130. package/src/cli/view-writes.ts +69 -60
  131. package/src/compile/access-gate-attach.ts +27 -0
  132. package/src/compile/closed-set.ts +65 -4
  133. package/src/compile/compile-page.ts +66 -11
  134. package/src/compile/component-candidates.ts +14 -1
  135. package/src/compile/fragment.ts +11 -0
  136. package/src/compile/layout-lint/engine.ts +82 -0
  137. package/src/compile/layout-lint/index.ts +55 -0
  138. package/src/compile/layout-lint/rules-composition.ts +267 -0
  139. package/src/compile/layout-lint/rules-form.ts +191 -0
  140. package/src/compile/layout-lint/rules-table.ts +278 -0
  141. package/src/compile/layout-lint/score.ts +52 -0
  142. package/src/compile/layout-lint/types.ts +51 -0
  143. package/src/compile/page-composition.ts +189 -0
  144. package/src/compile/parse.ts +4 -0
  145. package/src/compile/producer-fingerprint.ts +56 -0
  146. package/src/compile/remove-guard.ts +10 -7
  147. package/src/compile/styles.ts +46 -8
  148. package/src/compile/types.ts +16 -2
  149. package/src/compile/view-check.ts +149 -16
  150. package/src/data/access-gate.ts +112 -0
  151. package/src/data/amount-breakdown.ts +9 -2
  152. package/src/data/approval-flow.ts +5 -2
  153. package/src/data/assignment-picker.ts +59 -28
  154. package/src/data/async-result-panel.ts +49 -3
  155. package/src/data/breadcrumbs.ts +3 -2
  156. package/src/data/calendar.ts +8 -3
  157. package/src/data/carousel.ts +10 -6
  158. package/src/data/chart.ts +744 -46
  159. package/src/data/checklist.ts +22 -6
  160. package/src/data/code-view.ts +8 -4
  161. package/src/data/comment-thread.ts +3 -2
  162. package/src/data/confirm-dialog.ts +72 -25
  163. package/src/data/context-menu.ts +3 -3
  164. package/src/data/dock.ts +1 -1
  165. package/src/data/embed.ts +231 -29
  166. package/src/data/field-mapper.ts +7 -4
  167. package/src/data/flow-editor-contract.ts +7 -0
  168. package/src/data/flow-editor.ts +26 -9
  169. package/src/data/flow-node-options.ts +33 -3
  170. package/src/data/footer.ts +2 -0
  171. package/src/data/gantt.ts +192 -27
  172. package/src/data/hero.ts +4 -1
  173. package/src/data/image-viewer.ts +7 -4
  174. package/src/data/index.ts +16 -4
  175. package/src/data/item-list.ts +27 -12
  176. package/src/data/kanban.ts +41 -10
  177. package/src/data/matrix.ts +391 -0
  178. package/src/data/media-grid.ts +6 -1
  179. package/src/data/mega-menu.ts +6 -4
  180. package/src/data/menu-dom.ts +4 -2
  181. package/src/data/menu.ts +60 -16
  182. package/src/data/mockup.ts +5 -1
  183. package/src/data/modal-dialog.ts +146 -26
  184. package/src/data/navbar.ts +8 -6
  185. package/src/data/notice-list.ts +301 -0
  186. package/src/data/notify-renderer.ts +21 -6
  187. package/src/data/object-form.ts +409 -87
  188. package/src/data/outcome-watch.ts +61 -2
  189. package/src/data/pager.ts +19 -8
  190. package/src/data/panel-head.ts +406 -0
  191. package/src/data/permission-matrix.ts +36 -11
  192. package/src/data/permission-tree.ts +52 -23
  193. package/src/data/pricing-table.ts +22 -11
  194. package/src/data/prompt-dialog.ts +165 -0
  195. package/src/data/reaction-bar.ts +6 -4
  196. package/src/data/record-card.ts +40 -7
  197. package/src/data/record-picker.ts +13 -7
  198. package/src/data/resident.ts +8 -0
  199. package/src/data/result-panel.ts +4 -2
  200. package/src/data/rich-text.ts +17 -1
  201. package/src/data/row-editor.ts +77 -24
  202. package/src/data/rule-builder.ts +14 -9
  203. package/src/data/shape-util.ts +27 -12
  204. package/src/data/stat-group.ts +459 -74
  205. package/src/data/static-lazy.ts +5 -0
  206. package/src/data/static-registry.ts +8 -0
  207. package/src/data/steps.ts +8 -3
  208. package/src/data/survey.ts +7 -4
  209. package/src/data/system-switcher.ts +3 -2
  210. package/src/data/text-action-button.ts +17 -0
  211. package/src/data/timeline.ts +17 -6
  212. package/src/data/tour-guide.ts +3 -2
  213. package/src/data/transfer.ts +40 -16
  214. package/src/data/tree-table.ts +65 -37
  215. package/src/data/tree.ts +22 -2
  216. package/src/data/virtual-rows.ts +21 -11
  217. package/src/data/wrapped-candidates.ts +32 -1
  218. package/src/frames/index.ts +1 -0
  219. package/src/frames/list-summary.ts +100 -0
  220. package/src/frames/page-bar.ts +7 -14
  221. package/src/frames/page-status.ts +7 -5
  222. package/src/frames/shared.ts +34 -13
  223. package/src/frames/split-frame/shell.ts +1 -1
  224. package/src/frames/tabs-frame/shell.ts +9 -6
  225. package/src/frames/tabs-frame/wiring.ts +1 -0
  226. package/src/frames/top-main-frame.ts +3 -3
  227. package/src/frames/types.ts +3 -1
  228. package/src/frames/workspace-frame/extras.ts +1 -1
  229. package/src/frames/workspace-frame/shell.ts +4 -4
  230. package/src/frames/workspace-frame/tab-scroll.ts +28 -0
  231. package/src/frames/workspace-frame/view.ts +168 -44
  232. package/src/generated/kit-grammar-runtime.ts +390 -59
  233. package/src/i18n/kit-text.ts +90 -4
  234. package/src/i18n/resolve-text-refs.ts +22 -6
  235. package/src/object-renderer/action-group.ts +139 -0
  236. package/src/object-renderer/action-more.ts +144 -0
  237. package/src/object-renderer/arrange.ts +71 -7
  238. package/src/object-renderer/candidates.ts +4 -0
  239. package/src/object-renderer/collection-parts.ts +264 -62
  240. package/src/object-renderer/collection-table.ts +177 -5
  241. package/src/object-renderer/collection.ts +188 -37
  242. package/src/object-renderer/compile-data.ts +28 -3
  243. package/src/object-renderer/defaults.ts +27 -2
  244. package/src/object-renderer/display-checks.ts +1 -1
  245. package/src/object-renderer/emit-events.ts +43 -9
  246. package/src/object-renderer/emit-object.ts +4 -0
  247. package/src/object-renderer/emit-static.ts +434 -41
  248. package/src/object-renderer/filter-plan.ts +84 -0
  249. package/src/object-renderer/form-detail.ts +1 -2
  250. package/src/object-renderer/form-notify.ts +45 -0
  251. package/src/object-renderer/index.ts +5 -0
  252. package/src/object-renderer/layout-facts.ts +394 -0
  253. package/src/object-renderer/layout-plan.ts +225 -0
  254. package/src/object-renderer/layout-plan.types.ts +59 -0
  255. package/src/object-renderer/parts.ts +6 -7
  256. package/src/object-renderer/render-object.ts +107 -46
  257. package/src/object-renderer/request-actions.ts +4 -2
  258. package/src/object-renderer/skeleton.ts +58 -19
  259. package/src/object-renderer/table-actions.ts +172 -32
  260. package/src/object-renderer/table-gap.ts +37 -0
  261. package/src/object-renderer/table-tools.ts +62 -30
  262. package/src/object-renderer/types.ts +84 -13
  263. package/src/object-renderer/view-binding.ts +205 -8
  264. package/src/page-target/intent-schema.ts +11 -0
  265. package/src/page-target/target.ts +5 -1
  266. package/src/recipes/container.ts +77 -1
  267. package/src/recipes/control.ts +76 -116
  268. package/src/recipes/emphasis.ts +56 -0
  269. package/src/recipes/frame-bleed.ts +33 -0
  270. package/src/recipes/index.ts +72 -0
  271. package/src/recipes/nowrap.ts +16 -0
  272. package/src/recipes/overlay.ts +120 -17
  273. package/src/recipes/placeholder.ts +95 -0
  274. package/src/recipes/rail-grid.ts +48 -0
  275. package/src/recipes/slot-align.ts +56 -0
  276. package/src/recipes/stat-state.ts +65 -0
  277. package/src/recipes/state.ts +40 -21
  278. package/src/recipes/status.ts +147 -0
  279. package/src/recipes/surface-edge.ts +16 -0
  280. package/src/recipes/surface.ts +40 -0
  281. package/src/recipes/table-gap.ts +80 -0
  282. package/src/recipes/table-native-edit.ts +242 -0
  283. package/src/recipes/table-row.ts +146 -3
  284. package/src/recipes/tabs.ts +49 -0
  285. package/src/recipes/title-row.ts +37 -0
  286. package/src/recipes/typography.ts +30 -37
  287. package/src/shared/confirm-decl.ts +118 -0
  288. package/src/shared/envelope.ts +2 -2
  289. package/src/shared/paged-list-adapter.ts +15 -240
  290. package/src/shared/theme-runtime-shared.ts +6 -1
  291. package/src/theme/index.ts +1 -0
  292. package/src/theme/kit-theme-text.ts +1 -1
  293. package/src/theme/kit-theme.css +384 -13
  294. package/src/theme/kit-theme.tpl +384 -13
  295. package/src/theme/nine-dim-structure.ts +244 -7
  296. package/src/theme/surface-layers.ts +10 -1
  297. package/src/theme/theme-tokens.ts +63 -16
  298. package/src/theme/theme-types.ts +32 -0
  299. package/src/theme/typography.ts +21 -17
  300. package/src/biz/shared/remove-key.ts +0 -6
@@ -0,0 +1,278 @@
1
+ // 布局体检 · 表格与动作类气味(001–013)。谓词全部静态:页面事实 + 影子规划,阈值读 KIT_LAYOUT_SMELLS,不抄数字。
2
+
3
+ import { KIT_WIDTH_LIMITS } from 'soma-foundation/kit-limits';
4
+ import { KIT_LAYOUT_SMELLS, kitLabelTooLong, kitReferenceContainerRem, kitRuleTableOf } from 'soma-foundation/kit-layout';
5
+ import { KIT_ARRANGE, textWidthEm } from 'soma-foundation/arrange';
6
+ import { sparsityMetrics, sparsityVerdict, SPARSITY_THRESHOLDS } from 'soma-foundation/arrange/measure';
7
+ import { arrangeColumns } from 'soma-foundation/arrange/table';
8
+ import { KIT_TABLE_EXT, KIT_TREE_TABLE } from '../../object-renderer/defaults';
9
+ import { splitRowActions } from '../../object-renderer/table-actions';
10
+ import type { KitFactAction, KitFactObject } from '../../object-renderer/layout-facts';
11
+ import { allFieldsOf, viewSites, type KitLintInput, type KitSmellFinding, type KitSmellRule } from './types';
12
+
13
+ const C = KIT_LAYOUT_SMELLS.catalog;
14
+ const isTable = (v: { slot: string; collection: string | null }): boolean => v.slot === 'list' && (v.collection === 'table' || v.collection === 'treeTable');
15
+ const numeric = (type: string): boolean => (kitRuleTableOf().table.numericTypes as readonly string[]).includes(type);
16
+
17
+ /** 对象上登记的行动作(按列表 rowActions 的声明序);没写 rowActions 的列表没有行动作。 */
18
+ function rowActionsOf(object: KitFactObject, ids: readonly string[]): KitFactAction[] {
19
+ const byId = new Map(object.actions.filter((a) => a.on === 'row').map((a) => [a.id, a]));
20
+ return ids.flatMap((id) => (byId.has(id) ? [byId.get(id) as KitFactAction] : []));
21
+ }
22
+
23
+ /** 行动作的行内 / 「更多」切分:与发射(KitTableActions)同一个函数,体检不再另算一份。 */
24
+ function inlineSplitOf(actions: readonly KitFactAction[], cap: number): ReturnType<typeof splitRowActions> {
25
+ return splitRowActions(
26
+ actions.map((a) => ({ id: a.id, name: a.name, tone: a.primary ? 'primary' as const : a.danger ? 'danger' as const : 'neutral' as const, ...(a.more ? { more: true } : {}) })),
27
+ cap,
28
+ false,
29
+ );
30
+ }
31
+
32
+ const r001: KitSmellRule = (input) => {
33
+ const out: KitSmellFinding[] = [];
34
+ for (const s of viewSites(input.facts)) {
35
+ const plan = input.plan.views[s.planKey];
36
+ if (plan === undefined || plan.kind !== 'table') continue;
37
+ const free = kitReferenceContainerRem() - plan.selectRem - plan.actionsRem;
38
+ const parts = KIT_WIDTH_LIMITS.totalParts;
39
+ for (const col of plan.columns) {
40
+ const fact = allFieldsOf(s.view).find((f) => f.name === col.field);
41
+ if (fact === undefined || fact.width === null) continue;
42
+ const have = (free * fact.width) / parts;
43
+ if (have + 0.0005 < col.minRem) {
44
+ out.push({ path: fact.path, message: `列「${fact.label}」写了 width: ${fact.width},在参考容器里约 ${have.toFixed(1)}rem,小于内容需求的最小宽 ${col.minRem.toFixed(1)}rem,会被压窄截断` });
45
+ }
46
+ }
47
+ }
48
+ return out;
49
+ };
50
+
51
+ const r002: KitSmellRule = (input) => {
52
+ const out: KitSmellFinding[] = [];
53
+ const max = C['002'].params.idealShareMax;
54
+ for (const s of viewSites(input.facts)) {
55
+ const plan = input.plan.views[s.planKey];
56
+ if (plan === undefined || plan.kind !== 'table' || plan.mode !== 'parts') continue;
57
+ const sum = plan.columns.reduce((a, c) => a + c.idealRem, 0);
58
+ if (sum < max * kitReferenceContainerRem()) out.push({ path: s.view.path, message: `每列都写了 width,而各列理想宽之和只有 ${sum.toFixed(1)}rem(不足参考宽的 ${Math.round(max * 100)}%),均分会把短值列拉稀` });
59
+ }
60
+ return out;
61
+ };
62
+
63
+ const r003: KitSmellRule = (input) => {
64
+ const out: KitSmellFinding[] = [];
65
+ if (input.plan.rules >= 1) return out; // 规则版本 ≥ 1 的操作列宽由求解保证放得下
66
+ const cap = C['008'].params.inlineCap;
67
+ const parts = KIT_WIDTH_LIMITS.tableFixedParts;
68
+ for (const s of viewSites(input.facts)) {
69
+ if (!isTable(s.view)) continue;
70
+ const actions = rowActionsOf(s.object, s.view.rowActionIds);
71
+ if (actions.every((a) => a.more)) continue;
72
+ // 行内平铺的实际集合 = 发射用的同一个切分(引擎保留序 + 危险动作默认收进「更多」),不再各判各的
73
+ const split = inlineSplitOf(actions, cap);
74
+ const flat = split.inline;
75
+ const hasMore = split.folded.length > 0;
76
+ // 行操作是文字链接形态:估宽用文字链接的度量(字数 × 字宽 + 项间距 + 「更多」触发钮),与实际投影同一个引擎估算,不按按钮宽
77
+ const need = arrangeColumns({ fontRem: KIT_LAYOUT_SMELLS.reference.bodyFontRem, columns: [], actions: { labelEms: flat.map((a) => textWidthEm(a.name)), hasMore } }).actionsRem ?? 0;
78
+ const colParts = flat.length >= parts.actionsWideFromInline ? parts.actionsWide : parts.actions;
79
+ const have = (kitReferenceContainerRem() * colParts) / KIT_WIDTH_LIMITS.totalParts;
80
+ if (need > have + 0.0005) out.push({ path: s.view.path, message: `行动作「${flat.map((a) => a.name).join('」「')}」平铺需要约 ${need}rem,操作列只有约 ${have.toFixed(1)}rem(${colParts} 份),放不下` });
81
+ }
82
+ return out;
83
+ };
84
+
85
+ const r004: KitSmellRule = (input) => {
86
+ const out: KitSmellFinding[] = [];
87
+ const max = C['004'].params.columnsMax;
88
+ for (const s of viewSites(input.facts)) {
89
+ if (!isTable(s.view) || s.view.hasFixedColumn || s.view.hasColumnsTool) continue;
90
+ const n = allFieldsOf(s.view).length;
91
+ if (n > max) out.push({ path: s.view.path, message: `表格有 ${n} 列(超过 ${max}),又没有固定列与列设置工具,一屏放不下` });
92
+ }
93
+ return out;
94
+ };
95
+
96
+ const r005: KitSmellRule = (input) => {
97
+ const out: KitSmellFinding[] = [];
98
+ const p = C['005'].params;
99
+ for (const s of viewSites(input.facts)) {
100
+ if (!isTable(s.view)) continue;
101
+ const hits = allFieldsOf(s.view).filter((f) => f.type === 'longtext' || (f.maxLen !== null && f.maxLen > p.maxLen));
102
+ const escalate = input.profile === 'ai' && hits.length >= p.aiEscalateColumns;
103
+ for (const f of hits) out.push({ path: f.path, message: `列「${f.label}」是长文本(${f.type === 'longtext' ? 'longtext' : `max_len ${f.maxLen}`}),在单行省略的表格里读不全`, ...(escalate ? { severity: 'error' as const } : {}) });
104
+ }
105
+ return out;
106
+ };
107
+
108
+ const r006: KitSmellRule = (input) => {
109
+ const out: KitSmellFinding[] = [];
110
+ for (const s of viewSites(input.facts)) {
111
+ if (!isTable(s.view)) continue;
112
+ const fields = allFieldsOf(s.view);
113
+ const first = fields[0];
114
+ if (first === undefined || first.roles.includes('title')) continue;
115
+ const identifying = first.type === 'text' || first.type === 'longtext' || first.type === 'enums';
116
+ if (!identifying && fields.some((f) => f.roles.includes('title'))) out.push({ path: first.path, message: `首列「${first.label}」不是标识列,而后面有标题类字段「${fields.find((f) => f.roles.includes('title'))?.label ?? ''}」` });
117
+ }
118
+ return out;
119
+ };
120
+
121
+ const r007: KitSmellRule = (input) => {
122
+ const out: KitSmellFinding[] = [];
123
+ for (const s of viewSites(input.facts)) {
124
+ if (!isTable(s.view)) continue;
125
+ for (const f of allFieldsOf(s.view)) if (numeric(f.type) && f.align !== null && f.align !== 'end') out.push({ path: f.path, message: `数值列「${f.label}」写了 align: ${f.align},数值列应右对齐` });
126
+ }
127
+ return out;
128
+ };
129
+
130
+ const r008: KitSmellRule = (input) => {
131
+ const out: KitSmellFinding[] = [];
132
+ if (input.plan.rules >= 1) return out;
133
+ const cap = C['008'].params.inlineCap;
134
+ for (const s of viewSites(input.facts)) {
135
+ if (!isTable(s.view)) continue;
136
+ const visible = rowActionsOf(s.object, s.view.rowActionIds).filter((a) => !a.more);
137
+ if (visible.length > cap) out.push({ path: s.view.path, message: `行内平铺 ${visible.length} 个动作,超过封顶 ${cap} 个` });
138
+ }
139
+ return out;
140
+ };
141
+
142
+ const r009: KitSmellRule = (input) => {
143
+ const out: KitSmellFinding[] = [];
144
+ if (input.plan.rules >= 1) return out;
145
+ for (const s of viewSites(input.facts)) {
146
+ if (!isTable(s.view)) continue;
147
+ const actions = rowActionsOf(s.object, s.view.rowActionIds);
148
+ // 按发射的实际内联集合判:危险动作内联时置末并与前一项分隔(有分隔即合规),多个危险动作默认收进「更多」;
149
+ // 仍违规的只剩「整组都是危险动作」(引擎不折叠)并排平铺
150
+ const split = inlineSplitOf(actions, C['008'].params.inlineCap);
151
+ const dangerInline = split.inline.filter((a) => a.tone === 'danger' && !split.separated.has(a.id));
152
+ const sole = split.inline.every((a) => a.tone === 'danger');
153
+ if (!(sole && dangerInline.length >= 2)) continue;
154
+ for (const a of dangerInline) out.push({ path: actions.find((x) => x.id === a.id)?.path ?? s.view.path, message: `危险动作「${a.name}」与其他危险动作并排平铺(整组都是危险动作,无处分隔),应拆出非危险动作或放进「更多」` });
155
+ }
156
+ return out;
157
+ };
158
+
159
+ const r010: KitSmellRule = (input) => {
160
+ const out: KitSmellFinding[] = [];
161
+ const p = C['010'].params;
162
+ for (const product of input.facts.products) {
163
+ for (const object of product.objects) {
164
+ for (const a of object.actions) {
165
+ const row = a.on === 'row';
166
+ const toolbar = a.on === 'toolbar';
167
+ if (!row && !toolbar) continue;
168
+ if (kitLabelTooLong(a.name, row ? p.rowCjk : p.toolbarCjk, p.rowLatin)) out.push({ path: a.path, message: `${row ? '行' : '工具栏'}动作名「${a.name}」过长` });
169
+ }
170
+ }
171
+ }
172
+ return out;
173
+ };
174
+
175
+ const r011: KitSmellRule = (input) => {
176
+ const out: KitSmellFinding[] = [];
177
+ const max = C['011'].params.primaryMax;
178
+ for (const product of input.facts.products) {
179
+ for (const object of product.objects) {
180
+ const primaries = object.actions.filter((a) => a.on === 'toolbar' && a.primary);
181
+ if (primaries.length > max) out.push({ path: primaries[max]?.path ?? object.path, message: `工具栏有 ${primaries.length} 个主操作(tone: primary):${primaries.map((a) => a.name).join('、')}` });
182
+ }
183
+ }
184
+ return out;
185
+ };
186
+
187
+ const r012: KitSmellRule = (input) => {
188
+ const out: KitSmellFinding[] = [];
189
+ for (const s of viewSites(input.facts)) {
190
+ if (!isTable(s.view)) continue;
191
+ for (const f of allFieldsOf(s.view)) {
192
+ if (f.type === 'enum' && f.optionTones && (f.component === undefined || f.component === 'Text')) out.push({ path: f.path, message: `状态列「${f.label}」的候选带 tone,却用纯文本展示` });
193
+ }
194
+ }
195
+ return out;
196
+ };
197
+
198
+ const r013: KitSmellRule = (input) => {
199
+ const out: KitSmellFinding[] = [];
200
+ const min = C['013'].params.columnsMin;
201
+ for (const s of viewSites(input.facts)) {
202
+ if (!isTable(s.view)) continue;
203
+ const ones = allFieldsOf(s.view).filter((f) => f.width === 1);
204
+ if (ones.length >= min) out.push({ path: s.view.path, message: `${ones.length} 列写了 width: 1(${ones.map((f) => f.label).join('、')}),每列只有约 8% 宽` });
205
+ }
206
+ return out;
207
+ };
208
+
209
+ /**
210
+ * 内容宽(rem):能从声明静态知道的列才有——枚举 / 布尔看最长选项文案 + 药丸内边距、日期类取真源日期内容宽、有长度上限的文本 / 标识取 上限 × 字宽;
211
+ * 数字 / 金额 / 无长度上限的文本在编译期不知道值,返回 0(不参与列宽 / 内容宽之比)。
212
+ */
213
+ function contentRemOf(f: { readonly type: string; readonly maxLen: number | null; readonly options?: readonly string[] }): number {
214
+ const font = KIT_LAYOUT_SMELLS.reference.bodyFontRem;
215
+ const A = KIT_ARRANGE.columns;
216
+ if (f.type === 'enum' || f.type === 'enums' || f.type === 'bool') {
217
+ const em = (f.options ?? []).reduce((m, o) => Math.max(m, textWidthEm(o)), 0);
218
+ return em > 0 ? em * font + A.pillPadRem : 0;
219
+ }
220
+ if (KIT_TREE_TABLE.columnWeightRules.dateTypes.includes(f.type)) return (KIT_TABLE_EXT.narrowGrid.dateEms[f.type] ?? 0) * font;
221
+ if ((f.type === 'text' || f.type === 'longtext') && f.maxLen !== null) return f.maxLen * A.charEm * font;
222
+ return 0;
223
+ }
224
+
225
+ /**
226
+ * 表格稀疏 / 拥挤(IR 盒子):列轨求出的每个定宽列宽 / 内容宽之比超过 `measure.maxWidthRatio`(与渲染测量同一份 `sparsityMetrics` / `sparsityVerdict`),
227
+ * 说明该列比内容宽得多(列内大片空白);各列最小宽之和超过参考容器宽为拥挤(放不下,横滚)。主列吸收余量、其留白是设计,不计。
228
+ */
229
+ const r040: KitSmellRule = (input) => {
230
+ const out: KitSmellFinding[] = [];
231
+ const font = KIT_LAYOUT_SMELLS.reference.bodyFontRem;
232
+ const idName = new RegExp(KIT_ARRANGE.columns.idNamePattern);
233
+ for (const s of viewSites(input.facts)) {
234
+ if (!isTable(s.view)) continue;
235
+ const fields = allFieldsOf(s.view);
236
+ if (fields.length === 0) continue;
237
+ const solved = arrangeColumns({
238
+ fontRem: font,
239
+ columns: fields.map((f) => {
240
+ const em = (f.options ?? []).reduce((m, o) => Math.max(m, textWidthEm(o)), 0);
241
+ return {
242
+ key: f.name,
243
+ type: f.type === 'text' && idName.test(f.name) ? 'id' : f.type,
244
+ labelEm: textWidthEm(f.label),
245
+ ...(em > 0 ? { optionEm: em } : {}),
246
+ ...(f.maxLen !== null ? { maxLen: f.maxLen } : {}),
247
+ };
248
+ }),
249
+ });
250
+ if (solved.minRem > kitReferenceContainerRem()) {
251
+ out.push({ path: s.view.path, message: `各列最小宽之和 ${solved.minRem.toFixed(1)}rem 超过参考容器 ${kitReferenceContainerRem().toFixed(1)}rem,表格拥挤、要横向滚动` });
252
+ continue;
253
+ }
254
+ const columnWidths: number[] = [];
255
+ const contentWidths: number[] = [];
256
+ const names: string[] = [];
257
+ solved.columns.forEach((c, i) => {
258
+ const content = contentRemOf(fields[i]!);
259
+ if (c.grow || content <= 0) return;
260
+ columnWidths.push(c.ideal);
261
+ contentWidths.push(content);
262
+ names.push(fields[i]!.label);
263
+ });
264
+ const metrics = sparsityMetrics({ width: 1, height: 1, boxes: [], dividers: [], columnWidths, contentWidths });
265
+ if (sparsityVerdict(metrics).violations.includes('widthRatio')) {
266
+ const worst = columnWidths.reduce((best, w, i) => (w / contentWidths[i]! > columnWidths[best]! / contentWidths[best]! ? i : best), 0);
267
+ out.push({ path: s.view.path, message: `列「${names[worst]}」的列宽是内容宽的 ${metrics.widthRatioMax.toFixed(1)} 倍(上限 ${SPARSITY_THRESHOLDS.maxWidthRatio}),列内空白过大` });
268
+ }
269
+ }
270
+ return out;
271
+ };
272
+
273
+ export const TABLE_SMELL_RULES: Readonly<Record<string, KitSmellRule>> = {
274
+ '001': r001, '002': r002, '003': r003, '004': r004, '005': r005, '006': r006, '007': r007, '008': r008,
275
+ '009': r009, '010': r010, '011': r011, '012': r012, '013': r013, '040': r040,
276
+ };
277
+
278
+ export type { KitLintInput };
@@ -0,0 +1,52 @@
1
+ // 页面质量分(RV-1117 T07):0–100,确定、可分解、可做棘轮。权重与上限读 kit-layout.json#score(KIT_QUALITY_SCORE),不抄数字。
2
+ //
3
+ // score = 100 − min(40, 结构扣分) − min(25, 可读扣分) − min(20, 一致扣分) − min(15, 克制扣分)
4
+ // 结构扣分 = Σ 表格 / 表单 / 筛选 / 详情 / 面板类气味:error 10、warn 4、advice 1
5
+ // 克制扣分 = Σ 页面组合 / AI 式装饰类气味:error 8、warn 4、advice 1
6
+ // 一致扣分 = 手写覆写(036、039)每处 1;可读扣分来自渲染门(第二期),静态分里恒为 0
7
+ // 分数是违例的函数,不是审美判断:它保证「没有已知的丑」,不保证「好看」。
8
+
9
+ import { KIT_QUALITY_SCORE } from 'soma-foundation/kit-layout';
10
+ import type { KitAdvisory } from '../../object-renderer/types';
11
+
12
+ export interface KitQualityScoreResult {
13
+ /** 0–100 */
14
+ readonly score: number;
15
+ /** 各类实际扣分(已受上限约束) */
16
+ readonly deductions: { readonly structure: number; readonly readability: number; readonly consistency: number; readonly restraint: number };
17
+ /** 各类未封顶的原始扣分 */
18
+ readonly raw: { readonly structure: number; readonly readability: number; readonly consistency: number; readonly restraint: number };
19
+ }
20
+
21
+ const codeNo = (code: string): string => code.slice('KIT-LAYOUT-'.length);
22
+
23
+ /** 由 advisories 算静态质量分。advisories 须来自同一档案(human / ai)。 */
24
+ export function scoreKitPage(advisories: readonly KitAdvisory[]): KitQualityScoreResult {
25
+ const S = KIT_QUALITY_SCORE;
26
+ const structure = new Set<string>(S.families.structure);
27
+ const restraint = new Set<string>(S.families.restraint);
28
+ const override = new Set<string>(S.families.override);
29
+ let rawStructure = 0;
30
+ let rawRestraint = 0;
31
+ let rawConsistency = 0;
32
+ for (const a of advisories) {
33
+ const no = codeNo(a.code);
34
+ if (structure.has(no)) rawStructure += S.weights.structure[a.severity];
35
+ else if (restraint.has(no)) rawRestraint += S.weights.restraint[a.severity];
36
+ else if (override.has(no)) rawConsistency += S.weights.override;
37
+ }
38
+ const raw = { structure: rawStructure, readability: 0, consistency: rawConsistency, restraint: rawRestraint };
39
+ const deductions = {
40
+ structure: Math.min(S.caps.structure, raw.structure),
41
+ readability: Math.min(S.caps.readability, raw.readability),
42
+ consistency: Math.min(S.caps.consistency, raw.consistency),
43
+ restraint: Math.min(S.caps.restraint, raw.restraint),
44
+ };
45
+ const score = Math.max(0, S.base - deductions.structure - deductions.readability - deductions.consistency - deductions.restraint);
46
+ return { score, deductions, raw };
47
+ }
48
+
49
+ /** AI 页接受线:分数不低于 aiAcceptMin 且没有 error 级建议。 */
50
+ export function meetsAiAcceptLine(result: KitQualityScoreResult, advisories: readonly KitAdvisory[]): boolean {
51
+ return result.score >= KIT_QUALITY_SCORE.thresholds.aiAcceptMin && advisories.every((a) => a.severity !== 'error');
52
+ }
@@ -0,0 +1,51 @@
1
+ // 布局体检(RV-1117 T05)的内部类型:规则是「事实 + 规划 → 发现」的纯函数,严重级与建议文案读真源 kit-layout.json#smells。
2
+
3
+ import type { KitAdvisorySeverity } from '../../object-renderer/types';
4
+ import type { KitFactField, KitFactObject, KitFactProduct, KitFactView, KitPageFacts } from '../../object-renderer/layout-facts';
5
+ import type { KitLayoutPlan } from '../../object-renderer/layout-plan.types';
6
+
7
+ /** 两个档案:human = 人写页;ai = AI 生成页(`soma kit check --profile ai` 取同一严格档)。 */
8
+ export type KitLintProfile = 'human' | 'ai';
9
+
10
+ export interface KitLintInput {
11
+ readonly facts: KitPageFacts;
12
+ readonly plan: KitLayoutPlan;
13
+ readonly profile: KitLintProfile;
14
+ }
15
+
16
+ /** 规则的一条发现:严重级缺省取真源 catalog 的该档案级,规则可按具体情形覆写(如 AI 档同表两列长文本升 error)。 */
17
+ export interface KitSmellFinding {
18
+ readonly path: string;
19
+ readonly message: string;
20
+ readonly severity?: KitAdvisorySeverity;
21
+ }
22
+
23
+ /** 编号(`001`)→ 规则函数。 */
24
+ export type KitSmellRule = (input: KitLintInput) => KitSmellFinding[];
25
+
26
+ /** 遍历上下文:产品 → 对象 → 视图。 */
27
+ export interface KitViewSite {
28
+ readonly product: KitFactProduct;
29
+ readonly object: KitFactObject;
30
+ readonly view: KitFactView;
31
+ /** 规划里的视图键(`<对象路径>.<槽>`) */
32
+ readonly planKey: string;
33
+ }
34
+
35
+ export function viewSites(facts: KitPageFacts): KitViewSite[] {
36
+ const out: KitViewSite[] = [];
37
+ for (const product of facts.products) {
38
+ for (const object of product.objects) {
39
+ for (const view of object.views) out.push({ product, object, view, planKey: `${object.path}.${view.slot}` });
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+
45
+ /** 视图里全部字段(fields + groups 里的字段,按字段名去重)。 */
46
+ export function allFieldsOf(view: KitFactView): KitFactField[] {
47
+ const seen = new Set<string>();
48
+ return [...view.fields, ...view.groups.flatMap((g) => g.fields)].filter((f) => (seen.has(f.name) ? false : (seen.add(f.name), true)));
49
+ }
50
+
51
+ export const NUMERIC_TYPES: readonly string[] = ['int', 'decimal', 'money', 'percent'];
@@ -0,0 +1,189 @@
1
+ // 页面构成的编译期收尾(页面级,字符串层):区域主动作搬进页头尾端、唯一主体页的页面底取面板面。
2
+ // 构成判定本身在 foundation 的 solveComposition;这里只做「业务壳打了标记 → 页面级落位」的纯字符串变换,运行时不测量、不改 DOM。
3
+
4
+ import { arrangeActionEmphasis, arrangeSameTitle, type ArrangeActionEmphasisItem } from 'soma-foundation/arrange';
5
+ import { flowToolbarHtml } from '../object-renderer/action-group';
6
+ import { KIT_HOIST_ATTR, KIT_HOIST_HEADER_ACTIONS, KIT_HOIST_HEADER_SUMMARY } from '../biz/shared/compile-helpers';
7
+ import { kitEmphasisVariantOfLevel } from '../recipes/emphasis';
8
+
9
+ /** 业务壳声明「页面底取面板面」的标记(C2 唯一主体:页面本身就是工作面,没有卡落在画布上)。 */
10
+ export const KIT_CANVAS_HINT_ATTR = 'data-kit-canvas-hint';
11
+ /** 页面根(层 0 画布元素)上的结果属性:结构 CSS 把 --soma-surface-layer-0 指向面板面。 */
12
+ export const KIT_CANVAS_ATTR = 'data-kit-canvas';
13
+
14
+ /** 在 html 的 start 位置(一个 `<div …>` 的起点)找到与它配对的 `</div>` 之后的下标;找不到 -1。只数 div 标签。 */
15
+ function endOfDiv(html: string, start: number): number {
16
+ const re = /<(\/?)div\b[^>]*>/gi;
17
+ re.lastIndex = start;
18
+ let depth = 0;
19
+ for (let m = re.exec(html); m !== null; m = re.exec(html)) {
20
+ depth += m[1] === '' ? (m[0].endsWith('/>') ? 0 : 1) : -1;
21
+ if (depth === 0) return m.index + m[0].length;
22
+ }
23
+ return -1;
24
+ }
25
+
26
+ /**
27
+ * 把带 `data-kit-hoist="header-actions"` 的包装块的内部 HTML 搬进页头(`<header>` 内最后一个 `</div></header>` 之前,`ms-auto` 靠右)。
28
+ * 没有页头或没有标记时原样返回(标记块保留原位:靠右一行)。组件实例 id / 事件按 id 绑定,位置变化不影响接线。
29
+ */
30
+ export function hoistHeaderActions(html: string): string {
31
+ const mark = `${KIT_HOIST_ATTR}="${KIT_HOIST_HEADER_ACTIONS}"`;
32
+ const tail = html.indexOf('</div></header>');
33
+ if (html.indexOf(mark) < 0 || tail < 0) return html;
34
+ // 同一页可以有多处标记(区域主动作、概况条里的范围切换……):按出现顺序全部并进同一个页头槽,各自原位移除
35
+ let rest = html;
36
+ let inner = '';
37
+ for (let from = 0; ;) {
38
+ const at = rest.indexOf(mark, from);
39
+ if (at < 0) break;
40
+ const open = rest.lastIndexOf('<div', at);
41
+ const openEnd = rest.indexOf('>', at) + 1;
42
+ const close = endOfDiv(rest, open);
43
+ if (open < 0 || close < 0 || open < tail) { from = at + mark.length; continue; }
44
+ inner += rest.slice(openEnd, close - '</div>'.length);
45
+ rest = rest.slice(0, open) + rest.slice(close);
46
+ from = open;
47
+ }
48
+ if (inner === '') return html;
49
+ const slot = `<div data-kit-header-actions="" class="ms-auto flex shrink-0 items-start gap-3">${inner}</div>`;
50
+ const t = rest.indexOf('</div></header>');
51
+ return rest.slice(0, t) + slot + rest.slice(t);
52
+ }
53
+
54
+ /**
55
+ * 把带 `data-kit-hoist="header-summary"` 的包装块的内部 HTML 搬进页头标题行之后(概况行在标题下一行)。
56
+ * 没有页头标题或没有标记时原样返回(标记块保留原位)。
57
+ */
58
+ export function hoistHeaderSummary(html: string): string {
59
+ const mark = `${KIT_HOIST_ATTR}="${KIT_HOIST_HEADER_SUMMARY}"`;
60
+ const at = html.indexOf(mark);
61
+ const h1End = html.indexOf('</h1>');
62
+ if (at < 0 || h1End < 0) return html;
63
+ const open = html.lastIndexOf('<div', at);
64
+ const openEnd = html.indexOf('>', at) + 1;
65
+ const close = endOfDiv(html, open);
66
+ if (open < 0 || close < 0 || open < h1End) return html;
67
+ const inner = html.slice(openEnd, close - '</div>'.length);
68
+ const without = html.slice(0, open) + html.slice(close);
69
+ const rowEnd = without.indexOf('</div>', without.indexOf('</h1>'));
70
+ if (rowEnd < 0) return html;
71
+ const cut = rowEnd + '</div>'.length;
72
+ return without.slice(0, cut) + inner + without.slice(cut);
73
+ }
74
+
75
+ /** 列表页对齐轴标记(业务壳打在列表工作面 section 上;页面编译再给页头打同一个标记,页头标题 / 主动作与列表文字同轴)。 */
76
+ export const KIT_AXIS_ATTR = 'data-kit-axis';
77
+
78
+ /** 页面里有列表工作面(带轴标记)时,给页面框的页头 `<header …frame__header>` 打同一个轴标记;没有页头或没有工作面原样返回。 */
79
+ export function tagAxisHeader(html: string): string {
80
+ if (!html.includes(` ${KIT_AXIS_ATTR}=""`)) return html;
81
+ return html.replace(/<header(?=[^>]*\sdata-soma-id="[^"]*frame__header")/, `<header ${KIT_AXIS_ATTR}=""`);
82
+ }
83
+
84
+ /**
85
+ * 页面底取面板面:页面内恰有一个业务壳声明了 canvas-hint=surface 时,给页面的层 0 画布元素写 `data-kit-canvas="surface"`(标注发生在
86
+ * annotateSurfaceLayers 之后)。提示属性随即去掉(只是编译期的传话,不进最终 HTML)。
87
+ */
88
+ export function applyCanvasSurface(html: string): string {
89
+ const hint = `${KIT_CANVAS_HINT_ATTR}="surface"`;
90
+ const count = html.split(hint).length - 1;
91
+ const stripped = html.split(` ${hint}`).join('');
92
+ if (count !== 1) return stripped;
93
+ return stripped.replace(/(<[a-zA-Z][^>]*?\sdata-kit-layer="0")/, `$1 ${KIT_CANVAS_ATTR}="surface"`);
94
+ }
95
+
96
+ // ── 唯一主体页:主体自带标题与页面标题同义时不再渲染(其标题行上的动作并入页头一行)──────────────
97
+
98
+ const unescapeText = (s: string): string => s.replace(/<[^>]*>/g, '').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, '&');
99
+
100
+ /**
101
+ * 页面只有一个列表工作面(唯一主体 = 页面本身,带轴标记)时,它的标题行 `<div data-kit-title-row>` 里的标题(h3)若与页面标题同义(foundation 的 arrangeSameTitle:
102
+ * 「角色管理」与「角色列表」词干相同)就不再渲染:页面标题已经说了这件事。标题行上的动作组(区域主动作)摘出来打页头搬运标记,随后由 hoistHeaderActions 并进页头一行;
103
+ * 标题行里剩下的集合辅助文字(共 N 条 / 已筛选提示)原位保留。标题与页面标题不同义、有多个工作面、没有标题行时原样返回。
104
+ */
105
+ export function dropRedundantListTitle(html: string, pageTitle: string | undefined): string {
106
+ if (pageTitle === undefined || pageTitle.trim() === '') return html;
107
+ const axisMark = ` ${KIT_AXIS_ATTR}=""`;
108
+ const axisAt = html.indexOf(axisMark);
109
+ if (axisAt < 0 || html.indexOf(axisMark, axisAt + 1) >= 0) return html;
110
+ const rowAt = html.indexOf('<div data-kit-title-row=""', axisAt);
111
+ if (rowAt < 0) return html;
112
+ const rowEnd = endOfDiv(html, rowAt);
113
+ if (rowEnd < 0) return html;
114
+ const row = html.slice(rowAt, rowEnd);
115
+ const h3 = /<h3\b[^>]*data-kit-part="title-section"[^>]*>([\s\S]*?)<\/h3>/.exec(row);
116
+ if (h3 === null || !arrangeSameTitle(unescapeText(h3[1]!), pageTitle).same) return html;
117
+ let rest = row.replace(h3[0], '');
118
+ let moved = '';
119
+ const groupAt = rest.indexOf('data-kit-action-group=""');
120
+ if (groupAt >= 0) {
121
+ const open = rest.lastIndexOf('<div', groupAt);
122
+ const close = endOfDiv(rest, open);
123
+ if (open >= 0 && close > open) {
124
+ moved = rest.slice(open, close);
125
+ rest = rest.slice(0, open) + rest.slice(close);
126
+ }
127
+ }
128
+ const wrapper = moved === '' ? '' : `<div ${KIT_HOIST_ATTR}="${KIT_HOIST_HEADER_ACTIONS}" class="flex justify-end">${flowToolbarHtml(moved)}</div>`;
129
+ return html.slice(0, rowAt) + wrapper + rest + html.slice(rowEnd);
130
+ }
131
+
132
+ // ── 每屏唯一主焦点(动作强调的编译期级联)──────────────────────────────────────────────────────
133
+
134
+ const TAG_RE = /<(\/?)([a-zA-Z][\w-]*)((?:"[^"]*"|'[^']*'|[^'">])*)>/g;
135
+ const VOID_TAGS: ReadonlySet<string> = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']);
136
+ const attrOf = (attrs: string, name: string): string | undefined => new RegExp(`(?:^|\\s)${name}="([^"]*)"`).exec(attrs)?.[1];
137
+ const hasAttr = (attrs: string, name: string): boolean => new RegExp(`(?:^|\\s)${name}(?:=|\\s|/|$)`).test(attrs);
138
+
139
+ /** 一个静态 Button 宿主在页面里的位置(编译期已知):区域(页头 / 叠层 / 控件角色 / 宿主强调级)与同屏范围(常显 / 页签面板 / 叠层)。 */
140
+ function placeOfButton(stack: ReadonlyArray<{ tag: string; attrs: string }>): { region: string; scope: string } {
141
+ const overlay = [...stack].reverse().find((o) => attrOf(o.attrs, 'role') === 'dialog');
142
+ if (overlay !== undefined) return { region: 'overlay', scope: `overlay:${attrOf(overlay.attrs, 'data-soma-id') ?? ''}` };
143
+ const panel = [...stack].reverse().find((o) => hasAttr(o.attrs, 'data-kit-vt'));
144
+ const scope = panel === undefined ? '' : `tab:${attrOf(panel.attrs, 'data-soma-id') ?? ''}`;
145
+ if (stack.some((o) => hasAttr(o.attrs, 'data-kit-header-actions') || (o.tag === 'header' && /data-soma-id="[^"]*frame__header/.test(o.attrs)))) return { region: 'header', scope };
146
+ if (stack.some((o) => attrOf(o.attrs, 'data-kit-role') === 'control')) return { region: 'control', scope };
147
+ const host = [...stack].reverse().find((o) => attrOf(o.attrs, 'data-kit-emphasis') !== undefined);
148
+ const level = host === undefined ? 'primary' : attrOf(host.attrs, 'data-kit-emphasis');
149
+ return { region: level === 'primary' ? 'body' : 'aside', scope };
150
+ }
151
+
152
+ /**
153
+ * 每屏唯一主焦点:全页至多一个实心主动作(页头区域主动作优先,没有则取主体的主动作,其余降为色调);控件角色区域(主从的主列表列等)与次级宿主
154
+ * (secondary / tertiary / quiet 的面板头)里的动作上限为色调;叠层自成一个页面、名额独立。规则表在 kit-limits#emphasis,求解是 foundation 的 arrangeActionEmphasis。
155
+ * 本函数只负责「读出每个静态 Button 的位置 → 把求解结果写回它的 variant」:html 只读,ui.show 里被降的按钮改 props.variant。返回被降级的动作(id + 降到的变体)。
156
+ * 运行期组件里的按钮(筛选表单的「查询」等)由组件按自己的模式取变体,不经这里。
157
+ */
158
+ export function capActionEmphasis(html: string, show: Record<string, unknown> | undefined): Array<{ id: string; to: string }> {
159
+ if (show === undefined) return [];
160
+ const items: ArrangeActionEmphasisItem[] = [];
161
+ TAG_RE.lastIndex = 0;
162
+ const stack: Array<{ tag: string; attrs: string }> = [];
163
+ for (let m = TAG_RE.exec(html); m !== null; m = TAG_RE.exec(html)) {
164
+ const [, closing, rawTag, attrs] = m as unknown as [string, string, string, string];
165
+ const tag = rawTag.toLowerCase();
166
+ if (closing === '/') {
167
+ const at = stack.map((o) => o.tag).lastIndexOf(tag);
168
+ if (at >= 0) stack.length = at;
169
+ continue;
170
+ }
171
+ if (attrOf(attrs, 'data-soma-component') === 'Button') {
172
+ const id = attrOf(attrs, 'data-soma-id') ?? '';
173
+ const props = (show[id] as { props?: Record<string, unknown> } | undefined)?.props;
174
+ if (id !== '' && props?.variant === 'primary') items.push({ id, level: 'primary', ...placeOfButton(stack) });
175
+ }
176
+ if (!VOID_TAGS.has(tag) && !attrs.endsWith('/')) stack.push({ tag, attrs });
177
+ }
178
+ TAG_RE.lastIndex = 0;
179
+ if (items.length === 0) return [];
180
+ const plan = arrangeActionEmphasis(items);
181
+ const out: Array<{ id: string; to: string }> = [];
182
+ for (const r of plan.items) {
183
+ if (!r.demoted) continue;
184
+ const props = (show[r.id] as { props: Record<string, unknown> }).props;
185
+ props.variant = kitEmphasisVariantOfLevel(r.level);
186
+ out.push({ id: r.id, to: String(props.variant) });
187
+ }
188
+ return out;
189
+ }
@@ -616,6 +616,7 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[], defaul
616
616
  let explicitKind = false;
617
617
  let frameClass: string | undefined;
618
618
  let slotClass: Record<string, string> | undefined;
619
+ let frameBleed: boolean | undefined;
619
620
  let frameConfig: Record<string, unknown> | undefined;
620
621
  const slots: Record<string, KitProductDecl | KitTabDecl[]> = {};
621
622
  if (raw.frame !== undefined) {
@@ -633,6 +634,8 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[], defaul
633
634
  if (typeof f.class === 'string') frameClass = f.class;
634
635
  else if (f.class !== undefined) shape('frame.class', 'frame.class 必须是类串', diagnostics);
635
636
  slotClass = checkClassMap(f.slotClass, 'frame.slotClass', diagnostics);
637
+ if (typeof f.bleed === 'boolean') frameBleed = f.bleed;
638
+ else if (f.bleed !== undefined) shape('frame.bleed', 'frame.bleed 必须是布尔值(true = 内容区通栏)', diagnostics);
636
639
  if (f.config !== undefined) {
637
640
  if (!isRecord(f.config)) shape('frame.config', 'frame.config 必须是对象(页面框配置)', diagnostics);
638
641
  else frameConfig = f.config;
@@ -683,6 +686,7 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[], defaul
683
686
  const frame: KitPageDecl['frame'] = { kind: frameKind, explicitKind, slots };
684
687
  if (frameClass !== undefined) frame.class = frameClass;
685
688
  if (slotClass !== undefined) frame.slotClass = slotClass;
689
+ if (frameBleed !== undefined) frame.bleed = frameBleed;
686
690
  if (frameConfig !== undefined) frame.config = frameConfig;
687
691
  return { page: meta, frame };
688
692
  }
@@ -0,0 +1,56 @@
1
+ // kit 产出方指纹:落盘产物(core 的持久绑定)里的 `version` 以它开头。
2
+ //
3
+ // 编译产物的样子由「kit 包版本 + 语法真源 + 设计真源投影(限值含九维 / 控件 / 字阶)+ 缺省主题 CSS」决定;这些任一变了而页面源码没变,
4
+ // 旧产物(可能缺信封、闸门等新结构)就是过期的。core 只认不透明 version(缓存键 = URL + version),不认方言;
5
+ // 本指纹进页面 version,并经 core 的 `registerOwnerVersionGuard` 登记守卫:落盘产物恢复时 version 不以本版指纹开头即丢弃并重编。
6
+ // 同一份指纹也进进程内编译缓存键(server.ts)。
7
+
8
+ import { createHash } from 'node:crypto';
9
+ import { canonicalJson } from 'soma-foundation/fingerprint';
10
+ import * as kitLimitsNamespace from 'soma-foundation/kit-limits';
11
+ import { KIT_CONTROL } from 'soma-foundation/kit-control';
12
+ import { KIT_TYPE } from 'soma-foundation/kit-type';
13
+ import grammarJson from '../../spec/kit-grammar.json';
14
+ import pkg from '../../package.json';
15
+ import { KIT_DEFAULT_THEME_CSS } from '../theme/kit-theme-text';
16
+
17
+ /**
18
+ * kit 默认值指纹:这些变了而页面源码没变,旧缓存产物就是过期的——指纹进缓存键,kit 默认值一变整批自动失效。
19
+ * 纯函数:入参即全部输入,测试可直接换入参断言键随之变化。
20
+ */
21
+ export function kitDefaultsDigestOf(parts: {
22
+ readonly grammar: unknown;
23
+ readonly limits: unknown;
24
+ readonly control: unknown;
25
+ readonly type: unknown;
26
+ readonly defaultThemeCss: string;
27
+ }): string {
28
+ return createHash('sha256').update(canonicalJson(parts)).digest('hex').slice(0, 16);
29
+ }
30
+
31
+ function nonFunctionExports(ns: Readonly<Record<string, unknown>>): Record<string, unknown> {
32
+ const out: Record<string, unknown> = {};
33
+ for (const key of Object.keys(ns).sort()) {
34
+ if (typeof ns[key] !== 'function') out[key] = ns[key];
35
+ }
36
+ return out;
37
+ }
38
+
39
+ export const KIT_DEFAULTS_DIGEST = kitDefaultsDigestOf({
40
+ grammar: grammarJson,
41
+ limits: nonFunctionExports(kitLimitsNamespace as unknown as Record<string, unknown>),
42
+ control: KIT_CONTROL,
43
+ type: KIT_TYPE,
44
+ defaultThemeCss: KIT_DEFAULT_THEME_CSS,
45
+ });
46
+
47
+ /** 产出方指纹 = 包版本 + 默认值指纹;形如 `0.1.14.ab12cd34ef56ab12` */
48
+ export const KIT_PRODUCER_FINGERPRINT = `${pkg.version}.${KIT_DEFAULTS_DIGEST}`;
49
+
50
+ /** 页面 version 的前缀:`kit-<产出方指纹>-` */
51
+ export const KIT_VERSION_PREFIX = `kit-${KIT_PRODUCER_FINGERPRINT}-`;
52
+
53
+ /** core 版本守卫:只认本版产出方编出的页面 version(含 AI 提交页,同一条编译链);缺 version 一律不认 */
54
+ export function kitVersionGuard(version: string | undefined): boolean {
55
+ return typeof version === 'string' && version.startsWith(KIT_VERSION_PREFIX);
56
+ }