colorino 0.13.2 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -7
- package/dist/browser.d.mts +24 -3
- package/dist/browser.d.ts +24 -3
- package/dist/browser.mjs +359 -16
- package/dist/cdn.js +902 -0
- package/dist/cdn.js.map +1 -0
- package/dist/cdn.min.js +2 -0
- package/dist/cdn.min.js.map +1 -0
- package/dist/cdn.min.mjs +1 -0
- package/dist/{shared/colorino.vAejLjBp.mjs → cdn.mjs} +224 -274
- package/dist/cdn.mjs.map +1 -0
- package/dist/node.cjs +428 -22
- package/dist/node.d.cts +24 -3
- package/dist/node.d.mts +24 -3
- package/dist/node.d.ts +24 -3
- package/dist/node.mjs +410 -4
- package/package.json +18 -12
- package/dist/browser.bundle.cjs +0 -1011
- package/dist/browser.bundle.mjs +0 -1007
- package/dist/browser.cjs +0 -72
- package/dist/browser.d.cts +0 -8
- package/dist/shared/colorino.DMgDgITw.cjs +0 -948
- package/dist/shared/colorino.FdIbpxRG.d.cts +0 -25
- package/dist/shared/colorino.FdIbpxRG.d.mts +0 -25
- package/dist/shared/colorino.FdIbpxRG.d.ts +0 -25
package/dist/node.cjs
CHANGED
|
@@ -1,11 +1,417 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const neverthrow = require('neverthrow');
|
|
4
4
|
const node_child_process = require('node:child_process');
|
|
5
5
|
const node_url = require('node:url');
|
|
6
6
|
const node_path = require('node:path');
|
|
7
7
|
|
|
8
8
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
9
|
+
const ColorinoBrowserColorized = Symbol("colorino.browserColorized");
|
|
10
|
+
const ColorinoBrowserObject = Symbol("colorino.browserObject");
|
|
11
|
+
|
|
12
|
+
var ColorLevel = /* @__PURE__ */ ((ColorLevel2) => {
|
|
13
|
+
ColorLevel2[ColorLevel2["NO_COLOR"] = 0] = "NO_COLOR";
|
|
14
|
+
ColorLevel2[ColorLevel2["ANSI"] = 1] = "ANSI";
|
|
15
|
+
ColorLevel2[ColorLevel2["ANSI256"] = 2] = "ANSI256";
|
|
16
|
+
ColorLevel2[ColorLevel2["TRUECOLOR"] = 3] = "TRUECOLOR";
|
|
17
|
+
return ColorLevel2;
|
|
18
|
+
})(ColorLevel || {});
|
|
19
|
+
|
|
20
|
+
class TypeValidator {
|
|
21
|
+
static isNull(value) {
|
|
22
|
+
return value === null;
|
|
23
|
+
}
|
|
24
|
+
static isUndefined(value) {
|
|
25
|
+
return value === void 0;
|
|
26
|
+
}
|
|
27
|
+
static isNullOrUndefined(value) {
|
|
28
|
+
return value == null;
|
|
29
|
+
}
|
|
30
|
+
static isObject(value) {
|
|
31
|
+
return typeof value === "object" && value !== null;
|
|
32
|
+
}
|
|
33
|
+
static isString(value) {
|
|
34
|
+
return typeof value === "string" || value instanceof String;
|
|
35
|
+
}
|
|
36
|
+
static isArray(value) {
|
|
37
|
+
return Array.isArray(value);
|
|
38
|
+
}
|
|
39
|
+
static isError(value) {
|
|
40
|
+
return value instanceof Error;
|
|
41
|
+
}
|
|
42
|
+
static isBrowserColorizedArg(value) {
|
|
43
|
+
return TypeValidator.isObject(value) && ColorinoBrowserColorized in value;
|
|
44
|
+
}
|
|
45
|
+
static isBrowserObjectArg(value) {
|
|
46
|
+
return TypeValidator.isObject(value) && ColorinoBrowserObject in value;
|
|
47
|
+
}
|
|
48
|
+
static isAnsiColoredString(value) {
|
|
49
|
+
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value.toString());
|
|
50
|
+
}
|
|
51
|
+
static isFormattableObject(value) {
|
|
52
|
+
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value) && !TypeValidator.isString(value);
|
|
53
|
+
}
|
|
54
|
+
static isConsoleMethod(level) {
|
|
55
|
+
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class AbstractColorino {
|
|
60
|
+
constructor(initialPalette, _userPalette, _validator, colorLevel, _options = {}) {
|
|
61
|
+
this._userPalette = _userPalette;
|
|
62
|
+
this._validator = _validator;
|
|
63
|
+
this._options = _options;
|
|
64
|
+
this._palette = initialPalette;
|
|
65
|
+
const validatePaletteResult = this._validator.validatePalette(this._palette);
|
|
66
|
+
if (validatePaletteResult.isErr()) throw validatePaletteResult.error;
|
|
67
|
+
this._colorLevel = colorLevel;
|
|
68
|
+
}
|
|
69
|
+
_alreadyWarned = false;
|
|
70
|
+
_colorLevel;
|
|
71
|
+
_palette;
|
|
72
|
+
log(...args) {
|
|
73
|
+
this._out("log", args);
|
|
74
|
+
}
|
|
75
|
+
info(...args) {
|
|
76
|
+
this._out("info", args);
|
|
77
|
+
}
|
|
78
|
+
warn(...args) {
|
|
79
|
+
this._out("warn", args);
|
|
80
|
+
}
|
|
81
|
+
error(...args) {
|
|
82
|
+
this._out("error", args);
|
|
83
|
+
}
|
|
84
|
+
trace(...args) {
|
|
85
|
+
this._out("trace", args);
|
|
86
|
+
}
|
|
87
|
+
debug(...args) {
|
|
88
|
+
this._out("debug", args);
|
|
89
|
+
}
|
|
90
|
+
colorize(text, hex) {
|
|
91
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
92
|
+
return text;
|
|
93
|
+
}
|
|
94
|
+
if (this.isBrowser()) {
|
|
95
|
+
return {
|
|
96
|
+
[ColorinoBrowserColorized]: true,
|
|
97
|
+
text,
|
|
98
|
+
hex
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const ansiPrefix = this._toAnsiPrefix(hex);
|
|
102
|
+
if (!ansiPrefix) {
|
|
103
|
+
return text;
|
|
104
|
+
}
|
|
105
|
+
return `${ansiPrefix}${text}\x1B[0m`;
|
|
106
|
+
}
|
|
107
|
+
_out(level, args) {
|
|
108
|
+
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
109
|
+
const processedArgs = this.processArgs(args);
|
|
110
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
111
|
+
this.output(consoleMethod, processedArgs);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const coloredArgs = this.applyColors(consoleMethod, processedArgs);
|
|
115
|
+
this.output(consoleMethod, coloredArgs);
|
|
116
|
+
}
|
|
117
|
+
_toAnsiPrefix(_hex) {
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
120
|
+
_formatValue(value, maxDepth = this._options.maxDepth ?? 5) {
|
|
121
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
122
|
+
const sanitizeArray = (items, depth) => {
|
|
123
|
+
return items.map((item) => sanitize(item, depth));
|
|
124
|
+
};
|
|
125
|
+
const sanitizeObject = (obj, depth) => {
|
|
126
|
+
const result = {};
|
|
127
|
+
for (const key in obj) {
|
|
128
|
+
result[key] = sanitize(obj[key], depth);
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
const sanitize = (val, currentDepth) => {
|
|
133
|
+
if (TypeValidator.isNullOrUndefined(val) || !TypeValidator.isObject(val)) {
|
|
134
|
+
return val;
|
|
135
|
+
}
|
|
136
|
+
if (seen.has(val)) return "[Circular]";
|
|
137
|
+
seen.add(val);
|
|
138
|
+
if (currentDepth >= maxDepth) return "[Object]";
|
|
139
|
+
const nextDepth = currentDepth + 1;
|
|
140
|
+
if (TypeValidator.isArray(val)) {
|
|
141
|
+
return sanitizeArray(val, nextDepth);
|
|
142
|
+
}
|
|
143
|
+
return sanitizeObject(val, nextDepth);
|
|
144
|
+
};
|
|
145
|
+
return JSON.stringify(sanitize(value, 0), null, 2);
|
|
146
|
+
}
|
|
147
|
+
_filterStack(stack) {
|
|
148
|
+
return stack.split("\n").filter((line) => !line.match(/.*colorino.*/gi)).join("\n");
|
|
149
|
+
}
|
|
150
|
+
_cleanErrorStack(error) {
|
|
151
|
+
if (!error.stack) return error;
|
|
152
|
+
const cleanStack = this._filterStack(error.stack);
|
|
153
|
+
const cloned = Object.create(Object.getPrototypeOf(error));
|
|
154
|
+
Object.assign(cloned, error);
|
|
155
|
+
cloned.stack = cleanStack;
|
|
156
|
+
return cloned;
|
|
157
|
+
}
|
|
158
|
+
_printCleanTrace(args) {
|
|
159
|
+
const error = new Error();
|
|
160
|
+
if (error.stack) {
|
|
161
|
+
const cleanStack = this._filterStack(error.stack);
|
|
162
|
+
console.log(...args, `
|
|
163
|
+
${cleanStack}`);
|
|
164
|
+
} else {
|
|
165
|
+
console.log(...args);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function hexToRgb(hex) {
|
|
171
|
+
const match = hex.toString().match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
172
|
+
if (!match) {
|
|
173
|
+
return [0, 0, 0];
|
|
174
|
+
}
|
|
175
|
+
let colorString = match[0];
|
|
176
|
+
if (match[0].length === 3) {
|
|
177
|
+
colorString = [...colorString].map((char) => char + char).join("");
|
|
178
|
+
}
|
|
179
|
+
const integer = parseInt(colorString, 16);
|
|
180
|
+
const r = integer >> 16 & 255;
|
|
181
|
+
const g = integer >> 8 & 255;
|
|
182
|
+
const b = integer & 255;
|
|
183
|
+
return [r, g, b];
|
|
184
|
+
}
|
|
185
|
+
function rgbToAnsi256(rgb) {
|
|
186
|
+
const [r, g, b] = rgb;
|
|
187
|
+
if (r === g && g === b) {
|
|
188
|
+
if (r < 8) return 16;
|
|
189
|
+
if (r > 248) return 231;
|
|
190
|
+
return Math.round((r - 8) / 247 * 24) + 232;
|
|
191
|
+
}
|
|
192
|
+
return 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
|
193
|
+
}
|
|
194
|
+
function rgbToHsvValue(rgb) {
|
|
195
|
+
const r = rgb[0] / 255;
|
|
196
|
+
const g = rgb[1] / 255;
|
|
197
|
+
const b = rgb[2] / 255;
|
|
198
|
+
const v = Math.max(r, g, b);
|
|
199
|
+
return v * 100;
|
|
200
|
+
}
|
|
201
|
+
function rgbToAnsi16(rgb) {
|
|
202
|
+
const [r, g, b] = rgb;
|
|
203
|
+
const value = rgbToHsvValue(rgb);
|
|
204
|
+
const roundedValue = Math.round(value / 50);
|
|
205
|
+
if (roundedValue === 0) {
|
|
206
|
+
return 30;
|
|
207
|
+
}
|
|
208
|
+
let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
|
209
|
+
if (roundedValue === 2) {
|
|
210
|
+
ansi += 60;
|
|
211
|
+
}
|
|
212
|
+
return ansi;
|
|
213
|
+
}
|
|
214
|
+
const colorConverter = {
|
|
215
|
+
hex: {
|
|
216
|
+
toRgb: hexToRgb,
|
|
217
|
+
toAnsi16: (hex) => rgbToAnsi16(hexToRgb(hex)),
|
|
218
|
+
toAnsi256: (hex) => rgbToAnsi256(hexToRgb(hex))
|
|
219
|
+
}};
|
|
220
|
+
|
|
221
|
+
class ColorinoNode extends AbstractColorino {
|
|
222
|
+
constructor(initialPalette, userPalette, validator, colorLevel, options = {}) {
|
|
223
|
+
super(initialPalette, userPalette, validator, colorLevel, options);
|
|
224
|
+
this._maybeWarnUser();
|
|
225
|
+
}
|
|
226
|
+
applyColors(consoleMethod, args) {
|
|
227
|
+
const paletteHex = this._palette[consoleMethod];
|
|
228
|
+
const prefix = this._toAnsiPrefix(paletteHex);
|
|
229
|
+
if (!prefix) return args;
|
|
230
|
+
return args.map((arg) => {
|
|
231
|
+
if (!TypeValidator.isString(arg)) return arg;
|
|
232
|
+
if (TypeValidator.isAnsiColoredString(arg)) return arg;
|
|
233
|
+
return `${prefix}${String(arg)}\x1B[0m`;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
output(consoleMethod, args) {
|
|
237
|
+
if (consoleMethod === "trace") {
|
|
238
|
+
this._printCleanTrace(args);
|
|
239
|
+
} else {
|
|
240
|
+
console[consoleMethod](...args);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
processArgs(args) {
|
|
244
|
+
const processedArgs = [];
|
|
245
|
+
let previousWasObject = false;
|
|
246
|
+
for (const arg of args) {
|
|
247
|
+
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
248
|
+
processedArgs.push(arg);
|
|
249
|
+
previousWasObject = false;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (TypeValidator.isFormattableObject(arg)) {
|
|
253
|
+
processedArgs.push(`
|
|
254
|
+
${this._formatValue(arg)}`);
|
|
255
|
+
previousWasObject = true;
|
|
256
|
+
} else if (TypeValidator.isError(arg)) {
|
|
257
|
+
processedArgs.push("\n", this._cleanErrorStack(arg));
|
|
258
|
+
previousWasObject = true;
|
|
259
|
+
} else {
|
|
260
|
+
if (TypeValidator.isString(arg) && previousWasObject) {
|
|
261
|
+
processedArgs.push(`
|
|
262
|
+
${arg}`);
|
|
263
|
+
} else {
|
|
264
|
+
processedArgs.push(arg);
|
|
265
|
+
}
|
|
266
|
+
previousWasObject = false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return processedArgs;
|
|
270
|
+
}
|
|
271
|
+
isBrowser() {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
_toAnsiPrefix(hex) {
|
|
275
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
276
|
+
return "";
|
|
277
|
+
}
|
|
278
|
+
switch (this._colorLevel) {
|
|
279
|
+
case ColorLevel.TRUECOLOR: {
|
|
280
|
+
const [r, g, b] = colorConverter.hex.toRgb(hex);
|
|
281
|
+
return `\x1B[38;2;${r};${g};${b}m`;
|
|
282
|
+
}
|
|
283
|
+
case ColorLevel.ANSI256: {
|
|
284
|
+
const code = colorConverter.hex.toAnsi256(hex);
|
|
285
|
+
return `\x1B[38;5;${code}m`;
|
|
286
|
+
}
|
|
287
|
+
case ColorLevel.ANSI:
|
|
288
|
+
default: {
|
|
289
|
+
const code = colorConverter.hex.toAnsi16(hex);
|
|
290
|
+
return `\x1B[${code}m`;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
_maybeWarnUser() {
|
|
295
|
+
if (this._alreadyWarned) return;
|
|
296
|
+
this._alreadyWarned = true;
|
|
297
|
+
console.warn(
|
|
298
|
+
"No ANSI color support detected in this terminal. See https://github.com/chalk/supports-color#support-matrix to learn how to enable terminal color."
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const catppuccinMochaPalette = {
|
|
304
|
+
log: "#cdd6f4",
|
|
305
|
+
// Text
|
|
306
|
+
info: "#89b4fa",
|
|
307
|
+
// Blue
|
|
308
|
+
warn: "#f9e2af",
|
|
309
|
+
// Yellow
|
|
310
|
+
error: "#f38ba8",
|
|
311
|
+
// Red
|
|
312
|
+
debug: "#a6adc8",
|
|
313
|
+
// Subtext0
|
|
314
|
+
trace: "#9399b2"
|
|
315
|
+
// Subtext1
|
|
316
|
+
};
|
|
317
|
+
const catppuccinLattePalette = {
|
|
318
|
+
log: "#4c4f69",
|
|
319
|
+
// Text
|
|
320
|
+
info: "#1e66f5",
|
|
321
|
+
// Blue
|
|
322
|
+
warn: "#df8e1d",
|
|
323
|
+
// Yellow
|
|
324
|
+
error: "#d20f39",
|
|
325
|
+
// Red
|
|
326
|
+
debug: "#7c7f93",
|
|
327
|
+
// Subtext0
|
|
328
|
+
trace: "#8c8fa1"
|
|
329
|
+
// Subtext1
|
|
330
|
+
};
|
|
331
|
+
const draculaPalette = {
|
|
332
|
+
log: "#f8f8f2",
|
|
333
|
+
// Foreground
|
|
334
|
+
info: "#8be9fd",
|
|
335
|
+
// Cyan
|
|
336
|
+
warn: "#f1fa8c",
|
|
337
|
+
// Yellow
|
|
338
|
+
error: "#ff5555",
|
|
339
|
+
// Red
|
|
340
|
+
debug: "#bd93f9",
|
|
341
|
+
// Purple
|
|
342
|
+
trace: "#6272a4"
|
|
343
|
+
// Comment
|
|
344
|
+
};
|
|
345
|
+
const githubLightPalette = {
|
|
346
|
+
log: "#24292e",
|
|
347
|
+
// Text
|
|
348
|
+
info: "#0366d6",
|
|
349
|
+
// Blue
|
|
350
|
+
warn: "#f9a002",
|
|
351
|
+
// Yellow
|
|
352
|
+
error: "#d73a49",
|
|
353
|
+
// Red
|
|
354
|
+
debug: "#586069",
|
|
355
|
+
// Gray
|
|
356
|
+
trace: "#6a737d"
|
|
357
|
+
// Gray-light
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const themePalettes = {
|
|
361
|
+
"catppuccin-mocha": catppuccinMochaPalette,
|
|
362
|
+
"catppuccin-latte": catppuccinLattePalette,
|
|
363
|
+
dracula: draculaPalette,
|
|
364
|
+
"github-light": githubLightPalette
|
|
365
|
+
};
|
|
366
|
+
const defaultDarkTheme = "dracula";
|
|
367
|
+
const defaultLightTheme = "github-light";
|
|
368
|
+
function isThemeName(theme) {
|
|
369
|
+
return theme in themePalettes;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function determineBaseTheme(themeOpt, detectedBrowserTheme) {
|
|
373
|
+
let baseThemeName;
|
|
374
|
+
if (isThemeName(themeOpt)) {
|
|
375
|
+
baseThemeName = themeOpt;
|
|
376
|
+
} else if (themeOpt === "light") {
|
|
377
|
+
baseThemeName = defaultLightTheme;
|
|
378
|
+
} else if (themeOpt === "dark") {
|
|
379
|
+
baseThemeName = defaultDarkTheme;
|
|
380
|
+
} else {
|
|
381
|
+
baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
|
|
382
|
+
}
|
|
383
|
+
return baseThemeName;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
class InputValidationError extends Error {
|
|
387
|
+
constructor(message) {
|
|
388
|
+
super(message);
|
|
389
|
+
this.name = "InputValidationError";
|
|
390
|
+
Object.setPrototypeOf(this, InputValidationError.prototype);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
class InputValidator {
|
|
395
|
+
validateHex(hex) {
|
|
396
|
+
const trimmedHex = hex.trim();
|
|
397
|
+
const isHexValid = /^#[0-9A-F]{6}$/i.test(trimmedHex);
|
|
398
|
+
if (!isHexValid) {
|
|
399
|
+
return neverthrow.err(new InputValidationError(`Invalid hex color: '${hex}'`));
|
|
400
|
+
}
|
|
401
|
+
return neverthrow.ok(true);
|
|
402
|
+
}
|
|
403
|
+
validatePalette(palette) {
|
|
404
|
+
for (const level in palette) {
|
|
405
|
+
const hex = palette[level];
|
|
406
|
+
const result = this.validateHex(hex);
|
|
407
|
+
if (result.isErr()) {
|
|
408
|
+
return neverthrow.err(result.error);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return neverthrow.ok(true);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
9
415
|
const __dirname$1 = node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node.cjs', document.baseURI).href))));
|
|
10
416
|
function getTerminalThemeSync() {
|
|
11
417
|
const scriptPath = node_path.join(__dirname$1, "osc-child-probe.js");
|
|
@@ -68,59 +474,59 @@ class NodeColorSupportDetector {
|
|
|
68
474
|
}
|
|
69
475
|
getColorLevel() {
|
|
70
476
|
if (this._envNoColor !== void 0 && this._envNoColor !== "") {
|
|
71
|
-
return
|
|
477
|
+
return ColorLevel.NO_COLOR;
|
|
72
478
|
}
|
|
73
479
|
if (this._envForceColor !== void 0) {
|
|
74
480
|
if (this._envForceColor === "0" || this._envForceColor === "false") {
|
|
75
|
-
return
|
|
481
|
+
return ColorLevel.NO_COLOR;
|
|
76
482
|
}
|
|
77
483
|
if (this._envForceColor === "1" || this._envForceColor === "true") {
|
|
78
|
-
return
|
|
484
|
+
return ColorLevel.ANSI;
|
|
79
485
|
}
|
|
80
486
|
const level = parseInt(this._envForceColor, 10);
|
|
81
487
|
if (level >= 0 && level <= 3) {
|
|
82
488
|
return level;
|
|
83
489
|
}
|
|
84
|
-
return
|
|
490
|
+
return ColorLevel.ANSI;
|
|
85
491
|
}
|
|
86
492
|
const isForced = this._envCliColorForce !== void 0 && this._envCliColorForce !== "0";
|
|
87
493
|
if (!this._isTTY && !isForced) {
|
|
88
|
-
return
|
|
494
|
+
return ColorLevel.NO_COLOR;
|
|
89
495
|
}
|
|
90
496
|
if (this._envTerm === "dumb") {
|
|
91
|
-
return
|
|
497
|
+
return ColorLevel.NO_COLOR;
|
|
92
498
|
}
|
|
93
499
|
if (this._envColorTerm === "truecolor" || this._envColorTerm === "24bit") {
|
|
94
|
-
return
|
|
500
|
+
return ColorLevel.TRUECOLOR;
|
|
95
501
|
}
|
|
96
502
|
if (this._envWtSession !== void 0) {
|
|
97
|
-
return
|
|
503
|
+
return ColorLevel.TRUECOLOR;
|
|
98
504
|
}
|
|
99
505
|
if (this._envTerm) {
|
|
100
506
|
if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) || this._envTerm.endsWith("-truecolor")) {
|
|
101
|
-
return
|
|
507
|
+
return ColorLevel.TRUECOLOR;
|
|
102
508
|
}
|
|
103
509
|
if (/-256(color)?$/i.test(this._envTerm)) {
|
|
104
|
-
return
|
|
510
|
+
return ColorLevel.ANSI256;
|
|
105
511
|
}
|
|
106
512
|
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(
|
|
107
513
|
this._envTerm
|
|
108
514
|
)) {
|
|
109
|
-
return
|
|
515
|
+
return ColorLevel.ANSI;
|
|
110
516
|
}
|
|
111
517
|
}
|
|
112
518
|
if (this._envColorTerm) {
|
|
113
|
-
return
|
|
519
|
+
return ColorLevel.ANSI;
|
|
114
520
|
}
|
|
115
521
|
if (this._envCliColor !== void 0 && this._envCliColor !== "0") {
|
|
116
|
-
return
|
|
522
|
+
return ColorLevel.ANSI;
|
|
117
523
|
}
|
|
118
|
-
return this._isTTY || isForced ?
|
|
524
|
+
return this._isTTY || isForced ? ColorLevel.ANSI : ColorLevel.NO_COLOR;
|
|
119
525
|
}
|
|
120
526
|
}
|
|
121
527
|
|
|
122
528
|
function createColorino(userPalette = {}, options = {}) {
|
|
123
|
-
const validator = new
|
|
529
|
+
const validator = new InputValidator();
|
|
124
530
|
const themeOpt = options.theme ?? "auto";
|
|
125
531
|
let detectorThemeOverride;
|
|
126
532
|
if (themeOpt === "dark" || themeOpt === "light") {
|
|
@@ -134,20 +540,20 @@ function createColorino(userPalette = {}, options = {}) {
|
|
|
134
540
|
options.disableOscProbe ?? false
|
|
135
541
|
);
|
|
136
542
|
const detectedTerminalTheme = themeOpt === "auto" && !options.disableOscProbe ? nodeDetector.getTheme() : "unknown";
|
|
137
|
-
const baseThemeName =
|
|
138
|
-
const basePalette =
|
|
543
|
+
const baseThemeName = determineBaseTheme(themeOpt, detectedTerminalTheme);
|
|
544
|
+
const basePalette = themePalettes[baseThemeName];
|
|
139
545
|
const finalPalette = { ...basePalette, ...userPalette };
|
|
140
|
-
|
|
546
|
+
const colorLevel = nodeDetector.isNodeEnv() ? nodeDetector.getColorLevel() ?? "UnknownEnv" : "UnknownEnv";
|
|
547
|
+
return new ColorinoNode(
|
|
141
548
|
finalPalette,
|
|
142
549
|
userPalette,
|
|
143
550
|
validator,
|
|
144
|
-
|
|
145
|
-
nodeDetector,
|
|
551
|
+
colorLevel,
|
|
146
552
|
options
|
|
147
553
|
);
|
|
148
554
|
}
|
|
149
555
|
const colorino = createColorino();
|
|
150
556
|
|
|
151
|
-
exports.themePalettes = inputValidator.themePalettes;
|
|
152
557
|
exports.colorino = colorino;
|
|
153
558
|
exports.createColorino = createColorino;
|
|
559
|
+
exports.themePalettes = themePalettes;
|
package/dist/node.d.cts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
2
|
+
type LogLevel = ConsoleMethod & string;
|
|
3
|
+
type Palette = Record<LogLevel, string>;
|
|
4
|
+
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
5
|
+
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light';
|
|
6
|
+
interface ColorinoOptions {
|
|
7
|
+
disableWarnings?: boolean;
|
|
8
|
+
theme?: TerminalTheme | ThemeName | 'auto';
|
|
9
|
+
disableOscProbe?: boolean;
|
|
10
|
+
maxDepth?: number;
|
|
11
|
+
}
|
|
12
|
+
interface Colorino {
|
|
13
|
+
log(...args: unknown[]): void;
|
|
14
|
+
info(...args: unknown[]): void;
|
|
15
|
+
warn(...args: unknown[]): void;
|
|
16
|
+
error(...args: unknown[]): void;
|
|
17
|
+
debug(...args: unknown[]): void;
|
|
18
|
+
trace(...args: unknown[]): void;
|
|
19
|
+
colorize(text: string, hex: string): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare const themePalettes: Record<ThemeName, Palette>;
|
|
3
23
|
|
|
4
24
|
declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
25
|
|
|
6
26
|
declare const colorino: Colorino;
|
|
7
27
|
|
|
8
|
-
export {
|
|
28
|
+
export { colorino, createColorino, themePalettes };
|
|
29
|
+
export type { Colorino, ColorinoOptions, LogLevel, Palette, ThemeName };
|
package/dist/node.d.mts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
2
|
+
type LogLevel = ConsoleMethod & string;
|
|
3
|
+
type Palette = Record<LogLevel, string>;
|
|
4
|
+
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
5
|
+
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light';
|
|
6
|
+
interface ColorinoOptions {
|
|
7
|
+
disableWarnings?: boolean;
|
|
8
|
+
theme?: TerminalTheme | ThemeName | 'auto';
|
|
9
|
+
disableOscProbe?: boolean;
|
|
10
|
+
maxDepth?: number;
|
|
11
|
+
}
|
|
12
|
+
interface Colorino {
|
|
13
|
+
log(...args: unknown[]): void;
|
|
14
|
+
info(...args: unknown[]): void;
|
|
15
|
+
warn(...args: unknown[]): void;
|
|
16
|
+
error(...args: unknown[]): void;
|
|
17
|
+
debug(...args: unknown[]): void;
|
|
18
|
+
trace(...args: unknown[]): void;
|
|
19
|
+
colorize(text: string, hex: string): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare const themePalettes: Record<ThemeName, Palette>;
|
|
3
23
|
|
|
4
24
|
declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
25
|
|
|
6
26
|
declare const colorino: Colorino;
|
|
7
27
|
|
|
8
|
-
export {
|
|
28
|
+
export { colorino, createColorino, themePalettes };
|
|
29
|
+
export type { Colorino, ColorinoOptions, LogLevel, Palette, ThemeName };
|
package/dist/node.d.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
2
|
+
type LogLevel = ConsoleMethod & string;
|
|
3
|
+
type Palette = Record<LogLevel, string>;
|
|
4
|
+
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
5
|
+
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light';
|
|
6
|
+
interface ColorinoOptions {
|
|
7
|
+
disableWarnings?: boolean;
|
|
8
|
+
theme?: TerminalTheme | ThemeName | 'auto';
|
|
9
|
+
disableOscProbe?: boolean;
|
|
10
|
+
maxDepth?: number;
|
|
11
|
+
}
|
|
12
|
+
interface Colorino {
|
|
13
|
+
log(...args: unknown[]): void;
|
|
14
|
+
info(...args: unknown[]): void;
|
|
15
|
+
warn(...args: unknown[]): void;
|
|
16
|
+
error(...args: unknown[]): void;
|
|
17
|
+
debug(...args: unknown[]): void;
|
|
18
|
+
trace(...args: unknown[]): void;
|
|
19
|
+
colorize(text: string, hex: string): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare const themePalettes: Record<ThemeName, Palette>;
|
|
3
23
|
|
|
4
24
|
declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
25
|
|
|
6
26
|
declare const colorino: Colorino;
|
|
7
27
|
|
|
8
|
-
export {
|
|
28
|
+
export { colorino, createColorino, themePalettes };
|
|
29
|
+
export type { Colorino, ColorinoOptions, LogLevel, Palette, ThemeName };
|