import { EMPTY_KEYWORD_REGEXP as c } from "../../utils/const.js";
const n = (e) => {
  let s = e.keyword.replace(/[.^$*+?()[{|\\]/g, (f) => `\\${f}`).trim();
  const i = e.matchCase ? "g" : "gi";
  return {
    keyword: e.keyword,
    regExp: new RegExp(s, i),
    wholeWords: e.wholeWords || !1
  };
}, u = (e, t, r) => e instanceof RegExp ? {
  keyword: e.source,
  regExp: e,
  wholeWords: r || !1
} : typeof e == "string" ? e === "" ? c : n({
  keyword: e,
  matchCase: t || !1,
  wholeWords: r || !1
}) : (typeof t < "u" && (e.matchCase = t), typeof r < "u" && (e.wholeWords = r), n(e)), o = (e) => {
  const t = e.parentNode;
  t && t.removeChild(e);
}, p = (e, t) => {
  o(e);
  const r = t.parentNode;
  r && r.insertBefore(e, t), o(t);
}, l = (e) => {
  const t = e.parentNode;
  if (!t)
    return;
  const r = document.createRange();
  r.selectNodeContents(e), p(r.extractContents(), e), t.normalize();
}, g = (e, t) => e.top < t.top ? -1 : e.top > t.top ? 1 : e.left < t.left ? -1 : e.left > t.left ? 1 : 0;
export {
  n as normalizeFlagKeyword,
  u as normalizeSingleKeyword,
  g as sortHighlightPosition,
  l as unwrap
};
