vite-plus 0.1.22 → 0.1.23
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/binding/index.cjs +119 -52
- package/binding/index.d.cts +3222 -2
- package/dist/agent-aSGY0osq.js +2461 -0
- package/dist/bin.js +6 -5
- package/dist/cli-truncate-CWsmbK3p.js +867 -0
- package/dist/{compat-OlmU9EQz.js → compat-DXZgnEyq.js} +1 -1
- package/dist/config/bin.js +18 -5
- package/dist/{constants-kDaYqyWd.js → constants-DCBWlNrn.js} +7 -2
- package/dist/create/bin.js +135 -64
- package/dist/{define-config-IMCGDS2K.d.ts → define-config-COdn-tsn.d.ts} +7 -5
- package/dist/define-config.cjs +1 -1
- package/dist/define-config.d.ts +1 -1
- package/dist/define-config.js +1 -1
- package/dist/dist-Bapm49IR.js +3 -0
- package/dist/{dist-owlRxmBM.js → dist-BgQuvbtq.js} +136 -110
- package/dist/fmt.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/is-fullwidth-code-point-BUNlIICg.js +8 -0
- package/dist/lint.d.ts +1 -1
- package/dist/{log-update-NRrY6krx.js → log-update-lyIiuflf.js} +111 -24
- package/dist/migration/bin.js +71 -30
- package/dist/{oxlint-plugin-config-BkQeR4FR.js → oxlint-plugin-config-B89iKTKN.js} +1 -1
- package/dist/oxlint-plugin.d.ts +2 -4
- package/dist/oxlint-plugin.js +1 -1
- package/dist/pack-bin.js +1 -1
- package/dist/pack.d.ts +1 -1
- package/dist/{package-BoLLED6j.js → package-PmBUZ-ve.js} +2 -2
- package/dist/staged/bin.js +10 -10
- package/dist/strip-ansi-C3wrWz9t.js +853 -0
- package/dist/{agent-BWLe0i9g.js → tsconfig-DlUVXT3J.js} +648 -2089
- package/dist/version.js +5 -5
- package/dist/versions.js +6 -6
- package/dist/{workspace-Bi_9spVt.js → workspace-DElv730L.js} +13 -12
- package/dist/wrap-ansi-CeQuiQ31.js +2 -0
- package/dist/{wrap-ansi-DtUeUCjE.js → wrap-ansi-k7Dn4VtV.js} +1 -1
- package/docs/config/run.md +39 -4
- package/docs/guide/cache.md +10 -1
- package/docs/guide/env.md +3 -0
- package/docs/guide/ide-integration.md +2 -2
- package/docs/guide/install.md +2 -0
- package/docs/guide/run.md +2 -0
- package/docs/guide/troubleshooting.md +5 -2
- package/package.json +18 -18
- package/templates/monorepo/_gitignore +1 -0
- package/dist/cli-truncate-B62YnW2m.js +0 -138
- package/dist/dist-DZfItHAr.js +0 -3
- package/dist/slice-ansi-e4todZeH.js +0 -113
- package/dist/strip-ansi-D-eYYcD2.js +0 -198
- package/dist/tsconfig-BVyzXJ_o.js +0 -517
- package/dist/wrap-ansi-3S3qJ7j8.js +0 -2
- /package/dist/{chunk-q7NCDQ7-.js → chunk-DnnnRqeS.js} +0 -0
- /package/dist/{define-config-GqLoRwH9.cjs → define-config-BR1Y88zz.cjs} +0 -0
- /package/dist/{define-config-CzWdQTt2.js → define-config-BRC7qPNE.js} +0 -0
- /package/dist/{help-DK5wuu34.js → help-YP84FSEz.js} +0 -0
- /package/dist/{lib-DpwyUJWo.js → lib-L3DWSRQp.js} +0 -0
- /package/dist/{main-DhsO6ndq.js → main-DpJl3LoU.js} +0 -0
- /package/dist/{pack-K7H72Cum.d.ts → pack-Ciiho0Tq.d.ts} +0 -0
- /package/dist/{report-CYPv1VK1.js → report-DgSBQUdz.js} +0 -0
- /package/dist/{resolve-vite-config-C5AjksTj.js → resolve-vite-config-TTvhycU1.js} +0 -0
- /package/dist/{terminal-D_Kg-AA6.js → terminal-uTv0ZaMr.js} +0 -0
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
import { a as ansiStyles, n as eastAsianWidth, t as stripAnsi } from "./strip-ansi-C3wrWz9t.js";
|
|
2
|
+
import { t as isFullwidthCodePoint } from "./is-fullwidth-code-point-BUNlIICg.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/slice-ansi@8.0.0/node_modules/slice-ansi/tokenize-ansi.js
|
|
4
|
+
const ESCAPE_CODE_POINT = 27;
|
|
5
|
+
const C1_DCS_CODE_POINT = 144;
|
|
6
|
+
const C1_SOS_CODE_POINT = 152;
|
|
7
|
+
const C1_CSI_CODE_POINT = 155;
|
|
8
|
+
const C1_ST_CODE_POINT = 156;
|
|
9
|
+
const C1_OSC_CODE_POINT = 157;
|
|
10
|
+
const C1_PM_CODE_POINT = 158;
|
|
11
|
+
const C1_APC_CODE_POINT = 159;
|
|
12
|
+
const ESCAPES = new Set([
|
|
13
|
+
ESCAPE_CODE_POINT,
|
|
14
|
+
C1_DCS_CODE_POINT,
|
|
15
|
+
C1_SOS_CODE_POINT,
|
|
16
|
+
C1_CSI_CODE_POINT,
|
|
17
|
+
C1_ST_CODE_POINT,
|
|
18
|
+
C1_OSC_CODE_POINT,
|
|
19
|
+
C1_PM_CODE_POINT,
|
|
20
|
+
C1_APC_CODE_POINT
|
|
21
|
+
]);
|
|
22
|
+
const ESCAPE = "\x1B";
|
|
23
|
+
const ANSI_BELL = "\x07";
|
|
24
|
+
const ANSI_CSI = "[";
|
|
25
|
+
const ANSI_OSC = "]";
|
|
26
|
+
const ANSI_DCS = "P";
|
|
27
|
+
const ANSI_SOS = "X";
|
|
28
|
+
const ANSI_PM = "^";
|
|
29
|
+
const ANSI_APC = "_";
|
|
30
|
+
const ANSI_SGR_TERMINATOR = "m";
|
|
31
|
+
const ANSI_OSC_TERMINATOR = "\\";
|
|
32
|
+
const ANSI_STRING_TERMINATOR = `${ESCAPE}${ANSI_OSC_TERMINATOR}`;
|
|
33
|
+
const C1_OSC = "";
|
|
34
|
+
const C1_STRING_TERMINATOR = "";
|
|
35
|
+
const ANSI_HYPERLINK_ESC_PREFIX = `${ESCAPE}${ANSI_OSC}8;`;
|
|
36
|
+
const ANSI_HYPERLINK_C1_PREFIX = `${C1_OSC}8;`;
|
|
37
|
+
const ANSI_HYPERLINK_ESC_CLOSE = `${ANSI_HYPERLINK_ESC_PREFIX};`;
|
|
38
|
+
const ANSI_HYPERLINK_C1_CLOSE = `${ANSI_HYPERLINK_C1_PREFIX};`;
|
|
39
|
+
const CODE_POINT_0 = "0".codePointAt(0);
|
|
40
|
+
const CODE_POINT_9 = "9".codePointAt(0);
|
|
41
|
+
const CODE_POINT_SEMICOLON = ";".codePointAt(0);
|
|
42
|
+
const CODE_POINT_COLON = ":".codePointAt(0);
|
|
43
|
+
const CODE_POINT_CSI_PARAMETER_START = "0".codePointAt(0);
|
|
44
|
+
const CODE_POINT_CSI_PARAMETER_END = "?".codePointAt(0);
|
|
45
|
+
const CODE_POINT_CSI_INTERMEDIATE_START = " ".codePointAt(0);
|
|
46
|
+
const CODE_POINT_CSI_INTERMEDIATE_END = "/".codePointAt(0);
|
|
47
|
+
const CODE_POINT_CSI_FINAL_START = "@".codePointAt(0);
|
|
48
|
+
const CODE_POINT_CSI_FINAL_END = "~".codePointAt(0);
|
|
49
|
+
const REGIONAL_INDICATOR_SYMBOL_LETTER_A = 127462;
|
|
50
|
+
const REGIONAL_INDICATOR_SYMBOL_LETTER_Z = 127487;
|
|
51
|
+
const SGR_RESET_CODE = 0;
|
|
52
|
+
const SGR_EXTENDED_FOREGROUND_CODE = 38;
|
|
53
|
+
const SGR_DEFAULT_FOREGROUND_CODE = 39;
|
|
54
|
+
const SGR_EXTENDED_BACKGROUND_CODE = 48;
|
|
55
|
+
const SGR_DEFAULT_BACKGROUND_CODE = 49;
|
|
56
|
+
const SGR_COLOR_TYPE_ANSI_256 = 5;
|
|
57
|
+
const SGR_COLOR_TYPE_TRUECOLOR = 2;
|
|
58
|
+
const SGR_ANSI_256_FRAGMENT_LENGTH = 3;
|
|
59
|
+
const SGR_TRUECOLOR_FRAGMENT_LENGTH = 5;
|
|
60
|
+
const SGR_ANSI_256_LAST_PARAMETER_OFFSET = 2;
|
|
61
|
+
const SGR_TRUECOLOR_LAST_PARAMETER_OFFSET = 4;
|
|
62
|
+
const VARIATION_SELECTOR_16_CODE_POINT = 65039;
|
|
63
|
+
const COMBINING_ENCLOSING_KEYCAP_CODE_POINT = 8419;
|
|
64
|
+
const EMOJI_PRESENTATION_GRAPHEME_REGEX = /\p{Emoji_Presentation}/u;
|
|
65
|
+
const GRAPHEME_SEGMENTER = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
66
|
+
const endCodeNumbers = /* @__PURE__ */ new Set();
|
|
67
|
+
for (const [, end] of ansiStyles.codes) endCodeNumbers.add(end);
|
|
68
|
+
function isSgrParameterCharacter(codePoint) {
|
|
69
|
+
return codePoint >= CODE_POINT_0 && codePoint <= CODE_POINT_9 || codePoint === CODE_POINT_SEMICOLON || codePoint === CODE_POINT_COLON;
|
|
70
|
+
}
|
|
71
|
+
function isCsiParameterCharacter(codePoint) {
|
|
72
|
+
return codePoint >= CODE_POINT_CSI_PARAMETER_START && codePoint <= CODE_POINT_CSI_PARAMETER_END;
|
|
73
|
+
}
|
|
74
|
+
function isCsiIntermediateCharacter(codePoint) {
|
|
75
|
+
return codePoint >= CODE_POINT_CSI_INTERMEDIATE_START && codePoint <= CODE_POINT_CSI_INTERMEDIATE_END;
|
|
76
|
+
}
|
|
77
|
+
function isCsiFinalCharacter(codePoint) {
|
|
78
|
+
return codePoint >= CODE_POINT_CSI_FINAL_START && codePoint <= CODE_POINT_CSI_FINAL_END;
|
|
79
|
+
}
|
|
80
|
+
function isRegionalIndicatorCodePoint(codePoint) {
|
|
81
|
+
return codePoint >= REGIONAL_INDICATOR_SYMBOL_LETTER_A && codePoint <= REGIONAL_INDICATOR_SYMBOL_LETTER_Z;
|
|
82
|
+
}
|
|
83
|
+
function createControlParseResult(code, endIndex) {
|
|
84
|
+
return {
|
|
85
|
+
token: {
|
|
86
|
+
type: "control",
|
|
87
|
+
code
|
|
88
|
+
},
|
|
89
|
+
endIndex
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function isEmojiStyleGrapheme(grapheme) {
|
|
93
|
+
if (EMOJI_PRESENTATION_GRAPHEME_REGEX.test(grapheme)) return true;
|
|
94
|
+
for (const character of grapheme) {
|
|
95
|
+
const codePoint = character.codePointAt(0);
|
|
96
|
+
if (codePoint === VARIATION_SELECTOR_16_CODE_POINT || codePoint === COMBINING_ENCLOSING_KEYCAP_CODE_POINT) return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
function getGraphemeWidth(grapheme) {
|
|
101
|
+
let regionalIndicatorCount = 0;
|
|
102
|
+
for (const character of grapheme) {
|
|
103
|
+
const codePoint = character.codePointAt(0);
|
|
104
|
+
if (isFullwidthCodePoint(codePoint)) return 2;
|
|
105
|
+
if (isRegionalIndicatorCodePoint(codePoint)) regionalIndicatorCount++;
|
|
106
|
+
}
|
|
107
|
+
if (regionalIndicatorCount >= 1) return 2;
|
|
108
|
+
if (isEmojiStyleGrapheme(grapheme)) return 2;
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
function getSgrPrefix(code) {
|
|
112
|
+
if (code.startsWith("")) return "";
|
|
113
|
+
return `${ESCAPE}${ANSI_CSI}`;
|
|
114
|
+
}
|
|
115
|
+
function createSgrCode(prefix, values) {
|
|
116
|
+
return `${prefix}${values.join(";")}${ANSI_SGR_TERMINATOR}`;
|
|
117
|
+
}
|
|
118
|
+
function getSgrFragments(code) {
|
|
119
|
+
const fragments = [];
|
|
120
|
+
const sgrPrefix = getSgrPrefix(code);
|
|
121
|
+
let parameterString;
|
|
122
|
+
if (code.startsWith(`${ESCAPE}${ANSI_CSI}`)) parameterString = code.slice(2, -1);
|
|
123
|
+
else if (code.startsWith("")) parameterString = code.slice(1, -1);
|
|
124
|
+
else return fragments;
|
|
125
|
+
const rawCodes = parameterString.length === 0 ? [String(SGR_RESET_CODE)] : parameterString.split(";");
|
|
126
|
+
let index = 0;
|
|
127
|
+
while (index < rawCodes.length) {
|
|
128
|
+
const codeNumber = Number.parseInt(rawCodes[index], 10);
|
|
129
|
+
if (Number.isNaN(codeNumber)) {
|
|
130
|
+
index++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (codeNumber === SGR_RESET_CODE) {
|
|
134
|
+
fragments.push({ type: "reset" });
|
|
135
|
+
index++;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (codeNumber === SGR_EXTENDED_FOREGROUND_CODE || codeNumber === SGR_EXTENDED_BACKGROUND_CODE) {
|
|
139
|
+
const colorType = Number.parseInt(rawCodes[index + 1], 10);
|
|
140
|
+
if (colorType === SGR_COLOR_TYPE_ANSI_256 && index + SGR_ANSI_256_LAST_PARAMETER_OFFSET < rawCodes.length) {
|
|
141
|
+
const openCode = createSgrCode(sgrPrefix, rawCodes.slice(index, index + SGR_ANSI_256_FRAGMENT_LENGTH));
|
|
142
|
+
fragments.push({
|
|
143
|
+
type: "start",
|
|
144
|
+
code: openCode,
|
|
145
|
+
endCode: ansiStyles.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
|
|
146
|
+
});
|
|
147
|
+
index += SGR_ANSI_256_FRAGMENT_LENGTH;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (colorType === SGR_COLOR_TYPE_TRUECOLOR && index + SGR_TRUECOLOR_LAST_PARAMETER_OFFSET < rawCodes.length) {
|
|
151
|
+
const openCode = createSgrCode(sgrPrefix, rawCodes.slice(index, index + SGR_TRUECOLOR_FRAGMENT_LENGTH));
|
|
152
|
+
fragments.push({
|
|
153
|
+
type: "start",
|
|
154
|
+
code: openCode,
|
|
155
|
+
endCode: ansiStyles.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
|
|
156
|
+
});
|
|
157
|
+
index += SGR_TRUECOLOR_FRAGMENT_LENGTH;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const openCode = createSgrCode(sgrPrefix, [rawCodes[index]]);
|
|
161
|
+
fragments.push({
|
|
162
|
+
type: "start",
|
|
163
|
+
code: openCode,
|
|
164
|
+
endCode: ansiStyles.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
|
|
165
|
+
});
|
|
166
|
+
index++;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (endCodeNumbers.has(codeNumber)) {
|
|
170
|
+
fragments.push({
|
|
171
|
+
type: "end",
|
|
172
|
+
endCode: ansiStyles.color.ansi(codeNumber)
|
|
173
|
+
});
|
|
174
|
+
index++;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const mappedEndCode = ansiStyles.codes.get(codeNumber);
|
|
178
|
+
if (mappedEndCode !== void 0) {
|
|
179
|
+
const openCode = createSgrCode(sgrPrefix, [rawCodes[index]]);
|
|
180
|
+
fragments.push({
|
|
181
|
+
type: "start",
|
|
182
|
+
code: openCode,
|
|
183
|
+
endCode: ansiStyles.color.ansi(mappedEndCode)
|
|
184
|
+
});
|
|
185
|
+
index++;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const openCode = createSgrCode(sgrPrefix, [rawCodes[index]]);
|
|
189
|
+
fragments.push({
|
|
190
|
+
type: "start",
|
|
191
|
+
code: openCode,
|
|
192
|
+
endCode: ansiStyles.reset.open
|
|
193
|
+
});
|
|
194
|
+
index++;
|
|
195
|
+
}
|
|
196
|
+
if (fragments.length === 0) fragments.push({ type: "reset" });
|
|
197
|
+
return fragments;
|
|
198
|
+
}
|
|
199
|
+
function parseCsiCode(string, index) {
|
|
200
|
+
const escapeCodePoint = string.codePointAt(index);
|
|
201
|
+
let sequenceStartIndex;
|
|
202
|
+
if (escapeCodePoint === ESCAPE_CODE_POINT) {
|
|
203
|
+
if (string[index + 1] !== ANSI_CSI) return;
|
|
204
|
+
sequenceStartIndex = index + 2;
|
|
205
|
+
} else if (escapeCodePoint === C1_CSI_CODE_POINT) sequenceStartIndex = index + 1;
|
|
206
|
+
else return;
|
|
207
|
+
let hasCanonicalSgrParameters = true;
|
|
208
|
+
for (let sequenceIndex = sequenceStartIndex; sequenceIndex < string.length; sequenceIndex++) {
|
|
209
|
+
const codePoint = string.codePointAt(sequenceIndex);
|
|
210
|
+
if (isCsiFinalCharacter(codePoint)) {
|
|
211
|
+
const code = string.slice(index, sequenceIndex + 1);
|
|
212
|
+
if (string[sequenceIndex] !== ANSI_SGR_TERMINATOR || !hasCanonicalSgrParameters) return createControlParseResult(code, sequenceIndex + 1);
|
|
213
|
+
return {
|
|
214
|
+
token: {
|
|
215
|
+
type: "sgr",
|
|
216
|
+
code,
|
|
217
|
+
fragments: getSgrFragments(code)
|
|
218
|
+
},
|
|
219
|
+
endIndex: sequenceIndex + 1
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (isCsiParameterCharacter(codePoint)) {
|
|
223
|
+
if (!isSgrParameterCharacter(codePoint)) hasCanonicalSgrParameters = false;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (isCsiIntermediateCharacter(codePoint)) {
|
|
227
|
+
hasCanonicalSgrParameters = false;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const endIndex = sequenceIndex;
|
|
231
|
+
return createControlParseResult(string.slice(index, endIndex), endIndex);
|
|
232
|
+
}
|
|
233
|
+
return createControlParseResult(string.slice(index), string.length);
|
|
234
|
+
}
|
|
235
|
+
function parseHyperlinkCode(string, index) {
|
|
236
|
+
let hyperlinkPrefix;
|
|
237
|
+
let hyperlinkClose;
|
|
238
|
+
const codePoint = string.codePointAt(index);
|
|
239
|
+
if (codePoint === ESCAPE_CODE_POINT && string.startsWith(ANSI_HYPERLINK_ESC_PREFIX, index)) {
|
|
240
|
+
hyperlinkPrefix = ANSI_HYPERLINK_ESC_PREFIX;
|
|
241
|
+
hyperlinkClose = ANSI_HYPERLINK_ESC_CLOSE;
|
|
242
|
+
} else if (codePoint === C1_OSC_CODE_POINT && string.startsWith(ANSI_HYPERLINK_C1_PREFIX, index)) {
|
|
243
|
+
hyperlinkPrefix = ANSI_HYPERLINK_C1_PREFIX;
|
|
244
|
+
hyperlinkClose = ANSI_HYPERLINK_C1_CLOSE;
|
|
245
|
+
} else return;
|
|
246
|
+
const uriStart = string.indexOf(";", index + hyperlinkPrefix.length);
|
|
247
|
+
if (uriStart === -1) return createControlParseResult(string.slice(index), string.length);
|
|
248
|
+
for (let sequenceIndex = uriStart + 1; sequenceIndex < string.length; sequenceIndex++) {
|
|
249
|
+
const character = string[sequenceIndex];
|
|
250
|
+
if (character === ANSI_BELL) return {
|
|
251
|
+
token: {
|
|
252
|
+
type: "hyperlink",
|
|
253
|
+
code: string.slice(index, sequenceIndex + 1),
|
|
254
|
+
action: sequenceIndex === uriStart + 1 ? "close" : "open",
|
|
255
|
+
closePrefix: hyperlinkClose,
|
|
256
|
+
terminator: ANSI_BELL
|
|
257
|
+
},
|
|
258
|
+
endIndex: sequenceIndex + 1
|
|
259
|
+
};
|
|
260
|
+
if (character === ESCAPE && string[sequenceIndex + 1] === ANSI_OSC_TERMINATOR) return {
|
|
261
|
+
token: {
|
|
262
|
+
type: "hyperlink",
|
|
263
|
+
code: string.slice(index, sequenceIndex + 2),
|
|
264
|
+
action: sequenceIndex === uriStart + 1 ? "close" : "open",
|
|
265
|
+
closePrefix: hyperlinkClose,
|
|
266
|
+
terminator: ANSI_STRING_TERMINATOR
|
|
267
|
+
},
|
|
268
|
+
endIndex: sequenceIndex + 2
|
|
269
|
+
};
|
|
270
|
+
if (character === C1_STRING_TERMINATOR) return {
|
|
271
|
+
token: {
|
|
272
|
+
type: "hyperlink",
|
|
273
|
+
code: string.slice(index, sequenceIndex + 1),
|
|
274
|
+
action: sequenceIndex === uriStart + 1 ? "close" : "open",
|
|
275
|
+
closePrefix: hyperlinkClose,
|
|
276
|
+
terminator: C1_STRING_TERMINATOR
|
|
277
|
+
},
|
|
278
|
+
endIndex: sequenceIndex + 1
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return createControlParseResult(string.slice(index), string.length);
|
|
282
|
+
}
|
|
283
|
+
function parseControlStringCode(string, index) {
|
|
284
|
+
const codePoint = string.codePointAt(index);
|
|
285
|
+
let sequenceStartIndex;
|
|
286
|
+
let supportsBellTerminator = false;
|
|
287
|
+
switch (codePoint) {
|
|
288
|
+
case ESCAPE_CODE_POINT:
|
|
289
|
+
switch (string[index + 1]) {
|
|
290
|
+
case ANSI_OSC:
|
|
291
|
+
sequenceStartIndex = index + 2;
|
|
292
|
+
supportsBellTerminator = true;
|
|
293
|
+
break;
|
|
294
|
+
case ANSI_DCS:
|
|
295
|
+
case ANSI_SOS:
|
|
296
|
+
case ANSI_PM:
|
|
297
|
+
case ANSI_APC:
|
|
298
|
+
sequenceStartIndex = index + 2;
|
|
299
|
+
break;
|
|
300
|
+
case ANSI_OSC_TERMINATOR: return createControlParseResult(ANSI_STRING_TERMINATOR, index + 2);
|
|
301
|
+
default: return;
|
|
302
|
+
}
|
|
303
|
+
break;
|
|
304
|
+
case C1_OSC_CODE_POINT:
|
|
305
|
+
sequenceStartIndex = index + 1;
|
|
306
|
+
supportsBellTerminator = true;
|
|
307
|
+
break;
|
|
308
|
+
case C1_DCS_CODE_POINT:
|
|
309
|
+
case C1_SOS_CODE_POINT:
|
|
310
|
+
case C1_PM_CODE_POINT:
|
|
311
|
+
case C1_APC_CODE_POINT:
|
|
312
|
+
sequenceStartIndex = index + 1;
|
|
313
|
+
break;
|
|
314
|
+
case C1_ST_CODE_POINT: return createControlParseResult(C1_STRING_TERMINATOR, index + 1);
|
|
315
|
+
default: return;
|
|
316
|
+
}
|
|
317
|
+
for (let sequenceIndex = sequenceStartIndex; sequenceIndex < string.length; sequenceIndex++) {
|
|
318
|
+
if (supportsBellTerminator && string[sequenceIndex] === ANSI_BELL) return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
|
|
319
|
+
if (string[sequenceIndex] === ESCAPE && string[sequenceIndex + 1] === ANSI_OSC_TERMINATOR) return createControlParseResult(string.slice(index, sequenceIndex + 2), sequenceIndex + 2);
|
|
320
|
+
if (string[sequenceIndex] === C1_STRING_TERMINATOR) return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
|
|
321
|
+
}
|
|
322
|
+
return createControlParseResult(string.slice(index), string.length);
|
|
323
|
+
}
|
|
324
|
+
function parseAnsiCode(string, index) {
|
|
325
|
+
const codePoint = string.codePointAt(index);
|
|
326
|
+
if (codePoint === ESCAPE_CODE_POINT || codePoint === C1_OSC_CODE_POINT) {
|
|
327
|
+
const hyperlinkCode = parseHyperlinkCode(string, index);
|
|
328
|
+
if (hyperlinkCode) return hyperlinkCode;
|
|
329
|
+
}
|
|
330
|
+
const controlStringCode = parseControlStringCode(string, index);
|
|
331
|
+
if (controlStringCode) return controlStringCode;
|
|
332
|
+
return parseCsiCode(string, index);
|
|
333
|
+
}
|
|
334
|
+
function appendTrailingAnsiTokens(string, index, tokens) {
|
|
335
|
+
while (index < string.length) {
|
|
336
|
+
const nextCodePoint = string.codePointAt(index);
|
|
337
|
+
if (!ESCAPES.has(nextCodePoint)) break;
|
|
338
|
+
const escapeCode = parseAnsiCode(string, index);
|
|
339
|
+
if (!escapeCode) break;
|
|
340
|
+
tokens.push(escapeCode.token);
|
|
341
|
+
index = escapeCode.endIndex;
|
|
342
|
+
}
|
|
343
|
+
return index;
|
|
344
|
+
}
|
|
345
|
+
function parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments) {
|
|
346
|
+
const segment = graphemeSegments.containing(index);
|
|
347
|
+
if (!segment || segment.index !== index) return;
|
|
348
|
+
return {
|
|
349
|
+
token: {
|
|
350
|
+
type: "character",
|
|
351
|
+
value: segment.segment,
|
|
352
|
+
visibleWidth: getGraphemeWidth(segment.segment),
|
|
353
|
+
isGraphemeContinuation: false
|
|
354
|
+
},
|
|
355
|
+
endIndex: index + segment.segment.length
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function collectVisibleCharacters(string) {
|
|
359
|
+
const visibleCharacters = [];
|
|
360
|
+
let index = 0;
|
|
361
|
+
while (index < string.length) {
|
|
362
|
+
const codePoint = string.codePointAt(index);
|
|
363
|
+
if (ESCAPES.has(codePoint)) {
|
|
364
|
+
const code = parseAnsiCode(string, index);
|
|
365
|
+
if (code) {
|
|
366
|
+
index = code.endIndex;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const value = String.fromCodePoint(codePoint);
|
|
371
|
+
visibleCharacters.push({
|
|
372
|
+
value,
|
|
373
|
+
visibleWidth: 1,
|
|
374
|
+
isGraphemeContinuation: false
|
|
375
|
+
});
|
|
376
|
+
index += value.length;
|
|
377
|
+
}
|
|
378
|
+
return visibleCharacters;
|
|
379
|
+
}
|
|
380
|
+
function applyGraphemeMetadata(visibleCharacters) {
|
|
381
|
+
if (visibleCharacters.length === 0) return;
|
|
382
|
+
const visibleString = visibleCharacters.map(({ value }) => value).join("");
|
|
383
|
+
const scalarOffsets = [];
|
|
384
|
+
let scalarOffset = 0;
|
|
385
|
+
for (const visibleCharacter of visibleCharacters) {
|
|
386
|
+
scalarOffsets.push(scalarOffset);
|
|
387
|
+
scalarOffset += visibleCharacter.value.length;
|
|
388
|
+
}
|
|
389
|
+
let scalarIndex = 0;
|
|
390
|
+
for (const segment of GRAPHEME_SEGMENTER.segment(visibleString)) {
|
|
391
|
+
while (scalarIndex < visibleCharacters.length && scalarOffsets[scalarIndex] < segment.index) scalarIndex++;
|
|
392
|
+
let graphemeIndex = scalarIndex;
|
|
393
|
+
let isFirstInGrapheme = true;
|
|
394
|
+
while (graphemeIndex < visibleCharacters.length && scalarOffsets[graphemeIndex] < segment.index + segment.segment.length) {
|
|
395
|
+
visibleCharacters[graphemeIndex].visibleWidth = isFirstInGrapheme ? getGraphemeWidth(segment.segment) : 0;
|
|
396
|
+
visibleCharacters[graphemeIndex].isGraphemeContinuation = !isFirstInGrapheme;
|
|
397
|
+
isFirstInGrapheme = false;
|
|
398
|
+
graphemeIndex++;
|
|
399
|
+
}
|
|
400
|
+
scalarIndex = graphemeIndex;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function tokenizeAnsiWithVisibleSegmentation(string, { endCharacter = Number.POSITIVE_INFINITY } = {}) {
|
|
404
|
+
const tokens = [];
|
|
405
|
+
const visibleCharacters = collectVisibleCharacters(string);
|
|
406
|
+
applyGraphemeMetadata(visibleCharacters);
|
|
407
|
+
let index = 0;
|
|
408
|
+
let visibleCharacterIndex = 0;
|
|
409
|
+
let visibleCount = 0;
|
|
410
|
+
while (index < string.length) {
|
|
411
|
+
const codePoint = string.codePointAt(index);
|
|
412
|
+
if (ESCAPES.has(codePoint)) {
|
|
413
|
+
const code = parseAnsiCode(string, index);
|
|
414
|
+
if (code) {
|
|
415
|
+
tokens.push(code.token);
|
|
416
|
+
index = code.endIndex;
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const value = String.fromCodePoint(codePoint);
|
|
421
|
+
const visibleCharacter = visibleCharacters[visibleCharacterIndex];
|
|
422
|
+
let visibleWidth = isFullwidthCodePoint(codePoint) ? 2 : value.length;
|
|
423
|
+
if (visibleCharacter) visibleWidth = visibleCharacter.visibleWidth;
|
|
424
|
+
const token = {
|
|
425
|
+
type: "character",
|
|
426
|
+
value,
|
|
427
|
+
visibleWidth,
|
|
428
|
+
isGraphemeContinuation: visibleCharacter ? visibleCharacter.isGraphemeContinuation : false
|
|
429
|
+
};
|
|
430
|
+
tokens.push(token);
|
|
431
|
+
index += value.length;
|
|
432
|
+
visibleCharacterIndex++;
|
|
433
|
+
visibleCount += token.visibleWidth;
|
|
434
|
+
if (visibleCount >= endCharacter) {
|
|
435
|
+
const nextVisibleCharacter = visibleCharacters[visibleCharacterIndex];
|
|
436
|
+
if (!nextVisibleCharacter || !nextVisibleCharacter.isGraphemeContinuation) {
|
|
437
|
+
index = appendTrailingAnsiTokens(string, index, tokens);
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return tokens;
|
|
443
|
+
}
|
|
444
|
+
function areValuesInSameGrapheme(leftValue, rightValue) {
|
|
445
|
+
const pair = `${leftValue}${rightValue}`;
|
|
446
|
+
const splitIndex = leftValue.length;
|
|
447
|
+
for (const segment of GRAPHEME_SEGMENTER.segment(pair)) {
|
|
448
|
+
if (segment.index === splitIndex) return false;
|
|
449
|
+
if (segment.index > splitIndex) return true;
|
|
450
|
+
}
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
function hasAnsiSplitContinuationAhead(string, startIndex, previousVisibleValue, graphemeSegments) {
|
|
454
|
+
if (!previousVisibleValue) return false;
|
|
455
|
+
let index = startIndex;
|
|
456
|
+
let hasAnsiCode = false;
|
|
457
|
+
while (index < string.length) {
|
|
458
|
+
const codePoint = string.codePointAt(index);
|
|
459
|
+
if (ESCAPES.has(codePoint)) {
|
|
460
|
+
const code = parseAnsiCode(string, index);
|
|
461
|
+
if (code) {
|
|
462
|
+
hasAnsiCode = true;
|
|
463
|
+
index = code.endIndex;
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
if (!hasAnsiCode) return false;
|
|
468
|
+
const characterToken = parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments);
|
|
469
|
+
if (!characterToken) return true;
|
|
470
|
+
return areValuesInSameGrapheme(previousVisibleValue, characterToken.token.value);
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
function tokenizeAnsi(string, { endCharacter = Number.POSITIVE_INFINITY } = {}) {
|
|
475
|
+
const tokens = [];
|
|
476
|
+
const graphemeSegments = GRAPHEME_SEGMENTER.segment(string);
|
|
477
|
+
let index = 0;
|
|
478
|
+
let visibleCount = 0;
|
|
479
|
+
let previousVisibleValue;
|
|
480
|
+
let hasAnsiSinceLastVisible = false;
|
|
481
|
+
while (index < string.length) {
|
|
482
|
+
const codePoint = string.codePointAt(index);
|
|
483
|
+
if (ESCAPES.has(codePoint)) {
|
|
484
|
+
const code = parseAnsiCode(string, index);
|
|
485
|
+
if (code) {
|
|
486
|
+
tokens.push(code.token);
|
|
487
|
+
index = code.endIndex;
|
|
488
|
+
hasAnsiSinceLastVisible = true;
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const characterToken = parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments);
|
|
493
|
+
if (!characterToken) return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
|
|
494
|
+
if (hasAnsiSinceLastVisible && previousVisibleValue && areValuesInSameGrapheme(previousVisibleValue, characterToken.token.value)) return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
|
|
495
|
+
tokens.push(characterToken.token);
|
|
496
|
+
index = characterToken.endIndex;
|
|
497
|
+
visibleCount += characterToken.token.visibleWidth;
|
|
498
|
+
hasAnsiSinceLastVisible = false;
|
|
499
|
+
previousVisibleValue = characterToken.token.value;
|
|
500
|
+
if (visibleCount >= endCharacter) {
|
|
501
|
+
if (hasAnsiSplitContinuationAhead(string, index, previousVisibleValue, graphemeSegments)) return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
|
|
502
|
+
index = appendTrailingAnsiTokens(string, index, tokens);
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return tokens;
|
|
507
|
+
}
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region ../../node_modules/.pnpm/slice-ansi@8.0.0/node_modules/slice-ansi/index.js
|
|
510
|
+
function applySgrFragments(activeStyles, fragments) {
|
|
511
|
+
for (const fragment of fragments) switch (fragment.type) {
|
|
512
|
+
case "reset":
|
|
513
|
+
activeStyles.clear();
|
|
514
|
+
break;
|
|
515
|
+
case "end":
|
|
516
|
+
activeStyles.delete(fragment.endCode);
|
|
517
|
+
break;
|
|
518
|
+
case "start":
|
|
519
|
+
activeStyles.delete(fragment.endCode);
|
|
520
|
+
activeStyles.set(fragment.endCode, fragment.code);
|
|
521
|
+
break;
|
|
522
|
+
default: break;
|
|
523
|
+
}
|
|
524
|
+
return activeStyles;
|
|
525
|
+
}
|
|
526
|
+
function undoAnsiCodes(activeStyles) {
|
|
527
|
+
return [...activeStyles.keys()].reverse().join("");
|
|
528
|
+
}
|
|
529
|
+
function closeHyperlink(hyperlinkToken) {
|
|
530
|
+
return `${hyperlinkToken.closePrefix}${hyperlinkToken.terminator}`;
|
|
531
|
+
}
|
|
532
|
+
function shouldIncludeSgrAfterEnd(token, activeStyles) {
|
|
533
|
+
let hasStartFragment = false;
|
|
534
|
+
let hasClosingEffect = false;
|
|
535
|
+
for (const fragment of token.fragments) {
|
|
536
|
+
if (fragment.type === "start") {
|
|
537
|
+
hasStartFragment = true;
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
if (fragment.type === "reset" && activeStyles.size > 0) {
|
|
541
|
+
hasClosingEffect = true;
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
if (fragment.type === "end" && activeStyles.has(fragment.endCode)) hasClosingEffect = true;
|
|
545
|
+
}
|
|
546
|
+
return hasClosingEffect && !hasStartFragment;
|
|
547
|
+
}
|
|
548
|
+
function applySgrToken({ token, isPastEnd, activeStyles, returnValue, include, activeHyperlink, position }) {
|
|
549
|
+
if (isPastEnd && !shouldIncludeSgrAfterEnd(token, activeStyles)) return {
|
|
550
|
+
activeStyles,
|
|
551
|
+
activeHyperlink,
|
|
552
|
+
position,
|
|
553
|
+
returnValue,
|
|
554
|
+
include
|
|
555
|
+
};
|
|
556
|
+
activeStyles = applySgrFragments(activeStyles, token.fragments);
|
|
557
|
+
if (include) returnValue += token.code;
|
|
558
|
+
return {
|
|
559
|
+
activeStyles,
|
|
560
|
+
activeHyperlink,
|
|
561
|
+
position,
|
|
562
|
+
returnValue,
|
|
563
|
+
include
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
function applyHyperlinkToken({ token, isPastEnd, activeStyles, activeHyperlink, position, returnValue, include }) {
|
|
567
|
+
if (isPastEnd && (token.action !== "close" || !activeHyperlink)) return {
|
|
568
|
+
activeStyles,
|
|
569
|
+
activeHyperlink,
|
|
570
|
+
position,
|
|
571
|
+
returnValue,
|
|
572
|
+
include
|
|
573
|
+
};
|
|
574
|
+
if (token.action === "open") activeHyperlink = token;
|
|
575
|
+
else if (token.action === "close") activeHyperlink = void 0;
|
|
576
|
+
if (include) returnValue += token.code;
|
|
577
|
+
return {
|
|
578
|
+
activeStyles,
|
|
579
|
+
activeHyperlink,
|
|
580
|
+
position,
|
|
581
|
+
returnValue,
|
|
582
|
+
include
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function applyControlToken({ token, isPastEnd, activeStyles, activeHyperlink, position, returnValue, include }) {
|
|
586
|
+
if (!isPastEnd && include) returnValue += token.code;
|
|
587
|
+
return {
|
|
588
|
+
activeStyles,
|
|
589
|
+
activeHyperlink,
|
|
590
|
+
position,
|
|
591
|
+
returnValue,
|
|
592
|
+
include
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function applyCharacterToken({ token, start, activeStyles, activeHyperlink, position, returnValue, include }) {
|
|
596
|
+
if (!include && position >= start && !token.isGraphemeContinuation) {
|
|
597
|
+
include = true;
|
|
598
|
+
returnValue = [...activeStyles.values()].join("");
|
|
599
|
+
if (activeHyperlink) returnValue += activeHyperlink.code;
|
|
600
|
+
}
|
|
601
|
+
if (include) returnValue += token.value;
|
|
602
|
+
position += token.visibleWidth;
|
|
603
|
+
return {
|
|
604
|
+
activeStyles,
|
|
605
|
+
activeHyperlink,
|
|
606
|
+
position,
|
|
607
|
+
returnValue,
|
|
608
|
+
include
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
const tokenHandlers = {
|
|
612
|
+
sgr: applySgrToken,
|
|
613
|
+
hyperlink: applyHyperlinkToken,
|
|
614
|
+
control: applyControlToken,
|
|
615
|
+
character: applyCharacterToken
|
|
616
|
+
};
|
|
617
|
+
function applyToken(parameters) {
|
|
618
|
+
const tokenHandler = tokenHandlers[parameters.token.type];
|
|
619
|
+
if (!tokenHandler) {
|
|
620
|
+
const { activeStyles, activeHyperlink, position, returnValue, include } = parameters;
|
|
621
|
+
return {
|
|
622
|
+
activeStyles,
|
|
623
|
+
activeHyperlink,
|
|
624
|
+
position,
|
|
625
|
+
returnValue,
|
|
626
|
+
include
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
return tokenHandler(parameters);
|
|
630
|
+
}
|
|
631
|
+
function createHasContinuationAheadMap(tokens) {
|
|
632
|
+
const hasContinuationAhead = Array.from({ length: tokens.length }, () => false);
|
|
633
|
+
let nextCharacterIsContinuation = false;
|
|
634
|
+
for (let tokenIndex = tokens.length - 1; tokenIndex >= 0; tokenIndex--) {
|
|
635
|
+
const token = tokens[tokenIndex];
|
|
636
|
+
hasContinuationAhead[tokenIndex] = nextCharacterIsContinuation;
|
|
637
|
+
if (token.type === "character") nextCharacterIsContinuation = Boolean(token.isGraphemeContinuation);
|
|
638
|
+
}
|
|
639
|
+
return hasContinuationAhead;
|
|
640
|
+
}
|
|
641
|
+
function sliceAnsi(string, start, end) {
|
|
642
|
+
const tokens = tokenizeAnsi(string, { endCharacter: end });
|
|
643
|
+
const hasContinuationAhead = createHasContinuationAheadMap(tokens);
|
|
644
|
+
let activeStyles = /* @__PURE__ */ new Map();
|
|
645
|
+
let activeHyperlink;
|
|
646
|
+
let position = 0;
|
|
647
|
+
let returnValue = "";
|
|
648
|
+
let include = false;
|
|
649
|
+
for (const [tokenIndex, token] of tokens.entries()) {
|
|
650
|
+
let isPastEnd = end !== void 0 && position >= end;
|
|
651
|
+
if (isPastEnd && token.type !== "character" && hasContinuationAhead[tokenIndex]) isPastEnd = false;
|
|
652
|
+
if (isPastEnd && token.type === "character" && !token.isGraphemeContinuation) break;
|
|
653
|
+
({activeStyles, activeHyperlink, position, returnValue, include} = applyToken({
|
|
654
|
+
token,
|
|
655
|
+
isPastEnd,
|
|
656
|
+
start,
|
|
657
|
+
activeStyles,
|
|
658
|
+
activeHyperlink,
|
|
659
|
+
position,
|
|
660
|
+
returnValue,
|
|
661
|
+
include
|
|
662
|
+
}));
|
|
663
|
+
}
|
|
664
|
+
if (!include) return "";
|
|
665
|
+
if (activeHyperlink) returnValue += closeHyperlink(activeHyperlink);
|
|
666
|
+
returnValue += undoAnsiCodes(activeStyles);
|
|
667
|
+
return returnValue;
|
|
668
|
+
}
|
|
669
|
+
//#endregion
|
|
670
|
+
//#region ../../node_modules/.pnpm/string-width@8.2.1/node_modules/string-width/index.js
|
|
671
|
+
/**
|
|
672
|
+
Logic:
|
|
673
|
+
- Segment graphemes to match how terminals render clusters.
|
|
674
|
+
- Width rules:
|
|
675
|
+
1. Skip non-printing clusters (Default_Ignorable, Control, pure Mark, lone Surrogates). Tabs are ignored by design.
|
|
676
|
+
2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
|
|
677
|
+
3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
|
|
678
|
+
4. Hangul jamo collapse each standard modern Hangul L+V or L+V+T syllable piece to width 2.
|
|
679
|
+
Unmatched repeated leading/vowel/trailing jamo stay additive because that matches how the terminals we target render them.
|
|
680
|
+
5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
|
|
681
|
+
*/
|
|
682
|
+
const segmenter = new Intl.Segmenter();
|
|
683
|
+
const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Mark}|\p{Surrogate})+$/v;
|
|
684
|
+
const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Mark}\p{Surrogate}]+/v;
|
|
685
|
+
const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
|
|
686
|
+
const unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
|
|
687
|
+
const extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
|
|
688
|
+
function isDoubleWidthNonRgiEmojiSequence(segment) {
|
|
689
|
+
if (segment.length > 50) return false;
|
|
690
|
+
if (unqualifiedKeycapRegex.test(segment)) return true;
|
|
691
|
+
if (segment.includes("")) {
|
|
692
|
+
const pictographics = segment.match(extendedPictographicRegex);
|
|
693
|
+
return pictographics !== null && pictographics.length >= 2;
|
|
694
|
+
}
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
function baseVisible(segment) {
|
|
698
|
+
return segment.replace(leadingNonPrintingRegex, "");
|
|
699
|
+
}
|
|
700
|
+
function isZeroWidthCluster(segment) {
|
|
701
|
+
return zeroWidthClusterRegex.test(segment);
|
|
702
|
+
}
|
|
703
|
+
function isHangulLeadingJamo(codePoint) {
|
|
704
|
+
return codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388;
|
|
705
|
+
}
|
|
706
|
+
function isHangulVowelJamo(codePoint) {
|
|
707
|
+
return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
|
|
708
|
+
}
|
|
709
|
+
function isHangulTrailingJamo(codePoint) {
|
|
710
|
+
return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
|
|
711
|
+
}
|
|
712
|
+
function isHangulJamo(codePoint) {
|
|
713
|
+
return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
|
|
714
|
+
}
|
|
715
|
+
function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
716
|
+
const codePoints = [];
|
|
717
|
+
for (const character of visibleSegment) {
|
|
718
|
+
if (zeroWidthClusterRegex.test(character)) continue;
|
|
719
|
+
codePoints.push(character.codePointAt(0));
|
|
720
|
+
}
|
|
721
|
+
if (codePoints.length === 0) return;
|
|
722
|
+
let width = 0;
|
|
723
|
+
for (let index = 0; index < codePoints.length; index++) {
|
|
724
|
+
const codePoint = codePoints[index];
|
|
725
|
+
if (!isHangulJamo(codePoint)) {
|
|
726
|
+
if (width === 0) return;
|
|
727
|
+
for (let remaining = index; remaining < codePoints.length; remaining++) width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
|
|
728
|
+
return width;
|
|
729
|
+
}
|
|
730
|
+
if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index + 1])) {
|
|
731
|
+
width += 2;
|
|
732
|
+
index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
735
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
736
|
+
}
|
|
737
|
+
return width;
|
|
738
|
+
}
|
|
739
|
+
function trailingHalfwidthWidth(visibleSegment, eastAsianWidthOptions) {
|
|
740
|
+
let extra = 0;
|
|
741
|
+
let first = true;
|
|
742
|
+
for (const character of visibleSegment) {
|
|
743
|
+
if (first) {
|
|
744
|
+
first = false;
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
if (character >= "" && character <= "") extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
|
|
748
|
+
}
|
|
749
|
+
return extra;
|
|
750
|
+
}
|
|
751
|
+
function stringWidth(input, options = {}) {
|
|
752
|
+
if (typeof input !== "string" || input.length === 0) return 0;
|
|
753
|
+
const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
|
|
754
|
+
let string = input;
|
|
755
|
+
if (!countAnsiEscapeCodes && (string.includes("\x1B") || string.includes(""))) string = stripAnsi(string);
|
|
756
|
+
if (string.length === 0) return 0;
|
|
757
|
+
if (/^[\u0020-\u007E]*$/.test(string)) return string.length;
|
|
758
|
+
let width = 0;
|
|
759
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
760
|
+
for (const { segment } of segmenter.segment(string)) {
|
|
761
|
+
if (isZeroWidthCluster(segment)) continue;
|
|
762
|
+
if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
|
|
763
|
+
width += 2;
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
const visibleSegment = baseVisible(segment);
|
|
767
|
+
const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
|
|
768
|
+
if (hangulWidth !== void 0) {
|
|
769
|
+
width += hangulWidth;
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
const codePoint = visibleSegment.codePointAt(0);
|
|
773
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
774
|
+
width += trailingHalfwidthWidth(visibleSegment, eastAsianWidthOptions);
|
|
775
|
+
}
|
|
776
|
+
return width;
|
|
777
|
+
}
|
|
778
|
+
//#endregion
|
|
779
|
+
//#region ../../node_modules/.pnpm/cli-truncate@5.2.0/node_modules/cli-truncate/index.js
|
|
780
|
+
function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight) {
|
|
781
|
+
if (string.charAt(wantedIndex) === " ") return wantedIndex;
|
|
782
|
+
const direction = shouldSearchRight ? 1 : -1;
|
|
783
|
+
for (let index = 0; index <= 3; index++) {
|
|
784
|
+
const finalIndex = wantedIndex + index * direction;
|
|
785
|
+
if (string.charAt(finalIndex) === " ") return finalIndex;
|
|
786
|
+
}
|
|
787
|
+
return wantedIndex;
|
|
788
|
+
}
|
|
789
|
+
function cliTruncate(text, columns, options = {}) {
|
|
790
|
+
const { position = "end", space = false, preferTruncationOnSpace = false } = options;
|
|
791
|
+
let { truncationCharacter = "…" } = options;
|
|
792
|
+
if (typeof text !== "string") throw new TypeError(`Expected \`input\` to be a string, got ${typeof text}`);
|
|
793
|
+
if (typeof columns !== "number") throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
|
|
794
|
+
if (columns < 1) return "";
|
|
795
|
+
const length = stringWidth(text);
|
|
796
|
+
if (length <= columns) return text;
|
|
797
|
+
if (columns === 1) return truncationCharacter;
|
|
798
|
+
const ANSI = {
|
|
799
|
+
ESC: 27,
|
|
800
|
+
LEFT_BRACKET: 91,
|
|
801
|
+
LETTER_M: 109
|
|
802
|
+
};
|
|
803
|
+
const isSgrParameter = (code) => code >= 48 && code <= 57 || code === 59;
|
|
804
|
+
function leadingSgrSpanEndIndex(string) {
|
|
805
|
+
let index = 0;
|
|
806
|
+
while (index + 2 < string.length && string.codePointAt(index) === ANSI.ESC && string.codePointAt(index + 1) === ANSI.LEFT_BRACKET) {
|
|
807
|
+
let j = index + 2;
|
|
808
|
+
while (j < string.length && isSgrParameter(string.codePointAt(j))) j++;
|
|
809
|
+
if (j < string.length && string.codePointAt(j) === ANSI.LETTER_M) {
|
|
810
|
+
index = j + 1;
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
return index;
|
|
816
|
+
}
|
|
817
|
+
function trailingSgrSpanStartIndex(string) {
|
|
818
|
+
let start = string.length;
|
|
819
|
+
while (start > 1 && string.codePointAt(start - 1) === ANSI.LETTER_M) {
|
|
820
|
+
let j = start - 2;
|
|
821
|
+
while (j >= 0 && isSgrParameter(string.codePointAt(j))) j--;
|
|
822
|
+
if (j >= 1 && string.codePointAt(j - 1) === ANSI.ESC && string.codePointAt(j) === ANSI.LEFT_BRACKET) {
|
|
823
|
+
start = j - 1;
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
return start;
|
|
829
|
+
}
|
|
830
|
+
function appendWithInheritedStyleFromEnd(visible, suffix) {
|
|
831
|
+
const start = trailingSgrSpanStartIndex(visible);
|
|
832
|
+
if (start === visible.length) return visible + suffix;
|
|
833
|
+
return visible.slice(0, start) + suffix + visible.slice(start);
|
|
834
|
+
}
|
|
835
|
+
function prependWithInheritedStyleFromStart(prefix, visible) {
|
|
836
|
+
const end = leadingSgrSpanEndIndex(visible);
|
|
837
|
+
if (end === 0) return prefix + visible;
|
|
838
|
+
return visible.slice(0, end) + prefix + visible.slice(end);
|
|
839
|
+
}
|
|
840
|
+
if (position === "start") {
|
|
841
|
+
if (preferTruncationOnSpace) {
|
|
842
|
+
const right = sliceAnsi(text, getIndexOfNearestSpace(text, length - columns + 1, true), length).trim();
|
|
843
|
+
return prependWithInheritedStyleFromStart(truncationCharacter, right);
|
|
844
|
+
}
|
|
845
|
+
if (space) truncationCharacter += " ";
|
|
846
|
+
const right = sliceAnsi(text, length - columns + stringWidth(truncationCharacter), length);
|
|
847
|
+
return prependWithInheritedStyleFromStart(truncationCharacter, right);
|
|
848
|
+
}
|
|
849
|
+
if (position === "middle") {
|
|
850
|
+
if (space) truncationCharacter = ` ${truncationCharacter} `;
|
|
851
|
+
const half = Math.floor(columns / 2);
|
|
852
|
+
if (preferTruncationOnSpace) {
|
|
853
|
+
const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
|
|
854
|
+
const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + 1, true);
|
|
855
|
+
return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, spaceNearSecondBreakPoint, length).trim();
|
|
856
|
+
}
|
|
857
|
+
return sliceAnsi(text, 0, half) + truncationCharacter + sliceAnsi(text, length - (columns - half) + stringWidth(truncationCharacter), length);
|
|
858
|
+
}
|
|
859
|
+
if (position === "end") {
|
|
860
|
+
if (preferTruncationOnSpace) return appendWithInheritedStyleFromEnd(sliceAnsi(text, 0, getIndexOfNearestSpace(text, columns - 1)), truncationCharacter);
|
|
861
|
+
if (space) truncationCharacter = ` ${truncationCharacter}`;
|
|
862
|
+
return appendWithInheritedStyleFromEnd(sliceAnsi(text, 0, columns - stringWidth(truncationCharacter)), truncationCharacter);
|
|
863
|
+
}
|
|
864
|
+
throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
|
|
865
|
+
}
|
|
866
|
+
//#endregion
|
|
867
|
+
export { cliTruncate as default };
|