soma-kit 0.1.14 → 0.1.15

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 (287) hide show
  1. package/package.json +3 -3
  2. package/packs/finance/reconcile-desk/compile.ts +1 -1
  3. package/packs/finance/reconcile-desk/shell.ts +1 -1
  4. package/spec/generated/kit-app.schema.json +4 -2
  5. package/spec/generated/kit-page.schema.json +72 -2
  6. package/spec/kit-grammar.json +163 -57
  7. package/spec/kit-grammar.schema.json +0 -24
  8. package/src/app/app-config.ts +1 -1
  9. package/src/app/component-gate.ts +2 -2
  10. package/src/app/compose-apps.ts +5 -2
  11. package/src/app/define-kit-actions.ts +82 -10
  12. package/src/app/define-kit-app.ts +6 -5
  13. package/src/app/define-kit-view.ts +1 -1
  14. package/src/app/index.ts +7 -7
  15. package/src/app/kit-view-context.ts +11 -2
  16. package/src/app/theme-endpoint.ts +1 -1
  17. package/src/app/theme-runtime.ts +7 -2
  18. package/src/base/alert.ts +23 -20
  19. package/src/base/anchored-layer.ts +1 -1
  20. package/src/base/button.ts +30 -15
  21. package/src/base/cascader.ts +8 -4
  22. package/src/base/check-core.ts +9 -6
  23. package/src/base/color-picker.ts +10 -6
  24. package/src/base/command-palette.ts +10 -4
  25. package/src/base/context-menu.ts +5 -2
  26. package/src/base/date-range.ts +9 -6
  27. package/src/base/date.ts +10 -6
  28. package/src/base/delta.ts +4 -2
  29. package/src/base/divider.ts +15 -66
  30. package/src/base/fab.ts +11 -6
  31. package/src/base/gap-value.ts +1 -1
  32. package/src/base/hint-tips.ts +1 -1
  33. package/src/base/index.ts +15 -4
  34. package/src/base/inline-error.ts +84 -0
  35. package/src/base/input.ts +54 -18
  36. package/src/base/kbd.ts +4 -3
  37. package/src/base/link.ts +1 -1
  38. package/src/base/listbox-core.ts +70 -22
  39. package/src/base/mentions.ts +6 -3
  40. package/src/base/menu-button.ts +63 -27
  41. package/src/base/menu-core.ts +9 -2
  42. package/src/base/motion/hover-3d.ts +4 -1
  43. package/src/base/motion/hover-gallery.ts +4 -1
  44. package/src/base/otp.ts +7 -3
  45. package/src/base/overlay-runtime.ts +3 -2
  46. package/src/base/overlay-shell.ts +141 -0
  47. package/src/base/popover.ts +2 -2
  48. package/src/base/popup.ts +47 -41
  49. package/src/base/qty-stepper.ts +14 -9
  50. package/src/base/reason-tip.ts +2 -2
  51. package/src/{frames → base}/resize-handle.ts +1 -1
  52. package/src/base/segmented.ts +35 -36
  53. package/src/base/select.ts +1 -0
  54. package/src/base/shared.ts +43 -7
  55. package/src/base/status-tone.ts +1 -1
  56. package/src/base/tag-input.ts +13 -8
  57. package/src/base/tag.ts +53 -59
  58. package/src/base/text.ts +37 -13
  59. package/src/base/textarea.ts +1 -1
  60. package/src/base/time-picker.ts +9 -5
  61. package/src/base/tree-select.ts +12 -9
  62. package/src/base/upload.ts +21 -13
  63. package/src/biz/approval-desk/compile.ts +28 -1
  64. package/src/biz/approval-desk/shell.ts +2 -2
  65. package/src/biz/auth-panel/compile.ts +1 -1
  66. package/src/biz/auth-panel/shell.ts +2 -2
  67. package/src/biz/category-crud/compile.ts +17 -4
  68. package/src/biz/category-crud/shell.ts +7 -5
  69. package/src/biz/checkout-page/compile.ts +1 -1
  70. package/src/biz/checkout-page/shell.ts +7 -6
  71. package/src/biz/compose.ts +3 -3
  72. package/src/biz/define.ts +1 -1
  73. package/src/biz/import-wizard/compile.ts +1 -1
  74. package/src/biz/import-wizard/shell.ts +6 -4
  75. package/src/biz/index.ts +4 -3
  76. package/src/biz/landing-page/compile.ts +1 -1
  77. package/src/biz/landing-page/shell.ts +5 -4
  78. package/src/biz/link/shared.ts +8 -1
  79. package/src/biz/master-sub/compile.ts +162 -19
  80. package/src/biz/master-sub/detail-head.ts +7 -6
  81. package/src/biz/master-sub/index.ts +3 -3
  82. package/src/biz/master-sub/shell.ts +90 -53
  83. package/src/biz/multi-board/compile.ts +3 -3
  84. package/src/biz/multi-board/index.ts +24 -9
  85. package/src/biz/multi-board/prose-fold.ts +2 -2
  86. package/src/biz/multi-board/shell.ts +17 -13
  87. package/src/biz/names.ts +1 -0
  88. package/src/biz/notification-center/compile.ts +9 -2
  89. package/src/biz/notification-center/shell.ts +9 -2
  90. package/src/biz/page-templates/domain-templates.ts +6 -2
  91. package/src/biz/page-templates/result-page/compile.ts +1 -1
  92. package/src/biz/page-templates/result-page/shell.ts +4 -3
  93. package/src/biz/page-templates/shared.ts +1 -1
  94. package/src/biz/page-templates/sign-in-page/compile.ts +1 -1
  95. package/src/biz/page-templates/sign-in-page/shell.ts +4 -4
  96. package/src/biz/record-detail/compile.ts +5 -2
  97. package/src/biz/record-detail/shell.ts +4 -4
  98. package/src/biz/settings-center/compile.ts +1 -1
  99. package/src/biz/settings-center/shell.ts +8 -5
  100. package/src/biz/shared/action-host.ts +12 -5
  101. package/src/biz/shared/compile-helpers.ts +4 -4
  102. package/src/biz/shared/coordinator.ts +104 -21
  103. package/src/biz/shared/overlay-compile.ts +48 -18
  104. package/src/biz/shared/overlay-shell.ts +63 -112
  105. package/src/biz/single-form/compile.ts +2 -2
  106. package/src/biz/single-form/shell.ts +8 -4
  107. package/src/biz/standard-crud/compile.ts +11 -4
  108. package/src/biz/standard-crud/shell.ts +26 -9
  109. package/src/biz/standard-crud/summary.ts +3 -1
  110. package/src/biz/step-form/compile.ts +1 -1
  111. package/src/biz/step-form/hub.ts +4 -0
  112. package/src/biz/step-form/shell.ts +6 -4
  113. package/src/biz/types.ts +11 -4
  114. package/src/cli/app-layer-check.ts +375 -0
  115. package/src/cli/kit-cli.ts +35 -8
  116. package/src/cli/kit-init.ts +149 -0
  117. package/src/compile/access-gate-attach.ts +1 -1
  118. package/src/compile/action-host-attach.ts +1 -1
  119. package/src/compile/compile-page.ts +29 -234
  120. package/src/compile/component-candidates.ts +2 -1
  121. package/src/compile/hints.ts +5 -58
  122. package/src/compile/index.ts +2 -2
  123. package/src/compile/layout-lint/index.ts +4 -1
  124. package/src/compile/layout-lint/rules-composition.ts +43 -13
  125. package/src/compile/page-composition.ts +33 -31
  126. package/src/compile/redirect.ts +1 -1
  127. package/src/compile/stages.ts +169 -0
  128. package/src/compile/styles.ts +70 -32
  129. package/src/compile/types.ts +2 -2
  130. package/src/data/amount-breakdown.ts +4 -2
  131. package/src/data/anchor-nav.ts +4 -1
  132. package/src/data/approval-flow.ts +9 -4
  133. package/src/data/assignment-picker.ts +28 -18
  134. package/src/data/async-result-panel.ts +6 -2
  135. package/src/data/breadcrumbs.ts +13 -9
  136. package/src/data/calendar.ts +4 -3
  137. package/src/data/carousel.ts +11 -5
  138. package/src/data/chart.ts +153 -23
  139. package/src/data/checklist.ts +5 -4
  140. package/src/data/code-view.ts +220 -26
  141. package/src/data/comment-thread.ts +7 -2
  142. package/src/data/confirm-dialog.ts +56 -13
  143. package/src/data/diff.ts +4 -1
  144. package/src/data/dock.ts +5 -1
  145. package/src/data/embed.ts +1 -1
  146. package/src/data/engine-ports.ts +126 -0
  147. package/src/data/field-mapper.ts +12 -6
  148. package/src/data/flow-editor.ts +105 -29
  149. package/src/data/footer.ts +6 -2
  150. package/src/data/gantt.ts +11 -8
  151. package/src/data/hero.ts +6 -2
  152. package/src/data/image-viewer.ts +7 -3
  153. package/src/data/index.ts +12 -5
  154. package/src/data/item-list.ts +6 -5
  155. package/src/data/json-view.ts +844 -0
  156. package/src/data/kanban.ts +11 -8
  157. package/src/data/markdown-view.ts +487 -0
  158. package/src/data/matrix.ts +23 -14
  159. package/src/data/media-grid.ts +5 -2
  160. package/src/data/mega-menu.ts +4 -3
  161. package/src/data/menu-dom.ts +9 -8
  162. package/src/data/menu.ts +15 -9
  163. package/src/data/mockup.ts +9 -5
  164. package/src/data/modal-dialog.ts +39 -88
  165. package/src/data/navbar.ts +11 -7
  166. package/src/data/notice-list.ts +1 -1
  167. package/src/data/notify-renderer.ts +21 -10
  168. package/src/data/object-form.ts +129 -48
  169. package/src/data/pager.ts +12 -8
  170. package/src/data/panel-head.ts +1 -1
  171. package/src/data/permission-matrix.ts +15 -8
  172. package/src/data/permission-tree.ts +24 -11
  173. package/src/data/pricing-table.ts +8 -3
  174. package/src/data/reaction-bar.ts +6 -3
  175. package/src/data/record-card.ts +13 -9
  176. package/src/data/record-picker.ts +8 -4
  177. package/src/data/redirect.ts +1 -1
  178. package/src/data/request-console.ts +20 -7
  179. package/src/data/resident.ts +0 -12
  180. package/src/data/result-panel.ts +2 -2
  181. package/src/data/rich-text.ts +58 -96
  182. package/src/data/row-editor.ts +10 -5
  183. package/src/data/rule-builder.ts +14 -8
  184. package/src/data/shape-util.ts +14 -3
  185. package/src/data/stat-group.ts +63 -22
  186. package/src/data/static-lazy.ts +3 -0
  187. package/src/data/static-registry.ts +8 -2
  188. package/src/data/steps.ts +6 -2
  189. package/src/data/survey.ts +9 -3
  190. package/src/data/system-switcher.ts +15 -6
  191. package/src/data/text-diff.ts +663 -0
  192. package/src/data/timeline.ts +1 -1
  193. package/src/data/tour-guide.ts +6 -3
  194. package/src/data/transfer.ts +19 -10
  195. package/src/data/tree-table.ts +77 -12
  196. package/src/data/tree.ts +5 -2
  197. package/src/data/virtual-rows.ts +17 -7
  198. package/src/data/wrap.ts +2 -2
  199. package/src/frames/index.ts +3 -2
  200. package/src/frames/inherited-shell.ts +178 -0
  201. package/src/frames/list-summary.ts +59 -36
  202. package/src/frames/page-bar.ts +4 -2
  203. package/src/frames/resident-components.ts +20 -0
  204. package/src/frames/shared.ts +18 -14
  205. package/src/frames/split-frame/shell.ts +17 -11
  206. package/src/frames/split-frame/wiring.ts +2 -2
  207. package/src/frames/tabs-frame/shell.ts +12 -6
  208. package/src/frames/types.ts +3 -2
  209. package/src/frames/workspace-frame/extras.ts +19 -5
  210. package/src/frames/workspace-frame/shell.ts +2 -1
  211. package/src/frames/workspace-frame/state.ts +8 -2
  212. package/src/frames/workspace-frame/view.ts +125 -76
  213. package/src/generated/kit-grammar-runtime.ts +61 -39
  214. package/src/i18n/kit-text.ts +114 -2
  215. package/src/i18n/resolve-text-refs.ts +1 -1
  216. package/src/object-renderer/action-group.ts +31 -1
  217. package/src/object-renderer/action-more.ts +28 -12
  218. package/src/object-renderer/arrange.ts +37 -7
  219. package/src/object-renderer/collection-parts.ts +38 -7
  220. package/src/object-renderer/collection-table.ts +68 -23
  221. package/src/object-renderer/collection.ts +63 -30
  222. package/src/object-renderer/compile-data.ts +1 -1
  223. package/src/object-renderer/defaults.ts +8 -0
  224. package/src/object-renderer/emit-events.ts +1 -1
  225. package/src/object-renderer/emit-object.ts +3 -0
  226. package/src/object-renderer/emit-static.ts +140 -37
  227. package/src/object-renderer/field-value.ts +12 -239
  228. package/src/object-renderer/filter-toolbar.ts +103 -0
  229. package/src/{compile → object-renderer}/fragment.ts +2 -2
  230. package/src/object-renderer/index.ts +1 -1
  231. package/src/object-renderer/layout-facts.ts +37 -5
  232. package/src/object-renderer/overlay-decide.ts +82 -0
  233. package/src/object-renderer/render-object.ts +1 -1
  234. package/src/object-renderer/table-actions.ts +70 -23
  235. package/src/object-renderer/table-tools.ts +12 -5
  236. package/src/object-renderer/types.ts +9 -15
  237. package/src/recipes/app-blocks.ts +66 -0
  238. package/src/recipes/code-view.ts +56 -0
  239. package/src/recipes/compact-group.ts +31 -0
  240. package/src/recipes/container.ts +25 -15
  241. package/src/recipes/control.ts +21 -3
  242. package/src/recipes/desc-list.ts +14 -0
  243. package/src/recipes/divider.ts +53 -0
  244. package/src/recipes/emphasis.ts +12 -8
  245. package/src/recipes/frame-bleed.ts +3 -3
  246. package/src/recipes/index.ts +11 -1
  247. package/src/recipes/inherited-shell.ts +37 -0
  248. package/src/recipes/json-view.ts +49 -0
  249. package/src/recipes/markdown.ts +86 -0
  250. package/src/recipes/overlay.ts +112 -26
  251. package/src/recipes/page-width.ts +20 -0
  252. package/src/recipes/placeholder.ts +1 -1
  253. package/src/recipes/stat-state.ts +1 -1
  254. package/src/recipes/state.ts +10 -8
  255. package/src/recipes/status.ts +13 -12
  256. package/src/recipes/strip.ts +72 -0
  257. package/src/recipes/surface.ts +10 -6
  258. package/src/recipes/table-gap.ts +1 -1
  259. package/src/recipes/table-native-edit.ts +4 -4
  260. package/src/recipes/table-row.ts +11 -8
  261. package/src/recipes/tabs.ts +108 -31
  262. package/src/recipes/text-diff.ts +90 -0
  263. package/src/recipes/title-row.ts +4 -2
  264. package/src/recipes/typography.ts +2 -2
  265. package/src/shared/diagnostics.ts +16 -0
  266. package/src/shared/envelope.ts +1 -1
  267. package/src/shared/field-value-format.ts +246 -0
  268. package/src/shared/focus-ring.ts +8 -0
  269. package/src/shared/hints.ts +56 -0
  270. package/src/{base → shared}/icons.ts +12 -0
  271. package/src/shared/kit-error.ts +1 -1
  272. package/src/{object-renderer → shared}/merge-class.ts +3 -2
  273. package/src/shared/path-guard.ts +1 -1
  274. package/src/shared/primitives-types.ts +8 -0
  275. package/src/shared/theme-runtime-shared.ts +19 -0
  276. package/src/theme/kit-theme-text.ts +1 -1
  277. package/src/theme/kit-theme.css +38 -14
  278. package/src/theme/kit-theme.tpl +38 -14
  279. package/src/theme/nine-dim-structure.ts +66 -41
  280. package/src/theme/surface-layers.ts +11 -3
  281. package/src/theme/theme-tokens.ts +5 -1
  282. package/src/app/envelope.ts +0 -1
  283. package/src/app/notify-renderer.ts +0 -1
  284. package/src/app/paged-list-adapter.ts +0 -1
  285. package/src/app/theme-runtime-shared.ts +0 -1
  286. package/src/compile/kit-error.ts +0 -1
  287. /package/src/{base → shared}/class-candidates.ts +0 -0
