soma-kit 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (376) hide show
  1. package/README.md +106 -112
  2. package/bin/soma-kit.mjs +32 -2
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +14 -7
  5. package/packs/finance/reconcile-board.ts +5 -2
  6. package/packs/finance/reconcile-desk/compile.ts +3 -2
  7. package/spec/generated/kit-app.schema.json +929 -37
  8. package/spec/generated/kit-page.schema.json +1684 -161
  9. package/spec/kit-grammar.json +1176 -584
  10. package/spec/kit-grammar.schema.json +1971 -393
  11. package/src/app/app-config.ts +449 -347
  12. package/src/app/component-gate.ts +283 -28
  13. package/src/app/compose-apps.ts +79 -8
  14. package/src/app/define-kit-actions.ts +245 -41
  15. package/src/app/define-kit-app.ts +176 -33
  16. package/src/app/define-kit-view.ts +104 -0
  17. package/src/app/dev-diagnostic.ts +5 -0
  18. package/src/app/envelope.ts +1 -161
  19. package/src/app/index.ts +29 -6
  20. package/src/app/kit-view-context.ts +439 -0
  21. package/src/app/notify-renderer.ts +1 -115
  22. package/src/app/paged-list-adapter.ts +1 -240
  23. package/src/app/render-ports.ts +18 -0
  24. package/src/app/server-pages.ts +11 -3
  25. package/src/app/server.ts +530 -103
  26. package/src/app/submit.types.ts +1 -1
  27. package/src/app/theme-endpoint.ts +63 -0
  28. package/src/app/theme-runtime-shared.ts +1 -0
  29. package/src/app/theme-runtime.ts +667 -0
  30. package/src/base/action-busy.ts +103 -6
  31. package/src/base/action-gate.ts +4 -255
  32. package/src/base/action-slots.ts +58 -0
  33. package/src/base/alert.ts +5 -3
  34. package/src/base/anchored-layer.ts +50 -0
  35. package/src/base/avatar.ts +2 -2
  36. package/src/base/button.ts +99 -37
  37. package/src/base/cascader.ts +11 -12
  38. package/src/base/check-core.ts +9 -1
  39. package/src/base/checkbox.ts +2 -1
  40. package/src/base/choice.ts +49 -28
  41. package/src/base/class-candidates.ts +17 -0
  42. package/src/base/color-picker.ts +16 -11
  43. package/src/base/combobox.ts +5 -3
  44. package/src/base/command-palette.ts +10 -6
  45. package/src/base/context-menu.ts +10 -7
  46. package/src/base/countdown.ts +1 -1
  47. package/src/base/date-range.ts +32 -18
  48. package/src/base/date.ts +135 -28
  49. package/src/base/delta.ts +72 -0
  50. package/src/base/divider.ts +2 -2
  51. package/src/base/end-edge.ts +49 -0
  52. package/src/base/fab.ts +12 -5
  53. package/src/base/gap-value.ts +148 -0
  54. package/src/base/hint-tips.ts +170 -0
  55. package/src/base/icons.ts +8 -0
  56. package/src/base/illustrations.ts +94 -0
  57. package/src/base/image.ts +1 -1
  58. package/src/base/index.ts +35 -11
  59. package/src/base/input.ts +42 -13
  60. package/src/base/kbd.ts +3 -1
  61. package/src/base/link.ts +4 -4
  62. package/src/base/listbox-core.ts +56 -35
  63. package/src/base/loading-gate.ts +186 -0
  64. package/src/base/mentions.ts +7 -6
  65. package/src/base/menu-button.ts +28 -12
  66. package/src/base/menu-core.ts +41 -8
  67. package/src/base/motion/aura.ts +2 -2
  68. package/src/base/motion/hover-3d.ts +3 -3
  69. package/src/base/motion/hover-gallery.ts +2 -2
  70. package/src/base/motion/marquee.ts +3 -3
  71. package/src/base/motion/text-rotate.ts +2 -2
  72. package/src/base/number.ts +93 -80
  73. package/src/base/otp.ts +9 -5
  74. package/src/base/overlay-runtime.ts +235 -0
  75. package/src/base/permission-gate.ts +6 -0
  76. package/src/base/popover.ts +48 -16
  77. package/src/base/popup.ts +143 -19
  78. package/src/base/portal-core.ts +4 -0
  79. package/src/base/price-text.ts +2 -2
  80. package/src/base/progress.ts +2 -2
  81. package/src/base/qr-code.ts +4 -4
  82. package/src/base/qty-stepper.ts +14 -8
  83. package/src/base/radio.ts +2 -1
  84. package/src/base/range.ts +21 -4
  85. package/src/base/rating.ts +12 -7
  86. package/src/base/reason-tip.ts +150 -0
  87. package/src/base/segmented.ts +27 -21
  88. package/src/base/select.ts +4 -3
  89. package/src/base/shared.ts +387 -49
  90. package/src/base/state-panel.ts +346 -0
  91. package/src/base/status-tone.ts +27 -0
  92. package/src/base/sticky-edge.ts +116 -0
  93. package/src/base/swap.ts +10 -7
  94. package/src/base/switch.ts +11 -6
  95. package/src/base/tag-input.ts +20 -16
  96. package/src/base/tag.ts +68 -34
  97. package/src/base/text.ts +80 -18
  98. package/src/base/textarea.ts +37 -11
  99. package/src/base/time-picker.ts +18 -13
  100. package/src/base/tree-select.ts +21 -12
  101. package/src/base/trend-tone.ts +9 -0
  102. package/src/base/upload.ts +48 -14
  103. package/src/base/view-transition.ts +77 -0
  104. package/src/base/virtual-list.ts +107 -1
  105. package/src/biz/approval-desk/compile.ts +23 -41
  106. package/src/biz/approval-desk/shell.ts +11 -8
  107. package/src/biz/auth-panel/compile.ts +37 -52
  108. package/src/biz/auth-panel/index.ts +1 -1
  109. package/src/biz/auth-panel/shell.ts +5 -4
  110. package/src/biz/category-crud/compile.ts +23 -37
  111. package/src/biz/category-crud/shell.ts +2 -1
  112. package/src/biz/checkout-page/compile.ts +22 -5
  113. package/src/biz/checkout-page/shell.ts +4 -3
  114. package/src/biz/compose.ts +13 -27
  115. package/src/biz/define.ts +5 -4
  116. package/src/biz/import-wizard/compile.ts +22 -26
  117. package/src/biz/import-wizard/hub.ts +126 -61
  118. package/src/biz/import-wizard/shell.ts +5 -4
  119. package/src/biz/index.ts +3 -3
  120. package/src/biz/landing-page/compile.ts +19 -3
  121. package/src/biz/link/hub.ts +69 -22
  122. package/src/biz/link/shared.ts +127 -119
  123. package/src/biz/master-sub/compile.ts +127 -48
  124. package/src/biz/master-sub/index.ts +5 -2
  125. package/src/biz/master-sub/shell.ts +95 -18
  126. package/src/biz/multi-board/compile.ts +38 -50
  127. package/src/biz/multi-board/index.ts +18 -1
  128. package/src/biz/multi-board/shell.ts +32 -20
  129. package/src/biz/notification-center/compile.ts +21 -33
  130. package/src/biz/notification-center/shell.ts +6 -4
  131. package/src/biz/page-templates/domain-templates.ts +80 -13
  132. package/src/biz/page-templates/result-page/compile.ts +11 -2
  133. package/src/biz/page-templates/result-page/shell.ts +2 -1
  134. package/src/biz/page-templates/shared.ts +34 -36
  135. package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
  136. package/src/biz/record-detail/compile.ts +48 -43
  137. package/src/biz/record-detail/index.ts +11 -1
  138. package/src/biz/record-detail/shell.ts +8 -6
  139. package/src/biz/settings-center/compile.ts +7 -5
  140. package/src/biz/settings-center/shell.ts +6 -4
  141. package/src/biz/shared/action-host.ts +97 -211
  142. package/src/biz/shared/compile-helpers.ts +98 -0
  143. package/src/biz/shared/coordinator.ts +472 -92
  144. package/src/biz/shared/index.ts +13 -2
  145. package/src/biz/shared/object-aliases.ts +154 -0
  146. package/src/biz/shared/overlay-compile.ts +239 -0
  147. package/src/biz/shared/overlay-shell.ts +209 -0
  148. package/src/biz/shared/pipes.ts +50 -31
  149. package/src/biz/shared/remove-wire.ts +14 -0
  150. package/src/biz/shared/runtime-hub.ts +226 -24
  151. package/src/biz/single-form/compile.ts +16 -37
  152. package/src/biz/single-form/shell.ts +4 -3
  153. package/src/biz/standard-crud/compile.ts +72 -255
  154. package/src/biz/standard-crud/shell.ts +21 -99
  155. package/src/biz/step-form/compile.ts +26 -97
  156. package/src/biz/step-form/hub.ts +34 -41
  157. package/src/biz/step-form/shell.ts +5 -5
  158. package/src/biz/types.ts +4 -3
  159. package/src/cli/core-imports.ts +54 -0
  160. package/src/cli/kit-cli.ts +254 -25
  161. package/src/cli/kit-init.ts +227 -0
  162. package/src/cli/layout-cli.ts +167 -0
  163. package/src/cli/migrate/index.ts +10 -0
  164. package/src/cli/migrate/migrate.ts +248 -0
  165. package/src/cli/migrate/text-utils.ts +306 -0
  166. package/src/cli/migrate/theme-map.ts +104 -0
  167. package/src/cli/migrate/ts-rules.ts +235 -0
  168. package/src/cli/migrate/types.ts +95 -0
  169. package/src/cli/migrate/view-skeleton.ts +159 -0
  170. package/src/cli/migrate/yaml-report.ts +376 -0
  171. package/src/cli/migrate/yaml-rules.ts +465 -0
  172. package/src/cli/service-endpoint-check.ts +425 -0
  173. package/src/cli/source-path-check.d.mts +17 -0
  174. package/src/cli/source-path-check.mjs +334 -0
  175. package/src/cli/view-writes.ts +761 -0
  176. package/src/compile/action-host-attach.ts +21 -29
  177. package/src/compile/closed-set.ts +570 -0
  178. package/src/compile/compile-page.ts +267 -76
  179. package/src/compile/component-candidates.ts +13 -2
  180. package/src/compile/hints.ts +30 -1
  181. package/src/compile/index.ts +1 -0
  182. package/src/compile/kit-error.ts +1 -0
  183. package/src/compile/layout-lint/engine.ts +82 -0
  184. package/src/compile/layout-lint/index.ts +55 -0
  185. package/src/compile/layout-lint/rules-composition.ts +218 -0
  186. package/src/compile/layout-lint/rules-form.ts +192 -0
  187. package/src/compile/layout-lint/rules-table.ts +194 -0
  188. package/src/compile/layout-lint/score.ts +52 -0
  189. package/src/compile/layout-lint/types.ts +51 -0
  190. package/src/compile/locate.ts +21 -1
  191. package/src/compile/parse.ts +370 -41
  192. package/src/compile/redirect.ts +6 -2
  193. package/src/compile/remove-guard.ts +10 -7
  194. package/src/compile/styles.ts +63 -2
  195. package/src/compile/types.ts +31 -3
  196. package/src/compile/view-check.ts +284 -0
  197. package/src/data/amount-breakdown.ts +8 -3
  198. package/src/data/anchor-nav.ts +2 -2
  199. package/src/data/approval-flow.ts +3 -3
  200. package/src/data/assignment-picker.ts +92 -55
  201. package/src/data/async-result-panel.ts +111 -9
  202. package/src/data/breadcrumbs.ts +5 -4
  203. package/src/data/calendar.ts +24 -27
  204. package/src/data/carousel.ts +13 -8
  205. package/src/data/chart.ts +183 -44
  206. package/src/data/checklist.ts +20 -7
  207. package/src/data/code-view.ts +12 -6
  208. package/src/data/comment-thread.ts +7 -4
  209. package/src/data/confirm-dialog.ts +81 -18
  210. package/src/data/context-menu.ts +29 -37
  211. package/src/data/d9-util.ts +2 -18
  212. package/src/data/diff.ts +4 -2
  213. package/src/data/dock.ts +3 -3
  214. package/src/data/embed.ts +233 -30
  215. package/src/data/field-mapper.ts +35 -30
  216. package/src/data/flow-editor-contract.ts +8 -1
  217. package/src/data/flow-editor.ts +113 -108
  218. package/src/data/flow-node-options.ts +120 -0
  219. package/src/data/flow-remote-options.ts +0 -103
  220. package/src/data/footer.ts +2 -2
  221. package/src/data/form-draft-registry.ts +2 -4
  222. package/src/data/gantt.ts +19 -19
  223. package/src/data/hero.ts +4 -3
  224. package/src/data/image-viewer.ts +27 -30
  225. package/src/data/index.ts +5 -2
  226. package/src/data/item-list.ts +48 -31
  227. package/src/data/kanban.ts +82 -52
  228. package/src/data/media-grid.ts +20 -20
  229. package/src/data/mega-menu.ts +6 -4
  230. package/src/data/menu-dom.ts +4 -2
  231. package/src/data/menu.ts +47 -15
  232. package/src/data/mockup.ts +10 -6
  233. package/src/data/modal-dialog.ts +49 -25
  234. package/src/data/navbar.ts +12 -7
  235. package/src/data/notice-list.ts +268 -0
  236. package/src/data/notify-renderer.ts +250 -0
  237. package/src/data/object-form.ts +1360 -666
  238. package/src/data/outcome-watch.ts +61 -2
  239. package/src/data/pager.ts +80 -34
  240. package/src/data/permission-matrix.ts +52 -31
  241. package/src/data/permission-tree.ts +71 -44
  242. package/src/data/pricing-table.ts +30 -14
  243. package/src/data/prompt-dialog.ts +124 -194
  244. package/src/data/reaction-bar.ts +83 -92
  245. package/src/data/read-rollback.ts +73 -0
  246. package/src/data/record-card.ts +26 -5
  247. package/src/data/record-picker.ts +104 -55
  248. package/src/data/redirect.ts +32 -32
  249. package/src/data/remote-options.ts +13 -6
  250. package/src/data/request-console.ts +5 -3
  251. package/src/data/resident.ts +2 -1
  252. package/src/data/result-panel.ts +8 -4
  253. package/src/data/rich-text.ts +61 -55
  254. package/src/data/row-editor.ts +362 -76
  255. package/src/data/rule-builder.ts +26 -20
  256. package/src/data/shape-util.ts +27 -9
  257. package/src/data/stat-group.ts +392 -109
  258. package/src/data/static-lazy.ts +1 -0
  259. package/src/data/static-registry.ts +24 -11
  260. package/src/data/steps.ts +10 -5
  261. package/src/data/survey.ts +27 -32
  262. package/src/data/system-switcher.ts +3 -3
  263. package/src/data/text-action-button.ts +17 -0
  264. package/src/data/timeline.ts +19 -8
  265. package/src/data/tour-guide.ts +23 -30
  266. package/src/data/transfer.ts +62 -38
  267. package/src/data/tree-table.ts +152 -78
  268. package/src/data/tree.ts +49 -36
  269. package/src/data/trend-line.ts +6 -24
  270. package/src/data/virtual-rows.ts +133 -82
  271. package/src/data/watermark.ts +2 -2
  272. package/src/data/wrap.ts +63 -38
  273. package/src/data/wrapped-candidates.ts +10 -0
  274. package/src/frames/blank-frame.ts +1 -0
  275. package/src/frames/index.ts +2 -2
  276. package/src/frames/page-bar.ts +26 -24
  277. package/src/frames/page-header.ts +14 -5
  278. package/src/frames/page-status.ts +9 -7
  279. package/src/frames/shared.ts +36 -25
  280. package/src/frames/single-frame.ts +1 -0
  281. package/src/frames/split-frame/shell.ts +6 -6
  282. package/src/frames/split-frame/wiring.ts +2 -2
  283. package/src/frames/tabs-frame/shell.ts +4 -14
  284. package/src/frames/tabs-frame/wiring.ts +5 -8
  285. package/src/frames/top-main-frame.ts +3 -2
  286. package/src/frames/types.ts +13 -2
  287. package/src/frames/workspace-frame/extras.ts +21 -5
  288. package/src/frames/workspace-frame/index.ts +1 -1
  289. package/src/frames/workspace-frame/shell.ts +3 -2
  290. package/src/frames/workspace-frame/state.ts +13 -6
  291. package/src/frames/workspace-frame/view.ts +250 -48
  292. package/src/generated/kit-grammar-runtime.ts +645 -397
  293. package/src/generated/page-origin.ts +0 -11
  294. package/src/i18n/kit-text.ts +84 -29
  295. package/src/i18n/resolve-text-refs.ts +22 -6
  296. package/src/index.ts +2 -1
  297. package/src/object-renderer/action-gate.ts +11 -147
  298. package/src/object-renderer/arrange.ts +112 -84
  299. package/src/object-renderer/collapse-wiring.ts +2 -2
  300. package/src/object-renderer/collection-expand.ts +2 -2
  301. package/src/object-renderer/collection-parts.ts +401 -104
  302. package/src/object-renderer/collection-table.ts +287 -45
  303. package/src/object-renderer/collection.ts +258 -104
  304. package/src/object-renderer/compile-data.ts +112 -102
  305. package/src/object-renderer/crud-bridge.ts +32 -0
  306. package/src/object-renderer/defaults.ts +38 -16
  307. package/src/object-renderer/display-checks.ts +4 -25
  308. package/src/object-renderer/emit-events.ts +224 -176
  309. package/src/object-renderer/emit-object.ts +15 -2
  310. package/src/object-renderer/emit-static.ts +533 -151
  311. package/src/object-renderer/field-value.ts +593 -396
  312. package/src/object-renderer/filter-reload.ts +70 -0
  313. package/src/object-renderer/form-detail.ts +111 -2
  314. package/src/object-renderer/form-notify.ts +45 -0
  315. package/src/object-renderer/index.ts +26 -0
  316. package/src/object-renderer/key-field.ts +12 -0
  317. package/src/object-renderer/layout-facts.ts +386 -0
  318. package/src/object-renderer/layout-plan.ts +132 -0
  319. package/src/object-renderer/layout-plan.types.ts +22 -0
  320. package/src/object-renderer/linkage.ts +7 -270
  321. package/src/object-renderer/merge-class.ts +18 -1
  322. package/src/object-renderer/parts.ts +252 -1
  323. package/src/object-renderer/path-pick.ts +27 -0
  324. package/src/object-renderer/render-object.ts +456 -89
  325. package/src/object-renderer/request-actions.ts +232 -249
  326. package/src/object-renderer/skeleton.ts +58 -19
  327. package/src/object-renderer/table-actions.ts +319 -111
  328. package/src/object-renderer/table-summary.ts +2 -2
  329. package/src/object-renderer/table-tools.ts +429 -94
  330. package/src/object-renderer/types.ts +204 -127
  331. package/src/object-renderer/view-binding.ts +393 -0
  332. package/src/page-target/ai-surface.ts +37 -0
  333. package/src/page-target/compile.ts +48 -8
  334. package/src/page-target/index.ts +8 -1
  335. package/src/page-target/intent-schema.ts +165 -28
  336. package/src/page-target/target.ts +262 -51
  337. package/src/page-target/writer-policy.ts +14 -3
  338. package/src/recipes/container.ts +210 -0
  339. package/src/recipes/control.ts +277 -0
  340. package/src/recipes/index.ts +312 -0
  341. package/src/recipes/nowrap.ts +16 -0
  342. package/src/recipes/overlay.ts +240 -0
  343. package/src/recipes/placeholder.ts +79 -0
  344. package/src/recipes/rail-grid.ts +45 -0
  345. package/src/recipes/slot-align.ts +56 -0
  346. package/src/recipes/state.ts +99 -0
  347. package/src/recipes/status.ts +139 -0
  348. package/src/recipes/surface.ts +40 -0
  349. package/src/recipes/table-row.ts +88 -0
  350. package/src/recipes/title-row.ts +37 -0
  351. package/src/recipes/typography.ts +99 -0
  352. package/src/shared/action-field-guard.ts +41 -0
  353. package/src/shared/confirm-decl.ts +118 -0
  354. package/src/shared/envelope.ts +207 -0
  355. package/src/shared/escape.ts +57 -0
  356. package/src/shared/kit-error.ts +21 -0
  357. package/src/shared/paged-list-adapter.ts +15 -0
  358. package/src/shared/path-guard.ts +127 -0
  359. package/src/shared/theme-runtime-shared.ts +180 -0
  360. package/src/shared/view-info.ts +10 -0
  361. package/src/theme/index.ts +13 -0
  362. package/src/theme/kit-theme-text.ts +1 -1
  363. package/src/theme/kit-theme.css +407 -10
  364. package/src/theme/kit-theme.tpl +407 -10
  365. package/src/theme/nine-dim-structure.ts +247 -0
  366. package/src/theme/surface-layers.ts +101 -0
  367. package/src/theme/theme-tokens.ts +130 -84
  368. package/src/theme/theme-types.ts +103 -0
  369. package/src/theme/typography.ts +17 -17
  370. package/src/biz/shared/step-values.ts +0 -25
  371. package/src/biz/step-form/steps-ref.ts +0 -112
  372. package/src/data/options-bus.ts +0 -24
  373. package/src/object-renderer/adopt-gate.ts +0 -333
  374. package/src/object-renderer/field-policy.ts +0 -89
  375. package/src/object-renderer/outcome-draft.ts +0 -61
  376. package/src/theme/nine-dim-palettes.ts +0 -1473
