shadow-dom-selector 3.0.1 → 4.1.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.
- package/README.md +194 -15
- package/dist/esm/index.d.ts +16 -7
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +16 -7
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Having a DOM tree formed of Shadow DOM subtrees like the next one:
|
|
|
28
28
|
If one wants to query for the `li` elements, it is required to do this:
|
|
29
29
|
|
|
30
30
|
```javascript
|
|
31
|
-
const
|
|
31
|
+
const firstLi = document.querySelector('section').shadowRoot.querySelector('article').shadowRoot.querySelector('ul > li');
|
|
32
32
|
|
|
33
33
|
const allLis = document.querySelector('section').shadowRoot.querySelector('article').shadowRoot.querySelectorAll('ul > li');
|
|
34
34
|
|
|
@@ -40,11 +40,20 @@ const shadow = document.querySelector('section').shadowRoot.querySelector('artic
|
|
|
40
40
|
```javascript
|
|
41
41
|
// $ character at the end of a selector means to select its Shadom DOM
|
|
42
42
|
|
|
43
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
querySelector,
|
|
45
|
+
querySelectorAll,
|
|
46
|
+
shadowRootQuerySelector,
|
|
47
|
+
deepQuerySelector,
|
|
48
|
+
deepQuerySelectorAll
|
|
49
|
+
} from 'shadow-dom-selector';
|
|
44
50
|
|
|
45
|
-
const
|
|
46
|
-
const allLis querySelectorAll('section$ article$ ul > li');
|
|
51
|
+
const firstLi = querySelector('section$ article$ ul > li');
|
|
52
|
+
const allLis = querySelectorAll('section$ article$ ul > li');
|
|
47
53
|
const shadow = shadowRootQuerySelector('section$ article$');
|
|
54
|
+
|
|
55
|
+
const deepFirstLi = deepQuerySelector('li');
|
|
56
|
+
const deepAllLi = deepQuerySelectorAll('li');
|
|
48
57
|
```
|
|
49
58
|
|
|
50
59
|
It will traverse all the Shadow DOM subtrees removing all the hassle of writing long concatenated queries.
|
|
@@ -85,11 +94,19 @@ const elements = document.querySelector('article')?.shadowRoot?.querySelector('d
|
|
|
85
94
|
Which will return `undefined` if some element doesn‘t exist. With `shadow-dom-selector`, you just need to write the query and it will return the same that is returned by the native `querySelector` and `querySelectorAll` if the query cannot be satisfied.
|
|
86
95
|
|
|
87
96
|
```javascript
|
|
88
|
-
import {
|
|
97
|
+
import {
|
|
98
|
+
querySelector,
|
|
99
|
+
querySelectorAll,
|
|
100
|
+
shadowRootQuerySelector,
|
|
101
|
+
deepQuerySelector,
|
|
102
|
+
deepQuerySelectorAll
|
|
103
|
+
} from 'shadow-dom-selector';
|
|
89
104
|
|
|
90
105
|
const shadow = shadowRootQuerySelector('article$ div$'); // null
|
|
91
106
|
const element = querySelector('article$ div$ section > h1'); // null
|
|
92
107
|
const elements = querySelectorAll('article$ div$ p'); // empty NodeList
|
|
108
|
+
const deepElement = deepQuerySelector('span') // null;
|
|
109
|
+
const deepElements = deepQuerySelectorAll('p'); // empty NodeList
|
|
93
110
|
```
|
|
94
111
|
|
|
95
112
|
### Async queries
|
|
@@ -98,7 +115,13 @@ If the elements are not already rendered into the DOM in the moment that the que
|
|
|
98
115
|
|
|
99
116
|
```javascript
|
|
100
117
|
// Using the async methods
|
|
101
|
-
import {
|
|
118
|
+
import {
|
|
119
|
+
asyncQuerySelector,
|
|
120
|
+
asyncQuerySelectorAll,
|
|
121
|
+
asyncShadowRootQuerySelector,
|
|
122
|
+
asyncDeepQuerySelector,
|
|
123
|
+
asyncDeepQuerySelectorAll
|
|
124
|
+
} from 'shadow-dom-selector';
|
|
102
125
|
|
|
103
126
|
asyncShadowRootQuerySelector('article$ div$')
|
|
104
127
|
.then((shadowRoot) => {
|
|
@@ -118,7 +141,19 @@ asyncQuerySelectorAll('article$ div$ p')
|
|
|
118
141
|
// If they are not found after all the retries, it will return an empty NodeList
|
|
119
142
|
});
|
|
120
143
|
|
|
121
|
-
|
|
144
|
+
asyncDeepQuerySelector('h1')
|
|
145
|
+
.then((h1) => {
|
|
146
|
+
// Do stuff with the h1 element
|
|
147
|
+
// If it is not found after all the retries, it will return null
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
asyncDeepQuerySelectorAll('p')
|
|
151
|
+
.then((paragraphs) => {
|
|
152
|
+
// Do stuff with the paragraphs
|
|
153
|
+
// If they are not found after all the retries, it will return an empty NodeList
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Using de AsyncSelector class
|
|
122
157
|
import { AsyncSelector } from 'shadow-dom-selector';
|
|
123
158
|
|
|
124
159
|
const selector = new AsyncSelector();
|
|
@@ -140,6 +175,18 @@ selector.query('article').$.query('div').$.query('p').all
|
|
|
140
175
|
// Do stuff with the paragraphs
|
|
141
176
|
// If they are not found after all the retries, it will return an empty NodeList
|
|
142
177
|
});
|
|
178
|
+
|
|
179
|
+
selector.deepQuery('h1').element
|
|
180
|
+
.then((h1) => {
|
|
181
|
+
// Do stuff with the h1 element
|
|
182
|
+
// If it is not found after all the retries, it will return null
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
selector.deepQuery('p').all
|
|
186
|
+
.then((paragraphs) => {
|
|
187
|
+
// Do stuff with the paragraphs
|
|
188
|
+
// If they are not found after all the retries, it will return an empty NodeList
|
|
189
|
+
});
|
|
143
190
|
```
|
|
144
191
|
|
|
145
192
|
Either the async methods or the async dot notation allow you to to specify the amount of retries and the delay between each one of them. Consult the [API](#api) section for more details.
|
|
@@ -179,10 +226,14 @@ It is possible to include a compiled version of the package directly in an HTML
|
|
|
179
226
|
```javascript
|
|
180
227
|
/* There will be a global variable named ShadowDomSelector containing all the functions */
|
|
181
228
|
ShadowDomSelector.querySelector;
|
|
229
|
+
ShadowDomSelector.deepQuerySelector;
|
|
182
230
|
ShadowDomSelector.querySelectorAll;
|
|
231
|
+
ShadowDomSelector.deepQuerySelectorAll;
|
|
183
232
|
ShadowDomSelector.shadowRootQuerySelector;
|
|
184
233
|
ShadowDomSelector.asyncQuerySelector;
|
|
234
|
+
ShadowDomSelector.asyncDeepQuerySelector;
|
|
185
235
|
ShadowDomSelector.asyncQuerySelectorAll;
|
|
236
|
+
ShadowDomSelector.asyncDeepQuerySelectorAll;
|
|
186
237
|
ShadowDomSelector.asyncShadowRootQuerySelector;
|
|
187
238
|
ShadowDomSelector.AsyncSelector;
|
|
188
239
|
```
|
|
@@ -191,6 +242,8 @@ ShadowDomSelector.AsyncSelector;
|
|
|
191
242
|
|
|
192
243
|
#### querySelector
|
|
193
244
|
|
|
245
|
+
Performs a query selection passing through the `shadowRoot` of elements if you add `$` after them.
|
|
246
|
+
|
|
194
247
|
```typescript
|
|
195
248
|
querySelector(selectors): Element | null;
|
|
196
249
|
```
|
|
@@ -201,11 +254,32 @@ querySelector(root, selectors): Element | null;
|
|
|
201
254
|
|
|
202
255
|
| Parameter | Optional | Description |
|
|
203
256
|
| ------------ | ------------- | -------------------------------------------------- |
|
|
204
|
-
| `selectors` | no | A string containing one or more selectors to match. Selectors
|
|
257
|
+
| `selectors` | no | A string containing one or more selectors to match. Selectors may not end in a Shadow DOM (`$`) |
|
|
258
|
+
| `root` | yes | The element from where the query should be performed, it defaults to `document` |
|
|
259
|
+
|
|
260
|
+
#### deepQuerySelector
|
|
261
|
+
|
|
262
|
+
Performs a query selection of an element searching for it recursively in the whole DOM tree even if it needs to pass through the `shadowRoots` of elements.
|
|
263
|
+
|
|
264
|
+
>Note: use this method carefully, depending on the extension of your DOM tree, it could be an expensive task in terms of resources. Do this when you need to query for an element that could appear in any part of the DOM tree so you don‘t know its exact position, otherwise, the `querySelector` method is recommended.
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
deepQuerySelector(selectors): Element | null;
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
deepQuerySelector(root, selectors): Element | null;
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
| Parameter | Optional | Description |
|
|
275
|
+
| ------------ | ------------- | -------------------------------------------------- |
|
|
276
|
+
| `selectors` | no | A string containing one or more selectors to match. Selectors may not end in a Shadow DOM (`$`) |
|
|
205
277
|
| `root` | yes | The element from where the query should be performed, it defaults to `document` |
|
|
206
278
|
|
|
207
279
|
#### querySelectorAll
|
|
208
280
|
|
|
281
|
+
Performs a `querySelectionAll` query passing through the `shadowRoot` of elements if you add `$` after them.
|
|
282
|
+
|
|
209
283
|
```typescript
|
|
210
284
|
querySelectorAll(selectors): NodeListOf<Element>;
|
|
211
285
|
```
|
|
@@ -216,11 +290,32 @@ querySelectorAll(root, selectors): NodeListOf<Element>;
|
|
|
216
290
|
|
|
217
291
|
| Parameter | Optional | Description |
|
|
218
292
|
| ------------ | ------------- | -------------------------------------------------- |
|
|
219
|
-
| `selectors` | no | A string containing one or more selectors to match. Selectors
|
|
293
|
+
| `selectors` | no | A string containing one or more selectors to match. Selectors may not end in a Shadow DOM (`$`) |
|
|
294
|
+
| `root` | yes | The element from where the query should be performed, it defaults to `document` |
|
|
295
|
+
|
|
296
|
+
#### deepQuerySelectorAll
|
|
297
|
+
|
|
298
|
+
Performs a `querySelectionAll` query of elements searching for them recursively in the whole DOM tree even if it needs to pass through the `shadowRoots` of elements.
|
|
299
|
+
|
|
300
|
+
>Note: use this method carefully, depending on the extension of your DOM tree, it could be an expensive task in terms of resources. Do this when you need to query for elements that could appear in any part of the DOM tree so you don‘t know their exact position, otherwise, the `querySelectionAll` method is recommended.
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
deepQuerySelectorAll(selectors): NodeListOf<Element>;
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
deepQuerySelectorAll(root, selectors): NodeListOf<Element>;
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
| Parameter | Optional | Description |
|
|
311
|
+
| ------------ | ------------- | -------------------------------------------------- |
|
|
312
|
+
| `selectors` | no | A string containing one or more selectors to match. Selectors may not end in a Shadow DOM (`$`) |
|
|
220
313
|
| `root` | yes | The element from where the query should be performed, it defaults to `document` |
|
|
221
314
|
|
|
222
315
|
#### shadowRootQuerySelector
|
|
223
316
|
|
|
317
|
+
Performs a query selection of a `shadowRoot` passing through the `shadowRoot` of elements if you add `$` after them.
|
|
318
|
+
|
|
224
319
|
```typescript
|
|
225
320
|
shadowRootQuerySelector(selectors): ShadowRoot | null;
|
|
226
321
|
```
|
|
@@ -236,6 +331,8 @@ shadowRootQuerySelector(root, selectors): ShadowRoot | null;
|
|
|
236
331
|
|
|
237
332
|
#### asyncQuerySelector
|
|
238
333
|
|
|
334
|
+
Performs an asynchronous query selection passing through the `shadowRoot` of elements if you add `$` after them.
|
|
335
|
+
|
|
239
336
|
```typescript
|
|
240
337
|
asyncQuerySelector(selectors): Promise<Element | null>;
|
|
241
338
|
```
|
|
@@ -254,7 +351,43 @@ asyncQuerySelector(root, selectors, asyncParams): Promise<Element | null>;
|
|
|
254
351
|
|
|
255
352
|
| Parameter | Optional | Description |
|
|
256
353
|
| ------------- | ------------- | -------------------------------------------------- |
|
|
257
|
-
| `selectors` | no | A string containing one or more selectors to match. Selectors
|
|
354
|
+
| `selectors` | no | A string containing one or more selectors to match. Selectors may not end in a Shadow DOM (`$`) |
|
|
355
|
+
| `root` | yes | The element from where the query should be performed, it defaults to `document` |
|
|
356
|
+
| `asyncParams` | yes | An object containing the parameters which control the retries |
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
// asyncParams properties
|
|
360
|
+
{
|
|
361
|
+
retries?: number; // how many retries before giving up (defaults to 10)
|
|
362
|
+
delay?: number; // delay between each retry (defaults to 10)
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
#### asyncDeepQuerySelector
|
|
367
|
+
|
|
368
|
+
Performs an asynchronous query selection of an element searching for it recursively in the whole DOM tree even if it needs to pass through the `shadowRoots` of elements.
|
|
369
|
+
|
|
370
|
+
>Note: use this method carefully, depending on the extension of your DOM tree, it could be an expensive task in terms of resources. Do this when you need to query for an element that could appear in any part of the DOM tree so you don‘t know its exact position, otherwise, the `asyncQuerySelector` method is recommended.
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
asyncDeepQuerySelector(selectors): Promise<Element | null>;
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
asyncDeepQuerySelector(root, selectors): Promise<Element | null>;
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
asyncDeepQuerySelector(selectors, asyncParams): Promise<Element | null>;
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
asyncDeepQuerySelector(root, selectors, asyncParams): Promise<Element | null>;
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
| Parameter | Optional | Description |
|
|
389
|
+
| ------------- | ------------- | -------------------------------------------------- |
|
|
390
|
+
| `selectors` | no | A string containing one or more selectors to match. Selectors may not end in a Shadow DOM (`$`) |
|
|
258
391
|
| `root` | yes | The element from where the query should be performed, it defaults to `document` |
|
|
259
392
|
| `asyncParams` | yes | An object containing the parameters which control the retries |
|
|
260
393
|
|
|
@@ -268,6 +401,8 @@ asyncQuerySelector(root, selectors, asyncParams): Promise<Element | null>;
|
|
|
268
401
|
|
|
269
402
|
#### asyncQuerySelectorAll
|
|
270
403
|
|
|
404
|
+
Performs an asynchronous `querySelectionAll` query passing through the `shadowRoot` of elements if you add `$` after them.
|
|
405
|
+
|
|
271
406
|
```typescript
|
|
272
407
|
asyncQuerySelectorAll(selectors): Promise<NodeListOf<Element>>;
|
|
273
408
|
```
|
|
@@ -286,7 +421,43 @@ asyncQuerySelectorAll(root, selectors, asyncParams): Promise<NodeListOf<Element>
|
|
|
286
421
|
|
|
287
422
|
| Parameter | Optional | Description |
|
|
288
423
|
| ------------- | ------------- | -------------------------------------------------- |
|
|
289
|
-
| `selectors` | no | A string containing one or more selectors to match. Selectors
|
|
424
|
+
| `selectors` | no | A string containing one or more selectors to match. Selectors may not end in a Shadow DOM (`$`) |
|
|
425
|
+
| `root` | yes | The element from where the query should be performed, it defaults to `document` |
|
|
426
|
+
| `asyncParams` | yes | An object containing the parameters which control the retries |
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
// asyncParams properties
|
|
430
|
+
{
|
|
431
|
+
retries?: number; // how many retries before giving up (defaults to 10)
|
|
432
|
+
delay?: number; // delay between each retry (defaults to 10)
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
#### asyncDeepQuerySelectorAll
|
|
437
|
+
|
|
438
|
+
Performs an asynchronous `querySelectionAll` query of elements searching for them recursively in the whole DOM tree even if it needs to pass through the `shadowRoots` of elements.
|
|
439
|
+
|
|
440
|
+
>Note: use this method carefully, depending on the extension of your DOM tree, it could be an expensive task in terms of resources. Do this when you need to query for elements that could appear in any part of the DOM tree so you don‘t know their exact position, otherwise, the `asyncQuerySelectorAll` method is recommended.
|
|
441
|
+
|
|
442
|
+
```typescript
|
|
443
|
+
asyncDeepQuerySelectorAll(selectors): Promise<NodeListOf<Element>>;
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
```typescript
|
|
447
|
+
asyncDeepQuerySelectorAll(root, selectors): Promise<NodeListOf<Element>>;
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
asyncDeepQuerySelectorAll(selectors, asyncParams): Promise<NodeListOf<Element>>;
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
asyncDeepQuerySelectorAll(root, selectors, asyncParams): Promise<NodeListOf<Element>>;
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
| Parameter | Optional | Description |
|
|
459
|
+
| ------------- | ------------- | -------------------------------------------------- |
|
|
460
|
+
| `selectors` | no | A string containing one or more selectors to match. Selectors may not end in a Shadow DOM (`$`) |
|
|
290
461
|
| `root` | yes | The element from where the query should be performed, it defaults to `document` |
|
|
291
462
|
| `asyncParams` | yes | An object containing the parameters which control the retries |
|
|
292
463
|
|
|
@@ -300,6 +471,8 @@ asyncQuerySelectorAll(root, selectors, asyncParams): Promise<NodeListOf<Element>
|
|
|
300
471
|
|
|
301
472
|
#### asyncShadowRootQuerySelector
|
|
302
473
|
|
|
474
|
+
Performs an asynchronous query selection of a `shadowRoot` passing through the `shadowRoot` of elements if you add `$` after them.
|
|
475
|
+
|
|
303
476
|
```typescript
|
|
304
477
|
asyncShadowRootQuerySelector(selectors): Promise<ShadowRoot | null>;
|
|
305
478
|
```
|
|
@@ -332,6 +505,8 @@ asyncShadowRootQuerySelector(root, selectors, asyncParams): Promise<ShadowRoot |
|
|
|
332
505
|
|
|
333
506
|
#### AsyncSelector class
|
|
334
507
|
|
|
508
|
+
This class creates an instance of an element that could be used to perform asynchronous query selections in the DOM tree passing through the `shadowRoot` of elements.
|
|
509
|
+
|
|
335
510
|
```typescript
|
|
336
511
|
new AsyncSelector();
|
|
337
512
|
```
|
|
@@ -368,10 +543,12 @@ The instances of this class have the next properties:
|
|
|
368
543
|
|
|
369
544
|
And the next methods:
|
|
370
545
|
|
|
371
|
-
| Method
|
|
372
|
-
|
|
|
373
|
-
| `eq(index: number)`
|
|
374
|
-
| `query(selector: string)`
|
|
546
|
+
| Method | Return | Description |
|
|
547
|
+
| ----------------------------- | -------------------------- | ---------------------------------------------------------------- |
|
|
548
|
+
| `eq(index: number)` | `Promise<Element \| null>` | Returns a promise that resolves in the element in the index position of the queried elements (startig from `0`) |
|
|
549
|
+
| `query(selector: string)` | `AsyncSelector` | Performs a query and returns a new AsyncSelector instance |
|
|
550
|
+
| `deepQuery(selector: string)` | `AsyncSelector` | Performs a deep query (even through elements' shadowRoot) ans returns a new AsyncSelector instance |
|
|
551
|
+
|
|
375
552
|
|
|
376
553
|
##### Examples of the AsyncSelector class
|
|
377
554
|
|
|
@@ -392,6 +569,8 @@ await selector.query('section').$.element === document.querySelector('section').
|
|
|
392
569
|
await selector.query('section').$.all; // Empty Node list
|
|
393
570
|
await selector.query('section').$.query('article').all === document.querySelector('section').shadowRoot.querySelectorAll('article');
|
|
394
571
|
await selector.query('section').$.query('ul li').eq(1) === document.querySelector('section').shadowRoot.querySelectorAll('ul li')[1];
|
|
572
|
+
await selector.deepQuery('li.delayed-li').element; // try to query the element deep in the shadowDOM tree until the retries/delay expire
|
|
573
|
+
await selector.deepQuery('li.delayed-li').all; // try to perform a querySelectorAll deep in the shadowDOM tree until the retries/delay expire
|
|
395
574
|
selector.query('section').$.query('article').asyncParams; // { retries: 100, delay: 50 }
|
|
396
575
|
```
|
|
397
576
|
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,17 +3,25 @@ interface AsyncParams {
|
|
|
3
3
|
delay?: number;
|
|
4
4
|
}
|
|
5
5
|
declare const SHADOW_ROOT_SELECTOR = "$";
|
|
6
|
-
declare function querySelector<E extends Element = Element>(root: Document | Element, selectors: string): E | null;
|
|
6
|
+
declare function querySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
|
|
7
7
|
declare function querySelector<E extends Element = Element>(selectors: string): E | null;
|
|
8
|
-
declare function
|
|
8
|
+
declare function deepQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
|
|
9
|
+
declare function deepQuerySelector<E extends Element = Element>(selectors: string): E | null;
|
|
10
|
+
declare function querySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): NodeListOf<E>;
|
|
9
11
|
declare function querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
|
|
10
|
-
declare function
|
|
12
|
+
declare function deepQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): NodeListOf<E>;
|
|
13
|
+
declare function deepQuerySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
|
|
14
|
+
declare function shadowRootQuerySelector(root: Document | Element | ShadowRoot, selectors: string): ShadowRoot | null;
|
|
11
15
|
declare function shadowRootQuerySelector(selectors: string): ShadowRoot | null;
|
|
12
|
-
declare function asyncQuerySelector<E extends Element = Element>(root: Document | Element, selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
16
|
+
declare function asyncQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
13
17
|
declare function asyncQuerySelector<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
14
|
-
declare function
|
|
18
|
+
declare function asyncDeepQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
19
|
+
declare function asyncDeepQuerySelector<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
20
|
+
declare function asyncQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
|
|
15
21
|
declare function asyncQuerySelectorAll<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
|
|
16
|
-
declare function
|
|
22
|
+
declare function asyncDeepQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
|
|
23
|
+
declare function asyncDeepQuerySelectorAll<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
|
|
24
|
+
declare function asyncShadowRootQuerySelector(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<ShadowRoot | null>;
|
|
17
25
|
declare function asyncShadowRootQuerySelector(selectors: string, asyncParams?: AsyncParams): Promise<ShadowRoot | null>;
|
|
18
26
|
declare class AsyncSelector<T extends Document | Element | ShadowRoot> {
|
|
19
27
|
constructor(asyncParams?: AsyncParams);
|
|
@@ -26,6 +34,7 @@ declare class AsyncSelector<T extends Document | Element | ShadowRoot> {
|
|
|
26
34
|
get asyncParams(): AsyncParams;
|
|
27
35
|
eq(index: number): Promise<Element | null>;
|
|
28
36
|
query(selector: string): AsyncSelector<Element>;
|
|
37
|
+
deepQuery(selector: string): AsyncSelector<Element>;
|
|
29
38
|
}
|
|
30
|
-
export { querySelector, querySelectorAll, shadowRootQuerySelector, asyncQuerySelector, asyncQuerySelectorAll, asyncShadowRootQuerySelector, AsyncSelector };
|
|
39
|
+
export { querySelector, deepQuerySelector, querySelectorAll, deepQuerySelectorAll, shadowRootQuerySelector, asyncQuerySelector, asyncDeepQuerySelector, asyncQuerySelectorAll, asyncDeepQuerySelectorAll, asyncShadowRootQuerySelector, AsyncSelector };
|
|
31
40
|
export type { AsyncParams };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=function(){return e=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},e.apply(this,arguments)};function n(e,n,t,r){return new(t||(t=Promise))((function(o,u){function a(e){try{l(r.next(e))}catch(e){u(e)}}function c(e){try{l(r.throw(e))}catch(e){u(e)}}function l(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,c)}l((r=r.apply(e,n||[])).next())}))}function t(e,n){var t,r,o,u,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(c){return function(l){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;u&&(u=0,c[0]&&(a=0)),a;)try{if(t=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=n.call(e,a)}catch(e){c=[6,e],r=0}finally{t=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,l])}}}function r(e,n,t){if(t||2===arguments.length)for(var r,o=0,u=n.length;o<u;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}"function"==typeof SuppressedError&&SuppressedError;var o="$",u=":host",a="invalid selector",c=10,l=10,i=function(e){var n,t=e[0],r=e[1];return(n=t)&&(n instanceof Document||n instanceof Element)&&"string"==typeof r};function s(e,n){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var t=function(e){return e.split(o).map((function(e){return e.trim()}))}(e);return n(t)}))}function f(e,n,t,r,o){return void 0===o&&(o=!1),new Promise((function(u){var c=0,l=function(){var i=o?e.querySelectorAll(n):e.querySelector(n);o&&i.length||!o&&null!==i?u(i):++c<t?setTimeout(l,r):u(o?document.querySelectorAll(a):null)};l()}))}function h(e,n,t){return new Promise((function(r){var o=0,u=function(){var a=e.shadowRoot;a?r(a):++o<n?setTimeout(u,t):r(null)};u()}))}function d(e,n){var t=n?" If you want to select a shadowRoot, use ".concat(n," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(o,").").concat(t)}function y(e,n){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(o,"). If you don't want to select a shadowRoot, use ").concat(n," instead.")}function v(e){return e instanceof Promise?e:Promise.resolve(e)}function w(){return"You can not select a shadowRoot (".concat(o,") of the document.")}function p(e,n){for(var t,r,o=null,a=e.length,c=0;c<a;c++){if(0===c)if(e[c].length)o=n.querySelector(e[c]);else{if(n instanceof Document)throw new SyntaxError(w());o=(null===(t=n.shadowRoot)||void 0===t?void 0:t.querySelector(e[++c]))||null}else o=(null===(r=o.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(u," ").concat(e[c])))||null;if(null===o)return null}return o}function m(e,n){var t,o=r([],e,!0),a=o.pop();return o.length?(null===(t=p(o,n).shadowRoot)||void 0===t?void 0:t.querySelectorAll("".concat(u," ").concat(a)))||null:n.querySelectorAll(a)}function g(e,n){if(1===e.length&&!e[0].length){if(n instanceof Document)throw new SyntaxError(w());return n.shadowRoot}var t=p(e,n);return(null==t?void 0:t.shadowRoot)||null}function b(e,r,o,a){return n(this,void 0,void 0,(function(){var n,c,l,i,s,d;return t(this,(function(t){switch(t.label){case 0:n=null,c=e.length,l=0,t.label=1;case 1:if(!(l<c))return[3,15];if(0!==l)return[3,8];if(e[l].length)return[3,5];if(r instanceof Document)throw new SyntaxError(w());return r.shadowRoot?[4,f(r.shadowRoot,e[++l],o,a)]:[3,3];case 2:return i=t.sent(),[3,4];case 3:i=null,t.label=4;case 4:return n=i,[3,7];case 5:return[4,f(r,e[l],o,a)];case 6:n=t.sent(),t.label=7;case 7:return[3,13];case 8:return[4,h(n,o,a)];case 9:return(s=t.sent())?[4,f(s,"".concat(u," ").concat(e[l]),o,a)]:[3,11];case 10:return d=t.sent(),[3,12];case 11:d=null,t.label=12;case 12:n=d,t.label=13;case 13:if(null===n)return[2,null];t.label=14;case 14:return l++,[3,1];case 15:return[2,n]}}))}))}function S(e,o,a,c){return n(this,void 0,void 0,(function(){var n,l,i,s,d,y;return t(this,(function(t){switch(t.label){case 0:return n=r([],e,!0),l=n.pop(),n.length?[3,2]:[4,f(o,l,a,c,!0)];case 1:return[2,t.sent()];case 2:return[4,b(n,o,a,c)];case 3:return(i=t.sent())?[4,h(i,a,c)]:[3,5];case 4:return d=t.sent(),[3,6];case 5:d=null,t.label=6;case 6:return(s=d)?[4,f(s,"".concat(u," ").concat(l),a,c,!0)]:[3,8];case 7:return y=t.sent(),[3,9];case 8:y=null,t.label=9;case 9:return[2,y]}}))}))}function P(e,r,o,u){return n(this,void 0,void 0,(function(){var n,a;return t(this,(function(t){switch(t.label){case 0:if(1===e.length&&!e[0].length){if(r instanceof Document)throw new SyntaxError(w());return[2,h(r,o,u)]}return[4,b(e,r,o,u)];case 1:return(n=t.sent())?[4,h(n,o,u)]:[3,3];case 2:return a=t.sent(),[3,4];case 3:a=null,t.label=4;case 4:return[2,a]}}))}))}function _(e,n){for(var t=s(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(d("querySelector","shadowRootQuerySelector"));return e})),r=t.length,o=0;o<r;o++){var u=p(t[o],n);if(u)return u}return null}function R(e,n){for(var t=s(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(d("querySelectorAll"));return e})),r=t.length,o=0;o<r;o++){var u=m(t[o],n);if(null==u?void 0:u.length)return u}return document.querySelectorAll(a)}function q(e,n){for(var t=s(e,(function(e){if(e.pop().length)throw new SyntaxError(y("shadowRootQuerySelector","querySelector"));return e})),r=t.length,o=0;o<r;o++){var u=g(t[o],n);if(u)return u}return null}function x(e,r,o,u){return n(this,void 0,void 0,(function(){var n,a,c,l;return t(this,(function(t){switch(t.label){case 0:n=s(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(d("asyncQuerySelector","asyncShadowRootQuerySelector"));return e})),a=n.length,c=0,t.label=1;case 1:return c<a?[4,b(n[c],r,o,u)]:[3,4];case 2:if(l=t.sent())return[2,l];t.label=3;case 3:return c++,[3,1];case 4:return[2,null]}}))}))}function E(e,r,o,u){return n(this,void 0,void 0,(function(){var n,c,l,i;return t(this,(function(t){switch(t.label){case 0:n=s(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(d("asyncQuerySelectorAll"));return e})),c=n.length,l=0,t.label=1;case 1:return l<c?[4,S(n[l],r,o,u)]:[3,4];case 2:if(null==(i=t.sent())?void 0:i.length)return[2,i];t.label=3;case 3:return l++,[3,1];case 4:return[2,document.querySelectorAll(a)]}}))}))}function A(e,r,o,u){return n(this,void 0,void 0,(function(){var n,a,c,l;return t(this,(function(t){switch(t.label){case 0:n=s(e,(function(e){if(e.pop().length)throw new SyntaxError(y("asyncShadowRootQuerySelector","asyncQuerySelector"));return e})),a=n.length,c=0,t.label=1;case 1:return c<a?[4,P(n[c],r,o,u)]:[3,4];case 2:if(l=t.sent())return[2,l];t.label=3;case 3:return c++,[3,1];case 4:return[2,null]}}))}))}function N(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?_(t,document):_(r,t)}function L(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?R(t,document):R(r,t)}function O(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?q(t,document):q(r,t)}function Q(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return n(this,void 0,void 0,(function(){var n,r,o,u,a;return t(this,(function(t){switch(t.label){case 0:return i(e)?(n=e[0],r=e[1],o=e[2],[4,x(r,n,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:case 3:return[2,t.sent()];case 2:return u=e[0],a=e[1],[4,x(u,document,(null==a?void 0:a.retries)||c,(null==a?void 0:a.delay)||l)]}}))}))}function j(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return n(this,void 0,void 0,(function(){var n,r,o,u,a;return t(this,(function(t){switch(t.label){case 0:return i(e)?(n=e[0],r=e[1],o=e[2],[4,E(r,n,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:return[2,t.sent()];case 2:return u=e[0],a=e[1],[2,E(u,document,(null==a?void 0:a.retries)||c,(null==a?void 0:a.delay)||l)]}}))}))}function D(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return n(this,void 0,void 0,(function(){var n,r,o,u,a;return t(this,(function(t){switch(t.label){case 0:return i(e)?(n=e[0],r=e[1],o=e[2],[4,A(r,n,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:return[2,t.sent()];case 2:return u=e[0],a=e[1],[2,A(u,document,(null==a?void 0:a.retries)||c,(null==a?void 0:a.delay)||l)]}}))}))}var k=function(){function r(n,t){n instanceof Node||n instanceof Promise?(this._element=n,this._asyncParams=e({retries:c,delay:l},t||{})):(this._element=document,this._asyncParams=e({retries:c,delay:l},n||{}))}return Object.defineProperty(r.prototype,"element",{get:function(){return v(this._element).then((function(e){return e instanceof NodeList?e[0]||null:e}))},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,o,{get:function(){var e=this;return new r(v(this._element).then((function(n){return n instanceof Document||n instanceof ShadowRoot||null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?h(n[0],e._asyncParams.retries,e._asyncParams.delay):h(n,e._asyncParams.retries,e._asyncParams.delay)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"all",{get:function(){return v(this._element).then((function(e){return e instanceof NodeList?e:document.querySelectorAll(a)}))},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),r.prototype.eq=function(e){return n(this,void 0,void 0,(function(){return t(this,(function(n){return[2,v(this._element).then((function(n){return n instanceof NodeList&&n[e]||null}))]}))}))},r.prototype.query=function(e){var n=this;return new r(v(this._element).then((function(t){return null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?f(t[0],e,n._asyncParams.retries,n._asyncParams.delay,!0):f(t,e,n._asyncParams.retries,n._asyncParams.delay,!0)})),this._asyncParams)},r}();export{k as AsyncSelector,Q as asyncQuerySelector,j as asyncQuerySelectorAll,D as asyncShadowRootQuerySelector,N as querySelector,L as querySelectorAll,O as shadowRootQuerySelector};
|
|
1
|
+
var n=function(){return n=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n},n.apply(this,arguments)};function t(n,t,e,r){return new(e||(e=Promise))((function(o,u){function i(n){try{c(r.next(n))}catch(n){u(n)}}function a(n){try{c(r.throw(n))}catch(n){u(n)}}function c(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(i,a)}c((r=r.apply(n,t||[])).next())}))}function e(n,t){var e,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(i=0)),i;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(n,i)}catch(n){a=[6,n],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}"function"==typeof SuppressedError&&SuppressedError;var r="$",o=":host",u="invalid selector",i=10,a=10,c=function(n){var t,e=n[0],r=n[1];return(t=e)&&(t instanceof Document||t instanceof Element||t instanceof ShadowRoot)&&"string"==typeof r};function l(n,t){return function(n){return n.split(",").map((function(n){return n.trim()}))}(n).map((function(n){var e=function(n){return n.split(r).map((function(n){return n.trim()}))}(n);return t(e)}))}var s=function(n,t,e,r){return new Promise((function(o){var u=0,i=function(){var a=n();t(a)?o(a):++u<e?setTimeout(i,r):o(a)};i()}))};function f(n,t){var e=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(n," cannot be used with a selector ending in a shadowRoot (").concat(r,").").concat(e)}function d(n){return n instanceof Promise?n:Promise.resolve(n)}function h(){return"You can not select a shadowRoot (".concat(r,") of the document.")}function v(){return"You can not select a shadowRoot (".concat(r,") of a shadowRoot.")}function y(n,t){for(var e,r,u=null,i=n.length,a=0;a<i;a++){if(0===a)if(n[a].length)u=t.querySelector(n[a]);else{if(t instanceof Document)throw new SyntaxError(h());if(t instanceof ShadowRoot)throw new SyntaxError(v());u=(null===(e=t.shadowRoot)||void 0===e?void 0:e.querySelector(n[++a]))||null}else u=(null===(r=u.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(o," ").concat(n[a])))||null;if(null===u)return null}return u}function m(n,t){var e,r=function(n,t,e){if(e||2===arguments.length)for(var r,o=0,u=t.length;o<u;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return n.concat(r||Array.prototype.slice.call(t))}([],n,!0),u=r.pop();if(!r.length)return t.querySelectorAll(u);var i=y(r,t);return(null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelectorAll("".concat(o," ").concat(u)))||null}function p(n,t){if(1===n.length&&!n[0].length){if(t instanceof Document)throw new SyntaxError(h());if(t instanceof ShadowRoot)throw new SyntaxError(v());return t.shadowRoot}var e=y(n,t);return(null==e?void 0:e.shadowRoot)||null}function w(n,t,e,r){void 0===e&&(e="querySelector"),void 0===r&&(r="shadowRootQuerySelector");for(var o=l(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(f(e,r));return n})),u=o.length,i=0;i<u;i++){var a=y(o[i],t);if(a)return a}return null}function g(n,t,e){void 0===e&&(e="querySelectorAll");for(var r=l(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(f(e));return n})),o=r.length,i=0;i<o;i++){var a=m(r[i],t);if(null==a?void 0:a.length)return a}return document.querySelectorAll(u)}function S(n,t,e,o){void 0===e&&(e="shadowRootQuerySelector"),void 0===o&&(o="querySelector");for(var u=l(n,(function(n){if(n.pop().length)throw new SyntaxError(function(n,t){return"".concat(n," must be used with a selector ending in a shadowRoot (").concat(r,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}(e,o));return n})),i=u.length,a=0;a<i;a++){var c=p(u[a],t);if(c)return c}return null}function b(n,r,o,u){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,s((function(){return w(n,r,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(n){return!!n}),o,u)]}))}))}function P(n,r,o,u){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,s((function(){return g(n,r,"asyncQuerySelectorAll")}),(function(n){return!!n.length}),o,u)]}))}))}function R(n,r,o,u){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,s((function(){return S(n,r,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(n){return!!n}),o,u)]}))}))}var _=function(n,t){var e=n.querySelectorAll(t);if(e.length)return e;if(n instanceof Element&&n.shadowRoot){var r=_(n.shadowRoot,t);if(r.length)return r}for(var o=0,i=Array.from(n.querySelectorAll("*"));o<i.length;o++){var a=i[o],c=_(a,t);if(c.length)return c}return document.querySelectorAll(u)},q=function(n,t,e,r){return s((function(){return _(n,t)}),(function(n){return!!n.length}),e,r)};function x(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?w(e,document):w(r,e)}function A(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?_(document,e)[0]||null:_(e,r)[0]||null}function E(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?g(e,document):g(r,e)}function N(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?_(document,e):_(e,r)}function L(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?S(e,document):S(r,e)}function Q(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t(this,void 0,void 0,(function(){var t,r,o,u,l;return e(this,(function(e){switch(e.label){case 0:return c(n)?(t=n[0],r=n[1],o=n[2],[4,b(r,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)]):[3,2];case 1:case 3:return[2,e.sent()];case 2:return u=n[0],l=n[1],[4,b(u,document,(null==l?void 0:l.retries)||i,(null==l?void 0:l.delay)||a)]}}))}))}function O(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t(this,void 0,void 0,(function(){var t,r,o,u,l;return e(this,(function(e){switch(e.label){case 0:return c(n)?(t=n[0],r=n[1],o=n[2],[4,q(t,r,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)]):[3,2];case 1:case 3:return[2,e.sent()[0]||null];case 2:return u=n[0],l=n[1],[4,q(document,u,(null==l?void 0:l.retries)||i,(null==l?void 0:l.delay)||a)]}}))}))}function j(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t(this,void 0,void 0,(function(){var t,r,o,u,l;return e(this,(function(e){switch(e.label){case 0:return c(n)?(t=n[0],r=n[1],o=n[2],[4,P(r,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)]):[3,2];case 1:return[2,e.sent()];case 2:return u=n[0],l=n[1],[2,P(u,document,(null==l?void 0:l.retries)||i,(null==l?void 0:l.delay)||a)]}}))}))}function k(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];if(c(n)){var e=n[0],r=n[1],o=n[2];return q(e,r,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)}var u=n[0],l=n[1];return q(document,u,(null==l?void 0:l.retries)||i,(null==l?void 0:l.delay)||a)}function D(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t(this,void 0,void 0,(function(){var t,r,o,u,l;return e(this,(function(e){switch(e.label){case 0:return c(n)?(t=n[0],r=n[1],o=n[2],[4,R(r,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)]):[3,2];case 1:return[2,e.sent()];case 2:return u=n[0],l=n[1],[2,R(u,document,(null==l?void 0:l.retries)||i,(null==l?void 0:l.delay)||a)]}}))}))}var I=function(){function o(t,e){t instanceof Node||t instanceof Promise?(this._element=t,this._asyncParams=n({retries:i,delay:a},e||{})):(this._element=document,this._asyncParams=n({retries:i,delay:a},t||{}))}return Object.defineProperty(o.prototype,"element",{get:function(){return d(this._element).then((function(n){return n instanceof NodeList?n[0]||null:n}))},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,r,{get:function(){var n=this;return new o(d(this._element).then((function(t){return t instanceof Document||t instanceof ShadowRoot||null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?D(t[0],r,n._asyncParams):D(t,r,n._asyncParams)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"all",{get:function(){return d(this._element).then((function(n){return n instanceof NodeList?n:document.querySelectorAll(u)}))},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),o.prototype.eq=function(n){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,d(this._element).then((function(t){return t instanceof NodeList&&t[n]||null}))]}))}))},o.prototype.query=function(n){var t=this;return new o(d(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?j(e[0],n,t._asyncParams):j(e,n,t._asyncParams)})),this._asyncParams)},o.prototype.deepQuery=function(n){var t=this;return new o(d(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?Promise.race(Array.from(e).map((function(e){return q(e,n,t._asyncParams.retries,t._asyncParams.delay)}))):q(e,n,t._asyncParams.retries,t._asyncParams.delay)})),this._asyncParams)},o}();export{I as AsyncSelector,O as asyncDeepQuerySelector,k as asyncDeepQuerySelectorAll,Q as asyncQuerySelector,j as asyncQuerySelectorAll,D as asyncShadowRootQuerySelector,A as deepQuerySelector,N as deepQuerySelectorAll,x as querySelector,E as querySelectorAll,L as shadowRootQuerySelector};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,17 +3,25 @@ interface AsyncParams {
|
|
|
3
3
|
delay?: number;
|
|
4
4
|
}
|
|
5
5
|
declare const SHADOW_ROOT_SELECTOR = "$";
|
|
6
|
-
declare function querySelector<E extends Element = Element>(root: Document | Element, selectors: string): E | null;
|
|
6
|
+
declare function querySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
|
|
7
7
|
declare function querySelector<E extends Element = Element>(selectors: string): E | null;
|
|
8
|
-
declare function
|
|
8
|
+
declare function deepQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
|
|
9
|
+
declare function deepQuerySelector<E extends Element = Element>(selectors: string): E | null;
|
|
10
|
+
declare function querySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): NodeListOf<E>;
|
|
9
11
|
declare function querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
|
|
10
|
-
declare function
|
|
12
|
+
declare function deepQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): NodeListOf<E>;
|
|
13
|
+
declare function deepQuerySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
|
|
14
|
+
declare function shadowRootQuerySelector(root: Document | Element | ShadowRoot, selectors: string): ShadowRoot | null;
|
|
11
15
|
declare function shadowRootQuerySelector(selectors: string): ShadowRoot | null;
|
|
12
|
-
declare function asyncQuerySelector<E extends Element = Element>(root: Document | Element, selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
16
|
+
declare function asyncQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
13
17
|
declare function asyncQuerySelector<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
14
|
-
declare function
|
|
18
|
+
declare function asyncDeepQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
19
|
+
declare function asyncDeepQuerySelector<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
|
|
20
|
+
declare function asyncQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
|
|
15
21
|
declare function asyncQuerySelectorAll<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
|
|
16
|
-
declare function
|
|
22
|
+
declare function asyncDeepQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
|
|
23
|
+
declare function asyncDeepQuerySelectorAll<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
|
|
24
|
+
declare function asyncShadowRootQuerySelector(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<ShadowRoot | null>;
|
|
17
25
|
declare function asyncShadowRootQuerySelector(selectors: string, asyncParams?: AsyncParams): Promise<ShadowRoot | null>;
|
|
18
26
|
declare class AsyncSelector<T extends Document | Element | ShadowRoot> {
|
|
19
27
|
constructor(asyncParams?: AsyncParams);
|
|
@@ -26,6 +34,7 @@ declare class AsyncSelector<T extends Document | Element | ShadowRoot> {
|
|
|
26
34
|
get asyncParams(): AsyncParams;
|
|
27
35
|
eq(index: number): Promise<Element | null>;
|
|
28
36
|
query(selector: string): AsyncSelector<Element>;
|
|
37
|
+
deepQuery(selector: string): AsyncSelector<Element>;
|
|
29
38
|
}
|
|
30
|
-
export { querySelector, querySelectorAll, shadowRootQuerySelector, asyncQuerySelector, asyncQuerySelectorAll, asyncShadowRootQuerySelector, AsyncSelector };
|
|
39
|
+
export { querySelector, deepQuerySelector, querySelectorAll, deepQuerySelectorAll, shadowRootQuerySelector, asyncQuerySelector, asyncDeepQuerySelector, asyncQuerySelectorAll, asyncDeepQuerySelectorAll, asyncShadowRootQuerySelector, AsyncSelector };
|
|
31
40
|
export type { AsyncParams };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ShadowDomSelector={})}(this,(function(e){"use strict";var n=function(){return n=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},n.apply(this,arguments)};function t(e,n,t,r){return new(t||(t=Promise))((function(o,u){function c(e){try{l(r.next(e))}catch(e){u(e)}}function a(e){try{l(r.throw(e))}catch(e){u(e)}}function l(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(c,a)}l((r=r.apply(e,n||[])).next())}))}function r(e,n){var t,r,o,u,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(a){return function(l){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(c=0)),c;)try{if(t=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return c.label++,{value:a[1],done:!1};case 5:c.label++,r=a[1],a=[0];continue;case 7:a=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){c=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){c.label=a[1];break}if(6===a[0]&&c.label<o[1]){c.label=o[1],o=a;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(a);break}o[2]&&c.ops.pop(),c.trys.pop();continue}a=n.call(e,c)}catch(e){a=[6,e],r=0}finally{t=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}function o(e,n,t){if(t||2===arguments.length)for(var r,o=0,u=n.length;o<u;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}"function"==typeof SuppressedError&&SuppressedError;var u="$",c=":host",a="invalid selector",l=10,i=10,s=function(e){var n,t=e[0],r=e[1];return(n=t)&&(n instanceof Document||n instanceof Element)&&"string"==typeof r};function f(e,n){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var t=function(e){return e.split(u).map((function(e){return e.trim()}))}(e);return n(t)}))}function h(e,n,t,r,o){return void 0===o&&(o=!1),new Promise((function(u){var c=0,l=function(){var i=o?e.querySelectorAll(n):e.querySelector(n);o&&i.length||!o&&null!==i?u(i):++c<t?setTimeout(l,r):u(o?document.querySelectorAll(a):null)};l()}))}function d(e,n,t){return new Promise((function(r){var o=0,u=function(){var c=e.shadowRoot;c?r(c):++o<n?setTimeout(u,t):r(null)};u()}))}function y(e,n){var t=n?" If you want to select a shadowRoot, use ".concat(n," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(u,").").concat(t)}function v(e,n){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(u,"). If you don't want to select a shadowRoot, use ").concat(n," instead.")}function p(e){return e instanceof Promise?e:Promise.resolve(e)}function w(){return"You can not select a shadowRoot (".concat(u,") of the document.")}function m(e,n){for(var t,r,o=null,u=e.length,a=0;a<u;a++){if(0===a)if(e[a].length)o=n.querySelector(e[a]);else{if(n instanceof Document)throw new SyntaxError(w());o=(null===(t=n.shadowRoot)||void 0===t?void 0:t.querySelector(e[++a]))||null}else o=(null===(r=o.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(c," ").concat(e[a])))||null;if(null===o)return null}return o}function g(e,n){var t,r=o([],e,!0),u=r.pop();return r.length?(null===(t=m(r,n).shadowRoot)||void 0===t?void 0:t.querySelectorAll("".concat(c," ").concat(u)))||null:n.querySelectorAll(u)}function b(e,n){if(1===e.length&&!e[0].length){if(n instanceof Document)throw new SyntaxError(w());return n.shadowRoot}var t=m(e,n);return(null==t?void 0:t.shadowRoot)||null}function S(e,n,o,u){return t(this,void 0,void 0,(function(){var t,a,l,i,s,f;return r(this,(function(r){switch(r.label){case 0:t=null,a=e.length,l=0,r.label=1;case 1:if(!(l<a))return[3,15];if(0!==l)return[3,8];if(e[l].length)return[3,5];if(n instanceof Document)throw new SyntaxError(w());return n.shadowRoot?[4,h(n.shadowRoot,e[++l],o,u)]:[3,3];case 2:return i=r.sent(),[3,4];case 3:i=null,r.label=4;case 4:return t=i,[3,7];case 5:return[4,h(n,e[l],o,u)];case 6:t=r.sent(),r.label=7;case 7:return[3,13];case 8:return[4,d(t,o,u)];case 9:return(s=r.sent())?[4,h(s,"".concat(c," ").concat(e[l]),o,u)]:[3,11];case 10:return f=r.sent(),[3,12];case 11:f=null,r.label=12;case 12:t=f,r.label=13;case 13:if(null===t)return[2,null];r.label=14;case 14:return l++,[3,1];case 15:return[2,t]}}))}))}function P(e,n,u,a){return t(this,void 0,void 0,(function(){var t,l,i,s,f,y;return r(this,(function(r){switch(r.label){case 0:return t=o([],e,!0),l=t.pop(),t.length?[3,2]:[4,h(n,l,u,a,!0)];case 1:return[2,r.sent()];case 2:return[4,S(t,n,u,a)];case 3:return(i=r.sent())?[4,d(i,u,a)]:[3,5];case 4:return f=r.sent(),[3,6];case 5:f=null,r.label=6;case 6:return(s=f)?[4,h(s,"".concat(c," ").concat(l),u,a,!0)]:[3,8];case 7:return y=r.sent(),[3,9];case 8:y=null,r.label=9;case 9:return[2,y]}}))}))}function R(e,n,o,u){return t(this,void 0,void 0,(function(){var t,c;return r(this,(function(r){switch(r.label){case 0:if(1===e.length&&!e[0].length){if(n instanceof Document)throw new SyntaxError(w());return[2,d(n,o,u)]}return[4,S(e,n,o,u)];case 1:return(t=r.sent())?[4,d(t,o,u)]:[3,3];case 2:return c=r.sent(),[3,4];case 3:c=null,r.label=4;case 4:return[2,c]}}))}))}function _(e,n){for(var t=f(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(y("querySelector","shadowRootQuerySelector"));return e})),r=t.length,o=0;o<r;o++){var u=m(t[o],n);if(u)return u}return null}function q(e,n){for(var t=f(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(y("querySelectorAll"));return e})),r=t.length,o=0;o<r;o++){var u=g(t[o],n);if(null==u?void 0:u.length)return u}return document.querySelectorAll(a)}function x(e,n){for(var t=f(e,(function(e){if(e.pop().length)throw new SyntaxError(v("shadowRootQuerySelector","querySelector"));return e})),r=t.length,o=0;o<r;o++){var u=b(t[o],n);if(u)return u}return null}function A(e,n,o,u){return t(this,void 0,void 0,(function(){var t,c,a,l;return r(this,(function(r){switch(r.label){case 0:t=f(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(y("asyncQuerySelector","asyncShadowRootQuerySelector"));return e})),c=t.length,a=0,r.label=1;case 1:return a<c?[4,S(t[a],n,o,u)]:[3,4];case 2:if(l=r.sent())return[2,l];r.label=3;case 3:return a++,[3,1];case 4:return[2,null]}}))}))}function E(e,n,o,u){return t(this,void 0,void 0,(function(){var t,c,l,i;return r(this,(function(r){switch(r.label){case 0:t=f(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(y("asyncQuerySelectorAll"));return e})),c=t.length,l=0,r.label=1;case 1:return l<c?[4,P(t[l],n,o,u)]:[3,4];case 2:if(null==(i=r.sent())?void 0:i.length)return[2,i];r.label=3;case 3:return l++,[3,1];case 4:return[2,document.querySelectorAll(a)]}}))}))}function Q(e,n,o,u){return t(this,void 0,void 0,(function(){var t,c,a,l;return r(this,(function(r){switch(r.label){case 0:t=f(e,(function(e){if(e.pop().length)throw new SyntaxError(v("asyncShadowRootQuerySelector","asyncQuerySelector"));return e})),c=t.length,a=0,r.label=1;case 1:return a<c?[4,R(t[a],n,o,u)]:[3,4];case 2:if(l=r.sent())return[2,l];r.label=3;case 3:return a++,[3,1];case 4:return[2,null]}}))}))}var N=function(){function e(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=n({retries:l,delay:i},t||{})):(this._element=document,this._asyncParams=n({retries:l,delay:i},e||{}))}return Object.defineProperty(e.prototype,"element",{get:function(){return p(this._element).then((function(e){return e instanceof NodeList?e[0]||null:e}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,u,{get:function(){var n=this;return new e(p(this._element).then((function(e){return e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?d(e[0],n._asyncParams.retries,n._asyncParams.delay):d(e,n._asyncParams.retries,n._asyncParams.delay)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"all",{get:function(){return p(this._element).then((function(e){return e instanceof NodeList?e:document.querySelectorAll(a)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),e.prototype.eq=function(e){return t(this,void 0,void 0,(function(){return r(this,(function(n){return[2,p(this._element).then((function(n){return n instanceof NodeList&&n[e]||null}))]}))}))},e.prototype.query=function(n){var t=this;return new e(p(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?h(e[0],n,t._asyncParams.retries,t._asyncParams.delay,!0):h(e,n,t._asyncParams.retries,t._asyncParams.delay,!0)})),this._asyncParams)},e}();e.AsyncSelector=N,e.asyncQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,c;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,A(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||i)]):[3,2];case 1:case 3:return[2,r.sent()];case 2:return u=e[0],c=e[1],[4,A(u,document,(null==c?void 0:c.retries)||l,(null==c?void 0:c.delay)||i)]}}))}))},e.asyncQuerySelectorAll=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,c;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,E(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||i)]):[3,2];case 1:return[2,r.sent()];case 2:return u=e[0],c=e[1],[2,E(u,document,(null==c?void 0:c.retries)||l,(null==c?void 0:c.delay)||i)]}}))}))},e.asyncShadowRootQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,c;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,Q(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||i)]):[3,2];case 1:return[2,r.sent()];case 2:return u=e[0],c=e[1],[2,Q(u,document,(null==c?void 0:c.retries)||l,(null==c?void 0:c.delay)||i)]}}))}))},e.querySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?_(t,document):_(r,t)},e.querySelectorAll=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?q(t,document):q(r,t)},e.shadowRootQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?x(t,document):x(r,t)}}));
|
|
1
|
+
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).ShadowDomSelector={})}(this,(function(n){"use strict";var e=function(){return e=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},e.apply(this,arguments)};function t(n,e,t,r){return new(t||(t=Promise))((function(o,u){function i(n){try{l(r.next(n))}catch(n){u(n)}}function c(n){try{l(r.throw(n))}catch(n){u(n)}}function l(n){var e;n.done?o(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(i,c)}l((r=r.apply(n,e||[])).next())}))}function r(n,e){var t,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(c){return function(l){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;u&&(u=0,c[0]&&(i=0)),i;)try{if(t=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(n,i)}catch(n){c=[6,n],r=0}finally{t=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,l])}}}"function"==typeof SuppressedError&&SuppressedError;var o="$",u=":host",i="invalid selector",c=10,l=10,a=function(n){var e,t=n[0],r=n[1];return(e=t)&&(e instanceof Document||e instanceof Element||e instanceof ShadowRoot)&&"string"==typeof r};function s(n,e){return function(n){return n.split(",").map((function(n){return n.trim()}))}(n).map((function(n){var t=function(n){return n.split(o).map((function(n){return n.trim()}))}(n);return e(t)}))}var f=function(n,e,t,r){return new Promise((function(o){var u=0,i=function(){var c=n();e(c)?o(c):++u<t?setTimeout(i,r):o(c)};i()}))};function d(n,e){var t=e?" If you want to select a shadowRoot, use ".concat(e," instead."):"";return"".concat(n," cannot be used with a selector ending in a shadowRoot (").concat(o,").").concat(t)}function h(n){return n instanceof Promise?n:Promise.resolve(n)}function y(){return"You can not select a shadowRoot (".concat(o,") of the document.")}function v(){return"You can not select a shadowRoot (".concat(o,") of a shadowRoot.")}function p(n,e){for(var t,r,o=null,i=n.length,c=0;c<i;c++){if(0===c)if(n[c].length)o=e.querySelector(n[c]);else{if(e instanceof Document)throw new SyntaxError(y());if(e instanceof ShadowRoot)throw new SyntaxError(v());o=(null===(t=e.shadowRoot)||void 0===t?void 0:t.querySelector(n[++c]))||null}else o=(null===(r=o.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(u," ").concat(n[c])))||null;if(null===o)return null}return o}function m(n,e){var t,r=function(n,e,t){if(t||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return n.concat(r||Array.prototype.slice.call(e))}([],n,!0),o=r.pop();if(!r.length)return e.querySelectorAll(o);var i=p(r,e);return(null===(t=null==i?void 0:i.shadowRoot)||void 0===t?void 0:t.querySelectorAll("".concat(u," ").concat(o)))||null}function w(n,e){if(1===n.length&&!n[0].length){if(e instanceof Document)throw new SyntaxError(y());if(e instanceof ShadowRoot)throw new SyntaxError(v());return e.shadowRoot}var t=p(n,e);return(null==t?void 0:t.shadowRoot)||null}function g(n,e,t,r){void 0===t&&(t="querySelector"),void 0===r&&(r="shadowRootQuerySelector");for(var o=s(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(d(t,r));return n})),u=o.length,i=0;i<u;i++){var c=p(o[i],e);if(c)return c}return null}function S(n,e,t){void 0===t&&(t="querySelectorAll");for(var r=s(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(d(t));return n})),o=r.length,u=0;u<o;u++){var c=m(r[u],e);if(null==c?void 0:c.length)return c}return document.querySelectorAll(i)}function b(n,e,t,r){void 0===t&&(t="shadowRootQuerySelector"),void 0===r&&(r="querySelector");for(var u=s(n,(function(n){if(n.pop().length)throw new SyntaxError(function(n,e){return"".concat(n," must be used with a selector ending in a shadowRoot (").concat(o,"). If you don't want to select a shadowRoot, use ").concat(e," instead.")}(t,r));return n})),i=u.length,c=0;c<i;c++){var l=w(u[c],e);if(l)return l}return null}function P(n,e,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,f((function(){return g(n,e,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(n){return!!n}),o,u)]}))}))}function R(n,e,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,f((function(){return S(n,e,"asyncQuerySelectorAll")}),(function(n){return!!n.length}),o,u)]}))}))}function _(n,e,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,f((function(){return b(n,e,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(n){return!!n}),o,u)]}))}))}var A=function(n,e){var t=n.querySelectorAll(e);if(t.length)return t;if(n instanceof Element&&n.shadowRoot){var r=A(n.shadowRoot,e);if(r.length)return r}for(var o=0,u=Array.from(n.querySelectorAll("*"));o<u.length;o++){var c=u[o],l=A(c,e);if(l.length)return l}return document.querySelectorAll(i)},q=function(n,e,t,r){return f((function(){return A(n,e)}),(function(n){return!!n.length}),t,r)};function Q(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(this,void 0,void 0,(function(){var e,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return a(n)?(e=n[0],t=n[1],o=n[2],[4,R(t,e,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:return[2,r.sent()];case 2:return u=n[0],i=n[1],[2,R(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))}function x(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(this,void 0,void 0,(function(){var e,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return a(n)?(e=n[0],t=n[1],o=n[2],[4,_(t,e,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:return[2,r.sent()];case 2:return u=n[0],i=n[1],[2,_(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))}var E=function(){function n(n,t){n instanceof Node||n instanceof Promise?(this._element=n,this._asyncParams=e({retries:c,delay:l},t||{})):(this._element=document,this._asyncParams=e({retries:c,delay:l},n||{}))}return Object.defineProperty(n.prototype,"element",{get:function(){return h(this._element).then((function(n){return n instanceof NodeList?n[0]||null:n}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,o,{get:function(){var e=this;return new n(h(this._element).then((function(n){return n instanceof Document||n instanceof ShadowRoot||null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?x(n[0],o,e._asyncParams):x(n,o,e._asyncParams)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"all",{get:function(){return h(this._element).then((function(n){return n instanceof NodeList?n:document.querySelectorAll(i)}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),n.prototype.eq=function(n){return t(this,void 0,void 0,(function(){return r(this,(function(e){return[2,h(this._element).then((function(e){return e instanceof NodeList&&e[n]||null}))]}))}))},n.prototype.query=function(e){var t=this;return new n(h(this._element).then((function(n){return null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?Q(n[0],e,t._asyncParams):Q(n,e,t._asyncParams)})),this._asyncParams)},n.prototype.deepQuery=function(e){var t=this;return new n(h(this._element).then((function(n){return null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?Promise.race(Array.from(n).map((function(n){return q(n,e,t._asyncParams.retries,t._asyncParams.delay)}))):q(n,e,t._asyncParams.retries,t._asyncParams.delay)})),this._asyncParams)},n}();n.AsyncSelector=E,n.asyncDeepQuerySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(this,void 0,void 0,(function(){var e,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return a(n)?(e=n[0],t=n[1],o=n[2],[4,q(e,t,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:case 3:return[2,r.sent()[0]||null];case 2:return u=n[0],i=n[1],[4,q(document,u,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))},n.asyncDeepQuerySelectorAll=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];if(a(n)){var t=n[0],r=n[1],o=n[2];return q(t,r,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)}var u=n[0],i=n[1];return q(document,u,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)},n.asyncQuerySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(this,void 0,void 0,(function(){var e,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return a(n)?(e=n[0],t=n[1],o=n[2],[4,P(t,e,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:case 3:return[2,r.sent()];case 2:return u=n[0],i=n[1],[4,P(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))},n.asyncQuerySelectorAll=Q,n.asyncShadowRootQuerySelector=x,n.deepQuerySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?A(document,t)[0]||null:A(t,r)[0]||null},n.deepQuerySelectorAll=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?A(document,t):A(t,r)},n.querySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?g(t,document):g(r,t)},n.querySelectorAll=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?S(t,document):S(r,t)},n.shadowRootQuerySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?b(t,document):b(r,t)}}));
|
package/package.json
CHANGED