@@ -0,0 +1,126 @@
1
+ // kit 取用 core 引擎端口的唯一路径(端口标准形式,见 handoff 端口标准形式.md):
2
+ // 组件契约声明 `services: ['engines']`,运行时取 `api.services.engines.<端口>`;
3
+ // kit 不 import core 的引擎子路径(`soma-core/diff` 等属「收回 core 内部」的出口),这里按结构写一份只读形状。
4
+ // 形状与 soma-core/core/client/engines/<端口>/port.ts 对齐;core 改形状时这里同步(契约测试由测试同学补)。
5
+
6
+ // ── 文本差异端口(engines.diff) ──────────────────────────────────────────────
7
+
8
+ export interface KitDiffFragment { readonly v: string; readonly op: 'eq' | 'ins' | 'del' }
9
+ export interface KitProseBlock { readonly op: 'eq' | 'ins' | 'del' | 'mod'; readonly fragments: readonly KitDiffFragment[] }
10
+ export type KitProseDegraded = 'timeout' | 'too-large' | 'no-segmenter';
11
+ export interface KitProseDiff {
12
+ readonly kind: 'same' | 'inline' | 'rewrite';
13
+ readonly formatOnly: boolean;
14
+ readonly similarity: number;
15
+ readonly blocks: readonly KitProseBlock[];
16
+ readonly stats: { readonly insChars: number; readonly delChars: number; readonly changes: number };
17
+ readonly granularity: 'words-zh' | 'words' | 'chars';
18
+ readonly degraded?: KitProseDegraded;
19
+ }
20
+ export interface KitItemFieldSpec { readonly name: string; readonly label: string; readonly type: 'text' | 'value' }
21
+ export type KitItemState = 'added' | 'removed' | 'modified' | 'moved' | 'moved-modified' | 'same';
22
+ export interface KitItemFieldDiff {
23
+ readonly name: string;
24
+ readonly label: string;
25
+ readonly type: 'text' | 'value';
26
+ readonly state: 'same' | 'changed' | 'added' | 'removed';
27
+ readonly before: unknown;
28
+ readonly after: unknown;
29
+ readonly prose?: KitProseDiff;
30
+ }
31
+ export interface KitItemDiffEntry {
32
+ readonly state: KitItemState;
33
+ readonly key: string;
34
+ readonly beforeIndex?: number;
35
+ readonly afterIndex?: number;
36
+ readonly title: string;
37
+ readonly fields: readonly KitItemFieldDiff[];
38
+ readonly magnitude: number;
39
+ }
40
+ export interface KitItemDiff {
41
+ readonly items: readonly KitItemDiffEntry[];
42
+ readonly stats: { readonly total: number; readonly added: number; readonly removed: number; readonly modified: number; readonly moved: number; readonly same: number };
43
+ readonly pairing: 'key' | 'content';
44
+ readonly fields: readonly KitItemFieldSpec[];
45
+ readonly movesSkipped: boolean;
46
+ readonly degraded?: KitProseDegraded | 'too-many-items';
47
+ }
48
+ export interface KitDiffPart { readonly op: 'equal' | 'insert' | 'delete'; readonly text: string }
49
+ export interface KitDiffEnginePort {
50
+ diff(a: string, b: string, mode: 'chars' | 'words' | 'lines' | 'words-zh'): Promise<readonly KitDiffPart[]>;
51
+ diffProse(a: string, b: string): Promise<KitProseDiff>;
52
+ diffItems(before: readonly unknown[], after: readonly unknown[], options?: { key?: string; fields?: readonly KitItemFieldSpec[]; title?: string }): Promise<KitItemDiff>;
53
+ }
54
+
55
+ // ── 代码高亮端口(engines.highlight) ─────────────────────────────────────────
56
+
57
+ export interface KitCodeToken { readonly text: string; readonly kind: string }
58
+ export interface KitCodeResult {
59
+ readonly language: string;
60
+ readonly lines: readonly (readonly KitCodeToken[])[];
61
+ readonly plainFrom: number;
62
+ readonly fallback?: 'unknown-language' | 'too-large' | 'timeout' | 'engine-load-failed';
63
+ }
64
+ export interface KitHighlightEnginePort {
65
+ resolveLanguage(hint: { language?: string; filename?: string; fence?: string; firstLine?: string; sample?: string }): string;
66
+ highlight(code: string, language: string): Promise<KitCodeResult>;
67
+ languageLabel(id: string): string;
68
+ }
69
+
70
+ // ── 结构化文本端口(engines.structured) ─────────────────────────────────────
71
+
72
+ export type KitStructuredFormat = 'json' | 'yaml';
73
+ export type KitStructuredParseResult =
74
+ | { readonly ok: true; readonly format: KitStructuredFormat; readonly value: unknown; readonly nodes: number; readonly cycles: number }
75
+ | {
76
+ readonly ok: false; readonly format: KitStructuredFormat;
77
+ readonly reason: 'syntax' | 'too-large' | 'too-many-nodes' | 'not-structured' | 'engine-load-failed';
78
+ readonly line?: number; readonly column?: number; readonly message?: string;
79
+ };
80
+ export interface KitStructuredEnginePort {
81
+ detect(text: string, hint?: { format?: string; filename?: string }): KitStructuredFormat;
82
+ parse(text: string, format?: KitStructuredFormat | 'auto'): Promise<KitStructuredParseResult>;
83
+ }
84
+
85
+ // ── Markdown 解析端口(engines.markdown) ───────────────────────────────────
86
+
87
+ export type KitMdSrc = readonly [number, number];
88
+ export type KitMdInline =
89
+ | { readonly t: 'text'; readonly v: string }
90
+ | { readonly t: 'strong' | 'em' | 'del'; readonly c: readonly KitMdInline[] }
91
+ | { readonly t: 'code'; readonly v: string }
92
+ | { readonly t: 'br' }
93
+ | { readonly t: 'link'; readonly href: string; readonly external: boolean; readonly title?: string; readonly c: readonly KitMdInline[] }
94
+ | { readonly t: 'image'; readonly src: string; readonly alt: string; readonly title?: string }
95
+ | { readonly t: 'fnref'; readonly id: string; readonly n: number };
96
+ export type KitMdBlock =
97
+ | { readonly t: 'heading'; readonly depth: 1 | 2 | 3 | 4 | 5 | 6; readonly id: string; readonly inline: readonly KitMdInline[]; readonly src: KitMdSrc }
98
+ | { readonly t: 'paragraph'; readonly inline: readonly KitMdInline[]; readonly tight: boolean; readonly src: KitMdSrc }
99
+ | { readonly t: 'list'; readonly ordered: boolean; readonly start?: number; readonly items: readonly { readonly task: boolean | null; readonly blocks: readonly KitMdBlock[] }[]; readonly src: KitMdSrc }
100
+ | { readonly t: 'quote'; readonly blocks: readonly KitMdBlock[]; readonly src: KitMdSrc }
101
+ | { readonly t: 'code'; readonly lang: string; readonly text: string; readonly closed: boolean; readonly src: KitMdSrc }
102
+ | { readonly t: 'table'; readonly align: readonly ('left' | 'center' | 'right' | null)[]; readonly head: readonly (readonly KitMdInline[])[]; readonly rows: readonly (readonly (readonly KitMdInline[])[])[]; readonly src: KitMdSrc }
103
+ | { readonly t: 'hr'; readonly src: KitMdSrc }
104
+ | { readonly t: 'html'; readonly text: string; readonly src: KitMdSrc }
105
+ | { readonly t: 'footnotes'; readonly items: readonly { readonly id: string; readonly n: number; readonly blocks: readonly KitMdBlock[] }[]; readonly src: KitMdSrc };
106
+ export interface KitMdMeta {
107
+ readonly outline: readonly { readonly depth: number; readonly text: string; readonly id: string }[];
108
+ readonly plainText: string;
109
+ readonly summary: string;
110
+ readonly counts: { readonly chars: number; readonly blocks: number; readonly images: number; readonly links: number; readonly codeBlocks: number; readonly tables: number };
111
+ readonly dropped: { readonly html: number; readonly unsafeUrls: number };
112
+ readonly truncated: boolean;
113
+ }
114
+ export type KitMdResult =
115
+ | { readonly ok: true; readonly blocks: readonly KitMdBlock[]; readonly meta: KitMdMeta }
116
+ | { readonly ok: false; readonly reason: 'too-long' | 'parse-error' | 'engine-load-failed'; readonly plainText: string };
117
+ export interface KitMarkdownEnginePort {
118
+ parse(source: string, options?: { footnotes?: boolean }): Promise<KitMdResult>;
119
+ }
120
+
121
+ /** 取一个引擎端口;宿主没装配(纯 Node 单测、无运行时)返回 null,组件按「引擎加载失败」降级 */
122
+ export function kitEnginePort<T>(services: unknown, id: string): T | null {
123
+ const engines = (services as { engines?: Record<string, unknown> } | undefined)?.engines;
124
+ const port = engines?.[id];
125
+ return port !== undefined && port !== null ? (port as T) : null;
126
+ }
@@ -13,9 +13,13 @@
13
13
 
