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 2.0.3-a.7 to 2.0.3-a.8

2

dist/cjs/js/finder.js

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

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

@@ -62,3 +62,3 @@ {

},
"version": "2.0.3-a.7"
"version": "2.0.3-a.8"
}

@@ -22,2 +22,3 @@ /*!

* @param {object} [opt] - options
* @param {boolean} [opt.noexcept] - no exception
* @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class

@@ -47,2 +48,3 @@ * @returns {boolean} - `true` if matched, `false` otherwise

* @param {object} [opt] - options
* @param {boolean} [opt.noexcept] - no exception
* @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class

@@ -72,2 +74,3 @@ * @returns {?object} - matched node

* @param {object} [opt] - options
* @param {boolean} [opt.noexcept] - no exception
* @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class

@@ -98,2 +101,3 @@ * @returns {?object} - matched node

* @param {object} [opt] - options
* @param {boolean} [opt.noexcept] - no exception
* @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class

@@ -100,0 +104,0 @@ * @returns {Array.<object|undefined>} - array of matched nodes

export { Finder };
export let finder: Finder;
export function matches(selector: string, node: object, opt?: {
noexcept?: boolean;
warn?: boolean;
}): boolean;
export function closest(selector: string, node: object, opt?: {
noexcept?: boolean;
warn?: boolean;
}): object | null;
export function querySelector(selector: string, node: object, opt?: {
noexcept?: boolean;
warn?: boolean;
}): object | null;
export function querySelectorAll(selector: string, node: object, opt?: {
noexcept?: boolean;
warn?: boolean;
}): Array<object | undefined>;
import { Finder } from './js/finder.js';

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