@whitesev/domutils 1.6.6 → 1.6.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.
@@ -1,7 +1,7 @@
1
1
  const OriginPrototype = {
2
- Object: {
3
- defineProperty: Object.defineProperty,
4
- },
2
+ Object: {
3
+ defineProperty: Object.defineProperty,
4
+ },
5
5
  };
6
6
 
7
7
  export { OriginPrototype };
package/src/WindowApi.ts CHANGED
@@ -1,59 +1,59 @@
1
1
  import type { WindowApiOption } from "./types/WindowApi";
2
2
 
3
3
  export class WindowApi {
4
- /** 默认的配置 */
5
- private defaultApi: Required<WindowApiOption> = {
6
- document: document,
7
- window: window,
8
- globalThis: globalThis,
9
- self: self,
10
- top: top!,
11
- setTimeout: globalThis.setTimeout.bind(globalThis),
12
- setInterval: globalThis.setInterval.bind(globalThis),
13
- clearTimeout: globalThis.clearTimeout.bind(globalThis),
14
- clearInterval: globalThis.clearInterval.bind(globalThis),
15
- };
16
- /** 使用的配置 */
17
- private api: Required<WindowApiOption>;
18
- constructor(option?: WindowApiOption) {
19
- if (option) {
20
- if (option.globalThis == null) {
21
- option.globalThis = option.window;
22
- }
23
- if (option.self == null) {
24
- option.self = option.window;
25
- }
26
- }
27
- if (!option) {
28
- option = Object.assign({}, this.defaultApi);
29
- }
30
- this.api = Object.assign({}, option as Required<WindowApiOption>);
31
- }
32
- get document() {
33
- return this.api.document;
34
- }
35
- get window() {
36
- return this.api.window;
37
- }
38
- get globalThis() {
39
- return this.api.globalThis;
40
- }
41
- get self() {
42
- return this.api.self;
43
- }
44
- get top() {
45
- return this.api.top;
46
- }
47
- get setTimeout() {
48
- return this.api.setTimeout;
49
- }
50
- get clearTimeout() {
51
- return this.api.clearTimeout;
52
- }
53
- get setInterval() {
54
- return this.api.setInterval;
55
- }
56
- get clearInterval() {
57
- return this.api.clearInterval;
58
- }
4
+ /** 默认的配置 */
5
+ private defaultApi: Required<WindowApiOption> = {
6
+ document: document,
7
+ window: window,
8
+ globalThis: globalThis,
9
+ self: self,
10
+ top: top!,
11
+ setTimeout: globalThis.setTimeout.bind(globalThis),
12
+ setInterval: globalThis.setInterval.bind(globalThis),
13
+ clearTimeout: globalThis.clearTimeout.bind(globalThis),
14
+ clearInterval: globalThis.clearInterval.bind(globalThis),
15
+ };
16
+ /** 使用的配置 */
17
+ private api: Required<WindowApiOption>;
18
+ constructor(option?: WindowApiOption) {
19
+ if (option) {
20
+ if (option.globalThis == null) {
21
+ option.globalThis = option.window;
22
+ }
23
+ if (option.self == null) {
24
+ option.self = option.window;
25
+ }
26
+ }
27
+ if (!option) {
28
+ option = Object.assign({}, this.defaultApi);
29
+ }
30
+ this.api = Object.assign({}, option as Required<WindowApiOption>);
31
+ }
32
+ get document() {
33
+ return this.api.document;
34
+ }
35
+ get window() {
36
+ return this.api.window;
37
+ }
38
+ get globalThis() {
39
+ return this.api.globalThis;
40
+ }
41
+ get self() {
42
+ return this.api.self;
43
+ }
44
+ get top() {
45
+ return this.api.top;
46
+ }
47
+ get setTimeout() {
48
+ return this.api.setTimeout;
49
+ }
50
+ get clearTimeout() {
51
+ return this.api.clearTimeout;
52
+ }
53
+ get setInterval() {
54
+ return this.api.setInterval;
55
+ }
56
+ get clearInterval() {
57
+ return this.api.clearInterval;
58
+ }
59
59
  }
