"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getStepRange = void 0;
var _clamp = _interopRequireDefault(require("lodash/clamp"));
var getStepRange = exports.getStepRange = function getStepRange(transaction) {
  var from = -1;
  var to = -1;
  transaction.mapping.maps.forEach(function (stepMap, index) {
    stepMap.forEach(function (oldStart, oldEnd) {
      var newStart = transaction.mapping.slice(index).map(oldStart, -1);
      var newEnd = transaction.mapping.slice(index).map(oldEnd);
      var docSize = transaction.doc.content.size;
      from = (0, _clamp.default)(newStart < from || from === -1 ? newStart : from, 0, docSize);
      to = (0, _clamp.default)(newEnd > to || to === -1 ? newEnd : to, 0, docSize);
    });
  });
  if (from !== -1) {
    return {
      from: from,
      to: to
    };
  }
  return null;
};