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