@@ -1,14 +1,14 @@
1
1
  export type DOMUtilsEventObject<T extends Node> = Event & {
2
- target: T;
2
+ target: T;
3
3
  };
4
4
 
5
5
  export type DOMUtilsCreateElementAttributesMap = {
6
- style?: string;
7
- id?: string;
8
- class?: string;
9
- "data-"?: string;
10
- type?: string;
11
- [key: string]: any;
6
+ style?: string;
7
+ id?: string;
8
+ class?: string;
9
+ "data-"?: string;
10
+ type?: string;
11
+ [key: string]: any;
12
12
  };
13
13
  /**
14
14
  * 鼠标事件
@@ -16,57 +16,57 @@ export type DOMUtilsCreateElementAttributesMap = {
16
16
  */
17
17
 
18
18
  export interface DOMUtils_MouseEvent {
19
- click: MouseEvent | PointerEvent;
20
- auxclick: PointerEvent;
21
- contextmenu: MouseEvent | PointerEvent;
22
- dblclick: MouseEvent | PointerEvent;
23
- mousedown: MouseEvent | PointerEvent;
24
- mouseenter: MouseEvent | PointerEvent;
25
- mouseleave: MouseEvent | PointerEvent;
26
- mousemove: MouseEvent | PointerEvent;
27
- mouseover: MouseEvent | PointerEvent;
28
- mouseout: MouseEvent | PointerEvent;
29
- mouseup: MouseEvent | PointerEvent;
30
- hover: MouseEvent;
19
+ click: MouseEvent | PointerEvent;
20
+ auxclick: PointerEvent;
21
+ contextmenu: MouseEvent | PointerEvent;
22
+ dblclick: MouseEvent | PointerEvent;
23
+ mousedown: MouseEvent | PointerEvent;
24
+ mouseenter: MouseEvent | PointerEvent;
25
+ mouseleave: MouseEvent | PointerEvent;
26
+ mousemove: MouseEvent | PointerEvent;
27
+ mouseover: MouseEvent | PointerEvent;
28
+ mouseout: MouseEvent | PointerEvent;
29
+ mouseup: MouseEvent | PointerEvent;
30
+ hover: MouseEvent;
31
31
  }
32
32
  export type DOMUtils_MouseEventType = keyof DOMUtils_MouseEvent;
33
33
  /**
34
34
  * 鼠标事件
35
35
  */
36
36
  export interface DOMUtils_KeyboardEvent {
37
- keydown: KeyboardEvent;
38
- keypress: KeyboardEvent;
39
- keyup: KeyboardEvent;
37
+ keydown: KeyboardEvent;
38
+ keypress: KeyboardEvent;
39
+ keyup: KeyboardEvent;
40
40
  }
41
41
  export type DOMUtils_KeyboardEventType = keyof DOMUtils_KeyboardEvent;
42
42
  /**
43
43
  * 框架/对象事件
44
44
  */
45
45
  export interface DOMUtils_Frame_Object_Event {
46
- abort: Event;
47
- beforeunload: Event;
48
- error: Event;
49
- hashchange: Event;
50
- load: Event;
51
- pageshow: Event;
52
- pagehide: Event;
53
- resize: Event;
54
- scroll: Event;
55
- unload: Event;
46
+ abort: Event;
47
+ beforeunload: Event;
48
+ error: Event;
49
+ hashchange: Event;
50
+ load: Event;
51
+ pageshow: Event;
52
+ pagehide: Event;
53
+ resize: Event;
54
+ scroll: Event;
55
+ unload: Event;
56
56
  }
57
57
  export type DOMUtils_Frame_Object_EventType = keyof DOMUtils_Frame_Object_Event;
58
58
  /**
59
59
  * 表单事件
60
60
  */
61
61
  export interface DOMUtils_FormEvent {
62
- blur: Event;
63
- change: Event;
64
- focus: Event;
65
- focusin: Event;
66
- focusout: Event;
67
- input: Event;
68
- reset: Event;
69
- search: Event;
62
+ blur: Event;
63
+ change: Event;
64
+ focus: Event;
65
+ focusin: Event;
66
+ focusout: Event;
67
+ input: Event;
68
+ reset: Event;
69
+ search: Event;
70
70
  }
