@whitesev/domutils 1.3.5 → 1.3.6
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.amd.js +41 -0
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +41 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +41 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +41 -0
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +41 -0
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +41 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtilsEvent.d.ts +38 -0
- package/package.json +1 -1
- package/src/DOMUtils.ts +1 -1
- package/src/DOMUtilsEvent.ts +92 -0
package/dist/index.amd.js
CHANGED
|
@@ -912,6 +912,47 @@ define((function () { 'use strict';
|
|
|
912
912
|
},
|
|
913
913
|
};
|
|
914
914
|
}
|
|
915
|
+
selector(selector) {
|
|
916
|
+
return this.selectorAll(selector)[0];
|
|
917
|
+
}
|
|
918
|
+
selectorAll(selector) {
|
|
919
|
+
const context = this;
|
|
920
|
+
selector = selector.trim();
|
|
921
|
+
if (selector.match(/[^\s]{1}:empty$/gi)) {
|
|
922
|
+
// empty 语法
|
|
923
|
+
selector = selector.replace(/:empty$/gi, "");
|
|
924
|
+
return Array.from(context.windowApi.document.querySelectorAll(selector)).filter(($ele) => {
|
|
925
|
+
return $ele?.innerHTML?.trim() === "";
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/gi) ||
|
|
929
|
+
selector.match(/[^\s]{1}:contains\('(.*)'\)$/gi)) {
|
|
930
|
+
// contains 语法
|
|
931
|
+
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
932
|
+
let text = textMatch[2];
|
|
933
|
+
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
934
|
+
return Array.from(context.windowApi.document.querySelectorAll(selector)).filter(($ele) => {
|
|
935
|
+
// @ts-ignore
|
|
936
|
+
return ($ele?.textContent || $ele?.innerText)?.includes(text);
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/gi) ||
|
|
940
|
+
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/gi)) {
|
|
941
|
+
// regexp 语法
|
|
942
|
+
let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
|
|
943
|
+
let text = textMatch[2];
|
|
944
|
+
let regexp = new RegExp(text);
|
|
945
|
+
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
946
|
+
return Array.from(context.windowApi.document.querySelectorAll(selector)).filter(($ele) => {
|
|
947
|
+
// @ts-ignore
|
|
948
|
+
return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
// 普通语法
|
|
953
|
+
return Array.from(context.windowApi.document.querySelectorAll(selector));
|
|
954
|
+
}
|
|
955
|
+
}
|
|
915
956
|
}
|
|
916
957
|
|
|
917
958
|
/**
|