@whitesev/domutils 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -933,8 +933,8 @@ class DOMUtilsEvent {
933
933
  return $ele?.innerHTML?.trim() === "";
934
934
  });
935
935
  }
936
- else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/gi) ||
937
- selector.match(/[^\s]{1}:contains\('(.*)'\)$/gi)) {
936
+ else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
937
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
938
938
  // contains 语法
939
939
  let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
940
940
  let text = textMatch[2];
@@ -944,12 +944,18 @@ class DOMUtilsEvent {
944
944
  return ($ele?.textContent || $ele?.innerText)?.includes(text);
945
945
  });
946
946
  }
947
- else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/gi) ||
948
- selector.match(/[^\s]{1}:regexp\('(.*)'\)$/gi)) {
947
+ else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
948
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
949
949
  // regexp 语法
950
950
  let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
951
- let text = textMatch[2];
952
- let regexp = new RegExp(text);
951
+ let pattern = textMatch[2];
952
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
953
+ let flags = "";
954
+ if (flagMatch) {
955
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
956
+ flags = flagMatch[3];
957
+ }
958
+ let regexp = new RegExp(pattern, flags);
953
959
  selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
954
960
  return Array.from(context.windowApi.document.querySelectorAll(selector)).filter(($ele) => {
955
961
  // @ts-ignore