@@ -0,0 +1,72 @@
1
+ // KitDelta:涨跌标(展示件,单元格内微可视化)。一个数值 -> 箭头 + 绝对值文字,语气由 upIs 决定(涨不一定是绿)。
2
+ // percent(缺省)= value 是比率,0.12 显示 12%(与 StatGroup trendFormat 同一约定、同一格式化函数);number = 按数字格式化。
3
+ // 0 / 非数字:无箭头,灰色;非数字显示 '—'。彩色文字只用 -on-soft 令牌。读屏:文字后跟隐藏的「上升 / 下降」。
4
+
5
+ import type { SomaComponentDefinition } from 'soma-core';
6
+ import { kitLocaleAt, kitText } from '../i18n/kit-text';
7
+ import { kitIcon } from './icons';
8
+ import {
9
+ CLASS_PROP, ID_PROPS, SIZE_PROP,
10
+ classCandidates, createKitController, formatValue, joinClass, num, setAttr, sizeOf, str,
11
+ type KitSize,
12
+ } from './shared';
13
+ import { trendTone, type TrendTone } from './trend-tone';
14
+ import { KIT_DELTA_TEXT } from '../recipes/typography';
15
+
16
+ const ROOT: Readonly<Record<KitSize, string>> = KIT_DELTA_TEXT;
17
+ const TONE_CLASS: Record<TrendTone, string> = {
18
+ good: 'text-success-on-soft',
19
+ bad: 'text-danger-on-soft',
20
+ flat: 'text-fg-muted',
21
+ };
22
+ const SR_ONLY = 'sr-only';
23
+ const EMPTY_TEXT = '—';
24
+
25
+ export const KIT_DELTA_CLASS_CANDIDATES: readonly string[] = classCandidates(
26
+ Object.values(ROOT), Object.values(TONE_CLASS), SR_ONLY,
27
+ );
28
+
29
+ export function createKitDelta(): SomaComponentDefinition {
30
+ return {
31
+ contract: {
32
+ name: 'KitDelta',
33
+ layer: 'basic',
34
+ props: {
35
+ value: { type: 'string', default: '', desc: '涨跌数值(数字或数字串);percent 下是比率(0.12 = 12%);非数字显示 —' },
36
+ format: { type: 'enum', values: ['percent', 'number'], default: 'percent', desc: '显示格式:percent = 比率按百分比,number = 按数字' },
37
+ upIs: { type: 'enum', values: ['good', 'bad'], default: 'good', desc: '涨是好事还是坏事:good 涨绿跌红,bad 涨红跌绿' },
38
+ id: ID_PROPS.id,
39
+ size: SIZE_PROP,
40
+ class: CLASS_PROP,
41
+ },
42
+ emits: {},
43
+ },
44
+ templateHtml: `<span data-soma-id="root" class="${ROOT.md} ${TONE_CLASS.flat}"></span>`,
45
+ controllerFactory: createKitController(() => ({
46
+ render(root, p) {
47
+ const size = sizeOf(p.size);
48
+ const change = num(p.value);
49
+ const upIs = p.upIs === 'bad' ? 'bad' : 'good';
50
+ const format = p.format === 'number' ? 'number' : 'percent';
51
+ const tone: TrendTone = change === null ? 'flat' : trendTone(change, upIs);
52
+ root.textContent = '';
53
+ if (change === null) {
54
+ root.setAttribute('data-kit-trend', 'none');
55
+ root.appendChild(document.createTextNode(EMPTY_TEXT));
56
+ } else {
57
+ root.setAttribute('data-kit-trend', change > 0 ? 'up' : change < 0 ? 'down' : 'flat');
58
+ if (change !== 0) root.appendChild(kitIcon(change > 0 ? 'arrow-up' : 'arrow-down', 'xs'));
59
+ root.appendChild(document.createTextNode(formatValue(Math.abs(change), format, kitLocaleAt(root))));
60
+ if (change !== 0) {
61
+ const sr = document.createElement('span');
62
+ sr.className = SR_ONLY;
63
+ sr.textContent = kitText(change > 0 ? 'soma.kit.delta_up' : 'soma.kit.delta_down', undefined, root);
64
+ root.appendChild(sr);
65
+ }
66
+ }
67
+ setAttr(root, 'id', str(p.id));
68
+ root.className = joinClass(`${ROOT[size]} ${TONE_CLASS[tone]}`, p.class);
69
+ },
70
+ })),
71
+ };
72
+ }
@@ -129,7 +129,7 @@ export function createKitDivider(): SomaComponentDefinition {
129
129
  },
