@visulima/pail 4.0.0-alpha.4 → 4.0.0-alpha.6

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE.md +4 -4
  3. package/dist/index.browser.js +1488 -2
  4. package/dist/index.server.js +2656 -12
  5. package/dist/interactive/index.js +2 -2
  6. package/dist/packem_shared/AbstractJsonReporter-DWRpTtGw.js +204 -0
  7. package/dist/packem_shared/{InteractiveManager-CbE7d1kY.js → InteractiveManager-Cd6A14ZK.js} +1 -1
  8. package/dist/packem_shared/{interactive-stream-hook-DG4BtN12.js → InteractiveStreamHook-ePIURL_U.js} +1 -9
  9. package/dist/packem_shared/{JsonReporter-VzgyLEYz.js → JsonReporter-BV5lMnJX.js} +1 -1
  10. package/dist/packem_shared/{PrettyReporter-DySIXBjQ.js → PrettyReporter-BYL3NrdA.js} +49 -4
  11. package/dist/packem_shared/{format-label-De49vNPd.js → PrettyReporter-BjXCFQlo.js} +268 -3
  12. package/dist/packem_shared/Spinner-DIdVcfWq.js +2183 -0
  13. package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +2602 -0
  14. package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
  15. package/dist/packem_shared/getBarChar-BWj1UrH3.js +404 -0
  16. package/dist/packem_shared/{index-BomQ3E6J.js → index-DnkF86LQ.js} +9 -1
  17. package/dist/packem_shared/{index-EZ_WSQZS.js → index-frijFf5m.js} +120 -14
  18. package/dist/processor/message-formatter-processor.js +648 -1
  19. package/dist/reporter/file/json-file-reporter.js +1 -1
  20. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  21. package/dist/reporter/json/index.js +2 -2
  22. package/dist/reporter/pretty/index.browser.js +1 -1
  23. package/dist/reporter/pretty/index.js +1 -1
  24. package/dist/reporter/simple/simple-reporter.server.js +2 -7
  25. package/dist/spinner.js +34 -1
  26. package/package.json +4 -4
  27. package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +0 -21
  28. package/dist/packem_shared/PrettyReporter-C2wVB7yu.js +0 -222
  29. package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
  30. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
  31. package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
@@ -0,0 +1,2602 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const process$2 = __cjs_getProcess;
21
+ const {
22
+ execFileSync
23
+ } = __cjs_getBuiltinModule("node:child_process");
24
+ const fs = __cjs_getBuiltinModule("node:fs");
25
+ const tty = __cjs_getBuiltinModule("node:tty");
26
+ const {
27
+ createRequire
28
+ } = __cjs_getBuiltinModule("node:module");
29
+ import { grey, green, cyan, red, yellow, bold, magenta, underline } from '@visulima/colorize';
30
+
31
+ const r = String.raw;
32
+ const e = r`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`;
33
+ const emojiRegex = () => new RegExp(r`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${e}(?:\u200D${e})*`, "gu");
34
+ const ESCAPES = /* @__PURE__ */ new Set(["\x1B", "›"]);
35
+ const ANSI_ESCAPE_BELL = "\x07";
36
+ const ANSI_CSI = "[";
37
+ const ANSI_SGR_TERMINATOR = "m";
38
+ const ANSI_ESCAPE_LINK = `]8;;`;
39
+ const END_CODE = 39;
40
+ const RE_ZERO_WIDTH = /[\u200B\uFEFF\u2060-\u2064]/g;
41
+ const RE_ESCAPE_PATTERN = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`);
42
+ const ANSI_RESET_CODES = Object.freeze(
43
+ /* @__PURE__ */ new Map([
44
+ [0, 0],
45
+ // Reset all
46
+ [1, 22],
47
+ // Bold → Not bold
48
+ [2, 22],
49
+ // Dim → Not bold
50
+ [3, 23],
51
+ // Italic → Not italic
52
+ [4, 24],
53
+ // Underline → Not underline
54
+ [7, 27],
55
+ // Inverse → Not inverse
56
+ [8, 28],
57
+ // Hidden → Not hidden
58
+ [9, 29],
59
+ // Strikethrough → Not strikethrough
60
+ [30, 39],
61
+ // Foreground colors → Default foreground
62
+ [31, 39],
63
+ [32, 39],
64
+ [33, 39],
65
+ [34, 39],
66
+ [35, 39],
67
+ [36, 39],
68
+ [37, 39],
69
+ [40, 49],
70
+ // Background colors → Default background
71
+ [41, 49],
72
+ [42, 49],
73
+ [43, 49],
74
+ [44, 49],
75
+ [45, 49],
76
+ [46, 49],
77
+ [47, 49],
78
+ [90, 39]
79
+ // Bright foreground → Default foreground
80
+ ])
81
+ );
82
+ const RE_ANSI = /[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g;
83
+ const RE_CONTROL = /[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y;
84
+ const RE_EMOJI = emojiRegex();
85
+
86
+ const ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
87
+ const fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
88
+ const halfwidthRanges = [8361, 8361, 65377, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65512, 65518];
89
+ const narrowRanges = [32, 126, 162, 163, 165, 166, 172, 172, 175, 175, 10214, 10221, 10629, 10630];
90
+ const wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
91
+ const isInRange = (ranges, codePoint) => {
92
+ let low = 0;
93
+ let high = Math.floor(ranges.length / 2) - 1;
94
+ while (low <= high) {
95
+ const mid = Math.floor((low + high) / 2);
96
+ const i = mid * 2;
97
+ if (codePoint < ranges[i]) {
98
+ high = mid - 1;
99
+ } else if (codePoint > ranges[i + 1]) {
100
+ low = mid + 1;
101
+ } else {
102
+ return true;
103
+ }
104
+ }
105
+ return false;
106
+ };
107
+ const minimumAmbiguousCodePoint = ambiguousRanges[0];
108
+ const maximumAmbiguousCodePoint = ambiguousRanges.at(-1);
109
+ const minimumFullWidthCodePoint = fullwidthRanges[0];
110
+ const maximumFullWidthCodePoint = fullwidthRanges.at(-1);
111
+ const minimumHalfWidthCodePoint = halfwidthRanges[0];
112
+ const maximumHalfWidthCodePoint = halfwidthRanges.at(-1);
113
+ const minimumNarrowCodePoint = narrowRanges[0];
114
+ const maximumNarrowCodePoint = narrowRanges.at(-1);
115
+ const minimumWideCodePoint = wideRanges[0];
116
+ const maximumWideCodePoint = wideRanges.at(-1);
117
+ const commonCjkCodePoint = 19968;
118
+ const [wideFastPathStart, wideFastPathEnd] = findWideFastPathRange(wideRanges);
119
+ function findWideFastPathRange(ranges) {
120
+ let fastPathStart = ranges[0];
121
+ let fastPathEnd = ranges[1];
122
+ for (let index = 0; index < ranges.length; index += 2) {
123
+ const start = ranges[index];
124
+ const end = ranges[index + 1];
125
+ if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) {
126
+ return [start, end];
127
+ }
128
+ if (end - start > fastPathEnd - fastPathStart) {
129
+ fastPathStart = start;
130
+ fastPathEnd = end;
131
+ }
132
+ }
133
+ return [fastPathStart, fastPathEnd];
134
+ }
135
+ const isAmbiguous = (codePoint) => {
136
+ if (codePoint < minimumAmbiguousCodePoint || codePoint > maximumAmbiguousCodePoint) {
137
+ return false;
138
+ }
139
+ return isInRange(ambiguousRanges, codePoint);
140
+ };
141
+ const isFullWidth = (codePoint) => {
142
+ if (codePoint < minimumFullWidthCodePoint || codePoint > maximumFullWidthCodePoint) {
143
+ return false;
144
+ }
145
+ return isInRange(fullwidthRanges, codePoint);
146
+ };
147
+ const isHalfWidth = (codePoint) => {
148
+ if (codePoint < minimumHalfWidthCodePoint || codePoint > maximumHalfWidthCodePoint) {
149
+ return false;
150
+ }
151
+ return isInRange(halfwidthRanges, codePoint);
152
+ };
153
+ const isNarrow = (codePoint) => {
154
+ if (codePoint < minimumNarrowCodePoint || codePoint > maximumNarrowCodePoint) {
155
+ return false;
156
+ }
157
+ return isInRange(narrowRanges, codePoint);
158
+ };
159
+ const isWide = (codePoint) => {
160
+ if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
161
+ return true;
162
+ }
163
+ if (codePoint < minimumWideCodePoint || codePoint > maximumWideCodePoint) {
164
+ return false;
165
+ }
166
+ return isInRange(wideRanges, codePoint);
167
+ };
168
+ function getCategory(codePoint) {
169
+ if (isAmbiguous(codePoint)) {
170
+ return "ambiguous";
171
+ }
172
+ if (isFullWidth(codePoint)) {
173
+ return "fullwidth";
174
+ }
175
+ if (isHalfWidth(codePoint)) {
176
+ return "halfwidth";
177
+ }
178
+ if (isNarrow(codePoint)) {
179
+ return "narrow";
180
+ }
181
+ if (isWide(codePoint)) {
182
+ return "wide";
183
+ }
184
+ return "neutral";
185
+ }
186
+ function validate(codePoint) {
187
+ if (!Number.isSafeInteger(codePoint)) {
188
+ throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
189
+ }
190
+ }
191
+ function eastAsianWidthType(codePoint) {
192
+ validate(codePoint);
193
+ return getCategory(codePoint);
194
+ }
195
+ const charWidthCache = /* @__PURE__ */ new Map();
196
+ const RE_LATIN_CHARS = /(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y;
197
+ const getCharType = (codePoint) => {
198
+ if (codePoint >= 32 && codePoint <= 126) {
199
+ return "latin";
200
+ }
201
+ if (codePoint === 8203 || codePoint === 8204 || codePoint === 8205 || codePoint === 8288) {
202
+ return "zero";
203
+ }
204
+ if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
205
+ return "control";
206
+ }
207
+ if (codePoint >= 160 && codePoint <= 255) {
208
+ return "latin";
209
+ }
210
+ if (codePoint >= 9472 && codePoint <= 9599) {
211
+ return "latin";
212
+ }
213
+ if (codePoint >= 4352 && codePoint <= 4607 || codePoint >= 11904 && codePoint <= 40959 || codePoint >= 44032 && codePoint <= 55215 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 65280 && codePoint <= 65519 && !(codePoint >= 65377 && codePoint <= 65439) || codePoint >= 12352 && codePoint <= 12543) {
214
+ return "wide";
215
+ }
216
+ if (codePoint === 8230) {
217
+ return "latin";
218
+ }
219
+ return "other";
220
+ };
221
+ const getCachedCharWidth = (codePoint, config) => {
222
+ const highBits = Math.floor(codePoint / 65536);
223
+ const lowBits = codePoint % 65536;
224
+ let lowMap = charWidthCache.get(highBits);
225
+ if (!lowMap) {
226
+ lowMap = /* @__PURE__ */ new Map();
227
+ charWidthCache.set(highBits, lowMap);
228
+ }
229
+ if (lowMap.has(lowBits)) {
230
+ return lowMap.get(lowBits);
231
+ }
232
+ let width;
233
+ if (getCharType(codePoint) === "latin") {
234
+ width = config.width.regular;
235
+ } else if (getCharType(codePoint) === "control") {
236
+ width = config.width.control;
237
+ } else if (getCharType(codePoint) === "wide") {
238
+ width = config.width.wide;
239
+ } else {
240
+ const eaw = eastAsianWidthType(codePoint);
241
+ switch (eaw) {
242
+ case "ambiguous": {
243
+ width = config.width.ambiguousIsNarrow ? config.width.regular : config.width.wide;
244
+ break;
245
+ }
246
+ case "fullwidth": {
247
+ width = config.width.fullWidth;
248
+ break;
249
+ }
250
+ case "wide": {
251
+ width = config.width.wide;
252
+ break;
253
+ }
254
+ default: {
255
+ width = config.width.regular;
256
+ }
257
+ }
258
+ }
259
+ lowMap.set(lowBits, width);
260
+ return width;
261
+ };
262
+ const isCombiningCharacter = (codePoint) => {
263
+ if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
264
+ return true;
265
+ }
266
+ if (codePoint >= 917760 && codePoint <= 917999 || codePoint >= 65024 && codePoint <= 65039) {
267
+ return true;
268
+ }
269
+ if (codePoint >= 3633 && codePoint <= 3642 || codePoint >= 3655 && codePoint <= 3662 || codePoint >= 3761 && codePoint <= 3769 || codePoint >= 3771 && codePoint <= 3772 || codePoint >= 3784 && codePoint <= 3789) {
270
+ return true;
271
+ }
272
+ if (codePoint >= 2304 && codePoint <= 2307 || codePoint >= 2362 && codePoint <= 2383 || codePoint >= 2385 && codePoint <= 2391 || codePoint >= 2402 && codePoint <= 2403 || codePoint >= 2433 && codePoint <= 2435 || codePoint >= 2492 && codePoint <= 2500 || codePoint >= 2509 && codePoint <= 2509 || codePoint >= 2561 && codePoint <= 2563 || codePoint >= 2620 && codePoint <= 2637) {
273
+ return true;
274
+ }
275
+ if (codePoint >= 1611 && codePoint <= 1631 || codePoint >= 1648 && codePoint <= 1648 || codePoint >= 1750 && codePoint <= 1773 || codePoint >= 2276 && codePoint <= 2302) {
276
+ return true;
277
+ }
278
+ if (codePoint >= 1425 && codePoint <= 1469 || codePoint >= 1471 && codePoint <= 1471 || codePoint >= 1473 && codePoint <= 1474 || codePoint >= 1476 && codePoint <= 1477 || codePoint >= 1479 && codePoint <= 1479) {
279
+ return true;
280
+ }
281
+ if (codePoint >= 3893 && codePoint <= 3893 || codePoint >= 3895 && codePoint <= 3895 || codePoint >= 3897 && codePoint <= 3897 || codePoint >= 3953 && codePoint <= 3966 || codePoint >= 3968 && codePoint <= 3972 || codePoint >= 3974 && codePoint <= 3975) {
282
+ return true;
283
+ }
284
+ return codePoint >= 768 && codePoint <= 777 || codePoint >= 803 && codePoint <= 803;
285
+ };
286
+ const getStringTruncatedWidth = (input, options = {}) => {
287
+ if (!input || input.length === 0) {
288
+ return { ellipsed: false, index: 0, truncated: false, width: 0 };
289
+ }
290
+ const config = {
291
+ truncation: {
292
+ countAnsiEscapeCodes: options.countAnsiEscapeCodes ?? false,
293
+ ellipsis: options.ellipsis ?? "",
294
+ ellipsisWidth: options.ellipsisWidth ?? (options.ellipsis ? getStringTruncatedWidth(options.ellipsis, {
295
+ ...options,
296
+ ellipsis: "",
297
+ ellipsisWidth: 0,
298
+ limit: Number.POSITIVE_INFINITY
299
+ }).width : 0),
300
+ limit: options.limit ?? Number.POSITIVE_INFINITY
301
+ },
302
+ width: {
303
+ ambiguousIsNarrow: options.ambiguousIsNarrow ?? false,
304
+ ansi: options.ansiWidth ?? 0,
305
+ control: options.controlWidth ?? 0,
306
+ emoji: options.emojiWidth ?? 2,
307
+ fullWidth: options.fullWidth ?? 2,
308
+ halfWidth: options.halfWidth ?? 1,
309
+ regular: options.regularWidth ?? 1,
310
+ tab: options.tabWidth ?? 8,
311
+ wide: options.wideWidth ?? 2
312
+ }
313
+ };
314
+ const truncationLimit = Math.max(0, config.truncation.limit - config.truncation.ellipsisWidth);
315
+ const { length } = input;
316
+ const useCaching = length > 1e4;
317
+ let index = 0;
318
+ let width = 0;
319
+ let truncationIndex = length;
320
+ let truncationEnabled = false;
321
+ const hasAnsi = input.includes("\x1B") || input.includes("›");
322
+ while (index < length) {
323
+ if (hasAnsi && (input[index] === "\x1B" || input[index] === "›")) {
324
+ if (input.startsWith("\x1B]8;;", index)) {
325
+ const BELL = "\x07";
326
+ const OSC8_CLOSER = `\x1B]8;;${BELL}`;
327
+ const OSC8_CLOSER_LEN = OSC8_CLOSER.length;
328
+ const endOfParametersIndex = input.indexOf(BELL, index + 5);
329
+ if (endOfParametersIndex === -1) ;
330
+ else {
331
+ const startOfCloserIndex = input.indexOf(OSC8_CLOSER, endOfParametersIndex + 1);
332
+ if (startOfCloserIndex === -1) ;
333
+ else {
334
+ const endOfSequenceIndex = startOfCloserIndex + OSC8_CLOSER_LEN;
335
+ const linkText = input.slice(endOfParametersIndex + 1, startOfCloserIndex);
336
+ const strippedLinkText = linkText.replace(RE_ANSI, "");
337
+ const linkTextWidthResult = getStringTruncatedWidth(strippedLinkText, {
338
+ ambiguousIsNarrow: config.width.ambiguousIsNarrow,
339
+ ansiWidth: config.width.ansi,
340
+ controlWidth: config.width.control,
341
+ countAnsiEscapeCodes: false,
342
+ // Never count ANSI in link text width
343
+ ellipsis: config.truncation.ellipsis,
344
+ ellipsisWidth: config.truncation.ellipsisWidth,
345
+ emojiWidth: config.width.emoji,
346
+ fullWidth: config.width.fullWidth,
347
+ halfWidth: config.width.halfWidth,
348
+ limit: Math.max(0, truncationLimit - width),
349
+ regularWidth: config.width.regular,
350
+ tabWidth: config.width.tab,
351
+ wideWidth: config.width.wide
352
+ });
353
+ const textWidth = linkTextWidthResult.width;
354
+ if (linkTextWidthResult.truncated) {
355
+ truncationEnabled = true;
356
+ truncationIndex = Math.min(truncationIndex, index);
357
+ } else if (width + textWidth > truncationLimit) {
358
+ truncationIndex = Math.min(truncationIndex, index);
359
+ truncationEnabled = true;
360
+ if (width + textWidth > config.truncation.limit) {
361
+ break;
362
+ }
363
+ }
364
+ width += textWidth;
365
+ index = endOfSequenceIndex;
366
+ if (truncationEnabled && width >= config.truncation.limit) {
367
+ break;
368
+ }
369
+ continue;
370
+ }
371
+ }
372
+ }
373
+ RE_ANSI.lastIndex = index;
374
+ if (RE_ANSI.test(input)) {
375
+ const ansiLength = RE_ANSI.lastIndex - index;
376
+ const ansiWidth = config.truncation.countAnsiEscapeCodes ? ansiLength : config.width.ansi;
377
+ if (width + ansiWidth > truncationLimit) {
378
+ truncationIndex = Math.min(truncationIndex, index);
379
+ if (width + ansiWidth > config.truncation.limit) {
380
+ truncationEnabled = true;
381
+ break;
382
+ }
383
+ }
384
+ width += ansiWidth;
385
+ index = RE_ANSI.lastIndex;
386
+ continue;
387
+ }
388
+ }
389
+ const charCode = input.codePointAt(index);
390
+ if (charCode === 8203 || charCode === 65279 || charCode >= 8288 && charCode <= 8292) {
391
+ index += 1;
392
+ continue;
393
+ }
394
+ if (charCode === 9) {
395
+ if (width + config.width.tab > truncationLimit) {
396
+ truncationIndex = Math.min(truncationIndex, index);
397
+ if (width + config.width.tab > config.truncation.limit) {
398
+ truncationEnabled = true;
399
+ break;
400
+ }
401
+ }
402
+ width += config.width.tab;
403
+ index += 1;
404
+ continue;
405
+ }
406
+ RE_LATIN_CHARS.lastIndex = index;
407
+ if (RE_LATIN_CHARS.test(input)) {
408
+ const latinLength = RE_LATIN_CHARS.lastIndex - index;
409
+ const latinWidth = latinLength * config.width.regular;
410
+ if (width + latinWidth > truncationLimit) {
411
+ const charsToLimit = Math.floor((truncationLimit - width) / config.width.regular);
412
+ truncationIndex = Math.min(truncationIndex, index + charsToLimit);
413
+ if (width + latinWidth > config.truncation.limit) {
414
+ truncationEnabled = true;
415
+ break;
416
+ }
417
+ }
418
+ width += latinWidth;
419
+ index = RE_LATIN_CHARS.lastIndex;
420
+ continue;
421
+ }
422
+ if (charCode <= 31 || charCode >= 127 && charCode <= 159) {
423
+ RE_CONTROL.lastIndex = index;
424
+ if (RE_CONTROL.test(input)) {
425
+ const controlLength = RE_CONTROL.lastIndex - index;
426
+ const controlWidth = controlLength * config.width.control;
427
+ if (width + controlWidth > truncationLimit) {
428
+ truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / config.width.control));
429
+ if (width + controlWidth > config.truncation.limit) {
430
+ truncationEnabled = true;
431
+ break;
432
+ }
433
+ }
434
+ width += controlWidth;
435
+ index = RE_CONTROL.lastIndex;
436
+ continue;
437
+ }
438
+ }
439
+ RE_EMOJI.lastIndex = index;
440
+ if (RE_EMOJI.test(input)) {
441
+ if (width + config.width.emoji > truncationLimit) {
442
+ truncationIndex = Math.min(truncationIndex, index);
443
+ if (width + config.width.emoji > config.truncation.limit) {
444
+ truncationEnabled = true;
445
+ break;
446
+ }
447
+ }
448
+ width += config.width.emoji;
449
+ index = RE_EMOJI.lastIndex;
450
+ continue;
451
+ }
452
+ const codePoint = input.codePointAt(index) ?? 0;
453
+ if (isCombiningCharacter(codePoint)) {
454
+ index += codePoint > 65535 ? 2 : 1;
455
+ continue;
456
+ }
457
+ let charWidth;
458
+ if (useCaching) {
459
+ charWidth = getCachedCharWidth(codePoint, config);
460
+ } else {
461
+ const charType = getCharType(codePoint);
462
+ switch (charType) {
463
+ case "control": {
464
+ charWidth = config.width.control;
465
+ break;
466
+ }
467
+ case "latin": {
468
+ charWidth = config.width.regular;
469
+ break;
470
+ }
471
+ case "wide": {
472
+ charWidth = config.width.wide;
473
+ break;
474
+ }
475
+ case "zero": {
476
+ charWidth = 0;
477
+ break;
478
+ }
479
+ default: {
480
+ const eaw = eastAsianWidthType(codePoint);
481
+ switch (eaw) {
482
+ case "ambiguous": {
483
+ charWidth = config.width.ambiguousIsNarrow ? config.width.regular : config.width.wide;
484
+ break;
485
+ }
486
+ case "fullwidth": {
487
+ charWidth = config.width.fullWidth;
488
+ break;
489
+ }
490
+ case "wide": {
491
+ charWidth = config.width.wide;
492
+ break;
493
+ }
494
+ default: {
495
+ charWidth = config.width.regular;
496
+ }
497
+ }
498
+ }
499
+ }
500
+ }
501
+ if (width + charWidth > truncationLimit) {
502
+ truncationIndex = Math.min(truncationIndex, index);
503
+ if (width + charWidth > config.truncation.limit) {
504
+ truncationEnabled = true;
505
+ break;
506
+ }
507
+ }
508
+ width += charWidth;
509
+ index += codePoint > 65535 ? 2 : 1;
510
+ }
511
+ let finalWidth = width;
512
+ let ellipsed = false;
513
+ if (truncationEnabled && config.truncation.limit >= config.truncation.ellipsisWidth) {
514
+ finalWidth = config.truncation.limit;
515
+ ellipsed = true;
516
+ }
517
+ return {
518
+ ellipsed,
519
+ index: truncationEnabled ? truncationIndex : length,
520
+ truncated: truncationEnabled,
521
+ width: finalWidth
522
+ };
523
+ };
524
+
525
+ const getStringWidth = (input, options = {}) => getStringTruncatedWidth(input, { ...options, ellipsis: "", ellipsisWidth: 0, limit: Number.POSITIVE_INFINITY }).width;
526
+
527
+ class AnsiStateTracker {
528
+ activeForeground = void 0;
529
+ activeBackground = void 0;
530
+ // Track other formatting (bold, italic, etc.)
531
+ activeFormatting = [];
532
+ /**
533
+ * Processes an escape sequence and updates the internal state
534
+ * @param sequence The escape sequence to process
535
+ */
536
+ processEscape(sequence) {
537
+ const match = /\x1B\[(\d+)m/.exec(sequence);
538
+ if (!match) {
539
+ return;
540
+ }
541
+ const code = Number.parseInt(match[1], 10);
542
+ switch (code) {
543
+ case 0: {
544
+ this.activeForeground = void 0;
545
+ this.activeBackground = void 0;
546
+ this.activeFormatting = [];
547
+ break;
548
+ }
549
+ case 39: {
550
+ this.activeForeground = void 0;
551
+ break;
552
+ }
553
+ case 49: {
554
+ this.activeBackground = void 0;
555
+ break;
556
+ }
557
+ default: {
558
+ if (code >= 30 && code <= 37 || code >= 90 && code <= 97) {
559
+ this.activeForeground = sequence;
560
+ } else if (code >= 40 && code <= 47 || code >= 100 && code <= 107) {
561
+ this.activeBackground = sequence;
562
+ } else if ([1, 2, 3, 4, 7, 8, 9].includes(code)) {
563
+ this.activeFormatting.push(sequence);
564
+ } else if ([22, 23, 24, 27, 28, 29].includes(code)) {
565
+ const formatResetMap = {
566
+ 22: "[1m",
567
+ // Reset bold
568
+ 23: "[3m",
569
+ // Reset italic
570
+ 24: "[4m",
571
+ // Reset underline
572
+ 27: "[7m",
573
+ // Reset inverse
574
+ 28: "[8m",
575
+ // Reset hidden
576
+ 29: "[9m"
577
+ // Reset strikethrough
578
+ };
579
+ const formatToRemove = formatResetMap[code];
580
+ if (formatToRemove) {
581
+ this.activeFormatting = this.activeFormatting.filter((fmt) => !fmt.includes(formatToRemove));
582
+ }
583
+ }
584
+ }
585
+ }
586
+ }
587
+ /**
588
+ * Gets all active escape sequences to apply
589
+ * @returns String with all active escapes
590
+ */
591
+ getStartEscapesForAllActiveAttributes() {
592
+ return [this.activeBackground, this.activeForeground, ...this.activeFormatting].filter(Boolean).join("");
593
+ }
594
+ /**
595
+ * Gets all closing escape sequences for the currently active attributes.
596
+ * The order is generally reverse of application: formatting, foreground, background.
597
+ * @returns String with all necessary closing escapes.
598
+ */
599
+ getEndEscapesForAllActiveAttributes() {
600
+ const closingEscapes = [];
601
+ if (this.activeFormatting.length > 0) {
602
+ const formatResetMap = {
603
+ "\x1B[1m": "\x1B[22m",
604
+ // Bold
605
+ "\x1B[2m": "\x1B[22m",
606
+ // Faint/Dim (also reset by 22)
607
+ "\x1B[3m": "\x1B[23m",
608
+ // Italic
609
+ "\x1B[4m": "\x1B[24m",
610
+ // Underline
611
+ "\x1B[7m": "\x1B[27m",
612
+ // Inverse
613
+ "\x1B[8m": "\x1B[28m",
614
+ // Hidden/Conceal
615
+ "\x1B[9m": "\x1B[29m"
616
+ // Strikethrough
617
+ };
618
+ [...this.activeFormatting].toReversed().forEach((formatCode) => {
619
+ const resetCode = formatResetMap[formatCode];
620
+ if (resetCode) {
621
+ closingEscapes.push(resetCode);
622
+ }
623
+ });
624
+ }
625
+ if (this.activeForeground) {
626
+ closingEscapes.push("\x1B[39m");
627
+ }
628
+ if (this.activeBackground) {
629
+ closingEscapes.push("\x1B[49m");
630
+ }
631
+ return closingEscapes.join("");
632
+ }
633
+ }
634
+ const checkEscapeSequence = (chars, index) => {
635
+ if (!ESCAPES.has(chars[index])) {
636
+ return { isInsideEscape: false, isInsideLinkEscape: false };
637
+ }
638
+ const isInsideEscape = true;
639
+ const possibleLink = chars.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join("");
640
+ const isInsideLinkEscape = possibleLink === ANSI_ESCAPE_LINK;
641
+ return { isInsideEscape, isInsideLinkEscape };
642
+ };
643
+ const processAnsiString = (string, options = {}) => {
644
+ const stateTracker = new AnsiStateTracker();
645
+ let currentText = "";
646
+ let isInsideEscape = false;
647
+ let isInsideLinkEscape = false;
648
+ let escapeBuffer = "";
649
+ let currentUrl = "";
650
+ let isInHyperlink = false;
651
+ const chars = [...string];
652
+ for (let index = 0; index < chars.length; index++) {
653
+ const character = chars[index];
654
+ if (character && ESCAPES.has(character)) {
655
+ if (currentText) {
656
+ const width2 = options.getWidth?.(currentText) ?? 0;
657
+ const segment2 = {
658
+ isEscapeSequence: false,
659
+ isGrapheme: true,
660
+ text: currentText,
661
+ width: width2
662
+ };
663
+ if (isInHyperlink) {
664
+ segment2.isHyperlink = true;
665
+ segment2.hyperlinkUrl = currentUrl;
666
+ }
667
+ if (options.onSegment?.(segment2, stateTracker) === false) {
668
+ return;
669
+ }
670
+ currentText = "";
671
+ }
672
+ isInsideEscape = true;
673
+ escapeBuffer = character;
674
+ const escapeInfo = checkEscapeSequence(chars, index);
675
+ isInsideLinkEscape = escapeInfo.isInsideLinkEscape;
676
+ if (isInsideLinkEscape) {
677
+ let urlEnd = index + 1;
678
+ currentUrl = "";
679
+ while (urlEnd < chars.length) {
680
+ const nextChar = chars[urlEnd];
681
+ if (nextChar === ANSI_ESCAPE_BELL) {
682
+ break;
683
+ }
684
+ currentUrl += nextChar;
685
+ urlEnd += 1;
686
+ }
687
+ currentUrl = currentUrl.slice(4);
688
+ const segment2 = {
689
+ hyperlinkUrl: currentUrl,
690
+ isEscapeSequence: true,
691
+ isGrapheme: false,
692
+ isHyperlink: true,
693
+ isHyperlinkStart: true,
694
+ width: 0
695
+ };
696
+ if (options.onSegment?.(segment2, stateTracker) === false) {
697
+ return;
698
+ }
699
+ index = urlEnd;
700
+ isInHyperlink = true;
701
+ isInsideEscape = false;
702
+ isInsideLinkEscape = false;
703
+ escapeBuffer = "";
704
+ continue;
705
+ }
706
+ if (index + 1 < chars.length && chars[index + 1] === "\\" && isInHyperlink) {
707
+ const segment2 = {
708
+ isEscapeSequence: true,
709
+ isGrapheme: false,
710
+ isHyperlink: true,
711
+ isHyperlinkEnd: true,
712
+ width: 0
713
+ };
714
+ if (options.onSegment?.(segment2, stateTracker) === false) {
715
+ return;
716
+ }
717
+ isInHyperlink = false;
718
+ currentUrl = "";
719
+ index += 1;
720
+ isInsideEscape = false;
721
+ escapeBuffer = "";
722
+ continue;
723
+ }
724
+ }
725
+ if (isInsideEscape) {
726
+ if (escapeBuffer !== character) {
727
+ escapeBuffer += character;
728
+ }
729
+ if (character === ANSI_SGR_TERMINATOR) {
730
+ isInsideEscape = false;
731
+ stateTracker.processEscape(escapeBuffer);
732
+ const segment2 = {
733
+ isEscapeSequence: true,
734
+ isGrapheme: false,
735
+ text: escapeBuffer,
736
+ width: 0
737
+ };
738
+ if (options.onSegment?.(segment2, stateTracker) === false) {
739
+ return;
740
+ }
741
+ escapeBuffer = "";
742
+ }
743
+ continue;
744
+ }
745
+ currentText += character;
746
+ const width = options.getWidth?.(currentText) ?? 0;
747
+ const segment = {
748
+ isEscapeSequence: false,
749
+ isGrapheme: true,
750
+ text: currentText,
751
+ width
752
+ };
753
+ if (isInHyperlink) {
754
+ segment.isHyperlink = true;
755
+ segment.hyperlinkUrl = currentUrl;
756
+ }
757
+ if (options.onSegment?.(segment, stateTracker) === false) {
758
+ return;
759
+ }
760
+ currentText = "";
761
+ }
762
+ if (currentText) {
763
+ const width = options.getWidth?.(currentText) ?? 0;
764
+ const segment = {
765
+ isEscapeSequence: false,
766
+ isGrapheme: true,
767
+ text: currentText,
768
+ width
769
+ };
770
+ if (isInHyperlink) {
771
+ segment.isHyperlink = true;
772
+ segment.hyperlinkUrl = currentUrl;
773
+ }
774
+ options.onSegment?.(segment, stateTracker);
775
+ }
776
+ if (escapeBuffer) {
777
+ const segment = {
778
+ isEscapeSequence: true,
779
+ isGrapheme: false,
780
+ text: escapeBuffer,
781
+ width: 0
782
+ };
783
+ options.onSegment?.(segment, stateTracker);
784
+ }
785
+ };
786
+ const wrapAnsiCode = (code) => {
787
+ const escapeChar = ESCAPES.values().next().value;
788
+ return `${escapeChar}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
789
+ };
790
+ const wrapAnsiHyperlink = (url) => {
791
+ const escapeChar = ESCAPES.values().next().value;
792
+ return `${escapeChar}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
793
+ };
794
+ const preserveAnsi = (rawLines) => {
795
+ if (rawLines.length === 0) {
796
+ return "";
797
+ }
798
+ if (rawLines.length === 1) {
799
+ return rawLines[0];
800
+ }
801
+ let returnValue = "";
802
+ let escapeCode;
803
+ let escapeUrl;
804
+ const preString = rawLines.join("\n");
805
+ const pre = [...preString];
806
+ let preStringIndex = 0;
807
+ for (const [index, character] of pre.entries()) {
808
+ returnValue += character;
809
+ if (ESCAPES.has(character)) {
810
+ const match = RE_ESCAPE_PATTERN.exec(preString.slice(preStringIndex));
811
+ const groups = match?.groups ?? {};
812
+ if (groups.code !== void 0) {
813
+ const code2 = Number.parseFloat(groups.code);
814
+ escapeCode = code2 === END_CODE ? void 0 : code2;
815
+ } else if (groups.uri !== void 0) {
816
+ escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
817
+ }
818
+ }
819
+ const code = ANSI_RESET_CODES.get(Number(escapeCode));
820
+ if (pre[index + 1] === "\n") {
821
+ if (escapeUrl) {
822
+ returnValue += wrapAnsiHyperlink("");
823
+ }
824
+ if (escapeCode && code) {
825
+ returnValue += wrapAnsiCode(code);
826
+ }
827
+ } else if (character === "\n") {
828
+ if (escapeCode && code) {
829
+ returnValue += wrapAnsiCode(escapeCode);
830
+ }
831
+ if (escapeUrl) {
832
+ returnValue += wrapAnsiHyperlink(escapeUrl);
833
+ }
834
+ }
835
+ preStringIndex += character.length;
836
+ }
837
+ return returnValue;
838
+ };
839
+ const resetAnsiAtLineBreak = (currentLine) => {
840
+ if (!currentLine.includes("\x1B")) {
841
+ return currentLine;
842
+ }
843
+ let result = currentLine;
844
+ if (currentLine.includes("\x1B[30m")) {
845
+ result += "\x1B[39m";
846
+ }
847
+ if (currentLine.includes("\x1B[42m")) {
848
+ result += "\x1B[49m";
849
+ }
850
+ return result;
851
+ };
852
+ const stringVisibleTrimSpacesRight = (string) => {
853
+ const words = string.split(" ");
854
+ let last = words.length;
855
+ while (last > 0 && getStringWidth(words[last - 1]) === 0) {
856
+ last--;
857
+ }
858
+ if (last === words.length) {
859
+ return string;
860
+ }
861
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
862
+ };
863
+ const wrapWithBreakAtWidth = (string, width, trim) => {
864
+ if (string.length === 0) {
865
+ return [""];
866
+ }
867
+ if (width <= 0) {
868
+ return [string];
869
+ }
870
+ const rows = [];
871
+ const ansiTracker = new AnsiStateTracker();
872
+ let currentLine = "";
873
+ let currentWidth = 0;
874
+ let isInsideEscape = false;
875
+ let isInsideLinkEscape = false;
876
+ let escapeBuffer = "";
877
+ let index = 0;
878
+ while (index < string.length) {
879
+ const char = string[index];
880
+ if (ESCAPES.has(char)) {
881
+ isInsideEscape = true;
882
+ escapeBuffer = char;
883
+ currentLine += char;
884
+ const escapeInfo = checkEscapeSequence([...string], index);
885
+ isInsideLinkEscape = escapeInfo.isInsideLinkEscape;
886
+ index += 1;
887
+ continue;
888
+ }
889
+ if (isInsideEscape) {
890
+ escapeBuffer += char;
891
+ currentLine += char;
892
+ if (isInsideLinkEscape) {
893
+ if (char === ANSI_ESCAPE_BELL) {
894
+ isInsideEscape = isInsideLinkEscape = false;
895
+ }
896
+ } else if (char === ANSI_SGR_TERMINATOR) {
897
+ isInsideEscape = false;
898
+ ansiTracker.processEscape(escapeBuffer);
899
+ }
900
+ index += 1;
901
+ continue;
902
+ }
903
+ const charWidth = getStringWidth(char);
904
+ const isSpace = char === " ";
905
+ if (charWidth === 0) {
906
+ currentLine += char;
907
+ index += 1;
908
+ continue;
909
+ }
910
+ if (currentWidth + charWidth > width) {
911
+ if (currentLine) {
912
+ rows.push(currentLine + ansiTracker.getEndEscapesForAllActiveAttributes());
913
+ }
914
+ currentLine = ansiTracker.getStartEscapesForAllActiveAttributes();
915
+ currentWidth = getStringWidth(currentLine);
916
+ if (isSpace && trim) {
917
+ while (index < string.length && string[index] === " ") {
918
+ index += 1;
919
+ }
920
+ continue;
921
+ }
922
+ }
923
+ currentLine += char;
924
+ currentWidth += charWidth;
925
+ if (currentWidth === width && index < string.length - 1) {
926
+ rows.push(currentLine + ansiTracker.getEndEscapesForAllActiveAttributes());
927
+ currentLine = ansiTracker.getStartEscapesForAllActiveAttributes();
928
+ currentWidth = getStringWidth(currentLine);
929
+ if (index + 1 < string.length && string[index + 1] === " " && trim) {
930
+ index += 1;
931
+ while (index < string.length && string[index] === " ") {
932
+ index += 1;
933
+ }
934
+ continue;
935
+ }
936
+ }
937
+ index += 1;
938
+ }
939
+ if (currentLine) {
940
+ rows.push(currentLine + ansiTracker.getEndEscapesForAllActiveAttributes());
941
+ }
942
+ return trim ? rows.map((element) => stringVisibleTrimSpacesRight(element)) : rows;
943
+ };
944
+ const wrapCharByChar = (string, width, trim) => {
945
+ if (string.length === 0) {
946
+ return [];
947
+ }
948
+ const inputToProcess = trim ? string.trim() : string;
949
+ if (inputToProcess.length === 0) {
950
+ return [];
951
+ }
952
+ const rows = [];
953
+ let currentLine = "";
954
+ let currentWidth = 0;
955
+ processAnsiString(inputToProcess, {
956
+ getWidth: getStringWidth,
957
+ // eslint-disable-next-line sonarjs/cognitive-complexity,sonarjs/no-invariant-returns
958
+ onSegment: (segment, stateTracker) => {
959
+ if (segment.isEscapeSequence) {
960
+ currentLine += segment.text;
961
+ } else {
962
+ const isSpace = segment.text === " ";
963
+ if (segment.width === 0) {
964
+ currentLine += segment.text;
965
+ return true;
966
+ }
967
+ if (currentWidth + segment.width > width) {
968
+ if (currentLine) {
969
+ rows.push(currentLine);
970
+ }
971
+ currentLine = stateTracker.getStartEscapesForAllActiveAttributes();
972
+ currentWidth = 0;
973
+ if (isSpace) {
974
+ if (trim) {
975
+ return true;
976
+ }
977
+ rows.push(stateTracker.getStartEscapesForAllActiveAttributes() + segment.text);
978
+ return true;
979
+ }
980
+ }
981
+ currentLine += segment.text;
982
+ currentWidth += segment.width;
983
+ }
984
+ return true;
985
+ }
986
+ });
987
+ if (currentLine) {
988
+ rows.push(currentLine);
989
+ }
990
+ return trim ? rows.map((row) => stringVisibleTrimSpacesRight(row)) : rows;
991
+ };
992
+ const wrapWithWordBoundaries = (string, width, trim) => {
993
+ if (string.length === 0) {
994
+ return [];
995
+ }
996
+ const inputToProcess = trim ? string.trim() : string;
997
+ if (inputToProcess.length === 0) {
998
+ return [];
999
+ }
1000
+ const tokens = inputToProcess.split(/(?=\s)|(?<=\s)/);
1001
+ const rows = [];
1002
+ let currentLine = "";
1003
+ let currentWidth = 0;
1004
+ let index = 0;
1005
+ while (index < tokens.length) {
1006
+ const token = tokens[index];
1007
+ const isSpace = /^\s+$/.test(token);
1008
+ const tokenVisibleWidth = getStringWidth(token);
1009
+ if (token.length === 0) {
1010
+ index += 1;
1011
+ continue;
1012
+ }
1013
+ if (trim && isSpace && currentWidth === 0) {
1014
+ index += 1;
1015
+ continue;
1016
+ }
1017
+ if (currentWidth + tokenVisibleWidth > width && currentWidth > 0) {
1018
+ if (trim) {
1019
+ rows.push(stringVisibleTrimSpacesRight(currentLine));
1020
+ } else {
1021
+ rows.push(currentLine);
1022
+ }
1023
+ currentLine = "";
1024
+ currentWidth = 0;
1025
+ continue;
1026
+ }
1027
+ currentLine += token;
1028
+ currentWidth += tokenVisibleWidth;
1029
+ index += 1;
1030
+ }
1031
+ if (currentLine) {
1032
+ if (trim) {
1033
+ rows.push(stringVisibleTrimSpacesRight(currentLine));
1034
+ } else {
1035
+ rows.push(currentLine);
1036
+ }
1037
+ }
1038
+ return rows;
1039
+ };
1040
+ const wrapAndBreakWords = (string, width, trim) => {
1041
+ if (string.length === 0) {
1042
+ return [];
1043
+ }
1044
+ const inputToProcess = trim ? string.trim() : string;
1045
+ if (inputToProcess.length === 0) {
1046
+ return [];
1047
+ }
1048
+ const tokens = inputToProcess.split(/(?=\s)|(?<=\s)/);
1049
+ const rows = [];
1050
+ let currentLine = "";
1051
+ let currentWidth = 0;
1052
+ let index = 0;
1053
+ while (index < tokens.length) {
1054
+ const token = tokens[index];
1055
+ const isSpace = /^\s+$/.test(token);
1056
+ const tokenVisibleWidth = getStringWidth(token);
1057
+ if (token.length === 0) {
1058
+ index += 1;
1059
+ continue;
1060
+ }
1061
+ if (trim && isSpace && currentWidth === 0) {
1062
+ index += 1;
1063
+ continue;
1064
+ }
1065
+ if (tokenVisibleWidth > width) {
1066
+ if (currentLine) {
1067
+ rows.push(resetAnsiAtLineBreak(trim ? stringVisibleTrimSpacesRight(currentLine) : currentLine));
1068
+ }
1069
+ const brokenLines = wrapWithBreakAtWidth(token, width, trim);
1070
+ if (brokenLines.length > 0) {
1071
+ for (let brokenLineIndex = 0; brokenLineIndex < brokenLines.length - 1; brokenLineIndex += 1) {
1072
+ rows.push(brokenLines[brokenLineIndex]);
1073
+ }
1074
+ currentLine = brokenLines[brokenLines.length - 1];
1075
+ currentWidth = getStringWidth(currentLine);
1076
+ } else {
1077
+ currentLine = "";
1078
+ currentWidth = 0;
1079
+ }
1080
+ index += 1;
1081
+ continue;
1082
+ }
1083
+ if (currentWidth + tokenVisibleWidth > width && currentWidth > 0) {
1084
+ rows.push(resetAnsiAtLineBreak(trim ? stringVisibleTrimSpacesRight(currentLine) : currentLine));
1085
+ currentLine = "";
1086
+ currentWidth = 0;
1087
+ if (trim && isSpace) {
1088
+ index += 1;
1089
+ continue;
1090
+ }
1091
+ }
1092
+ currentLine += token;
1093
+ currentWidth += tokenVisibleWidth;
1094
+ index += 1;
1095
+ }
1096
+ if (currentLine) {
1097
+ rows.push(resetAnsiAtLineBreak(trim ? stringVisibleTrimSpacesRight(currentLine) : currentLine));
1098
+ }
1099
+ return rows;
1100
+ };
1101
+ const WrapMode = {
1102
+ /**
1103
+ * Breaks words at character boundaries to fit the width
1104
+ */
1105
+ BREAK_AT_CHARACTERS: "BREAK_AT_CHARACTERS",
1106
+ /**
1107
+ * Breaks lines at word boundaries. If a word is longer than the width, it will be broken.
1108
+ */
1109
+ BREAK_WORDS: "BREAK_WORDS",
1110
+ /**
1111
+ * Preserves word boundaries, words are kept intact even if they exceed width
1112
+ */
1113
+ PRESERVE_WORDS: "PRESERVE_WORDS",
1114
+ /**
1115
+ * Enforces strict adherence to the width limit by breaking at exact width
1116
+ */
1117
+ STRICT_WIDTH: "STRICT_WIDTH"
1118
+ };
1119
+ const wordWrap = (string, options = {}) => {
1120
+ const { removeZeroWidthCharacters = true, trim = true, width = 80, wrapMode = WrapMode.PRESERVE_WORDS } = options;
1121
+ if (trim && string.trim() === "") {
1122
+ return "";
1123
+ }
1124
+ let normalizedString = String(string).normalize("NFC").replaceAll("\r\n", "\n");
1125
+ if (removeZeroWidthCharacters) {
1126
+ normalizedString = normalizedString.replaceAll(RE_ZERO_WIDTH, "");
1127
+ }
1128
+ const result = normalizedString.split("\n").map((line) => {
1129
+ if (trim && line.trim() === "") {
1130
+ return "";
1131
+ }
1132
+ let wrappedLines;
1133
+ switch (wrapMode) {
1134
+ case WrapMode.BREAK_AT_CHARACTERS: {
1135
+ wrappedLines = wrapCharByChar(line, width, trim);
1136
+ break;
1137
+ }
1138
+ case WrapMode.BREAK_WORDS: {
1139
+ wrappedLines = wrapAndBreakWords(line, width, trim);
1140
+ break;
1141
+ }
1142
+ case WrapMode.STRICT_WIDTH: {
1143
+ wrappedLines = wrapWithBreakAtWidth(line, width, trim);
1144
+ break;
1145
+ }
1146
+ default: {
1147
+ wrappedLines = wrapWithWordBoundaries(line, width, trim);
1148
+ }
1149
+ }
1150
+ return preserveAnsi(wrappedLines);
1151
+ });
1152
+ return result.join("\n");
1153
+ };
1154
+
1155
+ const defaultColumns = 80;
1156
+ const defaultRows = 24;
1157
+ const exec = (command, arguments_, { shell, env } = {}) => execFileSync(command, arguments_, {
1158
+ encoding: "utf8",
1159
+ stdio: ["ignore", "pipe", "ignore"],
1160
+ timeout: 500,
1161
+ shell,
1162
+ env
1163
+ }).trim();
1164
+ const create = (columns, rows) => ({
1165
+ columns: Number.parseInt(columns, 10),
1166
+ rows: Number.parseInt(rows, 10)
1167
+ });
1168
+ const createIfNotDefault = (maybeColumns, maybeRows) => {
1169
+ const { columns, rows } = create(maybeColumns, maybeRows);
1170
+ if (Number.isNaN(columns) || Number.isNaN(rows)) {
1171
+ return;
1172
+ }
1173
+ if (columns === defaultColumns && rows === defaultRows) {
1174
+ return;
1175
+ }
1176
+ return { columns, rows };
1177
+ };
1178
+ const isForegroundProcess = () => {
1179
+ if (process$2.platform !== "linux") {
1180
+ return true;
1181
+ }
1182
+ try {
1183
+ const statContents = fs.readFileSync("/proc/self/stat", "utf8");
1184
+ const closingParenthesisIndex = statContents.lastIndexOf(") ");
1185
+ if (closingParenthesisIndex === -1) {
1186
+ return false;
1187
+ }
1188
+ const statFields = statContents.slice(closingParenthesisIndex + 2).trim().split(/\s+/);
1189
+ const processGroupId = Number.parseInt(statFields[2], 10);
1190
+ const foregroundProcessGroupId = Number.parseInt(statFields[5], 10);
1191
+ if (Number.isNaN(processGroupId) || Number.isNaN(foregroundProcessGroupId)) {
1192
+ return false;
1193
+ }
1194
+ if (foregroundProcessGroupId <= 0) {
1195
+ return false;
1196
+ }
1197
+ return processGroupId === foregroundProcessGroupId;
1198
+ } catch {
1199
+ return false;
1200
+ }
1201
+ };
1202
+ function terminalSize() {
1203
+ const { env, stdout, stderr } = process$2;
1204
+ if (stdout?.columns && stdout?.rows) {
1205
+ return create(stdout.columns, stdout.rows);
1206
+ }
1207
+ if (stderr?.columns && stderr?.rows) {
1208
+ return create(stderr.columns, stderr.rows);
1209
+ }
1210
+ if (env.COLUMNS && env.LINES) {
1211
+ return create(env.COLUMNS, env.LINES);
1212
+ }
1213
+ const fallback = {
1214
+ columns: defaultColumns,
1215
+ rows: defaultRows
1216
+ };
1217
+ if (process$2.platform === "win32") {
1218
+ return tput() ?? fallback;
1219
+ }
1220
+ if (process$2.platform === "darwin") {
1221
+ return devTty() ?? tput() ?? fallback;
1222
+ }
1223
+ return devTty() ?? tput() ?? resize() ?? fallback;
1224
+ }
1225
+ const devTty = () => {
1226
+ try {
1227
+ const flags = process$2.platform === "darwin" ? fs.constants.O_EVTONLY | fs.constants.O_NONBLOCK : fs.constants.O_NONBLOCK;
1228
+ const { columns, rows } = tty.WriteStream(fs.openSync("/dev/tty", flags));
1229
+ return { columns, rows };
1230
+ } catch {
1231
+ }
1232
+ };
1233
+ const tput = () => {
1234
+ try {
1235
+ const columns = exec("tput", ["cols"], { env: { TERM: "dumb", ...process$2.env } });
1236
+ const rows = exec("tput", ["lines"], { env: { TERM: "dumb", ...process$2.env } });
1237
+ if (columns && rows) {
1238
+ return createIfNotDefault(columns, rows);
1239
+ }
1240
+ } catch {
1241
+ }
1242
+ };
1243
+ const resize = () => {
1244
+ try {
1245
+ if (!isForegroundProcess()) {
1246
+ return;
1247
+ }
1248
+ const size = exec("resize", ["-u"]).match(/\d+/g);
1249
+ if (size.length === 2) {
1250
+ return createIfNotDefault(size[0], size[1]);
1251
+ }
1252
+ } catch {
1253
+ }
1254
+ };
1255
+
1256
+ const EXTENDED_RFC_5424_LOG_LEVELS = {
1257
+ alert: 7,
1258
+ // Action must be taken immediately. Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
1259
+ critical: 6,
1260
+ // Critical conditions. Example: Application component unavailable, unexpected exception.
1261
+ debug: 1,
1262
+ // Detailed debug information.
1263
+ emergency: 8,
1264
+ // Emergency: system is unusable.
1265
+ error: 5,
1266
+ // Runtime errors that do not require immediate action but should typically be logged and monitored.
1267
+ informational: 2,
1268
+ // Interesting events. Examples: User logs in, SQL logs.
1269
+ notice: 3,
1270
+ // Normal but significant events.
1271
+ trace: 2,
1272
+ // Trace information.
1273
+ warning: 4
1274
+ // Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
1275
+ };
1276
+ const LOG_TYPES = {
1277
+ alert: {
1278
+ color: "red",
1279
+ label: "alert",
1280
+ logLevel: "alert"
1281
+ },
1282
+ await: {
1283
+ color: "blue",
1284
+ label: "awaiting",
1285
+ logLevel: "informational"
1286
+ },
1287
+ complete: {
1288
+ color: "cyan",
1289
+ label: "complete",
1290
+ logLevel: "informational"
1291
+ },
1292
+ critical: {
1293
+ color: "redBright",
1294
+ label: "critical",
1295
+ logLevel: "critical"
1296
+ },
1297
+ debug: {
1298
+ color: "gray",
1299
+ label: "debug",
1300
+ logLevel: "debug"
1301
+ },
1302
+ emergency: {
1303
+ color: "redBright",
1304
+ label: "emergency",
1305
+ logLevel: "emergency"
1306
+ },
1307
+ error: {
1308
+ color: "red",
1309
+ label: "error",
1310
+ logLevel: "error"
1311
+ },
1312
+ info: {
1313
+ color: "blueBright",
1314
+ label: "info",
1315
+ logLevel: "informational"
1316
+ },
1317
+ log: {
1318
+ label: "",
1319
+ logLevel: "informational"
1320
+ },
1321
+ notice: {
1322
+ color: "magentaBright",
1323
+ label: "notice",
1324
+ logLevel: "notice"
1325
+ },
1326
+ pending: {
1327
+ color: "magenta",
1328
+ label: "pending",
1329
+ logLevel: "informational"
1330
+ },
1331
+ start: {
1332
+ color: "greenBright",
1333
+ label: "start",
1334
+ logLevel: "informational"
1335
+ },
1336
+ stop: {
1337
+ color: "red",
1338
+ label: "stop",
1339
+ logLevel: "informational"
1340
+ },
1341
+ success: {
1342
+ color: "green",
1343
+ label: "success",
1344
+ logLevel: "informational"
1345
+ },
1346
+ trace: {
1347
+ color: "cyanBright",
1348
+ label: "trace",
1349
+ logLevel: "trace"
1350
+ },
1351
+ wait: {
1352
+ color: "blue",
1353
+ label: "waiting",
1354
+ logLevel: "informational"
1355
+ },
1356
+ warn: {
1357
+ color: "yellow",
1358
+ label: "warning",
1359
+ logLevel: "warning"
1360
+ },
1361
+ warning: {
1362
+ color: "yellow",
1363
+ label: "warning",
1364
+ logLevel: "warning"
1365
+ },
1366
+ watch: {
1367
+ color: "yellowBright",
1368
+ label: "watching",
1369
+ logLevel: "informational"
1370
+ }
1371
+ };
1372
+ const EMPTY_SYMBOL = /* @__PURE__ */ Symbol("EMPTY");
1373
+
1374
+ const getLongestLabel = (types) => {
1375
+ const labels = Object.keys(types).map((x) => types[x].label ?? "");
1376
+ if (labels.length === 0) {
1377
+ return "";
1378
+ }
1379
+ return labels.reduce((x, y) => x.length > y.length ? x : y);
1380
+ };
1381
+
1382
+ const TRUNCATOR = "…";
1383
+ const inspectList = (list, from, options, inspect2, inspectItem, separator = ", ") => {
1384
+ const size = list.length;
1385
+ if (size === 0) {
1386
+ return "";
1387
+ }
1388
+ let inspect_ = inspect2;
1389
+ if (inspectItem !== void 0) {
1390
+ inspect_ = inspectItem;
1391
+ }
1392
+ const originalLength = options.truncate;
1393
+ let output = "";
1394
+ let peek = "";
1395
+ let truncated = "";
1396
+ for (let index = 0; index < size; index += 1) {
1397
+ const last = index + 1 === list.length;
1398
+ const secondToLast = index + 2 === list.length;
1399
+ truncated = `${TRUNCATOR}(${list.length - index})`;
1400
+ let value = list[index];
1401
+ options.truncate = originalLength - output.length - (last ? 0 : separator.length);
1402
+ const string = peek || inspect_(value, from, options, inspect2) + (last ? "" : separator);
1403
+ const nextLength = output.length + string.length;
1404
+ const truncatedLength = nextLength + truncated.length;
1405
+ if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) {
1406
+ break;
1407
+ }
1408
+ if (!last && !secondToLast && truncatedLength > originalLength) {
1409
+ break;
1410
+ }
1411
+ value = list[index + 1];
1412
+ peek = last ? "" : inspect_(value, from, options, inspect2) + (secondToLast ? "" : separator);
1413
+ if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) {
1414
+ break;
1415
+ }
1416
+ output += string;
1417
+ if (!last && !secondToLast && nextLength + peek.length >= originalLength) {
1418
+ truncated = `${TRUNCATOR}(${list.length - index - 1})`;
1419
+ break;
1420
+ }
1421
+ truncated = "";
1422
+ }
1423
+ return `${output}${truncated}`;
1424
+ };
1425
+ const inspectAttribute = ([key, value], _, options) => {
1426
+ options.truncate -= 3;
1427
+ if (!value) {
1428
+ return options.stylize(String(key), "yellow");
1429
+ }
1430
+ return `${options.stylize(String(key), "yellow")}=${options.stylize(`"${value}"`, "string")}`;
1431
+ };
1432
+ const inspectNode = (node, inspect2, options) => {
1433
+ switch (node.nodeType) {
1434
+ case 1: {
1435
+ return inspectHTMLElement(node, node, options, inspect2);
1436
+ }
1437
+ case 3: {
1438
+ return inspect2(node.data, inspect2, options);
1439
+ }
1440
+ default: {
1441
+ return inspect2(node, inspect2, options);
1442
+ }
1443
+ }
1444
+ };
1445
+ const inspectNodeCollection = (collection, options, inspect2, _) => inspectList(collection, collection, options, inspect2, inspectNode, "\n");
1446
+ const inspectHTMLElement = (element, object, options, inspect2) => {
1447
+ const properties = element.getAttributeNames();
1448
+ const name = element.tagName.toLowerCase();
1449
+ const head = options.stylize(`<${name}`, "special");
1450
+ const headClose = options.stylize(`>`, "special");
1451
+ const tail = options.stylize(`</${name}>`, "special");
1452
+ options.truncate -= name.length * 2 + 5;
1453
+ let propertyContents = "";
1454
+ if (properties.length > 0) {
1455
+ propertyContents += " ";
1456
+ propertyContents += inspectList(
1457
+ properties.map((key) => [key, element.getAttribute(key)]),
1458
+ object,
1459
+ options,
1460
+ inspect2,
1461
+ inspectAttribute,
1462
+ " "
1463
+ );
1464
+ }
1465
+ options.truncate -= propertyContents.length;
1466
+ const { truncate: truncate2 } = options;
1467
+ let children = inspectNodeCollection(element.children, options, inspect2);
1468
+ if (children && children.length > truncate2) {
1469
+ children = `${TRUNCATOR}(${element.children.length})`;
1470
+ }
1471
+ return `${head}${propertyContents}${headClose}${children}${tail}`;
1472
+ };
1473
+ const inspectArguments = (arguments_, options, inspect2) => {
1474
+ if (arguments_.length === 0) {
1475
+ return "Arguments []";
1476
+ }
1477
+ options.truncate -= 13;
1478
+ return `Arguments [ ${inspectList(arguments_, arguments_, options, inspect2)} ]`;
1479
+ };
1480
+ const getIndent = (indent, depth) => {
1481
+ let baseIndent;
1482
+ if (indent === " ") {
1483
+ baseIndent = " ";
1484
+ } else if (typeof indent === "number" && indent > 0) {
1485
+ baseIndent = Array.from({ length: indent + 1 }).join(" ");
1486
+ } else {
1487
+ return void 0;
1488
+ }
1489
+ return {
1490
+ base: baseIndent,
1491
+ prev: `
1492
+ ${Array.from({ length: depth + 1 }).join(baseIndent)}`
1493
+ };
1494
+ };
1495
+ const indentedJoin = (values, indent) => {
1496
+ if (values.length === 0) {
1497
+ return "";
1498
+ }
1499
+ const lineJoiner = indent.prev + indent.base;
1500
+ return lineJoiner + values.split(", ").join(`,${lineJoiner}`) + indent.prev;
1501
+ };
1502
+ const quoteComplexKey = (key, options) => {
1503
+ if (/^[a-z_]\w*$/i.test(key)) {
1504
+ return key;
1505
+ }
1506
+ const stringifiedKey = JSON.stringify(key);
1507
+ if (options.quoteStyle === "double") {
1508
+ return stringifiedKey.replaceAll('"', String.raw`\"`);
1509
+ }
1510
+ return stringifiedKey.replaceAll("'", String.raw`\'`).replaceAll(String.raw`\"`, '"').replaceAll(/^"|"$/g, "'");
1511
+ };
1512
+ const inspectProperty = ([key, value], object, options, inspect2) => {
1513
+ options.truncate -= 2;
1514
+ if (typeof key === "string") {
1515
+ key = quoteComplexKey(key, options);
1516
+ } else if (typeof key !== "number") {
1517
+ key = `[${inspect2(key, object, options)}]`;
1518
+ }
1519
+ options.truncate -= key.length;
1520
+ value = inspect2(value, object, options);
1521
+ return `${key}: ${value}`;
1522
+ };
1523
+ const multiLineValues = (values) => {
1524
+ for (const value of values) {
1525
+ if (Array.isArray(value) || typeof value === "object" && value !== null) {
1526
+ return true;
1527
+ }
1528
+ }
1529
+ return false;
1530
+ };
1531
+ const inspectArray = (array, options, inspect2, indent) => {
1532
+ const nonIndexProperties = Object.keys(array).slice(array.length);
1533
+ if (array.length === 0 && nonIndexProperties.length === 0) {
1534
+ return "[]";
1535
+ }
1536
+ options.truncate -= 4;
1537
+ let listContents = inspectList(array, array, options, inspect2);
1538
+ options.truncate -= listContents.length;
1539
+ let propertyContents = "";
1540
+ if (nonIndexProperties.length > 0) {
1541
+ propertyContents = inspectList(
1542
+ nonIndexProperties.map((key) => [key, array[key]]),
1543
+ array,
1544
+ options,
1545
+ inspect2,
1546
+ inspectProperty
1547
+ );
1548
+ }
1549
+ const hasIndent = indent && multiLineValues(array);
1550
+ if (hasIndent) {
1551
+ listContents = indentedJoin(listContents, indent);
1552
+ }
1553
+ return `[${hasIndent ? "" : " "}${listContents}${propertyContents ? `, ${propertyContents}` : ""}${hasIndent ? "" : " "}]`;
1554
+ };
1555
+ const addNumericSeparator = (number_, string_) => {
1556
+ if (number_ === Number.POSITIVE_INFINITY || number_ === Number.NEGATIVE_INFINITY || string_.includes("e")) {
1557
+ return string_;
1558
+ }
1559
+ const separatorRegex = /\d(?=(?:\d{3})+(?!\d))/g;
1560
+ if (typeof number_ === "number") {
1561
+ const int = number_ < 0 ? -Math.floor(-number_) : Math.floor(number_);
1562
+ if (int !== number_) {
1563
+ const intString = String(int);
1564
+ const dec = string_.slice(intString.length + 1);
1565
+ return (
1566
+ // eslint-disable-next-line unicorn/prefer-string-replace-all
1567
+ `${intString.replace(separatorRegex, "$&_")}.${dec.replace(/\d{3}/g, "$&_").replace(/_$/, "")}`
1568
+ );
1569
+ }
1570
+ }
1571
+ return string_.replace(separatorRegex, "$&_");
1572
+ };
1573
+ const isHighSurrogate = (char) => char >= "\uD800" && char <= "\uDBFF";
1574
+ const truncate = (string, length, tail = TRUNCATOR) => {
1575
+ string = String(string);
1576
+ const tailLength = tail.length;
1577
+ const stringLength = string.length;
1578
+ if (tailLength > length && stringLength > tailLength) {
1579
+ return tail;
1580
+ }
1581
+ if (stringLength > length && stringLength > tailLength) {
1582
+ let end = length - tailLength;
1583
+ if (end > 0 && isHighSurrogate(string[end - 1])) {
1584
+ end -= 1;
1585
+ }
1586
+ return `${string.slice(0, end)}${tail}`;
1587
+ }
1588
+ return string;
1589
+ };
1590
+ const inspectBigInt = (number, options) => {
1591
+ let nums = truncate(number.toString(), options.truncate - 1);
1592
+ if (nums !== TRUNCATOR) {
1593
+ nums += "n";
1594
+ }
1595
+ return options.stylize(options.numericSeparator ? addNumericSeparator(number, nums) : nums, "bigint");
1596
+ };
1597
+ const gPO = (typeof Reflect === "function" ? Reflect.getPrototypeOf : Object.getPrototypeOf) || ([].__proto__ === Array.prototype ? function(O) {
1598
+ return O.__proto__;
1599
+ } : null);
1600
+ const inspectObject$1 = (object, options, inspect2, indent) => {
1601
+ if (globalThis.window !== void 0 && object === globalThis) {
1602
+ return "{ [object Window] }";
1603
+ }
1604
+ if (typeof globalThis !== "undefined" && object === globalThis || globalThis.global !== void 0 && object === globalThis) {
1605
+ return "{ [object globalThis] }";
1606
+ }
1607
+ const properties = Object.getOwnPropertyNames(object);
1608
+ const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [];
1609
+ const isPlainObject = gPO(object) === Object.prototype || object.constructor === Object;
1610
+ const protoTag = object instanceof Object ? "" : "null prototype";
1611
+ const stringTag = !isPlainObject && typeof Symbol !== "undefined" && Symbol.toStringTag in object ? object[Symbol.toStringTag] : protoTag ? "Object" : "";
1612
+ const tag = stringTag || protoTag ? `[${[stringTag, protoTag].filter(Boolean).join(": ")}] ` : "";
1613
+ if (properties.length === 0 && symbols.length === 0) {
1614
+ return `${tag}{}`;
1615
+ }
1616
+ options.truncate -= 4;
1617
+ const propertyContents = inspectList(
1618
+ properties.map((key) => [key, object[key]]),
1619
+ object,
1620
+ options,
1621
+ inspect2,
1622
+ inspectProperty
1623
+ );
1624
+ const symbolContents = inspectList(
1625
+ symbols.map((key) => [key, object[key]]),
1626
+ object,
1627
+ options,
1628
+ inspect2,
1629
+ inspectProperty
1630
+ );
1631
+ let separator = "";
1632
+ if (propertyContents && symbolContents) {
1633
+ separator = ", ";
1634
+ }
1635
+ if (indent) {
1636
+ return `${tag}{${indentedJoin(propertyContents + separator + symbolContents, indent)}}`;
1637
+ }
1638
+ return `${tag}{ ${propertyContents}${separator}${symbolContents} }`;
1639
+ };
1640
+ const inspectClass = (value, options, inspect2, indent) => {
1641
+ let name = "";
1642
+ name = name || value.constructor.name;
1643
+ if (!name || name === "_class") {
1644
+ name = "<Anonymous Class>";
1645
+ }
1646
+ options.truncate -= name.length;
1647
+ return `${name} ${inspectObject$1(value, options, inspect2, indent)}`;
1648
+ };
1649
+ const inspectDate = (dateObject, options) => {
1650
+ const stringRepresentation = dateObject.toJSON();
1651
+ if (stringRepresentation === null) {
1652
+ return "Invalid Date";
1653
+ }
1654
+ const split = stringRepresentation.split("T");
1655
+ const date = split[0];
1656
+ return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, "date");
1657
+ };
1658
+ const errorKeys = /* @__PURE__ */ new Set(["column", "columnNumber", "description", "fileName", "line", "lineNumber", "message", "name", "number", "stack"]);
1659
+ const inspectObject = (error, options, inspect2) => {
1660
+ const properties = Object.getOwnPropertyNames(error).filter((key) => !errorKeys.has(key));
1661
+ const { name } = error;
1662
+ options.truncate -= name.length;
1663
+ let message = "";
1664
+ if (typeof error.message === "string") {
1665
+ message = truncate(error.message, options.truncate);
1666
+ } else {
1667
+ properties.unshift("message");
1668
+ }
1669
+ message = message ? `: ${message}` : "";
1670
+ options.truncate -= message.length + 5;
1671
+ const propertyContents = inspectList(
1672
+ properties.map((key) => [key, error[key]]),
1673
+ error,
1674
+ options,
1675
+ inspect2,
1676
+ inspectProperty
1677
+ );
1678
+ return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ""}`;
1679
+ };
1680
+ const inspectFunction = (function_, options) => {
1681
+ const functionType = function_[Symbol.toStringTag] || "Function";
1682
+ const source = function_.toString();
1683
+ if (source.length < options.truncate - 12) {
1684
+ return options.stylize(`[${functionType}: ${source}]`, "special");
1685
+ }
1686
+ const { name } = function_;
1687
+ if (!name) {
1688
+ return options.stylize(`[${functionType}]`, "special");
1689
+ }
1690
+ return options.stylize(`[${functionType} ${truncate(name, options.truncate - 11)}]`, "special");
1691
+ };
1692
+ const inspectMapEntry = ([key, value], object, options, inspect2) => {
1693
+ options.truncate -= 4;
1694
+ key = inspect2(key, object, options);
1695
+ options.truncate -= key.length;
1696
+ return `${key} => ${inspect2(value, object, options)}`;
1697
+ };
1698
+ const inspectMap = (map, options, inspect2, indent) => {
1699
+ if (map.size <= 0) {
1700
+ return "Map (0) {}";
1701
+ }
1702
+ options.truncate -= 7;
1703
+ let returnValue = inspectList([...map.entries()], map, options, inspect2, inspectMapEntry);
1704
+ if (indent) {
1705
+ returnValue = indentedJoin(returnValue, indent);
1706
+ }
1707
+ return `Map (${map.size}) {${indent ? "" : " "}${returnValue}${indent ? "" : " "}}`;
1708
+ };
1709
+ function inspectNumber(number, options) {
1710
+ if (Number.isNaN(number)) {
1711
+ return options.stylize("NaN", "number");
1712
+ }
1713
+ if (number === Number.POSITIVE_INFINITY) {
1714
+ return options.stylize("Infinity", "number");
1715
+ }
1716
+ if (number === Number.NEGATIVE_INFINITY) {
1717
+ return options.stylize("-Infinity", "number");
1718
+ }
1719
+ if (number === 0) {
1720
+ return options.stylize(1 / number === Number.POSITIVE_INFINITY ? "+0" : "-0", "number");
1721
+ }
1722
+ return options.stylize(truncate(options.numericSeparator ? addNumericSeparator(number, number.toString()) : number.toString(), options.truncate), "number");
1723
+ }
1724
+ const getPromiseValue = () => "Promise{…}";
1725
+ const inspectRegExp = (regExp, options) => {
1726
+ const sourceLength = options.truncate - (2 + regExp.flags.length);
1727
+ return options.stylize(`/${truncate(regExp.source, sourceLength)}/${regExp.flags}`, "regexp");
1728
+ };
1729
+ const inspectSet = (set, options, inspect2, indent) => {
1730
+ if (set.size === 0) {
1731
+ return "Set (0) {}";
1732
+ }
1733
+ options.truncate -= 7;
1734
+ let returnValue = inspectList([...set], set, options, inspect2);
1735
+ if (indent) {
1736
+ returnValue = indentedJoin(returnValue, indent);
1737
+ }
1738
+ return `Set (${set.size}) {${indent ? "" : " "}${returnValue}${indent ? "" : " "}}`;
1739
+ };
1740
+ const wrapQuotes = (string_, options) => {
1741
+ const quoteChar = options.quoteStyle === "double" ? '"' : "'";
1742
+ if (options.quoteStyle === "double") {
1743
+ string_ = string_.replaceAll('"', '"');
1744
+ }
1745
+ return quoteChar + string_ + quoteChar;
1746
+ };
1747
+ const stringEscapeChars = new RegExp(
1748
+ String.raw`['\0-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5` + String.raw`\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]`,
1749
+ "g"
1750
+ );
1751
+ const escapeCharacters = {
1752
+ " ": String.raw`\t`,
1753
+ "\n": String.raw`\n`,
1754
+ "\f": String.raw`\f`,
1755
+ "\r": String.raw`\r`,
1756
+ "\b": String.raw`\b`,
1757
+ "'": String.raw`\'`,
1758
+ "\\": "\\\\"
1759
+ };
1760
+ const hex = 16;
1761
+ const escape = (char) => escapeCharacters[char] || String.raw`\u${`0000${char.codePointAt(0).toString(hex)}`.slice(-4)}`;
1762
+ const inspectString = (string_, options) => {
1763
+ if (stringEscapeChars.test(string_)) {
1764
+ string_ = string_.replaceAll(stringEscapeChars, escape);
1765
+ }
1766
+ return options.stylize(wrapQuotes(truncate(string_, options.truncate - 2), options), "string");
1767
+ };
1768
+ const inspectSymbol = (value) => {
1769
+ if ("description" in Symbol.prototype) {
1770
+ return value.description ? `Symbol(${value.description})` : "Symbol()";
1771
+ }
1772
+ return value.toString();
1773
+ };
1774
+ const getArrayName = (array) => {
1775
+ if (typeof Buffer === "function" && array instanceof Buffer) {
1776
+ return "Buffer";
1777
+ }
1778
+ if (array[Symbol.toStringTag]) {
1779
+ return array[Symbol.toStringTag];
1780
+ }
1781
+ return array.constructor.name;
1782
+ };
1783
+ const inspectTypedArray = (array, options, inspect2) => {
1784
+ const name = getArrayName(array);
1785
+ options.truncate -= name.length + 4;
1786
+ const nonIndexProperties = Object.keys(array).slice(array.length);
1787
+ if (array.length === 0 && nonIndexProperties.length === 0) {
1788
+ return `${name}[]`;
1789
+ }
1790
+ let output = "";
1791
+ for (let index = 0; index < array.length; index++) {
1792
+ const string = `${options.stylize(truncate(array[index], options.truncate), "number")}${index === array.length - 1 ? "" : ", "}`;
1793
+ options.truncate -= string.length;
1794
+ if (array[index] !== array.length && options.truncate <= 3) {
1795
+ output += `${TRUNCATOR}(${array.length - array[index] + 1})`;
1796
+ break;
1797
+ }
1798
+ output += string;
1799
+ }
1800
+ let propertyContents = "";
1801
+ if (nonIndexProperties.length > 0) {
1802
+ propertyContents = inspectList(
1803
+ nonIndexProperties.map((key) => [key, array[key]]),
1804
+ array,
1805
+ options,
1806
+ inspect2,
1807
+ inspectProperty
1808
+ );
1809
+ }
1810
+ return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ""} ]`;
1811
+ };
1812
+ const constructorMap = /* @__PURE__ */ new WeakMap();
1813
+ const stringTagMap = {};
1814
+ const baseTypesMap = {
1815
+ Arguments: inspectArguments,
1816
+ Array: inspectArray,
1817
+ ArrayBuffer: () => "",
1818
+ BigInt: inspectBigInt,
1819
+ bigint: inspectBigInt,
1820
+ Boolean: (value, options) => options.stylize(String(value), "boolean"),
1821
+ boolean: (value, options) => options.stylize(String(value), "boolean"),
1822
+ DataView: () => "",
1823
+ Date: inspectDate,
1824
+ Error: inspectObject,
1825
+ Float32Array: inspectTypedArray,
1826
+ Float64Array: inspectTypedArray,
1827
+ Function: inspectFunction,
1828
+ function: inspectFunction,
1829
+ Generator: () => "",
1830
+ HTMLCollection: inspectNodeCollection,
1831
+ Int8Array: inspectTypedArray,
1832
+ Int16Array: inspectTypedArray,
1833
+ Int32Array: inspectTypedArray,
1834
+ Map: inspectMap,
1835
+ NodeList: inspectNodeCollection,
1836
+ null: (_value, options) => options.stylize("null", "null"),
1837
+ Number: inspectNumber,
1838
+ number: inspectNumber,
1839
+ Promise: getPromiseValue,
1840
+ RegExp: inspectRegExp,
1841
+ Set: inspectSet,
1842
+ String: inspectString,
1843
+ string: inspectString,
1844
+ // A Symbol polyfill will return `Symbol` not `symbol` from typedetect
1845
+ Symbol: inspectSymbol,
1846
+ symbol: inspectSymbol,
1847
+ Uint8Array: inspectTypedArray,
1848
+ Uint8ClampedArray: inspectTypedArray,
1849
+ Uint16Array: inspectTypedArray,
1850
+ Uint32Array: inspectTypedArray,
1851
+ undefined: (_value, options) => options.stylize("undefined", "undefined"),
1852
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1853
+ WeakMap: (_value, options) => options.stylize("WeakMap{…}", "special"),
1854
+ // WeakSet, WeakMap are totally opaque to us
1855
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1856
+ WeakSet: (_value, options) => options.stylize("WeakSet{…}", "special")
1857
+ };
1858
+ const inspectCustom = (value, options, type, depth) => {
1859
+ if (globalThis.window === void 0 && typeof value[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] === "function") {
1860
+ return value[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")](depth, options);
1861
+ }
1862
+ if ("inspect" in value && typeof value.inspect === "function") {
1863
+ return value.inspect(depth, options);
1864
+ }
1865
+ if ("constructor" in value && constructorMap.has(value.constructor)) {
1866
+ return constructorMap.get(value.constructor)?.(value, options) ?? "unknown";
1867
+ }
1868
+ if (stringTagMap[type]) {
1869
+ return stringTagMap[type](value, options);
1870
+ }
1871
+ return "";
1872
+ };
1873
+ const internalInspect = (value, options, depth, seen) => {
1874
+ if (seen.includes(value)) {
1875
+ return "[Circular]";
1876
+ }
1877
+ if (depth >= options.depth && options.depth > 0 && typeof value === "object") {
1878
+ return Array.isArray(value) ? "[Array]" : "[Object]";
1879
+ }
1880
+ const inspect2 = (object, from, options2) => {
1881
+ if (from) {
1882
+ seen = [...seen, from];
1883
+ }
1884
+ return internalInspect(object, options2, depth + 1, seen);
1885
+ };
1886
+ const indent = options.indent ? getIndent(options.indent, depth) : void 0;
1887
+ let type = value === null ? "null" : typeof value;
1888
+ if (type === "object") {
1889
+ type = Object.prototype.toString.call(value).slice(8, -1);
1890
+ }
1891
+ if (baseTypesMap[type] !== void 0) {
1892
+ return baseTypesMap[type](value, options, inspect2, indent);
1893
+ }
1894
+ if (options.customInspect && value) {
1895
+ const output = inspectCustom(value, options, type, options.depth - depth);
1896
+ if (output) {
1897
+ if (typeof output === "string") {
1898
+ return output;
1899
+ }
1900
+ return inspect2(output, value, options);
1901
+ }
1902
+ }
1903
+ const proto = value ? Object.getPrototypeOf(value) : false;
1904
+ if (proto === Object.prototype || proto === null) {
1905
+ return inspectObject$1(value, options, inspect2, indent);
1906
+ }
1907
+ if (value && typeof HTMLElement === "function" && value instanceof HTMLElement) {
1908
+ return inspectHTMLElement(value, value, options, inspect2);
1909
+ }
1910
+ if ("constructor" in value) {
1911
+ if (value.constructor !== Object) {
1912
+ return inspectClass(value, options, inspect2, indent);
1913
+ }
1914
+ return inspectObject$1(value, options, inspect2, indent);
1915
+ }
1916
+ if (value === Object(value)) {
1917
+ return inspectObject$1(value, options, inspect2, indent);
1918
+ }
1919
+ return options.stylize(String(value), type);
1920
+ };
1921
+ const inspect = (value, options_ = {}) => {
1922
+ const options = {
1923
+ breakLength: Number.POSITIVE_INFINITY,
1924
+ customInspect: true,
1925
+ depth: 5,
1926
+ indent: void 0,
1927
+ maxArrayLength: Number.POSITIVE_INFINITY,
1928
+ numericSeparator: true,
1929
+ quoteStyle: "single",
1930
+ showHidden: false,
1931
+ showProxy: false,
1932
+ stylize: (s) => s.toString(),
1933
+ truncate: Number.POSITIVE_INFINITY,
1934
+ ...options_
1935
+ };
1936
+ if (options.indent !== void 0 && options.indent !== " " && !(Number.parseInt(options.indent, 10) === options.indent && options.indent > 0)) {
1937
+ throw new TypeError('option "indent" must be "\\t", an integer > 0, or `undefined`');
1938
+ }
1939
+ return internalInspect(value, options, 0, []);
1940
+ };
1941
+
1942
+ const writeStream = (data, stream) => {
1943
+ const write = stream.__write ?? stream.write;
1944
+ return write.call(stream, data);
1945
+ };
1946
+
1947
+ const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
1948
+ const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
1949
+ const processShims = {
1950
+ versions: {}
1951
+ };
1952
+ const process$1 = /* @__PURE__ */ new Proxy(_process, {
1953
+ get(target, property) {
1954
+ if (property in target) {
1955
+ return target[property];
1956
+ }
1957
+ if (property in processShims) {
1958
+ return processShims[property];
1959
+ }
1960
+ return void 0;
1961
+ }
1962
+ });
1963
+ const getMarkerLines = (loc, source, linesAbove, linesBelow) => {
1964
+ const startLoc = {
1965
+ column: 0,
1966
+ // @ts-expect-error Can be overwritten
1967
+ line: -1,
1968
+ ...loc.start
1969
+ };
1970
+ const endLoc = {
1971
+ ...startLoc,
1972
+ ...loc.end
1973
+ };
1974
+ const startLine = startLoc.line;
1975
+ const startColumn = startLoc.column;
1976
+ const endLine = endLoc.line;
1977
+ const endColumn = endLoc.column;
1978
+ let start = Math.max(startLine - (linesAbove + 1), 0);
1979
+ let end = Math.min(source.length, endLine + linesBelow);
1980
+ if (startLine === -1) {
1981
+ start = 0;
1982
+ }
1983
+ if (endLine === -1) {
1984
+ end = source.length;
1985
+ }
1986
+ const lineDiff = endLine - startLine;
1987
+ const markerLines = {};
1988
+ if (lineDiff) {
1989
+ for (let index = 0; index <= lineDiff; index++) {
1990
+ const lineNumber = index + startLine;
1991
+ if (!startColumn) {
1992
+ markerLines[lineNumber] = true;
1993
+ } else if (index === 0) {
1994
+ const sourceLength = source[lineNumber - 1]?.length;
1995
+ markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
1996
+ } else if (index === lineDiff) {
1997
+ markerLines[lineNumber] = [0, endColumn];
1998
+ } else {
1999
+ const sourceLength = source[lineNumber - index]?.length;
2000
+ markerLines[lineNumber] = [0, sourceLength];
2001
+ }
2002
+ }
2003
+ } else if (startColumn === endColumn) {
2004
+ markerLines[startLine] = startColumn ? [startColumn, 0] : true;
2005
+ } else {
2006
+ markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
2007
+ }
2008
+ return { end, markerLines, start };
2009
+ };
2010
+ const CODE_FRAME_POINTER = process$1.platform === "win32" && !process$1.env?.WT_SESSION ? ">" : "❯";
2011
+ const codeFrame = (source, loc, options) => {
2012
+ const config = {
2013
+ // grab 2 lines before, and 3 lines after focused line
2014
+ linesAbove: 2,
2015
+ linesBelow: 3,
2016
+ prefix: "",
2017
+ showGutter: true,
2018
+ tabWidth: 4,
2019
+ ...options,
2020
+ color: {
2021
+ gutter: (value) => value,
2022
+ marker: (value) => value,
2023
+ message: (value) => value,
2024
+ ...options?.color
2025
+ }
2026
+ };
2027
+ const hasColumns = loc.start && typeof loc.start.column === "number";
2028
+ let lines = normalizeLF(source).split("\n");
2029
+ if (typeof config?.tabWidth === "number") {
2030
+ lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
2031
+ }
2032
+ const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
2033
+ const numberMaxWidth = String(end).length;
2034
+ const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
2035
+ let frame = lines.slice(start, end).map((line, index) => {
2036
+ const number = start + 1 + index;
2037
+ const hasMarker = markerLines[number];
2038
+ const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
2039
+ const lastMarkerLine = !markerLines[number + 1];
2040
+ const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
2041
+ if (hasMarker) {
2042
+ let markerLine = "";
2043
+ if (Array.isArray(hasMarker)) {
2044
+ const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
2045
+ const numberOfMarkers = hasMarker[1] || 1;
2046
+ markerLine = [
2047
+ "\n ",
2048
+ config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
2049
+ " ",
2050
+ markerSpacing,
2051
+ colorizeMarker("^").repeat(numberOfMarkers)
2052
+ ].join("");
2053
+ if (lastMarkerLine && config.message) {
2054
+ markerLine += ` ${colorizeMessage(config.message)}`;
2055
+ }
2056
+ }
2057
+ return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
2058
+ }
2059
+ return `${config.prefix} ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
2060
+ }).join("\n");
2061
+ if (config.message && !hasColumns) {
2062
+ frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
2063
+ ${frame}`;
2064
+ }
2065
+ return frame;
2066
+ };
2067
+
2068
+ const debugLog = (message, ...arguments_) => {
2069
+ if (process.env.DEBUG && String(process.env.DEBUG) === "true") {
2070
+ console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);
2071
+ }
2072
+ };
2073
+ const UNKNOWN_FUNCTION = "<unknown>";
2074
+ const CHROMIUM_REGEX = /^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
2075
+ const CHROMIUM_EVAL_REGEX = /\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/;
2076
+ const CHROMIUM_MAPPED = /(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/;
2077
+ const WINDOWS_EVAL_REGEX = /(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/;
2078
+ const NODE_REGEX = /^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/;
2079
+ const NODE_NESTED_REGEX = /in\s(.*)\s\(at\s(.+)\)\sat/;
2080
+ const REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\d+):(\d+)$/;
2081
+ const GECKO_REGEX = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
2082
+ const GECKO_EVAL_REGEX = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
2083
+ const FIREFOX_REGEX = /(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/;
2084
+ const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
2085
+ const extractSafariExtensionDetails = (methodName, url) => {
2086
+ const isSafariExtension = methodName.includes("safari-extension");
2087
+ const isSafariWebExtension = methodName.includes("safari-web-extension");
2088
+ return isSafariExtension || isSafariWebExtension ? [
2089
+ methodName.includes("@") ? methodName.split("@")[0] : UNKNOWN_FUNCTION,
2090
+ isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`
2091
+ ] : [methodName, url];
2092
+ };
2093
+ const parseMapped = (trace, maybeMapped) => {
2094
+ const match = CHROMIUM_MAPPED.exec(maybeMapped);
2095
+ if (match) {
2096
+ trace.file = match[1];
2097
+ trace.line = +match[2];
2098
+ trace.column = +match[3];
2099
+ }
2100
+ };
2101
+ const parseNode = (line) => {
2102
+ const nestedNode = NODE_NESTED_REGEX.exec(line);
2103
+ if (nestedNode) {
2104
+ debugLog(`parse nested node error stack line: "${line}"`, `found: ${JSON.stringify(nestedNode)}`);
2105
+ const split = nestedNode[2].split(":");
2106
+ return {
2107
+ column: split[2] ? +split[2] : void 0,
2108
+ file: split[0],
2109
+ line: split[1] ? +split[1] : void 0,
2110
+ methodName: nestedNode[1] || UNKNOWN_FUNCTION,
2111
+ raw: line,
2112
+ type: void 0
2113
+ };
2114
+ }
2115
+ const node = NODE_REGEX.exec(line);
2116
+ if (node) {
2117
+ debugLog(`parse node error stack line: "${line}"`, `found: ${JSON.stringify(node)}`);
2118
+ const trace = {
2119
+ column: node[4] ? +node[4] : void 0,
2120
+ file: node[2] ? node[2].replace(/at\s/, "") : void 0,
2121
+ line: node[3] ? +node[3] : void 0,
2122
+ methodName: node[1] || UNKNOWN_FUNCTION,
2123
+ raw: line,
2124
+ type: line.startsWith("internal") ? "internal" : void 0
2125
+ };
2126
+ parseMapped(trace, `${node[2]}:${node[3]}:${node[4]}`);
2127
+ return trace;
2128
+ }
2129
+ return void 0;
2130
+ };
2131
+ const parseChromium = (line) => {
2132
+ const parts = CHROMIUM_REGEX.exec(line);
2133
+ if (parts) {
2134
+ debugLog(`parse chrome error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
2135
+ const isNative = parts[2]?.startsWith("native");
2136
+ const isEval = parts[2]?.startsWith("eval") || parts[1]?.startsWith("eval");
2137
+ let evalOrigin;
2138
+ let windowsParts;
2139
+ if (isEval) {
2140
+ const subMatch = CHROMIUM_EVAL_REGEX.exec(line);
2141
+ if (subMatch) {
2142
+ const split = /^(\S+):(\d+):(\d+)$|^(\S+):(\d+)$/.exec(subMatch[1]);
2143
+ if (split) {
2144
+ parts[2] = split[4] ?? split[1];
2145
+ parts[3] = split[5] ?? split[2];
2146
+ parts[4] = split[3];
2147
+ } else if (subMatch[2]) {
2148
+ parts[2] = subMatch[1];
2149
+ }
2150
+ if (subMatch[2]) {
2151
+ evalOrigin = {
2152
+ column: subMatch[4] ? +subMatch[4] : void 0,
2153
+ file: subMatch[2],
2154
+ line: subMatch[3] ? +subMatch[3] : void 0,
2155
+ methodName: "eval",
2156
+ raw: line,
2157
+ type: "eval"
2158
+ };
2159
+ }
2160
+ } else {
2161
+ const windowsSubMatch = WINDOWS_EVAL_REGEX.exec(line);
2162
+ if (windowsSubMatch) {
2163
+ windowsParts = {
2164
+ column: windowsSubMatch[5] ? +windowsSubMatch[5] : void 0,
2165
+ file: windowsSubMatch[3],
2166
+ line: windowsSubMatch[4] ? +windowsSubMatch[4] : void 0
2167
+ };
2168
+ evalOrigin = {
2169
+ column: windowsSubMatch[8] ? +windowsSubMatch[8] : void 0,
2170
+ file: windowsSubMatch[2],
2171
+ line: windowsSubMatch[7] ? +windowsSubMatch[7] : void 0,
2172
+ methodName: "eval",
2173
+ raw: windowsSubMatch[0],
2174
+ type: "eval"
2175
+ };
2176
+ }
2177
+ }
2178
+ }
2179
+ const [methodName, file] = extractSafariExtensionDetails(
2180
+ // Normalize IE's 'Anonymous function'
2181
+ parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
2182
+ parts[2]
2183
+ );
2184
+ const trace = {
2185
+ column: parts[4] ? +parts[4] : void 0,
2186
+ evalOrigin,
2187
+ file,
2188
+ line: parts[3] ? +parts[3] : void 0,
2189
+ methodName,
2190
+ raw: line,
2191
+ // eslint-disable-next-line sonarjs/no-nested-conditional
2192
+ type: isEval ? "eval" : isNative ? "native" : void 0
2193
+ };
2194
+ if (windowsParts) {
2195
+ trace.column = windowsParts.column;
2196
+ trace.file = windowsParts.file;
2197
+ trace.line = windowsParts.line;
2198
+ } else {
2199
+ parseMapped(trace, `${file}:${parts[3]}:${parts[4]}`);
2200
+ }
2201
+ return trace;
2202
+ }
2203
+ return void 0;
2204
+ };
2205
+ const parseGecko = (line, topFrameMeta) => {
2206
+ const parts = GECKO_REGEX.exec(line);
2207
+ if (parts) {
2208
+ debugLog(`parse gecko error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
2209
+ const isEval = parts[3]?.includes(" > eval");
2210
+ const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);
2211
+ let evalOrigin;
2212
+ if (isEval && subMatch) {
2213
+ parts[3] = subMatch[1];
2214
+ evalOrigin = {
2215
+ column: parts[5] ? +parts[5] : void 0,
2216
+ file: parts[3],
2217
+ line: parts[4] ? +parts[4] : void 0,
2218
+ methodName: "eval",
2219
+ raw: line,
2220
+ type: "eval"
2221
+ };
2222
+ parts[4] = subMatch[2];
2223
+ }
2224
+ const [methodName, file] = extractSafariExtensionDetails(
2225
+ // Normalize IE's 'Anonymous function'
2226
+ parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
2227
+ parts[3]
2228
+ );
2229
+ let column;
2230
+ if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.column) {
2231
+ column = topFrameMeta.column;
2232
+ } else if (!isEval && parts[5]) {
2233
+ column = +parts[5];
2234
+ }
2235
+ let lineNumber;
2236
+ if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.line) {
2237
+ lineNumber = topFrameMeta.line;
2238
+ } else if (parts[4]) {
2239
+ lineNumber = +parts[4];
2240
+ }
2241
+ return {
2242
+ column,
2243
+ evalOrigin,
2244
+ file,
2245
+ line: lineNumber,
2246
+ methodName,
2247
+ raw: line,
2248
+ // eslint-disable-next-line sonarjs/no-nested-conditional
2249
+ type: isEval ? "eval" : file.includes("[native code]") ? "native" : void 0
2250
+ };
2251
+ }
2252
+ return void 0;
2253
+ };
2254
+ const parseFirefox = (line, topFrameMeta) => {
2255
+ const parts = FIREFOX_REGEX.exec(line);
2256
+ const isEval = parts ? parts[2].includes(" > eval") : false;
2257
+ if (!isEval && parts) {
2258
+ debugLog(`parse firefox error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
2259
+ return {
2260
+ column: parts[4] ? +parts[4] : topFrameMeta?.column ?? void 0,
2261
+ file: parts[2],
2262
+ line: parts[3] ? +parts[3] : topFrameMeta?.line ?? void 0,
2263
+ methodName: parts[1] || UNKNOWN_FUNCTION,
2264
+ raw: line,
2265
+ type: void 0
2266
+ };
2267
+ }
2268
+ return void 0;
2269
+ };
2270
+ const parseReactAndroidNative = (line) => {
2271
+ const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);
2272
+ if (parts) {
2273
+ debugLog(`parse react android native error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
2274
+ return {
2275
+ column: parts[3] ? +parts[3] : void 0,
2276
+ file: parts[1],
2277
+ line: parts[2] ? +parts[2] : void 0,
2278
+ methodName: UNKNOWN_FUNCTION,
2279
+ raw: line,
2280
+ type: void 0
2281
+ };
2282
+ }
2283
+ return void 0;
2284
+ };
2285
+ const parseStacktrace = (error, { filter, frameLimit = 50 } = {}) => {
2286
+ let lines = (error.stacktrace ?? error.stack ?? "").split("\n").map((line) => {
2287
+ const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, "$1") : line;
2288
+ return cleanedLine.replace(/^\s+|\s+$/g, "");
2289
+ }).filter((line) => !/\S*(?:Error: |AggregateError:)/.test(line) && line !== "eval code");
2290
+ if (filter) {
2291
+ lines = lines.filter((element) => filter(element));
2292
+ }
2293
+ lines = lines.slice(0, frameLimit);
2294
+ return lines.reduce((stack, line, currentIndex) => {
2295
+ if (!line) {
2296
+ return stack;
2297
+ }
2298
+ if (line.length > 1024) {
2299
+ return stack;
2300
+ }
2301
+ let parseResult;
2302
+ if (/^\s*in\s.*/.test(line)) {
2303
+ parseResult = parseNode(line);
2304
+ } else if (/^.*?\s*at\s.*/.test(line)) {
2305
+ parseResult = parseChromium(line);
2306
+ } else if (/^.*?\s*@.*|\[native code\]/.test(line)) {
2307
+ let topFrameMeta;
2308
+ if (currentIndex === 0) {
2309
+ if (error.columnNumber || error.lineNumber) {
2310
+ topFrameMeta = {
2311
+ // @ts-expect-error columnNumber and columnNumber property only exists on Firefox
2312
+ column: error.columnNumber,
2313
+ // @ts-expect-error columnNumber and lineNumber property only exists on Firefox
2314
+ line: error.lineNumber,
2315
+ type: "firefox"
2316
+ };
2317
+ } else if (error.line || error.column) {
2318
+ topFrameMeta = {
2319
+ // @ts-expect-error column property only exists on safari
2320
+ column: error.column,
2321
+ // @ts-expect-error line property only exists on safari
2322
+ line: error.line,
2323
+ type: "safari"
2324
+ };
2325
+ }
2326
+ }
2327
+ parseResult = parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);
2328
+ } else {
2329
+ parseResult = parseReactAndroidNative(line);
2330
+ }
2331
+ if (parseResult) {
2332
+ stack.push(parseResult);
2333
+ } else {
2334
+ debugLog(`parse error stack line: "${line}"`, "not parser found");
2335
+ }
2336
+ return stack;
2337
+ }, []);
2338
+ };
2339
+
2340
+ const {
2341
+ existsSync,
2342
+ readFileSync
2343
+ } = __cjs_getBuiltinModule("node:fs");
2344
+ const {
2345
+ relative
2346
+ } = __cjs_getBuiltinModule("node:path");
2347
+ const {
2348
+ cwd
2349
+ } = __cjs_getProcess;
2350
+ const {
2351
+ fileURLToPath
2352
+ } = __cjs_getBuiltinModule("node:url");
2353
+ const getPrefix = (prefix, indentation, deep) => {
2354
+ if (deep === 0) {
2355
+ return prefix.toString();
2356
+ }
2357
+ if (indentation === " ") {
2358
+ return prefix + " ".repeat(deep);
2359
+ }
2360
+ return prefix + " ".repeat(indentation * deep);
2361
+ };
2362
+ const getRelativePath = (filePath, cwdPath) => {
2363
+ const path = filePath.replace("async file:", "file:");
2364
+ return relative(cwdPath, path.startsWith("file:") ? fileURLToPath(path) : path);
2365
+ };
2366
+ const getTitleText = (error, hideErrorTitle, color) => {
2367
+ if (hideErrorTitle) {
2368
+ return color.title(error.message);
2369
+ }
2370
+ const messagePart = error.message ? `: ${error.message}` : "";
2371
+ return color.title(error.name + messagePart);
2372
+ };
2373
+ const getMessage = (error, { color, hideErrorTitle, indentation, prefix }, deep) => `${getPrefix(prefix, indentation, deep)}${getTitleText(error, hideErrorTitle, color)}
2374
+ `;
2375
+ const getHint = (error, { color, indentation, prefix }, deep) => {
2376
+ if (error.hint === void 0) {
2377
+ return void 0;
2378
+ }
2379
+ const spaces = getPrefix(prefix, indentation, deep);
2380
+ let message = "";
2381
+ if (Array.isArray(error.hint)) {
2382
+ for (const line of error.hint) {
2383
+ message += `${(spaces + line).toString()}
2384
+ `;
2385
+ }
2386
+ } else {
2387
+ message += spaces + error.hint;
2388
+ }
2389
+ return color.hint(message);
2390
+ };
2391
+ const getMainFrame = (trace, { color, cwd: cwdPath, displayShortPath, indentation, prefix }, deep = 0) => {
2392
+ const filePath = displayShortPath ? getRelativePath(trace.file, cwdPath) : trace.file;
2393
+ const { fileLine, method } = color;
2394
+ return `${getPrefix(prefix, indentation, deep)}at ${trace.methodName ? `${method(trace.methodName)} ` : ""}${fileLine(filePath)}:${fileLine(
2395
+ trace.line?.toString() ?? ""
2396
+ )}`.toString();
2397
+ };
2398
+ const getCode = (trace, { color, indentation, linesAbove, linesBelow, prefix, showGutter, showLineNumbers, tabWidth }, deep) => {
2399
+ if (trace.file === void 0) {
2400
+ return void 0;
2401
+ }
2402
+ const filePath = trace.file.replace("file://", "");
2403
+ if (!existsSync(filePath)) {
2404
+ return void 0;
2405
+ }
2406
+ const fileContent = readFileSync(filePath, "utf8");
2407
+ return codeFrame(
2408
+ fileContent,
2409
+ {
2410
+ start: { column: trace.column, line: trace.line }
2411
+ },
2412
+ { color, linesAbove, linesBelow, prefix: getPrefix(prefix, indentation, deep), showGutter, showLineNumbers, tabWidth }
2413
+ );
2414
+ };
2415
+ const getErrors = (error, options, deep) => {
2416
+ if (error.errors.length === 0) {
2417
+ return void 0;
2418
+ }
2419
+ let message = `${getPrefix(options.prefix, options.indentation, deep)}Errors:
2420
+
2421
+ `;
2422
+ let first = true;
2423
+ for (const error_ of error.errors) {
2424
+ if (first) {
2425
+ first = false;
2426
+ } else {
2427
+ message += "\n\n";
2428
+ }
2429
+ message += internalRenderError(error_, { ...options, framesMaxLimit: 1, hideErrorCodeView: options.hideErrorErrorsCodeView }, deep + 1);
2430
+ }
2431
+ return `
2432
+ ${message}`;
2433
+ };
2434
+ const getCause = (error, options, deep) => {
2435
+ let message = `${getPrefix(options.prefix, options.indentation, deep)}Caused by:
2436
+
2437
+ `;
2438
+ const cause = error.cause;
2439
+ message += getMessage(cause, options, deep);
2440
+ const stacktrace = parseStacktrace(cause);
2441
+ const mainFrame = stacktrace.shift();
2442
+ const hint = getHint(cause, options, deep);
2443
+ if (hint) {
2444
+ message += `${hint}
2445
+ `;
2446
+ }
2447
+ if (mainFrame) {
2448
+ message += getMainFrame(mainFrame, options, deep);
2449
+ if (!options.hideErrorCauseCodeView) {
2450
+ const code = getCode(mainFrame, options, deep);
2451
+ if (code !== void 0) {
2452
+ message += `
2453
+ ${code}`;
2454
+ }
2455
+ }
2456
+ }
2457
+ if (cause.cause) {
2458
+ message += `
2459
+ ${getCause(cause, options, deep + 1)}`;
2460
+ } else if (cause instanceof AggregateError) {
2461
+ const errors = getErrors(cause, options, deep);
2462
+ if (errors !== void 0) {
2463
+ message += `
2464
+ ${errors}`;
2465
+ }
2466
+ }
2467
+ return `
2468
+ ${message}`;
2469
+ };
2470
+ const getStacktrace = (stack, options) => (stack.length > 0 ? "\n" : "") + stack.map((frame) => getMainFrame(frame, options)).join("\n");
2471
+ const internalRenderError = (error, options, deep) => {
2472
+ const config = {
2473
+ cwd: cwd(),
2474
+ displayShortPath: false,
2475
+ filterStacktrace: void 0,
2476
+ framesMaxLimit: Number.POSITIVE_INFINITY,
2477
+ hideErrorCauseCodeView: false,
2478
+ hideErrorCodeView: false,
2479
+ hideErrorErrorsCodeView: false,
2480
+ hideErrorTitle: false,
2481
+ hideMessage: false,
2482
+ indentation: 4,
2483
+ linesAbove: 2,
2484
+ linesBelow: 3,
2485
+ prefix: "",
2486
+ showGutter: true,
2487
+ showLineNumbers: true,
2488
+ tabWidth: 4,
2489
+ ...options,
2490
+ color: {
2491
+ fileLine: (value) => value,
2492
+ gutter: (value) => value,
2493
+ hint: (value) => value,
2494
+ marker: (value) => value,
2495
+ message: (value) => value,
2496
+ method: (value) => value,
2497
+ title: (value) => value,
2498
+ ...options.color
2499
+ }
2500
+ };
2501
+ const stack = parseStacktrace(error, {
2502
+ filter: options.filterStacktrace,
2503
+ frameLimit: config.framesMaxLimit
2504
+ });
2505
+ const mainFrame = stack.shift();
2506
+ return [
2507
+ options.hideMessage ? void 0 : getMessage(error, config, deep),
2508
+ getHint(error, config, deep),
2509
+ mainFrame ? getMainFrame(mainFrame, config, deep) : void 0,
2510
+ mainFrame && !config.hideErrorCodeView ? getCode(mainFrame, config, deep) : void 0,
2511
+ error instanceof AggregateError ? getErrors(error, config, deep) : void 0,
2512
+ error.cause === void 0 ? void 0 : getCause(error, config, deep),
2513
+ stack.length > 0 ? getStacktrace(stack, config) : void 0
2514
+ ].filter(Boolean).join("\n").replaceAll("\\", "/");
2515
+ };
2516
+ const renderError = (error, options = {}) => {
2517
+ if (options.framesMaxLimit !== void 0 && options.framesMaxLimit <= 0) {
2518
+ throw new RangeError("The 'framesMaxLimit' option must be a positive number");
2519
+ }
2520
+ return internalRenderError(error, options, 0);
2521
+ };
2522
+
2523
+ const getLongestBadge = (types) => {
2524
+ const badges = Object.keys(types).map((x) => types[x].badge ?? "");
2525
+ if (badges.length === 0) {
2526
+ return "";
2527
+ }
2528
+ return badges.reduce((x, y) => x.length > y.length ? x : y);
2529
+ };
2530
+
2531
+ const defaultInspectorConfig = {
2532
+ indent: 2,
2533
+ quoteStyle: "single",
2534
+ stylize: (string_, style) => {
2535
+ const styles = {
2536
+ bigint: yellow,
2537
+ boolean: yellow,
2538
+ date: magenta,
2539
+ null: bold,
2540
+ number: yellow,
2541
+ regexp: red,
2542
+ special: cyan,
2543
+ string: green,
2544
+ symbol: green,
2545
+ undefined: grey
2546
+ };
2547
+ if (styles[style] === void 0) {
2548
+ return string_;
2549
+ }
2550
+ return styles[style](string_);
2551
+ }
2552
+ };
2553
+
2554
+ const formatLabel = (label, styles) => {
2555
+ let formattedLabel = styles.uppercase.label ? label.toUpperCase() : label;
2556
+ formattedLabel = styles.underline.label ? underline(formattedLabel) : formattedLabel;
2557
+ if (styles.bold.label) {
2558
+ formattedLabel = bold(formattedLabel);
2559
+ }
2560
+ return formattedLabel;
2561
+ };
2562
+
2563
+ const dateFormatter = (date) => [date.getHours(), date.getMinutes(), date.getSeconds()].map((n) => String(n).padStart(2, "0")).join(":");
2564
+ class AbstractPrettyReporter {
2565
+ /** Styling options for pretty formatting */
2566
+ styles;
2567
+ /** Logger type configurations for styling */
2568
+ loggerTypes;
2569
+ /**
2570
+ * Creates a new AbstractPrettyReporter instance.
2571
+ * @param options Styling options for pretty formatting
2572
+ * @protected
2573
+ */
2574
+ constructor(options) {
2575
+ this.styles = {
2576
+ bold: {
2577
+ label: false
2578
+ },
2579
+ dateFormatter,
2580
+ underline: {
2581
+ label: false,
2582
+ message: false,
2583
+ prefix: false,
2584
+ suffix: false
2585
+ },
2586
+ uppercase: {
2587
+ label: false
2588
+ },
2589
+ ...options
2590
+ };
2591
+ this.loggerTypes = LOG_TYPES;
2592
+ }
2593
+ /**
2594
+ * Sets the logger types configuration for styling.
2595
+ * @param types Logger type configurations with colors and labels
2596
+ */
2597
+ setLoggerTypes(types) {
2598
+ this.loggerTypes = types;
2599
+ }
2600
+ }
2601
+
2602
+ export { AbstractPrettyReporter as A, EXTENDED_RFC_5424_LOG_LEVELS as E, LOG_TYPES as L, WrapMode as W, EMPTY_SYMBOL as a, writeStream as b, getLongestBadge as c, defaultInspectorConfig as d, getStringWidth as e, formatLabel as f, getLongestLabel as g, inspect as i, renderError as r, terminalSize as t, wordWrap as w };