colorino 0.15.4 → 0.16.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 +21 -12
- package/dist/browser.d.mts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.mjs +23 -26
- package/dist/cdn.js +23 -26
- package/dist/cdn.js.map +1 -1
- package/dist/cdn.min.js +1 -1
- package/dist/cdn.min.js.map +1 -1
- package/dist/cdn.min.mjs +1 -1
- package/dist/cdn.mjs +23 -26
- package/dist/cdn.mjs.map +1 -1
- package/dist/node.cjs +58 -40
- package/dist/node.d.cts +1 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.mjs +58 -40
- package/dist/osc-child-probe.js +66 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
Colorino automatically adapts its palette to your terminal or browser DevTools theme, and degrades colors gracefully so your logs stay readable and on‑brand even in limited environments
|
|
6
6
|
|
|
7
7
|

|
|
8
|
+

|
|
8
9
|
|
|
9
10
|
# <a id="0"></a><a id="0"></a>
|
|
10
11
|
|
|
@@ -137,14 +138,11 @@ Use the factory to create as many loggers as you want (each with its own palette
|
|
|
137
138
|
```typescript
|
|
138
139
|
import { createColorino } from 'colorino'
|
|
139
140
|
|
|
140
|
-
const myLogger = createColorino(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
},
|
|
146
|
-
{ disableWarnings: true } // Options (see below)
|
|
147
|
-
)
|
|
141
|
+
const myLogger = createColorino({
|
|
142
|
+
// Palette (partial)
|
|
143
|
+
error: '#ff007b',
|
|
144
|
+
info: '#3498db',
|
|
145
|
+
})
|
|
148
146
|
myLogger.error('Critical!')
|
|
149
147
|
myLogger.info('Rebranded info!')
|
|
150
148
|
```
|
|
@@ -155,7 +153,6 @@ myLogger.info('Rebranded info!')
|
|
|
155
153
|
|
|
156
154
|
| Option | Type | Default | Description |
|
|
157
155
|
| ----------------- | ------------------------- | -------- | -------------------------------------------------------------------------- |
|
|
158
|
-
| `disableWarnings` | `boolean` | `false` | Suppress warnings when color support can't be detected or is disabled. |
|
|
159
156
|
| `theme` | `ThemeOption` (see below) | `'auto'` | Control the active color theme or force a specific mode. |
|
|
160
157
|
| `disableOscProbe` | `boolean` | `false` | Disable OSC 11 terminal theme probing (use only env heuristics for theme). |
|
|
161
158
|
| `maxDepth` | `number` | `5` | Maximum depth when pretty-printing objects in log output. |
|
|
@@ -269,7 +266,7 @@ Colorino auto-detects your environment and color support, but you can override b
|
|
|
269
266
|
| `WT_SESSION` | Enables color detection for Windows Terminal | |
|
|
270
267
|
| `CI` | Many CI platforms default to no color | `CI=1 node app.js` |
|
|
271
268
|
|
|
272
|
-
### <a id="5-6"></a>Colorize Helper (Manual Overrides)
|
|
269
|
+
### <a id="5-6"></a>Colorize Helper (Manual Overrides) (`colorize(text, hex)`)
|
|
273
270
|
|
|
274
271
|
Sometimes you want full control over a single piece of text without changing your global palette, e.g. when you use a mostly neutral theme but still want to highlight a keyword.
|
|
275
272
|
|
|
@@ -284,7 +281,7 @@ colorino.info(important, 'Something happened')
|
|
|
284
281
|
|
|
285
282
|
When color is disabled (for example via `NO_COLOR=1` or lack of support), `colorize` returns the plain input string, so your logs stay readable.
|
|
286
283
|
|
|
287
|
-
### <a id="5-7"></a>Browser‑only CSS Helper (`css()`)
|
|
284
|
+
### <a id="5-7"></a>Browser‑only CSS Helper (`css(text, style)`)
|
|
288
285
|
|
|
289
286
|
In the browser, Colorino also exposes a `css(text, style)` helper that lets you apply arbitrary CSS to a single segment in DevTools using the `%c` formatter.
|
|
290
287
|
|
|
@@ -303,6 +300,19 @@ const badge = colorino.css('NEW', {
|
|
|
303
300
|
colorino.info('Release status:', badge, 'shipped')
|
|
304
301
|
```
|
|
305
302
|
|
|
303
|
+
### <a id="5-7"></a>Gradient Text (`gradient(text, startHex, endHex)`)
|
|
304
|
+
|
|
305
|
+
Create smooth color transitions across text with the `gradient(text, startHex, endHex)` method, available on all logger instances. Like the css and colorize helper.
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
import { colorino } from 'colorino'
|
|
309
|
+
|
|
310
|
+
const rainbow = colorino.gradient('Hello Gradient!', '#ff0000', '#0000ff')
|
|
311
|
+
colorino.log(rainbow)
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Requires ANSI-256 or Truecolor support (most modern terminals). Degrades gracefully to palette colors on older terminals.
|
|
315
|
+
|
|
306
316
|
## <a id="6"></a>Colorino vs. Chalk
|
|
307
317
|
|
|
308
318
|
| Feature | 🎨 **Colorino** | 🖍️ **Chalk** |
|
|
@@ -334,7 +344,6 @@ A factory function to create your own customized logger instances.
|
|
|
334
344
|
|
|
335
345
|
- `palette` (`Partial<Palette>`): An object to override default colors for specific log levels (e.g., `{ error: '#ff007b' }`).
|
|
336
346
|
- `options` (`ColorinoOptions`): An object to control behavior:
|
|
337
|
-
- `disableWarnings: boolean` (default `false`): Suppress warnings on environments with no color support.
|
|
338
347
|
- `theme: 'dark' | 'light'` (default `auto`): Force a specific theme instead of auto-detecting.
|
|
339
348
|
|
|
340
349
|
## <a id="8"></a>Extending Colorino
|
package/dist/browser.d.mts
CHANGED
|
@@ -14,7 +14,6 @@ interface BrowserCssArg {
|
|
|
14
14
|
declare const themePalettes: Record<ThemeName, Palette>;
|
|
15
15
|
|
|
16
16
|
interface ColorinoOptions {
|
|
17
|
-
disableWarnings?: boolean;
|
|
18
17
|
theme?: TerminalTheme | ThemeName | 'auto';
|
|
19
18
|
disableOscProbe?: boolean;
|
|
20
19
|
maxDepth?: number;
|
|
@@ -27,6 +26,7 @@ interface Colorino {
|
|
|
27
26
|
debug(...args: unknown[]): void;
|
|
28
27
|
trace(...args: unknown[]): void;
|
|
29
28
|
colorize(text: string, hex: string): void;
|
|
29
|
+
gradient(text: string, startHex: string, endHex: string): void;
|
|
30
30
|
}
|
|
31
31
|
interface ColorinoBrowserInterface extends Colorino {
|
|
32
32
|
css(text: string, style: CssConsoleStyle): string | BrowserCssArg;
|
package/dist/browser.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ interface BrowserCssArg {
|
|
|
14
14
|
declare const themePalettes: Record<ThemeName, Palette>;
|
|
15
15
|
|
|
16
16
|
interface ColorinoOptions {
|
|
17
|
-
disableWarnings?: boolean;
|
|
18
17
|
theme?: TerminalTheme | ThemeName | 'auto';
|
|
19
18
|
disableOscProbe?: boolean;
|
|
20
19
|
maxDepth?: number;
|
|
@@ -27,6 +26,7 @@ interface Colorino {
|
|
|
27
26
|
debug(...args: unknown[]): void;
|
|
28
27
|
trace(...args: unknown[]): void;
|
|
29
28
|
colorize(text: string, hex: string): void;
|
|
29
|
+
gradient(text: string, startHex: string, endHex: string): void;
|
|
30
30
|
}
|
|
31
31
|
interface ColorinoBrowserInterface extends Colorino {
|
|
32
32
|
css(text: string, style: CssConsoleStyle): string | BrowserCssArg;
|
package/dist/browser.mjs
CHANGED
|
@@ -97,21 +97,9 @@ class AbstractColorino {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
const ansiPrefix = this._toAnsiPrefix(hex);
|
|
100
|
-
if (!ansiPrefix)
|
|
101
|
-
return text;
|
|
102
|
-
}
|
|
100
|
+
if (!ansiPrefix) return text;
|
|
103
101
|
return `${ansiPrefix}${text}\x1B[0m`;
|
|
104
102
|
}
|
|
105
|
-
_out(level, args) {
|
|
106
|
-
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
107
|
-
const processedArgs = this._processArgs(args);
|
|
108
|
-
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
109
|
-
this._output(consoleMethod, processedArgs);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const coloredArgs = this._applyColors(consoleMethod, processedArgs);
|
|
113
|
-
this._output(consoleMethod, coloredArgs);
|
|
114
|
-
}
|
|
115
103
|
_toAnsiPrefix(_hex) {
|
|
116
104
|
return "";
|
|
117
105
|
}
|
|
@@ -163,12 +151,33 @@ ${cleanStack}`);
|
|
|
163
151
|
console.log(...args);
|
|
164
152
|
}
|
|
165
153
|
}
|
|
154
|
+
_out(level, args) {
|
|
155
|
+
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
156
|
+
const processedArgs = this._processArgs(args);
|
|
157
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
158
|
+
this._output(consoleMethod, processedArgs);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const coloredArgs = this._applyColors(consoleMethod, processedArgs);
|
|
162
|
+
this._output(consoleMethod, coloredArgs);
|
|
163
|
+
}
|
|
166
164
|
}
|
|
167
165
|
|
|
168
166
|
class ColorinoBrowser extends AbstractColorino {
|
|
169
167
|
constructor(initialPalette, userPalette, validator, colorLevel, options = {}) {
|
|
170
168
|
super(initialPalette, userPalette, validator, colorLevel, options);
|
|
171
169
|
}
|
|
170
|
+
gradient(text, startHex, endHex) {
|
|
171
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
172
|
+
return text;
|
|
173
|
+
}
|
|
174
|
+
const css = `background: linear-gradient(to right, ${startHex}, ${endHex}); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;`;
|
|
175
|
+
return {
|
|
176
|
+
[ColorinoBrowserCss]: true,
|
|
177
|
+
text,
|
|
178
|
+
css
|
|
179
|
+
};
|
|
180
|
+
}
|
|
172
181
|
css(text, style) {
|
|
173
182
|
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
174
183
|
return text;
|
|
@@ -261,13 +270,11 @@ ${arg}` : arg
|
|
|
261
270
|
}
|
|
262
271
|
|
|
263
272
|
class BrowserColorSupportDetector {
|
|
264
|
-
constructor(
|
|
265
|
-
this._areWarningsDisabled = _areWarningsDisabled;
|
|
273
|
+
constructor(_window, _navigator, _overrideTheme) {
|
|
266
274
|
this._window = _window;
|
|
267
275
|
this._navigator = _navigator;
|
|
268
276
|
this._overrideTheme = _overrideTheme;
|
|
269
277
|
}
|
|
270
|
-
_alreadyWarned;
|
|
271
278
|
isBrowserEnv() {
|
|
272
279
|
return !!this._window && !!this._navigator?.userAgent;
|
|
273
280
|
}
|
|
@@ -279,7 +286,6 @@ class BrowserColorSupportDetector {
|
|
|
279
286
|
return this._overrideTheme;
|
|
280
287
|
}
|
|
281
288
|
if (typeof this._window.matchMedia !== "function") {
|
|
282
|
-
this._maybeWarnUser();
|
|
283
289
|
return "unknown";
|
|
284
290
|
}
|
|
285
291
|
const isDarkTheme = this._window.matchMedia(
|
|
@@ -290,16 +296,8 @@ class BrowserColorSupportDetector {
|
|
|
290
296
|
if (this._window.matchMedia(isLightTheme).matches) {
|
|
291
297
|
return "light";
|
|
292
298
|
}
|
|
293
|
-
this._maybeWarnUser();
|
|
294
299
|
return "unknown";
|
|
295
300
|
}
|
|
296
|
-
_maybeWarnUser() {
|
|
297
|
-
if (this._alreadyWarned || this._areWarningsDisabled) return;
|
|
298
|
-
this._alreadyWarned = true;
|
|
299
|
-
console.warn(
|
|
300
|
-
"Consider switching the browser. You browser doesn't have a window.matchMedia() Web API."
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
301
|
}
|
|
304
302
|
|
|
305
303
|
class InputValidationError extends Error {
|
|
@@ -421,7 +419,6 @@ function createColorino(userPalette = {}, options = {}) {
|
|
|
421
419
|
detectorThemeOverride = options.theme;
|
|
422
420
|
}
|
|
423
421
|
const browserDetector = new BrowserColorSupportDetector(
|
|
424
|
-
!!options.disableWarnings,
|
|
425
422
|
window,
|
|
426
423
|
navigator,
|
|
427
424
|
detectorThemeOverride
|
package/dist/cdn.js
CHANGED
|
@@ -101,21 +101,9 @@
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
const ansiPrefix = this._toAnsiPrefix(hex);
|
|
104
|
-
if (!ansiPrefix)
|
|
105
|
-
return text;
|
|
106
|
-
}
|
|
104
|
+
if (!ansiPrefix) return text;
|
|
107
105
|
return `${ansiPrefix}${text}\x1B[0m`;
|
|
108
106
|
}
|
|
109
|
-
_out(level, args) {
|
|
110
|
-
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
111
|
-
const processedArgs = this._processArgs(args);
|
|
112
|
-
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
113
|
-
this._output(consoleMethod, processedArgs);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const coloredArgs = this._applyColors(consoleMethod, processedArgs);
|
|
117
|
-
this._output(consoleMethod, coloredArgs);
|
|
118
|
-
}
|
|
119
107
|
_toAnsiPrefix(_hex) {
|
|
120
108
|
return "";
|
|
121
109
|
}
|
|
@@ -167,12 +155,33 @@ ${cleanStack}`);
|
|
|
167
155
|
console.log(...args);
|
|
168
156
|
}
|
|
169
157
|
}
|
|
158
|
+
_out(level, args) {
|
|
159
|
+
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
160
|
+
const processedArgs = this._processArgs(args);
|
|
161
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
162
|
+
this._output(consoleMethod, processedArgs);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const coloredArgs = this._applyColors(consoleMethod, processedArgs);
|
|
166
|
+
this._output(consoleMethod, coloredArgs);
|
|
167
|
+
}
|
|
170
168
|
}
|
|
171
169
|
|
|
172
170
|
class ColorinoBrowser extends AbstractColorino {
|
|
173
171
|
constructor(initialPalette, userPalette, validator, colorLevel, options = {}) {
|
|
174
172
|
super(initialPalette, userPalette, validator, colorLevel, options);
|
|
175
173
|
}
|
|
174
|
+
gradient(text, startHex, endHex) {
|
|
175
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
176
|
+
return text;
|
|
177
|
+
}
|
|
178
|
+
const css = `background: linear-gradient(to right, ${startHex}, ${endHex}); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;`;
|
|
179
|
+
return {
|
|
180
|
+
[ColorinoBrowserCss]: true,
|
|
181
|
+
text,
|
|
182
|
+
css
|
|
183
|
+
};
|
|
184
|
+
}
|
|
176
185
|
css(text, style) {
|
|
177
186
|
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
178
187
|
return text;
|
|
@@ -265,13 +274,11 @@ ${arg}` : arg
|
|
|
265
274
|
}
|
|
266
275
|
|
|
267
276
|
class BrowserColorSupportDetector {
|
|
268
|
-
constructor(
|
|
269
|
-
this._areWarningsDisabled = _areWarningsDisabled;
|
|
277
|
+
constructor(_window, _navigator, _overrideTheme) {
|
|
270
278
|
this._window = _window;
|
|
271
279
|
this._navigator = _navigator;
|
|
272
280
|
this._overrideTheme = _overrideTheme;
|
|
273
281
|
}
|
|
274
|
-
_alreadyWarned;
|
|
275
282
|
isBrowserEnv() {
|
|
276
283
|
return !!this._window && !!this._navigator?.userAgent;
|
|
277
284
|
}
|
|
@@ -283,7 +290,6 @@ ${arg}` : arg
|
|
|
283
290
|
return this._overrideTheme;
|
|
284
291
|
}
|
|
285
292
|
if (typeof this._window.matchMedia !== "function") {
|
|
286
|
-
this._maybeWarnUser();
|
|
287
293
|
return "unknown";
|
|
288
294
|
}
|
|
289
295
|
const isDarkTheme = this._window.matchMedia(
|
|
@@ -294,16 +300,8 @@ ${arg}` : arg
|
|
|
294
300
|
if (this._window.matchMedia(isLightTheme).matches) {
|
|
295
301
|
return "light";
|
|
296
302
|
}
|
|
297
|
-
this._maybeWarnUser();
|
|
298
303
|
return "unknown";
|
|
299
304
|
}
|
|
300
|
-
_maybeWarnUser() {
|
|
301
|
-
if (this._alreadyWarned || this._areWarningsDisabled) return;
|
|
302
|
-
this._alreadyWarned = true;
|
|
303
|
-
console.warn(
|
|
304
|
-
"Consider switching the browser. You browser doesn't have a window.matchMedia() Web API."
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
305
|
}
|
|
308
306
|
|
|
309
307
|
const defaultErrorConfig = {
|
|
@@ -907,7 +905,6 @@ ${arg}` : arg
|
|
|
907
905
|
detectorThemeOverride = options.theme;
|
|
908
906
|
}
|
|
909
907
|
const browserDetector = new BrowserColorSupportDetector(
|
|
910
|
-
!!options.disableWarnings,
|
|
911
908
|
window,
|
|
912
909
|
navigator,
|
|
913
910
|
detectorThemeOverride
|