@mnrendra/chalk-ansi-styles
Version:
Refactored ansi-styles code to support both CommonJS (CJS) and ES Modules (ESM) with mixed exports.
277 lines (258 loc) • 9.57 kB
TypeScript
declare const ESCAPE = "\u001B[";
type Escape = typeof ESCAPE;
declare const LAYER: {
readonly foreground: 38;
readonly background: 48;
};
type Layer = typeof LAYER['foreground'] | typeof LAYER['background'];
type ANSI<Param extends string = string> = `${Escape}${Param}m`;
type ANSI16<Num extends number = number> = ANSI<`${Num}`>;
interface CSPair<Open extends number = number, Close extends number = number> {
/**
* The ANSI terminal control sequence for starting this style.
*/
readonly open: ANSI16<Open>;
/**
* The ANSI terminal control sequence for ending this style.
*/
readonly close: ANSI16<Close>;
}
declare const modifier: {
/**
* Resets the current color chain.
*/
readonly reset: CSPair<0, 0>;
/**
* Make text bold.
*/
readonly bold: CSPair<1, 22>;
/**
* Emitting only a small amount of light.
*/
readonly dim: CSPair<2, 22>;
/**
* Make text italic. (Not widely supported).
*/
readonly italic: CSPair<3, 23>;
/**
* Make text underline. (Not widely supported).
*/
readonly underline: CSPair<4, 24>;
/**
* Inverse background and foreground colors.
*/
readonly inverse: CSPair<7, 27>;
/**
* Prints the text, but makes it invisible.
*/
readonly hidden: CSPair<8, 28>;
/**
* Puts a horizontal line through the center of the text. (Not widely
* supported).
*/
readonly strikethrough: CSPair<9, 29>;
/**
* Make text overline.
*
* Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
*/
readonly overline: CSPair<53, 55>;
};
type Modifier = typeof modifier;
/**
* Basic modifier names.
*/
type ModifierName = keyof Modifier;
declare const foregroundColor: {
readonly black: CSPair<30, 39>;
readonly red: CSPair<31, 39>;
readonly green: CSPair<32, 39>;
readonly yellow: CSPair<33, 39>;
readonly blue: CSPair<34, 39>;
readonly magenta: CSPair<35, 39>;
readonly cyan: CSPair<36, 39>;
readonly white: CSPair<37, 39>;
readonly gray: CSPair<90, 39>;
readonly grey: CSPair<90, 39>;
readonly blackBright: CSPair<90, 39>;
readonly redBright: CSPair<91, 39>;
readonly greenBright: CSPair<92, 39>;
readonly yellowBright: CSPair<93, 39>;
readonly blueBright: CSPair<94, 39>;
readonly magentaBright: CSPair<95, 39>;
readonly cyanBright: CSPair<96, 39>;
readonly whiteBright: CSPair<97, 39>;
};
type ForegroundColor = typeof foregroundColor;
/**
* Basic foreground color names.
*
* [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
type ForegroundColorName = keyof ForegroundColor;
declare const backgroundColor: {
readonly bgBlack: CSPair<40, 49>;
readonly bgRed: CSPair<41, 49>;
readonly bgGreen: CSPair<42, 49>;
readonly bgYellow: CSPair<43, 49>;
readonly bgBlue: CSPair<44, 49>;
readonly bgMagenta: CSPair<45, 49>;
readonly bgCyan: CSPair<46, 49>;
readonly bgWhite: CSPair<47, 49>;
readonly bgGray: CSPair<100, 49>;
readonly bgGrey: CSPair<100, 49>;
readonly bgBlackBright: CSPair<100, 49>;
readonly bgRedBright: CSPair<101, 49>;
readonly bgGreenBright: CSPair<102, 49>;
readonly bgYellowBright: CSPair<103, 49>;
readonly bgBlueBright: CSPair<104, 49>;
readonly bgMagentaBright: CSPair<105, 49>;
readonly bgCyanBright: CSPair<106, 49>;
readonly bgWhiteBright: CSPair<107, 49>;
};
type BackgroundColor = typeof backgroundColor;
/**
* Basic background color names.
*
* [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
type BackgroundColorName = keyof BackgroundColor;
/**
* Basic color names. The combination of foreground and background color names.
*
* [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
type ColorName = ForegroundColorName | BackgroundColorName;
/**
* Basic style names. The combination of modifier and color names.
*/
type StyleName = ModifierName | ColorName;
type StyleNumbers = Record<StyleName, readonly [number, number]>;
declare const ansi256ToAnsi: (code: number) => number;
declare const hexToAnsi: (hex: number | string) => number;
declare const hexToAnsi256: (hex: number | string) => number;
declare const hexToRgb: (hex: number | string) => [number, number, number];
declare const rgbToAnsi: (red: number, green: number, blue: number) => number;
declare const rgbToAnsi256: (red: number, green: number, blue: number) => number;
/**
* ANSI color styles.
*/
declare const styles: {
readonly bgBlack: CSPair<40, 49>;
readonly bgRed: CSPair<41, 49>;
readonly bgGreen: CSPair<42, 49>;
readonly bgYellow: CSPair<43, 49>;
readonly bgBlue: CSPair<44, 49>;
readonly bgMagenta: CSPair<45, 49>;
readonly bgCyan: CSPair<46, 49>;
readonly bgWhite: CSPair<47, 49>;
readonly bgGray: CSPair<100, 49>;
readonly bgGrey: CSPair<100, 49>;
readonly bgBlackBright: CSPair<100, 49>;
readonly bgRedBright: CSPair<101, 49>;
readonly bgGreenBright: CSPair<102, 49>;
readonly bgYellowBright: CSPair<103, 49>;
readonly bgBlueBright: CSPair<104, 49>;
readonly bgMagentaBright: CSPair<105, 49>;
readonly bgCyanBright: CSPair<106, 49>;
readonly bgWhiteBright: CSPair<107, 49>;
readonly black: CSPair<30, 39>;
readonly red: CSPair<31, 39>;
readonly green: CSPair<32, 39>;
readonly yellow: CSPair<33, 39>;
readonly blue: CSPair<34, 39>;
readonly magenta: CSPair<35, 39>;
readonly cyan: CSPair<36, 39>;
readonly white: CSPair<37, 39>;
readonly gray: CSPair<90, 39>;
readonly grey: CSPair<90, 39>;
readonly blackBright: CSPair<90, 39>;
readonly redBright: CSPair<91, 39>;
readonly greenBright: CSPair<92, 39>;
readonly yellowBright: CSPair<93, 39>;
readonly blueBright: CSPair<94, 39>;
readonly magentaBright: CSPair<95, 39>;
readonly cyanBright: CSPair<96, 39>;
readonly whiteBright: CSPair<97, 39>;
readonly reset: CSPair<0, 0>;
readonly bold: CSPair<1, 22>;
readonly dim: CSPair<2, 22>;
readonly italic: CSPair<3, 23>;
readonly underline: CSPair<4, 24>;
readonly inverse: CSPair<7, 27>;
readonly hidden: CSPair<8, 28>;
readonly strikethrough: CSPair<9, 29>;
readonly overline: CSPair<53, 55>;
};
type Styles = typeof styles;
declare const color: {
close: "\u001B[39m";
ansi: <Num extends number = number>(num: Num) => ANSI16<Num>;
ansi256: <Num extends number = number>(num: Num) => `\u001B[38;5;${Num}m`;
ansi16m: <Red extends number = number, Green extends number = number, Blue extends number = number>(red: Red, green: Green, blue: Blue) => `\u001B[38;2;${Red};${Green};${Blue}m`;
black: CSPair<30, 39>;
red: CSPair<31, 39>;
green: CSPair<32, 39>;
yellow: CSPair<33, 39>;
blue: CSPair<34, 39>;
magenta: CSPair<35, 39>;
cyan: CSPair<36, 39>;
white: CSPair<37, 39>;
gray: CSPair<90, 39>;
grey: CSPair<90, 39>;
blackBright: CSPair<90, 39>;
redBright: CSPair<91, 39>;
greenBright: CSPair<92, 39>;
yellowBright: CSPair<93, 39>;
blueBright: CSPair<94, 39>;
magentaBright: CSPair<95, 39>;
cyanBright: CSPair<96, 39>;
whiteBright: CSPair<97, 39>;
};
type Color = typeof color;
declare const bgColor: {
close: "\u001B[49m";
ansi: <Num extends number = number>(num: Num) => ANSI16<Num>;
ansi256: <Num extends number = number>(num: Num) => `\u001B[48;5;${Num}m`;
ansi16m: <Red extends number = number, Green extends number = number, Blue extends number = number>(red: Red, green: Green, blue: Blue) => `\u001B[48;2;${Red};${Green};${Blue}m`;
bgBlack: CSPair<40, 49>;
bgRed: CSPair<41, 49>;
bgGreen: CSPair<42, 49>;
bgYellow: CSPair<43, 49>;
bgBlue: CSPair<44, 49>;
bgMagenta: CSPair<45, 49>;
bgCyan: CSPair<46, 49>;
bgWhite: CSPair<47, 49>;
bgGray: CSPair<100, 49>;
bgGrey: CSPair<100, 49>;
bgBlackBright: CSPair<100, 49>;
bgRedBright: CSPair<101, 49>;
bgGreenBright: CSPair<102, 49>;
bgYellowBright: CSPair<103, 49>;
bgBlueBright: CSPair<104, 49>;
bgMagentaBright: CSPair<105, 49>;
bgCyanBright: CSPair<106, 49>;
bgWhiteBright: CSPair<107, 49>;
};
type BgColor = typeof bgColor;
declare const codes: Map<number, number>;
type Codes = typeof codes;
declare const modifierNames: readonly ModifierName[];
declare const foregroundColorNames: readonly ForegroundColorName[];
declare const backgroundColorNames: readonly BackgroundColorName[];
declare const colorNames: readonly ColorName[];
type AnsiStyles = Styles & {
readonly modifier: Modifier;
readonly color: Color;
readonly bgColor: BgColor;
readonly codes: Codes;
readonly rgbToAnsi256: typeof rgbToAnsi256;
readonly hexToRgb: typeof hexToRgb;
readonly hexToAnsi256: typeof hexToAnsi256;
readonly ansi256ToAnsi: typeof ansi256ToAnsi;
readonly rgbToAnsi: typeof rgbToAnsi;
readonly hexToAnsi: typeof hexToAnsi;
};
declare const ansiStyles: AnsiStyles;
export { type AnsiStyles, type BackgroundColor, type BackgroundColorName, type CSPair, type ColorName, type ForegroundColor, type ForegroundColorName, type Layer, type Modifier, type ModifierName, type StyleName, type StyleNumbers, type Styles, ansiStyles, backgroundColorNames, colorNames, styles as default, foregroundColorNames, modifierNames };
//# sourceMappingURL=index.d.ts.map