ansimax 1.1.0 → 1.1.2
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 +324 -0
- package/README.es.md +148 -47
- package/README.md +147 -46
- package/dist/index.js +39 -8
- package/dist/index.mjs +39 -8
- package/examples/01-quick-smoke.ts +121 -0
- package/examples/02-colors-gradients.ts +108 -0
- package/examples/03-ascii-banners.ts +81 -0
- package/examples/04-trees.ts +117 -0
- package/examples/05-components.ts +96 -0
- package/examples/06-pixel-art.ts +116 -0
- package/examples/07-animations.ts +68 -0
- package/examples/08-loaders.ts +98 -0
- package/examples/09-themes.ts +90 -0
- package/examples/10-everything.ts +133 -0
- package/examples/all-in-one.cjs +210 -0
- package/examples/all-in-one.mjs +203 -0
- package/examples/tsconfig.json +18 -18
- package/package.json +2 -2
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 01 — Quick Smoke Test
|
|
3
|
+
*
|
|
4
|
+
* Verifies all major named exports from `ansimax` are importable and callable.
|
|
5
|
+
* This is the FIRST test to run — if it fails, the package is broken.
|
|
6
|
+
*
|
|
7
|
+
* Run: npx tsx examples/01-quick-smoke.ts
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
color,
|
|
12
|
+
gradient,
|
|
13
|
+
rainbow,
|
|
14
|
+
ascii,
|
|
15
|
+
loader,
|
|
16
|
+
animate,
|
|
17
|
+
frames,
|
|
18
|
+
components,
|
|
19
|
+
themes,
|
|
20
|
+
images,
|
|
21
|
+
trees,
|
|
22
|
+
tree,
|
|
23
|
+
configure,
|
|
24
|
+
getConfig,
|
|
25
|
+
// Utils
|
|
26
|
+
stripAnsi,
|
|
27
|
+
visibleLen,
|
|
28
|
+
hexToRgb,
|
|
29
|
+
rgbToHex,
|
|
30
|
+
clamp,
|
|
31
|
+
// ANSI primitives
|
|
32
|
+
cursor,
|
|
33
|
+
screen,
|
|
34
|
+
supportsColor,
|
|
35
|
+
} from '../src/index.js';
|
|
36
|
+
|
|
37
|
+
const pass = (msg: string): void => console.log(color.green('✓'), msg);
|
|
38
|
+
const info = (label: string, value: unknown): void =>
|
|
39
|
+
console.log(' ' + color.dim(label.padEnd(20)), value);
|
|
40
|
+
|
|
41
|
+
console.log();
|
|
42
|
+
console.log(color.bold(color.cyan('━━━ Ansimax v1.1.0 Smoke Test ━━━')));
|
|
43
|
+
console.log();
|
|
44
|
+
|
|
45
|
+
// 1. Colors
|
|
46
|
+
pass('color.red / color.green / color.blue');
|
|
47
|
+
info('color.red:', color.red('red text'));
|
|
48
|
+
info('color.green:', color.green('green text'));
|
|
49
|
+
|
|
50
|
+
// 2. Gradient
|
|
51
|
+
pass('gradient with multi-stop');
|
|
52
|
+
info('gradient:', gradient('rainbow text', ['#ff0000', '#00ff00', '#0000ff']));
|
|
53
|
+
|
|
54
|
+
// 3. Rainbow preset
|
|
55
|
+
pass('rainbow preset');
|
|
56
|
+
info('rainbow:', rainbow('hello rainbow!'));
|
|
57
|
+
|
|
58
|
+
// 4. Style modifiers
|
|
59
|
+
pass('color.bold / italic / underline');
|
|
60
|
+
info('bold:', color.bold('bold text'));
|
|
61
|
+
info('italic:', color.italic('italic text'));
|
|
62
|
+
info('underline:', color.underline('underlined text'));
|
|
63
|
+
|
|
64
|
+
// 5. Hex & RGB
|
|
65
|
+
pass('color.hex / color.rgb');
|
|
66
|
+
info('color.hex:', color.hex('#ff79c6')('Dracula pink'));
|
|
67
|
+
info('color.rgb:', color.rgb(189, 147, 249)('Dracula purple'));
|
|
68
|
+
|
|
69
|
+
// 6. ANSI utils
|
|
70
|
+
pass('stripAnsi / visibleLen');
|
|
71
|
+
const colored = color.red('hello');
|
|
72
|
+
info('stripAnsi:', JSON.stringify(stripAnsi(colored)));
|
|
73
|
+
info('visibleLen:', visibleLen(colored));
|
|
74
|
+
|
|
75
|
+
// 7. hexToRgb / rgbToHex
|
|
76
|
+
pass('hexToRgb / rgbToHex');
|
|
77
|
+
info('hexToRgb #ff79c6:', JSON.stringify(hexToRgb('#ff79c6')));
|
|
78
|
+
info('rgbToHex 189,147,249:', rgbToHex(189, 147, 249));
|
|
79
|
+
|
|
80
|
+
// 8. clamp
|
|
81
|
+
pass('clamp');
|
|
82
|
+
info('clamp(15, 0, 10):', clamp(15, 0, 10));
|
|
83
|
+
|
|
84
|
+
// 9. Capability detection
|
|
85
|
+
pass('supportsColor');
|
|
86
|
+
info('supportsColor():', supportsColor());
|
|
87
|
+
|
|
88
|
+
// 10. Module namespaces
|
|
89
|
+
pass('All namespaces accessible');
|
|
90
|
+
info('color:', typeof color);
|
|
91
|
+
info('ascii:', typeof ascii);
|
|
92
|
+
info('loader:', typeof loader);
|
|
93
|
+
info('animate:', typeof animate);
|
|
94
|
+
info('frames:', typeof frames);
|
|
95
|
+
info('components:', typeof components);
|
|
96
|
+
info('themes:', typeof themes);
|
|
97
|
+
info('images:', typeof images);
|
|
98
|
+
info('trees:', typeof trees);
|
|
99
|
+
|
|
100
|
+
// 11. tree() builder
|
|
101
|
+
pass('tree() builder');
|
|
102
|
+
const t = tree({ label: 'root', icon: '📦' });
|
|
103
|
+
t.addLeaf({ label: 'child1', icon: '📄' });
|
|
104
|
+
info('tree.render():', '\n' + t.render());
|
|
105
|
+
|
|
106
|
+
// 12. configure
|
|
107
|
+
pass('configure / getConfig');
|
|
108
|
+
const cfg = getConfig();
|
|
109
|
+
info('theme:', cfg.theme);
|
|
110
|
+
info('colorMode:', cfg.colorMode);
|
|
111
|
+
|
|
112
|
+
// 13. cursor / screen primitives
|
|
113
|
+
pass('cursor / screen primitives');
|
|
114
|
+
info('cursor.hide():', JSON.stringify(cursor.hide()));
|
|
115
|
+
info('cursor.show():', JSON.stringify(cursor.show()));
|
|
116
|
+
info('screen.clearLine():', JSON.stringify(screen.clearLine()));
|
|
117
|
+
|
|
118
|
+
console.log();
|
|
119
|
+
console.log(color.bold(color.green('✅ All smoke tests passed!')));
|
|
120
|
+
console.log(color.dim('You have a working ansimax installation.'));
|
|
121
|
+
console.log();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 02 — Colors & Gradients
|
|
3
|
+
* Tests verified against actual ansimax@1.1.0 exports.
|
|
4
|
+
*
|
|
5
|
+
* Run: npx tsx examples/02-colors-gradients.ts
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
color,
|
|
10
|
+
gradient,
|
|
11
|
+
rainbow,
|
|
12
|
+
colorPresets,
|
|
13
|
+
presetNames,
|
|
14
|
+
compose,
|
|
15
|
+
chain,
|
|
16
|
+
registerPreset,
|
|
17
|
+
listPresets,
|
|
18
|
+
} from '../src/index.js';
|
|
19
|
+
|
|
20
|
+
console.log();
|
|
21
|
+
console.log(color.bold('━━━ Basic Colors ━━━'));
|
|
22
|
+
console.log();
|
|
23
|
+
|
|
24
|
+
const basic = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'] as const;
|
|
25
|
+
console.log('Basic 8 colors:');
|
|
26
|
+
for (const c of basic) process.stdout.write(color[c](c.padEnd(8)) + ' ');
|
|
27
|
+
console.log('\n');
|
|
28
|
+
|
|
29
|
+
const bright = ['brightRed', 'brightGreen', 'brightYellow', 'brightBlue', 'brightMagenta', 'brightCyan'] as const;
|
|
30
|
+
console.log('Bright variants:');
|
|
31
|
+
for (const c of bright) process.stdout.write(color[c](c.padEnd(15)) + ' ');
|
|
32
|
+
console.log('\n');
|
|
33
|
+
|
|
34
|
+
const bg = ['bgRed', 'bgGreen', 'bgBlue', 'bgYellow', 'bgMagenta', 'bgCyan'] as const;
|
|
35
|
+
console.log('Backgrounds:');
|
|
36
|
+
for (const c of bg) process.stdout.write(color[c](` ${c} `) + ' ');
|
|
37
|
+
console.log('\n');
|
|
38
|
+
|
|
39
|
+
console.log('Modifiers:');
|
|
40
|
+
console.log(' ',
|
|
41
|
+
color.bold('bold'),
|
|
42
|
+
color.italic('italic'),
|
|
43
|
+
color.underline('underline'),
|
|
44
|
+
color.dim('dim'),
|
|
45
|
+
color.inverse('inverse'),
|
|
46
|
+
color.strikethrough('strikethrough'),
|
|
47
|
+
);
|
|
48
|
+
console.log();
|
|
49
|
+
|
|
50
|
+
console.log(color.bold('━━━ Hex / RGB / 256 ━━━'));
|
|
51
|
+
console.log();
|
|
52
|
+
|
|
53
|
+
const hexes = ['#ff79c6', '#bd93f9', '#8be9fd', '#50fa7b', '#ffb86c', '#ff5555'];
|
|
54
|
+
console.log('Hex colors:');
|
|
55
|
+
for (const hex of hexes) process.stdout.write(color.hex(hex)(hex) + ' ');
|
|
56
|
+
console.log('\n');
|
|
57
|
+
|
|
58
|
+
console.log('RGB:');
|
|
59
|
+
console.log(' ', color.rgb(255, 121, 198)('rgb(255, 121, 198)'));
|
|
60
|
+
console.log(' ', color.rgb(189, 147, 249)('rgb(189, 147, 249)'));
|
|
61
|
+
console.log();
|
|
62
|
+
|
|
63
|
+
console.log('256-color (palette indices):');
|
|
64
|
+
for (const n of [196, 208, 226, 46, 51, 21, 201]) {
|
|
65
|
+
process.stdout.write(color.color256(n)(`[${n}]`) + ' ');
|
|
66
|
+
}
|
|
67
|
+
console.log('\n');
|
|
68
|
+
|
|
69
|
+
console.log(color.bold('━━━ Gradients ━━━'));
|
|
70
|
+
console.log();
|
|
71
|
+
|
|
72
|
+
console.log('Multi-stop gradients:');
|
|
73
|
+
console.log(' ', gradient('Hello gradient world!', ['#ff0000', '#00ff00', '#0000ff']));
|
|
74
|
+
console.log(' ', gradient('Fire to ice', ['#ff6b6b', '#feca57', '#48dbfb']));
|
|
75
|
+
console.log(' ', gradient('Dracula theme', ['#ff79c6', '#bd93f9', '#8be9fd']));
|
|
76
|
+
console.log();
|
|
77
|
+
|
|
78
|
+
console.log(color.bold('━━━ Built-in colorPresets ━━━'));
|
|
79
|
+
console.log();
|
|
80
|
+
console.log(' Available:', presetNames.join(', '));
|
|
81
|
+
console.log();
|
|
82
|
+
console.log(' rainbow: ', rainbow('rainbow text!'));
|
|
83
|
+
console.log(' sunset: ', colorPresets.sunset!('sunset preset'));
|
|
84
|
+
console.log(' ocean: ', colorPresets.ocean!('ocean preset'));
|
|
85
|
+
console.log(' fire: ', colorPresets.fire!('fire preset'));
|
|
86
|
+
console.log(' neon: ', colorPresets.neon!('neon preset'));
|
|
87
|
+
console.log(' forest: ', colorPresets.forest!('forest preset'));
|
|
88
|
+
console.log(' aurora: ', colorPresets.aurora!('aurora preset'));
|
|
89
|
+
console.log(' candy: ', colorPresets.candy!('candy preset'));
|
|
90
|
+
console.log(' gold: ', colorPresets.gold!('gold preset'));
|
|
91
|
+
console.log();
|
|
92
|
+
|
|
93
|
+
console.log(color.bold('━━━ Custom presets ━━━'));
|
|
94
|
+
console.log();
|
|
95
|
+
registerPreset('my-pink', ['#ff6b6b', '#ff79c6', '#ffb6c1']);
|
|
96
|
+
console.log(' Registered. All presets now:', listPresets().join(', '));
|
|
97
|
+
console.log(' my-pink: ', colorPresets['my-pink']!('My custom pink preset!'));
|
|
98
|
+
console.log();
|
|
99
|
+
|
|
100
|
+
console.log(color.bold('━━━ Compose & Chain ━━━'));
|
|
101
|
+
console.log();
|
|
102
|
+
const fancy = compose(color.red, color.bold, color.underline);
|
|
103
|
+
console.log(' compose: ', fancy('red + bold + underline'));
|
|
104
|
+
console.log(' chain: ', chain().magenta().italic().underline().apply('chained styles'));
|
|
105
|
+
console.log();
|
|
106
|
+
|
|
107
|
+
console.log(color.bold(color.green('✓ Colors & gradients test complete')));
|
|
108
|
+
console.log();
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 03 — ASCII Banners & Boxes
|
|
3
|
+
* Real box styles: single, double, rounded, heavy, dashed, ascii
|
|
4
|
+
*
|
|
5
|
+
* Run: npx tsx examples/03-ascii-banners.ts
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ascii, gradient, color, listFonts, hasFont } from '../src/index.js';
|
|
9
|
+
|
|
10
|
+
console.log();
|
|
11
|
+
console.log(color.bold('━━━ ASCII Banners ━━━'));
|
|
12
|
+
console.log();
|
|
13
|
+
|
|
14
|
+
console.log(color.dim('// Big font (default)'));
|
|
15
|
+
console.log(ascii.banner('HELLO'));
|
|
16
|
+
|
|
17
|
+
console.log(color.dim('// Small font'));
|
|
18
|
+
console.log(ascii.banner('HELLO', { font: 'small' }));
|
|
19
|
+
|
|
20
|
+
console.log(color.dim('// With gradient'));
|
|
21
|
+
console.log(ascii.banner('ANSIMAX', {
|
|
22
|
+
font: 'big',
|
|
23
|
+
colorFn: (t) => gradient(t, ['#ff79c6', '#bd93f9', '#8be9fd']),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
console.log(color.dim('// Aligned center'));
|
|
27
|
+
console.log(ascii.banner('CENTER', { align: 'center' }));
|
|
28
|
+
|
|
29
|
+
console.log(color.dim('// Available fonts:'));
|
|
30
|
+
console.log(' fonts:', listFonts().join(', '));
|
|
31
|
+
console.log(' has "big":', hasFont('big'));
|
|
32
|
+
console.log(' has "small":', hasFont('small'));
|
|
33
|
+
console.log(' has "unicorn":', hasFont('unicorn'));
|
|
34
|
+
console.log();
|
|
35
|
+
|
|
36
|
+
console.log(color.bold('━━━ Boxes (6 real styles) ━━━'));
|
|
37
|
+
console.log();
|
|
38
|
+
|
|
39
|
+
// REAL box styles: single, double, rounded, heavy, dashed, ascii
|
|
40
|
+
const boxStyles = ['single', 'double', 'rounded', 'heavy', 'dashed', 'ascii'] as const;
|
|
41
|
+
for (const style of boxStyles) {
|
|
42
|
+
console.log(color.dim(`// borderStyle: ${style}`));
|
|
43
|
+
console.log(ascii.box(`This is a ${style} box`, {
|
|
44
|
+
padding: 1,
|
|
45
|
+
borderStyle: style,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(color.dim('// Multi-line box'));
|
|
50
|
+
console.log(ascii.box(
|
|
51
|
+
'Line 1\nLine 2 with a bit longer text\nLine 3',
|
|
52
|
+
{ padding: 1, borderStyle: 'rounded' },
|
|
53
|
+
));
|
|
54
|
+
|
|
55
|
+
console.log();
|
|
56
|
+
console.log(color.bold('━━━ Dividers ━━━'));
|
|
57
|
+
console.log();
|
|
58
|
+
|
|
59
|
+
console.log(ascii.divider({ char: '─', width: 50 }));
|
|
60
|
+
console.log(ascii.divider({ char: '═', width: 50 }));
|
|
61
|
+
console.log(ascii.divider({ char: '━', width: 50, label: 'Section' }));
|
|
62
|
+
console.log();
|
|
63
|
+
|
|
64
|
+
console.log(color.bold('━━━ Logo composer ━━━'));
|
|
65
|
+
console.log();
|
|
66
|
+
|
|
67
|
+
console.log(ascii.logo('LOGO', {
|
|
68
|
+
font: 'big',
|
|
69
|
+
colorFn: (t) => gradient(t, ['#ff6b6b', '#feca57', '#48dbfb']),
|
|
70
|
+
borderStyle: 'rounded',
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
console.log();
|
|
74
|
+
console.log(color.bold('━━━ ascii.measure ━━━'));
|
|
75
|
+
console.log();
|
|
76
|
+
const dim = ascii.measure('Hello World', { font: 'big' });
|
|
77
|
+
console.log(` Banner dimensions: ${dim.width} × ${dim.height}`);
|
|
78
|
+
console.log();
|
|
79
|
+
|
|
80
|
+
console.log(color.bold(color.green('✓ ASCII test complete')));
|
|
81
|
+
console.log();
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 04 — Trees
|
|
3
|
+
*
|
|
4
|
+
* Run: npx tsx examples/04-trees.ts
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
tree,
|
|
9
|
+
renderTree,
|
|
10
|
+
walkTree,
|
|
11
|
+
findInTree,
|
|
12
|
+
countNodes,
|
|
13
|
+
mapTree,
|
|
14
|
+
filterTree,
|
|
15
|
+
measureTree,
|
|
16
|
+
color,
|
|
17
|
+
type TreeData,
|
|
18
|
+
} from '../src/index.js';
|
|
19
|
+
|
|
20
|
+
console.log();
|
|
21
|
+
console.log(color.bold('━━━ Builder API ━━━'));
|
|
22
|
+
console.log();
|
|
23
|
+
|
|
24
|
+
const project = tree({ label: 'my-app', icon: '📦', color: color.bold });
|
|
25
|
+
const src = project.add({ label: 'src', icon: '📁' });
|
|
26
|
+
src.addLeaf({ label: 'index.ts', icon: '📄' });
|
|
27
|
+
src.addLeaf({ label: 'app.ts', icon: '📄' });
|
|
28
|
+
const utils = src.add({ label: 'utils', icon: '📁' });
|
|
29
|
+
utils.addLeaf({ label: 'helpers.ts', icon: '📄' });
|
|
30
|
+
utils.addLeaf({ label: 'logger.ts', icon: '📄' });
|
|
31
|
+
project.addLeaf({ label: 'package.json', icon: '📦' });
|
|
32
|
+
project.addLeaf({ label: 'README.md', icon: '📝' });
|
|
33
|
+
|
|
34
|
+
console.log(project.render());
|
|
35
|
+
console.log();
|
|
36
|
+
|
|
37
|
+
console.log(color.bold('━━━ Tree styles ━━━'));
|
|
38
|
+
console.log();
|
|
39
|
+
|
|
40
|
+
const styles = ['rounded', 'classic', 'thick', 'double', 'ascii', 'heavy'] as const;
|
|
41
|
+
for (const style of styles) {
|
|
42
|
+
console.log(color.dim(`// style: ${style}`));
|
|
43
|
+
console.log(project.render({ style }));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
console.log(color.bold('━━━ Palette colors ━━━'));
|
|
47
|
+
console.log();
|
|
48
|
+
|
|
49
|
+
console.log(project.render({
|
|
50
|
+
style: 'rounded',
|
|
51
|
+
palette: [color.cyan, color.green, color.magenta, color.yellow],
|
|
52
|
+
guideColor: color.dim,
|
|
53
|
+
}));
|
|
54
|
+
console.log();
|
|
55
|
+
|
|
56
|
+
console.log(color.bold('━━━ Plain-data API ━━━'));
|
|
57
|
+
console.log();
|
|
58
|
+
|
|
59
|
+
const tree2: TreeData = {
|
|
60
|
+
label: 'dependencies',
|
|
61
|
+
icon: '📦',
|
|
62
|
+
children: [
|
|
63
|
+
{
|
|
64
|
+
label: 'production',
|
|
65
|
+
icon: '🔒',
|
|
66
|
+
children: [
|
|
67
|
+
{ label: 'react@18.2.0', icon: '⚛️' },
|
|
68
|
+
{ label: 'tailwind@3.4.1', icon: '🎨' },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
label: 'development',
|
|
73
|
+
icon: '🛠️',
|
|
74
|
+
children: [
|
|
75
|
+
{ label: 'typescript@5.4.0', icon: '🔷' },
|
|
76
|
+
{ label: 'jest@29.7.0', icon: '🧪' },
|
|
77
|
+
{ label: 'eslint@8.57.0', icon: '✅' },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
console.log(renderTree(tree2));
|
|
84
|
+
console.log();
|
|
85
|
+
|
|
86
|
+
console.log(color.bold('━━━ maxDepth truncation ━━━'));
|
|
87
|
+
console.log();
|
|
88
|
+
console.log(color.dim('// maxDepth: 1'));
|
|
89
|
+
console.log(renderTree(tree2, { maxDepth: 1 }));
|
|
90
|
+
console.log();
|
|
91
|
+
|
|
92
|
+
console.log(color.bold('━━━ Algorithms ━━━'));
|
|
93
|
+
console.log();
|
|
94
|
+
console.log(' countNodes:', countNodes(tree2));
|
|
95
|
+
|
|
96
|
+
const found = findInTree(tree2, (n) => n.label.includes('react'));
|
|
97
|
+
console.log(' findInTree (react):', found?.label);
|
|
98
|
+
|
|
99
|
+
console.log(' walkTree paths:');
|
|
100
|
+
walkTree(tree2, (node, depth) => {
|
|
101
|
+
if (depth > 0) console.log(' ' + ' '.repeat(depth) + '→ ' + node.label);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const upper = mapTree(tree2, (node) => ({ ...node, label: node.label.toUpperCase() }));
|
|
105
|
+
console.log('\n mapTree (uppercase):');
|
|
106
|
+
console.log(renderTree(upper));
|
|
107
|
+
|
|
108
|
+
const onlyDev = filterTree(tree2, (n) => n.label !== 'production', { prune: true });
|
|
109
|
+
console.log(' filterTree (no production):');
|
|
110
|
+
if (onlyDev) console.log(renderTree(onlyDev));
|
|
111
|
+
|
|
112
|
+
const dim = measureTree(tree2);
|
|
113
|
+
console.log(` measureTree: ${dim.width} × ${dim.height}`);
|
|
114
|
+
console.log();
|
|
115
|
+
|
|
116
|
+
console.log(color.bold(color.green('✓ Trees test complete')));
|
|
117
|
+
console.log();
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 05 — Components (NO interactive menu — tested separately)
|
|
3
|
+
*
|
|
4
|
+
* Run: npx tsx examples/05-components.ts
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { components, box, color } from '../src/index.js';
|
|
8
|
+
|
|
9
|
+
console.log();
|
|
10
|
+
console.log(color.bold('━━━ Tables ━━━'));
|
|
11
|
+
console.log();
|
|
12
|
+
|
|
13
|
+
console.log(components.table([
|
|
14
|
+
['Module', 'Status', 'Coverage', 'Tests'],
|
|
15
|
+
['colors', color.green('● ready'), '100%', '180'],
|
|
16
|
+
['animations', color.green('● ready'), '99%', '245'],
|
|
17
|
+
['loaders', color.green('● ready'), '99%', '210'],
|
|
18
|
+
['frames', color.green('● ready'), '99%', '125'],
|
|
19
|
+
['components', color.green('● ready'), '100%', '198'],
|
|
20
|
+
['themes', color.green('● ready'), '100%', '94'],
|
|
21
|
+
['trees', color.green('● ready'), '100%', '87'],
|
|
22
|
+
], { borderStyle: 'rounded' }));
|
|
23
|
+
console.log();
|
|
24
|
+
|
|
25
|
+
console.log(color.dim('// Table with double border'));
|
|
26
|
+
console.log(components.table([
|
|
27
|
+
['Name', 'Age', 'City'],
|
|
28
|
+
['Ana', '25', 'Madrid'],
|
|
29
|
+
['Carlos', '30', 'Lima'],
|
|
30
|
+
], { borderStyle: 'double' }));
|
|
31
|
+
console.log();
|
|
32
|
+
|
|
33
|
+
console.log(color.bold('━━━ Badges ━━━'));
|
|
34
|
+
console.log();
|
|
35
|
+
console.log(' ',
|
|
36
|
+
components.badge('VERSION', 'v1.1.0'),
|
|
37
|
+
components.badge('BUILD', 'passing'),
|
|
38
|
+
components.badge('LICENSE', 'Apache 2.0'),
|
|
39
|
+
components.badge('NPM', 'ansimax'),
|
|
40
|
+
);
|
|
41
|
+
console.log();
|
|
42
|
+
|
|
43
|
+
console.log(color.bold('━━━ Status ━━━'));
|
|
44
|
+
console.log();
|
|
45
|
+
console.log(components.status('Build started', { type: 'info' }));
|
|
46
|
+
console.log(components.status('Linting passed', { type: 'success' }));
|
|
47
|
+
console.log(components.status('5 deprecation warnings', { type: 'warning' }));
|
|
48
|
+
console.log(components.status('Build failed', { type: 'error' }));
|
|
49
|
+
console.log();
|
|
50
|
+
|
|
51
|
+
console.log(color.bold('━━━ Section ━━━'));
|
|
52
|
+
console.log();
|
|
53
|
+
console.log(components.section('Installation Steps', { width: 60 }));
|
|
54
|
+
console.log();
|
|
55
|
+
console.log(components.section('Configuration', { width: 60 }));
|
|
56
|
+
console.log();
|
|
57
|
+
|
|
58
|
+
console.log(color.bold('━━━ Columns ━━━'));
|
|
59
|
+
console.log();
|
|
60
|
+
console.log(components.columns([
|
|
61
|
+
'Lorem ipsum dolor sit amet',
|
|
62
|
+
'Consectetur adipiscing elit',
|
|
63
|
+
'Sed do eiusmod tempor',
|
|
64
|
+
], { cols: 3, gap: 2, width: 60 }));
|
|
65
|
+
console.log();
|
|
66
|
+
|
|
67
|
+
console.log(color.bold('━━━ Timeline ━━━'));
|
|
68
|
+
console.log();
|
|
69
|
+
console.log(components.timeline([
|
|
70
|
+
{ label: 'Project initialized', done: true, time: '10:00' },
|
|
71
|
+
{ label: 'Dependencies installed', done: true, time: '10:05' },
|
|
72
|
+
{ label: 'Build pipeline configured', done: true, time: '10:15' },
|
|
73
|
+
{ label: 'Tests running', done: false, time: '10:32' },
|
|
74
|
+
{ label: 'Deploy to npm', done: false },
|
|
75
|
+
]));
|
|
76
|
+
console.log();
|
|
77
|
+
|
|
78
|
+
console.log(color.bold('━━━ Static progress bars ━━━'));
|
|
79
|
+
console.log();
|
|
80
|
+
for (const pct of [10, 25, 50, 75, 90, 100]) {
|
|
81
|
+
console.log(' ', `${pct.toString().padStart(3)}%`, components.progressBar(pct, { width: 30 }));
|
|
82
|
+
}
|
|
83
|
+
console.log();
|
|
84
|
+
|
|
85
|
+
console.log(color.bold('━━━ box utility ━━━'));
|
|
86
|
+
console.log();
|
|
87
|
+
console.log(box('Simple box utility', { padding: 1 }));
|
|
88
|
+
console.log();
|
|
89
|
+
console.log(box('Padded + bordered\nwith multiple lines', {
|
|
90
|
+
padding: 2,
|
|
91
|
+
borderStyle: 'rounded',
|
|
92
|
+
}));
|
|
93
|
+
console.log();
|
|
94
|
+
|
|
95
|
+
console.log(color.bold(color.green('✓ Components test complete')));
|
|
96
|
+
console.log();
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 06 — Pixel Art & Canvas
|
|
3
|
+
*
|
|
4
|
+
* Tests sprites, custom canvas, gradient rectangles, transforms.
|
|
5
|
+
*
|
|
6
|
+
* Run: npx tsx examples/06-pixel-art.ts
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
images,
|
|
11
|
+
createCanvas,
|
|
12
|
+
gradientRect,
|
|
13
|
+
SPRITES,
|
|
14
|
+
flipHorizontal,
|
|
15
|
+
flipVertical,
|
|
16
|
+
rotate90,
|
|
17
|
+
color,
|
|
18
|
+
} from '../src/index.js';
|
|
19
|
+
|
|
20
|
+
console.log();
|
|
21
|
+
console.log(color.bold('━━━ Built-in Sprites ━━━'));
|
|
22
|
+
console.log();
|
|
23
|
+
|
|
24
|
+
// List available sprites
|
|
25
|
+
console.log(color.dim('Available sprites:'), Object.keys(SPRITES).join(', '));
|
|
26
|
+
console.log();
|
|
27
|
+
|
|
28
|
+
// Render a couple
|
|
29
|
+
console.log(color.dim('// heart sprite'));
|
|
30
|
+
console.log(images.sprite('heart'));
|
|
31
|
+
console.log();
|
|
32
|
+
|
|
33
|
+
console.log(color.dim('// star sprite'));
|
|
34
|
+
console.log(images.sprite('star'));
|
|
35
|
+
console.log();
|
|
36
|
+
|
|
37
|
+
console.log(color.bold('━━━ Gradient Rectangles ━━━'));
|
|
38
|
+
console.log();
|
|
39
|
+
|
|
40
|
+
console.log(color.dim('// Linear gradient'));
|
|
41
|
+
console.log(gradientRect({
|
|
42
|
+
width: 50,
|
|
43
|
+
height: 3,
|
|
44
|
+
colors: ['#ff6b6b', '#feca57', '#48dbfb'],
|
|
45
|
+
}));
|
|
46
|
+
console.log();
|
|
47
|
+
|
|
48
|
+
console.log(color.dim('// Linear with Bayer dither'));
|
|
49
|
+
console.log(gradientRect({
|
|
50
|
+
width: 50,
|
|
51
|
+
height: 4,
|
|
52
|
+
colors: ['#ff6b6b', '#feca57', '#48dbfb'],
|
|
53
|
+
dither: 'bayer',
|
|
54
|
+
}));
|
|
55
|
+
console.log();
|
|
56
|
+
|
|
57
|
+
console.log(color.dim('// Diagonal gradient'));
|
|
58
|
+
console.log(gradientRect({
|
|
59
|
+
width: 40,
|
|
60
|
+
height: 4,
|
|
61
|
+
colors: ['#bd93f9', '#8be9fd'],
|
|
62
|
+
angle: 45,
|
|
63
|
+
}));
|
|
64
|
+
console.log();
|
|
65
|
+
|
|
66
|
+
console.log(color.dim('// Radial gradient'));
|
|
67
|
+
console.log(gradientRect({
|
|
68
|
+
width: 30,
|
|
69
|
+
height: 8,
|
|
70
|
+
colors: ['#ff79c6', '#282a36'],
|
|
71
|
+
type: 'radial',
|
|
72
|
+
}));
|
|
73
|
+
console.log();
|
|
74
|
+
|
|
75
|
+
console.log(color.bold('━━━ Custom Canvas ━━━'));
|
|
76
|
+
console.log();
|
|
77
|
+
|
|
78
|
+
const c = createCanvas(40, 10);
|
|
79
|
+
|
|
80
|
+
// Background
|
|
81
|
+
c.fill({ r: 18, g: 18, b: 38 });
|
|
82
|
+
|
|
83
|
+
// Some shapes
|
|
84
|
+
c.drawRect(2, 2, 8, 4, { r: 255, g: 100, b: 100 }, true);
|
|
85
|
+
c.drawRect(15, 2, 8, 4, { r: 100, g: 255, b: 100 }, true);
|
|
86
|
+
c.drawRect(28, 2, 8, 4, { r: 100, g: 100, b: 255 }, true);
|
|
87
|
+
|
|
88
|
+
// Circle
|
|
89
|
+
c.drawCircle(20, 7, 2, { r: 255, g: 220, b: 100 }, true);
|
|
90
|
+
|
|
91
|
+
c.print();
|
|
92
|
+
console.log();
|
|
93
|
+
|
|
94
|
+
console.log(color.bold('━━━ Sprite transforms ━━━'));
|
|
95
|
+
console.log();
|
|
96
|
+
|
|
97
|
+
const star = SPRITES.star!.pixels;
|
|
98
|
+
|
|
99
|
+
console.log(color.dim('// Original'));
|
|
100
|
+
console.log(images.render(star));
|
|
101
|
+
console.log();
|
|
102
|
+
|
|
103
|
+
console.log(color.dim('// Flipped horizontal'));
|
|
104
|
+
console.log(images.render(flipHorizontal(star)));
|
|
105
|
+
console.log();
|
|
106
|
+
|
|
107
|
+
console.log(color.dim('// Flipped vertical'));
|
|
108
|
+
console.log(images.render(flipVertical(star)));
|
|
109
|
+
console.log();
|
|
110
|
+
|
|
111
|
+
console.log(color.dim('// Rotated 90°'));
|
|
112
|
+
console.log(images.render(rotate90(star)));
|
|
113
|
+
console.log();
|
|
114
|
+
|
|
115
|
+
console.log(color.bold(color.green('✓ Pixel art test complete')));
|
|
116
|
+
console.log();
|