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 4.1.6 to 4.1.7

2

dist/cjs/js/finder.js

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

var W=Object.create;var P=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(E,a)=>{for(var e in a)P(E,e,{get:a[e],enumerable:!0})},U=(E,a,e,n)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of B(a))!G.call(E,l)&&l!==e&&P(E,l,{get:()=>a[l],enumerable:!(n=H(a,l))||n.enumerable});return E};var z=(E,a,e)=>(e=E!=null?W(j(E)):{},U(a||!E||!E.__esModule?P(e,"default",{value:E,enumerable:!0}):e,E)),V=E=>U(P({},"__esModule",{value:!0}),E);var Y={};q(Y,{Finder:()=>X});module.exports=V(Y);var I=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),y=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",A="first",R="lineal",D="self";class X{#a;#l;#t;#o;#f;#e;#h;#w;#c;#n;#m;#s;#d;#b;#r;#u;#i;#p;constructor(a){this.#p=a,this.#f=a.document,this.#l=new WeakMap,this.#m=new WeakMap,this.#c=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#c.configure({LOGERRORS:!1})}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#p.DOMException)if(a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#p.DOMException(a.message,a.name);else throw a}_setup(a,e,n={}){const{noexcept:l,warn:s}=n;return this.#w=!!l,this.#i=!!s,this.#e=e,[this.#t,this.#s,this.#r]=(0,C.resolveContent)(e),this.#d=(0,C.isInShadowTree)(e),[this.#a,this.#h]=this._correspond(a),this.#u=new WeakMap,e}_correspond(a){const e=[];this.#o=!1;let n;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${a}`)){const s=l.get(`${a}`);this.#o=s.descendant,n=s.ast}}if(n){const l=n.length;for(let s=0;s<l;s++)n[s].collected=!1,n[s].dir=null,n[s].filtered=!1,n[s].find=!1,e[s]=[]}else{let l;try{l=(0,y.parseSelector)(a)}catch(d){this._onError(d)}const s=(0,y.walkAST)(l);let c=!1,r=0;n=[];for(const[...d]of s){const f=[];let t=d.shift();if(t&&t.type!==b.COMBINATOR){const i=new Set;for(;t;){if(t.type===b.COMBINATOR){const[o]=d;if(o.type===b.COMBINATOR){const _=`Invalid selector ${a}`;throw new DOMException(_,b.SYNTAX_ERR)}const m=t.name;/^[\s>]$/.test(m)&&(c=!0),f.push({combo:t,leaves:(0,y.sortAST)(i)}),i.clear()}else if(t){let{name:o}=t;o&&typeof o=="string"&&(o=(0,y.unescapeSelector)(o),typeof o=="string"&&o!==t.name&&(t.name=o),/[|:]/.test(o)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{f.push({combo:null,leaves:(0,y.sortAST)(i)}),i.clear();break}}}n.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[r]=[],r++}if(this.#t){let d;this.#l.has(this.#t)?d=this.#l.get(this.#t):d=new Map,d.set(`${a}`,{ast:n,descendant:c}),this.#l.set(this.#t,d)}this.#o=c}return[n,e]}_createTreeWalker(a){let e;return this.#u.has(a)?e=this.#u.get(a):(e=this.#f.createTreeWalker(a,b.WALKER_FILTER),this.#u.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#n=this._createTreeWalker(this.#e),this.#b=!1,this.#n}_traverse(a,e=this.#r){let n=e.currentNode,l;if(n===a)l=n;else if(n.contains(a))for(n=e.nextNode();n;){if(n===a){l=n;break}n=e.nextNode()}else{if(n!==e.root)for(;n&&!(n===e.root||n===a);)n=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;n;){if(n===a){l=n;break}n=e.nextNode()}else l=n}return l??null}_collectNthChild(a,e,n){const{a:l,b:s,reverse:c,selector:r}=a,{parentNode:d}=e,f=new Set;let t;if(r&&(this.#l.has(r)?t=this.#l.get(r):(t=(0,y.walkAST)(r),this.#l.set(r,t))),d){const i=this.#r;let o=this._traverse(d,i);o=i.firstChild();let m=0;for(;o;)m++,o=i.nextSibling();o=this._traverse(d,i);const _=new Set;if(t)for(o=i.firstChild();o;){let u;for(const N of t)if(u=this._matchLeaves(N,o,n),!u)break;u&&_.add(o),o=i.nextSibling()}if(l===0){if(s>0&&s<=m){if(_.size){o=this._traverse(d,i),c?o=i.lastChild():o=i.firstChild();let u=0;for(;o;){if(_.has(o)){if(u===s-1){f.add(o);break}u++}c?o=i.previousSibling():o=i.nextSibling()}}else if(!r){o=this._traverse(d,i),c?o=i.lastChild():o=i.firstChild();let u=0;for(;o;){if(u===s-1){f.add(o);break}c?o=i.previousSibling():o=i.nextSibling(),u++}}}}else{let u=s-1;if(l>0)for(;u<0;)u+=l;if(u>=0&&u<m){o=this._traverse(d,i),c?o=i.lastChild():o=i.firstChild();let N=0,k=l>0?0:s-1;for(;o&&(o&&u>=0&&u<m);)_.size?_.has(o)&&(k===u&&(f.add(o),u+=l),l>0?k++:k--):N===u&&(r||f.add(o),u+=l),c?o=i.previousSibling():o=i.nextSibling(),N++}}if(c&&f.size>1){const u=[...f];return new Set(u.reverse())}}else if(e===this.#s&&l+s===1)if(t){let i;for(const o of t)if(i=this._matchLeaves(o,e,n),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:n,b:l,reverse:s}=a,{localName:c,parentNode:r,prefix:d}=e,f=new Set;if(r){const t=this.#r;let i=this._traverse(r,t);i=t.firstChild();let o=0;for(;i;)o++,i=t.nextSibling();if(n===0){if(l>0&&l<=o){i=this._traverse(r,t),s?i=t.lastChild():i=t.firstChild();let m=0;for(;i;){const{localName:_,prefix:u}=i;if(_===c&&u===d){if(m===l-1){f.add(i);break}m++}s?i=t.previousSibling():i=t.nextSibling()}}}else{let m=l-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m<o){i=this._traverse(r,t),s?i=t.lastChild():i=t.firstChild();let _=n>0?0:l-1;for(;i;){const{localName:u,prefix:N}=i;if(u===c&&N===d){if(_===m&&(f.add(i),m+=n),m<0||m>=o)break;n>0?_++:_--}s?i=t.previousSibling():i=t.nextSibling()}}}if(s&&f.size>1){const m=[...f];return new Set(m.reverse())}}else e===this.#s&&n+l===1&&f.add(e);return f}_matchAnPlusB(a,e,n,l){const{nth:{a:s,b:c,name:r},selector:d}=a,f=new Map;if(r?(r==="even"?(f.set("a",2),f.set("b",0)):r==="odd"&&(f.set("a",2),f.set("b",1)),n.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof c=="string"&&/-?\d+/.test(c)?f.set("b",c*1):f.set("b",0),n.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(n)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(n)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,n={}){let l;if(Array.isArray(a)&&a.length){const[s]=a,{type:c}=s;let r;c===b.COMBINATOR?r=a.shift():r={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[i]=a,{type:o}=i;if(o===b.COMBINATOR)break;d.push(a.shift())}const f={combo:r,leaves:d};n.dir=T;const t=this._matchCombinator(f,e,n);if(t.size)if(a.length){for(const i of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),i,n),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,n={}){const{astName:l="",branches:s=[],selector:c="",twigBranches:r=[]}=a;let d;if(l==="has")if(c.includes(":has("))d=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,n),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);n.forgive=f;const t=r.length;let i;for(let o=0;o<t;o++){const m=r[o],_=m.length-1,{leaves:u}=m[_];if(i=this._matchLeaves(u,e,n),i&&_>0){let N=new Set([e]);for(let k=_-1;k>=0;k--){const g=m[k],h=[];n.dir=O;for(const p of N){const w=this._matchCombinator(g,p,n);w.size&&h.push(...w)}if(h.length)k===0?i=!0:N=new Set(h);else{i=!1;break}}}if(i)break}l==="not"?i||(d=e):i&&(d=e)}return d??null}_matchPseudoClassSelector(a,e,n={}){const{children:l,name:s}=a,{localName:c,parentNode:r}=e,{forgive:d,warn:f=this.#i}=n,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let i;if(this.#l.has(a))i=this.#l.get(a);else{const m=(0,y.walkAST)(a),_=[],u=[];for(const[...N]of m){for(const p of N){const w=(0,y.generateCSS)(p);_.push(w)}const k=[],g=new Set;let h=N.shift();for(;h;)if(h.type===b.COMBINATOR?(k.push({combo:h,leaves:[...g]}),g.clear()):h&&g.add(h),N.length)h=N.shift();else{k.push({combo:null,leaves:[...g]}),g.clear();break}u.push(k)}i={astName:s,branches:m,twigBranches:u,selector:_.join(",")},this.#l.set(a,i)}const o=this._matchLogicalPseudoFunc(i,e,n);o&&t.add(o)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[i]=l;return this._matchAnPlusB(i,e,s,n)}else switch(s){case"dir":case"lang":{const i=$.matcher.matchSelector(a,e);i&&t.add(i);break}case"current":case"nth-col":case"nth-last-col":{if(f){const i=`Unsupported pseudo-class :${s}()`;throw new DOMException(i,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!d){const i=`Unknown pseudo-class :${s}()`;throw new DOMException(i,b.SYNTAX_ERR)}}else{const i=/^a(?:rea)?$/,o=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,m=/^(?:(?:inpu|selec)t|button|form|textarea)$/,_=/^d(?:etails|ialog)$/,u=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,k=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,g=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(s){case"any-link":case"link":{i.test(c)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(c)&&e.hasAttribute("href")){const{href:h,origin:p,pathname:w}=new URL(this.#t.URL),S=new URL(e.getAttribute("href"),h);S.origin===p&&S.pathname===w&&t.add(e)}break}case"visited":break;case"target":{const{hash:h}=new URL(this.#t.URL);e.id&&h===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:h}=new URL(this.#t.URL);if(h){const p=h.replace(/^#/,"");let w=this.#t.getElementById(p);for(;w;){if(w===e){t.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#d&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":{if(e===this.#t.activeElement){let h=e,p=!0;for(;h;){if(h.disabled||h.hasAttribute("disabled")||h.hidden||h.hasAttribute("hidden")){p=!1;break}else if(h.hasAttribute("style")){const{display:w,visibility:S}=h.style;if(p=!(w==="none"||S==="hidden"),!p)break}if(h.parentNode&&h.parentNode.nodeType===b.ELEMENT_NODE)h=h.parentNode;else break}p&&t.add(e)}break}case"focus-within":{let h=this.#t.activeElement,p;for(;h;){if(h===e){p=!0;break}h=h.parentNode}if(p){let w=e,S=!0;for(;w;){if(w.disabled||w.hasAttribute("disabled")||w.hidden||w.hasAttribute("hidden")){S=!1;break}else if(w.hasAttribute("style")){const{display:v,visibility:L}=w.style;if(S=!(v==="none"||L==="hidden"),!S)break}if(w.parentNode&&w.parentNode.nodeType===b.ELEMENT_NODE)w=w.parentNode;else break}S&&t.add(e)}break}case"open":{_.test(c)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(c)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(o.test(c)||(0,I.default)(c))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=r;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&r.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(o.test(c)||(0,I.default)(c))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(c){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(c){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let h;c==="textarea"?h=e:c==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(h=e):h=e),h&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&c==="input"&&e.hasAttribute("type")&&u.test(e.getAttribute("type"))||e.selected&&c==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&c==="input"&&e.type==="checkbox"||c==="progress"&&!e.hasAttribute("value"))t.add(e);else if(c==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const h=e.name;let p=e.parentNode;for(;p&&p.localName!=="form";)p=p.parentNode;p||(p=this.#t.documentElement);const w=p.getElementsByTagName("input"),S=w.length;let v;for(let L=0;L<S;L++){const x=w[L];if(x.getAttribute("type")==="radio"&&(h?x.getAttribute("name")===h&&(v=!!x.checked):x.hasAttribute("name")||(v=!!x.checked),v))break}v||t.add(e)}break}case"default":{const h=/^(?:button|reset)$/,p=/^(?:image|submit)$/;if(c==="button"&&!(e.hasAttribute("type")&&h.test(e.getAttribute("type")))||c==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))){let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;if(w){const S=this.#r;let v=this._traverse(w,S);for(v=S.firstChild();v&&w.contains(v);){const L=v.localName;let x;if(L==="button"?x=!(v.hasAttribute("type")&&h.test(v.getAttribute("type"))):L==="input"&&(x=v.hasAttribute("type")&&p.test(v.getAttribute("type"))),x){v===e&&t.add(e);break}v=S.nextNode()}}}else if(c==="input"&&e.hasAttribute("type")&&u.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(c==="option"){let w=r,S=!1;for(;w&&w.localName!=="datalist";){if(w.localName==="select"){(w.multiple||w.hasAttribute("multiple"))&&(S=!0);break}w=w.parentNode}if(S)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,L=this.#r;let x=this._traverse(r,L);for(x=L.firstChild();x;){if(x.selected||x.hasAttribute("selected")){v.add(x);break}x=L.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(m.test(c))e.checkValidity()&&t.add(e);else if(c==="fieldset"){const h=this.#r;let p=this._traverse(e,h);p=h.firstChild();let w;for(;p&&e.contains(p)&&!(m.test(p.localName)&&(w=p.checkValidity(),!w));)p=h.nextNode();w&&t.add(e)}break}case"invalid":{if(m.test(c))e.checkValidity()||t.add(e);else if(c==="fieldset"){const h=this.#r;let p=this._traverse(e,h);p=h.firstChild();let w;for(;p&&e.contains(p)&&!(m.test(p.localName)&&(w=p.checkValidity(),!w));)p=h.nextNode();w||t.add(e)}break}case"in-range":{c==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{c==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let h;if(/^(?:select|textarea)$/.test(c))h=e;else if(c==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||u.test(p)||N.test(p)||g.test(p))&&(h=e)}else h=e;h&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let h;if(/^(?:select|textarea)$/.test(c))h=e;else if(c==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||u.test(p)||N.test(p)||g.test(p))&&(h=e)}else h=e;h&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const h=this.#f.createTreeWalker(e,b.SHOW_ALL);let p=h.firstChild(),w;for(;p&&(w=p.nodeType!==b.ELEMENT_NODE&&p.nodeType!==b.TEXT_NODE,!!w);)p=h.nextSibling();w&&t.add(e)}else t.add(e);break}case"first-child":{(r&&e===r.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(r&&e===r.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(r&&e===r.firstElementChild&&e===r.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(r){const[h]=this._collectNthOfType({a:0,b:1},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(r){const[h]=this._collectNthOfType({a:0,b:1,reverse:!0},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(r){const[h]=this._collectNthOfType({a:0,b:1},e);if(h===e){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const h=`Unsupported pseudo-element ::${s}`;throw new DOMException(h,b.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 h=`Unsupported pseudo-class :${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}default:if(s.startsWith("-webkit-")){if(f){const h=`Unsupported pseudo-class :${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}}else if(!d){const h=`Unknown pseudo-class :${s}`;throw new DOMException(h,b.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(a,e){const{children:n,name:l}=a;let s;if(Array.isArray(n)){const[c]=(0,y.walkAST)(n[0]),[...r]=c,{host:d}=e;if(l==="host"){let f;for(const t of r){const{type:i}=t;if(i===b.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(a)}`;throw new DOMException(m,b.SYNTAX_ERR)}if(f=this._matchSelector(t,d).has(d),!f)break}f&&(s=e)}else if(l==="host-context"){let f=d,t;for(;f;){for(const i of r){const{type:o}=i;if(o===b.COMBINATOR){const _=`Invalid selector ${(0,y.generateCSS)(a)}`;throw new DOMException(_,b.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}if(t)break;f=f.parentNode}t&&(s=e)}}else if(l==="host")s=e;else{const c=`Invalid selector :${l}`;throw new DOMException(c,b.SYNTAX_ERR)}return s??null}_matchSelector(a,e,n){const{type:l}=a,s=new Set;if(a.name===b.EMPTY)return s;const c=(0,y.unescapeSelector)(a.name);if(typeof c=="string"&&c!==a.name&&(a.name=c),e.nodeType===b.ELEMENT_NODE)switch(l){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(c,n);break}case b.SELECTOR_ID:{e.id===c&&s.add(e);break}case b.SELECTOR_CLASS:{e.classList.contains(c)&&s.add(e);break}case b.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,n);default:{const r=$.matcher.matchSelector(a,e,n);r&&s.add(r)}}else if(this.#d&&l===b.SELECTOR_PSEUDO_CLASS&&e.nodeType===b.DOCUMENT_FRAGMENT_NODE){if(c!=="has"&&b.REG_LOGICAL_PSEUDO.test(c))return this._matchPseudoClassSelector(a,e,n);if(b.REG_SHADOW_HOST.test(c)){const r=this._matchShadowHostPseudoClass(a,e,n);r&&s.add(r)}}return s}_matchLeaves(a,e,n){const{attributes:l,localName:s,nodeType:c}=e;let r=this.#m.get(a),d;if(r&&r.has(e)){const{attr:f,matched:t}=r.get(e);l?.length===f&&(d=t)}if(typeof d!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;c===b.ELEMENT_NODE&&f.test(s)?t=!1:t=!0;for(const i of a){const{name:o,type:m}=i;if(m===b.SELECTOR_PSEUDO_CLASS&&o==="dir"&&(t=!1),d=this._matchSelector(i,e,n).has(e),!d)break}t&&(r||(r=new WeakMap),r.set(e,{attr:l?.length,matched:d}),this.#m.set(a,r))}return!!d}_matchHTMLCollection(a,e={}){const{compound:n,filterLeaves:l}=e,s=new Set,c=a.length;if(c)if(n)for(let r=0;r<c;r++){const d=a[r];this._matchLeaves(l,d,e)&&s.add(d)}else{const r=[].slice.call(a);return new Set(r)}return s}_findDescendantNodes(a,e,n){const[l,...s]=a,c=s.length>0,{type:r}=l,d=(0,y.unescapeSelector)(l.name);typeof d=="string"&&d!==l.name&&(l.name=d);let f=new Set,t=!1;if(this.#d)t=!0;else switch(r){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,n);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const i=this.#s.getElementById(d);i&&i!==e&&e.contains(i)&&(c?this._matchLeaves(s,i,n)&&f.add(i):f.add(i))}break}case b.SELECTOR_CLASS:{const i=e.getElementsByClassName(d);f=this._matchHTMLCollection(i,{compound:c,filterLeaves:s});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const i=e.getElementsByTagName(d);f=this._matchHTMLCollection(i,{compound:c,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,n={}){const{combo:l,leaves:s}=a,{name:c}=l,{parentNode:r}=e,{dir:d}=n,f=new Set;if(d===T)switch(c){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,n)&&f.add(t);break}case"~":{if(r){const t=this._createTreeWalker(r);let i=this._traverse(e,t);for(i=t.nextSibling();i;)this._matchLeaves(s,i,n)&&f.add(i),i=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let i=this._traverse(e,t);for(i=t.firstChild();i;)this._matchLeaves(s,i,n)&&f.add(i),i=t.nextSibling();break}case" ":default:{const{nodes:t,pending:i}=this._findDescendantNodes(s,e);if(t.size)return t;if(i){const o=this._createTreeWalker(e);let m=this._traverse(e,o);for(m=o.nextNode();m&&e.contains(m);)this._matchLeaves(s,m,n)&&f.add(m),m=o.nextNode()}}}else switch(c){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,n)&&f.add(t);break}case"~":{if(r){const t=this._createTreeWalker(r);let i=this._traverse(r,t);for(i=t.firstChild();i&&i!==e;)this._matchLeaves(s,i,n)&&f.add(i),i=t.nextSibling()}break}case">":{r&&this._matchLeaves(s,r,n)&&f.add(r);break}case" ":default:{const t=[];let i=r;for(;i;)this._matchLeaves(s,i,n)&&t.push(i),i=i.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:n}=e;let l=this._traverse(n,this.#n),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#n.nextNode():l===n&&l!==this.#s&&(l=this.#n.nextNode());l;){if(this._matchLeaves(a,l,{warn:this.#i})){s=l;break}l=this.#n.nextNode()}return s??null}_matchSelf(a){const e=[],n=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return n&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:n}=e,l=[];let s=this._matchLeaves(a,this.#e,{warn:this.#i}),c=!1;if(s&&(l.push(this.#e),c=!0),!s||n){let r=this.#e.parentNode;for(;r&&(s=this._matchLeaves(a,r,{warn:this.#i}),s&&(l.push(r),c=!0),r.parentNode);)r=r.parentNode}return[l,c]}_findFirst(a){const e=[],n=this._findNode(a,{node:this.#e});let l=!1;return n&&(e.push(n),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:n,compound:l,filterLeaves:s,targetType:c}=e;let r=[],d=!1,f=!1;const t=a.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let i=0;i<t;i++){const o=a[i];if(o!==this.#e&&(this.#e.contains(o)||o.contains(this.#e))){if(l){if(this._matchLeaves(s,o,{warn:this.#i})&&(r.push(o),d=!0,c===A))break}else if(r.push(o),d=!0,c===A)break}}else if(n)if(l)for(let i=0;i<t;i++){const o=a[i];if(this._matchLeaves(s,o,{warn:this.#i})&&(r.push(o),d=!0,c===A))break}else r=[].slice.call(a),d=!0,f=!0;else if(l)for(let i=0;i<t;i++){const o=a[i];if(this._matchLeaves(s,o,{warn:this.#i})&&(r.push(o),d=!0,c===A))break}else r=[].slice.call(a),d=!0,f=!0;return[r,d,f]}_findEntryNodes(a,e,n){const{leaves:l}=a,[s,...c]=l,r=c.length>0,{name:d,type:f}=s;let t=[],i=!1,o=!1,m=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(e===A&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(r?this._matchLeaves(c,_,{warn:this.#i})&&(t.push(_),o=!0):(t.push(_),o=!0))}else e===A?[t,o]=this._findFirst(l):m=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,o,i]=this._findFromHTMLCollection(_,{complex:n,compound:r,filterLeaves:c,targetType:e}))}else e===A?[t,o]=this._findFirst(l):m=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,o,i]=this._findFromHTMLCollection(_,{complex:n,compound:r,filterLeaves:c,targetType:e}))}else e===A?[t,o]=this._findFirst(l):m=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(d)){if(this.#d&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(s,this.#e);_&&(t.push(_),o=!0)}}else e===D?[t,o]=this._matchSelf(l):e===R?[t,o]=this._findLineal(l,{complex:n}):e===A?[t,o]=this._findFirst(l):m=!0}return{collected:i,compound:r,filtered:o,nodes:t,pending:m}}_getEntryTwig(a,e){const n=a.length,l=n>1,s=a[0];let c,r;if(l){const{combo:d,leaves:[{name:f,type:t}]}=s,i=a[n-1],{leaves:[{name:o,type:m}]}=i;if(m===b.SELECTOR_PSEUDO_ELEMENT||m===b.SELECTOR_ID)c=O,r=i;else if(t===b.SELECTOR_PSEUDO_ELEMENT||t===b.SELECTOR_ID)c=T,r=s;else if(e===M)if(f==="*"&&t===b.SELECTOR_TYPE)c=O,r=i;else if(o==="*"&&m===b.SELECTOR_TYPE)c=T,r=s;else if(n===2){const{name:_}=d;/^[+~]$/.test(_)?(c=O,r=i):(c=T,r=s)}else c=T,r=s;else if(o==="*"&&m===b.SELECTOR_TYPE)c=T,r=s;else if(f==="*"&&t===b.SELECTOR_TYPE)c=O,r=i;else{let _;for(const{combo:u,leaves:[N]}of a){const{name:k,type:g}=N;if(g===b.SELECTOR_PSEUDO_CLASS&&k==="dir"){_=!1;break}if(!_&&u){const{name:h}=u;/^[+~]$/.test(h)&&(_=!0)}}_?(c=T,r=s):(c=O,r=i)}}else c=O,r=s;return{complex:l,dir:c,twig:r}}_collectNodes(a){const e=this.#a.values();if(a===M||a===A){const n=new Set;let l=0;for(const{branch:s}of e){const{complex:c,dir:r,twig:d}=this._getEntryTwig(s,a),{collected:f,compound:t,filtered:i,nodes:o,pending:m}=this._findEntryNodes(d,a,c);o.length?(this.#a[l].find=!0,this.#h[l]=o):m&&n.add(new Map([["index",l],["twig",d]])),this.#a[l].collected=f,this.#a[l].dir=r,this.#a[l].filtered=i||!t,l++}if(n.size){let s,c;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,c=this.#n):(s=this.#s,c=this.#r);let r=this._traverse(s,c);for(;r;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?r===this.#e?d=!0:d=this.#e.contains(r):d=!0,d)for(const f of n){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,r,{warn:this.#i})){const o=f.get("index");this.#a[o].filtered=!0,this.#a[o].find=!0,this.#h[o].push(r)}}r!==c.currentNode&&(r=this._traverse(r,c)),r=c.nextNode()}}}else{let n=0;for(const{branch:l}of e){const s=l[l.length-1],c=l.length>1,{compound:r,filtered:d,nodes:f}=this._findEntryNodes(s,a,c);f.length&&(this.#a[n].find=!0,this.#h[n]=f),this.#a[n].dir=O,this.#a[n].filtered=d||!r,n++}}return[this.#a,this.#h]}_getCombinedNodes(a,e,n){const l=[];for(const s of e){const c=this._matchCombinator(a,s,{dir:n,warn:this.#i});c.size&&l.push(...c)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,n){const{combo:l,index:s}=n,{combo:c,leaves:r}=a[s],d={combo:l,leaves:r},f=this._getCombinedNodes(d,e,T);let t;if(f.size)if(s===a.length-1){const[i]=(0,C.sortNodes)(f);t=i}else t=this._matchNodeNext(a,f,{combo:c,index:s+1});return t??null}_matchNodePrev(a,e,n){const{index:l}=n,s=a[l],c=new Set([e]),r=this._getCombinedNodes(s,c,O);let d;if(r.size){if(l===0)d=e;else for(const f of r)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_matchNodes(a){const[[...e],n]=this._collectNodes(a),l=e.length;let s=new Set;for(let c=0;c<l;c++){const{branch:r,collected:d,dir:f,find:t}=e[c],i=r.length;if(i&&t){const o=n[c],m=o.length,_=i-1;if(_===0)if((a===M||a===A)&&this.#e.nodeType===b.ELEMENT_NODE)for(let u=0;u<m;u++){const N=o[u];if(N!==this.#e&&this.#e.contains(N)&&(s.add(N),a!==M))break}else if(a===M)if(s.size){const u=[...s];s=new Set([...u,...o]),this.#b=!0}else s=new Set(o);else{const[u]=o;s.add(u)}else if(a===M)if(f===T){let{combo:u}=r[0];for(const N of o){let k=new Set([N]);for(let g=1;g<i;g++){const{combo:h,leaves:p}=r[g],w={combo:u,leaves:p};if(k=this._getCombinedNodes(w,k,f),k.size)if(g===_)if(s.size){const S=[...s];s=new Set([...S,...k]),this.#b=!0}else s=k;else u=h;else break}}}else for(const u of o){let N=new Set([u]);for(let k=_-1;k>=0;k--){const g=r[k];if(N=this._getCombinedNodes(g,N,f),N.size)k===0&&(s.add(u),i>1&&s.size>1&&(this.#b=!0));else break}}else if(a===A&&f===T){const{combo:u}=r[0];let N;for(const k of o)if(N=this._matchNodeNext(r,new Set([k]),{combo:u,index:1}),N){s.add(N);break}if(!N&&!d){const{leaves:k}=r[0],[g]=o;let h=this._findNode(k,{node:g});for(;h;){if(N=this._matchNodeNext(r,new Set([h]),{combo:u,index:1}),N){s.add(N);break}h=this._findNode(k,{node:h})}}}else{let u;for(const N of o)if(u=this._matchNodePrev(r,N,{index:_-1}),u){s.add(N);break}if(!u&&!d&&a===A){const{leaves:N}=r[_],[k]=o;let g=this._findNode(N,{node:k});for(;g;){if(u=this._matchNodePrev(r,g,{index:_-1}),u){s.add(g);break}g=this._findNode(N,{node:g})}}}}}return s}_find(a){return(a===M||a===A)&&this._prepareQuerySelectorWalker(),this._matchNodes(a)}matches(a,e,n){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,y.filterSelector)(a)?l=this.#c.match(a,e):(this._setup(a,e,n),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(a,e,n){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,y.filterSelector)(a))l=this.#c.closest(a,e);else{this._setup(a,e,n);const s=this._find(R);if(s.size){let c=this.#e;for(;c;){if(s.has(c)){l=c;break}c=c.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(a,e,n){let l;try{if(this._setup(a,e,n),this.#f===this.#t&&!this.#o&&(0,y.filterSelector)(a))l=this.#c.first(a,e);else{const s=this._find(A);s.delete(this.#e),s.size&&([l]=(0,C.sortNodes)(s))}}catch(s){this._onError(s)}return l??null}querySelectorAll(a,e,n){let l;try{if(this._setup(a,e,n),this.#f===this.#t&&!this.#o&&(0,y.filterSelector)(a))l=this.#c.select(a,e);else{const s=this._find(M);s.delete(this.#e),s.size&&(this.#b?l=(0,C.sortNodes)(s):l=[...s])}}catch(s){this._onError(s)}return l??[]}}0&&(module.exports={Finder});
var B=Object.create;var P=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(E,a)=>{for(var e in a)P(E,e,{get:a[e],enumerable:!0})},U=(E,a,e,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of G(a))!V.call(E,l)&&l!==e&&P(E,l,{get:()=>a[l],enumerable:!(r=j(a,l))||r.enumerable});return E};var z=(E,a,e)=>(e=E!=null?B(q(E)):{},U(a||!E||!E.__esModule?P(e,"default",{value:E,enumerable:!0}):e,E)),Y=E=>U(P({},"__esModule",{value:!0}),E);var K={};X(K,{Finder:()=>Q});module.exports=Y(K);var I=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),S=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",A="first",R="lineal",D="self";class Q{#a;#l;#t;#o;#f;#e;#h;#w;#c;#n;#m;#s;#d;#b;#r;#u;#i;#p;constructor(a){this.#p=a,this.#f=a.document,this.#l=new WeakMap,this.#m=new WeakMap,this.#c=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#c.configure({LOGERRORS:!1})}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#p.DOMException)if(a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#p.DOMException(a.message,a.name);else throw a}_setup(a,e,r={}){const{noexcept:l,warn:s}=r;return this.#w=!!l,this.#i=!!s,this.#e=e,[this.#t,this.#s,this.#r]=(0,C.resolveContent)(e),this.#d=(0,C.isInShadowTree)(e),[this.#a,this.#h]=this._correspond(a),this.#u=new WeakMap,e}_correspond(a){const e=[];this.#o=!1;let r;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${a}`)){const s=l.get(`${a}`);this.#o=s.descendant,r=s.ast}}if(r){const l=r.length;for(let s=0;s<l;s++)r[s].collected=!1,r[s].dir=null,r[s].filtered=!1,r[s].find=!1,e[s]=[]}else{let l;try{l=(0,S.parseSelector)(a)}catch(d){this._onError(d)}const s=(0,S.walkAST)(l);let o=!1,n=0;r=[];for(const[...d]of s){const f=[];let t=d.shift();if(t&&t.type!==b.COMBINATOR){const i=new Set;for(;t;){if(t.type===b.COMBINATOR){const[c]=d;if(c.type===b.COMBINATOR){const _=`Invalid selector ${a}`;throw new DOMException(_,b.SYNTAX_ERR)}const w=t.name;/^[\s>]$/.test(w)&&(o=!0),f.push({combo:t,leaves:(0,S.sortAST)(i)}),i.clear()}else if(t){let{name:c}=t;c&&typeof c=="string"&&(c=(0,S.unescapeSelector)(c),typeof c=="string"&&c!==t.name&&(t.name=c),/[|:]/.test(c)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{f.push({combo:null,leaves:(0,S.sortAST)(i)}),i.clear();break}}}r.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#t){let d;this.#l.has(this.#t)?d=this.#l.get(this.#t):d=new Map,d.set(`${a}`,{ast:r,descendant:o}),this.#l.set(this.#t,d)}this.#o=o}return[r,e]}_createTreeWalker(a){let e;return this.#u.has(a)?e=this.#u.get(a):(e=this.#f.createTreeWalker(a,b.WALKER_FILTER),this.#u.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#n=this._createTreeWalker(this.#e),this.#b=!1,this.#n}_traverse(a,e=this.#r){let r=e.currentNode,l;if(r===a)l=r;else if(r.contains(a))for(r=e.nextNode();r;){if(r===a){l=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===a);)r=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;r;){if(r===a){l=r;break}r=e.nextNode()}else l=r}return l??null}_collectNthChild(a,e,r){const{a:l,b:s,reverse:o,selector:n}=a,{parentNode:d}=e,f=new Set;let t;if(n&&(this.#l.has(n)?t=this.#l.get(n):(t=(0,S.walkAST)(n),this.#l.set(n,t))),d){const i=this.#r;let c=this._traverse(d,i);c=i.firstChild();let w=0;for(;c;)w++,c=i.nextSibling();c=this._traverse(d,i);const _=new Set;if(t)for(c=i.firstChild();c;){let m;for(const N of t)if(m=this._matchLeaves(N,c,r),!m)break;m&&_.add(c),c=i.nextSibling()}if(l===0){if(s>0&&s<=w){if(_.size){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(_.has(c)){if(m===s-1){f.add(c);break}m++}o?c=i.previousSibling():c=i.nextSibling()}}else if(!n){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(m===s-1){f.add(c);break}o?c=i.previousSibling():c=i.nextSibling(),m++}}}}else{let m=s-1;if(l>0)for(;m<0;)m+=l;if(m>=0&&m<w){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let N=0,k=l>0?0:s-1;for(;c&&(c&&m>=0&&m<w);)_.size?_.has(c)&&(k===m&&(f.add(c),m+=l),l>0?k++:k--):N===m&&(n||f.add(c),m+=l),o?c=i.previousSibling():c=i.nextSibling(),N++}}if(o&&f.size>1){const m=[...f];return new Set(m.reverse())}}else if(e===this.#s&&l+s===1)if(t){let i;for(const c of t)if(i=this._matchLeaves(c,e,r),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:r,b:l,reverse:s}=a,{localName:o,parentNode:n,prefix:d}=e,f=new Set;if(n){const t=this.#r;let i=this._traverse(n,t);i=t.firstChild();let c=0;for(;i;)c++,i=t.nextSibling();if(r===0){if(l>0&&l<=c){i=this._traverse(n,t),s?i=t.lastChild():i=t.firstChild();let w=0;for(;i;){const{localName:_,prefix:m}=i;if(_===o&&m===d){if(w===l-1){f.add(i);break}w++}s?i=t.previousSibling():i=t.nextSibling()}}}else{let w=l-1;if(r>0)for(;w<0;)w+=r;if(w>=0&&w<c){i=this._traverse(n,t),s?i=t.lastChild():i=t.firstChild();let _=r>0?0:l-1;for(;i;){const{localName:m,prefix:N}=i;if(m===o&&N===d){if(_===w&&(f.add(i),w+=r),w<0||w>=c)break;r>0?_++:_--}s?i=t.previousSibling():i=t.nextSibling()}}}if(s&&f.size>1){const w=[...f];return new Set(w.reverse())}}else e===this.#s&&r+l===1&&f.add(e);return f}_matchAnPlusB(a,e,r,l){const{nth:{a:s,b:o,name:n},selector:d}=a,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?f.set("b",o*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,r={}){let l;if(Array.isArray(a)&&a.length){const[s]=a,{type:o}=s;let n;o===b.COMBINATOR?n=a.shift():n={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[i]=a,{type:c}=i;if(c===b.COMBINATOR)break;d.push(a.shift())}const f={combo:n,leaves:d};r.dir=T;const t=this._matchCombinator(f,e,r);if(t.size)if(a.length){for(const i of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),i,r),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,r={}){const{astName:l="",branches:s=[],selector:o="",twigBranches:n=[]}=a;let d;if(l==="has")if(o.includes(":has("))d=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);r.forgive=f;const t=n.length;let i;for(let c=0;c<t;c++){const w=n[c],_=w.length-1,{leaves:m}=w[_];if(i=this._matchLeaves(m,e,r),i&&_>0){let N=new Set([e]);for(let k=_-1;k>=0;k--){const g=w[k],h=[];r.dir=O;for(const p of N){const u=this._matchCombinator(g,p,r);u.size&&h.push(...u)}if(h.length)k===0?i=!0:N=new Set(h);else{i=!1;break}}}if(i)break}l==="not"?i||(d=e):i&&(d=e)}return d??null}_matchPseudoClassSelector(a,e,r={}){const{children:l,name:s}=a,{localName:o,parentNode:n}=e,{forgive:d,warn:f=this.#i}=r,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let i;if(this.#l.has(a))i=this.#l.get(a);else{const w=(0,S.walkAST)(a),_=[],m=[];for(const[...N]of w){for(const p of N){const u=(0,S.generateCSS)(p);_.push(u)}const k=[],g=new Set;let h=N.shift();for(;h;)if(h.type===b.COMBINATOR?(k.push({combo:h,leaves:[...g]}),g.clear()):h&&g.add(h),N.length)h=N.shift();else{k.push({combo:null,leaves:[...g]}),g.clear();break}m.push(k)}i={astName:s,branches:w,twigBranches:m,selector:_.join(",")},this.#l.set(a,i)}const c=this._matchLogicalPseudoFunc(i,e,r);c&&t.add(c)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[i]=l;return this._matchAnPlusB(i,e,s,r)}else switch(s){case"dir":case"lang":{const i=$.matcher.matchSelector(a,e);i&&t.add(i);break}case"current":case"nth-col":case"nth-last-col":{if(f){const i=`Unsupported pseudo-class :${s}()`;throw new DOMException(i,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!d){const i=`Unknown pseudo-class :${s}()`;throw new DOMException(i,b.SYNTAX_ERR)}}else{const i=/^a(?:rea)?$/,c=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,w=/^(?:(?:inpu|selec)t|button|form|textarea)$/,_=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,k=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,g=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(s){case"any-link":case"link":{i.test(o)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(o)&&e.hasAttribute("href")){const{href:h,origin:p,pathname:u}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),h);y.origin===p&&y.pathname===u&&t.add(e)}break}case"visited":break;case"target":{const{hash:h}=new URL(this.#t.URL);e.id&&h===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:h}=new URL(this.#t.URL);if(h){const p=h.replace(/^#/,"");let u=this.#t.getElementById(p);for(;u;){if(u===e){t.add(e);break}u=u.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#d&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":{if(e===this.#t.activeElement){let h=e,p=!0;for(;h;){if(h.disabled||h.hasAttribute("disabled")||h.hidden||h.hasAttribute("hidden")){p=!1;break}else if(h.hasAttribute("style")){const{display:u,visibility:y}=h.style;if(p=!(u==="none"||y==="hidden"),!p)break}if(h.parentNode&&h.parentNode.nodeType===b.ELEMENT_NODE)h=h.parentNode;else break}p&&t.add(e)}break}case"focus-within":{let h=this.#t.activeElement,p;for(;h;){if(h===e){p=!0;break}h=h.parentNode}if(p){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else if(u.hasAttribute("style")){const{display:v,visibility:L}=u.style;if(y=!(v==="none"||L==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"open":{_.test(o)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(o)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(c.test(o)||(0,I.default)(o))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=n;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&n.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(c.test(o)||(0,I.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let h;o==="textarea"?h=e:o==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(h=e):h=e),h&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&o==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))t.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const h=e.name;let p=e.parentNode;for(;p&&p.localName!=="form";)p=p.parentNode;p||(p=this.#t.documentElement);const u=p.getElementsByTagName("input"),y=u.length;let v;for(let L=0;L<y;L++){const x=u[L];if(x.getAttribute("type")==="radio"&&(h?x.getAttribute("name")===h&&(v=!!x.checked):x.hasAttribute("name")||(v=!!x.checked),v))break}v||t.add(e)}break}case"default":{const h=/^(?:button|reset)$/,p=/^(?:image|submit)$/;if(o==="button"&&!(e.hasAttribute("type")&&h.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))){let u=e.parentNode;for(;u&&u.localName!=="form";)u=u.parentNode;if(u){const y=this.#r;let v=this._traverse(u,y);for(v=y.firstChild();v&&u.contains(v);){const L=v.localName;let x;if(L==="button"?x=!(v.hasAttribute("type")&&h.test(v.getAttribute("type"))):L==="input"&&(x=v.hasAttribute("type")&&p.test(v.getAttribute("type"))),x){v===e&&t.add(e);break}v=y.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(o==="option"){let u=n,y=!1;for(;u&&u.localName!=="datalist";){if(u.localName==="select"){(u.multiple||u.hasAttribute("multiple"))&&(y=!0);break}u=u.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,L=this.#r;let x=this._traverse(n,L);for(x=L.firstChild();x;){if(x.selected||x.hasAttribute("selected")){v.add(x);break}x=L.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(w.test(o))e.checkValidity()&&t.add(e);else if(o==="fieldset"){const h=this.#r;let p=this._traverse(e,h);p=h.firstChild();let u;for(;p&&e.contains(p)&&!(w.test(p.localName)&&(u=p.checkValidity(),!u));)p=h.nextNode();u&&t.add(e)}break}case"invalid":{if(w.test(o))e.checkValidity()||t.add(e);else if(o==="fieldset"){const h=this.#r;let p=this._traverse(e,h);p=h.firstChild();let u;for(;p&&e.contains(p)&&!(w.test(p.localName)&&(u=p.checkValidity(),!u));)p=h.nextNode();u||t.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let h;if(/^(?:select|textarea)$/.test(o))h=e;else if(o==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||m.test(p)||N.test(p)||g.test(p))&&(h=e)}else h=e;h&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let h;if(/^(?:select|textarea)$/.test(o))h=e;else if(o==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||m.test(p)||N.test(p)||g.test(p))&&(h=e)}else h=e;h&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const h=this.#f.createTreeWalker(e,b.SHOW_ALL);let p=h.firstChild(),u;for(;p&&(u=p.nodeType!==b.ELEMENT_NODE&&p.nodeType!==b.TEXT_NODE,!!u);)p=h.nextSibling();u&&t.add(e)}else t.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1,reverse:!0},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);if(h===e){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const h=`Unsupported pseudo-element ::${s}`;throw new DOMException(h,b.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 h=`Unsupported pseudo-class :${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}default:if(s.startsWith("-webkit-")){if(f){const h=`Unsupported pseudo-class :${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}}else if(!d){const h=`Unknown pseudo-class :${s}`;throw new DOMException(h,b.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(a,e){const{children:r,name:l}=a;let s;if(Array.isArray(r)){const[o]=(0,S.walkAST)(r[0]),[...n]=o,{host:d}=e;if(l==="host"){let f;for(const t of n){const{type:i}=t;if(i===b.COMBINATOR){const w=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(w,b.SYNTAX_ERR)}if(f=this._matchSelector(t,d).has(d),!f)break}f&&(s=e)}else if(l==="host-context"){let f=d,t;for(;f;){for(const i of n){const{type:c}=i;if(c===b.COMBINATOR){const _=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(_,b.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}if(t)break;f=f.parentNode}t&&(s=e)}}else if(l==="host")s=e;else{const o=`Invalid selector :${l}`;throw new DOMException(o,b.SYNTAX_ERR)}return s??null}_matchSelector(a,e,r){const{type:l}=a,s=new Set;if(a.name===b.EMPTY)return s;const o=(0,S.unescapeSelector)(a.name);if(typeof o=="string"&&o!==a.name&&(a.name=o),e.nodeType===b.ELEMENT_NODE)switch(l){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(o,r);break}case b.SELECTOR_ID:{e.id===o&&s.add(e);break}case b.SELECTOR_CLASS:{e.classList.contains(o)&&s.add(e);break}case b.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,r);default:{const n=$.matcher.matchSelector(a,e,r);n&&s.add(n)}}else if(this.#d&&l===b.SELECTOR_PSEUDO_CLASS&&e.nodeType===b.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&b.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(a,e,r);if(b.REG_SHADOW_HOST.test(o)){const n=this._matchShadowHostPseudoClass(a,e,r);n&&s.add(n)}}return s}_matchLeaves(a,e,r){const{attributes:l,localName:s,nodeType:o}=e;let n=this.#m.get(a),d;if(n&&n.has(e)){const{attr:f,matched:t}=n.get(e);l?.length===f&&(d=t)}if(typeof d!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;o===b.ELEMENT_NODE&&f.test(s)?t=!1:t=!0;for(const i of a){const{name:c,type:w}=i;if(w===b.SELECTOR_PSEUDO_CLASS&&c==="dir"&&(t=!1),d=this._matchSelector(i,e,r).has(e),!d)break}t&&(n||(n=new WeakMap),n.set(e,{attr:l?.length,matched:d}),this.#m.set(a,n))}return!!d}_matchHTMLCollection(a,e={}){const{compound:r,filterLeaves:l}=e,s=new Set,o=a.length;if(o)if(r)for(let n=0;n<o;n++){const d=a[n];this._matchLeaves(l,d,e)&&s.add(d)}else{const n=[].slice.call(a);return new Set(n)}return s}_findDescendantNodes(a,e,r){const[l,...s]=a,o=s.length>0,{type:n}=l,d=(0,S.unescapeSelector)(l.name);typeof d=="string"&&d!==l.name&&(l.name=d);let f=new Set,t=!1;if(this.#d)t=!0;else switch(n){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,r);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const i=this.#s.getElementById(d);i&&i!==e&&e.contains(i)&&(o?this._matchLeaves(s,i,r)&&f.add(i):f.add(i))}break}case b.SELECTOR_CLASS:{const i=e.getElementsByClassName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const i=e.getElementsByTagName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,r={}){const{combo:l,leaves:s}=a,{name:o}=l,{parentNode:n}=e,{dir:d}=r,f=new Set;if(d===T)switch(o){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(e,t);for(i=t.nextSibling();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let i=this._traverse(e,t);for(i=t.firstChild();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling();break}case" ":default:{const{nodes:t,pending:i}=this._findDescendantNodes(s,e);if(t.size)return t;if(i){const c=this._createTreeWalker(e);let w=this._traverse(e,c);for(w=c.nextNode();w&&e.contains(w);)this._matchLeaves(s,w,r)&&f.add(w),w=c.nextNode()}}}else switch(o){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(n,t);for(i=t.firstChild();i&&i!==e;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{n&&this._matchLeaves(s,n,r)&&f.add(n);break}case" ":default:{const t=[];let i=n;for(;i;)this._matchLeaves(s,i,r)&&t.push(i),i=i.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:r}=e;let l=this._traverse(r,this.#n),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#n.nextNode():l===r&&l!==this.#s&&(l=this.#n.nextNode());l;){if(this._matchLeaves(a,l,{warn:this.#i})){s=l;break}l=this.#n.nextNode()}return s??null}_matchSelf(a){const e=[],r=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return r&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:r}=e,l=[];let s=this._matchLeaves(a,this.#e,{warn:this.#i}),o=!1;if(s&&(l.push(this.#e),o=!0),!s||r){let n=this.#e.parentNode;for(;n&&(s=this._matchLeaves(a,n,{warn:this.#i}),s&&(l.push(n),o=!0),n.parentNode);)n=n.parentNode}return[l,o]}_findFirst(a){const e=[],r=this._findNode(a,{node:this.#e});let l=!1;return r&&(e.push(r),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:r,compound:l,filterLeaves:s,targetType:o}=e;let n=[],d=!1,f=!1;const t=a.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let i=0;i<t;i++){const c=a[i];if(c!==this.#e&&(this.#e.contains(c)||c.contains(this.#e))){if(l){if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else if(n.push(c),d=!0,o===A)break}}else if(r)if(l)for(let i=0;i<t;i++){const c=a[i];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else n=[].slice.call(a),d=!0,f=!0;else if(l)for(let i=0;i<t;i++){const c=a[i];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else n=[].slice.call(a),d=!0,f=!0;return[n,d,f]}_findEntryNodes(a,e,r){const{leaves:l}=a,[s,...o]=l,n=o.length>0,{name:d,type:f}=s;let t=[],i=!1,c=!1,w=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(e===A&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(n?this._matchLeaves(o,_,{warn:this.#i})&&(t.push(_),c=!0):(t.push(_),c=!0))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(d)){if(this.#d&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(s,this.#e);_&&(t.push(_),c=!0)}}else e===D?[t,c]=this._matchSelf(l):e===R?[t,c]=this._findLineal(l,{complex:r}):e===A?[t,c]=this._findFirst(l):w=!0}return{collected:i,compound:n,filtered:c,nodes:t,pending:w}}_collectNodes(a){const e=this.#a.values();if(a===M||a===A){const r=new Set;let l=0;for(const{branch:s}of e){const o=s.length,n=o>1,d=s[0];let f,t;if(n){const{combo:N,leaves:[{name:k,type:g}]}=d,h=s[o-1],{leaves:[{name:p,type:u}]}=h;if(u===b.SELECTOR_PSEUDO_ELEMENT||u===b.SELECTOR_ID)f=O,t=h;else if(g===b.SELECTOR_PSEUDO_ELEMENT||g===b.SELECTOR_ID)f=T,t=d;else if(a===M)if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else if(p==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(o===2){const{name:y}=N;/^[+~]$/.test(y)?(f=O,t=h):(f=T,t=d)}else f=T,t=d;else if(p==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else{let y;for(const{combo:v,leaves:[L]}of s){const{name:x,type:W}=L;if(W===b.SELECTOR_PSEUDO_CLASS&&x==="dir"){y=!1;break}if(!y&&v){const{name:H}=v;/^[+~]$/.test(H)&&(y=!0)}}y?(f=T,t=d):(f=O,t=h)}}else f=O,t=d;const{collected:i,compound:c,filtered:w,nodes:_,pending:m}=this._findEntryNodes(t,a,n);_.length?(this.#a[l].find=!0,this.#h[l]=_):m&&r.add(new Map([["index",l],["twig",t]])),this.#a[l].collected=i,this.#a[l].dir=f,this.#a[l].filtered=w||!c,l++}if(r.size){let s,o;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,o=this.#n):(s=this.#s,o=this.#r);let n=this._traverse(s,o);for(;n;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?n===this.#e?d=!0:d=this.#e.contains(n):d=!0,d)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const c=f.get("index");this.#a[c].filtered=!0,this.#a[c].find=!0,this.#h[c].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let r=0;for(const{branch:l}of e){const s=l[l.length-1],o=l.length>1,{compound:n,filtered:d,nodes:f}=this._findEntryNodes(s,a,o);f.length&&(this.#a[r].find=!0,this.#h[r]=f),this.#a[r].dir=O,this.#a[r].filtered=d||!n,r++}}return[this.#a,this.#h]}_getCombinedNodes(a,e,r){const l=[];for(const s of e){const o=this._matchCombinator(a,s,{dir:r,warn:this.#i});o.size&&l.push(...o)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,r){const{combo:l,index:s}=r,{combo:o,leaves:n}=a[s],d={combo:l,leaves:n},f=this._getCombinedNodes(d,e,T);let t;if(f.size)if(s===a.length-1){const[i]=(0,C.sortNodes)(f);t=i}else t=this._matchNodeNext(a,f,{combo:o,index:s+1});return t??null}_matchNodePrev(a,e,r){const{index:l}=r,s=a[l],o=new Set([e]),n=this._getCombinedNodes(s,o,O);let d;if(n.size){if(l===0)d=e;else for(const f of n)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_find(a){(a===M||a===A)&&this._prepareQuerySelectorWalker();const[[...e],r]=this._collectNodes(a),l=e.length;let s=new Set;for(let o=0;o<l;o++){const{branch:n,collected:d,dir:f,find:t}=e[o],i=n.length;if(i&&t){const c=r[o],w=c.length,_=i-1;if(_===0)if((a===M||a===A)&&this.#e.nodeType===b.ELEMENT_NODE)for(let m=0;m<w;m++){const N=c[m];if(N!==this.#e&&this.#e.contains(N)&&(s.add(N),a!==M))break}else if(a===M)if(s.size){const m=[...s];s=new Set([...m,...c]),this.#b=!0}else s=new Set(c);else{const[m]=c;s.add(m)}else if(a===M)if(f===T){let{combo:m}=n[0];for(const N of c){let k=new Set([N]);for(let g=1;g<i;g++){const{combo:h,leaves:p}=n[g],u={combo:m,leaves:p};if(k=this._getCombinedNodes(u,k,f),k.size)if(g===_)if(s.size){const y=[...s];s=new Set([...y,...k]),this.#b=!0}else s=k;else m=h;else break}}}else for(const m of c){let N=new Set([m]);for(let k=_-1;k>=0;k--){const g=n[k];if(N=this._getCombinedNodes(g,N,f),N.size)k===0&&(s.add(m),i>1&&s.size>1&&(this.#b=!0));else break}}else if(a===A&&f===T){const{combo:m}=n[0];let N;for(const k of c)if(N=this._matchNodeNext(n,new Set([k]),{combo:m,index:1}),N){s.add(N);break}if(!N&&!d){const{leaves:k}=n[0],[g]=c;let h=this._findNode(k,{node:g});for(;h;){if(N=this._matchNodeNext(n,new Set([h]),{combo:m,index:1}),N){s.add(N);break}h=this._findNode(k,{node:h})}}}else{let m;for(const N of c)if(m=this._matchNodePrev(n,N,{index:_-1}),m){s.add(N);break}if(!m&&!d&&a===A){const{leaves:N}=n[_],[k]=c;let g=this._findNode(N,{node:k});for(;g;){if(m=this._matchNodePrev(n,g,{index:_-1}),m){s.add(g);break}g=this._findNode(N,{node:g})}}}}}return s}matches(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,S.filterSelector)(a)?l=this.#c.match(a,e):(this._setup(a,e,r),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,S.filterSelector)(a))l=this.#c.closest(a,e);else{this._setup(a,e,r);const s=this._find(R);if(s.size){let o=this.#e;for(;o;){if(s.has(o)){l=o;break}o=o.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(a,e,r){let l;try{if(this._setup(a,e,r),this.#f===this.#t&&!this.#o&&(0,S.filterSelector)(a))l=this.#c.first(a,e);else{const s=this._find(A);s.delete(this.#e),s.size&&([l]=(0,C.sortNodes)(s))}}catch(s){this._onError(s)}return l??null}querySelectorAll(a,e,r){let l;try{if(this._setup(a,e,r),this.#f===this.#t&&!this.#o&&(0,S.filterSelector)(a))l=this.#c.select(a,e);else{const s=this._find(M);s.delete(this.#e),s.size&&(this.#b?l=(0,C.sortNodes)(s):l=[...s])}}catch(s){this._onError(s)}return l??[]}}0&&(module.exports={Finder});
//# sourceMappingURL=finder.js.map
var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var A=(s,t)=>{for(var r in t)g(s,r,{get:t[r],enumerable:!0})},O=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!y.call(s,n)&&n!==r&&g(s,n,{get:()=>t[n],enumerable:!(i=S(t,n))||i.enumerable});return s};var T=s=>O(g({},"__esModule",{value:!0}),s);var C={};A(C,{filterSelector:()=>L,generateCSS:()=>u.generate,parseAstName:()=>I,parseSelector:()=>h,preprocess:()=>E,sortAST:()=>_,unescapeSelector:()=>$,walkAST:()=>m});module.exports=T(C);var d=require("css-tree"),e=require("./constant.js"),u=require("css-tree");const $=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let i=1;i<r;i++){let n=t[i];if(n===""&&i===r-1)n=e.U_FFFD;else{const f=/^([\da-f]{1,6}\s?)/i.exec(n);if(f){const[,a]=f;let c;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),w=parseInt(a,e.HEX);w===0||w>=o&&w<=p?c=e.U_FFFD:c=String.fromCodePoint(w)}catch{c=e.U_FFFD}let l="";n.length>a.length&&(l=n.substring(a.length)),n=`${c}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},E=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let n=t.substring(r+1);const f=n.codePointAt(0);if(f===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(f>e.BIT_FFFF){const a=`\\${f.toString(e.HEX)} `;n.length===e.DUO?n=a:n=`${a}${n.substring(e.DUO)}`}t=`${i}${n}`,r++}t=t.replace(/\f|\r\n?/g,`
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},h=s=>{if(s=E(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,d.toPlainObject)(r)}catch(r){const{message:i}=r,n=/(:(is|where)\(\s*\))/,f=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;if(i==="Identifier is expected"&&f.test(s)){const[,a,c]=f.exec(s),l=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let o=a.replace(c,l);o===":lang()"&&(o=`:lang(${e.EMPTY})`),t=h(s.replace(a,o))}else if((i==="Identifier is expected"||i==="Selector is expected")&&n.test(s)){const[,a,c]=n.exec(s),l=`:${c}(${e.EMPTY})`;t=h(s.replace(a,l))}else if(i==='"]" is expected'&&!s.endsWith("]"))t=h(`${s}]`);else if(i==='")" is expected'&&!s.endsWith(")"))t=h(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set;let r;return(0,d.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)||n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,d.findAll)(s,(n,f,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)for(const{children:p}of o)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)t.has(o)&&t.delete(o)}}}),[...t]},_=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,n)=>{const{type:f}=i,{type:a}=n,c=r.get(f),l=r.get(a);let o;return c===l?o=0:c>l?o=1:o=-1,o})}return t},I=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},L=s=>!(!s||typeof s!="string"||/\||::|\[\s*[\w$*=^|~-]+(?:\s+[\w$*=^|~-]+)+\s*\]|\[\s*[\w$*=^|~-]+["'][\w$*=^|~\s-]+['"]+\s+[\w$*=^|~-]+\s*\]/.test(s)||s.includes(":")&&/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|n|[+-]?(?:0|[1-9]\d*)n?|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(s));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},h=s=>{if(s=E(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,d.toPlainObject)(r)}catch(r){const{message:i}=r,n=/(:(is|where)\(\s*\))/,f=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;if(i==="Identifier is expected"&&f.test(s)){const[,a,c]=f.exec(s),l=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let o=a.replace(c,l);o===":lang()"&&(o=`:lang(${e.EMPTY})`),t=h(s.replace(a,o))}else if((i==="Identifier is expected"||i==="Selector is expected")&&n.test(s)){const[,a,c]=n.exec(s),l=`:${c}(${e.EMPTY})`;t=h(s.replace(a,l))}else if(i==='"]" is expected'&&!s.endsWith("]"))t=h(`${s}]`);else if(i==='")" is expected'&&!s.endsWith(")"))t=h(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set;let r;return(0,d.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)||n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,d.findAll)(s,(n,f,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)for(const{children:p}of o)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)t.has(o)&&t.delete(o)}}}),[...t]},_=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,n)=>{const{type:f}=i,{type:a}=n,c=r.get(f),l=r.get(a);let o;return c===l?o=0:c>l?o=1:o=-1,o})}return t},I=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},L=s=>!(!s||typeof s!="string"||/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(s)||s.includes(":")&&/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\d*)n?|n)|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(s));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
//# sourceMappingURL=parser.js.map

