ansimax 1.3.3 → 1.3.5
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/CHANGELOG.md +279 -0
- package/README.es.md +61 -3
- package/README.md +61 -3
- package/dist/index.d.mts +556 -225
- package/dist/index.d.ts +556 -225
- package/dist/index.js +478 -51
- package/dist/index.mjs +460 -51
- package/examples/all-in-one.cjs +1 -1
- package/examples/all-in-one.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -95,6 +95,463 @@ 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
|
+
* 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
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
declare const setConfigValue: <K extends keyof AnsimaxConfig>(key: K, value: AnsimaxConfig[K]) => void;
|
|
111
|
+
/**
|
|
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
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
declare const subscribeConfig: (listener: ConfigChangeListener) => (() => void);
|
|
128
|
+
|
|
129
|
+
interface RGB {
|
|
130
|
+
r: number;
|
|
131
|
+
g: number;
|
|
132
|
+
b: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Type guard: true when `n` is a finite number (rejects NaN, ±Infinity,
|
|
136
|
+
* non-numbers). Useful for input validation.
|
|
137
|
+
*
|
|
138
|
+
* @since 1.3.5
|
|
139
|
+
*/
|
|
140
|
+
declare const isFiniteNumber: (n: unknown) => n is number;
|
|
141
|
+
/**
|
|
142
|
+
* Coerce any value to a safe integer. Handles non-numbers, NaN, Infinity,
|
|
143
|
+
* and floats. Consolidates the `Math.max(0, Math.floor(Number(x) || 0))`
|
|
144
|
+
* pattern that appears across the codebase.
|
|
145
|
+
*
|
|
146
|
+
* @param value - Any value (will be coerced via `Number()`).
|
|
147
|
+
* @param fallback - Returned when `value` is non-finite. Default `0`.
|
|
148
|
+
* @param min - Lower bound (inclusive). Default `-Infinity`.
|
|
149
|
+
* @param max - Upper bound (inclusive). Default `Infinity`.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* safeInt('abc') // → 0
|
|
154
|
+
* safeInt(3.7) // → 3
|
|
155
|
+
* safeInt(-5, 0, 0, 100) // → 0 (clamped to min)
|
|
156
|
+
* safeInt(NaN, 50) // → 50 (fallback)
|
|
157
|
+
* safeInt(null, 1) // → 1 (fallback — null is not a real number)
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @since 1.3.5
|
|
161
|
+
*/
|
|
162
|
+
declare const safeInt: (value: unknown, fallback?: number, min?: number, max?: number) => number;
|
|
163
|
+
declare const clamp: (n: number, min: number, max: number) => number;
|
|
164
|
+
declare const lerp: (a: number, b: number, t: number) => number;
|
|
165
|
+
/**
|
|
166
|
+
* Clamp + round a number to the 0–255 byte range. Exported as of v1.3.5.
|
|
167
|
+
*
|
|
168
|
+
* @since 1.3.5
|
|
169
|
+
*/
|
|
170
|
+
declare const clampByte: (v: number) => number;
|
|
171
|
+
/** Returns true when a string is a valid 3- or 6-digit hex color. */
|
|
172
|
+
declare const isHexColor: (hex: string) => boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Parses a hex color string to RGB. Throws on invalid input.
|
|
175
|
+
* Use isHexColor() first if you need fail-soft behaviour.
|
|
176
|
+
*/
|
|
177
|
+
declare const hexToRgb: (hex: string) => RGB;
|
|
178
|
+
/** Converts R, G, B values to a hex string. Values are clamped to 0–255. */
|
|
179
|
+
declare const rgbToHex: (r: number, g: number, b: number) => string;
|
|
180
|
+
interface HSL {
|
|
181
|
+
/** Hue in degrees, 0–360 (wraps; 360 ≡ 0). */
|
|
182
|
+
h: number;
|
|
183
|
+
/** Saturation in [0, 1] (0 = grayscale, 1 = pure color). */
|
|
184
|
+
s: number;
|
|
185
|
+
/** Lightness in [0, 1] (0 = black, 0.5 = pure, 1 = white). */
|
|
186
|
+
l: number;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Convert RGB (0–255) to HSL.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* rgbToHsl({ r: 255, g: 0, b: 0 }) // → { h: 0, s: 1, l: 0.5 }
|
|
193
|
+
* rgbToHsl({ r: 0, g: 255, b: 0 }) // → { h: 120, s: 1, l: 0.5 }
|
|
194
|
+
*
|
|
195
|
+
* @since 1.3.5
|
|
196
|
+
*/
|
|
197
|
+
declare const rgbToHsl: (rgb: RGB) => HSL;
|
|
198
|
+
/**
|
|
199
|
+
* Convert HSL to RGB (0–255). Hue wraps modulo 360.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* hslToRgb({ h: 0, s: 1, l: 0.5 }) // → { r: 255, g: 0, b: 0 }
|
|
203
|
+
* hslToRgb({ h: 240, s: 1, l: 0.5 }) // → { r: 0, g: 0, b: 255 }
|
|
204
|
+
*
|
|
205
|
+
* @since 1.3.5
|
|
206
|
+
*/
|
|
207
|
+
declare const hslToRgb: (hsl: HSL) => RGB;
|
|
208
|
+
interface Oklab {
|
|
209
|
+
/** Perceptual lightness in [0, 1]. */
|
|
210
|
+
L: number;
|
|
211
|
+
/** Green↔Red axis, roughly [-0.4, 0.4]. */
|
|
212
|
+
a: number;
|
|
213
|
+
/** Blue↔Yellow axis, roughly [-0.4, 0.4]. */
|
|
214
|
+
b: number;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Convert RGB (0–255) to Oklab. Perceptually uniform — interpolating in
|
|
218
|
+
* this space produces smoother gradients than naive RGB.
|
|
219
|
+
*
|
|
220
|
+
* @since 1.3.5
|
|
221
|
+
*/
|
|
222
|
+
declare const rgbToOklab: (rgb: RGB) => Oklab;
|
|
223
|
+
/**
|
|
224
|
+
* Convert Oklab back to RGB (0–255). Out-of-gamut values are clamped.
|
|
225
|
+
*
|
|
226
|
+
* @since 1.3.5
|
|
227
|
+
*/
|
|
228
|
+
declare const oklabToRgb: (oklab: Oklab) => RGB;
|
|
229
|
+
/** Color space to interpolate in. Default `'rgb'` for backward compatibility. */
|
|
230
|
+
type ColorSpace = 'rgb' | 'hsl' | 'oklab';
|
|
231
|
+
/**
|
|
232
|
+
* Linearly interpolate between two RGB colors. `t` is clamped to [0, 1].
|
|
233
|
+
*
|
|
234
|
+
* **v1.3.5+**: Accepts an optional 4th argument `space` to control which
|
|
235
|
+
* color space the interpolation happens in. `'oklab'` produces the
|
|
236
|
+
* smoothest, most perceptually uniform gradients but is ~3× slower than
|
|
237
|
+
* naive RGB. `'hsl'` is useful for hue rotation.
|
|
238
|
+
*
|
|
239
|
+
* @param a - Start color (RGB, 0–255).
|
|
240
|
+
* @param b - End color (RGB, 0–255).
|
|
241
|
+
* @param t - Mixing factor in [0, 1] (clamped).
|
|
242
|
+
* @param space - Interpolation space. Default `'rgb'` (backward-compat).
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* lerpColor(red, blue, 0.5); // naive RGB midpoint
|
|
247
|
+
* lerpColor(red, blue, 0.5, 'oklab'); // perceptual midpoint
|
|
248
|
+
* lerpColor(red, blue, 0.5, 'hsl'); // through purple via hue
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
declare const lerpColor: (a: RGB, b: RGB, t: number, space?: ColorSpace) => RGB;
|
|
252
|
+
/**
|
|
253
|
+
* Semantic alias for `lerpColor`. Reads more naturally for the "blend
|
|
254
|
+
* two colors" use case, especially with a named color space.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* mixColors('#ff0000', '#0000ff', 0.5, 'oklab');
|
|
259
|
+
* // Accepts hex strings OR RGB objects
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @since 1.3.5
|
|
263
|
+
*/
|
|
264
|
+
declare const mixColors: (a: RGB | string, b: RGB | string, t: number, space?: ColorSpace) => RGB;
|
|
265
|
+
/**
|
|
266
|
+
* Quantize a color to N levels per channel. Useful for palette
|
|
267
|
+
* reduction, posterization effects, or matching a constrained color
|
|
268
|
+
* palette (e.g., 16-color terminals).
|
|
269
|
+
*
|
|
270
|
+
* Mathematically: maps each channel to the nearest of `levels` evenly
|
|
271
|
+
* spaced values in [0, 255]. With `levels=2` you get pure on/off per
|
|
272
|
+
* channel (8 colors total). With `levels=4` you get a 64-color palette.
|
|
273
|
+
*
|
|
274
|
+
* @param color - Input RGB (0–255).
|
|
275
|
+
* @param levels - Number of discrete levels per channel (≥2, default `4`).
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* quantizeColor({ r: 100, g: 150, b: 200 }, 4);
|
|
280
|
+
* // → snaps each channel to nearest of [0, 85, 170, 255]
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* @since 1.3.5
|
|
284
|
+
*/
|
|
285
|
+
declare const quantizeColor: (color: RGB, levels?: number) => RGB;
|
|
286
|
+
/**
|
|
287
|
+
* Multi-stop gradient interpolation. Given a list of color stops and t in [0, 1],
|
|
288
|
+
* returns the interpolated RGB. Equivalent to a CSS `linear-gradient` sampler.
|
|
289
|
+
*
|
|
290
|
+
* Defensive: empty colors throws (no sensible default), single color returns
|
|
291
|
+
* that color regardless of t, t outside [0,1] is clamped automatically.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* gradientColor([red, yellow, green], 0.5) → yellow
|
|
295
|
+
* gradientColor([red, blue], 0.0) → red
|
|
296
|
+
* gradientColor([red, blue], -1) → red (t clamped to 0)
|
|
297
|
+
* gradientColor([red, blue], 99) → blue (t clamped to 1)
|
|
298
|
+
*/
|
|
299
|
+
declare const gradientColor: (colors: RGB[], t: number, space?: ColorSpace) => RGB;
|
|
300
|
+
declare const rgbTo256: (r: number, g: number, b: number) => number;
|
|
301
|
+
declare const stripAnsi$2: (str: string) => string;
|
|
302
|
+
/**
|
|
303
|
+
* Width of a single character (or grapheme) in terminal cells.
|
|
304
|
+
* - 0 for combining marks, ZWJ, VS, BOM
|
|
305
|
+
* - 2 for wide CJK / emoji presentation
|
|
306
|
+
* - 1 for everything else
|
|
307
|
+
*/
|
|
308
|
+
declare const charWidth: (char: string) => number;
|
|
309
|
+
/**
|
|
310
|
+
* Iterate grapheme clusters in a string. A grapheme is a user-perceived
|
|
311
|
+
* character — e.g. '👨👩👧👦' is one grapheme even though it's 7 codepoints.
|
|
312
|
+
*
|
|
313
|
+
* Uses Intl.Segmenter when available, otherwise falls back to Unicode
|
|
314
|
+
* codepoint iteration via [...str].
|
|
315
|
+
*/
|
|
316
|
+
declare const graphemes: (str: string) => Generator<string, void, unknown>;
|
|
317
|
+
/**
|
|
318
|
+
* Visible terminal width of a string.
|
|
319
|
+
*
|
|
320
|
+
* Strips ANSI escapes first, then sums grapheme cluster widths using
|
|
321
|
+
* the Unicode-aware `charWidth()`. This is the function every layout
|
|
322
|
+
* helper (padding, centering, table columns) should use.
|
|
323
|
+
*/
|
|
324
|
+
declare const visibleLen: (str: string) => number;
|
|
325
|
+
declare const sliceAnsi: (str: string, start: number, end?: number) => string;
|
|
326
|
+
/**
|
|
327
|
+
* Truncates a string with ANSI escapes to a max visible width.
|
|
328
|
+
* Preserves color codes that started before the cut and emits a final reset.
|
|
329
|
+
* Now Unicode-aware (handles CJK, emoji, graphemes correctly).
|
|
330
|
+
*/
|
|
331
|
+
declare const truncateAnsi: (str: string, width: number, ellipsis?: string) => string;
|
|
332
|
+
declare const padEnd: (str: string, width: number, ch?: string) => string;
|
|
333
|
+
declare const padStart: (str: string, width: number, ch?: string) => string;
|
|
334
|
+
declare const center$1: (str: string, width: number, ch?: string) => string;
|
|
335
|
+
/** Repeats a string until its visible length reaches the target width. */
|
|
336
|
+
declare const repeatVisible: (str: string, width: number) => string;
|
|
337
|
+
/**
|
|
338
|
+
* Current terminal size. Reads from process.stdout each call so callers
|
|
339
|
+
* always get up-to-date dimensions after a resize.
|
|
340
|
+
*
|
|
341
|
+
* Falls back to 80×24 (classic VT100 default) if stdout doesn't expose
|
|
342
|
+
* dimensions. Negative or non-number values are also handled.
|
|
343
|
+
*/
|
|
344
|
+
declare const termSize: () => {
|
|
345
|
+
cols: number;
|
|
346
|
+
rows: number;
|
|
347
|
+
};
|
|
348
|
+
type ResizeListener = (size: {
|
|
349
|
+
cols: number;
|
|
350
|
+
rows: number;
|
|
351
|
+
}) => void;
|
|
352
|
+
interface OnResizeOptions {
|
|
353
|
+
/**
|
|
354
|
+
* Throttle interval in ms. Coalesces rapid resize events (which can
|
|
355
|
+
* fire dozens per second during active drag-resize). Default: 50ms.
|
|
356
|
+
* Pass 0 to disable throttling.
|
|
357
|
+
*/
|
|
358
|
+
throttle?: number;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Subscribe to terminal resize events. Returns a function that unsubscribes.
|
|
362
|
+
* Useful for dashboards and live UIs that need responsive re-layout.
|
|
363
|
+
*
|
|
364
|
+
* By default coalesces rapid resize events at ~20fps (50ms throttle) to
|
|
365
|
+
* avoid flooding the redraw path.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* const off = onResize(({ cols, rows }) => redraw(cols, rows));
|
|
369
|
+
* // Later: off();
|
|
370
|
+
*/
|
|
371
|
+
declare const onResize: (listener: ResizeListener, opts?: OnResizeOptions) => (() => void);
|
|
372
|
+
/**
|
|
373
|
+
* ANSI-aware word wrap. Tokens are split by whitespace, but ANSI escape
|
|
374
|
+
* sequences within tokens are preserved verbatim. Visible width is
|
|
375
|
+
* computed Unicode-correctly. Tokens longer than `width` are soft-broken
|
|
376
|
+
* into chunks that respect ANSI boundaries.
|
|
377
|
+
*/
|
|
378
|
+
declare const wrapAnsi: (text: string, width: number) => string[];
|
|
379
|
+
/**
|
|
380
|
+
* Backwards-compat alias. Newer code should use `wrapAnsi`.
|
|
381
|
+
* Identical behavior — wrapAnsi is the same algorithm but ANSI-aware.
|
|
382
|
+
*/
|
|
383
|
+
declare const wordWrap: (text: string, width: number) => string[];
|
|
384
|
+
interface DebounceOptions {
|
|
385
|
+
/**
|
|
386
|
+
* Maximum time (ms) to wait before forcing invocation, even if calls
|
|
387
|
+
* keep arriving. Useful for resize handlers — without maxWait, an
|
|
388
|
+
* actively-resized window never fires its handler.
|
|
389
|
+
*/
|
|
390
|
+
maxWait?: number;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Debounce a function: delay invocation until `ms` have passed since the
|
|
394
|
+
* last call. Optional `maxWait` guarantees invocation within that window
|
|
395
|
+
* even if calls keep coming.
|
|
396
|
+
*/
|
|
397
|
+
declare const debounce: <T extends (...args: never[]) => unknown>(fn: T, ms: number, opts?: DebounceOptions) => T & {
|
|
398
|
+
cancel(): void;
|
|
399
|
+
flush(): void;
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Throttle a function: invoke at most once per `ms` window. The first
|
|
403
|
+
* call fires immediately; subsequent calls inside the window are
|
|
404
|
+
* coalesced and the last one fires when the window expires.
|
|
405
|
+
*/
|
|
406
|
+
declare const throttle: <T extends (...args: never[]) => unknown>(fn: T, ms: number) => T & {
|
|
407
|
+
cancel(): void;
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* Schedules a callback for the next animation frame (~16ms).
|
|
411
|
+
* Inspired by browser `requestAnimationFrame` — useful for coalescing
|
|
412
|
+
* multiple render requests into a single paint.
|
|
413
|
+
*
|
|
414
|
+
* Returns a handle that can be passed to `cancelTerminalFrame()`.
|
|
415
|
+
*/
|
|
416
|
+
type FrameHandle = ReturnType<typeof setTimeout>;
|
|
417
|
+
declare const requestTerminalFrame: (cb: () => void) => FrameHandle;
|
|
418
|
+
declare const cancelTerminalFrame: (handle: FrameHandle) => void;
|
|
419
|
+
/**
|
|
420
|
+
* Coalesce sync work to the next event loop turn (microtask + I/O).
|
|
421
|
+
* Falls back to setTimeout(0) in environments without setImmediate.
|
|
422
|
+
*/
|
|
423
|
+
declare const nextTick: (cb: () => void) => void;
|
|
424
|
+
interface MemoizeOptions<A extends unknown[]> {
|
|
425
|
+
/** Max cached entries before FIFO eviction. Default: 100. */
|
|
426
|
+
max?: number;
|
|
427
|
+
/**
|
|
428
|
+
* Key extractor — given the args, returns the cache key.
|
|
429
|
+
* Use to memoize multi-arg fns: `keyFn: (a, b) => a + ':' + b`.
|
|
430
|
+
* Default: first arg.
|
|
431
|
+
*/
|
|
432
|
+
keyFn?: (...args: A) => unknown;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Memoize a function with bounded FIFO cache.
|
|
436
|
+
*
|
|
437
|
+
* Single-arg simple form (passes the arg as cache key):
|
|
438
|
+
* memoize((n: number) => expensive(n))
|
|
439
|
+
*
|
|
440
|
+
* Multi-arg with key extractor:
|
|
441
|
+
* memoize((a, b, c) => f(a,b,c), { keyFn: (a, b, c) => `${a}:${b}:${c}` })
|
|
442
|
+
*
|
|
443
|
+
* Returns the memoized fn with `clear()` and `size()` methods.
|
|
444
|
+
*/
|
|
445
|
+
declare const memoize: <A extends unknown[], V>(fn: (...args: A) => V, optsOrMax?: number | MemoizeOptions<A>) => ((...args: A) => V) & {
|
|
446
|
+
clear(): void;
|
|
447
|
+
size(): number;
|
|
448
|
+
};
|
|
449
|
+
type DiffType = 'added' | 'removed' | 'changed';
|
|
450
|
+
interface LineDiff {
|
|
451
|
+
/** Index of the line that changed. */
|
|
452
|
+
index: number;
|
|
453
|
+
/** New content of that line (empty string for 'removed'). */
|
|
454
|
+
line: string;
|
|
455
|
+
/** What kind of change this line represents. */
|
|
456
|
+
type: DiffType;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Compute line-level differences between two multi-line frames.
|
|
460
|
+
* Returns only the lines that changed, with their indices and type.
|
|
461
|
+
*
|
|
462
|
+
* Useful for damage-tracked redraws: instead of clearing and re-rendering
|
|
463
|
+
* the full frame, redraw only the changed lines.
|
|
464
|
+
*/
|
|
465
|
+
declare const diffLines: (oldFrame: string, newFrame: string) => LineDiff[];
|
|
466
|
+
/**
|
|
467
|
+
* Wraps a function so it only invokes the underlying fn ONCE.
|
|
468
|
+
* Subsequent calls return the cached first result. Useful for one-time
|
|
469
|
+
* setup / lazy initialization that must not run twice.
|
|
470
|
+
*/
|
|
471
|
+
declare const once: <T extends (...args: never[]) => unknown>(fn: T) => T;
|
|
472
|
+
/**
|
|
473
|
+
* Escape a string for safe use inside a regex literal. Escapes
|
|
474
|
+
* `.`, `*`, `+`, `?`, `^`, `$`, `(`, `)`, `[`, `]`, `{`, `}`, `|`,
|
|
475
|
+
* `\`, `/`.
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* new RegExp(escapeRegex('a.b+c')); // matches "a.b+c" literally
|
|
479
|
+
*/
|
|
480
|
+
declare const escapeRegex: (str: string) => string;
|
|
481
|
+
/**
|
|
482
|
+
* JSON.stringify replacement that handles BigInt and circular refs.
|
|
483
|
+
* BigInt is serialized as its string form. Circular references emit
|
|
484
|
+
* `"[Circular]"` placeholder instead of throwing.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* safeJson({ n: 1n, ref: obj }); // never throws
|
|
488
|
+
*/
|
|
489
|
+
declare const safeJson: (value: unknown, indent?: number) => string;
|
|
490
|
+
/**
|
|
491
|
+
* Pad a string equally on both sides until it reaches `width`.
|
|
492
|
+
* If the padding can't be split evenly, the right side gets the extra char.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* padBoth('hi', 6) → ' hi '
|
|
496
|
+
* padBoth('hi', 5) → ' hi '
|
|
497
|
+
*/
|
|
498
|
+
declare const padBoth: (str: string, width: number, ch?: string) => string;
|
|
499
|
+
/**
|
|
500
|
+
* Interpolate a sequence of N colors between two endpoint hex colors.
|
|
501
|
+
* Useful for procedurally generating gradient stops without calling the
|
|
502
|
+
* full gradient pipeline.
|
|
503
|
+
*
|
|
504
|
+
* @param start - Start hex color (e.g. `'#ff0000'`).
|
|
505
|
+
* @param end - End hex color (e.g. `'#0000ff'`).
|
|
506
|
+
* @param count - Number of stops (>= 2; clamped if smaller).
|
|
507
|
+
* @param space - **v1.3.5+** Color space for interpolation:
|
|
508
|
+
* `'rgb'` (default, fast), `'hsl'` (hue rotation),
|
|
509
|
+
* or `'oklab'` (perceptually uniform).
|
|
510
|
+
* @returns Array of hex strings, including both endpoints.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* ```ts
|
|
514
|
+
* import { gradientStops } from 'ansimax';
|
|
515
|
+
*
|
|
516
|
+
* // Naive RGB (default)
|
|
517
|
+
* const stops = gradientStops('#ff0000', '#0000ff', 5);
|
|
518
|
+
*
|
|
519
|
+
* // Perceptually uniform (smoother visual transition)
|
|
520
|
+
* const smooth = gradientStops('#ff0000', '#0000ff', 5, 'oklab');
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
declare const gradientStops: (start: string, end: string, count: number, space?: ColorSpace) => string[];
|
|
524
|
+
/**
|
|
525
|
+
* Escape a string for safe use inside a regular expression literal.
|
|
526
|
+
* Escapes all 12 regex meta-characters: `. * + ? ^ $ { } ( ) | [ ] \`.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```ts
|
|
530
|
+
* import { escapeForRegex } from 'ansimax';
|
|
531
|
+
*
|
|
532
|
+
* const userInput = 'hello.world+code';
|
|
533
|
+
* const re = new RegExp(escapeForRegex(userInput));
|
|
534
|
+
* // Matches the literal string, not as a regex pattern
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
declare const escapeForRegex: (str: string) => string;
|
|
538
|
+
/**
|
|
539
|
+
* Measure a pre-rendered string block's dimensions: width (max visible
|
|
540
|
+
* width of any line) and height (line count). ANSI escapes are ignored.
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* ```ts
|
|
544
|
+
* import { measureBlock } from 'ansimax';
|
|
545
|
+
*
|
|
546
|
+
* const box = ascii.box('Hello world!');
|
|
547
|
+
* const { width, height } = measureBlock(box);
|
|
548
|
+
* // → { width: 15, height: 3 }
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
declare const measureBlock: (block: string) => {
|
|
552
|
+
width: number;
|
|
553
|
+
height: number;
|
|
554
|
+
};
|
|
98
555
|
|
|
99
556
|
declare const ESC = "\u001B";
|
|
100
557
|
declare const CSI = "\u001B[";
|
|
@@ -234,7 +691,7 @@ declare const resetColorSupportCache: () => void;
|
|
|
234
691
|
declare const getTerminalWidth: () => number;
|
|
235
692
|
/** Returns terminal height in rows. Falls back to DEFAULT_TERM_ROWS. */
|
|
236
693
|
declare const getTerminalHeight: () => number;
|
|
237
|
-
declare const stripAnsi$
|
|
694
|
+
declare const stripAnsi$1: (str: string) => string;
|
|
238
695
|
/** Sync write to stdout. Returns false if stdout is missing or full. */
|
|
239
696
|
declare const write: (str: string) => boolean;
|
|
240
697
|
/** Sync write to stderr. Useful for CLI errors and logs. */
|
|
@@ -292,238 +749,39 @@ declare const sleep: (ms: number, opts?: SleepOptions) => Promise<void>;
|
|
|
292
749
|
* Useful inside animation loops to throttle output to a reasonable framerate.
|
|
293
750
|
*/
|
|
294
751
|
declare const sleepFrame: (ms?: number, opts?: SleepOptions) => Promise<void>;
|
|
295
|
-
|
|
296
|
-
interface RGB {
|
|
297
|
-
r: number;
|
|
298
|
-
g: number;
|
|
299
|
-
b: number;
|
|
300
|
-
}
|
|
301
|
-
declare const clamp: (n: number, min: number, max: number) => number;
|
|
302
|
-
declare const lerp: (a: number, b: number, t: number) => number;
|
|
303
|
-
/** Returns true when a string is a valid 3- or 6-digit hex color. */
|
|
304
|
-
declare const isHexColor: (hex: string) => boolean;
|
|
305
|
-
/**
|
|
306
|
-
* Parses a hex color string to RGB. Throws on invalid input.
|
|
307
|
-
* Use isHexColor() first if you need fail-soft behaviour.
|
|
308
|
-
*/
|
|
309
|
-
declare const hexToRgb: (hex: string) => RGB;
|
|
310
|
-
/** Converts R, G, B values to a hex string. Values are clamped to 0–255. */
|
|
311
|
-
declare const rgbToHex: (r: number, g: number, b: number) => string;
|
|
312
|
-
/** Linearly interpolates between two RGB colors. t is clamped to [0, 1]. */
|
|
313
|
-
declare const lerpColor: (a: RGB, b: RGB, t: number) => RGB;
|
|
314
|
-
/**
|
|
315
|
-
* Multi-stop gradient interpolation. Given a list of color stops and t in [0, 1],
|
|
316
|
-
* returns the interpolated RGB. Equivalent to a CSS `linear-gradient` sampler.
|
|
317
|
-
*
|
|
318
|
-
* Defensive: empty colors throws (no sensible default), single color returns
|
|
319
|
-
* that color regardless of t, t outside [0,1] is clamped automatically.
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* gradientColor([red, yellow, green], 0.5) → yellow
|
|
323
|
-
* gradientColor([red, blue], 0.0) → red
|
|
324
|
-
* gradientColor([red, blue], -1) → red (t clamped to 0)
|
|
325
|
-
* gradientColor([red, blue], 99) → blue (t clamped to 1)
|
|
326
|
-
*/
|
|
327
|
-
declare const gradientColor: (colors: RGB[], t: number) => RGB;
|
|
328
|
-
declare const rgbTo256: (r: number, g: number, b: number) => number;
|
|
329
|
-
declare const stripAnsi$1: (str: string) => string;
|
|
330
|
-
/**
|
|
331
|
-
* Width of a single character (or grapheme) in terminal cells.
|
|
332
|
-
* - 0 for combining marks, ZWJ, VS, BOM
|
|
333
|
-
* - 2 for wide CJK / emoji presentation
|
|
334
|
-
* - 1 for everything else
|
|
335
|
-
*/
|
|
336
|
-
declare const charWidth: (char: string) => number;
|
|
337
|
-
/**
|
|
338
|
-
* Iterate grapheme clusters in a string. A grapheme is a user-perceived
|
|
339
|
-
* character — e.g. '👨👩👧👦' is one grapheme even though it's 7 codepoints.
|
|
340
|
-
*
|
|
341
|
-
* Uses Intl.Segmenter when available, otherwise falls back to Unicode
|
|
342
|
-
* codepoint iteration via [...str].
|
|
343
|
-
*/
|
|
344
|
-
declare const graphemes: (str: string) => Generator<string, void, unknown>;
|
|
345
|
-
/**
|
|
346
|
-
* Visible terminal width of a string.
|
|
347
|
-
*
|
|
348
|
-
* Strips ANSI escapes first, then sums grapheme cluster widths using
|
|
349
|
-
* the Unicode-aware `charWidth()`. This is the function every layout
|
|
350
|
-
* helper (padding, centering, table columns) should use.
|
|
351
|
-
*/
|
|
352
|
-
declare const visibleLen: (str: string) => number;
|
|
353
|
-
declare const sliceAnsi: (str: string, start: number, end?: number) => string;
|
|
354
|
-
/**
|
|
355
|
-
* Truncates a string with ANSI escapes to a max visible width.
|
|
356
|
-
* Preserves color codes that started before the cut and emits a final reset.
|
|
357
|
-
* Now Unicode-aware (handles CJK, emoji, graphemes correctly).
|
|
358
|
-
*/
|
|
359
|
-
declare const truncateAnsi: (str: string, width: number, ellipsis?: string) => string;
|
|
360
|
-
declare const padEnd: (str: string, width: number, ch?: string) => string;
|
|
361
|
-
declare const padStart: (str: string, width: number, ch?: string) => string;
|
|
362
|
-
declare const center$1: (str: string, width: number, ch?: string) => string;
|
|
363
|
-
/** Repeats a string until its visible length reaches the target width. */
|
|
364
|
-
declare const repeatVisible: (str: string, width: number) => string;
|
|
365
|
-
/**
|
|
366
|
-
* Current terminal size. Reads from process.stdout each call so callers
|
|
367
|
-
* always get up-to-date dimensions after a resize.
|
|
368
|
-
*
|
|
369
|
-
* Falls back to 80×24 (classic VT100 default) if stdout doesn't expose
|
|
370
|
-
* dimensions. Negative or non-number values are also handled.
|
|
371
|
-
*/
|
|
372
|
-
declare const termSize: () => {
|
|
373
|
-
cols: number;
|
|
374
|
-
rows: number;
|
|
375
|
-
};
|
|
376
|
-
type ResizeListener = (size: {
|
|
377
|
-
cols: number;
|
|
378
|
-
rows: number;
|
|
379
|
-
}) => void;
|
|
380
|
-
interface OnResizeOptions {
|
|
381
|
-
/**
|
|
382
|
-
* Throttle interval in ms. Coalesces rapid resize events (which can
|
|
383
|
-
* fire dozens per second during active drag-resize). Default: 50ms.
|
|
384
|
-
* Pass 0 to disable throttling.
|
|
385
|
-
*/
|
|
386
|
-
throttle?: number;
|
|
387
|
-
}
|
|
388
752
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
753
|
+
* Wrap a label in an OSC 8 hyperlink escape sequence. Terminals that
|
|
754
|
+
* support hyperlinks (VS Code, iTerm2, WezTerm, Kitty, etc.) render it
|
|
755
|
+
* as clickable. Terminals without support just show the label text.
|
|
391
756
|
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
757
|
+
* @param url - Target URL (https://, mailto:, file://, etc.)
|
|
758
|
+
* @param label - Visible text. Defaults to the URL itself.
|
|
759
|
+
* @returns String with OSC 8 wrappers around the label.
|
|
394
760
|
*
|
|
395
761
|
* @example
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*/
|
|
399
|
-
declare const onResize: (listener: ResizeListener, opts?: OnResizeOptions) => (() => void);
|
|
400
|
-
/**
|
|
401
|
-
* ANSI-aware word wrap. Tokens are split by whitespace, but ANSI escape
|
|
402
|
-
* sequences within tokens are preserved verbatim. Visible width is
|
|
403
|
-
* computed Unicode-correctly. Tokens longer than `width` are soft-broken
|
|
404
|
-
* into chunks that respect ANSI boundaries.
|
|
405
|
-
*/
|
|
406
|
-
declare const wrapAnsi: (text: string, width: number) => string[];
|
|
407
|
-
/**
|
|
408
|
-
* Backwards-compat alias. Newer code should use `wrapAnsi`.
|
|
409
|
-
* Identical behavior — wrapAnsi is the same algorithm but ANSI-aware.
|
|
410
|
-
*/
|
|
411
|
-
declare const wordWrap: (text: string, width: number) => string[];
|
|
412
|
-
interface DebounceOptions {
|
|
413
|
-
/**
|
|
414
|
-
* Maximum time (ms) to wait before forcing invocation, even if calls
|
|
415
|
-
* keep arriving. Useful for resize handlers — without maxWait, an
|
|
416
|
-
* actively-resized window never fires its handler.
|
|
417
|
-
*/
|
|
418
|
-
maxWait?: number;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Debounce a function: delay invocation until `ms` have passed since the
|
|
422
|
-
* last call. Optional `maxWait` guarantees invocation within that window
|
|
423
|
-
* even if calls keep coming.
|
|
424
|
-
*/
|
|
425
|
-
declare const debounce: <T extends (...args: never[]) => unknown>(fn: T, ms: number, opts?: DebounceOptions) => T & {
|
|
426
|
-
cancel(): void;
|
|
427
|
-
flush(): void;
|
|
428
|
-
};
|
|
429
|
-
/**
|
|
430
|
-
* Throttle a function: invoke at most once per `ms` window. The first
|
|
431
|
-
* call fires immediately; subsequent calls inside the window are
|
|
432
|
-
* coalesced and the last one fires when the window expires.
|
|
433
|
-
*/
|
|
434
|
-
declare const throttle: <T extends (...args: never[]) => unknown>(fn: T, ms: number) => T & {
|
|
435
|
-
cancel(): void;
|
|
436
|
-
};
|
|
437
|
-
/**
|
|
438
|
-
* Schedules a callback for the next animation frame (~16ms).
|
|
439
|
-
* Inspired by browser `requestAnimationFrame` — useful for coalescing
|
|
440
|
-
* multiple render requests into a single paint.
|
|
441
|
-
*
|
|
442
|
-
* Returns a handle that can be passed to `cancelTerminalFrame()`.
|
|
443
|
-
*/
|
|
444
|
-
type FrameHandle = ReturnType<typeof setTimeout>;
|
|
445
|
-
declare const requestTerminalFrame: (cb: () => void) => FrameHandle;
|
|
446
|
-
declare const cancelTerminalFrame: (handle: FrameHandle) => void;
|
|
447
|
-
/**
|
|
448
|
-
* Coalesce sync work to the next event loop turn (microtask + I/O).
|
|
449
|
-
* Falls back to setTimeout(0) in environments without setImmediate.
|
|
450
|
-
*/
|
|
451
|
-
declare const nextTick: (cb: () => void) => void;
|
|
452
|
-
interface MemoizeOptions<A extends unknown[]> {
|
|
453
|
-
/** Max cached entries before FIFO eviction. Default: 100. */
|
|
454
|
-
max?: number;
|
|
455
|
-
/**
|
|
456
|
-
* Key extractor — given the args, returns the cache key.
|
|
457
|
-
* Use to memoize multi-arg fns: `keyFn: (a, b) => a + ':' + b`.
|
|
458
|
-
* Default: first arg.
|
|
459
|
-
*/
|
|
460
|
-
keyFn?: (...args: A) => unknown;
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Memoize a function with bounded FIFO cache.
|
|
464
|
-
*
|
|
465
|
-
* Single-arg simple form (passes the arg as cache key):
|
|
466
|
-
* memoize((n: number) => expensive(n))
|
|
467
|
-
*
|
|
468
|
-
* Multi-arg with key extractor:
|
|
469
|
-
* memoize((a, b, c) => f(a,b,c), { keyFn: (a, b, c) => `${a}:${b}:${c}` })
|
|
470
|
-
*
|
|
471
|
-
* Returns the memoized fn with `clear()` and `size()` methods.
|
|
472
|
-
*/
|
|
473
|
-
declare const memoize: <A extends unknown[], V>(fn: (...args: A) => V, optsOrMax?: number | MemoizeOptions<A>) => ((...args: A) => V) & {
|
|
474
|
-
clear(): void;
|
|
475
|
-
size(): number;
|
|
476
|
-
};
|
|
477
|
-
type DiffType = 'added' | 'removed' | 'changed';
|
|
478
|
-
interface LineDiff {
|
|
479
|
-
/** Index of the line that changed. */
|
|
480
|
-
index: number;
|
|
481
|
-
/** New content of that line (empty string for 'removed'). */
|
|
482
|
-
line: string;
|
|
483
|
-
/** What kind of change this line represents. */
|
|
484
|
-
type: DiffType;
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Compute line-level differences between two multi-line frames.
|
|
488
|
-
* Returns only the lines that changed, with their indices and type.
|
|
489
|
-
*
|
|
490
|
-
* Useful for damage-tracked redraws: instead of clearing and re-rendering
|
|
491
|
-
* the full frame, redraw only the changed lines.
|
|
492
|
-
*/
|
|
493
|
-
declare const diffLines: (oldFrame: string, newFrame: string) => LineDiff[];
|
|
494
|
-
/**
|
|
495
|
-
* Wraps a function so it only invokes the underlying fn ONCE.
|
|
496
|
-
* Subsequent calls return the cached first result. Useful for one-time
|
|
497
|
-
* setup / lazy initialization that must not run twice.
|
|
498
|
-
*/
|
|
499
|
-
declare const once: <T extends (...args: never[]) => unknown>(fn: T) => T;
|
|
500
|
-
/**
|
|
501
|
-
* Escape a string for safe use inside a regex literal. Escapes
|
|
502
|
-
* `.`, `*`, `+`, `?`, `^`, `$`, `(`, `)`, `[`, `]`, `{`, `}`, `|`,
|
|
503
|
-
* `\`, `/`.
|
|
762
|
+
* ```ts
|
|
763
|
+
* import { hyperlink } from 'ansimax';
|
|
504
764
|
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
765
|
+
* console.log(`Visit ${hyperlink('https://github.com/Brashkie/ansimax', 'the repo')}`);
|
|
766
|
+
* console.log(`Email: ${hyperlink('mailto:hi@example.com')}`);
|
|
767
|
+
* ```
|
|
507
768
|
*/
|
|
508
|
-
declare const
|
|
769
|
+
declare const hyperlink: (url: string, label?: string) => string;
|
|
509
770
|
/**
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* `"[Circular]"` placeholder instead of throwing.
|
|
771
|
+
* Returns the escape sequence to clear the entire current line and move
|
|
772
|
+
* the cursor back to column 1. Equivalent to `screen.clearLine() + '\r'`.
|
|
513
773
|
*
|
|
514
774
|
* @example
|
|
515
|
-
*
|
|
516
|
-
|
|
517
|
-
declare const safeJson: (value: unknown, indent?: number) => string;
|
|
518
|
-
/**
|
|
519
|
-
* Pad a string equally on both sides until it reaches `width`.
|
|
520
|
-
* If the padding can't be split evenly, the right side gets the extra char.
|
|
775
|
+
* ```ts
|
|
776
|
+
* import { clearLine } from 'ansimax';
|
|
521
777
|
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
778
|
+
* for (let i = 0; i <= 100; i++) {
|
|
779
|
+
* process.stdout.write(clearLine() + `Progress: ${i}%`);
|
|
780
|
+
* await sleep(30);
|
|
781
|
+
* }
|
|
782
|
+
* ```
|
|
525
783
|
*/
|
|
526
|
-
declare const
|
|
784
|
+
declare const clearLine: () => string;
|
|
527
785
|
|
|
528
786
|
type ColorFn = (text: string) => string;
|
|
529
787
|
|
|
@@ -921,6 +1179,40 @@ interface ParallelOptions {
|
|
|
921
1179
|
*/
|
|
922
1180
|
type AnimFn = (text: string, opts?: Record<string, unknown>) => Promise<void>;
|
|
923
1181
|
type ChainStep = AnimFn | [AnimFn] | [AnimFn, Record<string, unknown>];
|
|
1182
|
+
interface ShakeOptions extends AnimationHooks {
|
|
1183
|
+
/** Number of shake cycles. Default `5`. */
|
|
1184
|
+
times?: number;
|
|
1185
|
+
/** Pixels of horizontal displacement per frame. Default `2`. */
|
|
1186
|
+
intensity?: number;
|
|
1187
|
+
/** Milliseconds between frames. Default `50`. */
|
|
1188
|
+
interval?: number;
|
|
1189
|
+
/** Emit newline at end. Default `true`. */
|
|
1190
|
+
newline?: boolean;
|
|
1191
|
+
signal?: AbortSignal;
|
|
1192
|
+
reducedMotion?: boolean;
|
|
1193
|
+
}
|
|
1194
|
+
interface CountUpOptions extends AnimationHooks {
|
|
1195
|
+
/** Total animation duration in ms. Default `1500`. */
|
|
1196
|
+
duration?: number;
|
|
1197
|
+
/** Frame count — more = smoother but slower. Default `60`. */
|
|
1198
|
+
steps?: number;
|
|
1199
|
+
/** Decimal places to show. Default `0`. */
|
|
1200
|
+
decimals?: number;
|
|
1201
|
+
/**
|
|
1202
|
+
* Format the displayed value. Default: `(n) => n.toString()`.
|
|
1203
|
+
* Use this to add prefixes/suffixes, commas, etc.
|
|
1204
|
+
*/
|
|
1205
|
+
format?: (value: number) => string;
|
|
1206
|
+
/**
|
|
1207
|
+
* Easing function — input/output both in [0, 1]. Default linear.
|
|
1208
|
+
* Try `(t) => t * t` for accelerate, `(t) => 1 - (1-t)**2` for decelerate.
|
|
1209
|
+
*/
|
|
1210
|
+
easing?: (t: number) => number;
|
|
1211
|
+
/** Emit newline at end. Default `true`. */
|
|
1212
|
+
newline?: boolean;
|
|
1213
|
+
signal?: AbortSignal;
|
|
1214
|
+
reducedMotion?: boolean;
|
|
1215
|
+
}
|
|
924
1216
|
declare const animate: {
|
|
925
1217
|
typewriter: (text: string, opts?: TypewriterOptions) => Promise<void>;
|
|
926
1218
|
fadeIn: (text: string, opts?: FadeOptions) => Promise<void>;
|
|
@@ -940,6 +1232,8 @@ declare const animate: {
|
|
|
940
1232
|
delay: (ms: number) => (opts?: {
|
|
941
1233
|
signal?: AbortSignal;
|
|
942
1234
|
}) => Promise<void>;
|
|
1235
|
+
shake: (text: string, opts?: ShakeOptions) => Promise<void>;
|
|
1236
|
+
countUp: (from: number, to: number, opts?: CountUpOptions) => Promise<void>;
|
|
943
1237
|
};
|
|
944
1238
|
|
|
945
1239
|
interface RGBA {
|
|
@@ -1227,7 +1521,7 @@ declare const images: {
|
|
|
1227
1521
|
createCanvas: (width: number, height: number, fillColor?: Pixel) => Canvas;
|
|
1228
1522
|
colors: {
|
|
1229
1523
|
hex: (h: unknown) => RGB | null;
|
|
1230
|
-
lerp: (a: RGB, b: RGB, t: number) => RGB;
|
|
1524
|
+
lerp: (a: RGB, b: RGB, t: number, space?: ColorSpace) => RGB;
|
|
1231
1525
|
blend: (fg: Pixel, bg: RGB) => RGB;
|
|
1232
1526
|
};
|
|
1233
1527
|
clearAnsiCache: () => void;
|
|
@@ -2557,6 +2851,41 @@ declare const json: {
|
|
|
2557
2851
|
pretty: (value: unknown, opts?: PrettyOptions) => string;
|
|
2558
2852
|
};
|
|
2559
2853
|
|
|
2854
|
+
type EasingFunction = (t: number) => number;
|
|
2855
|
+
/**
|
|
2856
|
+
* Union of all built-in easing names in the comprehensive Robert Penner
|
|
2857
|
+
* library. Provides autocompletion and prevents typos when looking up
|
|
2858
|
+
* functions in `easings`.
|
|
2859
|
+
*
|
|
2860
|
+
* **Note**: This is the v1.3.5 extended library. The original `EasingName`
|
|
2861
|
+
* from the gradient module is a smaller union (5 values) and is
|
|
2862
|
+
* preserved for backward compatibility.
|
|
2863
|
+
*
|
|
2864
|
+
* @since 1.3.5
|
|
2865
|
+
*/
|
|
2866
|
+
type EasingLibraryName = 'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic' | 'easeInQuart' | 'easeOutQuart' | 'easeInOutQuart' | 'easeInQuint' | 'easeOutQuint' | 'easeInOutQuint' | 'easeInSine' | 'easeOutSine' | 'easeInOutSine' | 'easeInExpo' | 'easeOutExpo' | 'easeInOutExpo' | 'easeInCirc' | 'easeOutCirc' | 'easeInOutCirc' | 'easeInBack' | 'easeOutBack' | 'easeInOutBack' | 'easeInElastic' | 'easeOutElastic' | 'easeInOutElastic' | 'easeInBounce' | 'easeOutBounce' | 'easeInOutBounce';
|
|
2867
|
+
/**
|
|
2868
|
+
* A library of named easing functions. Each maps `t ∈ [0, 1]` to an
|
|
2869
|
+
* eased value, typically also in `[0, 1]` (back/elastic briefly
|
|
2870
|
+
* overshoot by design).
|
|
2871
|
+
*
|
|
2872
|
+
* Typed as `Record<EasingLibraryName, EasingFunction>` so all 31 keys are
|
|
2873
|
+
* known to TypeScript — autocompletion + no `possibly undefined` errors
|
|
2874
|
+
* when accessing standard names.
|
|
2875
|
+
*
|
|
2876
|
+
* @since 1.3.5
|
|
2877
|
+
*/
|
|
2878
|
+
declare const easings: Record<EasingLibraryName, EasingFunction>;
|
|
2879
|
+
/**
|
|
2880
|
+
* Resolve an easing reference to a function. Accepts a function (returned
|
|
2881
|
+
* as-is), a named string in `easings` (typed `EasingName` for autocomplete,
|
|
2882
|
+
* but any string is allowed at runtime with linear fallback), or
|
|
2883
|
+
* `undefined`/invalid input (returns `linear`).
|
|
2884
|
+
*
|
|
2885
|
+
* @since 1.3.5
|
|
2886
|
+
*/
|
|
2887
|
+
declare const resolveEasingByName: (e: EasingLibraryName | string | EasingFunction | undefined | null) => EasingFunction;
|
|
2888
|
+
|
|
2560
2889
|
declare const ansimax: {
|
|
2561
2890
|
color: {
|
|
2562
2891
|
black: ColorFn;
|
|
@@ -2624,6 +2953,8 @@ declare const ansimax: {
|
|
|
2624
2953
|
delay: (ms: number) => (opts?: {
|
|
2625
2954
|
signal?: AbortSignal;
|
|
2626
2955
|
}) => Promise<void>;
|
|
2956
|
+
shake: (text: string, opts?: ShakeOptions) => Promise<void>;
|
|
2957
|
+
countUp: (from: number, to: number, opts?: CountUpOptions) => Promise<void>;
|
|
2627
2958
|
};
|
|
2628
2959
|
ascii: {
|
|
2629
2960
|
big: (text: string) => string;
|
|
@@ -2715,7 +3046,7 @@ declare const ansimax: {
|
|
|
2715
3046
|
createCanvas: (width: number, height: number, fillColor?: Pixel) => Canvas;
|
|
2716
3047
|
colors: {
|
|
2717
3048
|
hex: (h: unknown) => RGB | null;
|
|
2718
|
-
lerp: (a: RGB, b: RGB, t: number) => RGB;
|
|
3049
|
+
lerp: (a: RGB, b: RGB, t: number, space?: ColorSpace) => RGB;
|
|
2719
3050
|
blend: (fg: Pixel, bg: RGB) => RGB;
|
|
2720
3051
|
};
|
|
2721
3052
|
clearAnsiCache: () => void;
|
|
@@ -2723,4 +3054,4 @@ declare const ansimax: {
|
|
|
2723
3054
|
configure: (opts?: AnsimaxConfig, meta?: ConfigureOptions) => void;
|
|
2724
3055
|
};
|
|
2725
3056
|
|
|
2726
|
-
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, 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, grid, 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$
|
|
3057
|
+
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 ColorSpace, 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 EasingFunction, type EasingLibraryName, 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 HSL, 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 Oklab, 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, clampByte, clearAnsiCache, clearColorCache, clearLine, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createGradient, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, easings, 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, hslToRgb, hsplit, hyperlink, images, isFiniteNumber, isHexColor, isNoColor, json, pretty as jsonPretty, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureBlock, measureTree, memoize, mixColors, nextTick, oklabToRgb, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, panels, parseFiglet, pauseListeners, presetNames, presets, quantizeColor, rainbow, registerFont, registerPreset, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resolveEasingByName, resumeListeners, reverseGradient, rgbTo256, rgbToHex, rgbToHsl, rgbToOklab, rotate90, safeInt, 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 };
|