Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asamuzakjp/dom-selector

Package Overview
Dependencies
Maintainers
1
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asamuzakjp/dom-selector - npm Package Compare versions

Comparing version 3.0.2 to 3.0.3

2

dist/cjs/js/finder.js

@@ -1,2 +0,2 @@

var j=Object.create;var U=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(T,a)=>{for(var e in a)U(T,e,{get:a[e],enumerable:!0})},I=(T,a,e,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of H(a))!G.call(T,i)&&i!==e&&U(T,i,{get:()=>a[i],enumerable:!(c=F(a,i))||c.enumerable});return T};var V=(T,a,e)=>(e=T!=null?j(B(T)):{},I(a||!T||!T.__esModule?U(e,"default",{value:T,enumerable:!0}):e,T)),X=T=>I(U({},"__esModule",{value:!0}),T);var K={};q(K,{Finder:()=>Y});module.exports=X(K);var z=V(require("is-potential-custom-element-name"),1),A=require("./dom-util.js"),R=require("./matcher.js"),S=require("./parser.js"),h=require("./constant.js");const C="next",O="prev",L="all",$="first",M="lineal",P="self",W=h.SHOW_DOCUMENT|h.SHOW_DOCUMENT_FRAGMENT|h.SHOW_ELEMENT;class Y{#a;#l;#t;#r;#e;#c;#b;#o;#s;#h;#f;#d;#i;#n;constructor(){this.#l=new WeakMap}_onError(a){if(!this.#b)if(a instanceof DOMException||this.#n&&a instanceof this.#n.DOMException)if(a.name===h.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw this.#n?new this.#n.DOMException(a.message,a.name):a;else throw a}_setup(a,e,c={}){const{noexcept:i,warn:t}=c;return this.#b=!!i,this.#i=!!t,this.#e=e,[this.#n,this.#t,this.#s]=(0,A.prepareDOMObjects)(e),this.#h=(0,A.isInShadowTree)(e),[this.#a,this.#c]=this._correspond(a),this.#o=new WeakMap,e}_correspond(a){const e=[];let c,i=this.#t&&this.#l.get(this.#t);if(i&&i.has(`${a}`)&&(c=i.get(a)),c){const t=c.length;for(let n=0;n<t;n++)c[n].dir=null,c[n].filtered=!1,c[n].find=!1,e[n]=[]}else{let t;try{t=(0,S.parseSelector)(a)}catch(f){this._onError(f)}const n=(0,S.walkAST)(t);c=[];let o=0;for(const[...f]of n){const l=[];let s=f.shift();if(s&&s.type!==h.COMBINATOR){const r=new Set;for(;s;){if(s.type===h.COMBINATOR){const[b]=f;if(b.type===h.COMBINATOR){const d=`Invalid selector ${a}`;throw new DOMException(d,h.SYNTAX_ERR)}l.push({combo:s,leaves:(0,S.sortAST)(r)}),r.clear()}else if(s){let{name:b}=s;b&&(Object.prototype.hasOwnProperty.call(b,"name")?(b=(0,S.unescapeSelector)(b.name),/[|:]/.test(b)&&(s.namespace=!0)):typeof b=="string"&&(b=(0,S.unescapeSelector)(b),/[|:]/.test(b)&&(s.namespace=!0))),r.add(s)}if(f.length)s=f.shift();else{l.push({combo:null,leaves:(0,S.sortAST)(r)}),r.clear();break}}}c.push({branch:l,dir:null,filtered:!1,find:!1}),e[o]=[],o++}this.#t&&(i||(i=new Map),i.set(`${a}`,c),this.#l.set(this.#t,i))}return[c,e]}_prepareTreeWalkers(a){return this.#d=this.#t.createTreeWalker(this.#s,W),this.#r=this.#t.createTreeWalker(a,W),this.#f=!1,[this.#d,this.#r]}_traverse(a={},e=this.#d){let c,i=e.currentNode;if(a.nodeType===h.ELEMENT_NODE&&i===a)c=i;else{if(i!==e.root)for(;i&&!(i===e.root||a.nodeType===h.ELEMENT_NODE&&i===a);)i=e.parentNode();if(a.nodeType===h.ELEMENT_NODE)for(;i;){if(i===a){c=i;break}i=e.nextNode()}else c=i}return c??null}_collectNthChild(a,e,c){const{a:i,b:t,reverse:n,selector:o}=a,{parentNode:f}=e;let l=new Set,s;if(o&&(this.#l.has(o)?s=this.#l.get(o):(s=(0,S.walkAST)(o),this.#l.set(o,s))),f){const r=this.#t.createTreeWalker(f,W);let b=0,d=r.firstChild();for(;d;)b++,d=r.nextSibling();d=this._traverse(f,r);const k=new Set;if(s)for(d=this._traverse(f,r),d=r.firstChild();d;){let m;for(const g of s)if(m=this._matchLeaves(g,d,c),!m)break;m&&k.add(d),d=r.nextSibling()}if(i===0){if(t>0&&t<=b){if(k.size){let m=0;for(d=this._traverse(f,r),n?d=r.lastChild():d=r.firstChild();d;){if(k.has(d)){if(m===t-1){l.add(d);break}m++}n?d=r.previousSibling():d=r.nextSibling()}}else if(!o){let m=0;for(d=this._traverse(f,r),n?d=r.lastChild():d=r.firstChild();d;){if(m===t-1){l.add(d);break}n?d=r.previousSibling():d=r.nextSibling(),m++}}}}else{let m=t-1;if(i>0)for(;m<0;)m+=i;if(m>=0&&m<b){let g=0,_=i>0?0:t-1;for(d=this._traverse(f,r),n?d=r.lastChild():d=r.firstChild();d&&(d&&m>=0&&m<b);)k.size?k.has(d)&&(_===m&&(l.add(d),m+=i),i>0?_++:_--):g===m&&(o||l.add(d),m+=i),n?d=r.previousSibling():d=r.nextSibling(),g++}}if(n&&l.size>1){const m=[...l];l=new Set(m.reverse())}}else if(e===this.#s&&i+t===1)if(s){let r;for(const b of s)if(r=this._matchLeaves(b,e,c),r)break;r&&l.add(e)}else l.add(e);return l}_collectNthOfType(a,e){const{a:c,b:i,reverse:t}=a,{localName:n,parentNode:o,prefix:f}=e;let l=new Set;if(o){const s=this.#t.createTreeWalker(o,W);let r=0,b=s.firstChild();for(;b;)r++,b=s.nextSibling();if(c===0){if(i>0&&i<=r){let d=0;for(b=this._traverse(o,s),t?b=s.lastChild():b=s.firstChild();b;){const{localName:k,prefix:m}=b;if(k===n&&m===f){if(d===i-1){l.add(b);break}d++}t?b=s.previousSibling():b=s.nextSibling()}}}else{let d=i-1;if(c>0)for(;d<0;)d+=c;if(d>=0&&d<r){let k=c>0?0:i-1;for(b=this._traverse(o,s),t?b=s.lastChild():b=s.firstChild();b;){const{localName:m,prefix:g}=b;if(m===n&&g===f){if(k===d&&(l.add(b),d+=c),d<0||d>=r)break;c>0?k++:k--}t?b=s.previousSibling():b=s.nextSibling()}}}if(t&&l.size>1){const d=[...l];l=new Set(d.reverse())}}else e===this.#s&&c+i===1&&l.add(e);return l}_matchAnPlusB(a,e,c,i){const{nth:{a:t,b:n,name:o},selector:f}=a,l=(0,S.unescapeSelector)(o),s=new Map;l?(l==="even"?(s.set("a",2),s.set("b",0)):l==="odd"&&(s.set("a",2),s.set("b",1)),c.indexOf("last")>-1&&s.set("reverse",!0)):(typeof t=="string"&&/-?\d+/.test(t)?s.set("a",t*1):s.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?s.set("b",n*1):s.set("b",0),c.indexOf("last")>-1&&s.set("reverse",!0));let r=new Set;if(s.has("a")&&s.has("b")){if(/^nth-(?:last-)?child$/.test(c)){f&&s.set("selector",f);const b=Object.fromEntries(s),d=this._collectNthChild(b,e,i);d.size&&(r=d)}else if(/^nth-(?:last-)?of-type$/.test(c)){const b=Object.fromEntries(s),d=this._collectNthOfType(b,e);d.size&&(r=d)}}return r}_matchDirectionPseudoClass(a,e){const c=(0,S.unescapeSelector)(a.name),i=(0,A.getDirectionality)(e);let t;return c===i&&(t=e),t??null}_matchLanguagePseudoClass(a,e){const c=(0,S.unescapeSelector)(a.name);let i;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(i=e);else{let t=e.parentNode;for(;t&&t.nodeType===h.ELEMENT_NODE;){if(t.hasAttribute("lang")){t.getAttribute("lang")&&(i=e);break}t=t.parentNode}}else if(c){const t=`(?:-${h.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${h.ALPHA_NUM}${t}$`,"i").test(c)){let o;if(c.indexOf("-")>-1){const[f,l,...s]=c.split("-");let r;f==="*"?r=`${h.ALPHA_NUM}${t}`:r=`${f}${t}`;const b=`-${l}${t}`,d=s.length;let k="";if(d)for(let m=0;m<d;m++)k+=`-${s[m]}${t}`;o=new RegExp(`^${r}${b}${k}$`,"i")}else o=new RegExp(`^${c}${t}$`,"i");if(e.hasAttribute("lang"))o.test(e.getAttribute("lang"))&&(i=e);else{let f=e.parentNode;for(;f&&f.nodeType===h.ELEMENT_NODE;){if(f.hasAttribute("lang")){const l=f.getAttribute("lang");o.test(l)&&(i=e);break}f=f.parentNode}}}}return i??null}_matchHasPseudoFunc(a,e,c={}){let i;if(Array.isArray(a)&&a.length){const[t]=a,{type:n}=t;let o;n===h.COMBINATOR?o=a.shift():o={name:" ",type:h.COMBINATOR};const f=[];for(;a.length;){const[r]=a,{type:b}=r;if(b===h.COMBINATOR)break;f.push(a.shift())}const l={combo:o,leaves:f};c.dir=C;const s=this._matchCombinator(l,e,c);if(s.size)if(a.length){for(const r of s)if(i=this._matchHasPseudoFunc(Object.assign([],a),r,c),i)break}else i=!0}return!!i}_matchLogicalPseudoFunc(a,e,c={}){const{astName:i="",branches:t=[],selector:n="",twigBranches:o=[]}=a;let f;if(i==="has")if(n.includes(":has("))f=null;else{let l;for(const s of t)if(l=this._matchHasPseudoFunc(Object.assign([],s),e,c),l)break;l&&(f=e)}else{const l=/^(?:is|where)$/.test(i);c.forgive=l;const s=o.length;let r;for(let b=0;b<s;b++){const d=o[b],k=d.length-1,{leaves:m}=d[k];if(r=this._matchLeaves(m,e,c),r&&k>0){let g=new Set([e]);for(let _=k-1;_>=0;_--){const y=d[_],u=[];c.dir=O;for(const p of g){const w=this._matchCombinator(y,p,c);w.size&&u.push(...w)}if(u.length)_===0?r=!0:g=new Set(u);else{r=!1;break}}}if(r)break}i==="not"?r||(f=e):r&&(f=e)}return f??null}_matchPseudoClassSelector(a,e,c={}){const{children:i}=a,{localName:t,parentNode:n}=e,{forgive:o,warn:f=this.#i}=c,l=(0,S.unescapeSelector)(a.name);let s=new Set;if(h.REG_LOGICAL_PSEUDO.test(l)){let r;if(this.#l.has(a))r=this.#l.get(a);else{const d=(0,S.walkAST)(a),k=[],m=[];for(const[...g]of d){for(const p of g){const w=(0,S.generateCSS)(p);k.push(w)}const _=[],y=new Set;let u=g.shift();for(;u;)if(u.type===h.COMBINATOR?(_.push({combo:u,leaves:[...y]}),y.clear()):u&&y.add(u),g.length)u=g.shift();else{_.push({combo:null,leaves:[...y]}),y.clear();break}m.push(_)}r={astName:l,branches:d,twigBranches:m,selector:k.join(",")},this.#l.set(a,r)}const b=this._matchLogicalPseudoFunc(r,e,c);b&&s.add(b)}else if(Array.isArray(i)){const[r]=i;if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const b=this._matchAnPlusB(r,e,l,c);b.size&&(s=b)}else if(l==="dir"){const b=this._matchDirectionPseudoClass(r,e);b&&s.add(b)}else if(l==="lang"){const b=this._matchLanguagePseudoClass(r,e);b&&s.add(b)}else switch(l){case"current":case"nth-col":case"nth-last-col":{if(f){const b=`Unsupported pseudo-class :${l}()`;throw new DOMException(b,h.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!o){const b=`Unknown pseudo-class :${l}()`;throw new DOMException(b,h.SYNTAX_ERR)}}}else{const r=/^a(?:rea)?$/,b=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,d=/^(?:(?:inpu|selec)t|button|form|textarea)$/,k=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,g=/^(?:date(?:time-local)?|month|time|week)$/,_=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,y=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(l){case"any-link":case"link":{r.test(t)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(r.test(t)&&e.hasAttribute("href")){const{href:u,origin:p,pathname:w}=new URL(this.#t.URL),E=new URL(e.getAttribute("href"),u);E.origin===p&&E.pathname===w&&s.add(e)}break}case"visited":break;case"target":{const{hash:u}=new URL(this.#t.URL);e.id&&u===`#${e.id}`&&this.#t.contains(e)&&s.add(e);break}case"target-within":{const{hash:u}=new URL(this.#t.URL);if(u){const p=u.replace(/^#/,"");let w=this.#t.getElementById(p);for(;w;){if(w===e){s.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===h.ELEMENT_NODE?e===this.#e&&s.add(e):e===this.#t.documentElement&&s.add(e);break}case"focus":{e===this.#t.activeElement&&this.#n.getComputedStyle(e).display!=="none"&&s.add(e);break}case"focus-within":{let u=this.#t.activeElement;for(;u;){if(u===e){this.#n.getComputedStyle(e).display!=="none"&&s.add(e);break}u=u.parentNode}break}case"open":{k.test(t)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{k.test(t)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(b.test(t)||(0,z.default)(t))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let u=n;for(;u&&u.localName!=="fieldset";)u=u.parentNode;u&&n.localName!=="legend"&&u.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(b.test(t)||(0,z.default)(t))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(t){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||g.test(e.type)||y.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,A.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(t){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||g.test(e.type)||y.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,A.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let u;t==="textarea"?u=e:t==="input"&&(e.hasAttribute("type")?y.test(e.getAttribute("type"))&&(u=e):u=e),u&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&t==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&t==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&t==="input"&&e.type==="checkbox"||t==="progress"&&!e.hasAttribute("value"))s.add(e);else if(t==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const u=e.name;let p=e.parentNode;for(;p&&p.localName!=="form";)p=p.parentNode;p||(p=this.#t.documentElement);let w;const E=p.getElementsByTagName("input"),N=E.length;if(N)for(let v=0;v<N;v++){const x=E[v];if(x.getAttribute("type")==="radio"&&(u?x.getAttribute("name")===u&&(w=!!x.checked):x.hasAttribute("name")||(w=!!x.checked),w))break}w||s.add(e)}break}case"default":{const u=/^(?:button|reset)$/,p=/^(?:image|submit)$/;if(t==="button"&&!(e.hasAttribute("type")&&u.test(e.getAttribute("type")))||t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))){let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;if(w){const E=this.#t.createTreeWalker(w,h.SHOW_ELEMENT);let N=E.firstChild();for(;N;){const v=N.localName;let x;if(v==="button"?x=!(N.hasAttribute("type")&&u.test(N.getAttribute("type"))):v==="input"&&(x=N.hasAttribute("type")&&p.test(N.getAttribute("type"))),x){N===e&&s.add(e);break}N=E.nextNode()}}}else if(t==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(t==="option"){let w=!1,E=n;for(;E&&E.localName!=="datalist";){if(E.localName==="select"){(E.multiple||E.hasAttribute("multiple"))&&(w=!0);break}E=E.parentNode}if(w)(e.selected||e.hasAttribute("selected"))&&s.add(e);else{const N=new Set,v=this.#t.createTreeWalker(n,h.SHOW_ELEMENT);let x=v.firstChild();for(;x;){if(x.selected||x.hasAttribute("selected")){N.add(x);break}x=v.nextSibling()}N.size&&N.has(e)&&s.add(e)}}break}case"valid":{if(d.test(t))e.checkValidity()&&s.add(e);else if(t==="fieldset"){let u;const p=this.#t.createTreeWalker(e,h.SHOW_ELEMENT);let w=p.firstChild();for(;w&&!(d.test(w.localName)&&(u=w.checkValidity(),!u));)w=p.nextNode();u&&s.add(e)}break}case"invalid":{if(d.test(t))e.checkValidity()||s.add(e);else if(t==="fieldset"){let u;const p=this.#t.createTreeWalker(e,h.SHOW_ELEMENT);let w=p.firstChild();for(;w&&!(d.test(w.localName)&&(u=w.checkValidity(),!u));)w=p.nextNode();u||s.add(e)}break}case"in-range":{t==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&_.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&s.add(e);break}case"out-of-range":{t==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&_.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&s.add(e);break}case"required":{let u;if(/^(?:select|textarea)$/.test(t))u=e;else if(t==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||m.test(p)||g.test(p)||y.test(p))&&(u=e)}else u=e;u&&(e.required||e.hasAttribute("required"))&&s.add(e);break}case"optional":{let u;if(/^(?:select|textarea)$/.test(t))u=e;else if(t==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||m.test(p)||g.test(p)||y.test(p))&&(u=e)}else u=e;u&&!(e.required||e.hasAttribute("required"))&&s.add(e);break}case"root":{e===this.#t.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){let u;const p=this.#t.createTreeWalker(e,h.SHOW_ALL);let w=p.firstChild();for(;w&&(u=w.nodeType!==h.ELEMENT_NODE&&w.nodeType!==h.TEXT_NODE,!!u);)w=p.nextSibling();u&&s.add(e)}else s.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&s.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&s.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&s.add(e);break}case"first-of-type":{if(n){const[u]=this._collectNthOfType({a:0,b:1},e);u&&s.add(u)}else e===this.#s&&s.add(e);break}case"last-of-type":{if(n){const[u]=this._collectNthOfType({a:0,b:1,reverse:!0},e);u&&s.add(u)}else e===this.#s&&s.add(e);break}case"only-of-type":{if(n){const[u]=this._collectNthOfType({a:0,b:1},e);if(u===e){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p===e&&s.add(e)}}else e===this.#s&&s.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const u=`Unsupported pseudo-element ::${l}`;throw new DOMException(u,h.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"defined":case"focus-visible":case"fullscreen":case"future":case"hover":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(f){const u=`Unsupported pseudo-class :${l}`;throw new DOMException(u,h.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(f){const u=`Unsupported pseudo-class :${l}`;throw new DOMException(u,h.NOT_SUPPORTED_ERR)}}else if(!o){const u=`Unknown pseudo-class :${l}`;throw new DOMException(u,h.SYNTAX_ERR)}}}return s}_matchShadowHostPseudoClass(a,e){const{children:c}=a,i=(0,S.unescapeSelector)(a.name);let t;if(Array.isArray(c)){const[n]=(0,S.walkAST)(c[0]),[...o]=n,{host:f}=e;if(i==="host"){let l;for(const s of o){const{type:r}=s;if(r===h.COMBINATOR){const d=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(d,h.SYNTAX_ERR)}if(l=this._matchSelector(s,f).has(f),!l)break}l&&(t=e)}else if(i==="host-context"){let l,s=f;for(;s;){for(const r of o){const{type:b}=r;if(b===h.COMBINATOR){const k=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(k,h.SYNTAX_ERR)}if(l=this._matchSelector(r,s).has(s),!l)break}if(l)break;s=s.parentNode}l&&(t=e)}}else if(i==="host")t=e;else{const n=`Invalid selector :${i}`;throw new DOMException(n,h.SYNTAX_ERR)}return t??null}_matchSelector(a,e,c){const{type:i}=a,t=(0,S.unescapeSelector)(a.name);let n=new Set;if(e.nodeType===h.ELEMENT_NODE)switch(i){case h.SELECTOR_PSEUDO_CLASS:{const o=this._matchPseudoClassSelector(a,e,c);o.size&&(n=o);break}case h.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(t,c);break}default:{const o=(0,R.matchSelector)(a,e,c);o&&n.add(o)}}else if(this.#h&&i===h.SELECTOR_PSEUDO_CLASS&&e.nodeType===h.DOCUMENT_FRAGMENT_NODE){if(t!=="has"&&h.REG_LOGICAL_PSEUDO.test(t)){const o=this._matchPseudoClassSelector(a,e,c);o.size&&(n=o)}else if(h.REG_SHADOW_HOST.test(t)){const o=this._matchShadowHostPseudoClass(a,e,c);o&&n.add(o)}}return n}_matchLeaves(a,e,c){let i;if(this.#o.has(a)){const t=this.#o.get(a);if(t.has(e))i=t.get(e);else{for(const n of a)if(i=this._matchSelector(n,e,c).has(e),!i)break;t.set(e,i),this.#o.set(a,t)}}else{for(const n of a)if(i=this._matchSelector(n,e,c).has(e),!i)break;const t=new WeakMap;t.set(e,i),this.#o.set(a,t)}return!!i}_matchHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=new Set;const n=a.length;if(n)if(c)for(let o=0;o<n;o++){const f=a[o];this._matchLeaves(i,f,e)&&t.add(f)}else{const o=[].slice.call(a);t=new Set(o)}return t}_findDescendantNodes(a,e,c){const[i,...t]=a,{type:n}=i,o=(0,S.unescapeSelector)(i.name),f=t.length>0;let l=new Set,s=!1;if(this.#h)s=!0;else switch(n){case h.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(o,c);break}case h.SELECTOR_ID:{if(this.#s.nodeType===h.ELEMENT_NODE)s=!0;else{const r=this.#s.getElementById(o);r&&r!==e&&e.contains(r)&&(f?this._matchLeaves(t,r,c)&&l.add(r):l.add(r))}break}case h.SELECTOR_CLASS:{const r=e.getElementsByClassName(o);l=this._matchHTMLCollection(r,{compound:f,filterLeaves:t});break}case h.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(o)){const r=e.getElementsByTagName(o);l=this._matchHTMLCollection(r,{compound:f,filterLeaves:t})}else s=!0;break}default:s=!0}return{nodes:l,pending:s}}_matchCombinator(a,e,c={}){const{combo:i,leaves:t}=a,{name:n}=i,{dir:o}=c;let f=new Set;if(o===C)switch(n){case"+":{const l=e.nextElementSibling;l&&this._matchLeaves(t,l,c)&&f.add(l);break}case"~":{const{parentNode:l}=e;if(l){const s=this.#t.createTreeWalker(l,h.SHOW_ELEMENT);let r=this._traverse(e,s);for(r===e&&(r=s.nextSibling());r;)this._matchLeaves(t,r,c)&&f.add(r),r=s.nextSibling()}break}case">":{const l=this.#t.createTreeWalker(e,h.SHOW_ELEMENT);let s=l.firstChild();for(;s;)this._matchLeaves(t,s,c)&&f.add(s),s=l.nextSibling();break}case" ":default:{const{nodes:l,pending:s}=this._findDescendantNodes(t,e);if(l.size)f=l;else if(s){const r=this.#t.createTreeWalker(e,h.SHOW_ELEMENT);let b=r.nextNode();for(;b;)this._matchLeaves(t,b,c)&&f.add(b),b=r.nextNode()}}}else switch(n){case"+":{const l=e.previousElementSibling;l&&this._matchLeaves(t,l,c)&&f.add(l);break}case"~":{const l=this.#t.createTreeWalker(e.parentNode,h.SHOW_ELEMENT);let s=l.firstChild();for(;s&&s!==e;)this._matchLeaves(t,s,c)&&f.add(s),s=l.nextSibling();break}case">":{const l=e.parentNode;l&&this._matchLeaves(t,l,c)&&f.add(l);break}case" ":default:{const l=[];let s=e.parentNode;for(;s;)this._matchLeaves(t,s,c)&&l.push(s),s=s.parentNode;l.length&&(f=new Set(l.reverse()))}}return f}_findNode(a,e={}){const{node:c}=e;let i,t=this._traverse(c,this.#r);if(t)for(t.nodeType!==h.ELEMENT_NODE?t=this.#r.nextNode():t===c&&t!==this.#s&&(t=this.#r.nextNode());t;){let n;if(this.#e.nodeType===h.ELEMENT_NODE?t===this.#e?n=!0:n=this.#e.contains(t):n=!0,n&&this._matchLeaves(a,t,{warn:this.#i})){i=t;break}t=this.#r.nextNode()}return i??null}_matchSelf(a){const e=[];let c=!1;return this._matchLeaves(a,this.#e)&&(e.push(this.#e),c=!0),[e,c]}_findLineal(a,e={}){const{complex:c,compound:i,filterLeaves:t}=e,n=[];let o=!1,f=this._matchLeaves([a],this.#e);if(f&&!c&&(i?(f=this._matchLeaves(t,this.#e),f&&(n.push(this.#e),o=!0)):(n.push(this.#e),o=!0)),!f||c){f&&(n.push(this.#e),i||(o=!0));let l=this.#e.parentNode;for(;l&&(f=this._matchLeaves([a],l),f&&(n.push(l),i||(o=!0)),l.parentNode);)l=l.parentNode}return[n,o]}_findFirst(a){const e=[];let c=!1;const i=this._findNode(a,{node:this.#e});return i&&(e.push(i),c=!0),[e,c]}_findFromHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=[],n=!1;const o=a.length;if(o)if(this.#e.nodeType===h.ELEMENT_NODE)for(let f=0;f<o;f++){const l=a[f];(l===this.#e||(0,A.isInclusive)(l,this.#e))&&(c?this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),n=!0):(t.push(l),n=!0))}else if(c)for(let f=0;f<o;f++){const l=a[f];this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),n=!0)}else t=[].slice.call(a),n=!0;return[t,n]}_findEntryNodes(a,e,c){const{leaves:i}=a,[t,...n]=i,{type:o}=t,f=(0,S.unescapeSelector)(t.name),l=n.length>0;let s=[],r=!1,b=!1;switch(o){case h.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(f,{warn:this.#i});break}case h.SELECTOR_ID:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$&&this.#s.nodeType!==h.ELEMENT_NODE){const d=this.#s.getElementById(f);d&&(l?this._matchLeaves(n,d,{warn:this.#i})&&(s.push(d),r=!0):(s.push(d),r=!0))}else b=!0;break}case h.SELECTOR_CLASS:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$)[s,r]=this._findFirst(i);else if(this.#s.nodeType===h.DOCUMENT_NODE){const d=this.#s.getElementsByClassName(f);[s,r]=this._findFromHTMLCollection(d,{compound:l,filterLeaves:n})}else b=!0;break}case h.SELECTOR_TYPE:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===h.DOCUMENT_NODE&&!/[*|]/.test(f)){const d=this.#s.getElementsByTagName(f);[s,r]=this._findFromHTMLCollection(d,{compound:l,filterLeaves:n})}else b=!0;break}default:if(e!==M&&h.REG_SHADOW_HOST.test(f)){if(this.#h&&this.#e.nodeType===h.DOCUMENT_FRAGMENT_NODE){const d=this._matchShadowHostPseudoClass(t,this.#e);d&&(s.push(d),r=!0)}}else e===P?[s,r]=this._matchSelf(i):e===M?[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n}):e===$?[s,r]=this._findFirst(i):b=!0}return{compound:l,filtered:r,nodes:s,pending:b}}_getEntryTwig(a,e){const c=a.length,i=c>1,t=a[0];let n,o;if(i){const{combo:f,leaves:[{name:l,type:s}]}=t,r=a[c-1],{leaves:[{name:b,type:d}]}=r;if(d===h.SELECTOR_PSEUDO_ELEMENT||d===h.SELECTOR_ID)n=O,o=r;else if(s===h.SELECTOR_PSEUDO_ELEMENT||s===h.SELECTOR_ID)n=C,o=t;else if(e===L)if(l==="*"&&s===h.SELECTOR_TYPE)n=O,o=r;else if(b==="*"&&d===h.SELECTOR_TYPE)n=C,o=t;else if(c===2){const{name:k}=f;/^[+~]$/.test(k)?(n=O,o=r):(n=C,o=t)}else n=C,o=t;else if(b==="*"&&d===h.SELECTOR_TYPE)n=C,o=t;else if(l==="*"&&s===h.SELECTOR_TYPE)n=O,o=r;else{let k,m;for(const{combo:g,leaves:[_]}of a){const{type:y}=_,u=(0,S.unescapeSelector)(_.name);if(y===h.SELECTOR_PSEUDO_CLASS&&u==="dir"){k=!1;break}if(g&&!m){const{name:p}=g;/^[+~]$/.test(p)&&(k=!0,m=!0)}}k?(n=C,o=t):(n=O,o=r)}}else n=O,o=t;return{complex:i,dir:n,twig:o}}_collectNodes(a){const e=this.#a.values();if(a===L||a===$){const c=new Set;let i=0;for(const{branch:t}of e){const{complex:n,dir:o,twig:f}=this._getEntryTwig(t,a),{compound:l,filtered:s,nodes:r,pending:b}=this._findEntryNodes(f,a,n);r.length?(this.#a[i].find=!0,this.#c[i]=r):b&&c.add(new Map([["index",i],["twig",f]])),this.#a[i].dir=o,this.#a[i].filtered=s||!l,i++}if(c.size){let t,n;this.#e!==this.#s&&this.#e.nodeType===h.ELEMENT_NODE?(t=this.#e,n=this.#r):(t=this.#s,n=this.#d);let o=this._traverse(t,n);for(;o;){let f=!1;if(this.#e.nodeType===h.ELEMENT_NODE?o===this.#e?f=!0:f=this.#e.contains(o):f=!0,f)for(const l of c){const{leaves:s}=l.get("twig");if(this._matchLeaves(s,o,{warn:this.#i})){const b=l.get("index");this.#a[b].filtered=!0,this.#a[b].find=!0,this.#c[b].push(o)}}o=n.nextNode()}}}else{let c=0;for(const{branch:i}of e){const t=i[i.length-1],n=i.length>1,{compound:o,filtered:f,nodes:l}=this._findEntryNodes(t,a,n);l.length&&(this.#a[c].find=!0,this.#c[c]=l),this.#a[c].dir=O,this.#a[c].filtered=f||!o,c++}}return[this.#a,this.#c]}_matchNodes(a){const[...e]=this.#a,c=e.length;let i=new Set;for(let t=0;t<c;t++){const{branch:n,dir:o,filtered:f,find:l}=e[t],s=n.length;if(s&&l){const r=this.#c[t],b=r.length,d=s-1;if(d===0){const{leaves:[,...k]}=n[0];if((a===L||a===$)&&this.#e.nodeType===h.ELEMENT_NODE)for(let m=0;m<b;m++){const g=r[m];if(g!==this.#e&&this.#e.contains(g)&&(i.add(g),a!==L))break}else if(k.length)for(let m=0;m<b;m++){const g=r[m];if((f||this._matchLeaves(k,g,{warn:this.#i}))&&(i.add(g),a!==L))break}else if(a===L)if(i.size){const m=[...i];i=new Set([...m,...r]),this.#f=!0}else i=new Set([...r]);else{const[m]=[...r];i.add(m)}}else if(o===C){let{combo:k,leaves:m}=n[0],g;for(let _=0;_<b;_++){const y=r[_];let u=new Set([y]);for(let p=1;p<s;p++){const{combo:w,leaves:E}=n[p],N=[];for(const v of u){const x={combo:k,leaves:E},D=this._matchCombinator(x,v,{dir:o,warn:this.#i});D.size&&N.push(...D)}if(N.length)if(p===d){if(a===L){if(i.size){const v=[...i];i=new Set([...v,...N])}else i=new Set([...N]);this.#f=!0}else{const[v]=(0,A.sortNodes)(N);i.add(v)}g=!0}else k=w,u=new Set(N),g=!1;else{g=!1;break}}if(g&&a!==L)break}if(!g&&a===$){const[_]=[...r];let y=this._findNode(m,{node:_});for(;y;){let u=new Set([y]);for(let p=1;p<s;p++){const{combo:w,leaves:E}=n[p],N=[];for(const v of u){const x={combo:k,leaves:E},D=this._matchCombinator(x,v,{dir:o,warn:this.#i});D.size&&N.push(...D)}if(N.length)if(p===d){const[v]=(0,A.sortNodes)(N);i.add(v),g=!0}else k=w,u=new Set(N),g=!1;else{g=!1;break}}if(g)break;y=this._findNode(m,{node:y}),u=new Set([y])}}}else{const{leaves:k}=n[d];let m;for(let g=0;g<b;g++){const _=r[g];let y=new Set([_]);for(let u=d-1;u>=0;u--){const p=n[u],w=[];for(const E of y){const N=this._matchCombinator(p,E,{dir:o,warn:this.#i});N.size&&w.push(...N)}if(w.length)u===0?(i.add(_),m=!0,a===L&&s>1&&i.size>1&&(this.#f=!0)):(y=new Set(w),m=!1);else{m=!1;break}}if(m&&a!==L)break}if(!m&&a===$){const[g]=[...r];let _=this._findNode(k,{node:g});for(;_;){let y=new Set([_]);for(let u=d-1;u>=0;u--){const p=n[u],w=[];for(const E of y){const N=this._matchCombinator(p,E,{dir:o,warn:this.#i});N.size&&w.push(...N)}if(w.length)u===0?(i.add(_),m=!0):(y=new Set(w),m=!1);else{m=!1;break}}if(m)break;_=this._findNode(k,{node:_}),y=new Set([_])}}}}}return i}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==h.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}i=this._find(P).size}catch(t){this._onError(t)}return!!i}closest(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==h.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}const t=this._find(M);if(t.size){let n=this.#e;for(;n;){if(t.has(n)){i=n;break}n=n.parentNode}}}catch(t){this._onError(t)}return i??null}querySelector(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find($);t.delete(this.#e),t.size&&([i]=(0,A.sortNodes)(t))}catch(t){this._onError(t)}return i??null}querySelectorAll(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find(L);t.delete(this.#e),t.size&&(this.#f?i=(0,A.sortNodes)(t):i=[...t])}catch(t){this._onError(t)}return i??[]}}0&&(module.exports={Finder});
var j=Object.create;var U=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(T,a)=>{for(var e in a)U(T,e,{get:a[e],enumerable:!0})},I=(T,a,e,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of H(a))!G.call(T,i)&&i!==e&&U(T,i,{get:()=>a[i],enumerable:!(c=F(a,i))||c.enumerable});return T};var V=(T,a,e)=>(e=T!=null?j(B(T)):{},I(a||!T||!T.__esModule?U(e,"default",{value:T,enumerable:!0}):e,T)),X=T=>I(U({},"__esModule",{value:!0}),T);var K={};q(K,{Finder:()=>Y});module.exports=X(K);var z=V(require("is-potential-custom-element-name"),1),x=require("./dom-util.js"),R=require("./matcher.js"),v=require("./parser.js"),h=require("./constant.js");const C="next",O="prev",L="all",$="first",M="lineal",P="self",W=h.SHOW_DOCUMENT|h.SHOW_DOCUMENT_FRAGMENT|h.SHOW_ELEMENT;class Y{#a;#l;#t;#r;#e;#n;#b;#c;#s;#h;#o;#d;#i;#f;constructor(){this.#l=new WeakMap}_onError(a){if(!this.#b)if(a instanceof DOMException||this.#f&&a instanceof this.#f.DOMException)if(a.name===h.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw this.#f?new this.#f.DOMException(a.message,a.name):a;else throw a}_setup(a,e,c={}){const{noexcept:i,warn:t}=c;return this.#b=!!i,this.#i=!!t,this.#e=e,[this.#f,this.#t,this.#s]=(0,x.prepareDOMObjects)(e),this.#h=(0,x.isInShadowTree)(e),[this.#a,this.#n]=this._correspond(a),this.#c=new WeakMap,e}_correspond(a){const e=[];let c,i=this.#t&&this.#l.get(this.#t);if(i&&i.has(`${a}`)&&(c=i.get(a)),c){const t=c.length;for(let n=0;n<t;n++)c[n].dir=null,c[n].filtered=!1,c[n].find=!1,e[n]=[]}else{let t;try{t=(0,v.parseSelector)(a)}catch(f){this._onError(f)}const n=(0,v.walkAST)(t);c=[];let o=0;for(const[...f]of n){const l=[];let s=f.shift();if(s&&s.type!==h.COMBINATOR){const r=new Set;for(;s;){if(s.type===h.COMBINATOR){const[u]=f;if(u.type===h.COMBINATOR){const b=`Invalid selector ${a}`;throw new DOMException(b,h.SYNTAX_ERR)}l.push({combo:s,leaves:(0,v.sortAST)(r)}),r.clear()}else if(s){let{name:u}=s;u&&(Object.prototype.hasOwnProperty.call(u,"name")?(u=(0,v.unescapeSelector)(u.name),/[|:]/.test(u)&&(s.namespace=!0)):typeof u=="string"&&(u=(0,v.unescapeSelector)(u),/[|:]/.test(u)&&(s.namespace=!0))),r.add(s)}if(f.length)s=f.shift();else{l.push({combo:null,leaves:(0,v.sortAST)(r)}),r.clear();break}}}c.push({branch:l,dir:null,filtered:!1,find:!1}),e[o]=[],o++}this.#t&&(i||(i=new Map),i.set(`${a}`,c),this.#l.set(this.#t,i))}return[c,e]}_prepareTreeWalkers(a){return this.#d=this.#t.createTreeWalker(this.#s,W),this.#r=this.#t.createTreeWalker(a,W),this.#o=!1,[this.#d,this.#r]}_traverse(a={},e=this.#d){let c,i=e.currentNode;if(a.nodeType===h.ELEMENT_NODE&&i===a)c=i;else{if(i!==e.root)for(;i&&!(i===e.root||a.nodeType===h.ELEMENT_NODE&&i===a);)i=e.parentNode();if(a.nodeType===h.ELEMENT_NODE)for(;i;){if(i===a){c=i;break}i=e.nextNode()}else c=i}return c??null}_collectNthChild(a,e,c){const{a:i,b:t,reverse:n,selector:o}=a,{parentNode:f}=e;let l=new Set,s;if(o&&(this.#l.has(o)?s=this.#l.get(o):(s=(0,v.walkAST)(o),this.#l.set(o,s))),f){const r=this.#t.createTreeWalker(f,W);let u=0,b=r.firstChild();for(;b;)u++,b=r.nextSibling();b=this._traverse(f,r);const k=new Set;if(s)for(b=this._traverse(f,r),b=r.firstChild();b;){let p;for(const g of s)if(p=this._matchLeaves(g,b,c),!p)break;p&&k.add(b),b=r.nextSibling()}if(i===0){if(t>0&&t<=u){if(k.size){let p=0;for(b=this._traverse(f,r),n?b=r.lastChild():b=r.firstChild();b;){if(k.has(b)){if(p===t-1){l.add(b);break}p++}n?b=r.previousSibling():b=r.nextSibling()}}else if(!o){let p=0;for(b=this._traverse(f,r),n?b=r.lastChild():b=r.firstChild();b;){if(p===t-1){l.add(b);break}n?b=r.previousSibling():b=r.nextSibling(),p++}}}}else{let p=t-1;if(i>0)for(;p<0;)p+=i;if(p>=0&&p<u){let g=0,N=i>0?0:t-1;for(b=this._traverse(f,r),n?b=r.lastChild():b=r.firstChild();b&&(b&&p>=0&&p<u);)k.size?k.has(b)&&(N===p&&(l.add(b),p+=i),i>0?N++:N--):g===p&&(o||l.add(b),p+=i),n?b=r.previousSibling():b=r.nextSibling(),g++}}if(n&&l.size>1){const p=[...l];l=new Set(p.reverse())}}else if(e===this.#s&&i+t===1)if(s){let r;for(const u of s)if(r=this._matchLeaves(u,e,c),r)break;r&&l.add(e)}else l.add(e);return l}_collectNthOfType(a,e){const{a:c,b:i,reverse:t}=a,{localName:n,parentNode:o,prefix:f}=e;let l=new Set;if(o){const s=this.#t.createTreeWalker(o,W);let r=0,u=s.firstChild();for(;u;)r++,u=s.nextSibling();if(c===0){if(i>0&&i<=r){let b=0;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:k,prefix:p}=u;if(k===n&&p===f){if(b===i-1){l.add(u);break}b++}t?u=s.previousSibling():u=s.nextSibling()}}}else{let b=i-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b<r){let k=c>0?0:i-1;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:p,prefix:g}=u;if(p===n&&g===f){if(k===b&&(l.add(u),b+=c),b<0||b>=r)break;c>0?k++:k--}t?u=s.previousSibling():u=s.nextSibling()}}}if(t&&l.size>1){const b=[...l];l=new Set(b.reverse())}}else e===this.#s&&c+i===1&&l.add(e);return l}_matchAnPlusB(a,e,c,i){const{nth:{a:t,b:n,name:o},selector:f}=a,l=(0,v.unescapeSelector)(o),s=new Map;l?(l==="even"?(s.set("a",2),s.set("b",0)):l==="odd"&&(s.set("a",2),s.set("b",1)),c.indexOf("last")>-1&&s.set("reverse",!0)):(typeof t=="string"&&/-?\d+/.test(t)?s.set("a",t*1):s.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?s.set("b",n*1):s.set("b",0),c.indexOf("last")>-1&&s.set("reverse",!0));let r=new Set;if(s.has("a")&&s.has("b")){if(/^nth-(?:last-)?child$/.test(c)){f&&s.set("selector",f);const u=Object.fromEntries(s),b=this._collectNthChild(u,e,i);b.size&&(r=b)}else if(/^nth-(?:last-)?of-type$/.test(c)){const u=Object.fromEntries(s),b=this._collectNthOfType(u,e);b.size&&(r=b)}}return r}_matchDirectionPseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name),i=(0,x.getDirectionality)(e);let t;return c===i&&(t=e),t??null}_matchLanguagePseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name);let i;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(i=e);else{let t=e.parentNode;for(;t&&t.nodeType===h.ELEMENT_NODE;){if(t.hasAttribute("lang")){t.getAttribute("lang")&&(i=e);break}t=t.parentNode}}else if(c){const t=`(?:-${h.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${h.ALPHA_NUM}${t}$`,"i").test(c)){let o;if(c.indexOf("-")>-1){const[f,l,...s]=c.split("-");let r;f==="*"?r=`${h.ALPHA_NUM}${t}`:r=`${f}${t}`;const u=`-${l}${t}`,b=s.length;let k="";if(b)for(let p=0;p<b;p++)k+=`-${s[p]}${t}`;o=new RegExp(`^${r}${u}${k}$`,"i")}else o=new RegExp(`^${c}${t}$`,"i");if(e.hasAttribute("lang"))o.test(e.getAttribute("lang"))&&(i=e);else{let f=e.parentNode;for(;f&&f.nodeType===h.ELEMENT_NODE;){if(f.hasAttribute("lang")){const l=f.getAttribute("lang");o.test(l)&&(i=e);break}f=f.parentNode}}}}return i??null}_matchHasPseudoFunc(a,e,c={}){let i;if(Array.isArray(a)&&a.length){const[t]=a,{type:n}=t;let o;n===h.COMBINATOR?o=a.shift():o={name:" ",type:h.COMBINATOR};const f=[];for(;a.length;){const[r]=a,{type:u}=r;if(u===h.COMBINATOR)break;f.push(a.shift())}const l={combo:o,leaves:f};c.dir=C;const s=this._matchCombinator(l,e,c);if(s.size)if(a.length){for(const r of s)if(i=this._matchHasPseudoFunc(Object.assign([],a),r,c),i)break}else i=!0}return!!i}_matchLogicalPseudoFunc(a,e,c={}){const{astName:i="",branches:t=[],selector:n="",twigBranches:o=[]}=a;let f;if(i==="has")if(n.includes(":has("))f=null;else{let l;for(const s of t)if(l=this._matchHasPseudoFunc(Object.assign([],s),e,c),l)break;l&&(f=e)}else{const l=/^(?:is|where)$/.test(i);c.forgive=l;const s=o.length;let r;for(let u=0;u<s;u++){const b=o[u],k=b.length-1,{leaves:p}=b[k];if(r=this._matchLeaves(p,e,c),r&&k>0){let g=new Set([e]);for(let N=k-1;N>=0;N--){const S=b[N],d=[];c.dir=O;for(const m of g){const w=this._matchCombinator(S,m,c);w.size&&d.push(...w)}if(d.length)N===0?r=!0:g=new Set(d);else{r=!1;break}}}if(r)break}i==="not"?r||(f=e):r&&(f=e)}return f??null}_matchPseudoClassSelector(a,e,c={}){const{children:i}=a,{localName:t,parentNode:n}=e,{forgive:o,warn:f=this.#i}=c,l=(0,v.unescapeSelector)(a.name);let s=new Set;if(h.REG_LOGICAL_PSEUDO.test(l)){let r;if(this.#l.has(a))r=this.#l.get(a);else{const b=(0,v.walkAST)(a),k=[],p=[];for(const[...g]of b){for(const m of g){const w=(0,v.generateCSS)(m);k.push(w)}const N=[],S=new Set;let d=g.shift();for(;d;)if(d.type===h.COMBINATOR?(N.push({combo:d,leaves:[...S]}),S.clear()):d&&S.add(d),g.length)d=g.shift();else{N.push({combo:null,leaves:[...S]}),S.clear();break}p.push(N)}r={astName:l,branches:b,twigBranches:p,selector:k.join(",")},this.#l.set(a,r)}const u=this._matchLogicalPseudoFunc(r,e,c);u&&s.add(u)}else if(Array.isArray(i)){const[r]=i;if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const u=this._matchAnPlusB(r,e,l,c);u.size&&(s=u)}else if(l==="dir"){const u=this._matchDirectionPseudoClass(r,e);u&&s.add(u)}else if(l==="lang"){const u=this._matchLanguagePseudoClass(r,e);u&&s.add(u)}else switch(l){case"current":case"nth-col":case"nth-last-col":{if(f){const u=`Unsupported pseudo-class :${l}()`;throw new DOMException(u,h.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!o){const u=`Unknown pseudo-class :${l}()`;throw new DOMException(u,h.SYNTAX_ERR)}}}else{const r=/^a(?:rea)?$/,u=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,b=/^(?:(?:inpu|selec)t|button|form|textarea)$/,k=/^d(?:etails|ialog)$/,p=/^(?:checkbox|radio)$/,g=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,S=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(l){case"any-link":case"link":{r.test(t)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(r.test(t)&&e.hasAttribute("href")){const{href:d,origin:m,pathname:w}=new URL(this.#t.URL),_=new URL(e.getAttribute("href"),d);_.origin===m&&_.pathname===w&&s.add(e)}break}case"visited":break;case"target":{const{hash:d}=new URL(this.#t.URL);e.id&&d===`#${e.id}`&&this.#t.contains(e)&&s.add(e);break}case"target-within":{const{hash:d}=new URL(this.#t.URL);if(d){const m=d.replace(/^#/,"");let w=this.#t.getElementById(m);for(;w;){if(w===e){s.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===h.ELEMENT_NODE?e===this.#e&&s.add(e):e===this.#t.documentElement&&s.add(e);break}case"focus":{if(e===this.#t.activeElement){let d=!0,m=e;for(;m;){if(m.hasAttribute("hidden")){d=!1;break}else if(m.hasAttribute("style")){const{display:w,visibility:_}=m.style;if(d=!(w==="none"||_==="hidden"),!d)break}if(m.parentNode&&m.parentNode.nodeType===h.ELEMENT_NODE)m=m.parentNode;else break}d&&s.add(e)}break}case"focus-within":{let d,m=this.#t.activeElement;for(;m;){if(m===e){d=!0;break}m=m.parentNode}if(d){let w=!0,_=e;for(;_;){if(_.hasAttribute("hidden")){w=!1;break}else if(_.hasAttribute("style")){const{display:y,visibility:E}=_.style;if(w=!(y==="none"||E==="hidden"),!w)break}if(_.parentNode&&_.parentNode.nodeType===h.ELEMENT_NODE)_=_.parentNode;else break}w&&s.add(e)}break}case"open":{k.test(t)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{k.test(t)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(u.test(t)||(0,z.default)(t))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let d=n;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&n.localName!=="legend"&&d.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(u.test(t)||(0,z.default)(t))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(t){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(t){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let d;t==="textarea"?d=e:t==="input"&&(e.hasAttribute("type")?S.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))||e.selected&&t==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&t==="input"&&e.type==="checkbox"||t==="progress"&&!e.hasAttribute("value"))s.add(e);else if(t==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let m=e.parentNode;for(;m&&m.localName!=="form";)m=m.parentNode;m||(m=this.#t.documentElement);let w;const _=m.getElementsByTagName("input"),y=_.length;if(y)for(let E=0;E<y;E++){const A=_[E];if(A.getAttribute("type")==="radio"&&(d?A.getAttribute("name")===d&&(w=!!A.checked):A.hasAttribute("name")||(w=!!A.checked),w))break}w||s.add(e)}break}case"default":{const d=/^(?:button|reset)$/,m=/^(?:image|submit)$/;if(t==="button"&&!(e.hasAttribute("type")&&d.test(e.getAttribute("type")))||t==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))){let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;if(w){const _=this.#t.createTreeWalker(w,h.SHOW_ELEMENT);let y=_.firstChild();for(;y;){const E=y.localName;let A;if(E==="button"?A=!(y.hasAttribute("type")&&d.test(y.getAttribute("type"))):E==="input"&&(A=y.hasAttribute("type")&&m.test(y.getAttribute("type"))),A){y===e&&s.add(e);break}y=_.nextNode()}}}else if(t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(t==="option"){let w=!1,_=n;for(;_&&_.localName!=="datalist";){if(_.localName==="select"){(_.multiple||_.hasAttribute("multiple"))&&(w=!0);break}_=_.parentNode}if(w)(e.selected||e.hasAttribute("selected"))&&s.add(e);else{const y=new Set,E=this.#t.createTreeWalker(n,h.SHOW_ELEMENT);let A=E.firstChild();for(;A;){if(A.selected||A.hasAttribute("selected")){y.add(A);break}A=E.nextSibling()}y.size&&y.has(e)&&s.add(e)}}break}case"valid":{if(b.test(t))e.checkValidity()&&s.add(e);else if(t==="fieldset"){let d;const m=this.#t.createTreeWalker(e,h.SHOW_ELEMENT);let w=m.firstChild();for(;w&&!(b.test(w.localName)&&(d=w.checkValidity(),!d));)w=m.nextNode();d&&s.add(e)}break}case"invalid":{if(b.test(t))e.checkValidity()||s.add(e);else if(t==="fieldset"){let d;const m=this.#t.createTreeWalker(e,h.SHOW_ELEMENT);let w=m.firstChild();for(;w&&!(b.test(w.localName)&&(d=w.checkValidity(),!d));)w=m.nextNode();d||s.add(e)}break}case"in-range":{t==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&s.add(e);break}case"out-of-range":{t==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&s.add(e);break}case"required":{let d;if(/^(?:select|textarea)$/.test(t))d=e;else if(t==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||p.test(m)||g.test(m)||S.test(m))&&(d=e)}else d=e;d&&(e.required||e.hasAttribute("required"))&&s.add(e);break}case"optional":{let d;if(/^(?:select|textarea)$/.test(t))d=e;else if(t==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||p.test(m)||g.test(m)||S.test(m))&&(d=e)}else d=e;d&&!(e.required||e.hasAttribute("required"))&&s.add(e);break}case"root":{e===this.#t.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){let d;const m=this.#t.createTreeWalker(e,h.SHOW_ALL);let w=m.firstChild();for(;w&&(d=w.nodeType!==h.ELEMENT_NODE&&w.nodeType!==h.TEXT_NODE,!!d);)w=m.nextSibling();d&&s.add(e)}else s.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&s.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&s.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&s.add(e);break}case"first-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);d&&s.add(d)}else e===this.#s&&s.add(e);break}case"last-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1,reverse:!0},e);d&&s.add(d)}else e===this.#s&&s.add(e);break}case"only-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);if(d===e){const[m]=this._collectNthOfType({a:0,b:1,reverse:!0},e);m===e&&s.add(e)}}else e===this.#s&&s.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const d=`Unsupported pseudo-element ::${l}`;throw new DOMException(d,h.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"defined":case"focus-visible":case"fullscreen":case"future":case"hover":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(f){const d=`Unsupported pseudo-class :${l}`;throw new DOMException(d,h.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(f){const d=`Unsupported pseudo-class :${l}`;throw new DOMException(d,h.NOT_SUPPORTED_ERR)}}else if(!o){const d=`Unknown pseudo-class :${l}`;throw new DOMException(d,h.SYNTAX_ERR)}}}return s}_matchShadowHostPseudoClass(a,e){const{children:c}=a,i=(0,v.unescapeSelector)(a.name);let t;if(Array.isArray(c)){const[n]=(0,v.walkAST)(c[0]),[...o]=n,{host:f}=e;if(i==="host"){let l;for(const s of o){const{type:r}=s;if(r===h.COMBINATOR){const b=`Invalid selector ${(0,v.generateCSS)(a)}`;throw new DOMException(b,h.SYNTAX_ERR)}if(l=this._matchSelector(s,f).has(f),!l)break}l&&(t=e)}else if(i==="host-context"){let l,s=f;for(;s;){for(const r of o){const{type:u}=r;if(u===h.COMBINATOR){const k=`Invalid selector ${(0,v.generateCSS)(a)}`;throw new DOMException(k,h.SYNTAX_ERR)}if(l=this._matchSelector(r,s).has(s),!l)break}if(l)break;s=s.parentNode}l&&(t=e)}}else if(i==="host")t=e;else{const n=`Invalid selector :${i}`;throw new DOMException(n,h.SYNTAX_ERR)}return t??null}_matchSelector(a,e,c){const{type:i}=a,t=(0,v.unescapeSelector)(a.name);let n=new Set;if(e.nodeType===h.ELEMENT_NODE)switch(i){case h.SELECTOR_PSEUDO_CLASS:{const o=this._matchPseudoClassSelector(a,e,c);o.size&&(n=o);break}case h.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(t,c);break}default:{const o=(0,R.matchSelector)(a,e,c);o&&n.add(o)}}else if(this.#h&&i===h.SELECTOR_PSEUDO_CLASS&&e.nodeType===h.DOCUMENT_FRAGMENT_NODE){if(t!=="has"&&h.REG_LOGICAL_PSEUDO.test(t)){const o=this._matchPseudoClassSelector(a,e,c);o.size&&(n=o)}else if(h.REG_SHADOW_HOST.test(t)){const o=this._matchShadowHostPseudoClass(a,e,c);o&&n.add(o)}}return n}_matchLeaves(a,e,c){let i;if(this.#c.has(a)){const t=this.#c.get(a);if(t.has(e))i=t.get(e);else{for(const n of a)if(i=this._matchSelector(n,e,c).has(e),!i)break;t.set(e,i),this.#c.set(a,t)}}else{for(const n of a)if(i=this._matchSelector(n,e,c).has(e),!i)break;const t=new WeakMap;t.set(e,i),this.#c.set(a,t)}return!!i}_matchHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=new Set;const n=a.length;if(n)if(c)for(let o=0;o<n;o++){const f=a[o];this._matchLeaves(i,f,e)&&t.add(f)}else{const o=[].slice.call(a);t=new Set(o)}return t}_findDescendantNodes(a,e,c){const[i,...t]=a,{type:n}=i,o=(0,v.unescapeSelector)(i.name),f=t.length>0;let l=new Set,s=!1;if(this.#h)s=!0;else switch(n){case h.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(o,c);break}case h.SELECTOR_ID:{if(this.#s.nodeType===h.ELEMENT_NODE)s=!0;else{const r=this.#s.getElementById(o);r&&r!==e&&e.contains(r)&&(f?this._matchLeaves(t,r,c)&&l.add(r):l.add(r))}break}case h.SELECTOR_CLASS:{const r=e.getElementsByClassName(o);l=this._matchHTMLCollection(r,{compound:f,filterLeaves:t});break}case h.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(o)){const r=e.getElementsByTagName(o);l=this._matchHTMLCollection(r,{compound:f,filterLeaves:t})}else s=!0;break}default:s=!0}return{nodes:l,pending:s}}_matchCombinator(a,e,c={}){const{combo:i,leaves:t}=a,{name:n}=i,{dir:o}=c;let f=new Set;if(o===C)switch(n){case"+":{const l=e.nextElementSibling;l&&this._matchLeaves(t,l,c)&&f.add(l);break}case"~":{const{parentNode:l}=e;if(l){const s=this.#t.createTreeWalker(l,h.SHOW_ELEMENT);let r=this._traverse(e,s);for(r===e&&(r=s.nextSibling());r;)this._matchLeaves(t,r,c)&&f.add(r),r=s.nextSibling()}break}case">":{const l=this.#t.createTreeWalker(e,h.SHOW_ELEMENT);let s=l.firstChild();for(;s;)this._matchLeaves(t,s,c)&&f.add(s),s=l.nextSibling();break}case" ":default:{const{nodes:l,pending:s}=this._findDescendantNodes(t,e);if(l.size)f=l;else if(s){const r=this.#t.createTreeWalker(e,h.SHOW_ELEMENT);let u=r.nextNode();for(;u;)this._matchLeaves(t,u,c)&&f.add(u),u=r.nextNode()}}}else switch(n){case"+":{const l=e.previousElementSibling;l&&this._matchLeaves(t,l,c)&&f.add(l);break}case"~":{const l=this.#t.createTreeWalker(e.parentNode,h.SHOW_ELEMENT);let s=l.firstChild();for(;s&&s!==e;)this._matchLeaves(t,s,c)&&f.add(s),s=l.nextSibling();break}case">":{const l=e.parentNode;l&&this._matchLeaves(t,l,c)&&f.add(l);break}case" ":default:{const l=[];let s=e.parentNode;for(;s;)this._matchLeaves(t,s,c)&&l.push(s),s=s.parentNode;l.length&&(f=new Set(l.reverse()))}}return f}_findNode(a,e={}){const{node:c}=e;let i,t=this._traverse(c,this.#r);if(t)for(t.nodeType!==h.ELEMENT_NODE?t=this.#r.nextNode():t===c&&t!==this.#s&&(t=this.#r.nextNode());t;){let n;if(this.#e.nodeType===h.ELEMENT_NODE?t===this.#e?n=!0:n=this.#e.contains(t):n=!0,n&&this._matchLeaves(a,t,{warn:this.#i})){i=t;break}t=this.#r.nextNode()}return i??null}_matchSelf(a){const e=[];let c=!1;return this._matchLeaves(a,this.#e)&&(e.push(this.#e),c=!0),[e,c]}_findLineal(a,e={}){const{complex:c,compound:i,filterLeaves:t}=e,n=[];let o=!1,f=this._matchLeaves([a],this.#e);if(f&&!c&&(i?(f=this._matchLeaves(t,this.#e),f&&(n.push(this.#e),o=!0)):(n.push(this.#e),o=!0)),!f||c){f&&(n.push(this.#e),i||(o=!0));let l=this.#e.parentNode;for(;l&&(f=this._matchLeaves([a],l),f&&(n.push(l),i||(o=!0)),l.parentNode);)l=l.parentNode}return[n,o]}_findFirst(a){const e=[];let c=!1;const i=this._findNode(a,{node:this.#e});return i&&(e.push(i),c=!0),[e,c]}_findFromHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=[],n=!1;const o=a.length;if(o)if(this.#e.nodeType===h.ELEMENT_NODE)for(let f=0;f<o;f++){const l=a[f];(l===this.#e||(0,x.isInclusive)(l,this.#e))&&(c?this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),n=!0):(t.push(l),n=!0))}else if(c)for(let f=0;f<o;f++){const l=a[f];this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),n=!0)}else t=[].slice.call(a),n=!0;return[t,n]}_findEntryNodes(a,e,c){const{leaves:i}=a,[t,...n]=i,{type:o}=t,f=(0,v.unescapeSelector)(t.name),l=n.length>0;let s=[],r=!1,u=!1;switch(o){case h.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(f,{warn:this.#i});break}case h.SELECTOR_ID:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$&&this.#s.nodeType!==h.ELEMENT_NODE){const b=this.#s.getElementById(f);b&&(l?this._matchLeaves(n,b,{warn:this.#i})&&(s.push(b),r=!0):(s.push(b),r=!0))}else u=!0;break}case h.SELECTOR_CLASS:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$)[s,r]=this._findFirst(i);else if(this.#s.nodeType===h.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(f);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}case h.SELECTOR_TYPE:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===h.DOCUMENT_NODE&&!/[*|]/.test(f)){const b=this.#s.getElementsByTagName(f);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}default:if(e!==M&&h.REG_SHADOW_HOST.test(f)){if(this.#h&&this.#e.nodeType===h.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(t,this.#e);b&&(s.push(b),r=!0)}}else e===P?[s,r]=this._matchSelf(i):e===M?[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n}):e===$?[s,r]=this._findFirst(i):u=!0}return{compound:l,filtered:r,nodes:s,pending:u}}_getEntryTwig(a,e){const c=a.length,i=c>1,t=a[0];let n,o;if(i){const{combo:f,leaves:[{name:l,type:s}]}=t,r=a[c-1],{leaves:[{name:u,type:b}]}=r;if(b===h.SELECTOR_PSEUDO_ELEMENT||b===h.SELECTOR_ID)n=O,o=r;else if(s===h.SELECTOR_PSEUDO_ELEMENT||s===h.SELECTOR_ID)n=C,o=t;else if(e===L)if(l==="*"&&s===h.SELECTOR_TYPE)n=O,o=r;else if(u==="*"&&b===h.SELECTOR_TYPE)n=C,o=t;else if(c===2){const{name:k}=f;/^[+~]$/.test(k)?(n=O,o=r):(n=C,o=t)}else n=C,o=t;else if(u==="*"&&b===h.SELECTOR_TYPE)n=C,o=t;else if(l==="*"&&s===h.SELECTOR_TYPE)n=O,o=r;else{let k,p;for(const{combo:g,leaves:[N]}of a){const{type:S}=N,d=(0,v.unescapeSelector)(N.name);if(S===h.SELECTOR_PSEUDO_CLASS&&d==="dir"){k=!1;break}if(g&&!p){const{name:m}=g;/^[+~]$/.test(m)&&(k=!0,p=!0)}}k?(n=C,o=t):(n=O,o=r)}}else n=O,o=t;return{complex:i,dir:n,twig:o}}_collectNodes(a){const e=this.#a.values();if(a===L||a===$){const c=new Set;let i=0;for(const{branch:t}of e){const{complex:n,dir:o,twig:f}=this._getEntryTwig(t,a),{compound:l,filtered:s,nodes:r,pending:u}=this._findEntryNodes(f,a,n);r.length?(this.#a[i].find=!0,this.#n[i]=r):u&&c.add(new Map([["index",i],["twig",f]])),this.#a[i].dir=o,this.#a[i].filtered=s||!l,i++}if(c.size){let t,n;this.#e!==this.#s&&this.#e.nodeType===h.ELEMENT_NODE?(t=this.#e,n=this.#r):(t=this.#s,n=this.#d);let o=this._traverse(t,n);for(;o;){let f=!1;if(this.#e.nodeType===h.ELEMENT_NODE?o===this.#e?f=!0:f=this.#e.contains(o):f=!0,f)for(const l of c){const{leaves:s}=l.get("twig");if(this._matchLeaves(s,o,{warn:this.#i})){const u=l.get("index");this.#a[u].filtered=!0,this.#a[u].find=!0,this.#n[u].push(o)}}o=n.nextNode()}}}else{let c=0;for(const{branch:i}of e){const t=i[i.length-1],n=i.length>1,{compound:o,filtered:f,nodes:l}=this._findEntryNodes(t,a,n);l.length&&(this.#a[c].find=!0,this.#n[c]=l),this.#a[c].dir=O,this.#a[c].filtered=f||!o,c++}}return[this.#a,this.#n]}_matchNodes(a){const[...e]=this.#a,c=e.length;let i=new Set;for(let t=0;t<c;t++){const{branch:n,dir:o,filtered:f,find:l}=e[t],s=n.length;if(s&&l){const r=this.#n[t],u=r.length,b=s-1;if(b===0){const{leaves:[,...k]}=n[0];if((a===L||a===$)&&this.#e.nodeType===h.ELEMENT_NODE)for(let p=0;p<u;p++){const g=r[p];if(g!==this.#e&&this.#e.contains(g)&&(i.add(g),a!==L))break}else if(k.length)for(let p=0;p<u;p++){const g=r[p];if((f||this._matchLeaves(k,g,{warn:this.#i}))&&(i.add(g),a!==L))break}else if(a===L)if(i.size){const p=[...i];i=new Set([...p,...r]),this.#o=!0}else i=new Set([...r]);else{const[p]=[...r];i.add(p)}}else if(o===C){let{combo:k,leaves:p}=n[0],g;for(let N=0;N<u;N++){const S=r[N];let d=new Set([S]);for(let m=1;m<s;m++){const{combo:w,leaves:_}=n[m],y=[];for(const E of d){const A={combo:k,leaves:_},D=this._matchCombinator(A,E,{dir:o,warn:this.#i});D.size&&y.push(...D)}if(y.length)if(m===b){if(a===L){if(i.size){const E=[...i];i=new Set([...E,...y])}else i=new Set([...y]);this.#o=!0}else{const[E]=(0,x.sortNodes)(y);i.add(E)}g=!0}else k=w,d=new Set(y),g=!1;else{g=!1;break}}if(g&&a!==L)break}if(!g&&a===$){const[N]=[...r];let S=this._findNode(p,{node:N});for(;S;){let d=new Set([S]);for(let m=1;m<s;m++){const{combo:w,leaves:_}=n[m],y=[];for(const E of d){const A={combo:k,leaves:_},D=this._matchCombinator(A,E,{dir:o,warn:this.#i});D.size&&y.push(...D)}if(y.length)if(m===b){const[E]=(0,x.sortNodes)(y);i.add(E),g=!0}else k=w,d=new Set(y),g=!1;else{g=!1;break}}if(g)break;S=this._findNode(p,{node:S}),d=new Set([S])}}}else{const{leaves:k}=n[b];let p;for(let g=0;g<u;g++){const N=r[g];let S=new Set([N]);for(let d=b-1;d>=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0,a===L&&s>1&&i.size>1&&(this.#o=!0)):(S=new Set(w),p=!1);else{p=!1;break}}if(p&&a!==L)break}if(!p&&a===$){const[g]=[...r];let N=this._findNode(k,{node:g});for(;N;){let S=new Set([N]);for(let d=b-1;d>=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0):(S=new Set(w),p=!1);else{p=!1;break}}if(p)break;N=this._findNode(k,{node:N}),S=new Set([N])}}}}}return i}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==h.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}i=this._find(P).size}catch(t){this._onError(t)}return!!i}closest(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==h.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}const t=this._find(M);if(t.size){let n=this.#e;for(;n;){if(t.has(n)){i=n;break}n=n.parentNode}}}catch(t){this._onError(t)}return i??null}querySelector(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find($);t.delete(this.#e),t.size&&([i]=(0,x.sortNodes)(t))}catch(t){this._onError(t)}return i??null}querySelectorAll(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find(L);t.delete(this.#e),t.size&&(this.#o?i=(0,x.sortNodes)(t):i=[...t])}catch(t){this._onError(t)}return i??[]}}0&&(module.exports={Finder});
//# sourceMappingURL=finder.js.map

@@ -43,3 +43,3 @@ {

"eslint-plugin-unicorn": "^50.0.1",
"happy-dom": "^13.3.5",
"happy-dom": "^13.3.8",
"jsdom": "24.0.0",

@@ -63,3 +63,3 @@ "linkedom": "^0.16.8",

},
"version": "3.0.2"
"version": "3.0.3"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc