diff --git a/dist/cjs/js/finder.js b/dist/cjs/js/finder.js index df86ed03..d086bbe1 100644 --- a/dist/cjs/js/finder.js +++ b/dist/cjs/js/finder.js @@ -1,2 +1,2 @@ -var W=Object.create;var P=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(E,a)=>{for(var e in a)P(E,e,{get:a[e],enumerable:!0})},z=(E,a,e,n)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of B(a))!G.call(E,l)&&l!==e&&P(E,l,{get:()=>a[l],enumerable:!(n=H(a,l))||n.enumerable});return E};var I=(E,a,e)=>(e=E!=null?W(j(E)):{},z(a||!E||!E.__esModule?P(e,"default",{value:E,enumerable:!0}):e,E)),V=E=>z(P({},"__esModule",{value:!0}),E);var Y={};q(Y,{Finder:()=>X});module.exports=V(Y);var U=I(require("is-potential-custom-element-name"),1),F=I(require("nwsapi"),1),C=require("./dom-util.js"),$=I(require("./matcher.js"),1),y=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",A="first",R="lineal",D="self";class X{#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,n={}){const{noexcept:l,warn:s}=n;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 n;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${a}`)){const s=l.get(`${a}`);this.#o=s.descendant,n=s.ast}}if(n){const l=n.length;for(let s=0;s]$/.test(m)&&(c=!0),f.push({combo:t,leaves:(0,y.sortAST)(i)}),i.clear()}else if(t){let{name:o}=t;o&&typeof o=="string"&&(o=(0,y.unescapeSelector)(o),typeof o=="string"&&o!==t.name&&(t.name=o),/[|:]/.test(o)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{f.push({combo:null,leaves:(0,y.sortAST)(i)}),i.clear();break}}}n.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[r]=[],r++}if(this.#t){let d;this.#l.has(this.#t)?d=this.#l.get(this.#t):d=new Map,d.set(`${a}`,{ast:n,descendant:c}),this.#l.set(this.#t,d)}this.#o=c}return[n,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 n=e.currentNode,l;if(n===a)l=n;else if(n.contains(a))for(n=e.nextNode();n;){if(n===a){l=n;break}n=e.nextNode()}else{if(n!==e.root)for(;n&&!(n===e.root||n===a);)n=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;n;){if(n===a){l=n;break}n=e.nextNode()}else l=n}return l??null}_collectNthChild(a,e,n){const{a:l,b:s,reverse:c,selector:r}=a,{parentNode:d}=e,f=new Set;let t;if(r&&(this.#l.has(r)?t=this.#l.get(r):(t=(0,y.walkAST)(r),this.#l.set(r,t))),d){const i=this.#r;let o=this._traverse(d,i);o=i.firstChild();let m=0;for(;o;)m++,o=i.nextSibling();o=this._traverse(d,i);const _=new Set;if(t)for(o=i.firstChild();o;){let u;for(const N of t)if(u=this._matchLeaves(N,o,n),!u)break;u&&_.add(o),o=i.nextSibling()}if(l===0){if(s>0&&s<=m){if(_.size){o=this._traverse(d,i),c?o=i.lastChild():o=i.firstChild();let u=0;for(;o;){if(_.has(o)){if(u===s-1){f.add(o);break}u++}c?o=i.previousSibling():o=i.nextSibling()}}else if(!r){o=this._traverse(d,i),c?o=i.lastChild():o=i.firstChild();let u=0;for(;o;){if(u===s-1){f.add(o);break}c?o=i.previousSibling():o=i.nextSibling(),u++}}}}else{let u=s-1;if(l>0)for(;u<0;)u+=l;if(u>=0&&u0?0:s-1;for(;o&&(o&&u>=0&&u0?k++:k--):N===u&&(r||f.add(o),u+=l),c?o=i.previousSibling():o=i.nextSibling(),N++}}if(c&&f.size>1){const u=[...f];return new Set(u.reverse())}}else if(e===this.#s&&l+s===1)if(t){let i;for(const o of t)if(i=this._matchLeaves(o,e,n),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:n,b:l,reverse:s}=a,{localName:c,parentNode:r,prefix:d}=e,f=new Set;if(r){const t=this.#r;let i=this._traverse(r,t);i=t.firstChild();let o=0;for(;i;)o++,i=t.nextSibling();if(n===0){if(l>0&&l<=o){i=this._traverse(r,t),s?i=t.lastChild():i=t.firstChild();let m=0;for(;i;){const{localName:_,prefix:u}=i;if(_===c&&u===d){if(m===l-1){f.add(i);break}m++}s?i=t.previousSibling():i=t.nextSibling()}}}else{let m=l-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m0?0:l-1;for(;i;){const{localName:u,prefix:N}=i;if(u===c&&N===d){if(_===m&&(f.add(i),m+=n),m<0||m>=o)break;n>0?_++:_--}s?i=t.previousSibling():i=t.nextSibling()}}}if(s&&f.size>1){const m=[...f];return new Set(m.reverse())}}else e===this.#s&&n+l===1&&f.add(e);return f}_matchAnPlusB(a,e,n,l){const{nth:{a:s,b:c,name:r},selector:d}=a,f=new Map;if(r?(r==="even"?(f.set("a",2),f.set("b",0)):r==="odd"&&(f.set("a",2),f.set("b",1)),n.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof c=="string"&&/-?\d+/.test(c)?f.set("b",c*1):f.set("b",0),n.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(n)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(n)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,n={}){let l;if(Array.isArray(a)&&a.length){const[s]=a,{type:c}=s;let r;c===b.COMBINATOR?r=a.shift():r={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[i]=a,{type:o}=i;if(o===b.COMBINATOR)break;d.push(a.shift())}const f={combo:r,leaves:d};n.dir=T;const t=this._matchCombinator(f,e,n);if(t.size)if(a.length){for(const i of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),i,n),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,n={}){const{astName:l="",branches:s=[],selector:c="",twigBranches:r=[]}=a;let d;if(l==="has")if(c.includes(":has("))d=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,n),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);n.forgive=f;const t=r.length;let i;for(let o=0;o0){let N=new Set([e]);for(let k=_-1;k>=0;k--){const g=m[k],h=[];n.dir=O;for(const p of N){const w=this._matchCombinator(g,p,n);w.size&&h.push(...w)}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,n={}){const{children:l,name:s}=a,{localName:c,parentNode:r}=e,{forgive:d,warn:f=this.#i}=n,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let i;if(this.#l.has(a))i=this.#l.get(a);else{const m=(0,y.walkAST)(a),_=[],u=[];for(const[...N]of m){for(const p of N){const w=(0,y.generateCSS)(p);_.push(w)}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}u.push(k)}i={astName:s,branches:m,twigBranches:u,selector:_.join(",")},this.#l.set(a,i)}const o=this._matchLogicalPseudoFunc(i,e,n);o&&t.add(o)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[i]=l;return this._matchAnPlusB(i,e,s,n)}else switch(s){case"dir":case"lang":{const i=$.default.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)?$/,o=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,m=/^(?:(?:inpu|selec)t|button|form|textarea)$/,_=/^d(?:etails|ialog)$/,u=/^(?: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(c)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(c)&&e.hasAttribute("href")){const{href:h,origin:p,pathname:w}=new URL(this.#t.URL),S=new URL(e.getAttribute("href"),h);S.origin===p&&S.pathname===w&&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 w=this.#t.getElementById(p);for(;w;){if(w===e){t.add(e);break}w=w.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:w,visibility:S}=h.style;if(p=!(w==="none"||S==="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 w=e,S=!0;for(;w;){if(w.disabled||w.hasAttribute("disabled")||w.hidden||w.hasAttribute("hidden")){S=!1;break}else if(w.hasAttribute("style")){const{display:v,visibility:L}=w.style;if(S=!(v==="none"||L==="hidden"),!S)break}if(w.parentNode&&w.parentNode.nodeType===b.ELEMENT_NODE)w=w.parentNode;else break}S&&t.add(e)}break}case"open":{_.test(c)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(c)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(o.test(c)||(0,U.default)(c))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=r;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&r.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(o.test(c)||(0,U.default)(c))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(c){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(c){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;c==="textarea"?h=e:c==="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&&c==="input"&&e.hasAttribute("type")&&u.test(e.getAttribute("type"))||e.selected&&c==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&c==="input"&&e.type==="checkbox"||c==="progress"&&!e.hasAttribute("value"))t.add(e);else if(c==="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 w=p.getElementsByTagName("input"),S=w.length;let v;for(let L=0;L0,{type:r}=l,d=(0,y.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(r){case b.SELECTOR_PSEUDO_ELEMENT:{$.default.matchPseudoElementSelector(d,n);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)&&(c?this._matchLeaves(s,i,n)&&f.add(i):f.add(i))}break}case b.SELECTOR_CLASS:{const i=e.getElementsByClassName(d);f=this._matchHTMLCollection(i,{compound:c,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:c,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,n={}){const{combo:l,leaves:s}=a,{name:c}=l,{parentNode:r}=e,{dir:d}=n,f=new Set;if(d===T)switch(c){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,n)&&f.add(t);break}case"~":{if(r){const t=this._createTreeWalker(r);let i=this._traverse(e,t);for(i=t.nextSibling();i;)this._matchLeaves(s,i,n)&&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,n)&&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 o=this._createTreeWalker(e);let m=this._traverse(e,o);for(m=o.nextNode();m&&e.contains(m);)this._matchLeaves(s,m,n)&&f.add(m),m=o.nextNode()}}}else switch(c){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,n)&&f.add(t);break}case"~":{if(r){const t=this._createTreeWalker(r);let i=this._traverse(r,t);for(i=t.firstChild();i&&i!==e;)this._matchLeaves(s,i,n)&&f.add(i),i=t.nextSibling()}break}case">":{r&&this._matchLeaves(s,r,n)&&f.add(r);break}case" ":default:{const t=[];let i=r;for(;i;)this._matchLeaves(s,i,n)&&t.push(i),i=i.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:n}=e;let l=this._traverse(n,this.#n),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#n.nextNode():l===n&&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=[],n=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return n&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:n}=e,l=[];let s=this._matchLeaves(a,this.#e,{warn:this.#i}),c=!1;if(s&&(l.push(this.#e),c=!0),!s||n){let r=this.#e.parentNode;for(;r&&(s=this._matchLeaves(a,r,{warn:this.#i}),s&&(l.push(r),c=!0),r.parentNode);)r=r.parentNode}return[l,c]}_findFirst(a){const e=[],n=this._findNode(a,{node:this.#e});let l=!1;return n&&(e.push(n),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:n,compound:l,filterLeaves:s,targetType:c}=e;let r=[],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,o=!1,m=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.default.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(e===A&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(r?this._matchLeaves(c,_,{warn:this.#i})&&(t.push(_),o=!0):(t.push(_),o=!0))}else e===A?[t,o]=this._findFirst(l):m=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,o,i]=this._findFromHTMLCollection(_,{complex:n,compound:r,filterLeaves:c,targetType:e}))}else e===A?[t,o]=this._findFirst(l):m=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,o,i]=this._findFromHTMLCollection(_,{complex:n,compound:r,filterLeaves:c,targetType:e}))}else e===A?[t,o]=this._findFirst(l):m=!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(_),o=!0)}}else e===D?[t,o]=this._matchSelf(l):e===R?[t,o]=this._findLineal(l,{complex:n}):e===A?[t,o]=this._findFirst(l):m=!0}return{collected:i,compound:r,filtered:o,nodes:t,pending:m}}_getEntryTwig(a,e){const n=a.length,l=n>1,s=a[0];let c,r;if(l){const{combo:d,leaves:[{name:f,type:t}]}=s,i=a[n-1],{leaves:[{name:o,type:m}]}=i;if(m===b.SELECTOR_PSEUDO_ELEMENT||m===b.SELECTOR_ID)c=O,r=i;else if(t===b.SELECTOR_PSEUDO_ELEMENT||t===b.SELECTOR_ID)c=T,r=s;else if(e===M)if(f==="*"&&t===b.SELECTOR_TYPE)c=O,r=i;else if(o==="*"&&m===b.SELECTOR_TYPE)c=T,r=s;else if(n===2){const{name:_}=d;/^[+~]$/.test(_)?(c=O,r=i):(c=T,r=s)}else c=T,r=s;else if(o==="*"&&m===b.SELECTOR_TYPE)c=T,r=s;else if(f==="*"&&t===b.SELECTOR_TYPE)c=O,r=i;else{let _;for(const{combo:u,leaves:[N]}of a){const{name:k,type:g}=N;if(g===b.SELECTOR_PSEUDO_CLASS&&k==="dir"){_=!1;break}if(!_&&u){const{name:h}=u;/^[+~]$/.test(h)&&(_=!0)}}_?(c=T,r=s):(c=O,r=i)}}else c=O,r=s;return{complex:l,dir:c,twig:r}}_collectNodes(a){const e=this.#a.values();if(a===M||a===A){const n=new Set;let l=0;for(const{branch:s}of e){const{complex:c,dir:r,twig:d}=this._getEntryTwig(s,a),{collected:f,compound:t,filtered:i,nodes:o,pending:m}=this._findEntryNodes(d,a,c);o.length?(this.#a[l].find=!0,this.#h[l]=o):m&&n.add(new Map([["index",l],["twig",d]])),this.#a[l].collected=f,this.#a[l].dir=r,this.#a[l].filtered=i||!t,l++}if(n.size){let s,c;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,c=this.#n):(s=this.#s,c=this.#r);let r=this._traverse(s,c);for(;r;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?r===this.#e?d=!0:d=this.#e.contains(r):d=!0,d)for(const f of n){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,r,{warn:this.#i})){const o=f.get("index");this.#a[o].filtered=!0,this.#a[o].find=!0,this.#h[o].push(r)}}r!==c.currentNode&&(r=this._traverse(r,c)),r=c.nextNode()}}}else{let n=0;for(const{branch:l}of e){const s=l[l.length-1],c=l.length>1,{compound:r,filtered:d,nodes:f}=this._findEntryNodes(s,a,c);f.length&&(this.#a[n].find=!0,this.#h[n]=f),this.#a[n].dir=O,this.#a[n].filtered=d||!r,n++}}return[this.#a,this.#h]}_getCombinedNodes(a,e,n){const l=[];for(const s of e){const c=this._matchCombinator(a,s,{dir:n,warn:this.#i});c.size&&l.push(...c)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,n){const{combo:l,index:s}=n,{combo:c,leaves:r}=a[s],d={combo:l,leaves:r},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:c,index:s+1});return t??null}_matchNodePrev(a,e,n){const{index:l}=n,s=a[l],c=new Set([e]),r=this._getCombinedNodes(s,c,O);let d;if(r.size){if(l===0)d=e;else for(const f of r)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_matchNodes(a){const[[...e],n]=this._collectNodes(a),l=e.length;let s=new Set;for(let c=0;c=0;k--){const g=r[k];if(N=this._getCombinedNodes(g,N,f),N.size)k===0&&(s.add(u),i>1&&s.size>1&&(this.#b=!0));else break}}else if(a===A&&f===T){const{combo:u}=r[0];let N;for(const k of o)if(N=this._matchNodeNext(r,new Set([k]),{combo:u,index:1}),N){s.add(N);break}if(!N&&!d){const{leaves:k}=r[0],[g]=o;let h=this._findNode(k,{node:g});for(;h;){if(N=this._matchNodeNext(r,new Set([h]),{combo:u,index:1}),N){s.add(N);break}h=this._findNode(k,{node:h})}}}else{let u;for(const N of o)if(u=this._matchNodePrev(r,N,{index:_-1}),u){s.add(N);break}if(!u&&!d&&a===A){const{leaves:N}=r[_],[k]=o;let g=this._findNode(N,{node:k});for(;g;){if(u=this._matchNodePrev(r,g,{index:_-1}),u){s.add(g);break}g=this._findNode(N,{node:g})}}}}}return s}_find(a){return(a===M||a===A)&&this._prepareQuerySelectorWalker(),this._matchNodes(a)}matches(a,e,n){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,y.filterSelector)(a)?l=this.#c.match(a,e):(this._setup(a,e,n),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(a,e,n){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,y.filterSelector)(a))l=this.#c.closest(a,e);else{this._setup(a,e,n);const s=this._find(R);if(s.size){let c=this.#e;for(;c;){if(s.has(c)){l=c;break}c=c.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(a,e,n){let l;try{if(this._setup(a,e,n),this.#f===this.#t&&!this.#o&&(0,y.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,n){let l;try{if(this._setup(a,e,n),this.#f===this.#t&&!this.#o&&(0,y.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 W=Object.create;var P=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(E,a)=>{for(var e in a)P(E,e,{get:a[e],enumerable:!0})},U=(E,a,e,n)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of B(a))!G.call(E,l)&&l!==e&&P(E,l,{get:()=>a[l],enumerable:!(n=H(a,l))||n.enumerable});return E};var z=(E,a,e)=>(e=E!=null?W(j(E)):{},U(a||!E||!E.__esModule?P(e,"default",{value:E,enumerable:!0}):e,E)),V=E=>U(P({},"__esModule",{value:!0}),E);var Y={};q(Y,{Finder:()=>X});module.exports=V(Y);var I=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),y=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",A="first",R="lineal",D="self";class X{#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,n={}){const{noexcept:l,warn:s}=n;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 n;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${a}`)){const s=l.get(`${a}`);this.#o=s.descendant,n=s.ast}}if(n){const l=n.length;for(let s=0;s]$/.test(m)&&(c=!0),f.push({combo:t,leaves:(0,y.sortAST)(i)}),i.clear()}else if(t){let{name:o}=t;o&&typeof o=="string"&&(o=(0,y.unescapeSelector)(o),typeof o=="string"&&o!==t.name&&(t.name=o),/[|:]/.test(o)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{f.push({combo:null,leaves:(0,y.sortAST)(i)}),i.clear();break}}}n.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[r]=[],r++}if(this.#t){let d;this.#l.has(this.#t)?d=this.#l.get(this.#t):d=new Map,d.set(`${a}`,{ast:n,descendant:c}),this.#l.set(this.#t,d)}this.#o=c}return[n,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 n=e.currentNode,l;if(n===a)l=n;else if(n.contains(a))for(n=e.nextNode();n;){if(n===a){l=n;break}n=e.nextNode()}else{if(n!==e.root)for(;n&&!(n===e.root||n===a);)n=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;n;){if(n===a){l=n;break}n=e.nextNode()}else l=n}return l??null}_collectNthChild(a,e,n){const{a:l,b:s,reverse:c,selector:r}=a,{parentNode:d}=e,f=new Set;let t;if(r&&(this.#l.has(r)?t=this.#l.get(r):(t=(0,y.walkAST)(r),this.#l.set(r,t))),d){const i=this.#r;let o=this._traverse(d,i);o=i.firstChild();let m=0;for(;o;)m++,o=i.nextSibling();o=this._traverse(d,i);const _=new Set;if(t)for(o=i.firstChild();o;){let u;for(const N of t)if(u=this._matchLeaves(N,o,n),!u)break;u&&_.add(o),o=i.nextSibling()}if(l===0){if(s>0&&s<=m){if(_.size){o=this._traverse(d,i),c?o=i.lastChild():o=i.firstChild();let u=0;for(;o;){if(_.has(o)){if(u===s-1){f.add(o);break}u++}c?o=i.previousSibling():o=i.nextSibling()}}else if(!r){o=this._traverse(d,i),c?o=i.lastChild():o=i.firstChild();let u=0;for(;o;){if(u===s-1){f.add(o);break}c?o=i.previousSibling():o=i.nextSibling(),u++}}}}else{let u=s-1;if(l>0)for(;u<0;)u+=l;if(u>=0&&u0?0:s-1;for(;o&&(o&&u>=0&&u0?k++:k--):N===u&&(r||f.add(o),u+=l),c?o=i.previousSibling():o=i.nextSibling(),N++}}if(c&&f.size>1){const u=[...f];return new Set(u.reverse())}}else if(e===this.#s&&l+s===1)if(t){let i;for(const o of t)if(i=this._matchLeaves(o,e,n),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:n,b:l,reverse:s}=a,{localName:c,parentNode:r,prefix:d}=e,f=new Set;if(r){const t=this.#r;let i=this._traverse(r,t);i=t.firstChild();let o=0;for(;i;)o++,i=t.nextSibling();if(n===0){if(l>0&&l<=o){i=this._traverse(r,t),s?i=t.lastChild():i=t.firstChild();let m=0;for(;i;){const{localName:_,prefix:u}=i;if(_===c&&u===d){if(m===l-1){f.add(i);break}m++}s?i=t.previousSibling():i=t.nextSibling()}}}else{let m=l-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m0?0:l-1;for(;i;){const{localName:u,prefix:N}=i;if(u===c&&N===d){if(_===m&&(f.add(i),m+=n),m<0||m>=o)break;n>0?_++:_--}s?i=t.previousSibling():i=t.nextSibling()}}}if(s&&f.size>1){const m=[...f];return new Set(m.reverse())}}else e===this.#s&&n+l===1&&f.add(e);return f}_matchAnPlusB(a,e,n,l){const{nth:{a:s,b:c,name:r},selector:d}=a,f=new Map;if(r?(r==="even"?(f.set("a",2),f.set("b",0)):r==="odd"&&(f.set("a",2),f.set("b",1)),n.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof c=="string"&&/-?\d+/.test(c)?f.set("b",c*1):f.set("b",0),n.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(n)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(n)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,n={}){let l;if(Array.isArray(a)&&a.length){const[s]=a,{type:c}=s;let r;c===b.COMBINATOR?r=a.shift():r={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[i]=a,{type:o}=i;if(o===b.COMBINATOR)break;d.push(a.shift())}const f={combo:r,leaves:d};n.dir=T;const t=this._matchCombinator(f,e,n);if(t.size)if(a.length){for(const i of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),i,n),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,n={}){const{astName:l="",branches:s=[],selector:c="",twigBranches:r=[]}=a;let d;if(l==="has")if(c.includes(":has("))d=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,n),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);n.forgive=f;const t=r.length;let i;for(let o=0;o0){let N=new Set([e]);for(let k=_-1;k>=0;k--){const g=m[k],h=[];n.dir=O;for(const p of N){const w=this._matchCombinator(g,p,n);w.size&&h.push(...w)}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,n={}){const{children:l,name:s}=a,{localName:c,parentNode:r}=e,{forgive:d,warn:f=this.#i}=n,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let i;if(this.#l.has(a))i=this.#l.get(a);else{const m=(0,y.walkAST)(a),_=[],u=[];for(const[...N]of m){for(const p of N){const w=(0,y.generateCSS)(p);_.push(w)}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}u.push(k)}i={astName:s,branches:m,twigBranches:u,selector:_.join(",")},this.#l.set(a,i)}const o=this._matchLogicalPseudoFunc(i,e,n);o&&t.add(o)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[i]=l;return this._matchAnPlusB(i,e,s,n)}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)?$/,o=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,m=/^(?:(?:inpu|selec)t|button|form|textarea)$/,_=/^d(?:etails|ialog)$/,u=/^(?: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(c)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(c)&&e.hasAttribute("href")){const{href:h,origin:p,pathname:w}=new URL(this.#t.URL),S=new URL(e.getAttribute("href"),h);S.origin===p&&S.pathname===w&&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 w=this.#t.getElementById(p);for(;w;){if(w===e){t.add(e);break}w=w.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:w,visibility:S}=h.style;if(p=!(w==="none"||S==="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 w=e,S=!0;for(;w;){if(w.disabled||w.hasAttribute("disabled")||w.hidden||w.hasAttribute("hidden")){S=!1;break}else if(w.hasAttribute("style")){const{display:v,visibility:L}=w.style;if(S=!(v==="none"||L==="hidden"),!S)break}if(w.parentNode&&w.parentNode.nodeType===b.ELEMENT_NODE)w=w.parentNode;else break}S&&t.add(e)}break}case"open":{_.test(c)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(c)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(o.test(c)||(0,I.default)(c))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=r;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&r.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(o.test(c)||(0,I.default)(c))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(c){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(c){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;c==="textarea"?h=e:c==="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&&c==="input"&&e.hasAttribute("type")&&u.test(e.getAttribute("type"))||e.selected&&c==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&c==="input"&&e.type==="checkbox"||c==="progress"&&!e.hasAttribute("value"))t.add(e);else if(c==="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 w=p.getElementsByTagName("input"),S=w.length;let v;for(let L=0;L0,{type:r}=l,d=(0,y.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(r){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,n);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)&&(c?this._matchLeaves(s,i,n)&&f.add(i):f.add(i))}break}case b.SELECTOR_CLASS:{const i=e.getElementsByClassName(d);f=this._matchHTMLCollection(i,{compound:c,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:c,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,n={}){const{combo:l,leaves:s}=a,{name:c}=l,{parentNode:r}=e,{dir:d}=n,f=new Set;if(d===T)switch(c){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,n)&&f.add(t);break}case"~":{if(r){const t=this._createTreeWalker(r);let i=this._traverse(e,t);for(i=t.nextSibling();i;)this._matchLeaves(s,i,n)&&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,n)&&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 o=this._createTreeWalker(e);let m=this._traverse(e,o);for(m=o.nextNode();m&&e.contains(m);)this._matchLeaves(s,m,n)&&f.add(m),m=o.nextNode()}}}else switch(c){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,n)&&f.add(t);break}case"~":{if(r){const t=this._createTreeWalker(r);let i=this._traverse(r,t);for(i=t.firstChild();i&&i!==e;)this._matchLeaves(s,i,n)&&f.add(i),i=t.nextSibling()}break}case">":{r&&this._matchLeaves(s,r,n)&&f.add(r);break}case" ":default:{const t=[];let i=r;for(;i;)this._matchLeaves(s,i,n)&&t.push(i),i=i.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:n}=e;let l=this._traverse(n,this.#n),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#n.nextNode():l===n&&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=[],n=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return n&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:n}=e,l=[];let s=this._matchLeaves(a,this.#e,{warn:this.#i}),c=!1;if(s&&(l.push(this.#e),c=!0),!s||n){let r=this.#e.parentNode;for(;r&&(s=this._matchLeaves(a,r,{warn:this.#i}),s&&(l.push(r),c=!0),r.parentNode);)r=r.parentNode}return[l,c]}_findFirst(a){const e=[],n=this._findNode(a,{node:this.#e});let l=!1;return n&&(e.push(n),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:n,compound:l,filterLeaves:s,targetType:c}=e;let r=[],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,o=!1,m=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(e===A&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(r?this._matchLeaves(c,_,{warn:this.#i})&&(t.push(_),o=!0):(t.push(_),o=!0))}else e===A?[t,o]=this._findFirst(l):m=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,o,i]=this._findFromHTMLCollection(_,{complex:n,compound:r,filterLeaves:c,targetType:e}))}else e===A?[t,o]=this._findFirst(l):m=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,o,i]=this._findFromHTMLCollection(_,{complex:n,compound:r,filterLeaves:c,targetType:e}))}else e===A?[t,o]=this._findFirst(l):m=!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(_),o=!0)}}else e===D?[t,o]=this._matchSelf(l):e===R?[t,o]=this._findLineal(l,{complex:n}):e===A?[t,o]=this._findFirst(l):m=!0}return{collected:i,compound:r,filtered:o,nodes:t,pending:m}}_getEntryTwig(a,e){const n=a.length,l=n>1,s=a[0];let c,r;if(l){const{combo:d,leaves:[{name:f,type:t}]}=s,i=a[n-1],{leaves:[{name:o,type:m}]}=i;if(m===b.SELECTOR_PSEUDO_ELEMENT||m===b.SELECTOR_ID)c=O,r=i;else if(t===b.SELECTOR_PSEUDO_ELEMENT||t===b.SELECTOR_ID)c=T,r=s;else if(e===M)if(f==="*"&&t===b.SELECTOR_TYPE)c=O,r=i;else if(o==="*"&&m===b.SELECTOR_TYPE)c=T,r=s;else if(n===2){const{name:_}=d;/^[+~]$/.test(_)?(c=O,r=i):(c=T,r=s)}else c=T,r=s;else if(o==="*"&&m===b.SELECTOR_TYPE)c=T,r=s;else if(f==="*"&&t===b.SELECTOR_TYPE)c=O,r=i;else{let _;for(const{combo:u,leaves:[N]}of a){const{name:k,type:g}=N;if(g===b.SELECTOR_PSEUDO_CLASS&&k==="dir"){_=!1;break}if(!_&&u){const{name:h}=u;/^[+~]$/.test(h)&&(_=!0)}}_?(c=T,r=s):(c=O,r=i)}}else c=O,r=s;return{complex:l,dir:c,twig:r}}_collectNodes(a){const e=this.#a.values();if(a===M||a===A){const n=new Set;let l=0;for(const{branch:s}of e){const{complex:c,dir:r,twig:d}=this._getEntryTwig(s,a),{collected:f,compound:t,filtered:i,nodes:o,pending:m}=this._findEntryNodes(d,a,c);o.length?(this.#a[l].find=!0,this.#h[l]=o):m&&n.add(new Map([["index",l],["twig",d]])),this.#a[l].collected=f,this.#a[l].dir=r,this.#a[l].filtered=i||!t,l++}if(n.size){let s,c;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,c=this.#n):(s=this.#s,c=this.#r);let r=this._traverse(s,c);for(;r;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?r===this.#e?d=!0:d=this.#e.contains(r):d=!0,d)for(const f of n){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,r,{warn:this.#i})){const o=f.get("index");this.#a[o].filtered=!0,this.#a[o].find=!0,this.#h[o].push(r)}}r!==c.currentNode&&(r=this._traverse(r,c)),r=c.nextNode()}}}else{let n=0;for(const{branch:l}of e){const s=l[l.length-1],c=l.length>1,{compound:r,filtered:d,nodes:f}=this._findEntryNodes(s,a,c);f.length&&(this.#a[n].find=!0,this.#h[n]=f),this.#a[n].dir=O,this.#a[n].filtered=d||!r,n++}}return[this.#a,this.#h]}_getCombinedNodes(a,e,n){const l=[];for(const s of e){const c=this._matchCombinator(a,s,{dir:n,warn:this.#i});c.size&&l.push(...c)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,n){const{combo:l,index:s}=n,{combo:c,leaves:r}=a[s],d={combo:l,leaves:r},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:c,index:s+1});return t??null}_matchNodePrev(a,e,n){const{index:l}=n,s=a[l],c=new Set([e]),r=this._getCombinedNodes(s,c,O);let d;if(r.size){if(l===0)d=e;else for(const f of r)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_matchNodes(a){const[[...e],n]=this._collectNodes(a),l=e.length;let s=new Set;for(let c=0;c=0;k--){const g=r[k];if(N=this._getCombinedNodes(g,N,f),N.size)k===0&&(s.add(u),i>1&&s.size>1&&(this.#b=!0));else break}}else if(a===A&&f===T){const{combo:u}=r[0];let N;for(const k of o)if(N=this._matchNodeNext(r,new Set([k]),{combo:u,index:1}),N){s.add(N);break}if(!N&&!d){const{leaves:k}=r[0],[g]=o;let h=this._findNode(k,{node:g});for(;h;){if(N=this._matchNodeNext(r,new Set([h]),{combo:u,index:1}),N){s.add(N);break}h=this._findNode(k,{node:h})}}}else{let u;for(const N of o)if(u=this._matchNodePrev(r,N,{index:_-1}),u){s.add(N);break}if(!u&&!d&&a===A){const{leaves:N}=r[_],[k]=o;let g=this._findNode(N,{node:k});for(;g;){if(u=this._matchNodePrev(r,g,{index:_-1}),u){s.add(g);break}g=this._findNode(N,{node:g})}}}}}return s}_find(a){return(a===M||a===A)&&this._prepareQuerySelectorWalker(),this._matchNodes(a)}matches(a,e,n){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,y.filterSelector)(a)?l=this.#c.match(a,e):(this._setup(a,e,n),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(a,e,n){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,y.filterSelector)(a))l=this.#c.closest(a,e);else{this._setup(a,e,n);const s=this._find(R);if(s.size){let c=this.#e;for(;c;){if(s.has(c)){l=c;break}c=c.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(a,e,n){let l;try{if(this._setup(a,e,n),this.#f===this.#t&&!this.#o&&(0,y.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,n){let l;try{if(this._setup(a,e,n),this.#f===this.#t&&!this.#o&&(0,y.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}); //# sourceMappingURL=finder.js.map diff --git a/dist/cjs/js/finder.js.map b/dist/cjs/js/finder.js.map index cc9530d6..c2525dbb 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 * get entry twig\n * @private\n * @param {Array.} branch - AST branch\n * @param {string} targetType - target type\n * @returns {object} - direction and twig\n */\n _getEntryTwig(branch, targetType) {\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 || 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 return {\n complex,\n dir,\n twig\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 { complex, dir, twig } = this._getEntryTwig(branch, targetType);\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 * match nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.} - collection of matched nodes\n */\n _matchNodes(targetType) {\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 * 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 nodes = this._matchNodes(targetType);\n return nodes;\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,EAAoB,6BACpBC,EAEO,uBAGPC,EAKO,yBACP,MAAMC,EAAW,OACXC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AK,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", "m", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "anbMap", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "astName", "twigBranches", "res", "forgive", "lastIndex", "nextNodes", "arr", "astChildren", "selectors", "css", "leavesSet", "matcher", "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", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "pendingItems", "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 '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 * get entry twig\n * @private\n * @param {Array.} branch - AST branch\n * @param {string} targetType - target type\n * @returns {object} - direction and twig\n */\n _getEntryTwig(branch, targetType) {\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 || 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 return {\n complex,\n dir,\n twig\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 { complex, dir, twig } = this._getEntryTwig(branch, targetType);\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 * match nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.} - collection of matched nodes\n */\n _matchNodes(targetType) {\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 * 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 nodes = this._matchNodes(targetType);\n return nodes;\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,EACf,KAAKd,GAAYc,EAAO,SACxB,KAAKjB,GAAS,IAAI,QAClB,KAAKS,GAAW,IAAI,QACpB,KAAKF,MAAU,EAAAW,SAAO,CACpB,SAAUD,EAAO,SACjB,aAAcA,EAAO,YACvB,CAAC,EACD,KAAKV,GAAQ,UAAU,CACrB,UAAW,EACb,CAAC,CACH,CASA,SAASY,EAAG,CACV,GAAI,CAAC,KAAKb,GACR,GAAIa,aAAa,cACbA,aAAa,KAAKH,GAAQ,aAC5B,GAAIG,EAAE,OAAS,oBACT,KAAKJ,IACP,QAAQ,KAAKI,EAAE,OAAO,MAGxB,OAAM,IAAI,KAAKH,GAAQ,aAAaG,EAAE,QAASA,EAAE,IAAI,MAGvD,OAAMA,CAGZ,CAYA,OAAOC,EAA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AAKb,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", "m", "localName", "prefix", "itemLocalName", "itemPrefix", "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", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "pendingItems", "pendingItem", "index", "nextCombo", "find", "entryNodes", "entryNodesLen", "n", "entryCombo", "entryLeaves", "entryNode"] } diff --git a/dist/cjs/js/matcher.js b/dist/cjs/js/matcher.js index d805f1eb..94aba357 100644 --- a/dist/cjs/js/matcher.js +++ b/dist/cjs/js/matcher.js @@ -1,2 +1,2 @@ -var y=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var O=(x,t)=>{for(var e in t)y(x,e,{get:t[e],enumerable:!0})},P=(x,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of N(t))!S.call(x,r)&&r!==e&&y(x,r,{get:()=>t[r],enumerable:!(n=L(t,r))||n.enumerable});return x};var R=x=>P(y({},"__esModule",{value:!0}),x);var A={};O(A,{Matcher:()=>k,default:()=>_});module.exports=R(A);var $=require("./dom-util.js"),b=require("./parser.js"),i=require("./constant.js");class k{matchPseudoElementSelector(t,e={}){if(!t||typeof t!="string"){const d=`Unexpected type ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(d)}const{forgive:n,warn:r}=e;switch(t){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(r){const s=`Unsupported pseudo-element ::${t}`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(r){const s=`Unsupported pseudo-element ::${t}()`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}break}default:if(t.startsWith("-webkit-")){if(r){const s=`Unsupported pseudo-element ::${t}`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}}else if(!n){const s=`Unknown pseudo-element ::${t}`;throw new DOMException(s,i.SYNTAX_ERR)}}}_matchAttributeSelector(t,e){const{flags:n,matcher:r,name:s,value:d}=t;if(typeof n=="string"&&!/^[is]$/i.test(n)){const o=`Invalid selector ${(0,b.generateCSS)(t)}`;throw new DOMException(o,i.SYNTAX_ERR)}const{attributes:w}=e;let m;if(w&&w.length){const h=e.ownerDocument.contentType;let o;h==="text/html"?typeof n=="string"&&/^s$/i.test(n)?o=!1:o=!0:typeof n=="string"&&/^i$/i.test(n)?o=!0:o=!1;let g=(0,b.unescapeSelector)(s.name);o&&(g=g.toLowerCase());const c=new Set;if(g.indexOf("|")>-1){const{prefix:f,localName:p}=(0,b.parseAstName)(g);for(const a of w){let{name:l,value:u}=a;switch(o&&(l=l.toLowerCase(),u=u.toLowerCase()),f){case"":{p===l&&c.add(u);break}case"*":{l.indexOf(":")>-1?l.endsWith(`:${p}`)&&c.add(u):p===l&&c.add(u);break}default:if(l.indexOf(":")>-1){const[T,E]=l.split(":");if(T==="xml"&&E==="lang")continue;f===T&&p===E&&(0,$.isNamespaceDeclared)(f,e)&&c.add(u)}}}}else for(let{name:f,value:p}of w)if(o&&(f=f.toLowerCase(),p=p.toLowerCase()),f.indexOf(":")>-1){const[a,l]=f.split(":");if(a==="xml"&&l==="lang")continue;g===l&&c.add(p)}else g===f&&c.add(p);if(c.size){const{name:f,value:p}=d??{};let a;switch(f?o?a=f.toLowerCase():a=f:p?o?a=p.toLowerCase():a=p:p===""&&(a=p),r){case"=":{typeof a=="string"&&c.has(a)&&(m=e);break}case"~=":{if(a&&typeof a=="string"){for(const l of c)if(new Set(l.split(/\s+/)).has(a)){m=e;break}}break}case"|=":{if(a&&typeof a=="string"){let l;for(const u of c)if(u===a||u.startsWith(`${a}-`)){l=u;break}l&&(m=e)}break}case"^=":{if(a&&typeof a=="string"){let l;for(const u of c)if(u.startsWith(`${a}`)){l=u;break}l&&(m=e)}break}case"$=":{if(a&&typeof a=="string"){let l;for(const u of c)if(u.endsWith(`${a}`)){l=u;break}l&&(m=e)}break}case"*=":{if(a&&typeof a=="string"){let l;for(const u of c)if(u.includes(`${a}`)){l=u;break}l&&(m=e)}break}case null:default:m=e}}}return m??null}_matchTypeSelector(t,e,n={}){const r=(0,b.unescapeSelector)(t.name),{localName:s,namespaceURI:d,prefix:w}=e,{forgive:m}=n;let{prefix:h,localName:o}=(0,b.parseAstName)(r,e);e.ownerDocument.contentType==="text/html"&&(h=h.toLowerCase(),o=o.toLowerCase());let g,c;s.indexOf(":")>-1?[g,c]=s.split(":"):(g=w||"",c=s);let f;switch(h){case"":{!g&&!d&&(o==="*"||o===c)&&(f=e);break}case"*":{(o==="*"||o===c)&&(f=e);break}default:{const p=e.lookupNamespaceURI(h),a=e.lookupNamespaceURI(g);if(p===a&&h===g)(o==="*"||o===c)&&(f=e);else if(!m&&!p){const l=`Undeclared namespace ${h}`;throw new DOMException(l,i.SYNTAX_ERR)}}}return f??null}_matchDirectionPseudoClass(t,e){const n=(0,$.getDirectionality)(e);let r;return t.name===n&&(r=e),r??null}_matchLanguagePseudoClass(t,e){if(t.name===i.EMPTY)return null;const n=(0,b.unescapeSelector)(t.name);typeof n=="string"&&n!==t.name&&(t.name=n);let r;if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(r=e);else{let s=e.parentNode;for(;s&&s.nodeType===i.ELEMENT_NODE;){if(s.hasAttribute("lang")){s.getAttribute("lang")&&(r=e);break}s=s.parentNode}}else if(n){const s=`(?:-${i.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${i.ALPHA_NUM}${s}$`,"i").test(n)){let w;if(n.indexOf("-")>-1){const[m,h,...o]=n.split("-");let g;m==="*"?g=`${i.ALPHA_NUM}${s}`:g=`${m}${s}`;const c=`-${h}${s}`,f=o.length;let p="";if(f)for(let a=0;a{for(var e in t)y(x,e,{get:t[e],enumerable:!0})},R=(x,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of S(t))!O.call(x,r)&&r!==e&&y(x,r,{get:()=>t[r],enumerable:!(n=N(t,r))||n.enumerable});return x};var _=x=>R(y({},"__esModule",{value:!0}),x);var C={};P(C,{Matcher:()=>k,default:()=>A,matcher:()=>L});module.exports=_(C);var $=require("./dom-util.js"),b=require("./parser.js"),i=require("./constant.js");class k{matchPseudoElementSelector(t,e={}){if(!t||typeof t!="string"){const h=`Unexpected type ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(h)}const{forgive:n,warn:r}=e;switch(t){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(r){const s=`Unsupported pseudo-element ::${t}`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(r){const s=`Unsupported pseudo-element ::${t}()`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}break}default:if(t.startsWith("-webkit-")){if(r){const s=`Unsupported pseudo-element ::${t}`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}}else if(!n){const s=`Unknown pseudo-element ::${t}`;throw new DOMException(s,i.SYNTAX_ERR)}}}_matchAttributeSelector(t,e){const{flags:n,matcher:r,name:s,value:h}=t;if(typeof n=="string"&&!/^[is]$/i.test(n)){const o=`Invalid selector ${(0,b.generateCSS)(t)}`;throw new DOMException(o,i.SYNTAX_ERR)}const{attributes:w}=e;let m;if(w&&w.length){const d=e.ownerDocument.contentType;let o;d==="text/html"?typeof n=="string"&&/^s$/i.test(n)?o=!1:o=!0:typeof n=="string"&&/^i$/i.test(n)?o=!0:o=!1;let g=(0,b.unescapeSelector)(s.name);o&&(g=g.toLowerCase());const c=new Set;if(g.indexOf("|")>-1){const{prefix:f,localName:p}=(0,b.parseAstName)(g);for(const a of w){let{name:l,value:u}=a;switch(o&&(l=l.toLowerCase(),u=u.toLowerCase()),f){case"":{p===l&&c.add(u);break}case"*":{l.indexOf(":")>-1?l.endsWith(`:${p}`)&&c.add(u):p===l&&c.add(u);break}default:if(l.indexOf(":")>-1){const[T,E]=l.split(":");if(T==="xml"&&E==="lang")continue;f===T&&p===E&&(0,$.isNamespaceDeclared)(f,e)&&c.add(u)}}}}else for(let{name:f,value:p}of w)if(o&&(f=f.toLowerCase(),p=p.toLowerCase()),f.indexOf(":")>-1){const[a,l]=f.split(":");if(a==="xml"&&l==="lang")continue;g===l&&c.add(p)}else g===f&&c.add(p);if(c.size){const{name:f,value:p}=h??{};let a;switch(f?o?a=f.toLowerCase():a=f:p?o?a=p.toLowerCase():a=p:p===""&&(a=p),r){case"=":{typeof a=="string"&&c.has(a)&&(m=e);break}case"~=":{if(a&&typeof a=="string"){for(const l of c)if(new Set(l.split(/\s+/)).has(a)){m=e;break}}break}case"|=":{if(a&&typeof a=="string"){let l;for(const u of c)if(u===a||u.startsWith(`${a}-`)){l=u;break}l&&(m=e)}break}case"^=":{if(a&&typeof a=="string"){let l;for(const u of c)if(u.startsWith(`${a}`)){l=u;break}l&&(m=e)}break}case"$=":{if(a&&typeof a=="string"){let l;for(const u of c)if(u.endsWith(`${a}`)){l=u;break}l&&(m=e)}break}case"*=":{if(a&&typeof a=="string"){let l;for(const u of c)if(u.includes(`${a}`)){l=u;break}l&&(m=e)}break}case null:default:m=e}}}return m??null}_matchTypeSelector(t,e,n={}){const r=(0,b.unescapeSelector)(t.name),{localName:s,namespaceURI:h,prefix:w}=e,{forgive:m}=n;let{prefix:d,localName:o}=(0,b.parseAstName)(r,e);e.ownerDocument.contentType==="text/html"&&(d=d.toLowerCase(),o=o.toLowerCase());let g,c;s.indexOf(":")>-1?[g,c]=s.split(":"):(g=w||"",c=s);let f;switch(d){case"":{!g&&!h&&(o==="*"||o===c)&&(f=e);break}case"*":{(o==="*"||o===c)&&(f=e);break}default:{const p=e.lookupNamespaceURI(d),a=e.lookupNamespaceURI(g);if(p===a&&d===g)(o==="*"||o===c)&&(f=e);else if(!m&&!p){const l=`Undeclared namespace ${d}`;throw new DOMException(l,i.SYNTAX_ERR)}}}return f??null}_matchDirectionPseudoClass(t,e){const n=(0,$.getDirectionality)(e);let r;return t.name===n&&(r=e),r??null}_matchLanguagePseudoClass(t,e){if(t.name===i.EMPTY)return null;const n=(0,b.unescapeSelector)(t.name);typeof n=="string"&&n!==t.name&&(t.name=n);let r;if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(r=e);else{let s=e.parentNode;for(;s&&s.nodeType===i.ELEMENT_NODE;){if(s.hasAttribute("lang")){s.getAttribute("lang")&&(r=e);break}s=s.parentNode}}else if(n){const s=`(?:-${i.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${i.ALPHA_NUM}${s}$`,"i").test(n)){let w;if(n.indexOf("-")>-1){const[m,d,...o]=n.split("-");let g;m==="*"?g=`${i.ALPHA_NUM}${s}`:g=`${m}${s}`;const c=`-${d}${s}`,f=o.length;let p="";if(f)for(let a=0;a -1) {\n const {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astAttrName);\n for (const item of attributes) {\n let { name: itemName, value: itemValue } = item;\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astPrefix) {\n case '': {\n if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astPrefix === itemPrefix &&\n astLocalName === itemLocalName) {\n const namespaceDeclared =\n isNamespaceDeclared(astPrefix, node);\n if (namespaceDeclared) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const { name: astIdentValue, value: astStringValue } = astValue ?? {};\n let attrValue;\n if (astIdentValue) {\n if (caseInsensitive) {\n attrValue = astIdentValue.toLowerCase();\n } else {\n attrValue = astIdentValue;\n }\n } else if (astStringValue) {\n if (caseInsensitive) {\n attrValue = astStringValue.toLowerCase();\n } else {\n attrValue = astStringValue;\n }\n } else if (astStringValue === '') {\n attrValue = astStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive undeclared namespace\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, namespaceURI, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astName, node);\n if (node.ownerDocument.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astLocalName = astLocalName.toLowerCase();\n }\n let nodePrefix;\n let nodeLocalName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeLocalName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeLocalName = localName;\n }\n let res;\n switch (astPrefix) {\n case '': {\n if (!nodePrefix && !namespaceURI &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n break;\n }\n case '*': {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n break;\n }\n default: {\n const astNS = node.lookupNamespaceURI(astPrefix);\n const nodeNS = node.lookupNamespaceURI(nodePrefix);\n if (astNS === nodeNS && astPrefix === nodePrefix) {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (!forgive && !astNS) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n return res ?? null;\n };\n\n /**\n * match directionality pseudo-class - :dir()\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const dir = getDirectionality(node);\n let res;\n if (ast.name === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n if (ast.name === EMPTY) {\n return null;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\n let res;\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n } else if (astName) {\n const langPart = `(?:-${ALPHA_NUM})*`;\n const regLang = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${langPart}$`, 'i');\n if (regLang.test(astName)) {\n let regExtendedLang;\n if (astName.indexOf('-') > -1) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${langPart}`;\n } else {\n extendedMain = `${langMain}${langPart}`;\n }\n const extendedSub = `-${langSub}${langPart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${langPart}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${langPart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (regExtendedLang.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (regExtendedLang.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n matchSelector(ast, node, opt) {\n if (!ast || !ast.type) {\n const nodeType =\n Object.prototype.toString.call(ast).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (!node || !node.nodeType) {\n const nodeType =\n Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n let matched;\n switch (ast.type) {\n case SELECTOR_ATTR: {\n matched = this._matchAttributeSelector(ast, node);\n break;\n }\n case SELECTOR_TYPE: {\n matched = this._matchTypeSelector(ast, node, opt);\n break;\n }\n default: {\n const { children: [child], name: astName } = ast;\n if (astName === 'dir') {\n matched = this._matchDirectionPseudoClass(child, node);\n } else if (astName === 'lang') {\n matched = this._matchLanguagePseudoClass(child, node);\n }\n }\n }\n return matched;\n }\n}\n\nexport default new Matcher();\n"], - "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAKA,IAAAK,EAAuD,yBACvDC,EAA4D,uBAG5DC,EAGO,yBAGA,MAAML,CAAQ,CAUnB,2BAA2BM,EAASC,EAAM,CAAC,EAAG,CAC5C,GAAI,CAACD,GAAW,OAAOA,GAAY,SAAU,CAG3C,MAAME,EAAM,mBADV,OAAO,UAAU,SAAS,KAAKF,CAAO,EAAE,MAAM,YAAW,SAAO,CAC3B,GACvC,MAAM,IAAI,UAAUE,CAAG,CACzB,CACA,KAAM,CAAE,QAAAC,EAAS,KAAAC,CAAK,EAAIH,EAC1B,OAAQD,EAAS,CACf,IAAK,QACL,IAAK,WACL,IAAK,SACL,IAAK,MACL,IAAK,aACL,IAAK,eACL,IAAK,aACL,IAAK,uBACL,IAAK,SACL,IAAK,cACL,IAAK,YACL,IAAK,cAAe,CAClB,GAAII,EAAM,CACR,MAAMF,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,IAAK,OACL,IAAK,UAAW,CACd,GAAIE,EAAM,CACR,MAAMF,EAAM,gC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,OAAOxB,GAAO,IAChB,CASA,cAAcN,EAAKC,EAAML,EAAK,CAC5B,GAAI,CAACI,GAAO,CAACA,EAAI,KAAM,CAGrB,MAAMH,EAAM,mBADV,OAAO,UAAU,SAAS,KAAKG,CAAG,EAAE,MAAM,YAAW,SAAO,CACvB,GACvC,MAAM,IAAI,UAAUH,CAAG,CACzB,SAAW,CAACI,GAAQ,CAACA,EAAK,SAAU,CAGlC,MAAMJ,EAAM,mBADV,OAAO,UAAU,SAAS,KAAKI,CAAI,EAAE,MAAM,YAAW,SAAO,CACxB,GACvC,MAAM,IAAI,UAAUJ,CAAG,CACzB,SAAWI,EAAK,WAAa,eAAc,CACzC,MAAMJ,EAAM,mBAAmBI,EAAK,QAAQ,GAC5C,MAAM,IAAI,UAAUJ,CAAG,CACzB,CACA,IAAI4C,EACJ,OAAQzC,EAAI,KAAM,CAChB,KAAK,gBAAe,CAClByC,EAAU,KAAK,wBAAwBzC,EAAKC,CAAI,EAChD,KACF,CACA,KAAK,gBAAe,CAClBwC,EAAU,KAAK,mBAAmBzC,EAAKC,EAAML,CAAG,EAChD,KACF,CACA,QAAS,CACP,KAAM,CAAE,SAAU,CAAC8C,CAAK,EAAG,KAAM/C,CAAQ,EAAIK,EACzCL,IAAY,MACd8C,EAAU,KAAK,2BAA2BC,EAAOzC,CAAI,EAC5CN,IAAY,SACrB8C,EAAU,KAAK,0BAA0BC,EAAOzC,CAAI,EAExD,CACF,CACA,OAAOwC,CACT,CACF,CAEA,IAAOnD,EAAQ,IAAID", - "names": ["matcher_exports", "__export", "Matcher", "matcher_default", "__toCommonJS", "import_dom_util", "import_parser", "import_constant", "astName", "opt", "msg", "forgive", "warn", "ast", "node", "astFlags", "astMatcher", "astValue", "attributes", "res", "contentType", "caseInsensitive", "astAttrName", "attrValues", "astPrefix", "astLocalName", "item", "itemName", "itemValue", "itemPrefix", "itemLocalName", "astIdentValue", "astStringValue", "attrValue", "value", "localName", "namespaceURI", "prefix", "nodePrefix", "nodeLocalName", "astNS", "nodeNS", "dir", "parent", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "i", "matched", "child"] + "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport { getDirectionality, isNamespaceDeclared } from './dom-util.js';\nimport { generateCSS, parseAstName, unescapeSelector } from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, ELEMENT_NODE, EMPTY, NOT_SUPPORTED_ERR, SELECTOR_ATTR,\n SELECTOR_TYPE, SYNTAX_ERR, TYPE_FROM, TYPE_TO\n} from './constant.js';\n\n/* Matcher */\nexport class Matcher {\n /**\n * match pseudo-element selector\n * @param {string} astName - AST name\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive unknown pseudo-element\n * @param {boolean} [opt.warn] - warn unsupported pseudo-element\n * @throws {DOMException}\n * @returns {void}\n */\n matchPseudoElementSelector(astName, opt = {}) {\n if (!astName || typeof astName !== 'string') {\n const nodeType =\n Object.prototype.toString.call(astName).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${nodeType}`;\n throw new TypeError(msg);\n }\n const { forgive, warn } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'placeholder':\n case 'selection':\n case 'target-text': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${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-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-element ::${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match attribute selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const contentType = node.ownerDocument.contentType;\n let caseInsensitive;\n if (contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\n const {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astAttrName);\n for (const item of attributes) {\n let { name: itemName, value: itemValue } = item;\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astPrefix) {\n case '': {\n if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astPrefix === itemPrefix &&\n astLocalName === itemLocalName) {\n const namespaceDeclared =\n isNamespaceDeclared(astPrefix, node);\n if (namespaceDeclared) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const { name: astIdentValue, value: astStringValue } = astValue ?? {};\n let attrValue;\n if (astIdentValue) {\n if (caseInsensitive) {\n attrValue = astIdentValue.toLowerCase();\n } else {\n attrValue = astIdentValue;\n }\n } else if (astStringValue) {\n if (caseInsensitive) {\n attrValue = astStringValue.toLowerCase();\n } else {\n attrValue = astStringValue;\n }\n } else if (astStringValue === '') {\n attrValue = astStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive undeclared namespace\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, namespaceURI, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astName, node);\n if (node.ownerDocument.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astLocalName = astLocalName.toLowerCase();\n }\n let nodePrefix;\n let nodeLocalName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeLocalName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeLocalName = localName;\n }\n let res;\n switch (astPrefix) {\n case '': {\n if (!nodePrefix && !namespaceURI &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n break;\n }\n case '*': {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n break;\n }\n default: {\n const astNS = node.lookupNamespaceURI(astPrefix);\n const nodeNS = node.lookupNamespaceURI(nodePrefix);\n if (astNS === nodeNS && astPrefix === nodePrefix) {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (!forgive && !astNS) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n return res ?? null;\n };\n\n /**\n * match directionality pseudo-class - :dir()\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const dir = getDirectionality(node);\n let res;\n if (ast.name === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n if (ast.name === EMPTY) {\n return null;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\n let res;\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n } else if (astName) {\n const langPart = `(?:-${ALPHA_NUM})*`;\n const regLang = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${langPart}$`, 'i');\n if (regLang.test(astName)) {\n let regExtendedLang;\n if (astName.indexOf('-') > -1) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${langPart}`;\n } else {\n extendedMain = `${langMain}${langPart}`;\n }\n const extendedSub = `-${langSub}${langPart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${langPart}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${langPart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (regExtendedLang.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (regExtendedLang.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n matchSelector(ast, node, opt) {\n if (!ast || !ast.type) {\n const nodeType =\n Object.prototype.toString.call(ast).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (!node || !node.nodeType) {\n const nodeType =\n Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n let matched;\n switch (ast.type) {\n case SELECTOR_ATTR: {\n matched = this._matchAttributeSelector(ast, node);\n break;\n }\n case SELECTOR_TYPE: {\n matched = this._matchTypeSelector(ast, node, opt);\n break;\n }\n default: {\n const { children: [child], name: astName } = ast;\n if (astName === 'dir') {\n matched = this._matchDirectionPseudoClass(child, node);\n } else if (astName === 'lang') {\n matched = this._matchLanguagePseudoClass(child, node);\n }\n }\n }\n return matched;\n }\n}\n\nexport const matcher = new Matcher();\nexport default matcher;\n"], + "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAL,GAKA,IAAAM,EAAuD,yBACvDC,EAA4D,uBAG5DC,EAGO,yBAGA,MAAMN,CAAQ,CAUnB,2BAA2BO,EAASC,EAAM,CAAC,EAAG,CAC5C,GAAI,CAACD,GAAW,OAAOA,GAAY,SAAU,CAG3C,MAAME,EAAM,mBADV,OAAO,UAAU,SAAS,KAAKF,CAAO,EAAE,MAAM,YAAW,SAAO,CAC3B,GACvC,MAAM,IAAI,UAAUE,CAAG,CACzB,CACA,KAAM,CAAE,QAAAC,EAAS,KAAAC,CAAK,EAAIH,EAC1B,OAAQD,E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EO,MAAMnD,EAAU,IAAIF,EAC3B,IAAOC,EAAQC", + "names": ["matcher_exports", "__export", "Matcher", "matcher_default", "matcher", "__toCommonJS", "import_dom_util", "import_parser", "import_constant", "astName", "opt", "msg", "forgive", "warn", "ast", "node", "astFlags", "astMatcher", "astValue", "attributes", "res", "contentType", "caseInsensitive", "astAttrName", "attrValues", "astPrefix", "astLocalName", "item", "itemName", "itemValue", "itemPrefix", "itemLocalName", "astIdentValue", "astStringValue", "attrValue", "value", "localName", "namespaceURI", "prefix", "nodePrefix", "nodeLocalName", "astNS", "nodeNS", "dir", "parent", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "i", "matched", "child"] } diff --git a/package.json b/package.json index 9a6aa632..f3a0b40f 100644 --- a/package.json +++ b/package.json @@ -63,5 +63,5 @@ "tsc": "node scripts/index clean --dir=types -i && npx tsc", "update-wpt": "git submodule update --init --recursive --remote" }, - "version": "4.1.5" + "version": "4.1.6" } diff --git a/types/js/matcher.d.ts b/types/js/matcher.d.ts index ae8359b2..257fdb21 100644 --- a/types/js/matcher.d.ts +++ b/types/js/matcher.d.ts @@ -9,5 +9,5 @@ export class Matcher { private _matchLanguagePseudoClass; matchSelector(ast: object, node: object, opt: object): object | null; } -declare const _default: Matcher; -export default _default; +export const matcher: Matcher; +export default matcher;