"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.wrapMath = exports.unWrapMath = exports.BracketTypes = void 0;

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _PAIRS;

var BracketTypes = {};
exports.BracketTypes = BracketTypes;
BracketTypes.ROUND_BRACKETS = 'round_brackets';
BracketTypes.SQUARE_BRACKETS = 'square_brackets';
BracketTypes.DOLLAR = 'dollar';
BracketTypes.DOUBLE_DOLLAR = 'double_dollar';
var PAIRS = (_PAIRS = {}, (0, _defineProperty2["default"])(_PAIRS, BracketTypes.ROUND_BRACKETS, ['\\(', '\\)']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.SQUARE_BRACKETS, ['\\[', '\\]']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.DOLLAR, ['$', '$']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.DOUBLE_DOLLAR, ['$$', '$$']), _PAIRS);

var wrapMath = function wrapMath(content, wrapType) {
  if (wrapType === BracketTypes.SQUARE_BRACKETS) {
    console.warn('\\[...\\] is not supported yet'); // eslint-disable-line

    wrapType = BracketTypes.ROUND_BRACKETS;
  }

  if (wrapType === BracketTypes.DOUBLE_DOLLAR) {
    console.warn('$$...$$ is not supported yet'); // eslint-disable-line

    wrapType = BracketTypes.DOLLAR;
  }

  var _ref = PAIRS[wrapType] || PAIRS[BracketTypes.ROUND_BRACKETS],
      _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
      start = _ref2[0],
      end = _ref2[1];

  return "".concat(start).concat(content).concat(end);
};

exports.wrapMath = wrapMath;

var unWrapMath = function unWrapMath(content) {
  var displayStyleIndex = content.indexOf('\\displaystyle');

  if (displayStyleIndex !== -1) {
    console.warn('\\displaystyle is not supported - removing'); // eslint-disable-line

    content = content.replace('\\displaystyle', '').trim();
  }

  if (content.startsWith('$$') && content.endsWith('$$')) {
    console.warn('$$ syntax is not yet supported'); // eslint-disable-line

    return {
      unwrapped: content.substring(2, content.length - 2),
      wrapType: BracketTypes.DOLLAR
    };
  }

  if (content.startsWith('$') && content.endsWith('$')) {
    return {
      unwrapped: content.substring(1, content.length - 1),
      wrapType: BracketTypes.DOLLAR
    };
  }

  if (content.startsWith('\\[') && content.endsWith('\\]')) {
    console.warn('\\[..\\] syntax is not yet supported'); // eslint-disable-line

    return {
      unwrapped: content.substring(2, content.length - 2),
      wrapType: BracketTypes.ROUND_BRACKETS
    };
  }

  if (content.startsWith('\\(') && content.endsWith('\\)')) {
    return {
      unwrapped: content.substring(2, content.length - 2),
      wrapType: BracketTypes.ROUND_BRACKETS
    };
  }

  return {
    unwrapped: content,
    wrapType: BracketTypes.ROUND_BRACKETS
  };
};

exports.unWrapMath = unWrapMath;
//# sourceMappingURL=normalization.js.map