From f79e36dea6fd4276617e2a209febab833c0652b5 Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Sat, 7 Sep 2024 21:41:17 +0900 Subject: [PATCH] v6.0.2 --- dist/cjs/js/finder.js | 2 +- dist/cjs/js/finder.js.map | 6 +++--- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/cjs/js/finder.js b/dist/cjs/js/finder.js index b0ef885..d9ac1bb 100644 --- a/dist/cjs/js/finder.js +++ b/dist/cjs/js/finder.js @@ -1,2 +1,2 @@ -var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var F=(x,r)=>{for(var e in r)C(x,e,{get:r[e],enumerable:!0})},W=(x,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of D(r))!U.call(x,n)&&n!==e&&C(x,n,{get:()=>r[n],enumerable:!(o=P(r,n))||o.enumerable});return x};var z=x=>W(C({},"__esModule",{value:!0}),x);var H={};F(H,{Finder:()=>$});module.exports=z(H);var O=require("./matcher.js"),g=require("./parser.js"),N=require("./utility.js"),c=require("./constant.js");const v="next",S="prev";class ${#l;#r;#w;#t;#f;#n;#k;#c;#b;#h;#e;#d;#g;#m;#N;#s;#u;#_;#o;#p;#i;#a;constructor(r){this.#a=r,this.#h=new O.Matcher,this.#r=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.#g))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,o={}){const{event:n,noexcept:a,warn:l}=o;return this.#g=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#o]=(0,N.resolveContent)(e),this.#u=(0,N.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(r),this.#b=new WeakMap,this.#p=new WeakMap,this.#_=null,this._setEvent(n),this}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],o=["mouseover","mousedown","mouseup","mouseout"];for(const l of o)e.push(this.#a.addEventListener(l,f=>{this.#n=f},r));const n=["keydown","keyup"];for(const l of n)e.push(this.#a.addEventListener(l,f=>{f.key==="Tab"&&(this.#n=f)},r));const a=["focus","focusin"];for(const l of a)e.push(this.#a.addEventListener(l,f=>{this.#k=f},r));return 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.#c=!1;let o;if(this.#f.has(this.#t)){const n=this.#f.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);o=a.ast,this.#w=a.descendant,this.#c=a.invalidate}}if(o){const n=o.length;for(let a=0;a0&&a<=h){if(b.size){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(b.has(s)){if(m===a-1){d.add(s);break}m++}l?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(m===a-1){d.add(s);break}l?s=t.previousSibling():s=t.nextSibling(),m++}}}}else{let m=a-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m0?0:a-1;for(;s&&(s&&m>=0&&m0?w++:w--):p===m&&(f||d.add(s),m+=n),l?s=t.previousSibling():s=t.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 t;for(const s of i)if(t=this._matchLeaves(s,e,o),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:o,b:n,reverse:a}=r,{localName:l,namespaceURI:f,parentNode:u,prefix:d}=e,i=new Set;if(u){const t=this.#o;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let h=0;for(;s;)h++,s=t.nextSibling();if(o===0){if(n>0&&n<=h){s=(0,N.traverseNode)(u,t),a?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){const{localName:m,namespaceURI:p,prefix:w}=s;if(m===l&&w===d&&p===f){if(b===n-1){i.add(s);break}b++}a?s=t.previousSibling():s=t.nextSibling()}}}else{let b=n-1;if(o>0)for(;b<0;)b+=o;if(b>=0&&b0?0:n-1;for(;s;){const{localName:p,namespaceURI:w,prefix:k}=s;if(p===l&&k===d&&w===f){if(m===b&&(i.add(s),b+=o),b<0||b>=h)break;o>0?m++:m--}a?s=t.previousSibling():s=t.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&o+n===1&&i.add(e);return i}_matchAnPlusB(r,e,o,n){const{nth:{a,b:l,name:f},selector:u}=r,d=new Map;if(f?(f==="even"?(d.set("a",2),d.set("b",0)):f==="odd"&&(d.set("a",2),d.set("b",1)),o.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),o.indexOf("last")>-1&&d.set("reverse",!0)),o==="nth-child"||o==="nth-last-child"){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(o==="nth-of-type"||o==="nth-last-of-type"){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,o){let n;if(Array.isArray(r)&&r.length){const a=[...r],[l]=a,{type:f}=l;let u;f===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:h}=s;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};o.dir=v;const t=this._matchCombinator(i,e,o);if(t.size)if(a.length){for(const s of t)if(n=this._matchHasPseudoFunc(a,s,o),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,o){const{astName:n,branches:a,twigBranches:l}=r,{isShadowRoot:f}=o;let u;if(n==="has"){let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,o),d)break;if(d)if(f){if(this.#_)return e}else return e}else{if(f){for(const t of a)if(t.length>1)return null}o.forgive=n==="is"||n==="where";const d=l.length;let i;for(let t=0;t0){let m=new Set([e]);for(let p=h-1;p>=0;p--){const w=s[p],k=[];o.dir=S;for(const _ of m){const y=this._matchCombinator(w,_,o);y.size&&k.push(...y)}if(k.length)p===0?i=!0:m=new Set(k);else{i=!1;break}}}if(i)break}if(n==="not"){if(!i)return e}else if(i)return e}return u??null}_matchPseudoClassSelector(r,e,o){const{children:n,name:a}=r,{localName:l,parentNode:f}=e,{forgive:u,warn:d=this.#i}=o,i=new Set;if(c.KEY_LOGICAL.includes(a)){let t;if(this.#r.has(r))t=this.#r.get(r);else{const{branches:h}=(0,g.walkAST)(r);if(a==="has"){for(const b of n){const m=(0,g.findAST)(b,p=>c.KEY_LOGICAL.includes(p.name)&&(0,g.findAST)(p,w=>w.name==="has")?p:null);if(m){const p=m.name;if(p==="is"||p==="where")return i;{const w=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${w}`,c.SYNTAX_ERR)}}}t={astName:a,branches:h}}else{const b=[];for(const[...m]of h){const p=[],w=new Set;let k=m.shift();for(;k;)if(k.type===c.COMBINATOR?(p.push({combo:k,leaves:[...w]}),w.clear()):k&&w.add(k),m.length)k=m.shift();else{p.push({combo:null,leaves:[...w]}),w.clear();break}b.push(p)}t={astName:a,branches:h,twigBranches:b},this.#c||this.#r.set(r,t)}}const s=this._matchLogicalPseudoFunc(t,e,o);s&&i.add(s)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=n;return this._matchAnPlusB(t,e,a,o)}else switch(a){case"dir":case"lang":{const t=this.#h.matchSelector(r,e,o,!0);t&&i.add(t);break}case"state":{if((0,N.isCustomElement)(e)){const[{value:t}]=n;if(t)if(e[t])i.add(e);else for(const s in e){const h=e[s];if(h instanceof this.#a.ElementInternals){h?.states?.has(t)&&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":{(l==="a"||l==="area")&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if((l==="a"||l==="area")&&e.hasAttribute("href")){const{href:t,origin:s,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),t);b.origin===s&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#n??{};["mousedown","mouseover","mouseup"].includes(s)&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:h}=this.#n??{};h==="mousedown"&&t&c.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#t.URL);e.id&&t===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#t.URL);if(t){const s=t.replace(/^#/,"");let h=this.#t.getElementById(s);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&&(0,N.isFocusableArea)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&(0,N.isFocusableArea)(e)){let t;if((0,N.isFocusVisible)(e))t=!0;else{const{target:s,relatedTarget:h}=this.#k??{};e===s&&((0,N.isFocusVisible)(h)||!this.#n&&!h&&(0,N.isFocusableArea)(e))&&(t=!0)}t&&i.add(e)}break}case"focus-within":{let t,s=this.#t.activeElement;if((0,N.isFocusableArea)(s))for(;s;){if(s===e){t=!0;break}s=s.parentNode}t&&i.add(e);break}case"open":case"closed":{(l==="details"||l==="dialog")&&(e.hasAttribute("open")?a==="open"&&i.add(e):a==="closed"&&i.add(e));break}case"disabled":case"enabled":{if([...c.KEY_FORM_FOCUS,"fieldset","optgroup","option"].includes(l)||(0,N.isCustomElement)(e,{formAssociated:!0})){let s;if(e.disabled||e.hasAttribute("disabled"))s=!0;else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&(s=!0);else if(e.localName!=="optgroup"){let h=f;for(;h;)if(h.localName==="fieldset"&&(h.disabled||h.hasAttribute("disabled"))){const b=this.#o;let m=(0,N.traverseNode)(h,b);for(m=b.firstChild();m&&m.localName!=="legend";)m=b.nextSibling();m&&m.contains(e)||(s=!0);break}else{if(h.localName==="form")break;if(h.parentNode?.nodeType===c.ELEMENT_NODE){if(h.parentNode.localName==="form")break;h=h.parentNode}else break}}s?a==="disabled"&&i.add(e):a==="enabled"&&i.add(e)}break}case"read-only":case"read-write":{let t,s;switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0;break}case"input":{(!e.type||c.KEY_INPUT_EDIT.includes(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0);break}default:(0,N.isContentEditable)(e)?s=!0:t=!0}t?a==="read-only"&&i.add(e):a==="read-write"&&s&&i.add(e);break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;l==="textarea"?s=e:l==="input"&&(e.hasAttribute("type")?[...c.KEY_INPUT_TEXT,"number"].includes(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{const t=e.getAttribute("type");(e.checked&&l==="input"&&(t==="checkbox"||t==="radio")||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 t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#t.documentElement);const h=s.getElementsByTagName("input"),b=h.length;let m;for(let p=0;p=0?e.maxLength>=e.value.length&&(s=!0):s=!0),s?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}else if(l==="fieldset"){const s=this.#o;let h=(0,N.traverseNode)(e,s);h=s.firstChild();let b;if(!h)b=!0;else for(;h&&e.contains(h)&&!(t.includes(h.localName)&&(h.checkValidity()?h.maxLength>=0?b=h.maxLength>=h.value.length:b=!0:b=!1,!b));)h=s.nextNode();b?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}break}case"in-range":case"out-of-range":{const t=[...c.KEY_INPUT_DATE,"number","range"],s=e.getAttribute("type");if(l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&t.includes(s)){const h=e.validity.rangeUnderflow||e.validity.rangeOverflow;(a==="out-of-range"&&h||a==="in-range"&&!h&&(e.hasAttribute("min")||e.hasAttribute("max")||s==="range"))&&i.add(e)}break}case"required":case"optional":{let t;if(l==="select"||l==="textarea")t=e;else if(l==="input")if(e.hasAttribute("type")){const s=[...c.KEY_INPUT_EDIT,"checkbox","file","radio"],h=e.getAttribute("type");s.includes(h)&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required")?a==="required"&&i.add(e):a==="optional"&&i.add(e));break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#t.createTreeWalker(e,c.SHOW_ALL);let s=t.firstChild(),h;for(;s&&(h=s.nodeType!==c.ELEMENT_NODE&&s.nodeType!==c.TEXT_NODE,!!h);)s=t.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,N.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,N.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:o,name:n}=r;let a;if(Array.isArray(o)){const{branches:l}=(0,g.walkAST)(o[0]),[f]=l,[...u]=f,{host:d}=e;if(n==="host"){let i;for(const t of u){const{type:s}=t;if(s===c.COMBINATOR){const h=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}if(i)return e}else if(n==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:h}=s;if(h===c.COMBINATOR){const b=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}if(t)return e}}else{if(n==="host")return e;throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR)}return a??null}_matchSelector(r,e,o={}){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,o);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,o);default:{const f=this.#h.matchSelector(r,e,o,!0);f&&a.add(f)}}else if(this.#u&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(c.KEY_LOGICAL.includes(l))return o.isShadowRoot=!0,this._matchPseudoClassSelector(r,e,o);if(l==="host"||l==="host-context"){const f=this._matchShadowHostPseudoClass(r,e,o);f&&(this.#_=!0,a.add(f))}}return a}_matchLeaves(r,e,o){let n,a;if(this.#c?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;const f=[...c.KEY_FORM_FOCUS,"fieldset","form"],u=["any-link","defined","dir","link"];e.nodeType===c.ELEMENT_NODE&&f.includes(e.localName)&&(l=!1);for(const d of r){switch(d.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{u.includes(d.name)&&(l=!1);break}default:}if(n=this._matchSelector(d,e,o).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#c?this.#b.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e){const{compound:o,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(o)for(let f=0;f0,{type:f}=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(f){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,o);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(u);t&&t!==e&&e.contains(t)&&(l?this._matchLeaves(a,t,o)&&d.add(t):d.add(t))}break}case c.CLASS_SELECTOR:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,o){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:f}=e,{dir:u}=o,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,o)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,N.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let h=(0,N.traverseNode)(e,s);for(h=s.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,o)&&d.add(h),h=s.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,o)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(a,f,o)&&d.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(a,t,o)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const o=this.#m;let n=(0,N.traverseNode)(e,o),a;if(n)for((n.nodeType!==c.ELEMENT_NODE||n===e&&n!==this.#s)&&(n=o.nextNode());n;){if(this._matchLeaves(r,n,{warn:this.#i})){a=n;break}n=o.nextNode()}return a??null}_matchSelf(r){const e=[],o=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return o&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e){const{complex:o}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||o){let f=this.#e.parentNode;for(;f&&(a=this._matchLeaves(r,f,{warn:this.#i}),a&&(n.push(f),l=!0),f.parentNode);)f=f.parentNode}return[n,l]}_findFirst(r){const e=[],o=this._findNode(r,this.#e);let n=!1;return o&&(e.push(o),n=!0),[e,n]}_findFromHTMLCollection(r,e){const{complex:o,compound:n,filterLeaves:a,targetType:l}=e;let f=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t0,{name:u,type:d}=a;let i=[],t=!1,s=!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,s]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(f?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),s=!0):(i.push(b),s=!0))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,s]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,s,t]=this._findFromHTMLCollection(b,{complex:o,compound:f,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,s]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,s,t]=this._findFromHTMLCollection(b,{complex:o,compound:f,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}default:if(e!==c.TARGET_LINEAL&&(u==="host"||u==="host-context")){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),s=!0)}}else e===c.TARGET_SELF?[i,s]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,s]=this._findLineal(n,{complex:o}):e===c.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:h}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const o=new Set;let n=0;for(const{branch:a}of e){const l=a.length,f=l>1,u=a[0];let d,i;if(f){const{combo:p,leaves:[{name:w,type:k}]}=u,_=a[l-1],{leaves:[{name:y,type:L}]}=_;if(L===c.PS_ELEMENT_SELECTOR||L===c.ID_SELECTOR)d=S,i=_;else if(k===c.PS_ELEMENT_SELECTOR||k===c.ID_SELECTOR)d=v,i=u;else if(r===c.TARGET_ALL)if(w==="*"&&k===c.TYPE_SELECTOR)d=S,i=_;else if(y==="*"&&L===c.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:E}=p;E==="+"||E==="~"?(d=S,i=_):(d=v,i=u)}else d=v,i=u;else if(w==="*"&&k===c.TYPE_SELECTOR)d=S,i=_;else if(y==="*"&&L===c.TYPE_SELECTOR)d=v,i=u;else{let E;for(const{combo:T,leaves:[M]}of a){const{name:R,type:I}=M;if(I===c.PS_CLASS_SELECTOR&&R==="dir"){E=!1;break}if(!E&&T){const{name:A}=T;(A==="+"||A==="~")&&(E=!0)}}E?(d=v,i=u):(d=S,i=_)}}else d=S,i=u;const{collected:t,compound:s,filtered:h,nodes:b,pending:m}=this._findEntryNodes(i,r,f);b.length?(this.#l[n].find=!0,this.#d[n]=b):m&&o.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=t,this.#l[n].dir=d,this.#l[n].filtered=h||!s,n++}if(o.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.#o);let f=(0,N.traverseNode)(a,l);for(;f;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?f===this.#e?u=!0:u=this.#e.contains(f):u=!0,u)for(const d of o){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=d.get("index");this.#l[s].filtered=!0,this.#l[s].find=!0,this.#d[s].push(f)}}f!==l.currentNode&&(f=(0,N.traverseNode)(f,l)),f=l.nextNode()}}}else{let o=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:f,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[o].find=!0,this.#d[o]=d),this.#l[o].dir=S,this.#l[o].filtered=u||!f,o++}}return[this.#l,this.#d]}_getCombinedNodes(r,e,o){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:o,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,o){const{combo:n,index:a}=o,{combo:l,leaves:f}=r[a],u={combo:n,leaves:f},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===r.length-1){const[t]=(0,N.sortNodes)(d);i=t}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,o){const{index:n}=o,a=r[n],l=new Set([e]),f=this._getCombinedNodes(a,l,S);let u;if(f.size){if(n===0)u=e;else for(const d of f)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],o]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let f=0;f=0;k--){const _=u[k];if(w=this._getCombinedNodes(_,w,i),w.size)k===0&&(l.add(p),s>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 k of h)if(w=this._matchNodeNext(u,new Set([k]),{combo:p,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:k}=u[0],[_]=h;let y=this._findNode(k,_);for(;y;){if(w=this._matchNodeNext(u,new Set([y]),{combo:p,index:1}),w){l.add(w);break}y=this._findNode(k,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],[k]=h;let _=this._findNode(w,k);for(;_;){if(p=this._matchNodePrev(u,_,{index:m-1}),p){l.add(_);break}_=this._findNode(w,_)}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,N.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,N.sortNodes)(l)))),l}}0&&(module.exports={Finder}); +var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var F=(x,r)=>{for(var e in r)C(x,e,{get:r[e],enumerable:!0})},W=(x,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of D(r))!U.call(x,n)&&n!==e&&C(x,n,{get:()=>r[n],enumerable:!(o=P(r,n))||o.enumerable});return x};var z=x=>W(C({},"__esModule",{value:!0}),x);var H={};F(H,{Finder:()=>$});module.exports=z(H);var O=require("./matcher.js"),y=require("./parser.js"),N=require("./utility.js"),c=require("./constant.js");const v="next",S="prev";class ${#l;#r;#w;#t;#f;#n;#k;#c;#b;#h;#e;#d;#y;#m;#N;#s;#u;#_;#o;#p;#i;#a;constructor(r){this.#a=r,this.#h=new O.Matcher,this.#r=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.#y))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,o={}){const{event:n,noexcept:a,warn:l}=o;return this.#y=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#o]=(0,N.resolveContent)(e),this.#u=(0,N.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(r),this.#b=new WeakMap,this.#p=new WeakMap,this.#_=null,this._setEvent(n),this}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],o=["mouseover","mousedown","mouseup","mouseout"];for(const l of o)e.push(this.#a.addEventListener(l,f=>{this.#n=f},r));const n=["keydown","keyup"];for(const l of n)e.push(this.#a.addEventListener(l,f=>{f.key==="Tab"&&(this.#n=f)},r));const a=["focus","focusin","blur","focusout"];for(const l of a)e.push(this.#a.addEventListener(l,f=>{this.#k=f},r));return 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.#c=!1;let o;if(this.#f.has(this.#t)){const n=this.#f.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);o=a.ast,this.#w=a.descendant,this.#c=a.invalidate}}if(o){const n=o.length;for(let a=0;a0&&a<=h){if(b.size){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(b.has(s)){if(m===a-1){d.add(s);break}m++}l?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(m===a-1){d.add(s);break}l?s=t.previousSibling():s=t.nextSibling(),m++}}}}else{let m=a-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m0?0:a-1;for(;s&&(s&&m>=0&&m0?w++:w--):p===m&&(f||d.add(s),m+=n),l?s=t.previousSibling():s=t.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 t;for(const s of i)if(t=this._matchLeaves(s,e,o),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:o,b:n,reverse:a}=r,{localName:l,namespaceURI:f,parentNode:u,prefix:d}=e,i=new Set;if(u){const t=this.#o;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let h=0;for(;s;)h++,s=t.nextSibling();if(o===0){if(n>0&&n<=h){s=(0,N.traverseNode)(u,t),a?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){const{localName:m,namespaceURI:p,prefix:w}=s;if(m===l&&w===d&&p===f){if(b===n-1){i.add(s);break}b++}a?s=t.previousSibling():s=t.nextSibling()}}}else{let b=n-1;if(o>0)for(;b<0;)b+=o;if(b>=0&&b0?0:n-1;for(;s;){const{localName:p,namespaceURI:w,prefix:k}=s;if(p===l&&k===d&&w===f){if(m===b&&(i.add(s),b+=o),b<0||b>=h)break;o>0?m++:m--}a?s=t.previousSibling():s=t.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&o+n===1&&i.add(e);return i}_matchAnPlusB(r,e,o,n){const{nth:{a,b:l,name:f},selector:u}=r,d=new Map;if(f?(f==="even"?(d.set("a",2),d.set("b",0)):f==="odd"&&(d.set("a",2),d.set("b",1)),o.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),o.indexOf("last")>-1&&d.set("reverse",!0)),o==="nth-child"||o==="nth-last-child"){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(o==="nth-of-type"||o==="nth-last-of-type"){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,o){let n;if(Array.isArray(r)&&r.length){const a=[...r],[l]=a,{type:f}=l;let u;f===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:h}=s;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};o.dir=v;const t=this._matchCombinator(i,e,o);if(t.size)if(a.length){for(const s of t)if(n=this._matchHasPseudoFunc(a,s,o),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,o){const{astName:n,branches:a,twigBranches:l}=r,{isShadowRoot:f}=o;let u;if(n==="has"){let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,o),d)break;if(d)if(f){if(this.#_)return e}else return e}else{if(f){for(const t of a)if(t.length>1)return null}o.forgive=n==="is"||n==="where";const d=l.length;let i;for(let t=0;t0){let m=new Set([e]);for(let p=h-1;p>=0;p--){const w=s[p],k=[];o.dir=S;for(const _ of m){const g=this._matchCombinator(w,_,o);g.size&&k.push(...g)}if(k.length)p===0?i=!0:m=new Set(k);else{i=!1;break}}}if(i)break}if(n==="not"){if(!i)return e}else if(i)return e}return u??null}_matchPseudoClassSelector(r,e,o){const{children:n,name:a}=r,{localName:l,parentNode:f}=e,{forgive:u,warn:d=this.#i}=o,i=new Set;if(c.KEY_LOGICAL.includes(a)){let t;if(this.#r.has(r))t=this.#r.get(r);else{const{branches:h}=(0,y.walkAST)(r);if(a==="has"){for(const b of n){const m=(0,y.findAST)(b,p=>c.KEY_LOGICAL.includes(p.name)&&(0,y.findAST)(p,w=>w.name==="has")?p:null);if(m){const p=m.name;if(p==="is"||p==="where")return i;{const w=(0,y.generateCSS)(r);throw new DOMException(`Invalid selector ${w}`,c.SYNTAX_ERR)}}}t={astName:a,branches:h}}else{const b=[];for(const[...m]of h){const p=[],w=new Set;let k=m.shift();for(;k;)if(k.type===c.COMBINATOR?(p.push({combo:k,leaves:[...w]}),w.clear()):k&&w.add(k),m.length)k=m.shift();else{p.push({combo:null,leaves:[...w]}),w.clear();break}b.push(p)}t={astName:a,branches:h,twigBranches:b},this.#c||this.#r.set(r,t)}}const s=this._matchLogicalPseudoFunc(t,e,o);s&&i.add(s)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=n;return this._matchAnPlusB(t,e,a,o)}else switch(a){case"dir":case"lang":{const t=this.#h.matchSelector(r,e,o,!0);t&&i.add(t);break}case"state":{if((0,N.isCustomElement)(e)){const[{value:t}]=n;if(t)if(e[t])i.add(e);else for(const s in e){const h=e[s];if(h instanceof this.#a.ElementInternals){h?.states?.has(t)&&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":{(l==="a"||l==="area")&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if((l==="a"||l==="area")&&e.hasAttribute("href")){const{href:t,origin:s,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),t);b.origin===s&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#n??{};["mousedown","mouseover","mouseup"].includes(s)&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:h}=this.#n??{};h==="mousedown"&&t&c.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#t.URL);e.id&&t===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#t.URL);if(t){const s=t.replace(/^#/,"");let h=this.#t.getElementById(s);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&&(0,N.isFocusableArea)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&(0,N.isFocusableArea)(e)){let t;if((0,N.isFocusVisible)(e))t=!0;else{const{target:s,relatedTarget:h,type:b}=this.#k??{};e===s&&(b==="focus"||b==="focusin")&&((0,N.isFocusVisible)(h)||!this.#n&&!h&&(0,N.isFocusableArea)(e))&&(t=!0)}t&&i.add(e)}break}case"focus-within":{let t,s=this.#t.activeElement;if((0,N.isFocusableArea)(s))for(;s;){if(s===e){t=!0;break}s=s.parentNode}t&&i.add(e);break}case"open":case"closed":{(l==="details"||l==="dialog")&&(e.hasAttribute("open")?a==="open"&&i.add(e):a==="closed"&&i.add(e));break}case"disabled":case"enabled":{if([...c.KEY_FORM_FOCUS,"fieldset","optgroup","option"].includes(l)||(0,N.isCustomElement)(e,{formAssociated:!0})){let s;if(e.disabled||e.hasAttribute("disabled"))s=!0;else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&(s=!0);else if(e.localName!=="optgroup"){let h=f;for(;h;)if(h.localName==="fieldset"&&(h.disabled||h.hasAttribute("disabled"))){const b=this.#o;let m=(0,N.traverseNode)(h,b);for(m=b.firstChild();m&&m.localName!=="legend";)m=b.nextSibling();m&&m.contains(e)||(s=!0);break}else{if(h.localName==="form")break;if(h.parentNode?.nodeType===c.ELEMENT_NODE){if(h.parentNode.localName==="form")break;h=h.parentNode}else break}}s?a==="disabled"&&i.add(e):a==="enabled"&&i.add(e)}break}case"read-only":case"read-write":{let t,s;switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0;break}case"input":{(!e.type||c.KEY_INPUT_EDIT.includes(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0);break}default:(0,N.isContentEditable)(e)?s=!0:t=!0}t?a==="read-only"&&i.add(e):a==="read-write"&&s&&i.add(e);break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;l==="textarea"?s=e:l==="input"&&(e.hasAttribute("type")?[...c.KEY_INPUT_TEXT,"number"].includes(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{const t=e.getAttribute("type");(e.checked&&l==="input"&&(t==="checkbox"||t==="radio")||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 t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#t.documentElement);const h=s.getElementsByTagName("input"),b=h.length;let m;for(let p=0;p=0?e.maxLength>=e.value.length&&(s=!0):s=!0),s?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}else if(l==="fieldset"){const s=this.#o;let h=(0,N.traverseNode)(e,s);h=s.firstChild();let b;if(!h)b=!0;else for(;h&&e.contains(h)&&!(t.includes(h.localName)&&(h.checkValidity()?h.maxLength>=0?b=h.maxLength>=h.value.length:b=!0:b=!1,!b));)h=s.nextNode();b?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}break}case"in-range":case"out-of-range":{const t=[...c.KEY_INPUT_DATE,"number","range"],s=e.getAttribute("type");if(l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&t.includes(s)){const h=e.validity.rangeUnderflow||e.validity.rangeOverflow;(a==="out-of-range"&&h||a==="in-range"&&!h&&(e.hasAttribute("min")||e.hasAttribute("max")||s==="range"))&&i.add(e)}break}case"required":case"optional":{let t;if(l==="select"||l==="textarea")t=e;else if(l==="input")if(e.hasAttribute("type")){const s=[...c.KEY_INPUT_EDIT,"checkbox","file","radio"],h=e.getAttribute("type");s.includes(h)&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required")?a==="required"&&i.add(e):a==="optional"&&i.add(e));break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#t.createTreeWalker(e,c.SHOW_ALL);let s=t.firstChild(),h;for(;s&&(h=s.nodeType!==c.ELEMENT_NODE&&s.nodeType!==c.TEXT_NODE,!!h);)s=t.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,N.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,N.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:o,name:n}=r;let a;if(Array.isArray(o)){const{branches:l}=(0,y.walkAST)(o[0]),[f]=l,[...u]=f,{host:d}=e;if(n==="host"){let i;for(const t of u){const{type:s}=t;if(s===c.COMBINATOR){const h=(0,y.generateCSS)(r);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}if(i)return e}else if(n==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:h}=s;if(h===c.COMBINATOR){const b=(0,y.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}if(t)return e}}else{if(n==="host")return e;throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR)}return a??null}_matchSelector(r,e,o={}){const{type:n}=r,a=new Set;if(r.name===c.EMPTY)return a;const l=(0,y.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,o);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,o);default:{const f=this.#h.matchSelector(r,e,o,!0);f&&a.add(f)}}else if(this.#u&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(c.KEY_LOGICAL.includes(l))return o.isShadowRoot=!0,this._matchPseudoClassSelector(r,e,o);if(l==="host"||l==="host-context"){const f=this._matchShadowHostPseudoClass(r,e,o);f&&(this.#_=!0,a.add(f))}}return a}_matchLeaves(r,e,o){let n,a;if(this.#c?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;const f=[...c.KEY_FORM_FOCUS,"fieldset","form"],u=["any-link","defined","dir","link"];e.nodeType===c.ELEMENT_NODE&&f.includes(e.localName)&&(l=!1);for(const d of r){switch(d.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{u.includes(d.name)&&(l=!1);break}default:}if(n=this._matchSelector(d,e,o).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#c?this.#b.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e){const{compound:o,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(o)for(let f=0;f0,{type:f}=n,u=(0,y.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(f){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,o);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(u);t&&t!==e&&e.contains(t)&&(l?this._matchLeaves(a,t,o)&&d.add(t):d.add(t))}break}case c.CLASS_SELECTOR:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,o){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:f}=e,{dir:u}=o,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,o)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,N.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let h=(0,N.traverseNode)(e,s);for(h=s.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,o)&&d.add(h),h=s.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,o)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(a,f,o)&&d.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(a,t,o)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const o=this.#m;let n=(0,N.traverseNode)(e,o),a;if(n)for((n.nodeType!==c.ELEMENT_NODE||n===e&&n!==this.#s)&&(n=o.nextNode());n;){if(this._matchLeaves(r,n,{warn:this.#i})){a=n;break}n=o.nextNode()}return a??null}_matchSelf(r){const e=[],o=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return o&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e){const{complex:o}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||o){let f=this.#e.parentNode;for(;f&&(a=this._matchLeaves(r,f,{warn:this.#i}),a&&(n.push(f),l=!0),f.parentNode);)f=f.parentNode}return[n,l]}_findFirst(r){const e=[],o=this._findNode(r,this.#e);let n=!1;return o&&(e.push(o),n=!0),[e,n]}_findFromHTMLCollection(r,e){const{complex:o,compound:n,filterLeaves:a,targetType:l}=e;let f=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t0,{name:u,type:d}=a;let i=[],t=!1,s=!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,s]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(f?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),s=!0):(i.push(b),s=!0))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,s]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,s,t]=this._findFromHTMLCollection(b,{complex:o,compound:f,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,s]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,s,t]=this._findFromHTMLCollection(b,{complex:o,compound:f,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}default:if(e!==c.TARGET_LINEAL&&(u==="host"||u==="host-context")){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),s=!0)}}else e===c.TARGET_SELF?[i,s]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,s]=this._findLineal(n,{complex:o}):e===c.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:h}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const o=new Set;let n=0;for(const{branch:a}of e){const l=a.length,f=l>1,u=a[0];let d,i;if(f){const{combo:p,leaves:[{name:w,type:k}]}=u,_=a[l-1],{leaves:[{name:g,type:L}]}=_;if(L===c.PS_ELEMENT_SELECTOR||L===c.ID_SELECTOR)d=S,i=_;else if(k===c.PS_ELEMENT_SELECTOR||k===c.ID_SELECTOR)d=v,i=u;else if(r===c.TARGET_ALL)if(w==="*"&&k===c.TYPE_SELECTOR)d=S,i=_;else if(g==="*"&&L===c.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:E}=p;E==="+"||E==="~"?(d=S,i=_):(d=v,i=u)}else d=v,i=u;else if(w==="*"&&k===c.TYPE_SELECTOR)d=S,i=_;else if(g==="*"&&L===c.TYPE_SELECTOR)d=v,i=u;else{let E;for(const{combo:T,leaves:[M]}of a){const{name:R,type:I}=M;if(I===c.PS_CLASS_SELECTOR&&R==="dir"){E=!1;break}if(!E&&T){const{name:A}=T;(A==="+"||A==="~")&&(E=!0)}}E?(d=v,i=u):(d=S,i=_)}}else d=S,i=u;const{collected:t,compound:s,filtered:h,nodes:b,pending:m}=this._findEntryNodes(i,r,f);b.length?(this.#l[n].find=!0,this.#d[n]=b):m&&o.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=t,this.#l[n].dir=d,this.#l[n].filtered=h||!s,n++}if(o.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.#o);let f=(0,N.traverseNode)(a,l);for(;f;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?f===this.#e?u=!0:u=this.#e.contains(f):u=!0,u)for(const d of o){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=d.get("index");this.#l[s].filtered=!0,this.#l[s].find=!0,this.#d[s].push(f)}}f!==l.currentNode&&(f=(0,N.traverseNode)(f,l)),f=l.nextNode()}}}else{let o=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:f,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[o].find=!0,this.#d[o]=d),this.#l[o].dir=S,this.#l[o].filtered=u||!f,o++}}return[this.#l,this.#d]}_getCombinedNodes(r,e,o){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:o,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,o){const{combo:n,index:a}=o,{combo:l,leaves:f}=r[a],u={combo:n,leaves:f},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===r.length-1){const[t]=(0,N.sortNodes)(d);i=t}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,o){const{index:n}=o,a=r[n],l=new Set([e]),f=this._getCombinedNodes(a,l,S);let u;if(f.size){if(n===0)u=e;else for(const d of f)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],o]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let f=0;f=0;k--){const _=u[k];if(w=this._getCombinedNodes(_,w,i),w.size)k===0&&(l.add(p),s>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 k of h)if(w=this._matchNodeNext(u,new Set([k]),{combo:p,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:k}=u[0],[_]=h;let g=this._findNode(k,_);for(;g;){if(w=this._matchNodeNext(u,new Set([g]),{combo:p,index:1}),w){l.add(w);break}g=this._findNode(k,g)}}}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],[k]=h;let _=this._findNode(w,k);for(;_;){if(p=this._matchNodePrev(u,_,{index:m-1}),p){l.add(_);break}_=this._findNode(w,_)}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,N.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,N.sortNodes)(l)))),l}}0&&(module.exports={Finder}); //# sourceMappingURL=finder.js.map diff --git a/dist/cjs/js/finder.js.map b/dist/cjs/js/finder.js.map index 2c10292..e2c1c6f 100644 --- a/dist/cjs/js/finder.js.map +++ b/dist/cjs/js/finder.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../../src/js/finder.js"], - "sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport { Matcher } from './matcher.js';\nimport {\n findAST, generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\nimport {\n isContentEditable, isCustomElement, isFocusVisible, isFocusableArea,\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, KEY_FORM_FOCUS,\n KEY_INPUT_DATE, KEY_INPUT_EDIT, KEY_INPUT_TEXT, KEY_LOGICAL,\n NOT_SUPPORTED_ERR, PS_CLASS_SELECTOR, PS_ELEMENT_SELECTOR, SHOW_ALL,\n SYNTAX_ERR, TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF, TEXT_NODE,\n TYPE_SELECTOR, WALKER_FILTER\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: Array\n * #nodes: Array\n * Ast: {\n * branch: Array,\n * collected: boolean,\n * dir: string | null,\n * filtered: boolean,\n * find: boolean\n * }\n * Branch: Array\n * Twig: {\n * combo: Leaf | null,\n * leaves: Array\n * }\n * Leaf: {\n * children: Array | null,\n * loc: null,\n * type: string\n * }\n * Nodes: Array\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 #verifyShadowHost;\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} - finder\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.#verifyShadowHost = null;\n this._setEvent(event);\n return this;\n }\n\n /**\n * register event listeners\n * @private\n * @returns {Array.} - 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 === 'Tab') {\n this.#event = evt;\n }\n }, opt));\n }\n const focusKeys = ['focus', 'focusin'];\n for (const key of focusKeys) {\n func.push(this.#window.addEventListener(key, evt => {\n this.#focus = evt;\n }, opt));\n }\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 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 let itemName = item.name;\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 if (itemName === '+' || itemName === '~') {\n invalidate = true;\n } else {\n descendant = true;\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (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.} - 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.} - 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.} - 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 (nthName === 'nth-child' || nthName === 'nth-last-child') {\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 (nthName === 'nth-of-type' || nthName === 'nth-last-of-type') {\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.} 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];\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 { astName, branches, twigBranches } = astData;\n const { isShadowRoot } = opt;\n let res;\n if (astName === 'has') {\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 if (isShadowRoot) {\n if (this.#verifyShadowHost) {\n return node;\n }\n } else {\n return node;\n }\n }\n } else {\n if (isShadowRoot) {\n for (const branch of branches) {\n if (branch.length > 1) {\n return null;\n }\n }\n }\n opt.forgive = astName === 'is' || astName === 'where';\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 return node;\n }\n } else if (bool) {\n return 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 * @returns {Set.} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt) {\n const { children: astChildren, name: astName } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = opt;\n const matched = new Set();\n // :has(), :is(), :not(), :where()\n if (KEY_LOGICAL.includes(astName)) {\n let astData;\n if (this.#astCache.has(ast)) {\n astData = this.#astCache.get(ast);\n } else {\n const { branches } = walkAST(ast);\n if (astName === 'has') {\n for (const child of astChildren) {\n const item = findAST(child, leaf => {\n if (KEY_LOGICAL.includes(leaf.name) &&\n findAST(leaf, nestedLeaf => nestedLeaf.name === 'has')) {\n return leaf;\n }\n return null;\n });\n if (item) {\n const itemName = item.name;\n if (itemName === 'is' || itemName === 'where') {\n return matched;\n } else {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n }\n }\n astData = {\n astName,\n branches\n };\n } else {\n const twigBranches = [];\n for (const [...leaves] of branches) {\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 };\n if (!this.#invalidate) {\n this.#astCache.set(ast, astData);\n }\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 ((localName === 'a' || localName === 'area') &&\n node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if ((localName === 'a' || localName === 'area') &&\n 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 (['mousedown', 'mouseover', 'mouseup'].includes(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 (type === 'mousedown' && 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 && isFocusableArea(node)) {\n matched.add(node);\n }\n break;\n }\n case 'focus-visible': {\n if (node === this.#document.activeElement && isFocusableArea(node)) {\n let bool;\n if (isFocusVisible(node)) {\n bool = true;\n } else {\n const { target: focusTarget, relatedTarget } = this.#focus ?? {};\n if (node === focusTarget) {\n if (isFocusVisible(relatedTarget)) {\n bool = true;\n } else if (!this.#event && !relatedTarget && isFocusableArea(node)) {\n bool = true;\n }\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let bool;\n let current = this.#document.activeElement;\n if (isFocusableArea(current)) {\n while (current) {\n if (current === node) {\n bool = true;\n break;\n }\n current = current.parentNode;\n }\n }\n if (bool) {\n matched.add(node);\n }\n break;\n }\n case 'open':\n case 'closed': {\n if (localName === 'details' || localName === 'dialog') {\n if (node.hasAttribute('open')) {\n if (astName === 'open') {\n matched.add(node);\n }\n } else if (astName === 'closed') {\n matched.add(node);\n }\n }\n break;\n }\n case 'disabled':\n case 'enabled': {\n const keys = [...KEY_FORM_FOCUS, 'fieldset', 'optgroup', 'option'];\n if (keys.includes(localName) ||\n isCustomElement(node, { formAssociated: true })) {\n let disabled;\n if (node.disabled || node.hasAttribute('disabled')) {\n disabled = true;\n } else if (node.localName === 'option') {\n if (parentNode.localName === 'optgroup' &&\n (parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n disabled = true;\n }\n } else if (node.localName !== 'optgroup') {\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 disabled = true;\n }\n } else {\n disabled = 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 }\n if (disabled) {\n if (astName === 'disabled') {\n matched.add(node);\n }\n } else if (astName === 'enabled') {\n matched.add(node);\n }\n }\n break;\n }\n case 'read-only':\n case 'read-write': {\n let readonly;\n let writable;\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n readonly = true;\n } else {\n writable = true;\n }\n break;\n }\n case 'input': {\n if (!node.type || KEY_INPUT_EDIT.includes(node.type)) {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n readonly = true;\n } else {\n writable = true;\n }\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n writable = true;\n } else {\n readonly = true;\n }\n }\n }\n if (readonly) {\n if (astName === 'read-only') {\n matched.add(node);\n }\n } else if (astName === 'read-write' && writable) {\n matched.add(node);\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 const keys = [...KEY_INPUT_TEXT, 'number'];\n if (keys.includes(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 const attrType = node.getAttribute('type');\n if ((node.checked && localName === 'input' &&\n (attrType === 'checkbox' || attrType === 'radio')) ||\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 const chekcKeys = ['checkbox', 'radio'];\n const resetKeys = ['button', 'reset'];\n const submitKeys = ['image', 'submit'];\n const attrType = node.getAttribute('type');\n if ((localName === 'button' &&\n !(node.hasAttribute('type') && resetKeys.includes(attrType))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n submitKeys.includes(attrType))) {\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 const nodeAttrType = nextNode.getAttribute('type');\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n resetKeys.includes(nodeAttrType));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n submitKeys.includes(nodeAttrType);\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 chekcKeys.includes(attrType) &&\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 case 'invalid': {\n const keys = [...KEY_FORM_FOCUS, 'form'];\n if (keys.includes(localName)) {\n let valid;\n if (node.checkValidity()) {\n if (node.maxLength >= 0) {\n if (node.maxLength >= node.value.length) {\n valid = true;\n }\n } else {\n valid = true;\n }\n }\n if (valid) {\n if (astName === 'valid') {\n matched.add(node);\n }\n } else if (astName === 'invalid') {\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 valid;\n if (!refNode) {\n valid = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (keys.includes(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n valid = refNode.maxLength >= refNode.value.length;\n } else {\n valid = true;\n }\n } else {\n valid = false;\n }\n if (!valid) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (valid) {\n if (astName === 'valid') {\n matched.add(node);\n }\n } else if (astName === 'invalid') {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range':\n case 'out-of-range': {\n const keys = [...KEY_INPUT_DATE, 'number', 'range'];\n const attrType = node.getAttribute('type');\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n keys.includes(attrType)) {\n const flowed =\n node.validity.rangeUnderflow || node.validity.rangeOverflow;\n if (astName === 'out-of-range' && flowed) {\n matched.add(node);\n } else if (astName === 'in-range' && !flowed &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n attrType === 'range')) {\n matched.add(node);\n }\n }\n break;\n }\n case 'required':\n case 'optional': {\n let targetNode;\n if (localName === 'select' || localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const keys = [...KEY_INPUT_EDIT, 'checkbox', 'file', 'radio'];\n const attrType = node.getAttribute('type');\n if (keys.includes(attrType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode) {\n if (node.required || node.hasAttribute('required')) {\n if (astName === 'required') {\n matched.add(node);\n }\n } else if (astName === 'optional') {\n matched.add(node);\n }\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 return 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 return node;\n }\n }\n } else if (astName === 'host') {\n return 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.} - 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 (KEY_LOGICAL.includes(astName)) {\n opt.isShadowRoot = true;\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n } else if (astName === 'host' || astName === 'host-context') {\n const res = this._matchShadowHostPseudoClass(ast, node, opt);\n if (res) {\n this.#verifyShadowHost = true;\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n 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 const formKeys = [...KEY_FORM_FOCUS, 'fieldset', 'form'];\n const pseudoKeys = ['any-link', 'defined', 'dir', 'link'];\n if (node.nodeType === ELEMENT_NODE && formKeys.includes(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 (pseudoKeys.includes(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.} - matched nodes\n */\n _matchHTMLCollection(items, opt) {\n const { compound, filterLeaves } = opt;\n const nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n return new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (typeof leafName === 'string' && leafName !== leaf.name) {\n leaf.name = leafName;\n }\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case 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.} - 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.} leaves - AST leaves\n * @param {object} node - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, node) {\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, this.#node);\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 * @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 &&\n (leafName === 'host' || leafName === 'host-context')) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === 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 (comboName === '+' || 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 (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 {\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 (comboName === '+' || 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.} - collection of matched nodes\n */\n _getCombinedNodes(twig, nodes, dir) {\n const arr = [];\n for (const node of nodes) {\n const matched = this._matchCombinator(twig, node, {\n dir,\n warn: this.#warn\n });\n if (matched.size) {\n arr.push(...matched);\n }\n }\n if (arr.length) {\n return new Set(arr);\n }\n return new Set();\n }\n\n /**\n * match node to next direction\n * @private\n * @param {Array} branch - branch\n * @param {Set.} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {Set.} - collection of matched nodes\n */\n find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], 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_FIRST) {\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, entryNode);\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, refNode);\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, entryNode);\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, refNode);\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"], - "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAwB,wBACxBC,EAEO,uBACPC,EAGO,wBAGPC,EAOO,yBACP,MAAMC,EAAW,OACXC,EAAW,OA0BV,MAAMP,CAAO,CAElBQ,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAMA,YAAYC,EAAQ,CAClB,KAAKD,GAAUC,EACf,KAAKb,GAAW,IAAI,UACpB,KAAKR,GAAY,IAAI,QACrB,KAAKG,GAAiB,IAAI,QAC1B,KAAKI,GAAqB,IAAI,QAC9B,KAAKM,GAAW,IAAI,QACpB,KAAKT,GAAS,KACd,KAAKC,GAAS,KACd,KAAK,wBAAwB,CAC/B,CASA,QAAQiB,EAAGC,EAAK,CAEd,GAAI,EADaA,GAAK,UAAY,KAAKZ,IAErC,GAAIW,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C,IAG7BA,CACT,CACF", - "names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_matcher", "import_parser", "import_utility", "import_constant", "DIR_NEXT", "DIR_PREV", "#ast", "#astCache", "#descendant", "#document", "#documentCache", "#event", "#focus", "#invalidate", "#invalidateResults", "#matcher", "#node", "#nodes", "#noexcept", "#qswalker", "#results", "#root", "#shadow", "#verifyShadowHost", "#walker", "#walkers", "#warn", "#window", "window", "e", "opt", "selector", "node", "event", "noexcept", "warn", "func", "mouseKeys", "key", "evt", "keyboardKeys", "focusKeys", "nodes", "ast", "cachedItem", "item", "l", "i", "cssAst", "branches", "info", "hasHasPseudoFunc", "hasLogicalPseudoFunc", "hasNthChildOfSelector", "invalidate", "descendant", "items", "branch", "leaves", "itemName", "nextItem", "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", "isShadowRoot", "res", "lastIndex", "nextNodes", "arr", "astChildren", "forgive", "child", "nestedLeaf", "css", "leavesSet", "stateValue", "prop", "href", "origin", "pathname", "attrURL", "target", "type", "buttons", "hash", "id", "current", "focusTarget", "relatedTarget", "disabled", "parent", "readonly", "writable", "placeholder", "targetNode", "attrType", "nodeName", "checked", "chekcKeys", "resetKeys", "submitKeys", "form", "nodeAttrType", "keys", "valid", "flowed", "node1", "node2", "host", "astType", "result", "cacheable", "formKeys", "pseudoKeys", "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"] + "sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport { Matcher } from './matcher.js';\nimport {\n findAST, generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\nimport {\n isContentEditable, isCustomElement, isFocusVisible, isFocusableArea,\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, KEY_FORM_FOCUS,\n KEY_INPUT_DATE, KEY_INPUT_EDIT, KEY_INPUT_TEXT, KEY_LOGICAL,\n NOT_SUPPORTED_ERR, PS_CLASS_SELECTOR, PS_ELEMENT_SELECTOR, SHOW_ALL,\n SYNTAX_ERR, TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF, TEXT_NODE,\n TYPE_SELECTOR, WALKER_FILTER\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: Array\n * #nodes: Array\n * Ast: {\n * branch: Array,\n * collected: boolean,\n * dir: string | null,\n * filtered: boolean,\n * find: boolean\n * }\n * Branch: Array\n * Twig: {\n * combo: Leaf | null,\n * leaves: Array\n * }\n * Leaf: {\n * children: Array | null,\n * loc: null,\n * type: string\n * }\n * Nodes: Array\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 #verifyShadowHost;\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} - finder\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.#verifyShadowHost = null;\n this._setEvent(event);\n return this;\n }\n\n /**\n * register event listeners\n * @private\n * @returns {Array.} - 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 === 'Tab') {\n this.#event = evt;\n }\n }, opt));\n }\n const focusKeys = ['focus', 'focusin', 'blur', 'focusout'];\n for (const key of focusKeys) {\n func.push(this.#window.addEventListener(key, evt => {\n this.#focus = evt;\n }, opt));\n }\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 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 let itemName = item.name;\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 if (itemName === '+' || itemName === '~') {\n invalidate = true;\n } else {\n descendant = true;\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (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.} - 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.} - 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.} - 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 (nthName === 'nth-child' || nthName === 'nth-last-child') {\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 (nthName === 'nth-of-type' || nthName === 'nth-last-of-type') {\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.} 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];\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 { astName, branches, twigBranches } = astData;\n const { isShadowRoot } = opt;\n let res;\n if (astName === 'has') {\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 if (isShadowRoot) {\n if (this.#verifyShadowHost) {\n return node;\n }\n } else {\n return node;\n }\n }\n } else {\n if (isShadowRoot) {\n for (const branch of branches) {\n if (branch.length > 1) {\n return null;\n }\n }\n }\n opt.forgive = astName === 'is' || astName === 'where';\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 return node;\n }\n } else if (bool) {\n return 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 * @returns {Set.} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt) {\n const { children: astChildren, name: astName } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = opt;\n const matched = new Set();\n // :has(), :is(), :not(), :where()\n if (KEY_LOGICAL.includes(astName)) {\n let astData;\n if (this.#astCache.has(ast)) {\n astData = this.#astCache.get(ast);\n } else {\n const { branches } = walkAST(ast);\n if (astName === 'has') {\n for (const child of astChildren) {\n const item = findAST(child, leaf => {\n if (KEY_LOGICAL.includes(leaf.name) &&\n findAST(leaf, nestedLeaf => nestedLeaf.name === 'has')) {\n return leaf;\n }\n return null;\n });\n if (item) {\n const itemName = item.name;\n if (itemName === 'is' || itemName === 'where') {\n return matched;\n } else {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n }\n }\n astData = {\n astName,\n branches\n };\n } else {\n const twigBranches = [];\n for (const [...leaves] of branches) {\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 };\n if (!this.#invalidate) {\n this.#astCache.set(ast, astData);\n }\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 ((localName === 'a' || localName === 'area') &&\n node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if ((localName === 'a' || localName === 'area') &&\n 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 (['mousedown', 'mouseover', 'mouseup'].includes(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 (type === 'mousedown' && 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 && isFocusableArea(node)) {\n matched.add(node);\n }\n break;\n }\n case 'focus-visible': {\n if (node === this.#document.activeElement && isFocusableArea(node)) {\n let bool;\n if (isFocusVisible(node)) {\n bool = true;\n } else {\n const { target, relatedTarget, type } = this.#focus ?? {};\n if (node === target && (type === 'focus' || type === 'focusin')) {\n if (isFocusVisible(relatedTarget)) {\n bool = true;\n } else if (!this.#event && !relatedTarget &&\n isFocusableArea(node)) {\n bool = true;\n }\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let bool;\n let current = this.#document.activeElement;\n if (isFocusableArea(current)) {\n while (current) {\n if (current === node) {\n bool = true;\n break;\n }\n current = current.parentNode;\n }\n }\n if (bool) {\n matched.add(node);\n }\n break;\n }\n case 'open':\n case 'closed': {\n if (localName === 'details' || localName === 'dialog') {\n if (node.hasAttribute('open')) {\n if (astName === 'open') {\n matched.add(node);\n }\n } else if (astName === 'closed') {\n matched.add(node);\n }\n }\n break;\n }\n case 'disabled':\n case 'enabled': {\n const keys = [...KEY_FORM_FOCUS, 'fieldset', 'optgroup', 'option'];\n if (keys.includes(localName) ||\n isCustomElement(node, { formAssociated: true })) {\n let disabled;\n if (node.disabled || node.hasAttribute('disabled')) {\n disabled = true;\n } else if (node.localName === 'option') {\n if (parentNode.localName === 'optgroup' &&\n (parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n disabled = true;\n }\n } else if (node.localName !== 'optgroup') {\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 disabled = true;\n }\n } else {\n disabled = 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 }\n if (disabled) {\n if (astName === 'disabled') {\n matched.add(node);\n }\n } else if (astName === 'enabled') {\n matched.add(node);\n }\n }\n break;\n }\n case 'read-only':\n case 'read-write': {\n let readonly;\n let writable;\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n readonly = true;\n } else {\n writable = true;\n }\n break;\n }\n case 'input': {\n if (!node.type || KEY_INPUT_EDIT.includes(node.type)) {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n readonly = true;\n } else {\n writable = true;\n }\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n writable = true;\n } else {\n readonly = true;\n }\n }\n }\n if (readonly) {\n if (astName === 'read-only') {\n matched.add(node);\n }\n } else if (astName === 'read-write' && writable) {\n matched.add(node);\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 const keys = [...KEY_INPUT_TEXT, 'number'];\n if (keys.includes(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 const attrType = node.getAttribute('type');\n if ((node.checked && localName === 'input' &&\n (attrType === 'checkbox' || attrType === 'radio')) ||\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 const chekcKeys = ['checkbox', 'radio'];\n const resetKeys = ['button', 'reset'];\n const submitKeys = ['image', 'submit'];\n const attrType = node.getAttribute('type');\n if ((localName === 'button' &&\n !(node.hasAttribute('type') && resetKeys.includes(attrType))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n submitKeys.includes(attrType))) {\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 const nodeAttrType = nextNode.getAttribute('type');\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n resetKeys.includes(nodeAttrType));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n submitKeys.includes(nodeAttrType);\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 chekcKeys.includes(attrType) &&\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 case 'invalid': {\n const keys = [...KEY_FORM_FOCUS, 'form'];\n if (keys.includes(localName)) {\n let valid;\n if (node.checkValidity()) {\n if (node.maxLength >= 0) {\n if (node.maxLength >= node.value.length) {\n valid = true;\n }\n } else {\n valid = true;\n }\n }\n if (valid) {\n if (astName === 'valid') {\n matched.add(node);\n }\n } else if (astName === 'invalid') {\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 valid;\n if (!refNode) {\n valid = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (keys.includes(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n valid = refNode.maxLength >= refNode.value.length;\n } else {\n valid = true;\n }\n } else {\n valid = false;\n }\n if (!valid) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (valid) {\n if (astName === 'valid') {\n matched.add(node);\n }\n } else if (astName === 'invalid') {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range':\n case 'out-of-range': {\n const keys = [...KEY_INPUT_DATE, 'number', 'range'];\n const attrType = node.getAttribute('type');\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n keys.includes(attrType)) {\n const flowed =\n node.validity.rangeUnderflow || node.validity.rangeOverflow;\n if (astName === 'out-of-range' && flowed) {\n matched.add(node);\n } else if (astName === 'in-range' && !flowed &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n attrType === 'range')) {\n matched.add(node);\n }\n }\n break;\n }\n case 'required':\n case 'optional': {\n let targetNode;\n if (localName === 'select' || localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const keys = [...KEY_INPUT_EDIT, 'checkbox', 'file', 'radio'];\n const attrType = node.getAttribute('type');\n if (keys.includes(attrType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode) {\n if (node.required || node.hasAttribute('required')) {\n if (astName === 'required') {\n matched.add(node);\n }\n } else if (astName === 'optional') {\n matched.add(node);\n }\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 return 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 return node;\n }\n }\n } else if (astName === 'host') {\n return 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.} - 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 (KEY_LOGICAL.includes(astName)) {\n opt.isShadowRoot = true;\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n } else if (astName === 'host' || astName === 'host-context') {\n const res = this._matchShadowHostPseudoClass(ast, node, opt);\n if (res) {\n this.#verifyShadowHost = true;\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n 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 const formKeys = [...KEY_FORM_FOCUS, 'fieldset', 'form'];\n const pseudoKeys = ['any-link', 'defined', 'dir', 'link'];\n if (node.nodeType === ELEMENT_NODE && formKeys.includes(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 (pseudoKeys.includes(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.} - matched nodes\n */\n _matchHTMLCollection(items, opt) {\n const { compound, filterLeaves } = opt;\n const nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n return new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (typeof leafName === 'string' && leafName !== leaf.name) {\n leaf.name = leafName;\n }\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case 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.} - 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.} leaves - AST leaves\n * @param {object} node - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, node) {\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, this.#node);\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 * @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 &&\n (leafName === 'host' || leafName === 'host-context')) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === 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 (comboName === '+' || 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 (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 {\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 (comboName === '+' || 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.} - collection of matched nodes\n */\n _getCombinedNodes(twig, nodes, dir) {\n const arr = [];\n for (const node of nodes) {\n const matched = this._matchCombinator(twig, node, {\n dir,\n warn: this.#warn\n });\n if (matched.size) {\n arr.push(...matched);\n }\n }\n if (arr.length) {\n return new Set(arr);\n }\n return new Set();\n }\n\n /**\n * match node to next direction\n * @private\n * @param {Array} branch - branch\n * @param {Set.} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {Set.} - collection of matched nodes\n */\n find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], 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_FIRST) {\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, entryNode);\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, refNode);\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, entryNode);\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, refNode);\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"], + "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAwB,wBACxBC,EAEO,uBACPC,EAGO,wBAGPC,EAOO,yBACP,MAAMC,EAAW,OACXC,EAAW,OA0BV,MAAMP,CAAO,CAElBQ,GACAC,G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,KAAK,UAAU0G,EAAaC,CAAS,EACnD,KAAO3G,GAAS,CAId,GAHAF,EAAU,KAAK,eAAeV,EAAQY,EAAS,CAC7C,MAAO4B,EAAY,CACrB,CAAC,EACG9B,EAAS,CACXzB,EAAM,IAAI2B,CAAO,EACjB,KACF,CACAA,EAAU,KAAK,UAAU0G,EAAa1G,CAAO,CAC/C,CACF,CACF,CACF,CACF,CACA,OAAIqF,IAAe,gBACjBhH,EAAM,OAAO,KAAK1B,EAAK,EACnB0B,EAAM,KAAO,IACfA,EAAQ,IAAI,OAAI,aAAUA,CAAK,CAAC,IAEzBgH,IAAe,eACxBhH,EAAM,OAAO,KAAK1B,EAAK,EACnByJ,GAAQ/H,EAAM,KAAO,IACvBA,EAAQ,IAAI,OAAI,aAAUA,CAAK,CAAC,IAG7BA,CACT,CACF", + "names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_matcher", "import_parser", "import_utility", "import_constant", "DIR_NEXT", "DIR_PREV", "#ast", "#astCache", "#descendant", "#document", "#documentCache", "#event", "#focus", "#invalidate", "#invalidateResults", "#matcher", "#node", "#nodes", "#noexcept", "#qswalker", "#results", "#root", "#shadow", "#verifyShadowHost", "#walker", "#walkers", "#warn", "#window", "window", "e", "opt", "selector", "node", "event", "noexcept", "warn", "func", "mouseKeys", "key", "evt", "keyboardKeys", "focusKeys", "nodes", "ast", "cachedItem", "item", "l", "i", "cssAst", "branches", "info", "hasHasPseudoFunc", "hasLogicalPseudoFunc", "hasNthChildOfSelector", "invalidate", "descendant", "items", "branch", "leaves", "itemName", "nextItem", "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", "isShadowRoot", "res", "lastIndex", "nextNodes", "arr", "astChildren", "forgive", "child", "nestedLeaf", "css", "leavesSet", "stateValue", "prop", "href", "origin", "pathname", "attrURL", "target", "type", "buttons", "hash", "id", "current", "relatedTarget", "disabled", "parent", "readonly", "writable", "placeholder", "targetNode", "attrType", "nodeName", "checked", "chekcKeys", "resetKeys", "submitKeys", "form", "nodeAttrType", "keys", "valid", "flowed", "node1", "node2", "host", "astType", "result", "cacheable", "formKeys", "pseudoKeys", "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"] } diff --git a/package.json b/package.json index cb2b860..c3e3eff 100644 --- a/package.json +++ b/package.json @@ -63,5 +63,5 @@ "tsc": "node scripts/index clean --dir=types -i && npx tsc", "update-wpt": "git submodule update --init --recursive --remote" }, - "version": "6.0.1" + "version": "6.0.2" }