soma-kit 0.1.14 → 0.1.16

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