@asamuzakjp/dom-selector 5.0.5 → 5.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var T=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var U=(x,c)=>{for(var e in c)T(x,e,{get:c[e],enumerable:!0})},F=(x,c,e,h)=>{if(c&&typeof c=="object"||typeof c=="function")for(let o of I(c))!$.call(x,o)&&o!==e&&T(x,o,{get:()=>c[o],enumerable:!(h=D(c,o))||h.enumerable});return x};var G=x=>F(T({},"__esModule",{value:!0}),x);var H={};U(H,{Finder:()=>W});module.exports=G(H);var k=require("./dom-util.js"),L=require("./matcher.js"),g=require("./parser.js"),a=require("./constant.js");const v="next",S="prev";class W{#a;#n;#p;#t;#c;#d;#o;#b;#e;#f;#k;#u;#w;#s;#h;#r;#m;#i;#l;constructor(c){this.#l=c,this.#n=new WeakMap,this.#c=new WeakMap,this.#b=new WeakMap,this.#w=new WeakMap}_onError(c){if(!this.#k)if(c instanceof DOMException||c instanceof this.#l.DOMException)if(c.name===a.NOT_SUPPORTED_ERR)this.#i&&console.warn(c.message);else throw new this.#l.DOMException(c.message,c.name);else throw c}_setup(c,e,h={}){const{event:o,noexcept:l,warn:n}=h;return this.#k=!!l,this.#i=!!n,this.#d=this._setEvent(o),this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#h=(0,k.isInShadowTree)(e),[this.#a,this.#f]=this._correspond(c),this.#b=new WeakMap,this.#m=new WeakMap,e}_setEvent(c){return c instanceof this.#l.KeyboardEvent||c instanceof this.#l.MouseEvent?c:null}_correspond(c){const e=[];this.#p=!1,this.#o=!1;let h;if(this.#c.has(this.#t)){const o=this.#c.get(this.#t);if(o&&o.has(`${c}`)){const l=o.get(`${c}`);h=l.ast,this.#p=l.descendant,this.#o=l.invalidate}}if(h){const o=h.length;for(let l=0;l<o;l++)h[l].collected=!1,h[l].dir=null,h[l].filtered=!1,h[l].find=!1,e[l]=[]}else{let o;try{o=(0,g.parseSelector)(c)}catch(t){this._onError(t)}const{branches:l,info:{hasHasPseudoFunc:n}}=(0,g.walkAST)(o),f=!!n;let b=!1,d=0;h=[];for(const[...t]of l){const s=[];let r=t.shift();if(r&&r.type!==a.COMBINATOR){const u=new Set;for(;r;){if(r.type===a.COMBINATOR){const[m]=t;if(m.type===a.COMBINATOR){const p=`Invalid selector ${c}`;throw new DOMException(p,a.SYNTAX_ERR)}const w=r.name;/^[\s>]$/.test(w)&&(b=!0),s.push({combo:r,leaves:(0,g.sortAST)(u)}),u.clear()}else if(r){let{name:m}=r;m&&typeof m=="string"&&(m=(0,g.unescapeSelector)(m),typeof m=="string"&&m!==r.name&&(r.name=m),/[|:]/.test(m)&&(r.namespace=!0)),u.add(r)}if(t.length)r=t.shift();else{s.push({combo:null,leaves:(0,g.sortAST)(u)}),u.clear();break}}}h.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[d]=[],d++}let i;this.#c.has(this.#t)?i=this.#c.get(this.#t):i=new Map,i.set(`${c}`,{ast:h,descendant:b,invalidate:f}),this.#c.set(this.#t,i),this.#p=b,this.#o=f}return[h,e]}_createTreeWalker(c){let e;return this.#m.has(c)?e=this.#m.get(c):(e=this.#t.createTreeWalker(c,a.WALKER_FILTER),this.#m.set(c,e)),e}_prepareQuerySelectorWalker(){return this.#u=this._createTreeWalker(this.#e),this.#u}_collectNthChild(c,e,h){const{a:o,b:l,reverse:n,selector:f}=c,{parentNode:b}=e,d=new Set;let i;if(f)if(this.#n.has(f))i=this.#n.get(f);else{const{branches:t,info:s}=(0,g.walkAST)(f);i=t,this.#n.set(f,i),s.hasLogicalPseudoFunc&&(this.#o=!0)}if(b){const t=this.#r;let s=(0,k.traverseNode)(b,t);s=t.firstChild();let r=0;for(;s;)r++,s=t.nextSibling();const u=new Set;if(i)for(s=(0,k.traverseNode)(b,t),s=t.firstChild();s;){const{display:m,visibility:w}=this.#l.getComputedStyle(s);if(m!=="none"&&w!=="hidden"){let p;for(const N of i)if(p=this._matchLeaves(N,s,h),!p)break;p&&u.add(s)}s=t.nextSibling()}if(o===0){if(l>0&&l<=r){if(u.size){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(u.has(s)){if(m===l-1){d.add(s);break}m++}n?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(m===l-1){d.add(s);break}n?s=t.previousSibling():s=t.nextSibling(),m++}}}}else{let m=l-1;if(o>0)for(;m<0;)m+=o;if(m>=0&&m<r){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let w=0,p=o>0?0:l-1;for(;s&&(s&&m>=0&&m<r);)u.size?u.has(s)&&(p===m&&(d.add(s),m+=o),o>0?p++:p--):w===m&&(f||d.add(s),m+=o),n?s=t.previousSibling():s=t.nextSibling(),w++}}if(n&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&o+l===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(c,e){const{a:h,b:o,reverse:l}=c,{localName:n,parentNode:f,prefix:b}=e,d=new Set;if(f){const i=this.#r;let t=(0,k.traverseNode)(f,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(o>0&&o<=s){t=(0,k.traverseNode)(f,i),l?t=i.lastChild():t=i.firstChild();let r=0;for(;t;){const{localName:u,prefix:m}=t;if(u===n&&m===b){if(r===o-1){d.add(t);break}r++}l?t=i.previousSibling():t=i.nextSibling()}}}else{let r=o-1;if(h>0)for(;r<0;)r+=h;if(r>=0&&r<s){t=(0,k.traverseNode)(f,i),l?t=i.lastChild():t=i.firstChild();let u=h>0?0:o-1;for(;t;){const{localName:m,prefix:w}=t;if(m===n&&w===b){if(u===r&&(d.add(t),r+=h),r<0||r>=s)break;h>0?u++:u--}l?t=i.previousSibling():t=i.nextSibling()}}}if(l&&d.size>1){const r=[...d];return new Set(r.reverse())}}else e===this.#s&&h+o===1&&d.add(e);return d}_matchAnPlusB(c,e,h,o){const{nth:{a:l,b:n,name:f},selector:b}=c,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)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?d.set("a",l*1):d.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?d.set("b",n*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){b&&d.set("selector",b);const i=Object.fromEntries(d);return this._collectNthChild(i,e,o)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(c,e,h={}){let o;if(Array.isArray(c)&&c.length){const l=c.map(s=>s),[n]=l,{type:f}=n;let b;f===a.COMBINATOR?b=l.shift():b={name:" ",type:a.COMBINATOR};const d=[];for(;l.length;){const[s]=l,{type:r}=s;if(r===a.COMBINATOR)break;d.push(l.shift())}const i={combo:b,leaves:d};h.dir=v;const t=this._matchCombinator(i,e,h);if(t.size)if(l.length){for(const s of t)if(o=this._matchHasPseudoFunc(l,s,h),o)break}else o=!0}return!!o}_matchLogicalPseudoFunc(c,e,h={}){const{astName:o="",branches:l=[],selector:n="",twigBranches:f=[]}=c;let b;if(o==="has")if(n.includes(":has("))b=null;else{let d;for(const i of l)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(b=e)}else{const d=/^(?:is|where)$/.test(o);h.forgive=d;const i=f.length;let t;for(let s=0;s<i;s++){const r=f[s],u=r.length-1,{leaves:m}=r[u];if(t=this._matchLeaves(m,e,h),t&&u>0){let w=new Set([e]);for(let p=u-1;p>=0;p--){const N=r[p],_=[];h.dir=S;for(const y of w){const E=this._matchCombinator(N,y,h);E.size&&_.push(...E)}if(_.length)p===0?t=!0:w=new Set(_);else{t=!1;break}}}if(t)break}o==="not"?t||(b=e):t&&(b=e)}return b??null}_matchPseudoClassSelector(c,e,h={}){const{children:o,name:l}=c,{localName:n,parentNode:f}=e,{forgive:b,warn:d=this.#i}=h,i=new Set;if(a.REG_LOGICAL_PSEUDO.test(l)){let t;if(this.#n.has(c))t=this.#n.get(c);else{const{branches:r}=(0,g.walkAST)(c),u=[],m=[];for(const[...w]of r){for(const y of w){const E=(0,g.generateCSS)(y);u.push(E)}const p=[],N=new Set;let _=w.shift();for(;_;)if(_.type===a.COMBINATOR?(p.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),w.length)_=w.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}m.push(p)}t={astName:l,branches:r,twigBranches:m,selector:u.join(",")},this.#n.set(c,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(o))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const[t]=o;return this._matchAnPlusB(t,e,l,h)}else switch(l){case"dir":case"lang":{const t=L.matcher.matchSelector(c,e);t&&i.add(t);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:t}]=o;t&&e[t]&&i.add(e)}break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${l}()`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}default:if(!b){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,a.SYNTAX_ERR)}}else switch(l){case"any-link":case"link":{a.REG_ANCHOR.test(n)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(a.REG_ANCHOR.test(n)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:r}=new URL(this.#t.URL),u=new URL(e.getAttribute("href"),t);u.origin===s&&u.pathname===r&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#d??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:r}=this.#d??{};(r==="mousedown"||r==="pointerdown")&&t&a.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 r=this.#t.getElementById(s);for(;r;){if(r===e){i.add(e);break}r=r.parentNode}}break}case"scope":{this.#e.nodeType===a.ELEMENT_NODE?!this.#h&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#d??{};if(e===this.#t.activeElement&&e.tabIndex>=0&&(l==="focus"||s==="keydown"&&e.contains(t))){let r=e,u=!0;for(;r;){if(r.disabled||r.hasAttribute("disabled")||r.hidden||r.hasAttribute("hidden")){u=!1;break}else{const{display:m,visibility:w}=this.#l.getComputedStyle(r);if(u=!(m==="none"||w==="hidden"),!u)break}if(r.parentNode&&r.parentNode.nodeType===a.ELEMENT_NODE)r=r.parentNode;else break}u&&i.add(e)}break}case"focus-within":{let t,s=this.#t.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}if(t){let r=e,u=!0;for(;r;){if(r.disabled||r.hasAttribute("disabled")||r.hidden||r.hasAttribute("hidden")){u=!1;break}else{const{display:m,visibility:w}=this.#l.getComputedStyle(r);if(u=!(m==="none"||w==="hidden"),!u)break}if(r.parentNode&&r.parentNode.nodeType===a.ELEMENT_NODE)r=r.parentNode;else break}u&&i.add(e)}break}case"open":{a.REG_INTERACT.test(n)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{a.REG_INTERACT.test(n)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(a.REG_FORM_CTRL.test(n)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let t,s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const r=this.#r;let u=(0,k.traverseNode)(s,r);for(u=r.firstChild();u&&u.localName!=="legend";)u=r.nextSibling();u&&u.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===a.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t&&i.add(e)}}break}case"enabled":{if((a.REG_FORM_CTRL.test(n)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(f.localName!=="optgroup"||!(f.disabled||f.hasAttribute("disabled")))&&i.add(e);else{let t,s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const r=this.#r;let u=(0,k.traverseNode)(s,r);for(u=r.firstChild();u&&u.localName!=="legend";)u=r.nextSibling();u&&u.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===a.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t||i.add(e)}break}case"read-only":{switch(n){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||a.REG_TYPE_DATE.test(e.type)||a.REG_TYPE_TEXT.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(n){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||a.REG_TYPE_DATE.test(e.type)||a.REG_TYPE_TEXT.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;n==="textarea"?s=e:n==="input"&&(e.hasAttribute("type")?a.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&n==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&n==="input"&&e.type==="checkbox"||n==="progress"&&!e.hasAttribute("value"))i.add(e);else if(n==="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 r=s.getElementsByTagName("input"),u=r.length;let m;for(let w=0;w<u;w++){const p=r[w];if(p.getAttribute("type")==="radio"&&(t?p.getAttribute("name")===t&&(m=!!p.checked):p.hasAttribute("name")||(m=!!p.checked),m))break}m||i.add(e)}break}case"default":{if(n==="button"&&!(e.hasAttribute("type")&&a.REG_TYPE_RESET.test(e.getAttribute("type")))||n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#r;let r=(0,k.traverseNode)(t,s);for(r=s.firstChild();r&&t.contains(r);){const u=r.localName;let m;if(u==="button"?m=!(r.hasAttribute("type")&&a.REG_TYPE_RESET.test(r.getAttribute("type"))):u==="input"&&(m=r.hasAttribute("type")&&a.REG_TYPE_SUBMIT.test(r.getAttribute("type"))),m){r===e&&i.add(e);break}r=s.nextNode()}}}else(n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_CHECK.test(e.getAttribute("type"))&&e.hasAttribute("checked")||n==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(a.REG_FORM_VALID.test(n))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(n==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let r;if(!s)r=!0;else for(;s&&e.contains(s)&&!(a.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?r=s.maxLength>=s.value.length:r=!0:r=!1,!r));)s=t.nextNode();r&&i.add(e)}break}case"invalid":{if(a.REG_FORM_VALID.test(n))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(n==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let r;if(!s)r=!0;else for(;s&&e.contains(s)&&!(a.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?r=s.maxLength>=s.value.length:r=!0:r=!1,!r));)s=t.nextNode();r||i.add(e)}break}case"in-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&a.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&a.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(n))t=e;else if(n==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||a.REG_TYPE_CHECK.test(s)||a.REG_TYPE_DATE.test(s)||a.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(n))t=e;else if(n==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||a.REG_TYPE_CHECK.test(s)||a.REG_TYPE_DATE.test(s)||a.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#t.createTreeWalker(e,a.SHOW_ALL);let s=t.firstChild(),r;for(;s&&(r=s.nodeType!==a.ELEMENT_NODE&&s.nodeType!==a.TEXT_NODE,!!r);)s=t.nextSibling();r&&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")||n.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#l.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${l}`;throw new DOMException(t,a.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){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}}else if(!b){const t=`Unknown pseudo-class :${l}`;throw new DOMException(t,a.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(c,e){const{children:h,name:o}=c;let l;if(Array.isArray(h)){const{branches:n}=(0,g.walkAST)(h[0]),[f]=n,[...b]=f,{host:d}=e;if(o==="host"){let i;for(const t of b){const{type:s}=t;if(s===a.COMBINATOR){const u=`Invalid selector ${(0,g.generateCSS)(c)}`;throw new DOMException(u,a.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(l=e)}else if(o==="host-context"){let i=d,t;for(;i;){for(const s of b){const{type:r}=s;if(r===a.COMBINATOR){const m=`Invalid selector ${(0,g.generateCSS)(c)}`;throw new DOMException(m,a.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(l=e)}}else if(o==="host")l=e;else{const n=`Invalid selector :${o}`;throw new DOMException(n,a.SYNTAX_ERR)}return l??null}_matchSelector(c,e,h){const{type:o}=c,l=new Set;if(c.name===a.EMPTY)return l;const n=(0,g.unescapeSelector)(c.name);if(typeof n=="string"&&n!==c.name&&(c.name=n),e.nodeType===a.ELEMENT_NODE)switch(o){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(n,h);break}case a.SELECTOR_ID:{e.id===n&&l.add(e);break}case a.SELECTOR_CLASS:{e.classList.contains(n)&&l.add(e);break}case a.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(c,e,h);default:{const f=L.matcher.matchSelector(c,e,h);f&&l.add(f)}}else if(this.#h&&o===a.SELECTOR_PSEUDO_CLASS&&e.nodeType===a.DOCUMENT_FRAGMENT_NODE){if(n!=="has"&&a.REG_LOGICAL_PSEUDO.test(n))return this._matchPseudoClassSelector(c,e,h);if(a.REG_SHADOW_HOST.test(n)){const f=this._matchShadowHostPseudoClass(c,e,h);f&&l.add(f)}}return l}_matchLeaves(c,e,h){let o,l;if(this.#o?l=this.#b.get(c):l=this.#w.get(c),l&&l.has(e)){const{matched:n}=l.get(e);o=n}if(typeof o!="boolean"){let n=!0;e.nodeType===a.ELEMENT_NODE&&a.REG_FORM.test(e.localName)&&(n=!1);for(const f of c){switch(f.type){case a.SELECTOR_ATTR:case a.SELECTOR_ID:{n=!1;break}case a.SELECTOR_PSEUDO_CLASS:{/^(?:(?:any-)?link|defined)$/.test(f.name)&&(n=!1);break}default:}if(o=this._matchSelector(f,e,h).has(e),!o)break}n&&(l||(l=new WeakMap),l.set(e,{matched:o}),this.#o?this.#b.set(c,l):this.#w.set(c,l))}return!!o}_matchHTMLCollection(c,e={}){const{compound:h,filterLeaves:o}=e,l=new Set,n=c.length;if(n)if(h)for(let f=0;f<n;f++){const b=c[f];this._matchLeaves(o,b,e)&&l.add(b)}else{const f=[].slice.call(c);return new Set(f)}return l}_findDescendantNodes(c,e,h){const[o,...l]=c,n=l.length>0,{type:f}=o,b=(0,g.unescapeSelector)(o.name);typeof b=="string"&&b!==o.name&&(o.name=b);let d=new Set,i=!1;if(this.#h)i=!0;else switch(f){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(b,h);break}case a.SELECTOR_ID:{if(this.#s.nodeType===a.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(b);t&&t!==e&&e.contains(t)&&(n?this._matchLeaves(l,t,h)&&d.add(t):d.add(t))}break}case a.SELECTOR_CLASS:{const t=e.getElementsByClassName(b);d=this._matchHTMLCollection(t,{compound:n,filterLeaves:l});break}case a.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(b)){const t=e.getElementsByTagName(b);d=this._matchHTMLCollection(t,{compound:n,filterLeaves:l})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(c,e,h={}){const{combo:o,leaves:l}=c,{name:n}=o,{parentNode:f}=e,{dir:b}=h,d=new Set;if(b===v)switch(n){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(l,i,h)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,k.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,k.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(l,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let r=(0,k.traverseNode)(e,s);for(r=s.nextNode();r&&e.contains(r);)this._matchLeaves(l,r,h)&&d.add(r),r=s.nextNode()}}}else switch(n){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(l,i,h)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,k.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(l,f,h)&&d.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(l,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(c,e){const{node:h}=e,o=this.#u;let l=(0,k.traverseNode)(h,o),n;if(l)for((l.nodeType!==a.ELEMENT_NODE||l===h&&l!==this.#s)&&(l=o.nextNode());l;){if(this._matchLeaves(c,l,{warn:this.#i})){n=l;break}l=o.nextNode()}return n??null}_matchSelf(c){const e=[],h=this._matchLeaves(c,this.#e,{warn:this.#i});let o=!1;return h&&(e.push(this.#e),o=!0),[e,o]}_findLineal(c,e={}){const{complex:h}=e,o=[];let l=this._matchLeaves(c,this.#e,{warn:this.#i}),n=!1;if(l&&(o.push(this.#e),n=!0),!l||h){let f=this.#e.parentNode;for(;f&&(l=this._matchLeaves(c,f,{warn:this.#i}),l&&(o.push(f),n=!0),f.parentNode);)f=f.parentNode}return[o,n]}_findFirst(c){const e=[],h=this._findNode(c,{node:this.#e});let o=!1;return h&&(e.push(h),o=!0),[e,o]}_findFromHTMLCollection(c,e={}){const{complex:h,compound:o,filterLeaves:l,targetType:n}=e;let f=[],b=!1,d=!1;const i=c.length;if(i)if(this.#e.nodeType===a.ELEMENT_NODE)for(let t=0;t<i;t++){const s=c[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(o){if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else if(f.push(s),b=!0,n===a.TARGET_FIRST)break}}else if(h)if(o)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else f=[].slice.call(c),b=!0,d=!0;else if(o)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else f=[].slice.call(c),b=!0,d=!0;return[f,b,d]}_findEntryNodes(c,e,h){const{leaves:o}=c,[l,...n]=o,f=n.length>0,{name:b,type:d}=l;let i=[],t=!1,s=!1,r=!1;switch(d){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(b,{warn:this.#i});break}case a.SELECTOR_ID:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(e===a.TARGET_FIRST&&this.#s.nodeType!==a.ELEMENT_NODE){const u=this.#s.getElementById(b);u&&(f?this._matchLeaves(n,u,{warn:this.#i})&&(i.push(u),s=!0):(i.push(u),s=!0))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}case a.SELECTOR_CLASS:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(this.#s.nodeType===a.DOCUMENT_NODE){const u=this.#s.getElementsByClassName(b);u.length&&([i,s,t]=this._findFromHTMLCollection(u,{complex:h,compound:f,filterLeaves:n,targetType:e}))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}case a.SELECTOR_TYPE:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===a.DOCUMENT_NODE&&!/[*|]/.test(b)){const u=this.#s.getElementsByTagName(b);u.length&&([i,s,t]=this._findFromHTMLCollection(u,{complex:h,compound:f,filterLeaves:n,targetType:e}))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}default:if(e!==a.TARGET_LINEAL&&a.REG_SHADOW_HOST.test(b)){if(this.#h&&this.#e.nodeType===a.DOCUMENT_FRAGMENT_NODE){const u=this._matchShadowHostPseudoClass(l,this.#e);u&&(i.push(u),s=!0)}}else e===a.TARGET_SELF?[i,s]=this._matchSelf(o):e===a.TARGET_LINEAL?[i,s]=this._findLineal(o,{complex:h}):e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:r}}_collectNodes(c){const e=this.#a.values();if(c===a.TARGET_ALL||c===a.TARGET_FIRST){const h=new Set;let o=0;for(const{branch:l}of e){const n=l.length,f=n>1,b=l[0];let d,i;if(f){const{combo:w,leaves:[{name:p,type:N}]}=b,_=l[n-1],{leaves:[{name:y,type:E}]}=_;if(E===a.SELECTOR_PSEUDO_ELEMENT||E===a.SELECTOR_ID)d=S,i=_;else if(N===a.SELECTOR_PSEUDO_ELEMENT||N===a.SELECTOR_ID)d=v,i=b;else if(c===a.TARGET_ALL)if(p==="*"&&N===a.SELECTOR_TYPE)d=S,i=_;else if(y==="*"&&E===a.SELECTOR_TYPE)d=v,i=b;else if(n===2){const{name:A}=w;/^[+~]$/.test(A)?(d=S,i=_):(d=v,i=b)}else d=v,i=b;else if(y==="*"&&E===a.SELECTOR_TYPE)d=v,i=b;else if(p==="*"&&N===a.SELECTOR_TYPE)d=S,i=_;else{let A;for(const{combo:C,leaves:[R]}of l){const{name:O,type:M}=R;if(M===a.SELECTOR_PSEUDO_CLASS&&O==="dir"){A=!1;break}if(!A&&C){const{name:P}=C;/^[+~]$/.test(P)&&(A=!0)}}A?(d=v,i=b):(d=S,i=_)}}else d=S,i=b;const{collected:t,compound:s,filtered:r,nodes:u,pending:m}=this._findEntryNodes(i,c,f);u.length?(this.#a[o].find=!0,this.#f[o]=u):m&&h.add(new Map([["index",o],["twig",i]])),this.#a[o].collected=t,this.#a[o].dir=d,this.#a[o].filtered=r||!s,o++}if(h.size){let l,n;this.#e!==this.#s&&this.#e.nodeType===a.ELEMENT_NODE?(l=this.#e,n=this.#u):(l=this.#s,n=this.#r);let f=(0,k.traverseNode)(l,n);for(;f;){let b=!1;if(this.#e.nodeType===a.ELEMENT_NODE?f===this.#e?b=!0:b=this.#e.contains(f):b=!0,b)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=d.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#f[s].push(f)}}f!==n.currentNode&&(f=(0,k.traverseNode)(f,n)),f=n.nextNode()}}}else{let h=0;for(const{branch:o}of e){const l=o[o.length-1],n=o.length>1,{compound:f,filtered:b,nodes:d}=this._findEntryNodes(l,c,n);d.length&&(this.#a[h].find=!0,this.#f[h]=d),this.#a[h].dir=S,this.#a[h].filtered=b||!f,h++}}return[this.#a,this.#f]}_getCombinedNodes(c,e,h){const o=[];for(const l of e){const n=this._matchCombinator(c,l,{dir:h,warn:this.#i});n.size&&o.push(...n)}return o.length?new Set(o):new Set}_matchNodeNext(c,e,h){const{combo:o,index:l}=h,{combo:n,leaves:f}=c[l],b={combo:o,leaves:f},d=this._getCombinedNodes(b,e,v);let i;if(d.size)if(l===c.length-1){const[t]=(0,k.sortNodes)(d);i=t}else i=this._matchNodeNext(c,d,{combo:n,index:l+1});return i??null}_matchNodePrev(c,e,h){const{index:o}=h,l=c[o],n=new Set([e]),f=this._getCombinedNodes(l,n,S);let b;if(f.size){if(o===0)b=e;else for(const d of f)if(this._matchNodePrev(c,d,{index:o-1}))return e}return b??null}_find(c){(c===a.TARGET_ALL||c===a.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(c),o=e.length;let l,n=new Set;for(let f=0;f<o;f++){const{branch:b,collected:d,dir:i,find:t}=e[f],s=b.length;if(s&&t){const r=h[f],u=r.length,m=s-1;if(m===0)if((c===a.TARGET_ALL||c===a.TARGET_FIRST)&&this.#e.nodeType===a.ELEMENT_NODE)for(let w=0;w<u;w++){const p=r[w];if(p!==this.#e&&this.#e.contains(p)&&(n.add(p),c!==a.TARGET_ALL))break}else if(c===a.TARGET_ALL)if(n.size){const w=[...n];n=new Set([...w,...r]),l=!0}else n=new Set(r);else{const[w]=r;n.add(w)}else if(c===a.TARGET_ALL)if(i===v){let{combo:w}=b[0];for(const p of r){let N=new Set([p]);for(let _=1;_<s;_++){const{combo:y,leaves:E}=b[_],A={combo:w,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(n.size){const C=[...n];n=new Set([...C,...N]),l=!0}else n=N;else w=y;else break}}}else for(const w of r){let p=new Set([w]);for(let N=m-1;N>=0;N--){const _=b[N];if(p=this._getCombinedNodes(_,p,i),p.size)N===0&&(n.add(w),s>1&&n.size>1&&(l=!0));else break}}else if(c===a.TARGET_FIRST&&i===v){const{combo:w}=b[0];let p;for(const N of r)if(p=this._matchNodeNext(b,new Set([N]),{combo:w,index:1}),p){n.add(p);break}if(!p&&!d){const{leaves:N}=b[0],[_]=r;let y=this._findNode(N,{node:_});for(;y;){if(p=this._matchNodeNext(b,new Set([y]),{combo:w,index:1}),p){n.add(p);break}y=this._findNode(N,{node:y})}}}else{let w;for(const p of r)if(w=this._matchNodePrev(b,p,{index:m-1}),w){n.add(p);break}if(!w&&!d&&c===a.TARGET_FIRST){const{leaves:p}=b[m],[N]=r;let _=this._findNode(p,{node:N});for(;_;){if(w=this._matchNodePrev(b,_,{index:m-1}),w){n.add(_);break}_=this._findNode(p,{node:_})}}}}}return c===a.TARGET_ALL&&l&&(n=new Set((0,k.sortNodes)(n))),n}}0&&(module.exports={Finder});
1
+ var T=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var U=(x,c)=>{for(var e in c)T(x,e,{get:c[e],enumerable:!0})},F=(x,c,e,h)=>{if(c&&typeof c=="object"||typeof c=="function")for(let o of I(c))!$.call(x,o)&&o!==e&&T(x,o,{get:()=>c[o],enumerable:!(h=D(c,o))||h.enumerable});return x};var G=x=>F(T({},"__esModule",{value:!0}),x);var H={};U(H,{Finder:()=>W});module.exports=G(H);var k=require("./dom-util.js"),L=require("./matcher.js"),g=require("./parser.js"),a=require("./constant.js");const v="next",S="prev";class W{#a;#n;#p;#t;#c;#d;#o;#b;#e;#f;#k;#u;#w;#s;#h;#r;#m;#i;#l;constructor(c){this.#l=c,this.#n=new WeakMap,this.#c=new WeakMap,this.#b=new WeakMap,this.#w=new WeakMap}_onError(c){if(!this.#k)if(c instanceof DOMException||c instanceof this.#l.DOMException)if(c.name===a.NOT_SUPPORTED_ERR)this.#i&&console.warn(c.message);else throw new this.#l.DOMException(c.message,c.name);else throw c}_setup(c,e,h={}){const{event:o,noexcept:l,warn:n}=h;return this.#k=!!l,this.#i=!!n,this.#d=this._setEvent(o),this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#h=(0,k.isInShadowTree)(e),[this.#a,this.#f]=this._correspond(c),this.#b=new WeakMap,this.#m=new WeakMap,e}_setEvent(c){return c instanceof this.#l.KeyboardEvent||c instanceof this.#l.MouseEvent?c:null}_correspond(c){const e=[];this.#p=!1,this.#o=!1;let h;if(this.#c.has(this.#t)){const o=this.#c.get(this.#t);if(o&&o.has(`${c}`)){const l=o.get(`${c}`);h=l.ast,this.#p=l.descendant,this.#o=l.invalidate}}if(h){const o=h.length;for(let l=0;l<o;l++)h[l].collected=!1,h[l].dir=null,h[l].filtered=!1,h[l].find=!1,e[l]=[]}else{let o;try{o=(0,g.parseSelector)(c)}catch(t){this._onError(t)}const{branches:l,info:{hasHasPseudoFunc:n}}=(0,g.walkAST)(o),f=!!n;let b=!1,d=0;h=[];for(const[...t]of l){const s=[];let r=t.shift();if(r&&r.type!==a.COMBINATOR){const u=new Set;for(;r;){if(r.type===a.COMBINATOR){const[m]=t;if(m.type===a.COMBINATOR){const p=`Invalid selector ${c}`;throw new DOMException(p,a.SYNTAX_ERR)}const w=r.name;/^[\s>]$/.test(w)&&(b=!0),s.push({combo:r,leaves:(0,g.sortAST)(u)}),u.clear()}else if(r){let{name:m}=r;m&&typeof m=="string"&&(m=(0,g.unescapeSelector)(m),typeof m=="string"&&m!==r.name&&(r.name=m),/[|:]/.test(m)&&(r.namespace=!0)),u.add(r)}if(t.length)r=t.shift();else{s.push({combo:null,leaves:(0,g.sortAST)(u)}),u.clear();break}}}h.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[d]=[],d++}let i;this.#c.has(this.#t)?i=this.#c.get(this.#t):i=new Map,i.set(`${c}`,{ast:h,descendant:b,invalidate:f}),this.#c.set(this.#t,i),this.#p=b,this.#o=f}return[h,e]}_createTreeWalker(c){let e;return this.#m.has(c)?e=this.#m.get(c):(e=this.#t.createTreeWalker(c,a.WALKER_FILTER),this.#m.set(c,e)),e}_prepareQuerySelectorWalker(){return this.#u=this._createTreeWalker(this.#e),this.#u}_collectNthChild(c,e,h){const{a:o,b:l,reverse:n,selector:f}=c,{parentNode:b}=e,d=new Set;let i;if(f)if(this.#n.has(f))i=this.#n.get(f);else{const{branches:t,info:s}=(0,g.walkAST)(f);i=t,this.#n.set(f,i),s.hasLogicalPseudoFunc&&(this.#o=!0)}if(b){const t=this.#r;let s=(0,k.traverseNode)(b,t);s=t.firstChild();let r=0;for(;s;)r++,s=t.nextSibling();const u=new Set;if(i)for(s=(0,k.traverseNode)(b,t),s=t.firstChild();s;){const{display:m,visibility:w}=this.#l.getComputedStyle(s);if(m!=="none"&&w!=="hidden"){let p;for(const N of i)if(p=this._matchLeaves(N,s,h),!p)break;p&&u.add(s)}s=t.nextSibling()}if(o===0){if(l>0&&l<=r){if(u.size){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(u.has(s)){if(m===l-1){d.add(s);break}m++}n?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(m===l-1){d.add(s);break}n?s=t.previousSibling():s=t.nextSibling(),m++}}}}else{let m=l-1;if(o>0)for(;m<0;)m+=o;if(m>=0&&m<r){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let w=0,p=o>0?0:l-1;for(;s&&(s&&m>=0&&m<r);)u.size?u.has(s)&&(p===m&&(d.add(s),m+=o),o>0?p++:p--):w===m&&(f||d.add(s),m+=o),n?s=t.previousSibling():s=t.nextSibling(),w++}}if(n&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&o+l===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(c,e){const{a:h,b:o,reverse:l}=c,{localName:n,parentNode:f,prefix:b}=e,d=new Set;if(f){const i=this.#r;let t=(0,k.traverseNode)(f,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(o>0&&o<=s){t=(0,k.traverseNode)(f,i),l?t=i.lastChild():t=i.firstChild();let r=0;for(;t;){const{localName:u,prefix:m}=t;if(u===n&&m===b){if(r===o-1){d.add(t);break}r++}l?t=i.previousSibling():t=i.nextSibling()}}}else{let r=o-1;if(h>0)for(;r<0;)r+=h;if(r>=0&&r<s){t=(0,k.traverseNode)(f,i),l?t=i.lastChild():t=i.firstChild();let u=h>0?0:o-1;for(;t;){const{localName:m,prefix:w}=t;if(m===n&&w===b){if(u===r&&(d.add(t),r+=h),r<0||r>=s)break;h>0?u++:u--}l?t=i.previousSibling():t=i.nextSibling()}}}if(l&&d.size>1){const r=[...d];return new Set(r.reverse())}}else e===this.#s&&h+o===1&&d.add(e);return d}_matchAnPlusB(c,e,h,o){const{nth:{a:l,b:n,name:f},selector:b}=c,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)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?d.set("a",l*1):d.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?d.set("b",n*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){b&&d.set("selector",b);const i=Object.fromEntries(d);return this._collectNthChild(i,e,o)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(c,e,h={}){let o;if(Array.isArray(c)&&c.length){const l=c.map(s=>s),[n]=l,{type:f}=n;let b;f===a.COMBINATOR?b=l.shift():b={name:" ",type:a.COMBINATOR};const d=[];for(;l.length;){const[s]=l,{type:r}=s;if(r===a.COMBINATOR)break;d.push(l.shift())}const i={combo:b,leaves:d};h.dir=v;const t=this._matchCombinator(i,e,h);if(t.size)if(l.length){for(const s of t)if(o=this._matchHasPseudoFunc(l,s,h),o)break}else o=!0}return!!o}_matchLogicalPseudoFunc(c,e,h={}){const{astName:o="",branches:l=[],selector:n="",twigBranches:f=[]}=c;let b;if(o==="has")if(n.includes(":has("))b=null;else{let d;for(const i of l)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(b=e)}else{const d=/^(?:is|where)$/.test(o);h.forgive=d;const i=f.length;let t;for(let s=0;s<i;s++){const r=f[s],u=r.length-1,{leaves:m}=r[u];if(t=this._matchLeaves(m,e,h),t&&u>0){let w=new Set([e]);for(let p=u-1;p>=0;p--){const N=r[p],_=[];h.dir=S;for(const y of w){const E=this._matchCombinator(N,y,h);E.size&&_.push(...E)}if(_.length)p===0?t=!0:w=new Set(_);else{t=!1;break}}}if(t)break}o==="not"?t||(b=e):t&&(b=e)}return b??null}_matchPseudoClassSelector(c,e,h={}){const{children:o,name:l}=c,{localName:n,parentNode:f}=e,{forgive:b,warn:d=this.#i}=h,i=new Set;if(a.REG_LOGICAL_PSEUDO.test(l)){let t;if(this.#n.has(c))t=this.#n.get(c);else{const{branches:r}=(0,g.walkAST)(c),u=[],m=[];for(const[...w]of r){for(const y of w){const E=(0,g.generateCSS)(y);u.push(E)}const p=[],N=new Set;let _=w.shift();for(;_;)if(_.type===a.COMBINATOR?(p.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),w.length)_=w.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}m.push(p)}t={astName:l,branches:r,twigBranches:m,selector:u.join(",")},this.#n.set(c,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(o))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const[t]=o;return this._matchAnPlusB(t,e,l,h)}else switch(l){case"dir":case"lang":{const t=L.matcher.matchSelector(c,e);t&&i.add(t);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:t}]=o;t&&e[t]&&i.add(e)}break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${l}()`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}default:if(!b){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,a.SYNTAX_ERR)}}else switch(l){case"any-link":case"link":{a.REG_ANCHOR.test(n)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(a.REG_ANCHOR.test(n)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:r}=new URL(this.#t.URL),u=new URL(e.getAttribute("href"),t);u.origin===s&&u.pathname===r&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#d??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:r}=this.#d??{};(r==="mousedown"||r==="pointerdown")&&t&a.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 r=this.#t.getElementById(s);for(;r;){if(r===e){i.add(e);break}r=r.parentNode}}break}case"scope":{this.#e.nodeType===a.ELEMENT_NODE?!this.#h&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#d??{};if(e===this.#t.activeElement&&e.tabIndex>=0&&(l==="focus"||s==="keydown"&&e.contains(t))){let r=e,u=!0;for(;r;){if(r.disabled||r.hasAttribute("disabled")||r.hidden||r.hasAttribute("hidden")){u=!1;break}else{const{display:m,visibility:w}=this.#l.getComputedStyle(r);if(u=!(m==="none"||w==="hidden"),!u)break}if(r.parentNode&&r.parentNode.nodeType===a.ELEMENT_NODE)r=r.parentNode;else break}u&&i.add(e)}break}case"focus-within":{let t,s=this.#t.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}if(t){let r=e,u=!0;for(;r;){if(r.disabled||r.hasAttribute("disabled")||r.hidden||r.hasAttribute("hidden")){u=!1;break}else{const{display:m,visibility:w}=this.#l.getComputedStyle(r);if(u=!(m==="none"||w==="hidden"),!u)break}if(r.parentNode&&r.parentNode.nodeType===a.ELEMENT_NODE)r=r.parentNode;else break}u&&i.add(e)}break}case"open":{a.REG_INTERACT.test(n)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{a.REG_INTERACT.test(n)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(a.REG_FORM_CTRL.test(n)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let t,s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const r=this.#r;let u=(0,k.traverseNode)(s,r);for(u=r.firstChild();u&&u.localName!=="legend";)u=r.nextSibling();u&&u.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===a.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t&&i.add(e)}}break}case"enabled":{if((a.REG_FORM_CTRL.test(n)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(f.localName!=="optgroup"||!(f.disabled||f.hasAttribute("disabled")))&&i.add(e);else{let t,s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const r=this.#r;let u=(0,k.traverseNode)(s,r);for(u=r.firstChild();u&&u.localName!=="legend";)u=r.nextSibling();u&&u.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===a.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t||i.add(e)}break}case"read-only":{switch(n){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||a.REG_TYPE_DATE.test(e.type)||a.REG_TYPE_TEXT.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(n){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||a.REG_TYPE_DATE.test(e.type)||a.REG_TYPE_TEXT.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;n==="textarea"?s=e:n==="input"&&(e.hasAttribute("type")?a.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&n==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&n==="input"&&e.type==="checkbox"||n==="progress"&&!e.hasAttribute("value"))i.add(e);else if(n==="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 r=s.getElementsByTagName("input"),u=r.length;let m;for(let w=0;w<u;w++){const p=r[w];if(p.getAttribute("type")==="radio"&&(t?p.getAttribute("name")===t&&(m=!!p.checked):p.hasAttribute("name")||(m=!!p.checked),m))break}m||i.add(e)}break}case"default":{if(n==="button"&&!(e.hasAttribute("type")&&a.REG_TYPE_RESET.test(e.getAttribute("type")))||n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#r;let r=(0,k.traverseNode)(t,s);for(r=s.firstChild();r&&t.contains(r);){const u=r.localName;let m;if(u==="button"?m=!(r.hasAttribute("type")&&a.REG_TYPE_RESET.test(r.getAttribute("type"))):u==="input"&&(m=r.hasAttribute("type")&&a.REG_TYPE_SUBMIT.test(r.getAttribute("type"))),m){r===e&&i.add(e);break}r=s.nextNode()}}}else(n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_CHECK.test(e.getAttribute("type"))&&e.hasAttribute("checked")||n==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(a.REG_FORM_VALID.test(n))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(n==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let r;if(!s)r=!0;else for(;s&&e.contains(s)&&!(a.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?r=s.maxLength>=s.value.length:r=!0:r=!1,!r));)s=t.nextNode();r&&i.add(e)}break}case"invalid":{if(a.REG_FORM_VALID.test(n))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(n==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let r;if(!s)r=!0;else for(;s&&e.contains(s)&&!(a.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?r=s.maxLength>=s.value.length:r=!0:r=!1,!r));)s=t.nextNode();r||i.add(e)}break}case"in-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&a.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&a.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(n))t=e;else if(n==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||a.REG_TYPE_CHECK.test(s)||a.REG_TYPE_DATE.test(s)||a.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(n))t=e;else if(n==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||a.REG_TYPE_CHECK.test(s)||a.REG_TYPE_DATE.test(s)||a.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#t.createTreeWalker(e,a.SHOW_ALL);let s=t.firstChild(),r;for(;s&&(r=s.nodeType!==a.ELEMENT_NODE&&s.nodeType!==a.TEXT_NODE,!!r);)s=t.nextSibling();r&&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")||n.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#l.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${l}`;throw new DOMException(t,a.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){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}}else if(!b){const t=`Unknown pseudo-class :${l}`;throw new DOMException(t,a.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(c,e){const{children:h,name:o}=c;let l;if(Array.isArray(h)){const{branches:n}=(0,g.walkAST)(h[0]),[f]=n,[...b]=f,{host:d}=e;if(o==="host"){let i;for(const t of b){const{type:s}=t;if(s===a.COMBINATOR){const u=`Invalid selector ${(0,g.generateCSS)(c)}`;throw new DOMException(u,a.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(l=e)}else if(o==="host-context"){let i=d,t;for(;i;){for(const s of b){const{type:r}=s;if(r===a.COMBINATOR){const m=`Invalid selector ${(0,g.generateCSS)(c)}`;throw new DOMException(m,a.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(l=e)}}else if(o==="host")l=e;else{const n=`Invalid selector :${o}`;throw new DOMException(n,a.SYNTAX_ERR)}return l??null}_matchSelector(c,e,h){const{type:o}=c,l=new Set;if(c.name===a.EMPTY)return l;const n=(0,g.unescapeSelector)(c.name);if(typeof n=="string"&&n!==c.name&&(c.name=n),e.nodeType===a.ELEMENT_NODE)switch(o){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(n,h);break}case a.SELECTOR_ID:{e.id===n&&l.add(e);break}case a.SELECTOR_CLASS:{e.classList.contains(n)&&l.add(e);break}case a.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(c,e,h);default:{const f=L.matcher.matchSelector(c,e,h);f&&l.add(f)}}else if(this.#h&&o===a.SELECTOR_PSEUDO_CLASS&&e.nodeType===a.DOCUMENT_FRAGMENT_NODE){if(n!=="has"&&a.REG_LOGICAL_PSEUDO.test(n))return this._matchPseudoClassSelector(c,e,h);if(a.REG_SHADOW_HOST.test(n)){const f=this._matchShadowHostPseudoClass(c,e,h);f&&l.add(f)}}return l}_matchLeaves(c,e,h){let o,l;if(this.#o?l=this.#b.get(c):l=this.#w.get(c),l&&l.has(e)){const{matched:n}=l.get(e);o=n}if(typeof o!="boolean"){let n=!0;e.nodeType===a.ELEMENT_NODE&&a.REG_FORM.test(e.localName)&&(n=!1);for(const f of c){switch(f.type){case a.SELECTOR_ATTR:case a.SELECTOR_ID:{n=!1;break}case a.SELECTOR_PSEUDO_CLASS:{/^(?:(?:any-)?link|defined|dir)$/.test(f.name)&&(n=!1);break}default:}if(o=this._matchSelector(f,e,h).has(e),!o)break}n&&(l||(l=new WeakMap),l.set(e,{matched:o}),this.#o?this.#b.set(c,l):this.#w.set(c,l))}return!!o}_matchHTMLCollection(c,e={}){const{compound:h,filterLeaves:o}=e,l=new Set,n=c.length;if(n)if(h)for(let f=0;f<n;f++){const b=c[f];this._matchLeaves(o,b,e)&&l.add(b)}else{const f=[].slice.call(c);return new Set(f)}return l}_findDescendantNodes(c,e,h){const[o,...l]=c,n=l.length>0,{type:f}=o,b=(0,g.unescapeSelector)(o.name);typeof b=="string"&&b!==o.name&&(o.name=b);let d=new Set,i=!1;if(this.#h)i=!0;else switch(f){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(b,h);break}case a.SELECTOR_ID:{if(this.#s.nodeType===a.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(b);t&&t!==e&&e.contains(t)&&(n?this._matchLeaves(l,t,h)&&d.add(t):d.add(t))}break}case a.SELECTOR_CLASS:{const t=e.getElementsByClassName(b);d=this._matchHTMLCollection(t,{compound:n,filterLeaves:l});break}case a.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(b)){const t=e.getElementsByTagName(b);d=this._matchHTMLCollection(t,{compound:n,filterLeaves:l})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(c,e,h={}){const{combo:o,leaves:l}=c,{name:n}=o,{parentNode:f}=e,{dir:b}=h,d=new Set;if(b===v)switch(n){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(l,i,h)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,k.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,k.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(l,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let r=(0,k.traverseNode)(e,s);for(r=s.nextNode();r&&e.contains(r);)this._matchLeaves(l,r,h)&&d.add(r),r=s.nextNode()}}}else switch(n){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(l,i,h)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,k.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(l,f,h)&&d.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(l,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(c,e){const{node:h}=e,o=this.#u;let l=(0,k.traverseNode)(h,o),n;if(l)for((l.nodeType!==a.ELEMENT_NODE||l===h&&l!==this.#s)&&(l=o.nextNode());l;){if(this._matchLeaves(c,l,{warn:this.#i})){n=l;break}l=o.nextNode()}return n??null}_matchSelf(c){const e=[],h=this._matchLeaves(c,this.#e,{warn:this.#i});let o=!1;return h&&(e.push(this.#e),o=!0),[e,o]}_findLineal(c,e={}){const{complex:h}=e,o=[];let l=this._matchLeaves(c,this.#e,{warn:this.#i}),n=!1;if(l&&(o.push(this.#e),n=!0),!l||h){let f=this.#e.parentNode;for(;f&&(l=this._matchLeaves(c,f,{warn:this.#i}),l&&(o.push(f),n=!0),f.parentNode);)f=f.parentNode}return[o,n]}_findFirst(c){const e=[],h=this._findNode(c,{node:this.#e});let o=!1;return h&&(e.push(h),o=!0),[e,o]}_findFromHTMLCollection(c,e={}){const{complex:h,compound:o,filterLeaves:l,targetType:n}=e;let f=[],b=!1,d=!1;const i=c.length;if(i)if(this.#e.nodeType===a.ELEMENT_NODE)for(let t=0;t<i;t++){const s=c[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(o){if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else if(f.push(s),b=!0,n===a.TARGET_FIRST)break}}else if(h)if(o)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else f=[].slice.call(c),b=!0,d=!0;else if(o)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else f=[].slice.call(c),b=!0,d=!0;return[f,b,d]}_findEntryNodes(c,e,h){const{leaves:o}=c,[l,...n]=o,f=n.length>0,{name:b,type:d}=l;let i=[],t=!1,s=!1,r=!1;switch(d){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(b,{warn:this.#i});break}case a.SELECTOR_ID:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(e===a.TARGET_FIRST&&this.#s.nodeType!==a.ELEMENT_NODE){const u=this.#s.getElementById(b);u&&(f?this._matchLeaves(n,u,{warn:this.#i})&&(i.push(u),s=!0):(i.push(u),s=!0))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}case a.SELECTOR_CLASS:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(this.#s.nodeType===a.DOCUMENT_NODE){const u=this.#s.getElementsByClassName(b);u.length&&([i,s,t]=this._findFromHTMLCollection(u,{complex:h,compound:f,filterLeaves:n,targetType:e}))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}case a.SELECTOR_TYPE:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===a.DOCUMENT_NODE&&!/[*|]/.test(b)){const u=this.#s.getElementsByTagName(b);u.length&&([i,s,t]=this._findFromHTMLCollection(u,{complex:h,compound:f,filterLeaves:n,targetType:e}))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}default:if(e!==a.TARGET_LINEAL&&a.REG_SHADOW_HOST.test(b)){if(this.#h&&this.#e.nodeType===a.DOCUMENT_FRAGMENT_NODE){const u=this._matchShadowHostPseudoClass(l,this.#e);u&&(i.push(u),s=!0)}}else e===a.TARGET_SELF?[i,s]=this._matchSelf(o):e===a.TARGET_LINEAL?[i,s]=this._findLineal(o,{complex:h}):e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:r}}_collectNodes(c){const e=this.#a.values();if(c===a.TARGET_ALL||c===a.TARGET_FIRST){const h=new Set;let o=0;for(const{branch:l}of e){const n=l.length,f=n>1,b=l[0];let d,i;if(f){const{combo:w,leaves:[{name:p,type:N}]}=b,_=l[n-1],{leaves:[{name:y,type:E}]}=_;if(E===a.SELECTOR_PSEUDO_ELEMENT||E===a.SELECTOR_ID)d=S,i=_;else if(N===a.SELECTOR_PSEUDO_ELEMENT||N===a.SELECTOR_ID)d=v,i=b;else if(c===a.TARGET_ALL)if(p==="*"&&N===a.SELECTOR_TYPE)d=S,i=_;else if(y==="*"&&E===a.SELECTOR_TYPE)d=v,i=b;else if(n===2){const{name:A}=w;/^[+~]$/.test(A)?(d=S,i=_):(d=v,i=b)}else d=v,i=b;else if(y==="*"&&E===a.SELECTOR_TYPE)d=v,i=b;else if(p==="*"&&N===a.SELECTOR_TYPE)d=S,i=_;else{let A;for(const{combo:C,leaves:[R]}of l){const{name:O,type:M}=R;if(M===a.SELECTOR_PSEUDO_CLASS&&O==="dir"){A=!1;break}if(!A&&C){const{name:P}=C;/^[+~]$/.test(P)&&(A=!0)}}A?(d=v,i=b):(d=S,i=_)}}else d=S,i=b;const{collected:t,compound:s,filtered:r,nodes:u,pending:m}=this._findEntryNodes(i,c,f);u.length?(this.#a[o].find=!0,this.#f[o]=u):m&&h.add(new Map([["index",o],["twig",i]])),this.#a[o].collected=t,this.#a[o].dir=d,this.#a[o].filtered=r||!s,o++}if(h.size){let l,n;this.#e!==this.#s&&this.#e.nodeType===a.ELEMENT_NODE?(l=this.#e,n=this.#u):(l=this.#s,n=this.#r);let f=(0,k.traverseNode)(l,n);for(;f;){let b=!1;if(this.#e.nodeType===a.ELEMENT_NODE?f===this.#e?b=!0:b=this.#e.contains(f):b=!0,b)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=d.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#f[s].push(f)}}f!==n.currentNode&&(f=(0,k.traverseNode)(f,n)),f=n.nextNode()}}}else{let h=0;for(const{branch:o}of e){const l=o[o.length-1],n=o.length>1,{compound:f,filtered:b,nodes:d}=this._findEntryNodes(l,c,n);d.length&&(this.#a[h].find=!0,this.#f[h]=d),this.#a[h].dir=S,this.#a[h].filtered=b||!f,h++}}return[this.#a,this.#f]}_getCombinedNodes(c,e,h){const o=[];for(const l of e){const n=this._matchCombinator(c,l,{dir:h,warn:this.#i});n.size&&o.push(...n)}return o.length?new Set(o):new Set}_matchNodeNext(c,e,h){const{combo:o,index:l}=h,{combo:n,leaves:f}=c[l],b={combo:o,leaves:f},d=this._getCombinedNodes(b,e,v);let i;if(d.size)if(l===c.length-1){const[t]=(0,k.sortNodes)(d);i=t}else i=this._matchNodeNext(c,d,{combo:n,index:l+1});return i??null}_matchNodePrev(c,e,h){const{index:o}=h,l=c[o],n=new Set([e]),f=this._getCombinedNodes(l,n,S);let b;if(f.size){if(o===0)b=e;else for(const d of f)if(this._matchNodePrev(c,d,{index:o-1}))return e}return b??null}_find(c){(c===a.TARGET_ALL||c===a.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(c),o=e.length;let l,n=new Set;for(let f=0;f<o;f++){const{branch:b,collected:d,dir:i,find:t}=e[f],s=b.length;if(s&&t){const r=h[f],u=r.length,m=s-1;if(m===0)if((c===a.TARGET_ALL||c===a.TARGET_FIRST)&&this.#e.nodeType===a.ELEMENT_NODE)for(let w=0;w<u;w++){const p=r[w];if(p!==this.#e&&this.#e.contains(p)&&(n.add(p),c!==a.TARGET_ALL))break}else if(c===a.TARGET_ALL)if(n.size){const w=[...n];n=new Set([...w,...r]),l=!0}else n=new Set(r);else{const[w]=r;n.add(w)}else if(c===a.TARGET_ALL)if(i===v){let{combo:w}=b[0];for(const p of r){let N=new Set([p]);for(let _=1;_<s;_++){const{combo:y,leaves:E}=b[_],A={combo:w,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(n.size){const C=[...n];n=new Set([...C,...N]),l=!0}else n=N;else w=y;else break}}}else for(const w of r){let p=new Set([w]);for(let N=m-1;N>=0;N--){const _=b[N];if(p=this._getCombinedNodes(_,p,i),p.size)N===0&&(n.add(w),s>1&&n.size>1&&(l=!0));else break}}else if(c===a.TARGET_FIRST&&i===v){const{combo:w}=b[0];let p;for(const N of r)if(p=this._matchNodeNext(b,new Set([N]),{combo:w,index:1}),p){n.add(p);break}if(!p&&!d){const{leaves:N}=b[0],[_]=r;let y=this._findNode(N,{node:_});for(;y;){if(p=this._matchNodeNext(b,new Set([y]),{combo:w,index:1}),p){n.add(p);break}y=this._findNode(N,{node:y})}}}else{let w;for(const p of r)if(w=this._matchNodePrev(b,p,{index:m-1}),w){n.add(p);break}if(!w&&!d&&c===a.TARGET_FIRST){const{leaves:p}=b[m],[N]=r;let _=this._findNode(p,{node:N});for(;_;){if(w=this._matchNodePrev(b,_,{index:m-1}),w){n.add(_);break}_=this._findNode(p,{node:_})}}}}}return c===a.TARGET_ALL&&l&&(n=new Set((0,k.sortNodes)(n))),n}}0&&(module.exports={Finder});
2
2
  //# sourceMappingURL=finder.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/finder.js"],
4
- "sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport {\n isContentEditable, isCustomElement, isInShadowTree, resolveContent,\n sortNodes, traverseNode\n} from './dom-util.js';\nimport { matcher } from './matcher.js';\nimport {\n generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n BIT_01, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE,\n EMPTY, NOT_SUPPORTED_ERR, REG_ANCHOR, REG_FORM, REG_FORM_CTRL,\n REG_FORM_VALID, REG_INTERACT, REG_LOGICAL_PSEUDO, REG_SHADOW_HOST,\n REG_TYPE_CHECK, REG_TYPE_DATE, REG_TYPE_RANGE, REG_TYPE_RESET,\n REG_TYPE_SUBMIT, REG_TYPE_TEXT, SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID,\n SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE, SHOW_ALL,\n SYNTAX_ERR, TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF, TEXT_NODE,\n 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<Ast | undefined>\n * #nodes: Array<Nodes>\n * Ast: {\n * branch: Array<Branch | undefined>,\n * collected: boolean,\n * dir: string | null,\n * filtered: boolean,\n * find: boolean\n * }\n * Branch: Array<Twig>\n * Twig: {\n * combo: Leaf | null,\n * leaves: Array<Leaf>\n * }\n * Leaf: {\n * children: Array<Leaf | undefined> | null,\n * loc: null,\n * type: string\n * }\n * Nodes: Array<HTMLElement | undefined>\n */\nexport class Finder {\n /* private fields */\n #ast;\n #astCache;\n #descendant;\n #document;\n #documentCache;\n #event;\n #invalidate;\n #invalidateResults;\n #node;\n #nodes;\n #noexcept;\n #qswalker;\n #results;\n #root;\n #shadow;\n #walker;\n #walkers;\n #warn;\n #window;\n\n /**\n * construct\n * @param {object} window - window\n */\n constructor(window) {\n this.#window = window;\n this.#astCache = new WeakMap();\n this.#documentCache = new WeakMap();\n this.#invalidateResults = new WeakMap();\n this.#results = new WeakMap();\n }\n\n /**\n * handle error\n * @private\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (!this.#noexcept) {\n if (e instanceof DOMException ||\n e instanceof this.#window.DOMException) {\n if (e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw new this.#window.DOMException(e.message, e.name);\n }\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @private\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {object} [opt.event] - MouseEvent, KeyboardEvent\n * @param {boolean} [opt.noexcept] - no exception\n * @param {boolean} [opt.warn] - console warn\n * @returns {object} - node\n */\n _setup(selector, node, opt = {}) {\n const { event, noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#event = this._setEvent(event);\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 return node;\n }\n\n /**\n * set event\n * @private\n * @param {object} event - instance of KeyboardEvent, MouseEvent\n * @returns {object} - result\n */\n _setEvent(event) {\n // NOTE: PointerEvent not implemented in jsdom\n return (event instanceof this.#window.KeyboardEvent ||\n event instanceof this.#window.MouseEvent)\n ? event\n : null;\n }\n\n /**\n * correspond ast and nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _correspond(selector) {\n const nodes = [];\n this.#descendant = false;\n this.#invalidate = false;\n let ast;\n if (this.#documentCache.has(this.#document)) {\n const cachedItem = this.#documentCache.get(this.#document);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n const item = cachedItem.get(`${selector}`);\n ast = item.ast;\n this.#descendant = item.descendant;\n this.#invalidate = item.invalidate;\n }\n }\n if (ast) {\n const l = ast.length;\n for (let i = 0; i < l; i++) {\n ast[i].collected = false;\n ast[i].dir = null;\n ast[i].filtered = false;\n ast[i].find = false;\n nodes[i] = [];\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n this._onError(e);\n }\n const { branches, info: { hasHasPseudoFunc } } = walkAST(cssAst);\n const invalidate = !!hasHasPseudoFunc;\n let descendant = false;\n let i = 0;\n ast = [];\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid selector ${selector}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const itemName = item.name;\n if (/^[\\s>]$/.test(itemName)) {\n descendant = true;\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (item) {\n let { name: itemName } = item;\n if (itemName && typeof itemName === 'string') {\n itemName = unescapeSelector(itemName);\n if (typeof itemName === 'string' && itemName !== item.name) {\n item.name = itemName;\n }\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n }\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n collected: false,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = [];\n i++;\n }\n let cachedItem;\n if (this.#documentCache.has(this.#document)) {\n cachedItem = this.#documentCache.get(this.#document);\n } else {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, {\n ast,\n descendant,\n invalidate\n });\n this.#documentCache.set(this.#document, cachedItem);\n this.#descendant = descendant;\n this.#invalidate = invalidate;\n }\n return [\n ast,\n nodes\n ];\n }\n\n /**\n * create tree walker\n * @private\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - tree walker\n */\n _createTreeWalker(node) {\n let walker;\n if (this.#walkers.has(node)) {\n walker = this.#walkers.get(node);\n } else {\n walker = this.#document.createTreeWalker(node, WALKER_FILTER);\n this.#walkers.set(node, walker);\n }\n return walker;\n }\n\n /**\n * prepare querySelector walker\n * @private\n * @returns {object} - tree walker\n */\n _prepareQuerySelectorWalker() {\n this.#qswalker = this._createTreeWalker(this.#node);\n return this.#qswalker;\n }\n\n /**\n * collect nth child\n * @private\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node, opt) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#astCache.has(selector)) {\n selectorBranches = this.#astCache.get(selector);\n } else {\n const { branches, info } = walkAST(selector);\n selectorBranches = branches;\n this.#astCache.set(selector, selectorBranches);\n if (info.hasLogicalPseudoFunc) {\n this.#invalidate = true;\n }\n }\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 const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n if (display !== 'none' && visibility !== 'hidden') {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, refNode, opt);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n }\n // :first-child, :last-child, :nth-child(b of S), :nth-last-child(b of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (selectorNodes.has(refNode)) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n i++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n } else if (!selector) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n }\n }\n }\n // :nth-child()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n if (refNode && nth >= 0 && nth < l) {\n if (selectorNodes.size) {\n if (selectorNodes.has(refNode)) {\n if (j === nth) {\n matched.add(refNode);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(refNode);\n }\n nth += a;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n } else {\n break;\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @private\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, 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 { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(refNode);\n break;\n }\n j++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n refNode = 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 { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(refNode);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @param {object} opt - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName, opt) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const anbMap = new Map();\n if (nthIdentName) {\n if (nthIdentName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (nthIdentName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node, opt);\n return nodes;\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n return nodes;\n }\n return new Set();\n }\n\n /**\n * match :has() pseudo-class function\n * @private\n * @param {Array.<object>} astLeaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(astLeaves, node, opt = {}) {\n let bool;\n if (Array.isArray(astLeaves) && astLeaves.length) {\n const leaves = astLeaves.map(i => i);\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n opt.dir = DIR_NEXT;\n const nodes = this._matchCombinator(twig, node, opt);\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool = this._matchHasPseudoFunc(leaves, nextNode, opt);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @private\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node, opt = {}) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n let bool;\n for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n opt.forgive = forgive;\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, opt);\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n opt.dir = DIR_PREV;\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, opt);\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @private\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive unknown pseudo-class\n * @param {boolean} [opt.warn] - warn unsupported pseudo-class\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren, name: astName } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = opt;\n const matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#astCache.has(ast)) {\n astData = this.#astCache.get(ast);\n } else {\n const { branches } = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#astCache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node, opt);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const [branch] = astChildren;\n const nodes = this._matchAnPlusB(branch, node, astName, opt);\n return nodes;\n } else {\n switch (astName) {\n // :dir(), :lang()\n case 'dir':\n case 'lang': {\n const res = matcher.matchSelector(ast, node);\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 && node[stateValue]) {\n matched.add(node);\n }\n }\n break;\n }\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // dropped from CSS Selectors 3\n case 'contains': {\n if (warn) {\n const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const { href, origin, pathname } = new URL(this.#document.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'hover': {\n const { target, type } = this.#event ?? {};\n if ((type === 'mouseover' || type === 'pointerover') &&\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' || type === 'pointerdown') &&\n buttons & BIT_01 && 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 case 'focus-visible': {\n const { target, type } = this.#event ?? {};\n if (node === this.#document.activeElement && node.tabIndex >= 0 &&\n (astName === 'focus' ||\n (type === 'keydown' && node.contains(target)))) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else {\n const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let active;\n let current = this.#document.activeElement;\n if (current.tabIndex >= 0) {\n while (current) {\n if (current === node) {\n active = true;\n break;\n }\n current = current.parentNode;\n }\n }\n if (active) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else {\n const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'open': {\n if (REG_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (REG_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (REG_FORM_CTRL.test(localName) ||\n isCustomElement(node, { formAssociated: true })) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else if (node.localName === 'option') {\n if (parentNode.localName === 'optgroup' &&\n (parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n matched.add(node);\n }\n } else if (node.localName !== 'optgroup') {\n let bool;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n const walker = this.#walker;\n let refNode = traverseNode(parent, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.localName === 'legend') {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (refNode) {\n if (!refNode.contains(node)) {\n bool = true;\n }\n } else {\n bool = true;\n }\n break;\n } else if (parent.localName === 'form') {\n break;\n } else if (parent.parentNode?.nodeType === ELEMENT_NODE) {\n if (parent.parentNode.localName === 'form') {\n break;\n } else {\n parent = parent.parentNode;\n }\n } else {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((REG_FORM_CTRL.test(localName) ||\n isCustomElement(node, { formAssociated: true })) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n if (node.localName === 'optgroup') {\n matched.add(node);\n } else if (node.localName === 'option') {\n if (parentNode.localName !== 'optgroup' ||\n !(parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n matched.add(node);\n }\n } else {\n let bool;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n const walker = this.#walker;\n let refNode = traverseNode(parent, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.localName === 'legend') {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (refNode) {\n if (!refNode.contains(node)) {\n bool = true;\n }\n } else {\n bool = true;\n }\n break;\n } else if (parent.localName === 'form') {\n break;\n } else if (parent.parentNode?.nodeType === ELEMENT_NODE) {\n if (parent.parentNode.localName === 'form') {\n break;\n } else {\n parent = parent.parentNode;\n }\n } else {\n break;\n }\n }\n if (!bool) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || REG_TYPE_DATE.test(node.type) ||\n REG_TYPE_TEXT.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || REG_TYPE_DATE.test(node.type) ||\n REG_TYPE_TEXT.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let placeholder;\n if (node.placeholder) {\n placeholder = node.placeholder;\n } else if (node.hasAttribute('placeholder')) {\n placeholder = node.getAttribute('placeholder');\n }\n if (typeof placeholder === 'string' && !/[\\r\\n]/.test(placeholder)) {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (REG_TYPE_TEXT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '') {\n matched.add(node);\n }\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n REG_TYPE_CHECK.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = this.#document.documentElement;\n }\n const items = parent.getElementsByTagName('input');\n const l = items.length;\n let checked;\n for (let i = 0; i < l; i++) {\n const item = items[i];\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n REG_TYPE_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_SUBMIT.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const walker = this.#walker;\n let nextNode = traverseNode(form, walker);\n nextNode = walker.firstChild();\n while (nextNode && form.contains(nextNode)) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n REG_TYPE_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n REG_TYPE_SUBMIT.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = walker.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_CHECK.test(node.getAttribute('type')) &&\n node.hasAttribute('checked')) {\n matched.add(node);\n // option\n } else if (localName === 'option' && node.hasAttribute('selected')) {\n matched.add(node);\n }\n break;\n }\n case 'valid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0) {\n if (node.maxLength >= node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0 && node.maxLength < node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n REG_TYPE_RANGE.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n REG_TYPE_RANGE.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_TYPE_DATE.test(inputType) ||\n REG_TYPE_TEXT.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_TYPE_DATE.test(inputType) ||\n REG_TYPE_TEXT.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === this.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n let bool;\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'defined': {\n if (node.hasAttribute('is') || localName.includes('-')) {\n if (isCustomElement(node)) {\n matched.add(node);\n }\n // NOTE: MathMLElement not implemented in jsdom\n } else if (node instanceof this.#window.HTMLElement ||\n node instanceof this.#window.SVGElement) {\n matched.add(node);\n }\n break;\n }\n case 'popover-open': {\n if (node.popover) {\n const { display } = this.#window.getComputedStyle(node);\n if (display !== 'none') {\n matched.add(node);\n }\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n // 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 const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match shadow host pseudo class\n * @private\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren, name: astName } = ast;\n let res;\n if (Array.isArray(astChildren)) {\n const { 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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n const msg = `Invalid selector :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const matched = new Set();\n if (ast.name === EMPTY) {\n return matched;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n }\n default: {\n const res = matcher.matchSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n let result;\n if (this.#invalidate) {\n result = this.#invalidateResults.get(leaves);\n } else {\n result = this.#results.get(leaves);\n }\n if (result && result.has(node)) {\n const { matched } = result.get(node);\n bool = matched;\n }\n if (typeof bool !== 'boolean') {\n let cacheable = true;\n if (node.nodeType === ELEMENT_NODE && REG_FORM.test(node.localName)) {\n cacheable = false;\n }\n for (const leaf of leaves) {\n switch (leaf.type) {\n case SELECTOR_ATTR:\n case SELECTOR_ID: {\n cacheable = false;\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n if (/^(?:(?:any-)?link|defined)$/.test(leaf.name)) {\n cacheable = false;\n }\n break;\n }\n default:\n }\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n if (cacheable) {\n if (!result) {\n result = new WeakMap();\n }\n result.set(node, {\n matched: bool\n });\n if (this.#invalidate) {\n this.#invalidateResults.set(leaves, result);\n } else {\n this.#results.set(leaves, result);\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @returns {Set.<object>} - matched nodes\n */\n _matchHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n const nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n return new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (typeof leafName === 'string' && leafName !== leaf.name) {\n leaf.name = leafName;\n }\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (this.#root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = this.#root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, opt);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#document.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const items = baseNode.getElementsByTagName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @private\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} opt - option\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { parentNode } = node;\n const { dir } = opt;\n const matched = new Set();\n if (dir === DIR_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = traverseNode(node, walker);\n refNode = walker.nextSibling();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n const walker = this._createTreeWalker(node);\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n return nodes;\n }\n if (pending) {\n const walker = this._createTreeWalker(node);\n let refNode = traverseNode(node, walker);\n refNode = walker.nextNode();\n while (refNode && node.contains(refNode)) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode === node) {\n break;\n } else {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n if (parentNode) {\n const bool = this._matchLeaves(leaves, parentNode, opt);\n if (bool) {\n matched.add(parentNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n return new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find matched node from #qswalker\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} [opt] - options\n * @param {object} [opt.node] - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, opt) {\n const { node } = opt;\n const walker = this.#qswalker;\n let refNode = traverseNode(node, walker);\n let matchedNode;\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = walker.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = walker.nextNode();\n }\n }\n while (refNode) {\n const matched = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (matched) {\n matchedNode = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * match self\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _matchSelf(leaves) {\n const nodes = [];\n const bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find lineal\n * @private\n * @param {Array} leaves - AST leaves\n * @param {object} opt - options\n * @returns {Array} - [nodes, filtered]\n */\n _findLineal(leaves, opt = {}) {\n const { complex } = opt;\n const nodes = [];\n let bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n if (!bool || complex) {\n let refNode = this.#node.parentNode;\n while (refNode) {\n bool = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(refNode);\n filtered = true;\n }\n if (refNode.parentNode) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find first\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFirst(leaves) {\n const nodes = [];\n const node = this._findNode(leaves, {\n node: this.#node\n });\n let filtered = false;\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find from HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @param {boolean} [opt.compound] - compound selector\n * @param {Array} [opt.filterLeaves] - filter leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFromHTMLCollection(items, opt = {}) {\n const { complex, compound, filterLeaves, targetType } = opt;\n let nodes = [];\n let filtered = false;\n let collected = false;\n const l = items.length;\n if (l) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n if (node !== this.#node &&\n (this.#node.contains(node) || node.contains(this.#node))) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n } else {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (complex) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n } else if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n }\n return [nodes, filtered, collected];\n }\n\n /**\n * find entry nodes\n * @private\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @param {boolean} complex - complex selector\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType, complex) {\n const { leaves } = twig;\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { name: leafName, type: leafType } = leaf;\n let nodes = [];\n let collected = false;\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const items = this.#root.getElementsByClassName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#document.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT ||\n lastType === SELECTOR_ID) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (branchLen === 2) {\n const { name: comboName } = firstCombo;\n if (/^[+~]$/.test(comboName)) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n let bool;\n for (const { combo, leaves: [leaf] } of branch) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n bool = false;\n break;\n }\n if (!bool && combo) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n const {\n collected, compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].collected = collected;\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#qswalker;\n } else {\n node = this.#root;\n walker = this.#walker;\n }\n let nextNode = traverseNode(node, walker);\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (nextNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(nextNode);\n }\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode, {\n warn: this.#warn\n });\n if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].push(nextNode);\n }\n }\n }\n if (nextNode !== walker.currentNode) {\n nextNode = traverseNode(nextNode, walker);\n }\n nextNode = walker.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const complex = branch.length > 1;\n const {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n }\n this.#ast[i].dir = DIR_PREV;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * get combined nodes\n * @private\n * @param {object} twig - twig\n * @param {object} nodes - collection of nodes\n * @param {string} dir - direction\n * @returns {Array.<object>} - collection of matched nodes\n */\n _getCombinedNodes(twig, nodes, dir) {\n const arr = [];\n for (const node of nodes) {\n const matched = this._matchCombinator(twig, node, {\n dir,\n warn: this.#warn\n });\n if (matched.size) {\n arr.push(...matched);\n }\n }\n if (arr.length) {\n return new Set(arr);\n }\n return new Set();\n }\n\n /**\n * match node to next direction\n * @private\n * @param {Array} branch - branch\n * @param {Set.<object>} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], collectedNodes] = this._collectNodes(targetType);\n const l = branches.length;\n let sort;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, collected, dir, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = collectedNodes[i];\n const entryNodesLen = entryNodes.length;\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n if (node !== this.#node && this.#node.contains(node)) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...entryNodes]);\n sort = true;\n } else {\n nodes = new Set(entryNodes);\n }\n } else {\n const [node] = entryNodes;\n nodes.add(node);\n }\n } else if (targetType === TARGET_ALL) {\n if (dir === DIR_NEXT) {\n let { combo } = branch[0];\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const twig = {\n combo,\n leaves\n };\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === lastIndex) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...nextNodes]);\n sort = true;\n } else {\n nodes = nextNodes;\n }\n } else {\n combo = nextCombo;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === 0) {\n nodes.add(node);\n if (branchLen > 1 && nodes.size > 1) {\n sort = true;\n }\n }\n } else {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST && dir === DIR_NEXT) {\n const { combo: entryCombo } = branch[0];\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodeNext(branch, new Set([node]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n nodes.add(matched);\n break;\n }\n }\n if (!matched && !collected) {\n const { leaves: entryLeaves } = branch[0];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodeNext(branch, new Set([refNode]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n nodes.add(matched);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n } else {\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodePrev(branch, node, {\n index: lastIndex - 1\n });\n if (matched) {\n nodes.add(node);\n break;\n }\n }\n if (!matched && !collected && targetType === TARGET_FIRST) {\n const { leaves: entryLeaves } = branch[lastIndex];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodePrev(branch, refNode, {\n index: lastIndex - 1\n });\n if (matched) {\n nodes.add(refNode);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n }\n }\n }\n if (targetType === TARGET_ALL && sort) {\n nodes = new Set(sortNodes(nodes));\n }\n return nodes;\n }\n};\n"],
5
- "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAGO,yBACPC,EAAwB,wBACxBC,EAEO,uBAGPC,EASO,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,GAMA,YAAYC,EAAQ,CAClB,KAAKD,GAAUC,EACf,KAAKlB,GAAY,IAAI,QACrB,KAAKG,GAAiB,IAAI,QAC1B,KAAKG,GAAqB,IAAI,QAC9B,KAAKK,GAAW,IAAI,OACtB,CASA,SAASQ,EAAG,CACV,GAAI,CAAC,KAAKV,GACR,GAAIU,aAAa,cACbA,aAAa,KAAKF,GAAQ,aAC5B,GAAIE,EAAE,OAAS,oBACT,KAAKH,IACP,QAAQ,KAAKG,EAAE,OAAO,MAGxB,OAAM,IAAI,KAAKF,GAAQ,aAAaE,EAAE,QAASA,EAAE,IAAI,MAGvD,OAAMA,CAGZ,CAaA,OAAOC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CAC/B,KAAM,CAAE,MAAAC,EAAO,SAAAC,EAAU,KAAAC,CAAK,EAAIH,EAClC,YAAKb,GAAY,CAAC,CAACe,EACnB,KAAKR,GAAQ,CAAC,CAACS,EACf,KAAKrB,GAAS,KAAK,UAAUmB,CAAK,EAClC,KAAKhB,GAAQc,EACb,CAAC,KAAKnB,GAAW,KAAKU,GAA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B,CAAY,EAAI1G,EAAO,CAAC,EAClC,CAAC2G,CAAS,EAAIL,EACpB,IAAIxF,EAAU,KAAK,UAAU4F,EAAa,CACxC,KAAMC,CACR,CAAC,EACD,KAAO7F,GAAS,CAKd,GAJAH,EAAU,KAAK,eAAeX,EAAQ,IAAI,IAAI,CAACc,CAAO,CAAC,EAAG,CACxD,MAAO2F,EACP,MAAO,CACT,CAAC,EACG9F,EAAS,CACXvB,EAAM,IAAIuB,CAAO,EACjB,KACF,CACAG,EAAU,KAAK,UAAU4F,EAAa,CACpC,KAAM5F,CACR,CAAC,CACH,CACF,CACF,KAAO,CACL,IAAIH,EACJ,UAAW5B,KAAQuH,EAIjB,GAHA3F,EAAU,KAAK,eAAeX,EAAQjB,EAAM,CAC1C,MAAO2D,EAAY,CACrB,CAAC,EACG/B,EAAS,CACXvB,EAAM,IAAIL,CAAI,EACd,KACF,CAEF,GAAI,CAAC4B,GAAW,CAAC2E,GAAaD,IAAe,eAAc,CACzD,KAAM,CAAE,OAAQqB,CAAY,EAAI1G,EAAO0C,CAAS,EAC1C,CAACiE,CAAS,EAAIL,EACpB,IAAIxF,EAAU,KAAK,UAAU4F,EAAa,CACxC,KAAMC,CACR,CAAC,EACD,KAAO7F,GAAS,CAId,GAHAH,EAAU,KAAK,eAAeX,EAAQc,EAAS,CAC7C,MAAO4B,EAAY,CACrB,CAAC,EACG/B,EAAS,CACXvB,EAAM,IAAI0B,CAAO,EACjB,KACF,CACAA,EAAU,KAAK,UAAU4F,EAAa,CACpC,KAAM5F,CACR,CAAC,CACH,CACF,CACF,CACF,CACF,CACA,OAAIuE,IAAe,cAAce,IAC/BhH,EAAQ,IAAI,OAAI,aAAUA,CAAK,CAAC,GAE3BA,CACT,CACF",
4
+ "sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport {\n isContentEditable, isCustomElement, isInShadowTree, resolveContent,\n sortNodes, traverseNode\n} from './dom-util.js';\nimport { matcher } from './matcher.js';\nimport {\n generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n BIT_01, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE,\n EMPTY, NOT_SUPPORTED_ERR, REG_ANCHOR, REG_FORM, REG_FORM_CTRL,\n REG_FORM_VALID, REG_INTERACT, REG_LOGICAL_PSEUDO, REG_SHADOW_HOST,\n REG_TYPE_CHECK, REG_TYPE_DATE, REG_TYPE_RANGE, REG_TYPE_RESET,\n REG_TYPE_SUBMIT, REG_TYPE_TEXT, SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID,\n SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE, SHOW_ALL,\n SYNTAX_ERR, TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF, TEXT_NODE,\n 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<Ast | undefined>\n * #nodes: Array<Nodes>\n * Ast: {\n * branch: Array<Branch | undefined>,\n * collected: boolean,\n * dir: string | null,\n * filtered: boolean,\n * find: boolean\n * }\n * Branch: Array<Twig>\n * Twig: {\n * combo: Leaf | null,\n * leaves: Array<Leaf>\n * }\n * Leaf: {\n * children: Array<Leaf | undefined> | null,\n * loc: null,\n * type: string\n * }\n * Nodes: Array<HTMLElement | undefined>\n */\nexport class Finder {\n /* private fields */\n #ast;\n #astCache;\n #descendant;\n #document;\n #documentCache;\n #event;\n #invalidate;\n #invalidateResults;\n #node;\n #nodes;\n #noexcept;\n #qswalker;\n #results;\n #root;\n #shadow;\n #walker;\n #walkers;\n #warn;\n #window;\n\n /**\n * construct\n * @param {object} window - window\n */\n constructor(window) {\n this.#window = window;\n this.#astCache = new WeakMap();\n this.#documentCache = new WeakMap();\n this.#invalidateResults = new WeakMap();\n this.#results = new WeakMap();\n }\n\n /**\n * handle error\n * @private\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (!this.#noexcept) {\n if (e instanceof DOMException ||\n e instanceof this.#window.DOMException) {\n if (e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw new this.#window.DOMException(e.message, e.name);\n }\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @private\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {object} [opt.event] - MouseEvent, KeyboardEvent\n * @param {boolean} [opt.noexcept] - no exception\n * @param {boolean} [opt.warn] - console warn\n * @returns {object} - node\n */\n _setup(selector, node, opt = {}) {\n const { event, noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#event = this._setEvent(event);\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 return node;\n }\n\n /**\n * set event\n * @private\n * @param {object} event - instance of KeyboardEvent, MouseEvent\n * @returns {object} - result\n */\n _setEvent(event) {\n // NOTE: PointerEvent not implemented in jsdom\n return (event instanceof this.#window.KeyboardEvent ||\n event instanceof this.#window.MouseEvent)\n ? event\n : null;\n }\n\n /**\n * correspond ast and nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _correspond(selector) {\n const nodes = [];\n this.#descendant = false;\n this.#invalidate = false;\n let ast;\n if (this.#documentCache.has(this.#document)) {\n const cachedItem = this.#documentCache.get(this.#document);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n const item = cachedItem.get(`${selector}`);\n ast = item.ast;\n this.#descendant = item.descendant;\n this.#invalidate = item.invalidate;\n }\n }\n if (ast) {\n const l = ast.length;\n for (let i = 0; i < l; i++) {\n ast[i].collected = false;\n ast[i].dir = null;\n ast[i].filtered = false;\n ast[i].find = false;\n nodes[i] = [];\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n this._onError(e);\n }\n const { branches, info: { hasHasPseudoFunc } } = walkAST(cssAst);\n const invalidate = !!hasHasPseudoFunc;\n let descendant = false;\n let i = 0;\n ast = [];\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid selector ${selector}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const itemName = item.name;\n if (/^[\\s>]$/.test(itemName)) {\n descendant = true;\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (item) {\n let { name: itemName } = item;\n if (itemName && typeof itemName === 'string') {\n itemName = unescapeSelector(itemName);\n if (typeof itemName === 'string' && itemName !== item.name) {\n item.name = itemName;\n }\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n }\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n collected: false,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = [];\n i++;\n }\n let cachedItem;\n if (this.#documentCache.has(this.#document)) {\n cachedItem = this.#documentCache.get(this.#document);\n } else {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, {\n ast,\n descendant,\n invalidate\n });\n this.#documentCache.set(this.#document, cachedItem);\n this.#descendant = descendant;\n this.#invalidate = invalidate;\n }\n return [\n ast,\n nodes\n ];\n }\n\n /**\n * create tree walker\n * @private\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - tree walker\n */\n _createTreeWalker(node) {\n let walker;\n if (this.#walkers.has(node)) {\n walker = this.#walkers.get(node);\n } else {\n walker = this.#document.createTreeWalker(node, WALKER_FILTER);\n this.#walkers.set(node, walker);\n }\n return walker;\n }\n\n /**\n * prepare querySelector walker\n * @private\n * @returns {object} - tree walker\n */\n _prepareQuerySelectorWalker() {\n this.#qswalker = this._createTreeWalker(this.#node);\n return this.#qswalker;\n }\n\n /**\n * collect nth child\n * @private\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node, opt) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#astCache.has(selector)) {\n selectorBranches = this.#astCache.get(selector);\n } else {\n const { branches, info } = walkAST(selector);\n selectorBranches = branches;\n this.#astCache.set(selector, selectorBranches);\n if (info.hasLogicalPseudoFunc) {\n this.#invalidate = true;\n }\n }\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 const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n if (display !== 'none' && visibility !== 'hidden') {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, refNode, opt);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n }\n // :first-child, :last-child, :nth-child(b of S), :nth-last-child(b of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (selectorNodes.has(refNode)) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n i++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n } else if (!selector) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n }\n }\n }\n // :nth-child()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n if (refNode && nth >= 0 && nth < l) {\n if (selectorNodes.size) {\n if (selectorNodes.has(refNode)) {\n if (j === nth) {\n matched.add(refNode);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(refNode);\n }\n nth += a;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n } else {\n break;\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @private\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, 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 { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(refNode);\n break;\n }\n j++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n refNode = 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 { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(refNode);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @param {object} opt - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName, opt) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const anbMap = new Map();\n if (nthIdentName) {\n if (nthIdentName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (nthIdentName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node, opt);\n return nodes;\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n return nodes;\n }\n return new Set();\n }\n\n /**\n * match :has() pseudo-class function\n * @private\n * @param {Array.<object>} astLeaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(astLeaves, node, opt = {}) {\n let bool;\n if (Array.isArray(astLeaves) && astLeaves.length) {\n const leaves = astLeaves.map(i => i);\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n opt.dir = DIR_NEXT;\n const nodes = this._matchCombinator(twig, node, opt);\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool = this._matchHasPseudoFunc(leaves, nextNode, opt);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @private\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node, opt = {}) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n let bool;\n for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n opt.forgive = forgive;\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, opt);\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n opt.dir = DIR_PREV;\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, opt);\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @private\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive unknown pseudo-class\n * @param {boolean} [opt.warn] - warn unsupported pseudo-class\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren, name: astName } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = opt;\n const matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#astCache.has(ast)) {\n astData = this.#astCache.get(ast);\n } else {\n const { branches } = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#astCache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node, opt);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const [branch] = astChildren;\n const nodes = this._matchAnPlusB(branch, node, astName, opt);\n return nodes;\n } else {\n switch (astName) {\n // :dir(), :lang()\n case 'dir':\n case 'lang': {\n const res = matcher.matchSelector(ast, node);\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 && node[stateValue]) {\n matched.add(node);\n }\n }\n break;\n }\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // dropped from CSS Selectors 3\n case 'contains': {\n if (warn) {\n const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const { href, origin, pathname } = new URL(this.#document.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'hover': {\n const { target, type } = this.#event ?? {};\n if ((type === 'mouseover' || type === 'pointerover') &&\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' || type === 'pointerdown') &&\n buttons & BIT_01 && 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 case 'focus-visible': {\n const { target, type } = this.#event ?? {};\n if (node === this.#document.activeElement && node.tabIndex >= 0 &&\n (astName === 'focus' ||\n (type === 'keydown' && node.contains(target)))) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else {\n const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let active;\n let current = this.#document.activeElement;\n if (current.tabIndex >= 0) {\n while (current) {\n if (current === node) {\n active = true;\n break;\n }\n current = current.parentNode;\n }\n }\n if (active) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else {\n const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'open': {\n if (REG_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (REG_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (REG_FORM_CTRL.test(localName) ||\n isCustomElement(node, { formAssociated: true })) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else if (node.localName === 'option') {\n if (parentNode.localName === 'optgroup' &&\n (parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n matched.add(node);\n }\n } else if (node.localName !== 'optgroup') {\n let bool;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n const walker = this.#walker;\n let refNode = traverseNode(parent, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.localName === 'legend') {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (refNode) {\n if (!refNode.contains(node)) {\n bool = true;\n }\n } else {\n bool = true;\n }\n break;\n } else if (parent.localName === 'form') {\n break;\n } else if (parent.parentNode?.nodeType === ELEMENT_NODE) {\n if (parent.parentNode.localName === 'form') {\n break;\n } else {\n parent = parent.parentNode;\n }\n } else {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((REG_FORM_CTRL.test(localName) ||\n isCustomElement(node, { formAssociated: true })) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n if (node.localName === 'optgroup') {\n matched.add(node);\n } else if (node.localName === 'option') {\n if (parentNode.localName !== 'optgroup' ||\n !(parentNode.disabled ||\n parentNode.hasAttribute('disabled'))) {\n matched.add(node);\n }\n } else {\n let bool;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n const walker = this.#walker;\n let refNode = traverseNode(parent, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.localName === 'legend') {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (refNode) {\n if (!refNode.contains(node)) {\n bool = true;\n }\n } else {\n bool = true;\n }\n break;\n } else if (parent.localName === 'form') {\n break;\n } else if (parent.parentNode?.nodeType === ELEMENT_NODE) {\n if (parent.parentNode.localName === 'form') {\n break;\n } else {\n parent = parent.parentNode;\n }\n } else {\n break;\n }\n }\n if (!bool) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || REG_TYPE_DATE.test(node.type) ||\n REG_TYPE_TEXT.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || REG_TYPE_DATE.test(node.type) ||\n REG_TYPE_TEXT.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let placeholder;\n if (node.placeholder) {\n placeholder = node.placeholder;\n } else if (node.hasAttribute('placeholder')) {\n placeholder = node.getAttribute('placeholder');\n }\n if (typeof placeholder === 'string' && !/[\\r\\n]/.test(placeholder)) {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (REG_TYPE_TEXT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '') {\n matched.add(node);\n }\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n REG_TYPE_CHECK.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = this.#document.documentElement;\n }\n const items = parent.getElementsByTagName('input');\n const l = items.length;\n let checked;\n for (let i = 0; i < l; i++) {\n const item = items[i];\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n REG_TYPE_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_SUBMIT.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const walker = this.#walker;\n let nextNode = traverseNode(form, walker);\n nextNode = walker.firstChild();\n while (nextNode && form.contains(nextNode)) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n REG_TYPE_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n REG_TYPE_SUBMIT.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = walker.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_CHECK.test(node.getAttribute('type')) &&\n node.hasAttribute('checked')) {\n matched.add(node);\n // option\n } else if (localName === 'option' && node.hasAttribute('selected')) {\n matched.add(node);\n }\n break;\n }\n case 'valid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0) {\n if (node.maxLength >= node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0 && node.maxLength < node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n REG_TYPE_RANGE.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n REG_TYPE_RANGE.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_TYPE_DATE.test(inputType) ||\n REG_TYPE_TEXT.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_TYPE_DATE.test(inputType) ||\n REG_TYPE_TEXT.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === this.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n let bool;\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'defined': {\n if (node.hasAttribute('is') || localName.includes('-')) {\n if (isCustomElement(node)) {\n matched.add(node);\n }\n // NOTE: MathMLElement not implemented in jsdom\n } else if (node instanceof this.#window.HTMLElement ||\n node instanceof this.#window.SVGElement) {\n matched.add(node);\n }\n break;\n }\n case 'popover-open': {\n if (node.popover) {\n const { display } = this.#window.getComputedStyle(node);\n if (display !== 'none') {\n matched.add(node);\n }\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n // 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 const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match shadow host pseudo class\n * @private\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren, name: astName } = ast;\n let res;\n if (Array.isArray(astChildren)) {\n const { 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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n const msg = `Invalid selector :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const matched = new Set();\n if (ast.name === EMPTY) {\n return matched;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n }\n default: {\n const res = matcher.matchSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n let result;\n if (this.#invalidate) {\n result = this.#invalidateResults.get(leaves);\n } else {\n result = this.#results.get(leaves);\n }\n if (result && result.has(node)) {\n const { matched } = result.get(node);\n bool = matched;\n }\n if (typeof bool !== 'boolean') {\n let cacheable = true;\n if (node.nodeType === ELEMENT_NODE && REG_FORM.test(node.localName)) {\n cacheable = false;\n }\n for (const leaf of leaves) {\n switch (leaf.type) {\n case SELECTOR_ATTR:\n case SELECTOR_ID: {\n cacheable = false;\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n if (/^(?:(?:any-)?link|defined|dir)$/.test(leaf.name)) {\n cacheable = false;\n }\n break;\n }\n default:\n }\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n if (cacheable) {\n if (!result) {\n result = new WeakMap();\n }\n result.set(node, {\n matched: bool\n });\n if (this.#invalidate) {\n this.#invalidateResults.set(leaves, result);\n } else {\n this.#results.set(leaves, result);\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @returns {Set.<object>} - matched nodes\n */\n _matchHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n const nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n return new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (typeof leafName === 'string' && leafName !== leaf.name) {\n leaf.name = leafName;\n }\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (this.#root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = this.#root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, opt);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#document.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const items = baseNode.getElementsByTagName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @private\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} opt - option\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { parentNode } = node;\n const { dir } = opt;\n const matched = new Set();\n if (dir === DIR_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = traverseNode(node, walker);\n refNode = walker.nextSibling();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n const walker = this._createTreeWalker(node);\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n return nodes;\n }\n if (pending) {\n const walker = this._createTreeWalker(node);\n let refNode = traverseNode(node, walker);\n refNode = walker.nextNode();\n while (refNode && node.contains(refNode)) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode === node) {\n break;\n } else {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n if (parentNode) {\n const bool = this._matchLeaves(leaves, parentNode, opt);\n if (bool) {\n matched.add(parentNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n return new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find matched node from #qswalker\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} [opt] - options\n * @param {object} [opt.node] - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, opt) {\n const { node } = opt;\n const walker = this.#qswalker;\n let refNode = traverseNode(node, walker);\n let matchedNode;\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = walker.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = walker.nextNode();\n }\n }\n while (refNode) {\n const matched = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (matched) {\n matchedNode = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * match self\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _matchSelf(leaves) {\n const nodes = [];\n const bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find lineal\n * @private\n * @param {Array} leaves - AST leaves\n * @param {object} opt - options\n * @returns {Array} - [nodes, filtered]\n */\n _findLineal(leaves, opt = {}) {\n const { complex } = opt;\n const nodes = [];\n let bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n if (!bool || complex) {\n let refNode = this.#node.parentNode;\n while (refNode) {\n bool = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(refNode);\n filtered = true;\n }\n if (refNode.parentNode) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find first\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFirst(leaves) {\n const nodes = [];\n const node = this._findNode(leaves, {\n node: this.#node\n });\n let filtered = false;\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find from HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @param {boolean} [opt.compound] - compound selector\n * @param {Array} [opt.filterLeaves] - filter leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFromHTMLCollection(items, opt = {}) {\n const { complex, compound, filterLeaves, targetType } = opt;\n let nodes = [];\n let filtered = false;\n let collected = false;\n const l = items.length;\n if (l) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n if (node !== this.#node &&\n (this.#node.contains(node) || node.contains(this.#node))) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n } else {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (complex) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n } else if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n }\n return [nodes, filtered, collected];\n }\n\n /**\n * find entry nodes\n * @private\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @param {boolean} complex - complex selector\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType, complex) {\n const { leaves } = twig;\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { name: leafName, type: leafType } = leaf;\n let nodes = [];\n let collected = false;\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const items = this.#root.getElementsByClassName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#document.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT ||\n lastType === SELECTOR_ID) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (branchLen === 2) {\n const { name: comboName } = firstCombo;\n if (/^[+~]$/.test(comboName)) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n let bool;\n for (const { combo, leaves: [leaf] } of branch) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n bool = false;\n break;\n }\n if (!bool && combo) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n const {\n collected, compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].collected = collected;\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#qswalker;\n } else {\n node = this.#root;\n walker = this.#walker;\n }\n let nextNode = traverseNode(node, walker);\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (nextNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(nextNode);\n }\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode, {\n warn: this.#warn\n });\n if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].push(nextNode);\n }\n }\n }\n if (nextNode !== walker.currentNode) {\n nextNode = traverseNode(nextNode, walker);\n }\n nextNode = walker.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const complex = branch.length > 1;\n const {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n }\n this.#ast[i].dir = DIR_PREV;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * get combined nodes\n * @private\n * @param {object} twig - twig\n * @param {object} nodes - collection of nodes\n * @param {string} dir - direction\n * @returns {Array.<object>} - collection of matched nodes\n */\n _getCombinedNodes(twig, nodes, dir) {\n const arr = [];\n for (const node of nodes) {\n const matched = this._matchCombinator(twig, node, {\n dir,\n warn: this.#warn\n });\n if (matched.size) {\n arr.push(...matched);\n }\n }\n if (arr.length) {\n return new Set(arr);\n }\n return new Set();\n }\n\n /**\n * match node to next direction\n * @private\n * @param {Array} branch - branch\n * @param {Set.<object>} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], collectedNodes] = this._collectNodes(targetType);\n const l = branches.length;\n let sort;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, collected, dir, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = collectedNodes[i];\n const entryNodesLen = entryNodes.length;\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n if (node !== this.#node && this.#node.contains(node)) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...entryNodes]);\n sort = true;\n } else {\n nodes = new Set(entryNodes);\n }\n } else {\n const [node] = entryNodes;\n nodes.add(node);\n }\n } else if (targetType === TARGET_ALL) {\n if (dir === DIR_NEXT) {\n let { combo } = branch[0];\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const twig = {\n combo,\n leaves\n };\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === lastIndex) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...nextNodes]);\n sort = true;\n } else {\n nodes = nextNodes;\n }\n } else {\n combo = nextCombo;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === 0) {\n nodes.add(node);\n if (branchLen > 1 && nodes.size > 1) {\n sort = true;\n }\n }\n } else {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST && dir === DIR_NEXT) {\n const { combo: entryCombo } = branch[0];\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodeNext(branch, new Set([node]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n nodes.add(matched);\n break;\n }\n }\n if (!matched && !collected) {\n const { leaves: entryLeaves } = branch[0];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodeNext(branch, new Set([refNode]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n nodes.add(matched);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n } else {\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodePrev(branch, node, {\n index: lastIndex - 1\n });\n if (matched) {\n nodes.add(node);\n break;\n }\n }\n if (!matched && !collected && targetType === TARGET_FIRST) {\n const { leaves: entryLeaves } = branch[lastIndex];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodePrev(branch, refNode, {\n index: lastIndex - 1\n });\n if (matched) {\n nodes.add(refNode);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n }\n }\n }\n if (targetType === TARGET_ALL && sort) {\n nodes = new Set(sortNodes(nodes));\n }\n return nodes;\n }\n};\n"],
5
+ "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAGO,yBACPC,EAAwB,wBACxBC,EAEO,uBAGPC,EASO,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,GAMA,YAAYC,EAAQ,CAClB,KAAKD,GAAUC,EACf,KAAKlB,GAAY,IAAI,QACrB,KAAKG,GAAiB,IAAI,QAC1B,KAAKG,GAAqB,IAAI,QAC9B,KAAKK,GAAW,IAAI,OACtB,CASA,SAASQ,EAAG,CACV,GAAI,CAAC,KAAKV,GACR,GAAIU,a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CAId,GAHAH,EAAU,KAAK,eAAeX,EAAQc,EAAS,CAC7C,MAAO4B,EAAY,CACrB,CAAC,EACG/B,EAAS,CACXvB,EAAM,IAAI0B,CAAO,EACjB,KACF,CACAA,EAAU,KAAK,UAAU4F,EAAa,CACpC,KAAM5F,CACR,CAAC,CACH,CACF,CACF,CACF,CACF,CACA,OAAIuE,IAAe,cAAce,IAC/BhH,EAAQ,IAAI,OAAI,aAAUA,CAAK,CAAC,GAE3BA,CACT,CACF",
6
6
  "names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_dom_util", "import_matcher", "import_parser", "import_constant", "DIR_NEXT", "DIR_PREV", "#ast", "#astCache", "#descendant", "#document", "#documentCache", "#event", "#invalidate", "#invalidateResults", "#node", "#nodes", "#noexcept", "#qswalker", "#results", "#root", "#shadow", "#walker", "#walkers", "#warn", "#window", "window", "e", "selector", "node", "opt", "event", "noexcept", "warn", "nodes", "ast", "cachedItem", "item", "l", "i", "cssAst", "branches", "hasHasPseudoFunc", "invalidate", "descendant", "items", "branch", "leaves", "nextItem", "msg", "itemName", "walker", "anb", "a", "b", "reverse", "parentNode", "matched", "selectorBranches", "info", "refNode", "selectorNodes", "display", "visibility", "bool", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "m", "nthName", "nthIdentName", "anbMap", "astLeaves", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "astName", "twigBranches", "res", "forgive", "lastIndex", "nextNodes", "arr", "astChildren", "selectors", "css", "leavesSet", "stateValue", "href", "origin", "pathname", "attrURL", "target", "type", "buttons", "hash", "id", "current", "focus", "active", "parent", "placeholder", "targetNode", "nodeName", "checked", "form", "inputType", "node1", "node2", "host", "astType", "result", "cacheable", "compound", "filterLeaves", "baseNode", "leafName", "pending", "comboName", "dir", "matchedNode", "filtered", "complex", "targetType", "collected", "pendingItems", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "pendingItem", "index", "nextCombo", "collectedNodes", "sort", "find", "entryNodes", "entryNodesLen", "n", "entryCombo", "entryLeaves", "entryNode"]
7
7
  }
package/package.json CHANGED
@@ -60,5 +60,5 @@
60
60
  "tsc": "node scripts/index clean --dir=types -i && npx tsc",
61
61
  "update-wpt": "git submodule update --init --recursive --remote"
62
62
  },
63
- "version": "5.0.5"
63
+ "version": "5.0.7"
64
64
  }
package/src/js/finder.js CHANGED
@@ -1823,7 +1823,7 @@ export class Finder {
1823
1823
  break;
1824
1824
  }
1825
1825
  case SELECTOR_PSEUDO_CLASS: {
1826
- if (/^(?:(?:any-)?link|defined)$/.test(leaf.name)) {
1826
+ if (/^(?:(?:any-)?link|defined|dir)$/.test(leaf.name)) {
1827
1827
  cacheable = false;
1828
1828
  }
1829
1829
  break;