130
130
  },
131
131
  templateHtml: '<div data-soma-id="root" role="separator" class="block w-full border-t border-border-subtle"></div>',
132
- controllerFactory: createKitController({
132
+ controllerFactory: createKitController(() => ({
133
133
  render(root, p) {
134
134
  const plan = dividerPlan(p);
135
135
  const doc = root.ownerDocument;
@@ -151,6 +151,6 @@ export function createKitDivider(): SomaComponentDefinition {
151
151
  b.setAttribute('aria-hidden', 'true');
152
152
  root.append(a, text, b);
153
153
  },
154
- }),
154
+ })),
155
155
  };
156
156
  }
@@ -0,0 +1,49 @@
1
+ // 表壳右侧遮挡标记(量滚动余量,不是版式切换:版式切换走容器查询,不在脚本里量宽度)。
2
+ // 表壳右侧还有被遮住的内容时标 `data-kit-edge-r`,贴右固定的操作格据此出分隔线与阴影;滚动 / 尺寸变化时重算。
3
+
4
+ const EDGES = new WeakMap<HTMLElement, { count: number; stop: () => void }>();
5
+
6
+ /**
7
+ * 表壳右侧是否还有被遮住的内容:有则在表壳上标 `data-kit-edge-r`(贴右固定格据此出分隔线与阴影),没有则去掉;
8
+ * 滚动 / 尺寸变化时重算。同一个表壳上多个订阅者共用一组监听(引用计数)。无 ResizeObserver 时只算一次。
9
+ */
10
+ export function watchEndEdge(el: HTMLElement | null): () => void {
11
+ if (el === null) return () => {};
12
+ const hit = EDGES.get(el);
13
+ if (hit !== undefined) {
14
+ hit.count += 1;
15
+ return () => release(el);
16
+ }
17
+ const apply = (): void => {
18
+ const hidden = el.scrollLeft + el.clientWidth < el.scrollWidth - 1;
19
+ if (hidden) el.setAttribute('data-kit-edge-r', '');
20
+ else el.removeAttribute('data-kit-edge-r');
21
+ };
22
+ apply();
23
+ // 订阅时可能还没布局(量到的宽全是 0):下一帧再算一次
24
+ if (typeof requestAnimationFrame === 'function') requestAnimationFrame(apply);
25
+ el.addEventListener('scroll', apply, { passive: true });
26
+ const ro = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(apply);
27
+ if (ro !== null) {
28
+ ro.observe(el);
29
+ if (el.firstElementChild !== null) ro.observe(el.firstElementChild);
30
+ }
31
+ EDGES.set(el, {
32
+ count: 1,
33
+ stop: () => {
34
+ el.removeEventListener('scroll', apply);
35
+ ro?.disconnect();
36
+ el.removeAttribute('data-kit-edge-r');
37
+ },
38
+ });
39
+ return () => release(el);
40
+ }
41
+
42
+ function release(el: HTMLElement): void {
43
+ const w = EDGES.get(el);
44
+ if (w === undefined) return;
45
+ w.count -= 1;
46
+ if (w.count > 0) return;
47
+ w.stop();
48
+ EDGES.delete(el);
49
+ }
package/src/base/fab.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  } from './shared';
12
12
  import { kitText } from '../i18n/kit-text';
