@reliverse/relico 1.1.0 → 1.1.2

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/mod.d.ts ADDED
@@ -0,0 +1,364 @@
1
+ /** A color definition: [primary, secondary]. */
2
+ export type ColorDefinition = [string, string];
3
+ /** A list of default color keys. */
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", "redPastel", "greenPastel", "yellowPastel", "bluePastel", "magentaPastel", "cyanPastel", "bgRedPastel", "bgGreenPastel", "bgYellowPastel", "bgBluePastel", "bgMagentaPastel", "bgCyanPastel", "orange", "pink", "purple", "teal", "lime", "brown", "navy", "maroon", "olive", "silver", "bgOrange", "bgPink", "bgPurple", "bgTeal", "bgLime", "bgBrown", "bgNavy", "bgMaroon", "bgOlive", "bgSilver", "gray10", "gray20", "gray30", "gray40", "gray50", "gray60", "gray70", "gray80", "gray90"];
5
+ /** Union of all default color keys */
6
+ export type DefaultColorKeys = (typeof defaultColorKeys)[number];
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>>;
16
+ /**
17
+ * `relico.config.ts` configuration options.
18
+ * Note: `customColors` is restricted to OverridableColorMap.
19
+ */
20
+ export type RelicoConfig = {
21
+ /**
22
+ * Determines which ANSI mode is used:
23
+ * - 0: no color
24
+ * - 1: basic ANSI (8 colors)
25
+ * - 2: 256 color palette
26
+ * - 3: 24-bit truecolor (default)
27
+ */
28
+ colorLevel?: 0 | 1 | 2 | 3;
29
+ /**
30
+ * Theme to use for color definitions.
31
+ * - "primary": primary theme (default)
32
+ * - "secondary": secondary theme
33
+ */
34
+ theme?: "primary" | "secondary";
35
+ /**
36
+ * Custom color definitions.
37
+ * - Theming: ["primary", "secondary"]
38
+ */
39
+ customColors?: OverridableColorMap;
40
+ /**
41
+ * Enable auto-detection of terminal color support
42
+ * Default: true
43
+ */
44
+ autoDetect?: boolean;
45
+ };
46
+ export type IRelicoColors = {
47
+ reset(text: string | number): string;
48
+ bold(text: string | number): string;
49
+ dim(text: string | number): string;
50
+ italic(text: string | number): string;
51
+ underline(text: string | number): string;
52
+ inverse(text: string | number): string;
53
+ hidden(text: string | number): string;
54
+ strikethrough(text: string | number): string;
55
+ black(text: string | number): string;
56
+ red(text: string | number): string;
57
+ green(text: string | number): string;
58
+ yellow(text: string | number): string;
59
+ blue(text: string | number): string;
60
+ magenta(text: string | number): string;
61
+ cyan(text: string | number): string;
62
+ white(text: string | number): string;
63
+ gray(text: string | number): string;
64
+ bgBlack(text: string | number): string;
65
+ bgRed(text: string | number): string;
66
+ bgGreen(text: string | number): string;
67
+ bgYellow(text: string | number): string;
68
+ bgBlue(text: string | number): string;
69
+ bgMagenta(text: string | number): string;
70
+ bgCyan(text: string | number): string;
71
+ bgWhite(text: string | number): string;
72
+ blackBright(text: string | number): string;
73
+ redBright(text: string | number): string;
74
+ greenBright(text: string | number): string;
75
+ yellowBright(text: string | number): string;
76
+ blueBright(text: string | number): string;
77
+ magentaBright(text: string | number): string;
78
+ cyanBright(text: string | number): string;
79
+ whiteBright(text: string | number): string;
80
+ bgBlackBright(text: string | number): string;
81
+ bgRedBright(text: string | number): string;
82
+ bgGreenBright(text: string | number): string;
83
+ bgYellowBright(text: string | number): string;
84
+ bgBlueBright(text: string | number): string;
85
+ bgMagentaBright(text: string | number): string;
86
+ bgCyanBright(text: string | number): string;
87
+ bgWhiteBright(text: string | number): string;
88
+ redPastel(text: string | number): string;
89
+ greenPastel(text: string | number): string;
90
+ yellowPastel(text: string | number): string;
91
+ bluePastel(text: string | number): string;
92
+ magentaPastel(text: string | number): string;
93
+ cyanPastel(text: string | number): string;
94
+ bgRedPastel(text: string | number): string;
95
+ bgGreenPastel(text: string | number): string;
96
+ bgYellowPastel(text: string | number): string;
97
+ bgBluePastel(text: string | number): string;
98
+ bgMagentaPastel(text: string | number): string;
99
+ bgCyanPastel(text: string | number): string;
100
+ orange(text: string | number): string;
101
+ pink(text: string | number): string;
102
+ purple(text: string | number): string;
103
+ teal(text: string | number): string;
104
+ lime(text: string | number): string;
105
+ brown(text: string | number): string;
106
+ navy(text: string | number): string;
107
+ maroon(text: string | number): string;
108
+ olive(text: string | number): string;
109
+ silver(text: string | number): string;
110
+ bgOrange(text: string | number): string;
111
+ bgPink(text: string | number): string;
112
+ bgPurple(text: string | number): string;
113
+ bgTeal(text: string | number): string;
114
+ bgLime(text: string | number): string;
115
+ bgBrown(text: string | number): string;
116
+ bgNavy(text: string | number): string;
117
+ bgMaroon(text: string | number): string;
118
+ bgOlive(text: string | number): string;
119
+ bgSilver(text: string | number): string;
120
+ gray10(text: string | number): string;
121
+ gray20(text: string | number): string;
122
+ gray30(text: string | number): string;
123
+ gray40(text: string | number): string;
124
+ gray50(text: string | number): string;
125
+ gray60(text: string | number): string;
126
+ gray70(text: string | number): string;
127
+ gray80(text: string | number): string;
128
+ gray90(text: string | number): string;
129
+ };
130
+ export declare const re: IRelicoColors;
131
+ /**
132
+ * Configures the library with a partial or complete
133
+ * `RelicoConfig`. Invalid fields are ignored.
134
+ */
135
+ export declare function configure(userInput: unknown): void;
136
+ /**
137
+ * Returns a color function by name (or `reset` or identity if not found).
138
+ * Uses cached functions for better performance.
139
+ */
140
+ export declare function getColor(name: string): (text: string | number) => string;
141
+ /**
142
+ * Colorizes text with a color function.
143
+ */
144
+ export declare function colorize(name: string, text: string | number): string;
145
+ /**
146
+ * Sets the color level (0=none, 1=basic, 2=256, 3=truecolor).
147
+ */
148
+ export declare function setColorLevel(level: 0 | 1 | 2 | 3): void;
149
+ /**
150
+ * Returns a custom "rgb" color function if level is truecolor, otherwise identity.
151
+ * Uses caching for better performance.
152
+ * @param r Red component (0-255)
153
+ * @param g Green component (0-255)
154
+ * @param b Blue component (0-255)
155
+ */
156
+ export declare function rgb(r: number, g: number, b: number): (text: string | number) => string;
157
+ /**
158
+ * Returns a custom background "bgRgb" color function.
159
+ * Uses caching for better performance.
160
+ * @param r Red component (0-255)
161
+ * @param g Green component (0-255)
162
+ * @param b Blue component (0-255)
163
+ */
164
+ export declare function bgRgb(r: number, g: number, b: number): (text: string | number) => string;
165
+ /**
166
+ * Creates a color function from a hex string or color name
167
+ * @param color Hex string (e.g., "#ff0000") or color name (e.g., "red")
168
+ */
169
+ export declare function hex(color: string): (text: string | number) => string;
170
+ /**
171
+ * Creates a background color function from a hex string or color name
172
+ * @param color Hex string (e.g., "#ff0000") or color name (e.g., "red")
173
+ */
174
+ export declare function bgHex(color: string): (text: string | number) => string;
175
+ /**
176
+ * Creates an HSL color from hue, saturation, and lightness values
177
+ * @param h Hue (0-360)
178
+ * @param s Saturation (0-100)
179
+ * @param l Lightness (0-100)
180
+ */
181
+ export declare function hsl(h: number, s: number, l: number): (text: string | number) => string;
182
+ /**
183
+ * Creates a background HSL color
184
+ * @param h Hue (0-360)
185
+ * @param s Saturation (0-100)
186
+ * @param l Lightness (0-100)
187
+ */
188
+ export declare function bgHsl(h: number, s: number, l: number): (text: string | number) => string;
189
+ /**
190
+ * Chain multiple color formatters together
191
+ * @param formatters Array of color formatters to apply in sequence
192
+ */
193
+ export declare function chain(...formatters: ((text: string | number) => string)[]): (text: string | number) => string;
194
+ /**
195
+ * Creates a rainbow text effect
196
+ * @param text The text to colorize
197
+ * @param saturation Saturation (0-100)
198
+ * @param lightness Lightness (0-100)
199
+ * @param options Additional options
200
+ * @returns The rainbow-colorized text
201
+ */
202
+ export declare function rainbow(text: string, saturation?: number, lightness?: number, options?: {
203
+ startHue?: number;
204
+ endHue?: number;
205
+ }): string;
206
+ /**
207
+ * Creates a gradient text effect between multiple colors
208
+ * @param text The text to colorize
209
+ * @param colors Array of colors (hex, rgb, hsl, or named colors)
210
+ * @param options Additional options (smoothing, distribution)
211
+ * @returns The gradient-colorized text
212
+ */
213
+ export declare function multiGradient(text: string, colors: string[], options?: {
214
+ smoothing?: number;
215
+ distribution?: "even" | "weighted";
216
+ }): string;
217
+ /**
218
+ * Creates a gradient text effect between two colors
219
+ * @param text The text to colorize
220
+ * @param startColor Starting color (hex, rgb, hsl, or named color)
221
+ * @param endColor Ending color (hex, rgb, hsl, or named color)
222
+ * @param options Additional options (smoothing)
223
+ * @returns The gradient-colorized text
224
+ */
225
+ export declare function gradient(text: string, startColor: string, endColor: string, options?: {
226
+ smoothing?: number;
227
+ }): string;
228
+ /**
229
+ * Blend two colors together with a given ratio
230
+ * @param color1 First color
231
+ * @param color2 Second color
232
+ * @param ratio Blend ratio (0-1, 0 = color1, 1 = color2)
233
+ * @returns A formatter function with the blended color
234
+ */
235
+ export declare function blend(color1: string, color2: string, ratio?: number): (text: string | number) => string;
236
+ /**
237
+ * Checks if a color meets WCAG contrast guidelines against another color
238
+ * @param foreground Foreground color
239
+ * @param background Background color (defaults to white)
240
+ * @returns Object with contrast ratio and pass/fail for AA and AAA levels
241
+ */
242
+ export declare function checkContrast(foreground: string, background?: string): {
243
+ ratio: number;
244
+ passesAA: boolean;
245
+ passesAAA: boolean;
246
+ passesAALarge: boolean;
247
+ passesAAALarge: boolean;
248
+ };
249
+ /**
250
+ * Find an accessible color by adjusting lightness until it meets contrast requirements
251
+ * @param color Base color to adjust
252
+ * @param background Background color to check contrast against
253
+ * @param targetRatio Minimum contrast ratio to achieve (4.5 = AA, 7 = AAA)
254
+ * @returns A color with sufficient contrast
255
+ */
256
+ export declare function getAccessibleColor(color: string, background?: string, targetRatio?: number): string;
257
+ export type ColorSupport = {
258
+ isColorSupported: boolean;
259
+ isForced: boolean;
260
+ isDisabled: boolean;
261
+ terminalName: string;
262
+ colorLevel: 0 | 1 | 2 | 3;
263
+ };
264
+ export declare const colorSupport: ColorSupport;
265
+ /**
266
+ * Creates a safe background color wrapping that prevents spillover to new lines
267
+ * @param text The text to colorize
268
+ * @param bgColorFn Background color formatter function
269
+ * @param textColorFn Optional text color formatter function
270
+ * @returns Safely wrapped colored text
271
+ */
272
+ export declare function colorWrap(text: string, bgColorFn: (text: string | number) => string, textColorFn?: (text: string | number) => string): string;
273
+ /**
274
+ * Smart background color function that prevents background color overflow
275
+ * Apply background color to text while ensuring it doesn't spill over to new lines
276
+ * @param color Background color (hex, named, etc.)
277
+ * @param text Optional text to colorize immediately
278
+ */
279
+ export declare function safeBg(color: string, text?: string | number): ((text: string | number) => string) | string;
280
+ /**
281
+ * Apply background and foreground colors while preventing spillover
282
+ * @param bgColor Background color
283
+ * @param fgColor Foreground color
284
+ * @param text Optional text to colorize immediately
285
+ */
286
+ export declare function safeColor(bgColor: string, fgColor: string, text?: string | number): ((text: string | number) => string) | string;
287
+ /**
288
+ * Creates a color function that automatically ensures good contrast
289
+ * @param color Base color to use
290
+ * @param background Background color to check contrast against
291
+ * @param targetRatio Minimum contrast ratio to achieve (4.5 = AA, 7 = AAA)
292
+ */
293
+ export declare function autoContrast(color: string, background?: string, targetRatio?: number): (text: string | number) => string;
294
+ /**
295
+ * Creates a color scheme from a base color
296
+ * @param baseColor The main color to generate a scheme from
297
+ * @returns Object with various related colors
298
+ */
299
+ export declare function createColorScheme(baseColor: string): {
300
+ base: (text: string | number) => string;
301
+ light: (text: string | number) => string;
302
+ dark: (text: string | number) => string;
303
+ bright: (text: string | number) => string;
304
+ pastel: (text: string | number) => string;
305
+ bg: (text: string | number) => string;
306
+ bgLight: (text: string | number) => string;
307
+ accent: (text: string | number) => string;
308
+ };
309
+ /**
310
+ * Creates a highlighted text with colored background and contrasting text
311
+ * @param text Text to highlight
312
+ * @param bgColor Background color
313
+ * @param options Additional options
314
+ */
315
+ export declare function highlight(text: string, bgColor: string, options?: {
316
+ padding?: number;
317
+ border?: boolean;
318
+ borderColor?: string;
319
+ }): string;
320
+ /**
321
+ * Creates an ANSI link (works in supported terminals)
322
+ * @param text Link text to display
323
+ * @param url The URL to link to
324
+ * @param color Optional color for the link text
325
+ */
326
+ export declare function link(text: string, url: string, color?: string): string;
327
+ /**
328
+ * Colorize a JSON object with syntax highlighting
329
+ * @param obj Object to stringify and colorize
330
+ * @param options Options for JSON stringification
331
+ */
332
+ export declare function colorizeJson(obj: unknown, options?: {
333
+ indent?: number;
334
+ compact?: boolean;
335
+ }): string;
336
+ /**
337
+ * Initialize user configuration with optional programmatic overrides
338
+ * @param programmaticConfig Optional configuration to override default settings
339
+ * @param userSettingsPrecedence If true, user file settings take precedence over programmatic
340
+ */
341
+ /**
342
+ * Initialize user configuration with optional programmatic overrides
343
+ * @param programmaticConfig Optional configuration to override settings
344
+ * @param userSettingsPrecedence If true, user file settings take precedence over programmatic
345
+ */
346
+ export declare function initUserConfig(programmaticConfig?: Partial<RelicoConfig>, userSettingsPrecedence?: boolean): Promise<void>;
347
+ /**
348
+ * Provides type safety and IntelliSense for user configuration.
349
+ * Example usage in `relico.config.ts`:
350
+ * ```ts
351
+ * import { defineConfig } from "@reliverse/relico-cfg";
352
+ * export default defineConfig({
353
+ * colorLevel: 3,
354
+ * theme: "secondary",
355
+ * customColors: {
356
+ * red: ["#f00", "#c00"],
357
+ * blue: ["#0af", "#08f"],
358
+ * green: ["#00ff00", "#00cc00"],
359
+ * },
360
+ * });
361
+ * ```
362
+ */
363
+ export declare function defineConfig(cfg: RelicoConfig): RelicoConfig;
364
+ export {};