@asamuzakjp/dom-selector
Advanced tools
Comparing version 4.2.1 to 4.2.2
@@ -1,2 +0,2 @@ | ||
var B=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(E,a)=>{for(var e in a)I(E,e,{get:a[e],enumerable:!0})},U=(E,a,e,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of G(a))!V.call(E,l)&&l!==e&&I(E,l,{get:()=>a[l],enumerable:!(r=j(a,l))||r.enumerable});return E};var z=(E,a,e)=>(e=E!=null?B(q(E)):{},U(a||!E||!E.__esModule?I(e,"default",{value:E,enumerable:!0}):e,E)),Y=E=>U(I({},"__esModule",{value:!0}),E);var K={};X(K,{Finder:()=>Q});module.exports=Y(K);var P=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),S=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",A="first",R="lineal",D="self";class Q{#a;#l;#t;#f;#h;#e;#d;#w;#o;#n;#p;#s;#b;#u;#r;#m;#i;#c;constructor(a){this.#c=a,this.#h=a.document,this.#l=new WeakMap,this.#p=new WeakMap,this.#o=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#o.configure({LOGERRORS:!1})}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#c.DOMException)if(a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#c.DOMException(a.message,a.name);else throw a}_setup(a,e,r={}){const{noexcept:l,warn:s}=r;return this.#w=!!l,this.#i=!!s,this.#e=e,[this.#t,this.#s,this.#r]=(0,C.resolveContent)(e),this.#b=(0,C.isInShadowTree)(e),[this.#a,this.#d]=this._correspond(a),this.#m=new WeakMap,e}_correspond(a){const e=[];this.#f=!1;let r;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${a}`)){const s=l.get(`${a}`);this.#f=s.descendant,r=s.ast}}if(r){const l=r.length;for(let s=0;s<l;s++)r[s].collected=!1,r[s].dir=null,r[s].filtered=!1,r[s].find=!1,e[s]=[]}else{let l;try{l=(0,S.parseSelector)(a)}catch(d){this._onError(d)}const s=(0,S.walkAST)(l);let o=!1,n=0;r=[];for(const[...d]of s){const f=[];let t=d.shift();if(t&&t.type!==b.COMBINATOR){const i=new Set;for(;t;){if(t.type===b.COMBINATOR){const[c]=d;if(c.type===b.COMBINATOR){const _=`Invalid selector ${a}`;throw new DOMException(_,b.SYNTAX_ERR)}const w=t.name;/^[\s>]$/.test(w)&&(o=!0),f.push({combo:t,leaves:(0,S.sortAST)(i)}),i.clear()}else if(t){let{name:c}=t;c&&typeof c=="string"&&(c=(0,S.unescapeSelector)(c),typeof c=="string"&&c!==t.name&&(t.name=c),/[|:]/.test(c)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{f.push({combo:null,leaves:(0,S.sortAST)(i)}),i.clear();break}}}r.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#t){let d;this.#l.has(this.#t)?d=this.#l.get(this.#t):d=new Map,d.set(`${a}`,{ast:r,descendant:o}),this.#l.set(this.#t,d)}this.#f=o}return[r,e]}_createTreeWalker(a){let e;return this.#m.has(a)?e=this.#m.get(a):(e=this.#h.createTreeWalker(a,b.WALKER_FILTER),this.#m.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#n=this._createTreeWalker(this.#e),this.#u=!1,this.#n}_traverse(a,e=this.#r){let r=e.currentNode,l;if(r===a)l=r;else if(r.contains(a))for(r=e.nextNode();r;){if(r===a){l=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===a);)r=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;r;){if(r===a){l=r;break}r=e.nextNode()}else l=r}return l??null}_collectNthChild(a,e,r){const{a:l,b:s,reverse:o,selector:n}=a,{parentNode:d}=e,f=new Set;let t;if(n&&(this.#l.has(n)?t=this.#l.get(n):(t=(0,S.walkAST)(n),this.#l.set(n,t))),d){const i=this.#r;let c=this._traverse(d,i);c=i.firstChild();let w=0;for(;c;)w++,c=i.nextSibling();c=this._traverse(d,i);const _=new Set;if(t)for(c=i.firstChild();c;){let m;for(const N of t)if(m=this._matchLeaves(N,c,r),!m)break;m&&_.add(c),c=i.nextSibling()}if(l===0){if(s>0&&s<=w){if(_.size){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(_.has(c)){if(m===s-1){f.add(c);break}m++}o?c=i.previousSibling():c=i.nextSibling()}}else if(!n){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(m===s-1){f.add(c);break}o?c=i.previousSibling():c=i.nextSibling(),m++}}}}else{let m=s-1;if(l>0)for(;m<0;)m+=l;if(m>=0&&m<w){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let N=0,k=l>0?0:s-1;for(;c&&(c&&m>=0&&m<w);)_.size?_.has(c)&&(k===m&&(f.add(c),m+=l),l>0?k++:k--):N===m&&(n||f.add(c),m+=l),o?c=i.previousSibling():c=i.nextSibling(),N++}}if(o&&f.size>1){const m=[...f];return new Set(m.reverse())}}else if(e===this.#s&&l+s===1)if(t){let i;for(const c of t)if(i=this._matchLeaves(c,e,r),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:r,b:l,reverse:s}=a,{localName:o,parentNode:n,prefix:d}=e,f=new Set;if(n){const t=this.#r;let i=this._traverse(n,t);i=t.firstChild();let c=0;for(;i;)c++,i=t.nextSibling();if(r===0){if(l>0&&l<=c){i=this._traverse(n,t),s?i=t.lastChild():i=t.firstChild();let w=0;for(;i;){const{localName:_,prefix:m}=i;if(_===o&&m===d){if(w===l-1){f.add(i);break}w++}s?i=t.previousSibling():i=t.nextSibling()}}}else{let w=l-1;if(r>0)for(;w<0;)w+=r;if(w>=0&&w<c){i=this._traverse(n,t),s?i=t.lastChild():i=t.firstChild();let _=r>0?0:l-1;for(;i;){const{localName:m,prefix:N}=i;if(m===o&&N===d){if(_===w&&(f.add(i),w+=r),w<0||w>=c)break;r>0?_++:_--}s?i=t.previousSibling():i=t.nextSibling()}}}if(s&&f.size>1){const w=[...f];return new Set(w.reverse())}}else e===this.#s&&r+l===1&&f.add(e);return f}_matchAnPlusB(a,e,r,l){const{nth:{a:s,b:o,name:n},selector:d}=a,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?f.set("b",o*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,r={}){let l;if(Array.isArray(a)&&a.length){const[s]=a,{type:o}=s;let n;o===b.COMBINATOR?n=a.shift():n={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[i]=a,{type:c}=i;if(c===b.COMBINATOR)break;d.push(a.shift())}const f={combo:n,leaves:d};r.dir=T;const t=this._matchCombinator(f,e,r);if(t.size)if(a.length){for(const i of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),i,r),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,r={}){const{astName:l="",branches:s=[],selector:o="",twigBranches:n=[]}=a;let d;if(l==="has")if(o.includes(":has("))d=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);r.forgive=f;const t=n.length;let i;for(let c=0;c<t;c++){const w=n[c],_=w.length-1,{leaves:m}=w[_];if(i=this._matchLeaves(m,e,r),i&&_>0){let N=new Set([e]);for(let k=_-1;k>=0;k--){const g=w[k],h=[];r.dir=O;for(const p of N){const u=this._matchCombinator(g,p,r);u.size&&h.push(...u)}if(h.length)k===0?i=!0:N=new Set(h);else{i=!1;break}}}if(i)break}l==="not"?i||(d=e):i&&(d=e)}return d??null}_matchPseudoClassSelector(a,e,r={}){const{children:l,name:s}=a,{localName:o,parentNode:n}=e,{forgive:d,warn:f=this.#i}=r,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let i;if(this.#l.has(a))i=this.#l.get(a);else{const w=(0,S.walkAST)(a),_=[],m=[];for(const[...N]of w){for(const p of N){const u=(0,S.generateCSS)(p);_.push(u)}const k=[],g=new Set;let h=N.shift();for(;h;)if(h.type===b.COMBINATOR?(k.push({combo:h,leaves:[...g]}),g.clear()):h&&g.add(h),N.length)h=N.shift();else{k.push({combo:null,leaves:[...g]}),g.clear();break}m.push(k)}i={astName:s,branches:w,twigBranches:m,selector:_.join(",")},this.#l.set(a,i)}const c=this._matchLogicalPseudoFunc(i,e,r);c&&t.add(c)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[i]=l;return this._matchAnPlusB(i,e,s,r)}else switch(s){case"dir":case"lang":{const i=$.matcher.matchSelector(a,e);i&&t.add(i);break}case"current":case"nth-col":case"nth-last-col":{if(f){const i=`Unsupported pseudo-class :${s}()`;throw new DOMException(i,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!d){const i=`Unknown pseudo-class :${s}()`;throw new DOMException(i,b.SYNTAX_ERR)}}else{const i=/^a(?:rea)?$/,c=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,w=/^(?:(?:inpu|selec)t|button|form|textarea)$/,_=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,k=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,g=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(s){case"any-link":case"link":{i.test(o)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(o)&&e.hasAttribute("href")){const{href:h,origin:p,pathname:u}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),h);y.origin===p&&y.pathname===u&&t.add(e)}break}case"visited":break;case"target":{const{hash:h}=new URL(this.#t.URL);e.id&&h===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:h}=new URL(this.#t.URL);if(h){const p=h.replace(/^#/,"");let u=this.#t.getElementById(p);for(;u;){if(u===e){t.add(e);break}u=u.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#b&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":{if(e===this.#t.activeElement){let h=e,p=!0;for(;h;){if(h.disabled||h.hasAttribute("disabled")||h.hidden||h.hasAttribute("hidden")){p=!1;break}else if(h.hasAttribute("style")){const{display:u,visibility:y}=h.style;if(p=!(u==="none"||y==="hidden"),!p)break}if(h.parentNode&&h.parentNode.nodeType===b.ELEMENT_NODE)h=h.parentNode;else break}p&&t.add(e)}break}case"focus-within":{let h=this.#t.activeElement,p;for(;h;){if(h===e){p=!0;break}h=h.parentNode}if(p){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else if(u.hasAttribute("style")){const{display:v,visibility:L}=u.style;if(y=!(v==="none"||L==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"open":{_.test(o)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(o)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(c.test(o)||(0,P.default)(o))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=n;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&n.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(c.test(o)||(0,P.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let h;o==="textarea"?h=e:o==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(h=e):h=e),h&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&o==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))t.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const h=e.name;let p=e.parentNode;for(;p&&p.localName!=="form";)p=p.parentNode;p||(p=this.#t.documentElement);const u=p.getElementsByTagName("input"),y=u.length;let v;for(let L=0;L<y;L++){const x=u[L];if(x.getAttribute("type")==="radio"&&(h?x.getAttribute("name")===h&&(v=!!x.checked):x.hasAttribute("name")||(v=!!x.checked),v))break}v||t.add(e)}break}case"default":{const h=/^(?:button|reset)$/,p=/^(?:image|submit)$/;if(o==="button"&&!(e.hasAttribute("type")&&h.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))){let u=e.parentNode;for(;u&&u.localName!=="form";)u=u.parentNode;if(u){const y=this.#r;let v=this._traverse(u,y);for(v=y.firstChild();v&&u.contains(v);){const L=v.localName;let x;if(L==="button"?x=!(v.hasAttribute("type")&&h.test(v.getAttribute("type"))):L==="input"&&(x=v.hasAttribute("type")&&p.test(v.getAttribute("type"))),x){v===e&&t.add(e);break}v=y.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(o==="option"){let u=n,y=!1;for(;u&&u.localName!=="datalist";){if(u.localName==="select"){(u.multiple||u.hasAttribute("multiple"))&&(y=!0);break}u=u.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,L=this.#r;let x=this._traverse(n,L);for(x=L.firstChild();x;){if(x.selected||x.hasAttribute("selected")){v.add(x);break}x=L.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(w.test(o))e.checkValidity()&&t.add(e);else if(o==="fieldset"){const h=this.#r;let p=this._traverse(e,h);p=h.firstChild();let u;for(;p&&e.contains(p)&&!(w.test(p.localName)&&(u=p.checkValidity(),!u));)p=h.nextNode();u&&t.add(e)}break}case"invalid":{if(w.test(o))e.checkValidity()||t.add(e);else if(o==="fieldset"){const h=this.#r;let p=this._traverse(e,h);p=h.firstChild();let u;for(;p&&e.contains(p)&&!(w.test(p.localName)&&(u=p.checkValidity(),!u));)p=h.nextNode();u||t.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let h;if(/^(?:select|textarea)$/.test(o))h=e;else if(o==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||m.test(p)||N.test(p)||g.test(p))&&(h=e)}else h=e;h&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let h;if(/^(?:select|textarea)$/.test(o))h=e;else if(o==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||m.test(p)||N.test(p)||g.test(p))&&(h=e)}else h=e;h&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const h=this.#h.createTreeWalker(e,b.SHOW_ALL);let p=h.firstChild(),u;for(;p&&(u=p.nodeType!==b.ELEMENT_NODE&&p.nodeType!==b.TEXT_NODE,!!u);)p=h.nextSibling();u&&t.add(e)}else t.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1,reverse:!0},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);if(h===e){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"defined":{const h=e.getAttribute("is");h?(0,P.default)(h)&&this.#c.customElements.get(h)&&t.add(e):(0,P.default)(o)?this.#c.customElements.get(o)&&t.add(e):(e instanceof this.#c.HTMLElement||e instanceof this.#c.SVGElement)&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const h=`Unsupported pseudo-element ::${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(f){const h=`Unsupported pseudo-class :${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}default:if(s.startsWith("-webkit-")){if(f){const h=`Unsupported pseudo-class :${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}}else if(!d){const h=`Unknown pseudo-class :${s}`;throw new DOMException(h,b.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(a,e){const{children:r,name:l}=a;let s;if(Array.isArray(r)){const[o]=(0,S.walkAST)(r[0]),[...n]=o,{host:d}=e;if(l==="host"){let f;for(const t of n){const{type:i}=t;if(i===b.COMBINATOR){const w=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(w,b.SYNTAX_ERR)}if(f=this._matchSelector(t,d).has(d),!f)break}f&&(s=e)}else if(l==="host-context"){let f=d,t;for(;f;){for(const i of n){const{type:c}=i;if(c===b.COMBINATOR){const _=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(_,b.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}if(t)break;f=f.parentNode}t&&(s=e)}}else if(l==="host")s=e;else{const o=`Invalid selector :${l}`;throw new DOMException(o,b.SYNTAX_ERR)}return s??null}_matchSelector(a,e,r){const{type:l}=a,s=new Set;if(a.name===b.EMPTY)return s;const o=(0,S.unescapeSelector)(a.name);if(typeof o=="string"&&o!==a.name&&(a.name=o),e.nodeType===b.ELEMENT_NODE)switch(l){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(o,r);break}case b.SELECTOR_ID:{e.id===o&&s.add(e);break}case b.SELECTOR_CLASS:{e.classList.contains(o)&&s.add(e);break}case b.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,r);default:{const n=$.matcher.matchSelector(a,e,r);n&&s.add(n)}}else if(this.#b&&l===b.SELECTOR_PSEUDO_CLASS&&e.nodeType===b.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&b.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(a,e,r);if(b.REG_SHADOW_HOST.test(o)){const n=this._matchShadowHostPseudoClass(a,e,r);n&&s.add(n)}}return s}_matchLeaves(a,e,r){const{attributes:l,localName:s,nodeType:o}=e;let n=this.#p.get(a),d;if(n&&n.has(e)){const{attr:f,matched:t}=n.get(e);l?.length===f&&(d=t)}if(typeof d!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;o===b.ELEMENT_NODE&&f.test(s)?t=!1:t=!0;for(const i of a){const{name:c,type:w}=i;if(w===b.SELECTOR_PSEUDO_CLASS&&c==="dir"&&(t=!1),d=this._matchSelector(i,e,r).has(e),!d)break}t&&(n||(n=new WeakMap),n.set(e,{attr:l?.length,matched:d}),this.#p.set(a,n))}return!!d}_matchHTMLCollection(a,e={}){const{compound:r,filterLeaves:l}=e,s=new Set,o=a.length;if(o)if(r)for(let n=0;n<o;n++){const d=a[n];this._matchLeaves(l,d,e)&&s.add(d)}else{const n=[].slice.call(a);return new Set(n)}return s}_findDescendantNodes(a,e,r){const[l,...s]=a,o=s.length>0,{type:n}=l,d=(0,S.unescapeSelector)(l.name);typeof d=="string"&&d!==l.name&&(l.name=d);let f=new Set,t=!1;if(this.#b)t=!0;else switch(n){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,r);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const i=this.#s.getElementById(d);i&&i!==e&&e.contains(i)&&(o?this._matchLeaves(s,i,r)&&f.add(i):f.add(i))}break}case b.SELECTOR_CLASS:{const i=e.getElementsByClassName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const i=e.getElementsByTagName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,r={}){const{combo:l,leaves:s}=a,{name:o}=l,{parentNode:n}=e,{dir:d}=r,f=new Set;if(d===T)switch(o){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(e,t);for(i=t.nextSibling();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let i=this._traverse(e,t);for(i=t.firstChild();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling();break}case" ":default:{const{nodes:t,pending:i}=this._findDescendantNodes(s,e);if(t.size)return t;if(i){const c=this._createTreeWalker(e);let w=this._traverse(e,c);for(w=c.nextNode();w&&e.contains(w);)this._matchLeaves(s,w,r)&&f.add(w),w=c.nextNode()}}}else switch(o){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(n,t);for(i=t.firstChild();i&&i!==e;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{n&&this._matchLeaves(s,n,r)&&f.add(n);break}case" ":default:{const t=[];let i=n;for(;i;)this._matchLeaves(s,i,r)&&t.push(i),i=i.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:r}=e;let l=this._traverse(r,this.#n),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#n.nextNode():l===r&&l!==this.#s&&(l=this.#n.nextNode());l;){if(this._matchLeaves(a,l,{warn:this.#i})){s=l;break}l=this.#n.nextNode()}return s??null}_matchSelf(a){const e=[],r=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return r&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:r}=e,l=[];let s=this._matchLeaves(a,this.#e,{warn:this.#i}),o=!1;if(s&&(l.push(this.#e),o=!0),!s||r){let n=this.#e.parentNode;for(;n&&(s=this._matchLeaves(a,n,{warn:this.#i}),s&&(l.push(n),o=!0),n.parentNode);)n=n.parentNode}return[l,o]}_findFirst(a){const e=[],r=this._findNode(a,{node:this.#e});let l=!1;return r&&(e.push(r),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:r,compound:l,filterLeaves:s,targetType:o}=e;let n=[],d=!1,f=!1;const t=a.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let i=0;i<t;i++){const c=a[i];if(c!==this.#e&&(this.#e.contains(c)||c.contains(this.#e))){if(l){if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else if(n.push(c),d=!0,o===A)break}}else if(r)if(l)for(let i=0;i<t;i++){const c=a[i];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else n=[].slice.call(a),d=!0,f=!0;else if(l)for(let i=0;i<t;i++){const c=a[i];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else n=[].slice.call(a),d=!0,f=!0;return[n,d,f]}_findEntryNodes(a,e,r){const{leaves:l}=a,[s,...o]=l,n=o.length>0,{name:d,type:f}=s;let t=[],i=!1,c=!1,w=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(e===A&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(n?this._matchLeaves(o,_,{warn:this.#i})&&(t.push(_),c=!0):(t.push(_),c=!0))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(d)){if(this.#b&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(s,this.#e);_&&(t.push(_),c=!0)}}else e===D?[t,c]=this._matchSelf(l):e===R?[t,c]=this._findLineal(l,{complex:r}):e===A?[t,c]=this._findFirst(l):w=!0}return{collected:i,compound:n,filtered:c,nodes:t,pending:w}}_collectNodes(a){const e=this.#a.values();if(a===M||a===A){const r=new Set;let l=0;for(const{branch:s}of e){const o=s.length,n=o>1,d=s[0];let f,t;if(n){const{combo:N,leaves:[{name:k,type:g}]}=d,h=s[o-1],{leaves:[{name:p,type:u}]}=h;if(u===b.SELECTOR_PSEUDO_ELEMENT||u===b.SELECTOR_ID)f=O,t=h;else if(g===b.SELECTOR_PSEUDO_ELEMENT||g===b.SELECTOR_ID)f=T,t=d;else if(a===M)if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else if(p==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(o===2){const{name:y}=N;/^[+~]$/.test(y)?(f=O,t=h):(f=T,t=d)}else f=T,t=d;else if(p==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else{let y;for(const{combo:v,leaves:[L]}of s){const{name:x,type:W}=L;if(W===b.SELECTOR_PSEUDO_CLASS&&x==="dir"){y=!1;break}if(!y&&v){const{name:H}=v;/^[+~]$/.test(H)&&(y=!0)}}y?(f=T,t=d):(f=O,t=h)}}else f=O,t=d;const{collected:i,compound:c,filtered:w,nodes:_,pending:m}=this._findEntryNodes(t,a,n);_.length?(this.#a[l].find=!0,this.#d[l]=_):m&&r.add(new Map([["index",l],["twig",t]])),this.#a[l].collected=i,this.#a[l].dir=f,this.#a[l].filtered=w||!c,l++}if(r.size){let s,o;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,o=this.#n):(s=this.#s,o=this.#r);let n=this._traverse(s,o);for(;n;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?n===this.#e?d=!0:d=this.#e.contains(n):d=!0,d)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const c=f.get("index");this.#a[c].filtered=!0,this.#a[c].find=!0,this.#d[c].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let r=0;for(const{branch:l}of e){const s=l[l.length-1],o=l.length>1,{compound:n,filtered:d,nodes:f}=this._findEntryNodes(s,a,o);f.length&&(this.#a[r].find=!0,this.#d[r]=f),this.#a[r].dir=O,this.#a[r].filtered=d||!n,r++}}return[this.#a,this.#d]}_getCombinedNodes(a,e,r){const l=[];for(const s of e){const o=this._matchCombinator(a,s,{dir:r,warn:this.#i});o.size&&l.push(...o)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,r){const{combo:l,index:s}=r,{combo:o,leaves:n}=a[s],d={combo:l,leaves:n},f=this._getCombinedNodes(d,e,T);let t;if(f.size)if(s===a.length-1){const[i]=(0,C.sortNodes)(f);t=i}else t=this._matchNodeNext(a,f,{combo:o,index:s+1});return t??null}_matchNodePrev(a,e,r){const{index:l}=r,s=a[l],o=new Set([e]),n=this._getCombinedNodes(s,o,O);let d;if(n.size){if(l===0)d=e;else for(const f of n)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_find(a){(a===M||a===A)&&this._prepareQuerySelectorWalker();const[[...e],r]=this._collectNodes(a),l=e.length;let s=new Set;for(let o=0;o<l;o++){const{branch:n,collected:d,dir:f,find:t}=e[o],i=n.length;if(i&&t){const c=r[o],w=c.length,_=i-1;if(_===0)if((a===M||a===A)&&this.#e.nodeType===b.ELEMENT_NODE)for(let m=0;m<w;m++){const N=c[m];if(N!==this.#e&&this.#e.contains(N)&&(s.add(N),a!==M))break}else if(a===M)if(s.size){const m=[...s];s=new Set([...m,...c]),this.#u=!0}else s=new Set(c);else{const[m]=c;s.add(m)}else if(a===M)if(f===T){let{combo:m}=n[0];for(const N of c){let k=new Set([N]);for(let g=1;g<i;g++){const{combo:h,leaves:p}=n[g],u={combo:m,leaves:p};if(k=this._getCombinedNodes(u,k,f),k.size)if(g===_)if(s.size){const y=[...s];s=new Set([...y,...k]),this.#u=!0}else s=k;else m=h;else break}}}else for(const m of c){let N=new Set([m]);for(let k=_-1;k>=0;k--){const g=n[k];if(N=this._getCombinedNodes(g,N,f),N.size)k===0&&(s.add(m),i>1&&s.size>1&&(this.#u=!0));else break}}else if(a===A&&f===T){const{combo:m}=n[0];let N;for(const k of c)if(N=this._matchNodeNext(n,new Set([k]),{combo:m,index:1}),N){s.add(N);break}if(!N&&!d){const{leaves:k}=n[0],[g]=c;let h=this._findNode(k,{node:g});for(;h;){if(N=this._matchNodeNext(n,new Set([h]),{combo:m,index:1}),N){s.add(N);break}h=this._findNode(k,{node:h})}}}else{let m;for(const N of c)if(m=this._matchNodePrev(n,N,{index:_-1}),m){s.add(N);break}if(!m&&!d&&a===A){const{leaves:N}=n[_],[k]=c;let g=this._findNode(N,{node:k});for(;g;){if(m=this._matchNodePrev(n,g,{index:_-1}),m){s.add(g);break}g=this._findNode(N,{node:g})}}}}}return s}matches(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,S.filterSelector)(a)?l=this.#o.match(a,e):(this._setup(a,e,r),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,S.filterSelector)(a))l=this.#o.closest(a,e);else{this._setup(a,e,r);const s=this._find(R);if(s.size){let o=this.#e;for(;o;){if(s.has(o)){l=o;break}o=o.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(a,e,r){let l;try{if(this._setup(a,e,r),this.#h===this.#t&&!this.#f&&(0,S.filterSelector)(a))l=this.#o.first(a,e);else{const s=this._find(A);s.delete(this.#e),s.size&&([l]=(0,C.sortNodes)(s))}}catch(s){this._onError(s)}return l??null}querySelectorAll(a,e,r){let l;try{if(this._setup(a,e,r),this.#h===this.#t&&!this.#f&&(0,S.filterSelector)(a))l=this.#o.select(a,e);else{const s=this._find(M);s.delete(this.#e),s.size&&(this.#u?l=(0,C.sortNodes)(s):l=[...s])}}catch(s){this._onError(s)}return l??[]}}0&&(module.exports={Finder}); | ||
var B=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(E,a)=>{for(var e in a)I(E,e,{get:a[e],enumerable:!0})},U=(E,a,e,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of G(a))!V.call(E,l)&&l!==e&&I(E,l,{get:()=>a[l],enumerable:!(r=j(a,l))||r.enumerable});return E};var z=(E,a,e)=>(e=E!=null?B(q(E)):{},U(a||!E||!E.__esModule?I(e,"default",{value:E,enumerable:!0}):e,E)),Y=E=>U(I({},"__esModule",{value:!0}),E);var K={};X(K,{Finder:()=>Q});module.exports=Y(K);var P=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),S=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",A="first",R="lineal",D="self";class Q{#a;#l;#t;#f;#h;#e;#d;#w;#o;#c;#p;#s;#b;#u;#r;#m;#i;#n;constructor(a){this.#n=a,this.#h=a.document,this.#l=new WeakMap,this.#p=new WeakMap,this.#o=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#o.configure({LOGERRORS:!1})}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#n.DOMException)if(a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#n.DOMException(a.message,a.name);else throw a}_setup(a,e,r={}){const{noexcept:l,warn:s}=r;return this.#w=!!l,this.#i=!!s,this.#e=e,[this.#t,this.#s,this.#r]=(0,C.resolveContent)(e),this.#b=(0,C.isInShadowTree)(e),[this.#a,this.#d]=this._correspond(a),this.#m=new WeakMap,e}_correspond(a){const e=[];this.#f=!1;let r;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${a}`)){const s=l.get(`${a}`);this.#f=s.descendant,r=s.ast}}if(r){const l=r.length;for(let s=0;s<l;s++)r[s].collected=!1,r[s].dir=null,r[s].filtered=!1,r[s].find=!1,e[s]=[]}else{let l;try{l=(0,S.parseSelector)(a)}catch(d){this._onError(d)}const s=(0,S.walkAST)(l);let o=!1,n=0;r=[];for(const[...d]of s){const f=[];let t=d.shift();if(t&&t.type!==b.COMBINATOR){const i=new Set;for(;t;){if(t.type===b.COMBINATOR){const[c]=d;if(c.type===b.COMBINATOR){const _=`Invalid selector ${a}`;throw new DOMException(_,b.SYNTAX_ERR)}const w=t.name;/^[\s>]$/.test(w)&&(o=!0),f.push({combo:t,leaves:(0,S.sortAST)(i)}),i.clear()}else if(t){let{name:c}=t;c&&typeof c=="string"&&(c=(0,S.unescapeSelector)(c),typeof c=="string"&&c!==t.name&&(t.name=c),/[|:]/.test(c)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{f.push({combo:null,leaves:(0,S.sortAST)(i)}),i.clear();break}}}r.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#t){let d;this.#l.has(this.#t)?d=this.#l.get(this.#t):d=new Map,d.set(`${a}`,{ast:r,descendant:o}),this.#l.set(this.#t,d)}this.#f=o}return[r,e]}_createTreeWalker(a){let e;return this.#m.has(a)?e=this.#m.get(a):(e=this.#h.createTreeWalker(a,b.WALKER_FILTER),this.#m.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#c=this._createTreeWalker(this.#e),this.#u=!1,this.#c}_traverse(a,e=this.#r){let r=e.currentNode,l;if(r===a)l=r;else if(r.contains(a))for(r=e.nextNode();r;){if(r===a){l=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===a);)r=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;r;){if(r===a){l=r;break}r=e.nextNode()}else l=r}return l??null}_collectNthChild(a,e,r){const{a:l,b:s,reverse:o,selector:n}=a,{parentNode:d}=e,f=new Set;let t;if(n&&(this.#l.has(n)?t=this.#l.get(n):(t=(0,S.walkAST)(n),this.#l.set(n,t))),d){const i=this.#r;let c=this._traverse(d,i);c=i.firstChild();let w=0;for(;c;)w++,c=i.nextSibling();c=this._traverse(d,i);const _=new Set;if(t)for(c=i.firstChild();c;){let m;for(const N of t)if(m=this._matchLeaves(N,c,r),!m)break;m&&_.add(c),c=i.nextSibling()}if(l===0){if(s>0&&s<=w){if(_.size){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(_.has(c)){if(m===s-1){f.add(c);break}m++}o?c=i.previousSibling():c=i.nextSibling()}}else if(!n){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let m=0;for(;c;){if(m===s-1){f.add(c);break}o?c=i.previousSibling():c=i.nextSibling(),m++}}}}else{let m=s-1;if(l>0)for(;m<0;)m+=l;if(m>=0&&m<w){c=this._traverse(d,i),o?c=i.lastChild():c=i.firstChild();let N=0,k=l>0?0:s-1;for(;c&&(c&&m>=0&&m<w);)_.size?_.has(c)&&(k===m&&(f.add(c),m+=l),l>0?k++:k--):N===m&&(n||f.add(c),m+=l),o?c=i.previousSibling():c=i.nextSibling(),N++}}if(o&&f.size>1){const m=[...f];return new Set(m.reverse())}}else if(e===this.#s&&l+s===1)if(t){let i;for(const c of t)if(i=this._matchLeaves(c,e,r),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:r,b:l,reverse:s}=a,{localName:o,parentNode:n,prefix:d}=e,f=new Set;if(n){const t=this.#r;let i=this._traverse(n,t);i=t.firstChild();let c=0;for(;i;)c++,i=t.nextSibling();if(r===0){if(l>0&&l<=c){i=this._traverse(n,t),s?i=t.lastChild():i=t.firstChild();let w=0;for(;i;){const{localName:_,prefix:m}=i;if(_===o&&m===d){if(w===l-1){f.add(i);break}w++}s?i=t.previousSibling():i=t.nextSibling()}}}else{let w=l-1;if(r>0)for(;w<0;)w+=r;if(w>=0&&w<c){i=this._traverse(n,t),s?i=t.lastChild():i=t.firstChild();let _=r>0?0:l-1;for(;i;){const{localName:m,prefix:N}=i;if(m===o&&N===d){if(_===w&&(f.add(i),w+=r),w<0||w>=c)break;r>0?_++:_--}s?i=t.previousSibling():i=t.nextSibling()}}}if(s&&f.size>1){const w=[...f];return new Set(w.reverse())}}else e===this.#s&&r+l===1&&f.add(e);return f}_matchAnPlusB(a,e,r,l){const{nth:{a:s,b:o,name:n},selector:d}=a,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?f.set("b",o*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,r={}){let l;if(Array.isArray(a)&&a.length){const[s]=a,{type:o}=s;let n;o===b.COMBINATOR?n=a.shift():n={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[i]=a,{type:c}=i;if(c===b.COMBINATOR)break;d.push(a.shift())}const f={combo:n,leaves:d};r.dir=T;const t=this._matchCombinator(f,e,r);if(t.size)if(a.length){for(const i of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),i,r),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,r={}){const{astName:l="",branches:s=[],selector:o="",twigBranches:n=[]}=a;let d;if(l==="has")if(o.includes(":has("))d=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);r.forgive=f;const t=n.length;let i;for(let c=0;c<t;c++){const w=n[c],_=w.length-1,{leaves:m}=w[_];if(i=this._matchLeaves(m,e,r),i&&_>0){let N=new Set([e]);for(let k=_-1;k>=0;k--){const g=w[k],h=[];r.dir=O;for(const u of N){const p=this._matchCombinator(g,u,r);p.size&&h.push(...p)}if(h.length)k===0?i=!0:N=new Set(h);else{i=!1;break}}}if(i)break}l==="not"?i||(d=e):i&&(d=e)}return d??null}_matchPseudoClassSelector(a,e,r={}){const{children:l,name:s}=a,{localName:o,parentNode:n}=e,{forgive:d,warn:f=this.#i}=r,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let i;if(this.#l.has(a))i=this.#l.get(a);else{const w=(0,S.walkAST)(a),_=[],m=[];for(const[...N]of w){for(const u of N){const p=(0,S.generateCSS)(u);_.push(p)}const k=[],g=new Set;let h=N.shift();for(;h;)if(h.type===b.COMBINATOR?(k.push({combo:h,leaves:[...g]}),g.clear()):h&&g.add(h),N.length)h=N.shift();else{k.push({combo:null,leaves:[...g]}),g.clear();break}m.push(k)}i={astName:s,branches:w,twigBranches:m,selector:_.join(",")},this.#l.set(a,i)}const c=this._matchLogicalPseudoFunc(i,e,r);c&&t.add(c)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[i]=l;return this._matchAnPlusB(i,e,s,r)}else switch(s){case"dir":case"lang":{const i=$.matcher.matchSelector(a,e);i&&t.add(i);break}case"current":case"nth-col":case"nth-last-col":{if(f){const i=`Unsupported pseudo-class :${s}()`;throw new DOMException(i,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!d){const i=`Unknown pseudo-class :${s}()`;throw new DOMException(i,b.SYNTAX_ERR)}}else{const i=/^a(?:rea)?$/,c=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,w=/^(?:(?:inpu|selec)t|button|form|textarea)$/,_=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,k=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,g=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(s){case"any-link":case"link":{i.test(o)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(o)&&e.hasAttribute("href")){const{href:h,origin:u,pathname:p}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),h);y.origin===u&&y.pathname===p&&t.add(e)}break}case"visited":break;case"target":{const{hash:h}=new URL(this.#t.URL);e.id&&h===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:h}=new URL(this.#t.URL);if(h){const u=h.replace(/^#/,"");let p=this.#t.getElementById(u);for(;p;){if(p===e){t.add(e);break}p=p.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#b&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":{if(e===this.#t.activeElement&&e.tabIndex>=0){let h=e,u=!0;for(;h;){if(h.disabled||h.hasAttribute("disabled")||h.hidden||h.hasAttribute("hidden")){u=!1;break}else{const{display:p,visibility:y}=this.#n.getComputedStyle(h);if(u=!(p==="none"||y==="hidden"),!u)break}if(h.parentNode&&h.parentNode.nodeType===b.ELEMENT_NODE)h=h.parentNode;else break}u&&t.add(e)}break}case"focus-within":{let h,u=this.#t.activeElement;if(u.tabIndex>=0)for(;u;){if(u===e){h=!0;break}u=u.parentNode}if(h){let p=e,y=!0;for(;p;){if(p.disabled||p.hasAttribute("disabled")||p.hidden||p.hasAttribute("hidden")){y=!1;break}else{const{display:v,visibility:L}=this.#n.getComputedStyle(p);if(y=!(v==="none"||L==="hidden"),!y)break}if(p.parentNode&&p.parentNode.nodeType===b.ELEMENT_NODE)p=p.parentNode;else break}y&&t.add(e)}break}case"open":{_.test(o)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(o)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(c.test(o)||(0,P.default)(o))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=n;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&n.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(c.test(o)||(0,P.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let h;o==="textarea"?h=e:o==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(h=e):h=e),h&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&o==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))t.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const h=e.name;let u=e.parentNode;for(;u&&u.localName!=="form";)u=u.parentNode;u||(u=this.#t.documentElement);const p=u.getElementsByTagName("input"),y=p.length;let v;for(let L=0;L<y;L++){const x=p[L];if(x.getAttribute("type")==="radio"&&(h?x.getAttribute("name")===h&&(v=!!x.checked):x.hasAttribute("name")||(v=!!x.checked),v))break}v||t.add(e)}break}case"default":{const h=/^(?:button|reset)$/,u=/^(?:image|submit)$/;if(o==="button"&&!(e.hasAttribute("type")&&h.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&u.test(e.getAttribute("type"))){let p=e.parentNode;for(;p&&p.localName!=="form";)p=p.parentNode;if(p){const y=this.#r;let v=this._traverse(p,y);for(v=y.firstChild();v&&p.contains(v);){const L=v.localName;let x;if(L==="button"?x=!(v.hasAttribute("type")&&h.test(v.getAttribute("type"))):L==="input"&&(x=v.hasAttribute("type")&&u.test(v.getAttribute("type"))),x){v===e&&t.add(e);break}v=y.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(o==="option"){let p=n,y=!1;for(;p&&p.localName!=="datalist";){if(p.localName==="select"){(p.multiple||p.hasAttribute("multiple"))&&(y=!0);break}p=p.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,L=this.#r;let x=this._traverse(n,L);for(x=L.firstChild();x;){if(x.selected||x.hasAttribute("selected")){v.add(x);break}x=L.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(w.test(o))e.checkValidity()&&t.add(e);else if(o==="fieldset"){const h=this.#r;let u=this._traverse(e,h);u=h.firstChild();let p;for(;u&&e.contains(u)&&!(w.test(u.localName)&&(p=u.checkValidity(),!p));)u=h.nextNode();p&&t.add(e)}break}case"invalid":{if(w.test(o))e.checkValidity()||t.add(e);else if(o==="fieldset"){const h=this.#r;let u=this._traverse(e,h);u=h.firstChild();let p;for(;u&&e.contains(u)&&!(w.test(u.localName)&&(p=u.checkValidity(),!p));)u=h.nextNode();p||t.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let h;if(/^(?:select|textarea)$/.test(o))h=e;else if(o==="input")if(e.hasAttribute("type")){const u=e.getAttribute("type");(u==="file"||m.test(u)||N.test(u)||g.test(u))&&(h=e)}else h=e;h&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let h;if(/^(?:select|textarea)$/.test(o))h=e;else if(o==="input")if(e.hasAttribute("type")){const u=e.getAttribute("type");(u==="file"||m.test(u)||N.test(u)||g.test(u))&&(h=e)}else h=e;h&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const h=this.#h.createTreeWalker(e,b.SHOW_ALL);let u=h.firstChild(),p;for(;u&&(p=u.nodeType!==b.ELEMENT_NODE&&u.nodeType!==b.TEXT_NODE,!!p);)u=h.nextSibling();p&&t.add(e)}else t.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1,reverse:!0},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);if(h===e){const[u]=this._collectNthOfType({a:0,b:1,reverse:!0},e);u===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"defined":{const h=e.getAttribute("is");h?(0,P.default)(h)&&this.#n.customElements.get(h)&&t.add(e):(0,P.default)(o)?this.#n.customElements.get(o)&&t.add(e):(e instanceof this.#n.HTMLElement||e instanceof this.#n.SVGElement)&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const h=`Unsupported pseudo-element ::${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(f){const h=`Unsupported pseudo-class :${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}default:if(s.startsWith("-webkit-")){if(f){const h=`Unsupported pseudo-class :${s}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}}else if(!d){const h=`Unknown pseudo-class :${s}`;throw new DOMException(h,b.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(a,e){const{children:r,name:l}=a;let s;if(Array.isArray(r)){const[o]=(0,S.walkAST)(r[0]),[...n]=o,{host:d}=e;if(l==="host"){let f;for(const t of n){const{type:i}=t;if(i===b.COMBINATOR){const w=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(w,b.SYNTAX_ERR)}if(f=this._matchSelector(t,d).has(d),!f)break}f&&(s=e)}else if(l==="host-context"){let f=d,t;for(;f;){for(const i of n){const{type:c}=i;if(c===b.COMBINATOR){const _=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(_,b.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}if(t)break;f=f.parentNode}t&&(s=e)}}else if(l==="host")s=e;else{const o=`Invalid selector :${l}`;throw new DOMException(o,b.SYNTAX_ERR)}return s??null}_matchSelector(a,e,r){const{type:l}=a,s=new Set;if(a.name===b.EMPTY)return s;const o=(0,S.unescapeSelector)(a.name);if(typeof o=="string"&&o!==a.name&&(a.name=o),e.nodeType===b.ELEMENT_NODE)switch(l){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(o,r);break}case b.SELECTOR_ID:{e.id===o&&s.add(e);break}case b.SELECTOR_CLASS:{e.classList.contains(o)&&s.add(e);break}case b.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,r);default:{const n=$.matcher.matchSelector(a,e,r);n&&s.add(n)}}else if(this.#b&&l===b.SELECTOR_PSEUDO_CLASS&&e.nodeType===b.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&b.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(a,e,r);if(b.REG_SHADOW_HOST.test(o)){const n=this._matchShadowHostPseudoClass(a,e,r);n&&s.add(n)}}return s}_matchLeaves(a,e,r){const{attributes:l,localName:s,nodeType:o}=e;let n=this.#p.get(a),d;if(n&&n.has(e)){const{attr:f,matched:t}=n.get(e);l?.length===f&&(d=t)}if(typeof d!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;o===b.ELEMENT_NODE&&f.test(s)?t=!1:t=!0;for(const i of a){const{name:c,type:w}=i;if(w===b.SELECTOR_PSEUDO_CLASS&&c==="dir"&&(t=!1),d=this._matchSelector(i,e,r).has(e),!d)break}t&&(n||(n=new WeakMap),n.set(e,{attr:l?.length,matched:d}),this.#p.set(a,n))}return!!d}_matchHTMLCollection(a,e={}){const{compound:r,filterLeaves:l}=e,s=new Set,o=a.length;if(o)if(r)for(let n=0;n<o;n++){const d=a[n];this._matchLeaves(l,d,e)&&s.add(d)}else{const n=[].slice.call(a);return new Set(n)}return s}_findDescendantNodes(a,e,r){const[l,...s]=a,o=s.length>0,{type:n}=l,d=(0,S.unescapeSelector)(l.name);typeof d=="string"&&d!==l.name&&(l.name=d);let f=new Set,t=!1;if(this.#b)t=!0;else switch(n){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,r);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const i=this.#s.getElementById(d);i&&i!==e&&e.contains(i)&&(o?this._matchLeaves(s,i,r)&&f.add(i):f.add(i))}break}case b.SELECTOR_CLASS:{const i=e.getElementsByClassName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const i=e.getElementsByTagName(d);f=this._matchHTMLCollection(i,{compound:o,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,r={}){const{combo:l,leaves:s}=a,{name:o}=l,{parentNode:n}=e,{dir:d}=r,f=new Set;if(d===T)switch(o){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(e,t);for(i=t.nextSibling();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let i=this._traverse(e,t);for(i=t.firstChild();i;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling();break}case" ":default:{const{nodes:t,pending:i}=this._findDescendantNodes(s,e);if(t.size)return t;if(i){const c=this._createTreeWalker(e);let w=this._traverse(e,c);for(w=c.nextNode();w&&e.contains(w);)this._matchLeaves(s,w,r)&&f.add(w),w=c.nextNode()}}}else switch(o){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let i=this._traverse(n,t);for(i=t.firstChild();i&&i!==e;)this._matchLeaves(s,i,r)&&f.add(i),i=t.nextSibling()}break}case">":{n&&this._matchLeaves(s,n,r)&&f.add(n);break}case" ":default:{const t=[];let i=n;for(;i;)this._matchLeaves(s,i,r)&&t.push(i),i=i.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:r}=e;let l=this._traverse(r,this.#c),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#c.nextNode():l===r&&l!==this.#s&&(l=this.#c.nextNode());l;){if(this._matchLeaves(a,l,{warn:this.#i})){s=l;break}l=this.#c.nextNode()}return s??null}_matchSelf(a){const e=[],r=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return r&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:r}=e,l=[];let s=this._matchLeaves(a,this.#e,{warn:this.#i}),o=!1;if(s&&(l.push(this.#e),o=!0),!s||r){let n=this.#e.parentNode;for(;n&&(s=this._matchLeaves(a,n,{warn:this.#i}),s&&(l.push(n),o=!0),n.parentNode);)n=n.parentNode}return[l,o]}_findFirst(a){const e=[],r=this._findNode(a,{node:this.#e});let l=!1;return r&&(e.push(r),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:r,compound:l,filterLeaves:s,targetType:o}=e;let n=[],d=!1,f=!1;const t=a.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let i=0;i<t;i++){const c=a[i];if(c!==this.#e&&(this.#e.contains(c)||c.contains(this.#e))){if(l){if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else if(n.push(c),d=!0,o===A)break}}else if(r)if(l)for(let i=0;i<t;i++){const c=a[i];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else n=[].slice.call(a),d=!0,f=!0;else if(l)for(let i=0;i<t;i++){const c=a[i];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),d=!0,o===A))break}else n=[].slice.call(a),d=!0,f=!0;return[n,d,f]}_findEntryNodes(a,e,r){const{leaves:l}=a,[s,...o]=l,n=o.length>0,{name:d,type:f}=s;let t=[],i=!1,c=!1,w=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(e===A&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(n?this._matchLeaves(o,_,{warn:this.#i})&&(t.push(_),c=!0):(t.push(_),c=!0))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,c]=this._matchSelf(l);else if(e===R)[t,c]=this._findLineal(l,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,c,i]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(l):w=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(d)){if(this.#b&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(s,this.#e);_&&(t.push(_),c=!0)}}else e===D?[t,c]=this._matchSelf(l):e===R?[t,c]=this._findLineal(l,{complex:r}):e===A?[t,c]=this._findFirst(l):w=!0}return{collected:i,compound:n,filtered:c,nodes:t,pending:w}}_collectNodes(a){const e=this.#a.values();if(a===M||a===A){const r=new Set;let l=0;for(const{branch:s}of e){const o=s.length,n=o>1,d=s[0];let f,t;if(n){const{combo:N,leaves:[{name:k,type:g}]}=d,h=s[o-1],{leaves:[{name:u,type:p}]}=h;if(p===b.SELECTOR_PSEUDO_ELEMENT||p===b.SELECTOR_ID)f=O,t=h;else if(g===b.SELECTOR_PSEUDO_ELEMENT||g===b.SELECTOR_ID)f=T,t=d;else if(a===M)if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else if(u==="*"&&p===b.SELECTOR_TYPE)f=T,t=d;else if(o===2){const{name:y}=N;/^[+~]$/.test(y)?(f=O,t=h):(f=T,t=d)}else f=T,t=d;else if(u==="*"&&p===b.SELECTOR_TYPE)f=T,t=d;else if(k==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else{let y;for(const{combo:v,leaves:[L]}of s){const{name:x,type:W}=L;if(W===b.SELECTOR_PSEUDO_CLASS&&x==="dir"){y=!1;break}if(!y&&v){const{name:H}=v;/^[+~]$/.test(H)&&(y=!0)}}y?(f=T,t=d):(f=O,t=h)}}else f=O,t=d;const{collected:i,compound:c,filtered:w,nodes:_,pending:m}=this._findEntryNodes(t,a,n);_.length?(this.#a[l].find=!0,this.#d[l]=_):m&&r.add(new Map([["index",l],["twig",t]])),this.#a[l].collected=i,this.#a[l].dir=f,this.#a[l].filtered=w||!c,l++}if(r.size){let s,o;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,o=this.#c):(s=this.#s,o=this.#r);let n=this._traverse(s,o);for(;n;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?n===this.#e?d=!0:d=this.#e.contains(n):d=!0,d)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const c=f.get("index");this.#a[c].filtered=!0,this.#a[c].find=!0,this.#d[c].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let r=0;for(const{branch:l}of e){const s=l[l.length-1],o=l.length>1,{compound:n,filtered:d,nodes:f}=this._findEntryNodes(s,a,o);f.length&&(this.#a[r].find=!0,this.#d[r]=f),this.#a[r].dir=O,this.#a[r].filtered=d||!n,r++}}return[this.#a,this.#d]}_getCombinedNodes(a,e,r){const l=[];for(const s of e){const o=this._matchCombinator(a,s,{dir:r,warn:this.#i});o.size&&l.push(...o)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,r){const{combo:l,index:s}=r,{combo:o,leaves:n}=a[s],d={combo:l,leaves:n},f=this._getCombinedNodes(d,e,T);let t;if(f.size)if(s===a.length-1){const[i]=(0,C.sortNodes)(f);t=i}else t=this._matchNodeNext(a,f,{combo:o,index:s+1});return t??null}_matchNodePrev(a,e,r){const{index:l}=r,s=a[l],o=new Set([e]),n=this._getCombinedNodes(s,o,O);let d;if(n.size){if(l===0)d=e;else for(const f of n)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_find(a){(a===M||a===A)&&this._prepareQuerySelectorWalker();const[[...e],r]=this._collectNodes(a),l=e.length;let s=new Set;for(let o=0;o<l;o++){const{branch:n,collected:d,dir:f,find:t}=e[o],i=n.length;if(i&&t){const c=r[o],w=c.length,_=i-1;if(_===0)if((a===M||a===A)&&this.#e.nodeType===b.ELEMENT_NODE)for(let m=0;m<w;m++){const N=c[m];if(N!==this.#e&&this.#e.contains(N)&&(s.add(N),a!==M))break}else if(a===M)if(s.size){const m=[...s];s=new Set([...m,...c]),this.#u=!0}else s=new Set(c);else{const[m]=c;s.add(m)}else if(a===M)if(f===T){let{combo:m}=n[0];for(const N of c){let k=new Set([N]);for(let g=1;g<i;g++){const{combo:h,leaves:u}=n[g],p={combo:m,leaves:u};if(k=this._getCombinedNodes(p,k,f),k.size)if(g===_)if(s.size){const y=[...s];s=new Set([...y,...k]),this.#u=!0}else s=k;else m=h;else break}}}else for(const m of c){let N=new Set([m]);for(let k=_-1;k>=0;k--){const g=n[k];if(N=this._getCombinedNodes(g,N,f),N.size)k===0&&(s.add(m),i>1&&s.size>1&&(this.#u=!0));else break}}else if(a===A&&f===T){const{combo:m}=n[0];let N;for(const k of c)if(N=this._matchNodeNext(n,new Set([k]),{combo:m,index:1}),N){s.add(N);break}if(!N&&!d){const{leaves:k}=n[0],[g]=c;let h=this._findNode(k,{node:g});for(;h;){if(N=this._matchNodeNext(n,new Set([h]),{combo:m,index:1}),N){s.add(N);break}h=this._findNode(k,{node:h})}}}else{let m;for(const N of c)if(m=this._matchNodePrev(n,N,{index:_-1}),m){s.add(N);break}if(!m&&!d&&a===A){const{leaves:N}=n[_],[k]=c;let g=this._findNode(N,{node:k});for(;g;){if(m=this._matchNodePrev(n,g,{index:_-1}),m){s.add(g);break}g=this._findNode(N,{node:g})}}}}}return s}matches(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,S.filterSelector)(a)?l=this.#o.match(a,e):(this._setup(a,e,r),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,S.filterSelector)(a))l=this.#o.closest(a,e);else{this._setup(a,e,r);const s=this._find(R);if(s.size){let o=this.#e;for(;o;){if(s.has(o)){l=o;break}o=o.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(a,e,r){let l;try{if(this._setup(a,e,r),this.#h===this.#t&&!this.#f&&(0,S.filterSelector)(a))l=this.#o.first(a,e);else{const s=this._find(A);s.delete(this.#e),s.size&&([l]=(0,C.sortNodes)(s))}}catch(s){this._onError(s)}return l??null}querySelectorAll(a,e,r){let l;try{if(this._setup(a,e,r),this.#h===this.#t&&!this.#f&&(0,S.filterSelector)(a))l=this.#o.select(a,e);else{const s=this._find(M);s.delete(this.#e),s.size&&(this.#u?l=(0,C.sortNodes)(s):l=[...s])}}catch(s){this._onError(s)}return l??[]}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -1,3 +0,3 @@ | ||
var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var A=(s,t)=>{for(var r in t)g(s,r,{get:t[r],enumerable:!0})},O=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!y.call(s,n)&&n!==r&&g(s,n,{get:()=>t[n],enumerable:!(i=S(t,n))||i.enumerable});return s};var T=s=>O(g({},"__esModule",{value:!0}),s);var C={};A(C,{filterSelector:()=>L,generateCSS:()=>u.generate,parseAstName:()=>I,parseSelector:()=>h,preprocess:()=>E,sortAST:()=>_,unescapeSelector:()=>$,walkAST:()=>m});module.exports=T(C);var d=require("css-tree"),e=require("./constant.js"),u=require("css-tree");const $=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let i=1;i<r;i++){let n=t[i];if(n===""&&i===r-1)n=e.U_FFFD;else{const f=/^([\da-f]{1,6}\s?)/i.exec(n);if(f){const[,a]=f;let c;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),w=parseInt(a,e.HEX);w===0||w>=o&&w<=p?c=e.U_FFFD:c=String.fromCodePoint(w)}catch{c=e.U_FFFD}let l="";n.length>a.length&&(l=n.substring(a.length)),n=`${c}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},E=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let n=t.substring(r+1);const f=n.codePointAt(0);if(f===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(f>e.BIT_FFFF){const a=`\\${f.toString(e.HEX)} `;n.length===e.DUO?n=a:n=`${a}${n.substring(e.DUO)}`}t=`${i}${n}`,r++}t=t.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},h=s=>{if(s=E(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,d.toPlainObject)(r)}catch(r){const{message:i}=r,n=/(:(is|where)\(\s*\))/,f=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;if(i==="Identifier is expected"&&f.test(s)){const[,a,c]=f.exec(s),l=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let o=a.replace(c,l);o===":lang()"&&(o=`:lang(${e.EMPTY})`),t=h(s.replace(a,o))}else if((i==="Identifier is expected"||i==="Selector is expected")&&n.test(s)){const[,a,c]=n.exec(s),l=`:${c}(${e.EMPTY})`;t=h(s.replace(a,l))}else if(i==='"]" is expected'&&!s.endsWith("]"))t=h(`${s}]`);else if(i==='")" is expected'&&!s.endsWith(")"))t=h(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set;let r;return(0,d.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)||n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,d.findAll)(s,(n,f,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)for(const{children:p}of o)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)t.has(o)&&t.delete(o)}}}),[...t]},_=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,n)=>{const{type:f}=i,{type:a}=n,c=r.get(f),l=r.get(a);let o;return c===l?o=0:c>l?o=1:o=-1,o})}return t},I=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},L=s=>!(!s||typeof s!="string"||/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(s)||s.includes(":")&&/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\d*)n?|n)|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(s));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var A=(s,t)=>{for(var r in t)g(s,r,{get:t[r],enumerable:!0})},O=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!y.call(s,n)&&n!==r&&g(s,n,{get:()=>t[n],enumerable:!(i=S(t,n))||i.enumerable});return s};var T=s=>O(g({},"__esModule",{value:!0}),s);var L={};A(L,{filterSelector:()=>D,generateCSS:()=>u.generate,parseAstName:()=>I,parseSelector:()=>h,preprocess:()=>E,sortAST:()=>_,unescapeSelector:()=>$,walkAST:()=>m});module.exports=T(L);var d=require("css-tree"),e=require("./constant.js"),u=require("css-tree");const $=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let i=1;i<r;i++){let n=t[i];if(n===""&&i===r-1)n=e.U_FFFD;else{const f=/^([\da-f]{1,6}\s?)/i.exec(n);if(f){const[,a]=f;let c;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),w=parseInt(a,e.HEX);w===0||w>=o&&w<=p?c=e.U_FFFD:c=String.fromCodePoint(w)}catch{c=e.U_FFFD}let l="";n.length>a.length&&(l=n.substring(a.length)),n=`${c}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},E=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let n=t.substring(r+1);if(/^\d$/.test(n.substring(0,1)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);const f=n.codePointAt(0);if(f===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(f>e.BIT_FFFF){const a=`\\${f.toString(e.HEX)} `;n.length===e.DUO?n=a:n=`${a}${n.substring(e.DUO)}`}t=`${i}${n}`,r++}t=t.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},h=s=>{if(s=E(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,d.toPlainObject)(r)}catch(r){const{message:i}=r,n=/(:(is|where)\(\s*\))/,f=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;if(i==="Identifier is expected"&&f.test(s)){const[,a,c]=f.exec(s),l=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let o=a.replace(c,l);o===":lang()"&&(o=`:lang(${e.EMPTY})`),t=h(s.replace(a,o))}else if((i==="Identifier is expected"||i==="Selector is expected")&&n.test(s)){const[,a,c]=n.exec(s),l=`:${c}(${e.EMPTY})`;t=h(s.replace(a,l))}else if(i==='"]" is expected'&&!s.endsWith("]"))t=h(`${s}]`);else if(i==='")" is expected'&&!s.endsWith(")"))t=h(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set;let r;return(0,d.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)||n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,d.findAll)(s,(n,f,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)for(const{children:p}of o)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)t.has(o)&&t.delete(o)}}}),[...t]},_=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,n)=>{const{type:f}=i,{type:a}=n,c=r.get(f),l=r.get(a);let o;return c===l?o=0:c>l?o=1:o=-1,o})}return t},I=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},D=s=>!(!s||typeof s!="string"||/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(s)||s.includes(":")&&/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\d*)n?|n)|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(s));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
//# sourceMappingURL=parser.js.map |
@@ -37,3 +37,3 @@ { | ||
"commander": "^12.0.0", | ||
"esbuild": "^0.20.2", | ||
"esbuild": "^0.21.0", | ||
"eslint": "^8.57.0", | ||
@@ -45,7 +45,7 @@ "eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-unicorn": "^52.0.0", | ||
"happy-dom": "^14.7.1", | ||
"happy-dom": "^14.10.1", | ||
"jsdom": "^24.0.0", | ||
"linkedom": "^0.16.11", | ||
"mocha": "^10.4.0", | ||
"sinon": "^17.0.1", | ||
"sinon": "^17.0.2", | ||
"typescript": "^5.4.5", | ||
@@ -65,3 +65,3 @@ "wpt-runner": "^5.0.0" | ||
}, | ||
"version": "4.2.1" | ||
"version": "4.2.2" | ||
} |
@@ -257,8 +257,9 @@ # DOM Selector | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`matches('.content')`|1,000,095 ops/sec ±0.29%|6,105 ops/sec ±0.45%|8,636 ops/sec ±0.36%|949,741 ops/sec ±0.21%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|592,559 ops/sec ±1.72%|5,932 ops/sec ±0.48%|8,724 ops/sec ±0.67%|517,958 ops/sec ±0.28%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|5,893 ops/sec ±0.35%|F|157,436 ops/sec ±0.22%|patched-jsdom is the fastest.| | ||
|compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|481,007 ops/sec ±0.24%|F|8,232 ops/sec ±0.26%|405,841 ops/sec ±1.50%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|162,394 ops/sec ±1.46%|F|7,686 ops/sec ±0.76%|143,901 ops/sec ±1.34%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|7,645 ops/sec ±0.91%|46,398 ops/sec ±1.03%|patched-jsdom is the fastest.| | ||
|simple selector:<br>`matches('.content')`|993,434 ops/sec ±0.92%|7,738 ops/sec ±0.82%|9,388 ops/sec ±0.63%|934,402 ops/sec ±1.24%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|593,746 ops/sec ±0.24%|7,510 ops/sec ±0.73%|9,048 ops/sec ±1.11%|510,470 ops/sec ±0.17%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|7,532 ops/sec ±0.64%|F|148,751 ops/sec ±1.43%|patched-jsdom is the fastest.| | ||
|compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|478,481 ops/sec ±0.32%|7,437 ops/sec ±0.57%|8,922 ops/sec ±0.47%|406,300 ops/sec ±0.32%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|151,608 ops/sec ±0.24%|F|5,749 ops/sec ±0.57%|136,036 ops/sec ±0.46%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,654 ops/sec ±0.57%|40,774 ops/sec ±0.59%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|F|F|6,243 ops/sec ±0.45%|146,879 ops/sec ±1.92%|patched-jsdom is the fastest.| | ||
@@ -269,6 +270,7 @@ ### closest() | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`closest('.container')`|384,943 ops/sec ±0.17%|6,050 ops/sec ±0.26%|8,544 ops/sec ±0.49%|373,062 ops/sec ±2.06%|jsdom is the fastest and 1.0 times faster than patched-jsdom.| | ||
|compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|136,836 ops/sec ±1.49%|F|8,201 ops/sec ±0.65%|133,472 ops/sec ±1.39%|jsdom is the fastest and 1.0 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|151,300 ops/sec ±1.42%|F|7,769 ops/sec ±0.48%|136,348 ops/sec ±1.36%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|7,648 ops/sec ±0.60%|32,514 ops/sec ±0.85%|patched-jsdom is the fastest.| | ||
|simple selector:<br>`closest('.container')`|362,505 ops/sec ±0.41%|7,607 ops/sec ±0.62%|9,365 ops/sec ±0.59%|362,275 ops/sec ±0.39%|jsdom is the fastest and 1.0 times faster than patched-jsdom.| | ||
|compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|137,678 ops/sec ±0.32%|F|8,749 ops/sec ±0.67%|129,174 ops/sec ±0.30%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|139,504 ops/sec ±0.43%|F|5,774 ops/sec ±0.51%|126,287 ops/sec ±0.32%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,710 ops/sec ±0.36%|29,552 ops/sec ±0.90%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|F|4,754 ops/sec ±0.73%|5,935 ops/sec ±0.32%|64,421 ops/sec ±0.98%|patched-jsdom is the fastest.| | ||
@@ -279,6 +281,7 @@ ### querySelector() | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`querySelector('.content')`|36,453 ops/sec ±1.64%|7,377 ops/sec ±0.82%|9,762 ops/sec ±0.43%|30,278 ops/sec ±1.31%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|10,518 ops/sec ±1.26%|7,286 ops/sec ±0.67%|9,400 ops/sec ±0.54%| 9,657 ops/sec ±1.35%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|230 ops/sec ±1.38%|F|1,309 ops/sec ±1.39%|732 ops/sec ±2.31%|linkedom is the fastest and 1.8 times faster than patched-jsdom. patched-jsdom is 3.2 times faster than jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|1,626 ops/sec ±0.28%|493 ops/sec ±2.35%|linkedom is the fastest and 3.3 times faster than patched-jsdom.| | ||
|simple selector:<br>`querySelector('.content')`|28,406 ops/sec ±0.62%|9,286 ops/sec ±0.63%|10,750 ops/sec ±0.59%|25,303 ops/sec ±1.00%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|9,564 ops/sec ±0.33%|8,884 ops/sec ±0.59%|10,834 ops/sec ±0.60%|8,809 ops/sec ±0.53%|linkedom is the fastest and 1.2 times faster than patched-jsdom. jsdom is 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|228 ops/sec ±0.41%|F|1,390 ops/sec ±0.61%|713 ops/sec ±2.32%|linkedom is the fastest and 1.9 times faster than patched-jsdom. patched-jsdom is 3.1 times faster than jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|1,523 ops/sec ±1.72%|494 ops/sec ±1.97%|linkedom is the fastest and 3.1 times faster than patched-jsdom.| | ||
|complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|F|F|9,987 ops/sec ±0.59%|101,461 ops/sec ±1.56%|patched-jsdom is the fastest.| | ||
@@ -289,6 +292,7 @@ ### querySelectorAll() | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`querySelectorAll('.content')`|3,194 ops/sec ±1.32%|794 ops/sec ±1.69%|1,213 ops/sec ±0.20%|3,526 ops/sec ±0.24%|patched-jsdom is the fastest. patched-jsdom is 1.1 times faster than jsdom.| | ||
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|1,056 ops/sec ±0.21%|946 ops/sec ±1.32%|1,166 ops/sec ±1.19%|1,063 ops/sec ±1.09%|linkedom is the fastest and 1.1 times faster than patched-jsdom. patched-jsdom is 1.0 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|233 ops/sec ±1.24%|F|428 ops/sec ±1.25%|819 ops/sec ±1.43%|patched-jsdom is the fastest. patched-jsdom is 3.5 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|460 ops/sec ±0.20%|534 ops/sec ±1.83%|patched-jsdom is the fastest.| | ||
|simple selector:<br>`querySelectorAll('.content')`|2,713 ops/sec ±1.04%|729 ops/sec ±0.29%|1,187 ops/sec ±0.40%|2,988 ops/sec ±0.19%|patched-jsdom is the fastest. patched-jsdom is 1.1 times faster than jsdom.| | ||
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|946 ops/sec ±0.26%|724 ops/sec ±0.35%|1,194 ops/sec ±0.25%|971 ops/sec ±0.25%|linkedom is the fastest and 1.2 times faster than patched-jsdom. patched-jsdom is 1.0 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|225 ops/sec ±1.41%|F|416 ops/sec ±1.46%|818 ops/sec ±1.67%|patched-jsdom is the fastest. patched-jsdom is 3.6 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|443 ops/sec ±1.47%|530 ops/sec ±1.87%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|F|F|525 ops/sec ±0.27%|255 ops/sec ±1.13%|linkedom is the fastest and 2.1 times faster than patched-jsdom.| | ||
@@ -295,0 +299,0 @@ |
@@ -83,5 +83,8 @@ /** | ||
let postHash = selector.substring(index + 1); | ||
const codePoint = postHash.codePointAt(0); | ||
// @see https://drafts.csswg.org/selectors/#id-selectors | ||
// @see https://drafts.csswg.org/css-syntax-3/#ident-token-diagram | ||
if (/^\d$/.test(postHash.substring(0, 1))) { | ||
throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR); | ||
} | ||
const codePoint = postHash.codePointAt(0); | ||
if (codePoint === BIT_HYPHEN) { | ||
@@ -88,0 +91,0 @@ if (/^\d$/.test(postHash.substring(1, 2))) { |
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
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
385837
4375
330