@whitesev/utils 1.9.6 → 1.9.7

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.umd.js CHANGED
@@ -3821,7 +3821,9 @@
3821
3821
  /* CODE FOR BROWSERS THAT SUPPORT window.find */
3822
3822
  let windowFind = UtilsCore.self.find;
3823
3823
  strFound = windowFind(str, caseSensitive, true, true, false);
3824
- if (strFound && UtilsCore.self.getSelection && !UtilsCore.self.getSelection().anchorNode) {
3824
+ if (strFound &&
3825
+ UtilsCore.self.getSelection &&
3826
+ !UtilsCore.self.getSelection().anchorNode) {
3825
3827
  strFound = windowFind(str, caseSensitive, true, true, false);
3826
3828
  }
3827
3829
  if (!strFound) {
@@ -4893,7 +4895,8 @@
4893
4895
  return result;
4894
4896
  }
4895
4897
  isThemeDark() {
4896
- return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
4898
+ return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)")
4899
+ .matches;
4897
4900
  }
4898
4901
  isVisible(element, inView = false) {
4899
4902
  let needCheckDomList = [];
@@ -5092,11 +5095,6 @@
5092
5095
  }
5093
5096
  mutationObserver(target, observer_config) {
5094
5097
  let UtilsContext = this;
5095
- if (!(target instanceof Node) &&
5096
- !(target instanceof NodeList) &&
5097
- !UtilsContext.isJQuery(target)) {
5098
- throw new Error("Utils.mutationObserver 参数 target 必须为 Node|NodeList|jQuery类型");
5099
- }
5100
5098
  let default_obverser_config = {
5101
5099
  /* 监听到元素有反馈,需执行的函数 */
5102
5100
  callback: () => { },
@@ -5145,12 +5143,8 @@
5145
5143
  let mutationObserver = new windowMutationObserver(function (mutations, observer) {
5146
5144
  observer_config?.callback(mutations, observer);
5147
5145
  });
5148
- if (target instanceof Node) {
5149
- /* 传入的参数是节点元素 */
5150
- mutationObserver.observe(target, observer_config.config);
5151
- }
5152
- else if (target instanceof NodeList) {
5153
- /* 传入的参数是节点元素数组 */
5146
+ if (Array.isArray(target) || target instanceof NodeList) {
5147
+ // 传入的是数组或者元素数组
5154
5148
  target.forEach((item) => {
5155
5149
  mutationObserver.observe(item, observer_config.config);
5156
5150
  });
@@ -5162,8 +5156,7 @@
5162
5156
  });
5163
5157
  }
5164
5158
  else {
5165
- /* 未知 */
5166
- console.error("Utils.mutationObserver 未知参数", arguments);
5159
+ mutationObserver.observe(target, observer_config.config);
5167
5160
  }
5168
5161
  if (observer_config.immediate) {
5169
5162
  /* 主动触发一次 */