colorino 0.10.0 → 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 +96 -65
- package/dist/browser.bundle.cjs +129 -118
- package/dist/browser.bundle.mjs +130 -118
- 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 +6 -6
- package/dist/node.cjs +59 -126
- 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 +42 -108
- package/dist/shared/{colorino.B23laVKA.mjs → colorino.BPD_4Zhq.mjs} +126 -121
- package/dist/shared/{colorino.Y3oJ89MM.cjs → colorino.D9xuyiJg.cjs} +126 -124
- package/dist/shared/colorino.bX_hrCT6.d.cts +21 -0
- package/dist/shared/colorino.bX_hrCT6.d.mts +21 -0
- package/dist/shared/colorino.bX_hrCT6.d.ts +21 -0
- package/package.json +2 -1
- package/dist/shared/colorino.DVUvKR4R.d.cts +0 -465
- package/dist/shared/colorino.DVUvKR4R.d.mts +0 -465
- package/dist/shared/colorino.DVUvKR4R.d.ts +0 -465
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# <a id="0"></a>🎨 Colorino
|
|
2
2
|
|
|
3
|
-
**The zero
|
|
3
|
+
**The zero‑configuration, context‑aware `console` logger for Node.js and the browser—with smart theming and graceful color degradation.**
|
|
4
4
|
|
|
5
|
-
Colorino automatically adapts its palette to your terminal or browser DevTools theme, and
|
|
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
|
# <a id="0"></a><a id="0"></a>
|
|
8
8
|
|
|
@@ -23,8 +23,10 @@ Colorino automatically adapts its palette to your terminal or browser DevTools t
|
|
|
23
23
|
- [1. `colorino` (default instance)](#7-1)
|
|
24
24
|
- [2. `createColorino(palette?, options?)` (factory)](#7-2)
|
|
25
25
|
- [Extending Colorino](#8)
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
26
|
+
- [Use case: automatic file/context info](#8-1)
|
|
27
|
+
- [Internals & Dependencies](#9)
|
|
28
|
+
- [Why This Pattern?](#9-1)
|
|
29
|
+
- [License](#10)
|
|
28
30
|
|
|
29
31
|
<!-- Table of contents is made with https://github.com/eugene-khyst/md-toc-cli -->
|
|
30
32
|
|
|
@@ -37,6 +39,7 @@ Colorino is different: it’s a "batteries-included" logging facade with beautif
|
|
|
37
39
|
## <a id="2"></a>Features
|
|
38
40
|
|
|
39
41
|
- 🎨 **Smart Theming:** Automatically detects *dark/light* mode and applies a **minimal** high-contrast base palette by default; opt into a coordinated theme preset when you want richer colors.
|
|
42
|
+
- 🤘 **Graceful Color Degradation**: Accepts rich colors (hex/RGB) and automatically down‑samples to the best ANSI‑16/ANSI‑256/Truecolor match for the current environment.
|
|
40
43
|
- 🤝 **Familiar API:** If you know `console.log`, you already know Colorino: all standard log levels are supported.
|
|
41
44
|
- 🔀 **Environment-Aware:** Works in **Node.js** (ANSI color and truecolor) and all major **Browsers** (CSS styles).
|
|
42
45
|
- ⚡️ **Fast, Lightweight:** Minimal dependencies, works great in modern frameworks and CLIs.
|
|
@@ -127,14 +130,17 @@ myLogger.info('Rebranded info!')
|
|
|
127
130
|
|
|
128
131
|
`createColorino(palette?, options?)` accepts:
|
|
129
132
|
|
|
130
|
-
| Option | Type
|
|
131
|
-
|
|
132
|
-
| `disableWarnings` | `boolean`
|
|
133
|
-
| `theme` | `ThemeOption` (see below)
|
|
133
|
+
| Option | Type | Default | Description |
|
|
134
|
+
|-------------------|--------------------------------------|---------|-----------------------------------------------------------------------------|
|
|
135
|
+
| `disableWarnings` | `boolean` | `false` | Suppress warnings when color support can't be detected or is disabled. |
|
|
136
|
+
| `theme` | `ThemeOption` (see below) | `'auto'`| Control the active color theme or force a specific mode. |
|
|
137
|
+
| `disableOscProbe` | `boolean` | `false` | Disable OSC 11 terminal theme probing (use only env heuristics for theme). |
|
|
138
|
+
| `maxDepth` | `number` | `5` | Maximum depth when pretty-printing objects in log output. |
|
|
134
139
|
|
|
135
140
|
**`theme` accepts three types of values:**
|
|
136
141
|
|
|
137
|
-
1. **`'auto'`** (Default): Automatically detects your terminal or browser theme (dark/light) and applies the matching default preset.
|
|
142
|
+
1. **`'auto'`** (Default): Automatically detects your terminal or browser theme (dark/light) and applies the matching default preset.
|
|
143
|
+
When combined with `disableOscProbe: true`, only environment variables are used for theme detection (no OSC 11 probe).
|
|
138
144
|
2. **`'dark' | 'light'`**: Forces the logger into a specific mode using the default preset for that mode.
|
|
139
145
|
3. **`ThemeName`**: Forces a specific built-in palette (e.g., `'dracula'`).
|
|
140
146
|
|
|
@@ -174,15 +180,7 @@ const myLogger = createColorino({
|
|
|
174
180
|
// - info, log, debug, trace: #000000 (black - safe on light)
|
|
175
181
|
```
|
|
176
182
|
|
|
177
|
-
**2.
|
|
178
|
-
Useful for CI/CD or environments where detection fails.
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
// Forces dark mode using the default minimal palette (minimal-dark)
|
|
182
|
-
const darkLogger = createColorino({}, { theme: 'dark' })
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
**3. Use a specific preset:**
|
|
183
|
+
**2. Use a specific preset:**
|
|
186
184
|
Instant branding with zero configuration.
|
|
187
185
|
|
|
188
186
|
```typescript
|
|
@@ -190,7 +188,7 @@ Instant branding with zero configuration.
|
|
|
190
188
|
const draculaLogger = createColorino({}, { theme: 'dracula' })
|
|
191
189
|
```
|
|
192
190
|
|
|
193
|
-
**
|
|
191
|
+
**3. Customize a preset:**
|
|
194
192
|
Overlay your own colors on top of a built-in theme.
|
|
195
193
|
|
|
196
194
|
```typescript
|
|
@@ -201,6 +199,14 @@ const myLogger = createColorino(
|
|
|
201
199
|
)
|
|
202
200
|
```
|
|
203
201
|
|
|
202
|
+
**4. Force a specific mode (uses defaults):**
|
|
203
|
+
Useful for CI/CD or environments where detection fails.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
// Forces dark mode using the default minimal palette (minimal-dark)
|
|
207
|
+
const darkLogger = createColorino({}, { theme: 'dark' })
|
|
208
|
+
```
|
|
209
|
+
|
|
204
210
|
> **Tip:**
|
|
205
211
|
> Forcing `'dark'` or `'light'` bypasses automatic theming, ensuring predictable colors in environments with unknown or unsupported theme detection (like some CI pipelines, dumb terminals, or minimal browsers).
|
|
206
212
|
|
|
@@ -208,6 +214,10 @@ const myLogger = createColorino(
|
|
|
208
214
|
|
|
209
215
|
Use your brand colors by passing a partial palette to the `createColorino` factory. Any log levels you don't specify will use the detected **minimal** defaults (`minimal-dark` / `minimal-light`) unless you explicitly select a theme preset.
|
|
210
216
|
|
|
217
|
+
Colorino always targets the highest color fidelity supported by the environment. If your palette uses hex colors but only ANSI‑16 is available, Colorino computes the nearest ANSI color so your branding stays recognizable, even on limited terminals.
|
|
218
|
+
|
|
219
|
+
If you pass an invalid color value (e.g. malformed hex) in a custom palette, Colorino throws an InputValidationError at creation time so broken palettes fail fast.
|
|
220
|
+
|
|
211
221
|
```typescript
|
|
212
222
|
import { createColorino } from 'colorino'
|
|
213
223
|
|
|
@@ -222,16 +232,16 @@ myLogger.info('Still styled by theme.') // Uses the default theme color
|
|
|
222
232
|
|
|
223
233
|
Colorino auto-detects your environment and color support, but you can override behavior using these standard environment variables (compatible with Chalk):
|
|
224
234
|
|
|
225
|
-
| Variable
|
|
226
|
-
|
|
227
|
-
| `NO_COLOR`
|
|
228
|
-
| `FORCE_COLOR`
|
|
229
|
-
| `CLICOLOR`
|
|
230
|
-
| `CLICOLOR_FORCE
|
|
231
|
-
| `TERM`
|
|
232
|
-
| `COLORTERM`
|
|
233
|
-
| `WT_SESSION`
|
|
234
|
-
| `CI`
|
|
235
|
+
| Variable | Effect | Example |
|
|
236
|
+
|-----------------|------------------------------------------------------------------------------------------|--------------------------------------|
|
|
237
|
+
| `NO_COLOR` | Forces no color output | `NO_COLOR=1 node app.js` |
|
|
238
|
+
| `FORCE_COLOR` | Forces color level: `0`=off, `1`=ANSI‑16, `2`=ANSI‑256, `3`=Truecolor | `FORCE_COLOR=3 node app.js` |
|
|
239
|
+
| `CLICOLOR` | `"0"` disables color | `CLICOLOR=0 node app.js` |
|
|
240
|
+
| `CLICOLOR_FORCE`| Non‑`"0"` value enables color even if not a TTY | `CLICOLOR_FORCE=1 node app.js` |
|
|
241
|
+
| `TERM` | Terminal type; may influence color support | `TERM=xterm-256color` |
|
|
242
|
+
| `COLORTERM` | `'truecolor'` or `'24bit'` enables truecolor | `COLORTERM=truecolor` |
|
|
243
|
+
| `WT_SESSION` | Enables color detection for Windows Terminal | |
|
|
244
|
+
| `CI` | Many CI platforms default to no color | `CI=1 node app.js` |
|
|
235
245
|
|
|
236
246
|
## <a id="6"></a>Colorino vs. Chalk
|
|
237
247
|
|
|
@@ -269,48 +279,69 @@ A factory function to create your own customized logger instances.
|
|
|
269
279
|
|
|
270
280
|
## <a id="8"></a>Extending Colorino
|
|
271
281
|
|
|
272
|
-
|
|
282
|
+
Colorino is designed for composition: create a base logger via `createColorino()`, then extend it by inheriting from the base and overriding only the methods you need.
|
|
273
283
|
|
|
274
|
-
|
|
284
|
+
### <a id="8-1"></a>Use case: automatic file/context info
|
|
275
285
|
|
|
276
|
-
|
|
277
|
-
import { createColorino, type ColorinoOptions, type Palette } from 'colorino'
|
|
278
|
-
|
|
279
|
-
// Create a factory for your custom logger
|
|
280
|
-
export function createMyLogger(palette?: Partial<Palette>, options?: ColorinoOptions) {
|
|
281
|
-
// Get the base logger instance
|
|
282
|
-
const baseLogger = createColorino(palette, options)
|
|
283
|
-
|
|
284
|
-
// Define your custom method
|
|
285
|
-
function fatal(...args: unknown[]): void {
|
|
286
|
-
// Reuse the base logger's error method
|
|
287
|
-
baseLogger.error(...args)
|
|
288
|
-
|
|
289
|
-
// Add your custom behavior
|
|
290
|
-
if (typeof process !== 'undefined' && process.exit) {
|
|
291
|
-
process.exit(1)
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Return a new object with all base methods + your custom ones
|
|
296
|
-
// This preserves type safety and the original API
|
|
297
|
-
return {
|
|
298
|
-
...baseLogger,
|
|
299
|
-
fatal,
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
```
|
|
286
|
+
This example prefixes every `.info()` and `.error()` call with best‑effort caller context (file/line) derived from a synthetic `Error` stack.
|
|
303
287
|
|
|
304
|
-
|
|
288
|
+
```ts
|
|
289
|
+
import { createColorino, type Colorino, type ColorinoOptions, type Palette } from 'colorino'
|
|
305
290
|
|
|
306
|
-
|
|
307
|
-
const
|
|
291
|
+
function getCallerContext(): string {
|
|
292
|
+
const err = new Error()
|
|
293
|
+
if (!err.stack) return 'unknown'
|
|
294
|
+
|
|
295
|
+
const lines = err.stack.split('\n').slice(2) // skip "Error" + current frame
|
|
296
|
+
const frame = lines[0] ?? ''
|
|
297
|
+
|
|
298
|
+
const match =
|
|
299
|
+
frame.match(/at (.+?) \((.+?):(\d+):\d+\)/) ??
|
|
300
|
+
frame.match(/at (.+?):(\d+):\d+/)
|
|
301
|
+
|
|
302
|
+
if (!match) return frame.trim() || 'unknown'
|
|
308
303
|
|
|
309
|
-
|
|
310
|
-
|
|
304
|
+
const [_, maybeFn, fileOrLine, maybeLine] = match
|
|
305
|
+
const file = maybeLine ? fileOrLine : maybeFn
|
|
306
|
+
const line = maybeLine ?? fileOrLine
|
|
307
|
+
|
|
308
|
+
return `${file}:${line}`
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function createContextLogger(
|
|
312
|
+
palette?: Partial<Palette>,
|
|
313
|
+
options?: ColorinoOptions,
|
|
314
|
+
): Colorino {
|
|
315
|
+
const base = createColorino(palette, options)
|
|
316
|
+
|
|
317
|
+
// Inherit all default methods from the base logger...
|
|
318
|
+
const logger = Object.create(base) as Colorino // Object.create uses `base` as the prototype.
|
|
319
|
+
|
|
320
|
+
// ...and override only what you need.
|
|
321
|
+
Object.assign(logger, { // Object.assign copies these methods onto `logger`. [web:346]
|
|
322
|
+
info(...args: unknown[]) {
|
|
323
|
+
base.info(`[${getCallerContext()}]`, ...args)
|
|
324
|
+
},
|
|
325
|
+
error(...args: unknown[]) {
|
|
326
|
+
base.error(`[${getCallerContext()}]`, ...args)
|
|
327
|
+
},
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
return logger
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Usage
|
|
334
|
+
const logger = createContextLogger({}, { theme: 'dracula' })
|
|
335
|
+
logger.info('User created', { id: 123 })
|
|
336
|
+
logger.error('Failed to load user', { id: 456 })
|
|
311
337
|
```
|
|
312
338
|
|
|
313
|
-
|
|
339
|
+
## <a id="9"></a>Internals & Dependencies
|
|
340
|
+
|
|
341
|
+
- Colorino’s runtime logic depends on a single bundled library, `neverthrow`, which is MIT‑licensed and used for type‑safe Result handling.
|
|
342
|
+
- `neverthrow` is bundled into the published artifacts, so you do not need to install it separately; your application sees a single runtime dependency: Colorino itself.
|
|
343
|
+
|
|
344
|
+
### <a id="9-1"></a>Why This Pattern?
|
|
314
345
|
|
|
315
346
|
- **Composition > Inheritance**: No fragile base class problems
|
|
316
347
|
- **Type Safe**: TypeScript infers the return type correctly
|
|
@@ -318,6 +349,6 @@ logger.fatal('Missing config: Exiting')
|
|
|
318
349
|
- **Clean**: No messing with `super()` or constructor parameters
|
|
319
350
|
- **Composable**: You can layer multiple extensions
|
|
320
351
|
|
|
321
|
-
## <a id="
|
|
352
|
+
## <a id="10"></a>License
|
|
322
353
|
|
|
323
354
|
[MIT](LICENSE.md)
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
|
|
167
|
+
class MyColorino {
|
|
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 Colorino {
|
|
|
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 Colorino {
|
|
|
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, ...
|
|
914
|
-
return new
|
|
925
|
+
const finalPalette = { ...basePalette, ...userPalette };
|
|
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;
|