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