@@ -32,3 +32,3 @@ {

"devDependencies": {
"@types/css-tree": "^2.3.6",
"@types/css-tree": "^2.3.7",
"benchmark": "^2.1.4",

@@ -38,10 +38,10 @@ "c8": "^9.1.0",

"commander": "^12.0.0",
"esbuild": "^0.20.0",
"eslint": "^8.56.0",
"esbuild": "^0.20.1",
"eslint": "^8.57.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.1.0",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-regexp": "^2.2.0",
"eslint-plugin-unicorn": "^51.0.1",
"happy-dom": "^13.3.8",
"happy-dom": "^13.7.0",
"jsdom": "^24.0.0",

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

"sinon": "^17.0.1",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"wpt-runner": "^5.0.0"

@@ -69,3 +69,3 @@ },

},
"version": "4.1.6"
"version": "4.1.7"
}

@@ -300,5 +300,5 @@ /**

}
// filter namespaced selectors, e.g. ns|E, pseudo-element selectors
// and attribute selectors with case flag, i.e. [attr i], [attr s]
if (/\||::|\[\s*[\w$*=^|~-]+(?:\s+[\w$*=^|~-]+)+\s*\]|\[\s*[\w$*=^|~-]+["'][\w$*=^|~\s-]+['"]+\s+[\w$*=^|~-]+\s*\]/.test(selector)) {
// filter namespaced selectors, e.g. ns|E, pseudo-element selectors and
// attribute selectors with case flag, e.g. [attr i], and unclosed quotes
if (/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(selector)) {
return false;

@@ -308,19 +308,25 @@ }

if (selector.includes(':')) {
// filter pseudos other than child-indexed and logical combination pseudos
// :(?!(?:first|last|only)-(?:child|of-type)|${nth}|${logical})
// digit:
// `(?:0|[1-9]\d*)`
// anb:
// `[+-]?(?:${digit}n?|n)|(?:[+-]?${digit})?n\s*[+-]\s*${digit}`
// type: *, tag
// `\*|[A-Za-z][\w-]*`
// subclass: attr, id, class, pseudo-class (nst)
// `\[[^\]]+\]|[#.:][\w-]+`
// compound:
// `(?:${type}|(?:${type})?(?:${subclass})+)`
// nested logical:
// `(?:is|not|where)\(\s*${compound}(?:\s*,\s*${compound})*\s*\)`
// compoundB:
// `(?:${type}|(?:${type})?(?:${subclass}|:${nestedLogical})+)`
// nst:
// `(?:first|last|only)-(?:child|of-type)`
// nth: exclude An+B with selector list, e.g. :nth-child(2n+1 of .foo)
// nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|${an+b})\s*\)
// an+b:
// n|[+-]?(?:0|[1-9]\d*)n?|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*)
// `nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|${anb})\s*\)`
// logical: exclude complex selector, e.g. :is(.foo > .bar)
// (?:is|not|where)\(\s*${compound}(?:\s*,\s*${compound})*\s*\)
// compound:
// (?:${type}|(?:${type})?(?:${subclass})+)
// type: *, tag
// \*|[A-Za-z][\w-]*
// subclass: attr, class, id, pseudo-class
// \[[^\]]+\]|[#.:][\w-]+|:${logical}
// subclass w/o logical:
// \[[^\]]+\]|[#.:][\w-]+
if (/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|n|[+-]?(?:0|[1-9]\d*)n?|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(selector)) {
// `(?:is|not|where)\(\s*${compoundB}(?:\s*,\s*${compoundB})*\s*\)`
// filter pseudos other than child-indexed and logical combination pseudos
// `:(?!${nst}|${nth}|${logical})`
if (/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\d*)n?|n)|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(selector)) {
return false;

@@ -327,0 +333,0 @@ }

@@ -27,3 +27,2 @@ export class Finder {

private _findEntryNodes;
private _getEntryTwig;
private _collectNodes;

@@ -33,3 +32,2 @@ private _getCombinedNodes;

private _matchNodePrev;
private _matchNodes;
private _find;

@@ -36,0 +34,0 @@ matches(selector: string, node: object, opt: object): boolean;

Sorry, the diff of this file is not supported yet

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