@visulima/string 1.2.3 → 1.4.0

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 (102) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +46 -0
  3. package/dist/case/camel-case.cjs +1 -59
  4. package/dist/case/camel-case.mjs +1 -57
  5. package/dist/case/capital-case.cjs +1 -51
  6. package/dist/case/capital-case.mjs +1 -49
  7. package/dist/case/constant-case.cjs +1 -11
  8. package/dist/case/constant-case.mjs +1 -9
  9. package/dist/case/dot-case.cjs +1 -11
  10. package/dist/case/dot-case.mjs +1 -9
  11. package/dist/case/flat-case.cjs +1 -11
  12. package/dist/case/flat-case.mjs +1 -9
  13. package/dist/case/flip-case.cjs +1 -61
  14. package/dist/case/flip-case.mjs +1 -57
  15. package/dist/case/identify-case.cjs +1 -69
  16. package/dist/case/identify-case.mjs +1 -67
  17. package/dist/case/index.cjs +1 -47
  18. package/dist/case/index.mjs +1 -20
  19. package/dist/case/kebab-case.cjs +1 -61
  20. package/dist/case/kebab-case.mjs +1 -57
  21. package/dist/case/lower-first.cjs +1 -13
  22. package/dist/case/lower-first.mjs +1 -11
  23. package/dist/case/no-case.cjs +1 -11
  24. package/dist/case/no-case.mjs +1 -9
  25. package/dist/case/pascal-case.cjs +1 -52
  26. package/dist/case/pascal-case.mjs +1 -50
  27. package/dist/case/pascal-snake-case.cjs +1 -32
  28. package/dist/case/pascal-snake-case.mjs +1 -30
  29. package/dist/case/path-case.cjs +1 -11
  30. package/dist/case/path-case.mjs +1 -9
  31. package/dist/case/sentence-case.cjs +1 -58
  32. package/dist/case/sentence-case.mjs +1 -56
  33. package/dist/case/snake-case.cjs +1 -11
  34. package/dist/case/snake-case.mjs +1 -9
  35. package/dist/case/split-by-case.cjs +1 -641
  36. package/dist/case/split-by-case.mjs +1 -637
  37. package/dist/case/title-case.cjs +1 -47
  38. package/dist/case/title-case.mjs +1 -45
  39. package/dist/case/train-case.cjs +1 -44
  40. package/dist/case/train-case.mjs +1 -42
  41. package/dist/case/upper-first.cjs +1 -13
  42. package/dist/case/upper-first.mjs +1 -11
  43. package/dist/get-string-truncated-width.cjs +1 -422
  44. package/dist/get-string-truncated-width.mjs +1 -418
  45. package/dist/get-string-width.cjs +1 -11
  46. package/dist/get-string-width.mjs +1 -7
  47. package/dist/index.cjs +1 -66
  48. package/dist/index.d.cts +13 -3
  49. package/dist/index.d.mts +13 -3
  50. package/dist/index.d.ts +13 -3
  51. package/dist/index.mjs +1 -29
  52. package/dist/outdent.cjs +1 -125
  53. package/dist/outdent.mjs +1 -121
  54. package/dist/packem_shared/LRUCache-Bjo6gsbC.mjs +1 -0
  55. package/dist/packem_shared/LRUCache-TYqfUYE5.cjs +1 -0
  56. package/dist/packem_shared/WrapMode-BZ3jkEf1.mjs +8 -0
  57. package/dist/packem_shared/WrapMode-DR7vv3px.cjs +8 -0
  58. package/dist/packem_shared/alignText-BCKbnqhC.mjs +2 -0
  59. package/dist/packem_shared/alignText-CLZJuPP6.cjs +2 -0
  60. package/dist/packem_shared/constants-Cd17VNEv.mjs +1 -0
  61. package/dist/packem_shared/constants-D3K8u3G8.cjs +1 -0
  62. package/dist/packem_shared/generate-cache-key-BZf0GiMs.cjs +1 -0
  63. package/dist/packem_shared/generate-cache-key-DPByFaMH.mjs +1 -0
  64. package/dist/packem_shared/joinSegments-CDHNMXsF.cjs +1 -0
  65. package/dist/packem_shared/joinSegments-H7QJ7rwJ.mjs +1 -0
  66. package/dist/packem_shared/normalize-german-eszett-4k1qRtEP.mjs +1 -0
  67. package/dist/packem_shared/normalize-german-eszett-Bop4wOp9.cjs +1 -0
  68. package/dist/packem_shared/replaceString-Ce8TI_-L.cjs +1 -0
  69. package/dist/packem_shared/replaceString-D7R-5VFX.mjs +1 -0
  70. package/dist/packem_shared/slugify-B1vlQQO1.mjs +1 -0
  71. package/dist/packem_shared/slugify-CH3GI7E5.cjs +1 -0
  72. package/dist/packem_shared/transliterate-BXaP38Sh.mjs +5 -0
  73. package/dist/packem_shared/transliterate-CToQ-aeM.cjs +5 -0
  74. package/dist/slice.cjs +1 -419
  75. package/dist/slice.mjs +1 -415
  76. package/dist/test/utils.cjs +13 -74
  77. package/dist/test/utils.mjs +14 -69
  78. package/dist/test/vitest.cjs +1 -11
  79. package/dist/test/vitest.mjs +1 -7
  80. package/dist/truncate.cjs +1 -101
  81. package/dist/truncate.mjs +1 -97
  82. package/dist/utils.cjs +1 -65
  83. package/dist/utils.mjs +1 -56
  84. package/package.json +8 -1
  85. package/dist/packem_shared/LRUCache-Crb-m7cw.cjs +0 -53
  86. package/dist/packem_shared/LRUCache-udNErhWw.mjs +0 -51
  87. package/dist/packem_shared/WrapMode-BCVbMqYK.mjs +0 -545
  88. package/dist/packem_shared/WrapMode-DebG_Nll.cjs +0 -550
  89. package/dist/packem_shared/constants-6-GJ6zA-.cjs +0 -150
  90. package/dist/packem_shared/constants-CKdlkHVU.mjs +0 -99
  91. package/dist/packem_shared/generate-cache-key-D8f1auDB.cjs +0 -10
  92. package/dist/packem_shared/generate-cache-key-YSju5pj2.mjs +0 -8
  93. package/dist/packem_shared/joinSegments-BfSDBmPF.mjs +0 -46
  94. package/dist/packem_shared/joinSegments-HYXurfoq.cjs +0 -48
  95. package/dist/packem_shared/normalize-german-eszett-DJK0S2qj.cjs +0 -11
  96. package/dist/packem_shared/normalize-german-eszett-fpJ4lZL6.mjs +0 -9
  97. package/dist/packem_shared/replaceString-C7Dp5vAg.mjs +0 -200
  98. package/dist/packem_shared/replaceString-iYo1cDfZ.cjs +0 -202
  99. package/dist/packem_shared/slugify-SKjCL8DF.cjs +0 -50
  100. package/dist/packem_shared/slugify-pbxTlzeQ.mjs +0 -48
  101. package/dist/packem_shared/transliterate-4P32b49d.mjs +0 -47780
  102. package/dist/packem_shared/transliterate-CtOTNpLs.cjs +0 -47782
