@remotex-labs/xmap 3.0.0 → 3.0.2

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 (28) hide show
  1. package/dist/cjs/formatter.component.js +3 -3
  2. package/dist/cjs/formatter.component.js.map +3 -3
  3. package/dist/cjs/highlighter.component.js.map +3 -3
  4. package/dist/cjs/index.js +1 -1
  5. package/dist/cjs/index.js.map +3 -3
  6. package/dist/cjs/parser.component.js +1 -1
  7. package/dist/cjs/parser.component.js.map +4 -4
  8. package/dist/esm/formatter.component.js +3 -3
  9. package/dist/esm/formatter.component.js.map +3 -3
  10. package/dist/esm/highlighter.component.js.map +3 -3
  11. package/dist/esm/index.js +2 -2
  12. package/dist/esm/index.js.map +3 -3
  13. package/dist/esm/parser.component.js +2 -2
  14. package/dist/esm/parser.component.js.map +3 -3
  15. package/dist/formatter.component.d.ts +258 -0
  16. package/dist/{components/highlighter.component.d.ts → highlighter.component.d.ts} +94 -11
  17. package/dist/index.d.ts +866 -3
  18. package/dist/{components/parser.component.d.ts → parser.component.d.ts} +58 -14
  19. package/package.json +32 -32
  20. package/dist/components/base64.component.d.ts +0 -70
  21. package/dist/components/formatter.component.d.ts +0 -68
  22. package/dist/components/interfaces/formatter-component.interface.d.ts +0 -60
  23. package/dist/components/interfaces/highlighter-component.interface.d.ts +0 -94
  24. package/dist/components/interfaces/parse-component.interface.d.ts +0 -52
  25. package/dist/providers/interfaces/mapping-provider.interface.d.ts +0 -141
  26. package/dist/providers/mapping.provider.d.ts +0 -317
  27. package/dist/services/interfaces/source-service.interface.d.ts +0 -139
  28. package/dist/services/source.service.d.ts +0 -216
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/components/parser.component.ts"],
4
- "sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.0/",
5
- "sourcesContent": ["/**\n * Export interfaces\n */\nexport { ParsedStackTrace, StackFrame } from '@components/interfaces/parse-component.interface';\n/**\n * Import will remove at compile time\n */\nimport type { ParsedStackTrace, StackFrame } from '@components/interfaces/parse-component.interface';\n/**\n * Regular expression patterns for different JavaScript engines' stack traces\n *\n * @since 2.1.0\n */\nconst PATTERNS = {\n V8: {\n STANDARD: /at\\s+(?:([^(]+?)\\s+)?\\(?(?:(.+?):(\\d+):(\\d+)|(native))\\)?/,\n EVAL: /^at\\s(.+?)\\s\\(eval\\sat\\s(.+?)\\s?\\((.*):(\\d+):(\\d+)\\),\\s(.+?):(\\d+):(\\d+)\\)$/\n },\n SPIDERMONKEY: {\n EVAL: /^(.*)@(.+?):(\\d+):(\\d+),\\s(.+?)@(.+?):(\\d+):(\\d+)$/,\n STANDARD: /^(.*)@(.*?)(?:(\\[native code\\])|:(\\d+):(\\d+))$/\n },\n JAVASCRIPT_CORE: {\n STANDARD: /^(?:(global|eval)\\s)?(.*)@(.*?)(?::(\\d+)(?::(\\d+))?)?$/\n }\n};\n/**\n * Enumeration of JavaScript engines that can be detected from stack traces\n *\n * @since 2.1.0\n */\nexport const enum JSEngines {\n V8,\n SPIDERMONKEY,\n JAVASCRIPT_CORE,\n UNKNOWN\n}\n/**\n * Detects the JavaScript engine based on the format of a stack trace line\n *\n * @param stack - The stack trace to analyze\n * @returns The identified JavaScript engine type\n *\n * @example\n * ```ts\n * const engine = detectJSEngine(\"at functionName (/path/to/file.js:10:15)\");\n * if (engine === JSEngines.V8) {\n * // Handle V8 specific logic\n * }\n * ```\n *\n * @since 2.1.0\n */\nexport function detectJSEngine(stack: string): JSEngines {\n if (stack.startsWith(' at ') || stack.startsWith('at '))\n return JSEngines.V8;\n if (stack.includes('@'))\n return /(?:global|eval) code@/.test(stack)\n ? JSEngines.JAVASCRIPT_CORE : JSEngines.SPIDERMONKEY;\n return JSEngines.UNKNOWN;\n}\n/**\n * Normalizes file paths from various formats to a standard format\n *\n * @param filePath - The file path to normalize, which may include protocol prefixes\n * @returns A normalized file path with consistent separators and without protocol prefixes\n *\n * @remarks\n * Handles both Windows and Unix-style paths, as well as file:// protocol URLs.\n * Converts all backslashes to forward slashes for consistency.\n *\n * @example\n * ```ts\n * // Windows file URL to a normal path\n * normalizePath(\"file:///C:/path/to/file.js\"); // \"C:/path/to/file.js\"\n *\n * // Unix file URL to a normal path\n * normalizePath(\"file:///path/to/file.js\"); // \"/path/to/file.js\"\n *\n * // Windows backslashes to forward slashes\n * normalizePath(\"C:\\\\path\\\\to\\\\file.js\"); // \"C:/path/to/file.js\"\n * ```\n *\n * @since 2.1.0\n */\nexport function normalizePath(filePath: string): string {\n // Handle file:// protocol URLs\n if (filePath.startsWith('file://')) {\n // Handle Windows file:/// format\n if (filePath.startsWith('file:///') && /^file:\\/\\/\\/[A-Za-z]:/.test(filePath)) {\n // Windows absolute path: file:///C:/path/to/file.js\n return filePath.substring(8);\n }\n // Handle *nix file:// format\n return filePath.substring(7);\n }\n // Handle Windows-style paths with backward slashes\n filePath = filePath.replace(/\\\\/g, '/');\n return filePath;\n}\n/**\n * Creates a default stack frame object with initial values\n *\n * @param source - The original source line from the stack trace\n * @returns A new StackFrame object with default null values\n *\n * @see ParsedStackTrace\n * @see StackFrame\n *\n * @since 2.1.0\n */\nexport function createDefaultFrame(source: string): StackFrame {\n return {\n source,\n eval: false,\n async: false,\n native: false,\n constructor: false\n };\n}\n/**\n * Safely parses a string value to an integer, handling undefined and null cases\n *\n * @param value - The string value to parse\n * @returns The parsed integer or null if the input is undefined/null\n *\n * @example\n * ```ts\n * safeParseInt(\"42\"); // 42\n * safeParseInt(undefined); // null\n * safeParseInt(null); // null\n * ```\n *\n * @since 2.1.0\n */\nexport function safeParseInt(value: string | undefined | null): number | undefined {\n return value && value.trim() !== '' ? parseInt(value, 10) : undefined;\n}\n/**\n * Parses a V8 JavaScript engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard V8 stack frames and eval-generated stack frames which\n * have a more complex structure with nested origin information.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseV8StackLine(\"at functionName (/path/to/file.js:10:15)\");\n *\n * // Eval frame\n * parseV8StackLine(\"at eval (eval at evalFn (/source.js:5:10), <anonymous>:1:5)\");\n * ```\n *\n * @throws Error - If the line format doesn't match any known V8 pattern\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\nexport function parseV8StackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n // Check for eval format first\n const evalMatch = line.match(PATTERNS.V8.EVAL);\n if (evalMatch) {\n frame.eval = true;\n frame.functionName = evalMatch[1] ? evalMatch[1] : undefined;\n // Add eval origin information\n frame.evalOrigin = {\n line: safeParseInt(evalMatch[4]) ?? undefined,\n column: safeParseInt(evalMatch[5]) ?? undefined,\n fileName: evalMatch[3] ? normalizePath(evalMatch[3]) : undefined,\n functionName: evalMatch[2] || '<anonymous>'\n };\n // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[7]) ?? undefined;\n frame.column = safeParseInt(evalMatch[8]) ?? undefined;\n frame.fileName = evalMatch[6] ? normalizePath(evalMatch[6]) : undefined;\n frame.native = (frame.fileName ?? '').startsWith('node') ?? false;\n return frame;\n }\n // Standard V8 format\n const match = line.match(PATTERNS.V8.STANDARD);\n if (match) {\n frame.functionName = match[1] ? match[1].trim() : undefined;\n if (line.toLowerCase().includes('new'))\n frame.constructor = true;\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n if (match[5] === 'native') {\n frame.native = true;\n frame.fileName = '[native code]';\n }\n else {\n frame.line = safeParseInt(match[3]) ?? undefined;\n frame.column = safeParseInt(match[4]) ?? undefined;\n frame.fileName = match[2] ? normalizePath(match[2]) : undefined;\n frame.native = (frame.fileName ?? '').startsWith('node') ?? false;\n }\n }\n return frame;\n}\n/**\n * Parses a SpiderMonkey JavaScript engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard SpiderMonkey stack frames and eval/Function-generated stack frames\n * which contain additional evaluation context information.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseSpiderMonkeyStackLine(\"functionName@/path/to/file.js:10:15\");\n *\n * // Eval frame\n * parseSpiderMonkeyStackLine(\"evalFn@/source.js line 5 > eval:1:5\");\n * ```\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\nexport function parseSpiderMonkeyStackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n // Check for eval/Function format\n const evalMatch = line.match(PATTERNS.SPIDERMONKEY.EVAL);\n if (evalMatch) {\n frame.eval = true;\n frame.functionName = evalMatch[1] ? evalMatch[1] : undefined;\n if (line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n // Add eval origin information\n frame.evalOrigin = {\n line: safeParseInt(evalMatch[7]) ?? undefined,\n column: safeParseInt(evalMatch[8]) ?? undefined,\n fileName: normalizePath(evalMatch[6]),\n functionName: evalMatch[5] ? evalMatch[5] : undefined\n };\n // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[3]) ?? undefined;\n frame.column = safeParseInt(evalMatch[4]) ?? undefined;\n return frame;\n }\n // Standard SpiderMonkey format\n const match = line.match(PATTERNS.SPIDERMONKEY.STANDARD);\n if (match) {\n frame.functionName = match[1] ? match[1] : undefined;\n frame.fileName = normalizePath(match[2]);\n if (match[3] === '[native code]') {\n frame.fileName = '[native code]';\n }\n else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n }\n }\n return frame;\n}\n/**\n * Parses a JavaScriptCore engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard JavaScriptCore stack frames and eval-generated stack frames.\n * Special handling is provided for \"global code\" references and native code.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseJavaScriptCoreStackLine(\"functionName@/path/to/file.js:10:15\");\n *\n * // Eval frame\n * parseJavaScriptCoreStackLine(\"eval code@\");\n * ```\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\nexport function parseJavaScriptCoreStackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n // Standard JavaScriptCore format\n const match = line.match(PATTERNS.JAVASCRIPT_CORE.STANDARD);\n if (match) {\n frame.functionName = match[2];\n frame.eval = (match[1] === 'eval' || match[3] === 'eval');\n if (line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n if (match[3] === '[native code]') {\n frame.native = true;\n frame.fileName = '[native code]';\n }\n else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n frame.fileName = normalizePath(match[3]);\n }\n }\n return frame;\n}\n/**\n * Parses a stack trace line based on the detected JavaScript engine\n *\n * @param line - The stack trace line to parse\n * @param engine - The JavaScript engine type that generated the stack trace\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Delegates to the appropriate parsing function based on the JavaScript engine.\n * Defaults to V8 parsing if the engine is unknown.\n *\n * @example\n * ```ts\n * const engine = detectJSEngine(stackLine);\n * const frame = parseStackLine(stackLine, engine);\n * ```\n *\n * @see JSEngines\n * @see parseV8StackLine\n * @see parseSpiderMonkeyStackLine\n * @see parseJavaScriptCoreStackLine\n *\n * @since 2.1.0\n */\nexport function parseStackLine(line: string, engine: JSEngines): StackFrame {\n switch (engine) {\n case JSEngines.SPIDERMONKEY:\n return parseSpiderMonkeyStackLine(line);\n case JSEngines.JAVASCRIPT_CORE:\n return parseJavaScriptCoreStackLine(line);\n case JSEngines.V8:\n default:\n return parseV8StackLine(line);\n }\n}\n/**\n * Parses a complete error stack trace into a structured format\n *\n * @param error - Error object or error message string to parse\n * @returns A ParsedStackTrace object containing structured stack trace information\n *\n * @remarks\n * Automatically detects the JavaScript engine from the stack format.\n * Filters out redundant information like the error name/message line.\n * Handles both Error objects and string error messages.\n *\n * @example\n * ```ts\n * try {\n * throw new Error (\"Something went wrong\");\n * } catch (error) {\n * const parsedStack = parseErrorStack(error);\n * console.log(parsedStack.name); // \"Error\"\n * console.log(parsedStack.message); // \"Something went wrong\"\n * console.log(parsedStack.stack); // Array of StackFrame objects\n * }\n * ```\n *\n * @see ParsedStackTrace\n * @see StackFrame\n * @see parseStackLine\n * @see detectJSEngine\n *\n * @since 2.1.0\n */\nexport function parseErrorStack(error: Error | string): ParsedStackTrace {\n const errorObj = typeof error === 'string' ? new Error(error) : error;\n const stack = errorObj.stack || '';\n const message = errorObj.message || '';\n const name = errorObj.name || 'Error';\n const engine = detectJSEngine(stack);\n const stackLines = stack.split('\\n')\n .map(line => line.trim())\n .filter(line => line.trim() !== '')\n .slice(1);\n return {\n name,\n message,\n stack: stackLines.map(line => parseStackLine(line, engine)),\n rawStack: stack\n };\n}\n"],
6
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,uBAAAC,EAAA,mBAAAC,EAAA,kBAAAC,EAAA,oBAAAC,EAAA,iCAAAC,EAAA,+BAAAC,EAAA,mBAAAC,EAAA,qBAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAZ,GAaA,IAAMa,EAAW,CACb,GAAI,CACA,SAAU,4DACV,KAAM,6EACV,EACA,aAAc,CACV,KAAM,qDACN,SAAU,gDACd,EACA,gBAAiB,CACb,SAAU,wDACd,CACJ,EAMkBC,OACdA,IAAA,WACAA,IAAA,+BACAA,IAAA,qCACAA,IAAA,qBAJcA,OAAA,IAsBX,SAASC,EAAeC,EAA0B,CACrD,OAAIA,EAAM,WAAW,SAAS,GAAKA,EAAM,WAAW,KAAK,EAC9C,EACPA,EAAM,SAAS,GAAG,EACX,wBAAwB,KAAKA,CAAK,EACnC,EAA4B,EAC/B,CACX,CAyBO,SAASC,EAAcC,EAA0B,CAEpD,OAAIA,EAAS,WAAW,SAAS,EAEzBA,EAAS,WAAW,UAAU,GAAK,wBAAwB,KAAKA,CA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AeN,EAAMO,CAAM,CAAC,EAC1D,SAAUf,CACd,CACJ",
7
- "names": ["parser_component_exports", "__export", "JSEngines", "createDefaultFrame", "detectJSEngine", "normalizePath", "parseErrorStack", "parseJavaScriptCoreStackLine", "parseSpiderMonkeyStackLine", "parseStackLine", "parseV8StackLine", "safeParseInt", "__toCommonJS", "PATTERNS", "JSEngines", "detectJSEngine", "stack", "normalizePath", "filePath", "createDefaultFrame", "source", "safeParseInt", "value", "parseV8StackLine", "line", "frame", "evalMatch", "match", "parseSpiderMonkeyStackLine", "parseJavaScriptCoreStackLine", "parseStackLine", "engine", "parseErrorStack", "error", "errorObj", "message", "name", "stackLines"]
4
+ "sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.2/",
5
+ "sourcesContent": ["/**\n * Export interfaces\n */\n\nexport type * from '@components/interfaces/parse-component.interface';\n\n/**\n * Import will remove at compile time\n */\n\nimport type { ParsedStackTrace, StackFrame } from '@components/interfaces/parse-component.interface';\n\n/**\n * Regular expression patterns for different JavaScript engines' stack traces\n *\n * @since 2.1.0\n */\n\nconst PATTERNS = {\n V8: {\n STANDARD: /at\\s+(?:([^(]+?)\\s+)?\\(?(?:(.+?):(\\d+):(\\d+)|(native))\\)?/,\n EVAL: /^at\\s(.+?)\\s\\(eval\\sat\\s(.+?)\\s?\\((.*):(\\d+):(\\d+)\\),\\s(.+?):(\\d+):(\\d+)\\)$/\n },\n SPIDERMONKEY: {\n EVAL: /^(.*)@(.+?):(\\d+):(\\d+),\\s(.+?)@(.+?):(\\d+):(\\d+)$/,\n STANDARD: /^(.*)@(.*?)(?:(\\[native code\\])|:(\\d+):(\\d+))$/\n },\n JAVASCRIPT_CORE: {\n STANDARD: /^(?:(global|eval)\\s)?(.*)@(.*?)(?::(\\d+)(?::(\\d+))?)?$/\n }\n};\n\n/**\n * Enumeration of JavaScript engines that can be detected from stack traces\n *\n * @since 2.1.0\n */\n\nexport const enum JSEngines {\n V8,\n SPIDERMONKEY,\n JAVASCRIPT_CORE,\n UNKNOWN\n}\n\n/**\n * Detects the JavaScript engine based on the format of a stack trace line\n *\n * @param stack - The stack trace to analyze\n * @returns The identified JavaScript engine type\n *\n * @example\n * ```ts\n * const engine = detectJSEngine(\"at functionName (/path/to/file.js:10:15)\");\n * if (engine === JSEngines.V8) {\n * // Handle V8 specific logic\n * }\n * ```\n *\n * @since 2.1.0\n */\n\nexport function detectJSEngine(stack: string): JSEngines {\n if (stack.startsWith(' at ') || stack.startsWith('at '))\n return JSEngines.V8;\n\n if (stack.includes('@'))\n return /(?:global|eval) code@/.test(stack)\n ? JSEngines.JAVASCRIPT_CORE : JSEngines.SPIDERMONKEY;\n\n return JSEngines.UNKNOWN;\n}\n\n/**\n * Normalizes file paths from various formats to a standard format\n *\n * @param filePath - The file path to normalize, which may include protocol prefixes\n * @returns A normalized file path with consistent separators and without protocol prefixes\n *\n * @remarks\n * Handles both Windows and Unix-style paths, as well as file:// protocol URLs.\n * Converts all backslashes to forward slashes for consistency.\n *\n * @example\n * ```ts\n * // Windows file URL to a normal path\n * normalizePath(\"file:///C:/path/to/file.js\"); // \"C:/path/to/file.js\"\n *\n * // Unix file URL to a normal path\n * normalizePath(\"file:///path/to/file.js\"); // \"/path/to/file.js\"\n *\n * // Windows backslashes to forward slashes\n * normalizePath(\"C:\\\\path\\\\to\\\\file.js\"); // \"C:/path/to/file.js\"\n * ```\n *\n * @since 2.1.0\n */\n\nexport function normalizePath(filePath: string): string {\n // Handle file:// protocol URLs\n if (filePath.startsWith('file://')) {\n // Handle Windows file:/// format\n if (filePath.startsWith('file:///') && /^file:\\/\\/\\/[A-Za-z]:/.test(filePath)) {\n // Windows absolute path: file:///C:/path/to/file.js\n return filePath.substring(8);\n }\n\n // Handle *nix file:// format\n return filePath.substring(7);\n }\n\n // Handle Windows-style paths with backward slashes\n filePath = filePath.replace(/\\\\/g, '/');\n\n return filePath;\n}\n\n/**\n * Creates a default stack frame object with initial values\n *\n * @param source - The original source line from the stack trace\n * @returns A new StackFrame object with default null values\n *\n * @see ParsedStackTrace\n * @see StackFrame\n *\n * @since 2.1.0\n */\n\nexport function createDefaultFrame(source: string): StackFrame {\n return {\n source,\n eval: false,\n async: false,\n native: false,\n constructor: false\n };\n}\n\n/**\n * Safely parses a string value to an integer, handling undefined and null cases\n *\n * @param value - The string value to parse\n * @returns The parsed integer or null if the input is undefined/null\n *\n * @example\n * ```ts\n * safeParseInt(\"42\"); // 42\n * safeParseInt(undefined); // null\n * safeParseInt(null); // null\n * ```\n *\n * @since 2.1.0\n */\n\nexport function safeParseInt(value: string | undefined | null): number | undefined {\n return value && value.trim() !== '' ? parseInt(value, 10) : undefined;\n}\n\n/**\n * Parses a V8 JavaScript engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard V8 stack frames and eval-generated stack frames which\n * have a more complex structure with nested origin information.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseV8StackLine(\"at functionName (/path/to/file.js:10:15)\");\n *\n * // Eval frame\n * parseV8StackLine(\"at eval (eval at evalFn (/source.js:5:10), <anonymous>:1:5)\");\n * ```\n *\n * @throws Error - If the line format doesn't match any known V8 pattern\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseV8StackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n\n // Check for eval format first\n const evalMatch = line.match(PATTERNS.V8.EVAL);\n if (evalMatch) {\n frame.eval = true;\n frame.functionName = evalMatch[1] ? evalMatch[1] : undefined;\n\n // Add eval origin information\n frame.evalOrigin = {\n line: safeParseInt(evalMatch[4]) ?? undefined,\n column: safeParseInt(evalMatch[5]) ?? undefined,\n fileName: evalMatch[3] ? normalizePath(evalMatch[3]) : undefined,\n functionName: evalMatch[2] || '<anonymous>'\n };\n\n // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[7]) ?? undefined;\n frame.column = safeParseInt(evalMatch[8]) ?? undefined;\n frame.fileName = evalMatch[6] ? normalizePath(evalMatch[6]) : undefined;\n frame.native = (frame.fileName ?? '').startsWith('node') ?? false;\n\n return frame;\n }\n\n // Standard V8 format\n const match = line.match(PATTERNS.V8.STANDARD);\n if (match) {\n frame.functionName = match[1] ? match[1].trim() : undefined;\n\n if(line.toLowerCase().includes('new'))\n frame.constructor = true;\n\n if(line.toLowerCase().includes('async'))\n frame.async = true;\n\n if (match[5] === 'native') {\n frame.native = true;\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(match[3]) ?? undefined;\n frame.column = safeParseInt(match[4]) ?? undefined;\n frame.fileName = match[2] ? normalizePath(match[2]) : undefined;\n frame.native = (frame.fileName ?? '').startsWith('node') ?? false;\n }\n }\n\n return frame;\n}\n\n/**\n * Parses a SpiderMonkey JavaScript engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard SpiderMonkey stack frames and eval/Function-generated stack frames\n * which contain additional evaluation context information.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseSpiderMonkeyStackLine(\"functionName@/path/to/file.js:10:15\");\n *\n * // Eval frame\n * parseSpiderMonkeyStackLine(\"evalFn@/source.js line 5 > eval:1:5\");\n * ```\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseSpiderMonkeyStackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n\n // Check for eval/Function format\n const evalMatch = line.match(PATTERNS.SPIDERMONKEY.EVAL);\n if (evalMatch) {\n frame.eval = true;\n frame.functionName = evalMatch[1] ? evalMatch[1] : undefined;\n\n if(line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n\n if(line.toLowerCase().includes('async'))\n frame.async = true;\n\n // Add eval origin information\n frame.evalOrigin = {\n line: safeParseInt(evalMatch[7]) ?? undefined,\n column: safeParseInt(evalMatch[8]) ?? undefined,\n fileName: normalizePath(evalMatch[6]),\n functionName: evalMatch[5] ? evalMatch[5] : undefined\n };\n\n // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[3]) ?? undefined;\n frame.column = safeParseInt(evalMatch[4]) ?? undefined;\n\n return frame;\n }\n\n // Standard SpiderMonkey format\n const match = line.match(PATTERNS.SPIDERMONKEY.STANDARD);\n if (match) {\n frame.functionName = match[1] ? match[1] : undefined;\n frame.fileName = normalizePath(match[2]);\n\n if (match[3] === '[native code]') {\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n }\n }\n\n return frame;\n}\n\n/**\n * Parses a JavaScriptCore engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard JavaScriptCore stack frames and eval-generated stack frames.\n * Special handling is provided for \"global code\" references and native code.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseJavaScriptCoreStackLine(\"functionName@/path/to/file.js:10:15\");\n *\n * // Eval frame\n * parseJavaScriptCoreStackLine(\"eval code@\");\n * ```\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseJavaScriptCoreStackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n\n // Standard JavaScriptCore format\n const match = line.match(PATTERNS.JAVASCRIPT_CORE.STANDARD);\n if (match) {\n frame.functionName = match[2];\n frame.eval = (match[1] === 'eval' || match[3] === 'eval');\n\n if(line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n\n if(line.toLowerCase().includes('async'))\n frame.async = true;\n\n if (match[3] === '[native code]') {\n frame.native = true;\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n frame.fileName = normalizePath(match[3]);\n }\n }\n\n return frame;\n}\n\n/**\n * Parses a stack trace line based on the detected JavaScript engine\n *\n * @param line - The stack trace line to parse\n * @param engine - The JavaScript engine type that generated the stack trace\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Delegates to the appropriate parsing function based on the JavaScript engine.\n * Defaults to V8 parsing if the engine is unknown.\n *\n * @example\n * ```ts\n * const engine = detectJSEngine(stackLine);\n * const frame = parseStackLine(stackLine, engine);\n * ```\n *\n * @see JSEngines\n * @see parseV8StackLine\n * @see parseSpiderMonkeyStackLine\n * @see parseJavaScriptCoreStackLine\n *\n * @since 2.1.0\n */\n\nexport function parseStackLine(line: string, engine: JSEngines): StackFrame {\n switch (engine) {\n case JSEngines.SPIDERMONKEY:\n return parseSpiderMonkeyStackLine(line);\n case JSEngines.JAVASCRIPT_CORE:\n return parseJavaScriptCoreStackLine(line);\n case JSEngines.V8:\n default:\n return parseV8StackLine(line);\n }\n}\n\n/**\n * Parses a complete error stack trace into a structured format\n *\n * @param error - Error object or error message string to parse\n * @returns A ParsedStackTrace object containing structured stack trace information\n *\n * @remarks\n * Automatically detects the JavaScript engine from the stack format.\n * Filters out redundant information like the error name/message line.\n * Handles both Error objects and string error messages.\n *\n * @example\n * ```ts\n * try {\n * throw new Error (\"Something went wrong\");\n * } catch (error) {\n * const parsedStack = parseErrorStack(error);\n * console.log(parsedStack.name); // \"Error\"\n * console.log(parsedStack.message); // \"Something went wrong\"\n * console.log(parsedStack.stack); // Array of StackFrame objects\n * }\n * ```\n *\n * @see ParsedStackTrace\n * @see StackFrame\n * @see parseStackLine\n * @see detectJSEngine\n *\n * @since 2.1.0\n */\n\nexport function parseErrorStack(error: Error | string): ParsedStackTrace {\n const errorObj = typeof error === 'string' ? new Error(error) : error;\n const stack = errorObj.stack || '';\n const message = errorObj.message || '';\n const name = errorObj.name || 'Error';\n\n const engine = detectJSEngine(stack);\n const stackLines = stack.split('\\n')\n .map(line => line.trim())\n .filter(line => line.trim() !== '')\n .slice(1);\n\n return {\n name,\n message,\n stack: stackLines.map(line => parseStackLine(line, engine)),\n rawStack: stack\n };\n}\n"],
6
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,E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,EAAM,CAAC,CAAC,IAIxCF,CACX,CA2BO,SAASV,EAAeS,EAAcI,EAA+B,CACxE,OAAQA,EAAQ,CACZ,IAAK,GACD,OAAOd,EAA2BU,CAAI,EAC1C,IAAK,GACD,OAAOX,EAA6BW,CAAI,EAC5C,IAAK,GACL,QACI,OAAOR,EAAiBQ,CAAI,CACpC,CACJ,CAiCO,SAASZ,EAAgBiB,EAAyC,CACrE,IAAMC,EAAW,OAAOD,GAAU,SAAW,IAAI,MAAMA,CAAK,EAAIA,EAC1DT,EAAQU,EAAS,OAAS,GAC1BC,EAAUD,EAAS,SAAW,GAC9BE,EAAOF,EAAS,MAAQ,QAExBF,EAASlB,EAAeU,CAAK,EAC7Ba,EAAab,EAAM,MAAM;AAAA,CAAI,EAC9B,IAAII,GAAQA,EAAK,KAAK,CAAC,EACvB,OAAOA,GAAQA,EAAK,KAAK,IAAM,EAAE,EACjC,MAAM,CAAC,EAEZ,MAAO,CACH,KAAAQ,EACA,QAAAD,EACA,MAAOE,EAAW,IAAIT,GAAQT,EAAeS,EAAMI,CAAM,CAAC,EAC1D,SAAUR,CACd,CACJ",
7
+ "names": ["parser_component_exports", "__export", "JSEngines", "createDefaultFrame", "detectJSEngine", "normalizePath", "parseErrorStack", "parseJavaScriptCoreStackLine", "parseSpiderMonkeyStackLine", "parseStackLine", "parseV8StackLine", "safeParseInt", "__toCommonJS", "PATTERNS", "stack", "filePath", "source", "value", "line", "frame", "evalMatch", "match", "engine", "error", "errorObj", "message", "name", "stackLines"]
8
8
  }
