soma-kit 0.1.12 → 0.1.13

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 (261) 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 +158 -4
  6. package/spec/generated/kit-page.schema.json +139 -5
  7. package/spec/kit-grammar.json +438 -87
  8. package/spec/kit-grammar.schema.json +11 -3
  9. package/src/app/app-config.ts +83 -5
  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 +17 -5
  15. package/src/app/kit-view-context.ts +163 -14
  16. package/src/app/render-ports.ts +18 -0
  17. package/src/app/server-pages.ts +3 -1
  18. package/src/app/server.ts +40 -3
  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 +57 -12
  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 +49 -0
  34. package/src/base/fab.ts +1 -1
  35. package/src/base/gap-value.ts +148 -0
  36. package/src/base/hint-tips.ts +170 -0
  37. package/src/base/icons.ts +8 -0
  38. package/src/base/illustrations.ts +94 -0
  39. package/src/base/index.ts +27 -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 +23 -12
  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 +9 -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 +24 -22
  58. package/src/base/shared.ts +169 -23
  59. package/src/base/state-panel.ts +346 -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 +63 -33
  66. package/src/base/text.ts +42 -13
  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 -10
  71. package/src/base/view-transition.ts +77 -0
  72. package/src/biz/approval-desk/shell.ts +11 -8
  73. package/src/biz/auth-panel/shell.ts +5 -4
  74. package/src/biz/category-crud/compile.ts +2 -2
  75. package/src/biz/category-crud/shell.ts +2 -1
  76. package/src/biz/checkout-page/compile.ts +2 -1
  77. package/src/biz/checkout-page/shell.ts +4 -3
  78. package/src/biz/import-wizard/shell.ts +2 -1
  79. package/src/biz/link/hub.ts +23 -5
  80. package/src/biz/link/shared.ts +23 -12
  81. package/src/biz/master-sub/compile.ts +102 -10
  82. package/src/biz/master-sub/index.ts +5 -2
  83. package/src/biz/master-sub/shell.ts +95 -18
  84. package/src/biz/multi-board/compile.ts +4 -1
  85. package/src/biz/multi-board/shell.ts +8 -5
  86. package/src/biz/notification-center/shell.ts +6 -4
  87. package/src/biz/page-templates/result-page/shell.ts +2 -1
  88. package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
  89. package/src/biz/record-detail/compile.ts +2 -2
  90. package/src/biz/record-detail/shell.ts +8 -6
  91. package/src/biz/settings-center/compile.ts +2 -1
  92. package/src/biz/settings-center/shell.ts +6 -4
  93. package/src/biz/shared/action-host.ts +6 -0
  94. package/src/biz/shared/compile-helpers.ts +18 -0
  95. package/src/biz/shared/coordinator.ts +7 -30
  96. package/src/biz/shared/index.ts +5 -0
  97. package/src/biz/shared/object-aliases.ts +154 -0
  98. package/src/biz/shared/overlay-compile.ts +239 -0
  99. package/src/biz/shared/overlay-shell.ts +139 -10
  100. package/src/biz/shared/pipes.ts +11 -5
  101. package/src/biz/shared/remove-wire.ts +4 -19
  102. package/src/biz/shared/runtime-hub.ts +10 -0
  103. package/src/biz/single-form/compile.ts +3 -2
  104. package/src/biz/single-form/shell.ts +4 -3
  105. package/src/biz/standard-crud/compile.ts +22 -160
  106. package/src/biz/standard-crud/shell.ts +16 -44
  107. package/src/biz/step-form/shell.ts +5 -5
  108. package/src/cli/kit-cli.ts +138 -13
  109. package/src/cli/kit-init.ts +6 -1
  110. package/src/cli/layout-cli.ts +167 -0
  111. package/src/cli/migrate/index.ts +10 -0
  112. package/src/cli/migrate/migrate.ts +248 -0
  113. package/src/cli/migrate/text-utils.ts +306 -0
  114. package/src/cli/migrate/theme-map.ts +104 -0
  115. package/src/cli/migrate/ts-rules.ts +235 -0
  116. package/src/cli/migrate/types.ts +95 -0
  117. package/src/cli/migrate/view-skeleton.ts +159 -0
  118. package/src/cli/migrate/yaml-report.ts +376 -0
  119. package/src/cli/migrate/yaml-rules.ts +465 -0
  120. package/src/cli/view-writes.ts +69 -60
  121. package/src/compile/closed-set.ts +65 -4
  122. package/src/compile/compile-page.ts +51 -7
  123. package/src/compile/component-candidates.ts +12 -1
  124. package/src/compile/layout-lint/engine.ts +82 -0
  125. package/src/compile/layout-lint/index.ts +55 -0
  126. package/src/compile/layout-lint/rules-composition.ts +218 -0
  127. package/src/compile/layout-lint/rules-form.ts +192 -0
  128. package/src/compile/layout-lint/rules-table.ts +194 -0
  129. package/src/compile/layout-lint/score.ts +52 -0
  130. package/src/compile/layout-lint/types.ts +51 -0
  131. package/src/compile/remove-guard.ts +10 -7
  132. package/src/compile/styles.ts +36 -8
  133. package/src/compile/types.ts +13 -1
  134. package/src/compile/view-check.ts +149 -16
  135. package/src/data/amount-breakdown.ts +6 -1
  136. package/src/data/approval-flow.ts +1 -1
  137. package/src/data/assignment-picker.ts +53 -27
  138. package/src/data/async-result-panel.ts +49 -3
  139. package/src/data/breadcrumbs.ts +3 -2
  140. package/src/data/calendar.ts +2 -2
  141. package/src/data/carousel.ts +8 -6
  142. package/src/data/chart.ts +141 -10
  143. package/src/data/checklist.ts +18 -5
  144. package/src/data/code-view.ts +8 -4
  145. package/src/data/comment-thread.ts +2 -2
  146. package/src/data/confirm-dialog.ts +71 -18
  147. package/src/data/context-menu.ts +3 -3
  148. package/src/data/dock.ts +1 -1
  149. package/src/data/embed.ts +231 -29
  150. package/src/data/field-mapper.ts +4 -4
  151. package/src/data/flow-editor-contract.ts +7 -0
  152. package/src/data/flow-editor.ts +25 -9
  153. package/src/data/flow-node-options.ts +33 -3
  154. package/src/data/gantt.ts +5 -2
  155. package/src/data/hero.ts +2 -1
  156. package/src/data/image-viewer.ts +7 -4
  157. package/src/data/index.ts +6 -1
  158. package/src/data/item-list.ts +18 -10
  159. package/src/data/kanban.ts +39 -10
  160. package/src/data/media-grid.ts +6 -1
  161. package/src/data/mega-menu.ts +6 -4
  162. package/src/data/menu-dom.ts +4 -2
  163. package/src/data/menu.ts +45 -13
  164. package/src/data/mockup.ts +8 -4
  165. package/src/data/modal-dialog.ts +29 -9
  166. package/src/data/navbar.ts +5 -5
  167. package/src/data/notice-list.ts +268 -0
  168. package/src/data/notify-renderer.ts +21 -6
  169. package/src/data/object-form.ts +354 -48
  170. package/src/data/outcome-watch.ts +61 -2
  171. package/src/data/pager.ts +17 -7
  172. package/src/data/permission-matrix.ts +33 -11
  173. package/src/data/permission-tree.ts +47 -22
  174. package/src/data/pricing-table.ts +21 -11
  175. package/src/data/prompt-dialog.ts +165 -0
  176. package/src/data/reaction-bar.ts +6 -4
  177. package/src/data/record-card.ts +23 -2
  178. package/src/data/record-picker.ts +13 -7
  179. package/src/data/result-panel.ts +4 -2
  180. package/src/data/rich-text.ts +17 -1
  181. package/src/data/row-editor.ts +79 -26
  182. package/src/data/rule-builder.ts +8 -8
  183. package/src/data/shape-util.ts +23 -9
  184. package/src/data/stat-group.ts +170 -29
  185. package/src/data/static-lazy.ts +1 -0
  186. package/src/data/static-registry.ts +2 -0
  187. package/src/data/steps.ts +8 -3
  188. package/src/data/survey.ts +3 -3
  189. package/src/data/system-switcher.ts +1 -1
  190. package/src/data/text-action-button.ts +17 -0
  191. package/src/data/timeline.ts +17 -6
  192. package/src/data/tour-guide.ts +1 -1
  193. package/src/data/transfer.ts +36 -16
  194. package/src/data/tree-table.ts +62 -36
  195. package/src/data/tree.ts +22 -2
  196. package/src/data/virtual-rows.ts +19 -10
  197. package/src/data/wrapped-candidates.ts +10 -0
  198. package/src/frames/page-bar.ts +14 -13
  199. package/src/frames/page-status.ts +7 -5
  200. package/src/frames/shared.ts +15 -10
  201. package/src/frames/split-frame/shell.ts +1 -1
  202. package/src/frames/tabs-frame/shell.ts +2 -1
  203. package/src/frames/tabs-frame/wiring.ts +1 -0
  204. package/src/frames/top-main-frame.ts +2 -2
  205. package/src/frames/workspace-frame/extras.ts +1 -1
  206. package/src/frames/workspace-frame/shell.ts +2 -2
  207. package/src/frames/workspace-frame/view.ts +141 -33
  208. package/src/generated/kit-grammar-runtime.ts +239 -55
  209. package/src/i18n/kit-text.ts +63 -4
  210. package/src/i18n/resolve-text-refs.ts +22 -6
  211. package/src/object-renderer/arrange.ts +42 -8
  212. package/src/object-renderer/collection-parts.ts +241 -60
  213. package/src/object-renderer/collection-table.ts +109 -5
  214. package/src/object-renderer/collection.ts +174 -36
  215. package/src/object-renderer/compile-data.ts +28 -3
  216. package/src/object-renderer/defaults.ts +30 -2
  217. package/src/object-renderer/display-checks.ts +1 -1
  218. package/src/object-renderer/emit-events.ts +43 -9
  219. package/src/object-renderer/emit-static.ts +370 -30
  220. package/src/object-renderer/form-detail.ts +1 -2
  221. package/src/object-renderer/form-notify.ts +45 -0
  222. package/src/object-renderer/layout-facts.ts +386 -0
  223. package/src/object-renderer/layout-plan.ts +132 -0
  224. package/src/object-renderer/layout-plan.types.ts +22 -0
  225. package/src/object-renderer/parts.ts +252 -1
  226. package/src/object-renderer/render-object.ts +54 -6
  227. package/src/object-renderer/request-actions.ts +4 -2
  228. package/src/object-renderer/skeleton.ts +58 -19
  229. package/src/object-renderer/table-actions.ts +135 -27
  230. package/src/object-renderer/table-tools.ts +12 -11
  231. package/src/object-renderer/types.ts +78 -7
  232. package/src/object-renderer/view-binding.ts +205 -8
  233. package/src/page-target/intent-schema.ts +11 -0
  234. package/src/page-target/target.ts +5 -1
  235. package/src/recipes/container.ts +46 -1
  236. package/src/recipes/control.ts +70 -12
  237. package/src/recipes/index.ts +49 -0
  238. package/src/recipes/nowrap.ts +16 -0
  239. package/src/recipes/overlay.ts +75 -17
  240. package/src/recipes/placeholder.ts +79 -0
  241. package/src/recipes/rail-grid.ts +45 -0
  242. package/src/recipes/slot-align.ts +56 -0
  243. package/src/recipes/state.ts +34 -5
  244. package/src/recipes/status.ts +139 -0
  245. package/src/recipes/surface.ts +40 -0
  246. package/src/recipes/table-row.ts +40 -3
  247. package/src/recipes/title-row.ts +37 -0
  248. package/src/recipes/typography.ts +13 -1
  249. package/src/shared/confirm-decl.ts +118 -0
  250. package/src/shared/envelope.ts +2 -2
  251. package/src/shared/paged-list-adapter.ts +15 -240
  252. package/src/shared/theme-runtime-shared.ts +6 -1
  253. package/src/theme/index.ts +1 -0
  254. package/src/theme/kit-theme-text.ts +1 -1
  255. package/src/theme/kit-theme.css +372 -12
  256. package/src/theme/kit-theme.tpl +372 -12
  257. package/src/theme/nine-dim-structure.ts +177 -7
  258. package/src/theme/surface-layers.ts +4 -0
  259. package/src/theme/theme-tokens.ts +53 -13
  260. package/src/theme/theme-types.ts +32 -0
  261. package/src/biz/shared/remove-key.ts +0 -6