13
13
  import { kitIcon } from './icons';
14
+ import { setKitFixed } from '../recipes';
14
15
  import { menuItemsOf, wireMenu, type MenuClasses, type MenuHandle } from './menu-core';
15
16
  import { KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, popPlaceClass, type PopPlace } from './popup';
16
17
 
@@ -45,7 +46,7 @@ const menuClass = (place: PopPlace): string =>
45
46
  const BACK_TOP_HIDDEN = 'hidden';
46
47
  const BACK_TOP_OFFSET = 200;
47
48
  const MENU_CLASSES: MenuClasses = {
48
- idle: 'flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-full border border-border-subtle bg-surface-raised px-4 py-2 text-sm font-medium text-fg shadow-md transition-colors hover:bg-surface-sunken focus-visible:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
49
+ idle: 'flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-full border border-border-subtle bg-surface-raised px-4 py-2 text-sm font-medium text-fg shadow-md transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
49
50
  danger: 'flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-full border border-border-subtle bg-surface-raised px-4 py-2 text-sm font-medium text-danger-on-soft shadow-md transition-colors hover:bg-danger-soft focus-visible:bg-danger-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
50
51
  disabled: 'flex cursor-not-allowed items-center gap-2 whitespace-nowrap rounded-full border border-border-subtle bg-surface-raised px-4 py-2 text-sm font-medium text-fg-subtle opacity-60',
51
52
  divider: 'hidden',
@@ -85,7 +86,9 @@ function makeView(): KitView {
85
86
  const scrolled = (): boolean => (typeof window === 'undefined' ? 0 : window.scrollY) >= backTopOffsetOf(api.props().back_top_offset);
86
87
  paintRoot = (): void => {
87
88
  const p = api.props();
88
- root.className = bool(p.back_top) && !backTopShown ? BACK_TOP_HIDDEN : joinClass(ROOT_CLASS[placementOf(p.placement)], p.class);
89
+ const hiddenNow = bool(p.back_top) && !backTopShown;
90
+ root.className = hiddenNow ? BACK_TOP_HIDDEN : joinClass(ROOT_CLASS[placementOf(p.placement)], p.class);
91
+ setKitFixed(root, !hiddenNow && placementOf(p.placement) !== 'inline');
89
92
  };
90
93
  const onScroll = (): void => {
91
94
  if (!bool(api.props().back_top)) return;
@@ -104,6 +107,7 @@ function makeView(): KitView {
104
107
  hiddenClass: MENU_HIDDEN,
105
108
  fitted: () => ({ pref: pref(), classFor: menuClass }),
106
109
  classes: MENU_CLASSES,
110
+ rowFace: 'raised',
107
111
  items: () => menuItemsOf(api.props().items),
108
112
  locked: () => bool(api.props().disabled) || !hasItems(),
109
113
  onPick: (item) => api.emit('select', { key: item.key }),
@@ -145,7 +149,10 @@ function makeView(): KitView {
145
149
  if (bool(p.disabled) && handle?.isOpen()) handle.close(false);
146
150
  handle?.sync();
147
151
  if (paintRoot) paintRoot();
148
- else root.className = joinClass(ROOT_CLASS[placementOf(p.placement)], p.class);
152
+ else {
153
+ root.className = joinClass(ROOT_CLASS[placementOf(p.placement)], p.class);
154
+ setKitFixed(root, placementOf(p.placement) !== 'inline');
155
+ }
149
156
  },
150
157
  };
151
158
  }
@@ -186,7 +193,7 @@ export function createFab(): SomaComponentDefinition {
186
193
  click: { payload: {}, desc: '没有动作项时点主按钮' },
187
194
  },
188
195
  },
189
- templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS.inline}"><button type="button" class="${TRIGGER_CLASS.md}"><span aria-hidden="true">+</span></button><div class="${MENU_HIDDEN}"></div></div>`,
190
- controllerFactory: (ctx) => createKitController(withTooltip(makeView(), (root) => root.firstElementChild as HTMLElement))(ctx),
196
+ templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS.inline}"><button type="button" data-kit-face="raised" class="${TRIGGER_CLASS.md}"><span aria-hidden="true">+</span></button><div class="${MENU_HIDDEN}"></div></div>`,
197
+ controllerFactory: createKitController(() => withTooltip(makeView(), (root) => root.firstElementChild as HTMLElement)),
191
198
  };
