@textui/widgets 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 (423) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +69 -0
  3. package/dist/chart/area-chart.d.ts +4 -0
  4. package/dist/chart/area-chart.d.ts.map +1 -0
  5. package/dist/chart/area-chart.js +3 -0
  6. package/dist/chart/bar-chart.d.ts +32 -0
  7. package/dist/chart/bar-chart.d.ts.map +1 -0
  8. package/dist/chart/bar-chart.js +32 -0
  9. package/dist/chart/gauge.d.ts +26 -0
  10. package/dist/chart/gauge.d.ts.map +1 -0
  11. package/dist/chart/gauge.js +26 -0
  12. package/dist/chart/heatmap.d.ts +13 -0
  13. package/dist/chart/heatmap.d.ts.map +1 -0
  14. package/dist/chart/heatmap.js +27 -0
  15. package/dist/chart/histogram.d.ts +12 -0
  16. package/dist/chart/histogram.d.ts.map +1 -0
  17. package/dist/chart/histogram.js +22 -0
  18. package/dist/chart/index.d.ts +20 -0
  19. package/dist/chart/index.d.ts.map +1 -0
  20. package/dist/chart/index.js +32 -0
  21. package/dist/chart/line-chart.d.ts +7 -0
  22. package/dist/chart/line-chart.d.ts.map +1 -0
  23. package/dist/chart/line-chart.js +75 -0
  24. package/dist/chart/shared.d.ts +34 -0
  25. package/dist/chart/shared.d.ts.map +1 -0
  26. package/dist/chart/shared.js +78 -0
  27. package/dist/chart/sparkline.d.ts +15 -0
  28. package/dist/chart/sparkline.d.ts.map +1 -0
  29. package/dist/chart/sparkline.js +22 -0
  30. package/dist/control/button.d.ts +27 -0
  31. package/dist/control/button.d.ts.map +1 -0
  32. package/dist/control/button.js +130 -0
  33. package/dist/control/checkbox.d.ts +10 -0
  34. package/dist/control/checkbox.d.ts.map +1 -0
  35. package/dist/control/checkbox.js +31 -0
  36. package/dist/control/index.d.ts +20 -0
  37. package/dist/control/index.d.ts.map +1 -0
  38. package/dist/control/index.js +36 -0
  39. package/dist/control/radio-group.d.ts +17 -0
  40. package/dist/control/radio-group.d.ts.map +1 -0
  41. package/dist/control/radio-group.js +32 -0
  42. package/dist/control/search-box.d.ts +7 -0
  43. package/dist/control/search-box.d.ts.map +1 -0
  44. package/dist/control/search-box.js +3 -0
  45. package/dist/control/select.d.ts +42 -0
  46. package/dist/control/select.d.ts.map +1 -0
  47. package/dist/control/select.js +166 -0
  48. package/dist/control/shared.d.ts +41 -0
  49. package/dist/control/shared.d.ts.map +1 -0
  50. package/dist/control/shared.js +1 -0
  51. package/dist/control/slider.d.ts +14 -0
  52. package/dist/control/slider.d.ts.map +1 -0
  53. package/dist/control/slider.js +45 -0
  54. package/dist/control/switch.d.ts +10 -0
  55. package/dist/control/switch.d.ts.map +1 -0
  56. package/dist/control/switch.js +32 -0
  57. package/dist/control/text-area.d.ts +87 -0
  58. package/dist/control/text-area.d.ts.map +1 -0
  59. package/dist/control/text-area.js +299 -0
  60. package/dist/control/text-input.d.ts +10 -0
  61. package/dist/control/text-input.d.ts.map +1 -0
  62. package/dist/control/text-input.js +129 -0
  63. package/dist/data/code-viewer.d.ts +71 -0
  64. package/dist/data/code-viewer.d.ts.map +1 -0
  65. package/dist/data/code-viewer.js +232 -0
  66. package/dist/data/feed.d.ts +43 -0
  67. package/dist/data/feed.d.ts.map +1 -0
  68. package/dist/data/feed.js +178 -0
  69. package/dist/data/index.d.ts +54 -0
  70. package/dist/data/index.d.ts.map +1 -0
  71. package/dist/data/index.js +187 -0
  72. package/dist/data/list.d.ts +31 -0
  73. package/dist/data/list.d.ts.map +1 -0
  74. package/dist/data/list.js +104 -0
  75. package/dist/data/log-viewer.d.ts +26 -0
  76. package/dist/data/log-viewer.d.ts.map +1 -0
  77. package/dist/data/log-viewer.js +69 -0
  78. package/dist/data/markdown-view.d.ts +31 -0
  79. package/dist/data/markdown-view.d.ts.map +1 -0
  80. package/dist/data/markdown-view.js +139 -0
  81. package/dist/data/pagination.d.ts +9 -0
  82. package/dist/data/pagination.d.ts.map +1 -0
  83. package/dist/data/pagination.js +18 -0
  84. package/dist/data/scroll-thumb.d.ts +15 -0
  85. package/dist/data/scroll-thumb.d.ts.map +1 -0
  86. package/dist/data/scroll-thumb.js +32 -0
  87. package/dist/data/shared.d.ts +12 -0
  88. package/dist/data/shared.d.ts.map +1 -0
  89. package/dist/data/shared.js +17 -0
  90. package/dist/data/tree.d.ts +35 -0
  91. package/dist/data/tree.d.ts.map +1 -0
  92. package/dist/data/tree.js +158 -0
  93. package/dist/decorations.d.ts +88 -0
  94. package/dist/decorations.d.ts.map +1 -0
  95. package/dist/decorations.js +135 -0
  96. package/dist/display/alert.d.ts +8 -0
  97. package/dist/display/alert.d.ts.map +1 -0
  98. package/dist/display/alert.js +12 -0
  99. package/dist/display/badge.d.ts +10 -0
  100. package/dist/display/badge.d.ts.map +1 -0
  101. package/dist/display/badge.js +21 -0
  102. package/dist/display/card.d.ts +8 -0
  103. package/dist/display/card.d.ts.map +1 -0
  104. package/dist/display/card.js +12 -0
  105. package/dist/display/empty-state.d.ts +10 -0
  106. package/dist/display/empty-state.d.ts.map +1 -0
  107. package/dist/display/empty-state.js +5 -0
  108. package/dist/display/error-state.d.ts +9 -0
  109. package/dist/display/error-state.d.ts.map +1 -0
  110. package/dist/display/error-state.js +7 -0
  111. package/dist/display/heading.d.ts +6 -0
  112. package/dist/display/heading.d.ts.map +1 -0
  113. package/dist/display/heading.js +8 -0
  114. package/dist/display/index.d.ts +25 -0
  115. package/dist/display/index.d.ts.map +1 -0
  116. package/dist/display/index.js +52 -0
  117. package/dist/display/key-value.d.ts +14 -0
  118. package/dist/display/key-value.d.ts.map +1 -0
  119. package/dist/display/key-value.js +11 -0
  120. package/dist/display/label.d.ts +6 -0
  121. package/dist/display/label.d.ts.map +1 -0
  122. package/dist/display/label.js +3 -0
  123. package/dist/display/marquee.d.ts +36 -0
  124. package/dist/display/marquee.d.ts.map +1 -0
  125. package/dist/display/marquee.js +55 -0
  126. package/dist/display/progress.d.ts +39 -0
  127. package/dist/display/progress.d.ts.map +1 -0
  128. package/dist/display/progress.js +46 -0
  129. package/dist/display/skeleton.d.ts +20 -0
  130. package/dist/display/skeleton.d.ts.map +1 -0
  131. package/dist/display/skeleton.js +20 -0
  132. package/dist/display/spinner.d.ts +7 -0
  133. package/dist/display/spinner.d.ts.map +1 -0
  134. package/dist/display/spinner.js +9 -0
  135. package/dist/display/status-dot.d.ts +8 -0
  136. package/dist/display/status-dot.d.ts.map +1 -0
  137. package/dist/display/status-dot.js +13 -0
  138. package/dist/display/timeline.d.ts +12 -0
  139. package/dist/display/timeline.d.ts.map +1 -0
  140. package/dist/display/timeline.js +22 -0
  141. package/dist/find.d.ts +74 -0
  142. package/dist/find.d.ts.map +1 -0
  143. package/dist/find.js +102 -0
  144. package/dist/form/danger-zone.d.ts +11 -0
  145. package/dist/form/danger-zone.d.ts.map +1 -0
  146. package/dist/form/danger-zone.js +15 -0
  147. package/dist/form/field.d.ts +19 -0
  148. package/dist/form/field.d.ts.map +1 -0
  149. package/dist/form/field.js +35 -0
  150. package/dist/form/form-actions.d.ts +11 -0
  151. package/dist/form/form-actions.d.ts.map +1 -0
  152. package/dist/form/form-actions.js +16 -0
  153. package/dist/form/form-section.d.ts +7 -0
  154. package/dist/form/form-section.d.ts.map +1 -0
  155. package/dist/form/form-section.js +5 -0
  156. package/dist/form/form.d.ts +7 -0
  157. package/dist/form/form.d.ts.map +1 -0
  158. package/dist/form/form.js +3 -0
  159. package/dist/form/index.d.ts +42 -0
  160. package/dist/form/index.d.ts.map +1 -0
  161. package/dist/form/index.js +140 -0
  162. package/dist/form/shared.d.ts +25 -0
  163. package/dist/form/shared.d.ts.map +1 -0
  164. package/dist/form/shared.js +9 -0
  165. package/dist/index.d.ts +26 -0
  166. package/dist/index.d.ts.map +1 -0
  167. package/dist/index.js +62 -0
  168. package/dist/layout/center.d.ts +7 -0
  169. package/dist/layout/center.d.ts.map +1 -0
  170. package/dist/layout/center.js +8 -0
  171. package/dist/layout/column.d.ts +3 -0
  172. package/dist/layout/column.d.ts.map +1 -0
  173. package/dist/layout/column.js +2 -0
  174. package/dist/layout/divider.d.ts +11 -0
  175. package/dist/layout/divider.d.ts.map +1 -0
  176. package/dist/layout/divider.js +13 -0
  177. package/dist/layout/grid.d.ts +10 -0
  178. package/dist/layout/grid.d.ts.map +1 -0
  179. package/dist/layout/grid.js +22 -0
  180. package/dist/layout/index.d.ts +19 -0
  181. package/dist/layout/index.d.ts.map +1 -0
  182. package/dist/layout/index.js +36 -0
  183. package/dist/layout/panel.d.ts +37 -0
  184. package/dist/layout/panel.d.ts.map +1 -0
  185. package/dist/layout/panel.js +71 -0
  186. package/dist/layout/row.d.ts +7 -0
  187. package/dist/layout/row.d.ts.map +1 -0
  188. package/dist/layout/row.js +2 -0
  189. package/dist/layout/scroll-view.d.ts +27 -0
  190. package/dist/layout/scroll-view.d.ts.map +1 -0
  191. package/dist/layout/scroll-view.js +93 -0
  192. package/dist/layout/splitter.d.ts +10 -0
  193. package/dist/layout/splitter.d.ts.map +1 -0
  194. package/dist/layout/splitter.js +9 -0
  195. package/dist/layout/stack.d.ts +7 -0
  196. package/dist/layout/stack.d.ts.map +1 -0
  197. package/dist/layout/stack.js +5 -0
  198. package/dist/navigation/breadcrumb.d.ts +14 -0
  199. package/dist/navigation/breadcrumb.d.ts.map +1 -0
  200. package/dist/navigation/breadcrumb.js +24 -0
  201. package/dist/navigation/index.d.ts +17 -0
  202. package/dist/navigation/index.d.ts.map +1 -0
  203. package/dist/navigation/index.js +30 -0
  204. package/dist/navigation/key-hints.d.ts +11 -0
  205. package/dist/navigation/key-hints.d.ts.map +1 -0
  206. package/dist/navigation/key-hints.js +13 -0
  207. package/dist/navigation/menu.d.ts +35 -0
  208. package/dist/navigation/menu.d.ts.map +1 -0
  209. package/dist/navigation/menu.js +88 -0
  210. package/dist/navigation/status-bar.d.ts +18 -0
  211. package/dist/navigation/status-bar.d.ts.map +1 -0
  212. package/dist/navigation/status-bar.js +12 -0
  213. package/dist/navigation/tabs.d.ts +20 -0
  214. package/dist/navigation/tabs.d.ts.map +1 -0
  215. package/dist/navigation/tabs.js +41 -0
  216. package/dist/navigation/toolbar.d.ts +14 -0
  217. package/dist/navigation/toolbar.d.ts.map +1 -0
  218. package/dist/navigation/toolbar.js +10 -0
  219. package/dist/navigation/wizard.d.ts +15 -0
  220. package/dist/navigation/wizard.d.ts.map +1 -0
  221. package/dist/navigation/wizard.js +17 -0
  222. package/dist/overlay/command-palette.d.ts +63 -0
  223. package/dist/overlay/command-palette.d.ts.map +1 -0
  224. package/dist/overlay/command-palette.js +415 -0
  225. package/dist/overlay/dialog.d.ts +16 -0
  226. package/dist/overlay/dialog.d.ts.map +1 -0
  227. package/dist/overlay/dialog.js +44 -0
  228. package/dist/overlay/index.d.ts +84 -0
  229. package/dist/overlay/index.d.ts.map +1 -0
  230. package/dist/overlay/index.js +157 -0
  231. package/dist/overlay/layer-scope.d.ts +21 -0
  232. package/dist/overlay/layer-scope.d.ts.map +1 -0
  233. package/dist/overlay/layer-scope.js +5 -0
  234. package/dist/overlay/path-picker.d.ts +14 -0
  235. package/dist/overlay/path-picker.d.ts.map +1 -0
  236. package/dist/overlay/path-picker.js +200 -0
  237. package/dist/overlay/prompt-dialog.d.ts +12 -0
  238. package/dist/overlay/prompt-dialog.d.ts.map +1 -0
  239. package/dist/overlay/prompt-dialog.js +29 -0
  240. package/dist/overlay/shared.d.ts +17 -0
  241. package/dist/overlay/shared.d.ts.map +1 -0
  242. package/dist/overlay/shared.js +17 -0
  243. package/dist/overlay/toast-host.d.ts +8 -0
  244. package/dist/overlay/toast-host.d.ts.map +1 -0
  245. package/dist/overlay/toast-host.js +19 -0
  246. package/dist/overlay/toast.d.ts +9 -0
  247. package/dist/overlay/toast.d.ts.map +1 -0
  248. package/dist/overlay/toast.js +20 -0
  249. package/dist/overlay/tooltip.d.ts +6 -0
  250. package/dist/overlay/tooltip.d.ts.map +1 -0
  251. package/dist/overlay/tooltip.js +11 -0
  252. package/dist/panel/index.d.ts +79 -0
  253. package/dist/panel/index.d.ts.map +1 -0
  254. package/dist/panel/index.js +256 -0
  255. package/dist/panel/resource-panel.d.ts +93 -0
  256. package/dist/panel/resource-panel.d.ts.map +1 -0
  257. package/dist/panel/resource-panel.js +213 -0
  258. package/dist/panel/shared.d.ts +6 -0
  259. package/dist/panel/shared.d.ts.map +1 -0
  260. package/dist/panel/shared.js +4 -0
  261. package/dist/shells/console-shell.d.ts +8 -0
  262. package/dist/shells/console-shell.d.ts.map +1 -0
  263. package/dist/shells/console-shell.js +30 -0
  264. package/dist/shells/index.d.ts +20 -0
  265. package/dist/shells/index.d.ts.map +1 -0
  266. package/dist/shells/index.js +61 -0
  267. package/dist/shells/paper-shell.d.ts +9 -0
  268. package/dist/shells/paper-shell.d.ts.map +1 -0
  269. package/dist/shells/paper-shell.js +23 -0
  270. package/dist/shells/plain-shell.d.ts +3 -0
  271. package/dist/shells/plain-shell.d.ts.map +1 -0
  272. package/dist/shells/plain-shell.js +11 -0
  273. package/dist/shells/shared.d.ts +12 -0
  274. package/dist/shells/shared.d.ts.map +1 -0
  275. package/dist/shells/shared.js +21 -0
  276. package/dist/shells/workbench-shell.d.ts +9 -0
  277. package/dist/shells/workbench-shell.d.ts.map +1 -0
  278. package/dist/shells/workbench-shell.js +43 -0
  279. package/dist/surface/bar-layout.d.ts +4 -0
  280. package/dist/surface/bar-layout.d.ts.map +1 -0
  281. package/dist/surface/bar-layout.js +7 -0
  282. package/dist/surface/index.d.ts +58 -0
  283. package/dist/surface/index.d.ts.map +1 -0
  284. package/dist/surface/index.js +48 -0
  285. package/dist/surface/inline-layout.d.ts +4 -0
  286. package/dist/surface/inline-layout.d.ts.map +1 -0
  287. package/dist/surface/inline-layout.js +7 -0
  288. package/dist/surface/mount-view.d.ts +7 -0
  289. package/dist/surface/mount-view.d.ts.map +1 -0
  290. package/dist/surface/mount-view.js +19 -0
  291. package/dist/surface/rail-layout.d.ts +4 -0
  292. package/dist/surface/rail-layout.d.ts.map +1 -0
  293. package/dist/surface/rail-layout.js +19 -0
  294. package/dist/surface/shared.d.ts +7 -0
  295. package/dist/surface/shared.d.ts.map +1 -0
  296. package/dist/surface/shared.js +1 -0
  297. package/dist/surface/single-layout.d.ts +4 -0
  298. package/dist/surface/single-layout.d.ts.map +1 -0
  299. package/dist/surface/single-layout.js +18 -0
  300. package/dist/surface/split-layout.d.ts +4 -0
  301. package/dist/surface/split-layout.d.ts.map +1 -0
  302. package/dist/surface/split-layout.js +7 -0
  303. package/dist/surface/stack-layout.d.ts +4 -0
  304. package/dist/surface/stack-layout.d.ts.map +1 -0
  305. package/dist/surface/stack-layout.js +22 -0
  306. package/dist/surface/surface-area.d.ts +16 -0
  307. package/dist/surface/surface-area.d.ts.map +1 -0
  308. package/dist/surface/surface-area.js +32 -0
  309. package/dist/surface/tabs-layout.d.ts +4 -0
  310. package/dist/surface/tabs-layout.d.ts.map +1 -0
  311. package/dist/surface/tabs-layout.js +24 -0
  312. package/dist/tone.d.ts +16 -0
  313. package/dist/tone.d.ts.map +1 -0
  314. package/dist/tone.js +45 -0
  315. package/dist/viewport.d.ts +30 -0
  316. package/dist/viewport.d.ts.map +1 -0
  317. package/dist/viewport.js +17 -0
  318. package/package.json +54 -0
  319. package/src/chart/area-chart.ts +9 -0
  320. package/src/chart/bar-chart.ts +74 -0
  321. package/src/chart/gauge.ts +60 -0
  322. package/src/chart/heatmap.ts +49 -0
  323. package/src/chart/histogram.ts +36 -0
  324. package/src/chart/index.ts +36 -0
  325. package/src/chart/line-chart.ts +100 -0
  326. package/src/chart/shared.ts +112 -0
  327. package/src/chart/sparkline.ts +46 -0
  328. package/src/control/button.ts +184 -0
  329. package/src/control/checkbox.ts +48 -0
  330. package/src/control/index.ts +40 -0
  331. package/src/control/radio-group.ts +60 -0
  332. package/src/control/search-box.ts +15 -0
  333. package/src/control/select.ts +230 -0
  334. package/src/control/shared.ts +41 -0
  335. package/src/control/slider.ts +63 -0
  336. package/src/control/switch.ts +39 -0
  337. package/src/control/text-area.ts +390 -0
  338. package/src/control/text-input.ts +150 -0
  339. package/src/data/code-viewer.ts +337 -0
  340. package/src/data/feed.ts +204 -0
  341. package/src/data/index.ts +243 -0
  342. package/src/data/list.ts +149 -0
  343. package/src/data/log-viewer.ts +105 -0
  344. package/src/data/markdown-view.ts +182 -0
  345. package/src/data/pagination.ts +31 -0
  346. package/src/data/scroll-thumb.ts +40 -0
  347. package/src/data/shared.ts +23 -0
  348. package/src/data/tree.ts +215 -0
  349. package/src/decorations.ts +176 -0
  350. package/src/display/alert.ts +28 -0
  351. package/src/display/badge.ts +40 -0
  352. package/src/display/card.ts +23 -0
  353. package/src/display/empty-state.ts +21 -0
  354. package/src/display/error-state.ts +23 -0
  355. package/src/display/heading.ts +17 -0
  356. package/src/display/index.ts +55 -0
  357. package/src/display/key-value.ts +32 -0
  358. package/src/display/label.ts +11 -0
  359. package/src/display/marquee.ts +88 -0
  360. package/src/display/progress.ts +92 -0
  361. package/src/display/skeleton.ts +34 -0
  362. package/src/display/spinner.ts +20 -0
  363. package/src/display/status-dot.ts +24 -0
  364. package/src/display/timeline.ts +47 -0
  365. package/src/find.ts +138 -0
  366. package/src/form/danger-zone.ts +34 -0
  367. package/src/form/field.ts +61 -0
  368. package/src/form/form-actions.ts +35 -0
  369. package/src/form/form-section.ts +16 -0
  370. package/src/form/form.ts +13 -0
  371. package/src/form/index.ts +191 -0
  372. package/src/form/shared.ts +36 -0
  373. package/src/index.ts +63 -0
  374. package/src/layout/center.ts +17 -0
  375. package/src/layout/column.ts +6 -0
  376. package/src/layout/divider.ts +31 -0
  377. package/src/layout/grid.ts +34 -0
  378. package/src/layout/index.ts +39 -0
  379. package/src/layout/panel.ts +114 -0
  380. package/src/layout/row.ts +11 -0
  381. package/src/layout/scroll-view.ts +115 -0
  382. package/src/layout/splitter.ts +24 -0
  383. package/src/layout/stack.ts +12 -0
  384. package/src/navigation/breadcrumb.ts +43 -0
  385. package/src/navigation/index.ts +33 -0
  386. package/src/navigation/key-hints.ts +25 -0
  387. package/src/navigation/menu.ts +134 -0
  388. package/src/navigation/status-bar.ts +43 -0
  389. package/src/navigation/tabs.ts +73 -0
  390. package/src/navigation/toolbar.ts +25 -0
  391. package/src/navigation/wizard.ts +43 -0
  392. package/src/overlay/command-palette.ts +485 -0
  393. package/src/overlay/dialog.ts +65 -0
  394. package/src/overlay/index.ts +232 -0
  395. package/src/overlay/layer-scope.ts +26 -0
  396. package/src/overlay/path-picker.ts +215 -0
  397. package/src/overlay/prompt-dialog.ts +45 -0
  398. package/src/overlay/shared.ts +19 -0
  399. package/src/overlay/toast-host.ts +30 -0
  400. package/src/overlay/toast.ts +35 -0
  401. package/src/overlay/tooltip.ts +17 -0
  402. package/src/panel/index.ts +317 -0
  403. package/src/panel/resource-panel.ts +304 -0
  404. package/src/panel/shared.ts +8 -0
  405. package/src/shells/console-shell.ts +47 -0
  406. package/src/shells/index.ts +66 -0
  407. package/src/shells/paper-shell.ts +31 -0
  408. package/src/shells/plain-shell.ts +19 -0
  409. package/src/shells/shared.ts +24 -0
  410. package/src/shells/workbench-shell.ts +62 -0
  411. package/src/surface/bar-layout.ts +11 -0
  412. package/src/surface/index.ts +53 -0
  413. package/src/surface/inline-layout.ts +11 -0
  414. package/src/surface/mount-view.ts +30 -0
  415. package/src/surface/rail-layout.ts +27 -0
  416. package/src/surface/shared.ts +7 -0
  417. package/src/surface/single-layout.ts +25 -0
  418. package/src/surface/split-layout.ts +11 -0
  419. package/src/surface/stack-layout.ts +32 -0
  420. package/src/surface/surface-area.ts +46 -0
  421. package/src/surface/tabs-layout.ts +30 -0
  422. package/src/tone.ts +48 -0
  423. package/src/viewport.ts +45 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Softov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @textui/widgets
2
+
3
+ The component catalog: eighty-seven components built out of the four primitives
4
+ in [`@textui/core`](https://github.com/softov/textui/tree/main/packages/core).
5
+
6
+ ```bash
7
+ npm install @textui/widgets
8
+ ```
9
+
10
+ ```tsx
11
+ import { Card, Row, Badge } from '@textui/widgets';
12
+
13
+ <Card title="Services">
14
+ <Row gap={2}>
15
+ <text content="api" />
16
+ <Badge label="up" tone="success" />
17
+ </Row>
18
+ </Card>
19
+ ```
20
+
21
+ ## Importing is registering
22
+
23
+ There is nothing to call first. `<Card/>` compiles to a node that carries the
24
+ imported function, and the runtime uses that in preference to any registry - so
25
+ a screen written in JSX renders with the registry empty.
26
+
27
+ `registerBuiltins(app)` exists for the other case: a screen named in data, where
28
+ a string has to resolve to something.
29
+
30
+ ```ts
31
+ import { createApp } from '@textui/core';
32
+ import { registerBuiltins } from '@textui/widgets';
33
+
34
+ const app = createApp({ terminal, root, onBoot: registerBuiltins });
35
+ ```
36
+
37
+ It registers the catalog, the surface layouts and the built-in shells in one
38
+ call, and returns one `Disposable` that takes all of it back out. For a static
39
+ render, `renderOnce(node, { components: CATALOG })` is the same idea.
40
+
41
+ ## What is here
42
+
43
+ | Group | Count | |
44
+ |---|---|---|
45
+ | `layout` | 10 | Row, Column, Grid, Panel, Splitter, ScrollView |
46
+ | `display` | 14 | Heading, Badge, Card, Alert, Progress, Spinner, Timeline |
47
+ | `control` | 9 | Button, TextInput, TextArea, Select, Checkbox, RadioGroup, Slider, Switch |
48
+ | `data` | 8 | Table, Tree, List, CodeViewer, MarkdownView, Feed |
49
+ | `overlay` | 8 | Dialog, CommandPalette, PathPicker, Toast, Tooltip |
50
+ | `navigation` | 7 | Tabs, Menu, Breadcrumb, Wizard |
51
+ | `surface` | 9 | Mounts and layouts - how a screen is divided |
52
+ | `chart` | 7 | Sparkline, BarChart, LineChart, Histogram, Heatmap, Gauge |
53
+ | `form` | 5 | Form, Field, validation |
54
+ | `shells` | 4 | The frame around an application |
55
+ | `panel` | 1 | A pane that opens a resource with whatever viewer is registered |
56
+
57
+ One file per component, in a folder per group - `src/display/badge.ts`. `ls
58
+ src/display/` is the inventory.
59
+
60
+ ## Runtime
61
+
62
+ No dependencies beyond `@textui/core`, and no `node:` imports. Node 22+ and Bun.
63
+
64
+ ## Documentation
65
+
66
+ <https://softov.github.io/textui/>
67
+
68
+ Every component has its own page, with the prop table generated from the source
69
+ and a working example - see [`docs/components/`](https://softov.github.io/textui/components/).
@@ -0,0 +1,4 @@
1
+ import type { LineChartProps } from './shared.js';
2
+ export type AreaChartProps = LineChartProps;
3
+ export declare const AreaChart: (props: LineChartProps) => import("@textui/core").RenderOutput;
4
+ //# sourceMappingURL=area-chart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"area-chart.d.ts","sourceRoot":"","sources":["../../src/chart/area-chart.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,MAAM,cAAc,GAAG,cAAc,CAAC;AAE5C,eAAO,MAAM,SAAS,gEAErB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { defineComponent, h } from '@textui/core';
2
+ import { LineChart } from './line-chart.js';
3
+ export const AreaChart = defineComponent('AreaChart', (props) => h(LineChart, { area: true, ...props }));
@@ -0,0 +1,32 @@
1
+ import type { BoxProps, SemanticVariant } from '@textui/core';
2
+ export interface BarChartProps extends BoxProps {
3
+ data: {
4
+ label: string;
5
+ value: number;
6
+ tone?: SemanticVariant;
7
+ }[];
8
+ max?: number;
9
+ /** Cells the bars occupy, not counting labels. Horizontal only - see below. */
10
+ barWidth?: number;
11
+ showValue?: boolean;
12
+ format?(value: number): string;
13
+ orientation?: 'horizontal' | 'vertical';
14
+ /**
15
+ * How many cells across each bar is, standing up.
16
+ *
17
+ * Vertical only, and one by default - which is what it always was, and is a
18
+ * hairline rather than a bar. Two or three read as bars, and the label under
19
+ * each one grows to match, so `columnWidth: 2` gets two letters instead of
20
+ * an initial.
21
+ *
22
+ * The two axes are named separately on purpose. `barWidth` is how far a
23
+ * horizontal bar runs, which is the *value* axis; this is the thickness of a
24
+ * vertical one, which is the category axis. Lying flat they swap over, and a
25
+ * single prop meaning both would mean neither.
26
+ */
27
+ columnWidth?: number;
28
+ /** Rows tall, standing up. Vertical only. */
29
+ chartHeight?: number;
30
+ }
31
+ export declare const BarChart: (props: BarChartProps) => import("@textui/core").RenderOutput;
32
+ //# sourceMappingURL=bar-chart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../src/chart/bar-chart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI9D,MAAM,WAAW,aAAc,SAAQ,QAAQ;IAC7C,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,eAAe,CAAA;KAAE,EAAE,CAAC;IACjE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACxC;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,QAAQ,+DA2CnB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { defineComponent, h, stringWidth, useTheme } from '@textui/core';
2
+ import { TONE, VerticalBars } from './shared.js';
3
+ export const BarChart = defineComponent('BarChart', (props) => {
4
+ const theme = useTheme();
5
+ const { data, max, barWidth = 20, showValue = true, format, orientation = 'horizontal', columnWidth, chartHeight = 8, ...rest } = props;
6
+ const hi = max ?? Math.max(1, ...data.map((d) => d.value));
7
+ const labelWidth = Math.max(0, ...data.map((d) => stringWidth(d.label)));
8
+ if (orientation === 'vertical') {
9
+ return h(VerticalBars, {
10
+ data,
11
+ max: hi,
12
+ height: chartHeight,
13
+ ...(columnWidth === undefined ? {} : { columnWidth }),
14
+ ...rest,
15
+ });
16
+ }
17
+ const partials = theme.glyphs.progressPartial;
18
+ return h('box', { direction: 'column', ...rest }, ...data.map((item) => {
19
+ const exact = (item.value / hi) * barWidth;
20
+ const full = Math.floor(exact);
21
+ const rem = exact - full;
22
+ const partial = full < barWidth && rem > 0
23
+ ? (partials[Math.floor(rem * partials.length)] ?? '')
24
+ : '';
25
+ return h('box', { key: item.label, direction: 'row', gap: 1 }, h('box', { width: labelWidth }, h('text', { content: item.label, fg: 'muted' })), h('text', {
26
+ content: theme.glyphs.progressFull.repeat(full) + partial,
27
+ fg: TONE[item.tone ?? 'accent'],
28
+ }), showValue
29
+ ? h('text', { content: format ? format(item.value) : String(item.value), fg: 'muted' })
30
+ : null);
31
+ }));
32
+ });
@@ -0,0 +1,26 @@
1
+ import type { BoxProps, SemanticVariant } from '@textui/core';
2
+ export interface GaugeProps extends BoxProps {
3
+ value: number;
4
+ min?: number;
5
+ max?: number;
6
+ label?: string;
7
+ /** Bands that colour the reading by range. */
8
+ thresholds?: {
9
+ at: number;
10
+ tone: SemanticVariant;
11
+ }[];
12
+ format?(value: number): string;
13
+ gaugeWidth?: number;
14
+ /**
15
+ * Push the gauge away from the label, to the right edge of the row.
16
+ *
17
+ * The label's cell stretches, so it stays at the left and
18
+ * the track ends up hard against the right - which is what makes a column of
19
+ * these read as a table rather than as a ragged stack. Needs a row wider
20
+ * than its contents to have any effect, so the caller has to have given it a
21
+ * width or a `flex`.
22
+ */
23
+ spacer?: boolean;
24
+ }
25
+ export declare const Gauge: (props: GaugeProps) => import("@textui/core").RenderOutput;
26
+ //# sourceMappingURL=gauge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gauge.d.ts","sourceRoot":"","sources":["../../src/chart/gauge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI9D,MAAM,WAAW,UAAW,SAAQ,QAAQ;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,UAAU,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,eAAe,CAAA;KAAE,EAAE,CAAC;IACrD,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,KAAK,4DAkChB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { defineComponent, h, useTheme } from '@textui/core';
2
+ import { TONE } from './shared.js';
3
+ export const Gauge = defineComponent('Gauge', (props) => {
4
+ const theme = useTheme();
5
+ const { value, min = 0, max = 100, label, thresholds = [], format, gaugeWidth = 20, spacer, ...rest } = props;
6
+ const ratio = Math.max(0, Math.min(1, (value - min) / (max - min || 1)));
7
+ const filled = Math.round(ratio * gaugeWidth);
8
+ // The highest threshold at or below the value wins.
9
+ const tone = [...thresholds]
10
+ .sort((a, b) => b.at - a.at)
11
+ .find((t) => value >= t.at)?.tone ?? 'accent';
12
+ return h('box', { direction: 'row', gap: 1, role: 'meter', label, ...rest }, label !== undefined
13
+ // The label's own cell stretches rather than a `spacer` child going in
14
+ // beside it: a child would be free but its gap would not, and a row
15
+ // sized exactly to its contents would truncate the gauge to fit a space.
16
+ ? h('text', { content: label, fg: 'muted', ...(spacer === true ? { flex: 1 } : {}) })
17
+ : spacer === true ? h('spacer', {}) : null, h('text', {
18
+ content: theme.glyphs.progressFull.repeat(filled) +
19
+ theme.glyphs.progressEmpty.repeat(Math.max(0, gaugeWidth - filled)),
20
+ fg: TONE[tone],
21
+ }), h('text', {
22
+ content: format ? format(value) : `${Math.round(ratio * 100)}%`,
23
+ fg: TONE[tone],
24
+ bold: true,
25
+ }));
26
+ });
@@ -0,0 +1,13 @@
1
+ import type { BoxProps } from '@textui/core';
2
+ export interface HeatmapProps extends BoxProps {
3
+ /** Rows of values. All rows should be the same length. */
4
+ data: number[][];
5
+ min?: number;
6
+ max?: number;
7
+ rowLabels?: string[];
8
+ columnLabels?: string[];
9
+ /** Glyph ramp, lowest to highest. Defaults to the theme's blocks. */
10
+ ramp?: readonly string[];
11
+ }
12
+ export declare const Heatmap: (props: HeatmapProps) => import("@textui/core").RenderOutput;
13
+ //# sourceMappingURL=heatmap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heatmap.d.ts","sourceRoot":"","sources":["../../src/chart/heatmap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,WAAW,YAAa,SAAQ,QAAQ;IAC5C,0DAA0D;IAC1D,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,qEAAqE;IACrE,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED,eAAO,MAAM,OAAO,8DAiClB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { defineComponent, h, stringWidth, useTheme } from '@textui/core';
2
+ import { bounds } from './shared.js';
3
+ export const Heatmap = defineComponent('Heatmap', (props) => {
4
+ const theme = useTheme();
5
+ const { data, min, max, rowLabels, columnLabels, ramp, ...rest } = props;
6
+ const glyphs = ramp ?? theme.glyphs.blocks;
7
+ const flat = data.flat();
8
+ const [lo, hi] = bounds(flat, min, max);
9
+ const labelWidth = rowLabels ? Math.max(0, ...rowLabels.map(stringWidth)) : 0;
10
+ return h('box', { direction: 'column', ...rest }, columnLabels
11
+ ? h('box', { direction: 'row', gap: 0 }, labelWidth ? h('box', { width: labelWidth + 1 }) : null, h('text', {
12
+ content: columnLabels.map((l) => l.slice(0, 1)).join(''),
13
+ fg: 'subtle',
14
+ }))
15
+ : null, ...data.map((row, y) => h('box', { key: y, direction: 'row', gap: rowLabels ? 1 : 0 }, rowLabels
16
+ ? h('box', { width: labelWidth }, h('text', { content: rowLabels[y] ?? '', fg: 'muted' }))
17
+ : null, h('text', {
18
+ content: row
19
+ .map((v) => {
20
+ const ratio = (v - lo) / (hi - lo);
21
+ const index = Math.max(0, Math.min(glyphs.length - 1, Math.round(ratio * (glyphs.length - 1))));
22
+ return glyphs[index];
23
+ })
24
+ .join(''),
25
+ fg: 'accent',
26
+ }))));
27
+ });
@@ -0,0 +1,12 @@
1
+ import type { BoxProps, SemanticVariant } from '@textui/core';
2
+ export interface HistogramProps extends BoxProps {
3
+ values: number[];
4
+ /** Number of buckets. */
5
+ buckets?: number;
6
+ min?: number;
7
+ max?: number;
8
+ tone?: SemanticVariant;
9
+ chartHeight?: number;
10
+ }
11
+ export declare const Histogram: (props: HistogramProps) => import("@textui/core").RenderOutput;
12
+ //# sourceMappingURL=histogram.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"histogram.d.ts","sourceRoot":"","sources":["../../src/chart/histogram.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI9D,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,SAAS,gEAqBpB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { defineComponent, h } from '@textui/core';
2
+ import { VerticalBars, bounds } from './shared.js';
3
+ export const Histogram = defineComponent('Histogram', (props) => {
4
+ const { values, buckets = 12, min, max, tone = 'accent', chartHeight = 6, ...rest } = props;
5
+ const [lo, hi] = bounds(values, min, max);
6
+ const counts = new Array(buckets).fill(0);
7
+ for (const value of values) {
8
+ const ratio = (value - lo) / (hi - lo);
9
+ const index = Math.max(0, Math.min(buckets - 1, Math.floor(ratio * buckets)));
10
+ counts[index] = counts[index] + 1;
11
+ }
12
+ return h(VerticalBars, {
13
+ data: counts.map((count, i) => ({
14
+ label: String(Math.round(lo + ((hi - lo) * i) / buckets)),
15
+ value: count,
16
+ tone,
17
+ })),
18
+ max: Math.max(1, ...counts),
19
+ height: chartHeight,
20
+ ...rest,
21
+ });
22
+ });
@@ -0,0 +1,20 @@
1
+ import type { ComponentDefinition } from '@textui/core';
2
+ /**
3
+ * Charts.
4
+ *
5
+ * A terminal chart has one cell of resolution vertically and one horizontally,
6
+ * so the honest approach is to pick glyphs that subdivide a cell - eight block
7
+ * levels, four braille dots - rather than to pretend at pixel plotting. Every
8
+ * chart here also states its numbers, because a shape without a scale is
9
+ * decoration.
10
+ */
11
+ export * from './area-chart.js';
12
+ export * from './bar-chart.js';
13
+ export * from './gauge.js';
14
+ export * from './heatmap.js';
15
+ export * from './histogram.js';
16
+ export * from './line-chart.js';
17
+ export * from './sparkline.js';
18
+ export type { LineChartProps, Series } from './shared.js';
19
+ export declare const CHART_COMPONENTS: ComponentDefinition[];
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chart/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AASxD;;;;;;;;GAQG;AACH,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1D,eAAO,MAAM,gBAAgB,EAAE,mBAAmB,EAQjD,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { AreaChart } from './area-chart.js';
2
+ import { BarChart } from './bar-chart.js';
3
+ import { Gauge } from './gauge.js';
4
+ import { Heatmap } from './heatmap.js';
5
+ import { Histogram } from './histogram.js';
6
+ import { LineChart } from './line-chart.js';
7
+ import { Sparkline } from './sparkline.js';
8
+ /**
9
+ * Charts.
10
+ *
11
+ * A terminal chart has one cell of resolution vertically and one horizontally,
12
+ * so the honest approach is to pick glyphs that subdivide a cell - eight block
13
+ * levels, four braille dots - rather than to pretend at pixel plotting. Every
14
+ * chart here also states its numbers, because a shape without a scale is
15
+ * decoration.
16
+ */
17
+ export * from './area-chart.js';
18
+ export * from './bar-chart.js';
19
+ export * from './gauge.js';
20
+ export * from './heatmap.js';
21
+ export * from './histogram.js';
22
+ export * from './line-chart.js';
23
+ export * from './sparkline.js';
24
+ export const CHART_COMPONENTS = [
25
+ { component: 'Sparkline', category: 'chart', renderer: { kind: 'function', render: Sparkline }, description: 'One row of block glyphs; eight levels per cell.' },
26
+ { component: 'BarChart', category: 'chart', renderer: { kind: 'function', render: BarChart }, description: 'Labelled bars, horizontal or vertical.' },
27
+ { component: 'LineChart', category: 'chart', renderer: { kind: 'function', render: LineChart }, description: 'Braille plot at 2x4 the cell resolution.' },
28
+ { component: 'AreaChart', category: 'chart', renderer: { kind: 'function', render: AreaChart }, description: 'A line chart, filled.' },
29
+ { component: 'Histogram', category: 'chart', renderer: { kind: 'function', render: Histogram }, description: 'Bucketed distribution.' },
30
+ { component: 'Gauge', category: 'chart', renderer: { kind: 'function', render: Gauge }, role: 'meter', description: 'A reading against thresholds.' },
31
+ { component: 'Heatmap', category: 'chart', renderer: { kind: 'function', render: Heatmap }, description: 'A grid of intensities.' },
32
+ ];
@@ -0,0 +1,7 @@
1
+ import type { LineChartProps } from './shared.js';
2
+ /**
3
+ * A line chart on a braille canvas: each cell holds a 2x4 dot grid, so a
4
+ * 40x8 chart really has 80x32 plot positions.
5
+ */
6
+ export declare const LineChart: (props: LineChartProps) => import("@textui/core").RenderOutput;
7
+ //# sourceMappingURL=line-chart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../src/chart/line-chart.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD;;;GAGG;AACH,eAAO,MAAM,SAAS,gEA+EpB,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { defineComponent, fitTo, h, stringWidth, useTheme } from '@textui/core';
2
+ import { TONE, bounds, resample } from './shared.js';
3
+ /**
4
+ * A line chart on a braille canvas: each cell holds a 2x4 dot grid, so a
5
+ * 40x8 chart really has 80x32 plot positions.
6
+ */
7
+ export const LineChart = defineComponent('LineChart', (props) => {
8
+ const theme = useTheme();
9
+ const { series, min, max, chartWidth, chartHeight = 8, axis = true, area = false, format, ...rest } = props;
10
+ const all = series.flatMap((s) => s.values);
11
+ const [lo, hi] = bounds(all, min, max);
12
+ const braille = theme.glyphs.blocks.length > 0 && theme.glyphs.spinner[0] !== '|';
13
+ const draw = (surface, ctx) => {
14
+ const { width, height } = surface.rect;
15
+ if (width <= 0 || height <= 0)
16
+ return;
17
+ for (const [index, s] of series.entries()) {
18
+ const color = ctx.color(TONE[s.tone ?? (index === 0 ? 'accent' : 'secondary')]);
19
+ const points = resample(s.values, braille ? width * 2 : width);
20
+ if (braille) {
21
+ // Accumulate dots per cell, then emit one braille glyph per cell.
22
+ const cells = new Map();
23
+ for (let px = 0; px < points.length; px++) {
24
+ const value = points[px];
25
+ const ratio = (value - lo) / (hi - lo);
26
+ const py = Math.round((1 - ratio) * (height * 4 - 1));
27
+ const startY = area ? py : py;
28
+ const endY = area ? height * 4 - 1 : py;
29
+ for (let y = startY; y <= endY; y++) {
30
+ const cx = Math.floor(px / 2);
31
+ const cy = Math.floor(y / 4);
32
+ const key = `${cx},${cy}`;
33
+ cells.set(key, (cells.get(key) ?? 0) | brailleBit(px % 2, y % 4));
34
+ }
35
+ }
36
+ for (const [key, bits] of cells) {
37
+ const [cx, cy] = key.split(',').map(Number);
38
+ surface.put(cx, cy, String.fromCharCode(0x2800 + bits), { fg: color });
39
+ }
40
+ continue;
41
+ }
42
+ // No braille: fall back to block levels, one column per cell.
43
+ const blocks = theme.glyphs.blocks;
44
+ for (let x = 0; x < points.length && x < width; x++) {
45
+ const ratio = (points[x] - lo) / (hi - lo);
46
+ const y = Math.round((1 - ratio) * (height - 1));
47
+ const level = blocks[Math.max(0, Math.min(blocks.length - 1, Math.round(ratio * (blocks.length - 1))))];
48
+ surface.put(x, y, level, { fg: color });
49
+ }
50
+ }
51
+ };
52
+ const chart = h('canvas', {
53
+ draw,
54
+ flex: 1,
55
+ height: chartHeight,
56
+ ...(chartWidth !== undefined ? { width: chartWidth } : {}),
57
+ });
58
+ if (!axis)
59
+ return h('box', { direction: 'column', ...rest }, chart);
60
+ const fmt = format ?? ((v) => (Number.isInteger(v) ? String(v) : v.toFixed(1)));
61
+ const axisWidth = Math.max(stringWidth(fmt(hi)), stringWidth(fmt(lo)));
62
+ return h('box', { direction: 'column', ...rest }, h('box', { direction: 'row', gap: 1 }, h('box', { direction: 'column', width: axisWidth, height: chartHeight, justify: 'between' }, h('text', { content: fitTo(fmt(hi), axisWidth, 'right'), fg: 'subtle' }), h('text', { content: fitTo(fmt(lo), axisWidth, 'right'), fg: 'subtle' })), chart), series.some((s) => s.label)
63
+ ? h('box', { direction: 'row', gap: 2 }, ...series.map((s, i) => h('box', { key: i, direction: 'row', gap: 1 }, h('text', { content: theme.glyphs.bulletFilled, fg: TONE[s.tone ?? (i === 0 ? 'accent' : 'secondary')] }), h('text', { content: s.label ?? `series ${i + 1}`, fg: 'muted' }))))
64
+ : null);
65
+ });
66
+ function brailleBit(x, y) {
67
+ // Braille dot numbering is column-major and not contiguous; this is the map.
68
+ const MAP = [
69
+ [0x01, 0x08],
70
+ [0x02, 0x10],
71
+ [0x04, 0x20],
72
+ [0x40, 0x80],
73
+ ];
74
+ return MAP[y][x];
75
+ }
@@ -0,0 +1,34 @@
1
+ import type { BoxProps, SemanticVariant, StyleColor } from '@textui/core';
2
+ export declare const TONE: Record<SemanticVariant, StyleColor>;
3
+ export interface Series {
4
+ values: number[];
5
+ label?: string;
6
+ tone?: SemanticVariant;
7
+ }
8
+ export declare function bounds(values: number[], min?: number, max?: number): [number, number];
9
+ /** Take `width` samples, averaging when there is more data than cells. */
10
+ export declare function resample(values: number[], width: number): number[];
11
+ export declare const VerticalBars: (props: {
12
+ data: {
13
+ label: string;
14
+ value: number;
15
+ tone?: SemanticVariant;
16
+ }[];
17
+ max: number;
18
+ height: number;
19
+ /** Cells across, per bar. One is a hairline; two or three read as bars. */
20
+ columnWidth?: number;
21
+ }) => import("@textui/core").RenderOutput;
22
+ export interface LineChartProps extends BoxProps {
23
+ series: Series[];
24
+ min?: number;
25
+ max?: number;
26
+ chartWidth?: number;
27
+ chartHeight?: number;
28
+ /** Draw a y-axis with the bounds labelled. */
29
+ axis?: boolean;
30
+ /** Fill under the line. */
31
+ area?: boolean;
32
+ format?(value: number): string;
33
+ }
34
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/chart/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1E,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,eAAe,EAAE,UAAU,CAGpD,CAAC;AAEF,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAKrF;AAED,0EAA0E;AAC1E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA2BlE;AAED,eAAO,MAAM,YAAY;UACjB;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,eAAe,CAAA;KAAE,EAAE;SAC3D,MAAM;YACH,MAAM;IACd,2EAA2E;kBAC7D,MAAM;yCA0CpB,CAAC;AAEH,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,2BAA2B;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC"}
@@ -0,0 +1,78 @@
1
+ import { defineComponent, h, useTheme } from '@textui/core';
2
+ export const TONE = {
3
+ default: 'text', primary: 'primary', secondary: 'secondary', accent: 'accent',
4
+ success: 'success', warning: 'warning', danger: 'danger', info: 'info', muted: 'muted',
5
+ };
6
+ export function bounds(values, min, max) {
7
+ if (values.length === 0)
8
+ return [min ?? 0, max ?? 1];
9
+ const lo = min ?? Math.min(...values);
10
+ const hi = max ?? Math.max(...values);
11
+ return lo === hi ? [lo, lo + 1] : [lo, hi];
12
+ }
13
+ /** Take `width` samples, averaging when there is more data than cells. */
14
+ export function resample(values, width) {
15
+ if (width <= 0)
16
+ return [];
17
+ if (values.length === 0)
18
+ return new Array(width).fill(0);
19
+ if (values.length === width)
20
+ return values;
21
+ if (values.length < width) {
22
+ // Fewer points than cells: stretch across the width. Padding with the
23
+ // first value would invent a flat stretch of history that never happened,
24
+ // which on a chart reads as "nothing was going on" rather than "no data".
25
+ return Array.from({ length: width }, (_, i) => {
26
+ const position = (i * (values.length - 1)) / (width - 1 || 1);
27
+ const low = Math.floor(position);
28
+ const high = Math.min(values.length - 1, low + 1);
29
+ const t = position - low;
30
+ return values[low] * (1 - t) + values[high] * t;
31
+ });
32
+ }
33
+ const out = [];
34
+ const bucket = values.length / width;
35
+ for (let i = 0; i < width; i++) {
36
+ const start = Math.floor(i * bucket);
37
+ const end = Math.max(start + 1, Math.floor((i + 1) * bucket));
38
+ const slice = values.slice(start, end);
39
+ out.push(slice.reduce((a, b) => a + b, 0) / slice.length);
40
+ }
41
+ return out;
42
+ }
43
+ export const VerticalBars = defineComponent('VerticalBars', ({ data, max, height, columnWidth = 1, ...rest }) => {
44
+ const theme = useTheme();
45
+ const blocks = theme.glyphs.blocks;
46
+ // Each cell holds eight levels, so a column is a run of full blocks plus one
47
+ // partial - the same trick as the progress bar, turned on its side.
48
+ const columns = data.map((item) => {
49
+ const units = Math.round((item.value / max) * height * blocks.length);
50
+ const full = Math.floor(units / blocks.length);
51
+ const partialIndex = units % blocks.length;
52
+ const cells = [];
53
+ for (let row = height - 1; row >= 0; row--) {
54
+ if (row < full)
55
+ cells.push(blocks[blocks.length - 1]);
56
+ else if (row === full && partialIndex > 0)
57
+ cells.push(blocks[partialIndex - 1]);
58
+ else
59
+ cells.push(' ');
60
+ }
61
+ return { cells: cells.reverse(), item };
62
+ });
63
+ return h('box', { direction: 'column', ...rest }, ...Array.from({ length: height }, (_, row) => h('box', { key: row, direction: 'row', gap: 1 }, ...columns.map((col, i) => h('text', {
64
+ key: i,
65
+ // The glyph repeated, not a wider glyph: a column is one cell of
66
+ // vertical resolution and `columnWidth` of horizontal, so widening
67
+ // it must not change how the value is drawn.
68
+ content: col.cells[height - 1 - row].repeat(columnWidth),
69
+ fg: TONE[col.item.tone ?? 'accent'],
70
+ })))), h('box', { direction: 'row', gap: 1 }, ...data.map((item, i) =>
71
+ // As much of the label as the bar is wide, padded so the next one
72
+ // starts over its own bar rather than sliding left under a short name.
73
+ h('text', {
74
+ key: i,
75
+ content: item.label.slice(0, columnWidth).padEnd(columnWidth),
76
+ fg: 'subtle',
77
+ }))));
78
+ });
@@ -0,0 +1,15 @@
1
+ import type { BoxProps, SemanticVariant } from '@textui/core';
2
+ export interface SparklineProps extends BoxProps {
3
+ values: number[];
4
+ min?: number;
5
+ max?: number;
6
+ tone?: SemanticVariant;
7
+ /** Cells wide. Values are sampled to fit. */
8
+ chartWidth?: number;
9
+ /** Print the latest value after the line. */
10
+ showValue?: boolean;
11
+ format?(value: number): string;
12
+ }
13
+ /** One row of block glyphs: eight levels per cell. */
14
+ export declare const Sparkline: (props: SparklineProps) => import("@textui/core").RenderOutput;
15
+ //# sourceMappingURL=sparkline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparkline.d.ts","sourceRoot":"","sources":["../../src/chart/sparkline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI9D,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC;AAED,sDAAsD;AACtD,eAAO,MAAM,SAAS,gEA4BpB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { defineComponent, h, useTheme } from '@textui/core';
2
+ import { TONE, bounds, resample } from './shared.js';
3
+ /** One row of block glyphs: eight levels per cell. */
4
+ export const Sparkline = defineComponent('Sparkline', (props) => {
5
+ const theme = useTheme();
6
+ const { values, min, max, tone = 'accent', chartWidth, showValue = false, format, ...rest } = props;
7
+ const blocks = theme.glyphs.blocks;
8
+ const width = chartWidth ?? values.length;
9
+ const sampled = resample(values, width);
10
+ const [lo, hi] = bounds(sampled, min, max);
11
+ const line = sampled
12
+ .map((v) => {
13
+ const ratio = (v - lo) / (hi - lo);
14
+ const index = Math.max(0, Math.min(blocks.length - 1, Math.round(ratio * (blocks.length - 1))));
15
+ return blocks[index];
16
+ })
17
+ .join('');
18
+ const latest = values[values.length - 1];
19
+ return h('box', { direction: 'row', gap: 1, ...rest }, h('text', { content: line, fg: TONE[tone] }), showValue && latest !== undefined
20
+ ? h('text', { content: format ? format(latest) : String(latest), fg: 'muted' })
21
+ : null);
22
+ });