From 2179dcd0a92303203748472dec74ac6794302e9a Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Tue, 26 Mar 2024 21:56:43 +0900 Subject: [PATCH] v4.2.0 --- dist/cjs/js/finder.js | 2 +- dist/cjs/js/finder.js.map | 6 +++--- dist/cjs/js/parser.js.map | 2 +- package.json | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/cjs/js/finder.js b/dist/cjs/js/finder.js index 9cb6fc9a..22042163 100644 --- a/dist/cjs/js/finder.js +++ b/dist/cjs/js/finder.js @@ -1,2 +1,2 @@ -var B=Object.create;var P=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(E,a)=>{for(var e in a)P(E,e,{get:a[e],enumerable:!0})},U=(E,a,e,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of G(a))!V.call(E,l)&&l!==e&&P(E,l,{get:()=>a[l],enumerable:!(r=j(a,l))||r.enumerable});return E};var z=(E,a,e)=>(e=E!=null?B(q(E)):{},U(a||!E||!E.__esModule?P(e,"default",{value:E,enumerable:!0}):e,E)),Y=E=>U(P({},"__esModule",{value:!0}),E);var K={};X(K,{Finder:()=>Q});module.exports=Y(K);var I=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),S=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",A="first",R="lineal",D="self";class Q{#a;#l;#t;#o;#f;#e;#h;#w;#c;#n;#m;#s;#d;#b;#r;#u;#i;#p;constructor(a){this.#p=a,this.#f=a.document,this.#l=new WeakMap,this.#m=new WeakMap,this.#c=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#c.configure({LOGERRORS:!1})}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#p.DOMException)if(a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#p.DOMException(a.message,a.name);else throw a}_setup(a,e,r={}){const{noexcept:l,warn:s}=r;return this.#w=!!l,this.#i=!!s,this.#e=e,[this.#t,this.#s,this.#r]=(0,C.resolveContent)(e),this.#d=(0,C.isInShadowTree)(e),[this.#a,this.#h]=this._correspond(a),this.#u=new WeakMap,e}_correspond(a){const e=[];this.#o=!1;let r;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${a}`)){const s=l.get(`${a}`);this.#o=s.descendant,r=s.ast}}if(r){const l=r.length;for(let s=0;s]$/.test(w)&&(o=!0),f.push({combo:t,leaves:(0,S.sortAST)(i)}),i.clear()}else if(t){let{name:c}=t;c&&typeof c=="string"&&(c=(0,S.unescapeSelector)(c),typeof c=="string"&&c!==t.name&&(t.name=c),/[|:]/.test(c)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{f.push({combo:null,leaves:(0,S.sortAST)(i)}),i.clear();break}}}r.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#t){let d;this.#l.has(this.#t)?d=this.#l.get(this.#t):d=new Map,d.set(`${a}`,{ast:r,descendant:o}),this.#l.set(this.#t,d)}this.#o=o}return[r,e]}_createTreeWalker(a){let e;return this.#u.has(a)?e=this.#u.get(a):(e=this.#f.createTreeWalker(a,b.WALKER_FILTER),this.#u.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#n=this._createTreeWalker(this.#e),this.#b=!1,this.#n}_traverse(a,e=this.#r){let r=e.currentNode,l;if(r===a)l=r;else if(r.contains(a))for(r=e.nextNode();r;){if(r===a){l=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===a);)r=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;r;){if(r===a){l=r;break}r=e.nextNode()}else l=r}return l??null}_collectNthChild(a,e,r){const{a:l,b:s,reverse:o,selector:n}=a,{parentNode:d}=e,f=new Set;let t;if(n&&(this.#l.has(n)?t=this.#l.get(n):(t=(0,S.walkAST)(n),this.#l.set(n,t))),d){const i=this.#r;let c=this._traverse(d,i);c=i.firstChild();let w=0;for(;c;)w++,c=i.nextSibling();c=this._traverse(d,i);const _=new Set;if(t)for(c=i.firstChild();c;){let m;for(const N of t)if(m=this._matchLeaves(N,c,r),!m)break;m&&_.add(c),c=i.nextSibling()}if(l===0){if(s>0&&s<=w){if(_.size){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(_.has(c)){if(m===s-1){f.add(c);break}m++}o?c=i.previousSibling():c=i.nextSibling()}}else if(!n){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(m===s-1){f.add(c);break}o?c=i.previousSibling():c=i.nextSibling(),m++}}}}else{let m=s-1;if(l>0)for(;m<0;)m+=l;if(m>=0&&m0?0:s-1;for(;c&&(c&&m>=0&&m0?k++:k--):N===m&&(n||f.add(c),m+=l),o?c=i.previousSibling():c=i.nextSibling(),N++}}if(o&&f.size>1){const m=[...f];return new Set(m.reverse())}}else if(e===this.#s&&l+s===1)if(t){let i;for(const c of t)if(i=this._matchLeaves(c,e,r),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:r,b:l,reverse:s}=a,{localName:o,parentNode:n,prefix:d}=e,f=new Set;if(n){const t=this.#r;let i=this._traverse(n,t);i=t.firstChild();let c=0;for(;i;)c++,i=t.nextSibling();if(r===0){if(l>0&&l<=c){i=this._traverse(n,t),s?i=t.lastChild():i=t.firstChild();let w=0;for(;i;){const{localName:_,prefix:m}=i;if(_===o&&m===d){if(w===l-1){f.add(i);break}w++}s?i=t.previousSibling():i=t.nextSibling()}}}else{let w=l-1;if(r>0)for(;w<0;)w+=r;if(w>=0&&w0?0:l-1;for(;i;){const{localName:m,prefix:N}=i;if(m===o&&N===d){if(_===w&&(f.add(i),w+=r),w<0||w>=c)break;r>0?_++:_--}s?i=t.previousSibling():i=t.nextSibling()}}}if(s&&f.size>1){const w=[...f];return new Set(w.reverse())}}else e===this.#s&&r+l===1&&f.add(e);return f}_matchAnPlusB(a,e,r,l){const{nth:{a:s,b:o,name:n},selector:d}=a,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?f.set("b",o*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,r={}){let l;if(Array.isArray(a)&&a.length){const[s]=a,{type:o}=s;let n;o===b.COMBINATOR?n=a.shift():n={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[i]=a,{type:c}=i;if(c===b.COMBINATOR)break;d.push(a.shift())}const f={combo:n,leaves:d};r.dir=T;const t=this._matchCombinator(f,e,r);if(t.size)if(a.length){for(const i of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),i,r),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,r={}){const{astName:l="",branches:s=[],selector:o="",twigBranches:n=[]}=a;let d;if(l==="has")if(o.includes(":has("))d=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);r.forgive=f;const t=n.length;let i;for(let c=0;c0){let N=new Set([e]);for(let k=_-1;k>=0;k--){const g=w[k],h=[];r.dir=O;for(const p of N){const u=this._matchCombinator(g,p,r);u.size&&h.push(...u)}if(h.length)k===0?i=!0:N=new Set(h);else{i=!1;break}}}if(i)break}l==="not"?i||(d=e):i&&(d=e)}return d??null}_matchPseudoClassSelector(a,e,r={}){const{children:l,name:s}=a,{localName:o,parentNode:n}=e,{forgive:d,warn:f=this.#i}=r,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let i;if(this.#l.has(a))i=this.#l.get(a);else{const w=(0,S.walkAST)(a),_=[],m=[];for(const[...N]of w){for(const p of N){const u=(0,S.generateCSS)(p);_.push(u)}const k=[],g=new Set;let h=N.shift();for(;h;)if(h.type===b.COMBINATOR?(k.push({combo:h,leaves:[...g]}),g.clear()):h&&g.add(h),N.length)h=N.shift();else{k.push({combo:null,leaves:[...g]}),g.clear();break}m.push(k)}i={astName:s,branches:w,twigBranches:m,selector:_.join(",")},this.#l.set(a,i)}const c=this._matchLogicalPseudoFunc(i,e,r);c&&t.add(c)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[i]=l;return this._matchAnPlusB(i,e,s,r)}else switch(s){case"dir":case"lang":{const i=$.matcher.matchSelector(a,e);i&&t.add(i);break}case"current":case"nth-col":case"nth-last-col":{if(f){const i=`Unsupported pseudo-class :${s}()`;throw new DOMException(i,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!d){const i=`Unknown pseudo-class :${s}()`;throw new DOMException(i,b.SYNTAX_ERR)}}else{const i=/^a(?:rea)?$/,c=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,w=/^(?:(?:inpu|selec)t|button|form|textarea)$/,_=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,k=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,g=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(s){case"any-link":case"link":{i.test(o)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(o)&&e.hasAttribute("href")){const{href:h,origin:p,pathname:u}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),h);y.origin===p&&y.pathname===u&&t.add(e)}break}case"visited":break;case"target":{const{hash:h}=new URL(this.#t.URL);e.id&&h===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:h}=new URL(this.#t.URL);if(h){const p=h.replace(/^#/,"");let u=this.#t.getElementById(p);for(;u;){if(u===e){t.add(e);break}u=u.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#d&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":{if(e===this.#t.activeElement){let h=e,p=!0;for(;h;){if(h.disabled||h.hasAttribute("disabled")||h.hidden||h.hasAttribute("hidden")){p=!1;break}else if(h.hasAttribute("style")){const{display:u,visibility:y}=h.style;if(p=!(u==="none"||y==="hidden"),!p)break}if(h.parentNode&&h.parentNode.nodeType===b.ELEMENT_NODE)h=h.parentNode;else break}p&&t.add(e)}break}case"focus-within":{let h=this.#t.activeElement,p;for(;h;){if(h===e){p=!0;break}h=h.parentNode}if(p){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else if(u.hasAttribute("style")){const{display:v,visibility:L}=u.style;if(y=!(v==="none"||L==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"open":{_.test(o)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(o)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(c.test(o)||(0,I.default)(o))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=n;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&n.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(c.test(o)||(0,I.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let h;o==="textarea"?h=e:o==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(h=e):h=e),h&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&o==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))t.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const h=e.name;let p=e.parentNode;for(;p&&p.localName!=="form";)p=p.parentNode;p||(p=this.#t.documentElement);const u=p.getElementsByTagName("input"),y=u.length;let v;for(let L=0;L0,{type:n}=l,d=(0,S.unescapeSelector)(l.name);typeof d=="string"&&d!==l.name&&(l.name=d);let f=new Set,t=!1;if(this.#d)t=!0;else switch(n){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,r);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const i=this.#s.getElementById(d);i&&i!==e&&e.contains(i)&&(o?this._matchLeaves(s,i,r)&&f.add(i):f.add(i))}break}case b.SELECTOR_CLASS:{const i=e.getElementsByClassName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const i=e.getElementsByTagName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,r={}){const{combo:l,leaves:s}=a,{name:o}=l,{parentNode:n}=e,{dir:d}=r,f=new Set;if(d===T)switch(o){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(e,t);for(i=t.nextSibling();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let i=this._traverse(e,t);for(i=t.firstChild();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling();break}case" ":default:{const{nodes:t,pending:i}=this._findDescendantNodes(s,e);if(t.size)return t;if(i){const c=this._createTreeWalker(e);let w=this._traverse(e,c);for(w=c.nextNode();w&&e.contains(w);)this._matchLeaves(s,w,r)&&f.add(w),w=c.nextNode()}}}else switch(o){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(n,t);for(i=t.firstChild();i&&i!==e;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{n&&this._matchLeaves(s,n,r)&&f.add(n);break}case" ":default:{const t=[];let i=n;for(;i;)this._matchLeaves(s,i,r)&&t.push(i),i=i.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:r}=e;let l=this._traverse(r,this.#n),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#n.nextNode():l===r&&l!==this.#s&&(l=this.#n.nextNode());l;){if(this._matchLeaves(a,l,{warn:this.#i})){s=l;break}l=this.#n.nextNode()}return s??null}_matchSelf(a){const e=[],r=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return r&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:r}=e,l=[];let s=this._matchLeaves(a,this.#e,{warn:this.#i}),o=!1;if(s&&(l.push(this.#e),o=!0),!s||r){let n=this.#e.parentNode;for(;n&&(s=this._matchLeaves(a,n,{warn:this.#i}),s&&(l.push(n),o=!0),n.parentNode);)n=n.parentNode}return[l,o]}_findFirst(a){const e=[],r=this._findNode(a,{node:this.#e});let l=!1;return r&&(e.push(r),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:r,compound:l,filterLeaves:s,targetType:o}=e;let n=[],d=!1,f=!1;const t=a.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let i=0;i0,{name:d,type:f}=s;let t=[],i=!1,c=!1,w=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(e===A&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(n?this._matchLeaves(o,_,{warn:this.#i})&&(t.push(_),c=!0):(t.push(_),c=!0))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(d)){if(this.#d&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(s,this.#e);_&&(t.push(_),c=!0)}}else e===D?[t,c]=this._matchSelf(l):e===R?[t,c]=this._findLineal(l,{complex:r}):e===A?[t,c]=this._findFirst(l):w=!0}return{collected:i,compound:n,filtered:c,nodes:t,pending:w}}_collectNodes(a){const e=this.#a.values();if(a===M||a===A){const r=new Set;let l=0;for(const{branch:s}of e){const o=s.length,n=o>1,d=s[0];let f,t;if(n){const{combo:N,leaves:[{name:k,type:g}]}=d,h=s[o-1],{leaves:[{name:p,type:u}]}=h;if(u===b.SELECTOR_PSEUDO_ELEMENT||u===b.SELECTOR_ID)f=O,t=h;else if(g===b.SELECTOR_PSEUDO_ELEMENT||g===b.SELECTOR_ID)f=T,t=d;else if(a===M)if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else if(p==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(o===2){const{name:y}=N;/^[+~]$/.test(y)?(f=O,t=h):(f=T,t=d)}else f=T,t=d;else if(p==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else{let y;for(const{combo:v,leaves:[L]}of s){const{name:x,type:W}=L;if(W===b.SELECTOR_PSEUDO_CLASS&&x==="dir"){y=!1;break}if(!y&&v){const{name:H}=v;/^[+~]$/.test(H)&&(y=!0)}}y?(f=T,t=d):(f=O,t=h)}}else f=O,t=d;const{collected:i,compound:c,filtered:w,nodes:_,pending:m}=this._findEntryNodes(t,a,n);_.length?(this.#a[l].find=!0,this.#h[l]=_):m&&r.add(new Map([["index",l],["twig",t]])),this.#a[l].collected=i,this.#a[l].dir=f,this.#a[l].filtered=w||!c,l++}if(r.size){let s,o;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,o=this.#n):(s=this.#s,o=this.#r);let n=this._traverse(s,o);for(;n;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?n===this.#e?d=!0:d=this.#e.contains(n):d=!0,d)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const c=f.get("index");this.#a[c].filtered=!0,this.#a[c].find=!0,this.#h[c].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let r=0;for(const{branch:l}of e){const s=l[l.length-1],o=l.length>1,{compound:n,filtered:d,nodes:f}=this._findEntryNodes(s,a,o);f.length&&(this.#a[r].find=!0,this.#h[r]=f),this.#a[r].dir=O,this.#a[r].filtered=d||!n,r++}}return[this.#a,this.#h]}_getCombinedNodes(a,e,r){const l=[];for(const s of e){const o=this._matchCombinator(a,s,{dir:r,warn:this.#i});o.size&&l.push(...o)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,r){const{combo:l,index:s}=r,{combo:o,leaves:n}=a[s],d={combo:l,leaves:n},f=this._getCombinedNodes(d,e,T);let t;if(f.size)if(s===a.length-1){const[i]=(0,C.sortNodes)(f);t=i}else t=this._matchNodeNext(a,f,{combo:o,index:s+1});return t??null}_matchNodePrev(a,e,r){const{index:l}=r,s=a[l],o=new Set([e]),n=this._getCombinedNodes(s,o,O);let d;if(n.size){if(l===0)d=e;else for(const f of n)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_find(a){(a===M||a===A)&&this._prepareQuerySelectorWalker();const[[...e],r]=this._collectNodes(a),l=e.length;let s=new Set;for(let o=0;o=0;k--){const g=n[k];if(N=this._getCombinedNodes(g,N,f),N.size)k===0&&(s.add(m),i>1&&s.size>1&&(this.#b=!0));else break}}else if(a===A&&f===T){const{combo:m}=n[0];let N;for(const k of c)if(N=this._matchNodeNext(n,new Set([k]),{combo:m,index:1}),N){s.add(N);break}if(!N&&!d){const{leaves:k}=n[0],[g]=c;let h=this._findNode(k,{node:g});for(;h;){if(N=this._matchNodeNext(n,new Set([h]),{combo:m,index:1}),N){s.add(N);break}h=this._findNode(k,{node:h})}}}else{let m;for(const N of c)if(m=this._matchNodePrev(n,N,{index:_-1}),m){s.add(N);break}if(!m&&!d&&a===A){const{leaves:N}=n[_],[k]=c;let g=this._findNode(N,{node:k});for(;g;){if(m=this._matchNodePrev(n,g,{index:_-1}),m){s.add(g);break}g=this._findNode(N,{node:g})}}}}}return s}matches(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,S.filterSelector)(a)?l=this.#c.match(a,e):(this._setup(a,e,r),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,S.filterSelector)(a))l=this.#c.closest(a,e);else{this._setup(a,e,r);const s=this._find(R);if(s.size){let o=this.#e;for(;o;){if(s.has(o)){l=o;break}o=o.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(a,e,r){let l;try{if(this._setup(a,e,r),this.#f===this.#t&&!this.#o&&(0,S.filterSelector)(a))l=this.#c.first(a,e);else{const s=this._find(A);s.delete(this.#e),s.size&&([l]=(0,C.sortNodes)(s))}}catch(s){this._onError(s)}return l??null}querySelectorAll(a,e,r){let l;try{if(this._setup(a,e,r),this.#f===this.#t&&!this.#o&&(0,S.filterSelector)(a))l=this.#c.select(a,e);else{const s=this._find(M);s.delete(this.#e),s.size&&(this.#b?l=(0,C.sortNodes)(s):l=[...s])}}catch(s){this._onError(s)}return l??[]}}0&&(module.exports={Finder}); +var B=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(E,a)=>{for(var e in a)I(E,e,{get:a[e],enumerable:!0})},U=(E,a,e,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of G(a))!V.call(E,l)&&l!==e&&I(E,l,{get:()=>a[l],enumerable:!(r=j(a,l))||r.enumerable});return E};var z=(E,a,e)=>(e=E!=null?B(q(E)):{},U(a||!E||!E.__esModule?I(e,"default",{value:E,enumerable:!0}):e,E)),Y=E=>U(I({},"__esModule",{value:!0}),E);var K={};X(K,{Finder:()=>Q});module.exports=Y(K);var P=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),S=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",A="first",R="lineal",D="self";class Q{#a;#l;#t;#f;#h;#e;#d;#w;#o;#n;#p;#s;#b;#u;#r;#m;#i;#c;constructor(a){this.#c=a,this.#h=a.document,this.#l=new WeakMap,this.#p=new WeakMap,this.#o=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#o.configure({LOGERRORS:!1})}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#c.DOMException)if(a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#c.DOMException(a.message,a.name);else throw a}_setup(a,e,r={}){const{noexcept:l,warn:s}=r;return this.#w=!!l,this.#i=!!s,this.#e=e,[this.#t,this.#s,this.#r]=(0,C.resolveContent)(e),this.#b=(0,C.isInShadowTree)(e),[this.#a,this.#d]=this._correspond(a),this.#m=new WeakMap,e}_correspond(a){const e=[];this.#f=!1;let r;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${a}`)){const s=l.get(`${a}`);this.#f=s.descendant,r=s.ast}}if(r){const l=r.length;for(let s=0;s]$/.test(w)&&(o=!0),f.push({combo:t,leaves:(0,S.sortAST)(i)}),i.clear()}else if(t){let{name:c}=t;c&&typeof c=="string"&&(c=(0,S.unescapeSelector)(c),typeof c=="string"&&c!==t.name&&(t.name=c),/[|:]/.test(c)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{f.push({combo:null,leaves:(0,S.sortAST)(i)}),i.clear();break}}}r.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#t){let d;this.#l.has(this.#t)?d=this.#l.get(this.#t):d=new Map,d.set(`${a}`,{ast:r,descendant:o}),this.#l.set(this.#t,d)}this.#f=o}return[r,e]}_createTreeWalker(a){let e;return this.#m.has(a)?e=this.#m.get(a):(e=this.#h.createTreeWalker(a,b.WALKER_FILTER),this.#m.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#n=this._createTreeWalker(this.#e),this.#u=!1,this.#n}_traverse(a,e=this.#r){let r=e.currentNode,l;if(r===a)l=r;else if(r.contains(a))for(r=e.nextNode();r;){if(r===a){l=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===a);)r=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;r;){if(r===a){l=r;break}r=e.nextNode()}else l=r}return l??null}_collectNthChild(a,e,r){const{a:l,b:s,reverse:o,selector:n}=a,{parentNode:d}=e,f=new Set;let t;if(n&&(this.#l.has(n)?t=this.#l.get(n):(t=(0,S.walkAST)(n),this.#l.set(n,t))),d){const i=this.#r;let c=this._traverse(d,i);c=i.firstChild();let w=0;for(;c;)w++,c=i.nextSibling();c=this._traverse(d,i);const _=new Set;if(t)for(c=i.firstChild();c;){let m;for(const N of t)if(m=this._matchLeaves(N,c,r),!m)break;m&&_.add(c),c=i.nextSibling()}if(l===0){if(s>0&&s<=w){if(_.size){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(_.has(c)){if(m===s-1){f.add(c);break}m++}o?c=i.previousSibling():c=i.nextSibling()}}else if(!n){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(m===s-1){f.add(c);break}o?c=i.previousSibling():c=i.nextSibling(),m++}}}}else{let m=s-1;if(l>0)for(;m<0;)m+=l;if(m>=0&&m0?0:s-1;for(;c&&(c&&m>=0&&m0?k++:k--):N===m&&(n||f.add(c),m+=l),o?c=i.previousSibling():c=i.nextSibling(),N++}}if(o&&f.size>1){const m=[...f];return new Set(m.reverse())}}else if(e===this.#s&&l+s===1)if(t){let i;for(const c of t)if(i=this._matchLeaves(c,e,r),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:r,b:l,reverse:s}=a,{localName:o,parentNode:n,prefix:d}=e,f=new Set;if(n){const t=this.#r;let i=this._traverse(n,t);i=t.firstChild();let c=0;for(;i;)c++,i=t.nextSibling();if(r===0){if(l>0&&l<=c){i=this._traverse(n,t),s?i=t.lastChild():i=t.firstChild();let w=0;for(;i;){const{localName:_,prefix:m}=i;if(_===o&&m===d){if(w===l-1){f.add(i);break}w++}s?i=t.previousSibling():i=t.nextSibling()}}}else{let w=l-1;if(r>0)for(;w<0;)w+=r;if(w>=0&&w0?0:l-1;for(;i;){const{localName:m,prefix:N}=i;if(m===o&&N===d){if(_===w&&(f.add(i),w+=r),w<0||w>=c)break;r>0?_++:_--}s?i=t.previousSibling():i=t.nextSibling()}}}if(s&&f.size>1){const w=[...f];return new Set(w.reverse())}}else e===this.#s&&r+l===1&&f.add(e);return f}_matchAnPlusB(a,e,r,l){const{nth:{a:s,b:o,name:n},selector:d}=a,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?f.set("b",o*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,r={}){let l;if(Array.isArray(a)&&a.length){const[s]=a,{type:o}=s;let n;o===b.COMBINATOR?n=a.shift():n={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[i]=a,{type:c}=i;if(c===b.COMBINATOR)break;d.push(a.shift())}const f={combo:n,leaves:d};r.dir=T;const t=this._matchCombinator(f,e,r);if(t.size)if(a.length){for(const i of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),i,r),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,r={}){const{astName:l="",branches:s=[],selector:o="",twigBranches:n=[]}=a;let d;if(l==="has")if(o.includes(":has("))d=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);r.forgive=f;const t=n.length;let i;for(let c=0;c0){let N=new Set([e]);for(let k=_-1;k>=0;k--){const g=w[k],h=[];r.dir=O;for(const p of N){const u=this._matchCombinator(g,p,r);u.size&&h.push(...u)}if(h.length)k===0?i=!0:N=new Set(h);else{i=!1;break}}}if(i)break}l==="not"?i||(d=e):i&&(d=e)}return d??null}_matchPseudoClassSelector(a,e,r={}){const{children:l,name:s}=a,{localName:o,parentNode:n}=e,{forgive:d,warn:f=this.#i}=r,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let i;if(this.#l.has(a))i=this.#l.get(a);else{const w=(0,S.walkAST)(a),_=[],m=[];for(const[...N]of w){for(const p of N){const u=(0,S.generateCSS)(p);_.push(u)}const k=[],g=new Set;let h=N.shift();for(;h;)if(h.type===b.COMBINATOR?(k.push({combo:h,leaves:[...g]}),g.clear()):h&&g.add(h),N.length)h=N.shift();else{k.push({combo:null,leaves:[...g]}),g.clear();break}m.push(k)}i={astName:s,branches:w,twigBranches:m,selector:_.join(",")},this.#l.set(a,i)}const c=this._matchLogicalPseudoFunc(i,e,r);c&&t.add(c)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[i]=l;return this._matchAnPlusB(i,e,s,r)}else switch(s){case"dir":case"lang":{const i=$.matcher.matchSelector(a,e);i&&t.add(i);break}case"current":case"nth-col":case"nth-last-col":{if(f){const i=`Unsupported pseudo-class :${s}()`;throw new DOMException(i,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!d){const i=`Unknown pseudo-class :${s}()`;throw new DOMException(i,b.SYNTAX_ERR)}}else{const i=/^a(?:rea)?$/,c=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,w=/^(?:(?:inpu|selec)t|button|form|textarea)$/,_=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,k=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,g=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(s){case"any-link":case"link":{i.test(o)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(o)&&e.hasAttribute("href")){const{href:h,origin:p,pathname:u}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),h);y.origin===p&&y.pathname===u&&t.add(e)}break}case"visited":break;case"target":{const{hash:h}=new URL(this.#t.URL);e.id&&h===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:h}=new URL(this.#t.URL);if(h){const p=h.replace(/^#/,"");let u=this.#t.getElementById(p);for(;u;){if(u===e){t.add(e);break}u=u.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#b&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":{if(e===this.#t.activeElement){let h=e,p=!0;for(;h;){if(h.disabled||h.hasAttribute("disabled")||h.hidden||h.hasAttribute("hidden")){p=!1;break}else if(h.hasAttribute("style")){const{display:u,visibility:y}=h.style;if(p=!(u==="none"||y==="hidden"),!p)break}if(h.parentNode&&h.parentNode.nodeType===b.ELEMENT_NODE)h=h.parentNode;else break}p&&t.add(e)}break}case"focus-within":{let h=this.#t.activeElement,p;for(;h;){if(h===e){p=!0;break}h=h.parentNode}if(p){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else if(u.hasAttribute("style")){const{display:v,visibility:L}=u.style;if(y=!(v==="none"||L==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"open":{_.test(o)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(o)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(c.test(o)||(0,P.default)(o))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=n;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&n.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(c.test(o)||(0,P.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let h;o==="textarea"?h=e:o==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(h=e):h=e),h&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&o==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))t.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const h=e.name;let p=e.parentNode;for(;p&&p.localName!=="form";)p=p.parentNode;p||(p=this.#t.documentElement);const u=p.getElementsByTagName("input"),y=u.length;let v;for(let L=0;L0,{type:n}=l,d=(0,S.unescapeSelector)(l.name);typeof d=="string"&&d!==l.name&&(l.name=d);let f=new Set,t=!1;if(this.#b)t=!0;else switch(n){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,r);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const i=this.#s.getElementById(d);i&&i!==e&&e.contains(i)&&(o?this._matchLeaves(s,i,r)&&f.add(i):f.add(i))}break}case b.SELECTOR_CLASS:{const i=e.getElementsByClassName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const i=e.getElementsByTagName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,r={}){const{combo:l,leaves:s}=a,{name:o}=l,{parentNode:n}=e,{dir:d}=r,f=new Set;if(d===T)switch(o){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(e,t);for(i=t.nextSibling();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let i=this._traverse(e,t);for(i=t.firstChild();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling();break}case" ":default:{const{nodes:t,pending:i}=this._findDescendantNodes(s,e);if(t.size)return t;if(i){const c=this._createTreeWalker(e);let w=this._traverse(e,c);for(w=c.nextNode();w&&e.contains(w);)this._matchLeaves(s,w,r)&&f.add(w),w=c.nextNode()}}}else switch(o){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(n,t);for(i=t.firstChild();i&&i!==e;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{n&&this._matchLeaves(s,n,r)&&f.add(n);break}case" ":default:{const t=[];let i=n;for(;i;)this._matchLeaves(s,i,r)&&t.push(i),i=i.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:r}=e;let l=this._traverse(r,this.#n),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#n.nextNode():l===r&&l!==this.#s&&(l=this.#n.nextNode());l;){if(this._matchLeaves(a,l,{warn:this.#i})){s=l;break}l=this.#n.nextNode()}return s??null}_matchSelf(a){const e=[],r=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return r&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:r}=e,l=[];let s=this._matchLeaves(a,this.#e,{warn:this.#i}),o=!1;if(s&&(l.push(this.#e),o=!0),!s||r){let n=this.#e.parentNode;for(;n&&(s=this._matchLeaves(a,n,{warn:this.#i}),s&&(l.push(n),o=!0),n.parentNode);)n=n.parentNode}return[l,o]}_findFirst(a){const e=[],r=this._findNode(a,{node:this.#e});let l=!1;return r&&(e.push(r),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:r,compound:l,filterLeaves:s,targetType:o}=e;let n=[],d=!1,f=!1;const t=a.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let i=0;i0,{name:d,type:f}=s;let t=[],i=!1,c=!1,w=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(e===A&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(n?this._matchLeaves(o,_,{warn:this.#i})&&(t.push(_),c=!0):(t.push(_),c=!0))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(d)){if(this.#b&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(s,this.#e);_&&(t.push(_),c=!0)}}else e===D?[t,c]=this._matchSelf(l):e===R?[t,c]=this._findLineal(l,{complex:r}):e===A?[t,c]=this._findFirst(l):w=!0}return{collected:i,compound:n,filtered:c,nodes:t,pending:w}}_collectNodes(a){const e=this.#a.values();if(a===M||a===A){const r=new Set;let l=0;for(const{branch:s}of e){const o=s.length,n=o>1,d=s[0];let f,t;if(n){const{combo:N,leaves:[{name:k,type:g}]}=d,h=s[o-1],{leaves:[{name:p,type:u}]}=h;if(u===b.SELECTOR_PSEUDO_ELEMENT||u===b.SELECTOR_ID)f=O,t=h;else if(g===b.SELECTOR_PSEUDO_ELEMENT||g===b.SELECTOR_ID)f=T,t=d;else if(a===M)if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else if(p==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(o===2){const{name:y}=N;/^[+~]$/.test(y)?(f=O,t=h):(f=T,t=d)}else f=T,t=d;else if(p==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else{let y;for(const{combo:v,leaves:[L]}of s){const{name:x,type:W}=L;if(W===b.SELECTOR_PSEUDO_CLASS&&x==="dir"){y=!1;break}if(!y&&v){const{name:H}=v;/^[+~]$/.test(H)&&(y=!0)}}y?(f=T,t=d):(f=O,t=h)}}else f=O,t=d;const{collected:i,compound:c,filtered:w,nodes:_,pending:m}=this._findEntryNodes(t,a,n);_.length?(this.#a[l].find=!0,this.#d[l]=_):m&&r.add(new Map([["index",l],["twig",t]])),this.#a[l].collected=i,this.#a[l].dir=f,this.#a[l].filtered=w||!c,l++}if(r.size){let s,o;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,o=this.#n):(s=this.#s,o=this.#r);let n=this._traverse(s,o);for(;n;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?n===this.#e?d=!0:d=this.#e.contains(n):d=!0,d)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const c=f.get("index");this.#a[c].filtered=!0,this.#a[c].find=!0,this.#d[c].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let r=0;for(const{branch:l}of e){const s=l[l.length-1],o=l.length>1,{compound:n,filtered:d,nodes:f}=this._findEntryNodes(s,a,o);f.length&&(this.#a[r].find=!0,this.#d[r]=f),this.#a[r].dir=O,this.#a[r].filtered=d||!n,r++}}return[this.#a,this.#d]}_getCombinedNodes(a,e,r){const l=[];for(const s of e){const o=this._matchCombinator(a,s,{dir:r,warn:this.#i});o.size&&l.push(...o)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,r){const{combo:l,index:s}=r,{combo:o,leaves:n}=a[s],d={combo:l,leaves:n},f=this._getCombinedNodes(d,e,T);let t;if(f.size)if(s===a.length-1){const[i]=(0,C.sortNodes)(f);t=i}else t=this._matchNodeNext(a,f,{combo:o,index:s+1});return t??null}_matchNodePrev(a,e,r){const{index:l}=r,s=a[l],o=new Set([e]),n=this._getCombinedNodes(s,o,O);let d;if(n.size){if(l===0)d=e;else for(const f of n)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_find(a){(a===M||a===A)&&this._prepareQuerySelectorWalker();const[[...e],r]=this._collectNodes(a),l=e.length;let s=new Set;for(let o=0;o=0;k--){const g=n[k];if(N=this._getCombinedNodes(g,N,f),N.size)k===0&&(s.add(m),i>1&&s.size>1&&(this.#u=!0));else break}}else if(a===A&&f===T){const{combo:m}=n[0];let N;for(const k of c)if(N=this._matchNodeNext(n,new Set([k]),{combo:m,index:1}),N){s.add(N);break}if(!N&&!d){const{leaves:k}=n[0],[g]=c;let h=this._findNode(k,{node:g});for(;h;){if(N=this._matchNodeNext(n,new Set([h]),{combo:m,index:1}),N){s.add(N);break}h=this._findNode(k,{node:h})}}}else{let m;for(const N of c)if(m=this._matchNodePrev(n,N,{index:_-1}),m){s.add(N);break}if(!m&&!d&&a===A){const{leaves:N}=n[_],[k]=c;let g=this._findNode(N,{node:k});for(;g;){if(m=this._matchNodePrev(n,g,{index:_-1}),m){s.add(g);break}g=this._findNode(N,{node:g})}}}}}return s}matches(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,S.filterSelector)(a)?l=this.#o.match(a,e):(this._setup(a,e,r),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,S.filterSelector)(a))l=this.#o.closest(a,e);else{this._setup(a,e,r);const s=this._find(R);if(s.size){let o=this.#e;for(;o;){if(s.has(o)){l=o;break}o=o.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(a,e,r){let l;try{if(this._setup(a,e,r),this.#h===this.#t&&!this.#f&&(0,S.filterSelector)(a))l=this.#o.first(a,e);else{const s=this._find(A);s.delete(this.#e),s.size&&([l]=(0,C.sortNodes)(s))}}catch(s){this._onError(s)}return l??null}querySelectorAll(a,e,r){let l;try{if(this._setup(a,e,r),this.#h===this.#t&&!this.#f&&(0,S.filterSelector)(a))l=this.#o.select(a,e);else{const s=this._find(M);s.delete(this.#e),s.size&&(this.#u?l=(0,C.sortNodes)(s):l=[...s])}}catch(s){this._onError(s)}return l??[]}}0&&(module.exports={Finder}); //# sourceMappingURL=finder.js.map diff --git a/dist/cjs/js/finder.js.map b/dist/cjs/js/finder.js.map index 2e95c8e5..3760cfe7 100644 --- a/dist/cjs/js/finder.js.map +++ b/dist/cjs/js/finder.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../../src/js/finder.js"], - "sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport nwsapi from 'nwsapi';\nimport {\n isContentEditable, isInShadowTree, resolveContent, sortNodes\n} from './dom-util.js';\nimport { matcher } from './matcher.js';\nimport {\n filterSelector, generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, EMPTY,\n NOT_SUPPORTED_ERR, REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ALL, SYNTAX_ERR, TEXT_NODE, WALKER_FILTER\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * collected: boolean,\n * dir: string|null,\n * filtered: boolean,\n * find: boolean\n * },\n * {\n * branch: branch[],\n * collected: boolean,\n * dir: string|null,\n * filtered: boolean,\n * find: boolean\n * }\n * ]\n * #nodes: [\n * [node{}, node{}],\n * [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{}: CSSTree AST object\n * node{}: Element node\n */\nexport class Finder {\n /* private fields */\n #ast;\n #cache;\n #content;\n #descendant;\n #document;\n #node;\n #nodes;\n #noexcept;\n #nwsapi;\n #qswalker;\n #results;\n #root;\n #shadow;\n #sort;\n #walker;\n #walkers;\n #warn;\n #window;\n\n /**\n * construct\n * @param {object} window - window\n */\n constructor(window) {\n this.#window = window;\n this.#document = window.document;\n this.#cache = new WeakMap();\n this.#results = new WeakMap();\n this.#nwsapi = nwsapi({\n document: window.document,\n DOMException: window.DOMException\n });\n this.#nwsapi.configure({\n LOGERRORS: false\n });\n }\n\n /**\n * handle error\n * @private\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (!this.#noexcept) {\n if (e instanceof DOMException ||\n e instanceof this.#window.DOMException) {\n if (e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw new this.#window.DOMException(e.message, e.name);\n }\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @private\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {boolean} [opt.noexcept] - no exception\n * @param {boolean} [opt.warn] - console warn\n * @returns {object} - node\n */\n _setup(selector, node, opt = {}) {\n const { noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#node = node;\n [this.#content, this.#root, this.#walker] = resolveContent(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#walkers = new WeakMap();\n return node;\n }\n\n /**\n * correspond ast and nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.>} - array of ast and nodes\n */\n _correspond(selector) {\n const nodes = [];\n this.#descendant = false;\n let ast;\n if (this.#content) {\n const cachedItem = this.#cache.get(this.#content);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n const item = cachedItem.get(`${selector}`);\n this.#descendant = item.descendant;\n ast = item.ast;\n }\n }\n if (ast) {\n const l = ast.length;\n for (let i = 0; i < l; i++) {\n ast[i].collected = false;\n ast[i].dir = null;\n ast[i].filtered = false;\n ast[i].find = false;\n nodes[i] = [];\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n this._onError(e);\n }\n const branches = walkAST(cssAst);\n let descendant = false;\n let i = 0;\n ast = [];\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 selector ${selector}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const itemName = item.name;\n if (/^[\\s>]$/.test(itemName)) {\n descendant = true;\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (item) {\n let { name: itemName } = item;\n if (itemName && typeof itemName === 'string') {\n itemName = unescapeSelector(itemName);\n if (typeof itemName === 'string' && itemName !== item.name) {\n item.name = itemName;\n }\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n }\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n collected: false,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = [];\n i++;\n }\n if (this.#content) {\n let cachedItem;\n if (this.#cache.has(this.#content)) {\n cachedItem = this.#cache.get(this.#content);\n } else {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, {\n ast,\n descendant\n });\n this.#cache.set(this.#content, cachedItem);\n }\n this.#descendant = descendant;\n }\n return [\n ast,\n nodes\n ];\n }\n\n /**\n * create tree walker\n * @private\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - tree walker\n */\n _createTreeWalker(node) {\n let walker;\n if (this.#walkers.has(node)) {\n walker = this.#walkers.get(node);\n } else {\n walker = this.#document.createTreeWalker(node, WALKER_FILTER);\n this.#walkers.set(node, walker);\n }\n return walker;\n }\n\n /**\n * prepare querySelector walker\n * @private\n * @returns {object} - tree walker\n */\n _prepareQuerySelectorWalker() {\n this.#qswalker = this._createTreeWalker(this.#node);\n this.#sort = false;\n return this.#qswalker;\n }\n\n /**\n * traverse tree walker\n * @private\n * @param {object} node - Element node\n * @param {object} [walker] - tree walker\n * @returns {?object} - current node\n */\n _traverse(node, walker = this.#walker) {\n let refNode = walker.currentNode;\n let current;\n if (refNode === node) {\n current = refNode;\n } else if (refNode.contains(node)) {\n refNode = walker.nextNode();\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root || refNode === node) {\n break;\n }\n refNode = walker.parentNode();\n }\n }\n if (node?.nodeType === ELEMENT_NODE) {\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n current = refNode;\n }\n }\n return current ?? null;\n }\n\n /**\n * collect nth child\n * @private\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 * @param {object} opt - options\n * @returns {Set.} - collection of matched nodes\n */\n _collectNthChild(anb, node, opt) {\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 walker = this.#walker;\n let refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n refNode = this._traverse(parentNode, walker);\n const selectorNodes = new Set();\n if (selectorBranches) {\n refNode = walker.firstChild();\n while (refNode) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, refNode, opt);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n // :first-child, :last-child, :nth-child(b of S), :nth-last-child(b of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (selectorNodes.has(refNode)) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n i++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n } else if (!selector) {\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n }\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 refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n if (refNode && nth >= 0 && nth < l) {\n if (selectorNodes.size) {\n if (selectorNodes.has(refNode)) {\n if (j === nth) {\n matched.add(refNode);\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(refNode);\n }\n nth += a;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n } else {\n break;\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @private\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.} - 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 walker = this.#walker;\n let refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let j = 0;\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(refNode);\n break;\n }\n j++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\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 refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(refNode);\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 if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @param {object} opt - options\n * @returns {Set.} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName, opt) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const anbMap = new Map();\n if (nthIdentName) {\n if (nthIdentName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (nthIdentName === '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 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, opt);\n return nodes;\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n return nodes;\n }\n return new Set();\n }\n\n /**\n * match :has() pseudo-class function\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node, opt = {}) {\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 opt.dir = DIR_NEXT;\n const nodes = this._matchCombinator(twig, node, opt);\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves),\n nextNode, opt);\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 * @private\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node, opt = {}) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n let bool;\n for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node, opt);\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 opt.forgive = forgive;\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, opt);\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 opt.dir = DIR_PREV;\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, opt);\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\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 * @private\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] - forgive unknown pseudo-class\n * @param {boolean} [opt.warn] - warn unsupported pseudo-class\n * @returns {Set.} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren, name: astName } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = opt;\n const 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, opt);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(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 [branch] = astChildren;\n const nodes = this._matchAnPlusB(branch, node, astName, opt);\n return nodes;\n } else {\n switch (astName) {\n // :dir(), :lang()\n case 'dir':\n case 'lang': {\n const res = matcher.matchSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}()`;\n throw new DOMException(msg, 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 const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n } else {\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(this.#content.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(this.#content.URL);\n if (node.id && hash === `#${node.id}` &&\n this.#content.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(this.#content.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = this.#content.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 (!this.#shadow && node === this.#node) {\n matched.add(node);\n }\n } else if (node === this.#content.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === this.#content.activeElement) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else if (refNode.hasAttribute('style')) {\n const { display, visibility } = refNode.style;\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let current = this.#content.activeElement;\n let active;\n while (current) {\n if (current === node) {\n active = true;\n break;\n }\n current = current.parentNode;\n }\n if (active) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else if (refNode.hasAttribute('style')) {\n const { display, visibility } = refNode.style;\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\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 = this.#content.documentElement;\n }\n const items = parent.getElementsByTagName('input');\n const l = items.length;\n let checked;\n for (let i = 0; i < l; i++) {\n const item = items[i];\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 walker = this.#walker;\n let nextNode = this._traverse(form, walker);\n nextNode = walker.firstChild();\n while (nextNode && form.contains(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 = walker.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 parent = parentNode;\n let isMultiple = false;\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 defaultOpt = new Set();\n const walker = this.#walker;\n let refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.selected || refNode.hasAttribute('selected')) {\n defaultOpt.add(refNode);\n break;\n }\n refNode = walker.nextSibling();\n }\n if (defaultOpt.size) {\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\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 walker = this.#walker;\n let refNode = this._traverse(node, walker);\n refNode = walker.firstChild();\n let bool;\n while (refNode && node.contains(refNode)) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = walker.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 walker = this.#walker;\n let refNode = this._traverse(node, walker);\n refNode = walker.firstChild();\n let bool;\n while (refNode && node.contains(refNode)) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = walker.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 === this.#content.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n let bool;\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\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 === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === this.#root) {\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 (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'defined':\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 (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match shadow host pseudo class\n * @private\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, name: astName } = ast;\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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, 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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, 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 const msg = `Invalid selector :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const matched = new Set();\n if (ast.name === EMPTY) {\n return matched;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n }\n default: {\n const res = matcher.matchSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#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 return nodes;\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n const { attributes, localName, nodeType } = node;\n let result = this.#results.get(leaves);\n let bool;\n if (result && result.has(node)) {\n const { attr, matched } = result.get(node);\n if (attributes?.length === attr) {\n bool = matched;\n }\n }\n if (typeof bool !== 'boolean') {\n const regForm = /^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;\n let save;\n if (nodeType === ELEMENT_NODE && regForm.test(localName)) {\n save = false;\n } else {\n save = true;\n }\n for (const leaf of leaves) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n save = false;\n }\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n if (save) {\n if (!result) {\n result = new WeakMap();\n }\n result.set(node, {\n attr: attributes?.length,\n matched: bool\n });\n this.#results.set(leaves, result);\n }\n }\n return !!bool;\n }\n\n /**\n * match HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @returns {Set.} - matched nodes\n */\n _matchHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n const nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n return new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (typeof leafName === 'string' && leafName !== leaf.name) {\n leaf.name = leafName;\n }\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (this.#root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = this.#root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, opt);\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 items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#content.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const items = baseNode.getElementsByTagName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\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 * @private\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} opt - option\n * @returns {Set.} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { parentNode } = node;\n const { dir } = opt;\n const matched = new Set();\n if (dir === DIR_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = this._traverse(node, walker);\n refNode = walker.nextSibling();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n const walker = this._createTreeWalker(node);\n let refNode = this._traverse(node, walker);\n refNode = walker.firstChild();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n return nodes;\n }\n if (pending) {\n const walker = this._createTreeWalker(node);\n let refNode = this._traverse(node, walker);\n refNode = walker.nextNode();\n while (refNode && node.contains(refNode)) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.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, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode === node) {\n break;\n } else {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n if (parentNode) {\n const bool = this._matchLeaves(leaves, parentNode, opt);\n if (bool) {\n matched.add(parentNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n return new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find matched node from #qswalker\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} [opt] - options\n * @param {object} [opt.node] - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, opt) {\n const { node } = opt;\n let refNode = this._traverse(node, this.#qswalker);\n let matchedNode;\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = this.#qswalker.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = this.#qswalker.nextNode();\n }\n }\n while (refNode) {\n const matched = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (matched) {\n matchedNode = refNode;\n break;\n }\n refNode = this.#qswalker.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * match self\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _matchSelf(leaves) {\n const nodes = [];\n const bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find lineal\n * @private\n * @param {Array} leaves - AST leaves\n * @param {object} opt - options\n * @returns {Array} - [nodes, filtered]\n */\n _findLineal(leaves, opt = {}) {\n const { complex } = opt;\n const nodes = [];\n let bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n if (!bool || complex) {\n let refNode = this.#node.parentNode;\n while (refNode) {\n bool = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(refNode);\n filtered = true;\n }\n if (refNode.parentNode) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find first\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFirst(leaves) {\n const nodes = [];\n const node = this._findNode(leaves, {\n node: this.#node\n });\n let filtered = false;\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find from HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @param {boolean} [opt.compound] - compound selector\n * @param {Array} [opt.filterLeaves] - filter leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFromHTMLCollection(items, opt = {}) {\n const { complex, compound, filterLeaves, targetType } = opt;\n let nodes = [];\n let filtered = false;\n let collected = false;\n const l = items.length;\n if (l) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n if (node !== this.#node &&\n (this.#node.contains(node) || node.contains(this.#node))) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n } else {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (complex) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n } else if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n }\n return [nodes, filtered, collected];\n }\n\n /**\n * find entry nodes\n * @private\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @param {boolean} complex - complex selector\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType, complex) {\n const { leaves } = twig;\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { name: leafName, type: leafType } = leaf;\n let nodes = [];\n let collected = false;\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const items = this.#root.getElementsByClassName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#content.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.>} - #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 branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT ||\n lastType === SELECTOR_ID) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (branchLen === 2) {\n const { name: comboName } = firstCombo;\n if (/^[+~]$/.test(comboName)) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n let bool;\n for (const { combo, leaves: [leaf] } of branch) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n bool = false;\n break;\n }\n if (!bool && combo) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n const {\n collected, compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].collected = collected;\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#qswalker;\n } else {\n node = this.#root;\n walker = this.#walker;\n }\n let nextNode = this._traverse(node, walker);\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 warn: this.#warn\n });\n if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].push(nextNode);\n }\n }\n }\n if (nextNode !== walker.currentNode) {\n nextNode = this._traverse(nextNode, walker);\n }\n nextNode = walker.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const complex = branch.length > 1;\n const {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n }\n this.#ast[i].dir = DIR_PREV;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * get combined nodes\n * @private\n * @param {object} twig - twig\n * @param {object} nodes - collection of nodes\n * @param {string} dir - direction\n * @returns {Array.} - collection of matched nodes\n */\n _getCombinedNodes(twig, nodes, dir) {\n const arr = [];\n for (const node of nodes) {\n const matched = this._matchCombinator(twig, node, {\n dir,\n warn: this.#warn\n });\n if (matched.size) {\n arr.push(...matched);\n }\n }\n if (arr.length) {\n return new Set(arr);\n }\n return new Set();\n }\n\n /**\n * match node to next direction\n * @private\n * @param {Array} branch - branch\n * @param {Set.} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.} - collection of matched nodes\n */\n _find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], nodes] = this._collectNodes(targetType);\n const l = branches.length;\n let res = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, collected, dir, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = nodes[i];\n const entryNodesLen = entryNodes.length;\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 (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n if (node !== this.#node && this.#node.contains(node)) {\n res.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (res.size) {\n const n = [...res];\n res = new Set([...n, ...entryNodes]);\n this.#sort = true;\n } else {\n res = new Set(entryNodes);\n }\n } else {\n const [node] = entryNodes;\n res.add(node);\n }\n } else if (targetType === TARGET_ALL) {\n if (dir === DIR_NEXT) {\n let { combo } = branch[0];\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const twig = {\n combo,\n leaves\n };\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === lastIndex) {\n if (res.size) {\n const n = [...res];\n res = new Set([...n, ...nextNodes]);\n this.#sort = true;\n } else {\n res = nextNodes;\n }\n } else {\n combo = nextCombo;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === 0) {\n res.add(node);\n if (branchLen > 1 && res.size > 1) {\n this.#sort = true;\n }\n }\n } else {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST && dir === DIR_NEXT) {\n const { combo: entryCombo } = branch[0];\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodeNext(branch, new Set([node]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n res.add(matched);\n break;\n }\n }\n if (!matched && !collected) {\n const { leaves: entryLeaves } = branch[0];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodeNext(branch, new Set([refNode]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n res.add(matched);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n } else {\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodePrev(branch, node, {\n index: lastIndex - 1\n });\n if (matched) {\n res.add(node);\n break;\n }\n }\n if (!matched && !collected && targetType === TARGET_FIRST) {\n const { leaves: entryLeaves } = branch[lastIndex];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodePrev(branch, refNode, {\n index: lastIndex - 1\n });\n if (matched) {\n res.add(refNode);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n }\n }\n }\n return res;\n }\n\n /**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n let res;\n try {\n if (node?.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node?.nodeName}`;\n throw new TypeError(msg);\n }\n if (filterSelector(selector)) {\n res = this.#nwsapi.match(selector, node);\n } else {\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_SELF);\n res = nodes.size;\n }\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n let res;\n try {\n if (node?.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node?.nodeName}`;\n throw new TypeError(msg);\n }\n if (filterSelector(selector)) {\n res = this.#nwsapi.closest(selector, node);\n } else {\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = this.#node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n let res;\n try {\n this._setup(selector, node, opt);\n if (this.#document === this.#content && !this.#descendant &&\n filterSelector(selector)) {\n res = this.#nwsapi.first(selector, node);\n } else {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = sortNodes(nodes);\n }\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 * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n let res;\n try {\n this._setup(selector, node, opt);\n if (this.#document === this.#content && !this.#descendant &&\n filterSelector(selector)) {\n res = this.#nwsapi.select(selector, node);\n } else {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n if (this.#sort) {\n res = sortNodes(nodes);\n } else {\n res = [...nodes];\n }\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"], - "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAAmB,uBACnBC,EAEO,yBACPC,EAAwB,wBACxBC,EAEO,uBAGPC,EAKO,yBACP,MAAMC,EAAW,OACXC,EAAW,OACXC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OAkCb,MAAMb,CAAO,CAElBc,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAMA,YAAYC,EAAQ,CAClB,KAAKD,GAAUC,E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AAMC,CAAG,EAC3B,KAAKnB,KAAc,KAAKF,IAAY,CAAC,KAAKC,OAC1C,kBAAekB,CAAQ,EACzBoD,EAAM,KAAKjE,GAAQ,OAAOa,EAAUC,CAAI,MACnC,CACL,MAAMI,EAAQ,KAAK,MAAM9B,CAAU,EACnC8B,EAAM,OAAO,KAAKrB,EAAK,EACnBqB,EAAM,OACJ,KAAKb,GACP4D,KAAM,aAAU/C,CAAK,EAErB+C,EAAM,CAAC,GAAG/C,CAAK,EAGrB,CACF,OAASN,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAOqD,GAAO,CAAC,CACjB,CACF", - "names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_is_potential_custom_element_name", "import_nwsapi", "import_dom_util", "import_matcher", "import_parser", "import_constant", "DIR_NEXT", "DIR_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#cache", "#content", "#descendant", "#document", "#node", "#nodes", "#noexcept", "#nwsapi", "#qswalker", "#results", "#root", "#shadow", "#sort", "#walker", "#walkers", "#warn", "#window", "window", "nwsapi", "e", "selector", "node", "opt", "noexcept", "warn", "nodes", "ast", "cachedItem", "item", "i", "cssAst", "branches", "descendant", "items", "branch", "leaves", "nextItem", "msg", "itemName", "walker", "refNode", "current", "anb", "a", "b", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "bool", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "m", "nthName", "nthIdentName", "anbMap", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "astName", "twigBranches", "res", "forgive", "lastIndex", "nextNodes", "arr", "astChildren", "selectors", "css", "leavesSet", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "href", "origin", "pathname", "attrURL", "hash", "id", "focus", "display", "visibility", "active", "isCustomElementName", "parent", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "isMultiple", "defaultOpt", "inputType", "node1", "node2", "host", "astType", "attributes", "nodeType", "result", "attr", "regForm", "save", "leafName", "compound", "filterLeaves", "baseNode", "pending", "comboName", "dir", "matchedNode", "filtered", "complex", "targetType", "collected", "pendingItems", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "pendingItem", "index", "nextCombo", "find", "entryNodes", "entryNodesLen", "n", "entryCombo", "entryLeaves", "entryNode"] + "sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport nwsapi from 'nwsapi';\nimport {\n isContentEditable, isInShadowTree, resolveContent, sortNodes\n} from './dom-util.js';\nimport { matcher } from './matcher.js';\nimport {\n filterSelector, generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, EMPTY,\n NOT_SUPPORTED_ERR, REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ALL, SYNTAX_ERR, TEXT_NODE, WALKER_FILTER\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * collected: boolean,\n * dir: string|null,\n * filtered: boolean,\n * find: boolean\n * },\n * {\n * branch: branch[],\n * collected: boolean,\n * dir: string|null,\n * filtered: boolean,\n * find: boolean\n * }\n * ]\n * #nodes: [\n * [node{}, node{}],\n * [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{}: CSSTree AST object\n * node{}: Element node\n */\nexport class Finder {\n /* private fields */\n #ast;\n #cache;\n #content;\n #descendant;\n #document;\n #node;\n #nodes;\n #noexcept;\n #nwsapi;\n #qswalker;\n #results;\n #root;\n #shadow;\n #sort;\n #walker;\n #walkers;\n #warn;\n #window;\n\n /**\n * construct\n * @param {object} window - window\n */\n constructor(window) {\n this.#window = window;\n this.#document = window.document;\n this.#cache = new WeakMap();\n this.#results = new WeakMap();\n this.#nwsapi = nwsapi({\n document: window.document,\n DOMException: window.DOMException\n });\n this.#nwsapi.configure({\n LOGERRORS: false\n });\n }\n\n /**\n * handle error\n * @private\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (!this.#noexcept) {\n if (e instanceof DOMException ||\n e instanceof this.#window.DOMException) {\n if (e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw new this.#window.DOMException(e.message, e.name);\n }\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @private\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {boolean} [opt.noexcept] - no exception\n * @param {boolean} [opt.warn] - console warn\n * @returns {object} - node\n */\n _setup(selector, node, opt = {}) {\n const { noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#node = node;\n [this.#content, this.#root, this.#walker] = resolveContent(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#walkers = new WeakMap();\n return node;\n }\n\n /**\n * correspond ast and nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.>} - array of ast and nodes\n */\n _correspond(selector) {\n const nodes = [];\n this.#descendant = false;\n let ast;\n if (this.#content) {\n const cachedItem = this.#cache.get(this.#content);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n const item = cachedItem.get(`${selector}`);\n this.#descendant = item.descendant;\n ast = item.ast;\n }\n }\n if (ast) {\n const l = ast.length;\n for (let i = 0; i < l; i++) {\n ast[i].collected = false;\n ast[i].dir = null;\n ast[i].filtered = false;\n ast[i].find = false;\n nodes[i] = [];\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n this._onError(e);\n }\n const branches = walkAST(cssAst);\n let descendant = false;\n let i = 0;\n ast = [];\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 selector ${selector}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const itemName = item.name;\n if (/^[\\s>]$/.test(itemName)) {\n descendant = true;\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (item) {\n let { name: itemName } = item;\n if (itemName && typeof itemName === 'string') {\n itemName = unescapeSelector(itemName);\n if (typeof itemName === 'string' && itemName !== item.name) {\n item.name = itemName;\n }\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n }\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n collected: false,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = [];\n i++;\n }\n if (this.#content) {\n let cachedItem;\n if (this.#cache.has(this.#content)) {\n cachedItem = this.#cache.get(this.#content);\n } else {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, {\n ast,\n descendant\n });\n this.#cache.set(this.#content, cachedItem);\n }\n this.#descendant = descendant;\n }\n return [\n ast,\n nodes\n ];\n }\n\n /**\n * create tree walker\n * @private\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - tree walker\n */\n _createTreeWalker(node) {\n let walker;\n if (this.#walkers.has(node)) {\n walker = this.#walkers.get(node);\n } else {\n walker = this.#document.createTreeWalker(node, WALKER_FILTER);\n this.#walkers.set(node, walker);\n }\n return walker;\n }\n\n /**\n * prepare querySelector walker\n * @private\n * @returns {object} - tree walker\n */\n _prepareQuerySelectorWalker() {\n this.#qswalker = this._createTreeWalker(this.#node);\n this.#sort = false;\n return this.#qswalker;\n }\n\n /**\n * traverse tree walker\n * @private\n * @param {object} node - Element node\n * @param {object} [walker] - tree walker\n * @returns {?object} - current node\n */\n _traverse(node, walker = this.#walker) {\n let refNode = walker.currentNode;\n let current;\n if (refNode === node) {\n current = refNode;\n } else if (refNode.contains(node)) {\n refNode = walker.nextNode();\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root || refNode === node) {\n break;\n }\n refNode = walker.parentNode();\n }\n }\n if (node?.nodeType === ELEMENT_NODE) {\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n current = refNode;\n }\n }\n return current ?? null;\n }\n\n /**\n * collect nth child\n * @private\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 * @param {object} opt - options\n * @returns {Set.} - collection of matched nodes\n */\n _collectNthChild(anb, node, opt) {\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 walker = this.#walker;\n let refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n refNode = this._traverse(parentNode, walker);\n const selectorNodes = new Set();\n if (selectorBranches) {\n refNode = walker.firstChild();\n while (refNode) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, refNode, opt);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n // :first-child, :last-child, :nth-child(b of S), :nth-last-child(b of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (selectorNodes.has(refNode)) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n i++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n } else if (!selector) {\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n }\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 refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n if (refNode && nth >= 0 && nth < l) {\n if (selectorNodes.size) {\n if (selectorNodes.has(refNode)) {\n if (j === nth) {\n matched.add(refNode);\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(refNode);\n }\n nth += a;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n } else {\n break;\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @private\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.} - 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 walker = this.#walker;\n let refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let j = 0;\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(refNode);\n break;\n }\n j++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\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 refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(refNode);\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 if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @param {object} opt - options\n * @returns {Set.} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName, opt) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const anbMap = new Map();\n if (nthIdentName) {\n if (nthIdentName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (nthIdentName === '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 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, opt);\n return nodes;\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n return nodes;\n }\n return new Set();\n }\n\n /**\n * match :has() pseudo-class function\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node, opt = {}) {\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 opt.dir = DIR_NEXT;\n const nodes = this._matchCombinator(twig, node, opt);\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves),\n nextNode, opt);\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 * @private\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node, opt = {}) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n let bool;\n for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node, opt);\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 opt.forgive = forgive;\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, opt);\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 opt.dir = DIR_PREV;\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, opt);\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\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 * @private\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] - forgive unknown pseudo-class\n * @param {boolean} [opt.warn] - warn unsupported pseudo-class\n * @returns {Set.} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren, name: astName } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = opt;\n const 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, opt);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(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 [branch] = astChildren;\n const nodes = this._matchAnPlusB(branch, node, astName, opt);\n return nodes;\n } else {\n switch (astName) {\n // :dir(), :lang()\n case 'dir':\n case 'lang': {\n const res = matcher.matchSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}()`;\n throw new DOMException(msg, 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 const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n } else {\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(this.#content.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(this.#content.URL);\n if (node.id && hash === `#${node.id}` &&\n this.#content.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(this.#content.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = this.#content.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 (!this.#shadow && node === this.#node) {\n matched.add(node);\n }\n } else if (node === this.#content.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === this.#content.activeElement) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else if (refNode.hasAttribute('style')) {\n const { display, visibility } = refNode.style;\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let current = this.#content.activeElement;\n let active;\n while (current) {\n if (current === node) {\n active = true;\n break;\n }\n current = current.parentNode;\n }\n if (active) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else if (refNode.hasAttribute('style')) {\n const { display, visibility } = refNode.style;\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\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 = this.#content.documentElement;\n }\n const items = parent.getElementsByTagName('input');\n const l = items.length;\n let checked;\n for (let i = 0; i < l; i++) {\n const item = items[i];\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 walker = this.#walker;\n let nextNode = this._traverse(form, walker);\n nextNode = walker.firstChild();\n while (nextNode && form.contains(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 = walker.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 parent = parentNode;\n let isMultiple = false;\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 defaultOpt = new Set();\n const walker = this.#walker;\n let refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.selected || refNode.hasAttribute('selected')) {\n defaultOpt.add(refNode);\n break;\n }\n refNode = walker.nextSibling();\n }\n if (defaultOpt.size) {\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\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 walker = this.#walker;\n let refNode = this._traverse(node, walker);\n refNode = walker.firstChild();\n let bool;\n while (refNode && node.contains(refNode)) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = walker.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 walker = this.#walker;\n let refNode = this._traverse(node, walker);\n refNode = walker.firstChild();\n let bool;\n while (refNode && node.contains(refNode)) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = walker.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 === this.#content.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n let bool;\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\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 === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'defined': {\n const attr = node.getAttribute('is');\n if (attr) {\n if (isCustomElementName(attr) &&\n this.#window.customElements.get(attr)) {\n matched.add(node);\n }\n } else if (isCustomElementName(localName)) {\n if (this.#window.customElements.get(localName)) {\n matched.add(node);\n }\n // NOTE: MathMLElement not implemented in jsdom\n } else if (node instanceof this.#window.HTMLElement ||\n node instanceof this.#window.SVGElement) {\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 (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, 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 (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match shadow host pseudo class\n * @private\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, name: astName } = ast;\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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, 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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, 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 const msg = `Invalid selector :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const matched = new Set();\n if (ast.name === EMPTY) {\n return matched;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n }\n default: {\n const res = matcher.matchSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#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 return nodes;\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n const { attributes, localName, nodeType } = node;\n let result = this.#results.get(leaves);\n let bool;\n if (result && result.has(node)) {\n const { attr, matched } = result.get(node);\n if (attributes?.length === attr) {\n bool = matched;\n }\n }\n if (typeof bool !== 'boolean') {\n const regForm = /^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;\n let save;\n if (nodeType === ELEMENT_NODE && regForm.test(localName)) {\n save = false;\n } else {\n save = true;\n }\n for (const leaf of leaves) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n save = false;\n }\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n if (save) {\n if (!result) {\n result = new WeakMap();\n }\n result.set(node, {\n attr: attributes?.length,\n matched: bool\n });\n this.#results.set(leaves, result);\n }\n }\n return !!bool;\n }\n\n /**\n * match HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @returns {Set.} - matched nodes\n */\n _matchHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n const nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n return new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (typeof leafName === 'string' && leafName !== leaf.name) {\n leaf.name = leafName;\n }\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (this.#root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = this.#root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, opt);\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 items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#content.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const items = baseNode.getElementsByTagName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\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 * @private\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} opt - option\n * @returns {Set.} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { parentNode } = node;\n const { dir } = opt;\n const matched = new Set();\n if (dir === DIR_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = this._traverse(node, walker);\n refNode = walker.nextSibling();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n const walker = this._createTreeWalker(node);\n let refNode = this._traverse(node, walker);\n refNode = walker.firstChild();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n return nodes;\n }\n if (pending) {\n const walker = this._createTreeWalker(node);\n let refNode = this._traverse(node, walker);\n refNode = walker.nextNode();\n while (refNode && node.contains(refNode)) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.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, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode === node) {\n break;\n } else {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n if (parentNode) {\n const bool = this._matchLeaves(leaves, parentNode, opt);\n if (bool) {\n matched.add(parentNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n return new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find matched node from #qswalker\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} [opt] - options\n * @param {object} [opt.node] - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, opt) {\n const { node } = opt;\n let refNode = this._traverse(node, this.#qswalker);\n let matchedNode;\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = this.#qswalker.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = this.#qswalker.nextNode();\n }\n }\n while (refNode) {\n const matched = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (matched) {\n matchedNode = refNode;\n break;\n }\n refNode = this.#qswalker.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * match self\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _matchSelf(leaves) {\n const nodes = [];\n const bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find lineal\n * @private\n * @param {Array} leaves - AST leaves\n * @param {object} opt - options\n * @returns {Array} - [nodes, filtered]\n */\n _findLineal(leaves, opt = {}) {\n const { complex } = opt;\n const nodes = [];\n let bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n if (!bool || complex) {\n let refNode = this.#node.parentNode;\n while (refNode) {\n bool = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(refNode);\n filtered = true;\n }\n if (refNode.parentNode) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find first\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFirst(leaves) {\n const nodes = [];\n const node = this._findNode(leaves, {\n node: this.#node\n });\n let filtered = false;\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find from HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @param {boolean} [opt.compound] - compound selector\n * @param {Array} [opt.filterLeaves] - filter leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFromHTMLCollection(items, opt = {}) {\n const { complex, compound, filterLeaves, targetType } = opt;\n let nodes = [];\n let filtered = false;\n let collected = false;\n const l = items.length;\n if (l) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n if (node !== this.#node &&\n (this.#node.contains(node) || node.contains(this.#node))) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n } else {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (complex) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n } else if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n }\n return [nodes, filtered, collected];\n }\n\n /**\n * find entry nodes\n * @private\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @param {boolean} complex - complex selector\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType, complex) {\n const { leaves } = twig;\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { name: leafName, type: leafType } = leaf;\n let nodes = [];\n let collected = false;\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const items = this.#root.getElementsByClassName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#content.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.>} - #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 branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT ||\n lastType === SELECTOR_ID) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (branchLen === 2) {\n const { name: comboName } = firstCombo;\n if (/^[+~]$/.test(comboName)) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n let bool;\n for (const { combo, leaves: [leaf] } of branch) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n bool = false;\n break;\n }\n if (!bool && combo) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n const {\n collected, compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].collected = collected;\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#qswalker;\n } else {\n node = this.#root;\n walker = this.#walker;\n }\n let nextNode = this._traverse(node, walker);\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 warn: this.#warn\n });\n if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].push(nextNode);\n }\n }\n }\n if (nextNode !== walker.currentNode) {\n nextNode = this._traverse(nextNode, walker);\n }\n nextNode = walker.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const complex = branch.length > 1;\n const {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n }\n this.#ast[i].dir = DIR_PREV;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * get combined nodes\n * @private\n * @param {object} twig - twig\n * @param {object} nodes - collection of nodes\n * @param {string} dir - direction\n * @returns {Array.} - collection of matched nodes\n */\n _getCombinedNodes(twig, nodes, dir) {\n const arr = [];\n for (const node of nodes) {\n const matched = this._matchCombinator(twig, node, {\n dir,\n warn: this.#warn\n });\n if (matched.size) {\n arr.push(...matched);\n }\n }\n if (arr.length) {\n return new Set(arr);\n }\n return new Set();\n }\n\n /**\n * match node to next direction\n * @private\n * @param {Array} branch - branch\n * @param {Set.} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.} - collection of matched nodes\n */\n _find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], nodes] = this._collectNodes(targetType);\n const l = branches.length;\n let res = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, collected, dir, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = nodes[i];\n const entryNodesLen = entryNodes.length;\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 (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n if (node !== this.#node && this.#node.contains(node)) {\n res.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (res.size) {\n const n = [...res];\n res = new Set([...n, ...entryNodes]);\n this.#sort = true;\n } else {\n res = new Set(entryNodes);\n }\n } else {\n const [node] = entryNodes;\n res.add(node);\n }\n } else if (targetType === TARGET_ALL) {\n if (dir === DIR_NEXT) {\n let { combo } = branch[0];\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const twig = {\n combo,\n leaves\n };\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === lastIndex) {\n if (res.size) {\n const n = [...res];\n res = new Set([...n, ...nextNodes]);\n this.#sort = true;\n } else {\n res = nextNodes;\n }\n } else {\n combo = nextCombo;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === 0) {\n res.add(node);\n if (branchLen > 1 && res.size > 1) {\n this.#sort = true;\n }\n }\n } else {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST && dir === DIR_NEXT) {\n const { combo: entryCombo } = branch[0];\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodeNext(branch, new Set([node]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n res.add(matched);\n break;\n }\n }\n if (!matched && !collected) {\n const { leaves: entryLeaves } = branch[0];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodeNext(branch, new Set([refNode]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n res.add(matched);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n } else {\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodePrev(branch, node, {\n index: lastIndex - 1\n });\n if (matched) {\n res.add(node);\n break;\n }\n }\n if (!matched && !collected && targetType === TARGET_FIRST) {\n const { leaves: entryLeaves } = branch[lastIndex];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodePrev(branch, refNode, {\n index: lastIndex - 1\n });\n if (matched) {\n res.add(refNode);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n }\n }\n }\n return res;\n }\n\n /**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n let res;\n try {\n if (node?.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node?.nodeName}`;\n throw new TypeError(msg);\n }\n if (filterSelector(selector)) {\n res = this.#nwsapi.match(selector, node);\n } else {\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_SELF);\n res = nodes.size;\n }\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n let res;\n try {\n if (node?.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node?.nodeName}`;\n throw new TypeError(msg);\n }\n if (filterSelector(selector)) {\n res = this.#nwsapi.closest(selector, node);\n } else {\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = this.#node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n let res;\n try {\n this._setup(selector, node, opt);\n if (this.#document === this.#content && !this.#descendant &&\n filterSelector(selector)) {\n res = this.#nwsapi.first(selector, node);\n } else {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = sortNodes(nodes);\n }\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 * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n let res;\n try {\n this._setup(selector, node, opt);\n if (this.#document === this.#content && !this.#descendant &&\n filterSelector(selector)) {\n res = this.#nwsapi.select(selector, node);\n } else {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n if (this.#sort) {\n res = sortNodes(nodes);\n } else {\n res = [...nodes];\n }\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"], + "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAAmB,uBACnBC,EAEO,yBACPC,EAAwB,wBACxBC,EAEO,uBAGPC,EAKO,yBACP,MAAMC,EAAW,OACXC,EAAW,OACXC,EAAa,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CACA,OAAOqD,GAAO,IAChB,CASA,cAAcpD,EAAUC,EAAMC,EAAK,CACjC,IAAIkD,EACJ,GAAI,CAEF,GADA,KAAK,OAAOpD,EAAUC,EAAMC,CAAG,EAC3B,KAAKnB,KAAc,KAAKF,IAAY,CAAC,KAAKC,OAC1C,kBAAekB,CAAQ,EACzBoD,EAAM,KAAKjE,GAAQ,MAAMa,EAAUC,CAAI,MAClC,CACL,MAAMI,EAAQ,KAAK,MAAM7B,CAAY,EACrC6B,EAAM,OAAO,KAAKrB,EAAK,EACnBqB,EAAM,OACR,CAAC+C,CAAG,KAAI,aAAU/C,CAAK,EAE3B,CACF,OAASN,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAOqD,GAAO,IAChB,CAUA,iBAAiBpD,EAAUC,EAAMC,EAAK,CACpC,IAAIkD,EACJ,GAAI,CAEF,GADA,KAAK,OAAOpD,EAAUC,EAAMC,CAAG,EAC3B,KAAKnB,KAAc,KAAKF,IAAY,CAAC,KAAKC,OAC1C,kBAAekB,CAAQ,EACzBoD,EAAM,KAAKjE,GAAQ,OAAOa,EAAUC,CAAI,MACnC,CACL,MAAMI,EAAQ,KAAK,MAAM9B,CAAU,EACnC8B,EAAM,OAAO,KAAKrB,EAAK,EACnBqB,EAAM,OACJ,KAAKb,GACP4D,KAAM,aAAU/C,CAAK,EAErB+C,EAAM,CAAC,GAAG/C,CAAK,EAGrB,CACF,OAASN,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAOqD,GAAO,CAAC,CACjB,CACF", + "names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_is_potential_custom_element_name", "import_nwsapi", "import_dom_util", "import_matcher", "import_parser", "import_constant", "DIR_NEXT", "DIR_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#cache", "#content", "#descendant", "#document", "#node", "#nodes", "#noexcept", "#nwsapi", "#qswalker", "#results", "#root", "#shadow", "#sort", "#walker", "#walkers", "#warn", "#window", "window", "nwsapi", "e", "selector", "node", "opt", "noexcept", "warn", "nodes", "ast", "cachedItem", "item", "i", "cssAst", "branches", "descendant", "items", "branch", "leaves", "nextItem", "msg", "itemName", "walker", "refNode", "current", "anb", "a", "b", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "bool", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "m", "nthName", "nthIdentName", "anbMap", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "astName", "twigBranches", "res", "forgive", "lastIndex", "nextNodes", "arr", "astChildren", "selectors", "css", "leavesSet", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "href", "origin", "pathname", "attrURL", "hash", "id", "focus", "display", "visibility", "active", "isCustomElementName", "parent", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "isMultiple", "defaultOpt", "inputType", "node1", "node2", "attr", "host", "astType", "attributes", "nodeType", "result", "regForm", "save", "leafName", "compound", "filterLeaves", "baseNode", "pending", "comboName", "dir", "matchedNode", "filtered", "complex", "targetType", "collected", "pendingItems", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "pendingItem", "index", "nextCombo", "find", "entryNodes", "entryNodesLen", "n", "entryCombo", "entryLeaves", "entryNode"] } diff --git a/dist/cjs/js/parser.js.map b/dist/cjs/js/parser.js.map index b495ec69..e190bbd1 100644 --- a/dist/cjs/js/parser.js.map +++ b/dist/cjs/js/parser.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../../src/js/parser.js"], - "sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\n\n/* constants */\nimport {\n BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF, BIT_HYPHEN,\n DUO, EMPTY, HEX, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR,\n SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS,\n SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE, SYNTAX_ERR, 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 > BIT_FFFF) {\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 const { message } = e;\n const regEmptyIs = /(:(is|where)\\(\\s*\\))/;\n // workaround for https://github.com/csstree/csstree/issues/265\n const regLang = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]*\")\\s*\\))/;\n if (message === 'Identifier is expected' && regLang.test(selector)) {\n const [, lang, range] = regLang.exec(selector);\n const escapedRange =\n range.replaceAll('*', '\\\\*').replace(/^\"/, '').replace(/\"$/, '');\n let escapedLang = lang.replace(range, escapedRange);\n if (escapedLang === ':lang()') {\n escapedLang = `:lang(${EMPTY})`;\n }\n res = parseSelector(selector.replace(lang, escapedLang));\n } else if ((message === 'Identifier is expected' ||\n message === 'Selector is expected') &&\n regEmptyIs.test(selector)) {\n const [, logic, name] = regEmptyIs.exec(selector);\n const emptyIs = `:${name}(${EMPTY})`;\n res = parseSelector(selector.replace(logic, emptyIs));\n } else if (message === '\"]\" is expected' && !selector.endsWith(']')) {\n res = parseSelector(`${selector}]`);\n } else if (message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(message, SYNTAX_ERR);\n }\n }\n return res;\n};\n\n/**\n * walk AST\n * @param {object} ast - AST\n * @returns {Array.} - 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/**\n * sort AST\n * @param {Array.} asts - collection of AST\n * @returns {Array.} - collection of sorted AST\n */\nexport const sortAST = asts => {\n const arr = [...asts];\n if (arr.length > 1) {\n const order = 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 arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = order.get(typeA);\n const bitB = order.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 * parse AST name - e.g. ns|E -> { prefix: ns, localName: E }\n * @param {string} selector - type selector\n * @returns {object} - node properties\n */\nexport const parseAstName = selector => {\n let prefix;\n let localName;\n if (selector && typeof selector === 'string') {\n if (selector.indexOf('|') > -1) {\n [prefix, localName] = selector.split('|');\n } else {\n prefix = '*';\n localName = selector;\n }\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return {\n prefix,\n localName\n };\n};\n\n/**\n * filter selector (for nwsapi)\n * @param {string} selector - selector\n * @returns {boolean} - result\n */\nexport const filterSelector = selector => {\n if (!selector || typeof selector !== 'string') {\n return false;\n }\n // filter namespaced selectors, e.g. ns|E, pseudo-element selectors and\n // attribute selectors with case flag, e.g. [attr i], and unclosed quotes\n if (/\\||::|\\[\\s*[\\w$*=^|~-]+(?:(?:\"[\\w$*=^|~\\s'-]+\"|'[\\w$*=^|~\\s\"-]+')?(?:\\s+[\\w$*=^|~-]+)+|\"[^\"\\]]{1,255}|'[^'\\]]{1,255})\\s*\\]/.test(selector)) {\n return false;\n }\n // filter pseudo-class selectors\n if (selector.includes(':')) {\n // digit:\n // `(?:0|[1-9]\\d*)`\n // anb:\n // `[+-]?(?:${digit}n?|n)|(?:[+-]?${digit})?n\\s*[+-]\\s*${digit}`\n // type: *, tag\n // `\\*|[A-Za-z][\\w-]*`\n // subclass: attr, id, class, pseudo-class (nst)\n // `\\[[^\\]]+\\]|[#.:][\\w-]+`\n // compound:\n // `(?:${type}|(?:${type})?(?:${subclass})+)`\n // nested logical:\n // `(?:is|not|where)\\(\\s*${compound}(?:\\s*,\\s*${compound})*\\s*\\)`\n // compoundB:\n // `(?:${type}|(?:${type})?(?:${subclass}|:${nestedLogical})+)`\n // nst:\n // `(?:first|last|only)-(?:child|of-type)`\n // nth: exclude An+B with selector list, e.g. :nth-child(2n+1 of .foo)\n // `nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${anb})\\s*\\)`\n // logical: exclude complex selector, e.g. :is(.foo > .bar)\n // `(?:is|not|where)\\(\\s*${compoundB}(?:\\s*,\\s*${compoundB})*\\s*\\)`\n // filter pseudos other than child-indexed and logical combination pseudos\n // `:(?!${nst}|${nth}|${logical})`\n if (/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\\d*)n?|n)|(?:[+-]?(?:0|[1-9]\\d*))?n\\s*[+-]\\s*(?:0|[1-9]\\d*))\\s*\\)|(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+))*\\s*\\))/.test(selector)) {\n return false;\n }\n }\n return true;\n};\n\n/* export */\nexport { generate as generateCSS } from 'css-tree';\n"], + "sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\n\n/* constants */\nimport {\n BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF, BIT_HYPHEN,\n DUO, EMPTY, HEX, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR,\n SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS,\n SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE, SYNTAX_ERR, 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 > BIT_FFFF) {\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 const { message } = e;\n const regEmptyIs = /(:(is|where)\\(\\s*\\))/;\n // workaround for https://github.com/csstree/csstree/issues/265\n const regLang = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]*\")\\s*\\))/;\n if (message === 'Identifier is expected' && regLang.test(selector)) {\n const [, lang, range] = regLang.exec(selector);\n const escapedRange =\n range.replaceAll('*', '\\\\*').replace(/^\"/, '').replace(/\"$/, '');\n let escapedLang = lang.replace(range, escapedRange);\n if (escapedLang === ':lang()') {\n escapedLang = `:lang(${EMPTY})`;\n }\n res = parseSelector(selector.replace(lang, escapedLang));\n } else if ((message === 'Identifier is expected' ||\n message === 'Selector is expected') &&\n regEmptyIs.test(selector)) {\n const [, logic, name] = regEmptyIs.exec(selector);\n const emptyIs = `:${name}(${EMPTY})`;\n res = parseSelector(selector.replace(logic, emptyIs));\n } else if (message === '\"]\" is expected' && !selector.endsWith(']')) {\n res = parseSelector(`${selector}]`);\n } else if (message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(message, SYNTAX_ERR);\n }\n }\n return res;\n};\n\n/**\n * walk AST\n * @param {object} ast - AST\n * @returns {Array.} - 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/**\n * sort AST\n * @param {Array.} asts - collection of AST\n * @returns {Array.} - collection of sorted AST\n */\nexport const sortAST = asts => {\n const arr = [...asts];\n if (arr.length > 1) {\n const order = 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 arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = order.get(typeA);\n const bitB = order.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 * parse AST name - e.g. ns|E -> { prefix: ns, localName: E }\n * @param {string} selector - type selector\n * @returns {object} - node properties\n */\nexport const parseAstName = selector => {\n let prefix;\n let localName;\n if (selector && typeof selector === 'string') {\n if (selector.indexOf('|') > -1) {\n [prefix, localName] = selector.split('|');\n } else {\n prefix = '*';\n localName = selector;\n }\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return {\n prefix,\n localName\n };\n};\n\n/**\n * filter selector (for nwsapi)\n * @param {string} selector - selector\n * @returns {boolean} - result\n */\nexport const filterSelector = selector => {\n if (!selector || typeof selector !== 'string') {\n return false;\n }\n // filter namespaced selectors, e.g. ns|E, pseudo-element selectors and\n // attribute selectors with case flag, e.g. [attr i], and unclosed quotes\n if (/\\||::|\\[\\s*[\\w$*=^|~-]+(?:(?:\"[\\w$*=^|~\\s'-]+\"|'[\\w$*=^|~\\s\"-]+')?(?:\\s+[\\w$*=^|~-]+)+|\"[^\"\\]]{1,255}|'[^'\\]]{1,255})\\s*\\]/.test(selector)) {\n return false;\n }\n // filter pseudo-class selectors\n if (selector.includes(':')) {\n // digit:\n // `(?:0|[1-9]\\d*)`\n // anb:\n // `[+-]?(?:${digit}n?|n)|(?:[+-]?${digit})?n\\s*[+-]\\s*${digit}`\n // type: *, tag\n // `\\*|[A-Za-z][\\w-]*`\n // subclass: attr, id, class, pseudo-class (nst)\n // `\\[[^\\]]+\\]|[#.:][\\w-]+`\n // compound:\n // `(?:${type}|(?:${type})?(?:${subclass})+)`\n // nested logical:\n // `:(?:is|not|where)\\(\\s*${compound}(?:\\s*,\\s*${compound})*\\s*\\)`\n // compoundB:\n // `(?:${type}|(?:${type})?(?:${subclass}|${nestedLogical})+)`\n // nst:\n // `(?:first|last|only)-(?:child|of-type)`\n // nth: exclude An+B with selector list, e.g. :nth-child(2n+1 of .foo)\n // `nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${anb})\\s*\\)`\n // logical: exclude complex selector, e.g. :is(.foo > .bar)\n // `(?:is|not|where)\\(\\s*${compoundB}(?:\\s*,\\s*${compoundB})*\\s*\\)`\n // filter pseudos other than child-indexed and logical combination pseudos\n // `:(?!${nst}|${nth}|${logical})`\n if (/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\\d*)n?|n)|(?:[+-]?(?:0|[1-9]\\d*))?n\\s*[+-]\\s*(?:0|[1-9]\\d*))\\s*\\)|(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+|:(?:is|not|where)\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+))*\\s*\\))/.test(selector)) {\n return false;\n }\n }\n return true;\n};\n\n/* export */\nexport { generate as generateCSS } from 'css-tree';\n"], "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,4CAAAC,EAAA,kBAAAC,EAAA,eAAAC,EAAA,YAAAC,EAAA,qBAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAT,GAKA,IAAAU,EAAoD,oBAGpDC,EAKO,yBAmUPD,EAAwC,oBA5Tj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G6B,EAAOC,EAChB9B,EAAM,EAENA,EAAM,GAEDA,CACT,CAAC,CACH,CACA,OAAOf,CACT,EAOaV,EAAeS,GAAY,CACtC,IAAI+C,EACAC,EACJ,GAAIhD,GAAY,OAAOA,GAAa,SAC9BA,EAAS,QAAQ,GAAG,EAAI,GAC1B,CAAC+C,EAAQC,CAAS,EAAIhD,EAAS,MAAM,GAAG,GAExC+C,EAAS,IACTC,EAAYhD,OAGd,OAAM,IAAI,aAAa,oBAAoBA,CAAQ,GAAI,YAAU,EAEnE,MAAO,CACL,OAAA+C,EACA,UAAAC,CACF,CACF,EAOa1D,EAAiBU,GACxB,GAACA,GAAY,OAAOA,GAAa,UAKjC,6HAA6H,KAAKA,CAAQ,GAI1IA,EAAS,SAAS,GAAG,GAuBnB,ktBAAktB,KAAKA,CAAQ", "names": ["parser_exports", "__export", "filterSelector", "parseAstName", "parseSelector", "preprocess", "sortAST", "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", "message", "regEmptyIs", "regLang", "lang", "range", "escapedRange", "escapedLang", "logic", "name", "emptyIs", "branches", "hasPseudoFunc", "node", "list", "itemList", "i", "type", "children", "grandChildren", "greatGrandChildren", "asts", "order", "a", "b", "typeA", "typeB", "bitA", "bitB", "prefix", "localName"] } diff --git a/package.json b/package.json index 67a217c7..24ec2e17 100644 --- a/package.json +++ b/package.json @@ -39,14 +39,14 @@ "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.29.1", "eslint-plugin-jsdoc": "^48.2.1", - "eslint-plugin-regexp": "^2.3.0", + "eslint-plugin-regexp": "^2.4.0", "eslint-plugin-unicorn": "^51.0.1", - "happy-dom": "^13.8.6", + "happy-dom": "^14.3.8", "jsdom": "^24.0.0", - "linkedom": "^0.16.10", + "linkedom": "^0.16.11", "mocha": "^10.3.0", "sinon": "^17.0.1", - "typescript": "^5.4.2", + "typescript": "^5.4.3", "wpt-runner": "^5.0.0" }, "scripts": { @@ -60,5 +60,5 @@ "tsc": "node scripts/index clean --dir=types -i && npx tsc", "update-wpt": "git submodule update --init --recursive --remote" }, - "version": "4.1.7" + "version": "4.2.0" }