@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.
- package/README.md +571 -0
- package/dist/ansi-css-Sk5mWtdK.d.ts +119 -0
- package/dist/ansi-css-V6JIHGsM.d.ts +119 -0
- package/dist/ansi-css-_3eSEU9d.d.ts +119 -0
- package/dist/chunk-3EFDH7PK.js +5235 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-3X5IR6WE.js +884 -0
- package/dist/chunk-4FV5ZDCE.js +5236 -0
- package/dist/chunk-4OVMSF2J.js +243 -0
- package/dist/chunk-63FEETIS.js +4048 -0
- package/dist/chunk-B43KP7XJ.js +884 -0
- package/dist/chunk-BMTJXWUV.js +655 -0
- package/dist/chunk-C3SVH4N7.js +882 -0
- package/dist/chunk-EVWR7Y47.js +874 -0
- package/dist/chunk-F6A5VWUC.js +1285 -0
- package/dist/chunk-FD7KW7GE.js +882 -0
- package/dist/chunk-GBQ6UD6I.js +655 -0
- package/dist/chunk-GMDD3M6U.js +5227 -0
- package/dist/chunk-JBHRXOXM.js +1058 -0
- package/dist/chunk-JFOO3EYO.js +1182 -0
- package/dist/chunk-JQ5H3WXL.js +1291 -0
- package/dist/chunk-JQD5NASE.js +234 -0
- package/dist/chunk-KRHJP5R7.js +592 -0
- package/dist/chunk-KWF6WVJE.js +962 -0
- package/dist/chunk-LHYQVN3H.js +1038 -0
- package/dist/chunk-M3TLQLGC.js +1032 -0
- package/dist/chunk-MVW4Q5OP.js +240 -0
- package/dist/chunk-NXCZSWLU.js +1294 -0
- package/dist/chunk-O25TNRO6.js +607 -0
- package/dist/chunk-PNECDA2I.js +884 -0
- package/dist/chunk-QIHWRLJR.js +962 -0
- package/dist/chunk-QW5YMQ7K.js +882 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RP2MVQLR.js +962 -0
- package/dist/chunk-TP6RXGXA.js +1087 -0
- package/dist/chunk-TQQSTITZ.js +655 -0
- package/dist/chunk-X24GWXQV.js +1281 -0
- package/dist/components/index.d.ts +802 -0
- package/dist/components/index.js +149 -0
- package/dist/data/index.d.ts +2554 -0
- package/dist/data/index.js +51 -0
- package/dist/forms/index.d.ts +1596 -0
- package/dist/forms/index.js +464 -0
- package/dist/index-CQRFZntR.d.ts +867 -0
- package/dist/index.d.ts +579 -0
- package/dist/index.js +786 -0
- package/dist/interactive-D0JkWosD.d.ts +217 -0
- package/dist/keyboard/index.d.ts +2 -0
- package/dist/keyboard/index.js +43 -0
- package/dist/renderers/index.d.ts +546 -0
- package/dist/renderers/index.js +2157 -0
- package/dist/storybook/index.d.ts +396 -0
- package/dist/storybook/index.js +641 -0
- package/dist/theme/index.d.ts +1339 -0
- package/dist/theme/index.js +123 -0
- package/dist/types-Bxu5PAgA.d.ts +710 -0
- package/dist/types-CIlop5Ji.d.ts +701 -0
- package/dist/types-Ca8p_p5X.d.ts +710 -0
- package/package.json +90 -0
- package/src/__tests__/components/data/card.test.ts +458 -0
- package/src/__tests__/components/data/list.test.ts +473 -0
- package/src/__tests__/components/data/metrics.test.ts +541 -0
- package/src/__tests__/components/data/table.test.ts +448 -0
- package/src/__tests__/components/input/field.test.ts +555 -0
- package/src/__tests__/components/input/form.test.ts +870 -0
- package/src/__tests__/components/input/search.test.ts +1238 -0
- package/src/__tests__/components/input/select.test.ts +658 -0
- package/src/__tests__/components/navigation/breadcrumb.test.ts +923 -0
- package/src/__tests__/components/navigation/command-palette.test.ts +1095 -0
- package/src/__tests__/components/navigation/sidebar.test.ts +1018 -0
- package/src/__tests__/components/navigation/tabs.test.ts +995 -0
- package/src/__tests__/components.test.tsx +1197 -0
- package/src/__tests__/core/compiler.test.ts +986 -0
- package/src/__tests__/core/parser.test.ts +785 -0
- package/src/__tests__/core/tier-switcher.test.ts +1103 -0
- package/src/__tests__/core/types.test.ts +1398 -0
- package/src/__tests__/data/collections.test.ts +1337 -0
- package/src/__tests__/data/db.test.ts +1265 -0
- package/src/__tests__/data/reactive.test.ts +1010 -0
- package/src/__tests__/data/sync.test.ts +1614 -0
- package/src/__tests__/errors.test.ts +660 -0
- package/src/__tests__/forms/integration.test.ts +444 -0
- package/src/__tests__/integration.test.ts +905 -0
- package/src/__tests__/keyboard.test.ts +1791 -0
- package/src/__tests__/renderer.test.ts +489 -0
- package/src/__tests__/renderers/ansi-css.test.ts +948 -0
- package/src/__tests__/renderers/ansi.test.ts +1366 -0
- package/src/__tests__/renderers/ascii.test.ts +1360 -0
- package/src/__tests__/renderers/interactive.test.ts +2353 -0
- package/src/__tests__/renderers/markdown.test.ts +1483 -0
- package/src/__tests__/renderers/text.test.ts +1369 -0
- package/src/__tests__/renderers/unicode.test.ts +1307 -0
- package/src/__tests__/theme.test.ts +639 -0
- package/src/__tests__/utils/assertions.ts +685 -0
- package/src/__tests__/utils/index.ts +115 -0
- package/src/__tests__/utils/test-renderer.ts +381 -0
- package/src/__tests__/utils/utils.test.ts +560 -0
- package/src/components/containers/card.ts +56 -0
- package/src/components/containers/dialog.ts +53 -0
- package/src/components/containers/index.ts +9 -0
- package/src/components/containers/panel.ts +59 -0
- package/src/components/feedback/badge.ts +40 -0
- package/src/components/feedback/index.ts +8 -0
- package/src/components/feedback/spinner.ts +23 -0
- package/src/components/helpers.ts +81 -0
- package/src/components/index.ts +153 -0
- package/src/components/layout/breadcrumb.ts +31 -0
- package/src/components/layout/index.ts +10 -0
- package/src/components/layout/list.ts +29 -0
- package/src/components/layout/sidebar.ts +79 -0
- package/src/components/layout/table.ts +62 -0
- package/src/components/primitives/box.ts +95 -0
- package/src/components/primitives/button.ts +54 -0
- package/src/components/primitives/index.ts +11 -0
- package/src/components/primitives/input.ts +88 -0
- package/src/components/primitives/select.ts +97 -0
- package/src/components/primitives/text.ts +60 -0
- package/src/components/render.ts +155 -0
- package/src/components/templates/app.ts +43 -0
- package/src/components/templates/index.ts +8 -0
- package/src/components/templates/site.ts +54 -0
- package/src/components/types.ts +777 -0
- package/src/core/compiler.ts +718 -0
- package/src/core/parser.ts +127 -0
- package/src/core/tier-switcher.ts +607 -0
- package/src/core/types.ts +672 -0
- package/src/data/collection.ts +316 -0
- package/src/data/collections.ts +50 -0
- package/src/data/context.tsx +174 -0
- package/src/data/db.ts +127 -0
- package/src/data/hooks.ts +532 -0
- package/src/data/index.ts +138 -0
- package/src/data/reactive.ts +1225 -0
- package/src/data/saas-collections.ts +375 -0
- package/src/data/sync.ts +1213 -0
- package/src/data/types.ts +660 -0
- package/src/forms/converters.ts +512 -0
- package/src/forms/index.ts +133 -0
- package/src/forms/schemas.ts +403 -0
- package/src/forms/types.ts +476 -0
- package/src/index.ts +542 -0
- package/src/keyboard/focus.ts +748 -0
- package/src/keyboard/index.ts +96 -0
- package/src/keyboard/integration.ts +371 -0
- package/src/keyboard/manager.ts +377 -0
- package/src/keyboard/presets.ts +90 -0
- package/src/renderers/ansi-css.ts +576 -0
- package/src/renderers/ansi.ts +802 -0
- package/src/renderers/ascii.ts +680 -0
- package/src/renderers/breadcrumb.ts +480 -0
- package/src/renderers/command-palette.ts +802 -0
- package/src/renderers/components/field.ts +210 -0
- package/src/renderers/components/form.ts +327 -0
- package/src/renderers/components/index.ts +21 -0
- package/src/renderers/components/search.ts +449 -0
- package/src/renderers/components/select.ts +222 -0
- package/src/renderers/index.ts +101 -0
- package/src/renderers/interactive/component-handlers.ts +622 -0
- package/src/renderers/interactive/cursor-manager.ts +147 -0
- package/src/renderers/interactive/focus-manager.ts +279 -0
- package/src/renderers/interactive/index.ts +661 -0
- package/src/renderers/interactive/input-handler.ts +164 -0
- package/src/renderers/interactive/keyboard-handler.ts +212 -0
- package/src/renderers/interactive/mouse-handler.ts +167 -0
- package/src/renderers/interactive/state-manager.ts +109 -0
- package/src/renderers/interactive/types.ts +338 -0
- package/src/renderers/interactive-string.ts +299 -0
- package/src/renderers/interactive.ts +59 -0
- package/src/renderers/markdown.ts +950 -0
- package/src/renderers/sidebar.ts +549 -0
- package/src/renderers/tabs.ts +682 -0
- package/src/renderers/text.ts +791 -0
- package/src/renderers/unicode.ts +917 -0
- package/src/renderers/utils.ts +942 -0
- package/src/router/adapters.ts +383 -0
- package/src/router/types.ts +140 -0
- package/src/router/utils.ts +452 -0
- package/src/schemas.ts +205 -0
- package/src/storybook/index.ts +91 -0
- package/src/storybook/interactive-decorator.tsx +659 -0
- package/src/storybook/keyboard-simulator.ts +501 -0
- package/src/theme/ansi-codes.ts +80 -0
- package/src/theme/box-drawing.ts +132 -0
- package/src/theme/color-convert.ts +254 -0
- package/src/theme/color-support.ts +321 -0
- package/src/theme/index.ts +134 -0
- package/src/theme/strip-ansi.ts +50 -0
- package/src/theme/tailwind-map.ts +469 -0
- package/src/theme/text-styles.ts +206 -0
- package/src/theme/theme-system.ts +568 -0
- package/src/types.ts +103 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,786 @@
|
|
|
1
|
+
import {
|
|
2
|
+
App,
|
|
3
|
+
AppHeader,
|
|
4
|
+
Badge,
|
|
5
|
+
Box,
|
|
6
|
+
Breadcrumb,
|
|
7
|
+
Button,
|
|
8
|
+
COMPONENT_TYPES,
|
|
9
|
+
Card,
|
|
10
|
+
Dashboard,
|
|
11
|
+
Dialog,
|
|
12
|
+
FAQ,
|
|
13
|
+
Features,
|
|
14
|
+
Footer,
|
|
15
|
+
Header,
|
|
16
|
+
Hero,
|
|
17
|
+
Input,
|
|
18
|
+
LandingPage,
|
|
19
|
+
List,
|
|
20
|
+
Page,
|
|
21
|
+
Panel,
|
|
22
|
+
Pricing,
|
|
23
|
+
Select,
|
|
24
|
+
Settings,
|
|
25
|
+
Shell,
|
|
26
|
+
Sidebar,
|
|
27
|
+
SidebarItem,
|
|
28
|
+
SidebarLayout,
|
|
29
|
+
Site,
|
|
30
|
+
Spinner,
|
|
31
|
+
Table,
|
|
32
|
+
Text,
|
|
33
|
+
bgColorMap,
|
|
34
|
+
colorMap,
|
|
35
|
+
extractChildren,
|
|
36
|
+
getBgColorCode,
|
|
37
|
+
getColorCode,
|
|
38
|
+
isBadgeProps,
|
|
39
|
+
isBoxProps,
|
|
40
|
+
isBreadcrumbProps,
|
|
41
|
+
isButtonProps,
|
|
42
|
+
isCardProps,
|
|
43
|
+
isDialogProps,
|
|
44
|
+
isInputProps,
|
|
45
|
+
isListProps,
|
|
46
|
+
isPanelProps,
|
|
47
|
+
isPropsObject,
|
|
48
|
+
isSelectProps,
|
|
49
|
+
isSidebarItemProps,
|
|
50
|
+
isSidebarProps,
|
|
51
|
+
isSpinnerProps,
|
|
52
|
+
isTableProps,
|
|
53
|
+
isTerminalComponentType,
|
|
54
|
+
isTextProps,
|
|
55
|
+
renderBadge,
|
|
56
|
+
renderBox,
|
|
57
|
+
renderBreadcrumb,
|
|
58
|
+
renderButton,
|
|
59
|
+
renderCard,
|
|
60
|
+
renderComponent,
|
|
61
|
+
renderDialog,
|
|
62
|
+
renderElement,
|
|
63
|
+
renderInput,
|
|
64
|
+
renderList,
|
|
65
|
+
renderPanel,
|
|
66
|
+
renderSelect,
|
|
67
|
+
renderSidebar,
|
|
68
|
+
renderSidebarItem,
|
|
69
|
+
renderSpinner,
|
|
70
|
+
renderTable,
|
|
71
|
+
spinnerFrames
|
|
72
|
+
} from "./chunk-B43KP7XJ.js";
|
|
73
|
+
import {
|
|
74
|
+
APIKeySchema,
|
|
75
|
+
APIKeysCollection,
|
|
76
|
+
DBProvider,
|
|
77
|
+
TeamSchema,
|
|
78
|
+
TeamsCollection,
|
|
79
|
+
UsageCollection,
|
|
80
|
+
UsageSchema,
|
|
81
|
+
UserRoleSchema,
|
|
82
|
+
UserSchema,
|
|
83
|
+
UsersCollection,
|
|
84
|
+
WebhookSchema,
|
|
85
|
+
WebhooksCollection,
|
|
86
|
+
createCollection,
|
|
87
|
+
createDB,
|
|
88
|
+
createDOSync,
|
|
89
|
+
useDBContext,
|
|
90
|
+
useMutation,
|
|
91
|
+
useQuery,
|
|
92
|
+
useReactiveCard,
|
|
93
|
+
useReactiveData,
|
|
94
|
+
useReactiveList,
|
|
95
|
+
useReactiveMetrics,
|
|
96
|
+
useReactiveTable
|
|
97
|
+
} from "./chunk-JQ5H3WXL.js";
|
|
98
|
+
import {
|
|
99
|
+
ARROW_BINDINGS,
|
|
100
|
+
COMMON_BINDINGS,
|
|
101
|
+
EMACS_BINDINGS,
|
|
102
|
+
FocusContext,
|
|
103
|
+
FocusProvider,
|
|
104
|
+
KEY,
|
|
105
|
+
VIM_BINDINGS,
|
|
106
|
+
__resetFocusIdCounter,
|
|
107
|
+
attachKeyboardManager,
|
|
108
|
+
createFocusId,
|
|
109
|
+
createKeyboardManager,
|
|
110
|
+
createOpenTUIKeyHandler,
|
|
111
|
+
isFocusId,
|
|
112
|
+
keyToBindingString,
|
|
113
|
+
matchKey,
|
|
114
|
+
normalizeOpenTUIKey,
|
|
115
|
+
normalizeReadlineKey,
|
|
116
|
+
useFocus,
|
|
117
|
+
useFocusManager,
|
|
118
|
+
useKeyboard,
|
|
119
|
+
useNavigableGrid,
|
|
120
|
+
useNavigableList
|
|
121
|
+
} from "./chunk-GBQ6UD6I.js";
|
|
122
|
+
import {
|
|
123
|
+
ansiToCSS,
|
|
124
|
+
ansiToHTML,
|
|
125
|
+
parseAnsiToSpans,
|
|
126
|
+
renderText,
|
|
127
|
+
spanToInlineStyle
|
|
128
|
+
} from "./chunk-F6A5VWUC.js";
|
|
129
|
+
import {
|
|
130
|
+
TAILWIND_COLORS,
|
|
131
|
+
adaptColor,
|
|
132
|
+
applyThemeStyles,
|
|
133
|
+
bg,
|
|
134
|
+
bold,
|
|
135
|
+
boxChars,
|
|
136
|
+
colors,
|
|
137
|
+
composeThemes,
|
|
138
|
+
createTerminalTheme,
|
|
139
|
+
createTheme,
|
|
140
|
+
createThemeVariant,
|
|
141
|
+
cssVarToAnsi,
|
|
142
|
+
darkTheme,
|
|
143
|
+
defaultTheme,
|
|
144
|
+
degradeColor,
|
|
145
|
+
detectColorScheme,
|
|
146
|
+
detectColorSupport,
|
|
147
|
+
dim,
|
|
148
|
+
drawBox,
|
|
149
|
+
extendTheme,
|
|
150
|
+
fg,
|
|
151
|
+
getThemeColor,
|
|
152
|
+
highContrastTheme,
|
|
153
|
+
italic,
|
|
154
|
+
lightTheme,
|
|
155
|
+
strikethrough,
|
|
156
|
+
stripAnsi,
|
|
157
|
+
style,
|
|
158
|
+
styled,
|
|
159
|
+
tailwindToAnsi,
|
|
160
|
+
tailwindToTerminal,
|
|
161
|
+
themePresets,
|
|
162
|
+
themeTokens,
|
|
163
|
+
underline,
|
|
164
|
+
visibleLength
|
|
165
|
+
} from "./chunk-KWF6WVJE.js";
|
|
166
|
+
import {
|
|
167
|
+
ANSI,
|
|
168
|
+
Ansi256CodeSchema,
|
|
169
|
+
AnsiEscapeSchema,
|
|
170
|
+
ColorSupportSchema,
|
|
171
|
+
CreateTerminalThemeOptionsSchema,
|
|
172
|
+
CreateThemeInputSchema,
|
|
173
|
+
HexColorSchema,
|
|
174
|
+
LegacyTerminalThemeSchema,
|
|
175
|
+
LegacyTerminalThemeWithExtrasSchema,
|
|
176
|
+
RgbColorSchema,
|
|
177
|
+
RgbComponentSchema,
|
|
178
|
+
RgbToAnsiOptionsSchema,
|
|
179
|
+
TerminalThemeColorsSchema,
|
|
180
|
+
ThemeModeSchema,
|
|
181
|
+
ansi256,
|
|
182
|
+
ansi256Bg,
|
|
183
|
+
hex,
|
|
184
|
+
hexBg,
|
|
185
|
+
hexToAnsi,
|
|
186
|
+
hexToRgb,
|
|
187
|
+
rgb,
|
|
188
|
+
rgbBg,
|
|
189
|
+
rgbToAnsi
|
|
190
|
+
} from "./chunk-MVW4Q5OP.js";
|
|
191
|
+
import "./chunk-3RG5ZIWI.js";
|
|
192
|
+
|
|
193
|
+
// src/index.ts
|
|
194
|
+
import React2, { createContext, useContext, useState, useEffect } from "react";
|
|
195
|
+
|
|
196
|
+
// src/core/compiler.ts
|
|
197
|
+
import React from "react";
|
|
198
|
+
var UNKNOWN_COMPONENT_TYPE = "Unknown";
|
|
199
|
+
function resolveTypeName(type) {
|
|
200
|
+
if (typeof type === "string") {
|
|
201
|
+
return type;
|
|
202
|
+
}
|
|
203
|
+
return type.name || UNKNOWN_COMPONENT_TYPE;
|
|
204
|
+
}
|
|
205
|
+
function isFilterableChild(value) {
|
|
206
|
+
return value === null || value === void 0 || typeof value === "boolean";
|
|
207
|
+
}
|
|
208
|
+
function compileJSX(element) {
|
|
209
|
+
const { type, props, key } = element;
|
|
210
|
+
const typeName = resolveTypeName(type);
|
|
211
|
+
const { children: rawChildren, ...restProps } = props || {};
|
|
212
|
+
const hasChildrenArg = rawChildren !== void 0;
|
|
213
|
+
const processedChildren = processChildren(rawChildren);
|
|
214
|
+
const result = {
|
|
215
|
+
type: typeName,
|
|
216
|
+
props: restProps || {}
|
|
217
|
+
};
|
|
218
|
+
if (processedChildren.length > 0 || hasChildrenArg) {
|
|
219
|
+
result.children = processedChildren;
|
|
220
|
+
}
|
|
221
|
+
if (key !== null && key !== void 0) {
|
|
222
|
+
result.key = String(key);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
function processChildren(children) {
|
|
227
|
+
if (children === null || children === void 0) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
if (Array.isArray(children)) {
|
|
231
|
+
return children.flatMap((child) => processChild(child));
|
|
232
|
+
}
|
|
233
|
+
return processChild(children);
|
|
234
|
+
}
|
|
235
|
+
function processChild(child) {
|
|
236
|
+
if (isFilterableChild(child)) {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
if (typeof child === "string") {
|
|
240
|
+
return [child];
|
|
241
|
+
}
|
|
242
|
+
if (typeof child === "number") {
|
|
243
|
+
return [String(child)];
|
|
244
|
+
}
|
|
245
|
+
if (React.isValidElement(child)) {
|
|
246
|
+
const element = child;
|
|
247
|
+
if (element.type === React.Fragment) {
|
|
248
|
+
return processChildren(element.props?.children);
|
|
249
|
+
}
|
|
250
|
+
return [compileJSX(element)];
|
|
251
|
+
}
|
|
252
|
+
if (Array.isArray(child)) {
|
|
253
|
+
return child.flatMap((c) => processChild(c));
|
|
254
|
+
}
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
function compileJSXDeep(element) {
|
|
258
|
+
const root = createUINodeShell(element);
|
|
259
|
+
const rawChildren = element.props?.children;
|
|
260
|
+
if (rawChildren === void 0) {
|
|
261
|
+
return root;
|
|
262
|
+
}
|
|
263
|
+
root.children = [];
|
|
264
|
+
const workStack = [];
|
|
265
|
+
populateChildrenWork(rawChildren, root.children, workStack);
|
|
266
|
+
while (workStack.length > 0) {
|
|
267
|
+
const work = workStack.pop();
|
|
268
|
+
const node = createUINodeShell(work.element);
|
|
269
|
+
work.targetArray[work.targetIndex] = node;
|
|
270
|
+
const nodeChildren = work.element.props?.children;
|
|
271
|
+
if (nodeChildren !== void 0) {
|
|
272
|
+
node.children = [];
|
|
273
|
+
populateChildrenWork(nodeChildren, node.children, workStack);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return root;
|
|
277
|
+
}
|
|
278
|
+
function createUINodeShell(element) {
|
|
279
|
+
const { type, props, key } = element;
|
|
280
|
+
const typeName = resolveTypeName(type);
|
|
281
|
+
const { children: _rawChildren, ...restProps } = props || {};
|
|
282
|
+
const result = {
|
|
283
|
+
type: typeName,
|
|
284
|
+
props: restProps || {}
|
|
285
|
+
};
|
|
286
|
+
if (key !== null && key !== void 0) {
|
|
287
|
+
result.key = String(key);
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
function populateChildrenWork(children, targetArray, workStack) {
|
|
292
|
+
if (children === null || children === void 0) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const childList = Array.isArray(children) ? children : [children];
|
|
296
|
+
let insertIndex = targetArray.length;
|
|
297
|
+
for (const child of childList) {
|
|
298
|
+
if (isFilterableChild(child)) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (typeof child === "string") {
|
|
302
|
+
targetArray.push(child);
|
|
303
|
+
insertIndex++;
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (typeof child === "number") {
|
|
307
|
+
targetArray.push(String(child));
|
|
308
|
+
insertIndex++;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (React.isValidElement(child)) {
|
|
312
|
+
const elem = child;
|
|
313
|
+
if (elem.type === React.Fragment) {
|
|
314
|
+
const fragChildren = elem.props?.children;
|
|
315
|
+
if (fragChildren !== null && fragChildren !== void 0) {
|
|
316
|
+
populateChildrenWork(fragChildren, targetArray, workStack);
|
|
317
|
+
insertIndex = targetArray.length;
|
|
318
|
+
}
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
targetArray.push({});
|
|
322
|
+
workStack.push({
|
|
323
|
+
element: elem,
|
|
324
|
+
targetArray,
|
|
325
|
+
targetIndex: insertIndex
|
|
326
|
+
});
|
|
327
|
+
insertIndex++;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (Array.isArray(child)) {
|
|
331
|
+
populateChildrenWork(child, targetArray, workStack);
|
|
332
|
+
insertIndex = targetArray.length;
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/core/types.ts
|
|
339
|
+
import { z } from "zod";
|
|
340
|
+
var RenderTierSchema = z.enum([
|
|
341
|
+
"text",
|
|
342
|
+
"markdown",
|
|
343
|
+
"ascii",
|
|
344
|
+
"unicode",
|
|
345
|
+
"ansi",
|
|
346
|
+
"interactive"
|
|
347
|
+
]);
|
|
348
|
+
var ThemeTokensSchema = z.object({
|
|
349
|
+
primary: z.string(),
|
|
350
|
+
secondary: z.string(),
|
|
351
|
+
muted: z.string(),
|
|
352
|
+
foreground: z.string(),
|
|
353
|
+
background: z.string(),
|
|
354
|
+
border: z.string(),
|
|
355
|
+
success: z.string(),
|
|
356
|
+
warning: z.string(),
|
|
357
|
+
error: z.string(),
|
|
358
|
+
info: z.string()
|
|
359
|
+
});
|
|
360
|
+
var UINodeSchema = z.lazy(
|
|
361
|
+
() => z.object({
|
|
362
|
+
type: z.string(),
|
|
363
|
+
props: z.record(z.string(), z.unknown()).optional(),
|
|
364
|
+
children: z.union([z.array(UINodeSchema), z.string()]).optional(),
|
|
365
|
+
text: z.string().optional(),
|
|
366
|
+
data: z.unknown().optional(),
|
|
367
|
+
key: z.string().optional()
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
var RenderContextSchema = z.object({
|
|
371
|
+
tier: RenderTierSchema,
|
|
372
|
+
width: z.number().nonnegative(),
|
|
373
|
+
height: z.number().nonnegative(),
|
|
374
|
+
depth: z.number().nonnegative(),
|
|
375
|
+
theme: ThemeTokensSchema,
|
|
376
|
+
interactive: z.boolean()
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// src/core/parser.ts
|
|
380
|
+
var ParseError = class _ParseError extends Error {
|
|
381
|
+
constructor(message) {
|
|
382
|
+
super(message);
|
|
383
|
+
this.name = "ParseError";
|
|
384
|
+
Object.setPrototypeOf(this, _ParseError.prototype);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
function parseUINode(input) {
|
|
388
|
+
let parsed;
|
|
389
|
+
if (typeof input === "string") {
|
|
390
|
+
if (input.trim() === "") {
|
|
391
|
+
throw new ParseError("Invalid JSON: empty string");
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
parsed = JSON.parse(input);
|
|
395
|
+
} catch (error) {
|
|
396
|
+
throw new ParseError(
|
|
397
|
+
`Invalid JSON: ${error instanceof Error ? error.message : "parse error"}`
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
parsed = input;
|
|
402
|
+
}
|
|
403
|
+
if (parsed === null) {
|
|
404
|
+
throw new ParseError("Invalid UINode: expected object, got null");
|
|
405
|
+
}
|
|
406
|
+
if (Array.isArray(parsed)) {
|
|
407
|
+
throw new ParseError("Invalid UINode: expected object, got array");
|
|
408
|
+
}
|
|
409
|
+
if (typeof parsed !== "object") {
|
|
410
|
+
throw new ParseError(`Invalid UINode: expected object, got ${typeof parsed}`);
|
|
411
|
+
}
|
|
412
|
+
const result = UINodeSchema.safeParse(parsed);
|
|
413
|
+
if (!result.success) {
|
|
414
|
+
const issues = result.error.issues;
|
|
415
|
+
const errorMessages = issues.map((issue) => {
|
|
416
|
+
const path = issue.path.length > 0 ? ` at path "${issue.path.join(".")}"` : "";
|
|
417
|
+
return `${issue.message}${path}`;
|
|
418
|
+
});
|
|
419
|
+
const hasTypeError = issues.some(
|
|
420
|
+
(issue) => issue.path.includes("type") || issue.path.length === 0 && issue.code === "invalid_type"
|
|
421
|
+
);
|
|
422
|
+
const hasMissingType = issues.some(
|
|
423
|
+
(issue) => issue.code === "invalid_type" && issue.path.length === 1 && issue.path[0] === "type"
|
|
424
|
+
);
|
|
425
|
+
if (hasMissingType || !("type" in parsed)) {
|
|
426
|
+
if (!("type" in parsed)) {
|
|
427
|
+
throw new ParseError('Invalid UINode: missing required field "type"');
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
throw new ParseError(`Invalid UINode: ${errorMessages.join("; ")}`);
|
|
431
|
+
}
|
|
432
|
+
return result.data;
|
|
433
|
+
}
|
|
434
|
+
function parseUINodeFromJSON(json) {
|
|
435
|
+
return parseUINode(json);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/index.ts
|
|
439
|
+
async function createCliRenderer(config) {
|
|
440
|
+
const { createCliRenderer: opentuiCreateCliRenderer } = await import("@opentui/core");
|
|
441
|
+
return opentuiCreateCliRenderer(config);
|
|
442
|
+
}
|
|
443
|
+
function createRoot(renderer) {
|
|
444
|
+
let rootInstance = null;
|
|
445
|
+
let initPromise = null;
|
|
446
|
+
return {
|
|
447
|
+
render: async (element) => {
|
|
448
|
+
if (!initPromise) {
|
|
449
|
+
initPromise = import("@opentui/react").then(({ createRoot: opentuiCreateRoot }) => {
|
|
450
|
+
rootInstance = opentuiCreateRoot(renderer);
|
|
451
|
+
return rootInstance;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
const root = await initPromise;
|
|
455
|
+
root.render(element);
|
|
456
|
+
},
|
|
457
|
+
unmount: () => {
|
|
458
|
+
if (rootInstance) {
|
|
459
|
+
rootInstance.unmount();
|
|
460
|
+
rootInstance = null;
|
|
461
|
+
}
|
|
462
|
+
initPromise = null;
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
async function CLI(options) {
|
|
467
|
+
const colorSupport = options?.colorSupport ?? detectColorSupport();
|
|
468
|
+
const { createCliRenderer: opentuiCreateCliRenderer } = await import("@opentui/core");
|
|
469
|
+
const { createRoot: opentuiCreateRoot } = await import("@opentui/react");
|
|
470
|
+
const opentuiRenderer = await opentuiCreateCliRenderer({
|
|
471
|
+
stdin: options?.stdin,
|
|
472
|
+
stdout: options?.stdout,
|
|
473
|
+
exitOnCtrlC: options?.exitOnCtrlC,
|
|
474
|
+
targetFps: options?.targetFps,
|
|
475
|
+
useAlternateScreen: options?.useAlternateScreen,
|
|
476
|
+
useMouse: options?.useMouse,
|
|
477
|
+
backgroundColor: options?.backgroundColor
|
|
478
|
+
});
|
|
479
|
+
const root = opentuiCreateRoot(opentuiRenderer);
|
|
480
|
+
const renderer = {
|
|
481
|
+
get width() {
|
|
482
|
+
return opentuiRenderer.width;
|
|
483
|
+
},
|
|
484
|
+
get height() {
|
|
485
|
+
return opentuiRenderer.height;
|
|
486
|
+
},
|
|
487
|
+
start: () => opentuiRenderer.start(),
|
|
488
|
+
stop: () => opentuiRenderer.stop(),
|
|
489
|
+
destroy: () => opentuiRenderer.destroy(),
|
|
490
|
+
requestRender: () => opentuiRenderer.requestRender()
|
|
491
|
+
};
|
|
492
|
+
return {
|
|
493
|
+
get width() {
|
|
494
|
+
return opentuiRenderer.width;
|
|
495
|
+
},
|
|
496
|
+
get height() {
|
|
497
|
+
return opentuiRenderer.height;
|
|
498
|
+
},
|
|
499
|
+
render: (element) => {
|
|
500
|
+
root.render(element);
|
|
501
|
+
},
|
|
502
|
+
clear: () => {
|
|
503
|
+
root.render(null);
|
|
504
|
+
},
|
|
505
|
+
destroy: () => {
|
|
506
|
+
root.unmount();
|
|
507
|
+
opentuiRenderer.destroy();
|
|
508
|
+
},
|
|
509
|
+
requestRender: () => {
|
|
510
|
+
opentuiRenderer.requestRender();
|
|
511
|
+
},
|
|
512
|
+
renderer,
|
|
513
|
+
root
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function useTerminalSize() {
|
|
517
|
+
const getSize = () => {
|
|
518
|
+
if (typeof process !== "undefined" && process.stdout?.columns && process.stdout?.rows) {
|
|
519
|
+
return {
|
|
520
|
+
width: process.stdout.columns,
|
|
521
|
+
height: process.stdout.rows
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
return { width: 80, height: 24 };
|
|
525
|
+
};
|
|
526
|
+
const [size, setSize] = useState(getSize);
|
|
527
|
+
useEffect(() => {
|
|
528
|
+
if (typeof process === "undefined" || !process.stdout?.on) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
const handleResize = () => {
|
|
532
|
+
setSize(getSize());
|
|
533
|
+
};
|
|
534
|
+
process.stdout.on("resize", handleResize);
|
|
535
|
+
const currentSize = getSize();
|
|
536
|
+
if (currentSize.width !== size.width || currentSize.height !== size.height) {
|
|
537
|
+
setSize(currentSize);
|
|
538
|
+
}
|
|
539
|
+
return () => {
|
|
540
|
+
process.stdout.off("resize", handleResize);
|
|
541
|
+
};
|
|
542
|
+
}, []);
|
|
543
|
+
return size;
|
|
544
|
+
}
|
|
545
|
+
function useTerminal() {
|
|
546
|
+
const { width, height } = useTerminalSize();
|
|
547
|
+
const detected = detectColorSupport();
|
|
548
|
+
const colorSupport = detected === "16" ? "basic" : detected;
|
|
549
|
+
const isRaw = typeof process !== "undefined" && process.stdin?.isRaw === true;
|
|
550
|
+
return {
|
|
551
|
+
width,
|
|
552
|
+
height,
|
|
553
|
+
colorSupport,
|
|
554
|
+
isRaw
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
var ThemeContext = createContext(null);
|
|
558
|
+
function useTheme() {
|
|
559
|
+
const context = useContext(ThemeContext);
|
|
560
|
+
if (!context) {
|
|
561
|
+
return {
|
|
562
|
+
theme: "dark",
|
|
563
|
+
setTheme: () => {
|
|
564
|
+
},
|
|
565
|
+
colors: {}
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
return context;
|
|
569
|
+
}
|
|
570
|
+
function TerminalProvider(props) {
|
|
571
|
+
return React2.createElement("terminal-provider", props);
|
|
572
|
+
}
|
|
573
|
+
function ThemeProvider(props) {
|
|
574
|
+
const value = {
|
|
575
|
+
theme: props.theme || "dark",
|
|
576
|
+
setTheme: () => {
|
|
577
|
+
},
|
|
578
|
+
colors: {}
|
|
579
|
+
};
|
|
580
|
+
return React2.createElement(
|
|
581
|
+
ThemeContext.Provider,
|
|
582
|
+
{ value },
|
|
583
|
+
props.children
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
function TerminalApp(props) {
|
|
587
|
+
return React2.createElement("terminal-app", props);
|
|
588
|
+
}
|
|
589
|
+
export {
|
|
590
|
+
ANSI,
|
|
591
|
+
APIKeySchema,
|
|
592
|
+
APIKeysCollection,
|
|
593
|
+
ARROW_BINDINGS,
|
|
594
|
+
Ansi256CodeSchema,
|
|
595
|
+
AnsiEscapeSchema,
|
|
596
|
+
App,
|
|
597
|
+
AppHeader,
|
|
598
|
+
Badge,
|
|
599
|
+
Box,
|
|
600
|
+
Breadcrumb,
|
|
601
|
+
Button,
|
|
602
|
+
CLI,
|
|
603
|
+
COMMON_BINDINGS,
|
|
604
|
+
COMPONENT_TYPES,
|
|
605
|
+
Card,
|
|
606
|
+
ColorSupportSchema,
|
|
607
|
+
CreateTerminalThemeOptionsSchema,
|
|
608
|
+
CreateThemeInputSchema,
|
|
609
|
+
DBProvider,
|
|
610
|
+
Dashboard,
|
|
611
|
+
Dialog,
|
|
612
|
+
EMACS_BINDINGS,
|
|
613
|
+
FAQ,
|
|
614
|
+
Features,
|
|
615
|
+
FocusContext,
|
|
616
|
+
FocusProvider,
|
|
617
|
+
Footer,
|
|
618
|
+
Header,
|
|
619
|
+
Hero,
|
|
620
|
+
HexColorSchema,
|
|
621
|
+
Input,
|
|
622
|
+
KEY,
|
|
623
|
+
LandingPage,
|
|
624
|
+
LegacyTerminalThemeSchema,
|
|
625
|
+
LegacyTerminalThemeWithExtrasSchema,
|
|
626
|
+
List,
|
|
627
|
+
Page,
|
|
628
|
+
Panel,
|
|
629
|
+
ParseError,
|
|
630
|
+
Pricing,
|
|
631
|
+
RenderContextSchema,
|
|
632
|
+
RenderTierSchema,
|
|
633
|
+
RgbColorSchema,
|
|
634
|
+
RgbComponentSchema,
|
|
635
|
+
RgbToAnsiOptionsSchema,
|
|
636
|
+
Select,
|
|
637
|
+
Settings,
|
|
638
|
+
Shell,
|
|
639
|
+
Sidebar,
|
|
640
|
+
SidebarItem,
|
|
641
|
+
SidebarLayout,
|
|
642
|
+
Site,
|
|
643
|
+
Spinner,
|
|
644
|
+
TAILWIND_COLORS,
|
|
645
|
+
Table,
|
|
646
|
+
TeamSchema,
|
|
647
|
+
TeamsCollection,
|
|
648
|
+
TerminalApp,
|
|
649
|
+
TerminalProvider,
|
|
650
|
+
TerminalThemeColorsSchema,
|
|
651
|
+
Text,
|
|
652
|
+
ThemeModeSchema,
|
|
653
|
+
ThemeProvider,
|
|
654
|
+
ThemeTokensSchema,
|
|
655
|
+
UINodeSchema,
|
|
656
|
+
UsageCollection,
|
|
657
|
+
UsageSchema,
|
|
658
|
+
UserRoleSchema,
|
|
659
|
+
UserSchema,
|
|
660
|
+
UsersCollection,
|
|
661
|
+
VIM_BINDINGS,
|
|
662
|
+
WebhookSchema,
|
|
663
|
+
WebhooksCollection,
|
|
664
|
+
__resetFocusIdCounter,
|
|
665
|
+
adaptColor,
|
|
666
|
+
ansi256,
|
|
667
|
+
ansi256Bg,
|
|
668
|
+
ansiToCSS,
|
|
669
|
+
ansiToHTML,
|
|
670
|
+
applyThemeStyles,
|
|
671
|
+
attachKeyboardManager,
|
|
672
|
+
bg,
|
|
673
|
+
bgColorMap,
|
|
674
|
+
bold,
|
|
675
|
+
boxChars,
|
|
676
|
+
colorMap,
|
|
677
|
+
colors,
|
|
678
|
+
compileJSX,
|
|
679
|
+
compileJSXDeep,
|
|
680
|
+
composeThemes,
|
|
681
|
+
createCliRenderer,
|
|
682
|
+
createCollection,
|
|
683
|
+
createDB,
|
|
684
|
+
createDOSync,
|
|
685
|
+
createFocusId,
|
|
686
|
+
createKeyboardManager,
|
|
687
|
+
createOpenTUIKeyHandler,
|
|
688
|
+
createRoot,
|
|
689
|
+
createTerminalTheme,
|
|
690
|
+
createTheme,
|
|
691
|
+
createThemeVariant,
|
|
692
|
+
cssVarToAnsi,
|
|
693
|
+
darkTheme,
|
|
694
|
+
defaultTheme,
|
|
695
|
+
degradeColor,
|
|
696
|
+
detectColorScheme,
|
|
697
|
+
detectColorSupport,
|
|
698
|
+
dim,
|
|
699
|
+
drawBox,
|
|
700
|
+
extendTheme,
|
|
701
|
+
extractChildren,
|
|
702
|
+
fg,
|
|
703
|
+
getBgColorCode,
|
|
704
|
+
getColorCode,
|
|
705
|
+
getThemeColor,
|
|
706
|
+
hex,
|
|
707
|
+
hexBg,
|
|
708
|
+
hexToAnsi,
|
|
709
|
+
hexToRgb,
|
|
710
|
+
highContrastTheme,
|
|
711
|
+
isBadgeProps,
|
|
712
|
+
isBoxProps,
|
|
713
|
+
isBreadcrumbProps,
|
|
714
|
+
isButtonProps,
|
|
715
|
+
isCardProps,
|
|
716
|
+
isDialogProps,
|
|
717
|
+
isFocusId,
|
|
718
|
+
isInputProps,
|
|
719
|
+
isListProps,
|
|
720
|
+
isPanelProps,
|
|
721
|
+
isPropsObject,
|
|
722
|
+
isSelectProps,
|
|
723
|
+
isSidebarItemProps,
|
|
724
|
+
isSidebarProps,
|
|
725
|
+
isSpinnerProps,
|
|
726
|
+
isTableProps,
|
|
727
|
+
isTerminalComponentType,
|
|
728
|
+
isTextProps,
|
|
729
|
+
italic,
|
|
730
|
+
keyToBindingString,
|
|
731
|
+
lightTheme,
|
|
732
|
+
matchKey,
|
|
733
|
+
normalizeOpenTUIKey,
|
|
734
|
+
normalizeReadlineKey,
|
|
735
|
+
parseAnsiToSpans,
|
|
736
|
+
parseUINode,
|
|
737
|
+
parseUINodeFromJSON,
|
|
738
|
+
renderBadge,
|
|
739
|
+
renderBox,
|
|
740
|
+
renderBreadcrumb,
|
|
741
|
+
renderButton,
|
|
742
|
+
renderCard,
|
|
743
|
+
renderComponent,
|
|
744
|
+
renderDialog,
|
|
745
|
+
renderElement,
|
|
746
|
+
renderInput,
|
|
747
|
+
renderList,
|
|
748
|
+
renderPanel,
|
|
749
|
+
renderSelect,
|
|
750
|
+
renderSidebar,
|
|
751
|
+
renderSidebarItem,
|
|
752
|
+
renderSpinner,
|
|
753
|
+
renderTable,
|
|
754
|
+
renderText,
|
|
755
|
+
rgb,
|
|
756
|
+
rgbBg,
|
|
757
|
+
rgbToAnsi,
|
|
758
|
+
spanToInlineStyle,
|
|
759
|
+
spinnerFrames,
|
|
760
|
+
strikethrough,
|
|
761
|
+
stripAnsi,
|
|
762
|
+
style,
|
|
763
|
+
styled,
|
|
764
|
+
tailwindToAnsi,
|
|
765
|
+
tailwindToTerminal,
|
|
766
|
+
themePresets,
|
|
767
|
+
themeTokens,
|
|
768
|
+
underline,
|
|
769
|
+
useDBContext,
|
|
770
|
+
useFocus,
|
|
771
|
+
useFocusManager,
|
|
772
|
+
useKeyboard,
|
|
773
|
+
useMutation,
|
|
774
|
+
useNavigableGrid,
|
|
775
|
+
useNavigableList,
|
|
776
|
+
useQuery,
|
|
777
|
+
useReactiveCard,
|
|
778
|
+
useReactiveData,
|
|
779
|
+
useReactiveList,
|
|
780
|
+
useReactiveMetrics,
|
|
781
|
+
useReactiveTable,
|
|
782
|
+
useTerminal,
|
|
783
|
+
useTerminalSize,
|
|
784
|
+
useTheme,
|
|
785
|
+
visibleLength
|
|
786
|
+
};
|