@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.amd.js +12 -6
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +12 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +12 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +12 -6
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +12 -6
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +12 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtilsEvent.d.ts +3 -0
- package/package.json +1 -1
- package/src/DOMUtilsEvent.ts +15 -6
|
@@ -411,6 +411,9 @@ export declare class DOMUtilsEvent {
|
|
|
411
411
|
* @example
|
|
412
412
|
* DOMUtils.selectorAll("div:regexp('^xxxx$')")
|
|
413
413
|
* > [div.xxx]
|
|
414
|
+
* @example
|
|
415
|
+
* DOMUtils.selectorAll("div:regexp(/^xxx/ig)")
|
|
416
|
+
* > [div.xxx]
|
|
414
417
|
*/
|
|
415
418
|
selectorAll<K extends keyof HTMLElementTagNameMap>(selector: K): HTMLElementTagNameMap[K][];
|
|
416
419
|
selectorAll<E extends Element = Element>(selector: string): E[];
|
package/package.json
CHANGED
package/src/DOMUtilsEvent.ts
CHANGED
|
@@ -1230,6 +1230,9 @@ export class DOMUtilsEvent {
|
|
|
1230
1230
|
* @example
|
|
1231
1231
|
* DOMUtils.selectorAll("div:regexp('^xxxx$')")
|
|
1232
1232
|
* > [div.xxx]
|
|
1233
|
+
* @example
|
|
1234
|
+
* DOMUtils.selectorAll("div:regexp(/^xxx/ig)")
|
|
1235
|
+
* > [div.xxx]
|
|
1233
1236
|
*/
|
|
1234
1237
|
selectorAll<K extends keyof HTMLElementTagNameMap>(
|
|
1235
1238
|
selector: K
|
|
@@ -1247,8 +1250,8 @@ export class DOMUtilsEvent {
|
|
|
1247
1250
|
return $ele?.innerHTML?.trim() === "";
|
|
1248
1251
|
});
|
|
1249
1252
|
} else if (
|
|
1250
|
-
selector.match(/[^\s]{1}:contains\("(.*)"\)$/
|
|
1251
|
-
selector.match(/[^\s]{1}:contains\('(.*)'\)$/
|
|
1253
|
+
selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
|
|
1254
|
+
selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)
|
|
1252
1255
|
) {
|
|
1253
1256
|
// contains 语法
|
|
1254
1257
|
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
@@ -1261,13 +1264,19 @@ export class DOMUtilsEvent {
|
|
|
1261
1264
|
return ($ele?.textContent || $ele?.innerText)?.includes(text);
|
|
1262
1265
|
});
|
|
1263
1266
|
} else if (
|
|
1264
|
-
selector.match(/[^\s]{1}:regexp\("(.*)"\)$/
|
|
1265
|
-
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/
|
|
1267
|
+
selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
|
|
1268
|
+
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)
|
|
1266
1269
|
) {
|
|
1267
1270
|
// regexp 语法
|
|
1268
1271
|
let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
|
|
1269
|
-
let
|
|
1270
|
-
let
|
|
1272
|
+
let pattern = textMatch![2];
|
|
1273
|
+
let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
|
|
1274
|
+
let flags = "";
|
|
1275
|
+
if (flagMatch) {
|
|
1276
|
+
pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
|
|
1277
|
+
flags = flagMatch[3];
|
|
1278
|
+
}
|
|
1279
|
+
let regexp = new RegExp(pattern, flags);
|
|
1271
1280
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
1272
1281
|
return Array.from(
|
|
1273
1282
|
context.windowApi.document.querySelectorAll<E>(selector)
|