@visulima/pail 4.0.0-alpha.10 → 4.0.0-alpha.12

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 (106) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE.md +143 -931
  3. package/dist/error.d.ts +95 -96
  4. package/dist/index.browser.d.ts +557 -47
  5. package/dist/index.browser.js +2 -2
  6. package/dist/index.server.d.ts +722 -65
  7. package/dist/index.server.js +27 -410
  8. package/dist/middleware/elysia.d.ts +65 -63
  9. package/dist/middleware/elysia.js +2 -2
  10. package/dist/middleware/express.d.ts +73 -71
  11. package/dist/middleware/express.js +1 -1
  12. package/dist/middleware/fastify.d.ts +69 -67
  13. package/dist/middleware/fastify.js +2 -2
  14. package/dist/middleware/hono.d.ts +74 -72
  15. package/dist/middleware/next/handler.d.ts +101 -34
  16. package/dist/middleware/sveltekit.d.ts +100 -98
  17. package/dist/object-tree.d.ts +67 -70
  18. package/dist/packem_shared/{AbstractJsonReporter-DlugSJpY.js → AbstractJsonReporter-BO8Calb4.js} +1 -5
  19. package/dist/packem_shared/{AbstractJsonReporter-CjtVgHbU.js → AbstractJsonReporter-nOj0Ft1F.js} +1 -5
  20. package/dist/packem_shared/{JsonReporter-Dbw82ewj.js → JsonReporter-CCmj7oYL.js} +1 -1
  21. package/dist/packem_shared/{JsonReporter-BgPvIyC2.js → JsonReporter-Ck2PIAEw.js} +2 -2
  22. package/dist/packem_shared/{PrettyReporter-C2dCzIaf.js → PrettyReporter-CIbrmjUV.js} +2 -4
  23. package/dist/packem_shared/{PrettyReporter-gMqa7j_m.js → PrettyReporter-CNJEO9g7.js} +1250 -15
  24. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  25. package/dist/packem_shared/{abstract-pretty-reporter-szQO-IgK.js → abstract-pretty-reporter-CkqCt5hg.js} +2300 -2298
  26. package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
  27. package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
  28. package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
  29. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  30. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  31. package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
  32. package/dist/packem_shared/{write-stream-BuFtjATz.js → write-stream-MDqyXmc_.js} +1 -1
  33. package/dist/processor/caller/caller-processor.d.ts +49 -47
  34. package/dist/processor/caller/caller-processor.js +1 -1
  35. package/dist/processor/environment-processor.d.ts +113 -113
  36. package/dist/processor/message-formatter-processor.d.ts +51 -49
  37. package/dist/processor/message-formatter-processor.js +2 -2
  38. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  39. package/dist/processor/redact-processor.d.ts +60 -41
  40. package/dist/processor/sampling-processor.d.ts +102 -101
  41. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  42. package/dist/reporter/file/json-file-reporter.js +1 -1
  43. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  44. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  45. package/dist/reporter/http/http-reporter.d.ts +40 -36
  46. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  47. package/dist/reporter/http/http-reporter.edge-light.js +1 -5
  48. package/dist/reporter/json/index.browser.d.ts +99 -3
  49. package/dist/reporter/json/index.browser.js +2 -2
  50. package/dist/reporter/json/index.d.ts +51 -3
  51. package/dist/reporter/json/index.js +2 -2
  52. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +219 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  57. package/dist/reporter/simple/simple-reporter.server.js +3 -2
  58. package/dist/wide-event.d.ts +5 -300
  59. package/dist/wide-event.js +3 -2
  60. package/package.json +9 -21
  61. package/dist/constants.d.ts +0 -37
  62. package/dist/interactive/index.d.ts +0 -2
  63. package/dist/interactive/index.js +0 -2
  64. package/dist/interactive/interactive-manager.d.ts +0 -108
  65. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  66. package/dist/middleware/next/middleware.d.ts +0 -59
  67. package/dist/middleware/next/storage.d.ts +0 -14
  68. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  69. package/dist/middleware/shared/headers.d.ts +0 -14
  70. package/dist/middleware/shared/routes.d.ts +0 -30
  71. package/dist/middleware/shared/storage.d.ts +0 -29
  72. package/dist/packem_shared/InteractiveManager-CowYA3Hx.js +0 -178
  73. package/dist/packem_shared/InteractiveStreamHook-BypRlYTX.js +0 -133
  74. package/dist/packem_shared/Spinner-Cokext9b.js +0 -2183
  75. package/dist/packem_shared/getBarChar-D7JfmdTr.js +0 -459
  76. package/dist/packem_shared/index-BEfVUy9P.js +0 -1256
  77. package/dist/pail.browser.d.ts +0 -412
  78. package/dist/pail.server.d.ts +0 -233
  79. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  80. package/dist/progress-bar.d.ts +0 -145
  81. package/dist/progress-bar.js +0 -459
  82. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  83. package/dist/reporter/http/utils/compression.d.ts +0 -7
  84. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  85. package/dist/reporter/http/utils/retry.d.ts +0 -27
  86. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  87. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  88. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  89. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  90. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  91. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  92. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  93. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  94. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  95. package/dist/reporter/utils/format-label.d.ts +0 -3
  96. package/dist/spinner.d.ts +0 -220
  97. package/dist/spinner.js +0 -2183
  98. package/dist/types.d.ts +0 -241
  99. package/dist/utils/ansi-escapes.d.ts +0 -4
  100. package/dist/utils/arrayify.d.ts +0 -2
  101. package/dist/utils/get-longest-badge.d.ts +0 -4
  102. package/dist/utils/get-longest-label.d.ts +0 -4
  103. package/dist/utils/merge-types.d.ts +0 -4
  104. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  105. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  106. package/dist/utils/write-stream.d.ts +0 -2
