colorino 0.1.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/dist/node.mjs ADDED
@@ -0,0 +1,191 @@
1
+ import { O as OscQueryError, C as ColorLevel, a as Colorino, I as InputValidator, d as darkDraculaPalette } from './shared/colorino.xxLMfJFV.mjs';
2
+ import { err, ok } from 'neverthrow';
3
+
4
+ class OscThemeQuerier {
5
+ constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
6
+ this._stdin = _stdin;
7
+ this._stdout = _stdout;
8
+ this._timeout = _timeout;
9
+ this._cacheTtl = _cacheTtl;
10
+ }
11
+ cachedResult;
12
+ cacheTimestamp;
13
+ async query() {
14
+ if (!this._stdout.isTTY || typeof this._stdin.setRawMode !== "function") {
15
+ return err(new OscQueryError("Not a TTY environment"));
16
+ }
17
+ const now = Date.now();
18
+ if (this.cachedResult !== void 0 && this.cacheTimestamp !== void 0 && now - this.cacheTimestamp < this._cacheTtl) {
19
+ return this.cachedResult;
20
+ }
21
+ const result = await this._performQuery();
22
+ this.cachedResult = result;
23
+ this.cacheTimestamp = now;
24
+ return result;
25
+ }
26
+ async _performQuery() {
27
+ return new Promise((resolve) => {
28
+ const originalRawMode = this._stdin.isRaw;
29
+ let buffer = "";
30
+ let isResolved = false;
31
+ const cleanup = () => {
32
+ if (isResolved) return;
33
+ isResolved = true;
34
+ clearTimeout(timer);
35
+ this._stdin.removeListener("data", onData);
36
+ this._stdin.setRawMode(originalRawMode);
37
+ };
38
+ const onData = (chunk) => {
39
+ buffer += chunk.toString();
40
+ const parseResult = this._parseResponse(buffer);
41
+ if (parseResult.isOk()) {
42
+ cleanup();
43
+ resolve(parseResult);
44
+ }
45
+ };
46
+ const timer = setTimeout(() => {
47
+ cleanup();
48
+ resolve(
49
+ err(new OscQueryError("OSC query timeout - terminal did not respond"))
50
+ );
51
+ }, this._timeout);
52
+ this._stdin.setRawMode(true);
53
+ this._stdin.on("data", onData);
54
+ this._stdout.write("\x1B]11;?\x1B\\");
55
+ });
56
+ }
57
+ _parseResponse(response) {
58
+ const rgbMatch = response.match(
59
+ /rgb:([0-9a-f]{2,4})\/([0-9a-f]{2,4})\/([0-9a-f]{2,4})/i
60
+ );
61
+ if (!rgbMatch) {
62
+ return err(new OscQueryError("No valid OSC response found in buffer"));
63
+ }
64
+ const red = this._normalizeHex(rgbMatch[1]);
65
+ const green = this._normalizeHex(rgbMatch[2]);
66
+ const blue = this._normalizeHex(rgbMatch[3]);
67
+ const luminance = this._calculateLuminance(red, green, blue);
68
+ return ok(luminance < 0.5 ? "dark" : "light");
69
+ }
70
+ _normalizeHex(hexValue) {
71
+ const normalized = hexValue.padEnd(4, "0").slice(0, 2);
72
+ return parseInt(normalized, 16);
73
+ }
74
+ _calculateLuminance(red, green, blue) {
75
+ return (0.299 * red + 0.587 * green + 0.114 * blue) / 255;
76
+ }
77
+ }
78
+
79
+ class NodeColorSupportDetector {
80
+ constructor(_process, overrideTheme) {
81
+ this._process = _process;
82
+ if (!this.isNodeEnv()) return;
83
+ const processEnv = _process.env;
84
+ this._envForceColor = processEnv["FORCE_COLOR"];
85
+ this._envNoColor = processEnv["NO_COLOR"];
86
+ this._envTerm = processEnv["TERM"];
87
+ this._envColorTerm = processEnv["COLORTERM"];
88
+ this._envCliColor = processEnv["CLICOLOR"];
89
+ this._envCliColorForce = processEnv["CLICOLOR_FORCE"];
90
+ this._envWtSession = processEnv["WT_SESSION"];
91
+ this._isTTY = !!_process.stdout.isTTY;
92
+ this._overrideTheme = overrideTheme;
93
+ if (!this._overrideTheme && this._isTTY && typeof this._process.stdin.setRawMode === "function") {
94
+ this._querier = new OscThemeQuerier(
95
+ this._process.stdin,
96
+ this._process.stdout
97
+ );
98
+ }
99
+ }
100
+ _envForceColor;
101
+ _envTerm;
102
+ _envColorTerm;
103
+ _envNoColor;
104
+ _envCliColor;
105
+ _envCliColorForce;
106
+ _envWtSession;
107
+ _isTTY;
108
+ _querier;
109
+ _overrideTheme;
110
+ isNodeEnv() {
111
+ return typeof this._process !== "undefined";
112
+ }
113
+ getColorLevel() {
114
+ if (this._envNoColor !== void 0) {
115
+ return ColorLevel.NO_COLOR;
116
+ }
117
+ if (this._envForceColor !== void 0) {
118
+ if (this._envForceColor === "0" || this._envForceColor === "false") {
119
+ return ColorLevel.NO_COLOR;
120
+ }
121
+ if (this._envForceColor === "1" || this._envForceColor === "true") {
122
+ return ColorLevel.ANSI;
123
+ }
124
+ const level = parseInt(this._envForceColor, 10);
125
+ if (level >= 0 && level <= 3) {
126
+ return level;
127
+ }
128
+ return ColorLevel.ANSI;
129
+ }
130
+ const isForced = this._envCliColorForce !== void 0 && this._envCliColorForce !== "0";
131
+ if (!this._isTTY && !isForced) {
132
+ return ColorLevel.NO_COLOR;
133
+ }
134
+ if (this._envTerm === "dumb") {
135
+ return ColorLevel.NO_COLOR;
136
+ }
137
+ if (this._envColorTerm === "truecolor" || this._envColorTerm === "24bit") {
138
+ return ColorLevel.TRUECOLOR;
139
+ }
140
+ if (this._envWtSession !== void 0) {
141
+ return ColorLevel.TRUECOLOR;
142
+ }
143
+ if (this._envTerm) {
144
+ if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) || /-truecolor$/.test(this._envTerm)) {
145
+ return ColorLevel.TRUECOLOR;
146
+ }
147
+ if (/-256(color)?$/i.test(this._envTerm)) {
148
+ return ColorLevel.ANSI256;
149
+ }
150
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(
151
+ this._envTerm
152
+ )) {
153
+ return ColorLevel.ANSI;
154
+ }
155
+ }
156
+ if (this._envColorTerm) {
157
+ return ColorLevel.ANSI;
158
+ }
159
+ if (this._envCliColor !== void 0 && this._envCliColor !== "0") {
160
+ return ColorLevel.ANSI;
161
+ }
162
+ return this._isTTY ? ColorLevel.ANSI : ColorLevel.NO_COLOR;
163
+ }
164
+ async getTheme() {
165
+ if (this._overrideTheme) {
166
+ return this._overrideTheme;
167
+ }
168
+ if (!this.isNodeEnv() || !this._isTTY || !this._querier) {
169
+ return "unknown";
170
+ }
171
+ const result = await this._querier.query();
172
+ return result.unwrapOr("unknown");
173
+ }
174
+ }
175
+
176
+ function createColorino(palette, options = {}) {
177
+ const validator = new InputValidator();
178
+ const nodeDetector = new NodeColorSupportDetector(process, options.theme);
179
+ return new Colorino(
180
+ palette,
181
+ validator,
182
+ void 0,
183
+ // Browser detector is never available
184
+ nodeDetector,
185
+ // Always use node detector
186
+ options
187
+ );
188
+ }
189
+ const colorino = createColorino(darkDraculaPalette);
190
+
191
+ export { colorino, createColorino };
@@ -0,0 +1,210 @@
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._colorLevel = this._detectColorSupport();
76
+ const validatePaletteResult = this._validator.validatePalette(this._palette);
77
+ if (validatePaletteResult.isErr()) throw validatePaletteResult.error;
78
+ if ((this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") && !this._options.disableWarnings) {
79
+ this._maybeWarnUser();
80
+ }
81
+ }
82
+ _alreadyWarned = false;
83
+ _colorLevel;
84
+ color(level, text) {
85
+ const hex = this._palette[level];
86
+ let ansiCode;
87
+ switch (this._colorLevel) {
88
+ case ColorLevel.TRUECOLOR: {
89
+ const [r, g, b] = colorConverter.hex.toRgb(hex);
90
+ ansiCode = `\x1B[38;2;${r};${g};${b}m`;
91
+ break;
92
+ }
93
+ case ColorLevel.ANSI256: {
94
+ const code = colorConverter.hex.toAnsi256(hex);
95
+ ansiCode = `\x1B[38;5;${code}m`;
96
+ break;
97
+ }
98
+ case ColorLevel.ANSI: {
99
+ const code = colorConverter.hex.toAnsi16(hex);
100
+ if (code < 38) {
101
+ ansiCode = `\x1B[${code}m`;
102
+ } else {
103
+ ansiCode = `\x1B[${code}m`;
104
+ }
105
+ break;
106
+ }
107
+ case "UnknownEnv": {
108
+ return text;
109
+ }
110
+ default:
111
+ return text;
112
+ }
113
+ return `${ansiCode}${text}\x1B[0m`;
114
+ }
115
+ log(...args) {
116
+ this._out("log", args);
117
+ }
118
+ info(...args) {
119
+ this._out("info", args);
120
+ }
121
+ warn(...args) {
122
+ this._out("warn", args);
123
+ }
124
+ error(...args) {
125
+ this._out("error", args);
126
+ }
127
+ trace(...args) {
128
+ this._out("trace", args);
129
+ }
130
+ debug(...args) {
131
+ this._out("debug", args);
132
+ }
133
+ _detectColorSupport() {
134
+ const isBrowserEnv = this._browserColorSupportDetector?.isBrowserEnv();
135
+ if (isBrowserEnv) {
136
+ this._colorLevel = this._browserColorSupportDetector?.getColorLevel() ?? "UnknownEnv";
137
+ return this._colorLevel;
138
+ }
139
+ const isNodeEnv = this._nodeColorSupportDetector?.isNodeEnv();
140
+ if (isNodeEnv) {
141
+ this._colorLevel = this._nodeColorSupportDetector?.getColorLevel() ?? "UnknownEnv";
142
+ return this._colorLevel;
143
+ }
144
+ return "UnknownEnv";
145
+ }
146
+ _maybeWarnUser() {
147
+ if (this._alreadyWarned) return;
148
+ this._alreadyWarned = true;
149
+ console.warn(
150
+ "[Colorino] No ANSI color support detected in this terminal. See https://github.com/chalk/supports-color#support-matrix to learn how to enable terminal color."
151
+ );
152
+ }
153
+ _out(level, args) {
154
+ const processedArgs = args.map(
155
+ (arg) => typeof arg === "string" ? this.color(level, arg) : arg
156
+ );
157
+ if (isConsoleMethod(level)) console[level](...processedArgs);
158
+ else console.log(...processedArgs);
159
+ }
160
+ }
161
+
162
+ class ColorinoError extends Error {
163
+ constructor(message) {
164
+ super(message);
165
+ this.name = "ColorinoError";
166
+ Object.setPrototypeOf(this, ColorinoError.prototype);
167
+ }
168
+ }
169
+ class OscQueryError extends Error {
170
+ constructor(message) {
171
+ super(message);
172
+ this.name = "OscQueryError";
173
+ }
174
+ }
175
+
176
+ class InputValidator {
177
+ validateHex(hex) {
178
+ const trimmedHex = hex.trim();
179
+ const isHexValid = /^#[0-9A-F]{6}$/i.test(trimmedHex);
180
+ if (!isHexValid) {
181
+ return neverthrow.err(new ColorinoError(`Invalid hex color: '${hex}'`));
182
+ }
183
+ return neverthrow.ok(true);
184
+ }
185
+ validatePalette(palette) {
186
+ for (const level in palette) {
187
+ const hex = palette[level];
188
+ const result = this.validateHex(hex);
189
+ if (result.isErr()) {
190
+ return neverthrow.err(result.error);
191
+ }
192
+ }
193
+ return neverthrow.ok(true);
194
+ }
195
+ }
196
+
197
+ const darkDraculaPalette = {
198
+ log: "#f8f8f2",
199
+ debug: "#f1fa8c",
200
+ error: "#ff5555",
201
+ info: " #8be9fd",
202
+ trace: "#bd93f9",
203
+ warn: "#ffb86c"
204
+ };
205
+
206
+ exports.ColorLevel = ColorLevel;
207
+ exports.Colorino = Colorino;
208
+ exports.InputValidator = InputValidator;
209
+ exports.OscQueryError = OscQueryError;
210
+ exports.darkDraculaPalette = darkDraculaPalette;
@@ -0,0 +1,89 @@
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 _colorLevel;
75
+ constructor(_palette: Palette, _validator: InputValidator, _browserColorSupportDetector?: BrowserColorSupportDetector | undefined, _nodeColorSupportDetector?: NodeColorSupportDetector | undefined, _options?: ColorinoOptions);
76
+ color(level: LogLevel, text: string): string;
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, Palette as P };
@@ -0,0 +1,89 @@
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 _colorLevel;
75
+ constructor(_palette: Palette, _validator: InputValidator, _browserColorSupportDetector?: BrowserColorSupportDetector | undefined, _nodeColorSupportDetector?: NodeColorSupportDetector | undefined, _options?: ColorinoOptions);
76
+ color(level: LogLevel, text: string): string;
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, Palette as P };
@@ -0,0 +1,89 @@
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 _colorLevel;
75
+ constructor(_palette: Palette, _validator: InputValidator, _browserColorSupportDetector?: BrowserColorSupportDetector | undefined, _nodeColorSupportDetector?: NodeColorSupportDetector | undefined, _options?: ColorinoOptions);
76
+ color(level: LogLevel, text: string): string;
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, Palette as P };