ansimax 1.3.2 → 1.3.4

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/dist/index.d.ts CHANGED
@@ -95,203 +95,36 @@ declare const getConfigValue: <K extends keyof AnsimaxConfig>(key: K) => Require
95
95
  * });
96
96
  */
97
97
  declare const withConfig: <T>(overrides: AnsimaxConfig, fn: () => T | Promise<T>) => T | Promise<T>;
98
-
99
- declare const ESC = "\u001B";
100
- declare const CSI = "\u001B[";
101
- /** OSC sequence introducer (Operating System Command). */
102
- declare const OSC = "\u001B]";
103
- /** String terminator used to close OSC sequences. */
104
- declare const ST = "\u001B\\";
105
- /** BEL — alternative OSC terminator (older terminals). */
106
- declare const BEL = "\u0007";
107
- type AnsiCode = number;
108
- /** Default fallback dimensions when stdout is not a TTY. */
109
- declare const DEFAULT_TERM_COLS = 80;
110
- declare const DEFAULT_TERM_ROWS = 24;
111
- declare const cursor: {
112
- readonly up: (n?: number) => string;
113
- readonly down: (n?: number) => string;
114
- readonly right: (n?: number) => string;
115
- readonly left: (n?: number) => string;
116
- readonly to: (x: number, y: number) => string;
117
- /** Move cursor to absolute column n (1-based). */
118
- readonly column: (n: number) => string;
119
- /** Save cursor (CSI s — DEC private). */
120
- readonly save: () => string;
121
- /** Restore cursor (CSI u). */
122
- readonly restore: () => string;
123
- /** Save cursor (ESC 7 — VT100 standard). */
124
- readonly saveCompat: () => string;
125
- /** Restore cursor (ESC 8). */
126
- readonly restoreCompat: () => string;
127
- readonly hide: () => string;
128
- readonly show: () => string;
129
- /** Query cursor position. Terminal responds with CSI <row>;<col>R. */
130
- readonly position: () => string;
131
- /** Move cursor to next line (CR + line down). */
132
- readonly nextLine: (n?: number) => string;
133
- /** Move cursor to previous line. */
134
- readonly prevLine: (n?: number) => string;
135
- };
136
- /**
137
- * Hide cursor and register an exit handler that restores it on crash/SIGINT.
138
- * Use this instead of writing `cursor.hide()` directly when you care about
139
- * leaving the user's shell in a clean state.
140
- */
141
- declare const hideCursor: () => boolean;
142
- declare const showCursor: () => boolean;
143
- type EraseMode = 'down' | 'up' | 'all';
144
- declare const screen: {
145
- readonly clear: () => string;
146
- /** Alias for clear() — covers `screen.clearAll()` callers. */
147
- readonly clearAll: () => string;
148
- readonly clearLine: () => string;
149
- readonly clearRight: () => string;
150
- readonly clearLeft: () => string;
151
- readonly clearDown: () => string;
152
- readonly clearUp: () => string;
153
- readonly eraseDisplay: (mode?: EraseMode) => string;
154
- readonly scrollUp: (n?: number) => string;
155
- readonly scrollDown: (n?: number) => string;
156
- };
157
- declare const FG: {
158
- readonly black: 30;
159
- readonly red: 31;
160
- readonly green: 32;
161
- readonly yellow: 33;
162
- readonly blue: 34;
163
- readonly magenta: 35;
164
- readonly cyan: 36;
165
- readonly white: 37;
166
- readonly brightBlack: 90;
167
- readonly brightRed: 91;
168
- readonly brightGreen: 92;
169
- readonly brightYellow: 93;
170
- readonly brightBlue: 94;
171
- readonly brightMagenta: 95;
172
- readonly brightCyan: 96;
173
- readonly brightWhite: 97;
174
- };
175
- declare const BG: {
176
- readonly black: 40;
177
- readonly red: 41;
178
- readonly green: 42;
179
- readonly yellow: 43;
180
- readonly blue: 44;
181
- readonly magenta: 45;
182
- readonly cyan: 46;
183
- readonly white: 47;
184
- readonly brightBlack: 100;
185
- readonly brightRed: 101;
186
- readonly brightGreen: 102;
187
- readonly brightYellow: 103;
188
- readonly brightBlue: 104;
189
- readonly brightMagenta: 105;
190
- readonly brightCyan: 106;
191
- readonly brightWhite: 107;
192
- };
193
- declare const STYLE: {
194
- readonly reset: 0;
195
- readonly bold: 1;
196
- readonly dim: 2;
197
- readonly italic: 3;
198
- readonly underline: 4;
199
- readonly blink: 5;
200
- readonly inverse: 7;
201
- readonly hidden: 8;
202
- readonly strikethrough: 9;
203
- };
204
- declare const sgr: (...codes: AnsiCode[]) => string;
205
- declare const reset: () => string;
206
- declare const fgRgb: (r: number, g: number, b: number) => string;
207
- declare const bgRgb: (r: number, g: number, b: number) => string;
208
- declare const fg256: (n: number) => string;
209
- declare const bg256: (n: number) => string;
210
- /**
211
- * Set the terminal window title (OSC 2). Most terminals support this.
212
- * Returns the escape sequence; caller is responsible for writing it.
213
- */
214
- declare const setTitle: (text: string) => string;
215
98
  /**
216
- * Make `text` a clickable hyperlink to `url` (OSC 8).
217
- * Supported by iTerm2, Terminal.app (macOS 13+), WezTerm, Kitty, modern xterm.
218
- * Falls back gracefully (just prints text) on terminals that don't support it.
219
- */
220
- declare const link: (text: string, url: string) => string;
221
- /** Ring the terminal bell. Most modern terminals visualize, not audio. */
222
- declare const bell: () => string;
223
- type ColorSupport = 'none' | 'basic' | '256' | 'truecolor';
224
- type ColorLevel = 0 | 1 | 2 | 3;
225
- declare const supportsColor: () => ColorSupport;
226
- declare const supportsColorLevel: () => ColorLevel;
227
- /**
228
- * Reset the cached capability — call after changing FORCE_COLOR /
229
- * NO_COLOR env vars at runtime, or before a test that needs to
230
- * exercise different code paths.
231
- */
232
- declare const resetColorSupportCache: () => void;
233
- /** Returns terminal width in columns. Falls back to DEFAULT_TERM_COLS. */
234
- declare const getTerminalWidth: () => number;
235
- /** Returns terminal height in rows. Falls back to DEFAULT_TERM_ROWS. */
236
- declare const getTerminalHeight: () => number;
237
- declare const stripAnsi$2: (str: string) => string;
238
- /** Sync write to stdout. Returns false if stdout is missing or full. */
239
- declare const write: (str: string) => boolean;
240
- /** Sync write to stderr. Useful for CLI errors and logs. */
241
- declare const writeErr: (str: string) => boolean;
242
- declare const writeln: (str?: string) => boolean;
243
- declare const writelnErr: (str?: string) => boolean;
244
- /**
245
- * Async write with backpressure handling.
246
- * - Resolves immediately when the buffer accepted the data
247
- * - Waits for `'drain'` when full
248
- * - Resolves on `'error'` instead of hanging forever
249
- * - No-ops gracefully if stdout is missing
250
- * - Optional timeout (ms) — resolves anyway after timeout to prevent
251
- * infinite hangs on broken streams
252
- */
253
- interface WriteAsyncOptions {
254
- /** Max time (ms) to wait for drain. Default: 5000. 0 disables. */
255
- timeout?: number;
256
- }
257
- declare const writeAsync: (str: string, opts?: WriteAsyncOptions) => Promise<void>;
258
- interface OutputBuffer {
259
- /** Append a string to the buffer. */
260
- push(str: string): OutputBuffer;
261
- /** Append a string with a trailing newline. */
262
- pushln(str?: string): OutputBuffer;
263
- /** Append `str` only when `cond` is truthy. Useful for conditional escapes. */
264
- pushIf(cond: unknown, str: string): OutputBuffer;
265
- /** Get the buffered content without flushing. */
266
- toString(): string;
267
- /** Number of characters currently buffered. */
268
- length(): number;
269
- /** Clear the buffer without writing. */
270
- reset(): OutputBuffer;
271
- /** Flush to stdout synchronously. Returns false on backpressure. */
272
- flush(): boolean;
273
- /** Flush to stdout asynchronously. Awaits drain on backpressure. */
274
- flushAsync(opts?: WriteAsyncOptions): Promise<void>;
275
- }
276
- declare const createOutputBuffer: () => OutputBuffer;
277
- /** Recommended frame interval (ms) for animations. ~60 fps. */
278
- declare const FRAME_MS = 16;
279
- interface SleepOptions {
280
- /** Optional AbortSignal — sleep resolves immediately when aborted. */
281
- signal?: AbortSignal;
282
- }
283
- /**
284
- * Pause for `ms` milliseconds. Cancellable via AbortSignal.
285
- * - Negative or NaN ms is clamped to 0
286
- * - Resolves silently on abort (no rejection)
287
- * - Cleans up timer + listener on every path
99
+ * Set a single config key without wrapping in an object. Convenience
100
+ * shortcut equivalent to `configure({ [key]: value })`.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { setConfigValue } from 'ansimax';
105
+ *
106
+ * setConfigValue('theme', 'dracula');
107
+ * setConfigValue('animationSpeed', 'fast');
108
+ * ```
288
109
  */
