@reliverse/relico 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/main.d.ts +20 -26
- package/bin/main.js +28 -20
- package/package.json +3 -4
package/bin/main.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
/** A color definition: [primary, secondary
|
|
2
|
-
export type ColorDefinition = [string, string
|
|
1
|
+
/** A color definition: [primary, secondary]. */
|
|
2
|
+
export type ColorDefinition = [string, string];
|
|
3
3
|
/** A list of default color keys. */
|
|
4
4
|
export declare const defaultColorKeys: readonly ["reset", "bold", "dim", "italic", "underline", "inverse", "hidden", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue", "bgMagenta", "bgCyan", "bgWhite", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright", "bgBlackBright", "bgRedBright", "bgGreenBright", "bgYellowBright", "bgBlueBright", "bgMagentaBright", "bgCyanBright", "bgWhiteBright"];
|
|
5
|
+
/** Union of all default color keys */
|
|
5
6
|
export type DefaultColorKeys = (typeof defaultColorKeys)[number];
|
|
6
|
-
/**
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Format keys that must NOT be overridden by the user.
|
|
9
|
+
* We'll exclude them from IntelliSense and also skip them at runtime.
|
|
10
|
+
*/
|
|
11
|
+
type RestrictedKeys = "reset" | "bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough";
|
|
12
|
+
/** All the keys user is allowed to override */
|
|
13
|
+
type OverridableColorKeys = Exclude<DefaultColorKeys, RestrictedKeys>;
|
|
14
|
+
/** A map of user-overridable color definitions (no format keys) */
|
|
15
|
+
export type OverridableColorMap = Partial<Record<OverridableColorKeys, ColorDefinition>>;
|
|
8
16
|
/**
|
|
9
17
|
* `relico.config.ts` configuration options.
|
|
18
|
+
* Note: `customColors` is restricted to OverridableColorMap.
|
|
10
19
|
*/
|
|
11
20
|
export type RelicoConfig = {
|
|
12
21
|
/**
|
|
@@ -14,21 +23,20 @@ export type RelicoConfig = {
|
|
|
14
23
|
* - 0: no color
|
|
15
24
|
* - 1: basic ANSI (8 colors)
|
|
16
25
|
* - 2: 256 color palette
|
|
17
|
-
* - 3: 24-bit truecolor
|
|
26
|
+
* - 3: 24-bit truecolor (default)
|
|
18
27
|
*/
|
|
19
28
|
colorLevel?: 0 | 1 | 2 | 3;
|
|
20
29
|
/**
|
|
21
30
|
* Theme to use for color definitions.
|
|
22
|
-
* - "primary": primary theme
|
|
31
|
+
* - "primary": primary theme (default)
|
|
23
32
|
* - "secondary": secondary theme
|
|
24
33
|
*/
|
|
25
34
|
theme?: "primary" | "secondary";
|
|
26
35
|
/**
|
|
27
36
|
* Custom color definitions.
|
|
28
|
-
* - Use IntelliSense to see available colors.
|
|
29
37
|
* - Theming: ["primary", "secondary"]
|
|
30
38
|
*/
|
|
31
|
-
customColors?:
|
|
39
|
+
customColors?: OverridableColorMap;
|
|
32
40
|
};
|
|
33
41
|
export type IRelicoColors = {
|
|
34
42
|
reset(text: string | number): string;
|
|
@@ -102,29 +110,15 @@ export declare function initUserConfig(): Promise<void>;
|
|
|
102
110
|
* ```ts
|
|
103
111
|
* import { defineConfig } from "@reliverse/relico-cfg";
|
|
104
112
|
* export default defineConfig({
|
|
105
|
-
* // Set the color level: 3 for truecolor
|
|
106
113
|
* colorLevel: 3,
|
|
107
|
-
* // Choose the theme: "primary" or "secondary"
|
|
108
114
|
* theme: "secondary",
|
|
109
|
-
* // Override specific colors
|
|
110
|
-
* // - Use Intellisense to see the available colors
|
|
111
|
-
* // - Theming: ["primary", "secondary"]
|
|
112
115
|
* customColors: {
|
|
113
|
-
*
|
|
114
|
-
*
|
|
116
|
+
* red: ["#f00", "#c00"],
|
|
117
|
+
* blue: ["#0af", "#08f"],
|
|
115
118
|
* green: ["#00ff00", "#00cc00"],
|
|
116
|
-
* // Note: The following text formatting
|
|
117
|
-
* // colors can be defined only via ANSI:
|
|
118
|
-
* // reset: ["\x1b[0m", "\x1b[0m"],
|
|
119
|
-
* // bold: ["\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"],
|
|
120
|
-
* // dim: ["\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"],
|
|
121
|
-
* // italic: ["\x1b[3m", "\x1b[23m"],
|
|
122
|
-
* // underline: ["\x1b[4m", "\x1b[24m"],
|
|
123
|
-
* // inverse: ["\x1b[7m", "\x1b[27m"],
|
|
124
|
-
* // hidden: ["\x1b[8m", "\x1b[28m"],
|
|
125
|
-
* // strikethrough: ["\x1b[9m", "\x1b[29m"],
|
|
126
119
|
* },
|
|
127
120
|
* });
|
|
128
121
|
* ```
|
|
129
122
|
*/
|
|
130
|
-
export declare function defineConfig(
|
|
123
|
+
export declare function defineConfig(cfg: RelicoConfig): RelicoConfig;
|
|
124
|
+
export {};
|
package/bin/main.js
CHANGED
|
@@ -63,14 +63,14 @@ function detectColorLevel() {
|
|
|
63
63
|
const baseColors = {
|
|
64
64
|
// Text formatting
|
|
65
65
|
reset: ["\x1B[0m", "\x1B[0m"],
|
|
66
|
-
bold: ["\x1B[1m", "\x1B[22m"
|
|
67
|
-
dim: ["\x1B[2m", "\x1B[22m"
|
|
66
|
+
bold: ["\x1B[1m", "\x1B[22m"],
|
|
67
|
+
dim: ["\x1B[2m", "\x1B[22m"],
|
|
68
68
|
italic: ["\x1B[3m", "\x1B[23m"],
|
|
69
69
|
underline: ["\x1B[4m", "\x1B[24m"],
|
|
70
70
|
inverse: ["\x1B[7m", "\x1B[27m"],
|
|
71
71
|
hidden: ["\x1B[8m", "\x1B[28m"],
|
|
72
72
|
strikethrough: ["\x1B[9m", "\x1B[29m"],
|
|
73
|
-
// Foreground colors
|
|
73
|
+
// Foreground colors
|
|
74
74
|
black: ["#000000", "#000000"],
|
|
75
75
|
red: ["#ff5555", "#ff0000"],
|
|
76
76
|
green: ["#00ff00", "#00ff00"],
|
|
@@ -80,7 +80,7 @@ const baseColors = {
|
|
|
80
80
|
cyan: ["#00ffff", "#00ffff"],
|
|
81
81
|
white: ["#ffffff", "#ffffff"],
|
|
82
82
|
gray: ["#808080", "#808080"],
|
|
83
|
-
// Background colors
|
|
83
|
+
// Background colors
|
|
84
84
|
bgBlack: ["#000000", "#000000"],
|
|
85
85
|
bgRed: ["#ff5555", "#ff0000"],
|
|
86
86
|
bgGreen: ["#00ff00", "#00ff00"],
|
|
@@ -117,6 +117,16 @@ const windowsTerminalColors = {
|
|
|
117
117
|
magenta: ["#ff79c6", "#ff79c6"],
|
|
118
118
|
cyan: ["#8be9fd", "#8be9fd"]
|
|
119
119
|
};
|
|
120
|
+
const restrictedKeys = /* @__PURE__ */ new Set([
|
|
121
|
+
"reset",
|
|
122
|
+
"bold",
|
|
123
|
+
"dim",
|
|
124
|
+
"italic",
|
|
125
|
+
"underline",
|
|
126
|
+
"inverse",
|
|
127
|
+
"hidden",
|
|
128
|
+
"strikethrough"
|
|
129
|
+
]);
|
|
120
130
|
let config = {
|
|
121
131
|
colorLevel: detectColorLevel(),
|
|
122
132
|
theme: "primary"
|
|
@@ -199,8 +209,7 @@ function convertColorDefinition(key, def) {
|
|
|
199
209
|
}
|
|
200
210
|
const openConverted = convert(chosen);
|
|
201
211
|
const close = isBg ? "\x1B[49m" : "\x1B[39m";
|
|
202
|
-
|
|
203
|
-
return [openConverted, close, rep];
|
|
212
|
+
return [openConverted, close];
|
|
204
213
|
}
|
|
205
214
|
function buildColorMap(cfg) {
|
|
206
215
|
const terminalName = getCurrentTerminalName();
|
|
@@ -208,14 +217,16 @@ function buildColorMap(cfg) {
|
|
|
208
217
|
if (cfg.colorLevel === 0) {
|
|
209
218
|
const noColorMap = {};
|
|
210
219
|
for (const k of Object.keys(baseColors)) {
|
|
211
|
-
noColorMap[k] = ["", ""
|
|
220
|
+
noColorMap[k] = ["", ""];
|
|
212
221
|
}
|
|
213
222
|
return noColorMap;
|
|
214
223
|
}
|
|
215
224
|
let builtIn = { ...baseColors };
|
|
216
225
|
if (cfg.customColors) {
|
|
217
226
|
for (const [k, v] of Object.entries(cfg.customColors)) {
|
|
218
|
-
|
|
227
|
+
if (!restrictedKeys.has(k)) {
|
|
228
|
+
builtIn[k] = v;
|
|
229
|
+
}
|
|
219
230
|
}
|
|
220
231
|
}
|
|
221
232
|
if (isWinTerm && cfg.colorLevel === 3) {
|
|
@@ -226,12 +237,9 @@ function buildColorMap(cfg) {
|
|
|
226
237
|
}
|
|
227
238
|
return builtIn;
|
|
228
239
|
}
|
|
229
|
-
function createFormatter(open, close
|
|
230
|
-
const escapedClose = close.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
231
|
-
const regex = new RegExp(escapedClose, "g");
|
|
240
|
+
function createFormatter(open, close) {
|
|
232
241
|
return (input) => {
|
|
233
|
-
|
|
234
|
-
return open + stringed.replace(regex, replace) + close;
|
|
242
|
+
return open + String(input) + close;
|
|
235
243
|
};
|
|
236
244
|
}
|
|
237
245
|
function identityColor(text) {
|
|
@@ -297,8 +305,8 @@ function initColorFunctions() {
|
|
|
297
305
|
}
|
|
298
306
|
return;
|
|
299
307
|
}
|
|
300
|
-
for (const [key, [open, close
|
|
301
|
-
colorFunctions[key] = createFormatter(open, close
|
|
308
|
+
for (const [key, [open, close]] of Object.entries(colorMap)) {
|
|
309
|
+
colorFunctions[key] = createFormatter(open, close);
|
|
302
310
|
}
|
|
303
311
|
}
|
|
304
312
|
function rebuild() {
|
|
@@ -339,6 +347,9 @@ export function rgb(r, g, b) {
|
|
|
339
347
|
}
|
|
340
348
|
return identityColor;
|
|
341
349
|
}
|
|
350
|
+
function getConfig() {
|
|
351
|
+
return { ...config };
|
|
352
|
+
}
|
|
342
353
|
export const colorSupport = {
|
|
343
354
|
isColorSupported: getConfig().colorLevel !== 0,
|
|
344
355
|
isForced,
|
|
@@ -353,9 +364,6 @@ export async function initUserConfig() {
|
|
|
353
364
|
console.warn("Failed to load user config via c12:", err);
|
|
354
365
|
}
|
|
355
366
|
}
|
|
356
|
-
export function defineConfig(
|
|
357
|
-
return
|
|
358
|
-
}
|
|
359
|
-
function getConfig() {
|
|
360
|
-
return { ...config };
|
|
367
|
+
export function defineConfig(cfg) {
|
|
368
|
+
return cfg;
|
|
361
369
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
3
|
"@reliverse/runtime": "^1.0.3",
|
|
4
|
-
"bun-types": "^1.2.8",
|
|
5
4
|
"c12": "^3.0.2",
|
|
6
5
|
"pathe": "^2.0.3"
|
|
7
6
|
},
|
|
@@ -10,7 +9,7 @@
|
|
|
10
9
|
"license": "MIT",
|
|
11
10
|
"name": "@reliverse/relico",
|
|
12
11
|
"type": "module",
|
|
13
|
-
"version": "1.0
|
|
12
|
+
"version": "1.1.0",
|
|
14
13
|
"author": "reliverse",
|
|
15
14
|
"bugs": {
|
|
16
15
|
"email": "blefnk@gmail.com",
|
|
@@ -29,10 +28,10 @@
|
|
|
29
28
|
"@reliverse/relidler-cfg": "^1.1.3",
|
|
30
29
|
"@stylistic/eslint-plugin": "^4.2.0",
|
|
31
30
|
"@types/bun": "^1.2.8",
|
|
32
|
-
"@types/node": "^22.13.
|
|
31
|
+
"@types/node": "^22.13.17",
|
|
33
32
|
"eslint": "^9.23.0",
|
|
34
33
|
"eslint-plugin-no-relative-import-paths": "^1.6.1",
|
|
35
|
-
"eslint-plugin-perfectionist": "^4.
|
|
34
|
+
"eslint-plugin-perfectionist": "^4.11.0",
|
|
36
35
|
"jiti": "^2.4.2",
|
|
37
36
|
"knip": "^5.46.4",
|
|
38
37
|
"typescript": "^5.8.2",
|