linecraft 0.5.4 → 0.5.5

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.
@@ -0,0 +1,253 @@
1
+ // Unit tests for code-debug component
2
+ import { describe, it, expect, beforeEach } from 'vitest';
3
+ import { CodeDebug } from './code-debug.js';
4
+ import { TerminalRegion } from '../region.js';
5
+ import { callComponent } from '../component.js';
6
+ import { stripAnsi } from '../utils/text.js';
7
+ describe('code-debug component', () => {
8
+ let region;
9
+ beforeEach(() => {
10
+ region = new TerminalRegion({ disableRendering: true, width: 100 });
11
+ });
12
+ function render(component, width = 100) {
13
+ const ctx = {
14
+ availableWidth: width,
15
+ region: region,
16
+ columnIndex: 0,
17
+ rowIndex: 0,
18
+ };
19
+ const result = callComponent(component, ctx);
20
+ if (Array.isArray(result)) {
21
+ return result;
22
+ }
23
+ else if (result) {
24
+ return [result];
25
+ }
26
+ return [];
27
+ }
28
+ describe('truncated code with ellipsis', () => {
29
+ it('should correctly point to .v at columns 77-78 when code is truncated with start ellipsis', () => {
30
+ // This is the extend-chaining example that's failing
31
+ const errorLine = ' .ma:extend(.a,.b,.c,.d,.e,.f,.g,.h,.i,.j,.k,.l,.m,.n,.o,.p,.q,.r,.s,.t,.u,.v) {};';
32
+ const startColumn = 77; // Should point to '.'
33
+ const endColumn = 78; // Should point to 'v'
34
+ // Verify original columns
35
+ expect(errorLine[startColumn - 1]).toBe('.');
36
+ expect(errorLine[endColumn - 1]).toBe('v');
37
+ // Test with width that causes truncation (80 chars should truncate this 83-char line)
38
+ const width = 80;
39
+ const component = CodeDebug({
40
+ startLine: 77,
41
+ startColumn,
42
+ endColumn,
43
+ errorLine,
44
+ message: 'Extend target ".v" not accessible',
45
+ shortMessage: 'extend target not accessible',
46
+ filePath: 'test.less',
47
+ fullPath: '/test/test.less',
48
+ baseDir: '/test',
49
+ type: 'warning',
50
+ });
51
+ const output = render(component, width);
52
+ const outputText = output.join('\n');
53
+ const outputTextPlain = stripAnsi(outputText);
54
+ // Find the error line (line with │ and the code) - format: "77 │ ..."
55
+ const errorLineRegex = /^\s*\d+\s*│\s*(.+)$/m;
56
+ const errorLineMatch = outputTextPlain.match(errorLineRegex);
57
+ expect(errorLineMatch, `Error line should be found in:\n${outputTextPlain}`).toBeTruthy();
58
+ const renderedErrorLinePlain = errorLineMatch[1];
59
+ // Find the indicator line (line with │ and the underline) - format: " │ ..."
60
+ // Look for lines with indicator characters (┖, ┬, ┚, ╿)
61
+ const lines = outputTextPlain.split('\n');
62
+ let indicatorLinePlain = null;
63
+ let fullIndicatorLine = null;
64
+ for (const line of lines) {
65
+ if (line.includes('│') && (line.includes('┖') || line.includes('┬') || line.includes('┚') || line.includes('╿'))) {
66
+ fullIndicatorLine = line;
67
+ const match = line.match(/│ (.*)$/);
68
+ if (match) {
69
+ indicatorLinePlain = match[1];
70
+ break;
71
+ }
72
+ }
73
+ }
74
+ expect(indicatorLinePlain, `Indicator line should be found in:\n${outputTextPlain}`).toBeTruthy();
75
+ // The indicator should point to .v in the rendered error line
76
+ // Find where .v appears in the rendered error line
77
+ const dotVIndex = renderedErrorLinePlain.indexOf('.v');
78
+ expect(dotVIndex, `.v should be visible in rendered line: "${renderedErrorLinePlain}"`).toBeGreaterThanOrEqual(0);
79
+ // The indicator (┖, ┬, ┚, or ╿) should be positioned at or near .v
80
+ // Find the position of the T-bar (┬) or bracket (┖/┚) in the indicator line
81
+ const tBarIndex = indicatorLinePlain.indexOf('┬');
82
+ const bracketStart = indicatorLinePlain.indexOf('┖');
83
+ const bracketEnd = indicatorLinePlain.indexOf('┚');
84
+ const indicatorPos = tBarIndex >= 0 ? tBarIndex : (bracketStart >= 0 ? bracketStart : bracketEnd);
85
+ expect(indicatorPos, `Indicator should be found in: "${indicatorLinePlain}"`).toBeGreaterThanOrEqual(0);
86
+ // Account for ellipsis at start if present
87
+ // renderedErrorLinePlain includes ellipsis if present
88
+ const expectedIndicatorPos = dotVIndex;
89
+ // The indicator should be at or near where .v is (within 2 characters)
90
+ expect(Math.abs(indicatorPos - expectedIndicatorPos), `Indicator at ${indicatorPos} should be near .v at ${expectedIndicatorPos} in error line "${renderedErrorLinePlain}" and indicator "${indicatorLinePlain}"`).toBeLessThanOrEqual(2);
91
+ });
92
+ });
93
+ describe('short message alignment', () => {
94
+ it('should correctly align left-placed short message (message on right side)', () => {
95
+ // Left placement means message appears to the right of the code
96
+ const component = CodeDebug({
97
+ startLine: 50,
98
+ startColumn: 16,
99
+ endColumn: 35,
100
+ errorLine: 'const result = veryLongFunctionName(withManyParameters, andMoreParameters)',
101
+ message: 'Line too long',
102
+ shortMessage: 'line too long',
103
+ shortMessagePlacement: 'left',
104
+ filePath: 'test.ts',
105
+ fullPath: '/test/test.ts',
106
+ baseDir: '/test',
107
+ type: 'error',
108
+ });
109
+ const output = render(component, 100);
110
+ // Find the short message line (should have connector ──╯ pointing left)
111
+ const shortMessageLineRegex = /^\s*│\s*(.+)$/m;
112
+ const lines = output.join('\n').split('\n');
113
+ let shortMessageLine = null;
114
+ for (const line of lines) {
115
+ if (line.includes('──╯') || line.includes('line too long')) {
116
+ shortMessageLine = line;
117
+ break;
118
+ }
119
+ }
120
+ expect(shortMessageLine).toBeTruthy();
121
+ const shortMessageLinePlain = stripAnsi(shortMessageLine);
122
+ // Find the indicator line to get the T-bar position
123
+ const indicatorLineRegex = /^\s*│\s*(.+)$/m;
124
+ let indicatorLine = null;
125
+ for (const line of lines) {
126
+ if (line.includes('┬') || line.includes('┖')) {
127
+ indicatorLine = line;
128
+ break;
129
+ }
130
+ }
131
+ expect(indicatorLine).toBeTruthy();
132
+ const indicatorLinePlain = stripAnsi(indicatorLine);
133
+ // Find T-bar position in indicator line
134
+ const tBarPos = indicatorLinePlain.indexOf('┬');
135
+ expect(tBarPos).toBeGreaterThanOrEqual(0);
136
+ // Find connector end (╯) position in short message line
137
+ const connectorEndPos = shortMessageLinePlain.indexOf('╯');
138
+ expect(connectorEndPos).toBeGreaterThanOrEqual(0);
139
+ // The connector end (╯) should be at the T-bar position (exactly)
140
+ // Account for the │ prefix (lineNumWidth + 3)
141
+ const lineNumWidth = 2; // "50" is 2 chars
142
+ const prefixWidth = lineNumWidth + 3; // lineNumWidth + space + │ + space
143
+ const tBarPosInLine = tBarPos + prefixWidth;
144
+ const connectorEndPosInLine = connectorEndPos + prefixWidth;
145
+ // Should be exactly aligned (within 1 char tolerance)
146
+ expect(Math.abs(connectorEndPosInLine - tBarPosInLine), `Left-placed message: T-bar at ${tBarPosInLine}, connector end at ${connectorEndPosInLine}, difference: ${Math.abs(connectorEndPosInLine - tBarPosInLine)}`).toBeLessThanOrEqual(1);
147
+ });
148
+ it('should correctly align right-placed short message (message on left side)', () => {
149
+ // Right placement means message appears to the left of the code
150
+ const component = CodeDebug({
151
+ startLine: 12,
152
+ startColumn: 12,
153
+ endColumn: 16,
154
+ errorLine: ' return x + y + z;',
155
+ message: 'Type error: cannot add string and number',
156
+ shortMessage: 'string + number',
157
+ shortMessagePlacement: 'right',
158
+ filePath: 'test.ts',
159
+ fullPath: '/test/test.ts',
160
+ baseDir: '/test',
161
+ type: 'error',
162
+ });
163
+ const output = render(component, 100);
164
+ // Find the short message line (should have connector ╰── pointing right)
165
+ const lines = output.join('\n').split('\n');
166
+ let shortMessageLine = null;
167
+ for (const line of lines) {
168
+ if (line.includes('╰──') || line.includes('string + number')) {
169
+ shortMessageLine = line;
170
+ break;
171
+ }
172
+ }
173
+ expect(shortMessageLine).toBeTruthy();
174
+ const shortMessageLinePlain = stripAnsi(shortMessageLine);
175
+ // Find the indicator line to get the T-bar position
176
+ let indicatorLine = null;
177
+ for (const line of lines) {
178
+ if (line.includes('┬') || line.includes('┖')) {
179
+ indicatorLine = line;
180
+ break;
181
+ }
182
+ }
183
+ expect(indicatorLine).toBeTruthy();
184
+ const indicatorLinePlain = stripAnsi(indicatorLine);
185
+ // Find T-bar position in indicator line
186
+ const tBarPos = indicatorLinePlain.indexOf('┬');
187
+ expect(tBarPos).toBeGreaterThanOrEqual(0);
188
+ // Find connector start (╰) position in short message line
189
+ const connectorStartPos = shortMessageLinePlain.indexOf('╰');
190
+ expect(connectorStartPos).toBeGreaterThanOrEqual(0);
191
+ // The connector "╰── " has the last dash at position 3 from start
192
+ // So connectorStartPos + 3 should be at T-bar position
193
+ const lineNumWidth = 2; // "12" is 2 chars
194
+ const prefixWidth = lineNumWidth + 3; // lineNumWidth + space + │ + space
195
+ const tBarPosInLine = tBarPos + prefixWidth;
196
+ const connectorLastDashPosInLine = connectorStartPos + prefixWidth + 3;
197
+ // Should be exactly aligned (within 1 char tolerance)
198
+ expect(Math.abs(connectorLastDashPosInLine - tBarPosInLine), `Right-placed message: T-bar at ${tBarPosInLine}, connector last dash at ${connectorLastDashPosInLine}, difference: ${Math.abs(connectorLastDashPosInLine - tBarPosInLine)}`).toBeLessThanOrEqual(1);
199
+ });
200
+ });
201
+ describe('hyperlink preservation', () => {
202
+ it('should preserve OSC 8 hyperlink on truncated file path', () => {
203
+ // When a file path with a hyperlink is truncated, the entire visible portion should remain clickable
204
+ const component = CodeDebug({
205
+ startLine: 77,
206
+ startColumn: 77,
207
+ endColumn: 78,
208
+ errorLine: ' .ma:extend(.a,.b,.c,.d,.e,.f,.g,.h,.i,.j,.k,.l,.m,.n,.o,.p,.q,.r,.s,.t,.u,.v) {};',
209
+ message: 'Extend target ".v" not accessible',
210
+ shortMessage: 'extend target not accessible',
211
+ filePath: '../less.js/packages/test-data/tests-unit/extend-chaining/extend-chaining.less',
212
+ fullPath: '/project/../less.js/packages/test-data/tests-unit/extend-chaining/extend-chaining.less',
213
+ baseDir: '/project',
214
+ type: 'warning',
215
+ });
216
+ const output = render(component, 80); // Narrow width to force truncation
217
+ const outputText = output.join('\n');
218
+ const outputTextPlain = stripAnsi(outputText);
219
+ // Find the location line (has the file path with hyperlink)
220
+ // Format: " ╭─[path:line:column]"
221
+ const locationLineMatch = outputTextPlain.match(/╭─\[(.+?)\]/);
222
+ expect(locationLineMatch, `Location line should be found in:\n${outputTextPlain.substring(0, 200)}`).toBeTruthy();
223
+ // Get the actual line with ANSI codes for hyperlink checking
224
+ const locationLineWithAnsi = output.join('\n').split('\n').find(line => stripAnsi(line).includes('╭─['));
225
+ expect(locationLineWithAnsi, 'Location line with ANSI should be found').toBeTruthy();
226
+ const locationLine = locationLineWithAnsi;
227
+ // Check that the entire visible path (not just ellipsis) has the OSC 8 hyperlink
228
+ // OSC 8 format: \x1b]8;;<url>\x1b\\<text>\x1b]8;;\x1b\\
229
+ // The hyperlink should wrap the entire visible text, not just the ellipsis
230
+ const hasOsc8Start = locationLine.includes('\x1b]8;;');
231
+ expect(hasOsc8Start, 'Location line should contain OSC 8 hyperlink start').toBe(true);
232
+ // Extract the visible path portion (after ellipsis if present)
233
+ const pathMatch = locationLine.match(/\[(.+?)\]/);
234
+ expect(pathMatch, 'Path should be found in location line').toBeTruthy();
235
+ const visiblePath = pathMatch[1];
236
+ const visiblePathPlain = stripAnsi(visiblePath);
237
+ // If truncated with ellipsis, check that text after ellipsis is still in the link
238
+ if (visiblePathPlain.startsWith('...')) {
239
+ // Find where the ellipsis ends and the actual path text begins
240
+ const pathAfterEllipsis = visiblePathPlain.substring(3);
241
+ // The path after ellipsis should still be part of the hyperlink
242
+ // We can't easily test this without parsing OSC 8, but we can check that
243
+ // the hyperlink sequence appears before the ellipsis and continues after
244
+ const ellipsisIndex = locationLine.indexOf('...');
245
+ const pathAfterEllipsisIndex = locationLine.indexOf(pathAfterEllipsis.substring(0, Math.min(10, pathAfterEllipsis.length)));
246
+ // There should be an OSC 8 start before the ellipsis
247
+ const osc8BeforeEllipsis = locationLine.substring(0, ellipsisIndex).includes('\x1b]8;;');
248
+ expect(osc8BeforeEllipsis || pathAfterEllipsisIndex > ellipsisIndex, 'Hyperlink should start before ellipsis and continue on the visible path text').toBe(true);
249
+ }
250
+ });
251
+ });
252
+ });
253
+ //# sourceMappingURL=code-debug.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-debug.test.js","sourceRoot":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AM,CAAC,YAAY,EAAE,oDAAoD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEtF,+DAA+D;YAC/D,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAClD,MAAM,CAAC,SAAS,EAAE,uCAAuC,CAAC,CAAC,UAAU,EAAE,CAAC;YACxE,MAAM,WAAW,GAAG,SAAU,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,gBAAgB,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;YAEhD,kFAAkF;YAClF,IAAI,gBAAgB,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvC,+DAA+D;gBAC/D,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBACxD,gEAAgE;gBAChE,yEAAyE;gBACzE,yEAAyE;gBACzE,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAClD,MAAM,sBAAsB,GAAG,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAE5H,qDAAqD;gBACrD,MAAM,kBAAkB,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;gBACzF,MAAM,CAAC,kBAAkB,IAAI,sBAAsB,GAAG,aAAa,EACjE,8EAA8E,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/F,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -15,8 +15,8 @@ export declare function stripAnsi(text: string): string;
15
15
  * Truncate text to a maximum visual width while preserving ANSI escape codes
