@asamuzakjp/dom-selector 1.2.0 → 1.2.2

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
@@ -231,38 +231,38 @@ const dom = new JSDOM('', {
231
231
 
232
232
  |method('selector')|jsdom v23.0.1 (nwsapi)|patched-jsdom (dom-selector)|Result|
233
233
  |:-----------------|:-----------------|:-----------------|:-----------------|
234
- |matches('p.content')|2,488,583 ops/sec ±0.53%|116,167 ops/sec ±0.45%|jsdom is 21.4 times faster. patched-jsdom took 0.009msec.|
235
- |matches('div.container:not(.box)')|1,434,984 ops/sec ±0.81%|65,530 ops/sec ±0.32%|jsdom is 21.9 times faster. patched-jsdom took 0.015msec.|
236
- |matches('.box + .box')|2,356,896 ops/sec ±0.35%|123,992 ops/sec ±1.80%|jsdom is 19.0 times faster. patched-jsdom took 0.008msec.|
237
- |matches('.box ~ .box')|2,383,794 ops/sec ±1.66%|126,361 ops/sec ±1.71%|jsdom is 18.9 times faster. patched-jsdom took 0.008msec.|
238
- |matches('.box > .block')|2,375,732 ops/sec ±1.72%|125,569 ops/sec ±1.60%|jsdom is 18.9 times faster. patched-jsdom took 0.008msec.|
239
- |matches('.box .content')|392,589 ops/sec ±1.38%|66,923 ops/sec ±1.46%|jsdom is 5.9 times faster. patched-jsdom took 0.015msec.|
240
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|180,656 ops/sec ±1.32%|18,095 ops/sec ±1.63%|jsdom is 10.0 times faster. patched-jsdom took 0.055msec.|
241
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|27,379 ops/sec ±1.63%|jsdom throws. patched-jsdom took 0.037msec.|
242
- |closest('p.content')|1,762,604 ops/sec ±1.66%|66,973 ops/sec ±1.39%|jsdom is 26.3 times faster. patched-jsdom took 0.015msec.|
243
- |closest('div.container:not(.box)')|274,748 ops/sec ±2.04%|36,550 ops/sec ±2.18%|jsdom is 7.5 times faster. patched-jsdom took 0.027msec.|
244
- |closest('.box + .box')|451,724 ops/sec ±0.23%|60,899 ops/sec ±1.59%|jsdom is 7.4 times faster. patched-jsdom took 0.016msec.|
245
- |closest('.box ~ .box')|182,663 ops/sec ±1.45%|38,159 ops/sec ±1.49%|jsdom is 4.8 times faster. patched-jsdom took 0.026msec.|
246
- |closest('.box > .block')|485,172 ops/sec ±1.46%|57,094 ops/sec ±1.52%|jsdom is 8.5 times faster. patched-jsdom took 0.018msec.|
247
- |closest('.box .content')|369,453 ops/sec ±1.48%|47,294 ops/sec ±1.46%|jsdom is 7.8 times faster. patched-jsdom took 0.021msec.|
248
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|174,341 ops/sec ±1.38%|16,067 ops/sec ±1.53%|jsdom is 10.9 times faster. patched-jsdom took 0.062msec.|
249
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|12,062 ops/sec ±2.23%|jsdom throws. patched-jsdom took 0.083msec.|
250
- |querySelector('p.content')|2,694 ops/sec ±0.92%|2,809 ops/sec ±0.94%|patched-jsdom is 1.0 times faster. patched-jsdom took 0.356msec.|
251
- |querySelector('div.container:not(.box)')|83,924 ops/sec ±1.53%|45,590 ops/sec ±1.95%|jsdom is 1.8 times faster. patched-jsdom took 0.022msec.|
252
- |querySelector('.box + .box')|87,433 ops/sec ±1.52%|77,785 ops/sec ±1.73%|jsdom is 1.1 times faster. patched-jsdom took 0.013msec.|
253
- |querySelector('.box ~ .box')|88,269 ops/sec ±1.48%|76,784 ops/sec ±0.18%|jsdom is 1.1 times faster. patched-jsdom took 0.013msec.|
254
- |querySelector('.box > .block')|1,360 ops/sec ±0.44%|2,493 ops/sec ±1.12%|patched-jsdom is 1.8 times faster. patched-jsdom took 0.401msec.|
255
- |querySelector('.box .content')|709 ops/sec ±1.44%|2,719 ops/sec ±1.04%|patched-jsdom is 3.8 times faster. patched-jsdom took 0.368msec.|
256
- |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|272 ops/sec ±1.61%|842 ops/sec ±1.17%|patched-jsdom is 3.1 times faster. patched-jsdom took 1.188msec.|
257
- |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|675 ops/sec ±1.27%|jsdom throws. patched-jsdom took 1.481msec.|
258
- |querySelectorAll('p.content')|2,441 ops/sec ±0.93%|375 ops/sec ±0.21%|jsdom is 6.5 times faster. patched-jsdom took 2.665msec.|
259
- |querySelectorAll('div.container:not(.box)')|101,494 ops/sec ±0.25%|19,038 ops/sec ±1.59%|jsdom is 5.3 times faster. patched-jsdom took 0.053msec.|
260
- |querySelectorAll('.box + .box')|101,742 ops/sec ±1.55%|29,586 ops/sec ±1.92%|jsdom is 3.4 times faster. patched-jsdom took 0.034msec.|
261
- |querySelectorAll('.box ~ .box')|102,009 ops/sec ±1.39%|12,332 ops/sec ±1.68%|jsdom is 8.3 times faster. patched-jsdom took 0.081msec.|
262
- |querySelectorAll('.box > .block')|1,314 ops/sec ±0.17%|3,817 ops/sec ±1.61%|patched-jsdom is 2.9 times faster. patched-jsdom took 0.262msec.|
263
- |querySelectorAll('.box .content')|659 ops/sec ±0.94%|689 ops/sec ±1.54%|patched-jsdom is 1.0 times faster. patched-jsdom took 1.451msec.|
264
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|275 ops/sec ±1.21%|827 ops/sec ±1.13%|patched-jsdom is 3.0 times faster. patched-jsdom took 1.210msec.|
265
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|671 ops/sec ±0.17%|jsdom throws. patched-jsdom took 1.491msec.|
234
+ |matches('.content')|2,619,961 ops/sec ±0.62%|155,025 ops/sec ±0.18%|jsdom is 16.9 times faster than patched-jsdom. patched-jsdom took 0.006msec.|
235
+ |matches('div.container:not(.box)')|1,355,967 ops/sec ±0.28%|63,278 ops/sec ±0.35%|jsdom is 21.4 times faster than patched-jsdom. patched-jsdom took 0.016msec.|
236
+ |matches('.box + .box')|2,208,946 ops/sec ±0.87%|124,143 ops/sec ±2.04%|jsdom is 17.8 times faster than patched-jsdom. patched-jsdom took 0.008msec.|
237
+ |matches('.box ~ .box')|2,188,431 ops/sec ±2.08%|125,437 ops/sec ±1.63%|jsdom is 17.4 times faster than patched-jsdom. patched-jsdom took 0.008msec.|
238
+ |matches('.box > .block')|2,246,947 ops/sec ±1.64%|120,531 ops/sec ±2.70%|jsdom is 18.6 times faster than patched-jsdom. patched-jsdom took 0.008msec.|
239
+ |matches('.box .content')|404,669 ops/sec ±0.23%|66,697 ops/sec ±1.51%|jsdom is 6.1 times faster than patched-jsdom. patched-jsdom took 0.015msec.|
240
+ |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|181,396 ops/sec ±1.36%|18,238 ops/sec ±1.51%|jsdom is 9.9 times faster than patched-jsdom. patched-jsdom took 0.055msec.|
241
+ |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|28,165 ops/sec ±1.58%|jsdom throws. patched-jsdom took 0.036msec.|
242
+ |closest('.content')|1,794,514 ops/sec ±1.60%|79,672 ops/sec ±0.17%|jsdom is 22.5 times faster than patched-jsdom. patched-jsdom took 0.013msec.|
243
+ |closest('div.container:not(.box)')|279,777 ops/sec ±0.82%|39,476 ops/sec ±2.45%|jsdom is 7.1 times faster than patched-jsdom. patched-jsdom took 0.025msec.|
244
+ |closest('.box + .box')|451,727 ops/sec ±1.48%|61,676 ops/sec ±1.52%|jsdom is 7.3 times faster than patched-jsdom. patched-jsdom took 0.016msec.|
245
+ |closest('.box ~ .box')|188,226 ops/sec ±1.42%|38,601 ops/sec ±0.08%|jsdom is 4.9 times faster than patched-jsdom. patched-jsdom took 0.026msec.|
246
+ |closest('.box > .block')|488,841 ops/sec ±0.17%|58,206 ops/sec ±0.24%|jsdom is 8.4 times faster than patched-jsdom. patched-jsdom took 0.017msec.|
247
+ |closest('.box .content')|381,026 ops/sec ±1.55%|47,268 ops/sec ±1.41%|jsdom is 8.1 times faster than patched-jsdom. patched-jsdom took 0.021msec.|
248
+ |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|178,775 ops/sec ±1.37%|16,100 ops/sec ±1.44%|jsdom is 11.1 times faster than patched-jsdom. patched-jsdom took 0.062msec.|
249
+ |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|12,437 ops/sec ±1.54%|jsdom throws. patched-jsdom took 0.080msec.|
250
+ |querySelector('.content')|2,836 ops/sec ±0.97%|2,553 ops/sec ±0.95%|jsdom is 1.1 times faster than patched-jsdom. patched-jsdom took 0.392msec.|
251
+ |querySelector('div.container:not(.box)')|82,774 ops/sec ±1.50%|46,588 ops/sec ±1.75%|jsdom is 1.8 times faster than patched-jsdom. patched-jsdom took 0.021msec.|
252
+ |querySelector('.box + .box')|84,227 ops/sec ±1.55%|75,745 ops/sec ±1.75%|jsdom is 1.1 times faster than patched-jsdom. patched-jsdom took 0.013msec.|
253
+ |querySelector('.box ~ .box')|86,191 ops/sec ±1.56%|76,286 ops/sec ±0.23%|jsdom is 1.1 times faster than patched-jsdom. patched-jsdom took 0.013msec.|
254
+ |querySelector('.box > .block')|1,274 ops/sec ±1.73%|2,342 ops/sec ±1.40%|patched-jsdom is 1.8 times faster than jsdom. patched-jsdom took 0.427msec.|
255
+ |querySelector('.box .content')|686 ops/sec ±1.34%|2,559 ops/sec ±1.50%|patched-jsdom is 3.7 times faster than jsdom. patched-jsdom took 0.391msec.|
256
+ |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|271 ops/sec ±1.71%|820 ops/sec ±1.30%|patched-jsdom is 3.0 times faster than jsdom. patched-jsdom took 1.219msec.|
257
+ |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|672 ops/sec ±0.17%|jsdom throws. patched-jsdom took 1.488msec.|
258
+ |querySelectorAll('.content')|2,698 ops/sec ±0.93%|840 ops/sec ±1.45%|jsdom is 3.2 times faster than patched-jsdom. patched-jsdom took 1.191msec.|
259
+ |querySelectorAll('div.container:not(.box)')|100,029 ops/sec ±1.43%|24,773 ops/sec ±1.56%|jsdom is 4.0 times faster than patched-jsdom. patched-jsdom took 0.040msec.|
260
+ |querySelectorAll('.box + .box')|102,134 ops/sec ±1.37%|28,783 ops/sec ±2.31%|jsdom is 3.5 times faster than patched-jsdom. patched-jsdom took 0.035msec.|
261
+ |querySelectorAll('.box ~ .box')|101,553 ops/sec ±1.53%|12,375 ops/sec ±1.68%|jsdom is 8.2 times faster than patched-jsdom. patched-jsdom took 0.081msec.|
262
+ |querySelectorAll('.box > .block')|1,255 ops/sec ±1.61%|3,751 ops/sec ±1.56%|patched-jsdom is 3.0 times faster than jsdom. patched-jsdom took 0.267msec.|
263
+ |querySelectorAll('.box .content')|652 ops/sec ±1.41%|684 ops/sec ±1.67%|patched-jsdom is 1.0 times faster than jsdom. patched-jsdom took 1.462msec.|
264
+ |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|270 ops/sec ±0.24%|809 ops/sec ±1.20%|patched-jsdom is 3.0 times faster than jsdom. patched-jsdom took 1.236msec.|
265
+ |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|656 ops/sec ±1.23%|jsdom throws. patched-jsdom took 1.524msec.|
266
266
 
267
267
 
268
268
  ## Acknowledgments
@@ -1,2 +1,2 @@
1
- var B=Object.create;var I=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(T,i)=>{for(var e in i)I(T,e,{get:i[e],enumerable:!0})},U=(T,i,e,n)=>{if(i&&typeof i=="object"||typeof i=="function")for(let h of F(i))!j.call(T,h)&&h!==e&&I(T,h,{get:()=>i[h],enumerable:!(n=z(i,h))||n.enumerable});return T};var W=(T,i,e)=>(e=T!=null?B(V(T)):{},U(i||!T||!T.__esModule?I(e,"default",{value:T,enumerable:!0}):e,T)),G=T=>U(I({},"__esModule",{value:!0}),T);var X={};H(X,{Matcher:()=>q});module.exports=G(X);var M=W(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),k=require("./parser.js"),r=require("./constant.js");const P="next",R="prev",C="all",$="first",O="lineal",D="self";class q{#i;#r;#a;#e;#l;#t;#o;#s;constructor(i,e,n={}){const{warn:h}=n;this.#r=new Map([[r.SELECTOR_PSEUDO_ELEMENT,r.BIT_01],[r.SELECTOR_ID,r.BIT_02],[r.SELECTOR_CLASS,r.BIT_04],[r.SELECTOR_TYPE,r.BIT_08],[r.SELECTOR_ATTR,r.BIT_16],[r.SELECTOR_PSEUDO_CLASS,r.BIT_32]]),this.#a=new WeakMap,this.#o=i,this.#e=e,this.#s=!!h,[this.#i,this.#l]=this._prepare(i),this.#t=this._getRoot(e)}_onError(i){if(i instanceof DOMException&&i.name===r.NOT_SUPPORTED_ERR)this.#s&&console.warn(i.message);else throw i}_getRoot(i=this.#e){let e,n;switch(i.nodeType){case r.DOCUMENT_NODE:{e=i,n=i;break}case r.DOCUMENT_FRAGMENT_NODE:{e=i.ownerDocument,n=i;break}case r.ELEMENT_NODE:{if(i.ownerDocument.contains(i))e=i.ownerDocument,n=i.ownerDocument;else{let l=i;for(;l&&l.parentNode;)l=l.parentNode;e=l.ownerDocument,n=l}break}default:throw new TypeError(`Unexpected node ${i.nodeName}`)}const h=(0,E.isInShadowTree)(i);return{document:e,root:n,shadow:h}}_sortLeaves(i){const e=[...i];return e.length>1&&e.sort((n,h)=>{const{type:l}=n,{type:u}=h,m=this.#r.get(l),f=this.#r.get(u);let t;return m===f?t=0:m>f?t=1:t=-1,t}),e}_prepare(i=this.#o){const e=(0,k.parseSelector)(i),n=(0,k.walkAST)(e),h=[],l=[];let u=0;for(const[...m]of n){const f=[];let t=m.shift();if(t&&t.type!==r.COMBINATOR){const s=new Set;for(;t;){if(t.type===r.COMBINATOR){const[o]=m;if(o.type===r.COMBINATOR){const b=`Invalid combinator ${t.name}${o.name}`;throw new DOMException(b,r.SYNTAX_ERR)}f.push({combo:t,leaves:this._sortLeaves(s)}),s.clear()}else t&&s.add(t);if(m.length)t=m.shift();else{f.push({combo:null,leaves:this._sortLeaves(s)}),s.clear();break}}}h.push({branch:f,find:null,skip:!1}),l[u]=new Set,u++}return[h,l]}_collectNthChild(i,e){const{a:n,b:h,reverse:l,selector:u}=i,{parentNode:m}=e,f=new Set;let t;if(u&&(this.#a.has(u)?t=this.#a.get(u):(t=(0,k.walkAST)(u),this.#a.set(u,t))),m){const s=[].slice.call(m.children),o=s.length;if(o){const b=new Set;if(t){const a=t.length;for(const c of s){let d;for(let w=0;w<a;w++){const N=t[w];if(d=this._matchLeaves(N,c),!d)break}d&&b.add(c)}}if(l&&s.reverse(),n===0){if(h>0&&h<=o){if(b.size)for(let a=0;a<o;a++){const c=s[a];if(b.has(c)){f.add(c);break}}else if(!u){const a=s[h-1];f.add(a)}}}else{let a=h-1;if(n>0)for(;a<0;)a+=n;if(a>=0&&a<o){let c=n>0?0:h-1;for(let d=0;d<o&&a>=0&&a<o;d++){const w=s[d];b.size?b.has(w)&&(c===a&&(f.add(w),a+=n),n>0?c++:c--):d===a&&(u||f.add(w),a+=n)}}}}}else{const{root:s}=this.#t;if(e===s&&s.nodeType===r.ELEMENT_NODE&&n+h===1)if(t){const o=t.length;let b;for(let a=0;a<o;a++){const c=t[a];if(b=this._matchLeaves(c,e),b)break}b&&f.add(e)}else f.add(e)}return f}_collectNthOfType(i,e){const{a:n,b:h,reverse:l}=i,{localName:u,parentNode:m,prefix:f}=e,t=new Set;if(m){const s=[].slice.call(m.children),o=s.length;if(o)if(l&&s.reverse(),n===0){if(h>0&&h<=o){let b=0;for(let a=0;a<o;a++){const c=s[a],{localName:d,prefix:w}=c;if(d===u&&w===f){if(b===h-1){t.add(c);break}b++}}}}else{let b=h-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<o){let a=n>0?0:h-1;for(let c=0;c<o;c++){const d=s[c],{localName:w,prefix:N}=d;if(w===u&&N===f){if(a===b&&(t.add(d),b+=n),b<0||b>=o)break;n>0?a++:a--}}}}}else{const{root:s}=this.#t;e===s&&s.nodeType===r.ELEMENT_NODE&&n+h===1&&t.add(e)}return t}_matchAnPlusB(i,e,n){const{nth:{a:h,b:l,name:u},selector:m}=i,f=(0,k.unescapeSelector)(u),t=new Map;f?(f==="even"?(t.set("a",2),t.set("b",0)):f==="odd"&&(t.set("a",2),t.set("b",1)),n.indexOf("last")>-1&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?t.set("b",l*1):t.set("b",0),n.indexOf("last")>-1&&t.set("reverse",!0));let s=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(n)){m&&t.set("selector",m);const o=Object.fromEntries(t),b=this._collectNthChild(o,e);b.size&&(s=b)}else if(/^nth-(?:last-)?of-type$/.test(n)){const o=Object.fromEntries(t),b=this._collectNthOfType(o,e);b.size&&(s=b)}}return s}_matchPseudoElementSelector(i,e={}){const{forgive:n}=e;switch(i){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${i}`,r.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${i}()`,r.NOT_SUPPORTED_ERR);break}default:if(i.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${i}`,r.NOT_SUPPORTED_ERR)}else if(!n)throw new DOMException(`Unknown pseudo-element ::${i}`,r.SYNTAX_ERR)}}_matchDirectionPseudoClass(i,e){const n=(0,k.unescapeSelector)(i.name),h=(0,E.getDirectionality)(e);let l;return n===h&&(l=e),l??null}_matchLanguagePseudoClass(i,e){const n=(0,k.unescapeSelector)(i.name);let h;if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let l=e.parentNode;for(;l&&l.nodeType===r.ELEMENT_NODE;){if(l.hasAttribute("lang")){l.getAttribute("lang")&&(h=e);break}l=l.parentNode}}else if(n){const l=`(?:-${r.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${r.ALPHA_NUM}${l}$`,"i").test(n)){let m;if(n.indexOf("-")>-1){const[f,t,...s]=n.split("-");let o;f==="*"?o=`${r.ALPHA_NUM}${l}`:o=`${f}${l}`;const b=`-${t}${l}`,a=s.length;let c="";if(a)for(let d=0;d<a;d++)c+=`-${s[d]}${l}`;m=new RegExp(`^${o}${b}${c}$`,"i")}else m=new RegExp(`^${n}${l}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(h=e);else{let f=e.parentNode;for(;f&&f.nodeType===r.ELEMENT_NODE;){if(f.hasAttribute("lang")){const t=f.getAttribute("lang");m.test(t)&&(h=e);break}f=f.parentNode}}}}return h??null}_matchHasPseudoFunc(i,e){let n;if(Array.isArray(i)&&i.length){const[h]=i,{type:l}=h;let u;l===r.COMBINATOR?u=i.shift():u={name:" ",type:r.COMBINATOR};const m=[];for(;i.length;){const[s]=i,{type:o}=s;if(o===r.COMBINATOR)break;m.push(i.shift())}const f={combo:u,leaves:m},t=this._matchCombinator(f,e,{find:P});if(t.size)if(i.length){for(const s of t)if(n=this._matchHasPseudoFunc(Object.assign([],i),s),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(i,e){const{astName:n="",branches:h=[],selector:l="",twigBranches:u=[]}=i;let m;if(n==="has")if(l.includes(":has("))m=null;else{const f=h.length;let t;for(let s=0;s<f;s++){const o=h[s];if(t=this._matchHasPseudoFunc(Object.assign([],o),e),t)break}t&&(m=e)}else{const f=/^(?:is|where)$/.test(n),t=u.length;let s;for(let o=0;o<t;o++){const b=u[o],a=b.length-1,{leaves:c}=b[a];if(s=this._matchLeaves(c,e,{forgive:f}),s&&a>0){let d=new Set([e]);for(let w=a-1;w>=0;w--){const N=b[w],_=[];for(const x of d){const p=this._matchCombinator(N,x,{forgive:f,find:R});p.size&&_.push(...p)}if(_.length)if(w===0){s=!0;break}else d=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(m=e):s&&(m=e)}return m??null}_matchPseudoClassSelector(i,e,n={}){const{children:h}=i,{localName:l,parentNode:u}=e,{forgive:m}=n,f=(0,k.unescapeSelector)(i.name);let t=new Set;if(r.REG_LOGICAL_PSEUDO.test(f)){let s;if(this.#a.has(i))s=this.#a.get(i);else{const b=(0,k.walkAST)(i),a=[],c=[];for(const[...d]of b){for(const x of d){const p=(0,k.generateCSS)(x);a.push(p)}const w=[],N=new Set;let _=d.shift();for(;_;)if(_.type===r.COMBINATOR?(w.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),d.length)_=d.shift();else{w.push({combo:null,leaves:[...N]}),N.clear();break}c.push(w)}s={astName:f,branches:b,twigBranches:c,selector:a.join(",")},this.#a.set(i,s)}const o=this._matchLogicalPseudoFunc(s,e);o&&t.add(o)}else if(Array.isArray(h)){const[s]=h;if(/^nth-(?:last-)?(?:child|of-type)$/.test(f)){const o=this._matchAnPlusB(s,e,f);o.size&&(t=o)}else if(f==="dir"){const o=this._matchDirectionPseudoClass(s,e);o&&t.add(o)}else if(f==="lang"){const o=this._matchLanguagePseudoClass(s,e);o&&t.add(o)}else switch(f){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}()`,r.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;default:if(!m)throw new DOMException(`Unknown pseudo-class :${f}()`,r.SYNTAX_ERR)}}else{const{document:s,root:o}=this.#t,b=/^a(?:rea)?$/,a=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,c=/^(?:(?:inpu|selec)t|button|form|textarea)$/,d=/^d(?:etails|ialog)$/,w=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,_=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,x=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(f){case"any-link":case"link":{b.test(l)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(b.test(l)&&e.hasAttribute("href")){const{href:p,origin:g,pathname:y}=new URL(s.URL),A=new URL(e.getAttribute("href"),p);A.origin===g&&A.pathname===y&&t.add(e)}break}case"visited":break;case"target":{const{hash:p}=new URL(s.URL);e.id&&p===`#${e.id}`&&s.contains(e)&&t.add(e);break}case"target-within":{const{hash:p}=new URL(s.URL);if(p){const g=p.replace(/^#/,"");let y=s.getElementById(g);for(;y;){if(y===e){t.add(e);break}y=y.parentNode}}break}case"scope":{this.#e.nodeType===r.ELEMENT_NODE?e===this.#e&&t.add(e):e===s.documentElement&&t.add(e);break}case"focus":{e===s.activeElement&&t.add(e);break}case"focus-within":{let p=s.activeElement;for(;p;){if(p===e){t.add(e);break}p=p.parentNode}break}case"open":{d.test(l)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{d.test(l)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(a.test(l)||(0,M.default)(l))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let p=u;for(;p&&p.localName!=="fieldset";)p=p.parentNode;p&&u.localName!=="legend"&&p.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(a.test(l)||(0,M.default)(l))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||x.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||x.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let p;l==="textarea"?p=e:l==="input"&&(e.hasAttribute("type")?x.test(e.getAttribute("type"))&&(p=e):p=e),p&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))||e.selected&&l==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))t.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const p=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=s.documentElement);const y=[].slice.call(g.getElementsByTagName("input"));let A;for(const v of y)if(v.getAttribute("type")==="radio"&&(p?v.getAttribute("name")===p&&(A=!!v.checked):v.hasAttribute("name")||(A=!!v.checked),A))break;A||t.add(e)}break}case"default":{const p=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(l==="button"&&!(e.hasAttribute("type")&&p.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let y=e.parentNode;for(;y&&y.localName!=="form";)y=y.parentNode;if(y){const A=s.createNodeIterator(y,r.SHOW_ELEMENT);let v=A.nextNode();for(;v;){const L=v.localName;let S;if(L==="button"?S=!(v.hasAttribute("type")&&p.test(v.getAttribute("type"))):L==="input"&&(S=v.hasAttribute("type")&&g.test(v.getAttribute("type"))),S){v===e&&t.add(e);break}v=A.nextNode()}}}else if(l==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(l==="option"){let y=!1,A=u;for(;A&&A.localName!=="datalist";){if(A.localName==="select"){(A.multiple||A.hasAttribute("multiple"))&&(y=!0);break}A=A.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=u.firstElementChild,L=new Set;let S=v;for(;S;){if(S.selected||S.hasAttribute("selected")){L.add(S);break}S=S.nextElementSibling}L.size||L.add(v),L.has(e)&&t.add(e)}}break}case"valid":{if(c.test(l))e.checkValidity()&&t.add(e);else if(l==="fieldset"){const p=s.createNodeIterator(e,r.SHOW_ELEMENT);let g=p.nextNode();g===e&&(g=p.nextNode());let y;for(;g&&!(c.test(g.localName)&&(y=g.checkValidity(),!y));)g=p.nextNode();y&&t.add(e)}break}case"invalid":{if(c.test(l))e.checkValidity()||t.add(e);else if(l==="fieldset"){const p=s.createNodeIterator(e,r.SHOW_ELEMENT);let g=p.nextNode();g===e&&(g=p.nextNode());let y;for(;g&&!(c.test(g.localName)&&(y=g.checkValidity(),!y));)g=p.nextNode();y||t.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&_.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":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&_.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let p;if(/^(?:select|textarea)$/.test(l))p=e;else if(l==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||w.test(g)||N.test(g)||x.test(g))&&(p=e)}else p=e;p&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let p;if(/^(?:select|textarea)$/.test(l))p=e;else if(l==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||w.test(g)||N.test(g)||x.test(g))&&(p=e)}else p=e;p&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===s.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const p=e.childNodes.values();let g;for(const y of p)if(g=y.nodeType!==r.ELEMENT_NODE&&y.nodeType!==r.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(u&&e===u.firstElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(u&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(u&&e===u.firstElementChild&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(u){const[p]=this._collectNthOfType({a:0,b:1},e);p&&t.add(p)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(u){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p&&t.add(p)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(u){const[p]=this._collectNthOfType({a:0,b:1},e);if(p===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${f}`,r.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 :${f}`,r.NOT_SUPPORTED_ERR);break}default:if(f.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,r.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${f}`,r.SYNTAX_ERR)}}return t}_matchAttributeSelector(i,e){const{flags:n,matcher:h,name:l,value:u}=i;if(typeof n=="string"&&!/^[is]$/i.test(n)){const t=(0,k.generateCSS)(i);throw new DOMException(`Invalid selector ${t}`,r.SYNTAX_ERR)}const{attributes:m}=e;let f;if(m&&m.length){const{document:t}=this.#t;let s;t.contentType==="text/html"?typeof n=="string"&&/^s$/i.test(n)?s=!1:s=!0:typeof n=="string"&&/^i$/i.test(n)?s=!0:s=!1;let o=(0,k.unescapeSelector)(l.name);s&&(o=o.toLowerCase());const b=new Set;if(o.indexOf("|")>-1){const{prefix:a,tagName:c}=(0,E.selectorToNodeProps)(o);for(let{name:d,value:w}of m)switch(s&&(d=d.toLowerCase(),w=w.toLowerCase()),a){case"":{c===d&&b.add(w);break}case"*":{d.indexOf(":")>-1?d.endsWith(`:${c}`)&&b.add(w):c===d&&b.add(w);break}default:if(d.indexOf(":")>-1){const[N,_]=d.split(":");a===N&&c===_&&(0,E.isNamespaceDeclared)(a,e)&&b.add(w)}}}else for(let{name:a,value:c}of m)if(s&&(a=a.toLowerCase(),c=c.toLowerCase()),a.indexOf(":")>-1){const[d,w]=a.split(":");if(d==="xml"&&w==="lang")continue;o===w&&b.add(c)}else o===a&&b.add(c);if(b.size){const{name:a,value:c}=u||{};let d;switch(a?s?d=a.toLowerCase():d=a:c?s?d=c.toLowerCase():d=c:c===""&&(d=c),h){case"=":{typeof d=="string"&&b.has(d)&&(f=e);break}case"~=":{if(d&&typeof d=="string"){for(const w of b)if(new Set(w.split(/\s+/)).has(d)){f=e;break}}break}case"|=":{if(d&&typeof d=="string"){let w;for(const N of b)if(N===d||N.startsWith(`${d}-`)){w=N;break}w&&(f=e)}break}case"^=":{if(d&&typeof d=="string"){let w;for(const N of b)if(N.startsWith(`${d}`)){w=N;break}w&&(f=e)}break}case"$=":{if(d&&typeof d=="string"){let w;for(const N of b)if(N.endsWith(`${d}`)){w=N;break}w&&(f=e)}break}case"*=":{if(d&&typeof d=="string"){let w;for(const N of b)if(N.includes(`${d}`)){w=N;break}w&&(f=e)}break}case null:default:f=e}}}return f??null}_matchClassSelector(i,e){const n=(0,k.unescapeSelector)(i.name);let h;return e.classList.contains(n)&&(h=e),h??null}_matchIDSelector(i,e){const n=(0,k.unescapeSelector)(i.name),{id:h}=e;let l;return n===h&&(l=e),l??null}_matchTypeSelector(i,e,n={}){const h=(0,k.unescapeSelector)(i.name),{localName:l,prefix:u}=e,{forgive:m}=n,{document:f}=this.#t;let{prefix:t,tagName:s}=(0,E.selectorToNodeProps)(h,e);f.contentType==="text/html"&&(t=t.toLowerCase(),s=s.toLowerCase());let o,b;l.indexOf(":")>-1?[o,b]=l.split(":"):(o=u||"",b=l);let a;if(t===""&&o==="")e.namespaceURI===null&&(s==="*"||s===b)&&(a=e);else if(t==="*")(s==="*"||s===b)&&(a=e);else if(t===o){if((0,E.isNamespaceDeclared)(t,e))(s==="*"||s===b)&&(a=e);else if(!m)throw new DOMException(`Undeclared namespace ${t}`,r.SYNTAX_ERR)}else if(t&&!m&&!(0,E.isNamespaceDeclared)(t,e))throw new DOMException(`Undeclared namespace ${t}`,r.SYNTAX_ERR);return a??null}_matchShadowHostPseudoClass(i,e){const{children:n}=i,h=(0,k.unescapeSelector)(i.name);let l;if(Array.isArray(n)){const[u]=(0,k.walkAST)(n[0]),[...m]=u,{host:f}=e;if(h==="host"){let t;for(const s of m){const{type:o}=s;if(o===r.COMBINATOR){const b=(0,k.generateCSS)(i);throw new DOMException(`Invalid selector ${b}`,r.SYNTAX_ERR)}if(t=this._matchSelector(s,f).has(f),!t)break}t&&(l=e)}else if(h==="host-context"){let t=f,s;for(;t;){for(const o of m){const{type:b}=o;if(b===r.COMBINATOR){const a=(0,k.generateCSS)(i);throw new DOMException(`Invalid selector ${a}`,r.SYNTAX_ERR)}if(s=this._matchSelector(o,t).has(t),!s)break}if(s)break;t=t.parentNode}s&&(l=e)}}else if(h==="host")l=e;else throw new DOMException(`Invalid selector :${h}`,r.SYNTAX_ERR);return l??null}_matchSelector(i,e,n){const{type:h}=i,l=(0,k.unescapeSelector)(i.name),{shadow:u}=this.#t;let m=new Set;if(e.nodeType===r.ELEMENT_NODE)switch(h){case r.SELECTOR_ATTR:{const f=this._matchAttributeSelector(i,e);f&&m.add(f);break}case r.SELECTOR_CLASS:{const f=this._matchClassSelector(i,e);f&&m.add(f);break}case r.SELECTOR_ID:{const f=this._matchIDSelector(i,e);f&&m.add(f);break}case r.SELECTOR_PSEUDO_CLASS:{const f=this._matchPseudoClassSelector(i,e,n);f.size&&(m=f);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(l,n);break}case r.SELECTOR_TYPE:default:{const f=this._matchTypeSelector(i,e,n);f&&m.add(f)}}else if(u&&h===r.SELECTOR_PSEUDO_CLASS&&e.nodeType===r.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&r.REG_LOGICAL_PSEUDO.test(l)){const f=this._matchPseudoClassSelector(i,e,n);f.size&&(m=f)}else if(r.REG_SHADOW_HOST.test(l)){const f=this._matchShadowHostPseudoClass(i,e);f&&m.add(f)}}return m}_matchLeaves(i,e,n){let h;for(const l of i)if(h=this._matchSelector(l,e,n).has(e),!h)break;return!!h}_findDescendantNodes(i,e){const[n,...h]=i,{type:l}=n,u=(0,k.unescapeSelector)(n.name),m=h.length>0,{document:f,root:t,shadow:s}=this.#t;let o=new Set,b=!1;if(s)b=!0;else switch(l){case r.SELECTOR_ID:{if(t.nodeType===r.ELEMENT_NODE)b=!0;else{const a=t.getElementById(u);a&&a!==e&&e.contains(a)&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a))}break}case r.SELECTOR_CLASS:{const a=[].slice.call(e.getElementsByClassName(u));if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_TYPE:{if(f.contentType==="text/html"&&!/[*|]/.test(u)){const a=[].slice.call(e.getElementsByTagName(u));if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a)}else b=!0;break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:b=!0}return{nodes:o,pending:b}}_matchCombinator(i,e,n={}){const{combo:h,leaves:l}=i,{name:u}=h,{find:m,forgive:f}=n;let t=new Set;if(m===P)switch(u){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(l,s,{forgive:f})&&t.add(s);break}case"~":{let s=e.nextElementSibling;for(;s;)this._matchLeaves(l,s,{forgive:f})&&t.add(s),s=s.nextElementSibling;break}case">":{const s=[].slice.call(e.children);for(const o of s)this._matchLeaves(l,o,{forgive:f})&&t.add(o);break}case" ":default:{const{nodes:s,pending:o}=this._findDescendantNodes(l,e);if(s.size)t=s;else if(o){const{document:b}=this.#t,a=b.createNodeIterator(e,r.SHOW_ELEMENT);let c=a.nextNode();for(c===e&&(c=a.nextNode());c;)this._matchLeaves(l,c,{forgive:f})&&t.add(c),c=a.nextNode()}}}else switch(u){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(l,s,{forgive:f})&&t.add(s);break}case"~":{const s=[];let o=e.previousElementSibling;for(;o;)this._matchLeaves(l,o,{forgive:f})&&s.push(o),o=o.previousElementSibling;s.length&&(t=new Set(s.reverse()));break}case">":{const s=e.parentNode;s&&this._matchLeaves(l,s,{forgive:f})&&t.add(s);break}case" ":default:{const s=[];let o=e.parentNode;for(;o;)this._matchLeaves(l,o,{forgive:f})&&s.push(o),o=o.parentNode;s.length&&(t=new Set(s.reverse()))}}return t}_findNodes(i,e){const{leaves:[n,...h]}=i,{type:l}=n,u=(0,k.unescapeSelector)(n.name),m=h.length>0,{document:f,root:t,shadow:s}=this.#t;let o=new Set,b=!1;switch(l){case r.SELECTOR_ID:{let a;if(e===D)this._matchLeaves([n],this.#e)&&(a=this.#e);else if(e===O){let c=this.#e;for(;c;){if(this._matchLeaves([n],c)){a=c;break}c=c.parentNode}}else e===C||t.nodeType===r.ELEMENT_NODE?b=!0:a=t.getElementById(u);a&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a));break}case r.SELECTOR_CLASS:{let a=[];if(e===D)this.#e.nodeType===r.ELEMENT_NODE&&this.#e.classList.contains(u)&&a.push(this.#e);else if(e===O){let c=this.#e;for(;c&&c.nodeType===r.ELEMENT_NODE;)c.classList.contains(u)&&a.push(c),c=c.parentNode}else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=[].slice.call(t.children);for(const d of c){d.classList.contains(u)&&a.push(d);const w=[].slice.call(d.getElementsByClassName(u));a.push(...w)}}else{const c=[].slice.call(t.getElementsByClassName(u));if(this.#e.nodeType===r.ELEMENT_NODE)for(const d of c)(d===this.#e||(0,E.isInclusive)(d,this.#e))&&a.push(d);else a=c}if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_TYPE:{let a=[];if(e===D)this.#e.nodeType===r.ELEMENT_NODE&&this._matchLeaves([n],this.#e)&&a.push(this.#e);else if(e===O){let c=this.#e;for(;c&&c.nodeType===r.ELEMENT_NODE;)this._matchLeaves([n],c)&&a.push(c),c=c.parentNode}else if(f.contentType!=="text/html"||/[*|]/.test(u))b=!0;else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=u.toLowerCase(),d=[].slice.call(t.children);for(const w of d){w.localName===c&&a.push(w);const N=[].slice.call(w.getElementsByTagName(u));a.push(...N)}}else{const c=[].slice.call(t.getElementsByTagName(u));if(this.#e.nodeType===r.ELEMENT_NODE)for(const d of c)(d===this.#e||(0,E.isInclusive)(d,this.#e))&&a.push(d);else a=c}if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:{const a=[];if(e!==O&&r.REG_SHADOW_HOST.test(u)){if(s&&this.#e.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=this._matchShadowHostPseudoClass(n,this.#e);c&&a.push(c)}}else if(e===D)this._matchLeaves([n],this.#e)&&a.push(this.#e);else if(e===O){let c=this.#e;for(;c;)this._matchLeaves([n],c)&&a.push(c),c=c.parentNode}else b=!0;if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a)}}if(m&&!b&&!o.size){const a=h[h.length-1],{type:c}=a;if(c===r.SELECTOR_PSEUDO_CLASS){let d;t.nodeType===r.ELEMENT_NODE?d=t:d=t.firstElementChild,this._matchPseudoClassSelector(a,d)}}return{nodes:o,pending:b}}_getFirstTwig(i){const e=i.length-1,n=i[0];let h,l;if(e){const u=i[e],{leaves:[{type:m}]}=u;m===r.SELECTOR_PSEUDO_ELEMENT||m===r.SELECTOR_ID?(h=R,l=u):(h=P,l=n)}else h=R,l=n;return{find:h,twig:l}}_collectNodes(i){const e=this.#i.values();if(i===C||i===$){const n=new Set;let h=0;for(const{branch:l}of e){const{find:u,twig:m}=this._getFirstTwig(l),{nodes:f,pending:t}=this._findNodes(m,i);f.size?this.#l[h]=f:t?n.add(new Map([["index",h],["twig",m]])):this.#i[h].skip=!0,this.#i[h].find=u,h++}if(n.size){const{document:l,root:u}=this.#t,m=l.createNodeIterator(u,r.SHOW_ELEMENT);let f=m.nextNode();for(;f;){let t=!1;if(this.#e.nodeType===r.ELEMENT_NODE?f===this.#e?t=!0:t=this.#e.contains(f):t=!0,t)for(const s of n){const{leaves:o}=s.get("twig");if(this._matchLeaves(o,f)){const a=s.get("index");this.#l[a].add(f)}}f=m.nextNode()}}}else{let n=0;for(const{branch:h}of e){const l=h[h.length-1],{nodes:u}=this._findNodes(l,i);u.size?this.#l[n]=u:this.#i[n].skip=!0,this.#i[n].find=R,n++}}return[this.#i,this.#l]}_sortNodes(i){const e=[...i];return e.length>1&&e.sort((n,h)=>{let l;return(0,E.isPreceding)(h,n)?l=1:l=-1,l}),e}_matchNodes(i){const[...e]=this.#i,n=e.length;let h=new Set;for(let l=0;l<n;l++){const{branch:u,find:m,skip:f}=e[l],t=u.length;if(!f&&t){const s=this.#l[l],o=t-1;if(o===0)if((i===C||i===$)&&this.#e.nodeType===r.ELEMENT_NODE){for(const b of s)if(b!==this.#e&&this.#e.contains(b)&&(h.add(b),i===$))break}else if(i===$){const[b]=this._sortNodes(s);h.add(b)}else{const b=[...h],a=[...s];h=new Set([...b,...a])}else if(m===P){let{combo:b}=u[0];for(const a of s){let c=new Set([a]);for(let d=1;d<t;d++){const{combo:w,leaves:N}=u[d],_=[];for(const x of c){const p={combo:b,leaves:N},g=this._matchCombinator(p,x,{find:m});g.size&&_.push(...g)}if(_.length)if(d===o){if(i===$){const[x]=this._sortNodes(_);h.add(x)}else{const x=[...h];h=new Set([...x,..._])}break}else b=w,c=new Set(_);else break}}}else for(const b of s){let a=new Set([b]),c;for(let d=o-1;d>=0;d--){const w=u[d],N=[];for(const _ of a){const x=this._matchCombinator(w,_,{find:m});x.size&&N.push(...x)}if(N.length)if(c=!0,d===0){h.add(b);break}else a=new Set(N);else{c=!1;break}}if(c&&i!==C)break}}}return h}_find(i){return this._collectNodes(i),this._matchNodes(i)}matches(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let i;try{i=this._find(D).has(this.#e)}catch(e){this._onError(e)}return!!i}closest(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let i;try{const e=this._find(O);let n=this.#e;for(;n;){if(e.has(n)){i=n;break}n=n.parentNode}}catch(e){this._onError(e)}return i??null}querySelector(){let i;try{const e=this._find($);e.delete(this.#e),e.size&&([i]=this._sortNodes(e))}catch(e){this._onError(e)}return i??null}querySelectorAll(){let i;try{const e=this._find(C);e.delete(this.#e),e.size&&(i=this._sortNodes(e))}catch(e){this._onError(e)}return i??[]}}0&&(module.exports={Matcher});
1
+ var B=Object.create;var R=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(S,a)=>{for(var e in a)R(S,e,{get:a[e],enumerable:!0})},U=(S,a,e,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of F(a))!j.call(S,f)&&f!==e&&R(S,f,{get:()=>a[f],enumerable:!(c=z(a,f))||c.enumerable});return S};var W=(S,a,e)=>(e=S!=null?B(V(S)):{},U(a||!S||!S.__esModule?R(e,"default",{value:S,enumerable:!0}):e,S)),G=S=>U(R({},"__esModule",{value:!0}),S);var X={};H(X,{Matcher:()=>q});module.exports=G(X);var M=W(require("is-potential-custom-element-name"),1),x=require("./dom-util.js"),k=require("./parser.js"),o=require("./constant.js");const C="next",D="prev",$="all",I="first",O="lineal",P="self";class q{#t;#r;#a;#e;#l;#s;#o;#i;constructor(a,e,c={}){const{warn:f}=c;this.#r=new Map([[o.SELECTOR_PSEUDO_ELEMENT,o.BIT_01],[o.SELECTOR_ID,o.BIT_02],[o.SELECTOR_CLASS,o.BIT_04],[o.SELECTOR_TYPE,o.BIT_08],[o.SELECTOR_ATTR,o.BIT_16],[o.SELECTOR_PSEUDO_CLASS,o.BIT_32]]),this.#a=new WeakMap,this.#o=a,this.#e=e,this.#i=!!f,[this.#t,this.#l]=this._prepare(a),this.#s=this._getRoot(e)}_onError(a){if(a instanceof DOMException&&a.name===o.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw a}_getRoot(a=this.#e){let e,c;switch(a.nodeType){case o.DOCUMENT_NODE:{e=a,c=a;break}case o.DOCUMENT_FRAGMENT_NODE:{e=a.ownerDocument,c=a;break}case o.ELEMENT_NODE:{if(a.ownerDocument.contains(a))e=a.ownerDocument,c=a.ownerDocument;else{let r=a;for(;r&&r.parentNode;)r=r.parentNode;e=r.ownerDocument,c=r}break}default:throw new TypeError(`Unexpected node ${a.nodeName}`)}const f=(0,x.isInShadowTree)(a);return{document:e,root:c,shadow:f}}_sortLeaves(a){const e=[...a];return e.length>1&&e.sort((c,f)=>{const{type:r}=c,{type:d}=f,m=this.#r.get(r),l=this.#r.get(d);let t;return m===l?t=0:m>l?t=1:t=-1,t}),e}_prepare(a=this.#o){const e=(0,k.parseSelector)(a),c=(0,k.walkAST)(e),f=[],r=[];let d=0;for(const[...m]of c){const l=[];let t=m.shift();if(t&&t.type!==o.COMBINATOR){const s=new Set;for(;t;){if(t.type===o.COMBINATOR){const[n]=m;if(n.type===o.COMBINATOR){const b=`Invalid combinator ${t.name}${n.name}`;throw new DOMException(b,o.SYNTAX_ERR)}l.push({combo:t,leaves:this._sortLeaves(s)}),s.clear()}else t&&s.add(t);if(m.length)t=m.shift();else{l.push({combo:null,leaves:this._sortLeaves(s)}),s.clear();break}}}f.push({branch:l,filtered:!1,find:null,skip:!1}),r[d]=new Set,d++}return[f,r]}_collectNthChild(a,e){const{a:c,b:f,reverse:r,selector:d}=a,{parentNode:m}=e,l=new Set;let t;if(d&&(this.#a.has(d)?t=this.#a.get(d):(t=(0,k.walkAST)(d),this.#a.set(d,t))),m){const s=[].slice.call(m.children),n=s.length;if(n){const b=new Set;if(t){const i=t.length;for(const h of s){let u;for(let w=0;w<i;w++){const N=t[w];if(u=this._matchLeaves(N,h),!u)break}u&&b.add(h)}}if(r&&s.reverse(),c===0){if(f>0&&f<=n){if(b.size)for(let i=0;i<n;i++){const h=s[i];if(b.has(h)){l.add(h);break}}else if(!d){const i=s[f-1];l.add(i)}}}else{let i=f-1;if(c>0)for(;i<0;)i+=c;if(i>=0&&i<n){let h=c>0?0:f-1;for(let u=0;u<n&&i>=0&&i<n;u++){const w=s[u];b.size?b.has(w)&&(h===i&&(l.add(w),i+=c),c>0?h++:h--):u===i&&(d||l.add(w),i+=c)}}}}}else{const{root:s}=this.#s;if(e===s&&s.nodeType===o.ELEMENT_NODE&&c+f===1)if(t){const n=t.length;let b;for(let i=0;i<n;i++){const h=t[i];if(b=this._matchLeaves(h,e),b)break}b&&l.add(e)}else l.add(e)}return l}_collectNthOfType(a,e){const{a:c,b:f,reverse:r}=a,{localName:d,parentNode:m,prefix:l}=e,t=new Set;if(m){const s=[].slice.call(m.children),n=s.length;if(n)if(r&&s.reverse(),c===0){if(f>0&&f<=n){let b=0;for(let i=0;i<n;i++){const h=s[i],{localName:u,prefix:w}=h;if(u===d&&w===l){if(b===f-1){t.add(h);break}b++}}}}else{let b=f-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b<n){let i=c>0?0:f-1;for(let h=0;h<n;h++){const u=s[h],{localName:w,prefix:N}=u;if(w===d&&N===l){if(i===b&&(t.add(u),b+=c),b<0||b>=n)break;c>0?i++:i--}}}}}else{const{root:s}=this.#s;e===s&&s.nodeType===o.ELEMENT_NODE&&c+f===1&&t.add(e)}return t}_matchAnPlusB(a,e,c){const{nth:{a:f,b:r,name:d},selector:m}=a,l=(0,k.unescapeSelector)(d),t=new Map;l?(l==="even"?(t.set("a",2),t.set("b",0)):l==="odd"&&(t.set("a",2),t.set("b",1)),c.indexOf("last")>-1&&t.set("reverse",!0)):(typeof f=="string"&&/-?\d+/.test(f)?t.set("a",f*1):t.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?t.set("b",r*1):t.set("b",0),c.indexOf("last")>-1&&t.set("reverse",!0));let s=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){m&&t.set("selector",m);const n=Object.fromEntries(t),b=this._collectNthChild(n,e);b.size&&(s=b)}else if(/^nth-(?:last-)?of-type$/.test(c)){const n=Object.fromEntries(t),b=this._collectNthOfType(n,e);b.size&&(s=b)}}return s}_matchPseudoElementSelector(a,e={}){const{forgive:c}=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"placeholder":case"selection":case"target-text":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${a}`,o.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${a}()`,o.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${a}`,o.NOT_SUPPORTED_ERR)}else if(!c)throw new DOMException(`Unknown pseudo-element ::${a}`,o.SYNTAX_ERR)}}_matchDirectionPseudoClass(a,e){const c=(0,k.unescapeSelector)(a.name),f=(0,x.getDirectionality)(e);let r;return c===f&&(r=e),r??null}_matchLanguagePseudoClass(a,e){const c=(0,k.unescapeSelector)(a.name);let f;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(f=e);else{let r=e.parentNode;for(;r&&r.nodeType===o.ELEMENT_NODE;){if(r.hasAttribute("lang")){r.getAttribute("lang")&&(f=e);break}r=r.parentNode}}else if(c){const r=`(?:-${o.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${o.ALPHA_NUM}${r}$`,"i").test(c)){let m;if(c.indexOf("-")>-1){const[l,t,...s]=c.split("-");let n;l==="*"?n=`${o.ALPHA_NUM}${r}`:n=`${l}${r}`;const b=`-${t}${r}`,i=s.length;let h="";if(i)for(let u=0;u<i;u++)h+=`-${s[u]}${r}`;m=new RegExp(`^${n}${b}${h}$`,"i")}else m=new RegExp(`^${c}${r}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(f=e);else{let l=e.parentNode;for(;l&&l.nodeType===o.ELEMENT_NODE;){if(l.hasAttribute("lang")){const t=l.getAttribute("lang");m.test(t)&&(f=e);break}l=l.parentNode}}}}return f??null}_matchHasPseudoFunc(a,e){let c;if(Array.isArray(a)&&a.length){const[f]=a,{type:r}=f;let d;r===o.COMBINATOR?d=a.shift():d={name:" ",type:o.COMBINATOR};const m=[];for(;a.length;){const[s]=a,{type:n}=s;if(n===o.COMBINATOR)break;m.push(a.shift())}const l={combo:d,leaves:m},t=this._matchCombinator(l,e,{find:C});if(t.size)if(a.length){for(const s of t)if(c=this._matchHasPseudoFunc(Object.assign([],a),s),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(a,e){const{astName:c="",branches:f=[],selector:r="",twigBranches:d=[]}=a;let m;if(c==="has")if(r.includes(":has("))m=null;else{const l=f.length;let t;for(let s=0;s<l;s++){const n=f[s];if(t=this._matchHasPseudoFunc(Object.assign([],n),e),t)break}t&&(m=e)}else{const l=/^(?:is|where)$/.test(c),t=d.length;let s;for(let n=0;n<t;n++){const b=d[n],i=b.length-1,{leaves:h}=b[i];if(s=this._matchLeaves(h,e,{forgive:l}),s&&i>0){let u=new Set([e]);for(let w=i-1;w>=0;w--){const N=b[w],E=[];for(const A of u){const p=this._matchCombinator(N,A,{forgive:l,find:D});p.size&&E.push(...p)}if(E.length)if(w===0){s=!0;break}else u=new Set(E);else{s=!1;break}}}if(s)break}c==="not"?s||(m=e):s&&(m=e)}return m??null}_matchPseudoClassSelector(a,e,c={}){const{children:f}=a,{localName:r,parentNode:d}=e,{forgive:m}=c,l=(0,k.unescapeSelector)(a.name);let t=new Set;if(o.REG_LOGICAL_PSEUDO.test(l)){let s;if(this.#a.has(a))s=this.#a.get(a);else{const b=(0,k.walkAST)(a),i=[],h=[];for(const[...u]of b){for(const A of u){const p=(0,k.generateCSS)(A);i.push(p)}const w=[],N=new Set;let E=u.shift();for(;E;)if(E.type===o.COMBINATOR?(w.push({combo:E,leaves:[...N]}),N.clear()):E&&N.add(E),u.length)E=u.shift();else{w.push({combo:null,leaves:[...N]}),N.clear();break}h.push(w)}s={astName:l,branches:b,twigBranches:h,selector:i.join(",")},this.#a.set(a,s)}const n=this._matchLogicalPseudoFunc(s,e);n&&t.add(n)}else if(Array.isArray(f)){const[s]=f;if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const n=this._matchAnPlusB(s,e,l);n.size&&(t=n)}else if(l==="dir"){const n=this._matchDirectionPseudoClass(s,e);n&&t.add(n)}else if(l==="lang"){const n=this._matchLanguagePseudoClass(s,e);n&&t.add(n)}else switch(l){case"current":case"nth-col":case"nth-last-col":{if(this.#i)throw new DOMException(`Unsupported pseudo-class :${l}()`,o.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;default:if(!m)throw new DOMException(`Unknown pseudo-class :${l}()`,o.SYNTAX_ERR)}}else{const{document:s,root:n}=this.#s,b=/^a(?:rea)?$/,i=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,h=/^(?:(?:inpu|selec)t|button|form|textarea)$/,u=/^d(?:etails|ialog)$/,w=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,E=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,A=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(l){case"any-link":case"link":{b.test(r)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(b.test(r)&&e.hasAttribute("href")){const{href:p,origin:g,pathname:y}=new URL(s.URL),_=new URL(e.getAttribute("href"),p);_.origin===g&&_.pathname===y&&t.add(e)}break}case"visited":break;case"target":{const{hash:p}=new URL(s.URL);e.id&&p===`#${e.id}`&&s.contains(e)&&t.add(e);break}case"target-within":{const{hash:p}=new URL(s.URL);if(p){const g=p.replace(/^#/,"");let y=s.getElementById(g);for(;y;){if(y===e){t.add(e);break}y=y.parentNode}}break}case"scope":{this.#e.nodeType===o.ELEMENT_NODE?e===this.#e&&t.add(e):e===s.documentElement&&t.add(e);break}case"focus":{e===s.activeElement&&t.add(e);break}case"focus-within":{let p=s.activeElement;for(;p;){if(p===e){t.add(e);break}p=p.parentNode}break}case"open":{u.test(r)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{u.test(r)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(i.test(r)||(0,M.default)(r))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let p=d;for(;p&&p.localName!=="fieldset";)p=p.parentNode;p&&d.localName!=="legend"&&p.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(i.test(r)||(0,M.default)(r))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(r){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||A.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,x.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||A.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,x.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let p;r==="textarea"?p=e:r==="input"&&(e.hasAttribute("type")?A.test(e.getAttribute("type"))&&(p=e):p=e),p&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&r==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))||e.selected&&r==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&r==="input"&&e.type==="checkbox"||r==="progress"&&!e.hasAttribute("value"))t.add(e);else if(r==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const p=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=s.documentElement);const y=[].slice.call(g.getElementsByTagName("input"));let _;for(const v of y)if(v.getAttribute("type")==="radio"&&(p?v.getAttribute("name")===p&&(_=!!v.checked):v.hasAttribute("name")||(_=!!v.checked),_))break;_||t.add(e)}break}case"default":{const p=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(r==="button"&&!(e.hasAttribute("type")&&p.test(e.getAttribute("type")))||r==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let y=e.parentNode;for(;y&&y.localName!=="form";)y=y.parentNode;if(y){const _=s.createNodeIterator(y,o.SHOW_ELEMENT);let v=_.nextNode();for(;v;){const T=v.localName;let L;if(T==="button"?L=!(v.hasAttribute("type")&&p.test(v.getAttribute("type"))):T==="input"&&(L=v.hasAttribute("type")&&g.test(v.getAttribute("type"))),L){v===e&&t.add(e);break}v=_.nextNode()}}}else if(r==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(r==="option"){let y=!1,_=d;for(;_&&_.localName!=="datalist";){if(_.localName==="select"){(_.multiple||_.hasAttribute("multiple"))&&(y=!0);break}_=_.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=d.firstElementChild,T=new Set;let L=v;for(;L;){if(L.selected||L.hasAttribute("selected")){T.add(L);break}L=L.nextElementSibling}T.size||T.add(v),T.has(e)&&t.add(e)}}break}case"valid":{if(h.test(r))e.checkValidity()&&t.add(e);else if(r==="fieldset"){const p=s.createNodeIterator(e,o.SHOW_ELEMENT);let g=p.nextNode();g===e&&(g=p.nextNode());let y;for(;g&&!(h.test(g.localName)&&(y=g.checkValidity(),!y));)g=p.nextNode();y&&t.add(e)}break}case"invalid":{if(h.test(r))e.checkValidity()||t.add(e);else if(r==="fieldset"){const p=s.createNodeIterator(e,o.SHOW_ELEMENT);let g=p.nextNode();g===e&&(g=p.nextNode());let y;for(;g&&!(h.test(g.localName)&&(y=g.checkValidity(),!y));)g=p.nextNode();y||t.add(e)}break}case"in-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&E.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":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&E.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let p;if(/^(?:select|textarea)$/.test(r))p=e;else if(r==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||w.test(g)||N.test(g)||A.test(g))&&(p=e)}else p=e;p&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let p;if(/^(?:select|textarea)$/.test(r))p=e;else if(r==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||w.test(g)||N.test(g)||A.test(g))&&(p=e)}else p=e;p&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===s.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const p=e.childNodes.values();let g;for(const y of p)if(g=y.nodeType!==o.ELEMENT_NODE&&y.nodeType!==o.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(d&&e===d.firstElementChild||e===n&&n.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(d&&e===d.lastElementChild||e===n&&n.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||e===n&&n.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(d){const[p]=this._collectNthOfType({a:0,b:1},e);p&&t.add(p)}else e===n&&n.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(d){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p&&t.add(p)}else e===n&&n.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(d){const[p]=this._collectNthOfType({a:0,b:1},e);if(p===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===n&&n.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${l}`,o.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 :${l}`,o.NOT_SUPPORTED_ERR);break}default:if(l.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-class :${l}`,o.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${l}`,o.SYNTAX_ERR)}}return t}_matchAttributeSelector(a,e){const{flags:c,matcher:f,name:r,value:d}=a;if(typeof c=="string"&&!/^[is]$/i.test(c)){const t=(0,k.generateCSS)(a);throw new DOMException(`Invalid selector ${t}`,o.SYNTAX_ERR)}const{attributes:m}=e;let l;if(m&&m.length){const{document:t}=this.#s;let s;t.contentType==="text/html"?typeof c=="string"&&/^s$/i.test(c)?s=!1:s=!0:typeof c=="string"&&/^i$/i.test(c)?s=!0:s=!1;let n=(0,k.unescapeSelector)(r.name);s&&(n=n.toLowerCase());const b=new Set;if(n.indexOf("|")>-1){const{prefix:i,tagName:h}=(0,x.selectorToNodeProps)(n);for(let{name:u,value:w}of m)switch(s&&(u=u.toLowerCase(),w=w.toLowerCase()),i){case"":{h===u&&b.add(w);break}case"*":{u.indexOf(":")>-1?u.endsWith(`:${h}`)&&b.add(w):h===u&&b.add(w);break}default:if(u.indexOf(":")>-1){const[N,E]=u.split(":");i===N&&h===E&&(0,x.isNamespaceDeclared)(i,e)&&b.add(w)}}}else for(let{name:i,value:h}of m)if(s&&(i=i.toLowerCase(),h=h.toLowerCase()),i.indexOf(":")>-1){const[u,w]=i.split(":");if(u==="xml"&&w==="lang")continue;n===w&&b.add(h)}else n===i&&b.add(h);if(b.size){const{name:i,value:h}=d||{};let u;switch(i?s?u=i.toLowerCase():u=i:h?s?u=h.toLowerCase():u=h:h===""&&(u=h),f){case"=":{typeof u=="string"&&b.has(u)&&(l=e);break}case"~=":{if(u&&typeof u=="string"){for(const w of b)if(new Set(w.split(/\s+/)).has(u)){l=e;break}}break}case"|=":{if(u&&typeof u=="string"){let w;for(const N of b)if(N===u||N.startsWith(`${u}-`)){w=N;break}w&&(l=e)}break}case"^=":{if(u&&typeof u=="string"){let w;for(const N of b)if(N.startsWith(`${u}`)){w=N;break}w&&(l=e)}break}case"$=":{if(u&&typeof u=="string"){let w;for(const N of b)if(N.endsWith(`${u}`)){w=N;break}w&&(l=e)}break}case"*=":{if(u&&typeof u=="string"){let w;for(const N of b)if(N.includes(`${u}`)){w=N;break}w&&(l=e)}break}case null:default:l=e}}}return l??null}_matchClassSelector(a,e){const c=(0,k.unescapeSelector)(a.name);let f;return e.classList.contains(c)&&(f=e),f??null}_matchIDSelector(a,e){const c=(0,k.unescapeSelector)(a.name),{id:f}=e;let r;return c===f&&(r=e),r??null}_matchTypeSelector(a,e,c={}){const f=(0,k.unescapeSelector)(a.name),{localName:r,prefix:d}=e,{forgive:m}=c,{document:l}=this.#s;let{prefix:t,tagName:s}=(0,x.selectorToNodeProps)(f,e);l.contentType==="text/html"&&(t=t.toLowerCase(),s=s.toLowerCase());let n,b;r.indexOf(":")>-1?[n,b]=r.split(":"):(n=d||"",b=r);let i;if(t===""&&n==="")e.namespaceURI===null&&(s==="*"||s===b)&&(i=e);else if(t==="*")(s==="*"||s===b)&&(i=e);else if(t===n){if((0,x.isNamespaceDeclared)(t,e))(s==="*"||s===b)&&(i=e);else if(!m)throw new DOMException(`Undeclared namespace ${t}`,o.SYNTAX_ERR)}else if(t&&!m&&!(0,x.isNamespaceDeclared)(t,e))throw new DOMException(`Undeclared namespace ${t}`,o.SYNTAX_ERR);return i??null}_matchShadowHostPseudoClass(a,e){const{children:c}=a,f=(0,k.unescapeSelector)(a.name);let r;if(Array.isArray(c)){const[d]=(0,k.walkAST)(c[0]),[...m]=d,{host:l}=e;if(f==="host"){let t;for(const s of m){const{type:n}=s;if(n===o.COMBINATOR){const b=(0,k.generateCSS)(a);throw new DOMException(`Invalid selector ${b}`,o.SYNTAX_ERR)}if(t=this._matchSelector(s,l).has(l),!t)break}t&&(r=e)}else if(f==="host-context"){let t=l,s;for(;t;){for(const n of m){const{type:b}=n;if(b===o.COMBINATOR){const i=(0,k.generateCSS)(a);throw new DOMException(`Invalid selector ${i}`,o.SYNTAX_ERR)}if(s=this._matchSelector(n,t).has(t),!s)break}if(s)break;t=t.parentNode}s&&(r=e)}}else if(f==="host")r=e;else throw new DOMException(`Invalid selector :${f}`,o.SYNTAX_ERR);return r??null}_matchSelector(a,e,c){const{type:f}=a,r=(0,k.unescapeSelector)(a.name),{shadow:d}=this.#s;let m=new Set;if(e.nodeType===o.ELEMENT_NODE)switch(f){case o.SELECTOR_ATTR:{const l=this._matchAttributeSelector(a,e);l&&m.add(l);break}case o.SELECTOR_CLASS:{const l=this._matchClassSelector(a,e);l&&m.add(l);break}case o.SELECTOR_ID:{const l=this._matchIDSelector(a,e);l&&m.add(l);break}case o.SELECTOR_PSEUDO_CLASS:{const l=this._matchPseudoClassSelector(a,e,c);l.size&&(m=l);break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(r,c);break}case o.SELECTOR_TYPE:default:{const l=this._matchTypeSelector(a,e,c);l&&m.add(l)}}else if(d&&f===o.SELECTOR_PSEUDO_CLASS&&e.nodeType===o.DOCUMENT_FRAGMENT_NODE){if(r!=="has"&&o.REG_LOGICAL_PSEUDO.test(r)){const l=this._matchPseudoClassSelector(a,e,c);l.size&&(m=l)}else if(o.REG_SHADOW_HOST.test(r)){const l=this._matchShadowHostPseudoClass(a,e);l&&m.add(l)}}return m}_matchLeaves(a,e,c){let f;for(const r of a)if(f=this._matchSelector(r,e,c).has(e),!f)break;return!!f}_findDescendantNodes(a,e){const[c,...f]=a,{type:r}=c,d=(0,k.unescapeSelector)(c.name),m=f.length>0,{document:l,root:t,shadow:s}=this.#s;let n=new Set,b=!1;if(s)b=!0;else switch(r){case o.SELECTOR_ID:{if(t.nodeType===o.ELEMENT_NODE)b=!0;else{const i=t.getElementById(d);i&&i!==e&&e.contains(i)&&(m?this._matchLeaves(f,i)&&n.add(i):n.add(i))}break}case o.SELECTOR_CLASS:{const i=[].slice.call(e.getElementsByClassName(d));if(i.length)if(m)for(const h of i)this._matchLeaves(f,h)&&n.add(h);else n=new Set(i);break}case o.SELECTOR_TYPE:{if(l.contentType==="text/html"&&!/[*|]/.test(d)){const i=[].slice.call(e.getElementsByTagName(d));if(i.length)if(m)for(const h of i)this._matchLeaves(f,h)&&n.add(h);else n=new Set(i)}else b=!0;break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(d);break}default:b=!0}return{nodes:n,pending:b}}_matchCombinator(a,e,c={}){const{combo:f,leaves:r}=a,{name:d}=f,{find:m,forgive:l}=c;let t=new Set;if(m===C)switch(d){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(r,s,{forgive:l})&&t.add(s);break}case"~":{let s=e.nextElementSibling;for(;s;)this._matchLeaves(r,s,{forgive:l})&&t.add(s),s=s.nextElementSibling;break}case">":{const s=[].slice.call(e.children);for(const n of s)this._matchLeaves(r,n,{forgive:l})&&t.add(n);break}case" ":default:{const{nodes:s,pending:n}=this._findDescendantNodes(r,e);if(s.size)t=s;else if(n){const{document:b}=this.#s,i=b.createNodeIterator(e,o.SHOW_ELEMENT);let h=i.nextNode();for(h===e&&(h=i.nextNode());h;)this._matchLeaves(r,h,{forgive:l})&&t.add(h),h=i.nextNode()}}}else switch(d){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(r,s,{forgive:l})&&t.add(s);break}case"~":{const s=[];let n=e.previousElementSibling;for(;n;)this._matchLeaves(r,n,{forgive:l})&&s.push(n),n=n.previousElementSibling;s.length&&(t=new Set(s.reverse()));break}case">":{const s=e.parentNode;s&&this._matchLeaves(r,s,{forgive:l})&&t.add(s);break}case" ":default:{const s=[];let n=e.parentNode;for(;n;)this._matchLeaves(r,n,{forgive:l})&&s.push(n),n=n.parentNode;s.length&&(t=new Set(s.reverse()))}}return t}_findNodes(a,e){const{leaves:[c,...f]}=a,{type:r}=c,d=(0,k.unescapeSelector)(c.name),{document:m,root:l,shadow:t}=this.#s;let s=new Set,n=!1;switch(r){case o.SELECTOR_ID:{if(e===P)this._matchLeaves([c],this.#e)&&s.add(this.#e);else if(e===O){let i=this.#e;for(;i;){if(this._matchLeaves([c],i)){s.add(i);break}i=i.parentNode}}else if(e===$||l.nodeType===o.ELEMENT_NODE)n=!0;else{const i=l.getElementById(d);i&&s.add(i)}break}case o.SELECTOR_CLASS:{if(e===P)this.#e.nodeType===o.ELEMENT_NODE&&this.#e.classList.contains(d)&&s.add(this.#e);else if(e===O){let i=this.#e;for(;i&&i.nodeType===o.ELEMENT_NODE;)i.classList.contains(d)&&s.add(i),i=i.parentNode}else if(l.nodeType===o.DOCUMENT_FRAGMENT_NODE){const i=[].slice.call(l.children),h=[];for(const u of i){u.classList.contains(d)&&h.push(u);const w=[].slice.call(u.getElementsByClassName(d));h.push(...w)}h.length&&(s=new Set(h))}else{const i=[].slice.call(l.getElementsByClassName(d));if(this.#e.nodeType===o.ELEMENT_NODE)for(const h of i)(h===this.#e||(0,x.isInclusive)(h,this.#e))&&s.add(h);else i.length&&(s=new Set(i))}break}case o.SELECTOR_TYPE:{if(e===P)this.#e.nodeType===o.ELEMENT_NODE&&this._matchLeaves([c],this.#e)&&s.add(this.#e);else if(e===O){let i=this.#e;for(;i&&i.nodeType===o.ELEMENT_NODE;)this._matchLeaves([c],i)&&s.add(i),i=i.parentNode}else if(m.contentType!=="text/html"||/[*|]/.test(d))n=!0;else if(l.nodeType===o.DOCUMENT_FRAGMENT_NODE){const i=d.toLowerCase(),h=[].slice.call(l.children),u=[];for(const w of h){w.localName===i&&u.push(w);const N=[].slice.call(w.getElementsByTagName(d));u.push(...N)}u.length&&(s=new Set(u))}else{const i=[].slice.call(l.getElementsByTagName(d));if(this.#e.nodeType===o.ELEMENT_NODE)for(const h of i)(h===this.#e||(0,x.isInclusive)(h,this.#e))&&s.add(h);else i.length&&(s=new Set(i))}break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(d);break}default:if(e!==O&&o.REG_SHADOW_HOST.test(d)){if(t&&this.#e.nodeType===o.DOCUMENT_FRAGMENT_NODE){const i=this._matchShadowHostPseudoClass(c,this.#e);i&&s.add(i)}}else if(e===P)this._matchLeaves([c],this.#e)&&s.add(this.#e);else if(e===O){let i=this.#e;for(;i;)this._matchLeaves([c],i)&&s.add(i),i=i.parentNode}else n=!0}const b=f.length;if(!s.size&&!n&&b){const i=f[b-1],{type:h}=i;if(h===o.SELECTOR_PSEUDO_CLASS){let u;l.nodeType===o.ELEMENT_NODE?u=l:u=l.firstElementChild,this._matchPseudoClassSelector(i,u)}}return{compound:b>0,nodes:s,pending:n}}_getEntryTwig(a,e){const c=a.length,f=a[0];let r,d;if(c>1){const{leaves:[{type:m}]}=f,l=a[c-1],{leaves:[{type:t}]}=l;t===o.SELECTOR_PSEUDO_ELEMENT||t===o.SELECTOR_ID?(r=D,d=l):m===o.SELECTOR_PSEUDO_ELEMENT||m===o.SELECTOR_ID?(r=C,d=f):e===I&&c<o.BIT_04?(r=D,d=l):(r=C,d=f)}else r=D,d=f;return{find:r,twig:d}}_collectNodes(a){const e=this.#t.values();if(a===$||a===I){const c=new Set;let f=0;for(const{branch:r}of e){const{find:d,twig:m}=this._getEntryTwig(r,a),{compound:l,nodes:t,pending:s}=this._findNodes(m,a);t.size?this.#l[f]=t:s?c.add(new Map([["index",f],["twig",m]])):this.#t[f].skip=!0,this.#t[f].filtered=!l,this.#t[f].find=d,f++}if(c.size){const{document:r,root:d}=this.#s,m=r.createNodeIterator(d,o.SHOW_ELEMENT);let l=m.nextNode();for(;l;){let t=!1;if(this.#e.nodeType===o.ELEMENT_NODE?l===this.#e?t=!0:t=this.#e.contains(l):t=!0,t)for(const s of c){const{leaves:n}=s.get("twig");if(this._matchLeaves(n,l)){const i=s.get("index");this.#l[i].add(l),this.#t[i].filtered||(this.#t[i].filtered=!0)}}l=m.nextNode()}}}else{let c=0;for(const{branch:f}of e){const r=f[f.length-1],{compound:d,nodes:m}=this._findNodes(r,a);m.size?this.#l[c]=m:this.#t[c].skip=!0,this.#t[c].filtered=!d,this.#t[c].find=D,c++}}return[this.#t,this.#l]}_sortNodes(a){const e=[...a];return e.length>1&&e.sort((c,f)=>{let r;return(0,x.isPreceding)(f,c)?r=1:r=-1,r}),e}_matchNodes(a){const[...e]=this.#t,c=e.length;let f=new Set;for(let r=0;r<c;r++){const{branch:d,filtered:m,find:l,skip:t}=e[r],s=d.length;if(!t&&s){const n=this.#l[r],b=s-1;if(b===0){const{leaves:[,...i]}=d[0];if((a===$||a===I)&&this.#e.nodeType===o.ELEMENT_NODE){for(const h of n)if((m||this._matchLeaves(i,h))&&h!==this.#e&&this.#e.contains(h)&&(f.add(h),a!==$))break}else if(i.length){for(const h of n)if((m||this._matchLeaves(i,h))&&(f.add(h),a!==$))break}else if(a===$){const h=[...f];f=new Set([...h,...n])}else{const[h]=[...n];f.add(h)}}else if(l===C){let{combo:i,leaves:[,...h]}=d[0];for(const u of n){const w=m||this._matchLeaves(h,u);let N;if(w){let E=new Set([u]);for(let A=1;A<s;A++){const{combo:p,leaves:g}=d[A],y=[];for(const _ of E){const v={combo:i,leaves:g},T=this._matchCombinator(v,_,{find:l});T.size&&y.push(...T)}if(y.length)if(A===b){if(a===I){const[_]=this._sortNodes(y);f.add(_)}else{const _=[...f];f=new Set([..._,...y])}N=!0;break}else N=!1,i=p,E=new Set(y);else{N=!1;break}}}else N=!1;if(N&&a!==$)break}}else{const{leaves:[,...i]}=d[b];for(const h of n){const u=m||this._matchLeaves(i,h);let w;if(u){let N=new Set([h]);for(let E=b-1;E>=0;E--){const A=d[E],p=[];for(const g of N){const y=this._matchCombinator(A,g,{find:l});y.size&&p.push(...y)}if(p.length)if(E===0){f.add(h),w=!0;break}else w=!1,N=new Set(p);else{w=!1;break}}}else w=!1;if(w&&a!==$)break}}}}return f}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(){if(this.#e.nodeType!==o.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let a;try{const e=this._find(P);e.size&&(a=e.has(this.#e))}catch(e){this._onError(e)}return!!a}closest(){if(this.#e.nodeType!==o.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let a;try{const e=this._find(O);let c=this.#e;for(;c;){if(e.has(c)){a=c;break}c=c.parentNode}}catch(e){this._onError(e)}return a??null}querySelector(){let a;try{const e=this._find(I);e.delete(this.#e),e.size&&([a]=this._sortNodes(e))}catch(e){this._onError(e)}return a??null}querySelectorAll(){let a;try{const e=this._find($);e.delete(this.#e),e.size&&(a=this._sortNodes(e))}catch(e){this._onError(e)}return a??[]}}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, isInclusive, isInShadowTree,\n isNamespaceDeclared, isPreceding, selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, COMBINATOR,\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, NOT_SUPPORTED_ERR,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_ATTR, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\nconst FIND_NEXT = 'next';\nconst FIND_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * find: string\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 #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.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { warn } = opt;\n this.#bit = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\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 (node.ownerDocument.contains(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 const shadow = isInShadowTree(node);\n return {\n document,\n root,\n shadow\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - collection of 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>>} - array of ast and nodes\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 {Set.<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 = [].slice.call(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 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 && 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 (node === root && root.nodeType === ELEMENT_NODE && (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 {Set.<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 = [].slice.call(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 (node === root && root.nodeType === ELEMENT_NODE && (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 {Set.<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 (nthName.indexOf('last') > -1) {\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 (nthName.indexOf('last') > -1) {\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 'placeholder':\n case 'selection':\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 case 'part':\n case 'slotted': {\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 astName = unescapeSelector(ast.name);\n let res;\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n } else if (astName) {\n const langPart = `(?:-${ALPHA_NUM})*`;\n const regLang = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${langPart}$`, 'i');\n if (regLang.test(astName)) {\n let regExtendedLang;\n if (astName.indexOf('-') > -1) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${langPart}`;\n } else {\n extendedMain = `${langMain}${langPart}`;\n }\n const extendedSub = `-${langSub}${langPart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${langPart}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${langPart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (regExtendedLang.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (regExtendedLang.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\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: 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 const l = branches.length;\n let bool;\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 const l = twigBranches.length;\n let bool;\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, { forgive });\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: FIND_PREV\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = new Set(arr);\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 {Set.<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 (REG_LOGICAL_PSEUDO.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 (/^nth-(?:last-)?(?:child|of-type)$/.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 case 'host':\n case 'host-context': {\n // ignore\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 regAnchor = /^a(?:rea)?$/;\n const regFormCtrl =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\n const regFormValidity = /^(?:(?:inpu|selec)t|button|form|textarea)$/;\n const regInteract = /^d(?:etails|ialog)$/;\n const regTypeCheck = /^(?:checkbox|radio)$/;\n const regTypeDate = /^(?:date(?:time-local)?|month|time|week)$/;\n const regTypeRange =\n /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\n const regTypeText = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n const { href, origin, pathname } = new URL(document.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n const { hash } = new URL(document.URL);\n if (node.id && hash === `#${node.id}` && document.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(document.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = document.getElementById(id);\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 === document.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 (regInteract.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (regInteract.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (regFormCtrl.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 && parentNode.localName !== 'legend' &&\n parent.hasAttribute('disabled')) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((regFormCtrl.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 || regTypeDate.test(node.type) ||\n regTypeText.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 || regTypeDate.test(node.type) ||\n regTypeText.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 (regTypeText.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '' &&\n node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length) {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\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 = document.documentElement;\n }\n const nodes = [].slice.call(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 const regTypeReset = /^(?:button|reset)$/;\n const regTypeSubmit = /^(?:image|submit)$/;\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n regTypeReset.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n regTypeSubmit.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 regTypeReset.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n regTypeSubmit.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 regTypeCheck.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 (regFormValidity.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\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 (regFormValidity.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 (regFormValidity.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\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 (regFormValidity.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 regTypeRange.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 regTypeRange.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 (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\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 (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\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 === document.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 (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\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 (node === root && root.nodeType === ELEMENT_NODE) {\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 (node === root && root.nodeType === ELEMENT_NODE) {\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 (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\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 const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, 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 astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\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 (itemName.indexOf(':') > -1) {\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 (itemName.indexOf(':') > -1) {\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 (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else 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 astName = unescapeSelector(ast.name);\n const { id } = node;\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 * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { forgive } = opt;\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 (localName.indexOf(':') > -1) {\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 if (isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (!forgive) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n } else if (astPrefix && !forgive && !isNamespaceDeclared(astPrefix, node)) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n return res ?? null;\n };\n\n /**\n * match shadow host pseudo class\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren } = ast;\n const astName = unescapeSelector(ast.name);\n let res;\n if (Array.isArray(astChildren)) {\n const [branch] = walkAST(astChildren[0]);\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n throw new DOMException(`Invalid selector :${astName}`, SYNTAX_ERR);\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 {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n const { shadow } = this.#root;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_ATTR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_CLASS: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_ID: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n const res = this._matchTypeSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node);\n if (res) {\n matched.add(res);\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} - collection of nodes and pending state\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, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n if (shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_ID: {\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(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 break;\n }\n case SELECTOR_CLASS: {\n const arr = [].slice.call(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 SELECTOR_TYPE: {\n if (document.contentType === 'text/html' && !/[*|]/.test(leafName)) {\n const arr = [].slice.call(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 } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\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 {Set.<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 === FIND_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\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, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [].slice.call(node.children);\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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} - collection of nodes and pending state\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, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case SELECTOR_ID: {\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 (targetType === TARGET_ALL ||\n 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 SELECTOR_CLASS: {\n let 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 = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByClassName(leafName));\n arr.push(...a);\n }\n } else {\n const a = [].slice.call(root.getElementsByClassName(leafName));\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (const node of a) {\n if (node === this.#node || isInclusive(node, this.#node)) {\n arr.push(node);\n }\n }\n } else {\n arr = a;\n }\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 SELECTOR_TYPE: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\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 = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByTagName(leafName));\n arr.push(...a);\n }\n } else {\n const a = [].slice.call(root.getElementsByTagName(leafName));\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (const node of a) {\n if (node === this.#node || isInclusive(node, this.#node)) {\n arr.push(node);\n }\n }\n } else {\n arr = a;\n }\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 SELECTOR_PSEUDO_ELEMENT: {\n // throws\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (shadow && this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n arr.push(node);\n }\n }\n } else 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 if (matchItems && !pending && !nodes.size) {\n const lastLeaf = items[items.length - 1];\n const { type: lastLeafType } = lastLeaf;\n if (lastLeafType === SELECTOR_PSEUDO_CLASS) {\n let node;\n if (root.nodeType === ELEMENT_NODE) {\n node = root;\n } else {\n node = root.firstElementChild;\n }\n // throws if unknown pseudo-class\n this._matchPseudoClassSelector(lastLeaf, node);\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} - find direction and twig\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 === SELECTOR_PSEUDO_ELEMENT || lastType === SELECTOR_ID) {\n find = FIND_PREV;\n twig = lastTwig;\n } else {\n find = FIND_NEXT;\n twig = firstTwig;\n }\n } else {\n find = 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>>} - #ast and #nodes\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 if (nextNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(nextNode);\n }\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 = FIND_PREV;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {Set.<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 && this.#node.contains(node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(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 === 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 if (arr.length) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(arr);\n nodes.add(node);\n } else {\n const n = [...nodes];\n nodes = new Set([...n, ...arr]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\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 if (arr.length) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = new Set(arr);\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 {Set.<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 * 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) {\n [res] = this._sortNodes(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 let res;\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n res = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAMO,yBACP,MAAMC,EAAY,OACZC,EAAY,OACZC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OA8Bb,MAAMX,CAAQ,CAEnBY,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GASA,YAAYC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CACpC,KAAM,CAAE,KAAAC,CAAK,EAAID,EACjB,KAAKT,GAAO,IAAI,IAAI,CAClB,CAAC,0BAAyB,QA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AAS,CAAC,CACjB,CACA,OAAOJ,GAAO,IAChB,CAOA,kBAAmB,CACjB,IAAIA,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAMjC,CAAU,EACnCiC,EAAM,OAAO,KAAK1B,EAAK,EACnB0B,EAAM,OACRJ,EAAM,KAAK,WAAWI,CAAK,EAE/B,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,CAAC,CACjB,CACF",
6
- "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "FIND_NEXT", "FIND_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#warn", "selector", "node", "opt", "warn", "e", "document", "root", "parent", "shadow", "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", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "astChildren", "selectors", "css", "leavesSet", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "href", "origin", "pathname", "attrURL", "hash", "id", "isCustomElementName", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "astPrefix", "astNodeName", "nodePrefix", "host", "astType", "baseNode", "leafName", "matchItems", "pending", "comboName", "find", "childNodes", "targetType", "tagName", "lastLeaf", "lastLeafType", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "skip", "branchLen", "n", "nextCombo"]
4
+ "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isInclusive, isInShadowTree,\n isNamespaceDeclared, isPreceding, selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, COMBINATOR,\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, NOT_SUPPORTED_ERR,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_ATTR, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\nconst FIND_NEXT = 'next';\nconst FIND_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * filtered: boolean,\n * find: string,\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * filtered: boolean,\n * find: string,\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 #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.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { warn } = opt;\n this.#bit = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\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 (node.ownerDocument.contains(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 const shadow = isInShadowTree(node);\n return {\n document,\n root,\n shadow\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - collection of 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>>} - array of ast and nodes\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 filtered: false,\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 {Set.<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 = [].slice.call(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 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 && 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 (node === root && root.nodeType === ELEMENT_NODE && (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 {Set.<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 = [].slice.call(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 (node === root && root.nodeType === ELEMENT_NODE && (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 {Set.<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 (nthName.indexOf('last') > -1) {\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 (nthName.indexOf('last') > -1) {\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 'placeholder':\n case 'selection':\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 case 'part':\n case 'slotted': {\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 astName = unescapeSelector(ast.name);\n let res;\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n } else if (astName) {\n const langPart = `(?:-${ALPHA_NUM})*`;\n const regLang = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${langPart}$`, 'i');\n if (regLang.test(astName)) {\n let regExtendedLang;\n if (astName.indexOf('-') > -1) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${langPart}`;\n } else {\n extendedMain = `${langMain}${langPart}`;\n }\n const extendedSub = `-${langSub}${langPart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${langPart}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${langPart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (regExtendedLang.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (regExtendedLang.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\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: 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 const l = branches.length;\n let bool;\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 const l = twigBranches.length;\n let bool;\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, { forgive });\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: FIND_PREV\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = new Set(arr);\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 {Set.<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 (REG_LOGICAL_PSEUDO.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 (/^nth-(?:last-)?(?:child|of-type)$/.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 case 'host':\n case 'host-context': {\n // ignore\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 regAnchor = /^a(?:rea)?$/;\n const regFormCtrl =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\n const regFormValidity = /^(?:(?:inpu|selec)t|button|form|textarea)$/;\n const regInteract = /^d(?:etails|ialog)$/;\n const regTypeCheck = /^(?:checkbox|radio)$/;\n const regTypeDate = /^(?:date(?:time-local)?|month|time|week)$/;\n const regTypeRange =\n /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\n const regTypeText = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n const { href, origin, pathname } = new URL(document.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n const { hash } = new URL(document.URL);\n if (node.id && hash === `#${node.id}` && document.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(document.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = document.getElementById(id);\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 === document.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 (regInteract.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (regInteract.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (regFormCtrl.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 && parentNode.localName !== 'legend' &&\n parent.hasAttribute('disabled')) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((regFormCtrl.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 || regTypeDate.test(node.type) ||\n regTypeText.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 || regTypeDate.test(node.type) ||\n regTypeText.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 (regTypeText.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '' &&\n node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length) {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\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 = document.documentElement;\n }\n const nodes = [].slice.call(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 const regTypeReset = /^(?:button|reset)$/;\n const regTypeSubmit = /^(?:image|submit)$/;\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n regTypeReset.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n regTypeSubmit.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 regTypeReset.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n regTypeSubmit.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 regTypeCheck.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 (regFormValidity.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\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 (regFormValidity.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 (regFormValidity.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\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 (regFormValidity.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 regTypeRange.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 regTypeRange.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 (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\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 (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\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 === document.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 (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\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 (node === root && root.nodeType === ELEMENT_NODE) {\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 (node === root && root.nodeType === ELEMENT_NODE) {\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 (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\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 const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, 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 astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\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 (itemName.indexOf(':') > -1) {\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 (itemName.indexOf(':') > -1) {\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 (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else 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 astName = unescapeSelector(ast.name);\n const { id } = node;\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 * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { forgive } = opt;\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 (localName.indexOf(':') > -1) {\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 if (isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (!forgive) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n } else if (astPrefix && !forgive && !isNamespaceDeclared(astPrefix, node)) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n return res ?? null;\n };\n\n /**\n * match shadow host pseudo class\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren } = ast;\n const astName = unescapeSelector(ast.name);\n let res;\n if (Array.isArray(astChildren)) {\n const [branch] = walkAST(astChildren[0]);\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n throw new DOMException(`Invalid selector :${astName}`, SYNTAX_ERR);\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 {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n const { shadow } = this.#root;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_ATTR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_CLASS: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_ID: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n const res = this._matchTypeSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node);\n if (res) {\n matched.add(res);\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} - collection of nodes and pending state\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, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n if (shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_ID: {\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(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 break;\n }\n case SELECTOR_CLASS: {\n const arr = [].slice.call(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 SELECTOR_TYPE: {\n if (document.contentType === 'text/html' && !/[*|]/.test(leafName)) {\n const arr = [].slice.call(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 } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\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 {Set.<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 === FIND_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\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, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [].slice.call(node.children);\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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} - collection of nodes etc.\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n nodes.add(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 nodes.add(refNode);\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (targetType === TARGET_ALL ||\n root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = root.getElementById(leafName);\n if (node) {\n nodes.add(node);\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n nodes.add(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 nodes.add(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [].slice.call(root.children);\n const arr = [];\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByClassName(leafName));\n arr.push(...a);\n }\n if (arr.length) {\n nodes = new Set(arr);\n }\n } else {\n const arr = [].slice.call(root.getElementsByClassName(leafName));\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (const node of arr) {\n if (node === this.#node || isInclusive(node, this.#node)) {\n nodes.add(node);\n }\n }\n } else if (arr.length) {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n nodes.add(this.#node);\n }\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 nodes.add(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 = [].slice.call(root.children);\n const arr = [];\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByTagName(leafName));\n arr.push(...a);\n }\n if (arr.length) {\n nodes = new Set(arr);\n }\n } else {\n const arr = [].slice.call(root.getElementsByTagName(leafName));\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (const node of arr) {\n if (node === this.#node || isInclusive(node, this.#node)) {\n nodes.add(node);\n }\n }\n } else if (arr.length) {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n // throws\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (shadow && this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.add(node);\n }\n }\n } else if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n nodes.add(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 nodes.add(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n }\n }\n const itemsLen = items.length;\n // check last leaf if node not found, not pending and leaves left\n if (!nodes.size && !pending && itemsLen) {\n const lastLeaf = items[itemsLen - 1];\n const { type: lastLeafType } = lastLeaf;\n if (lastLeafType === SELECTOR_PSEUDO_CLASS) {\n let node;\n if (root.nodeType === ELEMENT_NODE) {\n node = root;\n } else {\n node = root.firstElementChild;\n }\n // throws if unknown pseudo-class\n this._matchPseudoClassSelector(lastLeaf, node);\n }\n }\n return {\n compound: itemsLen > 0,\n nodes,\n pending\n };\n }\n\n /**\n * get entry twig\n * @param {Array.<object>} branch - AST branch\n * @param {string} targetType - target type\n * @returns {object} - find direction and twig\n */\n _getEntryTwig(branch, targetType) {\n const branchLen = branch.length;\n const firstTwig = branch[0];\n let find;\n let twig;\n if (branchLen > 1) {\n const { leaves: [{ type: firstType }] } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const { leaves: [{ type: lastType }] } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT || lastType === SELECTOR_ID) {\n find = FIND_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n find = FIND_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_FIRST && branchLen < BIT_04) {\n find = FIND_PREV;\n twig = lastTwig;\n } else {\n find = FIND_NEXT;\n twig = firstTwig;\n }\n } else {\n find = 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>>} - #ast and #nodes\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._getEntryTwig(branch, targetType);\n const { compound, 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].filtered = !compound;\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 if (nextNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(nextNode);\n }\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 if (!this.#ast[index].filtered) {\n this.#ast[index].filtered = true;\n }\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 { compound, 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].filtered = !compound;\n this.#ast[i].find = FIND_PREV;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {Set.<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, filtered, find, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const collectedNodes = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n const { leaves: [, ...filterLeaves] } = branch[0];\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of collectedNodes) {\n const bool = filtered || this._matchLeaves(filterLeaves, node);\n if (bool && node !== this.#node && this.#node.contains(node)) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (!filterLeaves.length) {\n if (targetType === TARGET_ALL) {\n const n = [...nodes];\n nodes = new Set([...n, ...collectedNodes]);\n } else {\n const [node] = [...collectedNodes];\n nodes.add(node);\n }\n } else {\n for (const node of collectedNodes) {\n const bool = filtered || this._matchLeaves(filterLeaves, node);\n if (bool) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n } else if (find === FIND_NEXT) {\n let { combo, leaves: [, ...filterLeaves] } = branch[0];\n for (const node of collectedNodes) {\n const bool = filtered || this._matchLeaves(filterLeaves, node);\n let matched;\n if (bool) {\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 if (arr.length) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(arr);\n nodes.add(node);\n } else {\n const n = [...nodes];\n nodes = new Set([...n, ...arr]);\n }\n matched = true;\n break;\n } else {\n matched = false;\n combo = nextCombo;\n nextNodes = new Set(arr);\n }\n } else {\n matched = false;\n break;\n }\n }\n } else {\n matched = false;\n }\n if (matched && targetType !== TARGET_ALL) {\n break;\n }\n }\n } else {\n const { leaves: [, ...filterLeaves] } = branch[lastIndex];\n for (const node of collectedNodes) {\n const bool = filtered || this._matchLeaves(filterLeaves, node);\n let matched;\n if (bool) {\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, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n nodes.add(node);\n matched = true;\n break;\n } else {\n matched = false;\n nextNodes = new Set(arr);\n }\n } else {\n matched = false;\n break;\n }\n }\n } else {\n matched = false;\n }\n if (matched && 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 {Set.<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 * 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 if (nodes.size) {\n res = nodes.has(this.#node);\n }\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) {\n [res] = this._sortNodes(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 let res;\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n res = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBAC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EAAM,OACRJ,EAAM,KAAK,WAAWI,CAAK,EAE/B,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,CAAC,CACjB,CACF",
6
+ "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "FIND_NEXT", "FIND_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#warn", "selector", "node", "opt", "warn", "e", "document", "root", "parent", "shadow", "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", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "astChildren", "selectors", "css", "leavesSet", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "href", "origin", "pathname", "attrURL", "hash", "id", "isCustomElementName", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "astPrefix", "astNodeName", "nodePrefix", "host", "astType", "baseNode", "leafName", "matchItems", "pending", "comboName", "find", "childNodes", "targetType", "tagName", "itemsLen", "lastLeaf", "lastLeafType", "branchLen", "firstTwig", "firstType", "lastTwig", "lastType", "pendingItems", "compound", "pendingItem", "index", "filtered", "skip", "collectedNodes", "filterLeaves", "n", "nextCombo"]
7
7
  }
@@ -1,3 +1,3 @@
1
- var E=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var $=(s,t)=>{for(var r in t)E(s,r,{get:t[r],enumerable:!0})},w=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of S(t))!O.call(s,n)&&n!==r&&E(s,n,{get:()=>t[n],enumerable:!(i=x(t,n))||i.enumerable});return s};var y=s=>w(E({},"__esModule",{value:!0}),s);var L={};$(L,{generateCSS:()=>m.generate,parseSelector:()=>d,preprocess:()=>u,unescapeSelector:()=>D,walkAST:()=>_});module.exports=y(L);var g=require("css-tree"),e=require("./constant.js"),m=require("css-tree");const D=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let i=1;i<r;i++){let n=t[i];if(n===""&&i===r-1)n=e.U_FFFD;else{const a=/^([\da-f]{1,6}\s?)/i.exec(n);if(a){const[,o]=a;let l;try{const c=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),h=parseInt(o,e.HEX);h===0||h>=c&&h<=p?l=e.U_FFFD:l=String.fromCodePoint(h)}catch{l=e.U_FFFD}let f="";n.length>o.length&&(f=n.substring(o.length)),n=`${l}${f}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},u=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let n=t.substring(r+1);const a=n.codePointAt(0);if(a===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(a>e.MAX_BIT_16){const o=`\\${a.toString(e.HEX)} `;n.length===e.DUO?n=o:n=`${o}${n.substring(e.DUO)}`}t=`${i}${n}`,r++}t=t.replace(/\f|\r\n?/g,`
2
- `).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},d=s=>{if(s=u(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,g.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,g.toPlainObject)(r)}catch(r){const i=/(:lang\(\s*("[A-Za-z\d\-*]+")\s*\))/;if(r.message==="Identifier is expected"&&i.test(s)){const[,n,a]=i.exec(s),o=a.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,""),l=n.replace(a,o);t=d(s.replace(n,l))}else if(r.message==='"]" is expected'&&!s.endsWith("]"))t=d(`${s}]`);else if(r.message==='")" is expected'&&!s.endsWith(")"))t=d(`${s})`);else throw new DOMException(r.message,e.SYNTAX_ERR)}return t},_=(s={})=>{const t=new Set;let r;return(0,g.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)||n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,g.findAll)(s,(n,a,o)=>{if(o){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const l=o.filter(f=>{const{name:c,type:p}=f;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(c)});for(const{children:f}of l)for(const{children:c}of f)for(const{children:p}of c)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const l=o.filter(f=>{const{name:c,type:p}=f;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(c)});for(const{children:f}of l)for(const{children:c}of f)t.has(c)&&t.delete(c)}}}),[...t]};0&&(module.exports={generateCSS,parseSelector,preprocess,unescapeSelector,walkAST});
1
+ var E=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var y=(s,e)=>{for(var r in e)E(s,r,{get:e[r],enumerable:!0})},w=(s,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of O(e))!x.call(s,n)&&n!==r&&E(s,n,{get:()=>e[n],enumerable:!(i=m(e,n))||i.enumerable});return s};var $=s=>w(E({},"__esModule",{value:!0}),s);var P={};y(P,{generateCSS:()=>S.generate,parseSelector:()=>d,preprocess:()=>u,unescapeSelector:()=>D,walkAST:()=>_});module.exports=$(P);var g=require("css-tree"),t=require("./constant.js"),S=require("css-tree");const D=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const e=s.split("\\"),r=e.length;for(let i=1;i<r;i++){let n=e[i];if(n===""&&i===r-1)n=t.U_FFFD;else{const a=/^([\da-f]{1,6}\s?)/i.exec(n);if(a){const[,o]=a;let l;try{const c=parseInt("D800",t.HEX),p=parseInt("DFFF",t.HEX),h=parseInt(o,t.HEX);h===0||h>=c&&h<=p?l=t.U_FFFD:l=String.fromCodePoint(h)}catch{l=t.U_FFFD}let f="";n.length>o.length&&(f=n.substring(o.length)),n=`${l}${f}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}e[i]=n}s=e.join("")}return s},u=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[e]=s;if(typeof e=="string"){let r=0;for(;r>=0&&(r=e.indexOf("#",r),!(r<0));){const i=e.substring(0,r+1);let n=e.substring(r+1);const a=n.codePointAt(0);if(a===t.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR)}else if(a>t.MAX_BIT_16){const o=`\\${a.toString(t.HEX)} `;n.length===t.DUO?n=o:n=`${o}${n.substring(t.DUO)}`}e=`${i}${n}`,r++}e=e.replace(/\f|\r\n?/g,`
2
+ `).replace(/[\0\uD800-\uDFFF]|\\$/g,t.U_FFFD)}else if(e==null)e=Object.prototype.toString.call(e).slice(t.TYPE_FROM,t.TYPE_TO).toLowerCase();else if(Array.isArray(e))e=e.join(",");else if(Object.prototype.hasOwnProperty.call(e,"toString"))e=e.toString();else throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR);return e},d=s=>{if(s=u(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,t.SYNTAX_ERR);let e;try{const r=(0,g.parse)(s,{context:"selectorList",parseCustomProperty:!0});e=(0,g.toPlainObject)(r)}catch(r){const i=/(:lang\(\s*("[A-Za-z\d\-*]+")\s*\))/;if(r.message==="Identifier is expected"&&i.test(s)){const[,n,a]=i.exec(s),o=a.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,""),l=n.replace(a,o);e=d(s.replace(n,l))}else if(r.message==='"]" is expected'&&!s.endsWith("]"))e=d(`${s}]`);else if(r.message==='")" is expected'&&!s.endsWith(")"))e=d(`${s})`);else throw new DOMException(r.message,t.SYNTAX_ERR)}return e},_=(s={})=>{const e=new Set;let r;return(0,g.walk)(s,{enter:n=>{n.type===t.SELECTOR?e.add(n.children):(n.type===t.SELECTOR_PSEUDO_CLASS&&t.REG_LOGICAL_PSEUDO.test(n.name)||n.type===t.SELECTOR_PSEUDO_ELEMENT&&t.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,g.findAll)(s,(n,a,o)=>{if(o){if(n.type===t.SELECTOR_PSEUDO_CLASS&&t.REG_LOGICAL_PSEUDO.test(n.name)){const l=o.filter(f=>{const{name:c,type:p}=f;return p===t.SELECTOR_PSEUDO_CLASS&&t.REG_LOGICAL_PSEUDO.test(c)});for(const{children:f}of l)for(const{children:c}of f)for(const{children:p}of c)e.has(p)&&e.delete(p)}else if(n.type===t.SELECTOR_PSEUDO_ELEMENT&&t.REG_SHADOW_PSEUDO.test(n.name)){const l=o.filter(f=>{const{name:c,type:p}=f;return p===t.SELECTOR_PSEUDO_ELEMENT&&t.REG_SHADOW_PSEUDO.test(c)});for(const{children:f}of l)for(const{children:c}of f)e.has(c)&&e.delete(c)}}}),[...e]};0&&(module.exports={generateCSS,parseSelector,preprocess,unescapeSelector,walkAST});
3
3
  //# sourceMappingURL=parser.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/parser.js"],
4
- "sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\n\n/* constants */\nimport {\n DUO, HEX, MAX_BIT_16, BIT_HYPHEN, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO,\n SELECTOR, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SYNTAX_ERR,\n TYPE_FROM, TYPE_TO, U_FFFD\n} from './constant.js';\n\n/**\n * unescape selector\n * @param {string} selector - CSS selector\n * @returns {?string} - unescaped selector\n */\nexport const unescapeSelector = (selector = '') => {\n if (typeof selector === 'string' && selector.indexOf('\\\\', 0) >= 0) {\n const arr = selector.split('\\\\');\n const l = arr.length;\n for (let i = 1; i < l; i++) {\n let item = arr[i];\n if (item === '' && i === l - 1) {\n item = U_FFFD;\n } else {\n const hexExists = /^([\\da-f]{1,6}\\s?)/i.exec(item);\n if (hexExists) {\n const [, hex] = hexExists;\n let str;\n try {\n const low = parseInt('D800', HEX);\n const high = parseInt('DFFF', HEX);\n const deci = parseInt(hex, HEX);\n if (deci === 0 || (deci >= low && deci <= high)) {\n str = U_FFFD;\n } else {\n str = String.fromCodePoint(deci);\n }\n } catch (e) {\n str = U_FFFD;\n }\n let postStr = '';\n if (item.length > hex.length) {\n postStr = item.substring(hex.length);\n }\n item = `${str}${postStr}`;\n // whitespace\n } else if (/^[\\n\\r\\f]/.test(item)) {\n item = '\\\\' + item;\n }\n }\n arr[i] = item;\n }\n selector = arr.join('');\n }\n return selector;\n};\n\n/**\n * preprocess\n * @see https://drafts.csswg.org/css-syntax-3/#input-preprocessing\n * @param {...*} args - arguments\n * @returns {string} - filtered selector string\n */\nexport const preprocess = (...args) => {\n if (!args.length) {\n throw new TypeError('1 argument required, but only 0 present.');\n }\n let [selector] = args;\n if (typeof selector === 'string') {\n let index = 0;\n while (index >= 0) {\n index = selector.indexOf('#', index);\n if (index < 0) {\n break;\n }\n const preHash = selector.substring(0, index + 1);\n let postHash = selector.substring(index + 1);\n const codePoint = postHash.codePointAt(0);\n // @see https://drafts.csswg.org/selectors/#id-selectors\n // @see https://drafts.csswg.org/css-syntax-3/#ident-token-diagram\n if (codePoint === BIT_HYPHEN) {\n if (/^\\d$/.test(postHash.substring(1, 2))) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n // escape char above 0xFFFF\n } else if (codePoint > MAX_BIT_16) {\n const str = `\\\\${codePoint.toString(HEX)} `;\n if (postHash.length === DUO) {\n postHash = str;\n } else {\n postHash = `${str}${postHash.substring(DUO)}`;\n }\n }\n selector = `${preHash}${postHash}`;\n index++;\n }\n selector = selector.replace(/\\f|\\r\\n?/g, '\\n')\n .replace(/[\\0\\uD800-\\uDFFF]|\\\\$/g, U_FFFD);\n } else if (selector === undefined || selector === null) {\n selector = Object.prototype.toString.call(selector)\n .slice(TYPE_FROM, TYPE_TO).toLowerCase();\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return selector;\n};\n\n/**\n * create AST from CSS selector\n * @param {string} selector - CSS selector\n * @returns {object} - AST\n */\nexport const parseSelector = selector => {\n selector = preprocess(selector);\n // invalid selectors\n if (/^$|^\\s*>|,\\s*$/.test(selector)) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n let res;\n try {\n const ast = parse(selector, {\n context: 'selectorList',\n parseCustomProperty: true\n });\n res = toPlainObject(ast);\n } catch (e) {\n // workaround for https://github.com/csstree/csstree/issues/265\n // NOTE: still throws on `:lang(\"\")`;\n const regLang = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]+\")\\s*\\))/;\n if (e.message === 'Identifier is expected' && regLang.test(selector)) {\n const [, lang, range] = regLang.exec(selector);\n const escapedRange =\n range.replaceAll('*', '\\\\*').replace(/^\"/, '').replace(/\"$/, '');\n const escapedLang = lang.replace(range, escapedRange);\n res = parseSelector(selector.replace(lang, escapedLang));\n } else if (e.message === '\"]\" is expected' && !selector.endsWith(']')) {\n res = parseSelector(`${selector}]`);\n } else if (e.message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(e.message, SYNTAX_ERR);\n }\n }\n return res;\n};\n\n/**\n * walk AST\n * @param {object} ast - AST\n * @returns {Array.<object|undefined>} - collection of AST branches\n */\nexport const walkAST = (ast = {}) => {\n const branches = new Set();\n let hasPseudoFunc;\n const opt = {\n enter: node => {\n if (node.type === SELECTOR) {\n branches.add(node.children);\n } else if ((node.type === SELECTOR_PSEUDO_CLASS &&\n REG_LOGICAL_PSEUDO.test(node.name)) ||\n (node.type === SELECTOR_PSEUDO_ELEMENT &&\n REG_SHADOW_PSEUDO.test(node.name))) {\n hasPseudoFunc = true;\n }\n }\n };\n walk(ast, opt);\n if (hasPseudoFunc) {\n findAll(ast, (node, item, list) => {\n if (list) {\n if (node.type === SELECTOR_PSEUDO_CLASS &&\n REG_LOGICAL_PSEUDO.test(node.name)) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n const res =\n type === SELECTOR_PSEUDO_CLASS && REG_LOGICAL_PSEUDO.test(name);\n return res;\n });\n for (const { children } of itemList) {\n // SelectorList\n for (const { children: grandChildren } of children) {\n // Selector\n for (const { children: greatGrandChildren } of grandChildren) {\n if (branches.has(greatGrandChildren)) {\n branches.delete(greatGrandChildren);\n }\n }\n }\n }\n } else if (node.type === SELECTOR_PSEUDO_ELEMENT &&\n REG_SHADOW_PSEUDO.test(node.name)) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n const res =\n type === SELECTOR_PSEUDO_ELEMENT && REG_SHADOW_PSEUDO.test(name);\n return res;\n });\n for (const { children } of itemList) {\n // Selector\n for (const { children: grandChildren } of children) {\n if (branches.has(grandChildren)) {\n branches.delete(grandChildren);\n }\n }\n }\n }\n }\n });\n }\n return [...branches];\n};\n\n/* export */\nexport { generate as generateCSS } from 'css-tree';\n"],
5
- "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8CAAAE,EAAA,eAAAC,EAAA,qBAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAN,GAKA,IAAAO,EAAoD,oBAGpDC,EAIO,yBA6MPD,EAAwC,oBAtMjC,MAAMH,EAAmB,CAACK,EAAW,KAAO,CACjD,GAAI,OAAOA,GAAa,UAAYA,EAAS,QAAQ,KAAM,CAAC,GAAK,EAAG,CAClE,MAAMC,EAAMD,EAAS,MAAM,IAAI,EACzBE,EAAID,EAAI,OACd,QAAS,EAAI,EAAG,EAAIC,EAAG,IAAK,CAC1B,IAAIC,EAAOF,EAAI,CAAC,EAChB,GAAIE,IAAS,IAAM,IAAMD,EAAI,EAC3BC,EAAO,aACF,CACL,MAAMC,EAAY,sBAAsB,KAAKD,CAAI,EACjD,GAAIC,EAAW,CACb,KAAM,CAAC,CAAEC,CAAG,EAAID,EAChB,IAAIE,EACJ,GAAI,CACF,MAAMC,EAAM,SAAS,OAAQ,KAAG,EAC1BC,EAAO,SAAS,OAAQ,KAAG,EAC3BC,EAAO,SAASJ,EAAK,KAAG,EAC1BI,IAAS,GAAMA,GAAQF,GAAOE,GAAQD,EACxCF,EAAM,SAENA,EAAM,OAAO,cAAcG,CAAI,CAEnC,MAAY,CACVH,EAAM,QACR,CACA,IAAII,EAAU,GAC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R,EAAK,CAACS,EAAMvB,EAAMwB,IAAS,CACjC,GAAIA,GACF,GAAID,EAAK,OAAS,yBACd,qBAAmB,KAAKA,EAAK,IAAI,EAAG,CACtC,MAAME,EAAWD,EAAK,OAAOE,GAAK,CAChC,KAAM,CAAE,KAAAC,EAAM,KAAAC,CAAK,EAAIF,EAGvB,OADEE,IAAS,yBAAyB,qBAAmB,KAAKD,CAAI,CAElE,CAAC,EACD,SAAW,CAAE,SAAAE,CAAS,IAAKJ,EAEzB,SAAW,CAAE,SAAUK,CAAc,IAAKD,EAExC,SAAW,CAAE,SAAUE,CAAmB,IAAKD,EACzCT,EAAS,IAAIU,CAAkB,GACjCV,EAAS,OAAOU,CAAkB,CAK5C,SAAWR,EAAK,OAAS,2BACd,oBAAkB,KAAKA,EAAK,IAAI,EAAG,CAC5C,MAAME,EAAWD,EAAK,OAAOE,GAAK,CAChC,KAAM,CAAE,KAAAC,EAAM,KAAAC,CAAK,EAAIF,EAGvB,OADEE,IAAS,2BAA2B,oBAAkB,KAAKD,CAAI,CAEnE,CAAC,EACD,SAAW,CAAE,SAAAE,CAAS,IAAKJ,EAEzB,SAAW,CAAE,SAAUK,CAAc,IAAKD,EACpCR,EAAS,IAAIS,CAAa,GAC5BT,EAAS,OAAOS,CAAa,CAIrC,EAEJ,CAAC,EAEI,CAAC,GAAGT,CAAQ,CACrB",
4
+ "sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\n\n/* constants */\nimport {\n DUO, HEX, MAX_BIT_16, BIT_HYPHEN, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO,\n SELECTOR, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SYNTAX_ERR,\n TYPE_FROM, TYPE_TO, U_FFFD\n} from './constant.js';\n\n/**\n * unescape selector\n * @param {string} selector - CSS selector\n * @returns {?string} - unescaped selector\n */\nexport const unescapeSelector = (selector = '') => {\n if (typeof selector === 'string' && selector.indexOf('\\\\', 0) >= 0) {\n const arr = selector.split('\\\\');\n const l = arr.length;\n for (let i = 1; i < l; i++) {\n let item = arr[i];\n if (item === '' && i === l - 1) {\n item = U_FFFD;\n } else {\n const hexExists = /^([\\da-f]{1,6}\\s?)/i.exec(item);\n if (hexExists) {\n const [, hex] = hexExists;\n let str;\n try {\n const low = parseInt('D800', HEX);\n const high = parseInt('DFFF', HEX);\n const deci = parseInt(hex, HEX);\n if (deci === 0 || (deci >= low && deci <= high)) {\n str = U_FFFD;\n } else {\n str = String.fromCodePoint(deci);\n }\n } catch (e) {\n str = U_FFFD;\n }\n let postStr = '';\n if (item.length > hex.length) {\n postStr = item.substring(hex.length);\n }\n item = `${str}${postStr}`;\n // whitespace\n } else if (/^[\\n\\r\\f]/.test(item)) {\n item = '\\\\' + item;\n }\n }\n arr[i] = item;\n }\n selector = arr.join('');\n }\n return selector;\n};\n\n/**\n * preprocess\n * @see https://drafts.csswg.org/css-syntax-3/#input-preprocessing\n * @param {...*} args - arguments\n * @returns {string} - filtered selector string\n */\nexport const preprocess = (...args) => {\n if (!args.length) {\n throw new TypeError('1 argument required, but only 0 present.');\n }\n let [selector] = args;\n if (typeof selector === 'string') {\n let index = 0;\n while (index >= 0) {\n index = selector.indexOf('#', index);\n if (index < 0) {\n break;\n }\n const preHash = selector.substring(0, index + 1);\n let postHash = selector.substring(index + 1);\n const codePoint = postHash.codePointAt(0);\n // @see https://drafts.csswg.org/selectors/#id-selectors\n // @see https://drafts.csswg.org/css-syntax-3/#ident-token-diagram\n if (codePoint === BIT_HYPHEN) {\n if (/^\\d$/.test(postHash.substring(1, 2))) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n // escape char above 0xFFFF\n } else if (codePoint > MAX_BIT_16) {\n const str = `\\\\${codePoint.toString(HEX)} `;\n if (postHash.length === DUO) {\n postHash = str;\n } else {\n postHash = `${str}${postHash.substring(DUO)}`;\n }\n }\n selector = `${preHash}${postHash}`;\n index++;\n }\n selector = selector.replace(/\\f|\\r\\n?/g, '\\n')\n .replace(/[\\0\\uD800-\\uDFFF]|\\\\$/g, U_FFFD);\n } else if (selector === undefined || selector === null) {\n selector = Object.prototype.toString.call(selector)\n .slice(TYPE_FROM, TYPE_TO).toLowerCase();\n } else if (Array.isArray(selector)) {\n selector = selector.join(',');\n } else if (Object.prototype.hasOwnProperty.call(selector, 'toString')) {\n selector = selector.toString();\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return selector;\n};\n\n/**\n * create AST from CSS selector\n * @param {string} selector - CSS selector\n * @returns {object} - AST\n */\nexport const parseSelector = selector => {\n selector = preprocess(selector);\n // invalid selectors\n if (/^$|^\\s*>|,\\s*$/.test(selector)) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n let res;\n try {\n const ast = parse(selector, {\n context: 'selectorList',\n parseCustomProperty: true\n });\n res = toPlainObject(ast);\n } catch (e) {\n // workaround for https://github.com/csstree/csstree/issues/265\n // NOTE: still throws on `:lang(\"\")`;\n const regLang = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]+\")\\s*\\))/;\n if (e.message === 'Identifier is expected' && regLang.test(selector)) {\n const [, lang, range] = regLang.exec(selector);\n const escapedRange =\n range.replaceAll('*', '\\\\*').replace(/^\"/, '').replace(/\"$/, '');\n const escapedLang = lang.replace(range, escapedRange);\n res = parseSelector(selector.replace(lang, escapedLang));\n } else if (e.message === '\"]\" is expected' && !selector.endsWith(']')) {\n res = parseSelector(`${selector}]`);\n } else if (e.message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(e.message, SYNTAX_ERR);\n }\n }\n return res;\n};\n\n/**\n * walk AST\n * @param {object} ast - AST\n * @returns {Array.<object|undefined>} - collection of AST branches\n */\nexport const walkAST = (ast = {}) => {\n const branches = new Set();\n let hasPseudoFunc;\n const opt = {\n enter: node => {\n if (node.type === SELECTOR) {\n branches.add(node.children);\n } else if ((node.type === SELECTOR_PSEUDO_CLASS &&\n REG_LOGICAL_PSEUDO.test(node.name)) ||\n (node.type === SELECTOR_PSEUDO_ELEMENT &&\n REG_SHADOW_PSEUDO.test(node.name))) {\n hasPseudoFunc = true;\n }\n }\n };\n walk(ast, opt);\n if (hasPseudoFunc) {\n findAll(ast, (node, item, list) => {\n if (list) {\n if (node.type === SELECTOR_PSEUDO_CLASS &&\n REG_LOGICAL_PSEUDO.test(node.name)) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n const res =\n type === SELECTOR_PSEUDO_CLASS && REG_LOGICAL_PSEUDO.test(name);\n return res;\n });\n for (const { children } of itemList) {\n // SelectorList\n for (const { children: grandChildren } of children) {\n // Selector\n for (const { children: greatGrandChildren } of grandChildren) {\n if (branches.has(greatGrandChildren)) {\n branches.delete(greatGrandChildren);\n }\n }\n }\n }\n } else if (node.type === SELECTOR_PSEUDO_ELEMENT &&\n REG_SHADOW_PSEUDO.test(node.name)) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n const res =\n type === SELECTOR_PSEUDO_ELEMENT && REG_SHADOW_PSEUDO.test(name);\n return res;\n });\n for (const { children } of itemList) {\n // Selector\n for (const { children: grandChildren } of children) {\n if (branches.has(grandChildren)) {\n branches.delete(grandChildren);\n }\n }\n }\n }\n }\n });\n }\n return [...branches];\n};\n\n/* export */\nexport { generate as generateCSS } from 'css-tree';\n"],
5
+ "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8CAAAE,EAAA,eAAAC,EAAA,qBAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAN,GAKA,IAAAO,EAAoD,oBAGpDC,EAIO,yBAiNPD,EAAwC,oBA1MjC,MAAMH,EAAmB,CAACK,EAAW,KAAO,CACjD,GAAI,OAAOA,GAAa,UAAYA,EAAS,QAAQ,KAAM,CAAC,GAAK,EAAG,CAClE,MAAMC,EAAMD,EAAS,MAAM,IAAI,EACzBE,EAAID,EAAI,OACd,QAAS,EA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2B,oBAAkB,KAAKD,CAAI,CAEnE,CAAC,EACD,SAAW,CAAE,SAAAE,CAAS,IAAKJ,EAEzB,SAAW,CAAE,SAAUK,CAAc,IAAKD,EACpCR,EAAS,IAAIS,CAAa,GAC5BT,EAAS,OAAOS,CAAa,CAIrC,EAEJ,CAAC,EAEI,CAAC,GAAGT,CAAQ,CACrB",
6
6
  "names": ["parser_exports", "__export", "parseSelector", "preprocess", "unescapeSelector", "walkAST", "__toCommonJS", "import_css_tree", "import_constant", "selector", "arr", "l", "item", "hexExists", "hex", "str", "low", "high", "deci", "postStr", "args", "index", "preHash", "postHash", "codePoint", "res", "ast", "e", "regLang", "lang", "range", "escapedRange", "escapedLang", "branches", "hasPseudoFunc", "node", "list", "itemList", "i", "name", "type", "children", "grandChildren", "greatGrandChildren"]
7
7
  }
