ansimax 1.2.2 → 1.2.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/CHANGELOG.md +118 -0
- package/README.es.md +71 -2
- package/README.md +71 -2
- package/dist/index.d.mts +66 -1
- package/dist/index.d.ts +66 -1
- package/dist/index.js +52 -0
- package/dist/index.mjs +49 -0
- package/examples/all-in-one.cjs +1 -1
- package/examples/all-in-one.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,124 @@
|
|
|
3
3
|
All notable changes to **ansimax** are documented in this file.
|
|
4
4
|
This project follows [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## [1.2.4] — Gradient utilities + inspectability
|
|
7
|
+
|
|
8
|
+
Patch release adding gradient inspection and manipulation utilities.
|
|
9
|
+
No breaking changes — `createGradient()` callers from 1.2.3 continue
|
|
10
|
+
to work, but now have access to metadata.
|
|
11
|
+
|
|
12
|
+
### Added — `ReusableGradient` metadata
|
|
13
|
+
|
|
14
|
+
`createGradient()` now returns a `ReusableGradient` — still callable
|
|
15
|
+
like before, but with frozen metadata for inspection and debugging:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c'], {
|
|
19
|
+
easing: 'ease-in',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// All still callable
|
|
23
|
+
console.log(fire('hello'));
|
|
24
|
+
|
|
25
|
+
// New: read-only inspection
|
|
26
|
+
fire.stops; // → ['#ff5555', '#ffb86c', '#f1fa8c']
|
|
27
|
+
fire.resolvedStops; // → [{r:255,g:85,b:85}, {r:255,g:184,b:108}, ...]
|
|
28
|
+
fire.defaultOptions; // → { easing: 'ease-in' }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
All three properties are frozen — attempting to mutate them throws in
|
|
32
|
+
strict mode and silently fails in sloppy mode.
|
|
33
|
+
|
|
34
|
+
### Added — `reverseGradient()` helper
|
|
35
|
+
|
|
36
|
+
Returns a new gradient with stops in reverse order. Works with both
|
|
37
|
+
plain arrays and `ReusableGradient` instances. Default options are
|
|
38
|
+
preserved when reversing a `ReusableGradient`:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
42
|
+
const ice = reverseGradient(fire); // → '#f1fa8c' → '#ffb86c' → '#ff5555'
|
|
43
|
+
|
|
44
|
+
console.log(fire('warm side'));
|
|
45
|
+
console.log(ice('cool side'));
|
|
46
|
+
|
|
47
|
+
// Also works with plain arrays
|
|
48
|
+
reverseGradient(['#f00', '#0f0', '#00f']); // → ['#00f', '#0f0', '#f00']
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The original array / gradient is never mutated.
|
|
52
|
+
|
|
53
|
+
### Added — `presets` alias (canonical name)
|
|
54
|
+
|
|
55
|
+
Previously `presets` was exported only as `colorPresets`. Many users
|
|
56
|
+
referenced `presets` based on docs and got `ReferenceError`. Now both
|
|
57
|
+
names point to the same object:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { presets, colorPresets } from 'ansimax';
|
|
61
|
+
|
|
62
|
+
presets === colorPresets; // → true
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`colorPresets` remains for backwards compatibility; new code can use
|
|
66
|
+
either name.
|
|
67
|
+
|
|
68
|
+
### Notes
|
|
69
|
+
|
|
70
|
+
- Coverage holds steady at ~98%.
|
|
71
|
+
- No new runtime dependencies — still zero.
|
|
72
|
+
- All 1892 + 22 new tests pass.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## [1.2.3] — Gradient factory + performance
|
|
77
|
+
|
|
78
|
+
Patch release adding a new performance-oriented API and refinements. No
|
|
79
|
+
breaking changes — every 1.2.x program runs identically.
|
|
80
|
+
|
|
81
|
+
### Added — `createGradient()` factory
|
|
82
|
+
|
|
83
|
+
A pre-resolved gradient that can be applied repeatedly to different
|
|
84
|
+
strings without re-parsing hex stops on every call. Significantly
|
|
85
|
+
faster for animation loops, frame-based rendering, and bulk colorizing:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { createGradient } from 'ansimax';
|
|
89
|
+
|
|
90
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
91
|
+
|
|
92
|
+
// Reuse — hex stops are pre-resolved
|
|
93
|
+
console.log(fire('first line'));
|
|
94
|
+
console.log(fire('second line'));
|
|
95
|
+
|
|
96
|
+
// Use as colorFn for ascii.banner (matches the ColorFn signature)
|
|
97
|
+
console.log(ascii.banner('FIRE', { colorFn: fire }));
|
|
98
|
+
|
|
99
|
+
// Per-call options still work (especially useful for animation)
|
|
100
|
+
for (let p = 0; p < 1; p += 0.05) {
|
|
101
|
+
process.stdout.write('\r' + fire('flowing', { phase: p }));
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Performance**: hex→RGB conversion happens once at factory time. For
|
|
106
|
+
loops calling `gradient()` hundreds of times per frame, this can cut
|
|
107
|
+
gradient overhead by ~40–60% (depending on stop count).
|
|
108
|
+
|
|
109
|
+
**API surface**:
|
|
110
|
+
- `createGradient(stops, defaultOpts?)` returns `(text, opts?) => string`
|
|
111
|
+
- The returned function matches the `ColorFn` shape (compatible with
|
|
112
|
+
`ascii.banner({ colorFn })`, `themes.gradient`, etc.)
|
|
113
|
+
- Per-call `opts` override defaults; useful for varying `phase` per frame
|
|
114
|
+
while keeping the same colors/easing
|
|
115
|
+
|
|
116
|
+
### Improved
|
|
117
|
+
|
|
118
|
+
- **More JSDoc on `createGradient`** with three runnable `@example` blocks.
|
|
119
|
+
- All 1880 + 12 new tests pass.
|
|
120
|
+
- No new runtime dependencies — still zero.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
6
124
|
## [1.2.2] — Quality polish
|
|
7
125
|
|
|
8
126
|
Patch release focused on API ergonomics and robustness refinements. No
|
package/README.es.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
_Colores • Gradientes • Animaciones • ASCII Art • Pixel Art • Árboles • Componentes • Temas_
|
|
8
8
|
|
|
9
9
|
[](LICENSE)
|
|
10
|
-
[](https://www.npmjs.com/package/ansimax)
|
|
11
11
|
[](tsconfig.json)
|
|
12
12
|
[](#testing)
|
|
13
13
|
[](#testing)
|
|
@@ -260,6 +260,36 @@ console.log(gradientRect({
|
|
|
260
260
|
}));
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
+
### Gradientes reusables (v1.2.3)
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
import { createGradient, reverseGradient, ascii } from 'ansimax';
|
|
267
|
+
|
|
268
|
+
// Pre-resuelve los stops de hex una vez — significativamente más rápido para uso repetido
|
|
269
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
270
|
+
|
|
271
|
+
console.log(fire('Primera línea'));
|
|
272
|
+
console.log(fire('Segunda línea'));
|
|
273
|
+
console.log(fire('Tercera línea'));
|
|
274
|
+
|
|
275
|
+
// Úsalo como colorFn para banners — misma firma de ColorFn
|
|
276
|
+
console.log(ascii.banner('FIRE', { colorFn: fire }));
|
|
277
|
+
|
|
278
|
+
// v1.2.4: inspecciona metadata
|
|
279
|
+
console.log('Stops:', fire.stops); // → ['#ff5555', '#ffb86c', '#f1fa8c']
|
|
280
|
+
console.log('Resolved:', fire.resolvedStops); // → [{r:255,g:85,b:85}, ...]
|
|
281
|
+
|
|
282
|
+
// v1.2.4: invierte un gradiente (preserva las opciones por defecto)
|
|
283
|
+
const ice = reverseGradient(fire);
|
|
284
|
+
console.log(ice('Lado frío'));
|
|
285
|
+
|
|
286
|
+
// Las opciones por-llamada aún funcionan — perfecto para animación
|
|
287
|
+
for (let p = 0; p < 1; p += 0.05) {
|
|
288
|
+
process.stdout.write('\r' + fire('fluyendo', { phase: p }));
|
|
289
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
263
293
|
### ASCII Art
|
|
264
294
|
|
|
265
295
|
<img src="media/ascii_art.png" alt="ASCII art" />
|
|
@@ -335,7 +365,7 @@ console.log(components.table([
|
|
|
335
365
|
['loaders', color.green('● listo'), '100%'],
|
|
336
366
|
], { borderStyle: 'rounded' }));
|
|
337
367
|
|
|
338
|
-
console.log(components.badge('VERSION', 'v1.2.
|
|
368
|
+
console.log(components.badge('VERSION', 'v1.2.4'));
|
|
339
369
|
console.log(components.badge('BUILD', 'passing'));
|
|
340
370
|
```
|
|
341
371
|
|
|
@@ -737,6 +767,45 @@ ansimax/
|
|
|
737
767
|
|
|
738
768
|
## 📝 Changelog
|
|
739
769
|
|
|
770
|
+
### v1.2.4 — Utilidades de gradiente + inspectabilidad
|
|
771
|
+
|
|
772
|
+
Release patch añadiendo metadata de inspección y un helper `reverseGradient()`:
|
|
773
|
+
|
|
774
|
+
- 🔍 **`ReusableGradient` expone `.stops`, `.resolvedStops`, `.defaultOptions`** — todos congelados, todos de solo lectura
|
|
775
|
+
- 🔄 **Helper `reverseGradient()`** — invierte el orden de stops de un gradiente (funciona con arrays o `ReusableGradient`)
|
|
776
|
+
- 🎯 **`presets` exportado con su nombre canónico** — junto al alias existente `colorPresets`
|
|
777
|
+
|
|
778
|
+
```ts
|
|
779
|
+
import { createGradient, reverseGradient } from 'ansimax';
|
|
780
|
+
|
|
781
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
782
|
+
const ice = reverseGradient(fire);
|
|
783
|
+
|
|
784
|
+
console.log(fire.stops); // ['#ff5555', '#ffb86c', '#f1fa8c'] — read-only
|
|
785
|
+
console.log(fire('cálido'));
|
|
786
|
+
console.log(ice('frío'));
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
Drop-in replacement para `1.2.3`.
|
|
790
|
+
|
|
791
|
+
### v1.2.3 — Factory de gradientes + performance
|
|
792
|
+
|
|
793
|
+
Release patch añadiendo una API orientada a performance:
|
|
794
|
+
|
|
795
|
+
- ⚡ **Factory `createGradient()`** — pre-resuelve los stops de hex una vez para reuso, ~40-60% más rápido en loops de animación y colorizado en bulk
|
|
796
|
+
- 📖 Más JSDoc con ejemplos ejecutables
|
|
797
|
+
- 🎯 Coincide con la firma `ColorFn` — funciona como `colorFn` en `ascii.banner`, themes, etc.
|
|
798
|
+
|
|
799
|
+
```ts
|
|
800
|
+
import { createGradient } from 'ansimax';
|
|
801
|
+
|
|
802
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
803
|
+
console.log(fire('¡Colores reusados!'));
|
|
804
|
+
console.log(ascii.banner('FIRE', { colorFn: fire }));
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
Drop-in replacement para `1.2.2`.
|
|
808
|
+
|
|
740
809
|
### v1.2.2 — Pulido de calidad
|
|
741
810
|
|
|
742
811
|
Release patch enfocado en ergonomía de API y refinamientos de robustez.
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
_Colors • Gradients • Animations • ASCII Art • Pixel Art • Trees • Components • Themes_
|
|
8
8
|
|
|
9
9
|
[](LICENSE)
|
|
10
|
-
[](https://www.npmjs.com/package/ansimax)
|
|
11
11
|
[](tsconfig.json)
|
|
12
12
|
[](#testing)
|
|
13
13
|
[](#testing)
|
|
@@ -260,6 +260,36 @@ console.log(gradientRect({
|
|
|
260
260
|
}));
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
+
### Reusable Gradients (v1.2.3)
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
import { createGradient, reverseGradient, ascii } from 'ansimax';
|
|
267
|
+
|
|
268
|
+
// Pre-resolve hex stops once — significantly faster for repeated use
|
|
269
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
270
|
+
|
|
271
|
+
console.log(fire('First line'));
|
|
272
|
+
console.log(fire('Second line'));
|
|
273
|
+
console.log(fire('Third line'));
|
|
274
|
+
|
|
275
|
+
// Use as a colorFn for banners — same ColorFn signature
|
|
276
|
+
console.log(ascii.banner('FIRE', { colorFn: fire }));
|
|
277
|
+
|
|
278
|
+
// v1.2.4: inspect metadata
|
|
279
|
+
console.log('Stops:', fire.stops); // → ['#ff5555', '#ffb86c', '#f1fa8c']
|
|
280
|
+
console.log('Resolved:', fire.resolvedStops); // → [{r:255,g:85,b:85}, ...]
|
|
281
|
+
|
|
282
|
+
// v1.2.4: reverse a gradient (preserves default options)
|
|
283
|
+
const ice = reverseGradient(fire);
|
|
284
|
+
console.log(ice('Cool side'));
|
|
285
|
+
|
|
286
|
+
// Per-call options still work — perfect for animation
|
|
287
|
+
for (let p = 0; p < 1; p += 0.05) {
|
|
288
|
+
process.stdout.write('\r' + fire('flowing', { phase: p }));
|
|
289
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
263
293
|
### ASCII Art
|
|
264
294
|
|
|
265
295
|
<img src="media/ascii_art.png" alt="ASCII art" />
|
|
@@ -335,7 +365,7 @@ console.log(components.table([
|
|
|
335
365
|
['loaders', color.green('● ready'), '100%'],
|
|
336
366
|
], { borderStyle: 'rounded' }));
|
|
337
367
|
|
|
338
|
-
console.log(components.badge('VERSION', 'v1.2.
|
|
368
|
+
console.log(components.badge('VERSION', 'v1.2.4'));
|
|
339
369
|
console.log(components.badge('BUILD', 'passing'));
|
|
340
370
|
```
|
|
341
371
|
|
|
@@ -737,6 +767,45 @@ ansimax/
|
|
|
737
767
|
|
|
738
768
|
## 📝 Changelog
|
|
739
769
|
|
|
770
|
+
### v1.2.4 — Gradient utilities + inspectability
|
|
771
|
+
|
|
772
|
+
Patch release adding inspection metadata and a `reverseGradient()` helper:
|
|
773
|
+
|
|
774
|
+
- 🔍 **`ReusableGradient` exposes `.stops`, `.resolvedStops`, `.defaultOptions`** — all frozen, all read-only
|
|
775
|
+
- 🔄 **`reverseGradient()` helper** — flips a gradient's stop order (works with arrays or `ReusableGradient`)
|
|
776
|
+
- 🎯 **`presets` exported as canonical name** — alongside the existing `colorPresets` alias
|
|
777
|
+
|
|
778
|
+
```ts
|
|
779
|
+
import { createGradient, reverseGradient } from 'ansimax';
|
|
780
|
+
|
|
781
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
782
|
+
const ice = reverseGradient(fire);
|
|
783
|
+
|
|
784
|
+
console.log(fire.stops); // ['#ff5555', '#ffb86c', '#f1fa8c'] — read-only
|
|
785
|
+
console.log(fire('warm'));
|
|
786
|
+
console.log(ice('cool'));
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
Drop-in replacement for `1.2.3`.
|
|
790
|
+
|
|
791
|
+
### v1.2.3 — Gradient factory + performance
|
|
792
|
+
|
|
793
|
+
Patch release adding a performance-oriented API:
|
|
794
|
+
|
|
795
|
+
- ⚡ **`createGradient()` factory** — pre-resolves hex stops once for reuse, ~40-60% faster for animation loops and bulk colorizing
|
|
796
|
+
- 📖 More JSDoc with runnable examples
|
|
797
|
+
- 🎯 Matches the `ColorFn` signature — works as `colorFn` in `ascii.banner`, themes, etc.
|
|
798
|
+
|
|
799
|
+
```ts
|
|
800
|
+
import { createGradient } from 'ansimax';
|
|
801
|
+
|
|
802
|
+
const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
803
|
+
console.log(fire('Reused colors!'));
|
|
804
|
+
console.log(ascii.banner('FIRE', { colorFn: fire }));
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
Drop-in replacement for `1.2.2`.
|
|
808
|
+
|
|
740
809
|
### v1.2.2 — Quality polish
|
|
741
810
|
|
|
742
811
|
Patch release focused on API ergonomics and robustness refinements.
|
package/dist/index.d.mts
CHANGED
|
@@ -598,6 +598,71 @@ interface GradientOptions {
|
|
|
598
598
|
* ```
|
|
599
599
|
*/
|
|
600
600
|
declare const gradient: (text: unknown, stops: string[] | null | undefined, opts?: GradientOptions) => string;
|
|
601
|
+
/**
|
|
602
|
+
* A pre-resolved gradient that can be applied repeatedly to different
|
|
603
|
+
* strings without re-parsing hex stops. Useful for hot loops, animation
|
|
604
|
+
* frames, or any case where the same color palette colorizes many texts.
|
|
605
|
+
*
|
|
606
|
+
* The returned function accepts the same per-call options as `gradient()`
|
|
607
|
+
* (e.g. you can still override `phase` per call for animation).
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```ts
|
|
611
|
+
* const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
612
|
+
*
|
|
613
|
+
* console.log(fire('first line'));
|
|
614
|
+
* console.log(fire('second line'));
|
|
615
|
+
*
|
|
616
|
+
* // Use as colorFn for ascii.banner
|
|
617
|
+
* console.log(ascii.banner('FIRE', { colorFn: fire }));
|
|
618
|
+
*
|
|
619
|
+
* // Animate by overriding phase per frame
|
|
620
|
+
* for (let p = 0; p < 1; p += 0.05) {
|
|
621
|
+
* console.log(fire('flowing', { phase: p }));
|
|
622
|
+
* }
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
/**
|
|
626
|
+
* The function returned by `createGradient()`. Callable just like `gradient()`,
|
|
627
|
+
* but also exposes metadata for inspection and chaining.
|
|
628
|
+
*/
|
|
629
|
+
interface ReusableGradient {
|
|
630
|
+
/** Apply the gradient to text. */
|
|
631
|
+
(text: unknown, opts?: GradientOptions): string;
|
|
632
|
+
/** The original hex stops that were passed to `createGradient()`. */
|
|
633
|
+
readonly stops: readonly string[];
|
|
634
|
+
/** The resolved RGB stops (after filtering invalid hex). */
|
|
635
|
+
readonly resolvedStops: readonly Readonly<RGB>[];
|
|
636
|
+
/** Default options frozen at factory time. */
|
|
637
|
+
readonly defaultOptions: Readonly<Omit<GradientOptions, 'phase'>>;
|
|
638
|
+
}
|
|
639
|
+
declare const createGradient: (stops: string[] | null | undefined, defaultOpts?: Omit<GradientOptions, "phase">) => ReusableGradient;
|
|
640
|
+
/**
|
|
641
|
+
* Return a new gradient with the stops reversed. Useful for symmetric
|
|
642
|
+
* effects (e.g. fade in / fade out) or to flip an existing palette.
|
|
643
|
+
*
|
|
644
|
+
* Accepts either:
|
|
645
|
+
* - A `ReusableGradient` returned from `createGradient()` — returns a new one
|
|
646
|
+
* - An array of hex stops — returns a new array with the order flipped
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```ts
|
|
650
|
+
* const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
651
|
+
* const ice = reverseGradient(fire); // ReusableGradient with reversed stops
|
|
652
|
+
*
|
|
653
|
+
* console.log(fire('warm side'));
|
|
654
|
+
* console.log(ice('cool side'));
|
|
655
|
+
* ```
|
|
656
|
+
*
|
|
657
|
+
* @example with plain stops
|
|
658
|
+
* ```ts
|
|
659
|
+
* const stops = ['#ff0000', '#00ff00', '#0000ff'];
|
|
660
|
+
* const reversed = reverseGradient(stops);
|
|
661
|
+
* // → ['#0000ff', '#00ff00', '#ff0000']
|
|
662
|
+
* ```
|
|
663
|
+
*/
|
|
664
|
+
declare function reverseGradient(grad: ReusableGradient): ReusableGradient;
|
|
665
|
+
declare function reverseGradient(stops: string[]): string[];
|
|
601
666
|
declare const rainbow: ColorFn;
|
|
602
667
|
interface AnimateGradientOptions {
|
|
603
668
|
/** Total animation duration in ms. Default `2000`. */
|
|
@@ -1742,4 +1807,4 @@ declare const ansimax: {
|
|
|
1742
1807
|
configure: (opts?: AnsimaxConfig, meta?: ConfigureOptions) => void;
|
|
1743
1808
|
};
|
|
1744
1809
|
|
|
1745
|
-
export { type AnimateGradientController, type AnimateGradientOptions, type AnimationHooks, type AnimationSpeed, type AnsiCode, type AnsimaxConfig, BEL, BG, type BadgeOptions, type BallOptions, type BannerOptions, type BoxOptions, type BoxStyle, type BreatheOptions, DEFAULTS as CONFIG_DEFAULTS, CSI, type Canvas, type CanvasRenderOptions, 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 FontMap, type FontName, type FrameCallback, type FrameHandle, type GlitchOptions, type Glyph, type GradientOptions, type GradientRectOptions, 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, type ResizeListener, 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$1 as TreeRenderOptions, type TreeStyle, type TypeDeleteOptions, type TypewriterOptions, type WalkVisitor, type WaveOptions, type WriteAsyncOptions, animate, animateGradient, ascii, bell, bg256, bgRgb, box, canAnimate, cancelTerminalFrame, center, chain, charWidth, clamp, clearAnsiCache, clearColorCache, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, escapeRegex, fg256, fgRgb, filterTree, findInTree, flipHorizontal, flipVertical, frames, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, graphemes, hasFont, hexToRgb, hideCursor, images, isHexColor, isNoColor, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureTree, memoize, nextTick, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, pauseListeners, presetNames, rainbow, registerFont, registerPreset, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resumeListeners, 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, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };
|
|
1810
|
+
export { type AnimateGradientController, type AnimateGradientOptions, type AnimationHooks, type AnimationSpeed, type AnsiCode, type AnsimaxConfig, BEL, BG, type BadgeOptions, type BallOptions, type BannerOptions, type BoxOptions, type BoxStyle, type BreatheOptions, DEFAULTS as CONFIG_DEFAULTS, CSI, type Canvas, type CanvasRenderOptions, 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 FontMap, type FontName, type FrameCallback, type FrameHandle, type GlitchOptions, type Glyph, type GradientOptions, type GradientRectOptions, 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, 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$1 as TreeRenderOptions, type TreeStyle, type TypeDeleteOptions, type TypewriterOptions, type WalkVisitor, type WaveOptions, type WriteAsyncOptions, animate, animateGradient, ascii, bell, bg256, bgRgb, box, canAnimate, cancelTerminalFrame, center, 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, filterTree, findInTree, flipHorizontal, flipVertical, frames, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, graphemes, hasFont, hexToRgb, hideCursor, images, isHexColor, isNoColor, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureTree, memoize, nextTick, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, 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, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };
|
package/dist/index.d.ts
CHANGED
|
@@ -598,6 +598,71 @@ interface GradientOptions {
|
|
|
598
598
|
* ```
|
|
599
599
|
*/
|
|
600
600
|
declare const gradient: (text: unknown, stops: string[] | null | undefined, opts?: GradientOptions) => string;
|
|
601
|
+
/**
|
|
602
|
+
* A pre-resolved gradient that can be applied repeatedly to different
|
|
603
|
+
* strings without re-parsing hex stops. Useful for hot loops, animation
|
|
604
|
+
* frames, or any case where the same color palette colorizes many texts.
|
|
605
|
+
*
|
|
606
|
+
* The returned function accepts the same per-call options as `gradient()`
|
|
607
|
+
* (e.g. you can still override `phase` per call for animation).
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```ts
|
|
611
|
+
* const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
612
|
+
*
|
|
613
|
+
* console.log(fire('first line'));
|
|
614
|
+
* console.log(fire('second line'));
|
|
615
|
+
*
|
|
616
|
+
* // Use as colorFn for ascii.banner
|
|
617
|
+
* console.log(ascii.banner('FIRE', { colorFn: fire }));
|
|
618
|
+
*
|
|
619
|
+
* // Animate by overriding phase per frame
|
|
620
|
+
* for (let p = 0; p < 1; p += 0.05) {
|
|
621
|
+
* console.log(fire('flowing', { phase: p }));
|
|
622
|
+
* }
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
/**
|
|
626
|
+
* The function returned by `createGradient()`. Callable just like `gradient()`,
|
|
627
|
+
* but also exposes metadata for inspection and chaining.
|
|
628
|
+
*/
|
|
629
|
+
interface ReusableGradient {
|
|
630
|
+
/** Apply the gradient to text. */
|
|
631
|
+
(text: unknown, opts?: GradientOptions): string;
|
|
632
|
+
/** The original hex stops that were passed to `createGradient()`. */
|
|
633
|
+
readonly stops: readonly string[];
|
|
634
|
+
/** The resolved RGB stops (after filtering invalid hex). */
|
|
635
|
+
readonly resolvedStops: readonly Readonly<RGB>[];
|
|
636
|
+
/** Default options frozen at factory time. */
|
|
637
|
+
readonly defaultOptions: Readonly<Omit<GradientOptions, 'phase'>>;
|
|
638
|
+
}
|
|
639
|
+
declare const createGradient: (stops: string[] | null | undefined, defaultOpts?: Omit<GradientOptions, "phase">) => ReusableGradient;
|
|
640
|
+
/**
|
|
641
|
+
* Return a new gradient with the stops reversed. Useful for symmetric
|
|
642
|
+
* effects (e.g. fade in / fade out) or to flip an existing palette.
|
|
643
|
+
*
|
|
644
|
+
* Accepts either:
|
|
645
|
+
* - A `ReusableGradient` returned from `createGradient()` — returns a new one
|
|
646
|
+
* - An array of hex stops — returns a new array with the order flipped
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```ts
|
|
650
|
+
* const fire = createGradient(['#ff5555', '#ffb86c', '#f1fa8c']);
|
|
651
|
+
* const ice = reverseGradient(fire); // ReusableGradient with reversed stops
|
|
652
|
+
*
|
|
653
|
+
* console.log(fire('warm side'));
|
|
654
|
+
* console.log(ice('cool side'));
|
|
655
|
+
* ```
|
|
656
|
+
*
|
|
657
|
+
* @example with plain stops
|
|
658
|
+
* ```ts
|
|
659
|
+
* const stops = ['#ff0000', '#00ff00', '#0000ff'];
|
|
660
|
+
* const reversed = reverseGradient(stops);
|
|
661
|
+
* // → ['#0000ff', '#00ff00', '#ff0000']
|
|
662
|
+
* ```
|
|
663
|
+
*/
|
|
664
|
+
declare function reverseGradient(grad: ReusableGradient): ReusableGradient;
|
|
665
|
+
declare function reverseGradient(stops: string[]): string[];
|
|
601
666
|
declare const rainbow: ColorFn;
|
|
602
667
|
interface AnimateGradientOptions {
|
|
603
668
|
/** Total animation duration in ms. Default `2000`. */
|
|
@@ -1742,4 +1807,4 @@ declare const ansimax: {
|
|
|
1742
1807
|
configure: (opts?: AnsimaxConfig, meta?: ConfigureOptions) => void;
|
|
1743
1808
|
};
|
|
1744
1809
|
|
|
1745
|
-
export { type AnimateGradientController, type AnimateGradientOptions, type AnimationHooks, type AnimationSpeed, type AnsiCode, type AnsimaxConfig, BEL, BG, type BadgeOptions, type BallOptions, type BannerOptions, type BoxOptions, type BoxStyle, type BreatheOptions, DEFAULTS as CONFIG_DEFAULTS, CSI, type Canvas, type CanvasRenderOptions, 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 FontMap, type FontName, type FrameCallback, type FrameHandle, type GlitchOptions, type Glyph, type GradientOptions, type GradientRectOptions, 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, type ResizeListener, 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$1 as TreeRenderOptions, type TreeStyle, type TypeDeleteOptions, type TypewriterOptions, type WalkVisitor, type WaveOptions, type WriteAsyncOptions, animate, animateGradient, ascii, bell, bg256, bgRgb, box, canAnimate, cancelTerminalFrame, center, chain, charWidth, clamp, clearAnsiCache, clearColorCache, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, escapeRegex, fg256, fgRgb, filterTree, findInTree, flipHorizontal, flipVertical, frames, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, graphemes, hasFont, hexToRgb, hideCursor, images, isHexColor, isNoColor, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureTree, memoize, nextTick, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, pauseListeners, presetNames, rainbow, registerFont, registerPreset, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resumeListeners, 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, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };
|
|
1810
|
+
export { type AnimateGradientController, type AnimateGradientOptions, type AnimationHooks, type AnimationSpeed, type AnsiCode, type AnsimaxConfig, BEL, BG, type BadgeOptions, type BallOptions, type BannerOptions, type BoxOptions, type BoxStyle, type BreatheOptions, DEFAULTS as CONFIG_DEFAULTS, CSI, type Canvas, type CanvasRenderOptions, 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 FontMap, type FontName, type FrameCallback, type FrameHandle, type GlitchOptions, type Glyph, type GradientOptions, type GradientRectOptions, 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, 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$1 as TreeRenderOptions, type TreeStyle, type TypeDeleteOptions, type TypewriterOptions, type WalkVisitor, type WaveOptions, type WriteAsyncOptions, animate, animateGradient, ascii, bell, bg256, bgRgb, box, canAnimate, cancelTerminalFrame, center, 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, filterTree, findInTree, flipHorizontal, flipVertical, frames, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, graphemes, hasFont, hexToRgb, hideCursor, images, isHexColor, isNoColor, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureTree, memoize, nextTick, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, 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, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };
|
package/dist/index.js
CHANGED
|
@@ -70,6 +70,7 @@ __export(index_exports, {
|
|
|
70
70
|
configure: () => configure,
|
|
71
71
|
countNodes: () => countNodes,
|
|
72
72
|
createCanvas: () => createCanvas,
|
|
73
|
+
createGradient: () => createGradient,
|
|
73
74
|
createOutputBuffer: () => createOutputBuffer,
|
|
74
75
|
createTheme: () => createTheme,
|
|
75
76
|
cursor: () => cursor,
|
|
@@ -119,6 +120,7 @@ __export(index_exports, {
|
|
|
119
120
|
padStart: () => padStart,
|
|
120
121
|
pauseListeners: () => pauseListeners,
|
|
121
122
|
presetNames: () => presetNames,
|
|
123
|
+
presets: () => presets,
|
|
122
124
|
rainbow: () => rainbow,
|
|
123
125
|
registerFont: () => registerFont,
|
|
124
126
|
registerPreset: () => registerPreset,
|
|
@@ -135,6 +137,7 @@ __export(index_exports, {
|
|
|
135
137
|
resetLoaderCursorCount: () => resetLoaderCursorCount,
|
|
136
138
|
resetNoColor: () => resetNoColor,
|
|
137
139
|
resumeListeners: () => resumeListeners,
|
|
140
|
+
reverseGradient: () => reverseGradient,
|
|
138
141
|
rgbTo256: () => rgbTo256,
|
|
139
142
|
rgbToHex: () => rgbToHex,
|
|
140
143
|
rotate90: () => rotate90,
|
|
@@ -1165,6 +1168,52 @@ var gradient = (text, stops, opts = {}) => {
|
|
|
1165
1168
|
}
|
|
1166
1169
|
return _gradientAnsiAware(s, colors, easingFn, phaseN);
|
|
1167
1170
|
};
|
|
1171
|
+
var createGradient = (stops, defaultOpts = {}) => {
|
|
1172
|
+
const originalStops = Array.isArray(stops) ? [...stops] : [];
|
|
1173
|
+
const colors = originalStops.map(safeHex).filter((c) => c !== null);
|
|
1174
|
+
const defaultEasingFn = resolveEasing(defaultOpts.easing);
|
|
1175
|
+
const defaultPreserveAnsi = defaultOpts.preserveAnsi ?? false;
|
|
1176
|
+
const fn = ((text, opts = {}) => {
|
|
1177
|
+
const s = coerceText(text);
|
|
1178
|
+
if (!s || isNoColor()) return s;
|
|
1179
|
+
if (colors.length === 0) return s;
|
|
1180
|
+
if (colors.length === 1) {
|
|
1181
|
+
const c = colors[0];
|
|
1182
|
+
return adaptiveFg(c.r, c.g, c.b) + s + reset();
|
|
1183
|
+
}
|
|
1184
|
+
const easingFn = opts.easing !== void 0 ? resolveEasing(opts.easing) : defaultEasingFn;
|
|
1185
|
+
const preserveAnsi = opts.preserveAnsi ?? defaultPreserveAnsi;
|
|
1186
|
+
const phase = opts.phase ?? 0;
|
|
1187
|
+
const phaseN = Number.isFinite(phase) ? (phase % 1 + 1) % 1 : 0;
|
|
1188
|
+
if (!preserveAnsi || !s.includes("\x1B")) {
|
|
1189
|
+
return _gradientPlain(s, colors, easingFn, phaseN);
|
|
1190
|
+
}
|
|
1191
|
+
return _gradientAnsiAware(s, colors, easingFn, phaseN);
|
|
1192
|
+
});
|
|
1193
|
+
Object.defineProperty(fn, "stops", {
|
|
1194
|
+
value: Object.freeze(originalStops),
|
|
1195
|
+
enumerable: true,
|
|
1196
|
+
writable: false
|
|
1197
|
+
});
|
|
1198
|
+
Object.defineProperty(fn, "resolvedStops", {
|
|
1199
|
+
value: Object.freeze(colors.map((c) => Object.freeze({ ...c }))),
|
|
1200
|
+
enumerable: true,
|
|
1201
|
+
writable: false
|
|
1202
|
+
});
|
|
1203
|
+
Object.defineProperty(fn, "defaultOptions", {
|
|
1204
|
+
value: Object.freeze({ ...defaultOpts }),
|
|
1205
|
+
enumerable: true,
|
|
1206
|
+
writable: false
|
|
1207
|
+
});
|
|
1208
|
+
return fn;
|
|
1209
|
+
};
|
|
1210
|
+
function reverseGradient(input) {
|
|
1211
|
+
if (Array.isArray(input)) {
|
|
1212
|
+
return [...input].reverse();
|
|
1213
|
+
}
|
|
1214
|
+
const reversedStops = [...input.stops].reverse();
|
|
1215
|
+
return createGradient(reversedStops, input.defaultOptions);
|
|
1216
|
+
}
|
|
1168
1217
|
var _gradientPlain = (text, colors, easingFn, phase) => {
|
|
1169
1218
|
const chars = [...text];
|
|
1170
1219
|
const visible = chars.filter((c) => c !== " ").length;
|
|
@@ -5488,6 +5537,7 @@ var index_default = ansimax;
|
|
|
5488
5537
|
configure,
|
|
5489
5538
|
countNodes,
|
|
5490
5539
|
createCanvas,
|
|
5540
|
+
createGradient,
|
|
5491
5541
|
createOutputBuffer,
|
|
5492
5542
|
createTheme,
|
|
5493
5543
|
cursor,
|
|
@@ -5536,6 +5586,7 @@ var index_default = ansimax;
|
|
|
5536
5586
|
padStart,
|
|
5537
5587
|
pauseListeners,
|
|
5538
5588
|
presetNames,
|
|
5589
|
+
presets,
|
|
5539
5590
|
rainbow,
|
|
5540
5591
|
registerFont,
|
|
5541
5592
|
registerPreset,
|
|
@@ -5552,6 +5603,7 @@ var index_default = ansimax;
|
|
|
5552
5603
|
resetLoaderCursorCount,
|
|
5553
5604
|
resetNoColor,
|
|
5554
5605
|
resumeListeners,
|
|
5606
|
+
reverseGradient,
|
|
5555
5607
|
rgbTo256,
|
|
5556
5608
|
rgbToHex,
|
|
5557
5609
|
rotate90,
|
package/dist/index.mjs
CHANGED
|
@@ -992,6 +992,52 @@ var gradient = (text, stops, opts = {}) => {
|
|
|
992
992
|
}
|
|
993
993
|
return _gradientAnsiAware(s, colors, easingFn, phaseN);
|
|
994
994
|
};
|
|
995
|
+
var createGradient = (stops, defaultOpts = {}) => {
|
|
996
|
+
const originalStops = Array.isArray(stops) ? [...stops] : [];
|
|
997
|
+
const colors = originalStops.map(safeHex).filter((c) => c !== null);
|
|
998
|
+
const defaultEasingFn = resolveEasing(defaultOpts.easing);
|
|
999
|
+
const defaultPreserveAnsi = defaultOpts.preserveAnsi ?? false;
|
|
1000
|
+
const fn = ((text, opts = {}) => {
|
|
1001
|
+
const s = coerceText(text);
|
|
1002
|
+
if (!s || isNoColor()) return s;
|
|
1003
|
+
if (colors.length === 0) return s;
|
|
1004
|
+
if (colors.length === 1) {
|
|
1005
|
+
const c = colors[0];
|
|
1006
|
+
return adaptiveFg(c.r, c.g, c.b) + s + reset();
|
|
1007
|
+
}
|
|
1008
|
+
const easingFn = opts.easing !== void 0 ? resolveEasing(opts.easing) : defaultEasingFn;
|
|
1009
|
+
const preserveAnsi = opts.preserveAnsi ?? defaultPreserveAnsi;
|
|
1010
|
+
const phase = opts.phase ?? 0;
|
|
1011
|
+
const phaseN = Number.isFinite(phase) ? (phase % 1 + 1) % 1 : 0;
|
|
1012
|
+
if (!preserveAnsi || !s.includes("\x1B")) {
|
|
1013
|
+
return _gradientPlain(s, colors, easingFn, phaseN);
|
|
1014
|
+
}
|
|
1015
|
+
return _gradientAnsiAware(s, colors, easingFn, phaseN);
|
|
1016
|
+
});
|
|
1017
|
+
Object.defineProperty(fn, "stops", {
|
|
1018
|
+
value: Object.freeze(originalStops),
|
|
1019
|
+
enumerable: true,
|
|
1020
|
+
writable: false
|
|
1021
|
+
});
|
|
1022
|
+
Object.defineProperty(fn, "resolvedStops", {
|
|
1023
|
+
value: Object.freeze(colors.map((c) => Object.freeze({ ...c }))),
|
|
1024
|
+
enumerable: true,
|
|
1025
|
+
writable: false
|
|
1026
|
+
});
|
|
1027
|
+
Object.defineProperty(fn, "defaultOptions", {
|
|
1028
|
+
value: Object.freeze({ ...defaultOpts }),
|
|
1029
|
+
enumerable: true,
|
|
1030
|
+
writable: false
|
|
1031
|
+
});
|
|
1032
|
+
return fn;
|
|
1033
|
+
};
|
|
1034
|
+
function reverseGradient(input) {
|
|
1035
|
+
if (Array.isArray(input)) {
|
|
1036
|
+
return [...input].reverse();
|
|
1037
|
+
}
|
|
1038
|
+
const reversedStops = [...input.stops].reverse();
|
|
1039
|
+
return createGradient(reversedStops, input.defaultOptions);
|
|
1040
|
+
}
|
|
995
1041
|
var _gradientPlain = (text, colors, easingFn, phase) => {
|
|
996
1042
|
const chars = [...text];
|
|
997
1043
|
const visible = chars.filter((c) => c !== " ").length;
|
|
@@ -5314,6 +5360,7 @@ export {
|
|
|
5314
5360
|
configure,
|
|
5315
5361
|
countNodes,
|
|
5316
5362
|
createCanvas,
|
|
5363
|
+
createGradient,
|
|
5317
5364
|
createOutputBuffer,
|
|
5318
5365
|
createTheme,
|
|
5319
5366
|
cursor,
|
|
@@ -5363,6 +5410,7 @@ export {
|
|
|
5363
5410
|
padStart,
|
|
5364
5411
|
pauseListeners,
|
|
5365
5412
|
presetNames,
|
|
5413
|
+
presets,
|
|
5366
5414
|
rainbow,
|
|
5367
5415
|
registerFont,
|
|
5368
5416
|
registerPreset,
|
|
@@ -5379,6 +5427,7 @@ export {
|
|
|
5379
5427
|
resetLoaderCursorCount,
|
|
5380
5428
|
resetNoColor,
|
|
5381
5429
|
resumeListeners,
|
|
5430
|
+
reverseGradient,
|
|
5382
5431
|
rgbTo256,
|
|
5383
5432
|
rgbToHex,
|
|
5384
5433
|
rotate90,
|
package/examples/all-in-one.cjs
CHANGED
|
@@ -118,7 +118,7 @@ async function main() {
|
|
|
118
118
|
console.log(components.section('🏷️ Badges & Status', { width: 60 }));
|
|
119
119
|
console.log();
|
|
120
120
|
console.log(' ',
|
|
121
|
-
components.badge('VERSION', 'v1.2.
|
|
121
|
+
components.badge('VERSION', 'v1.2.4'),
|
|
122
122
|
components.badge('BUILD', 'passing'),
|
|
123
123
|
components.badge('LICENSE', 'Apache 2.0'));
|
|
124
124
|
console.log();
|
package/examples/all-in-one.mjs
CHANGED
|
@@ -117,7 +117,7 @@ console.log();
|
|
|
117
117
|
console.log(components.section('🏷️ Badges & Status', { width: 60 }));
|
|
118
118
|
console.log();
|
|
119
119
|
console.log(' ',
|
|
120
|
-
components.badge('VERSION', 'v1.2.
|
|
120
|
+
components.badge('VERSION', 'v1.2.4'),
|
|
121
121
|
components.badge('BUILD', 'passing'),
|
|
122
122
|
components.badge('LICENSE', 'Apache 2.0'));
|
|
123
123
|
console.log();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ansimax",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Zero-dependency CLI rendering library: colors, gradients, animations, ASCII art, pixel art, components, and themes \u2014 all in TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|