@mdxui/terminal 2.0.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 (191) hide show
  1. package/README.md +571 -0
  2. package/dist/ansi-css-Sk5mWtdK.d.ts +119 -0
  3. package/dist/ansi-css-V6JIHGsM.d.ts +119 -0
  4. package/dist/ansi-css-_3eSEU9d.d.ts +119 -0
  5. package/dist/chunk-3EFDH7PK.js +5235 -0
  6. package/dist/chunk-3RG5ZIWI.js +10 -0
  7. package/dist/chunk-3X5IR6WE.js +884 -0
  8. package/dist/chunk-4FV5ZDCE.js +5236 -0
  9. package/dist/chunk-4OVMSF2J.js +243 -0
  10. package/dist/chunk-63FEETIS.js +4048 -0
  11. package/dist/chunk-B43KP7XJ.js +884 -0
  12. package/dist/chunk-BMTJXWUV.js +655 -0
  13. package/dist/chunk-C3SVH4N7.js +882 -0
  14. package/dist/chunk-EVWR7Y47.js +874 -0
  15. package/dist/chunk-F6A5VWUC.js +1285 -0
  16. package/dist/chunk-FD7KW7GE.js +882 -0
  17. package/dist/chunk-GBQ6UD6I.js +655 -0
  18. package/dist/chunk-GMDD3M6U.js +5227 -0
  19. package/dist/chunk-JBHRXOXM.js +1058 -0
  20. package/dist/chunk-JFOO3EYO.js +1182 -0
  21. package/dist/chunk-JQ5H3WXL.js +1291 -0
  22. package/dist/chunk-JQD5NASE.js +234 -0
  23. package/dist/chunk-KRHJP5R7.js +592 -0
  24. package/dist/chunk-KWF6WVJE.js +962 -0
  25. package/dist/chunk-LHYQVN3H.js +1038 -0
  26. package/dist/chunk-M3TLQLGC.js +1032 -0
  27. package/dist/chunk-MVW4Q5OP.js +240 -0
  28. package/dist/chunk-NXCZSWLU.js +1294 -0
  29. package/dist/chunk-O25TNRO6.js +607 -0
  30. package/dist/chunk-PNECDA2I.js +884 -0
  31. package/dist/chunk-QIHWRLJR.js +962 -0
  32. package/dist/chunk-QW5YMQ7K.js +882 -0
  33. package/dist/chunk-R5U7XKVJ.js +16 -0
  34. package/dist/chunk-RP2MVQLR.js +962 -0
  35. package/dist/chunk-TP6RXGXA.js +1087 -0
  36. package/dist/chunk-TQQSTITZ.js +655 -0
  37. package/dist/chunk-X24GWXQV.js +1281 -0
  38. package/dist/components/index.d.ts +802 -0
  39. package/dist/components/index.js +149 -0
  40. package/dist/data/index.d.ts +2554 -0
  41. package/dist/data/index.js +51 -0
  42. package/dist/forms/index.d.ts +1596 -0
  43. package/dist/forms/index.js +464 -0
  44. package/dist/index-CQRFZntR.d.ts +867 -0
  45. package/dist/index.d.ts +579 -0
  46. package/dist/index.js +786 -0
  47. package/dist/interactive-D0JkWosD.d.ts +217 -0
  48. package/dist/keyboard/index.d.ts +2 -0
  49. package/dist/keyboard/index.js +43 -0
  50. package/dist/renderers/index.d.ts +546 -0
  51. package/dist/renderers/index.js +2157 -0
  52. package/dist/storybook/index.d.ts +396 -0
  53. package/dist/storybook/index.js +641 -0
  54. package/dist/theme/index.d.ts +1339 -0
  55. package/dist/theme/index.js +123 -0
  56. package/dist/types-Bxu5PAgA.d.ts +710 -0
  57. package/dist/types-CIlop5Ji.d.ts +701 -0
  58. package/dist/types-Ca8p_p5X.d.ts +710 -0
  59. package/package.json +90 -0
  60. package/src/__tests__/components/data/card.test.ts +458 -0
  61. package/src/__tests__/components/data/list.test.ts +473 -0
  62. package/src/__tests__/components/data/metrics.test.ts +541 -0
  63. package/src/__tests__/components/data/table.test.ts +448 -0
  64. package/src/__tests__/components/input/field.test.ts +555 -0
  65. package/src/__tests__/components/input/form.test.ts +870 -0
  66. package/src/__tests__/components/input/search.test.ts +1238 -0
  67. package/src/__tests__/components/input/select.test.ts +658 -0
  68. package/src/__tests__/components/navigation/breadcrumb.test.ts +923 -0
  69. package/src/__tests__/components/navigation/command-palette.test.ts +1095 -0
  70. package/src/__tests__/components/navigation/sidebar.test.ts +1018 -0
  71. package/src/__tests__/components/navigation/tabs.test.ts +995 -0
  72. package/src/__tests__/components.test.tsx +1197 -0
  73. package/src/__tests__/core/compiler.test.ts +986 -0
  74. package/src/__tests__/core/parser.test.ts +785 -0
  75. package/src/__tests__/core/tier-switcher.test.ts +1103 -0
  76. package/src/__tests__/core/types.test.ts +1398 -0
  77. package/src/__tests__/data/collections.test.ts +1337 -0
  78. package/src/__tests__/data/db.test.ts +1265 -0
  79. package/src/__tests__/data/reactive.test.ts +1010 -0
  80. package/src/__tests__/data/sync.test.ts +1614 -0
  81. package/src/__tests__/errors.test.ts +660 -0
  82. package/src/__tests__/forms/integration.test.ts +444 -0
  83. package/src/__tests__/integration.test.ts +905 -0
  84. package/src/__tests__/keyboard.test.ts +1791 -0
  85. package/src/__tests__/renderer.test.ts +489 -0
  86. package/src/__tests__/renderers/ansi-css.test.ts +948 -0
  87. package/src/__tests__/renderers/ansi.test.ts +1366 -0
  88. package/src/__tests__/renderers/ascii.test.ts +1360 -0
  89. package/src/__tests__/renderers/interactive.test.ts +2353 -0
  90. package/src/__tests__/renderers/markdown.test.ts +1483 -0
  91. package/src/__tests__/renderers/text.test.ts +1369 -0
  92. package/src/__tests__/renderers/unicode.test.ts +1307 -0
  93. package/src/__tests__/theme.test.ts +639 -0
  94. package/src/__tests__/utils/assertions.ts +685 -0
  95. package/src/__tests__/utils/index.ts +115 -0
  96. package/src/__tests__/utils/test-renderer.ts +381 -0
  97. package/src/__tests__/utils/utils.test.ts +560 -0
  98. package/src/components/containers/card.ts +56 -0
  99. package/src/components/containers/dialog.ts +53 -0
  100. package/src/components/containers/index.ts +9 -0
  101. package/src/components/containers/panel.ts +59 -0
  102. package/src/components/feedback/badge.ts +40 -0
  103. package/src/components/feedback/index.ts +8 -0
  104. package/src/components/feedback/spinner.ts +23 -0
  105. package/src/components/helpers.ts +81 -0
  106. package/src/components/index.ts +153 -0
  107. package/src/components/layout/breadcrumb.ts +31 -0
  108. package/src/components/layout/index.ts +10 -0
  109. package/src/components/layout/list.ts +29 -0
  110. package/src/components/layout/sidebar.ts +79 -0
  111. package/src/components/layout/table.ts +62 -0
  112. package/src/components/primitives/box.ts +95 -0
  113. package/src/components/primitives/button.ts +54 -0
  114. package/src/components/primitives/index.ts +11 -0
  115. package/src/components/primitives/input.ts +88 -0
  116. package/src/components/primitives/select.ts +97 -0
  117. package/src/components/primitives/text.ts +60 -0
  118. package/src/components/render.ts +155 -0
  119. package/src/components/templates/app.ts +43 -0
  120. package/src/components/templates/index.ts +8 -0
  121. package/src/components/templates/site.ts +54 -0
  122. package/src/components/types.ts +777 -0
  123. package/src/core/compiler.ts +718 -0
  124. package/src/core/parser.ts +127 -0
  125. package/src/core/tier-switcher.ts +607 -0
  126. package/src/core/types.ts +672 -0
  127. package/src/data/collection.ts +316 -0
  128. package/src/data/collections.ts +50 -0
  129. package/src/data/context.tsx +174 -0
  130. package/src/data/db.ts +127 -0
  131. package/src/data/hooks.ts +532 -0
  132. package/src/data/index.ts +138 -0
  133. package/src/data/reactive.ts +1225 -0
  134. package/src/data/saas-collections.ts +375 -0
  135. package/src/data/sync.ts +1213 -0
  136. package/src/data/types.ts +660 -0
  137. package/src/forms/converters.ts +512 -0
  138. package/src/forms/index.ts +133 -0
  139. package/src/forms/schemas.ts +403 -0
  140. package/src/forms/types.ts +476 -0
  141. package/src/index.ts +542 -0
  142. package/src/keyboard/focus.ts +748 -0
  143. package/src/keyboard/index.ts +96 -0
  144. package/src/keyboard/integration.ts +371 -0
  145. package/src/keyboard/manager.ts +377 -0
  146. package/src/keyboard/presets.ts +90 -0
  147. package/src/renderers/ansi-css.ts +576 -0
  148. package/src/renderers/ansi.ts +802 -0
  149. package/src/renderers/ascii.ts +680 -0
  150. package/src/renderers/breadcrumb.ts +480 -0
  151. package/src/renderers/command-palette.ts +802 -0
  152. package/src/renderers/components/field.ts +210 -0
  153. package/src/renderers/components/form.ts +327 -0
  154. package/src/renderers/components/index.ts +21 -0
  155. package/src/renderers/components/search.ts +449 -0
  156. package/src/renderers/components/select.ts +222 -0
  157. package/src/renderers/index.ts +101 -0
  158. package/src/renderers/interactive/component-handlers.ts +622 -0
  159. package/src/renderers/interactive/cursor-manager.ts +147 -0
  160. package/src/renderers/interactive/focus-manager.ts +279 -0
  161. package/src/renderers/interactive/index.ts +661 -0
  162. package/src/renderers/interactive/input-handler.ts +164 -0
  163. package/src/renderers/interactive/keyboard-handler.ts +212 -0
  164. package/src/renderers/interactive/mouse-handler.ts +167 -0
  165. package/src/renderers/interactive/state-manager.ts +109 -0
  166. package/src/renderers/interactive/types.ts +338 -0
  167. package/src/renderers/interactive-string.ts +299 -0
  168. package/src/renderers/interactive.ts +59 -0
  169. package/src/renderers/markdown.ts +950 -0
  170. package/src/renderers/sidebar.ts +549 -0
  171. package/src/renderers/tabs.ts +682 -0
  172. package/src/renderers/text.ts +791 -0
  173. package/src/renderers/unicode.ts +917 -0
  174. package/src/renderers/utils.ts +942 -0
  175. package/src/router/adapters.ts +383 -0
  176. package/src/router/types.ts +140 -0
  177. package/src/router/utils.ts +452 -0
  178. package/src/schemas.ts +205 -0
  179. package/src/storybook/index.ts +91 -0
  180. package/src/storybook/interactive-decorator.tsx +659 -0
  181. package/src/storybook/keyboard-simulator.ts +501 -0
  182. package/src/theme/ansi-codes.ts +80 -0
  183. package/src/theme/box-drawing.ts +132 -0
  184. package/src/theme/color-convert.ts +254 -0
  185. package/src/theme/color-support.ts +321 -0
  186. package/src/theme/index.ts +134 -0
  187. package/src/theme/strip-ansi.ts +50 -0
  188. package/src/theme/tailwind-map.ts +469 -0
  189. package/src/theme/text-styles.ts +206 -0
  190. package/src/theme/theme-system.ts +568 -0
  191. package/src/types.ts +103 -0
@@ -0,0 +1,882 @@
1
+ import {
2
+ ANSI,
3
+ boxChars,
4
+ colors,
5
+ visibleLength
6
+ } from "./chunk-4FV5ZDCE.js";
7
+
8
+ // src/components/types.ts
9
+ var COMPONENT_TYPES = /* @__PURE__ */ new Set([
10
+ "box",
11
+ "text",
12
+ "table",
13
+ "input",
14
+ "select",
15
+ "sidebar",
16
+ "sidebar-item",
17
+ "breadcrumb",
18
+ "badge",
19
+ "dialog",
20
+ "spinner",
21
+ "button",
22
+ "panel",
23
+ "list",
24
+ "card"
25
+ ]);
26
+ function isTerminalComponentType(type) {
27
+ return typeof type === "string" && COMPONENT_TYPES.has(type);
28
+ }
29
+ function isPropsObject(props) {
30
+ return typeof props === "object" && props !== null;
31
+ }
32
+ function isBoxProps(props) {
33
+ return isPropsObject(props);
34
+ }
35
+ function isTextProps(props) {
36
+ return isPropsObject(props);
37
+ }
38
+ function isTableProps(props) {
39
+ if (!isPropsObject(props)) return false;
40
+ return Array.isArray(props.data) && Array.isArray(props.columns);
41
+ }
42
+ function isInputProps(props) {
43
+ return isPropsObject(props);
44
+ }
45
+ function isSelectProps(props) {
46
+ if (!isPropsObject(props)) return false;
47
+ return Array.isArray(props.options);
48
+ }
49
+ function isSidebarProps(props) {
50
+ return isPropsObject(props);
51
+ }
52
+ function isSidebarItemProps(props) {
53
+ if (!isPropsObject(props)) return false;
54
+ return typeof props.label === "string";
55
+ }
56
+ function isBreadcrumbProps(props) {
57
+ if (!isPropsObject(props)) return false;
58
+ return Array.isArray(props.items);
59
+ }
60
+ function isBadgeProps(props) {
61
+ return isPropsObject(props);
62
+ }
63
+ function isDialogProps(props) {
64
+ return isPropsObject(props);
65
+ }
66
+ function isSpinnerProps(props) {
67
+ return isPropsObject(props);
68
+ }
69
+ function isButtonProps(props) {
70
+ return isPropsObject(props);
71
+ }
72
+ function isPanelProps(props) {
73
+ return isPropsObject(props);
74
+ }
75
+ function isListProps(props) {
76
+ if (!isPropsObject(props)) return false;
77
+ return Array.isArray(props.items);
78
+ }
79
+ function isCardProps(props) {
80
+ return isPropsObject(props);
81
+ }
82
+
83
+ // src/components/helpers.ts
84
+ import { isValidElement } from "react";
85
+ var colorMap = {
86
+ // Basic colors (from ANSI)
87
+ black: ANSI.black,
88
+ red: ANSI.red,
89
+ green: ANSI.green,
90
+ yellow: ANSI.yellow,
91
+ blue: ANSI.blue,
92
+ magenta: ANSI.magenta,
93
+ cyan: ANSI.cyan,
94
+ white: ANSI.white,
95
+ // Semantic colors (from theme)
96
+ error: colors.error,
97
+ success: colors.success,
98
+ warning: colors.warning,
99
+ info: colors.info,
100
+ primary: colors.primary,
101
+ secondary: colors.secondary,
102
+ muted: colors.muted
103
+ };
104
+ var bgColorMap = {
105
+ black: ANSI.bgBlack,
106
+ red: ANSI.bgRed,
107
+ green: ANSI.bgGreen,
108
+ yellow: ANSI.bgYellow,
109
+ blue: ANSI.bgBlue,
110
+ magenta: ANSI.bgMagenta,
111
+ cyan: ANSI.bgCyan,
112
+ white: ANSI.bgWhite
113
+ };
114
+ function getColorCode(color) {
115
+ return colorMap[color] || ANSI.white;
116
+ }
117
+ function getBgColorCode(color) {
118
+ return bgColorMap[color] || "";
119
+ }
120
+ function extractChildren(children) {
121
+ if (typeof children === "string") return children;
122
+ if (typeof children === "number") return String(children);
123
+ if (Array.isArray(children)) {
124
+ return children.map(extractChildren).join("");
125
+ }
126
+ if (isValidElement(children)) {
127
+ const props = children.props;
128
+ return extractChildren(props.children);
129
+ }
130
+ return "";
131
+ }
132
+ var visibleLength2 = visibleLength;
133
+
134
+ // src/components/primitives/box.ts
135
+ import React, { isValidElement as isValidElement2 } from "react";
136
+ var renderElementFn = null;
137
+ function setRenderElement(fn) {
138
+ renderElementFn = fn;
139
+ }
140
+ function renderBox(props, context) {
141
+ const { children, border = "none", padding = 0, width, height, bg } = props;
142
+ const boxWidth = typeof width === "number" ? width : context.width;
143
+ const boxHeight = typeof height === "number" ? height : void 0;
144
+ let childLines = [];
145
+ if (children) {
146
+ if (isValidElement2(children) && renderElementFn) {
147
+ childLines = renderElementFn(children, { ...context, width: boxWidth - (border !== "none" ? 2 : 0) - padding * 2, parentWidth: boxWidth });
148
+ } else {
149
+ const text = extractChildren(children);
150
+ if (text) childLines = [text];
151
+ }
152
+ }
153
+ if (padding > 0) {
154
+ childLines = childLines.map((line) => " ".repeat(padding) + line + " ".repeat(padding));
155
+ }
156
+ const contentWidth = border !== "none" ? boxWidth - 2 : boxWidth;
157
+ if (border === "none") {
158
+ let result = childLines.length > 0 ? childLines : [""];
159
+ if (boxHeight) {
160
+ while (result.length < boxHeight) {
161
+ result.push("");
162
+ }
163
+ result = result.slice(0, boxHeight);
164
+ }
165
+ if (bg) {
166
+ const bgCode = getBgColorCode(bg);
167
+ result = result.map((line) => bgCode + line.padEnd(boxWidth) + ANSI.reset);
168
+ }
169
+ return result;
170
+ }
171
+ const chars = boxChars[border] || boxChars.single;
172
+ const lines = [];
173
+ lines.push(chars.topLeft + chars.horizontal.repeat(contentWidth) + chars.topRight);
174
+ const targetHeight = boxHeight ? boxHeight - 2 : childLines.length;
175
+ for (let i = 0; i < targetHeight; i++) {
176
+ const content = i < childLines.length ? childLines[i] : "";
177
+ const stripped = content.replace(/\x1b\[[\d;]*m/g, "");
178
+ const paddedContent = content + " ".repeat(Math.max(0, contentWidth - stripped.length));
179
+ lines.push(chars.vertical + paddedContent + chars.vertical);
180
+ }
181
+ lines.push(chars.bottomLeft + chars.horizontal.repeat(contentWidth) + chars.bottomRight);
182
+ if (bg) {
183
+ const bgCode = getBgColorCode(bg);
184
+ return lines.map((line) => bgCode + line + ANSI.reset);
185
+ }
186
+ return lines;
187
+ }
188
+ function Box(props) {
189
+ return React.createElement("box", props);
190
+ }
191
+
192
+ // src/components/primitives/text.ts
193
+ import React2 from "react";
194
+ function renderText(props, context) {
195
+ const { children, bold, italic, underline, dim, color, backgroundColor, wrap } = props;
196
+ let text = extractChildren(children);
197
+ const codes = [];
198
+ if (bold) codes.push(ANSI.bold);
199
+ if (italic) codes.push(ANSI.italic);
200
+ if (underline) codes.push(ANSI.underline);
201
+ if (dim) codes.push(ANSI.dim);
202
+ if (color) codes.push(getColorCode(color));
203
+ if (backgroundColor) codes.push(getBgColorCode(backgroundColor));
204
+ const maxWidth = context.parentWidth || context.width;
205
+ if (wrap === "truncate" && text.length > maxWidth) {
206
+ text = text.slice(0, maxWidth - 1) + "\u2026";
207
+ } else if (wrap === "wrap" && text.length > maxWidth) {
208
+ const lines = [];
209
+ let remaining = text;
210
+ while (remaining.length > 0) {
211
+ if (remaining.length <= maxWidth) {
212
+ lines.push(remaining);
213
+ break;
214
+ }
215
+ let breakPoint = maxWidth;
216
+ const lastSpace = remaining.lastIndexOf(" ", maxWidth);
217
+ if (lastSpace > 0) breakPoint = lastSpace;
218
+ lines.push(remaining.slice(0, breakPoint));
219
+ remaining = remaining.slice(breakPoint).trim();
220
+ }
221
+ return lines.map((line) => codes.join("") + line + ANSI.reset);
222
+ }
223
+ if (codes.length > 0) {
224
+ return [codes.join("") + text + ANSI.reset];
225
+ }
226
+ return [text];
227
+ }
228
+ function Text(props) {
229
+ return React2.createElement("text", props);
230
+ }
231
+
232
+ // src/components/primitives/input.ts
233
+ import React3 from "react";
234
+ function renderInput(props, context) {
235
+ const {
236
+ value = "",
237
+ placeholder = "",
238
+ label,
239
+ disabled,
240
+ focused = false,
241
+ type,
242
+ cursorPosition,
243
+ width
244
+ } = props;
245
+ const lines = [];
246
+ if (label) {
247
+ lines.push(label);
248
+ }
249
+ let displayValue;
250
+ if (type === "password" && value) {
251
+ displayValue = "*".repeat(value.length);
252
+ } else if (value) {
253
+ displayValue = value;
254
+ } else {
255
+ displayValue = "";
256
+ }
257
+ const inputWidth = width || context.width || 20;
258
+ const effectiveCursorPosition = cursorPosition !== void 0 ? Math.min(cursorPosition, displayValue.length) : displayValue.length;
259
+ let rendered;
260
+ if (disabled) {
261
+ const content = displayValue || placeholder;
262
+ rendered = ANSI.dim + content + ANSI.reset;
263
+ } else if (focused) {
264
+ if (displayValue.length === 0) {
265
+ rendered = ANSI.inverse + " " + ANSI.reset;
266
+ } else {
267
+ const before = displayValue.slice(0, effectiveCursorPosition);
268
+ const cursorChar = displayValue[effectiveCursorPosition] || " ";
269
+ const after = displayValue.slice(effectiveCursorPosition + 1);
270
+ rendered = ANSI.underline + before + ANSI.reset + ANSI.inverse + cursorChar + ANSI.reset + ANSI.underline + after + ANSI.reset;
271
+ }
272
+ } else {
273
+ if (displayValue.length === 0 && placeholder) {
274
+ rendered = ANSI.dim + placeholder + ANSI.reset;
275
+ } else {
276
+ rendered = displayValue;
277
+ }
278
+ }
279
+ const visible = visibleLength2(rendered);
280
+ const padding = " ".repeat(Math.max(0, inputWidth - visible));
281
+ rendered = rendered + padding;
282
+ lines.push(rendered);
283
+ return lines;
284
+ }
285
+ function Input(props) {
286
+ return React3.createElement("input", props);
287
+ }
288
+
289
+ // src/components/primitives/select.ts
290
+ import React4 from "react";
291
+ function renderSelect(props, _context) {
292
+ const {
293
+ options,
294
+ value,
295
+ label,
296
+ focused = false,
297
+ highlightedIndex = 0,
298
+ maxVisible = 5
299
+ } = props;
300
+ const lines = [];
301
+ if (label) {
302
+ lines.push(label);
303
+ }
304
+ const selectedIndex = options.findIndex((opt) => opt.value === value);
305
+ const selected = selectedIndex >= 0 ? options[selectedIndex] : null;
306
+ if (focused) {
307
+ let startIdx = 0;
308
+ let endIdx = options.length;
309
+ if (options.length > maxVisible) {
310
+ const halfVisible = Math.floor(maxVisible / 2);
311
+ startIdx = Math.max(0, highlightedIndex - halfVisible);
312
+ endIdx = Math.min(options.length, startIdx + maxVisible);
313
+ if (endIdx - startIdx < maxVisible) {
314
+ startIdx = Math.max(0, endIdx - maxVisible);
315
+ }
316
+ }
317
+ if (startIdx > 0) {
318
+ lines.push(ANSI.dim + " \u25B2 more" + ANSI.reset);
319
+ }
320
+ for (let idx = startIdx; idx < endIdx; idx++) {
321
+ const opt = options[idx];
322
+ const isSelected = opt.value === value;
323
+ const isHighlighted = idx === highlightedIndex;
324
+ const prefix = isSelected ? "\u25CF " : "\u25CB ";
325
+ let line;
326
+ if (opt.disabled) {
327
+ line = ANSI.dim + prefix + opt.label + ANSI.reset;
328
+ } else if (isHighlighted) {
329
+ line = ANSI.inverse + prefix + opt.label + ANSI.reset;
330
+ } else if (isSelected) {
331
+ line = ANSI.bold + prefix + opt.label + ANSI.reset;
332
+ } else {
333
+ line = ANSI.dim + prefix + opt.label + ANSI.reset;
334
+ }
335
+ lines.push(line);
336
+ }
337
+ if (endIdx < options.length) {
338
+ lines.push(ANSI.dim + " \u25BC more" + ANSI.reset);
339
+ }
340
+ } else {
341
+ const selectedLabel = selected ? selected.label : "";
342
+ const prefix = selected ? "\u25CF " : "\u25CB ";
343
+ lines.push(prefix + selectedLabel + " \u25BC");
344
+ }
345
+ return lines;
346
+ }
347
+ function Select(props) {
348
+ return React4.createElement("select", props);
349
+ }
350
+
351
+ // src/components/primitives/button.ts
352
+ import React5 from "react";
353
+ function renderButton(props, _context) {
354
+ const { children, hotkey, disabled, focused, variant = "primary" } = props;
355
+ const text = extractChildren(children);
356
+ let style = "";
357
+ let bgColor = "";
358
+ switch (variant) {
359
+ case "primary":
360
+ bgColor = "\x1B[44m";
361
+ style = ANSI.bold;
362
+ break;
363
+ case "secondary":
364
+ bgColor = "\x1B[100m";
365
+ break;
366
+ case "destructive":
367
+ bgColor = "\x1B[41m";
368
+ style = ANSI.bold;
369
+ break;
370
+ }
371
+ let buttonText = ` ${text} `;
372
+ if (hotkey) {
373
+ buttonText += `[${hotkey}]`;
374
+ }
375
+ if (disabled) {
376
+ return [ANSI.dim + `[ ${text} ]` + ANSI.reset];
377
+ }
378
+ if (focused) {
379
+ return [bgColor + style + "\x1B[37m" + buttonText + ANSI.reset];
380
+ }
381
+ return [bgColor + style + buttonText + ANSI.reset];
382
+ }
383
+ function Button(props) {
384
+ return React5.createElement("button", props);
385
+ }
386
+
387
+ // src/components/containers/panel.ts
388
+ import React6 from "react";
389
+ function renderPanel(props, context) {
390
+ const { children, title, border = "single", collapsed, padding = 0 } = props;
391
+ if (collapsed) {
392
+ return [ANSI.dim + "\u25B6 " + ANSI.reset + ANSI.bold + (title || "Panel") + ANSI.reset];
393
+ }
394
+ const lines = [];
395
+ const chars = border === "double" ? boxChars.double : border === "rounded" ? boxChars.rounded : boxChars.single;
396
+ const panelWidth = context.width;
397
+ if (title && border !== "none") {
398
+ const titleText = ` ${title} `;
399
+ const remainingWidth = panelWidth - titleText.length - 2;
400
+ const leftBorder = Math.floor(remainingWidth / 2);
401
+ const rightBorder = remainingWidth - leftBorder;
402
+ lines.push(chars.topLeft + chars.horizontal.repeat(leftBorder) + ANSI.bold + titleText + ANSI.reset + chars.horizontal.repeat(rightBorder) + chars.topRight);
403
+ } else if (border !== "none") {
404
+ lines.push(chars.topLeft + chars.horizontal.repeat(panelWidth - 2) + chars.topRight);
405
+ }
406
+ const content = extractChildren(children);
407
+ const contentLines = content.split("\n");
408
+ const paddingStr = " ".repeat(padding);
409
+ for (const line of contentLines) {
410
+ if (border !== "none") {
411
+ lines.push(chars.vertical + paddingStr + line.padEnd(panelWidth - 2 - padding * 2) + paddingStr + chars.vertical);
412
+ } else {
413
+ lines.push(paddingStr + line);
414
+ }
415
+ }
416
+ if (border !== "none") {
417
+ lines.push(chars.bottomLeft + chars.horizontal.repeat(panelWidth - 2) + chars.bottomRight);
418
+ }
419
+ return lines;
420
+ }
421
+ function Panel(props) {
422
+ return React6.createElement("panel", props);
423
+ }
424
+
425
+ // src/components/containers/card.ts
426
+ import React7 from "react";
427
+ function renderCard(props, context) {
428
+ const { children, title, border = "single" } = props;
429
+ const lines = [];
430
+ const chars = border === "double" ? boxChars.double : boxChars.single;
431
+ const cardWidth = Math.min(context.width, 60);
432
+ if (border !== "none") {
433
+ lines.push(chars.topLeft + chars.horizontal.repeat(cardWidth - 2) + chars.topRight);
434
+ }
435
+ if (title) {
436
+ const titleLine = " " + ANSI.bold + title + ANSI.reset;
437
+ if (border !== "none") {
438
+ lines.push(chars.vertical + titleLine.padEnd(cardWidth - 2 + ANSI.bold.length + ANSI.reset.length) + chars.vertical);
439
+ lines.push(chars.teeLeft + chars.horizontal.repeat(cardWidth - 2) + chars.teeRight);
440
+ } else {
441
+ lines.push(ANSI.bold + title + ANSI.reset);
442
+ }
443
+ }
444
+ const content = extractChildren(children);
445
+ const contentLines = content.split("\n");
446
+ for (const line of contentLines) {
447
+ if (border !== "none") {
448
+ lines.push(chars.vertical + " " + line.padEnd(cardWidth - 4) + " " + chars.vertical);
449
+ } else {
450
+ lines.push(line);
451
+ }
452
+ }
453
+ if (border !== "none") {
454
+ lines.push(chars.bottomLeft + chars.horizontal.repeat(cardWidth - 2) + chars.bottomRight);
455
+ }
456
+ return lines;
457
+ }
458
+ function Card(props) {
459
+ return React7.createElement("card", props);
460
+ }
461
+
462
+ // src/components/containers/dialog.ts
463
+ import React8 from "react";
464
+ function renderDialog(props, context) {
465
+ const { open, title, children } = props;
466
+ if (!open) {
467
+ return [""];
468
+ }
469
+ const dialogWidth = 40;
470
+ const padding = Math.floor((context.width - dialogWidth) / 2);
471
+ const paddingStr = " ".repeat(Math.max(0, padding));
472
+ const lines = [];
473
+ const chars = boxChars.single;
474
+ lines.push(paddingStr + ANSI.cyan + chars.topLeft + chars.horizontal.repeat(dialogWidth - 2) + chars.topRight + ANSI.reset);
475
+ if (title) {
476
+ const titlePadded = (" " + title).padEnd(dialogWidth - 2);
477
+ lines.push(paddingStr + ANSI.cyan + chars.vertical + ANSI.reset + ANSI.bold + titlePadded + ANSI.reset + ANSI.cyan + chars.vertical + ANSI.reset);
478
+ lines.push(paddingStr + ANSI.cyan + chars.teeLeft + chars.horizontal.repeat(dialogWidth - 2) + chars.teeRight + ANSI.reset);
479
+ }
480
+ const content = extractChildren(children);
481
+ const contentLines = content.split("\n");
482
+ for (const contentLine of contentLines) {
483
+ const paddedContent = (" " + contentLine).padEnd(dialogWidth - 2);
484
+ lines.push(paddingStr + ANSI.cyan + chars.vertical + ANSI.reset + paddedContent + ANSI.cyan + chars.vertical + ANSI.reset);
485
+ }
486
+ lines.push(paddingStr + ANSI.cyan + chars.bottomLeft + chars.horizontal.repeat(dialogWidth - 2) + chars.bottomRight + ANSI.reset);
487
+ return lines;
488
+ }
489
+ function Dialog(props) {
490
+ return React8.createElement("dialog", props);
491
+ }
492
+
493
+ // src/components/layout/sidebar.ts
494
+ import React9, { Children, isValidElement as isValidElement3 } from "react";
495
+ function renderSidebarItem(props, _context) {
496
+ const { label, icon, active, _collapsed } = props;
497
+ if (_collapsed) {
498
+ return [icon || ""];
499
+ }
500
+ let line = "";
501
+ if (active) {
502
+ line = "\u25B6 ";
503
+ }
504
+ if (icon) {
505
+ line += icon + " ";
506
+ }
507
+ line += label;
508
+ if (active) {
509
+ line = "\x1B[44m" + line + ANSI.reset;
510
+ }
511
+ return [line];
512
+ }
513
+ function renderSidebar(props, context) {
514
+ const { children, width = 20, collapsed } = props;
515
+ const lines = [];
516
+ const childArray = Children.toArray(children);
517
+ for (const child of childArray) {
518
+ if (isValidElement3(child)) {
519
+ const childProps = child.props;
520
+ const modifiedProps = { ...childProps, _collapsed: collapsed };
521
+ const childLines = renderSidebarItem(modifiedProps, { ...context, width });
522
+ lines.push(...childLines);
523
+ }
524
+ }
525
+ return lines.map((line) => {
526
+ const stripped = line.replace(/\x1b\[[\d;]*m/g, "");
527
+ if (stripped.length > width) {
528
+ return line.slice(0, width);
529
+ }
530
+ return line;
531
+ });
532
+ }
533
+ function SidebarLayout(props) {
534
+ return React9.createElement("sidebar", props);
535
+ }
536
+ function SidebarItem(props) {
537
+ return React9.createElement("sidebar-item", props);
538
+ }
539
+
540
+ // src/components/layout/breadcrumb.ts
541
+ import React10 from "react";
542
+ function renderBreadcrumb(props, _context) {
543
+ const { items, separator = "/" } = props;
544
+ const parts = [];
545
+ items.forEach((item, idx) => {
546
+ const isLast = idx === items.length - 1;
547
+ if (isLast) {
548
+ parts.push(ANSI.bold + item.label + ANSI.reset);
549
+ } else {
550
+ parts.push(ANSI.dim + item.label + ANSI.reset);
551
+ }
552
+ });
553
+ return [parts.join(` ${separator} `)];
554
+ }
555
+ function Breadcrumb(props) {
556
+ return React10.createElement("breadcrumb", props);
557
+ }
558
+
559
+ // src/components/layout/list.ts
560
+ import React11 from "react";
561
+ function renderList(props, _context) {
562
+ const { items, selectedIndex, bullet = "\u2022", numbered = false } = props;
563
+ return items.map((item, idx) => {
564
+ const text = typeof item === "string" ? item : extractChildren(item);
565
+ const prefix = numbered ? `${idx + 1}. ` : `${bullet} `;
566
+ const isSelected = selectedIndex === idx;
567
+ if (isSelected) {
568
+ return ANSI.cyan + "\x1B[44m" + prefix + text + ANSI.reset;
569
+ }
570
+ return prefix + text;
571
+ });
572
+ }
573
+ function List(props) {
574
+ return React11.createElement("list", props);
575
+ }
576
+
577
+ // src/components/layout/table.ts
578
+ import React12 from "react";
579
+ function renderTable(props, _context) {
580
+ const { data, columns, selectedIndex } = props;
581
+ const lines = [];
582
+ const colWidths = columns.map((col) => {
583
+ if (col.width) return col.width;
584
+ let maxWidth = col.header.length;
585
+ for (const row of data) {
586
+ const value = String(row[col.key] ?? "");
587
+ maxWidth = Math.max(maxWidth, value.length);
588
+ }
589
+ return maxWidth + 2;
590
+ });
591
+ const headerParts = columns.map((col, idx) => {
592
+ const width = colWidths[idx];
593
+ return col.header.padEnd(width);
594
+ });
595
+ lines.push("\u2502" + headerParts.join("\u2502") + "\u2502");
596
+ const separatorParts = colWidths.map((w) => "\u2500".repeat(w));
597
+ lines.push("\u251C" + separatorParts.join("\u253C") + "\u2524");
598
+ data.forEach((row, rowIndex) => {
599
+ const rowParts = columns.map((col, idx) => {
600
+ const value = String(row[col.key] ?? "");
601
+ const width = colWidths[idx];
602
+ if (col.align === "right") {
603
+ return value.padStart(width);
604
+ }
605
+ return value.padEnd(width);
606
+ });
607
+ let rowLine = "\u2502" + rowParts.join("\u2502") + "\u2502";
608
+ if (selectedIndex === rowIndex) {
609
+ rowLine = "\x1B[44m" + rowLine + ANSI.reset;
610
+ }
611
+ lines.push(rowLine);
612
+ });
613
+ return lines;
614
+ }
615
+ function Table(props) {
616
+ return React12.createElement("table", props);
617
+ }
618
+
619
+ // src/components/feedback/badge.ts
620
+ import React13 from "react";
621
+ function renderBadge(props, _context) {
622
+ const { children, variant = "default" } = props;
623
+ const text = extractChildren(children);
624
+ let color;
625
+ switch (variant) {
626
+ case "success":
627
+ color = "\x1B[32m";
628
+ break;
629
+ case "warning":
630
+ color = "\x1B[33m";
631
+ break;
632
+ case "error":
633
+ color = "\x1B[31m";
634
+ break;
635
+ case "info":
636
+ color = "\x1B[34m";
637
+ break;
638
+ default:
639
+ color = ANSI.dim;
640
+ }
641
+ return [color + "[" + text + "]" + ANSI.reset];
642
+ }
643
+ function Badge(props) {
644
+ return React13.createElement("badge", props);
645
+ }
646
+
647
+ // src/components/feedback/spinner.ts
648
+ import React14 from "react";
649
+ var spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
650
+ function renderSpinner(props, _context) {
651
+ const { label } = props;
652
+ const frame = spinnerFrames[0];
653
+ const text = label ? `${frame} ${label}` : frame;
654
+ return [ANSI.cyan + text + ANSI.reset];
655
+ }
656
+ function Spinner(props) {
657
+ return React14.createElement("spinner", props);
658
+ }
659
+
660
+ // src/components/render.ts
661
+ function renderElement(element, context) {
662
+ const props = element.props;
663
+ const type = element.type;
664
+ if (typeof type === "function") {
665
+ const result = type(props);
666
+ return renderElement(result, context);
667
+ }
668
+ if (isTerminalComponentType(type)) {
669
+ switch (type) {
670
+ case "box":
671
+ if (isBoxProps(props)) {
672
+ return renderBox(props, context);
673
+ }
674
+ break;
675
+ case "text":
676
+ if (isTextProps(props)) {
677
+ return renderText(props, context);
678
+ }
679
+ break;
680
+ case "table":
681
+ if (isTableProps(props)) {
682
+ return renderTable(props, context);
683
+ }
684
+ break;
685
+ case "input":
686
+ if (isInputProps(props)) {
687
+ return renderInput(props, context);
688
+ }
689
+ break;
690
+ case "select":
691
+ if (isSelectProps(props)) {
692
+ return renderSelect(props, context);
693
+ }
694
+ break;
695
+ case "sidebar":
696
+ if (isSidebarProps(props)) {
697
+ return renderSidebar(props, context);
698
+ }
699
+ break;
700
+ case "sidebar-item":
701
+ if (isSidebarItemProps(props)) {
702
+ return renderSidebarItem(props, context);
703
+ }
704
+ break;
705
+ case "breadcrumb":
706
+ if (isBreadcrumbProps(props)) {
707
+ return renderBreadcrumb(props, context);
708
+ }
709
+ break;
710
+ case "badge":
711
+ if (isBadgeProps(props)) {
712
+ return renderBadge(props, context);
713
+ }
714
+ break;
715
+ case "dialog":
716
+ if (isDialogProps(props)) {
717
+ return renderDialog(props, context);
718
+ }
719
+ break;
720
+ case "spinner":
721
+ if (isSpinnerProps(props)) {
722
+ return renderSpinner(props, context);
723
+ }
724
+ break;
725
+ case "button":
726
+ if (isButtonProps(props)) {
727
+ return renderButton(props, context);
728
+ }
729
+ break;
730
+ case "panel":
731
+ if (isPanelProps(props)) {
732
+ return renderPanel(props, context);
733
+ }
734
+ break;
735
+ case "list":
736
+ if (isListProps(props)) {
737
+ return renderList(props, context);
738
+ }
739
+ break;
740
+ case "card":
741
+ if (isCardProps(props)) {
742
+ return renderCard(props, context);
743
+ }
744
+ break;
745
+ }
746
+ }
747
+ if (isPropsObject(props)) {
748
+ const childText = extractChildren(props.children);
749
+ return childText ? [childText] : [];
750
+ }
751
+ return [];
752
+ }
753
+ setRenderElement(renderElement);
754
+ function renderComponent(element) {
755
+ const context = { width: 80 };
756
+ return renderElement(element, context);
757
+ }
758
+
759
+ // src/components/templates/site.ts
760
+ import React15 from "react";
761
+ function Site(props) {
762
+ return React15.createElement("site", props);
763
+ }
764
+ function Header(props) {
765
+ return React15.createElement("header", props);
766
+ }
767
+ function Footer(props) {
768
+ return React15.createElement("footer", props);
769
+ }
770
+ function Hero(props) {
771
+ return React15.createElement("hero", props);
772
+ }
773
+ function Features(props) {
774
+ return React15.createElement("features", props);
775
+ }
776
+ function Pricing(props) {
777
+ return React15.createElement("pricing", props);
778
+ }
779
+ function FAQ(props) {
780
+ return React15.createElement("faq", props);
781
+ }
782
+ function LandingPage(props) {
783
+ return React15.createElement("landing-page", props);
784
+ }
785
+ function Page(props) {
786
+ return React15.createElement("page", props);
787
+ }
788
+
789
+ // src/components/templates/app.ts
790
+ import React16 from "react";
791
+ function App(props) {
792
+ return React16.createElement("app", props);
793
+ }
794
+ function Shell(props) {
795
+ return React16.createElement("shell", props);
796
+ }
797
+ function Sidebar(props) {
798
+ return React16.createElement("sidebar", props);
799
+ }
800
+ function AppHeader(props) {
801
+ return React16.createElement("app-header", props);
802
+ }
803
+ function Dashboard(props) {
804
+ return React16.createElement("dashboard", props);
805
+ }
806
+ function Settings(props) {
807
+ return React16.createElement("settings", props);
808
+ }
809
+
810
+ export {
811
+ COMPONENT_TYPES,
812
+ isTerminalComponentType,
813
+ isPropsObject,
814
+ isBoxProps,
815
+ isTextProps,
816
+ isTableProps,
817
+ isInputProps,
818
+ isSelectProps,
819
+ isSidebarProps,
820
+ isSidebarItemProps,
821
+ isBreadcrumbProps,
822
+ isBadgeProps,
823
+ isDialogProps,
824
+ isSpinnerProps,
825
+ isButtonProps,
826
+ isPanelProps,
827
+ isListProps,
828
+ isCardProps,
829
+ colorMap,
830
+ bgColorMap,
831
+ getColorCode,
832
+ getBgColorCode,
833
+ extractChildren,
834
+ renderBox,
835
+ Box,
836
+ renderText,
837
+ Text,
838
+ renderInput,
839
+ Input,
840
+ renderSelect,
841
+ Select,
842
+ renderButton,
843
+ Button,
844
+ renderPanel,
845
+ Panel,
846
+ renderCard,
847
+ Card,
848
+ renderDialog,
849
+ Dialog,
850
+ renderSidebarItem,
851
+ renderSidebar,
852
+ SidebarLayout,
853
+ SidebarItem,
854
+ renderBreadcrumb,
855
+ Breadcrumb,
856
+ renderList,
857
+ List,
858
+ renderTable,
859
+ Table,
860
+ renderBadge,
861
+ Badge,
862
+ spinnerFrames,
863
+ renderSpinner,
864
+ Spinner,
865
+ renderElement,
866
+ renderComponent,
867
+ Site,
868
+ Header,
869
+ Footer,
870
+ Hero,
871
+ Features,
872
+ Pricing,
873
+ FAQ,
874
+ LandingPage,
875
+ Page,
876
+ App,
877
+ Shell,
878
+ Sidebar,
879
+ AppHeader,
880
+ Dashboard,
881
+ Settings
882
+ };