@cjser/chalk 5.6.2-cjser.2 → 6.0.0-cjser.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjser/index.cjs +172 -103
- package/package.json +39 -29
- package/readme.md +42 -8
- package/source/index.d.ts +125 -13
- package/source/index.js +99 -63
- package/source/utilities.js +5 -5
- package/source/vendor/ansi-styles/index.d.ts +79 -16
- package/source/vendor/ansi-styles/index.js +48 -10
- package/source/vendor/supports-color/browser.js +3 -5
- package/source/vendor/supports-color/index.js +27 -11
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
const ANSI_BACKGROUND_OFFSET = 10;
|
|
2
|
+
const ANSI_UNDERLINE_OFFSET = 20;
|
|
2
3
|
|
|
3
|
-
const wrapAnsi16 = (offset = 0) => code => `\
|
|
4
|
+
const wrapAnsi16 = (offset = 0) => code => `\u{1B}[${code + offset}m`;
|
|
4
5
|
|
|
5
|
-
const wrapAnsi256 = (offset = 0) => code => `\
|
|
6
|
+
const wrapAnsi256 = (offset = 0) => code => `\u{1B}[${38 + offset};5;${code}m`;
|
|
6
7
|
|
|
7
|
-
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\
|
|
8
|
+
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u{1B}[${38 + offset};2;${red};${green};${blue}m`;
|
|
9
|
+
|
|
10
|
+
// `SGR 58` has no basic 16-color form, so the basic color code is mapped to its palette index instead.
|
|
11
|
+
const wrapUnderlineAnsi = code => `\u{1B}[58;5;${code < 90 ? code - 30 : code - 90 + 8}m`;
|
|
8
12
|
|
|
9
13
|
const styles = {
|
|
10
14
|
modifier: {
|
|
@@ -14,6 +18,11 @@ const styles = {
|
|
|
14
18
|
dim: [2, 22],
|
|
15
19
|
italic: [3, 23],
|
|
16
20
|
underline: [4, 24],
|
|
21
|
+
// Extended underline styles (`SGR 4:x` sub-parameters). Not in upstream `ansi-styles`.
|
|
22
|
+
underlineDouble: ['4:2', 24],
|
|
23
|
+
underlineCurly: ['4:3', 24],
|
|
24
|
+
underlineDotted: ['4:4', 24],
|
|
25
|
+
underlineDashed: ['4:5', 24],
|
|
17
26
|
overline: [53, 55],
|
|
18
27
|
inverse: [7, 27],
|
|
19
28
|
hidden: [8, 28],
|
|
@@ -63,11 +72,35 @@ const styles = {
|
|
|
63
72
|
bgCyanBright: [106, 49],
|
|
64
73
|
bgWhiteBright: [107, 49],
|
|
65
74
|
},
|
|
75
|
+
// Underline color (`SGR 58`/`59`). Not in upstream `ansi-styles`.
|
|
76
|
+
underlineColor: {
|
|
77
|
+
underlineBlack: ['58;5;0', 59],
|
|
78
|
+
underlineRed: ['58;5;1', 59],
|
|
79
|
+
underlineGreen: ['58;5;2', 59],
|
|
80
|
+
underlineYellow: ['58;5;3', 59],
|
|
81
|
+
underlineBlue: ['58;5;4', 59],
|
|
82
|
+
underlineMagenta: ['58;5;5', 59],
|
|
83
|
+
underlineCyan: ['58;5;6', 59],
|
|
84
|
+
underlineWhite: ['58;5;7', 59],
|
|
85
|
+
|
|
86
|
+
// Bright color
|
|
87
|
+
underlineBlackBright: ['58;5;8', 59],
|
|
88
|
+
underlineGray: ['58;5;8', 59], // Alias of `underlineBlackBright`
|
|
89
|
+
underlineGrey: ['58;5;8', 59], // Alias of `underlineBlackBright`
|
|
90
|
+
underlineRedBright: ['58;5;9', 59],
|
|
91
|
+
underlineGreenBright: ['58;5;10', 59],
|
|
92
|
+
underlineYellowBright: ['58;5;11', 59],
|
|
93
|
+
underlineBlueBright: ['58;5;12', 59],
|
|
94
|
+
underlineMagentaBright: ['58;5;13', 59],
|
|
95
|
+
underlineCyanBright: ['58;5;14', 59],
|
|
96
|
+
underlineWhiteBright: ['58;5;15', 59],
|
|
97
|
+
},
|
|
66
98
|
};
|
|
67
99
|
|
|
68
100
|
export const modifierNames = Object.keys(styles.modifier);
|
|
69
101
|
export const foregroundColorNames = Object.keys(styles.color);
|
|
70
102
|
export const backgroundColorNames = Object.keys(styles.bgColor);
|
|
103
|
+
export const underlineColorNames = Object.keys(styles.underlineColor);
|
|
71
104
|
export const colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
72
105
|
|
|
73
106
|
function assembleStyles() {
|
|
@@ -76,13 +109,14 @@ function assembleStyles() {
|
|
|
76
109
|
for (const [groupName, group] of Object.entries(styles)) {
|
|
77
110
|
for (const [styleName, style] of Object.entries(group)) {
|
|
78
111
|
styles[styleName] = {
|
|
79
|
-
open: `\
|
|
80
|
-
close: `\
|
|
112
|
+
open: `\u{1B}[${style[0]}m`,
|
|
113
|
+
close: `\u{1B}[${style[1]}m`,
|
|
81
114
|
};
|
|
82
115
|
|
|
83
116
|
group[styleName] = styles[styleName];
|
|
84
117
|
|
|
85
|
-
|
|
118
|
+
// Only the leading SGR parameter identifies a style, so `4:3` and `58;5;1` are keyed as `4` and `58`.
|
|
119
|
+
codes.set(Number.parseInt(style[0], 10), style[1]);
|
|
86
120
|
}
|
|
87
121
|
|
|
88
122
|
Object.defineProperty(styles, groupName, {
|
|
@@ -96,8 +130,9 @@ function assembleStyles() {
|
|
|
96
130
|
enumerable: false,
|
|
97
131
|
});
|
|
98
132
|
|
|
99
|
-
styles.color.close = '\
|
|
100
|
-
styles.bgColor.close = '\
|
|
133
|
+
styles.color.close = '\u{1B}[39m';
|
|
134
|
+
styles.bgColor.close = '\u{1B}[49m';
|
|
135
|
+
styles.underlineColor.close = '\u{1B}[59m';
|
|
101
136
|
|
|
102
137
|
styles.color.ansi = wrapAnsi16();
|
|
103
138
|
styles.color.ansi256 = wrapAnsi256();
|
|
@@ -105,6 +140,9 @@ function assembleStyles() {
|
|
|
105
140
|
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
106
141
|
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
107
142
|
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
143
|
+
styles.underlineColor.ansi = wrapUnderlineAnsi;
|
|
144
|
+
styles.underlineColor.ansi256 = wrapAnsi256(ANSI_UNDERLINE_OFFSET);
|
|
145
|
+
styles.underlineColor.ansi16m = wrapAnsi16m(ANSI_UNDERLINE_OFFSET);
|
|
108
146
|
|
|
109
147
|
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
|
110
148
|
Object.defineProperties(styles, {
|
|
@@ -133,7 +171,7 @@ function assembleStyles() {
|
|
|
133
171
|
},
|
|
134
172
|
hexToRgb: {
|
|
135
173
|
value(hex) {
|
|
136
|
-
const matches = /[
|
|
174
|
+
const matches = /[\da-f]{6}|[\da-f]{3}/i.exec(hex.toString(16));
|
|
137
175
|
if (!matches) {
|
|
138
176
|
return [0, 0, 0];
|
|
139
177
|
}
|
|
@@ -147,7 +185,7 @@ function assembleStyles() {
|
|
|
147
185
|
const integer = Number.parseInt(colorString, 16);
|
|
148
186
|
|
|
149
187
|
return [
|
|
150
|
-
/* eslint-disable no-bitwise */
|
|
188
|
+
/* eslint-disable no-bitwise -- We need the speed */
|
|
151
189
|
(integer >> 16) & 0xFF,
|
|
152
190
|
(integer >> 8) & 0xFF,
|
|
153
191
|
integer & 0xFF,
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
|
|
3
1
|
const level = (() => {
|
|
4
2
|
if (!('navigator' in globalThis)) {
|
|
5
3
|
return 0;
|
|
6
4
|
}
|
|
7
5
|
|
|
8
6
|
if (globalThis.navigator.userAgentData) {
|
|
9
|
-
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
|
|
10
|
-
if (brand
|
|
7
|
+
const brand = globalThis.navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
|
|
8
|
+
if (brand?.version > 93) {
|
|
11
9
|
return 3;
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
|
|
13
|
+
if (/\b(?:Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
|
|
16
14
|
return 1;
|
|
17
15
|
}
|
|
18
16
|
|
|
@@ -30,18 +30,29 @@ if (
|
|
|
30
30
|
flagForceColor = 1;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// Whether `FORCE_COLOR` names a level. Shared with the exact-level check below so that the two cannot disagree on what counts as numeric.
|
|
34
|
+
function hasNumericForceColor() {
|
|
35
|
+
return /^\d+$/.test(env.FORCE_COLOR);
|
|
36
|
+
}
|
|
37
|
+
|
|
33
38
|
function envForceColor() {
|
|
34
|
-
if ('FORCE_COLOR' in env) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
39
|
+
if (!('FORCE_COLOR' in env)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
if (env.FORCE_COLOR === 'false') {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (env.FORCE_COLOR === 'true' || env.FORCE_COLOR.length === 0) {
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
if (!hasNumericForceColor()) {
|
|
52
|
+
return;
|
|
44
53
|
}
|
|
54
|
+
|
|
55
|
+
return Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
function translateLevel(level) {
|
|
@@ -81,6 +92,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
|
81
92
|
}
|
|
82
93
|
}
|
|
83
94
|
|
|
95
|
+
// A numeric `FORCE_COLOR` requests an exact level, while `FORCE_COLOR=true` and `FORCE_COLOR=` only enable color and let the level be detected.
|
|
96
|
+
if (forceColor !== undefined && hasNumericForceColor()) {
|
|
97
|
+
return forceColor;
|
|
98
|
+
}
|
|
99
|
+
|
|
84
100
|
// Check for Azure DevOps pipelines.
|
|
85
101
|
// Has to be above the `!streamIsTTY` check.
|
|
86
102
|
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
|
|
@@ -124,7 +140,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
if ('TEAMCITY_VERSION' in env) {
|
|
127
|
-
return /^(9\.
|
|
143
|
+
return /^(?:9\.0*[1-9]\d*\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
128
144
|
}
|
|
129
145
|
|
|
130
146
|
if (env.COLORTERM === 'truecolor') {
|
|
@@ -144,7 +160,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
|
144
160
|
}
|
|
145
161
|
|
|
146
162
|
if ('TERM_PROGRAM' in env) {
|
|
147
|
-
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
163
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.', 1)[0], 10);
|
|
148
164
|
|
|
149
165
|
switch (env.TERM_PROGRAM) {
|
|
150
166
|
case 'iTerm.app': {
|
|
@@ -158,7 +174,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
|
158
174
|
}
|
|
159
175
|
}
|
|
160
176
|
|
|
161
|
-
if (/-256(color)?$/i.test(env.TERM)) {
|
|
177
|
+
if (/-256(?:color)?$/i.test(env.TERM)) {
|
|
162
178
|
return 2;
|
|
163
179
|
}
|
|
164
180
|
|