16
16
  *
17
17
  * This function truncates text based on its visual width (ignoring ANSI codes),
18
- * but preserves all ANSI escape sequences in the output. This is the base function
19
- * used by all other truncate functions.
18
+ * but preserves all ANSI escape sequences in the output. Active ANSI codes are
19
+ * preserved in the truncated result.
20
20
  *
21
21
  * @param text - Text that may contain ANSI escape codes
22
22
  * @param maxWidth - Maximum visual width (number of visible characters)
@@ -29,6 +29,9 @@ export declare function truncateToWidth(text: string, maxWidth: number): string;
29
29
  /**
30
30
  * Truncate text with ellipsis at the end, preserving ANSI escape codes
31
31
  *
32
+ * Active ANSI codes from the truncated portion are preserved, and the ellipsis
33
+ * is added after the truncated text (without ANSI codes).
34
+ *
32
35
  * @param text - Text that may contain ANSI escape codes
33
36
  * @param maxWidth - Maximum visual width (number of visible characters)
34
37
  * @returns Truncated text with '...' at the end, ANSI codes preserved
@@ -40,6 +43,10 @@ export declare function truncateEnd(text: string, maxWidth: number): string;
40
43
  /**
41
44
  * Truncate text with ellipsis at the beginning, preserving ANSI escape codes
42
45
  *
46
+ * When truncating from the start, we preserve ANSI codes that are active in the
47
+ * remaining portion. The ellipsis is added at the beginning (without ANSI codes),
48
+ * and active codes from the original text are re-applied to the remaining portion.
49
+ *
43
50
  * @param text - Text that may contain ANSI escape codes
44
51
  * @param maxWidth - Maximum visual width (number of visible characters)
45
52
  * @returns Truncated text with '...' at the beginning, ANSI codes preserved
@@ -51,6 +58,9 @@ export declare function truncateStart(text: string, maxWidth: number): string;
51
58
  /**
52
59
  * Truncate text with ellipsis in the middle, preserving ANSI escape codes
53
60
  *
61
+ * When truncating in the middle, we preserve ANSI codes from the start portion
62
+ * and re-apply them to the end portion to maintain consistent styling.
63
+ *
54
64
  * @param text - Text that may contain ANSI escape codes
55
65
  * @param maxWidth - Maximum visual width (number of visible characters)
56
66
  * @returns Truncated text with '...' in the middle, ANSI codes preserved
@@ -59,6 +69,56 @@ export declare function truncateStart(text: string, maxWidth: number): string;
59
69
  * truncateMiddle('\x1b[31mHello World\x1b[0m', 8) // '\x1b[31mHel...ld\x1b[0m'
60
70
  */
61
71
  export declare function truncateMiddle(text: string, maxWidth: number): string;
72
+ /**
73
+ * Map an original column position to its display position in truncated text
74
+ *
75
+ * This function takes the original text, the truncated result, and the visible range
76
+ * that was shown, and maps an original column to where it appears in the truncated text.
77
+ *
78
+ * @param originalText - The original text (plain, no ANSI)
79
+ * @param truncatedText - The truncated text result (may have ellipsis)
80
+ * @param visibleStartCol - The first column that was shown (1-based, includes truncated before)
81
+ * @param visibleEndCol - The last column that was shown (1-based, includes truncated after)
82
+ * @param originalCol - The original column to map (1-based)
83
+ * @param rangeStartCol - The start column of the main range (1-based, optional, for better accuracy)
84
+ * @param rangeEndCol - The end column of the main range (1-based, optional, for better accuracy)
85
+ * @returns The display position in the truncated text (1-based, visible characters)
86
+ */
87
+ export declare function mapColumnToDisplay(originalText: string, truncatedText: string, visibleStartCol: number, visibleEndCol: number, originalCol: number, rangeStartCol?: number, rangeEndCol?: number): number;
88
+ /**
89
+ * Result of truncateFocusRange, including information about what range was shown
90
+ */
91
+ export interface TruncateFocusRangeResult {
92
+ /** The truncated text with target range visible */
93
+ text: string;
94
+ /** The first column that was shown (1-based, includes truncated before portion) */
95
+ visibleStartCol: number;
96
+ /** The last column that was shown (1-based, includes truncated after portion) */
97
+ visibleEndCol: number;
98
+ /** The start column of the main range (1-based, the focused portion) */
99
+ rangeStartCol: number;
100
+ /** The end column of the main range (1-based, the focused portion) */
101
+ rangeEndCol: number;
102
+ }
103
+ /**
104
+ * Truncate text to show a specific column range, with ellipsis as needed
105
+ *
106
+ * This function ensures a target range (startCol to endCol) is visible in the output,
107
+ * adding ellipsis at the start, end, or both as needed to fit within maxWidth.
108
+ * All ANSI codes and OSC 8 hyperlinks are preserved.
109
+ *
110
+ * @param text - Text that may contain ANSI escape codes
111
+ * @param maxWidth - Maximum visual width (number of visible characters)
112
+ * @param targetStartCol - Start column of target range (1-based)
113
+ * @param targetEndCol - End column of target range (1-based, optional)
114
+ * @param maxColumn - Maximum column to show (optional, for limiting display)
115
+ * @returns Truncated text with target range visible, ANSI codes preserved, and visible range info
116
+ *
117
+ * @example
118
+ * truncateFocusRange('console.log("hello world");', 20, 1, 11)
119
+ * // Returns text showing columns 1-11 with ellipsis if needed
120
+ */
121
+ export declare function truncateFocusRange(text: string, maxWidth: number, targetStartCol: number, targetEndCol?: number, maxColumn?: number): TruncateFocusRangeResult;
62
122
  /**
63
123
  * Wrap text to fit within a width, breaking on spaces
64
124
  * Never breaks words mid-word - if a word is too long, it will extend the line
@@ -1 +1 @@
1
- {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB9C;AAwDD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA8BtE;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAWlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA8BpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAsCrE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAuK9D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIxD;AAGD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiBtD;A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