@remotex-labs/xmap 3.0.5 → 4.0.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.
@@ -1,68 +1,79 @@
1
+
1
2
  /**
2
- * A callback function for formatting code lines
3
- *
4
- * @param lineString - The content of the line to be formatted
5
- * @param padding - The amount of padding to be applied to the line
6
- * @param line - The line number of the line to be formatted
7
- * @returns Formatted line string
8
- *
9
- * @since 1.0.0
3
+ * This file was automatically generated by xBuild.
4
+ * DO NOT EDIT MANUALLY.
5
+ */
6
+ /**
7
+ * Import will remove at compile time
10
8
  */
11
- export type FormatCodeCallbackType = (lineString: string, padding: number, line: number) => string;
12
9
  /**
13
- * Configuration options for formatting code
10
+ * Export interfaces
11
+ */
12
+ /**
13
+ * Formats a code snippet with optional line padding and custom actions
14
+ *
15
+ * @param code - The source code | stack to be formatted
16
+ * @param options - Configuration options for formatting the code
17
+ * @returns A formatted string of the code snippet with applied padding and custom actions
18
+ *
19
+ * @remarks
20
+ * This function takes a code string and an options object to format the code snippet.
21
+ * It applies padding to line numbers and can trigger custom actions for specific lines.
22
+ * Options include padding (default 10), startLine (default 0), and custom actions for specific lines.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const formattedCode = formatCode(code, {
27
+ * padding: 8,
28
+ * startLine: 5,
29
+ * action: {
30
+ * triggerLine: 7,
31
+ * callback: (lineString, padding, lineNumber) => {
32
+ * return `Custom formatting for line ${lineNumber}: ${lineString}`;
33
+ * }
34
+ * }
35
+ * });
36
+ * ```
14
37
  *
15
38
  * @since 1.0.0
16
39
  */
17
- export interface FormatCodeInterface {
18
- /**
19
- * The amount of padding to be applied to each line
20
- * @since 1.0.0
21
- */
22
- padding?: number;
23
- /**
24
- * The starting line number for formatting
25
- * @since 1.0.0
26
- */
27
- startLine?: number;
28
- /**
29
- * An optional action object specifying a line where a callback function should be triggered.
30
- * @since 1.0.0
31
- */
32
- action?: {
33
- /**
34
- * The line number at which the callback function should be triggered.
35
- * @since 1.0.0
36
- */
37
- triggerLine: number;
38
- /**
39
- * The callback function to be executed when the trigger line is encountered.
40
- * @since 1.0.0
41
- */
42
- callback: FormatCodeCallbackType;
43
- };
44
- }
40
+ export declare function formatCode(code: string, options?: FormatCodeInterface): string;
45
41
  /**
46
- * Configuration for ANSI color styling of error pointers
42
+ * Formats a code snippet around an error location with special highlighting
43
+ *
44
+ * @param sourcePosition - An object containing information about the source code and error location
45
+ * @param ansiOption - Optional configuration for ANSI color codes
46
+ * @returns A formatted string representing the relevant code snippet with error highlighting
47
+ *
48
+ * @throws Error - If the provided sourcePosition object has invalid line or column numbers
49
+ *
50
+ * @remarks
51
+ * This function takes a sourcePosition object with code content and error location information,
52
+ * then uses formatCode to format and highlight the relevant code snippet around the error.
53
+ * The sourcePosition object should contain code (string), line (number), column (number),
54
+ * and optional startLine (number, defaults to 1).
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const formattedErrorCode = formatErrorCode({
59
+ * code: "const x = 1;\nconst y = x.undefined;\n",
60
+ * line: 2,
61
+ * column: 15,
62
+ * startLine: 1
63
+ * });
64
+ * ```
65
+ *
66
+ * @see formatCode - The underlying function used for basic code formatting
67
+ *
47
68
  * @since 1.0.0
48
69
  */
49
- export interface AnsiOptionInterface {
50
- /**
51
- * ANSI color code to apply to the error pointer
52
- * @since 1.0.0
53
- */
54
- color: string;
55
- /**
56
- * ANSI reset code to restore default styling after the error pointer
57
- * @since 1.0.0
58
- */
59
- reset: string;
60
- }
70
+ export declare function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string;
71
+
61
72
  /**
62
73
  * Represents a source map structure used for mapping code within a file to its original source
63
74
  * @since 1.0.0
64
75
  */
65
- export interface SourceMapInterface {
76
+ interface SourceMapInterface {
66
77
  /**
67
78
  * The generated file's name that the source map is associated with
68
79
  * @since 1.0.0
@@ -103,7 +114,7 @@ export interface SourceMapInterface {
103
114
  * Represents a position in source code with mapping information
104
115
  * @since 1.0.0
105
116
  */
106
- export interface PositionInterface {
117
+ interface PositionInterface {
107
118
  /**
108
119
  * Name of the identifier at this position
109
120
  * @since 1.0.0
@@ -151,7 +162,7 @@ export interface PositionInterface {
151
162
  * @see PositionInterface
152
163
  * @since 1.0.0
153
164
  */
154
- export interface PositionWithContentInterface extends PositionInterface {
165
+ interface PositionWithContentInterface extends PositionInterface {
155
166
  /**
156
167
  * Content of the original source file
157
168
  * @since 1.0.0
@@ -164,7 +175,7 @@ export interface PositionWithContentInterface extends PositionInterface {
164
175
  * @see PositionInterface
165
176
  * @since 1.0.0
166
177
  */
167
- export interface PositionWithCodeInterface extends PositionInterface {
178
+ interface PositionWithCodeInterface extends PositionInterface {
168
179
  /**
169
180
  * Code fragment from the original source
170
181
  * @since 1.0.0
@@ -185,7 +196,7 @@ export interface PositionWithCodeInterface extends PositionInterface {
185
196
  * Options for retrieving source code context
186
197
  * @since 1.0.0
187
198
  */
188
- export interface SourceOptionsInterface {
199
+ interface SourceOptionsInterface {
189
200
  /**
190
201
  * Number of lines to include after the target line
191
202
  * @since 1.0.0
@@ -197,62 +208,212 @@ export interface SourceOptionsInterface {
197
208
  */
198
209
  linesBefore?: number;
199
210
  }
211
+
200
212
  /**
201
- * Formats a code snippet with optional line padding and custom actions
213
+ * Import will remove at compile time
214
+ */
215
+ /**
216
+ * A callback function for formatting code lines
202
217
  *
203
- * @param code - The source code | stack to be formatted
204
- * @param options - Configuration options for formatting the code
205
- * @returns A formatted string of the code snippet with applied padding and custom actions
218
+ * @param lineString - The content of the line to be formatted
219
+ * @param padding - The amount of padding to be applied to the line
220
+ * @param line - The line number of the line to be formatted
221
+ * @returns Formatted line string
206
222
  *
207
- * @remarks
208
- * This function takes a code string and an options object to format the code snippet.
209
- * It applies padding to line numbers and can trigger custom actions for specific lines.
210
- * Options include padding (default 10), startLine (default 0), and custom actions for specific lines.
223
+ * @since 1.0.0
224
+ */
225
+ export type FormatCodeCallbackType = (lineString: string, padding: number, line: number) => string;
226
+ /**
227
+ * Configuration options for formatting code
211
228
  *
212
- * @example
213
- * ```ts
214
- * const formattedCode = formatCode(code, {
215
- * padding: 8,
216
- * startLine: 5,
217
- * action: {
218
- * triggerLine: 7,
219
- * callback: (lineString, padding, lineNumber) => {
220
- * return `Custom formatting for line ${lineNumber}: ${lineString}`;
221
- * }
222
- * }
223
- * });
224
- * ```
229
+ * @since 1.0.0
230
+ */
231
+ export interface FormatCodeInterface {
232
+ /**
233
+ * The amount of padding to be applied to each line
234
+ * @since 1.0.0
235
+ */
236
+ padding?: number;
237
+ /**
238
+ * The starting line number for formatting
239
+ * @since 1.0.0
240
+ */
241
+ startLine?: number;
242
+ /**
243
+ * An optional action object specifying a line where a callback function should be triggered.
244
+ * @since 1.0.0
245
+ */
246
+ action?: {
247
+ /**
248
+ * The line number at which the callback function should be triggered.
249
+ * @since 1.0.0
250
+ */
251
+ triggerLine: number;
252
+ /**
253
+ * The callback function to be executed when the trigger line is encountered.
254
+ * @since 1.0.0
255
+ */
256
+ callback: FormatCodeCallbackType;
257
+ };
258
+ }
259
+ /**
260
+ * Configuration for ANSI color styling of error pointers
261
+ * @since 1.0.0
262
+ */
263
+ export interface AnsiOptionInterface {
264
+ /**
265
+ * ANSI color code to apply to the error pointer
266
+ * @since 1.0.0
267
+ */
268
+ color: ColorFunctionType;
269
+ }
270
+
271
+ /**
272
+ * Represents a function that applies coloring or formatting to strings.
273
+ *
274
+ * @param args - Strings to be formatted
275
+ * @returns The formatted string
225
276
  *
226
277
  * @since 1.0.0
227
278
  */
228
- export declare function formatCode(code: string, options?: FormatCodeInterface): string;
279
+ type ColorFunctionType = (...args: Array<string>) => string;
229
280
  /**
230
- * Formats a code snippet around an error location with special highlighting
281
+ * Defines a color scheme for syntax highlighting various code elements.
231
282
  *
232
- * @param sourcePosition - An object containing information about the source code and error location
233
- * @param ansiOption - Optional configuration for ANSI color codes
234
- * @returns A formatted string representing the relevant code snippet with error highlighting
283
+ * @remarks
284
+ * Each property is a {@link ColorFunctionType} that formats a specific type of syntax element,
285
+ * such as enums, classes, keywords, or literals.
235
286
  *
236
- * @throws Error - If the provided sourcePosition object has invalid line or column numbers
287
+ * @see ColorFunctionType
288
+ * @since 1.0.0
289
+ */
290
+ interface HighlightSchemeInterface {
291
+ /**
292
+ * Color function for enum names.
293
+ * @since 1.0.0
294
+ */
295
+ enumColor: ColorFunctionType;
296
+ /**
297
+ * Color function for type names.
298
+ * @since 1.0.0
299
+ */
300
+ typeColor: ColorFunctionType;
301
+ /**
302
+ * Color function for class names.
303
+ * @since 1.0.0
304
+ */
305
+ classColor: ColorFunctionType;
306
+ /**
307
+ * Color function for string literals.
308
+ * @since 1.0.0
309
+ */
310
+ stringColor: ColorFunctionType;
311
+ /**
312
+ * Color function for language keywords.
313
+ * @since 1.0.0
314
+ */
315
+ keywordColor: ColorFunctionType;
316
+ /**
317
+ * Color function for comments.
318
+ * @since 1.0.0
319
+ */
320
+ commentColor: ColorFunctionType;
321
+ /**
322
+ * Color function for function names.
323
+ * @since 1.0.0
324
+ */
325
+ functionColor: ColorFunctionType;
326
+ /**
327
+ * Color function for variable names.
328
+ * @since 1.0.0
329
+ */
330
+ variableColor: ColorFunctionType;
331
+ /**
332
+ * Color function for interface names.
333
+ * @since 1.0.0
334
+ */
335
+ interfaceColor: ColorFunctionType;
336
+ /**
337
+ * Color function for function/method parameters.
338
+ * @since 1.0.0
339
+ */
340
+ parameterColor: ColorFunctionType;
341
+ /**
342
+ * Color function for getter accessor names.
343
+ * @since 1.0.0
344
+ */
345
+ getAccessorColor: ColorFunctionType;
346
+ /**
347
+ * Color function for numeric literals.
348
+ * @since 1.0.0
349
+ */
350
+ numericLiteralColor: ColorFunctionType;
351
+ /**
352
+ * Color function for method signatures.
353
+ * @since 1.0.0
354
+ */
355
+ methodSignatureColor: ColorFunctionType;
356
+ /**
357
+ * Color function for regular expressions.
358
+ * @since 1.0.0
359
+ */
360
+ regularExpressionColor: ColorFunctionType;
361
+ /**
362
+ * Color function for property assignments.
363
+ * @since 1.0.0
364
+ */
365
+ propertyAssignmentColor: ColorFunctionType;
366
+ /**
367
+ * Color function for property access expressions.
368
+ * @since 1.0.0
369
+ */
370
+ propertyAccessExpressionColor: ColorFunctionType;
371
+ /**
372
+ * Color function for expressions with type arguments.
373
+ * @since 1.0.0
374
+ */
375
+ expressionWithTypeArgumentsColor: ColorFunctionType;
376
+ }
377
+ /**
378
+ * Represents a segment of source code to be highlighted with specific styling.
237
379
  *
238
380
  * @remarks
239
- * This function takes a sourcePosition object with code content and error location information,
240
- * then uses formatCode to format and highlight the relevant code snippet around the error.
241
- * The sourcePosition object should contain code (string), line (number), column (number),
242
- * and optional startLine (number, defaults to 1).
381
+ * Segments are the fundamental units of the highlighting system.
382
+ * Each segment represents a portion of text that should receive specific styling.
383
+ * When the source code is processed for display,
384
+ * these segments are used to insert the appropriate color/style codes at the correct positions.
385
+ *
386
+ * The highlighter maintains a collection of these segments and applies them
387
+ * in position order to create the complete highlighted output.
243
388
  *
244
389
  * @example
245
390
  * ```ts
246
- * const formattedErrorCode = formatErrorCode({
247
- * code: "const x = 1;\nconst y = x.undefined;\n",
248
- * line: 2,
249
- * column: 15,
250
- * startLine: 1
251
- * });
391
+ * const keywordSegment: HighlightNodeSegmentInterface = {
392
+ * start: 0,
393
+ * end: 6,
394
+ * color: xterm.red
395
+ * };
252
396
  * ```
253
397
  *
254
- * @see formatCode - The underlying function used for basic code formatting
398
+ * @see addSegment
399
+ * @see HighlightSchemeInterface
255
400
  *
256
401
  * @since 1.0.0
257
402
  */
258
- export declare function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string;
403
+ interface HighlightNodeSegmentInterface {
404
+ /**
405
+ * The starting character position of the segment in the source text.
406
+ * @since 1.0.0
407
+ */
408
+ start: number;
409
+ /**
410
+ * The ending character position of the segment in the source text.
411
+ * @since 1.0.0
412
+ */
413
+ end: number;
414
+ /**
415
+ * The color or style code to apply to this segment.
416
+ * @since 1.0.0
417
+ */
418
+ color: ColorFunctionType;
419
+ }