@alchemy.run/sigil 0.0.0-alpha.1 → 0.0.0-alpha.2

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 (121) hide show
  1. package/README.md +299 -299
  2. package/dist/ansi.d.ts +223 -0
  3. package/dist/ansi.js +2 -0
  4. package/dist/{devtools-QpCMm9JH.mjs → devtools-BhYGjb7h.js} +1 -1
  5. package/dist/index-DDVME65c.d.ts +919 -0
  6. package/dist/index.d.ts +1657 -0
  7. package/dist/index.js +4643 -0
  8. package/dist/sgr-CMfEpjSk.d.ts +91 -0
  9. package/dist/truncate-CBiyyZzw.js +2156 -0
  10. package/dist/yoga-5jKhYCJC.js +3465 -0
  11. package/dist/yoga.d.ts +2 -0
  12. package/dist/yoga.js +2 -0
  13. package/package.json +37 -17
  14. package/src/ansi/chalk.ts +179 -0
  15. package/src/ansi/cursor.ts +48 -0
  16. package/src/ansi/east-asian-width.ts +215 -0
  17. package/src/ansi/escapes.ts +128 -0
  18. package/src/ansi/index.ts +27 -0
  19. package/src/ansi/sgr.ts +237 -0
  20. package/src/ansi/slice.ts +43 -0
  21. package/src/ansi/string-width.ts +236 -0
  22. package/src/ansi/strip.ts +33 -0
  23. package/src/ansi/supports-color.ts +213 -0
  24. package/src/ansi/tokenize.ts +453 -0
  25. package/src/ansi/truncate.ts +194 -0
  26. package/src/ansi/widest-line.ts +12 -0
  27. package/src/ansi/wrap.ts +766 -0
  28. package/src/ansi-tokenizer.ts +510 -0
  29. package/src/auto-bind.ts +41 -0
  30. package/src/boxes.ts +100 -0
  31. package/src/code-excerpt.ts +39 -0
  32. package/src/colorize.ts +60 -0
  33. package/src/components/AccessibilityContext.ts +5 -0
  34. package/src/components/AnimationContext.ts +24 -0
  35. package/src/components/App.tsx +781 -0
  36. package/src/components/AppContext.ts +111 -0
  37. package/src/components/BackgroundContext.ts +8 -0
  38. package/src/components/Box.tsx +116 -0
  39. package/src/components/CursorContext.ts +19 -0
  40. package/src/components/ErrorBoundary.tsx +38 -0
  41. package/src/components/ErrorOverview.tsx +133 -0
  42. package/src/components/FocusContext.ts +30 -0
  43. package/src/components/Newline.tsx +15 -0
  44. package/src/components/Spacer.tsx +10 -0
  45. package/src/components/Static.tsx +59 -0
  46. package/src/components/StderrContext.ts +26 -0
  47. package/src/components/StdinContext.ts +49 -0
  48. package/src/components/StdoutContext.ts +28 -0
  49. package/src/components/Text.tsx +144 -0
  50. package/src/components/Transform.tsx +37 -0
  51. package/src/cursor-position.ts +103 -0
  52. package/src/devtools-window-polyfill.ts +73 -0
  53. package/src/devtools.ts +43 -0
  54. package/src/dom.ts +292 -0
  55. package/src/get-max-width.ts +11 -0
  56. package/src/global.d.ts +36 -0
  57. package/src/hooks/use-animation.ts +142 -0
  58. package/src/hooks/use-app.ts +8 -0
  59. package/src/hooks/use-box-metrics.ts +134 -0
  60. package/src/hooks/use-cursor.ts +33 -0
  61. package/src/hooks/use-focus-manager.ts +62 -0
  62. package/src/hooks/use-focus.ts +83 -0
  63. package/src/hooks/use-input.ts +267 -0
  64. package/src/hooks/use-is-screen-reader-enabled.ts +12 -0
  65. package/src/hooks/use-paste.ts +78 -0
  66. package/src/hooks/use-stderr.ts +8 -0
  67. package/src/hooks/use-stdin.ts +10 -0
  68. package/src/hooks/use-stdout.ts +8 -0
  69. package/src/hooks/use-window-size.ts +41 -0
  70. package/src/indent-string.ts +16 -0
  71. package/src/index.ts +44 -0
  72. package/src/ink.tsx +1506 -0
  73. package/src/input-parser.ts +283 -0
  74. package/src/instances.ts +9 -0
  75. package/src/is-in-ci.ts +7 -0
  76. package/src/kitty-keyboard.ts +57 -0
  77. package/src/log-update.ts +370 -0
  78. package/src/measure-element.ts +62 -0
  79. package/src/measure-text.ts +31 -0
  80. package/src/output.ts +308 -0
  81. package/src/parse-keypress.ts +516 -0
  82. package/src/parse-stack-line.ts +139 -0
  83. package/src/patch-console.ts +62 -0
  84. package/src/quick-lru.ts +85 -0
  85. package/src/reconciler.ts +451 -0
  86. package/src/render-background.ts +38 -0
  87. package/src/render-border.ts +134 -0
  88. package/src/render-node-to-output.ts +191 -0
  89. package/src/render-to-string.ts +131 -0
  90. package/src/render.ts +276 -0
  91. package/src/renderer.ts +73 -0
  92. package/src/sanitize-ansi.ts +33 -0
  93. package/src/signal-exit.ts +107 -0
  94. package/src/squash-text-nodes.ts +40 -0
  95. package/src/stream.ts +30 -0
  96. package/src/styles.ts +748 -0
  97. package/src/terminal-size.ts +57 -0
  98. package/src/throttle.ts +73 -0
  99. package/src/types.ts +15 -0
  100. package/src/utils.ts +40 -0
  101. package/src/wrap-text.ts +50 -0
  102. package/src/write-synchronized.ts +9 -0
  103. package/src/yoga/config.ts +57 -0
  104. package/src/yoga/core/absoluteLayout.ts +626 -0
  105. package/src/yoga/core/baseline.ts +66 -0
  106. package/src/yoga/core/cache.ts +136 -0
  107. package/src/yoga/core/calculateLayout.ts +2920 -0
  108. package/src/yoga/core/config.ts +104 -0
  109. package/src/yoga/core/flexLine.ts +177 -0
  110. package/src/yoga/core/helpers.ts +293 -0
  111. package/src/yoga/core/layoutResults.ts +167 -0
  112. package/src/yoga/core/node.ts +611 -0
  113. package/src/yoga/core/numeric.ts +44 -0
  114. package/src/yoga/core/pixelGrid.ts +151 -0
  115. package/src/yoga/core/style.ts +887 -0
  116. package/src/yoga/core/types.ts +224 -0
  117. package/src/yoga/generated/YGEnums.ts +263 -0
  118. package/src/yoga/index.ts +19 -0
  119. package/src/yoga/node.ts +1140 -0
  120. package/dist/index.d.mts +0 -2379
  121. package/dist/index.mjs +0 -10072
