"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createSelectionRangeMemo = void 0;
var createSelectionRangeMemo = exports.createSelectionRangeMemo = function createSelectionRangeMemo() {
  var selectedRange = null;
  var save = function save() {
    if (window.getSelection) {
      var sel = window.getSelection();
      if (sel.getRangeAt && sel.rangeCount) {
        selectedRange = sel.getRangeAt(0);
      }
    } else if (document.selection && document.selection.createRange) {
      selectedRange = document.selection.createRange();
    }
    return selectedRange;
  };
  var restore = function restore() {
    if (selectedRange) {
      if (window.getSelection) {
        var sel = window.getSelection();
        sel.removeAllRanges();
        // required for safari while addingRange element should be visible.
        selectedRange.startContainer.parentElement.style.visibility = 'visible';
        sel.addRange(selectedRange);
      } else if (document.selection && selectedRange.select) {
        selectedRange.select();
      }
    }
  };
  return {
    save: save,
    restore: restore
  };
};