@whitesev/domutils 1.9.1 → 1.9.3

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.
Files changed (51) hide show
  1. package/README.md +58 -58
  2. package/dist/index.amd.js +40 -22
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +1 -1
  5. package/dist/index.amd.min.js.map +1 -1
  6. package/dist/index.cjs.js +40 -22
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +1 -1
  9. package/dist/index.cjs.min.js.map +1 -1
  10. package/dist/index.esm.js +40 -22
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +1 -1
  13. package/dist/index.esm.min.js.map +1 -1
  14. package/dist/index.iife.js +40 -22
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +1 -1
  17. package/dist/index.iife.min.js.map +1 -1
  18. package/dist/index.system.js +40 -22
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +1 -1
  21. package/dist/index.system.min.js.map +1 -1
  22. package/dist/index.umd.js +40 -22
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +1 -1
  25. package/dist/index.umd.min.js.map +1 -1
  26. package/dist/types/src/index.d.ts +4 -4
  27. package/dist/types/src/types/DOMUtilsCSSProperty.d.ts +36 -36
  28. package/dist/types/src/types/DOMUtilsEvent.d.ts +420 -420
  29. package/dist/types/src/types/WindowApi.d.ts +14 -14
  30. package/dist/types/src/types/env.d.ts +10 -10
  31. package/dist/types/src/types/global.d.ts +1 -1
  32. package/dist/types/src/types/gm.d.ts +2 -2
  33. package/index.ts +3 -3
  34. package/package.json +21 -22
  35. package/src/CommonUtils.ts +163 -163
  36. package/src/ElementAnimate.ts +290 -290
  37. package/src/ElementEvent.ts +1569 -1569
  38. package/src/ElementHandler.ts +43 -43
  39. package/src/ElementSelector.ts +307 -289
  40. package/src/ElementWait.ts +742 -742
  41. package/src/GlobalData.ts +5 -5
  42. package/src/OriginPrototype.ts +5 -5
  43. package/src/Utils.ts +388 -388
  44. package/src/WindowApi.ts +59 -59
  45. package/src/index.ts +2052 -2024
  46. package/src/types/DOMUtilsCSSProperty.d.ts +36 -36
  47. package/src/types/DOMUtilsEvent.d.ts +420 -420
  48. package/src/types/WindowApi.d.ts +14 -14
  49. package/src/types/env.d.ts +10 -10
  50. package/src/types/global.d.ts +1 -1
  51. package/src/types/gm.d.ts +2 -2
@@ -1,14 +1,14 @@
1
- /**
2
- * 配置类型
3
- */
4
- export type WindowApiOption = {
5
- document: Document;
6
- window: Window & typeof globalThis;
7
- globalThis?: typeof globalThis | Window;
8
- self?: Window & typeof globalThis;
9
- top: Window;
10
- setTimeout: typeof setTimeout;
11
- clearTimeout: typeof clearTimeout;
12
- setInterval: typeof setInterval;
13
- clearInterval: typeof clearInterval;
14
- };
1
+ /**
2
+ * 配置类型
3
+ */
4
+ export type WindowApiOption = {
5
+ document: Document;
6
+ window: Window & typeof globalThis;
7
+ globalThis?: typeof globalThis | Window;
8
+ self?: Window & typeof globalThis;
9
+ top: Window;
10
+ setTimeout: typeof setTimeout;
11
+ clearTimeout: typeof clearTimeout;
12
+ setInterval: typeof setInterval;
13
+ clearInterval: typeof clearInterval;
14
+ };
@@ -1,10 +1,10 @@
1
- declare const jQuery: any;
2
- declare interface Window {
3
- webkitMutationObserver: MutationObserver;
4
- MozMutationObserver: MutationObserver;
5
- jQuery: any;
6
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
7
- DOMUtils: typeof import("./../index").DOMUtils;
8
- trustedTypes: any;
9
- }
10
- declare type IArray<T> = T | T[];
1
+ declare const jQuery: any;
2
+ declare interface Window {
3
+ webkitMutationObserver: MutationObserver;
4
+ MozMutationObserver: MutationObserver;
5
+ jQuery: any;
6
+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
7
+ DOMUtils: typeof import("./../index").DOMUtils;
8
+ trustedTypes: any;
9
+ }
10
+ declare type IArray<T> = T | T[];
@@ -1 +1 @@
1
- export type DOMUtilsTargetElementType = HTMLElement | string | NodeList | HTMLElement[];
1
+ export type DOMUtilsTargetElementType = HTMLElement | string | NodeList | HTMLElement[];
@@ -1,2 +1,2 @@
1
- /** GM中的unsafeWindow */
2
- declare const unsafeWindow: Window & typeof globalThis;
1
+ /** GM中的unsafeWindow */
2
+ declare const unsafeWindow: Window & typeof globalThis;
package/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { DOMUtils } from "./src";
2
-
3
- export default DOMUtils;
1
+ import { DOMUtils } from "./src";
2
+
3
+ export default DOMUtils;
package/package.json CHANGED
@@ -1,9 +1,20 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@whitesev/domutils",
4
- "version": "1.9.1",
5
- "type": "module",
4
+ "version": "1.9.3",
6
5
  "description": "适合在浏览器中操作DOM的常用工具类",
