soma-kit 0.1.11 → 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 (376) hide show
  1. package/README.md +106 -112
  2. package/bin/soma-kit.mjs +32 -2
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +14 -7
  5. package/packs/finance/reconcile-board.ts +5 -2
  6. package/packs/finance/reconcile-desk/compile.ts +3 -2
  7. package/spec/generated/kit-app.schema.json +929 -37
  8. package/spec/generated/kit-page.schema.json +1684 -161
  9. package/spec/kit-grammar.json +1176 -584
  10. package/spec/kit-grammar.schema.json +1971 -393
  11. package/src/app/app-config.ts +449 -347
  12. package/src/app/component-gate.ts +283 -28
  13. package/src/app/compose-apps.ts +79 -8
  14. package/src/app/define-kit-actions.ts +245 -41
  15. package/src/app/define-kit-app.ts +176 -33
  16. package/src/app/define-kit-view.ts +104 -0
  17. package/src/app/dev-diagnostic.ts +5 -0
  18. package/src/app/envelope.ts +1 -161
  19. package/src/app/index.ts +29 -6
  20. package/src/app/kit-view-context.ts +439 -0
  21. package/src/app/notify-renderer.ts +1 -115
  22. package/src/app/paged-list-adapter.ts +1 -240
  23. package/src/app/render-ports.ts +18 -0
  24. package/src/app/server-pages.ts +11 -3
  25. package/src/app/server.ts +530 -103
  26. package/src/app/submit.types.ts +1 -1
  27. package/src/app/theme-endpoint.ts +63 -0
  28. package/src/app/theme-runtime-shared.ts +1 -0
  29. package/src/app/theme-runtime.ts +667 -0
  30. package/src/base/action-busy.ts +103 -6
  31. package/src/base/action-gate.ts +4 -255
  32. package/src/base/action-slots.ts +58 -0
  33. package/src/base/alert.ts +5 -3
  34. package/src/base/anchored-layer.ts +50 -0
  35. package/src/base/avatar.ts +2 -2
  36. package/src/base/button.ts +99 -37
  37. package/src/base/cascader.ts +11 -12
  38. package/src/base/check-core.ts +9 -1
  39. package/src/base/checkbox.ts +2 -1
  40. package/src/base/choice.ts +49 -28
  41. package/src/base/class-candidates.ts +17 -0
  42. package/src/base/color-picker.ts +16 -11
  43. package/src/base/combobox.ts +5 -3
  44. package/src/base/command-palette.ts +10 -6
  45. package/src/base/context-menu.ts +10 -7
  46. package/src/base/countdown.ts +1 -1
  47. package/src/base/date-range.ts +32 -18
  48. package/src/base/date.ts +135 -28
  49. package/src/base/delta.ts +72 -0
  50. package/src/base/divider.ts +2 -2
  51. package/src/base/end-edge.ts +49 -0
  52. package/src/base/fab.ts +12 -5
  53. package/src/base/gap-value.ts +148 -0
  54. package/src/base/hint-tips.ts +170 -0
  55. package/src/base/icons.ts +8 -0
  56. package/src/base/illustrations.ts +94 -0
  57. package/src/base/image.ts +1 -1
  58. package/src/base/index.ts +35 -11
  59. package/src/base/input.ts +42 -13
  60. package/src/base/kbd.ts +3 -1
  61. package/src/base/link.ts +4 -4
  62. package/src/base/listbox-core.ts +56 -35
  63. package/src/base/loading-gate.ts +186 -0
  64. package/src/base/mentions.ts +7 -6
  65. package/src/base/menu-button.ts +28 -12
  66. package/src/base/menu-core.ts +41 -8
  67. package/src/base/motion/aura.ts +2 -2
  68. package/src/base/motion/hover-3d.ts +3 -3
  69. package/src/base/motion/hover-gallery.ts +2 -2
  70. package/src/base/motion/marquee.ts +3 -3
  71. package/src/base/motion/text-rotate.ts +2 -2
  72. package/src/base/number.ts +93 -80
  73. package/src/base/otp.ts +9 -5
  74. package/src/base/overlay-runtime.ts +235 -0
  75. package/src/base/permission-gate.ts +6 -0
  76. package/src/base/popover.ts +48 -16
  77. package/src/base/popup.ts +143 -19
  78. package/src/base/portal-core.ts +4 -0
  79. package/src/base/price-text.ts +2 -2
  80. package/src/base/progress.ts +2 -2
  81. package/src/base/qr-code.ts +4 -4
  82. package/src/base/qty-stepper.ts +14 -8
  83. package/src/base/radio.ts +2 -1
  84. package/src/base/range.ts +21 -4
  85. package/src/base/rating.ts +12 -7
  86. package/src/base/reason-tip.ts +150 -0
  87. package/src/base/segmented.ts +27 -21
  88. package/src/base/select.ts +4 -3
  89. package/src/base/shared.ts +387 -49
  90. package/src/base/state-panel.ts +346 -0
  91. package/src/base/status-tone.ts +27 -0
  92. package/src/base/sticky-edge.ts +116 -0
  93. package/src/base/swap.ts +10 -7
  94. package/src/base/switch.ts +11 -6
  95. package/src/base/tag-input.ts +20 -16
  96. package/src/base/tag.ts +68 -34
  97. package/src/base/text.ts +80 -18
  98. package/src/base/textarea.ts +37 -11
  99. package/src/base/time-picker.ts +18 -13
  100. package/src/base/tree-select.ts +21 -12
  101. package/src/base/trend-tone.ts +9 -0
  102. package/src/base/upload.ts +48 -14
  103. package/src/base/view-transition.ts +77 -0
  104. package/src/base/virtual-list.ts +107 -1
  105. package/src/biz/approval-desk/compile.ts +23 -41
  106. package/src/biz/approval-desk/shell.ts +11 -8
  107. package/src/biz/auth-panel/compile.ts +37 -52
  108. package/src/biz/auth-panel/index.ts +1 -1
  109. package/src/biz/auth-panel/shell.ts +5 -4
  110. package/src/biz/category-crud/compile.ts +23 -37
  111. package/src/biz/category-crud/shell.ts +2 -1
  112. package/src/biz/checkout-page/compile.ts +22 -5
  113. package/src/biz/checkout-page/shell.ts +4 -3
  114. package/src/biz/compose.ts +13 -27
  115. package/src/biz/define.ts +5 -4
  116. package/src/biz/import-wizard/compile.ts +22 -26
  117. package/src/biz/import-wizard/hub.ts +126 -61
  118. package/src/biz/import-wizard/shell.ts +5 -4
  119. package/src/biz/index.ts +3 -3
  120. package/src/biz/landing-page/compile.ts +19 -3
  121. package/src/biz/link/hub.ts +69 -22
  122. package/src/biz/link/shared.ts +127 -119
  123. package/src/biz/master-sub/compile.ts +127 -48
  124. package/src/biz/master-sub/index.ts +5 -2
  125. package/src/biz/master-sub/shell.ts +95 -18
  126. package/src/biz/multi-board/compile.ts +38 -50
  127. package/src/biz/multi-board/index.ts +18 -1
  128. package/src/biz/multi-board/shell.ts +32 -20
  129. package/src/biz/notification-center/compile.ts +21 -33
  130. package/src/biz/notification-center/shell.ts +6 -4
  131. package/src/biz/page-templates/domain-templates.ts +80 -13
  132. package/src/biz/page-templates/result-page/compile.ts +11 -2
  133. package/src/biz/page-templates/result-page/shell.ts +2 -1
  134. package/src/biz/page-templates/shared.ts +34 -36
  135. package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
  136. package/src/biz/record-detail/compile.ts +48 -43
  137. package/src/biz/record-detail/index.ts +11 -1
  138. package/src/biz/record-detail/shell.ts +8 -6
  139. package/src/biz/settings-center/compile.ts +7 -5
  140. package/src/biz/settings-center/shell.ts +6 -4
  141. package/src/biz/shared/action-host.ts +97 -211
  142. package/src/biz/shared/compile-helpers.ts +98 -0
  143. package/src/biz/shared/coordinator.ts +472 -92
  144. package/src/biz/shared/index.ts +13 -2
  145. package/src/biz/shared/object-aliases.ts +154 -0
  146. package/src/biz/shared/overlay-compile.ts +239 -0
  147. package/src/biz/shared/overlay-shell.ts +209 -0
  148. package/src/biz/shared/pipes.ts +50 -31
  149. package/src/biz/shared/remove-wire.ts +14 -0
  150. package/src/biz/shared/runtime-hub.ts +226 -24
  151. package/src/biz/single-form/compile.ts +16 -37
  152. package/src/biz/single-form/shell.ts +4 -3
  153. package/src/biz/standard-crud/compile.ts +72 -255
  154. package/src/biz/standard-crud/shell.ts +21 -99
  155. package/src/biz/step-form/compile.ts +26 -97
  156. package/src/biz/step-form/hub.ts +34 -41
  157. package/src/biz/step-form/shell.ts +5 -5
  158. package/src/biz/types.ts +4 -3
  159. package/src/cli/core-imports.ts +54 -0
  160. package/src/cli/kit-cli.ts +254 -25
  161. package/src/cli/kit-init.ts +227 -0
  162. package/src/cli/layout-cli.ts +167 -0
  163. package/src/cli/migrate/index.ts +10 -0
  164. package/src/cli/migrate/migrate.ts +248 -0
  165. package/src/cli/migrate/text-utils.ts +306 -0
  166. package/src/cli/migrate/theme-map.ts +104 -0
  167. package/src/cli/migrate/ts-rules.ts +235 -0
  168. package/src/cli/migrate/types.ts +95 -0
  169. package/src/cli/migrate/view-skeleton.ts +159 -0
  170. package/src/cli/migrate/yaml-report.ts +376 -0
  171. package/src/cli/migrate/yaml-rules.ts +465 -0
  172. package/src/cli/service-endpoint-check.ts +425 -0
  173. package/src/cli/source-path-check.d.mts +17 -0
  174. package/src/cli/source-path-check.mjs +334 -0
  175. package/src/cli/view-writes.ts +761 -0
  176. package/src/compile/action-host-attach.ts +21 -29
  177. package/src/compile/closed-set.ts +570 -0
  178. package/src/compile/compile-page.ts +267 -76
  179. package/src/compile/component-candidates.ts +13 -2
  180. package/src/compile/hints.ts +30 -1
  181. package/src/compile/index.ts +1 -0
  182. package/src/compile/kit-error.ts +1 -0
  183. package/src/compile/layout-lint/engine.ts +82 -0
  184. package/src/compile/layout-lint/index.ts +55 -0
  185. package/src/compile/layout-lint/rules-composition.ts +218 -0
  186. package/src/compile/layout-lint/rules-form.ts +192 -0
  187. package/src/compile/layout-lint/rules-table.ts +194 -0
  188. package/src/compile/layout-lint/score.ts +52 -0
  189. package/src/compile/layout-lint/types.ts +51 -0
  190. package/src/compile/locate.ts +21 -1
  191. package/src/compile/parse.ts +370 -41
  192. package/src/compile/redirect.ts +6 -2
  193. package/src/compile/remove-guard.ts +10 -7
  194. package/src/compile/styles.ts +63 -2
  195. package/src/compile/types.ts +31 -3
  196. package/src/compile/view-check.ts +284 -0
  197. package/src/data/amount-breakdown.ts +8 -3
  198. package/src/data/anchor-nav.ts +2 -2
  199. package/src/data/approval-flow.ts +3 -3
  200. package/src/data/assignment-picker.ts +92 -55
  201. package/src/data/async-result-panel.ts +111 -9
  202. package/src/data/breadcrumbs.ts +5 -4
  203. package/src/data/calendar.ts +24 -27
  204. package/src/data/carousel.ts +13 -8
  205. package/src/data/chart.ts +183 -44
  206. package/src/data/checklist.ts +20 -7
  207. package/src/data/code-view.ts +12 -6
  208. package/src/data/comment-thread.ts +7 -4
  209. package/src/data/confirm-dialog.ts +81 -18
  210. package/src/data/context-menu.ts +29 -37
  211. package/src/data/d9-util.ts +2 -18
  212. package/src/data/diff.ts +4 -2
  213. package/src/data/dock.ts +3 -3
  214. package/src/data/embed.ts +233 -30
  215. package/src/data/field-mapper.ts +35 -30
  216. package/src/data/flow-editor-contract.ts +8 -1
  217. package/src/data/flow-editor.ts +113 -108
  218. package/src/data/flow-node-options.ts +120 -0
  219. package/src/data/flow-remote-options.ts +0 -103
  220. package/src/data/footer.ts +2 -2
  221. package/src/data/form-draft-registry.ts +2 -4
  222. package/src/data/gantt.ts +19 -19
  223. package/src/data/hero.ts +4 -3
  224. package/src/data/image-viewer.ts +27 -30
  225. package/src/data/index.ts +5 -2
  226. package/src/data/item-list.ts +48 -31
  227. package/src/data/kanban.ts +82 -52
  228. package/src/data/media-grid.ts +20 -20
  229. package/src/data/mega-menu.ts +6 -4
  230. package/src/data/menu-dom.ts +4 -2
  231. package/src/data/menu.ts +47 -15
  232. package/src/data/mockup.ts +10 -6
  233. package/src/data/modal-dialog.ts +49 -25
  234. package/src/data/navbar.ts +12 -7
  235. package/src/data/notice-list.ts +268 -0
  236. package/src/data/notify-renderer.ts +250 -0
  237. package/src/data/object-form.ts +1360 -666
  238. package/src/data/outcome-watch.ts +61 -2
  239. package/src/data/pager.ts +80 -34
  240. package/src/data/permission-matrix.ts +52 -31
  241. package/src/data/permission-tree.ts +71 -44
  242. package/src/data/pricing-table.ts +30 -14
  243. package/src/data/prompt-dialog.ts +124 -194
  244. package/src/data/reaction-bar.ts +83 -92
  245. package/src/data/read-rollback.ts +73 -0
  246. package/src/data/record-card.ts +26 -5
  247. package/src/data/record-picker.ts +104 -55
  248. package/src/data/redirect.ts +32 -32
  249. package/src/data/remote-options.ts +13 -6
  250. package/src/data/request-console.ts +5 -3
  251. package/src/data/resident.ts +2 -1
  252. package/src/data/result-panel.ts +8 -4
  253. package/src/data/rich-text.ts +61 -55
  254. package/src/data/row-editor.ts +362 -76
  255. package/src/data/rule-builder.ts +26 -20
  256. package/src/data/shape-util.ts +27 -9
  257. package/src/data/stat-group.ts +392 -109
  258. package/src/data/static-lazy.ts +1 -0
  259. package/src/data/static-registry.ts +24 -11
  260. package/src/data/steps.ts +10 -5
  261. package/src/data/survey.ts +27 -32
  262. package/src/data/system-switcher.ts +3 -3
  263. package/src/data/text-action-button.ts +17 -0
  264. package/src/data/timeline.ts +19 -8
  265. package/src/data/tour-guide.ts +23 -30
  266. package/src/data/transfer.ts +62 -38
  267. package/src/data/tree-table.ts +152 -78
  268. package/src/data/tree.ts +49 -36
  269. package/src/data/trend-line.ts +6 -24
  270. package/src/data/virtual-rows.ts +133 -82
  271. package/src/data/watermark.ts +2 -2
  272. package/src/data/wrap.ts +63 -38
  273. package/src/data/wrapped-candidates.ts +10 -0
  274. package/src/frames/blank-frame.ts +1 -0
  275. package/src/frames/index.ts +2 -2
  276. package/src/frames/page-bar.ts +26 -24
  277. package/src/frames/page-header.ts +14 -5
  278. package/src/frames/page-status.ts +9 -7
  279. package/src/frames/shared.ts +36 -25
  280. package/src/frames/single-frame.ts +1 -0
  281. package/src/frames/split-frame/shell.ts +6 -6
  282. package/src/frames/split-frame/wiring.ts +2 -2
  283. package/src/frames/tabs-frame/shell.ts +4 -14
  284. package/src/frames/tabs-frame/wiring.ts +5 -8
  285. package/src/frames/top-main-frame.ts +3 -2
  286. package/src/frames/types.ts +13 -2
  287. package/src/frames/workspace-frame/extras.ts +21 -5
  288. package/src/frames/workspace-frame/index.ts +1 -1
  289. package/src/frames/workspace-frame/shell.ts +3 -2
  290. package/src/frames/workspace-frame/state.ts +13 -6
  291. package/src/frames/workspace-frame/view.ts +250 -48
  292. package/src/generated/kit-grammar-runtime.ts +645 -397
  293. package/src/generated/page-origin.ts +0 -11
  294. package/src/i18n/kit-text.ts +84 -29
  295. package/src/i18n/resolve-text-refs.ts +22 -6
  296. package/src/index.ts +2 -1
  297. package/src/object-renderer/action-gate.ts +11 -147
  298. package/src/object-renderer/arrange.ts +112 -84
  299. package/src/object-renderer/collapse-wiring.ts +2 -2
  300. package/src/object-renderer/collection-expand.ts +2 -2
  301. package/src/object-renderer/collection-parts.ts +401 -104
  302. package/src/object-renderer/collection-table.ts +287 -45
  303. package/src/object-renderer/collection.ts +258 -104
  304. package/src/object-renderer/compile-data.ts +112 -102
  305. package/src/object-renderer/crud-bridge.ts +32 -0
  306. package/src/object-renderer/defaults.ts +38 -16
  307. package/src/object-renderer/display-checks.ts +4 -25
  308. package/src/object-renderer/emit-events.ts +224 -176
  309. package/src/object-renderer/emit-object.ts +15 -2
  310. package/src/object-renderer/emit-static.ts +533 -151
  311. package/src/object-renderer/field-value.ts +593 -396
  312. package/src/object-renderer/filter-reload.ts +70 -0
  313. package/src/object-renderer/form-detail.ts +111 -2
  314. package/src/object-renderer/form-notify.ts +45 -0
  315. package/src/object-renderer/index.ts +26 -0
  316. package/src/object-renderer/key-field.ts +12 -0
  317. package/src/object-renderer/layout-facts.ts +386 -0
  318. package/src/object-renderer/layout-plan.ts +132 -0
  319. package/src/object-renderer/layout-plan.types.ts +22 -0
  320. package/src/object-renderer/linkage.ts +7 -270
  321. package/src/object-renderer/merge-class.ts +18 -1
  322. package/src/object-renderer/parts.ts +252 -1
  323. package/src/object-renderer/path-pick.ts +27 -0
  324. package/src/object-renderer/render-object.ts +456 -89
  325. package/src/object-renderer/request-actions.ts +232 -249
  326. package/src/object-renderer/skeleton.ts +58 -19
  327. package/src/object-renderer/table-actions.ts +319 -111
  328. package/src/object-renderer/table-summary.ts +2 -2
  329. package/src/object-renderer/table-tools.ts +429 -94
  330. package/src/object-renderer/types.ts +204 -127
  331. package/src/object-renderer/view-binding.ts +393 -0
  332. package/src/page-target/ai-surface.ts +37 -0
  333. package/src/page-target/compile.ts +48 -8
  334. package/src/page-target/index.ts +8 -1
  335. package/src/page-target/intent-schema.ts +165 -28
  336. package/src/page-target/target.ts +262 -51
  337. package/src/page-target/writer-policy.ts +14 -3
  338. package/src/recipes/container.ts +210 -0
  339. package/src/recipes/control.ts +277 -0
  340. package/src/recipes/index.ts +312 -0
  341. package/src/recipes/nowrap.ts +16 -0
  342. package/src/recipes/overlay.ts +240 -0
  343. package/src/recipes/placeholder.ts +79 -0
  344. package/src/recipes/rail-grid.ts +45 -0
  345. package/src/recipes/slot-align.ts +56 -0
  346. package/src/recipes/state.ts +99 -0
  347. package/src/recipes/status.ts +139 -0
  348. package/src/recipes/surface.ts +40 -0
  349. package/src/recipes/table-row.ts +88 -0
  350. package/src/recipes/title-row.ts +37 -0
  351. package/src/recipes/typography.ts +99 -0
  352. package/src/shared/action-field-guard.ts +41 -0
  353. package/src/shared/confirm-decl.ts +118 -0
  354. package/src/shared/envelope.ts +207 -0
  355. package/src/shared/escape.ts +57 -0
  356. package/src/shared/kit-error.ts +21 -0
  357. package/src/shared/paged-list-adapter.ts +15 -0
  358. package/src/shared/path-guard.ts +127 -0
  359. package/src/shared/theme-runtime-shared.ts +180 -0
  360. package/src/shared/view-info.ts +10 -0
  361. package/src/theme/index.ts +13 -0
  362. package/src/theme/kit-theme-text.ts +1 -1
  363. package/src/theme/kit-theme.css +407 -10
  364. package/src/theme/kit-theme.tpl +407 -10
  365. package/src/theme/nine-dim-structure.ts +247 -0
  366. package/src/theme/surface-layers.ts +101 -0
  367. package/src/theme/theme-tokens.ts +130 -84
  368. package/src/theme/theme-types.ts +103 -0
  369. package/src/theme/typography.ts +17 -17
  370. package/src/biz/shared/step-values.ts +0 -25
  371. package/src/biz/step-form/steps-ref.ts +0 -112
  372. package/src/data/options-bus.ts +0 -24
  373. package/src/object-renderer/adopt-gate.ts +0 -333
  374. package/src/object-renderer/field-policy.ts +0 -89
  375. package/src/object-renderer/outcome-draft.ts +0 -61
  376. package/src/theme/nine-dim-palettes.ts +0 -1473
