@asamuzakjp/dom-selector
Advanced tools
Comparing version 5.3.4 to 5.4.0
@@ -1,2 +0,2 @@ | ||
var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var j=(S,r)=>{for(var e in r)R(S,e,{get:r[e],enumerable:!0})},q=(S,r,e,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of V(r))!Y.call(S,n)&&n!==e&&R(S,n,{get:()=>r[n],enumerable:!(f=B(r,n))||f.enumerable});return S};var K=S=>q(R({},"__esModule",{value:!0}),S);var Z={};j(Z,{Finder:()=>J});module.exports=K(Z);var F=require("./matcher.js"),g=require("./parser.js"),k=require("./utility.js"),c=require("./constant.js");const E="next",x="prev",X="Tab",O=/^a(?:rea)?$/,M=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,T=/^(?:button|form|input|select|textarea)$/,$=/^(?:details|dialog)$/,I=/^host(?:-context)?$/,C=/^(?:checkbox|radio)$/,P=/^(?:date(?:time-local)?|month|number|range|time|week)$/,D=/^(?:button|reset)$/,U=/^(?:image|submit)$/,Q=/^(?:email|number|password|search|tel|text|url)$/;class J{#l;#c;#w;#t;#f;#n;#k;#o;#b;#h;#e;#d;#g;#m;#N;#s;#u;#_;#r;#p;#i;#a;constructor(r){this.#a=r,this.#h=new F.Matcher,this.#c=new WeakMap,this.#f=new WeakMap,this.#b=new WeakMap,this.#N=new WeakMap,this.#n=null,this.#k=null,this._registerEventListeners()}onError(r,e={}){if(!(e.noexcept??this.#g))if(r instanceof DOMException||r instanceof this.#a.DOMException)if(r.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw new this.#a.DOMException(r.message,r.name);else throw r.name in this.#a?new this.#a[r.name](r.message):r}setup(r,e,f={}){const{event:n,noexcept:a,warn:l}=f;return this.#g=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#u=(0,k.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(r),this.#b=new WeakMap,this.#p=new WeakMap,this.#_=null,this._setEvent(n),e}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],f=["mouseover","mousedown","mouseup","mouseout"];for(const a of f)e.push(this.#a.addEventListener(a,l=>{this.#n=l},r));const n=["keydown","keyup"];for(const a of n)e.push(this.#a.addEventListener(a,l=>{l.key===X&&(this.#n=l)},r));return e.push(this.#a.addEventListener("focusin",a=>{this.#k=a},r)),e}_setEvent(r){return(r instanceof this.#a.KeyboardEvent||r instanceof this.#a.MouseEvent)&&(this.#n=r),this.#n}_correspond(r){const e=[];this.#w=!1,this.#o=!1;let f;if(this.#f.has(this.#t)){const n=this.#f.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);f=a.ast,this.#w=a.descendant,this.#o=a.invalidate}}if(f){const n=f.length;for(let a=0;a<n;a++)f[a].collected=!1,f[a].dir=null,f[a].filtered=!1,f[a].find=!1,e[a]=[]}else{let n;try{n=(0,g.parseSelector)(r)}catch(b){this.onError(b)}const{branches:a,info:l}=(0,g.walkAST)(n),{hasHasPseudoFunc:o,hasLogicalPseudoFunc:u,hasNthChildOfSelector:d}=l;let i=o||!!(u&&d),s=!1,t=0;f=[];for(const[...b]of a){const p=[];let m=b.shift();if(m&&m.type!==c.COMBINATOR){const w=new Set;for(;m;){if(m.type===c.COMBINATOR){const[N]=b;if(N.type===c.COMBINATOR)throw new DOMException(`Invalid selector ${r}`,c.SYNTAX_ERR);const _=m.name;/^[\s>]$/.test(_)?s=!0:i=!0,p.push({combo:m,leaves:(0,g.sortAST)(w)}),w.clear()}else if(m){let{name:N}=m;N&&typeof N=="string"&&(N=(0,g.unescapeSelector)(N),typeof N=="string"&&N!==m.name&&(m.name=N),/[|:]/.test(N)&&(m.namespace=!0)),w.add(m)}if(b.length)m=b.shift();else{p.push({combo:null,leaves:(0,g.sortAST)(w)}),w.clear();break}}}f.push({branch:p,collected:!1,dir:null,filtered:!1,find:!1}),e[t]=[],t++}let h;this.#f.has(this.#t)?h=this.#f.get(this.#t):h=new Map,h.set(`${r}`,{ast:f,descendant:s,invalidate:i}),this.#f.set(this.#t,h),this.#w=s,this.#o=i}return[f,e]}_createTreeWalker(r){let e;return this.#p.has(r)?e=this.#p.get(r):(e=this.#t.createTreeWalker(r,c.WALKER_FILTER),this.#p.set(r,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(r,e,f){const{a:n,b:a,reverse:l,selector:o}=r,{parentNode:u}=e,d=new Set;let i;if(o){if(this.#c.has(o))i=this.#c.get(o);else{const{branches:t}=(0,g.walkAST)(o);i=t,this.#o||this.#c.set(o,i)}const{branches:s}=(0,g.walkAST)(o);i=s}if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();const b=new Set;if(i)for(t=(0,k.traverseNode)(u,s),t=s.firstChild();t;){if((0,k.isVisible)(t)){let p;for(const m of i)if(p=this._matchLeaves(m,t,f),!p)break;p&&b.add(t)}t=s.nextSibling()}if(n===0){if(a>0&&a<=h){if(b.size){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let p=0;for(;t;){if(b.has(t)){if(p===a-1){d.add(t);break}p++}l?t=s.previousSibling():t=s.nextSibling()}}else if(!o){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let p=0;for(;t;){if(p===a-1){d.add(t);break}l?t=s.previousSibling():t=s.nextSibling(),p++}}}}else{let p=a-1;if(n>0)for(;p<0;)p+=n;if(p>=0&&p<h){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0,w=n>0?0:a-1;for(;t&&(t&&p>=0&&p<h);)b.size?b.has(t)&&(w===p&&(d.add(t),p+=n),n>0?w++:w--):m===p&&(o||d.add(t),p+=n),l?t=s.previousSibling():t=s.nextSibling(),m++}}if(l&&d.size>1){const p=[...d];return new Set(p.reverse())}}else if(e===this.#s&&n+a===1)if(i){let s;for(const t of i)if(s=this._matchLeaves(t,e,f),s)break;s&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:f,b:n,reverse:a}=r,{localName:l,namespaceURI:o,parentNode:u,prefix:d}=e,i=new Set;if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();if(f===0){if(n>0&&n<=h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let b=0;for(;t;){const{localName:p,namespaceURI:m,prefix:w}=t;if(p===l&&w===d&&m===o){if(b===n-1){i.add(t);break}b++}a?t=s.previousSibling():t=s.nextSibling()}}}else{let b=n-1;if(f>0)for(;b<0;)b+=f;if(b>=0&&b<h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let p=f>0?0:n-1;for(;t;){const{localName:m,namespaceURI:w,prefix:N}=t;if(m===l&&N===d&&w===o){if(p===b&&(i.add(t),b+=f),b<0||b>=h)break;f>0?p++:p--}a?t=s.previousSibling():t=s.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&f+n===1&&i.add(e);return i}_matchAnPlusB(r,e,f,n){const{nth:{a,b:l,name:o},selector:u}=r,d=new Map;if(o?(o==="even"?(d.set("a",2),d.set("b",0)):o==="odd"&&(d.set("a",2),d.set("b",1)),f.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),f.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(f)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,f={}){let n;if(Array.isArray(r)&&r.length){const a=r.map(t=>t),[l]=a,{type:o}=l;let u;o===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[t]=a,{type:h}=t;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};f.dir=E;const s=this._matchCombinator(i,e,f);if(s.size)if(a.length){for(const t of s)if(n=this._matchHasPseudoFunc(a,t,f),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,f={}){const{astName:n,branches:a,twigBranches:l}=r,{isShadowRoot:o}=f;let u;if(n==="has"){let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,f),d)break;d&&(o?this.#_&&(u=e):u=e)}else{if(o){for(const t of a)if(t.length>1)return null}const d=/^(?:is|where)$/.test(n);f.forgive=d;const i=l.length;let s;for(let t=0;t<i;t++){const h=l[t],b=h.length-1,{leaves:p}=h[b];if(s=this._matchLeaves(p,e,f),s&&b>0){let m=new Set([e]);for(let w=b-1;w>=0;w--){const N=h[w],_=[];f.dir=x;for(const y of m){const v=this._matchCombinator(N,y,f);v.size&&_.push(...v)}if(_.length)w===0?s=!0:m=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(u=e):s&&(u=e)}return u??null}_matchPseudoClassSelector(r,e,f={}){const{children:n,name:a}=r,{localName:l,parentNode:o}=e,{forgive:u,warn:d=this.#i}=f,i=new Set;if(c.REG_LOGICAL.test(a)){let s;if(this.#c.has(r))s=this.#c.get(r);else{const{branches:h}=(0,g.walkAST)(r);if(a==="has"){for(const b of n){const p=(0,g.findAST)(b,m=>c.REG_LOGICAL.test(m.name)&&(0,g.findAST)(m,w=>w.name==="has")?m:null);if(p){if(/^(?:is|where)$/.test(p.name))return i;{const m=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${m}`,c.SYNTAX_ERR)}}}s={astName:a,branches:h}}else{const b=[];for(const[...p]of h){const m=[],w=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(m.push({combo:N,leaves:[...w]}),w.clear()):N&&w.add(N),p.length)N=p.shift();else{m.push({combo:null,leaves:[...w]}),w.clear();break}b.push(m)}s={astName:a,branches:h,twigBranches:b},this.#o||this.#c.set(r,s)}}const t=this._matchLogicalPseudoFunc(s,e,f);t&&i.add(t)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[s]=n;return this._matchAnPlusB(s,e,a,f)}else switch(a){case"dir":case"lang":{const s=this.#h.matchSelector(r,e,f,!0);s&&i.add(s);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:s}]=n;if(s)if(e[s])i.add(e);else for(const t in e){const h=e[t];if(h instanceof this.#a.ElementInternals){h?.states?.has(s)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,c.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{O.test(l)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(O.test(l)&&e.hasAttribute("href")){const{href:s,origin:t,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),s);b.origin===t&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:s,type:t}=this.#n??{};/^(?:mouse|pointer)(?:down|over|up)$/.test(t)&&e.contains(s)&&i.add(e);break}case"active":{const{buttons:s,target:t,type:h}=this.#n??{};/(?:mouse|pointer)down/.test(h)&&s&c.BIT_01&&e.contains(t)&&i.add(e);break}case"target":{const{hash:s}=new URL(this.#t.URL);e.id&&s===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:s}=new URL(this.#t.URL);if(s){const t=s.replace(/^#/,"");let h=this.#t.getElementById(t);for(;h;){if(h===e){i.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&e.tabIndex>=0&&(0,k.isFocusable)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&e.tabIndex>=0){let s;if((0,k.isFocusVisible)(e))s=!0;else{const{target:t,type:h}=this.#n??{},{target:b,relatedTarget:p}=this.#k??{};(/^key(?:down|up)$/.test(h)&&e.contains(t)||p&&(0,k.isFocusVisible)(p)&&e.contains(b))&&(s=!0)}s&&(0,k.isFocusable)(e)&&i.add(e)}break}case"focus-within":{let s,t=this.#t.activeElement;if(t.tabIndex>=0)for(;t;){if(t===e){s=!0;break}t=t.parentNode}s&&(0,k.isFocusable)(e)&&i.add(e);break}case"open":{$.test(l)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{$.test(l)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")o.localName==="optgroup"&&(o.disabled||o.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s&&i.add(e)}}break}case"enabled":{if((M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(o.localName!=="optgroup"||!(o.disabled||o.hasAttribute("disabled")))&&i.add(e);else{let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s||i.add(e)}break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let s;if(e.placeholder?s=e.placeholder:e.hasAttribute("placeholder")&&(s=e.getAttribute("placeholder")),typeof s=="string"&&!/[\r\n]/.test(s)){let t;l==="textarea"?t=e:l==="input"&&(e.hasAttribute("type")?Q.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;t||(t=this.#t.documentElement);const h=t.getElementsByTagName("input"),b=h.length;let p;for(let m=0;m<b;m++){const w=h[m];if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(p=!!w.checked):w.hasAttribute("name")||(p=!!w.checked),p))break}p||i.add(e)}break}case"default":{if(l==="button"&&!(e.hasAttribute("type")&&D.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&U.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const t=this.#r;let h=(0,k.traverseNode)(s,t);for(h=t.firstChild();h&&s.contains(h);){const b=h.localName;let p;if(b==="button"?p=!(h.hasAttribute("type")&&D.test(h.getAttribute("type"))):b==="input"&&(p=h.hasAttribute("type")&&U.test(h.getAttribute("type"))),p){h===e&&i.add(e);break}h=t.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(T.test(l))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h&&i.add(e)}break}case"invalid":{if(T.test(l))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h||i.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&P.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&P.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const s=this.#t.createTreeWalker(e,c.SHOW_ALL);let t=s.firstChild(),h;for(;t&&(h=t.nodeType!==c.ELEMENT_NODE&&t.nodeType!==c.TEXT_NODE,!!h);)t=s.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(o&&e===o.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(o&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(o&&e===o.firstElementChild&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,k.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d)throw new DOMException(`Unsupported pseudo-element ::${a}`,c.NOT_SUPPORTED_ERR);break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":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(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,c.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(r,e){const{children:f,name:n}=r;let a;if(Array.isArray(f)){const{branches:l}=(0,g.walkAST)(f[0]),[o]=l,[...u]=o,{host:d}=e;if(n==="host"){let i;for(const s of u){const{type:t}=s;if(t===c.COMBINATOR){const h=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(s,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,s;for(;i;){for(const t of u){const{type:h}=t;if(h===c.COMBINATOR){const b=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(s=this._matchSelector(t,i).has(i),!s)break}if(s)break;i=i.parentNode}s&&(a=e)}}else if(n==="host")a=e;else throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR);return a??null}_matchSelector(r,e,f={}){const{type:n}=r,a=new Set;if(r.name===c.EMPTY)return a;const l=(0,g.unescapeSelector)(r.name);if(typeof l=="string"&&l!==r.name&&(r.name=l),e.nodeType===c.ELEMENT_NODE)switch(n){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(l,f);break}case c.ID_SELECTOR:{e.id===l&&a.add(e);break}case c.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case c.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(r,e,f);default:{const o=this.#h.matchSelector(r,e,f,!0);o&&a.add(o)}}else if(this.#u&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(c.REG_LOGICAL.test(l))return f.isShadowRoot=!0,this._matchPseudoClassSelector(r,e,f);if(I.test(l)){const o=this._matchShadowHostPseudoClass(r,e,f);o&&(this.#_=!0,a.add(o))}}return a}_matchLeaves(r,e,f){let n,a;if(this.#o?a=this.#b.get(r):a=this.#N.get(r),a&&a.has(e)){const{matched:l}=a.get(e);n=l}if(typeof n!="boolean"){let l=!0;e.nodeType===c.ELEMENT_NODE&&/^(?:button|fieldset|form|input|select|textarea)$/.test(e.localName)&&(l=!1);for(const o of r){switch(o.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{/^(?:(?:any-)?link|defined|dir)$/.test(o.name)&&(l=!1);break}default:}if(n=this._matchSelector(o,e,f).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#o?this.#b.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e={}){const{compound:f,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(f)for(let o=0;o<l;o++){const u=r[o];this._matchLeaves(n,u,e)&&a.add(u)}else{const o=[].slice.call(r);return new Set(o)}return a}_findDescendantNodes(r,e,f){const[n,...a]=r,l=a.length>0,{type:o}=n,u=(0,g.unescapeSelector)(n.name);typeof u=="string"&&u!==n.name&&(n.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(o){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,f);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const s=this.#s.getElementById(u);s&&s!==e&&e.contains(s)&&(l?this._matchLeaves(a,s,f)&&d.add(s):d.add(s))}break}case c.CLASS_SELECTOR:{const s=e.getElementsByClassName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const s=e.getElementsByTagName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,f={}){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:o}=e,{dir:u}=f,d=new Set;if(u===E)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(e,i);for(s=i.nextSibling();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let s=(0,k.traverseNode)(e,i);for(s=i.firstChild();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling();break}case" ":default:{const{nodes:i,pending:s}=this._findDescendantNodes(a,e);if(i.size)return i;if(s){const t=this._createTreeWalker(e);let h=(0,k.traverseNode)(e,t);for(h=t.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,f)&&d.add(h),h=t.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(o,i);for(s=i.firstChild();s&&s!==e;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{o&&this._matchLeaves(a,o,f)&&d.add(o);break}case" ":default:{const i=[];let s=o;for(;s;)this._matchLeaves(a,s,f)&&i.push(s),s=s.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const{node:f}=e,n=this.#m;let a=(0,k.traverseNode)(f,n),l;if(a)for((a.nodeType!==c.ELEMENT_NODE||a===f&&a!==this.#s)&&(a=n.nextNode());a;){if(this._matchLeaves(r,a,{warn:this.#i})){l=a;break}a=n.nextNode()}return l??null}_matchSelf(r){const e=[],f=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return f&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e={}){const{complex:f}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||f){let o=this.#e.parentNode;for(;o&&(a=this._matchLeaves(r,o,{warn:this.#i}),a&&(n.push(o),l=!0),o.parentNode);)o=o.parentNode}return[n,l]}_findFirst(r){const e=[],f=this._findNode(r,{node:this.#e});let n=!1;return f&&(e.push(f),n=!0),[e,n]}_findFromHTMLCollection(r,e={}){const{complex:f,compound:n,filterLeaves:a,targetType:l}=e;let o=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let s=0;s<i;s++){const t=r[s];if(t!==this.#e&&(this.#e.contains(t)||t.contains(this.#e))){if(n){if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else if(o.push(t),u=!0,l===c.TARGET_FIRST)break}}else if(f)if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;else if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;return[o,u,d]}_findEntryNodes(r,e,f){const{leaves:n}=r,[a,...l]=n,o=l.length>0,{name:u,type:d}=a;let i=[],s=!1,t=!1,h=!1;switch(d){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,{warn:this.#i});break}case c.ID_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(o?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),t=!0):(i.push(b),t=!0))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}default:if(e!==c.TARGET_LINEAL&&I.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),t=!0)}}else e===c.TARGET_SELF?[i,t]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,t]=this._findLineal(n,{complex:f}):e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0}return{collected:s,compound:o,filtered:t,nodes:i,pending:h}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const f=new Set;let n=0;for(const{branch:a}of e){const l=a.length,o=l>1,u=a[0];let d,i;if(o){const{combo:m,leaves:[{name:w,type:N}]}=u,_=a[l-1],{leaves:[{name:y,type:v}]}=_;if(v===c.PS_ELEMENT_SELECTOR||v===c.ID_SELECTOR)d=x,i=_;else if(N===c.PS_ELEMENT_SELECTOR||N===c.ID_SELECTOR)d=E,i=u;else if(r===c.TARGET_ALL)if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else if(y==="*"&&v===c.TYPE_SELECTOR)d=E,i=u;else if(l===2){const{name:A}=m;/^[+~]$/.test(A)?(d=x,i=_):(d=E,i=u)}else d=E,i=u;else if(y==="*"&&v===c.TYPE_SELECTOR)d=E,i=u;else if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else{let A;for(const{combo:L,leaves:[W]}of a){const{name:G,type:H}=W;if(H===c.PS_CLASS_SELECTOR&&G==="dir"){A=!1;break}if(!A&&L){const{name:z}=L;/^[+~]$/.test(z)&&(A=!0)}}A?(d=E,i=u):(d=x,i=_)}}else d=x,i=u;const{collected:s,compound:t,filtered:h,nodes:b,pending:p}=this._findEntryNodes(i,r,o);b.length?(this.#l[n].find=!0,this.#d[n]=b):p&&f.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=s,this.#l[n].dir=d,this.#l[n].filtered=h||!t,n++}if(f.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,l=this.#m):(a=this.#s,l=this.#r);let o=(0,k.traverseNode)(a,l);for(;o;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?o===this.#e?u=!0:u=this.#e.contains(o):u=!0,u)for(const d of f){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,o,{warn:this.#i})){const t=d.get("index");this.#l[t].filtered=!0,this.#l[t].find=!0,this.#d[t].push(o)}}o!==l.currentNode&&(o=(0,k.traverseNode)(o,l)),o=l.nextNode()}}}else{let f=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:o,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[f].find=!0,this.#d[f]=d),this.#l[f].dir=x,this.#l[f].filtered=u||!o,f++}}return[this.#l,this.#d]}_getCombinedNodes(r,e,f){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:f,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,f){const{combo:n,index:a}=f,{combo:l,leaves:o}=r[a],u={combo:n,leaves:o},d=this._getCombinedNodes(u,e,E);let i;if(d.size)if(a===r.length-1){const[s]=(0,k.sortNodes)(d);i=s}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,f){const{index:n}=f,a=r[n],l=new Set([e]),o=this._getCombinedNodes(a,l,x);let u;if(o.size){if(n===0)u=e;else for(const d of o)if(this._matchNodePrev(r,d,{index:n-1}))return e}return u??null}find(r){(r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let o=0;o<n;o++){const{branch:u,collected:d,dir:i,find:s}=e[o],t=u.length;if(t&&s){const h=f[o],b=h.length,p=t-1;if(p===0)if((r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this.#e.nodeType===c.ELEMENT_NODE)for(let m=0;m<b;m++){const w=h[m];if(w!==this.#e&&this.#e.contains(w)&&(l.add(w),r!==c.TARGET_ALL))break}else if(r===c.TARGET_ALL)if(l.size){const m=[...l];l=new Set([...m,...h]),a=!0}else l=new Set(h);else{const[m]=h;l.add(m)}else if(r===c.TARGET_ALL)if(i===E){let{combo:m}=u[0];for(const w of h){let N=new Set([w]);for(let _=1;_<t;_++){const{combo:y,leaves:v}=u[_],A={combo:m,leaves:v};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===p)if(l.size){const L=[...l];l=new Set([...L,...N]),a=!0}else l=N;else m=y;else break}}}else for(const m of h){let w=new Set([m]);for(let N=p-1;N>=0;N--){const _=u[N];if(w=this._getCombinedNodes(_,w,i),w.size)N===0&&(l.add(m),t>1&&l.size>1&&(a=!0));else break}}else if(r===c.TARGET_FIRST&&i===E){const{combo:m}=u[0];let w;for(const N of h)if(w=this._matchNodeNext(u,new Set([N]),{combo:m,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:N}=u[0],[_]=h;let y=this._findNode(N,{node:_});for(;y;){if(w=this._matchNodeNext(u,new Set([y]),{combo:m,index:1}),w){l.add(w);break}y=this._findNode(N,{node:y})}}}else{let m;for(const w of h)if(m=this._matchNodePrev(u,w,{index:p-1}),m){l.add(w);break}if(!m&&!d&&r===c.TARGET_FIRST){const{leaves:w}=u[p],[N]=h;let _=this._findNode(w,{node:N});for(;_;){if(m=this._matchNodePrev(u,_,{index:p-1}),m){l.add(_);break}_=this._findNode(w,{node:_})}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,k.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,k.sortNodes)(l)))),l}}0&&(module.exports={Finder}); | ||
var A=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var B=(x,n)=>{for(var e in n)A(x,e,{get:n[e],enumerable:!0})},Y=(x,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of H(n))!z.call(x,r)&&r!==e&&A(x,r,{get:()=>n[r],enumerable:!(o=G(n,r))||o.enumerable});return x};var j=x=>Y(A({},"__esModule",{value:!0}),x);var Z={};B(Z,{Finder:()=>J});module.exports=j(Z);var P=require("./matcher.js"),g=require("./parser.js"),_=require("./utility.js"),c=require("./constant.js");const v="next",S="prev",V="Tab",R=/^a(?:rea)?$/,K=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,O=/^(?:button|form|input|select|textarea)$/,q=/^(?:details|dialog)$/,M=/^host(?:-context)?$/,C=/^(?:checkbox|radio)$/,X=/^(?:date(?:time-local)?|month|number|range|time|week)$/,I=/^(?:button|reset)$/,$=/^(?:image|submit)$/,Q=/^(?:email|number|password|search|tel|text|url)$/;class J{#l;#r;#w;#t;#f;#n;#k;#c;#b;#h;#e;#d;#g;#m;#_;#s;#u;#N;#o;#p;#i;#a;constructor(n){this.#a=n,this.#h=new P.Matcher,this.#r=new WeakMap,this.#f=new WeakMap,this.#b=new WeakMap,this.#_=new WeakMap,this.#n=null,this.#k=null,this._registerEventListeners()}onError(n,e){if(!(e?.noexcept??this.#g))if(n instanceof DOMException||n instanceof this.#a.DOMException)if(n.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(n.message);else throw new this.#a.DOMException(n.message,n.name);else throw n.name in this.#a?new this.#a[n.name](n.message):n}setup(n,e,o={}){const{event:r,noexcept:a,warn:l}=o;return this.#g=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#o]=(0,_.resolveContent)(e),this.#u=(0,_.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(n),this.#b=new WeakMap,this.#p=new WeakMap,this.#N=null,this._setEvent(r),this}_registerEventListeners(){const n={capture:!0,passive:!0},e=[],o=["mouseover","mousedown","mouseup","mouseout"];for(const a of o)e.push(this.#a.addEventListener(a,l=>{this.#n=l},n));const r=["keydown","keyup"];for(const a of r)e.push(this.#a.addEventListener(a,l=>{l.key===V&&(this.#n=l)},n));return e.push(this.#a.addEventListener("focusin",a=>{this.#k=a},n)),e}_setEvent(n){return(n instanceof this.#a.KeyboardEvent||n instanceof this.#a.MouseEvent)&&(this.#n=n),this.#n}_correspond(n){const e=[];this.#w=!1,this.#c=!1;let o;if(this.#f.has(this.#t)){const r=this.#f.get(this.#t);if(r&&r.has(`${n}`)){const a=r.get(`${n}`);o=a.ast,this.#w=a.descendant,this.#c=a.invalidate}}if(o){const r=o.length;for(let a=0;a<r;a++)o[a].collected=!1,o[a].dir=null,o[a].filtered=!1,o[a].find=!1,e[a]=[]}else{let r;try{r=(0,g.parseSelector)(n)}catch(b){this.onError(b)}const{branches:a,info:l}=(0,g.walkAST)(r),{hasHasPseudoFunc:f,hasLogicalPseudoFunc:u,hasNthChildOfSelector:d}=l;let i=f||!!(u&&d),t=!1,s=0;o=[];for(const[...b]of a){const p=[];let m=b.shift();if(m&&m.type!==c.COMBINATOR){const w=new Set;for(;m;){if(m.type===c.COMBINATOR){const[k]=b;if(k.type===c.COMBINATOR)throw new DOMException(`Invalid selector ${n}`,c.SYNTAX_ERR);const N=m.name;/^[\s>]$/.test(N)?t=!0:i=!0,p.push({combo:m,leaves:(0,g.sortAST)(w)}),w.clear()}else if(m){let{name:k}=m;k&&typeof k=="string"&&(k=(0,g.unescapeSelector)(k),typeof k=="string"&&k!==m.name&&(m.name=k),/[|:]/.test(k)&&(m.namespace=!0)),w.add(m)}if(b.length)m=b.shift();else{p.push({combo:null,leaves:(0,g.sortAST)(w)}),w.clear();break}}}o.push({branch:p,collected:!1,dir:null,filtered:!1,find:!1}),e[s]=[],s++}let h;this.#f.has(this.#t)?h=this.#f.get(this.#t):h=new Map,h.set(`${n}`,{ast:o,descendant:t,invalidate:i}),this.#f.set(this.#t,h),this.#w=t,this.#c=i}return[o,e]}_createTreeWalker(n){let e;return this.#p.has(n)?e=this.#p.get(n):(e=this.#t.createTreeWalker(n,c.WALKER_FILTER),this.#p.set(n,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(n,e,o){const{a:r,b:a,reverse:l,selector:f}=n,{parentNode:u}=e,d=new Set;let i;if(f){if(this.#r.has(f))i=this.#r.get(f);else{const{branches:s}=(0,g.walkAST)(f);i=s,this.#c||this.#r.set(f,i)}const{branches:t}=(0,g.walkAST)(f);i=t}if(u){const t=this.#o;let s=(0,_.traverseNode)(u,t);s=t.firstChild();let h=0;for(;s;)h++,s=t.nextSibling();const b=new Set;if(i)for(s=(0,_.traverseNode)(u,t),s=t.firstChild();s;){if((0,_.isVisible)(s)){let p;for(const m of i)if(p=this._matchLeaves(m,s,o),!p)break;p&&b.add(s)}s=t.nextSibling()}if(r===0){if(a>0&&a<=h){if(b.size){s=(0,_.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let p=0;for(;s;){if(b.has(s)){if(p===a-1){d.add(s);break}p++}l?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,_.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let p=0;for(;s;){if(p===a-1){d.add(s);break}l?s=t.previousSibling():s=t.nextSibling(),p++}}}}else{let p=a-1;if(r>0)for(;p<0;)p+=r;if(p>=0&&p<h){s=(0,_.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let m=0,w=r>0?0:a-1;for(;s&&(s&&p>=0&&p<h);)b.size?b.has(s)&&(w===p&&(d.add(s),p+=r),r>0?w++:w--):m===p&&(f||d.add(s),p+=r),l?s=t.previousSibling():s=t.nextSibling(),m++}}if(l&&d.size>1){const p=[...d];return new Set(p.reverse())}}else if(e===this.#s&&r+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,o),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(n,e){const{a:o,b:r,reverse:a}=n,{localName:l,namespaceURI:f,parentNode:u,prefix:d}=e,i=new Set;if(u){const t=this.#o;let s=(0,_.traverseNode)(u,t);s=t.firstChild();let h=0;for(;s;)h++,s=t.nextSibling();if(o===0){if(r>0&&r<=h){s=(0,_.traverseNode)(u,t),a?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){const{localName:p,namespaceURI:m,prefix:w}=s;if(p===l&&w===d&&m===f){if(b===r-1){i.add(s);break}b++}a?s=t.previousSibling():s=t.nextSibling()}}}else{let b=r-1;if(o>0)for(;b<0;)b+=o;if(b>=0&&b<h){s=(0,_.traverseNode)(u,t),a?s=t.lastChild():s=t.firstChild();let p=o>0?0:r-1;for(;s;){const{localName:m,namespaceURI:w,prefix:k}=s;if(m===l&&k===d&&w===f){if(p===b&&(i.add(s),b+=o),b<0||b>=h)break;o>0?p++:p--}a?s=t.previousSibling():s=t.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&o+r===1&&i.add(e);return i}_matchAnPlusB(n,e,o,r){const{nth:{a,b:l,name:f},selector:u}=n,d=new Map;if(f?(f==="even"?(d.set("a",2),d.set("b",0)):f==="odd"&&(d.set("a",2),d.set("b",1)),o.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),o.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(o)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,r)}else if(/^nth-(?:last-)?of-type$/.test(o)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(n,e,o){let r;if(Array.isArray(n)&&n.length){const a=n.map(s=>s),[l]=a,{type:f}=l;let u;f===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:h}=s;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};o.dir=v;const t=this._matchCombinator(i,e,o);if(t.size)if(a.length){for(const s of t)if(r=this._matchHasPseudoFunc(a,s,o),r)break}else r=!0}return!!r}_matchLogicalPseudoFunc(n,e,o){const{astName:r,branches:a,twigBranches:l}=n,{isShadowRoot:f}=o;let u;if(r==="has"){let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,o),d)break;d&&(f?this.#N&&(u=e):u=e)}else{if(f){for(const s of a)if(s.length>1)return null}const d=/^(?:is|where)$/.test(r);o.forgive=d;const i=l.length;let t;for(let s=0;s<i;s++){const h=l[s],b=h.length-1,{leaves:p}=h[b];if(t=this._matchLeaves(p,e,o),t&&b>0){let m=new Set([e]);for(let w=b-1;w>=0;w--){const k=h[w],N=[];o.dir=S;for(const E of m){const y=this._matchCombinator(k,E,o);y.size&&N.push(...y)}if(N.length)w===0?t=!0:m=new Set(N);else{t=!1;break}}}if(t)break}r==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(n,e,o){const{children:r,name:a}=n,{localName:l,parentNode:f}=e,{forgive:u,warn:d=this.#i}=o,i=new Set;if(c.REG_LOGICAL.test(a)){let t;if(this.#r.has(n))t=this.#r.get(n);else{const{branches:h}=(0,g.walkAST)(n);if(a==="has"){for(const b of r){const p=(0,g.findAST)(b,m=>c.REG_LOGICAL.test(m.name)&&(0,g.findAST)(m,w=>w.name==="has")?m:null);if(p){if(/^(?:is|where)$/.test(p.name))return i;{const m=(0,g.generateCSS)(n);throw new DOMException(`Invalid selector ${m}`,c.SYNTAX_ERR)}}}t={astName:a,branches:h}}else{const b=[];for(const[...p]of h){const m=[],w=new Set;let k=p.shift();for(;k;)if(k.type===c.COMBINATOR?(m.push({combo:k,leaves:[...w]}),w.clear()):k&&w.add(k),p.length)k=p.shift();else{m.push({combo:null,leaves:[...w]}),w.clear();break}b.push(m)}t={astName:a,branches:h,twigBranches:b},this.#c||this.#r.set(n,t)}}const s=this._matchLogicalPseudoFunc(t,e,o);s&&i.add(s)}else if(Array.isArray(r))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=r;return this._matchAnPlusB(t,e,a,o)}else switch(a){case"dir":case"lang":{const t=this.#h.matchSelector(n,e,o,!0);t&&i.add(t);break}case"state":{if((0,_.isCustomElement)(e)){const[{value:t}]=r;if(t)if(e[t])i.add(e);else for(const s in e){const h=e[s];if(h instanceof this.#a.ElementInternals){h?.states?.has(t)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,c.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{R.test(l)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(R.test(l)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),t);b.origin===s&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#n??{};/^(?:mouse|pointer)(?:down|over|up)$/.test(s)&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:h}=this.#n??{};/(?:mouse|pointer)down/.test(h)&&t&c.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#t.URL);e.id&&t===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#t.URL);if(t){const s=t.replace(/^#/,"");let h=this.#t.getElementById(s);for(;h;){if(h===e){i.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&e.tabIndex>=0&&(0,_.isFocusable)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&e.tabIndex>=0){let t;if((0,_.isFocusVisible)(e))t=!0;else{const{target:s,type:h}=this.#n??{},{target:b,relatedTarget:p}=this.#k??{};(/^key(?:down|up)$/.test(h)&&e.contains(s)||p&&(0,_.isFocusVisible)(p)&&e.contains(b))&&(t=!0)}t&&(0,_.isFocusable)(e)&&i.add(e)}break}case"focus-within":{let t,s=this.#t.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}t&&(0,_.isFocusable)(e)&&i.add(e);break}case"open":case"closed":{q.test(l)&&(e.hasAttribute("open")?a==="open"&&i.add(e):a==="closed"&&i.add(e));break}case"disabled":case"enabled":{if(K.test(l)||(0,_.isCustomElement)(e,{formAssociated:!0})){let t;if(e.disabled||e.hasAttribute("disabled"))t=!0;else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&(t=!0);else if(e.localName!=="optgroup"){let s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const h=this.#o;let b=(0,_.traverseNode)(s,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===c.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}}t?a==="disabled"&&i.add(e):a==="enabled"&&i.add(e)}break}case"read-only":case"read-write":{let t,s;switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0;break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0);break}default:(0,_.isContentEditable)(e)?s=!0:t=!0}t?a==="read-only"&&i.add(e):a==="read-write"&&s&&i.add(e);break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;l==="textarea"?s=e:l==="input"&&(e.hasAttribute("type")?Q.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#t.documentElement);const h=s.getElementsByTagName("input"),b=h.length;let p;for(let m=0;m<b;m++){const w=h[m];if(w.getAttribute("type")==="radio"&&(t?w.getAttribute("name")===t&&(p=!!w.checked):w.hasAttribute("name")||(p=!!w.checked),p))break}p||i.add(e)}break}case"default":{if(l==="button"&&!(e.hasAttribute("type")&&I.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#o;let h=(0,_.traverseNode)(t,s);for(h=s.firstChild();h&&t.contains(h);){const b=h.localName;let p;if(b==="button"?p=!(h.hasAttribute("type")&&I.test(h.getAttribute("type"))):b==="input"&&(p=h.hasAttribute("type")&&$.test(h.getAttribute("type"))),p){h===e&&i.add(e);break}h=s.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":case"invalid":{if(O.test(l)){let t;e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&(t=!0):t=!0),t?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}else if(l==="fieldset"){const t=this.#o;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let h;if(!s)h=!0;else for(;s&&e.contains(s)&&!(O.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?h=s.maxLength>=s.value.length:h=!0:h=!1,!h));)s=t.nextNode();h?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}break}case"in-range":case"out-of-range":{if(l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&X.test(e.getAttribute("type"))){let t;!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&(t=!0),t?a==="in-range"&&i.add(e):a==="out-of-range"&&i.add(e)}break}case"required":case"optional":{let t;if(/^(?:select|textarea)$/.test(l))t=e;else if(l==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||C.test(s)||c.REG_INPUT_TYPE.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required")?a==="required"&&i.add(e):a==="optional"&&i.add(e));break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#t.createTreeWalker(e,c.SHOW_ALL);let s=t.firstChild(),h;for(;s&&(h=s.nodeType!==c.ELEMENT_NODE&&s.nodeType!==c.TEXT_NODE,!!h);)s=t.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,_.isCustomElement)(e)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,_.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d)throw new DOMException(`Unsupported pseudo-element ::${a}`,c.NOT_SUPPORTED_ERR);break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":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(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,c.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(n,e){const{children:o,name:r}=n;let a;if(Array.isArray(o)){const{branches:l}=(0,g.walkAST)(o[0]),[f]=l,[...u]=f,{host:d}=e;if(r==="host"){let i;for(const t of u){const{type:s}=t;if(s===c.COMBINATOR){const h=(0,g.generateCSS)(n);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(a=e)}else if(r==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:h}=s;if(h===c.COMBINATOR){const b=(0,g.generateCSS)(n);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(a=e)}}else if(r==="host")a=e;else throw new DOMException(`Invalid selector :${r}`,c.SYNTAX_ERR);return a??null}_matchSelector(n,e,o={}){const{type:r}=n,a=new Set;if(n.name===c.EMPTY)return a;const l=(0,g.unescapeSelector)(n.name);if(typeof l=="string"&&l!==n.name&&(n.name=l),e.nodeType===c.ELEMENT_NODE)switch(r){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(l,o);break}case c.ID_SELECTOR:{e.id===l&&a.add(e);break}case c.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case c.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(n,e,o);default:{const f=this.#h.matchSelector(n,e,o,!0);f&&a.add(f)}}else if(this.#u&&r===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(c.REG_LOGICAL.test(l))return o.isShadowRoot=!0,this._matchPseudoClassSelector(n,e,o);if(M.test(l)){const f=this._matchShadowHostPseudoClass(n,e,o);f&&(this.#N=!0,a.add(f))}}return a}_matchLeaves(n,e,o){let r,a;if(this.#c?a=this.#b.get(n):a=this.#_.get(n),a&&a.has(e)){const{matched:l}=a.get(e);r=l}if(typeof r!="boolean"){let l=!0;e.nodeType===c.ELEMENT_NODE&&/^(?:button|fieldset|form|input|select|textarea)$/.test(e.localName)&&(l=!1);for(const f of n){switch(f.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{/^(?:(?:any-)?link|defined|dir)$/.test(f.name)&&(l=!1);break}default:}if(r=this._matchSelector(f,e,o).has(e),!r)break}l&&(a||(a=new WeakMap),a.set(e,{matched:r}),this.#c?this.#b.set(n,a):this.#_.set(n,a))}return!!r}_matchHTMLCollection(n,e){const{compound:o,filterLeaves:r}=e,a=new Set,l=n.length;if(l)if(o)for(let f=0;f<l;f++){const u=n[f];this._matchLeaves(r,u,e)&&a.add(u)}else{const f=[].slice.call(n);return new Set(f)}return a}_findDescendantNodes(n,e,o){const[r,...a]=n,l=a.length>0,{type:f}=r,u=(0,g.unescapeSelector)(r.name);typeof u=="string"&&u!==r.name&&(r.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(f){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,o);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(u);t&&t!==e&&e.contains(t)&&(l?this._matchLeaves(a,t,o)&&d.add(t):d.add(t))}break}case c.CLASS_SELECTOR:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(n,e,o){const{combo:r,leaves:a}=n,{name:l}=r,{parentNode:f}=e,{dir:u}=o,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,o)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,_.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,_.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let h=(0,_.traverseNode)(e,s);for(h=s.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,o)&&d.add(h),h=s.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,o)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,_.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(a,f,o)&&d.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(a,t,o)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(n,e){const o=this.#m;let r=(0,_.traverseNode)(e,o),a;if(r)for((r.nodeType!==c.ELEMENT_NODE||r===e&&r!==this.#s)&&(r=o.nextNode());r;){if(this._matchLeaves(n,r,{warn:this.#i})){a=r;break}r=o.nextNode()}return a??null}_matchSelf(n){const e=[],o=this._matchLeaves(n,this.#e,{warn:this.#i});let r=!1;return o&&(e.push(this.#e),r=!0),[e,r]}_findLineal(n,e){const{complex:o}=e,r=[];let a=this._matchLeaves(n,this.#e,{warn:this.#i}),l=!1;if(a&&(r.push(this.#e),l=!0),!a||o){let f=this.#e.parentNode;for(;f&&(a=this._matchLeaves(n,f,{warn:this.#i}),a&&(r.push(f),l=!0),f.parentNode);)f=f.parentNode}return[r,l]}_findFirst(n){const e=[],o=this._findNode(n,this.#e);let r=!1;return o&&(e.push(o),r=!0),[e,r]}_findFromHTMLCollection(n,e){const{complex:o,compound:r,filterLeaves:a,targetType:l}=e;let f=[],u=!1,d=!1;const i=n.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<i;t++){const s=n[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(r){if(this._matchLeaves(a,s,{warn:this.#i})&&(f.push(s),u=!0,l===c.TARGET_FIRST))break}else if(f.push(s),u=!0,l===c.TARGET_FIRST)break}}else if(o)if(r)for(let t=0;t<i;t++){const s=n[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(f.push(s),u=!0,l===c.TARGET_FIRST))break}else f=[].slice.call(n),u=!0,d=!0;else if(r)for(let t=0;t<i;t++){const s=n[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(f.push(s),u=!0,l===c.TARGET_FIRST))break}else f=[].slice.call(n),u=!0,d=!0;return[f,u,d]}_findEntryNodes(n,e,o){const{leaves:r}=n,[a,...l]=r,f=l.length>0,{name:u,type:d}=a;let i=[],t=!1,s=!1,h=!1;switch(d){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,{warn:this.#i});break}case c.ID_SELECTOR:{if(e===c.TARGET_SELF)[i,s]=this._matchSelf(r);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(r,{complex:o});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(f?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),s=!0):(i.push(b),s=!0))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(r):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,s]=this._matchSelf(r);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(r,{complex:o});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,s,t]=this._findFromHTMLCollection(b,{complex:o,compound:f,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(r):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,s]=this._matchSelf(r);else if(e===c.TARGET_LINEAL)[i,s]=this._findLineal(r,{complex:o});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,s,t]=this._findFromHTMLCollection(b,{complex:o,compound:f,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,s]=this._findFirst(r):h=!0;break}default:if(e!==c.TARGET_LINEAL&&M.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),s=!0)}}else e===c.TARGET_SELF?[i,s]=this._matchSelf(r):e===c.TARGET_LINEAL?[i,s]=this._findLineal(r,{complex:o}):e===c.TARGET_FIRST?[i,s]=this._findFirst(r):h=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:h}}_collectNodes(n){const e=this.#l.values();if(n===c.TARGET_ALL||n===c.TARGET_FIRST){const o=new Set;let r=0;for(const{branch:a}of e){const l=a.length,f=l>1,u=a[0];let d,i;if(f){const{combo:m,leaves:[{name:w,type:k}]}=u,N=a[l-1],{leaves:[{name:E,type:y}]}=N;if(y===c.PS_ELEMENT_SELECTOR||y===c.ID_SELECTOR)d=S,i=N;else if(k===c.PS_ELEMENT_SELECTOR||k===c.ID_SELECTOR)d=v,i=u;else if(n===c.TARGET_ALL)if(w==="*"&&k===c.TYPE_SELECTOR)d=S,i=N;else if(E==="*"&&y===c.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:L}=m;/^[+~]$/.test(L)?(d=S,i=N):(d=v,i=u)}else d=v,i=u;else if(E==="*"&&y===c.TYPE_SELECTOR)d=v,i=u;else if(w==="*"&&k===c.TYPE_SELECTOR)d=S,i=N;else{let L;for(const{combo:T,leaves:[D]}of a){const{name:U,type:F}=D;if(F===c.PS_CLASS_SELECTOR&&U==="dir"){L=!1;break}if(!L&&T){const{name:W}=T;/^[+~]$/.test(W)&&(L=!0)}}L?(d=v,i=u):(d=S,i=N)}}else d=S,i=u;const{collected:t,compound:s,filtered:h,nodes:b,pending:p}=this._findEntryNodes(i,n,f);b.length?(this.#l[r].find=!0,this.#d[r]=b):p&&o.add(new Map([["index",r],["twig",i]])),this.#l[r].collected=t,this.#l[r].dir=d,this.#l[r].filtered=h||!s,r++}if(o.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,l=this.#m):(a=this.#s,l=this.#o);let f=(0,_.traverseNode)(a,l);for(;f;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?f===this.#e?u=!0:u=this.#e.contains(f):u=!0,u)for(const d of o){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=d.get("index");this.#l[s].filtered=!0,this.#l[s].find=!0,this.#d[s].push(f)}}f!==l.currentNode&&(f=(0,_.traverseNode)(f,l)),f=l.nextNode()}}}else{let o=0;for(const{branch:r}of e){const a=r[r.length-1],l=r.length>1,{compound:f,filtered:u,nodes:d}=this._findEntryNodes(a,n,l);d.length&&(this.#l[o].find=!0,this.#d[o]=d),this.#l[o].dir=S,this.#l[o].filtered=u||!f,o++}}return[this.#l,this.#d]}_getCombinedNodes(n,e,o){const r=[];for(const a of e){const l=this._matchCombinator(n,a,{dir:o,warn:this.#i});l.size&&r.push(...l)}return r.length?new Set(r):new Set}_matchNodeNext(n,e,o){const{combo:r,index:a}=o,{combo:l,leaves:f}=n[a],u={combo:r,leaves:f},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===n.length-1){const[t]=(0,_.sortNodes)(d);i=t}else i=this._matchNodeNext(n,d,{combo:l,index:a+1});return i??null}_matchNodePrev(n,e,o){const{index:r}=o,a=n[r],l=new Set([e]),f=this._getCombinedNodes(a,l,S);let u;if(f.size){if(r===0)u=e;else for(const d of f)if(this._matchNodePrev(n,d,{index:r-1}))return e}return u??null}find(n){(n===c.TARGET_ALL||n===c.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],o]=this._collectNodes(n),r=e.length;let a,l=new Set;for(let f=0;f<r;f++){const{branch:u,collected:d,dir:i,find:t}=e[f],s=u.length;if(s&&t){const h=o[f],b=h.length,p=s-1;if(p===0)if((n===c.TARGET_ALL||n===c.TARGET_FIRST)&&this.#e.nodeType===c.ELEMENT_NODE)for(let m=0;m<b;m++){const w=h[m];if(w!==this.#e&&this.#e.contains(w)&&(l.add(w),n!==c.TARGET_ALL))break}else if(n===c.TARGET_ALL)if(l.size){const m=[...l];l=new Set([...m,...h]),a=!0}else l=new Set(h);else{const[m]=h;l.add(m)}else if(n===c.TARGET_ALL)if(i===v){let{combo:m}=u[0];for(const w of h){let k=new Set([w]);for(let N=1;N<s;N++){const{combo:E,leaves:y}=u[N],L={combo:m,leaves:y};if(k=this._getCombinedNodes(L,k,i),k.size)if(N===p)if(l.size){const T=[...l];l=new Set([...T,...k]),a=!0}else l=k;else m=E;else break}}}else for(const m of h){let w=new Set([m]);for(let k=p-1;k>=0;k--){const N=u[k];if(w=this._getCombinedNodes(N,w,i),w.size)k===0&&(l.add(m),s>1&&l.size>1&&(a=!0));else break}}else if(n===c.TARGET_FIRST&&i===v){const{combo:m}=u[0];let w;for(const k of h)if(w=this._matchNodeNext(u,new Set([k]),{combo:m,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:k}=u[0],[N]=h;let E=this._findNode(k,N);for(;E;){if(w=this._matchNodeNext(u,new Set([E]),{combo:m,index:1}),w){l.add(w);break}E=this._findNode(k,E)}}}else{let m;for(const w of h)if(m=this._matchNodePrev(u,w,{index:p-1}),m){l.add(w);break}if(!m&&!d&&n===c.TARGET_FIRST){const{leaves:w}=u[p],[k]=h;let N=this._findNode(w,k);for(;N;){if(m=this._matchNodePrev(u,N,{index:p-1}),m){l.add(N);break}N=this._findNode(w,N)}}}}}return n===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,_.sortNodes)(l)))):n===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,_.sortNodes)(l)))),l}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -44,3 +44,3 @@ { | ||
"eslint-plugin-unicorn": "^55.0.0", | ||
"happy-dom": "^15.7.0", | ||
"happy-dom": "^15.7.3", | ||
"jsdom": "^25.0.0", | ||
@@ -67,3 +67,3 @@ "linkedom": "^0.18.4", | ||
}, | ||
"version": "5.3.4" | ||
"version": "5.4.0" | ||
} |
@@ -289,41 +289,41 @@ # DOM Selector | ||
|Selector|jsdom v24.1.1 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|Selector|jsdom v25.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`matches('.content')`|1,031,169 ops/sec ±0.30%|7,650 ops/sec ±0.75%|9,438 ops/sec ±0.58%|828,526 ops/sec ±0.28%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|603,664 ops/sec ±1.24%|7,430 ops/sec ±0.65%|8,923 ops/sec ±0.98%|400,799 ops/sec ±0.31%|jsdom is the fastest and 1.5 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|7,358 ops/sec ±1.45%|F|73,167 ops/sec ±0.99%|patched-jsdom is the fastest.| | ||
|compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|478,859 ops/sec ±1.56%|7,312 ops/sec ±1.24%|8,786 ops/sec ±0.75%|338,833 ops/sec ±1.37%|jsdom is the fastest and 1.4 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|154,200 ops/sec ±1.15%|F|5,852 ops/sec ±0.74%|127,543 ops/sec ±1.23%|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:has(> .content)')`|F|F|5,792 ops/sec ±0.81%|18,981 ops/sec ±1.80%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|414,939 ops/sec ±1.14%|F|6,158 ops/sec ±0.44%|332,506 ops/sec ±0.26%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|simple selector:<br>`matches('.content')`|937,822 ops/sec ±0.50%|7,910,671 ops/sec ±0.27%|8,620 ops/sec ±0.75%|772,780 ops/sec ±0.30%|happydom is the fastest and 10.2 times faster than patched-jsdom. jsdom is 1.2 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|572,176 ops/sec ±0.38%|7,693,760 ops/sec ±1.88%|8,257 ops/sec ±0.63%|402,508 ops/sec ±0.21%|happydom is the fastest and 19.1 times faster than patched-jsdom. jsdom is 1.4 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|6,987,723 ops/sec ±0.39%|F|74,756 ops/sec ±1.26%|happydom is the fastest and 93.5 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|455,833 ops/sec ±1.90%|6,645,611 ops/sec ±1.63%|8,205 ops/sec ±1.12%|326,773 ops/sec ±1.38%|happydom is the fastest and 20.3 times faster than patched-jsdom. jsdom is 1.4 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|144,430 ops/sec ±1.65%|F|5,445 ops/sec ±1.00%|121,298 ops/sec ±1.34%|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:has(> .content)')`|F|F|5,337 ops/sec ±0.86%|17,419 ops/sec ±2.05%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|398,206 ops/sec ±0.51%|F|5,719 ops/sec ±0.84%|326,625 ops/sec ±1.25%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
### closest() | ||
|Selector|jsdom v24.1.1 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|Selector|jsdom v25.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`closest('.container')`|376,552 ops/sec ±1.42%|7,476 ops/sec ±0.84%|9,281 ops/sec ±0.63%|340,692 ops/sec ±1.37%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|138,076 ops/sec ±1.49%|F|8,643 ops/sec ±0.96%|121,489 ops/sec ±1.12%|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')`|141,376 ops/sec ±1.33%|F|5,795 ops/sec ±0.80%|120,433 ops/sec ±1.28%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|5,723 ops/sec ±0.73%|15,392 ops/sec ±1.58%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|194,922 ops/sec ±1.40%|4,752 ops/sec ±1.20%|6,139 ops/sec ±0.35%|176,281 ops/sec ±0.32%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|simple selector:<br>`closest('.container')`|357,783 ops/sec ±1.70%|2,319,384 ops/sec ±0.92%|8,581 ops/sec ±0.84%|328,849 ops/sec ±1.31%|happydom is the fastest and 7.1 times faster than patched-jsdom. jsdom is 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|131,236 ops/sec ±0.73%|F|8,052 ops/sec ±0.95%|119,653 ops/sec ±1.44%|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')`|137,291 ops/sec ±0.17%|F|5,483 ops/sec ±0.36%|116,733 ops/sec ±0.21%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|5,354 ops/sec ±0.87%|14,363 ops/sec ±1.58%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|190,643 ops/sec ±1.69%|2,819,109 ops/sec ±1.22%|5,732 ops/sec ±0.34%|169,772 ops/sec ±1.48%|happydom is the fastest and 16.6 times faster than patched-jsdom. jsdom is 1.1 times faster than patched-jsdom.| | ||
### querySelector() | ||
|Selector|jsdom v24.1.1 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|Selector|jsdom v25.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`querySelector('.content')`|27,103 ops/sec ±0.78%|9,293 ops/sec ±0.55%|11,341 ops/sec ±0.46%|30,262 ops/sec ±0.23%|patched-jsdom is the fastest. patched-jsdom is 1.1 times faster than jsdom.| | ||
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|10,072 ops/sec ±1.46%|9,055 ops/sec ±0.95%|10,058 ops/sec ±0.84%|9,716 ops/sec ±1.34%|jsdom is the fastest and 1.0 times faster than patched-jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|225 ops/sec ±0.61%|F|1,267 ops/sec ±1.48%|271 ops/sec ±1.37%|linkedom is the fastest and 4.7 times faster than patched-jsdom. patched-jsdom is 1.2 times faster than jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|1,611 ops/sec ±1.52%|730 ops/sec ±1.58%|linkedom is the fastest and 2.2 times faster than patched-jsdom.| | ||
|complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|3,152 ops/sec ±2.67%|F|9,906 ops/sec ±0.94%|159,199 ops/sec ±1.91%|patched-jsdom is the fastest. patched-jsdom is 50.5 times faster than jsdom.| | ||
|simple selector:<br>`querySelector('.content')`|30,752 ops/sec ±1.40%|3,402,064 ops/sec ±1.11%|10,466 ops/sec ±0.91%|30,353 ops/sec ±1.46%|happydom is the fastest and 112.1 times faster than patched-jsdom. jsdom is 1.0 times faster than patched-jsdom.| | ||
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|9,716 ops/sec ±1.63%|3,318,668 ops/sec ±1.19%|9,481 ops/sec ±0.59%|9,123 ops/sec ±0.47%|happydom is the fastest and 363.8 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')`|219 ops/sec ±1.75%|F|1,270 ops/sec ±0.34%|779 ops/sec ±2.08%|linkedom is the fastest and 1.6 times faster than patched-jsdom. patched-jsdom is 3.6 times faster than jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|1,532 ops/sec ±1.81%|516 ops/sec ±1.93%|linkedom is the fastest and 3.0 times faster than patched-jsdom.| | ||
|complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|3,215 ops/sec ±0.60%|F|9,656 ops/sec ±1.10%|159,781 ops/sec ±2.23%|patched-jsdom is the fastest. patched-jsdom is 49.7 times faster than jsdom.| | ||
### querySelectorAll() | ||
|Selector|jsdom v24.1.1 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|Selector|jsdom v25.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`querySelectorAll('.content')`|2,684 ops/sec ±1.00%|758 ops/sec ±1.65%|1,231 ops/sec ±1.45%|3,131 ops/sec ±0.90%|patched-jsdom is the fastest. patched-jsdom is 1.2 times faster than jsdom.| | ||
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|958 ops/sec ±0.29%|686 ops/sec ±1.79%|1,171 ops/sec ±1.23%|996 ops/sec ±1.17%|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')`|210 ops/sec ±1.78%|F|421 ops/sec ±1.53%|240 ops/sec ±1.51%|linkedom is the fastest and 1.8 times faster than patched-jsdom. patched-jsdom is 1.1 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|442 ops/sec ±1.84%|823 ops/sec ±1.64%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|302 ops/sec ±1.43%|F|518 ops/sec ±1.47%|785 ops/sec ±0.98%|patched-jsdom is the fastest. patched-jsdom is 2.6 times faster than jsdom.| | ||
|simple selector:<br>`querySelectorAll('.content')`|3,145 ops/sec ±1.24%|7,471,952 ops/sec ±0.97%|1,187 ops/sec ±0.18%|3,330 ops/sec ±0.40%|happydom is the fastest and 2244.1 times faster than patched-jsdom. patched-jsdom is 1.1 times faster than jsdom.| | ||
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|969 ops/sec ±1.23%|6,444,347 ops/sec ±0.86%|1,155 ops/sec ±1.22%|993 ops/sec ±0.21%|happydom is the fastest and 6486.9 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')`|221 ops/sec ±1.66%|F|418 ops/sec ±1.84%|905 ops/sec ±1.45%|patched-jsdom is the fastest. patched-jsdom is 4.1 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner:has(> .content)')`|F|F|454 ops/sec ±0.15%|567 ops/sec ±1.60%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|295 ops/sec ±1.89%|F|515 ops/sec ±1.81%|790 ops/sec ±1.60%|patched-jsdom is the fastest. patched-jsdom is 2.7 times faster than jsdom.| | ||
@@ -330,0 +330,0 @@ |
@@ -586,3 +586,3 @@ /** | ||
} | ||
// filter missing close square bracket | ||
// exclude missing close square bracket | ||
if (selector.includes('[')) { | ||
@@ -595,5 +595,5 @@ const index = selector.lastIndexOf('['); | ||
} | ||
// filter namespace selector, escaped selector, pseudo-element selector, | ||
// selector containing non-ASCII or control character other than whitespace, | ||
// attribute selector with case flag, e.g. [attr i], or with unclosed quotes, | ||
// exclude namespaced selectors, escaped selectors, pseudo-element selectors, | ||
// selectors containing non-ASCII or control character other than whitespace, | ||
// attribute selectors with case flag, e.g. [attr i], or with unclosed quotes, | ||
// and empty :is() or :where() | ||
@@ -603,3 +603,3 @@ if (/[|\\]|::|[^\u0021-\u007F\s]|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]|:(?:is|where)\(\s*\)/.test(selector)) { | ||
} | ||
// filter pseudo-classes | ||
// include pseudo-classes that are known to work correctly | ||
if (selector.includes(':')) { | ||
@@ -606,0 +606,0 @@ const { complex, descend } = opt; |
export class Finder { | ||
constructor(window: object); | ||
onError(e: Error, opt?: object): void; | ||
onError(e: Error, opt: object): void; | ||
setup(selector: string, node: object, opt?: { | ||
@@ -5,0 +5,0 @@ event?: object; |
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
431276
4877