@@ -1,5 +1,5 @@
1
- function d(i,e={}){let f=i.split(`
2
- `),n=e.padding??10,c=e.startLine??0;return f.map((a,o)=>{let r=o+c+1,t=`${`${r} | `.padStart(n)}${a}`;return e.action&&r===e.action.triggerLine?e.action.callback(t,n,r):t}).join(`
3
- `)}function u(i,e){let{code:f,line:n,column:c,startLine:a}=i;if(n<a||c<1)throw new Error("Invalid line or column number.");return d(f,{startLine:a,action:{triggerLine:n,callback:(o,r,s)=>{let t="^",m=r-1,l=">";e&&(t=`${e.color}${t}${e.reset}`,m+=e.color.length+e.reset.length,l=`${e.color}>${e.reset}`);let p=" | ".padStart(r)+" ".repeat(c-1)+`${t}`;return o=`${l} ${s} |`.padStart(m)+o.split("|")[1],o+`
1
+ function d(a,e={}){let f=a.split(`
2
+ `),n=e.padding??10,c=e.startLine??0;return f.map((i,o)=>{let r=o+c+1,t=`${`${r} | `.padStart(n)}${i}`;return e.action&&r===e.action.triggerLine?e.action.callback(t,n,r):t}).join(`
3
+ `)}function u(a,e){let{code:f,line:n,column:c,startLine:i}=a;if(n<i||c<1)throw new Error("Invalid line or column number.");return d(f,{startLine:i,action:{triggerLine:n,callback:(o,r,s)=>{let t="^",m=r-1,l=">";e&&(t=`${e.color}${t}${e.reset}`,m+=e.color.length+e.reset.length,l=`${e.color}>${e.reset}`);let p=" | ".padStart(r)+" ".repeat(c-1)+`${t}`;return o=`${l} ${s} |`.padStart(m)+o.split("|")[1],o+`
4
4
  ${p}`}}})}export{d as formatCode,u as formatErrorCode};
5
5
  //# sourceMappingURL=formatter.component.js.map
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/components/formatter.component.ts"],
4
- "sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.0/",
5
- "sourcesContent": ["/**\n * Export interfaces\n */\nexport type { AnsiOptionInterface, FormatCodeInterface } from '@components/interfaces/formatter-component.interface';\n/**\n * Import will remove at compile time\n */\nimport type { PositionWithCodeInterface } from '@services/interfaces/source-service.interface';\nimport type { AnsiOptionInterface, FormatCodeInterface } from '@components/interfaces/formatter-component.interface';\n/**\n * Formats a code snippet with optional line padding and custom actions\n *\n * @param code - The source code | stack to be formatted\n * @param options - Configuration options for formatting the code\n * @returns A formatted string of the code snippet with applied padding and custom actions\n *\n * @remarks\n * This function takes a code string and an options object to format the code snippet.\n * It applies padding to line numbers and can trigger custom actions for specific lines.\n * Options include padding (default 10), startLine (default 0), and custom actions for specific lines.\n *\n * @example\n * ```ts\n * const formattedCode = formatCode(code, {\n * padding: 8,\n * startLine: 5,\n * action: {\n * triggerLine: 7,\n * callback: (lineString, padding, lineNumber) => {\n * return `Custom formatting for line ${lineNumber}: ${lineString}`;\n * }\n * }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport function formatCode(code: string, options: FormatCodeInterface = {}): string {\n const lines = code.split('\\n');\n const padding = options.padding ?? 10;\n const startLine = options.startLine ?? 0;\n return lines.map((lineContent, index) => {\n const currentLineNumber = index + startLine + 1;\n const prefix = `${currentLineNumber} | `;\n const string = `${prefix.padStart(padding)}${lineContent}`;\n if (options.action && currentLineNumber === options.action.triggerLine) {\n return options.action.callback(string, padding, currentLineNumber);\n }\n return string;\n }).join('\\n');\n}\n/**\n * Formats a code snippet around an error location with special highlighting\n *\n * @param sourcePosition - An object containing information about the source code and error location\n * @param ansiOption - Optional configuration for ANSI color codes\n * @returns A formatted string representing the relevant code snippet with error highlighting\n *\n * @throws Error - If the provided sourcePosition object has invalid line or column numbers\n *\n * @remarks\n * This function takes a sourcePosition object with code content and error location information,\n * then uses formatCode to format and highlight the relevant code snippet around the error.\n * The sourcePosition object should contain code (string), line (number), column (number),\n * and optional startLine (number, defaults to 1).\n *\n * @example\n * ```ts\n * const formattedErrorCode = formatErrorCode({\n * code: \"const x = 1;\\nconst y = x.undefined;\\n\",\n * line: 2,\n * column: 15,\n * startLine: 1\n * });\n * ```\n *\n * @see formatCode - The underlying function used for basic code formatting\n *\n * @since 1.0.0\n */\nexport function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string {\n const { code, line: errorLine, column: errorColumn, startLine } = sourcePosition;\n // Validate line and column numbers\n if (errorLine < startLine || errorColumn < 1) {\n throw new Error('Invalid line or column number.');\n }\n return formatCode(code, {\n startLine,\n action: {\n triggerLine: errorLine,\n callback: (lineString, padding, line) => {\n let pointer = '^';\n let ansiPadding = padding - 1; // 1 size of the char we added\n let prefixPointer = '>';\n if (ansiOption) {\n pointer = `${ansiOption.color}${pointer}${ansiOption.reset}`;\n ansiPadding += (ansiOption.color.length + ansiOption.reset.length);\n prefixPointer = `${ansiOption.color}>${ansiOption.reset}`;\n }\n const errorMarker = ' | '.padStart(padding) + ' '.repeat(errorColumn - 1) + `${pointer}`;\n lineString = `${prefixPointer} ${line} |`.padStart(ansiPadding) + lineString.split('|')[1];\n return lineString + `\\n${errorMarker}`;\n }\n }\n });\n}\n"],
6
- "mappings": "AAqCO,SAASA,EAAWC,EAAcC,EAA+B,CAAC,EAAW,CAChF,IAAMC,EAAQF,EAAK,MAAM;AAAA,CAAI,EACvBG,EAAUF,EAAQ,SAAW,GAC7BG,EAAYH,EAAQ,WAAa,EACvC,OAAOC,EAAM,IAAI,CAACG,EAAaC,IAAU,CACrC,IAAMC,EAAoBD,EAAQF,EAAY,EAExCI,EAAS,GADA,GAAGD,CAAiB,MACV,SAASJ,CAAO,CAAC,GAAGE,CAAW,GACxD,OAAIJ,EAAQ,QAAUM,IAAsBN,EAAQ,OAAO,YAChDA,EAAQ,OAAO,SAASO,EAAQL,EAASI,CAAiB,EAE9DC,CACX,CAAC,EAAE,KAAK;AAAA,CAAI,CAChB,CA8BO,SAASC,EAAgBC,EAA2CC,EAA0C,CACjH,GAAM,CAAE,KAAAX,EAAM,KAAMY,EAAW,OAAQC,EAAa,UAAAT,CAAU,EAAIM,EAElE,GAAIE,EAAYR,GAAaS,EAAc,EACvC,MAAM,IAAI,MAAM,gCAAgC,EAEpD,OAAOd,EAAWC,EAAM,CACpB,UAAAI,EACA,OAAQ,CACJ,YAAaQ,EACb,SAAU,CAACE,EAAYX,EAASY,IAAS,CACrC,IAAIC,EAAU,IACVC,EAAcd,EAAU,EACxBe,EAAgB,IAChBP,IACAK,EAAU,GAAGL,EAAW,KAAK,GAAGK,CAAO,GAAGL,EAAW,KAAK,GAC1DM,GAAgBN,EAAW,MAAM,OAASA,EAAW,MAAM,OAC3DO,EAAgB,GAAGP,EAAW,KAAK,IAAIA,EAAW,KAAK,IAE3D,IAAMQ,EAAc,MAAM,SAAShB,CAAO,EAAI,IAAI,OAAOU,EAAc,CAAC,EAAI,GAAGG,CAAO,GACtF,OAAAF,EAAa,GAAGI,CAAa,IAAIH,CAAI,KAAK,SAASE,CAAW,EAAIH,EAAW,MAAM,GAAG,EAAE,CAAC,EAClFA,EAAa;AAAA,EAAKK,CAAW,EACxC,CACJ,CACJ,CAAC,CACL",
4
+ "sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.2/",
5
+ "sourcesContent": ["/**\n * Export interfaces\n */\n\nexport type * from '@components/interfaces/formatter-component.interface';\n\n/**\n * Import will remove at compile time\n */\n\nimport type { PositionWithCodeInterface } from '@services/interfaces/source-service.interface';\nimport type { AnsiOptionInterface, FormatCodeInterface } from '@components/interfaces/formatter-component.interface';\n\n/**\n * Formats a code snippet with optional line padding and custom actions\n *\n * @param code - The source code | stack to be formatted\n * @param options - Configuration options for formatting the code\n * @returns A formatted string of the code snippet with applied padding and custom actions\n *\n * @remarks\n * This function takes a code string and an options object to format the code snippet.\n * It applies padding to line numbers and can trigger custom actions for specific lines.\n * Options include padding (default 10), startLine (default 0), and custom actions for specific lines.\n *\n * @example\n * ```ts\n * const formattedCode = formatCode(code, {\n * padding: 8,\n * startLine: 5,\n * action: {\n * triggerLine: 7,\n * callback: (lineString, padding, lineNumber) => {\n * return `Custom formatting for line ${lineNumber}: ${lineString}`;\n * }\n * }\n * });\n * ```\n *\n * @since 1.0.0\n */\n\nexport function formatCode(code: string, options: FormatCodeInterface = {}): string {\n const lines = code.split('\\n');\n const padding = options.padding ?? 10;\n const startLine = options.startLine ?? 0;\n\n return lines.map((lineContent, index) => {\n const currentLineNumber = index + startLine + 1;\n const prefix = `${ currentLineNumber} | `;\n const string = `${ prefix.padStart(padding) }${ lineContent }`;\n\n if (options.action && currentLineNumber === options.action.triggerLine) {\n return options.action.callback(string, padding, currentLineNumber);\n }\n\n return string;\n }).join('\\n');\n}\n\n/**\n * Formats a code snippet around an error location with special highlighting\n *\n * @param sourcePosition - An object containing information about the source code and error location\n * @param ansiOption - Optional configuration for ANSI color codes\n * @returns A formatted string representing the relevant code snippet with error highlighting\n *\n * @throws Error - If the provided sourcePosition object has invalid line or column numbers\n *\n * @remarks\n * This function takes a sourcePosition object with code content and error location information,\n * then uses formatCode to format and highlight the relevant code snippet around the error.\n * The sourcePosition object should contain code (string), line (number), column (number),\n * and optional startLine (number, defaults to 1).\n *\n * @example\n * ```ts\n * const formattedErrorCode = formatErrorCode({\n * code: \"const x = 1;\\nconst y = x.undefined;\\n\",\n * line: 2,\n * column: 15,\n * startLine: 1\n * });\n * ```\n *\n * @see formatCode - The underlying function used for basic code formatting\n *\n * @since 1.0.0\n */\n\nexport function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string {\n const { code, line: errorLine, column: errorColumn, startLine } = sourcePosition;\n\n // Validate line and column numbers\n if (errorLine < startLine || errorColumn < 1) {\n throw new Error('Invalid line or column number.');\n }\n\n return formatCode(code, {\n startLine,\n action: {\n triggerLine: errorLine,\n callback: (lineString, padding, line) => {\n let pointer = '^';\n let ansiPadding = padding - 1; // 1 size of the char we added\n let prefixPointer = '>';\n\n if (ansiOption) {\n pointer = `${ ansiOption.color }${ pointer }${ ansiOption.reset }`;\n ansiPadding += (ansiOption.color.length + ansiOption.reset.length);\n prefixPointer = `${ ansiOption.color }>${ ansiOption.reset }`;\n }\n\n const errorMarker = ' | '.padStart(padding) + ' '.repeat(errorColumn - 1) + `${ pointer }`;\n lineString = `${ prefixPointer } ${ line } |`.padStart(ansiPadding) + lineString.split('|')[1];\n\n return lineString + `\\n${ errorMarker }`;\n }\n }\n });\n}\n"],
6
+ "mappings": "AA0CO,SAASA,EAAWC,EAAcC,EAA+B,CAAC,EAAW,CAChF,IAAMC,EAAQF,EAAK,MAAM;AAAA,CAAI,EACvBG,EAAUF,EAAQ,SAAW,GAC7BG,EAAYH,EAAQ,WAAa,EAEvC,OAAOC,EAAM,IAAI,CAACG,EAAaC,IAAU,CACrC,IAAMC,EAAoBD,EAAQF,EAAY,EAExCI,EAAS,GADA,GAAID,CAAiB,MACV,SAASJ,CAAO,CAAE,GAAIE,CAAY,GAE5D,OAAIJ,EAAQ,QAAUM,IAAsBN,EAAQ,OAAO,YAChDA,EAAQ,OAAO,SAASO,EAAQL,EAASI,CAAiB,EAG9DC,CACX,CAAC,EAAE,KAAK;AAAA,CAAI,CAChB,CAgCO,SAASC,EAAgBC,EAA2CC,EAA0C,CACjH,GAAM,CAAE,KAAAX,EAAM,KAAMY,EAAW,OAAQC,EAAa,UAAAT,CAAU,EAAIM,EAGlE,GAAIE,EAAYR,GAAaS,EAAc,EACvC,MAAM,IAAI,MAAM,gCAAgC,EAGpD,OAAOd,EAAWC,EAAM,CACpB,UAAAI,EACA,OAAQ,CACJ,YAAaQ,EACb,SAAU,CAACE,EAAYX,EAASY,IAAS,CACrC,IAAIC,EAAU,IACVC,EAAcd,EAAU,EACxBe,EAAgB,IAEhBP,IACAK,EAAU,GAAIL,EAAW,KAAM,GAAIK,CAAQ,GAAIL,EAAW,KAAM,GAChEM,GAAgBN,EAAW,MAAM,OAASA,EAAW,MAAM,OAC3DO,EAAgB,GAAIP,EAAW,KAAM,IAAKA,EAAW,KAAM,IAG/D,IAAMQ,EAAc,MAAM,SAAShB,CAAO,EAAI,IAAI,OAAOU,EAAc,CAAC,EAAI,GAAIG,CAAQ,GACxF,OAAAF,EAAa,GAAII,CAAc,IAAKH,CAAK,KAAK,SAASE,CAAW,EAAIH,EAAW,MAAM,GAAG,EAAE,CAAC,EAEtFA,EAAa;AAAA,EAAMK,CAAY,EAC1C,CACJ,CACJ,CAAC,CACL",
7
7
  "names": ["formatCode", "code", "options", "lines", "padding", "startLine", "lineContent", "index", "currentLineNumber", "string", "formatErrorCode", "sourcePosition", "ansiOption", "errorLine", "errorColumn", "lineString", "line", "pointer", "ansiPadding", "prefixPointer", "errorMarker"]
8
8
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/components/highlighter.component.ts"],
4
- "sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.0/",
5
- "sourcesContent": ["/**\n * Export interfaces\n */\nexport type { HighlightSchemeInterface, HighlightNodeSegmentInterface } from '@components/interfaces/highlighter-component.interface';\n/**\n * Import will remove at compile time\n */\nimport type { HighlightSchemeInterface, HighlightNodeSegmentInterface } from '@components/interfaces/highlighter-component.interface';\n/**\n * Imports\n */\nimport * as ts from 'typescript';\nimport { SyntaxKind } from 'typescript';\n/**\n * An enum containing ANSI escape sequences for various colors\n *\n * @remarks\n * This enum is primarily intended for terminal output and won't work directly in JavaScript for web development.\n * It defines color codes for various colors and a reset code to return to the default text color.\n *\n * @example\n * ```ts\n * console.log(`${Colors.red}This text will be red in the terminal.${Colors.reset}`);\n * ```\n *\n * @since 1.0.0\n */\nexport const enum Colors {\n reset = '\\x1b[0m',\n gray = '\\x1b[38;5;243m',\n darkGray = '\\x1b[38;5;238m',\n lightCoral = '\\x1b[38;5;203m',\n lightOrange = '\\x1b[38;5;215m',\n oliveGreen = '\\x1b[38;5;149m',\n burntOrange = '\\x1b[38;5;208m',\n lightGoldenrodYellow = '\\x1b[38;5;221m',\n lightYellow = '\\x1b[38;5;230m',\n canaryYellow = '\\x1b[38;5;227m',\n deepOrange = '\\x1b[38;5;166m',\n lightGray = '\\x1b[38;5;252m',\n brightPink = '\\x1b[38;5;197m'\n}\n/**\n * Default color scheme for semantic highlighting\n *\n * @remarks\n * This scheme defines colors for different code elements to be used for syntax highlighting.\n *\n * @example\n * ```ts\n * const scheme = defaultScheme;\n * console.log(scheme.typeColor); // Outputs: the color code for types\n * ```\n *\n * @see HighlightSchemeInterface\n * @see Colors\n *\n * @since 1.0.0\n */\nconst defaultScheme: HighlightSchemeInterface = {\n enumColor: Colors.burntOrange,\n typeColor: Colors.lightGoldenrodYellow,\n classColor: Colors.lightOrange,\n stringColor: Colors.oliveGreen,\n keywordColor: Colors.lightCoral,\n commentColor: Colors.darkGray,\n functionColor: Colors.lightOrange,\n variableColor: Colors.burntOrange,\n interfaceColor: Colors.lightGoldenrodYellow,\n parameterColor: Colors.deepOrange,\n getAccessorColor: Colors.lightYellow,\n numericLiteralColor: Colors.lightGray,\n methodSignatureColor: Colors.burntOrange,\n regularExpressionColor: Colors.oliveGreen,\n propertyAssignmentColor: Colors.canaryYellow,\n propertyAccessExpressionColor: Colors.lightYellow,\n expressionWithTypeArgumentsColor: Colors.lightOrange\n};\n/**\n * Class responsible for applying semantic highlighting to a source code string based on a given color scheme\n *\n * @remarks\n * Processes TypeScript AST nodes and applies color formatting to different code elements\n * according to the provided color scheme.\n *\n * @example\n * ```ts\n * const sourceFile = ts.createSourceFile('example.ts', code, ts.ScriptTarget.Latest);\n * const highlighter = new CodeHighlighter(sourceFile, code, customScheme);\n * highlighter.parseNode(sourceFile);\n * const highlightedCode = highlighter.highlight();\n * ```\n *\n * @since 1.0.0\n */\nexport class CodeHighlighter {\n /**\n * A Map of segments where the key is a combination of start and end positions.\n *\n * @remarks\n * This structure ensures unique segments and allows for fast lookups and updates.\n *\n * @see HighlightNodeSegmentInterface\n * @since 1.0.0\n */\n private segments: Map<string, HighlightNodeSegmentInterface> = new Map();\n /**\n * Creates an instance of the CodeHighlighter class.\n *\n * @param sourceFile - The TypeScript AST node representing the source file\n * @param code - The source code string to be highlighted\n * @param schema - The color scheme used for highlighting different elements in the code\n *\n * @since 1.0.0\n */\n constructor(private sourceFile: ts.Node, private code: string, private schema: HighlightSchemeInterface) {\n }\n /**\n * Parses a TypeScript AST node and processes its comments to identify segments that need highlighting.\n *\n * @param node - The TypeScript AST node to be parsed\n *\n * @since 1.0.0\n */\n parseNode(node: ts.Node): void {\n this.processComments(node);\n this.processKeywords(node);\n this.processNode(node);\n }\n /**\n * Generates a string with highlighted code segments based on the provided color scheme.\n *\n * @returns The highlighted code as a string, with ANSI color codes applied to the segments\n *\n * @remarks\n * This method processes the stored segments, applies the appropriate colors to each segment,\n * and returns the resulting highlighted code as a single string.\n *\n * @since 1.0.0\n */\n highlight(): string {\n let previousSegmentEnd = 0;\n let parent: HighlightNodeSegmentInterface | undefined;\n const result: Array<string> = [];\n const segments = Array.from(this.segments.values()).sort((a, b) => a.start - b.start || a.end - b.end);\n segments.forEach((segment) => {\n if (parent && segment.start < parent.end) {\n const lastSegment = result.pop();\n if (!lastSegment)\n return;\n const source = this.getSegmentSource(segment.start, segment.end);\n const combinedSource = `${segment.color}${source}${parent.color}`;\n result.push(lastSegment.replace(source, combinedSource));\n return;\n }\n result.push(this.getSegmentSource(previousSegmentEnd, segment.start));\n result.push(`${segment.color}${this.getSegmentSource(segment.start, segment.end)}${segment.reset}`);\n previousSegmentEnd = segment.end;\n parent = segment;\n });\n return result.join('') + this.getSegmentSource(previousSegmentEnd);\n }\n /**\n * Extracts a text segment from the source code using position indices.\n *\n * @param start - The starting index position in the source text\n * @param end - The ending index position in the source text (optional)\n * @returns The substring of source text between the start and end positions\n *\n * @remarks\n * This utility method provides access to specific portions of the source code\n * based on character positions. When the end parameter is omitted, the extraction\n * will continue to the end of the source text.\n *\n * This method is typically used during the highlighting process to access the\n * actual text content that corresponds to syntax nodes or other text ranges\n * before applying formatting.\n *\n * @example\n * ```ts\n * // Extract a variable name\n * const variableName = this.getSegmentSource(10, 15);\n *\n * // Extract from a position to the end of source\n * const remaining = this.getSegmentSource(100);\n * ```\n *\n * @see addSegment\n * @see highlight\n *\n * @since 1.0.0\n */\n private getSegmentSource(start: number, end?: number): string {\n return this.code.slice(start, end);\n }\n /**\n * Registers a text segment for syntax highlighting with specified style information.\n *\n * @param start - The starting position of the segment in the source text\n * @param end - The ending position of the segment in the source text\n * @param color - The color code to apply to this segment\n * @param reset - The color reset code to apply after the segment (defaults to the standard reset code)\n *\n * @remarks\n * This method creates a unique key for each segment based on its position and stores the segment information in a map.\n * Each segment contains its position information, styling code,\n * and reset code which will later be used during the highlighting process.\n *\n * If multiple segments are added with the same positions, the later additions will\n * overwrite earlier ones due to the map's key-based storage.\n *\n * @example\n * ```ts\n * // Highlight a variable name in red\n * this.addSegment(10, 15, Colors.red);\n *\n * // Highlight a keyword with custom color and reset\n * this.addSegment(20, 26, Colors.blue, Colors.customReset);\n * ```\n *\n * @see Colors\n * @see processNode\n *\n * @since 1.0.0\n */\n private addSegment(start: number, end: number, color: string, reset: string = Colors.reset) {\n const key = `${start}-${end}`;\n this.segments.set(key, { start, end, color, reset });\n }\n /**\n * Processes and highlights comments associated with a TypeScript AST node.\n *\n * @param node - The TypeScript AST node whose comments are to be processed\n *\n * @remarks\n * This method identifies both leading and trailing comments associated with the given node\n * and adds them to the highlighting segments.\n * The comments are extracted from the full source text using TypeScript's utility functions\n * and are highlighted using the color specified\n * in the schema's commentColor property.\n *\n * Leading comments appear before the node, while trailing comments appear after it.\n * Both types are processed with the same highlighting style.\n *\n * @example\n * ```ts\n * // For a node that might have comments like:\n * // This is a leading comment\n * const x = 5; // This is a trailing comment\n *\n * this.processComments(someNode);\n * // Both comments will be added to segments with the comment color\n * ```\n *\n * @see addSegment\n * @see ts.getLeadingCommentRanges\n * @see ts.getTrailingCommentRanges\n *\n * @since 1.0.0\n */\n private processComments(node: ts.Node): void {\n const comments = [\n ...ts.getTrailingCommentRanges(this.sourceFile.getFullText(), node.getFullStart()) || [],\n ...ts.getLeadingCommentRanges(this.sourceFile.getFullText(), node.getFullStart()) || []\n ];\n comments.forEach(comment => this.addSegment(comment.pos, comment.end, this.schema.commentColor));\n }\n /**\n * Processes TypeScript keywords and primitive type references in an AST node for syntax highlighting.\n *\n * @param node - The TypeScript AST node to be processed for keywords\n *\n * @remarks\n * This method handles two categories of tokens that require special highlighting:\n *\n * 1. Primitive type references: Highlights references to built-in types like `null`,\n * `void`, `string`, `number`, `boolean`, and `undefined` using the type color.\n *\n * 2. TypeScript keywords: Identifies any node whose kind falls within the TypeScript\n * keyword range (between FirstKeyword and LastKeyword) and highlights it using\n * the keyword color.\n *\n * Each identified token is added to the segments collection with appropriate position\n * and color information.\n *\n * @example\n * ```ts\n * // Inside syntax highlighting process\n * this.processKeywords(someNode);\n * // If the node represents a keyword like 'const' or a primitive type like 'string',\n * // it will be added to the segments with the appropriate color\n * ```\n *\n * @see addSegment\n * @see ts.SyntaxKind\n *\n * @since 1.0.0\n */\n private processKeywords(node: ts.Node): void {\n if ([\n SyntaxKind.NullKeyword,\n SyntaxKind.VoidKeyword,\n SyntaxKind.StringKeyword,\n SyntaxKind.NumberKeyword,\n SyntaxKind.BooleanKeyword,\n SyntaxKind.UndefinedKeyword\n ].includes(node.kind)) {\n return this.addSegment(node.getStart(), node.getEnd(), this.schema.typeColor);\n }\n if (node && node.kind >= ts.SyntaxKind.FirstKeyword && node.kind <= ts.SyntaxKind.LastKeyword) {\n this.addSegment(node.getStart(), node.getEnd(), this.schema.keywordColor);\n }\n }\n /**\n * Processes identifier nodes and applies appropriate syntax highlighting based on their context.\n *\n * @param node - The TypeScript AST node representing the identifier to be processed\n *\n * @remarks\n * This method determines the appropriate color for an identifier by examining its parent node's kind.\n * Different colors are applied based on the identifier's role in the code:\n * - Enum members use enumColor\n * - Interface names use interfaceColor\n * - Class names use classColor\n * - Function and method names use functionColor\n * - Parameters use parameterColor\n * - Variables and properties use variableColor\n * - Types use typeColor\n * - And more specialized cases for other syntax kinds\n *\n * Special handling is applied to property access expressions to differentiate between\n * the object being accessed and the property being accessed.\n *\n * @example\n * ```ts\n * // Inside the CodeHighlighter class\n * const identifierNode = getIdentifierNode(); // Get some identifier node\n * this.processIdentifier(identifierNode);\n * // The identifier is now added to segments with appropriate color based on its context\n * ```\n *\n * @see addSegment\n * @see HighlightSchemeInterface\n *\n * @since 1.0.0\n */\n private processIdentifier(node: ts.Node): void {\n const end = node.getEnd();\n const start = node.getStart();\n switch (node.parent.kind) {\n case ts.SyntaxKind.EnumMember:\n return this.addSegment(start, end, this.schema.enumColor);\n case ts.SyntaxKind.CallExpression:\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.PropertySignature:\n case ts.SyntaxKind.ModuleDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.InterfaceDeclaration:\n return this.addSegment(start, end, this.schema.interfaceColor);\n case ts.SyntaxKind.GetAccessor:\n return this.addSegment(start, end, this.schema.getAccessorColor);\n case ts.SyntaxKind.PropertyAssignment:\n return this.addSegment(start, end, this.schema.propertyAssignmentColor);\n case ts.SyntaxKind.MethodSignature:\n return this.addSegment(start, end, this.schema.methodSignatureColor);\n case ts.SyntaxKind.MethodDeclaration:\n case ts.SyntaxKind.FunctionDeclaration:\n return this.addSegment(start, end, this.schema.functionColor);\n case ts.SyntaxKind.ClassDeclaration:\n return this.addSegment(start, end, this.schema.classColor);\n case ts.SyntaxKind.Parameter:\n return this.addSegment(start, end, this.schema.parameterColor);\n case ts.SyntaxKind.VariableDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.PropertyDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.PropertyAccessExpression: {\n if (node.parent.getChildAt(0).getText() === node.getText()) {\n return this.addSegment(start, end, this.schema.variableColor);\n }\n return this.addSegment(start, end, this.schema.propertyAccessExpressionColor);\n }\n case ts.SyntaxKind.ExpressionWithTypeArguments:\n return this.addSegment(start, end, this.schema.expressionWithTypeArgumentsColor);\n case ts.SyntaxKind.BreakStatement:\n case ts.SyntaxKind.ShorthandPropertyAssignment:\n case ts.SyntaxKind.BindingElement:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.BinaryExpression:\n case ts.SyntaxKind.SwitchStatement:\n case ts.SyntaxKind.TemplateSpan:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.TypeReference:\n case ts.SyntaxKind.TypeAliasDeclaration:\n return this.addSegment(start, end, this.schema.typeColor);\n case ts.SyntaxKind.NewExpression:\n return this.addSegment(start, end, this.schema.variableColor);\n }\n }\n /**\n * Processes a TypeScript template expression and adds highlighting segments for its literal parts.\n *\n * @param templateExpression - The TypeScript template expression to be processed\n *\n * @remarks\n * This method adds color segments for both the template head and each template span's literal part.\n * All template string components are highlighted using the color defined in the schema's stringColor.\n *\n * @example\n * ```ts\n * // Given a template expression like: `Hello ${name}`\n * this.processTemplateExpression(templateNode);\n * // Both \"Hello \" and the closing part after the expression will be highlighted\n * ```\n *\n * @see addSegment\n *\n * @since 1.0.0\n */\n private processTemplateExpression(templateExpression: ts.TemplateExpression): void {\n const start = templateExpression.head.getStart();\n const end = templateExpression.head.getEnd();\n this.addSegment(start, end, this.schema.stringColor);\n templateExpression.templateSpans.forEach(span => {\n const spanStart = span.literal.getStart();\n const spanEnd = span.literal.getEnd();\n this.addSegment(spanStart, spanEnd, this.schema.stringColor);\n });\n }\n /**\n * Processes a TypeScript AST node and adds highlighting segments based on the node's kind.\n *\n * @param node - The TypeScript AST node to be processed\n *\n * @remarks\n * This method identifies the node's kind and applies the appropriate color for highlighting.\n * It handles various syntax kinds including literals (string, numeric, regular expressions),\n * template expressions, identifiers, and type references.\n * For complex node types like template expressions and identifiers, it delegates to specialized processing methods.\n *\n * @throws Error - When casting to TypeParameterDeclaration fails for non-compatible node kinds\n *\n * @example\n * ```ts\n * // Inside the CodeHighlighter class\n * const node = sourceFile.getChildAt(0);\n * this.processNode(node);\n * // Node is now added to the segments map with appropriate colors\n * ```\n *\n * @see processTemplateExpression\n * @see processIdentifier\n *\n * @since 1.0.0\n */\n private processNode(node: ts.Node): void {\n const start = node.getStart();\n const end = node.getEnd();\n switch (node.kind) {\n case ts.SyntaxKind.TypeParameter:\n return this.addSegment(start, start + (node as ts.TypeParameterDeclaration).name.text.length, this.schema.typeColor);\n case ts.SyntaxKind.TypeReference:\n return this.addSegment(start, end, this.schema.typeColor);\n case ts.SyntaxKind.StringLiteral:\n case ts.SyntaxKind.NoSubstitutionTemplateLiteral:\n return this.addSegment(start, end, this.schema.stringColor);\n case ts.SyntaxKind.RegularExpressionLiteral:\n return this.addSegment(start, end, this.schema.regularExpressionColor);\n case ts.SyntaxKind.TemplateExpression:\n return this.processTemplateExpression(node as ts.TemplateExpression);\n case ts.SyntaxKind.Identifier:\n return this.processIdentifier(node);\n case ts.SyntaxKind.BigIntLiteral:\n case ts.SyntaxKind.NumericLiteral:\n return this.addSegment(start, end, this.schema.numericLiteralColor);\n }\n }\n}\n/**\n * Applies semantic highlighting to the provided code string using the specified color scheme.\n *\n * @param code - The source code to be highlighted\n * @param schema - An optional partial schema defining the color styles for various code elements\n *\n * @returns A string with the code elements wrapped in the appropriate color styles\n *\n * @remarks\n * If no schema is provided, the default schema will be used. The function creates a TypeScript\n * source file from the provided code and walks through its AST to apply syntax highlighting.\n *\n * @example\n * ```ts\n * const code = 'const x: number = 42;';\n * const schema = {\n * keywordColor: '\\x1b[34m', // Blue\n * numberColor: '\\x1b[31m', // Red\n * };\n * const highlightedCode = highlightCode(code, schema);\n * console.log(highlightedCode);\n * ```\n *\n * @see CodeHighlighter\n * @see HighlightSchemeInterface\n *\n * @since 1.0.0\n */\nexport function highlightCode(code: string, schema: Partial<HighlightSchemeInterface> = {}) {\n const sourceFile = ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const codeHighlighter = new CodeHighlighter(sourceFile, code, Object.assign(defaultScheme, schema));\n function walk(node: ts.Node): void {\n codeHighlighter.parseNode(node);\n for (let i = 0; i < node.getChildCount(); i++) {\n walk(node.getChildAt(i));\n }\n }\n ts.forEachChild(sourceFile, walk);\n return codeHighlighter.highlight();\n}\n"],
6
- "mappings": "AAWA,UAAYA,MAAQ,aACpB,OAAS,cAAAC,MAAkB,aAepB,IAAWC,OACdA,EAAA,MAAQ,UACRA,EAAA,KAAO,iBACPA,EAAA,SAAW,iBACXA,EAAA,WAAa,iBACbA,EAAA,YAAc,iBACdA,EAAA,WAAa,iBACbA,EAAA,YAAc,iBACdA,EAAA,qBAAuB,iBACvBA,EAAA,YAAc,iBACdA,EAAA,aAAe,iBACfA,EAAA,W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,aAAW,cACnB,KAAQ,aAAW,eACf,OAAO,KAAK,WAAWU,EAAOC,EAAK,KAAK,OAAO,mBAAmB,CAC1E,CACJ,CACJ,EA6BO,SAASS,EAActB,EAAcC,EAA4C,CAAC,EAAG,CACxF,IAAMF,EAAgB,mBAAiB,UAAWC,EAAS,eAAa,OAAQ,GAAS,aAAW,EAAE,EAChGuB,EAAkB,IAAIzB,EAAgBC,EAAYC,EAAM,OAAO,OAAOH,EAAeI,CAAM,CAAC,EAClG,SAASuB,EAAKtB,EAAqB,CAC/BqB,EAAgB,UAAUrB,CAAI,EAC9B,QAAS,EAAI,EAAG,EAAIA,EAAK,cAAc,EAAG,IACtCsB,EAAKtB,EAAK,WAAW,CAAC,CAAC,CAE/B,CACA,OAAG,eAAaH,EAAYyB,CAAI,EACzBD,EAAgB,UAAU,CACrC",
4
+ "sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.2/",
5
+ "sourcesContent": ["/**\n * Export interfaces\n */\n\nexport type * from '@components/interfaces/highlighter-component.interface';\n\n/**\n * Import will remove at compile time\n */\n\nimport type { HighlightSchemeInterface, HighlightNodeSegmentInterface } from '@components/interfaces/highlighter-component.interface';\n\n/**\n * Imports\n */\n\nimport * as ts from 'typescript';\nimport { SyntaxKind } from 'typescript';\n\n/**\n * An enum containing ANSI escape sequences for various colors\n *\n * @remarks\n * This enum is primarily intended for terminal output and won't work directly in JavaScript for web development.\n * It defines color codes for various colors and a reset code to return to the default text color.\n *\n * @example\n * ```ts\n * console.log(`${Colors.red}This text will be red in the terminal.${Colors.reset}`);\n * ```\n *\n * @since 1.0.0\n */\n\nexport const enum Colors {\n reset = '\\x1b[0m',\n gray = '\\x1b[38;5;243m',\n darkGray = '\\x1b[38;5;238m',\n lightCoral = '\\x1b[38;5;203m',\n lightOrange = '\\x1b[38;5;215m',\n oliveGreen = '\\x1b[38;5;149m',\n burntOrange = '\\x1b[38;5;208m',\n lightGoldenrodYellow = '\\x1b[38;5;221m',\n lightYellow = '\\x1b[38;5;230m',\n canaryYellow = '\\x1b[38;5;227m',\n deepOrange = '\\x1b[38;5;166m',\n lightGray = '\\x1b[38;5;252m',\n brightPink = '\\x1b[38;5;197m'\n}\n\n/**\n * Default color scheme for semantic highlighting\n *\n * @remarks\n * This scheme defines colors for different code elements to be used for syntax highlighting.\n *\n * @example\n * ```ts\n * const scheme = defaultScheme;\n * console.log(scheme.typeColor); // Outputs: the color code for types\n * ```\n *\n * @see HighlightSchemeInterface\n * @see Colors\n *\n * @since 1.0.0\n */\n\nconst defaultScheme: HighlightSchemeInterface = {\n enumColor: Colors.burntOrange,\n typeColor: Colors.lightGoldenrodYellow,\n classColor: Colors.lightOrange,\n stringColor: Colors.oliveGreen,\n keywordColor: Colors.lightCoral,\n commentColor: Colors.darkGray,\n functionColor: Colors.lightOrange,\n variableColor: Colors.burntOrange,\n interfaceColor: Colors.lightGoldenrodYellow,\n parameterColor: Colors.deepOrange,\n getAccessorColor: Colors.lightYellow,\n numericLiteralColor: Colors.lightGray,\n methodSignatureColor: Colors.burntOrange,\n regularExpressionColor: Colors.oliveGreen,\n propertyAssignmentColor: Colors.canaryYellow,\n propertyAccessExpressionColor: Colors.lightYellow,\n expressionWithTypeArgumentsColor: Colors.lightOrange\n};\n\n/**\n * Class responsible for applying semantic highlighting to a source code string based on a given color scheme\n *\n * @remarks\n * Processes TypeScript AST nodes and applies color formatting to different code elements\n * according to the provided color scheme.\n *\n * @example\n * ```ts\n * const sourceFile = ts.createSourceFile('example.ts', code, ts.ScriptTarget.Latest);\n * const highlighter = new CodeHighlighter(sourceFile, code, customScheme);\n * highlighter.parseNode(sourceFile);\n * const highlightedCode = highlighter.highlight();\n * ```\n *\n * @since 1.0.0\n */\n\nexport class CodeHighlighter {\n\n /**\n * A Map of segments where the key is a combination of start and end positions.\n *\n * @remarks\n * This structure ensures unique segments and allows for fast lookups and updates.\n *\n * @see HighlightNodeSegmentInterface\n * @since 1.0.0\n */\n\n private segments: Map<string, HighlightNodeSegmentInterface> = new Map();\n\n /**\n * Creates an instance of the CodeHighlighter class.\n *\n * @param sourceFile - The TypeScript AST node representing the source file\n * @param code - The source code string to be highlighted\n * @param schema - The color scheme used for highlighting different elements in the code\n *\n * @since 1.0.0\n */\n\n constructor(private sourceFile: ts.Node, private code: string, private schema: HighlightSchemeInterface) {\n }\n\n /**\n * Parses a TypeScript AST node and processes its comments to identify segments that need highlighting.\n *\n * @param node - The TypeScript AST node to be parsed\n *\n * @since 1.0.0\n */\n\n parseNode(node: ts.Node): void {\n this.processComments(node);\n this.processKeywords(node);\n this.processNode(node);\n }\n\n /**\n * Generates a string with highlighted code segments based on the provided color scheme.\n *\n * @returns The highlighted code as a string, with ANSI color codes applied to the segments\n *\n * @remarks\n * This method processes the stored segments, applies the appropriate colors to each segment,\n * and returns the resulting highlighted code as a single string.\n *\n * @since 1.0.0\n */\n\n highlight(): string {\n let previousSegmentEnd = 0;\n let parent: HighlightNodeSegmentInterface | undefined;\n\n const result: Array<string> = [];\n const segments = Array.from(\n this.segments.values()\n ).sort((a, b) => a.start - b.start || a.end - b.end);\n\n segments.forEach((segment) => {\n if (parent && segment.start < parent.end) {\n const lastSegment = result.pop();\n if (!lastSegment) return;\n\n const source = this.getSegmentSource(segment.start, segment.end);\n const combinedSource = `${ segment.color }${ source }${ parent.color }`;\n result.push(lastSegment.replace(source, combinedSource));\n\n return;\n }\n\n result.push(this.getSegmentSource(previousSegmentEnd, segment.start));\n result.push(`${ segment.color }${ this.getSegmentSource(segment.start, segment.end) }${ segment.reset }`);\n previousSegmentEnd = segment.end;\n parent = segment;\n });\n\n return result.join('') + this.getSegmentSource(previousSegmentEnd);\n }\n\n /**\n * Extracts a text segment from the source code using position indices.\n *\n * @param start - The starting index position in the source text\n * @param end - The ending index position in the source text (optional)\n * @returns The substring of source text between the start and end positions\n *\n * @remarks\n * This utility method provides access to specific portions of the source code\n * based on character positions. When the end parameter is omitted, the extraction\n * will continue to the end of the source text.\n *\n * This method is typically used during the highlighting process to access the\n * actual text content that corresponds to syntax nodes or other text ranges\n * before applying formatting.\n *\n * @example\n * ```ts\n * // Extract a variable name\n * const variableName = this.getSegmentSource(10, 15);\n *\n * // Extract from a position to the end of source\n * const remaining = this.getSegmentSource(100);\n * ```\n *\n * @see addSegment\n * @see highlight\n *\n * @since 1.0.0\n */\n\n private getSegmentSource(start: number, end?: number): string {\n return this.code.slice(start, end);\n }\n\n /**\n * Registers a text segment for syntax highlighting with specified style information.\n *\n * @param start - The starting position of the segment in the source text\n * @param end - The ending position of the segment in the source text\n * @param color - The color code to apply to this segment\n * @param reset - The color reset code to apply after the segment (defaults to the standard reset code)\n *\n * @remarks\n * This method creates a unique key for each segment based on its position and stores the segment information in a map.\n * Each segment contains its position information, styling code,\n * and reset code which will later be used during the highlighting process.\n *\n * If multiple segments are added with the same positions, the later additions will\n * overwrite earlier ones due to the map's key-based storage.\n *\n * @example\n * ```ts\n * // Highlight a variable name in red\n * this.addSegment(10, 15, Colors.red);\n *\n * // Highlight a keyword with custom color and reset\n * this.addSegment(20, 26, Colors.blue, Colors.customReset);\n * ```\n *\n * @see Colors\n * @see processNode\n *\n * @since 1.0.0\n */\n\n private addSegment(start: number, end: number, color: string, reset: string = Colors.reset) {\n const key = `${ start }-${ end }`;\n this.segments.set(key, { start, end, color, reset });\n }\n\n /**\n * Processes and highlights comments associated with a TypeScript AST node.\n *\n * @param node - The TypeScript AST node whose comments are to be processed\n *\n * @remarks\n * This method identifies both leading and trailing comments associated with the given node\n * and adds them to the highlighting segments.\n * The comments are extracted from the full source text using TypeScript's utility functions\n * and are highlighted using the color specified\n * in the schema's commentColor property.\n *\n * Leading comments appear before the node, while trailing comments appear after it.\n * Both types are processed with the same highlighting style.\n *\n * @example\n * ```ts\n * // For a node that might have comments like:\n * // This is a leading comment\n * const x = 5; // This is a trailing comment\n *\n * this.processComments(someNode);\n * // Both comments will be added to segments with the comment color\n * ```\n *\n * @see addSegment\n * @see ts.getLeadingCommentRanges\n * @see ts.getTrailingCommentRanges\n *\n * @since 1.0.0\n */\n\n private processComments(node: ts.Node): void {\n const comments = [\n ...ts.getTrailingCommentRanges(this.sourceFile.getFullText(), node.getFullStart()) || [],\n ...ts.getLeadingCommentRanges(this.sourceFile.getFullText(), node.getFullStart()) || []\n ];\n\n comments.forEach(comment => this.addSegment(comment.pos, comment.end, this.schema.commentColor));\n }\n\n /**\n * Processes TypeScript keywords and primitive type references in an AST node for syntax highlighting.\n *\n * @param node - The TypeScript AST node to be processed for keywords\n *\n * @remarks\n * This method handles two categories of tokens that require special highlighting:\n *\n * 1. Primitive type references: Highlights references to built-in types like `null`,\n * `void`, `string`, `number`, `boolean`, and `undefined` using the type color.\n *\n * 2. TypeScript keywords: Identifies any node whose kind falls within the TypeScript\n * keyword range (between FirstKeyword and LastKeyword) and highlights it using\n * the keyword color.\n *\n * Each identified token is added to the segments collection with appropriate position\n * and color information.\n *\n * @example\n * ```ts\n * // Inside syntax highlighting process\n * this.processKeywords(someNode);\n * // If the node represents a keyword like 'const' or a primitive type like 'string',\n * // it will be added to the segments with the appropriate color\n * ```\n *\n * @see addSegment\n * @see ts.SyntaxKind\n *\n * @since 1.0.0\n */\n\n private processKeywords(node: ts.Node): void {\n if ([\n SyntaxKind.NullKeyword,\n SyntaxKind.VoidKeyword,\n SyntaxKind.StringKeyword,\n SyntaxKind.NumberKeyword,\n SyntaxKind.BooleanKeyword,\n SyntaxKind.UndefinedKeyword\n ].includes(node.kind)) {\n return this.addSegment(node.getStart(), node.getEnd(), this.schema.typeColor);\n }\n\n if (node && node.kind >= ts.SyntaxKind.FirstKeyword && node.kind <= ts.SyntaxKind.LastKeyword) {\n this.addSegment(node.getStart(), node.getEnd(), this.schema.keywordColor);\n }\n }\n\n /**\n * Processes identifier nodes and applies appropriate syntax highlighting based on their context.\n *\n * @param node - The TypeScript AST node representing the identifier to be processed\n *\n * @remarks\n * This method determines the appropriate color for an identifier by examining its parent node's kind.\n * Different colors are applied based on the identifier's role in the code:\n * - Enum members use enumColor\n * - Interface names use interfaceColor\n * - Class names use classColor\n * - Function and method names use functionColor\n * - Parameters use parameterColor\n * - Variables and properties use variableColor\n * - Types use typeColor\n * - And more specialized cases for other syntax kinds\n *\n * Special handling is applied to property access expressions to differentiate between\n * the object being accessed and the property being accessed.\n *\n * @example\n * ```ts\n * // Inside the CodeHighlighter class\n * const identifierNode = getIdentifierNode(); // Get some identifier node\n * this.processIdentifier(identifierNode);\n * // The identifier is now added to segments with appropriate color based on its context\n * ```\n *\n * @see addSegment\n * @see HighlightSchemeInterface\n *\n * @since 1.0.0\n */\n\n private processIdentifier(node: ts.Node): void {\n const end = node.getEnd();\n const start = node.getStart();\n\n switch (node.parent.kind) {\n case ts.SyntaxKind.EnumMember:\n return this.addSegment(start, end, this.schema.enumColor);\n case ts.SyntaxKind.CallExpression:\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.PropertySignature:\n case ts.SyntaxKind.ModuleDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.InterfaceDeclaration:\n return this.addSegment(start, end, this.schema.interfaceColor);\n case ts.SyntaxKind.GetAccessor:\n return this.addSegment(start, end, this.schema.getAccessorColor);\n case ts.SyntaxKind.PropertyAssignment:\n return this.addSegment(start, end, this.schema.propertyAssignmentColor);\n case ts.SyntaxKind.MethodSignature:\n return this.addSegment(start, end, this.schema.methodSignatureColor);\n case ts.SyntaxKind.MethodDeclaration:\n case ts.SyntaxKind.FunctionDeclaration:\n return this.addSegment(start, end, this.schema.functionColor);\n case ts.SyntaxKind.ClassDeclaration:\n return this.addSegment(start, end, this.schema.classColor);\n case ts.SyntaxKind.Parameter:\n return this.addSegment(start, end, this.schema.parameterColor);\n case ts.SyntaxKind.VariableDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.PropertyDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.PropertyAccessExpression: {\n if (node.parent.getChildAt(0).getText() === node.getText()) {\n return this.addSegment(start, end, this.schema.variableColor);\n }\n\n return this.addSegment(start, end, this.schema.propertyAccessExpressionColor);\n }\n case ts.SyntaxKind.ExpressionWithTypeArguments:\n return this.addSegment(start, end, this.schema.expressionWithTypeArgumentsColor);\n case ts.SyntaxKind.BreakStatement:\n case ts.SyntaxKind.ShorthandPropertyAssignment:\n case ts.SyntaxKind.BindingElement:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.BinaryExpression:\n case ts.SyntaxKind.SwitchStatement:\n case ts.SyntaxKind.TemplateSpan:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.TypeReference:\n case ts.SyntaxKind.TypeAliasDeclaration:\n return this.addSegment(start, end, this.schema.typeColor);\n case ts.SyntaxKind.NewExpression:\n return this.addSegment(start, end, this.schema.variableColor);\n }\n }\n\n /**\n * Processes a TypeScript template expression and adds highlighting segments for its literal parts.\n *\n * @param templateExpression - The TypeScript template expression to be processed\n *\n * @remarks\n * This method adds color segments for both the template head and each template span's literal part.\n * All template string components are highlighted using the color defined in the schema's stringColor.\n *\n * @example\n * ```ts\n * // Given a template expression like: `Hello ${name}`\n * this.processTemplateExpression(templateNode);\n * // Both \"Hello \" and the closing part after the expression will be highlighted\n * ```\n *\n * @see addSegment\n *\n * @since 1.0.0\n */\n\n private processTemplateExpression(templateExpression: ts.TemplateExpression): void {\n const start = templateExpression.head.getStart();\n const end = templateExpression.head.getEnd();\n this.addSegment(start, end, this.schema.stringColor);\n\n templateExpression.templateSpans.forEach(span => {\n const spanStart = span.literal.getStart();\n const spanEnd = span.literal.getEnd();\n this.addSegment(spanStart, spanEnd, this.schema.stringColor);\n });\n }\n\n /**\n * Processes a TypeScript AST node and adds highlighting segments based on the node's kind.\n *\n * @param node - The TypeScript AST node to be processed\n *\n * @remarks\n * This method identifies the node's kind and applies the appropriate color for highlighting.\n * It handles various syntax kinds including literals (string, numeric, regular expressions),\n * template expressions, identifiers, and type references.\n * For complex node types like template expressions and identifiers, it delegates to specialized processing methods.\n *\n * @throws Error - When casting to TypeParameterDeclaration fails for non-compatible node kinds\n *\n * @example\n * ```ts\n * // Inside the CodeHighlighter class\n * const node = sourceFile.getChildAt(0);\n * this.processNode(node);\n * // Node is now added to the segments map with appropriate colors\n * ```\n *\n * @see processTemplateExpression\n * @see processIdentifier\n *\n * @since 1.0.0\n */\n\n private processNode(node: ts.Node): void {\n const start = node.getStart();\n const end = node.getEnd();\n\n switch (node.kind) {\n case ts.SyntaxKind.TypeParameter:\n return this.addSegment(start, start + (node as ts.TypeParameterDeclaration).name.text.length, this.schema.typeColor);\n case ts.SyntaxKind.TypeReference:\n return this.addSegment(start, end, this.schema.typeColor);\n case ts.SyntaxKind.StringLiteral:\n case ts.SyntaxKind.NoSubstitutionTemplateLiteral:\n return this.addSegment(start, end, this.schema.stringColor);\n case ts.SyntaxKind.RegularExpressionLiteral:\n return this.addSegment(start, end, this.schema.regularExpressionColor);\n case ts.SyntaxKind.TemplateExpression:\n return this.processTemplateExpression(node as ts.TemplateExpression);\n case ts.SyntaxKind.Identifier:\n return this.processIdentifier(node);\n case ts.SyntaxKind.BigIntLiteral:\n case ts.SyntaxKind.NumericLiteral:\n return this.addSegment(start, end, this.schema.numericLiteralColor);\n }\n }\n}\n\n/**\n * Applies semantic highlighting to the provided code string using the specified color scheme.\n *\n * @param code - The source code to be highlighted\n * @param schema - An optional partial schema defining the color styles for various code elements\n *\n * @returns A string with the code elements wrapped in the appropriate color styles\n *\n * @remarks\n * If no schema is provided, the default schema will be used. The function creates a TypeScript\n * source file from the provided code and walks through its AST to apply syntax highlighting.\n *\n * @example\n * ```ts\n * const code = 'const x: number = 42;';\n * const schema = {\n * keywordColor: '\\x1b[34m', // Blue\n * numberColor: '\\x1b[31m', // Red\n * };\n * const highlightedCode = highlightCode(code, schema);\n * console.log(highlightedCode);\n * ```\n *\n * @see CodeHighlighter\n * @see HighlightSchemeInterface\n *\n * @since 1.0.0\n */\n\nexport function highlightCode(code: string, schema: Partial<HighlightSchemeInterface> = {}) {\n const sourceFile = ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const codeHighlighter = new CodeHighlighter(sourceFile, code, Object.assign(defaultScheme, schema));\n\n function walk(node: ts.Node): void {\n codeHighlighter.parseNode(node);\n\n for (let i = 0; i < node.getChildCount(); i++) {\n walk(node.getChildAt(i));\n }\n } ts.forEachChild(sourceFile, walk);\n\n return codeHighlighter.highlight();\n}\n"],
6
+ "mappings": "AAgBA,UAAYA,MAAQ,aACpB,OAAS,cAAAC,MAAkB,aAiBpB,IAAWC,OACdA,EAAA,MAAQ,UACRA,EAAA,KAAO,iBACPA,EAAA,SAAW,iBACXA,EAAA,WAAa,iBACbA,EAAA,YAAc,iBACdA,EAAA,WAAa,iBACbA,EAAA,YAAc,iBACdA,EAAA,qBAAuB,iBACvBA,EAAA,YAAc,iBACdA,EAAA,aAAe,iBACfA,EAAA,WAAa,iBACbA,EAAA,UAAY,iBACZA,EAAA,WAAa,iBAbCA,OAAA,IAkCZC,EAA0C,CAC5C,UAAW,iBACX,UAAW,iBACX,WAAY,iBACZ,YAAa,iBACb,aAAc,iBACd,aAAc,iBACd,cAAe,iBACf,cAAe,iBACf,eAAgB,iBAChB,eAAgB,iBAChB,iBAAkB,iBAClB,oBAAqB,iBACrB,qBAAsB,iBACtB,uBAAwB,iBACxB,wBAAyB,iBACzB,8BAA+B,iBAC/B,iCAAkC,gBACtC,EAoBaC,EAAN,KAAsB,CAwBzB,YAAoBC,EAA6BC,EAAsBC,EAAkC,CAArF,gBAAAF,EAA6B,UAAAC,EAAsB,YAAAC,CACvE,CAbQ,SAAuD,IAAI,IAuBnE,UAAUC,EAAqB,CAC3B,KAAK,gBAAgBA,CAAI,EACzB,KAAK,gBAAgBA,CAAI,EACzB,KAAK,YAAYA,CAAI,CACzB,CAcA,WAAoB,CAChB,IAAIC,EAAqB,EACrBC,EAEEC,EAAwB,CAAC,EAK/B,OAJiB,MAAM,KACnB,KAAK,SAAS,OAAO,CACzB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,YAAYnB,EAAqB,CACrC,IAAMU,EAAQV,EAAK,SAAS,EACtBW,EAAMX,EAAK,OAAO,EAExB,OAAQA,EAAK,KAAM,CACf,KAAQ,aAAW,cACf,OAAO,KAAK,WAAWU,EAAOA,EAASV,EAAqC,KAAK,KAAK,OAAQ,KAAK,OAAO,SAAS,EACvH,KAAQ,aAAW,cACf,OAAO,KAAK,WAAWU,EAAOC,EAAK,KAAK,OAAO,SAAS,EAC5D,KAAQ,aAAW,cACnB,KAAQ,aAAW,8BACf,OAAO,KAAK,WAAWD,EAAOC,EAAK,KAAK,OAAO,WAAW,EAC9D,KAAQ,aAAW,yBACf,OAAO,KAAK,WAAWD,EAAOC,EAAK,KAAK,OAAO,sBAAsB,EACzE,KAAQ,aAAW,mBACf,OAAO,KAAK,0BAA0BX,CAA6B,EACvE,KAAQ,aAAW,WACf,OAAO,KAAK,kBAAkBA,CAAI,EACtC,KAAQ,aAAW,cACnB,KAAQ,aAAW,eACf,OAAO,KAAK,WAAWU,EAAOC,EAAK,KAAK,OAAO,mBAAmB,CAC1E,CACJ,CACJ,EA+BO,SAASS,EAActB,EAAcC,EAA4C,CAAC,EAAG,CACxF,IAAMF,EAAgB,mBAAiB,UAAWC,EAAS,eAAa,OAAQ,GAAS,aAAW,EAAE,EAChGuB,EAAkB,IAAIzB,EAAgBC,EAAYC,EAAM,OAAO,OAAOH,EAAeI,CAAM,CAAC,EAElG,SAASuB,EAAKtB,EAAqB,CAC/BqB,EAAgB,UAAUrB,CAAI,EAE9B,QAAS,EAAI,EAAG,EAAIA,EAAK,cAAc,EAAG,IACtCsB,EAAKtB,EAAK,WAAW,CAAC,CAAC,CAE/B,CAAE,OAAG,eAAaH,EAAYyB,CAAI,EAE3BD,EAAgB,UAAU,CACrC",
7
7
  "names": ["ts", "SyntaxKind", "Colors", "defaultScheme", "CodeHighlighter", "sourceFile", "code", "schema", "node", "previousSegmentEnd", "parent", "result", "a", "b", "segment", "lastSegment", "source", "combinedSource", "start", "end", "color", "reset", "key", "comment", "templateExpression", "span", "spanStart", "spanEnd", "highlightCode", "codeHighlighter", "walk"]
8
8
  }
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var h={},I="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");I.forEach((u,e)=>{h[u]=e});function S(u){let e=u<0,n="",r=e?(-u<<1)+1:u<<1;do{let t=r&31;r>>>=5,n+=I[t|(r>0?32:0)]}while(r>0);return n}function m(u){return u.map(S).join("")}function p(u){let e=[],n=0,r=0;for(let t=0;t<u.length;t++){let o=h[u[t]];if(o===void 0)throw new Error(`Invalid Base64 character: ${u[t]}`);let i=o&32;if(r+=(o&31)<<n,i)n+=5;else{let s=(r&1)===1,a=r>>1;e.push(s?-a:a),r=n=0}}return e}var d=class u{mapping=[];constructor(e,n=0,r=0){e=e instanceof u?e.mapping:e,Array.isArray(e)?this.decodeMappingArray(e,n,r):this.decodeMappingString(e,n,r)}encode(){return this.encodeMappings(this.mapping)}decode(e,n=0,r=0){e=e instanceof u?e.mapping:e,Array.isArray(e)?this.decodeMappingArray(e,n,r):this.decodeMappingString(e,n,r)}getSegment(e,n,r=0){let t=this.mapping[e-1];if(!t||t.length===0)return null;let o=0,i=t.length-1,s=null;for(;o<=i;){let a=Math.floor((o+i)/2),c=t[a];if(c.generatedColumn<n)o=a+1,s=r===1?c:s;else if(c.generatedColumn>n)i=a-1,s=r===2?c:s;else return c}return s}getOriginalSegment(e,n,r,t=0){let o=null;for(let i of this.mapping){if(!i)continue;let s=0,a=i.length-1;for(;s<=a;){let c=Math.floor((s+a)/2),l=i[c];if(l.sourceIndex<r||l.line<e)s=c+1;else if(l.sourceIndex>r||l.line>e)a=c-1;else if(l.column<n)s=c+1,o=t===1?l:o;else if(l.column>n)a=c-1,o=t===2?l:o;else return l}}return o}initPositionOffsets(e=0,n=0){return{line:0,column:0,nameIndex:e,sourceIndex:n,generatedLine:0,generatedColumn:0}}validateMappingString(e){return/^[a-zA-Z0-9+/,;]+$/.test(e)}validateSegment(e){if(!Number.isFinite(e.line))throw new Error(`Invalid segment: line must be a finite number, received ${e.line}`);if(!Number.isFinite(e.column))throw new Error(`Invalid segment: column must be a finite number, received ${e.column}`);if(e.nameIndex!==null&&!Number.isFinite(e.nameIndex))throw new Error(`Invalid segment: nameIndex must be a number or null, received ${e.nameIndex}`);if(!Number.isFinite(e.sourceIndex))throw new Error(`Invalid segment: sourceIndex must be a finite number, received ${e.sourceIndex}`);if(!Number.isFinite(e.generatedLine))throw new Error(`Invalid segment: generatedLine must be a finite number, received ${e.generatedLine}`);if(!Number.isFinite(e.generatedColumn))throw new Error(`Invalid segment: generatedColumn must be a finite number, received ${e.generatedColumn}`)}encodeSegment(e,n){let{line:r,column:t,generatedColumn:o,nameIndex:i,sourceIndex:s}=n,a=r-1,c=t-1,l=o-1,f=[l-e.generatedColumn,s!==e.sourceIndex?s-e.sourceIndex:0,a-e.line,c-e.column];return i!=null&&(f[4]=i-e.nameIndex,e.nameIndex=i),e.line=a,e.column=c,e.generatedColumn=l,e.sourceIndex=s,m(f)}encodeMappings(e){let n=this.initPositionOffsets();return e.map(r=>r?(n.generatedColumn=0,r.map(o=>this.encodeSegment(n,o)).join(",")):"").join(";")}decodedSegment(e,n){let[r,t,o,i,s]=n;return e.line+=o,e.column+=i,e.nameIndex+=s??0,e.sourceIndex+=t,e.generatedColumn+=r,{line:e.line+1,column:e.column+1,nameIndex:s!==void 0?e.nameIndex:null,sourceIndex:e.sourceIndex,generatedLine:e.generatedLine+1,generatedColumn:e.generatedColumn+1}}decodeMappingString(e,n,r){if(!this.validateMappingString(e))throw new Error("Invalid Mappings string format: the provided string does not conform to expected VLQ format.");let t=e.split(";"),o=this.mapping.length,i=this.initPositionOffsets(n,r);try{t.forEach((s,a)=>{if(!s){this.mapping.push(null);return}i.generatedColumn=0,i.generatedLine=o+a;let c=s.split(",").map(l=>this.decodedSegment(i,p(l)));this.mapping.push(c)})}catch(s){throw new Error(`Error decoding mappings at frame index ${t.length}: ${s.message}`)}}decodeMappingArray(e,n,r){let t=this.mapping.length;if(!Array.isArray(e))throw new Error("Invalid encoded map: expected an array of frames.");try{e.forEach((o,i)=>{if(!o){this.mapping.push(o);return}if(!Array.isArray(o))throw new Error(`Invalid Mappings array format at frame index ${i}: expected an array, received ${typeof o}.`);let s=o.map(a=>(this.validateSegment(a),{...a,nameIndex:typeof a.nameIndex=="number"?a.nameIndex+n:null,sourceIndex:a.sourceIndex+r,generatedLine:a.generatedLine+t}));this.mapping.push(s)})}catch(o){let i=o instanceof Error?o.message:"Unknown error";throw new Error(`Error decoding mappings: ${i}`)}}};var g=class u{file;mappings;sourceRoot;names;sources;sourcesContent;constructor(e,n=null){typeof e=="string"&&(e=JSON.parse(e)),e=e,this.validateSourceMap(e),this.file=e.file??n,this.names=[...e.names??[]],this.sources=[...e.sources??[]],this.sourceRoot=e.sourceRoot??null,this.sourcesContent=e.sourcesContent?[...e.sourcesContent]:[],this.mappings=new d(e.mappings)}getMapObject(){let e={version:3,names:this.names,sources:this.sources,mappings:this.mappings.encode(),sourcesContent:this.sourcesContent};return this.file&&(e.file=this.file),this.sourceRoot&&(e.sourceRoot=this.sourceRoot),e}concat(...e){if(e.length<1)throw new Error("At least one map must be provided for concatenation.");for(let n of e)this.mappings.decode(n.mappings,this.names.length,this.sources.length),this.names.push(...n.names),this.sources.push(...n.sources),this.sourcesContent.push(...n.sourcesContent??[])}concatNewMap(...e){if(e.length<1)throw new Error("At least one map must be provided for concatenation.");let n=new u(this);for(let r of e)n.mappings.decode(r.mappings,n.names.length,n.sources.length),n.names.push(...r.names),n.sources.push(...r.sources),n.sourcesContent.push(...r.sourcesContent??[]);return n}getPositionByOriginal(e,n,r,t=0){let o=r;if(typeof r=="string"&&(o=this.sources.findIndex(s=>s.includes(r))),o<0)return null;let i=this.mappings.getOriginalSegment(e,n,o,t);return i?{name:this.names[i.nameIndex??-1]??null,line:i.line,column:i.column,source:this.sources[i.sourceIndex],sourceRoot:this.sourceRoot,sourceIndex:i.sourceIndex,generatedLine:i.generatedLine,generatedColumn:i.generatedColumn}:null}getPosition(e,n,r=0){let t=this.mappings.getSegment(e,n,r);return t?{name:this.names[t.nameIndex??-1]??null,line:t.line,column:t.column,source:this.sources[t.sourceIndex],sourceRoot:this.sourceRoot,sourceIndex:t.sourceIndex,generatedLine:t.generatedLine,generatedColumn:t.generatedColumn}:null}getPositionWithContent(e,n,r=0){let t=this.getPosition(e,n,r);return t?{...t,sourcesContent:this.sourcesContent[t.sourceIndex]}:null}getPositionWithCode(e,n,r=0,t){let o=this.getPosition(e,n,r);if(!o||!this.sourcesContent[o.sourceIndex])return null;let i=Object.assign({linesAfter:4,linesBefore:3},t),s=this.sourcesContent[o.sourceIndex].split(`
1
+ var p={},g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");g.forEach((u,e)=>{p[u]=e});function S(u){let e=u<0,n="",r=e?(-u<<1)+1:u<<1;do{let t=r&31;r>>>=5,n+=g[t|(r>0?32:0)]}while(r>0);return n}function f(u){return u.map(S).join("")}function h(u){let e=[],n=0,r=0;for(let t=0;t<u.length;t++){let o=p[u[t]];if(o===void 0)throw new Error(`Invalid Base64 character: ${u[t]}`);let i=o&32;if(r+=(o&31)<<n,i)n+=5;else{let s=(r&1)===1,a=r>>1;e.push(s?-a:a),r=n=0}}return e}var d=class u{mapping=[];constructor(e,n=0,r=0){e=e instanceof u?e.mapping:e,Array.isArray(e)?this.decodeMappingArray(e,n,r):this.decodeMappingString(e,n,r)}encode(){return this.encodeMappings(this.mapping)}decode(e,n=0,r=0){e=e instanceof u?e.mapping:e,Array.isArray(e)?this.decodeMappingArray(e,n,r):this.decodeMappingString(e,n,r)}getSegment(e,n,r=0){let t=this.mapping[e-1];if(!t||t.length===0)return null;let o=0,i=t.length-1,s=null;for(;o<=i;){let a=Math.floor((o+i)/2),c=t[a];if(c.generatedColumn<n)o=a+1,s=r===1?c:s;else if(c.generatedColumn>n)i=a-1,s=r===2?c:s;else return c}return s}getOriginalSegment(e,n,r,t=0){let o=null;for(let i of this.mapping){if(!i)continue;let s=0,a=i.length-1;for(;s<=a;){let c=Math.floor((s+a)/2),l=i[c];if(l.sourceIndex<r||l.line<e)s=c+1;else if(l.sourceIndex>r||l.line>e)a=c-1;else if(l.column<n)s=c+1,o=t===1?l:o;else if(l.column>n)a=c-1,o=t===2?l:o;else return l}}return o}initPositionOffsets(e=0,n=0){return{line:0,column:0,nameIndex:e,sourceIndex:n,generatedLine:0,generatedColumn:0}}validateMappingString(e){return/^[a-zA-Z0-9+/,;]+$/.test(e)}validateSegment(e){if(!Number.isFinite(e.line))throw new Error(`Invalid segment: line must be a finite number, received ${e.line}`);if(!Number.isFinite(e.column))throw new Error(`Invalid segment: column must be a finite number, received ${e.column}`);if(e.nameIndex!==null&&!Number.isFinite(e.nameIndex))throw new Error(`Invalid segment: nameIndex must be a number or null, received ${e.nameIndex}`);if(!Number.isFinite(e.sourceIndex))throw new Error(`Invalid segment: sourceIndex must be a finite number, received ${e.sourceIndex}`);if(!Number.isFinite(e.generatedLine))throw new Error(`Invalid segment: generatedLine must be a finite number, received ${e.generatedLine}`);if(!Number.isFinite(e.generatedColumn))throw new Error(`Invalid segment: generatedColumn must be a finite number, received ${e.generatedColumn}`)}encodeSegment(e,n){let{line:r,column:t,generatedColumn:o,nameIndex:i,sourceIndex:s}=n,a=r-1,c=t-1,l=o-1,m=[l-e.generatedColumn,s!==e.sourceIndex?s-e.sourceIndex:0,a-e.line,c-e.column];return i!=null&&(m[4]=i-e.nameIndex,e.nameIndex=i),e.line=a,e.column=c,e.generatedColumn=l,e.sourceIndex=s,f(m)}encodeMappings(e){let n=this.initPositionOffsets();return e.map(r=>r?(n.generatedColumn=0,r.map(o=>this.encodeSegment(n,o)).join(",")):"").join(";")}decodedSegment(e,n){let[r,t,o,i,s]=n;return e.line+=o,e.column+=i,e.nameIndex+=s??0,e.sourceIndex+=t,e.generatedColumn+=r,{line:e.line+1,column:e.column+1,nameIndex:s!==void 0?e.nameIndex:null,sourceIndex:e.sourceIndex,generatedLine:e.generatedLine+1,generatedColumn:e.generatedColumn+1}}decodeMappingString(e,n,r){if(!this.validateMappingString(e))throw new Error("Invalid Mappings string format: the provided string does not conform to expected VLQ format.");let t=e.split(";"),o=this.mapping.length,i=this.initPositionOffsets(n,r);try{t.forEach((s,a)=>{if(!s){this.mapping.push(null);return}i.generatedColumn=0,i.generatedLine=o+a;let c=s.split(",").map(l=>this.decodedSegment(i,h(l)));this.mapping.push(c)})}catch(s){throw new Error(`Error decoding mappings at frame index ${t.length}: ${s.message}`)}}decodeMappingArray(e,n,r){let t=this.mapping.length;if(!Array.isArray(e))throw new Error("Invalid encoded map: expected an array of frames.");try{e.forEach((o,i)=>{if(!o){this.mapping.push(o);return}if(!Array.isArray(o))throw new Error(`Invalid Mappings array format at frame index ${i}: expected an array, received ${typeof o}.`);let s=o.map(a=>(this.validateSegment(a),{...a,nameIndex:typeof a.nameIndex=="number"?a.nameIndex+n:null,sourceIndex:a.sourceIndex+r,generatedLine:a.generatedLine+t}));this.mapping.push(s)})}catch(o){let i=o instanceof Error?o.message:"Unknown error";throw new Error(`Error decoding mappings: ${i}`)}}};var I=class u{file;mappings;sourceRoot;names;sources;sourcesContent;constructor(e,n=null){typeof e=="string"&&(e=JSON.parse(e)),e=e,this.validateSourceMap(e),this.file=e.file??n,this.names=[...e.names??[]],this.sources=[...e.sources??[]],this.sourceRoot=e.sourceRoot??null,this.sourcesContent=e.sourcesContent?[...e.sourcesContent]:[],this.mappings=new d(e.mappings)}getMapObject(){let e={version:3,names:this.names,sources:this.sources,mappings:this.mappings.encode(),sourcesContent:this.sourcesContent};return this.file&&(e.file=this.file),this.sourceRoot&&(e.sourceRoot=this.sourceRoot),e}concat(...e){if(e.length<1)throw new Error("At least one map must be provided for concatenation.");for(let n of e)this.mappings.decode(n.mappings,this.names.length,this.sources.length),this.names.push(...n.names),this.sources.push(...n.sources),this.sourcesContent.push(...n.sourcesContent??[])}concatNewMap(...e){if(e.length<1)throw new Error("At least one map must be provided for concatenation.");let n=new u(this);for(let r of e)n.mappings.decode(r.mappings,n.names.length,n.sources.length),n.names.push(...r.names),n.sources.push(...r.sources),n.sourcesContent.push(...r.sourcesContent??[]);return n}getPositionByOriginal(e,n,r,t=0){let o=r;if(typeof r=="string"&&(o=this.sources.findIndex(s=>s.includes(r))),o<0)return null;let i=this.mappings.getOriginalSegment(e,n,o,t);return i?{name:this.names[i.nameIndex??-1]??null,line:i.line,column:i.column,source:this.sources[i.sourceIndex],sourceRoot:this.sourceRoot,sourceIndex:i.sourceIndex,generatedLine:i.generatedLine,generatedColumn:i.generatedColumn}:null}getPosition(e,n,r=0){let t=this.mappings.getSegment(e,n,r);return t?{name:this.names[t.nameIndex??-1]??null,line:t.line,column:t.column,source:this.sources[t.sourceIndex],sourceRoot:this.sourceRoot,sourceIndex:t.sourceIndex,generatedLine:t.generatedLine,generatedColumn:t.generatedColumn}:null}getPositionWithContent(e,n,r=0){let t=this.getPosition(e,n,r);return t?{...t,sourcesContent:this.sourcesContent[t.sourceIndex]}:null}getPositionWithCode(e,n,r=0,t){let o=this.getPosition(e,n,r);if(!o||!this.sourcesContent[o.sourceIndex])return null;let i=Object.assign({linesAfter:4,linesBefore:3},t),s=this.sourcesContent[o.sourceIndex].split(`
2
2
  `),a=Math.min((o.line??1)+i.linesAfter,s.length),c=Math.max((o.line??1)-i.linesBefore,0),l=s.slice(c,Math.min(a+1,s.length)).join(`
3
- `);return{...o,code:l,endLine:a,startLine:c}}toString(){return JSON.stringify(this.getMapObject())}validateSourceMap(e){if(!["sources","mappings","names"].every(r=>r in e))throw new Error("Missing required keys in SourceMap.")}};export{g as SourceService,p as decodeVLQ,m as encodeArrayVLQ,S as encodeVLQ};
3
+ `);return{...o,code:l,endLine:a,startLine:c}}toString(){return JSON.stringify(this.getMapObject())}validateSourceMap(e){if(!["sources","mappings","names"].every(r=>r in e))throw new Error("Missing required keys in SourceMap.")}};export{I as SourceService,h as decodeVLQ,f as encodeArrayVLQ,S as encodeVLQ};
4
4
  //# sourceMappingURL=index.js.map