@crustjs/style 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -58,6 +58,63 @@ console.log(applyStyle("critical error", boldRed));
58
58
 
59
59
  Nested styles are handled safely — no style bleed across boundaries.
60
60
 
61
+ ## Dynamic Colors (Truecolor)
62
+
63
+ Use any RGB or hex color via 24-bit truecolor ANSI sequences:
64
+
65
+ ```ts
66
+ import { rgb, bgRgb, hex, bgHex } from "@crustjs/style";
67
+
68
+ // RGB values (0–255)
69
+ console.log(rgb("ocean", 0, 128, 255));
70
+ console.log(bgRgb("warning", 255, 128, 0));
71
+
72
+ // Hex colors (#RGB or #RRGGBB)
73
+ console.log(hex("error", "#ff0000"));
74
+ console.log(hex("short", "#f00"));
75
+ console.log(bgHex("highlight", "#ff8800"));
76
+ ```
77
+
78
+ ### Pair Factories
79
+
80
+ Create reusable `AnsiPair` objects for composition:
81
+
82
+ ```ts
83
+ import { rgbCode, bgRgbCode, hexCode, bgHexCode, applyStyle, composeStyles, boldCode } from "@crustjs/style";
84
+
85
+ const coral = rgbCode(255, 127, 80);
86
+ console.log(applyStyle("coral text", coral));
87
+
88
+ const boldCoral = composeStyles(boldCode, hexCode("#ff7f50"));
89
+ console.log(applyStyle("bold coral", boldCoral));
90
+ ```
91
+
92
+ ### Style Instance
93
+
94
+ Dynamic colors on `createStyle` instances respect mode and truecolor detection:
95
+
96
+ ```ts
97
+ import { createStyle } from "@crustjs/style";
98
+
99
+ const s = createStyle({ mode: "always" });
100
+ console.log(s.rgb("text", 255, 0, 0));
101
+ console.log(s.hex("text", "#ff0000"));
102
+ console.log(s.bgRgb("text", 0, 128, 255));
103
+ console.log(s.bgHex("text", "#0080ff"));
104
+ ```
105
+
106
+ In `"auto"` mode, dynamic colors are emitted only when the terminal supports truecolor (detected via `COLORTERM=truecolor|24bit` or `TERM` containing `truecolor`, `24bit`, or `-direct`). When truecolor is not detected, dynamic color methods return plain text while standard 16-color methods continue to work.
107
+
108
+ In `"never"` mode, all dynamic color methods return plain text. In `"always"` mode, truecolor sequences are always emitted.
109
+
110
+ ### Terminal Compatibility
111
+
112
+ Dynamic colors use truecolor (24-bit) ANSI sequences. There is no automatic fallback to 256 or 16 colors. On terminals that do not support truecolor:
113
+
114
+ - Colors may be approximated to the nearest supported color
115
+ - Colors may be silently ignored (text renders in default color)
116
+ - No runtime errors will occur
117
+
61
118
  ## Color Modes
62
119
 
63
120
  Control when ANSI codes are emitted using `createStyle`:
@@ -92,6 +149,12 @@ const testStyle = createStyle({
92
149
  mode: "auto",
93
150
  overrides: { isTTY: true, noColor: undefined },
94
151
  });
152
+
153
+ // Include truecolor overrides for dynamic color testing
154
+ const truecolorStyle = createStyle({
155
+ mode: "auto",
156
+ overrides: { isTTY: true, noColor: undefined, colorTerm: "truecolor" },
157
+ });
95
158
  ```
96
159
 
97
160
  ## Text Utilities
package/dist/index.d.ts CHANGED
@@ -312,6 +312,18 @@ interface CapabilityOverrides {
312
312
  readonly noColor?: string | undefined;
313
313
  }
314
314
  /**
315
+ * Truecolor capability overrides for deterministic testing.
316
+ *
317
+ * These override environment variable checks used by
318
+ * {@link resolveTrueColor} to detect 24-bit color support.
319
+ */
320
+ interface TrueColorOverrides {
321
+ /** Override `process.env.COLORTERM`. */
322
+ readonly colorTerm?: string | undefined;
323
+ /** Override `process.env.TERM`. */
324
+ readonly term?: string | undefined;
325
+ }
326
+ /**
315
327
  * Configuration options for creating a style instance.
316
328
  *
317
329
  * @example
@@ -323,7 +335,7 @@ interface StyleOptions {
323
335
  /** Color emission mode. Defaults to `"auto"`. */
324
336
  readonly mode?: ColorMode;
325
337
  /** Capability overrides for deterministic testing. */
326
- readonly overrides?: CapabilityOverrides;
338
+ readonly overrides?: CapabilityOverrides & TrueColorOverrides;
327
339
  }
328
340
  /**
329
341
  * A style function that applies an ANSI style pair to text,
@@ -360,8 +372,18 @@ type StyleMethodName2 = StyleMethodName;
360
372
  interface StyleInstance extends StyleMethodMap {
361
373
  /** Whether ANSI codes will be emitted by this instance. */
362
374
  readonly enabled: boolean;
375
+ /** Whether truecolor (24-bit) sequences will be emitted by this instance. */
376
+ readonly trueColorEnabled: boolean;
363
377
  /** Apply an arbitrary ANSI pair to text, respecting the color mode. */
364
378
  readonly apply: (text: string, pair: AnsiPair) => string;
379
+ /** Apply a truecolor foreground RGB color to text. */
380
+ readonly rgb: (text: string, r: number, g: number, b: number) => string;
381
+ /** Apply a truecolor background RGB color to text. */
382
+ readonly bgRgb: (text: string, r: number, g: number, b: number) => string;
383
+ /** Apply a truecolor foreground hex color to text. */
384
+ readonly hex: (text: string, hexColor: string) => string;
385
+ /** Apply a truecolor background hex color to text. */
386
+ readonly bgHex: (text: string, hexColor: string) => string;
365
387
  }
366
388
  /**
367
389
  * Resolve whether ANSI color codes should be emitted.
@@ -391,6 +413,35 @@ interface StyleInstance extends StyleMethodMap {
391
413
  * ```
392
414
  */
393
415
  declare function resolveCapability(mode: ColorMode, overrides?: CapabilityOverrides): boolean;
416
+ /**
417
+ * Resolve whether the terminal supports truecolor (24-bit) ANSI sequences.
418
+ *
419
+ * Detection heuristics (checked in order):
420
+ * 1. `COLORTERM` environment variable is `"truecolor"` or `"24bit"`.
421
+ * 2. `TERM` environment variable contains `"24bit"`, `"truecolor"`, or `"-direct"`.
422
+ *
423
+ * In `"always"` mode, returns `true` unconditionally.
424
+ * In `"never"` mode, returns `false` unconditionally.
425
+ * In `"auto"` mode, requires base color to be enabled **and** truecolor
426
+ * to be detected.
427
+ *
428
+ * @param mode - The color emission mode.
429
+ * @param overrides - Optional overrides for deterministic testing.
430
+ * @returns `true` if truecolor sequences should be emitted.
431
+ *
432
+ * @example
433
+ * ```ts
434
+ * resolveTrueColor("auto"); // true if TTY + truecolor env detected
435
+ * resolveTrueColor("always"); // true
436
+ * resolveTrueColor("never"); // false
437
+ * resolveTrueColor("auto", {
438
+ * isTTY: true,
439
+ * noColor: undefined,
440
+ * colorTerm: "truecolor",
441
+ * }); // true
442
+ * ```
443
+ */
444
+ declare function resolveTrueColor(mode: ColorMode, overrides?: CapabilityOverrides & TrueColorOverrides): boolean;
394
445
  /** Apply black foreground color. */
395
446
  declare function black2(text: string): string;
396
447
  /** Apply red foreground color. */
@@ -506,6 +557,150 @@ declare function createStyle(options?: StyleOptions): StyleInstance;
506
557
  */
507
558
  declare const style: StyleInstance;
