@asamuzakjp/dom-selector 0.24.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,8 +8,7 @@
8
8
  [![release](https://img.shields.io/github/v/release/asamuzaK/domSelector)](https://github.com/asamuzaK/domSelector/releases)
9
9
  -->
10
10
 
11
- Retrieve DOM node from the given CSS selector.
12
- **Experimental**
11
+ Retrieve DOM node from the given CSS selector.
13
12
 
14
13
  ## Install
15
14
 
@@ -130,7 +129,7 @@ Returns **[Array][62]<([object][60] \| [undefined][63])>** array of matched n
130
129
  |E:enabled<br>E:disabled|✓| |
131
130
  |E:read&#8209;write<br>E:read&#8209;only|✓| |
132
131
  |E:placeholder&#8209;shown|✓| |
133
- |E:default|Partially supported|&lt;option&gt; within &lt;select multiple&gt; is not supported.|
132
+ |E:default|✓| |
134
133
  |E:checked|✓| |
135
134
  |E:indeterminate|✓| |
136
135
  |E:valid<br>E:invalid|✓| |
@@ -234,34 +233,38 @@ const dom = new JSDOM('', {
234
233
 
235
234
  |Method and CSS selector|Jsdom|Patched-jsdom|Result|
236
235
  |:------------|:------------|:------------|:------------|
237
- |matches('.container.box')|1,704,793 ops/sec ±2.10%|95,691 ops/sec ±2.40%|jsdom is 17.8 times faster. patched-jsdom took 0.010msec.|
238
- |matches('.container:not(.box)')|906,712 ops/sec ±2.02%|57,603 ops/sec ±4.57%|jsdom is 15.7 times faster. patched-jsdom took 0.017msec.|
239
- |matches('.box + .box')|1,566,175 ops/sec ±2.17%|90,759 ops/sec ±5.32%|jsdom is 17.3 times faster. patched-jsdom took 0.011msec.|
240
- |matches('.box ~ .box')|1,585,314 ops/sec ±2.06%|90,257 ops/sec ±3.06%|jsdom is 17.6 times faster. patched-jsdom took 0.011msec.|
241
- |matches('.box > .block')|830,259 ops/sec ±2.29%|79,630 ops/sec ±2.76%|jsdom is 10.4 times faster. patched-jsdom took 0.013msec.|
242
- |matches('.box .content')|1,465,248 ops/sec ±2.74%|95,500 ops/sec ±2.36%|jsdom is 15.3 times faster. patched-jsdom took 0.010msec.|
243
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|1,531,871 ops/sec ±2.68%|30,324 ops/sec ±3.09%|* jsdom is 50.5 times faster. patched-jsdom took 0.033msec.|
244
- |closest('.container.box')|398,561 ops/sec ±2.74%|46,478 ops/sec ±2.31%|jsdom is 8.6 times faster. patched-jsdom took 0.022msec.|
245
- |closest('.container:not(.box)')|220,109 ops/sec ±2.58%|28,449 ops/sec ±4.44%|jsdom is 7.7 times faster. patched-jsdom took 0.035msec.|
246
- |closest('.box + .box')|355,897 ops/sec ±1.53%|43,752 ops/sec ±1.70%|jsdom is 8.1 times faster. patched-jsdom took 0.023msec.|
247
- |closest('.box ~ .box')|124,255 ops/sec ±1.87%|25,663 ops/sec ±2.76%|jsdom is 4.8 times faster. patched-jsdom took 0.039msec.|
248
- |closest('.box > .block')|387,622 ops/sec ±1.59%|40,747 ops/sec ±3.41%|jsdom is 9.5 times faster. patched-jsdom took 0.025msec.|
249
- |closest('.box .content')|235,499 ops/sec ±2.42%|50,113 ops/sec ±2.81%|jsdom is 4.7 times faster. patched-jsdom took 0.020msec.|
250
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|235,201 ops/sec ±2.80%|24,940 ops/sec ±2.26%|jsdom is 9.4 times faster. patched-jsdom took 0.040msec.|
251
- |querySelector('.container.box')|59,348 ops/sec ±3.98%|20,617 ops/sec ±2.05%|jsdom is 2.9 times faster. patched-jsdom took 0.049msec.|
252
- |querySelector('.container:not(.box)')|51,310 ops/sec ±2.61%|15,210 ops/sec ±1.42%|jsdom is 3.4 times faster. patched-jsdom took 0.066msec.|
253
- |querySelector('.box + .box')|52,099 ops/sec ±1.32%|16,644 ops/sec ±1.21%|jsdom is 3.1 times faster. patched-jsdom took 0.060msec.|
254
- |jsdom querySelector('.box ~ .box')|53,329 ops/sec ±2.51%|7,801 ops/sec ±2.10%|jsdom is 6.8 times faster. patched-jsdom took 0.128msec.|
255
- |querySelector('.box > .block')|755 ops/sec ±2.34%|2,492 ops/sec ±1.13%|patched-jsdom is 3.3 times faster. patched-jsdom took 0.401msec.|
256
- |querySelector('.box .content')|386 ops/sec ±2.96%|187 ops/sec ±1.12%|jsdom is 2.1 times faster. patched-jsdom took 5.359msec.|
257
- | querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|158 ops/sec ±2.40%|287 ops/sec ±2.03%|patched-jsdom is 1.8 times faster. patched-jsdom took 3.486msec.|
258
- |querySelectorAll('.container.box')|73,206 ops/sec ±3.78%|19,290 ops/sec ±1.55%|jsdom is 3.8 times faster. patched-jsdom took 0.052msec.|
259
- |querySelectorAll('.container:not(.box)')|65,761 ops/sec ±3.31%|14,269 ops/sec ±2.86%|jsdom is 4.6 times faster. patched-jsdom took 0.070msec.|
260
- |querySelectorAll('.box + .box')|69,019 ops/sec ±1.54%|17,941 ops/sec ±1.48%|jsdom is 3.8 times faster. patched-jsdom took 0.056msec.|
261
- |querySelectorAll('.box ~ .box')|64,329 ops/sec ±1.25%|7,748 ops/sec ±3.19%|jsdom is 8.3 times faster. patched-jsdom took 0.129msec.|
262
- |jsdom querySelectorAll('.box > .block')|764 ops/sec ±1.90%|2,086 ops/sec ±1.49%|patched-jsdom is 2.7 times faster. patched-jsdom took 0.479msec.|
263
- |querySelectorAll('.box .content')|370 ops/sec ±1.67%|165 ops/sec ±2.22%|jsdom is 2.3 times faster. patched-jsdom took 6.076msec.|
264
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|165 ops/sec ±1.13%|292 ops/sec ±1.79%|patched-jsdom is 1.8 times faster. patched-jsdom took 3.425msec.|
236
+ |matches('.container.box')|1,974,730 ops/sec ±2.26%|96,201 ops/sec ±19.30%|jsdom is 20.5 times faster. patched-jsdom took 0.010msec.|
237
+ |matches('.container:not(.box)')|991,905 ops/sec ±4.18%|67,844 ops/sec ±2.04%|jsdom is 14.6 times faster. patched-jsdom took 0.015msec.|
238
+ |matches('.box + .box')|1,761,449 ops/sec ±0.59%|92,724 ops/sec ±1.55%|jsdom is 19.0 times faster. patched-jsdom took 0.011msec.|
239
+ |matches('.box ~ .box')|1,756,640 ops/sec ±0.52%|92,254 ops/sec ±2.28%|jsdom is 19.0 times faster. patched-jsdom took 0.011msec.|
240
+ |matches('.box > .block')|965,850 ops/sec ±0.19%|77,155 ops/sec ±2.01%|jsdom is 12.5 times faster. patched-jsdom took 0.013msec.|
241
+ |matches('.box .content')|1,743,309 ops/sec ±0.25%|99,436 ops/sec ±0.68%|jsdom is 17.5 times faster. patched-jsdom took 0.010msec.|
242
+ |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|1,698,687 ops/sec ±0.38%|33,653 ops/sec ±2.79%|jsdom is 50.5 times faster. patched-jsdom took 0.030msec.|
243
+ |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|7,974 ops/sec ±4.39%|jsdom throws. patched-jsdom took 0.125msec.|
244
+ |closest('.container.box')|463,672 ops/sec ±0.24%|52,369 ops/sec ±0.38%|jsdom is 8.9 times faster. patched-jsdom took 0.019msec.|
245
+ |closest('.container:not(.box)')|263,034 ops/sec ±0.32%|32,326 ops/sec ±2.52%|jsdom is 8.1 times faster. patched-jsdom took 0.031msec.|
246
+ |closest('.box + .box')|421,756 ops/sec ±2.42%|49,539 ops/sec ±1.98%|jsdom is 8.5 times faster. patched-jsdom took 0.020msec.|
247
+ |closest('.box ~ .box')|144,622 ops/sec ±0.38%|29,353 ops/sec ±2.29%|jsdom is 4.9 times faster. patched-jsdom took 0.034msec.|
248
+ |closest('.box > .block')|454,446 ops/sec ±0.31%|46,650 ops/sec ±2.24%|jsdom is 9.7 times faster. patched-jsdom took 0.021msec.|
249
+ |closest('.box .content')|275,146 ops/sec ±0.23%|55,813 ops/sec ±2.08%|jsdom is 4.9 times faster. patched-jsdom took 0.018msec.|
250
+ |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|275,823 ops/sec ±0.25%|26,754 ops/sec ±1.96%|jsdom is 10.3 times faster. patched-jsdom took 0.037msec.|
251
+ |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|7,397 ops/sec ±1.94%|jsdom throws. patched-jsdom took 0.135msec.|
252
+ |querySelector('.container.box')|68,619 ops/sec ±0.41%|21,887 ops/sec ±1.07%|jsdom is 3.1 times faster. patched-jsdom took 0.046msec.|
253
+ |querySelector('.container:not(.box)')|58,150 ops/sec ±2.03%|16,315 ops/sec ±0.30%|jsdom is 3.6 times faster. patched-jsdom took 0.061msec.|
254
+ |querySelector('.box + .box')|56,085 ops/sec ±0.23%|17,980 ops/sec ±0.43%|jsdom is 3.1 times faster. patched-jsdom took 0.056msec.|
255
+ |jsdom querySelector('.box ~ .box')|58,053 ops/sec ±0.45%|8,473 ops/sec ±0.32%|jsdom is 6.9 times faster. patched-jsdom took 0.118msec.|
256
+ |querySelector('.box > .block')|834 ops/sec ±0.23%|2,513 ops/sec ±0.32%|patched-jsdom is 3.0 times faster. patched-jsdom took 0.398msec.|
257
+ |querySelector('.box .content')|422 ops/sec ±0.31%|107 ops/sec ±0.33%|jsdom is 3.9 times faster. patched-jsdom took 9.342msec.|
258
+ |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|181 ops/sec ±0.37%|236 ops/sec ±1.38%|patched-jsdom is 1.3 times faster. patched-jsdom took 4.231msec.|
259
+ |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|215 ops/sec ±1.77%|jsdom throws. patched-jsdom took 4.648msec.|
260
+ |querySelectorAll('.container.box')|80,975 ops/sec ±1.87%|18,873 ops/sec ±2.83%|jsdom is 4.3 times faster. patched-jsdom took 0.053msec.|
261
+ |querySelectorAll('.container:not(.box)')|72,800 ops/sec ±0.36%|15,009 ops/sec ±1.78%|jsdom is 4.9 times faster. patched-jsdom took 0.067msec.|
262
+ |querySelectorAll('.box + .box')|73,029 ops/sec ±2.18%|17,280 ops/sec ±2.70%|jsdom is 4.2 times faster. patched-jsdom took 0.058msec.|
263
+ |querySelectorAll('.box ~ .box')|73,630 ops/sec ±0.56%|8,192 ops/sec ±0.30%|jsdom is 9.0 times faster. patched-jsdom took 0.122msec.|
264
+ |jsdom querySelectorAll('.box > .block')|806 ops/sec ±0.27%|2,096 ops/sec ±1.77%|patched-jsdom is 2.6 times faster. patched-jsdom took 0.477msec.|
265
+ |querySelectorAll('.box .content')|409 ops/sec ±2.06%|103 ops/sec ±1.21%|jsdom is 4.0 times faster. patched-jsdom took 9.721msec.|
266
+ |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|184 ops/sec ±1.74%|240 ops/sec ±0.88%|patched-jsdom is 1.3 times faster. patched-jsdom took 4.173msec.|
267
+ |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|214 ops/sec ±1.32%|jsdom throws. patched-jsdom took 4.673msec.|
265
268
 
266
269
 
267
270
  ## Acknowledgments
@@ -1,2 +1,2 @@
1
- var V=Object.create;var L=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var G=(y,a)=>{for(var e in a)L(y,e,{get:a[e],enumerable:!0})},P=(y,a,e,n)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of H(a))!q.call(y,f)&&f!==e&&L(y,f,{get:()=>a[f],enumerable:!(n=j(a,f))||n.enumerable});return y};var Y=(y,a,e)=>(e=y!=null?V(W(y)):{},P(a||!y||!y.__esModule?L(e,"default",{value:y,enumerable:!0}):e,y)),X=y=>P(L({},"__esModule",{value:!0}),y);var Q={};G(Q,{Matcher:()=>J});module.exports=X(Q);var D=Y(require("is-potential-custom-element-name"),1),g=require("./dom-util.js"),k=require("./parser.js"),b=require("./constant.js");const C="all",A="first",S="lineal",v="self",M=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,O=/^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/,R=/^a(?:rea)?$/,U=/^d(?:etails|ialog)$/,$=/^(?:checkbox|radio)$/,x=/^(?:(?:emai|te|ur)l|number|password|search|text)$/,B=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,z=/^(?:button|reset)$/,F=/^(?:image|submit)$/,I=/^(?:date(?:time-local)?|month|time|week)$/,Z=/^(?:(?:ha|i)s|not|where)$/,K=/^nth-(?:last-)?(?:child|of-type)$/;class J{#a;#i;#e;#r;#t;#o;#l;#s;constructor(a,e,n={}){const{sort:f,warn:h}=n;this.#o=a,this.#e=e,[this.#a,this.#r]=this._prepare(a),this.#t=this._getRoot(e),this.#i=new WeakMap,this.#l=!!f,this.#s=!!h}_onError(a){if(a instanceof DOMException&&a.name===b.NOT_SUPPORTED_ERR)this.#s&&console.warn(a.message);else throw a}_getRoot(a=this.#e){let e,n;switch(a.nodeType){case b.DOCUMENT_NODE:{e=a,n=a;break}case b.DOCUMENT_FRAGMENT_NODE:{e=a.ownerDocument,n=a;break}case b.ELEMENT_NODE:{if((0,g.isSameOrDescendant)(a))e=a.ownerDocument,n=a.ownerDocument;else{let f=a;for(;f&&f.parentNode;)f=f.parentNode;e=f.ownerDocument,n=f}break}default:throw new TypeError(`Unexpected node ${a.nodeName}`)}return{document:e,root:n}}_sortLeaves(a){const e=[...a];if(e.length>1){const n=new Map([[b.ATTRIBUTE_SELECTOR,b.BIT_10000],[b.CLASS_SELECTOR,b.BIT_100],[b.ID_SELECTOR,b.BIT_10],[b.PSEUDO_CLASS_SELECTOR,b.BIT_100000],[b.PSEUDO_ELEMENT_SELECTOR,b.BIT_1],[b.TYPE_SELECTOR,b.BIT_1000]]);e.sort((f,h)=>{const{type:d}=f,{type:p}=h,u=n.get(d),t=n.get(p);let i;return u===t?i=0:u>t?i=1:i=-1,i})}return e}_prepare(a=this.#o){const e=(0,k.parseSelector)(a),n=(0,k.walkAST)(e),f=[],h=[];let d=0;for(const[...p]of n){const u=[];let t=p.shift();if(t&&t.type!==b.COMBINATOR){const i=new Set;for(;t;){if(t.type===b.COMBINATOR){const[l]=p;if(l.type===b.COMBINATOR){const c=`Invalid combinator ${t.name}${l.name}`;throw new DOMException(c,b.SYNTAX_ERR)}u.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(p.length)t=p.shift();else{u.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}f.push({branch:u,skip:!1}),h[d]=new Set,d++}return[f,h]}_collectNthChild(a,e){const{a:n,b:f,reverse:h,selector:d}=a,{parentNode:p}=e,u=new Set;let t;if(d&&(this.#i.has(d)?t=this.#i.get(d):(t=(0,k.walkAST)(d),this.#i.set(d,t))),p){const i=[...p.children],l=i.length;if(l){const c=new Set;if(t){const o=t.length;for(const s of i){let r;for(let m=0;m<o;m++){const N=t[m];if(r=this._matchLeaves(N,s),!r)break}r&&c.add(s)}}if(h&&i.reverse(),n===0){if(f>0&&f<=l){if(c.size)for(let o=0;o<l;o++){const s=i[o];if(c.has(s)){u.add(s);break}}else if(!d){const o=i[f-1];u.add(o)}}}else{let o=0,s=f-1;if(n>0)for(;s<0;)s+=++o*n;if(s>=0&&s<l){let r=n>0?0:f-1;for(let m=0;m<l&&s>=0&&s<l;m++){const N=i[m];c.size?c.has(N)&&(r===s&&(u.add(N),s+=n),n>0?r++:r--):m===s&&(d||u.add(N),s+=n)}}}}}else{const{root:i}=this.#t;if(i.nodeType===b.ELEMENT_NODE&&e===i&&n+f===1)if(t){const l=t.length;let c;for(let o=0;o<l;o++){const s=t[o];if(c=this._matchLeaves(s,e),c)break}c&&u.add(e)}else u.add(e)}return u}_collectNthOfType(a,e){const{a:n,b:f,reverse:h}=a,{localName:d,parentNode:p,prefix:u}=e,t=new Set;if(p){const i=[...p.children],l=i.length;if(l)if(h&&i.reverse(),n===0){if(f>0&&f<=l){let c=0;for(let o=0;o<l;o++){const s=i[o],{localName:r,prefix:m}=s;if(r===d&&m===u){if(c===f-1){t.add(s);break}c++}}}}else{let c=f-1;if(n>0)for(;c<0;)c+=n;if(c>=0&&c<l){let o=n>0?0:f-1;for(let s=0;s<l;s++){const r=i[s],{localName:m,prefix:N}=r;if(m===d&&N===u){if(o===c&&(t.add(r),c+=n),c<0||c>=l)break;n>0?o++:o--}}}}}else{const{root:i}=this.#t;i.nodeType===b.ELEMENT_NODE&&e===i&&n+f===1&&t.add(e)}return t}_matchAnPlusB(a,e,n){const{nth:{a:f,b:h,name:d},selector:p}=a,u=(0,k.unescapeSelector)(d),t=new Map;u?(u==="even"?(t.set("a",2),t.set("b",0)):u==="odd"&&(t.set("a",2),t.set("b",1)),/last/.test(n)&&t.set("reverse",!0)):(typeof f=="string"&&/-?\d+/.test(f)?t.set("a",f*1):t.set("a",0),typeof h=="string"&&/-?\d+/.test(h)?t.set("b",h*1):t.set("b",0),/last/.test(n)&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(n)){p&&t.set("selector",p);const l=Object.fromEntries(t),c=this._collectNthChild(l,e);c.size&&(i=c)}else if(/^nth-(?:last-)?of-type$/.test(n)){const l=Object.fromEntries(t),c=this._collectNthOfType(l,e);c.size&&(i=c)}}return i}_matchPseudoElementSelector(a,e={}){const{forgive:n}=e;switch(a){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"part":case"placeholder":case"selection":case"slotted":case"target-text":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${a}`,b.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${a}`,b.NOT_SUPPORTED_ERR)}else if(!n)throw new DOMException(`Unknown pseudo-element ::${a}`,b.SYNTAX_ERR)}}_matchDirectionPseudoClass(a,e){const n=(0,k.unescapeSelector)(a.name),f=(0,g.getDirectionality)(e);let h;return n===f&&(h=e),h??null}_matchLanguagePseudoClass(a,e){const{lang:n}=e,f=(0,k.unescapeSelector)(a.name);let h;if(f==="")e.getAttribute("lang")===""&&(h=e);else if(f==="*")e.hasAttribute("lang")||(h=e);else if(/[A-Z\d-]+/i.test(f)){const d="(?:-[A-Za-z\\d]+)?";let p;if(/-/.test(f)){const[u,t,...i]=f.split("-"),l=`${u}${d}`,c=`-${t}${d}`,o=i.length;let s="";if(o)for(let r=0;r<o;r++)s+=`-${i[r]}${d}`;p=new RegExp(`^${l}${c}${s}$`,"i")}else p=new RegExp(`^${f}${d}$`,"i");if(n)p.test(n)&&(h=e);else{let u=e;for(;u;){if(p.test(u.lang)){h=e;break}u=u.parentNode}}}return h??null}_matchHasPseudoFunc(a,e){let n;if(Array.isArray(a)&&a.length){const[f]=a,{type:h}=f;let d;h===b.COMBINATOR?d=a.shift():d={name:" ",type:b.COMBINATOR};const p=[];for(;a.length;){const[i]=a,{type:l}=i;if(l===b.COMBINATOR)break;p.push(a.shift())}const u={combo:d,leaves:p},t=this._matchCombinator(u,e,{find:"next"});if(t.size)if(a.length){for(const i of t)if(n=this._matchHasPseudoFunc(Object.assign([],a),i),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(a,e){const{astName:n="",branches:f=[],selector:h="",twigBranches:d=[]}=a;let p;if(n==="has")if(h.includes(":has("))p=null;else{let u;const t=f.length;for(let i=0;i<t;i++){const l=f[i];if(u=this._matchHasPseudoFunc(Object.assign([],l),e),u)break}u&&(p=e)}else{const u=/^(?:is|where)$/.test(n);let t;const i=d.length;for(let l=0;l<i;l++){const c=d[l],o=c.length-1,{leaves:s}=c[o];if(t=this._matchLeaves(s,e,{forgive:u}),t&&o>0){let r=new Set([e]);for(let m=o-1;m>=0;m--){const N=c[m],w=[];for(const E of r){const T=this._matchCombinator(N,E,{forgive:u,find:"prev"});T.size&&w.push(...T)}const _=new Set(w);if(_.size)if(m===0){t=!0;break}else r=_;else{t=!1;break}}}if(t)break}n==="not"?t||(p=e):t&&(p=e)}return p??null}_matchPseudoClassSelector(a,e,n={}){const{children:f}=a,{localName:h,parentNode:d}=e,{forgive:p}=n,u=(0,k.unescapeSelector)(a.name);let t=new Set;if(Z.test(u)){let i;if(this.#i.has(a))i=this.#i.get(a);else{const c=(0,k.walkAST)(a),o=[],s=[];for(const[...r]of c){for(const _ of r){const E=(0,k.generateCSS)(_);o.push(E)}const m=[],N=new Set;let w=r.shift();for(;w;)if(w.type===b.COMBINATOR?(m.push({combo:w,leaves:[...N]}),N.clear()):w&&N.add(w),r.length)w=r.shift();else{m.push({combo:null,leaves:[...N]}),N.clear();break}s.push(m)}i={astName:u,branches:c,twigBranches:s,selector:o.join(",")},this.#i.set(a,i)}const l=this._matchLogicalPseudoFunc(i,e);l&&t.add(l)}else if(Array.isArray(f)){const[i]=f;if(K.test(u)){const l=this._matchAnPlusB(i,e,u);l.size&&(t=l)}else if(u==="dir"){const l=this._matchDirectionPseudoClass(i,e);l&&t.add(l)}else if(u==="lang"){const l=this._matchLanguagePseudoClass(i,e);l&&t.add(l)}else switch(u){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${u}()`,b.NOT_SUPPORTED_ERR);break}default:if(!p)throw new DOMException(`Unknown pseudo-class :${u}()`,b.SYNTAX_ERR)}}else{const{document:i,root:l}=this.#t,{documentElement:c}=i,o=new URL(i.URL);switch(u){case"any-link":case"link":{R.test(h)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(R.test(h)&&e.hasAttribute("href")){const s=new URL(e.getAttribute("href"),o.href);s.origin===o.origin&&s.pathname===o.pathname&&t.add(e)}break}case"visited":break;case"target":{(0,g.isSameOrDescendant)(e)&&o.hash&&e.id&&o.hash===`#${e.id}`&&t.add(e);break}case"target-within":{if(o.hash){const s=o.hash.replace(/^#/,"");let r=i.getElementById(s);for(;r;){if(r===e){t.add(e);break}r=r.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?e===this.#e&&t.add(e):e===c&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let s=i.activeElement;for(;s;){if(s===e){t.add(e);break}s=s.parentNode}break}case"open":{U.test(h)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{U.test(h)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(M.test(h)||(0,D.default)(h))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let s=d;for(;s&&s.localName!=="fieldset";)s=s.parentNode;s&&s.hasAttribute("disabled")&&d.localName!=="legend"&&t.add(e)}break}case"enabled":{(M.test(h)||(0,D.default)(h))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(h){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,g.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(h){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,g.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let s;h==="textarea"?s=e:h==="input"&&(e.hasAttribute("type")?x.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&e.value===""&&t.add(e);break}case"checked":{(h==="input"&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&e.checked||h==="option"&&e.selected)&&t.add(e);break}case"indeterminate":{if(h==="input"&&e.type==="checkbox"&&e.indeterminate||h==="progress"&&!e.hasAttribute("value"))t.add(e);else if(h==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let r=e.parentNode;for(;r&&r.localName!=="form";)r=r.parentNode;r||(r=c);const m=[...r.getElementsByTagName("input")];let N;for(const w of m)if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(N=!!w.checked):w.hasAttribute("name")||(N=!!w.checked),N))break;N||t.add(e)}break}case"default":{if(h==="button"&&!(e.hasAttribute("type")&&z.test(e.getAttribute("type")))||h==="input"&&e.hasAttribute("type")&&F.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const r=i.createNodeIterator(s,b.SHOW_ELEMENT);let m=r.nextNode();for(;m;){const N=m.localName;let w;if(N==="button"?w=!(m.hasAttribute("type")&&z.test(m.getAttribute("type"))):N==="input"&&(w=m.hasAttribute("type")&&F.test(m.getAttribute("type"))),w){m===e&&t.add(e);break}m=r.nextNode()}}}else if(h==="input"&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&e.hasAttribute("checked"))t.add(e);else if(h==="option"){let s=!1,r=d;for(;r&&r.localName!=="datalist";){if(r.localName==="select"){s=!!r.multiple;break}r=r.parentNode}if(s){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR)}else{const m=d.firstElementChild,N=new Set;let w=m;for(;w;){if(w.hasAttribute("selected")){N.add(w);break}w=w.nextElementSibling}N.size||N.add(m),N.has(e)&&t.add(e)}}break}case"valid":{if(O.test(h))e.checkValidity()&&t.add(e);else if(/^fieldset$/.test(h)){const s=i.createNodeIterator(e,b.SHOW_ELEMENT);let r=s.nextNode();r===e&&(r=s.nextNode());let m;for(;r&&!(O.test(r.localName)&&(m=r.checkValidity(),!m));)r=s.nextNode();m&&t.add(e)}break}case"invalid":{if(O.test(h))e.checkValidity()||t.add(e);else if(/^fieldset$/.test(h)){const s=i.createNodeIterator(e,b.SHOW_ELEMENT);let r=s.nextNode();r===e&&(r=s.nextNode());let m;for(;r&&!(O.test(r.localName)&&(m=r.checkValidity(),!m));)r=s.nextNode();m||t.add(e)}break}case"in-range":{h==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&B.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{h==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&B.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(h))s=e;else if(h==="input")if(e.hasAttribute("type")){const r=e.getAttribute("type");(x.test(r)||$.test(r)||I.test(r)||r==="file")&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(h))s=e;else if(h==="input")if(e.hasAttribute("type")){const r=e.getAttribute("type");(x.test(r)||$.test(r)||I.test(r)||r==="file")&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===c&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const s=e.childNodes.values();let r;for(const m of s)if(r=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!r)break;r&&t.add(e)}else t.add(e);break}case"first-child":{(d&&e===d.firstElementChild||l.nodeType===b.ELEMENT_NODE&&e===l)&&t.add(e);break}case"last-child":{(d&&e===d.lastElementChild||l.nodeType===b.ELEMENT_NODE&&e===l)&&t.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||l.nodeType===b.ELEMENT_NODE&&e===l)&&t.add(e);break}case"first-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);s&&t.add(s)}else l.nodeType===b.ELEMENT_NODE&&e===l&&t.add(e);break}case"last-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&t.add(s)}else l.nodeType===b.ELEMENT_NODE&&e===l&&t.add(e);break}case"only-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[r]=this._collectNthOfType({a:0,b:1,reverse:!0},e);r===e&&t.add(e)}}else l.nodeType===b.ELEMENT_NODE&&e===l&&t.add(e);break}case"after":case"before":case"first-letter":case"first-line":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${u}`,b.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":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(this.#s)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR);break}default:if(u.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR)}else if(!p)throw new DOMException(`Unknown pseudo-class :${u}`,b.SYNTAX_ERR)}}return t}_matchAttributeSelector(a,e){const{flags:n,matcher:f,name:h,value:d}=a;if(typeof n=="string"&&!/^[is]$/i.test(n))throw new DOMException("Invalid attribute selector",b.SYNTAX_ERR);const{attributes:p}=e;let u;if(p&&p.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof n=="string"&&/^s$/i.test(n)?i=!1:i=!0:typeof n=="string"&&/^i$/i.test(n)?i=!0:i=!1;let{name:l}=h;l=(0,k.unescapeSelector)(l),i&&(l=l.toLowerCase());const c=new Set;if(/\|/.test(l)){const{prefix:o,tagName:s}=(0,g.selectorToNodeProps)(l);for(let{name:r,value:m}of p)switch(i&&(r=r.toLowerCase(),m=m.toLowerCase()),o){case"":{s===r&&c.add(m);break}case"*":{/:/.test(r)?r.endsWith(`:${s}`)&&c.add(m):s===r&&c.add(m);break}default:if(/:/.test(r)){const[N,w]=r.split(":");o===N&&s===w&&(0,g.isNamespaceDeclared)(o,e)&&c.add(m)}}}else for(let{name:o,value:s}of p)if(i&&(o=o.toLowerCase(),s=s.toLowerCase()),/:/.test(o)){const[,r]=o.split(":");l===r&&c.add(s)}else l===o&&c.add(s);if(c.size){const{name:o,value:s}=d||{};let r;switch(o?i?r=o.toLowerCase():r=o:s?i?r=s.toLowerCase():r=s:s===""&&(r=s),f){case"=":{typeof r=="string"&&c.has(r)&&(u=e);break}case"~=":{if(r&&typeof r=="string"){for(const m of c)if(new Set(m.split(/\s+/)).has(r)){u=e;break}}break}case"|=":{if(r&&typeof r=="string"){let m;for(const N of c)if(N===r||N.startsWith(`${r}-`)){m=N;break}m&&(u=e)}break}case"^=":{if(r&&typeof r=="string"){let m;for(const N of c)if(N.startsWith(`${r}`)){m=N;break}m&&(u=e)}break}case"$=":{if(r&&typeof r=="string"){let m;for(const N of c)if(N.endsWith(`${r}`)){m=N;break}m&&(u=e)}break}case"*=":{if(r&&typeof r=="string"){let m;for(const N of c)if(N.includes(`${r}`)){m=N;break}m&&(u=e)}break}case null:default:u=e}}}return u??null}_matchClassSelector(a,e){const n=(0,k.unescapeSelector)(a.name);let f;return e.classList.contains(n)&&(f=e),f??null}_matchIDSelector(a,e){const{id:n}=e,f=(0,k.unescapeSelector)(a.name);let h;return f===n&&(h=e),h??null}_matchTypeSelector(a,e){const n=(0,k.unescapeSelector)(a.name),{localName:f,prefix:h}=e,{document:d}=this.#t;let{prefix:p,tagName:u}=(0,g.selectorToNodeProps)(n,e);d.contentType==="text/html"&&(p=p.toLowerCase(),u=u.toLowerCase());let t,i;/:/.test(f)?[t,i]=f.split(":"):(t=h||"",i=f);let l;return p===""&&t===""?e.namespaceURI===null&&(u==="*"||u===i)&&(l=e):p==="*"?(u==="*"||u===i)&&(l=e):p===t&&(0,g.isNamespaceDeclared)(p,e)&&(u==="*"||u===i)&&(l=e),l??null}_matchSelector(a,e,n){const{type:f}=a;let h=new Set;if(e.nodeType===b.ELEMENT_NODE)switch(f){case b.ATTRIBUTE_SELECTOR:{const d=this._matchAttributeSelector(a,e);d&&h.add(d);break}case b.CLASS_SELECTOR:{const d=this._matchClassSelector(a,e);d&&h.add(d);break}case b.ID_SELECTOR:{const d=this._matchIDSelector(a,e);d&&h.add(d);break}case b.PSEUDO_CLASS_SELECTOR:{const d=this._matchPseudoClassSelector(a,e,n);d.size&&(h=d);break}case b.PSEUDO_ELEMENT_SELECTOR:{const d=(0,k.unescapeSelector)(a.name);this._matchPseudoElementSelector(d,n);break}case b.TYPE_SELECTOR:default:{const d=this._matchTypeSelector(a,e);d&&h.add(d)}}return h}_matchLeaves(a,e,n){let f;for(const h of a)if(f=this._matchSelector(h,e,n).has(e),!f)break;return!!f}_findDescendantNodes(a,e){const[n,...f]=a,{type:h}=n,d=(0,k.unescapeSelector)(n.name),p=f.length>0,{document:u,root:t}=this.#t;let i=new Set,l=!1;switch(h){case b.ID_SELECTOR:{if(t.nodeType===b.ELEMENT_NODE)l=!0;else{const c=t.getElementById(d);if(c&&c!==e){const o=(0,g.isSameOrDescendant)(c,e);let s;o&&(s=c),s&&(p?this._matchLeaves(f,s)&&i.add(s):i.add(s))}}break}case b.CLASS_SELECTOR:{const c=[...e.getElementsByClassName(d)];if(c.length)if(p)for(const o of c)this._matchLeaves(f,o)&&i.add(o);else i=new Set(c);break}case b.TYPE_SELECTOR:{if(u.contentType!=="text/html"||/[*|]/.test(d))l=!0;else{const c=[...e.getElementsByTagName(d)];if(c.length)if(p)for(const o of c)this._matchLeaves(f,o)&&i.add(o);else i=new Set(c)}break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:l=!0}return{nodes:i,pending:l}}_matchCombinator(a,e,n={}){const{combo:f,leaves:h}=a,{name:d}=f,{find:p,forgive:u}=n;let t=new Set;if(p==="next")switch(d){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(h,i)&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(h,i)&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[...e.children];for(const l of i)this._matchLeaves(h,l)&&t.add(l);break}case" ":default:{const{nodes:i,pending:l}=this._findDescendantNodes(h,e);if(i.size)t=i;else if(l){const{document:c}=this.#t,o=c.createNodeIterator(e,b.SHOW_ELEMENT);let s=o.nextNode();for(s===e&&(s=o.nextNode());s;)this._matchLeaves(h,s)&&t.add(s),s=o.nextNode()}}}else switch(d){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(h,i,{forgive:u})&&t.add(i);break}case"~":{const i=[];let l=e.previousElementSibling;for(;l;)this._matchLeaves(h,l,{forgive:u})&&i.push(l),l=l.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(h,i,{forgive:u})&&t.add(i);break}case" ":default:{const i=[];let l=e.parentNode;for(;l;)this._matchLeaves(h,l,{forgive:u})&&i.push(l),l=l.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(a,e){const{leaves:[n,...f]}=a,{type:h}=n,d=(0,k.unescapeSelector)(n.name),p=f.length>0,{document:u,root:t}=this.#t;let i=new Set,l=!1;switch(h){case b.ID_SELECTOR:{let c;if(e===v)this._matchLeaves([n],this.#e)&&(c=this.#e);else if(e===S){let o=this.#e;for(;o;){if(this._matchLeaves([n],o)){c=o;break}o=o.parentNode}}else t.nodeType===b.ELEMENT_NODE?l=!0:c=t.getElementById(d);c&&(p?this._matchLeaves(f,c)&&i.add(c):i.add(c));break}case b.CLASS_SELECTOR:{const c=[];if(e===v)this.#e.nodeType===b.ELEMENT_NODE&&this.#e.classList.contains(d)&&c.push(this.#e);else if(e===S){let o=this.#e;for(;o&&o.nodeType===b.ELEMENT_NODE;)o.classList.contains(d)&&c.push(o),o=o.parentNode}else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const o=[...t.children];for(const s of o){s.classList.contains(d)&&c.push(s);const r=[...s.getElementsByClassName(d)];c.push(...r)}}else{const o=[...t.getElementsByClassName(d)];c.push(...o)}if(c.length)if(p)for(const o of c)this._matchLeaves(f,o)&&i.add(o);else i=new Set(c);break}case b.TYPE_SELECTOR:{const c=[];if(e===v)this.#e.nodeType===b.ELEMENT_NODE&&this._matchLeaves([n],this.#e)&&c.push(this.#e);else if(e===S){let o=this.#e;for(;o&&o.nodeType===b.ELEMENT_NODE;)this._matchLeaves([n],o)&&c.push(o),o=o.parentNode}else if(u.contentType!=="text/html"||/[*|]/.test(d))l=!0;else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const o=d.toLowerCase(),s=[...t.children];for(const r of s){r.localName===o&&c.push(r);const m=[...r.getElementsByTagName(d)];c.push(...m)}}else{const o=[...t.getElementsByTagName(d)];c.push(...o)}if(c.length)if(p)for(const o of c)this._matchLeaves(f,o)&&i.add(o);else i=new Set(c);break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:{const c=[];if(e===v)this._matchLeaves([n],this.#e)&&c.push(this.#e);else if(e===S){let o=this.#e;for(;o;)this._matchLeaves([n],o)&&c.push(o),o=o.parentNode}else l=!0;if(c.length)if(p)for(const o of c)this._matchLeaves(f,o)&&i.add(o);else i=new Set(c)}}return{nodes:i,pending:l}}_collectNodes(a){const e=this.#a.values();if(a===C||a===A){const n=new Set;let f=0;for(const{branch:h}of e){const d=h[0],{nodes:p,pending:u}=this._findNodes(d,a);p.size?this.#r[f]=p:u?n.add(new Map([["index",f],["twig",d]])):this.#a[f].skip=!0,f++}if(n.size){const{document:h,root:d}=this.#t,p=h.createNodeIterator(d,b.SHOW_ELEMENT);let u=p.nextNode();for(;u;){let t=!1;if(this.#e.nodeType===b.ELEMENT_NODE?t=(0,g.isSameOrDescendant)(u,this.#e):t=!0,t)for(const i of n){const{leaves:l}=i.get("twig");if(this._matchLeaves(l,u)){const o=i.get("index");this.#r[o].add(u)}}u=p.nextNode()}}}else{let n=0;for(const{branch:f}of e){const h=f[f.length-1],{nodes:d}=this._findNodes(h,a);d.size?this.#r[n]=d:this.#a[n].skip=!0,n++}}return[this.#a,this.#r]}_matchNodes(a){const[...e]=this.#a,n=e.length;let f=new Set;for(let h=0;h<n;h++){const{branch:d,skip:p}=e[h],u=d.length;if(!p&&u){const t=this.#r[h],i=u-1;if(i===0)if((a===C||a===A)&&this.#e.nodeType===b.ELEMENT_NODE){for(const l of t)if(l!==this.#e&&(0,g.isSameOrDescendant)(l,this.#e)&&(f.add(l),a===A))break}else if(a===A){const[l]=[...t];f.add(l)}else{const l=[...f],c=[...t];f=new Set([...l,...c])}else if(a===C||a===A){let{combo:l}=d[0];for(const c of t){let o=new Set([c]);for(let s=1;s<u;s++){const{combo:r,leaves:m}=d[s],N=[];for(const _ of o){const E={combo:l,leaves:m},T=this._matchCombinator(E,_,{find:"next"});T.size&&N.push(...T)}const w=new Set(N);if(w.size)if(s===i){if(a===A){const[_]=[...w];f.add(_)}else{const _=[...f],E=[...w];f=new Set([..._,...E])}break}else l=r,o=w;else break}}}else for(const l of t){let c=new Set([l]),o;for(let s=i-1;s>=0;s--){const r=d[s],m=[];for(const w of c){const _=this._matchCombinator(r,w,{find:"prev"});_.size&&m.push(..._)}const N=new Set(m);if(N.size)if(o=!0,s===0){f.add(l);break}else c=N;else{o=!1;break}}if(o)break}}}return f}_find(a){return this._collectNodes(a),this._matchNodes(a)}_sortNodes(a){const e=[...a];return e.length>1&&e.sort((n,f)=>{let h;const d=n.compareDocumentPosition(f);return d&b.DOCUMENT_POSITION_PRECEDING||d&b.DOCUMENT_POSITION_CONTAINS?h=1:h=-1,h}),e}matches(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let a;try{a=this._find(v).has(this.#e)}catch(e){this._onError(e)}return!!a}closest(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let a;try{const e=this._find(S);let n=this.#e;for(;n;){if(e.has(n)){a=n;break}n=n.parentNode}}catch(e){this._onError(e)}return a??null}querySelector(){let a;try{const e=this._find(A);e.delete(this.#e),e.size>1?[a]=this._sortNodes(e):e.size&&([a]=[...e])}catch(e){this._onError(e)}return a??null}querySelectorAll(){const a=[];try{const e=this._find(C);e.delete(this.#e),e.size>1&&this.#l?a.push(...this._sortNodes(e)):e.size&&a.push(...e)}catch(e){this._onError(e)}return a}}0&&(module.exports={Matcher});
1
+ var j=Object.create;var L=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var Y=(y,l)=>{for(var e in l)L(y,e,{get:l[e],enumerable:!0})},R=(y,l,e,f)=>{if(l&&typeof l=="object"||typeof l=="function")for(let c of W(l))!G.call(y,c)&&c!==e&&L(y,c,{get:()=>l[c],enumerable:!(f=H(l,c))||f.enumerable});return y};var X=(y,l,e)=>(e=y!=null?j(q(y)):{},R(l||!y||!y.__esModule?L(e,"default",{value:y,enumerable:!0}):e,y)),Z=y=>R(L({},"__esModule",{value:!0}),y);var ee={};Y(ee,{Matcher:()=>Q});module.exports=Z(ee);var D=X(require("is-potential-custom-element-name"),1),k=require("./dom-util.js"),g=require("./parser.js"),b=require("./constant.js");const C="all",A="first",v="lineal",S="self",U=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,O=/^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/,M=/^a(?:rea)?$/,B=/^d(?:etails|ialog)$/,$=/^(?:checkbox|radio)$/,x=/^(?:(?:emai|te|ur)l|number|password|search|text)$/,z=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,F=/^(?:button|reset)$/,V=/^(?:image|submit)$/,I=/^(?:date(?:time-local)?|month|time|week)$/,K=/^(?:(?:ha|i)s|not|where)$/,J=/^nth-(?:last-)?(?:child|of-type)$/;class Q{#s;#r;#a;#e;#l;#t;#o;#c;#i;constructor(l,e,f={}){const{sort:c,warn:n}=f;this.#r=new Map([[b.ATTRIBUTE_SELECTOR,b.BIT_10000],[b.CLASS_SELECTOR,b.BIT_100],[b.ID_SELECTOR,b.BIT_10],[b.PSEUDO_CLASS_SELECTOR,b.BIT_100000],[b.PSEUDO_ELEMENT_SELECTOR,b.BIT_1],[b.TYPE_SELECTOR,b.BIT_1000]]),this.#a=new WeakMap,this.#o=l,this.#e=e,this.#c=!!c,this.#i=!!n,[this.#s,this.#l]=this._prepare(l),this.#t=this._getRoot(e)}_onError(l){if(l instanceof DOMException&&l.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw l}_getRoot(l=this.#e){let e,f;switch(l.nodeType){case b.DOCUMENT_NODE:{e=l,f=l;break}case b.DOCUMENT_FRAGMENT_NODE:{e=l.ownerDocument,f=l;break}case b.ELEMENT_NODE:{if((0,k.isSameOrDescendant)(l))e=l.ownerDocument,f=l.ownerDocument;else{let c=l;for(;c&&c.parentNode;)c=c.parentNode;e=c.ownerDocument,f=c}break}default:throw new TypeError(`Unexpected node ${l.nodeName}`)}return{document:e,root:f}}_sortLeaves(l){const e=[...l];return e.length>1&&e.sort((f,c)=>{const{type:n}=f,{type:d}=c,p=this.#r.get(n),u=this.#r.get(d);let t;return p===u?t=0:p>u?t=1:t=-1,t}),e}_prepare(l=this.#o){const e=(0,g.parseSelector)(l),f=(0,g.walkAST)(e),c=[],n=[];let d=0;for(const[...p]of f){const u=[];let t=p.shift();if(t&&t.type!==b.COMBINATOR){const i=new Set;for(;t;){if(t.type===b.COMBINATOR){const[h]=p;if(h.type===b.COMBINATOR){const r=`Invalid combinator ${t.name}${h.name}`;throw new DOMException(r,b.SYNTAX_ERR)}u.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(p.length)t=p.shift();else{u.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}c.push({branch:u,find:null,skip:!1}),n[d]=new Set,d++}return[c,n]}_collectNthChild(l,e){const{a:f,b:c,reverse:n,selector:d}=l,{parentNode:p}=e,u=new Set;let t;if(d&&(this.#a.has(d)?t=this.#a.get(d):(t=(0,g.walkAST)(d),this.#a.set(d,t))),p){const i=[...p.children],h=i.length;if(h){const r=new Set;if(t){const o=t.length;for(const s of i){let a;for(let m=0;m<o;m++){const N=t[m];if(a=this._matchLeaves(N,s),!a)break}a&&r.add(s)}}if(n&&i.reverse(),f===0){if(c>0&&c<=h){if(r.size)for(let o=0;o<h;o++){const s=i[o];if(r.has(s)){u.add(s);break}}else if(!d){const o=i[c-1];u.add(o)}}}else{let o=0,s=c-1;if(f>0)for(;s<0;)s+=++o*f;if(s>=0&&s<h){let a=f>0?0:c-1;for(let m=0;m<h&&s>=0&&s<h;m++){const N=i[m];r.size?r.has(N)&&(a===s&&(u.add(N),s+=f),f>0?a++:a--):m===s&&(d||u.add(N),s+=f)}}}}}else{const{root:i}=this.#t;if(i.nodeType===b.ELEMENT_NODE&&e===i&&f+c===1)if(t){const h=t.length;let r;for(let o=0;o<h;o++){const s=t[o];if(r=this._matchLeaves(s,e),r)break}r&&u.add(e)}else u.add(e)}return u}_collectNthOfType(l,e){const{a:f,b:c,reverse:n}=l,{localName:d,parentNode:p,prefix:u}=e,t=new Set;if(p){const i=[...p.children],h=i.length;if(h)if(n&&i.reverse(),f===0){if(c>0&&c<=h){let r=0;for(let o=0;o<h;o++){const s=i[o],{localName:a,prefix:m}=s;if(a===d&&m===u){if(r===c-1){t.add(s);break}r++}}}}else{let r=c-1;if(f>0)for(;r<0;)r+=f;if(r>=0&&r<h){let o=f>0?0:c-1;for(let s=0;s<h;s++){const a=i[s],{localName:m,prefix:N}=a;if(m===d&&N===u){if(o===r&&(t.add(a),r+=f),r<0||r>=h)break;f>0?o++:o--}}}}}else{const{root:i}=this.#t;i.nodeType===b.ELEMENT_NODE&&e===i&&f+c===1&&t.add(e)}return t}_matchAnPlusB(l,e,f){const{nth:{a:c,b:n,name:d},selector:p}=l,u=(0,g.unescapeSelector)(d),t=new Map;u?(u==="even"?(t.set("a",2),t.set("b",0)):u==="odd"&&(t.set("a",2),t.set("b",1)),/last/.test(f)&&t.set("reverse",!0)):(typeof c=="string"&&/-?\d+/.test(c)?t.set("a",c*1):t.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?t.set("b",n*1):t.set("b",0),/last/.test(f)&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(f)){p&&t.set("selector",p);const h=Object.fromEntries(t),r=this._collectNthChild(h,e);r.size&&(i=r)}else if(/^nth-(?:last-)?of-type$/.test(f)){const h=Object.fromEntries(t),r=this._collectNthOfType(h,e);r.size&&(i=r)}}return i}_matchPseudoElementSelector(l,e={}){const{forgive:f}=e;switch(l){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"part":case"placeholder":case"selection":case"slotted":case"target-text":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${l}`,b.NOT_SUPPORTED_ERR);break}default:if(l.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${l}`,b.NOT_SUPPORTED_ERR)}else if(!f)throw new DOMException(`Unknown pseudo-element ::${l}`,b.SYNTAX_ERR)}}_matchDirectionPseudoClass(l,e){const f=(0,g.unescapeSelector)(l.name),c=(0,k.getDirectionality)(e);let n;return f===c&&(n=e),n??null}_matchLanguagePseudoClass(l,e){const{lang:f}=e,c=(0,g.unescapeSelector)(l.name);let n;if(c==="")e.getAttribute("lang")===""&&(n=e);else if(c==="*")e.hasAttribute("lang")||(n=e);else if(/[A-Z\d-]+/i.test(c)){const d="(?:-[A-Za-z\\d]+)?";let p;if(/-/.test(c)){const[u,t,...i]=c.split("-"),h=`${u}${d}`,r=`-${t}${d}`,o=i.length;let s="";if(o)for(let a=0;a<o;a++)s+=`-${i[a]}${d}`;p=new RegExp(`^${h}${r}${s}$`,"i")}else p=new RegExp(`^${c}${d}$`,"i");if(f)p.test(f)&&(n=e);else{let u=e;for(;u;){if(p.test(u.lang)){n=e;break}u=u.parentNode}}}return n??null}_matchHasPseudoFunc(l,e){let f;if(Array.isArray(l)&&l.length){const[c]=l,{type:n}=c;let d;n===b.COMBINATOR?d=l.shift():d={name:" ",type:b.COMBINATOR};const p=[];for(;l.length;){const[i]=l,{type:h}=i;if(h===b.COMBINATOR)break;p.push(l.shift())}const u={combo:d,leaves:p},t=this._matchCombinator(u,e,{find:"next"});if(t.size)if(l.length){for(const i of t)if(f=this._matchHasPseudoFunc(Object.assign([],l),i),f)break}else f=!0}return!!f}_matchLogicalPseudoFunc(l,e){const{astName:f="",branches:c=[],selector:n="",twigBranches:d=[]}=l;let p;if(f==="has")if(n.includes(":has("))p=null;else{let u;const t=c.length;for(let i=0;i<t;i++){const h=c[i];if(u=this._matchHasPseudoFunc(Object.assign([],h),e),u)break}u&&(p=e)}else{const u=/^(?:is|where)$/.test(f);let t;const i=d.length;for(let h=0;h<i;h++){const r=d[h],o=r.length-1,{leaves:s}=r[o];if(t=this._matchLeaves(s,e,{forgive:u}),t&&o>0){let a=new Set([e]);for(let m=o-1;m>=0;m--){const N=r[m],w=[];for(const _ of a){const T=this._matchCombinator(N,_,{forgive:u,find:"prev"});T.size&&w.push(...T)}const E=new Set(w);if(E.size)if(m===0){t=!0;break}else a=E;else{t=!1;break}}}if(t)break}f==="not"?t||(p=e):t&&(p=e)}return p??null}_matchPseudoClassSelector(l,e,f={}){const{children:c}=l,{localName:n,parentNode:d}=e,{forgive:p}=f,u=(0,g.unescapeSelector)(l.name);let t=new Set;if(K.test(u)){let i;if(this.#a.has(l))i=this.#a.get(l);else{const r=(0,g.walkAST)(l),o=[],s=[];for(const[...a]of r){for(const E of a){const _=(0,g.generateCSS)(E);o.push(_)}const m=[],N=new Set;let w=a.shift();for(;w;)if(w.type===b.COMBINATOR?(m.push({combo:w,leaves:[...N]}),N.clear()):w&&N.add(w),a.length)w=a.shift();else{m.push({combo:null,leaves:[...N]}),N.clear();break}s.push(m)}i={astName:u,branches:r,twigBranches:s,selector:o.join(",")},this.#a.set(l,i)}const h=this._matchLogicalPseudoFunc(i,e);h&&t.add(h)}else if(Array.isArray(c)){const[i]=c;if(J.test(u)){const h=this._matchAnPlusB(i,e,u);h.size&&(t=h)}else if(u==="dir"){const h=this._matchDirectionPseudoClass(i,e);h&&t.add(h)}else if(u==="lang"){const h=this._matchLanguagePseudoClass(i,e);h&&t.add(h)}else switch(u){case"current":case"nth-col":case"nth-last-col":{if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}()`,b.NOT_SUPPORTED_ERR);break}default:if(!p)throw new DOMException(`Unknown pseudo-class :${u}()`,b.SYNTAX_ERR)}}else{const{document:i,root:h}=this.#t,{documentElement:r}=i,o=new URL(i.URL);switch(u){case"any-link":case"link":{M.test(n)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(M.test(n)&&e.hasAttribute("href")){const s=new URL(e.getAttribute("href"),o.href);s.origin===o.origin&&s.pathname===o.pathname&&t.add(e)}break}case"visited":break;case"target":{(0,k.isSameOrDescendant)(e)&&o.hash&&e.id&&o.hash===`#${e.id}`&&t.add(e);break}case"target-within":{if(o.hash){const s=o.hash.replace(/^#/,"");let a=i.getElementById(s);for(;a;){if(a===e){t.add(e);break}a=a.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?e===this.#e&&t.add(e):e===r&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let s=i.activeElement;for(;s;){if(s===e){t.add(e);break}s=s.parentNode}break}case"open":{B.test(n)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{B.test(n)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(U.test(n)||(0,D.default)(n))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let s=d;for(;s&&s.localName!=="fieldset";)s=s.parentNode;s&&s.hasAttribute("disabled")&&d.localName!=="legend"&&t.add(e)}break}case"enabled":{(U.test(n)||(0,D.default)(n))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(n){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(n){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let s;n==="textarea"?s=e:n==="input"&&(e.hasAttribute("type")?x.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&e.value===""&&t.add(e);break}case"checked":{(n==="input"&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&e.checked||n==="option"&&e.selected)&&t.add(e);break}case"indeterminate":{if(n==="input"&&e.type==="checkbox"&&e.indeterminate||n==="progress"&&!e.hasAttribute("value"))t.add(e);else if(n==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let a=e.parentNode;for(;a&&a.localName!=="form";)a=a.parentNode;a||(a=r);const m=[...a.getElementsByTagName("input")];let N;for(const w of m)if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(N=!!w.checked):w.hasAttribute("name")||(N=!!w.checked),N))break;N||t.add(e)}break}case"default":{if(n==="button"&&!(e.hasAttribute("type")&&F.test(e.getAttribute("type")))||n==="input"&&e.hasAttribute("type")&&V.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const a=i.createNodeIterator(s,b.SHOW_ELEMENT);let m=a.nextNode();for(;m;){const N=m.localName;let w;if(N==="button"?w=!(m.hasAttribute("type")&&F.test(m.getAttribute("type"))):N==="input"&&(w=m.hasAttribute("type")&&V.test(m.getAttribute("type"))),w){m===e&&t.add(e);break}m=a.nextNode()}}}else if(n==="input"&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(n==="option"){let s=!1,a=d;for(;a&&a.localName!=="datalist";){if(a.localName==="select"){(a.multiple||a.hasAttribute("multiple"))&&(s=!0);break}a=a.parentNode}if(s)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const m=d.firstElementChild,N=new Set;let w=m;for(;w;){if(w.selected||w.hasAttribute("selected")){N.add(w);break}w=w.nextElementSibling}N.size||N.add(m),N.has(e)&&t.add(e)}}break}case"valid":{if(O.test(n))e.checkValidity()&&t.add(e);else if(/^fieldset$/.test(n)){const s=i.createNodeIterator(e,b.SHOW_ELEMENT);let a=s.nextNode();a===e&&(a=s.nextNode());let m;for(;a&&!(O.test(a.localName)&&(m=a.checkValidity(),!m));)a=s.nextNode();m&&t.add(e)}break}case"invalid":{if(O.test(n))e.checkValidity()||t.add(e);else if(/^fieldset$/.test(n)){const s=i.createNodeIterator(e,b.SHOW_ELEMENT);let a=s.nextNode();a===e&&(a=s.nextNode());let m;for(;a&&!(O.test(a.localName)&&(m=a.checkValidity(),!m));)a=s.nextNode();m||t.add(e)}break}case"in-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&z.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&z.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(n))s=e;else if(n==="input")if(e.hasAttribute("type")){const a=e.getAttribute("type");(x.test(a)||$.test(a)||I.test(a)||a==="file")&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(n))s=e;else if(n==="input")if(e.hasAttribute("type")){const a=e.getAttribute("type");(x.test(a)||$.test(a)||I.test(a)||a==="file")&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===r&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const s=e.childNodes.values();let a;for(const m of s)if(a=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!a)break;a&&t.add(e)}else t.add(e);break}case"first-child":{(d&&e===d.firstElementChild||h.nodeType===b.ELEMENT_NODE&&e===h)&&t.add(e);break}case"last-child":{(d&&e===d.lastElementChild||h.nodeType===b.ELEMENT_NODE&&e===h)&&t.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||h.nodeType===b.ELEMENT_NODE&&e===h)&&t.add(e);break}case"first-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);s&&t.add(s)}else h.nodeType===b.ELEMENT_NODE&&e===h&&t.add(e);break}case"last-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&t.add(s)}else h.nodeType===b.ELEMENT_NODE&&e===h&&t.add(e);break}case"only-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[a]=this._collectNthOfType({a:0,b:1,reverse:!0},e);a===e&&t.add(e)}}else h.nodeType===b.ELEMENT_NODE&&e===h&&t.add(e);break}case"after":case"before":case"first-letter":case"first-line":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${u}`,b.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":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(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR);break}default:if(u.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR)}else if(!p)throw new DOMException(`Unknown pseudo-class :${u}`,b.SYNTAX_ERR)}}return t}_matchAttributeSelector(l,e){const{flags:f,matcher:c,name:n,value:d}=l;if(typeof f=="string"&&!/^[is]$/i.test(f))throw new DOMException("Invalid attribute selector",b.SYNTAX_ERR);const{attributes:p}=e;let u;if(p&&p.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof f=="string"&&/^s$/i.test(f)?i=!1:i=!0:typeof f=="string"&&/^i$/i.test(f)?i=!0:i=!1;let{name:h}=n;h=(0,g.unescapeSelector)(h),i&&(h=h.toLowerCase());const r=new Set;if(/\|/.test(h)){const{prefix:o,tagName:s}=(0,k.selectorToNodeProps)(h);for(let{name:a,value:m}of p)switch(i&&(a=a.toLowerCase(),m=m.toLowerCase()),o){case"":{s===a&&r.add(m);break}case"*":{/:/.test(a)?a.endsWith(`:${s}`)&&r.add(m):s===a&&r.add(m);break}default:if(/:/.test(a)){const[N,w]=a.split(":");o===N&&s===w&&(0,k.isNamespaceDeclared)(o,e)&&r.add(m)}}}else for(let{name:o,value:s}of p)if(i&&(o=o.toLowerCase(),s=s.toLowerCase()),/:/.test(o)){const[,a]=o.split(":");h===a&&r.add(s)}else h===o&&r.add(s);if(r.size){const{name:o,value:s}=d||{};let a;switch(o?i?a=o.toLowerCase():a=o:s?i?a=s.toLowerCase():a=s:s===""&&(a=s),c){case"=":{typeof a=="string"&&r.has(a)&&(u=e);break}case"~=":{if(a&&typeof a=="string"){for(const m of r)if(new Set(m.split(/\s+/)).has(a)){u=e;break}}break}case"|=":{if(a&&typeof a=="string"){let m;for(const N of r)if(N===a||N.startsWith(`${a}-`)){m=N;break}m&&(u=e)}break}case"^=":{if(a&&typeof a=="string"){let m;for(const N of r)if(N.startsWith(`${a}`)){m=N;break}m&&(u=e)}break}case"$=":{if(a&&typeof a=="string"){let m;for(const N of r)if(N.endsWith(`${a}`)){m=N;break}m&&(u=e)}break}case"*=":{if(a&&typeof a=="string"){let m;for(const N of r)if(N.includes(`${a}`)){m=N;break}m&&(u=e)}break}case null:default:u=e}}}return u??null}_matchClassSelector(l,e){const f=(0,g.unescapeSelector)(l.name);let c;return e.classList.contains(f)&&(c=e),c??null}_matchIDSelector(l,e){const{id:f}=e,c=(0,g.unescapeSelector)(l.name);let n;return c===f&&(n=e),n??null}_matchTypeSelector(l,e){const f=(0,g.unescapeSelector)(l.name),{localName:c,prefix:n}=e,{document:d}=this.#t;let{prefix:p,tagName:u}=(0,k.selectorToNodeProps)(f,e);d.contentType==="text/html"&&(p=p.toLowerCase(),u=u.toLowerCase());let t,i;/:/.test(c)?[t,i]=c.split(":"):(t=n||"",i=c);let h;return p===""&&t===""?e.namespaceURI===null&&(u==="*"||u===i)&&(h=e):p==="*"?(u==="*"||u===i)&&(h=e):p===t&&(0,k.isNamespaceDeclared)(p,e)&&(u==="*"||u===i)&&(h=e),h??null}_matchSelector(l,e,f){const{type:c}=l;let n=new Set;if(e.nodeType===b.ELEMENT_NODE)switch(c){case b.ATTRIBUTE_SELECTOR:{const d=this._matchAttributeSelector(l,e);d&&n.add(d);break}case b.CLASS_SELECTOR:{const d=this._matchClassSelector(l,e);d&&n.add(d);break}case b.ID_SELECTOR:{const d=this._matchIDSelector(l,e);d&&n.add(d);break}case b.PSEUDO_CLASS_SELECTOR:{const d=this._matchPseudoClassSelector(l,e,f);d.size&&(n=d);break}case b.PSEUDO_ELEMENT_SELECTOR:{const d=(0,g.unescapeSelector)(l.name);this._matchPseudoElementSelector(d,f);break}case b.TYPE_SELECTOR:default:{const d=this._matchTypeSelector(l,e);d&&n.add(d)}}return n}_matchLeaves(l,e,f){let c;for(const n of l)if(c=this._matchSelector(n,e,f).has(e),!c)break;return!!c}_findDescendantNodes(l,e){const[f,...c]=l,{type:n}=f,d=(0,g.unescapeSelector)(f.name),p=c.length>0,{document:u,root:t}=this.#t;let i=new Set,h=!1;switch(n){case b.ID_SELECTOR:{if(t.nodeType===b.ELEMENT_NODE)h=!0;else{const r=t.getElementById(d);if(r&&r!==e){const o=(0,k.isSameOrDescendant)(r,e);let s;o&&(s=r),s&&(p?this._matchLeaves(c,s)&&i.add(s):i.add(s))}}break}case b.CLASS_SELECTOR:{const r=[...e.getElementsByClassName(d)];if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r);break}case b.TYPE_SELECTOR:{if(u.contentType!=="text/html"||/[*|]/.test(d))h=!0;else{const r=[...e.getElementsByTagName(d)];if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r)}break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:h=!0}return{nodes:i,pending:h}}_matchCombinator(l,e,f={}){const{combo:c,leaves:n}=l,{name:d}=c,{find:p,forgive:u}=f;let t=new Set;if(p==="next")switch(d){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(n,i)&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(n,i)&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[...e.children];for(const h of i)this._matchLeaves(n,h)&&t.add(h);break}case" ":default:{const{nodes:i,pending:h}=this._findDescendantNodes(n,e);if(i.size)t=i;else if(h){const{document:r}=this.#t,o=r.createNodeIterator(e,b.SHOW_ELEMENT);let s=o.nextNode();for(s===e&&(s=o.nextNode());s;)this._matchLeaves(n,s)&&t.add(s),s=o.nextNode()}}}else switch(d){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(n,i,{forgive:u})&&t.add(i);break}case"~":{const i=[];let h=e.previousElementSibling;for(;h;)this._matchLeaves(n,h,{forgive:u})&&i.push(h),h=h.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(n,i,{forgive:u})&&t.add(i);break}case" ":default:{const i=[];let h=e.parentNode;for(;h;)this._matchLeaves(n,h,{forgive:u})&&i.push(h),h=h.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(l,e){const{leaves:[f,...c]}=l,{type:n}=f,d=(0,g.unescapeSelector)(f.name),p=c.length>0,{document:u,root:t}=this.#t;let i=new Set,h=!1;switch(n){case b.ID_SELECTOR:{let r;if(e===S)this._matchLeaves([f],this.#e)&&(r=this.#e);else if(e===v){let o=this.#e;for(;o;){if(this._matchLeaves([f],o)){r=o;break}o=o.parentNode}}else t.nodeType===b.ELEMENT_NODE?h=!0:r=t.getElementById(d);r&&(p?this._matchLeaves(c,r)&&i.add(r):i.add(r));break}case b.CLASS_SELECTOR:{const r=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this.#e.classList.contains(d)&&r.push(this.#e);else if(e===v){let o=this.#e;for(;o&&o.nodeType===b.ELEMENT_NODE;)o.classList.contains(d)&&r.push(o),o=o.parentNode}else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const o=[...t.children];for(const s of o){s.classList.contains(d)&&r.push(s);const a=[...s.getElementsByClassName(d)];r.push(...a)}}else{const o=[...t.getElementsByClassName(d)];r.push(...o)}if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r);break}case b.TYPE_SELECTOR:{const r=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this._matchLeaves([f],this.#e)&&r.push(this.#e);else if(e===v){let o=this.#e;for(;o&&o.nodeType===b.ELEMENT_NODE;)this._matchLeaves([f],o)&&r.push(o),o=o.parentNode}else if(u.contentType!=="text/html"||/[*|]/.test(d))h=!0;else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const o=d.toLowerCase(),s=[...t.children];for(const a of s){a.localName===o&&r.push(a);const m=[...a.getElementsByTagName(d)];r.push(...m)}}else{const o=[...t.getElementsByTagName(d)];r.push(...o)}if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r);break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:{const r=[];if(e===S)this._matchLeaves([f],this.#e)&&r.push(this.#e);else if(e===v){let o=this.#e;for(;o;)this._matchLeaves([f],o)&&r.push(o),o=o.parentNode}else h=!0;if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r)}}return{nodes:i,pending:h}}_getFirstTwig(l){const e=l.length-1,f=l[0];let c,n;if(e){const d=l[e],{leaves:[{type:p}]}=d;p===b.PSEUDO_ELEMENT_SELECTOR||p===b.ID_SELECTOR?(c="prev",n=d):(c="next",n=f)}else c="prev",n=f;return{find:c,twig:n}}_collectNodes(l){const e=this.#s.values();if(l===C||l===A){const f=new Set;let c=0;for(const{branch:n}of e){const{find:d,twig:p}=this._getFirstTwig(n),{nodes:u,pending:t}=this._findNodes(p,l);u.size?this.#l[c]=u:t?f.add(new Map([["index",c],["twig",p]])):this.#s[c].skip=!0,this.#s[c].find=d,c++}if(f.size){const{document:n,root:d}=this.#t,p=n.createNodeIterator(d,b.SHOW_ELEMENT);let u=p.nextNode();for(;u;){let t=!1;if(this.#e.nodeType===b.ELEMENT_NODE?t=(0,k.isSameOrDescendant)(u,this.#e):t=!0,t)for(const i of f){const{leaves:h}=i.get("twig");if(this._matchLeaves(h,u)){const o=i.get("index");this.#l[o].add(u)}}u=p.nextNode()}}}else{let f=0;for(const{branch:c}of e){const n=c[c.length-1],{nodes:d}=this._findNodes(n,l);d.size?this.#l[f]=d:this.#s[f].skip=!0,this.#s[f].find="prev",f++}}return[this.#s,this.#l]}_matchNodes(l){const[...e]=this.#s,f=e.length;let c=new Set;for(let n=0;n<f;n++){const{branch:d,find:p,skip:u}=e[n],t=d.length;if(!u&&t){const i=this.#l[n],h=t-1;if(h===0)if((l===C||l===A)&&this.#e.nodeType===b.ELEMENT_NODE){for(const r of i)if(r!==this.#e&&(0,k.isSameOrDescendant)(r,this.#e)&&(c.add(r),l===A))break}else if(l===A){const[r]=[...i];c.add(r)}else{const r=[...c],o=[...i];c=new Set([...r,...o])}else if(p==="next"){let{combo:r}=d[0];for(const o of i){let s=new Set([o]);for(let a=1;a<t;a++){const{combo:m,leaves:N}=d[a],w=[];for(const _ of s){const T={combo:r,leaves:N},P=this._matchCombinator(T,_,{find:p});P.size&&w.push(...P)}const E=new Set(w);if(E.size)if(a===h){if(l===A){const[_]=[...E];c.add(_)}else{const _=[...c],T=[...E];c=new Set([..._,...T])}break}else r=m,s=E;else break}}}else for(const r of i){let o=new Set([r]),s;for(let a=h-1;a>=0;a--){const m=d[a],N=[];for(const E of o){const _=this._matchCombinator(m,E,{find:p});_.size&&N.push(..._)}const w=new Set(N);if(w.size)if(s=!0,a===0){c.add(r);break}else o=w;else{s=!1;break}}if(s&&l!==C)break}}}return c}_find(l){return this._collectNodes(l),this._matchNodes(l)}_sortNodes(l){const e=[...l];return e.length>1&&e.sort((f,c)=>{let n;const d=f.compareDocumentPosition(c);return d&b.DOCUMENT_POSITION_PRECEDING||d&b.DOCUMENT_POSITION_CONTAINS?n=1:n=-1,n}),e}matches(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let l;try{l=this._find(S).has(this.#e)}catch(e){this._onError(e)}return!!l}closest(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let l;try{const e=this._find(v);let f=this.#e;for(;f;){if(e.has(f)){l=f;break}f=f.parentNode}}catch(e){this._onError(e)}return l??null}querySelector(){let l;try{const e=this._find(A);e.delete(this.#e),e.size>1?[l]=this._sortNodes(e):e.size&&([l]=[...e])}catch(e){this._onError(e)}return l??null}querySelectorAll(){const l=[];try{const e=this._find(C);e.delete(this.#e),e.size>1&&this.#c?l.push(...this._sortNodes(e)):e.size&&l.push(...e)}catch(e){this._onError(e)}return l}}0&&(module.exports={Matcher});
2
2
  //# sourceMappingURL=matcher.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/matcher.js"],
4
- "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isNamespaceDeclared, isSameOrDescendant,\n selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ATTRIBUTE_SELECTOR, BIT_1, BIT_10, BIT_100, BIT_1000, BIT_10000, BIT_100000,\n CLASS_SELECTOR, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,\n DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n ID_SELECTOR, NOT_SUPPORTED_ERR, PSEUDO_CLASS_SELECTOR,\n PSEUDO_ELEMENT_SELECTOR, SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE, TYPE_SELECTOR\n} from './constant.js';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/* regexp */\nconst FORM_PARTS =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\nconst FORM_VALIDITY = /^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/;\nconst HTML_ANCHOR = /^a(?:rea)?$/;\nconst HTML_INTERACT = /^d(?:etails|ialog)$/;\nconst INPUT_CHECK = /^(?:checkbox|radio)$/;\nconst INPUT_EDIT = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\nconst INPUT_RANGE = /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\nconst INPUT_RESET = /^(?:button|reset)$/;\nconst INPUT_SUBMIT = /^(?:image|submit)$/;\nconst INPUT_TIME = /^(?:date(?:time-local)?|month|time|week)$/;\nconst PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;\nconst PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * skip: boolean\n * }\n * ]\n * #nodes: [\n * Set([node{}, node{}]),\n * Set([node{}, node, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: AST leaf\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #cache;\n #node;\n #nodes;\n #root;\n #selector;\n #sort;\n #warn;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.sort] - sort results of querySelectorAll()\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { sort, warn } = opt;\n this.#selector = selector;\n this.#node = node;\n [this.#ast, this.#nodes] = this._prepare(selector);\n this.#root = this._getRoot(node);\n this.#cache = new WeakMap();\n this.#sort = !!sort;\n this.#warn = !!warn;\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException && e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw e;\n }\n }\n\n /**\n * get root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - root object\n */\n _getRoot(node = this.#node) {\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (isSameOrDescendant(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n document = parent.ownerDocument;\n root = parent;\n }\n break;\n }\n default: {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n return {\n document,\n root\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n const bitMap = new Map([\n [ATTRIBUTE_SELECTOR, BIT_10000],\n [CLASS_SELECTOR, BIT_100],\n [ID_SELECTOR, BIT_10],\n [PSEUDO_CLASS_SELECTOR, BIT_100000],\n [PSEUDO_ELEMENT_SELECTOR, BIT_1],\n [TYPE_SELECTOR, BIT_1000]\n ]);\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = bitMap.get(typeA);\n const bitB = bitMap.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * prepare ast and nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - list and matrix\n */\n _prepare(selector = this.#selector) {\n const ast = parseSelector(selector);\n const branches = walkAST(ast);\n const tree = [];\n const nodes = [];\n let i = 0;\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid combinator ${item.name}${nextItem.name}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n tree.push({\n branch,\n skip: false\n });\n nodes[i] = new Set();\n i++;\n }\n return [\n tree,\n nodes\n ];\n }\n\n /**\n * collect nth child\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {object} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#cache.has(selector)) {\n selectorBranches = this.#cache.get(selector);\n } else {\n selectorBranches = walkAST(selector);\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const arr = [...parentNode.children];\n const l = arr.length;\n if (l) {\n const selectorNodes = new Set();\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n for (const refNode of arr) {\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, refNode);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n }\n if (reverse) {\n arr.reverse();\n }\n // :first-child, :last-child, :nth-child(0 of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n if (selectorNodes.has(current)) {\n matched.add(current);\n break;\n }\n }\n } else if (!selector) {\n const current = arr[b - 1];\n matched.add(current);\n }\n }\n // :nth-child()\n } else {\n let n = 0;\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += (++n * a);\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l && nth >= 0 && nth < l; i++) {\n const current = arr[i];\n if (selectorNodes.size) {\n if (selectorNodes.has(current)) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(current);\n }\n nth += a;\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE && node === root && (a + b) === 1) {\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {object} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const arr = [...parentNode.children];\n const l = arr.length;\n if (l) {\n if (reverse) {\n arr.reverse();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(current);\n break;\n }\n j++;\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE && node === root && (a + b) === 1) {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {object} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (/last/.test(nthName)) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (/last/.test(nthName)) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} opt - options\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'part':\n case 'placeholder':\n case 'selection':\n case 'slotted':\n case 'target-text': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const { lang } = node;\n const astName = unescapeSelector(ast.name);\n let res;\n // TBD: what about xml:lang?\n if (astName === '') {\n if (node.getAttribute('lang') === '') {\n res = node;\n }\n } else if (astName === '*') {\n if (!node.hasAttribute('lang')) {\n res = node;\n }\n } else if (/[A-Z\\d-]+/i.test(astName)) {\n const codePart = '(?:-[A-Za-z\\\\d]+)?';\n let reg;\n if (/-/.test(astName)) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n const extendedMain = `${langMain}${codePart}`;\n const extendedSub = `-${langSub}${codePart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${codePart}`;\n }\n }\n reg = new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n reg = new RegExp(`^${astName}${codePart}$`, 'i');\n }\n if (lang) {\n if (reg.test(lang)) {\n res = node;\n }\n } else {\n let target = node;\n while (target) {\n if (reg.test(target.lang)) {\n res = node;\n break;\n }\n target = target.parentNode;\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n find: 'next'\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n let bool;\n const l = branches.length;\n for (let i = 0; i < l; i++) {\n const leaves = branches[i];\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n let bool;\n const l = twigBranches.length;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, {\n forgive\n });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n find: 'prev'\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = matchedNodes;\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {object} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (PSEUDO_FUNC.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (PSEUDO_NTH.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n const { document, root } = this.#root;\n const { documentElement } = document;\n const docURL = new URL(document.URL);\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const attrURL = new URL(node.getAttribute('href'), docURL.href);\n if (attrURL.origin === docURL.origin &&\n attrURL.pathname === docURL.pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n if (isSameOrDescendant(node) && docURL.hash &&\n node.id && docURL.hash === `#${node.id}`) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n if (docURL.hash) {\n const hash = docURL.hash.replace(/^#/, '');\n let current = document.getElementById(hash);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (node === this.#node) {\n matched.add(node);\n }\n } else if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === document.activeElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (HTML_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (HTML_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (FORM_PARTS.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parent.hasAttribute('disabled') &&\n parentNode.localName !== 'legend') {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((FORM_PARTS.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (INPUT_EDIT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length &&\n node.value === '') {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n node.checked) ||\n (localName === 'option' && node.selected)) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((localName === 'input' && node.type === 'checkbox' &&\n node.indeterminate) ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = documentElement;\n }\n const nodes = [...parent.getElementsByTagName('input')];\n let checked;\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n INPUT_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n INPUT_SUBMIT.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const iterator = document.createNodeIterator(form, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n INPUT_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n INPUT_SUBMIT.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = iterator.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n node.hasAttribute('checked')) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let isMultiple = false;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'datalist') {\n break;\n } else if (parent.localName === 'select') {\n isMultiple = !!parent.multiple;\n break;\n }\n parent = parent.parentNode;\n }\n // FIXME:\n if (isMultiple) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else {\n const firstOpt = parentNode.firstElementChild;\n const defaultOpt = new Set();\n let opt = firstOpt;\n while (opt) {\n if (opt.hasAttribute('selected')) {\n defaultOpt.add(opt);\n break;\n }\n opt = opt.nextElementSibling;\n }\n if (!defaultOpt.size) {\n defaultOpt.add(firstOpt);\n }\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'valid': {\n if (FORM_VALIDITY.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (FORM_VALIDITY.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (FORM_VALIDITY.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (FORM_VALIDITY.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n INPUT_RANGE.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n INPUT_RANGE.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const nodes = node.childNodes.values();\n let bool;\n for (const refNode of nodes) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'focus-visible':\n case 'fullscreen':\n case 'future':\n case 'hover':\n case 'modal':\n case 'muted':\n case 'past':\n case 'paused':\n case 'picture-in-picture':\n case 'playing':\n case 'seeking':\n case 'stalled':\n case 'user-invalid':\n case 'user-valid':\n case 'volume-locked':\n case '-webkit-autofill': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n throw new DOMException('Invalid attribute selector', SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const { document } = this.#root;\n let caseInsensitive;\n if (document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let { name: astAttrName } = astName;\n astAttrName = unescapeSelector(astAttrName);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (/\\|/.test(astAttrName)) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (/:/.test(itemName)) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (/:/.test(itemName)) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (/:/.test(itemName)) {\n const [, itemNameLocalName] = itemName.split(':');\n if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const { id } = node;\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { document } = this.#root;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (/:/.test(localName)) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix &&\n isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n }\n return res ?? null;\n };\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {object} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type } = ast;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (type) {\n case ATTRIBUTE_SELECTOR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case CLASS_SELECTOR: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case ID_SELECTOR: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case PSEUDO_CLASS_SELECTOR: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n const astName = unescapeSelector(ast.name);\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case TYPE_SELECTOR:\n default: {\n const res = this._matchTypeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - result\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...items] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const elm = root.getElementById(leafName);\n if (elm && elm !== baseNode) {\n const bool = isSameOrDescendant(elm, baseNode);\n let node;\n if (bool) {\n node = elm;\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n }\n break;\n }\n case CLASS_SELECTOR: {\n const arr = [...baseNode.getElementsByClassName(leafName)];\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case TYPE_SELECTOR: {\n if (document.contentType !== 'text/html' || /[*|]/.test(leafName)) {\n pending = true;\n } else {\n const arr = [...baseNode.getElementsByTagName(leafName)];\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.find] - 'prev'|'next', which nodes to find\n * @returns {object} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { find, forgive } = opt;\n let matched = new Set();\n if (find === 'next') {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n let refNode = node.nextElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [...node.children];\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n matched = nodes;\n } else if (pending) {\n const { document } = this.#root;\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n matched.add(refNode);\n }\n refNode = iterator.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, {\n forgive\n });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const arr = [];\n let refNode = node.previousElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, {\n forgive\n });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.previousElementSibling;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, {\n forgive\n });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, {\n forgive\n });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - result\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\n let node;\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n node = this.#node;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n node = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n node = root.getElementById(leafName);\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n break;\n }\n case CLASS_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [...root.children];\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [...node.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case TYPE_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this.#node.nodeType === ELEMENT_NODE &&\n this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (document.contentType !== 'text/html' ||\n /[*|]/.test(leafName)) {\n pending = true;\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const tagName = leafName.toLowerCase();\n const childNodes = [...root.children];\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [...node.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - matrix\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[0];\n const { nodes, pending } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n } else {\n this.#ast[i].skip = true;\n }\n i++;\n }\n if (pendingItems.size) {\n const { document, root } = this.#root;\n const iterator = document.createNodeIterator(root, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n bool = isSameOrDescendant(nextNode, this.#node);\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode);\n if (matched) {\n const index = pendingItem.get('index');\n this.#nodes[index].add(nextNode);\n }\n }\n }\n nextNode = iterator.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const { nodes } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else {\n this.#ast[i].skip = true;\n }\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {object} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const matched = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of matched) {\n if (node !== this.#node) {\n if (isSameOrDescendant(node, this.#node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = [...matched];\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matched];\n nodes = new Set([...n, ...m]);\n }\n } else if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n let { combo } = branch[0];\n for (const node of matched) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const twig = {\n combo,\n leaves\n };\n const m = this._matchCombinator(twig, nextNode, {\n find: 'next'\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = [...matchedNodes];\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matchedNodes];\n nodes = new Set([...n, ...m]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = matchedNodes;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of matched) {\n let nextNodes = new Set([node]);\n let bool;\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n find: 'prev'\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = matchedNodes;\n }\n } else {\n bool = false;\n break;\n }\n }\n if (bool) {\n break;\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {object} - collection of matched nodes\n */\n _find(targetType) {\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * sort nodes\n * @param {object} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n const posBit = a.compareDocumentPosition(b);\n if (posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * matches\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_SELF);\n res = nodes.has(this.#node);\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @returns {?object} - matched node\n */\n closest() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL);\n let node = this.#node;\n while (node) {\n if (nodes.has(node)) {\n res = node;\n break;\n }\n node = node.parentNode;\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @returns {?object} - matched node\n */\n querySelector() {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size > 1) {\n [res] = this._sortNodes(nodes);\n } else if (nodes.size) {\n [res] = [...nodes];\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll() {\n const res = [];\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size > 1 && this.#sort) {\n res.push(...this._sortNodes(nodes));\n } else if (nodes.size) {\n res.push(...nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res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WI,CAAK,EACpBA,EAAM,OACf,CAACJ,CAAG,EAAI,CAAC,GAAGI,CAAK,EAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,IAChB,CAOA,kBAAmB,CACjB,MAAMA,EAAM,CAAC,EACb,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM9C,CAAU,EACnC8C,EAAM,OAAO,KAAK5B,EAAK,EACnB4B,EAAM,KAAO,GAAK,KAAKxB,GACzBoB,EAAI,KAAK,GAAG,KAAK,WAAWI,CAAK,CAAC,EACzBA,EAAM,MACfJ,EAAI,KAAK,GAAGI,CAAK,CAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,CACT,CACF",
6
- "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "FORM_PARTS", "FORM_VALIDITY", "HTML_ANCHOR", "HTML_INTERACT", "INPUT_CHECK", "INPUT_EDIT", "INPUT_RANGE", "INPUT_RESET", "INPUT_SUBMIT", "INPUT_TIME", "PSEUDO_FUNC", "PSEUDO_NTH", "#ast", "#cache", "#node", "#nodes", "#root", "#selector", "#sort", "#warn", "selector", "node", "opt", "sort", "warn", "e", "document", "root", "parent", "leaves", "arr", "bitMap", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "ast", "branches", "tree", "nodes", "i", "items", "branch", "item", "nextItem", "msg", "anb", "reverse", "parentNode", "matched", "selectorBranches", "selectorNodes", "branchesLen", "refNode", "bool", "current", "n", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "lang", "codePart", "reg", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "target", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "l", "lastIndex", "nextNodes", "m", "matchedNodes", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "value", "id", "astPrefix", "astNodeName", "nodePrefix", "type", "baseNode", "leafName", "matchItems", "pending", "elm", "comboName", "find", "childNodes", "targetType", "tagName", "pendingItems", "pendingItem", "index", "skip", "branchLen", "nextCombo", "posBit"]
4
+ "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isNamespaceDeclared, isSameOrDescendant,\n selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ATTRIBUTE_SELECTOR, BIT_1, BIT_10, BIT_100, BIT_1000, BIT_10000, BIT_100000,\n CLASS_SELECTOR, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,\n DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n ID_SELECTOR, NOT_SUPPORTED_ERR, PSEUDO_CLASS_SELECTOR,\n PSEUDO_ELEMENT_SELECTOR, SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE, TYPE_SELECTOR\n} from './constant.js';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/* regexp */\nconst FORM_PARTS =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\nconst FORM_VALIDITY = /^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/;\nconst HTML_ANCHOR = /^a(?:rea)?$/;\nconst HTML_INTERACT = /^d(?:etails|ialog)$/;\nconst INPUT_CHECK = /^(?:checkbox|radio)$/;\nconst INPUT_EDIT = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\nconst INPUT_RANGE = /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\nconst INPUT_RESET = /^(?:button|reset)$/;\nconst INPUT_SUBMIT = /^(?:image|submit)$/;\nconst INPUT_TIME = /^(?:date(?:time-local)?|month|time|week)$/;\nconst PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;\nconst PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * skip: boolean\n * }\n * ]\n * #nodes: [\n * Set([node{}, node{}]),\n * Set([node{}, node, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: AST leaf\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #bit;\n #cache;\n #node;\n #nodes;\n #root;\n #selector;\n #sort;\n #warn;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.sort] - sort results of querySelectorAll()\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { sort, warn } = opt;\n this.#bit = new Map([\n [ATTRIBUTE_SELECTOR, BIT_10000],\n [CLASS_SELECTOR, BIT_100],\n [ID_SELECTOR, BIT_10],\n [PSEUDO_CLASS_SELECTOR, BIT_100000],\n [PSEUDO_ELEMENT_SELECTOR, BIT_1],\n [TYPE_SELECTOR, BIT_1000]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#sort = !!sort;\n this.#warn = !!warn;\n [this.#ast, this.#nodes] = this._prepare(selector);\n this.#root = this._getRoot(node);\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException && e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw e;\n }\n }\n\n /**\n * get root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - root object\n */\n _getRoot(node = this.#node) {\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (isSameOrDescendant(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n document = parent.ownerDocument;\n root = parent;\n }\n break;\n }\n default: {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n return {\n document,\n root\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = this.#bit.get(typeA);\n const bitB = this.#bit.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * prepare ast and nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - list and matrix\n */\n _prepare(selector = this.#selector) {\n const ast = parseSelector(selector);\n const branches = walkAST(ast);\n const tree = [];\n const nodes = [];\n let i = 0;\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid combinator ${item.name}${nextItem.name}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n tree.push({\n branch,\n find: null,\n skip: false\n });\n nodes[i] = new Set();\n i++;\n }\n return [\n tree,\n nodes\n ];\n }\n\n /**\n * collect nth child\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {object} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#cache.has(selector)) {\n selectorBranches = this.#cache.get(selector);\n } else {\n selectorBranches = walkAST(selector);\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const arr = [...parentNode.children];\n const l = arr.length;\n if (l) {\n const selectorNodes = new Set();\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n for (const refNode of arr) {\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, refNode);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n }\n if (reverse) {\n arr.reverse();\n }\n // :first-child, :last-child, :nth-child(0 of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n if (selectorNodes.has(current)) {\n matched.add(current);\n break;\n }\n }\n } else if (!selector) {\n const current = arr[b - 1];\n matched.add(current);\n }\n }\n // :nth-child()\n } else {\n let n = 0;\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += (++n * a);\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l && nth >= 0 && nth < l; i++) {\n const current = arr[i];\n if (selectorNodes.size) {\n if (selectorNodes.has(current)) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(current);\n }\n nth += a;\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE && node === root && (a + b) === 1) {\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {object} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const arr = [...parentNode.children];\n const l = arr.length;\n if (l) {\n if (reverse) {\n arr.reverse();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(current);\n break;\n }\n j++;\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE && node === root && (a + b) === 1) {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {object} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (/last/.test(nthName)) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (/last/.test(nthName)) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'part':\n case 'placeholder':\n case 'selection':\n case 'slotted':\n case 'target-text': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const { lang } = node;\n const astName = unescapeSelector(ast.name);\n let res;\n // TBD: what about xml:lang?\n if (astName === '') {\n if (node.getAttribute('lang') === '') {\n res = node;\n }\n } else if (astName === '*') {\n if (!node.hasAttribute('lang')) {\n res = node;\n }\n } else if (/[A-Z\\d-]+/i.test(astName)) {\n const codePart = '(?:-[A-Za-z\\\\d]+)?';\n let reg;\n if (/-/.test(astName)) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n const extendedMain = `${langMain}${codePart}`;\n const extendedSub = `-${langSub}${codePart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${codePart}`;\n }\n }\n reg = new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n reg = new RegExp(`^${astName}${codePart}$`, 'i');\n }\n if (lang) {\n if (reg.test(lang)) {\n res = node;\n }\n } else {\n let target = node;\n while (target) {\n if (reg.test(target.lang)) {\n res = node;\n break;\n }\n target = target.parentNode;\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n find: 'next'\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n let bool;\n const l = branches.length;\n for (let i = 0; i < l; i++) {\n const leaves = branches[i];\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n let bool;\n const l = twigBranches.length;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, {\n forgive\n });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n find: 'prev'\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = matchedNodes;\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {object} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (PSEUDO_FUNC.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (PSEUDO_NTH.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n const { document, root } = this.#root;\n const { documentElement } = document;\n const docURL = new URL(document.URL);\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const attrURL = new URL(node.getAttribute('href'), docURL.href);\n if (attrURL.origin === docURL.origin &&\n attrURL.pathname === docURL.pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n if (isSameOrDescendant(node) && docURL.hash &&\n node.id && docURL.hash === `#${node.id}`) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n if (docURL.hash) {\n const hash = docURL.hash.replace(/^#/, '');\n let current = document.getElementById(hash);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (node === this.#node) {\n matched.add(node);\n }\n } else if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === document.activeElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (HTML_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (HTML_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (FORM_PARTS.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parent.hasAttribute('disabled') &&\n parentNode.localName !== 'legend') {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((FORM_PARTS.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (INPUT_EDIT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length &&\n node.value === '') {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n node.checked) ||\n (localName === 'option' && node.selected)) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((localName === 'input' && node.type === 'checkbox' &&\n node.indeterminate) ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = documentElement;\n }\n const nodes = [...parent.getElementsByTagName('input')];\n let checked;\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n INPUT_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n INPUT_SUBMIT.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const iterator = document.createNodeIterator(form, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n INPUT_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n INPUT_SUBMIT.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = iterator.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let isMultiple = false;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'datalist') {\n break;\n } else if (parent.localName === 'select') {\n if (parent.multiple || parent.hasAttribute('multiple')) {\n isMultiple = true;\n }\n break;\n }\n parent = parent.parentNode;\n }\n if (isMultiple) {\n if (node.selected || node.hasAttribute('selected')) {\n matched.add(node);\n }\n } else {\n const firstOpt = parentNode.firstElementChild;\n const defaultOpt = new Set();\n let opt = firstOpt;\n while (opt) {\n if (opt.selected || opt.hasAttribute('selected')) {\n defaultOpt.add(opt);\n break;\n }\n opt = opt.nextElementSibling;\n }\n if (!defaultOpt.size) {\n defaultOpt.add(firstOpt);\n }\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'valid': {\n if (FORM_VALIDITY.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (FORM_VALIDITY.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (FORM_VALIDITY.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (FORM_VALIDITY.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n INPUT_RANGE.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n INPUT_RANGE.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const nodes = node.childNodes.values();\n let bool;\n for (const refNode of nodes) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'focus-visible':\n case 'fullscreen':\n case 'future':\n case 'hover':\n case 'modal':\n case 'muted':\n case 'past':\n case 'paused':\n case 'picture-in-picture':\n case 'playing':\n case 'seeking':\n case 'stalled':\n case 'user-invalid':\n case 'user-valid':\n case 'volume-locked':\n case '-webkit-autofill': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n throw new DOMException('Invalid attribute selector', SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const { document } = this.#root;\n let caseInsensitive;\n if (document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let { name: astAttrName } = astName;\n astAttrName = unescapeSelector(astAttrName);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (/\\|/.test(astAttrName)) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (/:/.test(itemName)) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (/:/.test(itemName)) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (/:/.test(itemName)) {\n const [, itemNameLocalName] = itemName.split(':');\n if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const { id } = node;\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { document } = this.#root;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (/:/.test(localName)) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix &&\n isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n }\n return res ?? null;\n };\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {object} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type } = ast;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (type) {\n case ATTRIBUTE_SELECTOR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case CLASS_SELECTOR: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case ID_SELECTOR: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case PSEUDO_CLASS_SELECTOR: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n const astName = unescapeSelector(ast.name);\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case TYPE_SELECTOR:\n default: {\n const res = this._matchTypeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} [opt] - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - result\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...items] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const elm = root.getElementById(leafName);\n if (elm && elm !== baseNode) {\n const bool = isSameOrDescendant(elm, baseNode);\n let node;\n if (bool) {\n node = elm;\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n }\n break;\n }\n case CLASS_SELECTOR: {\n const arr = [...baseNode.getElementsByClassName(leafName)];\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case TYPE_SELECTOR: {\n if (document.contentType !== 'text/html' || /[*|]/.test(leafName)) {\n pending = true;\n } else {\n const arr = [...baseNode.getElementsByTagName(leafName)];\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.find] - 'prev'|'next', which nodes to find\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {object} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { find, forgive } = opt;\n let matched = new Set();\n if (find === 'next') {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n let refNode = node.nextElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [...node.children];\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n matched = nodes;\n } else if (pending) {\n const { document } = this.#root;\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n matched.add(refNode);\n }\n refNode = iterator.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, {\n forgive\n });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const arr = [];\n let refNode = node.previousElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, {\n forgive\n });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.previousElementSibling;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, {\n forgive\n });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, {\n forgive\n });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - result\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\n let node;\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n node = this.#node;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n node = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n node = root.getElementById(leafName);\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n break;\n }\n case CLASS_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [...root.children];\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [...node.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case TYPE_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this.#node.nodeType === ELEMENT_NODE &&\n this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (document.contentType !== 'text/html' ||\n /[*|]/.test(leafName)) {\n pending = true;\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const tagName = leafName.toLowerCase();\n const childNodes = [...root.children];\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [...node.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * get first twig\n * @param {Array.<object>} branch - AST branch\n * @returns {object} - result\n */\n _getFirstTwig(branch) {\n const lastIndex = branch.length - 1;\n const firstTwig = branch[0];\n let find;\n let twig;\n if (lastIndex) {\n const lastTwig = branch[lastIndex];\n const { leaves: [{ type: lastType }] } = lastTwig;\n if (lastType === PSEUDO_ELEMENT_SELECTOR || lastType === ID_SELECTOR) {\n find = 'prev';\n twig = lastTwig;\n } else {\n find = 'next';\n twig = firstTwig;\n }\n } else {\n find = 'prev';\n twig = firstTwig;\n }\n return {\n find,\n twig\n };\n }\n\n /**\n * collect nodes\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - matrix\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const { find, twig } = this._getFirstTwig(branch);\n const { nodes, pending } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = find;\n i++;\n }\n if (pendingItems.size) {\n const { document, root } = this.#root;\n const iterator = document.createNodeIterator(root, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n bool = isSameOrDescendant(nextNode, this.#node);\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode);\n if (matched) {\n const index = pendingItem.get('index');\n this.#nodes[index].add(nextNode);\n }\n }\n }\n nextNode = iterator.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const { nodes } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = 'prev';\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {object} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, find, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const matched = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of matched) {\n if (node !== this.#node) {\n if (isSameOrDescendant(node, this.#node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = [...matched];\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matched];\n nodes = new Set([...n, ...m]);\n }\n } else if (find === 'next') {\n let { combo } = branch[0];\n for (const node of matched) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const twig = {\n combo,\n leaves\n };\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = [...matchedNodes];\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matchedNodes];\n nodes = new Set([...n, ...m]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = matchedNodes;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of matched) {\n let nextNodes = new Set([node]);\n let bool;\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = matchedNodes;\n }\n } else {\n bool = false;\n break;\n }\n }\n if (bool && targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {object} - collection of matched nodes\n */\n _find(targetType) {\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * sort nodes\n * @param {object} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n const posBit = a.compareDocumentPosition(b);\n if (posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * matches\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_SELF);\n res = nodes.has(this.#node);\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @returns {?object} - matched node\n */\n closest() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL);\n let node = this.#node;\n while (node) {\n if (nodes.has(node)) {\n res = node;\n break;\n }\n node = node.parentNode;\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @returns {?object} - matched node\n */\n querySelector() {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size > 1) {\n [res] = this._sortNodes(nodes);\n } else if (nodes.size) {\n [res] = [...nodes];\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll() {\n const res = [];\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size > 1 && this.#sort) {\n res.push(...this._sortNodes(nodes));\n } else if (nodes.size) {\n res.push(...nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res;\n }\n};\n"],
5
+ "mappings": "6iBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,IAAA,eAAAC,EAAAH,IAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAMO,yBACP,MAAMC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OAGdC,EACJ,iEACIC,EAAgB,qDAChBC,EAAc,cACdC,EAAgB,sBAChBC,EAAc,uBACdC,EAAa,oDACbC,EAAc,2DACdC,EAAc,qBACdC,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I,EAAG,CACnBgB,EAAMhB,EACN,KACF,CACAA,EAAOA,EAAK,UACd,CACF,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOgB,GAAO,IAChB,CAMA,eAAgB,CACd,IAAIA,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM7C,CAAY,EACrC6C,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,EACf,CAACJ,CAAG,EAAI,KAAK,WAAWI,CAAK,EACpBA,EAAM,OACf,CAACJ,CAAG,EAAI,CAAC,GAAGI,CAAK,EAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,IAChB,CAOA,kBAAmB,CACjB,MAAMA,EAAM,CAAC,EACb,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM9C,CAAU,EACnC8C,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,GAAK,KAAKvB,GACzBmB,EAAI,KAAK,GAAG,KAAK,WAAWI,CAAK,CAAC,EACzBA,EAAM,MACfJ,EAAI,KAAK,GAAGI,CAAK,CAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,CACT,CACF",
6
+ "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "FORM_PARTS", "FORM_VALIDITY", "HTML_ANCHOR", "HTML_INTERACT", "INPUT_CHECK", "INPUT_EDIT", "INPUT_RANGE", "INPUT_RESET", "INPUT_SUBMIT", "INPUT_TIME", "PSEUDO_FUNC", "PSEUDO_NTH", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#sort", "#warn", "selector", "node", "opt", "sort", "warn", "e", "document", "root", "parent", "leaves", "arr", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "ast", "branches", "tree", "nodes", "i", "items", "branch", "item", "nextItem", "msg", "anb", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "branchesLen", "refNode", "bool", "current", "n", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "lang", "codePart", "reg", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "target", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "matchedNodes", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "value", "id", "astPrefix", "astNodeName", "nodePrefix", "type", "baseNode", "leafName", "matchItems", "pending", "elm", "comboName", "find", "childNodes", "targetType", "tagName", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "skip", "branchLen", "nextCombo", "posBit"]
7
7
  }
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "is-potential-custom-element-name": "^1.0.1"
29
29
  },
