@hypercli/ui 0.1.1

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 (267) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/capabilities/index.d.ts +62 -0
  4. package/dist/capabilities/index.d.ts.map +1 -0
  5. package/dist/capabilities/index.js +182 -0
  6. package/dist/capabilities/index.js.map +1 -0
  7. package/dist/colors.d.ts +32 -0
  8. package/dist/colors.d.ts.map +1 -0
  9. package/dist/colors.js +40 -0
  10. package/dist/colors.js.map +1 -0
  11. package/dist/components/columns.d.ts +28 -0
  12. package/dist/components/columns.d.ts.map +1 -0
  13. package/dist/components/columns.js +70 -0
  14. package/dist/components/columns.js.map +1 -0
  15. package/dist/components/confirmPrompt.d.ts +38 -0
  16. package/dist/components/confirmPrompt.d.ts.map +1 -0
  17. package/dist/components/confirmPrompt.js +109 -0
  18. package/dist/components/confirmPrompt.js.map +1 -0
  19. package/dist/components/diff.d.ts +37 -0
  20. package/dist/components/diff.d.ts.map +1 -0
  21. package/dist/components/diff.js +36 -0
  22. package/dist/components/diff.js.map +1 -0
  23. package/dist/components/helpLayout.d.ts +59 -0
  24. package/dist/components/helpLayout.d.ts.map +1 -0
  25. package/dist/components/helpLayout.js +103 -0
  26. package/dist/components/helpLayout.js.map +1 -0
  27. package/dist/components/index.d.ts +38 -0
  28. package/dist/components/index.d.ts.map +1 -0
  29. package/dist/components/index.js +23 -0
  30. package/dist/components/index.js.map +1 -0
  31. package/dist/components/keyValue.d.ts +31 -0
  32. package/dist/components/keyValue.d.ts.map +1 -0
  33. package/dist/components/keyValue.js +36 -0
  34. package/dist/components/keyValue.js.map +1 -0
  35. package/dist/components/list.d.ts +30 -0
  36. package/dist/components/list.d.ts.map +1 -0
  37. package/dist/components/list.js +80 -0
  38. package/dist/components/list.js.map +1 -0
  39. package/dist/components/message.d.ts +33 -0
  40. package/dist/components/message.d.ts.map +1 -0
  41. package/dist/components/message.js +86 -0
  42. package/dist/components/message.js.map +1 -0
  43. package/dist/components/panel.d.ts +28 -0
  44. package/dist/components/panel.d.ts.map +1 -0
  45. package/dist/components/panel.js +30 -0
  46. package/dist/components/panel.js.map +1 -0
  47. package/dist/components/progressBar.d.ts +44 -0
  48. package/dist/components/progressBar.d.ts.map +1 -0
  49. package/dist/components/progressBar.js +154 -0
  50. package/dist/components/progressBar.js.map +1 -0
  51. package/dist/components/section.d.ts +22 -0
  52. package/dist/components/section.d.ts.map +1 -0
  53. package/dist/components/section.js +48 -0
  54. package/dist/components/section.js.map +1 -0
  55. package/dist/components/selectPrompt.d.ts +58 -0
  56. package/dist/components/selectPrompt.d.ts.map +1 -0
  57. package/dist/components/selectPrompt.js +206 -0
  58. package/dist/components/selectPrompt.js.map +1 -0
  59. package/dist/components/spinner.d.ts +38 -0
  60. package/dist/components/spinner.d.ts.map +1 -0
  61. package/dist/components/spinner.js +125 -0
  62. package/dist/components/spinner.js.map +1 -0
  63. package/dist/components/statusList.d.ts +22 -0
  64. package/dist/components/statusList.d.ts.map +1 -0
  65. package/dist/components/statusList.js +43 -0
  66. package/dist/components/statusList.js.map +1 -0
  67. package/dist/components/table.d.ts +39 -0
  68. package/dist/components/table.d.ts.map +1 -0
  69. package/dist/components/table.js +132 -0
  70. package/dist/components/table.js.map +1 -0
  71. package/dist/components/textPrompt.d.ts +43 -0
  72. package/dist/components/textPrompt.d.ts.map +1 -0
  73. package/dist/components/textPrompt.js +123 -0
  74. package/dist/components/textPrompt.js.map +1 -0
  75. package/dist/components/tree.d.ts +30 -0
  76. package/dist/components/tree.d.ts.map +1 -0
  77. package/dist/components/tree.js +49 -0
  78. package/dist/components/tree.js.map +1 -0
  79. package/dist/ds-index.d.ts +113 -0
  80. package/dist/ds-index.d.ts.map +1 -0
  81. package/dist/ds-index.js +112 -0
  82. package/dist/ds-index.js.map +1 -0
  83. package/dist/help.d.ts +32 -0
  84. package/dist/help.d.ts.map +1 -0
  85. package/dist/help.js +34 -0
  86. package/dist/help.js.map +1 -0
  87. package/dist/hyper-theme.d.ts +8 -0
  88. package/dist/hyper-theme.d.ts.map +1 -0
  89. package/dist/hyper-theme.js +30 -0
  90. package/dist/hyper-theme.js.map +1 -0
  91. package/dist/index.d.ts +50 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +39 -0
  94. package/dist/index.js.map +1 -0
  95. package/dist/md.d.ts +12 -0
  96. package/dist/md.d.ts.map +1 -0
  97. package/dist/md.js +19 -0
  98. package/dist/md.js.map +1 -0
  99. package/dist/messages.d.ts +20 -0
  100. package/dist/messages.d.ts.map +1 -0
  101. package/dist/messages.js +65 -0
  102. package/dist/messages.js.map +1 -0
  103. package/dist/palette.d.ts +20 -0
  104. package/dist/palette.d.ts.map +1 -0
  105. package/dist/palette.js +22 -0
  106. package/dist/palette.js.map +1 -0
  107. package/dist/primitives/align.d.ts +23 -0
  108. package/dist/primitives/align.d.ts.map +1 -0
  109. package/dist/primitives/align.js +40 -0
  110. package/dist/primitives/align.js.map +1 -0
  111. package/dist/primitives/badge.d.ts +24 -0
  112. package/dist/primitives/badge.d.ts.map +1 -0
  113. package/dist/primitives/badge.js +40 -0
  114. package/dist/primitives/badge.js.map +1 -0
  115. package/dist/primitives/border.d.ts +29 -0
  116. package/dist/primitives/border.d.ts.map +1 -0
  117. package/dist/primitives/border.js +100 -0
  118. package/dist/primitives/border.js.map +1 -0
  119. package/dist/primitives/context.d.ts +48 -0
  120. package/dist/primitives/context.d.ts.map +1 -0
  121. package/dist/primitives/context.js +64 -0
  122. package/dist/primitives/context.js.map +1 -0
  123. package/dist/primitives/divider.d.ts +25 -0
  124. package/dist/primitives/divider.d.ts.map +1 -0
  125. package/dist/primitives/divider.js +56 -0
  126. package/dist/primitives/divider.js.map +1 -0
  127. package/dist/primitives/indent.d.ts +16 -0
  128. package/dist/primitives/indent.d.ts.map +1 -0
  129. package/dist/primitives/indent.js +25 -0
  130. package/dist/primitives/indent.js.map +1 -0
  131. package/dist/primitives/index.d.ts +32 -0
  132. package/dist/primitives/index.d.ts.map +1 -0
  133. package/dist/primitives/index.js +22 -0
  134. package/dist/primitives/index.js.map +1 -0
  135. package/dist/primitives/line.d.ts +21 -0
  136. package/dist/primitives/line.d.ts.map +1 -0
  137. package/dist/primitives/line.js +29 -0
  138. package/dist/primitives/line.js.map +1 -0
  139. package/dist/primitives/markdown.d.ts +91 -0
  140. package/dist/primitives/markdown.d.ts.map +1 -0
  141. package/dist/primitives/markdown.js +62 -0
  142. package/dist/primitives/markdown.js.map +1 -0
  143. package/dist/primitives/pad.d.ts +24 -0
  144. package/dist/primitives/pad.d.ts.map +1 -0
  145. package/dist/primitives/pad.js +20 -0
  146. package/dist/primitives/pad.js.map +1 -0
  147. package/dist/primitives/stack.d.ts +22 -0
  148. package/dist/primitives/stack.d.ts.map +1 -0
  149. package/dist/primitives/stack.js +21 -0
  150. package/dist/primitives/stack.js.map +1 -0
  151. package/dist/primitives/styledText.d.ts +36 -0
  152. package/dist/primitives/styledText.d.ts.map +1 -0
  153. package/dist/primitives/styledText.js +42 -0
  154. package/dist/primitives/styledText.js.map +1 -0
  155. package/dist/primitives/symbol.d.ts +15 -0
  156. package/dist/primitives/symbol.d.ts.map +1 -0
  157. package/dist/primitives/symbol.js +18 -0
  158. package/dist/primitives/symbol.js.map +1 -0
  159. package/dist/primitives/truncate.d.ts +23 -0
  160. package/dist/primitives/truncate.d.ts.map +1 -0
  161. package/dist/primitives/truncate.js +99 -0
  162. package/dist/primitives/truncate.js.map +1 -0
  163. package/dist/primitives/wrap.d.ts +23 -0
  164. package/dist/primitives/wrap.d.ts.map +1 -0
  165. package/dist/primitives/wrap.js +30 -0
  166. package/dist/primitives/wrap.js.map +1 -0
  167. package/dist/render/ansi-utils.d.ts +49 -0
  168. package/dist/render/ansi-utils.d.ts.map +1 -0
  169. package/dist/render/ansi-utils.js +405 -0
  170. package/dist/render/ansi-utils.js.map +1 -0
  171. package/dist/render/index.d.ts +11 -0
  172. package/dist/render/index.d.ts.map +1 -0
  173. package/dist/render/index.js +11 -0
  174. package/dist/render/index.js.map +1 -0
  175. package/dist/render/sgr.d.ts +60 -0
  176. package/dist/render/sgr.d.ts.map +1 -0
  177. package/dist/render/sgr.js +191 -0
  178. package/dist/render/sgr.js.map +1 -0
  179. package/dist/render/strip.d.ts +24 -0
  180. package/dist/render/strip.d.ts.map +1 -0
  181. package/dist/render/strip.js +81 -0
  182. package/dist/render/strip.js.map +1 -0
  183. package/dist/render/width.d.ts +30 -0
  184. package/dist/render/width.d.ts.map +1 -0
  185. package/dist/render/width.js +149 -0
  186. package/dist/render/width.js.map +1 -0
  187. package/dist/shortcuts.d.ts +76 -0
  188. package/dist/shortcuts.d.ts.map +1 -0
  189. package/dist/shortcuts.js +117 -0
  190. package/dist/shortcuts.js.map +1 -0
  191. package/dist/styles.d.ts +43 -0
  192. package/dist/styles.d.ts.map +1 -0
  193. package/dist/styles.js +44 -0
  194. package/dist/styles.js.map +1 -0
  195. package/dist/symbols.d.ts +19 -0
  196. package/dist/symbols.d.ts.map +1 -0
  197. package/dist/symbols.js +21 -0
  198. package/dist/symbols.js.map +1 -0
  199. package/dist/test/compare.d.ts +28 -0
  200. package/dist/test/compare.d.ts.map +1 -0
  201. package/dist/test/compare.js +37 -0
  202. package/dist/test/compare.js.map +1 -0
  203. package/dist/test/index.d.ts +16 -0
  204. package/dist/test/index.d.ts.map +1 -0
  205. package/dist/test/index.js +14 -0
  206. package/dist/test/index.js.map +1 -0
  207. package/dist/test/mock.d.ts +50 -0
  208. package/dist/test/mock.d.ts.map +1 -0
  209. package/dist/test/mock.js +135 -0
  210. package/dist/test/mock.js.map +1 -0
  211. package/dist/test/render.d.ts +29 -0
  212. package/dist/test/render.d.ts.map +1 -0
  213. package/dist/test/render.js +87 -0
  214. package/dist/test/render.js.map +1 -0
  215. package/dist/test/snapshot.d.ts +16 -0
  216. package/dist/test/snapshot.d.ts.map +1 -0
  217. package/dist/test/snapshot.js +216 -0
  218. package/dist/test/snapshot.js.map +1 -0
  219. package/dist/theme/builtins.d.ts +10 -0
  220. package/dist/theme/builtins.d.ts.map +1 -0
  221. package/dist/theme/builtins.js +102 -0
  222. package/dist/theme/builtins.js.map +1 -0
  223. package/dist/theme/engine.d.ts +51 -0
  224. package/dist/theme/engine.d.ts.map +1 -0
  225. package/dist/theme/engine.js +123 -0
  226. package/dist/theme/engine.js.map +1 -0
  227. package/dist/theme/index.d.ts +10 -0
  228. package/dist/theme/index.d.ts.map +1 -0
  229. package/dist/theme/index.js +12 -0
  230. package/dist/theme/index.js.map +1 -0
  231. package/dist/theme/merge.d.ts +24 -0
  232. package/dist/theme/merge.d.ts.map +1 -0
  233. package/dist/theme/merge.js +66 -0
  234. package/dist/theme/merge.js.map +1 -0
  235. package/dist/theme/types.d.ts +44 -0
  236. package/dist/theme/types.d.ts.map +1 -0
  237. package/dist/theme/types.js +8 -0
  238. package/dist/theme/types.js.map +1 -0
  239. package/dist/theme.d.ts +9 -0
  240. package/dist/theme.d.ts.map +1 -0
  241. package/dist/theme.js +53 -0
  242. package/dist/theme.js.map +1 -0
  243. package/dist/tokens/defaults.d.ts +13 -0
  244. package/dist/tokens/defaults.d.ts.map +1 -0
  245. package/dist/tokens/defaults.js +248 -0
  246. package/dist/tokens/defaults.js.map +1 -0
  247. package/dist/tokens/index.d.ts +10 -0
  248. package/dist/tokens/index.d.ts.map +1 -0
  249. package/dist/tokens/index.js +10 -0
  250. package/dist/tokens/index.js.map +1 -0
  251. package/dist/tokens/resolver.d.ts +100 -0
  252. package/dist/tokens/resolver.d.ts.map +1 -0
  253. package/dist/tokens/resolver.js +138 -0
  254. package/dist/tokens/resolver.js.map +1 -0
  255. package/dist/tokens/types.d.ts +265 -0
  256. package/dist/tokens/types.d.ts.map +1 -0
  257. package/dist/tokens/types.js +10 -0
  258. package/dist/tokens/types.js.map +1 -0
  259. package/dist/tokens.d.ts +26 -0
  260. package/dist/tokens.d.ts.map +1 -0
  261. package/dist/tokens.js +30 -0
  262. package/dist/tokens.js.map +1 -0
  263. package/dist/types.d.ts +38 -0
  264. package/dist/types.d.ts.map +1 -0
  265. package/dist/types.js +11 -0
  266. package/dist/types.js.map +1 -0
  267. package/package.json +78 -0