289
- declare const sleep: (ms: number, opts?: SleepOptions) => Promise<void>;
110
+ declare const setConfigValue: <K extends keyof AnsimaxConfig>(key: K, value: AnsimaxConfig[K]) => void;
290
111
  /**
291
- * Like sleep, but rounds the wait time up to the next frame boundary.
292
- * Useful inside animation loops to throttle output to a reasonable framerate.
112
+ * Alias for `onConfigChange` matches the naming convention used by
113
+ * `themes.onChange` and other observers in the codebase. Returns an
114
+ * unsubscribe function.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { subscribeConfig } from 'ansimax';
119
+ *
120
+ * const unsubscribe = subscribeConfig((newCfg, oldCfg) => {
121
+ * console.log('Config changed:', newCfg);
122
+ * });
123
+ *
124
+ * // Later: unsubscribe();
125
+ * ```
293
126
  */
294
- declare const sleepFrame: (ms?: number, opts?: SleepOptions) => Promise<void>;
127
+ declare const subscribeConfig: (listener: ConfigChangeListener) => (() => void);
295
128
 
296
129
  interface RGB {
297
130
  r: number;
@@ -326,7 +159,7 @@ declare const lerpColor: (a: RGB, b: RGB, t: number) => RGB;
326
159
  */
327
160
  declare const gradientColor: (colors: RGB[], t: number) => RGB;
328
161
  declare const rgbTo256: (r: number, g: number, b: number) => number;
329
- declare const stripAnsi$1: (str: string) => string;
162
+ declare const stripAnsi$2: (str: string) => string;
330
163
  /**
331
164
  * Width of a single character (or grapheme) in terminal cells.
332
165
  * - 0 for combining marks, ZWJ, VS, BOM
@@ -524,6 +357,286 @@ declare const safeJson: (value: unknown, indent?: number) => string;
524
357
  * padBoth('hi', 5) → ' hi '
525
358
  */
526
359
  declare const padBoth: (str: string, width: number, ch?: string) => string;
360
+ /**
361
+ * Interpolate a sequence of N colors between two endpoint hex colors.
362
+ * Useful for procedurally generating gradient stops without calling the
363
+ * full gradient pipeline.
364
+ *
365
+ * @param start - Start hex color (e.g. `'#ff0000'`).
366
+ * @param end - End hex color (e.g. `'#0000ff'`).
367
+ * @param count - Number of stops (>= 2; clamped if smaller).
368
+ * @returns Array of hex strings, including both endpoints.
369
+ *
370
+ * @example
371
+ * ```ts
372
+ * import { gradientStops } from 'ansimax';
373
+ *
374
+ * const stops = gradientStops('#ff0000', '#0000ff', 5);
375
+ * // → ['#ff0000', '#bf003f', '#7f007f', '#3f00bf', '#0000ff']
376
+ * ```
377
+ */
378
+ declare const gradientStops: (start: string, end: string, count: number) => string[];
379
+ /**
380
+ * Escape a string for safe use inside a regular expression literal.
381
+ * Escapes all 12 regex meta-characters: `. * + ? ^ $ { } ( ) | [ ] \`.
382
+ *
383
+ * @example
384
+ * ```ts
385
+ * import { escapeForRegex } from 'ansimax';
386
+ *
387
+ * const userInput = 'hello.world+code';
388
+ * const re = new RegExp(escapeForRegex(userInput));
389
+ * // Matches the literal string, not as a regex pattern
390
+ * ```
391
+ */
392
+ declare const escapeForRegex: (str: string) => string;
393
+ /**
394
+ * Measure a pre-rendered string block's dimensions: width (max visible
395
+ * width of any line) and height (line count). ANSI escapes are ignored.
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * import { measureBlock } from 'ansimax';
400
+ *
401
+ * const box = ascii.box('Hello world!');
402
+ * const { width, height } = measureBlock(box);
403
+ * // → { width: 15, height: 3 }
404
+ * ```
405
+ */
406
+ declare const measureBlock: (block: string) => {
407
+ width: number;
408
+ height: number;
409
+ };
410
+
411
+ declare const ESC = "\u001B";
412
+ declare const CSI = "\u001B[";
413
+ /** OSC sequence introducer (Operating System Command). */
414
+ declare const OSC = "\u001B]";
415
+ /** String terminator used to close OSC sequences. */
416
+ declare const ST = "\u001B\\";
417
+ /** BEL — alternative OSC terminator (older terminals). */
418
+ declare const BEL = "\u0007";
419
+ type AnsiCode = number;
420
+ /** Default fallback dimensions when stdout is not a TTY. */
421
+ declare const DEFAULT_TERM_COLS = 80;
422
+ declare const DEFAULT_TERM_ROWS = 24;
423
+ declare const cursor: {
424
+ readonly up: (n?: number) => string;
425
+ readonly down: (n?: number) => string;
426
+ readonly right: (n?: number) => string;
427
+ readonly left: (n?: number) => string;
428
+ readonly to: (x: number, y: number) => string;
429
+ /** Move cursor to absolute column n (1-based). */
430
+ readonly column: (n: number) => string;
431
+ /** Save cursor (CSI s — DEC private). */
432
+ readonly save: () => string;
433
+ /** Restore cursor (CSI u). */
434
+ readonly restore: () => string;
435
+ /** Save cursor (ESC 7 — VT100 standard). */
436
+ readonly saveCompat: () => string;
437
+ /** Restore cursor (ESC 8). */
438
+ readonly restoreCompat: () => string;
439
+ readonly hide: () => string;
440
+ readonly show: () => string;
441
+ /** Query cursor position. Terminal responds with CSI <row>;<col>R. */
442
+ readonly position: () => string;
443
+ /** Move cursor to next line (CR + line down). */
444
+ readonly nextLine: (n?: number) => string;
445
+ /** Move cursor to previous line. */
446
+ readonly prevLine: (n?: number) => string;
447
+ };
448
+ /**
449
+ * Hide cursor and register an exit handler that restores it on crash/SIGINT.
450
+ * Use this instead of writing `cursor.hide()` directly when you care about
451
+ * leaving the user's shell in a clean state.
452
+ */
453
+ declare const hideCursor: () => boolean;
454
+ declare const showCursor: () => boolean;
455
+ type EraseMode = 'down' | 'up' | 'all';
456
+ declare const screen: {
457
+ readonly clear: () => string;
458
+ /** Alias for clear() — covers `screen.clearAll()` callers. */
459
+ readonly clearAll: () => string;
460
+ readonly clearLine: () => string;
461
+ readonly clearRight: () => string;
462
+ readonly clearLeft: () => string;
463
+ readonly clearDown: () => string;
464
+ readonly clearUp: () => string;
465
+ readonly eraseDisplay: (mode?: EraseMode) => string;
466
+ readonly scrollUp: (n?: number) => string;
467
+ readonly scrollDown: (n?: number) => string;
468
+ };
469
+ declare const FG: {
470
+ readonly black: 30;
471
+ readonly red: 31;
472
+ readonly green: 32;
473
+ readonly yellow: 33;
474
+ readonly blue: 34;
475
+ readonly magenta: 35;
476
+ readonly cyan: 36;
477
+ readonly white: 37;
478
+ readonly brightBlack: 90;
479
+ readonly brightRed: 91;
480
+ readonly brightGreen: 92;
481
+ readonly brightYellow: 93;
482
+ readonly brightBlue: 94;
483
+ readonly brightMagenta: 95;
484
+ readonly brightCyan: 96;
485
+ readonly brightWhite: 97;
486
+ };
487
+ declare const BG: {
488
+ readonly black: 40;
489
+ readonly red: 41;
490
+ readonly green: 42;
491
+ readonly yellow: 43;
492
+ readonly blue: 44;
493
+ readonly magenta: 45;
494
+ readonly cyan: 46;
495
+ readonly white: 47;
496
+ readonly brightBlack: 100;
497
+ readonly brightRed: 101;
498
+ readonly brightGreen: 102;
499
+ readonly brightYellow: 103;
500
+ readonly brightBlue: 104;
501
+ readonly brightMagenta: 105;
502
+ readonly brightCyan: 106;
503
+ readonly brightWhite: 107;
504
+ };
505
+ declare const STYLE: {
506
+ readonly reset: 0;
507
+ readonly bold: 1;
508
+ readonly dim: 2;
509
+ readonly italic: 3;
510
+ readonly underline: 4;
511
+ readonly blink: 5;
512
+ readonly inverse: 7;
513
+ readonly hidden: 8;
514
+ readonly strikethrough: 9;
515
+ };
516
+ declare const sgr: (...codes: AnsiCode[]) => string;
517
+ declare const reset: () => string;
518
+ declare const fgRgb: (r: number, g: number, b: number) => string;
519
+ declare const bgRgb: (r: number, g: number, b: number) => string;
520
+ declare const fg256: (n: number) => string;
521
+ declare const bg256: (n: number) => string;
522
+ /**
523
+ * Set the terminal window title (OSC 2). Most terminals support this.
524
+ * Returns the escape sequence; caller is responsible for writing it.
525
+ */
526
+ declare const setTitle: (text: string) => string;
527
+ /**
528
+ * Make `text` a clickable hyperlink to `url` (OSC 8).
529
+ * Supported by iTerm2, Terminal.app (macOS 13+), WezTerm, Kitty, modern xterm.
530
+ * Falls back gracefully (just prints text) on terminals that don't support it.
531
+ */
532
+ declare const link: (text: string, url: string) => string;
533
+ /** Ring the terminal bell. Most modern terminals visualize, not audio. */
534
+ declare const bell: () => string;
535
+ type ColorSupport = 'none' | 'basic' | '256' | 'truecolor';
536
+ type ColorLevel = 0 | 1 | 2 | 3;
537
+ declare const supportsColor: () => ColorSupport;
538
+ declare const supportsColorLevel: () => ColorLevel;
539
+ /**
540
+ * Reset the cached capability — call after changing FORCE_COLOR /
541
+ * NO_COLOR env vars at runtime, or before a test that needs to
542
+ * exercise different code paths.
543
+ */
544
+ declare const resetColorSupportCache: () => void;
545
+ /** Returns terminal width in columns. Falls back to DEFAULT_TERM_COLS. */
546
+ declare const getTerminalWidth: () => number;
547
+ /** Returns terminal height in rows. Falls back to DEFAULT_TERM_ROWS. */
548
+ declare const getTerminalHeight: () => number;
549
+ declare const stripAnsi$1: (str: string) => string;
550
+ /** Sync write to stdout. Returns false if stdout is missing or full. */
551
+ declare const write: (str: string) => boolean;
552
+ /** Sync write to stderr. Useful for CLI errors and logs. */
553
+ declare const writeErr: (str: string) => boolean;
554
+ declare const writeln: (str?: string) => boolean;
555
+ declare const writelnErr: (str?: string) => boolean;
556
+ /**
557
+ * Async write with backpressure handling.
558
+ * - Resolves immediately when the buffer accepted the data
559
+ * - Waits for `'drain'` when full
560
+ * - Resolves on `'error'` instead of hanging forever
561
+ * - No-ops gracefully if stdout is missing
562
+ * - Optional timeout (ms) — resolves anyway after timeout to prevent
563
+ * infinite hangs on broken streams
564
+ */
565
+ interface WriteAsyncOptions {
566
+ /** Max time (ms) to wait for drain. Default: 5000. 0 disables. */
567
+ timeout?: number;
568
+ }
569
+ declare const writeAsync: (str: string, opts?: WriteAsyncOptions) => Promise<void>;
570
+ interface OutputBuffer {
571
+ /** Append a string to the buffer. */
572
+ push(str: string): OutputBuffer;
573
+ /** Append a string with a trailing newline. */
574
+ pushln(str?: string): OutputBuffer;
575
+ /** Append `str` only when `cond` is truthy. Useful for conditional escapes. */
576
+ pushIf(cond: unknown, str: string): OutputBuffer;
577
+ /** Get the buffered content without flushing. */
578
+ toString(): string;
579
+ /** Number of characters currently buffered. */
580
+ length(): number;
581
+ /** Clear the buffer without writing. */
582
+ reset(): OutputBuffer;
583
+ /** Flush to stdout synchronously. Returns false on backpressure. */
584
+ flush(): boolean;
585
+ /** Flush to stdout asynchronously. Awaits drain on backpressure. */
586
+ flushAsync(opts?: WriteAsyncOptions): Promise<void>;
587
+ }
588
+ declare const createOutputBuffer: () => OutputBuffer;
589
+ /** Recommended frame interval (ms) for animations. ~60 fps. */
590
+ declare const FRAME_MS = 16;
591
+ interface SleepOptions {
592
+ /** Optional AbortSignal — sleep resolves immediately when aborted. */
593
+ signal?: AbortSignal;
594
+ }
595
+ /**
596
+ * Pause for `ms` milliseconds. Cancellable via AbortSignal.
597
+ * - Negative or NaN ms is clamped to 0
598
+ * - Resolves silently on abort (no rejection)
599
+ * - Cleans up timer + listener on every path
600
+ */
601
+ declare const sleep: (ms: number, opts?: SleepOptions) => Promise<void>;
602
+ /**
603
+ * Like sleep, but rounds the wait time up to the next frame boundary.
604
+ * Useful inside animation loops to throttle output to a reasonable framerate.
605
+ */
606
+ declare const sleepFrame: (ms?: number, opts?: SleepOptions) => Promise<void>;
607
+ /**
608
+ * Wrap a label in an OSC 8 hyperlink escape sequence. Terminals that
609
+ * support hyperlinks (VS Code, iTerm2, WezTerm, Kitty, etc.) render it
610
+ * as clickable. Terminals without support just show the label text.
611
+ *
612
+ * @param url - Target URL (https://, mailto:, file://, etc.)
613
+ * @param label - Visible text. Defaults to the URL itself.
614
+ * @returns String with OSC 8 wrappers around the label.
615
+ *
616
+ * @example
617
+ * ```ts
618
+ * import { hyperlink } from 'ansimax';
619
+ *
620
+ * console.log(`Visit ${hyperlink('https://github.com/Brashkie/ansimax', 'the repo')}`);
621
+ * console.log(`Email: ${hyperlink('mailto:hi@example.com')}`);
622
+ * ```
623
+ */
624
+ declare const hyperlink: (url: string, label?: string) => string;
625
+ /**
626
+ * Returns the escape sequence to clear the entire current line and move
627
+ * the cursor back to column 1. Equivalent to `screen.clearLine() + '\r'`.
628
+ *
629
+ * @example
630
+ * ```ts
631
+ * import { clearLine } from 'ansimax';
632
+ *
633
+ * for (let i = 0; i <= 100; i++) {
634
+ * process.stdout.write(clearLine() + `Progress: ${i}%`);
635
+ * await sleep(30);
636
+ * }
637
+ * ```
638
+ */
639
+ declare const clearLine: () => string;
527
640
 
528
641
  type ColorFn = (text: string) => string;
529
642
 
@@ -921,6 +1034,40 @@ interface ParallelOptions {
921
1034
  */
922
1035
  type AnimFn = (text: string, opts?: Record<string, unknown>) => Promise<void>;
923
1036
  type ChainStep = AnimFn | [AnimFn] | [AnimFn, Record<string, unknown>];
1037
+ interface ShakeOptions extends AnimationHooks {
1038
+ /** Number of shake cycles. Default `5`. */
1039
+ times?: number;
1040
+ /** Pixels of horizontal displacement per frame. Default `2`. */
1041
+ intensity?: number;
1042
+ /** Milliseconds between frames. Default `50`. */
1043
+ interval?: number;
1044
+ /** Emit newline at end. Default `true`. */
1045
+ newline?: boolean;
1046
+ signal?: AbortSignal;
1047
+ reducedMotion?: boolean;
1048
+ }
1049
+ interface CountUpOptions extends AnimationHooks {
1050
+ /** Total animation duration in ms. Default `1500`. */
1051
+ duration?: number;
1052
+ /** Frame count — more = smoother but slower. Default `60`. */
1053
+ steps?: number;
1054
+ /** Decimal places to show. Default `0`. */
1055
+ decimals?: number;
1056
+ /**
1057
+ * Format the displayed value. Default: `(n) => n.toString()`.
1058
+ * Use this to add prefixes/suffixes, commas, etc.
1059
+ */
1060
+ format?: (value: number) => string;
1061
+ /**
1062
+ * Easing function — input/output both in [0, 1]. Default linear.
1063
+ * Try `(t) => t * t` for accelerate, `(t) => 1 - (1-t)**2` for decelerate.
1064
+ */
1065
+ easing?: (t: number) => number;
1066
+ /** Emit newline at end. Default `true`. */
1067
+ newline?: boolean;
1068
+ signal?: AbortSignal;
1069
+ reducedMotion?: boolean;
1070
+ }
924
1071
  declare const animate: {
925
1072
  typewriter: (text: string, opts?: TypewriterOptions) => Promise<void>;
926
1073
  fadeIn: (text: string, opts?: FadeOptions) => Promise<void>;
@@ -940,6 +1087,8 @@ declare const animate: {
940
1087
  delay: (ms: number) => (opts?: {
941
1088
  signal?: AbortSignal;
942
1089
  }) => Promise<void>;
1090
+ shake: (text: string, opts?: ShakeOptions) => Promise<void>;
1091
+ countUp: (from: number, to: number, opts?: CountUpOptions) => Promise<void>;
943
1092
  };
944
1093
 
945
1094
  interface RGBA {
@@ -1279,6 +1428,20 @@ interface BoxOptions {
1279
1428
  borderStyle?: BoxStyle;
1280
1429
  /** Fix inner content width. Lines are padded/truncated to fit. */
1281
1430
  width?: number | null;
1431
+ /**
1432
+ * Optional title shown in the top border, e.g. `─ Title ─────`.
1433
+ * When set, the box expands to fit the title if content is narrower.
1434
+ *
1435
+ * @since 1.3.3
1436
+ */
1437
+ title?: string | null;
1438
+ /**
1439
+ * Title alignment in the top border: `'left'` | `'center'` (default) | `'right'`.
1440
+ * Only applies when `title` is set.
1441
+ *
1442
+ * @since 1.3.3
1443
+ */
1444
+ titleAlign?: 'left' | 'center' | 'right';
1282
1445
  }
1283
1446
  interface BannerOptions {
1284
1447
  font?: FontName | string;
@@ -1294,6 +1457,13 @@ interface DividerOptions {
1294
1457
  width?: number | null;
1295
1458
  label?: string | null;
1296
1459
  style?: BoxStyle;
1460
+ /**
1461
+ * Label alignment: `'left'` | `'center'` (default) | `'right'`.
1462
+ * Only applies when `label` is set.
1463
+ *
1464
+ * @since 1.3.3
1465
+ */
1466
+ align?: 'left' | 'center' | 'right';
1297
1467
  }
1298
1468
  interface LogoOptions {
1299
1469
  gradient?: ColorFn | null;
@@ -2299,9 +2469,16 @@ interface FrameOptions {
2299
2469
  */
2300
2470
  bottomChar?: string;
2301
2471
  /**
2302
- * Optional title shown centered in the top edge.
2472
+ * Optional title shown in the top edge.
2303
2473
  */
2304
2474
  title?: string;
2475
+ /**
2476
+ * Title alignment: `'left'` | `'center'` (default) | `'right'`.
2477
+ * Only applies when `title` is set.
2478
+ *
2479
+ * @since 1.3.3
2480
+ */
2481
+ titleAlign?: 'left' | 'center' | 'right';
2305
2482
  }
2306
2483
  /**
2307
2484
  * Add decorative top/bottom rule lines around a block (lighter than `ascii.box`
@@ -2339,11 +2516,71 @@ interface FrameOptions {
2339
2516
  * ```
2340
2517
  */
2341
2518
  declare const frame: (block: string, opts?: FrameOptions) => string;
2519
+ interface GridOptions {
2520
+ /** Number of columns. Required. */
2521
+ columns: number;
2522
+ /** Horizontal gap between cells. Default `1`. */
2523
+ gapX?: number;
2524
+ /** Vertical gap between rows. Default `0`. */
2525
+ gapY?: number;
2526
+ /** Horizontal alignment of content within each cell. Default `'start'`. */
2527
+ alignX?: Alignment;
2528
+ /** Vertical alignment of content within each cell. Default `'start'`. */
2529
+ alignY?: Alignment;
2530
+ /**
2531
+ * Fix each cell to this width (in visible characters). If omitted, cells
2532
+ * use the max width of the widest block in their column.
2533
+ */
2534
+ cellWidth?: number | null;
2535
+ }
2536
+ /**
2537
+ * Arrange blocks in a grid of N columns, flowing left-to-right then
2538
+ * top-to-bottom. Each row is auto-sized to its tallest block, and each
2539
+ * column is auto-sized to its widest block (unless `cellWidth` is fixed).
2540
+ *
2541
+ * Internally uses `vsplit` for rows + `hsplit` for the column stack, so
2542
+ * all alignment + ANSI rules behave consistently.
2543
+ *
2544
+ * @param blocks - Pre-rendered string blocks. Flows in reading order.
2545
+ * @param opts - Grid configuration. `columns` is required.
2546
+ *
2547
+ * @example 2×2 grid of stats cards
2548
+ * ```js
2549
+ * import { panels, ascii } from 'ansimax';
2550
+ *
2551
+ * const cards = [
2552
+ * ascii.box('FILES\n42', { borderStyle: 'rounded', padding: 1 }),
2553
+ * ascii.box('LINES\n1247', { borderStyle: 'rounded', padding: 1 }),
2554
+ * ascii.box('TESTS\n38', { borderStyle: 'rounded', padding: 1 }),
2555
+ * ascii.box('COV\n98%', { borderStyle: 'rounded', padding: 1 }),
2556
+ * ];
2557
+ *
2558
+ * console.log(panels.grid(cards, { columns: 2, gapX: 2, gapY: 1 }));
2559
+ * ```
2560
+ *
2561
+ * @example 3-column gallery with auto-flow
2562
+ * ```js
2563
+ * // 7 items in 3 columns → 3 rows: [3, 3, 1]
2564
+ * const items = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven'];
2565
+ * console.log(panels.grid(items, { columns: 3, gapX: 4 }));
2566
+ * ```
2567
+ *
2568
+ * @example uniform cell width for visual consistency
2569
+ * ```js
2570
+ * console.log(panels.grid(blocks, {
2571
+ * columns: 4,
2572
+ * cellWidth: 15,
2573
+ * alignX: 'center',
2574
+ * }));
2575
+ * ```
2576
+ */
2577
+ declare const grid: (blocks: string[], opts: GridOptions) => string;
2342
2578
  declare const panels: {
2343
2579
  vsplit: (blocks: string[], opts?: VsplitOptions) => string;
2344
2580
  hsplit: (blocks: string[], opts?: HsplitOptions) => string;
2345
2581
  center: (block: string, opts: CenterOptions) => string;
2346
2582
  frame: (block: string, opts?: FrameOptions) => string;
2583
+ grid: (blocks: string[], opts: GridOptions) => string;
2347
2584
  };
2348
2585
 
2349
2586
  /**
@@ -2401,6 +2638,23 @@ interface PrettyOptions {
2401
2638
  * @since 1.3.1
2402
2639
  */
2403
2640
  inlineArrayMaxLength?: number;
2641
+ /**
2642
+ * Output mode controls what kind of string is produced:
2643
+ *
2644
+ * - `'display'` (default) — terminal-friendly output with colors (when
2645
+ * enabled) and informational placeholders like `[Circular]`,
2646
+ * `[Function: name]`, `Symbol(x)`, `Map(2) {...}`, `Set(3) {...}`,
2647
+ * `Date(2026-06-13T...)`, `BigInt(123n)`. Not parseable as JSON.
2648
+ *
2649
+ * - `'json'` — strict, parseable JSON output. Colors are forced off,
2650
+ * circular references throw `TypeError`, and types not representable
2651
+ * in JSON (functions, symbols, undefined) are omitted from objects /
2652
+ * replaced with `null` in arrays. Map/Set are converted to objects/arrays.
2653
+ * Dates become ISO strings. BigInt becomes a number (or string if too large).
2654
+ *
2655
+ * @since 1.3.3
2656
+ */
2657
+ mode?: 'display' | 'json';
2404
2658
  }
2405
2659
  /**
2406
2660
  * Pretty-print a JavaScript value with colored output suitable for
@@ -2519,6 +2773,8 @@ declare const ansimax: {
2519
2773
  delay: (ms: number) => (opts?: {
2520
2774
  signal?: AbortSignal;
2521
2775
  }) => Promise<void>;
2776
+ shake: (text: string, opts?: ShakeOptions) => Promise<void>;
2777
+ countUp: (from: number, to: number, opts?: CountUpOptions) => Promise<void>;
2522
2778
  };
2523
2779
  ascii: {
2524
2780
  big: (text: string) => string;
@@ -2618,4 +2874,4 @@ declare const ansimax: {
2618
2874
  configure: (opts?: AnsimaxConfig, meta?: ConfigureOptions) => void;
2619
2875
  };
2620
2876
 
2621
- export { ASCII_RAMPS, type Alignment, type AnimateGradientController, type AnimateGradientOptions, type AnimationHooks, type AnimationSpeed, type AnsiCode, type AnsimaxConfig, type AsciiRamp, BEL, BG, type BadgeOptions, type BallOptions, type BannerOptions, type BoxOptions, type BoxStyle, type BreatheOptions, DEFAULTS as CONFIG_DEFAULTS, CSI, type Canvas, type CanvasRenderOptions, type CenterOptions, type ColorChain, type ColorFn, type ColorLevel, type ColorMode, type ColorSupport, type ColumnsOptions, type ConfigChangeListener, type ConfigKey, type ConfigKeyListener, type ConfigureOptions, type CountdownOptions, type CustomOptions, DEFAULT_TERM_COLS, DEFAULT_TERM_ROWS, type DebounceOptions, type DiffType, type Dimensions, type DividerOptions, type DotsOptions, ESC, type EasingFn, type EasingName, type EraseMode, FG, FRAME_MS, type FadeOptions, type FigletFont, type FigletOptions, type FontMap, type FontName, type FrameCallback, type FrameHandle, type FrameOptions, type FromImageOptions, type GlitchOptions, type Glyph, type GradientOptions, type GradientRectOptions, type HsplitOptions, type PrettyOptions as JsonPrettyOptions, type LineDiff, type LiveController, type LiveOptions, type LoadingBarOptions, type LogoOptions, MENU_CANCELLED, type MemoizeOptions, type MenuInput, type MenuOptions, type MenuOutput, type MenuResult, type MultiLoader, type MultiLoaderItem, OSC, type OnResizeOptions, type OutputBuffer, type ParallelOptions, type ParallelStep, type Pixel, type PixelGrid, type PlayController, type PlayOptions, type PresetName, type ProgressAnimateOptions, type ProgressBarOptions, type ProgressOptions, type PulseOptions, type RGB, type RGBA, type RegisterFontOptions, type RenderOptions$1 as RenderOptions, type ResizeListener, type ReusableGradient, type RevealOptions, SPINNERS, SPRITES, ST, STYLE, type SectionOptions, type SleepOptions, type SlideOptions, type SpinOptions, type SpinnerType, type StatusOptions, type StatusType, type StopFn, type StreamOptions, type TableBorderStyle, type TableOptions, type Task, type TaskResult, type TasksOptions, type Theme, type BannerOpts as ThemeBannerOpts, type ThemeChangeListener, type ThemeInstance, type ThemeStyleName, type TimelineEvent, type TimelineOptions, type TreeData, type TreeDimensions, type TreeNode, type RenderOptions as TreeRenderOptions, type TreeStyle, type TypeDeleteOptions, type TypewriterOptions, type VsplitOptions, type WalkVisitor, type WaveOptions, type WriteAsyncOptions, animate, animateGradient, ascii, bell, bg256, bgRgb, box, canAnimate, cancelTerminalFrame, center$1 as center, center as centerBlock, chain, charWidth, clamp, clearAnsiCache, clearColorCache, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createGradient, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, escapeRegex, fg256, fgRgb, figletText, filterTree, findInTree, flipHorizontal, flipVertical, frame, frames, fromImage, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, graphemes, hasFont, hexToRgb, hideCursor, hsplit, images, isHexColor, isNoColor, json, pretty as jsonPretty, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureTree, memoize, nextTick, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, panels, parseFiglet, pauseListeners, presetNames, presets, rainbow, registerFont, registerPreset, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resumeListeners, reverseGradient, rgbTo256, rgbToHex, rotate90, safeJson, screen, setNoColor, setTitle, sgr, showCursor, sleep, sleepFrame, sliceAnsi, stripAnsi$1 as stripAnsi, stripAnsi$2 as stripAnsiCodes, stripAnsi as stripAnsiColors, supportsColor, supportsColorLevel, termSize, themes, throttle, tree, trees, truncateAnsi, visibleLen, vsplit, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };
2877
+ export { ASCII_RAMPS, type Alignment, type AnimateGradientController, type AnimateGradientOptions, type AnimationHooks, type AnimationSpeed, type AnsiCode, type AnsimaxConfig, type AsciiRamp, BEL, BG, type BadgeOptions, type BallOptions, type BannerOptions, type BoxOptions, type BoxStyle, type BreatheOptions, DEFAULTS as CONFIG_DEFAULTS, CSI, type Canvas, type CanvasRenderOptions, type CenterOptions, type ColorChain, type ColorFn, type ColorLevel, type ColorMode, type ColorSupport, type ColumnsOptions, type ConfigChangeListener, type ConfigKey, type ConfigKeyListener, type ConfigureOptions, type CountdownOptions, type CustomOptions, DEFAULT_TERM_COLS, DEFAULT_TERM_ROWS, type DebounceOptions, type DiffType, type Dimensions, type DividerOptions, type DotsOptions, ESC, type EasingFn, type EasingName, type EraseMode, FG, FRAME_MS, type FadeOptions, type FigletFont, type FigletOptions, type FontMap, type FontName, type FrameCallback, type FrameHandle, type FrameOptions, type FromImageOptions, type GlitchOptions, type Glyph, type GradientOptions, type GradientRectOptions, type GridOptions, type HsplitOptions, type PrettyOptions as JsonPrettyOptions, type LineDiff, type LiveController, type LiveOptions, type LoadingBarOptions, type LogoOptions, MENU_CANCELLED, type MemoizeOptions, type MenuInput, type MenuOptions, type MenuOutput, type MenuResult, type MultiLoader, type MultiLoaderItem, OSC, type OnResizeOptions, type OutputBuffer, type ParallelOptions, type ParallelStep, type Pixel, type PixelGrid, type PlayController, type PlayOptions, type PresetName, type ProgressAnimateOptions, type ProgressBarOptions, type ProgressOptions, type PulseOptions, type RGB, type RGBA, type RegisterFontOptions, type RenderOptions$1 as RenderOptions, type ResizeListener, type ReusableGradient, type RevealOptions, SPINNERS, SPRITES, ST, STYLE, type SectionOptions, type SleepOptions, type SlideOptions, type SpinOptions, type SpinnerType, type StatusOptions, type StatusType, type StopFn, type StreamOptions, type TableBorderStyle, type TableOptions, type Task, type TaskResult, type TasksOptions, type Theme, type BannerOpts as ThemeBannerOpts, type ThemeChangeListener, type ThemeInstance, type ThemeStyleName, type TimelineEvent, type TimelineOptions, type TreeData, type TreeDimensions, type TreeNode, type RenderOptions as TreeRenderOptions, type TreeStyle, type TypeDeleteOptions, type TypewriterOptions, type VsplitOptions, type WalkVisitor, type WaveOptions, type WriteAsyncOptions, animate, animateGradient, ascii, bell, bg256, bgRgb, box, canAnimate, cancelTerminalFrame, center$1 as center, center as centerBlock, chain, charWidth, clamp, clearAnsiCache, clearColorCache, clearLine, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createGradient, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, escapeForRegex, escapeRegex, fg256, fgRgb, figletText, filterTree, findInTree, flipHorizontal, flipVertical, frame, frames, fromImage, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, gradientStops, graphemes, grid, hasFont, hexToRgb, hideCursor, hsplit, hyperlink, images, isHexColor, isNoColor, json, pretty as jsonPretty, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureBlock, measureTree, memoize, nextTick, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, panels, parseFiglet, pauseListeners, presetNames, presets, rainbow, registerFont, registerPreset, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resumeListeners, reverseGradient, rgbTo256, rgbToHex, rotate90, safeJson, screen, setConfigValue, setNoColor, setTitle, sgr, showCursor, sleep, sleepFrame, sliceAnsi, stripAnsi$2 as stripAnsi, stripAnsi$1 as stripAnsiCodes, stripAnsi as stripAnsiColors, subscribeConfig, supportsColor, supportsColorLevel, termSize, themes, throttle, tree, trees, truncateAnsi, visibleLen, vsplit, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };