var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/comment-editor/utils.ts
var utils_exports = {};
__export(utils_exports, {
  getCommentInfo: () => getCommentInfo,
  setCursorAtLast: () => setCursorAtLast,
  transform2Tag: () => transform2Tag
});
module.exports = __toCommonJS(utils_exports);
var getCommentInfo = (html) => {
  var _a;
  let emojiStrList = html == null ? void 0 : html.match(/<span class="insertHtml insert-emoji"(.+?)<\/span>/g), tagStrList = html == null ? void 0 : html.match(/<span class="insertHtml tag"(.+?)<\/span>/g), atStrList = html == null ? void 0 : html.match(/<span class="insertHtml at"(.+?)<\/span>/g);
  let tagList = [];
  if (tagStrList) {
    tagList = tagStrList.join("").match(/#(.+?)#/g) || [];
  }
  let atList = [];
  if (atStrList) {
    (_a = atStrList.join("").match(/<a(.+?)<\/a>/g)) == null ? void 0 : _a.map((item) => {
      let parentNode = document.createElement("div"), htmlNode;
      parentNode.innerHTML = item;
      htmlNode = parentNode.childNodes[0];
      atList.push(Object.assign({}, htmlNode.dataset));
    });
  }
  return { emojiStrList, tagStrList, atStrList, tagList, atList };
};
var transform2Tag = (html) => {
  const pattern = /(?<!<a[^>]*>)(#(\S)+#)(?!<\/a>)/g;
  const res = html.match(pattern) || [];
  return [(res == null ? void 0 : res.length) > 0, html.replace(pattern, '<span class="insertHtml tag" contenteditable="false"><a>$1</a></span>')];
};
var setCursorAtLast = (target) => {
  const selection = getSelection();
  if (!selection || !target)
    return;
  const range = selection.getRangeAt(0);
  range.setEnd(target, target.childNodes.length);
  const newRange = document.createRange();
  newRange.setStart(range.endContainer, range.endOffset);
  newRange.setEnd(range.endContainer, range.endOffset);
  selection.removeAllRanges();
  selection.addRange(newRange);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getCommentInfo,
  setCursorAtLast,
  transform2Tag
});