508
559
  /**
560
+ * Parse a hex color string into RGB channel values.
561
+ *
562
+ * Supports `#RGB` (shorthand) and `#RRGGBB` (full) formats.
563
+ * The `#` prefix is required.
564
+ *
565
+ * @param hex - The hex color string.
566
+ * @returns A tuple of `[r, g, b]` channel values (0–255).
567
+ * @throws {TypeError} If the string is not a valid hex color.
568
+ *
569
+ * @example
570
+ * ```ts
571
+ * parseHex("#ff0000"); // [255, 0, 0]
572
+ * parseHex("#f00"); // [255, 0, 0]
573
+ * ```
574
+ */
575
+ declare function parseHex(hex: string): [r: number, g: number, b: number];
576
+ /**
577
+ * Create an {@link AnsiPair} for a truecolor foreground RGB color.
578
+ *
579
+ * Uses the ANSI escape sequence `\x1b[38;2;R;G;Bm` with close `\x1b[39m`.
580
+ *
581
+ * @param r - Red channel (0–255).
582
+ * @param g - Green channel (0–255).
583
+ * @param b - Blue channel (0–255).
584
+ * @returns An ANSI pair for the specified foreground color.
585
+ * @throws {RangeError} If any channel value is invalid.
586
+ *
587
+ * @example
588
+ * ```ts
589
+ * const pair = rgbCode(255, 0, 0);
590
+ * applyStyle("error", pair); // red foreground
591
+ * ```
592
+ */
593
+ declare function rgbCode(r: number, g: number, b: number): AnsiPair;
594
+ /**
595
+ * Create an {@link AnsiPair} for a truecolor background RGB color.
596
+ *
597
+ * Uses the ANSI escape sequence `\x1b[48;2;R;G;Bm` with close `\x1b[49m`.
598
+ *
599
+ * @param r - Red channel (0–255).
600
+ * @param g - Green channel (0–255).
601
+ * @param b - Blue channel (0–255).
602
+ * @returns An ANSI pair for the specified background color.
603
+ * @throws {RangeError} If any channel value is invalid.
604
+ *
605
+ * @example
606
+ * ```ts
607
+ * const pair = bgRgbCode(255, 128, 0);
608
+ * applyStyle("warning", pair); // orange background
609
+ * ```
610
+ */
611
+ declare function bgRgbCode(r: number, g: number, b: number): AnsiPair;
612
+ /**
613
+ * Create an {@link AnsiPair} for a truecolor foreground hex color.
614
+ *
615
+ * @param hex - Hex color string (`#RGB` or `#RRGGBB`).
616
+ * @returns An ANSI pair for the specified foreground color.
617
+ * @throws {TypeError} If the hex string is invalid.
618
+ *
619
+ * @example
620
+ * ```ts
621
+ * const pair = hexCode("#ff0000");
622
+ * applyStyle("error", pair); // red foreground
623
+ * ```
624
+ */
625
+ declare function hexCode(hex: string): AnsiPair;
626
+ /**
627
+ * Create an {@link AnsiPair} for a truecolor background hex color.
628
+ *
629
+ * @param hex - Hex color string (`#RGB` or `#RRGGBB`).
630
+ * @returns An ANSI pair for the specified background color.
631
+ * @throws {TypeError} If the hex string is invalid.
632
+ *
633
+ * @example
634
+ * ```ts
635
+ * const pair = bgHexCode("#ff8800");
636
+ * applyStyle("warning", pair); // orange background
637
+ * ```
638
+ */
639
+ declare function bgHexCode(hex: string): AnsiPair;
640
+ /**
641
+ * Apply a truecolor foreground RGB color to text.
642
+ *
643
+ * @param text - The text to style.
644
+ * @param r - Red channel (0–255).
645
+ * @param g - Green channel (0–255).
646
+ * @param b - Blue channel (0–255).
647
+ * @returns The styled string.
648
+ * @throws {RangeError} If any channel value is invalid.
649
+ *
650
+ * @example
651
+ * ```ts
652
+ * rgb("error", 255, 0, 0); // red text
653
+ * rgb("ocean", 0, 128, 255); // blue text
654
+ * ```
655
+ */
656
+ declare function rgb(text: string, r: number, g: number, b: number): string;
657
+ /**
658
+ * Apply a truecolor background RGB color to text.
659
+ *
660
+ * @param text - The text to style.
661
+ * @param r - Red channel (0–255).
662
+ * @param g - Green channel (0–255).
663
+ * @param b - Blue channel (0–255).
664
+ * @returns The styled string.
665
+ * @throws {RangeError} If any channel value is invalid.
666
+ *
667
+ * @example
668
+ * ```ts
669
+ * bgRgb("warning", 255, 128, 0); // orange background
670
+ * ```
671
+ */
672
+ declare function bgRgb2(text: string, r: number, g: number, b: number): string;
673
+ /**
674
+ * Apply a truecolor foreground hex color to text.
675
+ *
676
+ * @param text - The text to style.
677
+ * @param hexColor - Hex color string (`#RGB` or `#RRGGBB`).
678
+ * @returns The styled string.
679
+ * @throws {TypeError} If the hex string is invalid.
680
+ *
681
+ * @example
682
+ * ```ts
683
+ * hex("error", "#ff0000"); // red text
684
+ * hex("ocean", "#0080ff"); // blue text
685
+ * hex("short", "#f00"); // red text (shorthand)
686
+ * ```
687
+ */
688
+ declare function hex(text: string, hexColor: string): string;
689
+ /**
690
+ * Apply a truecolor background hex color to text.
691
+ *
692
+ * @param text - The text to style.
693
+ * @param hexColor - Hex color string (`#RGB` or `#RRGGBB`).
694
+ * @returns The styled string.
695
+ * @throws {TypeError} If the hex string is invalid.
696
+ *
697
+ * @example
698
+ * ```ts
699
+ * bgHex("warning", "#ff8800"); // orange background
700
+ * ```
701
+ */
702
+ declare function bgHex2(text: string, hexColor: string): string;
703
+ /**
509
704
  * Apply **bold** (increased intensity) to text.
510
705
  *
511
706
  * @example
@@ -949,4 +1144,4 @@ declare function createMarkdownTheme(options?: CreateMarkdownThemeOptions): Mark
949
1144
  * ```
950
1145
  */
951
1146
  declare const defaultTheme: MarkdownTheme;
952
- export { yellow as yellowCode, yellow2 as yellow, wrapText, white as whiteCode, white2 as white, visibleWidth, unorderedList, underline as underlineCode, underline2 as underline, taskList, table, style, stripAnsi, strikethrough as strikethroughCode, strikethrough2 as strikethrough, resolveCapability, reset, red as redCode, red2 as red, padStart, padEnd, orderedList, magenta as magentaCode, magenta2 as magenta, italic as italicCode, italic2 as italic, inverse as inverseCode, inverse2 as inverse, hidden as hiddenCode, hidden2 as hidden, green as greenCode, green2 as green, gray as grayCode, gray2 as gray, dim as dimCode, dim2 as dim, defaultTheme, cyan as cyanCode, cyan2 as cyan, createStyle, createMarkdownTheme, composeStyles, center, buildDefaultMarkdownTheme, brightYellow as brightYellowCode, brightYellow2 as brightYellow, brightWhite as brightWhiteCode, brightWhite2 as brightWhite, brightRed as brightRedCode, brightRed2 as brightRed, brightMagenta as brightMagentaCode, brightMagenta2 as brightMagenta, brightGreen as brightGreenCode, brightGreen2 as brightGreen, brightCyan as brightCyanCode, brightCyan2 as brightCyan, brightBlue as brightBlueCode, brightBlue2 as brightBlue, bold as boldCode, bold2 as bold, blue as blueCode, blue2 as blue, black as blackCode, black2 as black, bgYellow as bgYellowCode, bgYellow2 as bgYellow, bgWhite as bgWhiteCode, bgWhite2 as bgWhite, bgRed as bgRedCode, bgRed2 as bgRed, bgMagenta as bgMagentaCode, bgMagenta2 as bgMagenta, bgGreen as bgGreenCode, bgGreen2 as bgGreen, bgCyan as bgCyanCode, bgCyan2 as bgCyan, bgBrightYellow as bgBrightYellowCode, bgBrightYellow2 as bgBrightYellow, bgBrightWhite as bgBrightWhiteCode, bgBrightWhite2 as bgBrightWhite, bgBrightRed as bgBrightRedCode, bgBrightRed2 as bgBrightRed, bgBrightMagenta as bgBrightMagentaCode, bgBrightMagenta2 as bgBrightMagenta, bgBrightGreen as bgBrightGreenCode, bgBrightGreen2 as bgBrightGreen, bgBrightCyan as bgBrightCyanCode, bgBrightCyan2 as bgBrightCyan, bgBrightBlue as bgBrightBlueCode, bgBrightBlue2 as bgBrightBlue, bgBrightBlack as bgBrightBlackCode, bgBrightBlack2 as bgBrightBlack, bgBlue as bgBlueCode, bgBlue2 as bgBlue, bgBlack as bgBlackCode, bgBlack2 as bgBlack, applyStyle, WrapOptions, UnorderedListOptions, ThemeSlotFn, TaskListOptions, TaskListItem, TableOptions, StyleOptions, StyleInstance, StyleFn, PartialMarkdownTheme, OrderedListOptions, MarkdownTheme, CreateMarkdownThemeOptions, ColumnAlignment, ColorMode, CapabilityOverrides, AnsiPair };
1147
+ export { yellow as yellowCode, yellow2 as yellow, wrapText, white as whiteCode, white2 as white, visibleWidth, unorderedList, underline as underlineCode, underline2 as underline, taskList, table, style, stripAnsi, strikethrough as strikethroughCode, strikethrough2 as strikethrough, rgbCode, rgb, resolveTrueColor, resolveCapability, reset, red as redCode, red2 as red, parseHex, padStart, padEnd, orderedList, magenta as magentaCode, magenta2 as magenta, italic as italicCode, italic2 as italic, inverse as inverseCode, inverse2 as inverse, hidden as hiddenCode, hidden2 as hidden, hexCode, hex, green as greenCode, green2 as green, gray as grayCode, gray2 as gray, dim as dimCode, dim2 as dim, defaultTheme, cyan as cyanCode, cyan2 as cyan, createStyle, createMarkdownTheme, composeStyles, center, buildDefaultMarkdownTheme, brightYellow as brightYellowCode, brightYellow2 as brightYellow, brightWhite as brightWhiteCode, brightWhite2 as brightWhite, brightRed as brightRedCode, brightRed2 as brightRed, brightMagenta as brightMagentaCode, brightMagenta2 as brightMagenta, brightGreen as brightGreenCode, brightGreen2 as brightGreen, brightCyan as brightCyanCode, brightCyan2 as brightCyan, brightBlue as brightBlueCode, brightBlue2 as brightBlue, bold as boldCode, bold2 as bold, blue as blueCode, blue2 as blue, black as blackCode, black2 as black, bgYellow as bgYellowCode, bgYellow2 as bgYellow, bgWhite as bgWhiteCode, bgWhite2 as bgWhite, bgRgbCode, bgRgb2 as bgRgb, bgRed as bgRedCode, bgRed2 as bgRed, bgMagenta as bgMagentaCode, bgMagenta2 as bgMagenta, bgHexCode, bgHex2 as bgHex, bgGreen as bgGreenCode, bgGreen2 as bgGreen, bgCyan as bgCyanCode, bgCyan2 as bgCyan, bgBrightYellow as bgBrightYellowCode, bgBrightYellow2 as bgBrightYellow, bgBrightWhite as bgBrightWhiteCode, bgBrightWhite2 as bgBrightWhite, bgBrightRed as bgBrightRedCode, bgBrightRed2 as bgBrightRed, bgBrightMagenta as bgBrightMagentaCode, bgBrightMagenta2 as bgBrightMagenta, bgBrightGreen as bgBrightGreenCode, bgBrightGreen2 as bgBrightGreen, bgBrightCyan as bgBrightCyanCode, bgBrightCyan2 as bgBrightCyan, bgBrightBlue as bgBrightBlueCode, bgBrightBlue2 as bgBrightBlue, bgBrightBlack as bgBrightBlackCode, bgBrightBlack2 as bgBrightBlack, bgBlue as bgBlueCode, bgBlue2 as bgBlue, bgBlack as bgBlackCode, bgBlack2 as bgBlack, applyStyle, WrapOptions, UnorderedListOptions, TrueColorOverrides, ThemeSlotFn, TaskListOptions, TaskListItem, TableOptions, StyleOptions, StyleInstance, StyleFn, PartialMarkdownTheme, OrderedListOptions, MarkdownTheme, CreateMarkdownThemeOptions, ColumnAlignment, ColorMode, CapabilityOverrides, AnsiPair };
package/dist/index.js CHANGED
@@ -1,791 +1,10 @@
1
1
  // @bun
