colorino 0.3.3 → 0.5.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 +148 -81
- package/dist/browser.cjs +23 -13
- package/dist/browser.d.cts +3 -4
- package/dist/browser.d.mts +3 -4
- package/dist/browser.d.ts +3 -4
- package/dist/browser.mjs +17 -7
- package/dist/node.cjs +94 -79
- package/dist/node.d.cts +3 -4
- package/dist/node.d.mts +3 -4
- package/dist/node.d.ts +3 -4
- package/dist/node.mjs +75 -60
- package/dist/shared/colorino.B1MNcUze.d.cts +455 -0
- package/dist/shared/colorino.B1MNcUze.d.mts +455 -0
- package/dist/shared/colorino.B1MNcUze.d.ts +455 -0
- package/dist/shared/colorino.B9WUj1qg.cjs +777 -0
- package/dist/shared/colorino.CsFoITs1.mjs +768 -0
- package/package.json +16 -13
- package/dist/shared/colorino.Ddpe9uIB.d.cts +0 -89
- package/dist/shared/colorino.Ddpe9uIB.d.mts +0 -89
- package/dist/shared/colorino.Ddpe9uIB.d.ts +0 -89
- package/dist/shared/colorino.gkk2eRGY.cjs +0 -219
- package/dist/shared/colorino.iQv4mlpl.mjs +0 -213
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "colorino",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A super simple colorized logger that gets the most out of your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,12 +43,13 @@
|
|
|
43
43
|
],
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "unbuild",
|
|
46
|
-
"
|
|
46
|
+
"format": "oxlint --fix && oxfmt",
|
|
47
47
|
"test:all": "npm run test:node && npm run test:browser",
|
|
48
|
-
"test:node": "vitest run --
|
|
49
|
-
"test:browser": "vitest run --
|
|
50
|
-
"test:
|
|
51
|
-
"test:
|
|
48
|
+
"test:node": "vitest run --project=node",
|
|
49
|
+
"test:browser": "vitest run --project=chromium --browser=chromium",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"test:coverage": "vitest run --coverage",
|
|
52
|
+
"test:ui": "vitest --ui",
|
|
52
53
|
"version:patch": "npm version patch",
|
|
53
54
|
"version:minor": "npm version minor",
|
|
54
55
|
"version:major": "npm version major",
|
|
@@ -61,28 +62,30 @@
|
|
|
61
62
|
"neverthrow": "^8.2.0"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
|
-
"@
|
|
65
|
+
"@playwright/test": "^1.57.0",
|
|
65
66
|
"@types/node": "^24.9.2",
|
|
66
|
-
"@vitest/
|
|
67
|
-
"@vitest/
|
|
67
|
+
"@vitest/browser-playwright": "^4.0.15",
|
|
68
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
69
|
+
"@vitest/ui": "^4.0.15",
|
|
68
70
|
"husky": "^9.0.0",
|
|
69
|
-
"jsdom": "^27.1.0",
|
|
70
71
|
"lint-staged": "^15.2.0",
|
|
71
72
|
"oxfmt": "^0.9.0",
|
|
72
73
|
"oxlint": "^0.2.0",
|
|
74
|
+
"playwright": "^1.57.0",
|
|
73
75
|
"tsx": "^4.20.6",
|
|
76
|
+
"typescript": "^5.9.3",
|
|
74
77
|
"unbuild": "^3.6.1",
|
|
75
|
-
"vitest": "^4.0.
|
|
78
|
+
"vitest": "^4.0.15"
|
|
76
79
|
},
|
|
77
80
|
"lint-staged": {
|
|
78
|
-
"*.{ts,json
|
|
81
|
+
"*.{ts,json}": [
|
|
79
82
|
"oxlint --fix",
|
|
80
83
|
"oxfmt"
|
|
81
84
|
],
|
|
82
85
|
"*.ts": "vitest related --run"
|
|
83
86
|
},
|
|
84
87
|
"engines": {
|
|
85
|
-
"node": ">=
|
|
88
|
+
"node": ">=17.0.0",
|
|
86
89
|
"npm": ">=8.0.0"
|
|
87
90
|
},
|
|
88
91
|
"publishConfig": {
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Result } from 'neverthrow';
|
|
2
|
-
|
|
3
|
-
type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
4
|
-
type LogLevel = ConsoleMethod & string;
|
|
5
|
-
type Palette = Record<LogLevel, string>;
|
|
6
|
-
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
7
|
-
interface ColorinoOptions {
|
|
8
|
-
disableWarnings?: boolean;
|
|
9
|
-
theme?: TerminalTheme;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
declare enum ColorLevel {
|
|
13
|
-
NO_COLOR = 0,
|
|
14
|
-
ANSI = 1,
|
|
15
|
-
ANSI256 = 2,
|
|
16
|
-
TRUECOLOR = 3
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ColorSupportDetectorInterface {
|
|
20
|
-
getColorLevel(): ColorLevel;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
declare class NodeColorSupportDetector implements ColorSupportDetectorInterface {
|
|
24
|
-
private readonly _process?;
|
|
25
|
-
private readonly _envForceColor?;
|
|
26
|
-
private readonly _envTerm?;
|
|
27
|
-
private readonly _envColorTerm?;
|
|
28
|
-
private readonly _envNoColor?;
|
|
29
|
-
private readonly _envCliColor?;
|
|
30
|
-
private readonly _envCliColorForce?;
|
|
31
|
-
private readonly _envWtSession?;
|
|
32
|
-
private readonly _isTTY?;
|
|
33
|
-
private readonly _querier?;
|
|
34
|
-
private readonly _overrideTheme?;
|
|
35
|
-
constructor(_process?: NodeJS.Process | undefined, overrideTheme?: TerminalTheme);
|
|
36
|
-
isNodeEnv(): boolean;
|
|
37
|
-
getColorLevel(): ColorLevel;
|
|
38
|
-
getTheme(): Promise<TerminalTheme>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
declare class BrowserColorSupportDetector implements ColorSupportDetectorInterface {
|
|
42
|
-
private readonly _window;
|
|
43
|
-
private readonly _navigator;
|
|
44
|
-
private readonly _overrideTheme?;
|
|
45
|
-
constructor(_window: {
|
|
46
|
-
document: HTMLDocument;
|
|
47
|
-
matchMedia(arg0: string): {
|
|
48
|
-
matches: unknown;
|
|
49
|
-
};
|
|
50
|
-
} | undefined, _navigator: {
|
|
51
|
-
userAgent: string;
|
|
52
|
-
} | undefined, _overrideTheme?: TerminalTheme | undefined);
|
|
53
|
-
isBrowserEnv(): boolean;
|
|
54
|
-
getColorLevel(): ColorLevel;
|
|
55
|
-
getTheme(): TerminalTheme;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
declare class ColorinoError extends Error {
|
|
59
|
-
constructor(message: string);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
declare class InputValidator {
|
|
63
|
-
validateHex(hex: string): Result<boolean, ColorinoError>;
|
|
64
|
-
validatePalette(palette: Palette): Result<boolean, ColorinoError>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare class Colorino {
|
|
68
|
-
private readonly _palette;
|
|
69
|
-
private readonly _validator;
|
|
70
|
-
private readonly _browserColorSupportDetector?;
|
|
71
|
-
private readonly _nodeColorSupportDetector?;
|
|
72
|
-
private readonly _options;
|
|
73
|
-
private _alreadyWarned;
|
|
74
|
-
private readonly _colorLevel;
|
|
75
|
-
private readonly isBrowser;
|
|
76
|
-
constructor(_palette: Palette, _validator: InputValidator, _browserColorSupportDetector?: BrowserColorSupportDetector | undefined, _nodeColorSupportDetector?: NodeColorSupportDetector | undefined, _options?: ColorinoOptions);
|
|
77
|
-
log(...args: unknown[]): void;
|
|
78
|
-
info(...args: unknown[]): void;
|
|
79
|
-
warn(...args: unknown[]): void;
|
|
80
|
-
error(...args: unknown[]): void;
|
|
81
|
-
trace(...args: unknown[]): void;
|
|
82
|
-
debug(...args: unknown[]): void;
|
|
83
|
-
private _detectColorSupport;
|
|
84
|
-
private _maybeWarnUser;
|
|
85
|
-
private _out;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { Colorino as a };
|
|
89
|
-
export type { ColorinoOptions as C, LogLevel as L, Palette as P, TerminalTheme as T };
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Result } from 'neverthrow';
|
|
2
|
-
|
|
3
|
-
type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
4
|
-
type LogLevel = ConsoleMethod & string;
|
|
5
|
-
type Palette = Record<LogLevel, string>;
|
|
6
|
-
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
7
|
-
interface ColorinoOptions {
|
|
8
|
-
disableWarnings?: boolean;
|
|
9
|
-
theme?: TerminalTheme;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
declare enum ColorLevel {
|
|
13
|
-
NO_COLOR = 0,
|
|
14
|
-
ANSI = 1,
|
|
15
|
-
ANSI256 = 2,
|
|
16
|
-
TRUECOLOR = 3
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ColorSupportDetectorInterface {
|
|
20
|
-
getColorLevel(): ColorLevel;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
declare class NodeColorSupportDetector implements ColorSupportDetectorInterface {
|
|
24
|
-
private readonly _process?;
|
|
25
|
-
private readonly _envForceColor?;
|
|
26
|
-
private readonly _envTerm?;
|
|
27
|
-
private readonly _envColorTerm?;
|
|
28
|
-
private readonly _envNoColor?;
|
|
29
|
-
private readonly _envCliColor?;
|
|
30
|
-
private readonly _envCliColorForce?;
|
|
31
|
-
private readonly _envWtSession?;
|
|
32
|
-
private readonly _isTTY?;
|
|
33
|
-
private readonly _querier?;
|
|
34
|
-
private readonly _overrideTheme?;
|
|
35
|
-
constructor(_process?: NodeJS.Process | undefined, overrideTheme?: TerminalTheme);
|
|
36
|
-
isNodeEnv(): boolean;
|
|
37
|
-
getColorLevel(): ColorLevel;
|
|
38
|
-
getTheme(): Promise<TerminalTheme>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
declare class BrowserColorSupportDetector implements ColorSupportDetectorInterface {
|
|
42
|
-
private readonly _window;
|
|
43
|
-
private readonly _navigator;
|
|
44
|
-
private readonly _overrideTheme?;
|
|
45
|
-
constructor(_window: {
|
|
46
|
-
document: HTMLDocument;
|
|
47
|
-
matchMedia(arg0: string): {
|
|
48
|
-
matches: unknown;
|
|
49
|
-
};
|
|
50
|
-
} | undefined, _navigator: {
|
|
51
|
-
userAgent: string;
|
|
52
|
-
} | undefined, _overrideTheme?: TerminalTheme | undefined);
|
|
53
|
-
isBrowserEnv(): boolean;
|
|
54
|
-
getColorLevel(): ColorLevel;
|
|
55
|
-
getTheme(): TerminalTheme;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
declare class ColorinoError extends Error {
|
|
59
|
-
constructor(message: string);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
declare class InputValidator {
|
|
63
|
-
validateHex(hex: string): Result<boolean, ColorinoError>;
|
|
64
|
-
validatePalette(palette: Palette): Result<boolean, ColorinoError>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare class Colorino {
|
|
68
|
-
private readonly _palette;
|
|
69
|
-
private readonly _validator;
|
|
70
|
-
private readonly _browserColorSupportDetector?;
|
|
71
|
-
private readonly _nodeColorSupportDetector?;
|
|
72
|
-
private readonly _options;
|
|
73
|
-
private _alreadyWarned;
|
|
74
|
-
private readonly _colorLevel;
|
|
75
|
-
private readonly isBrowser;
|
|
76
|
-
constructor(_palette: Palette, _validator: InputValidator, _browserColorSupportDetector?: BrowserColorSupportDetector | undefined, _nodeColorSupportDetector?: NodeColorSupportDetector | undefined, _options?: ColorinoOptions);
|
|
77
|
-
log(...args: unknown[]): void;
|
|
78
|
-
info(...args: unknown[]): void;
|
|
79
|
-
warn(...args: unknown[]): void;
|
|
80
|
-
error(...args: unknown[]): void;
|
|
81
|
-
trace(...args: unknown[]): void;
|
|
82
|
-
debug(...args: unknown[]): void;
|
|
83
|
-
private _detectColorSupport;
|
|
84
|
-
private _maybeWarnUser;
|
|
85
|
-
private _out;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { Colorino as a };
|
|
89
|
-
export type { ColorinoOptions as C, LogLevel as L, Palette as P, TerminalTheme as T };
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Result } from 'neverthrow';
|
|
2
|
-
|
|
3
|
-
type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
4
|
-
type LogLevel = ConsoleMethod & string;
|
|
5
|
-
type Palette = Record<LogLevel, string>;
|
|
6
|
-
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
7
|
-
interface ColorinoOptions {
|
|
8
|
-
disableWarnings?: boolean;
|
|
9
|
-
theme?: TerminalTheme;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
declare enum ColorLevel {
|
|
13
|
-
NO_COLOR = 0,
|
|
14
|
-
ANSI = 1,
|
|
15
|
-
ANSI256 = 2,
|
|
16
|
-
TRUECOLOR = 3
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ColorSupportDetectorInterface {
|
|
20
|
-
getColorLevel(): ColorLevel;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
declare class NodeColorSupportDetector implements ColorSupportDetectorInterface {
|
|
24
|
-
private readonly _process?;
|
|
25
|
-
private readonly _envForceColor?;
|
|
26
|
-
private readonly _envTerm?;
|
|
27
|
-
private readonly _envColorTerm?;
|
|
28
|
-
private readonly _envNoColor?;
|
|
29
|
-
private readonly _envCliColor?;
|
|
30
|
-
private readonly _envCliColorForce?;
|
|
31
|
-
private readonly _envWtSession?;
|
|
32
|
-
private readonly _isTTY?;
|
|
33
|
-
private readonly _querier?;
|
|
34
|
-
private readonly _overrideTheme?;
|
|
35
|
-
constructor(_process?: NodeJS.Process | undefined, overrideTheme?: TerminalTheme);
|
|
36
|
-
isNodeEnv(): boolean;
|
|
37
|
-
getColorLevel(): ColorLevel;
|
|
38
|
-
getTheme(): Promise<TerminalTheme>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
declare class BrowserColorSupportDetector implements ColorSupportDetectorInterface {
|
|
42
|
-
private readonly _window;
|
|
43
|
-
private readonly _navigator;
|
|
44
|
-
private readonly _overrideTheme?;
|
|
45
|
-
constructor(_window: {
|
|
46
|
-
document: HTMLDocument;
|
|
47
|
-
matchMedia(arg0: string): {
|
|
48
|
-
matches: unknown;
|
|
49
|
-
};
|
|
50
|
-
} | undefined, _navigator: {
|
|
51
|
-
userAgent: string;
|
|
52
|
-
} | undefined, _overrideTheme?: TerminalTheme | undefined);
|
|
53
|
-
isBrowserEnv(): boolean;
|
|
54
|
-
getColorLevel(): ColorLevel;
|
|
55
|
-
getTheme(): TerminalTheme;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
declare class ColorinoError extends Error {
|
|
59
|
-
constructor(message: string);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
declare class InputValidator {
|
|
63
|
-
validateHex(hex: string): Result<boolean, ColorinoError>;
|
|
64
|
-
validatePalette(palette: Palette): Result<boolean, ColorinoError>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare class Colorino {
|
|
68
|
-
private readonly _palette;
|
|
69
|
-
private readonly _validator;
|
|
70
|
-
private readonly _browserColorSupportDetector?;
|
|
71
|
-
private readonly _nodeColorSupportDetector?;
|
|
72
|
-
private readonly _options;
|
|
73
|
-
private _alreadyWarned;
|
|
74
|
-
private readonly _colorLevel;
|
|
75
|
-
private readonly isBrowser;
|
|
76
|
-
constructor(_palette: Palette, _validator: InputValidator, _browserColorSupportDetector?: BrowserColorSupportDetector | undefined, _nodeColorSupportDetector?: NodeColorSupportDetector | undefined, _options?: ColorinoOptions);
|
|
77
|
-
log(...args: unknown[]): void;
|
|
78
|
-
info(...args: unknown[]): void;
|
|
79
|
-
warn(...args: unknown[]): void;
|
|
80
|
-
error(...args: unknown[]): void;
|
|
81
|
-
trace(...args: unknown[]): void;
|
|
82
|
-
debug(...args: unknown[]): void;
|
|
83
|
-
private _detectColorSupport;
|
|
84
|
-
private _maybeWarnUser;
|
|
85
|
-
private _out;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { Colorino as a };
|
|
89
|
-
export type { ColorinoOptions as C, LogLevel as L, Palette as P, TerminalTheme as T };
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const neverthrow = require('neverthrow');
|
|
4
|
-
|
|
5
|
-
function hexToRgb(hex) {
|
|
6
|
-
const match = hex.toString().match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
7
|
-
if (!match) {
|
|
8
|
-
return [0, 0, 0];
|
|
9
|
-
}
|
|
10
|
-
let colorString = match[0];
|
|
11
|
-
if (match[0].length === 3) {
|
|
12
|
-
colorString = [...colorString].map((char) => char + char).join("");
|
|
13
|
-
}
|
|
14
|
-
const integer = parseInt(colorString, 16);
|
|
15
|
-
const r = integer >> 16 & 255;
|
|
16
|
-
const g = integer >> 8 & 255;
|
|
17
|
-
const b = integer & 255;
|
|
18
|
-
return [r, g, b];
|
|
19
|
-
}
|
|
20
|
-
function rgbToAnsi256(rgb) {
|
|
21
|
-
const [r, g, b] = rgb;
|
|
22
|
-
if (r === g && g === b) {
|
|
23
|
-
if (r < 8) return 16;
|
|
24
|
-
if (r > 248) return 231;
|
|
25
|
-
return Math.round((r - 8) / 247 * 24) + 232;
|
|
26
|
-
}
|
|
27
|
-
return 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
|
28
|
-
}
|
|
29
|
-
function rgbToHsvValue(rgb) {
|
|
30
|
-
const r = rgb[0] / 255;
|
|
31
|
-
const g = rgb[1] / 255;
|
|
32
|
-
const b = rgb[2] / 255;
|
|
33
|
-
const v = Math.max(r, g, b);
|
|
34
|
-
return v * 100;
|
|
35
|
-
}
|
|
36
|
-
function rgbToAnsi16(rgb) {
|
|
37
|
-
const [r, g, b] = rgb;
|
|
38
|
-
const value = rgbToHsvValue(rgb);
|
|
39
|
-
const roundedValue = Math.round(value / 50);
|
|
40
|
-
if (roundedValue === 0) {
|
|
41
|
-
return 30;
|
|
42
|
-
}
|
|
43
|
-
let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
|
44
|
-
if (roundedValue === 2) {
|
|
45
|
-
ansi += 60;
|
|
46
|
-
}
|
|
47
|
-
return ansi;
|
|
48
|
-
}
|
|
49
|
-
const colorConverter = {
|
|
50
|
-
hex: {
|
|
51
|
-
toRgb: hexToRgb,
|
|
52
|
-
toAnsi16: (hex) => rgbToAnsi16(hexToRgb(hex)),
|
|
53
|
-
toAnsi256: (hex) => rgbToAnsi256(hexToRgb(hex))
|
|
54
|
-
}};
|
|
55
|
-
|
|
56
|
-
var ColorLevel = /* @__PURE__ */ ((ColorLevel2) => {
|
|
57
|
-
ColorLevel2[ColorLevel2["NO_COLOR"] = 0] = "NO_COLOR";
|
|
58
|
-
ColorLevel2[ColorLevel2["ANSI"] = 1] = "ANSI";
|
|
59
|
-
ColorLevel2[ColorLevel2["ANSI256"] = 2] = "ANSI256";
|
|
60
|
-
ColorLevel2[ColorLevel2["TRUECOLOR"] = 3] = "TRUECOLOR";
|
|
61
|
-
return ColorLevel2;
|
|
62
|
-
})(ColorLevel || {});
|
|
63
|
-
|
|
64
|
-
function isConsoleMethod(level) {
|
|
65
|
-
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
class Colorino {
|
|
69
|
-
constructor(_palette, _validator, _browserColorSupportDetector, _nodeColorSupportDetector, _options = {}) {
|
|
70
|
-
this._palette = _palette;
|
|
71
|
-
this._validator = _validator;
|
|
72
|
-
this._browserColorSupportDetector = _browserColorSupportDetector;
|
|
73
|
-
this._nodeColorSupportDetector = _nodeColorSupportDetector;
|
|
74
|
-
this._options = _options;
|
|
75
|
-
this.isBrowser = !!this._browserColorSupportDetector;
|
|
76
|
-
this._colorLevel = this._detectColorSupport();
|
|
77
|
-
const validatePaletteResult = this._validator.validatePalette(this._palette);
|
|
78
|
-
if (validatePaletteResult.isErr()) throw validatePaletteResult.error;
|
|
79
|
-
if (!this.isBrowser && (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") && !this._options.disableWarnings) {
|
|
80
|
-
this._maybeWarnUser();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
_alreadyWarned = false;
|
|
84
|
-
_colorLevel;
|
|
85
|
-
isBrowser;
|
|
86
|
-
log(...args) {
|
|
87
|
-
this._out("log", args);
|
|
88
|
-
}
|
|
89
|
-
info(...args) {
|
|
90
|
-
this._out("info", args);
|
|
91
|
-
}
|
|
92
|
-
warn(...args) {
|
|
93
|
-
this._out("warn", args);
|
|
94
|
-
}
|
|
95
|
-
error(...args) {
|
|
96
|
-
this._out("error", args);
|
|
97
|
-
}
|
|
98
|
-
trace(...args) {
|
|
99
|
-
this._out("trace", args);
|
|
100
|
-
}
|
|
101
|
-
debug(...args) {
|
|
102
|
-
this._out("debug", args);
|
|
103
|
-
}
|
|
104
|
-
_detectColorSupport() {
|
|
105
|
-
if (this.isBrowser) {
|
|
106
|
-
return this._browserColorSupportDetector?.getColorLevel() ?? "UnknownEnv";
|
|
107
|
-
}
|
|
108
|
-
if (this._nodeColorSupportDetector?.isNodeEnv()) {
|
|
109
|
-
return this._nodeColorSupportDetector?.getColorLevel() ?? "UnknownEnv";
|
|
110
|
-
}
|
|
111
|
-
return "UnknownEnv";
|
|
112
|
-
}
|
|
113
|
-
_maybeWarnUser() {
|
|
114
|
-
if (this._alreadyWarned) return;
|
|
115
|
-
this._alreadyWarned = true;
|
|
116
|
-
console.warn(
|
|
117
|
-
"[Colorino] 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."
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
_out(level, args) {
|
|
121
|
-
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
122
|
-
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
123
|
-
if (level === "trace") console.trace(...args);
|
|
124
|
-
else console[consoleMethod](...args);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (this.isBrowser) {
|
|
128
|
-
const hex2 = this._palette[level];
|
|
129
|
-
if (typeof args[0] === "string") {
|
|
130
|
-
console[consoleMethod](`%c${args[0]}`, `color:${hex2}`, ...args.slice(1));
|
|
131
|
-
} else {
|
|
132
|
-
console[consoleMethod](...args);
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const hex = this._palette[level];
|
|
137
|
-
let ansiCode;
|
|
138
|
-
switch (this._colorLevel) {
|
|
139
|
-
case ColorLevel.TRUECOLOR: {
|
|
140
|
-
const [r, g, b] = colorConverter.hex.toRgb(hex);
|
|
141
|
-
ansiCode = `\x1B[38;2;${r};${g};${b}m`;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case ColorLevel.ANSI256: {
|
|
145
|
-
const code = colorConverter.hex.toAnsi256(hex);
|
|
146
|
-
ansiCode = `\x1B[38;5;${code}m`;
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
case ColorLevel.ANSI:
|
|
150
|
-
default: {
|
|
151
|
-
const code = colorConverter.hex.toAnsi16(hex);
|
|
152
|
-
ansiCode = `\x1B[${code}m`;
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const processedArgs = [...args];
|
|
157
|
-
const firstStringIndex = processedArgs.findIndex(
|
|
158
|
-
(arg) => typeof arg === "string"
|
|
159
|
-
);
|
|
160
|
-
if (firstStringIndex !== -1) {
|
|
161
|
-
processedArgs[firstStringIndex] = `${ansiCode}${processedArgs[firstStringIndex]}\x1B[0m`;
|
|
162
|
-
}
|
|
163
|
-
if (level === "trace") {
|
|
164
|
-
console.trace(...processedArgs);
|
|
165
|
-
} else {
|
|
166
|
-
console[consoleMethod](...processedArgs);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
class ColorinoError extends Error {
|
|
172
|
-
constructor(message) {
|
|
173
|
-
super(message);
|
|
174
|
-
this.name = "ColorinoError";
|
|
175
|
-
Object.setPrototypeOf(this, ColorinoError.prototype);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
class OscQueryError extends Error {
|
|
179
|
-
constructor(message) {
|
|
180
|
-
super(message);
|
|
181
|
-
this.name = "OscQueryError";
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
class InputValidator {
|
|
186
|
-
validateHex(hex) {
|
|
187
|
-
const trimmedHex = hex.trim();
|
|
188
|
-
const isHexValid = /^#[0-9A-F]{6}$/i.test(trimmedHex);
|
|
189
|
-
if (!isHexValid) {
|
|
190
|
-
return neverthrow.err(new ColorinoError(`Invalid hex color: '${hex}'`));
|
|
191
|
-
}
|
|
192
|
-
return neverthrow.ok(true);
|
|
193
|
-
}
|
|
194
|
-
validatePalette(palette) {
|
|
195
|
-
for (const level in palette) {
|
|
196
|
-
const hex = palette[level];
|
|
197
|
-
const result = this.validateHex(hex);
|
|
198
|
-
if (result.isErr()) {
|
|
199
|
-
return neverthrow.err(result.error);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return neverthrow.ok(true);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const darkDraculaPalette = {
|
|
207
|
-
log: "#f8f8f2",
|
|
208
|
-
debug: "#f1fa8c",
|
|
209
|
-
error: "#ff5555",
|
|
210
|
-
info: " #8be9fd",
|
|
211
|
-
trace: "#bd93f9",
|
|
212
|
-
warn: "#ffb86c"
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
exports.ColorLevel = ColorLevel;
|
|
216
|
-
exports.Colorino = Colorino;
|
|
217
|
-
exports.InputValidator = InputValidator;
|
|
218
|
-
exports.OscQueryError = OscQueryError;
|
|
219
|
-
exports.darkDraculaPalette = darkDraculaPalette;
|