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