@qy_better_lib/core 0.2.6 → 0.2.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,10 +1,18 @@
1
+ /**
2
+ * 可能为null或undefined的Element
3
+ */
4
+ type MaybeElement = Element | null | undefined;
5
+ /**
6
+ * 可能为null或undefined的EventTarget(包括Element、Window、Document)
7
+ */
8
+ type MaybeEventTarget = (Element | Window | Document) | null | undefined;
1
9
  /**
2
10
  * 根据类名获取父元素
3
11
  * @param dom DOM元素
4
12
  * @param class_name CSS类名
5
13
  * @returns DOM元素或null
6
14
  */
7
- export declare function get_parent_by_class(dom: Element | null, class_name: string): Element | null;
15
+ export declare function get_parent_by_class(dom: MaybeElement, class_name: string): MaybeElement;
8
16
  /**
9
17
  * 滚动到底部
10
18
  * @param dom_id 元素ID
@@ -17,7 +25,7 @@ export declare function scroll_footer(dom_id: string, behavior?: boolean): void;
17
25
  * @param context 上下文元素,默认为document
18
26
  * @returns DOM元素或null
19
27
  */
20
- export declare function get_element(selector: string, context?: Element | Document): Element | null;
28
+ export declare function get_element(selector: string, context?: Element | Document): MaybeElement;
21
29
  /**
22
30
  * 根据选择器获取多个元素
23
31
  * @param selector 选择器
@@ -30,67 +38,67 @@ export declare function get_elements(selector: string, context?: Element | Docum
30
38
  * @param element DOM元素
31
39
  * @param class_name 类名
32
40
  */
33
- export declare function add_class(element: Element | null, class_name: string): void;
41
+ export declare function add_class(element: MaybeElement, class_name: string): void;
34
42
  /**
35
43
  * 移除类名
36
44
  * @param element DOM元素
37
45
  * @param class_name 类名
38
46
  */
39
- export declare function remove_class(element: Element | null, class_name: string): void;
47
+ export declare function remove_class(element: MaybeElement, class_name: string): void;
40
48
  /**
41
49
  * 切换类名
42
50
  * @param element DOM元素
43
51
  * @param class_name 类名
44
52
  * @returns 是否添加了类名
45
53
  */
46
- export declare function toggle_class(element: Element | null, class_name: string): boolean;
54
+ export declare function toggle_class(element: MaybeElement, class_name: string): boolean;
47
55
  /**
48
56
  * 检查是否包含类名
49
57
  * @param element DOM元素
50
58
  * @param class_name 类名
51
59
  * @returns 是否包含类名
52
60
  */
53
- export declare function has_class(element: Element | null, class_name: string): boolean;
61
+ export declare function has_class(element: MaybeElement, class_name: string): boolean;
54
62
  /**
55
63
  * 获取元素样式
56
64
  * @param element DOM元素
57
65
  * @param property CSS属性名
58
66
  * @returns CSS属性值
59
67
  */
60
- export declare function get_style(element: Element | null, property: string): string;
68
+ export declare function get_style(element: MaybeElement, property: string): string;
61
69
  /**
62
70
  * 设置元素样式
63
71
  * @param element DOM元素
64
72
  * @param property CSS属性名
65
73
  * @param value CSS属性值
66
74
  */
67
- export declare function set_style(element: Element | null, property: string, value: string): void;
75
+ export declare function set_style(element: MaybeElement, property: string, value: string): void;
68
76
  /**
69
77
  * 设置元素多个样式
70
78
  * @param element DOM元素
71
79
  * @param styles 样式对象
72
80
  */
73
- export declare function set_styles(element: Element | null, styles: Record<string, string>): void;
81
+ export declare function set_styles(element: MaybeElement, styles: Record<string, string>): void;
74
82
  /**
75
83
  * 获取元素属性
76
84
  * @param element DOM元素
77
85
  * @param attribute 属性名
78
86
  * @returns 属性值
79
87
  */
80
- export declare function get_attribute(element: Element | null, attribute: string): string;
88
+ export declare function get_attribute(element: MaybeElement, attribute: string): string;
81
89
  /**
82
90
  * 设置元素属性
83
91
  * @param element DOM元素
84
92
  * @param attribute 属性名
85
93
  * @param value 属性值
86
94
  */
87
- export declare function set_attribute(element: Element | null, attribute: string, value: string): void;
95
+ export declare function set_attribute(element: MaybeElement, attribute: string, value: string): void;
88
96
  /**
89
97
  * 移除元素属性
90
98
  * @param element DOM元素
91
99
  * @param attribute 属性名
92
100
  */
93
- export declare function remove_attribute(element: Element | null, attribute: string): void;
101
+ export declare function remove_attribute(element: MaybeElement, attribute: string): void;
94
102
  /**
95
103
  * 绑定事件
96
104
  * @param element DOM元素
@@ -98,7 +106,7 @@ export declare function remove_attribute(element: Element | null, attribute: str
98
106
  * @param handler 事件处理函数
99
107
  * @param options 事件选项
100
108
  */
101
- export declare function on(element: Element | Window | Document | null, event: string, handler: EventListener, options?: AddEventListenerOptions): void;
109
+ export declare function on(element: MaybeEventTarget, event: string, handler: EventListener, options?: AddEventListenerOptions): void;
102
110
  /**
103
111
  * 解绑事件
104
112
  * @param element DOM元素
@@ -106,7 +114,7 @@ export declare function on(element: Element | Window | Document | null, event: s
106
114
  * @param handler 事件处理函数
107
115
  * @param options 事件选项
108
116
  */
109
- export declare function off(element: Element | Window | Document | null, event: string, handler: EventListener, options?: EventListenerOptions): void;
117
+ export declare function off(element: MaybeEventTarget, event: string, handler: EventListener, options?: EventListenerOptions): void;
110
118
  /**
111
119
  * 创建元素
112
120
  * @param tag_name 标签名
@@ -124,13 +132,13 @@ export declare function create_element(tag_name: string, options?: {
124
132
  * @param element DOM元素
125
133
  * @returns 元素位置和尺寸信息
126
134
  */
127
- export declare function get_element_rect(element: Element | null): DOMRect | null;
135
+ export declare function get_element_rect(element: MaybeElement): DOMRect | null;
128
136
  /**
129
137
  * 获取元素相对于文档的位置
130
138
  * @param element DOM元素
131
139
  * @returns 元素位置信息
132
140
  */
133
- export declare function get_element_position(element: Element | null): {
141
+ export declare function get_element_position(element: MaybeElement): {
134
142
  top: number;
135
143
  left: number;
136
144
  } | null;
@@ -139,7 +147,7 @@ export declare function get_element_position(element: Element | null): {
139
147
  * @param element DOM元素
140
148
  * @returns 元素尺寸信息
141
149
  */
142
- export declare function get_element_size(element: Element | null): {
150
+ export declare function get_element_size(element: MaybeElement): {
143
151
  width: number;
144
152
  height: number;
145
153
  } | null;
@@ -148,7 +156,7 @@ export declare function get_element_size(element: Element | null): {
148
156
  * @param element DOM元素
149
157
  * @param options 滚动选项
150
158
  */
151
- export declare function scroll_to_element(element: Element | null, options?: {
159
+ export declare function scroll_to_element(element: MaybeElement, options?: {
152
160
  behavior?: 'smooth' | 'auto';
153
161
  offsetTop?: number;
154
162
  offsetLeft?: number;
@@ -158,13 +166,13 @@ export declare function scroll_to_element(element: Element | null, options?: {
158
166
  * @param element DOM元素
159
167
  * @returns 是否在视口中
160
168
  */
161
- export declare function is_in_viewport(element: Element | null): boolean;
169
+ export declare function is_in_viewport(element: MaybeElement): boolean;
162
170
  /**
163
171
  * 检查元素是否完全在视口中
164
172
  * @param element DOM元素
165
173
  * @returns 是否完全在视口中
166
174
  */
167
- export declare function is_completely_in_viewport(element: Element | null): boolean;
175
+ export declare function is_completely_in_viewport(element: MaybeElement): boolean;
168
176
  /**
169
177
  * 获取窗口尺寸
170
178
  * @returns 窗口尺寸信息
@@ -188,3 +196,4 @@ export declare function get_document_size(): {
188
196
  * @returns 自适应后的尺寸
189
197
  */
190
198
  export declare function auto_size(size: number, deflate_width?: number): number;
199
+ export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@qy_better_lib/core",
3
3
  "type": "module",
4
4
  "private": false,
5
- "version": "0.2.6",
5
+ "version": "0.2.7",
6
6
  "description": "qy better lib core",
7
7
  "author": "luhuiming",
8
8
  "license": "MIT",