@mks2508/better-logger 1.1.0 → 1.2.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/.claude/settings.local.json +3 -2
- package/CHANGELOG.md +63 -0
- package/bun.lock +10 -0
- package/dist/Logger.d.ts.map +1 -1
- package/dist/chunks/{Logger-Th9SfADL.js → Logger-BynuRJQf.js} +12 -6
- package/dist/chunks/{Logger-Th9SfADL.js.map → Logger-BynuRJQf.js.map} +1 -1
- package/dist/chunks/{Logger-C9zTFYBh.js → Logger-DMjlVQWi.js} +2 -2
- package/dist/chunks/{Logger-C9zTFYBh.js.map → Logger-DMjlVQWi.js.map} +1 -1
- package/dist/chunks/{ScopedLogger-uAAeJkfA.js → ScopedLogger-Bl56WovH.js} +2 -2
- package/dist/chunks/{ScopedLogger-uAAeJkfA.js.map → ScopedLogger-Bl56WovH.js.map} +1 -1
- package/dist/chunks/{ScopedLogger-HgV_J-ug.js → ScopedLogger-D2HzayKH.js} +2 -2
- package/dist/chunks/{ScopedLogger-HgV_J-ug.js.map → ScopedLogger-D2HzayKH.js.map} +1 -1
- package/dist/chunks/environment--eaTrhRu.js +4 -0
- package/dist/chunks/environment--eaTrhRu.js.map +1 -0
- package/dist/chunks/{environment-wXLQvk5g.js → environment-BanAyF-K.js} +539 -3
- package/dist/chunks/environment-BanAyF-K.js.map +1 -0
- package/dist/chunks/{formatting-CiFnwe1I.js → formatting-BSNvAxLK.js} +2 -2
- package/dist/chunks/{formatting-CiFnwe1I.js.map → formatting-BSNvAxLK.js.map} +1 -1
- package/dist/chunks/{formatting-DIhpRCCk.js → formatting-CgQSWgXR.js} +2 -2
- package/dist/chunks/{formatting-DIhpRCCk.js.map → formatting-CgQSWgXR.js.map} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +2 -2
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +6 -6
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +3 -3
- package/dist/terminal/terminal-renderer.d.ts +63 -0
- package/dist/terminal/terminal-renderer.d.ts.map +1 -0
- package/dist/utils/adapter.d.ts +48 -0
- package/dist/utils/adapter.d.ts.map +1 -0
- package/dist/utils/environment-detector.d.ts +35 -0
- package/dist/utils/environment-detector.d.ts.map +1 -0
- package/dist/utils/environment.d.ts +1 -1
- package/dist/utils/output.d.ts +7 -2
- package/dist/utils/output.d.ts.map +1 -1
- package/package.json +10 -2
- package/src/Logger.ts +21 -13
- package/src/terminal/terminal-renderer.ts +339 -0
- package/src/utils/adapter.ts +291 -0
- package/src/utils/environment-detector.ts +148 -0
- package/src/utils/output.ts +43 -1
- package/dist/chunks/environment-5I5unY89.js +0 -4
- package/dist/chunks/environment-5I5unY89.js.map +0 -1
- package/dist/chunks/environment-wXLQvk5g.js.map +0 -1
|
@@ -513,6 +513,524 @@ const StylePresets = {
|
|
|
513
513
|
accent: () => new StyleBuilder().bg("#f8f9fa").color("#495057").padding("2px 6px").rounded("3px").border("1px solid #dee2e6"),
|
|
514
514
|
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)")
|
|
515
515
|
};
|
|
516
|
+
function getEnvironment() {
|
|
517
|
+
if (typeof globalThis !== "undefined" && globalThis.Deno) {
|
|
518
|
+
return "deno";
|
|
519
|
+
}
|
|
520
|
+
if (typeof window === "undefined" && typeof self !== "undefined" && typeof self.importScripts === "function") {
|
|
521
|
+
return "webworker";
|
|
522
|
+
}
|
|
523
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
524
|
+
if (isRunningInTerminal()) {
|
|
525
|
+
return "terminal";
|
|
526
|
+
}
|
|
527
|
+
return "server";
|
|
528
|
+
}
|
|
529
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
530
|
+
return "browser";
|
|
531
|
+
}
|
|
532
|
+
return "unknown";
|
|
533
|
+
}
|
|
534
|
+
function isRunningInTerminal() {
|
|
535
|
+
if (typeof process === "undefined") return false;
|
|
536
|
+
const isTTY = process.stdout && process.stdout.isTTY;
|
|
537
|
+
const hasTerminalEnv = process.env && (process.env.TERM || process.env.TERM_PROGRAM || process.env.SSH_TTY || process.env.TERM_SESSION_ID);
|
|
538
|
+
const terminalPrograms = [
|
|
539
|
+
"vscode",
|
|
540
|
+
"hyper",
|
|
541
|
+
"iterm",
|
|
542
|
+
"terminal",
|
|
543
|
+
"alacritty",
|
|
544
|
+
"kitty",
|
|
545
|
+
"gnome-terminal",
|
|
546
|
+
"konsole",
|
|
547
|
+
"xterm",
|
|
548
|
+
"tmux",
|
|
549
|
+
"screen"
|
|
550
|
+
];
|
|
551
|
+
const isTerminalProgram = hasTerminalEnv && terminalPrograms.some(
|
|
552
|
+
(program) => process.env.TERM_PROGRAM?.toLowerCase().includes(program) || process.env.TERM?.toLowerCase().includes(program)
|
|
553
|
+
);
|
|
554
|
+
return Boolean(isTTY || hasTerminalEnv || isTerminalProgram);
|
|
555
|
+
}
|
|
556
|
+
function supportsANSI() {
|
|
557
|
+
const env = getEnvironment();
|
|
558
|
+
if (env === "browser") return false;
|
|
559
|
+
if (env === "terminal") return true;
|
|
560
|
+
if (env === "server") return checkServerANSISupport();
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
function checkServerANSISupport() {
|
|
564
|
+
if (typeof process === "undefined") return false;
|
|
565
|
+
const supportsANSI2 = process.env && (process.env.COLORTERM || process.env.FORCE_COLOR || process.env.TERM && process.env.TERM !== "dumb" || process.env.TERM_PROGRAM);
|
|
566
|
+
return Boolean(supportsANSI2);
|
|
567
|
+
}
|
|
568
|
+
function getColorCapability() {
|
|
569
|
+
const env = getEnvironment();
|
|
570
|
+
if (env === "browser") {
|
|
571
|
+
return "full";
|
|
572
|
+
}
|
|
573
|
+
if (!supportsANSI()) {
|
|
574
|
+
return "none";
|
|
575
|
+
}
|
|
576
|
+
if (typeof process !== "undefined" && process.env) {
|
|
577
|
+
const hasTrueColor = process.env.COLORTERM === "truecolor" || process.env.COLORTERM === "24bit";
|
|
578
|
+
const has256Colors = process.env.TERM && process.env.TERM.includes("256");
|
|
579
|
+
if (hasTrueColor || has256Colors) {
|
|
580
|
+
return "full";
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return "basic";
|
|
584
|
+
}
|
|
585
|
+
class TerminalRenderer {
|
|
586
|
+
colorCapability;
|
|
587
|
+
constructor(colorCapability = "full") {
|
|
588
|
+
this.colorCapability = colorCapability;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Get ANSI color codes for basic colors
|
|
592
|
+
*/
|
|
593
|
+
getColorCode(color, background = false) {
|
|
594
|
+
const colorCodes = {
|
|
595
|
+
"black": { normal: "30", bright: "90" },
|
|
596
|
+
"red": { normal: "31", bright: "91" },
|
|
597
|
+
"green": { normal: "32", bright: "92" },
|
|
598
|
+
"yellow": { normal: "33", bright: "93" },
|
|
599
|
+
"blue": { normal: "34", bright: "94" },
|
|
600
|
+
"magenta": { normal: "35", bright: "95" },
|
|
601
|
+
"cyan": { normal: "36", bright: "96" },
|
|
602
|
+
"white": { normal: "37", bright: "97" },
|
|
603
|
+
"gray": { normal: "90", bright: "37" },
|
|
604
|
+
"grey": { normal: "90", bright: "37" }
|
|
605
|
+
};
|
|
606
|
+
const codes = colorCodes[color.toLowerCase()] || { normal: "37" };
|
|
607
|
+
return `\x1B[${codes.normal}m`;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Get ANSI style codes
|
|
611
|
+
*/
|
|
612
|
+
getStyleCode(styles) {
|
|
613
|
+
const styleCodes = {
|
|
614
|
+
"bold": "1",
|
|
615
|
+
"dim": "2",
|
|
616
|
+
"italic": "3",
|
|
617
|
+
"underline": "4",
|
|
618
|
+
"reset": "0"
|
|
619
|
+
};
|
|
620
|
+
const codes = styles.map((style) => styleCodes[style] || "0").join(";");
|
|
621
|
+
return codes ? `\x1B[${codes}m` : "";
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Convert log styles to ANSI formatting
|
|
625
|
+
*/
|
|
626
|
+
renderTerminal(level, message, timestamp, prefix, location, styles) {
|
|
627
|
+
const reset = "\x1B[0m";
|
|
628
|
+
const result = { text: "", reset };
|
|
629
|
+
if (styles) {
|
|
630
|
+
result.timestamp = this.styleTimestamp(timestamp, styles.timestamp);
|
|
631
|
+
result.level = this.styleLevel(level, styles.level);
|
|
632
|
+
result.prefix = this.stylePrefix(prefix, styles.prefix);
|
|
633
|
+
result.message = this.styleMessage(message, styles.message);
|
|
634
|
+
result.location = this.styleLocation(location, styles.location);
|
|
635
|
+
} else {
|
|
636
|
+
result.timestamp = this.styleTimestamp(timestamp);
|
|
637
|
+
result.level = this.styleLevel(level);
|
|
638
|
+
result.prefix = this.stylePrefix(prefix);
|
|
639
|
+
result.message = this.styleMessage(message);
|
|
640
|
+
result.location = this.styleLocation(location);
|
|
641
|
+
}
|
|
642
|
+
const parts = [];
|
|
643
|
+
if (result.timestamp) parts.push(result.timestamp);
|
|
644
|
+
if (result.level) parts.push(result.level);
|
|
645
|
+
if (result.prefix) parts.push(result.prefix);
|
|
646
|
+
if (result.message) parts.push(result.message);
|
|
647
|
+
if (result.location) parts.push(result.location);
|
|
648
|
+
result.text = parts.join(" ") + reset;
|
|
649
|
+
return result;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Style timestamp based on preset or defaults
|
|
653
|
+
*/
|
|
654
|
+
styleTimestamp(timestamp, style) {
|
|
655
|
+
if (!timestamp || !style?.show) return "";
|
|
656
|
+
if (this.colorCapability === "none") {
|
|
657
|
+
return timestamp;
|
|
658
|
+
}
|
|
659
|
+
const dimStyle = this.getStyleCode(["dim"]);
|
|
660
|
+
return `${dimStyle}${timestamp}${"\x1B[0m"}`;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Style level with appropriate colors and formatting
|
|
664
|
+
*/
|
|
665
|
+
styleLevel(level, style) {
|
|
666
|
+
if (!style?.show) return "";
|
|
667
|
+
const levelText = this.getLevelText(level);
|
|
668
|
+
const levelColors = {
|
|
669
|
+
"debug": "magenta",
|
|
670
|
+
"info": "blue",
|
|
671
|
+
"warn": "yellow",
|
|
672
|
+
"error": "red",
|
|
673
|
+
"critical": "red"
|
|
674
|
+
};
|
|
675
|
+
if (this.colorCapability === "none") {
|
|
676
|
+
return `[${levelText}]`;
|
|
677
|
+
}
|
|
678
|
+
const color = levelColors[level] || "white";
|
|
679
|
+
const colorCode = this.getColorCode(color);
|
|
680
|
+
const boldStyle = this.getStyleCode(["bold"]);
|
|
681
|
+
if (style?.style === "compact") {
|
|
682
|
+
return `${colorCode}[${levelText}]${"\x1B[0m"}`;
|
|
683
|
+
} else {
|
|
684
|
+
return `${colorCode}${boldStyle}[${levelText}]${"\x1B[0m"}`;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Style prefix based on preset
|
|
689
|
+
*/
|
|
690
|
+
stylePrefix(prefix, style) {
|
|
691
|
+
if (!prefix || !style?.show) return "";
|
|
692
|
+
if (this.colorCapability === "none") {
|
|
693
|
+
return `[${prefix}]`;
|
|
694
|
+
}
|
|
695
|
+
const colorCode = this.getColorCode("cyan");
|
|
696
|
+
return `${colorCode}[${prefix}]${"\x1B[0m"}`;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Style message based on preset
|
|
700
|
+
*/
|
|
701
|
+
styleMessage(message, style) {
|
|
702
|
+
if (!style?.show) return message;
|
|
703
|
+
return message;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Style location (file:line) information
|
|
707
|
+
*/
|
|
708
|
+
styleLocation(location, style) {
|
|
709
|
+
if (!location || !style?.show) return "";
|
|
710
|
+
if (this.colorCapability === "none") {
|
|
711
|
+
return `(${location})`;
|
|
712
|
+
}
|
|
713
|
+
const dimStyle = this.getStyleCode(["dim"]);
|
|
714
|
+
if (style?.style === "clickable") {
|
|
715
|
+
const underlineStyle = this.getStyleCode(["dim", "underline"]);
|
|
716
|
+
return `${underlineStyle}(${location})${"\x1B[0m"}`;
|
|
717
|
+
}
|
|
718
|
+
return `${dimStyle}(${location})${"\x1B[0m"}`;
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Get text representation of log level
|
|
722
|
+
*/
|
|
723
|
+
getLevelText(level) {
|
|
724
|
+
const levelMap = {
|
|
725
|
+
"debug": "DEBUG",
|
|
726
|
+
"info": "INFO",
|
|
727
|
+
"warn": "WARN",
|
|
728
|
+
"error": "ERROR",
|
|
729
|
+
"critical": "CRITICAL"
|
|
730
|
+
};
|
|
731
|
+
return levelMap[level] || String(level).toUpperCase();
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Create cyberpunk-style ANSI rendering
|
|
735
|
+
*/
|
|
736
|
+
renderCyberpunk(level, message, timestamp, prefix, location) {
|
|
737
|
+
const reset = "\x1B[0m";
|
|
738
|
+
const levelColors = {
|
|
739
|
+
"debug": "\x1B[95m",
|
|
740
|
+
// Bright magenta
|
|
741
|
+
"info": "\x1B[94m",
|
|
742
|
+
// Bright blue
|
|
743
|
+
"warn": "\x1B[93m",
|
|
744
|
+
// Bright yellow
|
|
745
|
+
"error": "\x1B[91m",
|
|
746
|
+
// Bright red
|
|
747
|
+
"critical": "\x1B[91m\x1B[1m"
|
|
748
|
+
// Bright red + bold
|
|
749
|
+
};
|
|
750
|
+
const parts = [];
|
|
751
|
+
if (timestamp) {
|
|
752
|
+
parts.push(`\x1B[90m${timestamp}${reset}`);
|
|
753
|
+
}
|
|
754
|
+
const levelColor = levelColors[level] || "\x1B[97m";
|
|
755
|
+
const bgBlack = "\x1B[40m";
|
|
756
|
+
parts.push(`${bgBlack}${levelColor} ${this.getLevelText(level)} ${reset}`);
|
|
757
|
+
if (prefix) {
|
|
758
|
+
parts.push(`\x1B[96m[${prefix}]${reset}`);
|
|
759
|
+
}
|
|
760
|
+
parts.push(message);
|
|
761
|
+
if (location) {
|
|
762
|
+
parts.push(`\x1B[90m(${location})${reset}`);
|
|
763
|
+
}
|
|
764
|
+
return {
|
|
765
|
+
text: parts.join(" "),
|
|
766
|
+
reset
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Create minimal ANSI rendering
|
|
771
|
+
*/
|
|
772
|
+
renderMinimal(level, message, timestamp, prefix) {
|
|
773
|
+
const reset = "\x1B[0m";
|
|
774
|
+
const levelColors = {
|
|
775
|
+
"debug": "\x1B[95m",
|
|
776
|
+
// Magenta
|
|
777
|
+
"info": "\x1B[94m",
|
|
778
|
+
// Blue
|
|
779
|
+
"warn": "\x1B[93m",
|
|
780
|
+
// Yellow
|
|
781
|
+
"error": "\x1B[91m",
|
|
782
|
+
// Red
|
|
783
|
+
"critical": "\x1B[91m\x1B[1m"
|
|
784
|
+
// Red + bold
|
|
785
|
+
};
|
|
786
|
+
const parts = [];
|
|
787
|
+
if (timestamp) {
|
|
788
|
+
parts.push(`\x1B[90m${timestamp}${reset}`);
|
|
789
|
+
}
|
|
790
|
+
const levelColor = levelColors[level] || "\x1B[97m";
|
|
791
|
+
parts.push(`${levelColor}${this.getLevelText(level)}:${reset}`);
|
|
792
|
+
if (prefix) {
|
|
793
|
+
parts.push(`\x1B[96m${prefix}${reset}`);
|
|
794
|
+
}
|
|
795
|
+
parts.push(message);
|
|
796
|
+
return {
|
|
797
|
+
text: parts.join(" "),
|
|
798
|
+
reset
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Get chalk instance for log level (for compatibility with adapter)
|
|
803
|
+
*/
|
|
804
|
+
getChalkForLevel(level) {
|
|
805
|
+
const levelColors = {
|
|
806
|
+
"debug": "magenta",
|
|
807
|
+
"info": "blue",
|
|
808
|
+
"warn": "yellow",
|
|
809
|
+
"error": "red",
|
|
810
|
+
"critical": "red"
|
|
811
|
+
};
|
|
812
|
+
return {
|
|
813
|
+
color: (text) => {
|
|
814
|
+
const color = levelColors[level] || "white";
|
|
815
|
+
const colorCode = this.getColorCode(color);
|
|
816
|
+
return `${colorCode}${text}${"\x1B[0m"}`;
|
|
817
|
+
},
|
|
818
|
+
bold: (text) => {
|
|
819
|
+
const boldStyle = this.getStyleCode(["bold"]);
|
|
820
|
+
return `${boldStyle}${text}${"\x1B[0m"}`;
|
|
821
|
+
},
|
|
822
|
+
dim: (text) => {
|
|
823
|
+
const dimStyle = this.getStyleCode(["dim"]);
|
|
824
|
+
return `${dimStyle}${text}${"\x1B[0m"}`;
|
|
825
|
+
},
|
|
826
|
+
bgGray: (text) => {
|
|
827
|
+
return `\x1B[100m${text}${"\x1B[0m"}`;
|
|
828
|
+
},
|
|
829
|
+
bgBlue: (text) => {
|
|
830
|
+
return `\x1B[104m${text}${"\x1B[0m"}`;
|
|
831
|
+
},
|
|
832
|
+
reset: (text) => text,
|
|
833
|
+
cyan: {
|
|
834
|
+
bold: (text) => {
|
|
835
|
+
const cyan = this.getColorCode("cyan");
|
|
836
|
+
const bold = this.getStyleCode(["bold"]);
|
|
837
|
+
return `${cyan}${bold}${text}${"\x1B[0m"}`;
|
|
838
|
+
},
|
|
839
|
+
dim: (text) => {
|
|
840
|
+
const cyan = this.getColorCode("cyan");
|
|
841
|
+
const dim = this.getStyleCode(["dim"]);
|
|
842
|
+
return `${cyan}${dim}${text}${"\x1B[0m"}`;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
class CSS2ANSIAdapter {
|
|
849
|
+
renderer;
|
|
850
|
+
constructor() {
|
|
851
|
+
const colorCapability = getColorCapability();
|
|
852
|
+
this.renderer = new TerminalRenderer(colorCapability);
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Convert LogStyles to ANSIStyle for terminal rendering
|
|
856
|
+
*/
|
|
857
|
+
adaptStyles(level, message, timestamp, prefix, location, styles, presetName) {
|
|
858
|
+
if (presetName) {
|
|
859
|
+
switch (presetName) {
|
|
860
|
+
case "cyberpunk":
|
|
861
|
+
return this.renderer.renderCyberpunk(level, message, timestamp, prefix, location);
|
|
862
|
+
case "minimal":
|
|
863
|
+
return this.renderer.renderMinimal(level, message, timestamp, prefix);
|
|
864
|
+
case "production":
|
|
865
|
+
return this.adaptProductionStyles(level, message, timestamp, prefix, location, styles);
|
|
866
|
+
case "debug":
|
|
867
|
+
return this.adaptDebugStyles(level, message, timestamp, prefix, location, styles);
|
|
868
|
+
case "glassmorphism":
|
|
869
|
+
return this.adaptGlassmorphismStyles(level, message, timestamp, prefix, location, styles);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return this.renderer.renderTerminal(level, message, timestamp, prefix, location, styles);
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Adapt production preset for terminal
|
|
876
|
+
*/
|
|
877
|
+
adaptProductionStyles(level, message, timestamp, prefix, location, styles) {
|
|
878
|
+
const reset = "\x1B[0m";
|
|
879
|
+
const levelChalk = this.renderer.getChalkForLevel(level);
|
|
880
|
+
const parts = [];
|
|
881
|
+
if (timestamp && styles?.timestamp?.show) {
|
|
882
|
+
parts.push(levelChalk.dim(timestamp));
|
|
883
|
+
}
|
|
884
|
+
if (styles?.level?.show) {
|
|
885
|
+
parts.push(levelChalk.color(`[${this.renderer["getLevelText"](level)}]`));
|
|
886
|
+
}
|
|
887
|
+
if (prefix && styles?.prefix?.show) {
|
|
888
|
+
parts.push(levelChalk.dim(`[${prefix}]`));
|
|
889
|
+
}
|
|
890
|
+
if (message && styles?.message?.show) {
|
|
891
|
+
parts.push(levelChalk.reset(message));
|
|
892
|
+
}
|
|
893
|
+
if (location && styles?.location?.show) {
|
|
894
|
+
parts.push(levelChalk.dim(`(${location})`));
|
|
895
|
+
}
|
|
896
|
+
return {
|
|
897
|
+
text: parts.join(" ") + reset,
|
|
898
|
+
reset
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Adapt debug preset for terminal
|
|
903
|
+
*/
|
|
904
|
+
adaptDebugStyles(level, message, timestamp, prefix, location, styles) {
|
|
905
|
+
const reset = "\x1B[0m";
|
|
906
|
+
const levelChalk = this.renderer.getChalkForLevel(level);
|
|
907
|
+
const parts = [];
|
|
908
|
+
if (timestamp && styles?.timestamp?.show) {
|
|
909
|
+
parts.push(levelChalk.dim(timestamp));
|
|
910
|
+
}
|
|
911
|
+
if (styles?.level?.show) {
|
|
912
|
+
if (styles?.level?.style === "compact") {
|
|
913
|
+
parts.push(levelChalk.color(`[${this.renderer["getLevelText"](level)}]`));
|
|
914
|
+
} else {
|
|
915
|
+
parts.push(levelChalk.bold(`[${this.renderer["getLevelText"](level)}]`));
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
if (prefix && styles?.prefix?.show) {
|
|
919
|
+
if (styles?.prefix?.style === "compact") {
|
|
920
|
+
parts.push(levelChalk.cyan.dim(`[${prefix}]`));
|
|
921
|
+
} else {
|
|
922
|
+
parts.push(levelChalk.cyan.bold(`[${prefix}]`));
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
if (message && styles?.message?.show) {
|
|
926
|
+
parts.push(levelChalk.reset(message));
|
|
927
|
+
}
|
|
928
|
+
if (location && styles?.location?.show) {
|
|
929
|
+
if (styles?.location?.style === "clickable") {
|
|
930
|
+
parts.push(levelChalk.dim(`${location} (clickable)`));
|
|
931
|
+
} else {
|
|
932
|
+
parts.push(levelChalk.dim(`(${location})`));
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return {
|
|
936
|
+
text: parts.join(" ") + reset,
|
|
937
|
+
reset
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Adapt glassmorphism preset for terminal
|
|
942
|
+
*/
|
|
943
|
+
adaptGlassmorphismStyles(level, message, timestamp, prefix, location, styles) {
|
|
944
|
+
const reset = "\x1B[0m";
|
|
945
|
+
const levelChalk = this.renderer.getChalkForLevel(level);
|
|
946
|
+
const parts = [];
|
|
947
|
+
if (timestamp && styles?.timestamp?.show) {
|
|
948
|
+
parts.push(levelChalk.dim(timestamp));
|
|
949
|
+
}
|
|
950
|
+
if (styles?.level?.show) {
|
|
951
|
+
parts.push(levelChalk.bgGray(` ${this.renderer["getLevelText"](level)} `));
|
|
952
|
+
}
|
|
953
|
+
if (prefix && styles?.prefix?.show) {
|
|
954
|
+
parts.push(levelChalk.bgBlue(`[${prefix}]`));
|
|
955
|
+
}
|
|
956
|
+
if (message && styles?.message?.show) {
|
|
957
|
+
parts.push(levelChalk.reset(message));
|
|
958
|
+
}
|
|
959
|
+
if (location && styles?.location?.show) {
|
|
960
|
+
parts.push(levelChalk.dim(`(${location})`));
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
text: parts.join(" ") + reset,
|
|
964
|
+
reset
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Convert CSS color values to ANSI-friendly colors
|
|
969
|
+
*/
|
|
970
|
+
adaptColor(cssColor) {
|
|
971
|
+
if (cssColor.startsWith("#")) {
|
|
972
|
+
return cssColor;
|
|
973
|
+
}
|
|
974
|
+
if (cssColor.startsWith("rgb(")) {
|
|
975
|
+
return cssColor;
|
|
976
|
+
}
|
|
977
|
+
if (cssColor.includes("gradient")) {
|
|
978
|
+
return this.extractColorFromGradient(cssColor);
|
|
979
|
+
}
|
|
980
|
+
return this.cssNameToANSI(cssColor);
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Extract primary color from CSS gradient
|
|
984
|
+
*/
|
|
985
|
+
extractColorFromGradient(gradient) {
|
|
986
|
+
const match = gradient.match(/#[0-9a-fA-F]{6}|rgb\([^)]+\)/);
|
|
987
|
+
return match ? match[0] : "#ffffff";
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Convert CSS color names to ANSI-compatible names
|
|
991
|
+
*/
|
|
992
|
+
cssNameToANSI(cssColor) {
|
|
993
|
+
const colorMap = {
|
|
994
|
+
"black": "black",
|
|
995
|
+
"white": "white",
|
|
996
|
+
"red": "red",
|
|
997
|
+
"green": "green",
|
|
998
|
+
"blue": "blue",
|
|
999
|
+
"yellow": "yellow",
|
|
1000
|
+
"cyan": "cyan",
|
|
1001
|
+
"magenta": "magenta",
|
|
1002
|
+
"gray": "gray",
|
|
1003
|
+
"grey": "gray",
|
|
1004
|
+
"orange": "yellow",
|
|
1005
|
+
"purple": "magenta",
|
|
1006
|
+
"pink": "red",
|
|
1007
|
+
"brown": "yellow",
|
|
1008
|
+
"lightblue": "cyan",
|
|
1009
|
+
"lightgreen": "green",
|
|
1010
|
+
"lightgray": "gray",
|
|
1011
|
+
"lightgrey": "gray"
|
|
1012
|
+
};
|
|
1013
|
+
return colorMap[cssColor.toLowerCase()] || "white";
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Check if a style should be rendered in terminal
|
|
1017
|
+
*/
|
|
1018
|
+
shouldRenderStyle(styleType, styles) {
|
|
1019
|
+
if (!styles) return true;
|
|
1020
|
+
const styleConfig = styles[styleType];
|
|
1021
|
+
return styleConfig?.show !== false;
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Get renderer instance for advanced usage
|
|
1025
|
+
*/
|
|
1026
|
+
getRenderer() {
|
|
1027
|
+
return this.renderer;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
const css2ansiAdapter = new CSS2ANSIAdapter();
|
|
1031
|
+
function adaptToTerminal(level, message, timestamp, prefix, location, styles, presetName) {
|
|
1032
|
+
return css2ansiAdapter.adaptStyles(level, message, timestamp, prefix, location, styles, presetName);
|
|
1033
|
+
}
|
|
516
1034
|
function detectDevToolsTheme() {
|
|
517
1035
|
try {
|
|
518
1036
|
if (typeof window === "undefined" || !window.matchMedia) {
|
|
@@ -551,9 +1069,13 @@ function setupThemeChangeListener(callback) {
|
|
|
551
1069
|
return null;
|
|
552
1070
|
}
|
|
553
1071
|
}
|
|
554
|
-
function createStyledOutput(level, levelStyles, prefix, message, stackInfo, autoDetectTheme = true) {
|
|
1072
|
+
function createStyledOutput(level, levelStyles, prefix, message, stackInfo, autoDetectTheme = true, presetStyles, presetName) {
|
|
555
1073
|
const levelConfig = levelStyles[level];
|
|
556
1074
|
const timestamp = formatTimestamp();
|
|
1075
|
+
const environment = getEnvironment();
|
|
1076
|
+
if (environment !== "browser" && supportsANSI()) {
|
|
1077
|
+
return createTerminalOutput(level, message, timestamp, prefix, stackInfo, presetStyles, presetName);
|
|
1078
|
+
}
|
|
557
1079
|
const currentTheme = autoDetectTheme ? detectDevToolsTheme() : "light";
|
|
558
1080
|
const timestampStyle = new StyleBuilder().color(getAdaptiveColor(ADAPTIVE_COLORS.timestamp, currentTheme)).size("11px").font("Monaco, Consolas, monospace").build();
|
|
559
1081
|
const levelStyle = new StyleBuilder().bg(levelConfig.background).color(levelConfig.color).border(levelConfig.border).shadow(levelConfig.shadow).padding("2px 8px").rounded("4px").bold().font("Monaco, Consolas, monospace").size("12px").build();
|
|
@@ -595,6 +1117,19 @@ function safeStringify(obj, _maxDepth = 3) {
|
|
|
595
1117
|
return String(obj);
|
|
596
1118
|
}
|
|
597
1119
|
}
|
|
1120
|
+
function createTerminalOutput(level, message, timestamp, prefix, stackInfo, presetStyles, presetName) {
|
|
1121
|
+
const location = stackInfo ? `${stackInfo.file}:${stackInfo.line}:${stackInfo.column}` : void 0;
|
|
1122
|
+
const ansiStyle = adaptToTerminal(
|
|
1123
|
+
level,
|
|
1124
|
+
message,
|
|
1125
|
+
timestamp,
|
|
1126
|
+
prefix,
|
|
1127
|
+
location,
|
|
1128
|
+
presetStyles,
|
|
1129
|
+
presetName
|
|
1130
|
+
);
|
|
1131
|
+
return [ansiStyle.text];
|
|
1132
|
+
}
|
|
598
1133
|
const isNode = typeof process !== "undefined" && process.versions && process.versions.node;
|
|
599
1134
|
const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
600
1135
|
function supportsCSSColors() {
|
|
@@ -631,6 +1166,7 @@ export {
|
|
|
631
1166
|
parseStackTrace as p,
|
|
632
1167
|
EXPORT_FORMATS as q,
|
|
633
1168
|
setupThemeChangeListener as r,
|
|
634
|
-
supportsCSSColors as s
|
|
1169
|
+
supportsCSSColors as s,
|
|
1170
|
+
getEnvironment as t
|
|
635
1171
|
};
|
|
636
|
-
//# sourceMappingURL=environment-
|
|
1172
|
+
//# sourceMappingURL=environment-BanAyF-K.js.map
|