soma-kit 0.1.10 → 0.1.12

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 (302) hide show
  1. package/README.md +103 -110
  2. package/bin/soma-kit.mjs +1 -1
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +13 -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 +776 -38
  8. package/spec/generated/kit-page.schema.json +1613 -224
  9. package/spec/kit-grammar.json +770 -529
  10. package/spec/kit-grammar.schema.json +1962 -392
  11. package/src/app/app-config.ts +371 -347
  12. package/src/app/component-gate.ts +12 -15
  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 +174 -31
  16. package/src/app/define-kit-view.ts +100 -0
  17. package/src/app/envelope.ts +1 -161
  18. package/src/app/index.ts +13 -2
  19. package/src/app/kit-view-context.ts +290 -0
  20. package/src/app/notify-renderer.ts +1 -115
  21. package/src/app/paged-list-adapter.ts +1 -240
  22. package/src/app/server-pages.ts +8 -2
  23. package/src/app/server.ts +491 -101
  24. package/src/app/submit.types.ts +1 -1
  25. package/src/app/theme-endpoint.ts +63 -0
  26. package/src/app/theme-runtime-shared.ts +1 -0
  27. package/src/app/theme-runtime.ts +663 -0
  28. package/src/base/action-busy.ts +2 -2
  29. package/src/base/action-gate.ts +4 -255
  30. package/src/base/action-slots.ts +47 -0
  31. package/src/base/alert.ts +5 -3
  32. package/src/base/avatar.ts +2 -2
  33. package/src/base/button.ts +46 -29
  34. package/src/base/cascader.ts +11 -12
  35. package/src/base/check-core.ts +1 -1
  36. package/src/base/choice.ts +28 -26
  37. package/src/base/class-candidates.ts +17 -0
  38. package/src/base/color-picker.ts +6 -6
  39. package/src/base/combobox.ts +5 -3
  40. package/src/base/command-palette.ts +9 -5
  41. package/src/base/countdown.ts +1 -1
  42. package/src/base/date-range.ts +25 -11
  43. package/src/base/date.ts +85 -17
  44. package/src/base/divider.ts +2 -2
  45. package/src/base/fab.ts +11 -4
  46. package/src/base/image.ts +1 -1
  47. package/src/base/index.ts +9 -3
  48. package/src/base/input.ts +42 -13
  49. package/src/base/kbd.ts +3 -1
  50. package/src/base/link.ts +4 -4
  51. package/src/base/listbox-core.ts +50 -30
  52. package/src/base/loading-gate.ts +133 -0
  53. package/src/base/mentions.ts +5 -5
  54. package/src/base/menu-button.ts +6 -1
  55. package/src/base/menu-core.ts +4 -0
  56. package/src/base/motion/aura.ts +2 -2
  57. package/src/base/motion/hover-3d.ts +2 -2
  58. package/src/base/motion/hover-gallery.ts +2 -2
  59. package/src/base/motion/marquee.ts +2 -2
  60. package/src/base/motion/text-rotate.ts +2 -2
  61. package/src/base/number.ts +93 -80
  62. package/src/base/otp.ts +4 -1
  63. package/src/base/permission-gate.ts +6 -0
  64. package/src/base/popover.ts +40 -8
  65. package/src/base/popup.ts +79 -14
  66. package/src/base/price-text.ts +2 -2
  67. package/src/base/progress.ts +2 -2
  68. package/src/base/qr-code.ts +4 -4
  69. package/src/base/qty-stepper.ts +9 -3
  70. package/src/base/range.ts +2 -2
  71. package/src/base/rating.ts +1 -1
  72. package/src/base/segmented.ts +4 -0
  73. package/src/base/select.ts +4 -3
  74. package/src/base/shared.ts +221 -29
  75. package/src/base/swap.ts +4 -1
  76. package/src/base/switch.ts +1 -1
  77. package/src/base/tag-input.ts +14 -10
  78. package/src/base/tag.ts +5 -1
  79. package/src/base/text.ts +39 -6
  80. package/src/base/textarea.ts +37 -11
  81. package/src/base/time-picker.ts +12 -9
  82. package/src/base/tree-select.ts +15 -8
  83. package/src/base/upload.ts +34 -5
  84. package/src/base/virtual-list.ts +107 -1
  85. package/src/biz/approval-desk/compile.ts +23 -41
  86. package/src/biz/auth-panel/compile.ts +37 -52
  87. package/src/biz/auth-panel/index.ts +1 -1
  88. package/src/biz/category-crud/compile.ts +22 -36
  89. package/src/biz/checkout-page/compile.ts +21 -5
  90. package/src/biz/compose.ts +13 -27
  91. package/src/biz/define.ts +5 -4
  92. package/src/biz/import-wizard/compile.ts +22 -26
  93. package/src/biz/import-wizard/hub.ts +126 -61
  94. package/src/biz/import-wizard/shell.ts +3 -3
  95. package/src/biz/index.ts +3 -3
  96. package/src/biz/landing-page/compile.ts +19 -3
  97. package/src/biz/link/hub.ts +49 -20
  98. package/src/biz/link/shared.ts +115 -118
  99. package/src/biz/master-sub/compile.ts +31 -44
  100. package/src/biz/multi-board/compile.ts +34 -49
  101. package/src/biz/multi-board/index.ts +18 -1
  102. package/src/biz/multi-board/shell.ts +24 -15
  103. package/src/biz/notification-center/compile.ts +21 -33
  104. package/src/biz/page-templates/domain-templates.ts +80 -13
  105. package/src/biz/page-templates/result-page/compile.ts +11 -2
  106. package/src/biz/page-templates/shared.ts +34 -36
  107. package/src/biz/record-detail/compile.ts +47 -42
  108. package/src/biz/record-detail/index.ts +11 -1
  109. package/src/biz/settings-center/compile.ts +6 -5
  110. package/src/biz/shared/action-host.ts +91 -211
  111. package/src/biz/shared/compile-helpers.ts +80 -0
  112. package/src/biz/shared/coordinator.ts +486 -83
  113. package/src/biz/shared/index.ts +8 -2
  114. package/src/biz/shared/overlay-shell.ts +80 -0
  115. package/src/biz/shared/pipes.ts +43 -30
  116. package/src/biz/shared/remove-key.ts +6 -0
  117. package/src/biz/shared/remove-wire.ts +29 -0
  118. package/src/biz/shared/runtime-hub.ts +216 -24
  119. package/src/biz/single-form/compile.ts +15 -37
  120. package/src/biz/standard-crud/compile.ts +62 -107
  121. package/src/biz/standard-crud/shell.ts +16 -66
  122. package/src/biz/step-form/compile.ts +26 -97
  123. package/src/biz/step-form/hub.ts +34 -41
  124. package/src/biz/types.ts +4 -3
  125. package/src/cli/core-imports.ts +54 -0
  126. package/src/cli/kit-cli.ts +130 -26
  127. package/src/cli/kit-init.ts +222 -0
  128. package/src/cli/service-endpoint-check.ts +425 -0
  129. package/src/cli/source-path-check.d.mts +17 -0
  130. package/src/cli/source-path-check.mjs +334 -0
  131. package/src/cli/view-writes.ts +752 -0
  132. package/src/compile/action-host-attach.ts +21 -29
  133. package/src/compile/closed-set.ts +509 -0
  134. package/src/compile/compile-page.ts +219 -72
  135. package/src/compile/component-candidates.ts +1 -1
  136. package/src/compile/hints.ts +30 -1
  137. package/src/compile/index.ts +1 -0
  138. package/src/compile/kit-error.ts +1 -0
  139. package/src/compile/locate.ts +21 -1
  140. package/src/compile/parse.ts +370 -41
  141. package/src/compile/redirect.ts +6 -2
  142. package/src/compile/styles.ts +35 -2
  143. package/src/compile/types.ts +18 -2
  144. package/src/compile/view-check.ts +151 -0
  145. package/src/data/amount-breakdown.ts +2 -2
  146. package/src/data/anchor-nav.ts +2 -2
  147. package/src/data/approval-flow.ts +2 -2
  148. package/src/data/assignment-picker.ts +40 -29
  149. package/src/data/async-result-panel.ts +62 -6
  150. package/src/data/breadcrumbs.ts +2 -2
  151. package/src/data/calendar.ts +22 -25
  152. package/src/data/carousel.ts +5 -2
  153. package/src/data/chart.ts +42 -34
  154. package/src/data/checklist.ts +2 -2
  155. package/src/data/code-view.ts +4 -2
  156. package/src/data/comment-thread.ts +5 -2
  157. package/src/data/confirm-dialog.ts +10 -0
  158. package/src/data/context-menu.ts +29 -37
  159. package/src/data/d9-util.ts +2 -18
  160. package/src/data/diff.ts +4 -2
  161. package/src/data/dock.ts +2 -2
  162. package/src/data/embed.ts +2 -1
  163. package/src/data/field-mapper.ts +31 -26
  164. package/src/data/flow-editor-contract.ts +1 -1
  165. package/src/data/flow-editor.ts +89 -100
  166. package/src/data/flow-node-options.ts +90 -0
  167. package/src/data/flow-remote-options.ts +0 -103
  168. package/src/data/footer.ts +2 -2
  169. package/src/data/form-draft-registry.ts +2 -4
  170. package/src/data/gantt.ts +14 -17
  171. package/src/data/hero.ts +2 -2
  172. package/src/data/image-viewer.ts +20 -26
  173. package/src/data/index.ts +0 -2
  174. package/src/data/item-list.ts +31 -22
  175. package/src/data/kanban.ts +43 -42
  176. package/src/data/media-grid.ts +14 -19
  177. package/src/data/menu.ts +2 -2
  178. package/src/data/mockup.ts +2 -2
  179. package/src/data/modal-dialog.ts +22 -18
  180. package/src/data/navbar.ts +7 -2
  181. package/src/data/notify-renderer.ts +235 -0
  182. package/src/data/object-form.ts +1036 -648
  183. package/src/data/pager.ts +65 -29
  184. package/src/data/permission-matrix.ts +20 -21
  185. package/src/data/permission-tree.ts +28 -26
  186. package/src/data/pricing-table.ts +9 -3
  187. package/src/data/reaction-bar.ts +77 -88
  188. package/src/data/read-rollback.ts +73 -0
  189. package/src/data/record-card.ts +3 -3
  190. package/src/data/record-picker.ts +93 -50
  191. package/src/data/redirect.ts +32 -32
  192. package/src/data/remote-options.ts +13 -6
  193. package/src/data/request-console.ts +5 -3
  194. package/src/data/resident.ts +2 -1
  195. package/src/data/result-panel.ts +4 -2
  196. package/src/data/rich-text.ts +45 -55
  197. package/src/data/row-editor.ts +285 -52
  198. package/src/data/rule-builder.ts +18 -12
  199. package/src/data/shape-util.ts +4 -0
  200. package/src/data/stat-group.ts +243 -101
  201. package/src/data/static-registry.ts +22 -11
  202. package/src/data/steps.ts +2 -2
  203. package/src/data/survey.ts +24 -29
  204. package/src/data/system-switcher.ts +2 -2
  205. package/src/data/timeline.ts +2 -2
  206. package/src/data/tour-guide.ts +22 -29
  207. package/src/data/transfer.ts +27 -23
  208. package/src/data/tree-table.ts +96 -48
  209. package/src/data/tree.ts +27 -34
  210. package/src/data/trend-line.ts +6 -24
  211. package/src/data/virtual-rows.ts +118 -76
  212. package/src/data/watermark.ts +2 -2
  213. package/src/data/wrap.ts +63 -38
  214. package/src/frames/blank-frame.ts +1 -0
  215. package/src/frames/index.ts +2 -2
  216. package/src/frames/page-bar.ts +12 -11
  217. package/src/frames/page-header.ts +14 -5
  218. package/src/frames/page-status.ts +2 -2
  219. package/src/frames/shared.ts +23 -17
  220. package/src/frames/single-frame.ts +1 -0
  221. package/src/frames/split-frame/shell.ts +5 -5
  222. package/src/frames/split-frame/wiring.ts +2 -2
  223. package/src/frames/tabs-frame/shell.ts +2 -13
  224. package/src/frames/tabs-frame/wiring.ts +4 -8
  225. package/src/frames/top-main-frame.ts +1 -0
  226. package/src/frames/types.ts +13 -2
  227. package/src/frames/workspace-frame/extras.ts +20 -4
  228. package/src/frames/workspace-frame/index.ts +1 -1
  229. package/src/frames/workspace-frame/shell.ts +1 -0
  230. package/src/frames/workspace-frame/state.ts +13 -6
  231. package/src/frames/workspace-frame/view.ts +119 -25
  232. package/src/generated/kit-grammar-runtime.ts +430 -366
  233. package/src/generated/page-origin.ts +0 -11
  234. package/src/i18n/kit-text.ts +23 -27
  235. package/src/index.ts +2 -1
  236. package/src/object-renderer/action-gate.ts +11 -147
  237. package/src/object-renderer/arrange.ts +71 -77
  238. package/src/object-renderer/collapse-wiring.ts +2 -2
  239. package/src/object-renderer/collection-expand.ts +2 -2
  240. package/src/object-renderer/collection-parts.ts +216 -100
  241. package/src/object-renderer/collection-table.ts +180 -42
  242. package/src/object-renderer/collection.ts +95 -79
  243. package/src/object-renderer/compile-data.ts +85 -100
  244. package/src/object-renderer/crud-bridge.ts +32 -0
  245. package/src/object-renderer/defaults.ts +8 -14
  246. package/src/object-renderer/display-checks.ts +3 -24
  247. package/src/object-renderer/emit-events.ts +186 -172
  248. package/src/object-renderer/emit-object.ts +15 -2
  249. package/src/object-renderer/emit-static.ts +174 -132
  250. package/src/object-renderer/field-value.ts +593 -396
  251. package/src/object-renderer/filter-reload.ts +70 -0
  252. package/src/object-renderer/form-detail.ts +112 -2
  253. package/src/object-renderer/index.ts +26 -0
  254. package/src/object-renderer/key-field.ts +12 -0
  255. package/src/object-renderer/linkage.ts +7 -270
  256. package/src/object-renderer/merge-class.ts +18 -1
  257. package/src/object-renderer/path-pick.ts +27 -0
  258. package/src/object-renderer/render-object.ts +405 -86
  259. package/src/object-renderer/request-actions.ts +230 -249
  260. package/src/object-renderer/table-actions.ts +195 -95
  261. package/src/object-renderer/table-summary.ts +2 -2
  262. package/src/object-renderer/table-tools.ts +418 -84
  263. package/src/object-renderer/types.ts +128 -122
  264. package/src/object-renderer/view-binding.ts +196 -0
  265. package/src/page-target/ai-surface.ts +37 -0
  266. package/src/page-target/compile.ts +48 -8
  267. package/src/page-target/index.ts +8 -1
  268. package/src/page-target/intent-schema.ts +154 -28
  269. package/src/page-target/target.ts +257 -50
  270. package/src/page-target/writer-policy.ts +14 -3
  271. package/src/recipes/container.ts +165 -0
  272. package/src/recipes/control.ts +219 -0
  273. package/src/recipes/index.ts +263 -0
  274. package/src/recipes/overlay.ts +182 -0
  275. package/src/recipes/state.ts +70 -0
  276. package/src/recipes/table-row.ts +51 -0
  277. package/src/recipes/typography.ts +87 -0
  278. package/src/shared/action-field-guard.ts +41 -0
  279. package/src/shared/envelope.ts +207 -0
  280. package/src/shared/escape.ts +57 -0
  281. package/src/shared/kit-error.ts +21 -0
  282. package/src/shared/paged-list-adapter.ts +240 -0
  283. package/src/shared/path-guard.ts +127 -0
  284. package/src/shared/theme-runtime-shared.ts +175 -0
  285. package/src/shared/view-info.ts +10 -0
  286. package/src/theme/index.ts +12 -0
  287. package/src/theme/kit-theme-text.ts +1 -1
  288. package/src/theme/kit-theme.css +38 -1
  289. package/src/theme/kit-theme.tpl +38 -1
  290. package/src/theme/nine-dim-structure.ts +77 -0
  291. package/src/theme/surface-layers.ts +97 -0
  292. package/src/theme/theme-tokens.ts +85 -79
  293. package/src/theme/theme-types.ts +71 -0
  294. package/src/theme/typography.ts +17 -17
  295. package/src/biz/shared/step-values.ts +0 -25
  296. package/src/biz/step-form/steps-ref.ts +0 -112
  297. package/src/data/options-bus.ts +0 -24
  298. package/src/data/prompt-dialog.ts +0 -235
  299. package/src/object-renderer/adopt-gate.ts +0 -333
  300. package/src/object-renderer/field-policy.ts +0 -89
  301. package/src/object-renderer/outcome-draft.ts +0 -61
  302. package/src/theme/nine-dim-palettes.ts +0 -1278
@@ -22,6 +22,7 @@ import { KIT_DATE_CLASS_CANDIDATES, mountKitDateField } from '../base/date';
22
22
  import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
23
23
  import { createKitEmbedBag, mountKitSelectField, type KitEmbedBag } from './embed';
24
24
  import { bool, num, str } from '../base/shared';
25
+ import { setKitFace, type KitFaceKind } from '../recipes';
25
26
 
26
27
  // ════════════════════════════════════════════════════════════════
27
28
  // 单条条件模块(纯函数 + 值控件构造):运算符表、按字段类型取运算符、值形状归一、校验文字、值控件(复用 kit 基础文本类控件的
@@ -104,10 +105,11 @@ export function defaultOperatorFor(type: RuleFieldType): string {
104
105
  return operatorsFor(type)[0] ?? 'eq';
105
106
  }
106
107
 
107
- export const isKnownOperator = (op: string): boolean => op in OPERATORS;
108
- export const operatorLabel = (op: string): string => OPERATORS[op]?.label ?? op;
109
- export const operatorShort = (op: string): string => OPERATORS[op]?.short ?? op;
110
- export const valueKindOf = (op: string): RuleValueKind => OPERATORS[op]?.kind ?? 'single';
108
+ const operatorOf = (op: string): (typeof OPERATORS)[string] | undefined => Object.hasOwn(OPERATORS, op) ? OPERATORS[op] : undefined;
109
+ export const isKnownOperator = (op: string): boolean => Object.hasOwn(OPERATORS, op);
110
+ export const operatorLabel = (op: string): string => operatorOf(op)?.label ?? op;
111
+ export const operatorShort = (op: string): string => operatorOf(op)?.short ?? op;
112
+ export const valueKindOf = (op: string): RuleValueKind => operatorOf(op)?.kind ?? 'single';
111
113
 
112
114
  // ── 值形状 ──────────────────────────────────────────────────────
113
115
 
@@ -274,6 +276,7 @@ function valueSelectOf(part: string, label: string, opts: readonly RuleOption[],
274
276
 
275
277
  function inputOf(part: string, label: string, type: RuleFieldType, value: unknown): HTMLInputElement {
276
278
  const el = mk('input', CONTROL);
279
+ setKitFace(el, 'field');
277
280
  el.type = inputType(type);
278
281
  el.autocomplete = 'off';
279
282
  el.setAttribute('data-kit-part', part);
@@ -331,6 +334,7 @@ export function buildValueControl(cond: RuleCondition, field: RuleField | undefi
331
334
  for (const o of field?.options ?? []) {
332
335
  const b = mk('button', PILL, o.label);
333
336
  b.type = 'button';
337
+ setKitFace(b, 'raised');
334
338
  b.setAttribute('data-kit-part', 'value-opt');
335
339
  b.setAttribute('data-kit-opt', o.value);
336
340
  b.setAttribute('aria-pressed', chosen.has(o.value) ? 'true' : 'false');
@@ -672,9 +676,11 @@ const treeSig = (ctx: Ctx, tree: RuleGroup): string => ctx.cfgSig + JSON.stringi
672
676
  // 组件
673
677
  // ════════════════════════════════════════════════════════════════
674
678
 
675
- function button(cls: string, text: string, part: string, aria?: string): HTMLButtonElement {
679
+ /** surface:质感标记,由调用方按钮型传入(带边框 / 实心的传 'raised',ghost 钮不传),不按类串解析 */
680
+ function button(cls: string, text: string, part: string, aria?: string, surface: KitFaceKind | null = null): HTMLButtonElement {
676
681
  const b = mk('button', cls, text);
677
682
  b.type = 'button';
683
+ setKitFace(b, surface);
678
684
  b.setAttribute('data-kit-part', part);
679
685
  if (aria !== undefined) b.setAttribute('aria-label', aria);
680
686
  return b;
@@ -758,17 +764,17 @@ function buildGroup(g: RuleGroup, path: number[], index: number, count: number,
758
764
  }
759
765
  head.appendChild(modes);
760
766
  if (ctx.allowNot) {
761
- const nb = button(NOT_BTN_CLASS, l.not ?? '', 'not');
767
+ const nb = button(NOT_BTN_CLASS, l.not ?? '', 'not', undefined, 'raised');
762
768
  nb.setAttribute('aria-pressed', g.not === true ? 'true' : 'false');
763
769
  if (g.not === true) nb.setAttribute('data-kit-selected', '');
764
770
  head.appendChild(nb);
765
771
  }
766
772
  head.appendChild(mk('span', SPACER_CLASS));
767
- const addC = button(TOOL_BTN_CLASS, l.add_condition ?? '', 'add-cond');
773
+ const addC = button(TOOL_BTN_CLASS, l.add_condition ?? '', 'add-cond', undefined, 'raised');
768
774
  if (atLimit) { addC.disabled = true; addC.title = l.node_limit ?? ''; }
769
775
  head.appendChild(addC);
770
776
  if (ctx.allowGroup) {
771
- const addG = button(TOOL_BTN_CLASS, l.add_group ?? '', 'add-group');
777
+ const addG = button(TOOL_BTN_CLASS, l.add_group ?? '', 'add-group', undefined, 'raised');
772
778
  if (!canAddGroup(path, ctx.maxDepth)) { addG.disabled = true; addG.title = l.depth_limit ?? ''; }
773
779
  else if (total + 2 > RULE_MAX_NODES) { addG.disabled = true; addG.title = l.node_limit ?? ''; }
774
780
  head.appendChild(addG);
@@ -885,7 +891,7 @@ export function createRuleBuilder(): SomaComponentDefinition {
885
891
  },
886
892
  },
887
893
  templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
888
- controllerFactory: createKitController({
894
+ controllerFactory: createKitController(() => ({
889
895
  busyAware: true,
890
896
  attach(root, api) {
891
897
  const nodeOf = (el: Element | null): { key: string; path: number[] } | null => {
@@ -1063,7 +1069,7 @@ export function createRuleBuilder(): SomaComponentDefinition {
1063
1069
  render(root, p) {
1064
1070
  paint(root, p);
1065
1071
  },
1066
- }),
1072
+ })),
1067
1073
  };
1068
1074
 
1069
1075
  function paint(root: HTMLElement, p: KitProps): void {
@@ -1119,9 +1125,9 @@ export function createRuleBuilder(): SomaComponentDefinition {
1119
1125
  }
1120
1126
  if (ctx.saveLabel !== '' || ctx.cancelLabel !== '') {
1121
1127
  const foot = mk('div', FOOT_CLASS);
1122
- if (ctx.cancelLabel !== '') foot.appendChild(button(CANCEL_CLASS, ctx.cancelLabel, 'cancel'));
1128
+ if (ctx.cancelLabel !== '') foot.appendChild(button(CANCEL_CLASS, ctx.cancelLabel, 'cancel', undefined, 'raised'));
1123
1129
  if (ctx.saveLabel !== '') {
1124
- const saveBtn = button(SAVE_CLASS, ctx.saveLabel, 'save');
1130
+ const saveBtn = button(SAVE_CLASS, ctx.saveLabel, 'save', undefined, 'raised');
1125
1131
  if (ctx.busy) { saveBtn.disabled = true; saveBtn.setAttribute('aria-busy', 'true'); }
1126
1132
  foot.appendChild(saveBtn);
1127
1133
  }
@@ -5,6 +5,8 @@
5
5
  // - DOM 小工具:建元素、空态、动作按钮。
6
6
  // 颜色只用语义色名:彩色文字只配 `-on-soft`,实心底只配 `-fg`;空态与分隔用实线。
7
7
 
8
+ import { setKitFace } from '../recipes';
9
+
8
10
  export type Rec = Record<string, unknown>;
9
11
 
10
12
  export function recOf(raw: unknown): Rec {
@@ -138,6 +140,8 @@ export function actionButton(action: ShapeAction, extraClass = ''): HTMLButtonEl
138
140
  btn.type = 'button';
139
141
  btn.className = [BUTTON_BASE, BUTTON_TONE[action.tone], action.disabled ? BUTTON_DISABLED : '', extraClass]
140
142
  .filter((s) => s !== '').join(' ');
143
+ // 质感标记:三种语气都有实心 / 描边底面,同 Button 标 raised(所有经 actionButton 的动作钮单点覆盖)
144
+ setKitFace(btn, 'raised');
141
145
  btn.textContent = action.label;
142
146
  btn.setAttribute('data-kit-action', action.key);
143
147
  if (action.disabled) {
@@ -1,53 +1,90 @@
1
1
  // StatGroup:统计块一排(layer: data,写死形状,accept: single)。
2
2
  //
3
- // 数据:`data` 是一个对象(如汇总接口的返回)。展示哪几项由 `items` 外部传入 [{ key, label, format? }];
3
+ // 数据:`data` 是一个对象(如汇总接口的返回)。展示哪几项由 `items` 外部传入 [{ key, label, format?, unit?, trend?, compare?, compareValue? }];
4
4
  // `map` 是「组件期望的键 -> 数据里的键」的对照(浅映射,不改源数据)。
5
5
  // 没写 items 时:有 map 就按 map 的键序展示(label = 键名);也没有 map 就展示数据里全部数值字段。
6
- // 点某块抛 `select { item: { key, label, value } }`。窄屏 1 列,容器达到 md 档 2 列、xl 档 4 列(容器查询)。
6
+ // 点某块抛 `select { item: { key, label, value } }`。
7
+ // 列数按容器宽度档(容器查询)与项数选:每档只取不让末行落单一项的列数,无解的项数让末块拉伸占满整行;
8
+ // 规则与各档数字只在 soma-design 真源(kit-limits.json 的 statGrid),选列数的函数是 soma-foundation/data/values 的 gridFillPlanOf,这里只把结果写成类串。
7
9
 
8
- import type { SomaComponentControllerContext, SomaComponentDefinition } from 'soma-core';
9
- import { findRoot, formatValue, joinClass, num, str } from '../base/shared';
10
+ import type { SomaComponentDefinition } from 'soma-core';
11
+ import { gridFillPlanOf, type SomaGridFillPlan } from 'soma-foundation/data/values';
12
+ import { KIT_STAT_GRID } from 'soma-foundation/kit-limits';
13
+ import { createKitController, formatValue, joinClass, num, str } from '../base/shared';
10
14
  import { kitIcon } from '../base/icons';
11
15
  import { TAG_CLASS } from '../base/tag';
12
16
  import { KIT_TREND_LINE_CLASS_CANDIDATES, sparklineSvg, trendToneOf, trendValuesOf } from './trend-line';
17
+ import { KIT_PART_ATTRIBUTE, KIT_PART_CARD, KIT_PART_STAT_VALUE, kitTypographyRecipe } from '../recipes';
13
18
 
14
19
  const WRAP_CLASS = '@container';
15
- const GRID_CLASS = 'grid grid-cols-1 gap-4 @md:grid-cols-2 @xl:grid-cols-4';
20
+ const GRID_CLASS = 'grid grid-cols-1 gap-4';
16
21
  const BLOCK_CLASS = 'flex flex-col gap-1 rounded-lg border border-border-subtle bg-surface px-5 py-4 text-start shadow-xs transition-colors hover:bg-surface-sunken active:opacity-80 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
17
22
  const LABEL_CLASS = 'text-xs font-medium text-fg-muted';
18
- const VALUE_CLASS = 'text-2xl font-semibold text-fg';
23
+ /** 指标主数值样式:对齐规则卡 30px 大数字 + font-bold tabular-nums */
24
+ export const STAT_VALUE_CLASS = kitTypographyRecipe('statValue');
25
+ const VALUE_CLASS = STAT_VALUE_CLASS;
26
+ const VALUE_ROW_CLASS = 'inline-flex items-baseline gap-1';
27
+ const UNIT_CLASS = 'text-xs font-normal text-fg-muted';
19
28
 
20
29
  /** 本组件自带的全部类(供编译器并入候选类) */
21
30
  export const KIT_STAT_GROUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
22
- '@container', 'grid', 'grid-cols-1', 'gap-4', '@md:grid-cols-2', '@xl:grid-cols-4',
31
+ '@container', 'grid', 'grid-cols-1', 'gap-4',
23
32
  'flex', 'flex-col', 'gap-1', 'rounded-lg', 'border', 'border-border-subtle', 'bg-surface', 'px-5', 'py-4', 'text-start',
24
- 'transition-colors', 'active:opacity-80', 'font-medium',
33
+ 'transition-colors', 'active:opacity-80', 'font-medium', 'font-normal', 'font-bold', 'tabular-nums',
25
34
  'hover:bg-surface-sunken', 'focus-visible:outline-none', 'focus-visible:ring-1', 'focus-visible:ring-inset', 'focus-visible:ring-ring', 'shadow-xs',
26
- 'text-sm', 'text-fg-muted', 'text-2xl', 'font-semibold', 'text-fg',
27
- 'items-center', 'flex-wrap', 'rounded-md', 'px-1.5', 'py-0.5', 'text-xs', 'font-medium', 'inline-flex',
35
+ 'text-sm', 'text-fg-muted', 'text-2xl', 'text-stat-value', 'font-title', 'tracking-tight', 'font-semibold', 'text-fg',
36
+ 'items-center', 'items-baseline', 'flex-wrap', 'rounded-md', 'px-1.5', 'py-0.5', 'text-xs', 'inline-flex',
28
37
  ...Object.values(TAG_CLASS.sm).flatMap((s) => s.split(' ')),
29
- 'bg-success-soft', 'text-success-on-soft', 'bg-danger-soft', 'text-danger-on-soft', 'bg-surface-sunken', 'text-fg-subtle', 'gap-2',
38
+ 'bg-success-soft', 'text-success-on-soft', 'bg-danger-soft', 'text-danger-on-soft', 'bg-surface-sunken', 'text-fg-subtle', 'gap-2', 'border-primary', 'bg-primary-soft',
30
39
  ...KIT_TREND_LINE_CLASS_CANDIDATES, 'h-8', 'w-full',
31
- '@md:grid-cols-1', '@md:grid-cols-3', '@xl:grid-cols-1', '@xl:grid-cols-2', '@xl:grid-cols-3', '@xl:grid-cols-6',
40
+ // 各档列数与末块拉伸的全部可能类(档名 x 允许列数取自真源,Tailwind 静态扫描不到运行期拼的类名,所以在此列全)
41
+ ...Object.keys(KIT_STAT_GRID.tierCols).flatMap((tier) => [
42
+ ...KIT_STAT_GRID.allowed.map((k) => `@${tier}:grid-cols-${k}`),
43
+ `@${tier}:col-span-full`, `@${tier}:col-span-1`,
44
+ ]),
32
45
  ]);
33
46
 
34
- /** 列数(`columns` prop)-> 完整类串;缺省 md 档 2 列、xl 档 4 列 */
35
- const GRID_BY_COLUMNS: Readonly<Record<number, string>> = Object.freeze({
36
- 1: 'grid grid-cols-1 gap-4',
37
- 2: 'grid grid-cols-1 gap-4 @md:grid-cols-2',
38
- 3: 'grid grid-cols-1 gap-4 @md:grid-cols-3',
39
- 4: 'grid grid-cols-1 gap-4 @md:grid-cols-2 @xl:grid-cols-4',
40
- 6: 'grid grid-cols-1 gap-4 @md:grid-cols-3 @xl:grid-cols-6',
41
- });
47
+ /**
48
+ * 栅格计划 -> 类串:网格类按档升序只写列数变化处(窄屏基准 1 列);末块类只写拉伸标记变化处(拉伸 = 占满整行,退出 = 回到单列宽)。
49
+ * 计划由 gridFillPlanOf 给出,这里只做格式化。
50
+ */
51
+ export function statGridClassesOf(plan: SomaGridFillPlan): { grid: string; last: string } {
52
+ const grid = [GRID_CLASS];
53
+ const last: string[] = [];
54
+ let cols = 1;
55
+ let stretch = false;
56
+ for (const tier of Object.keys(KIT_STAT_GRID.tierCols)) {
57
+ const c: number = plan.cols[tier] ?? cols;
58
+ if (c !== cols) { grid.push(`@${tier}:grid-cols-${c}`); cols = c; }
59
+ const s: boolean = plan.stretch[tier] ?? stretch;
60
+ if (s !== stretch) { last.push(`@${tier}:col-span-${s ? 'full' : '1'}`); stretch = s; }
61
+ }
62
+ return { grid: grid.join(' '), last: last.join(' ') };
63
+ }
64
+
65
+ /** 一排统计块的类:columns 是作者显式写的列数(在真源 explicit 登记才生效),否则按项数防孤行。 */
66
+ export function statGridClasses(count: number, columns: number | null | undefined): { grid: string; last: string } {
67
+ return statGridClassesOf(gridFillPlanOf(KIT_STAT_GRID, count, columns ?? undefined));
68
+ }
42
69
 
43
70
  export interface KitStatItem {
44
71
  key: string;
45
72
  label: string;
46
73
  format: string;
74
+ /** 单位(如 '元'、'单'、'%') */
75
+ unit: string;
76
+ /** 单位取自数据里的键(给了就优先于 unit) */
77
+ unitKey: string;
47
78
  /** 环比:数据里放环比数值的键(正升负降);空 = 不显示 */
48
79
  trend: string;
49
80
  /** 环比的显示格式(缺省 percent,数据按小数,0.12 显示 12%) */
50
81
  trendFormat: string;
82
+ /** 对比期变化值(支持 '+12.5%' 或数字,或经 delta 传入) */
83
+ compareValue: string | number | undefined;
84
+ /** 对比期文案(支持 compare / compareLabel / period,如 '较昨日'、'同比上周') */
85
+ compare: string;
86
+ /** 对比期文案取自数据里的键 */
87
+ compareKey: string;
51
88
  /** 上升是好事(success)还是坏事(danger);缺省 good */
52
89
  upIs: 'good' | 'bad';
53
90
  /** 提示文案(字面量) */
@@ -56,6 +93,8 @@ export interface KitStatItem {
56
93
  hintKey: string;
57
94
  /** 迷你趋势线:数据里放数字数组的键(经 map 对照);空 = 不画。线色按首末涨跌与 upIs 取好 / 坏色 */
58
95
  spark: string;
96
+ /** 指标项主色高亮强调 */
97
+ highlight?: boolean;
59
98
  }
60
99
 
61
100
  // 趋势徽标直接复用基础组件 Tag 的 sm 档类串
@@ -65,6 +104,7 @@ const TREND_UP_CLASS: Record<'good' | 'bad' | 'flat', string> = {
65
104
  flat: TAG_CLASS.sm.neutral,
66
105
  };
67
106
  const FOOT_CLASS = 'flex flex-wrap items-center gap-2';
107
+ const COMPARE_CLASS = 'text-xs text-fg-muted';
68
108
  const HINT_CLASS = 'text-xs text-fg-subtle';
69
109
 
70
110
  /** 环比徽标的语气:涨跌方向 x 涨是好事还是坏事;纯函数 */
@@ -74,17 +114,33 @@ export function trendTone(change: number, upIs: 'good' | 'bad'): 'good' | 'bad'
74
114
  return up === (upIs === 'good') ? 'good' : 'bad';
75
115
  }
76
116
 
117
+ function resolveCompareValue(rec: Record<string, unknown>): string | number | undefined {
118
+ for (const k of ['compareValue', 'delta'] as const) {
119
+ const raw = rec[k];
120
+ if (typeof raw === 'number' && Number.isFinite(raw)) return raw;
121
+ if (typeof raw === 'string' && raw.trim() !== '') return raw.trim();
122
+ }
123
+ if (typeof rec.trend === 'number' && Number.isFinite(rec.trend)) return rec.trend;
124
+ return undefined;
125
+ }
126
+
77
127
  function itemOf(key: string, label: string, rec: Record<string, unknown>): KitStatItem {
78
128
  return {
79
129
  key,
80
130
  label,
81
131
  format: str(rec.format),
82
- trend: str(rec.trend),
132
+ unit: str(rec.unit),
133
+ unitKey: str(rec.unitKey),
134
+ trend: typeof rec.trend === 'string' ? rec.trend : '',
83
135
  trendFormat: str(rec.trendFormat, 'percent'),
136
+ compareValue: resolveCompareValue(rec),
137
+ compare: str(rec.compare) || str(rec.compareLabel) || str(rec.period),
138
+ compareKey: str(rec.compareKey),
84
139
  upIs: rec.upIs === 'bad' ? 'bad' : 'good',
85
140
  hint: str(rec.hint),
86
141
  hintKey: str(rec.hintKey),
87
142
  spark: str(rec.spark),
143
+ ...(rec.highlight === true ? { highlight: true } : {}),
88
144
  };
89
145
  }
90
146
 
@@ -92,6 +148,68 @@ function recOf(raw: unknown): Record<string, unknown> {
92
148
  return raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw as Record<string, unknown> : {};
93
149
  }
94
150
 
151
+ function parseChangeString(text: string): { change: number; text: string } {
152
+ const trimmed = text.trim();
153
+ const parsed = Number.parseFloat(trimmed.replace(/[,%\s+]/g, ''));
154
+ const mag = Number.isFinite(parsed) ? Math.abs(parsed) : 0;
155
+ const change = trimmed.startsWith('-') ? -(mag || 1) : trimmed.startsWith('+') ? (mag || 1) : (Number.isFinite(parsed) ? parsed : 0);
156
+ return { change, text: trimmed };
157
+ }
158
+
159
+ function resolveChangeBadge(
160
+ item: KitStatItem,
161
+ map: Record<string, unknown>,
162
+ data: Record<string, unknown>,
163
+ locale: string,
164
+ ): { change: number; text: string } | undefined {
165
+ if (item.trend !== '') {
166
+ const trendSource = typeof map[item.trend] === 'string' && map[item.trend] !== '' ? String(map[item.trend]) : item.trend;
167
+ const trendRaw = data[trendSource];
168
+ const change = num(trendRaw) ?? NaN;
169
+ if (Number.isFinite(change)) {
170
+ return { change, text: formatValue(Math.abs(change), item.trendFormat, locale) };
171
+ }
172
+ }
173
+ const cv = item.compareValue;
174
+ if (typeof cv === 'number' && Number.isFinite(cv)) {
175
+ return { change: cv, text: formatValue(Math.abs(cv), item.trendFormat, locale) };
176
+ }
177
+ if (typeof cv === 'string' && cv !== '') {
178
+ const mapped = typeof map[cv] === 'string' && map[cv] !== '' ? String(map[cv]) : cv;
179
+ if (Object.prototype.hasOwnProperty.call(data, mapped)) {
180
+ const raw = data[mapped];
181
+ const n = num(raw);
182
+ if (typeof n === "number" && Number.isFinite(n)) {
183
+ return { change: n, text: formatValue(Math.abs(n), item.trendFormat, locale) };
184
+ }
185
+ if (typeof raw === 'string' && raw.trim() !== '') {
186
+ return parseChangeString(raw);
187
+ }
188
+ return undefined;
189
+ }
190
+ return parseChangeString(cv);
191
+ }
192
+ return undefined;
193
+ }
194
+
195
+ function resolveMappedString(
196
+ literalOrKey: string,
197
+ explicitKey: string,
198
+ map: Record<string, unknown>,
199
+ data: Record<string, unknown>,
200
+ ): string {
201
+ if (explicitKey !== '') {
202
+ const source = typeof map[explicitKey] === 'string' && map[explicitKey] !== '' ? String(map[explicitKey]) : explicitKey;
203
+ return str(data[source]);
204
+ }
205
+ if (literalOrKey === '') return '';
206
+ const source = typeof map[literalOrKey] === 'string' && map[literalOrKey] !== '' ? String(map[literalOrKey]) : literalOrKey;
207
+ if (Object.prototype.hasOwnProperty.call(data, source) && typeof data[source] === 'string') {
208
+ return String(data[source]);
209
+ }
210
+ return literalOrKey;
211
+ }
212
+
95
213
  /** 决定展示哪几项(纯函数,便于单测) */
96
214
  export function statItemsOf(itemsRaw: unknown, mapRaw: unknown, data: Record<string, unknown>): KitStatItem[] {
97
215
  const map = recOf(mapRaw);
@@ -120,9 +238,9 @@ export function createStatGroup(): SomaComponentDefinition {
120
238
  layer: 'data',
121
239
  props: {
122
240
  data: { type: 'object', default: {}, desc: '统计对象,如 { total: 12, open: 3 }' },
123
- items: { type: 'array', default: [], desc: '展示项 [{ key, label, format?, trend?, trendFormat?, upIs?, hint?, hintKey? }];format 取 soma-foundation/values 的写法(number / percent / currency:CNY 等);trend = 数据里环比数值的键(正升负降,默认 percent 小数),upIs: good | bad 决定涨是绿还是红,hint 提示字面量、hintKey 取自数据' },
241
+ items: { type: 'array', default: [], desc: '展示项 [{ key, label, format?, unit?, unitKey?, trend?, trendFormat?, compare?, compareLabel?, period?, compareValue?, delta?, upIs?, hint?, hintKey? }];format 取 soma-foundation/values 的写法(number / percent / currency:CNY 等);unit 为数值单位;trend / compareValue / delta 为变化率,compare / compareLabel / period 为对比期说明(如「较昨日」),upIs: good | bad 决定涨是绿还是红,hint 提示字面量、hintKey 取自数据' },
124
242
  map: { type: 'object', default: {}, desc: '键名对照:items 里的 key -> 数据里的键' },
125
- columns: { type: 'number', default: 0, desc: '列数:1 / 2 / 3 / 4 / 6(宽容器下的列数,窄容器 1 列);0 或其它 = 默认(md 档 2 列、xl 档 4 列)。单个统计卡片 = 一项 items + columns: 1' },
243
+ columns: { type: 'number', default: 0, desc: '列数:1 / 2 / 3 / 4 / 6(宽容器下的列数,窄容器 1 列);0 或其它 = 自动(每个容器宽度档按项数取不让末行落单一项的列数,档位与上限见真源 kit-limits 的 statGrid)。单个统计卡片 = 一项 items + columns: 1' },
126
244
  locale: { type: 'string', default: '', desc: '格式化语言;空则 zh-CN' },
127
245
  class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
128
246
  },
@@ -131,77 +249,14 @@ export function createStatGroup(): SomaComponentDefinition {
131
249
  },
132
250
  },
133
251
  templateHtml: `<div data-soma-id="root" class="${WRAP_CLASS}"><div data-soma-id="grid" class="${GRID_CLASS}"></div></div>`,
134
- controllerFactory: (ctx: SomaComponentControllerContext) => {
135
- const P = (): Record<string, unknown> => (ctx.readProps ? ctx.readProps() : ctx.props);
252
+ controllerFactory: createKitController((api) => {
136
253
  let root: HTMLElement | null = null;
137
254
  let grid: HTMLElement | null = null;
138
- let cleanup: (() => void) | undefined;
139
255
  let current: Array<{ key: string; label: string; value: unknown }> = [];
140
256
 
141
- const paint = (): void => {
142
- if (!root || !grid) return;
143
- const p = P();
144
- const data = recOf(p.data);
145
- const map = recOf(p.map);
146
- const locale = str(p.locale);
147
- root.className = joinClass(WRAP_CLASS, p.class);
148
- grid.className = GRID_BY_COLUMNS[num(p.columns) ?? 0] ?? GRID_CLASS;
149
- grid.textContent = '';
150
- current = [];
151
- for (const item of statItemsOf(p.items, map, data)) {
152
- const source = typeof map[item.key] === 'string' && map[item.key] !== '' ? String(map[item.key]) : item.key;
153
- const value = data[source];
154
- current.push({ key: item.key, label: item.label, value });
155
- const block = document.createElement('button');
156
- block.type = 'button';
157
- block.className = BLOCK_CLASS;
158
- block.setAttribute('data-kit-stat', item.key);
159
- const label = document.createElement('span');
160
- label.className = LABEL_CLASS;
161
- label.textContent = item.label;
162
- const val = document.createElement('span');
163
- val.className = VALUE_CLASS;
164
- val.textContent = value === undefined || value === null || value === '' ? '' : formatValue(value, item.format, locale);
165
- block.appendChild(label);
166
- block.appendChild(val);
167
- if (item.spark !== '') {
168
- const sparkSource = typeof map[item.spark] === 'string' && map[item.spark] !== '' ? String(map[item.spark]) : item.spark;
169
- const values = trendValuesOf(data[sparkSource]);
170
- const svg = sparklineSvg(values, { tone: trendToneOf('auto', values, item.upIs), label: item.label, className: 'h-8 w-full' });
171
- if (svg) block.appendChild(svg);
172
- }
173
- // 环比与提示:规则写死——趋势数值取 trend 键(经 map 对照),正升负降,语气由 upIs 决定
174
- const trendSource = item.trend === '' ? '' : (typeof map[item.trend] === 'string' && map[item.trend] !== '' ? String(map[item.trend]) : item.trend);
175
- const trendRaw = trendSource === '' ? undefined : data[trendSource];
176
- // null / 空 / 非数字都不出徽标(Number(null) 是 0,不能让缺值显示成「持平 0%」)
177
- const change = num(trendRaw) ?? NaN;
178
- const hintText = item.hintKey !== '' ? str(data[typeof map[item.hintKey] === 'string' && map[item.hintKey] !== '' ? String(map[item.hintKey]) : item.hintKey]) : item.hint;
179
- if (Number.isFinite(change) || hintText !== '') {
180
- const foot = document.createElement('span');
181
- foot.className = FOOT_CLASS;
182
- if (Number.isFinite(change)) {
183
- const badge = document.createElement('span');
184
- badge.className = TREND_UP_CLASS[trendTone(change, item.upIs)];
185
- badge.setAttribute('data-kit-trend', change > 0 ? 'up' : change < 0 ? 'down' : 'flat');
186
- badge.appendChild(kitIcon(change > 0 ? 'arrow-up' : change < 0 ? 'arrow-down' : 'minus', 'xs'));
187
- badge.appendChild(document.createTextNode(formatValue(Math.abs(change), item.trendFormat, locale)));
188
- foot.appendChild(badge);
189
- }
190
- if (hintText !== '') {
191
- const hint = document.createElement('span');
192
- hint.className = HINT_CLASS;
193
- hint.textContent = hintText;
194
- foot.appendChild(hint);
195
- }
196
- block.appendChild(foot);
197
- }
198
- grid.appendChild(block);
199
- }
200
- };
201
-
202
257
  return {
203
- onMount(): void {
204
- root = findRoot(ctx.host);
258
+ attach(rootEl) {
259
+ root = rootEl;
205
260
  grid = root.querySelector<HTMLElement>('[data-soma-scoped-id="grid"]')
206
261
  ?? root.querySelector<HTMLElement>('[data-soma-id="grid"]');
207
262
  const r = root;
@@ -210,22 +265,109 @@ export function createStatGroup(): SomaComponentDefinition {
210
265
  if (!hit) return;
211
266
  const key = hit.getAttribute('data-kit-stat');
212
267
  const item = current.find((c) => c.key === key);
213
- if (item) ctx.emit('select', { item });
268
+ if (item) api.emit('select', { item });
214
269
  };
215
270
  r.addEventListener('click', onClick);
216
- cleanup = () => r.removeEventListener('click', onClick);
217
- paint();
218
- },
219
- onPropsChange(): void {
220
- paint();
271
+ return () => {
272
+ r.removeEventListener('click', onClick);
273
+ root = null;
274
+ grid = null;
275
+ };
221
276
  },
222
- onUnmount(): void {
223
- if (cleanup) cleanup();
224
- cleanup = undefined;
225
- root = null;
226
- grid = null;
277
+ render(rootEl, p) {
278
+ root = rootEl;
279
+ grid = root.querySelector<HTMLElement>('[data-soma-scoped-id="grid"]')
280
+ ?? root.querySelector<HTMLElement>('[data-soma-id="grid"]');
281
+ if (!grid) return;
282
+ const data = recOf(p.data);
283
+ const map = recOf(p.map);
284
+ const locale = str(p.locale);
285
+ root.className = joinClass(WRAP_CLASS, p.class);
286
+ const items = statItemsOf(p.items, map, data);
287
+ const classes = statGridClasses(items.length, num(p.columns));
288
+ grid.className = classes.grid;
289
+ grid.textContent = '';
290
+ current = [];
291
+ for (const [index, item] of items.entries()) {
292
+ const source = typeof map[item.key] === 'string' && map[item.key] !== '' ? String(map[item.key]) : item.key;
293
+ const value = data[source];
294
+ current.push({ key: item.key, label: item.label, value });
295
+ const block = document.createElement('button');
296
+ block.type = 'button';
297
+ const baseBlockClass = item.highlight === true
298
+ ? BLOCK_CLASS.replace('border-border-subtle bg-surface', 'border-primary bg-primary-soft')
299
+ : BLOCK_CLASS;
300
+ block.className = index === items.length - 1 && classes.last !== '' ? `${baseBlockClass} ${classes.last}` : baseBlockClass;
301
+ block.setAttribute('data-kit-stat', item.key);
302
+ block.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_CARD);
303
+ if (item.highlight === true) block.setAttribute('data-kit-highlight', 'true');
304
+ const label = document.createElement('span');
305
+ label.className = LABEL_CLASS;
306
+ label.textContent = item.label;
307
+ const val = document.createElement('span');
308
+ val.className = VALUE_CLASS;
309
+ val.setAttribute('data-kit-stat-value', '');
310
+ val.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_STAT_VALUE);
311
+ val.textContent = value === undefined || value === null || value === '' ? '' : formatValue(value, item.format, locale);
312
+ block.appendChild(label);
313
+
314
+ const unitText = resolveMappedString(item.unit, item.unitKey, map, data);
315
+ if (unitText !== '') {
316
+ const valRow = document.createElement('span');
317
+ valRow.className = VALUE_ROW_CLASS;
318
+ valRow.appendChild(val);
319
+ const unitEl = document.createElement('span');
320
+ unitEl.className = UNIT_CLASS;
321
+ unitEl.setAttribute('data-kit-stat-unit', '');
322
+ unitEl.textContent = unitText;
323
+ valRow.appendChild(unitEl);
324
+ block.appendChild(valRow);
325
+ } else {
326
+ block.appendChild(val);
327
+ }
328
+
329
+ if (item.spark !== '') {
330
+ const sparkSource = typeof map[item.spark] === 'string' && map[item.spark] !== '' ? String(map[item.spark]) : item.spark;
331
+ const values = trendValuesOf(data[sparkSource]);
332
+ const svg = sparklineSvg(values, { tone: trendToneOf('auto', values, item.upIs), label: item.label, className: 'h-8 w-full' });
333
+ if (svg) block.appendChild(svg);
334
+ }
335
+
336
+ // 变化率、对比期说明与提示:趋势数值取 trend / compareValue / delta,对比期取 compare / compareLabel / period
337
+ const changeBadge = resolveChangeBadge(item, map, data, locale);
338
+ const compareText = resolveMappedString(item.compare, item.compareKey, map, data);
339
+ const hintText = item.hintKey !== '' ? str(data[typeof map[item.hintKey] === 'string' && map[item.hintKey] !== '' ? String(map[item.hintKey]) : item.hintKey]) : item.hint;
340
+ if (changeBadge !== undefined || compareText !== '' || hintText !== '') {
341
+ const foot = document.createElement('span');
342
+ foot.className = FOOT_CLASS;
343
+ if (changeBadge !== undefined) {
344
+ const { change, text: changeText } = changeBadge;
345
+ const badge = document.createElement('span');
346
+ badge.className = TREND_UP_CLASS[trendTone(change, item.upIs)];
347
+ badge.setAttribute('data-kit-trend', change > 0 ? 'up' : change < 0 ? 'down' : 'flat');
348
+ badge.appendChild(kitIcon(change > 0 ? 'arrow-up' : change < 0 ? 'arrow-down' : 'minus', 'xs'));
349
+ badge.appendChild(document.createTextNode(changeText));
350
+ foot.appendChild(badge);
351
+ }
352
+ if (compareText !== '') {
353
+ const cmp = document.createElement('span');
354
+ cmp.className = COMPARE_CLASS;
355
+ cmp.setAttribute('data-kit-stat-compare', '');
356
+ cmp.textContent = compareText;
357
+ foot.appendChild(cmp);
358
+ }
359
+ if (hintText !== '') {
360
+ const hint = document.createElement('span');
361
+ hint.className = HINT_CLASS;
362
+ hint.textContent = hintText;
363
+ foot.appendChild(hint);
364
+ }
365
+ block.appendChild(foot);
366
+ }
367
+ grid.appendChild(block);
368
+ }
227
369
  },
228
370
  };
229
- },
371
+ }),
230
372
  };
231
373
  }