package/package.json CHANGED
@@ -31,7 +31,7 @@
31
31
  "@types/css-tree": "^2.3.4",
32
32
  "benchmark": "^2.1.4",
33
33
  "c8": "^8.0.1",
34
- "chai": "^4.3.10",
34
+ "chai": "^5.0.0",
35
35
  "commander": "^11.1.0",
36
36
  "esbuild": "^0.19.10",
37
37
  "eslint": "^8.56.0",
@@ -58,5 +58,5 @@
58
58
  "tsc": "npx tsc",
59
59
  "update-wpt": "git submodule update --init --recursive --remote"
60
60
  },
61
- "version": "1.2.0"
61
+ "version": "1.2.2"
62
62
  }
package/src/js/matcher.js CHANGED
@@ -2504,7 +2504,7 @@ export class Matcher {
2504
2504
  const collectedNodes = this.#nodes[i];
2505
2505
  const lastIndex = branchLen - 1;
2506
2506
  if (lastIndex === 0) {
2507
- const { leaves: filterLeaves } = branch[0];
2507
+ const { leaves: [, ...filterLeaves] } = branch[0];
2508
2508
  if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&
2509
2509
  this.#node.nodeType === ELEMENT_NODE) {
2510
2510
  for (const node of collectedNodes) {
@@ -2516,6 +2516,14 @@ export class Matcher {
2516
2516
  }
2517
2517
  }
2518
2518
  }
2519
+ } else if (!filterLeaves.length) {
2520
+ if (targetType === TARGET_ALL) {
2521
+ const n = [...nodes];
2522
+ nodes = new Set([...n, ...collectedNodes]);
2523
+ } else {
2524
+ const [node] = [...collectedNodes];
2525
+ nodes.add(node);
2526
+ }
2519
2527
  } else {
2520
2528
  for (const node of collectedNodes) {
2521
2529
  const bool = filtered || this._matchLeaves(filterLeaves, node);
@@ -2528,7 +2536,7 @@ export class Matcher {
2528
2536
  }
2529
2537
  }
2530
2538
  } else if (find === FIND_NEXT) {
2531
- let { combo, leaves: filterLeaves } = branch[0];
2539
+ let { combo, leaves: [, ...filterLeaves] } = branch[0];
2532
2540
  for (const node of collectedNodes) {
2533
2541
  const bool = filtered || this._matchLeaves(filterLeaves, node);
2534
2542
  let matched;
@@ -2576,7 +2584,7 @@ export class Matcher {
2576
2584
  }
2577
2585
  }
2578
2586
  } else {
2579
- const { leaves: filterLeaves } = branch[lastIndex];
2587
+ const { leaves: [, ...filterLeaves] } = branch[lastIndex];
2580
2588
  for (const node of collectedNodes) {
2581
2589
  const bool = filtered || this._matchLeaves(filterLeaves, node);
2582
2590
  let matched;
package/src/js/parser.js CHANGED
@@ -103,6 +103,10 @@ export const preprocess = (...args) => {
103
103
  } else if (selector === undefined || selector === null) {
104
104
  selector = Object.prototype.toString.call(selector)
105
105
  .slice(TYPE_FROM, TYPE_TO).toLowerCase();
106
+ } else if (Array.isArray(selector)) {
107
+ selector = selector.join(',');
108
+ } else if (Object.prototype.hasOwnProperty.call(selector, 'toString')) {
109
+ selector = selector.toString();
106
110
  } else {
107
111
  throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);
108
112
  }