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
package/src/base/otp.ts CHANGED
@@ -7,8 +7,8 @@ import type { SomaComponentDefinition } from 'soma-core';
7
7
  import { kitKey, kitText } from '../i18n/kit-text';
8
8
  import { setKitFace } from '../recipes';
9
9
  import {
10
- CLASS_PROP, ID_PROPS, SIZE_PROP,
11
- bool, classCandidates, createKitController, joinClass, num, setAttr, setBoolAttr, sizeOf, str,
10
+ CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
11
+ applyGroupA11y, bool, classCandidates, createKitController, joinClass, num, setAttr, setBoolAttr, sizeOf, str,
12
12
  type KitSize, type KitView,
13
13
  } from './shared';
14
14
 
@@ -227,8 +227,8 @@ function makeView(): KitView {
227
227
  });
228
228
  completed = chars.length === length;
229
229
  root.setAttribute('role', 'group');
230
- root.setAttribute('aria-label', label);
231
- // 只写 id:applyCommon 会把空的 aria_label 当作「清掉」,把上面写好的组名抹掉
230
+ // 组名(aria_label 缺省取默认文案)与必填 / 无效 / 说明 / 标签关联一并走 applyCommon(组根不写 name)
231
+ applyGroupA11y(root, { ...p, aria_label: label }, cells);
232
232
  setAttr(root, 'id', str(p.id));
233
233
  root.className = joinClass(GROUP_CLASS, p.class);
234
234
  },
@@ -248,6 +248,7 @@ export function createOtp(): SomaComponentDefinition {
248
248
  disabled: { type: 'boolean', default: false },
249
249
  readonly: { type: 'boolean', default: false },
250
250
  ...ID_PROPS,
251
+ ...INVALID_PROPS,
251
252
  size: SIZE_PROP,
252
253
  class: CLASS_PROP,
253
254
  },