@@ -0,0 +1,191 @@
1
+ /**
2
+ * SGR (Select Graphic Rendition) Code Generation
3
+ *
4
+ * Maps style specifications to ANSI escape sequences for terminal styling.
5
+ * Supports 16-color names, 256-color indices, and truecolor hex values.
6
+ */
7
+ // ANSI 16 foreground color codes
8
+ const ANSI_FG = {
9
+ black: 30,
10
+ red: 31,
11
+ green: 32,
12
+ yellow: 33,
13
+ blue: 34,
14
+ magenta: 35,
15
+ cyan: 36,
16
+ white: 37,
17
+ };
18
+ // ANSI 16 background color codes
19
+ const ANSI_BG = {
20
+ black: 40,
21
+ red: 41,
22
+ green: 42,
23
+ yellow: 43,
24
+ blue: 44,
25
+ magenta: 45,
26
+ cyan: 46,
27
+ white: 47,
28
+ };
29
+ // SGR attribute enable codes
30
+ const SGR_ATTR = {
31
+ bold: 1,
32
+ dim: 2,
33
+ italic: 3,
34
+ underline: 4,
35
+ inverse: 7,
36
+ strikethrough: 9,
37
+ };
38
+ // SGR attribute reset codes
39
+ const SGR_RESET = {
40
+ bold: 22,
41
+ dim: 22,
42
+ italic: 23,
43
+ underline: 24,
44
+ inverse: 27,
45
+ strikethrough: 29,
46
+ fg: 39,
47
+ bg: 49,
48
+ };
49
+ const ATTR_NAMES = ["bold", "dim", "italic", "underline", "strikethrough", "inverse"];
50
+ /**
51
+ * Parse a hex color string (`#RGB` or `#RRGGBB`) into an RGB tuple.
52
+ *
53
+ * @param hex - Hex color string starting with `#`.
54
+ * @returns RGB tuple of numeric values `[R, G, B]`.
55
+ */
56
+ function parseHex(hex) {
57
+ const h = hex.slice(1);
58
+ if (h.length === 3) {
59
+ const r = Number.parseInt(h[0] + h[0], 16);
60
+ const g = Number.parseInt(h[1] + h[1], 16);
61
+ const b = Number.parseInt(h[2] + h[2], 16);
62
+ return [r, g, b];
63
+ }
64
+ const r = Number.parseInt(h.slice(0, 2), 16);
65
+ const g = Number.parseInt(h.slice(2, 4), 16);
66
+ const b = Number.parseInt(h.slice(4, 6), 16);
67
+ return [r, g, b];
68
+ }
69
+ /**
70
+ * Generate SGR parameter strings for a color value.
71
+ *
72
+ * Handles named ANSI-16 colors, 256-color numeric indices, truecolor hex,
73
+ * and the special `"bold"`/`"dim"` attribute-as-color values.
74
+ *
75
+ * @param value - The color value string (name, numeric index, or `#hex`).
76
+ * @param isBg - Whether the color is for the background (uses code 48) rather than foreground (38).
77
+ * @returns Array of SGR parameter strings (may be compound, e.g. `"38;2;255;0;0"`). Empty if unrecognized.
78
+ */
79
+ function colorCodes(value, isBg) {
80
+ // 'bold' and 'dim' are attributes, not colors
81
+ if (value === "bold" || value === "dim") {
82
+ return [String(SGR_ATTR[value])];
83
+ }
84
+ if (value.startsWith("#")) {
85
+ const [r, g, b] = parseHex(value);
86
+ const prefix = isBg ? 48 : 38;
87
+ return [`${prefix};2;${r};${g};${b}`];
88
+ }
89
+ // Numeric string → 256-color
90
+ if (/^\d+$/.test(value)) {
91
+ const prefix = isBg ? 48 : 38;
92
+ return [`${prefix};5;${value}`];
93
+ }
94
+ // Named ANSI 16 color
95
+ const table = isBg ? ANSI_BG : ANSI_FG;
96
+ const code = table[value];
97
+ if (code !== undefined) {
98
+ return [String(code)];
99
+ }
100
+ return [];
101
+ }
102
+ /**
103
+ * Generate the opening SGR escape sequence for a style spec.
104
+ *
105
+ * Combines all attribute and color codes into a single sequence (e.g. `\x1b[1;31;4m`).
106
+ *
107
+ * @param style - The style specification to encode.
108
+ * @returns The opening ANSI escape sequence, or an empty string if no styles are set.
109
+ */
110
+ export function sgrOpen(style) {
111
+ const codes = [];
112
+ // Attributes
113
+ for (const attr of ATTR_NAMES) {
114
+ if (style[attr]) {
115
+ codes.push(String(SGR_ATTR[attr]));
116
+ }
117
+ }
118
+ // Foreground color
119
+ if (style.color != null && style.color !== "") {
120
+ codes.push(...colorCodes(style.color, false));
121
+ }
122
+ // Background color
123
+ if (style.bg != null && style.bg !== "") {
124
+ codes.push(...colorCodes(style.bg, true));
125
+ }
126
+ if (codes.length === 0)
127
+ return "";
128
+ return `\x1b[${codes.join(";")}m`;
129
+ }
130
+ /**
131
+ * Generate the closing SGR escape sequence that resets only the attributes
132
+ * set in the given style spec.
133
+ *
134
+ * Uses targeted reset codes (e.g. `22` for bold/dim, `39` for fg) rather
135
+ * than a full `\x1b[0m` reset, so surrounding styles are not disturbed.
136
+ *
137
+ * @param style - The style specification whose attributes should be reset.
138
+ * @returns The closing ANSI escape sequence, or an empty string if no styles were set.
139
+ */
140
+ export function sgrClose(style) {
141
+ const codes = [];
142
+ for (const attr of ATTR_NAMES) {
143
+ if (style[attr]) {
144
+ const resetCode = SGR_RESET[attr];
145
+ // Avoid duplicates (bold and dim share reset code 22)
146
+ if (!codes.includes(resetCode)) {
147
+ codes.push(resetCode);
148
+ }
149
+ }
150
+ }
151
+ // If color was set via 'bold'/'dim' as a color value, reset that attribute
152
+ if (style.color != null && style.color !== "") {
153
+ if (style.color === "bold" || style.color === "dim") {
154
+ const resetCode = SGR_RESET[style.color];
155
+ if (!codes.includes(resetCode)) {
156
+ codes.push(resetCode);
157
+ }
158
+ }
159
+ else {
160
+ codes.push(SGR_RESET.fg);
161
+ }
162
+ }
163
+ if (style.bg != null && style.bg !== "") {
164
+ if (style.bg === "bold" || style.bg === "dim") {
165
+ const resetCode = SGR_RESET[style.bg];
166
+ if (!codes.includes(resetCode)) {
167
+ codes.push(resetCode);
168
+ }
169
+ }
170
+ else {
171
+ codes.push(SGR_RESET.bg);
172
+ }
173
+ }
174
+ if (codes.length === 0)
175
+ return "";
176
+ return `\x1b[${codes.join(";")}m`;
177
+ }
178
+ /**
179
+ * Apply a style to text by wrapping it with the appropriate opening
180
+ * and closing SGR escape sequences.
181
+ *
182
+ * @param text - The text to style.
183
+ * @param style - The style specification to apply.
184
+ * @returns The text wrapped in ANSI escape sequences.
185
+ */
186
+ export function applyStyle(text, style) {
187
+ const open = sgrOpen(style);
188
+ const close = sgrClose(style);
189
+ return `${open}${text}${close}`;
190
+ }
191
+ //# sourceMappingURL=sgr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sgr.js","sourceRoot":"","sources":["../../src/render/sgr.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2BH,iCAAiC;AACjC,MAAM,OAAO,GAA2B;IACvC,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,EAAE;IACP,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,EAAE;CACT,CAAC;AAEF,iCAAiC;AACjC,MAAM,OAAO,GAA2B;IACvC,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,EAAE;IACP,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,EAAE;CACT,CAAC;AAEF,6BAA6B;AAC7B,MAAM,QAAQ,GAA2B;IACxC,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC;IACV,aAAa,EAAE,CAAC;CAChB,CAAC;AAEF,4BAA4B;AAC5B,MAAM,SAAS,GAA2B;IACzC,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE;IACP,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,EAAE;IACb,OAAO,EAAE,EAAE;IACX,aAAa,EAAE,EAAE;IACjB,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;CACN,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,CAAU,CAAC;AAE/F;;;;;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YAC1C,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAChC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACvB,CAAC;QACF,CAAC;aAAM,CAAC;YACP,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAG,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,IAAI,IAAI,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACzC,IAAI,KAAK,CAAC,EAAE,KAAK,MAAM,IAAI,KAAK,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;YAC/C,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,CAAE,CAAC;YACvC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAChC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACvB,CAAC;QACF,CAAC;aAAM,CAAC;YACP,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAG,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,OAAO,QAAQ,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AACnC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,KAAgB;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * ANSI Escape Sequence Stripping
3
+ *
4
+ * Functions to remove ANSI escape sequences from strings, either fully
5
+ * (for plain text output) or selectively (preserving typography for NO_COLOR mode).
6
+ */
7
+ /**
8
+ * Strips ALL ANSI escape sequences from a string, returning plain text.
9
+ *
10
+ * @param str - The string to strip.
11
+ * @returns The plain text with no ANSI codes.
12
+ */
13
+ export declare function stripAnsi(str: string): string;
14
+ /**
15
+ * Strips only color codes from ANSI escape sequences, preserving typography
16
+ * attributes (bold, dim, italic, underline, strikethrough, inverse and their resets).
17
+ *
18
+ * Implements NO_COLOR mode: text styling is preserved but all hue information is removed.
19
+ *
20
+ * @param str - The string to strip color codes from.
21
+ * @returns The string with color codes removed but typography preserved.
22
+ */
23
+ export declare function stripColor(str: string): string;
24
+ //# sourceMappingURL=strip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../../src/render/strip.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAUD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiD9C"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * ANSI Escape Sequence Stripping
3
+ *
4
+ * Functions to remove ANSI escape sequences from strings, either fully
5
+ * (for plain text output) or selectively (preserving typography for NO_COLOR mode).
6
+ */
7
+ /** Matches SGR (Select Graphic Rendition) escape sequences only. */
8
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape detection requires control characters
9
+ const ANSI_REGEX = /\x1b\[[0-9;]*m/g;
10
+ /** Matches all ANSI escape sequences (SGR, cursor movement, etc.). */
11
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape detection requires control characters
12
+ const ALL_ANSI_REGEX = /\x1b\[[0-9;]*[A-Za-z]/g;
13
+ /**
14
+ * Strips ALL ANSI escape sequences from a string, returning plain text.
15
+ *
16
+ * @param str - The string to strip.
17
+ * @returns The plain text with no ANSI codes.
18
+ */
19
+ export function stripAnsi(str) {
20
+ return str.replace(ALL_ANSI_REGEX, "");
21
+ }
22
+ /**
23
+ * Returns true if the SGR code number is a color-related code.
24
+ * Color codes: 30-37, 38, 39, 40-47, 48, 49, 90-97, 100-107
25
+ */
26
+ function isColorCode(code) {
27
+ return (code >= 30 && code <= 49) || (code >= 90 && code <= 97) || (code >= 100 && code <= 107);
28
+ }
29
+ /**
30
+ * Strips only color codes from ANSI escape sequences, preserving typography
31
+ * attributes (bold, dim, italic, underline, strikethrough, inverse and their resets).
32
+ *
33
+ * Implements NO_COLOR mode: text styling is preserved but all hue information is removed.
34
+ *
35
+ * @param str - The string to strip color codes from.
36
+ * @returns The string with color codes removed but typography preserved.
37
+ */
38
+ export function stripColor(str) {
39
+ return str.replace(ANSI_REGEX, (match) => {
40
+ // Extract the parameter portion between \x1b[ and m
41
+ const params = match.slice(2, -1);
42
+ if (params === "" || params === "0") {
43
+ // Full reset — keep it as-is since it resets attributes too
44
+ return match;
45
+ }
46
+ const parts = params.split(";");
47
+ const kept = [];
48
+ for (let i = 0; i < parts.length; i++) {
49
+ const code = Number.parseInt(parts[i], 10);
50
+ if (Number.isNaN(code)) {
51
+ kept.push(parts[i]);
52
+ continue;
53
+ }
54
+ // Extended color sequences: 38;5;N or 38;2;R;G;B (and 48 for bg)
55
+ if (code === 38 || code === 48) {
56
+ const next = parts[i + 1];
57
+ if (next === "5") {
58
+ // 256-color: skip code;5;N (3 parts)
59
+ i += 2;
60
+ continue;
61
+ }
62
+ if (next === "2") {
63
+ // Truecolor: skip code;2;R;G;B (5 parts)
64
+ i += 4;
65
+ continue;
66
+ }
67
+ // Just 38/48 alone — still a color code, skip it
68
+ continue;
69
+ }
70
+ if (isColorCode(code)) {
71
+ continue;
72
+ }
73
+ // Non-color code — keep it
74
+ kept.push(String(code));
75
+ }
76
+ if (kept.length === 0)
77
+ return "";
78
+ return `\x1b[${kept.join(";")}m`;
79
+ });
80
+ }
81
+ //# sourceMappingURL=strip.js.map
@@ -0,0 +1 @@
1
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C,CAAC;YAE5C,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;gBACrB,SAAS;YACV,CAAC;YAED,iEAAiE;YACjE,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;gBAChC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC1B,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;oBAClB,qCAAqC;oBACrC,CAAC,IAAI,CAAC,CAAC;oBACP,SAAS;gBACV,CAAC;gBACD,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;oBAClB,yCAAyC;oBACzC,CAAC,IAAI,CAAC,CAAC;oBACP,SAAS;gBACV,CAAC;gBACD,iDAAiD;gBACjD,SAAS;YACV,CAAC;YAED,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvB,SAAS;YACV,CAAC;YAED,2BAA2B;YAC3B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACzB,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACjC,OAAO,QAAQ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAClC,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * String Visual Width Calculation
3
+ *
4
+ * Computes the visual display width of strings in terminal columns,
5
+ * accounting for ANSI escape sequences, East Asian wide characters,
6
+ * emoji, zero-width characters, and control characters.
7
+ */
8
+ /**
9
+ * Determines the visual column width of a single Unicode code point.
10
+ *
11
+ * - `0` for control characters, combining marks, zero-width joiners, variation selectors
12
+ * - `2` for CJK ideographs, fullwidth forms, hangul syllables, emoji
13
+ * - `1` for everything else
14
+ *
15
+ * @param codePoint - The Unicode code point to measure.
16
+ * @returns The visual width in terminal columns (0, 1, or 2).
17
+ */
18
+ export declare function charWidth(codePoint: number): number;
19
+ /**
20
+ * Calculates the total visual width of a string in terminal columns.
21
+ *
22
+ * Skips ANSI escape sequences (zero width), handles surrogate pairs
23
+ * for supplementary plane characters, and uses {@link charWidth} for each
24
+ * visible code point.
25
+ *
26
+ * @param str - The string to measure.
27
+ * @returns The total visual width in terminal columns.
28
+ */
29
+ export declare function stringWidth(str: string): number;
30
+ //# sourceMappingURL=width.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"width.d.ts","sourceRoot":"","sources":["../../src/render/width.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAyFnD;AAMD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAkC/C"}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * String Visual Width Calculation
3
+ *
4
+ * Computes the visual display width of strings in terminal columns,
5
+ * accounting for ANSI escape sequences, East Asian wide characters,
6
+ * emoji, zero-width characters, and control characters.
7
+ */
8
+ /**
9
+ * Determines the visual column width of a single Unicode code point.
10
+ *
11
+ * - `0` for control characters, combining marks, zero-width joiners, variation selectors
12
+ * - `2` for CJK ideographs, fullwidth forms, hangul syllables, emoji
13
+ * - `1` for everything else
14
+ *
15
+ * @param codePoint - The Unicode code point to measure.
16
+ * @returns The visual width in terminal columns (0, 1, or 2).
17
+ */
18
+ export function charWidth(codePoint) {
19
+ // Control characters (C0 and DEL)
20
+ if (codePoint < 32 || codePoint === 0x7f)
21
+ return 0;
22
+ // Combining Diacritical Marks
23
+ if (codePoint >= 0x0300 && codePoint <= 0x036f)
24
+ return 0;
25
+ // Zero-width characters
26
+ if (codePoint === 0x200b || // Zero Width Space
27
+ codePoint === 0x200c || // Zero Width Non-Joiner
28
+ codePoint === 0x200d || // Zero Width Joiner
29
+ codePoint === 0x2060 || // Word Joiner
30
+ codePoint === 0xfeff // BOM / Zero Width No-Break Space
31
+ ) {
32
+ return 0;
33
+ }
34
+ // Variation Selectors
35
+ if (codePoint >= 0xfe00 && codePoint <= 0xfe0f)
36
+ return 0;
37
+ // Supplementary variation selectors
38
+ if (codePoint >= 0xe0100 && codePoint <= 0xe01ef)
39
+ return 0;
40
+ // Combining marks in other blocks
41
+ if ((codePoint >= 0x0483 && codePoint <= 0x0489) || // Cyrillic combining
42
+ (codePoint >= 0x0591 && codePoint <= 0x05bd) || // Hebrew combining
43
+ (codePoint >= 0x0610 && codePoint <= 0x061a) || // Arabic combining
44
+ (codePoint >= 0x064b && codePoint <= 0x065f) || // Arabic combining
45
+ (codePoint >= 0x0670 && codePoint <= 0x0670) || // Arabic combining
46
+ (codePoint >= 0x06d6 && codePoint <= 0x06dc) || // Arabic combining
47
+ (codePoint >= 0x0730 && codePoint <= 0x074a) || // Syriac combining
48
+ (codePoint >= 0x0900 && codePoint <= 0x0903) || // Devanagari combining
49
+ (codePoint >= 0x093a && codePoint <= 0x094f) || // Devanagari combining
50
+ (codePoint >= 0x0e31 && codePoint <= 0x0e3a) || // Thai combining
51
+ (codePoint >= 0x0e47 && codePoint <= 0x0e4e) || // Thai combining
52
+ (codePoint >= 0x20d0 && codePoint <= 0x20ff) || // Combining Diacriticals for Symbols
53
+ (codePoint >= 0xfe20 && codePoint <= 0xfe2f) // Combining Half Marks
54
+ ) {
55
+ return 0;
56
+ }
57
+ // Soft Hyphen
58
+ if (codePoint === 0x00ad)
59
+ return 0; // width 0 in most terminals
60
+ // CJK Symbols and Punctuation (U+3000-U+303F)
61
+ if (codePoint >= 0x3000 && codePoint <= 0x303f)
62
+ return 2;
63
+ // Hiragana (U+3040-U+309F)
64
+ if (codePoint >= 0x3040 && codePoint <= 0x309f)
65
+ return 2;
66
+ // Katakana (U+30A0-U+30FF)
67
+ if (codePoint >= 0x30a0 && codePoint <= 0x30ff)
68
+ return 2;
69
+ // CJK Unified Ideographs Extension A (U+3400-U+4DBF)
70
+ if (codePoint >= 0x3400 && codePoint <= 0x4dbf)
71
+ return 2;
72
+ // CJK Unified Ideographs (U+4E00-U+9FFF)
73
+ if (codePoint >= 0x4e00 && codePoint <= 0x9fff)
74
+ return 2;
75
+ // Hangul Syllables (U+AC00-U+D7AF)
76
+ if (codePoint >= 0xac00 && codePoint <= 0xd7af)
77
+ return 2;
78
+ // CJK Compatibility Ideographs (U+F900-U+FAFF)
79
+ if (codePoint >= 0xf900 && codePoint <= 0xfaff)
80
+ return 2;
81
+ // Fullwidth Forms (U+FF01-U+FF60, U+FFE0-U+FFE6)
82
+ if (codePoint >= 0xff01 && codePoint <= 0xff60)
83
+ return 2;
84
+ if (codePoint >= 0xffe0 && codePoint <= 0xffe6)
85
+ return 2;
86
+ // Halfwidth Katakana and other halfwidth forms (U+FF61-U+FFDC) — width 1
87
+ // (default case handles this)
88
+ // Supplementary CJK (U+20000-U+2FA1F)
89
+ if (codePoint >= 0x20000 && codePoint <= 0x2fa1f)
90
+ return 2;
91
+ // Emoji block (U+1F000-U+1FFFF) — Mahjong, Playing Cards, Emoticons, etc.
92
+ if (codePoint >= 0x1f000 && codePoint <= 0x1ffff)
93
+ return 2;
94
+ // Miscellaneous Symbols and Pictographs, Dingbats, Emoticons
95
+ if (codePoint >= 0x2600 && codePoint <= 0x26ff)
96
+ return 1; // Most are width 1 in terminals
97
+ if (codePoint >= 0x2700 && codePoint <= 0x27bf)
98
+ return 1;
99
+ // Regional indicator symbols (U+1F1E0-U+1F1FF) — flags
100
+ if (codePoint >= 0x1f1e0 && codePoint <= 0x1f1ff)
101
+ return 2;
102
+ // Default: standard width
103
+ return 1;
104
+ }
105
+ /** Regex to match ANSI escape sequences for skipping in width calculation. */
106
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape detection requires control characters
107
+ const ANSI_REGEX = /\x1b\[[0-9;]*[A-Za-z]/;
108
+ /**
109
+ * Calculates the total visual width of a string in terminal columns.
110
+ *
111
+ * Skips ANSI escape sequences (zero width), handles surrogate pairs
112
+ * for supplementary plane characters, and uses {@link charWidth} for each
113
+ * visible code point.
114
+ *
115
+ * @param str - The string to measure.
116
+ * @returns The total visual width in terminal columns.
117
+ */
118
+ export function stringWidth(str) {
119
+ let width = 0;
120
+ let i = 0;
121
+ while (i < str.length) {
122
+ // Skip ANSI escape sequences
123
+ if (str.charCodeAt(i) === 0x1b && str[i + 1] === "[") {
124
+ // Find the end of the sequence
125
+ let j = i + 2;
126
+ while (j < str.length) {
127
+ const ch = str.charCodeAt(j);
128
+ if ((ch >= 0x41 && ch <= 0x5a) || (ch >= 0x61 && ch <= 0x7a)) {
129
+ // Found the terminating letter
130
+ i = j + 1;
131
+ break;
132
+ }
133
+ j++;
134
+ }
135
+ if (j >= str.length) {
136
+ // Unterminated escape sequence, skip rest
137
+ break;
138
+ }
139
+ continue;
140
+ }
141
+ // Get code point (handle surrogate pairs)
142
+ const code = str.codePointAt(i);
143
+ width += charWidth(code);
144
+ // Advance past this character (2 code units for supplementary plane)
145
+ i += code > 0xffff ? 2 : 1;
146
+ }
147
+ return width;
148
+ }
149
+ //# sourceMappingURL=width.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"width.js","sourceRoot":"","sources":["../../src/render/width.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,SAAiB;IAC1C,kCAAkC;IAClC,IAAI,SAAS,GAAG,EAAE,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IAEnD,8BAA8B;IAC9B,IAAI,SAAS,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM;QAAE,OAAO,CAAC,CAAC;IAEzD,wBAAwB;IACxB,IACC,SAAS,KAAK,MAAM,IAAI,mBAAmB;QAC3C,SAAS,KAAK,MAAM,IAAI,wBAAwB;QAChD,SAAS,KAAK,MAAM,IAAI,oBAAoB;QA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gBACrB,0CAA0C;gBAC1C,MAAM;YACP,CAAC;YACD,SAAS;QACV,CAAC;QAED,0CAA0C;QAC1C,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;QACjC,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;QAEzB,qEAAqE;QACrE,CAAC,IAAI,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Shortcuts — Quick opinionated API
3
+ *
4
+ * Provides c (color functions), s (composite styles), msg (structured messages),
5
+ * md (inline markdown), symbols, and tokens as convenient shortcuts.
6
+ */
7
+ export declare function md(text: string): string;
8
+ export declare const c: {
9
+ success: (text: string) => string;
10
+ error: (text: string) => string;
11
+ warning: (text: string) => string;
12
+ info: (text: string) => string;
13
+ muted: (text: string) => string;
14
+ command: (text: string) => string;
15
+ danger: (text: string) => string;
16
+ highlight: (text: string) => string;
17
+ dim: (text: string) => string;
18
+ bold: (text: string) => string;
19
+ subtle: (text: string) => string;
20
+ text: (text: string) => string;
21
+ kit: (text: string) => string;
22
+ recipe: (text: string) => string;
23
+ cookbook: (text: string) => string;
24
+ helper: (text: string) => string;
25
+ property: (text: string) => string;
26
+ required: (text: string) => string;
27
+ default: (value: any) => string;
28
+ enum: (text: string) => string;
29
+ title: (text: string) => string;
30
+ heading: (text: string) => string;
31
+ version: (text: string) => string;
32
+ };
33
+ export declare const s: {
34
+ hint: (text: string) => string;
35
+ success: (text: string) => string;
36
+ error: (text: string) => string;
37
+ warning: (text: string) => string;
38
+ info: (text: string) => string;
39
+ section: (text: string) => string;
40
+ code: (text: string) => string;
41
+ highlight: (text: string) => string;
42
+ title: (prefix: string, text: string) => string;
43
+ hr: () => string;
44
+ keyValue: (key: string, value: string, indent?: number) => string;
45
+ header: (text: string, count?: number) => string;
46
+ description: (text: string, level?: number) => string;
47
+ listItem: (text: string) => string;
48
+ /**
49
+ * Renders indented paragraph lines under a list item, followed by a blank line.
50
+ * Use this when a list item has body content (description, sub-items, etc.).
51
+ * Items without body content should NOT use this — they get no trailing blank line.
52
+ */
53
+ listItemBody: (...lines: string[]) => string;
54
+ indent: (text: string, spaces: number) => string;
55
+ path: (text: string) => string;
56
+ version: (text: string) => string;
57
+ md: typeof md;
58
+ };
59
+ interface MessageProps {
60
+ title?: string;
61
+ summary: string;
62
+ body?: string | string[];
63
+ }
64
+ export declare const msg: {
65
+ error: (input: string | MessageProps) => string;
66
+ warning: (input: string | MessageProps) => string;
67
+ success: (input: string | MessageProps) => string;
68
+ info: (input: string | MessageProps) => string;
69
+ tip: (input: string | MessageProps) => string;
70
+ };
71
+ /** Get resolved symbol glyphs. Lazy getter to ensure system is initialized. */
72
+ export declare function getSymbols(): import("./tokens/resolver.ts").ResolvedSymbolTokens;
73
+ /** Get resolved tokens. Lazy getter to ensure system is initialized. */
74
+ export declare function getTokens(): import("./ds-index.ts").ResolvedTokens;
75
+ export { getSymbols as symbols, getTokens as tokens };
76
+ //# sourceMappingURL=shortcuts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shortcuts.d.ts","sourceRoot":"","sources":["../src/shortcuts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,wBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKvC;AAMD,eAAO,MAAM,CAAC;oBAEG,MAAM;kBACR,MAAM;oBACJ,MAAM;iBACT,MAAM;kBACL,MAAM;oBAGJ,MAAM;mBACP,MAAM;sBAGH,MAAM;gBACZ,MAAM;iBACL,MAAM;mBACJ,MAAM;iBACR,MAAM;gBAGP,MAAM;mBACH,MAAM;qBACJ,MAAM;mBACR,MAAM;qBAGJ,MAAM;qBACN,MAAM;qBACN,GAAG;iBACP,MAAM;kBAGL,MAAM;oBACJ,MAAM;oBACN,MAAM;CACtB,CAAC;A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