@@ -0,0 +1,186 @@
1
+ // 加载反馈时序:「延迟出现 + 最短显示」纯状态机 + 计时器外壳。
2
+ //
3
+ // 目的:
4
+ // 1. 快请求(在 delayMs 内完成)全程不进入 visible,不显示任何指示器(零闪屏);
5
+ // 2. 一旦进入 visible,即使请求随即完成也至少保持 minVisibleMs,防止一闪而过;
6
+ // 3. 从 visible 结束时进入短暂 done 过渡态停留 doneHoldMs 后回到 idle。
7
+ //
8
+ // 三个时长读真源 structure.loadingFeedback(delayMs / minVisibleMs / doneHoldMs,经 foundation 投影),本文件不写字面量。
9
+ // 状态转移是纯函数 `stepLoadingFeedback`(入参含当前时刻,不碰计时器、不读时钟),便于假时钟测试;
10
+ // `createLoadingGate` 只负责把它接到 setTimeout / Date.now 与回调上。
11
+
12
+ import { KIT_NINE_DIM } from 'soma-foundation/kit-nine-dim';
13
+
14
+ export type KitLoadingPhase = 'idle' | 'pending-delay' | 'visible' | 'done';
15
+
16
+ export interface KitLoadingGateOptions {
17
+ /** 延迟出现阈值(毫秒),缺省读真源 loadingFeedback.delayMs:在此时间内完成则不显示 loading 态 */
18
+ delayMs?: number;
19
+ /** 最短可见停留阈值(毫秒),缺省读真源 loadingFeedback.minVisibleMs:进入 visible 后至少保持此时长 */
20
+ minDurationMs?: number;
21
+ /** 完成态停留阈值(毫秒),缺省读真源 loadingFeedback.doneHoldMs:从 visible 结束时停留 done 态的时长 */
22
+ doneHoldMs?: number;
23
+ /** 状态变化回调(也可通过 createLoadingGate 第二参数传入) */
24
+ onChange?: (phase: KitLoadingPhase) => void;
25
+ }
26
+
27
+ export interface KitLoadingGate {
28
+ start(): void;
29
+ finish(): void;
30
+ cancel(): void;
31
+ phase(): KitLoadingPhase;
32
+ isVisible(): boolean;
33
+ }
34
+
35
+ const FEEDBACK = KIT_NINE_DIM.structure.loadingFeedback;
36
+
37
+ export const KIT_LOADING_GATE_DEFAULTS = Object.freeze({
38
+ delayMs: FEEDBACK.delayMs,
39
+ minDurationMs: FEEDBACK.minVisibleMs,
40
+ doneHoldMs: FEEDBACK.doneHoldMs,
41
+ } as const);
42
+
43
+ // ---------------------------------------------------------------- 纯状态机
44
+
45
+ export interface LoadingFeedbackConfig {
46
+ readonly delayMs: number;
47
+ readonly minVisibleMs: number;
48
+ readonly doneHoldMs: number;
49
+ }
50
+
51
+ export interface LoadingFeedbackState {
52
+ readonly phase: KitLoadingPhase;
53
+ /** 进入当前阶段的时刻(毫秒时间戳) */
54
+ readonly since: number;
55
+ /** visible 期间是否已收到 finish(等最短显示期满后退出) */
56
+ readonly finishing: boolean;
57
+ }
58
+
59
+ export type LoadingFeedbackEvent =
60
+ | { readonly type: 'start' }
61
+ | { readonly type: 'finish' }
62
+ | { readonly type: 'cancel' }
63
+ | { readonly type: 'tick' };
64
+
65
+ export interface LoadingFeedbackStep {
66
+ readonly state: LoadingFeedbackState;
67
+ /** 下一次需要送 tick 的时刻;null = 不需要计时 */
68
+ readonly wakeAt: number | null;
69
+ }
70
+
71
+ export const LOADING_FEEDBACK_IDLE: LoadingFeedbackState = Object.freeze({ phase: 'idle', since: 0, finishing: false });
72
+
73
+ /** 到期的阶段推进(可连续推进多步,如 visible 期满且 doneHold 为 0 直接回 idle) */
74
+ function settle(state: LoadingFeedbackState, now: number, cfg: LoadingFeedbackConfig): LoadingFeedbackState {
75
+ let s = state;
76
+ for (;;) {
77
+ if (s.phase === 'pending-delay' && now - s.since >= cfg.delayMs) {
78
+ s = { phase: 'visible', since: s.since + cfg.delayMs, finishing: false };
79
+ } else if (s.phase === 'visible' && s.finishing && now - s.since >= cfg.minVisibleMs) {
80
+ const at = s.since + cfg.minVisibleMs;
81
+ s = cfg.doneHoldMs <= 0 ? LOADING_FEEDBACK_IDLE : { phase: 'done', since: at, finishing: false };
82
+ } else if (s.phase === 'done' && now - s.since >= cfg.doneHoldMs) {
83
+ s = LOADING_FEEDBACK_IDLE;
84
+ } else {
85
+ return s;
86
+ }
87
+ }
88
+ }
89
+
90
+ function wakeOf(s: LoadingFeedbackState, cfg: LoadingFeedbackConfig): number | null {
91
+ if (s.phase === 'pending-delay') return s.since + cfg.delayMs;
92
+ if (s.phase === 'visible' && s.finishing) return s.since + cfg.minVisibleMs;
93
+ if (s.phase === 'done') return s.since + cfg.doneHoldMs;
94
+ return null;
95
+ }
96
+
97
+ /**
98
+ * 纯转移:(状态, 事件, 当前时刻, 配置) → (新状态, 下次唤醒时刻)。
99
+ * - start:从任何阶段重新开始;delayMs 为 0 直接 visible,否则 pending-delay;
100
+ * - finish:pending-delay 内完成 → 直接 idle(全程不显示);visible 内完成 → 记 finishing,满 minVisibleMs 后退出;idle / done 忽略;
101
+ * - cancel:立即回 idle;
102
+ * - tick:只做到期推进。
103
+ * 同一时刻先把已到期的阶段推进完,再处理事件。
104
+ */
105
+ export function stepLoadingFeedback(
106
+ state: LoadingFeedbackState,
107
+ event: LoadingFeedbackEvent,
108
+ now: number,
109
+ cfg: LoadingFeedbackConfig,
110
+ ): LoadingFeedbackStep {
111
+ let s = settle(state, now, cfg);
112
+ switch (event.type) {
113
+ case 'start':
114
+ s = cfg.delayMs <= 0 ? { phase: 'visible', since: now, finishing: false } : { phase: 'pending-delay', since: now, finishing: false };
115
+ break;
116
+ case 'finish':
117
+ if (s.phase === 'pending-delay') s = LOADING_FEEDBACK_IDLE;
118
+ else if (s.phase === 'visible' && !s.finishing) {
119
+ if (now - s.since >= cfg.minVisibleMs) {
120
+ s = cfg.doneHoldMs <= 0 ? LOADING_FEEDBACK_IDLE : { phase: 'done', since: now, finishing: false };
121
+ } else {
122
+ s = { ...s, finishing: true };
123
+ }
124
+ }
125
+ break;
126
+ case 'cancel':
127
+ s = LOADING_FEEDBACK_IDLE;
128
+ break;
129
+ case 'tick':
130
+ break;
131
+ }
132
+ return { state: s, wakeAt: wakeOf(s, cfg) };
133
+ }
134
+
135
+ // ---------------------------------------------------------------- 计时器外壳
136
+
137
+ function resolveMs(val: number | undefined, fallback: number): number {
138
+ return typeof val === 'number' && Number.isFinite(val) && val >= 0 ? val : fallback;
139
+ }
140
+
141
+ export function createLoadingGate(
142
+ options?: KitLoadingGateOptions | ((phase: KitLoadingPhase) => void),
143
+ onChange?: (phase: KitLoadingPhase) => void,
144
+ ): KitLoadingGate {
145
+ const opts: KitLoadingGateOptions = typeof options === 'function' ? { onChange: options } : (options ?? {});
146
+ const notify = onChange ?? opts.onChange;
147
+ const cfg: LoadingFeedbackConfig = {
148
+ delayMs: resolveMs(opts.delayMs, KIT_LOADING_GATE_DEFAULTS.delayMs),
149
+ minVisibleMs: resolveMs(opts.minDurationMs, KIT_LOADING_GATE_DEFAULTS.minDurationMs),
150
+ doneHoldMs: resolveMs(opts.doneHoldMs, KIT_LOADING_GATE_DEFAULTS.doneHoldMs),
151
+ };
152
+
153
+ let state: LoadingFeedbackState = LOADING_FEEDBACK_IDLE;
154
+ let timer: ReturnType<typeof setTimeout> | undefined;
155
+
156
+ const clearTimer = (): void => {
157
+ if (timer !== undefined) {
158
+ clearTimeout(timer);
159
+ timer = undefined;
160
+ }
161
+ };
162
+
163
+ const apply = (event: LoadingFeedbackEvent): void => {
164
+ const now = Date.now();
165
+ const before = state.phase;
166
+ const step = stepLoadingFeedback(state, event, now, cfg);
167
+ state = step.state;
168
+ clearTimer();
169
+ if (step.wakeAt !== null) {
170
+ timer = setTimeout(() => {
171
+ timer = undefined;
172
+ apply({ type: 'tick' });
173
+ }, Math.max(0, step.wakeAt - now));
174
+ }
175
+ // 一次推进可能连跨几个阶段(如 visible → done → idle);对外只报最终阶段的变化
176
+ if (state.phase !== before) notify?.(state.phase);
177
+ };
178
+
179
+ return {
180
+ start: () => apply({ type: 'start' }),
181
+ finish: () => apply({ type: 'finish' }),
182
+ cancel: () => apply({ type: 'cancel' }),
183
+ phase: () => state.phase,
184
+ isVisible: () => state.phase === 'visible',
185
+ };
186
+ }
@@ -17,7 +17,7 @@ import {
17
17
  cssEscape, createListNav, onOutsidePress, optionClass, scrollIntoViewIfAny,
18
18
  } from './popup';
