@whitesev/domutils 1.9.2 → 1.9.4
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/README.md +58 -58
- package/dist/index.amd.js +53 -30
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +53 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +53 -30
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +53 -30
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +53 -30
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +53 -30
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/ElementEvent.d.ts +2 -2
- package/dist/types/src/types/DOMUtilsCSSProperty.d.ts +36 -36
- package/dist/types/src/types/DOMUtilsEvent.d.ts +437 -420
- package/dist/types/src/types/WindowApi.d.ts +14 -14
- package/dist/types/src/types/env.d.ts +10 -10
- package/dist/types/src/types/global.d.ts +1 -1
- package/dist/types/src/types/gm.d.ts +2 -2
- package/index.ts +3 -3
- package/package.json +21 -22
- package/src/CommonUtils.ts +163 -163
- package/src/ElementAnimate.ts +290 -290
- package/src/ElementEvent.ts +1593 -1569
- package/src/ElementHandler.ts +43 -43
- package/src/ElementSelector.ts +307 -289
- package/src/ElementWait.ts +742 -742
- package/src/GlobalData.ts +5 -5
- package/src/OriginPrototype.ts +5 -5
- package/src/Utils.ts +388 -388
- package/src/WindowApi.ts +59 -59
- package/src/index.ts +2052 -2052
- package/src/types/DOMUtilsCSSProperty.d.ts +36 -36
- package/src/types/DOMUtilsEvent.d.ts +437 -420
- package/src/types/WindowApi.d.ts +14 -14
- package/src/types/env.d.ts +10 -10
- package/src/types/global.d.ts +1 -1
- package/src/types/gm.d.ts +2 -2
package/src/ElementHandler.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { ElementEvent } from "./ElementEvent";
|
|
2
|
-
import type { WindowApiOption } from "./types/WindowApi";
|
|
3
|
-
import { WindowApi } from "./WindowApi";
|
|
4
|
-
|
|
5
|
-
class ElementHandler extends ElementEvent {
|
|
6
|
-
windowApi: typeof WindowApi.prototype;
|
|
7
|
-
constructor(windowApiOption?: WindowApiOption) {
|
|
8
|
-
super(windowApiOption);
|
|
9
|
-
this.windowApi = new WindowApi(windowApiOption);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* 获取元素的选择器字符串
|
|
13
|
-
* @param $el
|
|
14
|
-
* @example
|
|
15
|
-
* DOMUtils.getElementSelector(document.querySelector("a"))
|
|
16
|
-
* > '.....'
|
|
17
|
-
*/
|
|
18
|
-
getElementSelector($el: HTMLElement): string {
|
|
19
|
-
const that = this;
|
|
20
|
-
if (!$el) return void 0 as any as string;
|
|
21
|
-
if (!$el.parentElement) return void 0 as any as string;
|
|
22
|
-
/* 如果元素有id属性,则直接返回id选择器 */
|
|
23
|
-
if ($el.id) return `#${$el.id}`;
|
|
24
|
-
|
|
25
|
-
/* 递归地获取父元素的选择器 */
|
|
26
|
-
let selector = that.getElementSelector($el.parentElement);
|
|
27
|
-
if (!selector) {
|
|
28
|
-
return $el.tagName.toLowerCase();
|
|
29
|
-
}
|
|
30
|
-
/* 如果有多个相同类型的兄弟元素,则需要添加索引 */
|
|
31
|
-
if ($el.parentElement.querySelectorAll($el.tagName).length > 1) {
|
|
32
|
-
const index = Array.prototype.indexOf.call($el.parentElement.children, $el) + 1;
|
|
33
|
-
selector += ` > ${$el.tagName.toLowerCase()}:nth-child(${index})`;
|
|
34
|
-
} else {
|
|
35
|
-
selector += ` > ${$el.tagName.toLowerCase()}`;
|
|
36
|
-
}
|
|
37
|
-
return selector;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const elementHandler = new ElementHandler();
|
|
42
|
-
|
|
43
|
-
export { elementHandler, ElementHandler };
|
|
1
|
+
import { ElementEvent } from "./ElementEvent";
|
|
2
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
3
|
+
import { WindowApi } from "./WindowApi";
|
|
4
|
+
|
|
5
|
+
class ElementHandler extends ElementEvent {
|
|
6
|
+
windowApi: typeof WindowApi.prototype;
|
|
7
|
+
constructor(windowApiOption?: WindowApiOption) {
|
|
8
|
+
super(windowApiOption);
|
|
9
|
+
this.windowApi = new WindowApi(windowApiOption);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 获取元素的选择器字符串
|
|
13
|
+
* @param $el
|
|
14
|
+
* @example
|
|
15
|
+
* DOMUtils.getElementSelector(document.querySelector("a"))
|
|
16
|
+
* > '.....'
|
|
17
|
+
*/
|
|
18
|
+
getElementSelector($el: HTMLElement): string {
|
|
19
|
+
const that = this;
|
|
20
|
+
if (!$el) return void 0 as any as string;
|
|
21
|
+
if (!$el.parentElement) return void 0 as any as string;
|
|
22
|
+
/* 如果元素有id属性,则直接返回id选择器 */
|
|
23
|
+
if ($el.id) return `#${$el.id}`;
|
|
24
|
+
|
|
25
|
+
/* 递归地获取父元素的选择器 */
|
|
26
|
+
let selector = that.getElementSelector($el.parentElement);
|
|
27
|
+
if (!selector) {
|
|
28
|
+
return $el.tagName.toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
/* 如果有多个相同类型的兄弟元素,则需要添加索引 */
|
|
31
|
+
if ($el.parentElement.querySelectorAll($el.tagName).length > 1) {
|
|
32
|
+
const index = Array.prototype.indexOf.call($el.parentElement.children, $el) + 1;
|
|
33
|
+
selector += ` > ${$el.tagName.toLowerCase()}:nth-child(${index})`;
|
|
34
|
+
} else {
|
|
35
|
+
selector += ` > ${$el.tagName.toLowerCase()}`;
|
|
36
|
+
}
|
|
37
|
+
return selector;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const elementHandler = new ElementHandler();
|
|
42
|
+
|
|
43
|
+
export { elementHandler, ElementHandler };
|