soma-kit 0.0.0-stage → 0.1.0

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 (353) hide show
  1. package/README.md +539 -2
  2. package/bin/soma-kit.mjs +27 -0
  3. package/package.json +66 -4
  4. package/packs/ai/agent-run-card.ts +64 -0
  5. package/packs/ai/evaluation-card.ts +51 -0
  6. package/packs/ai/guardrail-policy-card.ts +48 -0
  7. package/packs/ai/index.ts +31 -0
  8. package/packs/ai/model-card.ts +55 -0
  9. package/packs/ai/model-routing-card.ts +49 -0
  10. package/packs/ai/prompt-template-card.ts +49 -0
  11. package/packs/ai/texts.ts +19 -0
  12. package/packs/commerce/address-card.ts +58 -0
  13. package/packs/commerce/coupon-card.ts +64 -0
  14. package/packs/commerce/index.ts +25 -0
  15. package/packs/commerce/order-card.ts +60 -0
  16. package/packs/commerce/purchase-order-card.ts +74 -0
  17. package/packs/commerce/texts.ts +14 -0
  18. package/packs/finance/index.ts +30 -0
  19. package/packs/finance/invoice-summary-card.ts +48 -0
  20. package/packs/finance/reconcile-board.ts +450 -0
  21. package/packs/finance/reconcile-case-card.ts +70 -0
  22. package/packs/finance/reconcile-desk/compile.ts +208 -0
  23. package/packs/finance/reconcile-desk/index.ts +20 -0
  24. package/packs/finance/reconcile-desk/shell.ts +27 -0
  25. package/packs/finance/texts.ts +21 -0
  26. package/packs/ops/change-window-card.ts +54 -0
  27. package/packs/ops/dependency-status-card.ts +50 -0
  28. package/packs/ops/error-budget-card.ts +60 -0
  29. package/packs/ops/execution-task-runner.ts +61 -0
  30. package/packs/ops/index.ts +36 -0
  31. package/packs/ops/integration-status-card.ts +45 -0
  32. package/packs/ops/release-readiness-card.ts +63 -0
  33. package/packs/ops/runbook-execution-card.ts +81 -0
  34. package/packs/ops/texts.ts +21 -0
  35. package/packs/security/control-evidence-card.ts +54 -0
  36. package/packs/security/finding-card.ts +96 -0
  37. package/packs/security/index.ts +29 -0
  38. package/packs/security/texts.ts +31 -0
  39. package/packs/shared/card-util.ts +60 -0
  40. package/packs/shared/wrap.ts +13 -0
  41. package/spec/generated/kit-app.schema.json +84 -0
  42. package/spec/generated/kit-page.schema.json +2766 -0
  43. package/spec/kit-grammar.json +1358 -0
  44. package/spec/kit-grammar.schema.json +716 -0
  45. package/src/app/app-config.ts +108 -0
  46. package/src/app/compose-apps.ts +139 -0
  47. package/src/app/define-kit-actions.ts +89 -0
  48. package/src/app/define-kit-app.ts +362 -0
  49. package/src/app/define-kit-pack.ts +114 -0
  50. package/src/app/envelope.ts +117 -0
  51. package/src/app/index.ts +50 -0
  52. package/src/app/notify-renderer.ts +114 -0
  53. package/src/app/paged-list-adapter.ts +246 -0
  54. package/src/app/server-pages.ts +303 -0
  55. package/src/app/server.ts +244 -0
  56. package/src/app/submit.types.ts +87 -0
  57. package/src/base/action-busy.ts +159 -0
  58. package/src/base/action-gate.ts +267 -0
  59. package/src/base/action-status.ts +31 -0
  60. package/src/base/alert.ts +136 -0
  61. package/src/base/avatar.ts +271 -0
  62. package/src/base/button.ts +139 -0
  63. package/src/base/cascader.ts +523 -0
  64. package/src/base/check-core.ts +214 -0
  65. package/src/base/checkbox.ts +35 -0
  66. package/src/base/choice.ts +183 -0
  67. package/src/base/color-picker.ts +316 -0
  68. package/src/base/combobox.ts +61 -0
  69. package/src/base/command-palette.ts +371 -0
  70. package/src/base/context-menu.ts +103 -0
  71. package/src/base/countdown.ts +168 -0
  72. package/src/base/date-range.ts +444 -0
  73. package/src/base/date.ts +899 -0
  74. package/src/base/divider.ts +156 -0
  75. package/src/base/fab.ts +192 -0
  76. package/src/base/icons.ts +106 -0
  77. package/src/base/image.ts +177 -0
  78. package/src/base/index.ts +214 -0
  79. package/src/base/input.ts +316 -0
  80. package/src/base/kbd.ts +99 -0
  81. package/src/base/link.ts +167 -0
  82. package/src/base/listbox-core.ts +965 -0
  83. package/src/base/mentions.ts +323 -0
  84. package/src/base/menu-button.ts +240 -0
  85. package/src/base/menu-core.ts +341 -0
  86. package/src/base/month-grid.ts +171 -0
  87. package/src/base/motion/aura.ts +94 -0
  88. package/src/base/motion/hover-3d.ts +154 -0
  89. package/src/base/motion/hover-gallery.ts +185 -0
  90. package/src/base/motion/index.ts +27 -0
  91. package/src/base/motion/limits.ts +75 -0
  92. package/src/base/motion/marquee.ts +157 -0
  93. package/src/base/motion/text-rotate.ts +195 -0
  94. package/src/base/number.ts +121 -0
  95. package/src/base/otp.ts +259 -0
  96. package/src/base/permission-gate.ts +99 -0
  97. package/src/base/popover.ts +352 -0
  98. package/src/base/popup.ts +542 -0
  99. package/src/base/portal-core.ts +297 -0
  100. package/src/base/price-text.ts +126 -0
  101. package/src/base/progress.ts +216 -0
  102. package/src/base/qr-code.ts +446 -0
  103. package/src/base/qty-stepper.ts +241 -0
  104. package/src/base/radio.ts +33 -0
  105. package/src/base/range.ts +444 -0
  106. package/src/base/rating.ts +249 -0
  107. package/src/base/segmented.ts +286 -0
  108. package/src/base/select.ts +57 -0
  109. package/src/base/shared.ts +708 -0
  110. package/src/base/swap.ts +86 -0
  111. package/src/base/switch.ts +111 -0
  112. package/src/base/tag-input.ts +464 -0
  113. package/src/base/tag.ts +250 -0
  114. package/src/base/text.ts +126 -0
  115. package/src/base/textarea.ts +129 -0
  116. package/src/base/time-picker.ts +606 -0
  117. package/src/base/tree-select.ts +629 -0
  118. package/src/base/upload.ts +548 -0
  119. package/src/base/virtual-list.ts +286 -0
  120. package/src/biz/approval-desk/compile.ts +179 -0
  121. package/src/biz/approval-desk/index.ts +21 -0
  122. package/src/biz/approval-desk/shell.ts +50 -0
  123. package/src/biz/auth-panel/compile.ts +196 -0
  124. package/src/biz/auth-panel/index.ts +24 -0
  125. package/src/biz/auth-panel/shell.ts +46 -0
  126. package/src/biz/category-crud/compile.ts +173 -0
  127. package/src/biz/category-crud/index.ts +19 -0
  128. package/src/biz/category-crud/shell.ts +29 -0
  129. package/src/biz/checkout-page/compile.ts +111 -0
  130. package/src/biz/checkout-page/index.ts +20 -0
  131. package/src/biz/checkout-page/shell.ts +50 -0
  132. package/src/biz/compose.ts +313 -0
  133. package/src/biz/data-components.ts +26 -0
  134. package/src/biz/define.ts +23 -0
  135. package/src/biz/import-wizard/compile.ts +204 -0
  136. package/src/biz/import-wizard/hub.ts +540 -0
  137. package/src/biz/import-wizard/index.ts +24 -0
  138. package/src/biz/import-wizard/shell.ts +161 -0
  139. package/src/biz/index.ts +80 -0
  140. package/src/biz/landing-page/compile.ts +67 -0
  141. package/src/biz/landing-page/index.ts +20 -0
  142. package/src/biz/landing-page/shell.ts +48 -0
  143. package/src/biz/link/hub.ts +255 -0
  144. package/src/biz/link/shared.ts +493 -0
  145. package/src/biz/master-sub/compile.ts +232 -0
  146. package/src/biz/master-sub/index.ts +20 -0
  147. package/src/biz/master-sub/shell.ts +56 -0
  148. package/src/biz/multi-board/compile.ts +234 -0
  149. package/src/biz/multi-board/index.ts +19 -0
  150. package/src/biz/multi-board/shell.ts +70 -0
  151. package/src/biz/names.ts +30 -0
  152. package/src/biz/notification-center/compile.ts +138 -0
  153. package/src/biz/notification-center/index.ts +29 -0
  154. package/src/biz/notification-center/shell.ts +42 -0
  155. package/src/biz/page-templates/result-page/compile.ts +46 -0
  156. package/src/biz/page-templates/result-page/index.ts +19 -0
  157. package/src/biz/page-templates/result-page/shell.ts +31 -0
  158. package/src/biz/page-templates/shared.ts +121 -0
  159. package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
  160. package/src/biz/page-templates/sign-in-page/index.ts +18 -0
  161. package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
  162. package/src/biz/record-detail/compile.ts +290 -0
  163. package/src/biz/record-detail/index.ts +22 -0
  164. package/src/biz/record-detail/shell.ts +64 -0
  165. package/src/biz/settings-center/compile.ts +100 -0
  166. package/src/biz/settings-center/index.ts +18 -0
  167. package/src/biz/settings-center/shell.ts +51 -0
  168. package/src/biz/shared/action-host.ts +469 -0
  169. package/src/biz/shared/coordinator.ts +516 -0
  170. package/src/biz/shared/index.ts +9 -0
  171. package/src/biz/shared/pipes.ts +58 -0
  172. package/src/biz/shared/runtime-hub.ts +112 -0
  173. package/src/biz/shared/step-values.ts +25 -0
  174. package/src/biz/single-form/compile.ts +146 -0
  175. package/src/biz/single-form/index.ts +18 -0
  176. package/src/biz/single-form/shell.ts +38 -0
  177. package/src/biz/standard-crud/bridge.ts +11 -0
  178. package/src/biz/standard-crud/compile.ts +546 -0
  179. package/src/biz/standard-crud/index.ts +18 -0
  180. package/src/biz/standard-crud/shell.ts +157 -0
  181. package/src/biz/step-form/compile.ts +400 -0
  182. package/src/biz/step-form/hub.ts +412 -0
  183. package/src/biz/step-form/index.ts +23 -0
  184. package/src/biz/step-form/shell.ts +96 -0
  185. package/src/biz/step-form/steps-ref.ts +112 -0
  186. package/src/biz/types.ts +96 -0
  187. package/src/cli/kit-cli.ts +102 -0
  188. package/src/compile/action-host-attach.ts +76 -0
  189. package/src/compile/compile-page.ts +472 -0
  190. package/src/compile/component-candidates.ts +147 -0
  191. package/src/compile/fragment.ts +104 -0
  192. package/src/compile/hints.ts +255 -0
  193. package/src/compile/index.ts +16 -0
  194. package/src/compile/locate.ts +166 -0
  195. package/src/compile/page-params.ts +80 -0
  196. package/src/compile/parse.ts +355 -0
  197. package/src/compile/redirect.ts +90 -0
  198. package/src/compile/registry.ts +30 -0
  199. package/src/compile/remove-guard.ts +99 -0
  200. package/src/compile/styles.ts +244 -0
  201. package/src/compile/types.ts +106 -0
  202. package/src/data/amount-breakdown.ts +132 -0
  203. package/src/data/anchor-nav.ts +225 -0
  204. package/src/data/approval-flow.ts +269 -0
  205. package/src/data/assignment-picker.ts +652 -0
  206. package/src/data/async-result-panel.ts +308 -0
  207. package/src/data/breadcrumbs.ts +197 -0
  208. package/src/data/calendar.ts +363 -0
  209. package/src/data/carousel.ts +408 -0
  210. package/src/data/chart.ts +726 -0
  211. package/src/data/checklist.ts +215 -0
  212. package/src/data/code-view.ts +415 -0
  213. package/src/data/comment-thread.ts +342 -0
  214. package/src/data/confirm-dialog.ts +144 -0
  215. package/src/data/context-menu.ts +216 -0
  216. package/src/data/d9-limits.ts +42 -0
  217. package/src/data/d9-util.ts +81 -0
  218. package/src/data/diff.ts +239 -0
  219. package/src/data/display-util.ts +135 -0
  220. package/src/data/dock.ts +152 -0
  221. package/src/data/embed.ts +200 -0
  222. package/src/data/field-mapper.ts +544 -0
  223. package/src/data/flow-editor-contract.ts +41 -0
  224. package/src/data/flow-editor.ts +2622 -0
  225. package/src/data/flow-remote-options.ts +257 -0
  226. package/src/data/footer.ts +157 -0
  227. package/src/data/form-draft-registry.ts +76 -0
  228. package/src/data/gantt.ts +430 -0
  229. package/src/data/hero.ts +149 -0
  230. package/src/data/image-viewer.ts +333 -0
  231. package/src/data/index.ts +268 -0
  232. package/src/data/item-list.ts +335 -0
  233. package/src/data/kanban.ts +667 -0
  234. package/src/data/media-grid.ts +246 -0
  235. package/src/data/mega-menu.ts +257 -0
  236. package/src/data/menu-dom.ts +169 -0
  237. package/src/data/menu.ts +464 -0
  238. package/src/data/mockup.ts +176 -0
  239. package/src/data/modal-dialog.ts +182 -0
  240. package/src/data/navbar.ts +292 -0
  241. package/src/data/object-form.ts +1981 -0
  242. package/src/data/options-bus.ts +24 -0
  243. package/src/data/outcome-watch.ts +40 -0
  244. package/src/data/overlay-portal.ts +6 -0
  245. package/src/data/pager.ts +473 -0
  246. package/src/data/permission-matrix.ts +432 -0
  247. package/src/data/permission-tree.ts +916 -0
  248. package/src/data/pricing-table.ts +269 -0
  249. package/src/data/prompt-dialog.ts +235 -0
  250. package/src/data/reaction-bar.ts +236 -0
  251. package/src/data/record-card.ts +413 -0
  252. package/src/data/record-picker.ts +489 -0
  253. package/src/data/redirect.ts +109 -0
  254. package/src/data/remote-options.ts +54 -0
  255. package/src/data/request-console.ts +399 -0
  256. package/src/data/resident.ts +58 -0
  257. package/src/data/result-panel.ts +160 -0
  258. package/src/data/rich-text.ts +626 -0
  259. package/src/data/row-editor.ts +1066 -0
  260. package/src/data/rule-builder.ts +1137 -0
  261. package/src/data/shape-util.ts +221 -0
  262. package/src/data/staged-rows.ts +69 -0
  263. package/src/data/stat-group.ts +231 -0
  264. package/src/data/static-lazy.ts +63 -0
  265. package/src/data/static-registry.ts +227 -0
  266. package/src/data/steps.ts +195 -0
  267. package/src/data/survey.ts +455 -0
  268. package/src/data/system-switcher.ts +243 -0
  269. package/src/data/timeline.ts +204 -0
  270. package/src/data/tour-guide.ts +392 -0
  271. package/src/data/transfer.ts +597 -0
  272. package/src/data/tree-check.ts +30 -0
  273. package/src/data/tree-table.ts +674 -0
  274. package/src/data/tree.ts +656 -0
  275. package/src/data/trend-line.ts +147 -0
  276. package/src/data/virtual-rows.ts +556 -0
  277. package/src/data/watermark.ts +140 -0
  278. package/src/data/wrap.ts +267 -0
  279. package/src/data/wrapped-candidates.ts +96 -0
  280. package/src/frames/blank-frame.ts +19 -0
  281. package/src/frames/index.ts +44 -0
  282. package/src/frames/page-bar.ts +185 -0
  283. package/src/frames/page-header.ts +185 -0
  284. package/src/frames/page-status.ts +54 -0
  285. package/src/frames/resize-handle.ts +147 -0
  286. package/src/frames/shared.ts +242 -0
  287. package/src/frames/single-frame.ts +16 -0
  288. package/src/frames/split-frame/index.ts +4 -0
  289. package/src/frames/split-frame/shell.ts +219 -0
  290. package/src/frames/split-frame/span.ts +64 -0
  291. package/src/frames/split-frame/wiring.ts +164 -0
  292. package/src/frames/tabs-frame/index.ts +3 -0
  293. package/src/frames/tabs-frame/shell.ts +112 -0
  294. package/src/frames/tabs-frame/wiring.ts +69 -0
  295. package/src/frames/top-main-frame.ts +20 -0
  296. package/src/frames/types.ts +72 -0
  297. package/src/frames/workspace-frame/extras.ts +197 -0
  298. package/src/frames/workspace-frame/index.ts +13 -0
  299. package/src/frames/workspace-frame/shell.ts +282 -0
  300. package/src/frames/workspace-frame/state.ts +152 -0
  301. package/src/frames/workspace-frame/view.ts +1013 -0
  302. package/src/generated/kit-grammar-runtime.ts +2822 -0
  303. package/src/generated/page-origin.ts +57 -0
  304. package/src/i18n/index.ts +22 -0
  305. package/src/i18n/kit-text.ts +692 -0
  306. package/src/i18n/resolve-text-refs.ts +128 -0
  307. package/src/index.ts +6 -0
  308. package/src/object-renderer/action-gate.ts +216 -0
  309. package/src/object-renderer/adopt-gate.ts +333 -0
  310. package/src/object-renderer/arrange.ts +411 -0
  311. package/src/object-renderer/candidates.ts +68 -0
  312. package/src/object-renderer/collapse-wiring.ts +99 -0
  313. package/src/object-renderer/collection-expand.ts +185 -0
  314. package/src/object-renderer/collection-parts.ts +653 -0
  315. package/src/object-renderer/collection-table.ts +503 -0
  316. package/src/object-renderer/collection.ts +628 -0
  317. package/src/object-renderer/compile-data.ts +549 -0
  318. package/src/object-renderer/defaults.ts +252 -0
  319. package/src/object-renderer/display-checks.ts +153 -0
  320. package/src/object-renderer/emit-events.ts +498 -0
  321. package/src/object-renderer/emit-object.ts +98 -0
  322. package/src/object-renderer/emit-static.ts +1036 -0
  323. package/src/object-renderer/field-policy.ts +89 -0
  324. package/src/object-renderer/field-value.ts +581 -0
  325. package/src/object-renderer/form-detail.ts +116 -0
  326. package/src/object-renderer/index.ts +13 -0
  327. package/src/object-renderer/linkage.ts +371 -0
  328. package/src/object-renderer/merge-class.ts +126 -0
  329. package/src/object-renderer/mode.ts +25 -0
  330. package/src/object-renderer/outcome-draft.ts +61 -0
  331. package/src/object-renderer/parts.ts +136 -0
  332. package/src/object-renderer/pick-component.ts +36 -0
  333. package/src/object-renderer/render-object.ts +724 -0
  334. package/src/object-renderer/request-actions.ts +581 -0
  335. package/src/object-renderer/skeleton.ts +101 -0
  336. package/src/object-renderer/table-actions.ts +438 -0
  337. package/src/object-renderer/table-summary.ts +105 -0
  338. package/src/object-renderer/table-tools.ts +1072 -0
  339. package/src/object-renderer/types.ts +936 -0
  340. package/src/page-target/ai-surface.ts +154 -0
  341. package/src/page-target/compile.ts +354 -0
  342. package/src/page-target/drift.ts +186 -0
  343. package/src/page-target/index.ts +25 -0
  344. package/src/page-target/intent-map.ts +137 -0
  345. package/src/page-target/intent-schema.ts +711 -0
  346. package/src/page-target/origin.ts +17 -0
  347. package/src/page-target/target.ts +450 -0
  348. package/src/page-target/writer-policy.ts +315 -0
  349. package/src/theme/block-theme.ts +202 -0
  350. package/src/theme/kit-theme-text.ts +2 -0
  351. package/src/theme/kit-theme.css +275 -0
  352. package/src/theme/kit-theme.tpl +275 -0
  353. package/src/theme/theme-tokens.ts +135 -0
@@ -0,0 +1,275 @@
1
+ /*
2
+ * 用 @theme inline:值引用 var(--soma-*),inline 让工具类直接展开成 var(--soma-*),
3
+ * 运行时换主题、切密度时跟着变,不被 @theme 提前固化到 :root 的 --color-* 副本上。
4
+ * core 样式引擎禁止 @import / @plugin / @config,Tailwind 默认色板与尺度全为空,
5
+ * 所以这里必须自带用到的全部尺度;没声明的键不会生成工具类。
6
+ * 尺度允许的键见 spec/kit-grammar.json 的 utilityScales;尺度里的数字(容器档、命中区、透视、模糊、动画时长等)
7
+ * 由 scripts/build-kit-theme.mjs 从 soma-design/spec/pipeline/kit-limits.json 写入,本文件由 src/theme/kit-theme.tpl 生成,勿手改。
8
+ */
9
+ @theme inline {
10
+ --color-surface: var(--soma-surface-base);
11
+ --color-surface-sunken: var(--soma-surface-sunken);
12
+ --color-surface-raised: var(--soma-surface-raised);
13
+
14
+ --color-fg: var(--soma-text-primary);
15
+ --color-fg-muted: var(--soma-text-secondary);
16
+ --color-fg-subtle: var(--soma-text-muted);
17
+
18
+ --color-border: var(--soma-border-control);
19
+ --color-border-subtle: var(--soma-border-hairline);
20
+ --color-subtle: var(--soma-border-hairline);
21
+ --color-input: color-mix(in oklab, var(--soma-border-control) 60%, var(--soma-surface-base));
22
+ --color-input-hover: var(--soma-border-control);
23
+
24
+ --color-primary: var(--soma-c-primary);
25
+ --color-primary-fg: var(--soma-c-primary-fg);
26
+ --color-primary-soft: var(--soma-c-primary-soft);
27
+ --color-primary-on-soft: var(--soma-c-primary-on-soft);
28
+ --color-primary-hover: var(--soma-c-primary-hover);
29
+ --color-primary-active: var(--soma-c-primary-active);
30
+
31
+ --color-success: var(--soma-c-success);
32
+ --color-success-fg: var(--soma-c-success-fg);
33
+ --color-success-soft: var(--soma-c-success-soft);
34
+ --color-success-on-soft: var(--soma-c-success-on-soft);
35
+
36
+ --color-warning: var(--soma-c-warning);
37
+ --color-warning-fg: var(--soma-c-warning-fg);
38
+ --color-warning-soft: var(--soma-c-warning-soft);
39
+ --color-warning-on-soft: var(--soma-c-warning-on-soft);
40
+
41
+ --color-danger: var(--soma-c-danger);
42
+ --color-danger-fg: var(--soma-c-danger-fg);
43
+ --color-danger-soft: var(--soma-c-danger-soft);
44
+ --color-danger-on-soft: var(--soma-c-danger-on-soft);
45
+ --color-danger-hover: var(--soma-c-danger-hover);
46
+ --color-danger-active: var(--soma-c-danger-active);
47
+
48
+ --color-info: var(--soma-c-info);
49
+ --color-info-fg: var(--soma-c-info-fg);
50
+ --color-info-soft: var(--soma-c-info-soft);
51
+ --color-info-on-soft: var(--soma-c-info-on-soft);
52
+
53
+ --color-ring: var(--soma-focus-ring);
54
+
55
+ --spacing: var(--soma-space-1);
56
+
57
+ --radius-sm: var(--soma-radius-sm);
58
+ --radius-md: var(--soma-radius-md);
59
+ --radius-lg: var(--soma-radius-lg);
60
+ --radius-xl: var(--soma-radius-xl);
61
+ --radius-full: var(--soma-radius-full);
62
+
63
+ --text-xs: var(--soma-font-size-xs);
64
+ --text-xs--line-height: var(--soma-line-height-xs);
65
+ --text-sm: var(--soma-font-size-sm);
66
+ --text-sm--line-height: var(--soma-line-height-sm);
67
+ --text-base: var(--soma-font-size-md);
68
+ --text-base--line-height: var(--soma-line-height-md);
69
+ --text-lg: var(--soma-font-size-lg);
70
+ --text-lg--line-height: var(--soma-line-height-lg);
71
+ --text-xl: var(--soma-font-size-xl);
72
+ --text-xl--line-height: var(--soma-line-height-xl);
73
+ --text-2xl: var(--soma-font-size-xxl);
74
+ --text-2xl--line-height: var(--soma-line-height-xxl);
75
+
76
+ --font-weight-normal: var(--soma-font-weight-normal);
77
+ --font-weight-medium: var(--soma-font-weight-medium);
78
+ --font-weight-semibold: var(--soma-font-weight-bold);
79
+ --font-weight-bold: var(--soma-font-weight-heavy);
80
+
81
+ --font-sans: var(--soma-font-family);
82
+ --font-mono: var(--soma-font-family-mono);
83
+
84
+ --shadow-xs: var(--soma-shadow-step-0);
85
+ --shadow-sm: var(--soma-shadow-step-1);
86
+ --shadow-md: var(--soma-shadow-step-2);
87
+ --shadow-lg: var(--soma-shadow-popover);
88
+ --shadow-xl: var(--soma-shadow-dialog);
89
+
90
+ --ease-standard: var(--soma-motion-easing-standard);
91
+ --ease-enter: var(--soma-motion-easing-enter);
92
+ --ease-exit: var(--soma-motion-easing-exit);
93
+ --ease-emphasized: var(--soma-motion-spring-emphasized-easing);
94
+
95
+ --default-transition-duration: var(--soma-motion-duration-base);
96
+ --default-transition-timing-function: var(--soma-motion-easing-standard);
97
+
98
+ --container-xs: 20rem;
99
+ --container-sm: 24rem;
100
+ --container-md: 28rem;
101
+ --container-lg: 36rem;
102
+ --container-xl: 40rem;
103
+ --container-2xl: 48rem;
104
+ --container-3xl: 56rem;
105
+ --container-4xl: 64rem;
106
+
107
+ --aspect-video: 16 / 9;
108
+ }
109
+
110
+ /*
111
+ * 进退动效组:时长与缓动成对取自 design 动效真源(进入 200ms、退出 150ms,退出短于进入;减少动效档令牌自动归 100ms / linear)。
112
+ * motion-enter 用于出现,motion-exit 用于消失,motion-emphasized 用于强调进入(弹簧曲线);使用处一律 motion-safe: 前缀。
113
+ * 命中区 hit-area:小控件的不可见扩展点击区(伪元素铺满),最小边长取 design adaptive#/…/hitTarget(精细指针 24px、粗指针 44px,生成时换算成 rem);
114
+ * 宿主元素自带 relative 定位,宿主本身要有 overflow 可见。
115
+ * 文本框去自动填充底色 autofill-clear:文本类输入(input / textarea)与 appearance-none 同用,:-webkit-autofill 的黄 / 蓝底改回令牌色(surface-base / text-primary);
116
+ * 数字框不再用原生 type=number(改 type=text + role=spinbutton,步进自绘),所以没有隐藏原生微调钮的类。
117
+ */
118
+ @utility motion-enter {
119
+ transition-duration: var(--soma-motion-duration-enter);
120
+ transition-timing-function: var(--soma-motion-easing-enter);
121
+ }
122
+
123
+ @utility motion-exit {
124
+ transition-duration: var(--soma-motion-duration-exit);
125
+ transition-timing-function: var(--soma-motion-easing-exit);
126
+ }
127
+
128
+ @utility motion-emphasized {
129
+ transition-duration: var(--soma-motion-spring-emphasized-duration);
130
+ transition-timing-function: var(--soma-motion-spring-emphasized-easing);
131
+ }
132
+
133
+ @utility autofill-clear {
134
+ &:-webkit-autofill,
135
+ &:-webkit-autofill:hover,
136
+ &:-webkit-autofill:focus {
137
+ -webkit-text-fill-color: var(--soma-text-primary);
138
+ caret-color: var(--soma-text-primary);
139
+ box-shadow: 0 0 0 100vmax var(--soma-surface-base) inset;
140
+ transition: background-color 9999s ease-out 0s;
141
+ }
142
+ }
143
+
144
+ @utility hit-area {
145
+ position: relative;
146
+
147
+ &::after {
148
+ content: '';
149
+ position: absolute;
150
+ top: 50%;
151
+ left: 50%;
152
+ width: max(100%, 1.5rem);
153
+ height: max(100%, 1.5rem);
154
+ transform: translate(-50%, -50%);
155
+ }
156
+
157
+ @media (pointer: coarse) {
158
+ &::after {
159
+ width: max(100%, 2.75rem);
160
+ height: max(100%, 2.75rem);
161
+ }
162
+ }
163
+ }
164
+
165
+ /* 导航件(Menu / Navbar / MegaMenu / workspace-frame)的弹层入场;使用处一律 motion-safe: 前缀 */
166
+ @theme inline {
167
+ --animate-kit-menu-in: kit-menu-in var(--soma-motion-duration-base) var(--soma-motion-easing-standard);
168
+
169
+ @keyframes kit-menu-in {
170
+ from {
171
+ opacity: 0;
172
+ transform: translateY(-0.25rem);
173
+ }
174
+ to {
175
+ opacity: 1;
176
+ transform: translateY(0);
177
+ }
178
+ }
179
+ }
180
+
181
+ /* 状态件(StatusDot 脉冲、ProgressBar 不确定态):使用处一律 motion-safe: 前缀,motion-reduce 下静止 */
182
+ @theme inline {
183
+ --animate-kit-ping: kit-ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;
184
+ --animate-kit-indeterminate: kit-indeterminate 1.4s ease-in-out infinite;
185
+
186
+ @keyframes kit-ping {
187
+ 75%,
188
+ 100% {
189
+ opacity: 0;
190
+ transform: scale(2.2);
191
+ }
192
+ }
193
+
194
+ @keyframes kit-indeterminate {
195
+ from {
196
+ transform: translateX(-100%);
197
+ }
198
+ to {
199
+ transform: translateX(250%);
200
+ }
201
+ }
202
+ }
203
+
204
+ /* 动效展示件(TextRotate / Hover3d / HoverGallery / Aura / Marquee):关键帧与透视、模糊刻度;使用处一律 motion-safe: 前缀,motion-reduce 下静止 */
205
+ @theme inline {
206
+ --perspective-normal: 1000px;
207
+ --blur-sm: 4px;
208
+ --blur-md: 12px;
209
+
210
+ --animate-kit-rise: kit-rise var(--soma-motion-duration-base) var(--soma-motion-easing-standard);
211
+ --animate-kit-fade: kit-fade var(--soma-motion-duration-base) var(--soma-motion-easing-standard);
212
+ --animate-kit-aura: kit-aura 3s ease-in-out infinite;
213
+ --animate-kit-marquee-slow: kit-marquee 40s linear infinite;
214
+ --animate-kit-marquee-slow-paused: kit-marquee 40s linear infinite paused;
215
+ --animate-kit-marquee-normal: kit-marquee 25s linear infinite;
216
+ --animate-kit-marquee-normal-paused: kit-marquee 25s linear infinite paused;
217
+ --animate-kit-marquee-fast: kit-marquee 12s linear infinite;
218
+ --animate-kit-marquee-fast-paused: kit-marquee 12s linear infinite paused;
219
+
220
+ @keyframes kit-rise {
221
+ from {
222
+ opacity: 0;
223
+ transform: translateY(0.5rem);
224
+ }
225
+ to {
226
+ opacity: 1;
227
+ transform: translateY(0);
228
+ }
229
+ }
230
+
231
+ @keyframes kit-fade {
232
+ from {
233
+ opacity: 0;
234
+ }
235
+ to {
236
+ opacity: 1;
237
+ }
238
+ }
239
+
240
+ @keyframes kit-aura {
241
+ 0%,
242
+ 100% {
243
+ opacity: 0.5;
244
+ transform: scale(1);
245
+ }
246
+ 50% {
247
+ opacity: 1;
248
+ transform: scale(1.03);
249
+ }
250
+ }
251
+
252
+ @keyframes kit-marquee {
253
+ from {
254
+ transform: translateX(0);
255
+ }
256
+ to {
257
+ transform: translateX(-50%);
258
+ }
259
+ }
260
+ }
261
+
262
+ /* 骨架屏(KitCollectionState 的 loading: skeleton):呼吸占位;使用处一律 motion-safe: 前缀,减少动效下静止 */
263
+ @theme inline {
264
+ --animate-kit-pulse: kit-pulse 2s ease-in-out infinite;
265
+
266
+ @keyframes kit-pulse {
267
+ 0%,
268
+ 100% {
269
+ opacity: 1;
270
+ }
271
+ 50% {
272
+ opacity: 0.5;
273
+ }
274
+ }
275
+ }
@@ -0,0 +1,275 @@
1
+ /*
2
+ * 用 @theme inline:值引用 var(--soma-*),inline 让工具类直接展开成 var(--soma-*),
3
+ * 运行时换主题、切密度时跟着变,不被 @theme 提前固化到 :root 的 --color-* 副本上。
4
+ * core 样式引擎禁止 @import / @plugin / @config,Tailwind 默认色板与尺度全为空,
5
+ * 所以这里必须自带用到的全部尺度;没声明的键不会生成工具类。
6
+ * 尺度允许的键见 spec/kit-grammar.json 的 utilityScales;尺度里的数字(容器档、命中区、透视、模糊、动画时长等)
7
+ * 由 scripts/build-kit-theme.mjs 从 soma-design/spec/pipeline/kit-limits.json 写入,本文件由 src/theme/kit-theme.tpl 生成,勿手改。
8
+ */
9
+ @theme inline {
10
+ --color-surface: var(--soma-surface-base);
11
+ --color-surface-sunken: var(--soma-surface-sunken);
12
+ --color-surface-raised: var(--soma-surface-raised);
13
+
14
+ --color-fg: var(--soma-text-primary);
15
+ --color-fg-muted: var(--soma-text-secondary);
16
+ --color-fg-subtle: var(--soma-text-muted);
17
+
18
+ --color-border: var(--soma-border-control);
19
+ --color-border-subtle: var(--soma-border-hairline);
20
+ --color-subtle: var(--soma-border-hairline);
21
+ --color-input: color-mix(in oklab, var(--soma-border-control) 60%, var(--soma-surface-base));
22
+ --color-input-hover: var(--soma-border-control);
23
+
24
+ --color-primary: var(--soma-c-primary);
25
+ --color-primary-fg: var(--soma-c-primary-fg);
26
+ --color-primary-soft: var(--soma-c-primary-soft);
27
+ --color-primary-on-soft: var(--soma-c-primary-on-soft);
28
+ --color-primary-hover: var(--soma-c-primary-hover);
29
+ --color-primary-active: var(--soma-c-primary-active);
30
+
31
+ --color-success: var(--soma-c-success);
32
+ --color-success-fg: var(--soma-c-success-fg);
33
+ --color-success-soft: var(--soma-c-success-soft);
34
+ --color-success-on-soft: var(--soma-c-success-on-soft);
35
+
36
+ --color-warning: var(--soma-c-warning);
37
+ --color-warning-fg: var(--soma-c-warning-fg);
38
+ --color-warning-soft: var(--soma-c-warning-soft);
39
+ --color-warning-on-soft: var(--soma-c-warning-on-soft);
40
+
41
+ --color-danger: var(--soma-c-danger);
42
+ --color-danger-fg: var(--soma-c-danger-fg);
43
+ --color-danger-soft: var(--soma-c-danger-soft);
44
+ --color-danger-on-soft: var(--soma-c-danger-on-soft);
45
+ --color-danger-hover: var(--soma-c-danger-hover);
46
+ --color-danger-active: var(--soma-c-danger-active);
47
+
48
+ --color-info: var(--soma-c-info);
49
+ --color-info-fg: var(--soma-c-info-fg);
50
+ --color-info-soft: var(--soma-c-info-soft);
51
+ --color-info-on-soft: var(--soma-c-info-on-soft);
52
+
53
+ --color-ring: var(--soma-focus-ring);
54
+
55
+ --spacing: var(--soma-space-1);
56
+
57
+ --radius-sm: var(--soma-radius-sm);
58
+ --radius-md: var(--soma-radius-md);
59
+ --radius-lg: var(--soma-radius-lg);
60
+ --radius-xl: var(--soma-radius-xl);
61
+ --radius-full: var(--soma-radius-full);
62
+
63
+ --text-xs: var(--soma-font-size-xs);
64
+ --text-xs--line-height: var(--soma-line-height-xs);
65
+ --text-sm: var(--soma-font-size-sm);
66
+ --text-sm--line-height: var(--soma-line-height-sm);
67
+ --text-base: var(--soma-font-size-md);
68
+ --text-base--line-height: var(--soma-line-height-md);
69
+ --text-lg: var(--soma-font-size-lg);
70
+ --text-lg--line-height: var(--soma-line-height-lg);
71
+ --text-xl: var(--soma-font-size-xl);
72
+ --text-xl--line-height: var(--soma-line-height-xl);
73
+ --text-2xl: var(--soma-font-size-xxl);
74
+ --text-2xl--line-height: var(--soma-line-height-xxl);
75
+
76
+ --font-weight-normal: var(--soma-font-weight-normal);
77
+ --font-weight-medium: var(--soma-font-weight-medium);
78
+ --font-weight-semibold: var(--soma-font-weight-bold);
79
+ --font-weight-bold: var(--soma-font-weight-heavy);
80
+
81
+ --font-sans: var(--soma-font-family);
82
+ --font-mono: var(--soma-font-family-mono);
83
+
84
+ --shadow-xs: var(--soma-shadow-step-0);
85
+ --shadow-sm: var(--soma-shadow-step-1);
86
+ --shadow-md: var(--soma-shadow-step-2);
87
+ --shadow-lg: var(--soma-shadow-popover);
88
+ --shadow-xl: var(--soma-shadow-dialog);
89
+
90
+ --ease-standard: var(--soma-motion-easing-standard);
91
+ --ease-enter: var(--soma-motion-easing-enter);
92
+ --ease-exit: var(--soma-motion-easing-exit);
93
+ --ease-emphasized: var(--soma-motion-spring-emphasized-easing);
94
+
95
+ --default-transition-duration: var(--soma-motion-duration-base);
96
+ --default-transition-timing-function: var(--soma-motion-easing-standard);
97
+
98
+ --container-xs: {{utilityScales.container.rem.xs}}rem;
99
+ --container-sm: {{utilityScales.container.rem.sm}}rem;
100
+ --container-md: {{utilityScales.container.rem.md}}rem;
101
+ --container-lg: {{utilityScales.container.rem.lg}}rem;
102
+ --container-xl: {{utilityScales.container.rem.xl}}rem;
103
+ --container-2xl: {{utilityScales.container.rem.2xl}}rem;
104
+ --container-3xl: {{utilityScales.container.rem.3xl}}rem;
105
+ --container-4xl: {{utilityScales.container.rem.4xl}}rem;
106
+
107
+ --aspect-video: {{themeScales.aspectVideo.w}} / {{themeScales.aspectVideo.h}};
108
+ }
109
+
110
+ /*
111
+ * 进退动效组:时长与缓动成对取自 design 动效真源(进入 200ms、退出 150ms,退出短于进入;减少动效档令牌自动归 100ms / linear)。
112
+ * motion-enter 用于出现,motion-exit 用于消失,motion-emphasized 用于强调进入(弹簧曲线);使用处一律 motion-safe: 前缀。
113
+ * 命中区 hit-area:小控件的不可见扩展点击区(伪元素铺满),最小边长取 design adaptive#/…/hitTarget(精细指针 24px、粗指针 44px,生成时换算成 rem);
114
+ * 宿主元素自带 relative 定位,宿主本身要有 overflow 可见。
115
+ * 文本框去自动填充底色 autofill-clear:文本类输入(input / textarea)与 appearance-none 同用,:-webkit-autofill 的黄 / 蓝底改回令牌色(surface-base / text-primary);
116
+ * 数字框不再用原生 type=number(改 type=text + role=spinbutton,步进自绘),所以没有隐藏原生微调钮的类。
117
+ */
118
+ @utility motion-enter {
119
+ transition-duration: var(--soma-motion-duration-enter);
120
+ transition-timing-function: var(--soma-motion-easing-enter);
121
+ }
122
+
123
+ @utility motion-exit {
124
+ transition-duration: var(--soma-motion-duration-exit);
125
+ transition-timing-function: var(--soma-motion-easing-exit);
126
+ }
127
+
128
+ @utility motion-emphasized {
129
+ transition-duration: var(--soma-motion-spring-emphasized-duration);
130
+ transition-timing-function: var(--soma-motion-spring-emphasized-easing);
131
+ }
132
+
133
+ @utility autofill-clear {
134
+ &:-webkit-autofill,
135
+ &:-webkit-autofill:hover,
136
+ &:-webkit-autofill:focus {
137
+ -webkit-text-fill-color: var(--soma-text-primary);
138
+ caret-color: var(--soma-text-primary);
139
+ box-shadow: 0 0 0 100vmax var(--soma-surface-base) inset;
140
+ transition: background-color 9999s ease-out 0s;
141
+ }
142
+ }
143
+
144
+ @utility hit-area {
145
+ position: relative;
146
+
147
+ &::after {
148
+ content: '';
149
+ position: absolute;
150
+ top: 50%;
151
+ left: 50%;
152
+ width: max(100%, {{rem:utilityScales.hitArea.minPx.fine}}rem);
153
+ height: max(100%, {{rem:utilityScales.hitArea.minPx.fine}}rem);
154
+ transform: translate(-50%, -50%);
155
+ }
156
+
157
+ @media (pointer: coarse) {
158
+ &::after {
159
+ width: max(100%, {{rem:utilityScales.hitArea.minPx.coarse}}rem);
160
+ height: max(100%, {{rem:utilityScales.hitArea.minPx.coarse}}rem);
161
+ }
162
+ }
163
+ }
164
+
165
+ /* 导航件(Menu / Navbar / MegaMenu / workspace-frame)的弹层入场;使用处一律 motion-safe: 前缀 */
166
+ @theme inline {
167
+ --animate-kit-menu-in: kit-menu-in var(--soma-motion-duration-base) var(--soma-motion-easing-standard);
168
+
169
+ @keyframes kit-menu-in {
170
+ from {
171
+ opacity: 0;
172
+ transform: translateY(-{{themeScales.menuIn.offsetRem}}rem);
173
+ }
174
+ to {
175
+ opacity: 1;
176
+ transform: translateY(0);
177
+ }
178
+ }
179
+ }
180
+
181
+ /* 状态件(StatusDot 脉冲、ProgressBar 不确定态):使用处一律 motion-safe: 前缀,motion-reduce 下静止 */
182
+ @theme inline {
183
+ --animate-kit-ping: kit-ping {{themeScales.ping.durationS}}s cubic-bezier({{themeScales.ping.bezier}}) infinite;
184
+ --animate-kit-indeterminate: kit-indeterminate {{themeScales.indeterminate.durationS}}s ease-in-out infinite;
185
+
186
+ @keyframes kit-ping {
187
+ {{themeScales.ping.holdPct}}%,
188
+ 100% {
189
+ opacity: 0;
190
+ transform: scale({{themeScales.ping.scale}});
191
+ }
192
+ }
193
+
194
+ @keyframes kit-indeterminate {
195
+ from {
196
+ transform: translateX({{themeScales.indeterminate.fromPct}}%);
197
+ }
198
+ to {
199
+ transform: translateX({{themeScales.indeterminate.toPct}}%);
200
+ }
201
+ }
202
+ }
203
+
204
+ /* 动效展示件(TextRotate / Hover3d / HoverGallery / Aura / Marquee):关键帧与透视、模糊刻度;使用处一律 motion-safe: 前缀,motion-reduce 下静止 */
205
+ @theme inline {
206
+ --perspective-normal: {{themeScales.perspective.normal}}px;
207
+ --blur-sm: {{themeScales.blurPx.sm}}px;
208
+ --blur-md: {{themeScales.blurPx.md}}px;
209
+
210
+ --animate-kit-rise: kit-rise var(--soma-motion-duration-base) var(--soma-motion-easing-standard);
211
+ --animate-kit-fade: kit-fade var(--soma-motion-duration-base) var(--soma-motion-easing-standard);
212
+ --animate-kit-aura: kit-aura {{themeScales.aura.durationS}}s ease-in-out infinite;
213
+ --animate-kit-marquee-slow: kit-marquee {{themeScales.marquee.slowS}}s linear infinite;
214
+ --animate-kit-marquee-slow-paused: kit-marquee {{themeScales.marquee.slowS}}s linear infinite paused;
215
+ --animate-kit-marquee-normal: kit-marquee {{themeScales.marquee.normalS}}s linear infinite;
216
+ --animate-kit-marquee-normal-paused: kit-marquee {{themeScales.marquee.normalS}}s linear infinite paused;
217
+ --animate-kit-marquee-fast: kit-marquee {{themeScales.marquee.fastS}}s linear infinite;
218
+ --animate-kit-marquee-fast-paused: kit-marquee {{themeScales.marquee.fastS}}s linear infinite paused;
219
+
220
+ @keyframes kit-rise {
221
+ from {
222
+ opacity: 0;
223
+ transform: translateY({{themeScales.rise.offsetRem}}rem);
224
+ }
225
+ to {
226
+ opacity: 1;
227
+ transform: translateY(0);
228
+ }
229
+ }
230
+
231
+ @keyframes kit-fade {
232
+ from {
233
+ opacity: 0;
234
+ }
235
+ to {
236
+ opacity: 1;
237
+ }
238
+ }
239
+
240
+ @keyframes kit-aura {
241
+ 0%,
242
+ 100% {
243
+ opacity: {{themeScales.aura.lowOpacity}};
244
+ transform: scale(1);
245
+ }
246
+ {{themeScales.aura.midPct}}% {
247
+ opacity: 1;
248
+ transform: scale({{themeScales.aura.scale}});
249
+ }
250
+ }
251
+
252
+ @keyframes kit-marquee {
253
+ from {
254
+ transform: translateX(0);
255
+ }
256
+ to {
257
+ transform: translateX({{themeScales.marquee.endPct}}%);
258
+ }
259
+ }
260
+ }
261
+
262
+ /* 骨架屏(KitCollectionState 的 loading: skeleton):呼吸占位;使用处一律 motion-safe: 前缀,减少动效下静止 */
263
+ @theme inline {
264
+ --animate-kit-pulse: kit-pulse {{themeScales.pulse.durationS}}s ease-in-out infinite;
265
+
266
+ @keyframes kit-pulse {
267
+ 0%,
268
+ 100% {
269
+ opacity: 1;
270
+ }
271
+ 50% {
272
+ opacity: {{themeScales.pulse.lowOpacity}};
273
+ }
274
+ }
275
+ }
@@ -0,0 +1,135 @@
1
+ // 令牌 CSS:kit.app.yaml 的 `theme` 声明 -> soma-foundation 主题流水线(意图折叠 -> 令牌求解)-> `:root` 亮色块 + 暗色块。
2
+ // 本文件只做序列化与取值域校验:所有令牌值由 foundation 求出,kit 不手写任何色值、字号、间距。
3
+ // 只在服务端 / 构建面使用(server.ts 调用);不进浏览器包。
4
+ //
5
+ // 产物(顺序固定,同输入同输出):
6
+ // :root { color-scheme: light; --soma-*: …亮色全表 }
7
+ // system 极性:@media (prefers-color-scheme: dark) { :root … 只写与亮色不同的键 } 与 :root.soma-scheme-dark 同体、:root.soma-scheme-light { color-scheme: light }
8
+ // light / soft 极性:只有 :root(锁亮);dark 极性::root 取暗表全量(锁暗)
9
+ // 暗色切换:mode 缺省 system,跟随设备偏好,也可在根元素上加类 `soma-scheme-dark` / `soma-scheme-light` 显式切换(不重编译)。
10
+
11
+ import {
12
+ darkSchemeRules,
13
+ explicitLightSchemeRules,
14
+ projectThemeIntent,
15
+ solveTokenTables,
16
+ themeDeclarationOfString,
17
+ } from 'soma-foundation/compile';
18
+ import type { ScopeDeclaration, SchemeChoices, ThemeDeclaration, ThemeDiagnostic, TokenTables } from 'soma-foundation/compile';
19
+ import { SOMA_DESIGN_FONT_SCHEMES } from 'soma-foundation/design-data';
20
+ import { paletteById, selectFontScheme } from 'soma-foundation/theme';
21
+ import type { KitDiagnostic } from '../object-renderer/types';
22
+
23
+ /** kit.app.yaml 的 theme 段(已规整;取值域在 resolveKitThemeTokens 里按 foundation 真源校验) */
24
+ export interface KitThemeConfig {
25
+ /** 配色方案 id(配色方案库) */
26
+ paletteScheme?: string;
27
+ /** 字体方案 id 或 'auto' */
28
+ fontScheme?: string;
29
+ /** 品牌色 #rgb / #rrggbb */
30
+ color?: string;
31
+ /** 极性:light / dark / system / soft;缺省 system */
32
+ mode?: 'light' | 'dark' | 'system' | 'soft';
33
+ }
34
+
35
+ export const KIT_THEME_MODES: readonly string[] = ['light', 'dark', 'system', 'soft'];
36
+ const HEX = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
37
+
38
+ export interface KitThemeTokensResult {
39
+ /** 令牌 CSS(失败时为空串) */
40
+ css: string;
41
+ diagnostics: KitDiagnostic[];
42
+ }
43
+
44
+ function tokenBlock(selector: string, vars: Readonly<Record<string, string>>, extra: readonly string[] = []): string {
45
+ const body = [...extra, ...Object.entries(vars).map(([k, v]) => `${k}: ${v};`)];
46
+ return `${selector} {\n${body.map((l) => ` ${l}`).join('\n')}\n}`;
47
+ }
48
+
49
+ function tableDiff(base: Readonly<Record<string, string>>, next: Readonly<Record<string, string>>): Record<string, string> {
50
+ const out: Record<string, string> = {};
51
+ for (const [k, v] of Object.entries(next)) if (base[k] !== v) out[k] = v;
52
+ return out;
53
+ }
54
+
55
+ /** 令牌表 -> CSS 文本(极性决定发哪几块,格式与 soma-lite / soma-ui 同一份 foundation 规则) */
56
+ export function serializeTokenTables(tables: TokenTables): string {
57
+ if (tables.polarity === 'dark') return tokenBlock(':root', tables.dark, ['color-scheme: dark;']);
58
+ const parts = [tokenBlock(':root', tables.light, ['color-scheme: light;'])];
59
+ const darkOnly = tableDiff(tables.light, tables.dark);
60
+ const system = tables.polarity === 'system';
61
+ if (Object.keys(darkOnly).length > 0) {
62
+ parts.push(...darkSchemeRules(undefined, ['color-scheme: dark;', ...Object.entries(darkOnly).map(([k, v]) => `${k}: ${v};`)], system));
63
+ }
64
+ if (system) parts.push(...explicitLightSchemeRules(undefined));
65
+ return parts.join('\n\n');
66
+ }
67
+
68
+ function themeDiag(code: string, path: string, message: string): KitDiagnostic {
69
+ return { code, path, message };
70
+ }
71
+
72
+ function fromThemeDiagnostics(list: readonly ThemeDiagnostic[]): KitDiagnostic[] {
73
+ return list
74
+ .filter((d) => d.severity === 'error')
75
+ .map((d) => themeDiag('KIT-APP-003', 'kit.app.yaml.theme', `${d.code}:${d.message}${d.fix !== undefined && d.fix.length > 0 ? `;修法:${d.fix.join(';')}` : ''}`));
76
+ }
77
+
78
+ /** 求解令牌表(不序列化;测试与 explain 可单独用) */
79
+ export function solveKitTheme(
80
+ theme: KitThemeConfig | undefined,
81
+ locale?: string,
82
+ /** 页面 / 产品块级主题的作用域声明(block-theme.ts 读出);求解结果在 `tables.scopes` */
83
+ blockScopes: readonly ScopeDeclaration[] = [],
84
+ ): { tables?: TokenTables; diagnostics: KitDiagnostic[] } {
85
+ const cfg = theme ?? {};
86
+ const diagnostics: KitDiagnostic[] = [];
87
+ if (cfg.paletteScheme !== undefined && paletteById(cfg.paletteScheme) === undefined) {
88
+ diagnostics.push(themeDiag('KIT-APP-002', 'kit.app.yaml.theme.palette_scheme', `palette_scheme「${cfg.paletteScheme}」不是配色方案库里的方案 id`));
89
+ }
90
+ if (cfg.fontScheme !== undefined && cfg.fontScheme !== 'auto' && !Object.prototype.hasOwnProperty.call(SOMA_DESIGN_FONT_SCHEMES, cfg.fontScheme)) {
91
+ diagnostics.push(themeDiag('KIT-APP-002', 'kit.app.yaml.theme.font_scheme', `font_scheme「${cfg.fontScheme}」既不是 auto 也不是字体方案库里的方案 id`));
92
+ }
93
+ if (cfg.color !== undefined && !HEX.test(cfg.color)) {
94
+ diagnostics.push(themeDiag('KIT-APP-002', 'kit.app.yaml.theme.color', `color「${cfg.color}」必须是 #rgb / #rrggbb 品牌色号`));
95
+ }
96
+ if (cfg.mode !== undefined && !KIT_THEME_MODES.includes(cfg.mode)) {
97
+ diagnostics.push(themeDiag('KIT-APP-002', 'kit.app.yaml.theme.mode', `mode「${String(cfg.mode)}」只能是 ${KIT_THEME_MODES.join(' / ')}`));
98
+ }
99
+ if (diagnostics.length > 0) return { diagnostics };
100
+
101
+ const palette = cfg.paletteScheme === undefined ? undefined : paletteById(cfg.paletteScheme);
102
+ const fontSchemeId = cfg.fontScheme === undefined
103
+ ? undefined
104
+ : selectFontScheme({ ...(cfg.fontScheme === 'auto' ? {} : { explicit: cfg.fontScheme }), ...(locale === undefined ? {} : { locale }) }).id;
105
+ const schemes: SchemeChoices | undefined = palette === undefined && fontSchemeId === undefined
106
+ ? undefined
107
+ : {
108
+ ...(palette === undefined ? {} : { palette }),
109
+ ...(palette !== undefined && cfg.color !== undefined ? { brandHex: cfg.color } : {}),
110
+ ...(fontSchemeId === undefined ? {} : { fontSchemeId }),
111
+ };
112
+
113
+ // 声明:没写品牌色号时取平台默认库主题(name '');单写 color 走存量折叠(customBrandColor,不带 name)
114
+ const base = themeDeclarationOfString('');
115
+ const declaration: ThemeDeclaration = cfg.color !== undefined && palette === undefined
116
+ ? { terms: {}, factors: {}, scopes: [], customBrandColor: cfg.color, ...(cfg.mode === undefined ? {} : { mode: cfg.mode }) }
117
+ : { ...base, ...(cfg.mode === undefined ? {} : { mode: cfg.mode }) };
118
+
119
+ const withBlocks: ThemeDeclaration = blockScopes.length === 0 ? declaration : { ...declaration, scopes: [...declaration.scopes, ...blockScopes] };
120
+ const projected = projectThemeIntent(withBlocks, schemes === undefined ? {} : { schemes });
121
+ if (!projected.ok || projected.source === null) return { diagnostics: fromThemeDiagnostics(projected.diagnostics) };
122
+ const solved = solveTokenTables(projected, locale === undefined ? {} : { locales: [locale] });
123
+ if (!solved.ok || solved.tables === null) {
124
+ const detail = fromThemeDiagnostics(solved.diagnostics);
125
+ return { diagnostics: detail.length > 0 ? detail : [themeDiag('KIT-APP-003', 'kit.app.yaml.theme', '主题令牌求解失败:无亮暗令牌表')] };
126
+ }
127
+ return { tables: solved.tables, diagnostics: [] };
128
+ }
129
+
130
+ /** 一站式:theme 声明 -> 令牌 CSS(拼在 kit 主题头前面交样式引擎) */
131
+ export function resolveKitThemeTokens(theme: KitThemeConfig | undefined, locale?: string): KitThemeTokensResult {
132
+ const solved = solveKitTheme(theme, locale);
133
+ if (solved.tables === undefined) return { css: '', diagnostics: solved.diagnostics };
134
+ return { css: `${serializeTokenTables(solved.tables)}\n`, diagnostics: [] };
135
+ }