chalk-ts 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.
@@ -0,0 +1,807 @@
1
+ /**
2
+ * ANSI color and style codes
3
+ */
4
+ const ANSI_CODES = {
5
+ // Reset
6
+ reset: '\u001B[0m',
7
+ // Text styles
8
+ bold: '\u001B[1m',
9
+ dim: '\u001B[2m',
10
+ italic: '\u001B[3m',
11
+ underline: '\u001B[4m',
12
+ blink: '\u001B[5m',
13
+ inverse: '\u001B[7m',
14
+ hidden: '\u001B[8m',
15
+ strikethrough: '\u001B[9m',
16
+ // Foreground colors
17
+ black: '\u001B[30m',
18
+ red: '\u001B[31m',
19
+ green: '\u001B[32m',
20
+ yellow: '\u001B[33m',
21
+ blue: '\u001B[34m',
22
+ magenta: '\u001B[35m',
23
+ cyan: '\u001B[36m',
24
+ white: '\u001B[37m',
25
+ gray: '\u001B[90m',
26
+ grey: '\u001B[90m',
27
+ // Bright foreground colors
28
+ redBright: '\u001B[91m',
29
+ greenBright: '\u001B[92m',
30
+ yellowBright: '\u001B[93m',
31
+ blueBright: '\u001B[94m',
32
+ magentaBright: '\u001B[95m',
33
+ cyanBright: '\u001B[96m',
34
+ whiteBright: '\u001B[97m',
35
+ // Background colors
36
+ bgBlack: '\u001B[40m',
37
+ bgRed: '\u001B[41m',
38
+ bgGreen: '\u001B[42m',
39
+ bgYellow: '\u001B[43m',
40
+ bgBlue: '\u001B[44m',
41
+ bgMagenta: '\u001B[45m',
42
+ bgCyan: '\u001B[46m',
43
+ bgWhite: '\u001B[47m',
44
+ bgGray: '\u001B[100m',
45
+ bgGrey: '\u001B[100m',
46
+ // Bright background colors
47
+ bgRedBright: '\u001B[101m',
48
+ bgGreenBright: '\u001B[102m',
49
+ bgYellowBright: '\u001B[103m',
50
+ bgBlueBright: '\u001B[104m',
51
+ bgMagentaBright: '\u001B[105m',
52
+ bgCyanBright: '\u001B[106m',
53
+ bgWhiteBright: '\u001B[107m',
54
+ };
55
+ /**
56
+ * Check if colors are supported in the current environment
57
+ */
58
+ function supportsColor() {
59
+ if (typeof process === 'undefined')
60
+ return false;
61
+ const { env, platform, stdout } = process;
62
+ // Force color support
63
+ if (env.FORCE_COLOR === '1' || env.FORCE_COLOR === 'true')
64
+ return true;
65
+ if (env.FORCE_COLOR === '0' || env.FORCE_COLOR === 'false')
66
+ return false;
67
+ // No color support
68
+ if (env.NO_COLOR || env.NODE_DISABLE_COLORS)
69
+ return false;
70
+ // CI environments
71
+ if (env.CI && !env.GITHUB_ACTIONS)
72
+ return false;
73
+ // Terminal capabilities
74
+ if (platform === 'win32') {
75
+ return !!(env.TERM && env.TERM !== 'dumb');
76
+ }
77
+ if (!stdout || !stdout.isTTY)
78
+ return false;
79
+ const term = env.TERM?.toLowerCase();
80
+ if (term === 'dumb')
81
+ return false;
82
+ return !!(term &&
83
+ (term.includes('color') ||
84
+ term.includes('256') ||
85
+ term.includes('ansi') ||
86
+ term === 'xterm' ||
87
+ term === 'screen' ||
88
+ term === 'vt100' ||
89
+ env.COLORTERM));
90
+ }
91
+ /**
92
+ * Get color level support (0: no color, 1: basic, 2: 256 colors, 3: 16m colors)
93
+ */
94
+ function getColorLevel() {
95
+ if (!supportsColor())
96
+ return 0;
97
+ const { env } = process;
98
+ if (env.COLORTERM === 'truecolor' || env.TERM === 'xterm-256color')
99
+ return 3;
100
+ if (env.TERM?.includes('256'))
101
+ return 2;
102
+ return 1;
103
+ }
104
+
105
+ /**
106
+ * Color utilities for RGB, HSL, and HEX conversions
107
+ */
108
+ /**
109
+ * Convert HEX color to RGB
110
+ */
111
+ function hexToRgb(hex) {
112
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
113
+ return result && result.length >= 4
114
+ ? {
115
+ r: parseInt(result[1], 16),
116
+ g: parseInt(result[2], 16),
117
+ b: parseInt(result[3], 16),
118
+ }
119
+ : null;
120
+ }
121
+ /**
122
+ * Convert RGB to HEX
123
+ */
124
+ function rgbToHex(r, g, b) {
125
+ const toHex = (c) => {
126
+ const hex = Math.round(Math.max(0, Math.min(255, c))).toString(16);
127
+ return hex.length === 1 ? "0" + hex : hex;
128
+ };
129
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
130
+ }
131
+ /**
132
+ * Convert HSL to RGB
133
+ */
134
+ function hslToRgb(h, s, l) {
135
+ h = h / 360;
136
+ s = s / 100;
137
+ l = l / 100;
138
+ const hue2rgb = (p, q, t) => {
139
+ if (t < 0)
140
+ t += 1;
141
+ if (t > 1)
142
+ t -= 1;
143
+ if (t < 1 / 6)
144
+ return p + (q - p) * 6 * t;
145
+ if (t < 1 / 2)
146
+ return q;
147
+ if (t < 2 / 3)
148
+ return p + (q - p) * (2 / 3 - t) * 6;
149
+ return p;
150
+ };
151
+ let r, g, b;
152
+ if (s === 0) {
153
+ r = g = b = l;
154
+ }
155
+ else {
156
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
157
+ const p = 2 * l - q;
158
+ r = hue2rgb(p, q, h + 1 / 3);
159
+ g = hue2rgb(p, q, h);
160
+ b = hue2rgb(p, q, h - 1 / 3);
161
+ }
162
+ return {
163
+ r: Math.round(r * 255),
164
+ g: Math.round(g * 255),
165
+ b: Math.round(b * 255),
166
+ };
167
+ }
168
+ /**
169
+ * Convert RGB to HSL
170
+ */
171
+ function rgbToHsl(r, g, b) {
172
+ r /= 255;
173
+ g /= 255;
174
+ b /= 255;
175
+ const max = Math.max(r, g, b);
176
+ const min = Math.min(r, g, b);
177
+ let h = 0;
178
+ let s = 0;
179
+ const l = (max + min) / 2;
180
+ if (max === min) {
181
+ h = s = 0; // achromatic
182
+ }
183
+ else {
184
+ const d = max - min;
185
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
186
+ switch (max) {
187
+ case r:
188
+ h = (g - b) / d + (g < b ? 6 : 0);
189
+ break;
190
+ case g:
191
+ h = (b - r) / d + 2;
192
+ break;
193
+ case b:
194
+ h = (r - g) / d + 4;
195
+ break;
196
+ }
197
+ h /= 6;
198
+ }
199
+ return {
200
+ h: Math.round(h * 360),
201
+ s: Math.round(s * 100),
202
+ l: Math.round(l * 100),
203
+ };
204
+ }
205
+ /**
206
+ * Generate RGB ANSI escape code
207
+ */
208
+ function rgb(r, g, b, background = false) {
209
+ const prefix = background ? "48" : "38";
210
+ return `\u001B[${prefix};2;${Math.round(r)};${Math.round(g)};${Math.round(b)}m`;
211
+ }
212
+ /**
213
+ * Generate HEX ANSI escape code
214
+ */
215
+ function hex(color, background = false) {
216
+ const rgbColor = hexToRgb(color);
217
+ if (!rgbColor)
218
+ throw new Error(`Invalid hex color: ${color}`);
219
+ return rgb(rgbColor.r, rgbColor.g, rgbColor.b, background);
220
+ }
221
+ /**
222
+ * Generate HSL ANSI escape code
223
+ */
224
+ function hsl(h, s, l, background = false) {
225
+ const rgbColor = hslToRgb(h, s, l);
226
+ return rgb(rgbColor.r, rgbColor.g, rgbColor.b, background);
227
+ }
228
+ /**
229
+ * Predefined color palette
230
+ */
231
+ const COLORS = {
232
+ // Standard colors
233
+ black: { r: 0, g: 0, b: 0 },
234
+ red: { r: 255, g: 0, b: 0 },
235
+ green: { r: 0, g: 255, b: 0 },
236
+ yellow: { r: 255, g: 255, b: 0 },
237
+ blue: { r: 0, g: 0, b: 255 },
238
+ magenta: { r: 255, g: 0, b: 255 },
239
+ cyan: { r: 0, g: 255, b: 255 },
240
+ white: { r: 255, g: 255, b: 255 },
241
+ // Extended colors
242
+ orange: { r: 255, g: 165, b: 0 },
243
+ purple: { r: 128, g: 0, b: 128 },
244
+ pink: { r: 255, g: 192, b: 203 },
245
+ brown: { r: 165, g: 42, b: 42 },
246
+ lime: { r: 0, g: 255, b: 0 },
247
+ indigo: { r: 75, g: 0, b: 130 },
248
+ violet: { r: 238, g: 130, b: 238 },
249
+ turquoise: { r: 64, g: 224, b: 208 },
250
+ gold: { r: 255, g: 215, b: 0 },
251
+ silver: { r: 192, g: 192, b: 192 },
252
+ };
253
+
254
+ /**
255
+ * Main ChalkTS class with all styling capabilities
256
+ */
257
+ class ChalkTS {
258
+ colorEnabled;
259
+ constructor(enabled) {
260
+ this.colorEnabled = enabled ?? supportsColor();
261
+ }
262
+ /**
263
+ * Apply ANSI codes to text
264
+ */
265
+ apply(codes, text) {
266
+ if (!this.colorEnabled)
267
+ return String(text);
268
+ if (text == null)
269
+ return String(text);
270
+ if (text === "")
271
+ return text;
272
+ return codes.join("") + text + ANSI_CODES.reset;
273
+ }
274
+ /**
275
+ * Create a new instance with color support disabled
276
+ */
277
+ get disabled() {
278
+ return new ChalkTS(false);
279
+ }
280
+ /**
281
+ * Create a new instance with color support enabled
282
+ */
283
+ get enabled() {
284
+ return new ChalkTS(true);
285
+ }
286
+ // Text styles
287
+ get bold() {
288
+ return this.createStyler([ANSI_CODES.bold]);
289
+ }
290
+ get dim() {
291
+ return this.createStyler([ANSI_CODES.dim]);
292
+ }
293
+ get italic() {
294
+ return this.createStyler([ANSI_CODES.italic]);
295
+ }
296
+ get underline() {
297
+ return this.createStyler([ANSI_CODES.underline]);
298
+ }
299
+ get blink() {
300
+ return this.createStyler([ANSI_CODES.blink]);
301
+ }
302
+ get inverse() {
303
+ return this.createStyler([ANSI_CODES.inverse]);
304
+ }
305
+ get hidden() {
306
+ return this.createStyler([ANSI_CODES.hidden]);
307
+ }
308
+ get strikethrough() {
309
+ return this.createStyler([ANSI_CODES.strikethrough]);
310
+ }
311
+ // Foreground colors
312
+ get black() {
313
+ return this.createStyler([ANSI_CODES.black]);
314
+ }
315
+ get red() {
316
+ return this.createStyler([ANSI_CODES.red]);
317
+ }
318
+ get green() {
319
+ return this.createStyler([ANSI_CODES.green]);
320
+ }
321
+ get yellow() {
322
+ return this.createStyler([ANSI_CODES.yellow]);
323
+ }
324
+ get blue() {
325
+ return this.createStyler([ANSI_CODES.blue]);
326
+ }
327
+ get magenta() {
328
+ return this.createStyler([ANSI_CODES.magenta]);
329
+ }
330
+ get cyan() {
331
+ return this.createStyler([ANSI_CODES.cyan]);
332
+ }
333
+ get white() {
334
+ return this.createStyler([ANSI_CODES.white]);
335
+ }
336
+ get gray() {
337
+ return this.createStyler([ANSI_CODES.gray]);
338
+ }
339
+ get grey() {
340
+ return this.createStyler([ANSI_CODES.grey]);
341
+ }
342
+ // Bright foreground colors
343
+ get redBright() {
344
+ return this.createStyler([ANSI_CODES.redBright]);
345
+ }
346
+ get greenBright() {
347
+ return this.createStyler([ANSI_CODES.greenBright]);
348
+ }
349
+ get yellowBright() {
350
+ return this.createStyler([ANSI_CODES.yellowBright]);
351
+ }
352
+ get blueBright() {
353
+ return this.createStyler([ANSI_CODES.blueBright]);
354
+ }
355
+ get magentaBright() {
356
+ return this.createStyler([ANSI_CODES.magentaBright]);
357
+ }
358
+ get cyanBright() {
359
+ return this.createStyler([ANSI_CODES.cyanBright]);
360
+ }
361
+ get whiteBright() {
362
+ return this.createStyler([ANSI_CODES.whiteBright]);
363
+ }
364
+ // Background colors
365
+ get bgBlack() {
366
+ return this.createStyler([ANSI_CODES.bgBlack]);
367
+ }
368
+ get bgRed() {
369
+ return this.createStyler([ANSI_CODES.bgRed]);
370
+ }
371
+ get bgGreen() {
372
+ return this.createStyler([ANSI_CODES.bgGreen]);
373
+ }
374
+ get bgYellow() {
375
+ return this.createStyler([ANSI_CODES.bgYellow]);
376
+ }
377
+ get bgBlue() {
378
+ return this.createStyler([ANSI_CODES.bgBlue]);
379
+ }
380
+ get bgMagenta() {
381
+ return this.createStyler([ANSI_CODES.bgMagenta]);
382
+ }
383
+ get bgCyan() {
384
+ return this.createStyler([ANSI_CODES.bgCyan]);
385
+ }
386
+ get bgWhite() {
387
+ return this.createStyler([ANSI_CODES.bgWhite]);
388
+ }
389
+ get bgGray() {
390
+ return this.createStyler([ANSI_CODES.bgGray]);
391
+ }
392
+ get bgGrey() {
393
+ return this.createStyler([ANSI_CODES.bgGrey]);
394
+ }
395
+ // Bright background colors
396
+ get bgRedBright() {
397
+ return this.createStyler([ANSI_CODES.bgRedBright]);
398
+ }
399
+ get bgGreenBright() {
400
+ return this.createStyler([ANSI_CODES.bgGreenBright]);
401
+ }
402
+ get bgYellowBright() {
403
+ return this.createStyler([ANSI_CODES.bgYellowBright]);
404
+ }
405
+ get bgBlueBright() {
406
+ return this.createStyler([ANSI_CODES.bgBlueBright]);
407
+ }
408
+ get bgMagentaBright() {
409
+ return this.createStyler([ANSI_CODES.bgMagentaBright]);
410
+ }
411
+ get bgCyanBright() {
412
+ return this.createStyler([ANSI_CODES.bgCyanBright]);
413
+ }
414
+ get bgWhiteBright() {
415
+ return this.createStyler([ANSI_CODES.bgWhiteBright]);
416
+ }
417
+ // Advanced color methods
418
+ rgb(r, g, b) {
419
+ return this.createStyler([rgb(r, g, b)]);
420
+ }
421
+ bgRgb(r, g, b) {
422
+ return this.createStyler([rgb(r, g, b, true)]);
423
+ }
424
+ hex(color) {
425
+ return this.createStyler([hex(color)]);
426
+ }
427
+ bgHex(color) {
428
+ return this.createStyler([hex(color, true)]);
429
+ }
430
+ hsl(h, s, l) {
431
+ return this.createStyler([hsl(h, s, l)]);
432
+ }
433
+ bgHsl(h, s, l) {
434
+ return this.createStyler([hsl(h, s, l, true)]);
435
+ }
436
+ // Extended color palette
437
+ get orange() {
438
+ const color = COLORS.orange;
439
+ return this.createStyler([rgb(color.r, color.g, color.b)]);
440
+ }
441
+ get purple() {
442
+ const color = COLORS.purple;
443
+ return this.createStyler([rgb(color.r, color.g, color.b)]);
444
+ }
445
+ get pink() {
446
+ const color = COLORS.pink;
447
+ return this.createStyler([rgb(color.r, color.g, color.b)]);
448
+ }
449
+ get brown() {
450
+ const color = COLORS.brown;
451
+ return this.createStyler([rgb(color.r, color.g, color.b)]);
452
+ }
453
+ get lime() {
454
+ const color = COLORS.lime;
455
+ return this.createStyler([rgb(color.r, color.g, color.b)]);
456
+ }
457
+ get indigo() {
458
+ const color = COLORS.indigo;
459
+ return this.createStyler([rgb(color.r, color.g, color.b)]);
460
+ }
461
+ get violet() {
462
+ const color = COLORS.violet;
463
+ return this.createStyler([rgb(color.r, color.g, color.b)]);
464
+ }
465
+ get turquoise() {
466
+ return this.createStyler([rgb(64, 224, 208)]);
467
+ }
468
+ get gold() {
469
+ return this.createStyler([rgb(255, 215, 0)]);
470
+ }
471
+ get silver() {
472
+ return this.createStyler([rgb(192, 192, 192)]);
473
+ }
474
+ // Utility methods
475
+ strip(text) {
476
+ // Remove all ANSI escape sequences
477
+ return text.replace(/\u001B\[[0-9;]*m/g, "");
478
+ }
479
+ length(text) {
480
+ return this.strip(text).length;
481
+ }
482
+ // Template literal support
483
+ template(template, ...substitutions) {
484
+ let result = "";
485
+ for (let i = 0; i < template.length; i++) {
486
+ result += template[i];
487
+ if (i < substitutions.length) {
488
+ result += String(substitutions[i]);
489
+ }
490
+ }
491
+ return result;
492
+ }
493
+ /**
494
+ * Create a styled function that can be chained
495
+ */
496
+ createStyler(codes) {
497
+ const styler = (text) => this.apply(codes, text);
498
+ // Create a new ChalkTS instance with accumulated codes
499
+ const newChalk = new ChalkTS(this.colorEnabled);
500
+ // Copy all properties and methods to the styler function
501
+ Object.setPrototypeOf(styler, newChalk);
502
+ Object.assign(styler, newChalk);
503
+ // Override the createStyler method to accumulate codes
504
+ styler.createStyler = (newCodes) => {
505
+ return this.createStyler([...codes, ...newCodes]);
506
+ };
507
+ return styler;
508
+ }
509
+ }
510
+ /**
511
+ * Default instance
512
+ */
513
+ const chalkTs = new ChalkTS();
514
+ /**
515
+ * Export individual color functions for convenience
516
+ */
517
+ const { bold, dim, italic, underline, blink, inverse, hidden, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, grey, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray, bgGrey, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright, orange, purple, pink, brown, lime, indigo, violet, turquoise, gold, silver, } = chalkTs;
518
+
519
+ /**
520
+ * Advanced styling utilities and effects
521
+ */
522
+ /**
523
+ * Create a gradient effect between two colors
524
+ */
525
+ function gradient(text, startColor, endColor) {
526
+ if (text.length === 0)
527
+ return text;
528
+ const chalk = new ChalkTS();
529
+ // Parse hex colors
530
+ const parseHex = (hex) => {
531
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
532
+ return result && result.length >= 4
533
+ ? {
534
+ r: parseInt(result[1], 16),
535
+ g: parseInt(result[2], 16),
536
+ b: parseInt(result[3], 16),
537
+ }
538
+ : null;
539
+ };
540
+ const start = parseHex(startColor);
541
+ const end = parseHex(endColor);
542
+ if (!start || !end) {
543
+ throw new Error("Invalid hex colors provided");
544
+ }
545
+ let result = "";
546
+ for (let i = 0; i < text.length; i++) {
547
+ const char = text[i];
548
+ if (char) {
549
+ const ratio = i / (text.length - 1);
550
+ const r = Math.round(start.r + (end.r - start.r) * ratio);
551
+ const g = Math.round(start.g + (end.g - start.g) * ratio);
552
+ const b = Math.round(start.b + (end.b - start.b) * ratio);
553
+ result += chalk.rgb(r, g, b)(char);
554
+ }
555
+ }
556
+ return result;
557
+ }
558
+ /**
559
+ * Create a rainbow effect
560
+ */
561
+ function rainbow(text) {
562
+ if (text.length === 0)
563
+ return text;
564
+ const chalk = new ChalkTS();
565
+ const colors = [
566
+ [255, 0, 0], // Red
567
+ [255, 127, 0], // Orange
568
+ [255, 255, 0], // Yellow
569
+ [0, 255, 0], // Green
570
+ [0, 0, 255], // Blue
571
+ [75, 0, 130], // Indigo
572
+ [148, 0, 211], // Violet
573
+ ];
574
+ let result = "";
575
+ for (let i = 0; i < text.length; i++) {
576
+ const char = text[i];
577
+ if (char) {
578
+ const colorIndex = i % colors.length;
579
+ const color = colors[colorIndex];
580
+ if (color) {
581
+ const [r, g, b] = color;
582
+ result += chalk.rgb(r, g, b)(char);
583
+ }
584
+ }
585
+ }
586
+ return result;
587
+ }
588
+ /**
589
+ * Create pulsing effect (alternating bright and dim)
590
+ */
591
+ function pulse(text, color = "white") {
592
+ const chalk = new ChalkTS();
593
+ let result = "";
594
+ for (let i = 0; i < text.length; i++) {
595
+ const char = text[i];
596
+ if (i % 2 === 0) {
597
+ result += chalk[color].bold(char);
598
+ }
599
+ else {
600
+ result += chalk[color].dim(char);
601
+ }
602
+ }
603
+ return result;
604
+ }
605
+ /**
606
+ * Create zebra stripes effect (alternating colors)
607
+ */
608
+ function zebra(text, color1 = "white", color2 = "gray") {
609
+ const chalk = new ChalkTS();
610
+ let result = "";
611
+ for (let i = 0; i < text.length; i++) {
612
+ const char = text[i];
613
+ const color = i % 2 === 0 ? color1 : color2;
614
+ result += chalk[color](char);
615
+ }
616
+ return result;
617
+ }
618
+ /**
619
+ * Create a neon effect
620
+ */
621
+ function neon(text, color = "cyan") {
622
+ const chalk = new ChalkTS();
623
+ return chalk[color].bold.underline(text);
624
+ }
625
+ /**
626
+ * Create a shadow effect
627
+ */
628
+ function shadow(text, color = "white", shadowColor = "gray") {
629
+ const chalk = new ChalkTS();
630
+ const lines = text.split("\n");
631
+ let result = "";
632
+ for (let i = 0; i < lines.length; i++) {
633
+ result += chalk[color](lines[i]);
634
+ if (i < lines.length - 1) {
635
+ result += "\n";
636
+ }
637
+ }
638
+ // Add shadow line
639
+ if (lines.length === 1) {
640
+ result += "\n" + chalk[shadowColor].dim(" ".repeat(text.length));
641
+ }
642
+ return result;
643
+ }
644
+ /**
645
+ * Create ASCII art box around text
646
+ */
647
+ function box(text, options = {}) {
648
+ const { padding = 1, color = "white", style = "single" } = options;
649
+ const chalk = new ChalkTS();
650
+ const styles = {
651
+ single: {
652
+ top: "─",
653
+ bottom: "─",
654
+ left: "│",
655
+ right: "│",
656
+ topLeft: "┌",
657
+ topRight: "┐",
658
+ bottomLeft: "└",
659
+ bottomRight: "┘",
660
+ },
661
+ double: {
662
+ top: "═",
663
+ bottom: "═",
664
+ left: "║",
665
+ right: "║",
666
+ topLeft: "╔",
667
+ topRight: "╗",
668
+ bottomLeft: "╚",
669
+ bottomRight: "╝",
670
+ },
671
+ rounded: {
672
+ top: "─",
673
+ bottom: "─",
674
+ left: "│",
675
+ right: "│",
676
+ topLeft: "╭",
677
+ topRight: "╮",
678
+ bottomLeft: "╰",
679
+ bottomRight: "╯",
680
+ },
681
+ thick: {
682
+ top: "━",
683
+ bottom: "━",
684
+ left: "┃",
685
+ right: "┃",
686
+ topLeft: "┏",
687
+ topRight: "┓",
688
+ bottomLeft: "┗",
689
+ bottomRight: "┛",
690
+ },
691
+ };
692
+ const chars = styles[style];
693
+ const lines = text.split("\n");
694
+ const maxLength = Math.max(...lines.map((line) => line.length));
695
+ const width = maxLength + padding * 2;
696
+ const topLine = chalk[color](chars.topLeft + chars.top.repeat(width) + chars.topRight);
697
+ const bottomLine = chalk[color](chars.bottomLeft + chars.bottom.repeat(width) + chars.bottomRight);
698
+ let result = topLine + "\n";
699
+ // Add padding lines
700
+ for (let i = 0; i < padding; i++) {
701
+ result +=
702
+ chalk[color](chars.left + " ".repeat(width) + chars.right) +
703
+ "\n";
704
+ }
705
+ // Add content lines
706
+ for (const line of lines) {
707
+ const padLeft = " ".repeat(padding);
708
+ const padRight = " ".repeat(width - line.length - padding);
709
+ result +=
710
+ chalk[color](chars.left) +
711
+ padLeft +
712
+ line +
713
+ padRight +
714
+ chalk[color](chars.right) +
715
+ "\n";
716
+ }
717
+ // Add padding lines
718
+ for (let i = 0; i < padding; i++) {
719
+ result +=
720
+ chalk[color](chars.left + " ".repeat(width) + chars.right) +
721
+ "\n";
722
+ }
723
+ result += bottomLine;
724
+ return result;
725
+ }
726
+ /**
727
+ * Create a progress bar
728
+ */
729
+ function progressBar(progress, total, options = {}) {
730
+ const { width = 20, complete = "█", incomplete = "░", showPercentage = true, color = "green", } = options;
731
+ const chalk = new ChalkTS();
732
+ const percentage = Math.min(100, Math.max(0, (progress / total) * 100));
733
+ const completedWidth = Math.round((percentage / 100) * width);
734
+ const remainingWidth = width - completedWidth;
735
+ const bar = chalk[color](complete.repeat(completedWidth)) +
736
+ chalk.gray(incomplete.repeat(remainingWidth));
737
+ if (showPercentage) {
738
+ return `${bar} ${percentage.toFixed(1)}%`;
739
+ }
740
+ return bar;
741
+ }
742
+ /**
743
+ * Create a spinner animation frame
744
+ */
745
+ function spinner(frame, color = "cyan") {
746
+ const chalk = new ChalkTS();
747
+ const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
748
+ const spinnerChar = frames[frame % frames.length];
749
+ return chalk[color](spinnerChar);
750
+ }
751
+ /**
752
+ * Create a table with colored headers and rows
753
+ */
754
+ function table(data, options = {}) {
755
+ const { headers, headerColor = "cyan", borderColor = "gray", padding = 1, } = options;
756
+ const chalk = new ChalkTS();
757
+ if (data.length === 0)
758
+ return "";
759
+ const allRows = headers ? [headers, ...data] : data;
760
+ const firstRow = allRows[0];
761
+ if (!firstRow || firstRow.length === 0)
762
+ return "";
763
+ const columnWidths = firstRow.map((_, colIndex) => Math.max(...allRows.map((row) => row[colIndex]?.length || 0)));
764
+ let result = "";
765
+ // Top border
766
+ const topBorder = chalk[borderColor]("┌" + columnWidths.map((w) => "─".repeat(w + padding * 2)).join("┬") + "┐");
767
+ result += topBorder + "\n";
768
+ // Headers
769
+ if (headers) {
770
+ const headerRow = "│" +
771
+ headers
772
+ .map((header, i) => {
773
+ const width = columnWidths[i] || 0;
774
+ const padded = " ".repeat(padding) + header.padEnd(width) + " ".repeat(padding);
775
+ return chalk[headerColor].bold(padded);
776
+ })
777
+ .join(chalk[borderColor]("│")) +
778
+ chalk[borderColor]("│");
779
+ result += headerRow + "\n";
780
+ // Header separator
781
+ const separator = chalk[borderColor]("├" + columnWidths.map((w) => "─".repeat(w + padding * 2)).join("┼") + "┤");
782
+ result += separator + "\n";
783
+ }
784
+ // Data rows
785
+ const dataRows = headers ? data : allRows;
786
+ dataRows.forEach((row) => {
787
+ const tableRow = chalk[borderColor]("│") +
788
+ row
789
+ .map((cell, i) => {
790
+ const width = columnWidths[i] || 0;
791
+ const padded = " ".repeat(padding) +
792
+ (cell || "").padEnd(width) +
793
+ " ".repeat(padding);
794
+ return padded;
795
+ })
796
+ .join(chalk[borderColor]("│")) +
797
+ chalk[borderColor]("│");
798
+ result += tableRow + "\n";
799
+ });
800
+ // Bottom border
801
+ const bottomBorder = chalk[borderColor]("└" + columnWidths.map((w) => "─".repeat(w + padding * 2)).join("┴") + "┘");
802
+ result += bottomBorder;
803
+ return result;
804
+ }
805
+
806
+ export { ANSI_CODES, COLORS, ChalkTS, bgBlack, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgGrey, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blink, blue, blueBright, bold, box, brown, chalkTs as chalk, cyan, cyanBright, chalkTs as default, dim, getColorLevel, gold, gradient, gray, green, greenBright, grey, hex, hexToRgb, hidden, hsl, hslToRgb, indigo, inverse, italic, lime, magenta, magentaBright, neon, orange, pink, progressBar, pulse, purple, rainbow, red, redBright, rgb, rgbToHex, rgbToHsl, shadow, silver, spinner, strikethrough, supportsColor, table, turquoise, underline, violet, white, whiteBright, yellow, yellowBright, zebra };
807
+ //# sourceMappingURL=index.esm.js.map