@asamuzakjp/dom-selector 6.2.2 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -23
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/js/constant.js +1 -1
- package/dist/cjs/js/constant.js.map +3 -3
- package/dist/cjs/js/finder.js +1 -1
- package/dist/cjs/js/finder.js.map +3 -3
- package/dist/cjs/js/utility.js +1 -1
- package/dist/cjs/js/utility.js.map +3 -3
- package/package.json +3 -3
- package/src/index.js +13 -4
- package/src/js/constant.js +1 -0
- package/src/js/finder.js +145 -319
- package/src/js/utility.js +12 -9
- package/types/js/constant.d.ts +1 -0
- package/types/js/finder.d.ts +1 -4
- package/types/js/utility.d.ts +1 -1
package/README.md
CHANGED
|
@@ -291,43 +291,47 @@ See [benchmark](https://github.com/asamuzaK/domSelector/actions/workflows/benchm
|
|
|
291
291
|
|
|
292
292
|
|Selector|jsdom v25.0.1 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|
|
|
293
293
|
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
|
|
294
|
-
|simple selector:<br>`matches('.content')`|
|
|
295
|
-
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|
|
|
296
|
-
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|
|
|
297
|
-
|compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|
|
|
298
|
-
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|
|
|
299
|
-
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|
|
|
300
|
-
|complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|
|
|
294
|
+
|simple selector:<br>`matches('.content')`|116,283 ops/sec ±6.10%|352,497 ops/sec ±2.07%|8,165 ops/sec ±0.82%|116,887 ops/sec ±0.60%|happydom is the fastest and 3.0 times faster than patched-jsdom. patched-jsdom is 1.0 times faster than jsdom.|
|
|
295
|
+
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|105,845 ops/sec ±1.79%|331,734 ops/sec ±4.02%|7,846 ops/sec ±0.97%|86,644 ops/sec ±0.19%|happydom is the fastest and 3.8 times faster than patched-jsdom. jsdom is 1.2 times faster than patched-jsdom.|
|
|
296
|
+
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|341,380 ops/sec ±2.72%|F|44,663 ops/sec ±1.77%|happydom is the fastest and 7.6 times faster than patched-jsdom.|
|
|
297
|
+
|compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|103,273 ops/sec ±0.35%|347,609 ops/sec ±0.57%|7,707 ops/sec ±0.73%|84,748 ops/sec ±0.66%|happydom is the fastest and 4.1 times faster than patched-jsdom. jsdom is 1.2 times faster than patched-jsdom.|
|
|
298
|
+
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|67,766 ops/sec ±0.51%|F|5,090 ops/sec ±0.91%|61,711 ops/sec ±0.48%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|
|
299
|
+
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|4,976 ops/sec ±0.59%|14,990 ops/sec ±1.10%|patched-jsdom is the fastest.|
|
|
300
|
+
|complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|95,327 ops/sec ±0.61%|F|5,312 ops/sec ±0.53%|85,778 ops/sec ±0.66%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|
|
301
|
+
|nested and chained :not() selector:<br>`matches('p:not(:is(:not(.content))):not(.foo)')`|F|F|4,819 ops/sec ±11.64%|83,653 ops/sec ±1.44%|patched-jsdom is the fastest.|
|
|
301
302
|
|
|
302
303
|
### closest()
|
|
303
304
|
|
|
304
305
|
|Selector|jsdom v25.0.1 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|
|
|
305
306
|
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
|
|
306
|
-
|simple selector:<br>`closest('.container')`|
|
|
307
|
-
|compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|
|
|
308
|
-
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|
|
|
309
|
-
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|
|
|
310
|
-
|complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|
|
|
307
|
+
|simple selector:<br>`closest('.container')`|91,669 ops/sec ±0.71%|250,234 ops/sec ±39.44%|8,164 ops/sec ±0.64%|89,613 ops/sec ±0.67%|happydom is the fastest and 2.8 times faster than patched-jsdom. jsdom is 1.0 times faster than patched-jsdom.|
|
|
308
|
+
|compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|64,840 ops/sec ±0.44%|F|7,587 ops/sec ±0.85%|56,065 ops/sec ±0.62%|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[id] .block.inner > .content')`|63,753 ops/sec ±0.35%|F|5,105 ops/sec ±0.33%|60,020 ops/sec ±0.95%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|
|
310
|
+
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|4,978 ops/sec ±0.76%|12,812 ops/sec ±0.63%|patched-jsdom is the fastest.|
|
|
311
|
+
|complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|73,570 ops/sec ±0.64%|297,918 ops/sec ±0.63%|5,296 ops/sec ±0.54%|71,004 ops/sec ±0.51%|happydom is the fastest and 4.2 times faster than patched-jsdom. jsdom is 1.0 times faster than patched-jsdom.|
|
|
312
|
+
|nested and chained :not() selector:<br>`closest('div:not(:is(:not(.container))):not(.box)')`|F|F|7,487 ops/sec ±0.87%|71,354 ops/sec ±0.77%|patched-jsdom is the fastest.|
|
|
311
313
|
|
|
312
314
|
### querySelector()
|
|
313
315
|
|
|
314
|
-
|Selector|jsdom v25.0.
|
|
316
|
+
|Selector|jsdom v25.0.1 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|
|
|
315
317
|
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
|
|
316
|
-
|simple selector:<br>`querySelector('.content')`|
|
|
317
|
-
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|
|
|
318
|
-
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|
|
|
319
|
-
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|1,
|
|
320
|
-
|complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|
|
|
318
|
+
|simple selector:<br>`querySelector('.content')`|22,631 ops/sec ±1.24%|188,606 ops/sec ±59.77%|9,588 ops/sec ±0.83%|76,778 ops/sec ±0.84%|happydom is the fastest and 2.5 times faster than patched-jsdom. patched-jsdom is 3.4 times faster than jsdom.|
|
|
319
|
+
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|8,735 ops/sec ±0.49%|328,299 ops/sec ±0.56%|9,302 ops/sec ±0.67%|36,679 ops/sec ±0.91%|happydom is the fastest and 9.0 times faster than patched-jsdom. patched-jsdom is 4.2 times faster than jsdom.|
|
|
320
|
+
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|199 ops/sec ±0.95%|F|1,220 ops/sec ±0.76%|609 ops/sec ±0.53%|linkedom is the fastest and 2.0 times faster than patched-jsdom. patched-jsdom is 3.1 times faster than jsdom.|
|
|
321
|
+
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|1,489 ops/sec ±0.58%|445 ops/sec ±0.55%|linkedom is the fastest and 3.3 times faster than patched-jsdom.|
|
|
322
|
+
|complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|2,980 ops/sec ±0.79%|F|8,954 ops/sec ±0.70%|71,533 ops/sec ±0.63%|patched-jsdom is the fastest. patched-jsdom is 24.0 times faster than jsdom.|
|
|
323
|
+
|nested and chained :not() selector:<br>`querySelector('p:not(:is(:not(.content))):not(.foo)')`|F|F|9,045 ops/sec ±0.74%|67,579 ops/sec ±0.63%|patched-jsdom is the fastest.|
|
|
321
324
|
|
|
322
325
|
### querySelectorAll()
|
|
323
326
|
|
|
324
327
|
|Selector|jsdom v25.0.1 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|
|
|
325
328
|
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
|
|
326
|
-
|simple selector:<br>`querySelectorAll('.content')`|
|
|
327
|
-
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|
|
|
328
|
-
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|
|
|
329
|
-
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|
|
|
330
|
-
|complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|
|
|
329
|
+
|simple selector:<br>`querySelectorAll('.content')`|1,309 ops/sec ±0.65%|490 ops/sec ±39.19%|1,094 ops/sec ±0.63%|1,316 ops/sec ±1.08%|patched-jsdom is the fastest. patched-jsdom is 1.0 times faster than jsdom.|
|
|
330
|
+
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|680 ops/sec ±0.58%|433 ops/sec ±46.81%|1,068 ops/sec ±0.70%|647 ops/sec ±0.61%|linkedom is the fastest and 1.7 times faster than patched-jsdom. jsdom is 1.1 times faster than patched-jsdom.|
|
|
331
|
+
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|182 ops/sec ±1.53%|F|389 ops/sec ±0.67%|198 ops/sec ±0.88%|linkedom is the fastest and 2.0 times faster than patched-jsdom. patched-jsdom is 1.1 times faster than jsdom.|
|
|
332
|
+
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|424 ops/sec ±0.45%|173 ops/sec ±0.45%|linkedom is the fastest and 2.4 times faster than patched-jsdom.|
|
|
333
|
+
|complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|267 ops/sec ±0.62%|F|467 ops/sec ±0.49%|829 ops/sec ±1.16%|patched-jsdom is the fastest. patched-jsdom is 3.1 times faster than jsdom.|
|
|
334
|
+
|nested and chained :not() selector:<br>`querySelectorAll('p:not(:is(:not(.content))):not(.foo)')`|F|F|1,151 ops/sec ±0.27%|1,338 ops/sec ±0.69%|patched-jsdom is the fastest.|
|
|
331
335
|
|
|
332
336
|
|
|
333
337
|
## Acknowledgments
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var f=Object.defineProperty;var
|
|
1
|
+
var f=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var d=(p,t)=>{for(var e in t)f(p,e,{get:t[e],enumerable:!0})},x=(p,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of u(t))!T.call(p,n)&&n!==e&&f(p,n,{get:()=>t[n],enumerable:!(i=a(t,n))||i.enumerable});return p};var D=p=>x(f({},"__esModule",{value:!0}),p);var w={};d(w,{DOMSelector:()=>$});module.exports=D(w);var y=require("./js/finder.js"),o=require("./js/utility.js"),r=require("./js/constant.js");/*!
|
|
2
2
|
* DOM Selector - A CSS selector engine.
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @copyright asamuzaK (Kazz)
|
|
5
5
|
* @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}
|
|
6
|
-
*/const E=new RegExp(`${
|
|
6
|
+
*/const E=new RegExp(`${r.COMPOUND_I}${r.COMBO}${r.COMPOUND_I}`,"i"),l=new RegExp(`${r.COMPOUND_I}${r.DESCEND}${r.COMPOUND_I}`,"i"),m=new RegExp(`^${r.ID_CLASS}$`);class ${#t;#s;#e;#r;constructor(t,e){this.#t=t,this.#s=e??t.document,this.#e=new y.Finder(t),this.#r=(0,o.initNwsapi)(t,e)}matches(t,e,i){if(e?.nodeType){if(e.nodeType!==r.ELEMENT_NODE){const s=new this.#t.TypeError(`Unexpected node ${e.nodeName}`);this.#e.onError(s,i)}}else{const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}const n=e.ownerDocument;if(n===this.#s&&n.contentType==="text/html"){const s={complex:E.test(t),compound:!1,descend:!1,simple:!1,target:r.TARGET_SELF};if((0,o.filterSelector)(t,s))try{return this.#r.match(t,e)}catch{}}let h;try{this.#e.setup(t,e,i),h=this.#e.find(r.TARGET_SELF).size}catch(s){this.#e.onError(s,i)}return!!h}closest(t,e,i){if(e?.nodeType){if(e.nodeType!==r.ELEMENT_NODE){const s=new this.#t.TypeError(`Unexpected node ${e.nodeName}`);this.#e.onError(s,i)}}else{const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}const n=e.ownerDocument;if(n===this.#s&&n.contentType==="text/html"){const s={complex:E.test(t),compound:!1,descend:!1,simple:!1,target:r.TARGET_LINEAL};if((0,o.filterSelector)(t,s))try{return this.#r.closest(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_LINEAL);if(s.size){let c=e;for(;c;){if(s.has(c)){h=c;break}c=c.parentNode}}}catch(s){this.#e.onError(s,i)}return h??null}querySelector(t,e,i){if(!e?.nodeType){const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}let n;if(e.nodeType===r.DOCUMENT_NODE?n=e:n=e.ownerDocument,n===this.#s&&n.contentType==="text/html"){const s={complex:!1,compound:!E.test(t),descend:l.test(t),simple:m.test(t),target:r.TARGET_FIRST};if((0,o.filterSelector)(t,s))try{return this.#r.first(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_FIRST);s.size&&([h]=s)}catch(s){this.#e.onError(s,i)}return h??null}querySelectorAll(t,e,i){if(!e?.nodeType){const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}let n;if(e.nodeType===r.DOCUMENT_NODE?n=e:n=e.ownerDocument,n===this.#s&&n.contentType==="text/html"){const s={complex:!1,compound:!1,descend:l.test(t),simple:m.test(t),target:r.TARGET_ALL};if((0,o.filterSelector)(t,s))try{return this.#r.select(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_ALL);s.size&&(h=[...s])}catch(s){this.#e.onError(s,i)}return h??[]}}0&&(module.exports={DOMSelector});
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.js"],
|
|
4
|
-
"sourcesContent": ["/*!\n * DOM Selector - A CSS selector engine.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Finder } from './js/finder.js';\nimport { filterSelector, getType, initNwsapi } from './js/utility.js';\n\n/* constants */\nimport {\n COMBO, COMPOUND_I, DESCEND, DOCUMENT_NODE, ELEMENT_NODE,
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,eAAAC,EAAAH,GAQA,IAAAI,EAAuB,0BACvBC,EAAoD,2BAGpDC,EAGO,4BAfP;AAAA;AAAA;AAAA;AAAA;AAAA,GAgBA,MAAMC,EAAc,IAAI,OAAO,GAAG,OAAK,GAAG,YAAU,GAAI,GAAG,
|
|
6
|
-
"names": ["src_exports", "__export", "DOMSelector", "__toCommonJS", "import_finder", "import_utility", "import_constant", "REG_COMPLEX", "REG_DESCEND", "#window", "#document", "#finder", "#nwsapi", "window", "document", "selector", "node", "opt", "e", "filterOpt", "res", "nodes", "refNode"]
|
|
4
|
+
"sourcesContent": ["/*!\n * DOM Selector - A CSS selector engine.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Finder } from './js/finder.js';\nimport { filterSelector, getType, initNwsapi } from './js/utility.js';\n\n/* constants */\nimport {\n COMBO, COMPOUND_I, DESCEND, DOCUMENT_NODE, ELEMENT_NODE, ID_CLASS,\n TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF\n} from './js/constant.js';\nconst REG_COMPLEX = new RegExp(`${COMPOUND_I}${COMBO}${COMPOUND_I}`, 'i');\nconst REG_DESCEND = new RegExp(`${COMPOUND_I}${DESCEND}${COMPOUND_I}`, 'i');\nconst REG_SIMPLE = new RegExp(`^${ID_CLASS}$`);\n\n/* DOMSelector */\nexport class DOMSelector {\n /* private fields */\n #window;\n #document;\n #finder;\n #nwsapi;\n\n /**\n * construct\n * @param {object} window - window\n * @param {object} document - document\n */\n constructor(window, document) {\n this.#window = window;\n this.#document = document ?? window.document;\n this.#finder = new Finder(window);\n this.#nwsapi = initNwsapi(window, document);\n }\n\n /**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const e = new this.#window.TypeError(`Unexpected node ${node.nodeName}`);\n this.#finder.onError(e, opt);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX.test(selector),\n compound: false,\n descend: false,\n simple: false,\n target: TARGET_SELF\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.match(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_SELF);\n res = nodes.size;\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const e = new this.#window.TypeError(`Unexpected node ${node.nodeName}`);\n this.#finder.onError(e, opt);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX.test(selector),\n compound: false,\n descend: false,\n simple: false,\n target: TARGET_LINEAL\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.closest(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n }\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: false,\n compound: !REG_COMPLEX.test(selector),\n descend: REG_DESCEND.test(selector),\n simple: REG_SIMPLE.test(selector),\n target: TARGET_FIRST\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.first(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_FIRST);\n if (nodes.size) {\n [res] = nodes;\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n }\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: false,\n compound: false,\n descend: REG_DESCEND.test(selector),\n simple: REG_SIMPLE.test(selector),\n target: TARGET_ALL\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.select(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_ALL);\n if (nodes.size) {\n res = [...nodes];\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? [];\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["src_exports", "__export", "DOMSelector", "__toCommonJS", "import_finder", "import_utility", "import_constant", "REG_COMPLEX", "REG_DESCEND", "REG_SIMPLE", "#window", "#document", "#finder", "#nwsapi", "window", "document", "selector", "node", "opt", "e", "filterOpt", "res", "nodes", "refNode"]
|
|
7
7
|
}
|
package/dist/cjs/js/constant.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var F=(o,t)=>{for(var n in t)p(o,n,{get:t[n],enumerable:!0})},M=(o,t,n,L)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of a(t))!i.call(o,r)&&r!==n&&p(o,r,{get:()=>t[r],enumerable:!(L=R(t,r))||L.enumerable});return o};var U=o=>M(p({},"__esModule",{value:!0}),o);var Yt={};F(Yt,{ALPHA_NUM:()=>I,ANB:()=>A,ATTR_SELECTOR:()=>b,BIT_01:()=>g,BIT_02:()=>Z,BIT_04:()=>v,BIT_08:()=>q,BIT_16:()=>J,BIT_32:()=>Q,BIT_FFFF:()=>V,CHILD_IDX:()=>C,CLASS_SELECTOR:()=>d,COMBINATOR:()=>G,COMBO:()=>T,COMPLEX:()=>_,COMPLEX_L:()=>S,COMPOUND:()=>c,COMPOUND_A:()=>O,COMPOUND_B:()=>N,COMPOUND_I:()=>$t,DESCEND:()=>Dt,DIGIT:()=>x,DOCUMENT_FRAGMENT_NODE:()=>pt,DOCUMENT_NODE:()=>xt,DOCUMENT_POSITION_CONTAINED_BY:()=>_t,DOCUMENT_POSITION_CONTAINS:()=>Tt,DOCUMENT_POSITION_PRECEDING:()=>Et,DUO:()=>tt,ELEMENT_NODE:()=>ct,HEX:()=>ot,HYPHEN:()=>et,IDENT:()=>Y,ID_CLASS:()=>Pt,ID_SELECTOR:()=>f,KEY_FORM_FOCUS:()=>it,KEY_INPUT_BUTTON:()=>Ft,KEY_INPUT_DATE:()=>P,KEY_INPUT_EDIT:()=>Mt,KEY_INPUT_LTR:()=>Ut,KEY_INPUT_TEXT:()=>$,KEY_LOGICAL:()=>bt,KEY_MODIFIER:()=>dt,KEY_SHADOW_HOST:()=>Gt,LANG_PART:()=>Ct,LOGICAL_COMPLEX:()=>Rt,LOGICAL_COMPOUND:()=>at,NESTED_LOGICAL_A:()=>l,NESTED_LOGICAL_B:()=>D,NOT_SUPPORTED_ERR:()=>m,NTH:()=>B,N_TH:()=>lt,OPERATOR:()=>h,PSEUDO_CLASS:()=>At,PS_CLASS_SELECTOR:()=>H,PS_ELEMENT_SELECTOR:()=>u,SELECTOR:()=>y,SHOW_ALL:()=>Ot,SHOW_DOCUMENT:()=>Nt,SHOW_DOCUMENT_FRAGMENT:()=>St,SHOW_ELEMENT:()=>Lt,STRING:()=>z,SUB_TYPE:()=>s,SYNTAX_ERR:()=>K,TAG_TYPE:()=>e,TAG_TYPE_I:()=>E,TARGET_ALL:()=>j,TARGET_FIRST:()=>k,TARGET_LINEAL:()=>w,TARGET_SELF:()=>X,TEXT_NODE:()=>nt,TYPE_FROM:()=>rt,TYPE_SELECTOR:()=>W,TYPE_TO:()=>st,WALKER_FILTER:()=>It});module.exports=U(Yt);const b="AttributeSelector",d="ClassSelector",G="Combinator",Y="Identifier",f="IdSelector",m="NotSupportedError",B="Nth",h="Operator",H="PseudoClassSelector",u="PseudoElementSelector",y="Selector",z="String",K="SyntaxError",j="all",k="first",w="lineal",X="self",W="TypeSelector",g=1,Z=2,v=4,q=8,J=16,Q=32,V=65535,tt=2,ot=16,et=45,rt=8,st=-1,ct=1,nt=3,xt=9,pt=11,Et=2,Tt=8,_t=16,Ot=4294967295,Nt=256,St=1024,Lt=1,It=1281,I="[A-Z\\d]+",C="(?:first|last|only)-(?:child|of-type)",x="(?:0|[1-9]\\d*)",Ct=`(?:-${I})*`,At=`(?:any-)?link|${C}|checked|empty|indeterminate|read-(?:only|write)|root|target`,A=`[+-]?(?:${x}n?|n)|(?:[+-]?${x})?n\\s*[+-]\\s*${x}`,lt=`nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${A})\\s*\\)`,s="\\[[^|\\]]+\\]|[#.:][\\w-]+",e="\\*|[A-Za-z][\\w-]*",E="\\*|[A-Z][\\w-]*",c=`(?:${e}|(?:${e})?(?:${s})+)`,T="\\s?[\\s>~+]\\s?",_=`${c}(?:${T}${c})*`,Dt="\\s?[\\s>]\\s?",Pt="[#.][\\w-]+",l=`:is\\(\\s*${c}(?:\\s*,\\s*${c})*\\s*\\)`,D=`:is\\(\\s*${_}(?:\\s*,\\s*${_})*\\s*\\)`,O=`(?:${e}|(?:${e})?(?:${s}|${l})+)`,N=`(?:${e}|(?:${e})?(?:${s}|${D})+)`,$t=`(?:${E}|(?:${E})?(?:${s})+)`,S=`${N}(?:${T}${N})*`,Rt=`(?:is|not)\\(\\s*${S}(?:\\s*,\\s*${S})*\\s*\\)`,at=`(?:is|not)\\(\\s*${O}(?:\\s*,\\s*${O})*\\s*\\)`,it=Object.freeze(["button","input","select","textarea"]),Ft=Object.freeze(["button","reset","submit"]),P=Object.freeze(["date","datetime-local","month","time","week"]),$=Object.freeze(["email","password","search","tel","text","url"]),Mt=Object.freeze([...P,...$,"number"]),Ut=Object.freeze(["checkbox","color","date","image","number","range","radio","time"]),bt=Object.freeze(["has","is","not","where"]),dt=Object.freeze(["Alt","AltGraph","CapsLock","Control","Fn","FnLock","Hyper","Meta","NumLock","ScrollLock","Shift","Super","Symbol","SymbolLock"]),Gt=Object.freeze(["host","host-context"]);0&&(module.exports={ALPHA_NUM,ANB,ATTR_SELECTOR,BIT_01,BIT_02,BIT_04,BIT_08,BIT_16,BIT_32,BIT_FFFF,CHILD_IDX,CLASS_SELECTOR,COMBINATOR,COMBO,COMPLEX,COMPLEX_L,COMPOUND,COMPOUND_A,COMPOUND_B,COMPOUND_I,DESCEND,DIGIT,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,DUO,ELEMENT_NODE,HEX,HYPHEN,IDENT,ID_CLASS,ID_SELECTOR,KEY_FORM_FOCUS,KEY_INPUT_BUTTON,KEY_INPUT_DATE,KEY_INPUT_EDIT,KEY_INPUT_LTR,KEY_INPUT_TEXT,KEY_LOGICAL,KEY_MODIFIER,KEY_SHADOW_HOST,LANG_PART,LOGICAL_COMPLEX,LOGICAL_COMPOUND,NESTED_LOGICAL_A,NESTED_LOGICAL_B,NOT_SUPPORTED_ERR,NTH,N_TH,OPERATOR,PSEUDO_CLASS,PS_CLASS_SELECTOR,PS_ELEMENT_SELECTOR,SELECTOR,SHOW_ALL,SHOW_DOCUMENT,SHOW_DOCUMENT_FRAGMENT,SHOW_ELEMENT,STRING,SUB_TYPE,SYNTAX_ERR,TAG_TYPE,TAG_TYPE_I,TARGET_ALL,TARGET_FIRST,TARGET_LINEAL,TARGET_SELF,TEXT_NODE,TYPE_FROM,TYPE_SELECTOR,TYPE_TO,WALKER_FILTER});
|
|
2
2
|
//# sourceMappingURL=constant.js.map
|
|
@@ -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 ATTR_SELECTOR = 'AttributeSelector';\nexport const CLASS_SELECTOR = 'ClassSelector';\nexport const COMBINATOR = 'Combinator';\nexport const IDENT = 'Identifier';\nexport const ID_SELECTOR = 'IdSelector';\nexport const NOT_SUPPORTED_ERR = 'NotSupportedError';\nexport const NTH = 'Nth';\nexport const OPERATOR = 'Operator';\nexport const PS_CLASS_SELECTOR = 'PseudoClassSelector';\nexport const PS_ELEMENT_SELECTOR = 'PseudoElementSelector';\nexport const SELECTOR = 'Selector';\nexport const STRING = 'String';\nexport const SYNTAX_ERR = 'SyntaxError';\nexport const TARGET_ALL = 'all';\nexport const TARGET_FIRST = 'first';\nexport const TARGET_LINEAL = 'lineal';\nexport const TARGET_SELF = 'self';\nexport const TYPE_SELECTOR = 'TypeSelector';\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 DUO = 2;\nexport const HEX = 16;\nexport const HYPHEN = 0x2D;\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_CLASS = `(?:any-)?link|${CHILD_IDX}|checked|empty|indeterminate|read-(?:only|write)|root|target`;\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-]*';\nexport const COMPOUND = `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE})+)`;\nexport const COMBO = '\\\\s?[\\\\s>~+]\\\\s?';\nexport const COMPLEX = `${COMPOUND}(?:${COMBO}${COMPOUND})*`;\nexport const DESCEND = '\\\\s?[\\\\s>]\\\\s?';\nexport const NESTED_LOGICAL_A =\n `:is\\\\(\\\\s*${COMPOUND}(?:\\\\s*,\\\\s*${COMPOUND})*\\\\s*\\\\)`;\nexport const NESTED_LOGICAL_B =\n `:is\\\\(\\\\s*${COMPLEX}(?:\\\\s*,\\\\s*${COMPLEX})*\\\\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_I =\n `(?:${TAG_TYPE_I}|(?:${TAG_TYPE_I})?(?:${SUB_TYPE})+)`;\nexport const COMPLEX_L = `${COMPOUND_B}(?:${COMBO}${COMPOUND_B})*`;\nexport const LOGICAL_COMPLEX =\n `(?:is|not)\\\\(\\\\s*${COMPLEX_L}(?:\\\\s*,\\\\s*${COMPLEX_L})*\\\\s*\\\\)`;\nexport const LOGICAL_COMPOUND =\n `(?:is|not)\\\\(\\\\s*${COMPOUND_A}(?:\\\\s*,\\\\s*${COMPOUND_A})*\\\\s*\\\\)`;\n\n/* array */\nexport const KEY_FORM_FOCUS =\n Object.freeze(['button', 'input', 'select', 'textarea']);\nexport const KEY_INPUT_BUTTON = Object.freeze(['button', 'reset', 'submit']);\nexport const KEY_INPUT_DATE =\n Object.freeze(['date', 'datetime-local', 'month', 'time', 'week']);\nexport const KEY_INPUT_TEXT =\n Object.freeze(['email', 'password', 'search', 'tel', 'text', 'url']);\nexport const KEY_INPUT_EDIT =\n Object.freeze([...KEY_INPUT_DATE, ...KEY_INPUT_TEXT, 'number']);\nexport const KEY_INPUT_LTR = Object.freeze([\n 'checkbox', 'color', 'date', 'image', 'number', 'range', 'radio', 'time'\n]);\nexport const KEY_LOGICAL = Object.freeze(['has', 'is', 'not', 'where']);\nexport const KEY_MODIFIER = Object.freeze([\n 'Alt', 'AltGraph', 'CapsLock', 'Control', 'Fn', 'FnLock', 'Hyper', 'Meta',\n 'NumLock', 'ScrollLock', 'Shift', 'Super', 'Symbol', 'SymbolLock'\n]);\nexport const KEY_SHADOW_HOST = Object.freeze(['host', 'host-context']);\n"],
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,eAAAE,EAAA,QAAAC,EAAA,kBAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,aAAAC,EAAA,cAAAC,EAAA,mBAAAC,EAAA,eAAAC,EAAA,UAAAC,EAAA,YAAAC,EAAA,cAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,eAAAC,GAAA,YAAAC,GAAA,UAAAC,EAAA,2BAAAC,GAAA,kBAAAC,GAAA,mCAAAC,GAAA,+BAAAC,GAAA,gCAAAC,GAAA,QAAAC,GAAA,iBAAAC,GAAA,QAAAC,GAAA,WAAAC,GAAA,UAAAC,EAAA,gBAAAC,EAAA,mBAAAC,GAAA,qBAAAC,GAAA,mBAAAC,EAAA,mBAAAC,GAAA,kBAAAC,GAAA,mBAAAC,EAAA,gBAAAC,GAAA,iBAAAC,GAAA,oBAAAC,GAAA,cAAAC,GAAA,oBAAAC,GAAA,qBAAAC,GAAA,qBAAAC,EAAA,qBAAAC,EAAA,sBAAAC,EAAA,QAAAC,EAAA,SAAAC,GAAA,aAAAC,EAAA,iBAAAC,GAAA,sBAAAC,EAAA,wBAAAC,EAAA,aAAAC,EAAA,aAAAC,GAAA,kBAAAC,GAAA,2BAAAC,GAAA,iBAAAC,GAAA,WAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,iBAAAC,EAAA,kBAAAC,EAAA,gBAAAC,EAAA,cAAAC,GAAA,cAAAC,GAAA,kBAAAC,EAAA,YAAAC,GAAA,kBAAAC,KAAA,eAAAC,
|
|
6
|
-
"names": ["constant_exports", "__export", "ALPHA_NUM", "ANB", "ATTR_SELECTOR", "BIT_01", "BIT_02", "BIT_04", "BIT_08", "BIT_16", "BIT_32", "BIT_FFFF", "CHILD_IDX", "CLASS_SELECTOR", "COMBINATOR", "COMBO", "COMPLEX", "COMPLEX_L", "COMPOUND", "COMPOUND_A", "COMPOUND_B", "COMPOUND_I", "DESCEND", "DIGIT", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_PRECEDING", "DUO", "ELEMENT_NODE", "HEX", "HYPHEN", "IDENT", "ID_SELECTOR", "KEY_FORM_FOCUS", "KEY_INPUT_BUTTON", "KEY_INPUT_DATE", "KEY_INPUT_EDIT", "KEY_INPUT_LTR", "KEY_INPUT_TEXT", "KEY_LOGICAL", "KEY_MODIFIER", "KEY_SHADOW_HOST", "LANG_PART", "LOGICAL_COMPLEX", "LOGICAL_COMPOUND", "NESTED_LOGICAL_A", "NESTED_LOGICAL_B", "NOT_SUPPORTED_ERR", "NTH", "N_TH", "OPERATOR", "PSEUDO_CLASS", "PS_CLASS_SELECTOR", "PS_ELEMENT_SELECTOR", "SELECTOR", "SHOW_ALL", "SHOW_DOCUMENT", "SHOW_DOCUMENT_FRAGMENT", "SHOW_ELEMENT", "STRING", "SUB_TYPE", "SYNTAX_ERR", "TAG_TYPE", "TAG_TYPE_I", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "TEXT_NODE", "TYPE_FROM", "TYPE_SELECTOR", "TYPE_TO", "WALKER_FILTER", "__toCommonJS"]
|
|
4
|
+
"sourcesContent": ["/**\n * constant.js\n */\n\n/* string */\nexport const ATTR_SELECTOR = 'AttributeSelector';\nexport const CLASS_SELECTOR = 'ClassSelector';\nexport const COMBINATOR = 'Combinator';\nexport const IDENT = 'Identifier';\nexport const ID_SELECTOR = 'IdSelector';\nexport const NOT_SUPPORTED_ERR = 'NotSupportedError';\nexport const NTH = 'Nth';\nexport const OPERATOR = 'Operator';\nexport const PS_CLASS_SELECTOR = 'PseudoClassSelector';\nexport const PS_ELEMENT_SELECTOR = 'PseudoElementSelector';\nexport const SELECTOR = 'Selector';\nexport const STRING = 'String';\nexport const SYNTAX_ERR = 'SyntaxError';\nexport const TARGET_ALL = 'all';\nexport const TARGET_FIRST = 'first';\nexport const TARGET_LINEAL = 'lineal';\nexport const TARGET_SELF = 'self';\nexport const TYPE_SELECTOR = 'TypeSelector';\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 DUO = 2;\nexport const HEX = 16;\nexport const HYPHEN = 0x2D;\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_CLASS = `(?:any-)?link|${CHILD_IDX}|checked|empty|indeterminate|read-(?:only|write)|root|target`;\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-]*';\nexport const COMPOUND = `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE})+)`;\nexport const COMBO = '\\\\s?[\\\\s>~+]\\\\s?';\nexport const COMPLEX = `${COMPOUND}(?:${COMBO}${COMPOUND})*`;\nexport const DESCEND = '\\\\s?[\\\\s>]\\\\s?';\nexport const ID_CLASS = '[#.][\\\\w-]+';\nexport const NESTED_LOGICAL_A =\n `:is\\\\(\\\\s*${COMPOUND}(?:\\\\s*,\\\\s*${COMPOUND})*\\\\s*\\\\)`;\nexport const NESTED_LOGICAL_B =\n `:is\\\\(\\\\s*${COMPLEX}(?:\\\\s*,\\\\s*${COMPLEX})*\\\\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_I =\n `(?:${TAG_TYPE_I}|(?:${TAG_TYPE_I})?(?:${SUB_TYPE})+)`;\nexport const COMPLEX_L = `${COMPOUND_B}(?:${COMBO}${COMPOUND_B})*`;\nexport const LOGICAL_COMPLEX =\n `(?:is|not)\\\\(\\\\s*${COMPLEX_L}(?:\\\\s*,\\\\s*${COMPLEX_L})*\\\\s*\\\\)`;\nexport const LOGICAL_COMPOUND =\n `(?:is|not)\\\\(\\\\s*${COMPOUND_A}(?:\\\\s*,\\\\s*${COMPOUND_A})*\\\\s*\\\\)`;\n\n/* array */\nexport const KEY_FORM_FOCUS =\n Object.freeze(['button', 'input', 'select', 'textarea']);\nexport const KEY_INPUT_BUTTON = Object.freeze(['button', 'reset', 'submit']);\nexport const KEY_INPUT_DATE =\n Object.freeze(['date', 'datetime-local', 'month', 'time', 'week']);\nexport const KEY_INPUT_TEXT =\n Object.freeze(['email', 'password', 'search', 'tel', 'text', 'url']);\nexport const KEY_INPUT_EDIT =\n Object.freeze([...KEY_INPUT_DATE, ...KEY_INPUT_TEXT, 'number']);\nexport const KEY_INPUT_LTR = Object.freeze([\n 'checkbox', 'color', 'date', 'image', 'number', 'range', 'radio', 'time'\n]);\nexport const KEY_LOGICAL = Object.freeze(['has', 'is', 'not', 'where']);\nexport const KEY_MODIFIER = Object.freeze([\n 'Alt', 'AltGraph', 'CapsLock', 'Control', 'Fn', 'FnLock', 'Hyper', 'Meta',\n 'NumLock', 'ScrollLock', 'Shift', 'Super', 'Symbol', 'SymbolLock'\n]);\nexport const KEY_SHADOW_HOST = Object.freeze(['host', 'host-context']);\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["constant_exports", "__export", "ALPHA_NUM", "ANB", "ATTR_SELECTOR", "BIT_01", "BIT_02", "BIT_04", "BIT_08", "BIT_16", "BIT_32", "BIT_FFFF", "CHILD_IDX", "CLASS_SELECTOR", "COMBINATOR", "COMBO", "COMPLEX", "COMPLEX_L", "COMPOUND", "COMPOUND_A", "COMPOUND_B", "COMPOUND_I", "DESCEND", "DIGIT", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_PRECEDING", "DUO", "ELEMENT_NODE", "HEX", "HYPHEN", "IDENT", "ID_CLASS", "ID_SELECTOR", "KEY_FORM_FOCUS", "KEY_INPUT_BUTTON", "KEY_INPUT_DATE", "KEY_INPUT_EDIT", "KEY_INPUT_LTR", "KEY_INPUT_TEXT", "KEY_LOGICAL", "KEY_MODIFIER", "KEY_SHADOW_HOST", "LANG_PART", "LOGICAL_COMPLEX", "LOGICAL_COMPOUND", "NESTED_LOGICAL_A", "NESTED_LOGICAL_B", "NOT_SUPPORTED_ERR", "NTH", "N_TH", "OPERATOR", "PSEUDO_CLASS", "PS_CLASS_SELECTOR", "PS_ELEMENT_SELECTOR", "SELECTOR", "SHOW_ALL", "SHOW_DOCUMENT", "SHOW_DOCUMENT_FRAGMENT", "SHOW_ELEMENT", "STRING", "SUB_TYPE", "SYNTAX_ERR", "TAG_TYPE", "TAG_TYPE_I", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "TEXT_NODE", "TYPE_FROM", "TYPE_SELECTOR", "TYPE_TO", "WALKER_FILTER", "__toCommonJS"]
|
|
7
7
|
}
|
package/dist/cjs/js/finder.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var A=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var F=(L,c)=>{for(var e in c)A(L,e,{get:c[e],enumerable:!0})},$=(L,c,e,o)=>{if(c&&typeof c=="object"||typeof c=="function")for(let a of P(c))!U.call(L,a)&&a!==e&&A(L,a,{get:()=>c[a],enumerable:!(o=D(c,a))||o.enumerable});return L};var W=L=>$(A({},"__esModule",{value:!0}),L);var H={};F(H,{Finder:()=>z});module.exports=W(H);var v=require("./matcher.js"),y=require("./parser.js"),N=require("./utility.js"),n=require("./constant.js");const E="next",S="prev";class z{#a;#r;#k;#t;#h;#c;#b;#o;#m;#n;#e;#u;#y;#p;#N;#s;#d;#_;#f;#w;#i;#l;constructor(c){this.#l=c,this.#r=new WeakMap,this.#h=new WeakMap,this.#m=new WeakMap,this.#N=new WeakMap,this.#c=null,this.#b=null,this.#n=null,this._registerEventListeners()}onError(c,e){if(!(e?.noexcept??this.#y))if(c instanceof DOMException||c instanceof this.#l.DOMException)if(c.name===n.NOT_SUPPORTED_ERR)this.#i&&console.warn(c.message);else throw new this.#l.DOMException(c.message,c.name);else throw c.name in this.#l?new this.#l[c.name](c.message):c}setup(c,e,o={}){const{noexcept:a,warn:l}=o;return this.#y=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#f,this.#d]=(0,N.resolveContent)(e),[this.#a,this.#u]=this._correspond(c),this.#m=new WeakMap,this.#w=new WeakMap,this.#_=null,this}_registerEventListeners(){const c={capture:!0,passive:!0},e=[],o=["focus","focusin"];for(const r of o)e.push(this.#l.addEventListener(r,f=>{this.#b=f},c));const a=["keydown","keyup"];for(const r of a)e.push(this.#l.addEventListener(r,f=>{const{key:u}=f;n.KEY_MODIFIER.includes(u)||(this.#c=f)},c));const l=["mouseover","mousedown","mouseup","click","mouseout"];for(const r of l)e.push(this.#l.addEventListener(r,f=>{this.#c=f},c));return e}_correspond(c){const e=[];this.#k=!1,this.#o=!1;let o;if(this.#h.has(this.#t)){const a=this.#h.get(this.#t);if(a&&a.has(`${c}`)){const l=a.get(`${c}`);o=l.ast,this.#k=l.descendant,this.#o=l.invalidate}}if(o){const a=o.length;for(let l=0;l<a;l++)o[l].collected=!1,o[l].dir=null,o[l].filtered=!1,o[l].find=!1,e[l]=[]}else{let a;try{a=(0,y.parseSelector)(c)}catch(m){this.onError(m)}const{branches:l,info:r}=(0,y.walkAST)(a),{hasHasPseudoFunc:f,hasLogicalPseudoFunc:u,hasNthChildOfSelector:h}=r;let i=f||!!(u&&h),t=!1,s=0;o=[];for(const[...m]of l){const b=[];let w=m.shift();if(w&&w.type!==n.COMBINATOR){const p=new Set;for(;w;){let k=w.name;if(w.type===n.COMBINATOR){const[_]=m;if(_.type===n.COMBINATOR)throw new DOMException(`Invalid selector ${c}`,n.SYNTAX_ERR);k==="+"||k==="~"?i=!0:t=!0,b.push({combo:w,leaves:(0,y.sortAST)(p)}),p.clear()}else w&&(k&&typeof k=="string"&&(k=(0,y.unescapeSelector)(k),typeof k=="string"&&k!==w.name&&(w.name=k),/[|:]/.test(k)&&(w.namespace=!0)),p.add(w));if(m.length)w=m.shift();else{b.push({combo:null,leaves:(0,y.sortAST)(p)}),p.clear();break}}}o.push({branch:b,collected:!1,dir:null,filtered:!1,find:!1}),e[s]=[],s++}let d;this.#h.has(this.#t)?d=this.#h.get(this.#t):d=new Map,d.set(`${c}`,{ast:o,descendant:t,invalidate:i}),this.#h.set(this.#t,d),this.#k=t,this.#o=i}return[o,e]}_createTreeWalker(c){let e;return this.#w.has(c)?e=this.#w.get(c):(e=this.#t.createTreeWalker(c,n.WALKER_FILTER),this.#w.set(c,e)),e}_prepareQuerySelectorWalker(){return this.#p=this._createTreeWalker(this.#e),this.#p}_collectNthChild(c,e,o){const{a,b:l,reverse:r,selector:f}=c,{parentNode:u}=e,h=new Set;let i;if(f){if(this.#r.has(f))i=this.#r.get(f);else{const{branches:s}=(0,y.walkAST)(f);i=s,this.#o||this.#r.set(f,i)}const{branches:t}=(0,y.walkAST)(f);i=t}if(u){const t=this.#f;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let d=0;for(;s;)d++,s=t.nextSibling();const m=new Set;if(i)for(s=(0,N.traverseNode)(u,t),s=t.firstChild();s;){if((0,N.isVisible)(s)){let b;for(const w of i)if(b=this._matchLeaves(w,s,o),!b)break;b&&m.add(s)}s=t.nextSibling()}if(a===0){if(l>0&&l<=d){if(m.size){s=(0,N.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(m.has(s)){if(b===l-1){h.add(s);break}b++}r?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,N.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(b===l-1){h.add(s);break}r?s=t.previousSibling():s=t.nextSibling(),b++}}}}else{let b=l-1;if(a>0)for(;b<0;)b+=a;if(b>=0&&b<d){s=(0,N.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let w=0,p=a>0?0:l-1;for(;s&&(s&&b>=0&&b<d);)m.size?m.has(s)&&(p===b&&(h.add(s),b+=a),a>0?p++:p--):w===b&&(f||h.add(s),b+=a),r?s=t.previousSibling():s=t.nextSibling(),w++}}if(r&&h.size>1){const b=[...h];return new Set(b.reverse())}}else if(e===this.#s&&a+l===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,o),t)break;t&&h.add(e)}else h.add(e);return h}_collectNthOfType(c,e){const{a:o,b:a,reverse:l}=c,{localName:r,namespaceURI:f,parentNode:u,prefix:h}=e,i=new Set;if(u){const t=this.#f;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let d=0;for(;s;)d++,s=t.nextSibling();if(o===0){if(a>0&&a<=d){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){const{localName:b,namespaceURI:w,prefix:p}=s;if(b===r&&p===h&&w===f){if(m===a-1){i.add(s);break}m++}l?s=t.previousSibling():s=t.nextSibling()}}}else{let m=a-1;if(o>0)for(;m<0;)m+=o;if(m>=0&&m<d){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let b=o>0?0:a-1;for(;s;){const{localName:w,namespaceURI:p,prefix:k}=s;if(w===r&&k===h&&p===f){if(b===m&&(i.add(s),m+=o),m<0||m>=d)break;o>0?b++:b--}l?s=t.previousSibling():s=t.nextSibling()}}}if(l&&i.size>1){const m=[...i];return new Set(m.reverse())}}else e===this.#s&&o+a===1&&i.add(e);return i}_matchAnPlusB(c,e,o,a){const{nth:{a:l,b:r,name:f},selector:u}=c,h=new Map;if(f?(f==="even"?(h.set("a",2),h.set("b",0)):f==="odd"&&(h.set("a",2),h.set("b",1)),o.indexOf("last")>-1&&h.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?h.set("a",l*1):h.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?h.set("b",r*1):h.set("b",0),o.indexOf("last")>-1&&h.set("reverse",!0)),o==="nth-child"||o==="nth-last-child"){u&&h.set("selector",u);const i=Object.fromEntries(h);return this._collectNthChild(i,e,a)}else if(o==="nth-of-type"||o==="nth-last-of-type"){const i=Object.fromEntries(h);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(c,e,o){if(Array.isArray(c)&&c.length){const a=[...c],[l]=a,{type:r}=l;let f;r===n.COMBINATOR?f=a.shift():f={name:" ",type:n.COMBINATOR};const u=[];for(;a.length;){const[t]=a,{type:s}=t;if(s===n.COMBINATOR)break;u.push(a.shift())}const h={combo:f,leaves:u};o.dir=E;const i=this._matchCombinator(h,e,o);if(i.size){if(a.length){let t=!1;for(const s of i)if(t=this._matchHasPseudoFunc(a,s,o),t)break;return t}return!0}}return!1}_matchLogicalPseudoFunc(c,e,o){const{astName:a,branches:l,twigBranches:r}=c,f=(o.isShadowRoot||this.#d)&&e.nodeType===n.DOCUMENT_FRAGMENT_NODE;if(a==="has"){let u;for(const h of l)if(u=this._matchHasPseudoFunc(h,e,o),u)break;if(u)if(f){if(this.#_)return e}else return e}else{if(f){let i;for(const t of l)if(t.length>1){i=!0;break}else if(a==="not"){const[{type:s}]=t;if(s!==n.PS_CLASS_SELECTOR){i=!0;break}}if(i)return null}o.forgive=a==="is"||a==="where";const u=r.length;let h;for(let i=0;i<u;i++){const t=r[i],s=t.length-1,{leaves:d}=t[s];if(h=this._matchLeaves(d,e,o),h&&s>0){let m=new Set([e]);for(let b=s-1;b>=0;b--){const w=t[b],p=[];o.dir=S;for(const k of m){const _=this._matchCombinator(w,k,o);_.size&&p.push(..._)}if(p.length)b===0?h=!0:m=new Set(p);else{h=!1;break}}}if(h)break}if(a==="not")return h?null:e;if(h)return e}return null}_matchPseudoClassSelector(c,e,o){const{children:a,name:l}=c,{localName:r,parentNode:f}=e,{forgive:u,warn:h=this.#i}=o,i=new Set;if(Array.isArray(a)&&n.KEY_LOGICAL.includes(l)){if(!a.length&&l!=="is"&&l!=="where"){const d=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}let t;if(this.#r.has(c))t=this.#r.get(c);else{const{branches:d}=(0,y.walkAST)(c);if(l==="has"){let m;for(const b of a){const w=(0,y.findAST)(b,p=>n.KEY_LOGICAL.includes(p.name)&&(0,y.findAST)(p,k=>k.name==="has")?p:null);if(w){const p=w.name;if(p==="is"||p==="where"){m=!0;break}else{const k=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${k}`,n.SYNTAX_ERR)}}}if(m)return i;t={astName:l,branches:d}}else{const m=[];for(const[...b]of d){const w=[],p=new Set;let k=b.shift();for(;k;)if(k.type===n.COMBINATOR?(w.push({combo:k,leaves:[...p]}),p.clear()):k&&p.add(k),b.length)k=b.shift();else{w.push({combo:null,leaves:[...p]}),p.clear();break}m.push(w)}t={astName:l,branches:d,twigBranches:m},this.#o||this.#r.set(c,t)}}const s=this._matchLogicalPseudoFunc(t,e,o);s&&i.add(s)}else if(Array.isArray(a))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){if(a.length!==1){const d=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}const[t]=a;return this._matchAnPlusB(t,e,l,o)}else switch(l){case"dir":{if(a.length!==1){const d=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}const[t]=a;(0,v.matchDirectionPseudoClass)(t,e)&&i.add(e);break}case"lang":{if(!a.length){const s=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${s}`,n.SYNTAX_ERR)}let t;for(const s of a)if(t=(0,v.matchLanguagePseudoClass)(s,e),t)break;t&&i.add(e);break}case"state":{if((0,N.isCustomElement)(e)){const[{value:t}]=a;if(t)if(e[t])i.add(e);else for(const s in e){const d=e[s];if(d instanceof this.#l.ElementInternals){d?.states?.has(t)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(h)throw new DOMException(`Unsupported pseudo-class :${l}()`,n.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(h)throw new DOMException(`Unknown pseudo-class :${l}()`,n.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${l}()`,n.SYNTAX_ERR)}else switch(l){case"any-link":case"link":{(r==="a"||r==="area")&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if((r==="a"||r==="area")&&e.hasAttribute("href")){const{href:t,origin:s,pathname:d}=new URL(this.#t.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===d&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#c??{};/^(?:click|mouse(?:down|over|up))$/.test(s)&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:d}=this.#c??{};d==="mousedown"&&t&n.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#t.URL);e.id&&t===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#t.URL);if(t){const s=t.replace(/^#/,"");let d=this.#t.getElementById(s);for(;d;){if(d===e){i.add(e);break}d=d.parentNode}}break}case"scope":{this.#e.nodeType===n.ELEMENT_NODE?!this.#d&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&(0,N.isFocusableArea)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&(0,N.isFocusableArea)(e)){let t;if((0,N.isFocusVisible)(e))t=!0;else if(this.#b){const{relatedTarget:s,target:d}=this.#b;if(d===e)if((0,N.isFocusVisible)(s))t=!0;else if(this.#c){const{key:m,target:b,type:w}=this.#c;b===s?(this.#n===null||d===this.#n)&&(t=!0):m==="Tab"?(w==="keydown"&&b!==e||w==="keyup"&&b===e)&&(b===d?(this.#n===null||b===this.#n&&s===null)&&(t=!0):t=!0):m&&(w==="keydown"||w==="keyup")&&b===e&&(t=!0)}else(s===null||s===this.#n)&&(t=!0)}t?(this.#n=e,i.add(e)):this.#n===e&&(this.#n=null)}break}case"focus-within":{let t,s=this.#t.activeElement;if((0,N.isFocusableArea)(s))for(;s;){if(s===e){t=!0;break}s=s.parentNode}t&&i.add(e);break}case"open":case"closed":{(r==="details"||r==="dialog")&&(e.hasAttribute("open")?l==="open"&&i.add(e):l==="closed"&&i.add(e));break}case"disabled":case"enabled":{if([...n.KEY_FORM_FOCUS,"fieldset","optgroup","option"].includes(r)||(0,N.isCustomElement)(e,{formAssociated:!0})){let s;if(e.disabled||e.hasAttribute("disabled"))s=!0;else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&(s=!0);else if(e.localName!=="optgroup"){let d=f;for(;d;)if(d.localName==="fieldset"&&(d.disabled||d.hasAttribute("disabled"))){const m=this.#f;let b=(0,N.traverseNode)(d,m);for(b=m.firstChild();b&&b.localName!=="legend";)b=m.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(d.localName==="form")break;if(d.parentNode?.nodeType===n.ELEMENT_NODE){if(d.parentNode.localName==="form")break;d=d.parentNode}else break}}s?l==="disabled"&&i.add(e):l==="enabled"&&i.add(e)}break}case"read-only":case"read-write":{let t,s;switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0;break}case"input":{(!e.type||n.KEY_INPUT_EDIT.includes(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0);break}default:(0,N.isContentEditable)(e)?s=!0:t=!0}t?l==="read-only"&&i.add(e):l==="read-write"&&s&&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;r==="textarea"?s=e:r==="input"&&(e.hasAttribute("type")?[...n.KEY_INPUT_TEXT,"number"].includes(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{const t=e.getAttribute("type");(e.checked&&r==="input"&&(t==="checkbox"||t==="radio")||e.selected&&r==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&r==="input"&&e.type==="checkbox"||r==="progress"&&!e.hasAttribute("value"))i.add(e);else if(r==="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.#t.documentElement);const d=s.getElementsByTagName("input"),m=d.length;let b;for(let w=0;w<m;w++){const p=d[w];if(p.getAttribute("type")==="radio"&&(t?p.getAttribute("name")===t&&(b=!!p.checked):p.hasAttribute("name")||(b=!!p.checked),b))break}b||i.add(e)}break}case"default":{const t=["checkbox","radio"],s=["button","reset"],d=["image","submit"],m=e.getAttribute("type");if(r==="button"&&!(e.hasAttribute("type")&&s.includes(m))||r==="input"&&e.hasAttribute("type")&&d.includes(m)){let b=e.parentNode;for(;b&&b.localName!=="form";)b=b.parentNode;if(b){const w=this.#f;let p=(0,N.traverseNode)(b,w);for(p=w.firstChild();p&&b.contains(p);){const k=p.localName,_=p.getAttribute("type");let g;if(k==="button"?g=!(p.hasAttribute("type")&&s.includes(_)):k==="input"&&(g=p.hasAttribute("type")&&d.includes(_)),g){p===e&&i.add(e);break}p=w.nextNode()}}}else(r==="input"&&e.hasAttribute("type")&&t.includes(m)&&e.hasAttribute("checked")||r==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":case"invalid":{const t=[...n.KEY_FORM_FOCUS,"form"];if(t.includes(r)){let s;e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&(s=!0):s=!0),s?l==="valid"&&i.add(e):l==="invalid"&&i.add(e)}else if(r==="fieldset"){const s=this.#f;let d=(0,N.traverseNode)(e,s);d=s.firstChild();let m;if(!d)m=!0;else for(;d&&e.contains(d)&&!(t.includes(d.localName)&&(d.checkValidity()?d.maxLength>=0?m=d.maxLength>=d.value.length:m=!0:m=!1,!m));)d=s.nextNode();m?l==="valid"&&i.add(e):l==="invalid"&&i.add(e)}break}case"in-range":case"out-of-range":{const t=[...n.KEY_INPUT_DATE,"number","range"],s=e.getAttribute("type");if(r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&t.includes(s)){const d=e.validity.rangeUnderflow||e.validity.rangeOverflow;(l==="out-of-range"&&d||l==="in-range"&&!d&&(e.hasAttribute("min")||e.hasAttribute("max")||s==="range"))&&i.add(e)}break}case"required":case"optional":{let t;if(r==="select"||r==="textarea")t=e;else if(r==="input")if(e.hasAttribute("type")){const s=[...n.KEY_INPUT_EDIT,"checkbox","file","radio"],d=e.getAttribute("type");s.includes(d)&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required")?l==="required"&&i.add(e):l==="optional"&&i.add(e));break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#t.createTreeWalker(e,n.SHOW_ALL);let s=t.firstChild(),d;for(;s&&(d=s.nodeType!==n.ELEMENT_NODE&&s.nodeType!==n.TEXT_NODE,!!d);)s=t.nextSibling();d&&i.add(e)}else i.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(f){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.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||r.includes("-")?(0,N.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,N.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(h)throw new DOMException(`Unsupported pseudo-element ::${l}`,n.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(h)throw new DOMException(`Unsupported pseudo-class :${l}`,n.NOT_SUPPORTED_ERR);break}default:if(l.startsWith("-webkit-")){if(h)throw new DOMException(`Unsupported pseudo-class :${l}`,n.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${l}`,n.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(c,e){const{children:o,name:a}=c;if(Array.isArray(o)){if(o.length!==1){const h=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${h}`,n.SYNTAX_ERR)}const{branches:l}=(0,y.walkAST)(o[0]),[r]=l,[...f]=r,{host:u}=e;if(a==="host"){let h;for(const i of f){const{type:t}=i;if(t===n.COMBINATOR){const s=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${s}`,n.SYNTAX_ERR)}if(h=this._matchSelector(i,u).has(u),!h)break}return h?e:null}else if(a==="host-context"){let h=u,i;for(;h;){for(const t of f){const{type:s}=t;if(s===n.COMBINATOR){const d=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}if(i=this._matchSelector(t,h).has(h),!i)break}if(i)break;h=h.parentNode}return i?e:null}throw new DOMException(`Invalid selector :${a}`,n.SYNTAX_ERR)}else{if(a==="host")return e;throw new DOMException(`Invalid selector :${a}`,n.SYNTAX_ERR)}}_matchSelector(c,e,o={}){const{type:a}=c,l=(0,y.unescapeSelector)(c.name),r=new Set;if(e.nodeType===n.ELEMENT_NODE)switch(a){case n.ATTR_SELECTOR:{(0,v.matchAttributeSelector)(c,e)&&r.add(e);break}case n.ID_SELECTOR:{e.id===l&&r.add(e);break}case n.CLASS_SELECTOR:{e.classList.contains(l)&&r.add(e);break}case n.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(c,e,o);case n.TYPE_SELECTOR:{(0,v.matchTypeSelector)(c,e,o)&&r.add(e);break}case n.PS_ELEMENT_SELECTOR:default:(0,v.matchPseudoElementSelector)(l,a,o)}else if(this.#d&&a===n.PS_CLASS_SELECTOR&&e.nodeType===n.DOCUMENT_FRAGMENT_NODE){if(n.KEY_LOGICAL.includes(l))return o.isShadowRoot=!0,this._matchPseudoClassSelector(c,e,o);if(l==="host"||l==="host-context"){const f=this._matchShadowHostPseudoClass(c,e,o);f&&(this.#_=!0,r.add(f))}}return r}_matchLeaves(c,e,o){let a;if(this.#o?a=this.#m.get(c):a=this.#N.get(c),a&&a.has(e)){const{matched:l}=a.get(e);return l}else{let l=!0;const r=[...n.KEY_FORM_FOCUS,"fieldset","form"],f=["any-link","defined","dir","link"];e.nodeType===n.ELEMENT_NODE&&r.includes(e.localName)&&(l=!1);let u;for(const h of c){switch(h.type){case n.ATTR_SELECTOR:case n.ID_SELECTOR:{l=!1;break}case n.PS_CLASS_SELECTOR:{f.includes(h.name)&&(l=!1);break}default:}if(u=this._matchSelector(h,e,o).has(e),!u)break}return l&&(a||(a=new WeakMap),a.set(e,{matched:u}),this.#o?this.#m.set(c,a):this.#N.set(c,a)),u}}_matchHTMLCollection(c,e){if(c.length){const{compound:o,filterLeaves:a}=e;if(o){const l=new Set;for(const r of c)this._matchLeaves(a,r,e)&&l.add(r);return l}else{const l=[].slice.call(c);return new Set(l)}}return new Set}_findDescendantNodes(c,e,o){const[a,...l]=c,r=l.length>0,{type:f}=a,u=(0,y.unescapeSelector)(a.name);let h=new Set,i=!1;if(this.#d||e.nodeType!==n.ELEMENT_NODE)i=!0;else switch(f){case n.PS_ELEMENT_SELECTOR:{(0,v.matchPseudoElementSelector)(u,f,o);break}case n.ID_SELECTOR:{if(this.#s.nodeType===n.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(u);t&&t!==e&&e.contains(t)&&(r?this._matchLeaves(l,t,o)&&h.add(t):h.add(t))}break}case n.CLASS_SELECTOR:{const t=e.getElementsByClassName(u);h=this._matchHTMLCollection(t,{compound:r,filterLeaves:l});break}case n.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);h=this._matchHTMLCollection(t,{compound:r,filterLeaves:l})}else i=!0;break}default:i=!0}return{nodes:h,pending:i}}_matchCombinator(c,e,o){const{combo:a,leaves:l}=c,{name:r}=a,{parentNode:f}=e,{dir:u}=o,h=new Set;if(u===E)switch(r){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(l,i,o)&&h.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(l,t,o)&&h.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,N.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(l,t,o)&&h.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(l,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let d=(0,N.traverseNode)(e,s);for(d=s.nextNode();d&&e.contains(d);)this._matchLeaves(l,d,o)&&h.add(d),d=s.nextNode()}}}else switch(r){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(l,i,o)&&h.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(l,t,o)&&h.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(l,f,o)&&h.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(l,t,o)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return h}_findNode(c,e){const o=this.#p;let a=(0,N.traverseNode)(e,o),l;if(a)for((a.nodeType!==n.ELEMENT_NODE||a===e&&a!==this.#s)&&(a=o.nextNode());a;){if(this._matchLeaves(c,a,{warn:this.#i})){l=a;break}a=o.nextNode()}return l??null}_matchSelf(c){const e=[];let o=!1;return this._matchLeaves(c,this.#e,{warn:this.#i})&&(e.push(this.#e),o=!0),[e,o]}_findLineal(c,e){const{complex:o}=e,a=[];let l=!1,r=this._matchLeaves(c,this.#e,{warn:this.#i});if(r&&(a.push(this.#e),l=!0),!r||o){let f=this.#e.parentNode;for(;f&&(r=this._matchLeaves(c,f,{warn:this.#i}),r&&(a.push(f),l=!0),f.parentNode);)f=f.parentNode}return[a,l]}_findFirst(c){const e=[];let o=!1;const a=this._findNode(c,this.#e);return a&&(e.push(a),o=!0),[e,o]}_findFromHTMLCollection(c,e){const{complex:o,compound:a,filterLeaves:l,targetType:r}=e;let f=[],u=!1,h=!1;if(c.length)if(this.#e.nodeType===n.ELEMENT_NODE){for(const i of c)if(i!==this.#e&&(this.#e.contains(i)||i.contains(this.#e))){if(a){if(this._matchLeaves(l,i,{warn:this.#i})&&(f.push(i),u=!0,r===n.TARGET_FIRST))break}else if(f.push(i),u=!0,r===n.TARGET_FIRST)break}}else if(o)if(a){for(const i of c)if(this._matchLeaves(l,i,{warn:this.#i})&&(f.push(i),u=!0,r===n.TARGET_FIRST))break}else f=[].slice.call(c),u=!0,h=!0;else if(a){for(const i of c)if(this._matchLeaves(l,i,{warn:this.#i})&&(f.push(i),u=!0,r===n.TARGET_FIRST))break}else f=[].slice.call(c),u=!0,h=!0;return[f,u,h]}_findEntryNodes(c,e,o){const{leaves:a}=c,[l,...r]=a,f=r.length>0,{name:u,type:h}=l;let i=[],t=!1,s=!1,d=!1;switch(h){case n.PS_ELEMENT_SELECTOR:{(0,v.matchPseudoElementSelector)(u,h,{warn:this.#i});break}case n.ID_SELECTOR:{if(e===n.TARGET_SELF)[i,s]=this._matchSelf(a);else if(e===n.TARGET_LINEAL)[i,s]=this._findLineal(a,{complex:o});else if(e===n.TARGET_FIRST&&this.#s.nodeType!==n.ELEMENT_NODE){const m=this.#s.getElementById(u);m&&(f?this._matchLeaves(r,m,{warn:this.#i})&&(i.push(m),s=!0):(i.push(m),s=!0))}else e===n.TARGET_FIRST?[i,s]=this._findFirst(a):d=!0;break}case n.CLASS_SELECTOR:{if(e===n.TARGET_SELF)[i,s]=this._matchSelf(a);else if(e===n.TARGET_LINEAL)[i,s]=this._findLineal(a,{complex:o});else if(this.#s.nodeType===n.DOCUMENT_NODE){const m=this.#s.getElementsByClassName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:o,compound:f,filterLeaves:r,targetType:e}))}else e===n.TARGET_FIRST?[i,s]=this._findFirst(a):d=!0;break}case n.TYPE_SELECTOR:{if(e===n.TARGET_SELF)[i,s]=this._matchSelf(a);else if(e===n.TARGET_LINEAL)[i,s]=this._findLineal(a,{complex:o});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===n.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#s.getElementsByTagName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:o,compound:f,filterLeaves:r,targetType:e}))}else e===n.TARGET_FIRST?[i,s]=this._findFirst(a):d=!0;break}default:if(e!==n.TARGET_LINEAL&&(u==="host"||u==="host-context")){let m;if(this.#d&&this.#e.nodeType===n.DOCUMENT_FRAGMENT_NODE?m=this._matchShadowHostPseudoClass(l,this.#e):f&&this.#e.nodeType===n.ELEMENT_NODE&&(m=this._matchShadowHostPseudoClass(l,this.#e.shadowRoot)),m){let b;if(f){for(const w of r)if(/^host(?:-context)?$/.test(w.name)?b=this._matchShadowHostPseudoClass(w,m)===m:w.name==="has"?b=this._matchPseudoClassSelector(w,m,{}).has(m):b=!1,!b)break}else b=!0;b&&(i.push(m),s=!0)}}else e===n.TARGET_SELF?[i,s]=this._matchSelf(a):e===n.TARGET_LINEAL?[i,s]=this._findLineal(a,{complex:o}):e===n.TARGET_FIRST?[i,s]=this._findFirst(a):d=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:d}}_collectNodes(c){const e=this.#a.values();if(c===n.TARGET_ALL||c===n.TARGET_FIRST){const o=new Set;let a=0;for(const{branch:l}of e){const r=l.length,f=r>1,u=l[0];let h,i;if(f){const{combo:w,leaves:[{name:p,type:k}]}=u,_=l[r-1],{leaves:[{name:g,type:T}]}=_;if(T===n.PS_ELEMENT_SELECTOR||T===n.ID_SELECTOR)h=S,i=_;else if(k===n.PS_ELEMENT_SELECTOR||k===n.ID_SELECTOR)h=E,i=u;else if(c===n.TARGET_ALL)if(p==="*"&&k===n.TYPE_SELECTOR)h=S,i=_;else if(g==="*"&&T===n.TYPE_SELECTOR)h=E,i=u;else if(r===2){const{name:x}=w;x==="+"||x==="~"?(h=S,i=_):(h=E,i=u)}else h=E,i=u;else if(p==="*"&&k===n.TYPE_SELECTOR)h=S,i=_;else if(g==="*"&&T===n.TYPE_SELECTOR)h=E,i=u;else{let x;for(const{combo:C,leaves:[M]}of l){const{name:R,type:I}=M;if(I===n.PS_CLASS_SELECTOR&&R==="dir"){x=!1;break}if(!x&&C){const{name:O}=C;(O==="+"||O==="~")&&(x=!0)}}x?(h=E,i=u):(h=S,i=_)}}else h=S,i=u;const{collected:t,compound:s,filtered:d,nodes:m,pending:b}=this._findEntryNodes(i,c,f);m.length?(this.#a[a].find=!0,this.#u[a]=m):b&&o.add(new Map([["index",a],["twig",i]])),this.#a[a].collected=t,this.#a[a].dir=h,this.#a[a].filtered=d||!s,a++}if(o.size){let l,r;this.#e!==this.#s&&this.#e.nodeType===n.ELEMENT_NODE?(l=this.#e,r=this.#p):(l=this.#s,r=this.#f);let f=(0,N.traverseNode)(l,r);for(;f;){let u=!1;if(this.#e.nodeType===n.ELEMENT_NODE?f===this.#e?u=!0:u=this.#e.contains(f):u=!0,u)for(const h of o){const{leaves:i}=h.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=h.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#u[s].push(f)}}f!==r.currentNode&&(f=(0,N.traverseNode)(f,r)),f=r.nextNode()}}}else{let o=0;for(const{branch:a}of e){const l=a[a.length-1],r=a.length>1,{compound:f,filtered:u,nodes:h}=this._findEntryNodes(l,c,r);h.length&&(this.#a[o].find=!0,this.#u[o]=h),this.#a[o].dir=S,this.#a[o].filtered=u||!f,o++}}return[this.#a,this.#u]}_getCombinedNodes(c,e,o){const a=[];for(const l of e){const r=this._matchCombinator(c,l,{dir:o,warn:this.#i});r.size&&a.push(...r)}return a.length?new Set(a):new Set}_matchNodeNext(c,e,o){const{combo:a,index:l}=o,{combo:r,leaves:f}=c[l],u={combo:a,leaves:f},h=this._getCombinedNodes(u,e,E);if(h.size)if(l===c.length-1){const[i]=(0,N.sortNodes)(h);return i}else return this._matchNodeNext(c,h,{combo:r,index:l+1});return null}_matchNodePrev(c,e,o){const{index:a}=o,l=c[a],r=new Set([e]),f=this._getCombinedNodes(l,r,S);if(f.size){if(a===0)return e;{let u;for(const h of f)if(u=this._matchNodePrev(c,h,{index:a-1}),u)break;if(u)return e}}return null}find(c){(c===n.TARGET_ALL||c===n.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],o]=this._collectNodes(c),a=e.length;let l,r=new Set;for(let f=0;f<a;f++){const{branch:u,collected:h,dir:i,find:t}=e[f],s=u.length;if(s&&t){const d=o[f],m=d.length,b=s-1;if(b===0)if((c===n.TARGET_ALL||c===n.TARGET_FIRST)&&this.#e.nodeType===n.ELEMENT_NODE)for(let w=0;w<m;w++){const p=d[w];if(p!==this.#e&&this.#e.contains(p)&&(r.add(p),c===n.TARGET_FIRST))break}else if(c===n.TARGET_ALL)if(r.size){const w=[...r];r=new Set([...w,...d]),l=!0}else r=new Set(d);else{const[w]=d;r.add(w)}else if(c===n.TARGET_ALL)if(i===E){let{combo:w}=u[0];for(const p of d){let k=new Set([p]);for(let _=1;_<s;_++){const{combo:g,leaves:T}=u[_],x={combo:w,leaves:T};if(k=this._getCombinedNodes(x,k,i),k.size)if(_===b)if(r.size){const C=[...r];r=new Set([...C,...k]),l=!0}else r=k;else w=g;else break}}}else for(const w of d){let p=new Set([w]);for(let k=b-1;k>=0;k--){const _=u[k];if(p=this._getCombinedNodes(_,p,i),p.size)k===0&&(r.add(w),s>1&&r.size>1&&(l=!0));else break}}else if(c===n.TARGET_FIRST&&i===E){const{combo:w}=u[0];let p;for(const k of d)if(p=this._matchNodeNext(u,new Set([k]),{combo:w,index:1}),p){r.add(p);break}if(!p&&!h){const{leaves:k}=u[0],[_]=d;let g=this._findNode(k,_);for(;g;){if(p=this._matchNodeNext(u,new Set([g]),{combo:w,index:1}),p){r.add(p);break}g=this._findNode(k,g)}}}else{let w;for(const p of d)if(w=this._matchNodePrev(u,p,{index:b-1}),w){r.add(p);break}if(!w&&!h&&c===n.TARGET_FIRST){const{leaves:p}=u[b],[k]=d;let _=this._findNode(p,k);for(;_;){if(w=this._matchNodePrev(u,_,{index:b-1}),w){r.add(_);break}_=this._findNode(p,_)}}}}}return c===n.TARGET_FIRST?(r.delete(this.#e),r.size>1&&(r=new Set((0,N.sortNodes)(r)))):c===n.TARGET_ALL&&(r.delete(this.#e),l&&r.size>1&&(r=new Set((0,N.sortNodes)(r)))),r}}0&&(module.exports={Finder});
|
|
1
|
+
var C=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var M=(E,c)=>{for(var e in c)C(E,e,{get:c[e],enumerable:!0})},D=(E,c,e,o)=>{if(c&&typeof c=="object"||typeof c=="function")for(let l of R(c))!I.call(E,l)&&l!==e&&C(E,l,{get:()=>c[l],enumerable:!(o=O(c,l))||o.enumerable});return E};var P=E=>D(C({},"__esModule",{value:!0}),E);var U={};M(U,{Finder:()=>W});module.exports=P(U);var g=require("./matcher.js"),_=require("./parser.js"),N=require("./utility.js"),n=require("./constant.js");const S="next",x="prev";class W{#i;#n;#w;#t;#f;#c;#u;#o;#b;#r;#e;#d;#_;#m;#k;#s;#y;#h;#N;#p;#a;#l;constructor(c){this.#l=c,this.#n=new WeakMap,this.#f=new WeakMap,this.#b=new WeakMap,this.#k=new WeakMap,this.#c=null,this.#u=null,this.#r=null,this._registerEventListeners()}onError(c,e){if(!(e?.noexcept??this.#_))if(c instanceof DOMException||c instanceof this.#l.DOMException)if(c.name===n.NOT_SUPPORTED_ERR)this.#a&&console.warn(c.message);else throw new this.#l.DOMException(c.message,c.name);else throw c.name in this.#l?new this.#l[c.name](c.message):c}setup(c,e,o={}){const{noexcept:l,warn:a}=o;return this.#_=!!l,this.#a=!!a,this.#e=e,[this.#t,this.#s,this.#h]=(0,N.resolveContent)(e),this.#y=c,[this.#i,this.#d]=this._correspond(c),this.#b=new WeakMap,this.#p=new WeakMap,this.#N=null,this}_registerEventListeners(){const c={capture:!0,passive:!0},e=[],o=["focus","focusin"];for(const r of o)e.push(this.#l.addEventListener(r,f=>{this.#u=f},c));const l=["keydown","keyup"];for(const r of l)e.push(this.#l.addEventListener(r,f=>{const{key:b}=f;n.KEY_MODIFIER.includes(b)||(this.#c=f)},c));const a=["mouseover","mousedown","mouseup","click","mouseout"];for(const r of a)e.push(this.#l.addEventListener(r,f=>{this.#c=f},c));return e}_correspond(c){const e=[];this.#w=!1,this.#o=!1;let o;if(this.#f.has(this.#t)){const l=this.#f.get(this.#t);if(l&&l.has(`${c}`)){const a=l.get(`${c}`);o=a.ast,this.#w=a.descendant,this.#o=a.invalidate}}if(o){const l=o.length;for(let a=0;a<l;a++)o[a].dir=null,o[a].filtered=!1,o[a].find=!1,e[a]=[]}else{let l;try{l=(0,_.parseSelector)(c)}catch(m){this.onError(m)}const{branches:a,info:r}=(0,_.walkAST)(l),{hasHasPseudoFunc:f,hasLogicalPseudoFunc:b,hasNthChildOfSelector:h}=r;let i=f||!!(b&&h),t=!1,s=0;o=[];for(const[...m]of a){const u=[];let p=m.shift();if(p&&p.type!==n.COMBINATOR){const w=new Set;for(;p;){let k=p.name;if(p.type===n.COMBINATOR){const[y]=m;if(y.type===n.COMBINATOR)throw new DOMException(`Invalid selector ${c}`,n.SYNTAX_ERR);k==="+"||k==="~"?i=!0:t=!0,u.push({combo:p,leaves:(0,_.sortAST)(w)}),w.clear()}else p&&(k&&typeof k=="string"&&(k=(0,_.unescapeSelector)(k),typeof k=="string"&&k!==p.name&&(p.name=k),/[|:]/.test(k)&&(p.namespace=!0)),w.add(p));if(m.length)p=m.shift();else{u.push({combo:null,leaves:(0,_.sortAST)(w)}),w.clear();break}}}o.push({branch:u,dir:null,filtered:!1,find:!1}),e[s]=[],s++}let d;this.#f.has(this.#t)?d=this.#f.get(this.#t):d=new Map,d.set(`${c}`,{ast:o,descendant:t,invalidate:i}),this.#f.set(this.#t,d),this.#w=t,this.#o=i}return[o,e]}_createTreeWalker(c,e={}){const{force:o=!1,whatToShow:l=n.WALKER_FILTER}=e;let a;return o?a=this.#t.createTreeWalker(c,l):this.#p.has(c)?a=this.#p.get(c):(a=this.#t.createTreeWalker(c,l),this.#p.set(c,a)),a}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(c,e,o){const{a:l,b:a,reverse:r,selector:f}=c,{parentNode:b}=e,h=new Set;let i;if(f){if(this.#n.has(f))i=this.#n.get(f);else{const{branches:s}=(0,_.walkAST)(f);i=s,this.#o||this.#n.set(f,i)}const{branches:t}=(0,_.walkAST)(f);i=t}if(b){const t=this._createTreeWalker(b,{force:!0});let s=t.firstChild();const d=new Set;let m=0;if(i)for(;s;){if((0,N.isVisible)(s)){let u;for(const p of i)if(u=this._matchLeaves(p,s,o),!u)break;u&&d.add(s)}m++,s=t.nextSibling()}else for(;s;)m++,s=t.nextSibling();if(l===0){if(a>0&&a<=m){if(d.size){s=(0,N.traverseNode)(b,t),r?s=t.lastChild():s=t.firstChild();let u=0;for(;s;){if(d.has(s)){if(u===a-1){h.add(s);break}u++}r?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,N.traverseNode)(b,t),r?s=t.lastChild():s=t.firstChild();let u=0;for(;s;){if(u===a-1){h.add(s);break}r?s=t.previousSibling():s=t.nextSibling(),u++}}}}else{let u=a-1;if(l>0)for(;u<0;)u+=l;if(u>=0&&u<m){s=(0,N.traverseNode)(b,t),r?s=t.lastChild():s=t.firstChild();let p=0,w=l>0?0:a-1;for(;s&&(s&&u>=0&&u<m);)d.size?d.has(s)&&(w===u&&(h.add(s),u+=l),l>0?w++:w--):p===u&&(f||h.add(s),u+=l),r?s=t.previousSibling():s=t.nextSibling(),p++}}if(r&&h.size>1){const u=[...h];return new Set(u.reverse())}}else if(e===this.#s&&l+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,o),t)break;t&&h.add(e)}else h.add(e);return h}_collectNthOfType(c,e){const{a:o,b:l,reverse:a}=c,{localName:r,namespaceURI:f,parentNode:b,prefix:h}=e,i=new Set;if(b){const t=this._createTreeWalker(b);let s=(0,N.traverseNode)(b,t);s=t.firstChild();let d=0;for(;s;)d++,s=t.nextSibling();if(o===0){if(l>0&&l<=d){s=(0,N.traverseNode)(b,t),a?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){const{localName:u,namespaceURI:p,prefix:w}=s;if(u===r&&w===h&&p===f){if(m===l-1){i.add(s);break}m++}a?s=t.previousSibling():s=t.nextSibling()}}}else{let m=l-1;if(o>0)for(;m<0;)m+=o;if(m>=0&&m<d){s=(0,N.traverseNode)(b,t),a?s=t.lastChild():s=t.firstChild();let u=o>0?0:l-1;for(;s;){const{localName:p,namespaceURI:w,prefix:k}=s;if(p===r&&k===h&&w===f){if(u===m&&(i.add(s),m+=o),m<0||m>=d)break;o>0?u++:u--}a?s=t.previousSibling():s=t.nextSibling()}}}if(a&&i.size>1){const m=[...i];return new Set(m.reverse())}}else e===this.#s&&o+l===1&&i.add(e);return i}_matchAnPlusB(c,e,o,l){const{nth:{a,b:r,name:f},selector:b}=c,h=new Map;if(f?(f==="even"?(h.set("a",2),h.set("b",0)):f==="odd"&&(h.set("a",2),h.set("b",1)),o.indexOf("last")>-1&&h.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?h.set("a",a*1):h.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?h.set("b",r*1):h.set("b",0),o.indexOf("last")>-1&&h.set("reverse",!0)),o==="nth-child"||o==="nth-last-child"){b&&h.set("selector",b);const i=Object.fromEntries(h);return this._collectNthChild(i,e,l)}else if(o==="nth-of-type"||o==="nth-last-of-type"){const i=Object.fromEntries(h);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(c,e,o){if(Array.isArray(c)&&c.length){const l=[...c],[a]=l,{type:r}=a;let f;r===n.COMBINATOR?f=l.shift():f={name:" ",type:n.COMBINATOR};const b=[];for(;l.length;){const[t]=l,{type:s}=t;if(s===n.COMBINATOR)break;b.push(l.shift())}const h={combo:f,leaves:b};o.dir=S;const i=this._matchCombinator(h,e,o);if(i.size){if(l.length){let t=!1;for(const s of i)if(t=this._matchHasPseudoFunc(l,s,o),t)break;return t}return!0}}return!1}_matchLogicalPseudoFunc(c,e,o){const{astName:l,branches:a,twigBranches:r}=c,f=(o.isShadowRoot||this.#h)&&e.nodeType===n.DOCUMENT_FRAGMENT_NODE;if(l==="has"){let b;for(const h of a)if(b=this._matchHasPseudoFunc(h,e,o),b)break;if(b)if(f){if(this.#N)return e}else return e}else{if(f){let i;for(const t of a)if(t.length>1){i=!0;break}else if(l==="not"){const[{type:s}]=t;if(s!==n.PS_CLASS_SELECTOR){i=!0;break}}if(i)return null}o.forgive=l==="is"||l==="where";const b=r.length;let h;for(let i=0;i<b;i++){const t=r[i],s=t.length-1,{leaves:d}=t[s];if(h=this._matchLeaves(d,e,o),h&&s>0){let m=new Set([e]);for(let u=s-1;u>=0;u--){const p=t[u],w=[];o.dir=x;for(const k of m){const y=this._matchCombinator(p,k,o);y.size&&w.push(...y)}if(w.length)u===0?h=!0:m=new Set(w);else{h=!1;break}}}if(h)break}if(l==="not")return h?null:e;if(h)return e}return null}_matchPseudoClassSelector(c,e,o){const{children:l,name:a}=c,{localName:r,parentNode:f}=e,{forgive:b,warn:h=this.#a}=o,i=new Set;if(Array.isArray(l)&&n.KEY_LOGICAL.includes(a)){if(!l.length&&a!=="is"&&a!=="where"){const d=(0,_.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}let t;if(this.#n.has(c))t=this.#n.get(c);else{const{branches:d}=(0,_.walkAST)(c);if(a==="has"){let m;for(const u of l){const p=(0,_.findAST)(u,w=>n.KEY_LOGICAL.includes(w.name)&&(0,_.findAST)(w,k=>k.name==="has")?w:null);if(p){const w=p.name;if(w==="is"||w==="where"){m=!0;break}else{const k=(0,_.generateCSS)(c);throw new DOMException(`Invalid selector ${k}`,n.SYNTAX_ERR)}}}if(m)return i;t={astName:a,branches:d}}else{const m=[];for(const[...u]of d){const p=[],w=new Set;let k=u.shift();for(;k;)if(k.type===n.COMBINATOR?(p.push({combo:k,leaves:[...w]}),w.clear()):k&&w.add(k),u.length)k=u.shift();else{p.push({combo:null,leaves:[...w]}),w.clear();break}m.push(p)}t={astName:a,branches:d,twigBranches:m},this.#o||this.#n.set(c,t)}}const s=this._matchLogicalPseudoFunc(t,e,o);s&&i.add(s)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){if(l.length!==1){const d=(0,_.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}const[t]=l;return this._matchAnPlusB(t,e,a,o)}else switch(a){case"dir":{if(l.length!==1){const d=(0,_.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}const[t]=l;(0,g.matchDirectionPseudoClass)(t,e)&&i.add(e);break}case"lang":{if(!l.length){const s=(0,_.generateCSS)(c);throw new DOMException(`Invalid selector ${s}`,n.SYNTAX_ERR)}let t;for(const s of l)if(t=(0,g.matchLanguagePseudoClass)(s,e),t)break;t&&i.add(e);break}case"state":{if((0,N.isCustomElement)(e)){const[{value:t}]=l;if(t)if(e[t])i.add(e);else for(const s in e){const d=e[s];if(d instanceof this.#l.ElementInternals){d?.states?.has(t)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(h)throw new DOMException(`Unsupported pseudo-class :${a}()`,n.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(h)throw new DOMException(`Unknown pseudo-class :${a}()`,n.NOT_SUPPORTED_ERR);break}default:if(!b)throw new DOMException(`Unknown pseudo-class :${a}()`,n.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{(r==="a"||r==="area")&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if((r==="a"||r==="area")&&e.hasAttribute("href")){const{href:t,origin:s,pathname:d}=new URL(this.#t.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===d&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#c??{};/^(?:click|mouse(?:down|over|up))$/.test(s)&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:d}=this.#c??{};d==="mousedown"&&t&n.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#t.URL);e.id&&t===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#t.URL);if(t){const s=t.replace(/^#/,"");let d=this.#t.getElementById(s);for(;d;){if(d===e){i.add(e);break}d=d.parentNode}}break}case"scope":{this.#e.nodeType===n.ELEMENT_NODE?!this.#h&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&(0,N.isFocusableArea)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&(0,N.isFocusableArea)(e)){let t;if((0,N.isFocusVisible)(e))t=!0;else if(this.#u){const{relatedTarget:s,target:d}=this.#u;if(d===e)if((0,N.isFocusVisible)(s))t=!0;else if(this.#c){const{key:m,target:u,type:p}=this.#c;u===s?(this.#r===null||d===this.#r)&&(t=!0):m==="Tab"?(p==="keydown"&&u!==e||p==="keyup"&&u===e)&&(u===d?(this.#r===null||u===this.#r&&s===null)&&(t=!0):t=!0):m&&(p==="keydown"||p==="keyup")&&u===e&&(t=!0)}else(s===null||s===this.#r)&&(t=!0)}t?(this.#r=e,i.add(e)):this.#r===e&&(this.#r=null)}break}case"focus-within":{let t,s=this.#t.activeElement;if((0,N.isFocusableArea)(s))for(;s;){if(s===e){t=!0;break}s=s.parentNode}t&&i.add(e);break}case"open":case"closed":{(r==="details"||r==="dialog")&&(e.hasAttribute("open")?a==="open"&&i.add(e):a==="closed"&&i.add(e));break}case"disabled":case"enabled":{if([...n.KEY_FORM_FOCUS,"fieldset","optgroup","option"].includes(r)||(0,N.isCustomElement)(e,{formAssociated:!0})){let s;if(e.disabled||e.hasAttribute("disabled"))s=!0;else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&(s=!0);else if(e.localName!=="optgroup"){let d=f;for(;d;)if(d.localName==="fieldset"&&(d.disabled||d.hasAttribute("disabled"))){let m=d.firstElementChild;for(;m&&m.localName!=="legend";)m=m.nextElementSibling;m&&m.contains(e)||(s=!0);break}else{if(d.localName==="form")break;if(d.parentNode?.nodeType===n.ELEMENT_NODE){if(d.parentNode.localName==="form")break;d=d.parentNode}else break}}s?a==="disabled"&&i.add(e):a==="enabled"&&i.add(e)}break}case"read-only":case"read-write":{let t,s;switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0;break}case"input":{(!e.type||n.KEY_INPUT_EDIT.includes(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0);break}default:(0,N.isContentEditable)(e)?s=!0:t=!0}t?a==="read-only"&&i.add(e):a==="read-write"&&s&&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;r==="textarea"?s=e:r==="input"&&(e.hasAttribute("type")?[...n.KEY_INPUT_TEXT,"number"].includes(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{const t=e.getAttribute("type");(e.checked&&r==="input"&&(t==="checkbox"||t==="radio")||e.selected&&r==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&r==="input"&&e.type==="checkbox"||r==="progress"&&!e.hasAttribute("value"))i.add(e);else if(r==="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.#t.documentElement);const d=this._createTreeWalker(s);let m=(0,N.traverseNode)(s,d);m=d.firstChild();let u;for(;m&&!(m.localName==="input"&&m.getAttribute("type")==="radio"&&(m.hasAttribute("name")?m.getAttribute("name")===t&&(u=!!m.checked):u=!!m.checked,u));)m=d.nextNode();u||i.add(e)}break}case"default":{const t=["checkbox","radio"],s=["button","reset"],d=["image","submit"],m=e.getAttribute("type");if(r==="button"&&!(e.hasAttribute("type")&&s.includes(m))||r==="input"&&e.hasAttribute("type")&&d.includes(m)){let u=e.parentNode;for(;u&&u.localName!=="form";)u=u.parentNode;if(u){const p=this._createTreeWalker(u);let w=(0,N.traverseNode)(u,p);for(w=p.firstChild();w;){const k=w.localName,y=w.getAttribute("type");let v;if(k==="button"?v=!(w.hasAttribute("type")&&s.includes(y)):k==="input"&&(v=w.hasAttribute("type")&&d.includes(y)),v){w===e&&i.add(e);break}w=p.nextNode()}}}else(r==="input"&&e.hasAttribute("type")&&t.includes(m)&&e.hasAttribute("checked")||r==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":case"invalid":{const t=[...n.KEY_FORM_FOCUS,"form"];if(t.includes(r)){let s;e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&(s=!0):s=!0),s?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}else if(r==="fieldset"){const s=this._createTreeWalker(e);let d=(0,N.traverseNode)(e,s);d=s.firstChild();let m;if(!d)m=!0;else for(;d&&!(t.includes(d.localName)&&(d.checkValidity()?d.maxLength>=0?m=d.maxLength>=d.value.length:m=!0:m=!1,!m));)d=s.nextNode();m?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}break}case"in-range":case"out-of-range":{const t=[...n.KEY_INPUT_DATE,"number","range"],s=e.getAttribute("type");if(r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&t.includes(s)){const d=e.validity.rangeUnderflow||e.validity.rangeOverflow;(a==="out-of-range"&&d||a==="in-range"&&!d&&(e.hasAttribute("min")||e.hasAttribute("max")||s==="range"))&&i.add(e)}break}case"required":case"optional":{let t;if(r==="select"||r==="textarea")t=e;else if(r==="input")if(e.hasAttribute("type")){const s=[...n.KEY_INPUT_EDIT,"checkbox","file","radio"],d=e.getAttribute("type");s.includes(d)&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required")?a==="required"&&i.add(e):a==="optional"&&i.add(e));break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this._createTreeWalker(e,{force:!0,whatToShow:n.SHOW_ALL});let s=t.firstChild(),d;for(;s&&(d=s.nodeType!==n.ELEMENT_NODE&&s.nodeType!==n.TEXT_NODE,!!d);)s=t.nextSibling();d&&i.add(e)}else i.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(f){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.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||r.includes("-")?(0,N.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,N.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(h)throw new DOMException(`Unsupported pseudo-element ::${a}`,n.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(h)throw new DOMException(`Unsupported pseudo-class :${a}`,n.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(h)throw new DOMException(`Unsupported pseudo-class :${a}`,n.NOT_SUPPORTED_ERR)}else if(!b)throw new DOMException(`Unknown pseudo-class :${a}`,n.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(c,e){const{children:o,name:l}=c;if(Array.isArray(o)){if(o.length!==1){const h=(0,_.generateCSS)(c);throw new DOMException(`Invalid selector ${h}`,n.SYNTAX_ERR)}const{branches:a}=(0,_.walkAST)(o[0]),[r]=a,[...f]=r,{host:b}=e;if(l==="host"){let h;for(const i of f){const{type:t}=i;if(t===n.COMBINATOR){const s=(0,_.generateCSS)(c);throw new DOMException(`Invalid selector ${s}`,n.SYNTAX_ERR)}if(h=this._matchSelector(i,b).has(b),!h)break}return h?e:null}else if(l==="host-context"){let h=b,i;for(;h;){for(const t of f){const{type:s}=t;if(s===n.COMBINATOR){const d=(0,_.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}if(i=this._matchSelector(t,h).has(h),!i)break}if(i)break;h=h.parentNode}return i?e:null}throw new DOMException(`Invalid selector :${l}`,n.SYNTAX_ERR)}else{if(l==="host")return e;throw new DOMException(`Invalid selector :${l}`,n.SYNTAX_ERR)}}_matchSelector(c,e,o={}){const{type:l}=c,a=(0,_.unescapeSelector)(c.name),r=new Set;if(e.nodeType===n.ELEMENT_NODE)switch(l){case n.ATTR_SELECTOR:{(0,g.matchAttributeSelector)(c,e)&&r.add(e);break}case n.ID_SELECTOR:{e.id===a&&r.add(e);break}case n.CLASS_SELECTOR:{e.classList.contains(a)&&r.add(e);break}case n.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(c,e,o);case n.TYPE_SELECTOR:{(0,g.matchTypeSelector)(c,e,o)&&r.add(e);break}case n.PS_ELEMENT_SELECTOR:default:(0,g.matchPseudoElementSelector)(a,l,o)}else if(this.#h&&l===n.PS_CLASS_SELECTOR&&e.nodeType===n.DOCUMENT_FRAGMENT_NODE){if(n.KEY_LOGICAL.includes(a))return o.isShadowRoot=!0,this._matchPseudoClassSelector(c,e,o);if(a==="host"||a==="host-context"){const f=this._matchShadowHostPseudoClass(c,e,o);f&&(this.#N=!0,r.add(f))}}return r}_matchLeaves(c,e,o){let l;if(this.#o?l=this.#b.get(c):l=this.#k.get(c),l&&l.has(e)){const{matched:a}=l.get(e);return a}else{let a=!0;const r=[...n.KEY_FORM_FOCUS,"fieldset","form"],f=["any-link","defined","dir","link"];e.nodeType===n.ELEMENT_NODE&&r.includes(e.localName)&&(a=!1);let b;for(const h of c){switch(h.type){case n.ATTR_SELECTOR:case n.ID_SELECTOR:{a=!1;break}case n.PS_CLASS_SELECTOR:{f.includes(h.name)&&(a=!1);break}default:}if(b=this._matchSelector(h,e,o).has(e),!b)break}return a&&(l||(l=new WeakMap),l.set(e,{matched:b}),this.#o?this.#b.set(c,l):this.#k.set(c,l)),b}}_findDescendantNodes(c,e,o){const[l,...a]=c,r=a.length>0,{type:f}=l,b=(0,_.unescapeSelector)(l.name),h=new Set;let i=!1;if(this.#h||e.nodeType!==n.ELEMENT_NODE)i=!0;else switch(f){case n.PS_ELEMENT_SELECTOR:{(0,g.matchPseudoElementSelector)(b,f,o);break}case n.ID_SELECTOR:{if(this.#s.nodeType===n.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(b);t&&t!==e&&e.contains(t)&&(r?this._matchLeaves(a,t,o)&&h.add(t):h.add(t))}break}default:i=!0}if(i){const t=this._createTreeWalker(e);let s=(0,N.traverseNode)(e,t);for(s=t.firstChild();s;)this._matchLeaves(c,s,o)&&h.add(s),s=t.nextNode()}return h}_matchCombinator(c,e,o){const{combo:l,leaves:a}=c,{name:r}=l,{parentNode:f}=e,{dir:b}=o,h=new Set;if(b===S)switch(r){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,o)&&h.add(i);break}case"~":{if(f){let i=e.nextElementSibling;for(;i;)this._matchLeaves(a,i,o)&&h.add(i),i=i.nextElementSibling}break}case">":{let i=e.firstElementChild;for(;i;)this._matchLeaves(a,i,o)&&h.add(i),i=i.nextElementSibling;break}case" ":default:{const i=this._findDescendantNodes(a,e,o);if(i.size)return i}}else switch(r){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,o)&&h.add(i);break}case"~":{if(f){let i=f.firstElementChild;for(;i&&i!==e;)this._matchLeaves(a,i,o)&&h.add(i),i=i.nextElementSibling}break}case">":{f&&this._matchLeaves(a,f,o)&&h.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(a,t,o)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return h}_findWalker(c,e,o={}){const{force:l,targetType:a}=o,r=this.#m,f=[];let b=(0,N.traverseNode)(e,r,!!l);if(b)for((b.nodeType!==n.ELEMENT_NODE||b===e&&b!==this.#s)&&(b=r.nextNode());b&&!(this._matchLeaves(c,b,{warn:this.#a})&&(f.push(b),a!==n.TARGET_ALL));)b=r.nextNode();return f}_matchSelf(c){const e=[];let o=!1;return this._matchLeaves(c,this.#e,{warn:this.#a})&&(e.push(this.#e),o=!0),[e,o]}_findLineal(c,e){const{complex:o}=e,l=[];let a=!1,r=this._matchLeaves(c,this.#e,{warn:this.#a});if(r&&(l.push(this.#e),a=!0),!r||o){let f=this.#e.parentNode;for(;f&&(r=this._matchLeaves(c,f,{warn:this.#a}),r&&(l.push(f),a=!0),f.parentNode);)f=f.parentNode}return[l,a]}_findEntryNodes(c,e,o){const{leaves:l}=c,[a,...r]=l,f=r.length>0,{name:b,type:h}=a;let i=[],t=!1,s=!1;switch(h){case n.PS_ELEMENT_SELECTOR:{(0,g.matchPseudoElementSelector)(b,h,{warn:this.#a});break}case n.ID_SELECTOR:{if(e===n.TARGET_SELF)[i,t]=this._matchSelf(l);else if(e===n.TARGET_LINEAL)[i,t]=this._findLineal(l,{complex:o});else if(e===n.TARGET_FIRST&&this.#s.nodeType!==n.ELEMENT_NODE){const d=this.#s.getElementById(b);d&&(f?this._matchLeaves(r,d,{warn:this.#a})&&(i.push(d),t=!0):(i.push(d),t=!0))}else i=this._findWalker(l,this.#e,{targetType:e}),i.length&&(t=!0);break}case n.CLASS_SELECTOR:{e===n.TARGET_SELF?[i,t]=this._matchSelf(l):e===n.TARGET_LINEAL?[i,t]=this._findLineal(l,{complex:o}):(i=this._findWalker(l,this.#e,{targetType:e}),i.length&&(t=!0));break}case n.TYPE_SELECTOR:{e===n.TARGET_SELF?[i,t]=this._matchSelf(l):e===n.TARGET_LINEAL?[i,t]=this._findLineal(l,{complex:o}):(i=this._findWalker(l,this.#e,{targetType:e}),i.length&&(t=!0));break}default:if(e!==n.TARGET_LINEAL&&(b==="host"||b==="host-context")){let d;if(this.#h&&this.#e.nodeType===n.DOCUMENT_FRAGMENT_NODE?d=this._matchShadowHostPseudoClass(a,this.#e):f&&this.#e.nodeType===n.ELEMENT_NODE&&(d=this._matchShadowHostPseudoClass(a,this.#e.shadowRoot)),d){let m;if(f){for(const u of r)if(/^host(?:-context)?$/.test(u.name)?m=this._matchShadowHostPseudoClass(u,d)===d:u.name==="has"?m=this._matchPseudoClassSelector(u,d,{}).has(d):m=!1,!m)break}else m=!0;m&&(i.push(d),t=!0)}}else e===n.TARGET_SELF?[i,t]=this._matchSelf(l):e===n.TARGET_LINEAL?[i,t]=this._findLineal(l,{complex:o}):e===n.TARGET_FIRST?(i=this._findWalker(l,this.#e,{targetType:e}),i.length&&(t=!0)):s=!0}return{compound:f,filtered:t,nodes:i,pending:s}}_collectNodes(c){const e=this.#i.values();if(c===n.TARGET_ALL||c===n.TARGET_FIRST){const o=new Set;let l=0;for(const{branch:a}of e){const r=a.length,f=r>1,b=a[0];let h,i;if(f){const{combo:u,leaves:[{name:p,type:w}]}=b,k=a[r-1],{leaves:[{name:y,type:v}]}=k;if(h=S,i=b,this.#y.includes(":scope")||v===n.PS_ELEMENT_SELECTOR||v===n.ID_SELECTOR)h=x,i=k;else if(p==="*"&&w===n.TYPE_SELECTOR)h=x,i=k;else if(y==="*"&&v===n.TYPE_SELECTOR)h=S,i=b;else if(r===2){const{name:L}=u;(L==="+"||L==="~")&&(h=x,i=k)}}else h=x,i=b;const{compound:t,filtered:s,nodes:d,pending:m}=this._findEntryNodes(i,c,f);d.length?(this.#i[l].find=!0,this.#d[l]=d):m&&o.add(new Map([["index",l],["twig",i]])),this.#i[l].dir=h,this.#i[l].filtered=s||!t,l++}if(o.size){let a,r;this.#e!==this.#s&&this.#e.nodeType===n.ELEMENT_NODE?(a=this.#e,r=this.#m):(a=this.#s,r=this._createTreeWalker(a));let f=(0,N.traverseNode)(a,r);for(;f;){let b=!1;if(this.#e.nodeType===n.ELEMENT_NODE?f===this.#e?b=!0:b=this.#e.contains(f):b=!0,b)for(const h of o){const{leaves:i}=h.get("twig");if(this._matchLeaves(i,f,{warn:this.#a})){const s=h.get("index");this.#i[s].filtered=!0,this.#i[s].find=!0,this.#d[s].push(f)}}f!==r.currentNode&&(f=(0,N.traverseNode)(f,r)),f=r.nextNode()}}}else{let o=0;for(const{branch:l}of e){const a=l[l.length-1],r=l.length>1,{compound:f,filtered:b,nodes:h}=this._findEntryNodes(a,c,r);h.length&&(this.#i[o].find=!0,this.#d[o]=h),this.#i[o].dir=x,this.#i[o].filtered=b||!f,o++}}return[this.#i,this.#d]}_getCombinedNodes(c,e,o){const l=[];for(const a of e){const r=this._matchCombinator(c,a,{dir:o,warn:this.#a});r.size&&l.push(...r)}return l.length?new Set(l):new Set}_matchNodeNext(c,e,o){const{combo:l,index:a}=o,{combo:r,leaves:f}=c[a],b={combo:l,leaves:f},h=this._getCombinedNodes(b,e,S);if(h.size)if(a===c.length-1){const[i]=(0,N.sortNodes)(h);return i}else return this._matchNodeNext(c,h,{combo:r,index:a+1});return null}_matchNodePrev(c,e,o){const{index:l}=o,a=c[l],r=new Set([e]),f=this._getCombinedNodes(a,r,x);if(f.size){if(l===0)return e;{let b;for(const h of f)if(b=this._matchNodePrev(c,h,{index:l-1}),b)break;if(b)return e}}return null}find(c){(c===n.TARGET_ALL||c===n.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],o]=this._collectNodes(c),l=e.length;let a,r=new Set;for(let f=0;f<l;f++){const{branch:b,dir:h,find:i}=e[f],t=b.length;if(t&&i){const s=o[f],d=s.length,m=t-1;if(m===0)if((c===n.TARGET_ALL||c===n.TARGET_FIRST)&&this.#e.nodeType===n.ELEMENT_NODE)for(let u=0;u<d;u++){const p=s[u];if(p!==this.#e&&this.#e.contains(p)&&(r.add(p),c===n.TARGET_FIRST))break}else if(c===n.TARGET_ALL)if(r.size){const u=[...r];r=new Set([...u,...s]),a=!0}else r=new Set(s);else{const[u]=s;r.add(u)}else if(c===n.TARGET_ALL)if(h===S){const{combo:u}=b[0];let p=u;for(const w of s){let k=new Set([w]);for(let y=1;y<t;y++){const{combo:v,leaves:L}=b[y],A={combo:p,leaves:L};if(k=this._getCombinedNodes(A,k,h),k.size)if(y===m)if(r.size){const T=[...r];r=new Set([...T,...k]),a=!0,p=u}else r=k,p=u;else p=v;else break}}}else for(const u of s){let p=new Set([u]);for(let w=m-1;w>=0;w--){const k=b[w];if(p=this._getCombinedNodes(k,p,h),p.size)w===0&&(r.add(u),t>1&&r.size>1&&(a=!0));else break}}else if(c===n.TARGET_FIRST&&h===S){const{combo:u}=b[0];let p;for(const w of s)if(p=this._matchNodeNext(b,new Set([w]),{combo:u,index:1}),p){r.add(p);break}if(!p){const{leaves:w}=b[0],[k]=s;let[y]=this._findWalker(w,k,{targetType:c});for(;y;){if(p=this._matchNodeNext(b,new Set([y]),{combo:u,index:1}),p){r.add(p);break}[y]=this._findWalker(w,y,{targetType:c,force:!0})}}}else{let u;for(const p of s)if(u=this._matchNodePrev(b,p,{index:m-1}),u){r.add(p);break}if(!u&&c===n.TARGET_FIRST){const{leaves:p}=b[m],[w]=s;let[k]=this._findWalker(p,w,{targetType:c});for(;k;){if(u=this._matchNodePrev(b,k,{index:m-1}),u){r.add(k);break}[k]=this._findWalker(p,k,{targetType:c,force:!0})}}}}}return c===n.TARGET_FIRST?(r.delete(this.#e),r.size>1&&(r=new Set((0,N.sortNodes)(r)))):c===n.TARGET_ALL&&(r.delete(this.#e),a&&r.size>1&&(r=new Set((0,N.sortNodes)(r)))),r}}0&&(module.exports={Finder});
|
|
2
2
|
//# sourceMappingURL=finder.js.map
|