14
14
  import type { SomaComponentDefinition } from 'soma-core';
15
15
  import { bool, createKitController, joinClass, num, str } from '../base/shared';
16
- import { kitIcon } from '../base/icons';
16
+ import { kitIcon } from '../shared/icons';
17
17
  import { kitText, type KitTextKey } from '../i18n/kit-text';
18
18
  import { setKitFace } from '../recipes';
19
+ import { kitControlRecipe } from '../recipes/control';
20
+ import { KIT_DIVIDER_FOOT_CLASS, kitDivideRecipe } from '../recipes/divider';
21
+ import { kitShellRecipe } from '../recipes/container';
22
+ import { mergeClass } from '../shared/merge-class';
19
23
  import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
20
24
  import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
21
25
  import { createKitEmbedBag, mountKitSelectField, type KitSelectField } from './embed';
@@ -25,24 +29,26 @@ import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
25
29
  // ───────── 样式常量:Tailwind 类串与候选类清单 ─────────
26
30
 
27
31
  const ROOT_CLASS = 'flex flex-col gap-3 text-sm text-fg';
28
- const LIST_CLASS = 'flex flex-col';
29
- const ROW_CLASS = 'flex flex-wrap items-center gap-2 border-b border-border-subtle py-2';
32
+ // 映射行之间的线由父出(kitDivideRecipe,KT-B5);来源框 = 控件配方;预览表外缘 = 壳配方,行线 = 分隔线出口
33
+ const ROWS_DIVIDE = kitDivideRecipe('y');
34
+ const LIST_CLASS = `flex flex-col ${ROWS_DIVIDE}`;
35
+ const ROW_CLASS = 'flex flex-wrap items-center gap-2 py-2';
30
36
  const ROW_MISSING_CLASS = 'flex flex-wrap items-center gap-2 rounded-md border border-danger bg-danger-soft px-2 py-2';
