@whitesev/domutils 1.8.5 → 1.8.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.
- package/dist/index.amd.js +22 -22
- 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 +22 -22
- 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 +22 -22
- 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 +22 -22
- 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 +22 -22
- 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 +22 -22
- 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/ElementWait.d.ts +49 -27
- package/dist/types/src/index.d.ts +6 -9
- package/dist/types/src/types/DOMUtilsCSSProperty.d.ts +36 -0
- package/package.json +2 -2
- package/src/ElementWait.ts +73 -47
- package/src/index.ts +10 -22
- package/src/types/DOMUtilsCSSProperty.d.ts +36 -0
package/src/ElementWait.ts
CHANGED
|
@@ -18,7 +18,7 @@ class ElementWait extends ElementSelector {
|
|
|
18
18
|
* @param timeout 超时时间,默认0
|
|
19
19
|
* @param parent (可选)父元素,默认document
|
|
20
20
|
* @example
|
|
21
|
-
*
|
|
21
|
+
* DOMUtils.wait(()=> {
|
|
22
22
|
* let $test = document.querySelector("#test");
|
|
23
23
|
* return {
|
|
24
24
|
* success: $test !== null,
|
|
@@ -100,26 +100,52 @@ class ElementWait extends ElementSelector {
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* 等待元素出现
|
|
105
|
+
* @param selectorFn 获取元素的函数
|
|
106
|
+
* @example
|
|
107
|
+
* DOMUtils.waitNode(()=>document.querySelector("div")).then( $div =>{
|
|
108
|
+
* console.log($div); // $div => HTMLDivELement
|
|
109
|
+
* })
|
|
110
|
+
*/
|
|
111
|
+
waitNode<K>(selectorFn: () => K | null | undefined): Promise<K>;
|
|
103
112
|
/**
|
|
104
113
|
* 等待元素出现
|
|
105
114
|
* @param selectorFn 获取元素的函数
|
|
106
115
|
* @param timeout 超时时间,默认0
|
|
107
116
|
* @example
|
|
108
|
-
*
|
|
117
|
+
* DOMUtils.waitNode(()=>document.querySelector("div"), 1000).then( $div =>{
|
|
109
118
|
* console.log($div); // $div => HTMLDivELement | null
|
|
110
119
|
* })
|
|
111
120
|
*/
|
|
112
|
-
waitNode<K>(selectorFn: () => K | null | undefined): Promise<K>;
|
|
113
121
|
waitNode<K>(selectorFn: () => K | null | undefined, timeout: number): Promise<K | null | undefined>;
|
|
122
|
+
/**
|
|
123
|
+
* 等待元素出现
|
|
124
|
+
* @param selectorFn 获取元素的函数
|
|
125
|
+
* @param parent 父元素
|
|
126
|
+
* @param timeout 超时时间,默认0
|
|
127
|
+
* @example
|
|
128
|
+
* DOMUtils.waitNode(()=>document.querySelector("div"), document).then( $div =>{
|
|
129
|
+
* console.log($div); // $div => HTMLDivELement
|
|
130
|
+
* })
|
|
131
|
+
* DOMUtils.waitNode(()=>document.querySelector("div"), document, 1000).then( $div =>{
|
|
132
|
+
* console.log($div); // $div => HTMLDivELement | null
|
|
133
|
+
* })
|
|
134
|
+
*/
|
|
135
|
+
waitNode<K>(
|
|
136
|
+
selectorFn: () => K | null | undefined,
|
|
137
|
+
parent: Node | Element | Document | HTMLElement,
|
|
138
|
+
timeout?: number
|
|
139
|
+
): Promise<K | null | undefined>;
|
|
114
140
|
/**
|
|
115
141
|
* 等待元素出现
|
|
116
142
|
* @param selector CSS选择器
|
|
117
143
|
* @param parent (可选)父元素,默认document
|
|
118
144
|
* @example
|
|
119
|
-
*
|
|
145
|
+
* DOMUtils.waitNode("div").then( $div =>{
|
|
120
146
|
* console.log($div); // div => HTMLDivELement
|
|
121
147
|
* })
|
|
122
|
-
*
|
|
148
|
+
* DOMUtils.waitNode("div", document).then( $div =>{
|
|
123
149
|
* console.log($div); // div => HTMLDivELement
|
|
124
150
|
* })
|
|
125
151
|
*/
|
|
@@ -133,10 +159,10 @@ class ElementWait extends ElementSelector {
|
|
|
133
159
|
* @param selectorList CSS选择器数组
|
|
134
160
|
* @param parent (可选)父元素,默认document
|
|
135
161
|
* @example
|
|
136
|
-
*
|
|
162
|
+
* DOMUtils.waitNode(["div"]).then( ([$div]) =>{
|
|
137
163
|
* console.log($div); // div => HTMLDivELement[]
|
|
138
164
|
* })
|
|
139
|
-
*
|
|
165
|
+
* DOMUtils.waitNode(["div"], document).then( ([$div]) =>{
|
|
140
166
|
* console.log($div); // div => HTMLDivELement[]
|
|
141
167
|
* })
|
|
142
168
|
*/
|
|
@@ -151,7 +177,7 @@ class ElementWait extends ElementSelector {
|
|
|
151
177
|
* @param parent 父元素,默认document
|
|
152
178
|
* @param timeout 超时时间,默认0
|
|
153
179
|
* @example
|
|
154
|
-
*
|
|
180
|
+
* DOMUtils.waitNode("div", document, 1000).then( $div =>{
|
|
155
181
|
* console.log($div); // $div => HTMLDivELement | null
|
|
156
182
|
* })
|
|
157
183
|
*/
|
|
@@ -171,7 +197,7 @@ class ElementWait extends ElementSelector {
|
|
|
171
197
|
* @param parent 父元素,默认document
|
|
172
198
|
* @param timeout 超时时间,默认0
|
|
173
199
|
* @example
|
|
174
|
-
*
|
|
200
|
+
* DOMUtils.waitNode(["div"], document, 1000).then( ([$div]) =>{
|
|
175
201
|
* console.log($div); // $div => HTMLDivELement[] | null
|
|
176
202
|
* })
|
|
177
203
|
*/
|
|
@@ -190,7 +216,7 @@ class ElementWait extends ElementSelector {
|
|
|
190
216
|
* @param selector CSS选择器
|
|
191
217
|
* @param timeout 超时时间,默认0
|
|
192
218
|
* @example
|
|
193
|
-
*
|
|
219
|
+
* DOMUtils.waitNode("div", 1000).then( $div =>{
|
|
194
220
|
* console.log($div); // $div => HTMLDivELement | null
|
|
195
221
|
* })
|
|
196
222
|
*/
|
|
@@ -204,7 +230,7 @@ class ElementWait extends ElementSelector {
|
|
|
204
230
|
* @param selectorList CSS选择器数组
|
|
205
231
|
* @param timeout 超时时间,默认0
|
|
206
232
|
* @example
|
|
207
|
-
*
|
|
233
|
+
* DOMUtils.waitNode(["div"], 1000).then( [$div] =>{
|
|
208
234
|
* console.log($div); // $div => HTMLDivELement[] | null
|
|
209
235
|
* })
|
|
210
236
|
*/
|
|
@@ -224,7 +250,7 @@ class ElementWait extends ElementSelector {
|
|
|
224
250
|
// 超时时间
|
|
225
251
|
let timeout = 0;
|
|
226
252
|
if (typeof args[0] !== "string" && !Array.isArray(args[0]) && typeof args[0] !== "function") {
|
|
227
|
-
throw new TypeError("
|
|
253
|
+
throw new TypeError("DOMUtils.waitNode 第一个参数必须是string|string[]|Function");
|
|
228
254
|
}
|
|
229
255
|
if (args.length === 1) {
|
|
230
256
|
// 上面已做处理
|
|
@@ -237,7 +263,7 @@ class ElementWait extends ElementSelector {
|
|
|
237
263
|
// "div",document
|
|
238
264
|
parent = secondParam as any as Element;
|
|
239
265
|
} else {
|
|
240
|
-
throw new TypeError("
|
|
266
|
+
throw new TypeError("DOMUtils.waitNode 第二个参数必须是number|Node");
|
|
241
267
|
}
|
|
242
268
|
} else if (args.length === 3) {
|
|
243
269
|
// "div",document,10000
|
|
@@ -250,13 +276,13 @@ class ElementWait extends ElementSelector {
|
|
|
250
276
|
if (typeof thirdParam === "number") {
|
|
251
277
|
timeout = thirdParam;
|
|
252
278
|
} else {
|
|
253
|
-
throw new TypeError("
|
|
279
|
+
throw new TypeError("DOMUtils.waitNode 第三个参数必须是number");
|
|
254
280
|
}
|
|
255
281
|
} else {
|
|
256
|
-
throw new TypeError("
|
|
282
|
+
throw new TypeError("DOMUtils.waitNode 第二个参数必须是Node");
|
|
257
283
|
}
|
|
258
284
|
} else {
|
|
259
|
-
throw new TypeError("
|
|
285
|
+
throw new TypeError("DOMUtils.waitNode 参数个数错误");
|
|
260
286
|
}
|
|
261
287
|
function getNode() {
|
|
262
288
|
if (Array.isArray(selector)) {
|
|
@@ -300,10 +326,10 @@ class ElementWait extends ElementSelector {
|
|
|
300
326
|
* @param selectorList CSS选择器数组
|
|
301
327
|
* @param parent (可选)监听的父元素
|
|
302
328
|
* @example
|
|
303
|
-
*
|
|
329
|
+
* DOMUtils.waitAnyNode(["div","div"]).then( $div =>{
|
|
304
330
|
* console.log($div); // $div => HTMLDivELement 这里是第一个
|
|
305
331
|
* })
|
|
306
|
-
*
|
|
332
|
+
* DOMUtils.waitAnyNode(["a","div"], document).then( $a =>{
|
|
307
333
|
* console.log($a); // $a => HTMLAnchorElement 这里是第一个
|
|
308
334
|
* })
|
|
309
335
|
*/
|
|
@@ -318,7 +344,7 @@ class ElementWait extends ElementSelector {
|
|
|
318
344
|
* @param parent 父元素,默认document
|
|
319
345
|
* @param timeout 超时时间,默认0
|
|
320
346
|
* @example
|
|
321
|
-
*
|
|
347
|
+
* DOMUtils.waitAnyNode(["div","div"], document, 10000).then( $div =>{
|
|
322
348
|
* console.log($div); // $div => HTMLDivELement | null
|
|
323
349
|
* })
|
|
324
350
|
*/
|
|
@@ -337,7 +363,7 @@ class ElementWait extends ElementSelector {
|
|
|
337
363
|
* @param selectorList CSS选择器数组
|
|
338
364
|
* @param timeout 超时时间,默认0
|
|
339
365
|
* @example
|
|
340
|
-
*
|
|
366
|
+
* DOMUtils.waitAnyNode(["div","div"], 10000).then( $div =>{
|
|
341
367
|
* console.log($div); // $div => HTMLDivELement | null
|
|
342
368
|
* })
|
|
343
369
|
*/
|
|
@@ -357,7 +383,7 @@ class ElementWait extends ElementSelector {
|
|
|
357
383
|
// 超时时间
|
|
358
384
|
let timeout = 0;
|
|
359
385
|
if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
|
|
360
|
-
throw new TypeError("
|
|
386
|
+
throw new TypeError("DOMUtils.waitAnyNode 第一个参数必须是string[]");
|
|
361
387
|
}
|
|
362
388
|
if (args.length === 1) {
|
|
363
389
|
// 上面已做处理
|
|
@@ -370,7 +396,7 @@ class ElementWait extends ElementSelector {
|
|
|
370
396
|
// "div",document
|
|
371
397
|
parent = secondParam as any as Element;
|
|
372
398
|
} else {
|
|
373
|
-
throw new TypeError("
|
|
399
|
+
throw new TypeError("DOMUtils.waitAnyNode 第二个参数必须是number|Node");
|
|
374
400
|
}
|
|
375
401
|
} else if (args.length === 3) {
|
|
376
402
|
// "div",document,10000
|
|
@@ -383,13 +409,13 @@ class ElementWait extends ElementSelector {
|
|
|
383
409
|
if (typeof thirdParam === "number") {
|
|
384
410
|
timeout = thirdParam;
|
|
385
411
|
} else {
|
|
386
|
-
throw new TypeError("
|
|
412
|
+
throw new TypeError("DOMUtils.waitAnyNode 第三个参数必须是number");
|
|
387
413
|
}
|
|
388
414
|
} else {
|
|
389
|
-
throw new TypeError("
|
|
415
|
+
throw new TypeError("DOMUtils.waitAnyNode 第二个参数必须是Node");
|
|
390
416
|
}
|
|
391
417
|
} else {
|
|
392
|
-
throw new TypeError("
|
|
418
|
+
throw new TypeError("DOMUtils.waitAnyNode 参数个数错误");
|
|
393
419
|
}
|
|
394
420
|
const promiseList = selectorList.map((selector) => {
|
|
395
421
|
return UtilsContext.waitNode<T>(selector, parent, timeout);
|
|
@@ -401,10 +427,10 @@ class ElementWait extends ElementSelector {
|
|
|
401
427
|
* @param selector CSS选择器
|
|
402
428
|
* @param parent (可选)监听的父元素
|
|
403
429
|
* @example
|
|
404
|
-
*
|
|
430
|
+
* DOMUtils.waitNodeList("div").then( $result =>{
|
|
405
431
|
* console.log($result); // $result => NodeListOf<HTMLDivElement>
|
|
406
432
|
* })
|
|
407
|
-
*
|
|
433
|
+
* DOMUtils.waitNodeList("div", document).then( $result =>{
|
|
408
434
|
* console.log($result); // $result => NodeListOf<HTMLDivElement>
|
|
409
435
|
* })
|
|
410
436
|
*/
|
|
@@ -421,10 +447,10 @@ class ElementWait extends ElementSelector {
|
|
|
421
447
|
* @param selectorList CSS选择器数组
|
|
422
448
|
* @param parent (可选)监听的父元素
|
|
423
449
|
* @example
|
|
424
|
-
*
|
|
450
|
+
* DOMUtils.waitNodeList(["div"]).then( $result =>{
|
|
425
451
|
* console.log($result); // $result => NodeListOf<HTMLDivElement>[]
|
|
426
452
|
* })
|
|
427
|
-
*
|
|
453
|
+
* DOMUtils.waitNodeList(["div"], document).then( $result =>{
|
|
428
454
|
* console.log($result); // $result => NodeListOf<HTMLDivElement>[]
|
|
429
455
|
* })
|
|
430
456
|
*/
|
|
@@ -442,7 +468,7 @@ class ElementWait extends ElementSelector {
|
|
|
442
468
|
* @param parent 监听的父元素
|
|
443
469
|
* @param timeout 超时时间,默认0
|
|
444
470
|
* @example
|
|
445
|
-
*
|
|
471
|
+
* DOMUtils.waitNodeList("div", document, 10000).then( $result =>{
|
|
446
472
|
* console.log($result); // $result => NodeListOf<HTMLDivElement> | null
|
|
447
473
|
* })
|
|
448
474
|
*/
|
|
@@ -462,7 +488,7 @@ class ElementWait extends ElementSelector {
|
|
|
462
488
|
* @param parent 监听的父元素
|
|
463
489
|
* @param timeout 超时时间,默认0
|
|
464
490
|
* @example
|
|
465
|
-
*
|
|
491
|
+
* DOMUtils.waitNodeList(["div"], document, 10000).then( $result =>{
|
|
466
492
|
* console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
|
|
467
493
|
* })
|
|
468
494
|
*/
|
|
@@ -481,7 +507,7 @@ class ElementWait extends ElementSelector {
|
|
|
481
507
|
* @param selector CSS选择器数组
|
|
482
508
|
* @param timeout 超时时间,默认0
|
|
483
509
|
* @example
|
|
484
|
-
*
|
|
510
|
+
* DOMUtils.waitNodeList("div", 10000).then( $result =>{
|
|
485
511
|
* console.log($result); // $result => NodeListOf<HTMLDivElement> | null
|
|
486
512
|
* })
|
|
487
513
|
*/
|
|
@@ -495,7 +521,7 @@ class ElementWait extends ElementSelector {
|
|
|
495
521
|
* @param selectorList CSS选择器数组
|
|
496
522
|
* @param timeout 超时时间,默认0
|
|
497
523
|
* @example
|
|
498
|
-
*
|
|
524
|
+
* DOMUtils.waitNodeList(["div"], 10000).then( $result =>{
|
|
499
525
|
* console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
|
|
500
526
|
* })
|
|
501
527
|
*/
|
|
@@ -515,7 +541,7 @@ class ElementWait extends ElementSelector {
|
|
|
515
541
|
// 超时时间
|
|
516
542
|
let timeout = 0;
|
|
517
543
|
if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
|
|
518
|
-
throw new TypeError("
|
|
544
|
+
throw new TypeError("DOMUtils.waitNodeList 第一个参数必须是string|string[]");
|
|
519
545
|
}
|
|
520
546
|
if (args.length === 1) {
|
|
521
547
|
// 上面已做处理
|
|
@@ -528,7 +554,7 @@ class ElementWait extends ElementSelector {
|
|
|
528
554
|
// "div",document
|
|
529
555
|
parent = secondParam as any as Element;
|
|
530
556
|
} else {
|
|
531
|
-
throw new TypeError("
|
|
557
|
+
throw new TypeError("DOMUtils.waitNodeList 第二个参数必须是number|Node");
|
|
532
558
|
}
|
|
533
559
|
} else if (args.length === 3) {
|
|
534
560
|
// "div",document,10000
|
|
@@ -541,13 +567,13 @@ class ElementWait extends ElementSelector {
|
|
|
541
567
|
if (typeof thirdParam === "number") {
|
|
542
568
|
timeout = thirdParam;
|
|
543
569
|
} else {
|
|
544
|
-
throw new TypeError("
|
|
570
|
+
throw new TypeError("DOMUtils.waitNodeList 第三个参数必须是number");
|
|
545
571
|
}
|
|
546
572
|
} else {
|
|
547
|
-
throw new TypeError("
|
|
573
|
+
throw new TypeError("DOMUtils.waitNodeList 第二个参数必须是Node");
|
|
548
574
|
}
|
|
549
575
|
} else {
|
|
550
|
-
throw new TypeError("
|
|
576
|
+
throw new TypeError("DOMUtils.waitNodeList 参数个数错误");
|
|
551
577
|
}
|
|
552
578
|
function getNodeList() {
|
|
553
579
|
if (Array.isArray(selector)) {
|
|
@@ -592,10 +618,10 @@ class ElementWait extends ElementSelector {
|
|
|
592
618
|
* @param selectorList CSS选择器数组
|
|
593
619
|
* @param parent (可选)监听的父元素
|
|
594
620
|
* @example
|
|
595
|
-
*
|
|
621
|
+
* DOMUtils.waitAnyNodeList(["div","a"]).then( $result =>{
|
|
596
622
|
* console.log($result); // $result => NodeListOf<HTMLDivElement>
|
|
597
623
|
* })
|
|
598
|
-
*
|
|
624
|
+
* DOMUtils.waitAnyNodeList(["div","a"], document).then( $result =>{
|
|
599
625
|
* console.log($result); // $result => NodeListOf<HTMLDivElement>
|
|
600
626
|
* })
|
|
601
627
|
*/
|
|
@@ -613,7 +639,7 @@ class ElementWait extends ElementSelector {
|
|
|
613
639
|
* @param parent 父元素,默认document
|
|
614
640
|
* @param timeout 超时时间,默认0
|
|
615
641
|
* @example
|
|
616
|
-
*
|
|
642
|
+
* DOMUtils.waitAnyNodeList(["div","a"], document, 10000).then( $result =>{
|
|
617
643
|
* console.log($result); // $result => NodeListOf<HTMLDivElement> | null
|
|
618
644
|
* })
|
|
619
645
|
*/
|
|
@@ -632,7 +658,7 @@ class ElementWait extends ElementSelector {
|
|
|
632
658
|
* @param selectorList CSS选择器数组
|
|
633
659
|
* @param timeout 超时时间,默认0
|
|
634
660
|
* @example
|
|
635
|
-
*
|
|
661
|
+
* DOMUtils.waitAnyNodeList(["div","div"], 10000).then( $result =>{
|
|
636
662
|
* console.log($result); // $result => NodeListOf<HTMLDivElement> | null
|
|
637
663
|
* })
|
|
638
664
|
*/
|
|
@@ -652,7 +678,7 @@ class ElementWait extends ElementSelector {
|
|
|
652
678
|
// 超时时间
|
|
653
679
|
let timeout = 0;
|
|
654
680
|
if (!Array.isArray(args[0])) {
|
|
655
|
-
throw new TypeError("
|
|
681
|
+
throw new TypeError("DOMUtils.waitAnyNodeList 第一个参数必须是string[]");
|
|
656
682
|
}
|
|
657
683
|
if (args.length === 1) {
|
|
658
684
|
// 上面已做处理
|
|
@@ -665,7 +691,7 @@ class ElementWait extends ElementSelector {
|
|
|
665
691
|
// "div",document
|
|
666
692
|
parent = secondParam as any as Element;
|
|
667
693
|
} else {
|
|
668
|
-
throw new TypeError("
|
|
694
|
+
throw new TypeError("DOMUtils.waitAnyNodeList 第二个参数必须是number|Node");
|
|
669
695
|
}
|
|
670
696
|
} else if (args.length === 3) {
|
|
671
697
|
// "div",document,10000
|
|
@@ -678,13 +704,13 @@ class ElementWait extends ElementSelector {
|
|
|
678
704
|
if (typeof thirdParam === "number") {
|
|
679
705
|
timeout = thirdParam;
|
|
680
706
|
} else {
|
|
681
|
-
throw new TypeError("
|
|
707
|
+
throw new TypeError("DOMUtils.waitAnyNodeList 第三个参数必须是number");
|
|
682
708
|
}
|
|
683
709
|
} else {
|
|
684
|
-
throw new TypeError("
|
|
710
|
+
throw new TypeError("DOMUtils.waitAnyNodeList 第二个参数必须是Node");
|
|
685
711
|
}
|
|
686
712
|
} else {
|
|
687
|
-
throw new TypeError("
|
|
713
|
+
throw new TypeError("DOMUtils.waitAnyNodeList 参数个数错误");
|
|
688
714
|
}
|
|
689
715
|
|
|
690
716
|
const promiseList = selectorList.map((selector) => {
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CommonUtils } from "./CommonUtils";
|
|
2
2
|
import type { DOMUtilsCreateElementAttributesMap } from "./types/DOMUtilsEvent";
|
|
3
|
-
import { type
|
|
3
|
+
import { type DOMUtilsCSSProperty, type DOMUtilsCSSPropertyType } from "./types/DOMUtilsCSSProperty";
|
|
4
4
|
import type { WindowApiOption } from "./types/WindowApi";
|
|
5
5
|
import { version } from "../package.json";
|
|
6
6
|
import { ElementHandler } from "./ElementHandler";
|
|
7
|
+
import type { DOMUtilsTargetElementType } from "./types/global";
|
|
7
8
|
|
|
8
9
|
class DOMUtils extends ElementHandler {
|
|
9
10
|
constructor(option?: WindowApiOption) {
|
|
@@ -193,7 +194,7 @@ class DOMUtils extends ElementHandler {
|
|
|
193
194
|
* DOMUtils.css("a.xx","display");
|
|
194
195
|
* > "none"
|
|
195
196
|
* */
|
|
196
|
-
css($el: DOMUtilsTargetElementType, property:
|
|
197
|
+
css($el: DOMUtilsTargetElementType, property: DOMUtilsCSSPropertyType): string;
|
|
197
198
|
/**
|
|
198
199
|
* 获取元素的样式属性值
|
|
199
200
|
* @param $el 目标元素
|
|
@@ -221,11 +222,7 @@ class DOMUtils extends ElementHandler {
|
|
|
221
222
|
* DOMUtils.css(document.querySelector("a.xx"),"top","10px");
|
|
222
223
|
* DOMUtils.css(document.querySelector("a.xx"),"top",10);
|
|
223
224
|
* */
|
|
224
|
-
css(
|
|
225
|
-
$el: DOMUtilsTargetElementType,
|
|
226
|
-
property: (keyof Omit<CSSStyleDeclaration, "zIndex"> | "z-index") & string,
|
|
227
|
-
value: string | number
|
|
228
|
-
): string;
|
|
225
|
+
css($el: DOMUtilsTargetElementType, property: DOMUtilsCSSPropertyType & string, value: string | number): string;
|
|
229
226
|
/**
|
|
230
227
|
* 设置元素的样式属性
|
|
231
228
|
* @param $el 目标元素
|
|
@@ -243,24 +240,15 @@ class DOMUtils extends ElementHandler {
|
|
|
243
240
|
css(
|
|
244
241
|
$el: DOMUtilsTargetElementType,
|
|
245
242
|
property:
|
|
246
|
-
|
|
|
247
|
-
[P in keyof Omit<CSSStyleDeclaration, "zIndex">]?: CSSStyleDeclaration[P];
|
|
248
|
-
}
|
|
249
|
-
| {
|
|
250
|
-
"z-index": string | number;
|
|
251
|
-
}
|
|
243
|
+
| DOMUtilsCSSProperty
|
|
252
244
|
| {
|
|
253
245
|
[key: string]: string | number;
|
|
254
246
|
}
|
|
247
|
+
| string
|
|
255
248
|
): string;
|
|
256
249
|
css(
|
|
257
250
|
$el: DOMUtilsTargetElementType,
|
|
258
|
-
property:
|
|
259
|
-
| keyof Omit<CSSStyleDeclaration, "zIndex">
|
|
260
|
-
| string
|
|
261
|
-
| {
|
|
262
|
-
[P in keyof Omit<CSSStyleDeclaration, "zIndex">]?: string | number | CSSStyleDeclaration[P];
|
|
263
|
-
},
|
|
251
|
+
property: DOMUtilsCSSPropertyType | string | DOMUtilsCSSProperty,
|
|
264
252
|
value?: string | number
|
|
265
253
|
) {
|
|
266
254
|
const that = this;
|
|
@@ -298,7 +286,7 @@ class DOMUtils extends ElementHandler {
|
|
|
298
286
|
} else if (typeof property === "object") {
|
|
299
287
|
// 设置属性
|
|
300
288
|
$el.forEach(($elItem) => {
|
|
301
|
-
that.css($elItem as HTMLElement, property as
|
|
289
|
+
that.css($elItem as HTMLElement, property as DOMUtilsCSSProperty);
|
|
302
290
|
});
|
|
303
291
|
return;
|
|
304
292
|
}
|
|
@@ -324,7 +312,7 @@ class DOMUtils extends ElementHandler {
|
|
|
324
312
|
}
|
|
325
313
|
} else if (typeof property === "object") {
|
|
326
314
|
for (const prop in property) {
|
|
327
|
-
const value = property[prop];
|
|
315
|
+
const value = property[prop as keyof typeof property];
|
|
328
316
|
setStyleProperty(prop, value!);
|
|
329
317
|
}
|
|
330
318
|
} else {
|
|
@@ -1750,7 +1738,7 @@ class DOMUtils extends ElementHandler {
|
|
|
1750
1738
|
checkUserClickInNode($el: Element | Node | HTMLElement) {
|
|
1751
1739
|
const that = this;
|
|
1752
1740
|
if (!CommonUtils.isDOM($el)) {
|
|
1753
|
-
throw new Error("
|
|
1741
|
+
throw new Error("DOMUtils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
|
|
1754
1742
|
}
|
|
1755
1743
|
const clickEvent = that.windowApi.window.event as PointerEvent;
|
|
1756
1744
|
const touchEvent = that.windowApi.window.event as TouchEvent;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 属性转驼峰
|
|
3
|
+
*/
|
|
4
|
+
export type DOMUtilsCamelToKebabCSSProperty<S extends string> = S extends `webkit${infer U}`
|
|
5
|
+
? `-${Lowercase<"webkit">}${U extends `${infer First}${infer Rest}`
|
|
6
|
+
? First extends Uppercase<First>
|
|
7
|
+
? `-${Uncapitalize<First>}${DOMUtilsCamelToKebabCSSProperty<Rest>}`
|
|
8
|
+
: `${First}${DOMUtilsCamelToKebabCSSProperty<Rest>}`
|
|
9
|
+
: U}`
|
|
10
|
+
: S extends `${infer T}${infer U}`
|
|
11
|
+
? U extends Uncapitalize<U>
|
|
12
|
+
? `${Uncapitalize<T>}${DOMUtilsCamelToKebabCSSProperty<U>}`
|
|
13
|
+
: `${Uncapitalize<T>}-${DOMUtilsCamelToKebabCSSProperty<U>}`
|
|
14
|
+
: S;
|
|
15
|
+
|
|
16
|
+
export type DOMUtilsCSSPropertyType = DOMUtilsCamelToKebabCSSProperty<
|
|
17
|
+
Extract<
|
|
18
|
+
keyof Omit<
|
|
19
|
+
CSSStyleDeclaration,
|
|
20
|
+
| "cssFloat"
|
|
21
|
+
| "cssText"
|
|
22
|
+
| "length"
|
|
23
|
+
| "parentRule"
|
|
24
|
+
| "getPropertyPriority"
|
|
25
|
+
| "getPropertyValue"
|
|
26
|
+
| "item"
|
|
27
|
+
| "removeProperty"
|
|
28
|
+
| "setProperty"
|
|
29
|
+
>,
|
|
30
|
+
string
|
|
31
|
+
>
|
|
32
|
+
>;
|
|
33
|
+
|
|
34
|
+
export type DOMUtilsCSSProperty = {
|
|
35
|
+
[P in DOMUtilsCSSPropertyType]: string | number;
|
|
36
|
+
};
|