ansimax 1.0.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 +21 -0
- package/README.es.md +629 -0
- package/README.md +629 -0
- package/dist/index.d.mts +708 -0
- package/dist/index.d.ts +708 -0
- package/dist/index.js +1707 -0
- package/dist/index.mjs +1632 -0
- package/package.json +110 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1707 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
SPINNERS: () => SPINNERS,
|
|
24
|
+
SPRITES: () => SPRITES,
|
|
25
|
+
animate: () => animate,
|
|
26
|
+
ascii: () => ascii,
|
|
27
|
+
bgRgb: () => bgRgb,
|
|
28
|
+
center: () => center,
|
|
29
|
+
clamp: () => clamp,
|
|
30
|
+
color: () => color,
|
|
31
|
+
colorPresets: () => presets,
|
|
32
|
+
components: () => components,
|
|
33
|
+
compose: () => compose,
|
|
34
|
+
configure: () => configure,
|
|
35
|
+
createCanvas: () => createCanvas,
|
|
36
|
+
cursor: () => cursor,
|
|
37
|
+
default: () => index_default,
|
|
38
|
+
fgRgb: () => fgRgb,
|
|
39
|
+
frames: () => frames,
|
|
40
|
+
getConfig: () => getConfig,
|
|
41
|
+
getSpeedMultiplier: () => getSpeedMultiplier,
|
|
42
|
+
gradient: () => gradient,
|
|
43
|
+
gradientRect: () => gradientRect,
|
|
44
|
+
hexToRgb: () => hexToRgb,
|
|
45
|
+
images: () => images,
|
|
46
|
+
isHexColor: () => isHexColor,
|
|
47
|
+
isNoColor: () => isNoColor,
|
|
48
|
+
lerp: () => lerp,
|
|
49
|
+
lerpColor: () => lerpColor,
|
|
50
|
+
loader: () => loader,
|
|
51
|
+
padEnd: () => padEnd,
|
|
52
|
+
padStart: () => padStart,
|
|
53
|
+
rainbow: () => rainbow,
|
|
54
|
+
renderPixelArt: () => renderPixelArt,
|
|
55
|
+
repeatVisible: () => repeatVisible,
|
|
56
|
+
reset: () => reset,
|
|
57
|
+
resetNoColor: () => resetNoColor,
|
|
58
|
+
rgbTo256: () => rgbTo256,
|
|
59
|
+
rgbToHex: () => rgbToHex,
|
|
60
|
+
screen: () => screen,
|
|
61
|
+
setNoColor: () => setNoColor,
|
|
62
|
+
sgr: () => sgr,
|
|
63
|
+
sleep: () => sleep,
|
|
64
|
+
stripAnsi: () => stripAnsi,
|
|
65
|
+
supportsColor: () => supportsColor,
|
|
66
|
+
termSize: () => termSize,
|
|
67
|
+
themes: () => themes,
|
|
68
|
+
truncateAnsi: () => truncateAnsi,
|
|
69
|
+
visibleLen: () => visibleLen,
|
|
70
|
+
wordWrap: () => wordWrap,
|
|
71
|
+
write: () => write,
|
|
72
|
+
writeln: () => writeln
|
|
73
|
+
});
|
|
74
|
+
module.exports = __toCommonJS(index_exports);
|
|
75
|
+
|
|
76
|
+
// src/utils/ansi.ts
|
|
77
|
+
var ESC = "\x1B";
|
|
78
|
+
var CSI = `${ESC}[`;
|
|
79
|
+
var cursor = {
|
|
80
|
+
up: (n = 1) => `${CSI}${n}A`,
|
|
81
|
+
down: (n = 1) => `${CSI}${n}B`,
|
|
82
|
+
right: (n = 1) => `${CSI}${n}C`,
|
|
83
|
+
left: (n = 1) => `${CSI}${n}D`,
|
|
84
|
+
to: (x, y) => `${CSI}${y};${x}H`,
|
|
85
|
+
save: () => `${CSI}s`,
|
|
86
|
+
restore: () => `${CSI}u`,
|
|
87
|
+
hide: () => `${CSI}?25l`,
|
|
88
|
+
show: () => `${CSI}?25h`
|
|
89
|
+
};
|
|
90
|
+
var screen = {
|
|
91
|
+
clear: () => `${CSI}2J${CSI}H`,
|
|
92
|
+
clearLine: () => `${CSI}2K`,
|
|
93
|
+
clearRight: () => `${CSI}0K`,
|
|
94
|
+
clearDown: () => `${CSI}0J`,
|
|
95
|
+
scrollUp: (n = 1) => `${CSI}${n}S`,
|
|
96
|
+
scrollDown: (n = 1) => `${CSI}${n}T`
|
|
97
|
+
};
|
|
98
|
+
var FG = {
|
|
99
|
+
black: 30,
|
|
100
|
+
red: 31,
|
|
101
|
+
green: 32,
|
|
102
|
+
yellow: 33,
|
|
103
|
+
blue: 34,
|
|
104
|
+
magenta: 35,
|
|
105
|
+
cyan: 36,
|
|
106
|
+
white: 37,
|
|
107
|
+
brightBlack: 90,
|
|
108
|
+
brightRed: 91,
|
|
109
|
+
brightGreen: 92,
|
|
110
|
+
brightYellow: 93,
|
|
111
|
+
brightBlue: 94,
|
|
112
|
+
brightMagenta: 95,
|
|
113
|
+
brightCyan: 96,
|
|
114
|
+
brightWhite: 97
|
|
115
|
+
};
|
|
116
|
+
var BG = {
|
|
117
|
+
black: 40,
|
|
118
|
+
red: 41,
|
|
119
|
+
green: 42,
|
|
120
|
+
yellow: 43,
|
|
121
|
+
blue: 44,
|
|
122
|
+
magenta: 45,
|
|
123
|
+
cyan: 46,
|
|
124
|
+
white: 47,
|
|
125
|
+
brightBlack: 100,
|
|
126
|
+
brightRed: 101,
|
|
127
|
+
brightGreen: 102,
|
|
128
|
+
brightYellow: 103,
|
|
129
|
+
brightBlue: 104,
|
|
130
|
+
brightMagenta: 105,
|
|
131
|
+
brightCyan: 106,
|
|
132
|
+
brightWhite: 107
|
|
133
|
+
};
|
|
134
|
+
var STYLE = {
|
|
135
|
+
reset: 0,
|
|
136
|
+
bold: 1,
|
|
137
|
+
dim: 2,
|
|
138
|
+
italic: 3,
|
|
139
|
+
underline: 4,
|
|
140
|
+
blink: 5,
|
|
141
|
+
inverse: 7,
|
|
142
|
+
hidden: 8,
|
|
143
|
+
strikethrough: 9
|
|
144
|
+
};
|
|
145
|
+
var sgr = (...codes) => `${CSI}${codes.join(";")}m`;
|
|
146
|
+
var reset = () => sgr(STYLE.reset);
|
|
147
|
+
var fgRgb = (r, g, b) => `${CSI}38;2;${r};${g};${b}m`;
|
|
148
|
+
var bgRgb = (r, g, b) => `${CSI}48;2;${r};${g};${b}m`;
|
|
149
|
+
var fg256 = (n) => `${CSI}38;5;${n}m`;
|
|
150
|
+
var bg256 = (n) => `${CSI}48;5;${n}m`;
|
|
151
|
+
var supportsColor = () => {
|
|
152
|
+
if (process.env["NO_COLOR"]) return "none";
|
|
153
|
+
if (process.env["COLORTERM"] === "truecolor" || process.env["COLORTERM"] === "24bit") return "truecolor";
|
|
154
|
+
if (process.env["TERM_PROGRAM"] === "iTerm.app") return "truecolor";
|
|
155
|
+
if (process.env["TERM"]?.includes("256color")) return "256";
|
|
156
|
+
return "basic";
|
|
157
|
+
};
|
|
158
|
+
var sleep = (ms) => new Promise((r) => setTimeout(() => r(), ms));
|
|
159
|
+
var write = (str) => process.stdout.write(str);
|
|
160
|
+
var writeln = (str = "") => process.stdout.write(str + "\n");
|
|
161
|
+
|
|
162
|
+
// src/utils/helpers.ts
|
|
163
|
+
var clamp = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
164
|
+
var lerp = (a, b, t) => a + (b - a) * t;
|
|
165
|
+
var clampByte = (v) => clamp(Math.round(v), 0, 255);
|
|
166
|
+
var HEX_RE = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
167
|
+
var isHexColor = (hex) => typeof hex === "string" && HEX_RE.test(hex.trim());
|
|
168
|
+
var hexToRgb = (hex) => {
|
|
169
|
+
if (!isHexColor(hex)) {
|
|
170
|
+
throw new Error(`Invalid hex color: "${hex}"`);
|
|
171
|
+
}
|
|
172
|
+
const clean = hex.trim().replace("#", "");
|
|
173
|
+
const full = clean.length === 3 ? clean.split("").map((c) => c + c).join("") : clean;
|
|
174
|
+
const int = parseInt(full, 16);
|
|
175
|
+
return { r: int >> 16 & 255, g: int >> 8 & 255, b: int & 255 };
|
|
176
|
+
};
|
|
177
|
+
var rgbToHex = (r, g, b) => "#" + [clampByte(r), clampByte(g), clampByte(b)].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
178
|
+
var lerpColor = (a, b, t) => {
|
|
179
|
+
const ct = clamp(t, 0, 1);
|
|
180
|
+
return {
|
|
181
|
+
r: Math.round(lerp(a.r, b.r, ct)),
|
|
182
|
+
g: Math.round(lerp(a.g, b.g, ct)),
|
|
183
|
+
b: Math.round(lerp(a.b, b.b, ct))
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
var rgbTo256 = (r, g, b) => {
|
|
187
|
+
const cr = clampByte(r), cg = clampByte(g), cb = clampByte(b);
|
|
188
|
+
if (cr === cg && cg === cb) {
|
|
189
|
+
if (cr < 8) return 16;
|
|
190
|
+
if (cr > 248) return 231;
|
|
191
|
+
return Math.round((cr - 8) / 247 * 24) + 232;
|
|
192
|
+
}
|
|
193
|
+
return 16 + 36 * Math.round(cr / 255 * 5) + 6 * Math.round(cg / 255 * 5) + Math.round(cb / 255 * 5);
|
|
194
|
+
};
|
|
195
|
+
var ANSI_RE = new RegExp(
|
|
196
|
+
[
|
|
197
|
+
"\\x1b\\[[0-9;?]*[a-zA-Z]",
|
|
198
|
+
// CSI
|
|
199
|
+
"\\x1b\\][^\\x07\\x1b]*(?:\\x07|\\x1b\\\\)",
|
|
200
|
+
// OSC
|
|
201
|
+
"\\x1b[NOMP78=>c]"
|
|
202
|
+
// single-char escapes
|
|
203
|
+
].join("|"),
|
|
204
|
+
"g"
|
|
205
|
+
);
|
|
206
|
+
var stripAnsi = (str) => str.replace(ANSI_RE, "");
|
|
207
|
+
var visibleLen = (str) => stripAnsi(str).length;
|
|
208
|
+
var truncateAnsi = (str, width, ellipsis = "\u2026") => {
|
|
209
|
+
if (visibleLen(str) <= width) return str;
|
|
210
|
+
const ellipsisLen = visibleLen(ellipsis);
|
|
211
|
+
const target = Math.max(0, width - ellipsisLen);
|
|
212
|
+
let visible = 0;
|
|
213
|
+
let result = "";
|
|
214
|
+
let i = 0;
|
|
215
|
+
while (i < str.length && visible < target) {
|
|
216
|
+
if (str[i] === "\x1B") {
|
|
217
|
+
const match = str.slice(i).match(ANSI_RE);
|
|
218
|
+
if (match && match[0] && str.indexOf(match[0], i) === i) {
|
|
219
|
+
result += match[0];
|
|
220
|
+
i += match[0].length;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
result += str[i];
|
|
225
|
+
visible++;
|
|
226
|
+
i++;
|
|
227
|
+
}
|
|
228
|
+
return result + ellipsis + "\x1B[0m";
|
|
229
|
+
};
|
|
230
|
+
var padEnd = (str, width, ch = " ") => {
|
|
231
|
+
const pad = width - visibleLen(str);
|
|
232
|
+
return pad > 0 ? str + ch.repeat(pad) : str;
|
|
233
|
+
};
|
|
234
|
+
var padStart = (str, width, ch = " ") => {
|
|
235
|
+
const pad = width - visibleLen(str);
|
|
236
|
+
return pad > 0 ? ch.repeat(pad) + str : str;
|
|
237
|
+
};
|
|
238
|
+
var center = (str, width, ch = " ") => {
|
|
239
|
+
const pad = width - visibleLen(str);
|
|
240
|
+
if (pad <= 0) return str;
|
|
241
|
+
const l = Math.floor(pad / 2);
|
|
242
|
+
const r = pad - l;
|
|
243
|
+
return ch.repeat(l) + str + ch.repeat(r);
|
|
244
|
+
};
|
|
245
|
+
var repeatVisible = (str, width) => {
|
|
246
|
+
if (!str || width <= 0) return "";
|
|
247
|
+
const unit = visibleLen(str);
|
|
248
|
+
if (unit === 0) return "";
|
|
249
|
+
const times = Math.ceil(width / unit);
|
|
250
|
+
return truncateAnsi(str.repeat(times), width, "");
|
|
251
|
+
};
|
|
252
|
+
var termSize = () => ({
|
|
253
|
+
cols: process.stdout.columns || 80,
|
|
254
|
+
rows: process.stdout.rows || 24
|
|
255
|
+
});
|
|
256
|
+
var wordWrap = (text, width) => {
|
|
257
|
+
if (width <= 0) return [text];
|
|
258
|
+
const words = text.split(" ");
|
|
259
|
+
const lines = [];
|
|
260
|
+
let current = "";
|
|
261
|
+
const breakLong = (word) => {
|
|
262
|
+
const chunks = [];
|
|
263
|
+
for (let i = 0; i < word.length; i += width) {
|
|
264
|
+
chunks.push(word.slice(i, i + width));
|
|
265
|
+
}
|
|
266
|
+
return chunks;
|
|
267
|
+
};
|
|
268
|
+
for (const raw of words) {
|
|
269
|
+
const tokens = raw.length > width ? breakLong(raw) : [raw];
|
|
270
|
+
for (const word of tokens) {
|
|
271
|
+
if (current.length + word.length + (current ? 1 : 0) <= width) {
|
|
272
|
+
current += (current ? " " : "") + word;
|
|
273
|
+
} else {
|
|
274
|
+
if (current) lines.push(current);
|
|
275
|
+
current = word;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (current) lines.push(current);
|
|
280
|
+
return lines;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/colors/index.ts
|
|
284
|
+
var _noColor = null;
|
|
285
|
+
var setNoColor = (v) => {
|
|
286
|
+
_noColor = v;
|
|
287
|
+
};
|
|
288
|
+
var resetNoColor = () => {
|
|
289
|
+
_noColor = null;
|
|
290
|
+
};
|
|
291
|
+
var isNoColor = () => {
|
|
292
|
+
if (_noColor !== null) return _noColor;
|
|
293
|
+
return Boolean(process.env["NO_COLOR"]) || !process.stdout.isTTY;
|
|
294
|
+
};
|
|
295
|
+
var clampRgb = (n) => Math.max(0, Math.min(255, Math.round(n)));
|
|
296
|
+
var clamp256 = (n) => Math.max(0, Math.min(255, Math.round(n)));
|
|
297
|
+
var HEX_RE2 = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
298
|
+
var safeHex = (h) => {
|
|
299
|
+
if (!HEX_RE2.test(h.trim())) return null;
|
|
300
|
+
return hexToRgb(h);
|
|
301
|
+
};
|
|
302
|
+
var wrap = (open, text) => isNoColor() ? text : `${open}${text}${reset()}`;
|
|
303
|
+
var makeFg = (code) => (text) => wrap(sgr(code), text);
|
|
304
|
+
var makeBg = (code) => (text) => wrap(sgr(code), text);
|
|
305
|
+
var compose = (...fns) => (text) => {
|
|
306
|
+
if (isNoColor()) return text;
|
|
307
|
+
const opens = fns.map((fn) => {
|
|
308
|
+
const result = fn("");
|
|
309
|
+
return result.endsWith(reset()) ? result.slice(0, -reset().length) : result;
|
|
310
|
+
});
|
|
311
|
+
return opens.join("") + text + reset();
|
|
312
|
+
};
|
|
313
|
+
var gradient = (text, stops) => {
|
|
314
|
+
if (!text || isNoColor()) return text;
|
|
315
|
+
const colors = stops.map(safeHex).filter((c) => c !== null);
|
|
316
|
+
if (colors.length < 2) return text;
|
|
317
|
+
const chars = [...text];
|
|
318
|
+
const visible = chars.filter((c) => c !== " ").length;
|
|
319
|
+
if (visible === 0) return text;
|
|
320
|
+
let colorIdx = 0;
|
|
321
|
+
return chars.map((ch) => {
|
|
322
|
+
if (ch === " ") return ch;
|
|
323
|
+
const t = visible === 1 ? 0 : colorIdx / (visible - 1);
|
|
324
|
+
const scaled = t * (colors.length - 1);
|
|
325
|
+
const lo = Math.floor(scaled);
|
|
326
|
+
const hi = Math.min(lo + 1, colors.length - 1);
|
|
327
|
+
const { r, g, b } = lerpColor(colors[lo], colors[hi], scaled - lo);
|
|
328
|
+
colorIdx++;
|
|
329
|
+
return fgRgb(r, g, b) + ch + reset();
|
|
330
|
+
}).join("");
|
|
331
|
+
};
|
|
332
|
+
var RAINBOW = ["#ff0000", "#ff7f00", "#ffff00", "#00ff00", "#0000ff", "#8b00ff"];
|
|
333
|
+
var rainbow = (text) => gradient(text, RAINBOW);
|
|
334
|
+
var presets = {
|
|
335
|
+
sunset: (t) => gradient(t, ["#ff6b6b", "#feca57", "#48dbfb"]),
|
|
336
|
+
ocean: (t) => gradient(t, ["#0575e6", "#021b79"]),
|
|
337
|
+
fire: (t) => gradient(t, ["#f7971e", "#ffd200", "#ff0000"]),
|
|
338
|
+
neon: (t) => gradient(t, ["#f953c6", "#b91d73"]),
|
|
339
|
+
forest: (t) => gradient(t, ["#134e5e", "#71b280"]),
|
|
340
|
+
aurora: (t) => gradient(t, ["#00c6ff", "#0072ff", "#7e57c2"]),
|
|
341
|
+
candy: (t) => gradient(t, ["#fd79a8", "#a29bfe", "#74b9ff"]),
|
|
342
|
+
gold: (t) => gradient(t, ["#f7971e", "#ffd200"])
|
|
343
|
+
};
|
|
344
|
+
var color = {
|
|
345
|
+
// ── Named foreground colors ──
|
|
346
|
+
black: makeFg(FG.black),
|
|
347
|
+
red: makeFg(FG.red),
|
|
348
|
+
green: makeFg(FG.green),
|
|
349
|
+
yellow: makeFg(FG.yellow),
|
|
350
|
+
blue: makeFg(FG.blue),
|
|
351
|
+
magenta: makeFg(FG.magenta),
|
|
352
|
+
cyan: makeFg(FG.cyan),
|
|
353
|
+
white: makeFg(FG.white),
|
|
354
|
+
// ── Bright foreground ──
|
|
355
|
+
brightBlack: makeFg(FG.brightBlack),
|
|
356
|
+
brightRed: makeFg(FG.brightRed),
|
|
357
|
+
brightGreen: makeFg(FG.brightGreen),
|
|
358
|
+
brightYellow: makeFg(FG.brightYellow),
|
|
359
|
+
brightBlue: makeFg(FG.brightBlue),
|
|
360
|
+
brightMagenta: makeFg(FG.brightMagenta),
|
|
361
|
+
brightCyan: makeFg(FG.brightCyan),
|
|
362
|
+
brightWhite: makeFg(FG.brightWhite),
|
|
363
|
+
// ── Common aliases ──
|
|
364
|
+
gray: makeFg(FG.brightBlack),
|
|
365
|
+
grey: makeFg(FG.brightBlack),
|
|
366
|
+
orange: (t) => wrap(fgRgb(255, 165, 0), t),
|
|
367
|
+
purple: makeFg(FG.magenta),
|
|
368
|
+
// ── Named background colors ──
|
|
369
|
+
bgBlack: makeBg(BG.black),
|
|
370
|
+
bgRed: makeBg(BG.red),
|
|
371
|
+
bgGreen: makeBg(BG.green),
|
|
372
|
+
bgYellow: makeBg(BG.yellow),
|
|
373
|
+
bgBlue: makeBg(BG.blue),
|
|
374
|
+
bgMagenta: makeBg(BG.magenta),
|
|
375
|
+
bgCyan: makeBg(BG.cyan),
|
|
376
|
+
bgWhite: makeBg(BG.white),
|
|
377
|
+
// ── Text styles ──
|
|
378
|
+
bold: (t) => wrap(sgr(STYLE.bold), t),
|
|
379
|
+
dim: (t) => wrap(sgr(STYLE.dim), t),
|
|
380
|
+
italic: (t) => wrap(sgr(STYLE.italic), t),
|
|
381
|
+
underline: (t) => wrap(sgr(STYLE.underline), t),
|
|
382
|
+
blink: (t) => wrap(sgr(STYLE.blink), t),
|
|
383
|
+
// terminal support varies
|
|
384
|
+
inverse: (t) => wrap(sgr(STYLE.inverse), t),
|
|
385
|
+
strikethrough: (t) => wrap(sgr(STYLE.strikethrough), t),
|
|
386
|
+
hidden: (t) => wrap(sgr(STYLE.hidden), t),
|
|
387
|
+
// ── True-color (24-bit) — values clamped to 0–255 ──
|
|
388
|
+
rgb: (r, g, b) => (t) => wrap(fgRgb(clampRgb(r), clampRgb(g), clampRgb(b)), t),
|
|
389
|
+
bgRgb: (r, g, b) => (t) => wrap(bgRgb(clampRgb(r), clampRgb(g), clampRgb(b)), t),
|
|
390
|
+
// ── Hex — fail-soft: invalid hex → plain text ──
|
|
391
|
+
hex: (h) => (t) => {
|
|
392
|
+
const p = safeHex(h);
|
|
393
|
+
return p ? wrap(fgRgb(p.r, p.g, p.b), t) : t;
|
|
394
|
+
},
|
|
395
|
+
bgHex: (h) => (t) => {
|
|
396
|
+
const p = safeHex(h);
|
|
397
|
+
return p ? wrap(bgRgb(p.r, p.g, p.b), t) : t;
|
|
398
|
+
},
|
|
399
|
+
// ── 256-color — value clamped to 0–255 ──
|
|
400
|
+
color256: (n) => (t) => wrap(fg256(clamp256(n)), t),
|
|
401
|
+
bgColor256: (n) => (t) => wrap(bg256(clamp256(n)), t),
|
|
402
|
+
// ── Gradients ──
|
|
403
|
+
gradient,
|
|
404
|
+
rainbow,
|
|
405
|
+
...presets
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
// src/animations/index.ts
|
|
409
|
+
var isTTY = () => Boolean(process.stdout.isTTY);
|
|
410
|
+
var resolveRgb = (c) => typeof c === "string" ? hexToRgb(c) : c;
|
|
411
|
+
var safeSteps = (n) => Math.max(1, n);
|
|
412
|
+
var typewriter = async (text, opts = {}) => {
|
|
413
|
+
const { speed = 50, newline = true, colorFn = null, signal, reducedMotion = false } = opts;
|
|
414
|
+
if (!isTTY() || reducedMotion) {
|
|
415
|
+
write(colorFn ? [...text].map(colorFn).join("") : text);
|
|
416
|
+
if (newline) writeln();
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
write(cursor.hide());
|
|
420
|
+
try {
|
|
421
|
+
for (const ch of text) {
|
|
422
|
+
if (signal?.aborted) break;
|
|
423
|
+
write(colorFn ? colorFn(ch) : ch);
|
|
424
|
+
if (ch !== " ") await sleep(speed);
|
|
425
|
+
}
|
|
426
|
+
} finally {
|
|
427
|
+
write(cursor.show());
|
|
428
|
+
if (newline) writeln();
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var fadeIn = async (text, opts = {}) => {
|
|
432
|
+
const {
|
|
433
|
+
duration = 800,
|
|
434
|
+
steps = 16,
|
|
435
|
+
newline = true,
|
|
436
|
+
color: baseColor = { r: 255, g: 255, b: 255 },
|
|
437
|
+
signal,
|
|
438
|
+
reducedMotion = false
|
|
439
|
+
} = opts;
|
|
440
|
+
if (!isTTY() || reducedMotion) {
|
|
441
|
+
write(text);
|
|
442
|
+
if (newline) writeln();
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const base = resolveRgb(baseColor);
|
|
446
|
+
const n = safeSteps(steps);
|
|
447
|
+
write(cursor.hide());
|
|
448
|
+
try {
|
|
449
|
+
for (let i = 0; i <= n; i++) {
|
|
450
|
+
if (signal?.aborted) break;
|
|
451
|
+
const t = i / n;
|
|
452
|
+
write(
|
|
453
|
+
cursor.save() + fgRgb(Math.round(base.r * t), Math.round(base.g * t), Math.round(base.b * t)) + text + reset() + cursor.restore()
|
|
454
|
+
);
|
|
455
|
+
await sleep(duration / n);
|
|
456
|
+
}
|
|
457
|
+
} finally {
|
|
458
|
+
write(cursor.show());
|
|
459
|
+
if (newline) writeln();
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
var fadeOut = async (text, opts = {}) => {
|
|
463
|
+
const {
|
|
464
|
+
duration = 800,
|
|
465
|
+
steps = 16,
|
|
466
|
+
newline = true,
|
|
467
|
+
color: baseColor = { r: 255, g: 255, b: 255 },
|
|
468
|
+
signal,
|
|
469
|
+
reducedMotion = false
|
|
470
|
+
} = opts;
|
|
471
|
+
if (!isTTY() || reducedMotion) {
|
|
472
|
+
if (newline) writeln();
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const base = resolveRgb(baseColor);
|
|
476
|
+
const n = safeSteps(steps);
|
|
477
|
+
write(cursor.hide());
|
|
478
|
+
try {
|
|
479
|
+
for (let i = n; i >= 0; i--) {
|
|
480
|
+
if (signal?.aborted) break;
|
|
481
|
+
const t = i / n;
|
|
482
|
+
write(
|
|
483
|
+
cursor.save() + fgRgb(Math.round(base.r * t), Math.round(base.g * t), Math.round(base.b * t)) + text + reset() + cursor.restore()
|
|
484
|
+
);
|
|
485
|
+
await sleep(duration / n);
|
|
486
|
+
}
|
|
487
|
+
} finally {
|
|
488
|
+
write(cursor.show());
|
|
489
|
+
if (newline) writeln();
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
var slide = async (text, opts = {}) => {
|
|
493
|
+
const { direction = "left", duration = 400, newline = true, signal, reducedMotion = false } = opts;
|
|
494
|
+
if (!isTTY() || reducedMotion) {
|
|
495
|
+
write(text);
|
|
496
|
+
if (newline) writeln();
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const len = text.length;
|
|
500
|
+
const steps = Math.min(Math.max(1, len), 40);
|
|
501
|
+
const delay = duration / steps;
|
|
502
|
+
write(cursor.hide());
|
|
503
|
+
try {
|
|
504
|
+
for (let i = 1; i <= steps; i++) {
|
|
505
|
+
if (signal?.aborted) break;
|
|
506
|
+
const shown = Math.floor(i / steps * len);
|
|
507
|
+
const line = direction === "right" ? " ".repeat(len - shown) + text.slice(0, shown) : text.slice(0, shown);
|
|
508
|
+
write(cursor.save() + screen.clearRight() + line + cursor.restore());
|
|
509
|
+
await sleep(delay);
|
|
510
|
+
}
|
|
511
|
+
write(cursor.save() + screen.clearRight() + text + cursor.restore());
|
|
512
|
+
} finally {
|
|
513
|
+
write(cursor.show());
|
|
514
|
+
if (newline) writeln();
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
var pulse = async (text, opts = {}) => {
|
|
518
|
+
const {
|
|
519
|
+
times = 3,
|
|
520
|
+
interval = 300,
|
|
521
|
+
color1 = { r: 255, g: 255, b: 255 },
|
|
522
|
+
color2 = { r: 100, g: 100, b: 100 },
|
|
523
|
+
newline = true,
|
|
524
|
+
signal,
|
|
525
|
+
reducedMotion = false
|
|
526
|
+
} = opts;
|
|
527
|
+
if (!isTTY() || reducedMotion) {
|
|
528
|
+
write(text);
|
|
529
|
+
if (newline) writeln();
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const c1 = resolveRgb(color1);
|
|
533
|
+
const c2 = resolveRgb(color2);
|
|
534
|
+
write(cursor.hide());
|
|
535
|
+
try {
|
|
536
|
+
for (let t = 0; t < times; t++) {
|
|
537
|
+
if (signal?.aborted) break;
|
|
538
|
+
write(cursor.save() + fgRgb(c1.r, c1.g, c1.b) + text + reset() + cursor.restore());
|
|
539
|
+
await sleep(interval);
|
|
540
|
+
if (signal?.aborted) break;
|
|
541
|
+
write(cursor.save() + fgRgb(c2.r, c2.g, c2.b) + text + reset() + cursor.restore());
|
|
542
|
+
await sleep(interval);
|
|
543
|
+
}
|
|
544
|
+
write(cursor.save() + fgRgb(c1.r, c1.g, c1.b) + text + reset() + cursor.restore());
|
|
545
|
+
} finally {
|
|
546
|
+
write(cursor.show());
|
|
547
|
+
if (newline) writeln();
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
var wave = async (text, opts = {}) => {
|
|
551
|
+
const {
|
|
552
|
+
duration = 2e3,
|
|
553
|
+
steps = 30,
|
|
554
|
+
colors = ["#ff0000", "#ff7f00", "#ffff00", "#00ff00", "#0000ff", "#8b00ff"],
|
|
555
|
+
newline = true,
|
|
556
|
+
signal,
|
|
557
|
+
reducedMotion = false
|
|
558
|
+
} = opts;
|
|
559
|
+
if (!isTTY() || reducedMotion) {
|
|
560
|
+
write(text);
|
|
561
|
+
if (newline) writeln();
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
if (!text.length) {
|
|
565
|
+
if (newline) writeln();
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const palette = colors.map(hexToRgb);
|
|
569
|
+
const n = safeSteps(steps);
|
|
570
|
+
const delay = duration / n;
|
|
571
|
+
const chars = [...text];
|
|
572
|
+
const len = chars.length;
|
|
573
|
+
write(cursor.hide());
|
|
574
|
+
try {
|
|
575
|
+
for (let frame = 0; frame < n; frame++) {
|
|
576
|
+
if (signal?.aborted) break;
|
|
577
|
+
const offset = frame / n;
|
|
578
|
+
const colored = chars.map((ch, i) => {
|
|
579
|
+
if (ch === " ") return ch;
|
|
580
|
+
const t = (i / len + offset) % 1;
|
|
581
|
+
const scaled = t * (palette.length - 1);
|
|
582
|
+
const lo = Math.floor(scaled);
|
|
583
|
+
const hi = Math.min(lo + 1, palette.length - 1);
|
|
584
|
+
const { r, g, b } = lerpColor(palette[lo], palette[hi], scaled - lo);
|
|
585
|
+
return fgRgb(r, g, b) + ch + reset();
|
|
586
|
+
}).join("");
|
|
587
|
+
write(cursor.save() + screen.clearRight() + colored + cursor.restore());
|
|
588
|
+
await sleep(delay);
|
|
589
|
+
}
|
|
590
|
+
} finally {
|
|
591
|
+
write(cursor.show());
|
|
592
|
+
if (newline) writeln();
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
var glitch = async (text, opts = {}) => {
|
|
596
|
+
const { duration = 800, intensity = 3, newline = true, signal, reducedMotion = false } = opts;
|
|
597
|
+
if (!isTTY() || reducedMotion) {
|
|
598
|
+
write(text);
|
|
599
|
+
if (newline) writeln();
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const glitchChars = "!@#$%^&*[]{}|<>/\\~`\xB1\xA7";
|
|
603
|
+
const end = Date.now() + duration;
|
|
604
|
+
write(cursor.hide());
|
|
605
|
+
try {
|
|
606
|
+
while (Date.now() < end) {
|
|
607
|
+
if (signal?.aborted) break;
|
|
608
|
+
const out = [...text].map((ch) => {
|
|
609
|
+
if (ch === " ") return ch;
|
|
610
|
+
return Math.random() < intensity / 10 ? glitchChars[Math.floor(Math.random() * glitchChars.length)] : ch;
|
|
611
|
+
}).join("");
|
|
612
|
+
write(cursor.save() + screen.clearRight() + out + cursor.restore());
|
|
613
|
+
await sleep(40);
|
|
614
|
+
}
|
|
615
|
+
write(cursor.save() + screen.clearRight() + text + cursor.restore());
|
|
616
|
+
} finally {
|
|
617
|
+
write(cursor.show());
|
|
618
|
+
if (newline) writeln();
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
var reveal = async (text, opts = {}) => {
|
|
622
|
+
const {
|
|
623
|
+
duration = 1e3,
|
|
624
|
+
charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
625
|
+
newline = true,
|
|
626
|
+
signal,
|
|
627
|
+
reducedMotion = false
|
|
628
|
+
} = opts;
|
|
629
|
+
if (!isTTY() || reducedMotion) {
|
|
630
|
+
write(text);
|
|
631
|
+
if (newline) writeln();
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
const len = text.length;
|
|
635
|
+
const n = safeSteps(20);
|
|
636
|
+
const delay = duration / n;
|
|
637
|
+
const solved = new Array(len).fill(false);
|
|
638
|
+
write(cursor.hide());
|
|
639
|
+
try {
|
|
640
|
+
for (let step = 0; step < n; step++) {
|
|
641
|
+
if (signal?.aborted) break;
|
|
642
|
+
const toSolve = Math.floor(step / n * len);
|
|
643
|
+
for (let i = 0; i < toSolve; i++) solved[i] = true;
|
|
644
|
+
const line = [...text].map((ch, i) => {
|
|
645
|
+
if (ch === " ") return " ";
|
|
646
|
+
if (solved[i]) return ch;
|
|
647
|
+
return charset[Math.floor(Math.random() * charset.length)];
|
|
648
|
+
}).join("");
|
|
649
|
+
write(cursor.save() + screen.clearRight() + line + cursor.restore());
|
|
650
|
+
await sleep(delay);
|
|
651
|
+
}
|
|
652
|
+
write(cursor.save() + screen.clearRight() + text + cursor.restore());
|
|
653
|
+
} finally {
|
|
654
|
+
write(cursor.show());
|
|
655
|
+
if (newline) writeln();
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
var animate = {
|
|
659
|
+
typewriter,
|
|
660
|
+
fadeIn,
|
|
661
|
+
fadeOut,
|
|
662
|
+
slide,
|
|
663
|
+
pulse,
|
|
664
|
+
wave,
|
|
665
|
+
glitch,
|
|
666
|
+
reveal
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
// src/ascii/index.ts
|
|
670
|
+
var BLOCK = {
|
|
671
|
+
" ": [" ", " ", " ", " ", " "],
|
|
672
|
+
A: [" \u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588\u2588\u2588\u2588\u2588", "\u2588 \u2588", "\u2588 \u2588"],
|
|
673
|
+
B: ["\u2588\u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588\u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588\u2588\u2588\u2588 "],
|
|
674
|
+
C: [" \u2588\u2588\u2588 ", "\u2588 ", "\u2588 ", "\u2588 ", " \u2588\u2588\u2588 "],
|
|
675
|
+
D: ["\u2588\u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588 \u2588", "\u2588 \u2588", "\u2588\u2588\u2588\u2588 "],
|
|
676
|
+
E: ["\u2588\u2588\u2588\u2588\u2588", "\u2588 ", "\u2588\u2588\u2588\u2588 ", "\u2588 ", "\u2588\u2588\u2588\u2588\u2588"],
|
|
677
|
+
F: ["\u2588\u2588\u2588\u2588\u2588", "\u2588 ", "\u2588\u2588\u2588\u2588 ", "\u2588 ", "\u2588 "],
|
|
678
|
+
G: [" \u2588\u2588\u2588\u2588", "\u2588 ", "\u2588 \u2588\u2588", "\u2588 \u2588", " \u2588\u2588\u2588\u2588"],
|
|
679
|
+
H: ["\u2588 \u2588", "\u2588 \u2588", "\u2588\u2588\u2588\u2588\u2588", "\u2588 \u2588", "\u2588 \u2588"],
|
|
680
|
+
I: ["\u2588\u2588\u2588\u2588\u2588", " \u2588 ", " \u2588 ", " \u2588 ", "\u2588\u2588\u2588\u2588\u2588"],
|
|
681
|
+
J: ["\u2588\u2588\u2588\u2588\u2588", " \u2588 ", " \u2588 ", "\u2588 \u2588 ", " \u2588\u2588 "],
|
|
682
|
+
K: ["\u2588 \u2588", "\u2588 \u2588 ", "\u2588\u2588\u2588 ", "\u2588 \u2588 ", "\u2588 \u2588"],
|
|
683
|
+
L: ["\u2588 ", "\u2588 ", "\u2588 ", "\u2588 ", "\u2588\u2588\u2588\u2588\u2588"],
|
|
684
|
+
M: ["\u2588 \u2588", "\u2588\u2588 \u2588\u2588", "\u2588 \u2588 \u2588", "\u2588 \u2588", "\u2588 \u2588"],
|
|
685
|
+
N: ["\u2588 \u2588", "\u2588\u2588 \u2588", "\u2588 \u2588 \u2588", "\u2588 \u2588\u2588", "\u2588 \u2588"],
|
|
686
|
+
O: [" \u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588 \u2588", "\u2588 \u2588", " \u2588\u2588\u2588 "],
|
|
687
|
+
P: ["\u2588\u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588\u2588\u2588\u2588 ", "\u2588 ", "\u2588 "],
|
|
688
|
+
Q: [" \u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588 \u2588 \u2588", "\u2588 \u2588\u2588", " \u2588\u2588\u2588\u2588"],
|
|
689
|
+
R: ["\u2588\u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588\u2588\u2588\u2588 ", "\u2588 \u2588 ", "\u2588 \u2588"],
|
|
690
|
+
S: [" \u2588\u2588\u2588\u2588", "\u2588 ", " \u2588\u2588\u2588 ", " \u2588", "\u2588\u2588\u2588\u2588 "],
|
|
691
|
+
T: ["\u2588\u2588\u2588\u2588\u2588", " \u2588 ", " \u2588 ", " \u2588 ", " \u2588 "],
|
|
692
|
+
U: ["\u2588 \u2588", "\u2588 \u2588", "\u2588 \u2588", "\u2588 \u2588", " \u2588\u2588\u2588 "],
|
|
693
|
+
V: ["\u2588 \u2588", "\u2588 \u2588", "\u2588 \u2588", " \u2588 \u2588 ", " \u2588 "],
|
|
694
|
+
W: ["\u2588 \u2588", "\u2588 \u2588", "\u2588 \u2588 \u2588", "\u2588\u2588 \u2588\u2588", "\u2588 \u2588"],
|
|
695
|
+
X: ["\u2588 \u2588", " \u2588 \u2588 ", " \u2588 ", " \u2588 \u2588 ", "\u2588 \u2588"],
|
|
696
|
+
Y: ["\u2588 \u2588", " \u2588 \u2588 ", " \u2588 ", " \u2588 ", " \u2588 "],
|
|
697
|
+
Z: ["\u2588\u2588\u2588\u2588\u2588", " \u2588 ", " \u2588 ", " \u2588 ", "\u2588\u2588\u2588\u2588\u2588"],
|
|
698
|
+
"0": [" \u2588\u2588\u2588 ", "\u2588 \u2588\u2588", "\u2588 \u2588 \u2588", "\u2588\u2588 \u2588", " \u2588\u2588\u2588 "],
|
|
699
|
+
"1": [" \u2588 ", " \u2588\u2588 ", " \u2588 ", " \u2588 ", "\u2588\u2588\u2588\u2588\u2588"],
|
|
700
|
+
"2": [" \u2588\u2588\u2588 ", "\u2588 \u2588", " \u2588\u2588 ", " \u2588 ", "\u2588\u2588\u2588\u2588\u2588"],
|
|
701
|
+
"3": ["\u2588\u2588\u2588\u2588 ", " \u2588", " \u2588\u2588\u2588 ", " \u2588", "\u2588\u2588\u2588\u2588 "],
|
|
702
|
+
"4": ["\u2588 \u2588", "\u2588 \u2588", "\u2588\u2588\u2588\u2588\u2588", " \u2588", " \u2588"],
|
|
703
|
+
"5": ["\u2588\u2588\u2588\u2588\u2588", "\u2588 ", "\u2588\u2588\u2588\u2588 ", " \u2588", "\u2588\u2588\u2588\u2588 "],
|
|
704
|
+
"6": [" \u2588\u2588\u2588 ", "\u2588 ", "\u2588\u2588\u2588\u2588 ", "\u2588 \u2588", " \u2588\u2588\u2588 "],
|
|
705
|
+
"7": ["\u2588\u2588\u2588\u2588\u2588", " \u2588 ", " \u2588 ", " \u2588 ", "\u2588 "],
|
|
706
|
+
"8": [" \u2588\u2588\u2588 ", "\u2588 \u2588", " \u2588\u2588\u2588 ", "\u2588 \u2588", " \u2588\u2588\u2588 "],
|
|
707
|
+
"9": [" \u2588\u2588\u2588 ", "\u2588 \u2588", " \u2588\u2588\u2588\u2588", " \u2588", " \u2588\u2588\u2588 "],
|
|
708
|
+
"!": [" \u2588 ", " \u2588 ", " \u2588 ", " ", " \u2588 "],
|
|
709
|
+
"?": [" \u2588\u2588\u2588 ", "\u2588 \u2588", " \u2588 ", " ", " \u2588 "],
|
|
710
|
+
".": [" ", " ", " ", " ", " \u2588 "],
|
|
711
|
+
"-": [" ", " ", "\u2588\u2588\u2588\u2588 ", " ", " "],
|
|
712
|
+
"+": [" ", " \u2588 ", "\u2588\u2588\u2588\u2588\u2588", " \u2588 ", " "],
|
|
713
|
+
"#": [" \u2588 \u2588 ", "\u2588\u2588\u2588\u2588\u2588", " \u2588 \u2588 ", "\u2588\u2588\u2588\u2588\u2588", " \u2588 \u2588 "],
|
|
714
|
+
"@": [" \u2588\u2588\u2588 ", "\u2588 \u2588", "\u2588 \u2588\u2588 ", "\u2588 ", " \u2588\u2588\u2588\u2588"]
|
|
715
|
+
};
|
|
716
|
+
var SMALL = {
|
|
717
|
+
" ": [" ", " ", " "],
|
|
718
|
+
A: ["\u2584\u2580\u2584", "\u2588\u2580\u2588", "\u2580 \u2580"],
|
|
719
|
+
B: ["\u2588\u2580\u2584", "\u2588\u2580\u2584", "\u2580\u2580 "],
|
|
720
|
+
C: ["\u2584\u2580\u2580", "\u2588 ", "\u2580\u2580\u2584"],
|
|
721
|
+
D: ["\u2588\u2580\u2584", "\u2588 \u2588", "\u2580\u2580 "],
|
|
722
|
+
E: ["\u2588\u2580\u2580", "\u2588\u2580 ", "\u2580\u2580\u2580"],
|
|
723
|
+
F: ["\u2588\u2580\u2580", "\u2588\u2580 ", "\u2580 "],
|
|
724
|
+
G: ["\u2584\u2580\u2580", "\u2588 \u2584", "\u2580\u2580\u2598"],
|
|
725
|
+
H: ["\u2588 \u2588", "\u2588\u2588\u2588", "\u2580 \u2580"],
|
|
726
|
+
I: ["\u2580\u2588\u2580", " \u2588 ", "\u2580\u2588\u2580"],
|
|
727
|
+
J: [" \u2584\u2588", " \u2588", "\u2580\u2580 "],
|
|
728
|
+
K: ["\u2588\u2584\u2580", "\u2588\u2580\u2584", "\u2580 \u2580"],
|
|
729
|
+
L: ["\u2588 ", "\u2588 ", "\u2580\u2580\u2580"],
|
|
730
|
+
M: ["\u2588\u2584\u2588", "\u2588 \u2588", "\u2580 \u2580"],
|
|
731
|
+
N: ["\u2588\u2584\u2588", "\u2588\u2580\u2588", "\u2580 \u2580"],
|
|
732
|
+
O: ["\u2584\u2580\u2584", "\u2588 \u2588", "\u2580\u2584\u2580"],
|
|
733
|
+
P: ["\u2588\u2580\u2584", "\u2588\u2588 ", "\u2580 "],
|
|
734
|
+
Q: ["\u2584\u2580\u2584", "\u2588\u2584\u2588", "\u2580\u2584\u2580"],
|
|
735
|
+
R: ["\u2588\u2580\u2584", "\u2588\u2588\u2584", "\u2580 \u2580"],
|
|
736
|
+
S: ["\u2584\u2580\u2580", "\u2580\u2580\u2584", "\u2584\u2584\u2598"],
|
|
737
|
+
T: ["\u2580\u2588\u2580", " \u2588 ", " \u2580 "],
|
|
738
|
+
U: ["\u2588 \u2588", "\u2588 \u2588", "\u2580\u2584\u2580"],
|
|
739
|
+
V: ["\u2588 \u2588", "\u2588 \u2588", " \u2580 "],
|
|
740
|
+
W: ["\u2588 \u2588", "\u2588\u2584\u2588", "\u2580 \u2580"],
|
|
741
|
+
X: ["\u2580\u2584\u2580", " \u2588 ", "\u2580 \u2580"],
|
|
742
|
+
Y: ["\u2580\u2584\u2580", " \u2588 ", " \u2580 "],
|
|
743
|
+
Z: ["\u2580\u2580\u2588", " \u2588 ", "\u2588\u2580\u2580"],
|
|
744
|
+
"0": ["\u2584\u2580\u2584", "\u2588 \u2588", "\u2580\u2584\u2580"],
|
|
745
|
+
"1": [" \u2588 ", " \u2588 ", " \u2588 "],
|
|
746
|
+
"2": ["\u2584\u2580\u2584", " \u2584\u2580", "\u2580\u2580\u2580"],
|
|
747
|
+
"3": ["\u2580\u2580\u2584", " \u2580\u2584", "\u2584\u2584\u2598"],
|
|
748
|
+
"4": ["\u2588\u2584\u2588", " \u2588", " \u2580"],
|
|
749
|
+
"5": ["\u2588\u2580\u2580", "\u2580\u2580\u2584", "\u2584\u2584\u2598"],
|
|
750
|
+
"6": ["\u2584\u2580 ", "\u2588\u2580\u2584", "\u2580\u2584\u2580"],
|
|
751
|
+
"7": ["\u2580\u2580\u2588", " \u2588", " \u2580"],
|
|
752
|
+
"8": ["\u2584\u2580\u2584", "\u2584\u2580\u2584", "\u2580\u2584\u2580"],
|
|
753
|
+
"9": ["\u2584\u2580\u2584", "\u2580\u2580\u2588", " \u2584\u2598"],
|
|
754
|
+
"!": [" \u2588 ", " \u2588 ", " \u25AA "],
|
|
755
|
+
"?": ["\u2584\u2580\u2584", " \u2584\u2598", " \u25AA "],
|
|
756
|
+
".": [" ", " ", " \u25AA "],
|
|
757
|
+
"-": [" ", "\u2500\u2500\u2500", " "],
|
|
758
|
+
":": [" \u25AA ", " ", " \u25AA "]
|
|
759
|
+
};
|
|
760
|
+
var renderFont = (text, fontMap) => {
|
|
761
|
+
if (!text.length) return "";
|
|
762
|
+
const sampleChar = fontMap[" "];
|
|
763
|
+
const charWidth = sampleChar[0].length;
|
|
764
|
+
const empty = " ".repeat(charWidth);
|
|
765
|
+
const chars = text.toUpperCase().split("").map((c) => fontMap[c] ?? fontMap["?"] ?? [empty]);
|
|
766
|
+
const height = chars[0].length;
|
|
767
|
+
const lines = [];
|
|
768
|
+
for (let row = 0; row < height; row++) {
|
|
769
|
+
lines.push(chars.map((c) => c[row] ?? empty).join(" "));
|
|
770
|
+
}
|
|
771
|
+
return lines.join("\n");
|
|
772
|
+
};
|
|
773
|
+
var BOX_STYLES = {
|
|
774
|
+
single: { tl: "\u250C", tr: "\u2510", bl: "\u2514", br: "\u2518", h: "\u2500", v: "\u2502" },
|
|
775
|
+
double: { tl: "\u2554", tr: "\u2557", bl: "\u255A", br: "\u255D", h: "\u2550", v: "\u2551" },
|
|
776
|
+
rounded: { tl: "\u256D", tr: "\u256E", bl: "\u2570", br: "\u256F", h: "\u2500", v: "\u2502" },
|
|
777
|
+
heavy: { tl: "\u250F", tr: "\u2513", bl: "\u2517", br: "\u251B", h: "\u2501", v: "\u2503" },
|
|
778
|
+
dashed: { tl: "\u250C", tr: "\u2510", bl: "\u2514", br: "\u2518", h: "\u254C", v: "\u254E" },
|
|
779
|
+
ascii: { tl: "+", tr: "+", bl: "+", br: "+", h: "-", v: "|" }
|
|
780
|
+
};
|
|
781
|
+
var big = (text) => renderFont(text, BLOCK);
|
|
782
|
+
var small = (text) => renderFont(text, SMALL);
|
|
783
|
+
var figlet = (text, opts = {}) => opts.font === "small" ? small(text) : big(text);
|
|
784
|
+
var banner = (text, opts = {}) => {
|
|
785
|
+
const { font = "big", colorFn = null, align = "left" } = opts;
|
|
786
|
+
let rendered = font === "small" ? small(text) : big(text);
|
|
787
|
+
if (align === "center") {
|
|
788
|
+
const { cols } = termSize();
|
|
789
|
+
rendered = rendered.split("\n").map((l) => center(l, cols)).join("\n");
|
|
790
|
+
}
|
|
791
|
+
if (colorFn) rendered = rendered.split("\n").map(colorFn).join("\n");
|
|
792
|
+
return rendered;
|
|
793
|
+
};
|
|
794
|
+
var box = (text, opts = {}) => {
|
|
795
|
+
const { padding = 1, borderStyle = "rounded", width = null } = opts;
|
|
796
|
+
const b = BOX_STYLES[borderStyle] ?? BOX_STYLES.rounded;
|
|
797
|
+
const lines = text.split("\n");
|
|
798
|
+
const inner = width != null ? lines.map((l) => padEnd(truncateAnsi(l, width, ""), width)) : lines;
|
|
799
|
+
const w = Math.max(...inner.map((l) => visibleLen(l)), 0);
|
|
800
|
+
const pad = " ".repeat(padding);
|
|
801
|
+
const top = b.tl + b.h.repeat(w + padding * 2) + b.tr;
|
|
802
|
+
const bottom = b.bl + b.h.repeat(w + padding * 2) + b.br;
|
|
803
|
+
const emptyRow = b.v + " ".repeat(w + padding * 2) + b.v;
|
|
804
|
+
const rows = inner.map((l) => b.v + pad + padEnd(l, w) + pad + b.v);
|
|
805
|
+
const vPad = Array(padding).fill(emptyRow);
|
|
806
|
+
return [top, ...vPad, ...rows, ...vPad, bottom].join("\n");
|
|
807
|
+
};
|
|
808
|
+
var divider = (opts = {}) => {
|
|
809
|
+
const { char, width = null, label = null, style = "single" } = opts;
|
|
810
|
+
const { cols } = termSize();
|
|
811
|
+
const w = width ?? cols;
|
|
812
|
+
const b = BOX_STYLES[style] ?? BOX_STYLES.single;
|
|
813
|
+
const fill = char ?? b.h;
|
|
814
|
+
if (label) {
|
|
815
|
+
const labelLen = visibleLen(label);
|
|
816
|
+
const side = Math.max(0, Math.floor((w - labelLen - 2) / 2));
|
|
817
|
+
const trailLen = Math.max(0, w - side - labelLen - 2);
|
|
818
|
+
return fill.repeat(side) + " " + label + " " + fill.repeat(trailLen);
|
|
819
|
+
}
|
|
820
|
+
return fill.repeat(Math.max(0, w));
|
|
821
|
+
};
|
|
822
|
+
var logo = (text, opts = {}) => {
|
|
823
|
+
const { gradient: gfn = null, boxStyle = "double" } = opts;
|
|
824
|
+
const art = big(text);
|
|
825
|
+
const lines = art.split("\n").map((l) => gfn ? gfn(l) : l);
|
|
826
|
+
return box(lines.join("\n"), { borderStyle: boxStyle, padding: 1 });
|
|
827
|
+
};
|
|
828
|
+
var ascii = {
|
|
829
|
+
big,
|
|
830
|
+
small,
|
|
831
|
+
figlet,
|
|
832
|
+
banner,
|
|
833
|
+
box,
|
|
834
|
+
divider,
|
|
835
|
+
logo,
|
|
836
|
+
boxStyles: Object.keys(BOX_STYLES)
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// src/loaders/index.ts
|
|
840
|
+
var isTTY2 = () => Boolean(process.stdout.isTTY);
|
|
841
|
+
var HEX_RE3 = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
842
|
+
var safeColor = (hex) => {
|
|
843
|
+
if (!hex || !HEX_RE3.test(hex.trim())) return null;
|
|
844
|
+
return hexToRgb(hex);
|
|
845
|
+
};
|
|
846
|
+
var SPINNERS = {
|
|
847
|
+
dots: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"],
|
|
848
|
+
dots2: ["\u28FE", "\u28FD", "\u28FB", "\u28BF", "\u287F", "\u28DF", "\u28EF", "\u28F7"],
|
|
849
|
+
line: ["-", "\\", "|", "/"],
|
|
850
|
+
arrow: ["\u2190", "\u2196", "\u2191", "\u2197", "\u2192", "\u2198", "\u2193", "\u2199"],
|
|
851
|
+
bounce: ["\u2801", "\u2802", "\u2804", "\u2802"],
|
|
852
|
+
star: ["\u2736", "\u2738", "\u2739", "\u273A", "\u2739", "\u2737"],
|
|
853
|
+
moon: ["\u{1F311}", "\u{1F312}", "\u{1F313}", "\u{1F314}", "\u{1F315}", "\u{1F316}", "\u{1F317}", "\u{1F318}"],
|
|
854
|
+
clock: ["\u{1F55B}", "\u{1F550}", "\u{1F551}", "\u{1F552}", "\u{1F553}", "\u{1F554}", "\u{1F555}", "\u{1F556}", "\u{1F557}", "\u{1F558}", "\u{1F559}", "\u{1F55A}"],
|
|
855
|
+
pong: [
|
|
856
|
+
"\u2590\u2802 \u258C",
|
|
857
|
+
"\u2590\u2808 \u258C",
|
|
858
|
+
"\u2590 \u2802 \u258C",
|
|
859
|
+
"\u2590 \u2820 \u258C",
|
|
860
|
+
"\u2590 \u2840 \u258C",
|
|
861
|
+
"\u2590 \u2820 \u258C",
|
|
862
|
+
"\u2590 \u2802 \u258C",
|
|
863
|
+
"\u2590 \u2808 \u258C",
|
|
864
|
+
"\u2590 \u2802 \u258C",
|
|
865
|
+
"\u2590 \u2820 \u258C",
|
|
866
|
+
"\u2590 \u2840 \u258C",
|
|
867
|
+
"\u2590 \u2820 \u258C",
|
|
868
|
+
"\u2590 \u2802 \u258C",
|
|
869
|
+
"\u2590 \u2808 \u258C",
|
|
870
|
+
"\u2590 \u2802\u258C",
|
|
871
|
+
"\u2590 \u2820\u258C",
|
|
872
|
+
"\u2590 \u2840\u258C",
|
|
873
|
+
"\u2590 \u2820 \u258C",
|
|
874
|
+
"\u2590 \u2802 \u258C",
|
|
875
|
+
"\u2590 \u2808 \u258C"
|
|
876
|
+
],
|
|
877
|
+
aesthetic: ["\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1", "\u25B0\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1", "\u25B0\u25B0\u25B0\u25B1\u25B1\u25B1\u25B1", "\u25B0\u25B0\u25B0\u25B0\u25B1\u25B1\u25B1", "\u25B0\u25B0\u25B0\u25B0\u25B0\u25B1\u25B1", "\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0\u25B1", "\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0"],
|
|
878
|
+
blocks: ["\u2588\u2592\u2592\u2592\u2592\u2592\u2592", "\u2588\u2588\u2592\u2592\u2592\u2592\u2592", "\u2588\u2588\u2588\u2592\u2592\u2592\u2592", "\u2588\u2588\u2588\u2588\u2592\u2592\u2592", "\u2588\u2588\u2588\u2588\u2588\u2592\u2592", "\u2588\u2588\u2588\u2588\u2588\u2588\u2592", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588"]
|
|
879
|
+
};
|
|
880
|
+
var spin = (text = "Loading...", opts = {}) => {
|
|
881
|
+
const {
|
|
882
|
+
type = "dots",
|
|
883
|
+
interval = 80,
|
|
884
|
+
color: colorStr = null,
|
|
885
|
+
prefix = "",
|
|
886
|
+
suffix = "",
|
|
887
|
+
persist = false,
|
|
888
|
+
signal,
|
|
889
|
+
reducedMotion = false
|
|
890
|
+
} = opts;
|
|
891
|
+
if (!isTTY2() || reducedMotion) {
|
|
892
|
+
write(text + "\n");
|
|
893
|
+
return (message, success = true) => {
|
|
894
|
+
if (!message) return;
|
|
895
|
+
const icon = success ? "\u2713" : "\u2717";
|
|
896
|
+
const clr = success ? `${sgr(FG.green)}${icon}${reset()}` : `${sgr(FG.red)}${icon}${reset()}`;
|
|
897
|
+
writeln(`${clr} ${message}`);
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
const frames2 = SPINNERS[type] ?? SPINNERS.dots;
|
|
901
|
+
const rgb = safeColor(colorStr);
|
|
902
|
+
let i = 0;
|
|
903
|
+
let stopped = false;
|
|
904
|
+
let timer;
|
|
905
|
+
write(cursor.hide());
|
|
906
|
+
const stop = (message, success = true) => {
|
|
907
|
+
if (stopped) return;
|
|
908
|
+
stopped = true;
|
|
909
|
+
clearInterval(timer);
|
|
910
|
+
if (abortHandler) signal?.removeEventListener("abort", abortHandler);
|
|
911
|
+
write(cursor.show() + screen.clearLine() + "\r");
|
|
912
|
+
if (message) {
|
|
913
|
+
const icon = success ? "\u2713" : "\u2717";
|
|
914
|
+
const clr = success ? `${sgr(FG.green)}${icon}${reset()}` : `${sgr(FG.red)}${icon}${reset()}`;
|
|
915
|
+
writeln(`${clr} ${message}`);
|
|
916
|
+
} else if (persist) {
|
|
917
|
+
writeln(` ${text}`);
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
const abortHandler = signal ? () => stop("Cancelled", false) : null;
|
|
921
|
+
if (abortHandler) signal?.addEventListener("abort", abortHandler, { once: true });
|
|
922
|
+
timer = setInterval(() => {
|
|
923
|
+
if (stopped) return;
|
|
924
|
+
if (signal?.aborted) {
|
|
925
|
+
stop();
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
const frame = frames2[i % frames2.length];
|
|
929
|
+
const colored = rgb ? fgRgb(rgb.r, rgb.g, rgb.b) + frame + reset() : frame;
|
|
930
|
+
write(cursor.save() + screen.clearLine() + `\r${prefix}${colored} ${text}${suffix}` + cursor.restore());
|
|
931
|
+
i++;
|
|
932
|
+
}, interval);
|
|
933
|
+
return stop;
|
|
934
|
+
};
|
|
935
|
+
var dots = (text = "Processing", opts = {}) => {
|
|
936
|
+
const { interval = 400, max = 3, signal } = opts;
|
|
937
|
+
if (!isTTY2()) {
|
|
938
|
+
write(text + "\n");
|
|
939
|
+
return () => {
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
let i = 0;
|
|
943
|
+
let stopped = false;
|
|
944
|
+
write(cursor.hide());
|
|
945
|
+
const stop = () => {
|
|
946
|
+
if (stopped) return;
|
|
947
|
+
stopped = true;
|
|
948
|
+
clearInterval(timer);
|
|
949
|
+
write(cursor.show() + screen.clearLine() + "\r");
|
|
950
|
+
};
|
|
951
|
+
if (signal) signal.addEventListener("abort", stop, { once: true });
|
|
952
|
+
const timer = setInterval(() => {
|
|
953
|
+
if (stopped) return;
|
|
954
|
+
const d = ".".repeat(i % max + 1).padEnd(max);
|
|
955
|
+
write(cursor.save() + screen.clearLine() + `\r${text}${d}` + cursor.restore());
|
|
956
|
+
i++;
|
|
957
|
+
}, interval);
|
|
958
|
+
return stop;
|
|
959
|
+
};
|
|
960
|
+
var progress = (percent, label = "", opts = {}) => {
|
|
961
|
+
const {
|
|
962
|
+
width = 30,
|
|
963
|
+
char = "\u2588",
|
|
964
|
+
emptyChar = "\u2591",
|
|
965
|
+
showPercentage = true,
|
|
966
|
+
color: colorStr = null
|
|
967
|
+
} = opts;
|
|
968
|
+
const safeWidth = Math.max(1, width);
|
|
969
|
+
const clamped = Math.min(100, Math.max(0, percent));
|
|
970
|
+
const filled = Math.round(clamped / 100 * safeWidth);
|
|
971
|
+
const empty = safeWidth - filled;
|
|
972
|
+
const rgb = safeColor(colorStr);
|
|
973
|
+
let filledStr = char.repeat(filled);
|
|
974
|
+
const emptyStr = emptyChar.repeat(empty);
|
|
975
|
+
if (rgb) filledStr = fgRgb(rgb.r, rgb.g, rgb.b) + filledStr + reset();
|
|
976
|
+
const pct = showPercentage ? ` ${String(Math.round(clamped)).padStart(3)}%` : "";
|
|
977
|
+
const lbl = label ? ` ${label}` : "";
|
|
978
|
+
write(screen.clearLine() + `\r[${filledStr}${emptyStr}]${pct}${lbl}`);
|
|
979
|
+
};
|
|
980
|
+
var progressAnimate = async (steps, label = "", opts = {}) => {
|
|
981
|
+
const { delay = 100, signal, ...barOpts } = opts;
|
|
982
|
+
const safeSteps2 = Math.max(1, steps);
|
|
983
|
+
write(cursor.hide());
|
|
984
|
+
try {
|
|
985
|
+
for (let i = 0; i <= safeSteps2; i++) {
|
|
986
|
+
if (signal?.aborted) break;
|
|
987
|
+
progress(i / safeSteps2 * 100, label, barOpts);
|
|
988
|
+
await sleep(delay);
|
|
989
|
+
}
|
|
990
|
+
writeln();
|
|
991
|
+
} finally {
|
|
992
|
+
write(cursor.show());
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
var tasks = async (taskList, opts = {}) => {
|
|
996
|
+
const { type = "dots", spinColor = "#00ff88", parallel = false } = opts;
|
|
997
|
+
if (!taskList.length) return [];
|
|
998
|
+
const runTask = async ({ text, fn }) => {
|
|
999
|
+
const stop = spin(text, { type, color: spinColor, reducedMotion: parallel });
|
|
1000
|
+
try {
|
|
1001
|
+
const result = await fn();
|
|
1002
|
+
stop(text, true);
|
|
1003
|
+
return { success: true, result };
|
|
1004
|
+
} catch (err) {
|
|
1005
|
+
stop(`${text} \u2014 ${err.message}`, false);
|
|
1006
|
+
return { success: false, error: err };
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
if (parallel) {
|
|
1010
|
+
return Promise.all(taskList.map(runTask));
|
|
1011
|
+
}
|
|
1012
|
+
const results = [];
|
|
1013
|
+
for (const task of taskList) {
|
|
1014
|
+
results.push(await runTask(task));
|
|
1015
|
+
}
|
|
1016
|
+
return results;
|
|
1017
|
+
};
|
|
1018
|
+
var custom = (frames2, text = "", opts = {}) => {
|
|
1019
|
+
const { interval = 100, signal } = opts;
|
|
1020
|
+
if (!frames2.length) throw new Error("custom: frames cannot be empty");
|
|
1021
|
+
if (!isTTY2()) {
|
|
1022
|
+
write(text + "\n");
|
|
1023
|
+
return () => {
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
let i = 0;
|
|
1027
|
+
let stopped = false;
|
|
1028
|
+
write(cursor.hide());
|
|
1029
|
+
const stop = () => {
|
|
1030
|
+
if (stopped) return;
|
|
1031
|
+
stopped = true;
|
|
1032
|
+
clearInterval(timer);
|
|
1033
|
+
write(cursor.show() + screen.clearLine() + "\r");
|
|
1034
|
+
};
|
|
1035
|
+
if (signal) signal.addEventListener("abort", stop, { once: true });
|
|
1036
|
+
const timer = setInterval(() => {
|
|
1037
|
+
if (stopped) return;
|
|
1038
|
+
write(cursor.save() + screen.clearLine() + `\r${frames2[i % frames2.length]} ${text}` + cursor.restore());
|
|
1039
|
+
i++;
|
|
1040
|
+
}, interval);
|
|
1041
|
+
return stop;
|
|
1042
|
+
};
|
|
1043
|
+
var countdown = async (seconds, opts = {}) => {
|
|
1044
|
+
const { label = "Starting in", color: colorStr = "#ffd700", signal } = opts;
|
|
1045
|
+
const rgb = safeColor(colorStr) ?? { r: 255, g: 215, b: 0 };
|
|
1046
|
+
write(cursor.hide());
|
|
1047
|
+
try {
|
|
1048
|
+
for (let s = seconds; s >= 0; s--) {
|
|
1049
|
+
if (signal?.aborted) break;
|
|
1050
|
+
write(screen.clearLine() + `\r${label} ${fgRgb(rgb.r, rgb.g, rgb.b)}${s}${reset()}s`);
|
|
1051
|
+
if (s > 0) await sleep(1e3);
|
|
1052
|
+
}
|
|
1053
|
+
write(screen.clearLine() + "\r");
|
|
1054
|
+
} finally {
|
|
1055
|
+
write(cursor.show());
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
var loader = {
|
|
1059
|
+
spin,
|
|
1060
|
+
dots,
|
|
1061
|
+
progress,
|
|
1062
|
+
progressAnimate,
|
|
1063
|
+
tasks,
|
|
1064
|
+
custom,
|
|
1065
|
+
countdown,
|
|
1066
|
+
spinners: SPINNERS
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
// src/frames/index.ts
|
|
1070
|
+
var lineCount = (frame) => frame.split("\n").length;
|
|
1071
|
+
var clearLines = (n) => {
|
|
1072
|
+
for (let i = 0; i < n; i++) {
|
|
1073
|
+
write("\r" + screen.clearLine() + cursor.up(1));
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
var play = async (frames2, opts = {}) => {
|
|
1077
|
+
const {
|
|
1078
|
+
interval = 100,
|
|
1079
|
+
repeat = 1,
|
|
1080
|
+
clearOnFinish = false,
|
|
1081
|
+
onFrame = null,
|
|
1082
|
+
signal
|
|
1083
|
+
} = opts;
|
|
1084
|
+
if (!frames2 || frames2.length === 0) return;
|
|
1085
|
+
const safeRepeat = Math.max(0, repeat);
|
|
1086
|
+
const infinite = repeat === 0;
|
|
1087
|
+
let lastLines = 0;
|
|
1088
|
+
let iteration = 0;
|
|
1089
|
+
const renderFrame = (frame, idx) => {
|
|
1090
|
+
if (lastLines > 0) clearLines(lastLines);
|
|
1091
|
+
const rendered = onFrame ? onFrame(frame, idx) : frame;
|
|
1092
|
+
write(rendered);
|
|
1093
|
+
lastLines = lineCount(rendered) + (rendered.endsWith("\n") ? 0 : 1);
|
|
1094
|
+
if (!rendered.endsWith("\n")) writeln();
|
|
1095
|
+
};
|
|
1096
|
+
write(cursor.hide());
|
|
1097
|
+
try {
|
|
1098
|
+
while (infinite || iteration < safeRepeat) {
|
|
1099
|
+
for (let i = 0; i < frames2.length; i++) {
|
|
1100
|
+
if (signal?.aborted) return;
|
|
1101
|
+
renderFrame(frames2[i], i);
|
|
1102
|
+
await sleep(interval);
|
|
1103
|
+
}
|
|
1104
|
+
iteration++;
|
|
1105
|
+
if (!infinite && iteration >= safeRepeat) break;
|
|
1106
|
+
}
|
|
1107
|
+
if (clearOnFinish && lastLines > 0) clearLines(lastLines);
|
|
1108
|
+
} finally {
|
|
1109
|
+
write(cursor.show());
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
var generate = (count, fn) => Array.from({ length: Math.max(0, count) }, (_, i) => fn(i, count));
|
|
1113
|
+
var live = (opts = {}) => {
|
|
1114
|
+
const { fps = 12, autoStart = true } = opts;
|
|
1115
|
+
const safeFps = Math.max(1, fps);
|
|
1116
|
+
const interval = Math.floor(1e3 / safeFps);
|
|
1117
|
+
let currentFrame = "";
|
|
1118
|
+
let lastLines = 0;
|
|
1119
|
+
let running = false;
|
|
1120
|
+
let timer = null;
|
|
1121
|
+
const render = () => {
|
|
1122
|
+
if (lastLines > 0) clearLines(lastLines);
|
|
1123
|
+
write(currentFrame);
|
|
1124
|
+
lastLines = lineCount(currentFrame) + (currentFrame.endsWith("\n") ? 0 : 1);
|
|
1125
|
+
if (!currentFrame.endsWith("\n")) writeln();
|
|
1126
|
+
};
|
|
1127
|
+
const start = () => {
|
|
1128
|
+
if (running) return;
|
|
1129
|
+
running = true;
|
|
1130
|
+
write(cursor.hide());
|
|
1131
|
+
timer = setInterval(render, interval);
|
|
1132
|
+
};
|
|
1133
|
+
const stop = () => {
|
|
1134
|
+
running = false;
|
|
1135
|
+
if (timer) {
|
|
1136
|
+
clearInterval(timer);
|
|
1137
|
+
timer = null;
|
|
1138
|
+
}
|
|
1139
|
+
write(cursor.show());
|
|
1140
|
+
};
|
|
1141
|
+
const update = (newFrame) => {
|
|
1142
|
+
currentFrame = newFrame;
|
|
1143
|
+
if (running) render();
|
|
1144
|
+
};
|
|
1145
|
+
if (autoStart) start();
|
|
1146
|
+
return { start, stop, update };
|
|
1147
|
+
};
|
|
1148
|
+
var morph = (frameA, frameB, steps = 8, charset = "\u2591\u2592\u2593\u2588\u2593\u2592\u2591") => {
|
|
1149
|
+
const n = Math.max(2, steps);
|
|
1150
|
+
const len = Math.max(frameA.length, frameB.length);
|
|
1151
|
+
const a = frameA.padEnd(len);
|
|
1152
|
+
const b = frameB.padEnd(len);
|
|
1153
|
+
return generate(n, (i) => {
|
|
1154
|
+
const t = i / (n - 1);
|
|
1155
|
+
return [...Array(len)].map((_, ci) => {
|
|
1156
|
+
const ca = a[ci];
|
|
1157
|
+
const cb = b[ci];
|
|
1158
|
+
if (t === 0) return ca;
|
|
1159
|
+
if (t === 1) return cb;
|
|
1160
|
+
if (ca !== cb) {
|
|
1161
|
+
if (!charset.length) return "\u2591";
|
|
1162
|
+
const idx = Math.floor(t * charset.length) % charset.length;
|
|
1163
|
+
return charset[idx];
|
|
1164
|
+
}
|
|
1165
|
+
return ca;
|
|
1166
|
+
}).join("");
|
|
1167
|
+
});
|
|
1168
|
+
};
|
|
1169
|
+
var presets2 = {
|
|
1170
|
+
loadingBar: (opts = {}) => {
|
|
1171
|
+
const { width = 20, char = "\u2588", empty = "\u2591", label = "Loading" } = opts;
|
|
1172
|
+
return generate(width + 1, (i) => {
|
|
1173
|
+
const filled = char.repeat(i);
|
|
1174
|
+
const rest = empty.repeat(width - i);
|
|
1175
|
+
const pct = Math.round(i / width * 100);
|
|
1176
|
+
return `${label} [${filled}${rest}] ${pct}%`;
|
|
1177
|
+
});
|
|
1178
|
+
},
|
|
1179
|
+
ball: (opts = {}) => {
|
|
1180
|
+
const { width = 20, char = "\u25CF" } = opts;
|
|
1181
|
+
const forward = generate(width, (i) => " ".repeat(i) + char);
|
|
1182
|
+
const backward = generate(width, (i) => " ".repeat(width - i - 1) + char);
|
|
1183
|
+
return [...forward, ...backward.slice(1, -1).reverse()];
|
|
1184
|
+
},
|
|
1185
|
+
breathe: (text, opts = {}) => {
|
|
1186
|
+
const { steps = 8 } = opts;
|
|
1187
|
+
const shades = ["\u2591", "\u2592", "\u2593", "\u2588"];
|
|
1188
|
+
return generate(steps * 2, (i) => {
|
|
1189
|
+
const t = i < steps ? i / steps : 1 - (i - steps) / steps;
|
|
1190
|
+
const shade = shades[Math.min(shades.length - 1, Math.floor(t * shades.length))];
|
|
1191
|
+
return text.split("").map((ch) => ch === " " ? " " : shade).join("");
|
|
1192
|
+
});
|
|
1193
|
+
},
|
|
1194
|
+
typeDelete: (text, opts = {}) => {
|
|
1195
|
+
const { cursor: cur = "\u258C" } = opts;
|
|
1196
|
+
const typed = generate(text.length + 1, (i) => text.slice(0, i) + cur);
|
|
1197
|
+
const deleted = generate(text.length + 1, (i) => text.slice(0, text.length - i) + cur);
|
|
1198
|
+
return [...typed, ...deleted];
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
var frames = { play, generate, live, morph, presets: presets2 };
|
|
1202
|
+
|
|
1203
|
+
// src/components/index.ts
|
|
1204
|
+
var TABLE_BORDERS = {
|
|
1205
|
+
single: { tl: "\u250C", tr: "\u2510", bl: "\u2514", br: "\u2518", h: "\u2500", v: "\u2502", ml: "\u251C", mr: "\u2524", mt: "\u252C", mb: "\u2534", cx: "\u253C" },
|
|
1206
|
+
double: { tl: "\u2554", tr: "\u2557", bl: "\u255A", br: "\u255D", h: "\u2550", v: "\u2551", ml: "\u2560", mr: "\u2563", mt: "\u2566", mb: "\u2569", cx: "\u256C" },
|
|
1207
|
+
rounded: { tl: "\u256D", tr: "\u256E", bl: "\u2570", br: "\u256F", h: "\u2500", v: "\u2502", ml: "\u251C", mr: "\u2524", mt: "\u252C", mb: "\u2534", cx: "\u253C" },
|
|
1208
|
+
heavy: { tl: "\u250F", tr: "\u2513", bl: "\u2517", br: "\u251B", h: "\u2501", v: "\u2503", ml: "\u2523", mr: "\u252B", mt: "\u2533", mb: "\u253B", cx: "\u254B" }
|
|
1209
|
+
};
|
|
1210
|
+
var table = (rows, opts = {}) => {
|
|
1211
|
+
const { header = true, borderStyle = "rounded", padding = 1 } = opts;
|
|
1212
|
+
if (!rows || rows.length === 0) return "";
|
|
1213
|
+
const b = TABLE_BORDERS[borderStyle] ?? TABLE_BORDERS.rounded;
|
|
1214
|
+
const pad = " ".repeat(padding);
|
|
1215
|
+
const cols = Math.max(...rows.map((r) => r.length), 0);
|
|
1216
|
+
const widths = Array.from(
|
|
1217
|
+
{ length: cols },
|
|
1218
|
+
(_, ci) => Math.max(...rows.map((r) => visibleLen(String(r[ci] ?? ""))))
|
|
1219
|
+
);
|
|
1220
|
+
const rowSep = (left, mid, right, fill) => left + widths.map((w) => fill.repeat(w + padding * 2)).join(mid) + right;
|
|
1221
|
+
const renderRow = (row, isHeader = false) => {
|
|
1222
|
+
const cells = row.map((cell, ci) => {
|
|
1223
|
+
let s = padEnd(String(cell ?? ""), widths[ci] ?? 0);
|
|
1224
|
+
if (isHeader) s = sgr(STYLE.bold) + s + reset();
|
|
1225
|
+
return pad + s + pad;
|
|
1226
|
+
});
|
|
1227
|
+
return b.v + cells.join(b.v) + b.v;
|
|
1228
|
+
};
|
|
1229
|
+
const lines = [];
|
|
1230
|
+
lines.push(rowSep(b.tl, b.mt, b.tr, b.h));
|
|
1231
|
+
rows.forEach((row, ri) => {
|
|
1232
|
+
lines.push(renderRow(row, ri === 0 && header));
|
|
1233
|
+
if (ri === 0 && header && rows.length > 1) lines.push(rowSep(b.ml, b.cx, b.mr, b.h));
|
|
1234
|
+
});
|
|
1235
|
+
lines.push(rowSep(b.bl, b.mb, b.br, b.h));
|
|
1236
|
+
return lines.join("\n");
|
|
1237
|
+
};
|
|
1238
|
+
var badge = (label, value, opts = {}) => {
|
|
1239
|
+
const { labelBg = BG.blue, valueBg = BG.green, labelFg = FG.white, valueFg = FG.white } = opts;
|
|
1240
|
+
return sgr(labelBg, labelFg) + ` ${label} ` + reset() + sgr(valueBg, valueFg) + ` ${value} ` + reset();
|
|
1241
|
+
};
|
|
1242
|
+
var progressBar = (percent, opts = {}) => {
|
|
1243
|
+
const { width = 30, char = "\u2588", emptyChar = "\u2591", showPercentage = true, label = "", color: color2 = null } = opts;
|
|
1244
|
+
const clamped = Math.min(100, Math.max(0, percent));
|
|
1245
|
+
const filled = Math.round(clamped / 100 * width);
|
|
1246
|
+
const empty = width - filled;
|
|
1247
|
+
let filledStr = char.repeat(filled);
|
|
1248
|
+
const emptyStr = emptyChar.repeat(empty);
|
|
1249
|
+
if (color2 !== null) filledStr = sgr(color2) + filledStr + reset();
|
|
1250
|
+
const pct = showPercentage ? ` ${String(Math.round(clamped)).padStart(3)}%` : "";
|
|
1251
|
+
const lbl = label ? ` ${label}` : "";
|
|
1252
|
+
return `[${filledStr}${emptyStr}]${pct}${lbl}`;
|
|
1253
|
+
};
|
|
1254
|
+
var STATUS_MAP = {
|
|
1255
|
+
success: { icon: "\u2713", color: FG.green },
|
|
1256
|
+
error: { icon: "\u2717", color: FG.red },
|
|
1257
|
+
warn: { icon: "\u26A0", color: FG.yellow },
|
|
1258
|
+
info: { icon: "\u2139", color: FG.cyan },
|
|
1259
|
+
wait: { icon: "\u25CC", color: FG.brightBlack }
|
|
1260
|
+
};
|
|
1261
|
+
var status = (type, message) => {
|
|
1262
|
+
const { icon, color: color2 } = STATUS_MAP[type] ?? STATUS_MAP.info;
|
|
1263
|
+
return sgr(color2) + icon + reset() + " " + message;
|
|
1264
|
+
};
|
|
1265
|
+
var section = (title, opts = {}) => {
|
|
1266
|
+
const { char = "\u2500", width = null, color: colorCode = FG.cyan } = opts;
|
|
1267
|
+
const { cols } = termSize();
|
|
1268
|
+
const w = Math.max(width ?? cols, title.length + 2);
|
|
1269
|
+
const side = Math.floor((w - title.length - 2) / 2);
|
|
1270
|
+
const divider2 = sgr(colorCode) + char.repeat(side) + reset();
|
|
1271
|
+
const t = sgr(STYLE.bold, colorCode) + title + reset();
|
|
1272
|
+
const trail = sgr(colorCode) + char.repeat(Math.max(0, w - side - title.length - 2)) + reset();
|
|
1273
|
+
return divider2 + " " + t + " " + trail;
|
|
1274
|
+
};
|
|
1275
|
+
var columns = (items, opts = {}) => {
|
|
1276
|
+
const { cols: numCols = 2, gap = 2, width = null } = opts;
|
|
1277
|
+
if (numCols < 1) throw new Error("columns: cols must be >= 1");
|
|
1278
|
+
const { cols: termCols } = termSize();
|
|
1279
|
+
const totalW = width ?? termCols;
|
|
1280
|
+
const colW = Math.floor((totalW - gap * (numCols - 1)) / numCols);
|
|
1281
|
+
const rows = [];
|
|
1282
|
+
for (let i = 0; i < items.length; i += numCols) {
|
|
1283
|
+
const chunk = items.slice(i, i + numCols);
|
|
1284
|
+
rows.push(chunk.map((item) => padEnd(String(item), colW)).join(" ".repeat(gap)));
|
|
1285
|
+
}
|
|
1286
|
+
return rows.join("\n");
|
|
1287
|
+
};
|
|
1288
|
+
var timeline = (events, opts = {}) => {
|
|
1289
|
+
const {
|
|
1290
|
+
connector = "\u2502",
|
|
1291
|
+
node = "\u25CF",
|
|
1292
|
+
color: colorCode = FG.cyan,
|
|
1293
|
+
doneColor = FG.green,
|
|
1294
|
+
pendingColor = FG.brightBlack
|
|
1295
|
+
} = opts;
|
|
1296
|
+
const lines = [];
|
|
1297
|
+
events.forEach((ev, i) => {
|
|
1298
|
+
const isLast = i === events.length - 1;
|
|
1299
|
+
const clr = ev.done ? doneColor : i === 0 ? colorCode : pendingColor;
|
|
1300
|
+
const nodeStr = sgr(clr) + node + reset();
|
|
1301
|
+
const textStr = ev.done ? sgr(STYLE.bold) + ev.label + reset() : sgr(pendingColor) + ev.label + reset();
|
|
1302
|
+
lines.push(`${nodeStr} ${textStr}${ev.time ? sgr(FG.brightBlack) + " " + ev.time + reset() : ""}`);
|
|
1303
|
+
if (!isLast) lines.push(sgr(pendingColor) + connector + reset());
|
|
1304
|
+
});
|
|
1305
|
+
return lines.join("\n");
|
|
1306
|
+
};
|
|
1307
|
+
var MENU_CANCELLED = /* @__PURE__ */ Symbol("MENU_CANCELLED");
|
|
1308
|
+
var menu = (items, opts = {}) => {
|
|
1309
|
+
const {
|
|
1310
|
+
title = null,
|
|
1311
|
+
pointer = "\u25B6",
|
|
1312
|
+
multiSelect = false,
|
|
1313
|
+
color: colorCode = FG.cyan,
|
|
1314
|
+
input: inp = process.stdin,
|
|
1315
|
+
output: out = { write: (s) => process.stdout.write(s) }
|
|
1316
|
+
} = opts;
|
|
1317
|
+
if (!items.length) throw new Error("menu requires at least one item");
|
|
1318
|
+
if (!inp.isTTY) return Promise.resolve(multiSelect ? [] : 0);
|
|
1319
|
+
let cursorPos = 0;
|
|
1320
|
+
const selected = /* @__PURE__ */ new Set();
|
|
1321
|
+
const emit = (str) => {
|
|
1322
|
+
out.write(str);
|
|
1323
|
+
};
|
|
1324
|
+
const render = () => {
|
|
1325
|
+
if (title) emit(sgr(STYLE.bold) + title + reset() + "\n");
|
|
1326
|
+
items.forEach((item, i) => {
|
|
1327
|
+
const isActive = i === cursorPos;
|
|
1328
|
+
const isSelected = selected.has(i);
|
|
1329
|
+
const ptr = isActive ? sgr(colorCode) + pointer + reset() : " ";
|
|
1330
|
+
const sel = multiSelect ? isSelected ? sgr(colorCode) + "\u25CF" + reset() : "\u25CB" : "";
|
|
1331
|
+
const txt = isActive ? sgr(STYLE.bold, colorCode) + item + reset() : item;
|
|
1332
|
+
emit(`${ptr} ${sel}${multiSelect ? " " : ""}${txt}
|
|
1333
|
+
`);
|
|
1334
|
+
});
|
|
1335
|
+
};
|
|
1336
|
+
const clearLines2 = () => {
|
|
1337
|
+
const lines = items.length + (title ? 1 : 0);
|
|
1338
|
+
for (let i = 0; i < lines; i++) emit(cursor.up(1) + screen.clearLine());
|
|
1339
|
+
emit("\r");
|
|
1340
|
+
};
|
|
1341
|
+
const cleanup = (onKey) => {
|
|
1342
|
+
inp.removeListener("data", onKey);
|
|
1343
|
+
if (inp.setRawMode) inp.setRawMode(false);
|
|
1344
|
+
emit(cursor.show());
|
|
1345
|
+
};
|
|
1346
|
+
emit(cursor.hide());
|
|
1347
|
+
render();
|
|
1348
|
+
return new Promise((resolve) => {
|
|
1349
|
+
const onKey = (...args) => {
|
|
1350
|
+
const key = args[0];
|
|
1351
|
+
const k = key.toString();
|
|
1352
|
+
const KEY_UP = "\x1B[A";
|
|
1353
|
+
const KEY_DOWN = "\x1B[B";
|
|
1354
|
+
const KEY_ENTER = "\r";
|
|
1355
|
+
const KEY_SPACE = " ";
|
|
1356
|
+
const KEY_CTRL_C = "";
|
|
1357
|
+
if (k === KEY_CTRL_C) {
|
|
1358
|
+
clearLines2();
|
|
1359
|
+
cleanup(onKey);
|
|
1360
|
+
resolve(MENU_CANCELLED);
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
if (k === KEY_UP || k === "k" || k === "w") {
|
|
1364
|
+
cursorPos = (cursorPos - 1 + items.length) % items.length;
|
|
1365
|
+
} else if (k === KEY_DOWN || k === "j" || k === "s") {
|
|
1366
|
+
cursorPos = (cursorPos + 1) % items.length;
|
|
1367
|
+
} else if (k === KEY_SPACE && multiSelect) {
|
|
1368
|
+
if (selected.has(cursorPos)) selected.delete(cursorPos);
|
|
1369
|
+
else selected.add(cursorPos);
|
|
1370
|
+
} else if (k === KEY_ENTER) {
|
|
1371
|
+
clearLines2();
|
|
1372
|
+
cleanup(onKey);
|
|
1373
|
+
resolve(multiSelect ? selected.size ? [...selected] : [cursorPos] : cursorPos);
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
clearLines2();
|
|
1377
|
+
render();
|
|
1378
|
+
};
|
|
1379
|
+
if (inp.setRawMode) inp.setRawMode(true);
|
|
1380
|
+
inp.resume();
|
|
1381
|
+
inp.on("data", onKey);
|
|
1382
|
+
});
|
|
1383
|
+
};
|
|
1384
|
+
var components = { table, badge, progressBar, status, section, columns, timeline, menu };
|
|
1385
|
+
|
|
1386
|
+
// src/themes/index.ts
|
|
1387
|
+
var THEMES = {
|
|
1388
|
+
dracula: { name: "Dracula", primary: "#bd93f9", secondary: "#ff79c6", accent: "#50fa7b", warning: "#f1fa8c", error: "#ff5555", info: "#8be9fd", muted: "#6272a4", bg: "#282a36", surface: "#44475a", text: "#f8f8f2", gradient: ["#bd93f9", "#ff79c6"] },
|
|
1389
|
+
nord: { name: "Nord", primary: "#88c0d0", secondary: "#81a1c1", accent: "#a3be8c", warning: "#ebcb8b", error: "#bf616a", info: "#5e81ac", muted: "#4c566a", bg: "#2e3440", surface: "#3b4252", text: "#eceff4", gradient: ["#88c0d0", "#81a1c1"] },
|
|
1390
|
+
monokai: { name: "Monokai", primary: "#a6e22e", secondary: "#66d9e8", accent: "#f92672", warning: "#fd971f", error: "#f92672", info: "#66d9e8", muted: "#75715e", bg: "#272822", surface: "#3e3d32", text: "#f8f8f2", gradient: ["#a6e22e", "#66d9e8"] },
|
|
1391
|
+
cyberpunk: { name: "Cyberpunk", primary: "#ff2d78", secondary: "#00fff5", accent: "#ffe801", warning: "#ff8800", error: "#ff2d78", info: "#00fff5", muted: "#444466", bg: "#0d0d1a", surface: "#1a1a2e", text: "#e0e0ff", gradient: ["#ff2d78", "#00fff5", "#ffe801"] },
|
|
1392
|
+
pastel: { name: "Pastel", primary: "#a29bfe", secondary: "#fd79a8", accent: "#55efc4", warning: "#ffeaa7", error: "#e17055", info: "#74b9ff", muted: "#b2bec3", bg: "#f8f9fa", surface: "#ffffff", text: "#2d3436", gradient: ["#a29bfe", "#fd79a8", "#74b9ff"] },
|
|
1393
|
+
matrix: { name: "Matrix", primary: "#00ff41", secondary: "#008f11", accent: "#00ff41", warning: "#aaff00", error: "#ff0000", info: "#00cc33", muted: "#003b00", bg: "#0d0208", surface: "#001a00", text: "#00ff41", gradient: ["#00ff41", "#003b00"] },
|
|
1394
|
+
ocean: { name: "Ocean", primary: "#0099ff", secondary: "#00d2d3", accent: "#ffd32a", warning: "#ffa502", error: "#ff4757", info: "#70a1ff", muted: "#57606f", bg: "#0a1628", surface: "#0f2942", text: "#dfe6e9", gradient: ["#0099ff", "#00d2d3"] },
|
|
1395
|
+
sunset: { name: "Sunset", primary: "#fd7272", secondary: "#f9ca24", accent: "#6ab04c", warning: "#f0932b", error: "#eb4d4b", info: "#22a6b3", muted: "#95afc0", bg: "#1a1a2e", surface: "#16213e", text: "#f5f6fa", gradient: ["#fd7272", "#f9ca24", "#6ab04c"] }
|
|
1396
|
+
};
|
|
1397
|
+
var _active = THEMES["dracula"];
|
|
1398
|
+
var apply = (colorHex) => (text) => {
|
|
1399
|
+
const { r, g, b } = hexToRgb(colorHex);
|
|
1400
|
+
return fgRgb(r, g, b) + text + reset();
|
|
1401
|
+
};
|
|
1402
|
+
var themes = {
|
|
1403
|
+
list: () => Object.keys(THEMES),
|
|
1404
|
+
get: (name) => THEMES[name] ?? null,
|
|
1405
|
+
use(name) {
|
|
1406
|
+
const t = THEMES[name];
|
|
1407
|
+
if (!t) throw new Error(`Theme "${name}" not found. Available: ${Object.keys(THEMES).join(", ")}`);
|
|
1408
|
+
_active = t;
|
|
1409
|
+
return themes;
|
|
1410
|
+
},
|
|
1411
|
+
current: () => _active,
|
|
1412
|
+
primary: (text) => apply(_active.primary)(text),
|
|
1413
|
+
secondary: (text) => apply(_active.secondary)(text),
|
|
1414
|
+
accent: (text) => apply(_active.accent)(text),
|
|
1415
|
+
warning: (text) => apply(_active.warning)(text),
|
|
1416
|
+
error: (text) => apply(_active.error)(text),
|
|
1417
|
+
info: (text) => apply(_active.info)(text),
|
|
1418
|
+
muted: (text) => apply(_active.muted)(text),
|
|
1419
|
+
text: (text) => apply(_active.text)(text),
|
|
1420
|
+
bold: (text) => sgr(STYLE.bold) + text + reset(),
|
|
1421
|
+
gradient: (text) => gradient(text, _active.gradient),
|
|
1422
|
+
register: (name, def) => {
|
|
1423
|
+
THEMES[name] = def;
|
|
1424
|
+
},
|
|
1425
|
+
preview: () => {
|
|
1426
|
+
const orig = _active;
|
|
1427
|
+
Object.values(THEMES).forEach((t) => {
|
|
1428
|
+
_active = t;
|
|
1429
|
+
console.log(
|
|
1430
|
+
gradient(` ${t.name} `, t.gradient) + " " + themes.primary("primary") + " " + themes.secondary("secondary") + " " + themes.accent("accent") + " " + themes.error("error") + " " + themes.warning("warning")
|
|
1431
|
+
);
|
|
1432
|
+
});
|
|
1433
|
+
_active = orig;
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
// src/images/index.ts
|
|
1438
|
+
var FULL_BLOCK = "\u2588";
|
|
1439
|
+
var UPPER_HALF = "\u2580";
|
|
1440
|
+
var HEX_RE4 = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
1441
|
+
var safeHex2 = (h) => {
|
|
1442
|
+
if (!HEX_RE4.test(h.trim())) return null;
|
|
1443
|
+
return hexToRgb(h);
|
|
1444
|
+
};
|
|
1445
|
+
var toRgb = (p) => p ?? { r: 0, g: 0, b: 0 };
|
|
1446
|
+
var renderPixelArt = (pixels, opts = {}) => {
|
|
1447
|
+
const { scale = 1, halfBlock = true } = opts;
|
|
1448
|
+
if (!pixels.length) return "";
|
|
1449
|
+
const lines = [];
|
|
1450
|
+
if (halfBlock) {
|
|
1451
|
+
for (let row = 0; row < pixels.length; row += 2) {
|
|
1452
|
+
let line = "";
|
|
1453
|
+
const topRow = pixels[row] ?? [];
|
|
1454
|
+
const botRow = pixels[row + 1] ?? [];
|
|
1455
|
+
for (let col = 0; col < topRow.length; col++) {
|
|
1456
|
+
const top = topRow[col] ?? null;
|
|
1457
|
+
const bot = botRow[col] ?? null;
|
|
1458
|
+
if (!top && !bot) {
|
|
1459
|
+
line += " ".repeat(scale);
|
|
1460
|
+
continue;
|
|
1461
|
+
}
|
|
1462
|
+
let cell = "";
|
|
1463
|
+
for (let s = 0; s < scale; s++) {
|
|
1464
|
+
if (top && bot) {
|
|
1465
|
+
const t = toRgb(top), b = toRgb(bot);
|
|
1466
|
+
cell += fgRgb(t.r, t.g, t.b) + bgRgb(b.r, b.g, b.b) + UPPER_HALF + reset();
|
|
1467
|
+
} else if (top) {
|
|
1468
|
+
const { r, g, b } = toRgb(top);
|
|
1469
|
+
cell += fgRgb(r, g, b) + FULL_BLOCK + reset();
|
|
1470
|
+
} else {
|
|
1471
|
+
const { r, g, b } = toRgb(bot);
|
|
1472
|
+
cell += fgRgb(r, g, b) + "\u2584" + reset();
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
line += cell;
|
|
1476
|
+
}
|
|
1477
|
+
lines.push(line);
|
|
1478
|
+
}
|
|
1479
|
+
} else {
|
|
1480
|
+
for (const row of pixels) {
|
|
1481
|
+
let line = "";
|
|
1482
|
+
for (const pixel of row) {
|
|
1483
|
+
if (!pixel) line += " ".repeat(scale);
|
|
1484
|
+
else {
|
|
1485
|
+
const { r, g, b } = pixel;
|
|
1486
|
+
line += fgRgb(r, g, b) + FULL_BLOCK.repeat(scale) + reset();
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
lines.push(line);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
return lines.join("\n");
|
|
1493
|
+
};
|
|
1494
|
+
var R = { r: 255, g: 0, b: 0 };
|
|
1495
|
+
var Y = { r: 255, g: 220, b: 0 };
|
|
1496
|
+
var G = { r: 255, g: 215, b: 0 };
|
|
1497
|
+
var K = { r: 0, g: 0, b: 0 };
|
|
1498
|
+
var N = null;
|
|
1499
|
+
var SPRITES = {
|
|
1500
|
+
heart: { pixels: [
|
|
1501
|
+
[N, R, N, R, N],
|
|
1502
|
+
[R, R, R, R, R],
|
|
1503
|
+
[R, R, R, R, R],
|
|
1504
|
+
[N, R, R, R, N],
|
|
1505
|
+
[N, N, R, N, N]
|
|
1506
|
+
] },
|
|
1507
|
+
star: { pixels: [
|
|
1508
|
+
[N, G, N, G, N],
|
|
1509
|
+
[G, G, G, G, G],
|
|
1510
|
+
[N, G, G, G, N],
|
|
1511
|
+
[G, N, G, N, G],
|
|
1512
|
+
[N, N, G, N, N]
|
|
1513
|
+
] },
|
|
1514
|
+
smiley: { pixels: [
|
|
1515
|
+
[N, Y, Y, Y, N],
|
|
1516
|
+
[Y, K, Y, K, Y],
|
|
1517
|
+
[Y, Y, Y, Y, Y],
|
|
1518
|
+
[Y, K, Y, K, Y],
|
|
1519
|
+
[N, Y, Y, Y, N]
|
|
1520
|
+
] },
|
|
1521
|
+
pacman: { pixels: [
|
|
1522
|
+
[N, Y, Y, Y, N],
|
|
1523
|
+
[Y, Y, Y, N, N],
|
|
1524
|
+
[Y, Y, N, N, N],
|
|
1525
|
+
[Y, Y, Y, N, N],
|
|
1526
|
+
[N, Y, Y, Y, N]
|
|
1527
|
+
] }
|
|
1528
|
+
};
|
|
1529
|
+
var flipHorizontal = (pixels) => pixels.map((row) => [...row].reverse());
|
|
1530
|
+
var flipVertical = (pixels) => [...pixels].reverse();
|
|
1531
|
+
var rotate90 = (pixels) => {
|
|
1532
|
+
if (!pixels.length || !pixels[0]?.length) return pixels;
|
|
1533
|
+
const rows = pixels.length;
|
|
1534
|
+
const cols = pixels[0].length;
|
|
1535
|
+
return Array.from(
|
|
1536
|
+
{ length: cols },
|
|
1537
|
+
(_, c) => Array.from({ length: rows }, (__, r) => pixels[rows - 1 - r]?.[c] ?? null)
|
|
1538
|
+
);
|
|
1539
|
+
};
|
|
1540
|
+
var gradientRect = (opts = {}) => {
|
|
1541
|
+
const {
|
|
1542
|
+
width = 40,
|
|
1543
|
+
height = 10,
|
|
1544
|
+
colors = ["#ff0000", "#0000ff"],
|
|
1545
|
+
style = "horizontal"
|
|
1546
|
+
} = opts;
|
|
1547
|
+
const stops = colors.map(safeHex2).filter((c) => c !== null);
|
|
1548
|
+
if (stops.length < 2) throw new Error("gradientRect: at least 2 valid hex color stops required");
|
|
1549
|
+
const safeW = Math.max(2, width);
|
|
1550
|
+
const safeH = Math.max(2, height);
|
|
1551
|
+
const pixels = [];
|
|
1552
|
+
for (let row = 0; row < safeH; row++) {
|
|
1553
|
+
const line = [];
|
|
1554
|
+
for (let col = 0; col < safeW; col++) {
|
|
1555
|
+
let t;
|
|
1556
|
+
if (style === "horizontal") t = col / (safeW - 1);
|
|
1557
|
+
else if (style === "vertical") t = row / (safeH - 1);
|
|
1558
|
+
else if (style === "diagonal") t = (col + row) / (safeW + safeH - 2);
|
|
1559
|
+
else {
|
|
1560
|
+
const cx = safeW / 2, cy = safeH / 2;
|
|
1561
|
+
const dx = (col - cx) / cx;
|
|
1562
|
+
const dy = (row - cy) / cy;
|
|
1563
|
+
t = clamp(Math.sqrt(dx * dx + dy * dy) / Math.SQRT2, 0, 1);
|
|
1564
|
+
}
|
|
1565
|
+
const scaled = t * (stops.length - 1);
|
|
1566
|
+
const lo = Math.floor(scaled);
|
|
1567
|
+
const hi = Math.min(lo + 1, stops.length - 1);
|
|
1568
|
+
line.push(lerpColor(stops[lo], stops[hi], scaled - lo));
|
|
1569
|
+
}
|
|
1570
|
+
pixels.push(line);
|
|
1571
|
+
}
|
|
1572
|
+
return renderPixelArt(pixels, { scale: 1, halfBlock: true });
|
|
1573
|
+
};
|
|
1574
|
+
var createCanvas = (width, height, fillColor = null) => {
|
|
1575
|
+
const pixels = Array.from(
|
|
1576
|
+
{ length: height },
|
|
1577
|
+
() => Array.from({ length: width }, () => fillColor ? { ...fillColor } : null)
|
|
1578
|
+
);
|
|
1579
|
+
return {
|
|
1580
|
+
set(x, y, color2) {
|
|
1581
|
+
if (y >= 0 && y < height && x >= 0 && x < width) pixels[y][x] = color2;
|
|
1582
|
+
},
|
|
1583
|
+
get(x, y) {
|
|
1584
|
+
return pixels[y]?.[x] ?? null;
|
|
1585
|
+
},
|
|
1586
|
+
fill(color2) {
|
|
1587
|
+
for (let y = 0; y < height; y++)
|
|
1588
|
+
for (let x = 0; x < width; x++)
|
|
1589
|
+
pixels[y][x] = color2 ? { ...color2 } : null;
|
|
1590
|
+
},
|
|
1591
|
+
drawRect(x, y, w, h, color2, fill = false) {
|
|
1592
|
+
for (let dy = y; dy < y + h; dy++)
|
|
1593
|
+
for (let dx = x; dx < x + w; dx++)
|
|
1594
|
+
if (fill || dy === y || dy === y + h - 1 || dx === x || dx === x + w - 1)
|
|
1595
|
+
this.set(dx, dy, color2);
|
|
1596
|
+
},
|
|
1597
|
+
drawCircle(cx, cy, radius, color2, fill = false) {
|
|
1598
|
+
const r2 = radius * radius;
|
|
1599
|
+
for (let y = 0; y < height; y++)
|
|
1600
|
+
for (let x = 0; x < width; x++) {
|
|
1601
|
+
const dx = x - cx, dy = y - cy;
|
|
1602
|
+
const d2 = dx * dx + dy * dy;
|
|
1603
|
+
if (fill ? d2 <= r2 : Math.abs(Math.sqrt(d2) - radius) <= 0.7)
|
|
1604
|
+
this.set(x, y, color2);
|
|
1605
|
+
}
|
|
1606
|
+
},
|
|
1607
|
+
render(opts = {}) {
|
|
1608
|
+
return renderPixelArt(pixels, opts);
|
|
1609
|
+
},
|
|
1610
|
+
// Use write() instead of console.log for consistency with the I/O layer
|
|
1611
|
+
print(opts = {}) {
|
|
1612
|
+
write(this.render(opts) + "\n");
|
|
1613
|
+
},
|
|
1614
|
+
width,
|
|
1615
|
+
height,
|
|
1616
|
+
pixels
|
|
1617
|
+
};
|
|
1618
|
+
};
|
|
1619
|
+
var images = {
|
|
1620
|
+
render: renderPixelArt,
|
|
1621
|
+
sprites: SPRITES,
|
|
1622
|
+
flipHorizontal,
|
|
1623
|
+
flipVertical,
|
|
1624
|
+
rotate90,
|
|
1625
|
+
sprite(name, opts = {}) {
|
|
1626
|
+
const s = SPRITES[name];
|
|
1627
|
+
if (!s) throw new Error(`Sprite "${name}" not found. Available: ${Object.keys(SPRITES).join(", ")}`);
|
|
1628
|
+
return renderPixelArt(s.pixels, opts);
|
|
1629
|
+
},
|
|
1630
|
+
gradientRect,
|
|
1631
|
+
createCanvas
|
|
1632
|
+
};
|
|
1633
|
+
|
|
1634
|
+
// src/configure.ts
|
|
1635
|
+
var _config = {
|
|
1636
|
+
colorMode: "truecolor",
|
|
1637
|
+
animationSpeed: "normal",
|
|
1638
|
+
asciiFont: "big",
|
|
1639
|
+
locale: "es",
|
|
1640
|
+
theme: "dracula"
|
|
1641
|
+
};
|
|
1642
|
+
var SPEED_MAP = {
|
|
1643
|
+
slow: 2,
|
|
1644
|
+
normal: 1,
|
|
1645
|
+
fast: 0.4
|
|
1646
|
+
};
|
|
1647
|
+
var configure = (opts = {}) => {
|
|
1648
|
+
Object.assign(_config, opts);
|
|
1649
|
+
};
|
|
1650
|
+
var getConfig = () => ({ ..._config });
|
|
1651
|
+
var getSpeedMultiplier = () => SPEED_MAP[_config.animationSpeed] ?? 1;
|
|
1652
|
+
|
|
1653
|
+
// src/index.ts
|
|
1654
|
+
var ansimax = { color, animate, ascii, loader, frames, components, themes, images, configure };
|
|
1655
|
+
var index_default = ansimax;
|
|
1656
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1657
|
+
0 && (module.exports = {
|
|
1658
|
+
SPINNERS,
|
|
1659
|
+
SPRITES,
|
|
1660
|
+
animate,
|
|
1661
|
+
ascii,
|
|
1662
|
+
bgRgb,
|
|
1663
|
+
center,
|
|
1664
|
+
clamp,
|
|
1665
|
+
color,
|
|
1666
|
+
colorPresets,
|
|
1667
|
+
components,
|
|
1668
|
+
compose,
|
|
1669
|
+
configure,
|
|
1670
|
+
createCanvas,
|
|
1671
|
+
cursor,
|
|
1672
|
+
fgRgb,
|
|
1673
|
+
frames,
|
|
1674
|
+
getConfig,
|
|
1675
|
+
getSpeedMultiplier,
|
|
1676
|
+
gradient,
|
|
1677
|
+
gradientRect,
|
|
1678
|
+
hexToRgb,
|
|
1679
|
+
images,
|
|
1680
|
+
isHexColor,
|
|
1681
|
+
isNoColor,
|
|
1682
|
+
lerp,
|
|
1683
|
+
lerpColor,
|
|
1684
|
+
loader,
|
|
1685
|
+
padEnd,
|
|
1686
|
+
padStart,
|
|
1687
|
+
rainbow,
|
|
1688
|
+
renderPixelArt,
|
|
1689
|
+
repeatVisible,
|
|
1690
|
+
reset,
|
|
1691
|
+
resetNoColor,
|
|
1692
|
+
rgbTo256,
|
|
1693
|
+
rgbToHex,
|
|
1694
|
+
screen,
|
|
1695
|
+
setNoColor,
|
|
1696
|
+
sgr,
|
|
1697
|
+
sleep,
|
|
1698
|
+
stripAnsi,
|
|
1699
|
+
supportsColor,
|
|
1700
|
+
termSize,
|
|
1701
|
+
themes,
|
|
1702
|
+
truncateAnsi,
|
|
1703
|
+
visibleLen,
|
|
1704
|
+
wordWrap,
|
|
1705
|
+
write,
|
|
1706
|
+
writeln
|
|
1707
|
+
});
|