@zaly/tui 0.0.4

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 (228) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/assets/schemas/theme.schema.json +899 -0
  4. package/assets/themes/LICENSE-tokyonight.txt +201 -0
  5. package/assets/themes/NOTICES.md +69 -0
  6. package/assets/themes/ayu-dark.json +119 -0
  7. package/assets/themes/catppuccin-frappe.json +124 -0
  8. package/assets/themes/catppuccin-latte.json +124 -0
  9. package/assets/themes/catppuccin-macchiato.json +124 -0
  10. package/assets/themes/catppuccin-mocha.json +124 -0
  11. package/assets/themes/dracula-soft.json +119 -0
  12. package/assets/themes/dracula.json +119 -0
  13. package/assets/themes/everforest-dark.json +118 -0
  14. package/assets/themes/everforest-light.json +118 -0
  15. package/assets/themes/github-dark.json +123 -0
  16. package/assets/themes/github-light.json +123 -0
  17. package/assets/themes/gruvbox-dark-medium.json +112 -0
  18. package/assets/themes/kanagawa-dragon.json +115 -0
  19. package/assets/themes/kanagawa-wave.json +115 -0
  20. package/assets/themes/material-theme-palenight.json +114 -0
  21. package/assets/themes/min-dark.json +55 -0
  22. package/assets/themes/min-light.json +59 -0
  23. package/assets/themes/monokai.json +116 -0
  24. package/assets/themes/night-owl.json +116 -0
  25. package/assets/themes/nord.json +101 -0
  26. package/assets/themes/one-dark-pro.json +110 -0
  27. package/assets/themes/one-light.json +108 -0
  28. package/assets/themes/poimandres.json +123 -0
  29. package/assets/themes/rose-pine.json +98 -0
  30. package/assets/themes/solarized-dark.json +116 -0
  31. package/assets/themes/solarized-light.json +116 -0
  32. package/assets/themes/synthwave-84.json +100 -0
  33. package/assets/themes/tokyonight-day.json +157 -0
  34. package/assets/themes/tokyonight-moon.json +157 -0
  35. package/assets/themes/tokyonight-night.json +157 -0
  36. package/assets/themes/tokyonight-storm.json +157 -0
  37. package/assets/themes/vesper.json +103 -0
  38. package/assets/themes/vitesse-dark.json +126 -0
  39. package/assets/themes/vitesse-light.json +126 -0
  40. package/dist/ansi-Clq0ozyA.mjs +206 -0
  41. package/dist/ansi-Clq0ozyA.mjs.map +1 -0
  42. package/dist/ansi.d.mts +48 -0
  43. package/dist/ansi.d.mts.map +1 -0
  44. package/dist/ansi.mjs +2 -0
  45. package/dist/autocomplete-Dfw-yQDa.d.mts +100 -0
  46. package/dist/autocomplete-Dfw-yQDa.d.mts.map +1 -0
  47. package/dist/box-DyaByEiG.mjs +386 -0
  48. package/dist/box-DyaByEiG.mjs.map +1 -0
  49. package/dist/builder-D49ECBEf.mjs +385 -0
  50. package/dist/builder-D49ECBEf.mjs.map +1 -0
  51. package/dist/callbacks-CNjGNxVw.mjs +279 -0
  52. package/dist/callbacks-CNjGNxVw.mjs.map +1 -0
  53. package/dist/client-D6C_uczF.mjs +142 -0
  54. package/dist/client-D6C_uczF.mjs.map +1 -0
  55. package/dist/clipboard.d.mts +104 -0
  56. package/dist/clipboard.d.mts.map +1 -0
  57. package/dist/clipboard.mjs +404 -0
  58. package/dist/clipboard.mjs.map +1 -0
  59. package/dist/flex-Bguo-fUe.mjs +202 -0
  60. package/dist/flex-Bguo-fUe.mjs.map +1 -0
  61. package/dist/image-Cm5T-uw-.mjs +108 -0
  62. package/dist/image-Cm5T-uw-.mjs.map +1 -0
  63. package/dist/image.d.mts +123 -0
  64. package/dist/image.d.mts.map +1 -0
  65. package/dist/image.mjs +2 -0
  66. package/dist/index.d.mts +64 -0
  67. package/dist/index.d.mts.map +1 -0
  68. package/dist/index.mjs +222 -0
  69. package/dist/index.mjs.map +1 -0
  70. package/dist/input-B5Vy-iaa.d.mts +141 -0
  71. package/dist/input-B5Vy-iaa.d.mts.map +1 -0
  72. package/dist/inspect-D1d9t-ni.mjs +101 -0
  73. package/dist/inspect-D1d9t-ni.mjs.map +1 -0
  74. package/dist/inspect-D6FW_QUo.d.mts +67 -0
  75. package/dist/inspect-D6FW_QUo.d.mts.map +1 -0
  76. package/dist/kitty-JbCJC0iQ.mjs +673 -0
  77. package/dist/kitty-JbCJC0iQ.mjs.map +1 -0
  78. package/dist/markdown.d.mts +24 -0
  79. package/dist/markdown.d.mts.map +1 -0
  80. package/dist/markdown.mjs +2 -0
  81. package/dist/md.bun.d.mts +14 -0
  82. package/dist/md.bun.d.mts.map +1 -0
  83. package/dist/md.bun.mjs +28 -0
  84. package/dist/md.bun.mjs.map +1 -0
  85. package/dist/md.node.d.mts +14 -0
  86. package/dist/md.node.d.mts.map +1 -0
  87. package/dist/md.node.mjs +126 -0
  88. package/dist/md.node.mjs.map +1 -0
  89. package/dist/node-BZ7f6HzU.mjs +316 -0
  90. package/dist/node-BZ7f6HzU.mjs.map +1 -0
  91. package/dist/picker-D8OLb6kZ.d.mts +36 -0
  92. package/dist/picker-D8OLb6kZ.d.mts.map +1 -0
  93. package/dist/picker-ndVVt6qF.mjs +621 -0
  94. package/dist/picker-ndVVt6qF.mjs.map +1 -0
  95. package/dist/queries-DH3bj74K.d.mts +1963 -0
  96. package/dist/queries-DH3bj74K.d.mts.map +1 -0
  97. package/dist/reactive-f7NpAi69.mjs +623 -0
  98. package/dist/reactive-f7NpAi69.mjs.map +1 -0
  99. package/dist/registry-U654j61Y.mjs +356 -0
  100. package/dist/registry-U654j61Y.mjs.map +1 -0
  101. package/dist/render-DxVLqqB9.mjs +74 -0
  102. package/dist/render-DxVLqqB9.mjs.map +1 -0
  103. package/dist/renderer-CdLCkJB-.mjs +42 -0
  104. package/dist/renderer-CdLCkJB-.mjs.map +1 -0
  105. package/dist/renderer-CxL4xbkl.mjs +2644 -0
  106. package/dist/renderer-CxL4xbkl.mjs.map +1 -0
  107. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  108. package/dist/search-FvGnswRl.d.mts +49 -0
  109. package/dist/search-FvGnswRl.d.mts.map +1 -0
  110. package/dist/select-CbmAZdpt.d.mts +116 -0
  111. package/dist/select-CbmAZdpt.d.mts.map +1 -0
  112. package/dist/services/logger.d.mts +2 -0
  113. package/dist/services/logger.mjs +71 -0
  114. package/dist/services/logger.mjs.map +1 -0
  115. package/dist/services/notifier.d.mts +17 -0
  116. package/dist/services/notifier.d.mts.map +1 -0
  117. package/dist/services/notifier.mjs +71 -0
  118. package/dist/services/notifier.mjs.map +1 -0
  119. package/dist/services/picker.d.mts +36 -0
  120. package/dist/services/picker.d.mts.map +1 -0
  121. package/dist/services/picker.mjs +137 -0
  122. package/dist/services/picker.mjs.map +1 -0
  123. package/dist/services/prompt.d.mts +30 -0
  124. package/dist/services/prompt.d.mts.map +1 -0
  125. package/dist/services/prompt.mjs +83 -0
  126. package/dist/services/prompt.mjs.map +1 -0
  127. package/dist/shiki-BrjVUkeh.mjs +423 -0
  128. package/dist/shiki-BrjVUkeh.mjs.map +1 -0
  129. package/dist/size-D8JogYLy.mjs +34 -0
  130. package/dist/size-D8JogYLy.mjs.map +1 -0
  131. package/dist/style.d.mts +10 -0
  132. package/dist/style.d.mts.map +1 -0
  133. package/dist/style.mjs +4 -0
  134. package/dist/text.d.mts +33 -0
  135. package/dist/text.d.mts.map +1 -0
  136. package/dist/text.mjs +111 -0
  137. package/dist/text.mjs.map +1 -0
  138. package/dist/theme.config-CU3B50HN.mjs +832 -0
  139. package/dist/theme.config-CU3B50HN.mjs.map +1 -0
  140. package/dist/themes.d.mts +113 -0
  141. package/dist/themes.d.mts.map +1 -0
  142. package/dist/themes.mjs +2 -0
  143. package/dist/tree-C28QOVIK.d.mts +23 -0
  144. package/dist/tree-C28QOVIK.d.mts.map +1 -0
  145. package/dist/types-B9Eh7k2v.d.mts +212 -0
  146. package/dist/types-B9Eh7k2v.d.mts.map +1 -0
  147. package/dist/types-D3jk1rtk.d.mts +140 -0
  148. package/dist/types-D3jk1rtk.d.mts.map +1 -0
  149. package/dist/utils-3M4D_AXZ.mjs +40 -0
  150. package/dist/utils-3M4D_AXZ.mjs.map +1 -0
  151. package/dist/widgets/autocomplete.d.mts +2 -0
  152. package/dist/widgets/autocomplete.mjs +165 -0
  153. package/dist/widgets/autocomplete.mjs.map +1 -0
  154. package/dist/widgets/box.d.mts +2 -0
  155. package/dist/widgets/box.mjs +2 -0
  156. package/dist/widgets/code.d.mts +48 -0
  157. package/dist/widgets/code.d.mts.map +1 -0
  158. package/dist/widgets/code.mjs +59 -0
  159. package/dist/widgets/code.mjs.map +1 -0
  160. package/dist/widgets/completions/actions.d.mts +41 -0
  161. package/dist/widgets/completions/actions.d.mts.map +1 -0
  162. package/dist/widgets/completions/actions.mjs +48 -0
  163. package/dist/widgets/completions/actions.mjs.map +1 -0
  164. package/dist/widgets/completions/files.d.mts +29 -0
  165. package/dist/widgets/completions/files.d.mts.map +1 -0
  166. package/dist/widgets/completions/files.mjs +42 -0
  167. package/dist/widgets/completions/files.mjs.map +1 -0
  168. package/dist/widgets/completions/github.d.mts +64 -0
  169. package/dist/widgets/completions/github.d.mts.map +1 -0
  170. package/dist/widgets/completions/github.mjs +137 -0
  171. package/dist/widgets/completions/github.mjs.map +1 -0
  172. package/dist/widgets/completions/index.d.mts +4 -0
  173. package/dist/widgets/completions/index.mjs +4 -0
  174. package/dist/widgets/diff.d.mts +57 -0
  175. package/dist/widgets/diff.d.mts.map +1 -0
  176. package/dist/widgets/diff.mjs +199 -0
  177. package/dist/widgets/diff.mjs.map +1 -0
  178. package/dist/widgets/divider.d.mts +11 -0
  179. package/dist/widgets/divider.d.mts.map +1 -0
  180. package/dist/widgets/divider.mjs +9 -0
  181. package/dist/widgets/divider.mjs.map +1 -0
  182. package/dist/widgets/image.d.mts +37 -0
  183. package/dist/widgets/image.d.mts.map +1 -0
  184. package/dist/widgets/image.mjs +77 -0
  185. package/dist/widgets/image.mjs.map +1 -0
  186. package/dist/widgets/input.d.mts +2 -0
  187. package/dist/widgets/input.mjs +497 -0
  188. package/dist/widgets/input.mjs.map +1 -0
  189. package/dist/widgets/log.d.mts +2 -0
  190. package/dist/widgets/log.mjs +130 -0
  191. package/dist/widgets/log.mjs.map +1 -0
  192. package/dist/widgets/markdown.d.mts +45 -0
  193. package/dist/widgets/markdown.d.mts.map +1 -0
  194. package/dist/widgets/markdown.mjs +124 -0
  195. package/dist/widgets/markdown.mjs.map +1 -0
  196. package/dist/widgets/overlay.d.mts +2 -0
  197. package/dist/widgets/overlay.mjs +18 -0
  198. package/dist/widgets/overlay.mjs.map +1 -0
  199. package/dist/widgets/picker.d.mts +2 -0
  200. package/dist/widgets/picker.mjs +2 -0
  201. package/dist/widgets/progress.d.mts +48 -0
  202. package/dist/widgets/progress.d.mts.map +1 -0
  203. package/dist/widgets/progress.mjs +48 -0
  204. package/dist/widgets/progress.mjs.map +1 -0
  205. package/dist/widgets/select.d.mts +2 -0
  206. package/dist/widgets/select.mjs +195 -0
  207. package/dist/widgets/select.mjs.map +1 -0
  208. package/dist/widgets/show.d.mts +55 -0
  209. package/dist/widgets/show.d.mts.map +1 -0
  210. package/dist/widgets/show.mjs +85 -0
  211. package/dist/widgets/show.mjs.map +1 -0
  212. package/dist/widgets/spinner.d.mts +65 -0
  213. package/dist/widgets/spinner.d.mts.map +1 -0
  214. package/dist/widgets/spinner.mjs +147 -0
  215. package/dist/widgets/spinner.mjs.map +1 -0
  216. package/dist/widgets/text.d.mts +2 -0
  217. package/dist/widgets/text.mjs +32 -0
  218. package/dist/widgets/text.mjs.map +1 -0
  219. package/dist/widgets/tree.d.mts +2 -0
  220. package/dist/widgets/tree.mjs +73 -0
  221. package/dist/widgets/tree.mjs.map +1 -0
  222. package/dist/widgets/widget.d.mts +49 -0
  223. package/dist/widgets/widget.d.mts.map +1 -0
  224. package/dist/widgets/widget.mjs +40 -0
  225. package/dist/widgets/widget.mjs.map +1 -0
  226. package/dist/worker-DjHuQSbY.mjs +27 -0
  227. package/dist/worker-DjHuQSbY.mjs.map +1 -0
  228. package/package.json +117 -0
@@ -0,0 +1,2 @@
1
+ import { i as tree, n as TreeNode, r as TreeProps, t as TreeItem } from "../tree-C28QOVIK.mjs";
2
+ export { TreeItem, TreeNode, TreeProps, tree };
@@ -0,0 +1,73 @@
1
+ import { S as unwrap, h as memo } from "../reactive-f7NpAi69.mjs";
2
+ import { widget } from "./widget.mjs";
3
+ import { select } from "./select.mjs";
4
+ import { stringWidth } from "@zaly/shared/ansi";
5
+ //#region src/widgets/tree.ts
6
+ const icons = {
7
+ last: "╰─",
8
+ middle: "├─",
9
+ vertical: "│ "
10
+ };
11
+ var Tree = class {
12
+ root;
13
+ nodes = /* @__PURE__ */ new Map();
14
+ items = [];
15
+ constructor(root) {
16
+ this.root = root;
17
+ this.#build(root, void 0, true);
18
+ }
19
+ #build(item, parent, last) {
20
+ this.nodes.set(item, {
21
+ last,
22
+ parent
23
+ });
24
+ this.items.push(item);
25
+ const children = item.children ?? [];
26
+ for (let c = 0; c < children.length; c++) {
27
+ const child = children[c];
28
+ this.#build(child, item, c === children.length - 1);
29
+ }
30
+ }
31
+ node(item) {
32
+ return this.nodes.get(item);
33
+ }
34
+ };
35
+ const tree = widget((props) => {
36
+ const builder = memo(() => new Tree(unwrap(props.tree)));
37
+ const items = memo(() => props.root === true ? builder().items : builder().items.slice(1));
38
+ const activeFn = typeof props.active === "function" ? props.active : (i) => i === props.active;
39
+ const active = props.active ? items().findIndex((i) => activeFn(i)) : -1;
40
+ const ret = select({
41
+ ...props,
42
+ active: active === -1 ? 0 : active,
43
+ items
44
+ });
45
+ ret.extendRenderer((prev) => (item, ctx) => {
46
+ const t = builder();
47
+ const path = [];
48
+ const s = ctx.style;
49
+ const itemNode = t.node(item);
50
+ let n = t.node(item);
51
+ while (n?.parent) {
52
+ if (props.root !== true && n.parent === props.tree) break;
53
+ let icon = "";
54
+ if (n !== itemNode) icon = n.last ? " " : icons.vertical;
55
+ else icon = n.last ? icons.last : icons.middle;
56
+ path.unshift(icon);
57
+ n = t.node(n.parent);
58
+ }
59
+ const prefix = path.join("");
60
+ const prefixWidth = stringWidth(prefix);
61
+ const text = prev(item, {
62
+ ...ctx,
63
+ prefixWidth,
64
+ width: ctx.width - prefixWidth
65
+ }).replace(/\s/g, " ");
66
+ return `${s.gutter(prefix)}${text}`;
67
+ });
68
+ return Object.assign(ret, { items });
69
+ });
70
+ //#endregion
71
+ export { tree };
72
+
73
+ //# sourceMappingURL=tree.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.mjs","names":["#build"],"sources":["../../src/widgets/tree.ts"],"sourcesContent":["import type { Reactive } from \"../core/reactive.ts\"\nimport type { Option, Select, SelectState } from \"./select.ts\"\n\nimport { stringWidth } from \"@zaly/shared/ansi\"\nimport { memo, unwrap } from \"../core/reactive.ts\"\nimport { select } from \"./select.ts\"\nimport { widget } from \"./widget.ts\"\n\nexport type TreeItem<T extends Option = Option> = T & {\n children?: TreeItem<T>[]\n icon?: string\n}\n\nexport type TreeProps<T extends TreeItem = TreeItem> = Omit<SelectState<T>, \"items\" | \"active\"> & {\n tree: Reactive<T>\n /** If true, the root node will be rendered and selectable. Defaults to false. */\n root?: boolean\n active?: T | ((item: T) => boolean)\n}\n\nconst icons = {\n // last: \"└─\",\n last: \"╰─\",\n middle: \"├─\",\n vertical: \"│ \",\n}\n\nexport type TreeNode<T extends TreeItem> = {\n last?: boolean\n parent?: T\n}\n\nclass Tree<T extends TreeItem> {\n nodes = new Map<T, TreeNode<T>>()\n items: T[] = []\n\n constructor(public root: T) {\n this.#build(root, undefined, true)\n }\n\n #build(item: T, parent?: T, last?: boolean) {\n this.nodes.set(item, { last, parent })\n this.items.push(item)\n const children = item.children ?? []\n for (let c = 0; c < children.length; c++) {\n const child = children[c] as T\n this.#build(child, item, c === children.length - 1)\n }\n }\n\n node(item: T) {\n return this.nodes.get(item)\n }\n}\n\nexport const tree = widget(\n <T extends TreeItem>(props: TreeProps<T>): Select<T> & { items: Reactive<T[]> } => {\n const builder = memo(() => new Tree(unwrap(props.tree)))\n const items = memo(() => (props.root === true ? builder().items : builder().items.slice(1)))\n\n const activeFn =\n typeof props.active === \"function\" ? props.active : (i: T) => i === props.active\n const active = props.active ? items().findIndex((i) => activeFn(i)) : -1\n\n const ret = select({ ...props, active: active === -1 ? 0 : active, items })\n\n ret.extendRenderer((prev) => (item, ctx) => {\n const t = builder()\n const path: string[] = []\n const s = ctx.style\n const itemNode = t.node(item)\n let n = t.node(item)\n while (n?.parent) {\n if (props.root !== true && n.parent === props.tree) break\n let icon = \"\"\n if (n !== itemNode) icon = n.last ? \" \" : icons.vertical\n else icon = n.last ? icons.last : icons.middle\n path.unshift(icon)\n n = t.node(n.parent)\n }\n const prefix = path.join(\"\")\n const prefixWidth = stringWidth(prefix)\n const text = prev(item, { ...ctx, prefixWidth, width: ctx.width - prefixWidth }).replace(\n /\\s/g,\n \" \"\n )\n return `${s.gutter(prefix)}${text}`\n })\n\n return Object.assign(ret, { items })\n }\n)\n"],"mappings":";;;;;AAoBA,MAAM,QAAQ;CAEZ,MAAM;CACN,QAAQ;CACR,UAAU;AACZ;AAOA,IAAM,OAAN,MAA+B;CAIV;CAHnB,wBAAQ,IAAI,IAAoB;CAChC,QAAa,CAAC;CAEd,YAAY,MAAgB;EAAT,KAAA,OAAA;EACjB,KAAKA,OAAO,MAAM,KAAA,GAAW,IAAI;CACnC;CAEA,OAAO,MAAS,QAAY,MAAgB;EAC1C,KAAK,MAAM,IAAI,MAAM;GAAE;GAAM;EAAO,CAAC;EACrC,KAAK,MAAM,KAAK,IAAI;EACpB,MAAM,WAAW,KAAK,YAAY,CAAC;EACnC,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;GACxC,MAAM,QAAQ,SAAS;GACvB,KAAKA,OAAO,OAAO,MAAM,MAAM,SAAS,SAAS,CAAC;EACpD;CACF;CAEA,KAAK,MAAS;EACZ,OAAO,KAAK,MAAM,IAAI,IAAI;CAC5B;AACF;AAEA,MAAa,OAAO,QACG,UAA8D;CACjF,MAAM,UAAU,WAAW,IAAI,KAAK,OAAO,MAAM,IAAI,CAAC,CAAC;CACvD,MAAM,QAAQ,WAAY,MAAM,SAAS,OAAO,QAAQ,CAAC,CAAC,QAAQ,QAAQ,CAAC,CAAC,MAAM,MAAM,CAAC,CAAE;CAE3F,MAAM,WACJ,OAAO,MAAM,WAAW,aAAa,MAAM,UAAU,MAAS,MAAM,MAAM;CAC5E,MAAM,SAAS,MAAM,SAAS,MAAM,CAAC,CAAC,WAAW,MAAM,SAAS,CAAC,CAAC,IAAI;CAEtE,MAAM,MAAM,OAAO;EAAE,GAAG;EAAO,QAAQ,WAAW,KAAK,IAAI;EAAQ;CAAM,CAAC;CAE1E,IAAI,gBAAgB,UAAU,MAAM,QAAQ;EAC1C,MAAM,IAAI,QAAQ;EAClB,MAAM,OAAiB,CAAC;EACxB,MAAM,IAAI,IAAI;EACd,MAAM,WAAW,EAAE,KAAK,IAAI;EAC5B,IAAI,IAAI,EAAE,KAAK,IAAI;EACnB,OAAO,GAAG,QAAQ;GAChB,IAAI,MAAM,SAAS,QAAQ,EAAE,WAAW,MAAM,MAAM;GACpD,IAAI,OAAO;GACX,IAAI,MAAM,UAAU,OAAO,EAAE,OAAO,OAAO,MAAM;QAC5C,OAAO,EAAE,OAAO,MAAM,OAAO,MAAM;GACxC,KAAK,QAAQ,IAAI;GACjB,IAAI,EAAE,KAAK,EAAE,MAAM;EACrB;EACA,MAAM,SAAS,KAAK,KAAK,EAAE;EAC3B,MAAM,cAAc,YAAY,MAAM;EACtC,MAAM,OAAO,KAAK,MAAM;GAAE,GAAG;GAAK;GAAa,OAAO,IAAI,QAAQ;EAAY,CAAC,CAAC,CAAC,QAC/E,OACA,GACF;EACA,OAAO,GAAG,EAAE,OAAO,MAAM,IAAI;CAC/B,CAAC;CAED,OAAO,OAAO,OAAO,KAAK,EAAE,MAAM,CAAC;AACrC,CACF"}
@@ -0,0 +1,49 @@
1
+ import { p as Node } from "../queries-DH3bj74K.mjs";
2
+ //#region src/widgets/widget.d.ts
3
+ type Props = Record<string, unknown>;
4
+ /**
5
+ * A widget factory: takes some args, returns a `Node`.
6
+ *
7
+ * The default `A = never[]` makes the *bare* `Widget` the universal
8
+ * "any widget" type — the `(...args: never[]) => Node` idiom. Every
9
+ * concrete factory (zero-arg, `state + ...children`, single-props) is
10
+ * assignable to it, so it works both as the `widget()` constraint and
11
+ * as a stored value type (`details?: Widget`, invoked zero-arg). Supply
12
+ * `A` explicitly for a precise signature: `Widget<[State<LogState>]>`.
13
+ */
14
+ type Widget<A extends unknown[] = never[], N extends Node = Node> = (...args: A) => N;
15
+ /**
16
+ * Type helper for declaring widgets — runtime identity, just `return fn`.
17
+ *
18
+ * Three things it earns:
19
+ * 1. Inference at the declaration site: TS infers `S` from the function
20
+ * parameter and enforces it on every call site.
21
+ * 2. A consistent grep target: every component reads as
22
+ * `export const foo = widget((props) => …)`.
23
+ * 3. A future seam for instrumentation, lifecycle wrappers, devtools.
24
+ *
25
+ * The factory body runs **once** at construction. Reactive content lives
26
+ * in leaf thunks (`text(({ style }) => …)`), not by re-running the body
27
+ * — this is the Solid model, not React's. `ctx` is therefore unavailable
28
+ * inside the factory; reach for it inside leaf thunks where it belongs.
29
+ *
30
+ * ```ts
31
+ * const status = widget((props: { level: "ok" | "warn"; msg: string }) =>
32
+ * text(({ style }) => `${style.bold[props.level]("●")} ${style.dim(props.msg)}`),
33
+ * )
34
+ *
35
+ * status({ level: "ok", msg: "all systems nominal" })
36
+ * ```
37
+ */
38
+ /**
39
+ * Call-site args derived from `S`:
40
+ * - If `S` declares `children`, `children` is injected from rest args;
41
+ * state at the call site has `children` omitted, then `...children`.
42
+ * - Otherwise, no rest is allowed.
43
+ * - Either way, the state arg is optional when every field of the
44
+ * resolved state is optional (so bare `widget()` works).
45
+ */
46
+ declare function widget<T extends Widget>(fn: T): T;
47
+ //#endregion
48
+ export { Props, Widget, widget };
49
+ //# sourceMappingURL=widget.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.d.mts","names":[],"sources":["../../src/widgets/widget.ts"],"mappings":";;KAIY,QAAQ;;;;;;;;;;;KAYR,OAAO,+BAA+B,UAAU,OAAO,YAAY,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkC3E,OAAO,UAAU,QAAQ,IAAI,IAAI"}
@@ -0,0 +1,40 @@
1
+ import { o as createNode } from "../reactive-f7NpAi69.mjs";
2
+ //#region src/widgets/widget.ts
3
+ /**
4
+ * Type helper for declaring widgets — runtime identity, just `return fn`.
5
+ *
6
+ * Three things it earns:
7
+ * 1. Inference at the declaration site: TS infers `S` from the function
8
+ * parameter and enforces it on every call site.
9
+ * 2. A consistent grep target: every component reads as
10
+ * `export const foo = widget((props) => …)`.
11
+ * 3. A future seam for instrumentation, lifecycle wrappers, devtools.
12
+ *
13
+ * The factory body runs **once** at construction. Reactive content lives
14
+ * in leaf thunks (`text(({ style }) => …)`), not by re-running the body
15
+ * — this is the Solid model, not React's. `ctx` is therefore unavailable
16
+ * inside the factory; reach for it inside leaf thunks where it belongs.
17
+ *
18
+ * ```ts
19
+ * const status = widget((props: { level: "ok" | "warn"; msg: string }) =>
20
+ * text(({ style }) => `${style.bold[props.level]("●")} ${style.dim(props.msg)}`),
21
+ * )
22
+ *
23
+ * status({ level: "ok", msg: "all systems nominal" })
24
+ * ```
25
+ */
26
+ /**
27
+ * Call-site args derived from `S`:
28
+ * - If `S` declares `children`, `children` is injected from rest args;
29
+ * state at the call site has `children` omitted, then `...children`.
30
+ * - Otherwise, no rest is allowed.
31
+ * - Either way, the state arg is optional when every field of the
32
+ * resolved state is optional (so bare `widget()` works).
33
+ */
34
+ function widget(fn) {
35
+ return ((...args) => createNode(() => fn(...args)));
36
+ }
37
+ //#endregion
38
+ export { widget };
39
+
40
+ //# sourceMappingURL=widget.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.mjs","names":[],"sources":["../../src/widgets/widget.ts"],"sourcesContent":["import type { Node } from \"../core/node.ts\"\n\nimport { createNode } from \"../core/reactive.ts\"\n\nexport type Props = Record<string, unknown>\n\n/**\n * A widget factory: takes some args, returns a `Node`.\n *\n * The default `A = never[]` makes the *bare* `Widget` the universal\n * \"any widget\" type — the `(...args: never[]) => Node` idiom. Every\n * concrete factory (zero-arg, `state + ...children`, single-props) is\n * assignable to it, so it works both as the `widget()` constraint and\n * as a stored value type (`details?: Widget`, invoked zero-arg). Supply\n * `A` explicitly for a precise signature: `Widget<[State<LogState>]>`.\n */\nexport type Widget<A extends unknown[] = never[], N extends Node = Node> = (...args: A) => N\n\n/**\n * Type helper for declaring widgets — runtime identity, just `return fn`.\n *\n * Three things it earns:\n * 1. Inference at the declaration site: TS infers `S` from the function\n * parameter and enforces it on every call site.\n * 2. A consistent grep target: every component reads as\n * `export const foo = widget((props) => …)`.\n * 3. A future seam for instrumentation, lifecycle wrappers, devtools.\n *\n * The factory body runs **once** at construction. Reactive content lives\n * in leaf thunks (`text(({ style }) => …)`), not by re-running the body\n * — this is the Solid model, not React's. `ctx` is therefore unavailable\n * inside the factory; reach for it inside leaf thunks where it belongs.\n *\n * ```ts\n * const status = widget((props: { level: \"ok\" | \"warn\"; msg: string }) =>\n * text(({ style }) => `${style.bold[props.level](\"●\")} ${style.dim(props.msg)}`),\n * )\n *\n * status({ level: \"ok\", msg: \"all systems nominal\" })\n * ```\n */\n/**\n * Call-site args derived from `S`:\n * - If `S` declares `children`, `children` is injected from rest args;\n * state at the call site has `children` omitted, then `...children`.\n * - Otherwise, no rest is allowed.\n * - Either way, the state arg is optional when every field of the\n * resolved state is optional (so bare `widget()` works).\n */\n\nexport function widget<T extends Widget>(fn: T): T {\n return ((...args: Parameters<T>) => createNode(() => fn(...args))) as T\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,OAAyB,IAAU;CACjD,SAAS,GAAG,SAAwB,iBAAiB,GAAG,GAAG,IAAI,CAAC;AAClE"}
@@ -0,0 +1,27 @@
1
+ //#region src/shiki/worker.ts
2
+ async function createWorker(scriptURL) {
3
+ if (typeof globalThis.Worker === "function") {
4
+ const w = new Worker(scriptURL, { type: "module" });
5
+ w.unref?.();
6
+ return {
7
+ on: (event, handler) => {
8
+ if (event === "error") w.addEventListener(event, (e) => void handler(e.error ?? new Error(e.message)));
9
+ else w.addEventListener(event, (e) => void handler(e.data));
10
+ },
11
+ postMessage: (message) => w.postMessage(message),
12
+ terminate: () => w.terminate()
13
+ };
14
+ }
15
+ const { Worker: NodeWorker } = await import("node:worker_threads");
16
+ const worker = new NodeWorker(scriptURL);
17
+ worker.unref();
18
+ return {
19
+ on: (event, handler) => worker.on(event, (e) => void handler(e)),
20
+ postMessage: (message) => worker.postMessage(message),
21
+ terminate: () => void worker.terminate()
22
+ };
23
+ }
24
+ //#endregion
25
+ export { createWorker };
26
+
27
+ //# sourceMappingURL=worker-DjHuQSbY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-DjHuQSbY.mjs","names":[],"sources":["../src/shiki/worker.ts"],"sourcesContent":["// oxlint-disable typescript/method-signature-style unicorn/require-post-message-target-origin\nimport type { MaybePromise } from \"@zaly/shared\"\n\nexport const workerHost = {\n onMessage: (handler: (message: any) => MaybePromise): void => {\n if (typeof globalThis.addEventListener === \"function\") {\n globalThis.addEventListener(\"message\", (event: MessageEvent) => void handler(event.data))\n return\n }\n void import(\"node:worker_threads\").then(({ parentPort }) => {\n parentPort?.on(\"message\", (message) => void handler(message))\n })\n },\n\n postMessage: (message: unknown): void => {\n if (typeof globalThis.postMessage === \"function\") {\n // oxlint-disable-next-line unicorn/require-post-message-target-origin\n globalThis.postMessage(message)\n return\n }\n void import(\"node:worker_threads\").then(({ parentPort }) => {\n // oxlint-disable-next-line unicorn/require-post-message-target-origin\n parentPort?.postMessage(message)\n })\n },\n}\n\nexport type WorkerInstance<In = unknown, Out = unknown> = {\n on(event: \"message\", handler: (message: Out) => MaybePromise): void\n on(event: \"error\", handler: (error: Error) => MaybePromise): void\n postMessage(message: In): void\n terminate(): void\n}\n\nexport async function createWorker<In = unknown, Out = unknown>(\n scriptURL: string | URL\n): Promise<WorkerInstance<In, Out>> {\n if (typeof globalThis.Worker === \"function\") {\n const w = new Worker(scriptURL, { type: \"module\" })\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n w.unref?.()\n return {\n on: (event, handler) => {\n if (event === \"error\")\n w.addEventListener(event, (e) => void handler(e.error ?? new Error(e.message)))\n else w.addEventListener(event, (e) => void handler(e.data))\n },\n postMessage: (message) => w.postMessage(message),\n terminate: () => w.terminate(),\n }\n }\n const { Worker: NodeWorker } = await import(\"node:worker_threads\")\n const worker = new NodeWorker(scriptURL)\n worker.unref()\n return {\n on: (event, handler) => worker.on(event, (e) => void handler(e)),\n postMessage: (message) => worker.postMessage(message),\n terminate: () => void worker.terminate(),\n }\n}\n"],"mappings":";AAkCA,eAAsB,aACpB,WACkC;CAClC,IAAI,OAAO,WAAW,WAAW,YAAY;EAC3C,MAAM,IAAI,IAAI,OAAO,WAAW,EAAE,MAAM,SAAS,CAAC;EAElD,EAAE,QAAQ;EACV,OAAO;GACL,KAAK,OAAO,YAAY;IACtB,IAAI,UAAU,SACZ,EAAE,iBAAiB,QAAQ,MAAM,KAAK,QAAQ,EAAE,SAAS,IAAI,MAAM,EAAE,OAAO,CAAC,CAAC;SAC3E,EAAE,iBAAiB,QAAQ,MAAM,KAAK,QAAQ,EAAE,IAAI,CAAC;GAC5D;GACA,cAAc,YAAY,EAAE,YAAY,OAAO;GAC/C,iBAAiB,EAAE,UAAU;EAC/B;CACF;CACA,MAAM,EAAE,QAAQ,eAAe,MAAM,OAAO;CAC5C,MAAM,SAAS,IAAI,WAAW,SAAS;CACvC,OAAO,MAAM;CACb,OAAO;EACL,KAAK,OAAO,YAAY,OAAO,GAAG,QAAQ,MAAM,KAAK,QAAQ,CAAC,CAAC;EAC/D,cAAc,YAAY,OAAO,YAAY,OAAO;EACpD,iBAAiB,KAAK,OAAO,UAAU;CACzC;AACF"}
package/package.json ADDED
@@ -0,0 +1,117 @@
1
+ {
2
+ "name": "@zaly/tui",
3
+ "version": "0.0.4",
4
+ "description": "Terminal UI framework used by zaly.",
5
+ "keywords": [
6
+ "ansi",
7
+ "cli",
8
+ "terminal",
9
+ "tui",
10
+ "widgets"
11
+ ],
12
+ "homepage": "https://github.com/folke/zaly/tree/main/packages/tui#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/folke/zaly/issues"
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/folke/zaly.git",
20
+ "directory": "packages/tui"
21
+ },
22
+ "files": [
23
+ "dist/**/*",
24
+ "assets/**/*"
25
+ ],
26
+ "type": "module",
27
+ "imports": {
28
+ "#ansi": {
29
+ "bun": "./dist/ansi.bun.mjs",
30
+ "default": "./dist/ansi.node.mjs"
31
+ },
32
+ "#md": {
33
+ "bun": "./dist/md.bun.mjs",
34
+ "default": "./dist/md.node.mjs"
35
+ }
36
+ },
37
+ "exports": {
38
+ ".": "./dist/index.mjs",
39
+ "./ansi": "./dist/ansi.mjs",
40
+ "./clipboard": "./dist/clipboard.mjs",
41
+ "./image": "./dist/image.mjs",
42
+ "./markdown": "./dist/markdown.mjs",
43
+ "./services/logger": "./dist/services/logger.mjs",
44
+ "./services/notifier": "./dist/services/notifier.mjs",
45
+ "./services/picker": "./dist/services/picker.mjs",
46
+ "./services/prompt": "./dist/services/prompt.mjs",
47
+ "./style": "./dist/style.mjs",
48
+ "./text": "./dist/text.mjs",
49
+ "./themes": "./dist/themes.mjs",
50
+ "./widgets/autocomplete": "./dist/widgets/autocomplete.mjs",
51
+ "./widgets/box": "./dist/widgets/box.mjs",
52
+ "./widgets/code": "./dist/widgets/code.mjs",
53
+ "./widgets/completions": "./dist/widgets/completions/index.mjs",
54
+ "./widgets/completions/actions": "./dist/widgets/completions/actions.mjs",
55
+ "./widgets/completions/files": "./dist/widgets/completions/files.mjs",
56
+ "./widgets/completions/github": "./dist/widgets/completions/github.mjs",
57
+ "./widgets/diff": "./dist/widgets/diff.mjs",
58
+ "./widgets/divider": "./dist/widgets/divider.mjs",
59
+ "./widgets/image": "./dist/widgets/image.mjs",
60
+ "./widgets/input": "./dist/widgets/input.mjs",
61
+ "./widgets/log": "./dist/widgets/log.mjs",
62
+ "./widgets/markdown": "./dist/widgets/markdown.mjs",
63
+ "./widgets/overlay": "./dist/widgets/overlay.mjs",
64
+ "./widgets/picker": "./dist/widgets/picker.mjs",
65
+ "./widgets/progress": "./dist/widgets/progress.mjs",
66
+ "./widgets/select": "./dist/widgets/select.mjs",
67
+ "./widgets/show": "./dist/widgets/show.mjs",
68
+ "./widgets/spinner": "./dist/widgets/spinner.mjs",
69
+ "./widgets/text": "./dist/widgets/text.mjs",
70
+ "./widgets/tree": "./dist/widgets/tree.mjs",
71
+ "./widgets/widget": "./dist/widgets/widget.mjs",
72
+ "./package.json": "./package.json"
73
+ },
74
+ "publishConfig": {
75
+ "access": "public"
76
+ },
77
+ "dependencies": {
78
+ "diff": "^9.0.0",
79
+ "marked": "^18.0.6",
80
+ "pathe": "^2.0.3",
81
+ "shiki": "^4.3.1",
82
+ "@zaly/shared": "0.0.3"
83
+ },
84
+ "devDependencies": {
85
+ "@typia/transform": "^12.1.1",
86
+ "ghostty-web": "^0.4.0",
87
+ "mitata": "^1.0.34",
88
+ "slice-ansi": "^9.0.0",
89
+ "string-width": "^8.2.2",
90
+ "typia": "^13.0.2",
91
+ "wrap-ansi": "^10.0.0"
92
+ },
93
+ "optionalDependencies": {
94
+ "sharp": "^0.35.3"
95
+ },
96
+ "engines": {
97
+ "bun": ">=1.2",
98
+ "node": ">=24"
99
+ },
100
+ "inlinedDependencies": {
101
+ "typia": "13.0.2"
102
+ },
103
+ "scripts": {
104
+ "bench": "z bench",
105
+ "build": "z build",
106
+ "build:themes-1-shiki": "bun scripts/themes-shiki.ts",
107
+ "build:themes-2-nvim": "exit 0; nvim -l scripts/themes-nvim.lua",
108
+ "build:themes-3-tokyonight": "bun scripts/themes-tokyonight.ts",
109
+ "build:themes-4-builtin": "bun scripts/themes-builtin.ts && oxfmt src/themes/builtin.ts",
110
+ "docs:api": "typedoc",
111
+ "docs:build": "bun run docs:api && vitepress build docs",
112
+ "docs:dev": "bun run docs:api && vitepress dev docs",
113
+ "docs:preview": "vitepress preview docs",
114
+ "lint": "z lint",
115
+ "test": "z test"
116
+ }
117
+ }