@visulima/pail 4.0.0-alpha.1 → 4.0.0-alpha.11

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