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