@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
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Styling Utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions for applying ANSI styles to text with automatic reset.
|
|
5
|
+
* Includes semantic color helpers and compound style application.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { ANSI } from './ansi-codes'
|
|
11
|
+
import { colors, defaultTheme, type LegacyTerminalTheme } from './theme-system'
|
|
12
|
+
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Semantic Color Styling
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Applies a foreground color to text with automatic reset.
|
|
19
|
+
*
|
|
20
|
+
* Accepts either a semantic color name ('primary', 'error', etc.) or
|
|
21
|
+
* a raw ANSI escape sequence.
|
|
22
|
+
*
|
|
23
|
+
* @param colorName - Semantic color name or ANSI escape sequence
|
|
24
|
+
* @param text - The text to colorize
|
|
25
|
+
* @returns Colored text with ANSI codes
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* console.log(fg('error', 'Something went wrong'))
|
|
30
|
+
* console.log(fg('success', 'Operation completed'))
|
|
31
|
+
* console.log(fg(ANSI.brightCyan, 'Custom color'))
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function fg(colorName: keyof typeof colors | string, text: string): string {
|
|
35
|
+
const colorCode = colors[colorName as keyof typeof colors] || defaultTheme[colorName as keyof LegacyTerminalTheme] || colorName
|
|
36
|
+
return `${colorCode}${text}${ANSI.reset}`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Applies a background color to text with automatic reset.
|
|
41
|
+
*
|
|
42
|
+
* Accepts either a semantic color name ('primary', 'error', etc.) or
|
|
43
|
+
* a raw ANSI escape sequence.
|
|
44
|
+
*
|
|
45
|
+
* @param colorName - Semantic color name or ANSI escape sequence
|
|
46
|
+
* @param text - The text to highlight
|
|
47
|
+
* @returns Highlighted text with ANSI codes
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* console.log(bg('error', 'ALERT'))
|
|
52
|
+
* console.log(bg('success', ' OK '))
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function bg(colorName: keyof typeof colors | string, text: string): string {
|
|
56
|
+
const bgMap: Record<string, string> = {
|
|
57
|
+
primary: ANSI.bgCyan,
|
|
58
|
+
secondary: ANSI.bgBlue,
|
|
59
|
+
accent: ANSI.bgMagenta,
|
|
60
|
+
muted: ANSI.bgBlack,
|
|
61
|
+
success: ANSI.bgGreen,
|
|
62
|
+
warning: ANSI.bgYellow,
|
|
63
|
+
error: ANSI.bgRed,
|
|
64
|
+
info: ANSI.bgBlue,
|
|
65
|
+
}
|
|
66
|
+
const colorCode = bgMap[colorName] || colorName
|
|
67
|
+
return `${colorCode}${text}${ANSI.reset}`
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ============================================================================
|
|
71
|
+
// Text Style Modifiers
|
|
72
|
+
// ============================================================================
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Applies bold styling to text.
|
|
76
|
+
*
|
|
77
|
+
* @param text - The text to make bold
|
|
78
|
+
* @returns Bold text with ANSI codes
|
|
79
|
+
*/
|
|
80
|
+
export function bold(text: string): string {
|
|
81
|
+
return `${ANSI.bold}${text}${ANSI.reset}`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Applies dim/faint styling to text.
|
|
86
|
+
*
|
|
87
|
+
* @param text - The text to dim
|
|
88
|
+
* @returns Dimmed text with ANSI codes
|
|
89
|
+
*/
|
|
90
|
+
export function dim(text: string): string {
|
|
91
|
+
return `${ANSI.dim}${text}${ANSI.reset}`
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Applies italic styling to text.
|
|
96
|
+
*
|
|
97
|
+
* Note: Not all terminals support italic text.
|
|
98
|
+
*
|
|
99
|
+
* @param text - The text to italicize
|
|
100
|
+
* @returns Italic text with ANSI codes
|
|
101
|
+
*/
|
|
102
|
+
export function italic(text: string): string {
|
|
103
|
+
return `${ANSI.italic}${text}${ANSI.reset}`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Applies underline styling to text.
|
|
108
|
+
*
|
|
109
|
+
* @param text - The text to underline
|
|
110
|
+
* @returns Underlined text with ANSI codes
|
|
111
|
+
*/
|
|
112
|
+
export function underline(text: string): string {
|
|
113
|
+
return `${ANSI.underline}${text}${ANSI.reset}`
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Applies strikethrough styling to text.
|
|
118
|
+
*
|
|
119
|
+
* Note: Not all terminals support strikethrough text.
|
|
120
|
+
*
|
|
121
|
+
* @param text - The text to strike through
|
|
122
|
+
* @returns Strikethrough text with ANSI codes
|
|
123
|
+
*/
|
|
124
|
+
export function strikethrough(text: string): string {
|
|
125
|
+
return `${ANSI.strikethrough}${text}${ANSI.reset}`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ============================================================================
|
|
129
|
+
// Compound Styling
|
|
130
|
+
// ============================================================================
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Applies multiple style modifiers to text.
|
|
134
|
+
*
|
|
135
|
+
* Accepts an array of modifier names (e.g., 'bold', 'red', 'underline')
|
|
136
|
+
* and applies all of them to the text.
|
|
137
|
+
*
|
|
138
|
+
* @param text - The text to style
|
|
139
|
+
* @param modifiers - Array of modifier names
|
|
140
|
+
* @returns Styled text with ANSI codes
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```tsx
|
|
144
|
+
* console.log(style('Important', ['bold', 'red', 'underline']))
|
|
145
|
+
* console.log(style('Info', ['cyan', 'italic']))
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export function style(text: string, modifiers: string[]): string {
|
|
149
|
+
const modifierMap: Record<string, string> = {
|
|
150
|
+
bold: ANSI.bold,
|
|
151
|
+
dim: ANSI.dim,
|
|
152
|
+
italic: ANSI.italic,
|
|
153
|
+
underline: ANSI.underline,
|
|
154
|
+
strikethrough: ANSI.strikethrough,
|
|
155
|
+
black: ANSI.black,
|
|
156
|
+
red: ANSI.red,
|
|
157
|
+
green: ANSI.green,
|
|
158
|
+
yellow: ANSI.yellow,
|
|
159
|
+
blue: ANSI.blue,
|
|
160
|
+
magenta: ANSI.magenta,
|
|
161
|
+
cyan: ANSI.cyan,
|
|
162
|
+
white: ANSI.white,
|
|
163
|
+
brightBlack: ANSI.brightBlack,
|
|
164
|
+
brightRed: ANSI.brightRed,
|
|
165
|
+
brightGreen: ANSI.brightGreen,
|
|
166
|
+
brightYellow: ANSI.brightYellow,
|
|
167
|
+
brightBlue: ANSI.brightBlue,
|
|
168
|
+
brightMagenta: ANSI.brightMagenta,
|
|
169
|
+
brightCyan: ANSI.brightCyan,
|
|
170
|
+
brightWhite: ANSI.brightWhite,
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const codes = modifiers.map(m => modifierMap[m] || '').filter(Boolean)
|
|
174
|
+
if (codes.length === 0) return text
|
|
175
|
+
|
|
176
|
+
return `${codes.join('')}${text}${ANSI.reset}`
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Wraps text with ANSI escape codes and automatically appends reset.
|
|
181
|
+
*
|
|
182
|
+
* The primary utility for applying multiple ANSI styles to text.
|
|
183
|
+
* Accepts any number of ANSI escape code strings.
|
|
184
|
+
*
|
|
185
|
+
* @param text - The text to style (returns empty string if null/undefined)
|
|
186
|
+
* @param codes - ANSI escape code strings to apply
|
|
187
|
+
* @returns Styled text with reset appended
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```tsx
|
|
191
|
+
* // Bold cyan text
|
|
192
|
+
* console.log(styled('Hello', ANSI.bold, ANSI.cyan))
|
|
193
|
+
*
|
|
194
|
+
* // Error styling
|
|
195
|
+
* console.log(styled('Error!', ANSI.bold, ANSI.red, ANSI.bgBlack))
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export function styled(text: string, ...codes: string[]): string {
|
|
199
|
+
// Handle null/undefined text
|
|
200
|
+
if (text == null) return ''
|
|
201
|
+
if (codes.length === 0) return String(text)
|
|
202
|
+
// Filter out empty/null codes
|
|
203
|
+
const validCodes = codes.filter((c) => c && typeof c === 'string')
|
|
204
|
+
if (validCodes.length === 0) return String(text)
|
|
205
|
+
return `${validCodes.join('')}${text}${ANSI.reset}`
|
|
206
|
+
}
|