2
- var __defProp = Object.defineProperty;
3
- var __export = (target, all) => {
4
- for (var name in all)
5
- __defProp(target, name, {
6
- get: all[name],
7
- enumerable: true,
8
- configurable: true,
9
- set: (newValue) => all[name] = () => newValue
10
- });
11
- };
12
-
13
- // src/ansiCodes.ts
14
- var exports_ansiCodes = {};
15
- __export(exports_ansiCodes, {
16
- yellow: () => yellow,
17
- white: () => white,
18
- underline: () => underline,
19
- strikethrough: () => strikethrough,
20
- reset: () => reset,
21
- red: () => red,
22
- magenta: () => magenta,
23
- italic: () => italic,
24
- inverse: () => inverse,
25
- hidden: () => hidden,
26
- green: () => green,
27
- gray: () => gray,
28
- dim: () => dim,
29
- cyan: () => cyan,
30
- brightYellow: () => brightYellow,
31
- brightWhite: () => brightWhite,
32
- brightRed: () => brightRed,
33
- brightMagenta: () => brightMagenta,
34
- brightGreen: () => brightGreen,
35
- brightCyan: () => brightCyan,
36
- brightBlue: () => brightBlue,
37
- bold: () => bold,
38
- blue: () => blue,
39
- black: () => black,
40
- bgYellow: () => bgYellow,
41
- bgWhite: () => bgWhite,
42
- bgRed: () => bgRed,
43
- bgMagenta: () => bgMagenta,
44
- bgGreen: () => bgGreen,
45
- bgCyan: () => bgCyan,
46
- bgBrightYellow: () => bgBrightYellow,
47
- bgBrightWhite: () => bgBrightWhite,
48
- bgBrightRed: () => bgBrightRed,
49
- bgBrightMagenta: () => bgBrightMagenta,
50
- bgBrightGreen: () => bgBrightGreen,
51
- bgBrightCyan: () => bgBrightCyan,
52
- bgBrightBlue: () => bgBrightBlue,
53
- bgBrightBlack: () => bgBrightBlack,
54
- bgBlue: () => bgBlue,
55
- bgBlack: () => bgBlack
56
- });
57
- function pair(open, close) {
58
- return { open: `\x1B[${open}m`, close: `\x1B[${close}m` };
59
- }
60
- var reset = pair(0, 0);
61
- var bold = pair(1, 22);
62
- var dim = pair(2, 22);
63
- var italic = pair(3, 23);
64
- var underline = pair(4, 24);
65
- var inverse = pair(7, 27);
66
- var hidden = pair(8, 28);
67
- var strikethrough = pair(9, 29);
68
- var black = pair(30, 39);
69
- var red = pair(31, 39);
70
- var green = pair(32, 39);
71
- var yellow = pair(33, 39);
72
- var blue = pair(34, 39);
73
- var magenta = pair(35, 39);
74
- var cyan = pair(36, 39);
75
- var white = pair(37, 39);
76
- var gray = pair(90, 39);
77
- var brightRed = pair(91, 39);
78
- var brightGreen = pair(92, 39);
79
- var brightYellow = pair(93, 39);
80
- var brightBlue = pair(94, 39);
81
- var brightMagenta = pair(95, 39);
82
- var brightCyan = pair(96, 39);
83
- var brightWhite = pair(97, 39);
84
- var bgBlack = pair(40, 49);
85
- var bgRed = pair(41, 49);
86
- var bgGreen = pair(42, 49);
87
- var bgYellow = pair(43, 49);
88
- var bgBlue = pair(44, 49);
89
- var bgMagenta = pair(45, 49);
90
- var bgCyan = pair(46, 49);
91
- var bgWhite = pair(47, 49);
92
- var bgBrightBlack = pair(100, 49);
93
- var bgBrightRed = pair(101, 49);
94
- var bgBrightGreen = pair(102, 49);
95
- var bgBrightYellow = pair(103, 49);
96
- var bgBrightBlue = pair(104, 49);
97
- var bgBrightMagenta = pair(105, 49);
98
- var bgBrightCyan = pair(106, 49);
99
- var bgBrightWhite = pair(107, 49);
100
- // src/text/stripAnsi.ts
101
- var ANSI_REGEX = /[\x1b\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]/g;
102
- function stripAnsi(text) {
103
- return text.replace(ANSI_REGEX, "");
104
- }
105
-
106
- // src/text/width.ts
107
- function isFullWidth(codePoint) {
108
- return codePoint >= 19968 && codePoint <= 40959 || codePoint >= 13312 && codePoint <= 19903 || codePoint >= 131072 && codePoint <= 173791 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 65281 && codePoint <= 65376 || codePoint >= 65504 && codePoint <= 65510 || codePoint >= 11904 && codePoint <= 12031 || codePoint >= 12032 && codePoint <= 12255 || codePoint >= 12288 && codePoint <= 12351 || codePoint >= 12352 && codePoint <= 12447 || codePoint >= 12448 && codePoint <= 12543 || codePoint >= 12544 && codePoint <= 12591 || codePoint >= 12592 && codePoint <= 12687 || codePoint >= 12800 && codePoint <= 13055 || codePoint >= 13056 && codePoint <= 13311 || codePoint >= 44032 && codePoint <= 55215 || codePoint >= 65072 && codePoint <= 65103;
109
- }
110
- function visibleWidth(text) {
111
- const plain = stripAnsi(text);
112
- let width = 0;
113
- for (const char of plain) {
114
- const codePoint = char.codePointAt(0);
115
- if (codePoint === undefined) {
116
- continue;
117
- }
118
- width += isFullWidth(codePoint) ? 2 : 1;
119
- }
120
- return width;
121
- }
122
-
123
- // src/blocks/lists.ts
124
- function indentMultiline(text, contentIndent) {
125
- const lines = text.split(`
126
- `);
127
- if (lines.length <= 1) {
128
- return text;
129
- }
130
- const padding = " ".repeat(contentIndent);
131
- return lines.map((line, idx) => idx === 0 ? line : padding + line).join(`
132
- `);
133
- }
134
- function unorderedList(items, options) {
135
- const marker = options?.marker ?? "\u2022";
136
- const markerGap = options?.markerGap ?? 1;
137
- const indent = options?.indent ?? 0;
138
- const prefix = " ".repeat(indent);
139
- const gap = " ".repeat(markerGap);
140
- const markerWidth = visibleWidth(marker);
141
- const contentIndent = indent + markerWidth + markerGap;
142
- return items.map((item) => {
143
- const adjusted = indentMultiline(item, contentIndent);
144
- return `${prefix}${marker}${gap}${adjusted}`;
145
- }).join(`
146
- `);
147
- }
148
- function orderedList(items, options) {
149
- const start = options?.start ?? 1;
150
- const markerGap = options?.markerGap ?? 1;
151
- const indent = options?.indent ?? 0;
152
- if (items.length === 0) {
153
- return "";
154
- }
155
- const prefix = " ".repeat(indent);
156
- const gap = " ".repeat(markerGap);
157
- const lastIndex = start + items.length - 1;
158
- const maxMarkerWidth = `${lastIndex}.`.length;
159
- return items.map((item, idx) => {
160
- const index = start + idx;
161
- const markerText = `${index}.`;
162
- const paddedMarker = markerText.padStart(maxMarkerWidth, " ");
163
- const contentIndent = indent + maxMarkerWidth + markerGap;
164
- const adjusted = indentMultiline(item, contentIndent);
165
- return `${prefix}${paddedMarker}${gap}${adjusted}`;
166
- }).join(`
167
- `);
168
- }
169
- function taskList(items, options) {
170
- const checkedMarker = options?.checkedMarker ?? "[x]";
171
- const uncheckedMarker = options?.uncheckedMarker ?? "[ ]";
172
- const markerGap = options?.markerGap ?? 1;
173
- const indent = options?.indent ?? 0;
174
- const prefix = " ".repeat(indent);
175
- const gap = " ".repeat(markerGap);
176
- const markerWidth = Math.max(visibleWidth(checkedMarker), visibleWidth(uncheckedMarker));
177
- const contentIndent = indent + markerWidth + markerGap;
178
- return items.map((item) => {
179
- const marker = item.checked ? checkedMarker : uncheckedMarker;
180
- const adjusted = indentMultiline(item.text, contentIndent);
181
- return `${prefix}${marker}${gap}${adjusted}`;
182
- }).join(`
183
- `);
184
- }
185
- // src/text/pad.ts
186
- function padStart(text, width, fillChar = " ") {
187
- const currentWidth = visibleWidth(text);
188
- if (currentWidth >= width) {
189
- return text;
190
- }
191
- const padding = fillChar.repeat(width - currentWidth);
192
- return padding + text;
193
- }
194
- function padEnd(text, width, fillChar = " ") {
195
- const currentWidth = visibleWidth(text);
196
- if (currentWidth >= width) {
197
- return text;
198
- }
199
- const padding = fillChar.repeat(width - currentWidth);
200
- return text + padding;
201
- }
202
- function center(text, width, fillChar = " ") {
203
- const currentWidth = visibleWidth(text);
204
- if (currentWidth >= width) {
205
- return text;
206
- }
207
- const totalPadding = width - currentWidth;
208
- const leftPadding = Math.floor(totalPadding / 2);
209
- const rightPadding = totalPadding - leftPadding;
210
- return fillChar.repeat(leftPadding) + text + fillChar.repeat(rightPadding);
211
- }
212
-
213
- // src/blocks/tables.ts
214
- function computeColumnWidths(headers, rows, minWidth) {
215
- const columnCount = headers.length;
216
- const widths = new Array(columnCount).fill(minWidth);
217
- for (let col = 0;col < columnCount; col++) {
218
- const header = headers[col];
219
- if (header !== undefined) {
220
- widths[col] = Math.max(widths[col] ?? 0, visibleWidth(header));
221
- }
222
- }
223
- for (const row of rows) {
224
- for (let col = 0;col < columnCount; col++) {
225
- const cell = row[col];
226
- if (cell !== undefined) {
227
- widths[col] = Math.max(widths[col] ?? 0, visibleWidth(cell));
228
- }
229
- }
230
- }
231
- return widths;
232
- }
233
- function alignCell(value, width, alignment) {
234
- switch (alignment) {
235
- case "right":
236
- return padStart(value, width);
237
- case "center":
238
- return center(value, width);
239
- default:
240
- return padEnd(value, width);
241
- }
242
- }
243
- function formatRow(cells, columnWidths, alignments, cellPadding, borderChar) {
244
- const pad = " ".repeat(cellPadding);
245
- const formattedCells = columnWidths.map((width, col) => {
246
- const cell = cells[col] ?? "";
247
- const alignment = alignments[col] ?? "left";
248
- const aligned = alignCell(cell, width, alignment);
249
- return `${pad}${aligned}${pad}`;
250
- });
251
- return `${borderChar}${formattedCells.join(borderChar)}${borderChar}`;
252
- }
253
- function formatSeparator(columnWidths, cellPadding, separatorChar, borderChar) {
254
- const segments = columnWidths.map((width) => {
255
- return separatorChar.repeat(width + cellPadding * 2);
256
- });
257
- return `${borderChar}${segments.join(borderChar)}${borderChar}`;
258
- }
259
- function table(headers, rows, options) {
260
- const alignments = options?.align ?? [];
261
- const minColumnWidth = options?.minColumnWidth ?? 0;
262
- const cellPadding = options?.cellPadding ?? 1;
263
- const separatorChar = options?.separatorChar ?? "-";
264
- const borderChar = options?.borderChar ?? "|";
265
- const columnWidths = computeColumnWidths(headers, rows, minColumnWidth);
266
- const lines = [];
267
- lines.push(formatRow(headers, columnWidths, alignments, cellPadding, borderChar));
268
- lines.push(formatSeparator(columnWidths, cellPadding, separatorChar, borderChar));
269
- for (const row of rows) {
270
- lines.push(formatRow(row, columnWidths, alignments, cellPadding, borderChar));
271
- }
272
- return lines.join(`
273
- `);
274
- }
275
- // src/capability.ts
276
- function resolveCapability(mode, overrides) {
277
- if (mode === "always") {
278
- return true;
279
- }
280
- if (mode === "never") {
281
- return false;
282
- }
283
- const isTTY = overrides?.isTTY ?? process.stdout?.isTTY ?? false;
284
- const noColor = overrides?.noColor !== undefined ? overrides.noColor : process.env.NO_COLOR;
285
- if (noColor !== undefined) {
286
- return false;
287
- }
288
- return isTTY;
289
- }
290
- // src/styleEngine.ts
291
- function applyStyle(text, style) {
292
- if (text === "") {
293
- return "";
294
- }
295
- const { open, close } = style;
296
- if (text.includes(close)) {
297
- text = text.replaceAll(close, close + open);
298
- }
299
- return open + text + close;
300
- }
301
- function composeStyles(...styles) {
302
- return {
303
- open: styles.map((s) => s.open).join(""),
304
- close: styles.map((s) => s.close).reverse().join("")
305
- };
306
- }
307
-
308
- // src/colors.ts
309
- function black2(text) {
310
- return applyStyle(text, black);
311
- }
312
- function red2(text) {
313
- return applyStyle(text, red);
314
- }
315
- function green2(text) {
316
- return applyStyle(text, green);
317
- }
318
- function yellow2(text) {
319
- return applyStyle(text, yellow);
320
- }
321
- function blue2(text) {
322
- return applyStyle(text, blue);
323
- }
324
- function magenta2(text) {
325
- return applyStyle(text, magenta);
326
- }
327
- function cyan2(text) {
328
- return applyStyle(text, cyan);
329
- }
330
- function white2(text) {
331
- return applyStyle(text, white);
332
- }
333
- function gray2(text) {
334
- return applyStyle(text, gray);
335
- }
336
- function brightRed2(text) {
337
- return applyStyle(text, brightRed);
338
- }
339
- function brightGreen2(text) {
340
- return applyStyle(text, brightGreen);
341
- }
342
- function brightYellow2(text) {
343
- return applyStyle(text, brightYellow);
344
- }
345
- function brightBlue2(text) {
346
- return applyStyle(text, brightBlue);
347
- }
348
- function brightMagenta2(text) {
349
- return applyStyle(text, brightMagenta);
350
- }
351
- function brightCyan2(text) {
352
- return applyStyle(text, brightCyan);
353
- }
354
- function brightWhite2(text) {
355
- return applyStyle(text, brightWhite);
356
- }
357
- function bgBlack2(text) {
358
- return applyStyle(text, bgBlack);
359
- }
360
- function bgRed2(text) {
361
- return applyStyle(text, bgRed);
362
- }
363
- function bgGreen2(text) {
364
- return applyStyle(text, bgGreen);
365
- }
366
- function bgYellow2(text) {
367
- return applyStyle(text, bgYellow);
368
- }
369
- function bgBlue2(text) {
370
- return applyStyle(text, bgBlue);
371
- }
372
- function bgMagenta2(text) {
373
- return applyStyle(text, bgMagenta);
374
- }
375
- function bgCyan2(text) {
376
- return applyStyle(text, bgCyan);
377
- }
378
- function bgWhite2(text) {
379
- return applyStyle(text, bgWhite);
380
- }
381
- function bgBrightBlack2(text) {
382
- return applyStyle(text, bgBrightBlack);
383
- }
384
- function bgBrightRed2(text) {
385
- return applyStyle(text, bgBrightRed);
386
- }
387
- function bgBrightGreen2(text) {
388
- return applyStyle(text, bgBrightGreen);
389
- }
390
- function bgBrightYellow2(text) {
391
- return applyStyle(text, bgBrightYellow);
392
- }
393
- function bgBrightBlue2(text) {
394
- return applyStyle(text, bgBrightBlue);
395
- }
396
- function bgBrightMagenta2(text) {
397
- return applyStyle(text, bgBrightMagenta);
398
- }
399
- function bgBrightCyan2(text) {
400
- return applyStyle(text, bgBrightCyan);
401
- }
402
- function bgBrightWhite2(text) {
403
- return applyStyle(text, bgBrightWhite);
404
- }
405
- // src/styleMethodRegistry.ts
406
- function readStyleMethodPairs() {
407
- const { reset: _reset, ...pairs } = exports_ansiCodes;
408
- return pairs;
409
- }
410
- var styleMethodPairs = Object.freeze(readStyleMethodPairs());
411
- var styleMethodNames = Object.freeze(Object.keys(styleMethodPairs));
412
- function stylePairFor(name) {
413
- return styleMethodPairs[name];
414
- }
415
-
416
- // src/createStyle.ts
417
- function applyChain(text, methodNames, enabled) {
418
- if (!enabled || text === "") {
419
- return text;
420
- }
421
- let result = text;
422
- for (let i = methodNames.length - 1;i >= 0; i--) {
423
- const methodName = methodNames[i];
424
- if (methodName === undefined) {
425
- continue;
426
- }
427
- result = applyStyle(result, stylePairFor(methodName));
428
- }
429
- return result;
430
- }
431
- function buildChainableStyleFactory(enabled) {
432
- const cache = new Map;
433
- function makeKey(methodNames) {
434
- return methodNames.join("|");
435
- }
436
- function createChainableStyle(methodNames) {
437
- const key = makeKey(methodNames);
438
- const cached = cache.get(key);
439
- if (cached) {
440
- return cached;
441
- }
442
- const styleFn = (text) => applyChain(text, methodNames, enabled);
443
- cache.set(key, styleFn);
444
- for (const name of styleMethodNames) {
445
- Object.defineProperty(styleFn, name, {
446
- configurable: false,
447
- enumerable: true,
448
- get() {
449
- return createChainableStyle([...methodNames, name]);
450
- }
451
- });
452
- }
453
- return Object.freeze(styleFn);
454
- }
455
- return createChainableStyle;
456
- }
457
- function buildStyleMethods(createChainableStyle) {
458
- const methods = {};
459
- for (const methodName of styleMethodNames) {
460
- methods[methodName] = createChainableStyle([methodName]);
461
- }
462
- return methods;
463
- }
464
- function createStyle(options) {
465
- const mode = options?.mode ?? "auto";
466
- const enabled = resolveCapability(mode, options?.overrides);
467
- const createChainableStyle = buildChainableStyleFactory(enabled);
468
- const methods = buildStyleMethods(createChainableStyle);
469
- const instance = {
470
- enabled,
471
- apply: enabled ? (text, pair2) => applyStyle(text, pair2) : (text, _pair) => text,
472
- ...methods
473
- };
474
- return Object.freeze(instance);
475
- }
476
- var style = createStyle();
477
- // src/modifiers.ts
478
- function bold2(text) {
479
- return applyStyle(text, bold);
480
- }
481
- function dim2(text) {
482
- return applyStyle(text, dim);
483
- }
484
- function italic2(text) {
485
- return applyStyle(text, italic);
486
- }
487
- function underline2(text) {
488
- return applyStyle(text, underline);
489
- }
490
- function inverse2(text) {
491
- return applyStyle(text, inverse);
492
- }
493
- function hidden2(text) {
494
- return applyStyle(text, hidden);
495
- }
496
- function strikethrough2(text) {
497
- return applyStyle(text, strikethrough);
498
- }
499
- // src/text/wrap.ts
500
- var ANSI_SEQUENCE = /[\x1b\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]/;
501
- function isFullWidth2(codePoint) {
502
- return codePoint >= 19968 && codePoint <= 40959 || codePoint >= 13312 && codePoint <= 19903 || codePoint >= 131072 && codePoint <= 173791 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 65281 && codePoint <= 65376 || codePoint >= 65504 && codePoint <= 65510 || codePoint >= 11904 && codePoint <= 12031 || codePoint >= 12032 && codePoint <= 12255 || codePoint >= 12288 && codePoint <= 12351 || codePoint >= 12352 && codePoint <= 12447 || codePoint >= 12448 && codePoint <= 12543 || codePoint >= 12544 && codePoint <= 12591 || codePoint >= 12592 && codePoint <= 12687 || codePoint >= 12800 && codePoint <= 13055 || codePoint >= 13056 && codePoint <= 13311 || codePoint >= 44032 && codePoint <= 55215 || codePoint >= 65072 && codePoint <= 65103;
503
- }
504
- function isReset(seq) {
505
- return seq === "\x1B[0m";
506
- }
507
- function isSGR(seq) {
508
- return seq.endsWith("m") && seq.startsWith("\x1B[");
509
- }
510
- function wrapText(text, width, options) {
511
- if (width <= 0) {
512
- return text;
513
- }
514
- const wordBreak = options?.wordBreak ?? true;
515
- const inputLines = text.split(`
516
- `);
517
- const resultLines = [];
518
- let activeStyles = [];
519
- for (const inputLine of inputLines) {
520
- const wrapped = wrapLine(inputLine, width, wordBreak, activeStyles);
521
- resultLines.push(...wrapped.lines);
522
- activeStyles = wrapped.activeStyles;
523
- }
524
- return resultLines.join(`
525
- `);
526
- }
527
- function wrapLine(line, width, wordBreak, initialStyles) {
528
- const activeStyles = [...initialStyles];
529
- const lines = [];
530
- let currentLine = activeStyles.length > 0 ? activeStyles.join("") : "";
531
- let currentWidth = 0;
532
- let lastSpaceIdx = -1;
533
- let lastSpaceWidth = 0;
534
- let lastSpaceStyleSnapshot = [];
535
- let i = 0;
536
- while (i < line.length) {
537
- const ansiMatch = line.slice(i).match(ANSI_SEQUENCE);
538
- if (ansiMatch && ansiMatch.index === 0) {
539
- const seq = ansiMatch[0];
540
- if (isSGR(seq)) {
541
- if (isReset(seq)) {
542
- activeStyles.length = 0;
543
- } else {
544
- activeStyles.push(seq);
545
- }
546
- }
547
- currentLine += seq;
548
- i += seq.length;
549
- continue;
550
- }
551
- const char = line[i];
552
- if (char === undefined) {
553
- break;
554
- }
555
- const codePoint = char.codePointAt(0) ?? 0;
556
- const charWidth = isFullWidth2(codePoint) ? 2 : 1;
557
- if (currentWidth + charWidth > width) {
558
- if (wordBreak && lastSpaceIdx !== -1) {
559
- const beforeSpace = currentLine.slice(0, lastSpaceIdx);
560
- const afterSpace = currentLine.slice(lastSpaceIdx + 1);
561
- const closeSeq = activeStyles.length > 0 ? "\x1B[0m" : "";
562
- lines.push(beforeSpace + closeSeq);
563
- const reopenSeq = lastSpaceStyleSnapshot.length > 0 ? lastSpaceStyleSnapshot.join("") : "";
564
- currentLine = reopenSeq + afterSpace;
565
- currentWidth = currentWidth - lastSpaceWidth;
566
- lastSpaceIdx = -1;
567
- lastSpaceWidth = 0;
568
- lastSpaceStyleSnapshot = [];
569
- if (currentWidth + charWidth > width) {
570
- const closeSeq2 = activeStyles.length > 0 ? "\x1B[0m" : "";
571
- lines.push(currentLine + closeSeq2);
572
- const reopenSeq2 = activeStyles.length > 0 ? activeStyles.join("") : "";
573
- currentLine = reopenSeq2 + char;
574
- currentWidth = charWidth;
575
- } else {
576
- currentLine += char;
577
- currentWidth += charWidth;
578
- }
579
- } else {
580
- const closeSeq = activeStyles.length > 0 ? "\x1B[0m" : "";
581
- lines.push(currentLine + closeSeq);
582
- const reopenSeq = activeStyles.length > 0 ? activeStyles.join("") : "";
583
- currentLine = reopenSeq + char;
584
- currentWidth = charWidth;
585
- lastSpaceIdx = -1;
586
- lastSpaceWidth = 0;
587
- lastSpaceStyleSnapshot = [];
588
- }
589
- } else {
590
- if (wordBreak && char === " ") {
591
- currentLine += char;
592
- currentWidth += charWidth;
593
- lastSpaceIdx = currentLine.length - 1;
594
- lastSpaceWidth = currentWidth;
595
- lastSpaceStyleSnapshot = [...activeStyles];
596
- } else {
597
- currentLine += char;
598
- currentWidth += charWidth;
599
- }
600
- }
601
- i += char.length;
602
- }
603
- if (currentLine.length > 0) {
604
- const hasVisibleContent = currentLine.replace(/[\x1b\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]/g, "");
605
- if (hasVisibleContent.length > 0 || currentLine.length > 0) {
606
- lines.push(currentLine);
607
- }
608
- } else {
609
- lines.push("");
610
- }
611
- return { lines, activeStyles };
612
- }
613
- // src/theme/markdownTheme.ts
614
- function buildDefaultMarkdownTheme(s) {
615
- const theme = {
616
- heading1: (value) => s.bold(s.underline(value)),
617
- heading2: (value) => s.bold(value),
618
- heading3: (value) => s.bold(s.yellow(value)),
619
- heading4: (value) => s.yellow(value),
620
- heading5: (value) => s.dim(s.yellow(value)),
621
- heading6: (value) => s.dim(value),
622
- text: (value) => value,
623
- emphasis: (value) => s.italic(value),
624
- strong: (value) => s.bold(value),
625
- strongEmphasis: (value) => s.bold(s.italic(value)),
626
- strikethrough: (value) => s.strikethrough(value),
627
- inlineCode: (value) => s.cyan(value),
628
- linkText: (value) => s.blue(s.underline(value)),
629
- linkUrl: (value) => s.dim(s.underline(value)),
630
- autolink: (value) => s.blue(s.underline(value)),
631
- blockquoteMarker: (value) => s.dim(s.green(value)),
632
- blockquoteText: (value) => s.italic(value),
633
- listMarker: (value) => s.dim(value),
634
- orderedListMarker: (value) => s.dim(value),
635
- taskChecked: (value) => s.green(value),
636
- taskUnchecked: (value) => s.dim(value),
637
- codeFence: (value) => s.dim(value),
638
- codeInfo: (value) => s.dim(s.italic(value)),
639
- codeText: (value) => s.cyan(value),
640
- thematicBreak: (value) => s.dim(value),
641
- tableHeader: (value) => s.bold(value),
642
- tableCell: (value) => value,
643
- tableBorder: (value) => s.dim(value),
644
- imageAltText: (value) => s.italic(s.magenta(value)),
645
- imageUrl: (value) => s.dim(s.underline(value))
646
- };
647
- return Object.freeze(theme);
648
- }
649
-
650
- // src/theme/createMarkdownTheme.ts
651
- function createMarkdownTheme(options) {
652
- const styleInstance = createStyle(options?.style);
653
- const base = buildDefaultMarkdownTheme(styleInstance);
654
- const overrides = options?.overrides;
655
- if (!overrides) {
656
- return base;
657
- }
658
- const merged = {
659
- heading1: overrides.heading1 ?? base.heading1,
660
- heading2: overrides.heading2 ?? base.heading2,
661
- heading3: overrides.heading3 ?? base.heading3,
662
- heading4: overrides.heading4 ?? base.heading4,
663
- heading5: overrides.heading5 ?? base.heading5,
664
- heading6: overrides.heading6 ?? base.heading6,
665
- text: overrides.text ?? base.text,
666
- emphasis: overrides.emphasis ?? base.emphasis,
667
- strong: overrides.strong ?? base.strong,
668
- strongEmphasis: overrides.strongEmphasis ?? base.strongEmphasis,
669
- strikethrough: overrides.strikethrough ?? base.strikethrough,
670
- inlineCode: overrides.inlineCode ?? base.inlineCode,
671
- linkText: overrides.linkText ?? base.linkText,
672
- linkUrl: overrides.linkUrl ?? base.linkUrl,
673
- autolink: overrides.autolink ?? base.autolink,
674
- blockquoteMarker: overrides.blockquoteMarker ?? base.blockquoteMarker,
675
- blockquoteText: overrides.blockquoteText ?? base.blockquoteText,
676
- listMarker: overrides.listMarker ?? base.listMarker,
677
- orderedListMarker: overrides.orderedListMarker ?? base.orderedListMarker,
678
- taskChecked: overrides.taskChecked ?? base.taskChecked,
679
- taskUnchecked: overrides.taskUnchecked ?? base.taskUnchecked,
680
- codeFence: overrides.codeFence ?? base.codeFence,
681
- codeInfo: overrides.codeInfo ?? base.codeInfo,
682
- codeText: overrides.codeText ?? base.codeText,
683
- thematicBreak: overrides.thematicBreak ?? base.thematicBreak,
684
- tableHeader: overrides.tableHeader ?? base.tableHeader,
685
- tableCell: overrides.tableCell ?? base.tableCell,
686
- tableBorder: overrides.tableBorder ?? base.tableBorder,
687
- imageAltText: overrides.imageAltText ?? base.imageAltText,
688
- imageUrl: overrides.imageUrl ?? base.imageUrl
689
- };
690
- return Object.freeze(merged);
691
- }
692
- var defaultTheme = createMarkdownTheme();
693
- export {
694
- yellow as yellowCode,
695
- yellow2 as yellow,
696
- wrapText,
697
- white as whiteCode,
698
- white2 as white,
699
- visibleWidth,
700
- unorderedList,
701
- underline as underlineCode,
702
- underline2 as underline,
703
- taskList,
704
- table,
705
- style,
706
- stripAnsi,
707
- strikethrough as strikethroughCode,
708
- strikethrough2 as strikethrough,
709
- resolveCapability,
710
- reset,
711
- red as redCode,
712
- red2 as red,
713
- padStart,
714
- padEnd,
715
- orderedList,
716
- magenta as magentaCode,
717
- magenta2 as magenta,
718
- italic as italicCode,
719
- italic2 as italic,
720
- inverse as inverseCode,
721
- inverse2 as inverse,
722
- hidden as hiddenCode,
723
- hidden2 as hidden,
724
- green as greenCode,
725
- green2 as green,
726
- gray as grayCode,
727
- gray2 as gray,
728
- dim as dimCode,
729
- dim2 as dim,
730
- defaultTheme,
731
- cyan as cyanCode,
732
- cyan2 as cyan,
733
- createStyle,
734
- createMarkdownTheme,
735
- composeStyles,
736
- center,
737
- buildDefaultMarkdownTheme,
738
- brightYellow as brightYellowCode,
739
- brightYellow2 as brightYellow,
740
- brightWhite as brightWhiteCode,
741
- brightWhite2 as brightWhite,
742
- brightRed as brightRedCode,
743
- brightRed2 as brightRed,
744
- brightMagenta as brightMagentaCode,
745
- brightMagenta2 as brightMagenta,
746
- brightGreen as brightGreenCode,
747
- brightGreen2 as brightGreen,
748
- brightCyan as brightCyanCode,
749
- brightCyan2 as brightCyan,
750
- brightBlue as brightBlueCode,
751
- brightBlue2 as brightBlue,
752
- bold as boldCode,
753
- bold2 as bold,
754
- blue as blueCode,
755
- blue2 as blue,
756
- black as blackCode,
757
- black2 as black,
758
- bgYellow as bgYellowCode,
759
- bgYellow2 as bgYellow,
760
- bgWhite as bgWhiteCode,
761
- bgWhite2 as bgWhite,
762
- bgRed as bgRedCode,
763
- bgRed2 as bgRed,
764
- bgMagenta as bgMagentaCode,
765
- bgMagenta2 as bgMagenta,
766
- bgGreen as bgGreenCode,
767
- bgGreen2 as bgGreen,
768
- bgCyan as bgCyanCode,
769
- bgCyan2 as bgCyan,
770
- bgBrightYellow as bgBrightYellowCode,
771
- bgBrightYellow2 as bgBrightYellow,
772
- bgBrightWhite as bgBrightWhiteCode,
773
- bgBrightWhite2 as bgBrightWhite,
774
- bgBrightRed as bgBrightRedCode,
775
- bgBrightRed2 as bgBrightRed,
776
- bgBrightMagenta as bgBrightMagentaCode,
777
- bgBrightMagenta2 as bgBrightMagenta,
778
- bgBrightGreen as bgBrightGreenCode,
779
- bgBrightGreen2 as bgBrightGreen,
780
- bgBrightCyan as bgBrightCyanCode,
781
- bgBrightCyan2 as bgBrightCyan,
782
- bgBrightBlue as bgBrightBlueCode,
783
- bgBrightBlue2 as bgBrightBlue,
784
- bgBrightBlack as bgBrightBlackCode,
785
- bgBrightBlack2 as bgBrightBlack,
786
- bgBlue as bgBlueCode,
787
- bgBlue2 as bgBlue,
788
- bgBlack as bgBlackCode,
789
- bgBlack2 as bgBlack,
790
- applyStyle
791
- };
2
+ var bz=Object.defineProperty;var yz=(z,Z)=>{for(var V in Z)bz(z,V,{get:Z[V],enumerable:!0,configurable:!0,set:($)=>Z[V]=()=>$})};var q={};yz(q,{yellow:()=>C,white:()=>g,underline:()=>A,strikethrough:()=>T,reset:()=>Nz,red:()=>f,magenta:()=>S,italic:()=>L,inverse:()=>I,hidden:()=>N,green:()=>W,gray:()=>b,dim:()=>R,cyan:()=>P,brightYellow:()=>m,brightWhite:()=>p,brightRed:()=>y,brightMagenta:()=>x,brightGreen:()=>v,brightCyan:()=>h,brightBlue:()=>u,bold:()=>E,blue:()=>w,black:()=>k,bgYellow:()=>l,bgWhite:()=>o,bgRed:()=>d,bgMagenta:()=>s,bgGreen:()=>n,bgCyan:()=>a,bgBrightYellow:()=>zz,bgBrightWhite:()=>Qz,bgBrightRed:()=>t,bgBrightMagenta:()=>Zz,bgBrightGreen:()=>e,bgBrightCyan:()=>$z,bgBrightBlue:()=>Vz,bgBrightBlack:()=>i,bgBlue:()=>r,bgBlack:()=>c});function O(z,Z){return{open:`\x1B[${z}m`,close:`\x1B[${Z}m`}}var Nz=O(0,0),E=O(1,22),R=O(2,22),L=O(3,23),A=O(4,24),I=O(7,27),N=O(8,28),T=O(9,29),k=O(30,39),f=O(31,39),W=O(32,39),C=O(33,39),w=O(34,39),S=O(35,39),P=O(36,39),g=O(37,39),b=O(90,39),y=O(91,39),v=O(92,39),m=O(93,39),u=O(94,39),x=O(95,39),h=O(96,39),p=O(97,39),c=O(40,49),d=O(41,49),n=O(42,49),l=O(43,49),r=O(44,49),s=O(45,49),a=O(46,49),o=O(47,49),i=O(100,49),t=O(101,49),e=O(102,49),zz=O(103,49),Vz=O(104,49),Zz=O(105,49),$z=O(106,49),Qz=O(107,49);var vz=/[\x1b\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]/g;function Xz(z){return z.replace(vz,"")}function mz(z){return z>=19968&&z<=40959||z>=13312&&z<=19903||z>=131072&&z<=173791||z>=63744&&z<=64255||z>=65281&&z<=65376||z>=65504&&z<=65510||z>=11904&&z<=12031||z>=12032&&z<=12255||z>=12288&&z<=12351||z>=12352&&z<=12447||z>=12448&&z<=12543||z>=12544&&z<=12591||z>=12592&&z<=12687||z>=12800&&z<=13055||z>=13056&&z<=13311||z>=44032&&z<=55215||z>=65072&&z<=65103}function D(z){let Z=Xz(z),V=0;for(let $ of Z){let Q=$.codePointAt(0);if(Q===void 0)continue;V+=mz(Q)?2:1}return V}function Yz(z,Z){let V=z.split(`
3
+ `);if(V.length<=1)return z;let $=" ".repeat(Z);return V.map((Q,K)=>K===0?Q:$+Q).join(`
4
+ `)}function uz(z,Z){let V=Z?.marker??"\u2022",$=Z?.markerGap??1,Q=Z?.indent??0,K=" ".repeat(Q),J=" ".repeat($),j=D(V),Y=Q+j+$;return z.map((U)=>{let _=Yz(U,Y);return`${K}${V}${J}${_}`}).join(`
5
+ `)}function xz(z,Z){let V=Z?.start??1,$=Z?.markerGap??1,Q=Z?.indent??0;if(z.length===0)return"";let K=" ".repeat(Q),J=" ".repeat($),Y=`${V+z.length-1}.`.length;return z.map((U,_)=>{let F=`${V+_}.`.padStart(Y," "),Kz=Q+Y+$,B=Yz(U,Kz);return`${K}${F}${J}${B}`}).join(`
6
+ `)}function hz(z,Z){let V=Z?.checkedMarker??"[x]",$=Z?.uncheckedMarker??"[ ]",Q=Z?.markerGap??1,K=Z?.indent??0,J=" ".repeat(K),j=" ".repeat(Q),Y=Math.max(D(V),D($)),U=K+Y+Q;return z.map((_)=>{let H=_.checked?V:$,M=Yz(_.text,U);return`${J}${H}${j}${M}`}).join(`
7
+ `)}function Oz(z,Z,V=" "){let $=D(z);if($>=Z)return z;return V.repeat(Z-$)+z}function Uz(z,Z,V=" "){let $=D(z);if($>=Z)return z;let Q=V.repeat(Z-$);return z+Q}function _z(z,Z,V=" "){let $=D(z);if($>=Z)return z;let Q=Z-$,K=Math.floor(Q/2),J=Q-K;return V.repeat(K)+z+V.repeat(J)}function pz(z,Z,V){let $=z.length,Q=Array($).fill(V);for(let K=0;K<$;K++){let J=z[K];if(J!==void 0)Q[K]=Math.max(Q[K]??0,D(J))}for(let K of Z)for(let J=0;J<$;J++){let j=K[J];if(j!==void 0)Q[J]=Math.max(Q[J]??0,D(j))}return Q}function cz(z,Z,V){switch(V){case"right":return Oz(z,Z);case"center":return _z(z,Z);default:return Uz(z,Z)}}function Tz(z,Z,V,$,Q){let K=" ".repeat($),J=Z.map((j,Y)=>{let U=z[Y]??"",_=V[Y]??"left",H=cz(U,j,_);return`${K}${H}${K}`});return`${Q}${J.join(Q)}${Q}`}function dz(z,Z,V,$){let Q=z.map((K)=>{return V.repeat(K+Z*2)});return`${$}${Q.join($)}${$}`}function nz(z,Z,V){let $=V?.align??[],Q=V?.minColumnWidth??0,K=V?.cellPadding??1,J=V?.separatorChar??"-",j=V?.borderChar??"|",Y=pz(z,Z,Q),U=[];U.push(Tz(z,Y,$,K,j)),U.push(dz(Y,K,J,j));for(let _ of Z)U.push(Tz(_,Y,$,K,j));return U.join(`
8
+ `)}function jz(z,Z){if(z==="always")return!0;if(z==="never")return!1;let V=Z?.isTTY??process.stdout?.isTTY??!1;if((Z?.noColor!==void 0?Z.noColor:process.env.NO_COLOR)!==void 0)return!1;return V}function Dz(z,Z){if(z==="always")return!0;if(z==="never")return!1;if(!jz(z,Z))return!1;let Q=(Z!==void 0&&"colorTerm"in Z?Z.colorTerm:process.env.COLORTERM)?.toLowerCase();if(Q==="truecolor"||Q==="24bit")return!0;let J=Z!==void 0&&"term"in Z?Z.term:process.env.TERM;if(J!==void 0){let j=J.toLowerCase();if(j.includes("24bit")||j.includes("truecolor")||j.endsWith("-direct"))return!0}return!1}function X(z,Z){if(z==="")return"";let{open:V,close:$}=Z;if(z.includes($))z=z.replaceAll($,$+V);return V+z+$}function lz(...z){return{open:z.map((Z)=>Z.open).join(""),close:z.map((Z)=>Z.close).reverse().join("")}}function rz(z){return X(z,k)}function sz(z){return X(z,f)}function az(z){return X(z,W)}function oz(z){return X(z,C)}function iz(z){return X(z,w)}function tz(z){return X(z,S)}function ez(z){return X(z,P)}function zV(z){return X(z,g)}function VV(z){return X(z,b)}function ZV(z){return X(z,y)}function $V(z){return X(z,v)}function QV(z){return X(z,m)}function jV(z){return X(z,u)}function JV(z){return X(z,x)}function KV(z){return X(z,h)}function XV(z){return X(z,p)}function YV(z){return X(z,c)}function OV(z){return X(z,d)}function UV(z){return X(z,n)}function _V(z){return X(z,l)}function DV(z){return X(z,r)}function FV(z){return X(z,s)}function HV(z){return X(z,a)}function BV(z){return X(z,o)}function GV(z){return X(z,i)}function MV(z){return X(z,t)}function qV(z){return X(z,e)}function EV(z){return X(z,zz)}function RV(z){return X(z,Vz)}function LV(z){return X(z,Zz)}function AV(z){return X(z,$z)}function IV(z){return X(z,Qz)}function Fz(z,Z){if(!Number.isInteger(z)||z<0||z>255)throw RangeError(`Invalid ${Z} value: ${String(z)}. Must be an integer between 0 and 255.`)}function kz(z,Z,V){Fz(z,"red"),Fz(Z,"green"),Fz(V,"blue")}var NV=/^#([0-9a-f]{3})$/i,TV=/^#([0-9a-f]{6})$/i;function Hz(z){let Z=NV.exec(z);if(Z){let $=Z[1],Q=$.charAt(0),K=$.charAt(1),J=$.charAt(2);return[Number.parseInt(Q+Q,16),Number.parseInt(K+K,16),Number.parseInt(J+J,16)]}let V=TV.exec(z);if(V){let $=V[1];return[Number.parseInt($.slice(0,2),16),Number.parseInt($.slice(2,4),16),Number.parseInt($.slice(4,6),16)]}throw TypeError(`Invalid hex color: "${z}". Expected format: "#RGB" or "#RRGGBB".`)}function Bz(z,Z,V){return kz(z,Z,V),{open:`\x1B[38;2;${z};${Z};${V}m`,close:"\x1B[39m"}}function Gz(z,Z,V){return kz(z,Z,V),{open:`\x1B[48;2;${z};${Z};${V}m`,close:"\x1B[49m"}}function fz(z){let[Z,V,$]=Hz(z);return Bz(Z,V,$)}function Wz(z){let[Z,V,$]=Hz(z);return Gz(Z,V,$)}function Mz(z,Z,V,$){return X(z,Bz(Z,V,$))}function qz(z,Z,V,$){return X(z,Gz(Z,V,$))}function Ez(z,Z){return X(z,fz(Z))}function Rz(z,Z){return X(z,Wz(Z))}function kV(){let{reset:z,...Z}=q;return Z}var Cz=Object.freeze(kV()),Lz=Object.freeze(Object.keys(Cz));function wz(z){return Cz[z]}function fV(z,Z,V){if(!V||z==="")return z;let $=z;for(let Q=Z.length-1;Q>=0;Q--){let K=Z[Q];if(K===void 0)continue;$=X($,wz(K))}return $}function WV(z){let Z=new Map;function V(Q){return Q.join("|")}function $(Q){let K=V(Q),J=Z.get(K);if(J)return J;let j=(Y)=>fV(Y,Q,z);Z.set(K,j);for(let Y of Lz)Object.defineProperty(j,Y,{configurable:!1,enumerable:!0,get(){return $([...Q,Y])}});return Object.freeze(j)}return $}function CV(z){let Z={};for(let V of Lz)Z[V]=z([V]);return Z}function Jz(z){let Z=z?.mode??"auto",V=jz(Z,z?.overrides),$=Dz(Z,z?.overrides),Q=WV(V),K=CV(Q),J={enabled:V,trueColorEnabled:$,apply:V?(j,Y)=>X(j,Y):(j,Y)=>j,rgb:$?(j,Y,U,_)=>Mz(j,Y,U,_):(j,Y,U,_)=>j,bgRgb:$?(j,Y,U,_)=>qz(j,Y,U,_):(j,Y,U,_)=>j,hex:$?(j,Y)=>Ez(j,Y):(j,Y)=>j,bgHex:$?(j,Y)=>Rz(j,Y):(j,Y)=>j,...K};return Object.freeze(J)}var wV=Jz();function SV(z){return X(z,E)}function PV(z){return X(z,R)}function gV(z){return X(z,L)}function bV(z){return X(z,A)}function yV(z){return X(z,I)}function vV(z){return X(z,N)}function mV(z){return X(z,T)}var uV=/[\x1b\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]/;function xV(z){return z>=19968&&z<=40959||z>=13312&&z<=19903||z>=131072&&z<=173791||z>=63744&&z<=64255||z>=65281&&z<=65376||z>=65504&&z<=65510||z>=11904&&z<=12031||z>=12032&&z<=12255||z>=12288&&z<=12351||z>=12352&&z<=12447||z>=12448&&z<=12543||z>=12544&&z<=12591||z>=12592&&z<=12687||z>=12800&&z<=13055||z>=13056&&z<=13311||z>=44032&&z<=55215||z>=65072&&z<=65103}function hV(z){return z==="\x1B[0m"}function pV(z){return z.endsWith("m")&&z.startsWith("\x1B[")}function cV(z,Z,V){if(Z<=0)return z;let $=V?.wordBreak??!0,Q=z.split(`
9
+ `),K=[],J=[];for(let j of Q){let Y=dV(j,Z,$,J);K.push(...Y.lines),J=Y.activeStyles}return K.join(`
10
+ `)}function dV(z,Z,V,$){let Q=[...$],K=[],J=Q.length>0?Q.join(""):"",j=0,Y=-1,U=0,_=[],H=0;while(H<z.length){let M=z.slice(H).match(uV);if(M&&M.index===0){let G=M[0];if(pV(G))if(hV(G))Q.length=0;else Q.push(G);J+=G,H+=G.length;continue}let F=z[H];if(F===void 0)break;let Kz=F.codePointAt(0)??0,B=xV(Kz)?2:1;if(j+B>Z)if(V&&Y!==-1){let G=J.slice(0,Y),Iz=J.slice(Y+1),Pz=Q.length>0?"\x1B[0m":"";if(K.push(G+Pz),J=(_.length>0?_.join(""):"")+Iz,j=j-U,Y=-1,U=0,_=[],j+B>Z){let gz=Q.length>0?"\x1B[0m":"";K.push(J+gz),J=(Q.length>0?Q.join(""):"")+F,j=B}else J+=F,j+=B}else{let G=Q.length>0?"\x1B[0m":"";K.push(J+G),J=(Q.length>0?Q.join(""):"")+F,j=B,Y=-1,U=0,_=[]}else if(V&&F===" ")J+=F,j+=B,Y=J.length-1,U=j,_=[...Q];else J+=F,j+=B;H+=F.length}if(J.length>0){if(J.replace(/[\x1b\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]/g,"").length>0||J.length>0)K.push(J)}else K.push("");return{lines:K,activeStyles:Q}}function Az(z){return Object.freeze({heading1:(V)=>z.bold(z.underline(V)),heading2:(V)=>z.bold(V),heading3:(V)=>z.bold(z.yellow(V)),heading4:(V)=>z.yellow(V),heading5:(V)=>z.dim(z.yellow(V)),heading6:(V)=>z.dim(V),text:(V)=>V,emphasis:(V)=>z.italic(V),strong:(V)=>z.bold(V),strongEmphasis:(V)=>z.bold(z.italic(V)),strikethrough:(V)=>z.strikethrough(V),inlineCode:(V)=>z.cyan(V),linkText:(V)=>z.blue(z.underline(V)),linkUrl:(V)=>z.dim(z.underline(V)),autolink:(V)=>z.blue(z.underline(V)),blockquoteMarker:(V)=>z.dim(z.green(V)),blockquoteText:(V)=>z.italic(V),listMarker:(V)=>z.dim(V),orderedListMarker:(V)=>z.dim(V),taskChecked:(V)=>z.green(V),taskUnchecked:(V)=>z.dim(V),codeFence:(V)=>z.dim(V),codeInfo:(V)=>z.dim(z.italic(V)),codeText:(V)=>z.cyan(V),thematicBreak:(V)=>z.dim(V),tableHeader:(V)=>z.bold(V),tableCell:(V)=>V,tableBorder:(V)=>z.dim(V),imageAltText:(V)=>z.italic(z.magenta(V)),imageUrl:(V)=>z.dim(z.underline(V))})}function Sz(z){let Z=Jz(z?.style),V=Az(Z),$=z?.overrides;if(!$)return V;let Q={heading1:$.heading1??V.heading1,heading2:$.heading2??V.heading2,heading3:$.heading3??V.heading3,heading4:$.heading4??V.heading4,heading5:$.heading5??V.heading5,heading6:$.heading6??V.heading6,text:$.text??V.text,emphasis:$.emphasis??V.emphasis,strong:$.strong??V.strong,strongEmphasis:$.strongEmphasis??V.strongEmphasis,strikethrough:$.strikethrough??V.strikethrough,inlineCode:$.inlineCode??V.inlineCode,linkText:$.linkText??V.linkText,linkUrl:$.linkUrl??V.linkUrl,autolink:$.autolink??V.autolink,blockquoteMarker:$.blockquoteMarker??V.blockquoteMarker,blockquoteText:$.blockquoteText??V.blockquoteText,listMarker:$.listMarker??V.listMarker,orderedListMarker:$.orderedListMarker??V.orderedListMarker,taskChecked:$.taskChecked??V.taskChecked,taskUnchecked:$.taskUnchecked??V.taskUnchecked,codeFence:$.codeFence??V.codeFence,codeInfo:$.codeInfo??V.codeInfo,codeText:$.codeText??V.codeText,thematicBreak:$.thematicBreak??V.thematicBreak,tableHeader:$.tableHeader??V.tableHeader,tableCell:$.tableCell??V.tableCell,tableBorder:$.tableBorder??V.tableBorder,imageAltText:$.imageAltText??V.imageAltText,imageUrl:$.imageUrl??V.imageUrl};return Object.freeze(Q)}var nV=Sz();export{C as yellowCode,oz as yellow,cV as wrapText,g as whiteCode,zV as white,D as visibleWidth,uz as unorderedList,A as underlineCode,bV as underline,hz as taskList,nz as table,wV as style,Xz as stripAnsi,T as strikethroughCode,mV as strikethrough,Bz as rgbCode,Mz as rgb,Dz as resolveTrueColor,jz as resolveCapability,Nz as reset,f as redCode,sz as red,Hz as parseHex,Oz as padStart,Uz as padEnd,xz as orderedList,S as magentaCode,tz as magenta,L as italicCode,gV as italic,I as inverseCode,yV as inverse,N as hiddenCode,vV as hidden,fz as hexCode,Ez as hex,W as greenCode,az as green,b as grayCode,VV as gray,R as dimCode,PV as dim,nV as defaultTheme,P as cyanCode,ez as cyan,Jz as createStyle,Sz as createMarkdownTheme,lz as composeStyles,_z as center,Az as buildDefaultMarkdownTheme,m as brightYellowCode,QV as brightYellow,p as brightWhiteCode,XV as brightWhite,y as brightRedCode,ZV as brightRed,x as brightMagentaCode,JV as brightMagenta,v as brightGreenCode,$V as brightGreen,h as brightCyanCode,KV as brightCyan,u as brightBlueCode,jV as brightBlue,E as boldCode,SV as bold,w as blueCode,iz as blue,k as blackCode,rz as black,l as bgYellowCode,_V as bgYellow,o as bgWhiteCode,BV as bgWhite,Gz as bgRgbCode,qz as bgRgb,d as bgRedCode,OV as bgRed,s as bgMagentaCode,FV as bgMagenta,Wz as bgHexCode,Rz as bgHex,n as bgGreenCode,UV as bgGreen,a as bgCyanCode,HV as bgCyan,zz as bgBrightYellowCode,EV as bgBrightYellow,Qz as bgBrightWhiteCode,IV as bgBrightWhite,t as bgBrightRedCode,MV as bgBrightRed,Zz as bgBrightMagentaCode,LV as bgBrightMagenta,e as bgBrightGreenCode,qV as bgBrightGreen,$z as bgBrightCyanCode,AV as bgBrightCyan,Vz as bgBrightBlueCode,RV as bgBrightBlue,i as bgBrightBlackCode,GV as bgBrightBlack,r as bgBlueCode,DV as bgBlue,c as bgBlackCode,YV as bgBlack,X as applyStyle};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crustjs/style",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Terminal styling foundation for the Crust CLI framework",
5
5
  "type": "module",
6
6
  "license": "MIT",