Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asamuzakjp/dom-selector

Package Overview
Dependencies
Maintainers
1
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asamuzakjp/dom-selector - npm Package Compare versions

Comparing version 5.0.5 to 5.0.7

2

dist/cjs/js/finder.js

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

var T=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var U=(x,c)=>{for(var e in c)T(x,e,{get:c[e],enumerable:!0})},F=(x,c,e,h)=>{if(c&&typeof c=="object"||typeof c=="function")for(let o of I(c))!$.call(x,o)&&o!==e&&T(x,o,{get:()=>c[o],enumerable:!(h=D(c,o))||h.enumerable});return x};var G=x=>F(T({},"__esModule",{value:!0}),x);var H={};U(H,{Finder:()=>W});module.exports=G(H);var k=require("./dom-util.js"),L=require("./matcher.js"),g=require("./parser.js"),a=require("./constant.js");const v="next",S="prev";class W{#a;#n;#p;#t;#c;#d;#o;#b;#e;#f;#k;#u;#w;#s;#h;#r;#m;#i;#l;constructor(c){this.#l=c,this.#n=new WeakMap,this.#c=new WeakMap,this.#b=new WeakMap,this.#w=new WeakMap}_onError(c){if(!this.#k)if(c instanceof DOMException||c instanceof this.#l.DOMException)if(c.name===a.NOT_SUPPORTED_ERR)this.#i&&console.warn(c.message);else throw new this.#l.DOMException(c.message,c.name);else throw c}_setup(c,e,h={}){const{event:o,noexcept:l,warn:n}=h;return this.#k=!!l,this.#i=!!n,this.#d=this._setEvent(o),this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#h=(0,k.isInShadowTree)(e),[this.#a,this.#f]=this._correspond(c),this.#b=new WeakMap,this.#m=new WeakMap,e}_setEvent(c){return c instanceof this.#l.KeyboardEvent||c instanceof this.#l.MouseEvent?c:null}_correspond(c){const e=[];this.#p=!1,this.#o=!1;let h;if(this.#c.has(this.#t)){const o=this.#c.get(this.#t);if(o&&o.has(`${c}`)){const l=o.get(`${c}`);h=l.ast,this.#p=l.descendant,this.#o=l.invalidate}}if(h){const o=h.length;for(let l=0;l<o;l++)h[l].collected=!1,h[l].dir=null,h[l].filtered=!1,h[l].find=!1,e[l]=[]}else{let o;try{o=(0,g.parseSelector)(c)}catch(t){this._onError(t)}const{branches:l,info:{hasHasPseudoFunc:n}}=(0,g.walkAST)(o),f=!!n;let b=!1,d=0;h=[];for(const[...t]of l){const s=[];let r=t.shift();if(r&&r.type!==a.COMBINATOR){const u=new Set;for(;r;){if(r.type===a.COMBINATOR){const[m]=t;if(m.type===a.COMBINATOR){const p=`Invalid selector ${c}`;throw new DOMException(p,a.SYNTAX_ERR)}const w=r.name;/^[\s>]$/.test(w)&&(b=!0),s.push({combo:r,leaves:(0,g.sortAST)(u)}),u.clear()}else if(r){let{name:m}=r;m&&typeof m=="string"&&(m=(0,g.unescapeSelector)(m),typeof m=="string"&&m!==r.name&&(r.name=m),/[|:]/.test(m)&&(r.namespace=!0)),u.add(r)}if(t.length)r=t.shift();else{s.push({combo:null,leaves:(0,g.sortAST)(u)}),u.clear();break}}}h.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[d]=[],d++}let i;this.#c.has(this.#t)?i=this.#c.get(this.#t):i=new Map,i.set(`${c}`,{ast:h,descendant:b,invalidate:f}),this.#c.set(this.#t,i),this.#p=b,this.#o=f}return[h,e]}_createTreeWalker(c){let e;return this.#m.has(c)?e=this.#m.get(c):(e=this.#t.createTreeWalker(c,a.WALKER_FILTER),this.#m.set(c,e)),e}_prepareQuerySelectorWalker(){return this.#u=this._createTreeWalker(this.#e),this.#u}_collectNthChild(c,e,h){const{a:o,b:l,reverse:n,selector:f}=c,{parentNode:b}=e,d=new Set;let i;if(f)if(this.#n.has(f))i=this.#n.get(f);else{const{branches:t,info:s}=(0,g.walkAST)(f);i=t,this.#n.set(f,i),s.hasLogicalPseudoFunc&&(this.#o=!0)}if(b){const t=this.#r;let s=(0,k.traverseNode)(b,t);s=t.firstChild();let r=0;for(;s;)r++,s=t.nextSibling();const u=new Set;if(i)for(s=(0,k.traverseNode)(b,t),s=t.firstChild();s;){const{display:m,visibility:w}=this.#l.getComputedStyle(s);if(m!=="none"&&w!=="hidden"){let p;for(const N of i)if(p=this._matchLeaves(N,s,h),!p)break;p&&u.add(s)}s=t.nextSibling()}if(o===0){if(l>0&&l<=r){if(u.size){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(u.has(s)){if(m===l-1){d.add(s);break}m++}n?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(m===l-1){d.add(s);break}n?s=t.previousSibling():s=t.nextSibling(),m++}}}}else{let m=l-1;if(o>0)for(;m<0;)m+=o;if(m>=0&&m<r){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let w=0,p=o>0?0:l-1;for(;s&&(s&&m>=0&&m<r);)u.size?u.has(s)&&(p===m&&(d.add(s),m+=o),o>0?p++:p--):w===m&&(f||d.add(s),m+=o),n?s=t.previousSibling():s=t.nextSibling(),w++}}if(n&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&o+l===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(c,e){const{a:h,b:o,reverse:l}=c,{localName:n,parentNode:f,prefix:b}=e,d=new Set;if(f){const i=this.#r;let t=(0,k.traverseNode)(f,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(o>0&&o<=s){t=(0,k.traverseNode)(f,i),l?t=i.lastChild():t=i.firstChild();let r=0;for(;t;){const{localName:u,prefix:m}=t;if(u===n&&m===b){if(r===o-1){d.add(t);break}r++}l?t=i.previousSibling():t=i.nextSibling()}}}else{let r=o-1;if(h>0)for(;r<0;)r+=h;if(r>=0&&r<s){t=(0,k.traverseNode)(f,i),l?t=i.lastChild():t=i.firstChild();let u=h>0?0:o-1;for(;t;){const{localName:m,prefix:w}=t;if(m===n&&w===b){if(u===r&&(d.add(t),r+=h),r<0||r>=s)break;h>0?u++:u--}l?t=i.previousSibling():t=i.nextSibling()}}}if(l&&d.size>1){const r=[...d];return new Set(r.reverse())}}else e===this.#s&&h+o===1&&d.add(e);return d}_matchAnPlusB(c,e,h,o){const{nth:{a:l,b:n,name:f},selector:b}=c,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)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?d.set("a",l*1):d.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?d.set("b",n*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){b&&d.set("selector",b);const i=Object.fromEntries(d);return this._collectNthChild(i,e,o)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(c,e,h={}){let o;if(Array.isArray(c)&&c.length){const l=c.map(s=>s),[n]=l,{type:f}=n;let b;f===a.COMBINATOR?b=l.shift():b={name:" ",type:a.COMBINATOR};const d=[];for(;l.length;){const[s]=l,{type:r}=s;if(r===a.COMBINATOR)break;d.push(l.shift())}const i={combo:b,leaves:d};h.dir=v;const t=this._matchCombinator(i,e,h);if(t.size)if(l.length){for(const s of t)if(o=this._matchHasPseudoFunc(l,s,h),o)break}else o=!0}return!!o}_matchLogicalPseudoFunc(c,e,h={}){const{astName:o="",branches:l=[],selector:n="",twigBranches:f=[]}=c;let b;if(o==="has")if(n.includes(":has("))b=null;else{let d;for(const i of l)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(b=e)}else{const d=/^(?:is|where)$/.test(o);h.forgive=d;const i=f.length;let t;for(let s=0;s<i;s++){const r=f[s],u=r.length-1,{leaves:m}=r[u];if(t=this._matchLeaves(m,e,h),t&&u>0){let w=new Set([e]);for(let p=u-1;p>=0;p--){const N=r[p],_=[];h.dir=S;for(const y of w){const E=this._matchCombinator(N,y,h);E.size&&_.push(...E)}if(_.length)p===0?t=!0:w=new Set(_);else{t=!1;break}}}if(t)break}o==="not"?t||(b=e):t&&(b=e)}return b??null}_matchPseudoClassSelector(c,e,h={}){const{children:o,name:l}=c,{localName:n,parentNode:f}=e,{forgive:b,warn:d=this.#i}=h,i=new Set;if(a.REG_LOGICAL_PSEUDO.test(l)){let t;if(this.#n.has(c))t=this.#n.get(c);else{const{branches:r}=(0,g.walkAST)(c),u=[],m=[];for(const[...w]of r){for(const y of w){const E=(0,g.generateCSS)(y);u.push(E)}const p=[],N=new Set;let _=w.shift();for(;_;)if(_.type===a.COMBINATOR?(p.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),w.length)_=w.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}m.push(p)}t={astName:l,branches:r,twigBranches:m,selector:u.join(",")},this.#n.set(c,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(o))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const[t]=o;return this._matchAnPlusB(t,e,l,h)}else switch(l){case"dir":case"lang":{const t=L.matcher.matchSelector(c,e);t&&i.add(t);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:t}]=o;t&&e[t]&&i.add(e)}break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${l}()`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}default:if(!b){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,a.SYNTAX_ERR)}}else switch(l){case"any-link":case"link":{a.REG_ANCHOR.test(n)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(a.REG_ANCHOR.test(n)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:r}=new URL(this.#t.URL),u=new URL(e.getAttribute("href"),t);u.origin===s&&u.pathname===r&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#d??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:r}=this.#d??{};(r==="mousedown"||r==="pointerdown")&&t&a.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 r=this.#t.getElementById(s);for(;r;){if(r===e){i.add(e);break}r=r.parentNode}}break}case"scope":{this.#e.nodeType===a.ELEMENT_NODE?!this.#h&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#d??{};if(e===this.#t.activeElement&&e.tabIndex>=0&&(l==="focus"||s==="keydown"&&e.contains(t))){let r=e,u=!0;for(;r;){if(r.disabled||r.hasAttribute("disabled")||r.hidden||r.hasAttribute("hidden")){u=!1;break}else{const{display:m,visibility:w}=this.#l.getComputedStyle(r);if(u=!(m==="none"||w==="hidden"),!u)break}if(r.parentNode&&r.parentNode.nodeType===a.ELEMENT_NODE)r=r.parentNode;else break}u&&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}if(t){let r=e,u=!0;for(;r;){if(r.disabled||r.hasAttribute("disabled")||r.hidden||r.hasAttribute("hidden")){u=!1;break}else{const{display:m,visibility:w}=this.#l.getComputedStyle(r);if(u=!(m==="none"||w==="hidden"),!u)break}if(r.parentNode&&r.parentNode.nodeType===a.ELEMENT_NODE)r=r.parentNode;else break}u&&i.add(e)}break}case"open":{a.REG_INTERACT.test(n)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{a.REG_INTERACT.test(n)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(a.REG_FORM_CTRL.test(n)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let t,s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const r=this.#r;let u=(0,k.traverseNode)(s,r);for(u=r.firstChild();u&&u.localName!=="legend";)u=r.nextSibling();u&&u.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===a.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t&&i.add(e)}}break}case"enabled":{if((a.REG_FORM_CTRL.test(n)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(f.localName!=="optgroup"||!(f.disabled||f.hasAttribute("disabled")))&&i.add(e);else{let t,s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const r=this.#r;let u=(0,k.traverseNode)(s,r);for(u=r.firstChild();u&&u.localName!=="legend";)u=r.nextSibling();u&&u.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===a.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t||i.add(e)}break}case"read-only":{switch(n){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||a.REG_TYPE_DATE.test(e.type)||a.REG_TYPE_TEXT.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(n){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||a.REG_TYPE_DATE.test(e.type)||a.REG_TYPE_TEXT.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 t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;n==="textarea"?s=e:n==="input"&&(e.hasAttribute("type")?a.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&n==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&n==="input"&&e.type==="checkbox"||n==="progress"&&!e.hasAttribute("value"))i.add(e);else if(n==="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 r=s.getElementsByTagName("input"),u=r.length;let m;for(let w=0;w<u;w++){const p=r[w];if(p.getAttribute("type")==="radio"&&(t?p.getAttribute("name")===t&&(m=!!p.checked):p.hasAttribute("name")||(m=!!p.checked),m))break}m||i.add(e)}break}case"default":{if(n==="button"&&!(e.hasAttribute("type")&&a.REG_TYPE_RESET.test(e.getAttribute("type")))||n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#r;let r=(0,k.traverseNode)(t,s);for(r=s.firstChild();r&&t.contains(r);){const u=r.localName;let m;if(u==="button"?m=!(r.hasAttribute("type")&&a.REG_TYPE_RESET.test(r.getAttribute("type"))):u==="input"&&(m=r.hasAttribute("type")&&a.REG_TYPE_SUBMIT.test(r.getAttribute("type"))),m){r===e&&i.add(e);break}r=s.nextNode()}}}else(n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_CHECK.test(e.getAttribute("type"))&&e.hasAttribute("checked")||n==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(a.REG_FORM_VALID.test(n))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(n==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let r;if(!s)r=!0;else for(;s&&e.contains(s)&&!(a.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?r=s.maxLength>=s.value.length:r=!0:r=!1,!r));)s=t.nextNode();r&&i.add(e)}break}case"invalid":{if(a.REG_FORM_VALID.test(n))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(n==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let r;if(!s)r=!0;else for(;s&&e.contains(s)&&!(a.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?r=s.maxLength>=s.value.length:r=!0:r=!1,!r));)s=t.nextNode();r||i.add(e)}break}case"in-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&a.REG_TYPE_RANGE.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":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&a.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(n))t=e;else if(n==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||a.REG_TYPE_CHECK.test(s)||a.REG_TYPE_DATE.test(s)||a.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(n))t=e;else if(n==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||a.REG_TYPE_CHECK.test(s)||a.REG_TYPE_DATE.test(s)||a.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(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 t=this.#t.createTreeWalker(e,a.SHOW_ALL);let s=t.firstChild(),r;for(;s&&(r=s.nodeType!==a.ELEMENT_NODE&&s.nodeType!==a.TEXT_NODE,!!r);)s=t.nextSibling();r&&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")||n.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#l.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${l}`;throw new DOMException(t,a.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){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}}else if(!b){const t=`Unknown pseudo-class :${l}`;throw new DOMException(t,a.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(c,e){const{children:h,name:o}=c;let l;if(Array.isArray(h)){const{branches:n}=(0,g.walkAST)(h[0]),[f]=n,[...b]=f,{host:d}=e;if(o==="host"){let i;for(const t of b){const{type:s}=t;if(s===a.COMBINATOR){const u=`Invalid selector ${(0,g.generateCSS)(c)}`;throw new DOMException(u,a.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(l=e)}else if(o==="host-context"){let i=d,t;for(;i;){for(const s of b){const{type:r}=s;if(r===a.COMBINATOR){const m=`Invalid selector ${(0,g.generateCSS)(c)}`;throw new DOMException(m,a.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(l=e)}}else if(o==="host")l=e;else{const n=`Invalid selector :${o}`;throw new DOMException(n,a.SYNTAX_ERR)}return l??null}_matchSelector(c,e,h){const{type:o}=c,l=new Set;if(c.name===a.EMPTY)return l;const n=(0,g.unescapeSelector)(c.name);if(typeof n=="string"&&n!==c.name&&(c.name=n),e.nodeType===a.ELEMENT_NODE)switch(o){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(n,h);break}case a.SELECTOR_ID:{e.id===n&&l.add(e);break}case a.SELECTOR_CLASS:{e.classList.contains(n)&&l.add(e);break}case a.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(c,e,h);default:{const f=L.matcher.matchSelector(c,e,h);f&&l.add(f)}}else if(this.#h&&o===a.SELECTOR_PSEUDO_CLASS&&e.nodeType===a.DOCUMENT_FRAGMENT_NODE){if(n!=="has"&&a.REG_LOGICAL_PSEUDO.test(n))return this._matchPseudoClassSelector(c,e,h);if(a.REG_SHADOW_HOST.test(n)){const f=this._matchShadowHostPseudoClass(c,e,h);f&&l.add(f)}}return l}_matchLeaves(c,e,h){let o,l;if(this.#o?l=this.#b.get(c):l=this.#w.get(c),l&&l.has(e)){const{matched:n}=l.get(e);o=n}if(typeof o!="boolean"){let n=!0;e.nodeType===a.ELEMENT_NODE&&a.REG_FORM.test(e.localName)&&(n=!1);for(const f of c){switch(f.type){case a.SELECTOR_ATTR:case a.SELECTOR_ID:{n=!1;break}case a.SELECTOR_PSEUDO_CLASS:{/^(?:(?:any-)?link|defined)$/.test(f.name)&&(n=!1);break}default:}if(o=this._matchSelector(f,e,h).has(e),!o)break}n&&(l||(l=new WeakMap),l.set(e,{matched:o}),this.#o?this.#b.set(c,l):this.#w.set(c,l))}return!!o}_matchHTMLCollection(c,e={}){const{compound:h,filterLeaves:o}=e,l=new Set,n=c.length;if(n)if(h)for(let f=0;f<n;f++){const b=c[f];this._matchLeaves(o,b,e)&&l.add(b)}else{const f=[].slice.call(c);return new Set(f)}return l}_findDescendantNodes(c,e,h){const[o,...l]=c,n=l.length>0,{type:f}=o,b=(0,g.unescapeSelector)(o.name);typeof b=="string"&&b!==o.name&&(o.name=b);let d=new Set,i=!1;if(this.#h)i=!0;else switch(f){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(b,h);break}case a.SELECTOR_ID:{if(this.#s.nodeType===a.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(b);t&&t!==e&&e.contains(t)&&(n?this._matchLeaves(l,t,h)&&d.add(t):d.add(t))}break}case a.SELECTOR_CLASS:{const t=e.getElementsByClassName(b);d=this._matchHTMLCollection(t,{compound:n,filterLeaves:l});break}case a.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(b)){const t=e.getElementsByTagName(b);d=this._matchHTMLCollection(t,{compound:n,filterLeaves:l})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(c,e,h={}){const{combo:o,leaves:l}=c,{name:n}=o,{parentNode:f}=e,{dir:b}=h,d=new Set;if(b===v)switch(n){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(l,i,h)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,k.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,k.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(l,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let r=(0,k.traverseNode)(e,s);for(r=s.nextNode();r&&e.contains(r);)this._matchLeaves(l,r,h)&&d.add(r),r=s.nextNode()}}}else switch(n){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(l,i,h)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,k.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(l,f,h)&&d.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(l,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(c,e){const{node:h}=e,o=this.#u;let l=(0,k.traverseNode)(h,o),n;if(l)for((l.nodeType!==a.ELEMENT_NODE||l===h&&l!==this.#s)&&(l=o.nextNode());l;){if(this._matchLeaves(c,l,{warn:this.#i})){n=l;break}l=o.nextNode()}return n??null}_matchSelf(c){const e=[],h=this._matchLeaves(c,this.#e,{warn:this.#i});let o=!1;return h&&(e.push(this.#e),o=!0),[e,o]}_findLineal(c,e={}){const{complex:h}=e,o=[];let l=this._matchLeaves(c,this.#e,{warn:this.#i}),n=!1;if(l&&(o.push(this.#e),n=!0),!l||h){let f=this.#e.parentNode;for(;f&&(l=this._matchLeaves(c,f,{warn:this.#i}),l&&(o.push(f),n=!0),f.parentNode);)f=f.parentNode}return[o,n]}_findFirst(c){const e=[],h=this._findNode(c,{node:this.#e});let o=!1;return h&&(e.push(h),o=!0),[e,o]}_findFromHTMLCollection(c,e={}){const{complex:h,compound:o,filterLeaves:l,targetType:n}=e;let f=[],b=!1,d=!1;const i=c.length;if(i)if(this.#e.nodeType===a.ELEMENT_NODE)for(let t=0;t<i;t++){const s=c[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(o){if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else if(f.push(s),b=!0,n===a.TARGET_FIRST)break}}else if(h)if(o)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else f=[].slice.call(c),b=!0,d=!0;else if(o)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else f=[].slice.call(c),b=!0,d=!0;return[f,b,d]}_findEntryNodes(c,e,h){const{leaves:o}=c,[l,...n]=o,f=n.length>0,{name:b,type:d}=l;let i=[],t=!1,s=!1,r=!1;switch(d){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(b,{warn:this.#i});break}case a.SELECTOR_ID:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(e===a.TARGET_FIRST&&this.#s.nodeType!==a.ELEMENT_NODE){const u=this.#s.getElementById(b);u&&(f?this._matchLeaves(n,u,{warn:this.#i})&&(i.push(u),s=!0):(i.push(u),s=!0))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}case a.SELECTOR_CLASS:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(this.#s.nodeType===a.DOCUMENT_NODE){const u=this.#s.getElementsByClassName(b);u.length&&([i,s,t]=this._findFromHTMLCollection(u,{complex:h,compound:f,filterLeaves:n,targetType:e}))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}case a.SELECTOR_TYPE:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===a.DOCUMENT_NODE&&!/[*|]/.test(b)){const u=this.#s.getElementsByTagName(b);u.length&&([i,s,t]=this._findFromHTMLCollection(u,{complex:h,compound:f,filterLeaves:n,targetType:e}))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}default:if(e!==a.TARGET_LINEAL&&a.REG_SHADOW_HOST.test(b)){if(this.#h&&this.#e.nodeType===a.DOCUMENT_FRAGMENT_NODE){const u=this._matchShadowHostPseudoClass(l,this.#e);u&&(i.push(u),s=!0)}}else e===a.TARGET_SELF?[i,s]=this._matchSelf(o):e===a.TARGET_LINEAL?[i,s]=this._findLineal(o,{complex:h}):e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:r}}_collectNodes(c){const e=this.#a.values();if(c===a.TARGET_ALL||c===a.TARGET_FIRST){const h=new Set;let o=0;for(const{branch:l}of e){const n=l.length,f=n>1,b=l[0];let d,i;if(f){const{combo:w,leaves:[{name:p,type:N}]}=b,_=l[n-1],{leaves:[{name:y,type:E}]}=_;if(E===a.SELECTOR_PSEUDO_ELEMENT||E===a.SELECTOR_ID)d=S,i=_;else if(N===a.SELECTOR_PSEUDO_ELEMENT||N===a.SELECTOR_ID)d=v,i=b;else if(c===a.TARGET_ALL)if(p==="*"&&N===a.SELECTOR_TYPE)d=S,i=_;else if(y==="*"&&E===a.SELECTOR_TYPE)d=v,i=b;else if(n===2){const{name:A}=w;/^[+~]$/.test(A)?(d=S,i=_):(d=v,i=b)}else d=v,i=b;else if(y==="*"&&E===a.SELECTOR_TYPE)d=v,i=b;else if(p==="*"&&N===a.SELECTOR_TYPE)d=S,i=_;else{let A;for(const{combo:C,leaves:[R]}of l){const{name:O,type:M}=R;if(M===a.SELECTOR_PSEUDO_CLASS&&O==="dir"){A=!1;break}if(!A&&C){const{name:P}=C;/^[+~]$/.test(P)&&(A=!0)}}A?(d=v,i=b):(d=S,i=_)}}else d=S,i=b;const{collected:t,compound:s,filtered:r,nodes:u,pending:m}=this._findEntryNodes(i,c,f);u.length?(this.#a[o].find=!0,this.#f[o]=u):m&&h.add(new Map([["index",o],["twig",i]])),this.#a[o].collected=t,this.#a[o].dir=d,this.#a[o].filtered=r||!s,o++}if(h.size){let l,n;this.#e!==this.#s&&this.#e.nodeType===a.ELEMENT_NODE?(l=this.#e,n=this.#u):(l=this.#s,n=this.#r);let f=(0,k.traverseNode)(l,n);for(;f;){let b=!1;if(this.#e.nodeType===a.ELEMENT_NODE?f===this.#e?b=!0:b=this.#e.contains(f):b=!0,b)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=d.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#f[s].push(f)}}f!==n.currentNode&&(f=(0,k.traverseNode)(f,n)),f=n.nextNode()}}}else{let h=0;for(const{branch:o}of e){const l=o[o.length-1],n=o.length>1,{compound:f,filtered:b,nodes:d}=this._findEntryNodes(l,c,n);d.length&&(this.#a[h].find=!0,this.#f[h]=d),this.#a[h].dir=S,this.#a[h].filtered=b||!f,h++}}return[this.#a,this.#f]}_getCombinedNodes(c,e,h){const o=[];for(const l of e){const n=this._matchCombinator(c,l,{dir:h,warn:this.#i});n.size&&o.push(...n)}return o.length?new Set(o):new Set}_matchNodeNext(c,e,h){const{combo:o,index:l}=h,{combo:n,leaves:f}=c[l],b={combo:o,leaves:f},d=this._getCombinedNodes(b,e,v);let i;if(d.size)if(l===c.length-1){const[t]=(0,k.sortNodes)(d);i=t}else i=this._matchNodeNext(c,d,{combo:n,index:l+1});return i??null}_matchNodePrev(c,e,h){const{index:o}=h,l=c[o],n=new Set([e]),f=this._getCombinedNodes(l,n,S);let b;if(f.size){if(o===0)b=e;else for(const d of f)if(this._matchNodePrev(c,d,{index:o-1}))return e}return b??null}_find(c){(c===a.TARGET_ALL||c===a.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(c),o=e.length;let l,n=new Set;for(let f=0;f<o;f++){const{branch:b,collected:d,dir:i,find:t}=e[f],s=b.length;if(s&&t){const r=h[f],u=r.length,m=s-1;if(m===0)if((c===a.TARGET_ALL||c===a.TARGET_FIRST)&&this.#e.nodeType===a.ELEMENT_NODE)for(let w=0;w<u;w++){const p=r[w];if(p!==this.#e&&this.#e.contains(p)&&(n.add(p),c!==a.TARGET_ALL))break}else if(c===a.TARGET_ALL)if(n.size){const w=[...n];n=new Set([...w,...r]),l=!0}else n=new Set(r);else{const[w]=r;n.add(w)}else if(c===a.TARGET_ALL)if(i===v){let{combo:w}=b[0];for(const p of r){let N=new Set([p]);for(let _=1;_<s;_++){const{combo:y,leaves:E}=b[_],A={combo:w,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(n.size){const C=[...n];n=new Set([...C,...N]),l=!0}else n=N;else w=y;else break}}}else for(const w of r){let p=new Set([w]);for(let N=m-1;N>=0;N--){const _=b[N];if(p=this._getCombinedNodes(_,p,i),p.size)N===0&&(n.add(w),s>1&&n.size>1&&(l=!0));else break}}else if(c===a.TARGET_FIRST&&i===v){const{combo:w}=b[0];let p;for(const N of r)if(p=this._matchNodeNext(b,new Set([N]),{combo:w,index:1}),p){n.add(p);break}if(!p&&!d){const{leaves:N}=b[0],[_]=r;let y=this._findNode(N,{node:_});for(;y;){if(p=this._matchNodeNext(b,new Set([y]),{combo:w,index:1}),p){n.add(p);break}y=this._findNode(N,{node:y})}}}else{let w;for(const p of r)if(w=this._matchNodePrev(b,p,{index:m-1}),w){n.add(p);break}if(!w&&!d&&c===a.TARGET_FIRST){const{leaves:p}=b[m],[N]=r;let _=this._findNode(p,{node:N});for(;_;){if(w=this._matchNodePrev(b,_,{index:m-1}),w){n.add(_);break}_=this._findNode(p,{node:_})}}}}}return c===a.TARGET_ALL&&l&&(n=new Set((0,k.sortNodes)(n))),n}}0&&(module.exports={Finder});
var T=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var U=(x,c)=>{for(var e in c)T(x,e,{get:c[e],enumerable:!0})},F=(x,c,e,h)=>{if(c&&typeof c=="object"||typeof c=="function")for(let o of I(c))!$.call(x,o)&&o!==e&&T(x,o,{get:()=>c[o],enumerable:!(h=D(c,o))||h.enumerable});return x};var G=x=>F(T({},"__esModule",{value:!0}),x);var H={};U(H,{Finder:()=>W});module.exports=G(H);var k=require("./dom-util.js"),L=require("./matcher.js"),g=require("./parser.js"),a=require("./constant.js");const v="next",S="prev";class W{#a;#n;#p;#t;#c;#d;#o;#b;#e;#f;#k;#u;#w;#s;#h;#r;#m;#i;#l;constructor(c){this.#l=c,this.#n=new WeakMap,this.#c=new WeakMap,this.#b=new WeakMap,this.#w=new WeakMap}_onError(c){if(!this.#k)if(c instanceof DOMException||c instanceof this.#l.DOMException)if(c.name===a.NOT_SUPPORTED_ERR)this.#i&&console.warn(c.message);else throw new this.#l.DOMException(c.message,c.name);else throw c}_setup(c,e,h={}){const{event:o,noexcept:l,warn:n}=h;return this.#k=!!l,this.#i=!!n,this.#d=this._setEvent(o),this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#h=(0,k.isInShadowTree)(e),[this.#a,this.#f]=this._correspond(c),this.#b=new WeakMap,this.#m=new WeakMap,e}_setEvent(c){return c instanceof this.#l.KeyboardEvent||c instanceof this.#l.MouseEvent?c:null}_correspond(c){const e=[];this.#p=!1,this.#o=!1;let h;if(this.#c.has(this.#t)){const o=this.#c.get(this.#t);if(o&&o.has(`${c}`)){const l=o.get(`${c}`);h=l.ast,this.#p=l.descendant,this.#o=l.invalidate}}if(h){const o=h.length;for(let l=0;l<o;l++)h[l].collected=!1,h[l].dir=null,h[l].filtered=!1,h[l].find=!1,e[l]=[]}else{let o;try{o=(0,g.parseSelector)(c)}catch(t){this._onError(t)}const{branches:l,info:{hasHasPseudoFunc:n}}=(0,g.walkAST)(o),f=!!n;let b=!1,d=0;h=[];for(const[...t]of l){const s=[];let r=t.shift();if(r&&r.type!==a.COMBINATOR){const u=new Set;for(;r;){if(r.type===a.COMBINATOR){const[m]=t;if(m.type===a.COMBINATOR){const p=`Invalid selector ${c}`;throw new DOMException(p,a.SYNTAX_ERR)}const w=r.name;/^[\s>]$/.test(w)&&(b=!0),s.push({combo:r,leaves:(0,g.sortAST)(u)}),u.clear()}else if(r){let{name:m}=r;m&&typeof m=="string"&&(m=(0,g.unescapeSelector)(m),typeof m=="string"&&m!==r.name&&(r.name=m),/[|:]/.test(m)&&(r.namespace=!0)),u.add(r)}if(t.length)r=t.shift();else{s.push({combo:null,leaves:(0,g.sortAST)(u)}),u.clear();break}}}h.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[d]=[],d++}let i;this.#c.has(this.#t)?i=this.#c.get(this.#t):i=new Map,i.set(`${c}`,{ast:h,descendant:b,invalidate:f}),this.#c.set(this.#t,i),this.#p=b,this.#o=f}return[h,e]}_createTreeWalker(c){let e;return this.#m.has(c)?e=this.#m.get(c):(e=this.#t.createTreeWalker(c,a.WALKER_FILTER),this.#m.set(c,e)),e}_prepareQuerySelectorWalker(){return this.#u=this._createTreeWalker(this.#e),this.#u}_collectNthChild(c,e,h){const{a:o,b:l,reverse:n,selector:f}=c,{parentNode:b}=e,d=new Set;let i;if(f)if(this.#n.has(f))i=this.#n.get(f);else{const{branches:t,info:s}=(0,g.walkAST)(f);i=t,this.#n.set(f,i),s.hasLogicalPseudoFunc&&(this.#o=!0)}if(b){const t=this.#r;let s=(0,k.traverseNode)(b,t);s=t.firstChild();let r=0;for(;s;)r++,s=t.nextSibling();const u=new Set;if(i)for(s=(0,k.traverseNode)(b,t),s=t.firstChild();s;){const{display:m,visibility:w}=this.#l.getComputedStyle(s);if(m!=="none"&&w!=="hidden"){let p;for(const N of i)if(p=this._matchLeaves(N,s,h),!p)break;p&&u.add(s)}s=t.nextSibling()}if(o===0){if(l>0&&l<=r){if(u.size){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(u.has(s)){if(m===l-1){d.add(s);break}m++}n?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(m===l-1){d.add(s);break}n?s=t.previousSibling():s=t.nextSibling(),m++}}}}else{let m=l-1;if(o>0)for(;m<0;)m+=o;if(m>=0&&m<r){s=(0,k.traverseNode)(b,t),n?s=t.lastChild():s=t.firstChild();let w=0,p=o>0?0:l-1;for(;s&&(s&&m>=0&&m<r);)u.size?u.has(s)&&(p===m&&(d.add(s),m+=o),o>0?p++:p--):w===m&&(f||d.add(s),m+=o),n?s=t.previousSibling():s=t.nextSibling(),w++}}if(n&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&o+l===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(c,e){const{a:h,b:o,reverse:l}=c,{localName:n,parentNode:f,prefix:b}=e,d=new Set;if(f){const i=this.#r;let t=(0,k.traverseNode)(f,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(o>0&&o<=s){t=(0,k.traverseNode)(f,i),l?t=i.lastChild():t=i.firstChild();let r=0;for(;t;){const{localName:u,prefix:m}=t;if(u===n&&m===b){if(r===o-1){d.add(t);break}r++}l?t=i.previousSibling():t=i.nextSibling()}}}else{let r=o-1;if(h>0)for(;r<0;)r+=h;if(r>=0&&r<s){t=(0,k.traverseNode)(f,i),l?t=i.lastChild():t=i.firstChild();let u=h>0?0:o-1;for(;t;){const{localName:m,prefix:w}=t;if(m===n&&w===b){if(u===r&&(d.add(t),r+=h),r<0||r>=s)break;h>0?u++:u--}l?t=i.previousSibling():t=i.nextSibling()}}}if(l&&d.size>1){const r=[...d];return new Set(r.reverse())}}else e===this.#s&&h+o===1&&d.add(e);return d}_matchAnPlusB(c,e,h,o){const{nth:{a:l,b:n,name:f},selector:b}=c,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)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?d.set("a",l*1):d.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?d.set("b",n*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){b&&d.set("selector",b);const i=Object.fromEntries(d);return this._collectNthChild(i,e,o)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(c,e,h={}){let o;if(Array.isArray(c)&&c.length){const l=c.map(s=>s),[n]=l,{type:f}=n;let b;f===a.COMBINATOR?b=l.shift():b={name:" ",type:a.COMBINATOR};const d=[];for(;l.length;){const[s]=l,{type:r}=s;if(r===a.COMBINATOR)break;d.push(l.shift())}const i={combo:b,leaves:d};h.dir=v;const t=this._matchCombinator(i,e,h);if(t.size)if(l.length){for(const s of t)if(o=this._matchHasPseudoFunc(l,s,h),o)break}else o=!0}return!!o}_matchLogicalPseudoFunc(c,e,h={}){const{astName:o="",branches:l=[],selector:n="",twigBranches:f=[]}=c;let b;if(o==="has")if(n.includes(":has("))b=null;else{let d;for(const i of l)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(b=e)}else{const d=/^(?:is|where)$/.test(o);h.forgive=d;const i=f.length;let t;for(let s=0;s<i;s++){const r=f[s],u=r.length-1,{leaves:m}=r[u];if(t=this._matchLeaves(m,e,h),t&&u>0){let w=new Set([e]);for(let p=u-1;p>=0;p--){const N=r[p],_=[];h.dir=S;for(const y of w){const E=this._matchCombinator(N,y,h);E.size&&_.push(...E)}if(_.length)p===0?t=!0:w=new Set(_);else{t=!1;break}}}if(t)break}o==="not"?t||(b=e):t&&(b=e)}return b??null}_matchPseudoClassSelector(c,e,h={}){const{children:o,name:l}=c,{localName:n,parentNode:f}=e,{forgive:b,warn:d=this.#i}=h,i=new Set;if(a.REG_LOGICAL_PSEUDO.test(l)){let t;if(this.#n.has(c))t=this.#n.get(c);else{const{branches:r}=(0,g.walkAST)(c),u=[],m=[];for(const[...w]of r){for(const y of w){const E=(0,g.generateCSS)(y);u.push(E)}const p=[],N=new Set;let _=w.shift();for(;_;)if(_.type===a.COMBINATOR?(p.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),w.length)_=w.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}m.push(p)}t={astName:l,branches:r,twigBranches:m,selector:u.join(",")},this.#n.set(c,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(o))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const[t]=o;return this._matchAnPlusB(t,e,l,h)}else switch(l){case"dir":case"lang":{const t=L.matcher.matchSelector(c,e);t&&i.add(t);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:t}]=o;t&&e[t]&&i.add(e)}break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${l}()`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}default:if(!b){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,a.SYNTAX_ERR)}}else switch(l){case"any-link":case"link":{a.REG_ANCHOR.test(n)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(a.REG_ANCHOR.test(n)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:r}=new URL(this.#t.URL),u=new URL(e.getAttribute("href"),t);u.origin===s&&u.pathname===r&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#d??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:r}=this.#d??{};(r==="mousedown"||r==="pointerdown")&&t&a.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 r=this.#t.getElementById(s);for(;r;){if(r===e){i.add(e);break}r=r.parentNode}}break}case"scope":{this.#e.nodeType===a.ELEMENT_NODE?!this.#h&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#d??{};if(e===this.#t.activeElement&&e.tabIndex>=0&&(l==="focus"||s==="keydown"&&e.contains(t))){let r=e,u=!0;for(;r;){if(r.disabled||r.hasAttribute("disabled")||r.hidden||r.hasAttribute("hidden")){u=!1;break}else{const{display:m,visibility:w}=this.#l.getComputedStyle(r);if(u=!(m==="none"||w==="hidden"),!u)break}if(r.parentNode&&r.parentNode.nodeType===a.ELEMENT_NODE)r=r.parentNode;else break}u&&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}if(t){let r=e,u=!0;for(;r;){if(r.disabled||r.hasAttribute("disabled")||r.hidden||r.hasAttribute("hidden")){u=!1;break}else{const{display:m,visibility:w}=this.#l.getComputedStyle(r);if(u=!(m==="none"||w==="hidden"),!u)break}if(r.parentNode&&r.parentNode.nodeType===a.ELEMENT_NODE)r=r.parentNode;else break}u&&i.add(e)}break}case"open":{a.REG_INTERACT.test(n)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{a.REG_INTERACT.test(n)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(a.REG_FORM_CTRL.test(n)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let t,s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const r=this.#r;let u=(0,k.traverseNode)(s,r);for(u=r.firstChild();u&&u.localName!=="legend";)u=r.nextSibling();u&&u.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===a.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t&&i.add(e)}}break}case"enabled":{if((a.REG_FORM_CTRL.test(n)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(f.localName!=="optgroup"||!(f.disabled||f.hasAttribute("disabled")))&&i.add(e);else{let t,s=f;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const r=this.#r;let u=(0,k.traverseNode)(s,r);for(u=r.firstChild();u&&u.localName!=="legend";)u=r.nextSibling();u&&u.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===a.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t||i.add(e)}break}case"read-only":{switch(n){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||a.REG_TYPE_DATE.test(e.type)||a.REG_TYPE_TEXT.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(n){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||a.REG_TYPE_DATE.test(e.type)||a.REG_TYPE_TEXT.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 t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;n==="textarea"?s=e:n==="input"&&(e.hasAttribute("type")?a.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&n==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&n==="input"&&e.type==="checkbox"||n==="progress"&&!e.hasAttribute("value"))i.add(e);else if(n==="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 r=s.getElementsByTagName("input"),u=r.length;let m;for(let w=0;w<u;w++){const p=r[w];if(p.getAttribute("type")==="radio"&&(t?p.getAttribute("name")===t&&(m=!!p.checked):p.hasAttribute("name")||(m=!!p.checked),m))break}m||i.add(e)}break}case"default":{if(n==="button"&&!(e.hasAttribute("type")&&a.REG_TYPE_RESET.test(e.getAttribute("type")))||n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#r;let r=(0,k.traverseNode)(t,s);for(r=s.firstChild();r&&t.contains(r);){const u=r.localName;let m;if(u==="button"?m=!(r.hasAttribute("type")&&a.REG_TYPE_RESET.test(r.getAttribute("type"))):u==="input"&&(m=r.hasAttribute("type")&&a.REG_TYPE_SUBMIT.test(r.getAttribute("type"))),m){r===e&&i.add(e);break}r=s.nextNode()}}}else(n==="input"&&e.hasAttribute("type")&&a.REG_TYPE_CHECK.test(e.getAttribute("type"))&&e.hasAttribute("checked")||n==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(a.REG_FORM_VALID.test(n))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(n==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let r;if(!s)r=!0;else for(;s&&e.contains(s)&&!(a.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?r=s.maxLength>=s.value.length:r=!0:r=!1,!r));)s=t.nextNode();r&&i.add(e)}break}case"invalid":{if(a.REG_FORM_VALID.test(n))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(n==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let r;if(!s)r=!0;else for(;s&&e.contains(s)&&!(a.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?r=s.maxLength>=s.value.length:r=!0:r=!1,!r));)s=t.nextNode();r||i.add(e)}break}case"in-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&a.REG_TYPE_RANGE.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":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&a.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(n))t=e;else if(n==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||a.REG_TYPE_CHECK.test(s)||a.REG_TYPE_DATE.test(s)||a.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(n))t=e;else if(n==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||a.REG_TYPE_CHECK.test(s)||a.REG_TYPE_DATE.test(s)||a.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(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 t=this.#t.createTreeWalker(e,a.SHOW_ALL);let s=t.firstChild(),r;for(;s&&(r=s.nodeType!==a.ELEMENT_NODE&&s.nodeType!==a.TEXT_NODE,!!r);)s=t.nextSibling();r&&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")||n.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#l.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${l}`;throw new DOMException(t,a.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){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,a.NOT_SUPPORTED_ERR)}}else if(!b){const t=`Unknown pseudo-class :${l}`;throw new DOMException(t,a.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(c,e){const{children:h,name:o}=c;let l;if(Array.isArray(h)){const{branches:n}=(0,g.walkAST)(h[0]),[f]=n,[...b]=f,{host:d}=e;if(o==="host"){let i;for(const t of b){const{type:s}=t;if(s===a.COMBINATOR){const u=`Invalid selector ${(0,g.generateCSS)(c)}`;throw new DOMException(u,a.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(l=e)}else if(o==="host-context"){let i=d,t;for(;i;){for(const s of b){const{type:r}=s;if(r===a.COMBINATOR){const m=`Invalid selector ${(0,g.generateCSS)(c)}`;throw new DOMException(m,a.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(l=e)}}else if(o==="host")l=e;else{const n=`Invalid selector :${o}`;throw new DOMException(n,a.SYNTAX_ERR)}return l??null}_matchSelector(c,e,h){const{type:o}=c,l=new Set;if(c.name===a.EMPTY)return l;const n=(0,g.unescapeSelector)(c.name);if(typeof n=="string"&&n!==c.name&&(c.name=n),e.nodeType===a.ELEMENT_NODE)switch(o){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(n,h);break}case a.SELECTOR_ID:{e.id===n&&l.add(e);break}case a.SELECTOR_CLASS:{e.classList.contains(n)&&l.add(e);break}case a.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(c,e,h);default:{const f=L.matcher.matchSelector(c,e,h);f&&l.add(f)}}else if(this.#h&&o===a.SELECTOR_PSEUDO_CLASS&&e.nodeType===a.DOCUMENT_FRAGMENT_NODE){if(n!=="has"&&a.REG_LOGICAL_PSEUDO.test(n))return this._matchPseudoClassSelector(c,e,h);if(a.REG_SHADOW_HOST.test(n)){const f=this._matchShadowHostPseudoClass(c,e,h);f&&l.add(f)}}return l}_matchLeaves(c,e,h){let o,l;if(this.#o?l=this.#b.get(c):l=this.#w.get(c),l&&l.has(e)){const{matched:n}=l.get(e);o=n}if(typeof o!="boolean"){let n=!0;e.nodeType===a.ELEMENT_NODE&&a.REG_FORM.test(e.localName)&&(n=!1);for(const f of c){switch(f.type){case a.SELECTOR_ATTR:case a.SELECTOR_ID:{n=!1;break}case a.SELECTOR_PSEUDO_CLASS:{/^(?:(?:any-)?link|defined|dir)$/.test(f.name)&&(n=!1);break}default:}if(o=this._matchSelector(f,e,h).has(e),!o)break}n&&(l||(l=new WeakMap),l.set(e,{matched:o}),this.#o?this.#b.set(c,l):this.#w.set(c,l))}return!!o}_matchHTMLCollection(c,e={}){const{compound:h,filterLeaves:o}=e,l=new Set,n=c.length;if(n)if(h)for(let f=0;f<n;f++){const b=c[f];this._matchLeaves(o,b,e)&&l.add(b)}else{const f=[].slice.call(c);return new Set(f)}return l}_findDescendantNodes(c,e,h){const[o,...l]=c,n=l.length>0,{type:f}=o,b=(0,g.unescapeSelector)(o.name);typeof b=="string"&&b!==o.name&&(o.name=b);let d=new Set,i=!1;if(this.#h)i=!0;else switch(f){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(b,h);break}case a.SELECTOR_ID:{if(this.#s.nodeType===a.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(b);t&&t!==e&&e.contains(t)&&(n?this._matchLeaves(l,t,h)&&d.add(t):d.add(t))}break}case a.SELECTOR_CLASS:{const t=e.getElementsByClassName(b);d=this._matchHTMLCollection(t,{compound:n,filterLeaves:l});break}case a.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(b)){const t=e.getElementsByTagName(b);d=this._matchHTMLCollection(t,{compound:n,filterLeaves:l})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(c,e,h={}){const{combo:o,leaves:l}=c,{name:n}=o,{parentNode:f}=e,{dir:b}=h,d=new Set;if(b===v)switch(n){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(l,i,h)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,k.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,k.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(l,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let r=(0,k.traverseNode)(e,s);for(r=s.nextNode();r&&e.contains(r);)this._matchLeaves(l,r,h)&&d.add(r),r=s.nextNode()}}}else switch(n){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(l,i,h)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,k.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(l,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(l,f,h)&&d.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(l,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(c,e){const{node:h}=e,o=this.#u;let l=(0,k.traverseNode)(h,o),n;if(l)for((l.nodeType!==a.ELEMENT_NODE||l===h&&l!==this.#s)&&(l=o.nextNode());l;){if(this._matchLeaves(c,l,{warn:this.#i})){n=l;break}l=o.nextNode()}return n??null}_matchSelf(c){const e=[],h=this._matchLeaves(c,this.#e,{warn:this.#i});let o=!1;return h&&(e.push(this.#e),o=!0),[e,o]}_findLineal(c,e={}){const{complex:h}=e,o=[];let l=this._matchLeaves(c,this.#e,{warn:this.#i}),n=!1;if(l&&(o.push(this.#e),n=!0),!l||h){let f=this.#e.parentNode;for(;f&&(l=this._matchLeaves(c,f,{warn:this.#i}),l&&(o.push(f),n=!0),f.parentNode);)f=f.parentNode}return[o,n]}_findFirst(c){const e=[],h=this._findNode(c,{node:this.#e});let o=!1;return h&&(e.push(h),o=!0),[e,o]}_findFromHTMLCollection(c,e={}){const{complex:h,compound:o,filterLeaves:l,targetType:n}=e;let f=[],b=!1,d=!1;const i=c.length;if(i)if(this.#e.nodeType===a.ELEMENT_NODE)for(let t=0;t<i;t++){const s=c[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(o){if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else if(f.push(s),b=!0,n===a.TARGET_FIRST)break}}else if(h)if(o)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else f=[].slice.call(c),b=!0,d=!0;else if(o)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(l,s,{warn:this.#i})&&(f.push(s),b=!0,n===a.TARGET_FIRST))break}else f=[].slice.call(c),b=!0,d=!0;return[f,b,d]}_findEntryNodes(c,e,h){const{leaves:o}=c,[l,...n]=o,f=n.length>0,{name:b,type:d}=l;let i=[],t=!1,s=!1,r=!1;switch(d){case a.SELECTOR_PSEUDO_ELEMENT:{L.matcher.matchPseudoElementSelector(b,{warn:this.#i});break}case a.SELECTOR_ID:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(e===a.TARGET_FIRST&&this.#s.nodeType!==a.ELEMENT_NODE){const u=this.#s.getElementById(b);u&&(f?this._matchLeaves(n,u,{warn:this.#i})&&(i.push(u),s=!0):(i.push(u),s=!0))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}case a.SELECTOR_CLASS:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(this.#s.nodeType===a.DOCUMENT_NODE){const u=this.#s.getElementsByClassName(b);u.length&&([i,s,t]=this._findFromHTMLCollection(u,{complex:h,compound:f,filterLeaves:n,targetType:e}))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}case a.SELECTOR_TYPE:{if(e===a.TARGET_SELF)[i,s]=this._matchSelf(o);else if(e===a.TARGET_LINEAL)[i,s]=this._findLineal(o,{complex:h});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===a.DOCUMENT_NODE&&!/[*|]/.test(b)){const u=this.#s.getElementsByTagName(b);u.length&&([i,s,t]=this._findFromHTMLCollection(u,{complex:h,compound:f,filterLeaves:n,targetType:e}))}else e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0;break}default:if(e!==a.TARGET_LINEAL&&a.REG_SHADOW_HOST.test(b)){if(this.#h&&this.#e.nodeType===a.DOCUMENT_FRAGMENT_NODE){const u=this._matchShadowHostPseudoClass(l,this.#e);u&&(i.push(u),s=!0)}}else e===a.TARGET_SELF?[i,s]=this._matchSelf(o):e===a.TARGET_LINEAL?[i,s]=this._findLineal(o,{complex:h}):e===a.TARGET_FIRST?[i,s]=this._findFirst(o):r=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:r}}_collectNodes(c){const e=this.#a.values();if(c===a.TARGET_ALL||c===a.TARGET_FIRST){const h=new Set;let o=0;for(const{branch:l}of e){const n=l.length,f=n>1,b=l[0];let d,i;if(f){const{combo:w,leaves:[{name:p,type:N}]}=b,_=l[n-1],{leaves:[{name:y,type:E}]}=_;if(E===a.SELECTOR_PSEUDO_ELEMENT||E===a.SELECTOR_ID)d=S,i=_;else if(N===a.SELECTOR_PSEUDO_ELEMENT||N===a.SELECTOR_ID)d=v,i=b;else if(c===a.TARGET_ALL)if(p==="*"&&N===a.SELECTOR_TYPE)d=S,i=_;else if(y==="*"&&E===a.SELECTOR_TYPE)d=v,i=b;else if(n===2){const{name:A}=w;/^[+~]$/.test(A)?(d=S,i=_):(d=v,i=b)}else d=v,i=b;else if(y==="*"&&E===a.SELECTOR_TYPE)d=v,i=b;else if(p==="*"&&N===a.SELECTOR_TYPE)d=S,i=_;else{let A;for(const{combo:C,leaves:[R]}of l){const{name:O,type:M}=R;if(M===a.SELECTOR_PSEUDO_CLASS&&O==="dir"){A=!1;break}if(!A&&C){const{name:P}=C;/^[+~]$/.test(P)&&(A=!0)}}A?(d=v,i=b):(d=S,i=_)}}else d=S,i=b;const{collected:t,compound:s,filtered:r,nodes:u,pending:m}=this._findEntryNodes(i,c,f);u.length?(this.#a[o].find=!0,this.#f[o]=u):m&&h.add(new Map([["index",o],["twig",i]])),this.#a[o].collected=t,this.#a[o].dir=d,this.#a[o].filtered=r||!s,o++}if(h.size){let l,n;this.#e!==this.#s&&this.#e.nodeType===a.ELEMENT_NODE?(l=this.#e,n=this.#u):(l=this.#s,n=this.#r);let f=(0,k.traverseNode)(l,n);for(;f;){let b=!1;if(this.#e.nodeType===a.ELEMENT_NODE?f===this.#e?b=!0:b=this.#e.contains(f):b=!0,b)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=d.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#f[s].push(f)}}f!==n.currentNode&&(f=(0,k.traverseNode)(f,n)),f=n.nextNode()}}}else{let h=0;for(const{branch:o}of e){const l=o[o.length-1],n=o.length>1,{compound:f,filtered:b,nodes:d}=this._findEntryNodes(l,c,n);d.length&&(this.#a[h].find=!0,this.#f[h]=d),this.#a[h].dir=S,this.#a[h].filtered=b||!f,h++}}return[this.#a,this.#f]}_getCombinedNodes(c,e,h){const o=[];for(const l of e){const n=this._matchCombinator(c,l,{dir:h,warn:this.#i});n.size&&o.push(...n)}return o.length?new Set(o):new Set}_matchNodeNext(c,e,h){const{combo:o,index:l}=h,{combo:n,leaves:f}=c[l],b={combo:o,leaves:f},d=this._getCombinedNodes(b,e,v);let i;if(d.size)if(l===c.length-1){const[t]=(0,k.sortNodes)(d);i=t}else i=this._matchNodeNext(c,d,{combo:n,index:l+1});return i??null}_matchNodePrev(c,e,h){const{index:o}=h,l=c[o],n=new Set([e]),f=this._getCombinedNodes(l,n,S);let b;if(f.size){if(o===0)b=e;else for(const d of f)if(this._matchNodePrev(c,d,{index:o-1}))return e}return b??null}_find(c){(c===a.TARGET_ALL||c===a.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(c),o=e.length;let l,n=new Set;for(let f=0;f<o;f++){const{branch:b,collected:d,dir:i,find:t}=e[f],s=b.length;if(s&&t){const r=h[f],u=r.length,m=s-1;if(m===0)if((c===a.TARGET_ALL||c===a.TARGET_FIRST)&&this.#e.nodeType===a.ELEMENT_NODE)for(let w=0;w<u;w++){const p=r[w];if(p!==this.#e&&this.#e.contains(p)&&(n.add(p),c!==a.TARGET_ALL))break}else if(c===a.TARGET_ALL)if(n.size){const w=[...n];n=new Set([...w,...r]),l=!0}else n=new Set(r);else{const[w]=r;n.add(w)}else if(c===a.TARGET_ALL)if(i===v){let{combo:w}=b[0];for(const p of r){let N=new Set([p]);for(let _=1;_<s;_++){const{combo:y,leaves:E}=b[_],A={combo:w,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(n.size){const C=[...n];n=new Set([...C,...N]),l=!0}else n=N;else w=y;else break}}}else for(const w of r){let p=new Set([w]);for(let N=m-1;N>=0;N--){const _=b[N];if(p=this._getCombinedNodes(_,p,i),p.size)N===0&&(n.add(w),s>1&&n.size>1&&(l=!0));else break}}else if(c===a.TARGET_FIRST&&i===v){const{combo:w}=b[0];let p;for(const N of r)if(p=this._matchNodeNext(b,new Set([N]),{combo:w,index:1}),p){n.add(p);break}if(!p&&!d){const{leaves:N}=b[0],[_]=r;let y=this._findNode(N,{node:_});for(;y;){if(p=this._matchNodeNext(b,new Set([y]),{combo:w,index:1}),p){n.add(p);break}y=this._findNode(N,{node:y})}}}else{let w;for(const p of r)if(w=this._matchNodePrev(b,p,{index:m-1}),w){n.add(p);break}if(!w&&!d&&c===a.TARGET_FIRST){const{leaves:p}=b[m],[N]=r;let _=this._findNode(p,{node:N});for(;_;){if(w=this._matchNodePrev(b,_,{index:m-1}),w){n.add(_);break}_=this._findNode(p,{node:_})}}}}}return c===a.TARGET_ALL&&l&&(n=new Set((0,k.sortNodes)(n))),n}}0&&(module.exports={Finder});
//# sourceMappingURL=finder.js.map

@@ -63,3 +63,3 @@ {

},
"version": "5.0.5"
"version": "5.0.7"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc