soma-kit 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (505) hide show
  1. package/README.md +1 -1
  2. package/package.json +8 -5
  3. package/packs/ai/model-card.ts +3 -3
  4. package/packs/finance/reconcile-desk/compile.ts +1 -1
  5. package/packs/finance/reconcile-desk/shell.ts +1 -1
  6. package/packs/ops/error-budget-card.ts +3 -3
  7. package/packs/ops/release-readiness-card.ts +3 -3
  8. package/packs/security/control-evidence-card.ts +3 -3
  9. package/packs/security/finding-card.ts +3 -2
  10. package/packs/shared/card-util.ts +17 -0
  11. package/spec/generated/kit-app.schema.json +2148 -338
  12. package/spec/generated/kit-page.schema.json +1152 -87
  13. package/spec/kit-grammar.json +1084 -136
  14. package/spec/kit-grammar.schema.json +167 -26
  15. package/src/app/app-config.ts +220 -187
  16. package/src/app/component-gate.ts +2 -2
  17. package/src/app/compose-apps.ts +5 -2
  18. package/src/app/define-kit-actions.ts +200 -22
  19. package/src/app/define-kit-app.ts +54 -8
  20. package/src/app/define-kit-view.ts +1 -1
  21. package/src/app/index.ts +12 -7
  22. package/src/app/kit-view-context.ts +50 -3
  23. package/src/app/list-page-defaults.ts +14 -0
  24. package/src/app/server-pages.ts +239 -7
  25. package/src/app/server.ts +466 -25
  26. package/src/app/theme-endpoint.ts +68 -24
  27. package/src/app/theme-runtime.ts +421 -87
  28. package/src/app/theme-shards.ts +69 -0
  29. package/src/app/tier-compat.ts +107 -0
  30. package/src/base/action-busy.ts +215 -38
  31. package/src/base/affix.ts +137 -0
  32. package/src/base/alert.ts +107 -59
  33. package/src/base/anchored-layer.ts +8 -7
  34. package/src/base/avatar.ts +147 -61
  35. package/src/base/badge.ts +186 -0
  36. package/src/base/button-group.ts +227 -0
  37. package/src/base/button.ts +365 -53
  38. package/src/base/card.ts +233 -0
  39. package/src/base/cascader.ts +147 -32
  40. package/src/base/check-core.ts +196 -33
  41. package/src/base/checkbox.ts +67 -2
  42. package/src/base/choice.ts +132 -31
  43. package/src/base/collapse.ts +249 -0
  44. package/src/base/color-picker.ts +404 -28
  45. package/src/base/combobox.ts +6 -2
  46. package/src/base/command-palette.ts +155 -37
  47. package/src/base/context-menu.ts +26 -6
  48. package/src/base/countdown.ts +37 -15
  49. package/src/base/date-range.ts +115 -94
  50. package/src/base/date.ts +487 -76
  51. package/src/base/delta.ts +20 -11
  52. package/src/base/divider.ts +64 -97
  53. package/src/base/end-edge.ts +10 -4
  54. package/src/base/fab.ts +64 -23
  55. package/src/base/gap-value.ts +35 -16
  56. package/src/base/hint-tips.ts +100 -30
  57. package/src/base/identity-cells.ts +839 -0
  58. package/src/base/illustrations.ts +6 -4
  59. package/src/base/image.ts +40 -19
  60. package/src/base/index.ts +92 -24
  61. package/src/base/inline-error.ts +90 -0
  62. package/src/base/input.ts +174 -38
  63. package/src/base/kbd.ts +31 -17
  64. package/src/base/kit-contract.ts +400 -0
  65. package/src/base/link.ts +41 -20
  66. package/src/base/listbox-core.ts +324 -95
  67. package/src/base/loading-gate.ts +3 -0
  68. package/src/base/look.ts +197 -0
  69. package/src/base/mentions.ts +58 -22
  70. package/src/base/menu-button.ts +129 -42
  71. package/src/base/menu-core.ts +210 -26
  72. package/src/base/month-grid.ts +60 -3
  73. package/src/base/motion/aura.ts +52 -10
  74. package/src/base/motion/hover-3d.ts +10 -5
  75. package/src/base/motion/hover-gallery.ts +19 -12
  76. package/src/base/motion/limits.ts +10 -0
  77. package/src/base/motion/marquee.ts +18 -11
  78. package/src/base/motion/text-rotate.ts +34 -16
  79. package/src/base/notification.ts +292 -0
  80. package/src/base/number.ts +93 -12
  81. package/src/base/otp.ts +143 -27
  82. package/src/base/overlay-runtime.ts +32 -24
  83. package/src/base/overlay-shell.ts +186 -0
  84. package/src/base/period-picker.ts +868 -0
  85. package/src/base/popover.ts +625 -74
  86. package/src/base/popup.ts +219 -78
  87. package/src/base/portal-core.ts +99 -2
  88. package/src/base/price-text.ts +51 -17
  89. package/src/base/progress.ts +100 -18
  90. package/src/base/qr-code.ts +64 -17
  91. package/src/base/qty-stepper.ts +145 -21
  92. package/src/base/radio.ts +43 -2
  93. package/src/base/range.ts +194 -39
  94. package/src/base/rating.ts +117 -31
  95. package/src/base/reason-tip.ts +60 -18
  96. package/src/base/relation-cells.ts +541 -0
  97. package/src/{frames → base}/resize-handle.ts +6 -4
  98. package/src/base/row-fresh.ts +84 -0
  99. package/src/base/section-spy.ts +79 -0
  100. package/src/base/segmented.ts +99 -56
  101. package/src/base/select.ts +8 -2
  102. package/src/base/shared.ts +520 -73
  103. package/src/base/spinner.ts +107 -0
  104. package/src/base/state-panel.ts +77 -22
  105. package/src/base/status-tone.ts +1 -1
  106. package/src/base/sticky-edge.ts +96 -29
  107. package/src/base/swap.ts +39 -21
  108. package/src/base/switch.ts +158 -38
  109. package/src/base/tabs.ts +292 -0
  110. package/src/base/tag-input.ts +129 -55
  111. package/src/base/tag.ts +203 -91
  112. package/src/base/text.ts +491 -77
  113. package/src/base/textarea.ts +89 -40
  114. package/src/base/time-picker.ts +341 -57
  115. package/src/base/time-range.ts +846 -0
  116. package/src/base/tree-select.ts +346 -89
  117. package/src/base/upload.ts +612 -158
  118. package/src/base/view-transition.ts +7 -3
  119. package/src/base/virtual-list.ts +49 -14
  120. package/src/biz/approval-desk/compile.ts +98 -6
  121. package/src/biz/approval-desk/index.ts +2 -0
  122. package/src/biz/approval-desk/shell.ts +53 -13
  123. package/src/biz/auth-panel/compile.ts +14 -4
  124. package/src/biz/auth-panel/shell.ts +28 -8
  125. package/src/biz/category-crud/compile.ts +64 -13
  126. package/src/biz/category-crud/index.ts +2 -0
  127. package/src/biz/category-crud/shell.ts +30 -8
  128. package/src/biz/checkout-page/compile.ts +38 -4
  129. package/src/biz/checkout-page/index.ts +1 -0
  130. package/src/biz/checkout-page/shell.ts +28 -10
  131. package/src/biz/compose.ts +9 -4
  132. package/src/biz/data-components.ts +2 -0
  133. package/src/biz/define.ts +1 -1
  134. package/src/biz/import-wizard/compile.ts +5 -2
  135. package/src/biz/import-wizard/index.ts +1 -0
  136. package/src/biz/import-wizard/shell.ts +36 -20
  137. package/src/biz/index.ts +5 -4
  138. package/src/biz/landing-page/compile.ts +4 -3
  139. package/src/biz/landing-page/shell.ts +25 -5
  140. package/src/biz/layout-contracts.ts +918 -0
  141. package/src/biz/link/hub.ts +199 -8
  142. package/src/biz/link/shared.ts +62 -16
  143. package/src/biz/master-sub/compile.ts +318 -38
  144. package/src/biz/master-sub/detail-head.ts +145 -21
  145. package/src/biz/master-sub/index.ts +6 -3
  146. package/src/biz/master-sub/shell.ts +232 -66
  147. package/src/biz/multi-board/compile.ts +89 -38
  148. package/src/biz/multi-board/composition.ts +7 -20
  149. package/src/biz/multi-board/index.ts +25 -9
  150. package/src/biz/multi-board/prose-fold.ts +17 -13
  151. package/src/biz/multi-board/shell.ts +153 -38
  152. package/src/biz/names.ts +1 -0
  153. package/src/biz/notification-center/compile.ts +28 -7
  154. package/src/biz/notification-center/index.ts +2 -0
  155. package/src/biz/notification-center/shell.ts +51 -11
  156. package/src/biz/page-templates/domain-templates.ts +147 -20
  157. package/src/biz/page-templates/result-page/compile.ts +5 -2
  158. package/src/biz/page-templates/result-page/index.ts +1 -0
  159. package/src/biz/page-templates/result-page/shell.ts +20 -6
  160. package/src/biz/page-templates/shared.ts +1 -1
  161. package/src/biz/page-templates/sign-in-page/compile.ts +20 -9
  162. package/src/biz/page-templates/sign-in-page/index.ts +1 -0
  163. package/src/biz/page-templates/sign-in-page/shell.ts +30 -14
  164. package/src/biz/record-detail/compile.ts +43 -12
  165. package/src/biz/record-detail/index.ts +1 -0
  166. package/src/biz/record-detail/shell.ts +42 -11
  167. package/src/biz/settings-center/compile.ts +5 -2
  168. package/src/biz/settings-center/index.ts +1 -0
  169. package/src/biz/settings-center/shell.ts +33 -9
  170. package/src/biz/shared/action-host.ts +146 -48
  171. package/src/biz/shared/compile-helpers.ts +134 -32
  172. package/src/biz/shared/coordinator.ts +727 -163
  173. package/src/biz/shared/focus-return.ts +180 -0
  174. package/src/biz/shared/object-aliases.ts +7 -1
  175. package/src/biz/shared/overlay-compile.ts +102 -24
  176. package/src/biz/shared/overlay-shell.ts +97 -116
  177. package/src/biz/shared/page-form-actions.ts +151 -0
  178. package/src/biz/shared/page-form.ts +255 -0
  179. package/src/biz/shared/pipeline.ts +74 -0
  180. package/src/biz/shared/runtime-hub.ts +101 -8
  181. package/src/biz/shared/verbs.ts +129 -0
  182. package/src/biz/single-form/compile.ts +6 -4
  183. package/src/biz/single-form/index.ts +2 -0
  184. package/src/biz/single-form/shell.ts +22 -8
  185. package/src/biz/standard-crud/compile.ts +213 -38
  186. package/src/biz/standard-crud/index.ts +2 -1
  187. package/src/biz/standard-crud/shell.ts +90 -13
  188. package/src/biz/standard-crud/summary.ts +2 -35
  189. package/src/biz/step-form/compile.ts +13 -4
  190. package/src/biz/step-form/hub.ts +168 -49
  191. package/src/biz/step-form/index.ts +1 -0
  192. package/src/biz/step-form/shell.ts +35 -17
  193. package/src/biz/types.ts +49 -6
  194. package/src/cli/app-layer-check.ts +375 -0
  195. package/src/cli/kit-cli.ts +179 -33
  196. package/src/cli/kit-init.ts +152 -3
  197. package/src/cli/migrate/theme-map.ts +35 -28
  198. package/src/cli/migrate/ts-rules.ts +2 -2
  199. package/src/cli/migrate/types.ts +3 -3
  200. package/src/cli/migrate/yaml-rules.ts +11 -9
  201. package/src/cli/view-writes.ts +13 -0
  202. package/src/compile/access-gate-attach.ts +1 -1
  203. package/src/compile/action-host-attach.ts +1 -1
  204. package/src/compile/closed-set.ts +102 -6
  205. package/src/compile/compile-page.ts +461 -273
  206. package/src/compile/component-candidates.ts +58 -5
  207. package/src/compile/danger-tier.ts +65 -0
  208. package/src/compile/hints.ts +6 -59
  209. package/src/compile/index.ts +2 -2
  210. package/src/compile/info-structure.ts +155 -0
  211. package/src/compile/layout-lint/index.ts +4 -1
  212. package/src/compile/layout-lint/rules-composition.ts +44 -13
  213. package/src/compile/layout-lint/rules-table.ts +4 -19
  214. package/src/compile/look-page.ts +551 -0
  215. package/src/compile/look.ts +376 -0
  216. package/src/compile/page-composition.ts +405 -67
  217. package/src/compile/page-hierarchy.ts +131 -0
  218. package/src/compile/page-pipeline-look.ts +156 -0
  219. package/src/compile/page-pipeline.ts +200 -0
  220. package/src/compile/parse.ts +12 -11
  221. package/src/compile/redirect.ts +1 -1
  222. package/src/compile/relation-render.ts +120 -0
  223. package/src/compile/remove-guard.ts +115 -41
  224. package/src/compile/stages.ts +786 -0
  225. package/src/compile/styles.ts +286 -48
  226. package/src/compile/types.ts +63 -6
  227. package/src/compile/view-check.ts +190 -1
  228. package/src/data/access-gate.ts +17 -9
  229. package/src/data/amount-breakdown.ts +52 -23
  230. package/src/data/anchor-nav.ts +77 -16
  231. package/src/data/approval-flow.ts +217 -126
  232. package/src/data/assignment-picker.ts +182 -94
  233. package/src/data/async-result-panel.ts +114 -46
  234. package/src/data/audit-log.ts +461 -0
  235. package/src/data/breadcrumbs.ts +150 -24
  236. package/src/data/calendar.ts +436 -97
  237. package/src/data/card-grid.ts +319 -0
  238. package/src/data/carousel.ts +81 -41
  239. package/src/data/cell-value.ts +253 -0
  240. package/src/data/chart.ts +1053 -96
  241. package/src/data/checklist.ts +82 -38
  242. package/src/data/code-view.ts +296 -44
  243. package/src/data/comment-thread.ts +611 -86
  244. package/src/data/compare-view.ts +227 -0
  245. package/src/data/confirm-dialog.ts +250 -39
  246. package/src/data/context-menu.ts +95 -21
  247. package/src/data/d9-limits.ts +2 -0
  248. package/src/data/d9-util.ts +13 -5
  249. package/src/data/diff.ts +109 -49
  250. package/src/data/display-util.ts +9 -4
  251. package/src/data/dock.ts +38 -18
  252. package/src/data/embed.ts +143 -8
  253. package/src/data/engine-ports.ts +135 -0
  254. package/src/data/field-mapper.ts +116 -54
  255. package/src/data/file-list.ts +522 -0
  256. package/src/data/flow-editor.ts +695 -158
  257. package/src/data/flow-node-options.ts +24 -5
  258. package/src/data/flow-remote-options.ts +94 -19
  259. package/src/data/footer.ts +88 -26
  260. package/src/data/form-draft-registry.ts +183 -12
  261. package/src/data/gantt.ts +640 -117
  262. package/src/data/graph-view.ts +51 -0
  263. package/src/data/heat-calendar.ts +412 -0
  264. package/src/data/hero.ts +40 -13
  265. package/src/data/image-viewer.ts +265 -62
  266. package/src/data/index.ts +75 -6
  267. package/src/data/item-list.ts +219 -58
  268. package/src/data/json-view.ts +909 -0
  269. package/src/data/kanban.ts +346 -91
  270. package/src/data/kit-contract.ts +230 -0
  271. package/src/data/leaderboard.ts +343 -0
  272. package/src/data/level-class.ts +21 -0
  273. package/src/data/log-stream.ts +347 -0
  274. package/src/data/markdown-view.ts +597 -0
  275. package/src/data/matrix.ts +234 -120
  276. package/src/data/media-grid.ts +165 -38
  277. package/src/data/mega-menu.ts +43 -26
  278. package/src/data/menu-bar.ts +254 -0
  279. package/src/data/menu-dom.ts +55 -19
  280. package/src/data/menu.ts +138 -48
  281. package/src/data/mockup.ts +37 -25
  282. package/src/data/modal-dialog.ts +126 -98
  283. package/src/data/navbar.ts +152 -66
  284. package/src/data/notice-list.ts +101 -49
  285. package/src/data/notify-renderer.ts +80 -15
  286. package/src/data/object-form.ts +1504 -164
  287. package/src/data/org-chart.ts +544 -0
  288. package/src/data/outcome-watch.ts +90 -21
  289. package/src/data/pager.ts +129 -45
  290. package/src/data/panel-head.ts +238 -76
  291. package/src/data/permission-matrix.ts +379 -120
  292. package/src/data/permission-tree.ts +146 -78
  293. package/src/data/pricing-table.ts +112 -43
  294. package/src/data/prompt-dialog.ts +49 -21
  295. package/src/data/reaction-bar.ts +67 -32
  296. package/src/data/record-card.ts +245 -72
  297. package/src/data/record-picker.ts +61 -28
  298. package/src/data/redirect.ts +39 -15
  299. package/src/data/request-console.ts +141 -38
  300. package/src/data/resident.ts +11 -13
  301. package/src/data/result-panel.ts +65 -27
  302. package/src/data/rich-text.ts +260 -127
  303. package/src/data/row-confirm.ts +47 -0
  304. package/src/data/row-editor.ts +384 -105
  305. package/src/data/rule-builder.ts +136 -81
  306. package/src/data/schedule-grid.ts +238 -0
  307. package/src/data/segment-bar.ts +221 -0
  308. package/src/data/shape-util.ts +90 -36
  309. package/src/data/stage-flow.ts +244 -0
  310. package/src/data/staged-rows.ts +207 -24
  311. package/src/data/stat-group.ts +493 -100
  312. package/src/data/static-lazy.ts +21 -0
  313. package/src/data/static-registry.ts +46 -4
  314. package/src/data/status-strip.ts +171 -0
  315. package/src/data/steps.ts +69 -36
  316. package/src/data/summary-strip.ts +136 -0
  317. package/src/data/summary-util.ts +116 -0
  318. package/src/data/survey.ts +134 -47
  319. package/src/data/system-switcher.ts +53 -24
  320. package/src/data/target-progress.ts +208 -0
  321. package/src/data/text-action-button.ts +28 -7
  322. package/src/data/text-diff.ts +731 -0
  323. package/src/data/tile-grid.ts +343 -0
  324. package/src/data/timeline.ts +205 -36
  325. package/src/data/tour-guide.ts +113 -47
  326. package/src/data/transfer.ts +204 -47
  327. package/src/data/tree-table.ts +228 -81
  328. package/src/data/tree.ts +193 -69
  329. package/src/data/trend-line.ts +68 -12
  330. package/src/data/virtual-rows.ts +248 -98
  331. package/src/data/waterfall.ts +171 -0
  332. package/src/data/watermark.ts +35 -6
  333. package/src/data/wrap.ts +28 -6
  334. package/src/frames/blank-frame.ts +6 -4
  335. package/src/frames/index.ts +4 -4
  336. package/src/frames/inherited-shell.ts +219 -0
  337. package/src/frames/page-bar.ts +208 -28
  338. package/src/frames/page-status.ts +3 -2
  339. package/src/frames/resident-components.ts +18 -0
  340. package/src/frames/shared.ts +73 -26
  341. package/src/frames/single-frame.ts +20 -4
  342. package/src/frames/split-frame/shell.ts +27 -17
  343. package/src/frames/split-frame/wiring.ts +16 -12
  344. package/src/frames/tabs-frame/shell.ts +14 -7
  345. package/src/frames/tabs-frame/wiring.ts +2 -1
  346. package/src/frames/top-main-frame.ts +55 -3
  347. package/src/frames/types.ts +5 -2
  348. package/src/frames/workspace-frame/extras.ts +23 -7
  349. package/src/frames/workspace-frame/index.ts +1 -1
  350. package/src/frames/workspace-frame/pipeline-key.ts +6 -0
  351. package/src/frames/workspace-frame/shell.ts +24 -3
  352. package/src/frames/workspace-frame/state.ts +42 -8
  353. package/src/frames/workspace-frame/view.ts +773 -194
  354. package/src/generated/kit-grammar-runtime.ts +1061 -77
  355. package/src/generated/kit-page.ts +272 -0
  356. package/src/i18n/index.ts +2 -0
  357. package/src/i18n/kit-text.ts +210 -5
  358. package/src/i18n/resolve-text-refs.ts +1 -1
  359. package/src/object-renderer/action-group.ts +204 -22
  360. package/src/object-renderer/action-more.ts +66 -19
  361. package/src/object-renderer/arrange.ts +270 -28
  362. package/src/object-renderer/category-tone.ts +96 -0
  363. package/src/object-renderer/collapse-wiring.ts +19 -9
  364. package/src/object-renderer/collection-expand.ts +3 -3
  365. package/src/object-renderer/collection-parts.ts +459 -103
  366. package/src/object-renderer/collection-table.ts +406 -59
  367. package/src/object-renderer/collection.ts +333 -71
  368. package/src/object-renderer/compile-data.ts +13 -3
  369. package/src/object-renderer/defaults.ts +14 -5
  370. package/src/object-renderer/emit-events.ts +46 -20
  371. package/src/object-renderer/emit-object.ts +35 -6
  372. package/src/object-renderer/emit-static.ts +831 -153
  373. package/src/object-renderer/field-value.ts +12 -239
  374. package/src/object-renderer/filter-plan.ts +3 -3
  375. package/src/object-renderer/filter-toolbar.ts +190 -0
  376. package/src/object-renderer/form-detail.ts +87 -2
  377. package/src/{compile → object-renderer}/fragment.ts +2 -2
  378. package/src/object-renderer/index.ts +1 -1
  379. package/src/object-renderer/key-field.ts +21 -0
  380. package/src/object-renderer/layout-facts.ts +55 -7
  381. package/src/object-renderer/layout-plan.ts +6 -3
  382. package/src/object-renderer/overlay-decide.ts +124 -0
  383. package/src/object-renderer/pick-component.ts +8 -2
  384. package/src/object-renderer/pipeline-mode.ts +6 -0
  385. package/src/object-renderer/relation-field.ts +79 -0
  386. package/src/object-renderer/render-object.ts +72 -27
  387. package/src/object-renderer/request-actions.ts +119 -21
  388. package/src/object-renderer/table-actions.ts +479 -111
  389. package/src/object-renderer/table-gap.ts +2 -1
  390. package/src/object-renderer/table-reorder.ts +237 -0
  391. package/src/object-renderer/table-summary.ts +26 -12
  392. package/src/object-renderer/table-tools.ts +437 -130
  393. package/src/object-renderer/types.ts +100 -17
  394. package/src/object-renderer/value-present.ts +49 -0
  395. package/src/page-target/ai-surface.ts +15 -22
  396. package/src/page-target/compile.ts +5 -6
  397. package/src/page-target/drift.ts +0 -7
  398. package/src/page-target/intent-schema.ts +46 -43
  399. package/src/page-target/target.ts +4 -5
  400. package/src/page-target/writer-policy.ts +4 -5
  401. package/src/recipes/app-blocks.ts +66 -0
  402. package/src/recipes/chrome-surface.ts +20 -0
  403. package/src/recipes/code-view.ts +57 -0
  404. package/src/recipes/color-role.ts +442 -0
  405. package/src/recipes/compact-group.ts +32 -0
  406. package/src/recipes/composition-projector.ts +321 -0
  407. package/src/recipes/container.ts +93 -26
  408. package/src/recipes/control.ts +85 -8
  409. package/src/recipes/desc-list.ts +108 -0
  410. package/src/recipes/divider.ts +74 -0
  411. package/src/recipes/emphasis.ts +102 -13
  412. package/src/recipes/field-text.ts +72 -0
  413. package/src/recipes/form-section.ts +177 -0
  414. package/src/recipes/frame-bleed.ts +6 -5
  415. package/src/recipes/index.ts +39 -5
  416. package/src/recipes/inherited-shell.ts +43 -0
  417. package/src/recipes/json-view.ts +50 -0
  418. package/src/recipes/look.ts +56 -0
  419. package/src/recipes/mark.ts +138 -0
  420. package/src/recipes/markdown.ts +96 -0
  421. package/src/recipes/overlay.ts +151 -37
  422. package/src/recipes/page-width.ts +51 -0
  423. package/src/recipes/pipeline-runtime.ts +366 -0
  424. package/src/recipes/placeholder.ts +38 -20
  425. package/src/recipes/rail-grid.ts +6 -3
  426. package/src/recipes/self-owned.ts +59 -0
  427. package/src/recipes/slot-align.ts +5 -3
  428. package/src/recipes/stat-state.ts +6 -6
  429. package/src/recipes/state.ts +64 -11
  430. package/src/recipes/status.ts +21 -20
  431. package/src/recipes/strip.ts +114 -0
  432. package/src/recipes/surface-edge.ts +3 -1
  433. package/src/recipes/surface.ts +40 -7
  434. package/src/recipes/table-gap.ts +4 -3
  435. package/src/recipes/table-native-edit.ts +25 -12
  436. package/src/recipes/table-row.ts +56 -20
  437. package/src/recipes/tabs.ts +140 -31
  438. package/src/recipes/text-diff.ts +97 -0
  439. package/src/recipes/text-fit.ts +132 -0
  440. package/src/recipes/title-row.ts +72 -5
  441. package/src/recipes/typography.ts +2 -2
  442. package/src/shared/action-func.ts +106 -0
  443. package/src/shared/color-scheme.ts +127 -0
  444. package/src/shared/confirm-decl.ts +5 -2
  445. package/src/shared/danger-facts.ts +55 -0
  446. package/src/shared/diagnostics.ts +16 -0
  447. package/src/shared/dom-attrs-registry.ts +1009 -0
  448. package/src/shared/dom-attrs.ts +743 -0
  449. package/src/shared/envelope.ts +1 -1
  450. package/src/shared/field-kind.ts +49 -0
  451. package/src/shared/field-value-format.ts +292 -0
  452. package/src/shared/focus-ring.ts +8 -0
  453. package/src/shared/glyphs.ts +127 -0
  454. package/src/shared/hints.ts +56 -0
  455. package/src/{base → shared}/icons.ts +40 -1
  456. package/src/shared/identifier-field.ts +66 -0
  457. package/src/shared/kit-error.ts +1 -1
  458. package/src/shared/list-pager.ts +23 -0
  459. package/src/shared/list-title.ts +29 -0
  460. package/src/{object-renderer → shared}/merge-class.ts +3 -2
  461. package/src/shared/order-value.ts +15 -0
  462. package/src/shared/page-attrs-runtime.ts +327 -0
  463. package/src/shared/page-attrs.ts +262 -0
  464. package/src/shared/path-guard.ts +1 -1
  465. package/src/shared/pipeline-mode.ts +64 -0
  466. package/src/shared/primitives-types.ts +8 -0
  467. package/src/shared/row-key.ts +15 -0
  468. package/src/shared/theme-runtime-shared.ts +181 -21
  469. package/src/shared/theme-usage.ts +16 -0
  470. package/src/shared/value-table-contract.ts +68 -0
  471. package/src/spatial/action-func.ts +4 -0
  472. package/src/spatial/declared-actions.ts +116 -0
  473. package/src/spatial/emit.ts +660 -0
  474. package/src/spatial/expand.ts +1482 -0
  475. package/src/spatial/field-types.ts +48 -0
  476. package/src/spatial/index.ts +82 -0
  477. package/src/spatial/layout.ts +697 -0
  478. package/src/spatial/look-apply.ts +206 -0
  479. package/src/spatial/page-decl.ts +44 -0
  480. package/src/spatial/page-object.ts +349 -0
  481. package/src/spatial/recognize.ts +491 -0
  482. package/src/spatial/self-report.ts +571 -0
  483. package/src/spatial/shape.ts +205 -0
  484. package/src/spatial/spatial-map.ts +136 -0
  485. package/src/spatial/tone.ts +145 -0
  486. package/src/theme/index.ts +11 -2
  487. package/src/theme/kit-theme-text.ts +1 -1
  488. package/src/theme/kit-theme.css +563 -28
  489. package/src/theme/kit-theme.tpl +527 -28
  490. package/src/theme/look-carrier.ts +65 -0
  491. package/src/theme/nine-dim-structure.ts +538 -176
  492. package/src/theme/private-vars.ts +153 -0
  493. package/src/theme/surface-layers.ts +12 -3
  494. package/src/theme/theme-tokens.ts +1602 -90
  495. package/src/theme/theme-types.ts +38 -59
  496. package/src/theme/value-table.ts +2379 -0
  497. package/src/app/envelope.ts +0 -1
  498. package/src/app/notify-renderer.ts +0 -1
  499. package/src/app/paged-list-adapter.ts +0 -1
  500. package/src/app/theme-runtime-shared.ts +0 -1
  501. package/src/compile/kit-error.ts +0 -1
  502. package/src/frames/list-summary.ts +0 -100
  503. package/src/recipes/nowrap.ts +0 -16
  504. package/src/theme/block-theme.ts +0 -202
  505. /package/src/{base → shared}/class-candidates.ts +0 -0
@@ -0,0 +1,597 @@
1
+ // MarkdownView:Markdown 展示(layer: data,写死形状,accept: single;内容展示批次 ④,规格 knowledge/Kit主题规则与算法.md §10.18)。
2
+ //
3
+ // 数据:Markdown 原文字符串,或 { source | markdown | content | text },或字符串数组(按块拼接、中间分割线);`path` 取 data 里的点路径。
4
+ // 原文只经 core 端口 engines.markdown 解析成块树,这里按节点类型 createElement / textContent 出 DOM(不用 innerHTML、不渲染原始 HTML)。
5
+ // 自动决定:标题层级(heading_offset 叠加)、目录(二级以上标题够多且正文够长才出)、顶层成段正文首行缩进两字(裁决 #4:
6
+ // 列表 / 引用 / 表格 / 脚注里的段落不缩进;只有一段的短内容不缩进)、代码块(与 CodeView 同一画法:语言推断、行号、着色、复制)、
7
+ // 表格横向滚动壳、图片懒加载与失败替换、外链新窗口 + 图标 + 读屏提示、任务列表只读勾选。
8
+ // 流式(stream: true,AI 逐字输出):原文不断增长,按帧节流整段重解析,只替换从第一个变化的块起之后的 DOM,前面已输出的文字保持可选中。
9
+ // 降级:空 → 空态;引擎不可用 / 过长 / 解析失败 → 纯文本分段 + 说明;原始 HTML 与不安全地址各有计数提示。
10
+
11
+ import { kitApplyLevelClass } from './level-class';
12
+ import type { SomaComponentDefinition } from 'soma-core';
13
+ import { KIT_CONTENT_LIMITS } from 'soma-foundation/kit-limits';
14
+ import { markCheckBox } from '../base/check-core';
15
+ import { bool, createKitController, joinClass, str } from '../base/shared';
16
+ import { kitIcon } from '../shared/icons';
17
+ import { kitText } from '../i18n/kit-text';
18
+ import { KIT_PART_ATTRIBUTE, KIT_PART_WELL } from '../recipes';
19
+ import { KIT_CODE_LANG_CLASS, KIT_CODE_NOTE_CLASS, KIT_CODE_VIEW_RECIPE_CLASS_CANDIDATES } from '../recipes/code-view';
20
+ import {
21
+ KIT_MARKDOWN_RECIPE_CLASS_CANDIDATES, KIT_MD_BODY_CLASS, KIT_MD_CODE_CLASS, KIT_MD_DEL_CLASS, KIT_MD_FNREF_CLASS, KIT_MD_FOOTNOTES_CLASS,
22
+ KIT_MD_HR_CLASS, KIT_MD_HTML_CLASS, KIT_MD_IMG_CLASS, KIT_MD_LINK_CLASS, KIT_MD_LIST_CLASS, KIT_MD_LIST_STYLE, KIT_MD_LI_CLASS,
23
+ KIT_MD_P_CLASS, KIT_MD_P_INDENT_CLASS, KIT_MD_P_TIGHT_CLASS, KIT_MD_QUOTE_CLASS, KIT_MD_TABLE_CLASS, KIT_MD_TABLE_WRAP_CLASS,
24
+ KIT_MD_TASK_CLASS, KIT_MD_TD_CLASS, KIT_MD_TH_CLASS, kitMdHeadingClass,
25
+ KIT_MD_CODE_HEAD_CLASS, KIT_MD_CODE_WELL_CLASS, KIT_MD_EXT_ICON_CLASS, KIT_MD_IMG_FAIL_CLASS, KIT_MD_PLAIN_P_CLASS, KIT_MD_ROOT_CLASS,
26
+ KIT_MD_STRONG_CLASS, KIT_MD_TASK_BOX_CLASS, KIT_MD_TOC_CLASS, KIT_MD_TOC_ITEM_CLASS, KIT_MD_TOC_TITLE_CLASS,
27
+ } from '../recipes/markdown';
28
+ import { classTokens, emptyNode, mk } from './shape-util';
29
+ import { codeWrapDefault, paintCodeLines } from './code-view';
30
+ import {
31
+ kitEnginePort, type KitHighlightEnginePort, type KitMarkdownEnginePort, type KitMdBlock, type KitMdInline, type KitMdMeta, type KitMdResult,
32
+ } from './engine-ports';
33
+ import { KIT_STATE_PANEL_CLASS_CANDIDATES } from '../base/state-panel';
34
+ import { kitProseIndent } from '../recipes/text-fit';
35
+ import { TEXT_ACTION_CLASS_TOKENS, textActionButton } from './text-action-button';
36
+ import { kitMarkDataFacts, kitMarkLevel, kitMarkPart } from './kit-contract';
37
+ import { KIT_ATTR_ACTION, KIT_ATTR_CONTAINER, KIT_ATTR_MD_BODY, KIT_ATTR_MD_CODE, KIT_ATTR_MD_NOTE, kitAttrSel } from '../shared/dom-attrs';
38
+
39
+ const ML = KIT_CONTENT_LIMITS.markdownView;
40
+
41
+ // ── 纯函数 ────────────────────────────────────────────────────────────
42
+
43
+ /** 数据 → Markdown 原文:字符串原样;{ source | markdown | content | text };字符串数组以分割线拼接;数字 / 布尔转字符串;其余空串 */
44
+ export function markdownSourceOf(raw: unknown): string {
45
+ if (raw === null || raw === undefined) return '';
46
+ if (typeof raw === 'string') return raw;
47
+ if (typeof raw === 'number' || typeof raw === 'boolean') return String(raw);
48
+ if (Array.isArray(raw)) return raw.map(markdownSourceOf).filter((s) => s.trim() !== '').join('\n\n---\n\n');
49
+ if (typeof raw === 'object') {
50
+ const o = raw as Record<string, unknown>;
51
+ for (const k of ['source', 'markdown', 'content', 'text']) if (typeof o[k] === 'string') return o[k] as string;
52
+ }
53
+ return '';
54
+ }
55
+
56
+ /** 目录:二级及以上(叠加偏移前的 depth ≤ 3)标题数 ≥ tocMinHeadings 且正文字数 ≥ tocMinChars */
57
+ export function markdownTocOf(meta: KitMdMeta, mode: string): KitMdMeta['outline'] {
58
+ if (mode === 'off') return [];
59
+ const list = meta.outline.filter((o) => o.depth <= 3);
60
+ return list.length >= ML.tocMinHeadings && meta.counts.chars >= ML.tocMinChars ? list : [];
61
+ }
62
+
63
+ /** 首行缩进(裁决 #4):只有顶层段落;全文只有一个顶层段落时按成段正文出口的单段判据(text-fit#kitProseIndent:≥ minChars 字且 ≥ singleMinSentences 句);类同出口 */
64
+ export function markdownIndentTopLevel(blocks: readonly KitMdBlock[]): boolean {
65
+ const paras = blocks.filter((b) => b.t === 'paragraph');
66
+ if (paras.length === 0) return false;
67
+ if (paras.length === 1 && blocks.length === 1) {
68
+ const p = paras[0]!;
69
+ return p.t === 'paragraph' && kitProseIndent([inlinePlain(p.inline)]);
70
+ }
71
+ return true;
72
+ }
73
+
74
+ function inlinePlain(nodes: readonly KitMdInline[]): string {
75
+ let s = '';
76
+ for (const n of nodes) {
77
+ if (n.t === 'text' || n.t === 'code') s += n.v;
78
+ else if (n.t === 'image') s += n.alt;
79
+ else if (n.t === 'strong' || n.t === 'em' || n.t === 'del' || n.t === 'link') s += inlinePlain(n.c);
80
+ }
81
+ return s;
82
+ }
83
+
84
+ /** 只含图片(与空白)的段落:不缩进 */
85
+ const imageOnly = (nodes: readonly KitMdInline[]): boolean =>
86
+ nodes.length > 0 && nodes.every((n) => n.t === 'image' || (n.t === 'text' && n.v.trim() === '') || n.t === 'br');
87
+
88
+ // ── 块树渲染(MarkdownView 与 RichTextEditor 的 Markdown 来源共用) ─────────────────
89
+
90
+ // 类串全部来自配方 recipes/markdown.ts(G101:组件文件不手写圆角 / 字阶)
91
+ const CODE_WELL_CLASS = KIT_MD_CODE_WELL_CLASS;
92
+ const CODE_HEAD_CLASS = KIT_MD_CODE_HEAD_CLASS;
93
+ const TASK_BOX_CLASS = KIT_MD_TASK_BOX_CLASS;
94
+ const EXT_ICON_CLASS = KIT_MD_EXT_ICON_CLASS;
95
+ const IMG_FAIL_CLASS = KIT_MD_IMG_FAIL_CLASS;
96
+ const ROOT_CLASS = KIT_MD_ROOT_CLASS;
97
+ const TOC_CLASS = KIT_MD_TOC_CLASS;
98
+ const TOC_TITLE_CLASS = KIT_MD_TOC_TITLE_CLASS;
99
+ const TOC_ITEM_CLASS = KIT_MD_TOC_ITEM_CLASS;
100
+ const NOTE_CLASS = KIT_CODE_NOTE_CLASS;
101
+ const PLAIN_P_CLASS = KIT_MD_PLAIN_P_CLASS;
102
+
103
+ export const KIT_MARKDOWN_VIEW_CLASS_CANDIDATES: readonly string[] = classTokens(
104
+ NOTE_CLASS, KIT_CODE_LANG_CLASS, KIT_CODE_VIEW_RECIPE_CLASS_CANDIDATES, KIT_MARKDOWN_RECIPE_CLASS_CANDIDATES, KIT_STATE_PANEL_CLASS_CANDIDATES,
105
+ TEXT_ACTION_CLASS_TOKENS, 'sr-only', 'min-w-0', 'text-start', 'text-end', 'text-center',
106
+ );
107
+
108
+ export interface KitMdRenderContext {
109
+ /** 组件根(取页面语言的文案) */
110
+ readonly root: HTMLElement;
111
+ /** 标题层级偏移(0–5) */
112
+ readonly headingOffset: number;
113
+ /** 本实例的 id 前缀(同页多个 Markdown 不撞 id) */
114
+ readonly idPrefix: string;
115
+ /** 顶层段落是否首行缩进 */
116
+ readonly indent: boolean;
117
+ readonly highlight: KitHighlightEnginePort | null;
118
+ /** 代码块是否出复制钮 */
119
+ readonly copyCode: boolean;
120
+ /** 当前异步高亮是否仍有效 */
121
+ readonly current?: () => boolean;
122
+ }
123
+
124
+ const CODE_RAW_TEXT = new WeakMap<HTMLElement, string>();
125
+
126
+ function inlineInto(host: HTMLElement, nodes: readonly KitMdInline[], ctx: KitMdRenderContext): void {
127
+ for (const n of nodes) {
128
+ switch (n.t) {
129
+ case 'text': host.appendChild(document.createTextNode(n.v)); break;
130
+ case 'br': host.appendChild(document.createElement('br')); break;
131
+ case 'code': host.appendChild(mk('code', KIT_MD_CODE_CLASS, n.v)); break;
132
+ case 'strong': { const el = mk('strong', KIT_MD_STRONG_CLASS); inlineInto(el, n.c, ctx); host.appendChild(el); break; }
133
+ case 'em': { const el = mk('em', ''); inlineInto(el, n.c, ctx); host.appendChild(el); break; }
134
+ case 'del': { const el = mk('del', KIT_MD_DEL_CLASS); inlineInto(el, n.c, ctx); host.appendChild(el); break; }
135
+ case 'link': {
136
+ const a = mk('a', KIT_MD_LINK_CLASS);
137
+ a.href = n.href.startsWith('#md-') ? `#${ctx.idPrefix}${n.href.slice(1)}` : n.href;
138
+ if (n.title) a.title = n.title;
139
+ inlineInto(a, n.c, ctx);
140
+ if (n.external) {
141
+ a.target = '_blank';
142
+ a.rel = 'noopener noreferrer nofollow';
143
+ const icon = kitIcon('external-link', 'xs', EXT_ICON_CLASS);
144
+ icon.setAttribute('aria-hidden', 'true');
145
+ a.appendChild(icon);
146
+ a.appendChild(mk('span', 'sr-only', kitText('soma.kit.md_external', undefined, ctx.root)));
147
+ }
148
+ host.appendChild(a);
149
+ break;
150
+ }
151
+ case 'image': {
152
+ const img = mk('img', KIT_MD_IMG_CLASS);
153
+ img.src = n.src;
154
+ img.alt = n.alt;
155
+ if (n.title) img.title = n.title;
156
+ img.setAttribute('loading', 'lazy');
157
+ img.setAttribute('decoding', 'async');
158
+ img.setAttribute('referrerpolicy', 'no-referrer');
159
+ img.addEventListener('error', () => {
160
+ img.replaceWith(mk('span', IMG_FAIL_CLASS, kitText('soma.kit.md_image_failed', { alt: n.alt !== '' ? n.alt : n.src }, ctx.root)));
161
+ }, { once: true });
162
+ host.appendChild(img);
163
+ break;
164
+ }
165
+ case 'fnref': {
166
+ const sup = mk('sup', KIT_MD_FNREF_CLASS);
167
+ const a = mk('a', KIT_MD_LINK_CLASS, `[${n.n}]`);
168
+ a.href = `#${ctx.idPrefix}${n.id}`;
169
+ a.setAttribute('aria-label', kitText('soma.kit.md_fnref', { n: n.n }, ctx.root));
170
+ sup.appendChild(a);
171
+ host.appendChild(sup);
172
+ break;
173
+ }
174
+ default: break;
175
+ }
176
+ }
177
+ }
178
+
179
+ /** 一个块 → DOM(level = 0 表示顶层,用于首行缩进判定) */
180
+ export function renderMdBlock(b: KitMdBlock, ctx: KitMdRenderContext, level: number): HTMLElement {
181
+ switch (b.t) {
182
+ case 'heading': {
183
+ const depth = Math.min(6, b.depth + ctx.headingOffset);
184
+ const h = mk(`h${depth}` as 'h1', kitMdHeadingClass(depth));
185
+ h.id = `${ctx.idPrefix}${b.id}`;
186
+ inlineInto(h, b.inline, ctx);
187
+ return h;
188
+ }
189
+ case 'paragraph': {
190
+ const cls = b.tight ? KIT_MD_P_TIGHT_CLASS : level === 0 && ctx.indent && !imageOnly(b.inline) ? KIT_MD_P_INDENT_CLASS : KIT_MD_P_CLASS;
191
+ const p = mk('p', cls);
192
+ inlineInto(p, b.inline, ctx);
193
+ return p;
194
+ }
195
+ case 'list': {
196
+ const tasky = b.items.some((it) => it.task !== null);
197
+ const list = mk(b.ordered ? 'ol' : 'ul', `${KIT_MD_LIST_CLASS} ${tasky ? '' : KIT_MD_LIST_STYLE[b.ordered ? 'ol' : 'ul']}`.trim());
198
+ if (b.ordered && b.start !== undefined) (list as HTMLOListElement).start = b.start;
199
+ for (const it of b.items) {
200
+ const li = mk('li', it.task !== null ? KIT_MD_TASK_CLASS : KIT_MD_LI_CLASS);
201
+ if (it.task !== null) {
202
+ const box = mk('span', TASK_BOX_CLASS);
203
+ markCheckBox(box);
204
+ box.setAttribute('role', 'checkbox');
205
+ box.setAttribute('aria-checked', it.task ? 'true' : 'false');
206
+ box.setAttribute('aria-disabled', 'true');
207
+ box.setAttribute('aria-label', kitText(it.task ? 'soma.kit.md_task_done' : 'soma.kit.md_task_todo', undefined, ctx.root));
208
+ if (it.task) box.appendChild(kitIcon('check', 'xs'));
209
+ li.appendChild(box);
210
+ const body = mk('div', 'min-w-0');
211
+ for (const c of it.blocks) body.appendChild(renderMdBlock(c, ctx, level + 1));
212
+ li.appendChild(body);
213
+ } else {
214
+ for (const c of it.blocks) li.appendChild(renderMdBlock(c, ctx, level + 1));
215
+ }
216
+ list.appendChild(li);
217
+ }
218
+ return list;
219
+ }
220
+ case 'quote': {
221
+ const q = mk('blockquote', KIT_MD_QUOTE_CLASS);
222
+ for (const c of b.blocks) q.appendChild(renderMdBlock(c, ctx, level + 1));
223
+ return q;
224
+ }
225
+ case 'code': {
226
+ const well = mk('div', CODE_WELL_CLASS);
227
+ well.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_WELL);
228
+ well.setAttribute(KIT_ATTR_MD_CODE, '');
229
+ CODE_RAW_TEXT.set(well, b.text);
230
+ const hl = ctx.highlight;
231
+ const language = hl === null ? 'text' : hl.resolveLanguage({ fence: b.lang, sample: b.text.length <= KIT_CONTENT_LIMITS.codeView.sniffMaxChars ? b.text : '' });
232
+ const label = language !== 'text' && hl !== null ? hl.languageLabel(language) : b.lang;
233
+ if (label !== '' || ctx.copyCode) {
234
+ const head = mk('div', CODE_HEAD_CLASS);
235
+ head.appendChild(mk('span', KIT_CODE_LANG_CLASS, label));
236
+ if (ctx.copyCode) head.appendChild(textActionButton('md-copy-code', kitText('soma.kit.copy', undefined, ctx.root), 'copy-text'));
237
+ well.appendChild(head);
238
+ }
239
+ well.setAttribute('role', 'region');
240
+ well.setAttribute(KIT_ATTR_CONTAINER, 'plain');
241
+ well.setAttribute('aria-label', kitText('soma.kit.code_region', { name: label !== '' ? label : kitText('soma.kit.code_plain', undefined, ctx.root) }, ctx.root));
242
+ paintCodeLines(well, b.text, {
243
+ language: b.closed ? language : 'text',
244
+ wrap: codeWrapDefault(language, b.text.split('\n')),
245
+ port: b.closed ? hl : null,
246
+ root: ctx.root,
247
+ current: () => (ctx.current ? ctx.current() : true) && ctx.root.contains(well),
248
+ });
249
+ return well;
250
+ }
251
+ case 'table': {
252
+ const wrap = mk('div', KIT_MD_TABLE_WRAP_CLASS);
253
+ wrap.tabIndex = 0;
254
+ wrap.setAttribute('role', 'region');
255
+ wrap.setAttribute(KIT_ATTR_CONTAINER, 'plain');
256
+ wrap.setAttribute('aria-label', kitText('soma.kit.md_table', undefined, ctx.root));
257
+ const table = mk('table', KIT_MD_TABLE_CLASS);
258
+ const alignClass = (i: number): string => (b.align[i] === 'right' ? ' text-end' : b.align[i] === 'center' ? ' text-center' : ' text-start');
259
+ const thead = mk('thead', '');
260
+ const hr = mk('tr', '');
261
+ b.head.forEach((cell, i) => { const th = mk('th', `${KIT_MD_TH_CLASS}${alignClass(i)}`); th.scope = 'col'; inlineInto(th, cell, ctx); hr.appendChild(th); });
262
+ thead.appendChild(hr);
263
+ table.appendChild(thead);
264
+ const tbody = mk('tbody', '');
265
+ for (const row of b.rows) {
266
+ const tr = mk('tr', '');
267
+ row.forEach((cell, i) => { const td = mk('td', `${KIT_MD_TD_CLASS}${alignClass(i)}`); inlineInto(td, cell, ctx); tr.appendChild(td); });
268
+ tbody.appendChild(tr);
269
+ }
270
+ table.appendChild(tbody);
271
+ wrap.appendChild(table);
272
+ return wrap;
273
+ }
274
+ case 'hr': return mk('hr', KIT_MD_HR_CLASS);
275
+ case 'html': return mk('pre', KIT_MD_HTML_CLASS, b.text);
276
+ case 'footnotes': {
277
+ const sec = mk('section', KIT_MD_FOOTNOTES_CLASS);
278
+ sec.setAttribute(KIT_ATTR_CONTAINER, 'plain');
279
+ sec.setAttribute('aria-label', kitText('soma.kit.md_footnotes', undefined, ctx.root));
280
+ const ol = mk('ol', `${KIT_MD_LIST_CLASS} ${KIT_MD_LIST_STYLE.ol}`);
281
+ for (const f of b.items) {
282
+ const li = mk('li', KIT_MD_LI_CLASS);
283
+ li.id = `${ctx.idPrefix}${f.id}`;
284
+ for (const c of f.blocks) li.appendChild(renderMdBlock(c, ctx, level + 1));
285
+ ol.appendChild(li);
286
+ }
287
+ sec.appendChild(ol);
288
+ return sec;
289
+ }
290
+ default: return mk('div', '');
291
+ }
292
+ }
293
+
294
+ /** 纯文本降级:按空行分段 */
295
+ export function renderMdPlain(host: HTMLElement, text: string): void {
296
+ for (const para of text.split(/\n{2,}/u)) if (para.trim() !== '') host.appendChild(mk('p', PLAIN_P_CLASS, para));
297
+ }
298
+
299
+ /** 块尾提示:原始 HTML、不安全地址、截断 */
300
+ export function mdNotes(meta: KitMdMeta, root: HTMLElement): HTMLElement[] {
301
+ const out: HTMLElement[] = [];
302
+ if (meta.dropped.html > 0) out.push(mk('p', NOTE_CLASS, kitText('soma.kit.md_html_dropped', { n: meta.dropped.html }, root)));
303
+ if (meta.dropped.unsafeUrls > 0) out.push(mk('p', NOTE_CLASS, kitText('soma.kit.md_unsafe_urls', { n: meta.dropped.unsafeUrls }, root)));
304
+ if (meta.truncated) out.push(mk('p', NOTE_CLASS, kitText('soma.kit.md_truncated', undefined, root)));
305
+ return out;
306
+ }
307
+
308
+ // ── 组件 ──────────────────────────────────────────────────────────────
309
+
310
+ interface ViewState {
311
+ wantedSource: string | null;
312
+ parsedSource: string | null;
313
+ result: KitMdResult | null;
314
+ parseSeq: number;
315
+ alive: boolean;
316
+ latestServices: unknown;
317
+ /** 流式:已画块的指纹与节点 */
318
+ keys: string[];
319
+ nodes: HTMLElement[];
320
+ timer: ReturnType<typeof setTimeout> | null;
321
+ copyTimers: Map<HTMLElement, ReturnType<typeof setTimeout>>;
322
+ lastParse: number;
323
+ indent: boolean;
324
+ }
325
+
326
+ let instanceSeq = 0;
327
+
328
+ export function createMarkdownView(): SomaComponentDefinition {
329
+ const states = new WeakMap<HTMLElement, ViewState>();
330
+ const prefixes = new WeakMap<HTMLElement, string>();
331
+ const stateOf = (root: HTMLElement): ViewState => {
332
+ let st = states.get(root);
333
+ if (st === undefined) {
334
+ st = {
335
+ wantedSource: null, parsedSource: null, result: null, parseSeq: 0, alive: true, latestServices: undefined,
336
+ keys: [], nodes: [], timer: null, copyTimers: new Map(), lastParse: 0, indent: false,
337
+ };
338
+ states.set(root, st);
339
+ }
340
+ return st;
341
+ };
342
+ const prefixOf = (root: HTMLElement): string => {
343
+ let p = prefixes.get(root);
344
+ if (p === undefined) { instanceSeq += 1; p = `kmd${instanceSeq}-`; prefixes.set(root, p); }
345
+ return p;
346
+ };
347
+
348
+ return {
349
+ contract: {
350
+ name: 'MarkdownView',
351
+ layer: 'data',
352
+ props: {
353
+ data: { type: 'any', default: '', desc: 'Markdown 原文字符串,或 { source | markdown | content | text },或字符串数组(按块拼接);经 core 端口 engines.markdown 解析' },
354
+ path: { type: 'string', default: '', desc: '只看 data 里的一个点路径(如 detail.description)' },
355
+ heading_offset: { type: 'number', default: 0, desc: '标题层级偏移(0–5):嵌在详情里时 # 从更低的层级开始,组件不另改层级' },
356
+ toc: { type: 'enum', values: ['auto', 'off'], default: 'auto', desc: '目录:auto = 二级以上标题够多且正文够长才出(阈值 kit-limits#content.markdownView)' },
357
+ stream: { type: 'boolean', default: false, desc: '流式(AI 逐字输出):原文不断增长,按帧节流重解析,只替换变化的块' },
358
+ copy_code: { type: 'boolean', default: true, desc: '代码块出「复制」钮' },
359
+ empty_text: { type: 'string', default: '', desc: '没有内容时的文案;缺省取内置文案' },
360
+ aria_label: { type: 'string', default: '', desc: '正文区的无障碍名称' },
361
+ class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
362
+ },
363
+ emits: {
364
+ copy: { payload: { ok: { type: 'boolean' } }, desc: '代码块复制后抛;不带文本' },
365
+ },
366
+ },
367
+ services: ['engines'],
368
+ templateHtml: `<article ${KIT_ATTR_CONTAINER}="plain" data-soma-id="root" class="${ROOT_CLASS}"></article>`,
369
+ controllerFactory: createKitController((api) => ({
370
+ attach(root) {
371
+ const initSt = stateOf(root);
372
+ initSt.alive = true;
373
+ const onClick = (event: Event): void => {
374
+ const btn = (event.target as HTMLElement | null)?.closest<HTMLElement>(kitAttrSel(KIT_ATTR_ACTION, 'md-copy-code'));
375
+ if (!btn || !root.contains(btn)) return;
376
+ const well = btn.closest<HTMLElement>(kitAttrSel(KIT_ATTR_MD_CODE));
377
+ const text = (well ? CODE_RAW_TEXT.get(well) : undefined) ?? '';
378
+ void (async () => {
379
+ let ok = false;
380
+ try { if (typeof navigator !== 'undefined' && navigator.clipboard) { await navigator.clipboard.writeText(text); ok = true; } } catch { ok = false; }
381
+ const curSt = states.get(root);
382
+ if (ok && curSt?.alive) {
383
+ btn.textContent = kitText('soma.kit.copied', undefined, root);
384
+ const prevTm = curSt.copyTimers.get(btn);
385
+ if (prevTm !== undefined) clearTimeout(prevTm);
386
+ const tm = setTimeout(() => {
387
+ curSt.copyTimers.delete(btn);
388
+ if (curSt.alive && root.contains(btn)) {
389
+ btn.textContent = kitText('soma.kit.copy', undefined, root);
390
+ }
391
+ }, KIT_CONTENT_LIMITS.codeView.copyFeedbackMs);
392
+ curSt.copyTimers.set(btn, tm);
393
+ }
394
+ if (curSt?.alive !== false) api.emit('copy', { ok });
395
+ })();
396
+ };
397
+ root.addEventListener('click', onClick);
398
+ return () => {
399
+ root.removeEventListener('click', onClick);
400
+ const st = states.get(root);
401
+ if (st) {
402
+ st.alive = false;
403
+ st.parseSeq += 1;
404
+ if (st.timer !== null) {
405
+ clearTimeout(st.timer);
406
+ st.timer = null;
407
+ }
408
+ for (const tm of st.copyTimers.values()) clearTimeout(tm);
409
+ st.copyTimers.clear();
410
+ }
411
+ states.delete(root);
412
+ };
413
+ },
414
+ render(root, p, renderApi) {
415
+ const st = stateOf(root);
416
+ st.alive = true;
417
+ st.latestServices = renderApi.services;
418
+ const source = markdownSourceOf(pathOf(p.data, str(p.path)));
419
+ const stream = bool(p.stream);
420
+
421
+ if (source.trim() === '') {
422
+ if (st.timer !== null) {
423
+ clearTimeout(st.timer);
424
+ st.timer = null;
425
+ }
426
+ st.wantedSource = source;
427
+ st.parsedSource = source;
428
+ st.result = null;
429
+ st.parseSeq += 1;
430
+ root.setAttribute('aria-busy', stream ? 'true' : 'false');
431
+ paintEmpty(root, p);
432
+ return;
433
+ }
434
+
435
+ if (source === st.parsedSource && st.result !== null && st.timer === null) {
436
+ st.wantedSource = source;
437
+ paint(root, p, st.latestServices, st, false);
438
+ return;
439
+ }
440
+
441
+ st.wantedSource = source;
442
+ if (stream) root.setAttribute('aria-busy', 'true');
443
+
444
+ const scheduleOrRun = (streaming: boolean): void => {
445
+ if (!st.alive) return;
446
+ if (!streaming) {
447
+ if (st.timer !== null) {
448
+ clearTimeout(st.timer);
449
+ st.timer = null;
450
+ }
451
+ run();
452
+ return;
453
+ }
454
+ if (st.timer !== null) return;
455
+ const wait = Math.max(0, ML.streamThrottleMs - (Date.now() - st.lastParse));
456
+ st.timer = setTimeout(run, wait);
457
+ };
458
+
459
+ const run = (): void => {
460
+ st.timer = null;
461
+ if (!st.alive) return;
462
+ const text = st.wantedSource ?? '';
463
+ const latestP = api.props();
464
+ const latestServices = st.latestServices;
465
+ if (text.trim() === '') {
466
+ st.parsedSource = text;
467
+ st.result = null;
468
+ st.parseSeq += 1;
469
+ root.setAttribute('aria-busy', bool(latestP.stream) ? 'true' : 'false');
470
+ paintEmpty(root, latestP);
471
+ return;
472
+ }
473
+ const port = kitEnginePort<KitMarkdownEnginePort>(latestServices, 'markdown');
474
+ if (port === null) {
475
+ st.parsedSource = text;
476
+ st.result = { ok: false, reason: 'engine-load-failed', plainText: text };
477
+ paint(root, latestP, latestServices, st, false);
478
+ return;
479
+ }
480
+ st.lastParse = Date.now();
481
+ const mine = (st.parseSeq += 1);
482
+ void port.parse(text).then((res) => {
483
+ if (!st.alive || st.parseSeq !== mine) return;
484
+ st.parsedSource = text;
485
+ st.result = res;
486
+ const curP = api.props();
487
+ const stillStreaming = bool(curP.stream);
488
+ paint(root, curP, st.latestServices, st, stillStreaming);
489
+ if (st.wantedSource !== null && st.wantedSource !== text) {
490
+ scheduleOrRun(stillStreaming);
491
+ }
492
+ }, () => {
493
+ if (!st.alive || st.parseSeq !== mine) return;
494
+ st.parsedSource = text;
495
+ st.result = { ok: false, reason: 'parse-error', plainText: text };
496
+ const curP = api.props();
497
+ paint(root, curP, st.latestServices, st, false);
498
+ });
499
+ };
500
+
501
+ scheduleOrRun(stream);
502
+ },
503
+ })),
504
+ };
505
+
506
+ function pathOf(data: unknown, path: string): unknown {
507
+ if (path.trim() === '') return data;
508
+ let cur: unknown = data;
509
+ for (const part of path.trim().split('.')) {
510
+ if (cur === null || typeof cur !== 'object') return undefined;
511
+ cur = (cur as Record<string, unknown>)[part];
512
+ }
513
+ return cur;
514
+ }
515
+
516
+ function paintEmpty(root: HTMLElement, p: Record<string, unknown>): void {
517
+ const st = stateOf(root);
518
+ st.keys = [];
519
+ st.nodes = [];
520
+ root.className = joinClass(ROOT_CLASS, p.class);
521
+ root.textContent = '';
522
+ kitMarkDataFacts(root, { empty: true });
523
+ root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty_content', undefined, root))));
524
+ }
525
+
526
+ function paint(root: HTMLElement, p: Record<string, unknown>, services: unknown, st: ViewState, incremental: boolean): void {
527
+ const res = st.result;
528
+ root.className = joinClass(ROOT_CLASS, p.class);
529
+ if (res === null) { paintEmpty(root, p); return; }
530
+ root.setAttribute('aria-busy', bool(p.stream) ? 'true' : 'false');
531
+ // 数据状态:解析失败 / 过长 / 引擎载入失败 = 出错(仍按纯文本兜底展示),其余常态
532
+ kitMarkDataFacts(root, { error: !res.ok });
533
+ if (!res.ok) {
534
+ st.keys = [];
535
+ st.nodes = [];
536
+ root.textContent = '';
537
+ const body = mk('div', KIT_MD_BODY_CLASS);
538
+ renderMdPlain(body, res.plainText);
539
+ root.appendChild(body);
540
+ const key = res.reason === 'too-long' ? 'soma.kit.md_too_long' : res.reason === 'engine-load-failed' ? 'soma.kit.md_engine_failed' : 'soma.kit.md_parse_failed';
541
+ root.appendChild(mk('p', NOTE_CLASS, kitText(key, undefined, root)));
542
+ return;
543
+ }
544
+ const ctx: KitMdRenderContext = {
545
+ root, headingOffset: Math.max(0, Math.min(5, Math.floor(Number(p.heading_offset) || 0))), idPrefix: prefixOf(root),
546
+ indent: markdownIndentTopLevel(res.blocks), highlight: kitEnginePort<KitHighlightEnginePort>(services, 'highlight'),
547
+ copyCode: p.copy_code === undefined ? true : bool(p.copy_code),
548
+ current: () => st.alive,
549
+ };
550
+ const keys = res.blocks.map((b) => JSON.stringify(b));
551
+ let body = root.querySelector<HTMLElement>(`:scope > ${kitAttrSel(KIT_ATTR_MD_BODY)}`);
552
+ // 流式增量:正文容器还在就从第一个变化的块起替换;否则整段重画
553
+ if (!incremental || body === null || st.nodes.length === 0 || st.nodes.some((n) => !body!.contains(n))) {
554
+ root.textContent = '';
555
+ const toc = markdownTocOf(res.meta, str(p.toc, 'auto'));
556
+ if (toc.length > 0) root.appendChild(tocNode(toc, ctx));
557
+ body = mk('div', KIT_MD_BODY_CLASS);
558
+ body.setAttribute(KIT_ATTR_MD_BODY, '');
559
+ const label = str(p.aria_label);
560
+ if (label !== '') { body.setAttribute('role', 'region'); body.setAttribute(KIT_ATTR_CONTAINER, 'plain'); body.setAttribute('aria-label', label); }
561
+ root.appendChild(body);
562
+ st.keys = [];
563
+ st.nodes = [];
564
+ }
565
+ let from = 0;
566
+ // 缩进判定随全文变化(单段 → 多段),变了就从头替换
567
+ if (ctx.indent === st.indent) while (from < keys.length && from < st.keys.length && keys[from] === st.keys[from]) from += 1;
568
+ st.indent = ctx.indent;
569
+ for (const n of st.nodes.slice(from)) n.remove();
570
+ const nodes = st.nodes.slice(0, from);
571
+ for (let i = from; i < res.blocks.length; i += 1) {
572
+ const el = renderMdBlock(res.blocks[i]!, ctx, 0);
573
+ body.appendChild(el);
574
+ nodes.push(el);
575
+ }
576
+ st.keys = keys;
577
+ st.nodes = nodes;
578
+ for (const old of Array.from(root.querySelectorAll(`:scope > ${kitAttrSel(KIT_ATTR_MD_NOTE)}`))) old.remove();
579
+ for (const note of mdNotes(res.meta, root)) { note.setAttribute(KIT_ATTR_MD_NOTE, ''); root.appendChild(note); }
580
+ }
581
+
582
+ function tocNode(toc: KitMdMeta['outline'], ctx: KitMdRenderContext): HTMLElement {
583
+ const nav = mk('nav', TOC_CLASS);
584
+ // 目录块是正文旁成块的子内容;目录标题 = 块标题
585
+ kitMarkLevel(nav, 'sub'); kitApplyLevelClass(nav);
586
+ nav.setAttribute('aria-label', kitText('soma.kit.md_toc', undefined, ctx.root));
587
+ const tocTitle = mk('span', TOC_TITLE_CLASS, kitText('soma.kit.md_toc', undefined, ctx.root));
588
+ kitMarkPart(tocTitle, 'block-title');
589
+ nav.appendChild(tocTitle);
590
+ for (const o of toc) {
591
+ const a = mk('a', `${KIT_MD_LINK_CLASS} ${TOC_ITEM_CLASS[o.depth] ?? 'ps-4'}`, o.text);
592
+ a.href = `#${ctx.idPrefix}${o.id}`;
593
+ nav.appendChild(a);
594
+ }
595
+ return nav;
596
+ }
597
+ }