import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { N as Node, F as Fragment, S as Slice, a as Selection } from './chunk-CBN5naeP.js';
import { isNotEmpty } from '@bigbinary/neeto-cist';
import { E as EDITOR_OPTIONS, A as ALL_PROTOCOL_URL_REGEXP } from './chunk-DDwycKmK.js';
import { I as IMAGE_REGEX, a as IMAGE_REPLACEMENT_PATTERN, E as EMPTY_DIV_REGEX, T as TRAILING_BR_REGEX, b as EDITOR_LINE_HEIGHT, c as EDITOR_PADDING_SIZE, d as EDITOR_BORDER_SIZE } from './chunk-CF5f8-fy.js';

var getEditorStyles = function getEditorStyles(_ref) {
  var rows = _ref.rows;
  var editorHeight = rows * EDITOR_LINE_HEIGHT + 2 * (EDITOR_PADDING_SIZE + EDITOR_BORDER_SIZE);
  return "min-height: ".concat(editorHeight, "px;");
};
var clipboardTextParser = function clipboardTextParser(text, context) {
  var nodes = [];
  var blocks = text.split(/\n/);
  blocks.forEach(function (line) {
    var nodeJson = {
      type: "paragraph"
    };
    if (isNotEmpty(line)) {
      nodeJson.content = [{
        type: "text",
        text: line
      }];
    }
    var node = Node.fromJSON(context.doc.type.schema, nodeJson);
    nodes.push(node);
  });
  var fragment = Fragment.fromArray(nodes);
  return Slice.maxOpen(fragment);
};
var setInitialPosition = function setInitialPosition(editor) {
  var state = editor.state,
    view = editor.view;
  var endPosition = Selection.atEnd(state.doc);
  var transaction = state.tr;
  transaction.setSelection(endPosition);
  view.dispatch(transaction);
};
var isEditorOverlaysActive = function isEditorOverlaysActive() {
  return document.querySelector(".ne-media-uploader,.ne-embed-modal,.tippy-content,.ne-link-popover");
};
var validateAndFormatUrl = function validateAndFormatUrl(url) {
  if (!ALL_PROTOCOL_URL_REGEXP.test(url)) {
    return null;
  }
  if (!/^[a-zA-Z]\w*:/i.test(url)) {
    return "https://".concat(url);
  }
  return url;
};
var transformEditorContent = function transformEditorContent(content) {
  var _content$replaceAll;
  return content === null || content === void 0 || (_content$replaceAll = content.replaceAll(IMAGE_REGEX, IMAGE_REPLACEMENT_PATTERN)) === null || _content$replaceAll === void 0 || (_content$replaceAll = _content$replaceAll.replaceAll(EMPTY_DIV_REGEX, "")) === null || _content$replaceAll === void 0 ? void 0 : _content$replaceAll.replace(TRAILING_BR_REGEX, "");
};
var isEmojiSuggestionsMenuActive = function isEmojiSuggestionsMenuActive() {
  return !!document.querySelector(".neeto-editor-emoji-suggestion");
};
var transformPastedHTML = function transformPastedHTML(content) {
  var contentWithoutBr = content.replaceAll("<br />", "<p></p>");
  var doc = new DOMParser().parseFromString(contentWithoutBr, "text/html");

  // ProseMirror tags clipboard output from any TipTap/ProseMirror editor with
  // `data-pm-slice`. When present, the paste is coming from another
  // neeto-editor instance and we preserve the author's color choices. When
  // absent, the source is external (Word, websites, customer messages) and we
  // strip inline colors so foreign theming does not bleed into the editor.
  var isInternalPaste = doc.querySelector("[data-pm-slice]") !== null;
  if (!isInternalPaste) {
    doc.querySelectorAll("[style]").forEach(function (el) {
      el.style.color = "";
      el.style.backgroundColor = "";
    });
  }
  return doc.body.innerHTML;
};
var buildLevelsFromOptions = function buildLevelsFromOptions(options) {
  var levels = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, EDITOR_OPTIONS.H1, 1), EDITOR_OPTIONS.H2, 2), EDITOR_OPTIONS.H3, 3), EDITOR_OPTIONS.H4, 4), EDITOR_OPTIONS.H5, 5), EDITOR_OPTIONS.H6, 6);
  return Object.entries(levels).filter(function (heading) {
    return options.includes(heading[0]);
  }).map(function (heading) {
    return heading[1];
  });
};

export { isEmojiSuggestionsMenuActive as a, buildLevelsFromOptions as b, transformPastedHTML as c, clipboardTextParser as d, getEditorStyles as g, isEditorOverlaysActive as i, setInitialPosition as s, transformEditorContent as t, validateAndFormatUrl as v };
//# sourceMappingURL=chunk-bG6hOjuU.js.map