71
71
  export type DOMUtils_FormEventType = keyof DOMUtils_FormEvent;
72
72
 
@@ -74,9 +74,9 @@ export type DOMUtils_FormEventType = keyof DOMUtils_FormEvent;
74
74
  * 剪贴板事件
75
75
  */
76
76
  export interface DOMUtils_ClipboardEvent {
77
- copy: ClipboardEvent;
78
- cut: ClipboardEvent;
79
- paste: ClipboardEvent;
77
+ copy: ClipboardEvent;
78
+ cut: ClipboardEvent;
79
+ paste: ClipboardEvent;
80
80
  }
81
81
  export type DOMUtils_ClipboardEventType = keyof DOMUtils_ClipboardEvent;
82
82
 
@@ -84,8 +84,8 @@ export type DOMUtils_ClipboardEventType = keyof DOMUtils_ClipboardEvent;
84
84
  * 打印事件
85
85
  */
86
86
  export interface DOMUtils_PrintEvent {
87
- afterprint: Event;
88
- beforeprint: Event;
87
+ afterprint: Event;
88
+ beforeprint: Event;
89
89
  }
90
90
  export type DOMUtils_PrintEventType = keyof DOMUtils_PrintEvent;
91
91
 
@@ -93,13 +93,13 @@ export type DOMUtils_PrintEventType = keyof DOMUtils_PrintEvent;
93
93
  * 拖动事件
94
94
  */
95
95
  export interface DOMUtils_DragEvent {
96
- drag: DragEvent;
97
- dragend: DragEvent;
98
- dragenter: DragEvent;
99
- dragleave: DragEvent;
100
- dragover: DragEvent;
101
- dragstart: DragEvent;
102
- drop: DragEvent;
96
+ drag: DragEvent;
97
+ dragend: DragEvent;
98
+ dragenter: DragEvent;
99
+ dragleave: DragEvent;
100
+ dragover: DragEvent;
101
+ dragstart: DragEvent;
102
+ drop: DragEvent;
103
103
  }
104
104
  export type DOMUtils_DragEventType = keyof DOMUtils_DragEvent;
105
105
 
@@ -107,28 +107,28 @@ export type DOMUtils_DragEventType = keyof DOMUtils_DragEvent;
107
107
  * 多媒体(Media)事件
108
108
  */
109
109
  export interface DOMUtils_MediaEvent {
110
- abort: Event;
111
- canplay: Event;
112
- canplaythrough: Event;
113
- durationchange: Event;
114
- emptied: Event;
115
- ended: Event;
116
- error: Event;
117
- loadeddata: Event;
118
- loadedmetadata: Event;
119
- loadstart: Event;
120
- pause: Event;
121
- play: Event;
122
- playing: Event;
123
- progress: Event;
124
- ratechange: Event;
125
- seeked: Event;
126
- seeking: Event;
127
- stalled: Event;
128
- suspend: Event;
129
- timeupdate: Event;
130
- volumechange: Event;
131
- waiting: Event;
110
+ abort: Event;
111
+ canplay: Event;
112
+ canplaythrough: Event;
113
+ durationchange: Event;
114
+ emptied: Event;
115
+ ended: Event;
116
+ error: Event;
117
+ loadeddata: Event;
118
+ loadedmetadata: Event;
119
+ loadstart: Event;
120
+ pause: Event;
121
+ play: Event;
122
+ playing: Event;
123
+ progress: Event;
124
+ ratechange: Event;
125
+ seeked: Event;
126
+ seeking: Event;
127
+ stalled: Event;
128
+ suspend: Event;
129
+ timeupdate: Event;
130
+ volumechange: Event;
131
+ waiting: Event;
132
132
  }
133
133
  export type DOMUtils_MediaEventType = keyof DOMUtils_MediaEvent;
134
134
 
@@ -136,9 +136,9 @@ export type DOMUtils_MediaEventType = keyof DOMUtils_MediaEvent;
136
136
  * 动画事件
137
137
  */
138
138
  export interface DOMUtils_AnimationEvent {
139
- animationend: AnimationEvent;
140
- animationiteration: AnimationEvent;
141
- animationstart: AnimationEvent;
139
+ animationend: AnimationEvent;
140
+ animationiteration: AnimationEvent;
141
+ animationstart: AnimationEvent;
142
142
  }
143
143
  export type DOMUtils_AnimationEventType = keyof DOMUtils_AnimationEvent;
144
144
 
@@ -146,7 +146,7 @@ export type DOMUtils_AnimationEventType = keyof DOMUtils_AnimationEvent;
146
146
  * 过渡事件
147
147
  */
148
148
  export interface DOMUtils_TransitionEvent {
149
- transitionend: TransitionEvent;
149
+ transitionend: TransitionEvent;
150
150
  }
151
151
  export type DOMUtils_TransitionEventType = keyof DOMUtils_TransitionEvent;
152
152
 
@@ -154,29 +154,29 @@ export type DOMUtils_TransitionEventType = keyof DOMUtils_TransitionEvent;
154
154
  * 触摸事件
155
155
  */
156
156
  export interface DOMUtils_TouchEvent {
157
- touchstart: TouchEvent;
158
- touchmove: TouchEvent;
159
- touchend: TouchEvent;
160
- touchcancel: TouchEvent;
161
- touchenter: TouchEvent;
162
- touchleave: TouchEvent;
157
+ touchstart: TouchEvent;
158
+ touchmove: TouchEvent;
159
+ touchend: TouchEvent;
160
+ touchcancel: TouchEvent;
161
+ touchenter: TouchEvent;
162
+ touchleave: TouchEvent;
163
163
  }
164
164
  export type DOMUtils_TouchEventType = keyof DOMUtils_TouchEvent;
165
165
  /**
166
166
  * 其它事件
167
167
  */
168
168
  export interface DOMUtils_OtherEvent {
169
- message: Event;
170
- online: Event;
171
- offline: Event;
172
- popstate: Event;
173
- show: Event;
174
- storage: Event;
175
- toggle: Event;
176
- wheel: Event;
177
- propertychange: Event;
178
- fullscreenchange: Event;
179
- DOMContentLoaded: Event;
169
+ message: Event;
170
+ online: Event;
171
+ offline: Event;
172
+ popstate: Event;
173
+ show: Event;
174
+ storage: Event;
175
+ toggle: Event;
176
+ wheel: Event;
177
+ propertychange: Event;
178
+ fullscreenchange: Event;
179
+ DOMContentLoaded: Event;
180
180
  }
181
181
  export type DOMUtils_OtherEventType = keyof DOMUtils_OtherEvent;
182
182
 
@@ -184,17 +184,17 @@ export type DOMUtils_OtherEventType = keyof DOMUtils_OtherEvent;
184
184
  * 全部事件
185
185
  */
186
186
  export declare type DOMUtils_Event = DOMUtils_MouseEvent &
187
- DOMUtils_KeyboardEvent &
188
- DOMUtils_Frame_Object_Event &
189
- DOMUtils_FormEvent &
190
- DOMUtils_ClipboardEvent &
191
- DOMUtils_PrintEvent &
192
- DOMUtils_DragEvent &
193
- DOMUtils_MediaEvent &
194
- DOMUtils_AnimationEvent &
195
- DOMUtils_TransitionEvent &
196
- DOMUtils_TouchEvent &
197
- DOMUtils_OtherEvent;
187
+ DOMUtils_KeyboardEvent &
188
+ DOMUtils_Frame_Object_Event &
189
+ DOMUtils_FormEvent &
190
+ DOMUtils_ClipboardEvent &
191
+ DOMUtils_PrintEvent &
192
+ DOMUtils_DragEvent &
193
+ DOMUtils_MediaEvent &
194
+ DOMUtils_AnimationEvent &
195
+ DOMUtils_TransitionEvent &
196
+ DOMUtils_TouchEvent &
197
+ DOMUtils_OtherEvent;
198
198
 