19
19
  import {
20
- CLASS_PROP, ID_PROPS, OPTIONS_PROP, SIZE_PROP,
20
+ CLASS_PROP, ID_PROPS, INVALID_PROPS, OPTIONS_PROP, SIZE_PROP,
21
21
  applyCommon, applyDisabled, bool, classCandidates, createKitController, joinClass, nextUid, num, optionsOf, setAttr, setBoolAttr, sizeOf, str,
22
22
  type KitOption, type KitProps, type KitSize,
23
23
  } from './shared';
@@ -108,6 +108,7 @@ export function createMentions(): SomaComponentDefinition {
108
108
  disabled: { type: 'boolean', default: false },
109
109
  readonly: { type: 'boolean', default: false },
110
110
  ...ID_PROPS,
111
+ ...INVALID_PROPS,
111
112
  size: SIZE_PROP,
112
113
  class: CLASS_PROP,
113
114
  },
@@ -119,16 +120,16 @@ export function createMentions(): SomaComponentDefinition {
119
120
  },
120
121
  templateHtml:
121
122
  `<div data-soma-id="root" class="${WRAP}">` +
122
- `<textarea data-soma-id="area" rows="3" aria-haspopup="listbox" class="${AREA.md}"></textarea>` +
123
+ `<textarea data-soma-id="area" rows="3" aria-haspopup="listbox" data-kit-face="field" class="${AREA.md}"></textarea>` +
123
124
  `<div data-soma-id="panel" role="listbox" class="${PANEL_HIDDEN_CLASS}"></div>` +
