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

@asamuzakjp/dom-selector

Package Overview
Dependencies
Maintainers
0
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 4.5.0-b.5 to 4.5.0-b.6

2

dist/cjs/js/finder.js

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

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

@@ -1,3 +0,3 @@

var h=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var S=(n,t)=>{for(var i in t)h(n,i,{get:t[i],enumerable:!0})},I=(n,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of x(t))!L.call(n,s)&&s!==i&&h(n,s,{get:()=>t[s],enumerable:!(r=_(t,s))||r.enumerable});return n};var T=n=>I(h({},"__esModule",{value:!0}),n);var A={};S(A,{filterSelector:()=>y,generateCSS:()=>O.generate,parseAstName:()=>m,parseSelector:()=>u,preprocess:()=>g,sortAST:()=>C,unescapeSelector:()=>$,walkAST:()=>w});module.exports=T(A);var E=require("css-tree"),e=require("./constant.js"),O=require("css-tree");const $=(n="")=>{if(typeof n=="string"&&n.indexOf("\\",0)>=0){const t=n.split("\\"),i=t.length;for(let r=1;r<i;r++){let s=t[r];if(s===""&&r===i-1)s=e.U_FFFD;else{const o=e.REG_HEX.exec(s);if(o){const[,a]=o;let l;try{const f=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),d=parseInt(a,e.HEX);d===0||d>=f&&d<=p?l=e.U_FFFD:l=String.fromCodePoint(d)}catch{l=e.U_FFFD}let c="";s.length>a.length&&(c=s.substring(a.length)),s=`${l}${c}`}else/^[\n\r\f]/.test(s)&&(s="\\"+s)}t[r]=s}n=t.join("")}return n},g=(...n)=>{if(!n.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=n;if(typeof t=="string"){let i=0;for(;i>=0&&(i=t.indexOf("#",i),!(i<0));){const r=t.substring(0,i+1);let s=t.substring(i+1);if(/^\d$/.test(s.substring(0,1)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);const o=s.codePointAt(0);if(o===e.BIT_HYPHEN){if(/^\d$/.test(s.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(o>e.BIT_FFFF){const a=`\\${o.toString(e.HEX)} `;s.length===e.DUO?s=a:s=`${a}${s.substring(e.DUO)}`}t=`${r}${s}`,i++}t=t.replace(/\f|\r\n?/g,`
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},u=n=>{if(n=g(n),e.REG_INVALID_SELECTOR.test(n))throw new DOMException(`Invalid selector ${n}`,e.SYNTAX_ERR);let t;try{const i=(0,E.parse)(n,{context:"selectorList",parseCustomProperty:!0});t=(0,E.toPlainObject)(i)}catch(i){const{message:r}=i;if(r==="Identifier is expected"&&e.REG_LANG_QUOTED.test(n)){const[,s,o]=e.REG_LANG_QUOTED.exec(n),a=o.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let l=s.replace(o,a);l===":lang()"&&(l=`:lang(${e.EMPTY})`),t=u(n.replace(s,l))}else if(/^(?:Identifier|Selector) is expected$/.test(r)&&e.REG_LOGICAL_EMPTY.test(n)){const[,s,o]=e.REG_LOGICAL_EMPTY.exec(n);t=u(n.replace(s,`:${o}(${e.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(r)&&!n.endsWith("]")){const s=n.lastIndexOf("["),o=n.substring(s);o.includes('"')?o.match(/"/g).length%2?t=u(`${n}"]`):t=u(`${n}]`):t=u(`${n}]`)}else if(r==='")" is expected'&&!n.endsWith(")"))t=u(`${n})`);else throw new DOMException(r,e.SYNTAX_ERR)}return t},w=(n={})=>{const t=new Set,i=new Map;return(0,E.walk)(n,{enter:s=>{s.type===e.SELECTOR?t.add(s.children):s.type===e.SELECTOR_PSEUDO_CLASS?(i.set("hasPseudo",!0),e.REG_LOGICAL_PSEUDO.test(s.name)&&(i.set("hasPseudoFunc",!0),s.name==="has"&&i.set("hasHasPseudoFunc",!0))):s.type===e.SELECTOR_PSEUDO_ELEMENT&&(i.set("hasPseudo",!0),e.REG_SHADOW_PSEUDO.test(s.name)&&i.set("hasPseudoFunc",!0))}}),i.get("hasPseudoFunc")&&(0,E.findAll)(n,(s,o,a)=>{if(a){if(s.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(s.name)){const l=a.filter(c=>{const{name:f,type:p}=c;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(f)});for(const{children:c}of l)for(const{children:f}of c)for(const{children:p}of f)t.has(p)&&t.delete(p)}else if(s.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(s.name)){const l=a.filter(c=>{const{name:f,type:p}=c;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(f)});for(const{children:c}of l)for(const{children:f}of c)t.has(f)&&t.delete(f)}}}),{branches:[...t],info:Object.fromEntries(i)}},C=n=>{const t=[...n];if(t.length>1){const i=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((r,s)=>{const{type:o}=r,{type:a}=s,l=i.get(o),c=i.get(a);let f;return l===c?f=0:l>c?f=1:f=-1,f})}return t},m=n=>{let t,i;if(n&&typeof n=="string")n.indexOf("|")>-1?[t,i]=n.split("|"):(t="*",i=n);else throw new DOMException(`Invalid selector ${n}`,e.SYNTAX_ERR);return{prefix:t,localName:i}},y=(n,t={})=>{if(!n||typeof n!="string")return!1;if(n.includes("[")){const i=n.lastIndexOf("[");if(n.substring(i).lastIndexOf("]")<0)return!1}if(/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(n))return!1;if(n.includes(":")){let i;if(e.REG_LOGICAL_KEY.test(n)){if(e.REG_LOGICAL_EMPTY.test(n))return!1;const{complex:r,descendant:s}=t;r&&s?i=e.REG_LOGICAL_COMPLEX_A:r?i=e.REG_LOGICAL_COMPLEX_B:i=e.REG_LOGICAL_COMPOUND}else i=e.REG_CHILD_INDEXED;if(i.test(n))return!1}return!0};0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
var h=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var L=(s,t)=>{for(var r in t)h(s,r,{get:t[r],enumerable:!0})},I=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!S.call(s,n)&&n!==r&&h(s,n,{get:()=>t[n],enumerable:!(i=_(t,n))||i.enumerable});return s};var T=s=>I(h({},"__esModule",{value:!0}),s);var A={};L(A,{filterSelector:()=>C,generateCSS:()=>O.generate,parseAstName:()=>y,parseSelector:()=>u,preprocess:()=>g,sortAST:()=>w,unescapeSelector:()=>$,walkAST:()=>m});module.exports=T(A);var E=require("css-tree"),e=require("./constant.js"),O=require("css-tree");const $=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let i=1;i<r;i++){let n=t[i];if(n===""&&i===r-1)n=e.U_FFFD;else{const o=e.REG_HEX.exec(n);if(o){const[,a]=o;let l;try{const f=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),d=parseInt(a,e.HEX);d===0||d>=f&&d<=p?l=e.U_FFFD:l=String.fromCodePoint(d)}catch{l=e.U_FFFD}let c="";n.length>a.length&&(c=n.substring(a.length)),n=`${l}${c}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},g=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let n=t.substring(r+1);if(/^\d$/.test(n.substring(0,1)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);const o=n.codePointAt(0);if(o===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(o>e.BIT_FFFF){const a=`\\${o.toString(e.HEX)} `;n.length===e.DUO?n=a:n=`${a}${n.substring(e.DUO)}`}t=`${i}${n}`,r++}t=t.replace(/\f|\r\n?/g,`
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},u=s=>{if(s=g(s),e.REG_INVALID_SELECTOR.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,E.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,E.toPlainObject)(r)}catch(r){const{message:i}=r;if(i==="Identifier is expected"&&e.REG_LANG_QUOTED.test(s)){const[,n,o]=e.REG_LANG_QUOTED.exec(s),a=o.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let l=n.replace(o,a);l===":lang()"&&(l=`:lang(${e.EMPTY})`),t=u(s.replace(n,l))}else if(/^(?:Identifier|Selector) is expected$/.test(i)&&e.REG_LOGICAL_EMPTY.test(s)){const[,n,o]=e.REG_LOGICAL_EMPTY.exec(s);t=u(s.replace(n,`:${o}(${e.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(i)&&!s.endsWith("]")){const n=s.lastIndexOf("["),o=s.substring(n);o.includes('"')?o.match(/"/g).length%2?t=u(`${s}"]`):t=u(`${s}]`):t=u(`${s}]`)}else if(i==='")" is expected'&&!s.endsWith(")"))t=u(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set,r=new Map;return(0,E.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):n.type===e.SELECTOR_PSEUDO_CLASS?(r.set("hasPseudo",!0),e.REG_LOGICAL_PSEUDO.test(n.name)&&(r.set("hasPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0))):n.type===e.SELECTOR_PSEUDO_ELEMENT?(r.set("hasPseudo",!0),e.REG_SHADOW_PSEUDO.test(n.name)&&r.set("hasPseudoFunc",!0)):n.type===e.SELECTOR_ATTR&&n.matcher==="|="&&r.set("hasHyphenSepAttr",!0)}}),r.get("hasPseudoFunc")&&(0,E.findAll)(s,(n,o,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const l=a.filter(c=>{const{name:f,type:p}=c;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(f)});for(const{children:c}of l)for(const{children:f}of c)for(const{children:p}of f)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const l=a.filter(c=>{const{name:f,type:p}=c;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(f)});for(const{children:c}of l)for(const{children:f}of c)t.has(f)&&t.delete(f)}}}),{branches:[...t],info:Object.fromEntries(r)}},w=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,n)=>{const{type:o}=i,{type:a}=n,l=r.get(o),c=r.get(a);let f;return l===c?f=0:l>c?f=1:f=-1,f})}return t},y=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},C=(s,t={})=>{if(!s||typeof s!="string")return!1;if(s.includes("[")){const r=s.lastIndexOf("[");if(s.substring(r).lastIndexOf("]")<0)return!1}if(/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(s))return!1;if(s.includes(":")){let r;if(e.REG_LOGICAL_KEY.test(s)){if(e.REG_LOGICAL_EMPTY.test(s))return!1;const{complex:i,descendant:n}=t;i&&n?r=e.REG_LOGICAL_COMPLEX_A:i?r=e.REG_LOGICAL_COMPLEX_B:r=e.REG_LOGICAL_COMPOUND}else r=e.REG_CHILD_INDEXED;if(r.test(s))return!1}return!0};0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
//# sourceMappingURL=parser.js.map

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

},
"version": "4.5.0-b.5"
"version": "4.5.0-b.6"
}

@@ -206,2 +206,4 @@ /**

}
} else if (node.type === SELECTOR_ATTR && node.matcher === '|=') {
info.set('hasHyphenSepAttr', true);
}

@@ -208,0 +210,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc