soma-kit 0.1.15 → 0.1.17

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 (470) hide show
  1. package/README.md +1 -1
  2. package/package.json +8 -5
  3. package/packs/ai/model-card.ts +3 -3
  4. package/packs/ops/error-budget-card.ts +3 -3
  5. package/packs/ops/release-readiness-card.ts +3 -3
  6. package/packs/security/control-evidence-card.ts +3 -3
  7. package/packs/security/finding-card.ts +3 -2
  8. package/packs/shared/card-util.ts +17 -0
  9. package/spec/generated/kit-app.schema.json +2148 -340
  10. package/spec/generated/kit-page.schema.json +1134 -139
  11. package/spec/kit-grammar.json +935 -93
  12. package/spec/kit-grammar.schema.json +167 -2
  13. package/src/app/app-config.ts +219 -186
  14. package/src/app/define-kit-actions.ts +126 -20
  15. package/src/app/define-kit-app.ts +49 -4
  16. package/src/app/index.ts +5 -0
  17. package/src/app/kit-view-context.ts +39 -1
  18. package/src/app/list-page-defaults.ts +14 -0
  19. package/src/app/server-pages.ts +239 -7
  20. package/src/app/server.ts +466 -25
  21. package/src/app/theme-endpoint.ts +67 -23
  22. package/src/app/theme-runtime.ts +414 -85
  23. package/src/app/theme-shards.ts +69 -0
  24. package/src/app/tier-compat.ts +107 -0
  25. package/src/base/action-busy.ts +215 -38
  26. package/src/base/affix.ts +137 -0
  27. package/src/base/alert.ts +104 -59
  28. package/src/base/anchored-layer.ts +7 -6
  29. package/src/base/avatar.ts +147 -61
  30. package/src/base/badge.ts +186 -0
  31. package/src/base/button-group.ts +227 -0
  32. package/src/base/button.ts +347 -50
  33. package/src/base/card.ts +233 -0
  34. package/src/base/cascader.ts +143 -32
  35. package/src/base/check-core.ts +193 -33
  36. package/src/base/checkbox.ts +67 -2
  37. package/src/base/choice.ts +132 -31
  38. package/src/base/collapse.ts +249 -0
  39. package/src/base/color-picker.ts +399 -27
  40. package/src/base/combobox.ts +6 -2
  41. package/src/base/command-palette.ts +148 -36
  42. package/src/base/context-menu.ts +23 -6
  43. package/src/base/countdown.ts +37 -15
  44. package/src/base/date-range.ts +114 -96
  45. package/src/base/date.ts +481 -74
  46. package/src/base/delta.ts +16 -9
  47. package/src/base/divider.ts +51 -33
  48. package/src/base/end-edge.ts +10 -4
  49. package/src/base/fab.ts +57 -21
  50. package/src/base/gap-value.ts +34 -15
  51. package/src/base/hint-tips.ts +99 -29
  52. package/src/base/identity-cells.ts +839 -0
  53. package/src/base/illustrations.ts +6 -4
  54. package/src/base/image.ts +40 -19
  55. package/src/base/index.ts +79 -22
  56. package/src/base/inline-error.ts +13 -7
  57. package/src/base/input.ts +135 -35
  58. package/src/base/kbd.ts +30 -17
  59. package/src/base/kit-contract.ts +400 -0
  60. package/src/base/link.ts +41 -20
  61. package/src/base/listbox-core.ts +282 -101
  62. package/src/base/loading-gate.ts +3 -0
  63. package/src/base/look.ts +197 -0
  64. package/src/base/mentions.ts +55 -22
  65. package/src/base/menu-button.ts +73 -22
  66. package/src/base/menu-core.ts +201 -24
  67. package/src/base/month-grid.ts +60 -3
  68. package/src/base/motion/aura.ts +52 -10
  69. package/src/base/motion/hover-3d.ts +7 -5
  70. package/src/base/motion/hover-gallery.ts +16 -12
  71. package/src/base/motion/limits.ts +10 -0
  72. package/src/base/motion/marquee.ts +18 -11
  73. package/src/base/motion/text-rotate.ts +34 -16
  74. package/src/base/notification.ts +292 -0
  75. package/src/base/number.ts +93 -12
  76. package/src/base/otp.ts +139 -27
  77. package/src/base/overlay-runtime.ts +30 -23
  78. package/src/base/overlay-shell.ts +59 -14
  79. package/src/base/period-picker.ts +868 -0
  80. package/src/base/popover.ts +624 -73
  81. package/src/base/popup.ts +187 -52
  82. package/src/base/portal-core.ts +99 -2
  83. package/src/base/price-text.ts +51 -17
  84. package/src/base/progress.ts +100 -18
  85. package/src/base/qr-code.ts +64 -17
  86. package/src/base/qty-stepper.ts +141 -22
  87. package/src/base/radio.ts +43 -2
  88. package/src/base/range.ts +194 -39
  89. package/src/base/rating.ts +117 -31
  90. package/src/base/reason-tip.ts +58 -16
  91. package/src/base/relation-cells.ts +541 -0
  92. package/src/base/resize-handle.ts +5 -3
  93. package/src/base/row-fresh.ts +84 -0
  94. package/src/base/section-spy.ts +79 -0
  95. package/src/base/segmented.ts +70 -26
  96. package/src/base/select.ts +8 -3
  97. package/src/base/shared.ts +482 -71
  98. package/src/base/spinner.ts +107 -0
  99. package/src/base/state-panel.ts +77 -22
  100. package/src/base/sticky-edge.ts +96 -29
  101. package/src/base/swap.ts +39 -21
  102. package/src/base/switch.ts +158 -38
  103. package/src/base/tabs.ts +292 -0
  104. package/src/base/tag-input.ts +123 -54
  105. package/src/base/tag.ts +184 -66
  106. package/src/base/text.ts +461 -71
  107. package/src/base/textarea.ts +88 -39
  108. package/src/base/time-picker.ts +335 -55
  109. package/src/base/time-range.ts +846 -0
  110. package/src/base/tree-select.ts +342 -88
  111. package/src/base/upload.ts +604 -158
  112. package/src/base/view-transition.ts +7 -3
  113. package/src/base/virtual-list.ts +49 -14
  114. package/src/biz/approval-desk/compile.ts +70 -5
  115. package/src/biz/approval-desk/index.ts +2 -0
  116. package/src/biz/approval-desk/shell.ts +52 -12
  117. package/src/biz/auth-panel/compile.ts +13 -3
  118. package/src/biz/auth-panel/shell.ts +27 -7
  119. package/src/biz/category-crud/compile.ts +51 -13
  120. package/src/biz/category-crud/index.ts +2 -0
  121. package/src/biz/category-crud/shell.ts +29 -9
  122. package/src/biz/checkout-page/compile.ts +37 -3
  123. package/src/biz/checkout-page/index.ts +1 -0
  124. package/src/biz/checkout-page/shell.ts +26 -9
  125. package/src/biz/compose.ts +6 -1
  126. package/src/biz/data-components.ts +2 -0
  127. package/src/biz/import-wizard/compile.ts +4 -1
  128. package/src/biz/import-wizard/index.ts +1 -0
  129. package/src/biz/import-wizard/shell.ts +32 -18
  130. package/src/biz/index.ts +1 -1
  131. package/src/biz/landing-page/compile.ts +3 -2
  132. package/src/biz/landing-page/shell.ts +22 -3
  133. package/src/biz/layout-contracts.ts +918 -0
  134. package/src/biz/link/hub.ts +199 -8
  135. package/src/biz/link/shared.ts +54 -15
  136. package/src/biz/master-sub/compile.ts +194 -57
  137. package/src/biz/master-sub/detail-head.ts +141 -18
  138. package/src/biz/master-sub/index.ts +3 -0
  139. package/src/biz/master-sub/shell.ts +188 -62
  140. package/src/biz/multi-board/compile.ts +87 -36
  141. package/src/biz/multi-board/composition.ts +7 -20
  142. package/src/biz/multi-board/index.ts +3 -2
  143. package/src/biz/multi-board/prose-fold.ts +15 -11
  144. package/src/biz/multi-board/shell.ts +148 -37
  145. package/src/biz/notification-center/compile.ts +20 -6
  146. package/src/biz/notification-center/index.ts +2 -0
  147. package/src/biz/notification-center/shell.ts +43 -10
  148. package/src/biz/page-templates/domain-templates.ts +145 -22
  149. package/src/biz/page-templates/result-page/compile.ts +4 -1
  150. package/src/biz/page-templates/result-page/index.ts +1 -0
  151. package/src/biz/page-templates/result-page/shell.ts +17 -4
  152. package/src/biz/page-templates/sign-in-page/compile.ts +19 -8
  153. package/src/biz/page-templates/sign-in-page/index.ts +1 -0
  154. package/src/biz/page-templates/sign-in-page/shell.ts +28 -12
  155. package/src/biz/record-detail/compile.ts +39 -11
  156. package/src/biz/record-detail/index.ts +1 -0
  157. package/src/biz/record-detail/shell.ts +41 -10
  158. package/src/biz/settings-center/compile.ts +4 -1
  159. package/src/biz/settings-center/index.ts +1 -0
  160. package/src/biz/settings-center/shell.ts +30 -9
  161. package/src/biz/shared/action-host.ts +137 -46
  162. package/src/biz/shared/compile-helpers.ts +152 -28
  163. package/src/biz/shared/coordinator.ts +628 -147
  164. package/src/biz/shared/focus-return.ts +180 -0
  165. package/src/biz/shared/object-aliases.ts +7 -1
  166. package/src/biz/shared/overlay-compile.ts +58 -10
  167. package/src/biz/shared/overlay-shell.ts +40 -10
  168. package/src/biz/shared/page-form-actions.ts +151 -0
  169. package/src/biz/shared/page-form.ts +255 -0
  170. package/src/biz/shared/pipeline.ts +74 -0
  171. package/src/biz/shared/runtime-hub.ts +101 -8
  172. package/src/biz/shared/verbs.ts +129 -0
  173. package/src/biz/single-form/compile.ts +4 -2
  174. package/src/biz/single-form/index.ts +2 -0
  175. package/src/biz/single-form/shell.ts +21 -11
  176. package/src/biz/standard-crud/compile.ts +206 -38
  177. package/src/biz/standard-crud/index.ts +2 -1
  178. package/src/biz/standard-crud/shell.ts +82 -22
  179. package/src/biz/standard-crud/summary.ts +2 -37
  180. package/src/biz/step-form/compile.ts +12 -3
  181. package/src/biz/step-form/hub.ts +165 -50
  182. package/src/biz/step-form/index.ts +1 -0
  183. package/src/biz/step-form/shell.ts +31 -15
  184. package/src/biz/types.ts +40 -4
  185. package/src/cli/kit-cli.ts +145 -26
  186. package/src/cli/kit-init.ts +3 -3
  187. package/src/cli/migrate/theme-map.ts +35 -28
  188. package/src/cli/migrate/ts-rules.ts +2 -2
  189. package/src/cli/migrate/types.ts +3 -3
  190. package/src/cli/migrate/yaml-rules.ts +11 -9
  191. package/src/cli/view-writes.ts +13 -0
  192. package/src/compile/closed-set.ts +102 -6
  193. package/src/compile/compile-page.ts +446 -53
  194. package/src/compile/component-candidates.ts +56 -4
  195. package/src/compile/danger-tier.ts +65 -0
  196. package/src/compile/hints.ts +1 -1
  197. package/src/compile/info-structure.ts +155 -0
  198. package/src/compile/layout-lint/rules-composition.ts +2 -1
  199. package/src/compile/layout-lint/rules-table.ts +4 -19
  200. package/src/compile/look-page.ts +551 -0
  201. package/src/compile/look.ts +376 -0
  202. package/src/compile/page-composition.ts +382 -46
  203. package/src/compile/page-hierarchy.ts +131 -0
  204. package/src/compile/page-pipeline-look.ts +156 -0
  205. package/src/compile/page-pipeline.ts +200 -0
  206. package/src/compile/parse.ts +12 -11
  207. package/src/compile/relation-render.ts +120 -0
  208. package/src/compile/remove-guard.ts +115 -41
  209. package/src/compile/stages.ts +645 -28
  210. package/src/compile/styles.ts +226 -26
  211. package/src/compile/types.ts +62 -5
  212. package/src/compile/view-check.ts +190 -1
  213. package/src/data/access-gate.ts +17 -9
  214. package/src/data/amount-breakdown.ts +49 -22
  215. package/src/data/anchor-nav.ts +73 -15
  216. package/src/data/approval-flow.ts +210 -124
  217. package/src/data/assignment-picker.ts +163 -85
  218. package/src/data/async-result-panel.ts +110 -46
  219. package/src/data/audit-log.ts +461 -0
  220. package/src/data/breadcrumbs.ts +141 -19
  221. package/src/data/calendar.ts +434 -96
  222. package/src/data/card-grid.ts +319 -0
  223. package/src/data/carousel.ts +72 -38
  224. package/src/data/cell-value.ts +253 -0
  225. package/src/data/chart.ts +904 -77
  226. package/src/data/checklist.ts +78 -35
  227. package/src/data/code-view.ts +106 -48
  228. package/src/data/comment-thread.ts +607 -87
  229. package/src/data/compare-view.ts +227 -0
  230. package/src/data/confirm-dialog.ts +198 -30
  231. package/src/data/context-menu.ts +95 -21
  232. package/src/data/d9-limits.ts +2 -0
  233. package/src/data/d9-util.ts +13 -5
  234. package/src/data/diff.ts +107 -50
  235. package/src/data/display-util.ts +9 -4
  236. package/src/data/dock.ts +33 -17
  237. package/src/data/embed.ts +142 -7
  238. package/src/data/engine-ports.ts +13 -4
  239. package/src/data/field-mapper.ts +104 -48
  240. package/src/data/file-list.ts +522 -0
  241. package/src/data/flow-editor.ts +603 -142
  242. package/src/data/flow-node-options.ts +24 -5
  243. package/src/data/flow-remote-options.ts +94 -19
  244. package/src/data/footer.ts +85 -27
  245. package/src/data/form-draft-registry.ts +183 -12
  246. package/src/data/gantt.ts +637 -117
  247. package/src/data/graph-view.ts +51 -0
  248. package/src/data/heat-calendar.ts +412 -0
  249. package/src/data/hero.ts +38 -15
  250. package/src/data/image-viewer.ts +261 -62
  251. package/src/data/index.ts +63 -1
  252. package/src/data/item-list.ts +217 -57
  253. package/src/data/json-view.ts +165 -100
  254. package/src/data/kanban.ts +339 -87
  255. package/src/data/kit-contract.ts +230 -0
  256. package/src/data/leaderboard.ts +343 -0
  257. package/src/data/level-class.ts +21 -0
  258. package/src/data/log-stream.ts +347 -0
  259. package/src/data/markdown-view.ts +155 -45
  260. package/src/data/matrix.ts +217 -112
  261. package/src/data/media-grid.ts +162 -38
  262. package/src/data/mega-menu.ts +39 -23
  263. package/src/data/menu-bar.ts +254 -0
  264. package/src/data/menu-dom.ts +50 -15
  265. package/src/data/menu.ts +131 -47
  266. package/src/data/mockup.ts +30 -22
  267. package/src/data/modal-dialog.ts +90 -13
  268. package/src/data/navbar.ts +143 -61
  269. package/src/data/notice-list.ts +100 -48
  270. package/src/data/notify-renderer.ts +61 -7
  271. package/src/data/object-form.ts +1389 -130
  272. package/src/data/org-chart.ts +544 -0
  273. package/src/data/outcome-watch.ts +90 -21
  274. package/src/data/pager.ts +122 -42
  275. package/src/data/panel-head.ts +237 -75
  276. package/src/data/permission-matrix.ts +371 -119
  277. package/src/data/permission-tree.ts +135 -80
  278. package/src/data/pricing-table.ts +106 -42
  279. package/src/data/prompt-dialog.ts +49 -21
  280. package/src/data/reaction-bar.ts +63 -31
  281. package/src/data/record-card.ts +239 -70
  282. package/src/data/record-picker.ts +56 -27
  283. package/src/data/redirect.ts +39 -15
  284. package/src/data/request-console.ts +131 -41
  285. package/src/data/resident.ts +11 -1
  286. package/src/data/result-panel.ts +65 -27
  287. package/src/data/rich-text.ts +206 -35
  288. package/src/data/row-confirm.ts +47 -0
  289. package/src/data/row-editor.ts +376 -102
  290. package/src/data/rule-builder.ts +129 -80
  291. package/src/data/schedule-grid.ts +238 -0
  292. package/src/data/segment-bar.ts +221 -0
  293. package/src/data/shape-util.ts +86 -43
  294. package/src/data/stage-flow.ts +244 -0
  295. package/src/data/staged-rows.ts +207 -24
  296. package/src/data/stat-group.ts +438 -86
  297. package/src/data/static-lazy.ts +18 -0
  298. package/src/data/static-registry.ts +38 -2
  299. package/src/data/status-strip.ts +171 -0
  300. package/src/data/steps.ts +63 -34
  301. package/src/data/summary-strip.ts +136 -0
  302. package/src/data/summary-util.ts +116 -0
  303. package/src/data/survey.ts +128 -47
  304. package/src/data/system-switcher.ts +40 -20
  305. package/src/data/target-progress.ts +208 -0
  306. package/src/data/text-action-button.ts +28 -7
  307. package/src/data/text-diff.ts +99 -31
  308. package/src/data/tile-grid.ts +343 -0
  309. package/src/data/timeline.ts +205 -36
  310. package/src/data/tour-guide.ts +110 -47
  311. package/src/data/transfer.ts +195 -47
  312. package/src/data/tree-table.ts +194 -112
  313. package/src/data/tree.ts +191 -70
  314. package/src/data/trend-line.ts +68 -12
  315. package/src/data/virtual-rows.ts +242 -102
  316. package/src/data/waterfall.ts +171 -0
  317. package/src/data/watermark.ts +35 -6
  318. package/src/data/wrap.ts +26 -4
  319. package/src/frames/blank-frame.ts +6 -4
  320. package/src/frames/index.ts +1 -2
  321. package/src/frames/inherited-shell.ts +54 -13
  322. package/src/frames/page-bar.ts +205 -27
  323. package/src/frames/page-status.ts +3 -2
  324. package/src/frames/resident-components.ts +0 -2
  325. package/src/frames/shared.ts +64 -21
  326. package/src/frames/single-frame.ts +20 -4
  327. package/src/frames/split-frame/shell.ts +11 -7
  328. package/src/frames/split-frame/wiring.ts +14 -10
  329. package/src/frames/tabs-frame/shell.ts +3 -2
  330. package/src/frames/tabs-frame/wiring.ts +2 -1
  331. package/src/frames/top-main-frame.ts +55 -3
  332. package/src/frames/types.ts +2 -0
  333. package/src/frames/workspace-frame/extras.ts +5 -3
  334. package/src/frames/workspace-frame/index.ts +1 -1
  335. package/src/frames/workspace-frame/pipeline-key.ts +6 -0
  336. package/src/frames/workspace-frame/shell.ts +22 -2
  337. package/src/frames/workspace-frame/state.ts +42 -14
  338. package/src/frames/workspace-frame/view.ts +697 -167
  339. package/src/generated/kit-grammar-runtime.ts +1016 -54
  340. package/src/generated/kit-page.ts +272 -0
  341. package/src/i18n/index.ts +2 -0
  342. package/src/i18n/kit-text.ts +96 -3
  343. package/src/object-renderer/action-group.ts +175 -23
  344. package/src/object-renderer/action-more.ts +48 -17
  345. package/src/object-renderer/arrange.ts +241 -29
  346. package/src/object-renderer/category-tone.ts +96 -0
  347. package/src/object-renderer/collapse-wiring.ts +19 -9
  348. package/src/object-renderer/collection-expand.ts +3 -3
  349. package/src/object-renderer/collection-parts.ts +432 -107
  350. package/src/object-renderer/collection-table.ts +347 -45
  351. package/src/object-renderer/collection.ts +291 -62
  352. package/src/object-renderer/compile-data.ts +12 -2
  353. package/src/object-renderer/defaults.ts +6 -5
  354. package/src/object-renderer/emit-events.ts +45 -19
  355. package/src/object-renderer/emit-object.ts +35 -9
  356. package/src/object-renderer/emit-static.ts +734 -159
  357. package/src/object-renderer/filter-plan.ts +3 -3
  358. package/src/object-renderer/filter-toolbar.ts +105 -18
  359. package/src/object-renderer/form-detail.ts +87 -2
  360. package/src/object-renderer/key-field.ts +21 -0
  361. package/src/object-renderer/layout-facts.ts +18 -2
  362. package/src/object-renderer/layout-plan.ts +6 -3
  363. package/src/object-renderer/overlay-decide.ts +44 -2
  364. package/src/object-renderer/pick-component.ts +8 -2
  365. package/src/object-renderer/pipeline-mode.ts +6 -0
  366. package/src/object-renderer/relation-field.ts +79 -0
  367. package/src/object-renderer/render-object.ts +71 -26
  368. package/src/object-renderer/request-actions.ts +119 -21
  369. package/src/object-renderer/table-actions.ts +423 -104
  370. package/src/object-renderer/table-gap.ts +2 -1
  371. package/src/object-renderer/table-reorder.ts +237 -0
  372. package/src/object-renderer/table-summary.ts +26 -12
  373. package/src/object-renderer/table-tools.ts +428 -128
  374. package/src/object-renderer/types.ts +91 -2
  375. package/src/object-renderer/value-present.ts +49 -0
  376. package/src/page-target/ai-surface.ts +15 -22
  377. package/src/page-target/compile.ts +5 -6
  378. package/src/page-target/drift.ts +0 -7
  379. package/src/page-target/intent-schema.ts +46 -43
  380. package/src/page-target/target.ts +4 -5
  381. package/src/page-target/writer-policy.ts +4 -5
  382. package/src/recipes/chrome-surface.ts +20 -0
  383. package/src/recipes/code-view.ts +15 -14
  384. package/src/recipes/color-role.ts +442 -0
  385. package/src/recipes/compact-group.ts +3 -2
  386. package/src/recipes/composition-projector.ts +321 -0
  387. package/src/recipes/container.ts +76 -19
  388. package/src/recipes/control.ts +64 -5
  389. package/src/recipes/desc-list.ts +101 -7
  390. package/src/recipes/divider.ts +30 -9
  391. package/src/recipes/emphasis.ts +90 -5
  392. package/src/recipes/field-text.ts +72 -0
  393. package/src/recipes/form-section.ts +177 -0
  394. package/src/recipes/frame-bleed.ts +3 -2
  395. package/src/recipes/index.ts +28 -4
  396. package/src/recipes/inherited-shell.ts +21 -15
  397. package/src/recipes/json-view.ts +6 -5
  398. package/src/recipes/look.ts +56 -0
  399. package/src/recipes/mark.ts +138 -0
  400. package/src/recipes/markdown.ts +16 -6
  401. package/src/recipes/overlay.ts +47 -19
  402. package/src/recipes/page-width.ts +31 -0
  403. package/src/recipes/pipeline-runtime.ts +366 -0
  404. package/src/recipes/placeholder.ts +37 -19
  405. package/src/recipes/rail-grid.ts +6 -3
  406. package/src/recipes/self-owned.ts +59 -0
  407. package/src/recipes/slot-align.ts +5 -3
  408. package/src/recipes/stat-state.ts +5 -5
  409. package/src/recipes/state.ts +54 -3
  410. package/src/recipes/status.ts +14 -14
  411. package/src/recipes/strip.ts +47 -5
  412. package/src/recipes/surface-edge.ts +3 -1
  413. package/src/recipes/surface.ts +33 -4
  414. package/src/recipes/table-gap.ts +3 -2
  415. package/src/recipes/table-native-edit.ts +22 -9
  416. package/src/recipes/table-row.ts +45 -12
  417. package/src/recipes/tabs.ts +54 -22
  418. package/src/recipes/text-diff.ts +15 -8
  419. package/src/recipes/text-fit.ts +132 -0
  420. package/src/recipes/title-row.ts +68 -3
  421. package/src/shared/action-func.ts +106 -0
  422. package/src/shared/color-scheme.ts +127 -0
  423. package/src/shared/confirm-decl.ts +5 -2
  424. package/src/shared/danger-facts.ts +55 -0
  425. package/src/shared/dom-attrs-registry.ts +1009 -0
  426. package/src/shared/dom-attrs.ts +743 -0
  427. package/src/shared/field-kind.ts +49 -0
  428. package/src/shared/field-value-format.ts +58 -12
  429. package/src/shared/glyphs.ts +127 -0
  430. package/src/shared/icons.ts +28 -1
  431. package/src/shared/identifier-field.ts +66 -0
  432. package/src/shared/list-pager.ts +23 -0
  433. package/src/shared/list-title.ts +29 -0
  434. package/src/shared/order-value.ts +15 -0
  435. package/src/shared/page-attrs-runtime.ts +327 -0
  436. package/src/shared/page-attrs.ts +262 -0
  437. package/src/shared/pipeline-mode.ts +64 -0
  438. package/src/shared/row-key.ts +15 -0
  439. package/src/shared/theme-runtime-shared.ts +165 -24
  440. package/src/shared/theme-usage.ts +16 -0
  441. package/src/shared/value-table-contract.ts +68 -0
  442. package/src/spatial/action-func.ts +4 -0
  443. package/src/spatial/declared-actions.ts +116 -0
  444. package/src/spatial/emit.ts +660 -0
  445. package/src/spatial/expand.ts +1482 -0
  446. package/src/spatial/field-types.ts +48 -0
  447. package/src/spatial/index.ts +82 -0
  448. package/src/spatial/layout.ts +697 -0
  449. package/src/spatial/look-apply.ts +206 -0
  450. package/src/spatial/page-decl.ts +44 -0
  451. package/src/spatial/page-object.ts +349 -0
  452. package/src/spatial/recognize.ts +491 -0
  453. package/src/spatial/self-report.ts +571 -0
  454. package/src/spatial/shape.ts +205 -0
  455. package/src/spatial/spatial-map.ts +136 -0
  456. package/src/spatial/tone.ts +145 -0
  457. package/src/theme/index.ts +11 -2
  458. package/src/theme/kit-theme-text.ts +1 -1
  459. package/src/theme/kit-theme.css +527 -16
  460. package/src/theme/kit-theme.tpl +491 -16
  461. package/src/theme/look-carrier.ts +65 -0
  462. package/src/theme/nine-dim-structure.ts +522 -185
  463. package/src/theme/private-vars.ts +153 -0
  464. package/src/theme/surface-layers.ts +3 -2
  465. package/src/theme/theme-tokens.ts +1601 -93
  466. package/src/theme/theme-types.ts +38 -59
  467. package/src/theme/value-table.ts +2379 -0
  468. package/src/frames/list-summary.ts +0 -123
  469. package/src/recipes/nowrap.ts +0 -16
  470. package/src/theme/block-theme.ts +0 -202
package/src/base/date.ts CHANGED
@@ -14,59 +14,120 @@
14
14
  import type { SomaComponentDefinition } from 'soma-core';
15
15
  import { kitDirAt, kitKey, kitLocaleAt, kitText } from '../i18n/kit-text';
16
16
  import {
17
- addMonths, dayFullName, dayNumOf, monthFirstOf, monthGridCells, monthGridStep, monthTitle, textOfDayNum, weekStartProp, weekdayHeads,
17
+ addMonths, dayFullName, dayNumOf, daysInMonth, monthFirstOf, monthGridCells, monthGridStep, monthTitle, textOfDayNum, weekStartProp, weekdayHeads, ymdOfDayNum,
18
18
  } from './month-grid';
19
19
  import {
20
20
  CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP,
21
- applyCommon, classCandidates, bool, createKitController, joinClass, nextUid, setAttr, sizeOf, str, withInvalid, type KitApi, type KitProps, type KitSize,
21
+ applyCommon, classCandidates, bool, createKitController, joinClass, nextUid, setAttr, str, withInvalid, type KitApi, type KitProps, type KitSize,
22
+ kitControlSizeOf, kitMarkDataState, kitMarkInteract, kitOuterRoot, kitReportSelf,
22
23
  } from './shared';
23
24
  import { kitIcon } from '../shared/icons';
25
+ import { KIT_ATTR_DAY, KIT_ATTR_NAV, KIT_ATTR_PERIOD, KIT_ATTR_PRESET, KIT_ATTR_QUIET, KIT_ATTR_RANGE_TEXT } from '../shared/dom-attrs';
24
26
  import { setKitFace } from '../recipes';
25
27
  import { kitControlEdgeRecipe } from '../recipes/control';
26
28
 
27
29
  // 日期框的边 = 控件轮廓出口(KT-B1 / §4 C6,与输入框同一条控件线)
28
30
  const CONTROL_EDGE = kitControlEdgeRecipe();
29
31
  import { mergeClass } from '../shared/merge-class';
30
- import { kitSurfaceRecipe } from '../recipes/surface';
32
+ import { kitLevelClassFor } from '../recipes/pipeline-runtime';
33
+ import { kitSurfaceRecipe, kitWellRecipe } from '../recipes/surface';
34
+ import { kitDividerRecipe } from '../recipes/divider';
35
+ import { KIT_FOCUS_DELEGATED_INPUT, KIT_FOCUS_ITEM_QUIET, KIT_FOCUS_RING, kitSelectedRecipe, kitTonalFillRecipe } from '../recipes/state';
36
+ import { kitActionRecipe } from '../recipes/emphasis';
37
+ import { KIT_PERIOD_PICKER_CLASS_CANDIDATES, isPeriodPicker, mountPeriodField } from './period-picker';
31
38
  import { KIT_DROPDOWN_CLASS_CANDIDATES, focusCellQuiet, handoffTab, onOutsidePress, releaseDropdown, syncDropdown, trackInputModality } from './popup';
32
39
 
33
40
  // ── 类串(整串写死,进候选类清单)──────────────────────────────
34
41
 
35
42
  const ROOT_CLASS = 'relative block w-full';
36
43
  const HIDDEN_CLASS = 'hidden';
44
+ // 隐藏的清除钮也带焦点环出口(集合项宿主),G121 ⑥
45
+ const HIDDEN_BTN_CLASS = mergeClass('hidden', KIT_FOCUS_RING.item);
46
+ const CLEAR_PAD_CLASS = 'pe-16';
47
+ const INPUT_BASE = mergeClass(
48
+ mergeClass(mergeClass('block w-full appearance-none autofill-clear rounded-control bg-surface text-fg transition-colors placeholder:text-fg-subtle disabled:cursor-not-allowed disabled:bg-control-disabled disabled:text-fg-disabled aria-invalid:border-danger', CONTROL_EDGE), KIT_FOCUS_RING.control),
49
+ kitWellRecipe('read-only'),
50
+ );
37
51
  const INPUT_CLASS: Record<KitSize, string> = {
38
- sm: 'block h-6 w-full appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface ps-2.5 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
39
- md: 'block h-8 w-full appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface ps-3 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
40
- lg: 'block h-10 w-full appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface ps-4 pe-9 text-base text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
52
+ sm: `${INPUT_BASE} h-control-sm ps-2.5 pe-10 text-xs tabular-nums`,
53
+ md: `${INPUT_BASE} h-control ps-3 pe-10 text-sm tabular-nums`,
54
+ lg: `${INPUT_BASE} h-control-lg ps-4 pe-11 text-base tabular-nums`,
55
+ };
56
+ const INPUT_CLEAR_CLASS: Record<KitSize, string> = {
57
+ sm: mergeClass(INPUT_CLASS.sm, CLEAR_PAD_CLASS),
58
+ md: mergeClass(INPUT_CLASS.md, CLEAR_PAD_CLASS),
59
+ lg: mergeClass(INPUT_CLASS.lg, CLEAR_PAD_CLASS),
41
60
  };
42
- const OPEN_BTN_CLASS = 'absolute end-0 top-0 border-0 bg-transparent flex h-full w-8 p-0 cursor-pointer items-center justify-center rounded-md text-fg-subtle transition-colors enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
43
- const CLEAR_BTN_CLASS = 'absolute end-8 top-0 border-0 bg-transparent flex h-full w-6 p-0 cursor-pointer items-center justify-center rounded-md text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
61
+ // 图标与清除钮内收留白,避免 shape=pill 大圆弧贴边拥挤(L1-05)
62
+ const OPEN_BTN_CLASS = mergeClass(
63
+ 'absolute end-1.5 top-0 border-0 bg-transparent flex h-full w-8 p-0 cursor-pointer items-center justify-center rounded-item text-fg-subtle transition-colors enabled:hover:text-fg disabled:cursor-not-allowed disabled:text-fg-disabled',
64
+ KIT_FOCUS_RING.item,
65
+ );
66
+ const CLEAR_BTN_CLASS = mergeClass(
67
+ 'absolute end-9 top-0 border-0 bg-transparent flex h-full w-6 p-0 cursor-pointer items-center justify-center rounded-item text-fg-subtle transition-colors hover:text-fg',
68
+ KIT_FOCUS_RING.item,
69
+ );
44
70
  const ICON_CLASS = 'size-4 pointer-events-none';
45
71
 
46
- const PANEL_BASE = mergeClass('absolute z-10 flex w-max min-w-full flex-col gap-2 p-4', kitSurfaceRecipe('raised'));
72
+ const PANEL_BASE = mergeClass('absolute z-10 flex w-max flex-col gap-2 p-3', kitSurfaceRecipe('raised'));
47
73
  const MONTHS_CLASS = 'flex gap-4';
48
74
  const MONTH_CLASS = 'flex flex-col gap-1';
49
75
  const MONTH_HEAD_CLASS = 'flex items-center justify-between gap-2';
50
- const MONTH_TITLE_CLASS = 'flex-1 text-center text-base font-medium text-fg';
51
- const NAV_CLASS = 'inline-flex size-8 p-0 border-0 bg-transparent cursor-pointer items-center justify-center rounded-md 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-1 focus-visible:ring-inset focus-visible:ring-ring data-kit-quiet:focus-visible:ring-0';
76
+ // 标题 = 可点按钮(点进月 / 年面板,卡 DatePicker §6);头高 40
77
+ const MONTH_TITLE_CLASS = mergeClass(
78
+ 'flex-1 cursor-pointer rounded-item border-0 bg-transparent px-2 py-1 text-center text-base font-medium text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press',
79
+ KIT_FOCUS_ITEM_QUIET,
80
+ );
81
+ const YEAR_TITLE_CLASS = 'flex-1 text-center text-base font-medium text-fg';
82
+ // 月 / 年面板:3 列格,格高 32,选中 / 今天与日格同角色
83
+ const PERIOD_GRID_CLASS = 'grid grid-cols-3 gap-1';
84
+ const PERIOD_BASE = mergeClass('flex h-8 min-w-14 items-center justify-center rounded-item px-2 text-sm transition-colors', KIT_FOCUS_ITEM_QUIET);
85
+ const NAV_CLASS = mergeClass(
86
+ 'inline-flex size-8 p-0 border-0 bg-transparent cursor-pointer items-center justify-center rounded-item text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg',
87
+ KIT_FOCUS_ITEM_QUIET,
88
+ );
52
89
  const NAV_SPACER_CLASS = 'size-8';
53
90
  const NAV_GLYPH_CLASS = 'inline-block rtl:rotate-180';
54
91
  const ROW_CLASS = 'grid grid-cols-7';
55
92
  const HEADCELL_CLASS = 'flex size-8 items-center justify-center text-xs font-medium text-fg-muted';
56
93
  const SPACER_CELL_CLASS = 'size-8';
57
94
  // 焦点环只在键盘操作时显示:focus-visible + 1px 内收环(列表项 / 日格类,R4);程序化落焦时若最近一次交互是鼠标,
58
- // 日格带 data-kit-quiet,data-kit-quiet:focus-visible:ring-0 把环压掉(见 focusCell)。今天只用文字强调(primary 粗体),不画边框,避免与焦点环叠成一团
59
- const DAY_FOCUS = 'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring data-kit-quiet:focus-visible:ring-0';
95
+ // 日格带 data-kit-quiet,data-kit-quiet:focus-visible:ring-0 把环压掉(见 focusCell)。今天 = 主色细描边(border),焦点环是内收环,两者不同层不叠
96
+ const DAY_FOCUS = KIT_FOCUS_ITEM_QUIET;
97
+ // 选中 = 选中出口 + 条目圆角;今天 = 主色细描边(与选中不冲突,选中格不画描边);范围中间格 = 直角通栏的主色淡底(kitTonalFillRecipe)
98
+ const DAY_BASE = mergeClass('flex size-8 items-center justify-center text-sm transition-colors', DAY_FOCUS);
60
99
  const DAY_CLASS = {
61
- idle: `flex size-8 cursor-pointer items-center justify-center rounded-md text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${DAY_FOCUS}`,
62
- today: `flex size-8 cursor-pointer items-center justify-center rounded-full text-sm font-semibold text-primary-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${DAY_FOCUS}`,
63
- between: `flex size-8 cursor-pointer items-center justify-center rounded-none bg-primary-soft text-sm text-primary-on-soft transition-colors ${DAY_FOCUS}`,
64
- selected: `flex size-8 cursor-pointer items-center justify-center rounded-full bg-primary text-sm font-medium text-primary-fg ${DAY_FOCUS}`,
65
- disabled: `flex size-8 cursor-not-allowed items-center justify-center rounded-md bg-surface-sunken text-sm text-fg-subtle ${DAY_FOCUS}`,
100
+ idle: mergeClass(DAY_BASE, 'cursor-pointer rounded-item text-fg hover:bg-state-layer-hover active:bg-state-layer-press'),
101
+ today: mergeClass(DAY_BASE, 'cursor-pointer rounded-item border border-primary text-primary-on-soft hover:bg-state-layer-hover active:bg-state-layer-press'),
102
+ between: mergeClass(mergeClass(DAY_BASE, 'cursor-pointer rounded-none text-primary-on-soft'), kitTonalFillRecipe()),
103
+ selected: mergeClass(mergeClass(DAY_BASE, 'cursor-pointer rounded-item'), kitSelectedRecipe()),
104
+ disabled: mergeClass(mergeClass(DAY_BASE, 'cursor-not-allowed rounded-item text-fg-subtle'), kitWellRecipe()),
105
+ } as const;
106
+ const PERIOD_CLASS = {
107
+ idle: mergeClass(PERIOD_BASE, 'cursor-pointer text-fg hover:bg-state-layer-hover active:bg-state-layer-press'),
108
+ today: mergeClass(PERIOD_BASE, 'cursor-pointer border border-primary text-primary-on-soft hover:bg-state-layer-hover active:bg-state-layer-press'),
109
+ selected: mergeClass(mergeClass(PERIOD_BASE, 'cursor-pointer'), kitSelectedRecipe()),
110
+ disabled: mergeClass(mergeClass(PERIOD_BASE, 'cursor-not-allowed text-fg-subtle'), kitWellRecipe()),
66
111
  } as const;
67
- const FOOT_CLASS = 'flex items-center justify-between gap-2';
112
+ // 底栏:上边一条发丝线;左「今天」,范围模式再接已选范围文字与取消 / 确定(卡 DateRange §7)
113
+ const FOOT_CLASS = mergeClass('flex items-center gap-2 pt-2', kitDividerRecipe('top'));
114
+ const FOOT_TEXT_CLASS = 'min-w-0 flex-1 truncate text-sm text-fg-muted';
115
+ const FOOT_CANCEL_CLASS = kitActionRecipe('cancel', { size: 'sm', pointer: true, region: 'confirm' });
116
+ const FOOT_CONFIRM_CLASS = kitActionRecipe('confirm', { size: 'sm', pointer: true, region: 'confirm' });
117
+ // 面板主体:左侧快捷项竖栏(范围模式的 presets,线隔开)+ 右侧日历
118
+ const BODY_CLASS = 'flex gap-3';
119
+ const SIDE_CLASS = mergeClass('flex shrink-0 flex-col gap-1 pe-3', kitDividerRecipe('end'));
120
+ const SIDE_ITEM_BASE = mergeClass(
121
+ 'flex h-8 cursor-pointer items-center rounded-item px-3 text-start text-sm transition-colors disabled:cursor-not-allowed disabled:text-fg-disabled',
122
+ DAY_FOCUS,
123
+ );
124
+ const SIDE_ITEM_CLASS = {
125
+ idle: mergeClass(SIDE_ITEM_BASE, 'text-fg-muted hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg'),
126
+ pressed: mergeClass(SIDE_ITEM_BASE, kitSelectedRecipe()),
127
+ } as const;
128
+ const MAIN_CLASS = 'flex min-w-0 flex-col gap-2';
68
129
  // 文字钮用底色表示键盘焦点,不用环
69
- const TODAY_BTN_CLASS = 'border-0 bg-transparent cursor-pointer rounded-md px-2 py-1 text-sm text-primary-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:bg-state-layer-hover focus-visible:outline-none';
130
+ const TODAY_BTN_CLASS = `border-0 bg-transparent cursor-pointer rounded-item px-2 py-1 text-sm text-primary-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:bg-state-layer-hover ${KIT_FOCUS_DELEGATED_INPUT} disabled:cursor-not-allowed disabled:text-fg-disabled`;
70
131
  // 状态文字不再可见(R7):只给读屏播报
71
132
  const STATUS_CLASS = { sr: 'sr-only' } as const;
72
133
 
@@ -74,9 +135,9 @@ const focusCell = focusCellQuiet;
74
135
 
75
136
  /** Date / DateRange / 命令式日期框共用的自带类(并入基础组件候选类清单) */
76
137
  export const KIT_DATE_CLASS_CANDIDATES: readonly string[] = classCandidates(
77
- ROOT_CLASS, HIDDEN_CLASS, Object.values(INPUT_CLASS), OPEN_BTN_CLASS, CLEAR_BTN_CLASS, ICON_CLASS, PANEL_BASE, MONTHS_CLASS, MONTH_CLASS,
78
- MONTH_HEAD_CLASS, MONTH_TITLE_CLASS, NAV_CLASS, NAV_SPACER_CLASS, NAV_GLYPH_CLASS, ROW_CLASS, HEADCELL_CLASS, SPACER_CELL_CLASS,
79
- Object.values(DAY_CLASS), FOOT_CLASS, TODAY_BTN_CLASS, Object.values(STATUS_CLASS), 'pointer-events-auto', KIT_DROPDOWN_CLASS_CANDIDATES, FIELD_INVALID_CLASS,
138
+ ROOT_CLASS, HIDDEN_CLASS, HIDDEN_BTN_CLASS, Object.values(INPUT_CLASS), Object.values(INPUT_CLEAR_CLASS), CLEAR_PAD_CLASS, OPEN_BTN_CLASS, CLEAR_BTN_CLASS, ICON_CLASS, PANEL_BASE, MONTHS_CLASS, MONTH_CLASS,
139
+ MONTH_HEAD_CLASS, MONTH_TITLE_CLASS, YEAR_TITLE_CLASS, PERIOD_GRID_CLASS, Object.values(PERIOD_CLASS), NAV_CLASS, NAV_SPACER_CLASS, NAV_GLYPH_CLASS, ROW_CLASS, HEADCELL_CLASS, SPACER_CELL_CLASS,
140
+ Object.values(DAY_CLASS), FOOT_CLASS, FOOT_TEXT_CLASS, FOOT_CANCEL_CLASS, FOOT_CONFIRM_CLASS, BODY_CLASS, SIDE_CLASS, Object.values(SIDE_ITEM_CLASS), MAIN_CLASS, TODAY_BTN_CLASS, Object.values(STATUS_CLASS), 'pointer-events-auto', KIT_DROPDOWN_CLASS_CANDIDATES, FIELD_INVALID_CLASS, KIT_PERIOD_PICKER_CLASS_CANDIDATES,
80
141
  );
81
142
 
82
143
  // ── 禁用日期规则(Date / DateRange 共用)────────────────────────
@@ -159,6 +220,40 @@ export function isDateOutOfBounds(day: string, min: string, max: string): boolea
159
220
  return (min !== '' && day < min) || (max !== '' && day > max);
160
221
  }
161
222
 
223
+ /** 区间 [start, end](含两端与中间全部日期;颠倒亦自动按序检查)内是否包含任意被 disabled_dates 禁用的日期 */
224
+ export function hasDisabledInSpan(
225
+ start: string,
226
+ end: string,
227
+ rules: readonly DateRule[],
228
+ today: string = localIso(new Date()),
229
+ ): boolean {
230
+ if (rules.length === 0 || !isIsoDay(start) || !isIsoDay(end)) return false;
231
+ const a = dayNumOf(start);
232
+ const b = dayNumOf(end);
233
+ if (a === null || b === null) return false;
234
+ const lo = Math.min(a, b);
235
+ const hi = Math.max(a, b);
236
+ const s = textOfDayNum(lo);
237
+ const e = textOfDayNum(hi);
238
+ return rules.some((rule) => {
239
+ switch (rule.kind) {
240
+ case 'weekends': {
241
+ if (hi - lo >= 6) return true;
242
+ for (let n = lo; n <= hi; n += 1) {
243
+ const wd = new Date(`${textOfDayNum(n)}T00:00:00Z`).getUTCDay();
244
+ if (wd === 0 || wd === 6) return true;
245
+ }
246
+ return false;
247
+ }
248
+ case 'past': return s < today;
249
+ case 'future': return e > today;
250
+ case 'day': return rule.day >= s && rule.day <= e;
251
+ case 'between': return (rule.from === '' || rule.from <= e) && (rule.to === '' || rule.to >= s);
252
+ default: return false;
253
+ }
254
+ });
255
+ }
256
+
162
257
  // ── 日历面板(Date 与 DateRange 共用的唯一实现)──────────────────
163
258
 
164
259
  export interface DateLimits { min: string; max: string; rules: DateRule[]; weekStart: number }
@@ -176,14 +271,21 @@ export interface DatePanelCfg {
176
271
  /** 当前值(single 只看 start) */
177
272
  value(): DateSpan;
178
273
  pick(span: DateSpan): void;
179
- reject(day: string): void;
274
+ reject(day: string, span?: DateSpan): void;
180
275
  onToggle(open: boolean): void;
276
+ /** 范围模式的快捷项(面板左栏竖排);点一项 = 把该区间放进草稿,确认后才提交 */
277
+ presets?(): DatePanelPreset[];
278
+ /** 快捷项分组的可访问名 */
279
+ presetsLabel?(): string;
181
280
  }
182
281
 
282
+ export interface DatePanelPreset { key: string; label: string; start: string; end: string; disabled: boolean }
283
+
183
284
  export interface DatePanel {
184
285
  el: HTMLElement;
185
286
  isOpen(): boolean;
186
- open(): void;
287
+ open(focusPanel?: boolean): void;
288
+ focusCursor(): void;
187
289
  close(refocus: boolean): void;
188
290
  /** 值 / 限制变了,开着时重画 */
189
291
  refresh(): void;
@@ -192,18 +294,31 @@ export interface DatePanel {
192
294
 
193
295
  type DayBar = 'rule' | 'bound' | null;
194
296
 
297
+ /**
298
+ * 日期格 / 周期格的自报(主题流水线):部件是「格」;选中与当前日(aria-current=date)按交互状态自报,
299
+ * 与 aria-selected / aria-pressed / aria-current 同步写,主题取值才认得出这一格(悬停、禁用仍走伪类与 aria-disabled)。
300
+ * DateRange / PeriodPicker 的格子共用这一份。
301
+ */
302
+ export function kitMarkPickCell(el: Element, selected: boolean, current: boolean): void {
303
+ kitReportSelf(el, { part: 'cell' });
304
+ kitMarkInteract(el, 'selected', selected);
305
+ kitMarkInteract(el, 'current', current);
306
+ }
307
+
195
308
  export function createDatePanel(cfg: DatePanelCfg): DatePanel {
196
309
  const el = document.createElement('div');
197
310
  el.id = nextUid('kit-datepanel');
198
311
  el.setAttribute('role', 'dialog');
199
312
  el.className = HIDDEN_CLASS;
313
+ // 日历面板是下拉浮起(§8.2「菜单、下拉、气泡」),挂在输入框里但取值按浮起走
314
+ kitReportSelf(el, { level: 'float' });
200
315
  const status = document.createElement('p');
201
316
  status.setAttribute('aria-live', 'polite');
202
317
  status.className = STATUS_CLASS.sr;
203
318
  trackInputModality(el.ownerDocument);
204
319
  // 键盘一动,鼠标落焦时压掉的焦点环恢复显示
205
320
  el.addEventListener('keydown', () => {
206
- el.querySelectorAll('[data-kit-quiet]').forEach((n) => n.removeAttribute('data-kit-quiet'));
321
+ el.querySelectorAll(`[${KIT_ATTR_QUIET}]`).forEach((n) => n.removeAttribute(KIT_ATTR_QUIET));
207
322
  }, true);
208
323
  cfg.scope.appendChild(el);
209
324
 
@@ -212,6 +327,10 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
212
327
  let cursor = 0;
213
328
  let pending: number | null = null;
214
329
  let hover: number | null = null;
330
+ // 范围模式:选完终点只进草稿,点「确定」才提交(取消 / 收起丢弃)
331
+ let draft: DateSpan | null = null;
332
+ // 标题下钻:day → month(选月)→ year(选年)
333
+ let view: 'day' | 'month' | 'year' = 'day';
215
334
  let offOutside: (() => void) | null = null;
216
335
 
217
336
  const todayNum = (): number => dayNumOf(localIso(new Date())) ?? 0;
@@ -233,7 +352,94 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
233
352
  syncDropdown(el, true, PANEL_BASE, cfg.anchor);
234
353
  };
235
354
 
236
- const cellOf = (day: number): HTMLElement | null => el.querySelector<HTMLElement>(`[data-kit-day="${textOfDayNum(day)}"]`);
355
+ const cellOf = (day: number): HTMLElement | null => el.querySelector<HTMLElement>(`[${KIT_ATTR_DAY}="${textOfDayNum(day)}"]`);
356
+
357
+ /** 月 / 年面板(标题下钻):头 = 上 / 下一页 + 标题,体 = 3 列周期格;返回标题文字。点格只改游标所在月 / 年,回到上一级 */
358
+ function drawPeriodView(doc: Document, wrap: HTMLElement, lim: DateLimits, selA: number | null, selB: number | null, today: number): string {
359
+ const cur = ymdOfDayNum(viewFirst);
360
+ const lang = kitLocaleAt(cfg.anchor) || 'zh-CN';
361
+ const box = doc.createElement('div');
362
+ box.className = MONTH_CLASS;
363
+ const head = doc.createElement('div');
364
+ head.className = MONTH_HEAD_CLASS;
365
+ const nav = (kind: 'prev' | 'next'): HTMLElement => {
366
+ const b = doc.createElement('button');
367
+ b.type = 'button';
368
+ b.className = NAV_CLASS;
369
+ b.setAttribute(KIT_ATTR_NAV, kind);
370
+ b.setAttribute('aria-label', kitText(kind === 'prev' ? 'soma.kit.dp_prev_month' : 'soma.kit.dp_next_month', undefined, cfg.anchor));
371
+ const glyph = doc.createElement('span');
372
+ glyph.setAttribute('aria-hidden', 'true');
373
+ glyph.className = NAV_GLYPH_CLASS;
374
+ glyph.appendChild(kitIcon(kind === 'prev' ? 'chevron-left' : 'chevron-right', 'md'));
375
+ b.appendChild(glyph);
376
+ return b;
377
+ };
378
+ let title: string;
379
+ const cells: Array<{ key: string; label: string; selected: boolean; current: boolean; off: boolean }> = [];
380
+ if (view === 'month') {
381
+ title = String(cur.y);
382
+ const fmt = new Intl.DateTimeFormat(lang, { month: 'short', timeZone: 'UTC' });
383
+ for (let m = 1; m <= 12; m += 1) {
384
+ const first = Math.round(Date.UTC(cur.y, m - 1, 1) / 86_400_000);
385
+ const last = first + daysInMonth(cur.y, m) - 1;
386
+ const inMonth = (n: number | null): boolean => n !== null && n >= first && n <= last;
387
+ const bounded = (lim.min !== '' && textOfDayNum(last) < lim.min) || (lim.max !== '' && textOfDayNum(first) > lim.max);
388
+ cells.push({
389
+ key: String(m),
390
+ label: fmt.format(new Date(first * 86_400_000)),
391
+ selected: inMonth(selA) || inMonth(selB),
392
+ current: inMonth(today),
393
+ off: bounded,
394
+ });
395
+ }
396
+ } else {
397
+ const start = cur.y - (cur.y % 12);
398
+ title = `${start} – ${start + 11}`;
399
+ const yearOf = (n: number | null): number | null => (n === null ? null : ymdOfDayNum(n).y);
400
+ for (let y = start; y < start + 12; y += 1) {
401
+ const bounded = (lim.min !== '' && y < Number(lim.min.slice(0, 4))) || (lim.max !== '' && y > Number(lim.max.slice(0, 4)));
402
+ cells.push({ key: String(y), label: String(y), selected: yearOf(selA) === y || yearOf(selB) === y, current: yearOf(today) === y, off: bounded });
403
+ }
404
+ }
405
+ const t = doc.createElement(view === 'month' ? 'button' : 'div');
406
+ t.textContent = title;
407
+ if (view === 'month') {
408
+ (t as HTMLButtonElement).type = 'button';
409
+ t.className = MONTH_TITLE_CLASS;
410
+ t.setAttribute(KIT_ATTR_NAV, 'title');
411
+ } else {
412
+ t.className = YEAR_TITLE_CLASS;
413
+ t.setAttribute('aria-live', 'polite');
414
+ }
415
+ head.append(nav('prev'), t, nav('next'));
416
+ // 年 / 月切换那一条是面板的标题行(先自报、后按实际角色剥类;旧版原样)
417
+ kitReportSelf(head, { level: 'head' });
418
+ head.className = kitLevelClassFor(head, head.className);
419
+ box.appendChild(head);
420
+ const grid = doc.createElement('div');
421
+ grid.className = PERIOD_GRID_CLASS;
422
+ grid.setAttribute('role', 'group');
423
+ grid.setAttribute('aria-label', title);
424
+ for (const c of cells) {
425
+ const b = doc.createElement('button');
426
+ b.type = 'button';
427
+ b.setAttribute(KIT_ATTR_PERIOD, c.key);
428
+ b.textContent = c.label;
429
+ b.className = c.off ? PERIOD_CLASS.disabled : c.selected ? PERIOD_CLASS.selected : c.current ? PERIOD_CLASS.today : PERIOD_CLASS.idle;
430
+ b.setAttribute('aria-pressed', c.selected ? 'true' : 'false');
431
+ if (c.current) b.setAttribute('aria-current', 'date');
432
+ if (c.off) {
433
+ b.disabled = true;
434
+ b.setAttribute('aria-disabled', 'true');
435
+ }
436
+ kitMarkPickCell(b, c.selected, c.current);
437
+ grid.appendChild(b);
438
+ }
439
+ box.appendChild(grid);
440
+ wrap.appendChild(box);
441
+ return title;
442
+ }
237
443
 
238
444
  /** focus: cursor = 强制把焦点放到游标格;keep = 重画前焦点在面板里就还原;none = 不动 */
239
445
  function render(focus: 'cursor' | 'keep' | 'none'): void {
@@ -242,8 +448,9 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
242
448
  const doc = el.ownerDocument;
243
449
  const active = doc.activeElement as HTMLElement | null;
244
450
  const had = active !== null && el.contains(active);
245
- const keepDay = had ? active.getAttribute('data-kit-day') : null;
246
- const keepNav = had ? active.getAttribute('data-kit-nav') : null;
451
+ const keepDay = had ? active.getAttribute(KIT_ATTR_DAY) : null;
452
+ const keepNav = had ? active.getAttribute(KIT_ATTR_NAV) : null;
453
+ const keepPreset = had ? active.getAttribute(KIT_ATTR_PRESET) : null;
247
454
  const lang = kitLocaleAt(cfg.anchor);
248
455
  if (lang !== '') el.setAttribute('lang', lang); else el.removeAttribute('lang');
249
456
  el.setAttribute('dir', kitDirAt(cfg.anchor));
@@ -257,18 +464,49 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
257
464
  const other = hover ?? pending;
258
465
  selA = Math.min(pending, other);
259
466
  selB = Math.max(pending, other);
467
+ } else if (range && draft !== null) {
468
+ selA = dayNumOf(draft.start);
469
+ selB = dayNumOf(draft.end);
260
470
  } else {
261
471
  selA = startN;
262
472
  selB = range ? (endN ?? startN) : startN;
263
473
  }
264
474
  const today = todayNum();
265
- const months = range ? [viewFirst, addMonths(viewFirst, 1)] : [viewFirst];
475
+ const months = view !== 'day' ? [] : range ? [viewFirst, addMonths(viewFirst, 1)] : [viewFirst];
266
476
  const ws = lim.weekStart;
267
477
  el.textContent = '';
268
478
 
479
+ const body = doc.createElement('div');
480
+ body.className = BODY_CLASS;
481
+ const presets = range && cfg.presets ? cfg.presets() : [];
482
+ if (presets.length > 0) {
483
+ const side = doc.createElement('div');
484
+ side.className = SIDE_CLASS;
485
+ side.setAttribute('role', 'group');
486
+ side.setAttribute('aria-label', cfg.presetsLabel ? cfg.presetsLabel() : '');
487
+ for (const pre of presets) {
488
+ const b = doc.createElement('button');
489
+ b.type = 'button';
490
+ b.setAttribute(KIT_ATTR_PRESET, pre.key);
491
+ const pressed = selA !== null && selB !== null && textOfDayNum(selA) === pre.start && textOfDayNum(selB) === pre.end;
492
+ b.className = pressed ? SIDE_ITEM_CLASS.pressed : SIDE_ITEM_CLASS.idle;
493
+ b.setAttribute('aria-pressed', pressed ? 'true' : 'false');
494
+ b.disabled = pre.disabled;
495
+ b.textContent = pre.label;
496
+ side.appendChild(b);
497
+ }
498
+ body.appendChild(side);
499
+ }
500
+ const main = doc.createElement('div');
501
+ main.className = MAIN_CLASS;
502
+ body.appendChild(main);
503
+
269
504
  const wrap = doc.createElement('div');
270
505
  wrap.className = MONTHS_CLASS;
271
506
  const titles: string[] = [];
507
+ if (view !== 'day') {
508
+ titles.push(drawPeriodView(doc, wrap, lim, selA, selB, today));
509
+ }
272
510
  months.forEach((first, idx) => {
273
511
  const title = monthTitle(first, '', cfg.anchor);
274
512
  titles.push(title);
@@ -280,7 +518,7 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
280
518
  const b = doc.createElement('button');
281
519
  b.type = 'button';
282
520
  b.className = NAV_CLASS;
283
- b.setAttribute('data-kit-nav', kind);
521
+ b.setAttribute(KIT_ATTR_NAV, kind);
284
522
  b.setAttribute('aria-label', kitText(kind === 'prev' ? 'soma.kit.dp_prev_month' : 'soma.kit.dp_next_month', undefined, cfg.anchor));
285
523
  const glyph = doc.createElement('span');
286
524
  glyph.setAttribute('aria-hidden', 'true');
@@ -294,10 +532,14 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
294
532
  s.className = NAV_SPACER_CLASS;
295
533
  return s;
296
534
  };
297
- const t = doc.createElement('div');
535
+ const t = doc.createElement('button');
536
+ t.type = 'button';
298
537
  t.className = MONTH_TITLE_CLASS;
538
+ t.setAttribute(KIT_ATTR_NAV, 'title');
299
539
  t.textContent = title;
300
540
  head.append(idx === 0 ? navBtn('prev') : spacer(), t, idx === months.length - 1 ? navBtn('next') : spacer());
541
+ kitReportSelf(head, { level: 'head' });
542
+ head.className = kitLevelClassFor(head, head.className);
301
543
  box.appendChild(head);
302
544
 
303
545
  const grid = doc.createElement('div');
@@ -331,7 +573,7 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
331
573
  const bar = barOf(n, lim);
332
574
  const endpoint = selA !== null && selB !== null && (n === selA || n === selB);
333
575
  const between = selA !== null && selB !== null && n > selA && n < selB;
334
- c.setAttribute('data-kit-day', text);
576
+ c.setAttribute(KIT_ATTR_DAY, text);
335
577
  c.tabIndex = n === cursor ? 0 : -1;
336
578
  c.setAttribute('aria-label', dayFullName(n, '', cfg.anchor));
337
579
  c.setAttribute('aria-selected', endpoint || between ? 'true' : 'false');
@@ -345,6 +587,7 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
345
587
  : between ? DAY_CLASS.between
346
588
  : n === today ? DAY_CLASS.today : DAY_CLASS.idle;
347
589
  c.textContent = String(cell.day);
590
+ kitMarkPickCell(c, endpoint || between, n === today);
348
591
  row.appendChild(c);
349
592
  }
350
593
  grid.appendChild(row);
@@ -352,7 +595,8 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
352
595
  box.appendChild(grid);
353
596
  wrap.appendChild(box);
354
597
  });
355
- el.appendChild(wrap);
598
+ main.appendChild(wrap);
599
+ el.appendChild(body);
356
600
 
357
601
  const stage = range ? kitText(pending === null ? 'soma.kit.dp_pick_start' : 'soma.kit.dp_pick_end', undefined, cfg.anchor) : '';
358
602
  const statusText = [titles.join(' – '), stage].filter((s) => s !== '').join(' · ');
@@ -361,20 +605,46 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
361
605
  el.appendChild(status);
362
606
 
363
607
  const foot = doc.createElement('div');
364
- foot.className = FOOT_CLASS;
608
+ // 「今天 / 取消 / 确定」那一排是面板底栏(先自报、后经 kitLevelClassFor 落类)
609
+ kitReportSelf(foot, { level: 'foot' });
610
+ foot.className = kitLevelClassFor(foot, FOOT_CLASS);
365
611
  const todayBtn = doc.createElement('button');
366
612
  todayBtn.type = 'button';
367
613
  todayBtn.className = TODAY_BTN_CLASS;
368
- todayBtn.setAttribute('data-kit-nav', 'today');
614
+ todayBtn.setAttribute(KIT_ATTR_NAV, 'today');
369
615
  todayBtn.textContent = kitText('soma.kit.cal_today', undefined, cfg.anchor);
616
+ if (!range && barOf(today, lim) !== null) {
617
+ todayBtn.disabled = true;
618
+ todayBtn.setAttribute('aria-disabled', 'true');
619
+ }
370
620
  foot.appendChild(todayBtn);
621
+ if (range) {
622
+ const shown = pending !== null ? `${textOfDayNum(pending)} – ` : selA !== null && selB !== null ? `${textOfDayNum(selA)} – ${textOfDayNum(selB)}` : '';
623
+ const text = doc.createElement('span');
624
+ text.className = FOOT_TEXT_CLASS;
625
+ text.setAttribute(KIT_ATTR_RANGE_TEXT, '');
626
+ text.textContent = shown;
627
+ const cancel = doc.createElement('button');
628
+ cancel.type = 'button';
629
+ cancel.className = FOOT_CANCEL_CLASS;
630
+ cancel.setAttribute(KIT_ATTR_NAV, 'cancel');
631
+ cancel.textContent = kitText('soma.kit.cancel', undefined, cfg.anchor);
632
+ const confirm = doc.createElement('button');
633
+ confirm.type = 'button';
634
+ confirm.className = FOOT_CONFIRM_CLASS;
635
+ confirm.setAttribute(KIT_ATTR_NAV, 'confirm');
636
+ confirm.disabled = draft === null;
637
+ confirm.textContent = kitText('soma.kit.ok', undefined, cfg.anchor);
638
+ foot.append(text, cancel, confirm);
639
+ }
371
640
  el.appendChild(foot);
372
641
 
373
642
  if (isOpen) mount();
374
- if (focus === 'cursor') focusCell(cellOf(cursor));
643
+ if (focus === 'cursor') focusCell(view === 'day' ? cellOf(cursor) : el.querySelector<HTMLElement>(`[${KIT_ATTR_NAV}="title"]`));
375
644
  else if (focus === 'keep' && had) {
376
- if (keepNav !== null) focusCell(el.querySelector<HTMLElement>(`[data-kit-nav="${keepNav}"]`));
377
- else focusCell((keepDay !== null ? el.querySelector<HTMLElement>(`[data-kit-day="${keepDay}"]`) : null) ?? cellOf(cursor));
645
+ if (keepPreset !== null) focusCell(el.querySelector<HTMLElement>(`[${KIT_ATTR_PRESET}="${keepPreset}"]`));
646
+ else if (keepNav !== null) focusCell(el.querySelector<HTMLElement>(`[${KIT_ATTR_NAV}="${keepNav}"]`));
647
+ else focusCell((keepDay !== null ? el.querySelector<HTMLElement>(`[${KIT_ATTR_DAY}="${keepDay}"]`) : null) ?? cellOf(cursor));
378
648
  }
379
649
  }
380
650
 
@@ -386,7 +656,7 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
386
656
  const a = el.ownerDocument.activeElement as HTMLElement | null;
387
657
  const inPanel = a !== null && el.contains(a);
388
658
  if (a === cell) return;
389
- if (!inPanel || a?.hasAttribute('data-kit-nav')) focusCell(cell);
659
+ if (!inPanel || a?.hasAttribute(KIT_ATTR_NAV)) focusCell(cell);
390
660
  }
391
661
 
392
662
  function close(refocus: boolean): void {
@@ -394,6 +664,8 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
394
664
  isOpen = false;
395
665
  pending = null;
396
666
  hover = null;
667
+ draft = null;
668
+ view = 'day';
397
669
  offOutside?.();
398
670
  offOutside = null;
399
671
  syncDropdown(el, false);
@@ -402,7 +674,7 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
402
674
  if (refocus) cfg.focusTarget().focus();
403
675
  }
404
676
 
405
- function open(): void {
677
+ function open(focusPanel = true): void {
406
678
  if (isOpen) return;
407
679
  const lim = cfg.limits();
408
680
  const v = cfg.value();
@@ -419,16 +691,20 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
419
691
  viewFirst = monthFirstOf(cursor);
420
692
  pending = null;
421
693
  hover = null;
694
+ draft = null;
695
+ view = 'day';
422
696
  isOpen = true;
423
697
  offOutside = onOutsidePress(cfg.scope, () => isOpen, () => close(false), (node) => el.contains(node));
424
698
  render('none');
425
699
  cfg.onToggle(true);
426
- // 面板经浮层端口挂出,搬移 / 同步可能让先前的落焦丢失,浏览器随后把焦点交给「第一个可聚焦」(底部今天钮):
427
- // 先落一次,再在微任务与下一帧各兜一次,只在焦点跑偏时才纠正
428
- focusCell(cellOf(cursor));
429
- queueMicrotask(settleOpenFocus);
430
- const raf = el.ownerDocument.defaultView?.requestAnimationFrame;
431
- if (typeof raf === 'function') raf.call(el.ownerDocument.defaultView, settleOpenFocus);
700
+ if (focusPanel) {
701
+ // 面板经浮层端口挂出,搬移 / 同步可能让先前的落焦丢失,浏览器随后把焦点交给「第一个可聚焦」(底部今天钮):
702
+ // 先落一次,再在微任务与下一帧各兜一次,只在焦点跑偏时才纠正
703
+ focusCell(cellOf(cursor));
704
+ queueMicrotask(settleOpenFocus);
705
+ const raf = el.ownerDocument.defaultView?.requestAnimationFrame;
706
+ if (typeof raf === 'function') raf.call(el.ownerDocument.defaultView, settleOpenFocus);
707
+ }
432
708
  }
433
709
 
434
710
  function pickDay(n: number): void {
@@ -450,35 +726,131 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
450
726
  if (pending === null) {
451
727
  pending = n;
452
728
  hover = n;
729
+ draft = null;
453
730
  render('cursor');
454
731
  return;
455
732
  }
456
733
  const a = Math.min(pending, n);
457
734
  const b = Math.max(pending, n);
458
- cfg.pick({ start: textOfDayNum(a), end: textOfDayNum(b) });
459
- close(true);
735
+ const nextDraft: DateSpan = { start: textOfDayNum(a), end: textOfDayNum(b) };
736
+ if (hasDisabledInSpan(nextDraft.start, nextDraft.end, lim.rules)) {
737
+ pending = null;
738
+ hover = null;
739
+ draft = null;
740
+ cfg.reject(nextDraft.start, nextDraft);
741
+ render('cursor');
742
+ return;
743
+ }
744
+ draft = nextDraft;
745
+ pending = null;
746
+ hover = null;
747
+ render('cursor');
748
+ }
749
+
750
+ /** 区间悬停预览原地更新:切换现有 [data-kit-day] 类名与底栏文案,不在 pointerover 时清空重建 120 个节点 */
751
+ function syncHoverPreview(): void {
752
+ if (cfg.mode !== 'range' || pending === null || view !== 'day') return;
753
+ const lim = cfg.limits();
754
+ const today = todayNum();
755
+ const other = hover ?? pending;
756
+ const selA = Math.min(pending, other);
757
+ const selB = Math.max(pending, other);
758
+ for (const c of Array.from(el.querySelectorAll<HTMLElement>(`[${KIT_ATTR_DAY}]`))) {
759
+ const n = dayNumOf(c.getAttribute(KIT_ATTR_DAY));
760
+ if (n === null) continue;
761
+ const bar = barOf(n, lim);
762
+ const endpoint = n === selA || n === selB;
763
+ const between = n > selA && n < selB;
764
+ const selectedAttr = endpoint || between ? 'true' : 'false';
765
+ if (c.getAttribute('aria-selected') !== selectedAttr) c.setAttribute('aria-selected', selectedAttr);
766
+ kitMarkInteract(c, 'selected', endpoint || between);
767
+ const nextCls = bar !== null ? DAY_CLASS.disabled
768
+ : endpoint ? DAY_CLASS.selected
769
+ : between ? DAY_CLASS.between
770
+ : n === today ? DAY_CLASS.today : DAY_CLASS.idle;
771
+ if (c.className !== nextCls) c.className = nextCls;
772
+ }
773
+ const rangeText = el.querySelector<HTMLElement>(`[${KIT_ATTR_RANGE_TEXT}]`);
774
+ if (rangeText) {
775
+ const shown = hover !== null && hover !== pending
776
+ ? `${textOfDayNum(selA)} – ${textOfDayNum(selB)}`
777
+ : `${textOfDayNum(pending)} – `;
778
+ if (rangeText.textContent !== shown) rangeText.textContent = shown;
779
+ }
460
780
  }
461
781
 
462
782
  const onClick = (event: Event): void => {
463
783
  const target = event.target as HTMLElement | null;
464
- const nav = target?.closest<HTMLElement>('[data-kit-nav]');
784
+ const pre = target?.closest<HTMLButtonElement>(`[${KIT_ATTR_PRESET}]`);
785
+ if (pre) {
786
+ const hit = cfg.presets?.().find((x) => x.key === pre.getAttribute(KIT_ATTR_PRESET));
787
+ const startN = hit ? dayNumOf(hit.start) : null;
788
+ if (!hit || hit.disabled || startN === null) return;
789
+ draft = { start: hit.start, end: hit.end };
790
+ pending = null;
791
+ hover = null;
792
+ cursor = startN;
793
+ viewFirst = monthFirstOf(startN);
794
+ view = 'day';
795
+ render('keep');
796
+ return;
797
+ }
798
+ const per = target?.closest<HTMLButtonElement>(`[${KIT_ATTR_PERIOD}]`);
799
+ if (per) {
800
+ if (per.disabled) return;
801
+ const key = Number(per.getAttribute(KIT_ATTR_PERIOD));
802
+ const cur = ymdOfDayNum(viewFirst);
803
+ const months = view === 'year' ? (key - cur.y) * 12 : key - cur.m;
804
+ viewFirst = addMonths(viewFirst, months);
805
+ cursor = addMonths(cursor, months);
806
+ view = view === 'year' ? 'month' : 'day';
807
+ render('cursor');
808
+ return;
809
+ }
810
+ const nav = target?.closest<HTMLElement>(`[${KIT_ATTR_NAV}]`);
465
811
  if (nav) {
466
- const kind = nav.getAttribute('data-kit-nav');
812
+ const kind = nav.getAttribute(KIT_ATTR_NAV);
467
813
  if (kind === 'today') {
468
- cursor = todayNum();
814
+ const tNum = todayNum();
815
+ if (cfg.mode === 'single') {
816
+ if (barOf(tNum, cfg.limits()) !== null) return;
817
+ cursor = tNum;
818
+ const tIso = textOfDayNum(tNum);
819
+ cfg.pick({ start: tIso, end: tIso });
820
+ close(true);
821
+ return;
822
+ }
823
+ cursor = tNum;
824
+ view = 'day';
469
825
  ensureVisible();
470
- if (cfg.mode === 'range') viewFirst = monthFirstOf(cursor);
826
+ viewFirst = monthFirstOf(cursor);
827
+ render('cursor');
828
+ return;
829
+ }
830
+ if (kind === 'title') {
831
+ view = view === 'day' ? 'month' : 'year';
471
832
  render('cursor');
472
833
  return;
473
834
  }
474
- const delta = kind === 'next' ? 1 : -1;
835
+ if (kind === 'cancel') {
836
+ close(true);
837
+ return;
838
+ }
839
+ if (kind === 'confirm') {
840
+ if (draft === null) return;
841
+ cfg.pick(draft);
842
+ close(true);
843
+ return;
844
+ }
845
+ const step = view === 'day' ? 1 : view === 'month' ? 12 : 144;
846
+ const delta = (kind === 'next' ? 1 : -1) * step;
475
847
  viewFirst = addMonths(viewFirst, delta);
476
848
  cursor = addMonths(cursor, delta);
477
849
  render('keep');
478
850
  return;
479
851
  }
480
- const cell = target?.closest<HTMLElement>('[data-kit-day]');
481
- const n = cell ? dayNumOf(cell.getAttribute('data-kit-day')) : null;
852
+ const cell = target?.closest<HTMLElement>(`[${KIT_ATTR_DAY}]`);
853
+ const n = cell ? dayNumOf(cell.getAttribute(KIT_ATTR_DAY)) : null;
482
854
  if (n !== null) pickDay(n);
483
855
  };
484
856
 
@@ -494,9 +866,9 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
494
866
  if (handoffTab(event, el, cfg.focusTarget())) close(false);
495
867
  return;
496
868
  }
497
- const cell = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-day]');
869
+ const cell = (event.target as HTMLElement | null)?.closest<HTMLElement>(`[${KIT_ATTR_DAY}]`);
498
870
  if (!cell) return;
499
- const here = dayNumOf(cell.getAttribute('data-kit-day'));
871
+ const here = dayNumOf(cell.getAttribute(KIT_ATTR_DAY));
500
872
  if (here === null) return;
501
873
  cursor = here;
502
874
  const ws = cfg.limits().weekStart;
@@ -527,11 +899,11 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
527
899
 
528
900
  const onOver = (event: Event): void => {
529
901
  if (pending === null) return;
530
- const cell = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-day]');
531
- const n = cell ? dayNumOf(cell.getAttribute('data-kit-day')) : null;
902
+ const cell = (event.target as HTMLElement | null)?.closest<HTMLElement>(`[${KIT_ATTR_DAY}]`);
903
+ const n = cell ? dayNumOf(cell.getAttribute(KIT_ATTR_DAY)) : null;
532
904
  if (n === null || n === hover) return;
533
905
  hover = n;
534
- render('keep');
906
+ syncHoverPreview();
535
907
  };
536
908
 
537
909
  el.addEventListener('click', onClick);
@@ -542,6 +914,7 @@ export function createDatePanel(cfg: DatePanelCfg): DatePanel {
542
914
  el,
543
915
  isOpen: () => isOpen,
544
916
  open,
917
+ focusCursor() { focusCell(cellOf(cursor)); },
545
918
  close,
546
919
  refresh() { if (isOpen) render('keep'); },
547
920
  dispose() {
@@ -626,6 +999,8 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
626
999
  input.autocomplete = 'off';
627
1000
  // 质感标记:带边框的是 input 自己(右侧开关钮 / 清除钮无边无底在其内)
628
1001
  setKitFace(input, 'field');
1002
+ // 文本框本身是承载值的控件部件(与 Input 的 <input> 同口径)
1003
+ kitReportSelf(input, { part: 'control' });
629
1004
  input.spellcheck = false;
630
1005
  const hidden = document.createElement('input');
631
1006
  hidden.type = 'hidden';
@@ -637,7 +1012,7 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
637
1012
  const clear = document.createElement('button');
638
1013
  clear.type = 'button';
639
1014
  clear.appendChild(kitIcon('close', 'sm'));
640
- clear.className = HIDDEN_CLASS;
1015
+ clear.className = HIDDEN_BTN_CLASS;
641
1016
  // 还原提示的礼貌播报位(仅读屏可听):还原后的值有效,不标 aria-invalid
642
1017
  const note = document.createElement('p');
643
1018
  note.setAttribute('role', 'status');
@@ -677,6 +1052,8 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
677
1052
  synced = value;
678
1053
  hidden.value = value;
679
1054
  internal = false;
1055
+ const showClear = canEdit(s) && s.clearable && synced !== '';
1056
+ clear.className = showClear ? CLEAR_BTN_CLASS : HIDDEN_BTN_CLASS;
680
1057
  paintValidity(s, value);
681
1058
  hooks.commit(value, typed);
682
1059
  }
@@ -691,7 +1068,10 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
691
1068
  input.setCustomValidity(msg);
692
1069
  const bad = msg !== '' || s.invalid;
693
1070
  if (bad) input.setAttribute('aria-invalid', 'true'); else input.removeAttribute('aria-invalid');
694
- const baseCls = s.fieldClass !== '' ? s.fieldClass : INPUT_CLASS[s.size];
1071
+ const showClear = canEdit(s) && s.clearable && synced !== '';
1072
+ const baseCls = s.fieldClass !== ''
1073
+ ? (showClear ? `${s.fieldClass} ${CLEAR_PAD_CLASS}` : s.fieldClass)
1074
+ : (showClear ? INPUT_CLEAR_CLASS : INPUT_CLASS)[s.size];
695
1075
  input.className = withInvalid(baseCls, bad);
696
1076
  }
697
1077
 
@@ -743,18 +1123,25 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
743
1123
  };
744
1124
  const onInputKeydown = (event: KeyboardEvent): void => {
745
1125
  const s = hooks.read();
746
- if (event.key === 'ArrowDown' && canEdit(s) && !panel.isOpen()) {
1126
+ if (event.key === 'ArrowDown' && canEdit(s)) {
747
1127
  event.preventDefault();
748
- panel.open();
1128
+ if (!panel.isOpen()) panel.open(true);
1129
+ else panel.focusCursor();
1130
+ } else if (event.key === 'Enter' && canEdit(s)) {
1131
+ onInputChange();
1132
+ if (panel.isOpen() && !input.hasAttribute('aria-invalid')) panel.close(false);
749
1133
  } else if (event.key === 'Escape' && panel.isOpen()) {
750
1134
  event.preventDefault();
751
1135
  event.stopPropagation();
752
1136
  panel.close(true);
753
1137
  }
754
1138
  };
1139
+ const onInputClick = (): void => {
1140
+ if (canEdit(hooks.read()) && !panel.isOpen()) panel.open(false);
1141
+ };
755
1142
  const onBtnClick = (): void => {
756
1143
  if (!canEdit(hooks.read())) return;
757
- if (panel.isOpen()) panel.close(true); else panel.open();
1144
+ if (panel.isOpen()) panel.close(true); else panel.open(true);
758
1145
  };
759
1146
  const onClear = (): void => {
760
1147
  if (!canEdit(hooks.read())) return;
@@ -764,6 +1151,7 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
764
1151
  input.addEventListener('change', onInputChange);
765
1152
  input.addEventListener('input', clearRejectedHint);
766
1153
  input.addEventListener('focus', clearRejectedHint);
1154
+ input.addEventListener('click', onInputClick);
767
1155
  input.addEventListener('keydown', onInputKeydown);
768
1156
  btn.addEventListener('click', onBtnClick);
769
1157
  clear.addEventListener('click', onClear);
@@ -780,7 +1168,10 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
780
1168
  hidden.value = synced;
781
1169
  setAttr(hidden, 'name', s.name);
782
1170
  hidden.disabled = s.disabled;
783
- input.className = s.fieldClass !== '' ? s.fieldClass : INPUT_CLASS[s.size];
1171
+ const showClear = editable && s.clearable && synced !== '';
1172
+ input.className = s.fieldClass !== ''
1173
+ ? (showClear ? `${s.fieldClass} ${CLEAR_PAD_CLASS}` : s.fieldClass)
1174
+ : (showClear ? INPUT_CLEAR_CLASS : INPUT_CLASS)[s.size];
784
1175
  input.placeholder = s.placeholder !== '' ? s.placeholder : kitText('soma.kit.dp_placeholder', undefined, root);
785
1176
  input.readOnly = s.readonly;
786
1177
  input.disabled = s.disabled;
@@ -797,8 +1188,7 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
797
1188
  });
798
1189
  btn.disabled = !editable;
799
1190
  btn.setAttribute('aria-label', kitText('soma.kit.dp_open', undefined, root));
800
- const showClear = editable && s.clearable && synced !== '';
801
- clear.className = showClear ? CLEAR_BTN_CLASS : HIDDEN_CLASS;
1191
+ clear.className = showClear ? CLEAR_BTN_CLASS : HIDDEN_BTN_CLASS;
802
1192
  clear.setAttribute('aria-label', kitText('soma.kit.dp_clear', undefined, root));
803
1193
  if (!editable && panel.isOpen()) panel.close(false);
804
1194
  paintValidity(s, input.value.trim());
@@ -813,6 +1203,7 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
813
1203
  input.removeEventListener('change', onInputChange);
814
1204
  input.removeEventListener('input', clearRejectedHint);
815
1205
  input.removeEventListener('focus', clearRejectedHint);
1206
+ input.removeEventListener('click', onInputClick);
816
1207
  input.removeEventListener('keydown', onInputKeydown);
817
1208
  btn.removeEventListener('click', onBtnClick);
818
1209
  clear.removeEventListener('click', onClear);
@@ -835,7 +1226,8 @@ function stateOfProps(p: KitProps): FieldState {
835
1226
  weekStart: weekStartProp(p.week_start, 1),
836
1227
  placeholder: str(p.placeholder),
837
1228
  clearable: p.clearable !== false,
838
- size: sizeOf(p.size),
1229
+ // 高度档:组件自己写了 sm / lg 优先,否则取页面线判定的 kit.controlSize(没有 kit 时同原来的 sizeOf)
1230
+ size: kitControlSizeOf(p),
839
1231
  disabled: bool(p.disabled),
840
1232
  readonly: bool(p.readonly),
841
1233
  id: str(p.id),
@@ -851,6 +1243,7 @@ function stateOfProps(p: KitProps): FieldState {
851
1243
  }
852
1244
 
853
1245
  const uis = new WeakMap<HTMLElement, FieldUi>();
1246
+ const periodUis = new WeakMap<HTMLElement, { paint(): void; dispose(): void }>();
854
1247
 
855
1248
  export function createDate(): SomaComponentDefinition {
856
1249
  return {
@@ -858,7 +1251,8 @@ export function createDate(): SomaComponentDefinition {
858
1251
  name: 'Date',
859
1252
  layer: 'basic',
860
1253
  props: {
861
- value: { type: 'string', default: '', desc: '日期,YYYY-MM-DD' },
1254
+ picker: { type: 'enum', values: ['date', 'week', 'month', 'quarter', 'year'], default: 'date', desc: '粒度:date(缺省,按日)/ week / month / quarter / year;非 date 时 value / min / max 是周期文本(week "YYYY-Www"、month "YYYY-MM"、quarter "YYYY-Qn"、year "YYYY"),面板换成周期格,disabled_dates / week_start 不生效' },
1255
+ value: { type: 'string', default: '', desc: '日期,YYYY-MM-DD(picker 非 date 时为周期文本)' },
862
1256
  min: { type: 'string', default: '', desc: '最早日期,YYYY-MM-DD;之外的日期在日历里是灰格' },
863
1257
  max: { type: 'string', default: '', desc: '最晚日期,YYYY-MM-DD;之外的日期在日历里是灰格' },
864
1258
  disabled_dates: { type: 'array', default: [], desc: '不可选的日期规则(闭集):weekends / past / future / "YYYY-MM-DD" / { from?, to? };选中被禁日期时不改值并抛 reject' },
@@ -880,6 +1274,15 @@ export function createDate(): SomaComponentDefinition {
880
1274
  templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
881
1275
  controllerFactory: createKitController(() => ({
882
1276
  attach(root, api: KitApi) {
1277
+ // picker 取 week / month / quarter / year 时,Date 与 PeriodPicker 是同一个周期选择器(base/period-picker),值换成周期文本
1278
+ if (isPeriodPicker(api.props().picker)) {
1279
+ const period = mountPeriodField(root, api);
1280
+ periodUis.set(root, period);
1281
+ return () => {
1282
+ periodUis.delete(root);
1283
+ period.dispose();
1284
+ };
1285
+ }
883
1286
  const ui = buildDateField(root, {
884
1287
  read: () => stateOfProps(api.props()),
885
1288
  commit: (value) => api.emit('change', { value }),
@@ -891,11 +1294,13 @@ export function createDate(): SomaComponentDefinition {
891
1294
  ui.dispose();
892
1295
  };
893
1296
  },
894
- render(root, p) {
1297
+ render(root, p, api) {
895
1298
  root.className = joinClass(ROOT_CLASS, p.class);
896
- uis.get(root)?.paint();
1299
+ // 只读形态是数据状态,自报到组件根上(主题据此给只读外观;交互仍由 readOnly / aria 原生表达)
1300
+ kitMarkDataState(kitOuterRoot(api.host, root), bool(p.readonly) ? 'readonly' : 'normal');
1301
+ (periodUis.get(root) ?? uis.get(root))?.paint();
897
1302
  },
898
- })),
1303
+ }), { self: { level: 'control' } }),
899
1304
  };
900
1305
  }
901
1306
 
@@ -953,6 +1358,8 @@ export interface KitDateField {
953
1358
  export function mountKitDateField(opts: KitDateFieldOptions = {}): KitDateField {
954
1359
  const root = document.createElement('div');
955
1360
  root.className = ROOT_CLASS;
1361
+ // 命令式调用方不经 createKitController 骨架,这里自己自报层级角色
1362
+ kitReportSelf(root, { level: 'control' });
956
1363
  const st: FieldState = {
957
1364
  value: opts.value ?? '',
958
1365
  min: opts.min ?? '',