@@ -1,550 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const constants = require('./constants-6-GJ6zA-.cjs');
6
- const getStringWidth = require('../get-string-width.cjs');
7
-
8
- var __defProp$5 = Object.defineProperty;
9
- var __name$5 = (target, value) => __defProp$5(target, "name", { value, configurable: true });
10
- class AnsiStateTracker {
11
- static {
12
- __name$5(this, "AnsiStateTracker");
13
- }
14
- activeForeground = null;
15
- activeBackground = null;
16
- // Track other formatting (bold, italic, etc.)
17
- activeFormatting = [];
18
- /**
19
- * Processes an escape sequence and updates the internal state
20
- * @param sequence - The escape sequence to process
21
- */
22
- // eslint-disable-next-line sonarjs/cognitive-complexity
23
- processEscape(sequence) {
24
- const match = /\x1B\[(\d+)m/.exec(sequence);
25
- if (!match) {
26
- return;
27
- }
28
- const code = Number.parseInt(match[1], 10);
29
- switch (code) {
30
- case 0: {
31
- this.activeForeground = null;
32
- this.activeBackground = null;
33
- this.activeFormatting = [];
34
- break;
35
- }
36
- case 39: {
37
- this.activeForeground = null;
38
- break;
39
- }
40
- case 49: {
41
- this.activeBackground = null;
42
- break;
43
- }
44
- default: {
45
- if (code >= 30 && code <= 37 || code >= 90 && code <= 97) {
46
- this.activeForeground = sequence;
47
- } else if (code >= 40 && code <= 47 || code >= 100 && code <= 107) {
48
- this.activeBackground = sequence;
49
- } else if ([1, 2, 3, 4, 7, 8, 9].includes(code)) {
50
- this.activeFormatting.push(sequence);
51
- } else if ([22, 23, 24, 27, 28, 29].includes(code)) {
52
- const formatResetMap = {
53
- 22: "[1m",
54
- // Reset bold
55
- 23: "[3m",
56
- // Reset italic
57
- 24: "[4m",
58
- // Reset underline
59
- 27: "[7m",
60
- // Reset inverse
61
- 28: "[8m",
62
- // Reset hidden
63
- 29: "[9m"
64
- // Reset strikethrough
65
- };
66
- const formatToRemove = formatResetMap[code];
67
- if (formatToRemove) {
68
- this.activeFormatting = this.activeFormatting.filter((fmt) => !fmt.includes(formatToRemove));
69
- }
70
- }
71
- }
72
- }
73
- }
74
- /**
75
- * Gets all active escape sequences to apply
76
- * @returns String with all active escapes
77
- */
78
- getActiveEscapes() {
79
- return [this.activeBackground, this.activeForeground, ...this.activeFormatting].filter(Boolean).join("");
80
- }
81
- }
82
-
83
- var __defProp$4 = Object.defineProperty;
84
- var __name$4 = (target, value) => __defProp$4(target, "name", { value, configurable: true });
85
- const checkEscapeSequence = /* @__PURE__ */ __name$4((chars, index) => {
86
- if (!constants.ESCAPES.has(chars[index])) {
87
- return { isInsideEscape: false, isInsideLinkEscape: false };
88
- }
89
- const isInsideEscape = true;
90
- const possibleLink = chars.slice(index + 1, index + 1 + constants.ANSI_ESCAPE_LINK.length).join("");
91
- const isInsideLinkEscape = possibleLink === constants.ANSI_ESCAPE_LINK;
92
- return { isInsideEscape, isInsideLinkEscape };
93
- }, "checkEscapeSequence");
94
- const processAnsiString = /* @__PURE__ */ __name$4((string, options = {}) => {
95
- const stateTracker = new AnsiStateTracker();
96
- let currentText = "";
97
- let isInsideEscape = false;
98
- let isInsideLinkEscape = false;
99
- let escapeBuffer = "";
100
- let currentUrl = "";
101
- let isInHyperlink = false;
102
- const chars = [...string];
103
- for (let index = 0; index < chars.length; index++) {
104
- const character = chars[index];
105
- if (character && constants.ESCAPES.has(character)) {
106
- if (currentText) {
107
- const width2 = options.getWidth?.(currentText) ?? 0;
108
- const segment2 = {
109
- isEscapeSequence: false,
110
- isGrapheme: true,
111
- text: currentText,
112
- width: width2
113
- };
114
- if (isInHyperlink) {
115
- segment2.isHyperlink = true;
116
- segment2.hyperlinkUrl = currentUrl;
117
- }
118
- if (options.onSegment?.(segment2, stateTracker) === false) {
119
- return;
120
- }
121
- currentText = "";
122
- }
123
- isInsideEscape = true;
124
- escapeBuffer = character;
125
- const escapeInfo = checkEscapeSequence(chars, index);
126
- isInsideLinkEscape = escapeInfo.isInsideLinkEscape;
127
- if (isInsideLinkEscape) {
128
- let urlEnd = index + 1;
129
- currentUrl = "";
130
- while (urlEnd < chars.length) {
131
- const nextChar = chars[urlEnd];
132
- if (nextChar === constants.ANSI_ESCAPE_BELL) {
133
- break;
134
- }
135
- currentUrl += nextChar;
136
- urlEnd++;
137
- }
138
- currentUrl = currentUrl.slice(4);
139
- const segment2 = {
140
- hyperlinkUrl: currentUrl,
141
- isEscapeSequence: true,
142
- isGrapheme: false,
143
- isHyperlink: true,
144
- isHyperlinkStart: true,
145
- width: 0
146
- };
147
- if (options.onSegment?.(segment2, stateTracker) === false) {
148
- return;
149
- }
150
- index = urlEnd;
151
- isInHyperlink = true;
152
- isInsideEscape = false;
153
- isInsideLinkEscape = false;
154
- escapeBuffer = "";
155
- continue;
156
- }
157
- if (index + 1 < chars.length && chars[index + 1] === "\\" && isInHyperlink) {
158
- const segment2 = {
159
- isEscapeSequence: true,
160
- isGrapheme: false,
161
- isHyperlink: true,
162
- isHyperlinkEnd: true,
163
- width: 0
164
- };
165
- if (options.onSegment?.(segment2, stateTracker) === false) {
166
- return;
167
- }
168
- isInHyperlink = false;
169
- currentUrl = "";
170
- index++;
171
- isInsideEscape = false;
172
- escapeBuffer = "";
173
- continue;
174
- }
175
- }
176
- if (isInsideEscape) {
177
- if (escapeBuffer !== character) {
178
- escapeBuffer += character;
179
- }
180
- if (character === constants.ANSI_SGR_TERMINATOR) {
181
- isInsideEscape = false;
182
- stateTracker.processEscape(escapeBuffer);
183
- const segment2 = {
184
- isEscapeSequence: true,
185
- isGrapheme: false,
186
- text: escapeBuffer,
187
- width: 0
188
- };
189
- if (options.onSegment?.(segment2, stateTracker) === false) {
190
- return;
191
- }
192
- escapeBuffer = "";
193
- }
194
- continue;
195
- }
196
- currentText += character;
197
- const width = options.getWidth?.(currentText) ?? 0;
198
- const segment = {
199
- isEscapeSequence: false,
200
- isGrapheme: true,
201
- text: currentText,
202
- width
203
- };
204
- if (isInHyperlink) {
205
- segment.isHyperlink = true;
206
- segment.hyperlinkUrl = currentUrl;
207
- }
208
- if (options.onSegment?.(segment, stateTracker) === false) {
209
- return;
210
- }
211
- currentText = "";
212
- }
213
- if (currentText) {
214
- const width = options.getWidth?.(currentText) ?? 0;
215
- const segment = {
216
- isEscapeSequence: false,
217
- isGrapheme: true,
218
- text: currentText,
219
- width
220
- };
221
- if (isInHyperlink) {
222
- segment.isHyperlink = true;
223
- segment.hyperlinkUrl = currentUrl;
224
- }
225
- options.onSegment?.(segment, stateTracker);
226
- }
227
- if (escapeBuffer) {
228
- const segment = {
229
- isEscapeSequence: true,
230
- isGrapheme: false,
231
- text: escapeBuffer,
232
- width: 0
233
- };
234
- options.onSegment?.(segment, stateTracker);
235
- }
236
- }, "processAnsiString");
237
-
238
- var __defProp$3 = Object.defineProperty;
239
- var __name$3 = (target, value) => __defProp$3(target, "name", { value, configurable: true });
240
- const wrapAnsiCode = /* @__PURE__ */ __name$3((code) => {
241
- const escapeChar = constants.ESCAPES.values().next().value;
242
- return `${escapeChar}${constants.ANSI_CSI}${code}${constants.ANSI_SGR_TERMINATOR}`;
243
- }, "wrapAnsiCode");
244
-
245
- var __defProp$2 = Object.defineProperty;
246
- var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
247
- const wrapAnsiHyperlink = /* @__PURE__ */ __name$2((url) => {
248
- const escapeChar = constants.ESCAPES.values().next().value;
249
- return `${escapeChar}${constants.ANSI_ESCAPE_LINK}${url}${constants.ANSI_ESCAPE_BELL}`;
250
- }, "wrapAnsiHyperlink");
251
-
252
- var __defProp$1 = Object.defineProperty;
253
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
254
- const preserveAnsi = /* @__PURE__ */ __name$1((rawLines) => {
255
- if (rawLines.length === 0) {
256
- return "";
257
- }
258
- if (rawLines.length === 1) {
259
- return rawLines[0];
260
- }
261
- let returnValue = "";
262
- let escapeCode;
263
- let escapeUrl;
264
- const preString = rawLines.join("\n");
265
- const pre = [...preString];
266
- let preStringIndex = 0;
267
- for (const [index, character] of pre.entries()) {
268
- returnValue += character;
269
- if (constants.ESCAPES.has(character)) {
270
- const match = constants.RE_ESCAPE_PATTERN.exec(preString.slice(preStringIndex));
271
- const groups = match?.groups ?? {};
272
- if (groups.code !== void 0) {
273
- const code2 = Number.parseFloat(groups.code);
274
- escapeCode = code2 === constants.END_CODE ? void 0 : code2;
275
- } else if (groups.uri !== void 0) {
276
- escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
277
- }
278
- }
279
- const code = constants.ANSI_RESET_CODES.get(Number(escapeCode));
280
- if (pre[index + 1] === "\n") {
281
- if (escapeUrl) {
282
- returnValue += wrapAnsiHyperlink("");
283
- }
284
- if (escapeCode && code) {
285
- returnValue += wrapAnsiCode(code);
286
- }
287
- } else if (character === "\n") {
288
- if (escapeCode && code) {
289
- returnValue += wrapAnsiCode(escapeCode);
290
- }
291
- if (escapeUrl) {
292
- returnValue += wrapAnsiHyperlink(escapeUrl);
293
- }
294
- }
295
- preStringIndex += character.length;
296
- }
297
- return returnValue;
298
- }, "preserveAnsi");
299
-
300
- var __defProp = Object.defineProperty;
301
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
302
- const resetAnsiAtLineBreak = /* @__PURE__ */ __name((currentLine) => {
303
- if (!currentLine.includes("\x1B")) {
304
- return currentLine;
305
- }
306
- let result = currentLine;
307
- if (currentLine.includes("\x1B[30m")) {
308
- result += "\x1B[39m";
309
- }
310
- if (currentLine.includes("\x1B[42m")) {
311
- result += "\x1B[49m";
312
- }
313
- return result;
314
- }, "resetAnsiAtLineBreak");
315
- const stringVisibleTrimSpacesRight = /* @__PURE__ */ __name((string) => {
316
- const words = string.split(" ");
317
- let last = words.length;
318
- while (last > 0 && getStringWidth.getStringWidth(words[last - 1]) === 0) {
319
- last--;
320
- }
321
- if (last === words.length) {
322
- return string;
323
- }
324
- return words.slice(0, last).join(" ") + words.slice(last).join("");
325
- }, "stringVisibleTrimSpacesRight");
326
- const wrapWithBreakAtWidth = /* @__PURE__ */ __name((string, width, trim) => {
327
- if (string.length === 0) {
328
- return [""];
329
- }
330
- if (width <= 0) {
331
- return [string];
332
- }
333
- const rows = [];
334
- let currentLine = "";
335
- let currentWidth = 0;
336
- const ansiTracker = new AnsiStateTracker();
337
- let isInsideEscape = false;
338
- let isInsideLinkEscape = false;
339
- let escapeBuffer = "";
340
- for (let index = 0; index < string.length; index++) {
341
- const char = string[index];
342
- if (constants.ESCAPES.has(char)) {
343
- isInsideEscape = true;
344
- escapeBuffer = char;
345
- currentLine += char;
346
- const escapeInfo = checkEscapeSequence([...string], index);
347
- isInsideLinkEscape = escapeInfo.isInsideLinkEscape;
348
- continue;
349
- }
350
- if (isInsideEscape) {
351
- escapeBuffer += char;
352
- currentLine += char;
353
- if (isInsideLinkEscape) {
354
- if (char === constants.ANSI_ESCAPE_BELL) {
355
- isInsideEscape = isInsideLinkEscape = false;
356
- }
357
- } else if (char === constants.ANSI_SGR_TERMINATOR) {
358
- isInsideEscape = false;
359
- ansiTracker.processEscape(escapeBuffer);
360
- }
361
- continue;
362
- }
363
- const charWidth = getStringWidth.getStringWidth(char);
364
- const isSpace = char === " ";
365
- if (charWidth === 0) {
366
- currentLine += char;
367
- continue;
368
- }
369
- if (currentWidth + charWidth > width) {
370
- if (currentLine) {
371
- rows.push(resetAnsiAtLineBreak(currentLine));
372
- }
373
- currentLine = ansiTracker.getActiveEscapes();
374
- currentWidth = 0;
375
- if (isSpace && trim) {
376
- while (index < string.length && string[index] === " ") {
377
- index++;
378
- if (index >= string.length) {
379
- break;
380
- }
381
- }
382
- if (index < string.length) {
383
- index--;
384
- }
385
- continue;
386
- }
387
- }
388
- currentLine += char;
389
- currentWidth += charWidth;
390
- if (currentWidth === width && index < string.length - 1) {
391
- rows.push(resetAnsiAtLineBreak(currentLine));
392
- currentLine = ansiTracker.getActiveEscapes();
393
- currentWidth = 0;
394
- if (index + 1 < string.length && string[index + 1] === " " && trim) {
395
- index++;
396
- while (index < string.length && string[index] === " ") {
397
- index++;
398
- }
399
- index--;
400
- }
401
- }
402
- }
403
- if (currentLine) {
404
- rows.push(currentLine);
405
- }
406
- return trim ? rows.map((element) => stringVisibleTrimSpacesRight(element)) : rows;
407
- }, "wrapWithBreakAtWidth");
408
- const wrapCharByChar = /* @__PURE__ */ __name((string, width, trim) => {
409
- if (string.length === 0) {
410
- return [];
411
- }
412
- const inputToProcess = trim ? string.trim() : string;
413
- if (inputToProcess.length === 0) {
414
- return [];
415
- }
416
- const rows = [];
417
- let currentLine = "";
418
- let currentWidth = 0;
419
- processAnsiString(inputToProcess, {
420
- getWidth: getStringWidth.getStringWidth,
421
- onSegment: /* @__PURE__ */ __name((segment, stateTracker) => {
422
- if (segment.isEscapeSequence) {
423
- currentLine += segment.text;
424
- } else {
425
- const isSpace = segment.text === " ";
426
- if (segment.width === 0) {
427
- currentLine += segment.text;
428
- return true;
429
- }
430
- if (currentWidth + segment.width > width) {
431
- if (currentLine) {
432
- rows.push(resetAnsiAtLineBreak(currentLine));
433
- }
434
- currentLine = stateTracker.getActiveEscapes();
435
- currentWidth = 0;
436
- if (isSpace) {
437
- if (trim) {
438
- return true;
439
- }
440
- rows.push(stateTracker.getActiveEscapes() + segment.text);
441
- return true;
442
- }
443
- }
444
- currentLine += segment.text;
445
- currentWidth += segment.width;
446
- }
447
- return true;
448
- }, "onSegment")
449
- });
450
- if (currentLine) {
451
- rows.push(currentLine);
452
- }
453
- return trim ? rows.map((row) => stringVisibleTrimSpacesRight(row)) : rows;
454
- }, "wrapCharByChar");
455
- const wrapWithWordBoundaries = /* @__PURE__ */ __name((string, width, trim) => {
456
- if (string.length === 0) {
457
- return [];
458
- }
459
- const inputToProcess = trim ? string.trim() : string;
460
- if (inputToProcess.length === 0) {
461
- return [];
462
- }
463
- const tokens = inputToProcess.split(/(?=\s)|(?<=\s)/);
464
- const rows = [];
465
- let currentLine = "";
466
- let currentWidth = 0;
467
- let index = 0;
468
- while (index < tokens.length) {
469
- const token = tokens[index];
470
- const isSpace = /^\s+$/.test(token);
471
- const tokenVisibleWidth = getStringWidth.getStringWidth(token);
472
- if (token.length === 0) {
473
- index++;
474
- continue;
475
- }
476
- if (trim && isSpace && currentWidth === 0) {
477
- index++;
478
- continue;
479
- }
480
- if (currentWidth + tokenVisibleWidth > width && currentWidth > 0) {
481
- if (trim) {
482
- rows.push(stringVisibleTrimSpacesRight(currentLine));
483
- } else {
484
- rows.push(currentLine);
485
- }
486
- currentLine = "";
487
- currentWidth = 0;
488
- continue;
489
- }
490
- currentLine += token;
491
- currentWidth += tokenVisibleWidth;
492
- index++;
493
- }
494
- if (currentLine) {
495
- if (trim) {
496
- rows.push(stringVisibleTrimSpacesRight(currentLine));
497
- } else {
498
- rows.push(currentLine);
499
- }
500
- }
501
- return rows;
502
- }, "wrapWithWordBoundaries");
503
- const WrapMode = {
504
- /**
505
- * Breaks words at character boundaries to fit the width
506
- */
507
- BREAK_AT_CHARACTERS: "BREAK_AT_CHARACTERS",
508
- /**
509
- * Preserves word boundaries, words are kept intact even if they exceed width
510
- */
511
- PRESERVE_WORDS: "PRESERVE_WORDS",
512
- /**
513
- * Enforces strict adherence to the width limit by breaking at exact width
514
- */
515
- STRICT_WIDTH: "STRICT_WIDTH"
516
- };
517
- const wordWrap = /* @__PURE__ */ __name((string, options = {}) => {
518
- const { removeZeroWidthCharacters = true, trim = true, width = 80, wrapMode = WrapMode.PRESERVE_WORDS } = options;
519
- if (trim && string.trim() === "") {
520
- return "";
521
- }
522
- let normalizedString = String(string).normalize("NFC").replaceAll("\r\n", "\n");
523
- if (removeZeroWidthCharacters) {
524
- normalizedString = normalizedString.replaceAll(constants.RE_ZERO_WIDTH, "");
525
- }
526
- const result = normalizedString.split("\n").map((line) => {
527
- if (trim && line.trim() === "") {
528
- return "";
529
- }
530
- let wrappedLines;
531
- switch (wrapMode) {
532
- case WrapMode.STRICT_WIDTH: {
533
- wrappedLines = wrapWithBreakAtWidth(line, width, trim);
534
- break;
535
- }
536
- case WrapMode.BREAK_AT_CHARACTERS: {
537
- wrappedLines = wrapCharByChar(line, width, trim);
538
- break;
539
- }
540
- default: {
541
- wrappedLines = wrapWithWordBoundaries(line, width, trim);
542
- }
543
- }
544
- return preserveAnsi(wrappedLines);
545
- });
546
- return result.join("\n");
547
- }, "wordWrap");
548
-
549
- exports.WrapMode = WrapMode;
550
- exports.wordWrap = wordWrap;
@@ -1,150 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp$1 = Object.defineProperty;
4
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
5
- const r = String.raw;
6
- const e = r`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`;
7
- const emojiRegex = /* @__PURE__ */ __name$1(() => new RegExp(r`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${e}(?:\u200D${e})*`, "gu"), "default");
8
-
9
- var __defProp = Object.defineProperty;
10
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- const ESCAPES = /* @__PURE__ */ new Set(["\x1B", "›"]);
12
- const ANSI_ESCAPE_BELL = "\x07";
13
- const ANSI_CSI = "[";
14
- const ANSI_SGR_TERMINATOR = "m";
15
- const ANSI_ESCAPE_LINK = `]8;;`;
16
- const END_CODE = 39;
17
- const RE_ZERO_WIDTH = /[\u200B\uFEFF\u2060-\u2064]/g;
18
- const RE_ESCAPE_PATTERN = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`);
19
- const ANSI_RESET_CODES = Object.freeze(
20
- /* @__PURE__ */ new Map([
21
- [0, 0],
22
- // Reset all
23
- [1, 22],
24
- // Bold → Not bold
25
- [2, 22],
26
- // Dim → Not bold
27
- [3, 23],
28
- // Italic → Not italic
29
- [4, 24],
30
- // Underline → Not underline
31
- [7, 27],
32
- // Inverse → Not inverse
33
- [8, 28],
34
- // Hidden → Not hidden
35
- [9, 29],
36
- // Strikethrough → Not strikethrough
37
- [30, 39],
38
- // Foreground colors → Default foreground
39
- [31, 39],
40
- [32, 39],
41
- [33, 39],
42
- [34, 39],
43
- [35, 39],
44
- [36, 39],
45
- [37, 39],
46
- [40, 49],
47
- // Background colors → Default background
48
- [41, 49],
49
- [42, 49],
50
- [43, 49],
51
- [44, 49],
52
- [45, 49],
53
- [46, 49],
54
- [47, 49],
55
- [90, 39]
56
- // Bright foreground → Default foreground
57
- ])
58
- );
59
- const RE_LEADING_NEWLINE = /^[ \t]*(?:\r\n|\r|\n)/;
60
- const RE_TRAILING_NEWLINE = /(?:\r\n|\r|\n)[ \t]*$/;
61
- const RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY = /^(?:[\r\n]|$)/;
62
- const RE_DETECT_INDENTATION = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
63
- const RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = /^[ \t]*[\r\n][ \t\r\n]*$/;
64
- const RE_MATCH_NEWLINES = /\r\n|\n|\r/g;
65
- 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;
66
- const RE_VALID_ANSI_PAIRS = /\u001B\[(\d+(?:;\d+)*)?m[^\u001B]*(?:\u001B\[(?:\d+(?:;\d+)*)?m|$)/g;
67
- const RE_VALID_HYPERLINKS = /\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)(.*?)\u001B\]8;;(?:\u0007|\u001B\\)/g;
68
- const RE_CONTROL = /[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y;
69
- const RE_EMOJI = emojiRegex();
70
- const RE_SEPARATORS = /[-_./\s]+/g;
71
- const RE_FAST_ANSI = /(\u001B\[[0-9;]*[a-z])/i;
72
- const RE_ARABIC = new RegExp("\\p{Script=Arabic}", "u");
73
- const RE_BENGALI = new RegExp("\\p{Script=Bengali}", "u");
74
- const RE_CYRILLIC = new RegExp("\\p{Script=Cyrillic}", "u");
75
- const RE_DEVANAGARI = new RegExp("\\p{Script=Devanagari}", "u");
76
- const RE_ETHIOPIC = new RegExp("\\p{Script=Ethiopic}", "u");
77
- const RE_GREEK = new RegExp("\\p{Script=Greek}", "u");
78
- const RE_GREEK_LATIN_SPLIT = new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+", "gu");
79
- const RE_GUJARATI = new RegExp("\\p{Script=Gujarati}", "u");
80
- const RE_GURMUKHI = new RegExp("\\p{Script=Gurmukhi}", "u");
81
- const RE_HANGUL = new RegExp("\\p{Script=Hangul}", "u");
82
- const RE_HEBREW = new RegExp("\\p{Script=Hebrew}", "u");
83
- const RE_HIRAGANA = new RegExp("\\p{Script=Hiragana}", "u");
84
- const RE_KANJI = new RegExp("\\p{Script=Han}", "u");
85
- const RE_KANNADA = new RegExp("\\p{Script=Kannada}", "u");
86
- const RE_KATAKANA = new RegExp("\\p{Script=Katakana}", "u");
87
- const RE_KHMER = new RegExp("\\p{Script=Khmer}", "u");
88
- const RE_LAO = new RegExp("\\p{Script=Lao}", "u");
89
- const RE_LATIN = new RegExp("\\p{Script=Latin}", "u");
90
- const RE_MALAYALAM = new RegExp("\\p{Script=Malayalam}", "u");
91
- const RE_MYANMAR = new RegExp("\\p{Script=Myanmar}", "u");
92
- const RE_ORIYA = new RegExp("\\p{Script=Oriya}", "u");
93
- const RE_SINHALA = new RegExp("\\p{Script=Sinhala}", "u");
94
- const RE_TAMIL = new RegExp("\\p{Script=Tamil}", "u");
95
- const RE_TELUGU = new RegExp("\\p{Script=Telugu}", "u");
96
- const RE_THAI = new RegExp("\\p{Script=Thai}", "u");
97
- const RE_TIBETAN = new RegExp("\\p{Script=Tibetan}", "u");
98
- const RE_UZBEK_LATIN_MODIFIER = /[\u02BB\u02BC\u0027]/u;
99
- const stripEmoji = /* @__PURE__ */ __name((stringValue) => stringValue.replace(RE_EMOJI, ""), "stripEmoji");
100
-
101
- exports.ANSI_CSI = ANSI_CSI;
102
- exports.ANSI_ESCAPE_BELL = ANSI_ESCAPE_BELL;
103
- exports.ANSI_ESCAPE_LINK = ANSI_ESCAPE_LINK;
104
- exports.ANSI_RESET_CODES = ANSI_RESET_CODES;
105
- exports.ANSI_SGR_TERMINATOR = ANSI_SGR_TERMINATOR;
106
- exports.END_CODE = END_CODE;
107
- exports.ESCAPES = ESCAPES;
108
- exports.RE_ANSI = RE_ANSI;
109
- exports.RE_ARABIC = RE_ARABIC;
110
- exports.RE_BENGALI = RE_BENGALI;
111
- exports.RE_CONTROL = RE_CONTROL;
112
- exports.RE_CYRILLIC = RE_CYRILLIC;
113
- exports.RE_DETECT_INDENTATION = RE_DETECT_INDENTATION;
114
- exports.RE_DEVANAGARI = RE_DEVANAGARI;
115
- exports.RE_EMOJI = RE_EMOJI;
116
- exports.RE_ESCAPE_PATTERN = RE_ESCAPE_PATTERN;
117
- exports.RE_ETHIOPIC = RE_ETHIOPIC;
118
- exports.RE_FAST_ANSI = RE_FAST_ANSI;
119
- exports.RE_GREEK = RE_GREEK;
120
- exports.RE_GREEK_LATIN_SPLIT = RE_GREEK_LATIN_SPLIT;
121
- exports.RE_GUJARATI = RE_GUJARATI;
122
- exports.RE_GURMUKHI = RE_GURMUKHI;
123
- exports.RE_HANGUL = RE_HANGUL;
124
- exports.RE_HEBREW = RE_HEBREW;
125
- exports.RE_HIRAGANA = RE_HIRAGANA;
126
- exports.RE_KANJI = RE_KANJI;
127
- exports.RE_KANNADA = RE_KANNADA;
128
- exports.RE_KATAKANA = RE_KATAKANA;
129
- exports.RE_KHMER = RE_KHMER;
130
- exports.RE_LAO = RE_LAO;
131
- exports.RE_LATIN = RE_LATIN;
132
- exports.RE_LEADING_NEWLINE = RE_LEADING_NEWLINE;
133
- exports.RE_MALAYALAM = RE_MALAYALAM;
134
- exports.RE_MATCH_NEWLINES = RE_MATCH_NEWLINES;
135
- exports.RE_MYANMAR = RE_MYANMAR;
136
- exports.RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE;
137
- exports.RE_ORIYA = RE_ORIYA;
138
- exports.RE_SEPARATORS = RE_SEPARATORS;
139
- exports.RE_SINHALA = RE_SINHALA;
140
- exports.RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY = RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY;
141
- exports.RE_TAMIL = RE_TAMIL;
142
- exports.RE_TELUGU = RE_TELUGU;
143
- exports.RE_THAI = RE_THAI;
144
- exports.RE_TIBETAN = RE_TIBETAN;
145
- exports.RE_TRAILING_NEWLINE = RE_TRAILING_NEWLINE;
146
- exports.RE_UZBEK_LATIN_MODIFIER = RE_UZBEK_LATIN_MODIFIER;
147
- exports.RE_VALID_ANSI_PAIRS = RE_VALID_ANSI_PAIRS;
148
- exports.RE_VALID_HYPERLINKS = RE_VALID_HYPERLINKS;
149
- exports.RE_ZERO_WIDTH = RE_ZERO_WIDTH;
150
- exports.stripEmoji = stripEmoji;