192
199
  }
@@ -0,0 +1,148 @@
1
+ // GapValue:可缺失的值 + 缺口 / 未知标记(单值展示,layer: basic)。
2
+ //
3
+ // 为什么存在:数据里「没有值」和「值是 0」是两件事。缺值不能画成 0、空白或「-」,要明说「缺口」(本该有、暂时没有)
4
+ // 或「未知」(无法判断),并把原因给读的人。Text 的 placeholder 只有一句固定文字,说不出原因,所以单独一个组件。
5
+ //
6
+ // 边界(展示对象 / 业务对象负责「缺不缺、为什么」,本组件只显示它们说的话):
7
+ // · state 由数据给:auto(缺省,值缺失就按缺口画)/ value / gap / unknown;组件不按业务规则判断 0 算不算缺口;
8
+ // 逐行不同的状态 / 原因由接口放进复合值 { value, state?, reason? }(表格单元格只绑得到「值」一个量);
9
+ // · reason 由数据给:组件不编原因,没给就只画标记、不写原因;
10
+ // · 「值缺失」只是显示层的在场判断:null / undefined / 空白串 / NaN / 空数组。0 与 false 是真实值,照常显示。
11
+ // 画法:有值 = 等宽数字文字(过长截断,完整内容走 tooltip prop);缺口 = 虚线胶囊,未知 = 点线胶囊,胶囊内是图标 + 文字,
12
+ // 不用符号字符,也不靠颜色区分(都是中性色)。非 compact 时原因直接写在胶囊里;compact 时胶囊只有「缺口」/「未知」,
13
+ // 原因走 kit tooltip(hover / 聚焦显示,aria-describedby 指向它),胶囊可键盘聚焦。
14
+ // 格式化复用 formatValue(number / percent / currency:CNY / date / datetime / relative / bytes / duration:s)。
15
+
16
+ import type { SomaComponentDefinition } from 'soma-core';
17
+ import { kitLocaleAt, kitText } from '../i18n/kit-text';
18
+ import { kitIcon } from './icons';
19
+ import { KIT_GAP_PILL, KIT_GAP_PILL_FOCUS, KIT_GAP_TEXT_TRUNCATE, KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES, KIT_GAP_VALUE_TEXT, type KitGapKind } from '../recipes/status';
20
+ import {
21
+ CLASS_PROP, SIZE_PROP, TOOLTIP_PROP,
22
+ bool, createKitController, formatValue, joinClass, sizeOf, str, withTooltip,
23
+ type KitProps, type KitSize, type KitView,
24
+ } from './shared';
25
+
26
+ /** 本组件自带的类(并入基础组件候选类清单) */
27
+ export const KIT_GAP_VALUE_CLASS_CANDIDATES: readonly string[] = KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES;
28
+
29
+ export type GapState = 'auto' | 'value' | 'gap' | 'unknown';
30
+
31
+ export function gapStateOf(raw: unknown): GapState {
32
+ return raw === 'value' || raw === 'gap' || raw === 'unknown' ? raw : 'auto';
33
+ }
34
+
35
+ /** 值是否在场:null / undefined / 空白串 / NaN / 空数组都算缺失;0 与 false 是真实值 */
36
+ export function gapPresent(raw: unknown): boolean {
37
+ if (raw === null || raw === undefined) return false;
38
+ if (typeof raw === 'string') return raw.trim() !== '';
39
+ if (typeof raw === 'number') return Number.isFinite(raw);
40
+ if (Array.isArray(raw)) return raw.length > 0;
41
+ return true;
42
+ }
43
+
44
+ export type GapResolved =
45
+ | { kind: 'value'; text: string }
46
+ | { kind: KitGapKind; reason: string };
47
+
48
+ /** 把 props 归一成展示意图(纯函数,便于单测) */
49
+ export function resolveGap(p: KitProps, locale: string): GapResolved {
50
+ // 复合值 { value, state?, reason? }:表格单元格只绑得到「值」一个量,逐行不同的状态 / 原因由接口放进复合值里(数据给,组件只读);
51
+ // 复合值里写了的优先于同名 prop
52
+ const composite = p.value !== null && typeof p.value === 'object' && !Array.isArray(p.value) && 'value' in (p.value as Record<string, unknown>)
53
+ ? p.value as Record<string, unknown>
54
+ : null;
55
+ const value = composite !== null ? composite.value : p.value;
56
+ const state = composite !== null && composite.state !== undefined ? gapStateOf(composite.state) : gapStateOf(p.state);
57
+ const reason = (composite !== null && typeof composite.reason === 'string' && composite.reason.trim() !== '' ? composite.reason : str(p.reason)).trim();
58
+ if (state === 'gap' || state === 'unknown') return { kind: state, reason };
59
+ // auto / value:值在场才画值;缺失一律按缺口画(绝不画成 0 或空白)
60
+ if (!gapPresent(value)) return { kind: 'gap', reason };
61
+ const text = formatValue(value, str(p.format), locale);
62
+ const unit = str(p.unit).trim();
63
+ return { kind: 'value', text: unit === '' ? text : `${text} ${unit}` };
64
+ }
65
+
66
+ /** 胶囊里的文字:单行,放不下时截断(胶囊本身 max-w-full + 不换行,图标不缩) */
67
+ function gapTextNode(text: string): HTMLElement {
68
+ const span = document.createElement('span');
69
+ span.className = KIT_GAP_TEXT_TRUNCATE;
70
+ span.textContent = text;
71
+ return span;
72
+ }
73
+
74
+ /**
75
+ * 缺口 / 未知标记节点(供数据组件内嵌:StatGroup 项等):虚线 / 点线胶囊 = 图标 + 文字,原因直接写在文字里(reason 空则只有标记)。
76
+ * 只做显示:缺不缺、为什么由调用方(数据)给。
77
+ */
78
+ export function gapMarkerNode(kind: KitGapKind, reason: string, at: Element | null = null, size: KitSize = 'md'): HTMLElement {
79
+ const el = document.createElement('span');
80
+ el.className = KIT_GAP_PILL[kind][size];
81
+ el.setAttribute('data-kit-gap', kind);
82
+ const marker = kitText(kind === 'gap' ? 'soma.kit.gap_marker' : 'soma.kit.gap_unknown_marker', undefined, at);
83
+ const text = reason.trim() !== ''
84
+ ? kitText(kind === 'gap' ? 'soma.kit.gap_with_reason' : 'soma.kit.gap_unknown_with_reason', { reason: reason.trim() }, at)
85
+ : marker;
86
+ el.append(kitIcon(kind === 'gap' ? 'minus' : 'info', 'xs'), gapTextNode(text));
87
+ return el;
88
+ }
89
+
90
+ export function createGapValue(): SomaComponentDefinition {
91
+ return {
92
+ contract: {
93
+ name: 'GapValue',
94
+ layer: 'basic',
95
+ props: {
96
+ value: { type: 'string', default: '', desc: '任意标量;缺失(null / 空串 / NaN)按缺口画,0 与 false 是真实值。也可是复合值 { value, state?, reason? }(接口逐行给出状态与原因,表格单元格只绑得到值这一个量时用),复合值里写了的优先于同名 prop' },
97
+ state: { type: 'enum', values: ['auto', 'value', 'gap', 'unknown'], default: 'auto', desc: '由数据给出的状态:auto = 值在场画值、缺失画缺口;value = 画值(值仍缺失则画缺口);gap = 缺口(本该有、暂时没有);unknown = 未知(无法判断)。组件不按业务规则判断' },
98
+ reason: { type: 'string', default: '', desc: '缺口 / 未知的原因文字(由数据给);空则只画标记、不写原因' },
99
+ format: { type: 'string', default: '', desc: '同 Text.format:number / percent / currency:CNY / date / datetime / relative / bytes / duration:s' },
100
+ unit: { type: 'string', default: '', desc: '追加在值后的单位文字' },
101
+ locale: { type: 'string', default: '', desc: '格式化语言;缺省取页面语言(page.locale),都没声明为 zh-CN' },
102
+ compact: { type: 'boolean', default: false, desc: '缺口 / 未知时胶囊只画「缺口」/「未知」,原因走 tooltip(可键盘聚焦读到),用于窄的表格单元格' },
103
+ tooltip: TOOLTIP_PROP,
104
+ size: SIZE_PROP,
105
+ class: CLASS_PROP,
106
+ },
107
+ },
108
+ templateHtml: `<span data-soma-id="root" class="${KIT_GAP_VALUE_TEXT.md}"></span>`,
109
+ controllerFactory: createKitController((api) => {
110
+ // 缺口 / 未知的原因要经 tooltip 展示(compact):先算出展示意图,再把派生的 tooltip 交给 withTooltip
111
+ let current: GapResolved = { kind: 'value', text: '' };
112
+ const inner = withTooltip((): KitView => ({
113
+ render(root, p) {
114
+ const size = sizeOf(p.size);
115
+ const r = current;
116
+ root.setAttribute('data-kit-gap', r.kind);
117
+ if (r.kind === 'value') {
118
+ root.className = joinClass(KIT_GAP_VALUE_TEXT[size], p.class);
119
+ root.removeAttribute('tabindex');
120
+ root.textContent = r.text;
121
+ return;
122
+ }
123
+ const compact = bool(p.compact);
124
+ const marker = kitText(r.kind === 'gap' ? 'soma.kit.gap_marker' : 'soma.kit.gap_unknown_marker', undefined, root);
125
+ const text = !compact && r.reason !== ''
126
+ ? kitText(r.kind === 'gap' ? 'soma.kit.gap_with_reason' : 'soma.kit.gap_unknown_with_reason', { reason: r.reason }, root)
127
+ : marker;
128
+ // compact 且有原因:胶囊可聚焦(键盘用户靠焦点读到 tooltip)
129
+ const focusable = compact && r.reason !== '';
130
+ root.className = joinClass(focusable ? `${KIT_GAP_PILL[r.kind][size]} ${KIT_GAP_PILL_FOCUS}` : KIT_GAP_PILL[r.kind][size], p.class);
131
+ if (focusable) root.setAttribute('tabindex', '0');
132
+ else root.removeAttribute('tabindex');
133
+ root.replaceChildren(kitIcon(r.kind === 'gap' ? 'minus' : 'info', 'xs'), gapTextNode(text));
134
+ },
135
+ }));
136
+ const view = inner(api);
137
+ return {
138
+ attach: (root, a) => view.attach?.(root, a),
139
+ render(root, p, a) {
140
+ current = resolveGap(p, str(p.locale, kitLocaleAt(root) || 'zh-CN'));
141
+ // tooltip:缺口 / 未知 compact 时取原因;其余沿用页面给的 tooltip
142
+ const tooltip = current.kind !== 'value' && bool(p.compact) && current.reason !== '' ? current.reason : str(p.tooltip);
143
+ return view.render(root, { ...p, tooltip }, a);
144
+ },
145
+ };
146
+ }),
147
+ };
148
+ }
@@ -0,0 +1,170 @@
1
+ // 按需提示(hint-tips):两类悬停 / 聚焦气泡共用一份「事件委托 + 按需挂载」实现,不 import 任何控制器,只靠标记属性认人。
2
+ //
3
+ // 1. 说明气泡(J9):字段 `help` 在只读容器(列表列头、摘要 / 描述标签旁)里显示成小「i」图标钮(`kitHelpButton` / `kitHelpButtonHtml`,
4
+ // 标记 `data-kit-help="<说明文字>"`)。悬停 / 聚焦时才建气泡(kitTooltip:role=tooltip、aria-describedby、Esc 只关提示)。
5
+ // 列头 / 标签各一个图标钮(一个 Tab 停靠点),行内容里没有;没有 help 的列不出任何节点,布局不位移。
6
+ // 2. 截断提示(J10):被截断的文字才有全文提示。表头 / 表格单元(`[data-kit-ellipsis]`、`.truncate`)与摘要 / 描述值,
7
+ // 都只在悬停 / 聚焦到它时量一次 `scrollWidth > clientWidth`:截断了才挂 kitTooltip,没截断不挂(已挂过但不再截断的摘掉)。
8
+ // 不观察每个单元格(大表 / 虚拟表的行会被整批换掉,常驻观察器要么泄漏要么白费),也不给单元格加 Tab 停靠点;
9
+ // 全文始终在 DOM 里(截断只是视觉),读屏不受影响;键盘用户到得了的元素(排序钮、链接、可编辑格)聚焦时同样触发。
10
+ // 作用范围 = 最近的 `[data-kit-tips]` 祖先(表格外壳、表头、摘要 / 描述的格都带),范围外的 truncate 不碰。
11
+ //
12
+ // 委托挂在文档上(pointerover / focusin,捕获阶段,每文档装一次,经控制器挂载钩子保证有 kit 组件的页面都有);
13
+ // 也可对任一元素 / 文档显式 `bindHintTips`(应用组件、测试用)。原生 `title=` 不再用于截断文字(见 table-tools 的单元格接线)。
14
+
15
+ import { hasReasonTip, kitTooltip, releaseReasonTip, showReasonTip } from './reason-tip';
16
+ import { kitIcon, kitIconHtml } from './icons';
17
+ import { onKitControllerMount } from './shared';
18
+ import { kitText } from '../i18n/kit-text';
19
+ import { esc } from '../shared/escape';
20
+ import { KIT_PART_ATTRIBUTE, KIT_PART_TABLE_HEAD, kitHelpTriggerRecipe } from '../recipes';
21
+
22
+ /** 提示作用范围标记:截断判定只在带它的祖先之内(表格外壳 / 表头 / 摘要或描述的格) */
23
+ export const KIT_TIPS_SCOPE_ATTR = 'data-kit-tips';
24
+ /** 说明气泡触发钮标记,值 = 说明文字 */
25
+ export const KIT_HELP_ATTR = 'data-kit-help';
26
+ /** 悬停提示标记,值 = 提示文字(不进可见文字,如错误态里被拆下来的状态码;原生 title 不用) */
27
+ export const KIT_TIP_ATTR = 'data-kit-tip';
28
+
29
+ const TRUNCATABLE = '[data-kit-ellipsis], .truncate';
30
+ /** 取整误差:scrollWidth / clientWidth 都是取整值,相差 1 以内不算截断 */
31
+ const ROUNDING_PX = 1;
32
+
33
+ /** 文字是否被截断(单行省略的横向溢出) */
34
+ export function isTextTruncated(el: HTMLElement): boolean {
35
+ return el.scrollWidth > el.clientWidth + ROUNDING_PX;
36
+ }
37
+
38
+ /** 元素里用户看得见的文字:去掉我们自己塞进去的气泡占位与说明图标钮 */
39
+ export function visibleTextOf(el: HTMLElement): string {
40
+ const clone = el.cloneNode(true) as HTMLElement;
41
+ clone.querySelectorAll(`[role="tooltip"], [${KIT_HELP_ATTR}]`).forEach((n) => n.remove());
42
+ return (clone.textContent ?? '').replace(/\s+/g, ' ').trim();
43
+ }
44
+
45
+ // ── 说明图标钮 ───────────────────────────────────────────────
46
+
47
+ /** 说明图标钮的读屏名:「<字段名>说明」 */
48
+ function helpLabel(label: string, at: Element | string | null | undefined): string {
49
+ return kitText('soma.kit.help_of', { label }, at);
50
+ }
51
+
52
+ /** DOM 版(表头重绘用):小「i」图标钮,悬停 / 聚焦才挂气泡(委托);text 为空返回 null */
53
+ export function kitHelpButton(doc: Document, text: string, label: string, at?: Element | string | null): HTMLButtonElement | null {
54
+ const help = text.trim();
55
+ if (help === '') return null;
56
+ const btn = doc.createElement('button');
57
+ btn.setAttribute('type', 'button');
58
+ btn.setAttribute(KIT_HELP_ATTR, help);
59
+ btn.setAttribute('aria-label', helpLabel(label, at));
60
+ btn.className = kitHelpTriggerRecipe();
61
+ btn.appendChild(kitIcon('info', 'sm'));
62
+ return btn;
63
+ }
64
+
65
+ /** HTML 版(静态发射:摘要标签旁、静态表头);text 为空返回 '' */
66
+ export function kitHelpButtonHtml(text: string, label: string, at?: Element | string | null): string {
67
+ const help = text.trim();
68
+ if (help === '') return '';
69
+ return `<button type="button" ${KIT_HELP_ATTR}="${esc(help)}" aria-label="${esc(helpLabel(label, at))}" class="${kitHelpTriggerRecipe()}">${kitIconHtml('info', 'sm')}</button>`;
70
+ }
71
+
72
+ // ── 委托 ─────────────────────────────────────────────────────
73
+
74
+ /** 我们挂的提示锚点(别人挂的——置灰原因、Button 的 tooltip——不碰) */
75
+ const OWNED = new WeakSet<HTMLElement>();
76
+
77
+ function attach(anchor: HTMLElement, text: string, inside: boolean): void {
78
+ if (hasReasonTip(anchor) && !OWNED.has(anchor)) return;
79
+ const had = hasReasonTip(anchor);
80
+ kitTooltip(anchor, text, { inside });
81
+ OWNED.add(anchor);
82
+ // 触发它的悬停 / 聚焦事件已经过去,新挂的监听接不到:补一次显示
83
+ if (!had) showReasonTip(anchor);
84
+ }
85
+
86
+ function releaseOwned(anchor: HTMLElement): void {
87
+ if (!OWNED.has(anchor)) return;
88
+ OWNED.delete(anchor);
89
+ releaseReasonTip(anchor);
90
+ }
91
+
92
+ /**
93
+ * 提示锚点:排序表头里文字在排序钮里,提示挂在排序钮上(键盘聚焦到的是它);其余就是被量的元素本身。
94
+ * 气泡占位放哪:表头与带 data-kit-ellipsis 的单元格放进元素里面(它们的子节点不归某个组件整块重写);
95
+ * 其余(Text 等组件的值节点,组件每次渲染会整个重写它的文字)放在它的后面,免得占位被冲掉。
96
+ */
97
+ function anchorOf(el: HTMLElement): HTMLElement {
98
+ return el.querySelector<HTMLElement>('[data-kit-sort]') ?? el;
99
+ }
100
+ function insideOf(el: HTMLElement): boolean {
101
+ return el.hasAttribute('data-kit-ellipsis') || el.closest(`[${KIT_PART_ATTRIBUTE}="${KIT_PART_TABLE_HEAD}"]`) !== null;
102
+ }
103
+
104
+ function onTruncatable(start: Element): void {
105
+ const scope = start.closest(`[${KIT_TIPS_SCOPE_ATTR}]`);
106
+ if (scope === null) return;
107
+ // 从事件目标往上走到作用范围:第一个真被截断的元素拿提示(嵌套时最内层的先量)
108
+ for (let cur: Element | null = start; cur !== null; cur = cur === scope ? null : cur.parentElement) {
109
+ if (!cur.matches(TRUNCATABLE) || cur.getAttribute('role') === 'tooltip') continue;
110
+ const el = cur as HTMLElement;
111
+ const anchor = anchorOf(el);
112
+ if (isTextTruncated(el)) {
113
+ const text = visibleTextOf(el);
114
+ if (text === '') continue;
115
+ attach(anchor, text, insideOf(el));
116
+ return;
117
+ }
118
+ releaseOwned(anchor);
119
+ }
120
+ }
121
+
122
+ function onHelp(btn: HTMLElement): void {
123
+ const text = (btn.getAttribute(KIT_HELP_ATTR) ?? '').trim();
124
+ if (text === '') return;
125
+ attach(btn, text, true);
126
+ }
127
+
128
+ function handle(event: Event): void {
129
+ const target = event.target as Node | null;
130
+ const start = target === null ? null : target.nodeType === 1 ? (target as Element) : target.parentElement;
131
+ if (start === null) return;
132
+ const help = start.closest<HTMLElement>(`[${KIT_HELP_ATTR}]`);
133
+ if (help !== null) {
134
+ onHelp(help);
135
+ return;
136
+ }
137
+ const tip = start.closest<HTMLElement>(`[${KIT_TIP_ATTR}]`);
138
+ if (tip !== null) {
139
+ const text = (tip.getAttribute(KIT_TIP_ATTR) ?? '').trim();
140
+ if (text !== '') {
141
+ attach(tip, text, false);
142
+ return;
143
+ }
144
+ }
145
+ if (start.closest(`[${KIT_TIPS_SCOPE_ATTR}]`) !== null) onTruncatable(start);
146
+ }
147
+
148
+ const BOUND = new WeakSet<EventTarget>();
149
+
150
+ /**
151
+ * 在文档或某个元素上装委托(幂等:同一对象只装一次,重复调用返回空函数)。
152
+ * 返回卸载函数(只摘委托,已挂的气泡随各自锚点的重绘 / `releaseReasonTipsIn` 清理)。
153
+ */
154
+ export function bindHintTips(scope: Document | HTMLElement): () => void {
155
+ if (BOUND.has(scope)) return () => {};
156
+ BOUND.add(scope);
157
+ scope.addEventListener('pointerover', handle, true);
158
+ scope.addEventListener('focusin', handle, true);
159
+ return () => {
160
+ BOUND.delete(scope);
161
+ scope.removeEventListener('pointerover', handle, true);
162
+ scope.removeEventListener('focusin', handle, true);
163
+ };
164
+ }
165
+
166
+ // 每个 kit 组件挂载时确保所在文档装过委托(一页只装一次)
167
+ onKitControllerMount((host) => {
168
+ const doc = host.ownerDocument;
169
+ if (doc !== null && doc !== undefined) bindHintTips(doc);
170
+ });
package/src/base/icons.ts CHANGED
@@ -50,6 +50,14 @@ const PATHS = {
50
50
  loading: 'M8 2.5a5.5 5.5 0 1 0 5.5 5.5',
51
51
  refresh: 'M13 8a5 5 0 1 1-1.5-3.5L13 6M13 3v3h-3',
52
52
  undo: 'M3 6h6a3.5 3.5 0 0 1 0 7H6M5.5 3.5L3 6l2.5 2.5',
53
+ // 后台导航常用(首页 / 用户 / 角色组 / 授权钥匙 / 安全 / 文档 / AI 生成)
54
+ home: 'M2.5 7.5L8 3l5.5 4.5M4 6.5v7h8v-7M6.5 13.5v-3.5h3v3.5',
55
+ user: 'M8 2.5a2.75 2.75 0 1 0 0 5.5 2.75 2.75 0 1 0 0-5.5zM3 13.5c.6-2.5 2.6-4 5-4s4.4 1.5 5 4',
56
+ users: 'M6 3a2.3 2.3 0 1 0 0 4.6A2.3 2.3 0 1 0 6 3zM1.8 13c.5-2.2 2.2-3.6 4.2-3.6s3.7 1.4 4.2 3.6M10.6 3.2a2.2 2.2 0 0 1 0 4.2M11.6 9.6c1.4.5 2.4 1.7 2.7 3.4',
57
+ key: 'M5.5 7a3 3 0 1 0 0 6 3 3 0 1 0 0-6zM7.6 7.9L13.5 2M11 4.5l2 2',
58
+ shield: 'M8 2l5 2v4c0 3-2.2 5.2-5 6-2.8-.8-5-3-5-6V4z',
59
+ file: 'M4 2.5h5l3 3v8H4zM9 2.5v3h3M6 9h4M6 11h4',
60
+ sparkles: 'M7 2.5l1.1 3.4 3.4 1.1-3.4 1.1L7 11.5 5.9 8.1 2.5 7l3.4-1.1zM12 10l.6 1.4 1.4.6-1.4.6-.6 1.4-.6-1.4-1.4-.6 1.4-.6z',
53
61
  } as const;
