{"version":3,"sources":["../../src/utils/code-block.ts"],"sourcesContent":["/**\n * Removes leading and trailing whitespace from a code block string.\n * @param code - The code block string to process.\n * @returns The processed code block string.\n */\nexport function codeBlock(code: string): string {\n  if (!code) {\n    throw new Error('Input string cannot be empty');\n  }\n\n  // Remove the new line at the start of the code\n  const newCode = code.replace(/^\\n/, '');\n\n  // Get the whitespace from the first line\n  const match = newCode.match(/^(\\s+)/);\n  const whitespace = match ? match[1] : '';\n\n  // Decrease code indentation by the length of the whitespace from the first line\n  const lines = newCode.split('\\n').map((s) => s.replace(whitespace, ''));\n\n  // Remove all whitespace from the last line\n  const lastLine = lines.at(-1)?.replaceAll(/\\s/g, '');\n  if (lastLine?.length === 0) {\n    lines[lines.length - 1] = '';\n  } else {\n    lines.push('');\n  }\n\n  return lines.join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,UAAU,MAAsB;AAC9C,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAGA,QAAM,UAAU,KAAK,QAAQ,OAAO,EAAE;AAGtC,QAAM,QAAQ,QAAQ,MAAM,QAAQ;AACpC,QAAM,aAAa,QAAQ,MAAM,CAAC,IAAI;AAGtC,QAAM,QAAQ,QAAQ,MAAM,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,YAAY,EAAE,CAAC;AAGtE,QAAM,WAAW,MAAM,GAAG,EAAE,GAAG,WAAW,OAAO,EAAE;AACnD,MAAI,UAAU,WAAW,GAAG;AAC1B,UAAM,MAAM,SAAS,CAAC,IAAI;AAAA,EAC5B,OAAO;AACL,UAAM,KAAK,EAAE;AAAA,EACf;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}