@visulima/colorize 2.0.0-alpha.7 → 2.0.0-alpha.9
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 +32 -0
- package/dist/gradient.cjs +9 -7
- package/dist/gradient.d.cts +2 -2
- package/dist/gradient.d.mts +2 -2
- package/dist/gradient.d.ts +2 -2
- package/dist/gradient.mjs +9 -7
- package/dist/index.browser.d.mts +2 -2
- package/dist/index.browser.mjs +1 -1
- package/dist/index.server.cjs +26 -16
- package/dist/index.server.d.cts +2 -2
- package/dist/index.server.d.mts +2 -2
- package/dist/index.server.d.ts +2 -2
- package/dist/index.server.mjs +1 -1
- package/dist/packem_shared/{Colorize-Ca9CXTcj.js → Colorize-BQ-Wlgs0.js} +9 -13
- package/dist/packem_shared/{Colorize-BenP3bFn.js → Colorize-q7kOM0WA.js} +26 -16
- package/dist/packem_shared/{GradientBuilder-DTnSGyYW.mjs → GradientBuilder-CkX4Imo9.mjs} +36 -39
- package/dist/packem_shared/{GradientBuilder-BXOgJeHi.cjs → GradientBuilder-DRrwebdU.cjs} +36 -39
- package/dist/packem_shared/{colorize.server-ry9FZNfG.mjs → colorize.server-DeZHO6IN.mjs} +15 -10
- package/dist/packem_shared/{colorize.server-BA3gZZXz.cjs → colorize.server-XetY_pdz.cjs} +15 -10
- package/dist/packem_shared/convertHexToRgb-51-edHxE.cjs +21 -0
- package/dist/packem_shared/convertHexToRgb-BZwJEiMZ.mjs +17 -0
- package/dist/packem_shared/{rgbToAnsi256-BdS0fomP.mjs → rgbToAnsi256-Bca58HoN.mjs} +2 -1
- package/dist/packem_shared/{rgbToAnsi256-DL8eajTz.cjs → rgbToAnsi256-C3-josZP.cjs} +2 -1
- package/dist/template/make-template.d.cts +1 -1
- package/dist/template/make-template.d.mts +1 -1
- package/dist/template/make-template.d.ts +1 -1
- package/dist/template.cjs +19 -8
- package/dist/template.d.cts +1 -1
- package/dist/template.d.mts +1 -1
- package/dist/template.d.ts +1 -1
- package/dist/template.mjs +19 -8
- package/dist/types.d.cts +3 -3
- package/dist/types.d.mts +3 -3
- package/dist/types.d.ts +3 -3
- package/dist/util/clamp.d.cts +1 -1
- package/dist/util/clamp.d.mts +1 -1
- package/dist/util/clamp.d.ts +1 -1
- package/dist/util/convert-hex-to-rgb.d.cts +1 -15
- package/dist/util/convert-hex-to-rgb.d.mts +1 -15
- package/dist/util/convert-hex-to-rgb.d.ts +1 -15
- package/dist/utils.cjs +2 -2
- package/dist/utils.mjs +2 -2
- package/package.json +2 -4
- package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +0 -13
- package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
## @visulima/colorize [2.0.0-alpha.9](https://github.com/visulima/visulima/compare/@visulima/colorize@2.0.0-alpha.8...@visulima/colorize@2.0.0-alpha.9) (2026-04-15)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **colorize:** resolve eslint and formatting issues ([edc292a](https://github.com/visulima/visulima/commit/edc292a567fb3a97e6428e6fee86b47137e00952))
|
|
6
|
+
* **terminal:** resolve eslint and formatting issues ([8f30389](https://github.com/visulima/visulima/commit/8f30389deb9ff81e7afce0aa064ef11fcb179f23))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Dependencies
|
|
10
|
+
|
|
11
|
+
* **@visulima/is-ansi-color-supported:** upgraded to 3.0.0-alpha.9
|
|
12
|
+
|
|
13
|
+
## @visulima/colorize [2.0.0-alpha.8](https://github.com/visulima/visulima/compare/@visulima/colorize@2.0.0-alpha.7...@visulima/colorize@2.0.0-alpha.8) (2026-04-08)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **colorize:** properly fix eslint errors in code ([c9941a4](https://github.com/visulima/visulima/commit/c9941a42e04570c7a4f39e4f65424b507a58352d))
|
|
18
|
+
* resolve failing tests across multiple packages ([2b4b6f0](https://github.com/visulima/visulima/commit/2b4b6f04169b60fdc4cf77b293015436a272c0fb))
|
|
19
|
+
|
|
20
|
+
### Miscellaneous Chores
|
|
21
|
+
|
|
22
|
+
* apply linting and formatting fixes across packages ([5d150a5](https://github.com/visulima/visulima/commit/5d150a578f9ce861c791843c683deeb849b774a9))
|
|
23
|
+
* **colorize:** add tsconfig.eslint.json for type-aware linting ([0a2b596](https://github.com/visulima/visulima/commit/0a2b596b74df932cf492400029ecdaf572b8f474))
|
|
24
|
+
* **colorize:** apply prettier formatting ([f572dc4](https://github.com/visulima/visulima/commit/f572dc47f1398070adc5d4879d9f99870fe71760))
|
|
25
|
+
* **colorize:** migrate .prettierrc.cjs to prettier.config.js ([6d84ecc](https://github.com/visulima/visulima/commit/6d84eccbfba7ff59fd7463ef973b80d50d85f464))
|
|
26
|
+
* **terminal:** remove empty dependency objects from package.json ([562c704](https://github.com/visulima/visulima/commit/562c704e5d90aa2d13eae942ebbdcfeb787c2b46))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Dependencies
|
|
30
|
+
|
|
31
|
+
* **@visulima/is-ansi-color-supported:** upgraded to 3.0.0-alpha.8
|
|
32
|
+
|
|
1
33
|
## @visulima/colorize [2.0.0-alpha.7](https://github.com/visulima/visulima/compare/@visulima/colorize@2.0.0-alpha.6...@visulima/colorize@2.0.0-alpha.7) (2026-03-26)
|
|
2
34
|
|
|
3
35
|
### Features
|
package/dist/gradient.cjs
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
4
|
|
|
5
|
-
const colorize_server = require('./packem_shared/colorize.server-
|
|
6
|
-
const GradientBuilder = require('./packem_shared/GradientBuilder-
|
|
5
|
+
const colorize_server = require('./packem_shared/colorize.server-XetY_pdz.cjs');
|
|
6
|
+
const GradientBuilder = require('./packem_shared/GradientBuilder-DRrwebdU.cjs');
|
|
7
7
|
|
|
8
8
|
const colorize = new colorize_server.Colorize();
|
|
9
|
-
const
|
|
9
|
+
const WHITESPACE_GLOBAL = /\s/g;
|
|
10
|
+
const WHITESPACE_TEST = /\s/;
|
|
10
11
|
const gradient = (stops, options) => {
|
|
11
12
|
const { hsvSpin = "short", interpolation = "rgb" } = options ?? {};
|
|
12
13
|
let builder = new GradientBuilder.GradientBuilder(colorize, stops);
|
|
@@ -16,11 +17,12 @@ const gradient = (stops, options) => {
|
|
|
16
17
|
builder = builder.reverse();
|
|
17
18
|
}
|
|
18
19
|
return (string_) => {
|
|
19
|
-
const
|
|
20
|
+
const stripped = string_.replaceAll(WHITESPACE_GLOBAL, "");
|
|
21
|
+
const colorsCount = Math.max(stripped.length, builder.stops.length);
|
|
20
22
|
const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
|
|
21
23
|
let result = "";
|
|
22
24
|
for (const s of string_) {
|
|
23
|
-
if (
|
|
25
|
+
if (WHITESPACE_TEST.test(s)) {
|
|
24
26
|
result += s;
|
|
25
27
|
} else {
|
|
26
28
|
const color = colors.shift();
|
|
@@ -40,14 +42,14 @@ const multilineGradient = (stops, options) => {
|
|
|
40
42
|
}
|
|
41
43
|
return (string_) => {
|
|
42
44
|
const lines = string_.split("\n");
|
|
43
|
-
const colorsCount = Reflect.apply(Math.max,
|
|
45
|
+
const colorsCount = Reflect.apply(Math.max, void 0, [...lines.map((l) => l.length), builder.stops.length]);
|
|
44
46
|
const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
|
|
45
47
|
const results = [];
|
|
46
48
|
for (const line of lines) {
|
|
47
49
|
const lineColors = [...colors];
|
|
48
50
|
let lineResult = "";
|
|
49
51
|
for (const l of line) {
|
|
50
|
-
lineResult +=
|
|
52
|
+
lineResult += WHITESPACE_TEST.test(l) ? l : lineColors.shift()(l);
|
|
51
53
|
}
|
|
52
54
|
results.push(lineResult);
|
|
53
55
|
}
|
package/dist/gradient.d.cts
CHANGED
|
@@ -4,11 +4,11 @@ export declare const gradient: (stops: (ColorValueHex | CssColorName | RGB | Sto
|
|
|
4
4
|
interpolation?: "hsv" | "rgb";
|
|
5
5
|
loop?: boolean;
|
|
6
6
|
reverse?: boolean;
|
|
7
|
-
}) => (string_: string) => string;
|
|
7
|
+
}) => ((string_: string) => string);
|
|
8
8
|
export declare const multilineGradient: (stops: (ColorValueHex | CssColorName | RGB | StopInput | [number, number, number])[], options?: {
|
|
9
9
|
hsvSpin?: "long" | "short";
|
|
10
10
|
interpolation?: "hsv" | "rgb";
|
|
11
11
|
loop?: boolean;
|
|
12
12
|
reverse?: boolean;
|
|
13
|
-
}) => (string_: string) => string;
|
|
13
|
+
}) => ((string_: string) => string);
|
|
14
14
|
export { GradientBuilder } from "./gradient/gradient-builder.d.cts";
|
package/dist/gradient.d.mts
CHANGED
|
@@ -4,11 +4,11 @@ export declare const gradient: (stops: (ColorValueHex | CssColorName | RGB | Sto
|
|
|
4
4
|
interpolation?: "hsv" | "rgb";
|
|
5
5
|
loop?: boolean;
|
|
6
6
|
reverse?: boolean;
|
|
7
|
-
}) => (string_: string) => string;
|
|
7
|
+
}) => ((string_: string) => string);
|
|
8
8
|
export declare const multilineGradient: (stops: (ColorValueHex | CssColorName | RGB | StopInput | [number, number, number])[], options?: {
|
|
9
9
|
hsvSpin?: "long" | "short";
|
|
10
10
|
interpolation?: "hsv" | "rgb";
|
|
11
11
|
loop?: boolean;
|
|
12
12
|
reverse?: boolean;
|
|
13
|
-
}) => (string_: string) => string;
|
|
13
|
+
}) => ((string_: string) => string);
|
|
14
14
|
export { GradientBuilder } from "./gradient/gradient-builder.d.mts";
|
package/dist/gradient.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ export declare const gradient: (stops: (ColorValueHex | CssColorName | RGB | Sto
|
|
|
4
4
|
interpolation?: "hsv" | "rgb";
|
|
5
5
|
loop?: boolean;
|
|
6
6
|
reverse?: boolean;
|
|
7
|
-
}) => (string_: string) => string;
|
|
7
|
+
}) => ((string_: string) => string);
|
|
8
8
|
export declare const multilineGradient: (stops: (ColorValueHex | CssColorName | RGB | StopInput | [number, number, number])[], options?: {
|
|
9
9
|
hsvSpin?: "long" | "short";
|
|
10
10
|
interpolation?: "hsv" | "rgb";
|
|
11
11
|
loop?: boolean;
|
|
12
12
|
reverse?: boolean;
|
|
13
|
-
}) => (string_: string) => string;
|
|
13
|
+
}) => ((string_: string) => string);
|
|
14
14
|
export { GradientBuilder } from "./gradient/gradient-builder.d.ts";
|
package/dist/gradient.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { C as Colorize } from './packem_shared/colorize.server-
|
|
2
|
-
import { GradientBuilder } from './packem_shared/GradientBuilder-
|
|
1
|
+
import { C as Colorize } from './packem_shared/colorize.server-DeZHO6IN.mjs';
|
|
2
|
+
import { GradientBuilder } from './packem_shared/GradientBuilder-CkX4Imo9.mjs';
|
|
3
3
|
|
|
4
4
|
const colorize = new Colorize();
|
|
5
|
-
const
|
|
5
|
+
const WHITESPACE_GLOBAL = /\s/g;
|
|
6
|
+
const WHITESPACE_TEST = /\s/;
|
|
6
7
|
const gradient = (stops, options) => {
|
|
7
8
|
const { hsvSpin = "short", interpolation = "rgb" } = options ?? {};
|
|
8
9
|
let builder = new GradientBuilder(colorize, stops);
|
|
@@ -12,11 +13,12 @@ const gradient = (stops, options) => {
|
|
|
12
13
|
builder = builder.reverse();
|
|
13
14
|
}
|
|
14
15
|
return (string_) => {
|
|
15
|
-
const
|
|
16
|
+
const stripped = string_.replaceAll(WHITESPACE_GLOBAL, "");
|
|
17
|
+
const colorsCount = Math.max(stripped.length, builder.stops.length);
|
|
16
18
|
const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
|
|
17
19
|
let result = "";
|
|
18
20
|
for (const s of string_) {
|
|
19
|
-
if (
|
|
21
|
+
if (WHITESPACE_TEST.test(s)) {
|
|
20
22
|
result += s;
|
|
21
23
|
} else {
|
|
22
24
|
const color = colors.shift();
|
|
@@ -36,14 +38,14 @@ const multilineGradient = (stops, options) => {
|
|
|
36
38
|
}
|
|
37
39
|
return (string_) => {
|
|
38
40
|
const lines = string_.split("\n");
|
|
39
|
-
const colorsCount = Reflect.apply(Math.max,
|
|
41
|
+
const colorsCount = Reflect.apply(Math.max, void 0, [...lines.map((l) => l.length), builder.stops.length]);
|
|
40
42
|
const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
|
|
41
43
|
const results = [];
|
|
42
44
|
for (const line of lines) {
|
|
43
45
|
const lineColors = [...colors];
|
|
44
46
|
let lineResult = "";
|
|
45
47
|
for (const l of line) {
|
|
46
|
-
lineResult +=
|
|
48
|
+
lineResult += WHITESPACE_TEST.test(l) ? l : lineColors.shift()(l);
|
|
47
49
|
}
|
|
48
50
|
results.push(lineResult);
|
|
49
51
|
}
|
package/dist/index.browser.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ColorizeType, ColorValueHex } from "./types.d.ts";
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const colorize: ColorizeType;
|
|
3
|
+
export default colorize;
|
|
4
4
|
export declare const ansi256: (code: number) => ColorizeType;
|
|
5
5
|
export declare const bg: (code: number) => ColorizeType;
|
|
6
6
|
export declare const bgAnsi256: (code: number) => ColorizeType;
|
package/dist/index.browser.mjs
CHANGED
package/dist/index.server.cjs
CHANGED
|
@@ -10,18 +10,27 @@ function ansiRegex({ onlyFirst = false } = {}) {
|
|
|
10
10
|
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const clamp = (number_, min, max) =>
|
|
13
|
+
const clamp = (number_, min, max) => {
|
|
14
|
+
if (min > number_) {
|
|
15
|
+
return min;
|
|
16
|
+
}
|
|
17
|
+
return Math.min(number_, max);
|
|
18
|
+
};
|
|
14
19
|
|
|
20
|
+
const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
|
|
15
21
|
const convertHexToRgb = (hex) => {
|
|
16
|
-
let [, color] =
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
|
|
23
|
+
const colorLength = color ? color.length : 0;
|
|
24
|
+
if (colorLength === 3) {
|
|
25
|
+
const c0 = color.charAt(0);
|
|
26
|
+
const c1 = color.charAt(1);
|
|
27
|
+
const c2 = color.charAt(2);
|
|
28
|
+
color = c0 + c0 + c1 + c1 + c2 + c2;
|
|
29
|
+
} else if (colorLength !== 6) {
|
|
21
30
|
return [0, 0, 0];
|
|
22
31
|
}
|
|
23
|
-
const
|
|
24
|
-
return [
|
|
32
|
+
const colorNumber = Number.parseInt(color, 16);
|
|
33
|
+
return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
|
|
25
34
|
};
|
|
26
35
|
|
|
27
36
|
const rgbToAnsi256 = (r, g, b) => {
|
|
@@ -34,7 +43,8 @@ const rgbToAnsi256 = (r, g, b) => {
|
|
|
34
43
|
}
|
|
35
44
|
return Math.round((r - 8) / 247 * 24) + 232;
|
|
36
45
|
}
|
|
37
|
-
return 16 +
|
|
46
|
+
return 16 + // r / 255 * 5 => r / 51
|
|
47
|
+
36 * Math.round(r / 51) + 6 * Math.round(g / 51) + Math.round(b / 51);
|
|
38
48
|
};
|
|
39
49
|
const ansi256To16 = (code) => {
|
|
40
50
|
let r;
|
|
@@ -70,17 +80,17 @@ const bgOffset = 10;
|
|
|
70
80
|
const supportedColor = isAnsiColorSupported.isStdoutColorSupported();
|
|
71
81
|
const mono = { close: "", open: "" };
|
|
72
82
|
const esc = supportedColor > 0 ? (open, close) => {
|
|
73
|
-
return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
|
|
83
|
+
return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
|
|
74
84
|
} : () => mono;
|
|
75
85
|
const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
|
|
76
86
|
const createHexFunction = (function_) => (hex) => {
|
|
77
87
|
const [r, g, b] = convertHexToRgb(hex);
|
|
78
88
|
return function_(r, g, b);
|
|
79
89
|
};
|
|
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);
|
|
90
|
+
let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
|
|
91
|
+
let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
|
|
92
|
+
let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
|
|
93
|
+
let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
|
|
84
94
|
if (supportedColor === 1) {
|
|
85
95
|
createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
|
|
86
96
|
createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
|
|
@@ -181,7 +191,7 @@ const wrapText = (strings, values, properties) => {
|
|
|
181
191
|
if (!strings) {
|
|
182
192
|
return "";
|
|
183
193
|
}
|
|
184
|
-
let string = strings.raw
|
|
194
|
+
let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
|
|
185
195
|
if (string.includes("\x1B")) {
|
|
186
196
|
for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
|
|
187
197
|
string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
|
|
@@ -203,7 +213,7 @@ const createStyle = ({ props }, { close, open }) => {
|
|
|
203
213
|
return style;
|
|
204
214
|
};
|
|
205
215
|
const Colorize = function() {
|
|
206
|
-
const self = (string_) =>
|
|
216
|
+
const self = (string_) => String(string_);
|
|
207
217
|
self.strip = (value) => value.replaceAll(ansiRegex(), "");
|
|
208
218
|
for (const name in baseColors) {
|
|
209
219
|
styles[name] = {
|
package/dist/index.server.d.cts
CHANGED
|
@@ -3,6 +3,6 @@ import type { ColorizeType } from "./types.d.cts";
|
|
|
3
3
|
type ColorizeTypeWithColorize = ColorizeType & {
|
|
4
4
|
Colorize: typeof ColorizeImpl;
|
|
5
5
|
};
|
|
6
|
-
declare const
|
|
7
|
-
export =
|
|
6
|
+
declare const colorize: ColorizeTypeWithColorize;
|
|
7
|
+
export = colorize;
|
|
8
8
|
export type { AnsiColors, AnsiStyles, ColorizeType } from "./types.d.cts";
|
package/dist/index.server.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ColorizeType, ColorValueHex } from "./types.d.ts";
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const colorize: ColorizeType;
|
|
3
|
+
export default colorize;
|
|
4
4
|
export declare const ansi256: (code: number) => ColorizeType;
|
|
5
5
|
export declare const bg: (code: number) => ColorizeType;
|
|
6
6
|
export declare const bgAnsi256: (code: number) => ColorizeType;
|
package/dist/index.server.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import type { ColorizeType } from "./types.d.ts";
|
|
|
3
3
|
type ColorizeTypeWithColorize = ColorizeType & {
|
|
4
4
|
Colorize: typeof ColorizeImpl;
|
|
5
5
|
};
|
|
6
|
-
declare const
|
|
7
|
-
export =
|
|
6
|
+
declare const colorize: ColorizeTypeWithColorize;
|
|
7
|
+
export = colorize;
|
|
8
8
|
export type { AnsiColors, AnsiStyles, ColorizeType } from "./types.d.ts";
|
package/dist/index.server.mjs
CHANGED
|
@@ -313,14 +313,12 @@ const baseColors = {
|
|
|
313
313
|
yellowBright: "color: #ff5;"
|
|
314
314
|
};
|
|
315
315
|
const styleMethods = {
|
|
316
|
-
|
|
317
|
-
bg: (code) => `background-color: ${ansiCodeHexMap[code]};`,
|
|
316
|
+
bg: (code) => `background-color: ${ansiCodeHexMap[code] ?? ""};`,
|
|
318
317
|
bgHex: (hex) => `background-color: ${hex};`,
|
|
319
|
-
bgRgb: (r, g, b) => `background-color: rgb(${r},${g},${b});`,
|
|
320
|
-
|
|
321
|
-
fg: (code) => `color: ${ansiCodeHexMap[code]};`,
|
|
318
|
+
bgRgb: (r, g, b) => `background-color: rgb(${String(r)},${String(g)},${String(b)});`,
|
|
319
|
+
fg: (code) => `color: ${ansiCodeHexMap[code] ?? ""};`,
|
|
322
320
|
hex: (hex) => `color:${hex};`,
|
|
323
|
-
rgb: (r, g, b) => `color: rgb(${r},${g},${b});`
|
|
321
|
+
rgb: (r, g, b) => `color: rgb(${String(r)},${String(g)},${String(b)});`
|
|
324
322
|
};
|
|
325
323
|
|
|
326
324
|
const styles = {};
|
|
@@ -339,9 +337,7 @@ const createStyle = ({ props }, css) => {
|
|
|
339
337
|
const cssObject = cssStringToObject(css);
|
|
340
338
|
const propertiesCssObject = cssStringToObject(props.cssStack);
|
|
341
339
|
for (const key in propertiesCssObject) {
|
|
342
|
-
|
|
343
|
-
cssObject[key] = propertiesCssObject[key];
|
|
344
|
-
}
|
|
340
|
+
cssObject[key] ??= propertiesCssObject[key];
|
|
345
341
|
}
|
|
346
342
|
cssStack = `${JSON.stringify(cssObject).replace(/["{}]/g, "").replace(/,/g, ";")};`;
|
|
347
343
|
}
|
|
@@ -355,9 +351,9 @@ const createStyle = ({ props }, css) => {
|
|
|
355
351
|
return [`%c${inputWithoutStyles}`, style.css, ...collectedStyles ?? []];
|
|
356
352
|
}
|
|
357
353
|
if (typeof input === "number" || typeof input === "string") {
|
|
358
|
-
return [`%c${input}`, style.css];
|
|
354
|
+
return [`%c${String(input)}`, style.css];
|
|
359
355
|
}
|
|
360
|
-
if (input.raw !==
|
|
356
|
+
if (input.raw !== void 0 && Array.isArray(values) && values.length > 0) {
|
|
361
357
|
const rawString = String.raw(input, ...values);
|
|
362
358
|
const collectedStyles = rawString.match(/(?<=,).*;/g);
|
|
363
359
|
const inputWithoutStyles = rawString.replace(/,.*;/g, "");
|
|
@@ -365,7 +361,7 @@ const createStyle = ({ props }, css) => {
|
|
|
365
361
|
}
|
|
366
362
|
const [first, ...rest] = input;
|
|
367
363
|
rest.unshift(style.css);
|
|
368
|
-
return [`${
|
|
364
|
+
return [`${String(first).includes("%c") ? "" : "%c"}${String(first)}`, rest.join("")];
|
|
369
365
|
};
|
|
370
366
|
Object.setPrototypeOf(style, stylePrototype);
|
|
371
367
|
style.props = { css, cssStack, props };
|
|
@@ -373,7 +369,7 @@ const createStyle = ({ props }, css) => {
|
|
|
373
369
|
return style;
|
|
374
370
|
};
|
|
375
371
|
const WebColorize = function() {
|
|
376
|
-
const self = (string_) =>
|
|
372
|
+
const self = (string_) => String(string_);
|
|
377
373
|
self.strip = (value) => value;
|
|
378
374
|
for (const name in baseColors) {
|
|
379
375
|
styles[name] = {
|
|
@@ -8,18 +8,27 @@ function ansiRegex({ onlyFirst = false } = {}) {
|
|
|
8
8
|
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const clamp = (number_, min, max) =>
|
|
11
|
+
const clamp = (number_, min, max) => {
|
|
12
|
+
if (min > number_) {
|
|
13
|
+
return min;
|
|
14
|
+
}
|
|
15
|
+
return Math.min(number_, max);
|
|
16
|
+
};
|
|
12
17
|
|
|
18
|
+
const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
|
|
13
19
|
const convertHexToRgb = (hex) => {
|
|
14
|
-
let [, color] =
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
|
|
21
|
+
const colorLength = color ? color.length : 0;
|
|
22
|
+
if (colorLength === 3) {
|
|
23
|
+
const c0 = color.charAt(0);
|
|
24
|
+
const c1 = color.charAt(1);
|
|
25
|
+
const c2 = color.charAt(2);
|
|
26
|
+
color = c0 + c0 + c1 + c1 + c2 + c2;
|
|
27
|
+
} else if (colorLength !== 6) {
|
|
19
28
|
return [0, 0, 0];
|
|
20
29
|
}
|
|
21
|
-
const
|
|
22
|
-
return [
|
|
30
|
+
const colorNumber = Number.parseInt(color, 16);
|
|
31
|
+
return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
|
|
23
32
|
};
|
|
24
33
|
|
|
25
34
|
const rgbToAnsi256 = (r, g, b) => {
|
|
@@ -32,7 +41,8 @@ const rgbToAnsi256 = (r, g, b) => {
|
|
|
32
41
|
}
|
|
33
42
|
return Math.round((r - 8) / 247 * 24) + 232;
|
|
34
43
|
}
|
|
35
|
-
return 16 +
|
|
44
|
+
return 16 + // r / 255 * 5 => r / 51
|
|
45
|
+
36 * Math.round(r / 51) + 6 * Math.round(g / 51) + Math.round(b / 51);
|
|
36
46
|
};
|
|
37
47
|
const ansi256To16 = (code) => {
|
|
38
48
|
let r;
|
|
@@ -68,17 +78,17 @@ const bgOffset = 10;
|
|
|
68
78
|
const supportedColor = isStdoutColorSupported();
|
|
69
79
|
const mono = { close: "", open: "" };
|
|
70
80
|
const esc = supportedColor > 0 ? (open, close) => {
|
|
71
|
-
return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
|
|
81
|
+
return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
|
|
72
82
|
} : () => mono;
|
|
73
83
|
const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
|
|
74
84
|
const createHexFunction = (function_) => (hex) => {
|
|
75
85
|
const [r, g, b] = convertHexToRgb(hex);
|
|
76
86
|
return function_(r, g, b);
|
|
77
87
|
};
|
|
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);
|
|
88
|
+
let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
|
|
89
|
+
let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
|
|
90
|
+
let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
|
|
91
|
+
let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
|
|
82
92
|
if (supportedColor === 1) {
|
|
83
93
|
createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
|
|
84
94
|
createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
|
|
@@ -179,7 +189,7 @@ const wrapText = (strings, values, properties) => {
|
|
|
179
189
|
if (!strings) {
|
|
180
190
|
return "";
|
|
181
191
|
}
|
|
182
|
-
let string = strings.raw
|
|
192
|
+
let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
|
|
183
193
|
if (string.includes("\x1B")) {
|
|
184
194
|
for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
|
|
185
195
|
string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
|
|
@@ -201,7 +211,7 @@ const createStyle = ({ props }, { close, open }) => {
|
|
|
201
211
|
return style;
|
|
202
212
|
};
|
|
203
213
|
const Colorize = function() {
|
|
204
|
-
const self = (string_) =>
|
|
214
|
+
const self = (string_) => String(string_);
|
|
205
215
|
self.strip = (value) => value.replaceAll(ansiRegex(), "");
|
|
206
216
|
for (const name in baseColors) {
|
|
207
217
|
styles[name] = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { convertHexToRgb } from './convertHexToRgb-
|
|
1
|
+
import { convertHexToRgb } from './convertHexToRgb-BZwJEiMZ.mjs';
|
|
2
2
|
|
|
3
3
|
const colorNames = {
|
|
4
4
|
aliceblue: [240, 248, 255],
|
|
@@ -161,23 +161,25 @@ const computeSubSteps = (stops, steps) => {
|
|
|
161
161
|
throw new Error("Number of steps cannot be inferior to number of stops");
|
|
162
162
|
}
|
|
163
163
|
const substeps = [];
|
|
164
|
-
for (let index = 1; index < l; index
|
|
164
|
+
for (let index = 1; index < l; index += 1) {
|
|
165
165
|
const step = (steps - 1) * (stops[index].position - stops[index - 1].position);
|
|
166
166
|
substeps.push(Math.max(1, Math.round(step)));
|
|
167
167
|
}
|
|
168
168
|
let totalSubsteps = 1;
|
|
169
|
-
for (let n = l -
|
|
169
|
+
for (let n = l - 2; n >= 0; n -= 1) {
|
|
170
170
|
totalSubsteps += substeps[n];
|
|
171
171
|
}
|
|
172
172
|
while (totalSubsteps !== steps) {
|
|
173
173
|
if (totalSubsteps < steps) {
|
|
174
174
|
const min = Math.min(...substeps);
|
|
175
|
-
substeps
|
|
176
|
-
|
|
175
|
+
const minIndex = substeps.indexOf(min);
|
|
176
|
+
substeps[minIndex] = substeps[minIndex] + 1;
|
|
177
|
+
totalSubsteps += 1;
|
|
177
178
|
} else {
|
|
178
179
|
const max = Math.max(...substeps);
|
|
179
|
-
substeps
|
|
180
|
-
|
|
180
|
+
const maxIndex = substeps.indexOf(max);
|
|
181
|
+
substeps[maxIndex] = substeps[maxIndex] - 1;
|
|
182
|
+
totalSubsteps -= 1;
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
185
|
return substeps;
|
|
@@ -262,7 +264,7 @@ const HSV_MAX = { h: 360, s: 1, v: 1 };
|
|
|
262
264
|
const calculateStepSize = (start, end, steps) => {
|
|
263
265
|
const step = {};
|
|
264
266
|
for (const k in start) {
|
|
265
|
-
if (Object.
|
|
267
|
+
if (Object.hasOwn(start, k)) {
|
|
266
268
|
step[k] = steps === 0 ? 0 : (end[k] - start[k]) / steps;
|
|
267
269
|
}
|
|
268
270
|
}
|
|
@@ -271,21 +273,14 @@ const calculateStepSize = (start, end, steps) => {
|
|
|
271
273
|
const interpolate = (step, start, index, max) => {
|
|
272
274
|
const color = {};
|
|
273
275
|
for (const k in start) {
|
|
274
|
-
if (Object.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
283
|
-
color[k]
|
|
284
|
-
) : (
|
|
285
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
286
|
-
color[k] % max[k]
|
|
287
|
-
)
|
|
288
|
-
);
|
|
276
|
+
if (Object.hasOwn(start, k)) {
|
|
277
|
+
let value = step[k] * index + start[k];
|
|
278
|
+
if (value < 0) {
|
|
279
|
+
value += max[k];
|
|
280
|
+
} else if (max[k] !== 1) {
|
|
281
|
+
value %= max[k];
|
|
282
|
+
}
|
|
283
|
+
color[k] = value;
|
|
289
284
|
}
|
|
290
285
|
}
|
|
291
286
|
return color;
|
|
@@ -295,7 +290,7 @@ const interpolateRgb = (stop1, stop2, steps) => {
|
|
|
295
290
|
const end = { b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] };
|
|
296
291
|
const step = calculateStepSize(start, end, steps);
|
|
297
292
|
const gradient = [{ ...start }];
|
|
298
|
-
for (let index = 1; index < steps; index
|
|
293
|
+
for (let index = 1; index < steps; index += 1) {
|
|
299
294
|
const color = interpolate(step, start, index, RGBA_MAX);
|
|
300
295
|
gradient.push({
|
|
301
296
|
b: Math.floor(color.b),
|
|
@@ -335,7 +330,7 @@ const interpolateHsv = (stop1, stop2, steps, mode) => {
|
|
|
335
330
|
diff = 360 - start.h + end.h;
|
|
336
331
|
}
|
|
337
332
|
step.h = (-1) ** (trigonometric ? 1 : 0) * Math.abs(diff) / steps;
|
|
338
|
-
for (let index = 1; index < steps; index
|
|
333
|
+
for (let index = 1; index < steps; index += 1) {
|
|
339
334
|
const color = interpolate(step, start, index, HSV_MAX);
|
|
340
335
|
gradient.push(hsvToRgb(color.h, color.s, color.v));
|
|
341
336
|
}
|
|
@@ -357,7 +352,7 @@ class GradientBuilder {
|
|
|
357
352
|
let p = -1;
|
|
358
353
|
let lastColorLess = false;
|
|
359
354
|
for (const [index, stop_] of stops.entries()) {
|
|
360
|
-
let stop
|
|
355
|
+
let stop;
|
|
361
356
|
const hasPosition = stop_.position !== void 0;
|
|
362
357
|
if (havingPositions !== hasPosition) {
|
|
363
358
|
throw new Error("Cannot mix positioned and non-positioned color stops");
|
|
@@ -375,7 +370,7 @@ class GradientBuilder {
|
|
|
375
370
|
color = stopInput.color;
|
|
376
371
|
} else if (typeof stopInput.color === "string") {
|
|
377
372
|
color = stopInput.color.includes("#") ? convertHexToRgb(stopInput.color) : colorNames[stopInput.color];
|
|
378
|
-
} else if (stopInput.color
|
|
373
|
+
} else if (stopInput.color && "r" in stopInput.color && "g" in stopInput.color && "b" in stopInput.color) {
|
|
379
374
|
color = [stopInput.color.r, stopInput.color.g, stopInput.color.b];
|
|
380
375
|
}
|
|
381
376
|
}
|
|
@@ -400,7 +395,7 @@ class GradientBuilder {
|
|
|
400
395
|
color: stop_.includes("#") ? convertHexToRgb(stop_) : colorNames[stop_],
|
|
401
396
|
position: index / (l - 1)
|
|
402
397
|
};
|
|
403
|
-
} else if (stop_
|
|
398
|
+
} else if (stop_?.r !== void 0 && stop_?.g !== void 0 && stop_?.b !== void 0) {
|
|
404
399
|
stop = {
|
|
405
400
|
color: [stop_.r, stop_.g, stop_.b],
|
|
406
401
|
position: index / (l - 1)
|
|
@@ -410,16 +405,18 @@ class GradientBuilder {
|
|
|
410
405
|
}
|
|
411
406
|
this.stops.push(stop);
|
|
412
407
|
}
|
|
413
|
-
|
|
408
|
+
const firstStop = this.stops[0];
|
|
409
|
+
if (firstStop.position !== 0) {
|
|
414
410
|
this.stops.unshift({
|
|
415
|
-
color:
|
|
411
|
+
color: firstStop.color,
|
|
416
412
|
position: 0
|
|
417
413
|
});
|
|
418
|
-
l
|
|
414
|
+
l += 1;
|
|
419
415
|
}
|
|
420
|
-
|
|
416
|
+
const lastStop = this.stops[l - 1];
|
|
417
|
+
if (lastStop.position !== 1) {
|
|
421
418
|
this.stops.push({
|
|
422
|
-
color:
|
|
419
|
+
color: lastStop.color,
|
|
423
420
|
position: 1
|
|
424
421
|
});
|
|
425
422
|
}
|
|
@@ -427,10 +424,10 @@ class GradientBuilder {
|
|
|
427
424
|
reverse() {
|
|
428
425
|
const stops = [];
|
|
429
426
|
for (const stop of this.stops) {
|
|
430
|
-
const
|
|
431
|
-
stops.push(
|
|
427
|
+
const reversedStop = { ...stop, position: 1 - stop.position };
|
|
428
|
+
stops.push(reversedStop);
|
|
432
429
|
}
|
|
433
|
-
return new GradientBuilder(this.#colorize, stops.
|
|
430
|
+
return new GradientBuilder(this.#colorize, stops.toReversed());
|
|
434
431
|
}
|
|
435
432
|
loop() {
|
|
436
433
|
const stops1 = [];
|
|
@@ -447,7 +444,7 @@ class GradientBuilder {
|
|
|
447
444
|
position: 1 - (stop.position || 0) / 2
|
|
448
445
|
});
|
|
449
446
|
}
|
|
450
|
-
return new GradientBuilder(this.#colorize, [...stops1, ...stops2.
|
|
447
|
+
return new GradientBuilder(this.#colorize, [...stops1, ...stops2.toReversed()]);
|
|
451
448
|
}
|
|
452
449
|
rgb(steps) {
|
|
453
450
|
const subSteps = computeSubSteps(this.stops, steps);
|
|
@@ -458,7 +455,7 @@ class GradientBuilder {
|
|
|
458
455
|
stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
|
|
459
456
|
}
|
|
460
457
|
});
|
|
461
|
-
for (let index = 0, l = this.stops.length; index < l - 1; index
|
|
458
|
+
for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
|
|
462
459
|
const rgbs = interpolateRgb(this.stops[index], this.stops[index + 1], subSteps[index]);
|
|
463
460
|
gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
|
|
464
461
|
}
|
|
@@ -474,7 +471,7 @@ class GradientBuilder {
|
|
|
474
471
|
stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
|
|
475
472
|
}
|
|
476
473
|
});
|
|
477
|
-
for (let index = 0, l = this.stops.length; index < l - 1; index
|
|
474
|
+
for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
|
|
478
475
|
const rgbs = interpolateHsv(this.stops[index], this.stops[index + 1], subSteps[index], mode);
|
|
479
476
|
gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
|
|
480
477
|
}
|