199
199
  /**
200
200
  * 事件类型
@@ -205,47 +205,47 @@ export declare type DOMUtils_EventType = keyof DOMUtils_Event;
205
205
  * 元素上的events属性
206
206
  */
207
207
  export declare interface DOMUtilsEventListenerOptionsAttribute {
208
- /**
209
- * DOMUtils的ownCallBack,元素上的监听事件就是它,移除事件时也需要传入这个函数
210
- */
211
- callback: (event: Event) => void;
212
- /**
213
- * 属性配置
214
- */
215
- option: DOMUtilsEventListenerOption;
216
- /**
217
- * 用户添加的事件
218
- */
219
- originCallBack: (event: Event, selectorTarget?: HTMLElement) => void;
220
- /**
221
- * 子元素选择器
222
- */
223
- selector?: string[];
208
+ /**
209
+ * DOMUtils的ownCallBack,元素上的监听事件就是它,移除事件时也需要传入这个函数
210
+ */
211
+ callback: (event: Event) => void;
212
+ /**
213
+ * 属性配置
214
+ */
215
+ option: DOMUtilsEventListenerOption;
216
+ /**
217
+ * 用户添加的事件
218
+ */
219
+ originCallBack: (event: Event, selectorTarget?: HTMLElement) => void;
220
+ /**
221
+ * 子元素选择器
222
+ */
223
+ selector?: string[];
224
224
  }
225
225
 
226
226
  /**
227
227
  * 事件的额外配置
228
228
  */
229
229
  export declare type DOMUtilsEventListenerOption = AddEventListenerOptions & {
230
- /**
231
- * 是否使用 event.composedPath() 来代替 event.target
232
- *
233
- * 一般用于设置了selector参数
234
- */
235
- isComposedPath?: boolean;
230
+ /**
231
+ * 是否使用 event.composedPath() 来代替 event.target
232
+ *
233
+ * 一般用于设置了selector参数
234
+ */
235
+ isComposedPath?: boolean;
236
236
  };
237
237
  export declare type DOMUtilsElementEventType =
238
- | HTMLElement
239
- | string
240
- | NodeList
241
- | (HTMLElement | Window | Document | Element | typeof globalThis)[]
242
- | Window
243
- | Document
244
- | Element
245
- | null
246
- | typeof globalThis
247
- | ShadowRoot
248
- | EventTarget
249
- | ChildNode
250
- | Node
251
- | DocumentFragment;
238
+ | HTMLElement
239
+ | string
240
+ | NodeList
241
+ | (HTMLElement | Window | Document | Element | typeof globalThis)[]
242
+ | Window
243
+ | Document
244
+ | Element
245
+ | null
246
+ | typeof globalThis
247
+ | ShadowRoot
248
+ | EventTarget
249
+ | ChildNode
250
+ | Node
251
+ | DocumentFragment;
@@ -2,13 +2,13 @@
2
2
  * 配置类型
3
3
  */
4
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;
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
14
  };
@@ -1,11 +1,3 @@
1
- export type ParseHTMLReturnType<T1, T2> = T1 extends true
2
- ? T2 extends true
3
- ? Document
4
- : HTMLElement
5
- : HTMLElement;
1
+ export type ParseHTMLReturnType<T1, T2> = T1 extends true ? (T2 extends true ? Document : HTMLElement) : HTMLElement;
6
2
 
7
- export type DOMUtilsTargetElementType =
8
- | HTMLElement
9
- | string
10
- | NodeList
11
- | HTMLElement[];
3
+ export type DOMUtilsTargetElementType = HTMLElement | string | NodeList | HTMLElement[];
package/src/types/gm.d.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  /** GM中的unsafeWindow */
2
- declare var unsafeWindow: Window & typeof globalThis;
2
+ declare const unsafeWindow: Window & typeof globalThis;
3
+
4
+ declare interface Window {
5
+ trustedTypes: any;
6
+ }