@@ -0,0 +1,235 @@
1
+ // 浮层页面侧运行期:退场过渡 + 向外壳通报「页内浮层栈」。纯 DOM,不依赖 kit 其它模块(base / data / biz / frames 都可 import,不成环)。
2
+ //
3
+ // 一、退场(W3 / D 类机制)
4
+ // core 的显隐只有一个执行点:`SomaContainerAdapter.setVisibility`。core 提供方言中性的端口 `renderPorts.hideTransition`
5
+ // (写 hidden 之前先等钩子返回的 Promise;等待中被再次显示则 abort 信号并直接显示),kit 在这里实现钩子:
6
+ // createKitHideTransition() -> 只处理浮层显隐外层(`_layer` 锚点,直接子节点含 `[data-kit-scrim]`),其余元素返回 void(立即隐藏);
7
+ // 首次收起静默(core 初始化时把未开的浮层收起,从未展示过的浮层不播退场);之后收起 -> beginKitLeave:
8
+ // 标 `data-kit-leaving` + `inert`,等退场动画结束(animationend,带超时兜底)再 resolve,由 core 写真的 hidden;
9
+ // abort(退场中重开)-> 撤销退场状态。
10
+ // 退场是否存在由「标上 data-kit-leaving 后计算样式的 animation-name 有没有变」判定:主题侧没有补退场关键帧时没有任何延迟(立即隐藏),
11
+ // 补了关键帧即自动生效,本文件不写任何时长 / 缓动(时长取计算样式里的 animation-duration)。
12
+ // prefers-reduced-motion: reduce 时不短路:主题侧该偏好下的退场关键帧只有淡出(无位移 / 缩放),时长由令牌归短;不全局压零。
13
+ // 收尾三路任一先到即可:动画对象 finished、animationend / animationcancel 事件、超时兜底(计算出的出场时长 + 真源宽限);el.getAnimations() 为空则立即继续。
14
+ // 接入点(主题侧):`[data-kit-scrim][data-kit-leaving]`、`[data-kit-leaving] [role="dialog"]`、`[data-kit-leaving]`(通知 / 命令式遮罩 / 外壳遮罩)。
15
+ //
16
+ // 二、页内浮层栈 -> 外壳遮罩(W5)
17
+ // 页面在 iframe 里时外壳遮罩盖不到页内浮层之外:页面(本模块)在可见模态面板数变化时向父窗口发
18
+ // `{ type: 'soma-kit:overlay', open: <数量> }`(targetOrigin = 本页 origin);外壳校验 origin 与来源 iframe 后据此显示 / 收回遮罩。
19
+ // 外壳不再窥探 iframe 文档。载荷只含计数。
20
+ // 安装点只有一处:kit 应用的渲染端口装配(`createKitRenderPorts`,app/define-kit-app 经它出端口);监听按文档级 `aria-modal`
21
+ // 统计,业务浮层 / 命令式模态 / 图片查看 / 引导 / 命令面板等一切 aria-modal 浮层自动覆盖,不在各浮层里各装一次。
22
+
23
+ import { KIT_OVERLAY_LIMITS } from 'soma-foundation/kit-limits';
24
+
25
+ export const KIT_OVERLAY_MESSAGE_TYPE = 'soma-kit:overlay';
26
+ /** 退场中的状态属性(主题侧据此挂退场关键帧) */
27
+ export const KIT_LEAVING_ATTR = 'data-kit-leaving';
28
+ /** 兜底超时在出场动画时长之外的宽限(毫秒,真源 kit-limits#overlay.leaveMarginMs) */
29
+ export const KIT_LEAVE_SLACK_MS: number = KIT_OVERLAY_LIMITS.leaveMarginMs;
30
+ /** 兜底超时上限:再长的动画也在这个时间内强制收尾,浮层不会卡在退场态 */
31
+ export const KIT_LEAVE_MAX_MS = 1000;
32
+
33
+ export interface KitOverlayMessage {
34
+ type: typeof KIT_OVERLAY_MESSAGE_TYPE;
35
+ /** 当前可见(非退场、非隐藏)的模态面板数 */
36
+ open: number;
37
+ }
38
+
39
+ /** 解析外壳收到的消息载荷;形状不对一律返回 null(不抛) */
40
+ export function parseKitOverlayMessage(data: unknown): KitOverlayMessage | null {
41
+ if (data === null || typeof data !== 'object') return null;
42
+ const m = data as { type?: unknown; open?: unknown };
43
+ if (m.type !== KIT_OVERLAY_MESSAGE_TYPE) return null;
44
+ if (typeof m.open !== 'number' || !Number.isInteger(m.open) || m.open < 0) return null;
45
+ return { type: KIT_OVERLAY_MESSAGE_TYPE, open: m.open };
46
+ }
47
+
48
+ // ---------------------------------------------------------------- 退场
49
+
50
+ export interface KitLeaveHandle {
51
+ /** 取消退场:移除退场状态,不调 done(元素回到可见) */
52
+ cancel(): void;
53
+ }
54
+
55
+ /** 参与退场的节点:根本身 + 其内的遮罩 / 对话框面板(动画通常挂在它们身上) */
56
+ function leaveTargets(root: HTMLElement): Element[] {
57
+ return [root, ...Array.from(root.querySelectorAll('[data-kit-scrim], [role="dialog"], [data-kit-part="drawer"]'))];
58
+ }
59
+
60
+ function animationNameOf(win: Window, el: Element): string {
61
+ try { return win.getComputedStyle(el).animationName ?? ''; } catch { return ''; }
62
+ }
63
+
64
+ function firstTimeMs(value: string | undefined): number {
65
+ const first = (value ?? '').split(',')[0]?.trim() ?? '';
66
+ const n = parseFloat(first);
67
+ if (!Number.isFinite(n)) return 0;
68
+ return first.endsWith('ms') ? n : n * 1000;
69
+ }
70
+
71
+ /** 退场里真在跑的有限动画(挂在参与退场的节点上、非无限循环);浏览器没有 getAnimations 时返回 null(只能靠事件 + 超时) */
72
+ function runningLeaveAnimations(root: HTMLElement, moving: readonly Element[]): Animation[] | null {
73
+ if (typeof root.getAnimations !== 'function') return null;
74
+ try {
75
+ return root.getAnimations({ subtree: true }).filter((a) => {
76
+ const target = (a.effect as KeyframeEffect | null)?.target ?? null;
77
+ if (target === null || !moving.includes(target)) return false;
78
+ return a.effect?.getComputedTiming().iterations !== Infinity;
79
+ });
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * 开始退场:给 el 标 data-kit-leaving + inert,等退场动画结束后调 done。
87
+ * 没有退场动画(标上状态后计算样式的 animation-name 没变,或 el.getAnimations() 为空)/ 无窗口 -> 返回 null,什么都没改,由调用方立即收尾。
88
+ * 减弱动效(prefers-reduced-motion: reduce)不在这里短路:主题侧在该偏好下只保留淡出(无位移 / 缩放,时长由令牌归短),
89
+ * 所以这里照常等它结束,退场的存在与否只看有没有动画。
90
+ * 收尾不依赖 animationend / transitionend 必达:三路任一先到即收尾——动画对象的 finished、事件、超时兜底(出场时长 + 真源宽限 KIT_LEAVE_SLACK_MS)。
91
+ */
92
+ export function beginKitLeave(el: HTMLElement, done: () => void): KitLeaveHandle | null {
93
+ const win = el.ownerDocument.defaultView;
94
+ if (!win) return null;
95
+ const targets = leaveTargets(el);
96
+ const before = targets.map((t) => animationNameOf(win, t));
97
+ el.setAttribute(KIT_LEAVING_ATTR, '');
98
+ const moving: Element[] = [];
99
+ let maxMs = 0;
100
+ targets.forEach((t, i) => {
101
+ const name = animationNameOf(win, t);
102
+ if (name === '' || name === 'none' || name === before[i]) return;
103
+ moving.push(t);
104
+ const cs = win.getComputedStyle(t);
105
+ maxMs = Math.max(maxMs, firstTimeMs(cs.animationDuration) + firstTimeMs(cs.animationDelay));
106
+ });
107
+ // 动画列表为空(浏览器已知没有在跑的退场动画,如 animation-name 变了但元素没有渲染框):立即继续,不等任何事件
108
+ const anims = moving.length === 0 ? null : runningLeaveAnimations(el, moving);
109
+ if (moving.length === 0 || (anims !== null && anims.length === 0)) {
110
+ el.removeAttribute(KIT_LEAVING_ATTR);
111
+ return null;
112
+ }
113
+ el.setAttribute('inert', '');
114
+ const pending = new Set<Element>(moving);
115
+ let over = false;
116
+ let timer: ReturnType<typeof setTimeout> | undefined;
117
+ const stop = (): void => {
118
+ over = true;
119
+ if (timer !== undefined) clearTimeout(timer);
120
+ el.removeEventListener('animationend', onEnd);
121
+ el.removeEventListener('animationcancel', onEnd);
122
+ el.removeAttribute(KIT_LEAVING_ATTR);
123
+ el.removeAttribute('inert');
124
+ };
125
+ const finish = (): void => {
126
+ if (over) return;
127
+ stop();
128
+ done();
129
+ };
130
+ function onEnd(e: Event): void {
131
+ pending.delete(e.target as Element);
132
+ if (pending.size === 0) finish();
133
+ }
134
+ el.addEventListener('animationend', onEnd);
135
+ el.addEventListener('animationcancel', onEnd);
136
+ timer = setTimeout(finish, Math.min(KIT_LEAVE_MAX_MS, maxMs + KIT_LEAVE_SLACK_MS));
137
+ if (anims !== null) {
138
+ void Promise.allSettled(anims.map((a) => a.finished)).then(finish);
139
+ }
140
+ return { cancel: () => { if (!over) stop(); } };
141
+ }
142
+
143
+ // ---------------------------------------------------------------- core 隐藏前过渡钩子(renderPorts.hideTransition)
144
+
145
+ /** 与 soma-core 的 HideTransition 同形(结构类型,本文件不 import core) */
146
+ export type KitHideTransition = (element: HTMLElement, signal: AbortSignal) => Promise<void> | void;
147
+
148
+ /** 浮层显隐外层:锚点 id 以 _layer 结尾(overlay-shell 的 dialogIds / overlayIds),且直接子节点含遮罩 */
149
+ export function isKitLayerHost(el: HTMLElement): boolean {
150
+ if (!(el.getAttribute('data-soma-id') ?? '').endsWith('_layer')) return false;
151
+ return Array.from(el.children).some((c) => c.hasAttribute('data-kit-scrim'));
152
+ }
153
+
154
+ /** 浮层退场钩子:只处理浮层显隐外层,其余元素立即隐藏(返回 void);首次收起静默,之后播退场(无关键帧 / 减弱动效即时) */
155
+ export function createKitHideTransition(): KitHideTransition {
156
+ const armed = new WeakSet<HTMLElement>();
157
+ return (el, signal) => {
158
+ if (!isKitLayerHost(el)) return undefined;
159
+ if (!armed.has(el)) { armed.add(el); return undefined; }
160
+ let resolveLeave: (() => void) | undefined;
161
+ const done = new Promise<void>((resolve) => { resolveLeave = resolve; });
162
+ const handle = beginKitLeave(el, () => resolveLeave?.());
163
+ if (handle === null) return undefined;
164
+ signal.addEventListener('abort', () => handle.cancel(), { once: true });
165
+ return done;
166
+ };
167
+ }
168
+
169
+ // ---------------------------------------------------------------- 页内浮层栈 -> 外壳
170
+
171
+ /** 可见的模态面板数:aria-modal 面板里,祖先没有 hidden 属性 / hidden 类 / 退场状态的 */
172
+ export function countOpenKitOverlays(doc: Document): number {
173
+ let n = 0;
174
+ doc.querySelectorAll('[aria-modal="true"]').forEach((el) => {
175
+ if (el.closest('[hidden], .hidden, [data-kit-leaving]') === null) n += 1;
176
+ });
177
+ return n;
178
+ }
179
+
180
+ interface RuntimeState { last: number; off: () => void }
181
+ const RUNTIMES = new WeakMap<Document, RuntimeState>();
182
+
183
+ /** 向父窗口通报当前浮层数(数量没变不发;顶层页面 / 无父窗口 / 不透明 origin 不发) */
184
+ export function notifyKitOverlays(doc: Document): void {
185
+ const st = RUNTIMES.get(doc);
186
+ const win = doc.defaultView;
187
+ if (!st || !win) return;
188
+ const open = countOpenKitOverlays(doc);
189
+ if (open === st.last) return;
190
+ st.last = open;
191
+ postOpen(win, open);
192
+ }
193
+
194
+ function postOpen(win: Window, open: number): void {
195
+ const parent = win.parent;
196
+ if (!parent || parent === win) return;
197
+ const origin = win.location?.origin;
198
+ if (!origin || origin === 'null') return;
199
+ try { parent.postMessage({ type: KIT_OVERLAY_MESSAGE_TYPE, open } satisfies KitOverlayMessage, origin); } catch { /* 父窗口不可达:忽略 */ }
200
+ }
201
+
202
+ const relevantNode = (n: Node): boolean => n instanceof Element && (n.matches('[aria-modal]') || n.querySelector('[aria-modal]') !== null);
203
+
204
+ /**
205
+ * 在本页安装浮层通报:监听浮层增删与显隐 / 退场状态变化并向外壳通报计数。幂等;页面卸载时报 0。
206
+ * 唯一安装点:kit 应用渲染端口装配(createKitRenderPorts)。
207
+ */
208
+ export function installKitOverlayRuntime(doc: Document): void {
209
+ if (RUNTIMES.has(doc)) return;
210
+ const win = doc.defaultView;
211
+ if (!win) return;
212
+ const state: RuntimeState = { last: 0, off: () => {} };
213
+ RUNTIMES.set(doc, state);
214
+ const onChange = (): void => notifyKitOverlays(doc);
215
+ const Observer = (win as Window & { MutationObserver?: typeof MutationObserver }).MutationObserver;
216
+ const root = doc.body ?? doc.documentElement;
217
+ let mo: MutationObserver | null = null;
218
+ if (typeof Observer === 'function' && root) {
219
+ mo = new Observer((records) => {
220
+ const hit = records.some((r) => r.type === 'attributes'
221
+ || Array.from(r.addedNodes).some(relevantNode) || Array.from(r.removedNodes).some(relevantNode));
222
+ if (hit) onChange();
223
+ });
224
+ mo.observe(root, { childList: true, subtree: true, attributes: true, attributeFilter: ['hidden', KIT_LEAVING_ATTR] });
225
+ }
226
+ const onHide = (): void => { if (state.last !== 0) { state.last = 0; postOpen(win, 0); } };
227
+ win.addEventListener('pagehide', onHide);
228
+ state.off = () => { mo?.disconnect(); win.removeEventListener('pagehide', onHide); RUNTIMES.delete(doc); };
229
+ onChange();
230
+ }
231
+
232
+ /** 卸载运行期(测试与应用销毁用) */
233
+ export function uninstallKitOverlayRuntime(doc: Document): void {
234
+ RUNTIMES.get(doc)?.off();
235
+ }
@@ -67,23 +67,23 @@ const HIDDEN = 'hidden';
67
67
 
68
68
  const TRIGGER: Record<PopVariant, Record<KitSize, string>> = {
69
69
  neutral: {
70
- sm: '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 disabled:cursor-not-allowed disabled:opacity-60',
71
- md: '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 disabled:cursor-not-allowed disabled:opacity-60',
72
- lg: '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 disabled:cursor-not-allowed disabled:opacity-60',
70
+ sm: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md border border-button-edge 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 disabled:cursor-not-allowed disabled:opacity-60',
71
+ md: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
72
+ lg: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md border border-button-edge bg-surface px-4 text-base text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
73
73
  },
74
74
  primary: {
75
- sm: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-primary px-2.5 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
76
- md: 'inline-flex h-9 cursor-pointer items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
75
+ sm: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md bg-primary px-2.5 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
76
+ md: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
77
77
  lg: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md bg-primary px-4 text-base font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
78
78
  },
79
79
  danger: {
80
- sm: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-danger px-2.5 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
81
- md: 'inline-flex h-9 cursor-pointer items-center justify-center rounded-md bg-danger px-3 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
80
+ sm: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md bg-danger px-2.5 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
81
+ md: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-danger px-3 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
82
82
  lg: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md bg-danger px-4 text-base font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
83
83
  },
84
84
  };
85
85
 
86
- const PANEL_BASE = mergeClass(kitOverlayRecipe({ kind: 'popover', size: 'md' }), 'absolute z-10 w-72 border-border-subtle p-3 text-sm focus-visible:outline-none motion-safe:animate-kit-menu-in');
86
+ const PANEL_BASE = mergeClass(kitOverlayRecipe({ kind: 'popover', size: 'md' }), 'absolute z-10 w-72 border-border-subtle p-3 text-sm focus-visible:outline-none');
87
87
  /** placement 字面 -> 偏好位置(贴边时由 popup.ts 的 showPopupFitted 在闭集位置间翻转) */
88
88
  export function popPlaceOf(placement: PopPlacement): PopPlace {
89
89
  const [side, align] = placement.split('-') as ['top' | 'bottom', 'start' | 'end'];
@@ -93,7 +93,7 @@ const panelClass = (place: PopPlace): string => `${PANEL_BASE} ${popPlaceClass(p
93
93
  const TITLE = 'text-sm font-semibold text-fg';
94
94
  const BODY = 'mt-2 text-sm text-fg-muted';
95
95
  const ACTIONS = mergeClass(kitPopoverActionsRecipe(), 'mt-2');
96
- const BTN_CANCEL = '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 hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
96
+ const BTN_CANCEL = 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
97
97
  const BTN_OK: Record<'primary' | 'danger', string> = {
98
98
  primary: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
99
99
  danger: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-danger px-3 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
package/src/base/popup.ts CHANGED
@@ -8,6 +8,9 @@
8
8
  import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
9
9
  import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
10
10
  import { kitDirAt } from '../i18n/kit-text';
11
+ import { kitSurfaceRecipe } from '../recipes/surface';
12
+ import { leaveAnchored, markAnchored, unmarkAnchored } from './anchored-layer';
13
+ import type { KitLeaveHandle } from './overlay-runtime';
11
14
  import {
12
15
  createPanelPortalWith, KIT_PANEL_PORTAL_CLASS_CANDIDATES, showAtPoint,
13
16
  type PanelPortal, type PointPanel, type PointPanelOptions, type PointXY,
@@ -25,6 +28,8 @@ type DropdownRules = {
25
28
  clamps: readonly { cls: string }[];
26
29
  };
27
30
  const DD = (grammarJson as unknown as { dropdown: DropdownRules }).dropdown;
31
+ /** 下拉 / 菜单面板的表面:浮起级(圆角 + 发丝描边 + 浮起底色 + 双层阴影 + 高光边,recipes/surface.ts 唯一拼装处) */
32
+ const SURFACE_RAISED = kitSurfaceRecipe('raised');
28
33
 
29
34
  export interface ListNavOptions {
30
35
  /** 集合宿主(列表容器;接线需要它判断书写方向) */
@@ -134,12 +139,12 @@ export function focusCellQuiet(node: HTMLElement | null | undefined): void {
134
139
  /** 默认的整串面板类:显隐只换整串,`hidden` 不与布局类并存 */
135
140
  export const PANEL_HIDDEN_CLASS = 'hidden';
136
141
  export const PANEL_SHOWN_CLASS =
137
- `absolute start-0 top-full z-10 mt-1 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto rounded-lg ${DD.panelBorderClass} bg-surface-raised py-1 ${DD.panelShadowClass}`;
142
+ `absolute start-0 top-full z-10 mt-1 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto ${SURFACE_RAISED} py-1`;
138
143
 
139
144
  // 选项行高固定(真源 dropdown.rowClass = h-9),面板最大高才能算成「整数行 + 半行」
140
145
  const ROW = DD.rowClass;
141
146
  export const OPTION_CLASS = {
142
- idle: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 px-3 text-sm text-fg transition-colors hover:bg-surface-sunken`,
147
+ idle: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 px-3 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press`,
143
148
  active: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-surface-sunken px-3 text-sm text-fg transition-colors`,
144
149
  selected: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors`,
145
150
  selectedActive: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors`,
@@ -158,9 +163,10 @@ export function optionClass(selected: boolean, active: boolean, disabled: boolea
158
163
  export const KIT_POPUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
159
164
  'hidden', 'absolute', 'start-0', 'top-full', 'z-10', 'mt-1', DD.panelMaxClass, DD.rowClass, 'w-full', 'w-max', 'min-w-full', 'max-w-screen', 'overflow-auto',
160
165
  'rounded-md', 'rounded-lg', 'border', 'border-border', 'border-border-subtle', 'bg-surface-raised', 'py-1', DD.panelShadowClass, 'shadow-sm',
166
+ ...SURFACE_RAISED.split(/\s+/),
161
167
  'flex', 'cursor-pointer', 'cursor-not-allowed', 'items-center', 'whitespace-nowrap', 'gap-2', 'px-3', 'py-2', 'text-sm',
162
168
  'text-fg', 'text-fg-subtle', 'bg-surface-sunken', 'font-medium', 'text-primary-on-soft',
163
- 'transition-colors', 'hover:bg-surface-sunken', 'bg-primary-soft', 'text-primary-on-soft', 'opacity-60',
169
+ 'transition-colors', 'hover:bg-state-layer-hover', 'active:bg-state-layer-press', 'bg-primary-soft', 'text-primary-on-soft', 'opacity-60',
164
170
  ]);
165
171
 
166
172
  /**
@@ -263,6 +269,19 @@ export function showPopupFitted(
263
269
  pref: PopPlace,
264
270
  classFor: (place: PopPlace) => string,
265
271
  gapPx = 8,
272
+ ): PopPlace {
273
+ const place = fitPopupPlace(panel, anchor, pref, classFor, gapPx);
274
+ // 锚定浮层统一标记(anchored-layer.ts):落位后的实际方向,重定位 / 翻转时随之更新
275
+ markAnchored(panel, place);
276
+ return place;
277
+ }
278
+
279
+ function fitPopupPlace(
280
+ panel: HTMLElement,
281
+ anchor: HTMLElement,
282
+ pref: PopPlace,
283
+ classFor: (place: PopPlace) => string,
284
+ gapPx: number,
266
285
  ): PopPlace {
267
286
  panel.className = classFor(pref);
268
287
  if (typeof panel.getBoundingClientRect !== 'function') return pref;
@@ -290,7 +309,7 @@ export const POPUP_TIP_SHOWN_CLASS = popupTipClass(POPUP_TIP_PREF);
290
309
 
291
310
  /** 下拉面板外观类(不含位置类):与 PANEL_SHOWN_CLASS 同一份外观 */
292
311
  export const PANEL_BASE_CLASS =
293
- `absolute z-10 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto rounded-lg ${DD.panelBorderClass} bg-surface-raised py-1 ${DD.panelShadowClass}`;
312
+ `absolute z-10 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto ${SURFACE_RAISED} py-1`;
294
313
 
295
314
  /** 空间不足时面板内部滚动的 max-h 闭集档位(px = 刻度 x 4),从大到小;每档都是「整数行 + 半行」(真源 dropdown.clamps),空间不够也不腰斩一行 */
296
315
  export const DROPDOWN_CLAMPS: readonly { cls: string; px: number }[] = Object.freeze(
@@ -356,6 +375,18 @@ export function showDropdownFitted(
356
375
  base: string,
357
376
  prefAlign: PopAlign = 'start',
358
377
  gap: 1 | 2 = 1,
378
+ ): PopPlace {
379
+ const place = fitDropdownPlace(panel, anchor, base, prefAlign, gap);
380
+ markAnchored(panel, place);
381
+ return place;
382
+ }
383
+
384
+ function fitDropdownPlace(
385
+ panel: HTMLElement,
386
+ anchor: HTMLElement,
387
+ base: string,
388
+ prefAlign: PopAlign,
389
+ gap: 1 | 2,
359
390
  ): PopPlace {
360
391
  const classFor = (place: PopPlace): string => `${base} ${popPlaceClass(place, gap)}`;
361
392
  const pref: PopPlace = { side: 'bottom', align: prefAlign };
@@ -471,6 +502,7 @@ export function releaseDropdownsIn(scope: Element): void {
471
502
 
472
503
  /** 收起并放回原位(restore)或直接销毁(组件卸载) */
473
504
  export function releaseDropdown(panel: HTMLElement, restore = true): void {
505
+ cancelLeave(panel);
474
506
  const m = DROPDOWN_MOUNTS.get(panel);
475
507
  if (!m) return;
476
508
  DROPDOWN_MOUNTS.delete(panel);
@@ -479,6 +511,33 @@ export function releaseDropdown(panel: HTMLElement, restore = true): void {
479
511
  else m.portal.destroy();
480
512
  }
481
513
 
514
+ // ── 锚定面板的出场 ──
515
+ // 收起时有退场动画(anchored-layer 的 leaveAnchored:标 data-kit-leaving + inert,等动画结束,带超时兜底)就先播完再放回原位并整串 hidden;
516
+ // 没有(无关键帧 / jsdom)立即收尾,行为与改动前一致。退场中被重新打开 / 被销毁时撤销退场。
517
+ const LEAVING = new WeakMap<HTMLElement, KitLeaveHandle>();
518
+
519
+ function cancelLeave(panel: HTMLElement): void {
520
+ LEAVING.get(panel)?.cancel();
521
+ LEAVING.delete(panel);
522
+ }
523
+
524
+ /** 收起锚定面板:已挂出且有退场动画 -> 播完再放回 + hidden;否则立即放回 + hidden */
525
+ function retireAnchored(panel: HTMLElement): void {
526
+ if (LEAVING.has(panel)) return;
527
+ const finish = (): void => {
528
+ LEAVING.delete(panel);
529
+ releaseDropdown(panel);
530
+ panel.className = PANEL_HIDDEN_CLASS;
531
+ unmarkAnchored(panel);
532
+ };
533
+ if (!DROPDOWN_MOUNTS.has(panel)) {
534
+ panel.className = PANEL_HIDDEN_CLASS;
535
+ return;
536
+ }
537
+ const handle = leaveAnchored(panel, finish);
538
+ if (handle !== null) LEAVING.set(panel, handle);
539
+ }
540
+
482
541
  /** 挂到端口并落位;返回实际锚点,端口不可用返回 null(调用方走原位) */
483
542
  function mountAnchored(panel: HTMLElement, anchor: HTMLElement | undefined, pref: PopPlace, fit: (p: HTMLElement, box: HTMLElement) => PopPlace): HTMLElement | null {
484
543
  const prev = DROPDOWN_MOUNTS.get(panel);
@@ -505,10 +564,10 @@ function mountAnchored(panel: HTMLElement, anchor: HTMLElement | undefined, pref
505
564
  */
506
565
  export function syncDropdown(panel: HTMLElement, open: boolean, base: string = PANEL_BASE_CLASS, anchor?: HTMLElement, prefAlign: PopAlign = 'start'): void {
507
566
  if (!open) {
508
- releaseDropdown(panel);
509
- panel.className = PANEL_HIDDEN_CLASS;
567
+ retireAnchored(panel);
510
568
  return;
511
569
  }
570
+ cancelLeave(panel);
512
571
  const live = `${base} ${DROPDOWN_LIVE_CLASS}`;
513
572
  const at = mountAnchored(panel, anchor, { side: 'bottom', align: prefAlign }, (p, box) => showDropdownFitted(p, box, live, prefAlign));
514
573
  if (at === null) showDropdownFitted(panel, anchor ?? panel.parentElement ?? panel, base, prefAlign);
@@ -522,10 +581,10 @@ export function syncAnchored(
522
581
  panel: HTMLElement, open: boolean, anchor: HTMLElement, pref: PopPlace, classFor: (place: PopPlace) => string, gapPx?: number,
523
582
  ): void {
524
583
  if (!open) {
525
- releaseDropdown(panel);
526
- panel.className = PANEL_HIDDEN_CLASS;
584
+ retireAnchored(panel);
527
585
  return;
528
586
  }
587
+ cancelLeave(panel);
529
588
  const live = (place: PopPlace): string => `${classFor(place)} ${DROPDOWN_LIVE_CLASS}`;
530
589
  const at = mountAnchored(panel, anchor, pref, (p, box) => showPopupFitted(p, box, pref, live, gapPx));
531
590
  if (at === null) showPopupFitted(panel, anchor, pref, classFor, gapPx);
@@ -12,6 +12,7 @@
12
12
  import { getOverlayHost } from 'soma-core/behavior';
13
13
  import type { OverlayMount } from 'soma-core/behavior';
14
14
  import type { PopPlace } from './popup';
15
+ import { markAnchored, unmarkAnchored } from './anchored-layer';
15
16
 
16
17
  export interface KitOverlayOptions {
17
18
  /** 逻辑所有者(组件宿主 / 触发元素):作用域属性从它取,它脱离文档后浮层自动卸载 */
@@ -124,6 +125,8 @@ export function showAtPoint(panel: HTMLElement, point: PointXY, opts: PointPanel
124
125
  });
125
126
  if (!mount) return null;
126
127
  placeAtPoint(panel, point, { rtl: opts.rtl === true, resolve: opts.resolve });
128
+ // 按落点定位的菜单(右键菜单)同属锚定浮层:进场由 [data-kit-anchored] 规则统一驱动(落点在上方,面板向下展开)
129
+ markAnchored(panel, { side: 'bottom' });
127
130
  const onMove = (event?: Event): void => {
128
131
  const t = event?.target;
129
132
  if (t instanceof Node && panel.contains(t)) return;
@@ -140,6 +143,7 @@ export function showAtPoint(panel: HTMLElement, point: PointXY, opts: PointPanel
140
143
  hide(restore = true): void {
141
144
  if (!alive) return;
142
145
  alive = false;
146
+ unmarkAnchored(panel);
143
147
  if (opts.onViewportChange && hasWindow) {
144
148
  window.removeEventListener('resize', onMove);
145
149
  document.removeEventListener('scroll', onMove, true);
@@ -14,16 +14,16 @@ import { kitText } from '../i18n/kit-text';
14
14
  import { setKitFace } from '../recipes';
15
15
 
16
16
  const GROUP: Record<KitSize, string> = {
17
- sm: 'inline-flex h-8 items-stretch overflow-hidden rounded-md border border-input bg-surface text-sm transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
18
- md: 'inline-flex h-9 items-stretch overflow-hidden rounded-md border border-input bg-surface text-sm transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
17
+ sm: 'inline-flex h-6 items-stretch overflow-hidden rounded-md border border-input bg-surface text-sm transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
18
+ md: 'inline-flex h-8 items-stretch overflow-hidden rounded-md border border-input bg-surface text-sm transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
19
19
  lg: 'inline-flex h-10 items-stretch overflow-hidden rounded-md border border-input bg-surface text-base transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
20
20
  };
21
21
  const GROUP_OFF: Record<KitSize, string> = {
22
- sm: 'inline-flex h-8 items-stretch overflow-hidden rounded-md border border-input bg-surface-sunken text-sm opacity-60',
23
- md: 'inline-flex h-9 items-stretch overflow-hidden rounded-md border border-input bg-surface-sunken text-sm opacity-60',
22
+ sm: 'inline-flex h-6 items-stretch overflow-hidden rounded-md border border-input bg-surface-sunken text-sm opacity-60',
23
+ md: 'inline-flex h-8 items-stretch overflow-hidden rounded-md border border-input bg-surface-sunken text-sm opacity-60',
24
24
  lg: 'inline-flex h-10 items-stretch overflow-hidden rounded-md border border-input bg-surface-sunken text-base opacity-60',
25
25
  };
26
- const BTN_ON = 'inline-flex w-8 shrink-0 cursor-pointer items-center justify-center text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
26
+ const BTN_ON = 'inline-flex w-8 shrink-0 cursor-pointer items-center justify-center text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
27
27
  const BTN_OFF = 'inline-flex w-8 shrink-0 cursor-not-allowed items-center justify-center text-fg-subtle opacity-60';
28
28
  // 无 preflight:input 不继承分组的字号(浏览器默认 13px),所以按档位自己写 text-sm / text-base
29
29
  export const STEPPER_INPUT: Record<KitSize, string> = {
package/src/base/radio.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type { SomaComponentDefinition } from 'soma-core';
6
6
  import { CHOICE_GROUP_DEFAULT_CLASS, createChoiceView } from './choice';
7
- import { CLASS_PROP, ID_PROPS, OPTIONS_PROP, SIZE_PROP, createKitController } from './shared';
7
+ import { CLASS_PROP, ID_PROPS, INVALID_PROPS, OPTIONS_PROP, SIZE_PROP, createKitController } from './shared';
8
8
 
9
9
  export function createRadio(): SomaComponentDefinition {
10
10
  return {
@@ -20,6 +20,7 @@ export function createRadio(): SomaComponentDefinition {
20
20
  disabled: { type: 'boolean', default: false },
21
21
  readonly: { type: 'boolean', default: false },
22
22
  ...ID_PROPS,
23
+ ...INVALID_PROPS,
23
24
  size: SIZE_PROP,
24
25
  class: CLASS_PROP,
25
26
  },
package/src/base/range.ts CHANGED
@@ -15,8 +15,8 @@
15
15
  import type { SomaComponentDefinition } from 'soma-core';
16
16
  import { kitDirAt, kitKey, kitText } from '../i18n/kit-text';
17
17
  import {
18
- CLASS_PROP, ID_PROPS, SIZE_PROP,
19
- bool, classCandidates, createKitController, joinClass, num, setAttr, sizeOf, str,
18
+ CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
19
+ applyCompositeField, bool, classCandidates, createKitController, joinClass, num, setAttr, sizeOf, str,
20
20
  type KitApi, type KitProps, type KitSize,
21
21
  } from './shared';
22
22
 
@@ -285,6 +285,22 @@ function paintCustom(root: HTMLElement, p: KitProps, ui: CustomUi): void {
285
285
  };
286
286
  paintThumb(ui.lo, 'lo', lo, range);
287
287
  paintThumb(ui.hi, 'hi', hi, true);
288
+
289
+ // 作表单字段:根(role=group)承载字段名 / 说明关联;单滑块的名字取字段标签;
290
+ // slider 角色支持 aria-invalid / aria-errormessage、不支持 aria-required,所以必填不写到滑块上
291
+ const labelledby = str(p.aria_labelledby, str(p.labelledby));
292
+ const single = !range && aria === '' && labelledby !== '';
293
+ if (single) {
294
+ ui.hi.dot.removeAttribute('aria-label');
295
+ ui.hi.dot.setAttribute('aria-labelledby', labelledby);
296
+ } else ui.hi.dot.removeAttribute('aria-labelledby');
297
+ ui.lo.dot.removeAttribute('aria-labelledby');
298
+ const thumbs = range ? [ui.lo.dot, ui.hi.dot] : [ui.hi.dot];
299
+ applyCompositeField(ui.wrap, { ...p, required: false }, thumbs);
300
+ for (const dot of [ui.lo.dot, ui.hi.dot]) {
301
+ if (!thumbs.includes(dot)) { dot.removeAttribute('aria-invalid'); dot.removeAttribute('aria-errormessage'); }
302
+ dot.removeAttribute('aria-required');
303
+ }
288
304
  }
289
305
 
290
306
  function buildCustomUi(root: HTMLElement, api: KitApi): CustomUi {
@@ -419,6 +435,7 @@ export function createRange(): SomaComponentDefinition {
419
435
  disabled: { type: 'boolean', default: false },
420
436
  readonly: { type: 'boolean', default: false },
421
437
  ...ID_PROPS,
438
+ ...INVALID_PROPS,
422
439
  size: SIZE_PROP,
423
440
  class: CLASS_PROP,
424
441
  },
@@ -6,24 +6,25 @@
6
6
  import type { SomaComponentDefinition } from 'soma-core';
7
7
  import { kitKey } from '../i18n/kit-text';
8
8
  import {
9
- CLASS_PROP, ID_PROPS, SIZE_PROP,
9
+ CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
10
10
  applyCommon, bool, classCandidates, createKitController, joinClass, nextUid, num, setAttr, sizeOf, str,
11
11
  type KitSize, type KitView,
12
12
  } from './shared';
13
13
 
14
- const GROUP_CLASS = 'inline-flex items-center gap-0.5';
14
+ // 排容器用 hit-gap-N(gap 同时写出 --kit-hit-gap),星的 hit-area-row 据此把沿排热区收到中心距,相邻热区相接不重叠
15
+ const GROUP_CLASS = 'inline-flex items-center hit-gap-0.5';
15
16
 
16
17
  const STAR_CLASS: Record<KitSize, { edit: string; read: string }> = {
17
18
  sm: {
18
- edit: 'inline-flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
19
+ edit: 'hit-area-row inline-flex h-5 w-5 shrink-0 p-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
19
20
  read: 'inline-flex h-5 w-5 shrink-0 items-center justify-center',
20
21
  },
21
22
  md: {
22
- edit: 'inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
23
+ edit: 'hit-area-row inline-flex h-6 w-6 shrink-0 p-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
23
24
  read: 'inline-flex h-6 w-6 shrink-0 items-center justify-center',
24
25
  },
25
26
  lg: {
26
- edit: 'inline-flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
27
+ edit: 'hit-area-row inline-flex h-8 w-8 shrink-0 p-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
27
28
  read: 'inline-flex h-8 w-8 shrink-0 items-center justify-center',
28
29
  },
29
30
  };
@@ -192,7 +193,10 @@ function makeView(): KitView {
192
193
  else root.removeAttribute('aria-disabled');
193
194
  }
194
195
  // 只读态的 aria-label 已在上面写好,这里只补 id(applyCommon 会把空的 aria_label 当作「清掉」)
195
- if (readonly) setAttr(root, 'id', str(p.id));
196
+ if (readonly) {
197
+ setAttr(root, 'id', str(p.id));
198
+ setAttr(root, 'aria-labelledby', str(p.aria_labelledby, str(p.labelledby)));
199
+ }
196
200
  // roving:焦点星 = 当前值所在星,没有值时第一颗
197
201
  if (focusIndex >= sp.count) focusIndex = 0;
198
202
  const tabStop = value > 0 ? Math.ceil(value) - 1 : focusIndex;
@@ -236,6 +240,7 @@ export function createRating(): SomaComponentDefinition {
236
240
  disabled: { type: 'boolean', default: false },
237
241
  readonly: { type: 'boolean', default: false, desc: '只读展示(role=img)' },
238
242
  ...ID_PROPS,
243
+ ...INVALID_PROPS,
239
244
  size: SIZE_PROP,
240
245
  class: CLASS_PROP,
241
246
  },