@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,386 @@
1
+ import { S as unwrap } from "./reactive-f7NpAi69.mjs";
2
+ import { t as Node } from "./node-BZ7f6HzU.mjs";
3
+ import { n as resolveSize, t as clamp } from "./size-D8JogYLy.mjs";
4
+ import { a as zipRow, i as stackColumn, n as isFixedWidth, r as padRow, t as allocateRow } from "./flex-Bguo-fUe.mjs";
5
+ import { textContent } from "./widgets/text.mjs";
6
+ import { sliceAnsi, stringWidth } from "@zaly/shared/ansi";
7
+ //#region src/layout/border.ts
8
+ /** @internal */
9
+ const borders = {
10
+ double: {
11
+ bl: "╚",
12
+ br: "╝",
13
+ h: "═",
14
+ tl: "╔",
15
+ tr: "╗",
16
+ v: "║"
17
+ },
18
+ rounded: {
19
+ bl: "╰",
20
+ br: "╯",
21
+ h: "─",
22
+ tl: "╭",
23
+ tr: "╮",
24
+ v: "│"
25
+ },
26
+ single: {
27
+ bl: "└",
28
+ br: "┘",
29
+ h: "─",
30
+ tl: "┌",
31
+ tr: "┐",
32
+ v: "│"
33
+ }
34
+ };
35
+ /** Resolve the `border` style value to a concrete BorderChars, or undefined.
36
+ *
37
+ * @internal*/
38
+ function resolveBorder(spec) {
39
+ if (spec === void 0 || spec === false) return void 0;
40
+ if (spec === true) return borders.single;
41
+ if (typeof spec === "string") return borders[spec];
42
+ return spec;
43
+ }
44
+ /** Pass-through wrapper used when no style is supplied. */
45
+ const identity = (s) => s;
46
+ /**
47
+ * Wrap pre-rendered inner rows with a border, adding top/bottom border rows
48
+ * and left/right border chars to each inner row. Inner rows must be padded
49
+ * to a uniform width; the output rows are `innerWidth + 2` wide.
50
+ *
51
+ * Border glyphs and the optional title can be styled independently via
52
+ * `borderStyle` / `titleStyle` — each is a pre-bound `StyleBuilder`, so
53
+ * this helper stays purely about geometry and never touches SGR itself.
54
+ *
55
+ * @internal
56
+ */
57
+ function drawBorder(rows, chars, opts = {}) {
58
+ const { title, titleAlign } = opts;
59
+ const inner = rows.length > 0 ? stringWidth(rows[0]) : 0;
60
+ const wrapB = opts.borderStyle ?? identity;
61
+ const wrapT = opts.titleStyle ?? identity;
62
+ const out = [];
63
+ out.push(topRow({
64
+ align: titleAlign ?? "left",
65
+ chars,
66
+ inner,
67
+ title,
68
+ wrapB,
69
+ wrapT
70
+ }));
71
+ const v = wrapB(chars.v);
72
+ for (const row of rows) out.push(v + row + v);
73
+ out.push(wrapB(chars.bl + chars.h.repeat(inner) + chars.br));
74
+ return out;
75
+ }
76
+ function topRow({ align, chars, inner, title, wrapB, wrapT }) {
77
+ if (title === void 0 || title === "") return wrapB(chars.tl + chars.h.repeat(inner) + chars.tr);
78
+ const budget = inner - 4;
79
+ if (budget <= 0) return wrapB(chars.tl + chars.h.repeat(inner) + chars.tr);
80
+ const shown = truncate(title, budget);
81
+ const { leading, trailing } = distributeH(inner - 2 - stringWidth(shown), align);
82
+ const prefix = wrapB(`${chars.tl}${chars.h.repeat(leading)}`);
83
+ const titleSeg = wrapT(` ${shown} `);
84
+ const suffix = wrapB(`${chars.h.repeat(trailing)}${chars.tr}`);
85
+ return prefix + titleSeg + suffix;
86
+ }
87
+ function distributeH(totalH, align) {
88
+ if (align === "left") return {
89
+ leading: 1,
90
+ trailing: totalH - 1
91
+ };
92
+ if (align === "right") return {
93
+ leading: totalH - 1,
94
+ trailing: 1
95
+ };
96
+ const leading = Math.floor(totalH / 2);
97
+ return {
98
+ leading,
99
+ trailing: totalH - leading
100
+ };
101
+ }
102
+ function truncate(s, width) {
103
+ if (stringWidth(s) <= width) return s;
104
+ if (width <= 1) return "…".repeat(width);
105
+ return `${sliceAnsi(s, 0, width - 1)}…`;
106
+ }
107
+ //#endregion
108
+ //#region src/widgets/box.ts
109
+ var Box = class extends Node {
110
+ async _render(ctx) {
111
+ const style = this.state;
112
+ const [padT, padR, padB, padL] = resolvePadding(style.padding);
113
+ const bchars = resolveBorder(style.border);
114
+ const hasBorder = bchars !== void 0;
115
+ const chrome = padL + padR + (hasBorder ? 2 : 0);
116
+ let outer;
117
+ let contentRows;
118
+ let inner;
119
+ if (style.width === "fit") {
120
+ const upper = Math.max(0, ctx.width - chrome);
121
+ const tentative = await this.#layoutChildren(upper, ctx);
122
+ const natural = tentative.reduce((m, r) => Math.max(m, stringWidth(r)), 0);
123
+ outer = clamp(Math.min(ctx.width, natural + chrome), {
124
+ available: ctx.width,
125
+ max: style.maxWidth,
126
+ min: style.minWidth
127
+ });
128
+ inner = Math.max(0, outer - chrome);
129
+ contentRows = tentative;
130
+ } else {
131
+ outer = clamp(resolveSize(style.width ?? "fill", ctx.width) ?? ctx.width, {
132
+ available: ctx.width,
133
+ max: style.maxWidth,
134
+ min: style.minWidth
135
+ });
136
+ inner = Math.max(0, outer - chrome);
137
+ contentRows = await this.#layoutChildren(inner, ctx);
138
+ }
139
+ const paddedWidth = Math.max(0, outer - (hasBorder ? 2 : 0));
140
+ contentRows = contentRows.map((row) => padRow(row, inner));
141
+ if (padL > 0 || padR > 0) {
142
+ const lp = " ".repeat(padL);
143
+ const rp = " ".repeat(padR);
144
+ contentRows = contentRows.map((row) => lp + row + rp);
145
+ }
146
+ const blank = " ".repeat(paddedWidth);
147
+ const top = Array.from({ length: padT }, () => blank);
148
+ const bot = Array.from({ length: padB }, () => blank);
149
+ let rows = [
150
+ ...top,
151
+ ...contentRows,
152
+ ...bot
153
+ ];
154
+ if (style.height !== void 0) {
155
+ const innerH = Math.max(0, style.height - (hasBorder ? 2 : 0));
156
+ if (rows.length > innerH) rows = style.verticalAlign === "bottom" ? rows.slice(-innerH) : rows.slice(0, innerH);
157
+ else if (rows.length < innerH) {
158
+ const filler = Array.from({ length: innerH - rows.length }, () => blank);
159
+ rows = style.verticalAlign === "bottom" ? [...filler, ...rows] : [...rows, ...filler];
160
+ }
161
+ }
162
+ if (bchars) rows = drawBorder(rows, bchars, {
163
+ borderStyle: ctx.style.add(style.borderStyle ?? "border"),
164
+ title: await textContent(style.borderTitle, ctx),
165
+ titleAlign: style.borderTitleAlign,
166
+ titleStyle: ctx.style.add(style.borderTitleStyle ?? "borderTitle")
167
+ });
168
+ const wrap = ctx.style.add(style);
169
+ return rows.map((row) => wrap(row));
170
+ }
171
+ /**
172
+ * Intrinsic content width derived from children (or the explicit
173
+ * `width` when fixed). Lets parent flex containers size this Box
174
+ * without falling back to a measure-render — important for
175
+ * side-effecting children like `Image` whose first render allocates
176
+ * a KGP placement: rendering twice would emit two placements and the
177
+ * second render's `transmitOnce` returns no bytes, so the bytes from
178
+ * the discarded measure pass would be lost.
179
+ *
180
+ * Row direction → bases sum (plus gaps). Column direction → bases
181
+ * max. Both add chrome (padding + border) at the end.
182
+ *
183
+ * Children without `layout()` contribute 0 — the row allocator's
184
+ * render-measure fallback still kicks in for them at allocation
185
+ * time, but their absence here just means this Box reports a
186
+ * smaller intrinsic. That's the safe direction: under-report and
187
+ * let shrink/grow handle slack, never over-report.
188
+ */
189
+ async layout(ctx) {
190
+ const s = this.state;
191
+ const [, padR, , padL] = resolvePadding(s.padding);
192
+ const chrome = padL + padR + (resolveBorder(s.border) ? 2 : 0);
193
+ if (isFixedWidth(s.width)) {
194
+ const w = resolveSize(s.width, ctx.width) ?? 0;
195
+ return {
196
+ minWidth: w,
197
+ width: w
198
+ };
199
+ }
200
+ const kids = layoutNodes(this.children);
201
+ if (kids.length === 0) return {
202
+ minWidth: chrome,
203
+ width: chrome
204
+ };
205
+ const isRow = (s.flexDirection ?? "column") === "row";
206
+ const totalGap = isRow ? (s.gap ?? 0) * Math.max(0, kids.length - 1) : 0;
207
+ let widthAcc = 0;
208
+ let minAcc = 0;
209
+ for (const k of kids) {
210
+ const l = await k.getLayout(ctx) ?? {
211
+ minWidth: 0,
212
+ width: 0
213
+ };
214
+ if (isRow) {
215
+ widthAcc += l.width;
216
+ minAcc += l.minWidth;
217
+ } else {
218
+ widthAcc = Math.max(widthAcc, l.width);
219
+ minAcc = Math.max(minAcc, l.minWidth);
220
+ }
221
+ }
222
+ return {
223
+ minWidth: minAcc + totalGap + chrome,
224
+ width: widthAcc + totalGap + chrome
225
+ };
226
+ }
227
+ async #layoutChildren(innerWidth, ctx) {
228
+ const children = layoutNodes(this.children);
229
+ if (children.length === 0) return [];
230
+ const gap = this.state.gap ?? 0;
231
+ return (this.state.flexDirection ?? "column") === "row" ? this.#layoutRow(children, innerWidth, ctx, gap) : this.#layoutColumn(children, innerWidth, ctx, gap);
232
+ }
233
+ /**
234
+ * Row direction — main axis is horizontal. CSS-style flex:
235
+ * each child sizes to its intrinsic content width unless it claims
236
+ * slack via `flexGrow > 0` or `width: "fill"`. Slack distributes by
237
+ * grow weights; deficit distributes by `basis * flexShrink` clamped
238
+ * at each child's `min-content` floor.
239
+ *
240
+ * Sizing strategy per child:
241
+ * 1. `node.layout(ctx)` — sync, content-derived. If implemented,
242
+ * use directly; no render needed for measurement.
243
+ * 2. Otherwise fall back to render-at-innerWidth and measure the
244
+ * widest emitted row. Cached; the paint pass reuses the result
245
+ * whenever the allocated width matches the measurement width.
246
+ *
247
+ * In `fit` mode the parent has no slack to give, so the allocator's
248
+ * available is capped at the natural sum.
249
+ */
250
+ async #layoutRow(children, innerWidth, ctx, gap) {
251
+ const intrinsics = await Promise.all(children.map((c) => c.getLayout(ctx)));
252
+ const measureWidths = children.map((c, i) => {
253
+ if (intrinsics[i] !== void 0) return -1;
254
+ if (isFixedWidth(c.state.width)) return resolveSize(c.state.width, innerWidth) ?? innerWidth;
255
+ return innerWidth;
256
+ });
257
+ const measureRows = await Promise.all(children.map((c, i) => {
258
+ if (measureWidths[i] === -1) return Promise.resolve(void 0);
259
+ return c.render({
260
+ ...ctx,
261
+ width: measureWidths[i]
262
+ });
263
+ }));
264
+ const naturals = children.map((c, i) => {
265
+ if (isFixedWidth(c.state.width)) return resolveSize(c.state.width, innerWidth) ?? 0;
266
+ const intr = intrinsics[i];
267
+ if (intr) return intr.width;
268
+ return (measureRows[i] ?? []).reduce((m, r) => Math.max(m, stringWidth(r)), 0);
269
+ });
270
+ const widths = allocateRow(children.map((c, i) => {
271
+ const s = c.state;
272
+ return {
273
+ flexGrow: s.flexGrow,
274
+ flexShrink: s.flexShrink,
275
+ intrinsicMin: intrinsics[i]?.minWidth,
276
+ maxWidth: s.maxWidth,
277
+ minWidth: s.minWidth,
278
+ natural: naturals[i],
279
+ width: s.width
280
+ };
281
+ }), {
282
+ contentWidth: this.state.width === "fit" ? naturals.reduce((a, b) => a + b, 0) + gap * Math.max(0, children.length - 1) : innerWidth,
283
+ gap
284
+ });
285
+ return zipRow((await Promise.all(children.map((c, i) => {
286
+ const cached = measureRows[i];
287
+ if (cached !== void 0 && widths[i] === measureWidths[i]) return Promise.resolve(cached);
288
+ return c.render({
289
+ ...ctx,
290
+ width: widths[i]
291
+ });
292
+ }))).map((rows, i) => rows.map((row) => padRow(row, widths[i]))), {
293
+ gap,
294
+ widths
295
+ });
296
+ }
297
+ /**
298
+ * Column direction — main axis is vertical, cross axis horizontal.
299
+ * Per CSS `align-items: stretch` (default), children with no
300
+ * explicit `width` fill the cross axis. A child with a fixed `width`
301
+ * (number / `Pct`) takes that width as its cross-axis size, with the
302
+ * leftover padded as right slack (default `flex-start`). `min`/`max`
303
+ * clamp the resolved width.
304
+ *
305
+ * In fit-mode (`width: "fit"`), the cross-axis target shrinks to the
306
+ * widest child row instead of stretching to `innerWidth` — symmetric
307
+ * to how row-direction caps allocator-available at the natural sum.
308
+ */
309
+ async #layoutColumn(children, innerWidth, ctx, gap) {
310
+ const widths = children.map((c) => {
311
+ const s = c.state;
312
+ return clamp((isFixedWidth(s.width) ? resolveSize(s.width, innerWidth) : void 0) ?? innerWidth, {
313
+ available: innerWidth,
314
+ max: s.maxWidth,
315
+ min: s.minWidth
316
+ });
317
+ });
318
+ const childRows = await Promise.all(children.map((c, i) => c.render({
319
+ ...ctx,
320
+ width: widths[i]
321
+ })));
322
+ const target = this.state.width === "fit" ? childRows.reduce((m, rows) => rows.reduce((mm, r) => Math.max(mm, stringWidth(r)), m), 0) : innerWidth;
323
+ return stackColumn(childRows.map((rows) => rows.map((row) => padRow(row, target))), {
324
+ gap,
325
+ width: target
326
+ });
327
+ }
328
+ };
329
+ /**
330
+ * Factory for `Box`. The style object is required (use `{}` if you don't
331
+ * need any styling) — the previous style-less overload caused TS to fail
332
+ * to discriminate between a Node child and an inferred-empty-state node
333
+ * like `WidgetNode`. Pass `box({}, child1, child2)` for un-styled boxes.
334
+ *
335
+ * Falsy children (`false`, `null`, `undefined`) are filtered out, enabling
336
+ * conditional JSX-like composition: `box({}, cond && child)`.
337
+ */
338
+ function box(style, ...children) {
339
+ const b = new Box(style);
340
+ for (const c of children) if (c) b.add(c);
341
+ return b;
342
+ }
343
+ /**
344
+ * Flatten fragment nodes (those that implement the `layoutChildren`
345
+ * protocol — `show`, `errorBoundary`, `suspense`) into their currently
346
+ * active leaves. Recursive: a fragment whose `layoutChildren()`
347
+ * itself contains fragments unfolds completely.
348
+ *
349
+ * The fragment Node still lives in the tree (mounted, propagating
350
+ * invalidates) — layout just sees through it so its children share
351
+ * the parent box's flex distribution, gap, and cross-axis sizing
352
+ * instead of collapsing into a single slot.
353
+ */
354
+ function layoutNodes(children) {
355
+ return children.flatMap((c) => c.layoutNodes).filter((c) => unwrap(c.state.visible) ?? true);
356
+ }
357
+ function resolvePadding(p) {
358
+ if (p === void 0) return [
359
+ 0,
360
+ 0,
361
+ 0,
362
+ 0
363
+ ];
364
+ if (typeof p === "number") return [
365
+ p,
366
+ p,
367
+ p,
368
+ p
369
+ ];
370
+ if (p.length === 2) return [
371
+ p[0],
372
+ p[1],
373
+ p[0],
374
+ p[1]
375
+ ];
376
+ return [
377
+ p[0],
378
+ p[1],
379
+ p[2],
380
+ p[3]
381
+ ];
382
+ }
383
+ //#endregion
384
+ export { box as n, Box as t };
385
+
386
+ //# sourceMappingURL=box-DyaByEiG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box-DyaByEiG.mjs","names":["#layoutChildren","#layoutRow","#layoutColumn"],"sources":["../src/layout/border.ts","../src/widgets/box.ts"],"sourcesContent":["import type { StyleBuilder } from \"../style/builder.ts\"\n\nimport { sliceAnsi, stringWidth } from \"@zaly/shared/ansi\"\n\n/**\n * Border-character glyphs for drawing a box outline. Any single-cell string\n * is allowed (including multi-byte glyphs like rounded corners).\n */\nexport interface BorderChars {\n h: string\n v: string\n tl: string\n tr: string\n bl: string\n br: string\n}\n\nexport type BorderSpec = boolean | \"single\" | \"double\" | \"rounded\" | BorderChars\n\n/** @internal */\nexport const borders = {\n double: { bl: \"╚\", br: \"╝\", h: \"═\", tl: \"╔\", tr: \"╗\", v: \"║\" },\n rounded: { bl: \"╰\", br: \"╯\", h: \"─\", tl: \"╭\", tr: \"╮\", v: \"│\" },\n single: { bl: \"└\", br: \"┘\", h: \"─\", tl: \"┌\", tr: \"┐\", v: \"│\" },\n} as const satisfies Record<string, BorderChars>\n\n/** Resolve the `border` style value to a concrete BorderChars, or undefined.\n *\n * @internal*/\nexport function resolveBorder(spec: BorderSpec | undefined): BorderChars | undefined {\n if (spec === undefined || spec === false) return undefined\n if (spec === true) return borders.single\n if (typeof spec === \"string\") return borders[spec]\n return spec\n}\n\nexport type TitleAlign = \"left\" | \"center\" | \"right\"\n\nexport interface DrawBorderOpts {\n /**\n * Optional title embedded in the top border, with a single-cell space on\n * each side. Ellipsis-truncated when it overflows the budget.\n */\n title?: string\n /** Placement of `title` along the top border. Defaults to `\"left\"`. */\n titleAlign?: TitleAlign\n /**\n * Styled wrapper applied to the border glyphs (corners, horizontal,\n * vertical). Use `ctx.style.add(slotOrStyle)` at the call site so the\n * theme is resolved once per render.\n */\n borderStyle?: StyleBuilder\n /** Styled wrapper applied to the title text (including the padding spaces). */\n titleStyle?: StyleBuilder\n}\n\n/** Pass-through wrapper used when no style is supplied. */\nconst identity = (s: string): string => s\n\n/**\n * Wrap pre-rendered inner rows with a border, adding top/bottom border rows\n * and left/right border chars to each inner row. Inner rows must be padded\n * to a uniform width; the output rows are `innerWidth + 2` wide.\n *\n * Border glyphs and the optional title can be styled independently via\n * `borderStyle` / `titleStyle` — each is a pre-bound `StyleBuilder`, so\n * this helper stays purely about geometry and never touches SGR itself.\n *\n * @internal\n */\nexport function drawBorder(\n rows: readonly string[],\n chars: BorderChars,\n opts: DrawBorderOpts = {}\n): string[] {\n const { title, titleAlign } = opts\n const inner = rows.length > 0 ? stringWidth(rows[0]) : 0\n const wrapB = opts.borderStyle ?? identity\n const wrapT = opts.titleStyle ?? identity\n\n const out: string[] = []\n out.push(topRow({ align: titleAlign ?? \"left\", chars, inner, title, wrapB, wrapT }))\n const v = wrapB(chars.v)\n for (const row of rows) out.push(v + row + v)\n out.push(wrapB(chars.bl + chars.h.repeat(inner) + chars.br))\n return out\n}\n\ninterface TopRowArgs {\n align: TitleAlign\n chars: BorderChars\n inner: number\n title: string | undefined\n wrapB: (s: string) => string\n wrapT: (s: string) => string\n}\n\nfunction topRow({ align, chars, inner, title, wrapB, wrapT }: TopRowArgs): string {\n if (title === undefined || title === \"\") {\n return wrapB(chars.tl + chars.h.repeat(inner) + chars.tr)\n }\n // Chrome: h + space + title + space + h (4 cells of chrome around the title)\n const budget = inner - 4\n if (budget <= 0) return wrapB(chars.tl + chars.h.repeat(inner) + chars.tr)\n const shown = truncate(title, budget)\n const totalH = inner - 2 - stringWidth(shown)\n const { leading, trailing } = distributeH(totalH, align)\n const prefix = wrapB(`${chars.tl}${chars.h.repeat(leading)}`)\n const titleSeg = wrapT(` ${shown} `)\n const suffix = wrapB(`${chars.h.repeat(trailing)}${chars.tr}`)\n return prefix + titleSeg + suffix\n}\n\nfunction distributeH(totalH: number, align: TitleAlign): { leading: number; trailing: number } {\n if (align === \"left\") return { leading: 1, trailing: totalH - 1 }\n if (align === \"right\") return { leading: totalH - 1, trailing: 1 }\n // center: leading rounds down so odd slack biases the title slightly left.\n const leading = Math.floor(totalH / 2)\n return { leading, trailing: totalH - leading }\n}\n\nfunction truncate(s: string, width: number): string {\n if (stringWidth(s) <= width) return s\n if (width <= 1) return \"…\".repeat(width)\n return `${sliceAnsi(s, 0, width - 1)}…`\n}\n","import type { RenderCtx } from \"../core/ctx.ts\"\nimport type { State } from \"../core/state.ts\"\nimport type { BorderSpec, TitleAlign } from \"../layout/border.ts\"\nimport type { RowItem } from \"../layout/flex.ts\"\nimport type { Style } from \"../style/types.ts\"\nimport type { TextContent } from \"./text.ts\"\n\nimport { stringWidth } from \"@zaly/shared/ansi\"\nimport { Node } from \"../core/node.ts\"\nimport { unwrap } from \"../core/reactive.ts\"\nimport { drawBorder, resolveBorder } from \"../layout/border.ts\"\nimport { allocateRow, isFixedWidth, padRow, stackColumn, zipRow } from \"../layout/flex.ts\"\nimport { clamp, resolveSize } from \"../layout/size.ts\"\nimport { textContent } from \"./text.ts\"\n\nexport type Padding =\n | number\n | readonly [v: number, h: number]\n | readonly [t: number, r: number, b: number, l: number]\n\nexport interface BoxStyle extends Style {\n flexDirection?: \"row\" | \"column\"\n gap?: number\n /** Fixed outer height in rows. When unset, the box's height emerges\n * naturally from its content + padding + border. When set, the\n * content area is truncated or padded with blank rows to land at\n * exactly this many rows of *outer* height. Pair with\n * `verticalAlign` to control which edge is anchored. */\n height?: number\n /** Anchor for the content when `height` truncates or extends.\n * `\"top\"` (default) keeps the top edge: extra rows added at the\n * bottom, overflow truncated from the bottom. `\"bottom\"` keeps the\n * bottom edge: extra rows prepended, overflow truncated from the\n * top. Other CSS-like values (`middle`) are not implemented. */\n verticalAlign?: \"top\" | \"bottom\"\n padding?: Padding\n border?: BorderSpec\n borderTitle?: TextContent\n /** Placement of `borderTitle` along the top border. Defaults to `\"left\"`. */\n borderTitleAlign?: TitleAlign\n /**\n * Style applied to the border glyphs. Either a theme slot name (resolved\n * via the active theme) or an inline `Style`. Defaults to the `\"border\"`\n * theme slot when a border is drawn.\n */\n borderStyle?: string | Style\n /**\n * Style applied to the border title. Defaults to the `\"borderTitle\"` theme\n * slot when a title is set.\n */\n borderTitleStyle?: string | Style\n}\n\nexport class Box<T extends object = {}> extends Node<BoxStyle & T> {\n protected async _render(ctx: RenderCtx): Promise<string[]> {\n const style = this.state\n\n const [padT, padR, padB, padL] = resolvePadding(style.padding)\n const bchars = resolveBorder(style.border)\n const hasBorder = bchars !== undefined\n const chrome = padL + padR + (hasBorder ? 2 : 0)\n\n let outer: number\n let contentRows: string[]\n let inner: number\n\n if (style.width === \"fit\") {\n // `fit`: render children at the parent's max inner width, measure\n // the natural max-row width, then clamp the box to that. Two-pass\n // — the first pass uses the upper bound as a measuring window,\n // the second re-pads each row to the chosen inner width.\n const upper = Math.max(0, ctx.width - chrome)\n const tentative = await this.#layoutChildren(upper, ctx)\n const natural = tentative.reduce((m, r) => Math.max(m, stringWidth(r)), 0)\n const fit = Math.min(ctx.width, natural + chrome)\n outer = clamp(fit, {\n available: ctx.width,\n max: style.maxWidth,\n min: style.minWidth,\n })\n inner = Math.max(0, outer - chrome)\n contentRows = tentative\n } else {\n const requested = resolveSize(style.width ?? \"fill\", ctx.width) ?? ctx.width\n outer = clamp(requested, {\n available: ctx.width,\n max: style.maxWidth,\n min: style.minWidth,\n })\n inner = Math.max(0, outer - chrome)\n contentRows = await this.#layoutChildren(inner, ctx)\n }\n\n const paddedWidth = Math.max(0, outer - (hasBorder ? 2 : 0))\n\n // Ensure each content row is exactly `inner` cells wide (absorbs slack).\n contentRows = contentRows.map((row) => padRow(row, inner))\n\n // Horizontal padding.\n if (padL > 0 || padR > 0) {\n const lp = \" \".repeat(padL)\n const rp = \" \".repeat(padR)\n contentRows = contentRows.map((row) => lp + row + rp)\n }\n\n // Vertical padding.\n const blank = \" \".repeat(paddedWidth)\n const top = Array.from({ length: padT }, () => blank)\n const bot = Array.from({ length: padB }, () => blank)\n let rows = [...top, ...contentRows, ...bot]\n\n // Fixed-height fit. The `height` field is the outer dimension —\n // border takes its 2 rows out before we measure against the\n // content area; padding is already baked into `rows`. `verticalAlign`\n // decides which end gets clipped (when too tall) or padded (when\n // too short). Default `\"top\"` matches the natural reading flow.\n if (style.height !== undefined) {\n const innerH = Math.max(0, style.height - (hasBorder ? 2 : 0))\n if (rows.length > innerH) {\n rows = style.verticalAlign === \"bottom\" ? rows.slice(-innerH) : rows.slice(0, innerH)\n } else if (rows.length < innerH) {\n const filler = Array.from({ length: innerH - rows.length }, () => blank)\n rows = style.verticalAlign === \"bottom\" ? [...filler, ...rows] : [...rows, ...filler]\n }\n }\n\n if (bchars) {\n rows = drawBorder(rows, bchars, {\n borderStyle: ctx.style.add(style.borderStyle ?? \"border\"),\n title: await textContent(style.borderTitle, ctx),\n titleAlign: style.borderTitleAlign,\n titleStyle: ctx.style.add(style.borderTitleStyle ?? \"borderTitle\"),\n })\n }\n\n const wrap = ctx.style.add(style)\n return rows.map((row) => wrap(row))\n }\n\n /**\n * Intrinsic content width derived from children (or the explicit\n * `width` when fixed). Lets parent flex containers size this Box\n * without falling back to a measure-render — important for\n * side-effecting children like `Image` whose first render allocates\n * a KGP placement: rendering twice would emit two placements and the\n * second render's `transmitOnce` returns no bytes, so the bytes from\n * the discarded measure pass would be lost.\n *\n * Row direction → bases sum (plus gaps). Column direction → bases\n * max. Both add chrome (padding + border) at the end.\n *\n * Children without `layout()` contribute 0 — the row allocator's\n * render-measure fallback still kicks in for them at allocation\n * time, but their absence here just means this Box reports a\n * smaller intrinsic. That's the safe direction: under-report and\n * let shrink/grow handle slack, never over-report.\n */\n override async layout(ctx: RenderCtx) {\n const s = this.state\n const [, padR, , padL] = resolvePadding(s.padding)\n const chrome = padL + padR + (resolveBorder(s.border) ? 2 : 0)\n\n // Fixed width wins outright.\n if (isFixedWidth(s.width)) {\n const w = resolveSize(s.width, ctx.width) ?? 0\n return { minWidth: w, width: w }\n }\n\n const kids = layoutNodes(this.children)\n if (kids.length === 0) return { minWidth: chrome, width: chrome }\n\n const isRow = (s.flexDirection ?? \"column\") === \"row\"\n const totalGap = isRow ? (s.gap ?? 0) * Math.max(0, kids.length - 1) : 0\n\n let widthAcc = 0\n let minAcc = 0\n for (const k of kids) {\n // oxlint-disable-next-line no-await-in-loop\n const l = (await k.getLayout(ctx)) ?? { minWidth: 0, width: 0 }\n if (isRow) {\n widthAcc += l.width\n minAcc += l.minWidth\n } else {\n widthAcc = Math.max(widthAcc, l.width)\n minAcc = Math.max(minAcc, l.minWidth)\n }\n }\n\n return { minWidth: minAcc + totalGap + chrome, width: widthAcc + totalGap + chrome }\n }\n\n async #layoutChildren(innerWidth: number, ctx: RenderCtx): Promise<string[]> {\n const children = layoutNodes(this.children)\n if (children.length === 0) return []\n const gap = this.state.gap ?? 0\n return (this.state.flexDirection ?? \"column\") === \"row\"\n ? this.#layoutRow(children, innerWidth, ctx, gap)\n : this.#layoutColumn(children, innerWidth, ctx, gap)\n }\n\n /**\n * Row direction — main axis is horizontal. CSS-style flex:\n * each child sizes to its intrinsic content width unless it claims\n * slack via `flexGrow > 0` or `width: \"fill\"`. Slack distributes by\n * grow weights; deficit distributes by `basis * flexShrink` clamped\n * at each child's `min-content` floor.\n *\n * Sizing strategy per child:\n * 1. `node.layout(ctx)` — sync, content-derived. If implemented,\n * use directly; no render needed for measurement.\n * 2. Otherwise fall back to render-at-innerWidth and measure the\n * widest emitted row. Cached; the paint pass reuses the result\n * whenever the allocated width matches the measurement width.\n *\n * In `fit` mode the parent has no slack to give, so the allocator's\n * available is capped at the natural sum.\n */\n async #layoutRow(\n children: readonly Node[],\n innerWidth: number,\n ctx: RenderCtx,\n gap: number\n ): Promise<string[]> {\n // Phase 1: figure out each child's intrinsic size.\n // - `layout()` short-circuits — sync, no render.\n // - Fallback: render at the upper bound (innerWidth or fixed spec)\n // and measure rows.\n const intrinsics = await Promise.all(children.map((c) => c.getLayout(ctx)))\n // For children with intrinsic sizing, skip the measure render\n // entirely. Others fall back to render-at-upper-bound (their fixed\n // width, or innerWidth if fluid).\n const measureWidths = children.map((c, i) => {\n if (intrinsics[i] !== undefined) return -1\n if (isFixedWidth(c.state.width)) {\n return resolveSize(c.state.width, innerWidth) ?? innerWidth\n }\n return innerWidth\n })\n const measureRows = await Promise.all(\n children.map((c, i): Promise<string[] | undefined> => {\n if (measureWidths[i] === -1) return Promise.resolve(undefined)\n return c.render({ ...ctx, width: measureWidths[i] })\n })\n )\n const naturals = children.map((c, i) => {\n // A fixed `state.width` is what the allocator will actually\n // assign this child — use it directly so the fit-mode\n // `allocAvailable` sum below matches what we'll consume. Falling\n // back to intrinsic when there's no override under-reports a\n // child like `text(\"x\", { width: 2 })` and shrinks every sibling\n // by the missing cells.\n if (isFixedWidth(c.state.width)) {\n return resolveSize(c.state.width, innerWidth) ?? 0\n }\n const intr = intrinsics[i]\n if (intr) return intr.width\n return (measureRows[i] ?? []).reduce((m, r) => Math.max(m, stringWidth(r)), 0)\n })\n const items: RowItem[] = children.map((c, i) => {\n const s = c.state\n return {\n flexGrow: s.flexGrow,\n flexShrink: s.flexShrink,\n intrinsicMin: intrinsics[i]?.minWidth,\n maxWidth: s.maxWidth,\n minWidth: s.minWidth,\n natural: naturals[i],\n width: s.width,\n }\n })\n const allocAvailable =\n this.state.width === \"fit\"\n ? naturals.reduce((a, b) => a + b, 0) + gap * Math.max(0, children.length - 1)\n : innerWidth\n const widths = allocateRow(items, { contentWidth: allocAvailable, gap })\n // Phase 2: paint at allocated widths. Reuse the measure-render when\n // the allocation matches; otherwise render fresh (cached).\n const childRows = await Promise.all(\n children.map((c, i): Promise<string[]> => {\n const cached = measureRows[i]\n if (cached !== undefined && widths[i] === measureWidths[i]) {\n return Promise.resolve(cached)\n }\n return c.render({ ...ctx, width: widths[i] })\n })\n )\n // `zipRow` expects rows to be exactly `widths[i]` wide. Children\n // that emit natural-width rows (text default, code default) get\n // padded here so the contract holds; over-wide rows get clipped.\n const padded = childRows.map((rows, i) => rows.map((row) => padRow(row, widths[i])))\n return zipRow(padded, { gap, widths })\n }\n\n /**\n * Column direction — main axis is vertical, cross axis horizontal.\n * Per CSS `align-items: stretch` (default), children with no\n * explicit `width` fill the cross axis. A child with a fixed `width`\n * (number / `Pct`) takes that width as its cross-axis size, with the\n * leftover padded as right slack (default `flex-start`). `min`/`max`\n * clamp the resolved width.\n *\n * In fit-mode (`width: \"fit\"`), the cross-axis target shrinks to the\n * widest child row instead of stretching to `innerWidth` — symmetric\n * to how row-direction caps allocator-available at the natural sum.\n */\n async #layoutColumn(\n children: readonly Node[],\n innerWidth: number,\n ctx: RenderCtx,\n gap: number\n ): Promise<string[]> {\n const widths = children.map((c) => {\n const s = c.state\n const fixed = isFixedWidth(s.width) ? resolveSize(s.width, innerWidth) : undefined\n const w = fixed ?? innerWidth\n return clamp(w, { available: innerWidth, max: s.maxWidth, min: s.minWidth })\n })\n const childRows = await Promise.all(\n children.map((c, i) => c.render({ ...ctx, width: widths[i] }))\n )\n const target =\n this.state.width === \"fit\"\n ? childRows.reduce((m, rows) => rows.reduce((mm, r) => Math.max(mm, stringWidth(r)), m), 0)\n : innerWidth\n // Pad each child's rows to the cross-axis target. For full-stretch\n // children this absorbs natural-row slack; for fixed-width\n // children it adds right-side slack (default `flex-start`\n // alignment). `stackColumn`'s contract requires uniform width.\n const padded = childRows.map((rows) => rows.map((row) => padRow(row, target)))\n return stackColumn(padded, { gap, width: target })\n }\n}\n\ntype Child = Node | false | null | undefined\n\n/**\n * Factory for `Box`. The style object is required (use `{}` if you don't\n * need any styling) — the previous style-less overload caused TS to fail\n * to discriminate between a Node child and an inferred-empty-state node\n * like `WidgetNode`. Pass `box({}, child1, child2)` for un-styled boxes.\n *\n * Falsy children (`false`, `null`, `undefined`) are filtered out, enabling\n * conditional JSX-like composition: `box({}, cond && child)`.\n */\nexport function box(style: State<BoxStyle>, ...children: Child[]): Box {\n const b = new Box(style)\n for (const c of children) if (c) b.add(c)\n return b\n}\n\n/**\n * Flatten fragment nodes (those that implement the `layoutChildren`\n * protocol — `show`, `errorBoundary`, `suspense`) into their currently\n * active leaves. Recursive: a fragment whose `layoutChildren()`\n * itself contains fragments unfolds completely.\n *\n * The fragment Node still lives in the tree (mounted, propagating\n * invalidates) — layout just sees through it so its children share\n * the parent box's flex distribution, gap, and cross-axis sizing\n * instead of collapsing into a single slot.\n */\nfunction layoutNodes(children: readonly Node[]): readonly Node[] {\n return children.flatMap((c) => c.layoutNodes).filter((c) => unwrap(c.state.visible) ?? true)\n}\n\nfunction resolvePadding(p: Padding | undefined): [t: number, r: number, b: number, l: number] {\n if (p === undefined) return [0, 0, 0, 0]\n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