31
37
  const TARGET_CLASS = 'flex min-w-0 flex-1 flex-col';
32
38
  const LABEL_CLASS = 'text-fg';
33
39
  const KEY_CLASS = 'text-xs text-fg-muted';
34
40
  const REQ_CLASS = 'ms-1 text-xs text-danger-on-soft';
35
41
  const ARROW_CLASS = 'shrink-0 text-fg-subtle';
36
- const CONTROL_CLASS = 'block h-8 w-48 max-w-full appearance-none autofill-clear rounded-md border border-border bg-surface px-2 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle';
42
+ const CONTROL_CLASS = mergeClass(kitControlRecipe(), 'w-48 max-w-full');
37
43
  const REMOVE_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-sm text-danger-on-soft hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
38
44
  const ADD_ROW_CLASS = 'flex flex-wrap items-center gap-2 pt-2';
39
45
  const BTN_CLASS = kitEmphasisButtonRecipe('button.toolbar');
40
46
  const NOTICE_CLASS = 'rounded-md bg-warning-soft px-3 py-2 text-xs text-warning-on-soft';
41
47
  const PREVIEW_TITLE_CLASS = 'text-xs text-fg-muted';
42
- const PREVIEW_WRAP_CLASS = 'overflow-x-auto rounded-lg border border-border-subtle';
48
+ const PREVIEW_WRAP_CLASS = mergeClass('overflow-x-auto', kitShellRecipe({ tone: 'base', shadow: false }));
43
49
  const PREVIEW_TABLE_CLASS = 'w-full text-start text-xs';
44
50
  const PREVIEW_HEAD_CLASS = 'bg-surface-sunken px-2 py-1 font-medium text-fg-muted';
45
- const PREVIEW_CELL_CLASS = 'border-t border-border-subtle px-2 py-1 text-fg';
51
+ const PREVIEW_CELL_CLASS = `${KIT_DIVIDER_FOOT_CLASS} px-2 py-1 text-fg`;
46
52
  /** 来源下拉(自绘 Select)根上的宽度类,和文本框来源控件同宽 */
47
53
  const SELECT_ROOT_CLASS = 'w-48 max-w-full';
48
54
  const FOOT_CLASS ='flex items-center justify-end gap-2';
@@ -20,8 +20,12 @@ import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
20
20
  import { applyCommon, bool, createKitController, joinClass, num, str } from '../base/shared';
21
21
  import { kitText, type KitTextKey } from '../i18n/kit-text';
22
22
  import { setKitFace } from '../recipes';
23
+ import { kitControlEdgeRecipe } from '../recipes/control';
24
+ import { kitShellRecipe } from '../recipes/container';
25
+ import { kitSurfaceRecipe } from '../recipes/surface';
26
+ import { mergeClass } from '../shared/merge-class';
23
27
  import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
24
- import { kitIcon, type KitIconName } from '../base/icons';
28
+ import { kitIcon, type KitIconName } from '../shared/icons';
25
29
  import { createInput, KIT_INPUT_CLASS_CANDIDATES } from '../base/input';
26
30
  import { createTextarea, KIT_TEXTAREA_CLASS_CANDIDATES } from '../base/textarea';
27
31
  import { createSwitch, KIT_SWITCH_CLASS_CANDIDATES } from '../base/switch';
