@asamuzakjp/dom-selector 4.5.0 → 4.6.0-b.1

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 CHANGED
@@ -168,6 +168,37 @@ Returns **[Array][62]<([object][60] \| [undefined][63])>** array of matched n
168
168
  |E:host|✓| |
169
169
  |E:host(s)|✓| |
170
170
  |E:host‑context(s)|✓| |
171
+ |E:state(v)|✓|*1|
172
+ |E:host(:state(v))|✓|*1|
173
+
174
+ *1: `ElementInternals.states` is not implemented in jsdom, so you need to implement yourself.
175
+ ``` javascript
176
+ class LabeledCheckbox extends window.HTMLElement {
177
+ #internals;
178
+ constructor() {
179
+ super();
180
+ this.#internals = this.attachInternals();
181
+ // implement CustomStateSet
182
+ if (!this.#internals.states) {
183
+ this.#internals.states = new Set();
184
+ }
185
+ this.addEventListener('click', this._onClick.bind(this));
186
+ }
187
+ get checked() {
188
+ return this.#internals.states.has('checked');
189
+ }
190
+ set checked(flag) {
191
+ if (flag) {
192
+ this.#internals.states.add('checked');
193
+ } else {
194
+ this.#internals.states.delete('checked');
195
+ }
196
+ }
197
+ _onClick(event) {
198
+ this.checked = !this.checked;
199
+ }
200
+ }
201
+ ```
171
202
 
172
203
 
173
204
  ## Monkey patch jsdom
@@ -249,53 +280,54 @@ const dom = new JSDOM('', {
249
280
  });