@@ -0,0 +1,2156 @@
1
+ import process from "node:process";
2
+ import os from "node:os";
3
+ import tty from "node:tty";
4
+ //#region src/ansi/escapes.ts
5
+ const ESC = "\x1B";
6
+ const BEL = "\x07";
7
+ const DEL = "";
8
+ /** Control Sequence Introducer. */
9
+ const CSI$1 = `[`;
10
+ /** Operating System Command. */
11
+ const OSC$1 = `]`;
12
+ /** String Terminator. */
13
+ const ST = `\\`;
14
+ /** Single-byte C1 forms of CSI and ST. */
15
+ const C1_CSI = "›";
16
+ const C1_ST = "œ";
17
+ const sep = ";";
18
+ const cursorTo = (x, y) => {
19
+ if (typeof y !== "number") return CSI$1 + (x + 1) + "G";
20
+ return CSI$1 + (y + 1) + sep + (x + 1) + "H";
21
+ };
22
+ const cursorUp = (count = 1) => CSI$1 + count + "A";
23
+ const cursorDown = (count = 1) => CSI$1 + count + "B";
24
+ const cursorLeft = CSI$1 + "G";
25
+ const cursorNextLine = CSI$1 + "E";
26
+ const eraseEndLine = CSI$1 + "K";
27
+ const eraseLine = CSI$1 + "2K";
28
+ const eraseScreen = CSI$1 + "2J";
29
+ const eraseLines = (count) => {
30
+ let clear = "";
31
+ for (let i = 0; i < count; i++) clear += eraseLine + (i < count - 1 ? cursorUp() : "");
32
+ if (count) clear += cursorLeft;
33
+ return clear;
34
+ };
35
+ const isOldWindows = () => {
36
+ if (process.platform !== "win32") return false;
37
+ const parts = os.release().split(".");
38
+ const major = Number(parts[0]);
39
+ const build = Number(parts[2] ?? 0);
40
+ if (major < 10) return true;
41
+ return major === 10 && build < 10586;
42
+ };
43
+ const clearTerminal = isOldWindows() ? `${eraseScreen}${CSI$1}0f` : `${eraseScreen}${CSI$1}3J${CSI$1}H`;
44
+ const enterAlternativeScreen = CSI$1 + "?1049h";
45
+ const exitAlternativeScreen = CSI$1 + "?1049l";
46
+ const cursorShow = CSI$1 + "?25h";
47
+ const cursorHide = CSI$1 + "?25l";
48
+ const enableBracketedPaste = CSI$1 + "?2004h";
49
+ const disableBracketedPaste = CSI$1 + "?2004l";
50
+ const pasteStart = CSI$1 + "200~";
51
+ const pasteEnd = CSI$1 + "201~";
52
+ const bsu = CSI$1 + "?2026h";
53
+ const esu = CSI$1 + "?2026l";
54
+ const kittyQuery = CSI$1 + "?u";
55
+ const pushKittyKeyboard = (flags) => `${CSI$1}>${flags}u`;
56
+ const popKittyKeyboard = CSI$1 + "<u";
57
+ const link = (text, url) => [
58
+ OSC$1,
59
+ "8",
60
+ sep,
61
+ sep,
62
+ url,
63
+ "\x07",
64
+ text,
65
+ OSC$1,
66
+ "8",
67
+ sep,
68
+ sep,
69
+ "\x07"
70
+ ].join("");
71
+ const ansiEscapes = {
72
+ cursorTo,
73
+ cursorUp,
74
+ cursorDown,
75
+ cursorLeft,
76
+ cursorNextLine,
77
+ eraseEndLine,
78
+ eraseLine,
79
+ eraseScreen,
80
+ eraseLines,
81
+ clearTerminal,
82
+ enterAlternativeScreen,
83
+ exitAlternativeScreen,
84
+ cursorShow,
85
+ cursorHide,
86
+ enableBracketedPaste,
87
+ disableBracketedPaste,
88
+ pasteStart,
89
+ pasteEnd,
90
+ bsu,
91
+ esu,
92
+ kittyQuery,
93
+ pushKittyKeyboard,
94
+ popKittyKeyboard,
95
+ link
96
+ };
97
+ //#endregion
98
+ //#region src/ansi/sgr.ts
99
+ const ANSI_BACKGROUND_OFFSET = 10;
100
+ const wrapAnsi16 = (offset = 0) => (code) => `${CSI$1}${code + offset}m`;
101
+ const wrapAnsi256 = (offset = 0) => (code) => `${CSI$1}${38 + offset};5;${code}m`;
102
+ const wrapAnsi16m = (offset = 0) => (red, green, blue) => `${CSI$1}${38 + offset};2;${red};${green};${blue}m`;
103
+ const modifierCodes = {
104
+ reset: [0, 0],
105
+ bold: [1, 22],
106
+ dim: [2, 22],
107
+ italic: [3, 23],
108
+ underline: [4, 24],
109
+ overline: [53, 55],
110
+ inverse: [7, 27],
111
+ hidden: [8, 28],
112
+ strikethrough: [9, 29]
113
+ };
114
+ const colorCodes = {
115
+ black: [30, 39],
116
+ red: [31, 39],
117
+ green: [32, 39],
118
+ yellow: [33, 39],
119
+ blue: [34, 39],
120
+ magenta: [35, 39],
121
+ cyan: [36, 39],
122
+ white: [37, 39],
123
+ blackBright: [90, 39],
124
+ gray: [90, 39],
125
+ grey: [90, 39],
126
+ redBright: [91, 39],
127
+ greenBright: [92, 39],
128
+ yellowBright: [93, 39],
129
+ blueBright: [94, 39],
130
+ magentaBright: [95, 39],
131
+ cyanBright: [96, 39],
132
+ whiteBright: [97, 39]
133
+ };
134
+ const bgColorCodes = {
135
+ bgBlack: [40, 49],
136
+ bgRed: [41, 49],
137
+ bgGreen: [42, 49],
138
+ bgYellow: [43, 49],
139
+ bgBlue: [44, 49],
140
+ bgMagenta: [45, 49],
141
+ bgCyan: [46, 49],
142
+ bgWhite: [47, 49],
143
+ bgBlackBright: [100, 49],
144
+ bgGray: [100, 49],
145
+ bgGrey: [100, 49],
146
+ bgRedBright: [101, 49],
147
+ bgGreenBright: [102, 49],
148
+ bgYellowBright: [103, 49],
149
+ bgBlueBright: [104, 49],
150
+ bgMagentaBright: [105, 49],
151
+ bgCyanBright: [106, 49],
152
+ bgWhiteBright: [107, 49]
153
+ };
154
+ const modifierNames = Object.keys(modifierCodes);
155
+ const foregroundColorNames = Object.keys(colorCodes);
156
+ const backgroundColorNames = Object.keys(bgColorCodes);
157
+ const toPairs = (codes) => {
158
+ const result = {};
159
+ for (const [name, [open, close]] of Object.entries(codes)) result[name] = {
160
+ open: `${CSI$1}${open}m`,
161
+ close: `${CSI$1}${close}m`
162
+ };
163
+ return result;
164
+ };
165
+ /**
166
+ Named SGR styles as `{open, close}` escape sequence pairs.
167
+ */
168
+ const styles = {
169
+ ...toPairs(modifierCodes),
170
+ ...toPairs(colorCodes),
171
+ ...toPairs(bgColorCodes)
172
+ };
173
+ /**
174
+ Raw SGR code numbers: open code → close code.
175
+ */
176
+ const codes = new Map([
177
+ ...Object.values(modifierCodes),
178
+ ...Object.values(colorCodes),
179
+ ...Object.values(bgColorCodes)
180
+ ].map(([open, close]) => [open, close]));
181
+ const foreground = {
182
+ close: `${CSI$1}39m`,
183
+ ansi: wrapAnsi16(),
184
+ ansi256: wrapAnsi256(),
185
+ ansi16m: wrapAnsi16m()
186
+ };
187
+ const background = {
188
+ close: `${CSI$1}49m`,
189
+ ansi: wrapAnsi16(ANSI_BACKGROUND_OFFSET),
190
+ ansi256: wrapAnsi256(ANSI_BACKGROUND_OFFSET),
191
+ ansi16m: wrapAnsi16m(ANSI_BACKGROUND_OFFSET)
192
+ };
193
+ const rgbToAnsi256 = (red, green, blue) => {
194
+ if (red === green && green === blue) {
195
+ if (red < 8) return 16;
196
+ if (red > 248) return 231;
197
+ return Math.round((red - 8) / 247 * 24) + 232;
198
+ }
199
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
200
+ };
201
+ const hexToRgb = (hex) => {
202
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex);
203
+ if (!matches) return [
204
+ 0,
205
+ 0,
206
+ 0
207
+ ];
208
+ let [colorString] = matches;
209
+ if (colorString.length === 3) colorString = colorString.split("").map((character) => character + character).join("");
210
+ const integer = Number.parseInt(colorString, 16);
211
+ return [
212
+ integer >> 16 & 255,
213
+ integer >> 8 & 255,
214
+ integer & 255
215
+ ];
216
+ };
217
+ const hexToAnsi256 = (hex) => rgbToAnsi256(...hexToRgb(hex));
218
+ const ansi256ToAnsi = (code) => {
219
+ if (code < 8) return 30 + code;
220
+ if (code < 16) return 90 + (code - 8);
221
+ let red;
222
+ let green;
223
+ let blue;
224
+ if (code >= 232) {
225
+ red = ((code - 232) * 10 + 8) / 255;
226
+ green = red;
227
+ blue = red;
228
+ } else {
229
+ code -= 16;
230
+ const remainder = code % 36;
231
+ red = Math.floor(code / 36) / 5;
232
+ green = Math.floor(remainder / 6) / 5;
233
+ blue = remainder % 6 / 5;
234
+ }
235
+ const value = Math.max(red, green, blue) * 2;
236
+ if (value === 0) return 30;
237
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
238
+ if (value === 2) result += 60;
239
+ return result;
240
+ };
241
+ const rgbToAnsi = (red, green, blue) => ansi256ToAnsi(rgbToAnsi256(red, green, blue));
242
+ const hexToAnsi = (hex) => ansi256ToAnsi(hexToAnsi256(hex));
243
+ //#endregion
244
+ //#region src/ansi/east-asian-width.ts
245
+ const isInRange = (ranges, codePoint) => {
246
+ let low = 0;
247
+ let high = Math.floor(ranges.length / 2) - 1;
248
+ while (low <= high) {
249
+ const mid = Math.floor((low + high) / 2);
250
+ const i = mid * 2;
251
+ if (codePoint < ranges[i]) high = mid - 1;
252
+ else if (codePoint > ranges[i + 1]) low = mid + 1;
253
+ else return true;
254
+ }
255
+ return false;
256
+ };
257
+ const ambiguousMinimalCodePoint = 161;
258
+ const ambiguousMaximumCodePoint = 1114109;
259
+ const ambiguousRanges = [
260
+ 161,
261
+ 161,
262
+ 164,
263
+ 164,
264
+ 167,
265
+ 168,
266
+ 170,
267
+ 170,
268
+ 173,
269
+ 174,
270
+ 176,
271
+ 180,
272
+ 182,
273
+ 186,
274
+ 188,
275
+ 191,
276
+ 198,
277
+ 198,
278
+ 208,
279
+ 208,
280
+ 215,
281
+ 216,
282
+ 222,
283
+ 225,
284
+ 230,
285
+ 230,
286
+ 232,
287
+ 234,
288
+ 236,
289
+ 237,
290
+ 240,
291
+ 240,
292
+ 242,
293
+ 243,
294
+ 247,
295
+ 250,
296
+ 252,
297
+ 252,
298
+ 254,
299
+ 254,
300
+ 257,
301
+ 257,
302
+ 273,
303
+ 273,
304
+ 275,
305
+ 275,
306
+ 283,
307
+ 283,
308
+ 294,
309
+ 295,
310
+ 299,
311
+ 299,
312
+ 305,
313
+ 307,
314
+ 312,
315
+ 312,
316
+ 319,
317
+ 322,
318
+ 324,
319
+ 324,
320
+ 328,
321
+ 331,
322
+ 333,
323
+ 333,
324
+ 338,
325
+ 339,
326
+ 358,
327
+ 359,
328
+ 363,
329
+ 363,
330
+ 462,
331
+ 462,
332
+ 464,
333
+ 464,
334
+ 466,
335
+ 466,
336
+ 468,
337
+ 468,
338
+ 470,
339
+ 470,
340
+ 472,
341
+ 472,
342
+ 474,
343
+ 474,
344
+ 476,
345
+ 476,
346
+ 593,
347
+ 593,
348
+ 609,
349
+ 609,
350
+ 708,
351
+ 708,
352
+ 711,
353
+ 711,
354
+ 713,
355
+ 715,
356
+ 717,
357
+ 717,
358
+ 720,
359
+ 720,
360
+ 728,
361
+ 731,
362
+ 733,
363
+ 733,
364
+ 735,
365
+ 735,
366
+ 768,
367
+ 879,
368
+ 913,
369
+ 929,
370
+ 931,
371
+ 937,
372
+ 945,
373
+ 961,
374
+ 963,
375
+ 969,
376
+ 1025,
377
+ 1025,
378
+ 1040,
379
+ 1103,
380
+ 1105,
381
+ 1105,
382
+ 8208,
383
+ 8208,
384
+ 8211,
385
+ 8214,
386
+ 8216,
387
+ 8217,
388
+ 8220,
389
+ 8221,
390
+ 8224,
391
+ 8226,
392
+ 8228,
393
+ 8231,
394
+ 8240,
395
+ 8240,
396
+ 8242,
397
+ 8243,
398
+ 8245,
399
+ 8245,
400
+ 8251,
401
+ 8251,
402
+ 8254,
403
+ 8254,
404
+ 8308,
405
+ 8308,
406
+ 8319,
407
+ 8319,
408
+ 8321,
409
+ 8324,
410
+ 8364,
411
+ 8364,
412
+ 8451,
413
+ 8451,
414
+ 8453,
415
+ 8453,
416
+ 8457,
417
+ 8457,
418
+ 8467,
419
+ 8467,
420
+ 8470,
421
+ 8470,
422
+ 8481,
423
+ 8482,
424
+ 8486,
425
+ 8486,
426
+ 8491,
427
+ 8491,
428
+ 8531,
429
+ 8532,
430
+ 8539,
431
+ 8542,
432
+ 8544,
433
+ 8555,
434
+ 8560,
435
+ 8569,
436
+ 8585,
437
+ 8585,
438
+ 8592,
439
+ 8601,
440
+ 8632,
441
+ 8633,
442
+ 8658,
443
+ 8658,
444
+ 8660,
445
+ 8660,
446
+ 8679,
447
+ 8679,
448
+ 8704,
449
+ 8704,
450
+ 8706,
451
+ 8707,
452
+ 8711,
453
+ 8712,
454
+ 8715,
455
+ 8715,
456
+ 8719,
457
+ 8719,
458
+ 8721,
459
+ 8721,
460
+ 8725,
461
+ 8725,
462
+ 8730,
463
+ 8730,
464
+ 8733,
465
+ 8736,
466
+ 8739,
467
+ 8739,
468
+ 8741,
469
+ 8741,
470
+ 8743,
471
+ 8748,
472
+ 8750,
473
+ 8750,
474
+ 8756,
475
+ 8759,
476
+ 8764,
477
+ 8765,
478
+ 8776,
479
+ 8776,
480
+ 8780,
481
+ 8780,
482
+ 8786,
483
+ 8786,
484
+ 8800,
485
+ 8801,
486
+ 8804,
487
+ 8807,
488
+ 8810,
489
+ 8811,
490
+ 8814,
491
+ 8815,
492
+ 8834,
493
+ 8835,
494
+ 8838,
495
+ 8839,
496
+ 8853,
497
+ 8853,
498
+ 8857,
499
+ 8857,
500
+ 8869,
501
+ 8869,
502
+ 8895,
503
+ 8895,
504
+ 8978,
505
+ 8978,
506
+ 9312,
507
+ 9449,
508
+ 9451,
509
+ 9547,
510
+ 9552,
511
+ 9587,
512
+ 9600,
513
+ 9615,
514
+ 9618,
515
+ 9621,
516
+ 9632,
517
+ 9633,
518
+ 9635,
519
+ 9641,
520
+ 9650,
521
+ 9651,
522
+ 9654,
523
+ 9655,
524
+ 9660,
525
+ 9661,
526
+ 9664,
527
+ 9665,
528
+ 9670,
529
+ 9672,
530
+ 9675,
531
+ 9675,
532
+ 9678,
533
+ 9681,
534
+ 9698,
535
+ 9701,
536
+ 9711,
537
+ 9711,
538
+ 9733,
539
+ 9734,
540
+ 9737,
541
+ 9737,
542
+ 9742,
543
+ 9743,
544
+ 9756,
545
+ 9756,
546
+ 9758,
547
+ 9758,
548
+ 9792,
549
+ 9792,
550
+ 9794,
551
+ 9794,
552
+ 9824,
553
+ 9825,
554
+ 9827,
555
+ 9829,
556
+ 9831,
557
+ 9834,
558
+ 9836,
559
+ 9837,
560
+ 9839,
561
+ 9839,
562
+ 9886,
563
+ 9887,
564
+ 9919,
565
+ 9919,
566
+ 9926,
567
+ 9933,
568
+ 9935,
569
+ 9939,
570
+ 9941,
571
+ 9953,
572
+ 9955,
573
+ 9955,
574
+ 9960,
575
+ 9961,
576
+ 9963,
577
+ 9969,
578
+ 9972,
579
+ 9972,
580
+ 9974,
581
+ 9977,
582
+ 9979,
583
+ 9980,
584
+ 9982,
585
+ 9983,
586
+ 10045,
587
+ 10045,
588
+ 10102,
589
+ 10111,
590
+ 11094,
591
+ 11097,
592
+ 12872,
593
+ 12879,
594
+ 57344,
595
+ 63743,
596
+ 65024,
597
+ 65039,
598
+ 65533,
599
+ 65533,
600
+ 127232,
601
+ 127242,
602
+ 127248,
603
+ 127277,
604
+ 127280,
605
+ 127337,
606
+ 127344,
607
+ 127373,
608
+ 127375,
609
+ 127376,
610
+ 127387,
611
+ 127404,
612
+ 917760,
613
+ 917999,
614
+ 983040,
615
+ 1048573,
616
+ 1048576,
617
+ 1114109
618
+ ];
619
+ const fullwidthMinimalCodePoint = 12288;
620
+ const fullwidthMaximumCodePoint = 65510;
621
+ const fullwidthRanges = [
622
+ 12288,
623
+ 12288,
624
+ 65281,
625
+ 65376,
626
+ 65504,
627
+ 65510
628
+ ];
629
+ const halfwidthMinimalCodePoint = 8361;
630
+ const halfwidthMaximumCodePoint = 65518;
631
+ const halfwidthRanges = [
632
+ 8361,
633
+ 8361,
634
+ 65377,
635
+ 65470,
636
+ 65474,
637
+ 65479,
638
+ 65482,
639
+ 65487,
640
+ 65490,
641
+ 65495,
642
+ 65498,
643
+ 65500,
644
+ 65512,
645
+ 65518
646
+ ];
647
+ const narrowMinimalCodePoint = 32;
648
+ const narrowMaximumCodePoint = 10630;
649
+ const narrowRanges = [
650
+ 32,
651
+ 126,
652
+ 162,
653
+ 163,
654
+ 165,
655
+ 166,
656
+ 172,
657
+ 172,
658
+ 175,
659
+ 175,
660
+ 10214,
661
+ 10221,
662
+ 10629,
663
+ 10630
664
+ ];
665
+ const wideMinimalCodePoint = 4352;
666
+ const wideMaximumCodePoint = 262141;
667
+ const wideRanges = [
668
+ 4352,
669
+ 4447,
670
+ 8986,
671
+ 8987,
672
+ 9001,
673
+ 9002,
674
+ 9193,
675
+ 9196,
676
+ 9200,
677
+ 9200,
678
+ 9203,
679
+ 9203,
680
+ 9725,
681
+ 9726,
682
+ 9748,
683
+ 9749,
684
+ 9776,
685
+ 9783,
686
+ 9800,
687
+ 9811,
688
+ 9855,
689
+ 9855,
690
+ 9866,
691
+ 9871,
692
+ 9875,
693
+ 9875,
694
+ 9889,
695
+ 9889,
696
+ 9898,
697
+ 9899,
698
+ 9917,
699
+ 9918,
700
+ 9924,
701
+ 9925,
702
+ 9934,
703
+ 9934,
704
+ 9940,
705
+ 9940,
706
+ 9962,
707
+ 9962,
708
+ 9970,
709
+ 9971,
710
+ 9973,
711
+ 9973,
712
+ 9978,
713
+ 9978,
714
+ 9981,
715
+ 9981,
716
+ 9989,
717
+ 9989,
718
+ 9994,
719
+ 9995,
720
+ 10024,
721
+ 10024,
722
+ 10060,
723
+ 10060,
724
+ 10062,
725
+ 10062,
726
+ 10067,
727
+ 10069,
728
+ 10071,
729
+ 10071,
730
+ 10133,
731
+ 10135,
732
+ 10160,
733
+ 10160,
734
+ 10175,
735
+ 10175,
736
+ 11035,
737
+ 11036,
738
+ 11088,
739
+ 11088,
740
+ 11093,
741
+ 11093,
742
+ 11904,
743
+ 11929,
744
+ 11931,
745
+ 12019,
746
+ 12032,
747
+ 12245,
748
+ 12272,
749
+ 12287,
750
+ 12289,
751
+ 12350,
752
+ 12353,
753
+ 12438,
754
+ 12441,
755
+ 12543,
756
+ 12549,
757
+ 12591,
758
+ 12593,
759
+ 12686,
760
+ 12688,
761
+ 12773,
762
+ 12783,
763
+ 12830,
764
+ 12832,
765
+ 12871,
766
+ 12880,
767
+ 42124,
768
+ 42128,
769
+ 42182,
770
+ 43360,
771
+ 43388,
772
+ 44032,
773
+ 55203,
774
+ 63744,
775
+ 64255,
776
+ 65040,
777
+ 65049,
778
+ 65072,
779
+ 65106,
780
+ 65108,
781
+ 65126,
782
+ 65128,
783
+ 65131,
784
+ 94176,
785
+ 94180,
786
+ 94192,
787
+ 94198,
788
+ 94208,
789
+ 101589,
790
+ 101631,
791
+ 101662,
792
+ 101760,
793
+ 101874,
794
+ 110576,
795
+ 110579,
796
+ 110581,
797
+ 110587,
798
+ 110589,
799
+ 110590,
800
+ 110592,
801
+ 110882,
802
+ 110898,
803
+ 110898,
804
+ 110928,
805
+ 110930,
806
+ 110933,
807
+ 110933,
808
+ 110948,
809
+ 110951,
810
+ 110960,
811
+ 111355,
812
+ 119552,
813
+ 119638,
814
+ 119648,
815
+ 119670,
816
+ 126980,
817
+ 126980,
818
+ 127183,
819
+ 127183,
820
+ 127374,
821
+ 127374,
822
+ 127377,
823
+ 127386,
824
+ 127488,
825
+ 127490,
826
+ 127504,
827
+ 127547,
828
+ 127552,
829
+ 127560,
830
+ 127568,
831
+ 127569,
832
+ 127584,
833
+ 127589,
834
+ 127744,
835
+ 127776,
836
+ 127789,
837
+ 127797,
838
+ 127799,
839
+ 127868,
840
+ 127870,
841
+ 127891,
842
+ 127904,
843
+ 127946,
844
+ 127951,
845
+ 127955,
846
+ 127968,
847
+ 127984,
848
+ 127988,
849
+ 127988,
850
+ 127992,
851
+ 128062,
852
+ 128064,
853
+ 128064,
854
+ 128066,
855
+ 128252,
856
+ 128255,
857
+ 128317,
858
+ 128331,
859
+ 128334,
860
+ 128336,
861
+ 128359,
862
+ 128378,
863
+ 128378,
864
+ 128405,
865
+ 128406,
866
+ 128420,
867
+ 128420,
868
+ 128507,
869
+ 128591,
870
+ 128640,
871
+ 128709,
872
+ 128716,
873
+ 128716,
874
+ 128720,
875
+ 128722,
876
+ 128725,
877
+ 128728,
878
+ 128732,
879
+ 128735,
880
+ 128747,
881
+ 128748,
882
+ 128756,
883
+ 128764,
884
+ 128992,
885
+ 129003,
886
+ 129008,
887
+ 129008,
888
+ 129292,
889
+ 129338,
890
+ 129340,
891
+ 129349,
892
+ 129351,
893
+ 129535,
894
+ 129648,
895
+ 129660,
896
+ 129664,
897
+ 129674,
898
+ 129678,
899
+ 129734,
900
+ 129736,
901
+ 129736,
902
+ 129741,
903
+ 129756,
904
+ 129759,
905
+ 129770,
906
+ 129775,
907
+ 129784,
908
+ 131072,
909
+ 196605,
910
+ 196608,
911
+ 262141
912
+ ];
913
+ const commonCjkCodePoint = 19968;
914
+ const [wideFastPathStart, wideFastPathEnd] = /* #__PURE__ */ findWideFastPathRange(wideRanges);
915
+ function findWideFastPathRange(ranges) {
916
+ let fastPathStart = ranges[0];
917
+ let fastPathEnd = ranges[1];
918
+ for (let index = 0; index < ranges.length; index += 2) {
919
+ const start = ranges[index];
920
+ const end = ranges[index + 1];
921
+ if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) return [start, end];
922
+ if (end - start > fastPathEnd - fastPathStart) {
923
+ fastPathStart = start;
924
+ fastPathEnd = end;
925
+ }
926
+ }
927
+ return [fastPathStart, fastPathEnd];
928
+ }
929
+ const isAmbiguous = (codePoint) => {
930
+ if (codePoint < 161 || codePoint > 1114109) return false;
931
+ return isInRange(ambiguousRanges, codePoint);
932
+ };
933
+ const isFullWidth = (codePoint) => {
934
+ if (codePoint < 12288 || codePoint > 65510) return false;
935
+ return isInRange(fullwidthRanges, codePoint);
936
+ };
937
+ const isHalfWidth = (codePoint) => {
938
+ if (codePoint < 8361 || codePoint > 65518) return false;
939
+ return isInRange(halfwidthRanges, codePoint);
940
+ };
941
+ const isNarrow = (codePoint) => {
942
+ if (codePoint < 32 || codePoint > 10630) return false;
943
+ return isInRange(narrowRanges, codePoint);
944
+ };
945
+ const isWide = (codePoint) => {
946
+ if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) return true;
947
+ if (codePoint < 4352 || codePoint > 262141) return false;
948
+ return isInRange(wideRanges, codePoint);
949
+ };
950
+ function getCategory(codePoint) {
951
+ if (isAmbiguous(codePoint)) return "ambiguous";
952
+ if (isFullWidth(codePoint)) return "fullwidth";
953
+ if (isHalfWidth(codePoint)) return "halfwidth";
954
+ if (isNarrow(codePoint)) return "narrow";
955
+ if (isWide(codePoint)) return "wide";
956
+ return "neutral";
957
+ }
958
+ function eastAsianWidthType(codePoint) {
959
+ return getCategory(codePoint);
960
+ }
961
+ function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
962
+ if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
963
+ return 1;
964
+ }
965
+ function isFullwidthCodePoint(codePoint) {
966
+ if (!Number.isInteger(codePoint)) return false;
967
+ return isFullWidth(codePoint) || isWide(codePoint);
968
+ }
969
+ //#endregion
970
+ //#region src/ansi/strip.ts
971
+ function ansiRegex({ onlyFirst = false } = {}) {
972
+ return new RegExp(`(?:\\][^œ]*(?:|\\\\|œ))|[›][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]`, onlyFirst ? void 0 : "g");
973
+ }
974
+ const regex = ansiRegex();
975
+ function stripAnsi(string) {
976
+ if (!string.includes("\x1B") && !string.includes("›")) return string;
977
+ return string.replace(regex, "");
978
+ }
979
+ //#endregion
980
+ //#region src/ansi/string-width.ts
981
+ const segmenter$2 = new Intl.Segmenter();
982
+ const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Nonspacing_Mark}|\p{Enclosing_Mark}|\p{Surrogate})+$/v;
983
+ const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]+/v;
984
+ const spacingMarkRegex = /\p{Spacing_Mark}/v;
985
+ const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
986
+ const unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
987
+ const extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
988
+ function isDoubleWidthNonRgiEmojiSequence(segment) {
989
+ if (segment.length > 50) return false;
990
+ if (unqualifiedKeycapRegex.test(segment)) return true;
991
+ if (segment.includes("‍")) {
992
+ const pictographics = segment.match(extendedPictographicRegex);
993
+ return pictographics !== null && pictographics.length >= 2;
994
+ }
995
+ return false;
996
+ }
997
+ function baseVisible(segment) {
998
+ return segment.replace(leadingNonPrintingRegex, "");
999
+ }
1000
+ function isZeroWidthCluster(segment) {
1001
+ return zeroWidthClusterRegex.test(segment);
1002
+ }
1003
+ function isHangulLeadingJamo(codePoint) {
1004
+ return codePoint !== void 0 && (codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388);
1005
+ }
1006
+ function isHangulVowelJamo(codePoint) {
1007
+ return codePoint !== void 0 && (codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238);
1008
+ }
1009
+ function isHangulTrailingJamo(codePoint) {
1010
+ return codePoint !== void 0 && (codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291);
1011
+ }
1012
+ function isHangulJamo(codePoint) {
1013
+ return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
1014
+ }
1015
+ function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
1016
+ const codePoints = [];
1017
+ for (const character of visibleSegment) {
1018
+ if (zeroWidthClusterRegex.test(character)) continue;
1019
+ codePoints.push(character.codePointAt(0));
1020
+ }
1021
+ if (codePoints.length === 0) return;
1022
+ let width = 0;
1023
+ for (let index = 0; index < codePoints.length; index++) {
1024
+ const codePoint = codePoints[index];
1025
+ if (!isHangulJamo(codePoint)) {
1026
+ if (width === 0) return;
1027
+ for (let remaining = index; remaining < codePoints.length; remaining++) width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
1028
+ return width;
1029
+ }
1030
+ if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index + 1])) {
1031
+ width += 2;
1032
+ index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
1033
+ continue;
1034
+ }
1035
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
1036
+ }
1037
+ return width;
1038
+ }
1039
+ function trailingWidth(visibleSegment, eastAsianWidthOptions) {
1040
+ let extra = 0;
1041
+ let first = true;
1042
+ for (const character of visibleSegment) {
1043
+ if (first) {
1044
+ first = false;
1045
+ continue;
1046
+ }
1047
+ if (spacingMarkRegex.test(character) || character >= "＀" && character <= "￯") extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
1048
+ }
1049
+ return extra;
1050
+ }
1051
+ function stringWidth(input, options = {}) {
1052
+ if (typeof input !== "string" || input.length === 0) return 0;
1053
+ const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
1054
+ let string = input;
1055
+ if (!countAnsiEscapeCodes && (string.includes("\x1B") || string.includes("›"))) string = stripAnsi(string);
1056
+ if (string.length === 0) return 0;
1057
+ if (/^[ -~]*$/.test(string)) return string.length;
1058
+ let width = 0;
1059
+ const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
1060
+ for (const { segment } of segmenter$2.segment(string)) {
1061
+ if (isZeroWidthCluster(segment)) continue;
1062
+ if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
1063
+ width += 2;
1064
+ continue;
1065
+ }
1066
+ const visibleSegment = baseVisible(segment);
1067
+ const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
1068
+ if (hangulWidth !== void 0) {
1069
+ width += hangulWidth;
1070
+ continue;
1071
+ }
1072
+ const codePoint = visibleSegment.codePointAt(0);
1073
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
1074
+ width += trailingWidth(visibleSegment, eastAsianWidthOptions);
1075
+ }
1076
+ return width;
1077
+ }
1078
+ //#endregion
1079
+ //#region src/ansi/wrap.ts
1080
+ const ANSI_ESCAPE = "\x1B";
1081
+ const ANSI_ESCAPE_BELL = "\x07";
1082
+ const ANSI_CSI = "[";
1083
+ const ANSI_OSC = "]";
1084
+ const ANSI_SGR_TERMINATOR = "m";
1085
+ const ANSI_SGR_RESET = 0;
1086
+ const ANSI_SGR_RESET_FOREGROUND = 39;
1087
+ const ANSI_SGR_RESET_BACKGROUND = 49;
1088
+ const ANSI_SGR_RESET_UNDERLINE_COLOR = 59;
1089
+ const ANSI_SGR_FOREGROUND_EXTENDED = 38;
1090
+ const ANSI_SGR_BACKGROUND_EXTENDED = 48;
1091
+ const ANSI_SGR_UNDERLINE_COLOR_EXTENDED = 58;
1092
+ const ANSI_SGR_COLOR_MODE_RGB = 2;
1093
+ const ANSI_SGR_COLOR_MODE_256 = 5;
1094
+ const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;`;
1095
+ const ESCAPES$1 = /* @__PURE__ */ new Set([ANSI_ESCAPE, "›"]);
1096
+ const ESCAPE_CHARACTERS = [...ESCAPES$1].join("");
1097
+ const CSI_INTRODUCER = `(?:${ANSI_ESCAPE}\\${ANSI_CSI}|›)`;
1098
+ const CSI_PARAMETERS = "[0-?]*[ -/]*[@-~]";
1099
+ const SGR_PARAMETERS = `(?<sgr>[0-9;:]*)${ANSI_SGR_TERMINATOR}`;
1100
+ const OSC_STRING_TERMINATOR = `(?:${ANSI_ESCAPE_BELL}|${ANSI_ESCAPE}\\\\)`;
1101
+ const OSC_STRING_PAYLOAD = String.raw`[^\u0000-\u001F\u007F-\u009F]*`;
1102
+ const LINK_PARAMETERS = String.raw`8;(?<parameters>[^;\u0000-\u001F\u007F-\u009F]*);(?<uri>${OSC_STRING_PAYLOAD})${OSC_STRING_TERMINATOR}`;
1103
+ const OSC_STRING = `${OSC_STRING_PAYLOAD}${OSC_STRING_TERMINATOR}`;
1104
+ const ANSI_ESCAPE_REGEX = new RegExp(`${CSI_INTRODUCER}(?:${SGR_PARAMETERS}|${CSI_PARAMETERS})|${ANSI_ESCAPE}\\${ANSI_OSC}(?:${LINK_PARAMETERS}|${OSC_STRING})`, "y");
1105
+ const ANSI_SGR_MODIFIER_CLOSE_CODES = new Set(codes.values());
1106
+ ANSI_SGR_MODIFIER_CLOSE_CODES.delete(ANSI_SGR_RESET);
1107
+ const segmenter$1 = new Intl.Segmenter();
1108
+ const getStringWidth = (string) => stringWidth(string, { countAnsiEscapeCodes: true });
1109
+ const TAB_SIZE = 8;
1110
+ const ESCAPE_INTRODUCER_REGEX = new RegExp(`[${ESCAPE_CHARACTERS}]`, "g");
1111
+ const ROW_BOUNDARY_REGEX = new RegExp(`[\\n${ESCAPE_CHARACTERS}]`, "g");
1112
+ const ASCII_PRINTABLE_REGEX = /^[ -~]*$/;
1113
+ const wrapAnsiCode = (code) => `${ANSI_ESCAPE}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
1114
+ const wrapAnsiHyperlink = (url, parameters = "") => `${ANSI_ESCAPE}${ANSI_ESCAPE_LINK}${parameters};${url}${ANSI_ESCAPE_BELL}`;
1115
+ const matchAnsiEscape = (string, index) => {
1116
+ if (!ESCAPES$1.has(string[index])) return;
1117
+ ANSI_ESCAPE_REGEX.lastIndex = index;
1118
+ return ANSI_ESCAPE_REGEX.exec(string) ?? void 0;
1119
+ };
1120
+ const forEachSegment = (string, onPlainText, onEscape = () => {}) => {
1121
+ let plainStart = 0;
1122
+ let index = 0;
1123
+ while (index < string.length) {
1124
+ ESCAPE_INTRODUCER_REGEX.lastIndex = index;
1125
+ const introducer = ESCAPE_INTRODUCER_REGEX.exec(string);
1126
+ if (!introducer) break;
1127
+ const escape = matchAnsiEscape(string, introducer.index);
1128
+ if (!escape) {
1129
+ index = introducer.index + 1;
1130
+ continue;
1131
+ }
1132
+ if (introducer.index > plainStart) onPlainText(string.slice(plainStart, introducer.index));
1133
+ onEscape(escape[0]);
1134
+ index = introducer.index + escape[0].length;
1135
+ plainStart = index;
1136
+ }
1137
+ if (plainStart < string.length) onPlainText(string.slice(plainStart));
1138
+ };
1139
+ const getWidth = (string) => {
1140
+ let plainText = "";
1141
+ forEachSegment(string, (part) => {
1142
+ plainText += part;
1143
+ });
1144
+ return getStringWidth(plainText);
1145
+ };
1146
+ const getTokens = (string) => {
1147
+ const tokens = [];
1148
+ forEachSegment(string, (plainText) => {
1149
+ if (ASCII_PRINTABLE_REGEX.test(plainText)) {
1150
+ for (const character of plainText) tokens.push({
1151
+ value: character,
1152
+ width: 1
1153
+ });
1154
+ return;
1155
+ }
1156
+ for (const { segment } of segmenter$1.segment(plainText)) tokens.push({
1157
+ value: segment,
1158
+ width: getStringWidth(segment)
1159
+ });
1160
+ }, (escape) => {
1161
+ tokens.push({
1162
+ value: escape,
1163
+ width: 0
1164
+ });
1165
+ });
1166
+ return tokens;
1167
+ };
1168
+ const splitWords = (string) => {
1169
+ let currentWord = {
1170
+ value: "",
1171
+ plainText: "",
1172
+ width: 0
1173
+ };
1174
+ const words = [currentWord];
1175
+ forEachSegment(string, (plainText) => {
1176
+ const parts = plainText.split(" ");
1177
+ currentWord.value += parts[0];
1178
+ currentWord.plainText += parts[0];
1179
+ for (let index = 1; index < parts.length; index++) {
1180
+ currentWord = {
1181
+ value: parts[index],
1182
+ plainText: parts[index],
1183
+ width: 0
1184
+ };
1185
+ words.push(currentWord);
1186
+ }
1187
+ }, (escape) => {
1188
+ currentWord.value += escape;
1189
+ });
1190
+ for (const word of words) word.width = getStringWidth(word.plainText);
1191
+ return words;
1192
+ };
1193
+ const getColonColorToken = (parameter) => {
1194
+ const parts = parameter.split(":");
1195
+ const code = Number.parseInt(parts[0], 10);
1196
+ const mode = Number.parseInt(parts[1], 10);
1197
+ if (![
1198
+ ANSI_SGR_FOREGROUND_EXTENDED,
1199
+ ANSI_SGR_BACKGROUND_EXTENDED,
1200
+ ANSI_SGR_UNDERLINE_COLOR_EXTENDED
1201
+ ].includes(code)) return;
1202
+ if (mode === ANSI_SGR_COLOR_MODE_256 && parts.length === 3 && /^\d+$/.test(parts[2])) return {
1203
+ code,
1204
+ open: parameter,
1205
+ hasArguments: true
1206
+ };
1207
+ if (mode !== ANSI_SGR_COLOR_MODE_RGB) return;
1208
+ const components = parts.length === 6 ? parts.slice(3) : parts.slice(2);
1209
+ const colorSpace = parts.length === 6 ? parts[2] : void 0;
1210
+ if (components.length === 3 && components.every((component) => /^\d+$/.test(component)) && (colorSpace === void 0 || /^\d*$/.test(colorSpace))) return {
1211
+ code,
1212
+ open: parameter,
1213
+ hasArguments: true
1214
+ };
1215
+ };
1216
+ const getSgrTokens = (sgrParameters) => {
1217
+ const parameters = sgrParameters.split(";");
1218
+ const sgrTokens = [];
1219
+ for (let index = 0; index < parameters.length; index++) {
1220
+ const parameter = parameters[index];
1221
+ if (parameter.includes(":")) {
1222
+ const colonColorToken = getColonColorToken(parameter);
1223
+ if (colonColorToken) sgrTokens.push(colonColorToken);
1224
+ continue;
1225
+ }
1226
+ const code = parameter === "" ? ANSI_SGR_RESET : Number.parseInt(parameter, 10);
1227
+ if (!Number.isFinite(code)) continue;
1228
+ if (code === ANSI_SGR_FOREGROUND_EXTENDED || code === ANSI_SGR_BACKGROUND_EXTENDED || code === ANSI_SGR_UNDERLINE_COLOR_EXTENDED) {
1229
+ if (index + 1 >= parameters.length) break;
1230
+ const mode = Number.parseInt(parameters[index + 1], 10);
1231
+ const colorIndex = Number.parseInt(parameters[index + 2] ?? "", 10);
1232
+ if (mode === ANSI_SGR_COLOR_MODE_256 && Number.isFinite(colorIndex)) {
1233
+ sgrTokens.push({
1234
+ code,
1235
+ open: [
1236
+ code,
1237
+ mode,
1238
+ colorIndex
1239
+ ].join(";"),
1240
+ hasArguments: true
1241
+ });
1242
+ index += 2;
1243
+ continue;
1244
+ }
1245
+ const red = Number.parseInt(parameters[index + 2] ?? "", 10);
1246
+ const green = Number.parseInt(parameters[index + 3] ?? "", 10);
1247
+ const blue = Number.parseInt(parameters[index + 4] ?? "", 10);
1248
+ if (mode === ANSI_SGR_COLOR_MODE_RGB && Number.isFinite(red) && Number.isFinite(green) && Number.isFinite(blue)) {
1249
+ sgrTokens.push({
1250
+ code,
1251
+ open: [
1252
+ code,
1253
+ mode,
1254
+ red,
1255
+ green,
1256
+ blue
1257
+ ].join(";"),
1258
+ hasArguments: true
1259
+ });
1260
+ index += 4;
1261
+ continue;
1262
+ }
1263
+ break;
1264
+ }
1265
+ sgrTokens.push({
1266
+ code,
1267
+ open: String(code),
1268
+ hasArguments: false
1269
+ });
1270
+ }
1271
+ return sgrTokens;
1272
+ };
1273
+ const removeActiveStyle = (activeStyles, family) => {
1274
+ const activeStyleIndex = activeStyles.findIndex((activeStyle) => activeStyle.family === family);
1275
+ if (activeStyleIndex !== -1) activeStyles.splice(activeStyleIndex, 1);
1276
+ };
1277
+ const upsertActiveStyle = (activeStyles, nextActiveStyle) => {
1278
+ removeActiveStyle(activeStyles, nextActiveStyle.family);
1279
+ activeStyles.push(nextActiveStyle);
1280
+ };
1281
+ const removeModifierStylesByClose = (activeStyles, closeCode) => {
1282
+ for (let index = activeStyles.length - 1; index >= 0; index--) {
1283
+ const activeStyle = activeStyles[index];
1284
+ if (activeStyle.family.startsWith("modifier-") && activeStyle.close === closeCode) activeStyles.splice(index, 1);
1285
+ }
1286
+ };
1287
+ const getColorStyle = (sgrToken) => {
1288
+ const { code, open, hasArguments } = sgrToken;
1289
+ if (code >= 30 && code <= 37 || code >= 90 && code <= 97 || code === ANSI_SGR_FOREGROUND_EXTENDED && hasArguments) return {
1290
+ family: "foreground",
1291
+ open,
1292
+ close: ANSI_SGR_RESET_FOREGROUND
1293
+ };
1294
+ if (code >= 40 && code <= 47 || code >= 100 && code <= 107 || code === ANSI_SGR_BACKGROUND_EXTENDED && hasArguments) return {
1295
+ family: "background",
1296
+ open,
1297
+ close: ANSI_SGR_RESET_BACKGROUND
1298
+ };
1299
+ if (code === ANSI_SGR_UNDERLINE_COLOR_EXTENDED && hasArguments) return {
1300
+ family: "underlineColor",
1301
+ open,
1302
+ close: ANSI_SGR_RESET_UNDERLINE_COLOR
1303
+ };
1304
+ };
1305
+ const applySgrResetCode = (code, activeStyles) => {
1306
+ if (code === ANSI_SGR_RESET) {
1307
+ activeStyles.length = 0;
1308
+ return true;
1309
+ }
1310
+ if (code === ANSI_SGR_RESET_FOREGROUND) {
1311
+ removeActiveStyle(activeStyles, "foreground");
1312
+ return true;
1313
+ }
1314
+ if (code === ANSI_SGR_RESET_BACKGROUND) {
1315
+ removeActiveStyle(activeStyles, "background");
1316
+ return true;
1317
+ }
1318
+ if (code === ANSI_SGR_RESET_UNDERLINE_COLOR) {
1319
+ removeActiveStyle(activeStyles, "underlineColor");
1320
+ return true;
1321
+ }
1322
+ if (ANSI_SGR_MODIFIER_CLOSE_CODES.has(code)) {
1323
+ removeModifierStylesByClose(activeStyles, code);
1324
+ return true;
1325
+ }
1326
+ return false;
1327
+ };
1328
+ const applySgrToken = (sgrToken, activeStyles) => {
1329
+ const { code } = sgrToken;
1330
+ if (applySgrResetCode(code, activeStyles)) return;
1331
+ const colorStyle = getColorStyle(sgrToken);
1332
+ if (colorStyle) {
1333
+ upsertActiveStyle(activeStyles, colorStyle);
1334
+ return;
1335
+ }
1336
+ const close = codes.get(code);
1337
+ if (close !== void 0 && close !== ANSI_SGR_RESET) upsertActiveStyle(activeStyles, {
1338
+ family: `modifier-${code}`,
1339
+ open: sgrToken.open,
1340
+ close
1341
+ });
1342
+ };
1343
+ const applySgrParameters = (sgrParameters, activeStyles) => {
1344
+ for (const sgrToken of getSgrTokens(sgrParameters)) applySgrToken(sgrToken, activeStyles);
1345
+ };
1346
+ const applySgrResets = (sgrParameters, activeStyles) => {
1347
+ for (const { code } of getSgrTokens(sgrParameters)) applySgrResetCode(code, activeStyles);
1348
+ };
1349
+ const applyLeadingSgrResets = (string, startIndex, activeStyles) => {
1350
+ let index = startIndex;
1351
+ while (index < string.length) {
1352
+ const match = matchAnsiEscape(string, index);
1353
+ if (!match) break;
1354
+ if (match.groups?.["sgr"] !== void 0) applySgrResets(match.groups["sgr"], activeStyles);
1355
+ index += match[0].length;
1356
+ }
1357
+ };
1358
+ const getClosingSgrSequence = (activeStyles) => [...activeStyles].reverse().map((activeStyle) => wrapAnsiCode(activeStyle.close)).join("");
1359
+ const getOpeningSgrSequence = (activeStyles) => activeStyles.map((activeStyle) => wrapAnsiCode(activeStyle.open)).join("");
1360
+ const wrapWord = (rows, word, columns, rowWidth) => {
1361
+ const tokens = getTokens(word);
1362
+ let visible = rowWidth;
1363
+ for (let index = 0; index < tokens.length; index++) {
1364
+ const token = tokens[index];
1365
+ if (token.width > 0 && visible > 0 && visible + token.width > columns) {
1366
+ rows.push("");
1367
+ visible = 0;
1368
+ }
1369
+ rows[rows.length - 1] += token.value;
1370
+ visible += token.width;
1371
+ if (visible === columns && index < tokens.length - 1) {
1372
+ rows.push("");
1373
+ visible = 0;
1374
+ }
1375
+ }
1376
+ if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
1377
+ const lastRow = rows.pop();
1378
+ rows[rows.length - 1] = rows[rows.length - 1] + lastRow;
1379
+ }
1380
+ return getWidth(rows.at(-1));
1381
+ };
1382
+ const stringVisibleTrimSpacesRight = (string) => {
1383
+ if (!string.includes(" ")) return string;
1384
+ const segments = [];
1385
+ forEachSegment(string, (plainText) => {
1386
+ segments.push({
1387
+ value: plainText,
1388
+ isEscape: false
1389
+ });
1390
+ }, (escape) => {
1391
+ segments.push({
1392
+ value: escape,
1393
+ isEscape: true
1394
+ });
1395
+ });
1396
+ for (let index = segments.length - 1; index >= 0; index--) {
1397
+ const segment = segments[index];
1398
+ if (segment.isEscape) continue;
1399
+ let end = segment.value.length;
1400
+ while (end > 0 && segment.value[end - 1] === " ") end--;
1401
+ segment.value = segment.value.slice(0, end);
1402
+ if (getStringWidth(segment.value) > 0) break;
1403
+ }
1404
+ return segments.map((segment) => segment.value).join("");
1405
+ };
1406
+ const expandTabs = (line) => {
1407
+ if (!line.includes(" ")) return line;
1408
+ let visible = 0;
1409
+ let expandedLine = "";
1410
+ let plainTextSinceTab = "";
1411
+ const expandPlainText = (plainText) => {
1412
+ const segments = plainText.split(" ");
1413
+ for (const [index, segment] of segments.entries()) {
1414
+ expandedLine += segment;
1415
+ plainTextSinceTab += segment;
1416
+ if (index < segments.length - 1) {
1417
+ visible += getStringWidth(plainTextSinceTab);
1418
+ plainTextSinceTab = "";
1419
+ const spaces = TAB_SIZE - visible % TAB_SIZE;
1420
+ expandedLine += " ".repeat(spaces);
1421
+ visible += spaces;
1422
+ }
1423
+ }
1424
+ };
1425
+ forEachSegment(line, expandPlainText, (escape) => {
1426
+ expandedLine += escape;
1427
+ });
1428
+ return expandedLine;
1429
+ };
1430
+ const restoreStylesAcrossRows = (preString) => {
1431
+ let returnValue = "";
1432
+ let activeHyperlink;
1433
+ const activeStyles = [];
1434
+ let index = 0;
1435
+ let copiedIndex = 0;
1436
+ while (index < preString.length) {
1437
+ ROW_BOUNDARY_REGEX.lastIndex = index;
1438
+ const boundary = ROW_BOUNDARY_REGEX.exec(preString);
1439
+ if (!boundary) break;
1440
+ index = boundary.index;
1441
+ if (boundary[0] !== "\n") {
1442
+ const escape = matchAnsiEscape(preString, index);
1443
+ if (!escape) {
1444
+ index++;
1445
+ continue;
1446
+ }
1447
+ const groups = escape.groups ?? {};
1448
+ if (groups["sgr"] !== void 0) applySgrParameters(groups["sgr"], activeStyles);
1449
+ else if (groups["uri"] !== void 0) activeHyperlink = groups["uri"].length === 0 ? void 0 : {
1450
+ parameters: groups["parameters"] ?? "",
1451
+ uri: groups["uri"]
1452
+ };
1453
+ index += escape[0].length;
1454
+ continue;
1455
+ }
1456
+ returnValue += preString.slice(copiedIndex, index);
1457
+ if (index > copiedIndex) {
1458
+ if (activeHyperlink) returnValue += wrapAnsiHyperlink("");
1459
+ returnValue += getClosingSgrSequence(activeStyles);
1460
+ }
1461
+ returnValue += "\n";
1462
+ index++;
1463
+ copiedIndex = index;
1464
+ if (index < preString.length && preString[index] !== "\n") {
1465
+ const openingStyles = [...activeStyles];
1466
+ applyLeadingSgrResets(preString, index, openingStyles);
1467
+ returnValue += getOpeningSgrSequence(openingStyles);
1468
+ if (activeHyperlink) returnValue += wrapAnsiHyperlink(activeHyperlink.uri, activeHyperlink.parameters);
1469
+ }
1470
+ }
1471
+ return returnValue + preString.slice(copiedIndex);
1472
+ };
1473
+ const exec = (string, columns, options = {}) => {
1474
+ if (options.trim !== false && string.trim() === "") return "";
1475
+ const words = splitWords(string);
1476
+ let rows = [""];
1477
+ let rowLength = 0;
1478
+ let trimmedRowIndex = -1;
1479
+ let isFirstWord = true;
1480
+ for (const word of words) {
1481
+ const rowIndex = rows.length - 1;
1482
+ if (options.trim !== false && trimmedRowIndex !== rowIndex) {
1483
+ const row = rows[rowIndex];
1484
+ const trimmedRow = row.trimStart();
1485
+ if (trimmedRow.length !== row.length) {
1486
+ rows[rowIndex] = trimmedRow;
1487
+ rowLength = getWidth(trimmedRow);
1488
+ }
1489
+ if (trimmedRow.length > 0) trimmedRowIndex = rowIndex;
1490
+ }
1491
+ if (isFirstWord) isFirstWord = false;
1492
+ else {
1493
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
1494
+ rows.push("");
1495
+ rowLength = 0;
1496
+ }
1497
+ if (rowLength > 0 || options.trim === false) {
1498
+ rows[rows.length - 1] += " ";
1499
+ rowLength++;
1500
+ }
1501
+ }
1502
+ if (options.hard && options.wordWrap !== false && word.width > columns) {
1503
+ const remainingColumns = columns - rowLength;
1504
+ const breaksStartingThisLine = 1 + Math.floor((word.width - remainingColumns - 1) / columns);
1505
+ if (Math.floor((word.width - 1) / columns) < breaksStartingThisLine) {
1506
+ rows.push("");
1507
+ rowLength = 0;
1508
+ }
1509
+ rowLength = wrapWord(rows, word.value, columns, rowLength);
1510
+ continue;
1511
+ }
1512
+ if (rowLength + word.width > columns && rowLength > 0 && word.width > 0) {
1513
+ if (options.wordWrap === false && rowLength < columns) {
1514
+ rowLength = wrapWord(rows, word.value, columns, rowLength);
1515
+ continue;
1516
+ }
1517
+ rows.push("");
1518
+ rowLength = 0;
1519
+ }
1520
+ if (rowLength + word.width > columns && options.wordWrap === false) {
1521
+ rowLength = wrapWord(rows, word.value, columns, rowLength);
1522
+ continue;
1523
+ }
1524
+ rows[rows.length - 1] += word.value;
1525
+ rowLength += word.width;
1526
+ }
1527
+ if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
1528
+ return restoreStylesAcrossRows(rows.join("\n"));
1529
+ };
1530
+ function wrapAnsi(string, columns, options) {
1531
+ return string.normalize().replaceAll("\r\n", "\n").split("\n").map((line) => exec(expandTabs(line), columns, options)).join("\n");
1532
+ }
1533
+ //#endregion
1534
+ //#region src/signal-exit.ts
1535
+ const signals = process.platform === "win32" ? [
1536
+ "SIGHUP",
1537
+ "SIGINT",
1538
+ "SIGTERM",
1539
+ "SIGBREAK"
1540
+ ] : [
1541
+ "SIGHUP",
1542
+ "SIGINT",
1543
+ "SIGTERM",
1544
+ "SIGQUIT",
1545
+ "SIGUSR2"
1546
+ ];
1547
+ const registrations = /* @__PURE__ */ new Set();
1548
+ const signalListeners = /* @__PURE__ */ new Map();
1549
+ let loaded = false;
1550
+ let emitted = false;
1551
+ const emitExit = (code, signal) => {
1552
+ if (emitted) return;
1553
+ emitted = true;
1554
+ const ordered = [...registrations].toSorted((a, b) => Number(a.alwaysLast) - Number(b.alwaysLast));
1555
+ for (const registration of ordered) registration.handler(code, signal);
1556
+ };
1557
+ const onExitEvent = (code) => {
1558
+ emitExit(code, null);
1559
+ };
1560
+ const unload = () => {
1561
+ if (!loaded) return;
1562
+ loaded = false;
1563
+ process.off("exit", onExitEvent);
1564
+ for (const [signal, listener] of signalListeners) process.off(signal, listener);
1565
+ signalListeners.clear();
1566
+ };
1567
+ const load = () => {
1568
+ if (loaded) return;
1569
+ loaded = true;
1570
+ process.on("exit", onExitEvent);
1571
+ for (const signal of signals) {
1572
+ const listener = () => {
1573
+ if (process.listenerCount(signal) === 1) {
1574
+ unload();
1575
+ emitExit(null, signal);
1576
+ process.kill(process.pid, signal);
1577
+ }
1578
+ };
1579
+ try {
1580
+ process.on(signal, listener);
1581
+ signalListeners.set(signal, listener);
1582
+ } catch {}
1583
+ }
1584
+ };
1585
+ const signalExit = (handler, options = {}) => {
1586
+ const registration = {
1587
+ handler,
1588
+ alwaysLast: options.alwaysLast ?? false
1589
+ };
1590
+ registrations.add(registration);
1591
+ load();
1592
+ return () => {
1593
+ registrations.delete(registration);
1594
+ if (registrations.size === 0) unload();
1595
+ };
1596
+ };
1597
+ //#endregion
1598
+ //#region src/ansi/cursor.ts
1599
+ let restoreRegistered = false;
1600
+ const registerRestore = () => {
1601
+ if (restoreRegistered) return;
1602
+ restoreRegistered = true;
1603
+ signalExit(() => {
1604
+ process.stderr.write(cursorShow);
1605
+ }, { alwaysLast: true });
1606
+ };
1607
+ const cliCursor = {
1608
+ show(writableStream = process.stderr) {
1609
+ if (!writableStream.isTTY) return;
1610
+ writableStream.write(cursorShow);
1611
+ },
1612
+ hide(writableStream = process.stderr) {
1613
+ if (!writableStream.isTTY) return;
1614
+ registerRestore();
1615
+ writableStream.write(cursorHide);
1616
+ }
1617
+ };
1618
+ //#endregion
1619
+ //#region src/ansi/supports-color.ts
1620
+ function hasFlag(flag, argv = process.argv) {
1621
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
1622
+ const position = argv.indexOf(prefix + flag);
1623
+ const terminatorPosition = argv.indexOf("--");
1624
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
1625
+ }
1626
+ const { env } = process;
1627
+ let flagForceColor;
1628
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) flagForceColor = 0;
1629
+ else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) flagForceColor = 1;
1630
+ function envForceColor() {
1631
+ if (!("FORCE_COLOR" in env)) return;
1632
+ if (env["FORCE_COLOR"] === "true") return 1;
1633
+ if (env["FORCE_COLOR"] === "false") return 0;
1634
+ return env["FORCE_COLOR"].length === 0 ? 1 : Math.min(Number.parseInt(env["FORCE_COLOR"], 10), 3);
1635
+ }
1636
+ function translateLevel(level) {
1637
+ if (level === 0) return false;
1638
+ return {
1639
+ level,
1640
+ hasBasic: true,
1641
+ has256: level >= 2,
1642
+ has16m: level >= 3
1643
+ };
1644
+ }
1645
+ function supportsColorLevel(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
1646
+ const noFlagForceColor = envForceColor();
1647
+ if (noFlagForceColor !== void 0) flagForceColor = noFlagForceColor;
1648
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
1649
+ if (forceColor === 0) return 0;
1650
+ if (sniffFlags) {
1651
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3;
1652
+ if (hasFlag("color=256")) return 2;
1653
+ }
1654
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) return 1;
1655
+ if (haveStream && !streamIsTTY && forceColor === void 0) return 0;
1656
+ const min = forceColor ?? 0;
1657
+ if (env["TERM"] === "dumb") return min;
1658
+ if (process.platform === "win32") {
1659
+ const osRelease = os.release().split(".");
1660
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
1661
+ return 1;
1662
+ }
1663
+ if ("CI" in env) {
1664
+ if ([
1665
+ "GITHUB_ACTIONS",
1666
+ "GITEA_ACTIONS",
1667
+ "CIRCLECI"
1668
+ ].some((key) => key in env)) return 3;
1669
+ if ([
1670
+ "TRAVIS",
1671
+ "APPVEYOR",
1672
+ "GITLAB_CI",
1673
+ "BUILDKITE",
1674
+ "DRONE"
1675
+ ].some((sign) => sign in env) || env["CI_NAME"] === "codeship") return 1;
1676
+ return min;
1677
+ }
1678
+ if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env["TEAMCITY_VERSION"]) ? 1 : 0;
1679
+ if (env["COLORTERM"] === "truecolor") return 3;
1680
+ if (env["TERM"] === "xterm-kitty") return 3;
1681
+ if (env["TERM"] === "xterm-ghostty") return 3;
1682
+ if (env["TERM"] === "wezterm") return 3;
1683
+ if ("TERM_PROGRAM" in env) {
1684
+ const version = Number.parseInt((env["TERM_PROGRAM_VERSION"] ?? "").split(".")[0], 10);
1685
+ switch (env["TERM_PROGRAM"]) {
1686
+ case "iTerm.app": return version >= 3 ? 3 : 2;
1687
+ case "Apple_Terminal": return 2;
1688
+ }
1689
+ }
1690
+ if (/-256(color)?$/i.test(env["TERM"] ?? "")) return 2;
1691
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env["TERM"] ?? "")) return 1;
1692
+ if ("COLORTERM" in env) return 1;
1693
+ return min;
1694
+ }
1695
+ function createSupportsColor(stream, options = {}) {
1696
+ return translateLevel(supportsColorLevel(Boolean(stream), {
1697
+ streamIsTTY: Boolean(stream?.isTTY),
1698
+ ...options
1699
+ }));
1700
+ }
1701
+ const supportsColor = {
1702
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
1703
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
1704
+ };
1705
+ //#endregion
1706
+ //#region src/ansi/chalk.ts
1707
+ const { stdout: stdoutColor } = supportsColor;
1708
+ const levelMapping = [
1709
+ "ansi",
1710
+ "ansi",
1711
+ "ansi256",
1712
+ "ansi16m"
1713
+ ];
1714
+ const state = { level: stdoutColor ? stdoutColor.level : 0 };
1715
+ const stringReplaceAll = (string, substring, replacer) => {
1716
+ let index = string.indexOf(substring);
1717
+ if (index === -1) return string;
1718
+ const substringLength = substring.length;
1719
+ let endIndex = 0;
1720
+ let returnValue = "";
1721
+ do {
1722
+ returnValue += string.slice(endIndex, index) + substring + replacer;
1723
+ endIndex = index + substringLength;
1724
+ index = string.indexOf(substring, endIndex);
1725
+ } while (index !== -1);
1726
+ returnValue += string.slice(endIndex);
1727
+ return returnValue;
1728
+ };
1729
+ const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
1730
+ let endIndex = 0;
1731
+ let returnValue = "";
1732
+ do {
1733
+ const gotCR = string[index - 1] === "\r";
1734
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
1735
+ endIndex = index + 1;
1736
+ index = string.indexOf("\n", endIndex);
1737
+ } while (index !== -1);
1738
+ returnValue += string.slice(endIndex);
1739
+ return returnValue;
1740
+ };
1741
+ const applyStyle = (open, close, text) => {
1742
+ if (state.level <= 0 || !text) return text;
1743
+ let string = text;
1744
+ if (string.includes("\x1B")) string = stringReplaceAll(string, close, open);
1745
+ const lfIndex = string.indexOf("\n");
1746
+ if (lfIndex !== -1) string = stringEncaseCRLFWithFirstIndex(string, close, open, lfIndex);
1747
+ return open + string + close;
1748
+ };
1749
+ const styleFunction = (open, close) => {
1750
+ return (text) => applyStyle(open, close, text);
1751
+ };
1752
+ const foregroundOpen = (model, args) => {
1753
+ return colorOpen(model, args, foreground, rgbToAnsi256, rgbToAnsi);
1754
+ };
1755
+ const backgroundOpen = (model, args) => {
1756
+ return colorOpen(model, args, background, rgbToAnsi256, rgbToAnsi);
1757
+ };
1758
+ const colorOpen = (model, args, space, toAnsi256, toAnsi) => {
1759
+ const rgb = typeof args[0] === "string" ? hexToRgb(args[0]) : args;
1760
+ if (model === "ansi16m") return space.ansi16m(...rgb);
1761
+ if (model === "ansi256") return space.ansi256(toAnsi256(...rgb));
1762
+ return space.ansi(toAnsi(...rgb));
1763
+ };
1764
+ const named = {};
1765
+ for (const name of [
1766
+ ...modifierNames,
1767
+ ...foregroundColorNames,
1768
+ ...backgroundColorNames
1769
+ ]) named[name] = styleFunction(styles[name].open, styles[name].close);
1770
+ const chalk = {
1771
+ ...named,
1772
+ get level() {
1773
+ return state.level;
1774
+ },
1775
+ set level(level) {
1776
+ state.level = level;
1777
+ },
1778
+ hex: (color) => styleFunction(foregroundOpen(levelMapping[state.level], [color]), foreground.close),
1779
+ bgHex: (color) => styleFunction(backgroundOpen(levelMapping[state.level], [color]), background.close),
1780
+ rgb: (red, green, blue) => styleFunction(foregroundOpen(levelMapping[state.level], [
1781
+ red,
1782
+ green,
1783
+ blue
1784
+ ]), foreground.close),
1785
+ bgRgb: (red, green, blue) => styleFunction(backgroundOpen(levelMapping[state.level], [
1786
+ red,
1787
+ green,
1788
+ blue
1789
+ ]), background.close),
1790
+ ansi256: (code) => styleFunction(foreground.ansi256(code), foreground.close),
1791
+ bgAnsi256: (code) => styleFunction(background.ansi256(code), background.close)
1792
+ };
1793
+ //#endregion
1794
+ //#region src/ansi/widest-line.ts
1795
+ const widestLine = (string) => {
1796
+ let lineWidth = 0;
1797
+ for (const line of string.split("\n")) lineWidth = Math.max(lineWidth, stringWidth(line));
1798
+ return lineWidth;
1799
+ };
1800
+ //#endregion
1801
+ //#region src/ansi/tokenize.ts
1802
+ const BACKSLASH = "\\";
1803
+ const CSI = "[";
1804
+ const OSC = "]";
1805
+ const CC_BEL = "\x07".charCodeAt(0);
1806
+ const CC_ESC = "\x1B".charCodeAt(0);
1807
+ const CC_BACKSLASH = BACKSLASH.charCodeAt(0);
1808
+ const CC_CSI = CSI.charCodeAt(0);
1809
+ const CC_OSC = OSC.charCodeAt(0);
1810
+ const CC_C1_ST = "œ".charCodeAt(0);
1811
+ const CC_0 = "0".charCodeAt(0);
1812
+ const CC_9 = "9".charCodeAt(0);
1813
+ const CC_SEMI = ";".charCodeAt(0);
1814
+ const CC_M = "m".charCodeAt(0);
1815
+ const ESCAPES = /* @__PURE__ */ new Set([CC_ESC, 155]);
1816
+ const linkCodePrefix = `${OSC}8;`;
1817
+ const linkCodePrefixCharCodes = linkCodePrefix.split("").map((char) => char.charCodeAt(0));
1818
+ const linkCodeSuffix = "\x07";
1819
+ const linkEndCode = `${OSC}8;;`;
1820
+ const linkEndCodeST = `${OSC}8;;${BACKSLASH}`;
1821
+ const linkEndCodeC1ST = `${OSC}8;;œ`;
1822
+ const endCodesSet = /* @__PURE__ */ new Set();
1823
+ const endCodesMap = /* @__PURE__ */ new Map();
1824
+ for (const [start, end] of codes) {
1825
+ endCodesSet.add(foreground.ansi(end));
1826
+ endCodesMap.set(foreground.ansi(start), foreground.ansi(end));
1827
+ }
1828
+ function getLinkStartCode(url, params) {
1829
+ const paramsString = params ? Object.entries(params).map(([key, value]) => `${key}=${value}`).join(":") : "";
1830
+ return `${linkCodePrefix}${paramsString};${url}${linkCodeSuffix}`;
1831
+ }
1832
+ function getEndCode(code) {
1833
+ if (endCodesSet.has(code)) return code;
1834
+ if (endCodesMap.has(code)) return endCodesMap.get(code);
1835
+ if (code.startsWith(linkCodePrefix)) {
1836
+ if (code.endsWith(`${BACKSLASH}`)) return linkEndCodeST;
1837
+ if (code.endsWith("œ")) return linkEndCodeC1ST;
1838
+ return linkEndCode;
1839
+ }
1840
+ code = code.slice(2);
1841
+ if (code.startsWith("38")) return foreground.close;
1842
+ if (code.startsWith("48")) return background.close;
1843
+ const endCode = codes.get(Number.parseInt(code, 10));
1844
+ if (endCode !== void 0) return foreground.ansi(endCode);
1845
+ return styles.reset.open;
1846
+ }
1847
+ function ansiCodesToString(codes) {
1848
+ return [...new Set(codes.map((code) => code.code))].join("");
1849
+ }
1850
+ /**
1851
+ Check if a code is an intensity code (bold or dim) — these share the end code
1852
+ `22m` but can coexist.
1853
+ */
1854
+ function isIntensityCode(code) {
1855
+ return code.code === styles.bold.open || code.code === styles.dim.open;
1856
+ }
1857
+ const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
1858
+ function isFullwidthGrapheme(grapheme, baseCodePoint) {
1859
+ if (isFullwidthCodePoint(baseCodePoint)) return true;
1860
+ if (grapheme.includes("️")) return true;
1861
+ if (baseCodePoint >= 127462 && baseCodePoint <= 127487) return true;
1862
+ return false;
1863
+ }
1864
+ function parseLinkCode(string, offset) {
1865
+ string = string.slice(offset);
1866
+ for (let index = 1; index < linkCodePrefixCharCodes.length; index++) if (string.charCodeAt(index) !== linkCodePrefixCharCodes[index]) return;
1867
+ const paramsEndIndex = string.indexOf(";", linkCodePrefix.length);
1868
+ if (paramsEndIndex === -1) return;
1869
+ const endIndex = findOscTerminatorIndex(string, paramsEndIndex + 1);
1870
+ if (endIndex === -1) return;
1871
+ return string.slice(0, endIndex + 1);
1872
+ }
1873
+ function parseOscSequence(string, offset) {
1874
+ string = string.slice(offset);
1875
+ const endIndex = findOscTerminatorIndex(string, 2);
1876
+ if (endIndex === -1) return;
1877
+ return string.slice(0, endIndex + 1);
1878
+ }
1879
+ /**
1880
+ Finds the index of the last character of the first OSC terminator at or after
1881
+ `startIndex`. Recognizes BEL (\u0007), C1 ST (\u009C), and ESC+backslash.
1882
+ Returns -1 if no terminator is found.
1883
+ */
1884
+ function findOscTerminatorIndex(string, startIndex) {
1885
+ for (let index = startIndex; index < string.length; index++) {
1886
+ const charCode = string.charCodeAt(index);
1887
+ if (charCode === CC_BEL) return index;
1888
+ if (charCode === CC_C1_ST) return index;
1889
+ if (charCode === CC_ESC && index + 1 < string.length && string.charCodeAt(index + 1) === CC_BACKSLASH) return index + 1;
1890
+ }
1891
+ return -1;
1892
+ }
1893
+ /**
1894
+ Scans through the given string and finds the index of the last character of an
1895
+ SGR sequence like `\u001B[38;2;123;123;123m`. This assumes that the string has
1896
+ been checked to start with `\u001B[`. Returns -1 if no valid SGR sequence is
1897
+ found.
1898
+ */
1899
+ function findSgrSequenceEndIndex(string) {
1900
+ for (let index = 2; index < string.length; index++) {
1901
+ const charCode = string.charCodeAt(index);
1902
+ if (charCode === CC_M) return index;
1903
+ if (charCode === CC_SEMI) continue;
1904
+ if (charCode >= CC_0 && charCode <= CC_9) continue;
1905
+ break;
1906
+ }
1907
+ return -1;
1908
+ }
1909
+ function parseSgrSequence(string, offset) {
1910
+ string = string.slice(offset);
1911
+ const endIndex = findSgrSequenceEndIndex(string);
1912
+ if (endIndex === -1) return;
1913
+ return string.slice(0, endIndex + 1);
1914
+ }
1915
+ /**
1916
+ Splits compound SGR sequences like `\u001B[1;3;31m` into individual components.
1917
+ */
1918
+ function splitCompoundSgrSequences(code) {
1919
+ if (!code.includes(";")) return [code];
1920
+ const codeParts = code.slice(2, -1).split(";");
1921
+ const result = [];
1922
+ for (let index = 0; index < codeParts.length; index++) {
1923
+ const rawCode = codeParts[index];
1924
+ if (rawCode === "38" || rawCode === "48") {
1925
+ if (index + 2 < codeParts.length && codeParts[index + 1] === "5") {
1926
+ result.push(codeParts.slice(index, index + 3).join(";"));
1927
+ index += 2;
1928
+ continue;
1929
+ } else if (index + 4 < codeParts.length && codeParts[index + 1] === "2") {
1930
+ result.push(codeParts.slice(index, index + 5).join(";"));
1931
+ index += 4;
1932
+ continue;
1933
+ }
1934
+ }
1935
+ result.push(rawCode);
1936
+ }
1937
+ return result.map((part) => `[${part}m`);
1938
+ }
1939
+ function tokenize(string, endChar = Number.POSITIVE_INFINITY) {
1940
+ const result = [];
1941
+ let visible = 0;
1942
+ let codeEndIndex = 0;
1943
+ for (const { segment, index } of segmenter.segment(string)) {
1944
+ if (index < codeEndIndex) continue;
1945
+ const codePoint = segment.codePointAt(0);
1946
+ if (ESCAPES.has(codePoint)) {
1947
+ let code;
1948
+ const nextCodePoint = string.codePointAt(index + 1);
1949
+ if (nextCodePoint === CC_OSC) {
1950
+ code = parseLinkCode(string, index);
1951
+ if (code) result.push({
1952
+ type: "ansi",
1953
+ code,
1954
+ endCode: getEndCode(code)
1955
+ });
1956
+ else {
1957
+ code = parseOscSequence(string, index);
1958
+ if (code) result.push({
1959
+ type: "control",
1960
+ code
1961
+ });
1962
+ }
1963
+ } else if (nextCodePoint === CC_CSI) {
1964
+ code = parseSgrSequence(string, index);
1965
+ if (code) for (const individualCode of splitCompoundSgrSequences(code)) result.push({
1966
+ type: "ansi",
1967
+ code: individualCode,
1968
+ endCode: getEndCode(individualCode)
1969
+ });
1970
+ }
1971
+ if (code) {
1972
+ codeEndIndex = index + code.length;
1973
+ continue;
1974
+ }
1975
+ }
1976
+ const fullWidth = isFullwidthGrapheme(segment, codePoint);
1977
+ result.push({
1978
+ type: "char",
1979
+ value: segment,
1980
+ fullWidth
1981
+ });
1982
+ visible += fullWidth ? 2 : 1;
1983
+ if (visible >= endChar) break;
1984
+ }
1985
+ return result;
1986
+ }
1987
+ /**
1988
+ Reduces the given array of ANSI codes to the minimum necessary to render with
1989
+ the same style.
1990
+ */
1991
+ function reduceAnsiCodes(codes) {
1992
+ return reduceAnsiCodesIncremental([], codes);
1993
+ }
1994
+ /**
1995
+ Like {@link reduceAnsiCodes}, but assumes that `codes` is already reduced.
1996
+ Further reductions are only done for the items in `newCodes`.
1997
+ */
1998
+ function reduceAnsiCodesIncremental(codes, newCodes) {
1999
+ let result = [...codes];
2000
+ for (const code of newCodes) if (code.code === styles.reset.open) result = [];
2001
+ else if (endCodesSet.has(code.code)) result = result.filter((existing) => existing.endCode !== code.code);
2002
+ else if (isIntensityCode(code)) {
2003
+ if (!result.some((existing) => existing.code === code.code && existing.endCode === code.endCode)) result.push(code);
2004
+ } else {
2005
+ result = result.filter((existing) => existing.endCode !== code.endCode);
2006
+ result.push(code);
2007
+ }
2008
+ return result;
2009
+ }
2010
+ /**
2011
+ Returns the combination of ANSI codes needed to undo the given ANSI codes.
2012
+ */
2013
+ function undoAnsiCodes(codes) {
2014
+ return reduceAnsiCodes(codes).reverse().map((code) => ({
2015
+ ...code,
2016
+ code: code.endCode
2017
+ }));
2018
+ }
2019
+ /**
2020
+ Returns the minimum amount of ANSI codes necessary to get from the compound
2021
+ style `from` to `to`. Both are expected to be reduced.
2022
+ */
2023
+ function diffAnsiCodes(from, to) {
2024
+ const endCodesInTo = new Set(to.map((code) => code.endCode));
2025
+ const startCodesInTo = new Set(to.map((code) => code.code));
2026
+ const startCodesInFrom = new Set(from.map((code) => code.code));
2027
+ return [...undoAnsiCodes(from.filter((code) => {
2028
+ if (isIntensityCode(code)) return !startCodesInTo.has(code.code);
2029
+ return !endCodesInTo.has(code.endCode);
2030
+ })), ...to.filter((code) => !startCodesInFrom.has(code.code))];
2031
+ }
2032
+ function styledCharsFromTokens(tokens) {
2033
+ let codes = [];
2034
+ const result = [];
2035
+ for (const token of tokens) if (token.type === "ansi") codes = reduceAnsiCodesIncremental(codes, [token]);
2036
+ else if (token.type === "char") result.push({
2037
+ ...token,
2038
+ styles: [...codes]
2039
+ });
2040
+ return result;
2041
+ }
2042
+ function styledCharsToString(chars) {
2043
+ let result = "";
2044
+ for (let index = 0; index < chars.length; index++) {
2045
+ const char = chars[index];
2046
+ if (index === 0) result += ansiCodesToString(char.styles);
2047
+ else result += ansiCodesToString(diffAnsiCodes(chars[index - 1].styles, char.styles));
2048
+ result += char.value;
2049
+ if (index === chars.length - 1) result += ansiCodesToString(diffAnsiCodes(char.styles, []));
2050
+ }
2051
+ return result;
2052
+ }
2053
+ //#endregion
2054
+ //#region src/ansi/slice.ts
2055
+ function sliceAnsi(string, start, end) {
2056
+ const sliceEnd = end ?? Number.POSITIVE_INFINITY;
2057
+ if (start >= sliceEnd || string === "") return "";
2058
+ if (start === 0 && sliceEnd === Number.POSITIVE_INFINITY) return string;
2059
+ const chars = styledCharsFromTokens(tokenize(string));
2060
+ const included = [];
2061
+ let column = 0;
2062
+ for (const char of chars) {
2063
+ const width = char.fullWidth ? 2 : 1;
2064
+ if (column + width > sliceEnd) break;
2065
+ if (column >= start) included.push(char);
2066
+ column += width;
2067
+ }
2068
+ return styledCharsToString(included);
2069
+ }
2070
+ //#endregion
2071
+ //#region src/ansi/truncate.ts
2072
+ function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight = false) {
2073
+ if (string.charAt(wantedIndex) === " ") return wantedIndex;
2074
+ const direction = shouldSearchRight ? 1 : -1;
2075
+ for (let index = 0; index <= 3; index++) {
2076
+ const finalIndex = wantedIndex + index * direction;
2077
+ if (string.charAt(finalIndex) === " ") return finalIndex;
2078
+ }
2079
+ return wantedIndex;
2080
+ }
2081
+ const ANSI_ESC = 27;
2082
+ const ANSI_LEFT_BRACKET = 91;
2083
+ const ANSI_LETTER_M = 109;
2084
+ const isSgrParameter = (code) => code >= 48 && code <= 57 || code === 59;
2085
+ function leadingSgrSpanEndIndex(string) {
2086
+ let index = 0;
2087
+ while (index + 2 < string.length && string.codePointAt(index) === ANSI_ESC && string.codePointAt(index + 1) === ANSI_LEFT_BRACKET) {
2088
+ let scan = index + 2;
2089
+ while (scan < string.length && isSgrParameter(string.codePointAt(scan))) scan++;
2090
+ if (scan < string.length && string.codePointAt(scan) === ANSI_LETTER_M) {
2091
+ index = scan + 1;
2092
+ continue;
2093
+ }
2094
+ break;
2095
+ }
2096
+ return index;
2097
+ }
2098
+ function trailingSgrSpanStartIndex(string) {
2099
+ let start = string.length;
2100
+ while (start > 1 && string.codePointAt(start - 1) === ANSI_LETTER_M) {
2101
+ let scan = start - 2;
2102
+ while (scan >= 0 && isSgrParameter(string.codePointAt(scan))) scan--;
2103
+ if (scan >= 1 && string.codePointAt(scan - 1) === ANSI_ESC && string.codePointAt(scan) === ANSI_LEFT_BRACKET) {
2104
+ start = scan - 1;
2105
+ continue;
2106
+ }
2107
+ break;
2108
+ }
2109
+ return start;
2110
+ }
2111
+ function appendWithInheritedStyleFromEnd(visible, suffix) {
2112
+ const start = trailingSgrSpanStartIndex(visible);
2113
+ if (start === visible.length) return visible + suffix;
2114
+ return visible.slice(0, start) + suffix + visible.slice(start);
2115
+ }
2116
+ function prependWithInheritedStyleFromStart(prefix, visible) {
2117
+ const end = leadingSgrSpanEndIndex(visible);
2118
+ if (end === 0) return prefix + visible;
2119
+ return visible.slice(0, end) + prefix + visible.slice(end);
2120
+ }
2121
+ function cliTruncate(text, columns, options = {}) {
2122
+ const { position = "end", space = false, preferTruncationOnSpace = false } = options;
2123
+ let { truncationCharacter = "…" } = options;
2124
+ if (columns < 1) return "";
2125
+ const length = stringWidth(text);
2126
+ if (length <= columns) return text;
2127
+ if (columns === 1) return truncationCharacter;
2128
+ if (position === "start") {
2129
+ if (preferTruncationOnSpace) {
2130
+ const right = sliceAnsi(text, getIndexOfNearestSpace(text, length - columns + stringWidth(truncationCharacter), true), length).trim();
2131
+ return prependWithInheritedStyleFromStart(truncationCharacter, right);
2132
+ }
2133
+ if (space) truncationCharacter += " ";
2134
+ const right = sliceAnsi(text, length - columns + stringWidth(truncationCharacter), length);
2135
+ return prependWithInheritedStyleFromStart(truncationCharacter, right);
2136
+ }
2137
+ if (position === "middle") {
2138
+ if (space) {
2139
+ truncationCharacter = ` ${truncationCharacter} `;
2140
+ if (stringWidth(truncationCharacter) >= columns) truncationCharacter = truncationCharacter.trim();
2141
+ }
2142
+ const truncationWidth = stringWidth(truncationCharacter);
2143
+ const half = Math.min(Math.floor(columns / 2), Math.max(0, columns - truncationWidth));
2144
+ if (preferTruncationOnSpace) {
2145
+ const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
2146
+ const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + truncationWidth, true);
2147
+ return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, spaceNearSecondBreakPoint, length).trim();
2148
+ }
2149
+ return sliceAnsi(text, 0, half) + truncationCharacter + sliceAnsi(text, length - (columns - half) + truncationWidth, length);
2150
+ }
2151
+ if (preferTruncationOnSpace) return appendWithInheritedStyleFromEnd(sliceAnsi(text, 0, getIndexOfNearestSpace(text, columns - stringWidth(truncationCharacter))), truncationCharacter);
2152
+ if (space) truncationCharacter = ` ${truncationCharacter}`;
2153
+ return appendWithInheritedStyleFromEnd(sliceAnsi(text, 0, columns - stringWidth(truncationCharacter)), truncationCharacter);
2154
+ }
2155
+ //#endregion
2156
+ export { hexToAnsi256 as $, fullwidthMinimalCodePoint as A, esu as At, narrowMaximumCodePoint as B, stripAnsi as C, disableBracketedPaste as Ct, eastAsianWidth as D, eraseLine as Dt, ambiguousRanges as E, eraseEndLine as Et, halfwidthRanges as F, pasteStart as Ft, wideRanges as G, narrowRanges as H, isAmbiguous as I, popKittyKeyboard as It, backgroundColorNames as J, ansi256ToAnsi as K, isFullWidth as L, pushKittyKeyboard as Lt, getCategory as M, kittyQuery as Mt, halfwidthMaximumCodePoint as N, link as Nt, eastAsianWidthType as O, eraseLines as Ot, halfwidthMinimalCodePoint as P, pasteEnd as Pt, hexToAnsi as Q, isFullwidthCodePoint as R, ansiRegex as S, cursorUp as St, ambiguousMinimalCodePoint as T, enterAlternativeScreen as Tt, wideMaximumCodePoint as U, narrowMinimalCodePoint as V, wideMinimalCodePoint as W, foreground as X, codes as Y, foregroundColorNames as Z, supportsColor as _, cursorHide as _t, endCodesSet as a, BEL as at, wrapAnsi as b, cursorShow as bt, isIntensityCode as c, CSI$1 as ct, styledCharsFromTokens as d, OSC$1 as dt, hexToRgb as et, styledCharsToString as f, ST as ft, chalk as g, cursorDown as gt, widestLine as h, clearTerminal as ht, diffAnsiCodes as i, styles as it, fullwidthRanges as j, exitAlternativeScreen as jt, fullwidthMaximumCodePoint as k, eraseScreen as kt, reduceAnsiCodes as l, DEL as lt, undoAnsiCodes as m, bsu as mt, sliceAnsi as n, rgbToAnsi as nt, getEndCode as o, C1_CSI as ot, tokenize as p, ansiEscapes as pt, background as q, ansiCodesToString as r, rgbToAnsi256 as rt, getLinkStartCode as s, C1_ST as st, cliTruncate as t, modifierNames as tt, reduceAnsiCodesIncremental as u, ESC as ut, cliCursor as v, cursorLeft as vt, ambiguousMaximumCodePoint as w, enableBracketedPaste as wt, stringWidth as x, cursorTo as xt, signalExit as y, cursorNextLine as yt, isWide as z };