@visulima/pail 4.0.0-alpha.3 → 4.0.0-alpha.5

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