soma-kit 0.1.15 → 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 (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 +934 -92
  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 +186 -57
  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 +130 -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 +1015 -53
  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 +424 -103
  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/data/chart.ts CHANGED
@@ -10,7 +10,10 @@
10
10
  // 没装配图表引擎、没数据、配置非法、引擎加载失败,都显示降级空态,不抛。
11
11
  // 颜色只取 `--soma-*` 令牌(读运行期计算值交给引擎主题,源码里不写裸色值);样式类只用语义色名与 utilityScales 内的尺度。
12
12
 
13
+ import { kitApplyLevelClass } from './level-class';
14
+ import { kitLevelClassFor } from '../recipes/pipeline-runtime';
13
15
  import type { SomaComponentDefinition } from 'soma-core';
16
+ import { kitMarkDataFacts, kitMarkLevel } from './kit-contract';
14
17
  import { createKitController, joinClass, num, str } from '../base/shared';
15
18
  import { createLoadingGate, type KitLoadingGate } from '../base/loading-gate';
16
19
  import { kitText, type KitTextKey } from '../i18n/kit-text';
@@ -25,10 +28,21 @@ import {
25
28
  } from 'soma-foundation/kit-viz';
26
29
  import { classCandidates } from '../shared/class-candidates';
27
30
  import { mergeClass } from '../shared/merge-class';
31
+ import { isDarkColorScheme, unwrapLightDark } from '../shared/color-scheme';
32
+ import { KIT_THEME_APPLIED_EVENT } from '../shared/theme-runtime-shared';
28
33
  import { kitShellRecipe } from '../recipes/container';
34
+ import { kitDividerRecipe } from '../recipes/divider';
35
+ import { kitApplyChartTones, kitClearChartTones } from '../recipes/self-owned';
29
36
  import { kitFocusRingRecipe } from '../recipes/state';
37
+ import { kitSurfaceRecipe } from '../recipes/surface';
38
+ import { kitTypographyRecipe } from '../recipes/typography';
39
+ import { KIT_SKELETON_BAR_LAST_TEXT, KIT_SKELETON_BAR_LINE } from '../recipes/placeholder';
40
+ import { cleanSummaryFloat, SERIES_BG, TONE_BG } from './summary-util';
30
41
  import { KIT_NOTICE_HEADLINE, KIT_STAT_VALUES_NUM, KIT_STAT_VALUES_ROW } from '../recipes/status';
31
42
  import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
43
+ import {
44
+ KIT_ATTR_CHART_INDEX, KIT_ATTR_CHART_READOUT, KIT_ATTR_CHART_READY, KIT_ATTR_CHART_SERIES, KIT_ATTR_CHART_TIP, KIT_ATTR_STATE, KIT_ATTR_TIP_ALIGN,
45
+ } from '../shared/dom-attrs';
32
46
 
33
47
  // 参考线 / 图例 / 数值格式的闭集与限值只读 kit-grammar.json#dataLimits.chart,代码里不手抄
34
48
  const CHART_LIMITS = (grammarJson as unknown as { dataLimits: { chart: {
@@ -86,28 +100,58 @@ const ROLE_TYPES: ReadonlySet<string> = new Set(['line', 'area', 'bar', 'combo']
86
100
 
87
101
  const ROOT_CLASS = 'relative w-full';
88
102
  /** 图已就绪的根标记:引擎加载完并出过图后才有(截图 / 渲染测量据此判断,不靠固定等待) */
89
- export const KIT_CHART_READY_ATTR = 'data-kit-chart-ready';
103
+ export const KIT_CHART_READY_ATTR = KIT_ATTR_CHART_READY;
90
104
  const STAGE_CLASS = 'h-72 w-full';
91
105
  // 空态框 = 凹槽面的壳配方(容器边,KT-B2)
92
- const EMPTY_INNER_CLASS = mergeClass('flex h-72 w-full items-center justify-center text-sm text-fg-muted', kitShellRecipe({ tone: 'sunken', shadow: false }));
106
+ const EMPTY_INNER_CLASS = mergeClass(mergeClass('flex h-72 w-full items-center justify-center', kitTypographyRecipe('textMuted')), kitShellRecipe({ tone: 'sunken', shadow: false }));
93
107
 
94
108
  /**
95
109
  * 逐列读数区的类:排版与表面取 kit 配方(说明条标题 / StatGroup 多值行的字阶与等宽数字),不手写字阶;
96
- * 容器是下沉面(bg-surface-sunken + rounded-md,与空态同一表面),键盘焦点环取条目焦点环配方。
110
+ * 容器是下沉面(井色 + rounded-card,与空态同一表面),键盘焦点环取条目焦点环配方。
97
111
  */
98
- const READOUT_CLASS = `rounded-md bg-surface-sunken px-3 py-2 ${KIT_STAT_VALUES_ROW}`;
112
+ // 逐列读数区是说明块 = 子块出口(层级策略 sub,2026-11-25 第 4 关;不再取凹槽色)
113
+ const READOUT_CLASS = `sub-block px-3 py-2 ${KIT_STAT_VALUES_ROW}`;
99
114
  const READOUT_TITLE_CLASS = KIT_NOTICE_HEADLINE;
100
115
  const READOUT_ITEM_CLASS = 'inline-flex items-baseline gap-1.5';
101
116
  const READOUT_VALUE_CLASS = KIT_STAT_VALUES_NUM;
102
117
  const READOUT_NOTE_CLASS = 'text-fg-subtle';
103
- const ROOT_FOCUS_CLASS = mergeClass('rounded-md', kitFocusRingRecipe('item'));
118
+ const ROOT_FOCUS_CLASS = mergeClass('rounded-card', kitFocusRingRecipe('item'));
104
119
  const READOUT_TOP_CLASS = 'mb-2';
105
120
  const READOUT_BOTTOM_CLASS = 'mt-2';
106
121
 
122
+ /**
123
+ * 悬停数据卡(组件卡 ChartCommon §6:浅色数据卡,浮起面 + 发丝边 + 影,跟随指针):标题 + 逐系列「色块 名称 数值」,数值等宽右对齐。
124
+ * 只给指针用(aria-hidden,pointer-events-none);键盘与读屏走逐列读数区与读屏数据表。
125
+ */
126
+ const TIP_CLASS = mergeClass('pointer-events-none absolute z-10 flex flex-col gap-1.5 px-3 py-2 text-xs', kitSurfaceRecipe('raised'));
127
+ const TIP_FLIP_X_CLASS = '-translate-x-full';
128
+ const TIP_FLIP_Y_CLASS = '-translate-y-full';
129
+ const TIP_ROW_CLASS = 'flex items-center gap-2';
130
+ const TIP_DOT_CLASS = 'size-2 shrink-0 rounded-full';
131
+ const TIP_NAME_CLASS = 'text-fg-muted';
132
+ const TIP_VALUE_CLASS = mergeClass('ms-auto ps-4 text-end', KIT_STAT_VALUES_NUM);
133
+ /** 悬停数据卡距指针的间距(像素,跟随定位用;取 legendGap 同一档) */
134
+ const TIP_OFFSET_PX = CHART_STYLE.legendGap;
135
+ /** 非直角坐标 SVG 图元委托提示序号属性(供指针悬停扇区/散点/漏斗层/雷达/热力格精准读数) */
136
+ export const KIT_CHART_ITEM_ATTR = KIT_ATTR_CHART_INDEX;
137
+
138
+ /**
139
+ * 空 / 加载态保留的空坐标网格(只有横向网格线,组件卡 ChartCommon §4 / §7):图区尺寸与真图一致,文字 / 骨架条叠在网格上。
140
+ * 线数取 gridMaxLines(与真图同一上限)。
141
+ */
142
+ const GRID_PLACE_CLASS = 'absolute inset-0 flex flex-col justify-between py-3';
143
+ const GRID_LINE_CLASS = kitDividerRecipe('top');
144
+ const GRID_OVER_CLASS = mergeClass('relative flex h-72 w-full flex-col items-center justify-center gap-3', kitTypographyRecipe('textMuted'));
145
+ const GRID_SKELETON_CLASS = 'flex w-1/2 flex-col gap-3';
146
+ /** 有直角坐标网格的图型(空 / 加载时保留网格;饼 / 仪表盘等没有网格,仍用整块面板) */
147
+ const GRID_TYPES: ReadonlySet<string> = new Set(['line', 'bar', 'area', 'combo', 'scatter', 'candlestick', 'boxplot', 'bullet']);
148
+
107
149
  /** 本组件自带的全部类(供编译器并入候选类) */
108
150
  export const KIT_CHART_CLASS_CANDIDATES: readonly string[] = classCandidates(
109
- ['relative', 'absolute', 'inset-0', 'invisible', 'w-full', 'h-72', 'hidden', 'sr-only',
110
- EMPTY_INNER_CLASS],
151
+ ['relative', 'absolute', 'inset-0', 'invisible', 'w-full', 'h-72', 'size-full', 'hidden', 'sr-only',
152
+ EMPTY_INNER_CLASS, TIP_CLASS, TIP_FLIP_X_CLASS, TIP_FLIP_Y_CLASS, TIP_ROW_CLASS, TIP_DOT_CLASS, TIP_NAME_CLASS, TIP_VALUE_CLASS,
153
+ GRID_PLACE_CLASS, GRID_LINE_CLASS, GRID_OVER_CLASS, GRID_SKELETON_CLASS, KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_LAST_TEXT,
154
+ ...SERIES_BG, ...Object.values(TONE_BG)],
111
155
  KIT_STATE_PANEL_CLASS_CANDIDATES,
112
156
  READOUT_CLASS, READOUT_TITLE_CLASS, READOUT_ITEM_CLASS, READOUT_VALUE_CLASS, READOUT_NOTE_CLASS, ROOT_FOCUS_CLASS,
113
157
  READOUT_TOP_CLASS, READOUT_BOTTOM_CLASS,
@@ -117,10 +161,12 @@ export const KIT_CHART_CLASS_CANDIDATES: readonly string[] = classCandidates(
117
161
 
118
162
  export type KitChartType =
119
163
  | 'line' | 'bar' | 'area' | 'pie' | 'donut' | 'funnel' | 'gauge'
120
- | 'scatter' | 'combo' | 'radar' | 'heatmap' | 'boxplot' | 'candlestick' | 'sankey' | 'treemap' | 'sunburst' | 'chord';
164
+ | 'scatter' | 'combo' | 'radar' | 'heatmap' | 'boxplot' | 'candlestick' | 'sankey' | 'treemap' | 'sunburst' | 'chord'
165
+ | 'rose' | 'network' | 'bullet';
121
166
  export const KIT_CHART_TYPES: readonly KitChartType[] = Object.freeze([
122
167
  'line', 'bar', 'area', 'pie', 'donut', 'funnel', 'gauge',
123
168
  'scatter', 'combo', 'radar', 'heatmap', 'boxplot', 'candlestick', 'sankey', 'treemap', 'sunburst', 'chord',
169
+ 'rose', 'network', 'bullet',
124
170
  ]);
125
171
 
126
172
  export interface KitChartConfig {
@@ -152,10 +198,14 @@ export interface KitChartConfig {
152
198
  readout?: ReadoutConfig;
153
199
  /** 点击 / Enter 选中列抛 point_pick(K3) */
154
200
  interact?: { pick: boolean };
201
+ /** 涨跌色反转开关(K 线):缺省 good = 涨为成功色、跌为危险色;bad = 涨为危险色、跌为成功色(红涨绿跌习惯 / 成本类指标) */
202
+ upIs?: 'good' | 'bad';
155
203
  /** 图例位置:auto = 多系列时在底部(饼 / 漏斗始终在底部),none 关闭 */
156
204
  legend?: 'auto' | 'top' | 'bottom' | 'none';
157
205
  /** 纵轴 / 标签的数值前后缀(引擎字符串模板,不含函数) */
158
206
  valueFormat?: { prefix: string; suffix: string };
207
+ /** heatmap 色阶模式:sequential(顺序 10 阶)| diverging(发散 17 阶);未指定时按数据是否同时含正负自动判定 */
208
+ scale?: 'sequential' | 'diverging';
159
209
  }
160
210
 
161
211
  export interface KitChartRefLine {
@@ -167,12 +217,13 @@ export interface KitChartRefLine {
167
217
 
168
218
  /** 引擎端口里的系列类型:area 走 line,donut 走 pie;combo 同时要柱和线两种 */
169
219
  export function engineSeriesOf(type: KitChartType): string {
170
- return type === 'area' ? 'line' : type === 'donut' ? 'pie' : type === 'combo' ? 'bar' : type;
220
+ return type === 'area' ? 'line' : type === 'donut' || type === 'rose' ? 'pie' : type === 'combo' || type === 'bullet' ? 'bar' : type === 'network' ? 'graph' : type;
171
221
  }
172
222
 
173
223
  /** 一张图要装的全部引擎系列类型(combo = bar + line;bar 等直角图含 baseline / ideal / projection / line 系列时补齐 line) */
174
224
  export function engineSeriesListOf(type: KitChartType, config?: Pick<KitChartConfig, 'roles' | 'line'>): string[] {
175
- const out = type === 'combo' ? ['bar', 'line'] : [engineSeriesOf(type)];
225
+ // bullet = 横条(实际值)+ 方块散点(目标刻度)
226
+ const out = type === 'combo' ? ['bar', 'line'] : type === 'bullet' ? ['bar', 'scatter'] : [engineSeriesOf(type)];
176
227
  const needsLine = (config?.line?.length ?? 0) > 0
177
228
  || Object.values(config?.roles ?? {}).some((r) => r === 'ideal' || r === 'baseline' || r === 'projection');
178
229
  if (needsLine && !out.includes('line')) out.push('line');
@@ -203,13 +254,14 @@ function appendRoleSuffix(name: string, suffix: string): string {
203
254
  }
204
255
 
205
256
  /** 数据要求:除 x / y 外还必须给的字段,以及 y 最少几个字段(纯函数,chartConfigOf 用) */
206
- const MIN_Y: Readonly<Partial<Record<KitChartType, number>>> = Object.freeze({ boxplot: 5, candlestick: 4 });
257
+ const MIN_Y: Readonly<Partial<Record<KitChartType, number>>> = Object.freeze({ boxplot: 5, candlestick: 4, bullet: 2 });
207
258
  const NEEDS_VALUE: ReadonlySet<KitChartType> = new Set<KitChartType>(['heatmap', 'sankey', 'chord']);
208
259
 
209
260
  /** 各类型需要的引擎组件:直角坐标系要 grid + legend;pie / donut / funnel 只要 legend;gauge 都不要 */
210
261
  export function engineComponentsOf(type: KitChartType, withMarkLine = false, extra: readonly string[] = []): string[] {
211
- if (type === 'gauge' || type === 'sankey' || type === 'treemap' || type === 'sunburst' || type === 'chord') return [];
212
- if (type === 'pie' || type === 'donut' || type === 'funnel') return ['legend'];
262
+ if (type === 'gauge' || type === 'sankey' || type === 'treemap' || type === 'sunburst' || type === 'chord' || type === 'network') return [];
263
+ if (type === 'pie' || type === 'donut' || type === 'rose' || type === 'funnel') return ['legend'];
264
+ if (type === 'bullet') return ['grid'];
213
265
  if (type === 'radar') return ['radar', 'legend'];
214
266
  if (type === 'heatmap') return ['grid', 'visualMap'];
215
267
  if (type === 'boxplot' || type === 'candlestick') return ['grid'];
@@ -330,6 +382,8 @@ export function chartConfigOf(chartRaw: unknown): KitChartConfig | null {
330
382
  const vf = recOf(src.value_format);
331
383
  const prefix = affixOf(vf.prefix);
332
384
  const suffix = affixOf(vf.suffix);
385
+ const rawScale = str(src.scale || src.mode);
386
+ const scale = type === 'heatmap' && (rawScale === 'sequential' || rawScale === 'diverging') ? rawScale : undefined;
333
387
  return {
334
388
  ...(lineFields.length > 0 ? { line: lineFields } : {}),
335
389
  ...(y2Fields.length > 0 ? { y2: y2Fields } : {}),
@@ -339,7 +393,9 @@ export function chartConfigOf(chartRaw: unknown): KitChartConfig | null {
339
393
  ...(readout !== undefined ? { readout } : {}),
340
394
  ...(interactRaw !== undefined && interactRaw !== null ? { interact: { pick: interactRec.pick === true || interactRec.pick === 'true' } } : {}),
341
395
  ...(legend !== 'auto' ? { legend } : {}),
396
+ ...(str(src.up_is) === 'bad' ? { upIs: 'bad' as const } : {}),
342
397
  ...(prefix !== '' || suffix !== '' ? { valueFormat: { prefix, suffix } } : {}),
398
+ ...(scale !== undefined ? { scale } : {}),
343
399
  type, x, y, stack, min, max, warnAt: num(src.warnAt), dangerAt: num(src.dangerAt),
344
400
  ...(value !== '' ? { value } : {}),
345
401
  ...(str(src.parent) !== '' ? { parent: str(src.parent) } : {}),
@@ -398,20 +454,82 @@ export function chartHierarchy(
398
454
  export interface KitChartTheme {
399
455
  /** 系列色(解析后的运行期颜色值,取自 --soma-c-*) */
400
456
  palette: string[];
457
+ /** 数据文字(标签、仪表读数、矩形树名):--soma-text-secondary */
401
458
  text: string;
402
- line: string;
459
+ /** 网格线(数值轴横线、雷达 / 仪表网格、热力色阶起点):--soma-chart-grid,十六进制实色 */
460
+ grid: string;
461
+ /** 类目轴基线:--soma-chart-axis,十六进制实色 */
462
+ axis: string;
463
+ /** 刻度字 / 图例字 / 轴名(弱化墨 --soma-text-muted);缺省退回 text */
464
+ tick?: string;
465
+ /** 刻度字号(px,读 --soma-font-size-xs 的计算值 = 字阶最小档);读不到不设,用引擎默认 */
466
+ tickPx?: number;
403
467
  /** 理想线色(中性令牌 --soma-text-muted 的运行期值);缺省退回 text */
404
468
  ideal?: string;
405
469
  /** 主色(标记 primary 语气、焦点带;--soma-c-primary 的运行期值);缺省退回 palette[0] */
406
470
  primary?: string;
407
471
  /** 预测线系列名后缀(如「(预测)」,来自 kit 文案);缺省不加 */
408
472
  projectionSuffix?: string;
473
+ /** gauge 底轨色(图表未填充底弧 --soma-chart-idle 的运行期值);缺省退回 grid */
474
+ track?: string;
409
475
  /** gauge 阈值着色:正常 / 警告 / 危险(取自 --soma-c-success / warning / danger);缺省退回系列色 */
410
476
  ok?: string;
411
477
  warn?: string;
412
478
  danger?: string;
413
479
  /** 柱宽 / 类间距的比例(百分数,取 --soma-chart-bar-ratio;强调级越低越细);缺省用引擎默认 */
414
480
  barRatioPct?: number;
481
+ /** 热力顺序色阶(--soma-chart-seq-1..10);缺省回落 [grid, palette[0]] */
482
+ seqRamp?: string[];
483
+ /** 热力发散色阶(--soma-chart-div-1..17);缺省回落 [grid, palette[0]] */
484
+ divRamp?: string[];
485
+ }
486
+
487
+ /** 十进制好数列 1-2-5(刻度步长的尾数,与引擎 / d3 nice 刻度同一序列;算法常量,不是视觉取值) */
488
+ const NICE_MANTISSAS: readonly number[] = [1, 2, 5, 10];
489
+
490
+ /**
491
+ * 数值轴步长:含 0 的数据跨度分成至多 maxLines − 1 段、步长取好数(纯函数)。堆叠序列按同一下标求和;没有数值或跨度为 0 返回 undefined(交给引擎)。
492
+ */
493
+ export function gridIntervalOf(series: ReadonlyArray<Record<string, unknown>>, maxLines: number): number | undefined {
494
+ return gridAxisOf(series, maxLines)?.interval;
495
+ }
496
+
497
+ /**
498
+ * 数值轴的步长与上下界(纯函数):界对齐到步长整数倍。只给步长时引擎仍按自己的好数取上界(实拍:数据最大 32、步长 10 时顶上多出一条 35),
499
+ * 所以上下界一起给,横线 = 跨度 / 步长 + 1 ≤ maxLines。
500
+ */
501
+ export function gridAxisOf(series: ReadonlyArray<Record<string, unknown>>, maxLines: number): { interval: number; min: number; max: number } | undefined {
502
+ const vals: number[] = [0];
503
+ const stacks = new Map<string, number[]>();
504
+ for (const s of series) {
505
+ const data = Array.isArray(s.data) ? s.data : [];
506
+ const nums = data.map((d) => (typeof d === 'number' && Number.isFinite(d) ? d : null));
507
+ if (typeof s.stack === 'string') {
508
+ const acc = stacks.get(s.stack) ?? [];
509
+ nums.forEach((v, i) => { acc[i] = (acc[i] ?? 0) + (v ?? 0); });
510
+ stacks.set(s.stack, acc);
511
+ } else {
512
+ for (const v of nums) if (v !== null) vals.push(v);
513
+ }
514
+ }
515
+ for (const acc of stacks.values()) vals.push(...acc.filter((v) => Number.isFinite(v)));
516
+ const lo = Math.min(...vals);
517
+ const hi = Math.max(...vals);
518
+ const span = hi - lo;
519
+ if (!(span > 0) || maxLines < 2) return undefined;
520
+ // 步长从好数里取最小的那个,使对齐后的格数 ≤ maxLines − 1(先按跨度估,再按对齐后的格数逐级放大)
521
+ const raw = span / (maxLines - 1);
522
+ let pow = 10 ** Math.floor(Math.log10(raw));
523
+ for (let guard = 0; guard < 4; guard += 1) {
524
+ for (const k of NICE_MANTISSAS) {
525
+ const interval = k * pow;
526
+ const min = Math.floor(lo / interval) * interval;
527
+ const max = Math.ceil(hi / interval) * interval;
528
+ if (Math.round((max - min) / interval) <= maxLines - 1) return { interval, min, max };
529
+ }
530
+ pow *= 10;
531
+ }
532
+ return undefined;
415
533
  }
416
534
 
417
535
  /** 把 #rrggbb 色按 pct% 混入面板面色(pct = 系列色占比);无法解析(非 #rrggbb)时原样返回。强调级低的图表填充更浅,主图表 100 = 实心。 */
@@ -448,11 +566,61 @@ export function gaugeBands(config: KitChartConfig, theme: KitChartTheme): Array<
448
566
  return bands.sort((a, b) => a[0] - b[0]);
449
567
  }
450
568
 
569
+ /** gauge 进度弧的颜色:值落在哪一段就取哪一段的阈值色(底轨不带阈值色);纯函数 */
570
+ export function gaugeValueColor(config: KitChartConfig, theme: KitChartTheme, value: number | null): string {
571
+ const min = config.min ?? 0;
572
+ const span = (config.max ?? 100) - min;
573
+ const ratio = value === null || span <= 0 ? 0 : Math.min(1, Math.max(0, (value - min) / span));
574
+ const bands = gaugeBands(config, theme);
575
+ return (bands.find(([upTo]) => ratio < upTo) ?? bands[bands.length - 1])?.[1] ?? theme.palette[0] ?? '';
576
+ }
577
+
451
578
  /**
452
579
  * 生成引擎 option(纯函数)。键名对照 map 只对数据键生效:配置里的 x / y 先经 map 取源键。
453
580
  * option 不含 tooltip(端口禁止)。
454
581
  */
582
+ /**
583
+ * 引擎 option 生成(含共用缺省):各图型选项由 buildChartOptionCore 产出,这里统一补:
584
+ * 动画(入场 600 / 更新 300 / cubicInOut / 超 2000 点关动画)、悬停高亮(聚焦本系列、其余降到 0.3)、柱顶圆角 4 与最小柱高 2。
585
+ * 取值同 05-图表与统计 的「共用」键(ECharts globalDefault / shadcn chart / Tremor),数字在 design kit-limits#dataLimits.chart.style。
586
+ */
455
587
  export function buildChartOption(
588
+ config: KitChartConfig,
589
+ rows: ReadonlyArray<Record<string, unknown>>,
590
+ theme: KitChartTheme,
591
+ mapRaw?: unknown,
592
+ view: { focus?: number } = {},
593
+ ): Record<string, unknown> {
594
+ const core = buildChartOptionCore(config, rows, theme, mapRaw, view);
595
+ const blur = CHART_STYLE.blurOpacity;
596
+ const series = Array.isArray(core.series) ? core.series.map((s: unknown) => {
597
+ if (s === null || typeof s !== 'object') return s;
598
+ const item = s as Record<string, unknown>;
599
+ const type = item.type;
600
+ if (type === 'line' || type === 'bar' || type === 'scatter' || type === 'radar') {
601
+ const stacked = item.stack !== undefined;
602
+ const round = type === 'bar' && !stacked && config.type !== 'bullet';
603
+ const itemStyle = item.itemStyle as Record<string, unknown> | undefined;
604
+ return {
605
+ ...item,
606
+ emphasis: { focus: 'series', ...(item.emphasis as Record<string, unknown> | undefined) },
607
+ blur: item.blur ?? { itemStyle: { opacity: blur }, lineStyle: { opacity: blur }, areaStyle: { opacity: blur } },
608
+ ...(round ? { barMinHeight: item.barMinHeight ?? CHART_STYLE.barMinHeight, itemStyle: { borderRadius: [CHART_STYLE.barRadius, CHART_STYLE.barRadius, 0, 0], ...itemStyle } } : {}),
609
+ };
610
+ }
611
+ return s;
612
+ }) : core.series;
613
+ return {
614
+ animationDuration: CHART_STYLE.animationMs,
615
+ animationDurationUpdate: CHART_STYLE.animationUpdateMs,
616
+ animationEasing: 'cubicInOut',
617
+ animationThreshold: CHART_STYLE.animationThreshold,
618
+ ...core,
619
+ ...(series !== undefined ? { series } : {}),
620
+ };
621
+ }
622
+
623
+ function buildChartOptionCore(
456
624
  config: KitChartConfig,
457
625
  rows: ReadonlyArray<Record<string, unknown>>,
458
626
  theme: KitChartTheme,
@@ -468,11 +636,36 @@ export function buildChartOption(
468
636
 
469
637
  // 图例位置与数值前后缀:legend 缺省按各图型原习惯(auto),value_format 只拼引擎字符串模板
470
638
  const fmt = config.valueFormat;
639
+ // 单位只写一次:数值轴刻度只写数,前后缀进数值轴的轴名(axisUnitName);数据标签 / 仪表读数仍带单位(valueTemplate / labelTemplate)
471
640
  const valueTemplate = fmt ? `${fmt.prefix}{value}${fmt.suffix}` : undefined;
472
641
  const labelTemplate = fmt ? `{b}: ${fmt.prefix}{c}${fmt.suffix}` : undefined;
642
+ const axisUnitName = fmt ? `${fmt.prefix}${fmt.suffix}`.trim() : '';
643
+ const tick = theme.tick ?? theme.text;
644
+ const tickText = { color: tick, ...(theme.tickPx !== undefined ? { fontSize: theme.tickPx } : {}) };
473
645
  const legendShown = (auto: boolean): boolean => (config.legend === 'none' ? false : config.legend === 'top' || config.legend === 'bottom' ? true : auto);
474
646
  const legendOf = (auto: boolean): Record<string, unknown> | undefined =>
475
- (legendShown(auto) ? { ...(config.legend === 'top' ? { top: 0 } : { bottom: 0 }), textStyle: { color: theme.text } } : undefined);
647
+ // 图例标记 8×8 圆角 2、项间距 16(共用取值:shadcn chart legend / ECharts legend)
648
+ (legendShown(auto) ? {
649
+ ...(config.legend === 'top' ? { top: 0 } : { bottom: 0 }), textStyle: tickText,
650
+ icon: 'roundRect', itemWidth: CHART_STYLE.legendMarkPx, itemHeight: CHART_STYLE.legendMarkPx, itemGap: CHART_STYLE.legendGap,
651
+ } : undefined);
652
+ // 直角坐标轴样式(落地工单第一批 §2):数值轴无轴线、无刻度线,只有 ≤ gridMaxLines 条横向网格(grid 色 1px);
653
+ // 类目轴一条基线(axis 色)、无刻度线、无竖网格;刻度字 = 弱化墨、字阶最小档、等宽数字,离轴 axisLabelGapPx
654
+ const tickLabel = { ...tickText, margin: CHART_STYLE.axisLabelGapPx, fontVariantNumeric: 'tabular-nums' };
655
+ const valueAxisStyle = (withUnit: boolean): Record<string, unknown> => ({
656
+ axisLine: { show: false },
657
+ axisTick: { show: false },
658
+ splitNumber: CHART_STYLE.gridMaxLines - 1,
659
+ splitLine: { lineStyle: { color: theme.grid, width: CHART_STYLE.gridLineWidth } },
660
+ axisLabel: tickLabel,
661
+ ...(withUnit && axisUnitName !== '' ? { name: axisUnitName, nameLocation: 'end', nameTextStyle: { ...tickText, align: 'left' } } : {}),
662
+ });
663
+ const categoryAxisStyle = {
664
+ axisLine: { lineStyle: { color: theme.axis, width: CHART_STYLE.gridLineWidth } },
665
+ axisTick: { show: false },
666
+ splitLine: { show: false },
667
+ axisLabel: tickLabel,
668
+ };
476
669
  const toneColor = (tone: KitChartRefLine['tone'] | VizTone): string =>
477
670
  (tone === 'success' ? (theme.ok ?? theme.palette[0] ?? theme.text)
478
671
  : tone === 'warning' ? (theme.warn ?? theme.palette[1] ?? theme.text)
@@ -659,7 +852,7 @@ export function buildChartOption(
659
852
  ];
660
853
  const rightLabelPad = rightMarkLabels.length > 0
661
854
  ? Math.min(136, Math.max(48, Math.max(...rightMarkLabels.map(estimateLabelPx)) + 20))
662
- : 8;
855
+ : 24;
663
856
  const gridFor = (multi: boolean): Record<string, unknown> => ({
664
857
  left: 8, right: rightLabelPad, containLabel: true,
665
858
  top: legendShown(multi) && config.legend === 'top' ? 40 : 24,
@@ -676,12 +869,16 @@ export function buildChartOption(
676
869
  type: 'gauge',
677
870
  min: config.min ?? 0,
678
871
  max: config.max ?? 100,
679
- axisLine: { lineStyle: { width: CHART_STYLE.gaugeWidth, color: gaugeBands(config, theme) } },
680
- axisLabel: { color: theme.text },
681
- axisTick: { lineStyle: { color: theme.line } },
682
- splitLine: { lineStyle: { color: theme.line } },
683
- pointer: { width: CHART_STYLE.pointerWidth },
684
- title: { color: theme.text },
872
+ // 组件卡 ChartCommon §6:轨宽 10、圆端、刻度与分割线默认隐藏(ECharts 默认带分割线与刻度,kit 取进度环形简化版)
873
+ // 底轨 = 凹陷面角色的整圈;进度 = 圆端弧,阈值只改进度色;不画指针与锚点(组件卡 ChartCommon §6 仪表盘)
874
+ axisLine: { roundCap: true, lineStyle: { width: CHART_STYLE.gaugeWidth, color: [[1, theme.track ?? theme.grid]] } },
875
+ progress: { show: true, roundCap: true, width: CHART_STYLE.gaugeWidth, itemStyle: { color: gaugeValueColor(config, theme, value) } },
876
+ axisLabel: { show: false },
877
+ axisTick: { show: false },
878
+ splitLine: { show: false },
879
+ pointer: { show: false },
880
+ anchor: { show: false },
881
+ title: { color: theme.text, offsetCenter: ['0%', '40%'] },
685
882
  detail: { color: theme.text, valueAnimation: false, ...(valueTemplate !== undefined ? { formatter: valueTemplate } : {}) },
686
883
  data: [{ name: label(first[xKey]), value }],
687
884
  }],
@@ -700,13 +897,65 @@ export function buildChartOption(
700
897
  sort: 'none',
701
898
  left: '10%',
702
899
  width: '80%',
900
+ // 取值:片间 2px 缝、最小片 10%、标签外置带 20px 引线(共用取值 05 漏斗图:ECharts funnel 默认 / G2 Funnel)
901
+ gap: CHART_STYLE.funnelGap,
902
+ minSize: `${CHART_STYLE.funnelMinSizePct}%`,
903
+ labelLine: { show: true, length: CHART_STYLE.funnelLabelLineLength, lineStyle: { color: theme.grid, width: CHART_STYLE.gridLineWidth } },
703
904
  data: rows.map((r) => ({ name: label(r[xKey]), value: numeric(r[yKey]) })),
704
905
  label: { color: theme.text, ...(labelTemplate !== undefined ? { formatter: labelTemplate } : {}) },
705
906
  }],
706
907
  };
707
908
  }
708
909
 
709
- if (config.type === 'pie' || config.type === 'donut') {
910
+ if (config.type === 'bullet') {
911
+ // 子弹图:x = 名称,y[0] = 实际值(窄横条),y[1] = 目标值(竖向方块刻度);横向条、名称在纵轴、自上而下
912
+ const names = rows.map((r) => label(r[xKey]));
913
+ const actualKey = src(config.y[0]!);
914
+ const targetKey = src(config.y[1]!);
915
+ const [markW, markH] = CHART_STYLE.bulletTargetSize;
916
+ return {
917
+ color: theme.palette,
918
+ textStyle: { color: theme.text },
919
+ grid: gridFor(false),
920
+ xAxis: { type: 'value', ...valueAxisStyle(false) },
921
+ yAxis: { type: 'category', data: names, inverse: true, ...categoryAxisStyle },
922
+ series: [
923
+ { type: 'bar', name: config.y[0]!, barWidth: `${CHART_STYLE.bulletBarPct}%`, data: rows.map((r) => numeric(r[actualKey])) },
924
+ {
925
+ type: 'scatter', name: config.y[1]!, symbol: 'rect', symbolSize: [markW, markH], z: 3,
926
+ itemStyle: { color: theme.text },
927
+ data: rows.map((r, i) => [numeric(r[targetKey]), i]),
928
+ },
929
+ ],
930
+ };
931
+ }
932
+
933
+ if (config.type === 'network') {
934
+ // 关系网络:每行一条边,x = 起点,y[0] = 终点,value 字段(可选)= 边权;节点由边两端去重,力导向布局
935
+ const weightKey = src(config.value ?? '');
936
+ const edges = rows
937
+ .map((r) => ({ source: label(r[xKey]), target: label(r[src(config.y[0]!)]), value: weightKey === '' ? 1 : numeric(r[weightKey]) }))
938
+ .filter((l) => l.source !== '' && l.target !== '' && l.source !== l.target);
939
+ const names: string[] = [];
940
+ for (const l of edges) for (const n of [l.source, l.target]) if (!names.includes(n)) names.push(n);
941
+ return {
942
+ color: theme.palette,
943
+ textStyle: { color: theme.text },
944
+ series: [{
945
+ type: 'graph',
946
+ layout: 'force',
947
+ roam: false,
948
+ symbolSize: CHART_STYLE.networkNodeSize,
949
+ force: { repulsion: CHART_STYLE.networkRepulsion },
950
+ data: names.map((name) => ({ name })),
951
+ links: edges,
952
+ label: { show: true, position: 'right', color: theme.text },
953
+ lineStyle: { color: theme.grid, width: CHART_STYLE.lineWidth, curveness: 0 },
954
+ }],
955
+ };
956
+ }
957
+
958
+ if (config.type === 'pie' || config.type === 'donut' || config.type === 'rose') {
710
959
  const yKey = src(config.y[0]!);
711
960
  return {
712
961
  color: theme.palette,
@@ -714,7 +963,9 @@ export function buildChartOption(
714
963
  legend: legendOf(true),
715
964
  series: [{
716
965
  type: 'pie',
717
- radius: config.type === 'donut' ? ['40%', '65%'] : '60%',
966
+ // rose = 南丁格尔玫瑰(半径编码数值,内缘留小孔);donut = 环;pie = 实心
967
+ ...(config.type === 'rose' ? { roseType: 'radius' } : {}),
968
+ radius: config.type === 'rose' ? [`${CHART_STYLE.roseInnerPct}%`, `${CHART_STYLE.roseOuterPct}%`] : config.type === 'donut' ? ['40%', '65%'] : '60%',
718
969
  data: rows.map((r) => ({ name: label(r[xKey]), value: numeric(r[yKey]) })),
719
970
  label: { color: theme.text, ...(labelTemplate !== undefined ? { formatter: labelTemplate } : {}) },
720
971
  }],
@@ -723,11 +974,6 @@ export function buildChartOption(
723
974
 
724
975
  const yKeys = config.y.map(src);
725
976
  const valueKey = src(config.value ?? '');
726
- const axisStyle = {
727
- axisLine: { lineStyle: { color: theme.line } },
728
- axisLabel: { color: theme.text },
729
- splitLine: { lineStyle: { color: theme.line } },
730
- };
731
977
  const gridBox = { left: 8, right: 8, top: 24, bottom: 8, containLabel: true };
732
978
 
733
979
  if (config.type === 'scatter') {
@@ -736,8 +982,9 @@ export function buildChartOption(
736
982
  textStyle: { color: theme.text },
737
983
  grid: gridFor(config.y.length > 1),
738
984
  legend: legendOf(config.y.length > 1),
739
- xAxis: { type: 'value', ...axisStyle },
740
- yAxis: { type: 'value', ...axisStyle, axisLabel: { ...axisStyle.axisLabel, ...(valueTemplate !== undefined ? { formatter: valueTemplate } : {}) } },
985
+ // 散点两轴都是数值轴:横轴不带单位名(单位描述纵轴的数值)
986
+ xAxis: { type: 'value', ...valueAxisStyle(false) },
987
+ yAxis: { type: 'value', ...valueAxisStyle(true) },
741
988
  series: config.y.map((y, i) => ({
742
989
  type: 'scatter',
743
990
  name: y,
@@ -756,12 +1003,12 @@ export function buildChartOption(
756
1003
  return {
757
1004
  color: theme.palette,
758
1005
  textStyle: { color: theme.text },
759
- legend: config.y.length > 1 ? { bottom: 0, textStyle: { color: theme.text } } : undefined,
1006
+ legend: config.y.length > 1 ? { bottom: 0, textStyle: tickText } : undefined,
760
1007
  radar: {
761
1008
  indicator,
762
- axisName: { color: theme.text },
763
- axisLine: { lineStyle: { color: theme.line } },
764
- splitLine: { lineStyle: { color: theme.line } },
1009
+ axisName: tickText,
1010
+ axisLine: { lineStyle: { color: theme.grid } },
1011
+ splitLine: { lineStyle: { color: theme.grid } },
765
1012
  },
766
1013
  series: [{
767
1014
  type: 'radar',
@@ -782,11 +1029,16 @@ export function buildChartOption(
782
1029
  }
783
1030
  const cells = rows.map((r) => [xs.indexOf(label(r[xKey])), ys.indexOf(label(r[yKeys[0]!])), numeric(r[valueKey])]);
784
1031
  const values = cells.map((c) => c[2]!);
1032
+ const isDiverging = config.scale === 'diverging'
1033
+ || (config.scale !== 'sequential' && values.some((v) => v < 0) && values.some((v) => v > 0));
1034
+ const ramp = isDiverging
1035
+ ? (theme.divRamp && theme.divRamp.length > 0 ? theme.divRamp : undefined)
1036
+ : (theme.seqRamp && theme.seqRamp.length > 0 ? theme.seqRamp : undefined);
785
1037
  return {
786
1038
  textStyle: { color: theme.text },
787
1039
  grid: { left: 8, right: 8, top: 16, bottom: 48, containLabel: true },
788
- xAxis: { type: 'category', data: xs, splitArea: { show: false }, ...axisStyle },
789
- yAxis: { type: 'category', data: ys, ...axisStyle },
1040
+ xAxis: { type: 'category', data: xs, splitArea: { show: false }, ...categoryAxisStyle },
1041
+ yAxis: { type: 'category', data: ys, ...categoryAxisStyle },
790
1042
  visualMap: {
791
1043
  min: Math.min(...values, 0),
792
1044
  max: Math.max(...values, 1),
@@ -795,7 +1047,7 @@ export function buildChartOption(
795
1047
  left: 'center',
796
1048
  bottom: 0,
797
1049
  textStyle: { color: theme.text },
798
- inRange: { color: [theme.line, theme.palette[0] ?? theme.text] },
1050
+ inRange: { color: ramp ?? [theme.grid, theme.palette[0] ?? theme.text] },
799
1051
  },
800
1052
  series: [{ type: 'heatmap', data: cells }],
801
1053
  };
@@ -808,9 +1060,20 @@ export function buildChartOption(
808
1060
  color: theme.palette,
809
1061
  textStyle: { color: theme.text },
810
1062
  grid: gridBox,
811
- xAxis: { type: 'category', data: rows.map((r) => label(r[xKey])), ...axisStyle },
812
- yAxis: { type: 'value', scale: true, ...axisStyle },
813
- series: [{ type: config.type, data: rows.map((r) => yKeys.slice(0, width).map((k) => numeric(r[k]))) }],
1063
+ xAxis: { type: 'category', data: rows.map((r) => label(r[xKey])), ...categoryAxisStyle },
1064
+ yAxis: { type: 'value', scale: true, ...valueAxisStyle(true) },
1065
+ series: [{
1066
+ type: config.type,
1067
+ data: rows.map((r) => yKeys.slice(0, width).map((k) => numeric(r[k]))),
1068
+ // K 线涨跌色走语义令牌(不用引擎内置红绿);up_is: bad 反转
1069
+ ...(config.type === 'candlestick' ? (() => {
1070
+ const good = theme.ok ?? theme.palette[0] ?? theme.text;
1071
+ const bad = theme.danger ?? theme.palette[2] ?? theme.text;
1072
+ const rise = config.upIs === 'bad' ? bad : good;
1073
+ const fall = config.upIs === 'bad' ? good : bad;
1074
+ return { itemStyle: { color: rise, color0: fall, borderColor: rise, borderColor0: fall } };
1075
+ })() : {}),
1076
+ }],
814
1077
  };
815
1078
  }
816
1079
 
@@ -859,6 +1122,12 @@ export function buildChartOption(
859
1122
  const projectionName = (y: string): string => appendRoleSuffix(y, theme.projectionSuffix ?? '');
860
1123
  /** 空值(null / undefined / 非数)保持 null:引擎据此断线留白,不补零不插值 */
861
1124
  const cell = (r: Record<string, unknown>, key: string): number | null => num(r[key]);
1125
+ // 面积渐变:自系列色顶部 areaTopOpacity 渐到底部 areaBottomOpacity(共用取值 05:0.4 → 0);色非 #rrggbb 时退回平填 areaOpacity
1126
+ const areaGradient = (color: string): Record<string, unknown> => {
1127
+ if (!/^#[0-9a-f]{6}$/i.test(color)) return { opacity: CHART_STYLE.areaOpacity };
1128
+ const alpha = (a: number): string => `${color}${Math.round(a * 255).toString(16).padStart(2, '0')}`;
1129
+ return { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: alpha(CHART_STYLE.areaTopOpacity) }, { offset: 1, color: alpha(CHART_STYLE.areaBottomOpacity) }] } };
1130
+ };
862
1131
  const idealSeries = idealYs.map((y) => {
863
1132
  const key = src(y);
864
1133
  const color = theme.ideal ?? theme.text;
@@ -903,7 +1172,7 @@ export function buildChartOption(
903
1172
  ...(seriesType === 'line' ? { connectNulls: false } : {}),
904
1173
  ...(seriesType === 'bar' && theme.barRatioPct !== undefined ? { barCategoryGap: `${Math.max(0, 100 - theme.barRatioPct)}%` } : {}),
905
1174
  ...(seriesType === 'line' ? { lineStyle: { width: CHART_STYLE.lineWidth }, symbolSize: CHART_STYLE.symbolSize } : {}),
906
- ...(config.type === 'area' ? { areaStyle: { opacity: CHART_STYLE.areaOpacity } } : {}),
1175
+ ...(config.type === 'area' ? { areaStyle: areaGradient(toneOfRole(y) !== null ? toneColor(toneOfRole(y) as VizTone) : theme.palette[i % Math.max(1, theme.palette.length)] ?? theme.text) } : {}),
907
1176
  ...(config.stack && (!combo || seriesType === 'bar') ? { stack: 'total' } : {}),
908
1177
  ...(combo && y2Set.has(y) ? { yAxisIndex: 1 } : {}),
909
1178
  ...(toneOfRole(y) !== null ? (() => { const c = toneColor(toneOfRole(y) as VizTone); return { color: c, itemStyle: { color: c } }; })() : {}),
@@ -934,21 +1203,23 @@ export function buildChartOption(
934
1203
  ],
935
1204
  }
936
1205
  : legend;
937
- const valueAxis = (extra: Record<string, unknown> = {}): Record<string, unknown> => ({
1206
+ // 单位名只挂主纵轴(左);组合图右侧第二纵轴不重复、也不画第二套网格
1207
+ const valueAxis = (extra: Record<string, unknown> = {}, withUnit = true): Record<string, unknown> => ({
938
1208
  type: 'value',
939
- splitLine: { lineStyle: { color: theme.line, width: CHART_STYLE.gridLineWidth } },
940
- axisLabel: { color: theme.text, ...(valueTemplate !== undefined ? { formatter: valueTemplate } : {}) },
1209
+ ...valueAxisStyle(withUnit),
941
1210
  ...extra,
942
1211
  });
1212
+ // 横网格条数上限:引擎的 splitNumber 只是提示(数据最大 32 时它取步长 5、画 8 条),主纵轴按数据跨度直接给好数步长,保证 ≤ gridMaxLines 条
1213
+ const primaryAxis = gridAxisOf(series.filter((s) => (s as { yAxisIndex?: number }).yAxisIndex !== 1), CHART_STYLE.gridMaxLines);
943
1214
  return {
944
1215
  color: theme.palette,
945
1216
  textStyle: { color: theme.text },
946
1217
  grid: gridFor(config.y.length > 1),
947
1218
  legend: legendWithIdeal,
948
- xAxis: { type: 'category', data: cats, axisLine: { lineStyle: { color: theme.line, width: CHART_STYLE.gridLineWidth } }, axisLabel: { color: theme.text } },
1219
+ xAxis: { type: 'category', data: cats, ...categoryAxisStyle },
949
1220
  yAxis: combo && y2Set.size > 0
950
- ? [valueAxis(), valueAxis({ position: 'right', splitLine: { show: false } })]
951
- : valueAxis(),
1221
+ ? [valueAxis(primaryAxis ?? {}), valueAxis({ position: 'right', splitLine: { show: false } }, false)]
1222
+ : valueAxis(primaryAxis ?? {}),
952
1223
  series,
953
1224
  };
954
1225
  }
@@ -962,6 +1233,7 @@ const CHART_TYPE_TEXT: Readonly<Record<KitChartType, KitTextKey>> = Object.freez
962
1233
  radar: 'soma.kit.chart_type_radar', heatmap: 'soma.kit.chart_type_heatmap', boxplot: 'soma.kit.chart_type_boxplot',
963
1234
  candlestick: 'soma.kit.chart_type_candlestick', sankey: 'soma.kit.chart_type_sankey', treemap: 'soma.kit.chart_type_treemap',
964
1235
  sunburst: 'soma.kit.chart_type_sunburst', chord: 'soma.kit.chart_type_chord',
1236
+ rose: 'soma.kit.chart_type_rose', network: 'soma.kit.chart_type_network', bullet: 'soma.kit.chart_type_bullet',
965
1237
  });
966
1238
 
967
1239
  /** 系列数:直角坐标 / 雷达按 y 字段数,其余图型(扇区、阶段、单值、层级、连线)都是一个系列;箱线 / K 线的 y 是同一系列的五 / 四个统计量 */
@@ -1036,7 +1308,150 @@ interface ChartInstanceLike {
1036
1308
  dispose(): void;
1037
1309
  highlight?(p: { seriesIndex: number; dataIndex: number } | null): void;
1038
1310
  onColumn?(handler: (kind: 'hover' | 'click' | 'leave', col: { dataIndex: number } | null) => void): () => void;
1039
- onPointer?(handler: (kind: 'hover' | 'click' | 'leave', p: { dataIndex: number } | null) => void): () => void;
1311
+ onPointer?(handler: (kind: 'hover' | 'click' | 'leave', p: { dataIndex: number; seriesIndex?: number } | null) => void): () => void;
1312
+ }
1313
+
1314
+ export interface KitChartSwatch {
1315
+ bgCls: string;
1316
+ color: string | undefined;
1317
+ }
1318
+
1319
+ /**
1320
+ * 解析系列或槽位在图中的真实色标(背景工具类 + 运行期实色),与 buildChartOptionCore 100% 同构:
1321
+ * - ideal / baseline 角色 -> 中性弱化色(不占序列调色板槽位);
1322
+ * - projection 角色 -> 与第 0 槽同色(不占序列调色板槽位);
1323
+ * - ok / caution / overload 等语义角色 -> 对应语义色(排在无角色普通系列之后,不挤占普通系列的调色板槽位);
1324
+ * - 普通无角色系列 -> 按其在无角色普通系列中的真实槽位取 orderedBg[slot] 与 theme.palette[slot]。
1325
+ */
1326
+ export function chartSeriesSwatchOf(
1327
+ config: KitChartConfig,
1328
+ theme: KitChartTheme,
1329
+ orderedTokens: readonly string[],
1330
+ field: string,
1331
+ mapRaw?: unknown,
1332
+ ): KitChartSwatch {
1333
+ const orderedBg = orderedTokens.map((tok) => {
1334
+ const idx = KIT_CHART_SERIES_TOKENS.indexOf(tok);
1335
+ return SERIES_BG[idx >= 0 ? idx : 0]!;
1336
+ });
1337
+ const palette = theme.palette;
1338
+ const slotSwatch = (slot: number): KitChartSwatch => {
1339
+ const bgLen = Math.max(1, orderedBg.length);
1340
+ const safeBg = ((slot % bgLen) + bgLen) % bgLen;
1341
+ const palLen = Math.max(1, palette.length);
1342
+ const safePal = ((slot % palLen) + palLen) % palLen;
1343
+ return {
1344
+ bgCls: orderedBg[safeBg] ?? SERIES_BG[safeBg % SERIES_BG.length]!,
1345
+ color: palette.length > 0 ? palette[safePal] : undefined,
1346
+ };
1347
+ };
1348
+ const map = recOf(mapRaw);
1349
+ const src = (k: string): string => (typeof map[k] === 'string' && map[k] !== '' ? String(map[k]) : k);
1350
+ const matchedY = config.y.find((y) => y === field || src(y) === src(field)) ?? field;
1351
+ if (config.type === 'bullet' && config.y[1] !== undefined && matchedY === config.y[1]) {
1352
+ return { bgCls: TONE_BG.neutral, color: theme.text };
1353
+ }
1354
+ const role = config.roles?.[matchedY];
1355
+ if (role === 'ideal' || role === 'baseline') {
1356
+ return { bgCls: TONE_BG.neutral, color: theme.ideal ?? theme.text };
1357
+ }
1358
+ if (role === 'projection') {
1359
+ return slotSwatch(0);
1360
+ }
1361
+ const roleTone = role !== undefined ? (SERIES_TONE_ROLES[role] ?? null) : null;
1362
+ if (roleTone !== null) {
1363
+ if (roleTone === 'success') return { bgCls: TONE_BG.success, color: theme.ok ?? palette[0] ?? theme.text };
1364
+ if (roleTone === 'warning') return { bgCls: TONE_BG.warning, color: theme.warn ?? palette[1] ?? theme.text };
1365
+ if (roleTone === 'danger') return { bgCls: TONE_BG.danger, color: theme.danger ?? palette[2] ?? theme.text };
1366
+ if (roleTone === 'primary') return { bgCls: TONE_BG.primary, color: theme.primary ?? palette[0] ?? theme.text };
1367
+ if (roleTone === 'info') return { bgCls: TONE_BG.info, color: theme.primary ?? palette[0] ?? theme.text };
1368
+ return { bgCls: TONE_BG.neutral, color: theme.ideal ?? theme.text };
1369
+ }
1370
+ const isRefRole = (y: string): boolean => {
1371
+ const r = config.roles?.[y];
1372
+ return r === 'ideal' || r === 'baseline' || r === 'projection';
1373
+ };
1374
+ const hasSemanticTone = (y: string): boolean => (SERIES_TONE_ROLES[config.roles?.[y] ?? ''] ?? null) !== null;
1375
+ const plainUnroled = config.y.filter((y) => !isRefRole(y) && !hasSemanticTone(y));
1376
+ const slot = plainUnroled.indexOf(matchedY);
1377
+ if (slot >= 0) return slotSwatch(slot);
1378
+ return { bgCls: TONE_BG.neutral, color: theme.ideal ?? theme.text };
1379
+ }
1380
+
1381
+ /** 计算选项结构签名:图表类型、图例显隐、纵轴数与系列集合一致时可安全走 'merge',保留用户已点击隐藏的图例开关态 */
1382
+ function optionMergeSignatureOf(config: KitChartConfig, option: Record<string, unknown>): string {
1383
+ const seriesSig = Array.isArray(option.series)
1384
+ ? option.series.map((s) => {
1385
+ if (s === null || typeof s !== 'object') return '';
1386
+ const item = s as Record<string, unknown>;
1387
+ const ml = item.markLine !== undefined ? '1' : '0';
1388
+ const ma = item.markArea !== undefined ? '1' : '0';
1389
+ const mp = item.markPoint !== undefined ? '1' : '0';
1390
+ return `${String(item.type ?? '')}:${String(item.name ?? '')}:${String(item.stack ?? '')}:${String(item.yAxisIndex ?? 0)}:${ml}${ma}${mp}`;
1391
+ }).join('|')
1392
+ : '';
1393
+ const legendSig = option.legend !== undefined ? `1:${config.legend ?? 'auto'}` : '0';
1394
+ const yAxisSig = Array.isArray(option.yAxis) ? String(option.yAxis.length) : option.yAxis !== undefined ? '1' : '0';
1395
+ return `${config.type}::${legendSig}::${yAxisSig}::${seriesSig}`;
1396
+ }
1397
+
1398
+ function fmtTipShare(part: number, total: number): string {
1399
+ if (!Number.isFinite(part) || !Number.isFinite(total) || total <= 0) return '';
1400
+ const pct = cleanSummaryFloat((Math.max(0, part) / total) * 100);
1401
+ const rounded = Number((Math.round((pct + Number.EPSILON) * 10) / 10).toFixed(1));
1402
+ return `${Object.is(rounded, -0) ? 0 : rounded}%`;
1403
+ }
1404
+
1405
+ /** 为非直角坐标图型的 SVG 图元补齐数据项提示委托属性(兼容无像素布局环境下的 DOM 事件悬停委托) */
1406
+ function annotateStageSvgItems(
1407
+ stageEl: HTMLElement | null,
1408
+ config: KitChartConfig,
1409
+ rows: ReadonlyArray<Record<string, unknown>>,
1410
+ ): void {
1411
+ if (!stageEl || KIT_CHART_COLUMN_TYPES.has(config.type) || rows.length === 0) return;
1412
+ const svg = stageEl.querySelector('svg');
1413
+ if (!svg) return;
1414
+ const allShapes = Array.from(svg.querySelectorAll('path, circle, rect, polygon')).filter((el) => {
1415
+ if (el.closest('defs') !== null) return false;
1416
+ const fill = (el.getAttribute('fill') ?? '').trim().toLowerCase();
1417
+ return fill !== 'none' && fill !== 'transparent' && !/\b0\s*\)$/.test(fill);
1418
+ });
1419
+ if (config.type === 'pie' || config.type === 'donut' || config.type === 'rose') {
1420
+ const sectors = allShapes.filter((el) => {
1421
+ const d = el.getAttribute('d') ?? '';
1422
+ const arc = /A\s*(\d+(?:\.\d+)?)/i.exec(d);
1423
+ return arc !== null && Number.parseFloat(arc[1]!) > 5;
1424
+ });
1425
+ sectors.slice(0, rows.length).forEach((el, i) => el.setAttribute(KIT_CHART_ITEM_ATTR, String(i)));
1426
+ return;
1427
+ }
1428
+ if (config.type === 'funnel' || config.type === 'heatmap' || config.type === 'treemap' || config.type === 'sunburst') {
1429
+ const polys = allShapes.filter((el) => el.tagName.toLowerCase() !== 'path' || !/[Aa]/.test(el.getAttribute('d') ?? ''));
1430
+ polys.slice(0, rows.length).forEach((el, i) => el.setAttribute(KIT_CHART_ITEM_ATTR, String(i)));
1431
+ return;
1432
+ }
1433
+ if (config.type === 'scatter') {
1434
+ const dots = allShapes.filter((el) => {
1435
+ if (el.tagName.toLowerCase() === 'circle') return true;
1436
+ const d = el.getAttribute('d') ?? '';
1437
+ return /[Aa]/.test(d) && !/[LlHhVv]/.test(d);
1438
+ });
1439
+ dots.slice(0, rows.length * config.y.length).forEach((el, idx) => {
1440
+ el.setAttribute(KIT_CHART_ITEM_ATTR, String(idx % rows.length));
1441
+ el.setAttribute(KIT_ATTR_CHART_SERIES, String(Math.floor(idx / rows.length)));
1442
+ });
1443
+ return;
1444
+ }
1445
+ if (config.type === 'radar') {
1446
+ const dots = allShapes.filter((el) => {
1447
+ if (el.tagName.toLowerCase() === 'circle') return true;
1448
+ const d = el.getAttribute('d') ?? '';
1449
+ return /[Aa]/.test(d) && !/[LlHhVv]/.test(d);
1450
+ });
1451
+ dots.slice(0, rows.length * config.y.length).forEach((el, idx) => {
1452
+ el.setAttribute(KIT_CHART_ITEM_ATTR, String(Math.floor(idx / rows.length)));
1453
+ });
1454
+ }
1040
1455
  }
1041
1456
 
1042
1457
  interface ChartEnginePort {
@@ -1045,8 +1460,8 @@ interface ChartEnginePort {
1045
1460
  }
1046
1461
 
1047
1462
  /** 把 --soma-* 令牌解析成运行期颜色值:直接读宿主的计算样式,源码不出现裸色值,也不写内联样式 */
1048
- function resolveToken(host: HTMLElement, token: string): string {
1049
- const value = typeof getComputedStyle === 'function' ? getComputedStyle(host).getPropertyValue(token).trim() : '';
1463
+ function resolveToken(host: HTMLElement, token: string, dark = isDarkColorScheme(host)): string {
1464
+ const value = readComputedToken(host, token, dark);
1050
1465
  return value === '' ? `var(${token})` : value;
1051
1466
  }
1052
1467
 
@@ -1057,25 +1472,72 @@ function pctToken(host: HTMLElement, token: string): number | null {
1057
1472
  return Number.isFinite(n) ? n : null;
1058
1473
  }
1059
1474
 
1475
+ /**
1476
+ * 系列令牌的取用顺序:页面样式在图表宿主上写的 --kit-chart-order(编译期按分类色自动序列求出,theme/theme-tokens#kitChartOrderCss——
1477
+ * 系列色与同页分类标签同名同色);没写或不合法时按 1…8 原序。
1478
+ */
1479
+ export function chartSeriesTokensOf(host: HTMLElement): readonly string[] {
1480
+ const raw = typeof getComputedStyle === 'function' ? getComputedStyle(host).getPropertyValue('--kit-chart-order').trim() : '';
1481
+ const order = raw.split(/\s+/).map(Number).filter((n) => Number.isInteger(n) && n >= 1 && n <= KIT_CHART_SERIES_TOKENS.length);
1482
+ if (order.length === 0) return KIT_CHART_SERIES_TOKENS;
1483
+ const seen = [...new Set(order)];
1484
+ for (let i = 1; i <= KIT_CHART_SERIES_TOKENS.length; i += 1) if (!seen.includes(i)) seen.push(i);
1485
+ return seen.map((i) => KIT_CHART_SERIES_TOKENS[i - 1]!);
1486
+ }
1487
+
1488
+ export const KIT_CHART_SEQ_TOKENS: readonly string[] = Object.freeze(
1489
+ Array.from({ length: 10 }, (_, i) => `--soma-chart-seq-${i + 1}`),
1490
+ );
1491
+ export const KIT_CHART_DIV_TOKENS: readonly string[] = Object.freeze(
1492
+ Array.from({ length: 17 }, (_, i) => `--soma-chart-div-${i + 1}`),
1493
+ );
1494
+
1495
+ function readComputedToken(host: HTMLElement, token: string, dark = isDarkColorScheme(host)): string {
1496
+ const view = host.ownerDocument?.defaultView;
1497
+ const raw = view && typeof view.getComputedStyle === 'function'
1498
+ ? view.getComputedStyle(host).getPropertyValue(token).trim()
1499
+ : (typeof getComputedStyle === 'function' ? getComputedStyle(host).getPropertyValue(token).trim() : '');
1500
+ return raw === '' ? '' : unwrapLightDark(raw, dark);
1501
+ }
1502
+
1503
+ function readTokenRamp(host: HTMLElement, tokens: readonly string[], dark = isDarkColorScheme(host)): string[] | undefined {
1504
+ const vals = tokens.map((t) => readComputedToken(host, t, dark));
1505
+ return vals.every((v) => v !== '') ? vals : undefined;
1506
+ }
1507
+
1060
1508
  function themeOf(host: HTMLElement): KitChartTheme {
1061
- // 图表填充重量(强调级作用域重写 --soma-chart-fill-mix / --soma-chart-bar-ratio):首绘读一次(data-kit-emphasis 是编译期常量,运行期不变)
1509
+ const dark = isDarkColorScheme(host);
1510
+ // 图表填充重量(强调级作用域重写 --soma-chart-fill-mix / --soma-chart-bar-ratio):每次绘制读(含换主题后的重绘),与系列色同一次取值
1062
1511
  const fillMix = pctToken(host, '--soma-chart-fill-mix');
1063
1512
  const barRatio = pctToken(host, '--soma-chart-bar-ratio');
1064
- const surface = resolveToken(host, '--soma-surface-panel');
1513
+ // 刻度字号 = 字阶最小档(--soma-font-size-xs,求解写成 px)
1514
+ const tickPx = pctToken(host, '--soma-font-size-xs');
1515
+ const surface = resolveToken(host, '--soma-surface-panel', dark);
1516
+ const idleRaw = readComputedToken(host, '--soma-chart-idle', dark);
1517
+ const seqRamp = readTokenRamp(host, KIT_CHART_SEQ_TOKENS, dark);
1518
+ const divRamp = readTokenRamp(host, KIT_CHART_DIV_TOKENS, dark);
1065
1519
  return {
1066
- palette: KIT_CHART_SERIES_TOKENS.map((n) => {
1067
- const c = resolveToken(host, n);
1520
+ palette: chartSeriesTokensOf(host).map((n) => {
1521
+ const c = resolveToken(host, n, dark);
1068
1522
  return fillMix === null ? c : mixTowardSurface(c, surface, fillMix);
1069
1523
  }),
1070
1524
  ...(barRatio !== null ? { barRatioPct: barRatio } : {}),
1071
- text: resolveToken(host, '--soma-text-secondary'),
1072
- line: resolveToken(host, '--soma-border-hairline'),
1073
- ideal: resolveToken(host, '--soma-text-muted'),
1074
- primary: resolveToken(host, '--soma-c-primary'),
1525
+ text: resolveToken(host, '--soma-text-secondary', dark),
1526
+ // 网格 / 轴是图表自己的结构色(不借分隔线发丝灰),配色方案求出十六进制实色(引擎解析不了 color-mix 字串)
1527
+ grid: resolveToken(host, '--soma-chart-grid', dark),
1528
+ axis: resolveToken(host, '--soma-chart-axis', dark),
1529
+ tick: resolveToken(host, '--soma-text-muted', dark),
1530
+ ...(tickPx !== null ? { tickPx } : {}),
1531
+ ideal: resolveToken(host, '--soma-text-muted', dark),
1532
+ primary: resolveToken(host, '--soma-c-primary', dark),
1533
+ // Gauge 未填充底弧优先读取 --soma-chart-idle(不再借用语义成功色;无该令牌的旧 mock 环境回落 --soma-chart-idle 变量或凹陷面)
1534
+ track: idleRaw !== '' ? idleRaw : (readComputedToken(host, '--soma-surface-sunken', dark) || 'var(--soma-chart-idle)'),
1075
1535
  projectionSuffix: kitText('soma.kit.chart_projection', { name: '' }, host),
1076
- ok: resolveToken(host, '--soma-c-success'),
1077
- warn: resolveToken(host, '--soma-c-warning'),
1078
- danger: resolveToken(host, '--soma-c-danger'),
1536
+ ok: resolveToken(host, '--soma-c-success', dark),
1537
+ warn: resolveToken(host, '--soma-c-warning', dark),
1538
+ danger: resolveToken(host, '--soma-c-danger', dark),
1539
+ ...(seqRamp !== undefined ? { seqRamp } : {}),
1540
+ ...(divRamp !== undefined ? { divRamp } : {}),
1079
1541
  };
1080
1542
  }
1081
1543
 
@@ -1086,7 +1548,7 @@ export function createChart(): SomaComponentDefinition {
1086
1548
  layer: 'data',
1087
1549
  props: {
1088
1550
  data: { type: 'array', default: [], desc: '行数组' },
1089
- chart: { type: 'object', default: {}, desc: '图形配置 { type: line | bar | area | pie | donut | funnel | gauge | scatter | combo | radar | heatmap | boxplot | candlestick | sankey | treemap | sunburst | chord, x: 字段, y: [字段…], stack?: bool(line / area / bar / combo 的 y 项也可写 { field, role?: ideal }:ideal = 理想线,虚线中性色、不占序列配色、图例排最后;数据点 null = 断线留白,不补零不连线), min? / max? / warnAt? / dangerAt?(gauge;radar 的 max 为各指标量程上限), value?: 字段, parent?: 字段 };funnel 行序即流程顺序;gauge 取列表第一行;scatter:x 与每个 y 字段都是数值;combo:柱线组合,line: [字段…] 里的 y 画折线、其余画柱,y2: [字段…] 挂右侧第二纵轴;ref_lines: [{ value 或 stat(average|max|min|median), label?, tone?(neutral|success|warning|danger) }] 虚线参考线(直角坐标系图型);legend: auto|top|bottom|none;value_format: { prefix?, suffix? } 纵轴与标签的数值前后缀;radar:每行一个指标(x 作名)、每个 y 字段一条系列;heatmap:x / y[0] 为横纵类目、value 为格值;boxplot:y 依次为 最小 / 下四分位 / 中位 / 上四分位 / 最大;candlestick:y 依次为 开盘 / 收盘 / 最低 / 最高;sankey / chord:每行一条连线,x 来源、y[0] 去向、value 流量;treemap / sunburst:x 名称、y[0] 数值、parent 父名称(空 = 根);折线 / 面积 / 柱 / 组合另可写 marks: [{ kind: line|band|point, axis?: x|y, at? / from? / to?: 字面量或 { field }, series?, label?, role? }](竖线 / 区间带 / 标记点,取色线型由 role 决定)、readout: { place?, title?, note?, items: [{ field, label?, format?, unit? }], default? }(逐列读数区)、interact: { pick?: bool }(点击 / Enter 选中列抛 point_pick);y 项 role 另有 projection(预测线)与 ok / caution / overload(语义取色)' },
1551
+ chart: { type: 'object', default: {}, desc: '图形配置 { type: line | bar | area | pie | donut | funnel | gauge | scatter | combo | radar | heatmap | boxplot | candlestick | sankey | treemap | sunburst | chord | rose | network | bullet, x: 字段, y: [字段…], stack?: bool(line / area / bar / combo 的 y 项也可写 { field, role?: ideal }:ideal = 理想线,虚线中性色、不占序列配色、图例排最后;数据点 null = 断线留白,不补零不连线), min? / max? / warnAt? / dangerAt?(gauge;radar 的 max 为各指标量程上限), value?: 字段, parent?: 字段 };funnel 行序即流程顺序;gauge 取列表第一行;scatter:x 与每个 y 字段都是数值;combo:柱线组合,line: [字段…] 里的 y 画折线、其余画柱,y2: [字段…] 挂右侧第二纵轴;ref_lines: [{ value 或 stat(average|max|min|median), label?, tone?(neutral|success|warning|danger) }] 虚线参考线(直角坐标系图型);legend: auto|top|bottom|none;value_format: { prefix?, suffix? } 纵轴与标签的数值前后缀;radar:每行一个指标(x 作名)、每个 y 字段一条系列;heatmap:x / y[0] 为横纵类目、value 为格值;boxplot:y 依次为 最小 / 下四分位 / 中位 / 上四分位 / 最大;candlestick:y 依次为 开盘 / 收盘 / 最低 / 最高;sankey / chord:每行一条连线,x 来源、y[0] 去向、value 流量;treemap / sunburst:x 名称、y[0] 数值、parent 父名称(空 = 根);rose:同 pie(x 名、y[0] 值,半径编码数值);network:每行一条边,x 起点、y[0] 终点、value 边权(可选),力导向布局;bullet:x 名称、y[0] 实际值(横条)、y[1] 目标值(刻度);折线 / 面积 / 柱 / 组合另可写 marks: [{ kind: line|band|point, axis?: x|y, at? / from? / to?: 字面量或 { field }, series?, label?, role? }](竖线 / 区间带 / 标记点,取色线型由 role 决定)、readout: { place?, title?, note?, items: [{ field, label?, format?, unit? }], default? }(逐列读数区)、interact: { pick?: bool }(点击 / Enter 选中列抛 point_pick);y 项 role 另有 projection(预测线)与 ok / caution / overload(语义取色);up_is?: good | bad(K 线涨跌色反转开关:good 涨为成功色,bad 涨为危险色)' },
1090
1552
  map: { type: 'object', default: {}, desc: '键名对照:chart 里的字段名 -> 数据里的键' },
1091
1553
  empty: { type: 'string', default: '', desc: '无数据时的空态文案;缺省取内置文案(按页面语言)' },
1092
1554
  title: { type: 'string', default: '', desc: '图表标题:进可访问名(role=img)与读屏数据表标题;缺省只用「图型 + 系列数 + 数据点数」' },
@@ -1108,7 +1570,7 @@ export function createChart(): SomaComponentDefinition {
1108
1570
  `<div data-soma-id="root" class="${ROOT_CLASS}">`
1109
1571
  + `<div data-soma-id="stageWrap" class="hidden"><div data-soma-id="stage" class="${STAGE_CLASS}"></div></div>`
1110
1572
  + '<div data-soma-id="altWrap" class="sr-only"></div>'
1111
- + `<div data-soma-id="emptyWrap"><div data-soma-id="emptyText" class="${EMPTY_INNER_CLASS}"></div></div>`
1573
+ + `<div data-soma-id="emptyWrap"><div data-soma-id="emptyGrid" class="hidden" aria-hidden="true"></div><div data-soma-id="emptyText" class="${EMPTY_INNER_CLASS}"></div></div>`
1112
1574
  + '</div>',
1113
1575
  controllerFactory: createKitController((api) => {
1114
1576
  const P = (): Record<string, unknown> => api.props();
@@ -1117,6 +1579,9 @@ export function createChart(): SomaComponentDefinition {
1117
1579
  let stage: HTMLElement | null = null;
1118
1580
  let emptyWrap: HTMLElement | null = null;
1119
1581
  let emptyText: HTMLElement | null = null;
1582
+ let emptyGrid: HTMLElement | null = null;
1583
+ let tipEl: HTMLElement | null = null;
1584
+ let pointerAt: { x: number; y: number } | null = null;
1120
1585
  let altWrap: HTMLElement | null = null;
1121
1586
  let instance: ChartInstanceLike | null = null;
1122
1587
  // 交互状态(K2 / K3):读数区 DOM、当前列、键盘漫游标记、最近一次出图的上下文(焦点带重建 option 用)
@@ -1126,6 +1591,7 @@ export function createChart(): SomaComponentDefinition {
1126
1591
  let defaultCol = -1;
1127
1592
  let kbdActive = false;
1128
1593
  let offColumn: (() => void) | null = null;
1594
+ let lastOptionSig: string | null = null;
1129
1595
  let drawn: { config: KitChartConfig; rows: Array<Record<string, unknown>>; theme: KitChartTheme; map: unknown; reduceMotion: boolean } | null = null;
1130
1596
  let creating: Promise<void> | null = null;
1131
1597
  let resizeObs: ResizeObserver | null = null;
@@ -1141,7 +1607,7 @@ export function createChart(): SomaComponentDefinition {
1141
1607
  revealed = true;
1142
1608
  engineGate = null;
1143
1609
  // 只收起加载占位;数据旁的错误提示条(keepStage 的 error 面板)保留
1144
- if (emptyText?.getAttribute('data-kit-state') === 'loading' || emptyText?.getAttribute('data-kit-state') === null) {
1610
+ if (emptyText?.getAttribute(KIT_ATTR_STATE) === 'loading' || emptyText?.getAttribute(KIT_ATTR_STATE) === null) {
1145
1611
  emptyWrap?.classList.remove('absolute', 'inset-0');
1146
1612
  emptyWrap?.classList.add('hidden');
1147
1613
  }
@@ -1156,6 +1622,7 @@ export function createChart(): SomaComponentDefinition {
1156
1622
  if (!alive) return;
1157
1623
  if (phase === 'visible' && !revealed) {
1158
1624
  showPanel('loading', str(P().loading_text, kitText('soma.kit.loading', undefined, root ?? undefined)), {}, true);
1625
+ emptyWrap?.classList.remove('relative');
1159
1626
  emptyWrap?.classList.add('absolute', 'inset-0');
1160
1627
  } else if (phase === 'idle' && settled) reveal();
1161
1628
  });
@@ -1172,8 +1639,9 @@ export function createChart(): SomaComponentDefinition {
1172
1639
  engineGate = null;
1173
1640
  };
1174
1641
 
1175
- // 深浅色切换:系列色取自运行期计算值,主题变了要重算并 setOption。
1176
- // 两个来源——系统偏好 prefers-color-scheme,以及 <html> 上 soma-scheme-dark / soma-scheme-light 类的变化
1642
+ // 主题切换:系列色 / 网格 / 轴取自运行期计算值,主题变了要重算并 setOption。
1643
+ // 三个来源——系统偏好 prefers-color-scheme、<html> 上 soma-scheme-dark / soma-scheme-light 类的变化,
1644
+ // 以及运行期换主题后的「主题已应用」事件(KIT_THEME_APPLIED_EVENT:换色族 / 对比度 / 中性灰时明暗类与媒体都不变)
1177
1645
  let schemeOff: (() => void) | null = null;
1178
1646
  const schemeKey = (): string => {
1179
1647
  const cl = typeof document !== 'undefined' ? document.documentElement.classList : null;
@@ -1186,10 +1654,10 @@ export function createChart(): SomaComponentDefinition {
1186
1654
  const offs: Array<() => void> = [];
1187
1655
  if (typeof matchMedia === 'function') {
1188
1656
  const mq = matchMedia('(prefers-color-scheme: dark)');
1189
- if (typeof mq.addEventListener === 'function') {
1657
+ if (typeof mq?.addEventListener === 'function') {
1190
1658
  mq.addEventListener('change', repaint);
1191
1659
  offs.push(() => mq.removeEventListener('change', repaint));
1192
- } else if (typeof mq.addListener === 'function') {
1660
+ } else if (typeof mq?.addListener === 'function') {
1193
1661
  mq.addListener(repaint);
1194
1662
  offs.push(() => mq.removeListener(repaint));
1195
1663
  }
@@ -1204,6 +1672,11 @@ export function createChart(): SomaComponentDefinition {
1204
1672
  mo.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
1205
1673
  offs.push(() => mo.disconnect());
1206
1674
  }
1675
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
1676
+ const onApplied = (): void => { last = schemeKey(); repaint(); };
1677
+ document.addEventListener(KIT_THEME_APPLIED_EVENT, onApplied);
1678
+ offs.push(() => document.removeEventListener(KIT_THEME_APPLIED_EVENT, onApplied));
1679
+ }
1207
1680
  schemeOff = () => { for (const off of offs) off(); };
1208
1681
  };
1209
1682
  const unwatchScheme = (): void => {
@@ -1218,9 +1691,43 @@ export function createChart(): SomaComponentDefinition {
1218
1691
  const showPanel = (kind: KitStateKind, text: string, o: Partial<KitStatePanelOptions> = {}, keepStage = false): void => {
1219
1692
  if (!stageWrap || !emptyWrap || !emptyText) return;
1220
1693
  emptyWrap.classList.remove('absolute', 'inset-0');
1694
+ emptyWrap.classList.add('relative');
1221
1695
  if (keepStage) stageWrap.classList.remove('hidden'); else { stageWrap.classList.add('hidden'); clearAlt(); }
1222
1696
  emptyWrap.classList.remove('hidden');
1697
+ // 空 / 加载且是直角坐标图型:保留空坐标网格,文字或骨架条叠在网格上(图区尺寸不变);其余整块面板
1698
+ const config = chartConfigOf(P().chart);
1699
+ const gridded = (kind === 'empty' || kind === 'loading') && config !== null && GRID_TYPES.has(config.type);
1700
+ paintGridPlace(gridded);
1701
+ if (!gridded) { paintKitStatePanel(emptyText, kind, { ...o, text }); return; }
1702
+ if (kind === 'loading') {
1703
+ const doc = emptyText.ownerDocument;
1704
+ const skeleton = doc.createElement('div');
1705
+ skeleton.className = GRID_SKELETON_CLASS;
1706
+ skeleton.setAttribute('aria-hidden', 'true');
1707
+ for (const cls of [KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_LAST_TEXT]) {
1708
+ const bar = doc.createElement('div');
1709
+ bar.className = cls;
1710
+ skeleton.appendChild(bar);
1711
+ }
1712
+ paintKitStatePanel(emptyText, kind, { ...o, text, skeleton });
1713
+ emptyText.className = GRID_OVER_CLASS;
1714
+ return;
1715
+ }
1223
1716
  paintKitStatePanel(emptyText, kind, { ...o, text });
1717
+ emptyText.className = GRID_OVER_CLASS;
1718
+ };
1719
+ /** 空坐标网格:横向发丝线 gridMaxLines 条(只在直角坐标图的空 / 加载态显示) */
1720
+ const paintGridPlace = (on: boolean): void => {
1721
+ if (!emptyGrid) return;
1722
+ emptyGrid.textContent = '';
1723
+ if (!on) { emptyGrid.className = 'hidden'; return; }
1724
+ emptyGrid.className = GRID_PLACE_CLASS;
1725
+ const doc = emptyGrid.ownerDocument;
1726
+ for (let i = 0; i < CHART_STYLE.gridMaxLines; i += 1) {
1727
+ const line = doc.createElement('div');
1728
+ line.className = GRID_LINE_CLASS;
1729
+ emptyGrid.appendChild(line);
1730
+ }
1224
1731
  };
1225
1732
  // 文字替代:只在真有图(舞台可见)时给舞台 role=img + 可访问名,并在旁边放读屏数据表;
1226
1733
  // 空 / 加载 / 错误 / 降级面板没有图,不带 role=img。role=img 会把子孙当装饰,所以数据表是舞台的兄弟而不是子孙。
@@ -1355,18 +1862,301 @@ export function createChart(): SomaComponentDefinition {
1355
1862
  api.emit('point_pick', { index: col, x: row[xKey] === undefined || row[xKey] === null ? '' : String(row[xKey]), row });
1356
1863
  announce(col, true);
1357
1864
  };
1358
- const onColumnEvent = (kind: 'hover' | 'click' | 'leave', col: { dataIndex: number } | null): void => {
1865
+ // ── 悬停数据卡:指针悬停某一列或图元时出卡(标题 + 逐系列色块 / 名称 / 数值 / 占比),跟随指针并防边裁切;读数区保留给键盘 ──
1866
+ const hideTip = (): void => {
1867
+ if (tipEl) tipEl.className = 'hidden';
1868
+ };
1869
+ const placeTip = (): void => {
1870
+ if (!tipEl || !root || pointerAt === null || tipEl.classList.contains('hidden')) return;
1871
+ const rootRect = root.getBoundingClientRect();
1872
+ const roomW = root.clientWidth || Math.round(rootRect.width);
1873
+ const roomH = root.clientHeight || stageWrap?.clientHeight || Math.round(rootRect.height);
1874
+ const tipRect = tipEl.getBoundingClientRect();
1875
+ const w = tipEl.offsetWidth || Math.round(tipRect.width);
1876
+ const h = tipEl.offsetHeight || Math.round(tipRect.height);
1877
+ const flipX = roomW > 0 && (w > 0 ? pointerAt.x + TIP_OFFSET_PX + w > roomW : pointerAt.x > roomW - 120);
1878
+ const flipY = roomH > 0 && (h > 0 ? pointerAt.y + TIP_OFFSET_PX + h > roomH : pointerAt.y > roomH - 80);
1879
+ tipEl.classList.toggle(TIP_FLIP_X_CLASS, flipX && w === 0);
1880
+ tipEl.classList.toggle(TIP_FLIP_Y_CLASS, flipY && h === 0);
1881
+ tipEl.setAttribute(KIT_ATTR_TIP_ALIGN, `${flipY ? 'top' : 'bottom'}-${flipX ? 'end' : 'start'}`);
1882
+ const rawLeft = flipX
1883
+ ? (w > 0 ? pointerAt.x - TIP_OFFSET_PX - w : pointerAt.x - TIP_OFFSET_PX)
1884
+ : pointerAt.x + TIP_OFFSET_PX;
1885
+ const rawTop = flipY
1886
+ ? (h > 0 ? pointerAt.y - TIP_OFFSET_PX - h : pointerAt.y - TIP_OFFSET_PX)
1887
+ : pointerAt.y + TIP_OFFSET_PX;
1888
+ const maxLeft = roomW > 0 && w > 0 ? Math.max(0, roomW - w) : Number.POSITIVE_INFINITY;
1889
+ const maxTop = roomH > 0 && h > 0 ? Math.max(0, roomH - h) : Number.POSITIVE_INFINITY;
1890
+ tipEl.style.left = `${Math.round(Math.min(maxLeft, Math.max(0, rawLeft)))}px`;
1891
+ tipEl.style.top = `${Math.round(Math.min(maxTop, Math.max(0, rawTop)))}px`;
1892
+ };
1893
+ const onPointerMove = (event: PointerEvent): void => {
1894
+ if (!root) return;
1895
+ const box = root.getBoundingClientRect();
1896
+ pointerAt = { x: event.clientX - box.left, y: event.clientY - box.top };
1897
+ placeTip();
1898
+ };
1899
+ const appendTipDot = (doc: Document, swatch: KitChartSwatch): HTMLElement => {
1900
+ const dot = doc.createElement('span');
1901
+ dot.className = mergeClass(TIP_DOT_CLASS, swatch.bgCls);
1902
+ if (swatch.color && !swatch.color.startsWith('var(')) {
1903
+ const svg = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
1904
+ svg.setAttribute('viewBox', '0 0 8 8');
1905
+ svg.setAttribute('class', 'size-full');
1906
+ svg.setAttribute('aria-hidden', 'true');
1907
+ const circle = doc.createElementNS('http://www.w3.org/2000/svg', 'circle');
1908
+ circle.setAttribute('cx', '4');
1909
+ circle.setAttribute('cy', '4');
1910
+ circle.setAttribute('r', '4');
1911
+ circle.setAttribute('fill', swatch.color);
1912
+ svg.appendChild(circle);
1913
+ dot.appendChild(svg);
1914
+ }
1915
+ return dot;
1916
+ };
1917
+ /** 悬停卡内容:直角坐标列与非直角坐标(饼/环/玫瑰/漏斗/散点/雷达/热力等)统一构建标题、真实色标、数值与占比 */
1918
+ const showTip = (col: number, seriesIndex?: number): void => {
1919
+ const d = drawn;
1920
+ if (!tipEl || !d || col < 0) { hideTip(); return; }
1921
+ const m = recOf(d.map);
1922
+ const src = (k: string): string => (typeof m[k] === 'string' && m[k] !== '' ? String(m[k]) : k);
1923
+ const empty = kitText('soma.kit.chart_readout_empty', undefined, root ?? undefined);
1924
+ const orderedTokens = root ? chartSeriesTokensOf(root) : KIT_CHART_SERIES_TOKENS;
1925
+ const orderedBg = orderedTokens.map((tok) => {
1926
+ const idx = KIT_CHART_SERIES_TOKENS.indexOf(tok);
1927
+ return SERIES_BG[idx >= 0 ? idx : 0]!;
1928
+ });
1929
+ const palette = d.theme.palette;
1930
+ const slotSwatch = (slot: number): KitChartSwatch => {
1931
+ const bgLen = Math.max(1, orderedBg.length);
1932
+ const safeBg = ((slot % bgLen) + bgLen) % bgLen;
1933
+ const palLen = Math.max(1, palette.length);
1934
+ const safePal = ((slot % palLen) + palLen) % palLen;
1935
+ return {
1936
+ bgCls: orderedBg[safeBg] ?? SERIES_BG[safeBg % SERIES_BG.length]!,
1937
+ color: palette.length > 0 ? palette[safePal] : undefined,
1938
+ };
1939
+ };
1940
+ const withAffix = (valText: string): string => {
1941
+ const vf = d.config.valueFormat;
1942
+ if (!vf || valText === empty) return valText;
1943
+ return `${vf.prefix}${valText}${vf.suffix}`;
1944
+ };
1945
+
1946
+ let title = '';
1947
+ const tipRows: Array<{ swatch: KitChartSwatch; label: string; value: string }> = [];
1948
+ const ctype = d.config.type;
1949
+
1950
+ if (KIT_CHART_COLUMN_TYPES.has(ctype)) {
1951
+ if (col >= d.rows.length) { hideTip(); return; }
1952
+ const row = d.rows[col];
1953
+ const items = d.config.readout?.items ?? d.config.y.map((field) => ({ field, label: field, format: 'number' as const, unit: '' }));
1954
+ title = d.config.readout !== undefined && d.config.readout.title !== '' ? cellText(row, d.config.readout.title, m) : cellText(row, d.config.x, m);
1955
+ for (const it of items) {
1956
+ const key = src(it.field);
1957
+ const rawText = formatReadoutValue(row?.[key], it.format, it.unit, empty);
1958
+ tipRows.push({
1959
+ swatch: chartSeriesSwatchOf(d.config, d.theme, orderedTokens, it.field, m),
1960
+ label: it.label,
1961
+ value: d.config.readout !== undefined ? rawText : withAffix(rawText),
1962
+ });
1963
+ }
1964
+ } else if (ctype === 'pie' || ctype === 'donut' || ctype === 'rose' || ctype === 'funnel' || ctype === 'treemap' || ctype === 'sunburst') {
1965
+ if (col >= d.rows.length) { hideTip(); return; }
1966
+ const row = d.rows[col]!;
1967
+ const yField = d.config.y[0]!;
1968
+ const yKey = src(yField);
1969
+ const rawVal = num(row[yKey]);
1970
+ const valText = withAffix(formatReadoutValue(row[yKey], 'number', '', empty));
1971
+ const sumVal = d.rows.reduce((acc, r) => acc + Math.max(0, num(r[yKey]) ?? 0), 0);
1972
+ const topVal = ctype === 'funnel' ? num(d.rows[0]?.[yKey]) : null;
1973
+ const base = topVal !== null && topVal > 0 ? topVal : sumVal;
1974
+ const share = rawVal !== null ? fmtTipShare(rawVal, base) : '';
1975
+ title = cellText(row, d.config.x, m);
1976
+ tipRows.push({
1977
+ swatch: slotSwatch(col),
1978
+ label: yField,
1979
+ value: share !== '' ? `${valText} (${share})` : valText,
1980
+ });
1981
+ } else if (ctype === 'scatter') {
1982
+ if (col >= d.rows.length) { hideTip(); return; }
1983
+ const row = d.rows[col]!;
1984
+ const xText = formatReadoutValue(row[src(d.config.x)], 'number', '', empty);
1985
+ title = `${d.config.x}: ${xText}`;
1986
+ const fields = seriesIndex !== undefined && seriesIndex >= 0 && seriesIndex < d.config.y.length
1987
+ ? [d.config.y[seriesIndex]!]
1988
+ : d.config.y;
1989
+ for (const field of fields) {
1990
+ tipRows.push({
1991
+ swatch: chartSeriesSwatchOf(d.config, d.theme, orderedTokens, field, m),
1992
+ label: field,
1993
+ value: withAffix(formatReadoutValue(row[src(field)], 'number', '', empty)),
1994
+ });
1995
+ }
1996
+ } else if (ctype === 'radar') {
1997
+ if (col < d.config.y.length) {
1998
+ const field = d.config.y[col]!;
1999
+ const swatch = chartSeriesSwatchOf(d.config, d.theme, orderedTokens, field, m);
2000
+ title = field;
2001
+ for (const r of d.rows) {
2002
+ tipRows.push({
2003
+ swatch,
2004
+ label: cellText(r, d.config.x, m),
2005
+ value: withAffix(formatReadoutValue(r[src(field)], 'number', '', empty)),
2006
+ });
2007
+ }
2008
+ } else if (col < d.rows.length) {
2009
+ const row = d.rows[col]!;
2010
+ title = cellText(row, d.config.x, m);
2011
+ for (const field of d.config.y) {
2012
+ tipRows.push({
2013
+ swatch: chartSeriesSwatchOf(d.config, d.theme, orderedTokens, field, m),
2014
+ label: field,
2015
+ value: withAffix(formatReadoutValue(row[src(field)], 'number', '', empty)),
2016
+ });
2017
+ }
2018
+ } else {
2019
+ hideTip();
2020
+ return;
2021
+ }
2022
+ } else if (ctype === 'heatmap') {
2023
+ if (col >= d.rows.length || !d.config.value) { hideTip(); return; }
2024
+ const row = d.rows[col]!;
2025
+ const valField = d.config.value;
2026
+ const valKey = src(valField);
2027
+ const rawVal = num(row[valKey]);
2028
+ const allVals = d.rows.map((r) => num(r[valKey]) ?? 0);
2029
+ const lo = Math.min(...allVals, 0);
2030
+ const hi = Math.max(...allVals, 1);
2031
+ const isDiv = d.config.scale === 'diverging'
2032
+ || (d.config.scale !== 'sequential' && allVals.some((v) => v < 0) && allVals.some((v) => v > 0));
2033
+ const ramp = isDiv ? d.theme.divRamp : d.theme.seqRamp;
2034
+ let rampColor = palette[0];
2035
+ if (ramp && ramp.length > 0 && rawVal !== null) {
2036
+ const ratio = hi > lo ? Math.min(1, Math.max(0, (rawVal - lo) / (hi - lo))) : 0.5;
2037
+ rampColor = ramp[Math.min(ramp.length - 1, Math.round(ratio * (ramp.length - 1)))];
2038
+ }
2039
+ const xCat = cellText(row, d.config.x, m);
2040
+ const yCat = cellText(row, d.config.y[0]!, m);
2041
+ title = [xCat, yCat].filter((s) => s !== '').join(' · ');
2042
+ tipRows.push({
2043
+ swatch: { bgCls: slotSwatch(0).bgCls, color: rampColor },
2044
+ label: valField,
2045
+ value: withAffix(formatReadoutValue(row[valKey], 'number', '', empty)),
2046
+ });
2047
+ } else if (ctype === 'gauge') {
2048
+ const row = d.rows[0];
2049
+ if (!row) { hideTip(); return; }
2050
+ const yField = d.config.y[0]!;
2051
+ const rawVal = num(row[src(yField)]);
2052
+ const span = (d.config.max ?? 100) - (d.config.min ?? 0);
2053
+ const share = rawVal !== null && span > 0 ? fmtTipShare(Math.max(0, rawVal - (d.config.min ?? 0)), span) : '';
2054
+ const valText = withAffix(formatReadoutValue(row[src(yField)], 'number', '', empty));
2055
+ title = cellText(row, d.config.x, m);
2056
+ tipRows.push({
2057
+ swatch: { bgCls: TONE_BG.primary, color: gaugeValueColor(d.config, d.theme, rawVal) },
2058
+ label: yField,
2059
+ value: share !== '' ? `${valText} (${share})` : valText,
2060
+ });
2061
+ } else {
2062
+ if (col >= d.rows.length) { hideTip(); return; }
2063
+ const row = d.rows[col]!;
2064
+ title = ctype === 'sankey' || ctype === 'chord' || ctype === 'network'
2065
+ ? [cellText(row, d.config.x, m), cellText(row, d.config.y[0]!, m)].filter((s) => s !== '').join(' -> ')
2066
+ : cellText(row, d.config.x, m);
2067
+ if (ctype === 'sankey' || ctype === 'chord' || ctype === 'network') {
2068
+ const valField = d.config.value ?? d.config.y[0]!;
2069
+ tipRows.push({
2070
+ swatch: slotSwatch(col),
2071
+ label: valField,
2072
+ value: withAffix(formatReadoutValue(row[src(valField)], 'number', '', empty)),
2073
+ });
2074
+ } else {
2075
+ const openVal = ctype === 'candlestick' ? (num(row[src(d.config.y[0]!)]) ?? 0) : 0;
2076
+ const closeVal = ctype === 'candlestick' ? (num(row[src(d.config.y[1]!)]) ?? 0) : 0;
2077
+ const rise = closeVal >= openVal;
2078
+ const goodSwatch: KitChartSwatch = { bgCls: TONE_BG.success, color: d.theme.ok ?? palette[0] ?? d.theme.text };
2079
+ const badSwatch: KitChartSwatch = { bgCls: TONE_BG.danger, color: d.theme.danger ?? palette[2] ?? d.theme.text };
2080
+ const candleSwatch = d.config.upIs === 'bad' ? (rise ? badSwatch : goodSwatch) : (rise ? goodSwatch : badSwatch);
2081
+ for (const field of d.config.y) {
2082
+ tipRows.push({
2083
+ swatch: ctype === 'candlestick' ? candleSwatch : chartSeriesSwatchOf(d.config, d.theme, orderedTokens, field, m),
2084
+ label: field,
2085
+ value: withAffix(formatReadoutValue(row[src(field)], 'number', '', empty)),
2086
+ });
2087
+ }
2088
+ }
2089
+ }
2090
+
2091
+ if (tipRows.length === 0) { hideTip(); return; }
2092
+ const doc = tipEl.ownerDocument;
2093
+ tipEl.textContent = '';
2094
+ if (title !== '') {
2095
+ const head = doc.createElement('div');
2096
+ head.className = READOUT_TITLE_CLASS;
2097
+ head.textContent = title.slice(0, CHART_NUM.readout.titleMax);
2098
+ tipEl.appendChild(head);
2099
+ }
2100
+ for (const it of tipRows) {
2101
+ const line = doc.createElement('div');
2102
+ line.className = TIP_ROW_CLASS;
2103
+ const dot = appendTipDot(doc, it.swatch);
2104
+ const name = doc.createElement('span');
2105
+ name.className = TIP_NAME_CLASS;
2106
+ name.textContent = it.label;
2107
+ const value = doc.createElement('span');
2108
+ value.className = TIP_VALUE_CLASS;
2109
+ value.textContent = it.value;
2110
+ line.append(dot, name, value);
2111
+ tipEl.appendChild(line);
2112
+ }
2113
+ tipEl.className = kitLevelClassFor(tipEl, TIP_CLASS);
2114
+ placeTip();
2115
+ };
2116
+ const handleChartHoverEvent = (kind: 'hover' | 'click' | 'leave', p: { dataIndex: number; seriesIndex?: number } | null): void => {
2117
+ if (kind === 'hover' && p) showTip(p.dataIndex, p.seriesIndex);
2118
+ else if (kind === 'leave') hideTip();
1359
2119
  if (!interactiveOf(drawn?.config)) return;
1360
- if (kind === 'click') { if (col) pick(col.dataIndex); return; }
2120
+ if (kind === 'click') { if (p) pick(p.dataIndex); return; }
1361
2121
  if (kbdActive) return;
1362
- if (kind === 'hover' && col) setColumn(col.dataIndex, 'pointer');
2122
+ if (kind === 'hover' && p) setColumn(p.dataIndex, 'pointer');
1363
2123
  else if (kind === 'leave') setColumn(defaultCol, 'default');
1364
2124
  };
1365
2125
  const bindColumns = (inst: ChartInstanceLike): void => {
1366
2126
  offColumn?.();
1367
- offColumn = inst.onColumn !== undefined
1368
- ? inst.onColumn(onColumnEvent)
1369
- : inst.onPointer !== undefined ? inst.onPointer(onColumnEvent) : null;
2127
+ const offs: Array<() => void> = [];
2128
+ const hasCol = inst.onColumn !== undefined;
2129
+ const hasPtr = inst.onPointer !== undefined;
2130
+ if (hasCol) {
2131
+ offs.push(inst.onColumn!((kind, col) => {
2132
+ if (KIT_CHART_COLUMN_TYPES.has(drawn?.config.type ?? '')) handleChartHoverEvent(kind, col);
2133
+ }));
2134
+ }
2135
+ if (hasPtr) {
2136
+ offs.push(inst.onPointer!((kind, p) => {
2137
+ if (!hasCol || !KIT_CHART_COLUMN_TYPES.has(drawn?.config.type ?? '')) handleChartHoverEvent(kind, p);
2138
+ }));
2139
+ }
2140
+ offColumn = offs.length > 0 ? () => { for (const fn of offs) fn(); } : null;
2141
+ };
2142
+ const onStagePointerOver = (event: PointerEvent): void => {
2143
+ const el = (event.target as Element | null)?.closest?.(`[${KIT_CHART_ITEM_ATTR}]`);
2144
+ if (!el) return;
2145
+ const idx = Number.parseInt(el.getAttribute(KIT_CHART_ITEM_ATTR) ?? '', 10);
2146
+ if (!Number.isFinite(idx) || idx < 0) return;
2147
+ const sAttr = el.getAttribute(KIT_ATTR_CHART_SERIES);
2148
+ const sIdx = sAttr !== null ? Number.parseInt(sAttr, 10) : undefined;
2149
+ if (root && pointerAt === null) {
2150
+ const box = root.getBoundingClientRect();
2151
+ pointerAt = { x: event.clientX - box.left, y: event.clientY - box.top };
2152
+ }
2153
+ showTip(idx, sIdx !== undefined && Number.isFinite(sIdx) ? sIdx : undefined);
2154
+ };
2155
+ const onStagePointerOut = (event: PointerEvent): void => {
2156
+ const fromEl = (event.target as Element | null)?.closest?.(`[${KIT_CHART_ITEM_ATTR}]`);
2157
+ if (!fromEl) return;
2158
+ const toEl = (event.relatedTarget as Element | null)?.closest?.(`[${KIT_CHART_ITEM_ATTR}]`);
2159
+ if (toEl !== fromEl) hideTip();
1370
2160
  };
1371
2161
  const onKeyDown = (event: KeyboardEvent): void => {
1372
2162
  const d = drawn;
@@ -1406,7 +2196,9 @@ export function createChart(): SomaComponentDefinition {
1406
2196
  readoutEl.className = `${READOUT_CLASS} ${top ? READOUT_TOP_CLASS : READOUT_BOTTOM_CLASS}`;
1407
2197
  readoutEl.setAttribute('aria-hidden', 'true');
1408
2198
  // data-kit-chart-readout:渲染判定 chart.readout.hover 的稳定选择器
1409
- readoutEl.setAttribute('data-kit-chart-readout', '');
2199
+ readoutEl.setAttribute(KIT_ATTR_CHART_READOUT, '');
2200
+ // 读数区是图上方 / 下方的一条摘要带(淡底带),不是浮出层
2201
+ kitMarkLevel(readoutEl, 'band'); kitApplyLevelClass(readoutEl);
1410
2202
  if (top) root.insertBefore(readoutEl, stageWrap); else stageWrap.after(readoutEl);
1411
2203
  }
1412
2204
  if (liveEl && !liveEl.isConnected) root.appendChild(liveEl);
@@ -1445,6 +2237,8 @@ export function createChart(): SomaComponentDefinition {
1445
2237
  const retryLabel = str(p.retry_text);
1446
2238
  const retry = retryLabel !== '' ? (): void => { api.emit('retry', {}); } : null;
1447
2239
  const loading = p.loading === true || p.loading === 'true';
2240
+ // 数据状态自报(每次绘制都写):与面板同一判据——出错 > 加载 > 空;配置 / 引擎问题也按出错报,与下面画错误面板同口径
2241
+ kitMarkDataFacts(root, { error: errorText !== '' || config === null || (rows.length > 0 && portOf() === null), loading: rows.length === 0 && loading, empty: rows.length === 0 });
1448
2242
  if (rows.length === 0 && errorText !== '') { showPanel('error', errorText, { retry, retryLabel }); return; }
1449
2243
  if (rows.length === 0 && loading) { showPanel('loading', str(p.loading_text, kitText('soma.kit.loading', undefined, root))); return; }
1450
2244
  // 配置 / 引擎问题是页面或环境的错,不是「没数据」:按错误态画(无重试)
@@ -1475,6 +2269,7 @@ export function createChart(): SomaComponentDefinition {
1475
2269
  const created = await port.create(stage!, { theme: { color: theme.palette }, ...(locale !== '' ? { locale } : {}) });
1476
2270
  if (!alive) { created.dispose(); return; }
1477
2271
  instance = created;
2272
+ lastOptionSig = null;
1478
2273
  bindColumns(created);
1479
2274
  if (typeof ResizeObserver === 'function') {
1480
2275
  resizeObs = new ResizeObserver(() => instance?.resize());
@@ -1496,7 +2291,11 @@ export function createChart(): SomaComponentDefinition {
1496
2291
  if (!alive || mine !== seq || instance === null) return;
1497
2292
  await port.ensure(requiredSeries, engineComponentsOf(config.type, marked.markLine, marked.extra));
1498
2293
  if (!alive || mine !== seq) return;
1499
- instance.setOption(option, 'replace');
2294
+ const nextSig = optionMergeSignatureOf(config, option);
2295
+ const updateMode: 'merge' | 'replace' = lastOptionSig !== null && lastOptionSig === nextSig ? 'merge' : 'replace';
2296
+ lastOptionSig = nextSig;
2297
+ instance.setOption(option, updateMode);
2298
+ annotateStageSvgItems(stage, config, rows);
1500
2299
  endEngineWait();
1501
2300
  } catch {
1502
2301
  creating = null;
@@ -1509,12 +2308,30 @@ export function createChart(): SomaComponentDefinition {
1509
2308
  attach(rootEl) {
1510
2309
  alive = true;
1511
2310
  root = rootEl;
2311
+ // 新模式:警告 / 危险色降一档由图表在自己宿主上改写两个变量(主题不再按组件名写 Chart,recipes/self-owned);
2312
+ // 写在首次取主题(themeOf(root))之前,根节点继承得到;旧版不写,宿主不变
2313
+ const toned = kitApplyChartTones(api.host);
1512
2314
  stageWrap = find('stageWrap');
1513
2315
  stage = find('stage');
1514
2316
  emptyWrap = find('emptyWrap');
2317
+ // 空 / 加载 / 出错面板与舞台同尺寸叠放,是成块的子内容(子块,含空状态块)
2318
+ if (emptyWrap) { kitMarkLevel(emptyWrap, 'sub'); kitApplyLevelClass(emptyWrap); }
1515
2319
  emptyText = find('emptyText');
2320
+ emptyGrid = find('emptyGrid');
1516
2321
  altWrap = find('altWrap');
1517
2322
  watchScheme();
2323
+ tipEl = rootEl.ownerDocument.createElement('div');
2324
+ tipEl.className = 'hidden';
2325
+ tipEl.setAttribute('aria-hidden', 'true');
2326
+ tipEl.setAttribute(KIT_ATTR_CHART_TIP, '');
2327
+ // 悬停读数气泡 = 浮起(§8.2 气泡)
2328
+ kitMarkLevel(tipEl, 'float'); kitApplyLevelClass(tipEl);
2329
+ rootEl.appendChild(tipEl);
2330
+ const stageHost = stageWrap;
2331
+ stageHost?.addEventListener('pointermove', onPointerMove);
2332
+ stageHost?.addEventListener('pointerover', onStagePointerOver);
2333
+ stageHost?.addEventListener('pointerout', onStagePointerOut);
2334
+ stageHost?.addEventListener('pointerleave', hideTip);
1518
2335
  // 读数区(视觉)与读屏播报区(仅键盘驱动更新):由 kit 自己渲染,位置在 paint 里按 readout.place 摆
1519
2336
  readoutEl = rootEl.ownerDocument.createElement('div');
1520
2337
  readoutEl.className = 'hidden';
@@ -1528,11 +2345,13 @@ export function createChart(): SomaComponentDefinition {
1528
2345
  rootEl.addEventListener('focusout', onFocusOut);
1529
2346
  return () => {
1530
2347
  alive = false;
2348
+ if (toned) kitClearChartTones(api.host);
1531
2349
  rootEl.removeEventListener('keydown', onKeyDown);
1532
2350
  rootEl.removeEventListener('focusin', onFocusIn);
1533
2351
  rootEl.removeEventListener('focusout', onFocusOut);
1534
2352
  offColumn?.();
1535
2353
  offColumn = null;
2354
+ lastOptionSig = null;
1536
2355
  readoutEl?.remove();
1537
2356
  liveEl?.remove();
1538
2357
  readoutEl = null;
@@ -1549,6 +2368,14 @@ export function createChart(): SomaComponentDefinition {
1549
2368
  stage = null;
1550
2369
  emptyWrap = null;
1551
2370
  emptyText = null;
2371
+ emptyGrid = null;
2372
+ stageHost?.removeEventListener('pointermove', onPointerMove);
2373
+ stageHost?.removeEventListener('pointerover', onStagePointerOver);
2374
+ stageHost?.removeEventListener('pointerout', onStagePointerOut);
2375
+ stageHost?.removeEventListener('pointerleave', hideTip);
2376
+ tipEl?.remove();
2377
+ tipEl = null;
2378
+ pointerAt = null;
1552
2379
  altWrap = null;
1553
2380
  };
1554
2381
  },