54
62
 
55
63
  export type KitIconName = keyof typeof PATHS;
@@ -0,0 +1,94 @@
1
+ // 空态 / 错误态插画:两层矢量(柔色底形 + 线稿),颜色只走调色板令牌类(fill-* / stroke-*),随 72 组调色板自动换色。
2
+ // 几何靠 SVG 属性(viewBox 固定 0 0 120 80),无内联样式、无裸色值;纯装饰:aria-hidden + focusable=false。
3
+
4
+ const SVG_NS = 'http://www.w3.org/2000/svg';
5
+ const ROOT_CLASS = 'h-20 w-28 shrink-0';
6
+ const ROOT_CLASS_SM = 'h-14 w-20 shrink-0';
7
+ const BACK_EMPTY = 'fill-primary-soft';
8
+ const BACK_ERROR = 'fill-danger-soft';
9
+ const LINE_EMPTY = 'fill-none stroke-primary stroke-2';
10
+ const LINE_ERROR = 'fill-none stroke-danger stroke-2';
11
+ // 新增三态:未就绪沿用空态的主色调(还没到点,不是出了问题);上游断供用警示色;无权限用中性色(不暗示「出错」)
12
+ const BACK_NOT_READY = BACK_EMPTY;
13
+ const LINE_NOT_READY = LINE_EMPTY;
14
+ const BACK_UPSTREAM = 'fill-warning-soft';
15
+ const LINE_UPSTREAM = 'fill-none stroke-warning stroke-2';
16
+ const BACK_DENIED = 'fill-surface-sunken';
17
+ const LINE_DENIED = 'fill-none stroke-fg-muted stroke-2';
18
+
19
+ export type KitIllustrationKind = 'empty' | 'error' | 'not_ready' | 'upstream_broken' | 'denied';
20
+ /** md = 默认(空态 / 未就绪等);sm = 紧凑(错误态:错误盒要小而平静,插画只占 3.5rem 高) */
21
+ export type KitIllustrationSize = 'md' | 'sm';
22
+
23
+ export const KIT_ILLUSTRATION_CLASS_CANDIDATES: readonly string[] = Object.freeze([...new Set(
24
+ [
25
+ ROOT_CLASS, ROOT_CLASS_SM,BACK_EMPTY, BACK_ERROR, LINE_EMPTY, LINE_ERROR,
26
+ BACK_NOT_READY, LINE_NOT_READY, BACK_UPSTREAM, LINE_UPSTREAM, BACK_DENIED, LINE_DENIED,
27
+ ].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')),
28
+ )].sort());
29
+
30
+ const LOOK: Readonly<Record<KitIllustrationKind, { back: string; line: string }>> = Object.freeze({
31
+ empty: { back: BACK_EMPTY, line: LINE_EMPTY },
32
+ error: { back: BACK_ERROR, line: LINE_ERROR },
33
+ not_ready: { back: BACK_NOT_READY, line: LINE_NOT_READY },
34
+ upstream_broken: { back: BACK_UPSTREAM, line: LINE_UPSTREAM },
35
+ denied: { back: BACK_DENIED, line: LINE_DENIED },
36
+ });
37
+
38
+ function node(doc: Document, tag: string, attrs: Record<string, string>): SVGElement {
39
+ const el = doc.createElementNS(SVG_NS, tag);
40
+ for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, v);
41
+ return el as SVGElement;
42
+ }
43
+
44
+ /**
45
+ * 构造插画:empty = 敞口托盘 + 几条内容线;error = 文档 + 感叹号;
46
+ * not_ready = 时钟;upstream_broken = 两个断开的插头;denied = 挂锁。
47
+ */
48
+ export function kitIllustration(doc: Document, kind: KitIllustrationKind, size: KitIllustrationSize = 'md'): SVGSVGElement {
49
+ const svg = doc.createElementNS(SVG_NS, 'svg') as SVGSVGElement;
50
+ svg.setAttribute('viewBox', '0 0 120 80');
51
+ svg.setAttribute('class', size === 'sm' ? ROOT_CLASS_SM : ROOT_CLASS);
52
+ svg.setAttribute('aria-hidden', 'true');
53
+ svg.setAttribute('focusable', 'false');
54
+ const look = LOOK[kind];
55
+ const line = (el: SVGElement): SVGElement => {
56
+ el.setAttribute('class', look.line);
57
+ el.setAttribute('stroke-linecap', 'round');
58
+ el.setAttribute('stroke-linejoin', 'round');
59
+ return el;
60
+ };
61
+ if (kind === 'not_ready') {
62
+ svg.appendChild(node(doc, 'ellipse', { cx: '60', cy: '40', rx: '48', ry: '32', class: look.back }));
63
+ svg.appendChild(line(node(doc, 'circle', { cx: '60', cy: '40', r: '22' })));
64
+ svg.appendChild(line(node(doc, 'path', { d: 'M60 26 V40 L70 46' })));
65
+ return svg;
66
+ }
67
+ if (kind === 'upstream_broken') {
68
+ svg.appendChild(node(doc, 'ellipse', { cx: '60', cy: '40', rx: '48', ry: '32', class: look.back }));
69
+ svg.appendChild(line(node(doc, 'path', { d: 'M18 40 H36 M36 30 V50 M36 34 H46 M36 46 H46' })));
70
+ svg.appendChild(line(node(doc, 'path', { d: 'M102 40 H84 M84 30 V50 M84 34 H74 M84 46 H74' })));
71
+ svg.appendChild(line(node(doc, 'path', { d: 'M56 32 L62 40 L56 48' })));
72
+ return svg;
73
+ }
74
+ if (kind === 'denied') {
75
+ svg.appendChild(node(doc, 'ellipse', { cx: '60', cy: '40', rx: '48', ry: '32', class: look.back }));
76
+ svg.appendChild(line(node(doc, 'path', { d: 'M44 42 a4 4 0 0 1 4 -4 H72 a4 4 0 0 1 4 4 V60 a4 4 0 0 1 -4 4 H48 a4 4 0 0 1 -4 -4 Z' })));
77
+ svg.appendChild(line(node(doc, 'path', { d: 'M50 38 V30 a10 10 0 0 1 20 0 V38' })));
78
+ svg.appendChild(line(node(doc, 'path', { d: 'M60 48 V54' })));
79
+ return svg;
80
+ }
81
+ if (kind === 'empty') {
82
+ svg.appendChild(node(doc, 'ellipse', { cx: '60', cy: '40', rx: '48', ry: '32', class: BACK_EMPTY }));
83
+ svg.appendChild(line(node(doc, 'path', { d: 'M30 44 L42 28 H78 L90 44 V60 a4 4 0 0 1 -4 4 H34 a4 4 0 0 1 -4 -4 Z' })));
84
+ svg.appendChild(line(node(doc, 'path', { d: 'M30 44 H48 a4 4 0 0 0 4 4 H68 a4 4 0 0 0 4 -4 H90' })));
85
+ svg.appendChild(line(node(doc, 'path', { d: 'M50 18 V12 M60 16 V8 M70 18 V12' })));
86
+ } else {
87
+ svg.appendChild(node(doc, 'ellipse', { cx: '60', cy: '40', rx: '48', ry: '32', class: BACK_ERROR }));
88
+ svg.appendChild(line(node(doc, 'path', { d: 'M44 14 H70 L82 26 V64 a4 4 0 0 1 -4 4 H44 a4 4 0 0 1 -4 -4 V18 a4 4 0 0 1 4 -4 Z' })));
89
+ svg.appendChild(line(node(doc, 'path', { d: 'M70 14 V26 H82' })));
90
+ svg.appendChild(line(node(doc, 'path', { d: 'M61 34 V50' })));
91
+ svg.appendChild(line(node(doc, 'path', { d: 'M61 58 V58.5' })));
92
+ }
93
+ return svg;
94
+ }
package/src/base/image.ts CHANGED
@@ -172,6 +172,6 @@ export function createImage(): SomaComponentDefinition {
172
172
  },
173
173
  },
174
174
  templateHtml: `<span data-soma-id="root" class="${ROOT_BASE}"></span>`,
175
- controllerFactory: (ctx) => createKitController(makeView())(ctx),
175
+ controllerFactory: createKitController(() => makeView()),
176
176
  };
177
177
  }