@mks2508/better-logger 3.1.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +45 -1
- package/dist/Logger.d.ts +129 -4
- package/dist/Logger.d.ts.map +1 -1
- package/dist/ScopedLogger.d.ts +17 -0
- package/dist/ScopedLogger.d.ts.map +1 -1
- package/dist/chunks/{Logger-C086w3EM.js → Logger-BZ7B7OXE.js} +258 -16
- package/dist/chunks/Logger-BZ7B7OXE.js.map +1 -0
- package/dist/chunks/Logger-Cbi1f10o.js +2 -0
- package/dist/chunks/Logger-Cbi1f10o.js.map +1 -0
- package/dist/chunks/cli-module-CadqgZ1Z.js +2 -0
- package/dist/chunks/cli-module-CadqgZ1Z.js.map +1 -0
- package/dist/chunks/cli-module-ClIJmaT8.js +383 -0
- package/dist/chunks/cli-module-ClIJmaT8.js.map +1 -0
- package/dist/chunks/color-converter-CCSQRztd.js +2 -0
- package/dist/chunks/color-converter-CCSQRztd.js.map +1 -0
- package/dist/chunks/color-converter-_Xdmsy7E.js +462 -0
- package/dist/chunks/color-converter-_Xdmsy7E.js.map +1 -0
- package/dist/chunks/{environment-DXHouGD4.js → environment-C1xxvc8l.js} +28 -478
- package/dist/chunks/environment-C1xxvc8l.js.map +1 -0
- package/dist/chunks/environment-Cprkw3g9.js +4 -0
- package/dist/chunks/environment-Cprkw3g9.js.map +1 -0
- package/dist/chunks/{formatting-BNnVUPcw.js → formatting-DMJxYq9o.js} +18 -18
- package/dist/chunks/{formatting-BNnVUPcw.js.map → formatting-DMJxYq9o.js.map} +1 -1
- package/dist/chunks/{formatting-Cg5YhB9Y.js → formatting-DpKxCsXq.js} +2 -2
- package/dist/chunks/{formatting-Cg5YhB9Y.js.map → formatting-DpKxCsXq.js.map} +1 -1
- package/dist/cli-module.d.ts +15 -0
- package/dist/cli-module.d.ts.map +1 -0
- package/dist/cli-primitives/box.d.ts +11 -0
- package/dist/cli-primitives/box.d.ts.map +1 -0
- package/dist/cli-primitives/cli-table.d.ts +11 -0
- package/dist/cli-primitives/cli-table.d.ts.map +1 -0
- package/dist/cli-primitives/divider.d.ts +11 -0
- package/dist/cli-primitives/divider.d.ts.map +1 -0
- package/dist/cli-primitives/header.d.ts +12 -0
- package/dist/cli-primitives/header.d.ts.map +1 -0
- package/dist/cli-primitives/index.d.ts +13 -0
- package/dist/cli-primitives/index.d.ts.map +1 -0
- package/dist/cli-primitives/server-fallback.d.ts +25 -0
- package/dist/cli-primitives/server-fallback.d.ts.map +1 -0
- package/dist/cli-primitives/spinner.d.ts +47 -0
- package/dist/cli-primitives/spinner.d.ts.map +1 -0
- package/dist/cli-primitives/step.d.ts +11 -0
- package/dist/cli-primitives/step.d.ts.map +1 -0
- package/dist/cli.cjs +2 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +12 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +9 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +2 -2
- package/dist/exports-module.d.ts +1 -1
- package/dist/exports-module.d.ts.map +1 -1
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +162 -195
- package/dist/index.js.map +1 -1
- package/dist/styling-module.d.ts +1 -1
- package/dist/styling-module.d.ts.map +1 -1
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +3 -3
- package/dist/types/core.d.ts +91 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/writers/BufferWriter.d.ts +96 -0
- package/dist/writers/BufferWriter.d.ts.map +1 -0
- package/dist/writers/index.d.ts +6 -0
- package/dist/writers/index.d.ts.map +1 -0
- package/package.json +28 -3
- package/packages/core/package.json +1 -1
- package/playground/demo-all.ts +95 -0
- package/playground/demo-box.ts +85 -0
- package/playground/demo-levels.ts +56 -0
- package/playground/demo-real-world.ts +98 -0
- package/playground/demo-spinner.ts +77 -0
- package/playground/demo-steps.ts +72 -0
- package/playground/demo-table.ts +83 -0
- package/src/Logger.ts +263 -16
- package/src/ScopedLogger.ts +43 -1
- package/src/cli-module.ts +21 -0
- package/src/cli-primitives/box.ts +86 -0
- package/src/cli-primitives/cli-table.ts +62 -0
- package/src/cli-primitives/divider.ts +17 -0
- package/src/cli-primitives/header.ts +18 -0
- package/src/cli-primitives/index.ts +13 -0
- package/src/cli-primitives/server-fallback.ts +54 -0
- package/src/cli-primitives/spinner.ts +133 -0
- package/src/cli-primitives/step.ts +22 -0
- package/src/constants.ts +14 -2
- package/src/index.ts +23 -2
- package/src/types/core.ts +99 -0
- package/src/types/index.ts +4 -0
- package/src/writers/BufferWriter.ts +157 -0
- package/src/writers/index.ts +6 -0
- package/vite.config.ts +33 -0
- package/dist/chunks/Logger-BV0v1AyC.js +0 -2
- package/dist/chunks/Logger-BV0v1AyC.js.map +0 -1
- package/dist/chunks/Logger-C086w3EM.js.map +0 -1
- package/dist/chunks/environment-C_8J-zQ_.js +0 -4
- package/dist/chunks/environment-C_8J-zQ_.js.map +0 -1
- package/dist/chunks/environment-DXHouGD4.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { b as getANSIBackground, g as getANSIForeground, A as ANSI, k as getColorCapability, i as getEnvironment, s as supportsANSI } from "./color-converter-_Xdmsy7E.js";
|
|
1
2
|
function isMinifiedFile(filename) {
|
|
2
3
|
const minifiedPatterns = [
|
|
3
4
|
/\.min\.js$/,
|
|
@@ -268,6 +269,13 @@ function getOptimalConfig() {
|
|
|
268
269
|
...BUILD_PRESETS[preset]
|
|
269
270
|
};
|
|
270
271
|
}
|
|
272
|
+
const CLI_LEVEL_MAP = {
|
|
273
|
+
silent: { verbosity: "silent", showPrimitives: false },
|
|
274
|
+
quiet: { verbosity: "error", showPrimitives: false },
|
|
275
|
+
normal: { verbosity: "info", showPrimitives: true },
|
|
276
|
+
verbose: { verbosity: "debug", showPrimitives: true },
|
|
277
|
+
debug: { verbosity: "debug", showPrimitives: true }
|
|
278
|
+
};
|
|
271
279
|
function formatTimestamp() {
|
|
272
280
|
try {
|
|
273
281
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -543,448 +551,6 @@ const StylePresets = {
|
|
|
543
551
|
accent: () => new StyleBuilder().bg("#f8f9fa").color("#495057").padding("2px 6px").rounded("3px").border("1px solid #dee2e6"),
|
|
544
552
|
neon: () => new StyleBuilder().bg("linear-gradient(135deg, #0f3460 0%, #e94560 100%)").color("#00ffff").padding("4px 8px").rounded("4px").bold().shadow("0 0 10px rgba(0, 255, 255, 0.5)")
|
|
545
553
|
};
|
|
546
|
-
function getEnvironment() {
|
|
547
|
-
if (typeof globalThis !== "undefined" && globalThis.Deno) {
|
|
548
|
-
return "deno";
|
|
549
|
-
}
|
|
550
|
-
if (typeof window === "undefined" && typeof self !== "undefined" && typeof self.importScripts === "function") {
|
|
551
|
-
return "webworker";
|
|
552
|
-
}
|
|
553
|
-
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
554
|
-
if (isRunningInTerminal()) {
|
|
555
|
-
return "terminal";
|
|
556
|
-
}
|
|
557
|
-
return "server";
|
|
558
|
-
}
|
|
559
|
-
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
560
|
-
return "browser";
|
|
561
|
-
}
|
|
562
|
-
return "unknown";
|
|
563
|
-
}
|
|
564
|
-
function isRunningInTerminal() {
|
|
565
|
-
if (typeof process === "undefined") return false;
|
|
566
|
-
const isTTY = process.stdout && process.stdout.isTTY;
|
|
567
|
-
const hasTerminalEnv = process.env && (process.env.TERM || process.env.TERM_PROGRAM || process.env.SSH_TTY || process.env.TERM_SESSION_ID);
|
|
568
|
-
const terminalPrograms = [
|
|
569
|
-
"vscode",
|
|
570
|
-
"hyper",
|
|
571
|
-
"iterm",
|
|
572
|
-
"terminal",
|
|
573
|
-
"alacritty",
|
|
574
|
-
"kitty",
|
|
575
|
-
"gnome-terminal",
|
|
576
|
-
"konsole",
|
|
577
|
-
"xterm",
|
|
578
|
-
"tmux",
|
|
579
|
-
"screen"
|
|
580
|
-
];
|
|
581
|
-
const isTerminalProgram = hasTerminalEnv && terminalPrograms.some(
|
|
582
|
-
(program) => process.env.TERM_PROGRAM?.toLowerCase().includes(program) || process.env.TERM?.toLowerCase().includes(program)
|
|
583
|
-
);
|
|
584
|
-
return Boolean(isTTY || hasTerminalEnv || isTerminalProgram);
|
|
585
|
-
}
|
|
586
|
-
function supportsANSI() {
|
|
587
|
-
const env = getEnvironment();
|
|
588
|
-
if (env === "browser") return false;
|
|
589
|
-
if (env === "terminal") return true;
|
|
590
|
-
if (env === "server") return checkServerANSISupport();
|
|
591
|
-
return false;
|
|
592
|
-
}
|
|
593
|
-
function checkServerANSISupport() {
|
|
594
|
-
if (typeof process === "undefined") return false;
|
|
595
|
-
const supportsANSI2 = process.env && (process.env.COLORTERM || process.env.FORCE_COLOR || process.env.TERM && process.env.TERM !== "dumb" || process.env.TERM_PROGRAM);
|
|
596
|
-
return Boolean(supportsANSI2);
|
|
597
|
-
}
|
|
598
|
-
function getColorCapability() {
|
|
599
|
-
const env = getEnvironment();
|
|
600
|
-
if (env === "browser") {
|
|
601
|
-
return "full";
|
|
602
|
-
}
|
|
603
|
-
if (!supportsANSI()) {
|
|
604
|
-
return "none";
|
|
605
|
-
}
|
|
606
|
-
if (typeof process !== "undefined" && process.env) {
|
|
607
|
-
const hasTrueColor = process.env.COLORTERM === "truecolor" || process.env.COLORTERM === "24bit";
|
|
608
|
-
const has256Colors = process.env.TERM && process.env.TERM.includes("256");
|
|
609
|
-
if (hasTrueColor || has256Colors) {
|
|
610
|
-
return "full";
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
return "basic";
|
|
614
|
-
}
|
|
615
|
-
function getTerminalWidth() {
|
|
616
|
-
if (typeof process !== "undefined" && process.stdout?.columns) {
|
|
617
|
-
return process.stdout.columns;
|
|
618
|
-
}
|
|
619
|
-
return 80;
|
|
620
|
-
}
|
|
621
|
-
function getTerminalHeight() {
|
|
622
|
-
if (typeof process !== "undefined" && process.stdout?.rows) {
|
|
623
|
-
return process.stdout.rows;
|
|
624
|
-
}
|
|
625
|
-
return 24;
|
|
626
|
-
}
|
|
627
|
-
function getEnvironmentInfo() {
|
|
628
|
-
return {
|
|
629
|
-
environment: getEnvironment(),
|
|
630
|
-
supportsANSI: supportsANSI(),
|
|
631
|
-
colorCapability: getColorCapability(),
|
|
632
|
-
isTTY: typeof process !== "undefined" ? Boolean(process.stdout?.isTTY) : false,
|
|
633
|
-
platform: typeof process !== "undefined" ? process.platform : "unknown",
|
|
634
|
-
nodeVersion: typeof process !== "undefined" ? process.versions?.node : null,
|
|
635
|
-
term: typeof process !== "undefined" ? process.env?.TERM : null,
|
|
636
|
-
colorTerm: typeof process !== "undefined" ? process.env?.COLORTERM : null,
|
|
637
|
-
terminalWidth: getTerminalWidth(),
|
|
638
|
-
terminalHeight: getTerminalHeight()
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
const ANSI_16_COLORS = {
|
|
642
|
-
black: { fg: "30", bg: "40", bright: { fg: "90", bg: "100" } },
|
|
643
|
-
red: { fg: "31", bg: "41", bright: { fg: "91", bg: "101" } },
|
|
644
|
-
green: { fg: "32", bg: "42", bright: { fg: "92", bg: "102" } },
|
|
645
|
-
yellow: { fg: "33", bg: "43", bright: { fg: "93", bg: "103" } },
|
|
646
|
-
blue: { fg: "34", bg: "44", bright: { fg: "94", bg: "104" } },
|
|
647
|
-
magenta: { fg: "35", bg: "45", bright: { fg: "95", bg: "105" } },
|
|
648
|
-
cyan: { fg: "36", bg: "46", bright: { fg: "96", bg: "106" } },
|
|
649
|
-
white: { fg: "37", bg: "47", bright: { fg: "97", bg: "107" } },
|
|
650
|
-
gray: { fg: "90", bg: "100", bright: { fg: "37", bg: "47" } },
|
|
651
|
-
grey: { fg: "90", bg: "100", bright: { fg: "37", bg: "47" } }
|
|
652
|
-
};
|
|
653
|
-
const CSS_NAMED_COLORS = {
|
|
654
|
-
aliceblue: "#f0f8ff",
|
|
655
|
-
antiquewhite: "#faebd7",
|
|
656
|
-
aqua: "#00ffff",
|
|
657
|
-
aquamarine: "#7fffd4",
|
|
658
|
-
azure: "#f0ffff",
|
|
659
|
-
beige: "#f5f5dc",
|
|
660
|
-
bisque: "#ffe4c4",
|
|
661
|
-
black: "#000000",
|
|
662
|
-
blanchedalmond: "#ffebcd",
|
|
663
|
-
blue: "#0000ff",
|
|
664
|
-
blueviolet: "#8a2be2",
|
|
665
|
-
brown: "#a52a2a",
|
|
666
|
-
burlywood: "#deb887",
|
|
667
|
-
cadetblue: "#5f9ea0",
|
|
668
|
-
chartreuse: "#7fff00",
|
|
669
|
-
chocolate: "#d2691e",
|
|
670
|
-
coral: "#ff7f50",
|
|
671
|
-
cornflowerblue: "#6495ed",
|
|
672
|
-
cornsilk: "#fff8dc",
|
|
673
|
-
crimson: "#dc143c",
|
|
674
|
-
cyan: "#00ffff",
|
|
675
|
-
darkblue: "#00008b",
|
|
676
|
-
darkcyan: "#008b8b",
|
|
677
|
-
darkgoldenrod: "#b8860b",
|
|
678
|
-
darkgray: "#a9a9a9",
|
|
679
|
-
darkgreen: "#006400",
|
|
680
|
-
darkkhaki: "#bdb76b",
|
|
681
|
-
darkmagenta: "#8b008b",
|
|
682
|
-
darkolivegreen: "#556b2f",
|
|
683
|
-
darkorange: "#ff8c00",
|
|
684
|
-
darkorchid: "#9932cc",
|
|
685
|
-
darkred: "#8b0000",
|
|
686
|
-
darksalmon: "#e9967a",
|
|
687
|
-
darkseagreen: "#8fbc8f",
|
|
688
|
-
darkslateblue: "#483d8b",
|
|
689
|
-
darkslategray: "#2f4f4f",
|
|
690
|
-
darkturquoise: "#00ced1",
|
|
691
|
-
darkviolet: "#9400d3",
|
|
692
|
-
deeppink: "#ff1493",
|
|
693
|
-
deepskyblue: "#00bfff",
|
|
694
|
-
dimgray: "#696969",
|
|
695
|
-
dodgerblue: "#1e90ff",
|
|
696
|
-
firebrick: "#b22222",
|
|
697
|
-
floralwhite: "#fffaf0",
|
|
698
|
-
forestgreen: "#228b22",
|
|
699
|
-
fuchsia: "#ff00ff",
|
|
700
|
-
gainsboro: "#dcdcdc",
|
|
701
|
-
ghostwhite: "#f8f8ff",
|
|
702
|
-
gold: "#ffd700",
|
|
703
|
-
goldenrod: "#daa520",
|
|
704
|
-
gray: "#808080",
|
|
705
|
-
green: "#008000",
|
|
706
|
-
greenyellow: "#adff2f",
|
|
707
|
-
honeydew: "#f0fff0",
|
|
708
|
-
hotpink: "#ff69b4",
|
|
709
|
-
indianred: "#cd5c5c",
|
|
710
|
-
indigo: "#4b0082",
|
|
711
|
-
ivory: "#fffff0",
|
|
712
|
-
khaki: "#f0e68c",
|
|
713
|
-
lavender: "#e6e6fa",
|
|
714
|
-
lavenderblush: "#fff0f5",
|
|
715
|
-
lawngreen: "#7cfc00",
|
|
716
|
-
lemonchiffon: "#fffacd",
|
|
717
|
-
lightblue: "#add8e6",
|
|
718
|
-
lightcoral: "#f08080",
|
|
719
|
-
lightcyan: "#e0ffff",
|
|
720
|
-
lightgoldenrodyellow: "#fafad2",
|
|
721
|
-
lightgray: "#d3d3d3",
|
|
722
|
-
lightgreen: "#90ee90",
|
|
723
|
-
lightpink: "#ffb6c1",
|
|
724
|
-
lightsalmon: "#ffa07a",
|
|
725
|
-
lightseagreen: "#20b2aa",
|
|
726
|
-
lightskyblue: "#87cefa",
|
|
727
|
-
lightslategray: "#778899",
|
|
728
|
-
lightsteelblue: "#b0c4de",
|
|
729
|
-
lightyellow: "#ffffe0",
|
|
730
|
-
lime: "#00ff00",
|
|
731
|
-
limegreen: "#32cd32",
|
|
732
|
-
linen: "#faf0e6",
|
|
733
|
-
magenta: "#ff00ff",
|
|
734
|
-
maroon: "#800000",
|
|
735
|
-
mediumaquamarine: "#66cdaa",
|
|
736
|
-
mediumblue: "#0000cd",
|
|
737
|
-
mediumorchid: "#ba55d3",
|
|
738
|
-
mediumpurple: "#9370db",
|
|
739
|
-
mediumseagreen: "#3cb371",
|
|
740
|
-
mediumslateblue: "#7b68ee",
|
|
741
|
-
mediumspringgreen: "#00fa9a",
|
|
742
|
-
mediumturquoise: "#48d1cc",
|
|
743
|
-
mediumvioletred: "#c71585",
|
|
744
|
-
midnightblue: "#191970",
|
|
745
|
-
mintcream: "#f5fffa",
|
|
746
|
-
mistyrose: "#ffe4e1",
|
|
747
|
-
moccasin: "#ffe4b5",
|
|
748
|
-
navajowhite: "#ffdead",
|
|
749
|
-
navy: "#000080",
|
|
750
|
-
oldlace: "#fdf5e6",
|
|
751
|
-
olive: "#808000",
|
|
752
|
-
olivedrab: "#6b8e23",
|
|
753
|
-
orange: "#ffa500",
|
|
754
|
-
orangered: "#ff4500",
|
|
755
|
-
orchid: "#da70d6",
|
|
756
|
-
palegoldenrod: "#eee8aa",
|
|
757
|
-
palegreen: "#98fb98",
|
|
758
|
-
paleturquoise: "#afeeee",
|
|
759
|
-
palevioletred: "#db7093",
|
|
760
|
-
papayawhip: "#ffefd5",
|
|
761
|
-
peachpuff: "#ffdab9",
|
|
762
|
-
peru: "#cd853f",
|
|
763
|
-
pink: "#ffc0cb",
|
|
764
|
-
plum: "#dda0dd",
|
|
765
|
-
powderblue: "#b0e0e6",
|
|
766
|
-
purple: "#800080",
|
|
767
|
-
rebeccapurple: "#663399",
|
|
768
|
-
red: "#ff0000",
|
|
769
|
-
rosybrown: "#bc8f8f",
|
|
770
|
-
royalblue: "#4169e1",
|
|
771
|
-
saddlebrown: "#8b4513",
|
|
772
|
-
salmon: "#fa8072",
|
|
773
|
-
sandybrown: "#f4a460",
|
|
774
|
-
seagreen: "#2e8b57",
|
|
775
|
-
seashell: "#fff5ee",
|
|
776
|
-
sienna: "#a0522d",
|
|
777
|
-
silver: "#c0c0c0",
|
|
778
|
-
skyblue: "#87ceeb",
|
|
779
|
-
slateblue: "#6a5acd",
|
|
780
|
-
slategray: "#708090",
|
|
781
|
-
snow: "#fffafa",
|
|
782
|
-
springgreen: "#00ff7f",
|
|
783
|
-
steelblue: "#4682b4",
|
|
784
|
-
tan: "#d2b48c",
|
|
785
|
-
teal: "#008080",
|
|
786
|
-
thistle: "#d8bfd8",
|
|
787
|
-
tomato: "#ff6347",
|
|
788
|
-
turquoise: "#40e0d0",
|
|
789
|
-
violet: "#ee82ee",
|
|
790
|
-
wheat: "#f5deb3",
|
|
791
|
-
white: "#ffffff",
|
|
792
|
-
whitesmoke: "#f5f5f5",
|
|
793
|
-
yellow: "#ffff00",
|
|
794
|
-
yellowgreen: "#9acd32"
|
|
795
|
-
};
|
|
796
|
-
function hexToRgb(hex) {
|
|
797
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
798
|
-
if (!result || !result[1] || !result[2] || !result[3]) {
|
|
799
|
-
return { r: 255, g: 255, b: 255 };
|
|
800
|
-
}
|
|
801
|
-
return {
|
|
802
|
-
r: parseInt(result[1], 16),
|
|
803
|
-
g: parseInt(result[2], 16),
|
|
804
|
-
b: parseInt(result[3], 16)
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
function rgbToHex(r, g, b) {
|
|
808
|
-
return "#" + [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
809
|
-
}
|
|
810
|
-
function hexTo256(hex) {
|
|
811
|
-
const { r, g, b } = hexToRgb(hex);
|
|
812
|
-
if (r === g && g === b) {
|
|
813
|
-
if (r < 8) return 16;
|
|
814
|
-
if (r > 248) return 231;
|
|
815
|
-
return Math.round((r - 8) / 247 * 24) + 232;
|
|
816
|
-
}
|
|
817
|
-
const ri = Math.round(r / 255 * 5);
|
|
818
|
-
const gi = Math.round(g / 255 * 5);
|
|
819
|
-
const bi = Math.round(b / 255 * 5);
|
|
820
|
-
return 16 + 36 * ri + 6 * gi + bi;
|
|
821
|
-
}
|
|
822
|
-
function colorToHex(color) {
|
|
823
|
-
if (color.startsWith("#")) {
|
|
824
|
-
return color;
|
|
825
|
-
}
|
|
826
|
-
const named = CSS_NAMED_COLORS[color.toLowerCase()];
|
|
827
|
-
if (named) {
|
|
828
|
-
return named;
|
|
829
|
-
}
|
|
830
|
-
const rgbMatch = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
831
|
-
if (rgbMatch && rgbMatch[1] && rgbMatch[2] && rgbMatch[3]) {
|
|
832
|
-
return rgbToHex(
|
|
833
|
-
parseInt(rgbMatch[1]),
|
|
834
|
-
parseInt(rgbMatch[2]),
|
|
835
|
-
parseInt(rgbMatch[3])
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
return "#ffffff";
|
|
839
|
-
}
|
|
840
|
-
function getANSIForeground(color, capability) {
|
|
841
|
-
if (capability === "none") return "";
|
|
842
|
-
const lowerColor = color.toLowerCase();
|
|
843
|
-
if (capability === "basic" && ANSI_16_COLORS[lowerColor]) {
|
|
844
|
-
return `\x1B[${ANSI_16_COLORS[lowerColor].fg}m`;
|
|
845
|
-
}
|
|
846
|
-
if (capability === "basic") {
|
|
847
|
-
const hex2 = colorToHex(color);
|
|
848
|
-
const nearestBasic = findNearestBasicColor(hex2);
|
|
849
|
-
const basicColor = ANSI_16_COLORS[nearestBasic];
|
|
850
|
-
return basicColor ? `\x1B[${basicColor.fg}m` : "\x1B[37m";
|
|
851
|
-
}
|
|
852
|
-
const hex = colorToHex(color);
|
|
853
|
-
const { r, g, b } = hexToRgb(hex);
|
|
854
|
-
return `\x1B[38;2;${r};${g};${b}m`;
|
|
855
|
-
}
|
|
856
|
-
function getANSIBackground(color, capability) {
|
|
857
|
-
if (capability === "none") return "";
|
|
858
|
-
const lowerColor = color.toLowerCase();
|
|
859
|
-
if (capability === "basic" && ANSI_16_COLORS[lowerColor]) {
|
|
860
|
-
return `\x1B[${ANSI_16_COLORS[lowerColor].bg}m`;
|
|
861
|
-
}
|
|
862
|
-
if (capability === "basic") {
|
|
863
|
-
const hex2 = colorToHex(color);
|
|
864
|
-
const nearestBasic = findNearestBasicColor(hex2);
|
|
865
|
-
const basicColor = ANSI_16_COLORS[nearestBasic];
|
|
866
|
-
return basicColor ? `\x1B[${basicColor.bg}m` : "\x1B[47m";
|
|
867
|
-
}
|
|
868
|
-
const hex = colorToHex(color);
|
|
869
|
-
const { r, g, b } = hexToRgb(hex);
|
|
870
|
-
return `\x1B[48;2;${r};${g};${b}m`;
|
|
871
|
-
}
|
|
872
|
-
function getANSI256Foreground(colorIndex) {
|
|
873
|
-
return `\x1B[38;5;${colorIndex}m`;
|
|
874
|
-
}
|
|
875
|
-
function getANSI256Background(colorIndex) {
|
|
876
|
-
return `\x1B[48;5;${colorIndex}m`;
|
|
877
|
-
}
|
|
878
|
-
function findNearestBasicColor(hex) {
|
|
879
|
-
const { r, g, b } = hexToRgb(hex);
|
|
880
|
-
const basicColors = {
|
|
881
|
-
black: { r: 0, g: 0, b: 0 },
|
|
882
|
-
red: { r: 205, g: 0, b: 0 },
|
|
883
|
-
green: { r: 0, g: 205, b: 0 },
|
|
884
|
-
yellow: { r: 205, g: 205, b: 0 },
|
|
885
|
-
blue: { r: 0, g: 0, b: 238 },
|
|
886
|
-
magenta: { r: 205, g: 0, b: 205 },
|
|
887
|
-
cyan: { r: 0, g: 205, b: 205 },
|
|
888
|
-
white: { r: 229, g: 229, b: 229 }
|
|
889
|
-
};
|
|
890
|
-
let nearest = "white";
|
|
891
|
-
let minDistance = Infinity;
|
|
892
|
-
for (const [name, rgb] of Object.entries(basicColors)) {
|
|
893
|
-
const distance = Math.sqrt(
|
|
894
|
-
Math.pow(r - rgb.r, 2) + Math.pow(g - rgb.g, 2) + Math.pow(b - rgb.b, 2)
|
|
895
|
-
);
|
|
896
|
-
if (distance < minDistance) {
|
|
897
|
-
minDistance = distance;
|
|
898
|
-
nearest = name;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
return nearest;
|
|
902
|
-
}
|
|
903
|
-
function extractGradientColors(gradient) {
|
|
904
|
-
const hexMatches = gradient.match(/#[a-fA-F0-9]{6}/g) || [];
|
|
905
|
-
const rgbMatches = gradient.match(/rgba?\([^)]+\)/g) || [];
|
|
906
|
-
const namedMatches = gradient.match(/,\s*([a-z]+)(?:\s|,|\))/gi) || [];
|
|
907
|
-
const colors = [
|
|
908
|
-
...hexMatches,
|
|
909
|
-
...rgbMatches.map(colorToHex),
|
|
910
|
-
...namedMatches.map((m) => {
|
|
911
|
-
const name = m.replace(/[,\s)]/g, "").toLowerCase();
|
|
912
|
-
return CSS_NAMED_COLORS[name] || null;
|
|
913
|
-
}).filter((c) => c !== null)
|
|
914
|
-
];
|
|
915
|
-
return colors.length > 0 ? colors : ["#ffffff"];
|
|
916
|
-
}
|
|
917
|
-
function gradientToSingleColor(gradient) {
|
|
918
|
-
const colors = extractGradientColors(gradient);
|
|
919
|
-
if (colors.length === 0) return "#ffffff";
|
|
920
|
-
if (colors.length === 1) return colors[0] ?? "#ffffff";
|
|
921
|
-
const rgbs = colors.map((c) => hexToRgb(colorToHex(c)));
|
|
922
|
-
const avgR = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.r, 0) / rgbs.length);
|
|
923
|
-
const avgG = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.g, 0) / rgbs.length);
|
|
924
|
-
const avgB = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.b, 0) / rgbs.length);
|
|
925
|
-
return rgbToHex(avgR, avgG, avgB);
|
|
926
|
-
}
|
|
927
|
-
function cssColorToANSI(cssColor, capability, isBackground = false) {
|
|
928
|
-
if (capability === "none") return "";
|
|
929
|
-
let resolvedColor;
|
|
930
|
-
if (cssColor.includes("gradient")) {
|
|
931
|
-
resolvedColor = gradientToSingleColor(cssColor);
|
|
932
|
-
} else {
|
|
933
|
-
resolvedColor = colorToHex(cssColor);
|
|
934
|
-
}
|
|
935
|
-
return isBackground ? getANSIBackground(resolvedColor, capability) : getANSIForeground(resolvedColor, capability);
|
|
936
|
-
}
|
|
937
|
-
const ANSI = {
|
|
938
|
-
reset: "\x1B[0m",
|
|
939
|
-
bold: "\x1B[1m",
|
|
940
|
-
dim: "\x1B[2m",
|
|
941
|
-
italic: "\x1B[3m",
|
|
942
|
-
underline: "\x1B[4m",
|
|
943
|
-
blink: "\x1B[5m",
|
|
944
|
-
inverse: "\x1B[7m",
|
|
945
|
-
hidden: "\x1B[8m",
|
|
946
|
-
strikethrough: "\x1B[9m",
|
|
947
|
-
fg: {
|
|
948
|
-
black: "\x1B[30m",
|
|
949
|
-
red: "\x1B[31m",
|
|
950
|
-
green: "\x1B[32m",
|
|
951
|
-
yellow: "\x1B[33m",
|
|
952
|
-
blue: "\x1B[34m",
|
|
953
|
-
magenta: "\x1B[35m",
|
|
954
|
-
cyan: "\x1B[36m",
|
|
955
|
-
white: "\x1B[37m",
|
|
956
|
-
gray: "\x1B[90m",
|
|
957
|
-
brightRed: "\x1B[91m",
|
|
958
|
-
brightGreen: "\x1B[92m",
|
|
959
|
-
brightYellow: "\x1B[93m",
|
|
960
|
-
brightBlue: "\x1B[94m",
|
|
961
|
-
brightMagenta: "\x1B[95m",
|
|
962
|
-
brightCyan: "\x1B[96m",
|
|
963
|
-
brightWhite: "\x1B[97m"
|
|
964
|
-
},
|
|
965
|
-
bg: {
|
|
966
|
-
black: "\x1B[40m",
|
|
967
|
-
red: "\x1B[41m",
|
|
968
|
-
green: "\x1B[42m",
|
|
969
|
-
yellow: "\x1B[43m",
|
|
970
|
-
blue: "\x1B[44m",
|
|
971
|
-
magenta: "\x1B[45m",
|
|
972
|
-
cyan: "\x1B[46m",
|
|
973
|
-
white: "\x1B[47m",
|
|
974
|
-
gray: "\x1B[100m",
|
|
975
|
-
brightRed: "\x1B[101m",
|
|
976
|
-
brightGreen: "\x1B[102m",
|
|
977
|
-
brightYellow: "\x1B[103m",
|
|
978
|
-
brightBlue: "\x1B[104m",
|
|
979
|
-
brightMagenta: "\x1B[105m",
|
|
980
|
-
brightCyan: "\x1B[106m",
|
|
981
|
-
brightWhite: "\x1B[107m"
|
|
982
|
-
},
|
|
983
|
-
rgb: (r, g, b) => `\x1B[38;2;${r};${g};${b}m`,
|
|
984
|
-
bgRgb: (r, g, b) => `\x1B[48;2;${r};${g};${b}m`,
|
|
985
|
-
color256: (n) => `\x1B[38;5;${n}m`,
|
|
986
|
-
bgColor256: (n) => `\x1B[48;5;${n}m`
|
|
987
|
-
};
|
|
988
554
|
class TerminalRenderer {
|
|
989
555
|
colorCapability;
|
|
990
556
|
constructor(colorCapability = "full") {
|
|
@@ -1530,48 +1096,32 @@ function supportsANSIColors() {
|
|
|
1530
1096
|
return false;
|
|
1531
1097
|
}
|
|
1532
1098
|
export {
|
|
1533
|
-
|
|
1099
|
+
ADAPTIVE_COLORS as A,
|
|
1534
1100
|
BUILD_PRESETS as B,
|
|
1535
|
-
|
|
1101
|
+
CLI_LEVEL_MAP as C,
|
|
1536
1102
|
DEFAULT_CONFIG as D,
|
|
1537
1103
|
ENVIRONMENT_DETECTION as E,
|
|
1538
|
-
ADAPTIVE_COLORS as F,
|
|
1539
|
-
BUFFER_LIMITS as G,
|
|
1540
|
-
generateLogId as H,
|
|
1541
|
-
parseTimeInput as I,
|
|
1542
|
-
formatDisplayTime as J,
|
|
1543
|
-
safeStringify as K,
|
|
1544
1104
|
LEVEL_STYLES as L,
|
|
1545
|
-
escapeHtml as M,
|
|
1546
|
-
EXPORT_FORMATS as N,
|
|
1547
|
-
setupThemeChangeListener as O,
|
|
1548
1105
|
StylePresets as S,
|
|
1549
1106
|
TerminalRenderer as T,
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1107
|
+
isNode as a,
|
|
1108
|
+
StyleBuilder as b,
|
|
1109
|
+
createStyledOutput as c,
|
|
1110
|
+
supportsANSIColors as d,
|
|
1111
|
+
detectEnvironmentPreset as e,
|
|
1555
1112
|
formatTimestamp as f,
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1113
|
+
getOptimalConfig as g,
|
|
1114
|
+
getAdaptiveColor as h,
|
|
1115
|
+
isBrowser as i,
|
|
1116
|
+
BUFFER_LIMITS as j,
|
|
1117
|
+
generateLogId as k,
|
|
1118
|
+
parseTimeInput as l,
|
|
1119
|
+
formatDisplayTime as m,
|
|
1120
|
+
safeStringify as n,
|
|
1121
|
+
escapeHtml as o,
|
|
1565
1122
|
parseStackTrace as p,
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
supportsANSI as t,
|
|
1570
|
-
getColorCapability as u,
|
|
1571
|
-
getTerminalHeight as v,
|
|
1572
|
-
getEnvironmentInfo as w,
|
|
1573
|
-
supportsCSSColors as x,
|
|
1574
|
-
createStyledOutput as y,
|
|
1575
|
-
supportsANSIColors as z
|
|
1123
|
+
EXPORT_FORMATS as q,
|
|
1124
|
+
setupThemeChangeListener as r,
|
|
1125
|
+
supportsCSSColors as s
|
|
1576
1126
|
};
|
|
1577
|
-
//# sourceMappingURL=environment-
|
|
1127
|
+
//# sourceMappingURL=environment-C1xxvc8l.js.map
|