30
30
  "devDependencies": {
31
- "@types/css-tree": "^2.3.3",
31
+ "@types/css-tree": "^2.3.4",
32
32
  "benchmark": "^2.1.4",
33
33
  "c8": "^8.0.1",
34
34
  "chai": "^4.3.10",
@@ -57,5 +57,5 @@
57
57
  "update": "npm-run-all -s update-*",
58
58
  "update-wpt": "git submodule update --init --recursive --remote"
59
59
  },
60
- "version": "0.24.0"
60
+ "version": "1.0.1"
61
61
  }
package/src/js/matcher.js CHANGED
@@ -69,6 +69,7 @@ const PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;
69
69
  export class Matcher {
70
70
  /* private fields */
71
71
  #ast;
72
+ #bit;
72
73
  #cache;
73
74
  #node;
74
75
  #nodes;
@@ -87,13 +88,21 @@ export class Matcher {
87
88
  */
88
89
  constructor(selector, node, opt = {}) {
89
90
  const { sort, warn } = opt;
91
+ this.#bit = new Map([
92
+ [ATTRIBUTE_SELECTOR, BIT_10000],
93
+ [CLASS_SELECTOR, BIT_100],
94
+ [ID_SELECTOR, BIT_10],
95
+ [PSEUDO_CLASS_SELECTOR, BIT_100000],
96
+ [PSEUDO_ELEMENT_SELECTOR, BIT_1],
97
+ [TYPE_SELECTOR, BIT_1000]
98
+ ]);
99
+ this.#cache = new WeakMap();
90
100
  this.#selector = selector;
91
101
  this.#node = node;
92
- [this.#ast, this.#nodes] = this._prepare(selector);
93
- this.#root = this._getRoot(node);
94
- this.#cache = new WeakMap();
95
102
  this.#sort = !!sort;
96
103
  this.#warn = !!warn;
104
+ [this.#ast, this.#nodes] = this._prepare(selector);
105
+ this.#root = this._getRoot(node);
97
106
  }
98
107
 
99
108
  /**
@@ -167,19 +176,11 @@ export class Matcher {
167
176
  _sortLeaves(leaves) {
168
177
  const arr = [...leaves];
169
178
  if (arr.length > 1) {
170
- const bitMap = new Map([
171
- [ATTRIBUTE_SELECTOR, BIT_10000],
172
- [CLASS_SELECTOR, BIT_100],
173
- [ID_SELECTOR, BIT_10],
174
- [PSEUDO_CLASS_SELECTOR, BIT_100000],
175
- [PSEUDO_ELEMENT_SELECTOR, BIT_1],
176
- [TYPE_SELECTOR, BIT_1000]
177
- ]);
178
179
  arr.sort((a, b) => {
179
180
  const { type: typeA } = a;
180
181
  const { type: typeB } = b;
181
- const bitA = bitMap.get(typeA);
182
- const bitB = bitMap.get(typeB);
182
+ const bitA = this.#bit.get(typeA);
183
+ const bitB = this.#bit.get(typeB);
183
184
  let res;
184
185
  if (bitA === bitB) {
185
186
  res = 0;
@@ -239,6 +240,7 @@ export class Matcher {
239
240
  }
240
241
  tree.push({
241
242
  branch,
243
+ find: null,
242
244
  skip: false
243
245
  });
244
246
  nodes[i] = new Set();
@@ -516,7 +518,8 @@ export class Matcher {
516
518
  /**
517
519
  * match pseudo element selector
518
520
  * @param {string} astName - AST name
519
- * @param {object} opt - options
521
+ * @param {object} [opt] - options
522
+ * @param {boolean} [opt.forgive] - is forgiving selector list
520
523
  * @throws {DOMException}
521
524
  * @returns {void}
522
525
  */
@@ -770,7 +773,8 @@ export class Matcher {
770
773
  * @see https://html.spec.whatwg.org/#pseudo-classes
771
774
  * @param {object} ast - AST
772
775
  * @param {object} node - Element node
773
- * @param {object} opt - options
776
+ * @param {object} [opt] - options
777
+ * @param {boolean} [opt.forgive] - is forgiving selector list
774
778
  * @returns {object} - collection of matched nodes
775
779
  */
776
780
  _matchPseudoClassSelector(ast, node, opt = {}) {
@@ -1143,7 +1147,7 @@ export class Matcher {
1143
1147
  // input[type="checkbox"], input[type="radio"]
1144
1148
  } else if (localName === 'input' && node.hasAttribute('type') &&
1145
1149
  INPUT_CHECK.test(node.getAttribute('type')) &&
1146
- node.hasAttribute('checked')) {
1150
+ (node.checked || node.hasAttribute('checked'))) {
1147
1151
  matched.add(node);
1148
1152
  // option
1149
1153
  } else if (localName === 'option') {
@@ -1153,23 +1157,23 @@ export class Matcher {
1153
1157
  if (parent.localName === 'datalist') {
1154
1158
  break;
1155
1159
  } else if (parent.localName === 'select') {
1156
- isMultiple = !!parent.multiple;
1160
+ if (parent.multiple || parent.hasAttribute('multiple')) {
1161
+ isMultiple = true;
1162
+ }
1157
1163
  break;
1158
1164
  }
1159
1165
  parent = parent.parentNode;
1160
1166
  }
1161
- // FIXME:
1162
1167
  if (isMultiple) {
1163
- if (this.#warn) {
1164
- throw new DOMException(`Unsupported pseudo-class :${astName}`,
1165
- NOT_SUPPORTED_ERR);
1168
+ if (node.selected || node.hasAttribute('selected')) {
1169
+ matched.add(node);
1166
1170
  }
1167
1171
  } else {
1168
1172
  const firstOpt = parentNode.firstElementChild;
1169
1173
  const defaultOpt = new Set();
1170
1174
  let opt = firstOpt;
1171
1175
  while (opt) {
1172
- if (opt.hasAttribute('selected')) {
1176
+ if (opt.selected || opt.hasAttribute('selected')) {
1173
1177
  defaultOpt.add(opt);
1174
1178
  break;
1175
1179
  }
@@ -1737,7 +1741,7 @@ export class Matcher {
1737
1741
  * match selector
1738
1742
  * @param {object} ast - AST
1739
1743
  * @param {object} node - Document, DocumentFragment, Element node
1740
- * @param {object} opt - options
1744
+ * @param {object} [opt] - options
1741
1745
  * @returns {object} - collection of matched nodes
1742
1746
  */
1743
1747
  _matchSelector(ast, node, opt) {
@@ -1794,7 +1798,7 @@ export class Matcher {
1794
1798
  * match leaves
1795
1799
  * @param {Array.<object>} leaves - AST leaves
1796
1800
  * @param {object} node - node
1797
- * @param {object} opt - options
1801
+ * @param {object} [opt] - options
1798
1802
  * @returns {boolean} - result
1799
1803
  */
1800
1804
  _matchLeaves(leaves, node, opt) {
@@ -1904,6 +1908,7 @@ export class Matcher {
1904
1908
  * @param {object} node - Element node
1905
1909
  * @param {object} [opt] - option
1906
1910
  * @param {string} [opt.find] - 'prev'|'next', which nodes to find
1911
+ * @param {boolean} [opt.forgive] - is forgiving selector list
1907
1912
  * @returns {object} - collection of matched nodes
1908
1913
  */
1909
1914
  _matchCombinator(twig, node, opt = {}) {
@@ -2221,6 +2226,36 @@ export class Matcher {
2221
2226
  };
2222
2227
  }
2223
2228
 
2229
+ /**
2230
+ * get first twig
2231
+ * @param {Array.<object>} branch - AST branch
2232
+ * @returns {object} - result
2233
+ */
2234
+ _getFirstTwig(branch) {
2235
+ const lastIndex = branch.length - 1;
2236
+ const firstTwig = branch[0];
2237
+ let find;
2238
+ let twig;
2239
+ if (lastIndex) {
2240
+ const lastTwig = branch[lastIndex];
2241
+ const { leaves: [{ type: lastType }] } = lastTwig;
2242
+ if (lastType === PSEUDO_ELEMENT_SELECTOR || lastType === ID_SELECTOR) {
2243
+ find = 'prev';
2244
+ twig = lastTwig;
2245
+ } else {
2246
+ find = 'next';
2247
+ twig = firstTwig;
2248
+ }
2249
+ } else {
2250
+ find = 'prev';
2251
+ twig = firstTwig;
2252
+ }
2253
+ return {
2254
+ find,
2255
+ twig
2256
+ };
2257
+ }
2258
+
2224
2259
  /**
2225
2260
  * collect nodes
2226
2261
  * @param {string} targetType - target type
@@ -2232,7 +2267,7 @@ export class Matcher {
2232
2267
  const pendingItems = new Set();
2233
2268
  let i = 0;
2234
2269
  for (const { branch } of ast) {
2235
- const twig = branch[0];
2270
+ const { find, twig } = this._getFirstTwig(branch);
2236
2271
  const { nodes, pending } = this._findNodes(twig, targetType);
2237
2272
  if (nodes.size) {
2238
2273
  this.#nodes[i] = nodes;
@@ -2244,6 +2279,7 @@ export class Matcher {
2244
2279
  } else {
2245
2280
  this.#ast[i].skip = true;
2246
2281
  }
2282
+ this.#ast[i].find = find;
2247
2283
  i++;
2248
2284
  }
2249
2285
  if (pendingItems.size) {
@@ -2280,6 +2316,7 @@ export class Matcher {
2280
2316
  } else {
2281
2317
  this.#ast[i].skip = true;
2282
2318
  }
2319
+ this.#ast[i].find = 'prev';
2283
2320
  i++;
2284
2321
  }
2285
2322
  }
@@ -2299,7 +2336,7 @@ export class Matcher {
2299
2336
  const l = branches.length;
2300
2337
  let nodes = new Set();
2301
2338
  for (let i = 0; i < l; i++) {
2302
- const { branch, skip } = branches[i];
2339
+ const { branch, find, skip } = branches[i];
2303
2340
  const branchLen = branch.length;
2304
2341
  if (skip) {
2305
2342
  continue;
@@ -2327,7 +2364,7 @@ export class Matcher {
2327
2364
  const m = [...matched];
2328
2365
  nodes = new Set([...n, ...m]);
2329
2366
  }
2330
- } else if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {
2367
+ } else if (find === 'next') {
2331
2368
  let { combo } = branch[0];
2332
2369
  for (const node of matched) {
2333
2370
  let nextNodes = new Set([node]);
@@ -2339,9 +2376,7 @@ export class Matcher {
2339
2376
  combo,
2340
2377
  leaves
2341
2378
  };
2342
- const m = this._matchCombinator(twig, nextNode, {
2343
- find: 'next'
2344
- });
2379
+ const m = this._matchCombinator(twig, nextNode, { find });
2345
2380
  if (m.size) {
2346
2381
  arr.push(...m);
2347
2382
  }
@@ -2375,9 +2410,7 @@ export class Matcher {
2375
2410
  const twig = branch[j];
2376
2411
  const arr = [];
2377
2412
  for (const nextNode of nextNodes) {
2378
- const m = this._matchCombinator(twig, nextNode, {
2379
- find: 'prev'
2380
- });
2413
+ const m = this._matchCombinator(twig, nextNode, { find });
2381
2414
  if (m.size) {
2382
2415
  arr.push(...m);
2383
2416
  }
@@ -2396,7 +2429,7 @@ export class Matcher {
2396
2429
  break;
2397
2430
  }
2398
2431
  }
2399
- if (bool) {
2432
+ if (bool && targetType !== TARGET_ALL) {
2400
2433
  break;
2401
2434
  }
2402
2435
  }
@@ -19,23 +19,29 @@ export class Matcher {
19
19
  reverse?: boolean;
20
20
  }, node: object): object;
21
21
  _matchAnPlusB(ast: object, node: object, nthName: string): object;
22
- _matchPseudoElementSelector(astName: string, opt?: object): void;
22
+ _matchPseudoElementSelector(astName: string, opt?: {
23
+ forgive?: boolean;
24
+ }): void;
23
25
  _matchDirectionPseudoClass(ast: object, node: object): object | null;
24
26
  _matchLanguagePseudoClass(ast: object, node: object): object | null;
25
27
  _matchHasPseudoFunc(leaves: Array<object>, node: object): boolean;
26
28
  _matchLogicalPseudoFunc(astData: object, node: object): object | null;
27
- _matchPseudoClassSelector(ast: object, node: object, opt?: object): object;
29
+ _matchPseudoClassSelector(ast: object, node: object, opt?: {
30
+ forgive?: boolean;
31
+ }): object;
28
32
  _matchAttributeSelector(ast: object, node: object): object | null;
29
33
  _matchClassSelector(ast: object, node: object): object | null;
30
34
  _matchIDSelector(ast: object, node: object): object | null;
31
35
  _matchTypeSelector(ast: object, node: object): object | null;
32
- _matchSelector(ast: object, node: object, opt: object): object;
33
- _matchLeaves(leaves: Array<object>, node: object, opt: object): boolean;
36
+ _matchSelector(ast: object, node: object, opt?: object): object;
37
+ _matchLeaves(leaves: Array<object>, node: object, opt?: object): boolean;
34
38
  _findDescendantNodes(leaves: Array<object>, baseNode: object): object;
35
39
  _matchCombinator(twig: object, node: object, opt?: {
36
40
  find?: string;
41
+ forgive?: boolean;
37
42
  }): object;
38
43
  _findNodes(twig: object, targetType: string): object;
44
+ _getFirstTwig(branch: Array<object>): object;
39
45
  _collectNodes(targetType: string): Array<Array<object | undefined>>;
40
46
  _matchNodes(targetType: string): object;
41
47
  _find(targetType: string): object;