@jacob-z/chalk 0.1.0 → 1.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 +15 -10
- package/dist/index.cjs +39 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +39 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jacob-z/chalk
|
|
2
2
|
|
|
3
|
-
Browser console coloring utilities — a modular, type-safe rewrite of `@alita/chalk
|
|
3
|
+
Browser console coloring utilities — a modular, type-safe rewrite of `@alita/chalk`, themed with [Catppuccin Mocha](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
11
|
- `bold()` text formatting
|
|
11
12
|
- `add()` for merging multiple formatted tuples
|
|
12
13
|
- Debug-gated logger methods: `log`, `wait`, `error`, `warn`, `ready`, `info`, `event`, `debug`
|
|
@@ -18,7 +19,7 @@ Browser console coloring utilities — a modular, type-safe rewrite of `@alita/c
|
|
|
18
19
|
## Install
|
|
19
20
|
|
|
20
21
|
```bash
|
|
21
|
-
pnpm add
|
|
22
|
+
pnpm add @jacob-z/chalk
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
## Basic Usage
|
|
@@ -26,19 +27,22 @@ pnpm add custom-chalk
|
|
|
26
27
|
Color formatters return `console.log`-ready tuples:
|
|
27
28
|
|
|
28
29
|
```ts
|
|
29
|
-
import chalk from '
|
|
30
|
+
import chalk from '@jacob-z/chalk'
|
|
30
31
|
|
|
31
32
|
chalk.red('text')
|
|
32
|
-
// → ['%ctext', 'color:#
|
|
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
37
|
|
|
34
38
|
chalk.bgRed('text')
|
|
35
|
-
// → ['%ctext', 'padding: 2px 4px; border-radius: 3px; color: #
|
|
39
|
+
// → ['%ctext', 'padding: 2px 4px; border-radius: 3px; color: #1e1e2e; font-weight: bold; background:#f38ba8;']
|
|
36
40
|
|
|
37
41
|
chalk.bold('text')
|
|
38
42
|
// → ['%ctext', 'font-weight: bold;']
|
|
39
43
|
|
|
40
44
|
chalk.add(chalk.red('a'), chalk.blue('b'))
|
|
41
|
-
// → [' %ca %cb', 'color:#
|
|
45
|
+
// → [' %ca %cb', 'color:#f38ba8', 'color:#89b4fa']
|
|
42
46
|
```
|
|
43
47
|
|
|
44
48
|
Use with `console.log` spread:
|
|
@@ -62,7 +66,7 @@ chalk.error('failed') // prints [Error] in red
|
|
|
62
66
|
For tests or controlled environments, use the factory:
|
|
63
67
|
|
|
64
68
|
```ts
|
|
65
|
-
import { createChalk } from '
|
|
69
|
+
import { createChalk } from '@jacob-z/chalk'
|
|
66
70
|
|
|
67
71
|
const chalk = createChalk({ console, isDebug: () => true })
|
|
68
72
|
chalk.info('loaded')
|
|
@@ -86,7 +90,7 @@ If a console method is unavailable, the logger falls back to `console.log`.
|
|
|
86
90
|
## Custom Colors
|
|
87
91
|
|
|
88
92
|
```ts
|
|
89
|
-
import { createChalk } from '
|
|
93
|
+
import { createChalk } from '@jacob-z/chalk'
|
|
90
94
|
|
|
91
95
|
const chalk = createChalk({
|
|
92
96
|
colors: { brand: '#123456' },
|
|
@@ -137,6 +141,7 @@ Design principles vs the original `@alita/chalk`:
|
|
|
137
141
|
- **No module-level side effects** — factory pattern, pure functions
|
|
138
142
|
- **No `any` / `@ts-ignore`** — strict TypeScript throughout
|
|
139
143
|
- **Modular & extensible** — custom colors, custom log levels, injected console
|
|
144
|
+
- **Dark-mode friendly** — light foreground colors get a subtle background for readability
|
|
140
145
|
|
|
141
146
|
## License
|
|
142
147
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
3
|
//#region src/colors.ts
|
|
4
|
+
/**
|
|
5
|
+
* Catppuccin Mocha palette — https://catppuccin.com/palette/
|
|
6
|
+
*/
|
|
4
7
|
const DEFAULT_COLORS = {
|
|
5
|
-
black: "#
|
|
6
|
-
red: "#
|
|
7
|
-
green: "#
|
|
8
|
-
yellow: "#
|
|
9
|
-
blue: "#
|
|
10
|
-
magenta: "#
|
|
11
|
-
cyan: "#
|
|
12
|
-
white: "#
|
|
13
|
-
gray: "#
|
|
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
|
|
14
25
|
};
|
|
15
26
|
function createColorMap(customColors = {}) {
|
|
16
27
|
return {
|
|
@@ -23,11 +34,27 @@ function resolveColor(colors, name) {
|
|
|
23
34
|
if (color$2 === void 0) throw new Error(`Unknown chalk color: ${name}`);
|
|
24
35
|
return color$2;
|
|
25
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
|
+
}
|
|
26
51
|
function getForegroundStyle(colors, name) {
|
|
27
|
-
|
|
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(";");
|
|
28
55
|
}
|
|
29
56
|
function getBackgroundStyle(colors, name) {
|
|
30
|
-
return `padding: 2px 4px; border-radius: 3px; color:
|
|
57
|
+
return `padding: 2px 4px; border-radius: 3px; color: #1e1e2e; font-weight: bold; background:${resolveColor(colors, name)};`;
|
|
31
58
|
}
|
|
32
59
|
|
|
33
60
|
//#endregion
|
|
@@ -36,7 +63,7 @@ function createBannerMethods(consoleLike, isDebug) {
|
|
|
36
63
|
return {
|
|
37
64
|
hello(title, version) {
|
|
38
65
|
if (!isDebug()) return;
|
|
39
|
-
consoleLike.log(`%c ${title} %c V${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #
|
|
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;");
|
|
40
67
|
},
|
|
41
68
|
image(url) {
|
|
42
69
|
if (!url) return;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["DEFAULT_COLORS: ColorMap","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\nexport const DEFAULT_COLORS: ColorMap = {\n black: '#000000',\n red: '#FF0000',\n green: '#008000',\n yellow: '#FFFF00',\n blue: '#0000FF',\n magenta: '#FF00FF',\n cyan: '#00FFFF',\n white: '#FFFFFF',\n gray: '#808080',\n}\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\nexport function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n return `color:${resolveColor(colors, name)}`\n}\n\nexport function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const textColor = name === 'white' ? '#000' : '#fff'\n return `padding: 2px 4px; border-radius: 3px; color: ${textColor}; font-weight: bold; background:${resolveColor(colors, name)};`\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: #fff; background: #606060; font-weight: bold;',\n 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; 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":";;;AAEA,MAAaA,iBAA2B;CACtC,OAAO;CACP,KAAK;C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,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.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;CACP,MAAM;CACP;;;;;AAMD,MAAaC,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[]): FormattedText;
|
|
69
69
|
//#endregion
|
|
70
70
|
//#region src/colors.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* Catppuccin Mocha palette — https://catppuccin.com/palette/
|
|
73
|
+
*/
|
|
71
74
|
declare const DEFAULT_COLORS: ColorMap;
|
|
72
75
|
type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>;
|
|
73
76
|
declare function createColorMap(customColors?: CustomColorMap): ResolvedColorMap;
|
package/dist/index.d.mts
CHANGED
|
@@ -68,6 +68,9 @@ declare function bold(text: string): FormattedText;
|
|
|
68
68
|
declare function add(...items: readonly FormattedText[]): FormattedText;
|
|
69
69
|
//#endregion
|
|
70
70
|
//#region src/colors.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* Catppuccin Mocha palette — https://catppuccin.com/palette/
|
|
73
|
+
*/
|
|
71
74
|
declare const DEFAULT_COLORS: ColorMap;
|
|
72
75
|
type ResolvedColorMap = Readonly<ColorMap & CustomColorMap>;
|
|
73
76
|
declare function createColorMap(customColors?: CustomColorMap): ResolvedColorMap;
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
//#region src/colors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Catppuccin Mocha palette — https://catppuccin.com/palette/
|
|
4
|
+
*/
|
|
2
5
|
const DEFAULT_COLORS = {
|
|
3
|
-
black: "#
|
|
4
|
-
red: "#
|
|
5
|
-
green: "#
|
|
6
|
-
yellow: "#
|
|
7
|
-
blue: "#
|
|
8
|
-
magenta: "#
|
|
9
|
-
cyan: "#
|
|
10
|
-
white: "#
|
|
11
|
-
gray: "#
|
|
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
|
|
12
23
|
};
|
|
13
24
|
function createColorMap(customColors = {}) {
|
|
14
25
|
return {
|
|
@@ -21,11 +32,27 @@ function resolveColor(colors, name) {
|
|
|
21
32
|
if (color$2 === void 0) throw new Error(`Unknown chalk color: ${name}`);
|
|
22
33
|
return color$2;
|
|
23
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
|
+
}
|
|
24
49
|
function getForegroundStyle(colors, name) {
|
|
25
|
-
|
|
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(";");
|
|
26
53
|
}
|
|
27
54
|
function getBackgroundStyle(colors, name) {
|
|
28
|
-
return `padding: 2px 4px; border-radius: 3px; color:
|
|
55
|
+
return `padding: 2px 4px; border-radius: 3px; color: #1e1e2e; font-weight: bold; background:${resolveColor(colors, name)};`;
|
|
29
56
|
}
|
|
30
57
|
|
|
31
58
|
//#endregion
|
|
@@ -34,7 +61,7 @@ function createBannerMethods(consoleLike, isDebug) {
|
|
|
34
61
|
return {
|
|
35
62
|
hello(title, version) {
|
|
36
63
|
if (!isDebug()) return;
|
|
37
|
-
consoleLike.log(`%c ${title} %c V${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #
|
|
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;");
|
|
38
65
|
},
|
|
39
66
|
image(url) {
|
|
40
67
|
if (!url) return;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["DEFAULT_COLORS: ColorMap","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\nexport const DEFAULT_COLORS: ColorMap = {\n black: '#000000',\n red: '#FF0000',\n green: '#008000',\n yellow: '#FFFF00',\n blue: '#0000FF',\n magenta: '#FF00FF',\n cyan: '#00FFFF',\n white: '#FFFFFF',\n gray: '#808080',\n}\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\nexport function getForegroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n return `color:${resolveColor(colors, name)}`\n}\n\nexport function getBackgroundStyle(colors: Readonly<Record<string, string>>, name: string): string {\n const textColor = name === 'white' ? '#000' : '#fff'\n return `padding: 2px 4px; border-radius: 3px; color: ${textColor}; font-weight: bold; background:${resolveColor(colors, name)};`\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: #fff; background: #606060; font-weight: bold;',\n 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; 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":";AAEA,MAAaA,iBAA2B;CACtC,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,MAAM;CACP;AAID,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;;AAGT,SAAgB,mBAAmB,QAA0C,MAAsB;AACjG,QAAO,SAAS,aAAa,QAAQ,KAAK;;AAG5C,SAAgB,mBAAmB,QAA0C,MAAsB;AAEjG,QAAO,gDADW,SAAS,UAAU,SAAS,OACmB,kCAAkC,aAAa,QAAQ,KAAK,CAAC;;;;;AC7BhI,SAAgB,oBAAoB,aAA0B,SAAwC;AACpG,QAAO;EACL,MAAM,OAAe,SAAuB;AAC1C,OAAI,CAAC,SAAS,CACZ;AACF,eAAY,IACV,MAAM,MAAM,OAAO,QAAQ,IAC3B,sGACA,qGACD;;EAEH,MAAM,KAAmB;AACvB,OAAI,CAAC,IACH;AACF,OAAI,CAAC,SAAS,CACZ;AACF,eAAY,IACV,OACA,yDAAyD,IAAI,mDAC9D;;EAEJ;;;;;ACzBH,SAAgB,WAAW,MAAc,OAA8B;AACrE,QAAO,CAAC,KAAK,QAAQ,MAAM;;AAG7B,SAAgBC,QAAM,QAA0C,MAAc,MAA6B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AM,QAAQ,QAAQ,KAAK;EACzC,QAAO,SAAQA,QAAM,QAAQ,SAAS,KAAK;EAC3C,UAAS,SAAQC,UAAQ,QAAQ,SAAS,KAAK;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","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;CACT,MAAM,MAAM,OAAO;AACnB,KAAI,CAAC,IACH,QAAO;AACT,QAAO,qBAAqB,IAAI,GAAG;;AAGrC,SAAS,qBAAqB,KAAqB;CACjD,MAAM,IAAI,IAAI,QAAQ,KAAK,GAAG;CAC9B,MAAM,IAAI,OAAO,SAAS,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG;CAC/C,MAAM,IAAI,OAAO,SAAS,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG;CAC/C,MAAM,IAAI,OAAO,SAAS,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG;AAC/C,QAAO,QAAS,IAAI,QAAS,IAAI,QAAS;;AAG5C,SAAgB,mBAAmB,QAA0C,MAAsB;CAEjG,MAAM,QAAQ,CAAC,SADH,aAAa,QAAQ,KAAK,GACR;AAC9B,KAAI,gBAAgB,QAAQ,KAAK,CAC/B,OAAM,KAAK,+BAA+B,i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