@visulima/colorize 1.4.26 → 1.4.28
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/CHANGELOG.md +48 -0
- package/README.md +208 -12
- package/dist/ansi-codes.d.cts +18 -0
- package/dist/ansi-codes.d.mts +18 -0
- package/dist/ansi-codes.d.ts +18 -0
- package/dist/colorize.browser.d.mts +3 -0
- package/dist/colorize.server.d.cts +10 -0
- package/dist/colorize.server.d.mts +10 -0
- package/dist/colorize.server.d.ts +10 -0
- package/dist/css-code.d.mts +11 -0
- package/dist/gradient/gradient-builder.d.cts +10 -0
- package/dist/gradient/gradient-builder.d.mts +10 -0
- package/dist/gradient/gradient-builder.d.ts +10 -0
- package/dist/gradient/util/color-names.d.cts +2 -0
- package/dist/gradient/util/color-names.d.mts +2 -0
- package/dist/gradient/util/color-names.d.ts +2 -0
- package/dist/gradient/util/compute.d.cts +2 -0
- package/dist/gradient/util/compute.d.mts +2 -0
- package/dist/gradient/util/compute.d.ts +2 -0
- package/dist/gradient/util/hsv-to-rgb.d.cts +5 -0
- package/dist/gradient/util/hsv-to-rgb.d.mts +5 -0
- package/dist/gradient/util/hsv-to-rgb.d.ts +5 -0
- package/dist/gradient/util/interpolate.d.cts +3 -0
- package/dist/gradient/util/interpolate.d.mts +3 -0
- package/dist/gradient/util/interpolate.d.ts +3 -0
- package/dist/gradient/util/rgb-to-hsv.d.cts +9 -0
- package/dist/gradient/util/rgb-to-hsv.d.mts +9 -0
- package/dist/gradient/util/rgb-to-hsv.d.ts +9 -0
- package/dist/gradient.cjs +60 -3
- package/dist/gradient.d.cts +4 -16
- package/dist/gradient.d.mts +4 -16
- package/dist/gradient.d.ts +4 -16
- package/dist/gradient.mjs +54 -3
- package/dist/index.browser.d.mts +60 -64
- package/dist/index.browser.mjs +61 -1
- package/dist/index.server.cjs +246 -2
- package/dist/index.server.d.cts +7 -73
- package/dist/index.server.d.mts +60 -64
- package/dist/index.server.d.ts +8 -65
- package/dist/index.server.mjs +61 -1
- package/dist/packem_shared/Colorize-BenP3bFn.mjs +241 -0
- package/dist/packem_shared/Colorize-Ca9CXTcj.mjs +413 -0
- package/dist/packem_shared/GradientBuilder-Ba4Teq6P.mjs +487 -0
- package/dist/packem_shared/GradientBuilder-DjJK22kP.cjs +491 -0
- package/dist/packem_shared/colorize.server-BA3gZZXz.cjs +193 -0
- package/dist/packem_shared/colorize.server-ry9FZNfG.mjs +191 -0
- package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +13 -0
- package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +17 -0
- package/dist/packem_shared/rgbToAnsi256-BdS0fomP.mjs +41 -0
- package/dist/packem_shared/rgbToAnsi256-DL8eajTz.cjs +47 -0
- package/dist/template/make-colorize-template.d.cts +9 -0
- package/dist/template/make-colorize-template.d.mts +9 -0
- package/dist/template/make-colorize-template.d.ts +9 -0
- package/dist/template/make-template.d.cts +10 -0
- package/dist/template/make-template.d.mts +10 -0
- package/dist/template/make-template.d.ts +10 -0
- package/dist/template.cjs +144 -2
- package/dist/template.d.cts +5 -11
- package/dist/template.d.mts +5 -7
- package/dist/template.d.ts +5 -11
- package/dist/template.mjs +138 -2
- package/dist/types.d.cts +174 -0
- package/dist/types.d.mts +174 -0
- package/dist/types.d.ts +174 -0
- package/dist/util/ansi-code-hex-map.d.mts +8 -0
- package/dist/util/clamp.d.cts +12 -0
- package/dist/util/clamp.d.mts +12 -0
- package/dist/util/clamp.d.ts +12 -0
- package/dist/util/convert-hex-to-rgb.d.cts +22 -0
- package/dist/util/convert-hex-to-rgb.d.mts +22 -0
- package/dist/util/convert-hex-to-rgb.d.ts +22 -0
- package/dist/util/convert-rgb-to-ansi.d.cts +18 -0
- package/dist/util/convert-rgb-to-ansi.d.mts +18 -0
- package/dist/util/convert-rgb-to-ansi.d.ts +18 -0
- package/dist/util/string-replace-all.d.cts +12 -0
- package/dist/util/string-replace-all.d.mts +12 -0
- package/dist/util/string-replace-all.d.ts +12 -0
- package/dist/util/unescape.d.cts +9 -0
- package/dist/util/unescape.d.mts +9 -0
- package/dist/util/unescape.d.ts +9 -0
- package/dist/utils.cjs +13 -1
- package/dist/utils.d.cts +2 -9
- package/dist/utils.d.mts +2 -9
- package/dist/utils.d.ts +2 -9
- package/dist/utils.mjs +2 -1
- package/package.json +2 -2
- package/dist/index.browser.d.ts +0 -65
- package/dist/packem_shared/Colorize-BHcGWJJ0.mjs +0 -1
- package/dist/packem_shared/Colorize-CFUl2AHz.mjs +0 -2
- package/dist/packem_shared/GradientBuilder-D6w_X2D1.cjs +0 -1
- package/dist/packem_shared/GradientBuilder-DnPdd2Cf.mjs +0 -1
- package/dist/packem_shared/colorize.server-BX0i6nN6.cjs +0 -2
- package/dist/packem_shared/colorize.server-BkwhBIE0.mjs +0 -2
- package/dist/packem_shared/convertHexToRgb-BEnfEytq.cjs +0 -1
- package/dist/packem_shared/convertHexToRgb-DGcGUKnj.mjs +0 -1
- package/dist/packem_shared/rgbToAnsi256--f09kvlF.cjs +0 -1
- package/dist/packem_shared/rgbToAnsi256-YETEPW8R.mjs +0 -1
- package/dist/packem_shared/types-CuuGv4d0.d.cts +0 -81
- package/dist/packem_shared/types-CuuGv4d0.d.mts +0 -81
- package/dist/packem_shared/types-CuuGv4d0.d.ts +0 -81
- package/dist/packem_shared/types-M28Oe2t1.d.mts +0 -67
- package/dist/packem_shared/types-M28Oe2t1.d.ts +0 -67
package/dist/index.server.d.cts
CHANGED
|
@@ -1,74 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(string: number | string): string;
|
|
8
|
-
(string: TemplateStringsArray, ...parameters: string[]): string;
|
|
9
|
-
ansi256: (code: number) => this;
|
|
10
|
-
bg: (code: number) => this;
|
|
11
|
-
bgAnsi256: (code: number) => this;
|
|
12
|
-
readonly bgBlack: this;
|
|
13
|
-
readonly bgBlackBright: this;
|
|
14
|
-
readonly bgBlue: this;
|
|
15
|
-
readonly bgBlueBright: this;
|
|
16
|
-
readonly bgCyan: this;
|
|
17
|
-
readonly bgCyanBright: this;
|
|
18
|
-
readonly bgGray: this;
|
|
19
|
-
readonly bgGreen: this;
|
|
20
|
-
readonly bgGreenBright: this;
|
|
21
|
-
readonly bgGrey: this;
|
|
22
|
-
bgHex: (color: ColorValueHex) => this;
|
|
23
|
-
readonly bgMagenta: this;
|
|
24
|
-
readonly bgMagentaBright: this;
|
|
25
|
-
readonly bgRed: this;
|
|
26
|
-
readonly bgRedBright: this;
|
|
27
|
-
bgRgb: (red: number, green: number, blue: number) => this;
|
|
28
|
-
readonly bgWhite: this;
|
|
29
|
-
readonly bgWhiteBright: this;
|
|
30
|
-
readonly bgYellow: this;
|
|
31
|
-
readonly bgYellowBright: this;
|
|
32
|
-
readonly black: this;
|
|
33
|
-
readonly blackBright: this;
|
|
34
|
-
readonly blue: this;
|
|
35
|
-
readonly blueBright: this;
|
|
36
|
-
readonly bold: this;
|
|
37
|
-
readonly close: string;
|
|
38
|
-
readonly cyan: this;
|
|
39
|
-
readonly cyanBright: this;
|
|
40
|
-
readonly dim: this;
|
|
41
|
-
fg: (code: number) => this;
|
|
42
|
-
readonly gray: this;
|
|
43
|
-
readonly green: this;
|
|
44
|
-
readonly greenBright: this;
|
|
45
|
-
readonly grey: this;
|
|
46
|
-
hex: (color: ColorValueHex) => this;
|
|
47
|
-
readonly hidden: this;
|
|
48
|
-
readonly inverse: this;
|
|
49
|
-
readonly italic: this;
|
|
50
|
-
readonly magenta: this;
|
|
51
|
-
readonly magentaBright: this;
|
|
52
|
-
readonly open: string;
|
|
53
|
-
readonly overline: this;
|
|
54
|
-
readonly red: this;
|
|
55
|
-
readonly redBright: this;
|
|
56
|
-
readonly reset: this;
|
|
57
|
-
rgb: (red: number, green: number, blue: number) => this;
|
|
58
|
-
readonly strike: this;
|
|
59
|
-
readonly strikethrough: this;
|
|
60
|
-
strip: (string: string) => string;
|
|
61
|
-
readonly underline: this;
|
|
62
|
-
readonly visible: this;
|
|
63
|
-
readonly white: this;
|
|
64
|
-
readonly whiteBright: this;
|
|
65
|
-
readonly yellow: this;
|
|
66
|
-
readonly yellowBright: this; }
|
|
67
|
-
export type AnsiStyles = "bold" | "dim" | "hidden" | "inverse" | "italic" | "overline" | "reset" | "strike" | "strikethrough" | "underline" | "visible";
|
|
68
|
-
export type AnsiColors = "bgBlack" | "bgBlackBright" | "bgBlue" | "bgBlueBright" | "bgCyan" | "bgCyanBright" | "bgGray" | "bgGreen" | "bgGreenBright" | "bgGrey" | "bgMagenta" | "bgMagentaBright" | "bgRed" | "bgRedBright" | "bgWhite" | "bgWhiteBright" | "bgYellow" | "bgYellowBright" | "black" | "blackBright" | "blue" | "blueBright" | "cyan" | "cyanBright" | "gray" | "green" | "greenBright" | "grey" | "magenta" | "magentaBright" | "red" | "redBright" | "white" | "whiteBright" | "yellow" | "yellowBright";
|
|
69
|
-
export const _default: ColorizeType;
|
|
70
|
-
export const Colorize: new () => ColorizeType;
|
|
71
|
-
import _default = _default;
|
|
72
|
-
export { _default as default };
|
|
73
|
-
}
|
|
1
|
+
import ColorizeImpl from "./colorize.d.cts";
|
|
2
|
+
import type { ColorizeType } from "./types.d.cts";
|
|
3
|
+
type ColorizeTypeWithColorize = ColorizeType & {
|
|
4
|
+
Colorize: typeof ColorizeImpl;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: ColorizeTypeWithColorize;
|
|
74
7
|
export = _default;
|
|
8
|
+
export type { AnsiColors, AnsiStyles, ColorizeType } from "./types.d.cts";
|
package/dist/index.server.d.mts
CHANGED
|
@@ -1,65 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as AnsiColors, b as AnsiStyles } from './packem_shared/types-M28Oe2t1.mjs';
|
|
3
|
-
|
|
4
|
-
declare const Colorize: new () => ColorizeType;
|
|
5
|
-
|
|
1
|
+
import type { ColorizeType, ColorValueHex } from "./types.d.mts";
|
|
6
2
|
declare const _default: ColorizeType;
|
|
7
|
-
|
|
8
|
-
declare const ansi256: (code: number) => ColorizeType;
|
|
9
|
-
declare const bg: (code: number) => ColorizeType;
|
|
10
|
-
declare const bgAnsi256: (code: number) => ColorizeType;
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
13
|
-
declare const
|
|
14
|
-
declare const
|
|
15
|
-
declare const
|
|
16
|
-
declare const
|
|
17
|
-
declare const
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
20
|
-
declare const
|
|
21
|
-
declare const
|
|
22
|
-
declare const
|
|
23
|
-
declare const
|
|
24
|
-
declare const
|
|
25
|
-
declare const
|
|
26
|
-
declare const
|
|
27
|
-
declare const
|
|
28
|
-
declare const
|
|
29
|
-
declare const
|
|
30
|
-
declare const
|
|
31
|
-
declare const
|
|
32
|
-
declare const
|
|
33
|
-
declare const
|
|
34
|
-
declare const
|
|
35
|
-
declare const
|
|
36
|
-
declare const
|
|
37
|
-
declare const
|
|
38
|
-
declare const
|
|
39
|
-
declare const
|
|
40
|
-
declare const
|
|
41
|
-
declare const
|
|
42
|
-
declare const
|
|
43
|
-
declare const
|
|
44
|
-
declare const
|
|
45
|
-
declare const
|
|
46
|
-
declare const
|
|
47
|
-
declare const
|
|
48
|
-
declare const
|
|
49
|
-
declare const
|
|
50
|
-
declare const
|
|
51
|
-
declare const
|
|
52
|
-
declare const
|
|
53
|
-
declare const
|
|
54
|
-
declare const
|
|
55
|
-
declare const
|
|
56
|
-
declare const
|
|
57
|
-
declare const
|
|
58
|
-
declare const underline: ColorizeType;
|
|
59
|
-
declare const visible: ColorizeType;
|
|
60
|
-
declare const white: ColorizeType;
|
|
61
|
-
declare const whiteBright: ColorizeType;
|
|
62
|
-
declare const yellow: ColorizeType;
|
|
63
|
-
declare const yellowBright: ColorizeType;
|
|
64
|
-
|
|
65
|
-
export {
|
|
3
|
+
export default _default;
|
|
4
|
+
export declare const ansi256: (code: number) => ColorizeType;
|
|
5
|
+
export declare const bg: (code: number) => ColorizeType;
|
|
6
|
+
export declare const bgAnsi256: (code: number) => ColorizeType;
|
|
7
|
+
export declare const bgHex: (color: ColorValueHex) => ColorizeType;
|
|
8
|
+
export declare const bgRgb: (red: number, green: number, blue: number) => ColorizeType;
|
|
9
|
+
export declare const fg: (code: number) => ColorizeType;
|
|
10
|
+
export declare const hex: (color: ColorValueHex) => ColorizeType;
|
|
11
|
+
export declare const rgb: (red: number, green: number, blue: number) => ColorizeType;
|
|
12
|
+
export declare const strip: (string: string) => string;
|
|
13
|
+
export declare const bgBlack: ColorizeType;
|
|
14
|
+
export declare const bgBlackBright: ColorizeType;
|
|
15
|
+
export declare const bgBlue: ColorizeType;
|
|
16
|
+
export declare const bgBlueBright: ColorizeType;
|
|
17
|
+
export declare const bgCyan: ColorizeType;
|
|
18
|
+
export declare const bgCyanBright: ColorizeType;
|
|
19
|
+
export declare const bgGray: ColorizeType;
|
|
20
|
+
export declare const bgGreen: ColorizeType;
|
|
21
|
+
export declare const bgGreenBright: ColorizeType;
|
|
22
|
+
export declare const bgGrey: ColorizeType;
|
|
23
|
+
export declare const bgMagenta: ColorizeType;
|
|
24
|
+
export declare const bgMagentaBright: ColorizeType;
|
|
25
|
+
export declare const bgRed: ColorizeType;
|
|
26
|
+
export declare const bgRedBright: ColorizeType;
|
|
27
|
+
export declare const bgWhite: ColorizeType;
|
|
28
|
+
export declare const bgWhiteBright: ColorizeType;
|
|
29
|
+
export declare const bgYellow: ColorizeType;
|
|
30
|
+
export declare const bgYellowBright: ColorizeType;
|
|
31
|
+
export declare const black: ColorizeType;
|
|
32
|
+
export declare const blackBright: ColorizeType;
|
|
33
|
+
export declare const blue: ColorizeType;
|
|
34
|
+
export declare const blueBright: ColorizeType;
|
|
35
|
+
export declare const bold: ColorizeType;
|
|
36
|
+
export declare const cyan: ColorizeType;
|
|
37
|
+
export declare const cyanBright: ColorizeType;
|
|
38
|
+
export declare const dim: ColorizeType;
|
|
39
|
+
export declare const gray: ColorizeType;
|
|
40
|
+
export declare const green: ColorizeType;
|
|
41
|
+
export declare const greenBright: ColorizeType;
|
|
42
|
+
export declare const grey: ColorizeType;
|
|
43
|
+
export declare const hidden: ColorizeType;
|
|
44
|
+
export declare const inverse: ColorizeType;
|
|
45
|
+
export declare const italic: ColorizeType;
|
|
46
|
+
export declare const magenta: ColorizeType;
|
|
47
|
+
export declare const magentaBright: ColorizeType;
|
|
48
|
+
export declare const overline: ColorizeType;
|
|
49
|
+
export declare const red: ColorizeType;
|
|
50
|
+
export declare const redBright: ColorizeType;
|
|
51
|
+
export declare const reset: ColorizeType;
|
|
52
|
+
export declare const strike: ColorizeType;
|
|
53
|
+
export declare const strikethrough: ColorizeType;
|
|
54
|
+
export declare const underline: ColorizeType;
|
|
55
|
+
export declare const visible: ColorizeType;
|
|
56
|
+
export declare const white: ColorizeType;
|
|
57
|
+
export declare const whiteBright: ColorizeType;
|
|
58
|
+
export declare const yellow: ColorizeType;
|
|
59
|
+
export declare const yellowBright: ColorizeType;
|
|
60
|
+
export { default as Colorize } from "./colorize.d.mts";
|
|
61
|
+
export type { AnsiColors, AnsiStyles, ColorizeType } from "./types.d.mts";
|
package/dist/index.server.d.ts
CHANGED
|
@@ -1,65 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const _default:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare const bg: (code: number) => ColorizeType;
|
|
10
|
-
declare const bgAnsi256: (code: number) => ColorizeType;
|
|
11
|
-
declare const bgBlack: ColorizeType;
|
|
12
|
-
declare const bgBlackBright: ColorizeType;
|
|
13
|
-
declare const bgBlue: ColorizeType;
|
|
14
|
-
declare const bgBlueBright: ColorizeType;
|
|
15
|
-
declare const bgCyan: ColorizeType;
|
|
16
|
-
declare const bgCyanBright: ColorizeType;
|
|
17
|
-
declare const bgGray: ColorizeType;
|
|
18
|
-
declare const bgGreen: ColorizeType;
|
|
19
|
-
declare const bgGreenBright: ColorizeType;
|
|
20
|
-
declare const bgGrey: ColorizeType;
|
|
21
|
-
declare const bgHex: (color: ColorValueHex) => ColorizeType;
|
|
22
|
-
declare const bgMagenta: ColorizeType;
|
|
23
|
-
declare const bgMagentaBright: ColorizeType;
|
|
24
|
-
declare const bgRed: ColorizeType;
|
|
25
|
-
declare const bgRedBright: ColorizeType;
|
|
26
|
-
declare const bgRgb: (red: number, green: number, blue: number) => ColorizeType;
|
|
27
|
-
declare const bgWhite: ColorizeType;
|
|
28
|
-
declare const bgWhiteBright: ColorizeType;
|
|
29
|
-
declare const bgYellow: ColorizeType;
|
|
30
|
-
declare const bgYellowBright: ColorizeType;
|
|
31
|
-
declare const black: ColorizeType;
|
|
32
|
-
declare const blackBright: ColorizeType;
|
|
33
|
-
declare const blue: ColorizeType;
|
|
34
|
-
declare const blueBright: ColorizeType;
|
|
35
|
-
declare const bold: ColorizeType;
|
|
36
|
-
declare const cyan: ColorizeType;
|
|
37
|
-
declare const cyanBright: ColorizeType;
|
|
38
|
-
declare const dim: ColorizeType;
|
|
39
|
-
declare const fg: (code: number) => ColorizeType;
|
|
40
|
-
declare const gray: ColorizeType;
|
|
41
|
-
declare const green: ColorizeType;
|
|
42
|
-
declare const greenBright: ColorizeType;
|
|
43
|
-
declare const grey: ColorizeType;
|
|
44
|
-
declare const hex: (color: ColorValueHex) => ColorizeType;
|
|
45
|
-
declare const hidden: ColorizeType;
|
|
46
|
-
declare const inverse: ColorizeType;
|
|
47
|
-
declare const italic: ColorizeType;
|
|
48
|
-
declare const magenta: ColorizeType;
|
|
49
|
-
declare const magentaBright: ColorizeType;
|
|
50
|
-
declare const overline: ColorizeType;
|
|
51
|
-
declare const red: ColorizeType;
|
|
52
|
-
declare const redBright: ColorizeType;
|
|
53
|
-
declare const reset: ColorizeType;
|
|
54
|
-
declare const rgb: (red: number, green: number, blue: number) => ColorizeType;
|
|
55
|
-
declare const strike: ColorizeType;
|
|
56
|
-
declare const strikethrough: ColorizeType;
|
|
57
|
-
declare const strip: (string: string) => string;
|
|
58
|
-
declare const underline: ColorizeType;
|
|
59
|
-
declare const visible: ColorizeType;
|
|
60
|
-
declare const white: ColorizeType;
|
|
61
|
-
declare const whiteBright: ColorizeType;
|
|
62
|
-
declare const yellow: ColorizeType;
|
|
63
|
-
declare const yellowBright: ColorizeType;
|
|
64
|
-
|
|
65
|
-
export { Colorize, ColorizeType, ansi256, bg, bgAnsi256, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgGrey, bgHex, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgRgb, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blue, blueBright, bold, cyan, cyanBright, _default as default, dim, fg, gray, green, greenBright, grey, hex, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, rgb, strike, strikethrough, strip, underline, visible, white, whiteBright, yellow, yellowBright };
|
|
1
|
+
import ColorizeImpl from "./colorize.d.ts";
|
|
2
|
+
import type { ColorizeType } from "./types.d.ts";
|
|
3
|
+
type ColorizeTypeWithColorize = ColorizeType & {
|
|
4
|
+
Colorize: typeof ColorizeImpl;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: ColorizeTypeWithColorize;
|
|
7
|
+
export = _default;
|
|
8
|
+
export type { AnsiColors, AnsiStyles, ColorizeType } from "./types.d.ts";
|
package/dist/index.server.mjs
CHANGED
|
@@ -1 +1,61 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Colorize from './packem_shared/Colorize-BenP3bFn.mjs';
|
|
2
|
+
|
|
3
|
+
const colorize = new Colorize();
|
|
4
|
+
const ansi256 = colorize.ansi256;
|
|
5
|
+
const bg = colorize.bg;
|
|
6
|
+
const bgAnsi256 = colorize.bgAnsi256;
|
|
7
|
+
const bgHex = colorize.bgHex;
|
|
8
|
+
const bgRgb = colorize.bgRgb;
|
|
9
|
+
const fg = colorize.fg;
|
|
10
|
+
const hex = colorize.hex;
|
|
11
|
+
const rgb = colorize.rgb;
|
|
12
|
+
const strip = colorize.strip;
|
|
13
|
+
const bgBlack = colorize.bgBlack;
|
|
14
|
+
const bgBlackBright = colorize.bgBlackBright;
|
|
15
|
+
const bgBlue = colorize.bgBlue;
|
|
16
|
+
const bgBlueBright = colorize.bgBlueBright;
|
|
17
|
+
const bgCyan = colorize.bgCyan;
|
|
18
|
+
const bgCyanBright = colorize.bgCyanBright;
|
|
19
|
+
const bgGray = colorize.bgGray;
|
|
20
|
+
const bgGreen = colorize.bgGreen;
|
|
21
|
+
const bgGreenBright = colorize.bgGreenBright;
|
|
22
|
+
const bgGrey = colorize.bgGrey;
|
|
23
|
+
const bgMagenta = colorize.bgMagenta;
|
|
24
|
+
const bgMagentaBright = colorize.bgMagentaBright;
|
|
25
|
+
const bgRed = colorize.bgRed;
|
|
26
|
+
const bgRedBright = colorize.bgRedBright;
|
|
27
|
+
const bgWhite = colorize.bgWhite;
|
|
28
|
+
const bgWhiteBright = colorize.bgWhiteBright;
|
|
29
|
+
const bgYellow = colorize.bgYellow;
|
|
30
|
+
const bgYellowBright = colorize.bgYellowBright;
|
|
31
|
+
const black = colorize.black;
|
|
32
|
+
const blackBright = colorize.blackBright;
|
|
33
|
+
const blue = colorize.blue;
|
|
34
|
+
const blueBright = colorize.blueBright;
|
|
35
|
+
const bold = colorize.bold;
|
|
36
|
+
const cyan = colorize.cyan;
|
|
37
|
+
const cyanBright = colorize.cyanBright;
|
|
38
|
+
const dim = colorize.dim;
|
|
39
|
+
const gray = colorize.gray;
|
|
40
|
+
const green = colorize.green;
|
|
41
|
+
const greenBright = colorize.greenBright;
|
|
42
|
+
const grey = colorize.grey;
|
|
43
|
+
const hidden = colorize.hidden;
|
|
44
|
+
const inverse = colorize.inverse;
|
|
45
|
+
const italic = colorize.italic;
|
|
46
|
+
const magenta = colorize.magenta;
|
|
47
|
+
const magentaBright = colorize.magentaBright;
|
|
48
|
+
const overline = colorize.overline;
|
|
49
|
+
const red = colorize.red;
|
|
50
|
+
const redBright = colorize.redBright;
|
|
51
|
+
const reset = colorize.reset;
|
|
52
|
+
const strike = colorize.strike;
|
|
53
|
+
const strikethrough = colorize.strikethrough;
|
|
54
|
+
const underline = colorize.underline;
|
|
55
|
+
const visible = colorize.visible;
|
|
56
|
+
const white = colorize.white;
|
|
57
|
+
const whiteBright = colorize.whiteBright;
|
|
58
|
+
const yellow = colorize.yellow;
|
|
59
|
+
const yellowBright = colorize.yellowBright;
|
|
60
|
+
|
|
61
|
+
export { Colorize, ansi256, bg, bgAnsi256, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgGrey, bgHex, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgRgb, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blue, blueBright, bold, cyan, cyanBright, colorize as default, dim, fg, gray, green, greenBright, grey, hex, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, rgb, strike, strikethrough, strip, underline, visible, white, whiteBright, yellow, yellowBright };
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported';
|
|
2
|
+
|
|
3
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
4
|
+
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
5
|
+
const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
|
|
6
|
+
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
7
|
+
const pattern = `${osc}|${csi}`;
|
|
8
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const clamp = (number_, min, max) => min > number_ ? min : Math.min(number_, max);
|
|
12
|
+
|
|
13
|
+
const convertHexToRgb = (hex) => {
|
|
14
|
+
let [, color] = /([a-f\d]{3,6})/i.exec(hex) ?? [];
|
|
15
|
+
const length_ = color ? color.length : 0;
|
|
16
|
+
if (length_ === 3) {
|
|
17
|
+
color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
|
|
18
|
+
} else if (length_ !== 6) {
|
|
19
|
+
return [0, 0, 0];
|
|
20
|
+
}
|
|
21
|
+
const number_ = Number.parseInt(color, 16);
|
|
22
|
+
return [number_ >> 16 & 255, number_ >> 8 & 255, number_ & 255];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const rgbToAnsi256 = (r, g, b) => {
|
|
26
|
+
if (r === g && g === b) {
|
|
27
|
+
if (r < 8) {
|
|
28
|
+
return 16;
|
|
29
|
+
}
|
|
30
|
+
if (r > 248) {
|
|
31
|
+
return 231;
|
|
32
|
+
}
|
|
33
|
+
return Math.round((r - 8) / 247 * 24) + 232;
|
|
34
|
+
}
|
|
35
|
+
return 16 + 36 * Math.round(r / 51) + 6 * Math.round(g / 51) + Math.round(b / 51);
|
|
36
|
+
};
|
|
37
|
+
const ansi256To16 = (code) => {
|
|
38
|
+
let r;
|
|
39
|
+
let g;
|
|
40
|
+
let b;
|
|
41
|
+
if (code < 8) {
|
|
42
|
+
return 30 + code;
|
|
43
|
+
}
|
|
44
|
+
if (code < 16) {
|
|
45
|
+
return 90 + (code - 8);
|
|
46
|
+
}
|
|
47
|
+
if (code >= 232) {
|
|
48
|
+
r = g = b = ((code - 232) * 10 + 8) / 255;
|
|
49
|
+
} else {
|
|
50
|
+
code -= 16;
|
|
51
|
+
const remainder = code % 36;
|
|
52
|
+
r = Math.floor(code / 36) / 5;
|
|
53
|
+
g = Math.floor(remainder / 6) / 5;
|
|
54
|
+
b = remainder % 6 / 5;
|
|
55
|
+
}
|
|
56
|
+
const value = Math.max(r, g, b) * 2;
|
|
57
|
+
if (value === 0) {
|
|
58
|
+
return 30;
|
|
59
|
+
}
|
|
60
|
+
const code16 = 30 + (Math.round(b) << 2 | Math.round(g) << 1 | Math.round(r));
|
|
61
|
+
return value === 2 ? code16 + 60 : code16;
|
|
62
|
+
};
|
|
63
|
+
const rgbToAnsi16 = (r, g, b) => ansi256To16(rgbToAnsi256(r, g, b));
|
|
64
|
+
|
|
65
|
+
const closeCode = 39;
|
|
66
|
+
const bgCloseCode = 49;
|
|
67
|
+
const bgOffset = 10;
|
|
68
|
+
const supportedColor = isStdoutColorSupported();
|
|
69
|
+
const mono = { close: "", open: "" };
|
|
70
|
+
const esc = supportedColor > 0 ? (open, close) => {
|
|
71
|
+
return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
|
|
72
|
+
} : () => mono;
|
|
73
|
+
const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
|
|
74
|
+
const createHexFunction = (function_) => (hex) => {
|
|
75
|
+
const [r, g, b] = convertHexToRgb(hex);
|
|
76
|
+
return function_(r, g, b);
|
|
77
|
+
};
|
|
78
|
+
let createAnsi256 = (code) => esc(`38;5;${code}`, closeCode);
|
|
79
|
+
let createBgAnsi256 = (code) => esc(`48;5;${code}`, bgCloseCode);
|
|
80
|
+
let createRgb = (r, g, b) => esc(`38;2;${r};${g};${b}`, closeCode);
|
|
81
|
+
let createBgRgb = (r, g, b) => esc(`48;2;${r};${g};${b}`, bgCloseCode);
|
|
82
|
+
if (supportedColor === 1) {
|
|
83
|
+
createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
|
|
84
|
+
createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
|
|
85
|
+
createRgb = (r, g, b) => esc(rgbToAnsi16(Number(r), Number(g), Number(b)), closeCode);
|
|
86
|
+
createBgRgb = (r, g, b) => esc(rgbToAnsi16(Number(r), Number(g), Number(b)) + bgOffset, bgCloseCode);
|
|
87
|
+
} else if (supportedColor === 2) {
|
|
88
|
+
createRgb = createRgbFunction(createAnsi256);
|
|
89
|
+
createBgRgb = createRgbFunction(createBgAnsi256);
|
|
90
|
+
}
|
|
91
|
+
const baseStyles = {
|
|
92
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
93
|
+
bold: esc(1, 22),
|
|
94
|
+
dim: esc(2, 22),
|
|
95
|
+
hidden: esc(8, 28),
|
|
96
|
+
inverse: esc(7, 27),
|
|
97
|
+
italic: esc(3, 23),
|
|
98
|
+
overline: esc(53, 55),
|
|
99
|
+
reset: esc(0, 0),
|
|
100
|
+
strike: esc(9, 29),
|
|
101
|
+
// alias for strikethrough
|
|
102
|
+
strikethrough: esc(9, 29),
|
|
103
|
+
underline: esc(4, 24),
|
|
104
|
+
visible: mono
|
|
105
|
+
};
|
|
106
|
+
const baseColors = {
|
|
107
|
+
bgBlack: esc(40, bgCloseCode),
|
|
108
|
+
bgBlackBright: esc(100, bgCloseCode),
|
|
109
|
+
bgBlue: esc(44, bgCloseCode),
|
|
110
|
+
bgBlueBright: esc(104, bgCloseCode),
|
|
111
|
+
bgCyan: esc(46, bgCloseCode),
|
|
112
|
+
bgCyanBright: esc(106, bgCloseCode),
|
|
113
|
+
bgGray: esc(100, bgCloseCode),
|
|
114
|
+
// US spelling alias for bgBlackBright
|
|
115
|
+
bgGreen: esc(42, bgCloseCode),
|
|
116
|
+
bgGreenBright: esc(102, bgCloseCode),
|
|
117
|
+
bgGrey: esc(100, bgCloseCode),
|
|
118
|
+
// UK spelling alias for bgBlackBright
|
|
119
|
+
bgMagenta: esc(45, bgCloseCode),
|
|
120
|
+
bgMagentaBright: esc(105, bgCloseCode),
|
|
121
|
+
bgRed: esc(41, bgCloseCode),
|
|
122
|
+
bgRedBright: esc(101, bgCloseCode),
|
|
123
|
+
bgWhite: esc(47, bgCloseCode),
|
|
124
|
+
bgWhiteBright: esc(107, bgCloseCode),
|
|
125
|
+
bgYellow: esc(43, bgCloseCode),
|
|
126
|
+
bgYellowBright: esc(103, bgCloseCode),
|
|
127
|
+
black: esc(30, closeCode),
|
|
128
|
+
blackBright: esc(90, closeCode),
|
|
129
|
+
blue: esc(34, closeCode),
|
|
130
|
+
blueBright: esc(94, closeCode),
|
|
131
|
+
cyan: esc(36, closeCode),
|
|
132
|
+
cyanBright: esc(96, closeCode),
|
|
133
|
+
gray: esc(90, closeCode),
|
|
134
|
+
// US spelling alias for blackBright
|
|
135
|
+
green: esc(32, closeCode),
|
|
136
|
+
greenBright: esc(92, closeCode),
|
|
137
|
+
grey: esc(90, closeCode),
|
|
138
|
+
// UK spelling alias for blackBright
|
|
139
|
+
magenta: esc(35, closeCode),
|
|
140
|
+
magentaBright: esc(95, closeCode),
|
|
141
|
+
red: esc(31, closeCode),
|
|
142
|
+
redBright: esc(91, closeCode),
|
|
143
|
+
white: esc(37, closeCode),
|
|
144
|
+
whiteBright: esc(97, closeCode),
|
|
145
|
+
yellow: esc(33, closeCode),
|
|
146
|
+
yellowBright: esc(93, closeCode)
|
|
147
|
+
};
|
|
148
|
+
const styleMethods = {
|
|
149
|
+
bg: (code) => createBgAnsi256(clamp(code, 0, 255)),
|
|
150
|
+
bgHex: createHexFunction(createBgRgb),
|
|
151
|
+
bgRgb: (r, g, b) => createBgRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255)),
|
|
152
|
+
fg: (code) => createAnsi256(clamp(code, 0, 255)),
|
|
153
|
+
hex: createHexFunction(createRgb),
|
|
154
|
+
rgb: (r, g, b) => createRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255))
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const stringReplaceAll = (string_, searchValue, replaceValue) => {
|
|
158
|
+
if (searchValue === "") {
|
|
159
|
+
return string_;
|
|
160
|
+
}
|
|
161
|
+
let pos = string_.indexOf(searchValue);
|
|
162
|
+
if (pos < 0) {
|
|
163
|
+
return string_;
|
|
164
|
+
}
|
|
165
|
+
const substringLength = searchValue.length;
|
|
166
|
+
let lastPos = 0;
|
|
167
|
+
let result = "";
|
|
168
|
+
while (~pos) {
|
|
169
|
+
result += string_.slice(lastPos, pos) + replaceValue;
|
|
170
|
+
lastPos = pos + substringLength;
|
|
171
|
+
pos = string_.indexOf(searchValue, lastPos);
|
|
172
|
+
}
|
|
173
|
+
return result + string_.slice(lastPos);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const styles = {};
|
|
177
|
+
let stylePrototype = null;
|
|
178
|
+
const wrapText = (strings, values, properties) => {
|
|
179
|
+
if (!strings) {
|
|
180
|
+
return "";
|
|
181
|
+
}
|
|
182
|
+
let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
|
|
183
|
+
if (string.includes("\x1B")) {
|
|
184
|
+
for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
|
|
185
|
+
string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (string.includes("\n")) {
|
|
189
|
+
string = string.replace(/(\r*\n)/g, `${properties.closeStack}$1${properties.openStack}`);
|
|
190
|
+
}
|
|
191
|
+
return properties.openStack + string + properties.closeStack;
|
|
192
|
+
};
|
|
193
|
+
const createStyle = ({ props }, { close, open }) => {
|
|
194
|
+
const openStack = (props?.openStack ?? "") + open;
|
|
195
|
+
const closeStack = close + (props?.closeStack ?? "");
|
|
196
|
+
const style = (strings, ...values) => wrapText(strings, values, style.props);
|
|
197
|
+
Object.setPrototypeOf(style, stylePrototype);
|
|
198
|
+
style.props = { close, closeStack, open, openStack, props };
|
|
199
|
+
style.open = openStack;
|
|
200
|
+
style.close = closeStack;
|
|
201
|
+
return style;
|
|
202
|
+
};
|
|
203
|
+
const Colorize = function() {
|
|
204
|
+
const self = (string_) => `${string_}`;
|
|
205
|
+
self.strip = (value) => value.replaceAll(ansiRegex(), "");
|
|
206
|
+
for (const name in baseColors) {
|
|
207
|
+
styles[name] = {
|
|
208
|
+
get() {
|
|
209
|
+
const style = createStyle(this, baseColors[name]);
|
|
210
|
+
Object.defineProperty(this, name, { value: style });
|
|
211
|
+
return style;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
for (const name in baseStyles) {
|
|
216
|
+
styles[name] = {
|
|
217
|
+
get() {
|
|
218
|
+
const style = createStyle(this, baseStyles[name]);
|
|
219
|
+
Object.defineProperty(this, name, { value: style });
|
|
220
|
+
return style;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
stylePrototype = Object.defineProperties({}, styles);
|
|
225
|
+
Object.setPrototypeOf(self, stylePrototype);
|
|
226
|
+
return self;
|
|
227
|
+
};
|
|
228
|
+
for (const name in styleMethods) {
|
|
229
|
+
styles[name] = {
|
|
230
|
+
get() {
|
|
231
|
+
return (...arguments_) => (
|
|
232
|
+
// @ts-expect-error: TODO: fix typing of `arguments_`
|
|
233
|
+
createStyle(this, styleMethods[name](...arguments_))
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
styles.ansi256 = styles.fg;
|
|
239
|
+
styles.bgAnsi256 = styles.bg;
|
|
240
|
+
|
|
241
|
+
export { Colorize as default };
|