@whitesev/domutils 1.3.8 → 1.4.0

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,13 +1,14 @@
1
- import { type DOMUtilsCreateElementAttributesMap, DOMUtilsEvent } from "./DOMUtilsEvent";
1
+ import { DOMUtilsEvent } from "./DOMUtilsEvent";
2
+ import type { DOMUtilsCreateElementAttributesMap } from "./types/DOMUtilsEvent";
2
3
  import { ParseHTMLReturnType, type DOMUtilsTargetElementType } from "./types/global";
3
- import { type UtilsWindowApiOption } from "./WindowApi";
4
+ import type { WindowApiOption } from "./types/WindowApi";
4
5
  /**
5
6
  * 判断是否是元素列表
6
7
  * @param $ele
7
8
  */
8
9
  export declare const isNodeList: ($ele: any) => $ele is any[] | NodeList;
9
10
  declare class DOMUtils extends DOMUtilsEvent {
10
- constructor(option?: UtilsWindowApiOption);
11
+ constructor(option?: WindowApiOption);
11
12
  /** 版本号 */
12
13
  version: string;
13
14
  /**
@@ -615,7 +616,7 @@ declare class DOMUtils extends DOMUtilsEvent {
615
616
  * @param option
616
617
  * @returns
617
618
  */
618
- createDOMUtils(option?: UtilsWindowApiOption): DOMUtils;
619
+ createDOMUtils(option?: WindowApiOption): DOMUtils;
619
620
  /**
620
621
  * 获取文字的位置信息
621
622
  * @param $input 输入框
@@ -1,7 +1,7 @@
1
- import { UtilsWindowApiOption } from "./WindowApi";
1
+ import { WindowApi } from "./WindowApi";
2
2
  /** 通用工具类 */
3
3
  declare const DOMUtilsCommonUtils: {
4
- windowApi: UtilsWindowApiOption;
4
+ windowApi: WindowApi;
5
5
  /**
6
6
  * 判断元素是否已显示或已连接
7
7
  * @param element
@@ -1,5 +1,5 @@
1
1
  declare const DOMUtilsData: {
2
- /** .on绑定的事件 */
2
+ /** .on添加在元素存储的事件 */
3
3
  SymbolEvents: symbol;
4
4
  };
5
5
  export { DOMUtilsData };
@@ -1,209 +1,10 @@
1
+ import type { DOMUtils_Event, DOMUtils_EventType, DOMUtilsElementEventType, DOMUtilsEventListenerOptionsAttribute } from "./types/DOMUtilsEvent";
1
2
  import type { DOMUtilsTargetElementType } from "./types/global";
2
- import { UtilsWindowApiOption } from "./WindowApi";
3
- export type DOMUtilsEventObject<T extends Node> = Event & {
4
- target: T;
5
- };
6
- export declare type DOMUtilsCreateElementAttributesMap = {
7
- style?: string;
8
- id?: string;
9
- class?: string;
10
- "data-"?: string;
11
- type?: string;
12
- [key: string]: any;
13
- };
14
- /**
15
- * 鼠标事件
16
- * + https://blog.csdn.net/weixin_68658847/article/details/126939879
17
- */
18
- export interface DOMUtils_MouseEvent {
19
- click: MouseEvent | PointerEvent;
20
- contextmenu: MouseEvent | PointerEvent;
21
- dblclick: MouseEvent | PointerEvent;
22
- mousedown: MouseEvent | PointerEvent;
23
- mouseenter: MouseEvent | PointerEvent;
24
- mouseleave: MouseEvent | PointerEvent;
25
- mousemove: MouseEvent | PointerEvent;
26
- mouseover: MouseEvent | PointerEvent;
27
- mouseout: MouseEvent | PointerEvent;
28
- mouseup: MouseEvent | PointerEvent;
29
- hover: MouseEvent;
30
- }
31
- export type DOMUtils_MouseEventType = keyof DOMUtils_MouseEvent;
32
- /**
33
- * 鼠标事件
34
- */
35
- export interface DOMUtils_KeyboardEvent {
36
- keydown: KeyboardEvent;
37
- keypress: KeyboardEvent;
38
- keyup: KeyboardEvent;
39
- }
40
- export type DOMUtils_KeyboardEventType = keyof DOMUtils_KeyboardEvent;
41
- /**
42
- * 框架/对象事件
43
- */
44
- export interface DOMUtils_Frame_Object_Event {
45
- abort: Event;
46
- beforeunload: Event;
47
- error: Event;
48
- hashchange: Event;
49
- load: Event;
50
- pageshow: Event;
51
- pagehide: Event;
52
- resize: Event;
53
- scroll: Event;
54
- unload: Event;
55
- }
56
- export type DOMUtils_Frame_Object_EventType = keyof DOMUtils_Frame_Object_Event;
57
- /**
58
- * 表单事件
59
- */
60
- export interface DOMUtils_FormEvent {
61
- blur: Event;
62
- change: Event;
63
- focus: Event;
64
- focusin: Event;
65
- focusout: Event;
66
- input: Event;
67
- reset: Event;
68
- search: Event;
69
- }
70
- export type DOMUtils_FormEventType = keyof DOMUtils_FormEvent;
71
- /**
72
- * 剪贴板事件
73
- */
74
- export interface DOMUtils_ClipboardEvent {
75
- copy: ClipboardEvent;
76
- cut: ClipboardEvent;
77
- paste: ClipboardEvent;
78
- }
79
- export type DOMUtils_ClipboardEventType = keyof DOMUtils_ClipboardEvent;
80
- /**
81
- * 打印事件
82
- */
83
- export interface DOMUtils_PrintEvent {
84
- afterprint: Event;
85
- beforeprint: Event;
86
- }
87
- export type DOMUtils_PrintEventType = keyof DOMUtils_PrintEvent;
88
- /**
89
- * 拖动事件
90
- */
91
- export interface DOMUtils_DragEvent {
92
- drag: DragEvent;
93
- dragend: DragEvent;
94
- dragenter: DragEvent;
95
- dragleave: DragEvent;
96
- dragover: DragEvent;
97
- dragstart: DragEvent;
98
- drop: DragEvent;
99
- }
100
- export type DOMUtils_DragEventType = keyof DOMUtils_DragEvent;
101
- /**
102
- * 多媒体(Media)事件
103
- */
104
- export interface DOMUtils_MediaEvent {
105
- abort: Event;
106
- canplay: Event;
107
- canplaythrough: Event;
108
- durationchange: Event;
109
- emptied: Event;
110
- ended: Event;
111
- error: Event;
112
- loadeddata: Event;
113
- loadedmetadata: Event;
114
- loadstart: Event;
115
- pause: Event;
116
- play: Event;
117
- playing: Event;
118
- progress: Event;
119
- ratechange: Event;
120
- seeked: Event;
121
- seeking: Event;
122
- stalled: Event;
123
- suspend: Event;
124
- timeupdate: Event;
125
- volumechange: Event;
126
- waiting: Event;
127
- }
128
- export type DOMUtils_MediaEventType = keyof DOMUtils_MediaEvent;
129
- /**
130
- * 动画事件
131
- */
132
- export interface DOMUtils_AnimationEvent {
133
- animationend: AnimationEvent;
134
- animationiteration: AnimationEvent;
135
- animationstart: AnimationEvent;
136
- }
137
- export type DOMUtils_AnimationEventType = keyof DOMUtils_AnimationEvent;
138
- /**
139
- * 过渡事件
140
- */
141
- export interface DOMUtils_TransitionEvent {
142
- transitionend: TransitionEvent;
143
- }
144
- export type DOMUtils_TransitionEventType = keyof DOMUtils_TransitionEvent;
145
- /**
146
- * 触摸事件
147
- */
148
- export interface DOMUtils_TouchEvent {
149
- touchstart: TouchEvent;
150
- touchmove: TouchEvent;
151
- touchend: TouchEvent;
152
- touchcancel: TouchEvent;
153
- touchenter: TouchEvent;
154
- touchleave: TouchEvent;
155
- }
156
- export type DOMUtils_TouchEventType = keyof DOMUtils_TouchEvent;
157
- /**
158
- * 其它事件
159
- */
160
- export interface DOMUtils_OtherEvent {
161
- message: Event;
162
- online: Event;
163
- offline: Event;
164
- popstate: Event;
165
- show: Event;
166
- storage: Event;
167
- toggle: Event;
168
- wheel: Event;
169
- propertychange: Event;
170
- fullscreenchange: Event;
171
- DOMContentLoaded: Event;
172
- }
173
- export type DOMUtils_OtherEventType = keyof DOMUtils_OtherEvent;
174
- /**
175
- * 全部事件
176
- */
177
- export declare type DOMUtils_Event = DOMUtils_MouseEvent & DOMUtils_KeyboardEvent & DOMUtils_Frame_Object_Event & DOMUtils_FormEvent & DOMUtils_ClipboardEvent & DOMUtils_PrintEvent & DOMUtils_DragEvent & DOMUtils_MediaEvent & DOMUtils_AnimationEvent & DOMUtils_TransitionEvent & DOMUtils_TouchEvent & DOMUtils_OtherEvent;
178
- /**
179
- * 事件类型
180
- */
181
- export declare type DOMUtils_EventType = keyof DOMUtils_Event;
182
- /**
183
- * 元素上的events属性
184
- */
185
- export declare interface DOMUtilsEventListenerOptionsAttribute {
186
- /**
187
- * 自定义的ownCallBack
188
- */
189
- callback: () => void;
190
- /**
191
- * 属性配置
192
- */
193
- option: AddEventListenerOptions;
194
- /**
195
- * 用户添加的事件
196
- */
197
- originCallBack: () => void;
198
- /**
199
- * 子元素选择器
200
- */
201
- selector?: string;
202
- }
203
- export declare type DOMUtilsElementEventType = HTMLElement | string | NodeList | (HTMLElement | Window | Document | Element | typeof globalThis)[] | Window | Document | Element | null | typeof globalThis | ShadowRoot | EventTarget | ChildNode | Node;
3
+ import type { WindowApiOption } from "./types/WindowApi";
4
+ import { WindowApi } from "./WindowApi";
204
5
  export declare class DOMUtilsEvent {
205
- windowApi: UtilsWindowApiOption;
206
- constructor(windowApiOption?: UtilsWindowApiOption);
6
+ windowApi: typeof WindowApi.prototype;
7
+ constructor(windowApiOption?: WindowApiOption);
207
8
  /**
208
9
  * 绑定事件
209
10
  * @param element 需要绑定的元素|元素数组|window
@@ -1,19 +1,10 @@
1
- /**
2
- * 配置类型
3
- */
4
- export type UtilsWindowApiOption = {
5
- document: Document;
6
- window: Window & typeof globalThis;
7
- globalThis: typeof globalThis | Window;
8
- self: Window & typeof globalThis;
9
- top: Window;
10
- };
1
+ import type { WindowApiOption } from "./types/WindowApi";
11
2
  export declare class WindowApi {
12
3
  /** 默认的配置 */
13
4
  private defaultApi;
14
5
  /** 使用的配置 */
15
6
  private api;
16
- constructor(option?: UtilsWindowApiOption);
7
+ constructor(option?: WindowApiOption);
17
8
  get document(): Document;
18
9
  get window(): Window & typeof globalThis;
19
10
  get globalThis(): typeof globalThis | Window;
@@ -0,0 +1,238 @@
1
+ export type DOMUtilsEventObject<T extends Node> = Event & {
2
+ target: T;
3
+ };
4
+
5
+ export type DOMUtilsCreateElementAttributesMap = {
6
+ style?: string;
7
+ id?: string;
8
+ class?: string;
9
+ "data-"?: string;
10
+ type?: string;
11
+ [key: string]: any;
12
+ };
13
+ /**
14
+ * 鼠标事件
15
+ * + https://blog.csdn.net/weixin_68658847/article/details/126939879
16
+ */
17
+
18
+ export interface DOMUtils_MouseEvent {
19
+ click: MouseEvent | PointerEvent;
20
+ contextmenu: MouseEvent | PointerEvent;
21
+ dblclick: MouseEvent | PointerEvent;
22
+ mousedown: MouseEvent | PointerEvent;
23
+ mouseenter: MouseEvent | PointerEvent;
24
+ mouseleave: MouseEvent | PointerEvent;
25
+ mousemove: MouseEvent | PointerEvent;
26
+ mouseover: MouseEvent | PointerEvent;
27
+ mouseout: MouseEvent | PointerEvent;
28
+ mouseup: MouseEvent | PointerEvent;
29
+ hover: MouseEvent;
30
+ }
31
+ export type DOMUtils_MouseEventType = keyof DOMUtils_MouseEvent;
32
+ /**
33
+ * 鼠标事件
34
+ */
35
+ export interface DOMUtils_KeyboardEvent {
36
+ keydown: KeyboardEvent;
37
+ keypress: KeyboardEvent;
38
+ keyup: KeyboardEvent;
39
+ }
40
+ export type DOMUtils_KeyboardEventType = keyof DOMUtils_KeyboardEvent;
41
+ /**
42
+ * 框架/对象事件
43
+ */
44
+ export interface DOMUtils_Frame_Object_Event {
45
+ abort: Event;
46
+ beforeunload: Event;
47
+ error: Event;
48
+ hashchange: Event;
49
+ load: Event;
50
+ pageshow: Event;
51
+ pagehide: Event;
52
+ resize: Event;
53
+ scroll: Event;
54
+ unload: Event;
55
+ }
56
+ export type DOMUtils_Frame_Object_EventType = keyof DOMUtils_Frame_Object_Event;
57
+ /**
58
+ * 表单事件
59
+ */
60
+ export interface DOMUtils_FormEvent {
61
+ blur: Event;
62
+ change: Event;
63
+ focus: Event;
64
+ focusin: Event;
65
+ focusout: Event;
66
+ input: Event;
67
+ reset: Event;
68
+ search: Event;
69
+ }
70
+ export type DOMUtils_FormEventType = keyof DOMUtils_FormEvent;
71
+
72
+ /**
73
+ * 剪贴板事件
74
+ */
75
+ export interface DOMUtils_ClipboardEvent {
76
+ copy: ClipboardEvent;
77
+ cut: ClipboardEvent;
78
+ paste: ClipboardEvent;
79
+ }
80
+ export type DOMUtils_ClipboardEventType = keyof DOMUtils_ClipboardEvent;
81
+
82
+ /**
83
+ * 打印事件
84
+ */
85
+ export interface DOMUtils_PrintEvent {
86
+ afterprint: Event;
87
+ beforeprint: Event;
88
+ }
89
+ export type DOMUtils_PrintEventType = keyof DOMUtils_PrintEvent;
90
+
91
+ /**
92
+ * 拖动事件
93
+ */
94
+ export interface DOMUtils_DragEvent {
95
+ drag: DragEvent;
96
+ dragend: DragEvent;
97
+ dragenter: DragEvent;
98
+ dragleave: DragEvent;
99
+ dragover: DragEvent;
100
+ dragstart: DragEvent;
101
+ drop: DragEvent;
102
+ }
103
+ export type DOMUtils_DragEventType = keyof DOMUtils_DragEvent;
104
+
105
+ /**
106
+ * 多媒体(Media)事件
107
+ */
108
+ export interface DOMUtils_MediaEvent {
109
+ abort: Event;
110
+ canplay: Event;
111
+ canplaythrough: Event;
112
+ durationchange: Event;
113
+ emptied: Event;
114
+ ended: Event;
115
+ error: Event;
116
+ loadeddata: Event;
117
+ loadedmetadata: Event;
118
+ loadstart: Event;
119
+ pause: Event;
120
+ play: Event;
121
+ playing: Event;
122
+ progress: Event;
123
+ ratechange: Event;
124
+ seeked: Event;
125
+ seeking: Event;
126
+ stalled: Event;
127
+ suspend: Event;
128
+ timeupdate: Event;
129
+ volumechange: Event;
130
+ waiting: Event;
131
+ }
132
+ export type DOMUtils_MediaEventType = keyof DOMUtils_MediaEvent;
133
+
134
+ /**
135
+ * 动画事件
136
+ */
137
+ export interface DOMUtils_AnimationEvent {
138
+ animationend: AnimationEvent;
139
+ animationiteration: AnimationEvent;
140
+ animationstart: AnimationEvent;
141
+ }
142
+ export type DOMUtils_AnimationEventType = keyof DOMUtils_AnimationEvent;
143
+
144
+ /**
145
+ * 过渡事件
146
+ */
147
+ export interface DOMUtils_TransitionEvent {
148
+ transitionend: TransitionEvent;
149
+ }
150
+ export type DOMUtils_TransitionEventType = keyof DOMUtils_TransitionEvent;
151
+
152
+ /**
153
+ * 触摸事件
154
+ */
155
+ export interface DOMUtils_TouchEvent {
156
+ touchstart: TouchEvent;
157
+ touchmove: TouchEvent;
158
+ touchend: TouchEvent;
159
+ touchcancel: TouchEvent;
160
+ touchenter: TouchEvent;
161
+ touchleave: TouchEvent;
162
+ }
163
+ export type DOMUtils_TouchEventType = keyof DOMUtils_TouchEvent;
164
+ /**
165
+ * 其它事件
166
+ */
167
+ export interface DOMUtils_OtherEvent {
168
+ message: Event;
169
+ online: Event;
170
+ offline: Event;
171
+ popstate: Event;
172
+ show: Event;
173
+ storage: Event;
174
+ toggle: Event;
175
+ wheel: Event;
176
+ propertychange: Event;
177
+ fullscreenchange: Event;
178
+ DOMContentLoaded: Event;
179
+ }
180
+ export type DOMUtils_OtherEventType = keyof DOMUtils_OtherEvent;
181
+
182
+ /**
183
+ * 全部事件
184
+ */
185
+ export declare type DOMUtils_Event = DOMUtils_MouseEvent &
186
+ DOMUtils_KeyboardEvent &
187
+ DOMUtils_Frame_Object_Event &
188
+ DOMUtils_FormEvent &
189
+ DOMUtils_ClipboardEvent &
190
+ DOMUtils_PrintEvent &
191
+ DOMUtils_DragEvent &
192
+ DOMUtils_MediaEvent &
193
+ DOMUtils_AnimationEvent &
194
+ DOMUtils_TransitionEvent &
195
+ DOMUtils_TouchEvent &
196
+ DOMUtils_OtherEvent;
197
+
198
+ /**
199
+ * 事件类型
200
+ */
201
+ export declare type DOMUtils_EventType = keyof DOMUtils_Event;
202
+
203
+ /**
204
+ * 元素上的events属性
205
+ */
206
+ export declare interface DOMUtilsEventListenerOptionsAttribute {
207
+ /**
208
+ * 自定义的ownCallBack
209
+ */
210
+ callback: () => void;
211
+ /**
212
+ * 属性配置
213
+ */
214
+ option: AddEventListenerOptions;
215
+ /**
216
+ * 用户添加的事件
217
+ */
218
+ originCallBack: () => void;
219
+ /**
220
+ * 子元素选择器
221
+ */
222
+ selector?: string;
223
+ }
224
+
225
+ export declare type DOMUtilsElementEventType =
226
+ | HTMLElement
227
+ | string
228
+ | NodeList
229
+ | (HTMLElement | Window | Document | Element | typeof globalThis)[]
230
+ | Window
231
+ | Document
232
+ | Element
233
+ | null
234
+ | typeof globalThis
235
+ | ShadowRoot
236
+ | EventTarget
237
+ | ChildNode
238
+ | Node;
@@ -0,0 +1,10 @@
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/domutils",
3
- "version": "1.3.8",
3
+ "version": "1.4.0",
4
4
  "description": "使用js重新对jQuery的部分函数进行了仿写",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/DOMUtils.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  import { DOMUtilsCommonUtils } from "./DOMUtilsCommonUtils";
2
- import {
3
- type DOMUtilsCreateElementAttributesMap,
4
- DOMUtilsEvent,
5
- } from "./DOMUtilsEvent";
2
+ import { DOMUtilsEvent } from "./DOMUtilsEvent";
3
+ import type { DOMUtilsCreateElementAttributesMap } from "./types/DOMUtilsEvent";
6
4
  import {
7
5
  ParseHTMLReturnType,
8
6
  type DOMUtilsTargetElementType,
9
7
  } from "./types/global";
10
- import { type UtilsWindowApiOption } from "./WindowApi";
8
+ import type { WindowApiOption } from "./types/WindowApi";
11
9
 
12
10
  /**
13
11
  * 判断是否是元素列表
@@ -18,11 +16,11 @@ export const isNodeList = ($ele: any): $ele is any[] | NodeList => {
18
16
  };
19
17
 
20
18
  class DOMUtils extends DOMUtilsEvent {
21
- constructor(option?: UtilsWindowApiOption) {
19
+ constructor(option?: WindowApiOption) {
22
20
  super(option);
23
21
  }
24
22
  /** 版本号 */
25
- version = "2024.10.23";
23
+ version = "2024.11.6";
26
24
  /**
27
25
  * 获取元素的属性值
28
26
  * @param element 目标元素
@@ -1951,7 +1949,7 @@ class DOMUtils extends DOMUtilsEvent {
1951
1949
  * @param option
1952
1950
  * @returns
1953
1951
  */
1954
- createDOMUtils(option?: UtilsWindowApiOption) {
1952
+ createDOMUtils(option?: WindowApiOption) {
1955
1953
  return new DOMUtils(option);
1956
1954
  }
1957
1955
  /**
@@ -1,11 +1,12 @@
1
- import { UtilsWindowApiOption } from "./WindowApi";
1
+ import { WindowApi } from "./WindowApi";
2
2
 
3
3
  /** 通用工具类 */
4
4
  const DOMUtilsCommonUtils = {
5
- windowApi: {
6
- window: window,
5
+ windowApi: new WindowApi({
7
6
  document: document,
8
- } as UtilsWindowApiOption,
7
+ window: window,
8
+ top: top!,
9
+ }),
9
10
  /**
10
11
  * 判断元素是否已显示或已连接
11
12
  * @param element
@@ -1,6 +1,6 @@
1
1
  /* 数据 */
2
2
  const DOMUtilsData = {
3
- /** .on绑定的事件 */
3
+ /** .on添加在元素存储的事件 */
4
4
  SymbolEvents: Symbol(
5
5
  "events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
6
6
  ),