124
125
  `<div data-soma-id="status" role="status" class="${STATUS}"></div></div>`,
125
- controllerFactory: (ctx) => {
126
+ controllerFactory: createKitController((api) => {
126
127
  let hit: MentionHit | null = null;
127
128
  let cursor: string | null = null;
128
129
  let lastQuery: string | null = null;
129
130
  let paintFn: (() => void) | null = null;
130
131
 
131
- return createKitController({
132
+ return {
132
133
  attach(root, api) {
133
134
  const area = root.querySelector<HTMLTextAreaElement>('[data-soma-id="area"], [data-soma-scoped-id="area"]') as HTMLTextAreaElement;
134
135
  const panel = root.querySelector<HTMLElement>('[data-soma-id="panel"], [data-soma-scoped-id="panel"]') as HTMLElement;
@@ -317,7 +318,7 @@ export function createMentions(): SomaComponentDefinition {
317
318
  root.className = joinClass(WRAP, p.class);
318
319
  paintFn?.();
319
320
  },
320
- })(ctx);
321
- },
321
+ };
322
+ }),
322
323
  };
323
324
  }
@@ -4,12 +4,16 @@
4
4
 
5
5
  import type { SomaComponentDefinition } from 'soma-core';
6
6
  import { kitText } from '../i18n/kit-text';