250
281
  ```
251
282
 
283
+
252
284
  ## Performance
253
285
 
254
286
  See [benchmark](https://github.com/asamuzaK/domSelector/actions/workflows/benchmark.yml) for the latest results.
255
287
 
256
- `F`: Failed because the selector is not supported or the result is incorrect.
288
+ `F`: Failed because the selector is not supported or the result was incorrect.
257
289
 
258
290
  ### matches()
259
291
 
260
292
  |Selector|jsdom v24.1.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|
261
293
  |:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
262
- |simple selector:<br>`matches('.content')`|989,361 ops/sec ±0.27%|7,447 ops/sec ±1.10%|9,037 ops/sec ±1.74%|947,094 ops/sec ±0.24%|jsdom is the fastest and 1.0 times faster than patched-jsdom.|
263
- |compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|581,187 ops/sec ±0.21%|7,137 ops/sec ±0.82%|8,808 ops/sec ±1.24%|492,756 ops/sec ±0.25%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
264
- |compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|7,144 ops/sec ±0.51%|F|145,203 ops/sec ±0.94%|patched-jsdom is the fastest.|
265
- |compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|472,261 ops/sec ±1.64%|7,199 ops/sec ±0.58%|8,612 ops/sec ±0.51%|403,920 ops/sec ±0.29%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
266
- |complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|152,011 ops/sec ±0.66%|F|5,737 ops/sec ±0.43%|135,540 ops/sec ±0.41%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
267
- |complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,767 ops/sec ±0.47%|39,996 ops/sec ±0.79%|patched-jsdom is the fastest.|
268
- |complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|416,215 ops/sec ±0.49%|F|6,105 ops/sec ±0.29%|358,945 ops/sec ±0.29%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
294
+ |simple selector:<br>`matches('.content')`|955,191 ops/sec ±1.19%|7,301 ops/sec ±0.75%|9,322 ops/sec ±0.65%|819,169 ops/sec ±0.43%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
295
+ |compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|581,444 ops/sec ±1.46%|7,152 ops/sec ±0.70%|8,836 ops/sec ±1.32%|402,486 ops/sec ±0.77%|jsdom is the fastest and 1.4 times faster than patched-jsdom.|
296
+ |compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|7,124 ops/sec ±0.90%|F|129,958 ops/sec ±0.22%|patched-jsdom is the fastest.|
297
+ |compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|469,482 ops/sec ±1.48%|7,179 ops/sec ±0.74%|8,851 ops/sec ±0.71%|343,674 ops/sec ±0.48%|jsdom is the fastest and 1.4 times faster than patched-jsdom.|
298
+ |complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|152,787 ops/sec ±0.23%|F|5,806 ops/sec ±0.82%|131,245 ops/sec ±0.28%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
299
+ |complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,610 ops/sec ±0.57%|9,285 ops/sec ±0.60%|patched-jsdom is the fastest.|
300
+ |complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|407,178 ops/sec ±0.44%|F|6,039 ops/sec ±0.33%|332,047 ops/sec ±0.36%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
269
301
 
270
302
  ### closest()
271
303
 
272
304
  |Selector|jsdom v24.1.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|
273
305
  |:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
274
- |simple selector:<br>`closest('.container')`|367,877 ops/sec ±1.14%|7,218 ops/sec ±0.76%|9,181 ops/sec ±0.64%|356,762 ops/sec ±1.02%|jsdom is the fastest and 1.0 times faster than patched-jsdom.|
275
- |compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|134,650 ops/sec ±0.32%|F|8,549 ops/sec ±0.62%|125,888 ops/sec ±3.16%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
276
- |complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|134,654 ops/sec ±2.02%|F|5,751 ops/sec ±1.01%|119,709 ops/sec ±2.00%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
277
- |complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,596 ops/sec ±0.81%|28,732 ops/sec ±1.13%|patched-jsdom is the fastest.|
278
- |complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|192,885 ops/sec ±1.15%|4,685 ops/sec ±1.30%|5,927 ops/sec ±0.64%|181,927 ops/sec ±1.39%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
306
+ |simple selector:<br>`closest('.container')`|367,267 ops/sec ±0.24%|7,283 ops/sec ±0.67%|9,298 ops/sec ±0.69%|338,618 ops/sec ±1.73%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
307
+ |compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|135,537 ops/sec ±0.34%|F|8,413 ops/sec ±1.50%|120,204 ops/sec ±1.90%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
308
+ |complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|139,190 ops/sec ±1.50%|F|5,821 ops/sec ±0.64%|119,681 ops/sec ±1.44%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
309
+ |complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,695 ops/sec ±0.58%|7,659 ops/sec ±1.85%|patched-jsdom is the fastest.|
310
+ |complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|198,275 ops/sec ±0.59%|4,568 ops/sec ±0.73%|5,922 ops/sec ±0.50%|175,254 ops/sec ±0.27%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
279
311
 
280
312
  ### querySelector()
281
313
 
282
314
  |Selector|jsdom v24.1.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|
283
315
  |:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
284
- |simple selector:<br>`querySelector('.content')`|27,400 ops/sec ±0.96%|9,042 ops/sec ±1.19%|10,550 ops/sec ±0.69%|25,885 ops/sec ±1.48%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
285
- |compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|8,685 ops/sec ±1.47%|8,723 ops/sec ±1.20%|9,836 ops/sec ±0.69%|8,418 ops/sec ±1.41%|linkedom is the fastest and 1.2 times faster than patched-jsdom. jsdom is 1.0 times faster than patched-jsdom.|
286
- |complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|206 ops/sec ±1.48%|F|1,289 ops/sec ±0.42%|709 ops/sec ±1.75%|linkedom is the fastest and 1.8 times faster than patched-jsdom. patched-jsdom is 3.4 times faster than jsdom.|
287
- |complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|1,598 ops/sec ±0.35%|476 ops/sec ±1.94%|linkedom is the fastest and 3.4 times faster than patched-jsdom.|
288
- |complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|2,921 ops/sec ±1.78%|F|9,782 ops/sec ±0.52%|97,513 ops/sec ±1.46%|patched-jsdom is the fastest. patched-jsdom is 33.4 times faster than jsdom.|
316
+ |simple selector:<br>`querySelector('.content')`|27,778 ops/sec ±1.10%|8,861 ops/sec ±0.73%|11,318 ops/sec ±0.66%|29,314 ops/sec ±1.45%|patched-jsdom is the fastest. patched-jsdom is 1.1 times faster than jsdom.|
317
+ |compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|9,731 ops/sec ±1.41%|8,732 ops/sec ±1.50%|9,954 ops/sec ±0.57%|9,492 ops/sec ±1.59%|linkedom is the fastest and 1.0 times faster than patched-jsdom. jsdom is 1.0 times faster than patched-jsdom.|
318
+ |complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|221 ops/sec ±1.70%|F|1,273 ops/sec ±1.13%|272 ops/sec ±1.28%|linkedom is the fastest and 4.7 times faster than patched-jsdom. patched-jsdom is 1.2 times faster than jsdom.|
319
+ |complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|1,594 ops/sec ±1.48%|487 ops/sec ±2.03%|linkedom is the fastest and 3.3 times faster than patched-jsdom.|
320
+ |complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|3,108 ops/sec ±2.01%|F|9,977 ops/sec ±0.99%|90,725 ops/sec ±1.26%|patched-jsdom is the fastest. patched-jsdom is 29.2 times faster than jsdom.|
289
321
 
290
322
  ### querySelectorAll()
291
323
 
292
324
  |Selector|jsdom v24.1.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|
293
325
  |:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
294
- |simple selector:<br>`querySelectorAll('.content')`|2,549 ops/sec ±0.55%|729 ops/sec ±0.48%|1,188 ops/sec ±1.57%|3,153 ops/sec ±0.95%|patched-jsdom is the fastest. patched-jsdom is 1.2 times faster than jsdom.|
295
- |compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|880 ops/sec ±1.32%|706 ops/sec ±1.55%|1,156 ops/sec ±0.93%|938 ops/sec ±1.27%|linkedom is the fastest and 1.2 times faster than patched-jsdom. patched-jsdom is 1.1 times faster than jsdom.|
296
- |complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|196 ops/sec ±0.73%|F|414 ops/sec ±0.24%|797 ops/sec ±1.66%|patched-jsdom is the fastest. patched-jsdom is 4.1 times faster than jsdom.|
297
- |complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|451 ops/sec ±0.36%|504 ops/sec ±1.88%|patched-jsdom is the fastest.|
298
- |complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|273 ops/sec ±0.89%|F|498 ops/sec ±1.38%|236 ops/sec ±2.36%|linkedom is the fastest and 2.1 times faster than patched-jsdom. jsdom is 1.2 times faster than patched-jsdom.|
326
+ |simple selector:<br>`querySelectorAll('.content')`|2,610 ops/sec ±0.33%|804 ops/sec ±0.47%|1,190 ops/sec ±1.78%|3,190 ops/sec ±0.91%|patched-jsdom is the fastest. patched-jsdom is 1.2 times faster than jsdom.|
327
+ |compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|928 ops/sec ±1.31%|753 ops/sec ±0.25%|1,201 ops/sec ±0.18%|1,041 ops/sec ±0.30%|linkedom is the fastest and 1.2 times faster than patched-jsdom. patched-jsdom is 1.1 times faster than jsdom.|
328
+ |complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|227 ops/sec ±1.32%|F|425 ops/sec ±1.37%|270 ops/sec ±1.39%|linkedom is the fastest and 1.6 times faster than patched-jsdom. patched-jsdom is 1.2 times faster than jsdom.|
329
+ |complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|451 ops/sec ±1.73%|535 ops/sec ±2.00%|patched-jsdom is the fastest.|
330
+ |complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|302 ops/sec ±0.67%|F|520 ops/sec ±0.32%|254 ops/sec ±1.65%|linkedom is the fastest and 2.0 times faster than patched-jsdom. jsdom is 1.2 times faster than patched-jsdom.|
299
331
 
300
332
 
301
333
  ## Acknowledgments
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/constant.js"],
4
- "sourcesContent": ["/**\n * constant.js\n */\n\n/* string */\nexport const AN_PLUS_B = 'AnPlusB';\nexport const COMBINATOR = 'Combinator';\nexport const EMPTY = '__EMPTY__';\nexport const IDENTIFIER = 'Identifier';\nexport const NOT_SUPPORTED_ERR = 'NotSupportedError';\nexport const NTH = 'Nth';\nexport const RAW = 'Raw';\nexport const SELECTOR = 'Selector';\nexport const SELECTOR_ATTR = 'AttributeSelector';\nexport const SELECTOR_CLASS = 'ClassSelector';\nexport const SELECTOR_ID = 'IdSelector';\nexport const SELECTOR_LIST = 'SelectorList';\nexport const SELECTOR_PSEUDO_CLASS = 'PseudoClassSelector';\nexport const SELECTOR_PSEUDO_ELEMENT = 'PseudoElementSelector';\nexport const SELECTOR_TYPE = 'TypeSelector';\nexport const STRING = 'String';\nexport const SYNTAX_ERR = 'SyntaxError';\nexport const U_FFFD = '\\uFFFD';\n\n/* numeric */\nexport const BIT_01 = 1;\nexport const BIT_02 = 2;\nexport const BIT_04 = 4;\nexport const BIT_08 = 8;\nexport const BIT_16 = 0x10;\nexport const BIT_32 = 0x20;\nexport const BIT_FFFF = 0xFFFF;\nexport const BIT_HYPHEN = 0x2D;\nexport const DUO = 2;\nexport const HEX = 16;\nexport const TYPE_FROM = 8;\nexport const TYPE_TO = -1;\n\n/* Node */\nexport const ELEMENT_NODE = 1;\nexport const TEXT_NODE = 3;\nexport const DOCUMENT_NODE = 9;\nexport const DOCUMENT_FRAGMENT_NODE = 11;\nexport const DOCUMENT_POSITION_PRECEDING = 2;\nexport const DOCUMENT_POSITION_CONTAINS = 8;\nexport const DOCUMENT_POSITION_CONTAINED_BY = 0x10;\n\n/* NodeFilter */\nexport const SHOW_ALL = 0xffffffff;\nexport const SHOW_DOCUMENT = 0x100;\nexport const SHOW_DOCUMENT_FRAGMENT = 0x400;\nexport const SHOW_ELEMENT = 1;\nexport const WALKER_FILTER = 0x501;\n\n/* selectors */\nexport const ALPHA_NUM = '[A-Z\\\\d]+';\nexport const CHILD_IDX = '(?:first|last|only)-(?:child|of-type)';\nexport const DIGIT = '(?:0|[1-9]\\\\d*)';\nexport const LANG_PART = `(?:-${ALPHA_NUM})*`;\nexport const PSEUDO_CLASSES =\n `(?:any-)?link|${CHILD_IDX}|checked|empty|indeterminate|root|target|visited`;\nexport const ANB =\n `[+-]?(?:${DIGIT}n?|n)|(?:[+-]?${DIGIT})?n\\\\s*[+-]\\\\s*${DIGIT}`;\n// N_TH: excludes An+B with selector list, e.g. :nth-child(2n+1 of .foo)\nexport const N_TH =\n `nth-(?:last-)?(?:child|of-type)\\\\(\\\\s*(?:even|odd|${ANB})\\\\s*\\\\)`;\n// SUB_TYPE: attr, id, class, pseudo-class\nexport const SUB_TYPE = '\\\\[[^|\\\\]]+\\\\]|[#.:][\\\\w-]+';\n// TAG_TYPE: *, tag\nexport const TAG_TYPE = '\\\\*|[A-Za-z][\\\\w-]*';\nexport const TAG_TYPE_I = '\\\\*|[A-Z][\\\\w-]*';\n// LOGICAL_KEY: excludes :has()\nexport const LOGICAL_KEY = '(?:is|not)';\nexport const COMPOUND = `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE})+)`;\nexport const COMBO_A = '\\\\s?[\\\\s>~+]\\\\s?';\nexport const COMBO_B = '\\\\s?[~+]\\\\s?';\nexport const COMPLEX_A = `${COMPOUND}(?:${COMBO_A}${COMPOUND})*`;\nexport const COMPLEX_B = `${COMPOUND}(?:${COMBO_B}${COMPOUND})*`;\nexport const NESTED_LOGICAL_A =\n `:is\\\\(\\\\s*${COMPOUND}(?:\\\\s*,\\\\s*${COMPOUND})*\\\\s*\\\\)`;\nexport const NESTED_LOGICAL_B =\n `:is\\\\(\\\\s*${COMPLEX_A}(?:\\\\s*,\\\\s*${COMPLEX_A})*\\\\s*\\\\)`;\nexport const NESTED_LOGICAL_C =\n `:is\\\\(\\\\s*${COMPLEX_B}(?:\\\\s*,\\\\s*${COMPLEX_B})*\\\\s*\\\\)`;\nexport const COMPOUND_A =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_A})+)`;\nexport const COMPOUND_B =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_B})+)`;\nexport const COMPOUND_C =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_C})+)`;\nexport const COMPOUND_I =\n `(?:${TAG_TYPE_I}|(?:${TAG_TYPE_I})?(?:${SUB_TYPE})+)`;\nexport const COMPLEX_C = `${COMPOUND_B}(?:${COMBO_A}${COMPOUND_B})*`;\nexport const COMPLEX_D = `${COMPOUND_C}(?:${COMBO_B}${COMPOUND_C})*`;\nexport const LOGICAL_COMPLEX_A =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_C}(?:\\\\s*,\\\\s*${COMPLEX_C})*\\\\s*\\\\)`;\nexport const LOGICAL_COMPLEX_B =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_D}(?:\\\\s*,\\\\s*${COMPLEX_D})*\\\\s*\\\\)`;\nexport const LOGICAL_COMPOUND =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPOUND_A}(?:\\\\s*,\\\\s*${COMPOUND_A})*\\\\s*\\\\)`;\n\n/* regexp */\nexport const REG_ANCHOR = /^a(?:rea)?$/;\nexport const REG_CHILD_INDEXED = new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH})`);\nexport const REG_COMPLEX_A = new RegExp(`${COMBO_A}${COMPOUND_I}`, 'i');\nexport const REG_COMPLEX_B = new RegExp(`${COMBO_B}${COMPOUND_I}`, 'i');\nexport const REG_DIR = /^(?:ltr|rtl)$/;\nexport const REG_FORM = /^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;\nexport const REG_FORM_CTRL =\n /^(?:button|fieldset|input|optgroup|option|select|textarea)$/;\nexport const REG_FORM_GROUP = /^(?:fieldset|optgroup|select)$/;\nexport const REG_FORM_VALID = /^(?:button|form|input|select|textarea)$/;\nexport const REG_HEX = /^([\\da-f]{1,6}\\s?)/i;\nexport const REG_INTERACT = /^(?:details|dialog)$/;\nexport const REG_INVALID_SELECTOR = /^$|^\\s*>|,\\s*$/;\nexport const REG_LANG = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');\nexport const REG_LANG_QUOTED = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]*\")\\s*\\))/;\nexport const REG_LOGICAL_COMPLEX_A =\n new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH}|${LOGICAL_COMPLEX_A})`);\nexport const REG_LOGICAL_COMPLEX_B =\n new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH}|${LOGICAL_COMPLEX_B})`);\nexport const REG_LOGICAL_COMPOUND =\n new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH}|${LOGICAL_COMPOUND})`);\nexport const REG_LOGICAL_EMPTY = /(:(is|where)\\(\\s*\\))/;\nexport const REG_LOGICAL_KEY = new RegExp(`:${LOGICAL_KEY}\\\\(`);\nexport const REG_LOGICAL_PSEUDO = /^(?:has|is|not|where)$/;\nexport const REG_SHADOW_HOST = /^host(?:-context)?$/;\nexport const REG_SHADOW_MODE = /^(?:close|open)$/;\nexport const REG_SHADOW_PSEUDO = /^part|slotted$/;\nexport const REG_TYPE_CHECK = /^(?:checkbox|radio)$/;\nexport const REG_TYPE_DATE = /^(?:date(?:time-local)?|month|time|week)$/;\nexport const REG_TYPE_RANGE =\n /(?:date(?:time-local)?|month|number|range|time|week)$/;\nexport const REG_TYPE_RESET = /^(?:button|reset)$/;\nexport const REG_TYPE_SUBMIT = /^(?:image|submit)$/;\nexport const REG_TYPE_TEXT = /^(?:email|number|password|search|tel|text|url)$/;\n"],
4
+ "sourcesContent": ["/**\n * constant.js\n */\n\n/* string */\nexport const AN_PLUS_B = 'AnPlusB';\nexport const COMBINATOR = 'Combinator';\nexport const EMPTY = '__EMPTY__';\nexport const IDENTIFIER = 'Identifier';\nexport const NOT_SUPPORTED_ERR = 'NotSupportedError';\nexport const NTH = 'Nth';\nexport const RAW = 'Raw';\nexport const SELECTOR = 'Selector';\nexport const SELECTOR_ATTR = 'AttributeSelector';\nexport const SELECTOR_CLASS = 'ClassSelector';\nexport const SELECTOR_ID = 'IdSelector';\nexport const SELECTOR_LIST = 'SelectorList';\nexport const SELECTOR_PSEUDO_CLASS = 'PseudoClassSelector';\nexport const SELECTOR_PSEUDO_ELEMENT = 'PseudoElementSelector';\nexport const SELECTOR_TYPE = 'TypeSelector';\nexport const STRING = 'String';\nexport const SYNTAX_ERR = 'SyntaxError';\nexport const U_FFFD = '\\uFFFD';\n\n/* numeric */\nexport const BIT_01 = 1;\nexport const BIT_02 = 2;\nexport const BIT_04 = 4;\nexport const BIT_08 = 8;\nexport const BIT_16 = 0x10;\nexport const BIT_32 = 0x20;\nexport const BIT_FFFF = 0xFFFF;\nexport const BIT_HYPHEN = 0x2D;\nexport const DUO = 2;\nexport const HEX = 16;\nexport const TYPE_FROM = 8;\nexport const TYPE_TO = -1;\n\n/* Node */\nexport const ELEMENT_NODE = 1;\nexport const TEXT_NODE = 3;\nexport const DOCUMENT_NODE = 9;\nexport const DOCUMENT_FRAGMENT_NODE = 11;\nexport const DOCUMENT_POSITION_PRECEDING = 2;\nexport const DOCUMENT_POSITION_CONTAINS = 8;\nexport const DOCUMENT_POSITION_CONTAINED_BY = 0x10;\n\n/* NodeFilter */\nexport const SHOW_ALL = 0xffffffff;\nexport const SHOW_DOCUMENT = 0x100;\nexport const SHOW_DOCUMENT_FRAGMENT = 0x400;\nexport const SHOW_ELEMENT = 1;\nexport const WALKER_FILTER = 0x501;\n\n/* selectors */\nexport const ALPHA_NUM = '[A-Z\\\\d]+';\nexport const CHILD_IDX = '(?:first|last|only)-(?:child|of-type)';\nexport const DIGIT = '(?:0|[1-9]\\\\d*)';\nexport const LANG_PART = `(?:-${ALPHA_NUM})*`;\nexport const PSEUDO_CLASSES =\n `(?:any-)?link|${CHILD_IDX}|checked|empty|indeterminate|root|target|visited`;\nexport const ANB =\n `[+-]?(?:${DIGIT}n?|n)|(?:[+-]?${DIGIT})?n\\\\s*[+-]\\\\s*${DIGIT}`;\n// N_TH: excludes An+B with selector list, e.g. :nth-child(2n+1 of .foo)\nexport const N_TH =\n `nth-(?:last-)?(?:child|of-type)\\\\(\\\\s*(?:even|odd|${ANB})\\\\s*\\\\)`;\n// SUB_TYPE: attr, id, class, pseudo-class, note that [foo|=bar] is excluded\nexport const SUB_TYPE = '\\\\[[^|\\\\]]+\\\\]|[#.:][\\\\w-]+';\n// TAG_TYPE: *, tag\nexport const TAG_TYPE = '\\\\*|[A-Za-z][\\\\w-]*';\nexport const TAG_TYPE_I = '\\\\*|[A-Z][\\\\w-]*';\n// LOGICAL_KEY: excludes :has()\nexport const LOGICAL_KEY = '(?:is|not)';\nexport const COMPOUND = `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE})+)`;\nexport const COMBO_A = '\\\\s?[\\\\s>~+]\\\\s?';\nexport const COMBO_B = '\\\\s?[~+]\\\\s?';\nexport const COMPLEX_A = `${COMPOUND}(?:${COMBO_A}${COMPOUND})*`;\nexport const COMPLEX_B = `${COMPOUND}(?:${COMBO_B}${COMPOUND})*`;\nexport const NESTED_LOGICAL_A =\n `:is\\\\(\\\\s*${COMPOUND}(?:\\\\s*,\\\\s*${COMPOUND})*\\\\s*\\\\)`;\nexport const NESTED_LOGICAL_B =\n `:is\\\\(\\\\s*${COMPLEX_A}(?:\\\\s*,\\\\s*${COMPLEX_A})*\\\\s*\\\\)`;\nexport const NESTED_LOGICAL_C =\n `:is\\\\(\\\\s*${COMPLEX_B}(?:\\\\s*,\\\\s*${COMPLEX_B})*\\\\s*\\\\)`;\nexport const COMPOUND_A =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_A})+)`;\nexport const COMPOUND_B =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_B})+)`;\nexport const COMPOUND_C =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_C})+)`;\nexport const COMPOUND_I =\n `(?:${TAG_TYPE_I}|(?:${TAG_TYPE_I})?(?:${SUB_TYPE})+)`;\nexport const COMPLEX_C = `${COMPOUND_B}(?:${COMBO_A}${COMPOUND_B})*`;\nexport const COMPLEX_D = `${COMPOUND_C}(?:${COMBO_B}${COMPOUND_C})*`;\nexport const LOGICAL_COMPLEX_A =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_C}(?:\\\\s*,\\\\s*${COMPLEX_C})*\\\\s*\\\\)`;\nexport const LOGICAL_COMPLEX_B =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_D}(?:\\\\s*,\\\\s*${COMPLEX_D})*\\\\s*\\\\)`;\nexport const LOGICAL_COMPOUND =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPOUND_A}(?:\\\\s*,\\\\s*${COMPOUND_A})*\\\\s*\\\\)`;\n\n/* regexp */\nexport const REG_ANCHOR = /^a(?:rea)?$/;\nexport const REG_CHILD_INDEXED = new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH})`);\nexport const REG_COMPLEX_A = new RegExp(`${COMBO_A}${COMPOUND_I}`, 'i');\nexport const REG_COMPLEX_B = new RegExp(`${COMBO_B}${COMPOUND_I}`, 'i');\nexport const REG_DIR = /^(?:ltr|rtl)$/;\nexport const REG_FORM = /^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;\nexport const REG_FORM_CTRL =\n /^(?:button|fieldset|input|optgroup|option|select|textarea)$/;\nexport const REG_FORM_GROUP = /^(?:fieldset|optgroup|select)$/;\nexport const REG_FORM_VALID = /^(?:button|form|input|select|textarea)$/;\nexport const REG_HEX = /^([\\da-f]{1,6}\\s?)/i;\nexport const REG_INTERACT = /^(?:details|dialog)$/;\nexport const REG_INVALID_SELECTOR = /^$|^\\s*>|,\\s*$/;\nexport const REG_LANG = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');\nexport const REG_LANG_QUOTED = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]*\")\\s*\\))/;\nexport const REG_LOGICAL_COMPLEX_A =\n new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH}|${LOGICAL_COMPLEX_A})`);\nexport const REG_LOGICAL_COMPLEX_B =\n new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH}|${LOGICAL_COMPLEX_B})`);\nexport const REG_LOGICAL_COMPOUND =\n new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH}|${LOGICAL_COMPOUND})`);\nexport const REG_LOGICAL_EMPTY = /(:(is|where)\\(\\s*\\))/;\nexport const REG_LOGICAL_KEY = new RegExp(`:${LOGICAL_KEY}\\\\(`);\nexport const REG_LOGICAL_PSEUDO = /^(?:has|is|not|where)$/;\nexport const REG_SHADOW_HOST = /^host(?:-context)?$/;\nexport const REG_SHADOW_MODE = /^(?:close|open)$/;\nexport const REG_SHADOW_PSEUDO = /^part|slotted$/;\nexport const REG_TYPE_CHECK = /^(?:checkbox|radio)$/;\nexport const REG_TYPE_DATE = /^(?:date(?:time-local)?|month|time|week)$/;\nexport const REG_TYPE_RANGE =\n /(?:date(?:time-local)?|month|number|range|time|week)$/;\nexport const REG_TYPE_RESET = /^(?:button|reset)$/;\nexport const REG_TYPE_SUBMIT = /^(?:image|submit)$/;\nexport const REG_TYPE_TEXT = /^(?:email|number|password|search|tel|text|url)$/;\n"],
5
5
  "mappings": "4ZAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,eAAAE,EAAA,QAAAC,EAAA,cAAAC,EAAA,WAAAC,GAAA,WAAAC,GAAA,WAAAC,GAAA,WAAAC,GAAA,WAAAC,GAAA,WAAAC,GAAA,aAAAC,GAAA,eAAAC,GAAA,cAAAC,EAAA,eAAAC,EAAA,YAAAC,EAAA,YAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,eAAAC,E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IT_04", "BIT_08", "BIT_16", "BIT_32", "BIT_FFFF", "BIT_HYPHEN", "CHILD_IDX", "COMBINATOR", "COMBO_A", "COMBO_B", "COMPLEX_A", "COMPLEX_B", "COMPLEX_C", "COMPLEX_D", "COMPOUND", "COMPOUND_A", "COMPOUND_B", "COMPOUND_C", "COMPOUND_I", "DIGIT", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_PRECEDING", "DUO", "ELEMENT_NODE", "EMPTY", "HEX", "IDENTIFIER", "LANG_PART", "LOGICAL_COMPLEX_A", "LOGICAL_COMPLEX_B", "LOGICAL_COMPOUND", "LOGICAL_KEY", "NESTED_LOGICAL_A", "NESTED_LOGICAL_B", "NESTED_LOGICAL_C", "NOT_SUPPORTED_ERR", "NTH", "N_TH", "PSEUDO_CLASSES", "RAW", "REG_ANCHOR", "REG_CHILD_INDEXED", "REG_COMPLEX_A", "REG_COMPLEX_B", "REG_DIR", "REG_FORM", "REG_FORM_CTRL", "REG_FORM_GROUP", "REG_FORM_VALID", "REG_HEX", "REG_INTERACT", "REG_INVALID_SELECTOR", "REG_LANG", "REG_LANG_QUOTED", "REG_LOGICAL_COMPLEX_A", "REG_LOGICAL_COMPLEX_B", "REG_LOGICAL_COMPOUND", "REG_LOGICAL_EMPTY", "REG_LOGICAL_KEY", "REG_LOGICAL_PSEUDO", "REG_SHADOW_HOST", "REG_SHADOW_MODE", "REG_SHADOW_PSEUDO", "REG_TYPE_CHECK", "REG_TYPE_DATE", "REG_TYPE_RANGE", "REG_TYPE_RESET", "REG_TYPE_SUBMIT", "REG_TYPE_TEXT", "SELECTOR", "SELECTOR_ATTR", "SELECTOR_CLASS", "SELECTOR_ID", "SELECTOR_LIST", "SELECTOR_PSEUDO_CLASS", "SELECTOR_PSEUDO_ELEMENT", "SELECTOR_TYPE", "SHOW_ALL", "SHOW_DOCUMENT", "SHOW_DOCUMENT_FRAGMENT", "SHOW_ELEMENT", "STRING", "SUB_TYPE", "SYNTAX_ERR", "TAG_TYPE", "TAG_TYPE_I", "TEXT_NODE", "TYPE_FROM", "TYPE_TO", "U_FFFD", "WALKER_FILTER", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var C=Object.create;var f=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var r in t)f(e,r,{get:t[r],enumerable:!0})},x=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of k(t))!d.call(e,l)&&l!==r&&f(e,l,{get:()=>t[l],enumerable:!(i=_(t,l))||i.enumerable});return e};var R=(e,t,r)=>(r=e!=null?C(w(e)):{},x(t||!e||!e.__esModule?f(r,"default",{value:e,enumerable:!0}):r,e)),v=e=>x(f({},"__esModule",{value:!0}),e);var $={};I($,{getDirectionality:()=>u,getNamespaceURI:()=>D,getSlottedTextContent:()=>T,isContentEditable:()=>g,isInShadowTree:()=>h,isNamespaceDeclared:()=>P,isPreceding:()=>O,resolveContent:()=>M,sortNodes:()=>S,traverseNode:()=>U,verifyNode:()=>n});module.exports=v($);var E=R(require("bidi-js"),1),s=require("./constant.js");const n=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(s.TYPE_FROM,s.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===s.DOCUMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE||e.nodeType===s.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},M=e=>{e=n(e);let t,r;switch(e.nodeType){case s.DOCUMENT_NODE:{t=e,r=e;break}case s.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case s.ELEMENT_NODE:default:{t=e.ownerDocument;let l=e;for(;l&&l.parentNode;)l=l.parentNode;r=l;break}}const i=t.createTreeWalker(r,s.WALKER_FILTER);return[t,r,i]},U=(e,t)=>{(!e||!e.nodeType)&&n(e);let r;if(t?.currentNode){let i=t.currentNode;if(i===e)r=i;else if(i.contains(e))for(i=t.nextNode();i;){if(i===e){r=i;break}i=t.nextNode()}else{if(i!==t.root)for(;i&&!(i===t.root||i===e);)i=t.parentNode();if(e.nodeType===s.ELEMENT_NODE)for(;i;){if(i===e){r=i;break}i=t.nextNode()}else r=i}}return r??null},h=e=>{(!e||!e.type)&&n(e);let t;if(e.nodeType===s.ELEMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:i,mode:l,nodeType:p,parentNode:o}=r;if(i&&l&&p===s.DOCUMENT_FRAGMENT_NODE&&s.REG_SHADOW_MODE.test(l)){t=!0;break}r=o}}return!!t},T=e=>{(!e||!e.nodeType)&&n(e);let t;if(e.localName==="slot"&&h(e)){const r=e.assignedNodes();if(r.length){for(const i of r)if(t=i.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},u=e=>{(!e||!e.nodeType)&&n(e);let t;if(e.nodeType===s.ELEMENT_NODE){const{dir:r,localName:i,parentNode:l}=e,{getEmbeddingLevels:p}=(0,E.default)();if(s.REG_DIR.test(r))t=r;else if(r==="auto"){let o;switch(i){case"input":{!e.type||/^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(e.type)?o=e.value:/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(e.type)&&(t="ltr");break}case"slot":{o=T(e);break}case"textarea":{o=e.value;break}default:{const a=[].slice.call(e.childNodes);for(const c of a){const{dir:y,localName:N,nodeType:m,textContent:b}=c;if(m===s.TEXT_NODE?o=b.trim():m===s.ELEMENT_NODE&&!/^(?:bdi|script|style|textarea)$/.test(N)&&(!y||!s.REG_DIR.test(y))&&(N==="slot"?o=T(c):o=b.trim()),o)break}}}if(o){const{paragraphs:[{level:a}]}=p(o);a%2===1?t="rtl":t="ltr"}if(!t)if(l){const{nodeType:a}=l;a===s.ELEMENT_NODE?t=u(l):(a===s.DOCUMENT_NODE||a===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(i==="bdi"){const o=e.textContent.trim();if(o){const{paragraphs:[{level:a}]}=p(o);a%2===1?t="rtl":t="ltr"}t||l||(t="ltr")}else if(i==="input"&&e.type==="tel")t="ltr";else if(l){if(i==="slot"){const o=T(e);if(o){const{paragraphs:[{level:a}]}=p(o);a%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:o}=l;o===s.ELEMENT_NODE?t=u(l):(o===s.DOCUMENT_NODE||o===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},g=e=>{(!e||!e.nodeType)&&n(e);let t;if(e.nodeType===s.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let i=e.parentNode;for(;i;){if(g(i)){t=!0;break}i=i.parentNode}}}}return!!t},D=(e,t)=>{(!t||!t.nodeType)&&n(t);let r;if(e&&typeof e=="string"&&t.nodeType===s.ELEMENT_NODE){const{attributes:i}=t;for(const l of i){const{name:p,namespaceURI:o,prefix:a,value:c}=l;if(p===`xmlns:${e}`){r=c;break}else if(a===e){r=o;break}}}return r??null},P=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===s.ELEMENT_NODE&&(r=t.lookupNamespaceURI(e),!r)){const i=t.ownerDocument.documentElement;let l=t;for(;l&&(r=D(e,l),!(r||l===i));)l=l.parentNode}return!!r},O=(e,t)=>{!e||!e.nodeType?n(e):(!t||!t.nodeType)&&n(t);let r;if(e.nodeType===s.ELEMENT_NODE&&t.nodeType===s.ELEMENT_NODE){const i=t.compareDocumentPosition(e);r=i&s.DOCUMENT_POSITION_PRECEDING||i&s.DOCUMENT_POSITION_CONTAINS}return!!r},S=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,i)=>{let l;return O(i,r)?l=1:l=-1,l}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isInShadowTree,isNamespaceDeclared,isPreceding,resolveContent,sortNodes,traverseNode,verifyNode});
