@jacob-z/chalk 1.0.0 → 2.0.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 CHANGED
@@ -1,19 +1,19 @@
1
1
  # @jacob-z/chalk
2
2
 
3
- Browser console coloring utilities — a modular, type-safe rewrite of `@alita/chalk`, themed with [Catppuccin Mocha](https://catppuccin.com/palette/).
3
+ Browser console coloring utilities — a modular, type-safe rewrite of `@alita/chalk`, themed with [Catppuccin Macchiato](https://catppuccin.com/palette/).
4
4
 
5
5
  ## Features
6
6
 
7
7
  - `%c` CSS tuple formatters for browser DevTools console output
8
8
  - 9 foreground colors: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `gray`
9
9
  - 8 background colors: `bgBlack`, `bgRed`, `bgGreen`, `bgYellow`, `bgBlue`, `bgMagenta`, `bgCyan`, `bgWhite`
10
- - Light foreground colors automatically get a subtle dark background for readability in dark-mode consoles
10
+ - Mode switching (`foreground` / `background`) controls logger output style globally
11
11
  - `bold()` text formatting
12
12
  - `add()` for merging multiple formatted tuples
13
13
  - Debug-gated logger methods: `log`, `wait`, `error`, `warn`, `ready`, `info`, `event`, `debug`
14
14
  - `hello(title, version)` version banner
15
15
  - `image(url)` console image
16
- - `createChalk(options?)` factory for dependency injection and custom colors
16
+ - `createChalk(options?)` factory for dependency injection
17
17
  - Zero runtime dependencies, fully tree-shakeable
18
18
 
19
19
  ## Install
@@ -30,19 +30,16 @@ Color formatters return `console.log`-ready tuples:
30
30
  import chalk from '@jacob-z/chalk'
31
31
 
32
32
  chalk.red('text')
33
- // → ['%ctext', 'color:#f38ba8']
34
-
35
- chalk.yellow('text')
36
- // → ['%ctext', 'color:#f9e2af;background:rgba(0,0,0,0.15);padding:0 2px;border-radius:2px']
33
+ // → ['%ctext', 'color:#ed8796']
37
34
 
38
35
  chalk.bgRed('text')
39
- // → ['%ctext', 'padding: 2px 4px; border-radius: 3px; color: #1e1e2e; font-weight: bold; background:#f38ba8;']
36
+ // → ['%ctext', 'padding: 2px 4px; border-radius: 3px; color: #24273a; font-weight: bold; background:#ed8796;']
40
37
 
41
38
  chalk.bold('text')
42
39
  // → ['%ctext', 'font-weight: bold;']
43
40
 
44
41
  chalk.add(chalk.red('a'), chalk.blue('b'))
45
- // → [' %ca %cb', 'color:#f38ba8', 'color:#89b4fa']
42
+ // → [' %ca %cb', 'color:#ed8796', 'color:#8aadf4']
46
43
  ```
47
44
 
48
45
  Use with `console.log` spread:
@@ -52,6 +49,35 @@ console.log(...chalk.red('colored text'))
52
49
  console.log(...chalk.add(chalk.red('error:'), chalk.bold(' not found')))
53
50
  ```
54
51
 
52
+ ### Foreground vs Background Methods
53
+
54
+ - **Foreground** (`red`, `green`, `blue`, …) — pure `color:<hex>`, no background or padding
55
+ - **Background** (`bgRed`, `bgGreen`, `bgBlue`, …) — `background:<hex>; color:#24273a; font-weight: bold; padding: 2px 4px; border-radius: 3px;`
56
+ - **bgBlack** special case — dark base background with blue text `#8aadf4`
57
+
58
+ These are fixed regardless of the `mode` setting. Mode only affects logger output.
59
+
60
+ ## Mode Switching
61
+
62
+ `createChalk({ mode })` controls how logger methods render. Default is `'background'`.
63
+
64
+ ```ts
65
+ import { createChalk } from '@jacob-z/chalk'
66
+
67
+ const bgChalk = createChalk({ console, mode: 'background', isDebug: true })
68
+ const fgChalk = createChalk({ console, mode: 'foreground', isDebug: true })
69
+
70
+ // background mode: label + message share same styled background
71
+ bgChalk.info('loaded')
72
+ // → %c[Info]%c loaded (both segments use background style)
73
+
74
+ // foreground mode: label + message share same foreground color
75
+ fgChalk.info('loaded')
76
+ // → %c[Info]%c loaded (both segments use color:<hex> only)
77
+ ```
78
+
79
+ Logger label and message body use the **same style** — no separate styling for the tag vs the content.
80
+
55
81
  ## Debug Logging
56
82
 
57
83
  Logger methods only print when debugging is enabled. By default they read `globalThis.alitadebug`:
@@ -87,33 +113,23 @@ chalk.info('loaded')
87
113
 
88
114
  If a console method is unavailable, the logger falls back to `console.log`.
89
115
 
90
- ## Custom Colors
91
-
92
- ```ts
93
- import { createChalk } from '@jacob-z/chalk'
94
-
95
- const chalk = createChalk({
96
- colors: { brand: '#123456' },
97
- })
98
-
99
- chalk.color('brand', 'Brand text') // → ['%cBrand text', 'color:#123456']
100
- chalk.bgColor('brand', 'Brand block') // → background with custom color
101
- ```
102
-
103
116
  ## Custom Log Levels
104
117
 
118
+ Extend the logger with additional methods using built-in color names:
119
+
105
120
  ```ts
106
121
  const chalk = createChalk({
107
122
  isDebug: true,
108
- colors: { trace: '#123456' },
109
123
  logLevels: [
110
- { name: 'trace', label: 'Trace', color: 'trace', method: 'debug' },
124
+ { name: 'trace', label: 'Trace', color: 'blue', method: 'debug' },
111
125
  ],
112
126
  })
113
127
 
114
- chalk.trace('details') // → [Trace] in custom color via console.debug
128
+ chalk.trace('details') // → [Trace] in blue via console.debug
115
129
  ```
116
130
 
131
+ `color` must be a built-in `ColorName`: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `gray`.
132
+
117
133
  ## Banner & Image
118
134
 
119
135
  ```ts
@@ -121,14 +137,39 @@ chalk.hello('MyApp', '1.0.0') // styled title + version banner
121
137
  chalk.image('https://example.com/logo.png') // console CSS background image
122
138
  ```
123
139
 
140
+ ## API
141
+
142
+ ### `createChalk(options?)`
143
+
144
+ | Option | Type | Default | Description |
145
+ | ------------ | --------------------------- | ------------------------------- | ------------------------------------- |
146
+ | `console` | `Console` | `globalThis.console` | Console instance for output |
147
+ | `isDebug` | `boolean \| (() => boolean)`| `() => globalThis.alitadebug` | Debug gate for logger methods |
148
+ | `mode` | `'foreground' \| 'background'` | `'background'` | Logger output style |
149
+ | `logLevels` | `LogLevelDefinition[]` | (built-in 8 levels) | Custom logger level definitions |
150
+
151
+ ### `getStyle(colors, name, mode)`
152
+
153
+ Low-level utility to get CSS style string for a given color name and mode:
154
+
155
+ ```ts
156
+ import { getStyle, DEFAULT_COLORS } from '@jacob-z/chalk'
157
+
158
+ getStyle(DEFAULT_COLORS, 'red', 'foreground')
159
+ // → 'color:#ed8796'
160
+
161
+ getStyle(DEFAULT_COLORS, 'red', 'background')
162
+ // → 'padding: 2px 4px; border-radius: 3px; color: #24273a; font-weight: bold; background:#ed8796;'
163
+ ```
164
+
124
165
  ## Architecture
125
166
 
126
167
  ```
127
168
  src/
128
- types.ts → All public & internal types
129
- colors.ts → Color map, CSS generation (pure functions)
130
- format.ts → %c format helpers, add(), bold()
131
- logger.ts → Debug-gated logger factory
169
+ types.ts → All public & internal types (ChalkMode, ColorName, LogLevelDefinition)
170
+ colors.ts → Macchiato palette, getStyle() (pure functions)
171
+ format.ts → %c format helpers, add(), bold(), coloredText()
172
+ logger.ts → Debug-gated logger factory (mode-aware)
132
173
  banner.ts → hello(), image()
133
174
  create.ts → createChalk() factory
134
175
  index.ts → Default instance + re-exports
@@ -140,8 +181,8 @@ Design principles vs the original `@alita/chalk`:
140
181
  - **No global cache** — no `window.chalk` mutation
141
182
  - **No module-level side effects** — factory pattern, pure functions
142
183
  - **No `any` / `@ts-ignore`** — strict TypeScript throughout
143
- - **Modular & extensible** — custom colors, custom log levels, injected console
144
- - **Dark-mode friendly** — light foreground colors get a subtle background for readability
184
+ - **Mode-driven styling** — single `mode` option controls all logger output
185
+ - **Dark-mode friendly** — Catppuccin Macchiato palette with proper contrast
145
186
 
146
187
  ## License
147
188
 
package/dist/index.cjs CHANGED
@@ -1,69 +1,11 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
- //#region src/colors.ts
4
- /**
5
- * Catppuccin Mocha palette — https://catppuccin.com/palette/
6
- */
7
- const DEFAULT_COLORS = {
8
- black: "#1e1e2e",
9
- red: "#f38ba8",
10
- green: "#a6e3a1",
11
- yellow: "#f9e2af",
12
- blue: "#89b4fa",
13
- magenta: "#cba6f7",
14
- cyan: "#94e2d5",
15
- white: "#cdd6f4",
16
- gray: "#6c7086"
17
- };
18
- /**
19
- * Colors that are dark enough to not need a background on dark consoles.
20
- * All other built-in Catppuccin Mocha colors are pastel and need a subtle bg.
21
- */
22
- const DARK_FG_COLORS = {
23
- black: true,
24
- gray: true
25
- };
26
- function createColorMap(customColors = {}) {
27
- return {
28
- ...DEFAULT_COLORS,
29
- ...customColors
30
- };
31
- }
32
- function resolveColor(colors, name) {
33
- const color$2 = colors[name];
34
- if (color$2 === void 0) throw new Error(`Unknown chalk color: ${name}`);
35
- return color$2;
36
- }
37
- /** Returns true when the color is bright enough to need a background in dark consoles. */
38
- function needsBackground(colors, name) {
39
- if (DARK_FG_COLORS[name]) return false;
40
- const hex = colors[name];
41
- if (!hex) return true;
42
- return getRelativeLuminance(hex) > .18;
43
- }
44
- function getRelativeLuminance(hex) {
45
- const h = hex.replace("#", "");
46
- const r = Number.parseInt(h.slice(0, 2), 16) / 255;
47
- const g = Number.parseInt(h.slice(2, 4), 16) / 255;
48
- const b = Number.parseInt(h.slice(4, 6), 16) / 255;
49
- return .2126 * r + .7152 * g + .0722 * b;
50
- }
51
- function getForegroundStyle(colors, name) {
52
- const parts = [`color:${resolveColor(colors, name)}`];
53
- if (needsBackground(colors, name)) parts.push("background:rgba(0,0,0,0.15)", "padding:0 2px", "border-radius:2px");
54
- return parts.join(";");
55
- }
56
- function getBackgroundStyle(colors, name) {
57
- return `padding: 2px 4px; border-radius: 3px; color: #1e1e2e; font-weight: bold; background:${resolveColor(colors, name)};`;
58
- }
59
-
60
- //#endregion
61
3
  //#region src/banner.ts
62
4
  function createBannerMethods(consoleLike, isDebug) {
63
5
  return {
64
6
  hello(title, version) {
65
7
  if (!isDebug()) return;
66
- consoleLike.log(`%c ${title} %c V${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #cdd6f4; background: #45475a; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #1e1e2e; background: #a6e3a1; font-weight: bold;");
8
+ consoleLike.log(`%c ${title} %c V${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #cad3f5; background: #494d64; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #24273a; background: #a6da95; font-weight: bold;");
67
9
  },
68
10
  image(url) {
69
11
  if (!url) return;
@@ -73,16 +15,45 @@ function createBannerMethods(consoleLike, isDebug) {
73
15
  };
74
16
  }
75
17
 
18
+ //#endregion
19
+ //#region src/colors.ts
20
+ /**
21
+ * Catppuccin Macchiato palette — https://catppuccin.com/palette/
22
+ */
23
+ const DEFAULT_COLORS = {
24
+ black: "#24273a",
25
+ red: "#ed8796",
26
+ green: "#a6da95",
27
+ yellow: "#eed49f",
28
+ blue: "#8aadf4",
29
+ magenta: "#c6a0f6",
30
+ cyan: "#8bd5ca",
31
+ white: "#cad3f5",
32
+ gray: "#6e738d"
33
+ };
34
+ function resolveColor(colors, name) {
35
+ const color = colors[name];
36
+ if (color === void 0) throw new Error(`Unknown chalk color: ${name}`);
37
+ return color;
38
+ }
39
+ function getForegroundStyle(colors, name) {
40
+ return `color:${resolveColor(colors, name)}`;
41
+ }
42
+ function getBackgroundStyle(colors, name) {
43
+ const hex = resolveColor(colors, name);
44
+ return `padding: 2px 4px; border-radius: 3px; color: ${name === "black" ? colors.blue ?? "#8aadf4" : "#24273a"}; font-weight: bold; background:${hex};`;
45
+ }
46
+ function getStyle(colors, name, mode) {
47
+ return mode === "background" ? getBackgroundStyle(colors, name) : getForegroundStyle(colors, name);
48
+ }
49
+
76
50
  //#endregion
77
51
  //#region src/format.ts
78
52
  function formatText(text, style) {
79
53
  return [`%c${text}`, style];
80
54
  }
81
- function color$1(colors, name, text) {
82
- return formatText(text, getForegroundStyle(colors, name));
83
- }
84
- function bgColor$1(colors, name, text) {
85
- return formatText(text, getBackgroundStyle(colors, name));
55
+ function coloredText(name, text, mode) {
56
+ return formatText(text, getStyle(DEFAULT_COLORS, name, mode));
86
57
  }
87
58
  function bold(text) {
88
59
  return formatText(text, "font-weight: bold;");
@@ -147,18 +118,30 @@ const DEFAULT_LOG_LEVELS = [
147
118
  function getConsoleMethod(consoleLike, method) {
148
119
  return consoleLike[method] ?? consoleLike.log;
149
120
  }
150
- function createLogMethod(consoleLike, colors, isDebug, level) {
121
+ function createLogMethod(consoleLike, isDebug, level, mode, getHooks) {
151
122
  return (message, ...args) => {
152
- if (!isDebug()) return;
153
- const method = getConsoleMethod(consoleLike, level.method);
154
- const labelStyle = `${getForegroundStyle(colors, level.color)};font-weight: bold;`;
155
- const messageStyle = getForegroundStyle(colors, level.color);
156
- method(`%c[${level.label}]%c ${message}`, labelStyle, messageStyle, ...args);
123
+ const debugValue = isDebug();
124
+ if (debugValue) {
125
+ const method = getConsoleMethod(consoleLike, level.method);
126
+ const style = getStyle(DEFAULT_COLORS, level.color, mode);
127
+ method(`%c[${level.label}]%c ${message}`, style, style, ...args);
128
+ }
129
+ const hooks = getHooks();
130
+ if (hooks.length > 0) {
131
+ const ctx = {
132
+ level: level.name,
133
+ label: level.label,
134
+ message,
135
+ args,
136
+ isDebug: debugValue
137
+ };
138
+ for (const hook of hooks) hook(ctx);
139
+ }
157
140
  };
158
141
  }
159
142
  function createLoggerMethods(options) {
160
143
  const levels = options.logLevels ?? DEFAULT_LOG_LEVELS;
161
- return Object.fromEntries(levels.map((level) => [level.name, createLogMethod(options.console, options.colors, options.isDebug, level)]));
144
+ return Object.fromEntries(levels.map((level) => [level.name, createLogMethod(options.console, options.isDebug, level, options.mode, options.getHooks)]));
162
145
  }
163
146
 
164
147
  //#endregion
@@ -177,37 +160,40 @@ function resolveDebugPredicate(isDebug) {
177
160
  }
178
161
  function createChalk(options = {}) {
179
162
  const consoleLike = resolveConsole(options.console);
180
- const colors = createColorMap(options.colors);
163
+ const mode = options.mode ?? "background";
181
164
  const isDebug = resolveDebugPredicate(options.isDebug);
182
165
  const banner = createBannerMethods(consoleLike, isDebug);
166
+ const hooks = [];
167
+ const getHooks = () => hooks;
183
168
  const loggers = createLoggerMethods({
184
169
  console: consoleLike,
185
- colors,
170
+ mode,
186
171
  isDebug,
187
- logLevels: options.logLevels
172
+ logLevels: options.logLevels,
173
+ getHooks
188
174
  });
189
- return {
175
+ const fg = (name) => (text) => coloredText(name, text, "foreground");
176
+ const bg = (name) => (text) => coloredText(name, text, "background");
177
+ const instance = {
190
178
  add,
191
179
  bold,
192
180
  ...banner,
193
- black: (text) => color$1(colors, "black", text),
194
- red: (text) => color$1(colors, "red", text),
195
- green: (text) => color$1(colors, "green", text),
196
- yellow: (text) => color$1(colors, "yellow", text),
197
- blue: (text) => color$1(colors, "blue", text),
198
- magenta: (text) => color$1(colors, "magenta", text),
199
- cyan: (text) => color$1(colors, "cyan", text),
200
- white: (text) => color$1(colors, "white", text),
201
- bgBlack: (text) => bgColor$1(colors, "black", text),
202
- bgRed: (text) => bgColor$1(colors, "red", text),
203
- bgGreen: (text) => bgColor$1(colors, "green", text),
204
- bgYellow: (text) => bgColor$1(colors, "yellow", text),
205
- bgBlue: (text) => bgColor$1(colors, "blue", text),
206
- bgMagenta: (text) => bgColor$1(colors, "magenta", text),
207
- bgCyan: (text) => bgColor$1(colors, "cyan", text),
208
- bgWhite: (text) => bgColor$1(colors, "white", text),
209
- color: (name, text) => color$1(colors, name, text),
210
- bgColor: (name, text) => bgColor$1(colors, name, text),
181
+ black: fg("black"),
182
+ red: fg("red"),
183
+ green: fg("green"),
184
+ yellow: fg("yellow"),
185
+ blue: fg("blue"),
186
+ magenta: fg("magenta"),
187
+ cyan: fg("cyan"),
188
+ white: fg("white"),
189
+ bgBlack: bg("black"),
190
+ bgRed: bg("red"),
191
+ bgGreen: bg("green"),
192
+ bgYellow: bg("yellow"),
193
+ bgBlue: bg("blue"),
194
+ bgMagenta: bg("magenta"),
195
+ bgCyan: bg("cyan"),
196
+ bgWhite: bg("white"),
211
197
  log: loggers.log,
212
198
  wait: loggers.wait,
213
199
  error: loggers.error,
@@ -215,33 +201,29 @@ function createChalk(options = {}) {
215
201
  ready: loggers.ready,
216
202
  info: loggers.info,
217
203
  event: loggers.event,
218
- debug: loggers.debug
204
+ debug: loggers.debug,
205
+ use(hook) {
206
+ hooks.push(hook);
207
+ return instance;
208
+ }
219
209
  };
210
+ return instance;
220
211
  }
221
212
 
222
213
  //#endregion
223
214
  //#region src/index.ts
224
- const defaultColors = createColorMap();
225
215
  const chalk = createChalk();
226
- function color(name, text) {
227
- return color$1(defaultColors, name, text);
228
- }
229
- function bgColor(name, text) {
230
- return bgColor$1(defaultColors, name, text);
231
- }
232
216
  var src_default = chalk;
233
217
 
234
218
  //#endregion
235
219
  exports.DEFAULT_COLORS = DEFAULT_COLORS;
236
220
  exports.add = add;
237
- exports.bgColor = bgColor;
238
221
  exports.bold = bold;
239
222
  exports.chalk = chalk;
240
- exports.color = color;
241
223
  exports.createChalk = createChalk;
242
- exports.createColorMap = createColorMap;
243
224
  exports.default = src_default;
244
225
  exports.getBackgroundStyle = getBackgroundStyle;
245
226
  exports.getForegroundStyle = getForegroundStyle;
227
+ exports.getStyle = getStyle;
246
228
  exports.resolveColor = resolveColor;
247
229
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["DEFAULT_COLORS: ColorMap","DARK_FG_COLORS: Record<string, true>","color","color","bgColor","noopConsole: ConsoleLike","color","bgColor","colorWithMap","bgColorWithMap"],"sources":["../src/colors.ts","../src/banner.ts","../src/format.ts","../src/logger.ts","../src/create.ts","../src/index.ts"],"sourcesContent":["import type { ColorMap, CustomColorMap } from './types'\n\n/**\n * Catppuccin Mocha palette — https://catppuccin.com/palette/\n */\nexport const DEFAULT_COLORS: ColorMap = {\n black: '#1e1e2e', // Base\n red: '#f38ba8', // Red\n green: '#a6e3a1', // Green\n yellow: '#f9e2af', // Yellow\n blue: '#89b4fa', // Blue\n magenta: '#cba6f7', // Mauve\n cyan: '#94e2d5', // Teal\n white: '#cdd6f4', // Text\n gray: '#6c7086', // Overlay0\n}\n\n/**\n * Colors that are dark enough to not need a background on dark consoles.\n * All other built-in Catppuccin Mocha colors are pastel and need a subtle bg.\n */\nexport const DARK_FG_COLORS: Record<string, true> = { black: true, gray: true }\n\nexport type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>\n\nexport function createColorMap(customColors: CustomColorMap = {} as CustomColorMap): ResolvedColorMap {\n return {\n ...DEFAULT_COLORS,\n ...customColors,\n }\n}\n\nexport function resolveColor(colors: Readonly<Record<string, string>>, name: string): string {\n const color = colors[name]\n if (color === undefined)\n throw new Error(`Unknown chalk color: ${name}`)\n return color\n}\n\n/** Returns true when the color is bright enough to need a background in dark consoles. */\nfunction needsBackground(colors: Readonly<Record<string, string>>, name: string): boolean {\n if (DARK_FG_COLORS[name])\n return false\n const hex = colors[name]\n if (!hex)\n return true\n return getRelativeLuminance(hex) > 0.18\n}\n\nfunction getRelativeLuminance(hex: string): number {\n const h = hex.replace('#', '')\n const r = Number.parseInt(h.slice(0, 2), 16) / 255\n const g = Number.parseInt(h.slice(2, 4), 16) / 255\n const b = Number.parseInt(h.slice(4, 6), 16) / 255\n return 0.2126 * r + 0.7152 * g + 0.0722 * b\n}\n\nexport function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const hex = resolveColor(colors, name)\n const parts = [`color:${hex}`]\n if (needsBackground(colors, name))\n parts.push('background:rgba(0,0,0,0.15)', 'padding:0 2px', 'border-radius:2px')\n return parts.join(';')\n}\n\nexport function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const hex = resolveColor(colors, name)\n const textColor = '#1e1e2e'\n return `padding: 2px 4px; border-radius: 3px; color: ${textColor}; font-weight: bold; background:${hex};`\n}\n","import type { ConsoleLike, DebugPredicate } from './types'\n\nexport interface BannerMethods {\n hello: (title: string, version: string) => void\n image: (url: string) => void\n}\n\nexport function createBannerMethods(consoleLike: ConsoleLike, isDebug: DebugPredicate): BannerMethods {\n return {\n hello(title: string, version: string): void {\n if (!isDebug())\n return\n consoleLike.log(\n `%c ${title} %c V${version} `,\n 'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #cdd6f4; background: #45475a; font-weight: bold;',\n 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #1e1e2e; background: #a6e3a1; font-weight: bold;',\n )\n },\n image(url: string): void {\n if (!url)\n return\n if (!isDebug())\n return\n consoleLike.log(\n '%c ',\n `font-size: 1px; padding: 100px 100px; background: url(${url}) no-repeat center / contain; color: transparent;`,\n )\n },\n }\n}\n","import type { FormattedText } from './types'\nimport { getBackgroundStyle, getForegroundStyle } from './colors'\n\nexport function formatText(text: string, style: string): FormattedText {\n return [`%c${text}`, style]\n}\n\nexport function color(colors: Readonly<Record<string, string>>, name: string, text: string): FormattedText {\n return formatText(text, getForegroundStyle(colors, name))\n}\n\nexport function bgColor(colors: Readonly<Record<string, string>>, name: string, text: string): FormattedText {\n return formatText(text, getBackgroundStyle(colors, name))\n}\n\nexport function bold(text: string): FormattedText {\n return formatText(text, 'font-weight: bold;')\n}\n\nexport function add(...items: readonly FormattedText[]): FormattedText {\n if (items.length === 0)\n return ['%c', '']\n const template = items.map(item => ` ${item[0]}`).join('')\n const styles = items.flatMap(([, ...itemStyles]) => itemStyles)\n return [template, ...styles] as FormattedText\n}\n","import type { ConsoleLike, ConsoleMethodName, DebugPredicate, LogLevelDefinition, LogMethod } from './types'\nimport { getForegroundStyle } from './colors'\n\nexport const DEFAULT_LOG_LEVELS = [\n { name: 'log', label: 'Log', color: 'black', method: 'log' },\n { name: 'wait', label: 'Wait', color: 'cyan', method: 'log' },\n { name: 'error', label: 'Error', color: 'red', method: 'error' },\n { name: 'warn', label: 'Warn', color: 'yellow', method: 'warn' },\n { name: 'ready', label: 'Ready', color: 'green', method: 'log' },\n { name: 'info', label: 'Info', color: 'blue', method: 'info' },\n { name: 'event', label: 'Event', color: 'magenta', method: 'log' },\n { name: 'debug', label: 'Debug', color: 'gray', method: 'debug' },\n] satisfies readonly LogLevelDefinition[]\n\nexport interface CreateLoggerMethodsOptions {\n console: ConsoleLike\n colors: Readonly<Record<string, string>>\n isDebug: DebugPredicate\n logLevels?: readonly LogLevelDefinition[]\n}\n\nfunction getConsoleMethod(consoleLike: ConsoleLike, method: ConsoleMethodName): (...data: unknown[]) => void {\n return consoleLike[method] ?? consoleLike.log\n}\n\nfunction createLogMethod(\n consoleLike: ConsoleLike,\n colors: Readonly<Record<string, string>>,\n isDebug: DebugPredicate,\n level: LogLevelDefinition,\n): LogMethod {\n return (message: string, ...args: unknown[]): void => {\n if (!isDebug())\n return\n const method = getConsoleMethod(consoleLike, level.method)\n const labelStyle = `${getForegroundStyle(colors, level.color)};font-weight: bold;`\n const messageStyle = getForegroundStyle(colors, level.color)\n method(`%c[${level.label}]%c ${message}`, labelStyle, messageStyle, ...args)\n }\n}\n\nexport function createLoggerMethods(options: CreateLoggerMethodsOptions): Record<string, LogMethod> {\n const levels = options.logLevels ?? DEFAULT_LOG_LEVELS\n return Object.fromEntries(\n levels.map(level => [\n level.name,\n createLogMethod(options.console, options.colors, options.isDebug, level),\n ]),\n )\n}\n","import type { ChalkInstance, ConsoleLike, CreateChalkOptions, DebugPredicate } from './types'\nimport { createBannerMethods } from './banner'\nimport { createColorMap } from './colors'\nimport { add, bgColor, bold, color } from './format'\nimport { createLoggerMethods } from './logger'\n\nconst noopConsole: ConsoleLike = {\n log: () => {},\n}\n\nfunction readGlobalDebugFlag(): boolean {\n return Object.prototype.hasOwnProperty.call(globalThis, 'alitadebug')\n && Boolean(globalThis.alitadebug)\n}\n\nfunction resolveConsole(consoleLike: ConsoleLike | undefined): ConsoleLike {\n return consoleLike ?? globalThis.console ?? noopConsole\n}\n\nfunction resolveDebugPredicate(isDebug: CreateChalkOptions['isDebug']): DebugPredicate {\n if (typeof isDebug === 'function')\n return isDebug\n if (typeof isDebug === 'boolean')\n return () => isDebug\n return readGlobalDebugFlag\n}\n\nexport function createChalk(options: CreateChalkOptions = {}): ChalkInstance {\n const consoleLike = resolveConsole(options.console)\n const colors = createColorMap(options.colors)\n const isDebug = resolveDebugPredicate(options.isDebug)\n const banner = createBannerMethods(consoleLike, isDebug)\n const loggers = createLoggerMethods({\n console: consoleLike,\n colors,\n isDebug,\n logLevels: options.logLevels,\n })\n\n return {\n add,\n bold,\n ...banner,\n black: text => color(colors, 'black', text),\n red: text => color(colors, 'red', text),\n green: text => color(colors, 'green', text),\n yellow: text => color(colors, 'yellow', text),\n blue: text => color(colors, 'blue', text),\n magenta: text => color(colors, 'magenta', text),\n cyan: text => color(colors, 'cyan', text),\n white: text => color(colors, 'white', text),\n bgBlack: text => bgColor(colors, 'black', text),\n bgRed: text => bgColor(colors, 'red', text),\n bgGreen: text => bgColor(colors, 'green', text),\n bgYellow: text => bgColor(colors, 'yellow', text),\n bgBlue: text => bgColor(colors, 'blue', text),\n bgMagenta: text => bgColor(colors, 'magenta', text),\n bgCyan: text => bgColor(colors, 'cyan', text),\n bgWhite: text => bgColor(colors, 'white', text),\n color: (name, text) => color(colors, name, text),\n bgColor: (name, text) => bgColor(colors, name, text),\n log: loggers.log,\n wait: loggers.wait,\n error: loggers.error,\n warn: loggers.warn,\n ready: loggers.ready,\n info: loggers.info,\n event: loggers.event,\n debug: loggers.debug,\n }\n}\n","import { createColorMap } from './colors'\nimport { createChalk } from './create'\nimport { add, bgColor as bgColorWithMap, bold, color as colorWithMap } from './format'\n\nconst defaultColors = createColorMap()\n\nexport const chalk = createChalk()\n\nexport { add, bold, createChalk }\nexport { createColorMap, DEFAULT_COLORS, getBackgroundStyle, getForegroundStyle, resolveColor } from './colors'\nexport type {\n ChalkInstance,\n ColorMap,\n ColorName,\n ConsoleLike,\n CreateChalkOptions,\n CustomColorMap,\n FormattedText,\n LogLevelDefinition,\n LogMethod,\n PublicColorName,\n TextFormatter,\n} from './types'\n\nexport function color(name: string, text: string) {\n return colorWithMap(defaultColors, name, text)\n}\n\nexport function bgColor(name: string, text: string) {\n return bgColorWithMap(defaultColors, name, text)\n}\n\nexport default chalk\n"],"mappings":";;;;;;AAKA,MAAaA,iBAA2B;CACtC,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;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sole: ConsoleLike","hooks: LogHook[]","instance: ChalkInstance"],"sources":["../src/banner.ts","../src/colors.ts","../src/format.ts","../src/logger.ts","../src/create.ts","../src/index.ts"],"sourcesContent":["import type { ConsoleLike, DebugPredicate } from './types'\n\nexport interface BannerMethods {\n hello: (title: string, version: string) => void\n image: (url: string) => void\n}\n\nexport function createBannerMethods(consoleLike: ConsoleLike, isDebug: DebugPredicate): BannerMethods {\n return {\n hello(title: string, version: string): void {\n if (!isDebug())\n return\n consoleLike.log(\n `%c ${title} %c V${version} `,\n 'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #cad3f5; background: #494d64; font-weight: bold;',\n 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #24273a; background: #a6da95; font-weight: bold;',\n )\n },\n image(url: string): void {\n if (!url)\n return\n if (!isDebug())\n return\n consoleLike.log(\n '%c ',\n `font-size: 1px; padding: 100px 100px; background: url(${url}) no-repeat center / contain; color: transparent;`,\n )\n },\n }\n}\n","import type { ChalkMode, ColorMap } from './types'\n\n/**\n * Catppuccin Macchiato palette — https://catppuccin.com/palette/\n */\nexport const DEFAULT_COLORS: ColorMap = {\n black: '#24273a', // Base\n red: '#ed8796', // Red\n green: '#a6da95', // Green\n yellow: '#eed49f', // Yellow\n blue: '#8aadf4', // Blue\n magenta: '#c6a0f6', // Mauve\n cyan: '#8bd5ca', // Teal\n white: '#cad3f5', // Text\n gray: '#6e738d', // Overlay0\n}\n\nexport function resolveColor(colors: Readonly<Record<string, string>>, name: string): string {\n const color = colors[name]\n if (color === undefined)\n throw new Error(`Unknown chalk color: ${name}`)\n return color\n}\n\nexport function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const hex = resolveColor(colors, name)\n return `color:${hex}`\n}\n\nexport function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const hex = resolveColor(colors, name)\n const textColor = name === 'black' ? (colors.blue ?? '#8aadf4') : '#24273a'\n return `padding: 2px 4px; border-radius: 3px; color: ${textColor}; font-weight: bold; background:${hex};`\n}\n\nexport function getStyle(colors: Readonly<Record<string, string>>, name: string, mode: ChalkMode): string {\n return mode === 'background'\n ? getBackgroundStyle(colors, name)\n : getForegroundStyle(colors, name)\n}\n","import type { ChalkMode, FormattedText } from './types'\nimport { DEFAULT_COLORS, getStyle } from './colors'\n\nexport function formatText(text: string, style: string): FormattedText {\n return [`%c${text}`, style]\n}\n\nexport function coloredText(name: string, text: string, mode: ChalkMode): FormattedText {\n return formatText(text, getStyle(DEFAULT_COLORS, name, mode))\n}\n\nexport function bold(text: string): FormattedText {\n return formatText(text, 'font-weight: bold;')\n}\n\nexport function add(...items: readonly FormattedText[]): FormattedText {\n if (items.length === 0)\n return ['%c', '']\n const template = items.map(item => ` ${item[0]}`).join('')\n const styles = items.flatMap(([, ...itemStyles]) => itemStyles)\n return [template, ...styles] as FormattedText\n}\n","import type { ChalkMode, ConsoleLike, ConsoleMethodName, DebugPredicate, LogHook, LogHookContext, LogLevelDefinition, LogMethod } from './types'\nimport { DEFAULT_COLORS, getStyle } from './colors'\n\nexport const DEFAULT_LOG_LEVELS = [\n { name: 'log', label: 'Log', color: 'black', method: 'log' },\n { name: 'wait', label: 'Wait', color: 'cyan', method: 'log' },\n { name: 'error', label: 'Error', color: 'red', method: 'error' },\n { name: 'warn', label: 'Warn', color: 'yellow', method: 'warn' },\n { name: 'ready', label: 'Ready', color: 'green', method: 'log' },\n { name: 'info', label: 'Info', color: 'blue', method: 'info' },\n { name: 'event', label: 'Event', color: 'magenta', method: 'log' },\n { name: 'debug', label: 'Debug', color: 'gray', method: 'debug' },\n] satisfies readonly LogLevelDefinition[]\n\nexport interface CreateLoggerMethodsOptions {\n console: ConsoleLike\n mode: ChalkMode\n isDebug: DebugPredicate\n logLevels?: readonly LogLevelDefinition[]\n getHooks: () => readonly LogHook[]\n}\n\nfunction getConsoleMethod(consoleLike: ConsoleLike, method: ConsoleMethodName): (...data: unknown[]) => void {\n return consoleLike[method] ?? consoleLike.log\n}\n\nfunction createLogMethod(\n consoleLike: ConsoleLike,\n isDebug: DebugPredicate,\n level: LogLevelDefinition,\n mode: ChalkMode,\n getHooks: () => readonly LogHook[],\n): LogMethod {\n return (message: string, ...args: unknown[]): void => {\n const debugValue = isDebug()\n\n if (debugValue) {\n const method = getConsoleMethod(consoleLike, level.method)\n const style = getStyle(DEFAULT_COLORS, level.color, mode)\n method(`%c[${level.label}]%c ${message}`, style, style, ...args)\n }\n\n const hooks = getHooks()\n if (hooks.length > 0) {\n const ctx: LogHookContext = {\n level: level.name,\n label: level.label,\n message,\n args,\n isDebug: debugValue,\n }\n for (const hook of hooks) {\n hook(ctx)\n }\n }\n }\n}\n\nexport function createLoggerMethods(options: CreateLoggerMethodsOptions): Record<string, LogMethod> {\n const levels = options.logLevels ?? DEFAULT_LOG_LEVELS\n return Object.fromEntries(\n levels.map(level => [\n level.name,\n createLogMethod(options.console, options.isDebug, level, options.mode, options.getHooks),\n ]),\n )\n}\n","import type { ChalkInstance, ConsoleLike, CreateChalkOptions, DebugPredicate, LogHook } from './types'\nimport { createBannerMethods } from './banner'\nimport { add, bold, coloredText } from './format'\nimport { createLoggerMethods } from './logger'\n\nconst noopConsole: ConsoleLike = {\n log: () => {},\n}\n\nfunction readGlobalDebugFlag(): boolean {\n return Object.prototype.hasOwnProperty.call(globalThis, 'alitadebug')\n && Boolean(globalThis.alitadebug)\n}\n\nfunction resolveConsole(consoleLike: ConsoleLike | undefined): ConsoleLike {\n return consoleLike ?? globalThis.console ?? noopConsole\n}\n\nfunction resolveDebugPredicate(isDebug: CreateChalkOptions['isDebug']): DebugPredicate {\n if (typeof isDebug === 'function')\n return isDebug\n if (typeof isDebug === 'boolean')\n return () => isDebug\n return readGlobalDebugFlag\n}\n\nexport function createChalk(options: CreateChalkOptions = {}): ChalkInstance {\n const consoleLike = resolveConsole(options.console)\n const mode = options.mode ?? 'background'\n const isDebug = resolveDebugPredicate(options.isDebug)\n const banner = createBannerMethods(consoleLike, isDebug)\n const hooks: LogHook[] = []\n const getHooks = (): readonly LogHook[] => hooks\n const loggers = createLoggerMethods({\n console: consoleLike,\n mode,\n isDebug,\n logLevels: options.logLevels,\n getHooks,\n })\n\n const fg = (name: string) => (text: string) => coloredText(name, text, 'foreground')\n const bg = (name: string) => (text: string) => coloredText(name, text, 'background')\n\n const instance: ChalkInstance = {\n add,\n bold,\n ...banner,\n black: fg('black'),\n red: fg('red'),\n green: fg('green'),\n yellow: fg('yellow'),\n blue: fg('blue'),\n magenta: fg('magenta'),\n cyan: fg('cyan'),\n white: fg('white'),\n bgBlack: bg('black'),\n bgRed: bg('red'),\n bgGreen: bg('green'),\n bgYellow: bg('yellow'),\n bgBlue: bg('blue'),\n bgMagenta: bg('magenta'),\n bgCyan: bg('cyan'),\n bgWhite: bg('white'),\n log: loggers.log,\n wait: loggers.wait,\n error: loggers.error,\n warn: loggers.warn,\n ready: loggers.ready,\n info: loggers.info,\n event: loggers.event,\n debug: loggers.debug,\n use(hook: LogHook): ChalkInstance {\n hooks.push(hook)\n return instance\n },\n }\n\n return instance\n}\n","import { createChalk } from './create'\nimport { add, bold } from './format'\n\nexport const chalk = createChalk()\n\nexport { add, bold, createChalk }\nexport { DEFAULT_COLORS, getBackgroundStyle, getForegroundStyle, getStyle, resolveColor } from './colors'\nexport type {\n ChalkInstance,\n ChalkMode,\n ColorMap,\n ColorName,\n ConsoleLike,\n CreateChalkOptions,\n FormattedText,\n LogHook,\n LogHookContext,\n LogLevelDefinition,\n LogMethod,\n PublicColorName,\n TextFormatter,\n} from './types'\n\nexport default chalk\n"],"mappings":";;;AAOA,SAAgB,oBAAoB,aAA0B,SAAwC;AACpG,QAAO;EACL,MAAM,OAAe,SAAuB;AAC1C,OAAI,CAAC,SAAS,CACZ;AACF,eAAY,IACV,MAAM,MAAM,OAAO,QAAQ,IAC3B,yGACA,wGACD;;EAEH,MAAM,KAAmB;AACvB,OAAI,CAAC,IACH;AACF,OAAI,CAAC,SAAS,CACZ;AACF,eAAY,IACV,OACA,yDAAyD,I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I,MAA8B;AAChC,SAAM,KAAK,KAAK;AAChB,UAAO;;EAEV;AAED,QAAO;;;;;AC3ET,MAAa,QAAQ,aAAa;AAoBlC,kBAAe"}
package/dist/index.d.cts CHANGED
@@ -11,22 +11,30 @@ type FormattedText = [template: `%c${string}`, ...styles: string[]];
11
11
  type ColorName = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray';
12
12
  type PublicColorName = Exclude<ColorName, 'gray'>;
13
13
  type ColorMap = Readonly<Record<ColorName, string>>;
14
- type CustomColorMap = Readonly<Record<string, string>>;
14
+ type ChalkMode = 'foreground' | 'background';
15
15
  type DebugPredicate = () => boolean;
16
16
  interface LogLevelDefinition {
17
17
  name: string;
18
18
  label: string;
19
- color: ColorName | string;
19
+ color: ColorName;
20
20
  method: ConsoleMethodName;
21
21
  }
22
22
  interface CreateChalkOptions {
23
23
  console?: ConsoleLike;
24
+ mode?: ChalkMode;
24
25
  isDebug?: boolean | DebugPredicate;
25
- colors?: CustomColorMap;
26
26
  logLevels?: readonly LogLevelDefinition[];
27
27
  }
28
28
  type TextFormatter = (text: string) => FormattedText;
29
29
  type LogMethod = (message: string, ...args: unknown[]) => void;
30
+ interface LogHookContext {
31
+ level: string;
32
+ label: string;
33
+ message: string;
34
+ args: unknown[];
35
+ isDebug: boolean;
36
+ }
37
+ type LogHook = (ctx: LogHookContext) => void;
30
38
  interface ChalkInstance {
31
39
  add: (...items: readonly FormattedText[]) => FormattedText;
32
40
  bold: TextFormatter;
@@ -56,8 +64,7 @@ interface ChalkInstance {
56
64
  bgMagenta: TextFormatter;
57
65
  bgCyan: TextFormatter;
58
66
  bgWhite: TextFormatter;
59
- color: (name: string, text: string) => FormattedText;
60
- bgColor: (name: string, text: string) => FormattedText;
67
+ use: (hook: LogHook) => ChalkInstance;
61
68
  }
62
69
  //#endregion
63
70
  //#region src/create.d.ts
@@ -69,19 +76,16 @@ declare function add(...items: readonly FormattedText[]): FormattedText;
69
76
  //#endregion
70
77
  //#region src/colors.d.ts
71
78
  /**
72
- * Catppuccin Mocha palette — https://catppuccin.com/palette/
79
+ * Catppuccin Macchiato palette — https://catppuccin.com/palette/
73
80
  */
74
81
  declare const DEFAULT_COLORS: ColorMap;
75
- type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>;
76
- declare function createColorMap(customColors?: CustomColorMap): ResolvedColorMap;
77
82
  declare function resolveColor(colors: Readonly<Record<string, string>>, name: string): string;
78
83
  declare function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string;
79
84
  declare function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string;
85
+ declare function getStyle(colors: Readonly<Record<string, string>>, name: string, mode: ChalkMode): string;
80
86
  //#endregion
81
87
  //#region src/index.d.ts
82
88
  declare const chalk: ChalkInstance;
83
- declare function color(name: string, text: string): FormattedText;
84
- declare function bgColor(name: string, text: string): FormattedText;
85
89
  //#endregion
86
- export { type ChalkInstance, type ColorMap, type ColorName, type ConsoleLike, type CreateChalkOptions, type CustomColorMap, DEFAULT_COLORS, type FormattedText, type LogLevelDefinition, type LogMethod, type PublicColorName, type TextFormatter, add, bgColor, bold, chalk, chalk as default, color, createChalk, createColorMap, getBackgroundStyle, getForegroundStyle, resolveColor };
90
+ export { type ChalkInstance, type ChalkMode, type ColorMap, type ColorName, type ConsoleLike, type CreateChalkOptions, DEFAULT_COLORS, type FormattedText, type LogHook, type LogHookContext, type LogLevelDefinition, type LogMethod, type PublicColorName, type TextFormatter, add, bold, chalk, chalk as default, createChalk, getBackgroundStyle, getForegroundStyle, getStyle, resolveColor };
87
91
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -11,22 +11,30 @@ type FormattedText = [template: `%c${string}`, ...styles: string[]];
11
11
  type ColorName = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray';
12
12
  type PublicColorName = Exclude<ColorName, 'gray'>;
13
13
  type ColorMap = Readonly<Record<ColorName, string>>;
14
- type CustomColorMap = Readonly<Record<string, string>>;
14
+ type ChalkMode = 'foreground' | 'background';
15
15
  type DebugPredicate = () => boolean;
16
16
  interface LogLevelDefinition {
17
17
  name: string;
18
18
  label: string;
19
- color: ColorName | string;
19
+ color: ColorName;
20
20
  method: ConsoleMethodName;
21
21
  }
22
22
  interface CreateChalkOptions {
23
23
  console?: ConsoleLike;
24
+ mode?: ChalkMode;
24
25
  isDebug?: boolean | DebugPredicate;
25
- colors?: CustomColorMap;
26
26
  logLevels?: readonly LogLevelDefinition[];
27
27
  }
28
28
  type TextFormatter = (text: string) => FormattedText;
29
29
  type LogMethod = (message: string, ...args: unknown[]) => void;
30
+ interface LogHookContext {
31
+ level: string;
32
+ label: string;
33
+ message: string;
34
+ args: unknown[];
35
+ isDebug: boolean;
36
+ }
37
+ type LogHook = (ctx: LogHookContext) => void;
30
38
  interface ChalkInstance {
31
39
  add: (...items: readonly FormattedText[]) => FormattedText;
32
40
  bold: TextFormatter;
@@ -56,8 +64,7 @@ interface ChalkInstance {
56
64
  bgMagenta: TextFormatter;
57
65
  bgCyan: TextFormatter;
58
66
  bgWhite: TextFormatter;
59
- color: (name: string, text: string) => FormattedText;
60
- bgColor: (name: string, text: string) => FormattedText;
67
+ use: (hook: LogHook) => ChalkInstance;
61
68
  }
62
69
  //#endregion
63
70
  //#region src/create.d.ts
@@ -69,19 +76,16 @@ declare function add(...items: readonly FormattedText[]): FormattedText;
69
76
  //#endregion
70
77
  //#region src/colors.d.ts
71
78
  /**
72
- * Catppuccin Mocha palette — https://catppuccin.com/palette/
79
+ * Catppuccin Macchiato palette — https://catppuccin.com/palette/
73
80
  */
74
81
  declare const DEFAULT_COLORS: ColorMap;
75
- type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>;
76
- declare function createColorMap(customColors?: CustomColorMap): ResolvedColorMap;
77
82
  declare function resolveColor(colors: Readonly<Record<string, string>>, name: string): string;
78
83
  declare function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string;
79
84
  declare function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string;
85
+ declare function getStyle(colors: Readonly<Record<string, string>>, name: string, mode: ChalkMode): string;
80
86
  //#endregion
81
87
  //#region src/index.d.ts
82
88
  declare const chalk: ChalkInstance;
83
- declare function color(name: string, text: string): FormattedText;
84
- declare function bgColor(name: string, text: string): FormattedText;
85
89
  //#endregion
86
- export { type ChalkInstance, type ColorMap, type ColorName, type ConsoleLike, type CreateChalkOptions, type CustomColorMap, DEFAULT_COLORS, type FormattedText, type LogLevelDefinition, type LogMethod, type PublicColorName, type TextFormatter, add, bgColor, bold, chalk, chalk as default, color, createChalk, createColorMap, getBackgroundStyle, getForegroundStyle, resolveColor };
90
+ export { type ChalkInstance, type ChalkMode, type ColorMap, type ColorName, type ConsoleLike, type CreateChalkOptions, DEFAULT_COLORS, type FormattedText, type LogHook, type LogHookContext, type LogLevelDefinition, type LogMethod, type PublicColorName, type TextFormatter, add, bold, chalk, chalk as default, createChalk, getBackgroundStyle, getForegroundStyle, getStyle, resolveColor };
87
91
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,67 +1,9 @@
1
- //#region src/colors.ts
2
- /**
3
- * Catppuccin Mocha palette — https://catppuccin.com/palette/
4
- */
5
- const DEFAULT_COLORS = {
6
- black: "#1e1e2e",
7
- red: "#f38ba8",
8
- green: "#a6e3a1",
9
- yellow: "#f9e2af",
10
- blue: "#89b4fa",
11
- magenta: "#cba6f7",
12
- cyan: "#94e2d5",
13
- white: "#cdd6f4",
14
- gray: "#6c7086"
15
- };
16
- /**
17
- * Colors that are dark enough to not need a background on dark consoles.
18
- * All other built-in Catppuccin Mocha colors are pastel and need a subtle bg.
19
- */
20
- const DARK_FG_COLORS = {
21
- black: true,
22
- gray: true
23
- };
24
- function createColorMap(customColors = {}) {
25
- return {
26
- ...DEFAULT_COLORS,
27
- ...customColors
28
- };
29
- }
30
- function resolveColor(colors, name) {
31
- const color$2 = colors[name];
32
- if (color$2 === void 0) throw new Error(`Unknown chalk color: ${name}`);
33
- return color$2;
34
- }
35
- /** Returns true when the color is bright enough to need a background in dark consoles. */
36
- function needsBackground(colors, name) {
37
- if (DARK_FG_COLORS[name]) return false;
38
- const hex = colors[name];
39
- if (!hex) return true;
40
- return getRelativeLuminance(hex) > .18;
41
- }
42
- function getRelativeLuminance(hex) {
43
- const h = hex.replace("#", "");
44
- const r = Number.parseInt(h.slice(0, 2), 16) / 255;
45
- const g = Number.parseInt(h.slice(2, 4), 16) / 255;
46
- const b = Number.parseInt(h.slice(4, 6), 16) / 255;
47
- return .2126 * r + .7152 * g + .0722 * b;
48
- }
49
- function getForegroundStyle(colors, name) {
50
- const parts = [`color:${resolveColor(colors, name)}`];
51
- if (needsBackground(colors, name)) parts.push("background:rgba(0,0,0,0.15)", "padding:0 2px", "border-radius:2px");
52
- return parts.join(";");
53
- }
54
- function getBackgroundStyle(colors, name) {
55
- return `padding: 2px 4px; border-radius: 3px; color: #1e1e2e; font-weight: bold; background:${resolveColor(colors, name)};`;
56
- }
57
-
58
- //#endregion
59
1
  //#region src/banner.ts
60
2
  function createBannerMethods(consoleLike, isDebug) {
61
3
  return {
62
4
  hello(title, version) {
63
5
  if (!isDebug()) return;
64
- consoleLike.log(`%c ${title} %c V${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #cdd6f4; background: #45475a; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #1e1e2e; background: #a6e3a1; font-weight: bold;");
6
+ consoleLike.log(`%c ${title} %c V${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #cad3f5; background: #494d64; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #24273a; background: #a6da95; font-weight: bold;");
65
7
  },
66
8
  image(url) {
67
9
  if (!url) return;
@@ -71,16 +13,45 @@ function createBannerMethods(consoleLike, isDebug) {
71
13
  };
72
14
  }
73
15
 
16
+ //#endregion
17
+ //#region src/colors.ts
18
+ /**
19
+ * Catppuccin Macchiato palette — https://catppuccin.com/palette/
20
+ */
21
+ const DEFAULT_COLORS = {
22
+ black: "#24273a",
23
+ red: "#ed8796",
24
+ green: "#a6da95",
25
+ yellow: "#eed49f",
26
+ blue: "#8aadf4",
27
+ magenta: "#c6a0f6",
28
+ cyan: "#8bd5ca",
29
+ white: "#cad3f5",
30
+ gray: "#6e738d"
31
+ };
32
+ function resolveColor(colors, name) {
33
+ const color = colors[name];
34
+ if (color === void 0) throw new Error(`Unknown chalk color: ${name}`);
35
+ return color;
36
+ }
37
+ function getForegroundStyle(colors, name) {
38
+ return `color:${resolveColor(colors, name)}`;
39
+ }
40
+ function getBackgroundStyle(colors, name) {
41
+ const hex = resolveColor(colors, name);
42
+ return `padding: 2px 4px; border-radius: 3px; color: ${name === "black" ? colors.blue ?? "#8aadf4" : "#24273a"}; font-weight: bold; background:${hex};`;
43
+ }
44
+ function getStyle(colors, name, mode) {
45
+ return mode === "background" ? getBackgroundStyle(colors, name) : getForegroundStyle(colors, name);
46
+ }
47
+
74
48
  //#endregion
75
49
  //#region src/format.ts
76
50
  function formatText(text, style) {
77
51
  return [`%c${text}`, style];
78
52
  }
79
- function color$1(colors, name, text) {
80
- return formatText(text, getForegroundStyle(colors, name));
81
- }
82
- function bgColor$1(colors, name, text) {
83
- return formatText(text, getBackgroundStyle(colors, name));
53
+ function coloredText(name, text, mode) {
54
+ return formatText(text, getStyle(DEFAULT_COLORS, name, mode));
84
55
  }
85
56
  function bold(text) {
86
57
  return formatText(text, "font-weight: bold;");
@@ -145,18 +116,30 @@ const DEFAULT_LOG_LEVELS = [
145
116
  function getConsoleMethod(consoleLike, method) {
146
117
  return consoleLike[method] ?? consoleLike.log;
147
118
  }
148
- function createLogMethod(consoleLike, colors, isDebug, level) {
119
+ function createLogMethod(consoleLike, isDebug, level, mode, getHooks) {
149
120
  return (message, ...args) => {
150
- if (!isDebug()) return;
151
- const method = getConsoleMethod(consoleLike, level.method);
152
- const labelStyle = `${getForegroundStyle(colors, level.color)};font-weight: bold;`;
153
- const messageStyle = getForegroundStyle(colors, level.color);
154
- method(`%c[${level.label}]%c ${message}`, labelStyle, messageStyle, ...args);
121
+ const debugValue = isDebug();
122
+ if (debugValue) {
123
+ const method = getConsoleMethod(consoleLike, level.method);
124
+ const style = getStyle(DEFAULT_COLORS, level.color, mode);
125
+ method(`%c[${level.label}]%c ${message}`, style, style, ...args);
126
+ }
127
+ const hooks = getHooks();
128
+ if (hooks.length > 0) {
129
+ const ctx = {
130
+ level: level.name,
131
+ label: level.label,
132
+ message,
133
+ args,
134
+ isDebug: debugValue
135
+ };
136
+ for (const hook of hooks) hook(ctx);
137
+ }
155
138
  };
156
139
  }
157
140
  function createLoggerMethods(options) {
158
141
  const levels = options.logLevels ?? DEFAULT_LOG_LEVELS;
159
- return Object.fromEntries(levels.map((level) => [level.name, createLogMethod(options.console, options.colors, options.isDebug, level)]));
142
+ return Object.fromEntries(levels.map((level) => [level.name, createLogMethod(options.console, options.isDebug, level, options.mode, options.getHooks)]));
160
143
  }
161
144
 
162
145
  //#endregion
@@ -175,37 +158,40 @@ function resolveDebugPredicate(isDebug) {
175
158
  }
176
159
  function createChalk(options = {}) {
177
160
  const consoleLike = resolveConsole(options.console);
178
- const colors = createColorMap(options.colors);
161
+ const mode = options.mode ?? "background";
179
162
  const isDebug = resolveDebugPredicate(options.isDebug);
180
163
  const banner = createBannerMethods(consoleLike, isDebug);
164
+ const hooks = [];
165
+ const getHooks = () => hooks;
181
166
  const loggers = createLoggerMethods({
182
167
  console: consoleLike,
183
- colors,
168
+ mode,
184
169
  isDebug,
185
- logLevels: options.logLevels
170
+ logLevels: options.logLevels,
171
+ getHooks
186
172
  });
187
- return {
173
+ const fg = (name) => (text) => coloredText(name, text, "foreground");
174
+ const bg = (name) => (text) => coloredText(name, text, "background");
175
+ const instance = {
188
176
  add,
189
177
  bold,
190
178
  ...banner,
191
- black: (text) => color$1(colors, "black", text),
192
- red: (text) => color$1(colors, "red", text),
193
- green: (text) => color$1(colors, "green", text),
194
- yellow: (text) => color$1(colors, "yellow", text),
195
- blue: (text) => color$1(colors, "blue", text),
196
- magenta: (text) => color$1(colors, "magenta", text),
197
- cyan: (text) => color$1(colors, "cyan", text),
198
- white: (text) => color$1(colors, "white", text),
199
- bgBlack: (text) => bgColor$1(colors, "black", text),
200
- bgRed: (text) => bgColor$1(colors, "red", text),
201
- bgGreen: (text) => bgColor$1(colors, "green", text),
202
- bgYellow: (text) => bgColor$1(colors, "yellow", text),
203
- bgBlue: (text) => bgColor$1(colors, "blue", text),
204
- bgMagenta: (text) => bgColor$1(colors, "magenta", text),
205
- bgCyan: (text) => bgColor$1(colors, "cyan", text),
206
- bgWhite: (text) => bgColor$1(colors, "white", text),
207
- color: (name, text) => color$1(colors, name, text),
208
- bgColor: (name, text) => bgColor$1(colors, name, text),
179
+ black: fg("black"),
180
+ red: fg("red"),
181
+ green: fg("green"),
182
+ yellow: fg("yellow"),
183
+ blue: fg("blue"),
184
+ magenta: fg("magenta"),
185
+ cyan: fg("cyan"),
186
+ white: fg("white"),
187
+ bgBlack: bg("black"),
188
+ bgRed: bg("red"),
189
+ bgGreen: bg("green"),
190
+ bgYellow: bg("yellow"),
191
+ bgBlue: bg("blue"),
192
+ bgMagenta: bg("magenta"),
193
+ bgCyan: bg("cyan"),
194
+ bgWhite: bg("white"),
209
195
  log: loggers.log,
210
196
  wait: loggers.wait,
211
197
  error: loggers.error,
@@ -213,22 +199,20 @@ function createChalk(options = {}) {
213
199
  ready: loggers.ready,
214
200
  info: loggers.info,
215
201
  event: loggers.event,
216
- debug: loggers.debug
202
+ debug: loggers.debug,
203
+ use(hook) {
204
+ hooks.push(hook);
205
+ return instance;
206
+ }
217
207
  };
208
+ return instance;
218
209
  }
219
210
 
220
211
  //#endregion
221
212
  //#region src/index.ts
222
- const defaultColors = createColorMap();
223
213
  const chalk = createChalk();
224
- function color(name, text) {
225
- return color$1(defaultColors, name, text);
226
- }
227
- function bgColor(name, text) {
228
- return bgColor$1(defaultColors, name, text);
229
- }
230
214
  var src_default = chalk;
231
215
 
232
216
  //#endregion
233
- export { DEFAULT_COLORS, add, bgColor, bold, chalk, color, createChalk, createColorMap, src_default as default, getBackgroundStyle, getForegroundStyle, resolveColor };
217
+ export { DEFAULT_COLORS, add, bold, chalk, createChalk, src_default as default, getBackgroundStyle, getForegroundStyle, getStyle, resolveColor };
234
218
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["DEFAULT_COLORS: ColorMap","DARK_FG_COLORS: Record<string, true>","color","color","bgColor","noopConsole: ConsoleLike","color","bgColor","colorWithMap","bgColorWithMap"],"sources":["../src/colors.ts","../src/banner.ts","../src/format.ts","../src/logger.ts","../src/create.ts","../src/index.ts"],"sourcesContent":["import type { ColorMap, CustomColorMap } from './types'\n\n/**\n * Catppuccin Mocha palette — https://catppuccin.com/palette/\n */\nexport const DEFAULT_COLORS: ColorMap = {\n black: '#1e1e2e', // Base\n red: '#f38ba8', // Red\n green: '#a6e3a1', // Green\n yellow: '#f9e2af', // Yellow\n blue: '#89b4fa', // Blue\n magenta: '#cba6f7', // Mauve\n cyan: '#94e2d5', // Teal\n white: '#cdd6f4', // Text\n gray: '#6c7086', // Overlay0\n}\n\n/**\n * Colors that are dark enough to not need a background on dark consoles.\n * All other built-in Catppuccin Mocha colors are pastel and need a subtle bg.\n */\nexport const DARK_FG_COLORS: Record<string, true> = { black: true, gray: true }\n\nexport type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>\n\nexport function createColorMap(customColors: CustomColorMap = {} as CustomColorMap): ResolvedColorMap {\n return {\n ...DEFAULT_COLORS,\n ...customColors,\n }\n}\n\nexport function resolveColor(colors: Readonly<Record<string, string>>, name: string): string {\n const color = colors[name]\n if (color === undefined)\n throw new Error(`Unknown chalk color: ${name}`)\n return color\n}\n\n/** Returns true when the color is bright enough to need a background in dark consoles. */\nfunction needsBackground(colors: Readonly<Record<string, string>>, name: string): boolean {\n if (DARK_FG_COLORS[name])\n return false\n const hex = colors[name]\n if (!hex)\n return true\n return getRelativeLuminance(hex) > 0.18\n}\n\nfunction getRelativeLuminance(hex: string): number {\n const h = hex.replace('#', '')\n const r = Number.parseInt(h.slice(0, 2), 16) / 255\n const g = Number.parseInt(h.slice(2, 4), 16) / 255\n const b = Number.parseInt(h.slice(4, 6), 16) / 255\n return 0.2126 * r + 0.7152 * g + 0.0722 * b\n}\n\nexport function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const hex = resolveColor(colors, name)\n const parts = [`color:${hex}`]\n if (needsBackground(colors, name))\n parts.push('background:rgba(0,0,0,0.15)', 'padding:0 2px', 'border-radius:2px')\n return parts.join(';')\n}\n\nexport function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const hex = resolveColor(colors, name)\n const textColor = '#1e1e2e'\n return `padding: 2px 4px; border-radius: 3px; color: ${textColor}; font-weight: bold; background:${hex};`\n}\n","import type { ConsoleLike, DebugPredicate } from './types'\n\nexport interface BannerMethods {\n hello: (title: string, version: string) => void\n image: (url: string) => void\n}\n\nexport function createBannerMethods(consoleLike: ConsoleLike, isDebug: DebugPredicate): BannerMethods {\n return {\n hello(title: string, version: string): void {\n if (!isDebug())\n return\n consoleLike.log(\n `%c ${title} %c V${version} `,\n 'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #cdd6f4; background: #45475a; font-weight: bold;',\n 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #1e1e2e; background: #a6e3a1; font-weight: bold;',\n )\n },\n image(url: string): void {\n if (!url)\n return\n if (!isDebug())\n return\n consoleLike.log(\n '%c ',\n `font-size: 1px; padding: 100px 100px; background: url(${url}) no-repeat center / contain; color: transparent;`,\n )\n },\n }\n}\n","import type { FormattedText } from './types'\nimport { getBackgroundStyle, getForegroundStyle } from './colors'\n\nexport function formatText(text: string, style: string): FormattedText {\n return [`%c${text}`, style]\n}\n\nexport function color(colors: Readonly<Record<string, string>>, name: string, text: string): FormattedText {\n return formatText(text, getForegroundStyle(colors, name))\n}\n\nexport function bgColor(colors: Readonly<Record<string, string>>, name: string, text: string): FormattedText {\n return formatText(text, getBackgroundStyle(colors, name))\n}\n\nexport function bold(text: string): FormattedText {\n return formatText(text, 'font-weight: bold;')\n}\n\nexport function add(...items: readonly FormattedText[]): FormattedText {\n if (items.length === 0)\n return ['%c', '']\n const template = items.map(item => ` ${item[0]}`).join('')\n const styles = items.flatMap(([, ...itemStyles]) => itemStyles)\n return [template, ...styles] as FormattedText\n}\n","import type { ConsoleLike, ConsoleMethodName, DebugPredicate, LogLevelDefinition, LogMethod } from './types'\nimport { getForegroundStyle } from './colors'\n\nexport const DEFAULT_LOG_LEVELS = [\n { name: 'log', label: 'Log', color: 'black', method: 'log' },\n { name: 'wait', label: 'Wait', color: 'cyan', method: 'log' },\n { name: 'error', label: 'Error', color: 'red', method: 'error' },\n { name: 'warn', label: 'Warn', color: 'yellow', method: 'warn' },\n { name: 'ready', label: 'Ready', color: 'green', method: 'log' },\n { name: 'info', label: 'Info', color: 'blue', method: 'info' },\n { name: 'event', label: 'Event', color: 'magenta', method: 'log' },\n { name: 'debug', label: 'Debug', color: 'gray', method: 'debug' },\n] satisfies readonly LogLevelDefinition[]\n\nexport interface CreateLoggerMethodsOptions {\n console: ConsoleLike\n colors: Readonly<Record<string, string>>\n isDebug: DebugPredicate\n logLevels?: readonly LogLevelDefinition[]\n}\n\nfunction getConsoleMethod(consoleLike: ConsoleLike, method: ConsoleMethodName): (...data: unknown[]) => void {\n return consoleLike[method] ?? consoleLike.log\n}\n\nfunction createLogMethod(\n consoleLike: ConsoleLike,\n colors: Readonly<Record<string, string>>,\n isDebug: DebugPredicate,\n level: LogLevelDefinition,\n): LogMethod {\n return (message: string, ...args: unknown[]): void => {\n if (!isDebug())\n return\n const method = getConsoleMethod(consoleLike, level.method)\n const labelStyle = `${getForegroundStyle(colors, level.color)};font-weight: bold;`\n const messageStyle = getForegroundStyle(colors, level.color)\n method(`%c[${level.label}]%c ${message}`, labelStyle, messageStyle, ...args)\n }\n}\n\nexport function createLoggerMethods(options: CreateLoggerMethodsOptions): Record<string, LogMethod> {\n const levels = options.logLevels ?? DEFAULT_LOG_LEVELS\n return Object.fromEntries(\n levels.map(level => [\n level.name,\n createLogMethod(options.console, options.colors, options.isDebug, level),\n ]),\n )\n}\n","import type { ChalkInstance, ConsoleLike, CreateChalkOptions, DebugPredicate } from './types'\nimport { createBannerMethods } from './banner'\nimport { createColorMap } from './colors'\nimport { add, bgColor, bold, color } from './format'\nimport { createLoggerMethods } from './logger'\n\nconst noopConsole: ConsoleLike = {\n log: () => {},\n}\n\nfunction readGlobalDebugFlag(): boolean {\n return Object.prototype.hasOwnProperty.call(globalThis, 'alitadebug')\n && Boolean(globalThis.alitadebug)\n}\n\nfunction resolveConsole(consoleLike: ConsoleLike | undefined): ConsoleLike {\n return consoleLike ?? globalThis.console ?? noopConsole\n}\n\nfunction resolveDebugPredicate(isDebug: CreateChalkOptions['isDebug']): DebugPredicate {\n if (typeof isDebug === 'function')\n return isDebug\n if (typeof isDebug === 'boolean')\n return () => isDebug\n return readGlobalDebugFlag\n}\n\nexport function createChalk(options: CreateChalkOptions = {}): ChalkInstance {\n const consoleLike = resolveConsole(options.console)\n const colors = createColorMap(options.colors)\n const isDebug = resolveDebugPredicate(options.isDebug)\n const banner = createBannerMethods(consoleLike, isDebug)\n const loggers = createLoggerMethods({\n console: consoleLike,\n colors,\n isDebug,\n logLevels: options.logLevels,\n })\n\n return {\n add,\n bold,\n ...banner,\n black: text => color(colors, 'black', text),\n red: text => color(colors, 'red', text),\n green: text => color(colors, 'green', text),\n yellow: text => color(colors, 'yellow', text),\n blue: text => color(colors, 'blue', text),\n magenta: text => color(colors, 'magenta', text),\n cyan: text => color(colors, 'cyan', text),\n white: text => color(colors, 'white', text),\n bgBlack: text => bgColor(colors, 'black', text),\n bgRed: text => bgColor(colors, 'red', text),\n bgGreen: text => bgColor(colors, 'green', text),\n bgYellow: text => bgColor(colors, 'yellow', text),\n bgBlue: text => bgColor(colors, 'blue', text),\n bgMagenta: text => bgColor(colors, 'magenta', text),\n bgCyan: text => bgColor(colors, 'cyan', text),\n bgWhite: text => bgColor(colors, 'white', text),\n color: (name, text) => color(colors, name, text),\n bgColor: (name, text) => bgColor(colors, name, text),\n log: loggers.log,\n wait: loggers.wait,\n error: loggers.error,\n warn: loggers.warn,\n ready: loggers.ready,\n info: loggers.info,\n event: loggers.event,\n debug: loggers.debug,\n }\n}\n","import { createColorMap } from './colors'\nimport { createChalk } from './create'\nimport { add, bgColor as bgColorWithMap, bold, color as colorWithMap } from './format'\n\nconst defaultColors = createColorMap()\n\nexport const chalk = createChalk()\n\nexport { add, bold, createChalk }\nexport { createColorMap, DEFAULT_COLORS, getBackgroundStyle, getForegroundStyle, resolveColor } from './colors'\nexport type {\n ChalkInstance,\n ColorMap,\n ColorName,\n ConsoleLike,\n CreateChalkOptions,\n CustomColorMap,\n FormattedText,\n LogLevelDefinition,\n LogMethod,\n PublicColorName,\n TextFormatter,\n} from './types'\n\nexport function color(name: string, text: string) {\n return colorWithMap(defaultColors, name, text)\n}\n\nexport function bgColor(name: string, text: string) {\n return bgColorWithMap(defaultColors, name, text)\n}\n\nexport default chalk\n"],"mappings":";;;;AAKA,MAAaA,iBAA2B;CACtC,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,MAAM;CACP;;;;;AAMD,MAAaC,iBAAuC;CAAE,OAAO;CAAM,MAAM;CAAM;AAI/E,SAAgB,eAAe,eAA+B,EAAE,EAAsC;AACpG,QAAO;EACL,GAAG;EACH,GAAG;EACJ;;AAGH,SAAgB,aAAa,QAA0C,MAAsB;CAC3F,MAAMC,UAAQ,OAAO;AACrB,KAAIA,YAAU,OACZ,OAAM,IAAI,MAAM,wBAAwB,OAAO;AACjD,QAAOA;;;AAIT,SAAS,gBAAgB,QAA0C,MAAuB;AACxF,KAAI,eAAe,MACjB,QAAO;CAC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K;EAC/C,QAAO,SAAQA,UAAQ,QAAQ,OAAO,KAAK;EAC3C,UAAS,SAAQA,UAAQ,QAAQ,SAAS,KAAK;EAC/C,WAAU,SAAQA,UAAQ,QAAQ,UAAU,KAAK;EACjD,SAAQ,SAAQA,UAAQ,QAAQ,QAAQ,KAAK;EAC7C,YAAW,SAAQA,UAAQ,QAAQ,WAAW,KAAK;EACnD,SAAQ,SAAQA,UAAQ,QAAQ,QAAQ,KAAK;EAC7C,UAAS,SAAQA,UAAQ,QAAQ,SAAS,KAAK;EAC/C,QAAQ,MAAM,SAASD,QAAM,QAAQ,MAAM,KAAK;EAChD,UAAU,MAAM,SAASC,UAAQ,QAAQ,MAAM,KAAK;EACpD,KAAK,QAAQ;EACb,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,OAAO,QAAQ;EAChB;;;;;ACjEH,MAAM,gBAAgB,gBAAgB;AAEtC,MAAa,QAAQ,aAAa;AAkBlC,SAAgB,MAAM,MAAc,MAAc;AAChD,QAAOC,QAAa,eAAe,MAAM,KAAK;;AAGhD,SAAgB,QAAQ,MAAc,MAAc;AAClD,QAAOC,UAAe,eAAe,MAAM,KAAK;;AAGlD,kBAAe"}
1
+ {"version":3,"file":"index.mjs","names":["DEFAULT_COLORS: ColorMap","ctx: LogHookContext","noopConsole: ConsoleLike","hooks: LogHook[]","instance: ChalkInstance"],"sources":["../src/banner.ts","../src/colors.ts","../src/format.ts","../src/logger.ts","../src/create.ts","../src/index.ts"],"sourcesContent":["import type { ConsoleLike, DebugPredicate } from './types'\n\nexport interface BannerMethods {\n hello: (title: string, version: string) => void\n image: (url: string) => void\n}\n\nexport function createBannerMethods(consoleLike: ConsoleLike, isDebug: DebugPredicate): BannerMethods {\n return {\n hello(title: string, version: string): void {\n if (!isDebug())\n return\n consoleLike.log(\n `%c ${title} %c V${version} `,\n 'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #cad3f5; background: #494d64; font-weight: bold;',\n 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #24273a; background: #a6da95; font-weight: bold;',\n )\n },\n image(url: string): void {\n if (!url)\n return\n if (!isDebug())\n return\n consoleLike.log(\n '%c ',\n `font-size: 1px; padding: 100px 100px; background: url(${url}) no-repeat center / contain; color: transparent;`,\n )\n },\n }\n}\n","import type { ChalkMode, ColorMap } from './types'\n\n/**\n * Catppuccin Macchiato palette — https://catppuccin.com/palette/\n */\nexport const DEFAULT_COLORS: ColorMap = {\n black: '#24273a', // Base\n red: '#ed8796', // Red\n green: '#a6da95', // Green\n yellow: '#eed49f', // Yellow\n blue: '#8aadf4', // Blue\n magenta: '#c6a0f6', // Mauve\n cyan: '#8bd5ca', // Teal\n white: '#cad3f5', // Text\n gray: '#6e738d', // Overlay0\n}\n\nexport function resolveColor(colors: Readonly<Record<string, string>>, name: string): string {\n const color = colors[name]\n if (color === undefined)\n throw new Error(`Unknown chalk color: ${name}`)\n return color\n}\n\nexport function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const hex = resolveColor(colors, name)\n return `color:${hex}`\n}\n\nexport function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const hex = resolveColor(colors, name)\n const textColor = name === 'black' ? (colors.blue ?? '#8aadf4') : '#24273a'\n return `padding: 2px 4px; border-radius: 3px; color: ${textColor}; font-weight: bold; background:${hex};`\n}\n\nexport function getStyle(colors: Readonly<Record<string, string>>, name: string, mode: ChalkMode): string {\n return mode === 'background'\n ? getBackgroundStyle(colors, name)\n : getForegroundStyle(colors, name)\n}\n","import type { ChalkMode, FormattedText } from './types'\nimport { DEFAULT_COLORS, getStyle } from './colors'\n\nexport function formatText(text: string, style: string): FormattedText {\n return [`%c${text}`, style]\n}\n\nexport function coloredText(name: string, text: string, mode: ChalkMode): FormattedText {\n return formatText(text, getStyle(DEFAULT_COLORS, name, mode))\n}\n\nexport function bold(text: string): FormattedText {\n return formatText(text, 'font-weight: bold;')\n}\n\nexport function add(...items: readonly FormattedText[]): FormattedText {\n if (items.length === 0)\n return ['%c', '']\n const template = items.map(item => ` ${item[0]}`).join('')\n const styles = items.flatMap(([, ...itemStyles]) => itemStyles)\n return [template, ...styles] as FormattedText\n}\n","import type { ChalkMode, ConsoleLike, ConsoleMethodName, DebugPredicate, LogHook, LogHookContext, LogLevelDefinition, LogMethod } from './types'\nimport { DEFAULT_COLORS, getStyle } from './colors'\n\nexport const DEFAULT_LOG_LEVELS = [\n { name: 'log', label: 'Log', color: 'black', method: 'log' },\n { name: 'wait', label: 'Wait', color: 'cyan', method: 'log' },\n { name: 'error', label: 'Error', color: 'red', method: 'error' },\n { name: 'warn', label: 'Warn', color: 'yellow', method: 'warn' },\n { name: 'ready', label: 'Ready', color: 'green', method: 'log' },\n { name: 'info', label: 'Info', color: 'blue', method: 'info' },\n { name: 'event', label: 'Event', color: 'magenta', method: 'log' },\n { name: 'debug', label: 'Debug', color: 'gray', method: 'debug' },\n] satisfies readonly LogLevelDefinition[]\n\nexport interface CreateLoggerMethodsOptions {\n console: ConsoleLike\n mode: ChalkMode\n isDebug: DebugPredicate\n logLevels?: readonly LogLevelDefinition[]\n getHooks: () => readonly LogHook[]\n}\n\nfunction getConsoleMethod(consoleLike: ConsoleLike, method: ConsoleMethodName): (...data: unknown[]) => void {\n return consoleLike[method] ?? consoleLike.log\n}\n\nfunction createLogMethod(\n consoleLike: ConsoleLike,\n isDebug: DebugPredicate,\n level: LogLevelDefinition,\n mode: ChalkMode,\n getHooks: () => readonly LogHook[],\n): LogMethod {\n return (message: string, ...args: unknown[]): void => {\n const debugValue = isDebug()\n\n if (debugValue) {\n const method = getConsoleMethod(consoleLike, level.method)\n const style = getStyle(DEFAULT_COLORS, level.color, mode)\n method(`%c[${level.label}]%c ${message}`, style, style, ...args)\n }\n\n const hooks = getHooks()\n if (hooks.length > 0) {\n const ctx: LogHookContext = {\n level: level.name,\n label: level.label,\n message,\n args,\n isDebug: debugValue,\n }\n for (const hook of hooks) {\n hook(ctx)\n }\n }\n }\n}\n\nexport function createLoggerMethods(options: CreateLoggerMethodsOptions): Record<string, LogMethod> {\n const levels = options.logLevels ?? DEFAULT_LOG_LEVELS\n return Object.fromEntries(\n levels.map(level => [\n level.name,\n createLogMethod(options.console, options.isDebug, level, options.mode, options.getHooks),\n ]),\n )\n}\n","import type { ChalkInstance, ConsoleLike, CreateChalkOptions, DebugPredicate, LogHook } from './types'\nimport { createBannerMethods } from './banner'\nimport { add, bold, coloredText } from './format'\nimport { createLoggerMethods } from './logger'\n\nconst noopConsole: ConsoleLike = {\n log: () => {},\n}\n\nfunction readGlobalDebugFlag(): boolean {\n return Object.prototype.hasOwnProperty.call(globalThis, 'alitadebug')\n && Boolean(globalThis.alitadebug)\n}\n\nfunction resolveConsole(consoleLike: ConsoleLike | undefined): ConsoleLike {\n return consoleLike ?? globalThis.console ?? noopConsole\n}\n\nfunction resolveDebugPredicate(isDebug: CreateChalkOptions['isDebug']): DebugPredicate {\n if (typeof isDebug === 'function')\n return isDebug\n if (typeof isDebug === 'boolean')\n return () => isDebug\n return readGlobalDebugFlag\n}\n\nexport function createChalk(options: CreateChalkOptions = {}): ChalkInstance {\n const consoleLike = resolveConsole(options.console)\n const mode = options.mode ?? 'background'\n const isDebug = resolveDebugPredicate(options.isDebug)\n const banner = createBannerMethods(consoleLike, isDebug)\n const hooks: LogHook[] = []\n const getHooks = (): readonly LogHook[] => hooks\n const loggers = createLoggerMethods({\n console: consoleLike,\n mode,\n isDebug,\n logLevels: options.logLevels,\n getHooks,\n })\n\n const fg = (name: string) => (text: string) => coloredText(name, text, 'foreground')\n const bg = (name: string) => (text: string) => coloredText(name, text, 'background')\n\n const instance: ChalkInstance = {\n add,\n bold,\n ...banner,\n black: fg('black'),\n red: fg('red'),\n green: fg('green'),\n yellow: fg('yellow'),\n blue: fg('blue'),\n magenta: fg('magenta'),\n cyan: fg('cyan'),\n white: fg('white'),\n bgBlack: bg('black'),\n bgRed: bg('red'),\n bgGreen: bg('green'),\n bgYellow: bg('yellow'),\n bgBlue: bg('blue'),\n bgMagenta: bg('magenta'),\n bgCyan: bg('cyan'),\n bgWhite: bg('white'),\n log: loggers.log,\n wait: loggers.wait,\n error: loggers.error,\n warn: loggers.warn,\n ready: loggers.ready,\n info: loggers.info,\n event: loggers.event,\n debug: loggers.debug,\n use(hook: LogHook): ChalkInstance {\n hooks.push(hook)\n return instance\n },\n }\n\n return instance\n}\n","import { createChalk } from './create'\nimport { add, bold } from './format'\n\nexport const chalk = createChalk()\n\nexport { add, bold, createChalk }\nexport { DEFAULT_COLORS, getBackgroundStyle, getForegroundStyle, getStyle, resolveColor } from './colors'\nexport type {\n ChalkInstance,\n ChalkMode,\n ColorMap,\n ColorName,\n ConsoleLike,\n CreateChalkOptions,\n FormattedText,\n LogHook,\n LogHookContext,\n LogLevelDefinition,\n LogMethod,\n PublicColorName,\n TextFormatter,\n} from './types'\n\nexport default chalk\n"],"mappings":";AAOA,SAAgB,oBAAoB,aAA0B,SAAwC;AACpG,QAAO;EACL,MAAM,OAAe,SAAuB;AAC1C,OAAI,CAAC,SAAS,CACZ;AACF,eAAY,IACV,MAAM,MAAM,OAAO,QAAQ,IAC3B,yGACA,wGACD;;EAEH,MAAM,KAAmB;AACvB,OAAI,CAAC,IACH;AACF,OAAI,CAAC,SAAS,CACZ;AACF,eAAY,IACV,OACA,yDAAyD,IAAI,mDAC9D;;EAEJ;;;;;;;;ACvBH,MAAaA,iBAA2B;CACtC,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,MAAM;CACP;AAED,SAAgB,aAAa,QAA0C,MAAsB;CAC3F,MAAM,QAAQ,OAAO;AACrB,KAAI,UAAU,OACZ,OAAM,IAAI,MAAM,wBAAwB,OAAO;AACjD,QAAO;;AAGT,SAAgB,mBAAmB,QAA0C,MAAsB;AAEjG,QAAO,SADK,aAAa,QAAQ,KAAK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D,MAAM,SAAS,oBAAoB,aAAa,QAAQ;CACxD,MAAMC,QAAmB,EAAE;CAC3B,MAAM,iBAAqC;CAC3C,MAAM,UAAU,oBAAoB;EAClC,SAAS;EACT;EACA;EACA,WAAW,QAAQ;EACnB;EACD,CAAC;CAEF,MAAM,MAAM,UAAkB,SAAiB,YAAY,MAAM,MAAM,aAAa;CACpF,MAAM,MAAM,UAAkB,SAAiB,YAAY,MAAM,MAAM,aAAa;CAEpF,MAAMC,WAA0B;EAC9B;EACA;EACA,GAAG;EACH,OAAO,GAAG,QAAQ;EAClB,KAAK,GAAG,MAAM;EACd,OAAO,GAAG,QAAQ;EAClB,QAAQ,GAAG,SAAS;EACpB,MAAM,GAAG,OAAO;EAChB,SAAS,GAAG,UAAU;EACtB,MAAM,GAAG,OAAO;EAChB,OAAO,GAAG,QAAQ;EAClB,SAAS,GAAG,QAAQ;EACpB,OAAO,GAAG,MAAM;EAChB,SAAS,GAAG,QAAQ;EACpB,UAAU,GAAG,SAAS;EACtB,QAAQ,GAAG,OAAO;EAClB,WAAW,GAAG,UAAU;EACxB,QAAQ,GAAG,OAAO;EAClB,SAAS,GAAG,QAAQ;EACpB,KAAK,QAAQ;EACb,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,OAAO,QAAQ;EACf,IAAI,MAA8B;AAChC,SAAM,KAAK,KAAK;AAChB,UAAO;;EAEV;AAED,QAAO;;;;;AC3ET,MAAa,QAAQ,aAAa;AAoBlC,kBAAe"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jacob-z/chalk",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "2.0.0",
5
5
  "description": "Browser console coloring utilities compatible with alita/chalk behavior.",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,