@oxog/pigment 1.0.1

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,1802 @@
1
+ /**
2
+ * @oxog/pigment - Zero-dependency terminal styling
3
+ * MIT License - https://pigment.oxog.dev
4
+ */
5
+ var __defProp = Object.defineProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // src/core/factory.ts
12
+ import { createKernel } from "@oxog/plugin";
13
+
14
+ // src/constants.ts
15
+ var ANSI_MODIFIERS = {
16
+ bold: { open: "\x1B[1m", close: "\x1B[22m" },
17
+ dim: { open: "\x1B[2m", close: "\x1B[22m" },
18
+ italic: { open: "\x1B[3m", close: "\x1B[23m" },
19
+ underline: { open: "\x1B[4m", close: "\x1B[24m" },
20
+ strikethrough: { open: "\x1B[9m", close: "\x1B[29m" },
21
+ inverse: { open: "\x1B[7m", close: "\x1B[27m" },
22
+ hidden: { open: "\x1B[8m", close: "\x1B[28m" },
23
+ reset: { open: "\x1B[0m", close: "\x1B[0m" }
24
+ };
25
+ var ANSI_FOREGROUND_COLORS = {
26
+ black: 30,
27
+ red: 31,
28
+ green: 32,
29
+ yellow: 33,
30
+ blue: 34,
31
+ magenta: 35,
32
+ cyan: 36,
33
+ white: 37
34
+ };
35
+ var ANSI_FOREGROUND_BRIGHT_COLORS = {
36
+ blackBright: 90,
37
+ redBright: 91,
38
+ greenBright: 92,
39
+ yellowBright: 93,
40
+ blueBright: 94,
41
+ magentaBright: 95,
42
+ cyanBright: 96,
43
+ whiteBright: 97
44
+ };
45
+ var ANSI_BACKGROUND_COLORS = {
46
+ bgBlack: 40,
47
+ bgRed: 41,
48
+ bgGreen: 42,
49
+ bgYellow: 43,
50
+ bgBlue: 44,
51
+ bgMagenta: 45,
52
+ bgCyan: 46,
53
+ bgWhite: 47
54
+ };
55
+ var ANSI_BACKGROUND_BRIGHT_COLORS = {
56
+ bgBlackBright: 100,
57
+ bgRedBright: 101,
58
+ bgGreenBright: 102,
59
+ bgYellowBright: 103,
60
+ bgBlueBright: 104,
61
+ bgMagentaBright: 105,
62
+ bgCyanBright: 106,
63
+ bgWhiteBright: 107
64
+ };
65
+ var THEME_PRESETS = {
66
+ monokai: {
67
+ keyword: "#ff79c6",
68
+ string: "#f1fa8c",
69
+ number: "#bd93f9",
70
+ comment: "#6272a4",
71
+ error: "#ff5555",
72
+ success: "#50fa7b",
73
+ warning: "#ffb86c",
74
+ info: "#8be9fd"
75
+ },
76
+ dracula: {
77
+ keyword: "#ff79c6",
78
+ string: "#f1fa8c",
79
+ number: "#bd93f9",
80
+ comment: "#6272a4",
81
+ error: "#ff5555",
82
+ success: "#50fa7b",
83
+ warning: "#ffb86c",
84
+ info: "#8be9fd"
85
+ },
86
+ nord: {
87
+ keyword: "#81a1c1",
88
+ string: "#a3be8c",
89
+ number: "#b48ead",
90
+ comment: "#616e88",
91
+ error: "#bf616a",
92
+ success: "#a3be8c",
93
+ warning: "#ebcb8b",
94
+ info: "#88c0d0"
95
+ },
96
+ github: {
97
+ keyword: "#ff7b72",
98
+ string: "#a5d6ff",
99
+ number: "#79c0ff",
100
+ comment: "#8b949e",
101
+ error: "#f85149",
102
+ success: "#3fb950",
103
+ warning: "#d29922",
104
+ info: "#58a6ff"
105
+ },
106
+ vscode: {
107
+ keyword: "#569cd6",
108
+ string: "#ce9178",
109
+ number: "#b5cea8",
110
+ comment: "#6a9955",
111
+ error: "#f14c4c",
112
+ success: "#4ec9b0",
113
+ warning: "#dcdcaa",
114
+ info: "#9cdcfe"
115
+ },
116
+ "tokyo-night": {
117
+ keyword: "#bb9af7",
118
+ string: "#9ece6a",
119
+ number: "#ff9e64",
120
+ comment: "#565f89",
121
+ error: "#f7768e",
122
+ success: "#73daca",
123
+ warning: "#e0af68",
124
+ info: "#7dcfff"
125
+ },
126
+ catppuccin: {
127
+ keyword: "#cba6f7",
128
+ string: "#a6e3a1",
129
+ number: "#fab387",
130
+ comment: "#6c7086",
131
+ error: "#f38ba8",
132
+ success: "#a6e3a1",
133
+ warning: "#f9e2af",
134
+ info: "#89b4fa"
135
+ },
136
+ "one-dark": {
137
+ keyword: "#c678dd",
138
+ string: "#98c379",
139
+ number: "#d19a66",
140
+ comment: "#5c6370",
141
+ error: "#e06c75",
142
+ success: "#98c379",
143
+ warning: "#e5c07b",
144
+ info: "#61afef"
145
+ },
146
+ solarized: {
147
+ keyword: "#859900",
148
+ string: "#2aa198",
149
+ number: "#d33682",
150
+ comment: "#586e75",
151
+ error: "#dc322f",
152
+ success: "#859900",
153
+ warning: "#b58900",
154
+ info: "#268bd2"
155
+ }
156
+ };
157
+ var BOX_BORDERS = {
158
+ single: { tl: "\u250C", tr: "\u2510", bl: "\u2514", br: "\u2518", h: "\u2500", v: "\u2502" },
159
+ double: { tl: "\u2554", tr: "\u2557", bl: "\u255A", br: "\u255D", h: "\u2550", v: "\u2551" },
160
+ rounded: { tl: "\u256D", tr: "\u256E", bl: "\u2570", br: "\u256F", h: "\u2500", v: "\u2502" },
161
+ bold: { tl: "\u250F", tr: "\u2513", bl: "\u2517", br: "\u251B", h: "\u2501", v: "\u2503" },
162
+ classic: { tl: "+", tr: "+", bl: "+", br: "+", h: "-", v: "|" }
163
+ };
164
+ var MODIFIER_NAMES = [
165
+ "bold",
166
+ "dim",
167
+ "italic",
168
+ "underline",
169
+ "strikethrough",
170
+ "inverse",
171
+ "hidden",
172
+ "reset"
173
+ ];
174
+ var COLOR_NAMES = [
175
+ "black",
176
+ "red",
177
+ "green",
178
+ "yellow",
179
+ "blue",
180
+ "magenta",
181
+ "cyan",
182
+ "white",
183
+ "blackBright",
184
+ "redBright",
185
+ "greenBright",
186
+ "yellowBright",
187
+ "blueBright",
188
+ "magentaBright",
189
+ "cyanBright",
190
+ "whiteBright",
191
+ "gray",
192
+ "grey"
193
+ ];
194
+ var BACKGROUND_COLOR_NAMES = [
195
+ "bgBlack",
196
+ "bgRed",
197
+ "bgGreen",
198
+ "bgYellow",
199
+ "bgBlue",
200
+ "bgMagenta",
201
+ "bgCyan",
202
+ "bgWhite",
203
+ "bgBlackBright",
204
+ "bgRedBright",
205
+ "bgGreenBright",
206
+ "bgYellowBright",
207
+ "bgBlueBright",
208
+ "bgMagentaBright",
209
+ "bgCyanBright",
210
+ "bgWhiteBright",
211
+ "bgGray",
212
+ "bgGrey"
213
+ ];
214
+ var EXTENDED_COLOR_METHODS = [
215
+ "ansi256",
216
+ "bgAnsi256",
217
+ "rgb",
218
+ "bgRgb",
219
+ "hex",
220
+ "bgHex",
221
+ "hsl",
222
+ "bgHsl"
223
+ ];
224
+
225
+ // src/errors.ts
226
+ var PigmentError = class _PigmentError extends Error {
227
+ code;
228
+ constructor(message, code) {
229
+ super(message);
230
+ this.name = "PigmentError";
231
+ this.code = code;
232
+ Error.captureStackTrace(this, _PigmentError);
233
+ }
234
+ };
235
+ var ColorError = class extends PigmentError {
236
+ constructor(message) {
237
+ super(message, "COLOR_ERROR");
238
+ this.name = "ColorError";
239
+ }
240
+ };
241
+ var StyleError = class extends PigmentError {
242
+ constructor(message) {
243
+ super(message, "STYLE_ERROR");
244
+ this.name = "StyleError";
245
+ }
246
+ };
247
+
248
+ // src/core/ansi.ts
249
+ function generateModifierCode(name) {
250
+ const modifier = ANSI_MODIFIERS[name];
251
+ if (!modifier) {
252
+ throw new StyleError(`Unknown modifier: ${name}`);
253
+ }
254
+ return {
255
+ name,
256
+ code: -1,
257
+ open: modifier.open,
258
+ close: modifier.close,
259
+ type: "modifier"
260
+ };
261
+ }
262
+ function generateColorCode(name, background = false) {
263
+ let normalizedName = name;
264
+ const lowerName = name.toLowerCase();
265
+ if (lowerName === "gray" || lowerName === "grey") {
266
+ normalizedName = "blackBright";
267
+ } else if (lowerName === "bggray" || lowerName === "bggrey") {
268
+ normalizedName = "bgBlackBright";
269
+ }
270
+ const foregroundColors = { ...ANSI_FOREGROUND_COLORS, ...ANSI_FOREGROUND_BRIGHT_COLORS };
271
+ const backgroundColors = { ...ANSI_BACKGROUND_COLORS, ...ANSI_BACKGROUND_BRIGHT_COLORS };
272
+ let lookupName = normalizedName;
273
+ if (background && !normalizedName.startsWith("bg")) {
274
+ lookupName = "bg" + normalizedName.charAt(0).toUpperCase() + normalizedName.slice(1);
275
+ }
276
+ const allColors = background ? backgroundColors : foregroundColors;
277
+ const code = allColors[lookupName];
278
+ if (code === void 0) {
279
+ throw new StyleError(`Unknown color: ${name}`);
280
+ }
281
+ const closeCode = background ? 49 : 39;
282
+ return {
283
+ name,
284
+ code,
285
+ open: `\x1B[${code}m`,
286
+ close: `\x1B[${closeCode}m`,
287
+ type: "color",
288
+ background
289
+ };
290
+ }
291
+ function generateAnsi256Code(code, background = false) {
292
+ if (code < 0 || code > 255) {
293
+ throw new StyleError(`ANSI 256 code must be between 0 and 255, got ${code}`);
294
+ }
295
+ const prefix = background ? 48 : 38;
296
+ const closeCode = background ? 49 : 39;
297
+ return {
298
+ name: `ansi256(${code})`,
299
+ code,
300
+ open: `\x1B[${prefix};5;${code}m`,
301
+ close: `\x1B[${closeCode}m`,
302
+ type: "color",
303
+ background
304
+ };
305
+ }
306
+ function generateRgbCode(r, g, b, background = false) {
307
+ if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
308
+ throw new StyleError(`RGB values must be between 0 and 255, got (${r}, ${g}, ${b})`);
309
+ }
310
+ const prefix = background ? 48 : 38;
311
+ const closeCode = background ? 49 : 39;
312
+ return {
313
+ name: `rgb(${r}, ${g}, ${b})`,
314
+ code: -1,
315
+ open: `\x1B[${prefix};2;${r};${g};${b}m`,
316
+ close: `\x1B[${closeCode}m`,
317
+ type: "color",
318
+ background
319
+ };
320
+ }
321
+
322
+ // src/core/proxy.ts
323
+ var proxyCache = /* @__PURE__ */ new WeakMap();
324
+ function createProxyPigment(kernel, styles = []) {
325
+ const handler = {
326
+ get(target, prop) {
327
+ const ctx = kernel.getContext();
328
+ if (prop === "level") {
329
+ return ctx.level;
330
+ }
331
+ if (prop === "supportsColor") {
332
+ return ctx.colorSupport;
333
+ }
334
+ if (MODIFIER_NAMES.includes(prop)) {
335
+ const modifierStyle = generateModifierCode(prop);
336
+ return createProxyPigment(kernel, [...styles, modifierStyle]);
337
+ }
338
+ if (COLOR_NAMES.includes(prop) || BACKGROUND_COLOR_NAMES.includes(prop)) {
339
+ const background = prop.startsWith("bg");
340
+ const colorName = background ? prop.slice(2) : prop;
341
+ const colorStyle = generateColorCode(colorName, background);
342
+ return createProxyPigment(kernel, [...styles, colorStyle]);
343
+ }
344
+ if (EXTENDED_COLOR_METHODS.includes(prop)) {
345
+ if (prop === "ansi256" || prop === "bgAnsi256") {
346
+ return (code) => {
347
+ const background = prop === "bgAnsi256";
348
+ const ansi256Style = generateAnsi256Code(code, background);
349
+ return createProxyPigment(kernel, [...styles, ansi256Style]);
350
+ };
351
+ }
352
+ if (prop === "rgb" || prop === "bgRgb") {
353
+ return (r, g, b) => {
354
+ const background = prop === "bgRgb";
355
+ const rgbStyle = generateRgbCode(r, g, b, background);
356
+ return createProxyPigment(kernel, [...styles, rgbStyle]);
357
+ };
358
+ }
359
+ if (prop === "hex" || prop === "bgHex") {
360
+ return (color) => {
361
+ const background = prop === "bgHex";
362
+ const hexToRgb2 = ctx.utils?.hexToRgb;
363
+ if (!hexToRgb2) {
364
+ throw new Error("hexToRgb utility not available");
365
+ }
366
+ const { r, g, b } = hexToRgb2(color);
367
+ const rgbStyle = generateRgbCode(r, g, b, background);
368
+ return createProxyPigment(kernel, [...styles, rgbStyle]);
369
+ };
370
+ }
371
+ if (prop === "hsl" || prop === "bgHsl") {
372
+ return (h, s, l) => {
373
+ const background = prop === "bgHsl";
374
+ const hslToRgb2 = ctx.utils?.hslToRgb;
375
+ if (!hslToRgb2) {
376
+ throw new Error("hslToRgb utility not available");
377
+ }
378
+ const { r, g, b } = hslToRgb2(h, s, l);
379
+ const rgbStyle = generateRgbCode(r, g, b, background);
380
+ return createProxyPigment(kernel, [...styles, rgbStyle]);
381
+ };
382
+ }
383
+ }
384
+ if (prop === "visible") {
385
+ const colorSupport = ctx.colorSupport;
386
+ return (text) => colorSupport.level > 0 ? text : text;
387
+ }
388
+ return target[prop];
389
+ },
390
+ apply(_target, _thisArg, argArray) {
391
+ const text = String(argArray[0] ?? "");
392
+ return applyStyles(text, styles);
393
+ }
394
+ };
395
+ const pigment2 = new Proxy((() => ""), handler);
396
+ proxyCache.set(pigment2, pigment2);
397
+ return pigment2;
398
+ }
399
+ function applyStyles(text, styles) {
400
+ if (styles.length === 0) {
401
+ return text;
402
+ }
403
+ const open = styles.map((style) => style.open).join("");
404
+ const close = [...styles].reverse().map((style) => style.close).join("");
405
+ return `${open}${text}${close}`;
406
+ }
407
+
408
+ // src/utils/hex-to-rgb.ts
409
+ function hexToRgb(hex) {
410
+ const hexString = hex.trim().replace(/^#/, "");
411
+ if (hexString.length === 3) {
412
+ const expanded = hexString.split("").map((c) => c + c).join("");
413
+ return parseExpandedHex(expanded);
414
+ }
415
+ if (hexString.length === 6) {
416
+ return parseExpandedHex(hexString);
417
+ }
418
+ throw new ColorError(`Invalid HEX color format: ${hex}. Expected #RRGGBB or #RGB`);
419
+ }
420
+ function parseExpandedHex(hex) {
421
+ if (!/^[0-9a-fA-F]{6}$/.test(hex)) {
422
+ throw new ColorError(`Invalid HEX color: ${hex}`);
423
+ }
424
+ const r = parseInt(hex.slice(0, 2), 16);
425
+ const g = parseInt(hex.slice(2, 4), 16);
426
+ const b = parseInt(hex.slice(4, 6), 16);
427
+ return { r, g, b };
428
+ }
429
+ function validateHex(hex) {
430
+ try {
431
+ hexToRgb(hex);
432
+ return true;
433
+ } catch {
434
+ return false;
435
+ }
436
+ }
437
+
438
+ // src/utils/hsl-to-rgb.ts
439
+ function hslToRgb(h, s, l) {
440
+ const hNormalized = h / 360;
441
+ const sNormalized = s / 100;
442
+ const lNormalized = l / 100;
443
+ let r;
444
+ let g;
445
+ let b;
446
+ if (sNormalized === 0) {
447
+ r = g = b = lNormalized;
448
+ } else {
449
+ const hue2rgb = (p2, q2, t) => {
450
+ if (t < 0) t += 1;
451
+ if (t > 1) t -= 1;
452
+ if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
453
+ if (t < 1 / 2) return q2;
454
+ if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
455
+ return p2;
456
+ };
457
+ const q = lNormalized < 0.5 ? lNormalized * (1 + sNormalized) : lNormalized + sNormalized - lNormalized * sNormalized;
458
+ const p = 2 * lNormalized - q;
459
+ r = hue2rgb(p, q, hNormalized + 1 / 3);
460
+ g = hue2rgb(p, q, hNormalized);
461
+ b = hue2rgb(p, q, hNormalized - 1 / 3);
462
+ }
463
+ return {
464
+ r: Math.round(Math.max(0, Math.min(255, r * 255))),
465
+ g: Math.round(Math.max(0, Math.min(255, g * 255))),
466
+ b: Math.round(Math.max(0, Math.min(255, b * 255)))
467
+ };
468
+ }
469
+
470
+ // src/core/builder.ts
471
+ var BuilderPigment = class {
472
+ styles = [];
473
+ constructor(_kernel) {
474
+ }
475
+ bold() {
476
+ this.styles.push(generateModifierCode("bold"));
477
+ return this;
478
+ }
479
+ dim() {
480
+ this.styles.push(generateModifierCode("dim"));
481
+ return this;
482
+ }
483
+ italic() {
484
+ this.styles.push(generateModifierCode("italic"));
485
+ return this;
486
+ }
487
+ underline() {
488
+ this.styles.push(generateModifierCode("underline"));
489
+ return this;
490
+ }
491
+ strikethrough() {
492
+ this.styles.push(generateModifierCode("strikethrough"));
493
+ return this;
494
+ }
495
+ inverse() {
496
+ this.styles.push(generateModifierCode("inverse"));
497
+ return this;
498
+ }
499
+ hidden() {
500
+ this.styles.push(generateModifierCode("hidden"));
501
+ return this;
502
+ }
503
+ reset() {
504
+ this.styles.push(generateModifierCode("reset"));
505
+ return this;
506
+ }
507
+ black() {
508
+ this.styles.push(generateColorCode("black", false));
509
+ return this;
510
+ }
511
+ red() {
512
+ this.styles.push(generateColorCode("red", false));
513
+ return this;
514
+ }
515
+ green() {
516
+ this.styles.push(generateColorCode("green", false));
517
+ return this;
518
+ }
519
+ yellow() {
520
+ this.styles.push(generateColorCode("yellow", false));
521
+ return this;
522
+ }
523
+ blue() {
524
+ this.styles.push(generateColorCode("blue", false));
525
+ return this;
526
+ }
527
+ magenta() {
528
+ this.styles.push(generateColorCode("magenta", false));
529
+ return this;
530
+ }
531
+ cyan() {
532
+ this.styles.push(generateColorCode("cyan", false));
533
+ return this;
534
+ }
535
+ white() {
536
+ this.styles.push(generateColorCode("white", false));
537
+ return this;
538
+ }
539
+ blackBright() {
540
+ this.styles.push(generateColorCode("blackBright", false));
541
+ return this;
542
+ }
543
+ redBright() {
544
+ this.styles.push(generateColorCode("redBright", false));
545
+ return this;
546
+ }
547
+ greenBright() {
548
+ this.styles.push(generateColorCode("greenBright", false));
549
+ return this;
550
+ }
551
+ yellowBright() {
552
+ this.styles.push(generateColorCode("yellowBright", false));
553
+ return this;
554
+ }
555
+ blueBright() {
556
+ this.styles.push(generateColorCode("blueBright", false));
557
+ return this;
558
+ }
559
+ magentaBright() {
560
+ this.styles.push(generateColorCode("magentaBright", false));
561
+ return this;
562
+ }
563
+ cyanBright() {
564
+ this.styles.push(generateColorCode("cyanBright", false));
565
+ return this;
566
+ }
567
+ whiteBright() {
568
+ this.styles.push(generateColorCode("whiteBright", false));
569
+ return this;
570
+ }
571
+ gray() {
572
+ this.styles.push(generateColorCode("gray", false));
573
+ return this;
574
+ }
575
+ grey() {
576
+ this.styles.push(generateColorCode("grey", false));
577
+ return this;
578
+ }
579
+ bgBlack() {
580
+ this.styles.push(generateColorCode("black", true));
581
+ return this;
582
+ }
583
+ bgRed() {
584
+ this.styles.push(generateColorCode("red", true));
585
+ return this;
586
+ }
587
+ bgGreen() {
588
+ this.styles.push(generateColorCode("green", true));
589
+ return this;
590
+ }
591
+ bgYellow() {
592
+ this.styles.push(generateColorCode("yellow", true));
593
+ return this;
594
+ }
595
+ bgBlue() {
596
+ this.styles.push(generateColorCode("blue", true));
597
+ return this;
598
+ }
599
+ bgMagenta() {
600
+ this.styles.push(generateColorCode("magenta", true));
601
+ return this;
602
+ }
603
+ bgCyan() {
604
+ this.styles.push(generateColorCode("cyan", true));
605
+ return this;
606
+ }
607
+ bgWhite() {
608
+ this.styles.push(generateColorCode("white", true));
609
+ return this;
610
+ }
611
+ bgBlackBright() {
612
+ this.styles.push(generateColorCode("blackBright", true));
613
+ return this;
614
+ }
615
+ bgRedBright() {
616
+ this.styles.push(generateColorCode("redBright", true));
617
+ return this;
618
+ }
619
+ bgGreenBright() {
620
+ this.styles.push(generateColorCode("greenBright", true));
621
+ return this;
622
+ }
623
+ bgYellowBright() {
624
+ this.styles.push(generateColorCode("yellowBright", true));
625
+ return this;
626
+ }
627
+ bgBlueBright() {
628
+ this.styles.push(generateColorCode("blueBright", true));
629
+ return this;
630
+ }
631
+ bgMagentaBright() {
632
+ this.styles.push(generateColorCode("magentaBright", true));
633
+ return this;
634
+ }
635
+ bgCyanBright() {
636
+ this.styles.push(generateColorCode("cyanBright", true));
637
+ return this;
638
+ }
639
+ bgWhiteBright() {
640
+ this.styles.push(generateColorCode("whiteBright", true));
641
+ return this;
642
+ }
643
+ bgGray() {
644
+ this.styles.push(generateColorCode("gray", true));
645
+ return this;
646
+ }
647
+ bgGrey() {
648
+ this.styles.push(generateColorCode("grey", true));
649
+ return this;
650
+ }
651
+ ansi256(code) {
652
+ this.styles.push(generateAnsi256Code(code, false));
653
+ return this;
654
+ }
655
+ bgAnsi256(code) {
656
+ this.styles.push(generateAnsi256Code(code, true));
657
+ return this;
658
+ }
659
+ rgb(r, g, b) {
660
+ this.styles.push(generateRgbCode(r, g, b, false));
661
+ return this;
662
+ }
663
+ bgRgb(r, g, b) {
664
+ this.styles.push(generateRgbCode(r, g, b, true));
665
+ return this;
666
+ }
667
+ hex(color) {
668
+ const rgb = hexToRgb(color);
669
+ if (rgb) {
670
+ const { r, g, b } = rgb;
671
+ this.styles.push(generateRgbCode(r, g, b, false));
672
+ }
673
+ return this;
674
+ }
675
+ bgHex(color) {
676
+ const rgb = hexToRgb(color);
677
+ if (rgb) {
678
+ const { r, g, b } = rgb;
679
+ this.styles.push(generateRgbCode(r, g, b, true));
680
+ }
681
+ return this;
682
+ }
683
+ hsl(h, s, l) {
684
+ const { r, g, b } = hslToRgb(h, s, l);
685
+ this.styles.push(generateRgbCode(r, g, b, false));
686
+ return this;
687
+ }
688
+ bgHsl(h, s, l) {
689
+ const { r, g, b } = hslToRgb(h, s, l);
690
+ this.styles.push(generateRgbCode(r, g, b, true));
691
+ return this;
692
+ }
693
+ paint(text) {
694
+ if (this.styles.length === 0) {
695
+ return text;
696
+ }
697
+ const open = this.styles.map((style) => style.open).join("");
698
+ const close = [...this.styles].reverse().map((style) => style.close).join("");
699
+ return `${open}${text}${close}`;
700
+ }
701
+ };
702
+
703
+ // src/utils/platform.ts
704
+ var cachedPlatform;
705
+ function detectPlatform() {
706
+ if (cachedPlatform) {
707
+ return cachedPlatform;
708
+ }
709
+ const isNode2 = typeof process !== "undefined" && process.versions?.node !== void 0;
710
+ const isBrowser2 = typeof window !== "undefined" && typeof document !== "undefined";
711
+ const isWindows2 = isNode2 && process.platform === "win32";
712
+ const isCI2 = isNode2 && (process.env.CI === "true" || process.env.CONTINUOUS_INTEGRATION === "true");
713
+ const hasTTY2 = isNode2 && process.stdout?.isTTY === true;
714
+ cachedPlatform = { isNode: isNode2, isBrowser: isBrowser2, isWindows: isWindows2, isCI: isCI2, hasTTY: hasTTY2 };
715
+ return cachedPlatform;
716
+ }
717
+ function isNode() {
718
+ return detectPlatform().isNode;
719
+ }
720
+ function isBrowser() {
721
+ return detectPlatform().isBrowser;
722
+ }
723
+ function isWindows() {
724
+ return detectPlatform().isWindows;
725
+ }
726
+ function isCI() {
727
+ return detectPlatform().isCI;
728
+ }
729
+ function hasTTY() {
730
+ return detectPlatform().hasTTY;
731
+ }
732
+
733
+ // src/utils/color-support.ts
734
+ var cachedColorSupport;
735
+ function detectColorSupport(overrideLevel) {
736
+ if (overrideLevel !== void 0) {
737
+ const level = overrideLevel;
738
+ return {
739
+ level,
740
+ hasBasic: level >= 1,
741
+ has256: level >= 2,
742
+ has16m: level >= 3
743
+ };
744
+ }
745
+ if (cachedColorSupport) {
746
+ return cachedColorSupport;
747
+ }
748
+ const platform = detectPlatform();
749
+ if (platform.isBrowser) {
750
+ cachedColorSupport = {
751
+ level: 3,
752
+ hasBasic: true,
753
+ has256: true,
754
+ has16m: true
755
+ };
756
+ return cachedColorSupport;
757
+ }
758
+ if (!platform.isNode) {
759
+ cachedColorSupport = {
760
+ level: 0,
761
+ hasBasic: false,
762
+ has256: false,
763
+ has16m: false
764
+ };
765
+ return cachedColorSupport;
766
+ }
767
+ if (process.env.NO_COLOR) {
768
+ cachedColorSupport = {
769
+ level: 0,
770
+ hasBasic: false,
771
+ has256: false,
772
+ has16m: false
773
+ };
774
+ return cachedColorSupport;
775
+ }
776
+ if (process.env.FORCE_COLOR) {
777
+ const level = parseInt(process.env.FORCE_COLOR, 10);
778
+ const clampedLevel = Math.max(0, Math.min(3, level));
779
+ cachedColorSupport = {
780
+ level: clampedLevel,
781
+ hasBasic: clampedLevel >= 1,
782
+ has256: clampedLevel >= 2,
783
+ has16m: clampedLevel >= 3
784
+ };
785
+ return cachedColorSupport;
786
+ }
787
+ if (!hasTTY() && !process.env.CI) {
788
+ cachedColorSupport = {
789
+ level: 0,
790
+ hasBasic: false,
791
+ has256: false,
792
+ has16m: false
793
+ };
794
+ return cachedColorSupport;
795
+ }
796
+ const term = process.env.TERM ?? "";
797
+ if (term.includes("truecolor") || term.includes("24bit")) {
798
+ cachedColorSupport = {
799
+ level: 3,
800
+ hasBasic: true,
801
+ has256: true,
802
+ has16m: true
803
+ };
804
+ return cachedColorSupport;
805
+ }
806
+ if (term.includes("256color")) {
807
+ cachedColorSupport = {
808
+ level: 2,
809
+ hasBasic: true,
810
+ has256: true,
811
+ has16m: false
812
+ };
813
+ return cachedColorSupport;
814
+ }
815
+ if (process.env.CI) {
816
+ cachedColorSupport = {
817
+ level: 1,
818
+ hasBasic: true,
819
+ has256: false,
820
+ has16m: false
821
+ };
822
+ return cachedColorSupport;
823
+ }
824
+ cachedColorSupport = {
825
+ level: 1,
826
+ hasBasic: true,
827
+ has256: false,
828
+ has16m: false
829
+ };
830
+ return cachedColorSupport;
831
+ }
832
+ function supportsColor() {
833
+ return detectColorSupport();
834
+ }
835
+
836
+ // src/utils/rgb-to-ansi256.ts
837
+ function rgbToAnsi256(r, g, b) {
838
+ const clampedR = Math.max(0, Math.min(255, r));
839
+ const clampedG = Math.max(0, Math.min(255, g));
840
+ const clampedB = Math.max(0, Math.min(255, b));
841
+ if (clampedR === clampedG && clampedG === clampedB) {
842
+ if (clampedR < 8) {
843
+ return 16;
844
+ }
845
+ if (clampedR > 248) {
846
+ return 231;
847
+ }
848
+ return Math.round((clampedR - 8) / 247 * 24) + 232;
849
+ }
850
+ return Math.round(clampedR / 51) * 36 + Math.round(clampedG / 51) * 6 + Math.round(clampedB / 51) + 16;
851
+ }
852
+
853
+ // src/plugins/core/base-colors.ts
854
+ function baseColorsPlugin() {
855
+ return {
856
+ name: "base-colors",
857
+ version: "1.0.0",
858
+ install(kernel) {
859
+ const k = kernel;
860
+ const foregroundColors = { ...ANSI_FOREGROUND_COLORS, ...ANSI_FOREGROUND_BRIGHT_COLORS };
861
+ const backgroundColors = { ...ANSI_BACKGROUND_COLORS, ...ANSI_BACKGROUND_BRIGHT_COLORS };
862
+ k.updateContext({
863
+ colors: {
864
+ foreground: foregroundColors,
865
+ background: backgroundColors,
866
+ all: { ...foregroundColors, ...backgroundColors }
867
+ }
868
+ });
869
+ }
870
+ };
871
+ }
872
+
873
+ // src/plugins/core/modifiers.ts
874
+ function modifiersPlugin() {
875
+ return {
876
+ name: "modifiers",
877
+ version: "1.0.0",
878
+ install(kernel) {
879
+ const k = kernel;
880
+ k.updateContext({
881
+ modifiers: ANSI_MODIFIERS
882
+ });
883
+ }
884
+ };
885
+ }
886
+
887
+ // src/plugins/core/ansi256.ts
888
+ function ansi256Plugin() {
889
+ return {
890
+ name: "ansi256",
891
+ version: "1.0.0",
892
+ install(kernel) {
893
+ const k = kernel;
894
+ const ctx = k.getContext();
895
+ k.updateContext({
896
+ ansi256: {
897
+ enabled: true,
898
+ supports256: ctx.colorSupport?.has256 ?? false
899
+ }
900
+ });
901
+ k.on("color:ansi256", (data) => {
902
+ const { code, background } = data;
903
+ if (code < 0 || code > 255) {
904
+ k.emit("error", new Error(`ANSI 256 code must be between 0 and 255, got ${code}`));
905
+ return;
906
+ }
907
+ const prefix = background ? 48 : 38;
908
+ const closeCode = background ? 49 : 39;
909
+ return {
910
+ name: `ansi256(${code})`,
911
+ code,
912
+ open: `\x1B[${prefix};5;${code}m`,
913
+ close: `\x1B[${closeCode}m`,
914
+ type: "color",
915
+ background
916
+ };
917
+ });
918
+ }
919
+ };
920
+ }
921
+
922
+ // src/plugins/core/true-color.ts
923
+ function trueColorPlugin() {
924
+ return {
925
+ name: "true-color",
926
+ version: "1.0.0",
927
+ install(kernel) {
928
+ const k = kernel;
929
+ const ctx = k.getContext();
930
+ const utils = ctx.utils;
931
+ k.updateContext({
932
+ trueColor: {
933
+ enabled: true,
934
+ supports16m: ctx.colorSupport?.has16m ?? false
935
+ }
936
+ });
937
+ k.on("color:rgb", (data) => {
938
+ const { r, g, b, background } = data;
939
+ if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
940
+ throw new ColorError(`RGB values must be between 0 and 255, got (${r}, ${g}, ${b})`);
941
+ }
942
+ const prefix = background ? 48 : 38;
943
+ const closeCode = background ? 49 : 39;
944
+ return {
945
+ name: `rgb(${r}, ${g}, ${b})`,
946
+ code: -1,
947
+ open: `\x1B[${prefix};2;${r};${g};${b}m`,
948
+ close: `\x1B[${closeCode}m`,
949
+ type: "color",
950
+ background
951
+ };
952
+ });
953
+ k.on("color:hex", (data) => {
954
+ const { hex, background } = data;
955
+ if (!utils?.hexToRgb) {
956
+ throw new Error("hexToRgb utility not available");
957
+ }
958
+ const rgb = utils.hexToRgb(hex);
959
+ k.emit("color:rgb", { ...rgb, background });
960
+ });
961
+ k.on("color:hsl", (data) => {
962
+ const { h, s, l, background } = data;
963
+ if (!utils?.hslToRgb) {
964
+ throw new Error("hslToRgb utility not available");
965
+ }
966
+ const rgb = utils.hslToRgb(h, s, l);
967
+ k.emit("color:rgb", { ...rgb, background });
968
+ });
969
+ }
970
+ };
971
+ }
972
+
973
+ // src/plugins/core/nesting.ts
974
+ function nestingPlugin() {
975
+ return {
976
+ name: "nesting",
977
+ version: "1.0.0",
978
+ install(kernel) {
979
+ const k = kernel;
980
+ k.updateContext({
981
+ nesting: {
982
+ enabled: true
983
+ }
984
+ });
985
+ k.on("style:nest", (data) => {
986
+ const { innerText, outerStyles } = data;
987
+ const open = outerStyles.join("");
988
+ const close = outerStyles.map(() => "\x1B[0m").join("");
989
+ return `${open}${innerText}${close}`;
990
+ });
991
+ }
992
+ };
993
+ }
994
+
995
+ // src/plugins/core/environment.ts
996
+ function environmentPlugin() {
997
+ return {
998
+ name: "environment",
999
+ version: "1.0.0",
1000
+ install(kernel) {
1001
+ const k = kernel;
1002
+ const ci = isCI();
1003
+ const colorSupport = detectColorSupport();
1004
+ k.updateContext({
1005
+ environment: {
1006
+ isCI: ci,
1007
+ noColor: process.env.NO_COLOR !== void 0,
1008
+ forceColor: process.env.FORCE_COLOR !== void 0,
1009
+ term: process.env.TERM ?? ""
1010
+ },
1011
+ colorSupport
1012
+ });
1013
+ k.on("environment:check", () => {
1014
+ const ctx = k.getContext();
1015
+ const env = ctx.environment;
1016
+ if (env?.noColor) {
1017
+ return { level: 0, enabled: false };
1018
+ }
1019
+ if (env?.forceColor) {
1020
+ const level = parseInt(process.env.FORCE_COLOR ?? "0", 10);
1021
+ return { level: Math.max(0, Math.min(3, level)), enabled: true };
1022
+ }
1023
+ if (ci) {
1024
+ return { level: 1, enabled: colorSupport.hasBasic };
1025
+ }
1026
+ return { level: colorSupport.level, enabled: colorSupport.level > 0 };
1027
+ });
1028
+ k.on("environment:override", (data) => {
1029
+ const { level, noColor, forceColor } = data;
1030
+ if (noColor !== void 0) {
1031
+ process.env.NO_COLOR = noColor ? "1" : "";
1032
+ }
1033
+ if (forceColor !== void 0 && level !== void 0) {
1034
+ process.env.FORCE_COLOR = String(level);
1035
+ }
1036
+ const newColorSupport = detectColorSupport(level);
1037
+ k.updateContext({ colorSupport: newColorSupport });
1038
+ });
1039
+ }
1040
+ };
1041
+ }
1042
+
1043
+ // src/core/factory.ts
1044
+ function createPigment(options) {
1045
+ const colorSupport = detectColorSupport(options?.level);
1046
+ const noColor = options?.noColor ?? false;
1047
+ const forceColor = options?.forceColor ?? false;
1048
+ const level = noColor ? 0 : forceColor ? options?.level ?? 3 : colorSupport.level;
1049
+ const kernel = createKernel({
1050
+ context: {
1051
+ colorSupport: { ...colorSupport, level },
1052
+ level,
1053
+ enabled: level > 0,
1054
+ styles: /* @__PURE__ */ new Map(),
1055
+ utils: {
1056
+ hexToRgb,
1057
+ hslToRgb,
1058
+ rgbToAnsi256,
1059
+ detectColorSupport,
1060
+ supportsColor: detectColorSupport
1061
+ }
1062
+ }
1063
+ });
1064
+ kernel.use(baseColorsPlugin());
1065
+ kernel.use(modifiersPlugin());
1066
+ kernel.use(ansi256Plugin());
1067
+ kernel.use(trueColorPlugin());
1068
+ kernel.use(nestingPlugin());
1069
+ kernel.use(environmentPlugin());
1070
+ if (options?.plugins) {
1071
+ for (const plugin of options.plugins) {
1072
+ kernel.use(plugin);
1073
+ }
1074
+ }
1075
+ kernel.init();
1076
+ const pigment2 = createProxyPigment(kernel);
1077
+ const builder = new BuilderPigment(kernel);
1078
+ Object.defineProperty(pigment2, "builder", { value: builder, enumerable: false });
1079
+ Object.defineProperty(pigment2, "level", { value: level, enumerable: true });
1080
+ Object.defineProperty(pigment2, "supportsColor", { value: colorSupport, enumerable: true });
1081
+ return pigment2;
1082
+ }
1083
+
1084
+ // src/core/chalk.ts
1085
+ var Chalk = class {
1086
+ level;
1087
+ supportsColor;
1088
+ pigment;
1089
+ constructor(options) {
1090
+ const colorSupport = detectColorSupport(options?.level);
1091
+ this.level = options?.level ?? colorSupport.level;
1092
+ this.supportsColor = colorSupport;
1093
+ this.pigment = createPigment({ level: this.level });
1094
+ }
1095
+ red(text) {
1096
+ return this.pigment.red(text);
1097
+ }
1098
+ green(text) {
1099
+ return this.pigment.green(text);
1100
+ }
1101
+ yellow(text) {
1102
+ return this.pigment.yellow(text);
1103
+ }
1104
+ blue(text) {
1105
+ return this.pigment.blue(text);
1106
+ }
1107
+ magenta(text) {
1108
+ return this.pigment.magenta(text);
1109
+ }
1110
+ cyan(text) {
1111
+ return this.pigment.cyan(text);
1112
+ }
1113
+ white(text) {
1114
+ return this.pigment.white(text);
1115
+ }
1116
+ black(text) {
1117
+ return this.pigment.black(text);
1118
+ }
1119
+ redBright(text) {
1120
+ return this.pigment.redBright(text);
1121
+ }
1122
+ greenBright(text) {
1123
+ return this.pigment.greenBright(text);
1124
+ }
1125
+ yellowBright(text) {
1126
+ return this.pigment.yellowBright(text);
1127
+ }
1128
+ blueBright(text) {
1129
+ return this.pigment.blueBright(text);
1130
+ }
1131
+ magentaBright(text) {
1132
+ return this.pigment.magentaBright(text);
1133
+ }
1134
+ cyanBright(text) {
1135
+ return this.pigment.cyanBright(text);
1136
+ }
1137
+ whiteBright(text) {
1138
+ return this.pigment.whiteBright(text);
1139
+ }
1140
+ gray(text) {
1141
+ return this.pigment.gray(text);
1142
+ }
1143
+ grey(text) {
1144
+ return this.pigment.grey(text);
1145
+ }
1146
+ bgRed(text) {
1147
+ return this.pigment.bgRed(text);
1148
+ }
1149
+ bgGreen(text) {
1150
+ return this.pigment.bgGreen(text);
1151
+ }
1152
+ bgYellow(text) {
1153
+ return this.pigment.bgYellow(text);
1154
+ }
1155
+ bgBlue(text) {
1156
+ return this.pigment.bgBlue(text);
1157
+ }
1158
+ bgMagenta(text) {
1159
+ return this.pigment.bgMagenta(text);
1160
+ }
1161
+ bgCyan(text) {
1162
+ return this.pigment.bgCyan(text);
1163
+ }
1164
+ bgWhite(text) {
1165
+ return this.pigment.bgWhite(text);
1166
+ }
1167
+ bgBlack(text) {
1168
+ return this.pigment.bgBlack(text);
1169
+ }
1170
+ bgRedBright(text) {
1171
+ return this.pigment.bgRedBright(text);
1172
+ }
1173
+ bgGreenBright(text) {
1174
+ return this.pigment.bgGreenBright(text);
1175
+ }
1176
+ bgYellowBright(text) {
1177
+ return this.pigment.bgYellowBright(text);
1178
+ }
1179
+ bgBlueBright(text) {
1180
+ return this.pigment.bgBlueBright(text);
1181
+ }
1182
+ bgMagentaBright(text) {
1183
+ return this.pigment.bgMagentaBright(text);
1184
+ }
1185
+ bgCyanBright(text) {
1186
+ return this.pigment.bgCyanBright(text);
1187
+ }
1188
+ bgWhiteBright(text) {
1189
+ return this.pigment.bgWhiteBright(text);
1190
+ }
1191
+ bgGray(text) {
1192
+ return this.pigment.bgGray(text);
1193
+ }
1194
+ bgGrey(text) {
1195
+ return this.pigment.bgGrey(text);
1196
+ }
1197
+ bold(text) {
1198
+ return this.pigment.bold(text);
1199
+ }
1200
+ dim(text) {
1201
+ return this.pigment.dim(text);
1202
+ }
1203
+ italic(text) {
1204
+ return this.pigment.italic(text);
1205
+ }
1206
+ underline(text) {
1207
+ return this.pigment.underline(text);
1208
+ }
1209
+ strikethrough(text) {
1210
+ return this.pigment.strikethrough(text);
1211
+ }
1212
+ inverse(text) {
1213
+ return this.pigment.inverse(text);
1214
+ }
1215
+ hidden(text) {
1216
+ return this.pigment.hidden(text);
1217
+ }
1218
+ reset(text) {
1219
+ return this.pigment.reset(text);
1220
+ }
1221
+ visible(text) {
1222
+ return this.supportsColor.level > 0 ? text : text;
1223
+ }
1224
+ rgb(r, g, b) {
1225
+ const coloredPigment = this.pigment.rgb(r, g, b);
1226
+ return (text) => coloredPigment(text);
1227
+ }
1228
+ bgRgb(r, g, b) {
1229
+ const coloredPigment = this.pigment.bgRgb(r, g, b);
1230
+ return (text) => coloredPigment(text);
1231
+ }
1232
+ hex(color) {
1233
+ const coloredPigment = this.pigment.hex(color);
1234
+ return (text) => coloredPigment(text);
1235
+ }
1236
+ bgHex(color) {
1237
+ const coloredPigment = this.pigment.bgHex(color);
1238
+ return (text) => coloredPigment(text);
1239
+ }
1240
+ ansi256(code) {
1241
+ const coloredPigment = this.pigment.ansi256(code);
1242
+ return (text) => coloredPigment(text);
1243
+ }
1244
+ bgAnsi256(code) {
1245
+ const coloredPigment = this.pigment.bgAnsi256(code);
1246
+ return (text) => coloredPigment(text);
1247
+ }
1248
+ };
1249
+
1250
+ // src/core/chalk-default.ts
1251
+ var chalk = new Chalk();
1252
+ chalk.level = chalk.supportsColor.level;
1253
+ var chalk_default_default = chalk;
1254
+
1255
+ // src/core/styler.ts
1256
+ function applyStyle(text, open, close) {
1257
+ if (text === "") {
1258
+ return "";
1259
+ }
1260
+ return `${open}${text}${close}`;
1261
+ }
1262
+
1263
+ // src/core/composer.ts
1264
+ var bold = (text) => applyStyle(text, "\x1B[1m", "\x1B[22m");
1265
+ var dim = (text) => applyStyle(text, "\x1B[2m", "\x1B[22m");
1266
+ var italic = (text) => applyStyle(text, "\x1B[3m", "\x1B[23m");
1267
+ var underline = (text) => applyStyle(text, "\x1B[4m", "\x1B[24m");
1268
+ var strikethrough = (text) => applyStyle(text, "\x1B[9m", "\x1B[29m");
1269
+ var inverse = (text) => applyStyle(text, "\x1B[7m", "\x1B[27m");
1270
+ var hidden = (text) => applyStyle(text, "\x1B[8m", "\x1B[28m");
1271
+ var reset = (text) => applyStyle(text, "\x1B[0m", "\x1B[0m");
1272
+ var black = (text) => applyStyle(text, "\x1B[30m", "\x1B[39m");
1273
+ var red = (text) => applyStyle(text, "\x1B[31m", "\x1B[39m");
1274
+ var green = (text) => applyStyle(text, "\x1B[32m", "\x1B[39m");
1275
+ var yellow = (text) => applyStyle(text, "\x1B[33m", "\x1B[39m");
1276
+ var blue = (text) => applyStyle(text, "\x1B[34m", "\x1B[39m");
1277
+ var magenta = (text) => applyStyle(text, "\x1B[35m", "\x1B[39m");
1278
+ var cyan = (text) => applyStyle(text, "\x1B[36m", "\x1B[39m");
1279
+ var white = (text) => applyStyle(text, "\x1B[37m", "\x1B[39m");
1280
+ var blackBright = (text) => applyStyle(text, "\x1B[90m", "\x1B[39m");
1281
+ var redBright = (text) => applyStyle(text, "\x1B[91m", "\x1B[39m");
1282
+ var greenBright = (text) => applyStyle(text, "\x1B[92m", "\x1B[39m");
1283
+ var yellowBright = (text) => applyStyle(text, "\x1B[93m", "\x1B[39m");
1284
+ var blueBright = (text) => applyStyle(text, "\x1B[94m", "\x1B[39m");
1285
+ var magentaBright = (text) => applyStyle(text, "\x1B[95m", "\x1B[39m");
1286
+ var cyanBright = (text) => applyStyle(text, "\x1B[96m", "\x1B[39m");
1287
+ var whiteBright = (text) => applyStyle(text, "\x1B[97m", "\x1B[39m");
1288
+ var gray = blackBright;
1289
+ var grey = blackBright;
1290
+ var bgBlack = (text) => applyStyle(text, "\x1B[40m", "\x1B[49m");
1291
+ var bgRed = (text) => applyStyle(text, "\x1B[41m", "\x1B[49m");
1292
+ var bgGreen = (text) => applyStyle(text, "\x1B[42m", "\x1B[49m");
1293
+ var bgYellow = (text) => applyStyle(text, "\x1B[43m", "\x1B[49m");
1294
+ var bgBlue = (text) => applyStyle(text, "\x1B[44m", "\x1B[49m");
1295
+ var bgMagenta = (text) => applyStyle(text, "\x1B[45m", "\x1B[49m");
1296
+ var bgCyan = (text) => applyStyle(text, "\x1B[46m", "\x1B[49m");
1297
+ var bgWhite = (text) => applyStyle(text, "\x1B[47m", "\x1B[49m");
1298
+ var bgBlackBright = (text) => applyStyle(text, "\x1B[100m", "\x1B[49m");
1299
+ var bgRedBright = (text) => applyStyle(text, "\x1B[101m", "\x1B[49m");
1300
+ var bgGreenBright = (text) => applyStyle(text, "\x1B[102m", "\x1B[49m");
1301
+ var bgYellowBright = (text) => applyStyle(text, "\x1B[103m", "\x1B[49m");
1302
+ var bgBlueBright = (text) => applyStyle(text, "\x1B[104m", "\x1B[49m");
1303
+ var bgMagentaBright = (text) => applyStyle(text, "\x1B[105m", "\x1B[49m");
1304
+ var bgCyanBright = (text) => applyStyle(text, "\x1B[106m", "\x1B[49m");
1305
+ var bgWhiteBright = (text) => applyStyle(text, "\x1B[107m", "\x1B[49m");
1306
+ var bgGray = bgBlackBright;
1307
+ var bgGrey = bgBlackBright;
1308
+ function compose(...stylers) {
1309
+ return (text) => {
1310
+ return stylers.reduce((acc, styler) => styler(acc), text);
1311
+ };
1312
+ }
1313
+
1314
+ // src/index.ts
1315
+ import { createKernel as createKernel2 } from "@oxog/plugin";
1316
+
1317
+ // src/plugins/index.ts
1318
+ var plugins_exports = {};
1319
+ __export(plugins_exports, {
1320
+ ansi256Plugin: () => ansi256Plugin,
1321
+ baseColorsPlugin: () => baseColorsPlugin,
1322
+ boxPlugin: () => boxPlugin,
1323
+ environmentPlugin: () => environmentPlugin,
1324
+ gradientPlugin: () => gradientPlugin,
1325
+ modifiersPlugin: () => modifiersPlugin,
1326
+ nestingPlugin: () => nestingPlugin,
1327
+ pigmentPlugin: () => pigmentPlugin,
1328
+ semanticPlugin: () => semanticPlugin,
1329
+ templatePlugin: () => templatePlugin,
1330
+ themePlugin: () => themePlugin,
1331
+ trueColorPlugin: () => trueColorPlugin
1332
+ });
1333
+
1334
+ // src/plugins/optional/gradient.ts
1335
+ function gradientPlugin(options) {
1336
+ const steps = options?.steps ?? 10;
1337
+ return {
1338
+ name: "gradient",
1339
+ version: "1.0.0",
1340
+ install(kernel) {
1341
+ const k = kernel;
1342
+ k.updateContext({
1343
+ gradient: {
1344
+ steps,
1345
+ enabled: true
1346
+ }
1347
+ });
1348
+ k.on("style:gradient", (data) => {
1349
+ const { start, end, text, steps: gradientSteps = steps } = data;
1350
+ const startRgb = start.startsWith("#") ? hexToRgb(start) : start.startsWith("rgb(") ? parseRgb(start) : hexToRgb(start);
1351
+ const endRgb = end.startsWith("#") ? hexToRgb(end) : end.startsWith("rgb(") ? parseRgb(end) : hexToRgb(end);
1352
+ if (!startRgb || !endRgb) {
1353
+ return text;
1354
+ }
1355
+ const colors = interpolateColors(startRgb, endRgb, text.length, gradientSteps);
1356
+ let result = "";
1357
+ for (let i = 0; i < text.length; i++) {
1358
+ const colorIndex = Math.floor(i / (text.length - 1) * (colors.length - 1));
1359
+ const color = colors[colorIndex];
1360
+ if (color) {
1361
+ const open = `\x1B[38;2;${color.r};${color.g};${color.b}m`;
1362
+ result += `${open}${text[i]}\x1B[39m`;
1363
+ } else {
1364
+ result += text[i];
1365
+ }
1366
+ }
1367
+ return result;
1368
+ });
1369
+ k.on("style:rainbow", (data) => {
1370
+ const { text, steps: rainbowSteps = steps } = data;
1371
+ const colors = generateRainbowColors(text.length, rainbowSteps);
1372
+ let result = "";
1373
+ for (let i = 0; i < text.length; i++) {
1374
+ const colorIndex = i % colors.length;
1375
+ const color = colors[colorIndex];
1376
+ if (color) {
1377
+ const open = `\x1B[38;2;${color.r};${color.g};${color.b}m`;
1378
+ result += `${open}${text[i]}\x1B[39m`;
1379
+ } else {
1380
+ result += text[i];
1381
+ }
1382
+ }
1383
+ return result;
1384
+ });
1385
+ }
1386
+ };
1387
+ }
1388
+ function parseRgb(rgb) {
1389
+ const match = rgb.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
1390
+ if (!match) {
1391
+ return null;
1392
+ }
1393
+ return { r: Number(match[1]), g: Number(match[2]), b: Number(match[3]) };
1394
+ }
1395
+ function interpolateColors(start, end, length, steps) {
1396
+ const colors = [];
1397
+ for (let i = 0; i < steps; i++) {
1398
+ const ratio = i / (steps - 1);
1399
+ colors.push({
1400
+ r: Math.round(start.r + (end.r - start.r) * ratio),
1401
+ g: Math.round(start.g + (end.g - start.g) * ratio),
1402
+ b: Math.round(start.b + (end.b - start.b) * ratio)
1403
+ });
1404
+ }
1405
+ return colors;
1406
+ }
1407
+ function generateRainbowColors(length, steps) {
1408
+ const colors = [];
1409
+ for (let i = 0; i < steps; i++) {
1410
+ const hue = i / steps * 360;
1411
+ const rgb = hslToRgb(hue, 100, 50);
1412
+ colors.push(rgb);
1413
+ }
1414
+ return colors;
1415
+ }
1416
+
1417
+ // src/plugins/optional/theme.ts
1418
+ function themePlugin(options) {
1419
+ const preset = options?.preset ?? "monokai";
1420
+ const custom = options?.custom ?? {};
1421
+ const theme = Object.keys(custom).length > 0 ? { ...custom } : THEME_PRESETS[preset];
1422
+ if (!theme) {
1423
+ throw new Error(`Unknown theme preset: ${preset}`);
1424
+ }
1425
+ return {
1426
+ name: "theme",
1427
+ version: "1.0.0",
1428
+ install(kernel) {
1429
+ const k = kernel;
1430
+ k.updateContext({
1431
+ theme: {
1432
+ preset,
1433
+ colors: theme,
1434
+ enabled: true
1435
+ }
1436
+ });
1437
+ k.on("style:theme", (data) => {
1438
+ const { type, text } = data;
1439
+ const color = theme[type];
1440
+ if (!color) {
1441
+ throw new Error(`Unknown theme color type: ${String(type)}`);
1442
+ }
1443
+ const ctx = k.getContext();
1444
+ const hexToRgb2 = ctx.utils?.hexToRgb;
1445
+ if (!hexToRgb2) {
1446
+ throw new Error("hexToRgb utility not available");
1447
+ }
1448
+ const { r, g, b } = hexToRgb2(color);
1449
+ const open = `\x1B[38;2;${r};${g};${b}m`;
1450
+ return `${open}${text}\x1B[39m`;
1451
+ });
1452
+ k.on("style:theme:keyword", (data) => {
1453
+ k.emit("style:theme", { type: "keyword", text: data.text });
1454
+ });
1455
+ k.on("style:theme:string", (data) => {
1456
+ k.emit("style:theme", { type: "string", text: data.text });
1457
+ });
1458
+ k.on("style:theme:number", (data) => {
1459
+ k.emit("style:theme", { type: "number", text: data.text });
1460
+ });
1461
+ k.on("style:theme:comment", (data) => {
1462
+ k.emit("style:theme", { type: "comment", text: data.text });
1463
+ });
1464
+ k.on("style:theme:error", (data) => {
1465
+ k.emit("style:theme", { type: "error", text: data.text });
1466
+ });
1467
+ k.on("style:theme:success", (data) => {
1468
+ k.emit("style:theme", { type: "success", text: data.text });
1469
+ });
1470
+ k.on("style:theme:warning", (data) => {
1471
+ k.emit("style:theme", { type: "warning", text: data.text });
1472
+ });
1473
+ k.on("style:theme:info", (data) => {
1474
+ k.emit("style:theme", { type: "info", text: data.text });
1475
+ });
1476
+ }
1477
+ };
1478
+ }
1479
+
1480
+ // src/plugins/optional/semantic.ts
1481
+ function semanticPlugin(options) {
1482
+ const colors = options ?? {};
1483
+ const defaultColors = {
1484
+ success: colors.success ?? "#50fa7b",
1485
+ error: colors.error ?? "#ff5555",
1486
+ warning: colors.warning ?? "#ffb86c",
1487
+ info: colors.info ?? "#8be9fd",
1488
+ debug: colors.debug ?? "#6272a4"
1489
+ };
1490
+ return {
1491
+ name: "semantic",
1492
+ version: "1.0.0",
1493
+ install(kernel) {
1494
+ const k = kernel;
1495
+ k.updateContext({
1496
+ semantic: {
1497
+ colors: defaultColors,
1498
+ enabled: true
1499
+ }
1500
+ });
1501
+ const ctx = k.getContext();
1502
+ const hexToRgb2 = ctx.utils?.hexToRgb;
1503
+ if (!hexToRgb2) {
1504
+ throw new Error("hexToRgb utility not available");
1505
+ }
1506
+ k.on("style:success", (data) => {
1507
+ const { r, g, b } = hexToRgb2(defaultColors.success);
1508
+ return `\x1B[38;2;${r};${g};${b}m${data.text}\x1B[39m`;
1509
+ });
1510
+ k.on("style:error", (data) => {
1511
+ const { r, g, b } = hexToRgb2(defaultColors.error);
1512
+ return `\x1B[38;2;${r};${g};${b}m${data.text}\x1B[39m`;
1513
+ });
1514
+ k.on("style:warning", (data) => {
1515
+ const { r, g, b } = hexToRgb2(defaultColors.warning);
1516
+ return `\x1B[38;2;${r};${g};${b}m${data.text}\x1B[39m`;
1517
+ });
1518
+ k.on("style:info", (data) => {
1519
+ const { r, g, b } = hexToRgb2(defaultColors.info);
1520
+ return `\x1B[38;2;${r};${g};${b}m${data.text}\x1B[39m`;
1521
+ });
1522
+ k.on("style:debug", (data) => {
1523
+ const { r, g, b } = hexToRgb2(defaultColors.debug);
1524
+ return `\x1B[38;2;${r};${g};${b}m${data.text}\x1B[39m`;
1525
+ });
1526
+ }
1527
+ };
1528
+ }
1529
+
1530
+ // src/plugins/optional/box.ts
1531
+ function boxPlugin(options) {
1532
+ const border = options?.border ?? "single";
1533
+ const padding = options?.padding ?? 1;
1534
+ return {
1535
+ name: "box",
1536
+ version: "1.0.0",
1537
+ install(kernel) {
1538
+ const k = kernel;
1539
+ k.updateContext({
1540
+ box: {
1541
+ border,
1542
+ padding,
1543
+ enabled: true,
1544
+ borders: BOX_BORDERS
1545
+ }
1546
+ });
1547
+ k.on("style:box", (data) => {
1548
+ const { text, border: boxBorder = border, padding: boxPadding = padding, bgColor } = data;
1549
+ const chars = BOX_BORDERS[boxBorder];
1550
+ const lines = text.split("\n");
1551
+ const width = Math.max(...lines.map((l) => l.length)) + boxPadding * 2;
1552
+ const pad = " ".repeat(boxPadding);
1553
+ const top = `${chars.tl}${chars.h.repeat(width)}${chars.tr}`;
1554
+ const middle = lines.map((line) => {
1555
+ const paddedLine = pad + line.padEnd(width - boxPadding * 2) + pad;
1556
+ return `${chars.v}${paddedLine}${chars.v}`;
1557
+ });
1558
+ const bottom = `${chars.bl}${chars.h.repeat(width)}${chars.br}`;
1559
+ const result = [top, ...middle, bottom].join("\n");
1560
+ if (bgColor) {
1561
+ const ctx = k.getContext();
1562
+ const hexToRgb2 = ctx.utils?.hexToRgb;
1563
+ if (!hexToRgb2) {
1564
+ throw new Error("hexToRgb utility not available");
1565
+ }
1566
+ const { r, g, b } = hexToRgb2(bgColor);
1567
+ return `\x1B[48;2;${r};${g};${b}m${result}\x1B[49m`;
1568
+ }
1569
+ return result;
1570
+ });
1571
+ }
1572
+ };
1573
+ }
1574
+
1575
+ // src/plugins/optional/template.ts
1576
+ function templatePlugin() {
1577
+ return {
1578
+ name: "template",
1579
+ version: "1.0.0",
1580
+ install(kernel) {
1581
+ const k = kernel;
1582
+ k.updateContext({
1583
+ template: {
1584
+ enabled: true
1585
+ }
1586
+ });
1587
+ k.on("style:template", (data) => {
1588
+ const { strings, values } = data;
1589
+ let result = "";
1590
+ for (let i = 0; i < strings.length; i++) {
1591
+ result += strings[i];
1592
+ if (i < values.length) {
1593
+ const value = values[i];
1594
+ if (typeof value === "string") {
1595
+ const match = value.match(/^\{(.+)\}(.*)$/);
1596
+ if (match) {
1597
+ const [, styleExpression, text] = match;
1598
+ result += parseStyleExpression(styleExpression, text, k);
1599
+ } else {
1600
+ result += value;
1601
+ }
1602
+ } else {
1603
+ result += String(value);
1604
+ }
1605
+ }
1606
+ }
1607
+ return result;
1608
+ });
1609
+ }
1610
+ };
1611
+ }
1612
+ function parseStyleExpression(expression, text, kernel) {
1613
+ const parts = expression.split(".");
1614
+ let current = kernel.getContext();
1615
+ for (const part of parts) {
1616
+ if (current && typeof current === "object" && part in current) {
1617
+ current = current[part];
1618
+ } else {
1619
+ return text;
1620
+ }
1621
+ }
1622
+ if (typeof current === "function") {
1623
+ return current(text);
1624
+ }
1625
+ return text;
1626
+ }
1627
+
1628
+ // src/plugins/ecosystem/pigment-plugin.ts
1629
+ function pigmentPlugin(options) {
1630
+ const theme = options?.theme ?? "monokai";
1631
+ const level = options?.level;
1632
+ return {
1633
+ name: "pigment",
1634
+ version: "1.0.0",
1635
+ install(kernel) {
1636
+ const k = kernel;
1637
+ const themeColors = THEME_PRESETS[theme] ?? THEME_PRESETS.monokai;
1638
+ const pigment2 = createPigment({ level });
1639
+ k.pigment = pigment2;
1640
+ k.updateContext({
1641
+ ecosystem: {
1642
+ theme,
1643
+ level,
1644
+ themeColors,
1645
+ enabled: true
1646
+ },
1647
+ colors: {
1648
+ red: pigment2.red,
1649
+ green: pigment2.green,
1650
+ yellow: pigment2.yellow,
1651
+ blue: pigment2.blue,
1652
+ magenta: pigment2.magenta,
1653
+ cyan: pigment2.cyan,
1654
+ white: pigment2.white,
1655
+ black: pigment2.black,
1656
+ bold: pigment2.bold,
1657
+ dim: pigment2.dim,
1658
+ italic: pigment2.italic,
1659
+ underline: pigment2.underline
1660
+ }
1661
+ });
1662
+ k.on("ecosystem:style", (data) => {
1663
+ const { text, type, preset: presetOverride } = data;
1664
+ const activeTheme = presetOverride ? THEME_PRESETS[presetOverride] ?? themeColors : themeColors;
1665
+ if (type && activeTheme[type]) {
1666
+ const color = activeTheme[type];
1667
+ const { r, g, b } = hexToRgb(color);
1668
+ return `\x1B[38;2;${r};${g};${b}m${text}\x1B[39m`;
1669
+ }
1670
+ return text;
1671
+ });
1672
+ k.on("ecosystem:format", (data) => {
1673
+ const { message, level: level2 = "info" } = data;
1674
+ const colorMap = {
1675
+ info: themeColors.info,
1676
+ success: themeColors.success,
1677
+ warning: themeColors.warning,
1678
+ error: themeColors.error
1679
+ };
1680
+ const color = colorMap[level2] ?? themeColors.info;
1681
+ const { r, g, b } = hexToRgb(color);
1682
+ return `\x1B[38;2;${r};${g};${b}m${message}\x1B[39m`;
1683
+ });
1684
+ }
1685
+ };
1686
+ }
1687
+
1688
+ // src/index.ts
1689
+ var pigment = createPigment();
1690
+ Object.assign(pigment, {
1691
+ bold,
1692
+ dim,
1693
+ italic,
1694
+ underline,
1695
+ strikethrough,
1696
+ inverse,
1697
+ hidden,
1698
+ reset,
1699
+ black,
1700
+ red,
1701
+ green,
1702
+ yellow,
1703
+ blue,
1704
+ magenta,
1705
+ cyan,
1706
+ white,
1707
+ blackBright,
1708
+ redBright,
1709
+ greenBright,
1710
+ yellowBright,
1711
+ blueBright,
1712
+ magentaBright,
1713
+ cyanBright,
1714
+ whiteBright,
1715
+ gray,
1716
+ grey,
1717
+ bgBlack,
1718
+ bgRed,
1719
+ bgGreen,
1720
+ bgYellow,
1721
+ bgBlue,
1722
+ bgMagenta,
1723
+ bgCyan,
1724
+ bgWhite,
1725
+ bgBlackBright,
1726
+ bgRedBright,
1727
+ bgGreenBright,
1728
+ bgYellowBright,
1729
+ bgBlueBright,
1730
+ bgMagentaBright,
1731
+ bgCyanBright,
1732
+ bgWhiteBright,
1733
+ bgGray,
1734
+ bgGrey
1735
+ });
1736
+ var index_default = chalk_default_default;
1737
+ export {
1738
+ BuilderPigment,
1739
+ bgBlack,
1740
+ bgBlackBright,
1741
+ bgBlue,
1742
+ bgBlueBright,
1743
+ bgCyan,
1744
+ bgCyanBright,
1745
+ bgGray,
1746
+ bgGreen,
1747
+ bgGreenBright,
1748
+ bgGrey,
1749
+ bgMagenta,
1750
+ bgMagentaBright,
1751
+ bgRed,
1752
+ bgRedBright,
1753
+ bgWhite,
1754
+ bgWhiteBright,
1755
+ bgYellow,
1756
+ bgYellowBright,
1757
+ black,
1758
+ blackBright,
1759
+ blue,
1760
+ blueBright,
1761
+ bold,
1762
+ compose,
1763
+ createKernel2 as createKernel,
1764
+ createPigment,
1765
+ cyan,
1766
+ cyanBright,
1767
+ index_default as default,
1768
+ detectColorSupport,
1769
+ detectPlatform,
1770
+ dim,
1771
+ gray,
1772
+ green,
1773
+ greenBright,
1774
+ grey,
1775
+ hasTTY,
1776
+ hexToRgb,
1777
+ hidden,
1778
+ hslToRgb,
1779
+ inverse,
1780
+ isBrowser,
1781
+ isCI,
1782
+ isNode,
1783
+ isWindows,
1784
+ italic,
1785
+ magenta,
1786
+ magentaBright,
1787
+ pigment,
1788
+ plugins_exports as plugins,
1789
+ red,
1790
+ redBright,
1791
+ reset,
1792
+ rgbToAnsi256,
1793
+ strikethrough,
1794
+ supportsColor,
1795
+ underline,
1796
+ validateHex,
1797
+ white,
1798
+ whiteBright,
1799
+ yellow,
1800
+ yellowBright
1801
+ };
1802
+ //# sourceMappingURL=index.js.map