1
+ var d=Object.create;var f=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var r in t)f(e,r,{get:t[r],enumerable:!0})},E=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of k(t))!R.call(e,o)&&o!==r&&f(e,o,{get:()=>t[o],enumerable:!(i=_(t,o))||i.enumerable});return e};var g=(e,t,r)=>(r=e!=null?d(I(e)):{},E(t||!e||!e.__esModule?f(r,"default",{value:e,enumerable:!0}):r,e)),U=e=>E(f({},"__esModule",{value:!0}),e);var L={};v(L,{getDirectionality:()=>y,getNamespaceURI:()=>C,getSlottedTextContent:()=>m,isContentEditable:()=>w,isCustomElement:()=>$,isInShadowTree:()=>D,isNamespaceDeclared:()=>P,isPreceding:()=>O,resolveContent:()=>M,sortNodes:()=>A,traverseNode:()=>S,verifyNode:()=>n});module.exports=U(L);var h=g(require("bidi-js"),1),u=g(require("is-potential-custom-element-name"),1),s=require("./constant.js");const n=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(s.TYPE_FROM,s.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===s.DOCUMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE||e.nodeType===s.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},M=e=>{e=n(e);let t,r;switch(e.nodeType){case s.DOCUMENT_NODE:{t=e,r=e;break}case s.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case s.ELEMENT_NODE:default:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;r=o;break}}const i=t.createTreeWalker(r,s.WALKER_FILTER);return[t,r,i]},S=(e,t)=>{let r;if(!e||!e.nodeType)n(e);else if(t?.currentNode){let i=t.currentNode;if(i===e)r=i;else if(i.contains(e))for(i=t.nextNode();i;){if(i===e){r=i;break}i=t.nextNode()}else{if(i!==t.root)for(;i&&!(i===t.root||i===e);)i=t.parentNode();if(e.nodeType===s.ELEMENT_NODE)for(;i;){if(i===e){r=i;break}i=t.nextNode()}else r=i}}return r??null},$=(e,t={})=>{let r;if(!e||!e.nodeType)n(e);else if(e.nodeType===s.ELEMENT_NODE){const{localName:i,ownerDocument:o}=e,{formAssociated:c}=t,l=o.defaultView;let a;const p=e.getAttribute("is");p?a=(0,u.default)(p)&&l.customElements.get(p):a=(0,u.default)(i)&&l.customElements.get(i),a&&(c?r=a.formAssociated:r=!0)}return!!r},D=e=>{let t;if(!e||!e.nodeType)n(e);else if(e.nodeType===s.ELEMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:i,mode:o,nodeType:c,parentNode:l}=r;if(i&&o&&c===s.DOCUMENT_FRAGMENT_NODE&&s.REG_SHADOW_MODE.test(o)){t=!0;break}r=l}}return!!t},m=e=>{let t;if(!e||!e.nodeType)n(e);else if(e.localName==="slot"&&D(e)){const r=e.assignedNodes();if(r.length){for(const i of r)if(t=i.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},y=e=>{let t;if(!e||!e.nodeType)n(e);else if(e.nodeType===s.ELEMENT_NODE){const{dir:r,localName:i,parentNode:o}=e,{getEmbeddingLevels:c}=(0,h.default)();if(s.REG_DIR.test(r))t=r;else if(r==="auto"){let l;switch(i){case"input":{!e.type||/^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(e.type)?l=e.value:/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(e.type)&&(t="ltr");break}case"slot":{l=m(e);break}case"textarea":{l=e.value;break}default:{const a=[].slice.call(e.childNodes);for(const p of a){const{dir:T,localName:N,nodeType:b,textContent:x}=p;if(b===s.TEXT_NODE?l=x.trim():b===s.ELEMENT_NODE&&!/^(?:bdi|script|style|textarea)$/.test(N)&&(!T||!s.REG_DIR.test(T))&&(N==="slot"?l=m(p):l=x.trim()),l)break}}}if(l){const{paragraphs:[{level:a}]}=c(l);a%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:a}=o;a===s.ELEMENT_NODE?t=y(o):(a===s.DOCUMENT_NODE||a===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(i==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:a}]}=c(l);a%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(i==="input"&&e.type==="tel")t="ltr";else if(o){if(i==="slot"){const l=m(e);if(l){const{paragraphs:[{level:a}]}=c(l);a%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=o;l===s.ELEMENT_NODE?t=y(o):(l===s.DOCUMENT_NODE||l===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},w=e=>{let t;if(!e||!e.nodeType)n(e);else if(e.nodeType===s.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let i=e.parentNode;for(;i;){if(w(i)){t=!0;break}i=i.parentNode}}}}return!!t},C=(e,t)=>{let r;if(typeof e!="string"||!t||!t.nodeType)if(typeof e!="string"){const o=`Unexpected type ${Object.prototype.toString.call(e).slice(s.TYPE_FROM,s.TYPE_TO)}`;throw new TypeError(o)}else n(t);else if(e&&t.nodeType===s.ELEMENT_NODE){const{attributes:i}=t;for(const o of i){const{name:c,namespaceURI:l,prefix:a,value:p}=o;if(c===`xmlns:${e}`){r=p;break}else if(a===e){r=l;break}}}return r??null},P=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===s.ELEMENT_NODE&&(r=t.lookupNamespaceURI(e),!r)){const i=t.ownerDocument.documentElement;let o=t;for(;o&&(r=C(e,o),!(r||o===i));)o=o.parentNode}return!!r},O=(e,t)=>{let r;if(!e||!e.nodeType)n(e);else if(!t||!t.nodeType)n(t);else if(e.nodeType===s.ELEMENT_NODE&&t.nodeType===s.ELEMENT_NODE){const i=t.compareDocumentPosition(e);r=i&s.DOCUMENT_POSITION_PRECEDING||i&s.DOCUMENT_POSITION_CONTAINS}return!!r},A=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,i)=>{let o;return O(i,r)?o=1:o=-1,o}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isCustomElement,isInShadowTree,isNamespaceDeclared,isPreceding,resolveContent,sortNodes,traverseNode,verifyNode});
2
2
  //# sourceMappingURL=dom-util.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/dom-util.js"],
4
- "sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, REG_DIR, REG_SHADOW_MODE,\n TEXT_NODE, TYPE_FROM, TYPE_TO, WALKER_FILTER\n} from './constant.js';\n\n/**\n * verify node\n * @param {*} node - node\n * @throws\n * @returns {object} - Document, DocumentFragment, Element node\n */\nexport const verifyNode = node => {\n if (!node || !node.nodeType || !node.nodeName) {\n const type = Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${type}`;\n throw new TypeError(msg);\n } else if (!(node.nodeType === DOCUMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE ||\n node.nodeType === ELEMENT_NODE)) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n return node;\n};\n\n/**\n * resolve content document, root node and tree walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of document, root node, tree walker\n */\nexport const resolveContent = node => {\n node = verifyNode(node);\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE:\n default: {\n document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n }\n const walker = document.createTreeWalker(root, WALKER_FILTER);\n return [\n document,\n root,\n walker\n ];\n};\n\n/**\n * traverse node tree\n * @private\n * @param {object} node - node\n * @param {object} walker - tree walker\n * @returns {?object} - current node\n */\nexport const traverseNode = (node, walker) => {\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n }\n let current;\n if (walker?.currentNode) {\n let refNode = walker.currentNode;\n if (refNode === node) {\n current = refNode;\n } else if (refNode.contains(node)) {\n refNode = walker.nextNode();\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root || refNode === node) {\n break;\n }\n refNode = walker.parentNode();\n }\n }\n if (node.nodeType === ELEMENT_NODE) {\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n current = refNode;\n }\n }\n }\n return current ?? null;\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = node => {\n if (!node || !node.type) {\n // throws\n verifyNode(node);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = node => {\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n }\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = node => {\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n if (REG_DIR.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(node.type)) {\n text = node.value;\n } else if (/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(node.type)) {\n res = 'ltr';\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|script|style|textarea)$/.test(itemLocalName) &&\n (!itemDir || !REG_DIR.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = node => {\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n }\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA, nodeB) => {\n if (!nodeA || !nodeA.nodeType) {\n // throws\n verifyNode(nodeA);\n } else if (!nodeB || !nodeB.nodeType) {\n // throws\n verifyNode(nodeB);\n }\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,oBAAAC,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,cAAAC,EAAA,iBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAb,GAKA,IAAAc,EAAwB,wBAGxBC,EAIO,yBAQA,MAAMH,EAAaI,GAAQ,CAChC,GAAI,CAACA,GAAQ,CAACA,EAAK,UAAY,CAACA,EAAK,SAAU,CAE7C,MAAMC,EAAM,mBADC,OAAO,UAAU,SAAS,KAAKD,CAAI,EAAE,MAAM,YAAW,SAAO,CACvC,GACnC,MAAM,IAAI,UAAUC,CAAG,CACzB,SAAW,EAAED,EAAK,WAAa,iBAClBA,EAAK,WAAa,0BAClBA,EAAK,WAAa,gBAAe,CAC5C,MAAMC,EAAM,mBAAmBD,EAAK,QAAQ,GAC5C,MAAM,IAAI,UAAUC,CAAG,CACzB,CACA,OAAOD,CACT,EAOaP,EAAiBO,GAAQ,CACpCA,EAAOJ,EAAWI,CAAI,EACtB,IAAIE,EACAC,EACJ,OAAQH,EAAK,SAAU,CACrB,KAAK,gBAAe,CAClBE,EAAWF,EACXG,EAAOH,EACP,KACF,CACA,KAAK,yBAAwB,CAC3BE,EAAWF,EAAK,cAChBG,EAAOH,EACP,KACF,CACA,KAAK,eACL,QAAS,CACPE,EAAWF,EAAK,cA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AAAS,GAAOT,IAAWD,KAGtBC,EAASA,EAAO,UAEpB,CAEF,MAAO,CAAC,CAACS,CACX,EAQarB,EAAc,CAAC2C,EAAOC,IAAU,CACvC,CAACD,GAAS,CAACA,EAAM,SAEnBvC,EAAWuC,CAAK,GACP,CAACC,GAAS,CAACA,EAAM,WAE1BxC,EAAWwC,CAAK,EAElB,IAAIvB,EACJ,GAAIsB,EAAM,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDtB,EAAMwB,EAAS,+BACTA,EAAS,4BACjB,CACA,MAAO,CAAC,CAACxB,CACX,EAOanB,EAAY,CAACoB,EAAQ,CAAC,IAAM,CACvC,MAAMwB,EAAM,CAAC,GAAGxB,CAAK,EACrB,OAAIwB,EAAI,OAAS,GACfA,EAAI,KAAK,CAACC,EAAGC,IAAM,CACjB,IAAI3B,EACJ,OAAIrB,EAAYgD,EAAGD,CAAC,EAClB1B,EAAM,EAENA,EAAM,GAEDA,CACT,CAAC,EAEIyB,CACT",
6
- "names": ["dom_util_exports", "__export", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isNamespaceDeclared", "isPreceding", "resolveContent", "sortNodes", "traverseNode", "verifyNode", "__toCommonJS", "import_bidi_js", "import_constant", "node", "msg", "document", "root", "parent", "walker", "current", "refNode", "bool", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "getEmbeddingLevels", "bidiFactory", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "attr", "ns", "attributes", "name", "namespaceURI", "prefix", "value", "nodeA", "nodeB", "posBit", "arr", "a", "b"]
4
+ "sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\nimport isCustomElementName from 'is-potential-custom-element-name';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, REG_DIR, REG_SHADOW_MODE,\n TEXT_NODE, TYPE_FROM, TYPE_TO, WALKER_FILTER\n} from './constant.js';\n\n/**\n * verify node\n * @param {*} node - node\n * @throws\n * @returns {object} - Document, DocumentFragment, Element node\n */\nexport const verifyNode = node => {\n if (!node || !node.nodeType || !node.nodeName) {\n const type = Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${type}`;\n throw new TypeError(msg);\n } else if (!(node.nodeType === DOCUMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE ||\n node.nodeType === ELEMENT_NODE)) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n return node;\n};\n\n/**\n * resolve content document, root node and tree walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of document, root node, tree walker\n */\nexport const resolveContent = node => {\n node = verifyNode(node);\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE:\n default: {\n document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n }\n const walker = document.createTreeWalker(root, WALKER_FILTER);\n return [\n document,\n root,\n walker\n ];\n};\n\n/**\n * traverse node tree\n * @private\n * @param {object} node - node\n * @param {object} walker - tree walker\n * @returns {?object} - current node\n */\nexport const traverseNode = (node, walker) => {\n let current;\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n } else if (walker?.currentNode) {\n let refNode = walker.currentNode;\n if (refNode === node) {\n current = refNode;\n } else if (refNode.contains(node)) {\n refNode = walker.nextNode();\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root || refNode === node) {\n break;\n }\n refNode = walker.parentNode();\n }\n }\n if (node.nodeType === ELEMENT_NODE) {\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n current = refNode;\n }\n }\n }\n return current ?? null;\n};\n\n/**\n * is custom element\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result;\n */\nexport const isCustomElement = (node, opt = {}) => {\n let bool;\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n } else if (node.nodeType === ELEMENT_NODE) {\n const { localName, ownerDocument } = node;\n const { formAssociated } = opt;\n const window = ownerDocument.defaultView;\n let elmConstructor;\n const attr = node.getAttribute('is');\n if (attr) {\n elmConstructor =\n isCustomElementName(attr) && window.customElements.get(attr);\n } else {\n elmConstructor =\n isCustomElementName(localName) && window.customElements.get(localName);\n }\n if (elmConstructor) {\n if (formAssociated) {\n bool = elmConstructor.formAssociated;\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = node => {\n let bool;\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n } else if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = node => {\n let res;\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n } else if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = node => {\n let res;\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n } else if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n if (REG_DIR.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(node.type)) {\n text = node.value;\n } else if (/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(node.type)) {\n res = 'ltr';\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|script|style|textarea)$/.test(itemLocalName) &&\n (!itemDir || !REG_DIR.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = node => {\n let res;\n if (!node || !node.nodeType) {\n // throws\n verifyNode(node);\n } else if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n let res;\n if (typeof ns !== 'string' || !node || !node.nodeType) {\n if (typeof ns !== 'string') {\n const type = Object.prototype.toString.call(ns).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${type}`;\n throw new TypeError(msg);\n } else {\n // throws\n verifyNode(node);\n }\n } else if (ns && node.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA, nodeB) => {\n let res;\n if (!nodeA || !nodeA.nodeType) {\n // throws\n verifyNode(nodeA);\n } else if (!nodeB || !nodeB.nodeType) {\n // throws\n verifyNode(nodeB);\n } else if (nodeA.nodeType === ELEMENT_NODE &&\n nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding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AQ,MAAAC,CAAM,EAAIzB,EAC9C,GAAIsB,IAAS,SAASF,CAAE,GAAI,CAC1Bd,EAAMmB,EACN,KACF,SAAWD,IAAWJ,EAAI,CACxBd,EAAMiB,EACN,KACF,CACF,CACF,CACA,OAAOjB,GAAO,IAChB,EAQa/B,EAAsB,CAAC6C,EAAK,GAAInC,EAAO,CAAC,IAAM,CACzD,IAAIqB,EACJ,GAAIc,GAAM,OAAOA,GAAO,UAAYnC,EAAK,WAAa,iBACpDqB,EAAMrB,EAAK,mBAAmBmC,CAAE,EAC5B,CAACd,GAAK,CACR,MAAMlB,EAAOH,EAAK,cAAc,gBAChC,IAAII,EAASJ,EACb,KAAOI,IACLiB,EAAMpC,EAAgBkD,EAAI/B,CAAM,EAC5B,EAAAiB,GAAOjB,IAAWD,KAGtBC,EAASA,EAAO,UAEpB,CAEF,MAAO,CAAC,CAACiB,CACX,EAQa9B,EAAc,CAACkD,EAAOC,IAAU,CAC3C,IAAIrB,EACJ,GAAI,CAACoB,GAAS,CAACA,EAAM,SAEnB9C,EAAW8C,CAAK,UACP,CAACC,GAAS,CAACA,EAAM,SAE1B/C,EAAW+C,CAAK,UACPD,EAAM,WAAa,gBACnBC,EAAM,WAAa,eAAc,CAC1C,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDpB,EAAMsB,EAAS,+BACTA,EAAS,4BACjB,CACA,MAAO,CAAC,CAACtB,CACX,EAOa5B,EAAY,CAAC6B,EAAQ,CAAC,IAAM,CACvC,MAAMsB,EAAM,CAAC,GAAGtB,CAAK,EACrB,OAAIsB,EAAI,OAAS,GACfA,EAAI,KAAK,CAACC,EAAGC,IAAM,CACjB,IAAIzB,EACJ,OAAI9B,EAAYuD,EAAGD,CAAC,EAClBxB,EAAM,EAENA,EAAM,GAEDA,CACT,CAAC,EAEIuB,CACT",
6
+ "names": ["dom_util_exports", "__export", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "isContentEditable", "isCustomElement", "isInShadowTree", "isNamespaceDeclared", "isPreceding", "resolveContent", "sortNodes", "traverseNode", "verifyNode", "__toCommonJS", "import_bidi_js", "import_is_potential_custom_element_name", "import_constant", "node", "msg", "document", "root", "parent", "walker", "current", "refNode", "opt", "bool", "localName", "ownerDocument", "formAssociated", "window", "elmConstructor", "attr", "isCustomElementName", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "getEmbeddingLevels", "bidiFactory", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "ns", "attributes", "name", "namespaceURI", "prefix", "value", "nodeA", "nodeB", "posBit", "arr", "a", "b"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var W=Object.create;var P=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(g,l)=>{for(var e in l)P(g,e,{get:l[e],enumerable:!0})},I=(g,l,e,h)=>{if(l&&typeof l=="object"||typeof l=="function")for(let n of j(l))!q.call(g,n)&&n!==e&&P(g,n,{get:()=>l[n],enumerable:!(h=B(l,n))||h.enumerable});return g};var U=(g,l,e)=>(e=g!=null?W(Y(g)):{},I(l||!g||!g.__esModule?P(e,"default",{value:g,enumerable:!0}):e,g)),X=g=>I(P({},"__esModule",{value:!0}),g);var Q={};V(Q,{Finder:()=>K});module.exports=X(Q);var M=U(require("is-potential-custom-element-name"),1),G=U(require("@asamuzakjp/nwsapi"),1),_=require("./dom-util.js"),O=require("./matcher.js"),y=require("./parser.js"),c=require("./constant.js");const x="next",S="prev",L="all",E="first",C="lineal",R="self";class K{#l;#c;#s;#h;#w;#r;#m;#e;#d;#k;#o;#f;#_;#t;#u;#b;#n;#p;#i;#a;constructor(l,e){this.#a=l,this.#r=e??l.document,this.#c=new WeakMap,this.#h=new WeakMap,this.#_=new WeakMap,this._initNwsapi()}_onError(l){if(!this.#k)if(l instanceof DOMException||l instanceof this.#a.DOMException)if(l.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw new this.#a.DOMException(l.message,l.name);else throw l}_setup(l,e,h={}){const{event:n,noexcept:a,warn:o}=h;return this.#k=!!a,this.#i=!!o,this.#m=this._setEvent(n),this.#e=e,[this.#s,this.#t,this.#n]=(0,_.resolveContent)(e),this.#u=(0,_.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(l),this.#p=new WeakMap,e}_initNwsapi(){return this.#o=(0,G.default)({DOMException:this.#a.DOMException,document:this.#r}),this.#o.configure({LOGERRORS:!1}),this.#o}_setEvent(l){return l instanceof this.#a.KeyboardEvent||l instanceof this.#a.MouseEvent?l:null}_correspond(l){const e=[];this.#w=!1;let h;if(this.#h.has(this.#s)){const n=this.#h.get(this.#s);if(n&&n.has(`${l}`)){const a=n.get(`${l}`);this.#w=a.descendant,h=a.ast}}if(h){const n=h.length;for(let a=0;a<n;a++)h[a].collected=!1,h[a].dir=null,h[a].filtered=!1,h[a].find=!1,e[a]=[]}else{let n;try{n=(0,y.parseSelector)(l)}catch(t){this._onError(t)}const{branches:a,info:{hasHasPseudoFunc:o,hasHyphenSepAttr:r}}=(0,y.walkAST)(n);let u;o||r?u=!1:u=!0;let d=!1,i=0;h=[];for(const[...t]of a){const s=[];let f=t.shift();if(f&&f.type!==c.COMBINATOR){const m=new Set;for(;f;){if(f.type===c.COMBINATOR){const[b]=t;if(b.type===c.COMBINATOR){const w=`Invalid selector ${l}`;throw new DOMException(w,c.SYNTAX_ERR)}const p=f.name;/^[\s>]$/.test(p)&&(d=!0),s.push({combo:f,leaves:(0,y.sortAST)(m)}),m.clear()}else if(f){let{name:b}=f;b&&typeof b=="string"&&(b=(0,y.unescapeSelector)(b),typeof b=="string"&&b!==f.name&&(f.name=b),/[|:]/.test(b)&&(f.namespace=!0)),m.add(f)}if(t.length)f=t.shift();else{s.push({combo:null,leaves:(0,y.sortAST)(m)}),m.clear();break}}}h.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[i]=[],i++}if(u){let t;this.#h.has(this.#s)?t=this.#h.get(this.#s):t=new Map,t.set(`${l}`,{ast:h,descendant:d}),this.#h.set(this.#s,t)}this.#w=d}return[h,e]}_createTreeWalker(l){let e;return this.#p.has(l)?e=this.#p.get(l):(e=this.#r.createTreeWalker(l,c.WALKER_FILTER),this.#p.set(l,e)),e}_prepareQuerySelectorWalker(){return this.#f=this._createTreeWalker(this.#e),this.#b=!1,this.#f}_collectNthChild(l,e,h){const{a:n,b:a,reverse:o,selector:r}=l,{parentNode:u}=e,d=new Set;let i;if(r)if(this.#c.has(r))i=this.#c.get(r);else{const{branches:t}=(0,y.walkAST)(r);i=t,this.#c.set(r,i)}if(u){const t=this.#n;let s=(0,_.traverseNode)(u,t);s=t.firstChild();let f=0;for(;s;)f++,s=t.nextSibling();s=(0,_.traverseNode)(u,t);const m=new Set;if(i)for(s=t.firstChild();s;){let b;for(const p of i)if(b=this._matchLeaves(p,s,h),!b)break;b&&m.add(s),s=t.nextSibling()}if(n===0){if(a>0&&a<=f){if(m.size){s=(0,_.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(m.has(s)){if(b===a-1){d.add(s);break}b++}o?s=t.previousSibling():s=t.nextSibling()}}else if(!r){s=(0,_.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(b===a-1){d.add(s);break}o?s=t.previousSibling():s=t.nextSibling(),b++}}}}else{let b=a-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<f){s=(0,_.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let p=0,w=n>0?0:a-1;for(;s&&(s&&b>=0&&b<f);)m.size?m.has(s)&&(w===b&&(d.add(s),b+=n),n>0?w++:w--):p===b&&(r||d.add(s),b+=n),o?s=t.previousSibling():s=t.nextSibling(),p++}}if(o&&d.size>1){const b=[...d];return new Set(b.reverse())}}else if(e===this.#t&&n+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(l,e){const{a:h,b:n,reverse:a}=l,{localName:o,parentNode:r,prefix:u}=e,d=new Set;if(r){const i=this.#n;let t=(0,_.traverseNode)(r,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(n>0&&n<=s){t=(0,_.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let f=0;for(;t;){const{localName:m,prefix:b}=t;if(m===o&&b===u){if(f===n-1){d.add(t);break}f++}a?t=i.previousSibling():t=i.nextSibling()}}}else{let f=n-1;if(h>0)for(;f<0;)f+=h;if(f>=0&&f<s){t=(0,_.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let m=h>0?0:n-1;for(;t;){const{localName:b,prefix:p}=t;if(b===o&&p===u){if(m===f&&(d.add(t),f+=h),f<0||f>=s)break;h>0?m++:m--}a?t=i.previousSibling():t=i.nextSibling()}}}if(a&&d.size>1){const f=[...d];return new Set(f.reverse())}}else e===this.#t&&h+n===1&&d.add(e);return d}_matchAnPlusB(l,e,h,n){const{nth:{a,b:o,name:r},selector:u}=l,d=new Map;if(r?(r==="even"?(d.set("a",2),d.set("b",0)):r==="odd"&&(d.set("a",2),d.set("b",1)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?d.set("b",o*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(l,e,h={}){let n;if(Array.isArray(l)&&l.length){const a=l.map(s=>s),[o]=a,{type:r}=o;let u;r===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:f}=s;if(f===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};h.dir=x;const t=this._matchCombinator(i,e,h);if(t.size)if(a.length){for(const s of t)if(n=this._matchHasPseudoFunc(a,s,h),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(l,e,h={}){const{astName:n="",branches:a=[],selector:o="",twigBranches:r=[]}=l;let u;if(n==="has")if(o.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(n);h.forgive=d;const i=r.length;let t;for(let s=0;s<i;s++){const f=r[s],m=f.length-1,{leaves:b}=f[m];if(t=this._matchLeaves(b,e,h),t&&m>0){let p=new Set([e]);for(let w=m-1;w>=0;w--){const k=f[w],N=[];h.dir=S;for(const A of p){const v=this._matchCombinator(k,A,h);v.size&&N.push(...v)}if(N.length)w===0?t=!0:p=new Set(N);else{t=!1;break}}}if(t)break}n==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(l,e,h={}){const{children:n,name:a}=l,{localName:o,parentNode:r}=e,{forgive:u,warn:d=this.#i}=h,i=new Set;if(c.REG_LOGICAL_PSEUDO.test(a)){let t;if(this.#c.has(l))t=this.#c.get(l);else{const{branches:f}=(0,y.walkAST)(l),m=[],b=[];for(const[...p]of f){for(const A of p){const v=(0,y.generateCSS)(A);m.push(v)}const w=[],k=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(w.push({combo:N,leaves:[...k]}),k.clear()):N&&k.add(N),p.length)N=p.shift();else{w.push({combo:null,leaves:[...k]}),k.clear();break}b.push(w)}t={astName:a,branches:f,twigBranches:b,selector:m.join(",")},this.#c.set(l,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=n;return this._matchAnPlusB(t,e,a,h)}else switch(a){case"dir":case"lang":{const t=O.matcher.matchSelector(l,e);t&&i.add(t);break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(!u){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.SYNTAX_ERR)}}else switch(a){case"any-link":case"link":{c.REG_ANCHOR.test(o)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(c.REG_ANCHOR.test(o)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:f}=new URL(this.#s.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===f&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#m??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:f}=this.#m??{};(f==="mousedown"||f==="pointerdown")&&t&c.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const s=t.replace(/^#/,"");let f=this.#s.getElementById(s);for(;f;){if(f===e){i.add(e);break}f=f.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#s.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#m??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(a==="focus"||s==="keydown"&&e.contains(t))){let f=e,m=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(f);if(m=!(b==="none"||p==="hidden"),!m)break}if(f.parentNode&&f.parentNode.nodeType===c.ELEMENT_NODE)f=f.parentNode;else break}m&&i.add(e)}break}case"focus-within":{let t,s=this.#s.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}if(t){let f=e,m=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(f);if(m=!(b==="none"||p==="hidden"),!m)break}if(f.parentNode&&f.parentNode.nodeType===c.ELEMENT_NODE)f=f.parentNode;else break}m&&i.add(e)}break}case"open":{c.REG_INTERACT.test(o)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{c.REG_INTERACT.test(o)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))if(e.disabled||e.hasAttribute("disabled"))i.add(e);else{let t=r;for(;t;){if(c.REG_FORM_GROUP.test(t.localName))if(t.localName==="fieldset"){if(t.disabled&&t.hasAttribute("disabled"))break}else break;t=t.parentNode}t&&r.localName!=="legend"&&(t.disabled||t.hasAttribute("disabled"))&&i.add(e)}break}case"enabled":{(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&i.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,_.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,_.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;o==="textarea"?s=e:o==="input"&&(e.hasAttribute("type")?c.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&o==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))i.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#s.documentElement);const f=s.getElementsByTagName("input"),m=f.length;let b;for(let p=0;p<m;p++){const w=f[p];if(w.getAttribute("type")==="radio"&&(t?w.getAttribute("name")===t&&(b=!!w.checked):w.hasAttribute("name")||(b=!!w.checked),b))break}b||i.add(e)}break}case"default":{if(o==="button"&&!(e.hasAttribute("type")&&c.REG_TYPE_RESET.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#n;let f=(0,_.traverseNode)(t,s);for(f=s.firstChild();f&&t.contains(f);){const m=f.localName;let b;if(m==="button"?b=!(f.hasAttribute("type")&&c.REG_TYPE_RESET.test(f.getAttribute("type"))):m==="input"&&(b=f.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(f.getAttribute("type"))),b){f===e&&i.add(e);break}f=s.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))i.add(e);else if(o==="option"){let t=r,s=!1;for(;t&&t.localName!=="datalist";){if(t.localName==="select"){(t.multiple||t.hasAttribute("multiple"))&&(s=!0);break}t=t.parentNode}if(s)(e.selected||e.hasAttribute("selected"))&&i.add(e);else{const f=new Set,m=this.#n;let b=(0,_.traverseNode)(r,m);for(b=m.firstChild();b;){if(b.selected||b.hasAttribute("selected")){f.add(b);break}b=m.nextSibling()}f.size&&f.has(e)&&i.add(e)}}break}case"valid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(o==="fieldset"){const t=this.#n;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(c.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f&&i.add(e)}break}case"invalid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(o==="fieldset"){const t=this.#n;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(c.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f||i.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||c.REG_TYPE_CHECK.test(s)||c.REG_TYPE_DATE.test(s)||c.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||c.REG_TYPE_CHECK.test(s)||c.REG_TYPE_DATE.test(s)||c.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#s.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#r.createTreeWalker(e,c.SHOW_ALL);let s=t.firstChild(),f;for(;s&&(f=s.nodeType!==c.ELEMENT_NODE&&s.nodeType!==c.TEXT_NODE,!!f);)s=t.nextSibling();f&&i.add(e)}else i.add(e);break}case"first-child":{(r&&e===r.firstElementChild||e===this.#t)&&i.add(e);break}case"last-child":{(r&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"only-child":{(r&&e===r.firstElementChild&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"first-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"last-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"only-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#t&&i.add(e);break}case"defined":{const t=e.getAttribute("is");t?(0,M.default)(t)&&this.#a.customElements.get(t)&&i.add(e):(0,M.default)(o)?this.#a.customElements.get(o)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#a.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(a.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${a}`;throw new DOMException(t,c.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(l,e){const{children:h,name:n}=l;let a;if(Array.isArray(h)){const{branches:o}=(0,y.walkAST)(h[0]),[r]=o,[...u]=r,{host:d}=e;if(n==="host"){let i;for(const t of u){const{type:s}=t;if(s===c.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(m,c.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:f}=s;if(f===c.COMBINATOR){const b=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(b,c.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(a=e)}}else if(n==="host")a=e;else{const o=`Invalid selector :${n}`;throw new DOMException(o,c.SYNTAX_ERR)}return a??null}_matchSelector(l,e,h){const{type:n}=l,a=new Set;if(l.name===c.EMPTY)return a;const o=(0,y.unescapeSelector)(l.name);if(typeof o=="string"&&o!==l.name&&(l.name=o),e.nodeType===c.ELEMENT_NODE)switch(n){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(o,h);break}case c.SELECTOR_ID:{e.id===o&&a.add(e);break}case c.SELECTOR_CLASS:{e.classList.contains(o)&&a.add(e);break}case c.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(l,e,h);default:{const r=O.matcher.matchSelector(l,e,h);r&&a.add(r)}}else if(this.#u&&n===c.SELECTOR_PSEUDO_CLASS&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&c.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(l,e,h);if(c.REG_SHADOW_HOST.test(o)){const r=this._matchShadowHostPseudoClass(l,e,h);r&&a.add(r)}}return a}_matchLeaves(l,e,h){const{attributes:n,localName:a,nodeType:o}=e;let r=this.#_.get(l),u;if(r&&r.has(e)){const{attr:d,matched:i}=r.get(e);n?.length===d&&(u=i)}if(typeof u!="boolean"){let d;o===c.ELEMENT_NODE&&c.REG_FORM.test(a)?d=!1:d=!0;for(const i of l){const{name:t,type:s}=i;if(s===c.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(d=!1),u=this._matchSelector(i,e,h).has(e),!u)break}d&&(r||(r=new WeakMap),r.set(e,{attr:n?.length,matched:u}),this.#_.set(l,r))}return!!u}_matchHTMLCollection(l,e={}){const{compound:h,filterLeaves:n}=e,a=new Set,o=l.length;if(o)if(h)for(let r=0;r<o;r++){const u=l[r];this._matchLeaves(n,u,e)&&a.add(u)}else{const r=[].slice.call(l);return new Set(r)}return a}_findDescendantNodes(l,e,h){const[n,...a]=l,o=a.length>0,{type:r}=n,u=(0,y.unescapeSelector)(n.name);typeof u=="string"&&u!==n.name&&(n.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(r){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,h);break}case c.SELECTOR_ID:{if(this.#t.nodeType===c.ELEMENT_NODE)i=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(o?this._matchLeaves(a,t,h)&&d.add(t):d.add(t))}break}case c.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:o,filterLeaves:a});break}case c.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:o,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(l,e,h={}){const{combo:n,leaves:a}=l,{name:o}=n,{parentNode:r}=e,{dir:u}=h,d=new Set;if(u===x)switch(o){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,_.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,_.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let f=(0,_.traverseNode)(e,s);for(f=s.nextNode();f&&e.contains(f);)this._matchLeaves(a,f,h)&&d.add(f),f=s.nextNode()}}}else switch(o){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,_.traverseNode)(r,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{r&&this._matchLeaves(a,r,h)&&d.add(r);break}case" ":default:{const i=[];let t=r;for(;t;)this._matchLeaves(a,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(l,e){const{node:h}=e;let n=(0,_.traverseNode)(h,this.#f),a;if(n)for(n.nodeType!==c.ELEMENT_NODE?n=this.#f.nextNode():n===h&&n!==this.#t&&(n=this.#f.nextNode());n;){if(this._matchLeaves(l,n,{warn:this.#i})){a=n;break}n=this.#f.nextNode()}return a??null}_matchSelf(l){const e=[],h=this._matchLeaves(l,this.#e,{warn:this.#i});let n=!1;return h&&(e.push(this.#e),n=!0),[e,n]}_findLineal(l,e={}){const{complex:h}=e,n=[];let a=this._matchLeaves(l,this.#e,{warn:this.#i}),o=!1;if(a&&(n.push(this.#e),o=!0),!a||h){let r=this.#e.parentNode;for(;r&&(a=this._matchLeaves(l,r,{warn:this.#i}),a&&(n.push(r),o=!0),r.parentNode);)r=r.parentNode}return[n,o]}_findFirst(l){const e=[],h=this._findNode(l,{node:this.#e});let n=!1;return h&&(e.push(h),n=!0),[e,n]}_findFromHTMLCollection(l,e={}){const{complex:h,compound:n,filterLeaves:a,targetType:o}=e;let r=[],u=!1,d=!1;const i=l.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<i;t++){const s=l[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(n){if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else if(r.push(s),u=!0,o===E)break}}else if(h)if(n)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else r=[].slice.call(l),u=!0,d=!0;else if(n)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else r=[].slice.call(l),u=!0,d=!0;return[r,u,d]}_findEntryNodes(l,e,h){const{leaves:n}=l,[a,...o]=n,r=o.length>0,{name:u,type:d}=a;let i=[],t=!1,s=!1,f=!1;switch(d){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{warn:this.#i});break}case c.SELECTOR_ID:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(e===E&&this.#t.nodeType!==c.ELEMENT_NODE){const m=this.#t.getElementById(u);m&&(r?this._matchLeaves(o,m,{warn:this.#i})&&(i.push(m),s=!0):(i.push(m),s=!0))}else e===E?[i,s]=this._findFirst(n):f=!0;break}case c.SELECTOR_CLASS:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(this.#t.nodeType===c.DOCUMENT_NODE){const m=this.#t.getElementsByClassName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:r,filterLeaves:o,targetType:e}))}else e===E?[i,s]=this._findFirst(n):f=!0;break}case c.SELECTOR_TYPE:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#t.getElementsByTagName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:r,filterLeaves:o,targetType:e}))}else e===E?[i,s]=this._findFirst(n):f=!0;break}default:if(e!==C&&c.REG_SHADOW_HOST.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(a,this.#e);m&&(i.push(m),s=!0)}}else e===R?[i,s]=this._matchSelf(n):e===C?[i,s]=this._findLineal(n,{complex:h}):e===E?[i,s]=this._findFirst(n):f=!0}return{collected:t,compound:r,filtered:s,nodes:i,pending:f}}_collectNodes(l){const e=this.#l.values();if(l===L||l===E){const h=new Set;let n=0;for(const{branch:a}of e){const o=a.length,r=o>1,u=a[0];let d,i;if(r){const{combo:p,leaves:[{name:w,type:k}]}=u,N=a[o-1],{leaves:[{name:A,type:v}]}=N;if(v===c.SELECTOR_PSEUDO_ELEMENT||v===c.SELECTOR_ID)d=S,i=N;else if(k===c.SELECTOR_PSEUDO_ELEMENT||k===c.SELECTOR_ID)d=x,i=u;else if(l===L)if(w==="*"&&k===c.SELECTOR_TYPE)d=S,i=N;else if(A==="*"&&v===c.SELECTOR_TYPE)d=x,i=u;else if(o===2){const{name:T}=p;/^[+~]$/.test(T)?(d=S,i=N):(d=x,i=u)}else d=x,i=u;else if(A==="*"&&v===c.SELECTOR_TYPE)d=x,i=u;else if(w==="*"&&k===c.SELECTOR_TYPE)d=S,i=N;else{let T;for(const{combo:D,leaves:[$]}of a){const{name:F,type:z}=$;if(z===c.SELECTOR_PSEUDO_CLASS&&F==="dir"){T=!1;break}if(!T&&D){const{name:H}=D;/^[+~]$/.test(H)&&(T=!0)}}T?(d=x,i=u):(d=S,i=N)}}else d=S,i=u;const{collected:t,compound:s,filtered:f,nodes:m,pending:b}=this._findEntryNodes(i,l,r);m.length?(this.#l[n].find=!0,this.#d[n]=m):b&&h.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=t,this.#l[n].dir=d,this.#l[n].filtered=f||!s,n++}if(h.size){let a,o;this.#e!==this.#t&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,o=this.#f):(a=this.#t,o=this.#n);let r=(0,_.traverseNode)(a,o);for(;r;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?r===this.#e?u=!0:u=this.#e.contains(r):u=!0,u)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,r,{warn:this.#i})){const s=d.get("index");this.#l[s].filtered=!0,this.#l[s].find=!0,this.#d[s].push(r)}}r!==o.currentNode&&(r=(0,_.traverseNode)(r,o)),r=o.nextNode()}}}else{let h=0;for(const{branch:n}of e){const a=n[n.length-1],o=n.length>1,{compound:r,filtered:u,nodes:d}=this._findEntryNodes(a,l,o);d.length&&(this.#l[h].find=!0,this.#d[h]=d),this.#l[h].dir=S,this.#l[h].filtered=u||!r,h++}}return[this.#l,this.#d]}_getCombinedNodes(l,e,h){const n=[];for(const a of e){const o=this._matchCombinator(l,a,{dir:h,warn:this.#i});o.size&&n.push(...o)}return n.length?new Set(n):new Set}_matchNodeNext(l,e,h){const{combo:n,index:a}=h,{combo:o,leaves:r}=l[a],u={combo:n,leaves:r},d=this._getCombinedNodes(u,e,x);let i;if(d.size)if(a===l.length-1){const[t]=(0,_.sortNodes)(d);i=t}else i=this._matchNodeNext(l,d,{combo:o,index:a+1});return i??null}_matchNodePrev(l,e,h){const{index:n}=h,a=l[n],o=new Set([e]),r=this._getCombinedNodes(a,o,S);let u;if(r.size){if(n===0)u=e;else for(const d of r)if(this._matchNodePrev(l,d,{index:n-1}))return e}return u??null}_find(l){(l===L||l===E)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(l),n=e.length;let a=new Set;for(let o=0;o<n;o++){const{branch:r,collected:u,dir:d,find:i}=e[o],t=r.length;if(t&&i){const s=h[o],f=s.length,m=t-1;if(m===0)if((l===L||l===E)&&this.#e.nodeType===c.ELEMENT_NODE)for(let b=0;b<f;b++){const p=s[b];if(p!==this.#e&&this.#e.contains(p)&&(a.add(p),l!==L))break}else if(l===L)if(a.size){const b=[...a];a=new Set([...b,...s]),this.#b=!0}else a=new Set(s);else{const[b]=s;a.add(b)}else if(l===L)if(d===x){let{combo:b}=r[0];for(const p of s){let w=new Set([p]);for(let k=1;k<t;k++){const{combo:N,leaves:A}=r[k],v={combo:b,leaves:A};if(w=this._getCombinedNodes(v,w,d),w.size)if(k===m)if(a.size){const T=[...a];a=new Set([...T,...w]),this.#b=!0}else a=w;else b=N;else break}}}else for(const b of s){let p=new Set([b]);for(let w=m-1;w>=0;w--){const k=r[w];if(p=this._getCombinedNodes(k,p,d),p.size)w===0&&(a.add(b),t>1&&a.size>1&&(this.#b=!0));else break}}else if(l===E&&d===x){const{combo:b}=r[0];let p;for(const w of s)if(p=this._matchNodeNext(r,new Set([w]),{combo:b,index:1}),p){a.add(p);break}if(!p&&!u){const{leaves:w}=r[0],[k]=s;let N=this._findNode(w,{node:k});for(;N;){if(p=this._matchNodeNext(r,new Set([N]),{combo:b,index:1}),p){a.add(p);break}N=this._findNode(w,{node:N})}}}else{let b;for(const p of s)if(b=this._matchNodePrev(r,p,{index:m-1}),b){a.add(p);break}if(!b&&!u&&l===E){const{leaves:p}=r[m],[w]=s;let k=this._findNode(p,{node:w});for(;k;){if(b=this._matchNodePrev(r,k,{index:m-1}),b){a.add(k);break}k=this._findNode(p,{node:k})}}}}}return a}matches(l,e,h){let n;try{if(e?.nodeType!==c.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_A.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#o.match(l,e)}this._setup(l,e,h),n=this._find(R).size}catch(a){this._onError(a)}return!!n}closest(l,e,h){let n;try{if(e?.nodeType!==c.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_A.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#o.closest(l,e)}this._setup(l,e,h);const o=this._find(C);if(o.size){let r=this.#e;for(;r;){if(o.has(r)){n=r;break}r=r.parentNode}}}catch(a){this._onError(a)}return n??null}querySelector(l,e,h){let n;try{(0,_.verifyNode)(e);let a;if(e.nodeType===c.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_B.test(l),descendant:!1};if((0,y.filterSelector)(l,r))return this.#o.first(l,e)}this._setup(l,e,h);const o=this._find(E);o.delete(this.#e),o.size&&([n]=(0,_.sortNodes)(o))}catch(a){this._onError(a)}return n??null}querySelectorAll(l,e,h){let n;try{(0,_.verifyNode)(e);let a;if(e.nodeType===c.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_B.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#o.select(l,e)}this._setup(l,e,h);const o=this._find(L);o.delete(this.#e),o.size&&(this.#b?n=(0,_.sortNodes)(o):n=[...o])}catch(a){this._onError(a)}return n??[]}}0&&(module.exports={Finder});
1
+ var z=Object.create;var M=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var Y=(g,l)=>{for(var e in l)M(g,e,{get:l[e],enumerable:!0})},D=(g,l,e,h)=>{if(l&&typeof l=="object"||typeof l=="function")for(let n of W(l))!j.call(g,n)&&n!==e&&M(g,n,{get:()=>l[n],enumerable:!(h=H(l,n))||h.enumerable});return g};var q=(g,l,e)=>(e=g!=null?z(B(g)):{},D(l||!g||!g.__esModule?M(e,"default",{value:g,enumerable:!0}):e,g)),V=g=>D(M({},"__esModule",{value:!0}),g);var K={};Y(K,{Finder:()=>X});module.exports=V(K);var I=q(require("@asamuzakjp/nwsapi"),1),_=require("./dom-util.js"),O=require("./matcher.js"),y=require("./parser.js"),c=require("./constant.js");const x="next",S="prev",L="all",E="first",C="lineal",R="self";class X{#a;#c;#s;#h;#w;#r;#m;#e;#d;#k;#f;#o;#_;#t;#u;#b;#n;#p;#i;#l;constructor(l,e){this.#l=l,this.#r=e??l.document,this.#c=new WeakMap,this.#h=new WeakMap,this.#_=new WeakMap,this._initNwsapi()}_onError(l){if(!this.#k)if(l instanceof DOMException||l instanceof this.#l.DOMException)if(l.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw new this.#l.DOMException(l.message,l.name);else throw l}_setup(l,e,h={}){const{event:n,noexcept:a,warn:f}=h;return this.#k=!!a,this.#i=!!f,this.#m=this._setEvent(n),this.#e=e,[this.#s,this.#t,this.#n]=(0,_.resolveContent)(e),this.#u=(0,_.isInShadowTree)(e),[this.#a,this.#d]=this._correspond(l),this.#p=new WeakMap,e}_initNwsapi(){return this.#f=(0,I.default)({DOMException:this.#l.DOMException,document:this.#r}),this.#f.configure({LOGERRORS:!1}),this.#f}_setEvent(l){return l instanceof this.#l.KeyboardEvent||l instanceof this.#l.MouseEvent?l:null}_correspond(l){const e=[];this.#w=!1;let h;if(this.#h.has(this.#s)){const n=this.#h.get(this.#s);if(n&&n.has(`${l}`)){const a=n.get(`${l}`);this.#w=a.descendant,h=a.ast}}if(h){const n=h.length;for(let a=0;a<n;a++)h[a].collected=!1,h[a].dir=null,h[a].filtered=!1,h[a].find=!1,e[a]=[]}else{let n;try{n=(0,y.parseSelector)(l)}catch(t){this._onError(t)}const{branches:a,info:{hasHasPseudoFunc:f,hasHyphenSepAttr:r}}=(0,y.walkAST)(n);let u;f||r?u=!1:u=!0;let d=!1,i=0;h=[];for(const[...t]of a){const s=[];let o=t.shift();if(o&&o.type!==c.COMBINATOR){const m=new Set;for(;o;){if(o.type===c.COMBINATOR){const[b]=t;if(b.type===c.COMBINATOR){const w=`Invalid selector ${l}`;throw new DOMException(w,c.SYNTAX_ERR)}const p=o.name;/^[\s>]$/.test(p)&&(d=!0),s.push({combo:o,leaves:(0,y.sortAST)(m)}),m.clear()}else if(o){let{name:b}=o;b&&typeof b=="string"&&(b=(0,y.unescapeSelector)(b),typeof b=="string"&&b!==o.name&&(o.name=b),/[|:]/.test(b)&&(o.namespace=!0)),m.add(o)}if(t.length)o=t.shift();else{s.push({combo:null,leaves:(0,y.sortAST)(m)}),m.clear();break}}}h.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[i]=[],i++}if(u){let t;this.#h.has(this.#s)?t=this.#h.get(this.#s):t=new Map,t.set(`${l}`,{ast:h,descendant:d}),this.#h.set(this.#s,t)}this.#w=d}return[h,e]}_createTreeWalker(l){let e;return this.#p.has(l)?e=this.#p.get(l):(e=this.#r.createTreeWalker(l,c.WALKER_FILTER),this.#p.set(l,e)),e}_prepareQuerySelectorWalker(){return this.#o=this._createTreeWalker(this.#e),this.#b=!1,this.#o}_collectNthChild(l,e,h){const{a:n,b:a,reverse:f,selector:r}=l,{parentNode:u}=e,d=new Set;let i;if(r)if(this.#c.has(r))i=this.#c.get(r);else{const{branches:t}=(0,y.walkAST)(r);i=t,this.#c.set(r,i)}if(u){const t=this.#n;let s=(0,_.traverseNode)(u,t);s=t.firstChild();let o=0;for(;s;)o++,s=t.nextSibling();s=(0,_.traverseNode)(u,t);const m=new Set;if(i)for(s=t.firstChild();s;){let b;for(const p of i)if(b=this._matchLeaves(p,s,h),!b)break;b&&m.add(s),s=t.nextSibling()}if(n===0){if(a>0&&a<=o){if(m.size){s=(0,_.traverseNode)(u,t),f?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(m.has(s)){if(b===a-1){d.add(s);break}b++}f?s=t.previousSibling():s=t.nextSibling()}}else if(!r){s=(0,_.traverseNode)(u,t),f?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(b===a-1){d.add(s);break}f?s=t.previousSibling():s=t.nextSibling(),b++}}}}else{let b=a-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<o){s=(0,_.traverseNode)(u,t),f?s=t.lastChild():s=t.firstChild();let p=0,w=n>0?0:a-1;for(;s&&(s&&b>=0&&b<o);)m.size?m.has(s)&&(w===b&&(d.add(s),b+=n),n>0?w++:w--):p===b&&(r||d.add(s),b+=n),f?s=t.previousSibling():s=t.nextSibling(),p++}}if(f&&d.size>1){const b=[...d];return new Set(b.reverse())}}else if(e===this.#t&&n+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(l,e){const{a:h,b:n,reverse:a}=l,{localName:f,parentNode:r,prefix:u}=e,d=new Set;if(r){const i=this.#n;let t=(0,_.traverseNode)(r,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(n>0&&n<=s){t=(0,_.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let o=0;for(;t;){const{localName:m,prefix:b}=t;if(m===f&&b===u){if(o===n-1){d.add(t);break}o++}a?t=i.previousSibling():t=i.nextSibling()}}}else{let o=n-1;if(h>0)for(;o<0;)o+=h;if(o>=0&&o<s){t=(0,_.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let m=h>0?0:n-1;for(;t;){const{localName:b,prefix:p}=t;if(b===f&&p===u){if(m===o&&(d.add(t),o+=h),o<0||o>=s)break;h>0?m++:m--}a?t=i.previousSibling():t=i.nextSibling()}}}if(a&&d.size>1){const o=[...d];return new Set(o.reverse())}}else e===this.#t&&h+n===1&&d.add(e);return d}_matchAnPlusB(l,e,h,n){const{nth:{a,b:f,name:r},selector:u}=l,d=new Map;if(r?(r==="even"?(d.set("a",2),d.set("b",0)):r==="odd"&&(d.set("a",2),d.set("b",1)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof f=="string"&&/-?\d+/.test(f)?d.set("b",f*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(l,e,h={}){let n;if(Array.isArray(l)&&l.length){const a=l.map(s=>s),[f]=a,{type:r}=f;let u;r===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:o}=s;if(o===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};h.dir=x;const t=this._matchCombinator(i,e,h);if(t.size)if(a.length){for(const s of t)if(n=this._matchHasPseudoFunc(a,s,h),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(l,e,h={}){const{astName:n="",branches:a=[],selector:f="",twigBranches:r=[]}=l;let u;if(n==="has")if(f.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(n);h.forgive=d;const i=r.length;let t;for(let s=0;s<i;s++){const o=r[s],m=o.length-1,{leaves:b}=o[m];if(t=this._matchLeaves(b,e,h),t&&m>0){let p=new Set([e]);for(let w=m-1;w>=0;w--){const k=o[w],N=[];h.dir=S;for(const A of p){const v=this._matchCombinator(k,A,h);v.size&&N.push(...v)}if(N.length)w===0?t=!0:p=new Set(N);else{t=!1;break}}}if(t)break}n==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(l,e,h={}){const{children:n,name:a}=l,{localName:f,parentNode:r}=e,{forgive:u,warn:d=this.#i}=h,i=new Set;if(c.REG_LOGICAL_PSEUDO.test(a)){let t;if(this.#c.has(l))t=this.#c.get(l);else{const{branches:o}=(0,y.walkAST)(l),m=[],b=[];for(const[...p]of o){for(const A of p){const v=(0,y.generateCSS)(A);m.push(v)}const w=[],k=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(w.push({combo:N,leaves:[...k]}),k.clear()):N&&k.add(N),p.length)N=p.shift();else{w.push({combo:null,leaves:[...k]}),k.clear();break}b.push(w)}t={astName:a,branches:o,twigBranches:b,selector:m.join(",")},this.#c.set(l,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=n;return this._matchAnPlusB(t,e,a,h)}else switch(a){case"dir":case"lang":{const t=O.matcher.matchSelector(l,e);t&&i.add(t);break}case"state":{if((0,_.isCustomElement)(e)){const[{value:t}]=n;t&&e[t]&&i.add(e)}break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(!u){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.SYNTAX_ERR)}}else switch(a){case"any-link":case"link":{c.REG_ANCHOR.test(f)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(c.REG_ANCHOR.test(f)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:o}=new URL(this.#s.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===o&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#m??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:o}=this.#m??{};(o==="mousedown"||o==="pointerdown")&&t&c.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const s=t.replace(/^#/,"");let o=this.#s.getElementById(s);for(;o;){if(o===e){i.add(e);break}o=o.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#s.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#m??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(a==="focus"||s==="keydown"&&e.contains(t))){let o=e,m=!0;for(;o;){if(o.disabled||o.hasAttribute("disabled")||o.hidden||o.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#l.getComputedStyle(o);if(m=!(b==="none"||p==="hidden"),!m)break}if(o.parentNode&&o.parentNode.nodeType===c.ELEMENT_NODE)o=o.parentNode;else break}m&&i.add(e)}break}case"focus-within":{let t,s=this.#s.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}if(t){let o=e,m=!0;for(;o;){if(o.disabled||o.hasAttribute("disabled")||o.hidden||o.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#l.getComputedStyle(o);if(m=!(b==="none"||p==="hidden"),!m)break}if(o.parentNode&&o.parentNode.nodeType===c.ELEMENT_NODE)o=o.parentNode;else break}m&&i.add(e)}break}case"open":{c.REG_INTERACT.test(f)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{c.REG_INTERACT.test(f)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(c.REG_FORM_CTRL.test(f)||(0,_.isCustomElement)(e,{formAssociated:!0}))if(e.disabled||e.hasAttribute("disabled"))i.add(e);else{let t=r;for(;t;){if(c.REG_FORM_GROUP.test(t.localName))if(t.localName==="fieldset"){if(t.disabled&&t.hasAttribute("disabled"))break}else break;t=t.parentNode}t&&r.localName!=="legend"&&(t.disabled||t.hasAttribute("disabled"))&&i.add(e)}break}case"enabled":{(c.REG_FORM_CTRL.test(f)||(0,_.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled"))&&i.add(e);break}case"read-only":{switch(f){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,_.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(f){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,_.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;f==="textarea"?s=e:f==="input"&&(e.hasAttribute("type")?c.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&f==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&f==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&f==="input"&&e.type==="checkbox"||f==="progress"&&!e.hasAttribute("value"))i.add(e);else if(f==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#s.documentElement);const o=s.getElementsByTagName("input"),m=o.length;let b;for(let p=0;p<m;p++){const w=o[p];if(w.getAttribute("type")==="radio"&&(t?w.getAttribute("name")===t&&(b=!!w.checked):w.hasAttribute("name")||(b=!!w.checked),b))break}b||i.add(e)}break}case"default":{if(f==="button"&&!(e.hasAttribute("type")&&c.REG_TYPE_RESET.test(e.getAttribute("type")))||f==="input"&&e.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#n;let o=(0,_.traverseNode)(t,s);for(o=s.firstChild();o&&t.contains(o);){const m=o.localName;let b;if(m==="button"?b=!(o.hasAttribute("type")&&c.REG_TYPE_RESET.test(o.getAttribute("type"))):m==="input"&&(b=o.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(o.getAttribute("type"))),b){o===e&&i.add(e);break}o=s.nextNode()}}}else if(f==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))i.add(e);else if(f==="option"){let t=r,s=!1;for(;t&&t.localName!=="datalist";){if(t.localName==="select"){(t.multiple||t.hasAttribute("multiple"))&&(s=!0);break}t=t.parentNode}if(s)(e.selected||e.hasAttribute("selected"))&&i.add(e);else{const o=new Set,m=this.#n;let b=(0,_.traverseNode)(r,m);for(b=m.firstChild();b;){if(b.selected||b.hasAttribute("selected")){o.add(b);break}b=m.nextSibling()}o.size&&o.has(e)&&i.add(e)}}break}case"valid":{if(c.REG_FORM_VALID.test(f))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(f==="fieldset"){const t=this.#n;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let o;if(!s)o=!0;else for(;s&&e.contains(s)&&!(c.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?o=s.maxLength>=s.value.length:o=!0:o=!1,!o));)s=t.nextNode();o&&i.add(e)}break}case"invalid":{if(c.REG_FORM_VALID.test(f))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(f==="fieldset"){const t=this.#n;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let o;if(!s)o=!0;else for(;s&&e.contains(s)&&!(c.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?o=s.maxLength>=s.value.length:o=!0:o=!1,!o));)s=t.nextNode();o||i.add(e)}break}case"in-range":{f==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{f==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(f))t=e;else if(f==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||c.REG_TYPE_CHECK.test(s)||c.REG_TYPE_DATE.test(s)||c.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(f))t=e;else if(f==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||c.REG_TYPE_CHECK.test(s)||c.REG_TYPE_DATE.test(s)||c.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#s.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#r.createTreeWalker(e,c.SHOW_ALL);let s=t.firstChild(),o;for(;s&&(o=s.nodeType!==c.ELEMENT_NODE&&s.nodeType!==c.TEXT_NODE,!!o);)s=t.nextSibling();o&&i.add(e)}else i.add(e);break}case"first-child":{(r&&e===r.firstElementChild||e===this.#t)&&i.add(e);break}case"last-child":{(r&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"only-child":{(r&&e===r.firstElementChild&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"first-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"last-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"only-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#t&&i.add(e);break}case"defined":{e.hasAttribute("is")||f.includes("-")?(0,_.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#l.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(a.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${a}`;throw new DOMException(t,c.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(l,e){const{children:h,name:n}=l;let a;if(Array.isArray(h)){const{branches:f}=(0,y.walkAST)(h[0]),[r]=f,[...u]=r,{host:d}=e;if(n==="host"){let i;for(const t of u){const{type:s}=t;if(s===c.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(m,c.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:o}=s;if(o===c.COMBINATOR){const b=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(b,c.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(a=e)}}else if(n==="host")a=e;else{const f=`Invalid selector :${n}`;throw new DOMException(f,c.SYNTAX_ERR)}return a??null}_matchSelector(l,e,h){const{type:n}=l,a=new Set;if(l.name===c.EMPTY)return a;const f=(0,y.unescapeSelector)(l.name);if(typeof f=="string"&&f!==l.name&&(l.name=f),e.nodeType===c.ELEMENT_NODE)switch(n){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(f,h);break}case c.SELECTOR_ID:{e.id===f&&a.add(e);break}case c.SELECTOR_CLASS:{e.classList.contains(f)&&a.add(e);break}case c.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(l,e,h);default:{const r=O.matcher.matchSelector(l,e,h);r&&a.add(r)}}else if(this.#u&&n===c.SELECTOR_PSEUDO_CLASS&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(f!=="has"&&c.REG_LOGICAL_PSEUDO.test(f))return this._matchPseudoClassSelector(l,e,h);if(c.REG_SHADOW_HOST.test(f)){const r=this._matchShadowHostPseudoClass(l,e,h);r&&a.add(r)}}return a}_matchLeaves(l,e,h){const{attributes:n,localName:a,nodeType:f}=e;let r=this.#_.get(l),u;if(r&&r.has(e)){const{attr:d,matched:i}=r.get(e);n?.length===d&&(u=i)}if(typeof u!="boolean"){let d;f===c.ELEMENT_NODE&&c.REG_FORM.test(a)?d=!1:d=!0;for(const i of l){const{name:t,type:s}=i;if(s===c.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(d=!1),u=this._matchSelector(i,e,h).has(e),!u)break}d&&(r||(r=new WeakMap),r.set(e,{attr:n?.length,matched:u}),this.#_.set(l,r))}return!!u}_matchHTMLCollection(l,e={}){const{compound:h,filterLeaves:n}=e,a=new Set,f=l.length;if(f)if(h)for(let r=0;r<f;r++){const u=l[r];this._matchLeaves(n,u,e)&&a.add(u)}else{const r=[].slice.call(l);return new Set(r)}return a}_findDescendantNodes(l,e,h){const[n,...a]=l,f=a.length>0,{type:r}=n,u=(0,y.unescapeSelector)(n.name);typeof u=="string"&&u!==n.name&&(n.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(r){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,h);break}case c.SELECTOR_ID:{if(this.#t.nodeType===c.ELEMENT_NODE)i=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(f?this._matchLeaves(a,t,h)&&d.add(t):d.add(t))}break}case c.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:f,filterLeaves:a});break}case c.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:f,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(l,e,h={}){const{combo:n,leaves:a}=l,{name:f}=n,{parentNode:r}=e,{dir:u}=h,d=new Set;if(u===x)switch(f){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,_.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,_.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let o=(0,_.traverseNode)(e,s);for(o=s.nextNode();o&&e.contains(o);)this._matchLeaves(a,o,h)&&d.add(o),o=s.nextNode()}}}else switch(f){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,_.traverseNode)(r,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{r&&this._matchLeaves(a,r,h)&&d.add(r);break}case" ":default:{const i=[];let t=r;for(;t;)this._matchLeaves(a,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(l,e){const{node:h}=e;let n=(0,_.traverseNode)(h,this.#o),a;if(n)for(n.nodeType!==c.ELEMENT_NODE?n=this.#o.nextNode():n===h&&n!==this.#t&&(n=this.#o.nextNode());n;){if(this._matchLeaves(l,n,{warn:this.#i})){a=n;break}n=this.#o.nextNode()}return a??null}_matchSelf(l){const e=[],h=this._matchLeaves(l,this.#e,{warn:this.#i});let n=!1;return h&&(e.push(this.#e),n=!0),[e,n]}_findLineal(l,e={}){const{complex:h}=e,n=[];let a=this._matchLeaves(l,this.#e,{warn:this.#i}),f=!1;if(a&&(n.push(this.#e),f=!0),!a||h){let r=this.#e.parentNode;for(;r&&(a=this._matchLeaves(l,r,{warn:this.#i}),a&&(n.push(r),f=!0),r.parentNode);)r=r.parentNode}return[n,f]}_findFirst(l){const e=[],h=this._findNode(l,{node:this.#e});let n=!1;return h&&(e.push(h),n=!0),[e,n]}_findFromHTMLCollection(l,e={}){const{complex:h,compound:n,filterLeaves:a,targetType:f}=e;let r=[],u=!1,d=!1;const i=l.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<i;t++){const s=l[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(n){if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,f===E))break}else if(r.push(s),u=!0,f===E)break}}else if(h)if(n)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,f===E))break}else r=[].slice.call(l),u=!0,d=!0;else if(n)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,f===E))break}else r=[].slice.call(l),u=!0,d=!0;return[r,u,d]}_findEntryNodes(l,e,h){const{leaves:n}=l,[a,...f]=n,r=f.length>0,{name:u,type:d}=a;let i=[],t=!1,s=!1,o=!1;switch(d){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{warn:this.#i});break}case c.SELECTOR_ID:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(e===E&&this.#t.nodeType!==c.ELEMENT_NODE){const m=this.#t.getElementById(u);m&&(r?this._matchLeaves(f,m,{warn:this.#i})&&(i.push(m),s=!0):(i.push(m),s=!0))}else e===E?[i,s]=this._findFirst(n):o=!0;break}case c.SELECTOR_CLASS:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(this.#t.nodeType===c.DOCUMENT_NODE){const m=this.#t.getElementsByClassName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:r,filterLeaves:f,targetType:e}))}else e===E?[i,s]=this._findFirst(n):o=!0;break}case c.SELECTOR_TYPE:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#t.getElementsByTagName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:r,filterLeaves:f,targetType:e}))}else e===E?[i,s]=this._findFirst(n):o=!0;break}default:if(e!==C&&c.REG_SHADOW_HOST.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(a,this.#e);m&&(i.push(m),s=!0)}}else e===R?[i,s]=this._matchSelf(n):e===C?[i,s]=this._findLineal(n,{complex:h}):e===E?[i,s]=this._findFirst(n):o=!0}return{collected:t,compound:r,filtered:s,nodes:i,pending:o}}_collectNodes(l){const e=this.#a.values();if(l===L||l===E){const h=new Set;let n=0;for(const{branch:a}of e){const f=a.length,r=f>1,u=a[0];let d,i;if(r){const{combo:p,leaves:[{name:w,type:k}]}=u,N=a[f-1],{leaves:[{name:A,type:v}]}=N;if(v===c.SELECTOR_PSEUDO_ELEMENT||v===c.SELECTOR_ID)d=S,i=N;else if(k===c.SELECTOR_PSEUDO_ELEMENT||k===c.SELECTOR_ID)d=x,i=u;else if(l===L)if(w==="*"&&k===c.SELECTOR_TYPE)d=S,i=N;else if(A==="*"&&v===c.SELECTOR_TYPE)d=x,i=u;else if(f===2){const{name:T}=p;/^[+~]$/.test(T)?(d=S,i=N):(d=x,i=u)}else d=x,i=u;else if(A==="*"&&v===c.SELECTOR_TYPE)d=x,i=u;else if(w==="*"&&k===c.SELECTOR_TYPE)d=S,i=N;else{let T;for(const{combo:P,leaves:[U]}of a){const{name:G,type:$}=U;if($===c.SELECTOR_PSEUDO_CLASS&&G==="dir"){T=!1;break}if(!T&&P){const{name:F}=P;/^[+~]$/.test(F)&&(T=!0)}}T?(d=x,i=u):(d=S,i=N)}}else d=S,i=u;const{collected:t,compound:s,filtered:o,nodes:m,pending:b}=this._findEntryNodes(i,l,r);m.length?(this.#a[n].find=!0,this.#d[n]=m):b&&h.add(new Map([["index",n],["twig",i]])),this.#a[n].collected=t,this.#a[n].dir=d,this.#a[n].filtered=o||!s,n++}if(h.size){let a,f;this.#e!==this.#t&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,f=this.#o):(a=this.#t,f=this.#n);let r=(0,_.traverseNode)(a,f);for(;r;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?r===this.#e?u=!0:u=this.#e.contains(r):u=!0,u)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,r,{warn:this.#i})){const s=d.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#d[s].push(r)}}r!==f.currentNode&&(r=(0,_.traverseNode)(r,f)),r=f.nextNode()}}}else{let h=0;for(const{branch:n}of e){const a=n[n.length-1],f=n.length>1,{compound:r,filtered:u,nodes:d}=this._findEntryNodes(a,l,f);d.length&&(this.#a[h].find=!0,this.#d[h]=d),this.#a[h].dir=S,this.#a[h].filtered=u||!r,h++}}return[this.#a,this.#d]}_getCombinedNodes(l,e,h){const n=[];for(const a of e){const f=this._matchCombinator(l,a,{dir:h,warn:this.#i});f.size&&n.push(...f)}return n.length?new Set(n):new Set}_matchNodeNext(l,e,h){const{combo:n,index:a}=h,{combo:f,leaves:r}=l[a],u={combo:n,leaves:r},d=this._getCombinedNodes(u,e,x);let i;if(d.size)if(a===l.length-1){const[t]=(0,_.sortNodes)(d);i=t}else i=this._matchNodeNext(l,d,{combo:f,index:a+1});return i??null}_matchNodePrev(l,e,h){const{index:n}=h,a=l[n],f=new Set([e]),r=this._getCombinedNodes(a,f,S);let u;if(r.size){if(n===0)u=e;else for(const d of r)if(this._matchNodePrev(l,d,{index:n-1}))return e}return u??null}_find(l){(l===L||l===E)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(l),n=e.length;let a=new Set;for(let f=0;f<n;f++){const{branch:r,collected:u,dir:d,find:i}=e[f],t=r.length;if(t&&i){const s=h[f],o=s.length,m=t-1;if(m===0)if((l===L||l===E)&&this.#e.nodeType===c.ELEMENT_NODE)for(let b=0;b<o;b++){const p=s[b];if(p!==this.#e&&this.#e.contains(p)&&(a.add(p),l!==L))break}else if(l===L)if(a.size){const b=[...a];a=new Set([...b,...s]),this.#b=!0}else a=new Set(s);else{const[b]=s;a.add(b)}else if(l===L)if(d===x){let{combo:b}=r[0];for(const p of s){let w=new Set([p]);for(let k=1;k<t;k++){const{combo:N,leaves:A}=r[k],v={combo:b,leaves:A};if(w=this._getCombinedNodes(v,w,d),w.size)if(k===m)if(a.size){const T=[...a];a=new Set([...T,...w]),this.#b=!0}else a=w;else b=N;else break}}}else for(const b of s){let p=new Set([b]);for(let w=m-1;w>=0;w--){const k=r[w];if(p=this._getCombinedNodes(k,p,d),p.size)w===0&&(a.add(b),t>1&&a.size>1&&(this.#b=!0));else break}}else if(l===E&&d===x){const{combo:b}=r[0];let p;for(const w of s)if(p=this._matchNodeNext(r,new Set([w]),{combo:b,index:1}),p){a.add(p);break}if(!p&&!u){const{leaves:w}=r[0],[k]=s;let N=this._findNode(w,{node:k});for(;N;){if(p=this._matchNodeNext(r,new Set([N]),{combo:b,index:1}),p){a.add(p);break}N=this._findNode(w,{node:N})}}}else{let b;for(const p of s)if(b=this._matchNodePrev(r,p,{index:m-1}),b){a.add(p);break}if(!b&&!u&&l===E){const{leaves:p}=r[m],[w]=s;let k=this._findNode(p,{node:w});for(;k;){if(b=this._matchNodePrev(r,k,{index:m-1}),b){a.add(k);break}k=this._findNode(p,{node:k})}}}}}return a}matches(l,e,h){let n;try{if(e?.nodeType!==c.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_A.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#f.match(l,e)}this._setup(l,e,h),n=this._find(R).size}catch(a){this._onError(a)}return!!n}closest(l,e,h){let n;try{if(e?.nodeType!==c.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_A.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#f.closest(l,e)}this._setup(l,e,h);const f=this._find(C);if(f.size){let r=this.#e;for(;r;){if(f.has(r)){n=r;break}r=r.parentNode}}}catch(a){this._onError(a)}return n??null}querySelector(l,e,h){let n;try{(0,_.verifyNode)(e);let a;if(e.nodeType===c.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_B.test(l),descendant:!1};if((0,y.filterSelector)(l,r))return this.#f.first(l,e)}this._setup(l,e,h);const f=this._find(E);f.delete(this.#e),f.size&&([n]=(0,_.sortNodes)(f))}catch(a){this._onError(a)}return n??null}querySelectorAll(l,e,h){let n;try{(0,_.verifyNode)(e);let a;if(e.nodeType===c.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_B.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#f.select(l,e)}this._setup(l,e,h);const f=this._find(L);f.delete(this.#e),f.size&&(this.#b?n=(0,_.sortNodes)(f):n=[...f])}catch(a){this._onError(a)}return n??[]}}0&&(module.exports={Finder});
2
2
  //# sourceMappingURL=finder.js.map