var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.createContentPreview = createContentPreview;exports.createLineKey = createLineKey;exports.removeExtraIndentation = removeExtraIndentation;var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

function createContentPreview(tokens) {var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 20;
  return tokens.
  slice(0, 3).
  map(function (token) {return token.content;}).
  join('').
  slice(0, maxLength);
}

function createLineKey(line, index) {
  var contentPreview = createContentPreview(line);
  return `line-${index}-${contentPreview}`;
}

function removeExtraIndentation(text) {
  var preserved = text.replace(/\\n/g, '§NEWLINE§');
  var lines = preserved.split('\n');
  var minIndent = Math.min.apply(Math, (0, _toConsumableArray2.default)(
    lines.
    filter(function (line) {return line.trim().length > 0;}).
    map(function (line) {var _line$match$0$length, _line$match;return (_line$match$0$length = (_line$match = line.match(/^\s*/)) == null ? void 0 : _line$match[0].length) != null ? _line$match$0$length : 0;}))
  );

  var normalized = lines.
  map(function (line) {var _line$match$, _line$match2;
    if (line.trim().length === 0)
    return '';

    var indent = (_line$match$ = (_line$match2 = line.match(/^\s*/)) == null ? void 0 : _line$match2[0]) != null ? _line$match$ : '';
    var relativeIndent = ' '.repeat(Math.max(0, indent.length - minIndent));
    return relativeIndent + line.trim();
  }).
  join('\n');

  return normalized.replace(/§NEWLINE§/g, '\\n');
}
//# sourceMappingURL=string.js.map