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