@@ -0,0 +1,150 @@
1
+ // 置灰原因气泡(动作的 disabledReason 的呈现,工具栏 Button / 行操作 KitTableActions 共用,只此一份实现)。
2
+ //
3
+ // 规则(页面只声明「原因从哪来」,怎么显示由这里写死):
4
+ // - 动作置灰且原因非空:控件不用原生 disabled(原生禁用的按钮拿不到焦点、读屏与键盘用户看不到原因),
5
+ // 只留 aria-disabled="true",保持可聚焦;原因经 role=tooltip 的气泡在悬停 / 聚焦时显示,控件带 aria-describedby 指向它,Esc 隐藏;
6
+ // - 点击 / Enter / Space 不抛事件由各控制器自己的置灰判断保证(本文件不接事件);
7
+ // - 气泡显示时经 core 浮层端口挂到浮层根(popup.ts 的 syncAnchored,与 Popover 同一机制),不被表格滚动容器 / overflow 祖先裁切;
8
+ // 收起时放回原位;端口不可用时退回原位绝对定位;
9
+ // - 原因为空 / 动作未置灰:不建气泡、不改 aria-describedby,行为与没有该声明时完全相同。
10
+ // 文字一律 textContent;气泡外观取 popup 底座的 tooltip 类(去掉 pointer-events-none,浮层根里需要 pointer-events-auto)。
11
+
12
+ import { classCandidates } from './class-candidates';
13
+ import {
14
+ KIT_POPUP_PLACE_CLASS_CANDIDATES, POPUP_TIP_BASE, POPUP_TIP_HIDDEN_CLASS, POPUP_TIP_PREF, popPlaceClass, releaseDropdown, syncAnchored,
15
+ type PopPlace,
16
+ } from './popup';
17
+ import { addIdToken, nextUid, removeIdToken } from './shared';
18
+
19
+ const REASON_TIP_BASE = POPUP_TIP_BASE.split(/\s+/).filter((t) => t !== 'pointer-events-none').join(' ');
20
+ const reasonTipClass = (place: PopPlace): string => `${REASON_TIP_BASE} ${popPlaceClass(place, 1)}`;
21
+
22
+ export const KIT_REASON_TIP_CLASS_CANDIDATES: readonly string[] = classCandidates(
23
+ POPUP_TIP_HIDDEN_CLASS, REASON_TIP_BASE, KIT_POPUP_PLACE_CLASS_CANDIDATES, 'pointer-events-auto',
24
+ );
25
+
26
+ interface TipState {
27
+ anchor: HTMLElement;
28
+ tip: HTMLElement;
29
+ shown: boolean;
30
+ show: () => void;
31
+ hide: () => void;
32
+ onKey: (event: KeyboardEvent) => void;
33
+ }
34
+
35
+ const STATES = new WeakMap<HTMLElement, TipState>();
36
+ const LIVE = new Set<TipState>();
37
+
38
+ // aria-describedby 令牌的合并 / 摘除只用 shared 的 addIdToken / removeIdToken(withTooltip 同一份)
39
+ const addDescribedBy = (el: Element, id: string): void => addIdToken(el, 'aria-describedby', id);
40
+ const removeDescribedBy = (el: Element, id: string): void => removeIdToken(el, 'aria-describedby', id);
41
+
42
+ function release(state: TipState): void {
43
+ const { anchor, tip } = state;
44
+ anchor.removeEventListener('mouseenter', state.show);
45
+ anchor.removeEventListener('mouseleave', state.hide);
46
+ anchor.removeEventListener('focusin', state.show);
47
+ anchor.removeEventListener('focusout', state.hide);
48
+ anchor.removeEventListener('keydown', state.onKey);
49
+ removeDescribedBy(anchor, tip.id);
50
+ releaseDropdown(tip, false);
51
+ tip.remove();
52
+ STATES.delete(anchor);
53
+ LIVE.delete(state);
54
+ }
55
+
56
+ /**
57
+ * 给 anchor 挂 / 更新 / 摘掉原因气泡:reason 非空 → 建(已有则更新文字);空 → 摘掉。幂等,可在每次渲染调用。
58
+ * inside:气泡占位节点放在 anchor 里面(Button 自己是控制器根,不能往它的宿主里插兄弟);缺省放在 anchor 之后。
59
+ */
60
+ export function syncReasonTip(anchor: HTMLElement, reason: string, inside = false): void {
61
+ const text = reason.trim();
62
+ const existing = STATES.get(anchor);
63
+ if (text === '') {
64
+ if (existing !== undefined) release(existing);
65
+ return;
66
+ }
67
+ if (existing !== undefined) {
68
+ existing.tip.textContent = text;
69
+ addDescribedBy(anchor, existing.tip.id);
70
+ return;
71
+ }
72
+ const doc = anchor.ownerDocument;
73
+ const tip = doc.createElement('span');
74
+ tip.id = nextUid('kit-reason');
75
+ tip.setAttribute('role', 'tooltip');
76
+ tip.className = POPUP_TIP_HIDDEN_CLASS;
77
+ tip.textContent = text;
78
+ if (!inside && anchor.parentNode !== null) anchor.parentNode.insertBefore(tip, anchor.nextSibling);
79
+ else anchor.appendChild(tip);
80
+ const state: TipState = {
81
+ anchor,
82
+ tip,
83
+ shown: false,
84
+ show: () => {
85
+ state.shown = true;
86
+ syncAnchored(tip, true, anchor, POPUP_TIP_PREF, reasonTipClass);
87
+ },
88
+ hide: () => {
89
+ if (!state.shown) return;
90
+ state.shown = false;
91
+ syncAnchored(tip, false, anchor, POPUP_TIP_PREF, () => '');
92
+ },
93
+ onKey: (event) => {
94
+ if (event.key !== 'Escape' || !state.shown) return;
95
+ // 先收气泡:这次 Esc 只用来关提示,不连带关闭外层对话框
96
+ event.stopPropagation();
97
+ state.hide();
98
+ },
99
+ };
100
+ anchor.addEventListener('mouseenter', state.show);
101
+ anchor.addEventListener('mouseleave', state.hide);
102
+ anchor.addEventListener('focusin', state.show);
103
+ anchor.addEventListener('focusout', state.hide);
104
+ anchor.addEventListener('keydown', state.onKey);
105
+ addDescribedBy(anchor, tip.id);
106
+ STATES.set(anchor, state);
107
+ LIVE.add(state);
108
+ }
109
+
110
+ /** 摘掉 anchor 上的原因气泡(没有则什么也不做) */
111
+ export function releaseReasonTip(anchor: HTMLElement): void {
112
+ const state = STATES.get(anchor);
113
+ if (state !== undefined) release(state);
114
+ }
115
+
116
+ /** anchor 上当前是否挂着气泡(按需挂载的委托据此判断「刚挂上、要立刻显示」还是「已有、交给自带的悬停 / 聚焦监听」) */
117
+ export function hasReasonTip(anchor: HTMLElement): boolean {
118
+ return STATES.has(anchor);
119
+ }
120
+
121
+ /** 立刻显示 anchor 上已挂的气泡(按需挂载时,触发它的悬停 / 聚焦事件已过,自带监听来不及接,要补一次显示;没挂则什么也不做) */
122
+ export function showReasonTip(anchor: HTMLElement): void {
123
+ STATES.get(anchor)?.show();
124
+ }
125
+
126
+ /** 摘掉 scope 内全部锚点的原因气泡(整片重画前调用;气泡可能正挂在浮层根里,随旧锚点丢弃会成孤儿) */
127
+ export function releaseReasonTipsIn(scope: Element): void {
128
+ for (const s of [...LIVE]) if (scope.contains(s.anchor)) release(s);
129
+ }
130
+
131
+ // ── 应用组件的公开提示 API ─────────────────────────────────────
132
+
133
+ /** 应用组件用 `kitTooltip` 时并入候选类的气泡 / 定位类(与置灰原因气泡同一份) */
134
+ export const KIT_APP_TOOLTIP_CLASS_CANDIDATES: readonly string[] = KIT_REASON_TIP_CLASS_CANDIDATES;
135
+
136
+ export interface KitTooltipOptions {
137
+ /** 气泡占位节点放进 el 里面(el 是 input / img 等不能有子节点的元素时不要用);缺省放在 el 之后 */
138
+ inside?: boolean;
139
+ }
140
+
141
+ /**
142
+ * 给元素挂 / 更新 / 摘掉悬停提示(替代 `title=`),返回清理函数:
143
+ * 悬停与聚焦显示,移开 / 失焦 / Esc 隐藏(Esc 只关提示,不连带关外层对话框);el 带 `aria-describedby` 指向气泡(与已有令牌合并,摘掉时只摘自己的);
144
+ * 显示时经浮层端口挂到浮层根,不被 overflow 祖先裁切。再次调用同一元素 = 更新文字(幂等);`text` 为空 = 摘掉。
145
+ * 提示只写补充说明;el 要能聚焦(可聚焦控件或自带 tabindex),键盘才读得到。整块重画前调清理函数或 `releaseReasonTipsIn`。
146
+ */
147
+ export function kitTooltip(el: HTMLElement, text: string, opts: KitTooltipOptions = {}): () => void {
148
+ syncReasonTip(el, text, opts.inside === true);
149
+ return () => releaseReasonTip(el);
150
+ }
@@ -18,45 +18,46 @@ import {
18
18
 
19
19
  // ── 类串(整串字面量,不拼接)─────────────────────────────────
20
20
 
21
- const SEG_ROOT = 'inline-flex items-center gap-0.5 rounded-lg bg-surface-sunken p-0.5';
22
- const SEG_ROOT_BLOCK = 'flex w-full items-center gap-0.5 rounded-lg bg-surface-sunken p-0.5';
21
+ // 2026-11-17(评审 K7):分段控件至多一层底色、无外描边——轨道无底无框,只有选中段是主色柔底(不再有「轨道底 + 白色滑块 + 阴影」的多层)
22
+ const SEG_ROOT = 'inline-flex items-center gap-0.5';
23
+ const SEG_ROOT_BLOCK = 'flex w-full items-center gap-0.5';
23
24
  const SEG_ITEM: Record<KitSize, { idle: string; on: string; off: string }> = {
24
25
  sm: {
25
- idle: 'inline-flex h-7 min-w-0 flex-1 cursor-pointer items-center justify-center rounded-md px-2.5 text-xs font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
26
- on: 'inline-flex h-7 min-w-0 flex-1 cursor-pointer items-center justify-center rounded-md bg-surface px-2.5 text-xs font-medium text-fg shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
27
- off: 'inline-flex h-7 min-w-0 flex-1 cursor-not-allowed items-center justify-center rounded-md px-2.5 text-xs font-medium text-fg-subtle opacity-60',
26
+ idle: 'inline-flex h-6 min-w-0 flex-1 whitespace-nowrap cursor-pointer items-center justify-center rounded-md px-2.5 text-xs font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
27
+ on: 'inline-flex h-6 min-w-0 flex-1 whitespace-nowrap cursor-pointer items-center justify-center rounded-md bg-primary-soft px-2.5 text-xs font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
28
+ off: 'inline-flex h-6 min-w-0 flex-1 whitespace-nowrap cursor-not-allowed items-center justify-center rounded-md px-2.5 text-xs font-medium text-fg-subtle opacity-60',
28
29
  },
29
30
  md: {
30
- idle: 'inline-flex h-8 min-w-0 flex-1 cursor-pointer items-center justify-center rounded-md px-3 text-sm font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
31
- on: 'inline-flex h-8 min-w-0 flex-1 cursor-pointer items-center justify-center rounded-md bg-surface px-3 text-sm font-medium text-fg shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
32
- off: 'inline-flex h-8 min-w-0 flex-1 cursor-not-allowed items-center justify-center rounded-md px-3 text-sm font-medium text-fg-subtle opacity-60',
31
+ idle: 'inline-flex h-8 min-w-0 flex-1 whitespace-nowrap cursor-pointer items-center justify-center rounded-md px-3 text-sm font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
32
+ on: 'inline-flex h-8 min-w-0 flex-1 whitespace-nowrap cursor-pointer items-center justify-center rounded-md bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
33
+ off: 'inline-flex h-8 min-w-0 flex-1 whitespace-nowrap cursor-not-allowed items-center justify-center rounded-md px-3 text-sm font-medium text-fg-subtle opacity-60',
33
34
  },
34
35
  lg: {
35
- idle: 'inline-flex h-9 min-w-0 flex-1 cursor-pointer items-center justify-center rounded-md px-4 text-base font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
36
- on: 'inline-flex h-9 min-w-0 flex-1 cursor-pointer items-center justify-center rounded-md bg-surface px-4 text-base font-medium text-fg shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
37
- off: 'inline-flex h-9 min-w-0 flex-1 cursor-not-allowed items-center justify-center rounded-md px-4 text-base font-medium text-fg-subtle opacity-60',
36
+ idle: 'inline-flex h-10 min-w-0 flex-1 whitespace-nowrap cursor-pointer items-center justify-center rounded-md px-4 text-base font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
37
+ on: 'inline-flex h-10 min-w-0 flex-1 whitespace-nowrap cursor-pointer items-center justify-center rounded-md bg-primary-soft px-4 text-base font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
38
+ off: 'inline-flex h-10 min-w-0 flex-1 whitespace-nowrap cursor-not-allowed items-center justify-center rounded-md px-4 text-base font-medium text-fg-subtle opacity-60',
38
39
  },
39
40
  };
40
41
 
41
- const SEG_ROOT_V = 'inline-flex flex-col items-stretch gap-0.5 rounded-lg bg-surface-sunken p-0.5';
42
- const SEG_ROOT_BLOCK_V = 'flex w-full flex-col items-stretch gap-0.5 rounded-lg bg-surface-sunken p-0.5';
42
+ const SEG_ROOT_V = 'inline-flex flex-col items-stretch gap-0.5';
43
+ const SEG_ROOT_BLOCK_V = 'flex w-full flex-col items-stretch gap-0.5';
43
44
  const TOG_ROOT = 'inline-flex flex-wrap items-center gap-2';
44
45
  const TOG_ROOT_V = 'inline-flex flex-col items-stretch gap-2';
45
46
  const OPT_ICON = 'shrink-0';
46
47
  const OPT_GAP = 'gap-1.5';
47
48
  const TOG_ITEM: Record<KitSize, { idle: string; on: string; off: string }> = {
48
49
  sm: {
49
- idle: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-2.5 text-sm text-fg transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
50
- on: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md border border-primary bg-primary-soft px-2.5 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
51
- off: 'inline-flex h-8 cursor-not-allowed items-center justify-center rounded-md border border-border bg-surface-sunken px-2.5 text-sm text-fg-subtle opacity-60',
50
+ idle: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-2.5 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
51
+ on: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md border border-primary bg-primary-soft px-2.5 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
52
+ off: 'inline-flex h-6 cursor-not-allowed items-center justify-center rounded-md border border-border bg-surface-sunken px-2.5 text-sm text-fg-subtle opacity-60',
52
53
  },
53
54
  md: {
54
- idle: 'inline-flex h-9 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-3 text-sm text-fg transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
55
- on: 'inline-flex h-9 cursor-pointer items-center justify-center rounded-md border border-primary bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
56
- off: 'inline-flex h-9 cursor-not-allowed items-center justify-center rounded-md border border-border bg-surface-sunken px-3 text-sm text-fg-subtle opacity-60',
55
+ idle: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-3 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
56
+ on: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md border border-primary bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
57
+ off: 'inline-flex h-8 cursor-not-allowed items-center justify-center rounded-md border border-border bg-surface-sunken px-3 text-sm text-fg-subtle opacity-60',
57
58
  },
58
59
  lg: {
59
- idle: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-4 text-base text-fg transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
60
+ idle: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-4 text-base text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
60
61
  on: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md border border-primary bg-primary-soft px-4 text-base font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
61
62
  off: 'inline-flex h-10 cursor-not-allowed items-center justify-center rounded-md border border-border bg-surface-sunken px-4 text-base text-fg-subtle opacity-60',
62
63
  },
@@ -210,7 +211,7 @@ export function createSegmentedView(): KitView {
210
211
  const off = disabled || o?.disabled === true;
211
212
  b.className = joinClass(off ? SEG_ITEM[size].off : on ? SEG_ITEM[size].on : SEG_ITEM[size].idle, o?.icon !== undefined && o.label !== '' ? OPT_GAP : '');
212
213
  b.setAttribute('aria-checked', on ? 'true' : 'false');
213
- setKitFace(b, on && !off ? 'raised' : null); // 只有选中的滑块段有底色 + shadow-sm(质感经合成槽叠进去);未选中段是透明的,无面
214
+ setKitFace(b, null); // 选中段是主色柔底、其余透明,整组无轨道无阴影,不标 raised(不叠质感阴影)
214
215
  if (off) b.setAttribute('aria-disabled', 'true');
215
216
  else b.removeAttribute('aria-disabled');
216
217
  b.tabIndex = !off && b.dataset.key === stop ? 0 : -1;
@@ -257,7 +258,8 @@ export function createToggleView(): KitView {
257
258
  render(root, p) {
258
259
  const options = optionsOf(p.options);
259
260
  const size = sizeOf(p.size);
260
- const disabled = bool(p.disabled) || bool(p.readonly);
261
+ // 状态呈现表:readonly 不置灰(仍画 on / idle 原样,只是不响应点击,见 onClick 与 locked);只有 disabled 画成禁用形态
262
+ const disabled = bool(p.disabled);
261
263
  const sig = optionsKey(options);
262
264
  if (sig !== root.dataset.kitTogKey) {
263
265
  root.dataset.kitTogKey = sig;
@@ -19,6 +19,9 @@ import {
19
19
  popupTipClass, showPopupFitted,
20
20
  } from './popup';
21
21
  import { classCandidates } from './class-candidates';
22
+ import { leaveAnchored, unmarkAnchored } from './anchored-layer';
23
+ import type { KitLeaveHandle } from './overlay-runtime';
24
+ import { withKitViewTransition } from './view-transition';
22
25
  import { kitBusyOf, onKitActionBusy } from './action-busy';
23
26
  import { deniedBy, registerLivePermissionGate } from './permission-gate';
24
27
  import { kitText } from '../i18n/kit-text';
@@ -75,7 +78,7 @@ export function withInvalid(base: string, invalid: boolean): string {
75
78
  return invalid ? `${base} ${FIELD_INVALID_CLASS}` : base;
76
79
  }
77
80
 
78
- export const KIT_SPINNER_CLASS = 'inline-block h-4 w-4 animate-spin rounded-full border-2 border-border border-t-primary';
81
+ export const KIT_SPINNER_CLASS = 'inline-block h-4 w-4 motion-safe:animate-spin rounded-full border-2 border-border border-t-primary';
79
82
 
80
83
  // ── props 读取 ────────────────────────────────────────────────
81
84
 
@@ -115,6 +118,8 @@ export interface KitOption {
115
118
  label: string;
116
119
  /** 仅 Tag 读:命中该选项时优先于 tone prop */
117
120
  tone?: KitTone;
121
+ /** 选项写了 `tone: unknown`(未知 / 无法判断):tone 按 neutral 归一(不认识 unknown 的组件照 neutral 画),Tag 读此标记画虚线未知外观 */
122
+ unknown?: boolean;
118
123
  disabled?: boolean;
119
124
  /** Radio / Checkbox 读:选项图标(短字符,emoji 或符号);label 为空时是纯图标选项 */
120
125
  icon?: string;
@@ -163,13 +168,15 @@ export function optionsOf(raw: unknown): KitOption[] {
163
168
  const icon = typeof rec.icon === 'string' ? rec.icon : '';
164
169
  // 带 icon 又没写 label = 纯图标选项(label 为空,可访问名取 aria_label,缺省取 value)
165
170
  const label = rec.label !== undefined && rec.label !== null ? String(rec.label) : icon !== '' ? '' : String(rec.value ?? '');
166
- const tone = toneOf(rec.tone, null);
171
+ const unknownTone = rec.tone === 'unknown';
172
+ const tone = unknownTone ? 'neutral' : toneOf(rec.tone, null);
167
173
  push({
168
174
  value: rec.value,
169
175
  label,
170
176
  ...(icon !== '' ? { icon } : {}),
171
177
  ...(typeof rec.aria_label === 'string' && rec.aria_label !== '' ? { aria_label: rec.aria_label } : {}),
172
178
  ...(tone ? { tone } : {}),
179
+ ...(unknownTone ? { unknown: true } : {}),
173
180
  ...(rec.disabled === true ? { disabled: true } : {}),
174
181
  });
175
182
  }
@@ -246,6 +253,11 @@ export interface DisplayResult {
246
253
  * 铁律:只产出文字。有 options 时按选项取 label(命中不到则显示原值);
247
254
  * 没有 options 时 bool、0/1 一律显示原值文字,不变成开关或色块。
248
255
  */
256
+ /** 空值判定(displayOf 与 Tag 共用唯一一份):null / undefined / '' / 空数组 */
257
+ export function valueIsEmpty(value: unknown): boolean {
258
+ return value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0);
259
+ }
260
+
249
261
  export function displayOf(
250
262
  value: unknown,
251
263
  options: readonly KitOption[],
@@ -253,7 +265,9 @@ export function displayOf(
253
265
  locale: string,
254
266
  placeholder: string,
255
267
  ): DisplayResult {
256
- if (value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0)) {
268
+ // 显式空串 '' 是「有意留白」:渲染为空白;null / undefined / 空数组仍按占位(缺省「-」)
269
+ if (value === '') return { text: '', option: null };
270
+ if (valueIsEmpty(value)) {
257
271
  return { text: placeholder, option: null };
258
272
  }
259
273
  if (options.length > 0) {
@@ -286,19 +300,111 @@ export function setAttr(el: Element, name: string, value: string): void {
286
300
  else el.setAttribute(name, value);
287
301
  }
288
302
 
289
- /** 标签关联、可访问名与程序化无障碍校验关联:`id` / `aria-label` / `name` / `aria-required` / `aria-invalid` / `aria-describedby` / `aria-errormessage` */
303
+ /** 上一次由 applyCommon 写进 aria-describedby 的 id 串(合并时只替换自己写的那部分,不抹掉控件自带的说明 id) */
304
+ const APPLIED_DESCRIBEDBY = new WeakMap<Element, string[]>();
305
+
306
+ /** 空白分隔的 id 串拆成去重的令牌表 */
307
+ function idRefTokens(raw: string): string[] {
308
+ return Array.from(new Set(raw.split(/\s+/).filter((t) => t !== '')));
309
+ }
310
+
311
+ /** 在空白分隔的 id 引用属性里加入一个令牌(已在则不动) */
312
+ export function addIdToken(el: Element, attr: string, id: string): void {
313
+ const tokens = idRefTokens(el.getAttribute(attr) ?? '');
314
+ if (id === '' || tokens.includes(id)) return;
315
+ el.setAttribute(attr, [...tokens, id].join(' '));
316
+ }
317
+
318
+ /** 从空白分隔的 id 引用属性里摘掉一个令牌;摘空则移除属性 */
319
+ export function removeIdToken(el: Element, attr: string, id: string): void {
320
+ const tokens = idRefTokens(el.getAttribute(attr) ?? '');
321
+ if (!tokens.includes(id)) return;
322
+ const rest = tokens.filter((t) => t !== id);
323
+ if (rest.length > 0) el.setAttribute(attr, rest.join(' '));
324
+ else el.removeAttribute(attr);
325
+ }
326
+
327
+ /**
328
+ * 合并写 aria-describedby:保留元素上已有、但不是上次 applyCommon 写入的令牌(控件自带的说明节点),
329
+ * 再并入这次的令牌;重复调用不累积。
330
+ */
331
+ function mergeDescribedby(el: Element, next: string): void {
332
+ const prevOwn = new Set(APPLIED_DESCRIBEDBY.get(el) ?? []);
333
+ const keep = idRefTokens(el.getAttribute('aria-describedby') ?? '').filter((t) => !prevOwn.has(t));
334
+ const own = idRefTokens(next);
335
+ APPLIED_DESCRIBEDBY.set(el, own);
336
+ const merged = [...keep, ...own.filter((t) => !keep.includes(t))];
337
+ if (merged.length > 0) el.setAttribute('aria-describedby', merged.join(' '));
338
+ else el.removeAttribute('aria-describedby');
339
+ }
340
+
341
+ /**
342
+ * 标签关联、可访问名与程序化无障碍校验关联:`id` / `aria-label` / `aria-labelledby` / `name` / `aria-required` / `aria-invalid` / `aria-describedby`(合并)/ `aria-errormessage`。
343
+ * `labelledby` 只在 props 里带了该键(契约声明过)时才写 / 清,避免只传部分键的调用方误清外部写好的名字。
344
+ */
290
345
  export function applyCommon(el: Element, p: KitProps): void {
291
346
  setAttr(el, 'id', str(p.id));
292
- setAttr(el, 'aria-label', str(p.aria_label));
293
347
  setAttr(el, 'name', str(p.name));
348
+ applyAria(el, p);
349
+ }
350
+
351
+ /** applyCommon 去掉 id / name 的部分:名字、标签关联、校验态与说明关联 */
352
+ function applyAria(el: Element, p: KitProps): void {
353
+ setAttr(el, 'aria-label', str(p.aria_label));
354
+ if ('labelledby' in p || 'aria_labelledby' in p) setAttr(el, 'aria-labelledby', str(p.aria_labelledby, str(p.labelledby)));
355
+ // WAI-ARIA 1.2:aria-required / aria-invalid / aria-errormessage 不属于 role=group,写了是无效 ARIA;
356
+ // group 根只留名字与说明关联(+ 一个 data-kit-invalid 标记供表单滚动聚焦),校验态落到组内真正承载值的控件上(见 applyGroupA11y)
357
+ if (el.getAttribute('role') === 'group') {
358
+ el.removeAttribute('aria-required');
359
+ el.removeAttribute('aria-invalid');
360
+ el.removeAttribute('aria-errormessage');
361
+ setAttr(el, KIT_INVALID_MARK, bool(p.invalid) ? 'true' : '');
362
+ } else {
363
+ applyValidity(el, p);
364
+ el.removeAttribute(KIT_INVALID_MARK);
365
+ }
366
+ mergeDescribedby(el, str(p.aria_describedby, str(p.describedby)));
367
+ }
368
+
369
+ /** group 根上的无效标记(ARIA 不允许 group 带 aria-invalid;表单据此找首个出错字段) */
370
+ export const KIT_INVALID_MARK = 'data-kit-invalid';
371
+
372
+ /** 必填 / 无效 / 错误消息关联三个校验属性(只给支持它们的角色:原生输入、radiogroup、combobox、textbox 等) */
373
+ function applyValidity(el: Element, p: KitProps): void {
294
374
  if (bool(p.required)) el.setAttribute('aria-required', 'true');
295
375
  else el.removeAttribute('aria-required');
296
376
  if (bool(p.invalid)) el.setAttribute('aria-invalid', 'true');
297
377
  else el.removeAttribute('aria-invalid');
298
- setAttr(el, 'aria-describedby', str(p.aria_describedby, str(p.describedby)));
299
378
  setAttr(el, 'aria-errormessage', str(p.aria_errormessage, str(p.errormessage)));
300
379
  }
301
380
 
381
+ /**
382
+ * 组类控件(无单一可标注原生元素:radiogroup / group / 自绘组合)的校验与名字写面:
383
+ * 与 applyCommon 同一套 aria 属性,但不碰 id / name(组根不占 id,id 给第一个可聚焦控件)。
384
+ * 组根是 role=group 时(多选组、验证码格组等),必填 / 无效 / 错误消息写到 `targets`(组内承载值的输入),
385
+ * 说明 / 错误节点仍经 aria-describedby 挂在组根上;radiogroup 根支持这些属性,直接写根。
386
+ */
387
+ export function applyGroupA11y(el: Element, p: KitProps, targets: Iterable<Element> = []): void {
388
+ applyAria(el, p);
389
+ if (el.getAttribute('role') !== 'group') return;
390
+ for (const target of targets) applyValidity(target, p);
391
+ }
392
+
393
+ /** 表单传给字段控件的无障碍 props 键:任一有值就说明该控件被当作表单字段用 */
394
+ const FIELD_A11Y_KEYS = ['labelledby', 'aria_labelledby', 'describedby', 'aria_describedby', 'required', 'invalid'] as const;
395
+
396
+ /**
397
+ * 复合字段控件(上传、取色、选记录、穿梭等:根不是原生可标注元素)的字段无障碍写面:
398
+ * 被当作表单字段用(props 里带了标签 / 说明 / 必填 / 无效)时根写 role=group + 名字 + 说明关联,必填 / 无效落到 `targets`;
399
+ * 没有这些 props 时不加角色(与单独使用时的原有输出一致),并清掉上一轮写的。
400
+ */
401
+ export function applyCompositeField(el: Element, p: KitProps, targets: Iterable<Element> = []): void {
402
+ const used = FIELD_A11Y_KEYS.some((k) => { const v = p[k]; return v !== undefined && v !== null && v !== '' && v !== false; });
403
+ if (used) el.setAttribute('role', 'group');
404
+ else if (el.getAttribute('role') === 'group') el.removeAttribute('role');
405
+ applyGroupA11y(el, { ...p, aria_label: '' }, targets);
406
+ }
407
+
302
408
  /** 禁用态:原生 disabled + aria-disabled 同写 */
303
409
  export function applyDisabled(el: Element, disabled: boolean): void {
304
410
  setBoolAttr(el, 'disabled', disabled);
@@ -354,6 +460,12 @@ export interface KitView {
354
460
  * (render 里用 `kitBusyOf(p)` 取状态落到触发钮)。
355
461
  */
356
462
  busyAware?: boolean;
463
+ /**
464
+ * 组件声明的数据对象取数完成(外部触发的重算,如 behavior.from 读取回来)后,core 在重渲之后调用一次;
465
+ * 骨架原样挂到控制器上(不包装)。需要在取数后「补画 / 回填」副作用时写在这里(重渲只让派生值重算,不会替你回填);
466
+ * 不要在里面改 props,需要重绘调 `api.refresh()`。抛错由 core 记录,不影响其它组件。
467
+ */
468
+ onDataObjectsChange?(): void;
357
469
  }
358
470
 
359
471
  export type KitViewSetup = (api: KitApi) => KitView;
@@ -398,6 +510,15 @@ function guardAsyncServices(
398
510
  return { ...services, engines: wrappedEngines };
399
511
  }
400
512
 
513
+ /**
514
+ * 控制器挂载钩子:每个 kit 组件实例挂载时按宿主元素各调一次(钩子自己保证幂等)。
515
+ * 给「每页只需装一次」的文档级装置用(按需提示的事件委托,见 hint-tips.ts);这里不 import 它们,避免 shared ↔ reason-tip 循环依赖。
516
+ */
517
+ const MOUNT_HOOKS = new Set<(host: HTMLElement) => void>();
518
+ export function onKitControllerMount(hook: (host: HTMLElement) => void): void {
519
+ MOUNT_HOOKS.add(hook);
520
+ }
521
+
401
522
  /**
402
523
  * 控制器骨架:每个实例调用一次 setup(api),闭包即实例状态;
403
524
  * onMount 取根、挂事件并首绘,onPropsChange 全量重绘,onUnmount 统一执行清理函数。
@@ -465,6 +586,7 @@ export function createKitController(setup: KitViewSetup | KitView): SomaComponen
465
586
  onMount(): void {
466
587
  alive = true;
467
588
  root = findRoot(ctx.host);
589
+ for (const hook of MOUNT_HOOKS) hook(ctx.host);
468
590
  offPerm = registerLivePermissionGate(applyPerm);
469
591
  cleanup = view.attach?.(root, api);
470
592
  paint();
@@ -588,6 +710,7 @@ export const CLASS_PROP = {
588
710
  export const ID_PROPS = {
589
711
  id: { type: 'string', default: '', desc: '根控件 id,供 label for 关联' },
590
712
  aria_label: { type: 'string', default: '', desc: '无可见标签时的可访问名' },
713
+ labelledby: { type: 'string', default: '', desc: '可见标签元素 id(写 aria-labelledby;非原生可标注控件靠它得到可访问名,表单自动传入)' },
591
714
  name: { type: 'string', default: '', desc: '表单字段名' },
592
715
  } as const;
593
716
 
@@ -629,6 +752,8 @@ export interface KitTablistOptions {
629
752
  orientation?: 'horizontal' | 'vertical';
630
753
  /** 选中变化(点击 / 键盘 / select())后回调;silent 的 select 不回调 */
631
754
  onSelect?: (id: string, tab: HTMLElement) => void;
755
+ /** 面板切换时用页面过渡(View Transitions,仅内容区参与;不支持 / 减弱动效时直切)。缺省 false;只对真正换了选中项的 select 生效 */
756
+ viewTransition?: boolean;
632
757
  }
633
758
 
634
759
  export interface KitTablistHandle {
@@ -720,15 +845,20 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
720
845
  const tab = byId(id);
721
846
  if (!tab || isDisabled(tab)) return;
722
847
  const changed = current !== id;
723
- const sLeft = root.scrollLeft;
724
- const sTop = root.scrollTop;
725
- current = id;
726
- cursor = id;
727
- paint();
728
- if (o.focus === true) tab.focus({ preventScroll: true });
729
- root.scrollLeft = sLeft;
730
- root.scrollTop = sTop;
731
- if (changed && o.silent !== true) opts.onSelect?.(id, tab);
848
+ const run = (): void => {
849
+ const sLeft = root.scrollLeft;
850
+ const sTop = root.scrollTop;
851
+ current = id;
852
+ cursor = id;
853
+ paint();
854
+ if (o.focus === true) tab.focus({ preventScroll: true });
855
+ root.scrollLeft = sLeft;
856
+ root.scrollTop = sTop;
857
+ if (changed && o.silent !== true) opts.onSelect?.(id, tab);
858
+ };
859
+ // 过渡路径下 run 由浏览器在下一帧调用;选中状态与回调都在 run 里一起落,顺序与直切一致
860
+ if (changed && opts.viewTransition === true) withKitViewTransition(run);
861
+ else run();
732
862
  };
733
863
 
734
864
  const reset = (): void => {
@@ -838,21 +968,34 @@ export function withTooltip(viewOrSetup: KitView | KitViewSetup, targetOf: (root
838
968
  function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLElement = (r) => r): KitView {
839
969
  // 视图对象在同一组件定义的所有实例间共享,逐实例状态按根元素存
840
970
  // bound / rebind:目标可随渲染变化(如 MenuButton split 时目标由箭头钮换成主钮),监听跟着目标走
841
- interface TipState { tip: HTMLElement | null; shown: boolean; bound: HTMLElement | null; rebind: ((t: HTMLElement) => void) | null }
971
+ interface TipState { tip: HTMLElement | null; shown: boolean; bound: HTMLElement | null; rebind: ((t: HTMLElement) => void) | null; leave: KitLeaveHandle | null }
842
972
  const states = new WeakMap<HTMLElement, TipState>();
843
973
  const stateOf = (root: HTMLElement): TipState => {
844
974
  let s = states.get(root);
845
975
  if (!s) {
846
- s = { tip: null, shown: false, bound: null, rebind: null };
976
+ s = { tip: null, shown: false, bound: null, rebind: null, leave: null };
847
977
  states.set(root, s);
848
978
  }
849
979
  return s;
850
980
  };
851
981
  const paintTip = (s: TipState): void => {
852
- if (s.tip === null) return;
982
+ const tip = s.tip;
983
+ if (tip === null) return;
853
984
  // 显示时量一次可用空间,贴边则在闭集位置类间翻转(popup.ts);隐藏只换整串类
854
- if (s.shown) showPopupFitted(s.tip, s.tip.parentElement ?? s.tip, POPUP_TIP_PREF, popupTipClass);
855
- else s.tip.className = TOOLTIP_HIDDEN_CLASS;
985
+ if (s.shown) {
986
+ // 退场中被重新唤起:撤销退场再落位
987
+ s.leave?.cancel();
988
+ s.leave = null;
989
+ showPopupFitted(tip, tip.parentElement ?? tip, POPUP_TIP_PREF, popupTipClass);
990
+ return;
991
+ }
992
+ if (tip.className === TOOLTIP_HIDDEN_CLASS || s.leave !== null) return;
993
+ // 出场:与其他锚定浮层同一机制(隐藏前过渡,anchored-layer 的 leaveAnchored);没有退场动画则立即收尾
994
+ s.leave = leaveAnchored(tip, () => {
995
+ s.leave = null;
996
+ tip.className = TOOLTIP_HIDDEN_CLASS;
997
+ unmarkAnchored(tip);
998
+ });
856
999
  };
857
1000
 
858
1001
  return {
@@ -884,7 +1027,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
884
1027
  };
885
1028
  const bind = (t: HTMLElement): void => {
886
1029
  if (s.bound === t) return;
887
- if (s.bound !== null && s.tip !== null && s.bound.getAttribute('aria-describedby') === s.tip.id) s.bound.removeAttribute('aria-describedby');
1030
+ if (s.bound !== null && s.tip !== null) removeIdToken(s.bound, 'aria-describedby', s.tip.id);
888
1031
  unbind();
889
1032
  t.addEventListener('mouseenter', show);
890
1033
  t.addEventListener('mouseleave', hide);
@@ -899,6 +1042,8 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
899
1042
  return () => {
900
1043
  unbind();
901
1044
  s.rebind = null;
1045
+ s.leave?.cancel();
1046
+ s.leave = null;
902
1047
  if (s.tip) s.tip.remove();
903
1048
  s.tip = null;
904
1049
  s.shown = false;
@@ -913,7 +1058,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
913
1058
  const text = str(p.tooltip);
914
1059
  if (text === '') {
915
1060
  if (s.tip) {
916
- if (target.getAttribute('aria-describedby') === s.tip.id) target.removeAttribute('aria-describedby');
1061
+ removeIdToken(target, 'aria-describedby', s.tip.id);
917
1062
  s.tip.remove();
918
1063
  s.tip = null;
919
1064
  }
@@ -927,7 +1072,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
927
1072
  }
928
1073
  s.tip.textContent = text;
929
1074
  if (s.tip.parentNode !== target) target.appendChild(s.tip);
930
- target.setAttribute('aria-describedby', s.tip.id);
1075
+ addIdToken(target, 'aria-describedby', s.tip.id);
931
1076
  const cls = target.className;
932
1077
  if (!/(^|\s)(relative|absolute|fixed|sticky)(\s|$)/.test(cls)) {
933
1078
  target.className = cls === '' ? TOOLTIP_ANCHOR_CLASS : `${cls} ${TOOLTIP_ANCHOR_CLASS}`;
@@ -941,3 +1086,4 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
941
1086
 
942
1087
  export * from '../recipes';
943
1088
  export * from './loading-gate';
1089
+ export { withKitViewTransition, canKitViewTransition } from './view-transition';