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
@@ -18,8 +18,24 @@ import {
18
18
  KIT_POPUP_PLACE_CLASS_CANDIDATES, POPUP_TIP_BASE, POPUP_TIP_HIDDEN_CLASS, POPUP_TIP_PREF, POPUP_TIP_SHOWN_CLASS,
19
19
  popupTipClass, showPopupFitted,
20
20
  } from './popup';
21
+ import { classCandidates } from './class-candidates';
22
+ import { leaveAnchored, unmarkAnchored } from './anchored-layer';
23
+ import type { KitLeaveHandle } from './overlay-runtime';
24
+ import { withKitViewTransition } from './view-transition';
21
25
  import { kitBusyOf, onKitActionBusy } from './action-busy';
26
+ import { deniedBy, registerLivePermissionGate } from './permission-gate';
22
27
  import { kitText } from '../i18n/kit-text';
28
+ import { mergeClass } from '../object-renderer/merge-class';
29
+ import {
30
+ KIT_PART_ATTRIBUTE,
31
+ KIT_PART_BADGE,
32
+ kitControlRecipe,
33
+ kitFocusRingRecipe,
34
+ kitInvalidRecipe,
35
+ KIT_TYPOGRAPHY_RECIPE_MAP,
36
+ kitTypographyRecipe,
37
+ type KitTypographyRecipeRole,
38
+ } from '../recipes';
23
39
 
24
40
  // ── 尺寸档 ────────────────────────────────────────────────────
25
41
 
@@ -31,16 +47,39 @@ export function sizeOf(raw: unknown): KitSize {
31
47
  }
32
48
 
33
49
  // ── 文本类控件的统一类串(Input / Textarea 的单行部分 / Number / Date / DateRange / Select)─────
34
- // 约定(参照 daisyUI input 的视觉细节,全部用 kit 语义色与 utilityScales 重新表达):
35
- // 高度 sm 32 / md 36 / lg 40;field 圆角 md;1px 边框;悬停边框加深;聚焦边框变主色并带 2px 焦点环;
36
- // 禁用 = 灰底 + 60% 不透明 + not-allowed;只读 = 灰底。
50
+ // 直接由 kitControlRecipe 与 kitInvalidRecipe 生成,不再维护平行字面量或拆单 token。
51
+
52
+ export const KIT_TYPOGRAPHY: Readonly<Record<KitTypographyRecipeRole, string>> = Object.freeze({
53
+ pageTitle: kitTypographyRecipe('pageTitle'),
54
+ dialogTitle: kitTypographyRecipe('dialogTitle'),
55
+ sectionTitle: kitTypographyRecipe('sectionTitle'),
56
+ statValue: kitTypographyRecipe('statValue'),
57
+ body: kitTypographyRecipe('body'),
58
+ bodyStrong: kitTypographyRecipe('bodyStrong'),
59
+ caption: kitTypographyRecipe('caption'),
60
+ muted: kitTypographyRecipe('muted'),
61
+ code: kitTypographyRecipe('code'),
62
+ label: kitTypographyRecipe('label'),
63
+ });
64
+
65
+ export { KIT_TYPOGRAPHY_RECIPE_MAP };
66
+
67
+ export const FOCUS_RING = kitFocusRingRecipe('control');
37
68
 
38
69
  export const FIELD_CLASS: Record<KitSize, string> = {
39
- sm: 'block h-8 w-full appearance-none autofill-clear rounded-md border border-input bg-surface px-2.5 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle read-only:bg-surface-sunken',
40
- md: 'block h-9 w-full appearance-none autofill-clear rounded-md border border-input bg-surface px-3 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle read-only:bg-surface-sunken',
41
- lg: 'block h-10 w-full appearance-none autofill-clear rounded-md border border-input bg-surface px-4 text-base text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle read-only:bg-surface-sunken',
70
+ sm: mergeClass(kitControlRecipe({ size: 'sm', variant: 'outline' }), 'aria-invalid:border-danger'),
71
+ md: mergeClass(kitControlRecipe({ size: 'md', variant: 'outline' }), 'aria-invalid:border-danger'),
72
+ lg: mergeClass(kitControlRecipe({ size: 'lg', variant: 'outline' }), 'aria-invalid:border-danger'),
42
73
  };
43
74
 
75
+ export const FIELD_INVALID_CLASS = kitInvalidRecipe();
76
+
77
+ export function withInvalid(base: string, invalid: boolean): string {
78
+ return invalid ? `${base} ${FIELD_INVALID_CLASS}` : base;
79
+ }
80
+
81
+ export const KIT_SPINNER_CLASS = 'inline-block h-4 w-4 motion-safe:animate-spin rounded-full border-2 border-border border-t-primary';
82
+
44
83
  // ── props 读取 ────────────────────────────────────────────────
45
84
 
46
85
  export type KitProps = Record<string, unknown>;
@@ -79,6 +118,8 @@ export interface KitOption {
79
118
  label: string;
80
119
  /** 仅 Tag 读:命中该选项时优先于 tone prop */
81
120
  tone?: KitTone;
121
+ /** 选项写了 `tone: unknown`(未知 / 无法判断):tone 按 neutral 归一(不认识 unknown 的组件照 neutral 画),Tag 读此标记画虚线未知外观 */
122
+ unknown?: boolean;
82
123
  disabled?: boolean;
83
124
  /** Radio / Checkbox 读:选项图标(短字符,emoji 或符号);label 为空时是纯图标选项 */
84
125
  icon?: string;
@@ -127,13 +168,15 @@ export function optionsOf(raw: unknown): KitOption[] {
127
168
  const icon = typeof rec.icon === 'string' ? rec.icon : '';
128
169
  // 带 icon 又没写 label = 纯图标选项(label 为空,可访问名取 aria_label,缺省取 value)
129
170
  const label = rec.label !== undefined && rec.label !== null ? String(rec.label) : icon !== '' ? '' : String(rec.value ?? '');
130
- const tone = toneOf(rec.tone, null);
171
+ const unknownTone = rec.tone === 'unknown';
172
+ const tone = unknownTone ? 'neutral' : toneOf(rec.tone, null);
131
173
  push({
132
174
  value: rec.value,
133
175
  label,
134
176
  ...(icon !== '' ? { icon } : {}),
135
177
  ...(typeof rec.aria_label === 'string' && rec.aria_label !== '' ? { aria_label: rec.aria_label } : {}),
136
178
  ...(tone ? { tone } : {}),
179
+ ...(unknownTone ? { unknown: true } : {}),
137
180
  ...(rec.disabled === true ? { disabled: true } : {}),
138
181
  });
139
182
  }
@@ -210,6 +253,11 @@ export interface DisplayResult {
210
253
  * 铁律:只产出文字。有 options 时按选项取 label(命中不到则显示原值);
211
254
  * 没有 options 时 bool、0/1 一律显示原值文字,不变成开关或色块。
212
255
  */
256
+ /** 空值判定(displayOf 与 Tag 共用唯一一份):null / undefined / '' / 空数组 */
257
+ export function valueIsEmpty(value: unknown): boolean {
258
+ return value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0);
259
+ }
260
+
213
261
  export function displayOf(
214
262
  value: unknown,
215
263
  options: readonly KitOption[],
@@ -217,7 +265,9 @@ export function displayOf(
217
265
  locale: string,
218
266
  placeholder: string,
219
267
  ): DisplayResult {
220
- if (value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0)) {
268
+ // 显式空串 '' 是「有意留白」:渲染为空白;null / undefined / 空数组仍按占位(缺省「-」)
269
+ if (value === '') return { text: '', option: null };
270
+ if (valueIsEmpty(value)) {
221
271
  return { text: placeholder, option: null };
222
272
  }
223
273
  if (options.length > 0) {
@@ -250,11 +300,109 @@ export function setAttr(el: Element, name: string, value: string): void {
250
300
  else el.setAttribute(name, value);
251
301
  }
252
302
 
253
- /** 标签关联与可访问名:`id` / `aria-label` / `name` 三个 prop */
303
+ /** 上一次由 applyCommon 写进 aria-describedby 的 id 串(合并时只替换自己写的那部分,不抹掉控件自带的说明 id) */
304
+ const APPLIED_DESCRIBEDBY = new WeakMap<Element, string[]>();
305
+
306
+ /** 空白分隔的 id 串拆成去重的令牌表 */
307
+ function idRefTokens(raw: string): string[] {
308
+ return Array.from(new Set(raw.split(/\s+/).filter((t) => t !== '')));
309
+ }
310
+
311
+ /** 在空白分隔的 id 引用属性里加入一个令牌(已在则不动) */
312
+ export function addIdToken(el: Element, attr: string, id: string): void {
313
+ const tokens = idRefTokens(el.getAttribute(attr) ?? '');
314
+ if (id === '' || tokens.includes(id)) return;
315
+ el.setAttribute(attr, [...tokens, id].join(' '));
316
+ }
317
+
318
+ /** 从空白分隔的 id 引用属性里摘掉一个令牌;摘空则移除属性 */
319
+ export function removeIdToken(el: Element, attr: string, id: string): void {
320
+ const tokens = idRefTokens(el.getAttribute(attr) ?? '');
321
+ if (!tokens.includes(id)) return;
322
+ const rest = tokens.filter((t) => t !== id);
323
+ if (rest.length > 0) el.setAttribute(attr, rest.join(' '));
324
+ else el.removeAttribute(attr);
325
+ }
326
+
327
+ /**
328
+ * 合并写 aria-describedby:保留元素上已有、但不是上次 applyCommon 写入的令牌(控件自带的说明节点),
329
+ * 再并入这次的令牌;重复调用不累积。
330
+ */
331
+ function mergeDescribedby(el: Element, next: string): void {
332
+ const prevOwn = new Set(APPLIED_DESCRIBEDBY.get(el) ?? []);
333
+ const keep = idRefTokens(el.getAttribute('aria-describedby') ?? '').filter((t) => !prevOwn.has(t));
334
+ const own = idRefTokens(next);
335
+ APPLIED_DESCRIBEDBY.set(el, own);
336
+ const merged = [...keep, ...own.filter((t) => !keep.includes(t))];
337
+ if (merged.length > 0) el.setAttribute('aria-describedby', merged.join(' '));
338
+ else el.removeAttribute('aria-describedby');
339
+ }
340
+
341
+ /**
342
+ * 标签关联、可访问名与程序化无障碍校验关联:`id` / `aria-label` / `aria-labelledby` / `name` / `aria-required` / `aria-invalid` / `aria-describedby`(合并)/ `aria-errormessage`。
343
+ * `labelledby` 只在 props 里带了该键(契约声明过)时才写 / 清,避免只传部分键的调用方误清外部写好的名字。
344
+ */
254
345
  export function applyCommon(el: Element, p: KitProps): void {
255
346
  setAttr(el, 'id', str(p.id));
256
- setAttr(el, 'aria-label', str(p.aria_label));
257
347
  setAttr(el, 'name', str(p.name));
348
+ applyAria(el, p);
349
+ }
350
+
351
+ /** applyCommon 去掉 id / name 的部分:名字、标签关联、校验态与说明关联 */
352
+ function applyAria(el: Element, p: KitProps): void {
353
+ setAttr(el, 'aria-label', str(p.aria_label));
354
+ if ('labelledby' in p || 'aria_labelledby' in p) setAttr(el, 'aria-labelledby', str(p.aria_labelledby, str(p.labelledby)));
355
+ // WAI-ARIA 1.2:aria-required / aria-invalid / aria-errormessage 不属于 role=group,写了是无效 ARIA;
356
+ // group 根只留名字与说明关联(+ 一个 data-kit-invalid 标记供表单滚动聚焦),校验态落到组内真正承载值的控件上(见 applyGroupA11y)
357
+ if (el.getAttribute('role') === 'group') {
358
+ el.removeAttribute('aria-required');
359
+ el.removeAttribute('aria-invalid');
360
+ el.removeAttribute('aria-errormessage');
361
+ setAttr(el, KIT_INVALID_MARK, bool(p.invalid) ? 'true' : '');
362
+ } else {
363
+ applyValidity(el, p);
364
+ el.removeAttribute(KIT_INVALID_MARK);
365
+ }
366
+ mergeDescribedby(el, str(p.aria_describedby, str(p.describedby)));
367
+ }
368
+
369
+ /** group 根上的无效标记(ARIA 不允许 group 带 aria-invalid;表单据此找首个出错字段) */
370
+ export const KIT_INVALID_MARK = 'data-kit-invalid';
371
+
372
+ /** 必填 / 无效 / 错误消息关联三个校验属性(只给支持它们的角色:原生输入、radiogroup、combobox、textbox 等) */
373
+ function applyValidity(el: Element, p: KitProps): void {
374
+ if (bool(p.required)) el.setAttribute('aria-required', 'true');
375
+ else el.removeAttribute('aria-required');
376
+ if (bool(p.invalid)) el.setAttribute('aria-invalid', 'true');
377
+ else el.removeAttribute('aria-invalid');
378
+ setAttr(el, 'aria-errormessage', str(p.aria_errormessage, str(p.errormessage)));
379
+ }
380
+
381
+ /**
382
+ * 组类控件(无单一可标注原生元素:radiogroup / group / 自绘组合)的校验与名字写面:
383
+ * 与 applyCommon 同一套 aria 属性,但不碰 id / name(组根不占 id,id 给第一个可聚焦控件)。
384
+ * 组根是 role=group 时(多选组、验证码格组等),必填 / 无效 / 错误消息写到 `targets`(组内承载值的输入),
385
+ * 说明 / 错误节点仍经 aria-describedby 挂在组根上;radiogroup 根支持这些属性,直接写根。
386
+ */
387
+ export function applyGroupA11y(el: Element, p: KitProps, targets: Iterable<Element> = []): void {
388
+ applyAria(el, p);
389
+ if (el.getAttribute('role') !== 'group') return;
390
+ for (const target of targets) applyValidity(target, p);
391
+ }
392
+
393
+ /** 表单传给字段控件的无障碍 props 键:任一有值就说明该控件被当作表单字段用 */
394
+ const FIELD_A11Y_KEYS = ['labelledby', 'aria_labelledby', 'describedby', 'aria_describedby', 'required', 'invalid'] as const;
395
+
396
+ /**
397
+ * 复合字段控件(上传、取色、选记录、穿梭等:根不是原生可标注元素)的字段无障碍写面:
398
+ * 被当作表单字段用(props 里带了标签 / 说明 / 必填 / 无效)时根写 role=group + 名字 + 说明关联,必填 / 无效落到 `targets`;
399
+ * 没有这些 props 时不加角色(与单独使用时的原有输出一致),并清掉上一轮写的。
400
+ */
401
+ export function applyCompositeField(el: Element, p: KitProps, targets: Iterable<Element> = []): void {
402
+ const used = FIELD_A11Y_KEYS.some((k) => { const v = p[k]; return v !== undefined && v !== null && v !== '' && v !== false; });
403
+ if (used) el.setAttribute('role', 'group');
404
+ else if (el.getAttribute('role') === 'group') el.removeAttribute('role');
405
+ applyGroupA11y(el, { ...p, aria_label: '' }, targets);
258
406
  }
259
407
 
260
408
  /** 禁用态:原生 disabled + aria-disabled 同写 */
@@ -272,48 +420,174 @@ export function nextUid(prefix: string): string {
272
420
 
273
421
  // ── 控制器骨架 ────────────────────────────────────────────────
274
422
 
423
+ /** createKitController 生成的控制器工厂内部标记(供 component-gate 与 G99 校验) */
424
+ export const KIT_CONTROLLER: unique symbol = Symbol.for('soma.kit.controller');
425
+ const KIT_CONTROLLER_SOURCE: unique symbol = Symbol.for('soma.kit.controller.source');
426
+
427
+ /** 判定一个值是否为经 createKitController 生成的控制器工厂 */
428
+ export function isKitControllerFactory(fn: unknown): fn is SomaComponentControllerFactory {
429
+ return typeof fn === 'function' && (fn as unknown as Record<symbol, unknown>)[KIT_CONTROLLER] === true;
430
+ }
431
+
432
+ /** 读取控制器工厂的内部实现源码(供 KIT-APP-005 扫描禁用原生控件) */
433
+ export function getKitControllerSource(fn: unknown): string {
434
+ if (typeof fn !== 'function') return '';
435
+ const inner = (fn as unknown as Record<symbol, unknown>)[KIT_CONTROLLER_SOURCE];
436
+ return typeof inner === 'string' ? `${inner}\n${Function.prototype.toString.call(fn)}` : Function.prototype.toString.call(fn);
437
+ }
438
+
275
439
  export interface KitApi {
276
440
  emit(name: string, payload?: unknown): void;
277
441
  props(): KitProps;
278
442
  host: HTMLElement;
279
443
  /** 契约 `services` 白名单过滤后的运行时服务(虚拟滚动取 `engines.virtual`) */
280
444
  services?: Record<string, unknown>;
445
+ /** 请求组件重绘(等价于触发新一轮全量 render) */
446
+ refresh(): void;
447
+ /** 当前这轮异步 render 是否仍为最新且组件未卸载 */
448
+ isCurrent(): boolean;
281
449
  }
282
450
 
283
451
  export interface KitView {
284
- /** 挂事件;返回清理函数。只在 onMount 调一次 */
452
+ /** 挂监听、观察器、引擎;返回清理函数。只在 onMount 调一次 */
285
453
  attach?(root: HTMLElement, api: KitApi): (() => void) | void;
286
- /** 把 props 画到 DOM 上;挂载与每次 props 下行都调用,必须幂等 */
287
- render(root: HTMLElement, p: KitProps, api: KitApi): void;
454
+ /** 必填;首绘和每次 prop 变化都整份重画(支持异步,后发先至由骨架统一处理) */
455
+ render(root: HTMLElement, p: KitProps, api: KitApi): void | Promise<void>;
456
+ /** 对展示对象公开的方法(由骨架挂到 core 读取的位置,组件不碰 core 内部键) */
457
+ handle?: Record<string, (...a: unknown[]) => unknown>;
288
458
  /**
289
459
  * 带忙闲通道:为真时骨架订阅 base/action-busy,`busy` / `busy_action` 对应的忙闲状态变了就重绘一次
290
460
  * (render 里用 `kitBusyOf(p)` 取状态落到触发钮)。
291
461
  */
292
462
  busyAware?: boolean;
463
+ /**
464
+ * 组件声明的数据对象取数完成(外部触发的重算,如 behavior.from 读取回来)后,core 在重渲之后调用一次;
465
+ * 骨架原样挂到控制器上(不包装)。需要在取数后「补画 / 回填」副作用时写在这里(重渲只让派生值重算,不会替你回填);
466
+ * 不要在里面改 props,需要重绘调 `api.refresh()`。抛错由 core 记录,不影响其它组件。
467
+ */
468
+ onDataObjectsChange?(): void;
469
+ }
470
+
471
+ export type KitViewSetup = (api: KitApi) => KitView;
472
+
473
+ /** 包装异步引擎调用:若 await 返回时本轮 render 已过期或组件已卸载,自动丢弃旧结果(若刚创建出实例且已卸载则销毁) */
474
+ function guardAsyncServices(
475
+ services: Record<string, unknown> | undefined,
476
+ isCurrent: () => boolean,
477
+ isAlive: () => boolean,
478
+ ): Record<string, unknown> | undefined {
479
+ if (!services || typeof services !== 'object') return services;
480
+ const engines = (services as { engines?: Record<string, unknown> }).engines;
481
+ if (!engines || typeof engines !== 'object') return services;
482
+ const wrappedEngines: Record<string, unknown> = { ...engines };
483
+ for (const [k, port] of Object.entries(engines)) {
484
+ if (!port || typeof port !== 'object') continue;
485
+ const pObj = port as Record<string, unknown>;
486
+ const proxyPort: Record<string, unknown> = { ...pObj };
487
+ for (const [m, fn] of Object.entries(pObj)) {
488
+ if (typeof fn !== 'function') continue;
489
+ proxyPort[m] = (...args: unknown[]) => {
490
+ const res = (fn as (...a: unknown[]) => unknown).apply(port, args);
491
+ if (res && typeof (res as Promise<unknown>).then === 'function') {
492
+ return (res as Promise<unknown>).then((val) => {
493
+ if (!isAlive()) {
494
+ if (val && typeof (val as { dispose?: () => void }).dispose === 'function') {
495
+ (val as { dispose: () => void }).dispose();
496
+ }
497
+ return new Promise<never>(() => {});
498
+ }
499
+ if (!isCurrent()) {
500
+ return new Promise<never>(() => {});
501
+ }
502
+ return val;
503
+ });
504
+ }
505
+ return res;
506
+ };
507
+ }
508
+ wrappedEngines[k] = proxyPort;
509
+ }
510
+ return { ...services, engines: wrappedEngines };
293
511
  }
294
512
 
295
513
  /**
296
- * 控制器骨架:onMount 取根、挂事件并首绘,onPropsChange 重绘,onUnmount 清理。
297
- * 事件只经 `ctx.emit` 上抛;组件不改数据,改数据走页面 `_event`。
514
+ * 控制器挂载钩子:每个 kit 组件实例挂载时按宿主元素各调一次(钩子自己保证幂等)。
515
+ * 给「每页只需装一次」的文档级装置用(按需提示的事件委托,见 hint-tips.ts);这里不 import 它们,避免 shared ↔ reason-tip 循环依赖。
298
516
  */
299
- export function createKitController(view: KitView): SomaComponentControllerFactory {
300
- return (ctx: SomaComponentControllerContext) => {
517
+ const MOUNT_HOOKS = new Set<(host: HTMLElement) => void>();
518
+ export function onKitControllerMount(hook: (host: HTMLElement) => void): void {
519
+ MOUNT_HOOKS.add(hook);
520
+ }
521
+
522
+ /**
523
+ * 控制器骨架:每个实例调用一次 setup(api),闭包即实例状态;
524
+ * onMount 取根、挂事件并首绘,onPropsChange 全量重绘,onUnmount 统一执行清理函数。
525
+ * 异步 render 由骨架统一处理后发先至(旧结果自动丢弃);handle 由骨架挂到 core 读取位置。
526
+ */
527
+ export function createKitController(setup: KitViewSetup | KitView): SomaComponentControllerFactory {
528
+ const setupFn: KitViewSetup | null = typeof setup === 'function' ? setup : (setup && typeof setup === 'object' && typeof (setup as KitView).render === 'function' ? () => setup as KitView : null);
529
+ if (!setupFn) {
530
+ throw new Error('[soma-kit] createKitController 只接受 (api: KitApi) => KitView 构造函数');
531
+ }
532
+ const factory: SomaComponentControllerFactory = (ctx: SomaComponentControllerContext) => {
301
533
  let root: HTMLElement | null = null;
302
534
  let cleanup: (() => void) | void;
535
+ let alive = false;
536
+ let seq = 0;
537
+ let view: KitView;
538
+ const readProps = (): KitProps => (ctx.readProps ? ctx.readProps() : ctx.props);
539
+ const applyPerm = (): void => {
540
+ const p = readProps();
541
+ if (p && 'permission' in p) {
542
+ if (deniedBy(ctx, p.permission)) ctx.host.setAttribute('hidden', '');
543
+ else ctx.host.removeAttribute('hidden');
544
+ }
545
+ };
546
+ const paint = (): void => {
547
+ applyPerm();
548
+ if (root) {
549
+ const mine = ++seq;
550
+ const isCurrent = (): boolean => alive && mine === seq;
551
+ const renderApi: KitApi = {
552
+ emit: api.emit,
553
+ props: readProps,
554
+ host: ctx.host,
555
+ services: guardAsyncServices(ctx.services, isCurrent, () => alive),
556
+ refresh: api.refresh,
557
+ isCurrent,
558
+ };
559
+ const out = view.render(root, readProps(), renderApi);
560
+ if (out && typeof (out as Promise<void>).then === 'function') {
561
+ (out as Promise<void>).catch(() => {});
562
+ }
563
+ }
564
+ };
303
565
  const api: KitApi = {
304
566
  emit: (name, payload) => ctx.emit(name, payload),
305
- props: () => (ctx.readProps ? ctx.readProps() : ctx.props),
567
+ props: readProps,
306
568
  host: ctx.host,
307
569
  services: ctx.services,
570
+ refresh: () => {
571
+ if (alive) {
572
+ paint();
573
+ ctx.refresh?.();
574
+ }
575
+ },
576
+ isCurrent: () => alive,
308
577
  };
309
- const paint = (): void => {
310
- if (root) view.render(root, api.props(), api);
311
- };
578
+ view = setupFn(api);
579
+ if (!view || typeof view.render !== 'function') {
580
+ throw new Error('[soma-kit] createKitController 的 setup 必须返回包含 render(root, p, api) 方法的 KitView');
581
+ }
312
582
  let offBusy: (() => void) | null = null;
583
+ let offPerm: (() => void) | null = null;
313
584
  let lastBusy = false;
314
- return {
585
+ const ctrl: Record<string, unknown> = {
315
586
  onMount(): void {
587
+ alive = true;
316
588
  root = findRoot(ctx.host);
589
+ for (const hook of MOUNT_HOOKS) hook(ctx.host);
590
+ offPerm = registerLivePermissionGate(applyPerm);
317
591
  cleanup = view.attach?.(root, api);
318
592
  paint();
319
593
  if (view.busyAware === true) {
@@ -331,6 +605,10 @@ export function createKitController(view: KitView): SomaComponentControllerFacto
331
605
  paint();
332
606
  },
333
607
  onUnmount(): void {
608
+ alive = false;
609
+ seq += 1;
610
+ offPerm?.();
611
+ offPerm = null;
334
612
  offBusy?.();
335
613
  offBusy = null;
336
614
  if (cleanup) cleanup();
@@ -338,7 +616,21 @@ export function createKitController(view: KitView): SomaComponentControllerFacto
338
616
  root = null;
339
617
  },
340
618
  };
619
+ for (const [k, desc] of Object.entries(Object.getOwnPropertyDescriptors(view))) {
620
+ if (k === 'attach' || k === 'render' || k === 'busyAware' || k === 'onMount' || k === 'onPropsChange' || k === 'onUnmount') continue;
621
+ Object.defineProperty(ctrl, k, desc);
622
+ }
623
+ return ctrl as ReturnType<SomaComponentControllerFactory>;
341
624
  };
625
+ const rawSource = typeof setup === 'function'
626
+ ? Function.prototype.toString.call(setup)
627
+ : Object.values(setup as unknown as Record<string, unknown>)
628
+ .filter((v): v is (...a: unknown[]) => unknown => typeof v === 'function')
629
+ .map((fn) => Function.prototype.toString.call(fn))
630
+ .join('\n');
631
+ Object.defineProperty(factory, KIT_CONTROLLER, { value: true, enumerable: false, configurable: false });
632
+ Object.defineProperty(factory, KIT_CONTROLLER_SOURCE, { value: rawSource, enumerable: false, configurable: false });
633
+ return factory;
342
634
  }
343
635
 
344
636
  // ── 角标(Button / Link / MenuButton / Tag / Avatar 共用)────────
@@ -378,6 +670,7 @@ export function paintBadge(host: HTMLElement, p: KitProps): boolean {
378
670
  if (!el) {
379
671
  el = document.createElement('span');
380
672
  el.setAttribute('data-kit-badge', '');
673
+ el.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_BADGE);
381
674
  host.appendChild(el);
382
675
  }
383
676
  if (text !== '') {
@@ -417,9 +710,19 @@ export const CLASS_PROP = {
417
710
  export const ID_PROPS = {
418
711
  id: { type: 'string', default: '', desc: '根控件 id,供 label for 关联' },
419
712
  aria_label: { type: 'string', default: '', desc: '无可见标签时的可访问名' },
713
+ labelledby: { type: 'string', default: '', desc: '可见标签元素 id(写 aria-labelledby;非原生可标注控件靠它得到可访问名,表单自动传入)' },
420
714
  name: { type: 'string', default: '', desc: '表单字段名' },
421
715
  } as const;
422
716
 
717
+ export const INVALID_PROPS = {
718
+ invalid: { type: 'boolean', default: false, desc: '校验无效态(写 aria-invalid="true" 并呈现错误态边框与焦点环)' },
719
+ required: { type: 'boolean', default: false, desc: '必填态(写 aria-required="true")' },
720
+ describedby: { type: 'string', default: '', desc: '关联说明/错误元素 id(写 aria-describedby)' },
721
+ errormessage: { type: 'string', default: '', desc: '关联错误消息元素 id(写 aria-errormessage)' },
722
+ aria_describedby: { type: 'string', default: '', desc: '关联说明/错误元素 id(写 aria-describedby)' },
723
+ aria_errormessage: { type: 'string', default: '', desc: '关联错误消息元素 id(写 aria-errormessage)' },
724
+ } as const;
725
+
423
726
  export const OPTIONS_PROP = {
424
727
  type: 'array',
425
728
  default: [],
@@ -449,6 +752,8 @@ export interface KitTablistOptions {
449
752
  orientation?: 'horizontal' | 'vertical';
450
753
  /** 选中变化(点击 / 键盘 / select())后回调;silent 的 select 不回调 */
451
754
  onSelect?: (id: string, tab: HTMLElement) => void;
755
+ /** 面板切换时用页面过渡(View Transitions,仅内容区参与;不支持 / 减弱动效时直切)。缺省 false;只对真正换了选中项的 select 生效 */
756
+ viewTransition?: boolean;
452
757
  }
453
758
 
454
759
  export interface KitTablistHandle {
@@ -540,15 +845,20 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
540
845
  const tab = byId(id);
541
846
  if (!tab || isDisabled(tab)) return;
542
847
  const changed = current !== id;
543
- const sLeft = root.scrollLeft;
544
- const sTop = root.scrollTop;
545
- current = id;
546
- cursor = id;
547
- paint();
548
- if (o.focus === true) tab.focus({ preventScroll: true });
549
- root.scrollLeft = sLeft;
550
- root.scrollTop = sTop;
551
- if (changed && o.silent !== true) opts.onSelect?.(id, tab);
848
+ const run = (): void => {
849
+ const sLeft = root.scrollLeft;
850
+ const sTop = root.scrollTop;
851
+ current = id;
852
+ cursor = id;
853
+ paint();
854
+ if (o.focus === true) tab.focus({ preventScroll: true });
855
+ root.scrollLeft = sLeft;
856
+ root.scrollTop = sTop;
857
+ if (changed && o.silent !== true) opts.onSelect?.(id, tab);
858
+ };
859
+ // 过渡路径下 run 由浏览器在下一帧调用;选中状态与回调都在 run 里一起落,顺序与直切一致
860
+ if (changed && opts.viewTransition === true) withKitViewTransition(run);
861
+ else run();
552
862
  };
553
863
 
554
864
  const reset = (): void => {
@@ -615,15 +925,7 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
615
925
 
616
926
  // ── 类候选小工具(K9 / D1:补齐波基础组件共用)────────────────
617
927
 
618
- /** 把若干整串类拆开、去重,作为组件自带的候选类清单(并入 KIT_BASE_CLASS_CANDIDATES) */
619
- export function classCandidates(...lists: ReadonlyArray<string | readonly string[]>): readonly string[] {
620
- const set = new Set<string>();
621
- for (const item of lists) {
622
- const parts = typeof item === 'string' ? [item] : item;
623
- for (const part of parts) for (const c of part.split(/\s+/)) if (c !== '') set.add(c);
624
- }
625
- return Object.freeze([...set]);
626
- }
928
+ export { classCandidates } from './class-candidates';
627
929
 
628
930
  // ── 通用 tooltip(按钮类基础组件的可选 prop)─────────────────
629
931
  // 提示气泡是目标元素内的一个 role=tooltip 子元素(绝对定位,目标补 `relative`):hover / focus 显示,Esc 与移开隐藏,
@@ -648,24 +950,52 @@ export const KIT_TOOLTIP_CLASS_CANDIDATES: readonly string[] = classCandidates(
648
950
  * 给一个控制器视图套上 tooltip:读 `tooltip` prop,渲染后把气泡挂到目标元素(缺省根)里。
649
951
  * 视图自己重写 `textContent` 把气泡清掉也没关系,每次渲染后会补挂;卸载时摘掉监听与气泡。
650
952
  */
651
- export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTMLElement = (r) => r): KitView {
953
+ export function withTooltip(view: KitViewSetup, targetOf?: (root: HTMLElement) => HTMLElement): KitViewSetup;
954
+ export function withTooltip(view: KitView, targetOf?: (root: HTMLElement) => HTMLElement): KitView & KitViewSetup;
955
+ export function withTooltip(viewOrSetup: KitView | KitViewSetup, targetOf: (root: HTMLElement) => HTMLElement = (r) => r): KitView & KitViewSetup {
956
+ if (typeof viewOrSetup === 'function') {
957
+ return ((api: KitApi) => wrapTooltipView(viewOrSetup(api), targetOf)) as unknown as KitView & KitViewSetup;
958
+ }
959
+ const wrapped = wrapTooltipView(viewOrSetup, targetOf);
960
+ const setupFn = (() => wrapped) as unknown as KitView & KitViewSetup;
961
+ setupFn.attach = wrapped.attach;
962
+ setupFn.render = wrapped.render;
963
+ if (wrapped.handle !== undefined) setupFn.handle = wrapped.handle;
964
+ if (wrapped.busyAware !== undefined) setupFn.busyAware = wrapped.busyAware;
965
+ return setupFn;
966
+ }
967
+
968
+ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLElement = (r) => r): KitView {
652
969
  // 视图对象在同一组件定义的所有实例间共享,逐实例状态按根元素存
653
970
  // bound / rebind:目标可随渲染变化(如 MenuButton split 时目标由箭头钮换成主钮),监听跟着目标走
654
- interface TipState { tip: HTMLElement | null; shown: boolean; bound: HTMLElement | null; rebind: ((t: HTMLElement) => void) | null }
971
+ interface TipState { tip: HTMLElement | null; shown: boolean; bound: HTMLElement | null; rebind: ((t: HTMLElement) => void) | null; leave: KitLeaveHandle | null }
655
972
  const states = new WeakMap<HTMLElement, TipState>();
656
973
  const stateOf = (root: HTMLElement): TipState => {
657
974
  let s = states.get(root);
658
975
  if (!s) {
659
- s = { tip: null, shown: false, bound: null, rebind: null };
976
+ s = { tip: null, shown: false, bound: null, rebind: null, leave: null };
660
977
  states.set(root, s);
661
978
  }
662
979
  return s;
663
980
  };
664
981
  const paintTip = (s: TipState): void => {
665
- if (s.tip === null) return;
982
+ const tip = s.tip;
983
+ if (tip === null) return;
666
984
  // 显示时量一次可用空间,贴边则在闭集位置类间翻转(popup.ts);隐藏只换整串类
667
- if (s.shown) showPopupFitted(s.tip, s.tip.parentElement ?? s.tip, POPUP_TIP_PREF, popupTipClass);
668
- else s.tip.className = TOOLTIP_HIDDEN_CLASS;
985
+ if (s.shown) {
986
+ // 退场中被重新唤起:撤销退场再落位
987
+ s.leave?.cancel();
988
+ s.leave = null;
989
+ showPopupFitted(tip, tip.parentElement ?? tip, POPUP_TIP_PREF, popupTipClass);
990
+ return;
991
+ }
992
+ if (tip.className === TOOLTIP_HIDDEN_CLASS || s.leave !== null) return;
993
+ // 出场:与其他锚定浮层同一机制(隐藏前过渡,anchored-layer 的 leaveAnchored);没有退场动画则立即收尾
994
+ s.leave = leaveAnchored(tip, () => {
995
+ s.leave = null;
996
+ tip.className = TOOLTIP_HIDDEN_CLASS;
997
+ unmarkAnchored(tip);
998
+ });
669
999
  };
670
1000
 
671
1001
  return {
@@ -697,7 +1027,7 @@ export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTML
697
1027
  };
698
1028
  const bind = (t: HTMLElement): void => {
699
1029
  if (s.bound === t) return;
700
- if (s.bound !== null && s.tip !== null && s.bound.getAttribute('aria-describedby') === s.tip.id) s.bound.removeAttribute('aria-describedby');
1030
+ if (s.bound !== null && s.tip !== null) removeIdToken(s.bound, 'aria-describedby', s.tip.id);
701
1031
  unbind();
702
1032
  t.addEventListener('mouseenter', show);
703
1033
  t.addEventListener('mouseleave', hide);
@@ -712,6 +1042,8 @@ export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTML
712
1042
  return () => {
713
1043
  unbind();
714
1044
  s.rebind = null;
1045
+ s.leave?.cancel();
1046
+ s.leave = null;
715
1047
  if (s.tip) s.tip.remove();
716
1048
  s.tip = null;
717
1049
  s.shown = false;
@@ -726,7 +1058,7 @@ export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTML
726
1058
  const text = str(p.tooltip);
727
1059
  if (text === '') {
728
1060
  if (s.tip) {
729
- if (target.getAttribute('aria-describedby') === s.tip.id) target.removeAttribute('aria-describedby');
1061
+ removeIdToken(target, 'aria-describedby', s.tip.id);
730
1062
  s.tip.remove();
731
1063
  s.tip = null;
732
1064
  }
@@ -740,12 +1072,18 @@ export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTML
740
1072
  }
741
1073
  s.tip.textContent = text;
742
1074
  if (s.tip.parentNode !== target) target.appendChild(s.tip);
743
- target.setAttribute('aria-describedby', s.tip.id);
1075
+ addIdToken(target, 'aria-describedby', s.tip.id);
744
1076
  const cls = target.className;
745
1077
  if (!/(^|\s)(relative|absolute|fixed|sticky)(\s|$)/.test(cls)) {
746
1078
  target.className = cls === '' ? TOOLTIP_ANCHOR_CLASS : `${cls} ${TOOLTIP_ANCHOR_CLASS}`;
747
1079
  }
748
1080
  paintTip(s);
749
1081
  },
1082
+ ...(view.handle !== undefined ? { handle: view.handle } : {}),
1083
+ ...(view.busyAware !== undefined ? { busyAware: view.busyAware } : {}),
750
1084
  };
751
1085
  }
1086
+
1087
+ export * from '../recipes';
1088
+ export * from './loading-gate';
1089
+ export { withKitViewTransition, canKitViewTransition } from './view-transition';