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