@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
@@ -60,4 +60,5 @@ interface SlugifyOptions extends OptionsTransliterate {
60
60
  uppercase?: boolean;
61
61
  }
62
62
 
63
- export { type All as A, type CharAt as C, type EndsWith as E, type Includes as I, type Join as J, type Length as L, Math as M, type NodeLocale as N, type OptionReplaceArray as O, type PadEnd as P, type Replace as R, type Slice as S, type ToLowerCase as T, type Concat as a, type PadStart as b, type ReplaceAll as c, type Split as d, type StartsWith as e, type ToUpperCase as f, type Trim as g, type TrimEnd as h, type TrimStart as i, type IsStringLiteral as j, type IntervalArray as k, type SlugifyOptions as l, type OptionsTransliterate as m, type Any as n, type Charmap as o, type Interval as p, type IsBooleanLiteral as q, type IsNumberLiteral as r, type IsStringLiteralArray as s, type OptionReplaceCombined as t, type OptionReplaceObject as u, type Repeat as v, type Reverse as w };
63
+ export { Math as M };
64
+ export type { All as A, CharAt as C, EndsWith as E, Includes as I, Join as J, Length as L, NodeLocale as N, OptionReplaceArray as O, PadEnd as P, Replace as R, Slice as S, ToLowerCase as T, Concat as a, PadStart as b, ReplaceAll as c, Split as d, StartsWith as e, ToUpperCase as f, Trim as g, TrimEnd as h, TrimStart as i, IsStringLiteral as j, IntervalArray as k, SlugifyOptions as l, OptionsTransliterate as m, Any as n, Charmap as o, Interval as p, IsBooleanLiteral as q, IsNumberLiteral as r, IsStringLiteralArray as s, OptionReplaceCombined as t, OptionReplaceObject as u, Repeat as v, Reverse as w };
@@ -60,4 +60,5 @@ interface SlugifyOptions extends OptionsTransliterate {
60
60
  uppercase?: boolean;
61
61
  }
62
62
 
63
- export { type All as A, type CharAt as C, type EndsWith as E, type Includes as I, type Join as J, type Length as L, Math as M, type NodeLocale as N, type OptionReplaceArray as O, type PadEnd as P, type Replace as R, type Slice as S, type ToLowerCase as T, type Concat as a, type PadStart as b, type ReplaceAll as c, type Split as d, type StartsWith as e, type ToUpperCase as f, type Trim as g, type TrimEnd as h, type TrimStart as i, type IsStringLiteral as j, type IntervalArray as k, type SlugifyOptions as l, type OptionsTransliterate as m, type Any as n, type Charmap as o, type Interval as p, type IsBooleanLiteral as q, type IsNumberLiteral as r, type IsStringLiteralArray as s, type OptionReplaceCombined as t, type OptionReplaceObject as u, type Repeat as v, type Reverse as w };
63
+ export { Math as M };
64
+ export type { All as A, CharAt as C, EndsWith as E, Includes as I, Join as J, Length as L, NodeLocale as N, OptionReplaceArray as O, PadEnd as P, Replace as R, Slice as S, ToLowerCase as T, Concat as a, PadStart as b, ReplaceAll as c, Split as d, StartsWith as e, ToUpperCase as f, Trim as g, TrimEnd as h, TrimStart as i, IsStringLiteral as j, IntervalArray as k, SlugifyOptions as l, OptionsTransliterate as m, Any as n, Charmap as o, Interval as p, IsBooleanLiteral as q, IsNumberLiteral as r, IsStringLiteralArray as s, OptionReplaceCombined as t, OptionReplaceObject as u, Repeat as v, Reverse as w };
@@ -60,4 +60,5 @@ interface SlugifyOptions extends OptionsTransliterate {
60
60
  uppercase?: boolean;
61
61
  }
62
62
 
