green-screen-react 0.3.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/LICENSE +21 -0
- package/README.md +160 -0
- package/dist/index.d.mts +400 -0
- package/dist/index.d.ts +400 -0
- package/dist/index.js +1269 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1223 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +307 -0
- package/package.json +76 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Supported terminal protocol types.
|
|
6
|
+
*/
|
|
7
|
+
type TerminalProtocol = 'tn5250' | 'tn3270' | 'vt' | 'hp6530';
|
|
8
|
+
/**
|
|
9
|
+
* Protocol-specific color/rendering conventions.
|
|
10
|
+
*/
|
|
11
|
+
interface ProtocolColorProfile {
|
|
12
|
+
/** CSS class for a row based on its index and content */
|
|
13
|
+
getRowColorClass(rowIndex: number, rowContent: string, totalRows: number): string;
|
|
14
|
+
/** Parse the header row into colored segments, or null for default rendering */
|
|
15
|
+
parseHeaderRow(line: string): {
|
|
16
|
+
text: string;
|
|
17
|
+
colorClass: string;
|
|
18
|
+
}[] | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Protocol profile — configures terminal behavior per legacy system type.
|
|
22
|
+
*/
|
|
23
|
+
interface ProtocolProfile {
|
|
24
|
+
/** Protocol identifier */
|
|
25
|
+
protocol: TerminalProtocol;
|
|
26
|
+
/** Human-readable name */
|
|
27
|
+
displayName: string;
|
|
28
|
+
/** Default terminal dimensions */
|
|
29
|
+
defaultRows: number;
|
|
30
|
+
defaultCols: number;
|
|
31
|
+
/** Color/rendering profile */
|
|
32
|
+
colors: ProtocolColorProfile;
|
|
33
|
+
/** Header label shown in terminal chrome */
|
|
34
|
+
headerLabel: string;
|
|
35
|
+
/** Boot loader default text */
|
|
36
|
+
bootText: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Field definition from the terminal data stream.
|
|
40
|
+
* Describes an input or protected field on the terminal screen.
|
|
41
|
+
*/
|
|
42
|
+
interface Field {
|
|
43
|
+
/** 0-based row index */
|
|
44
|
+
row: number;
|
|
45
|
+
/** 0-based column index */
|
|
46
|
+
col: number;
|
|
47
|
+
/** Field length in characters */
|
|
48
|
+
length: number;
|
|
49
|
+
/** Whether the field accepts user input */
|
|
50
|
+
is_input: boolean;
|
|
51
|
+
/** Whether the field is protected (read-only) */
|
|
52
|
+
is_protected: boolean;
|
|
53
|
+
/** Whether the field is displayed with high intensity (bright/white) */
|
|
54
|
+
is_highlighted?: boolean;
|
|
55
|
+
/** Whether the field is displayed in reverse video */
|
|
56
|
+
is_reverse?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Screen data returned by the adapter.
|
|
60
|
+
* Represents the current state of the terminal screen.
|
|
61
|
+
*/
|
|
62
|
+
interface ScreenData {
|
|
63
|
+
/** Screen content as newline-separated text (e.g. 24 lines of 80 chars) */
|
|
64
|
+
content: string;
|
|
65
|
+
/** 0-based cursor row */
|
|
66
|
+
cursor_row: number;
|
|
67
|
+
/** 0-based cursor column */
|
|
68
|
+
cursor_col: number;
|
|
69
|
+
/** Number of rows (default 24) */
|
|
70
|
+
rows?: number;
|
|
71
|
+
/** Number of columns (default 80) */
|
|
72
|
+
cols?: number;
|
|
73
|
+
/** Field definitions on the current screen */
|
|
74
|
+
fields?: Field[];
|
|
75
|
+
/** Unique identifier for the current screen state */
|
|
76
|
+
screen_signature?: string;
|
|
77
|
+
/** ISO timestamp of when this screen was captured */
|
|
78
|
+
timestamp?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Connection status information.
|
|
82
|
+
*/
|
|
83
|
+
interface ConnectionStatus {
|
|
84
|
+
/** Whether a TCP connection is established */
|
|
85
|
+
connected: boolean;
|
|
86
|
+
/** Current connection state */
|
|
87
|
+
status: 'disconnected' | 'connecting' | 'connected' | 'authenticated' | 'error';
|
|
88
|
+
/** Terminal protocol in use */
|
|
89
|
+
protocol?: TerminalProtocol;
|
|
90
|
+
/** Host address */
|
|
91
|
+
host?: string;
|
|
92
|
+
/** Authenticated username */
|
|
93
|
+
username?: string;
|
|
94
|
+
/** Error message if status is 'error' */
|
|
95
|
+
error?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Result from a send operation (text or key).
|
|
99
|
+
*/
|
|
100
|
+
interface SendResult {
|
|
101
|
+
/** Whether the operation succeeded */
|
|
102
|
+
success: boolean;
|
|
103
|
+
/** Updated cursor row after the operation */
|
|
104
|
+
cursor_row?: number;
|
|
105
|
+
/** Updated cursor column after the operation */
|
|
106
|
+
cursor_col?: number;
|
|
107
|
+
/** Updated screen content after the operation (for key presses that change screens) */
|
|
108
|
+
content?: string;
|
|
109
|
+
/** Updated screen signature */
|
|
110
|
+
screen_signature?: string;
|
|
111
|
+
/** Error message on failure */
|
|
112
|
+
error?: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Adapter interface for terminal communication.
|
|
116
|
+
*
|
|
117
|
+
* Implement this interface to connect the terminal component to your backend.
|
|
118
|
+
* The package ships a `RestAdapter` for HTTP-based backends.
|
|
119
|
+
*/
|
|
120
|
+
interface TerminalAdapter {
|
|
121
|
+
/** Fetch the current screen content */
|
|
122
|
+
getScreen(): Promise<ScreenData | null>;
|
|
123
|
+
/** Fetch the current connection status */
|
|
124
|
+
getStatus(): Promise<ConnectionStatus>;
|
|
125
|
+
/** Send text input to the terminal */
|
|
126
|
+
sendText(text: string): Promise<SendResult>;
|
|
127
|
+
/** Send a special key (ENTER, F1-F24, TAB, etc.) */
|
|
128
|
+
sendKey(key: string): Promise<SendResult>;
|
|
129
|
+
/** Establish a connection, optionally with sign-in config */
|
|
130
|
+
connect(config?: ConnectConfig): Promise<SendResult>;
|
|
131
|
+
/** Close the connection */
|
|
132
|
+
disconnect(): Promise<SendResult>;
|
|
133
|
+
/** Reconnect to the host */
|
|
134
|
+
reconnect(): Promise<SendResult>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Configuration passed from the inline sign-in form to adapter.connect().
|
|
138
|
+
*/
|
|
139
|
+
interface ConnectConfig {
|
|
140
|
+
/** Target host address */
|
|
141
|
+
host: string;
|
|
142
|
+
/** Target port (optional, adapter/server can default per protocol) */
|
|
143
|
+
port?: number;
|
|
144
|
+
/** Terminal protocol */
|
|
145
|
+
protocol: TerminalProtocol;
|
|
146
|
+
/** Username for authentication */
|
|
147
|
+
username: string;
|
|
148
|
+
/** Password for authentication */
|
|
149
|
+
password: string;
|
|
150
|
+
}
|
|
151
|
+
/** @deprecated Use `TerminalAdapter` instead */
|
|
152
|
+
type TN5250Adapter = TerminalAdapter;
|
|
153
|
+
|
|
154
|
+
interface GreenScreenTerminalProps {
|
|
155
|
+
/** Adapter for communicating with the terminal backend */
|
|
156
|
+
adapter: TerminalAdapter;
|
|
157
|
+
/** Terminal protocol (determines color conventions, header label, etc.) */
|
|
158
|
+
protocol?: TerminalProtocol;
|
|
159
|
+
/** Custom protocol profile (overrides protocol param) */
|
|
160
|
+
protocolProfile?: ProtocolProfile;
|
|
161
|
+
/** Direct screen data injection (bypasses polling) */
|
|
162
|
+
screenData?: ScreenData | null;
|
|
163
|
+
/** Direct connection status injection */
|
|
164
|
+
connectionStatus?: ConnectionStatus | null;
|
|
165
|
+
/** Whether the terminal is read-only (no keyboard input) */
|
|
166
|
+
readOnly?: boolean;
|
|
167
|
+
/** Polling interval in ms (0 to disable polling; default 2000) */
|
|
168
|
+
pollInterval?: number;
|
|
169
|
+
/** Whether to auto-reconnect on disconnect (default true) */
|
|
170
|
+
autoReconnect?: boolean;
|
|
171
|
+
/** Max auto-reconnect attempts (default 5) */
|
|
172
|
+
maxReconnectAttempts?: number;
|
|
173
|
+
/** Compact embedded mode */
|
|
174
|
+
embedded?: boolean;
|
|
175
|
+
/** Show the header bar (default true) */
|
|
176
|
+
showHeader?: boolean;
|
|
177
|
+
/** Enable typing animation (default true) */
|
|
178
|
+
typingAnimation?: boolean;
|
|
179
|
+
/** Typing animation budget in ms (default 60) */
|
|
180
|
+
typingBudgetMs?: number;
|
|
181
|
+
/** Show inline sign-in form when disconnected (default false) */
|
|
182
|
+
inlineSignIn?: boolean;
|
|
183
|
+
/** Default protocol for the sign-in form dropdown (default 'tn5250') */
|
|
184
|
+
defaultProtocol?: TerminalProtocol;
|
|
185
|
+
/** Callback when sign-in form is submitted */
|
|
186
|
+
onSignIn?: (config: ConnectConfig) => void;
|
|
187
|
+
/** Custom boot loader element, or false to disable */
|
|
188
|
+
bootLoader?: React.ReactNode | false;
|
|
189
|
+
/** Content for the right side of the header */
|
|
190
|
+
headerRight?: React.ReactNode;
|
|
191
|
+
/** Overlay content (e.g. "Extracting..." state) */
|
|
192
|
+
overlay?: React.ReactNode;
|
|
193
|
+
/** Callback for notifications (replaces toast) */
|
|
194
|
+
onNotification?: (message: string, type: 'info' | 'error') => void;
|
|
195
|
+
/** Callback when screen content changes */
|
|
196
|
+
onScreenChange?: (screen: ScreenData) => void;
|
|
197
|
+
/** Callback for minimize action (embedded mode) */
|
|
198
|
+
onMinimize?: () => void;
|
|
199
|
+
/** Additional CSS class name */
|
|
200
|
+
className?: string;
|
|
201
|
+
/** Inline styles */
|
|
202
|
+
style?: React.CSSProperties;
|
|
203
|
+
}
|
|
204
|
+
/** @deprecated Use GreenScreenTerminalProps instead */
|
|
205
|
+
type TN5250TerminalProps = GreenScreenTerminalProps;
|
|
206
|
+
/**
|
|
207
|
+
* GreenScreenTerminal — Multi-protocol legacy terminal emulator component.
|
|
208
|
+
*
|
|
209
|
+
* Renders a terminal screen with:
|
|
210
|
+
* - Green-on-black terminal aesthetic with protocol-specific color conventions
|
|
211
|
+
* - Connection status indicator
|
|
212
|
+
* - Keyboard input support (text, function keys, tab)
|
|
213
|
+
* - Auto-reconnect with exponential backoff
|
|
214
|
+
* - Typing animation for field entries
|
|
215
|
+
* - Focus lock mode for keyboard capture
|
|
216
|
+
*
|
|
217
|
+
* Supports: TN5250 (IBM i), TN3270 (z/OS), VT (OpenVMS/Pick), HP 6530 (NonStop)
|
|
218
|
+
*/
|
|
219
|
+
declare function GreenScreenTerminal({ adapter, protocol, protocolProfile: customProfile, screenData: externalScreenData, connectionStatus: externalStatus, readOnly, pollInterval, autoReconnect: autoReconnectEnabled, maxReconnectAttempts: maxAttempts, embedded, showHeader, typingAnimation, typingBudgetMs, inlineSignIn, defaultProtocol: signInDefaultProtocol, onSignIn, bootLoader, headerRight, overlay, onNotification, onScreenChange, onMinimize, className, style, }: GreenScreenTerminalProps): react_jsx_runtime.JSX.Element;
|
|
220
|
+
/** @deprecated Use GreenScreenTerminal instead */
|
|
221
|
+
declare const TN5250Terminal: typeof GreenScreenTerminal;
|
|
222
|
+
|
|
223
|
+
interface TerminalBootLoaderProps {
|
|
224
|
+
/** Text to display during boot animation */
|
|
225
|
+
brandText?: string;
|
|
226
|
+
/** Speed in ms per character */
|
|
227
|
+
charSpeed?: number;
|
|
228
|
+
/** Optional logo element to render alongside the text */
|
|
229
|
+
logo?: React.ReactNode;
|
|
230
|
+
/** Height of the boot loader container */
|
|
231
|
+
height?: number | string;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Animated boot loader for the terminal.
|
|
235
|
+
* Shows a typewriter-style text reveal animation.
|
|
236
|
+
*/
|
|
237
|
+
declare function TerminalBootLoader({ brandText, charSpeed, logo, height, }: TerminalBootLoaderProps): react_jsx_runtime.JSX.Element;
|
|
238
|
+
|
|
239
|
+
interface RestAdapterOptions {
|
|
240
|
+
/** Base URL for the terminal API (e.g. "https://myhost.com/api/terminal") */
|
|
241
|
+
baseUrl: string;
|
|
242
|
+
/** Optional headers to include with every request (e.g. Authorization) */
|
|
243
|
+
headers?: Record<string, string>;
|
|
244
|
+
/** Optional function that returns headers (called per-request, useful for dynamic tokens) */
|
|
245
|
+
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* REST API adapter for terminal communication.
|
|
249
|
+
*
|
|
250
|
+
* Expects a backend that exposes these endpoints relative to `baseUrl`:
|
|
251
|
+
* - GET /screen → ScreenData
|
|
252
|
+
* - GET /status → ConnectionStatus
|
|
253
|
+
* - POST /send-text → SendResult (body: { text })
|
|
254
|
+
* - POST /send-key → SendResult (body: { key })
|
|
255
|
+
* - POST /connect → SendResult
|
|
256
|
+
* - POST /disconnect → SendResult
|
|
257
|
+
* - POST /reconnect → SendResult
|
|
258
|
+
*/
|
|
259
|
+
declare class RestAdapter implements TerminalAdapter {
|
|
260
|
+
private baseUrl;
|
|
261
|
+
private staticHeaders;
|
|
262
|
+
private getHeaders?;
|
|
263
|
+
constructor(options: RestAdapterOptions);
|
|
264
|
+
private buildHeaders;
|
|
265
|
+
private request;
|
|
266
|
+
getScreen(): Promise<ScreenData | null>;
|
|
267
|
+
getStatus(): Promise<ConnectionStatus>;
|
|
268
|
+
sendText(text: string): Promise<SendResult>;
|
|
269
|
+
sendKey(key: string): Promise<SendResult>;
|
|
270
|
+
connect(config?: ConnectConfig): Promise<SendResult>;
|
|
271
|
+
disconnect(): Promise<SendResult>;
|
|
272
|
+
reconnect(): Promise<SendResult>;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Hook for typing animation effect on terminal screen content.
|
|
277
|
+
* Reveals characters progressively when screen content changes.
|
|
278
|
+
* Also provides animated cursor position that follows the typing.
|
|
279
|
+
*
|
|
280
|
+
* Uses a queue-based model: incoming content updates are queued when an
|
|
281
|
+
* animation is in progress, then played sequentially. This prevents
|
|
282
|
+
* blinks (no mid-animation cancellation) and skips (every field entry
|
|
283
|
+
* gets its own animation). Queue depth is capped to avoid falling
|
|
284
|
+
* behind real-time.
|
|
285
|
+
*
|
|
286
|
+
* Screen transitions (large changes) always display SYNCHRONOUSLY.
|
|
287
|
+
*/
|
|
288
|
+
declare function useTypingAnimation(content: string | null | undefined, enabled?: boolean, typingBudgetMs?: number): {
|
|
289
|
+
displayedContent: string;
|
|
290
|
+
isAnimating: boolean;
|
|
291
|
+
animatedCursorPos: {
|
|
292
|
+
row: number;
|
|
293
|
+
col: number;
|
|
294
|
+
} | null;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Hook for terminal connection management via adapter.
|
|
299
|
+
*/
|
|
300
|
+
declare function useTerminalConnection(adapter: TerminalAdapter): {
|
|
301
|
+
status: ConnectionStatus | null;
|
|
302
|
+
loading: boolean;
|
|
303
|
+
error: string | null;
|
|
304
|
+
fetchStatus: () => Promise<ConnectionStatus | null>;
|
|
305
|
+
connect: (config?: ConnectConfig) => Promise<{
|
|
306
|
+
success: boolean;
|
|
307
|
+
cursor_row?: number;
|
|
308
|
+
cursor_col?: number;
|
|
309
|
+
content?: string;
|
|
310
|
+
screen_signature?: string;
|
|
311
|
+
error?: string;
|
|
312
|
+
}>;
|
|
313
|
+
disconnect: () => Promise<{
|
|
314
|
+
success: boolean;
|
|
315
|
+
error?: undefined;
|
|
316
|
+
} | {
|
|
317
|
+
success: boolean;
|
|
318
|
+
error: string;
|
|
319
|
+
}>;
|
|
320
|
+
reconnect: () => Promise<{
|
|
321
|
+
success: boolean;
|
|
322
|
+
cursor_row?: number;
|
|
323
|
+
cursor_col?: number;
|
|
324
|
+
content?: string;
|
|
325
|
+
screen_signature?: string;
|
|
326
|
+
error?: string;
|
|
327
|
+
}>;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* Hook for terminal screen content with polling.
|
|
331
|
+
*/
|
|
332
|
+
declare function useTerminalScreen(adapter: TerminalAdapter, interval?: number, enabled?: boolean): {
|
|
333
|
+
data: ScreenData | null;
|
|
334
|
+
error: unknown;
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Hook for terminal operations (sendText, sendKey).
|
|
338
|
+
*/
|
|
339
|
+
declare function useTerminalInput(adapter: TerminalAdapter): {
|
|
340
|
+
loading: boolean;
|
|
341
|
+
error: string | null;
|
|
342
|
+
sendText: (text: string) => Promise<SendResult>;
|
|
343
|
+
sendKey: (key: string) => Promise<SendResult>;
|
|
344
|
+
};
|
|
345
|
+
/** @deprecated Use `useTerminalConnection` instead */
|
|
346
|
+
declare const useTN5250Connection: typeof useTerminalConnection;
|
|
347
|
+
/** @deprecated Use `useTerminalScreen` instead */
|
|
348
|
+
declare const useTN5250Screen: typeof useTerminalScreen;
|
|
349
|
+
/** @deprecated Use `useTerminalInput` instead */
|
|
350
|
+
declare const useTN5250Terminal: typeof useTerminalInput;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Get a protocol profile by type. Defaults to TN5250 for backward compatibility.
|
|
354
|
+
*/
|
|
355
|
+
declare function getProtocolProfile(protocol?: TerminalProtocol): ProtocolProfile;
|
|
356
|
+
|
|
357
|
+
declare const tn5250Profile: ProtocolProfile;
|
|
358
|
+
|
|
359
|
+
declare const tn3270Profile: ProtocolProfile;
|
|
360
|
+
|
|
361
|
+
declare const vtProfile: ProtocolProfile;
|
|
362
|
+
|
|
363
|
+
declare const hp6530Profile: ProtocolProfile;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Convert a linear position in screen content to row/col coordinates.
|
|
367
|
+
* Content is lines of characters separated by newlines.
|
|
368
|
+
*/
|
|
369
|
+
declare function positionToRowCol(content: string, position: number): {
|
|
370
|
+
row: number;
|
|
371
|
+
col: number;
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* Detect if a content change is a field entry (small, localized change)
|
|
375
|
+
* vs a screen transition (large, distributed change).
|
|
376
|
+
*
|
|
377
|
+
* Field entries: < 50 changed characters within a span of < 100 positions.
|
|
378
|
+
* Screen transitions: everything else.
|
|
379
|
+
*/
|
|
380
|
+
declare function isFieldEntry(previousContent: string | null | undefined, content: string | null | undefined): boolean;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Get the appropriate CSS class name for a row.
|
|
384
|
+
* Delegates to the TN5250 protocol profile for backward compatibility.
|
|
385
|
+
*
|
|
386
|
+
* For protocol-aware rendering, use `getProtocolProfile(protocol).colors.getRowColorClass()`.
|
|
387
|
+
*/
|
|
388
|
+
declare function getRowColorClass(rowIndex: number, rowContent: string): string;
|
|
389
|
+
/**
|
|
390
|
+
* Parse the header row into colored segments.
|
|
391
|
+
* Delegates to the TN5250 protocol profile for backward compatibility.
|
|
392
|
+
*
|
|
393
|
+
* For protocol-aware rendering, use `getProtocolProfile(protocol).colors.parseHeaderRow()`.
|
|
394
|
+
*/
|
|
395
|
+
declare function parseHeaderRow(line: string): {
|
|
396
|
+
text: string;
|
|
397
|
+
colorClass: string;
|
|
398
|
+
}[] | null;
|
|
399
|
+
|
|
400
|
+
export { type ConnectConfig, type ConnectionStatus, type Field, GreenScreenTerminal, type GreenScreenTerminalProps, type ProtocolColorProfile, type ProtocolProfile, RestAdapter, type RestAdapterOptions, type ScreenData, type SendResult, type TN5250Adapter, TN5250Terminal, type TN5250TerminalProps, type TerminalAdapter, TerminalBootLoader, type TerminalBootLoaderProps, type TerminalProtocol, getProtocolProfile, getRowColorClass, hp6530Profile, isFieldEntry, parseHeaderRow, positionToRowCol, tn3270Profile, tn5250Profile, useTN5250Connection, useTN5250Screen, useTN5250Terminal, useTerminalConnection, useTerminalInput, useTerminalScreen, useTypingAnimation, vtProfile };
|