7
+ import { mergeClass } from '../object-renderer/merge-class';
7
8
  import { kitIconHtml } from './icons';
8
9
  import {
9
10
  CLASS_PROP, ID_PROPS, SIZE_PROP, TOOLTIP_PROP, BADGE_PROPS, KIT_BADGE_CLASS_CANDIDATES,
10
11
  applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setBoolAttr, sizeOf, str, withBadgeAnchor, withTooltip,
11
12
  type KitSize, type KitView,
12
13
  } from './shared';
14
+ import { kitTypographyRecipe, setKitFace } from '../recipes';
15
+ import { kitButtonNoWrapMap } from '../recipes/nowrap';
16
+ import { kitSurfaceRecipe } from '../recipes/surface';
13
17
  import { menuItemsOf, wireMenu, type MenuClasses, type MenuHandle } from './menu-core';
14
18
  import { KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, popPlaceClass, type PopPlace } from './popup';
15
19
  import {
@@ -21,25 +25,31 @@ const ROOT_CONTEXT_CLASS = 'relative block';
21
25
  export type MenuButtonVariant = 'primary' | 'neutral' | 'ghost';
22
26
 
23
27
  const ROOT_CLASS = 'relative inline-block';
24
- const TRIGGER_CLASS: Record<MenuButtonVariant, Record<KitSize, string>> = {
28
+ const TRIGGER_CLASS_RAW: Record<MenuButtonVariant, Record<KitSize, string>> = {
25
29
  primary: {
26
- sm: 'inline-flex h-8 items-center justify-center gap-1 rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
27
- md: 'inline-flex h-9 items-center justify-center gap-2 rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
30
+ sm: 'inline-flex h-6 items-center justify-center gap-1 rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
31
+ md: 'inline-flex h-8 items-center justify-center gap-2 rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
28
32
  lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md bg-primary px-5 text-base font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
29
33
  },
30
34
  neutral: {
31
- sm: 'inline-flex h-8 items-center justify-center gap-1 rounded-md border border-border bg-surface px-3 text-sm font-medium text-fg transition-colors enabled:hover:bg-surface-sunken enabled:active:bg-border-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
32
- md: 'inline-flex h-9 items-center justify-center gap-2 rounded-md border border-border bg-surface px-4 text-sm font-medium text-fg transition-colors enabled:hover:bg-surface-sunken enabled:active:bg-border-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
33
- lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md border border-border bg-surface px-5 text-base font-medium text-fg transition-colors enabled:hover:bg-surface-sunken enabled:active:bg-border-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
35
+ sm: 'inline-flex h-6 items-center justify-center gap-1 rounded-md border border-button-edge bg-surface px-3 text-sm font-medium 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',
36
+ md: 'inline-flex h-8 items-center justify-center gap-2 rounded-md border border-button-edge bg-surface px-4 text-sm font-medium 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',
37
+ lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md border border-button-edge bg-surface px-5 text-base font-medium 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',
34
38
  },
35
39
  ghost: {
36
- sm: 'inline-flex h-8 items-center justify-center gap-1 rounded-md px-3 text-sm font-medium text-fg transition-colors enabled:hover:bg-fg/8 enabled:active:bg-fg/12 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
37
- md: 'inline-flex h-9 items-center justify-center gap-2 rounded-md px-4 text-sm font-medium text-fg transition-colors enabled:hover:bg-fg/8 enabled:active:bg-fg/12 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
38
- lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md px-5 text-base font-medium text-fg transition-colors enabled:hover:bg-fg/8 enabled:active:bg-fg/12 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
40
+ sm: 'inline-flex h-6 items-center justify-center gap-1 rounded-md px-3 text-sm font-medium text-fg transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
41
+ md: 'inline-flex h-8 items-center justify-center gap-2 rounded-md px-4 text-sm font-medium text-fg transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
42
+ lg: 'inline-flex h-10 items-center justify-center gap-2 rounded-md px-5 text-base font-medium text-fg transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
39
43
  },
40
44
  };
45
+ // 触发钮文案单行(「更多」「操作」等不逐字折行)
46
+ const TRIGGER_CLASS: Record<MenuButtonVariant, Record<KitSize, string>> = {
47
+ primary: kitButtonNoWrapMap(TRIGGER_CLASS_RAW.primary),
48
+ neutral: kitButtonNoWrapMap(TRIGGER_CLASS_RAW.neutral),
49
+ ghost: kitButtonNoWrapMap(TRIGGER_CLASS_RAW.ghost),
50
+ };
41
51
  const MENU_HIDDEN = 'hidden';
42
- const MENU_BASE = 'absolute z-10 flex min-w-40 flex-col rounded-lg border border-border-subtle bg-surface-raised p-1 shadow-lg';
52
+ const MENU_BASE = mergeClass('absolute z-10 flex min-w-40 flex-col p-1', kitSurfaceRecipe('raised'));
43
53
  /** 默认偏好:触发钮下方、左对齐;贴边时由 popup.ts 在闭集位置间翻转 */
44
54
  const MENU_PREF: PopPlace = { side: 'bottom', align: 'start' };
45
55
  const menuClass = (place: PopPlace): string => `${MENU_BASE} ${popPlaceClass(place, 1)}`;
@@ -52,11 +62,13 @@ export const KIT_MENU_PANEL = {
52
62
  ghostTrigger: (): string => TRIGGER_CLASS.ghost.sm,
53
63
  } as const;
54
64
  export const KIT_MENU_ITEM_CLASSES: MenuClasses = {
55
- idle: 'flex cursor-pointer h-9 items-center gap-2 rounded-md px-3 text-sm text-fg transition-colors hover:bg-fg/8 active:bg-fg/12 focus-visible:bg-fg/10 focus-visible:outline-none',
65
+ idle: 'flex cursor-pointer h-9 items-center gap-2 rounded-md px-3 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:bg-state-layer-hover focus-visible:outline-none',
56
66
  danger: 'flex cursor-pointer h-9 items-center gap-2 rounded-md px-3 text-sm text-danger-on-soft transition-colors hover:bg-danger-soft focus-visible:bg-danger-soft focus-visible:outline-none',
57
67
  disabled: 'flex cursor-not-allowed h-9 items-center gap-2 rounded-md px-3 text-sm text-fg-subtle opacity-60',
58
68
  divider: 'my-1 h-px bg-border-subtle',
59
69
  icon: 'inline-block shrink-0',
70
+ // 置灰项的原因描述(行内第二段文字,贴右、弱色小字)
71
+ desc: mergeClass(kitTypographyRecipe('caption'), 'ms-auto ps-3'),
60
72
  };
61
73
  const MENU_CLASSES = KIT_MENU_ITEM_CLASSES;
62
74
  const CARET_CLASS = 'inline-flex';
@@ -176,6 +188,8 @@ function makeView(): KitView {
176
188
  applyCommon(btn, { id: split ? '' : p.id, aria_label: split ? str(p.more_label, kitText('soma.kit.more_actions', undefined, btn)) : p.aria_label });
177
189
  const base = ctx ? (off ? CONTEXT_AREA_OFF : CONTEXT_AREA) : TRIGGER_CLASS[variant][size];
178
190
  btn.className = split ? `${base} ${SPLIT_TRIGGER_CLASS[variant]}` : base;
191
+ // 质感标记:实心 / 描边变体有面标 raised;ghost 与右键虚线区不标
192
+ setKitFace(btn, ctx || variant === 'ghost' ? null : 'raised');
179
193
  }
180
194
  if (main) {
181
195
  if (split) {
@@ -185,8 +199,10 @@ function makeView(): KitView {
185
199
  else main.removeAttribute('aria-disabled');
186
200
  applyCommon(main, { id: p.id, aria_label: p.aria_label });
187
201
  main.className = `${TRIGGER_CLASS[variant][size]} ${SPLIT_MAIN_CLASS}`;
202
+ setKitFace(main, variant === 'ghost' ? null : 'raised');
188
203
  badgeHost = main;
189
204
  } else {
205
+ setKitFace(main, null);
190
206
  main.textContent = '';
191
207
  main.className = MENU_HIDDEN;
192
208
  }
@@ -235,6 +251,6 @@ export function createMenuButton(): SomaComponentDefinition {
235
251
  },
236
252
  },
237
253
  templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"><button type="button" class="${TRIGGER_CLASS.neutral.md}"><span></span><span aria-hidden="true" class="${CARET_CLASS}">${kitIconHtml('chevron-down', 'sm')}</span></button><div class="${MENU_HIDDEN}"></div><button type="button" class="${MENU_HIDDEN}"></button></div>`,
238
- controllerFactory: (ctx) => createKitController(withTooltip(makeView(), tooltipTarget))(ctx),
254
+ controllerFactory: createKitController(() => withTooltip(makeView(), tooltipTarget)),
239
255
  };
240
256
  }
@@ -10,7 +10,10 @@
10
10
  import type { CollectionItem } from 'soma-core/keyboard';
11
11
  import { createListNav, createPanelPortal, onOutsidePress, showMenuAtPoint, showPopupFitted, type ListNav, type PopPlace } from './popup';
12
12
  import type { PointPanel } from './portal-core';
13
+ import { KIT_ANCHORED_ATTR, leaveAnchored, unmarkAnchored } from './anchored-layer';
14
+ import type { KitLeaveHandle } from './overlay-runtime';
13
15
  import { nextUid } from './shared';
16
+ import { setKitFace, type KitFaceKind } from '../recipes';
14
17
 
15
18
  /** 浮层端口缺失时的降级提示,整个页面只提示一次 */
16
19
  let pointFallbackWarned = false;
@@ -25,6 +28,8 @@ export interface MenuItemSpec {
25
28
  danger: boolean;
26
29
  /** 分隔线(此时只有 key 有意义) */
27
30
  divider: boolean;
31
+ /** 置灰原因(只对 disabled 项有意义):项里多一段可见的描述文字,项带 aria-describedby 指向它;空 / 缺省不画 */
32
+ reason?: string;
28
33
  }
29
34
 
30
35
  /** 菜单项归一:`[{ key, label, icon?, disabled?, danger?, divider? }]`;key 重复的第二项起丢弃,分隔线不要求 label */
@@ -62,6 +67,8 @@ export interface MenuClasses {
62
67
  disabled: string;
63
68
  divider: string;
64
69
  icon: string;
70
+ /** 置灰原因描述文字的类(项带 reason 时用;缺省不加类) */
71
+ desc?: string;
65
72
  }
66
73
 
67
74
  /** 面板挂载端口(实现见 data/overlay-portal 的 createPanelPortal;这里只认形状,base 不依赖 data) */
@@ -98,6 +105,8 @@ export interface MenuWireOptions {
98
105
  /** 按点挂出时的整串面板类(必须含 fixed) */
99
106
  pointClass?: string;
100
107
  classes: MenuClasses;
108
+ /** 菜单项自带底色 + 边框 + 阴影(Fab 的药丸项)时给每项打质感标记;平铺菜单项不传 */
109
+ rowFace?: KitFaceKind;
101
110
  items: () => MenuItemSpec[];
102
111
  /** 触发钮被禁用 / 只读:不能打开 */
103
112
  locked: () => boolean;
@@ -122,6 +131,18 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
122
131
  const portal: MenuPortal = o.portal ?? createPanelPortal(trigger);
123
132
  let open = false;
124
133
  let pointPanel: PointPanel | null = null;
134
+ // 出场(隐藏前过渡,与其他锚定浮层同一机制):播完退场动画再放回原位 / 整串 hidden;没有退场动画则立即收尾
135
+ let leaving: KitLeaveHandle | null = null;
136
+ const finishHide = (): void => {
137
+ leaving = null;
138
+ portal.hide(true);
139
+ if (pointPanel !== null) {
140
+ pointPanel.hide(true);
141
+ pointPanel = null;
142
+ }
143
+ menu.className = o.hiddenClass;
144
+ unmarkAnchored(menu);
145
+ };
125
146
  let cursor: string | null = null;
126
147
  let builtKey = '';
127
148
  const menuId = menu.id !== '' ? menu.id : nextUid('kit-menu');
@@ -163,6 +184,15 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
163
184
  const label = document.createElement('span');
164
185
  label.textContent = item.label;
165
186
  row.appendChild(label);
187
+ const reason = item.disabled && item.reason !== undefined ? item.reason.trim() : '';
188
+ if (reason !== '') {
189
+ const desc = document.createElement('span');
190
+ desc.id = nextUid('kit-menu-reason');
191
+ if (o.classes.desc !== undefined) desc.className = o.classes.desc;
192
+ desc.textContent = reason;
193
+ row.appendChild(desc);
194
+ row.setAttribute('aria-describedby', desc.id);
195
+ }
166
196
  menu.appendChild(row);
167
197
  }
168
198
  };
@@ -174,9 +204,15 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
174
204
  const el = elOf(item.key);
175
205
  if (!el) continue;
176
206
  el.className = classOf(item);
207
+ if (o.rowFace) setKitFace(el, o.rowFace);
177
208
  if (item.disabled) el.setAttribute('aria-disabled', 'true');
178
209
  else el.removeAttribute('aria-disabled');
179
210
  }
211
+ // 退场中被重新打开:撤销退场
212
+ if (open && leaving !== null) {
213
+ leaving.cancel();
214
+ leaving = null;
215
+ }
180
216
  const pt = open ? (o.point?.() ?? null) : null;
181
217
  const fit = open && pt === null ? (o.fitted?.() ?? null) : null;
182
218
  if (pt !== null) {
@@ -195,16 +231,11 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
195
231
  } else if (fit !== null) {
196
232
  const placed = portal.show(menu, trigger, fit.pref, fit.classFor, { ...(fit.gapPx !== undefined ? { gapPx: fit.gapPx } : {}), onEscape: () => close(true) });
197
233
  if (placed === null) showPopupFitted(menu, trigger, fit.pref, fit.classFor, fit.gapPx);
234
+ } else if (!open) {
235
+ if (leaving === null) leaving = menu.hasAttribute(KIT_ANCHORED_ATTR) ? leaveAnchored(menu, finishHide) : (finishHide(), null);
198
236
  } else {
199
- if (!open) {
200
- portal.hide(true);
201
- if (pointPanel !== null) {
202
- pointPanel.hide(true);
203
- pointPanel = null;
204
- }
205
- }
206
237
  const shown = typeof o.shownClass === 'function' ? o.shownClass() : o.shownClass;
207
- menu.className = open ? shown : o.hiddenClass;
238
+ menu.className = shown;
208
239
  }