6
+ "keywords": [
7
+ "typescript",
8
+ "元素工具类"
9
+ ],
10
+ "license": "MIT",
11
+ "author": "WhiteSev",
12
+ "files": [
13
+ "dist",
14
+ "src",
15
+ "./index.ts"
16
+ ],
17
+ "type": "module",
7
18
  "main": "dist/index.cjs.js",
8
19
  "module": "dist/index.esm.js",
9
20
  "types": "dist/types/index.d.ts",
@@ -12,28 +23,14 @@
12
23
  "./package.json": "./package.json",
13
24
  "./dist/*": "./dist/*",
14
25
  ".": {
26
+ "types": "./dist/types/index.d.ts",
15
27
  "import": "./dist/index.esm.js",
16
- "require": "./dist/index.cjs.js",
17
- "types": "./dist/types/index.d.ts"
28
+ "require": "./dist/index.cjs.js"
18
29
  }
19
30
  },
20
- "files": [
21
- "dist",
22
- "src",
23
- "./index.ts"
24
- ],
25
31
  "publishConfig": {
26
32
  "registry": "https://registry.npmjs.org/"
27
33
  },
28
- "keywords": [
29
- "typescript",
30
- "元素工具类"
31
- ],
32
- "author": "WhiteSev",
33
- "license": "MIT",
34
- "dependencies": {
35
- "worker-timers": "^8.0.27"
36
- },
37
34
  "devDependencies": {
38
35
  "@eslint/js": "^9.39.2",
39
36
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -42,12 +39,14 @@
42
39
  "@rollup/plugin-terser": "^0.4.4",
43
40
  "@rollup/plugin-typescript": "^12.3.0",
44
41
  "browserslist": "^4.28.1",
45
- "caniuse-lite": "^1.0.30001761",
42
+ "caniuse-lite": "^1.0.30001770",
46
43
  "eslint": "^9.39.2",
47
44
  "eslint-config-prettier": "^10.1.8",
48
45
  "eslint-plugin-compat": "^6.0.2",
49
46
  "eslint-plugin-prettier": "^5.5.4",
50
47
  "globals": "^16.5.0",
48
+ "oxfmt": "^0.32.0",
49
+ "oxlint": "1.46.0",
51
50
  "rollup": "^4.54.0",
52
51
  "rollup-plugin-clear": "^2.0.7",
53
52
  "tslib": "^2.8.1",
@@ -55,9 +54,9 @@
55
54
  "typescript-eslint": "^8.50.1"
56
55
  },
57
56
  "scripts": {
58
- "lint": "eslint .",
59
- "lint:fix": "eslint . --fix",
60
- "format": "prettier . --write",
57
+ "lint": "oxlint .",
58
+ "lint:fix": "oxlint . --fix",
59
+ "format": "oxfmt . --write",
61
60
  "dev": "vue-tsc --noEmit && vite --force",
62
61
  "build": "pnpm run format && pnpm run lint && rollup -c"
63
62
  }
