@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,550 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const constants = require('./constants-CKuHriHc.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,151 +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 seq = r`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`;
7
- const sTags = r`\u{E0061}-\u{E007A}`;
8
- const emojiRegex = /* @__PURE__ */ __name$1(() => new RegExp(r`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${sTags}]{2}[\u{E0030}-\u{E0039}${sTags}]{1,3}\u{E007F}|${seq}(?:\u200D${seq})*`, "gu"), "default");
9
-
10
- var __defProp = Object.defineProperty;
11
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- const ESCAPES = /* @__PURE__ */ new Set(["\x1B", "›"]);
13
- const ANSI_ESCAPE_BELL = "\x07";
14
- const ANSI_CSI = "[";
15
- const ANSI_SGR_TERMINATOR = "m";
16
- const ANSI_ESCAPE_LINK = `]8;;`;
17
- const END_CODE = 39;
18
- const RE_ZERO_WIDTH = /[\u200B\uFEFF\u2060-\u2064]/g;
19
- const RE_ESCAPE_PATTERN = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`);
20
- const ANSI_RESET_CODES = Object.freeze(
21
- /* @__PURE__ */ new Map([
22
- [0, 0],
23
- // Reset all
24
- [1, 22],
25
- // Bold → Not bold
26
- [2, 22],
27
- // Dim → Not bold
28
- [3, 23],
29
- // Italic → Not italic
30
- [4, 24],
31
- // Underline → Not underline
32
- [7, 27],
33
- // Inverse → Not inverse
34
- [8, 28],
35
- // Hidden → Not hidden
36
- [9, 29],
37
- // Strikethrough → Not strikethrough
38
- [30, 39],
39
- // Foreground colors → Default foreground
40
- [31, 39],
41
- [32, 39],
42
- [33, 39],
43
- [34, 39],
44
- [35, 39],
45
- [36, 39],
46
- [37, 39],
47
- [40, 49],
48
- // Background colors → Default background
49
- [41, 49],
50
- [42, 49],
51
- [43, 49],
52
- [44, 49],
53
- [45, 49],
54
- [46, 49],
55
- [47, 49],
56
- [90, 39]
57
- // Bright foreground → Default foreground
58
- ])
59
- );
60
- const RE_LEADING_NEWLINE = /^[ \t]*(?:\r\n|\r|\n)/;
61
- const RE_TRAILING_NEWLINE = /(?:\r\n|\r|\n)[ \t]*$/;
62
- const RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY = /^(?:[\r\n]|$)/;
63
- const RE_DETECT_INDENTATION = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
64
- const RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = /^[ \t]*[\r\n][ \t\r\n]*$/;
65
- const RE_MATCH_NEWLINES = /\r\n|\n|\r/g;
66
- 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;
67
- const RE_VALID_ANSI_PAIRS = /\u001B\[(\d+(?:;\d+)*)?m[^\u001B]*(?:\u001B\[(?:\d+(?:;\d+)*)?m|$)/g;
68
- const RE_VALID_HYPERLINKS = /\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)(.*?)\u001B\]8;;(?:\u0007|\u001B\\)/g;
69
- const RE_CONTROL = /[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y;
70
- const RE_EMOJI = emojiRegex();
71
- const RE_SEPARATORS = /[-_./\s]+/g;
72
- const RE_FAST_ANSI = /(\u001B\[[0-9;]*[a-z])/i;
73
- const RE_ARABIC = new RegExp("\\p{Script=Arabic}", "u");
74
- const RE_BENGALI = new RegExp("\\p{Script=Bengali}", "u");
75
- const RE_CYRILLIC = new RegExp("\\p{Script=Cyrillic}", "u");
76
- const RE_DEVANAGARI = new RegExp("\\p{Script=Devanagari}", "u");
77
- const RE_ETHIOPIC = new RegExp("\\p{Script=Ethiopic}", "u");
78
- const RE_GREEK = new RegExp("\\p{Script=Greek}", "u");
79
- const RE_GREEK_LATIN_SPLIT = new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+", "gu");
80
- const RE_GUJARATI = new RegExp("\\p{Script=Gujarati}", "u");
81
- const RE_GURMUKHI = new RegExp("\\p{Script=Gurmukhi}", "u");
82
- const RE_HANGUL = new RegExp("\\p{Script=Hangul}", "u");
83
- const RE_HEBREW = new RegExp("\\p{Script=Hebrew}", "u");
84
- const RE_HIRAGANA = new RegExp("\\p{Script=Hiragana}", "u");
85
- const RE_KANJI = new RegExp("\\p{Script=Han}", "u");
86
- const RE_KANNADA = new RegExp("\\p{Script=Kannada}", "u");
87
- const RE_KATAKANA = new RegExp("\\p{Script=Katakana}", "u");
88
- const RE_KHMER = new RegExp("\\p{Script=Khmer}", "u");
89
- const RE_LAO = new RegExp("\\p{Script=Lao}", "u");
90
- const RE_LATIN = new RegExp("\\p{Script=Latin}", "u");
91
- const RE_MALAYALAM = new RegExp("\\p{Script=Malayalam}", "u");
92
- const RE_MYANMAR = new RegExp("\\p{Script=Myanmar}", "u");
93
- const RE_ORIYA = new RegExp("\\p{Script=Oriya}", "u");
94
- const RE_SINHALA = new RegExp("\\p{Script=Sinhala}", "u");
95
- const RE_TAMIL = new RegExp("\\p{Script=Tamil}", "u");
96
- const RE_TELUGU = new RegExp("\\p{Script=Telugu}", "u");
97
- const RE_THAI = new RegExp("\\p{Script=Thai}", "u");
98
- const RE_TIBETAN = new RegExp("\\p{Script=Tibetan}", "u");
99
- const RE_UZBEK_LATIN_MODIFIER = /[\u02BB\u02BC\u0027]/u;
100
- const stripEmoji = /* @__PURE__ */ __name((stringValue) => stringValue.replace(RE_EMOJI, ""), "stripEmoji");
101
-
102
- exports.ANSI_CSI = ANSI_CSI;
103
- exports.ANSI_ESCAPE_BELL = ANSI_ESCAPE_BELL;
104
- exports.ANSI_ESCAPE_LINK = ANSI_ESCAPE_LINK;
105
- exports.ANSI_RESET_CODES = ANSI_RESET_CODES;
106
- exports.ANSI_SGR_TERMINATOR = ANSI_SGR_TERMINATOR;
107
- exports.END_CODE = END_CODE;
108
- exports.ESCAPES = ESCAPES;
109
- exports.RE_ANSI = RE_ANSI;
110
- exports.RE_ARABIC = RE_ARABIC;
111
- exports.RE_BENGALI = RE_BENGALI;
112
- exports.RE_CONTROL = RE_CONTROL;
113
- exports.RE_CYRILLIC = RE_CYRILLIC;
114
- exports.RE_DETECT_INDENTATION = RE_DETECT_INDENTATION;
115
- exports.RE_DEVANAGARI = RE_DEVANAGARI;
116
- exports.RE_EMOJI = RE_EMOJI;
117
- exports.RE_ESCAPE_PATTERN = RE_ESCAPE_PATTERN;
118
- exports.RE_ETHIOPIC = RE_ETHIOPIC;
119
- exports.RE_FAST_ANSI = RE_FAST_ANSI;
120
- exports.RE_GREEK = RE_GREEK;
121
- exports.RE_GREEK_LATIN_SPLIT = RE_GREEK_LATIN_SPLIT;
122
- exports.RE_GUJARATI = RE_GUJARATI;
123
- exports.RE_GURMUKHI = RE_GURMUKHI;
124
- exports.RE_HANGUL = RE_HANGUL;
125
- exports.RE_HEBREW = RE_HEBREW;
126
- exports.RE_HIRAGANA = RE_HIRAGANA;
127
- exports.RE_KANJI = RE_KANJI;
128
- exports.RE_KANNADA = RE_KANNADA;
129
- exports.RE_KATAKANA = RE_KATAKANA;
130
- exports.RE_KHMER = RE_KHMER;
131
- exports.RE_LAO = RE_LAO;
132
- exports.RE_LATIN = RE_LATIN;
133
- exports.RE_LEADING_NEWLINE = RE_LEADING_NEWLINE;
134
- exports.RE_MALAYALAM = RE_MALAYALAM;
135
- exports.RE_MATCH_NEWLINES = RE_MATCH_NEWLINES;
136
- exports.RE_MYANMAR = RE_MYANMAR;
137
- exports.RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE;
138
- exports.RE_ORIYA = RE_ORIYA;
139
- exports.RE_SEPARATORS = RE_SEPARATORS;
140
- exports.RE_SINHALA = RE_SINHALA;
141
- exports.RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY = RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY;
142
- exports.RE_TAMIL = RE_TAMIL;
143
- exports.RE_TELUGU = RE_TELUGU;
144
- exports.RE_THAI = RE_THAI;
145
- exports.RE_TIBETAN = RE_TIBETAN;
146
- exports.RE_TRAILING_NEWLINE = RE_TRAILING_NEWLINE;
147
- exports.RE_UZBEK_LATIN_MODIFIER = RE_UZBEK_LATIN_MODIFIER;
148
- exports.RE_VALID_ANSI_PAIRS = RE_VALID_ANSI_PAIRS;
149
- exports.RE_VALID_HYPERLINKS = RE_VALID_HYPERLINKS;
150
- exports.RE_ZERO_WIDTH = RE_ZERO_WIDTH;
151
- exports.stripEmoji = stripEmoji;