209
240
  trigger.setAttribute('aria-haspopup', 'menu');
210
241
  trigger.setAttribute('aria-expanded', open ? 'true' : 'false');
@@ -333,6 +364,8 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
333
364
  scope.removeEventListener('focusout', onFocusOut);
334
365
  menu.removeEventListener('focusout', onFocusOut);
335
366
  offOutside();
367
+ leaving?.cancel();
368
+ leaving = null;
336
369
  portal.hide(true);
337
370
  pointPanel?.hide(true);
338
371
  pointPanel = null;
@@ -71,7 +71,7 @@ export function createAura(): SomaComponentDefinition {
71
71
  '</div>',
72
72
  '</div>',
73
73
  ].join(''),
74
- controllerFactory: createKitController({
74
+ controllerFactory: createKitController(() => ({
75
75
  render(root, p) {
76
76
  const halo = part(root, 'halo');
77
77
  const box = part(root, 'box');
@@ -89,6 +89,6 @@ export function createAura(): SomaComponentDefinition {
89
89
  text.textContent = content;
90
90
  text.className = content === '' ? HIDDEN : TEXT_CLASS;
91
91
  },
92
- }),
92
+ })),
93
93
  };
94
94
  }
@@ -14,7 +14,7 @@ import { safeHref } from '../link';
14
14
  import { HOVER_3D_GRID, MOTION_STRENGTHS, prefersReducedMotion, segmentOf, strengthOf, type MotionStrength } from './limits';