63
- export { type All as A, type CharAt as C, type EndsWith as E, type Includes as I, type Join as J, type Length as L, Math as M, type NodeLocale as N, type OptionReplaceArray as O, type PadEnd as P, type Replace as R, type Slice as S, type ToLowerCase as T, type Concat as a, type PadStart as b, type ReplaceAll as c, type Split as d, type StartsWith as e, type ToUpperCase as f, type Trim as g, type TrimEnd as h, type TrimStart as i, type IsStringLiteral as j, type IntervalArray as k, type SlugifyOptions as l, type OptionsTransliterate as m, type Any as n, type Charmap as o, type Interval as p, type IsBooleanLiteral as q, type IsNumberLiteral as r, type IsStringLiteralArray as s, type OptionReplaceCombined as t, type OptionReplaceObject as u, type Repeat as v, type Reverse as w };
63
+ export { Math as M };
64
+ export type { All as A, CharAt as C, EndsWith as E, Includes as I, Join as J, Length as L, NodeLocale as N, OptionReplaceArray as O, PadEnd as P, Replace as R, Slice as S, ToLowerCase as T, Concat as a, PadStart as b, ReplaceAll as c, Split as d, StartsWith as e, ToUpperCase as f, Trim as g, TrimEnd as h, TrimStart as i, IsStringLiteral as j, IntervalArray as k, SlugifyOptions as l, OptionsTransliterate as m, Any as n, Charmap as o, Interval as p, IsBooleanLiteral as q, IsNumberLiteral as r, IsStringLiteralArray as s, OptionReplaceCombined as t, OptionReplaceObject as u, Repeat as v, Reverse as w };
@@ -1,4 +1,4 @@
1
- import { N as NodeLocale, j as IsStringLiteral } from './types-DmfKbIaI.js';
1
+ import { N as NodeLocale, j as IsStringLiteral } from './types-BSdIWVzn.js';
2
2
  import { L as LRUCache } from './lru-cache-B_t27XwI.js';
3
3
 
4
4
  type SplitterCharacter = " " | "_" | "-" | "." | "/";
@@ -1,4 +1,4 @@
1
- import { N as NodeLocale, j as IsStringLiteral } from './types-DmfKbIaI.cjs';
1
+ import { N as NodeLocale, j as IsStringLiteral } from './types-BSdIWVzn.cjs';
2
2
  import { L as LRUCache } from './lru-cache-B_t27XwI.cjs';
3
3
 
4
4
  type SplitterCharacter = " " | "_" | "-" | "." | "/";
@@ -1,4 +1,4 @@
1
- import { N as NodeLocale, j as IsStringLiteral } from './types-DmfKbIaI.mjs';
1
+ import { N as NodeLocale, j as IsStringLiteral } from './types-BSdIWVzn.mjs';
2
2
  import { L as LRUCache } from './lru-cache-B_t27XwI.mjs';
3
3
 
4
4
  type SplitterCharacter = " " | "_" | "-" | "." | "/";
package/dist/slice.cjs CHANGED
@@ -1,419 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const constants = require('./packem_shared/constants-CKuHriHc.cjs');
6
- const getStringWidth = require('./get-string-width.cjs');
7
- const LRUCache = require('./packem_shared/LRUCache-Crb-m7cw.cjs');
8
-
9
- var __defProp = Object.defineProperty;
10
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- const segmentCache = new LRUCache(100);
12
- const defaultSegmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
13
- const ANSI_RESET_CODES = /* @__PURE__ */ new Set([
14
- "0",
15
- // Full reset
16
- "22",
17
- // Bold reset
18
- "23",
19
- // Italic reset
20
- "24",
21
- // Underline reset
22
- "27",
23
- // Inverse reset
24
- "28",
25
- // Hidden reset
26
- "29",
27
- // Strikethrough reset
28
- "39",
29
- // Foreground color reset
30
- "49"
31
- // Background color reset
32
- ]);
33
- const STYLE_CODES = /* @__PURE__ */ new Set([
34
- "1",
35
- // Bold
36
- "3",
37
- // Italic
38
- "4",
39
- // Underline
40
- "7",
41
- // Inverse
42
- "8",
43
- // Hidden
44
- "9"
45
- // Strikethrough
46
- ]);
47
- const FORMAT_RESET_CODES = /* @__PURE__ */ new Map([
48
- ["22", "1"],
49
- // Bold reset
50
- ["23", "3"],
51
- // Italic reset
52
- ["24", "4"],
53
- // Underline reset
54
- ["27", "7"],
55
- // Inverse reset
56
- ["28", "8"],
57
- // Hidden reset
58
- ["29", "9"]
59
- // Strikethrough reset
60
- ]);
61
- const isForegroundColor = /* @__PURE__ */ __name((code) => code >= "30" && code <= "37" || code >= "90" && code <= "97" || code.startsWith("38;"), "isForegroundColor");
62
- const isBackgroundColor = /* @__PURE__ */ __name((code) => code >= "40" && code <= "47" || code >= "100" && code <= "107" || code.startsWith("48;"), "isBackgroundColor");
63
- const FORMAT_STYLES = [
64
- { close: "\x1B[22m", open: "\x1B[1m" },
65
- // Bold
66
- { close: "\x1B[23m", open: "\x1B[3m" },
67
- // Italic
68
- { close: "\x1B[24m", open: "\x1B[4m" },
69
- // Underline
70
- { close: "\x1B[27m", open: "\x1B[7m" },
71
- // Inverse
72
- { close: "\x1B[28m", open: "\x1B[8m" },
73
- // Hidden
74
- { close: "\x1B[29m", open: "\x1B[9m" }
75
- // Strikethrough
76
- ];
77
- const findFirstPositionOfAny = /* @__PURE__ */ __name((input, substrings) => {
78
- let firstPos = -1;
79
- for (const substring of substrings) {
80
- const pos = input.indexOf(substring);
81
- if (pos >= 0 && (firstPos === -1 || pos < firstPos)) {
82
- firstPos = pos;
83
- }
84
- }
85
- return firstPos;
86
- }, "findFirstPositionOfAny");
87
- const processIntoStyledSegments = /* @__PURE__ */ __name((input, options) => {
88
- if (!input.includes("\x1B")) {
89
- return [
90
- {
91
- after: "",
92
- before: "",
93
- content: input,
94
- visibleLength: getStringWidth.getStringWidth(input, options.width)
95
- }
96
- ];
97
- }
98
- const cachedResult = segmentCache.get(input);
99
- if (cachedResult) {
100
- return cachedResult;
101
- }
102
- const parts = [];
103
- const matches = [];
104
- let lastIndex = 0;
105
- let match;
106
- constants.RE_ANSI.lastIndex = 0;
107
- while ((match = constants.RE_ANSI.exec(input)) !== null) {
108
- const matchedText = match[0];
109
- parts.push(input.slice(lastIndex, match.index));
110
- matches.push(matchedText);
111
- lastIndex = match.index + matchedText.length;
112
- }
113
- if (lastIndex < input.length) {
114
- parts.push(input.slice(lastIndex));
115
- }
116
- const closingSequences = [];
117
- for (const ansi of matches) {
118
- if (ansi === "\x1B[0m" || ansi === "\x1B]8;;\x07") {
119
- closingSequences.push(ansi);
120
- continue;
121
- }
122
- if (ansi.startsWith("\x1B[") && ansi.endsWith("m")) {
123
- const code = ansi.slice(2, -1);
124
- if (ANSI_RESET_CODES.has(code)) {
125
- closingSequences.push(ansi);
126
- continue;
127
- }
128
- }
129
- }
130
- const activeStylesSet = /* @__PURE__ */ new Set();
131
- const segments = [];
132
- for (const [index, text] of parts.entries()) {
133
- if (index > 0 && matches[index - 1]) {
134
- const ansi = matches[index - 1];
135
- if (ansi === "\x1B[0m") {
136
- activeStylesSet.clear();
137
- } else if (ansi === "\x1B]8;;\x07") {
138
- for (const style of activeStylesSet) {
139
- if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
140
- activeStylesSet.delete(style);
141
- break;
142
- }
143
- }
144
- } else if (ansi.startsWith("\x1B[") && ansi.endsWith("m")) {
145
- const code = ansi.slice(2, -1);
146
- if (code === "39") {
147
- for (const style of activeStylesSet) {
148
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
149
- const styleCode = style.slice(2, -1);
150
- if (isForegroundColor(styleCode)) {
151
- activeStylesSet.delete(style);
152
- break;
153
- }
154
- }
155
- }
156
- } else if (code === "49") {
157
- for (const style of activeStylesSet) {
158
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
159
- const styleCode = style.slice(2, -1);
160
- if (isBackgroundColor(styleCode)) {
161
- activeStylesSet.delete(style);
162
- break;
163
- }
164
- }
165
- }
166
- } else if (FORMAT_RESET_CODES.has(code)) {
167
- const targetCode = FORMAT_RESET_CODES.get(code);
168
- for (const style of activeStylesSet) {
169
- if (style === `\x1B[${targetCode}m`) {
170
- activeStylesSet.delete(style);
171
- break;
172
- }
173
- }
174
- } else {
175
- if (isForegroundColor(code)) {
176
- for (const style of activeStylesSet) {
177
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
178
- const styleCode = style.slice(2, -1);
179
- if (isForegroundColor(styleCode)) {
180
- activeStylesSet.delete(style);
181
- break;
182
- }
183
- }
184
- }
185
- } else if (isBackgroundColor(code)) {
186
- for (const style of activeStylesSet) {
187
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
188
- const styleCode = style.slice(2, -1);
189
- if (isBackgroundColor(styleCode)) {
190
- activeStylesSet.delete(style);
191
- break;
192
- }
193
- }
194
- }
195
- } else if (STYLE_CODES.has(code)) {
196
- const targetStyle = `\x1B[${code}m`;
197
- if (activeStylesSet.has(targetStyle)) {
198
- activeStylesSet.delete(targetStyle);
199
- }
200
- }
201
- activeStylesSet.add(ansi);
202
- }
203
- } else if (ansi.startsWith("\x1B]8;;") && !ansi.endsWith("\x1B]8;;\x07")) {
204
- for (const style of activeStylesSet) {
205
- if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
206
- activeStylesSet.delete(style);
207
- break;
208
- }
209
- }
210
- activeStylesSet.add(ansi);
211
- }
212
- }
213
- if (text === "") {
214
- continue;
215
- }
216
- let closingSequence = "";
217
- if (activeStylesSet.size > 0) {
218
- if (closingSequences.includes("\x1B[0m")) {
219
- closingSequence = "\x1B[0m";
220
- } else {
221
- const closingParts = [];
222
- let needsHyperlinkClose = false;
223
- for (const style of activeStylesSet) {
224
- if (style.startsWith("\x1B]8;;") && !style.endsWith("\x1B]8;;\x07")) {
225
- needsHyperlinkClose = true;
226
- break;
227
- }
228
- }
229
- if (needsHyperlinkClose && closingSequences.includes("\x1B]8;;\x07")) {
230
- closingParts.push("\x1B]8;;\x07");
231
- }
232
- let needsForegroundClose = false;
233
- let needsBackgroundClose = false;
234
- for (const style of activeStylesSet) {
235
- if (style.startsWith("\x1B[") && style.endsWith("m")) {
236
- const styleCode = style.slice(2, -1);
237
- if (isForegroundColor(styleCode)) {
238
- needsForegroundClose = true;
239
- } else if (isBackgroundColor(styleCode)) {
240
- needsBackgroundClose = true;
241
- }
242
- }
243
- }
244
- if (needsForegroundClose && needsBackgroundClose) {
245
- const fgOpenPos = findFirstPositionOfAny(input, [
246
- "\x1B[3",
247
- // Basic colors 30-37
248
- "\x1B[9",
249
- // Bright colors 90-97
250
- "\x1B[38;"
251
- // RGB/256 colors
252
- ]);
253
- const bgOpenPos = findFirstPositionOfAny(input, [
254
- "\x1B[4",
255
- // Basic colors 40-47
256
- "\x1B[10",
257
- // Bright colors 100-107
258
- "\x1B[48;"
259
- // RGB/256 colors
260
- ]);
261
- if (fgOpenPos >= 0 && bgOpenPos >= 0) {
262
- if (fgOpenPos > bgOpenPos) {
263
- closingParts.push("\x1B[39m", "\x1B[49m");
264
- } else {
265
- closingParts.push("\x1B[49m", "\x1B[39m");
266
- }
267
- } else {
268
- closingParts.push("\x1B[39m", "\x1B[49m");
269
- }
270
- } else {
271
- if (needsForegroundClose) {
272
- closingParts.push("\x1B[39m");
273
- }
274
- if (needsBackgroundClose) {
275
- closingParts.push("\x1B[49m");
276
- }
277
- }
278
- if (needsForegroundClose && needsBackgroundClose && input.includes("\x1B[39m") && input.includes("\x1B[49m")) {
279
- if (input.indexOf("\x1B[39m") < input.indexOf("\x1B[49m")) {
280
- closingParts.length -= needsForegroundClose && needsBackgroundClose ? 2 : needsForegroundClose || needsBackgroundClose ? 1 : 0;
281
- closingParts.push("\x1B[39m", "\x1B[49m");
282
- } else if (input.indexOf("\x1B[49m") < input.indexOf("\x1B[39m")) {
283
- closingParts.length -= needsForegroundClose && needsBackgroundClose ? 2 : needsForegroundClose || needsBackgroundClose ? 1 : 0;
284
- closingParts.push("\x1B[49m", "\x1B[39m");
285
- }
286
- }
287
- const activeFormatStyles = FORMAT_STYLES.filter((style) => activeStylesSet.has(style.open)).map((style) => {
288
- return {
289
- position: input.indexOf(style.open),
290
- style
291
- };
292
- }).filter((item) => item.position >= 0).sort((a, b) => b.position - a.position);
293
- for (const item of activeFormatStyles) {
294
- if (closingSequences.includes(item.style.close)) {
295
- closingParts.push(item.style.close);
296
- }
297
- }
298
- closingSequence = closingParts.join("");
299
- }
300
- }
301
- const activeStylesString = [...activeStylesSet].join("");
302
- segments.push({
303
- after: closingSequence,
304
- before: activeStylesString,
305
- content: text,
306
- visibleLength: getStringWidth.getStringWidth(text, {
307
- fullWidth: 1,
308
- wideWidth: 1
309
- })
310
- });
311
- }
312
- segmentCache.set(input, segments);
313
- return segments;
314
- }, "processIntoStyledSegments");
315
- const fastSlice = /* @__PURE__ */ __name((inputString, startIndex, endIndex, options) => {
316
- const graphemes = [...options.segmenter.segment(inputString)];
317
- const result = [];
318
- let currentWidth = 0;
319
- let startFound = false;
320
- for (const grapheme of graphemes) {
321
- const graphemeWidth = getStringWidth.getStringWidth(grapheme.segment, options.width);
322
- const positionBefore = currentWidth;
323
- const positionAfter = currentWidth + graphemeWidth;
324
- if (!startFound) {
325
- if (positionBefore < startIndex) {
326
- currentWidth = positionAfter;
327
- continue;
328
- } else {
329
- startFound = true;
330
- }
331
- }
332
- if (positionBefore >= endIndex) {
333
- break;
334
- }
335
- if (positionAfter > endIndex) {
336
- break;
337
- }
338
- result.push(grapheme.segment);
339
- currentWidth = positionAfter;
340
- }
341
- return result.join("");
342
- }, "fastSlice");
343
- const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = Number.MAX_SAFE_INTEGER, options = {}) => {
344
- const config = {
345
- segmenter: defaultSegmenter,
346
- ...options
347
- };
348
- if (startIndex >= endIndex || inputString === "") {
349
- return "";
350
- }
351
- const inputStringWidth = getStringWidth.getStringWidth(inputString, config.width);
352
- if (startIndex === 0 && endIndex >= inputStringWidth) {
353
- return inputString;
354
- }
355
- if (startIndex < 0 || endIndex < 0) {
356
- throw new RangeError("Negative indices aren't supported");
357
- }
358
- if (!inputString.includes("\x1B")) {
359
- if (/^[\u0000-\u007F]*$/.test(inputString)) {
360
- return inputString.slice(startIndex, endIndex);
361
- }
362
- return fastSlice(inputString, startIndex, endIndex, config);
363
- }
364
- constants.RE_VALID_ANSI_PAIRS.lastIndex = 0;
365
- constants.RE_VALID_HYPERLINKS.lastIndex = 0;
366
- if (!constants.RE_VALID_ANSI_PAIRS.test(inputString) && !constants.RE_VALID_HYPERLINKS.test(inputString)) {
367
- return inputString;
368
- }
369
- const segments = processIntoStyledSegments(inputString, config);
370
- if (segments.length === 0) {
371
- return "";
372
- }
373
- let currentPos = 0;
374
- const visibleSegments = [];
375
- for (const [index, segment] of segments.entries()) {
376
- const segmentStart = currentPos;
377
- const segmentEnd = currentPos + segment.visibleLength;
378
- if (segmentEnd > startIndex && segmentStart < endIndex) {
379
- const visibleStart = Math.max(0, startIndex - segmentStart);
380
- const visibleEnd = Math.min(segment.visibleLength, endIndex - segmentStart);
381
- visibleSegments.push({
382
- end: visibleEnd,
383
- index,
384
- segment,
385
- start: visibleStart
386
- });
387
- }
388
- currentPos = segmentEnd;
389
- }
390
- if (visibleSegments.length === 0) {
391
- return "";
392
- }
393
- const resultParts = [];
394
- const firstSegment = visibleSegments[0].segment;
395
- resultParts.push(firstSegment.before);
396
- for (let index = 0; index < visibleSegments.length; index++) {
397
- const { end, segment, start } = visibleSegments[index];
398
- if (start === 0 && end === segment.visibleLength) {
399
- resultParts.push(segment.content);
400
- } else {
401
- const graphemes = [...config.segmenter.segment(segment.content)];
402
- resultParts.push(
403
- graphemes.slice(start, end).map((entry) => entry.segment).join("")
404
- );
405
- }
406
- if (index < visibleSegments.length - 1) {
407
- const nextSegment = visibleSegments[index + 1].segment;
408
- const segmentAfter = segment.after;
409
- const nextBefore = nextSegment.before;
410
- if (segmentAfter !== nextBefore && (segmentAfter || nextBefore)) {
411
- resultParts.push(segmentAfter, nextBefore);
412
- }
413
- }
414
- }
415
- resultParts.push(visibleSegments.at(-1).segment.after);
416
- return resultParts.join("");
417
- }, "slice");
418
-
419
- exports.slice = slice;
1
+ "use strict";var I=Object.defineProperty;var O=(t,f)=>I(t,"name",{value:f,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const b=require("./packem_shared/constants-D3K8u3G8.cjs"),k=require("./get-string-width.cjs"),F=require("./packem_shared/LRUCache-TYqfUYE5.cjs");var _=Object.defineProperty,S=O((t,f)=>_(t,"name",{value:f,configurable:!0}),"y");const y=new F(100),E=new Intl.Segmenter("en",{granularity:"grapheme"}),N=new Set(["0","22","23","24","27","28","29","39","49"]),P=new Set(["1","3","4","7","8","9"]),j=new Map([["22","1"],["23","3"],["24","4"],["27","7"],["28","8"],["29","9"]]),v=S(t=>t>="30"&&t<="37"||t>="90"&&t<="97"||t.startsWith("38;"),"isForegroundColor"),w=S(t=>t>="40"&&t<="47"||t>="100"&&t<="107"||t.startsWith("48;"),"isBackgroundColor"),R=[{close:"\x1B[22m",open:"\x1B[1m"},{close:"\x1B[23m",open:"\x1B[3m"},{close:"\x1B[24m",open:"\x1B[4m"},{close:"\x1B[27m",open:"\x1B[7m"},{close:"\x1B[28m",open:"\x1B[8m"},{close:"\x1B[29m",open:"\x1B[9m"}],L=S((t,f)=>{let l=-1;for(const d of f){const h=t.indexOf(d);h>=0&&(l===-1||h<l)&&(l=h)}return l},"findFirstPositionOfAny"),q=S((t,f)=>{if(!t.includes("\x1B"))return[{after:"",before:"",content:t,visibleLength:k.getStringWidth(t,f.width)}];const l=y.get(t);if(l)return l;const d=[],h=[];let p=0,a;for(b.c.lastIndex=0;(a=b.c.exec(t))!==null;){const c=a[0];d.push(t.slice(p,a.index)),h.push(c),p=a.index+c.length}p<t.length&&d.push(t.slice(p));const m=[];for(const c of h){if(c==="\x1B[0m"||c==="\x1B]8;;\x07"){m.push(c);continue}if(c.startsWith("\x1B[")&&c.endsWith("m")){const x=c.slice(2,-1);if(N.has(x)){m.push(c);continue}}}const s=new Set,B=[];for(const[c,x]of d.entries()){if(c>0&&h[c-1]){const n=h[c-1];if(n==="\x1B[0m")s.clear();else if(n==="\x1B]8;;\x07"){for(const i of s)if(i.startsWith("\x1B]8;;")&&!i.endsWith("\x1B]8;;\x07")){s.delete(i);break}}else if(n.startsWith("\x1B[")&&n.endsWith("m")){const i=n.slice(2,-1);if(i==="39"){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const o=e.slice(2,-1);if(v(o)){s.delete(e);break}}}else if(i==="49"){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const o=e.slice(2,-1);if(w(o)){s.delete(e);break}}}else if(j.has(i)){const e=j.get(i);for(const o of s)if(o===`\x1B[${e}m`){s.delete(o);break}}else{if(v(i)){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const o=e.slice(2,-1);if(v(o)){s.delete(e);break}}}else if(w(i)){for(const e of s)if(e.startsWith("\x1B[")&&e.endsWith("m")){const o=e.slice(2,-1);if(w(o)){s.delete(e);break}}}else if(P.has(i)){const e=`\x1B[${i}m`;s.has(e)&&s.delete(e)}s.add(n)}}else if(n.startsWith("\x1B]8;;")&&!n.endsWith("\x1B]8;;\x07")){for(const i of s)if(i.startsWith("\x1B]8;;")&&!i.endsWith("\x1B]8;;\x07")){s.delete(i);break}s.add(n)}}if(x==="")continue;let u="";if(s.size>0)if(m.includes("\x1B[0m"))u="\x1B[0m";else{const n=[];let i=!1;for(const r of s)if(r.startsWith("\x1B]8;;")&&!r.endsWith("\x1B]8;;\x07")){i=!0;break}i&&m.includes("\x1B]8;;\x07")&&n.push("\x1B]8;;\x07");let e=!1,o=!1;for(const r of s)if(r.startsWith("\x1B[")&&r.endsWith("m")){const W=r.slice(2,-1);v(W)?e=!0:w(W)&&(o=!0)}if(e&&o){const r=L(t,["\x1B[3","\x1B[9","\x1B[38;"]),W=L(t,["\x1B[4","\x1B[10","\x1B[48;"]);r>=0&&W>=0?r>W?n.push("\x1B[39m","\x1B[49m"):n.push("\x1B[49m","\x1B[39m"):n.push("\x1B[39m","\x1B[49m")}else e&&n.push("\x1B[39m"),o&&n.push("\x1B[49m");e&&o&&t.includes("\x1B[39m")&&t.includes("\x1B[49m")&&(t.indexOf("\x1B[39m")<t.indexOf("\x1B[49m")?(n.length-=e&&o?2:e||o?1:0,n.push("\x1B[39m","\x1B[49m")):t.indexOf("\x1B[49m")<t.indexOf("\x1B[39m")&&(n.length-=e&&o?2:e||o?1:0,n.push("\x1B[49m","\x1B[39m")));const M=R.filter(r=>s.has(r.open)).map(r=>({position:t.indexOf(r.open),style:r})).filter(r=>r.position>=0).sort((r,W)=>W.position-r.position);for(const r of M)m.includes(r.style.close)&&n.push(r.style.close);u=n.join("")}const g=[...s].join("");B.push({after:u,before:g,content:x,visibleLength:k.getStringWidth(x,{fullWidth:1,wideWidth:1})})}return y.set(t,B),B},"processIntoStyledSegments"),A=S((t,f,l,d)=>{const h=[...d.segmenter.segment(t)],p=[];let a=0,m=!1;for(const s of h){const B=k.getStringWidth(s.segment,d.width),c=a,x=a+B;if(!m)if(c<f){a=x;continue}else m=!0;if(c>=l||x>l)break;p.push(s.segment),a=x}return p.join("")},"fastSlice"),C=S((t,f=0,l=Number.MAX_SAFE_INTEGER,d={})=>{const h={segmenter:E,...d};if(f>=l||t==="")return"";const p=k.getStringWidth(t,h.width);if(f===0&&l>=p)return t;if(f<0||l<0)throw new RangeError("Negative indices aren't supported");if(!t.includes("\x1B"))return/^[\u0000-\u007F]*$/.test(t)?t.slice(f,l):A(t,f,l,h);if(b.a.lastIndex=0,b.b.lastIndex=0,!b.a.test(t)&&!b.b.test(t))return t;const a=q(t,h);if(a.length===0)return"";let m=0;const s=[];for(const[x,u]of a.entries()){const g=m,n=m+u.visibleLength;if(n>f&&g<l){const i=Math.max(0,f-g),e=Math.min(u.visibleLength,l-g);s.push({end:e,index:x,segment:u,start:i})}m=n}if(s.length===0)return"";const B=[],c=s[0].segment;B.push(c.before);for(let x=0;x<s.length;x++){const{end:u,segment:g,start:n}=s[x];if(n===0&&u===g.visibleLength)B.push(g.content);else{const i=[...h.segmenter.segment(g.content)];B.push(i.slice(n,u).map(e=>e.segment).join(""))}if(x<s.length-1){const i=s[x+1].segment,e=g.after,o=i.before;e!==o&&(e||o)&&B.push(e,o)}}return B.push(s.at(-1).segment.after),B.join("")},"slice");exports.slice=C;
package/dist/slice.d.cts CHANGED
@@ -7,4 +7,5 @@ type SliceOptions = {
7
7
  };
8
8
  declare const slice: (inputString: string, startIndex?: number, endIndex?: number, options?: SliceOptions) => string;
9
9
 
10
- export { type SliceOptions, slice };
10
+ export { slice };
11
+ export type { SliceOptions };
package/dist/slice.d.mts CHANGED
@@ -7,4 +7,5 @@ type SliceOptions = {
7
7
  };
8
8
  declare const slice: (inputString: string, startIndex?: number, endIndex?: number, options?: SliceOptions) => string;
9
9
 
10
- export { type SliceOptions, slice };
10
+ export { slice };
11
+ export type { SliceOptions };
package/dist/slice.d.ts CHANGED
@@ -7,4 +7,5 @@ type SliceOptions = {
7
7
  };
8
8
  declare const slice: (inputString: string, startIndex?: number, endIndex?: number, options?: SliceOptions) => string;
9
9
 
10
- export { type SliceOptions, slice };
10
+ export { slice };
11
+ export type { SliceOptions };