ansimax 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/README.es.md +697 -629
- package/README.md +444 -376
- package/dist/index.d.mts +1256 -336
- package/dist/index.d.ts +1256 -336
- package/dist/index.js +4391 -683
- package/dist/index.mjs +4293 -682
- package/examples/01-cli-installer.ts +96 -0
- package/examples/02-live-dashboard.ts +152 -0
- package/examples/03-pixel-art-game.ts +170 -0
- package/examples/04-interactive-deploy.ts +163 -0
- package/examples/05-tree-visualizations.ts +183 -0
- package/examples/06-everything-together.ts +466 -0
- package/examples/animations.ts +172 -0
- package/examples/demo.js +213 -0
- package/examples/demo.ts +212 -0
- package/examples/loaders.ts +254 -0
- package/examples/showcase.ts +174 -0
- package/examples/trees-basic.ts +99 -0
- package/examples/tsconfig.json +18 -0
- package/examples/tsconfig.vscode.json +25 -0
- package/package.json +20 -8
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// ANSIMAX — Animations Showcase
|
|
3
|
+
//
|
|
4
|
+
// Designed for screen recording. Each animation has:
|
|
5
|
+
// - A clear label before
|
|
6
|
+
// - A pause to capture the start
|
|
7
|
+
// - The animation itself
|
|
8
|
+
// - A pause to capture the end
|
|
9
|
+
//
|
|
10
|
+
// Run with:
|
|
11
|
+
// npx tsx examples/animations.ts
|
|
12
|
+
// ─────────────────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
color, gradient, rainbow,
|
|
16
|
+
animate,
|
|
17
|
+
ascii,
|
|
18
|
+
sleep, write, writeln, screen,
|
|
19
|
+
} from '../dist/index.js';
|
|
20
|
+
|
|
21
|
+
// ── Helper: clear screen and show section header ─────────────
|
|
22
|
+
const showHeader = async (num: number, name: string, description: string): Promise<void> => {
|
|
23
|
+
write(screen.clear());
|
|
24
|
+
writeln('');
|
|
25
|
+
writeln(ascii.banner('ANIMATIONS', { font: 'small', colorFn: rainbow, align: 'center' }));
|
|
26
|
+
writeln('');
|
|
27
|
+
writeln(ascii.divider({ width: 60 }));
|
|
28
|
+
writeln(' ' + color.bold(color.cyan(`${num}. ${name}`)));
|
|
29
|
+
writeln(' ' + color.dim(description));
|
|
30
|
+
writeln(ascii.divider({ width: 60 }));
|
|
31
|
+
writeln('');
|
|
32
|
+
await sleep(1500); // pause to capture title
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const main = async (): Promise<void> => {
|
|
36
|
+
write(screen.clear());
|
|
37
|
+
|
|
38
|
+
// ── INTRO ─────────────────────────────────────────────────
|
|
39
|
+
writeln('');
|
|
40
|
+
writeln(ascii.banner('ANSIMAX', { font: 'big', colorFn: rainbow, align: 'center' }));
|
|
41
|
+
writeln('');
|
|
42
|
+
writeln(' ' + color.bold(' All 7 animation effects'));
|
|
43
|
+
writeln(' ' + color.dim(' Watch each one in action'));
|
|
44
|
+
writeln('');
|
|
45
|
+
await sleep(2500);
|
|
46
|
+
|
|
47
|
+
// ── 1. TYPEWRITER ─────────────────────────────────────────
|
|
48
|
+
await showHeader(1, 'TYPEWRITER', 'Types each character one by one');
|
|
49
|
+
await animate.typewriter(' Welcome to Ansimax — typing character by character...', { speed: 60 });
|
|
50
|
+
writeln('');
|
|
51
|
+
await animate.typewriter(' ' + color.cyan('Perfect for intros and storytelling.'), { speed: 50 });
|
|
52
|
+
await sleep(2000);
|
|
53
|
+
|
|
54
|
+
// ── 2. FADE IN ────────────────────────────────────────────
|
|
55
|
+
await showHeader(2, 'FADE IN', 'Smooth color fade from black to full brightness');
|
|
56
|
+
await animate.fadeIn(' Fading in gracefully into view...', {
|
|
57
|
+
duration: 1500, steps: 20, color: '#48dbfb',
|
|
58
|
+
});
|
|
59
|
+
writeln('');
|
|
60
|
+
await animate.fadeIn(' Use it for elegant reveals.', {
|
|
61
|
+
duration: 1200, color: '#feca57',
|
|
62
|
+
});
|
|
63
|
+
await sleep(2000);
|
|
64
|
+
|
|
65
|
+
// ── 3. FADE OUT ───────────────────────────────────────────
|
|
66
|
+
await showHeader(3, 'FADE OUT', 'Disappears smoothly into the background');
|
|
67
|
+
writeln(' Watch this text fade away...');
|
|
68
|
+
await sleep(800);
|
|
69
|
+
await animate.fadeOut(' Watch this text fade away...', {
|
|
70
|
+
duration: 1500, steps: 20, color: '#ff6b6b',
|
|
71
|
+
});
|
|
72
|
+
await sleep(1500);
|
|
73
|
+
|
|
74
|
+
// ── 4. SLIDE ──────────────────────────────────────────────
|
|
75
|
+
await showHeader(4, 'SLIDE', 'Slides in from a direction');
|
|
76
|
+
await animate.slide(' Sliding in from the left...', {
|
|
77
|
+
direction: 'left', duration: 800,
|
|
78
|
+
});
|
|
79
|
+
writeln('');
|
|
80
|
+
await sleep(500);
|
|
81
|
+
await animate.slide(' And from the right...', {
|
|
82
|
+
direction: 'right', duration: 800,
|
|
83
|
+
});
|
|
84
|
+
await sleep(2000);
|
|
85
|
+
|
|
86
|
+
// ── 5. PULSE ──────────────────────────────────────────────
|
|
87
|
+
await showHeader(5, 'PULSE', 'Pulses between two colors — great for alerts');
|
|
88
|
+
await animate.pulse(' ⚠️ IMPORTANT NOTIFICATION', {
|
|
89
|
+
times: 4, interval: 350,
|
|
90
|
+
color1: { r: 255, g: 100, b: 100 },
|
|
91
|
+
color2: { r: 255, g: 220, b: 100 },
|
|
92
|
+
});
|
|
93
|
+
writeln('');
|
|
94
|
+
await animate.pulse(' ✓ SUCCESS — Operation complete', {
|
|
95
|
+
times: 3, interval: 400,
|
|
96
|
+
color1: { r: 100, g: 255, b: 150 },
|
|
97
|
+
color2: { r: 100, g: 200, b: 255 },
|
|
98
|
+
});
|
|
99
|
+
await sleep(2000);
|
|
100
|
+
|
|
101
|
+
// ── 6. WAVE ───────────────────────────────────────────────
|
|
102
|
+
await showHeader(6, 'WAVE', 'Color wave flowing across each character');
|
|
103
|
+
await animate.wave(' WAVE OF COLORS FLOWING ACROSS LETTERS', {
|
|
104
|
+
duration: 2500, steps: 40,
|
|
105
|
+
colors: ['#ff0000', '#ff7f00', '#ffff00', '#00ff00', '#0000ff', '#8b00ff'],
|
|
106
|
+
});
|
|
107
|
+
writeln('');
|
|
108
|
+
await animate.wave(' Custom palette: ocean tones', {
|
|
109
|
+
duration: 2000, steps: 30,
|
|
110
|
+
colors: ['#0070f3', '#48dbfb', '#7928ca', '#ff0080'],
|
|
111
|
+
});
|
|
112
|
+
await sleep(2000);
|
|
113
|
+
|
|
114
|
+
// ── 7. GLITCH ─────────────────────────────────────────────
|
|
115
|
+
await showHeader(7, 'GLITCH', 'Random character corruption — perfect for cyberpunk vibes');
|
|
116
|
+
await animate.glitch(' S Y S T E M E R R O R', {
|
|
117
|
+
duration: 1500, intensity: 5,
|
|
118
|
+
});
|
|
119
|
+
writeln('');
|
|
120
|
+
await animate.glitch(' Hacking the mainframe...', {
|
|
121
|
+
duration: 1800, intensity: 4,
|
|
122
|
+
});
|
|
123
|
+
writeln('');
|
|
124
|
+
await animate.glitch(' ACCESS GRANTED', {
|
|
125
|
+
duration: 1200, intensity: 6,
|
|
126
|
+
});
|
|
127
|
+
await sleep(2000);
|
|
128
|
+
|
|
129
|
+
// ── 8. REVEAL ─────────────────────────────────────────────
|
|
130
|
+
await showHeader(8, 'REVEAL', 'Decrypts random characters into the real text');
|
|
131
|
+
await animate.reveal(' TOP SECRET — CLASSIFIED INFORMATION', {
|
|
132
|
+
duration: 2000,
|
|
133
|
+
});
|
|
134
|
+
writeln('');
|
|
135
|
+
await animate.reveal(' Decoding transmission...', {
|
|
136
|
+
duration: 1500,
|
|
137
|
+
charset: '0123456789ABCDEF',
|
|
138
|
+
});
|
|
139
|
+
writeln('');
|
|
140
|
+
await animate.reveal(' Welcome to the future', {
|
|
141
|
+
duration: 1800,
|
|
142
|
+
});
|
|
143
|
+
await sleep(2000);
|
|
144
|
+
|
|
145
|
+
// ── COMBO ─────────────────────────────────────────────────
|
|
146
|
+
await showHeader(9, 'COMBINING EFFECTS', 'All animations work together');
|
|
147
|
+
await animate.typewriter(' Step 1: Typewriter intro...', { speed: 40 });
|
|
148
|
+
await sleep(500);
|
|
149
|
+
await animate.fadeIn(' Step 2: Fade in confirmation', { duration: 1000, color: '#00ff88' });
|
|
150
|
+
await sleep(500);
|
|
151
|
+
await animate.pulse(' Step 3: Pulse alert', { times: 2, interval: 400 });
|
|
152
|
+
await sleep(500);
|
|
153
|
+
await animate.glitch(' Step 4: Final glitch', { duration: 1000, intensity: 4 });
|
|
154
|
+
await sleep(2000);
|
|
155
|
+
|
|
156
|
+
// ── OUTRO ─────────────────────────────────────────────────
|
|
157
|
+
write(screen.clear());
|
|
158
|
+
writeln('');
|
|
159
|
+
writeln(ascii.banner('THANKS!', { font: 'big', colorFn: rainbow, align: 'center' }));
|
|
160
|
+
writeln('');
|
|
161
|
+
writeln(' ' + color.bold(color.cyan(' All 7 animations covered.')));
|
|
162
|
+
writeln(' ' + color.dim(' Each one supports AbortSignal + reducedMotion.'));
|
|
163
|
+
writeln('');
|
|
164
|
+
writeln(' ' + color.dim(' $ npm install ansimax'));
|
|
165
|
+
writeln('');
|
|
166
|
+
await sleep(3000);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
main().catch((err: unknown) => {
|
|
170
|
+
console.error(color.red('Demo failed:'), err);
|
|
171
|
+
process.exit(1);
|
|
172
|
+
});
|
package/examples/demo.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// ANSIMAX — JavaScript Demo (CommonJS)
|
|
3
|
+
//
|
|
4
|
+
// Run after build:
|
|
5
|
+
// npm run build
|
|
6
|
+
// node examples/demo.js
|
|
7
|
+
//
|
|
8
|
+
// This file imports from the compiled output in dist/ so it works
|
|
9
|
+
// with plain Node.js — no TypeScript or transpiler required.
|
|
10
|
+
// ─────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
const ansimax = require('../dist/index.js').default;
|
|
13
|
+
const {
|
|
14
|
+
color, gradient, rainbow, compose,
|
|
15
|
+
animate,
|
|
16
|
+
ascii,
|
|
17
|
+
loader,
|
|
18
|
+
frames,
|
|
19
|
+
components,
|
|
20
|
+
themes,
|
|
21
|
+
images, createCanvas,
|
|
22
|
+
sleep, writeln,
|
|
23
|
+
hexToRgb, isHexColor, truncateAnsi, wordWrap,
|
|
24
|
+
} = require('../dist/index.js');
|
|
25
|
+
|
|
26
|
+
// ── Section divider ──────────────────────────────────────────
|
|
27
|
+
const section = (title) => {
|
|
28
|
+
writeln('');
|
|
29
|
+
writeln(ascii.divider({ label: color.bold(color.cyan(title)), width: 60 }));
|
|
30
|
+
writeln('');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const main = async () => {
|
|
34
|
+
// ── 0 · INTRO ─────────────────────────────────────────────
|
|
35
|
+
writeln('');
|
|
36
|
+
writeln(ascii.banner('ANSIMAX', { font: 'big', colorFn: rainbow, align: 'center' }));
|
|
37
|
+
writeln(color.dim(' JavaScript demo — all modules'));
|
|
38
|
+
await sleep(800);
|
|
39
|
+
|
|
40
|
+
// ── 1 · COLORS ────────────────────────────────────────────
|
|
41
|
+
section('1 · Colors');
|
|
42
|
+
writeln(' ' + color.red('red') + ' ' + color.green('green') + ' ' + color.blue('blue') +
|
|
43
|
+
' ' + color.yellow('yellow') + ' ' + color.magenta('magenta'));
|
|
44
|
+
writeln(' ' + color.bold('bold') + ' ' + color.italic('italic') + ' ' +
|
|
45
|
+
color.underline('underline') + ' ' + color.strikethrough('strike'));
|
|
46
|
+
writeln(' ' + color.gray('gray') + ' ' + color.orange('orange') + ' ' + color.purple('purple'));
|
|
47
|
+
writeln(' rgb: ' + color.rgb(255, 100, 50)('custom RGB'));
|
|
48
|
+
writeln(' hex: ' + color.hex('#ff6b6b')('#ff6b6b'));
|
|
49
|
+
writeln(' bgHex: ' + color.bgHex('#0575e6')(color.white(' background ')));
|
|
50
|
+
writeln(' compose: ' + compose(color.bold, color.red, color.underline)('CRITICAL'));
|
|
51
|
+
writeln(' gradient: ' + gradient('Smooth color transitions', ['#ff6b6b', '#feca57', '#48dbfb']));
|
|
52
|
+
writeln(' rainbow: ' + rainbow('Taste the rainbow!'));
|
|
53
|
+
await sleep(800);
|
|
54
|
+
|
|
55
|
+
// ── 2 · ASCII ART ─────────────────────────────────────────
|
|
56
|
+
section('2 · ASCII Art');
|
|
57
|
+
writeln(ascii.big('HELLO'));
|
|
58
|
+
writeln('');
|
|
59
|
+
writeln(ascii.small('small font'));
|
|
60
|
+
writeln('');
|
|
61
|
+
writeln(ascii.box('Rounded box with padding', { borderStyle: 'rounded', padding: 1 }));
|
|
62
|
+
writeln('');
|
|
63
|
+
writeln(ascii.box(rainbow('Rainbow inside box'), { borderStyle: 'double', padding: 2 }));
|
|
64
|
+
await sleep(800);
|
|
65
|
+
|
|
66
|
+
// ── 3 · ANIMATIONS ────────────────────────────────────────
|
|
67
|
+
section('3 · Animations');
|
|
68
|
+
await animate.typewriter(' Typewriter effect — typing one char at a time...', { speed: 25 });
|
|
69
|
+
await animate.fadeIn(' Fading in...', { duration: 500, color: '#48dbfb' });
|
|
70
|
+
await animate.slide(' Sliding in', { direction: 'left', duration: 400 });
|
|
71
|
+
await animate.pulse(' Pulsing color', { times: 2, interval: 200 });
|
|
72
|
+
await animate.wave(' Wave through letters', { duration: 800, steps: 20 });
|
|
73
|
+
await animate.glitch(' Glitch effect!', { duration: 500, intensity: 4 });
|
|
74
|
+
await animate.reveal(' Revealing hidden text', { duration: 700 });
|
|
75
|
+
|
|
76
|
+
// ── 4 · LOADERS ───────────────────────────────────────────
|
|
77
|
+
section('4 · Loaders & Progress');
|
|
78
|
+
|
|
79
|
+
const spin = loader.spin('Processing data...', { type: 'dots', color: '#00ff88' });
|
|
80
|
+
await sleep(1500);
|
|
81
|
+
spin('Data processed', true);
|
|
82
|
+
|
|
83
|
+
await loader.progressAnimate(25, 'Installing packages', { delay: 30, color: '#48dbfb' });
|
|
84
|
+
|
|
85
|
+
const taskResults = await loader.tasks([
|
|
86
|
+
{ text: 'Fetching dependencies', fn: async () => { await sleep(400); return 'ok'; } },
|
|
87
|
+
{ text: 'Compiling sources', fn: async () => { await sleep(600); return 'ok'; } },
|
|
88
|
+
{ text: 'Running tests', fn: async () => { await sleep(300); return 'ok'; } },
|
|
89
|
+
]);
|
|
90
|
+
writeln(color.dim(` → ${taskResults.length} tasks completed`));
|
|
91
|
+
|
|
92
|
+
writeln('');
|
|
93
|
+
await loader.countdown(3, { label: 'Launching in', color: '#ffd700' });
|
|
94
|
+
writeln(color.green(' 🚀 Launched!'));
|
|
95
|
+
|
|
96
|
+
// ── 5 · FRAMES ────────────────────────────────────────────
|
|
97
|
+
section('5 · Frame Engine');
|
|
98
|
+
|
|
99
|
+
await frames.play(frames.presets.loadingBar({ width: 30 }), { interval: 40, repeat: 1 });
|
|
100
|
+
await frames.play(frames.presets.ball({ width: 25 }), { interval: 60, repeat: 2 });
|
|
101
|
+
|
|
102
|
+
// Morph — unique ansimax feature
|
|
103
|
+
const morphed = frames.morph('LOADING', 'COMPLETE', 12);
|
|
104
|
+
await frames.play(morphed, { interval: 80, repeat: 1 });
|
|
105
|
+
writeln('');
|
|
106
|
+
|
|
107
|
+
// ── 6 · COMPONENTS ────────────────────────────────────────
|
|
108
|
+
section('6 · UI Components');
|
|
109
|
+
|
|
110
|
+
writeln(components.table([
|
|
111
|
+
['Name', 'Status', 'Score'],
|
|
112
|
+
['Alice', '✓ active', '95'],
|
|
113
|
+
['Bob', '⚠ pending', '78'],
|
|
114
|
+
['Charlie', '✗ inactive', '42'],
|
|
115
|
+
], { header: true, borderStyle: 'rounded' }));
|
|
116
|
+
writeln('');
|
|
117
|
+
|
|
118
|
+
writeln(components.status('success', 'All tests passed'));
|
|
119
|
+
writeln(components.status('error', 'Build failed'));
|
|
120
|
+
writeln(components.status('warn', 'Deprecation notice'));
|
|
121
|
+
writeln(components.status('info', 'Update available'));
|
|
122
|
+
writeln(components.status('wait', 'Syncing...'));
|
|
123
|
+
writeln('');
|
|
124
|
+
|
|
125
|
+
writeln(' ' + components.badge('VERSION', 'v1.0.0') + ' ' +
|
|
126
|
+
components.badge('BUILD', 'passing') + ' ' +
|
|
127
|
+
components.badge('LICENSE', 'MIT'));
|
|
128
|
+
writeln('');
|
|
129
|
+
|
|
130
|
+
writeln(components.timeline([
|
|
131
|
+
{ label: 'Setup', done: true, time: '10:00' },
|
|
132
|
+
{ label: 'Build', done: true, time: '10:15' },
|
|
133
|
+
{ label: 'Test', done: true, time: '10:32' },
|
|
134
|
+
{ label: 'Deploy', done: false, time: 'pending' },
|
|
135
|
+
{ label: 'Notify', done: false },
|
|
136
|
+
]));
|
|
137
|
+
await sleep(600);
|
|
138
|
+
|
|
139
|
+
// ── 7 · THEMES ────────────────────────────────────────────
|
|
140
|
+
section('7 · Themes');
|
|
141
|
+
|
|
142
|
+
themes.list().forEach((name) => {
|
|
143
|
+
themes.use(name);
|
|
144
|
+
const t = themes.current();
|
|
145
|
+
writeln(' ' +
|
|
146
|
+
color.hex(t.primary)(name.padEnd(12)) +
|
|
147
|
+
color.hex(t.primary)('●') +
|
|
148
|
+
color.hex(t.secondary)('●') +
|
|
149
|
+
color.hex(t.accent)('●') +
|
|
150
|
+
color.hex(t.error)('●') +
|
|
151
|
+
color.hex(t.warning)('●'));
|
|
152
|
+
});
|
|
153
|
+
themes.use('dracula');
|
|
154
|
+
|
|
155
|
+
// ── 8 · IMAGES & CANVAS ───────────────────────────────────
|
|
156
|
+
section('8 · Pixel Art & Canvas');
|
|
157
|
+
|
|
158
|
+
writeln(' Built-in sprites:');
|
|
159
|
+
writeln(images.sprite('heart'));
|
|
160
|
+
writeln(images.sprite('star'));
|
|
161
|
+
writeln('');
|
|
162
|
+
|
|
163
|
+
writeln(' Sprite transforms (original / flipped):');
|
|
164
|
+
const heart = images.sprites.heart.pixels;
|
|
165
|
+
writeln(images.render(heart, { halfBlock: true }));
|
|
166
|
+
writeln(images.render(images.flipHorizontal(heart), { halfBlock: true }));
|
|
167
|
+
writeln('');
|
|
168
|
+
|
|
169
|
+
writeln(' Custom canvas:');
|
|
170
|
+
const canvas = createCanvas(20, 8);
|
|
171
|
+
canvas.drawRect(0, 0, 20, 8, { r: 30, g: 30, b: 40 }, true);
|
|
172
|
+
canvas.drawCircle(10, 4, 3, { r: 255, g: 200, b: 0 }, true);
|
|
173
|
+
canvas.drawRect(5, 2, 10, 4, { r: 255, g: 100, b: 100 });
|
|
174
|
+
writeln(canvas.render({ halfBlock: true }));
|
|
175
|
+
writeln('');
|
|
176
|
+
|
|
177
|
+
writeln(' Gradient rectangle:');
|
|
178
|
+
writeln(images.gradientRect({
|
|
179
|
+
width: 40, height: 6,
|
|
180
|
+
colors: ['#ff0080', '#7928ca', '#0070f3'],
|
|
181
|
+
style: 'horizontal',
|
|
182
|
+
}));
|
|
183
|
+
|
|
184
|
+
// ── 9 · UTILITIES ─────────────────────────────────────────
|
|
185
|
+
section('9 · Utilities');
|
|
186
|
+
|
|
187
|
+
writeln(` isHexColor('#ff0000'): ${color.green(String(isHexColor('#ff0000')))}`);
|
|
188
|
+
writeln(` isHexColor('banana'): ${color.red(String(isHexColor('banana')))}`);
|
|
189
|
+
writeln(` hexToRgb('#48dbfb'): ${JSON.stringify(hexToRgb('#48dbfb'))}`);
|
|
190
|
+
writeln(` truncateAnsi('hello world', 8): ${truncateAnsi('hello world', 8)}`);
|
|
191
|
+
writeln('');
|
|
192
|
+
writeln(' wordWrap demo (width 20):');
|
|
193
|
+
for (const line of wordWrap('Lorem ipsum dolor sit amet consectetur adipiscing', 20)) {
|
|
194
|
+
writeln(' ' + color.dim('│') + ' ' + line);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// ── 10 · DEFAULT EXPORT ───────────────────────────────────
|
|
198
|
+
section('10 · Default export');
|
|
199
|
+
writeln(' ansimax.color.cyan : ' + ansimax.color.cyan('reachable via default export'));
|
|
200
|
+
writeln(' ansimax.themes.list: ' + JSON.stringify(ansimax.themes.list()));
|
|
201
|
+
|
|
202
|
+
// ── CLOSING ───────────────────────────────────────────────
|
|
203
|
+
section('DONE');
|
|
204
|
+
writeln(ascii.banner('ALL MODULES OK', { font: 'small', colorFn: rainbow, align: 'center' }));
|
|
205
|
+
writeln('');
|
|
206
|
+
writeln(color.dim(' Built with JavaScript + Ansimax · MIT License'));
|
|
207
|
+
writeln('');
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
main().catch((err) => {
|
|
211
|
+
console.error(color.red('Demo failed:'), err);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
});
|
package/examples/demo.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// ANSIMAX — TypeScript Demo
|
|
3
|
+
//
|
|
4
|
+
// Run after build:
|
|
5
|
+
// npm run build
|
|
6
|
+
// npx tsx examples/demo.ts
|
|
7
|
+
//
|
|
8
|
+
// Or:
|
|
9
|
+
// npm run build
|
|
10
|
+
// node --loader ts-node/esm examples/demo.ts
|
|
11
|
+
// ─────────────────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
import ansimax, {
|
|
14
|
+
color, gradient, rainbow, compose,
|
|
15
|
+
animate,
|
|
16
|
+
ascii,
|
|
17
|
+
loader,
|
|
18
|
+
frames,
|
|
19
|
+
components,
|
|
20
|
+
themes,
|
|
21
|
+
images, createCanvas,
|
|
22
|
+
sleep, writeln,
|
|
23
|
+
hexToRgb, isHexColor, truncateAnsi, wordWrap,
|
|
24
|
+
} from '../dist/index.js';
|
|
25
|
+
|
|
26
|
+
const section = (title: string): void => {
|
|
27
|
+
writeln('');
|
|
28
|
+
writeln(ascii.divider({ label: color.bold(color.cyan(title)), width: 60 }));
|
|
29
|
+
writeln('');
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const main = async (): Promise<void> => {
|
|
33
|
+
// ── 0 · INTRO ─────────────────────────────────────────────
|
|
34
|
+
writeln('');
|
|
35
|
+
writeln(ascii.banner('ANSIMAX', { font: 'big', colorFn: rainbow, align: 'center' }));
|
|
36
|
+
writeln(color.dim(' TypeScript demo — all modules'));
|
|
37
|
+
await sleep(800);
|
|
38
|
+
|
|
39
|
+
// ── 1 · COLORS ────────────────────────────────────────────
|
|
40
|
+
section('1 · Colors');
|
|
41
|
+
writeln(' ' + color.red('red') + ' ' + color.green('green') + ' ' + color.blue('blue') +
|
|
42
|
+
' ' + color.yellow('yellow') + ' ' + color.magenta('magenta'));
|
|
43
|
+
writeln(' ' + color.bold('bold') + ' ' + color.italic('italic') + ' ' +
|
|
44
|
+
color.underline('underline') + ' ' + color.strikethrough('strike'));
|
|
45
|
+
writeln(' ' + color.gray('gray') + ' ' + color.orange('orange') + ' ' + color.purple('purple'));
|
|
46
|
+
writeln(' rgb: ' + color.rgb(255, 100, 50)('custom RGB'));
|
|
47
|
+
writeln(' hex: ' + color.hex('#ff6b6b')('#ff6b6b'));
|
|
48
|
+
writeln(' bgHex: ' + color.bgHex('#0575e6')(color.white(' background ')));
|
|
49
|
+
writeln(' compose: ' + compose(color.bold, color.red, color.underline)('CRITICAL'));
|
|
50
|
+
writeln(' gradient: ' + gradient('Smooth color transitions', ['#ff6b6b', '#feca57', '#48dbfb']));
|
|
51
|
+
writeln(' rainbow: ' + rainbow('Taste the rainbow!'));
|
|
52
|
+
await sleep(800);
|
|
53
|
+
|
|
54
|
+
// ── 2 · ASCII ART ─────────────────────────────────────────
|
|
55
|
+
section('2 · ASCII Art');
|
|
56
|
+
writeln(ascii.big('HELLO'));
|
|
57
|
+
writeln('');
|
|
58
|
+
writeln(ascii.small('small font'));
|
|
59
|
+
writeln('');
|
|
60
|
+
writeln(ascii.box('Rounded box with padding', { borderStyle: 'rounded', padding: 1 }));
|
|
61
|
+
writeln('');
|
|
62
|
+
writeln(ascii.box(rainbow('Rainbow inside box'), { borderStyle: 'double', padding: 2 }));
|
|
63
|
+
await sleep(800);
|
|
64
|
+
|
|
65
|
+
// ── 3 · ANIMATIONS ────────────────────────────────────────
|
|
66
|
+
section('3 · Animations');
|
|
67
|
+
await animate.typewriter(' Typewriter effect — typing one char at a time...', { speed: 25 });
|
|
68
|
+
await animate.fadeIn(' Fading in...', { duration: 500, color: '#48dbfb' });
|
|
69
|
+
await animate.slide(' Sliding in', { direction: 'left', duration: 400 });
|
|
70
|
+
await animate.pulse(' Pulsing color', { times: 2, interval: 200 });
|
|
71
|
+
await animate.wave(' Wave through letters', { duration: 800, steps: 20 });
|
|
72
|
+
await animate.glitch(' Glitch effect!', { duration: 500, intensity: 4 });
|
|
73
|
+
await animate.reveal(' Revealing hidden text', { duration: 700 });
|
|
74
|
+
|
|
75
|
+
// ── 4 · LOADERS ───────────────────────────────────────────
|
|
76
|
+
section('4 · Loaders & Progress');
|
|
77
|
+
|
|
78
|
+
const spin = loader.spin('Processing data...', { type: 'dots', color: '#00ff88' });
|
|
79
|
+
await sleep(1500);
|
|
80
|
+
spin('Data processed', true);
|
|
81
|
+
|
|
82
|
+
await loader.progressAnimate(25, 'Installing packages', { delay: 30, color: '#48dbfb' });
|
|
83
|
+
|
|
84
|
+
const taskResults = await loader.tasks([
|
|
85
|
+
{ text: 'Fetching dependencies', fn: async () => { await sleep(400); return 'ok'; } },
|
|
86
|
+
{ text: 'Compiling sources', fn: async () => { await sleep(600); return 'ok'; } },
|
|
87
|
+
{ text: 'Running tests', fn: async () => { await sleep(300); return 'ok'; } },
|
|
88
|
+
]);
|
|
89
|
+
writeln(color.dim(` → ${taskResults.length} tasks completed`));
|
|
90
|
+
|
|
91
|
+
writeln('');
|
|
92
|
+
await loader.countdown(3, { label: 'Launching in', color: '#ffd700' });
|
|
93
|
+
writeln(color.green(' 🚀 Launched!'));
|
|
94
|
+
|
|
95
|
+
// ── 5 · FRAMES ────────────────────────────────────────────
|
|
96
|
+
section('5 · Frame Engine');
|
|
97
|
+
|
|
98
|
+
await frames.play(frames.presets.loadingBar({ width: 30 }), { interval: 40, repeat: 1 });
|
|
99
|
+
await frames.play(frames.presets.ball({ width: 25 }), { interval: 60, repeat: 2 });
|
|
100
|
+
|
|
101
|
+
// Morph — unique ansimax feature
|
|
102
|
+
const morphed = frames.morph('LOADING', 'COMPLETE', 12);
|
|
103
|
+
await frames.play(morphed, { interval: 80, repeat: 1 });
|
|
104
|
+
writeln('');
|
|
105
|
+
|
|
106
|
+
// ── 6 · COMPONENTS ────────────────────────────────────────
|
|
107
|
+
section('6 · UI Components');
|
|
108
|
+
|
|
109
|
+
writeln(components.table([
|
|
110
|
+
['Name', 'Status', 'Score'],
|
|
111
|
+
['Alice', '✓ active', '95'],
|
|
112
|
+
['Bob', '⚠ pending', '78'],
|
|
113
|
+
['Charlie', '✗ inactive', '42'],
|
|
114
|
+
], { header: true, borderStyle: 'rounded' }));
|
|
115
|
+
writeln('');
|
|
116
|
+
|
|
117
|
+
writeln(components.status('success', 'All tests passed'));
|
|
118
|
+
writeln(components.status('error', 'Build failed'));
|
|
119
|
+
writeln(components.status('warn', 'Deprecation notice'));
|
|
120
|
+
writeln(components.status('info', 'Update available'));
|
|
121
|
+
writeln(components.status('wait', 'Syncing...'));
|
|
122
|
+
writeln('');
|
|
123
|
+
|
|
124
|
+
writeln(' ' + components.badge('VERSION', 'v1.0.0') + ' ' +
|
|
125
|
+
components.badge('BUILD', 'passing') + ' ' +
|
|
126
|
+
components.badge('LICENSE', 'MIT'));
|
|
127
|
+
writeln('');
|
|
128
|
+
|
|
129
|
+
writeln(components.timeline([
|
|
130
|
+
{ label: 'Setup', done: true, time: '10:00' },
|
|
131
|
+
{ label: 'Build', done: true, time: '10:15' },
|
|
132
|
+
{ label: 'Test', done: true, time: '10:32' },
|
|
133
|
+
{ label: 'Deploy', done: false, time: 'pending' },
|
|
134
|
+
{ label: 'Notify', done: false },
|
|
135
|
+
]));
|
|
136
|
+
await sleep(600);
|
|
137
|
+
|
|
138
|
+
// ── 7 · THEMES ────────────────────────────────────────────
|
|
139
|
+
section('7 · Themes');
|
|
140
|
+
|
|
141
|
+
themes.list().forEach((name) => {
|
|
142
|
+
themes.use(name);
|
|
143
|
+
const t = themes.current();
|
|
144
|
+
writeln(' ' +
|
|
145
|
+
color.hex(t.primary)(name.padEnd(12)) +
|
|
146
|
+
color.hex(t.primary)('●') +
|
|
147
|
+
color.hex(t.secondary)('●') +
|
|
148
|
+
color.hex(t.accent)('●') +
|
|
149
|
+
color.hex(t.error)('●') +
|
|
150
|
+
color.hex(t.warning)('●'));
|
|
151
|
+
});
|
|
152
|
+
themes.use('dracula');
|
|
153
|
+
|
|
154
|
+
// ── 8 · IMAGES & CANVAS ───────────────────────────────────
|
|
155
|
+
section('8 · Pixel Art & Canvas');
|
|
156
|
+
|
|
157
|
+
writeln(' Built-in sprites:');
|
|
158
|
+
writeln(images.sprite('heart'));
|
|
159
|
+
writeln(images.sprite('star'));
|
|
160
|
+
writeln('');
|
|
161
|
+
|
|
162
|
+
writeln(' Sprite transforms (original / flipped):');
|
|
163
|
+
const heart = images.sprites.heart.pixels;
|
|
164
|
+
writeln(images.render(heart, { halfBlock: true }));
|
|
165
|
+
writeln(images.render(images.flipHorizontal(heart), { halfBlock: true }));
|
|
166
|
+
writeln('');
|
|
167
|
+
|
|
168
|
+
writeln(' Custom canvas:');
|
|
169
|
+
const canvas = createCanvas(20, 8);
|
|
170
|
+
canvas.drawRect(0, 0, 20, 8, { r: 30, g: 30, b: 40 }, true);
|
|
171
|
+
canvas.drawCircle(10, 4, 3, { r: 255, g: 200, b: 0 }, true);
|
|
172
|
+
canvas.drawRect(5, 2, 10, 4, { r: 255, g: 100, b: 100 });
|
|
173
|
+
writeln(canvas.render({ halfBlock: true }));
|
|
174
|
+
writeln('');
|
|
175
|
+
|
|
176
|
+
writeln(' Gradient rectangle:');
|
|
177
|
+
writeln(images.gradientRect({
|
|
178
|
+
width: 40, height: 6,
|
|
179
|
+
colors: ['#ff0080', '#7928ca', '#0070f3'],
|
|
180
|
+
style: 'horizontal',
|
|
181
|
+
}));
|
|
182
|
+
|
|
183
|
+
// ── 9 · UTILITIES ─────────────────────────────────────────
|
|
184
|
+
section('9 · Utilities');
|
|
185
|
+
|
|
186
|
+
writeln(` isHexColor('#ff0000'): ${color.green(String(isHexColor('#ff0000')))}`);
|
|
187
|
+
writeln(` isHexColor('banana'): ${color.red(String(isHexColor('banana')))}`);
|
|
188
|
+
writeln(` hexToRgb('#48dbfb'): ${JSON.stringify(hexToRgb('#48dbfb'))}`);
|
|
189
|
+
writeln(` truncateAnsi('hello world', 8): ${truncateAnsi('hello world', 8)}`);
|
|
190
|
+
writeln('');
|
|
191
|
+
writeln(' wordWrap demo (width 20):');
|
|
192
|
+
for (const line of wordWrap('Lorem ipsum dolor sit amet consectetur adipiscing', 20)) {
|
|
193
|
+
writeln(' ' + color.dim('│') + ' ' + line);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ── 10 · DEFAULT EXPORT ───────────────────────────────────
|
|
197
|
+
section('10 · Default export');
|
|
198
|
+
writeln(' ansimax.color.cyan : ' + ansimax.color.cyan('reachable via default export'));
|
|
199
|
+
writeln(' ansimax.themes.list: ' + JSON.stringify(ansimax.themes.list()));
|
|
200
|
+
|
|
201
|
+
// ── CLOSING ───────────────────────────────────────────────
|
|
202
|
+
section('DONE');
|
|
203
|
+
writeln(ascii.banner('ALL MODULES OK', { font: 'small', colorFn: rainbow, align: 'center' }));
|
|
204
|
+
writeln('');
|
|
205
|
+
writeln(color.dim(' Built with TypeScript + Ansimax · MIT License'));
|
|
206
|
+
writeln('');
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
main().catch((err: unknown) => {
|
|
210
|
+
console.error(color.red('Demo failed:'), err);
|
|
211
|
+
process.exit(1);
|
|
212
|
+
});
|