15
15
 
16
16
  const ROOT_CLASS = 'block perspective-normal';
17
- const CARD_CORE = 'block overflow-hidden rounded-lg border border-border-subtle bg-surface text-fg transition-transform motion-reduce:transition-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
17
+ const CARD_CORE = 'block overflow-hidden rounded-lg border border-border-subtle bg-surface text-fg motion-safe:transition-transform focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
18
18
  const CARD_IDLE = `${CARD_CORE} shadow-sm`;
19
19
  const CARD_TILTED = `${CARD_CORE} shadow-md`;
20
20
  const IMAGE_CLASS = 'block h-40 w-full object-cover';
@@ -146,9 +146,9 @@ export function createHover3d(): SomaComponentDefinition {
146
146
  '</a>',
147
147
  '</div>',
148
148
  ].join(''),
149
- controllerFactory: createKitController({
149
+ controllerFactory: createKitController(() => ({
150
150
  attach: attachTilt,
151
151
  render: renderTilt,
152
- }),
152
+ })),
153
153
  };
154
154
  }
@@ -177,9 +177,9 @@ export function createHoverGallery(): SomaComponentDefinition {
177
177
  `<span data-soma-id="status" role="status" class="${SR_ONLY}"></span>`,
178
178
  '</div>',
179
179
  ].join(''),
180
- controllerFactory: createKitController({
180
+ controllerFactory: createKitController(() => ({
181
181
  attach: attachGallery,
182
182
  render: renderGallery,
183
- }),
183
+ })),
184
184
  };
185
185
  }
@@ -31,7 +31,7 @@ const TRACK_PAUSED: Record<Speed, string> = {
31
31
  };
32
32
  const GROUP_SCROLL = 'flex shrink-0 items-center gap-8 pe-8 whitespace-nowrap';
33
33
  const GROUP_STATIC = 'flex flex-wrap items-center gap-x-6 gap-y-1';
34
- const PAUSE_CLASS = 'inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
34
+ const PAUSE_CLASS = 'inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-xs 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 disabled:cursor-not-allowed disabled:opacity-60';
35
35
  const HIDDEN = 'hidden';
36
36
 
37
37
  /** 本组件自带的类 */
@@ -149,9 +149,9 @@ export function createMarquee(): SomaComponentDefinition {
149
149
  `<button data-soma-id="pause" type="button" aria-pressed="false" class="${HIDDEN}">⏸</button>`,
150
150
  '</div>',
151
151
  ].join(''),
152
- controllerFactory: createKitController({
152
+ controllerFactory: createKitController(() => ({
153
153
  attach: attachMarquee,
154
154
  render: renderMarquee,
155
- }),
155
+ })),
156
156
  };
157
157
  }
@@ -187,9 +187,9 @@ export function createTextRotate(): SomaComponentDefinition {
187
187
  `<span data-soma-id="all" class="${SR_ONLY}"></span>`,
188
188
  '</span>',
189
189
  ].join(''),
190
- controllerFactory: createKitController({
190
+ controllerFactory: createKitController(() => ({
191
191
  attach: attachRotate,
192
192
  render: renderRotate,
193
- }),
193
+ })),
194
194
  };
195
195
  }