@@ -17,14 +17,19 @@ const __cjs_getBuiltinModule = (module) => {
17
17
  return __cjs_require(module);
18
18
  };
19
19
 
20
+ const process$2 = __cjs_getProcess;
20
21
  const {
21
22
  stdout,
22
23
  stderr
23
- } = __cjs_getProcess;
24
- import colorize, { grey, green, cyan, red, yellow, bold, magenta, underline, greenBright, bgGrey, white } from '@visulima/colorize';
25
- import { t as terminalSize, g as getStringWidth, w as wordWrap, W as WrapMode } from './index-BEfVUy9P.js';
24
+ } = process$2;
25
+ import colorize 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");
26
31
  import { L as LOG_TYPES, E as EMPTY_SYMBOL } from './constants-B1RjD_ps.js';
27
- import { w as writeStream } from './write-stream-BuFtjATz.js';
32
+ import { w as writeStream } from './write-stream-MDqyXmc_.js';
28
33
  const {
29
34
  createRequire
30
35
  } = __cjs_getBuiltinModule("node:module");
@@ -1194,6 +1199,1235 @@ const inspect = (value, options_ = {}) => {
1194
1199
  return internalInspect(value, options, 0, []);
1195
1200
  };
1196
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
+
1197
2431
  const getLongestBadge = (types) => {
1198
2432
  const badges = Object.keys(types).map((x) => types[x].badge ?? "");
1199
2433
  if (badges.length === 0) {
@@ -1210,6 +2444,7 @@ const getLongestLabel = (types) => {
1210
2444
  return labels.reduce((x, y) => x.length > y.length ? x : y, "");
1211
2445
  };
1212
2446
 
2447
+ const { bold: bold$1, cyan: cyan$1, green: green$1, grey: grey$1, magenta, red: red$1, yellow } = colorize;
1213
2448
  const defaultInspectorConfig = {
1214
2449
  indent: 2,
1215
2450
  quoteStyle: "single",
@@ -1218,24 +2453,25 @@ const defaultInspectorConfig = {
1218
2453
  bigint: yellow,
1219
2454
  boolean: yellow,
1220
2455
  date: magenta,
1221
- null: bold,
2456
+ null: bold$1,
1222
2457
  number: yellow,
1223
- regexp: red,
1224
- special: cyan,
1225
- string: green,
1226
- symbol: green,
1227
- undefined: grey
2458
+ regexp: red$1,
2459
+ special: cyan$1,
2460
+ string: green$1,
2461
+ symbol: green$1,
2462
+ undefined: grey$1
1228
2463
  };
1229
- if (styles[style] === void 0) {
2464
+ if (!Object.hasOwn(styles, style)) {
1230
2465
  return string_;
1231
2466
  }
1232
2467
  return styles[style](string_);
1233
2468
  }
1234
2469
  };
1235
2470
 
2471
+ const { bold, underline: underline$1 } = colorize;
1236
2472
  const formatLabel = (label, styles) => {
1237
2473
  let formattedLabel = styles.uppercase.label ? label.toUpperCase() : label;
1238
- formattedLabel = styles.underline.label ? underline(formattedLabel) : formattedLabel;
2474
+ formattedLabel = styles.underline.label ? underline$1(formattedLabel) : formattedLabel;
1239
2475
  if (styles.bold.label) {
1240
2476
  formattedLabel = bold(formattedLabel);
1241
2477
  }
@@ -1281,6 +2517,7 @@ class AbstractPrettyReporter {
1281
2517
  }
1282
2518
  }
1283
2519
 
2520
+ const { bgGrey, cyan, green, greenBright, grey, red, underline, white } = colorize;
1284
2521
  const PAIL_DIST_REGEX = /[\\/]pail[\\/]dist/;
1285
2522
  const pailFileFilter = (line) => !PAIL_DIST_REGEX.test(line);
1286
2523
  class PrettyReporter extends AbstractPrettyReporter {
@@ -1390,9 +2627,7 @@ class PrettyReporter extends AbstractPrettyReporter {
1390
2627
  items.push(` ${grey(`[${scope.join(" > ")}]`)} `);
1391
2628
  }
1392
2629
  if (prefix) {
1393
- items.push(
1394
- `${grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `
1395
- );
2630
+ items.push(`${grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `);
1396
2631
  }
1397
2632
  const titleSize = getStringWidth(items.join(" "));
1398
2633
  if (file) {