@@ -1,163 +1,163 @@
1
- import { WindowApi } from "./WindowApi";
2
-
3
- /** 通用工具类 */
4
- export const CommonUtils = {
5
- windowApi: new WindowApi({
6
- document: document,
7
- window: window,
8
- top: top!,
9
- setTimeout: globalThis.setTimeout.bind(globalThis),
10
- clearTimeout: globalThis.clearTimeout.bind(globalThis),
11
- setInterval: globalThis.setInterval.bind(globalThis),
12
- clearInterval: globalThis.clearInterval.bind(globalThis),
13
- }),
14
- /**
15
- * 判断元素是否已显示或已连接
16
- * @param $el
17
- */
18
- isShow($el: HTMLElement) {
19
- return Boolean($el.getClientRects().length);
20
- },
21
- /**
22
- * 创建安全的html
23
- * @param text 字符串
24
- */
25
- createSafeHTML(text: string) {
26
- if (window.trustedTypes) {
27
- const policy = window.trustedTypes.createPolicy("safe-innerHTML", {
28
- createHTML: (html: string) => html,
29
- });
30
- return policy.createHTML(text);
31
- } else {
32
- return text;
33
- }
34
- },
35
- /**
36
- * 在CSP策略下设置innerHTML
37
- * @param $el 元素
38
- * @param text 文本
39
- */
40
- setSafeHTML($el: HTMLElement, text: string) {
41
- // 创建 TrustedHTML 策略(需 CSP 允许)
42
- $el.innerHTML = this.createSafeHTML(text);
43
- },
44
- /**
45
- * 用于强制显示元素并获取它的高度宽度等其它属性
46
- * @param $el
47
- */
48
- forceShow($el: HTMLElement) {
49
- const dupNode = $el.cloneNode(true) as HTMLElement;
50
- dupNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
51
- this.windowApi.document.documentElement.appendChild(dupNode);
52
- return {
53
- /**
54
- * 恢复修改的style
55
- */
56
- recovery() {
57
- dupNode.remove();
58
- },
59
- };
60
- },
61
- /**
62
- * 获取元素上的Float格式的属性px
63
- * @param element
64
- * @param styleName style名
65
- */
66
- getStyleValue(element: HTMLElement | CSSStyleDeclaration, styleName: string) {
67
- let view = null;
68
- let styles = null;
69
- if (element instanceof CSSStyleDeclaration) {
70
- /* 直接就获取了style属性 */
71
- styles = element;
72
- } else {
73
- view = element.ownerDocument.defaultView;
74
- if (!view || !view.opener) {
75
- view = window;
76
- }
77
- styles = view.getComputedStyle(element);
78
- }
79
- const value = parseFloat(styles[styleName as any]);
80
- if (isNaN(value)) {
81
- return 0;
82
- } else {
83
- return value;
84
- }
85
- },
86
- /**
87
- * 判断是否是window,例如window、self、globalThis
88
- * @param target
89
- */
90
- isWin(target: any) {
91
- if (typeof target !== "object") {
92
- return false;
93
- }
94
- if (target instanceof Node) {
95
- return false;
96
- }
97
- if (target === globalThis) {
98
- return true;
99
- }
100
- if (target === window) {
101
- return true;
102
- }
103
- if (target === self) {
104
- return true;
105
- }
106
- if (target === globalThis) {
107
- return true;
108
- }
109
- if (target === window) {
110
- return true;
111
- }
112
- if (target === self) {
113
- return true;
114
- }
115
- if (typeof unsafeWindow !== "undefined" && target === unsafeWindow) {
116
- return true;
117
- }
118
- if (target?.Math?.toString() !== "[object Math]") {
119
- return false;
120
- }
121
- return true;
122
- },
123
- /**
124
- * 判断对象是否是元素
125
- * @param $el
126
- * @returns
127
- * + true 是元素
128
- * + false 不是元素
129
- * @example
130
- * DOMUtilsCommonUtils.isDOM(document.querySelector("a"))
131
- * > true
132
- */
133
- isDOM($el: any): boolean {
134
- return $el instanceof Node;
135
- },
136
- /**
137
- * 删除对象上的属性
138
- * @param target
139
- * @param propName
140
- */
141
- delete(target: any, propName: any) {
142
- if (typeof Reflect === "object" && Reflect != null && Reflect.deleteProperty) {
143
- return Reflect.deleteProperty(target, propName);
144
- } else {
145
- delete target[propName];
146
- }
147
- },
148
- /**
149
- * 判断是否是元素列表
150
- * @param $ele
151
- */
152
- isNodeList($ele: any): $ele is any[] | NodeList {
153
- return Array.isArray($ele) || $ele instanceof NodeList;
154
- },
155
- /** 获取 animationend 在各个浏览器的兼容名 */
156
- getAnimationEndNameList() {
157
- return ["webkitAnimationEnd", "mozAnimationEnd", "MSAnimationEnd", "oanimationend", "animationend"];
158
- },
159
- /** 获取 transitionend 在各个浏览器的兼容名 */
160
- getTransitionEndNameList() {
161
- return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
162
- },
163
- };
1
+ import { WindowApi } from "./WindowApi";
2
+
3
+ /** 通用工具类 */
4
+ export const CommonUtils = {
5
+ windowApi: new WindowApi({
6
+ document: document,
7
+ window: window,
8
+ top: top!,
9
+ setTimeout: globalThis.setTimeout.bind(globalThis),
10
+ clearTimeout: globalThis.clearTimeout.bind(globalThis),
11
+ setInterval: globalThis.setInterval.bind(globalThis),
12
+ clearInterval: globalThis.clearInterval.bind(globalThis),
13
+ }),
14
+ /**
15
+ * 判断元素是否已显示或已连接
16
+ * @param $el
17
+ */
18
+ isShow($el: HTMLElement) {
19
+ return Boolean($el.getClientRects().length);
20
+ },
21
+ /**
22
+ * 创建安全的html
23
+ * @param text 字符串
24
+ */
25
+ createSafeHTML(text: string) {
26
+ if (window.trustedTypes) {
27
+ const policy = window.trustedTypes.createPolicy("safe-innerHTML", {
28
+ createHTML: (html: string) => html,
29
+ });
30
+ return policy.createHTML(text);
31
+ } else {
32
+ return text;
33
+ }
34
+ },
35
+ /**
36
+ * 在CSP策略下设置innerHTML
37
+ * @param $el 元素
38
+ * @param text 文本
39
+ */
40
+ setSafeHTML($el: HTMLElement, text: string) {
41
+ // 创建 TrustedHTML 策略(需 CSP 允许)
42
+ $el.innerHTML = this.createSafeHTML(text);
43
+ },
44
+ /**
45
+ * 用于强制显示元素并获取它的高度宽度等其它属性
46
+ * @param $el
47
+ */
48
+ forceShow($el: HTMLElement) {
49
+ const dupNode = $el.cloneNode(true) as HTMLElement;
50
+ dupNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
51
+ this.windowApi.document.documentElement.appendChild(dupNode);
52
+ return {
53
+ /**
54
+ * 恢复修改的style
55
+ */
56
+ recovery() {
57
+ dupNode.remove();
58
+ },
59
+ };
60
+ },
61
+ /**
62
+ * 获取元素上的Float格式的属性px
63
+ * @param element
64
+ * @param styleName style名
65
+ */
66
+ getStyleValue(element: HTMLElement | CSSStyleDeclaration, styleName: string) {
67
+ let view = null;
68
+ let styles = null;
69
+ if (element instanceof CSSStyleDeclaration) {
70
+ /* 直接就获取了style属性 */
71
+ styles = element;
72
+ } else {
73
+ view = element.ownerDocument.defaultView;
74
+ if (!view || !view.opener) {
75
+ view = window;
76
+ }
77
+ styles = view.getComputedStyle(element);
78
+ }
79
+ const value = parseFloat(styles[styleName as any]);
80
+ if (isNaN(value)) {
81
+ return 0;
82
+ } else {
83
+ return value;
84
+ }
85
+ },
86
+ /**
87
+ * 判断是否是window,例如window、self、globalThis
88
+ * @param target
89
+ */
90
+ isWin(target: any) {
91
+ if (typeof target !== "object") {
92
+ return false;
93
+ }
94
+ if (target instanceof Node) {
95
+ return false;
96
+ }
97
+ if (target === globalThis) {
98
+ return true;
99
+ }
100
+ if (target === window) {
101
+ return true;
102
+ }
103
+ if (target === self) {
104
+ return true;
105
+ }
106
+ if (target === globalThis) {
107
+ return true;
108
+ }
109
+ if (target === window) {
110
+ return true;
111
+ }
112
+ if (target === self) {
113
+ return true;
114
+ }
115
+ if (typeof unsafeWindow !== "undefined" && target === unsafeWindow) {
116
+ return true;
117
+ }
118
+ if (target?.Math?.toString() !== "[object Math]") {
119
+ return false;
120
+ }
121
+ return true;
122
+ },
123
+ /**
124
+ * 判断对象是否是元素
125
+ * @param $el
126
+ * @returns
127
+ * + true 是元素
128
+ * + false 不是元素
129
+ * @example
130
+ * DOMUtilsCommonUtils.isDOM(document.querySelector("a"))
131
+ * > true
132
+ */
133
+ isDOM($el: any): boolean {
134
+ return $el instanceof Node;
135
+ },
136
+ /**
137
+ * 删除对象上的属性
138
+ * @param target
139
+ * @param propName
140
+ */
141
+ delete(target: any, propName: any) {
142
+ if (typeof Reflect === "object" && Reflect != null && Reflect.deleteProperty) {
143
+ return Reflect.deleteProperty(target, propName);
144
+ } else {
145
+ delete target[propName];
146
+ }
147
+ },
148
+ /**
149
+ * 判断是否是元素列表
150
+ * @param $ele
151
+ */
152
+ isNodeList($ele: any): $ele is any[] | NodeList {
153
+ return Array.isArray($ele) || $ele instanceof NodeList;
154
+ },
155
+ /** 获取 animationend 在各个浏览器的兼容名 */
156
+ getAnimationEndNameList() {
157
+ return ["webkitAnimationEnd", "mozAnimationEnd", "MSAnimationEnd", "oanimationend", "animationend"];
158
+ },
159
+ /** 获取 transitionend 在各个浏览器的兼容名 */
160
+ getTransitionEndNameList() {
161
+ return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
162
+ },
163
+ };