@@ -194,15 +198,19 @@ export function fmt(template: string, vars: Record<string, string | number>): st
194
198
  // hidden 与布局类分写两层:外层只管显隐,内层管布局。
195
199
  // ════════════════════════════════════════════════════════════════
196
200
 
201
+ const EDGE_STILL = kitControlEdgeRecipe({ wrapper: true, hover: false });
202
+ const EDGE_LIVE = kitControlEdgeRecipe({ wrapper: true });
197
203
  export const FLOW_CLASS = Object.freeze({
198
204
  root: 'flex w-full flex-col gap-2',
199
205
  toolbar: 'flex flex-wrap items-center gap-2',
200
- btn: kitEmphasisButtonRecipe('button.toolbar'),
206
+ btnGroup: 'inline-flex shrink-0 flex-nowrap items-center gap-1',
207
+ btn: mergeClass(kitEmphasisButtonRecipe('button.toolbar'), 'shrink-0 whitespace-nowrap'),
201
208
  btnPrimary: 'inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-primary bg-primary px-3 text-sm text-primary-fg transition-colors hover:bg-primary-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
202
209
  zoomLabel: 'text-xs text-fg-muted',
203
210
  row: 'flex w-full items-start gap-2',
204
211
  panelOuter: 'w-80 shrink-0',
205
- panel: 'flex h-120 flex-col gap-3 overflow-y-auto rounded-md border border-border-subtle bg-surface p-3',
212
+ // 配置面板与画布外缘 = 壳配方(容器边,KT-B2);节点 / 端口 / 节点条的轮廓 = 控件轮廓(KT-B1);右键菜单 = 浮起表面(KT-B4)
213
+ panel: mergeClass('flex h-120 flex-col gap-3 overflow-y-auto p-3', kitShellRecipe({ tone: 'base', shadow: false })),
206
214
  panelTitle: 'text-sm font-semibold text-fg',
207
215
  panelField: 'flex flex-col gap-1',
208
216
  panelFull: 'w-full',
@@ -210,7 +218,7 @@ export const FLOW_CLASS = Object.freeze({
210
218
  panelReq: 'ms-1 text-danger-on-soft',
211
219
  panelHelp: 'text-xs text-fg-muted',
212
220
  panelWarn: 'rounded-md bg-warning-soft px-2 py-1 text-xs text-warning-on-soft',
213
- stage: 'relative h-120 w-full touch-none select-none overflow-hidden rounded-md border border-border-subtle bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
221
+ stage: mergeClass('relative h-120 w-full touch-none select-none overflow-hidden focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring', kitShellRecipe({ tone: 'sunken', shadow: false })),
214
222
  svgRoot: 'absolute left-0 top-0 h-full w-full',
215
223
  gridDot: 'fill-border',
216
224
  gridRect: 'h-full w-full',
@@ -226,9 +234,9 @@ export const FLOW_CLASS = Object.freeze({
226
234
  lineError: 'truncate text-xs text-danger-on-soft',
227
235
  lineWarning: 'truncate text-xs text-warning-on-soft',
228
236
  cfgBtn: 'shrink-0 rounded-sm px-1 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
229
- inPort: 'pointer-events-none absolute -left-1 top-10 -mt-1 h-2 w-2 rounded-full border border-border bg-surface',
230
- outPort: 'absolute -right-2 top-10 -mt-2 h-4 w-4 p-0 cursor-crosshair rounded-full border border-border bg-surface hover:bg-primary-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
231
- bar: 'box-border flex h-full w-full items-center gap-1 rounded-md border border-border bg-surface px-2 text-xs text-fg shadow-sm',
237
+ inPort: `pointer-events-none absolute -left-1 top-10 -mt-1 h-2 w-2 rounded-full ${EDGE_STILL} bg-surface`,
238
+ outPort: `absolute -right-2 top-10 -mt-2 h-4 w-4 p-0 cursor-crosshair rounded-full ${EDGE_LIVE} bg-surface hover:bg-primary-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,
239
+ bar: `box-border flex h-full w-full max-w-full items-center gap-1 overflow-hidden rounded-md ${EDGE_STILL} bg-surface px-2 text-xs text-fg shadow-sm`,
232
240
  edgeG: 'group cursor-pointer outline-none',
233
241
  edgeHit: 'fill-none stroke-transparent stroke-12',
234
242
  edgeLabel: 'fill-fg-muted text-xs',
@@ -238,7 +246,7 @@ export const FLOW_CLASS = Object.freeze({
238
246
  errorInner: 'rounded-md border border-danger bg-danger-soft px-3 py-2 text-sm text-danger-on-soft',
239
247
  marqueeRect: 'fill-primary-soft stroke-primary opacity-50',
240
248
  menuFo: 'pointer-events-auto overflow-visible',
241
- menuInner: 'box-border flex w-full flex-col gap-1 rounded-md border border-border bg-surface p-1 shadow-lg',
249
+ menuInner: mergeClass('box-border flex w-full flex-col gap-1 p-1', kitSurfaceRecipe('raised')),
242
250
  menuItem: 'rounded-sm px-2 py-1 text-start text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring',
243
251
  menuItemDanger: 'rounded-sm px-2 py-1 text-start text-sm text-danger-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring',
244
252
  status: 'text-xs text-fg-muted',
@@ -255,7 +263,7 @@ export const FLOW_NODE_BG = Object.freeze({
255
263
  });
256
264
 
257
265
  export const FLOW_NODE_BORDER = Object.freeze({
258
- normal: 'border-border',
266
+ normal: kitControlEdgeRecipe({ wrapper: true, hover: false }),
259
267
  error: 'border-danger',
260
268
  warning: 'border-warning',
261
269
  ghost: 'border-dashed border-primary',
@@ -1745,12 +1753,47 @@ export function createFlowEditor(): SomaComponentDefinition {
1745
1753
  gridDot.setAttribute('cy', String(step / 2));
1746
1754
  }
1747
1755
  };
1756
+ let userAdjustedView = false;
1757
+ let lastStageW = 0;
1758
+ let lastStageH = 0;
1759
+ const isFormField = (): boolean => typeof P().name === 'string' && P().name !== '';
1748
1760
  const stageSize = (): { w: number; h: number } => ({ w: stage.clientWidth || 0, h: stage.clientHeight || 0 });
1749
- const allRects = (): Rect[] => [...posCache.values(), ...ghostPosCache.values()].map(nodeRect);
1761
+ /** 计算全部 AI 建议条的画布落位:在锚点右侧可能超界时改按锚点右缘对齐,并纳入 fitView 包围盒 */
1762
+ const suggestionBarLayout = (gh: { nodes: Array<FlowNode & { sid?: string }>; edges: Array<FlowEdge & { sid?: string }> }): Array<{ suggestion: FlowSuggestion; at: Pt; width: number }> => {
1763
+ const list: Array<{ suggestion: FlowSuggestion; at: Pt; width: number }> = [];
1764
+ const allNodes = [...posCache.values(), ...ghostPosCache.values()];
1765
+ const maxRight = allNodes.length > 0 ? Math.max(...allNodes.map((p) => p.x + FLOW_GEOMETRY.nodeW)) : 0;
1766
+ const barW = FLOW_GEOMETRY.barW;
1767
+ for (const s of visibleSuggestions()) {
1768
+ const first = gh.nodes.find((n) => n.sid === s.id);
1769
+ const anchor = first ? ghostPosCache.get(first.id) : undefined;
1770
+ const firstEdge = gh.edges.find((e) => e.sid === s.id);
1771
+ const mid = firstEdge && posOf(firstEdge.from) && posOf(firstEdge.to) ? edgeGeometry(posOf(firstEdge.from)!, posOf(firstEdge.to)!).mid : undefined;
1772
+ const rawAt = anchor ? { x: anchor.x, y: anchor.y + FLOW_GEOMETRY.nodeH + 4 } : mid;
1773
+ if (!rawAt) continue;
1774
+ const x = anchor && barW > FLOW_GEOMETRY.nodeW && rawAt.x + barW > maxRight
1775
+ ? Math.min(rawAt.x, maxRight - barW)
1776
+ : rawAt.x;
1777
+ list.push({ suggestion: s, at: { x, y: rawAt.y }, width: barW });
1778
+ }
1779
+ return list;
1780
+ };
1781
+ const allRects = (): Rect[] => {
1782
+ const rects = [...posCache.values(), ...ghostPosCache.values()].map(nodeRect);
1783
+ for (const item of suggestionBarLayout(ghostsOf())) {
1784
+ rects.push({ x: item.at.x, y: item.at.y, w: item.width, h: FLOW_GEOMETRY.barH });
1785
+ }
1786
+ return rects;
1787
+ };
1750
1788
  function fit(): void {
1751
1789
  const { w, h } = stageSize();
1752
1790
  view = w > 0 && h > 0 ? fitView(allRects(), w, h) : { zoom: 1, panX: 0, panY: 0 };
1753
- needFit = false;
1791
+ if (w > 0 && h > 0) {
1792
+ needFit = false;
1793
+ userAdjustedView = false;
1794
+ lastStageW = w;
1795
+ lastStageH = h;
1796
+ }
1754
1797
  applyView();
1755
1798
  updateZoomLabel();
1756
1799
  }
@@ -1758,6 +1801,7 @@ export function createFlowEditor(): SomaComponentDefinition {
1758
1801
  const { w, h } = stageSize();
1759
1802
  view = zoomAt(view, factor, w / 2, h / 2);
1760
1803
  needFit = false;
1804
+ userAdjustedView = true;
1761
1805
  applyView();
1762
1806
  updateZoomLabel();
1763
1807
  };
@@ -1802,28 +1846,41 @@ export function createFlowEditor(): SomaComponentDefinition {
1802
1846
 
1803
1847
  const paintToolbar = (): void => {
1804
1848
  toolbar.textContent = '';
1849
+ const group = (...btns: HTMLButtonElement[]): HTMLElement => {
1850
+ const g = el('div', FLOW_CLASS.btnGroup);
1851
+ g.append(...btns);
1852
+ return g;
1853
+ };
1805
1854
  if (editable()) {
1806
1855
  const types = Object.values(cfg.nodeTypes);
1807
1856
  if (types.length === 0) toolbar.appendChild(mkButton('add:', t('add', { type: t('nodeDefault') })));
1808
1857
  for (const ty of types) toolbar.appendChild(mkButton(`add:${ty.type}`, t('add', { type: ty.label })));
1809
- toolbar.appendChild(mkButton('undo', t('undo'), { disabled: !canUndo(history) }));
1810
- toolbar.appendChild(mkButton('redo', t('redo'), { disabled: !canRedo(history) }));
1858
+ toolbar.appendChild(group(
1859
+ mkButton('undo', t('undo'), { disabled: !canUndo(history) }),
1860
+ mkButton('redo', t('redo'), { disabled: !canRedo(history) }),
1861
+ ));
1811
1862
  toolbar.appendChild(mkButton('del', t('del'), { disabled: selected.size === 0 }));
1812
1863
  toolbar.appendChild(mkButton('connect', t('connect'), { disabled: selectedNodeIds().length !== 1 }));
1813
1864
  const one = selectedNodeIds().length === 1 && selectedEdgeIds().length === 0;
1814
1865
  toolbar.appendChild(mkButton('insert-above', t('insertAbove'), { disabled: !one, icon: 'plus' }));
1815
- toolbar.appendChild(mkButton('move-up', t('moveUp'), { disabled: !one, icon: 'arrow-up' }));
1816
- toolbar.appendChild(mkButton('move-down', t('moveDown'), { disabled: !one, icon: 'arrow-down' }));
1866
+ // 成对动作(↑ 上移 / ↓ 下移)保持同组不拆行
1867
+ toolbar.appendChild(group(
1868
+ mkButton('move-up', t('moveUp'), { disabled: !one, icon: 'arrow-up' }),
1869
+ mkButton('move-down', t('moveDown'), { disabled: !one, icon: 'arrow-down' }),
1870
+ ));
1817
1871
  if (cfg.layout === 'manual') toolbar.appendChild(mkButton('layout', t('layout'), { disabled: graph.nodes.length === 0 }));
1818
1872
  }
1819
- toolbar.appendChild(mkButton('zoom-out', t('zoomOut')));
1820
- toolbar.appendChild(mkButton('zoom-in', t('zoomIn')));
1821
- toolbar.appendChild(mkButton('fit', t('fit')));
1873
+ toolbar.appendChild(group(
1874
+ mkButton('zoom-out', t('zoomOut')),
1875
+ mkButton('zoom-in', t('zoomIn')),
1876
+ mkButton('fit', t('fit')),
1877
+ ));
1822
1878
  const z = el('span', FLOW_CLASS.zoomLabel, { 'data-flow-zoom': '' });
1823
1879
  z.textContent = t('zoomLabel', { n: Math.round(view.zoom * 100) });
1824
1880
  toolbar.appendChild(z);
1825
1881
  toolbar.appendChild(el('span', FLOW_CLASS.zoomLabel, { 'data-flow-hint': '' })).textContent = t('zoomHint');
1826
- if (editable()) toolbar.appendChild(mkButton('save', t('save'), { primary: true }));
1882
+ // 作为表单字段嵌入时不画独立主色蓝底「保存」,避免与弹窗底栏主按钮冲突
1883
+ if (editable() && !isFormField()) toolbar.appendChild(mkButton('save', t('save'), { primary: true }));
1827
1884
  };
1828
1885
 
1829
1886
  const nodeClass = (sel: boolean, level: Level, ghost: boolean, canMove: boolean): string => {
@@ -2029,15 +2086,10 @@ export function createFlowEditor(): SomaComponentDefinition {
2029
2086
  const gh = ghostsOf();
2030
2087
  const sugLabels = new Map(visibleSuggestions().map((s) => [s.id, s.label] as const));
2031
2088
  for (const n of gh.nodes) nodesLayer.appendChild(buildNode(n, ghostPosCache.get(n.id) ?? { x: 0, y: 0 }, { ghost: true, ghostOf: n.sid === undefined ? undefined : sugLabels.get(n.sid) }));
2032
- for (const s of visibleSuggestions()) {
2033
- const first = gh.nodes.find((n) => n.sid === s.id);
2034
- const anchor = first ? ghostPosCache.get(first.id) : undefined;
2035
- const firstEdge = gh.edges.find((e) => e.sid === s.id);
2036
- const mid = firstEdge && posOf(firstEdge.from) && posOf(firstEdge.to) ? edgeGeometry(posOf(firstEdge.from)!, posOf(firstEdge.to)!).mid : undefined;
2037
- const at = anchor ? { x: anchor.x, y: anchor.y + FLOW_GEOMETRY.nodeH + 4 } : mid;
2038
- if (!at) continue;
2089
+ for (const item of suggestionBarLayout(gh)) {
2090
+ const { suggestion: s, at, width } = item;
2039
2091
  const barFo = svg('foreignObject', FLOW_CLASS.fo);
2040
- place(barFo, at, FLOW_GEOMETRY.barW, FLOW_GEOMETRY.barH);
2092
+ place(barFo, at, width, FLOW_GEOMETRY.barH);
2041
2093
  const bar = el('div', FLOW_CLASS.bar, { role: 'group', 'data-flow-bar': s.id, 'aria-label': t('suggestion', { label: s.label }) });
2042
2094
  barFo.appendChild(bar);
2043
2095
  const cap = el('span', FLOW_CLASS.barCap);
@@ -2085,7 +2137,7 @@ export function createFlowEditor(): SomaComponentDefinition {
2085
2137
  emptyOuter.className = empty ? '' : FLOW_CLASS.hidden;
2086
2138
  emptyInner.textContent = bool(p.loading) ? t('loading') : cfg.readonly ? t('emptyReadonly') : t('empty');
2087
2139
 
2088
- if (needFit && graph.nodes.length > 0 && stage.clientWidth > 0) fit();
2140
+ if (needFit && (graph.nodes.length > 0 || gh.nodes.length > 0) && stage.clientWidth > 0 && stage.clientHeight > 0) fit();
2089
2141
  applyView();
2090
2142
 
2091
2143
  const errors = [...issues.values()].flat().filter((i) => i.level === 'error').length;
@@ -2551,7 +2603,7 @@ export function createFlowEditor(): SomaComponentDefinition {
2551
2603
  statusEl = el('p', FLOW_CLASS.status, { role: 'status', 'aria-live': 'polite' });
2552
2604
  // 画布 + 右侧配置面板同一行;面板外层只管显隐,内层管样式
2553
2605
  panelOuter = el('div', FLOW_CLASS.hidden);
2554
- panelInner = el('div', FLOW_CLASS.panel, { role: 'region' });
2606
+ panelInner = el('div', FLOW_CLASS.panel, { role: 'region', 'data-kit-container': 'card' });
2555
2607
  panelOuter.appendChild(panelInner);
2556
2608
  panelId = '';
2557
2609
  panelVals = '';
@@ -2593,6 +2645,30 @@ export function createFlowEditor(): SomaComponentDefinition {
2593
2645
  on(root, 'contextmenu', onContextMenu as (e: Event) => void);
2594
2646
  on(root, 'keydown', onKeydown as (e: Event) => void);
2595
2647
  on(root, 'focusin', onFocusIn as (e: Event) => void);
2648
+ // 弹窗打开或容器尺寸变化后重新居中适配画布节点(避免挂载时 0×0 或弹窗显隐切换后节点沉底 / 出屏)
2649
+ const refitIfNeeded = (): void => {
2650
+ const { w, h } = stageSize();
2651
+ if (w <= 0 || h <= 0) return;
2652
+ if (graph.nodes.length === 0 && ghostsOf().nodes.length === 0) return;
2653
+ if (needFit || (!userAdjustedView && (w !== lastStageW || h !== lastStageH))) fit();
2654
+ };
2655
+ if (typeof IntersectionObserver === 'function') {
2656
+ const io = new IntersectionObserver((entries) => {
2657
+ if (entries.some((entry) => entry.isIntersecting)) refitIfNeeded();
2658
+ });
2659
+ io.observe(stage);
2660
+ removers.push(() => io.disconnect());
2661
+ }
2662
+ const win = root.ownerDocument.defaultView;
2663
+ if (win) {
2664
+ const onWinResize = (): void => refitIfNeeded();
2665
+ win.addEventListener('resize', onWinResize);
2666
+ removers.push(() => win.removeEventListener('resize', onWinResize));
2667
+ if (typeof win.requestAnimationFrame === 'function') {
2668
+ const rafId = win.requestAnimationFrame(() => refitIfNeeded());
2669
+ removers.push(() => win.cancelAnimationFrame(rafId));
2670
+ }
2671
+ }
2596
2672
  const port = dndPort();
2597
2673
  if (port) {
2598
2674
  offMove = port.onMove((intent) => {
@@ -13,10 +13,14 @@ import { createKitController, joinClass } from '../base/shared';
13
13
  import { classTokens, mk, rowsOf, textOf, type Rec } from './shape-util';
14
14
  import { singleOf, urlOf } from './display-util';
15
15
  import { markKitEdge } from '../recipes/surface-edge';
16
+ import { kitShellRecipe } from '../recipes/container';
17
+ import { KIT_DIVIDER_FOOT_CLASS } from '../recipes/divider';
16
18
 
17
19
  const KEYS = ['brand', 'columns', 'copyright', 'social'] as const;
18
20
 
19
- const ROOT_CLASS = '@container flex flex-col gap-6 rounded-lg border border-border-subtle bg-surface-sunken px-6 py-8 text-sm text-fg-muted';
21
+ // 外缘 = 凹槽面的壳配方(容器边,KT-B2);底部版权行的线 = 分隔线出口
22
+ const ROOT_EDGE = kitShellRecipe({ tone: 'sunken', shadow: false });
23
+ const ROOT_CLASS = `@container flex flex-col gap-6 ${ROOT_EDGE} px-6 py-8 text-sm text-fg-muted`;
20
24
  const TOP_CLASS = 'flex flex-col gap-6';
21
25
  const BRAND_CLASS = 'text-lg font-semibold text-fg';
22
26
  const GRID_CLASS = 'grid grid-cols-1 gap-6 @md:grid-cols-2 @xl:grid-cols-4';
@@ -25,7 +29,7 @@ const COL_TITLE_CLASS = 'text-xs font-semibold text-fg';
25
29
  const LIST_CLASS = 'flex flex-col gap-1.5';
26
30
  const LINK_CLASS = 'rounded-sm text-fg-muted underline-offset-2 transition-colors hover:text-fg hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring';
27
31
  const PLAIN_CLASS = 'text-fg-subtle';
28
- const BOTTOM_CLASS = 'flex flex-col gap-3 border-t border-border-subtle pt-4 @md:flex-row @md:items-center @md:justify-between';
32
+ const BOTTOM_CLASS = `flex flex-col gap-3 ${KIT_DIVIDER_FOOT_CLASS} pt-4 @md:flex-row @md:items-center @md:justify-between`;
29
33
  const COPY_CLASS = 'text-xs text-fg-subtle';
30
34
  const SOCIAL_CLASS = 'flex flex-wrap items-center gap-2';
31
35
  const SOCIAL_LINK_CLASS = 'inline-flex h-8 min-w-8 items-center justify-center rounded-md px-2 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
package/src/data/gantt.ts CHANGED
@@ -22,7 +22,8 @@ import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
22
22
  import { createKitController, joinClass, num, str } from '../base/shared';
23
23
  import { kitText } from '../i18n/kit-text';
24
24
  import { kitTypographyRecipe } from '../recipes/typography';
25
- import { mergeClass } from '../object-renderer/merge-class';
25
+ import { mergeClass } from '../shared/merge-class';
26
+ import { KIT_DIVIDER_HEAD_CLASS, kitDividerRecipe } from '../recipes/divider';
26
27
  import {
27
28
  GANTT_BAR_LABEL_MAX, GANTT_CHART_FALLBACK_PX, GANTT_LABEL_COLUMN_PX, GANTT_NOTE_MAX,
28
29
  ganttBarLabelPlace, ganttBaselineBox, ganttIsNarrow, ganttTextWidthPx,
@@ -240,15 +241,17 @@ export function ganttRows(tasks: readonly KitGanttTask[]): Row[] {
240
241
 
241
242
  const ROOT_CLASS = 'flex flex-col overflow-x-auto text-sm text-fg';
242
243
  const INNER_CLASS = 'flex min-w-160 flex-col';
243
- const HEAD_CLASS = 'flex border-b border-border-subtle';
244
- // 左栏宽 = 真源 dataLimits.gantt.labelColumnMinPx(192 = w-48);行头任务名有最小宽,状态 / 负责人附注截断在自己的上限内
245
- const CORNER_CLASS = 'w-48 shrink-0 px-2 py-1 text-xs font-medium text-fg-muted';
244
+ // 刻度头底线、刻度之间的竖线 = 分隔线出口(发丝宽、分隔灰,KT-B1 / KT-B5)
245
+ const TICK_LINE = kitDividerRecipe('start');
246
+ const HEAD_CLASS = `flex ${KIT_DIVIDER_HEAD_CLASS}`;
247
+ // 左栏宽:在紧凑密度下保持充裕宽度(w-64),避免任务标题全截断;行头任务名有最小宽,状态 / 负责人附注截断在自己的上限内
248
+ const CORNER_CLASS = 'w-64 shrink-0 px-2 py-1 text-xs font-medium text-fg-muted';
246
249
  const TICKS_CLASS = 'flex flex-1';
247
- const TICK_CLASS = 'flex-1 border-l border-border-subtle px-1 py-1 text-xs text-fg-muted';
250
+ const TICK_CLASS = `flex-1 ${TICK_LINE} px-1 py-1 text-xs text-fg-muted`;
248
251
  const BODY_CLASS = 'flex';
249
- const LABELS_CLASS = 'flex w-48 shrink-0 flex-col';
252
+ const LABELS_CLASS = 'flex w-64 shrink-0 flex-col';
250
253
  const ROW_BTN_CLASS = 'flex h-8 w-full items-center gap-2 px-2 text-start text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
251
- const ROW_TITLE_CLASS = 'min-w-24 flex-1 truncate';
254
+ const ROW_TITLE_CLASS = 'min-w-28 flex-1 truncate';
252
255
  const ROW_OWNER_CLASS = 'min-w-0 max-w-20 truncate text-xs text-fg-muted';
253
256
  const GROUP_ROW_CLASS = 'flex h-8 items-center gap-2 overflow-hidden whitespace-nowrap bg-surface-band px-2 text-xs font-medium text-fg-muted';
254
257
  const CHART_CLASS = 'relative flex-1';
@@ -459,7 +462,7 @@ export function createGantt(): SomaComponentDefinition {
459
462
  if (value === '') return;
460
463
  if (ganttBarLabelPlace(value, (w / 100) * chartPx) === 'inside') {
461
464
  const box = svgEl('svg', { x: pct(x), y: pct((i / n) * 100), width: pct(w), height: pct(100 / n), overflow: 'hidden' });
462
- const node = svgEl('text', { x: '6', y: '50%', 'dominant-baseline': 'central', 'paint-order': 'stroke', 'stroke-linejoin': 'round', 'data-kit-bar-label': t.id }, LABEL_IN_CLASS);
465
+ const node = svgEl('text', { x: '6', dx: '6', y: '50%', 'dominant-baseline': 'central', 'paint-order': 'stroke', 'stroke-linejoin': 'round', 'data-kit-bar-label': t.id }, LABEL_IN_CLASS);
463
466
  node.textContent = value;
464
467
  box.appendChild(node);
465
468
  svg.appendChild(box);
package/src/data/hero.ts CHANGED
@@ -10,13 +10,17 @@ import { createKitController, joinClass, str } from '../base/shared';
10
10
  import { actionButton, BUTTON_CLASS_TOKENS, classTokens, mk, rowsOf, type ShapeAction } from './shape-util';
11
11
  import { singleOf, urlOf } from './display-util';
12
12
  import { markKitEdge } from '../recipes/surface-edge';
13
+ import { kitShellRecipe } from '../recipes/container';
14
+
15
+ /** 外缘 = 凹槽面的壳配方(容器边,KT-B2) */
16
+ const ROOT_EDGE = kitShellRecipe({ tone: 'sunken', shadow: false });
13
17
 
14
18
  export const KIT_HERO_LAYOUTS = ['center', 'split'] as const;
15
19
  export type KitHeroLayout = (typeof KIT_HERO_LAYOUTS)[number];
16
20
 
17
21
  const KEYS = ['title', 'subtitle', 'description', 'image', 'image_alt', 'actions'] as const;
18
22
 
19
- const ROOT_CLASS = '@container rounded-lg border border-border-subtle bg-surface-sunken px-6 py-10 text-fg';
23
+ const ROOT_CLASS = `@container ${ROOT_EDGE} px-6 py-10 text-fg`;
20
24
  const CENTER_CLASS = 'mx-auto flex max-w-2xl flex-col items-center gap-4 text-center';
21
25
  const SPLIT_CLASS = 'flex flex-col gap-8 @md:flex-row @md:items-center';
22
26
  const TEXT_CLASS = 'flex flex-1 flex-col gap-3';
@@ -99,7 +103,7 @@ export function createHero(): SomaComponentDefinition {
99
103
  action: { payload: { key: { type: 'string' }, item: { type: 'object' } }, desc: '点某个动作按钮;item 是该动作的源对象' },
100
104
  },
101
105
  },
102
- templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
106
+ templateHtml: `<section data-kit-container="card" data-soma-id="root" class="${ROOT_CLASS}"></section>`,
103
107
  controllerFactory: createKitController(() => ({
104
108
  attach(root, api) {
105
109
  const onClick = (event: Event): void => {
@@ -17,16 +17,20 @@ import { classTokens, emptyNode, keyMap, mk, rowsOf, textOf } from './shape-util
17
17
  import { attrEsc, rowKey, safeImgSrc, trapTab } from './d9-util';
18
18
  import { IMAGE_DEFAULT_ZOOM, IMAGE_MAX, IMAGE_ZOOM_STEPS } from './d9-limits';
19
19
  import { mountKitOverlay } from './overlay-portal';
20
+ import { kitShellRecipe } from '../recipes/container';
21
+ import { KIT_DIVIDER_HEAD_CLASS } from '../recipes/divider';
20
22
  import type { OverlayMount } from 'soma-core/behavior';
21
23
 
22
24
  export const KIT_IMAGE_VIEWER_DEFAULT_MAP = Object.freeze({ id: 'id', src: 'src', thumb: 'thumb', title: 'title' });
23
25
 
24
26
  const ROOT_CLASS = 'flex flex-col gap-3 text-sm text-fg';
25
27
  const THUMBS_CLASS = 'grid grid-cols-3 gap-2 @md:grid-cols-4 @xl:grid-cols-6';
26
- const THUMB_CLASS = 'aspect-square overflow-hidden p-0 rounded-lg border border-border-subtle bg-surface-sunken transition-colors hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
28
+ // 缩略图格 = 凹槽面的壳配方(容器边,KT-B2);预览工具条只画朝内的一条分隔线
29
+ const THUMB_EDGE = kitShellRecipe({ tone: 'sunken', shadow: false });
30
+ const THUMB_CLASS = 'aspect-square overflow-hidden p-0 ' + THUMB_EDGE + ' transition-colors hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
27
31
  const THUMB_IMG = 'size-full object-cover';
28
32
  const LAYER_CLASS = 'fixed inset-0 z-50 flex flex-col bg-scrim focus-visible:outline-none';
29
- const BAR_CLASS = 'flex flex-wrap items-center gap-2 border-b border-border-subtle bg-surface-raised px-4 py-2';
33
+ const BAR_CLASS = `flex flex-wrap items-center gap-2 ${KIT_DIVIDER_HEAD_CLASS} bg-surface-raised px-4 py-2`;
30
34
  const BAR_TITLE = 'min-w-0 flex-1 truncate font-medium text-fg';
31
35
  const BAR_TEXT = 'text-xs text-fg-muted';
32
36
  const BAR_BTN = 'inline-flex h-8 min-w-8 items-center justify-center cursor-pointer rounded-md bg-transparent px-2 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press active:opacity-80 disabled:cursor-not-allowed disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
@@ -100,7 +104,7 @@ export function createImageViewer(): SomaComponentDefinition {
100
104
  close: { payload: {}, desc: '关闭预览层' },
101
105
  },
102
106
  },
103
- templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
107
+ templateHtml: `<section data-kit-container="card" data-soma-id="root" class="${ROOT_CLASS}"></section>`,
104
108
  controllerFactory: createKitController((api) => {
105
109
  const P = (): Record<string, unknown> => api.props();
106
110
  let root: HTMLElement | null = null;