svg-terminal 1.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/LICENSE +21 -0
- package/README.md +384 -0
- package/dist/chunk-IVINEQLU.js +4603 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +524 -0
- package/dist/index.d.ts +733 -0
- package/dist/index.js +101 -0
- package/package.json +76 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core type definitions for svg-terminal.
|
|
5
|
+
* All public interfaces used by the library, CLI, and plugins.
|
|
6
|
+
*/
|
|
7
|
+
/** Color palette for a terminal theme. */
|
|
8
|
+
interface ThemeColors {
|
|
9
|
+
/** Primary text color */
|
|
10
|
+
text: string;
|
|
11
|
+
/** Muted/comment text */
|
|
12
|
+
comment: string;
|
|
13
|
+
/** Terminal background */
|
|
14
|
+
background: string;
|
|
15
|
+
/** Title bar background */
|
|
16
|
+
titleBarBackground: string;
|
|
17
|
+
/** Title bar text */
|
|
18
|
+
titleBarText: string;
|
|
19
|
+
/** Prompt color */
|
|
20
|
+
prompt: string;
|
|
21
|
+
/** Cursor color */
|
|
22
|
+
cursor: string;
|
|
23
|
+
/** Named semantic colors */
|
|
24
|
+
red: string;
|
|
25
|
+
green: string;
|
|
26
|
+
yellow: string;
|
|
27
|
+
blue: string;
|
|
28
|
+
magenta: string;
|
|
29
|
+
cyan: string;
|
|
30
|
+
white: string;
|
|
31
|
+
orange: string;
|
|
32
|
+
purple: string;
|
|
33
|
+
pink: string;
|
|
34
|
+
/** Bright variants */
|
|
35
|
+
brightRed: string;
|
|
36
|
+
brightGreen: string;
|
|
37
|
+
brightYellow: string;
|
|
38
|
+
brightBlue: string;
|
|
39
|
+
brightMagenta: string;
|
|
40
|
+
brightCyan: string;
|
|
41
|
+
brightWhite: string;
|
|
42
|
+
brightBlack: string;
|
|
43
|
+
}
|
|
44
|
+
/** A complete terminal theme. */
|
|
45
|
+
interface Theme {
|
|
46
|
+
/** Theme name (e.g. "dracula") */
|
|
47
|
+
name: string;
|
|
48
|
+
/** Color palette */
|
|
49
|
+
colors: ThemeColors;
|
|
50
|
+
/** Title bar button colors */
|
|
51
|
+
buttons: {
|
|
52
|
+
close: string;
|
|
53
|
+
minimize: string;
|
|
54
|
+
maximize: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Window style variant. */
|
|
58
|
+
type WindowStyle = 'macos' | 'win95' | 'floating' | 'minimal' | 'none';
|
|
59
|
+
/** Window/SVG dimensions and chrome. */
|
|
60
|
+
interface WindowConfig {
|
|
61
|
+
/** SVG width in pixels (default: 1000) */
|
|
62
|
+
width: number;
|
|
63
|
+
/** SVG height in pixels (default: 560, ~16:9 terminal ratio) */
|
|
64
|
+
height: number;
|
|
65
|
+
/** Border radius for window corners (default: 12) */
|
|
66
|
+
borderRadius: number;
|
|
67
|
+
/** Title bar height (default: 40) */
|
|
68
|
+
titleBarHeight: number;
|
|
69
|
+
/** Title text shown in title bar */
|
|
70
|
+
title: string;
|
|
71
|
+
/** Window style variant (default: 'macos') */
|
|
72
|
+
style: WindowStyle;
|
|
73
|
+
/** Auto-calculate height from content (default: false) */
|
|
74
|
+
autoHeight: boolean;
|
|
75
|
+
/** Minimum height when autoHeight is true (default: 300) */
|
|
76
|
+
minHeight: number;
|
|
77
|
+
/** Maximum height when autoHeight is true (default: 1200) */
|
|
78
|
+
maxHeight: number;
|
|
79
|
+
}
|
|
80
|
+
/** Terminal text rendering config. */
|
|
81
|
+
interface TerminalTextConfig {
|
|
82
|
+
/** Font family stack (default: monospace) */
|
|
83
|
+
fontFamily: string;
|
|
84
|
+
/** Font size in pixels (default: 14) */
|
|
85
|
+
fontSize: number;
|
|
86
|
+
/** Line height multiplier (default: 1.8) */
|
|
87
|
+
lineHeight: number;
|
|
88
|
+
/** Left/right padding in pixels (default: 12) */
|
|
89
|
+
padding: number;
|
|
90
|
+
/** Top padding below title bar (default: 8) */
|
|
91
|
+
paddingTop: number;
|
|
92
|
+
/** Prompt string (default: "user@host:~$ ") */
|
|
93
|
+
prompt: string;
|
|
94
|
+
}
|
|
95
|
+
/** Animation timing presets. */
|
|
96
|
+
interface TimingPresets {
|
|
97
|
+
typing: Record<string, number>;
|
|
98
|
+
pause: Record<string, number>;
|
|
99
|
+
}
|
|
100
|
+
/** Accessibility-related output toggles. */
|
|
101
|
+
interface AccessibilityConfig {
|
|
102
|
+
/**
|
|
103
|
+
* Emit a `<desc>` child carrying the full final-frame content as plain
|
|
104
|
+
* text so screen readers can read more than the aria-label summary.
|
|
105
|
+
* Default: true. Set to false to skip duplicating output content into the
|
|
106
|
+
* SVG payload (e.g. if the output is sensitive).
|
|
107
|
+
*/
|
|
108
|
+
describe: boolean;
|
|
109
|
+
}
|
|
110
|
+
/** SVG visual effects toggles. */
|
|
111
|
+
interface EffectsConfig {
|
|
112
|
+
/** Enable phosphor text glow (default: false) */
|
|
113
|
+
textGlow: boolean;
|
|
114
|
+
/** Enable window drop shadow (default: true) */
|
|
115
|
+
shadow: boolean;
|
|
116
|
+
/** Enable CRT scanline effect (default: true) */
|
|
117
|
+
scanlines: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Subtle radial vignette over the terminal background (default: false).
|
|
120
|
+
* Auto-enabled for the three CRT-aesthetic themes (amber, green-phosphor,
|
|
121
|
+
* cyberpunk) via mergeConfig when the user hasn't set it. Mimics a real
|
|
122
|
+
* CRT's center-hot phosphor falloff.
|
|
123
|
+
*/
|
|
124
|
+
vignette: boolean;
|
|
125
|
+
}
|
|
126
|
+
/** Animation timing configuration. */
|
|
127
|
+
interface AnimationConfig {
|
|
128
|
+
/**
|
|
129
|
+
* Cursor blink cycle duration in ms (default: 1000).
|
|
130
|
+
* @deprecated As of v0.7.1 the cursor is solid-visible during typing —
|
|
131
|
+
* the blink would render it invisible for chunks of the typing window,
|
|
132
|
+
* which was the cursor-animation bug we fixed. Real terminals also
|
|
133
|
+
* don't blink during active key input. Will be removed in v1.0.
|
|
134
|
+
*/
|
|
135
|
+
cursorBlinkCycle: number;
|
|
136
|
+
/**
|
|
137
|
+
* Duration of character appear fade-in in ms (default: 10).
|
|
138
|
+
* @deprecated As of v0.7 typed-character reveal is discrete (one clip-path
|
|
139
|
+
* animate per command); this field only affects the prompt fade-in and
|
|
140
|
+
* the output-line fade-in. Will be removed in v1.0.
|
|
141
|
+
*/
|
|
142
|
+
charAppearDuration: number;
|
|
143
|
+
/** Delay between output lines in ms (default: 50) */
|
|
144
|
+
outputLineStagger: number;
|
|
145
|
+
/** Pause after typing command before output appears in ms (default: 300) */
|
|
146
|
+
commandOutputPause: number;
|
|
147
|
+
/** Extra delay added to scroll events in ms (default: 10) */
|
|
148
|
+
scrollDelay: number;
|
|
149
|
+
/** Pause at end of output block in ms (default: 200) */
|
|
150
|
+
outputEndPause: number;
|
|
151
|
+
/** Default typing duration for commands in ms (default: 2000) */
|
|
152
|
+
defaultTypingDuration: number;
|
|
153
|
+
/** Default pause between sequences in ms (default: 1000) */
|
|
154
|
+
defaultSequencePause: number;
|
|
155
|
+
/** Loop control: true = infinite, false = play once, number = N times (default: true) */
|
|
156
|
+
loop: boolean | number;
|
|
157
|
+
}
|
|
158
|
+
/** Window chrome appearance configuration. */
|
|
159
|
+
interface ChromeConfig {
|
|
160
|
+
/** Title bar font family — system UI stack by default, separate from terminal monospace */
|
|
161
|
+
titleFontFamily: string;
|
|
162
|
+
/** Title bar font size in px (default: 13) */
|
|
163
|
+
titleFontSize: number;
|
|
164
|
+
/** Window button radius in px (default: 6) */
|
|
165
|
+
buttonRadius: number;
|
|
166
|
+
/** Spacing between window buttons in px (default: 20) */
|
|
167
|
+
buttonSpacing: number;
|
|
168
|
+
/** Opacity for [[dim]] text (default: 0.6) */
|
|
169
|
+
dimOpacity: number;
|
|
170
|
+
/** Window button vertical center Y position (default: 16) */
|
|
171
|
+
buttonY: number;
|
|
172
|
+
}
|
|
173
|
+
/** Full terminal generator configuration. */
|
|
174
|
+
interface TerminalConfig {
|
|
175
|
+
window: WindowConfig;
|
|
176
|
+
text: TerminalTextConfig;
|
|
177
|
+
theme: Theme;
|
|
178
|
+
effects: EffectsConfig;
|
|
179
|
+
animation: AnimationConfig;
|
|
180
|
+
chrome: ChromeConfig;
|
|
181
|
+
accessibility: AccessibilityConfig;
|
|
182
|
+
/** Maximum animation duration in seconds (default: 90) */
|
|
183
|
+
maxDuration: number;
|
|
184
|
+
/** Scroll animation duration in ms (default: 100) */
|
|
185
|
+
scrollDuration: number;
|
|
186
|
+
/** HTTP fetch timeout in ms for dynamic blocks (default: 10000) */
|
|
187
|
+
fetchTimeout: number;
|
|
188
|
+
/** Cache TTL in seconds for dynamic-block fetches (default: 86400 = 24h) */
|
|
189
|
+
cacheTTL: number;
|
|
190
|
+
/** Cache file path, relative to the config file (default: `.svg-terminal-cache.json`) */
|
|
191
|
+
cachePath: string;
|
|
192
|
+
/** Optional aria-label override for the generated SVG. When set, replaces
|
|
193
|
+
* the auto-generated "Animated terminal showing: …" / "Static terminal
|
|
194
|
+
* showing N lines" defaults. Useful for screen-reader-first profile
|
|
195
|
+
* README labels. */
|
|
196
|
+
accessibilityLabel?: string;
|
|
197
|
+
}
|
|
198
|
+
/** A single animation sequence (command or output). */
|
|
199
|
+
interface Sequence {
|
|
200
|
+
/** Sequence type */
|
|
201
|
+
type: 'command' | 'output';
|
|
202
|
+
/** Text content (when `frames` is set, this is the first frame joined). */
|
|
203
|
+
content: string;
|
|
204
|
+
/** Override prompt for this command */
|
|
205
|
+
prompt?: string;
|
|
206
|
+
/** Text color override */
|
|
207
|
+
color?: string;
|
|
208
|
+
/** Typing duration in ms (for commands) */
|
|
209
|
+
typingDuration?: number;
|
|
210
|
+
/** Pause after this sequence in ms */
|
|
211
|
+
pause?: number;
|
|
212
|
+
/** Delay before this sequence starts in ms */
|
|
213
|
+
delay?: number;
|
|
214
|
+
/** Optional multi-frame payload — output sequences only. Each entry is one frame's content (newline-separated lines). Triggers frame-cycle rendering. */
|
|
215
|
+
frames?: string[];
|
|
216
|
+
/** Frames per second when `frames` is set (default 4, capped at 30). */
|
|
217
|
+
framesFps?: number;
|
|
218
|
+
/** Loop frames forever when set (default true). */
|
|
219
|
+
framesLoop?: boolean;
|
|
220
|
+
/** Width-pinning opt-in (BlockResult.pinWidth). When true, output line text
|
|
221
|
+
* elements emit `textLength` + `lengthAdjust="spacingAndGlyphs"`. */
|
|
222
|
+
pinWidth?: boolean;
|
|
223
|
+
}
|
|
224
|
+
/** An animation frame in the timeline. */
|
|
225
|
+
interface AnimationFrame {
|
|
226
|
+
time: number;
|
|
227
|
+
type: 'scroll' | 'add-command' | 'add-output' | 'final';
|
|
228
|
+
lineIndex?: number;
|
|
229
|
+
prompt?: string;
|
|
230
|
+
command?: string;
|
|
231
|
+
content?: string;
|
|
232
|
+
color?: string;
|
|
233
|
+
typingDuration?: number;
|
|
234
|
+
scrollLines?: number;
|
|
235
|
+
bufferStart?: number;
|
|
236
|
+
/** Multi-frame payload — present only on add-output frames spawned from animated blocks. */
|
|
237
|
+
frames?: string[];
|
|
238
|
+
framesFps?: number;
|
|
239
|
+
framesLoop?: boolean;
|
|
240
|
+
/** Width-pinning opt-in from BlockResult.pinWidth. */
|
|
241
|
+
pinWidth?: boolean;
|
|
242
|
+
}
|
|
243
|
+
/** Context passed to blocks during rendering. */
|
|
244
|
+
interface BlockContext {
|
|
245
|
+
/** Current date/time */
|
|
246
|
+
now: Date;
|
|
247
|
+
/** Terminal configuration */
|
|
248
|
+
config: TerminalConfig;
|
|
249
|
+
/** User-provided variables */
|
|
250
|
+
variables: Record<string, unknown>;
|
|
251
|
+
/**
|
|
252
|
+
* Cache helper. A block calls `useCache(key, () => fetchSomething())`
|
|
253
|
+
* to either return a cached payload (within TTL) or run the getter and
|
|
254
|
+
* write the result back to the cache file. Use a stable key — typically
|
|
255
|
+
* `${blockName}:${configHash}` so reconfigurations don't collide.
|
|
256
|
+
*
|
|
257
|
+
* Behavior is controlled by the runtime cache settings: enabled by
|
|
258
|
+
* default, bypassed under `--no-cache`, refreshed under
|
|
259
|
+
* `--refresh-cache`, and frozen (never fetch) under `--frozen-cache`.
|
|
260
|
+
*/
|
|
261
|
+
useCache?<T>(key: string, getter: () => Promise<T>, opts?: {
|
|
262
|
+
ttl?: number;
|
|
263
|
+
}): Promise<T>;
|
|
264
|
+
}
|
|
265
|
+
/** A rendered block — produces sequences for the animation. */
|
|
266
|
+
interface BlockResult {
|
|
267
|
+
/** The command to display being "typed" */
|
|
268
|
+
command: string;
|
|
269
|
+
/** Output lines (may contain [[fg:color]] markup). When `animation` is set, this is the FIRST frame — used as the static fallback and screen-reader snapshot. */
|
|
270
|
+
lines: string[];
|
|
271
|
+
/** Override color for output */
|
|
272
|
+
color?: string;
|
|
273
|
+
/** Typing speed preset name */
|
|
274
|
+
typing?: string;
|
|
275
|
+
/** Pause preset name after output */
|
|
276
|
+
pause?: string;
|
|
277
|
+
/**
|
|
278
|
+
* Optional frame-by-frame animation. Each frame is a `string[]` matching
|
|
279
|
+
* the column-width / line-count of `lines`. Renderer emits N text-group
|
|
280
|
+
* siblings with SMIL opacity-cycle animations. The static SVG (`--static`)
|
|
281
|
+
* and screen-reader `<desc>` use `lines` only.
|
|
282
|
+
*/
|
|
283
|
+
animation?: BlockAnimation;
|
|
284
|
+
/**
|
|
285
|
+
* Optional signal: the block's render produced FALLBACK output (network
|
|
286
|
+
* failure, missing config, etc.) rather than the canonical live payload.
|
|
287
|
+
* Surfaces via `GenerateOptions.onCacheEvent('fallback', blockName)` so
|
|
288
|
+
* the CLI can warn users that a dynamic block didn't get its real data.
|
|
289
|
+
* Cacheable blocks (weather, github-stats, quote, fun-fact, github-languages)
|
|
290
|
+
* set this when they return their fallback lines.
|
|
291
|
+
*/
|
|
292
|
+
fallback?: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Opt the output lines into width-pinning via SVG `textLength` +
|
|
295
|
+
* `lengthAdjust="spacingAndGlyphs"`. Use for blocks whose layout depends
|
|
296
|
+
* on a precise monospace advance (e.g. `neofetch`'s aligned columns) —
|
|
297
|
+
* forces the rendered width to our `CHAR_WIDTH_RATIO * fontSize` math
|
|
298
|
+
* regardless of the viewer's monospace fallback font.
|
|
299
|
+
*
|
|
300
|
+
* NOT recommended for blocks containing box-drawing characters (`╔═══╗`),
|
|
301
|
+
* full-width/double-width emoji, or other glyphs whose intrinsic widths
|
|
302
|
+
* vary by font — `spacingAndGlyphs` would scale them into looking worse.
|
|
303
|
+
* Defaults to false; existing blocks unaffected. (#85)
|
|
304
|
+
*/
|
|
305
|
+
pinWidth?: boolean;
|
|
306
|
+
}
|
|
307
|
+
/** Multi-frame animation payload for a block. */
|
|
308
|
+
interface BlockAnimation {
|
|
309
|
+
/** Frames in cycle order. Each entry is one frame's lines. */
|
|
310
|
+
frames: string[][];
|
|
311
|
+
/** Frames per second (default 4, capped at 30). */
|
|
312
|
+
fps?: number;
|
|
313
|
+
/** Loop forever (default true). When false, the final frame stays after one cycle. */
|
|
314
|
+
loop?: boolean;
|
|
315
|
+
}
|
|
316
|
+
/** Block definition — a self-contained terminal content module. */
|
|
317
|
+
interface Block {
|
|
318
|
+
/** Block type name (e.g. "neofetch", "custom") */
|
|
319
|
+
name: string;
|
|
320
|
+
/** Human-readable description */
|
|
321
|
+
description?: string;
|
|
322
|
+
/**
|
|
323
|
+
* Optional zod schema for the block's config. When set, the YAML config entry
|
|
324
|
+
* is parsed through this schema BEFORE render() is called; failures throw
|
|
325
|
+
* BlockConfigError. Use `.strict()` on the schema so typos surface as errors
|
|
326
|
+
* rather than being silently stripped.
|
|
327
|
+
*/
|
|
328
|
+
configSchema?: zod.ZodTypeAny;
|
|
329
|
+
/**
|
|
330
|
+
* Optional explicit list of config keys this block accepts. Used when
|
|
331
|
+
* configSchema is not set — unknown keys in the YAML produce a stderr
|
|
332
|
+
* warning (promoted to error under `--strict`). Keep this list synced with
|
|
333
|
+
* the actual destructures in render().
|
|
334
|
+
*/
|
|
335
|
+
allowedKeys?: readonly string[];
|
|
336
|
+
/**
|
|
337
|
+
* True if this block reads via `context.useCache`. Used by the `cache check`
|
|
338
|
+
* CLI command to know which entries should have a cache record.
|
|
339
|
+
*/
|
|
340
|
+
cacheable?: boolean;
|
|
341
|
+
/** Render the block content */
|
|
342
|
+
render(context: BlockContext, blockConfig: Record<string, unknown>): BlockResult | Promise<BlockResult>;
|
|
343
|
+
}
|
|
344
|
+
/** Block entry in user's YAML config. */
|
|
345
|
+
interface BlockEntry {
|
|
346
|
+
/** Block type name */
|
|
347
|
+
block: string;
|
|
348
|
+
/** Block-specific configuration */
|
|
349
|
+
config?: Record<string, unknown>;
|
|
350
|
+
/** Override command text */
|
|
351
|
+
command?: string;
|
|
352
|
+
/** Override color */
|
|
353
|
+
color?: string;
|
|
354
|
+
/** Override typing speed */
|
|
355
|
+
typing?: string;
|
|
356
|
+
/** Override pause */
|
|
357
|
+
pause?: string;
|
|
358
|
+
}
|
|
359
|
+
/** User-facing YAML configuration schema. */
|
|
360
|
+
interface UserConfig {
|
|
361
|
+
/** Theme name or custom theme object */
|
|
362
|
+
theme?: string | Theme;
|
|
363
|
+
/** Window dimensions */
|
|
364
|
+
window?: Partial<WindowConfig>;
|
|
365
|
+
/** Terminal text settings */
|
|
366
|
+
terminal?: Partial<TerminalTextConfig>;
|
|
367
|
+
/** Visual effects toggles */
|
|
368
|
+
effects?: Partial<EffectsConfig>;
|
|
369
|
+
/** Animation timing overrides */
|
|
370
|
+
animation?: Partial<AnimationConfig>;
|
|
371
|
+
/** Window chrome appearance overrides */
|
|
372
|
+
chrome?: Partial<ChromeConfig>;
|
|
373
|
+
/** Accessibility overrides */
|
|
374
|
+
accessibility?: Partial<AccessibilityConfig>;
|
|
375
|
+
/** Ordered list of blocks to render */
|
|
376
|
+
blocks: BlockEntry[];
|
|
377
|
+
/** User variables passed to blocks */
|
|
378
|
+
variables?: Record<string, unknown>;
|
|
379
|
+
/** Maximum animation duration in seconds */
|
|
380
|
+
maxDuration?: number;
|
|
381
|
+
/** Scroll animation duration in ms */
|
|
382
|
+
scrollDuration?: number;
|
|
383
|
+
/** Custom accessibility label for the SVG */
|
|
384
|
+
accessibilityLabel?: string;
|
|
385
|
+
/** HTTP fetch timeout in ms for dynamic blocks (default: 10000) */
|
|
386
|
+
fetchTimeout?: number;
|
|
387
|
+
/** Cache TTL in seconds for dynamic-block fetches (default: 86400 = 24h) */
|
|
388
|
+
cacheTTL?: number;
|
|
389
|
+
/** Cache file path, relative to the config file (default: `.svg-terminal-cache.json`) */
|
|
390
|
+
cachePath?: string;
|
|
391
|
+
}
|
|
392
|
+
/** A styled text span produced by the markup parser. */
|
|
393
|
+
interface StyledSpan {
|
|
394
|
+
text: string;
|
|
395
|
+
fg: string | null;
|
|
396
|
+
bg: string | null;
|
|
397
|
+
bold: boolean;
|
|
398
|
+
dim: boolean;
|
|
399
|
+
}
|
|
400
|
+
/** Box drawing style. */
|
|
401
|
+
type BoxStyle = 'double' | 'rounded' | 'single' | 'heavy' | 'dashed';
|
|
402
|
+
/** Box character set for drawing. */
|
|
403
|
+
interface BoxChars {
|
|
404
|
+
topLeft: string;
|
|
405
|
+
topRight: string;
|
|
406
|
+
bottomLeft: string;
|
|
407
|
+
bottomRight: string;
|
|
408
|
+
horizontal: string;
|
|
409
|
+
vertical: string;
|
|
410
|
+
separatorLeft: string;
|
|
411
|
+
separatorRight: string;
|
|
412
|
+
}
|
|
413
|
+
/** Configuration for creating an ASCII box. */
|
|
414
|
+
interface BoxConfig {
|
|
415
|
+
/** Box style (default: 'double') */
|
|
416
|
+
style?: BoxStyle;
|
|
417
|
+
/** Total box width including borders (default: 56) */
|
|
418
|
+
width?: number;
|
|
419
|
+
/** Content lines */
|
|
420
|
+
lines: string[];
|
|
421
|
+
/** Line indices after which to add a separator */
|
|
422
|
+
separatorAfter?: number[];
|
|
423
|
+
/** Truncate lines that exceed width (default: true) */
|
|
424
|
+
truncate?: boolean;
|
|
425
|
+
/** Wrap lines that exceed width instead of truncating (default: false) */
|
|
426
|
+
wrap?: boolean;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** Runtime cache mode driven by CLI flags. */
|
|
430
|
+
type CacheMode = 'normal' | 'refresh' | 'frozen' | 'off';
|
|
431
|
+
/** Per-entry status returned by checkCache(). */
|
|
432
|
+
interface CacheCheckResult {
|
|
433
|
+
key: string;
|
|
434
|
+
blockName: string;
|
|
435
|
+
entryIndex: number;
|
|
436
|
+
/** OK = present + within TTL; STALE = present + expired; MISSING = no entry. */
|
|
437
|
+
status: 'OK' | 'STALE' | 'MISSING';
|
|
438
|
+
/** Age in seconds, present when status is OK or STALE. */
|
|
439
|
+
ageSeconds?: number;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* SVG Terminal Generator — creates animated SVG terminals from sequences.
|
|
444
|
+
* This is the core rendering engine: sequences in, SVG string out.
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
/** Generate an animated SVG terminal from a sequence of commands/outputs. */
|
|
448
|
+
declare function generateSvg(sequences: Sequence[], config: TerminalConfig): string;
|
|
449
|
+
/** Generate a static (non-animated) SVG terminal showing all content. */
|
|
450
|
+
declare function generateStaticSvg(lines: string[], config: TerminalConfig): string;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Configuration loading and merging.
|
|
454
|
+
* Reads YAML config files and merges with defaults.
|
|
455
|
+
*/
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Load, parse, and validate a YAML config file. Throws ConfigError on any failure.
|
|
459
|
+
* js-yaml is loaded lazily so library consumers who only call `generate(parsedConfig)`
|
|
460
|
+
* don't pay for the parser in their bundle.
|
|
461
|
+
*/
|
|
462
|
+
declare function loadConfig(filePath: string): Promise<UserConfig>;
|
|
463
|
+
/** Merge user config with defaults to produce a full TerminalConfig. */
|
|
464
|
+
declare function mergeConfig(userConfig: UserConfig): TerminalConfig;
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Configuration errors with actionable, single-source-of-truth formatting.
|
|
468
|
+
* Thrown by loadConfig; the CLI renders them without a stack trace.
|
|
469
|
+
*/
|
|
470
|
+
/** A config-level error: bad YAML, schema violation, unknown theme/block. */
|
|
471
|
+
declare class ConfigError extends Error {
|
|
472
|
+
/** Pre-formatted multi-line message ready for stderr. */
|
|
473
|
+
readonly formatted: string;
|
|
474
|
+
constructor(formatted: string);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* A block-config validation failure: the block declares a configSchema (or an
|
|
478
|
+
* allowedKeys list under --strict) and the YAML entry violated it.
|
|
479
|
+
*
|
|
480
|
+
* Sibling of ConfigError so the CLI can render both with the same path —
|
|
481
|
+
* pattern-match on `err.formatted` either way.
|
|
482
|
+
*/
|
|
483
|
+
declare class BlockConfigError extends Error {
|
|
484
|
+
readonly formatted: string;
|
|
485
|
+
readonly blockName: string;
|
|
486
|
+
readonly entryIndex: number;
|
|
487
|
+
constructor(blockName: string, entryIndex: number, formatted: string);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Block registry — manages available block types.
|
|
492
|
+
* Blocks are self-contained terminal content modules.
|
|
493
|
+
*/
|
|
494
|
+
|
|
495
|
+
/** Register a block type. */
|
|
496
|
+
declare function registerBlock(block: Block): void;
|
|
497
|
+
/** Get a registered block by name. */
|
|
498
|
+
declare function getBlock(name: string): Block | undefined;
|
|
499
|
+
/** Get all registered block names. */
|
|
500
|
+
declare function listBlocks(): string[];
|
|
501
|
+
/** Register multiple blocks at once. */
|
|
502
|
+
declare function registerBlocks(blocks: Block[]): void;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Built-in blocks — register all default block types.
|
|
506
|
+
*/
|
|
507
|
+
/** Register all built-in blocks. */
|
|
508
|
+
declare function registerBuiltinBlocks(): void;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* ASCII Box Generator — creates formatted boxes for terminal output.
|
|
512
|
+
*
|
|
513
|
+
* Supports multiple styles: double, rounded, single, heavy, dashed.
|
|
514
|
+
*/
|
|
515
|
+
|
|
516
|
+
/** Create an ASCII box with automatic padding and alignment. */
|
|
517
|
+
declare function createBox(config: BoxConfig): string;
|
|
518
|
+
/** Convenience: create a double-line box. */
|
|
519
|
+
declare function createDoubleBox(lines: string[], width?: number, separatorAfter?: number[]): string;
|
|
520
|
+
/** Convenience: create a rounded box. */
|
|
521
|
+
declare function createRoundedBox(lines: string[], width?: number, separatorAfter?: number[]): string;
|
|
522
|
+
/** Create a titled box with a header section separated from content. */
|
|
523
|
+
declare function createTitledBox(opts: {
|
|
524
|
+
title: string;
|
|
525
|
+
subtitle?: string;
|
|
526
|
+
content: string[];
|
|
527
|
+
width?: number;
|
|
528
|
+
style?: BoxStyle;
|
|
529
|
+
}): string;
|
|
530
|
+
/** Configuration for auto-sizing boxes. */
|
|
531
|
+
interface AutoBoxConfig {
|
|
532
|
+
lines: string[];
|
|
533
|
+
style?: BoxStyle;
|
|
534
|
+
minWidth?: number;
|
|
535
|
+
maxWidth?: number;
|
|
536
|
+
separatorAfter?: number[];
|
|
537
|
+
}
|
|
538
|
+
/** Create a box that auto-sizes to fit its content. */
|
|
539
|
+
declare function createAutoBox(config: AutoBoxConfig): string;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Markup parser for [[style]] formatted text.
|
|
543
|
+
* Converts template output to styled spans for SVG rendering.
|
|
544
|
+
*
|
|
545
|
+
* Supported tags:
|
|
546
|
+
* - [[fg:colorName]]text[[/fg]] — foreground color
|
|
547
|
+
* - [[bg:colorName]]text[[/bg]] — background color
|
|
548
|
+
* - [[bold]]text[[/bold]] — bold weight
|
|
549
|
+
* - [[dim]]text[[/dim]] — dimmed opacity
|
|
550
|
+
*/
|
|
551
|
+
|
|
552
|
+
/** Build a color lookup map from theme colors. */
|
|
553
|
+
declare function buildColorMap(colors: ThemeColors): Record<string, string>;
|
|
554
|
+
/** Parse [[style]] markup into styled spans. */
|
|
555
|
+
declare function parseMarkup(text: string, colorMap: Record<string, string>, fallbackColor: string): StyledSpan[];
|
|
556
|
+
/** Check if text contains [[]] markup. */
|
|
557
|
+
declare function hasMarkup(text: string): boolean;
|
|
558
|
+
/**
|
|
559
|
+
* Strip all markup and return plain text. The inner class is bounded to
|
|
560
|
+
* 256 chars to defuse the polynomial-ReDoS risk that CodeQL flagged on
|
|
561
|
+
* the unbounded form (`/\[\[[^\]]+\]\]/`). Every legitimate markup tag
|
|
562
|
+
* fits — `[[fg:hexNNNNNN]]`, `[[bold]]`, `[[dim]]` are all <20 chars —
|
|
563
|
+
* so the cap doesn't lose real input; it only kills the attacker's
|
|
564
|
+
* backtrack runway.
|
|
565
|
+
*/
|
|
566
|
+
declare function stripMarkup(text: string): string;
|
|
567
|
+
|
|
568
|
+
/** Dracula color theme — https://draculatheme.com/ */
|
|
569
|
+
declare const dracula: Theme;
|
|
570
|
+
|
|
571
|
+
/** Nord color theme — https://www.nordtheme.com/ */
|
|
572
|
+
declare const nord: Theme;
|
|
573
|
+
|
|
574
|
+
/** Monokai Pro color theme */
|
|
575
|
+
declare const monokai: Theme;
|
|
576
|
+
|
|
577
|
+
/** Amber CRT — classic 1980s phosphor terminal (VT100/DEC aesthetic) */
|
|
578
|
+
declare const amber: Theme;
|
|
579
|
+
|
|
580
|
+
/** Green Phosphor — classic hacker terminal (Matrix/Mr. Robot aesthetic) */
|
|
581
|
+
declare const greenPhosphor: Theme;
|
|
582
|
+
|
|
583
|
+
/** Cyberpunk — neon on dark (Night City aesthetic) */
|
|
584
|
+
declare const cyberpunk: Theme;
|
|
585
|
+
|
|
586
|
+
/** Solarized Dark — Ethan Schoonover's precision-designed color scheme */
|
|
587
|
+
declare const solarizedDark: Theme;
|
|
588
|
+
|
|
589
|
+
/** Windows 95 — classic Microsoft DOS/command prompt aesthetic */
|
|
590
|
+
declare const win95: Theme;
|
|
591
|
+
|
|
592
|
+
/** Catppuccin Mocha — https://catppuccin.com/palette (dark variant) */
|
|
593
|
+
declare const catppuccin: Theme;
|
|
594
|
+
|
|
595
|
+
/** Tokyo Night — https://github.com/folke/tokyonight.nvim (default storm variant) */
|
|
596
|
+
declare const tokyoNight: Theme;
|
|
597
|
+
|
|
598
|
+
/** Gruvbox Dark (medium) — https://github.com/morhetz/gruvbox */
|
|
599
|
+
declare const gruvbox: Theme;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* High-contrast theme designed to clear WCAG AAA (≥7:1) for text and prompt
|
|
603
|
+
* on background. Useful for users with low vision, screen-readability needs,
|
|
604
|
+
* or anyone projecting an SVG terminal in a high-glare environment (slides,
|
|
605
|
+
* keynote backgrounds). Also reads well at very small thumbnail sizes.
|
|
606
|
+
*
|
|
607
|
+
* Pure black background + pure white text = 21:1. Accent colors are picked
|
|
608
|
+
* from a constrained palette where every one clears 7:1 on black:
|
|
609
|
+
* #ffffff (white) 21:1
|
|
610
|
+
* #ffff00 (yellow) 19.6:1
|
|
611
|
+
* #00ffff (cyan) 16.7:1
|
|
612
|
+
* #00ff00 (green) 15.3:1
|
|
613
|
+
* #ff00ff (magenta) 9.0:1
|
|
614
|
+
* #ff5555 (red) 5.7:1 — AA only; bumped from canonical red for visibility
|
|
615
|
+
* #aaaaff (blue) 8.4:1 — lifted from pure blue (#0000ff = 2.4:1, AAA-fail)
|
|
616
|
+
*
|
|
617
|
+
* NOT for general README aesthetic use — this is a deliberately blunt
|
|
618
|
+
* instrument. The standard themes (dracula, nord, …) are the default UX.
|
|
619
|
+
*/
|
|
620
|
+
declare const highContrast: Theme;
|
|
621
|
+
|
|
622
|
+
/** Built-in theme registry. */
|
|
623
|
+
declare const themes: Record<string, Theme>;
|
|
624
|
+
/**
|
|
625
|
+
* Register a custom theme. Mirrors registerBlock() — name shadows built-ins.
|
|
626
|
+
* Throws on the reserved name "random" (which triggers daily rotation).
|
|
627
|
+
*/
|
|
628
|
+
declare function registerTheme(theme: Theme): void;
|
|
629
|
+
/** Get a registered theme by name (custom + built-in). */
|
|
630
|
+
declare function getTheme(name: string): Theme | undefined;
|
|
631
|
+
/** All theme names — custom first, then built-ins. */
|
|
632
|
+
declare function listThemes(): string[];
|
|
633
|
+
/** Resolve a theme by name. Supports 'random' for random selection. Throws if not found. */
|
|
634
|
+
declare function resolveTheme(nameOrTheme: string | Theme): Theme;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Default configuration values for svg-terminal.
|
|
638
|
+
*/
|
|
639
|
+
|
|
640
|
+
/** Typing speed presets in milliseconds. */
|
|
641
|
+
declare const TYPING_PRESETS: Record<string, number>;
|
|
642
|
+
/** Pause duration presets in milliseconds. */
|
|
643
|
+
declare const PAUSE_PRESETS: Record<string, number>;
|
|
644
|
+
/** Resolve a typing speed from a preset name or number. */
|
|
645
|
+
declare function resolveTyping(value: string | number | undefined): number;
|
|
646
|
+
/** Resolve a pause duration from a preset name or number. */
|
|
647
|
+
declare function resolvePause(value: string | number | undefined): number;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Fetch a URL with a timeout. Returns the Response or null on failure.
|
|
651
|
+
* Never throws — all errors are caught and logged.
|
|
652
|
+
*/
|
|
653
|
+
declare function fetchWithTimeout(url: string, timeoutMs?: number): Promise<Response | null>;
|
|
654
|
+
/**
|
|
655
|
+
* Fetch JSON from a URL with a timeout. Returns parsed data or null.
|
|
656
|
+
* Never throws — all errors are caught and logged.
|
|
657
|
+
*/
|
|
658
|
+
declare function fetchJson<T = unknown>(url: string, timeoutMs?: number): Promise<T | null>;
|
|
659
|
+
/**
|
|
660
|
+
* Fetch plain text from a URL with a timeout. Returns text or null.
|
|
661
|
+
* Never throws — all errors are caught and logged.
|
|
662
|
+
*/
|
|
663
|
+
declare function fetchText(url: string, timeoutMs?: number): Promise<string | null>;
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* svg-terminal — Generate animated SVG terminals for GitHub READMEs.
|
|
667
|
+
*
|
|
668
|
+
* @example
|
|
669
|
+
* ```ts
|
|
670
|
+
* import { generate } from 'svg-terminal';
|
|
671
|
+
*
|
|
672
|
+
* const svg = await generate({
|
|
673
|
+
* theme: 'dracula',
|
|
674
|
+
* window: { title: 'my-terminal' },
|
|
675
|
+
* blocks: [
|
|
676
|
+
* { block: 'neofetch', config: { username: 'dev', hostname: 'box' } },
|
|
677
|
+
* { block: 'custom', config: { command: 'echo hi', lines: ['Hello!'] } },
|
|
678
|
+
* ],
|
|
679
|
+
* });
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
|
|
683
|
+
/** Cache + render event surfaced by `GenerateOptions.onCacheEvent`. */
|
|
684
|
+
type CacheEventType = 'hit' | 'miss' | 'refreshed' | 'fallback';
|
|
685
|
+
/** Options to thread cache runtime + file context into generate(). */
|
|
686
|
+
interface GenerateOptions {
|
|
687
|
+
/** Absolute or relative path to the YAML config file — anchors cachePath resolution. */
|
|
688
|
+
configPath?: string;
|
|
689
|
+
/** Cache mode (default: 'normal'). Set via CLI flags --no-cache / --refresh-cache / --frozen-cache. */
|
|
690
|
+
cacheMode?: CacheMode;
|
|
691
|
+
/**
|
|
692
|
+
* Override the `context.now` passed to each block. Defaults to `new Date()`.
|
|
693
|
+
* Useful for reproducible demos + tests: pass a fixed Date so time-dependent
|
|
694
|
+
* blocks (ascii-clock, ascii-calendar, dice-roll's per-day seed, etc.)
|
|
695
|
+
* produce deterministic output.
|
|
696
|
+
*/
|
|
697
|
+
now?: Date;
|
|
698
|
+
/**
|
|
699
|
+
* Optional callback for cache + render events. Called per cacheable-block
|
|
700
|
+
* `useCache` invocation (`'hit'` = served from cache within TTL, `'miss'` =
|
|
701
|
+
* fetched fresh, `'refreshed'` = forced refresh under `--refresh-cache`)
|
|
702
|
+
* AND once per block that returned `result.fallback === true` (failed to
|
|
703
|
+
* fetch live data, served defaults).
|
|
704
|
+
*
|
|
705
|
+
* `key` is the block's cache key for cache events (e.g.
|
|
706
|
+
* `"weather:abc123"`) OR the block's name for fallback events.
|
|
707
|
+
*
|
|
708
|
+
* The CLI uses this to print a one-line summary at the end of a generate
|
|
709
|
+
* run when dynamic blocks are involved — surfaces the
|
|
710
|
+
* "frozen-cache served a stale entry" / "network failed silently" cases
|
|
711
|
+
* that were previously invisible.
|
|
712
|
+
*/
|
|
713
|
+
onCacheEvent?: (event: CacheEventType, key: string) => void;
|
|
714
|
+
}
|
|
715
|
+
/** Enable strict mode globally — unknown block-config keys throw instead of warning. */
|
|
716
|
+
declare function setStrictBlockConfig(enabled: boolean): void;
|
|
717
|
+
/**
|
|
718
|
+
* Generate an animated SVG terminal from a declarative config.
|
|
719
|
+
* This is the main API entry point.
|
|
720
|
+
*/
|
|
721
|
+
declare function generate(userConfig: UserConfig, options?: GenerateOptions): Promise<string>;
|
|
722
|
+
/**
|
|
723
|
+
* Walk a config and report each cacheable block's status against the cache file.
|
|
724
|
+
* Returns one result per entry whose block declares `cacheable: true`.
|
|
725
|
+
* Used by the `svg-terminal cache check` CLI command.
|
|
726
|
+
*/
|
|
727
|
+
declare function inspectCache(userConfig: UserConfig, configPath: string): {
|
|
728
|
+
filePath: string;
|
|
729
|
+
results: CacheCheckResult[];
|
|
730
|
+
};
|
|
731
|
+
declare function generateStatic(userConfig: UserConfig, options?: GenerateOptions): Promise<string>;
|
|
732
|
+
|
|
733
|
+
export { type AccessibilityConfig, type AnimationConfig, type AnimationFrame, type Block, type BlockAnimation, BlockConfigError, type BlockContext, type BlockEntry, type BlockResult, type BoxChars, type BoxConfig, type BoxStyle, type CacheEventType, type ChromeConfig, ConfigError, type EffectsConfig, type GenerateOptions, PAUSE_PRESETS, type Sequence, type StyledSpan, TYPING_PRESETS, type TerminalConfig, type TerminalTextConfig, type Theme, type ThemeColors, type TimingPresets, type UserConfig, type WindowConfig, type WindowStyle, amber, buildColorMap, catppuccin, createAutoBox, createBox, createDoubleBox, createRoundedBox, createTitledBox, cyberpunk, dracula, fetchJson, fetchText, fetchWithTimeout, generate, generateStatic, generateStaticSvg, generateSvg, getBlock, getTheme, greenPhosphor, gruvbox, hasMarkup, highContrast, inspectCache, listBlocks, listThemes, loadConfig, mergeConfig, monokai, nord, parseMarkup, registerBlock, registerBlocks, registerBuiltinBlocks, registerTheme, resolvePause, resolveTheme, resolveTyping, setStrictBlockConfig, solarizedDark, stripMarkup, themes, tokyoNight, win95 };
|