@asamuzakjp/dom-selector 5.3.2 → 5.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/js/finder.js +1 -1
- package/dist/cjs/js/finder.js.map +3 -3
- package/package.json +2 -2
- package/src/js/finder.js +17 -7
package/dist/cjs/js/finder.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var Y=(S,r)=>{for(var e in r)R(S,e,{get:r[e],enumerable:!0})},q=(S,r,e,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of j(r))!V.call(S,n)&&n!==e&&R(S,n,{get:()=>r[n],enumerable:!(f=B(r,n))||f.enumerable});return S};var K=S=>q(R({},"__esModule",{value:!0}),S);var Z={};Y(Z,{Finder:()=>J});module.exports=K(Z);var F=require("./matcher.js"),g=require("./parser.js"),k=require("./utility.js"),c=require("./constant.js");const v="next",x="prev",X="Tab",O=/^a(?:rea)?$/,M=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,T=/^(?:button|form|input|select|textarea)$/,I=/^(?:details|dialog)$/,$=/^host(?:-context)?$/,C=/^(?:checkbox|radio)$/,P=/^(?:date(?:time-local)?|month|number|range|time|week)$/,D=/^(?:button|reset)$/,U=/^(?:image|submit)$/,Q=/^(?:email|number|password|search|tel|text|url)$/;class J{#l;#b;#w;#t;#c;#n;#k;#o;#h;#f;#e;#d;#_;#m;#N;#s;#u;#r;#p;#i;#a;constructor(r){this.#a=r,this.#f=new F.Matcher,this.#b=new WeakMap,this.#c=new WeakMap,this.#h=new WeakMap,this.#N=new WeakMap,this.#n=null,this.#k=null,this._registerEventListeners()}onError(r,e={}){if(!(e.noexcept??this.#_))if(r instanceof DOMException||r instanceof this.#a.DOMException)if(r.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw new this.#a.DOMException(r.message,r.name);else throw r.name in this.#a?new this.#a[r.name](r.message):r}setup(r,e,f={}){const{event:n,noexcept:a,warn:l}=f;return this.#_=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#u=(0,k.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(r),this.#h=new WeakMap,this.#p=new WeakMap,this._setEvent(n),e}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],f=["mouseover","mousedown","mouseup","mouseout"];for(const a of f)e.push(this.#a.addEventListener(a,l=>{this.#n=l},r));const n=["keydown","keyup"];for(const a of n)e.push(this.#a.addEventListener(a,l=>{l.key===X&&(this.#n=l)},r));return e.push(this.#a.addEventListener("focusin",a=>{this.#k=a},r)),e}_setEvent(r){return(r instanceof this.#a.KeyboardEvent||r instanceof this.#a.MouseEvent)&&(this.#n=r),this.#n}_correspond(r){const e=[];this.#w=!1,this.#o=!1;let f;if(this.#c.has(this.#t)){const n=this.#c.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);f=a.ast,this.#w=a.descendant,this.#o=a.invalidate}}if(f){const n=f.length;for(let a=0;a<n;a++)f[a].collected=!1,f[a].dir=null,f[a].filtered=!1,f[a].find=!1,e[a]=[]}else{let n;try{n=(0,g.parseSelector)(r)}catch(t){this.onError(t)}const{branches:a,info:{hasHasPseudoFunc:l,hasNthChildOfSelector:o}}=(0,g.walkAST)(n);let u=!!(l||o),d=!1,i=0;f=[];for(const[...t]of a){const h=[];let b=t.shift();if(b&&b.type!==c.COMBINATOR){const m=new Set;for(;b;){if(b.type===c.COMBINATOR){const[p]=t;if(p.type===c.COMBINATOR)throw new DOMException(`Invalid selector ${r}`,c.SYNTAX_ERR);const w=b.name;/^[\s>]$/.test(w)?d=!0:u=!0,h.push({combo:b,leaves:(0,g.sortAST)(m)}),m.clear()}else if(b){let{name:p}=b;p&&typeof p=="string"&&(p=(0,g.unescapeSelector)(p),typeof p=="string"&&p!==b.name&&(b.name=p),/[|:]/.test(p)&&(b.namespace=!0)),m.add(b)}if(t.length)b=t.shift();else{h.push({combo:null,leaves:(0,g.sortAST)(m)}),m.clear();break}}}f.push({branch:h,collected:!1,dir:null,filtered:!1,find:!1}),e[i]=[],i++}let s;this.#c.has(this.#t)?s=this.#c.get(this.#t):s=new Map,s.set(`${r}`,{ast:f,descendant:d,invalidate:u}),this.#c.set(this.#t,s),this.#w=d,this.#o=u}return[f,e]}_createTreeWalker(r){let e;return this.#p.has(r)?e=this.#p.get(r):(e=this.#t.createTreeWalker(r,c.WALKER_FILTER),this.#p.set(r,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(r,e,f){const{a:n,b:a,reverse:l,selector:o}=r,{parentNode:u}=e,d=new Set;let i;if(o){const{branches:s}=(0,g.walkAST)(o);i=s}if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();const b=new Set;if(i)for(t=(0,k.traverseNode)(u,s),t=s.firstChild();t;){if((0,k.isVisible)(t)){let m;for(const p of i)if(m=this._matchLeaves(p,t,f),!m)break;m&&b.add(t)}t=s.nextSibling()}if(n===0){if(a>0&&a<=h){if(b.size){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(b.has(t)){if(m===a-1){d.add(t);break}m++}l?t=s.previousSibling():t=s.nextSibling()}}else if(!o){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(m===a-1){d.add(t);break}l?t=s.previousSibling():t=s.nextSibling(),m++}}}}else{let m=a-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m<h){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let p=0,w=n>0?0:a-1;for(;t&&(t&&m>=0&&m<h);)b.size?b.has(t)&&(w===m&&(d.add(t),m+=n),n>0?w++:w--):p===m&&(o||d.add(t),m+=n),l?t=s.previousSibling():t=s.nextSibling(),p++}}if(l&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&n+a===1)if(i){let s;for(const t of i)if(s=this._matchLeaves(t,e,f),s)break;s&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:f,b:n,reverse:a}=r,{localName:l,namespaceURI:o,parentNode:u,prefix:d}=e,i=new Set;if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();if(f===0){if(n>0&&n<=h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let b=0;for(;t;){const{localName:m,namespaceURI:p,prefix:w}=t;if(m===l&&w===d&&p===o){if(b===n-1){i.add(t);break}b++}a?t=s.previousSibling():t=s.nextSibling()}}}else{let b=n-1;if(f>0)for(;b<0;)b+=f;if(b>=0&&b<h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let m=f>0?0:n-1;for(;t;){const{localName:p,namespaceURI:w,prefix:N}=t;if(p===l&&N===d&&w===o){if(m===b&&(i.add(t),b+=f),b<0||b>=h)break;f>0?m++:m--}a?t=s.previousSibling():t=s.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&f+n===1&&i.add(e);return i}_matchAnPlusB(r,e,f,n){const{nth:{a,b:l,name:o},selector:u}=r,d=new Map;if(o?(o==="even"?(d.set("a",2),d.set("b",0)):o==="odd"&&(d.set("a",2),d.set("b",1)),f.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),f.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(f)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,f={}){let n;if(Array.isArray(r)&&r.length){const a=r.map(t=>t),[l]=a,{type:o}=l;let u;o===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[t]=a,{type:h}=t;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};f.dir=v;const s=this._matchCombinator(i,e,f);if(s.size)if(a.length){for(const t of s)if(n=this._matchHasPseudoFunc(a,t,f),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,f={}){const{astName:n="",branches:a=[],selector:l="",twigBranches:o=[]}=r;let u;if(n==="has")if(l.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,f),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(n);f.forgive=d;const i=o.length;let s;for(let t=0;t<i;t++){const h=o[t],b=h.length-1,{leaves:m}=h[b];if(s=this._matchLeaves(m,e,f),s&&b>0){let p=new Set([e]);for(let w=b-1;w>=0;w--){const N=h[w],_=[];f.dir=x;for(const y of p){const E=this._matchCombinator(N,y,f);E.size&&_.push(...E)}if(_.length)w===0?s=!0:p=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(u=e):s&&(u=e)}return u??null}_matchPseudoClassSelector(r,e,f={}){const{children:n,name:a}=r,{localName:l,parentNode:o}=e,{forgive:u,warn:d=this.#i}=f,i=new Set;if(c.REG_LOGICAL.test(a)){let s;if(this.#b.has(r))s=this.#b.get(r);else{const{branches:h}=(0,g.walkAST)(r),b=[],m=[];for(const[...p]of h){for(const y of p){const E=(0,g.generateCSS)(y);b.push(E)}const w=[],N=new Set;let _=p.shift();for(;_;)if(_.type===c.COMBINATOR?(w.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),p.length)_=p.shift();else{w.push({combo:null,leaves:[...N]}),N.clear();break}m.push(w)}s={astName:a,branches:h,twigBranches:m,selector:b.join(",")},this.#b.set(r,s)}const t=this._matchLogicalPseudoFunc(s,e,f);t&&i.add(t)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[s]=n;return this._matchAnPlusB(s,e,a,f)}else switch(a){case"dir":case"lang":{const s=this.#f.matchSelector(r,e,f,!0);s&&i.add(s);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:s}]=n;if(s)if(e[s])i.add(e);else for(const t in e){const h=e[t];if(h instanceof this.#a.ElementInternals){h?.states?.has(s)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,c.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{O.test(l)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(O.test(l)&&e.hasAttribute("href")){const{href:s,origin:t,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),s);b.origin===t&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:s,type:t}=this.#n??{};/^(?:mouse|pointer)(?:down|over|up)$/.test(t)&&e.contains(s)&&i.add(e);break}case"active":{const{buttons:s,target:t,type:h}=this.#n??{};/(?:mouse|pointer)down/.test(h)&&s&c.BIT_01&&e.contains(t)&&i.add(e);break}case"target":{const{hash:s}=new URL(this.#t.URL);e.id&&s===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:s}=new URL(this.#t.URL);if(s){const t=s.replace(/^#/,"");let h=this.#t.getElementById(t);for(;h;){if(h===e){i.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&e.tabIndex>=0&&(0,k.isFocusable)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&e.tabIndex>=0){let s;if((0,k.isFocusVisible)(e))s=!0;else{const{target:t,type:h}=this.#n??{},{target:b,relatedTarget:m}=this.#k??{};(/^key(?:down|up)$/.test(h)&&e.contains(t)||m&&(0,k.isFocusVisible)(m)&&e.contains(b))&&(s=!0)}s&&(0,k.isFocusable)(e)&&i.add(e)}break}case"focus-within":{let s,t=this.#t.activeElement;if(t.tabIndex>=0)for(;t;){if(t===e){s=!0;break}t=t.parentNode}s&&(0,k.isFocusable)(e)&&i.add(e);break}case"open":{I.test(l)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{I.test(l)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")o.localName==="optgroup"&&(o.disabled||o.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s&&i.add(e)}}break}case"enabled":{if((M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(o.localName!=="optgroup"||!(o.disabled||o.hasAttribute("disabled")))&&i.add(e);else{let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s||i.add(e)}break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let s;if(e.placeholder?s=e.placeholder:e.hasAttribute("placeholder")&&(s=e.getAttribute("placeholder")),typeof s=="string"&&!/[\r\n]/.test(s)){let t;l==="textarea"?t=e:l==="input"&&(e.hasAttribute("type")?Q.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;t||(t=this.#t.documentElement);const h=t.getElementsByTagName("input"),b=h.length;let m;for(let p=0;p<b;p++){const w=h[p];if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(m=!!w.checked):w.hasAttribute("name")||(m=!!w.checked),m))break}m||i.add(e)}break}case"default":{if(l==="button"&&!(e.hasAttribute("type")&&D.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&U.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const t=this.#r;let h=(0,k.traverseNode)(s,t);for(h=t.firstChild();h&&s.contains(h);){const b=h.localName;let m;if(b==="button"?m=!(h.hasAttribute("type")&&D.test(h.getAttribute("type"))):b==="input"&&(m=h.hasAttribute("type")&&U.test(h.getAttribute("type"))),m){h===e&&i.add(e);break}h=t.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(T.test(l))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h&&i.add(e)}break}case"invalid":{if(T.test(l))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h||i.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&P.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&P.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const s=this.#t.createTreeWalker(e,c.SHOW_ALL);let t=s.firstChild(),h;for(;t&&(h=t.nodeType!==c.ELEMENT_NODE&&t.nodeType!==c.TEXT_NODE,!!h);)t=s.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(o&&e===o.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(o&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(o&&e===o.firstElementChild&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,k.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d)throw new DOMException(`Unsupported pseudo-element ::${a}`,c.NOT_SUPPORTED_ERR);break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,c.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(r,e){const{children:f,name:n}=r;let a;if(Array.isArray(f)){const{branches:l}=(0,g.walkAST)(f[0]),[o]=l,[...u]=o,{host:d}=e;if(n==="host"){let i;for(const s of u){const{type:t}=s;if(t===c.COMBINATOR){const h=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(s,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,s;for(;i;){for(const t of u){const{type:h}=t;if(h===c.COMBINATOR){const b=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(s=this._matchSelector(t,i).has(i),!s)break}if(s)break;i=i.parentNode}s&&(a=e)}}else if(n==="host")a=e;else throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR);return a??null}_matchSelector(r,e,f){const{type:n}=r,a=new Set;if(r.name===c.EMPTY)return a;const l=(0,g.unescapeSelector)(r.name);if(typeof l=="string"&&l!==r.name&&(r.name=l),e.nodeType===c.ELEMENT_NODE)switch(n){case c.PS_ELEMENT_SELECTOR:{this.#f.matchPseudoElementSelector(l,f);break}case c.ID_SELECTOR:{e.id===l&&a.add(e);break}case c.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case c.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(r,e,f);default:{const o=this.#f.matchSelector(r,e,f,!0);o&&a.add(o)}}else if(this.#u&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&c.REG_LOGICAL.test(l))return this._matchPseudoClassSelector(r,e,f);if($.test(l)){const o=this._matchShadowHostPseudoClass(r,e,f);o&&a.add(o)}}return a}_matchLeaves(r,e,f){let n,a;if(this.#o?a=this.#h.get(r):a=this.#N.get(r),a&&a.has(e)){const{matched:l}=a.get(e);n=l}if(typeof n!="boolean"){let l=!0;e.nodeType===c.ELEMENT_NODE&&/^(?:button|fieldset|form|input|select|textarea)$/.test(e.localName)&&(l=!1);for(const o of r){switch(o.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{/^(?:(?:any-)?link|defined|dir)$/.test(o.name)&&(l=!1);break}default:}if(n=this._matchSelector(o,e,f).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#o?this.#h.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e={}){const{compound:f,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(f)for(let o=0;o<l;o++){const u=r[o];this._matchLeaves(n,u,e)&&a.add(u)}else{const o=[].slice.call(r);return new Set(o)}return a}_findDescendantNodes(r,e,f){const[n,...a]=r,l=a.length>0,{type:o}=n,u=(0,g.unescapeSelector)(n.name);typeof u=="string"&&u!==n.name&&(n.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(o){case c.PS_ELEMENT_SELECTOR:{this.#f.matchPseudoElementSelector(u,f);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const s=this.#s.getElementById(u);s&&s!==e&&e.contains(s)&&(l?this._matchLeaves(a,s,f)&&d.add(s):d.add(s))}break}case c.CLASS_SELECTOR:{const s=e.getElementsByClassName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const s=e.getElementsByTagName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,f={}){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:o}=e,{dir:u}=f,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(e,i);for(s=i.nextSibling();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let s=(0,k.traverseNode)(e,i);for(s=i.firstChild();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling();break}case" ":default:{const{nodes:i,pending:s}=this._findDescendantNodes(a,e);if(i.size)return i;if(s){const t=this._createTreeWalker(e);let h=(0,k.traverseNode)(e,t);for(h=t.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,f)&&d.add(h),h=t.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(o,i);for(s=i.firstChild();s&&s!==e;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{o&&this._matchLeaves(a,o,f)&&d.add(o);break}case" ":default:{const i=[];let s=o;for(;s;)this._matchLeaves(a,s,f)&&i.push(s),s=s.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const{node:f}=e,n=this.#m;let a=(0,k.traverseNode)(f,n),l;if(a)for((a.nodeType!==c.ELEMENT_NODE||a===f&&a!==this.#s)&&(a=n.nextNode());a;){if(this._matchLeaves(r,a,{warn:this.#i})){l=a;break}a=n.nextNode()}return l??null}_matchSelf(r){const e=[],f=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return f&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e={}){const{complex:f}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||f){let o=this.#e.parentNode;for(;o&&(a=this._matchLeaves(r,o,{warn:this.#i}),a&&(n.push(o),l=!0),o.parentNode);)o=o.parentNode}return[n,l]}_findFirst(r){const e=[],f=this._findNode(r,{node:this.#e});let n=!1;return f&&(e.push(f),n=!0),[e,n]}_findFromHTMLCollection(r,e={}){const{complex:f,compound:n,filterLeaves:a,targetType:l}=e;let o=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let s=0;s<i;s++){const t=r[s];if(t!==this.#e&&(this.#e.contains(t)||t.contains(this.#e))){if(n){if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else if(o.push(t),u=!0,l===c.TARGET_FIRST)break}}else if(f)if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;else if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;return[o,u,d]}_findEntryNodes(r,e,f){const{leaves:n}=r,[a,...l]=n,o=l.length>0,{name:u,type:d}=a;let i=[],s=!1,t=!1,h=!1;switch(d){case c.PS_ELEMENT_SELECTOR:{this.#f.matchPseudoElementSelector(u,{warn:this.#i});break}case c.ID_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(o?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),t=!0):(i.push(b),t=!0))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}default:if(e!==c.TARGET_LINEAL&&$.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),t=!0)}}else e===c.TARGET_SELF?[i,t]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,t]=this._findLineal(n,{complex:f}):e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0}return{collected:s,compound:o,filtered:t,nodes:i,pending:h}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const f=new Set;let n=0;for(const{branch:a}of e){const l=a.length,o=l>1,u=a[0];let d,i;if(o){const{combo:p,leaves:[{name:w,type:N}]}=u,_=a[l-1],{leaves:[{name:y,type:E}]}=_;if(E===c.PS_ELEMENT_SELECTOR||E===c.ID_SELECTOR)d=x,i=_;else if(N===c.PS_ELEMENT_SELECTOR||N===c.ID_SELECTOR)d=v,i=u;else if(r===c.TARGET_ALL)if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:A}=p;/^[+~]$/.test(A)?(d=x,i=_):(d=v,i=u)}else d=v,i=u;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else{let A;for(const{combo:L,leaves:[W]}of a){const{name:G,type:H}=W;if(H===c.PS_CLASS_SELECTOR&&G==="dir"){A=!1;break}if(!A&&L){const{name:z}=L;/^[+~]$/.test(z)&&(A=!0)}}A?(d=v,i=u):(d=x,i=_)}}else d=x,i=u;const{collected:s,compound:t,filtered:h,nodes:b,pending:m}=this._findEntryNodes(i,r,o);b.length?(this.#l[n].find=!0,this.#d[n]=b):m&&f.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=s,this.#l[n].dir=d,this.#l[n].filtered=h||!t,n++}if(f.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,l=this.#m):(a=this.#s,l=this.#r);let o=(0,k.traverseNode)(a,l);for(;o;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?o===this.#e?u=!0:u=this.#e.contains(o):u=!0,u)for(const d of f){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,o,{warn:this.#i})){const t=d.get("index");this.#l[t].filtered=!0,this.#l[t].find=!0,this.#d[t].push(o)}}o!==l.currentNode&&(o=(0,k.traverseNode)(o,l)),o=l.nextNode()}}}else{let f=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:o,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[f].find=!0,this.#d[f]=d),this.#l[f].dir=x,this.#l[f].filtered=u||!o,f++}}return[this.#l,this.#d]}_getCombinedNodes(r,e,f){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:f,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,f){const{combo:n,index:a}=f,{combo:l,leaves:o}=r[a],u={combo:n,leaves:o},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===r.length-1){const[s]=(0,k.sortNodes)(d);i=s}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,f){const{index:n}=f,a=r[n],l=new Set([e]),o=this._getCombinedNodes(a,l,x);let u;if(o.size){if(n===0)u=e;else for(const d of o)if(this._matchNodePrev(r,d,{index:n-1}))return e}return u??null}find(r){(r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let o=0;o<n;o++){const{branch:u,collected:d,dir:i,find:s}=e[o],t=u.length;if(t&&s){const h=f[o],b=h.length,m=t-1;if(m===0)if((r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this.#e.nodeType===c.ELEMENT_NODE)for(let p=0;p<b;p++){const w=h[p];if(w!==this.#e&&this.#e.contains(w)&&(l.add(w),r!==c.TARGET_ALL))break}else if(r===c.TARGET_ALL)if(l.size){const p=[...l];l=new Set([...p,...h]),a=!0}else l=new Set(h);else{const[p]=h;l.add(p)}else if(r===c.TARGET_ALL)if(i===v){let{combo:p}=u[0];for(const w of h){let N=new Set([w]);for(let _=1;_<t;_++){const{combo:y,leaves:E}=u[_],A={combo:p,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(l.size){const L=[...l];l=new Set([...L,...N]),a=!0}else l=N;else p=y;else break}}}else for(const p of h){let w=new Set([p]);for(let N=m-1;N>=0;N--){const _=u[N];if(w=this._getCombinedNodes(_,w,i),w.size)N===0&&(l.add(p),t>1&&l.size>1&&(a=!0));else break}}else if(r===c.TARGET_FIRST&&i===v){const{combo:p}=u[0];let w;for(const N of h)if(w=this._matchNodeNext(u,new Set([N]),{combo:p,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:N}=u[0],[_]=h;let y=this._findNode(N,{node:_});for(;y;){if(w=this._matchNodeNext(u,new Set([y]),{combo:p,index:1}),w){l.add(w);break}y=this._findNode(N,{node:y})}}}else{let p;for(const w of h)if(p=this._matchNodePrev(u,w,{index:m-1}),p){l.add(w);break}if(!p&&!d&&r===c.TARGET_FIRST){const{leaves:w}=u[m],[N]=h;let _=this._findNode(w,{node:N});for(;_;){if(p=this._matchNodePrev(u,_,{index:m-1}),p){l.add(_);break}_=this._findNode(w,{node:_})}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,k.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,k.sortNodes)(l)))),this.#o&&(this.#h=new WeakMap),l}}0&&(module.exports={Finder});
|
|
1
|
+
var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var Y=(S,r)=>{for(var e in r)R(S,e,{get:r[e],enumerable:!0})},q=(S,r,e,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of j(r))!V.call(S,n)&&n!==e&&R(S,n,{get:()=>r[n],enumerable:!(f=B(r,n))||f.enumerable});return S};var K=S=>q(R({},"__esModule",{value:!0}),S);var Z={};Y(Z,{Finder:()=>J});module.exports=K(Z);var F=require("./matcher.js"),g=require("./parser.js"),k=require("./utility.js"),c=require("./constant.js");const v="next",x="prev",X="Tab",O=/^a(?:rea)?$/,M=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,T=/^(?:button|form|input|select|textarea)$/,I=/^(?:details|dialog)$/,P=/^host(?:-context)?$/,C=/^(?:checkbox|radio)$/,$=/^(?:date(?:time-local)?|month|number|range|time|week)$/,D=/^(?:button|reset)$/,U=/^(?:image|submit)$/,Q=/^(?:email|number|password|search|tel|text|url)$/;class J{#l;#c;#w;#t;#f;#n;#k;#o;#b;#h;#e;#d;#_;#m;#N;#s;#u;#r;#p;#i;#a;constructor(r){this.#a=r,this.#h=new F.Matcher,this.#c=new WeakMap,this.#f=new WeakMap,this.#b=new WeakMap,this.#N=new WeakMap,this.#n=null,this.#k=null,this._registerEventListeners()}onError(r,e={}){if(!(e.noexcept??this.#_))if(r instanceof DOMException||r instanceof this.#a.DOMException)if(r.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw new this.#a.DOMException(r.message,r.name);else throw r.name in this.#a?new this.#a[r.name](r.message):r}setup(r,e,f={}){const{event:n,noexcept:a,warn:l}=f;return this.#_=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#u=(0,k.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(r),this.#b=new WeakMap,this.#p=new WeakMap,this._setEvent(n),e}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],f=["mouseover","mousedown","mouseup","mouseout"];for(const a of f)e.push(this.#a.addEventListener(a,l=>{this.#n=l},r));const n=["keydown","keyup"];for(const a of n)e.push(this.#a.addEventListener(a,l=>{l.key===X&&(this.#n=l)},r));return e.push(this.#a.addEventListener("focusin",a=>{this.#k=a},r)),e}_setEvent(r){return(r instanceof this.#a.KeyboardEvent||r instanceof this.#a.MouseEvent)&&(this.#n=r),this.#n}_correspond(r){const e=[];this.#w=!1,this.#o=!1;let f;if(this.#f.has(this.#t)){const n=this.#f.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);f=a.ast,this.#w=a.descendant,this.#o=a.invalidate}}if(f){const n=f.length;for(let a=0;a<n;a++)f[a].collected=!1,f[a].dir=null,f[a].filtered=!1,f[a].find=!1,e[a]=[]}else{let n;try{n=(0,g.parseSelector)(r)}catch(b){this.onError(b)}const{branches:a,info:l}=(0,g.walkAST)(n),{hasHasPseudoFunc:o,hasLogicalPseudoFunc:u,hasNthChildOfSelector:d}=l;let i=o||!!(u&&d),s=!1,t=0;f=[];for(const[...b]of a){const m=[];let p=b.shift();if(p&&p.type!==c.COMBINATOR){const w=new Set;for(;p;){if(p.type===c.COMBINATOR){const[N]=b;if(N.type===c.COMBINATOR)throw new DOMException(`Invalid selector ${r}`,c.SYNTAX_ERR);const _=p.name;/^[\s>]$/.test(_)?s=!0:i=!0,m.push({combo:p,leaves:(0,g.sortAST)(w)}),w.clear()}else if(p){let{name:N}=p;N&&typeof N=="string"&&(N=(0,g.unescapeSelector)(N),typeof N=="string"&&N!==p.name&&(p.name=N),/[|:]/.test(N)&&(p.namespace=!0)),w.add(p)}if(b.length)p=b.shift();else{m.push({combo:null,leaves:(0,g.sortAST)(w)}),w.clear();break}}}f.push({branch:m,collected:!1,dir:null,filtered:!1,find:!1}),e[t]=[],t++}let h;this.#f.has(this.#t)?h=this.#f.get(this.#t):h=new Map,h.set(`${r}`,{ast:f,descendant:s,invalidate:i}),this.#f.set(this.#t,h),this.#w=s,this.#o=i}return[f,e]}_createTreeWalker(r){let e;return this.#p.has(r)?e=this.#p.get(r):(e=this.#t.createTreeWalker(r,c.WALKER_FILTER),this.#p.set(r,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(r,e,f){const{a:n,b:a,reverse:l,selector:o}=r,{parentNode:u}=e,d=new Set;let i;if(o){if(this.#c.has(o))i=this.#c.get(o);else{const{branches:t}=(0,g.walkAST)(o);i=t,this.#o||this.#c.set(o,i)}const{branches:s}=(0,g.walkAST)(o);i=s}if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();const b=new Set;if(i)for(t=(0,k.traverseNode)(u,s),t=s.firstChild();t;){if((0,k.isVisible)(t)){let m;for(const p of i)if(m=this._matchLeaves(p,t,f),!m)break;m&&b.add(t)}t=s.nextSibling()}if(n===0){if(a>0&&a<=h){if(b.size){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(b.has(t)){if(m===a-1){d.add(t);break}m++}l?t=s.previousSibling():t=s.nextSibling()}}else if(!o){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(m===a-1){d.add(t);break}l?t=s.previousSibling():t=s.nextSibling(),m++}}}}else{let m=a-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m<h){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let p=0,w=n>0?0:a-1;for(;t&&(t&&m>=0&&m<h);)b.size?b.has(t)&&(w===m&&(d.add(t),m+=n),n>0?w++:w--):p===m&&(o||d.add(t),m+=n),l?t=s.previousSibling():t=s.nextSibling(),p++}}if(l&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&n+a===1)if(i){let s;for(const t of i)if(s=this._matchLeaves(t,e,f),s)break;s&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:f,b:n,reverse:a}=r,{localName:l,namespaceURI:o,parentNode:u,prefix:d}=e,i=new Set;if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();if(f===0){if(n>0&&n<=h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let b=0;for(;t;){const{localName:m,namespaceURI:p,prefix:w}=t;if(m===l&&w===d&&p===o){if(b===n-1){i.add(t);break}b++}a?t=s.previousSibling():t=s.nextSibling()}}}else{let b=n-1;if(f>0)for(;b<0;)b+=f;if(b>=0&&b<h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let m=f>0?0:n-1;for(;t;){const{localName:p,namespaceURI:w,prefix:N}=t;if(p===l&&N===d&&w===o){if(m===b&&(i.add(t),b+=f),b<0||b>=h)break;f>0?m++:m--}a?t=s.previousSibling():t=s.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&f+n===1&&i.add(e);return i}_matchAnPlusB(r,e,f,n){const{nth:{a,b:l,name:o},selector:u}=r,d=new Map;if(o?(o==="even"?(d.set("a",2),d.set("b",0)):o==="odd"&&(d.set("a",2),d.set("b",1)),f.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),f.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(f)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,f={}){let n;if(Array.isArray(r)&&r.length){const a=r.map(t=>t),[l]=a,{type:o}=l;let u;o===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[t]=a,{type:h}=t;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};f.dir=v;const s=this._matchCombinator(i,e,f);if(s.size)if(a.length){for(const t of s)if(n=this._matchHasPseudoFunc(a,t,f),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,f={}){const{astName:n="",branches:a=[],selector:l="",twigBranches:o=[]}=r;let u;if(n==="has")if(l.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,f),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(n);f.forgive=d;const i=o.length;let s;for(let t=0;t<i;t++){const h=o[t],b=h.length-1,{leaves:m}=h[b];if(s=this._matchLeaves(m,e,f),s&&b>0){let p=new Set([e]);for(let w=b-1;w>=0;w--){const N=h[w],_=[];f.dir=x;for(const y of p){const E=this._matchCombinator(N,y,f);E.size&&_.push(...E)}if(_.length)w===0?s=!0:p=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(u=e):s&&(u=e)}return u??null}_matchPseudoClassSelector(r,e,f={}){const{children:n,name:a}=r,{localName:l,parentNode:o}=e,{forgive:u,warn:d=this.#i}=f,i=new Set;if(c.REG_LOGICAL.test(a)){let s;if(this.#c.has(r))s=this.#c.get(r);else{const{branches:h}=(0,g.walkAST)(r),b=[],m=[];for(const[...p]of h){for(const y of p){const E=(0,g.generateCSS)(y);b.push(E)}const w=[],N=new Set;let _=p.shift();for(;_;)if(_.type===c.COMBINATOR?(w.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),p.length)_=p.shift();else{w.push({combo:null,leaves:[...N]}),N.clear();break}m.push(w)}s={astName:a,branches:h,twigBranches:m,selector:b.join(",")},this.#o||this.#c.set(r,s)}const t=this._matchLogicalPseudoFunc(s,e,f);t&&i.add(t)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[s]=n;return this._matchAnPlusB(s,e,a,f)}else switch(a){case"dir":case"lang":{const s=this.#h.matchSelector(r,e,f,!0);s&&i.add(s);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:s}]=n;if(s)if(e[s])i.add(e);else for(const t in e){const h=e[t];if(h instanceof this.#a.ElementInternals){h?.states?.has(s)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,c.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{O.test(l)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(O.test(l)&&e.hasAttribute("href")){const{href:s,origin:t,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),s);b.origin===t&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:s,type:t}=this.#n??{};/^(?:mouse|pointer)(?:down|over|up)$/.test(t)&&e.contains(s)&&i.add(e);break}case"active":{const{buttons:s,target:t,type:h}=this.#n??{};/(?:mouse|pointer)down/.test(h)&&s&c.BIT_01&&e.contains(t)&&i.add(e);break}case"target":{const{hash:s}=new URL(this.#t.URL);e.id&&s===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:s}=new URL(this.#t.URL);if(s){const t=s.replace(/^#/,"");let h=this.#t.getElementById(t);for(;h;){if(h===e){i.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&e.tabIndex>=0&&(0,k.isFocusable)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&e.tabIndex>=0){let s;if((0,k.isFocusVisible)(e))s=!0;else{const{target:t,type:h}=this.#n??{},{target:b,relatedTarget:m}=this.#k??{};(/^key(?:down|up)$/.test(h)&&e.contains(t)||m&&(0,k.isFocusVisible)(m)&&e.contains(b))&&(s=!0)}s&&(0,k.isFocusable)(e)&&i.add(e)}break}case"focus-within":{let s,t=this.#t.activeElement;if(t.tabIndex>=0)for(;t;){if(t===e){s=!0;break}t=t.parentNode}s&&(0,k.isFocusable)(e)&&i.add(e);break}case"open":{I.test(l)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{I.test(l)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")o.localName==="optgroup"&&(o.disabled||o.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s&&i.add(e)}}break}case"enabled":{if((M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(o.localName!=="optgroup"||!(o.disabled||o.hasAttribute("disabled")))&&i.add(e);else{let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s||i.add(e)}break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let s;if(e.placeholder?s=e.placeholder:e.hasAttribute("placeholder")&&(s=e.getAttribute("placeholder")),typeof s=="string"&&!/[\r\n]/.test(s)){let t;l==="textarea"?t=e:l==="input"&&(e.hasAttribute("type")?Q.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;t||(t=this.#t.documentElement);const h=t.getElementsByTagName("input"),b=h.length;let m;for(let p=0;p<b;p++){const w=h[p];if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(m=!!w.checked):w.hasAttribute("name")||(m=!!w.checked),m))break}m||i.add(e)}break}case"default":{if(l==="button"&&!(e.hasAttribute("type")&&D.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&U.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const t=this.#r;let h=(0,k.traverseNode)(s,t);for(h=t.firstChild();h&&s.contains(h);){const b=h.localName;let m;if(b==="button"?m=!(h.hasAttribute("type")&&D.test(h.getAttribute("type"))):b==="input"&&(m=h.hasAttribute("type")&&U.test(h.getAttribute("type"))),m){h===e&&i.add(e);break}h=t.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(T.test(l))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h&&i.add(e)}break}case"invalid":{if(T.test(l))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h||i.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const s=this.#t.createTreeWalker(e,c.SHOW_ALL);let t=s.firstChild(),h;for(;t&&(h=t.nodeType!==c.ELEMENT_NODE&&t.nodeType!==c.TEXT_NODE,!!h);)t=s.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(o&&e===o.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(o&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(o&&e===o.firstElementChild&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,k.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d)throw new DOMException(`Unsupported pseudo-element ::${a}`,c.NOT_SUPPORTED_ERR);break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,c.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(r,e){const{children:f,name:n}=r;let a;if(Array.isArray(f)){const{branches:l}=(0,g.walkAST)(f[0]),[o]=l,[...u]=o,{host:d}=e;if(n==="host"){let i;for(const s of u){const{type:t}=s;if(t===c.COMBINATOR){const h=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(s,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,s;for(;i;){for(const t of u){const{type:h}=t;if(h===c.COMBINATOR){const b=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(s=this._matchSelector(t,i).has(i),!s)break}if(s)break;i=i.parentNode}s&&(a=e)}}else if(n==="host")a=e;else throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR);return a??null}_matchSelector(r,e,f){const{type:n}=r,a=new Set;if(r.name===c.EMPTY)return a;const l=(0,g.unescapeSelector)(r.name);if(typeof l=="string"&&l!==r.name&&(r.name=l),e.nodeType===c.ELEMENT_NODE)switch(n){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(l,f);break}case c.ID_SELECTOR:{e.id===l&&a.add(e);break}case c.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case c.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(r,e,f);default:{const o=this.#h.matchSelector(r,e,f,!0);o&&a.add(o)}}else if(this.#u&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&c.REG_LOGICAL.test(l))return this._matchPseudoClassSelector(r,e,f);if(P.test(l)){const o=this._matchShadowHostPseudoClass(r,e,f);o&&a.add(o)}}return a}_matchLeaves(r,e,f){let n,a;if(this.#o?a=this.#b.get(r):a=this.#N.get(r),a&&a.has(e)){const{matched:l}=a.get(e);n=l}if(typeof n!="boolean"){let l=!0;e.nodeType===c.ELEMENT_NODE&&/^(?:button|fieldset|form|input|select|textarea)$/.test(e.localName)&&(l=!1);for(const o of r){switch(o.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{/^(?:(?:any-)?link|defined|dir)$/.test(o.name)&&(l=!1);break}default:}if(n=this._matchSelector(o,e,f).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#o?this.#b.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e={}){const{compound:f,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(f)for(let o=0;o<l;o++){const u=r[o];this._matchLeaves(n,u,e)&&a.add(u)}else{const o=[].slice.call(r);return new Set(o)}return a}_findDescendantNodes(r,e,f){const[n,...a]=r,l=a.length>0,{type:o}=n,u=(0,g.unescapeSelector)(n.name);typeof u=="string"&&u!==n.name&&(n.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(o){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,f);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const s=this.#s.getElementById(u);s&&s!==e&&e.contains(s)&&(l?this._matchLeaves(a,s,f)&&d.add(s):d.add(s))}break}case c.CLASS_SELECTOR:{const s=e.getElementsByClassName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const s=e.getElementsByTagName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,f={}){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:o}=e,{dir:u}=f,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(e,i);for(s=i.nextSibling();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let s=(0,k.traverseNode)(e,i);for(s=i.firstChild();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling();break}case" ":default:{const{nodes:i,pending:s}=this._findDescendantNodes(a,e);if(i.size)return i;if(s){const t=this._createTreeWalker(e);let h=(0,k.traverseNode)(e,t);for(h=t.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,f)&&d.add(h),h=t.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(o,i);for(s=i.firstChild();s&&s!==e;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{o&&this._matchLeaves(a,o,f)&&d.add(o);break}case" ":default:{const i=[];let s=o;for(;s;)this._matchLeaves(a,s,f)&&i.push(s),s=s.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const{node:f}=e,n=this.#m;let a=(0,k.traverseNode)(f,n),l;if(a)for((a.nodeType!==c.ELEMENT_NODE||a===f&&a!==this.#s)&&(a=n.nextNode());a;){if(this._matchLeaves(r,a,{warn:this.#i})){l=a;break}a=n.nextNode()}return l??null}_matchSelf(r){const e=[],f=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return f&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e={}){const{complex:f}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||f){let o=this.#e.parentNode;for(;o&&(a=this._matchLeaves(r,o,{warn:this.#i}),a&&(n.push(o),l=!0),o.parentNode);)o=o.parentNode}return[n,l]}_findFirst(r){const e=[],f=this._findNode(r,{node:this.#e});let n=!1;return f&&(e.push(f),n=!0),[e,n]}_findFromHTMLCollection(r,e={}){const{complex:f,compound:n,filterLeaves:a,targetType:l}=e;let o=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let s=0;s<i;s++){const t=r[s];if(t!==this.#e&&(this.#e.contains(t)||t.contains(this.#e))){if(n){if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else if(o.push(t),u=!0,l===c.TARGET_FIRST)break}}else if(f)if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;else if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;return[o,u,d]}_findEntryNodes(r,e,f){const{leaves:n}=r,[a,...l]=n,o=l.length>0,{name:u,type:d}=a;let i=[],s=!1,t=!1,h=!1;switch(d){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,{warn:this.#i});break}case c.ID_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(o?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),t=!0):(i.push(b),t=!0))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}default:if(e!==c.TARGET_LINEAL&&P.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),t=!0)}}else e===c.TARGET_SELF?[i,t]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,t]=this._findLineal(n,{complex:f}):e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0}return{collected:s,compound:o,filtered:t,nodes:i,pending:h}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const f=new Set;let n=0;for(const{branch:a}of e){const l=a.length,o=l>1,u=a[0];let d,i;if(o){const{combo:p,leaves:[{name:w,type:N}]}=u,_=a[l-1],{leaves:[{name:y,type:E}]}=_;if(E===c.PS_ELEMENT_SELECTOR||E===c.ID_SELECTOR)d=x,i=_;else if(N===c.PS_ELEMENT_SELECTOR||N===c.ID_SELECTOR)d=v,i=u;else if(r===c.TARGET_ALL)if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:A}=p;/^[+~]$/.test(A)?(d=x,i=_):(d=v,i=u)}else d=v,i=u;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else{let A;for(const{combo:L,leaves:[W]}of a){const{name:G,type:H}=W;if(H===c.PS_CLASS_SELECTOR&&G==="dir"){A=!1;break}if(!A&&L){const{name:z}=L;/^[+~]$/.test(z)&&(A=!0)}}A?(d=v,i=u):(d=x,i=_)}}else d=x,i=u;const{collected:s,compound:t,filtered:h,nodes:b,pending:m}=this._findEntryNodes(i,r,o);b.length?(this.#l[n].find=!0,this.#d[n]=b):m&&f.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=s,this.#l[n].dir=d,this.#l[n].filtered=h||!t,n++}if(f.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,l=this.#m):(a=this.#s,l=this.#r);let o=(0,k.traverseNode)(a,l);for(;o;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?o===this.#e?u=!0:u=this.#e.contains(o):u=!0,u)for(const d of f){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,o,{warn:this.#i})){const t=d.get("index");this.#l[t].filtered=!0,this.#l[t].find=!0,this.#d[t].push(o)}}o!==l.currentNode&&(o=(0,k.traverseNode)(o,l)),o=l.nextNode()}}}else{let f=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:o,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[f].find=!0,this.#d[f]=d),this.#l[f].dir=x,this.#l[f].filtered=u||!o,f++}}return[this.#l,this.#d]}_getCombinedNodes(r,e,f){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:f,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,f){const{combo:n,index:a}=f,{combo:l,leaves:o}=r[a],u={combo:n,leaves:o},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===r.length-1){const[s]=(0,k.sortNodes)(d);i=s}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,f){const{index:n}=f,a=r[n],l=new Set([e]),o=this._getCombinedNodes(a,l,x);let u;if(o.size){if(n===0)u=e;else for(const d of o)if(this._matchNodePrev(r,d,{index:n-1}))return e}return u??null}find(r){(r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let o=0;o<n;o++){const{branch:u,collected:d,dir:i,find:s}=e[o],t=u.length;if(t&&s){const h=f[o],b=h.length,m=t-1;if(m===0)if((r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this.#e.nodeType===c.ELEMENT_NODE)for(let p=0;p<b;p++){const w=h[p];if(w!==this.#e&&this.#e.contains(w)&&(l.add(w),r!==c.TARGET_ALL))break}else if(r===c.TARGET_ALL)if(l.size){const p=[...l];l=new Set([...p,...h]),a=!0}else l=new Set(h);else{const[p]=h;l.add(p)}else if(r===c.TARGET_ALL)if(i===v){let{combo:p}=u[0];for(const w of h){let N=new Set([w]);for(let _=1;_<t;_++){const{combo:y,leaves:E}=u[_],A={combo:p,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(l.size){const L=[...l];l=new Set([...L,...N]),a=!0}else l=N;else p=y;else break}}}else for(const p of h){let w=new Set([p]);for(let N=m-1;N>=0;N--){const _=u[N];if(w=this._getCombinedNodes(_,w,i),w.size)N===0&&(l.add(p),t>1&&l.size>1&&(a=!0));else break}}else if(r===c.TARGET_FIRST&&i===v){const{combo:p}=u[0];let w;for(const N of h)if(w=this._matchNodeNext(u,new Set([N]),{combo:p,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:N}=u[0],[_]=h;let y=this._findNode(N,{node:_});for(;y;){if(w=this._matchNodeNext(u,new Set([y]),{combo:p,index:1}),w){l.add(w);break}y=this._findNode(N,{node:y})}}}else{let p;for(const w of h)if(p=this._matchNodePrev(u,w,{index:m-1}),p){l.add(w);break}if(!p&&!d&&r===c.TARGET_FIRST){const{leaves:w}=u[m],[N]=h;let _=this._findNode(w,{node:N});for(;_;){if(p=this._matchNodePrev(u,_,{index:m-1}),p){l.add(_);break}_=this._findNode(w,{node:_})}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,k.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,k.sortNodes)(l)))),l}}0&&(module.exports={Finder});
|
|
2
2
|
//# sourceMappingURL=finder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/finder.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport { Matcher } from './matcher.js';\nimport {\n generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\nimport {\n isContentEditable, isCustomElement, isFocusVisible, isFocusable,\n isInShadowTree, isVisible, resolveContent, sortNodes, traverseNode\n} from './utility.js';\n\n/* constants */\nimport {\n ATTR_SELECTOR, BIT_01, CLASS_SELECTOR, COMBINATOR, DOCUMENT_FRAGMENT_NODE,\n DOCUMENT_NODE, ELEMENT_NODE, EMPTY, ID_SELECTOR, NOT_SUPPORTED_ERR,\n PS_CLASS_SELECTOR, PS_ELEMENT_SELECTOR, REG_INPUT_TYPE, REG_LOGICAL,\n SHOW_ALL, SYNTAX_ERR, TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF,\n TEXT_NODE, TYPE_SELECTOR, WALKER_FILTER\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\nconst KEY_TAB = 'Tab';\nconst REG_ANCHOR = /^a(?:rea)?$/;\nconst REG_FORM_CTRL =\n /^(?:button|fieldset|input|optgroup|option|select|textarea)$/;\nconst REG_FORM_VALID = /^(?:button|form|input|select|textarea)$/;\nconst REG_INTERACT = /^(?:details|dialog)$/;\nconst REG_SHADOW_HOST = /^host(?:-context)?$/;\nconst REG_TYPE_CHECK = /^(?:checkbox|radio)$/;\nconst REG_TYPE_RANGE = /^(?:date(?:time-local)?|month|number|range|time|week)$/;\nconst REG_TYPE_RESET = /^(?:button|reset)$/;\nconst REG_TYPE_SUBMIT = /^(?:image|submit)$/;\nconst REG_TYPE_TEXT = /^(?:email|number|password|search|tel|text|url)$/;\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: Array<Ast | undefined>\n * #nodes: Array<Nodes>\n * Ast: {\n * branch: Array<Branch | undefined>,\n * collected: boolean,\n * dir: string | null,\n * filtered: boolean,\n * find: boolean\n * }\n * Branch: Array<Twig>\n * Twig: {\n * combo: Leaf | null,\n * leaves: Array<Leaf>\n * }\n * Leaf: {\n * children: Array<Leaf | undefined> | null,\n * loc: null,\n * type: string\n * }\n * Nodes: Array<HTMLElement | undefined>\n */\nexport class Finder {\n /* private fields */\n #ast;\n #astCache;\n #descendant;\n #document;\n #documentCache;\n #event;\n #focus;\n #invalidate;\n #invalidateResults;\n #matcher;\n #node;\n #nodes;\n #noexcept;\n #qswalker;\n #results;\n #root;\n #shadow;\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.#matcher = new Matcher();\n this.#astCache = new WeakMap();\n this.#documentCache = new WeakMap();\n this.#invalidateResults = new WeakMap();\n this.#results = new WeakMap();\n this.#event = null;\n this.#focus = null;\n this._registerEventListeners();\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @param {object} opt - options\n * @throws Error\n * @returns {void}\n */\n onError(e, opt = {}) {\n const noexcept = opt.noexcept ?? this.#noexcept;\n if (!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 if (e.name in this.#window) {\n throw new this.#window[e.name](e.message);\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {object} [opt.event] - MouseEvent, KeyboardEvent\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 { event, noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#node = node;\n [this.#document, this.#root, this.#walker] = resolveContent(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#invalidateResults = new WeakMap();\n this.#walkers = new WeakMap();\n this._setEvent(event);\n return node;\n }\n\n /**\n * register event listeners\n * @private\n * @returns {Array.<void>} - results\n */\n _registerEventListeners() {\n const opt = {\n capture: true,\n passive: true\n };\n const func = [];\n const mouseKeys = ['mouseover', 'mousedown', 'mouseup', 'mouseout'];\n for (const key of mouseKeys) {\n func.push(this.#window.addEventListener(key, evt => {\n this.#event = evt;\n }, opt));\n }\n const keyboardKeys = ['keydown', 'keyup'];\n for (const key of keyboardKeys) {\n func.push(this.#window.addEventListener(key, evt => {\n if (evt.key === KEY_TAB) {\n this.#event = evt;\n }\n }, opt));\n }\n func.push(this.#window.addEventListener('focusin', evt => {\n this.#focus = evt;\n }, opt));\n return func;\n }\n\n /**\n * set event\n * @private\n * @param {object} event - instance of KeyboardEvent, MouseEvent\n * @returns {object} - event\n */\n _setEvent(event) {\n // NOTE: PointerEvent not implemented in jsdom\n if (event instanceof this.#window.KeyboardEvent ||\n event instanceof this.#window.MouseEvent) {\n this.#event = event;\n }\n return this.#event;\n }\n\n /**\n * correspond ast and nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _correspond(selector) {\n const nodes = [];\n this.#descendant = false;\n this.#invalidate = false;\n let ast;\n if (this.#documentCache.has(this.#document)) {\n const cachedItem = this.#documentCache.get(this.#document);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n const item = cachedItem.get(`${selector}`);\n ast = item.ast;\n this.#descendant = item.descendant;\n this.#invalidate = item.invalidate;\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 {\n branches, info: { hasHasPseudoFunc, hasNthChildOfSelector }\n } = walkAST(cssAst);\n let invalidate = !!(hasHasPseudoFunc || hasNthChildOfSelector);\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 throw new DOMException(`Invalid selector ${selector}`,\n SYNTAX_ERR);\n }\n const itemName = item.name;\n if (/^[\\s>]$/.test(itemName)) {\n descendant = true;\n } else {\n invalidate = 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 let cachedItem;\n if (this.#documentCache.has(this.#document)) {\n cachedItem = this.#documentCache.get(this.#document);\n } else {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, {\n ast,\n descendant,\n invalidate\n });\n this.#documentCache.set(this.#document, cachedItem);\n this.#descendant = descendant;\n this.#invalidate = invalidate;\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 return this.#qswalker;\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.<object>} - 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 const { branches } = walkAST(selector);\n selectorBranches = branches;\n }\n if (parentNode) {\n const walker = this.#walker;\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n const selectorNodes = new Set();\n if (selectorBranches) {\n refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (isVisible(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 }\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 = traverseNode(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 = traverseNode(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 = traverseNode(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.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, namespaceURI, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const walker = this.#walker;\n let refNode = traverseNode(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 = traverseNode(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 {\n localName: itemLocalName, namespaceURI: itemNamespaceURI,\n prefix: itemPrefix\n } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix &&\n itemNamespaceURI === namespaceURI) {\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 = traverseNode(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 {\n localName: itemLocalName, namespaceURI: itemNamespaceURI,\n prefix: itemPrefix\n } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix &&\n itemNamespaceURI === namespaceURI) {\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.<object>} - 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.<object>} astLeaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(astLeaves, node, opt = {}) {\n let bool;\n if (Array.isArray(astLeaves) && astLeaves.length) {\n const leaves = astLeaves.map(i => i);\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(leaves, 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(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.<object>} - 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.test(astName)) {\n let astData;\n if (this.#astCache.has(ast)) {\n astData = this.#astCache.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.#astCache.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 = this.#matcher.matchSelector(ast, node, opt, true);\n if (res) {\n matched.add(res);\n }\n break;\n }\n // :state()\n case 'state': {\n if (isCustomElement(node)) {\n const [{ value: stateValue }] = astChildren;\n if (stateValue) {\n if (node[stateValue]) {\n matched.add(node);\n } else {\n for (const i in node) {\n const prop = node[i];\n if (prop instanceof this.#window.ElementInternals) {\n if (prop?.states?.has(stateValue)) {\n matched.add(node);\n }\n break;\n }\n }\n }\n }\n }\n break;\n }\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // dropped from CSS Selectors 3\n case 'contains': {\n if (warn) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const { href, origin, pathname } = new URL(this.#document.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'hover': {\n const { target, type } = this.#event ?? {};\n if (/^(?:mouse|pointer)(?:down|over|up)$/.test(type) &&\n node.contains(target)) {\n matched.add(node);\n }\n break;\n }\n case 'active': {\n const { buttons, target, type } = this.#event ?? {};\n if (/(?:mouse|pointer)down/.test(type) && buttons & BIT_01 &&\n node.contains(target)) {\n matched.add(node);\n }\n break;\n }\n case 'target': {\n const { hash } = new URL(this.#document.URL);\n if (node.id && hash === `#${node.id}` &&\n this.#document.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(this.#document.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = this.#document.getElementById(id);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (!this.#shadow && node === this.#node) {\n matched.add(node);\n }\n } else if (node === this.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === this.#document.activeElement && node.tabIndex >= 0 &&\n isFocusable(node)) {\n matched.add(node);\n }\n break;\n }\n case 'focus-visible': {\n if (node === this.#document.activeElement && node.tabIndex >= 0) {\n let bool;\n if (isFocusVisible(node)) {\n bool = true;\n } else {\n const { target: eventTarget, type } = this.#event ?? {};\n const { target: focusTarget, relatedTarget } = this.#focus ?? {};\n if (/^key(?:down|up)$/.test(type) && node.contains(eventTarget)) {\n bool = true;\n } else if (relatedTarget && isFocusVisible(relatedTarget) &&\n node.contains(focusTarget)) {\n bool = true;\n }\n }\n if (bool && isFocusable(node)) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let bool;\n let current = this.#document.activeElement;\n if (current.tabIndex >= 0) {\n while (current) {\n if (current === node) {\n bool = true;\n break;\n }\n current = current.parentNode;\n }\n }\n if (bool && isFocusable(node)) {\n matched.add(node);\n }\n break;\n }\n case 'open': {\n if (REG_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (REG_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (REG_FORM_CTRL.test(localName) ||\n isCustomElement(node, { formAssociated: true })) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else if (node.localName === 'option') {\n if (parentNode.localName === 'optgroup' &&\n (parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n matched.add(node);\n }\n } else if (node.localName !== 'optgroup') {\n let bool;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n const walker = this.#walker;\n let refNode = traverseNode(parent, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.localName === 'legend') {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (refNode) {\n if (!refNode.contains(node)) {\n bool = true;\n }\n } else {\n bool = true;\n }\n break;\n } else if (parent.localName === 'form') {\n break;\n } else if (parent.parentNode?.nodeType === ELEMENT_NODE) {\n if (parent.parentNode.localName === 'form') {\n break;\n } else {\n parent = parent.parentNode;\n }\n } else {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((REG_FORM_CTRL.test(localName) ||\n isCustomElement(node, { formAssociated: true })) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n if (node.localName === 'optgroup') {\n matched.add(node);\n } else if (node.localName === 'option') {\n if (parentNode.localName !== 'optgroup' ||\n !(parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n matched.add(node);\n }\n } else {\n let bool;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n const walker = this.#walker;\n let refNode = traverseNode(parent, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.localName === 'legend') {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (refNode) {\n if (!refNode.contains(node)) {\n bool = true;\n }\n } else {\n bool = true;\n }\n break;\n } else if (parent.localName === 'form') {\n break;\n } else if (parent.parentNode?.nodeType === ELEMENT_NODE) {\n if (parent.parentNode.localName === 'form') {\n break;\n } else {\n parent = parent.parentNode;\n }\n } else {\n break;\n }\n }\n if (!bool) {\n matched.add(node);\n }\n }\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 || REG_INPUT_TYPE.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 || REG_INPUT_TYPE.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 placeholder;\n if (node.placeholder) {\n placeholder = node.placeholder;\n } else if (node.hasAttribute('placeholder')) {\n placeholder = node.getAttribute('placeholder');\n }\n if (typeof placeholder === 'string' && !/[\\r\\n]/.test(placeholder)) {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (REG_TYPE_TEXT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '') {\n matched.add(node);\n }\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n REG_TYPE_CHECK.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.#document.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 // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n REG_TYPE_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_SUBMIT.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const walker = this.#walker;\n let nextNode = traverseNode(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 REG_TYPE_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n REG_TYPE_SUBMIT.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 REG_TYPE_CHECK.test(node.getAttribute('type')) &&\n node.hasAttribute('checked')) {\n matched.add(node);\n // option\n } else if (localName === 'option' && node.hasAttribute('selected')) {\n matched.add(node);\n }\n break;\n }\n case 'valid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0) {\n if (node.maxLength >= node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0 && node.maxLength < node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\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 REG_TYPE_RANGE.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n REG_TYPE_RANGE.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_INPUT_TYPE.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' || REG_TYPE_CHECK.test(inputType) ||\n REG_INPUT_TYPE.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.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n let bool;\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'defined': {\n if (node.hasAttribute('is') || localName.includes('-')) {\n if (isCustomElement(node)) {\n matched.add(node);\n }\n // NOTE: MathMLElement not implemented in jsdom\n } else if (node instanceof this.#window.HTMLElement ||\n node instanceof this.#window.SVGElement) {\n matched.add(node);\n }\n break;\n }\n case 'popover-open': {\n if (node.popover && isVisible(node)) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n // not supported\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'fullscreen':\n case 'future':\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 throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match 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 { branches } = walkAST(astChildren[0]);\n const [branch] = branches;\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n throw new DOMException(`Invalid selector :${astName}`, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const 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 PS_ELEMENT_SELECTOR: {\n this.#matcher.matchPseudoElementSelector(astName, opt);\n break;\n }\n case ID_SELECTOR: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case CLASS_SELECTOR: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case PS_CLASS_SELECTOR: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n }\n default: {\n const res = this.#matcher.matchSelector(ast, node, opt, true);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#shadow && astType === PS_CLASS_SELECTOR &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL.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.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n let result;\n if (this.#invalidate) {\n result = this.#invalidateResults.get(leaves);\n } else {\n result = this.#results.get(leaves);\n }\n if (result && result.has(node)) {\n const { matched } = result.get(node);\n bool = matched;\n }\n if (typeof bool !== 'boolean') {\n let cacheable = true;\n if (node.nodeType === ELEMENT_NODE &&\n /^(?:button|fieldset|form|input|select|textarea)$/.test(node.localName)) {\n cacheable = false;\n }\n for (const leaf of leaves) {\n switch (leaf.type) {\n case ATTR_SELECTOR:\n case ID_SELECTOR: {\n cacheable = false;\n break;\n }\n case PS_CLASS_SELECTOR: {\n if (/^(?:(?:any-)?link|defined|dir)$/.test(leaf.name)) {\n cacheable = false;\n }\n break;\n }\n default:\n }\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n if (cacheable) {\n if (!result) {\n result = new WeakMap();\n }\n result.set(node, {\n matched: bool\n });\n if (this.#invalidate) {\n this.#invalidateResults.set(leaves, result);\n } else {\n this.#results.set(leaves, result);\n }\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.<object>} - 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.<object>} 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 PS_ELEMENT_SELECTOR: {\n this.#matcher.matchPseudoElementSelector(leafName, opt);\n break;\n }\n case ID_SELECTOR: {\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 CLASS_SELECTOR: {\n const items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case TYPE_SELECTOR: {\n if (this.#document.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.<object>} - 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 = traverseNode(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 = traverseNode(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 = traverseNode(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 = traverseNode(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.<object>} 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 const walker = this.#qswalker;\n let refNode = traverseNode(node, walker);\n let matchedNode;\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = walker.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = walker.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 = walker.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 PS_ELEMENT_SELECTOR: {\n this.#matcher.matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case ID_SELECTOR: {\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 CLASS_SELECTOR: {\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 TYPE_SELECTOR: {\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.#document.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const 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 === PS_ELEMENT_SELECTOR ||\n lastType === ID_SELECTOR) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === PS_ELEMENT_SELECTOR ||\n firstType === ID_SELECTOR) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === TYPE_SELECTOR) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === TYPE_SELECTOR) {\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 === TYPE_SELECTOR) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === TYPE_SELECTOR) {\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 === PS_CLASS_SELECTOR && leafName === 'dir') {\n bool = false;\n break;\n }\n if (!bool && combo) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n const {\n collected, compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].collected = collected;\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#qswalker;\n } else {\n node = this.#root;\n walker = this.#walker;\n }\n let nextNode = traverseNode(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 = traverseNode(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.<object>} - 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.<object>} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], collectedNodes] = this._collectNodes(targetType);\n const l = branches.length;\n let sort;\n let nodes = 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 = collectedNodes[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 nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...entryNodes]);\n sort = true;\n } else {\n nodes = new Set(entryNodes);\n }\n } else {\n const [node] = entryNodes;\n nodes.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 (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...nextNodes]);\n sort = true;\n } else {\n nodes = 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 nodes.add(node);\n if (branchLen > 1 && nodes.size > 1) {\n 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 nodes.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 nodes.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 nodes.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 nodes.add(refNode);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n }\n }\n }\n if (targetType === TARGET_FIRST) {\n nodes.delete(this.#node);\n if (nodes.size > 1) {\n nodes = new Set(sortNodes(nodes));\n }\n } else if (targetType === TARGET_ALL) {\n nodes.delete(this.#node);\n if (sort && nodes.size > 1) {\n nodes = new Set(sortNodes(nodes));\n }\n }\n if (this.#invalidate) {\n this.#invalidateResults = new WeakMap();\n }\n return nodes;\n }\n};\n"],
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAwB,wBACxBC,EAEO,uBACPC,EAGO,wBAGPC,EAMO,yBACP,MAAMC,EAAW,OACXC,EAAW,OACXC,EAAU,MACVC,EAAa,cACbC,EACJ,8DACIC,EAAiB,0CACjBC,EAAe,uBACfC,EAAkB,s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K,eAAeV,EAAQtB,EAAM,CAC1C,MAAO8D,EAAY,CACrB,CAAC,EACG9B,EAAS,CACXvB,EAAM,IAAIT,CAAI,EACd,KACF,CAEF,GAAI,CAACgC,GAAW,CAAC4E,GAAaD,IAAe,eAAc,CACzD,KAAM,CAAE,OAAQqB,CAAY,EAAI1G,EAAOwC,CAAS,EAC1C,CAACmE,CAAS,EAAIL,EACpB,IAAI1F,EAAU,KAAK,UAAU8F,EAAa,CACxC,KAAMC,CACR,CAAC,EACD,KAAO/F,GAAS,CAId,GAHAF,EAAU,KAAK,eAAeV,EAAQY,EAAS,CAC7C,MAAO4B,EAAY,CACrB,CAAC,EACG9B,EAAS,CACXvB,EAAM,IAAIyB,CAAO,EACjB,KACF,CACAA,EAAU,KAAK,UAAU8F,EAAa,CACpC,KAAM9F,CACR,CAAC,CACH,CACF,CACF,CACF,CACF,CACA,OAAIyE,IAAe,gBACjBlG,EAAM,OAAO,KAAKxB,EAAK,EACnBwB,EAAM,KAAO,IACfA,EAAQ,IAAI,OAAI,aAAUA,CAAK,CAAC,IAEzBkG,IAAe,eACxBlG,EAAM,OAAO,KAAKxB,EAAK,EACnByI,GAAQjH,EAAM,KAAO,IACvBA,EAAQ,IAAI,OAAI,aAAUA,CAAK,CAAC,IAGhC,KAAK3B,KACP,KAAKC,GAAqB,IAAI,SAEzB0B,CACT,CACF",
|
|
6
|
-
"names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_matcher", "import_parser", "import_utility", "import_constant", "DIR_NEXT", "DIR_PREV", "KEY_TAB", "REG_ANCHOR", "REG_FORM_CTRL", "REG_FORM_VALID", "REG_INTERACT", "REG_SHADOW_HOST", "REG_TYPE_CHECK", "REG_TYPE_RANGE", "REG_TYPE_RESET", "REG_TYPE_SUBMIT", "REG_TYPE_TEXT", "#ast", "#astCache", "#descendant", "#document", "#documentCache", "#event", "#focus", "#invalidate", "#invalidateResults", "#matcher", "#node", "#nodes", "#noexcept", "#qswalker", "#results", "#root", "#shadow", "#walker", "#walkers", "#warn", "#window", "window", "e", "opt", "selector", "node", "event", "noexcept", "warn", "func", "mouseKeys", "key", "evt", "keyboardKeys", "nodes", "ast", "cachedItem", "item", "l", "i", "cssAst", "branches", "hasHasPseudoFunc", "hasNthChildOfSelector", "invalidate", "descendant", "items", "branch", "leaves", "nextItem", "itemName", "walker", "anb", "a", "b", "reverse", "parentNode", "matched", "selectorBranches", "refNode", "selectorNodes", "bool", "nth", "j", "localName", "namespaceURI", "prefix", "itemLocalName", "itemNamespaceURI", "itemPrefix", "m", "nthName", "nthIdentName", "anbMap", "astLeaves", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "astName", "twigBranches", "res", "forgive", "lastIndex", "nextNodes", "arr", "astChildren", "selectors", "css", "leavesSet", "stateValue", "prop", "href", "origin", "pathname", "attrURL", "target", "type", "buttons", "hash", "id", "current", "eventTarget", "focusTarget", "relatedTarget", "parent", "placeholder", "targetNode", "nodeName", "checked", "form", "inputType", "node1", "node2", "host", "astType", "result", "cacheable", "compound", "filterLeaves", "baseNode", "leafName", "pending", "comboName", "dir", "matchedNode", "filtered", "complex", "targetType", "collected", "pendingItems", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "pendingItem", "index", "nextCombo", "collectedNodes", "sort", "find", "entryNodes", "entryNodesLen", "n", "entryCombo", "entryLeaves", "entryNode"]
|
|
4
|
+
"sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport { Matcher } from './matcher.js';\nimport {\n generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\nimport {\n isContentEditable, isCustomElement, isFocusVisible, isFocusable,\n isInShadowTree, isVisible, resolveContent, sortNodes, traverseNode\n} from './utility.js';\n\n/* constants */\nimport {\n ATTR_SELECTOR, BIT_01, CLASS_SELECTOR, COMBINATOR, DOCUMENT_FRAGMENT_NODE,\n DOCUMENT_NODE, ELEMENT_NODE, EMPTY, ID_SELECTOR, NOT_SUPPORTED_ERR,\n PS_CLASS_SELECTOR, PS_ELEMENT_SELECTOR, REG_INPUT_TYPE, REG_LOGICAL,\n SHOW_ALL, SYNTAX_ERR, TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF,\n TEXT_NODE, TYPE_SELECTOR, WALKER_FILTER\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\nconst KEY_TAB = 'Tab';\nconst REG_ANCHOR = /^a(?:rea)?$/;\nconst REG_FORM_CTRL =\n /^(?:button|fieldset|input|optgroup|option|select|textarea)$/;\nconst REG_FORM_VALID = /^(?:button|form|input|select|textarea)$/;\nconst REG_INTERACT = /^(?:details|dialog)$/;\nconst REG_SHADOW_HOST = /^host(?:-context)?$/;\nconst REG_TYPE_CHECK = /^(?:checkbox|radio)$/;\nconst REG_TYPE_RANGE = /^(?:date(?:time-local)?|month|number|range|time|week)$/;\nconst REG_TYPE_RESET = /^(?:button|reset)$/;\nconst REG_TYPE_SUBMIT = /^(?:image|submit)$/;\nconst REG_TYPE_TEXT = /^(?:email|number|password|search|tel|text|url)$/;\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: Array<Ast | undefined>\n * #nodes: Array<Nodes>\n * Ast: {\n * branch: Array<Branch | undefined>,\n * collected: boolean,\n * dir: string | null,\n * filtered: boolean,\n * find: boolean\n * }\n * Branch: Array<Twig>\n * Twig: {\n * combo: Leaf | null,\n * leaves: Array<Leaf>\n * }\n * Leaf: {\n * children: Array<Leaf | undefined> | null,\n * loc: null,\n * type: string\n * }\n * Nodes: Array<HTMLElement | undefined>\n */\nexport class Finder {\n /* private fields */\n #ast;\n #astCache;\n #descendant;\n #document;\n #documentCache;\n #event;\n #focus;\n #invalidate;\n #invalidateResults;\n #matcher;\n #node;\n #nodes;\n #noexcept;\n #qswalker;\n #results;\n #root;\n #shadow;\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.#matcher = new Matcher();\n this.#astCache = new WeakMap();\n this.#documentCache = new WeakMap();\n this.#invalidateResults = new WeakMap();\n this.#results = new WeakMap();\n this.#event = null;\n this.#focus = null;\n this._registerEventListeners();\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @param {object} opt - options\n * @throws Error\n * @returns {void}\n */\n onError(e, opt = {}) {\n const noexcept = opt.noexcept ?? this.#noexcept;\n if (!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 if (e.name in this.#window) {\n throw new this.#window[e.name](e.message);\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {object} [opt.event] - MouseEvent, KeyboardEvent\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 { event, noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#node = node;\n [this.#document, this.#root, this.#walker] = resolveContent(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#invalidateResults = new WeakMap();\n this.#walkers = new WeakMap();\n this._setEvent(event);\n return node;\n }\n\n /**\n * register event listeners\n * @private\n * @returns {Array.<void>} - results\n */\n _registerEventListeners() {\n const opt = {\n capture: true,\n passive: true\n };\n const func = [];\n const mouseKeys = ['mouseover', 'mousedown', 'mouseup', 'mouseout'];\n for (const key of mouseKeys) {\n func.push(this.#window.addEventListener(key, evt => {\n this.#event = evt;\n }, opt));\n }\n const keyboardKeys = ['keydown', 'keyup'];\n for (const key of keyboardKeys) {\n func.push(this.#window.addEventListener(key, evt => {\n if (evt.key === KEY_TAB) {\n this.#event = evt;\n }\n }, opt));\n }\n func.push(this.#window.addEventListener('focusin', evt => {\n this.#focus = evt;\n }, opt));\n return func;\n }\n\n /**\n * set event\n * @private\n * @param {object} event - instance of KeyboardEvent, MouseEvent\n * @returns {object} - event\n */\n _setEvent(event) {\n // NOTE: PointerEvent not implemented in jsdom\n if (event instanceof this.#window.KeyboardEvent ||\n event instanceof this.#window.MouseEvent) {\n this.#event = event;\n }\n return this.#event;\n }\n\n /**\n * correspond ast and nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _correspond(selector) {\n const nodes = [];\n this.#descendant = false;\n this.#invalidate = false;\n let ast;\n if (this.#documentCache.has(this.#document)) {\n const cachedItem = this.#documentCache.get(this.#document);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n const item = cachedItem.get(`${selector}`);\n ast = item.ast;\n this.#descendant = item.descendant;\n this.#invalidate = item.invalidate;\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, info } = walkAST(cssAst);\n const {\n hasHasPseudoFunc, hasLogicalPseudoFunc, hasNthChildOfSelector\n } = info;\n let invalidate =\n hasHasPseudoFunc || !!(hasLogicalPseudoFunc && hasNthChildOfSelector);\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 throw new DOMException(`Invalid selector ${selector}`,\n SYNTAX_ERR);\n }\n const itemName = item.name;\n if (/^[\\s>]$/.test(itemName)) {\n descendant = true;\n } else {\n invalidate = 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 let cachedItem;\n if (this.#documentCache.has(this.#document)) {\n cachedItem = this.#documentCache.get(this.#document);\n } else {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, {\n ast,\n descendant,\n invalidate\n });\n this.#documentCache.set(this.#document, cachedItem);\n this.#descendant = descendant;\n this.#invalidate = invalidate;\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 return this.#qswalker;\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.<object>} - 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.#astCache.has(selector)) {\n selectorBranches = this.#astCache.get(selector);\n } else {\n const { branches } = walkAST(selector);\n selectorBranches = branches;\n if (!this.#invalidate) {\n this.#astCache.set(selector, selectorBranches);\n }\n }\n const { branches } = walkAST(selector);\n selectorBranches = branches;\n }\n if (parentNode) {\n const walker = this.#walker;\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n const selectorNodes = new Set();\n if (selectorBranches) {\n refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (isVisible(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 }\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 = traverseNode(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 = traverseNode(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 = traverseNode(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.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, namespaceURI, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const walker = this.#walker;\n let refNode = traverseNode(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 = traverseNode(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 {\n localName: itemLocalName, namespaceURI: itemNamespaceURI,\n prefix: itemPrefix\n } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix &&\n itemNamespaceURI === namespaceURI) {\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 = traverseNode(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 {\n localName: itemLocalName, namespaceURI: itemNamespaceURI,\n prefix: itemPrefix\n } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix &&\n itemNamespaceURI === namespaceURI) {\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.<object>} - 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.<object>} astLeaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(astLeaves, node, opt = {}) {\n let bool;\n if (Array.isArray(astLeaves) && astLeaves.length) {\n const leaves = astLeaves.map(i => i);\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(leaves, 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(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.<object>} - 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.test(astName)) {\n let astData;\n if (this.#astCache.has(ast)) {\n astData = this.#astCache.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 if (!this.#invalidate) {\n this.#astCache.set(ast, astData);\n }\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 = this.#matcher.matchSelector(ast, node, opt, true);\n if (res) {\n matched.add(res);\n }\n break;\n }\n // :state()\n case 'state': {\n if (isCustomElement(node)) {\n const [{ value: stateValue }] = astChildren;\n if (stateValue) {\n if (node[stateValue]) {\n matched.add(node);\n } else {\n for (const i in node) {\n const prop = node[i];\n if (prop instanceof this.#window.ElementInternals) {\n if (prop?.states?.has(stateValue)) {\n matched.add(node);\n }\n break;\n }\n }\n }\n }\n }\n break;\n }\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // dropped from CSS Selectors 3\n case 'contains': {\n if (warn) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const { href, origin, pathname } = new URL(this.#document.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'hover': {\n const { target, type } = this.#event ?? {};\n if (/^(?:mouse|pointer)(?:down|over|up)$/.test(type) &&\n node.contains(target)) {\n matched.add(node);\n }\n break;\n }\n case 'active': {\n const { buttons, target, type } = this.#event ?? {};\n if (/(?:mouse|pointer)down/.test(type) && buttons & BIT_01 &&\n node.contains(target)) {\n matched.add(node);\n }\n break;\n }\n case 'target': {\n const { hash } = new URL(this.#document.URL);\n if (node.id && hash === `#${node.id}` &&\n this.#document.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(this.#document.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = this.#document.getElementById(id);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (!this.#shadow && node === this.#node) {\n matched.add(node);\n }\n } else if (node === this.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === this.#document.activeElement && node.tabIndex >= 0 &&\n isFocusable(node)) {\n matched.add(node);\n }\n break;\n }\n case 'focus-visible': {\n if (node === this.#document.activeElement && node.tabIndex >= 0) {\n let bool;\n if (isFocusVisible(node)) {\n bool = true;\n } else {\n const { target: eventTarget, type } = this.#event ?? {};\n const { target: focusTarget, relatedTarget } = this.#focus ?? {};\n if (/^key(?:down|up)$/.test(type) && node.contains(eventTarget)) {\n bool = true;\n } else if (relatedTarget && isFocusVisible(relatedTarget) &&\n node.contains(focusTarget)) {\n bool = true;\n }\n }\n if (bool && isFocusable(node)) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let bool;\n let current = this.#document.activeElement;\n if (current.tabIndex >= 0) {\n while (current) {\n if (current === node) {\n bool = true;\n break;\n }\n current = current.parentNode;\n }\n }\n if (bool && isFocusable(node)) {\n matched.add(node);\n }\n break;\n }\n case 'open': {\n if (REG_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (REG_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (REG_FORM_CTRL.test(localName) ||\n isCustomElement(node, { formAssociated: true })) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else if (node.localName === 'option') {\n if (parentNode.localName === 'optgroup' &&\n (parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n matched.add(node);\n }\n } else if (node.localName !== 'optgroup') {\n let bool;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n const walker = this.#walker;\n let refNode = traverseNode(parent, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.localName === 'legend') {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (refNode) {\n if (!refNode.contains(node)) {\n bool = true;\n }\n } else {\n bool = true;\n }\n break;\n } else if (parent.localName === 'form') {\n break;\n } else if (parent.parentNode?.nodeType === ELEMENT_NODE) {\n if (parent.parentNode.localName === 'form') {\n break;\n } else {\n parent = parent.parentNode;\n }\n } else {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((REG_FORM_CTRL.test(localName) ||\n isCustomElement(node, { formAssociated: true })) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n if (node.localName === 'optgroup') {\n matched.add(node);\n } else if (node.localName === 'option') {\n if (parentNode.localName !== 'optgroup' ||\n !(parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n matched.add(node);\n }\n } else {\n let bool;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n const walker = this.#walker;\n let refNode = traverseNode(parent, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.localName === 'legend') {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (refNode) {\n if (!refNode.contains(node)) {\n bool = true;\n }\n } else {\n bool = true;\n }\n break;\n } else if (parent.localName === 'form') {\n break;\n } else if (parent.parentNode?.nodeType === ELEMENT_NODE) {\n if (parent.parentNode.localName === 'form') {\n break;\n } else {\n parent = parent.parentNode;\n }\n } else {\n break;\n }\n }\n if (!bool) {\n matched.add(node);\n }\n }\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 || REG_INPUT_TYPE.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 || REG_INPUT_TYPE.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 placeholder;\n if (node.placeholder) {\n placeholder = node.placeholder;\n } else if (node.hasAttribute('placeholder')) {\n placeholder = node.getAttribute('placeholder');\n }\n if (typeof placeholder === 'string' && !/[\\r\\n]/.test(placeholder)) {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (REG_TYPE_TEXT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '') {\n matched.add(node);\n }\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n REG_TYPE_CHECK.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.#document.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 // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n REG_TYPE_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_SUBMIT.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const walker = this.#walker;\n let nextNode = traverseNode(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 REG_TYPE_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n REG_TYPE_SUBMIT.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 REG_TYPE_CHECK.test(node.getAttribute('type')) &&\n node.hasAttribute('checked')) {\n matched.add(node);\n // option\n } else if (localName === 'option' && node.hasAttribute('selected')) {\n matched.add(node);\n }\n break;\n }\n case 'valid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0) {\n if (node.maxLength >= node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0 && node.maxLength < node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\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 REG_TYPE_RANGE.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n REG_TYPE_RANGE.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_INPUT_TYPE.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' || REG_TYPE_CHECK.test(inputType) ||\n REG_INPUT_TYPE.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.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n let bool;\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'defined': {\n if (node.hasAttribute('is') || localName.includes('-')) {\n if (isCustomElement(node)) {\n matched.add(node);\n }\n // NOTE: MathMLElement not implemented in jsdom\n } else if (node instanceof this.#window.HTMLElement ||\n node instanceof this.#window.SVGElement) {\n matched.add(node);\n }\n break;\n }\n case 'popover-open': {\n if (node.popover && isVisible(node)) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n // not supported\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'fullscreen':\n case 'future':\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 throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match 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 { branches } = walkAST(astChildren[0]);\n const [branch] = branches;\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n throw new DOMException(`Invalid selector :${astName}`, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const 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 PS_ELEMENT_SELECTOR: {\n this.#matcher.matchPseudoElementSelector(astName, opt);\n break;\n }\n case ID_SELECTOR: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case CLASS_SELECTOR: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case PS_CLASS_SELECTOR: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n }\n default: {\n const res = this.#matcher.matchSelector(ast, node, opt, true);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#shadow && astType === PS_CLASS_SELECTOR &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL.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.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n let result;\n if (this.#invalidate) {\n result = this.#invalidateResults.get(leaves);\n } else {\n result = this.#results.get(leaves);\n }\n if (result && result.has(node)) {\n const { matched } = result.get(node);\n bool = matched;\n }\n if (typeof bool !== 'boolean') {\n let cacheable = true;\n if (node.nodeType === ELEMENT_NODE &&\n /^(?:button|fieldset|form|input|select|textarea)$/.test(node.localName)) {\n cacheable = false;\n }\n for (const leaf of leaves) {\n switch (leaf.type) {\n case ATTR_SELECTOR:\n case ID_SELECTOR: {\n cacheable = false;\n break;\n }\n case PS_CLASS_SELECTOR: {\n if (/^(?:(?:any-)?link|defined|dir)$/.test(leaf.name)) {\n cacheable = false;\n }\n break;\n }\n default:\n }\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n if (cacheable) {\n if (!result) {\n result = new WeakMap();\n }\n result.set(node, {\n matched: bool\n });\n if (this.#invalidate) {\n this.#invalidateResults.set(leaves, result);\n } else {\n this.#results.set(leaves, result);\n }\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.<object>} - 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.<object>} 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 PS_ELEMENT_SELECTOR: {\n this.#matcher.matchPseudoElementSelector(leafName, opt);\n break;\n }\n case ID_SELECTOR: {\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 CLASS_SELECTOR: {\n const items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case TYPE_SELECTOR: {\n if (this.#document.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.<object>} - 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 = traverseNode(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 = traverseNode(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 = traverseNode(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 = traverseNode(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.<object>} 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 const walker = this.#qswalker;\n let refNode = traverseNode(node, walker);\n let matchedNode;\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = walker.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = walker.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 = walker.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 PS_ELEMENT_SELECTOR: {\n this.#matcher.matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case ID_SELECTOR: {\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 CLASS_SELECTOR: {\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 TYPE_SELECTOR: {\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.#document.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const 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 === PS_ELEMENT_SELECTOR ||\n lastType === ID_SELECTOR) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === PS_ELEMENT_SELECTOR ||\n firstType === ID_SELECTOR) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === TYPE_SELECTOR) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === TYPE_SELECTOR) {\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 === TYPE_SELECTOR) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === TYPE_SELECTOR) {\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 === PS_CLASS_SELECTOR && leafName === 'dir') {\n bool = false;\n break;\n }\n if (!bool && combo) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n const {\n collected, compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].collected = collected;\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#qswalker;\n } else {\n node = this.#root;\n walker = this.#walker;\n }\n let nextNode = traverseNode(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 = traverseNode(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.<object>} - 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.<object>} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], collectedNodes] = this._collectNodes(targetType);\n const l = branches.length;\n let sort;\n let nodes = 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 = collectedNodes[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 nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...entryNodes]);\n sort = true;\n } else {\n nodes = new Set(entryNodes);\n }\n } else {\n const [node] = entryNodes;\n nodes.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 (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...nextNodes]);\n sort = true;\n } else {\n nodes = 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 nodes.add(node);\n if (branchLen > 1 && nodes.size > 1) {\n 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 nodes.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 nodes.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 nodes.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 nodes.add(refNode);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n }\n }\n }\n if (targetType === TARGET_FIRST) {\n nodes.delete(this.#node);\n if (nodes.size > 1) {\n nodes = new Set(sortNodes(nodes));\n }\n } else if (targetType === TARGET_ALL) {\n nodes.delete(this.#node);\n if (sort && nodes.size > 1) {\n nodes = new Set(sortNodes(nodes));\n }\n }\n return nodes;\n }\n};\n"],
|
|
5
|
+
"mappings": "4ZAAA,IAAAA,EAAA,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,EAAM,KAAO,IACvBA,EAAQ,IAAI,OAAI,aAAUA,CAAK,CAAC,IAG7BA,CACT,CACF",
|
|
6
|
+
"names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_matcher", "import_parser", "import_utility", "import_constant", "DIR_NEXT", "DIR_PREV", "KEY_TAB", "REG_ANCHOR", "REG_FORM_CTRL", "REG_FORM_VALID", "REG_INTERACT", "REG_SHADOW_HOST", "REG_TYPE_CHECK", "REG_TYPE_RANGE", "REG_TYPE_RESET", "REG_TYPE_SUBMIT", "REG_TYPE_TEXT", "#ast", "#astCache", "#descendant", "#document", "#documentCache", "#event", "#focus", "#invalidate", "#invalidateResults", "#matcher", "#node", "#nodes", "#noexcept", "#qswalker", "#results", "#root", "#shadow", "#walker", "#walkers", "#warn", "#window", "window", "e", "opt", "selector", "node", "event", "noexcept", "warn", "func", "mouseKeys", "key", "evt", "keyboardKeys", "nodes", "ast", "cachedItem", "item", "l", "i", "cssAst", "branches", "info", "hasHasPseudoFunc", "hasLogicalPseudoFunc", "hasNthChildOfSelector", "invalidate", "descendant", "items", "branch", "leaves", "nextItem", "itemName", "walker", "anb", "a", "b", "reverse", "parentNode", "matched", "selectorBranches", "refNode", "selectorNodes", "bool", "nth", "j", "localName", "namespaceURI", "prefix", "itemLocalName", "itemNamespaceURI", "itemPrefix", "m", "nthName", "nthIdentName", "anbMap", "astLeaves", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "astName", "twigBranches", "res", "forgive", "lastIndex", "nextNodes", "arr", "astChildren", "selectors", "css", "leavesSet", "stateValue", "prop", "href", "origin", "pathname", "attrURL", "target", "type", "buttons", "hash", "id", "current", "eventTarget", "focusTarget", "relatedTarget", "parent", "placeholder", "targetNode", "nodeName", "checked", "form", "inputType", "node1", "node2", "host", "astType", "result", "cacheable", "compound", "filterLeaves", "baseNode", "leafName", "pending", "comboName", "dir", "matchedNode", "filtered", "complex", "targetType", "collected", "pendingItems", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "pendingItem", "index", "nextCombo", "collectedNodes", "sort", "find", "entryNodes", "entryNodesLen", "n", "entryCombo", "entryLeaves", "entryNode"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"eslint-plugin-jsdoc": "^50.2.2",
|
|
42
42
|
"eslint-plugin-regexp": "^2.6.0",
|
|
43
43
|
"eslint-plugin-unicorn": "^55.0.0",
|
|
44
|
-
"happy-dom": "^15.
|
|
44
|
+
"happy-dom": "^15.3.1",
|
|
45
45
|
"jsdom": "^25.0.0",
|
|
46
46
|
"linkedom": "^0.18.4",
|
|
47
47
|
"mocha": "^10.7.3",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"tsc": "node scripts/index clean --dir=types -i && npx tsc",
|
|
61
61
|
"update-wpt": "git submodule update --init --recursive --remote"
|
|
62
62
|
},
|
|
63
|
-
"version": "5.3.
|
|
63
|
+
"version": "5.3.3"
|
|
64
64
|
}
|
package/src/js/finder.js
CHANGED
|
@@ -232,10 +232,12 @@ export class Finder {
|
|
|
232
232
|
} catch (e) {
|
|
233
233
|
this.onError(e);
|
|
234
234
|
}
|
|
235
|
+
const { branches, info } = walkAST(cssAst);
|
|
235
236
|
const {
|
|
236
|
-
|
|
237
|
-
} =
|
|
238
|
-
let invalidate =
|
|
237
|
+
hasHasPseudoFunc, hasLogicalPseudoFunc, hasNthChildOfSelector
|
|
238
|
+
} = info;
|
|
239
|
+
let invalidate =
|
|
240
|
+
hasHasPseudoFunc || !!(hasLogicalPseudoFunc && hasNthChildOfSelector);
|
|
239
241
|
let descendant = false;
|
|
240
242
|
let i = 0;
|
|
241
243
|
ast = [];
|
|
@@ -363,6 +365,15 @@ export class Finder {
|
|
|
363
365
|
const matched = new Set();
|
|
364
366
|
let selectorBranches;
|
|
365
367
|
if (selector) {
|
|
368
|
+
if (this.#astCache.has(selector)) {
|
|
369
|
+
selectorBranches = this.#astCache.get(selector);
|
|
370
|
+
} else {
|
|
371
|
+
const { branches } = walkAST(selector);
|
|
372
|
+
selectorBranches = branches;
|
|
373
|
+
if (!this.#invalidate) {
|
|
374
|
+
this.#astCache.set(selector, selectorBranches);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
366
377
|
const { branches } = walkAST(selector);
|
|
367
378
|
selectorBranches = branches;
|
|
368
379
|
}
|
|
@@ -877,7 +888,9 @@ export class Finder {
|
|
|
877
888
|
twigBranches,
|
|
878
889
|
selector: selectors.join(',')
|
|
879
890
|
};
|
|
880
|
-
this.#
|
|
891
|
+
if (!this.#invalidate) {
|
|
892
|
+
this.#astCache.set(ast, astData);
|
|
893
|
+
}
|
|
881
894
|
}
|
|
882
895
|
const res = this._matchLogicalPseudoFunc(astData, node, opt);
|
|
883
896
|
if (res) {
|
|
@@ -2879,9 +2892,6 @@ export class Finder {
|
|
|
2879
2892
|
nodes = new Set(sortNodes(nodes));
|
|
2880
2893
|
}
|
|
2881
2894
|
}
|
|
2882
|
-
if (this.#invalidate) {
|
|
2883
|
-
this.#invalidateResults = new WeakMap();
|
|
2884
|
-
}
|
|
2885
2895
|
return nodes;
|
|
2886
2896
|
}
|
|
2887
2897
|
};
|