style-logs 0.0.1 → 0.0.3

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/dist/index.js CHANGED
@@ -17,83 +17,599 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- log: () => log
20
+ // Structure/index.ts
21
+ var Structure_exports = {};
22
+ __export(Structure_exports, {
23
+ animate: () => animate,
24
+ log: () => log,
25
+ style: () => style
24
26
  });
25
- module.exports = __toCommonJS(src_exports);
27
+ module.exports = __toCommonJS(Structure_exports);
26
28
 
27
- // src/console.ts
28
- var import_common_tags = require("common-tags");
29
- var style = {
30
- reset: "\x1B[0m",
31
- styles: {
32
- bold: "\x1B[1m",
33
- dim: "\x1B[2m",
34
- underline: "\x1B[4m",
35
- inverse: "\x1B[7m",
36
- hidden: "\x1B[8m"
37
- },
38
- fg: {
39
- black: "\x1B[30m",
40
- red: "\x1B[31m",
41
- green: "\x1B[32m",
42
- yellow: "\x1B[33m",
43
- blue: "\x1B[34m",
44
- magenta: "\x1B[35m",
45
- cyan: "\x1B[36m",
46
- white: "\x1B[37m",
47
- crimson: "\x1B[38m",
48
- orange: "\x1B[38;5;208m",
49
- teal: "\x1B[38;5;6m"
50
- },
51
- bg: {
52
- black: "\x1B[40m",
53
- red: "\x1B[41m",
54
- green: "\x1B[42m",
55
- yellow: "\x1B[43m",
56
- blue: "\x1B[44m",
57
- magenta: "\x1B[45m",
58
- cyan: "\x1B[46m",
59
- white: "\x1B[47m",
60
- crimson: "\x1B[48m",
61
- orange: "\x1B[48;5;208m",
62
- teal: "\x1B[48;5;6m"
29
+ // Structure/ansi.ts
30
+ var ESC = "\x1B[";
31
+ var RESET = `${ESC}0m`;
32
+ var STYLES = {
33
+ bold: `${ESC}1m`,
34
+ dim: `${ESC}2m`,
35
+ italic: `${ESC}3m`,
36
+ underline: `${ESC}4m`,
37
+ inverse: `${ESC}7m`,
38
+ hidden: `${ESC}8m`,
39
+ strikethrough: `${ESC}9m`
40
+ };
41
+ var COLORS = {
42
+ black: `${ESC}30m`,
43
+ red: `${ESC}31m`,
44
+ green: `${ESC}32m`,
45
+ yellow: `${ESC}33m`,
46
+ blue: `${ESC}34m`,
47
+ magenta: `${ESC}35m`,
48
+ cyan: `${ESC}36m`,
49
+ white: `${ESC}37m`,
50
+ gray: `${ESC}90m`
51
+ };
52
+ var BG_COLORS = {
53
+ black: `${ESC}40m`,
54
+ red: `${ESC}41m`,
55
+ green: `${ESC}42m`,
56
+ yellow: `${ESC}43m`,
57
+ blue: `${ESC}44m`,
58
+ magenta: `${ESC}45m`,
59
+ cyan: `${ESC}46m`,
60
+ white: `${ESC}47m`,
61
+ gray: `${ESC}100m`
62
+ };
63
+ function hexToRgb(hex) {
64
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
65
+ return result ? [
66
+ parseInt(result[1], 16),
67
+ parseInt(result[2], 16),
68
+ parseInt(result[3], 16)
69
+ ] : null;
70
+ }
71
+ function rgbToAnsi(r, g, b, isBg = false) {
72
+ return `${ESC}${isBg ? 48 : 38};2;${r};${g};${b}m`;
73
+ }
74
+ function stripAnsi(str) {
75
+ return str.replace(/\x1b\[[0-9;]*m/g, "");
76
+ }
77
+ function toHyperlink(url, text) {
78
+ return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
79
+ }
80
+ function lerp(start, end, t) {
81
+ return start + (end - start) * t;
82
+ }
83
+ function interpolateColor(c1, c2, t) {
84
+ return [
85
+ Math.round(lerp(c1[0], c2[0], t)),
86
+ Math.round(lerp(c1[1], c2[1], t)),
87
+ Math.round(lerp(c1[2], c2[2], t))
88
+ ];
89
+ }
90
+ function sliceAnsi(str, length) {
91
+ let visible = 0;
92
+ let i = 0;
93
+ let inAnsi = false;
94
+ while (i < str.length) {
95
+ if (visible >= length && !inAnsi && str[i] !== "\x1B") break;
96
+ const char = str[i];
97
+ if (char === "\x1B") {
98
+ inAnsi = true;
99
+ } else if (inAnsi && char === "m") {
100
+ inAnsi = false;
101
+ } else if (!inAnsi) {
102
+ visible++;
103
+ }
104
+ i++;
105
+ }
106
+ return str.substring(0, i) + RESET;
107
+ }
108
+ function getStandardColorRgb(name) {
109
+ const map = {
110
+ black: [0, 0, 0],
111
+ red: [205, 49, 49],
112
+ green: [13, 188, 121],
113
+ yellow: [229, 229, 16],
114
+ blue: [36, 114, 200],
115
+ magenta: [188, 63, 188],
116
+ cyan: [17, 168, 205],
117
+ white: [229, 229, 229],
118
+ gray: [102, 102, 102]
119
+ };
120
+ return map[name] || null;
121
+ }
122
+
123
+ // Structure/parser.ts
124
+ function parse(input) {
125
+ const root = { type: "block", children: [], styles: {} };
126
+ const stack = [root];
127
+ let current = 0;
128
+ while (current < input.length) {
129
+ const char = input[current];
130
+ if (char === "{") {
131
+ if (current > 0 && input[current - 1] === "\\") {
132
+ const last = stack[stack.length - 1].children[stack[stack.length - 1].children.length - 1];
133
+ if (last && last.type === "text") {
134
+ last.content += "{";
135
+ } else {
136
+ stack[stack.length - 1].children.push({ type: "text", content: "{" });
137
+ }
138
+ current++;
139
+ continue;
140
+ }
141
+ const endStyle = input.indexOf("}", current);
142
+ if (endStyle === -1) {
143
+ const last = stack[stack.length - 1].children[stack[stack.length - 1].children.length - 1];
144
+ if (last && last.type === "text") {
145
+ last.content += "{";
146
+ } else {
147
+ stack[stack.length - 1].children.push({ type: "text", content: "{" });
148
+ }
149
+ current++;
150
+ continue;
151
+ }
152
+ const styleStr = input.substring(current + 1, endStyle);
153
+ if (styleStr === "/") {
154
+ if (stack.length > 1) {
155
+ stack.pop();
156
+ }
157
+ current = endStyle + 1;
158
+ continue;
159
+ }
160
+ const styles = parseStyles(styleStr);
161
+ const newNode = { type: "block", styles, children: [] };
162
+ stack[stack.length - 1].children.push(newNode);
163
+ stack.push(newNode);
164
+ current = endStyle + 1;
165
+ } else {
166
+ let nextTag = input.indexOf("{", current);
167
+ if (nextTag === -1) nextTag = input.length;
168
+ while (nextTag > 0 && input[nextTag - 1] === "\\") {
169
+ const nextRealTag = input.indexOf("{", nextTag + 1);
170
+ if (nextRealTag === -1) {
171
+ nextTag = input.length;
172
+ break;
173
+ }
174
+ nextTag = nextRealTag;
175
+ }
176
+ let text = input.substring(current, nextTag);
177
+ text = text.replace(/\\{/g, "{");
178
+ if (text) {
179
+ stack[stack.length - 1].children.push({ type: "text", content: text });
180
+ }
181
+ current = nextTag;
182
+ }
183
+ }
184
+ return root.children || [];
185
+ }
186
+ function parseStyles(styleStr) {
187
+ const styles = {};
188
+ const parts = styleStr.split(";").map((s) => s.trim()).filter((s) => s);
189
+ for (const part of parts) {
190
+ if (part.includes(":")) {
191
+ let key, val;
192
+ if (part.startsWith("link:")) {
193
+ key = "link";
194
+ val = part.substring(5).trim();
195
+ } else {
196
+ [key, val] = part.split(":").map((s) => s.trim());
197
+ }
198
+ if (key === "color") styles.color = val;
199
+ if (key === "bg") styles.bg = val;
200
+ if (key === "link") styles.link = val;
201
+ if (key === "badge") styles.badge = val;
202
+ if (key === "border") styles.border = val;
203
+ if (key === "gradient") {
204
+ styles.gradient = val.split(",").map((s) => s.trim());
205
+ }
206
+ } else {
207
+ if (part === "bold") styles.bold = true;
208
+ if (part === "dim") styles.dim = true;
209
+ if (part === "italic") styles.italic = true;
210
+ if (part === "underline") styles.underline = true;
211
+ if (part === "inverse") styles.inverse = true;
212
+ if (part === "hidden") styles.hidden = true;
213
+ if (part === "strikethrough") styles.strikethrough = true;
214
+ if (part === "rainbow") styles.rainbow = true;
215
+ if (part === "border" || part === "box") styles.border = true;
216
+ }
217
+ }
218
+ return styles;
219
+ }
220
+ function render(nodes, parentStyles = {}, options = {}) {
221
+ let output = "";
222
+ for (const node of nodes) {
223
+ if (node.type === "text") {
224
+ output += applyStyles(node.content, parentStyles);
225
+ } else if (node.type === "block") {
226
+ const mergedStyles = { ...parentStyles, ...node.styles };
227
+ let content = "";
228
+ if (mergedStyles.gradient || mergedStyles.rainbow) {
229
+ const textContent = getTextContent(node.children || []);
230
+ content = applyGradient(textContent, mergedStyles, options);
231
+ } else {
232
+ content = render(node.children || [], mergedStyles, options);
233
+ }
234
+ if (mergedStyles.border) {
235
+ content = applyBorder(content, mergedStyles.border);
236
+ }
237
+ output += content;
238
+ }
239
+ }
240
+ return output;
241
+ }
242
+ function getTextContent(nodes) {
243
+ let text = "";
244
+ for (const node of nodes) {
245
+ if (node.type === "text") text += node.content;
246
+ else if (node.type === "block") text += getTextContent(node.children || []);
247
+ }
248
+ return text;
249
+ }
250
+ function applyStyles(text, styles) {
251
+ let start = "";
252
+ let end = RESET;
253
+ if (styles.bold) start += STYLES.bold;
254
+ if (styles.dim) start += STYLES.dim;
255
+ if (styles.italic) start += STYLES.italic;
256
+ if (styles.underline) start += STYLES.underline;
257
+ if (styles.inverse) start += STYLES.inverse;
258
+ if (styles.hidden) start += STYLES.hidden;
259
+ if (styles.strikethrough) start += STYLES.strikethrough;
260
+ if (styles.badge) {
261
+ const badgeStyles = getBadgeStyles(styles.badge);
262
+ if (badgeStyles.bg) start += badgeStyles.bg;
263
+ if (badgeStyles.color) start += badgeStyles.color;
264
+ text = ` ${text} `;
265
+ }
266
+ if (styles.color && !styles.badge) {
267
+ if (COLORS[styles.color]) start += COLORS[styles.color];
268
+ else {
269
+ const rgb = hexToRgb(styles.color);
270
+ if (rgb) start += rgbToAnsi(rgb[0], rgb[1], rgb[2]);
271
+ }
272
+ }
273
+ if (styles.bg && !styles.badge) {
274
+ if (BG_COLORS[styles.bg]) start += BG_COLORS[styles.bg];
275
+ else {
276
+ const rgb = hexToRgb(styles.bg);
277
+ if (rgb) start += rgbToAnsi(rgb[0], rgb[1], rgb[2], true);
278
+ }
279
+ }
280
+ if (styles.link) {
281
+ return start + toHyperlink(styles.link, text) + end;
282
+ }
283
+ return start + text + end;
284
+ }
285
+ function applyGradient(text, styles, options = {}) {
286
+ if (styles.rainbow) {
287
+ return applyRainbow(text, styles, options);
288
+ }
289
+ if (!styles.gradient || styles.gradient.length < 2) return text;
290
+ const startColorName = styles.gradient[0];
291
+ const endColorName = styles.gradient[1];
292
+ let c1 = hexToRgb(startColorName);
293
+ if (!c1 && COLORS[startColorName]) {
294
+ c1 = getStandardColorRgb(startColorName);
295
+ }
296
+ let c2 = hexToRgb(endColorName);
297
+ if (!c2 && COLORS[endColorName]) {
298
+ c2 = getStandardColorRgb(endColorName);
299
+ }
300
+ if (!c1 || !c2) return text;
301
+ let output = "";
302
+ const len = text.length;
303
+ const offset = options.gradientOffset || 0;
304
+ for (let i = 0; i < len; i++) {
305
+ const t = (Math.sin((i / (len || 1) + offset) * Math.PI * 2) + 1) / 2;
306
+ const [r, g, b] = interpolateColor(c1, c2, t);
307
+ let charStyle = "";
308
+ if (styles.bold) charStyle += STYLES.bold;
309
+ charStyle += rgbToAnsi(r, g, b);
310
+ output += charStyle + text[i];
63
311
  }
312
+ return output + RESET;
313
+ }
314
+ function applyRainbow(text, styles, options = {}) {
315
+ const rainbowColors = [
316
+ [255, 0, 0],
317
+ // Red
318
+ [255, 127, 0],
319
+ // Orange
320
+ [255, 255, 0],
321
+ // Yellow
322
+ [0, 255, 0],
323
+ // Green
324
+ [0, 0, 255],
325
+ // Blue
326
+ [75, 0, 130],
327
+ // Indigo
328
+ [148, 0, 211]
329
+ // Violet
330
+ ];
331
+ let output = "";
332
+ const len = text.length;
333
+ const offset = options.rainbowOffset || 0;
334
+ for (let i = 0; i < len; i++) {
335
+ const t = (i + offset) / (len || 1) * (rainbowColors.length - 1);
336
+ const wrappedT = t % (rainbowColors.length - 1);
337
+ const index = Math.floor(wrappedT);
338
+ const nextIndex = (index + 1) % rainbowColors.length;
339
+ const factor = wrappedT - index;
340
+ const c1 = rainbowColors[index];
341
+ const c2 = rainbowColors[nextIndex];
342
+ const [r, g, b] = interpolateColor(c1, c2, factor);
343
+ let charStyle = "";
344
+ if (styles.bold) charStyle += STYLES.bold;
345
+ if (styles.italic) charStyle += STYLES.italic;
346
+ if (styles.underline) charStyle += STYLES.underline;
347
+ charStyle += rgbToAnsi(r, g, b);
348
+ output += charStyle + text[i];
349
+ }
350
+ return output + RESET;
351
+ }
352
+ function getBadgeStyles(type) {
353
+ const map = {
354
+ info: { bg: BG_COLORS.blue, color: COLORS.white },
355
+ success: { bg: BG_COLORS.green, color: COLORS.black },
356
+ warning: { bg: BG_COLORS.yellow, color: COLORS.black },
357
+ error: { bg: BG_COLORS.red, color: COLORS.white }
358
+ };
359
+ return map[type] || { bg: BG_COLORS.gray, color: COLORS.white };
360
+ }
361
+ function applyBorder(content, style2) {
362
+ const lines = content.split("\n");
363
+ const cleanLines = lines.map((l) => stripAnsi(l));
364
+ const maxWidth = Math.max(...cleanLines.map((l) => l.length));
365
+ const color = typeof style2 === "string" && COLORS[style2] ? COLORS[style2] : "";
366
+ const reset = typeof style2 === "string" && COLORS[style2] ? RESET : "";
367
+ const top = "\u250C" + "\u2500".repeat(maxWidth + 2) + "\u2510";
368
+ const bottom = "\u2514" + "\u2500".repeat(maxWidth + 2) + "\u2518";
369
+ let output = "\n" + color + top + reset + "\n";
370
+ for (let i = 0; i < lines.length; i++) {
371
+ const line = lines[i];
372
+ const clean = cleanLines[i];
373
+ const padding = " ".repeat(maxWidth - clean.length);
374
+ output += color + "\u2502 " + reset + line + padding + color + " \u2502" + reset + "\n";
375
+ }
376
+ output += color + bottom + reset + "\n";
377
+ return output;
378
+ }
379
+
380
+ // Structure/animation.ts
381
+ var SPINNERS = {
382
+ line: ["|", "/", "-", "\\"],
383
+ circle: ["\u25DC", "\u25E0", "\u25DD", "\u25DE", "\u25E1", "\u25DF"],
384
+ dots: [".", "..", "..."],
385
+ bounce: ["\u2801", "\u2802", "\u2804", "\u2802"],
386
+ spin: ["\u283F", "\u2837", "\u282F", "\u281F", "\u283B"],
387
+ pulse: ["\u25CF\u25CB\u25CB", "\u25CB\u25CF\u25CB", "\u25CB\u25CB\u25CF", "\u25CB\u25CF\u25CB"],
388
+ quarter: ["\u25D0", "\u25D3", "\u25D1", "\u25D2"],
389
+ clock: ["\u25F4", "\u25F7", "\u25F6", "\u25F5"],
390
+ square: ["\u2B12", "\u2B14", "\u2B13", "\u2B15"],
391
+ bar: ["\u25B1\u25B1\u25B1", "\u25B0\u25B1\u25B1", "\u25B0\u25B0\u25B1", "\u25B0\u25B0\u25B0"],
392
+ hourglass: ["\u29D6", "\u29D7"]
64
393
  };
65
- var log = (text) => {
66
- const regex = /<text\s*(.*?)>(.*?)<\/text>/gs;
67
- let result = "";
68
- const lines = (0, import_common_tags.stripIndents)(text).split("\n");
69
- lines.forEach((line) => {
70
- let processedLine = line;
71
- let match;
72
- while ((match = regex.exec(line)) !== null) {
73
- const attributes = match[1].trim();
74
- const content = match[2];
75
- let colorCode = style.reset;
76
- if (attributes) {
77
- const attributeRegex = /(f|b|s)-(\w+)/g;
78
- let attrMatch;
79
- while ((attrMatch = attributeRegex.exec(attributes)) !== null) {
80
- const [, type, styleName] = attrMatch;
81
- if (type === "f" && style.fg[styleName]) {
82
- colorCode += style.fg[styleName];
83
- } else if (type === "b" && style.bg[styleName]) {
84
- colorCode += style.bg[styleName];
85
- } else if (type === "s" && style.styles[styleName]) {
86
- colorCode += style.styles[styleName];
394
+ var animate = {
395
+ typewriter: (text, speedOrOptions = 30) => {
396
+ const options = typeof speedOrOptions === "number" ? { speed: speedOrOptions } : speedOrOptions;
397
+ const speed = options.speed || 30;
398
+ const loop = options.loop || false;
399
+ const styled = style(text);
400
+ const plain = stripAnsi(styled);
401
+ const len = plain.length;
402
+ let interval;
403
+ let stopped = false;
404
+ const promise = new Promise((resolve) => {
405
+ const start = () => {
406
+ let i = 0;
407
+ interval = setInterval(() => {
408
+ if (stopped) {
409
+ clearInterval(interval);
410
+ resolve();
411
+ return;
412
+ }
413
+ i++;
414
+ process.stdout.write("\r" + sliceAnsi(styled, i));
415
+ if (i >= len) {
416
+ if (loop) {
417
+ clearInterval(interval);
418
+ setTimeout(() => {
419
+ if (!stopped) {
420
+ process.stdout.write("\r\x1B[2K");
421
+ start();
422
+ } else {
423
+ resolve();
424
+ }
425
+ }, 1e3);
426
+ } else {
427
+ clearInterval(interval);
428
+ process.stdout.write("\n");
429
+ resolve();
430
+ }
87
431
  }
432
+ }, speed);
433
+ };
434
+ start();
435
+ });
436
+ promise.stop = () => {
437
+ stopped = true;
438
+ if (interval) clearInterval(interval);
439
+ };
440
+ return promise;
441
+ },
442
+ gradient: (text, durationOrOptions = 2e3) => {
443
+ const options = typeof durationOrOptions === "number" ? { duration: durationOrOptions } : durationOrOptions;
444
+ const duration = options.duration || 2e3;
445
+ const loop = options.loop || false;
446
+ let input = text;
447
+ if (!text.includes("{gradient")) {
448
+ input = `{gradient: red, blue}${text}{/}`;
449
+ }
450
+ const astToRender = parse(input);
451
+ let offset = 0;
452
+ const startTime = Date.now();
453
+ let interval;
454
+ let stopped = false;
455
+ const promise = new Promise((resolve) => {
456
+ interval = setInterval(() => {
457
+ if (stopped) {
458
+ clearInterval(interval);
459
+ process.stdout.write("\n");
460
+ resolve();
461
+ return;
462
+ }
463
+ const elapsed = Date.now() - startTime;
464
+ if (!loop && elapsed > duration) {
465
+ clearInterval(interval);
466
+ process.stdout.write("\n");
467
+ resolve();
468
+ return;
469
+ }
470
+ offset += 0.02;
471
+ const output = render(astToRender, {}, { gradientOffset: offset });
472
+ process.stdout.write("\r" + output);
473
+ }, 50);
474
+ });
475
+ promise.stop = () => {
476
+ stopped = true;
477
+ };
478
+ return promise;
479
+ },
480
+ glitch: (text, durationOrOptions = 2e3) => {
481
+ const options = typeof durationOrOptions === "number" ? { duration: durationOrOptions } : durationOrOptions;
482
+ const duration = options.duration || 2e3;
483
+ const loop = options.loop || false;
484
+ const styled = style(text);
485
+ const plain = stripAnsi(styled);
486
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()";
487
+ const len = plain.length;
488
+ const startTime = Date.now();
489
+ let interval;
490
+ let stopped = false;
491
+ const promise = new Promise((resolve) => {
492
+ interval = setInterval(() => {
493
+ if (stopped) {
494
+ clearInterval(interval);
495
+ process.stdout.write("\r" + styled + "\n");
496
+ resolve();
497
+ return;
498
+ }
499
+ const elapsed = Date.now() - startTime;
500
+ if (!loop && elapsed > duration) {
501
+ clearInterval(interval);
502
+ process.stdout.write("\r" + styled + "\n");
503
+ resolve();
504
+ return;
505
+ }
506
+ let glitchText = "";
507
+ for (let i = 0; i < len; i++) {
508
+ if (Math.random() > 0.5 || plain[i] === " ") {
509
+ glitchText += plain[i];
510
+ } else {
511
+ glitchText += chars[Math.floor(Math.random() * chars.length)];
512
+ }
513
+ }
514
+ process.stdout.write("\r" + glitchText);
515
+ }, 50);
516
+ });
517
+ promise.stop = () => {
518
+ stopped = true;
519
+ };
520
+ return promise;
521
+ },
522
+ thinking: (text, durationOrPromise = 2e3, colorOrOptions = "cyan") => {
523
+ let color = "cyan";
524
+ let frames = SPINNERS.circle;
525
+ if (typeof colorOrOptions === "string") {
526
+ color = colorOrOptions;
527
+ } else {
528
+ color = colorOrOptions.color || color;
529
+ if (colorOrOptions.frames) {
530
+ if (Array.isArray(colorOrOptions.frames)) {
531
+ frames = colorOrOptions.frames;
532
+ } else if (typeof colorOrOptions.frames === "string" && SPINNERS[colorOrOptions.frames]) {
533
+ frames = SPINNERS[colorOrOptions.frames];
88
534
  }
89
535
  }
90
- processedLine = processedLine.replace(match[0], `${colorCode}${content}${style.reset}`);
91
536
  }
92
- result += processedLine + "\n";
93
- });
94
- console.log(result.trim());
537
+ let frameIndex = 0;
538
+ const styled = style(text);
539
+ let interval;
540
+ return new Promise((resolve) => {
541
+ interval = setInterval(() => {
542
+ const frame = frames[frameIndex = (frameIndex + 1) % frames.length];
543
+ process.stdout.write("\r" + style(`{color: ${color}}${frame}{/} `) + styled);
544
+ }, 80);
545
+ if (typeof durationOrPromise === "number") {
546
+ setTimeout(() => {
547
+ clearInterval(interval);
548
+ process.stdout.write("\r\x1B[2K");
549
+ resolve();
550
+ }, durationOrPromise);
551
+ } else {
552
+ durationOrPromise.then(() => {
553
+ clearInterval(interval);
554
+ process.stdout.write("\r\x1B[2K");
555
+ resolve();
556
+ });
557
+ }
558
+ });
559
+ },
560
+ stream: (text, minSpeed = 10, maxSpeed = 50) => {
561
+ const styled = style(text);
562
+ const plain = stripAnsi(styled);
563
+ const len = plain.length;
564
+ let stopped = false;
565
+ let timeout;
566
+ const promise = new Promise((resolve) => {
567
+ let i = 0;
568
+ const nextChar = () => {
569
+ if (stopped) {
570
+ process.stdout.write("\n");
571
+ resolve();
572
+ return;
573
+ }
574
+ i++;
575
+ process.stdout.write("\r" + sliceAnsi(styled, i));
576
+ if (i >= len) {
577
+ process.stdout.write("\n");
578
+ resolve();
579
+ } else {
580
+ const delay = Math.floor(Math.random() * (maxSpeed - minSpeed + 1)) + minSpeed;
581
+ timeout = setTimeout(nextChar, delay);
582
+ }
583
+ };
584
+ nextChar();
585
+ });
586
+ promise.stop = () => {
587
+ stopped = true;
588
+ if (timeout) clearTimeout(timeout);
589
+ };
590
+ return promise;
591
+ }
95
592
  };
593
+
594
+ // Structure/index.ts
595
+ function style(input) {
596
+ const ast = parse(input);
597
+ return render(ast);
598
+ }
599
+ function log(args, ...values) {
600
+ if (typeof args === "string") {
601
+ console.log(style(args));
602
+ } else {
603
+ let input = "";
604
+ args.forEach((str, i) => {
605
+ input += str + (values[i] !== void 0 ? values[i] : "");
606
+ });
607
+ console.log(style(input));
608
+ }
609
+ }
96
610
  // Annotate the CommonJS export names for ESM import in node:
97
611
  0 && (module.exports = {
98
- log
612
+ animate,
613
+ log,
614
+ style
99
615
  });