colorino 0.10.1 → 0.11.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/README.md +354 -351
- package/dist/browser.bundle.cjs +127 -116
- package/dist/browser.bundle.mjs +128 -116
- package/dist/browser.cjs +13 -14
- package/dist/browser.d.cts +5 -5
- package/dist/browser.d.mts +5 -5
- package/dist/browser.d.ts +5 -5
- package/dist/browser.mjs +5 -5
- package/dist/node.cjs +58 -125
- package/dist/node.d.cts +3 -6
- package/dist/node.d.mts +3 -6
- package/dist/node.d.ts +3 -6
- package/dist/node.mjs +40 -106
- package/dist/shared/{colorino.BnDovC2X.mjs → colorino.BPD_4Zhq.mjs} +125 -120
- package/dist/shared/{colorino.B4p-EEl9.cjs → colorino.D9xuyiJg.cjs} +124 -122
- package/dist/shared/{colorino.DjY5jpGa.d.ts → colorino.bX_hrCT6.d.cts} +2 -3
- package/dist/shared/{colorino.DjY5jpGa.d.cts → colorino.bX_hrCT6.d.mts} +2 -3
- package/dist/shared/{colorino.DjY5jpGa.d.mts → colorino.bX_hrCT6.d.ts} +2 -3
- package/package.json +2 -1
package/dist/browser.bundle.cjs
CHANGED
|
@@ -63,13 +63,115 @@ function isConsoleMethod(level) {
|
|
|
63
63
|
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
const catppuccinMochaPalette = {
|
|
67
|
+
log: "#cdd6f4",
|
|
68
|
+
// Text
|
|
69
|
+
info: "#89b4fa",
|
|
70
|
+
// Blue
|
|
71
|
+
warn: "#f9e2af",
|
|
72
|
+
// Yellow
|
|
73
|
+
error: "#f38ba8",
|
|
74
|
+
// Red
|
|
75
|
+
debug: "#a6adc8",
|
|
76
|
+
// Subtext0
|
|
77
|
+
trace: "#9399b2"
|
|
78
|
+
// Subtext1
|
|
79
|
+
};
|
|
80
|
+
const catppuccinLattePalette = {
|
|
81
|
+
log: "#4c4f69",
|
|
82
|
+
// Text
|
|
83
|
+
info: "#1e66f5",
|
|
84
|
+
// Blue
|
|
85
|
+
warn: "#df8e1d",
|
|
86
|
+
// Yellow
|
|
87
|
+
error: "#d20f39",
|
|
88
|
+
// Red
|
|
89
|
+
debug: "#7c7f93",
|
|
90
|
+
// Subtext0
|
|
91
|
+
trace: "#8c8fa1"
|
|
92
|
+
// Subtext1
|
|
93
|
+
};
|
|
94
|
+
const draculaPalette = {
|
|
95
|
+
log: "#f8f8f2",
|
|
96
|
+
// Foreground
|
|
97
|
+
info: "#8be9fd",
|
|
98
|
+
// Cyan
|
|
99
|
+
warn: "#f1fa8c",
|
|
100
|
+
// Yellow
|
|
101
|
+
error: "#ff5555",
|
|
102
|
+
// Red
|
|
103
|
+
debug: "#bd93f9",
|
|
104
|
+
// Purple
|
|
105
|
+
trace: "#6272a4"
|
|
106
|
+
// Comment
|
|
107
|
+
};
|
|
108
|
+
const githubLightPalette = {
|
|
109
|
+
log: "#24292e",
|
|
110
|
+
// Text
|
|
111
|
+
info: "#0366d6",
|
|
112
|
+
// Blue
|
|
113
|
+
warn: "#f9a002",
|
|
114
|
+
// Yellow
|
|
115
|
+
error: "#d73a49",
|
|
116
|
+
// Red
|
|
117
|
+
debug: "#586069",
|
|
118
|
+
// Gray
|
|
119
|
+
trace: "#6a737d"
|
|
120
|
+
// Gray-light
|
|
121
|
+
};
|
|
122
|
+
const minimalDarkPalette = {
|
|
123
|
+
log: "#ffffff",
|
|
124
|
+
info: "#ffffff",
|
|
125
|
+
warn: "#ffffff",
|
|
126
|
+
error: "#ffffff",
|
|
127
|
+
debug: "#ffffff",
|
|
128
|
+
trace: "#ffffff"
|
|
129
|
+
};
|
|
130
|
+
const minimalLightPalette = {
|
|
131
|
+
log: "#000000",
|
|
132
|
+
info: "#000000",
|
|
133
|
+
warn: "#000000",
|
|
134
|
+
error: "#000000",
|
|
135
|
+
debug: "#000000",
|
|
136
|
+
trace: "#000000"
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const themePalettes = {
|
|
140
|
+
"catppuccin-mocha": catppuccinMochaPalette,
|
|
141
|
+
"catppuccin-latte": catppuccinLattePalette,
|
|
142
|
+
dracula: draculaPalette,
|
|
143
|
+
"github-light": githubLightPalette,
|
|
144
|
+
"minimal-dark": minimalDarkPalette,
|
|
145
|
+
"minimal-light": minimalLightPalette
|
|
146
|
+
};
|
|
147
|
+
const defaultDarkTheme = "minimal-dark";
|
|
148
|
+
const defaultLightTheme = "minimal-light";
|
|
149
|
+
function isThemeName(theme) {
|
|
150
|
+
return theme in themePalettes;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function determineBaseTheme(themeOpt, detectedBrowserTheme) {
|
|
154
|
+
let baseThemeName;
|
|
155
|
+
if (isThemeName(themeOpt)) {
|
|
156
|
+
baseThemeName = themeOpt;
|
|
157
|
+
} else if (themeOpt === "light") {
|
|
158
|
+
baseThemeName = defaultLightTheme;
|
|
159
|
+
} else if (themeOpt === "dark") {
|
|
160
|
+
baseThemeName = defaultDarkTheme;
|
|
161
|
+
} else {
|
|
162
|
+
baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
|
|
163
|
+
}
|
|
164
|
+
return baseThemeName;
|
|
165
|
+
}
|
|
166
|
+
|
|
66
167
|
class MyColorino {
|
|
67
|
-
constructor(
|
|
68
|
-
this.
|
|
168
|
+
constructor(initialPalette, _userPalette, _validator, _browserColorSupportDetector, _nodeColorSupportDetector, _options = {}) {
|
|
169
|
+
this._userPalette = _userPalette;
|
|
69
170
|
this._validator = _validator;
|
|
70
171
|
this._browserColorSupportDetector = _browserColorSupportDetector;
|
|
71
172
|
this._nodeColorSupportDetector = _nodeColorSupportDetector;
|
|
72
173
|
this._options = _options;
|
|
174
|
+
this._palette = initialPalette;
|
|
73
175
|
this.isBrowser = !!this._browserColorSupportDetector;
|
|
74
176
|
this._colorLevel = this._detectColorSupport();
|
|
75
177
|
const validatePaletteResult = this._validator.validatePalette(this._palette);
|
|
@@ -77,10 +179,23 @@ class MyColorino {
|
|
|
77
179
|
if (this._colorLevel !== ColorLevel.NO_COLOR && !this._options.disableWarnings && this._colorLevel === "UnknownEnv") {
|
|
78
180
|
this._maybeWarnUser();
|
|
79
181
|
}
|
|
182
|
+
const themeOpt = this._options.theme ?? "auto";
|
|
183
|
+
if (themeOpt === "auto" && this._nodeColorSupportDetector) {
|
|
184
|
+
this._nodeColorSupportDetector.onTheme((resolvedTheme) => {
|
|
185
|
+
this._appllyResolvedTheme(resolvedTheme);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
80
188
|
}
|
|
81
189
|
_alreadyWarned = false;
|
|
82
190
|
_colorLevel;
|
|
83
191
|
isBrowser;
|
|
192
|
+
_palette;
|
|
193
|
+
_appllyResolvedTheme(resolvedTheme) {
|
|
194
|
+
const themeOpt = this._options.theme ?? "auto";
|
|
195
|
+
const baseThemeName = determineBaseTheme(themeOpt, resolvedTheme);
|
|
196
|
+
const basePalette = themePalettes[baseThemeName];
|
|
197
|
+
this._palette = { ...basePalette, ...this._userPalette };
|
|
198
|
+
}
|
|
84
199
|
log(...args) {
|
|
85
200
|
this._out("log", args);
|
|
86
201
|
}
|
|
@@ -112,10 +227,10 @@ class MyColorino {
|
|
|
112
227
|
if (this._alreadyWarned) return;
|
|
113
228
|
this._alreadyWarned = true;
|
|
114
229
|
console.warn(
|
|
115
|
-
"
|
|
230
|
+
"No ANSI color support detected in this terminal. See [https://github.com/chalk/supports-color#support-matrix](https://github.com/chalk/supports-color#support-matrix) to learn how to enable terminal color."
|
|
116
231
|
);
|
|
117
232
|
}
|
|
118
|
-
_formatValue(value, maxDepth = 5) {
|
|
233
|
+
_formatValue(value, maxDepth = this._options.maxDepth ?? 5) {
|
|
119
234
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
120
235
|
const sanitize = (val, currentDepth) => {
|
|
121
236
|
if (val === null || typeof val !== "object") return val;
|
|
@@ -200,7 +315,7 @@ ${arg}`);
|
|
|
200
315
|
}
|
|
201
316
|
_output(consoleMethod, args) {
|
|
202
317
|
if (consoleMethod === "trace") {
|
|
203
|
-
this._printCleanTrace(args
|
|
318
|
+
this._printCleanTrace(args);
|
|
204
319
|
} else {
|
|
205
320
|
console[consoleMethod](...args);
|
|
206
321
|
}
|
|
@@ -221,9 +336,7 @@ ${arg}`);
|
|
|
221
336
|
this._output(consoleMethod, coloredArgs);
|
|
222
337
|
}
|
|
223
338
|
_filterStack(stack) {
|
|
224
|
-
return stack.split("\n").filter(
|
|
225
|
-
(line) => !line.includes("colorino.js") && !line.includes("Colorino._out") && !line.includes("Colorino.error") && !line.includes("Colorino.warn") && !line.includes("Colorino.debug") && !line.includes("Colorino.info") && !line.includes("Colorino.log") && !line.includes("Colorino.trace") && !line.includes("Colorino._cleanErrorStack") && !line.includes("Colorino._printCleanTrace") && !line.includes("Colorino._filterStack")
|
|
226
|
-
).join("\n");
|
|
339
|
+
return stack.split("\n").filter((line) => !line.match(/.*colorino.*/gi)).join("\n");
|
|
227
340
|
}
|
|
228
341
|
_cleanErrorStack(error) {
|
|
229
342
|
if (!error.stack) return error;
|
|
@@ -233,14 +346,14 @@ ${arg}`);
|
|
|
233
346
|
cloned.stack = cleanStack;
|
|
234
347
|
return cloned;
|
|
235
348
|
}
|
|
236
|
-
_printCleanTrace(args
|
|
349
|
+
_printCleanTrace(args) {
|
|
237
350
|
const error = new Error();
|
|
238
351
|
if (error.stack) {
|
|
239
352
|
const cleanStack = this._filterStack(error.stack);
|
|
240
|
-
console
|
|
353
|
+
console.log(...args, `
|
|
241
354
|
${cleanStack}`);
|
|
242
355
|
} else {
|
|
243
|
-
console
|
|
356
|
+
console.log(...args);
|
|
244
357
|
}
|
|
245
358
|
}
|
|
246
359
|
}
|
|
@@ -756,107 +869,6 @@ class InputValidator {
|
|
|
756
869
|
}
|
|
757
870
|
}
|
|
758
871
|
|
|
759
|
-
const catppuccinMochaPalette = {
|
|
760
|
-
log: "#cdd6f4",
|
|
761
|
-
// Text
|
|
762
|
-
info: "#89b4fa",
|
|
763
|
-
// Blue
|
|
764
|
-
warn: "#f9e2af",
|
|
765
|
-
// Yellow
|
|
766
|
-
error: "#f38ba8",
|
|
767
|
-
// Red
|
|
768
|
-
debug: "#a6adc8",
|
|
769
|
-
// Subtext0
|
|
770
|
-
trace: "#9399b2"
|
|
771
|
-
// Subtext1
|
|
772
|
-
};
|
|
773
|
-
const catppuccinLattePalette = {
|
|
774
|
-
log: "#4c4f69",
|
|
775
|
-
// Text
|
|
776
|
-
info: "#1e66f5",
|
|
777
|
-
// Blue
|
|
778
|
-
warn: "#df8e1d",
|
|
779
|
-
// Yellow
|
|
780
|
-
error: "#d20f39",
|
|
781
|
-
// Red
|
|
782
|
-
debug: "#7c7f93",
|
|
783
|
-
// Subtext0
|
|
784
|
-
trace: "#8c8fa1"
|
|
785
|
-
// Subtext1
|
|
786
|
-
};
|
|
787
|
-
const draculaPalette = {
|
|
788
|
-
log: "#f8f8f2",
|
|
789
|
-
// Foreground
|
|
790
|
-
info: "#8be9fd",
|
|
791
|
-
// Cyan
|
|
792
|
-
warn: "#f1fa8c",
|
|
793
|
-
// Yellow
|
|
794
|
-
error: "#ff5555",
|
|
795
|
-
// Red
|
|
796
|
-
debug: "#bd93f9",
|
|
797
|
-
// Purple
|
|
798
|
-
trace: "#6272a4"
|
|
799
|
-
// Comment
|
|
800
|
-
};
|
|
801
|
-
const githubLightPalette = {
|
|
802
|
-
log: "#24292e",
|
|
803
|
-
// Text
|
|
804
|
-
info: "#0366d6",
|
|
805
|
-
// Blue
|
|
806
|
-
warn: "#f9a002",
|
|
807
|
-
// Yellow
|
|
808
|
-
error: "#d73a49",
|
|
809
|
-
// Red
|
|
810
|
-
debug: "#586069",
|
|
811
|
-
// Gray
|
|
812
|
-
trace: "#6a737d"
|
|
813
|
-
// Gray-light
|
|
814
|
-
};
|
|
815
|
-
const minimalDarkPalette = {
|
|
816
|
-
log: "#ffffff",
|
|
817
|
-
info: "#ffffff",
|
|
818
|
-
warn: "#ffffff",
|
|
819
|
-
error: "#ffffff",
|
|
820
|
-
debug: "#ffffff",
|
|
821
|
-
trace: "#ffffff"
|
|
822
|
-
};
|
|
823
|
-
const minimalLightPalette = {
|
|
824
|
-
log: "#000000",
|
|
825
|
-
info: "#000000",
|
|
826
|
-
warn: "#000000",
|
|
827
|
-
error: "#000000",
|
|
828
|
-
debug: "#000000",
|
|
829
|
-
trace: "#000000"
|
|
830
|
-
};
|
|
831
|
-
|
|
832
|
-
const themePalettes = {
|
|
833
|
-
"catppuccin-mocha": catppuccinMochaPalette,
|
|
834
|
-
"catppuccin-latte": catppuccinLattePalette,
|
|
835
|
-
dracula: draculaPalette,
|
|
836
|
-
"github-light": githubLightPalette,
|
|
837
|
-
"minimal-dark": minimalDarkPalette,
|
|
838
|
-
"minimal-light": minimalLightPalette
|
|
839
|
-
};
|
|
840
|
-
const defaultDarkTheme = "minimal-dark";
|
|
841
|
-
const defaultLightTheme = "minimal-light";
|
|
842
|
-
function isThemeName(theme) {
|
|
843
|
-
return theme in themePalettes;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
function determineBaseTheme(themeOpt, detectedBrowserTheme) {
|
|
847
|
-
let baseThemeName;
|
|
848
|
-
if (isThemeName(themeOpt)) {
|
|
849
|
-
baseThemeName = themeOpt;
|
|
850
|
-
} else if (themeOpt === "light") {
|
|
851
|
-
baseThemeName = defaultLightTheme;
|
|
852
|
-
} else if (themeOpt === "dark") {
|
|
853
|
-
baseThemeName = defaultDarkTheme;
|
|
854
|
-
} else {
|
|
855
|
-
baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
|
|
856
|
-
}
|
|
857
|
-
return baseThemeName;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
872
|
class BrowserColorSupportDetector {
|
|
861
873
|
constructor(_window, _navigator, _overrideTheme) {
|
|
862
874
|
this._window = _window;
|
|
@@ -892,7 +904,7 @@ class BrowserColorSupportDetector {
|
|
|
892
904
|
}
|
|
893
905
|
}
|
|
894
906
|
|
|
895
|
-
function createColorino(
|
|
907
|
+
function createColorino(userPalette = {}, options = {}) {
|
|
896
908
|
const validator = new InputValidator();
|
|
897
909
|
let detectorThemeOverride;
|
|
898
910
|
if (options.theme === "dark" || options.theme === "light") {
|
|
@@ -910,9 +922,10 @@ function createColorino(palette = {}, options = {}) {
|
|
|
910
922
|
detectedBrowserTheme
|
|
911
923
|
);
|
|
912
924
|
const basePalette = themePalettes[baseThemeName];
|
|
913
|
-
const finalPalette = { ...basePalette, ...
|
|
925
|
+
const finalPalette = { ...basePalette, ...userPalette };
|
|
914
926
|
return new MyColorino(
|
|
915
927
|
finalPalette,
|
|
928
|
+
userPalette,
|
|
916
929
|
validator,
|
|
917
930
|
browserDetector,
|
|
918
931
|
// Always use browser detector
|
|
@@ -921,8 +934,6 @@ function createColorino(palette = {}, options = {}) {
|
|
|
921
934
|
options
|
|
922
935
|
);
|
|
923
936
|
}
|
|
924
|
-
const colorino = createColorino();
|
|
925
937
|
|
|
926
|
-
exports.colorino = colorino;
|
|
927
938
|
exports.createColorino = createColorino;
|
|
928
939
|
exports.themePalettes = themePalettes;
|
package/dist/browser.bundle.mjs
CHANGED
|
@@ -61,13 +61,115 @@ function isConsoleMethod(level) {
|
|
|
61
61
|
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
const catppuccinMochaPalette = {
|
|
65
|
+
log: "#cdd6f4",
|
|
66
|
+
// Text
|
|
67
|
+
info: "#89b4fa",
|
|
68
|
+
// Blue
|
|
69
|
+
warn: "#f9e2af",
|
|
70
|
+
// Yellow
|
|
71
|
+
error: "#f38ba8",
|
|
72
|
+
// Red
|
|
73
|
+
debug: "#a6adc8",
|
|
74
|
+
// Subtext0
|
|
75
|
+
trace: "#9399b2"
|
|
76
|
+
// Subtext1
|
|
77
|
+
};
|
|
78
|
+
const catppuccinLattePalette = {
|
|
79
|
+
log: "#4c4f69",
|
|
80
|
+
// Text
|
|
81
|
+
info: "#1e66f5",
|
|
82
|
+
// Blue
|
|
83
|
+
warn: "#df8e1d",
|
|
84
|
+
// Yellow
|
|
85
|
+
error: "#d20f39",
|
|
86
|
+
// Red
|
|
87
|
+
debug: "#7c7f93",
|
|
88
|
+
// Subtext0
|
|
89
|
+
trace: "#8c8fa1"
|
|
90
|
+
// Subtext1
|
|
91
|
+
};
|
|
92
|
+
const draculaPalette = {
|
|
93
|
+
log: "#f8f8f2",
|
|
94
|
+
// Foreground
|
|
95
|
+
info: "#8be9fd",
|
|
96
|
+
// Cyan
|
|
97
|
+
warn: "#f1fa8c",
|
|
98
|
+
// Yellow
|
|
99
|
+
error: "#ff5555",
|
|
100
|
+
// Red
|
|
101
|
+
debug: "#bd93f9",
|
|
102
|
+
// Purple
|
|
103
|
+
trace: "#6272a4"
|
|
104
|
+
// Comment
|
|
105
|
+
};
|
|
106
|
+
const githubLightPalette = {
|
|
107
|
+
log: "#24292e",
|
|
108
|
+
// Text
|
|
109
|
+
info: "#0366d6",
|
|
110
|
+
// Blue
|
|
111
|
+
warn: "#f9a002",
|
|
112
|
+
// Yellow
|
|
113
|
+
error: "#d73a49",
|
|
114
|
+
// Red
|
|
115
|
+
debug: "#586069",
|
|
116
|
+
// Gray
|
|
117
|
+
trace: "#6a737d"
|
|
118
|
+
// Gray-light
|
|
119
|
+
};
|
|
120
|
+
const minimalDarkPalette = {
|
|
121
|
+
log: "#ffffff",
|
|
122
|
+
info: "#ffffff",
|
|
123
|
+
warn: "#ffffff",
|
|
124
|
+
error: "#ffffff",
|
|
125
|
+
debug: "#ffffff",
|
|
126
|
+
trace: "#ffffff"
|
|
127
|
+
};
|
|
128
|
+
const minimalLightPalette = {
|
|
129
|
+
log: "#000000",
|
|
130
|
+
info: "#000000",
|
|
131
|
+
warn: "#000000",
|
|
132
|
+
error: "#000000",
|
|
133
|
+
debug: "#000000",
|
|
134
|
+
trace: "#000000"
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const themePalettes = {
|
|
138
|
+
"catppuccin-mocha": catppuccinMochaPalette,
|
|
139
|
+
"catppuccin-latte": catppuccinLattePalette,
|
|
140
|
+
dracula: draculaPalette,
|
|
141
|
+
"github-light": githubLightPalette,
|
|
142
|
+
"minimal-dark": minimalDarkPalette,
|
|
143
|
+
"minimal-light": minimalLightPalette
|
|
144
|
+
};
|
|
145
|
+
const defaultDarkTheme = "minimal-dark";
|
|
146
|
+
const defaultLightTheme = "minimal-light";
|
|
147
|
+
function isThemeName(theme) {
|
|
148
|
+
return theme in themePalettes;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function determineBaseTheme(themeOpt, detectedBrowserTheme) {
|
|
152
|
+
let baseThemeName;
|
|
153
|
+
if (isThemeName(themeOpt)) {
|
|
154
|
+
baseThemeName = themeOpt;
|
|
155
|
+
} else if (themeOpt === "light") {
|
|
156
|
+
baseThemeName = defaultLightTheme;
|
|
157
|
+
} else if (themeOpt === "dark") {
|
|
158
|
+
baseThemeName = defaultDarkTheme;
|
|
159
|
+
} else {
|
|
160
|
+
baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
|
|
161
|
+
}
|
|
162
|
+
return baseThemeName;
|
|
163
|
+
}
|
|
164
|
+
|
|
64
165
|
class MyColorino {
|
|
65
|
-
constructor(
|
|
66
|
-
this.
|
|
166
|
+
constructor(initialPalette, _userPalette, _validator, _browserColorSupportDetector, _nodeColorSupportDetector, _options = {}) {
|
|
167
|
+
this._userPalette = _userPalette;
|
|
67
168
|
this._validator = _validator;
|
|
68
169
|
this._browserColorSupportDetector = _browserColorSupportDetector;
|
|
69
170
|
this._nodeColorSupportDetector = _nodeColorSupportDetector;
|
|
70
171
|
this._options = _options;
|
|
172
|
+
this._palette = initialPalette;
|
|
71
173
|
this.isBrowser = !!this._browserColorSupportDetector;
|
|
72
174
|
this._colorLevel = this._detectColorSupport();
|
|
73
175
|
const validatePaletteResult = this._validator.validatePalette(this._palette);
|
|
@@ -75,10 +177,23 @@ class MyColorino {
|
|
|
75
177
|
if (this._colorLevel !== ColorLevel.NO_COLOR && !this._options.disableWarnings && this._colorLevel === "UnknownEnv") {
|
|
76
178
|
this._maybeWarnUser();
|
|
77
179
|
}
|
|
180
|
+
const themeOpt = this._options.theme ?? "auto";
|
|
181
|
+
if (themeOpt === "auto" && this._nodeColorSupportDetector) {
|
|
182
|
+
this._nodeColorSupportDetector.onTheme((resolvedTheme) => {
|
|
183
|
+
this._appllyResolvedTheme(resolvedTheme);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
78
186
|
}
|
|
79
187
|
_alreadyWarned = false;
|
|
80
188
|
_colorLevel;
|
|
81
189
|
isBrowser;
|
|
190
|
+
_palette;
|
|
191
|
+
_appllyResolvedTheme(resolvedTheme) {
|
|
192
|
+
const themeOpt = this._options.theme ?? "auto";
|
|
193
|
+
const baseThemeName = determineBaseTheme(themeOpt, resolvedTheme);
|
|
194
|
+
const basePalette = themePalettes[baseThemeName];
|
|
195
|
+
this._palette = { ...basePalette, ...this._userPalette };
|
|
196
|
+
}
|
|
82
197
|
log(...args) {
|
|
83
198
|
this._out("log", args);
|
|
84
199
|
}
|
|
@@ -110,10 +225,10 @@ class MyColorino {
|
|
|
110
225
|
if (this._alreadyWarned) return;
|
|
111
226
|
this._alreadyWarned = true;
|
|
112
227
|
console.warn(
|
|
113
|
-
"
|
|
228
|
+
"No ANSI color support detected in this terminal. See [https://github.com/chalk/supports-color#support-matrix](https://github.com/chalk/supports-color#support-matrix) to learn how to enable terminal color."
|
|
114
229
|
);
|
|
115
230
|
}
|
|
116
|
-
_formatValue(value, maxDepth = 5) {
|
|
231
|
+
_formatValue(value, maxDepth = this._options.maxDepth ?? 5) {
|
|
117
232
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
118
233
|
const sanitize = (val, currentDepth) => {
|
|
119
234
|
if (val === null || typeof val !== "object") return val;
|
|
@@ -198,7 +313,7 @@ ${arg}`);
|
|
|
198
313
|
}
|
|
199
314
|
_output(consoleMethod, args) {
|
|
200
315
|
if (consoleMethod === "trace") {
|
|
201
|
-
this._printCleanTrace(args
|
|
316
|
+
this._printCleanTrace(args);
|
|
202
317
|
} else {
|
|
203
318
|
console[consoleMethod](...args);
|
|
204
319
|
}
|
|
@@ -219,9 +334,7 @@ ${arg}`);
|
|
|
219
334
|
this._output(consoleMethod, coloredArgs);
|
|
220
335
|
}
|
|
221
336
|
_filterStack(stack) {
|
|
222
|
-
return stack.split("\n").filter(
|
|
223
|
-
(line) => !line.includes("colorino.js") && !line.includes("Colorino._out") && !line.includes("Colorino.error") && !line.includes("Colorino.warn") && !line.includes("Colorino.debug") && !line.includes("Colorino.info") && !line.includes("Colorino.log") && !line.includes("Colorino.trace") && !line.includes("Colorino._cleanErrorStack") && !line.includes("Colorino._printCleanTrace") && !line.includes("Colorino._filterStack")
|
|
224
|
-
).join("\n");
|
|
337
|
+
return stack.split("\n").filter((line) => !line.match(/.*colorino.*/gi)).join("\n");
|
|
225
338
|
}
|
|
226
339
|
_cleanErrorStack(error) {
|
|
227
340
|
if (!error.stack) return error;
|
|
@@ -231,14 +344,14 @@ ${arg}`);
|
|
|
231
344
|
cloned.stack = cleanStack;
|
|
232
345
|
return cloned;
|
|
233
346
|
}
|
|
234
|
-
_printCleanTrace(args
|
|
347
|
+
_printCleanTrace(args) {
|
|
235
348
|
const error = new Error();
|
|
236
349
|
if (error.stack) {
|
|
237
350
|
const cleanStack = this._filterStack(error.stack);
|
|
238
|
-
console
|
|
351
|
+
console.log(...args, `
|
|
239
352
|
${cleanStack}`);
|
|
240
353
|
} else {
|
|
241
|
-
console
|
|
354
|
+
console.log(...args);
|
|
242
355
|
}
|
|
243
356
|
}
|
|
244
357
|
}
|
|
@@ -754,107 +867,6 @@ class InputValidator {
|
|
|
754
867
|
}
|
|
755
868
|
}
|
|
756
869
|
|
|
757
|
-
const catppuccinMochaPalette = {
|
|
758
|
-
log: "#cdd6f4",
|
|
759
|
-
// Text
|
|
760
|
-
info: "#89b4fa",
|
|
761
|
-
// Blue
|
|
762
|
-
warn: "#f9e2af",
|
|
763
|
-
// Yellow
|
|
764
|
-
error: "#f38ba8",
|
|
765
|
-
// Red
|
|
766
|
-
debug: "#a6adc8",
|
|
767
|
-
// Subtext0
|
|
768
|
-
trace: "#9399b2"
|
|
769
|
-
// Subtext1
|
|
770
|
-
};
|
|
771
|
-
const catppuccinLattePalette = {
|
|
772
|
-
log: "#4c4f69",
|
|
773
|
-
// Text
|
|
774
|
-
info: "#1e66f5",
|
|
775
|
-
// Blue
|
|
776
|
-
warn: "#df8e1d",
|
|
777
|
-
// Yellow
|
|
778
|
-
error: "#d20f39",
|
|
779
|
-
// Red
|
|
780
|
-
debug: "#7c7f93",
|
|
781
|
-
// Subtext0
|
|
782
|
-
trace: "#8c8fa1"
|
|
783
|
-
// Subtext1
|
|
784
|
-
};
|
|
785
|
-
const draculaPalette = {
|
|
786
|
-
log: "#f8f8f2",
|
|
787
|
-
// Foreground
|
|
788
|
-
info: "#8be9fd",
|
|
789
|
-
// Cyan
|
|
790
|
-
warn: "#f1fa8c",
|
|
791
|
-
// Yellow
|
|
792
|
-
error: "#ff5555",
|
|
793
|
-
// Red
|
|
794
|
-
debug: "#bd93f9",
|
|
795
|
-
// Purple
|
|
796
|
-
trace: "#6272a4"
|
|
797
|
-
// Comment
|
|
798
|
-
};
|
|
799
|
-
const githubLightPalette = {
|
|
800
|
-
log: "#24292e",
|
|
801
|
-
// Text
|
|
802
|
-
info: "#0366d6",
|
|
803
|
-
// Blue
|
|
804
|
-
warn: "#f9a002",
|
|
805
|
-
// Yellow
|
|
806
|
-
error: "#d73a49",
|
|
807
|
-
// Red
|
|
808
|
-
debug: "#586069",
|
|
809
|
-
// Gray
|
|
810
|
-
trace: "#6a737d"
|
|
811
|
-
// Gray-light
|
|
812
|
-
};
|
|
813
|
-
const minimalDarkPalette = {
|
|
814
|
-
log: "#ffffff",
|
|
815
|
-
info: "#ffffff",
|
|
816
|
-
warn: "#ffffff",
|
|
817
|
-
error: "#ffffff",
|
|
818
|
-
debug: "#ffffff",
|
|
819
|
-
trace: "#ffffff"
|
|
820
|
-
};
|
|
821
|
-
const minimalLightPalette = {
|
|
822
|
-
log: "#000000",
|
|
823
|
-
info: "#000000",
|
|
824
|
-
warn: "#000000",
|
|
825
|
-
error: "#000000",
|
|
826
|
-
debug: "#000000",
|
|
827
|
-
trace: "#000000"
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
const themePalettes = {
|
|
831
|
-
"catppuccin-mocha": catppuccinMochaPalette,
|
|
832
|
-
"catppuccin-latte": catppuccinLattePalette,
|
|
833
|
-
dracula: draculaPalette,
|
|
834
|
-
"github-light": githubLightPalette,
|
|
835
|
-
"minimal-dark": minimalDarkPalette,
|
|
836
|
-
"minimal-light": minimalLightPalette
|
|
837
|
-
};
|
|
838
|
-
const defaultDarkTheme = "minimal-dark";
|
|
839
|
-
const defaultLightTheme = "minimal-light";
|
|
840
|
-
function isThemeName(theme) {
|
|
841
|
-
return theme in themePalettes;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
function determineBaseTheme(themeOpt, detectedBrowserTheme) {
|
|
845
|
-
let baseThemeName;
|
|
846
|
-
if (isThemeName(themeOpt)) {
|
|
847
|
-
baseThemeName = themeOpt;
|
|
848
|
-
} else if (themeOpt === "light") {
|
|
849
|
-
baseThemeName = defaultLightTheme;
|
|
850
|
-
} else if (themeOpt === "dark") {
|
|
851
|
-
baseThemeName = defaultDarkTheme;
|
|
852
|
-
} else {
|
|
853
|
-
baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
|
|
854
|
-
}
|
|
855
|
-
return baseThemeName;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
870
|
class BrowserColorSupportDetector {
|
|
859
871
|
constructor(_window, _navigator, _overrideTheme) {
|
|
860
872
|
this._window = _window;
|
|
@@ -890,7 +902,7 @@ class BrowserColorSupportDetector {
|
|
|
890
902
|
}
|
|
891
903
|
}
|
|
892
904
|
|
|
893
|
-
function createColorino(
|
|
905
|
+
function createColorino(userPalette = {}, options = {}) {
|
|
894
906
|
const validator = new InputValidator();
|
|
895
907
|
let detectorThemeOverride;
|
|
896
908
|
if (options.theme === "dark" || options.theme === "light") {
|
|
@@ -908,9 +920,10 @@ function createColorino(palette = {}, options = {}) {
|
|
|
908
920
|
detectedBrowserTheme
|
|
909
921
|
);
|
|
910
922
|
const basePalette = themePalettes[baseThemeName];
|
|
911
|
-
const finalPalette = { ...basePalette, ...
|
|
923
|
+
const finalPalette = { ...basePalette, ...userPalette };
|
|
912
924
|
return new MyColorino(
|
|
913
925
|
finalPalette,
|
|
926
|
+
userPalette,
|
|
914
927
|
validator,
|
|
915
928
|
browserDetector,
|
|
916
929
|
// Always use browser detector
|
|
@@ -919,6 +932,5 @@ function createColorino(palette = {}, options = {}) {
|
|
|
919
932
|
options
|
|
920
933
|
);
|
|
921
934
|
}
|
|
922
|
-
const colorino = createColorino();
|
|
923
935
|
|
|
924
|
-
export {
|
|
936
|
+
export { createColorino, themePalettes };
|