@asamuzakjp/dom-selector
Advanced tools
Comparing version 5.3.0 to 5.3.1
@@ -1,2 +0,2 @@ | ||
var E=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var M=(o,t)=>{for(var c in t)E(o,c,{get:t[c],enumerable:!0})},i=(o,t,c,C)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of l(t))!F.call(o,s)&&s!==c&&E(o,s,{get:()=>t[s],enumerable:!(C=R(t,s))||C.enumerable});return o};var U=o=>i(E({},"__esModule",{value:!0}),o);var Gt={};M(Gt,{ALPHA_NUM:()=>A,ANB:()=>$,AN_PLUS_B:()=>a,ATTR_SELECTOR:()=>G,BIT_01:()=>q,BIT_02:()=>J,BIT_04:()=>Q,BIT_08:()=>V,BIT_16:()=>tt,BIT_32:()=>ot,BIT_FFFF:()=>et,CHILD_IDX:()=>I,CLASS_SELECTOR:()=>d,COMBINATOR:()=>B,COMBO:()=>T,COMPLEX:()=>_,COMPLEX_L:()=>S,COMPOUND:()=>n,COMPOUND_A:()=>O,COMPOUND_B:()=>N,COMPOUND_I:()=>Ft,DESCEND:()=>lt,DIGIT:()=>x,DOCUMENT_FRAGMENT_NODE:()=>_t,DOCUMENT_NODE:()=>Tt,DOCUMENT_POSITION_CONTAINED_BY:()=>St,DOCUMENT_POSITION_CONTAINS:()=>Nt,DOCUMENT_POSITION_PRECEDING:()=>Ot,DUO:()=>st,ELEMENT_NODE:()=>Et,EMPTY:()=>Y,HEX:()=>rt,HYPHEN:()=>nt,IDENT:()=>H,ID_SELECTOR:()=>h,KEY_IS_NOT:()=>L,LANG_PART:()=>Pt,LOGICAL_COMPLEX:()=>Mt,LOGICAL_COMPOUND:()=>it,NESTED_LOGICAL_A:()=>P,NESTED_LOGICAL_B:()=>D,NOT_SUPPORTED_ERR:()=>m,NTH:()=>u,N_TH:()=>Rt,PSEUDO_CLASS:()=>Dt,PS_CLASS_SELECTOR:()=>w,PS_ELEMENT_SELECTOR:()=>y,RAW:()=>X,REG_INPUT_TYPE:()=>at,REG_LOGICAL:()=>Ut,SELECTOR:()=>f,SELECTOR_LIST:()=>W,SHOW_ALL:()=>Lt,SHOW_DOCUMENT:()=>Ct,SHOW_DOCUMENT_FRAGMENT:()=>At,SHOW_ELEMENT:()=>It,STRING:()=>b,SUB_TYPE:()=>r,SYNTAX_ERR:()=>k,TAG_TYPE:()=>e,TAG_TYPE_I:()=>p,TARGET_ALL:()=>Z,TARGET_FIRST:()=>g,TARGET_LINEAL:()=>v,TARGET_SELF:()=>K,TEXT_NODE:()=>pt,TYPE_FROM:()=>ct,TYPE_SELECTOR:()=>z,TYPE_TO:()=>xt,U_FFFD:()=>j,WALKER_FILTER:()=>$t});module.exports=U(Gt);const a="AnPlusB",G="AttributeSelector",d="ClassSelector",B="Combinator",Y="__EMPTY__",H="Identifier",h="IdSelector",m="NotSupportedError",u="Nth",w="PseudoClassSelector",y="PseudoElementSelector",X="Raw",f="Selector",W="SelectorList",b="String",k="SyntaxError",Z="all",g="first",v="lineal",K="self",z="TypeSelector",j="\uFFFD",q=1,J=2,Q=4,V=8,tt=16,ot=32,et=65535,st=2,rt=16,nt=45,ct=8,xt=-1,Et=1,pt=3,Tt=9,_t=11,Ot=2,Nt=8,St=16,Lt=4294967295,Ct=256,At=1024,It=1,$t=1281,A="[A-Z\\d]+",I="(?:first|last|only)-(?:child|of-type)",x="(?:0|[1-9]\\d*)",Pt=`(?:-${A})*`,Dt=`(?:any-)?link|${I}|checked|empty|indeterminate|root|target|visited`,$=`[+-]?(?:${x}n?|n)|(?:[+-]?${x})?n\\s*[+-]\\s*${x}`,Rt=`nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${$})\\s*\\)`,r="\\[[^|\\]]+\\]|[#.:][\\w-]+",e="\\*|[A-Za-z][\\w-]*",p="\\*|[A-Z][\\w-]*",n=`(?:${e}|(?:${e})?(?:${r})+)`,T="\\s?[\\s>~+]\\s?",_=`${n}(?:${T}${n})*`,lt="\\s?[\\s>]\\s?",P=`:is\\(\\s*${n}(?:\\s*,\\s*${n})*\\s*\\)`,D=`:is\\(\\s*${_}(?:\\s*,\\s*${_})*\\s*\\)`,O=`(?:${e}|(?:${e})?(?:${r}|${P})+)`,N=`(?:${e}|(?:${e})?(?:${r}|${D})+)`,Ft=`(?:${p}|(?:${p})?(?:${r})+)`,S=`${N}(?:${T}${N})*`,L="(?:is|not)",Mt=`${L}\\(\\s*${S}(?:\\s*,\\s*${S})*\\s*\\)`,it=`${L}\\(\\s*${O}(?:\\s*,\\s*${O})*\\s*\\)`,Ut=/^(?:has|is|not|where)$/,at=/^(?:date(?:time-local)?|email|month|number|password|search|tel|text|time|url|week)$/;0&&(module.exports={ALPHA_NUM,ANB,AN_PLUS_B,ATTR_SELECTOR,BIT_01,BIT_02,BIT_04,BIT_08,BIT_16,BIT_32,BIT_FFFF,CHILD_IDX,CLASS_SELECTOR,COMBINATOR,COMBO,COMPLEX,COMPLEX_L,COMPOUND,COMPOUND_A,COMPOUND_B,COMPOUND_I,DESCEND,DIGIT,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,DUO,ELEMENT_NODE,EMPTY,HEX,HYPHEN,IDENT,ID_SELECTOR,KEY_IS_NOT,LANG_PART,LOGICAL_COMPLEX,LOGICAL_COMPOUND,NESTED_LOGICAL_A,NESTED_LOGICAL_B,NOT_SUPPORTED_ERR,NTH,N_TH,PSEUDO_CLASS,PS_CLASS_SELECTOR,PS_ELEMENT_SELECTOR,RAW,REG_INPUT_TYPE,REG_LOGICAL,SELECTOR,SELECTOR_LIST,SHOW_ALL,SHOW_DOCUMENT,SHOW_DOCUMENT_FRAGMENT,SHOW_ELEMENT,STRING,SUB_TYPE,SYNTAX_ERR,TAG_TYPE,TAG_TYPE_I,TARGET_ALL,TARGET_FIRST,TARGET_LINEAL,TARGET_SELF,TEXT_NODE,TYPE_FROM,TYPE_SELECTOR,TYPE_TO,U_FFFD,WALKER_FILTER}); | ||
var x=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var F=(o,t)=>{for(var c in t)x(o,c,{get:t[c],enumerable:!0})},i=(o,t,c,L)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of l(t))!M.call(o,s)&&s!==c&&x(o,s,{get:()=>t[s],enumerable:!(L=R(t,s))||L.enumerable});return o};var a=o=>i(x({},"__esModule",{value:!0}),o);var Mt={};F(Mt,{ALPHA_NUM:()=>$,ANB:()=>A,ATTR_SELECTOR:()=>G,BIT_01:()=>v,BIT_02:()=>K,BIT_04:()=>g,BIT_08:()=>z,BIT_16:()=>j,BIT_32:()=>q,BIT_FFFF:()=>J,CHILD_IDX:()=>I,CLASS_SELECTOR:()=>U,COMBINATOR:()=>d,COMBO:()=>T,COMPLEX:()=>_,COMPLEX_L:()=>S,COMPOUND:()=>n,COMPOUND_A:()=>O,COMPOUND_B:()=>N,COMPOUND_I:()=>At,DESCEND:()=>It,DIGIT:()=>E,DOCUMENT_FRAGMENT_NODE:()=>ct,DOCUMENT_NODE:()=>nt,DOCUMENT_POSITION_CONTAINED_BY:()=>pt,DOCUMENT_POSITION_CONTAINS:()=>xt,DOCUMENT_POSITION_PRECEDING:()=>Et,DUO:()=>Q,ELEMENT_NODE:()=>st,EMPTY:()=>B,HEX:()=>V,HYPHEN:()=>tt,IDENT:()=>Y,ID_SELECTOR:()=>H,KEY_IS_NOT:()=>C,LANG_PART:()=>Ct,LOGICAL_COMPLEX:()=>Pt,LOGICAL_COMPOUND:()=>Dt,NESTED_LOGICAL_A:()=>P,NESTED_LOGICAL_B:()=>D,NOT_SUPPORTED_ERR:()=>h,NTH:()=>m,N_TH:()=>$t,PSEUDO_CLASS:()=>Lt,PS_CLASS_SELECTOR:()=>y,PS_ELEMENT_SELECTOR:()=>X,REG_INPUT_TYPE:()=>lt,REG_LOGICAL:()=>Rt,SELECTOR:()=>f,SHOW_ALL:()=>Tt,SHOW_DOCUMENT:()=>_t,SHOW_DOCUMENT_FRAGMENT:()=>Ot,SHOW_ELEMENT:()=>Nt,SUB_TYPE:()=>r,SYNTAX_ERR:()=>u,TAG_TYPE:()=>e,TAG_TYPE_I:()=>p,TARGET_ALL:()=>w,TARGET_FIRST:()=>W,TARGET_LINEAL:()=>b,TARGET_SELF:()=>k,TEXT_NODE:()=>rt,TYPE_FROM:()=>ot,TYPE_SELECTOR:()=>Z,TYPE_TO:()=>et,WALKER_FILTER:()=>St});module.exports=a(Mt);const G="AttributeSelector",U="ClassSelector",d="Combinator",B="__EMPTY__",Y="Identifier",H="IdSelector",h="NotSupportedError",m="Nth",y="PseudoClassSelector",X="PseudoElementSelector",f="Selector",u="SyntaxError",w="all",W="first",b="lineal",k="self",Z="TypeSelector",v=1,K=2,g=4,z=8,j=16,q=32,J=65535,Q=2,V=16,tt=45,ot=8,et=-1,st=1,rt=3,nt=9,ct=11,Et=2,xt=8,pt=16,Tt=4294967295,_t=256,Ot=1024,Nt=1,St=1281,$="[A-Z\\d]+",I="(?:first|last|only)-(?:child|of-type)",E="(?:0|[1-9]\\d*)",Ct=`(?:-${$})*`,Lt=`(?:any-)?link|${I}|checked|empty|indeterminate|root|target|visited`,A=`[+-]?(?:${E}n?|n)|(?:[+-]?${E})?n\\s*[+-]\\s*${E}`,$t=`nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${A})\\s*\\)`,r="\\[[^|\\]]+\\]|[#.:][\\w-]+",e="\\*|[A-Za-z][\\w-]*",p="\\*|[A-Z][\\w-]*",n=`(?:${e}|(?:${e})?(?:${r})+)`,T="\\s?[\\s>~+]\\s?",_=`${n}(?:${T}${n})*`,It="\\s?[\\s>]\\s?",P=`:is\\(\\s*${n}(?:\\s*,\\s*${n})*\\s*\\)`,D=`:is\\(\\s*${_}(?:\\s*,\\s*${_})*\\s*\\)`,O=`(?:${e}|(?:${e})?(?:${r}|${P})+)`,N=`(?:${e}|(?:${e})?(?:${r}|${D})+)`,At=`(?:${p}|(?:${p})?(?:${r})+)`,S=`${N}(?:${T}${N})*`,C="(?:is|not)",Pt=`${C}\\(\\s*${S}(?:\\s*,\\s*${S})*\\s*\\)`,Dt=`${C}\\(\\s*${O}(?:\\s*,\\s*${O})*\\s*\\)`,Rt=/^(?:has|is|not|where)$/,lt=/^(?:date(?:time-local)?|email|month|number|password|search|tel|text|time|url|week)$/;0&&(module.exports={ALPHA_NUM,ANB,ATTR_SELECTOR,BIT_01,BIT_02,BIT_04,BIT_08,BIT_16,BIT_32,BIT_FFFF,CHILD_IDX,CLASS_SELECTOR,COMBINATOR,COMBO,COMPLEX,COMPLEX_L,COMPOUND,COMPOUND_A,COMPOUND_B,COMPOUND_I,DESCEND,DIGIT,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,DUO,ELEMENT_NODE,EMPTY,HEX,HYPHEN,IDENT,ID_SELECTOR,KEY_IS_NOT,LANG_PART,LOGICAL_COMPLEX,LOGICAL_COMPOUND,NESTED_LOGICAL_A,NESTED_LOGICAL_B,NOT_SUPPORTED_ERR,NTH,N_TH,PSEUDO_CLASS,PS_CLASS_SELECTOR,PS_ELEMENT_SELECTOR,REG_INPUT_TYPE,REG_LOGICAL,SELECTOR,SHOW_ALL,SHOW_DOCUMENT,SHOW_DOCUMENT_FRAGMENT,SHOW_ELEMENT,SUB_TYPE,SYNTAX_ERR,TAG_TYPE,TAG_TYPE_I,TARGET_ALL,TARGET_FIRST,TARGET_LINEAL,TARGET_SELF,TEXT_NODE,TYPE_FROM,TYPE_SELECTOR,TYPE_TO,WALKER_FILTER}); | ||
//# sourceMappingURL=constant.js.map |
@@ -1,2 +0,2 @@ | ||
var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var Y=(S,r)=>{for(var e in r)R(S,e,{get:r[e],enumerable:!0})},q=(S,r,e,h)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of j(r))!V.call(S,n)&&n!==e&&R(S,n,{get:()=>r[n],enumerable:!(h=B(r,n))||h.enumerable});return S};var K=S=>q(R({},"__esModule",{value:!0}),S);var Z={};Y(Z,{Finder:()=>J});module.exports=K(Z);var F=require("./matcher.js"),g=require("./parser.js"),k=require("./utility.js"),c=require("./constant.js");const v="next",x="prev",X="Tab",O=/^a(?:rea)?$/,M=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,T=/^(?:button|form|input|select|textarea)$/,I=/^(?:details|dialog)$/,P=/^host(?:-context)?$/,C=/^(?:checkbox|radio)$/,$=/^(?:date(?:time-local)?|month|number|range|time|week)$/,D=/^(?:button|reset)$/,U=/^(?:image|submit)$/,Q=/^(?:email|number|password|search|tel|text|url)$/;class J{#l;#c;#w;#t;#o;#n;#k;#f;#b;#h;#e;#d;#_;#m;#N;#s;#u;#r;#p;#i;#a;constructor(r){this.#a=r,this.#h=new F.Matcher,this.#c=new WeakMap,this.#o=new WeakMap,this.#b=new WeakMap,this.#N=new WeakMap,this.#n=null,this.#k=null,this._registerEventListeners()}onError(r,e={}){if(!(e.noexcept??this.#_))if(r instanceof DOMException||r instanceof this.#a.DOMException)if(r.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw new this.#a.DOMException(r.message,r.name);else throw r.name in this.#a?new this.#a[r.name](r.message):r}setup(r,e,h={}){const{event:n,noexcept:a,warn:l}=h;return this.#_=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#u=(0,k.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(r),this.#b=new WeakMap,this.#p=new WeakMap,this._setEvent(n),e}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],h=["mouseover","mousedown","mouseup","mouseout"];for(const a of h)e.push(this.#a.addEventListener(a,l=>{this.#n=l},r));const n=["keydown","keyup"];for(const a of n)e.push(this.#a.addEventListener(a,l=>{l.key===X&&(this.#n=l)},r));return e.push(this.#a.addEventListener("focusin",a=>{this.#k=a},r)),e}_setEvent(r){return(r instanceof this.#a.KeyboardEvent||r instanceof this.#a.MouseEvent)&&(this.#n=r),this.#n}_correspond(r){const e=[];this.#w=!1,this.#f=!1;let h;if(this.#o.has(this.#t)){const n=this.#o.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);h=a.ast,this.#w=a.descendant,this.#f=a.invalidate}}if(h){const n=h.length;for(let a=0;a<n;a++)h[a].collected=!1,h[a].dir=null,h[a].filtered=!1,h[a].find=!1,e[a]=[]}else{let n;try{n=(0,g.parseSelector)(r)}catch(s){this.onError(s)}const{branches:a,info:{hasHasPseudoFunc:l}}=(0,g.walkAST)(n);let o=!!l,u=!1,d=0;h=[];for(const[...s]of a){const t=[];let f=s.shift();if(f&&f.type!==c.COMBINATOR){const b=new Set;for(;f;){if(f.type===c.COMBINATOR){const[m]=s;if(m.type===c.COMBINATOR)throw new DOMException(`Invalid selector ${r}`,c.SYNTAX_ERR);const w=f.name;/^[\s>]$/.test(w)?u=!0:o=!0,t.push({combo:f,leaves:(0,g.sortAST)(b)}),b.clear()}else if(f){let{name:m}=f;m&&typeof m=="string"&&(m=(0,g.unescapeSelector)(m),typeof m=="string"&&m!==f.name&&(f.name=m),/[|:]/.test(m)&&(f.namespace=!0)),b.add(f)}if(s.length)f=s.shift();else{t.push({combo:null,leaves:(0,g.sortAST)(b)}),b.clear();break}}}h.push({branch:t,collected:!1,dir:null,filtered:!1,find:!1}),e[d]=[],d++}let i;this.#o.has(this.#t)?i=this.#o.get(this.#t):i=new Map,i.set(`${r}`,{ast:h,descendant:u,invalidate:o}),this.#o.set(this.#t,i),this.#w=u,this.#f=o}return[h,e]}_createTreeWalker(r){let e;return this.#p.has(r)?e=this.#p.get(r):(e=this.#t.createTreeWalker(r,c.WALKER_FILTER),this.#p.set(r,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(r,e,h){const{a:n,b:a,reverse:l,selector:o}=r,{parentNode:u}=e,d=new Set;let i;if(o)if(this.#c.has(o))i=this.#c.get(o);else{const{branches:s,info:t}=(0,g.walkAST)(o);i=s,this.#c.set(o,i),t.hasLogicalPseudoFunc&&(this.#f=!0)}if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let f=0;for(;t;)f++,t=s.nextSibling();const b=new Set;if(i)for(t=(0,k.traverseNode)(u,s),t=s.firstChild();t;){if((0,k.isVisible)(t)){let m;for(const w of i)if(m=this._matchLeaves(w,t,h),!m)break;m&&b.add(t)}t=s.nextSibling()}if(n===0){if(a>0&&a<=f){if(b.size){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(b.has(t)){if(m===a-1){d.add(t);break}m++}l?t=s.previousSibling():t=s.nextSibling()}}else if(!o){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(m===a-1){d.add(t);break}l?t=s.previousSibling():t=s.nextSibling(),m++}}}}else{let m=a-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m<f){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let w=0,p=n>0?0:a-1;for(;t&&(t&&m>=0&&m<f);)b.size?b.has(t)&&(p===m&&(d.add(t),m+=n),n>0?p++:p--):w===m&&(o||d.add(t),m+=n),l?t=s.previousSibling():t=s.nextSibling(),w++}}if(l&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&n+a===1)if(i){let s;for(const t of i)if(s=this._matchLeaves(t,e,h),s)break;s&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:h,b:n,reverse:a}=r,{localName:l,namespaceURI:o,parentNode:u,prefix:d}=e,i=new Set;if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let f=0;for(;t;)f++,t=s.nextSibling();if(h===0){if(n>0&&n<=f){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let b=0;for(;t;){const{localName:m,namespaceURI:w,prefix:p}=t;if(m===l&&p===d&&w===o){if(b===n-1){i.add(t);break}b++}a?t=s.previousSibling():t=s.nextSibling()}}}else{let b=n-1;if(h>0)for(;b<0;)b+=h;if(b>=0&&b<f){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let m=h>0?0:n-1;for(;t;){const{localName:w,namespaceURI:p,prefix:N}=t;if(w===l&&N===d&&p===o){if(m===b&&(i.add(t),b+=h),b<0||b>=f)break;h>0?m++:m--}a?t=s.previousSibling():t=s.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&h+n===1&&i.add(e);return i}_matchAnPlusB(r,e,h,n){const{nth:{a,b:l,name:o},selector:u}=r,d=new Map;if(o?(o==="even"?(d.set("a",2),d.set("b",0)):o==="odd"&&(d.set("a",2),d.set("b",1)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),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,n)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,h={}){let n;if(Array.isArray(r)&&r.length){const a=r.map(t=>t),[l]=a,{type:o}=l;let u;o===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[t]=a,{type:f}=t;if(f===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};h.dir=v;const s=this._matchCombinator(i,e,h);if(s.size)if(a.length){for(const t of s)if(n=this._matchHasPseudoFunc(a,t,h),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,h={}){const{astName:n="",branches:a=[],selector:l="",twigBranches:o=[]}=r;let u;if(n==="has")if(l.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(n);h.forgive=d;const i=o.length;let s;for(let t=0;t<i;t++){const f=o[t],b=f.length-1,{leaves:m}=f[b];if(s=this._matchLeaves(m,e,h),s&&b>0){let w=new Set([e]);for(let p=b-1;p>=0;p--){const N=f[p],_=[];h.dir=x;for(const y of w){const E=this._matchCombinator(N,y,h);E.size&&_.push(...E)}if(_.length)p===0?s=!0:w=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(u=e):s&&(u=e)}return u??null}_matchPseudoClassSelector(r,e,h={}){const{children:n,name:a}=r,{localName:l,parentNode:o}=e,{forgive:u,warn:d=this.#i}=h,i=new Set;if(c.REG_LOGICAL.test(a)){let s;if(this.#c.has(r))s=this.#c.get(r);else{const{branches:f}=(0,g.walkAST)(r),b=[],m=[];for(const[...w]of f){for(const y of w){const E=(0,g.generateCSS)(y);b.push(E)}const p=[],N=new Set;let _=w.shift();for(;_;)if(_.type===c.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)}s={astName:a,branches:f,twigBranches:m,selector:b.join(",")},this.#c.set(r,s)}const t=this._matchLogicalPseudoFunc(s,e,h);t&&i.add(t)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[s]=n;return this._matchAnPlusB(s,e,a,h)}else switch(a){case"dir":case"lang":{const s=this.#h.matchSelector(r,e,h,!0);s&&i.add(s);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:s}]=n;if(s)if(e[s])i.add(e);else for(const t in e){const f=e[t];if(f instanceof this.#a.ElementInternals){f?.states?.has(s)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,c.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{O.test(l)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(O.test(l)&&e.hasAttribute("href")){const{href:s,origin:t,pathname:f}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),s);b.origin===t&&b.pathname===f&&i.add(e)}break}case"visited":break;case"hover":{const{target:s,type:t}=this.#n??{};/^(?:mouse|pointer)(?:down|over|up)$/.test(t)&&e.contains(s)&&i.add(e);break}case"active":{const{buttons:s,target:t,type:f}=this.#n??{};/(?:mouse|pointer)down/.test(f)&&s&c.BIT_01&&e.contains(t)&&i.add(e);break}case"target":{const{hash:s}=new URL(this.#t.URL);e.id&&s===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:s}=new URL(this.#t.URL);if(s){const t=s.replace(/^#/,"");let f=this.#t.getElementById(t);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.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&e.tabIndex>=0&&(0,k.isFocusable)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&e.tabIndex>=0){let s;if((0,k.isFocusVisible)(e))s=!0;else{const{target:t,type:f}=this.#n??{},{target:b,relatedTarget:m}=this.#k??{};(/^key(?:down|up)$/.test(f)&&e.contains(t)||m&&(0,k.isFocusVisible)(m)&&e.contains(b))&&(s=!0)}s&&(0,k.isFocusable)(e)&&i.add(e)}break}case"focus-within":{let s,t=this.#t.activeElement;if(t.tabIndex>=0)for(;t;){if(t===e){s=!0;break}t=t.parentNode}s&&(0,k.isFocusable)(e)&&i.add(e);break}case"open":{I.test(l)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{I.test(l)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")o.localName==="optgroup"&&(o.disabled||o.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const f=this.#r;let b=(0,k.traverseNode)(t,f);for(b=f.firstChild();b&&b.localName!=="legend";)b=f.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s&&i.add(e)}}break}case"enabled":{if((M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(o.localName!=="optgroup"||!(o.disabled||o.hasAttribute("disabled")))&&i.add(e);else{let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const f=this.#r;let b=(0,k.traverseNode)(t,f);for(b=f.firstChild();b&&b.localName!=="legend";)b=f.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s||i.add(e)}break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let s;if(e.placeholder?s=e.placeholder:e.hasAttribute("placeholder")&&(s=e.getAttribute("placeholder")),typeof s=="string"&&!/[\r\n]/.test(s)){let t;l==="textarea"?t=e:l==="input"&&(e.hasAttribute("type")?Q.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;t||(t=this.#t.documentElement);const f=t.getElementsByTagName("input"),b=f.length;let m;for(let w=0;w<b;w++){const p=f[w];if(p.getAttribute("type")==="radio"&&(s?p.getAttribute("name")===s&&(m=!!p.checked):p.hasAttribute("name")||(m=!!p.checked),m))break}m||i.add(e)}break}case"default":{if(l==="button"&&!(e.hasAttribute("type")&&D.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&U.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const t=this.#r;let f=(0,k.traverseNode)(s,t);for(f=t.firstChild();f&&s.contains(f);){const b=f.localName;let m;if(b==="button"?m=!(f.hasAttribute("type")&&D.test(f.getAttribute("type"))):b==="input"&&(m=f.hasAttribute("type")&&U.test(f.getAttribute("type"))),m){f===e&&i.add(e);break}f=t.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(T.test(l))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let f;if(!t)f=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?f=t.maxLength>=t.value.length:f=!0:f=!1,!f));)t=s.nextNode();f&&i.add(e)}break}case"invalid":{if(T.test(l))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let f;if(!t)f=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?f=t.maxLength>=t.value.length:f=!0:f=!1,!f));)t=s.nextNode();f||i.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const s=this.#t.createTreeWalker(e,c.SHOW_ALL);let t=s.firstChild(),f;for(;t&&(f=t.nodeType!==c.ELEMENT_NODE&&t.nodeType!==c.TEXT_NODE,!!f);)t=s.nextSibling();f&&i.add(e)}else i.add(e);break}case"first-child":{(o&&e===o.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(o&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(o&&e===o.firstElementChild&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,k.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d)throw new DOMException(`Unsupported pseudo-element ::${a}`,c.NOT_SUPPORTED_ERR);break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,c.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(r,e){const{children:h,name:n}=r;let a;if(Array.isArray(h)){const{branches:l}=(0,g.walkAST)(h[0]),[o]=l,[...u]=o,{host:d}=e;if(n==="host"){let i;for(const s of u){const{type:t}=s;if(t===c.COMBINATOR){const f=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${f}`,c.SYNTAX_ERR)}if(i=this._matchSelector(s,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,s;for(;i;){for(const t of u){const{type:f}=t;if(f===c.COMBINATOR){const b=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(s=this._matchSelector(t,i).has(i),!s)break}if(s)break;i=i.parentNode}s&&(a=e)}}else if(n==="host")a=e;else throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR);return a??null}_matchSelector(r,e,h){const{type:n}=r,a=new Set;if(r.name===c.EMPTY)return a;const l=(0,g.unescapeSelector)(r.name);if(typeof l=="string"&&l!==r.name&&(r.name=l),e.nodeType===c.ELEMENT_NODE)switch(n){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(l,h);break}case c.ID_SELECTOR:{e.id===l&&a.add(e);break}case c.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case c.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(r,e,h);default:{const o=this.#h.matchSelector(r,e,h,!0);o&&a.add(o)}}else if(this.#u&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&c.REG_LOGICAL.test(l))return this._matchPseudoClassSelector(r,e,h);if(P.test(l)){const o=this._matchShadowHostPseudoClass(r,e,h);o&&a.add(o)}}return a}_matchLeaves(r,e,h){let n,a;if(this.#f?a=this.#b.get(r):a=this.#N.get(r),a&&a.has(e)){const{matched:l}=a.get(e);n=l}if(typeof n!="boolean"){let l=!0;e.nodeType===c.ELEMENT_NODE&&/^(?:button|fieldset|form|input|select|textarea)$/.test(e.localName)&&(l=!1);for(const o of r){switch(o.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{/^(?:(?:any-)?link|defined|dir)$/.test(o.name)&&(l=!1);break}default:}if(n=this._matchSelector(o,e,h).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#f?this.#b.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e={}){const{compound:h,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(h)for(let o=0;o<l;o++){const u=r[o];this._matchLeaves(n,u,e)&&a.add(u)}else{const o=[].slice.call(r);return new Set(o)}return a}_findDescendantNodes(r,e,h){const[n,...a]=r,l=a.length>0,{type:o}=n,u=(0,g.unescapeSelector)(n.name);typeof u=="string"&&u!==n.name&&(n.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(o){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,h);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const s=this.#s.getElementById(u);s&&s!==e&&e.contains(s)&&(l?this._matchLeaves(a,s,h)&&d.add(s):d.add(s))}break}case c.CLASS_SELECTOR:{const s=e.getElementsByClassName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const s=e.getElementsByTagName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,h={}){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:o}=e,{dir:u}=h,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(e,i);for(s=i.nextSibling();s;)this._matchLeaves(a,s,h)&&d.add(s),s=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let s=(0,k.traverseNode)(e,i);for(s=i.firstChild();s;)this._matchLeaves(a,s,h)&&d.add(s),s=i.nextSibling();break}case" ":default:{const{nodes:i,pending:s}=this._findDescendantNodes(a,e);if(i.size)return i;if(s){const t=this._createTreeWalker(e);let f=(0,k.traverseNode)(e,t);for(f=t.nextNode();f&&e.contains(f);)this._matchLeaves(a,f,h)&&d.add(f),f=t.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(o,i);for(s=i.firstChild();s&&s!==e;)this._matchLeaves(a,s,h)&&d.add(s),s=i.nextSibling()}break}case">":{o&&this._matchLeaves(a,o,h)&&d.add(o);break}case" ":default:{const i=[];let s=o;for(;s;)this._matchLeaves(a,s,h)&&i.push(s),s=s.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const{node:h}=e,n=this.#m;let a=(0,k.traverseNode)(h,n),l;if(a)for((a.nodeType!==c.ELEMENT_NODE||a===h&&a!==this.#s)&&(a=n.nextNode());a;){if(this._matchLeaves(r,a,{warn:this.#i})){l=a;break}a=n.nextNode()}return l??null}_matchSelf(r){const e=[],h=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return h&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e={}){const{complex:h}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||h){let o=this.#e.parentNode;for(;o&&(a=this._matchLeaves(r,o,{warn:this.#i}),a&&(n.push(o),l=!0),o.parentNode);)o=o.parentNode}return[n,l]}_findFirst(r){const e=[],h=this._findNode(r,{node:this.#e});let n=!1;return h&&(e.push(h),n=!0),[e,n]}_findFromHTMLCollection(r,e={}){const{complex:h,compound:n,filterLeaves:a,targetType:l}=e;let o=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let s=0;s<i;s++){const t=r[s];if(t!==this.#e&&(this.#e.contains(t)||t.contains(this.#e))){if(n){if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else if(o.push(t),u=!0,l===c.TARGET_FIRST)break}}else if(h)if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;else if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;return[o,u,d]}_findEntryNodes(r,e,h){const{leaves:n}=r,[a,...l]=n,o=l.length>0,{name:u,type:d}=a;let i=[],s=!1,t=!1,f=!1;switch(d){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,{warn:this.#i});break}case c.ID_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:h});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(o?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),t=!0):(i.push(b),t=!0))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):f=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:h});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:h,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):f=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:h});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:h,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):f=!0;break}default:if(e!==c.TARGET_LINEAL&&P.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),t=!0)}}else e===c.TARGET_SELF?[i,t]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,t]=this._findLineal(n,{complex:h}):e===c.TARGET_FIRST?[i,t]=this._findFirst(n):f=!0}return{collected:s,compound:o,filtered:t,nodes:i,pending:f}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const h=new Set;let n=0;for(const{branch:a}of e){const l=a.length,o=l>1,u=a[0];let d,i;if(o){const{combo:w,leaves:[{name:p,type:N}]}=u,_=a[l-1],{leaves:[{name:y,type:E}]}=_;if(E===c.PS_ELEMENT_SELECTOR||E===c.ID_SELECTOR)d=x,i=_;else if(N===c.PS_ELEMENT_SELECTOR||N===c.ID_SELECTOR)d=v,i=u;else if(r===c.TARGET_ALL)if(p==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:A}=w;/^[+~]$/.test(A)?(d=x,i=_):(d=v,i=u)}else d=v,i=u;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(p==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else{let A;for(const{combo:L,leaves:[W]}of a){const{name:G,type:H}=W;if(H===c.PS_CLASS_SELECTOR&&G==="dir"){A=!1;break}if(!A&&L){const{name:z}=L;/^[+~]$/.test(z)&&(A=!0)}}A?(d=v,i=u):(d=x,i=_)}}else d=x,i=u;const{collected:s,compound:t,filtered:f,nodes:b,pending:m}=this._findEntryNodes(i,r,o);b.length?(this.#l[n].find=!0,this.#d[n]=b):m&&h.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=s,this.#l[n].dir=d,this.#l[n].filtered=f||!t,n++}if(h.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,l=this.#m):(a=this.#s,l=this.#r);let o=(0,k.traverseNode)(a,l);for(;o;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?o===this.#e?u=!0:u=this.#e.contains(o):u=!0,u)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,o,{warn:this.#i})){const t=d.get("index");this.#l[t].filtered=!0,this.#l[t].find=!0,this.#d[t].push(o)}}o!==l.currentNode&&(o=(0,k.traverseNode)(o,l)),o=l.nextNode()}}}else{let h=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:o,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[h].find=!0,this.#d[h]=d),this.#l[h].dir=x,this.#l[h].filtered=u||!o,h++}}return[this.#l,this.#d]}_getCombinedNodes(r,e,h){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:h,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,h){const{combo:n,index:a}=h,{combo:l,leaves:o}=r[a],u={combo:n,leaves:o},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===r.length-1){const[s]=(0,k.sortNodes)(d);i=s}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,h){const{index:n}=h,a=r[n],l=new Set([e]),o=this._getCombinedNodes(a,l,x);let u;if(o.size){if(n===0)u=e;else for(const d of o)if(this._matchNodePrev(r,d,{index:n-1}))return e}return u??null}find(r){(r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let o=0;o<n;o++){const{branch:u,collected:d,dir:i,find:s}=e[o],t=u.length;if(t&&s){const f=h[o],b=f.length,m=t-1;if(m===0)if((r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this.#e.nodeType===c.ELEMENT_NODE)for(let w=0;w<b;w++){const p=f[w];if(p!==this.#e&&this.#e.contains(p)&&(l.add(p),r!==c.TARGET_ALL))break}else if(r===c.TARGET_ALL)if(l.size){const w=[...l];l=new Set([...w,...f]),a=!0}else l=new Set(f);else{const[w]=f;l.add(w)}else if(r===c.TARGET_ALL)if(i===v){let{combo:w}=u[0];for(const p of f){let N=new Set([p]);for(let _=1;_<t;_++){const{combo:y,leaves:E}=u[_],A={combo:w,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(l.size){const L=[...l];l=new Set([...L,...N]),a=!0}else l=N;else w=y;else break}}}else for(const w of f){let p=new Set([w]);for(let N=m-1;N>=0;N--){const _=u[N];if(p=this._getCombinedNodes(_,p,i),p.size)N===0&&(l.add(w),t>1&&l.size>1&&(a=!0));else break}}else if(r===c.TARGET_FIRST&&i===v){const{combo:w}=u[0];let p;for(const N of f)if(p=this._matchNodeNext(u,new Set([N]),{combo:w,index:1}),p){l.add(p);break}if(!p&&!d){const{leaves:N}=u[0],[_]=f;let y=this._findNode(N,{node:_});for(;y;){if(p=this._matchNodeNext(u,new Set([y]),{combo:w,index:1}),p){l.add(p);break}y=this._findNode(N,{node:y})}}}else{let w;for(const p of f)if(w=this._matchNodePrev(u,p,{index:m-1}),w){l.add(p);break}if(!w&&!d&&r===c.TARGET_FIRST){const{leaves:p}=u[m],[N]=f;let _=this._findNode(p,{node:N});for(;_;){if(w=this._matchNodePrev(u,_,{index:m-1}),w){l.add(_);break}_=this._findNode(p,{node:_})}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,k.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,k.sortNodes)(l)))),l}}0&&(module.exports={Finder}); | ||
var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var Y=(S,r)=>{for(var e in r)R(S,e,{get:r[e],enumerable:!0})},q=(S,r,e,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of j(r))!V.call(S,n)&&n!==e&&R(S,n,{get:()=>r[n],enumerable:!(f=B(r,n))||f.enumerable});return S};var K=S=>q(R({},"__esModule",{value:!0}),S);var Z={};Y(Z,{Finder:()=>J});module.exports=K(Z);var F=require("./matcher.js"),g=require("./parser.js"),k=require("./utility.js"),c=require("./constant.js");const v="next",x="prev",X="Tab",O=/^a(?:rea)?$/,M=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,T=/^(?:button|form|input|select|textarea)$/,I=/^(?:details|dialog)$/,$=/^host(?:-context)?$/,C=/^(?:checkbox|radio)$/,P=/^(?:date(?:time-local)?|month|number|range|time|week)$/,D=/^(?:button|reset)$/,U=/^(?:image|submit)$/,Q=/^(?:email|number|password|search|tel|text|url)$/;class J{#l;#c;#w;#t;#o;#n;#k;#f;#d;#h;#e;#u;#_;#m;#N;#s;#b;#r;#p;#i;#a;constructor(r){this.#a=r,this.#h=new F.Matcher,this.#c=new WeakMap,this.#o=new WeakMap,this.#d=new WeakMap,this.#N=new WeakMap,this.#n=null,this.#k=null,this._registerEventListeners()}onError(r,e={}){if(!(e.noexcept??this.#_))if(r instanceof DOMException||r instanceof this.#a.DOMException)if(r.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw new this.#a.DOMException(r.message,r.name);else throw r.name in this.#a?new this.#a[r.name](r.message):r}setup(r,e,f={}){const{event:n,noexcept:a,warn:l}=f;return this.#_=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#b=(0,k.isInShadowTree)(e),[this.#l,this.#u]=this._correspond(r),this.#d=new WeakMap,this.#p=new WeakMap,this._setEvent(n),e}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],f=["mouseover","mousedown","mouseup","mouseout"];for(const a of f)e.push(this.#a.addEventListener(a,l=>{this.#n=l},r));const n=["keydown","keyup"];for(const a of n)e.push(this.#a.addEventListener(a,l=>{l.key===X&&(this.#n=l)},r));return e.push(this.#a.addEventListener("focusin",a=>{this.#k=a},r)),e}_setEvent(r){return(r instanceof this.#a.KeyboardEvent||r instanceof this.#a.MouseEvent)&&(this.#n=r),this.#n}_correspond(r){const e=[];this.#w=!1,this.#f=!1;let f;if(this.#o.has(this.#t)){const n=this.#o.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);f=a.ast,this.#w=a.descendant,this.#f=a.invalidate}}if(f){const n=f.length;for(let a=0;a<n;a++)f[a].collected=!1,f[a].dir=null,f[a].filtered=!1,f[a].find=!1,e[a]=[]}else{let n;try{n=(0,g.parseSelector)(r)}catch(t){this.onError(t)}const{branches:a,info:{hasHasPseudoFunc:l,hasNthChildOfSelector:o}}=(0,g.walkAST)(n);let u=!!(l||o),d=!1,i=0;f=[];for(const[...t]of a){const h=[];let b=t.shift();if(b&&b.type!==c.COMBINATOR){const m=new Set;for(;b;){if(b.type===c.COMBINATOR){const[p]=t;if(p.type===c.COMBINATOR)throw new DOMException(`Invalid selector ${r}`,c.SYNTAX_ERR);const w=b.name;/^[\s>]$/.test(w)?d=!0:u=!0,h.push({combo:b,leaves:(0,g.sortAST)(m)}),m.clear()}else if(b){let{name:p}=b;p&&typeof p=="string"&&(p=(0,g.unescapeSelector)(p),typeof p=="string"&&p!==b.name&&(b.name=p),/[|:]/.test(p)&&(b.namespace=!0)),m.add(b)}if(t.length)b=t.shift();else{h.push({combo:null,leaves:(0,g.sortAST)(m)}),m.clear();break}}}f.push({branch:h,collected:!1,dir:null,filtered:!1,find:!1}),e[i]=[],i++}let s;this.#o.has(this.#t)?s=this.#o.get(this.#t):s=new Map,s.set(`${r}`,{ast:f,descendant:d,invalidate:u}),this.#o.set(this.#t,s),this.#w=d,this.#f=u}return[f,e]}_createTreeWalker(r){let e;return this.#p.has(r)?e=this.#p.get(r):(e=this.#t.createTreeWalker(r,c.WALKER_FILTER),this.#p.set(r,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(r,e,f){const{a:n,b:a,reverse:l,selector:o}=r,{parentNode:u}=e,d=new Set;let i;if(o)if(this.#c.has(o))i=this.#c.get(o);else{const{branches:s}=(0,g.walkAST)(o);i=s,this.#c.set(o,i)}if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();const b=new Set;if(i)for(t=(0,k.traverseNode)(u,s),t=s.firstChild();t;){if((0,k.isVisible)(t)){let m;for(const p of i)if(m=this._matchLeaves(p,t,f),!m)break;m&&b.add(t)}t=s.nextSibling()}if(n===0){if(a>0&&a<=h){if(b.size){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(b.has(t)){if(m===a-1){d.add(t);break}m++}l?t=s.previousSibling():t=s.nextSibling()}}else if(!o){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(m===a-1){d.add(t);break}l?t=s.previousSibling():t=s.nextSibling(),m++}}}}else{let m=a-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m<h){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let p=0,w=n>0?0:a-1;for(;t&&(t&&m>=0&&m<h);)b.size?b.has(t)&&(w===m&&(d.add(t),m+=n),n>0?w++:w--):p===m&&(o||d.add(t),m+=n),l?t=s.previousSibling():t=s.nextSibling(),p++}}if(l&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&n+a===1)if(i){let s;for(const t of i)if(s=this._matchLeaves(t,e,f),s)break;s&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:f,b:n,reverse:a}=r,{localName:l,namespaceURI:o,parentNode:u,prefix:d}=e,i=new Set;if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();if(f===0){if(n>0&&n<=h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let b=0;for(;t;){const{localName:m,namespaceURI:p,prefix:w}=t;if(m===l&&w===d&&p===o){if(b===n-1){i.add(t);break}b++}a?t=s.previousSibling():t=s.nextSibling()}}}else{let b=n-1;if(f>0)for(;b<0;)b+=f;if(b>=0&&b<h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let m=f>0?0:n-1;for(;t;){const{localName:p,namespaceURI:w,prefix:N}=t;if(p===l&&N===d&&w===o){if(m===b&&(i.add(t),b+=f),b<0||b>=h)break;f>0?m++:m--}a?t=s.previousSibling():t=s.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&f+n===1&&i.add(e);return i}_matchAnPlusB(r,e,f,n){const{nth:{a,b:l,name:o},selector:u}=r,d=new Map;if(o?(o==="even"?(d.set("a",2),d.set("b",0)):o==="odd"&&(d.set("a",2),d.set("b",1)),f.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),f.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(f)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,f={}){let n;if(Array.isArray(r)&&r.length){const a=r.map(t=>t),[l]=a,{type:o}=l;let u;o===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[t]=a,{type:h}=t;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};f.dir=v;const s=this._matchCombinator(i,e,f);if(s.size)if(a.length){for(const t of s)if(n=this._matchHasPseudoFunc(a,t,f),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,f={}){const{astName:n="",branches:a=[],selector:l="",twigBranches:o=[]}=r;let u;if(n==="has")if(l.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,f),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(n);f.forgive=d;const i=o.length;let s;for(let t=0;t<i;t++){const h=o[t],b=h.length-1,{leaves:m}=h[b];if(s=this._matchLeaves(m,e,f),s&&b>0){let p=new Set([e]);for(let w=b-1;w>=0;w--){const N=h[w],_=[];f.dir=x;for(const y of p){const E=this._matchCombinator(N,y,f);E.size&&_.push(...E)}if(_.length)w===0?s=!0:p=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(u=e):s&&(u=e)}return u??null}_matchPseudoClassSelector(r,e,f={}){const{children:n,name:a}=r,{localName:l,parentNode:o}=e,{forgive:u,warn:d=this.#i}=f,i=new Set;if(c.REG_LOGICAL.test(a)){let s;if(this.#c.has(r))s=this.#c.get(r);else{const{branches:h}=(0,g.walkAST)(r),b=[],m=[];for(const[...p]of h){for(const y of p){const E=(0,g.generateCSS)(y);b.push(E)}const w=[],N=new Set;let _=p.shift();for(;_;)if(_.type===c.COMBINATOR?(w.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),p.length)_=p.shift();else{w.push({combo:null,leaves:[...N]}),N.clear();break}m.push(w)}s={astName:a,branches:h,twigBranches:m,selector:b.join(",")},this.#c.set(r,s)}const t=this._matchLogicalPseudoFunc(s,e,f);t&&i.add(t)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[s]=n;return this._matchAnPlusB(s,e,a,f)}else switch(a){case"dir":case"lang":{const s=this.#h.matchSelector(r,e,f,!0);s&&i.add(s);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:s}]=n;if(s)if(e[s])i.add(e);else for(const t in e){const h=e[t];if(h instanceof this.#a.ElementInternals){h?.states?.has(s)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,c.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{O.test(l)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(O.test(l)&&e.hasAttribute("href")){const{href:s,origin:t,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),s);b.origin===t&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:s,type:t}=this.#n??{};/^(?:mouse|pointer)(?:down|over|up)$/.test(t)&&e.contains(s)&&i.add(e);break}case"active":{const{buttons:s,target:t,type:h}=this.#n??{};/(?:mouse|pointer)down/.test(h)&&s&c.BIT_01&&e.contains(t)&&i.add(e);break}case"target":{const{hash:s}=new URL(this.#t.URL);e.id&&s===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:s}=new URL(this.#t.URL);if(s){const t=s.replace(/^#/,"");let h=this.#t.getElementById(t);for(;h;){if(h===e){i.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#b&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&e.tabIndex>=0&&(0,k.isFocusable)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&e.tabIndex>=0){let s;if((0,k.isFocusVisible)(e))s=!0;else{const{target:t,type:h}=this.#n??{},{target:b,relatedTarget:m}=this.#k??{};(/^key(?:down|up)$/.test(h)&&e.contains(t)||m&&(0,k.isFocusVisible)(m)&&e.contains(b))&&(s=!0)}s&&(0,k.isFocusable)(e)&&i.add(e)}break}case"focus-within":{let s,t=this.#t.activeElement;if(t.tabIndex>=0)for(;t;){if(t===e){s=!0;break}t=t.parentNode}s&&(0,k.isFocusable)(e)&&i.add(e);break}case"open":{I.test(l)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{I.test(l)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")o.localName==="optgroup"&&(o.disabled||o.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s&&i.add(e)}}break}case"enabled":{if((M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(o.localName!=="optgroup"||!(o.disabled||o.hasAttribute("disabled")))&&i.add(e);else{let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s||i.add(e)}break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let s;if(e.placeholder?s=e.placeholder:e.hasAttribute("placeholder")&&(s=e.getAttribute("placeholder")),typeof s=="string"&&!/[\r\n]/.test(s)){let t;l==="textarea"?t=e:l==="input"&&(e.hasAttribute("type")?Q.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;t||(t=this.#t.documentElement);const h=t.getElementsByTagName("input"),b=h.length;let m;for(let p=0;p<b;p++){const w=h[p];if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(m=!!w.checked):w.hasAttribute("name")||(m=!!w.checked),m))break}m||i.add(e)}break}case"default":{if(l==="button"&&!(e.hasAttribute("type")&&D.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&U.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const t=this.#r;let h=(0,k.traverseNode)(s,t);for(h=t.firstChild();h&&s.contains(h);){const b=h.localName;let m;if(b==="button"?m=!(h.hasAttribute("type")&&D.test(h.getAttribute("type"))):b==="input"&&(m=h.hasAttribute("type")&&U.test(h.getAttribute("type"))),m){h===e&&i.add(e);break}h=t.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(T.test(l))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h&&i.add(e)}break}case"invalid":{if(T.test(l))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h||i.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&P.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&P.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const s=this.#t.createTreeWalker(e,c.SHOW_ALL);let t=s.firstChild(),h;for(;t&&(h=t.nodeType!==c.ELEMENT_NODE&&t.nodeType!==c.TEXT_NODE,!!h);)t=s.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(o&&e===o.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(o&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(o&&e===o.firstElementChild&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,k.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d)throw new DOMException(`Unsupported pseudo-element ::${a}`,c.NOT_SUPPORTED_ERR);break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,c.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(r,e){const{children:f,name:n}=r;let a;if(Array.isArray(f)){const{branches:l}=(0,g.walkAST)(f[0]),[o]=l,[...u]=o,{host:d}=e;if(n==="host"){let i;for(const s of u){const{type:t}=s;if(t===c.COMBINATOR){const h=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(s,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,s;for(;i;){for(const t of u){const{type:h}=t;if(h===c.COMBINATOR){const b=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(s=this._matchSelector(t,i).has(i),!s)break}if(s)break;i=i.parentNode}s&&(a=e)}}else if(n==="host")a=e;else throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR);return a??null}_matchSelector(r,e,f){const{type:n}=r,a=new Set;if(r.name===c.EMPTY)return a;const l=(0,g.unescapeSelector)(r.name);if(typeof l=="string"&&l!==r.name&&(r.name=l),e.nodeType===c.ELEMENT_NODE)switch(n){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(l,f);break}case c.ID_SELECTOR:{e.id===l&&a.add(e);break}case c.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case c.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(r,e,f);default:{const o=this.#h.matchSelector(r,e,f,!0);o&&a.add(o)}}else if(this.#b&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&c.REG_LOGICAL.test(l))return this._matchPseudoClassSelector(r,e,f);if($.test(l)){const o=this._matchShadowHostPseudoClass(r,e,f);o&&a.add(o)}}return a}_matchLeaves(r,e,f){let n,a;if(this.#f?a=this.#d.get(r):a=this.#N.get(r),a&&a.has(e)){const{matched:l}=a.get(e);n=l}if(typeof n!="boolean"){let l=!0;e.nodeType===c.ELEMENT_NODE&&/^(?:button|fieldset|form|input|select|textarea)$/.test(e.localName)&&(l=!1);for(const o of r){switch(o.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{/^(?:(?:any-)?link|defined|dir)$/.test(o.name)&&(l=!1);break}default:}if(n=this._matchSelector(o,e,f).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#f?this.#d.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e={}){const{compound:f,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(f)for(let o=0;o<l;o++){const u=r[o];this._matchLeaves(n,u,e)&&a.add(u)}else{const o=[].slice.call(r);return new Set(o)}return a}_findDescendantNodes(r,e,f){const[n,...a]=r,l=a.length>0,{type:o}=n,u=(0,g.unescapeSelector)(n.name);typeof u=="string"&&u!==n.name&&(n.name=u);let d=new Set,i=!1;if(this.#b)i=!0;else switch(o){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,f);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const s=this.#s.getElementById(u);s&&s!==e&&e.contains(s)&&(l?this._matchLeaves(a,s,f)&&d.add(s):d.add(s))}break}case c.CLASS_SELECTOR:{const s=e.getElementsByClassName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const s=e.getElementsByTagName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,f={}){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:o}=e,{dir:u}=f,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(e,i);for(s=i.nextSibling();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let s=(0,k.traverseNode)(e,i);for(s=i.firstChild();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling();break}case" ":default:{const{nodes:i,pending:s}=this._findDescendantNodes(a,e);if(i.size)return i;if(s){const t=this._createTreeWalker(e);let h=(0,k.traverseNode)(e,t);for(h=t.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,f)&&d.add(h),h=t.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(o,i);for(s=i.firstChild();s&&s!==e;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{o&&this._matchLeaves(a,o,f)&&d.add(o);break}case" ":default:{const i=[];let s=o;for(;s;)this._matchLeaves(a,s,f)&&i.push(s),s=s.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const{node:f}=e,n=this.#m;let a=(0,k.traverseNode)(f,n),l;if(a)for((a.nodeType!==c.ELEMENT_NODE||a===f&&a!==this.#s)&&(a=n.nextNode());a;){if(this._matchLeaves(r,a,{warn:this.#i})){l=a;break}a=n.nextNode()}return l??null}_matchSelf(r){const e=[],f=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return f&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e={}){const{complex:f}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||f){let o=this.#e.parentNode;for(;o&&(a=this._matchLeaves(r,o,{warn:this.#i}),a&&(n.push(o),l=!0),o.parentNode);)o=o.parentNode}return[n,l]}_findFirst(r){const e=[],f=this._findNode(r,{node:this.#e});let n=!1;return f&&(e.push(f),n=!0),[e,n]}_findFromHTMLCollection(r,e={}){const{complex:f,compound:n,filterLeaves:a,targetType:l}=e;let o=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let s=0;s<i;s++){const t=r[s];if(t!==this.#e&&(this.#e.contains(t)||t.contains(this.#e))){if(n){if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else if(o.push(t),u=!0,l===c.TARGET_FIRST)break}}else if(f)if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;else if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;return[o,u,d]}_findEntryNodes(r,e,f){const{leaves:n}=r,[a,...l]=n,o=l.length>0,{name:u,type:d}=a;let i=[],s=!1,t=!1,h=!1;switch(d){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,{warn:this.#i});break}case c.ID_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(o?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),t=!0):(i.push(b),t=!0))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}default:if(e!==c.TARGET_LINEAL&&$.test(u)){if(this.#b&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),t=!0)}}else e===c.TARGET_SELF?[i,t]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,t]=this._findLineal(n,{complex:f}):e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0}return{collected:s,compound:o,filtered:t,nodes:i,pending:h}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const f=new Set;let n=0;for(const{branch:a}of e){const l=a.length,o=l>1,u=a[0];let d,i;if(o){const{combo:p,leaves:[{name:w,type:N}]}=u,_=a[l-1],{leaves:[{name:y,type:E}]}=_;if(E===c.PS_ELEMENT_SELECTOR||E===c.ID_SELECTOR)d=x,i=_;else if(N===c.PS_ELEMENT_SELECTOR||N===c.ID_SELECTOR)d=v,i=u;else if(r===c.TARGET_ALL)if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:A}=p;/^[+~]$/.test(A)?(d=x,i=_):(d=v,i=u)}else d=v,i=u;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else{let A;for(const{combo:L,leaves:[W]}of a){const{name:G,type:H}=W;if(H===c.PS_CLASS_SELECTOR&&G==="dir"){A=!1;break}if(!A&&L){const{name:z}=L;/^[+~]$/.test(z)&&(A=!0)}}A?(d=v,i=u):(d=x,i=_)}}else d=x,i=u;const{collected:s,compound:t,filtered:h,nodes:b,pending:m}=this._findEntryNodes(i,r,o);b.length?(this.#l[n].find=!0,this.#u[n]=b):m&&f.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=s,this.#l[n].dir=d,this.#l[n].filtered=h||!t,n++}if(f.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,l=this.#m):(a=this.#s,l=this.#r);let o=(0,k.traverseNode)(a,l);for(;o;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?o===this.#e?u=!0:u=this.#e.contains(o):u=!0,u)for(const d of f){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,o,{warn:this.#i})){const t=d.get("index");this.#l[t].filtered=!0,this.#l[t].find=!0,this.#u[t].push(o)}}o!==l.currentNode&&(o=(0,k.traverseNode)(o,l)),o=l.nextNode()}}}else{let f=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:o,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[f].find=!0,this.#u[f]=d),this.#l[f].dir=x,this.#l[f].filtered=u||!o,f++}}return[this.#l,this.#u]}_getCombinedNodes(r,e,f){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:f,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,f){const{combo:n,index:a}=f,{combo:l,leaves:o}=r[a],u={combo:n,leaves:o},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===r.length-1){const[s]=(0,k.sortNodes)(d);i=s}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,f){const{index:n}=f,a=r[n],l=new Set([e]),o=this._getCombinedNodes(a,l,x);let u;if(o.size){if(n===0)u=e;else for(const d of o)if(this._matchNodePrev(r,d,{index:n-1}))return e}return u??null}find(r){(r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let o=0;o<n;o++){const{branch:u,collected:d,dir:i,find:s}=e[o],t=u.length;if(t&&s){const h=f[o],b=h.length,m=t-1;if(m===0)if((r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this.#e.nodeType===c.ELEMENT_NODE)for(let p=0;p<b;p++){const w=h[p];if(w!==this.#e&&this.#e.contains(w)&&(l.add(w),r!==c.TARGET_ALL))break}else if(r===c.TARGET_ALL)if(l.size){const p=[...l];l=new Set([...p,...h]),a=!0}else l=new Set(h);else{const[p]=h;l.add(p)}else if(r===c.TARGET_ALL)if(i===v){let{combo:p}=u[0];for(const w of h){let N=new Set([w]);for(let _=1;_<t;_++){const{combo:y,leaves:E}=u[_],A={combo:p,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(l.size){const L=[...l];l=new Set([...L,...N]),a=!0}else l=N;else p=y;else break}}}else for(const p of h){let w=new Set([p]);for(let N=m-1;N>=0;N--){const _=u[N];if(w=this._getCombinedNodes(_,w,i),w.size)N===0&&(l.add(p),t>1&&l.size>1&&(a=!0));else break}}else if(r===c.TARGET_FIRST&&i===v){const{combo:p}=u[0];let w;for(const N of h)if(w=this._matchNodeNext(u,new Set([N]),{combo:p,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:N}=u[0],[_]=h;let y=this._findNode(N,{node:_});for(;y;){if(w=this._matchNodeNext(u,new Set([y]),{combo:p,index:1}),w){l.add(w);break}y=this._findNode(N,{node:y})}}}else{let p;for(const w of h)if(p=this._matchNodePrev(u,w,{index:m-1}),p){l.add(w);break}if(!p&&!d&&r===c.TARGET_FIRST){const{leaves:w}=u[m],[N]=h;let _=this._findNode(w,{node:N});for(;_;){if(p=this._matchNodePrev(u,_,{index:m-1}),p){l.add(_);break}_=this._findNode(w,{node:_})}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,k.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,k.sortNodes)(l)))),this.#f&&(this.#d=new WeakMap),l}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -1,3 +0,3 @@ | ||
var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var _=(s,t)=>{for(var r in t)u(s,r,{get:t[r],enumerable:!0})},L=(s,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of w(t))!y.call(s,n)&&n!==r&&u(s,n,{get:()=>t[n],enumerable:!(o=T(t,n))||o.enumerable});return s};var b=s=>L(u({},"__esModule",{value:!0}),s);var F={};_(F,{generateCSS:()=>O.generate,parseAstName:()=>D,parseSelector:()=>g,preprocess:()=>m,sortAST:()=>C,unescapeSelector:()=>I,walkAST:()=>A});module.exports=b(F);var d=require("css-tree"),$=require("./utility.js"),e=require("./constant.js"),O=require("css-tree");const S=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/,x=/(:(is|where)\(\s*\))/,E=/^part|slotted$/,I=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let o=1;o<r;o++){let n=t[o];if(n===""&&o===r-1)n=e.U_FFFD;else{const c=/^([\da-f]{1,6}\s?)/i.exec(n);if(c){const[,f]=c;let a;try{const i=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),h=parseInt(f,e.HEX);h===0||h>=i&&h<=p?a=e.U_FFFD:a=String.fromCodePoint(h)}catch{a=e.U_FFFD}let l="";n.length>f.length&&(l=n.substring(f.length)),n=`${a}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[o]=n}s=t.join("")}return s},m=(...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 o=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 c=n.codePointAt(0);if(c===e.HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(c>e.BIT_FFFF){const f=`\\${c.toString(e.HEX)} `;n.length===e.DUO?n=f:n=`${f}${n.substring(e.DUO)}`}t=`${o}${n}`,r++}t=t.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=(0,$.getType)(t).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},g=s=>{if(s=m(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,d.toPlainObject)(r)}catch(r){const{message:o}=r;if(o==="Identifier is expected"&&S.test(s)){const[,n,c]=S.exec(s),f=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let a=n.replace(c,f);a===":lang()"&&(a=`:lang(${e.EMPTY})`),t=g(s.replace(n,a))}else if(/^(?:Identifier|Selector) is expected$/.test(o)&&x.test(s)){const[,n,c]=x.exec(s);t=g(s.replace(n,`:${c}(${e.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(o)&&!s.endsWith("]")){const n=s.lastIndexOf("["),c=s.substring(n);c.includes('"')?c.match(/"/g).length%2?t=g(`${s}"]`):t=g(`${s}]`):t=g(`${s}]`)}else if(o==='")" is expected'&&!s.endsWith(")"))t=g(`${s})`);else throw new DOMException(o,e.SYNTAX_ERR)}return t},A=(s={})=>{const t=new Set,r=new Map;return(0,d.walk)(s,{enter:n=>{switch(n.type){case e.SELECTOR:{t.add(n.children);break}case e.PS_CLASS_SELECTOR:{e.REG_LOGICAL.test(n.name)&&(r.set("hasNestedSelector",!0),r.set("hasLogicalPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0));break}case e.PS_ELEMENT_SELECTOR:{E.test(n.name)&&r.set("hasNestedSelector",!0);break}case e.NTH:{n.selector&&r.set("hasNestedSelector",!0);break}default:}}}),r.get("hasNestedSelector")&&(0,d.findAll)(s,(n,c,f)=>{if(f){if(n.type===e.PS_CLASS_SELECTOR&&e.REG_LOGICAL.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===e.PS_CLASS_SELECTOR&&e.REG_LOGICAL.test(i)});for(const{children:l}of a)for(const{children:i}of l)for(const{children:p}of i)t.has(p)&&t.delete(p)}else if(n.type===e.PS_ELEMENT_SELECTOR&&E.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===e.PS_ELEMENT_SELECTOR&&E.test(i)});for(const{children:l}of a)for(const{children:i}of l)t.has(i)&&t.delete(i)}else if(n.type===e.NTH&&n.selector){const a=f.filter(l=>{const{selector:i,type:p}=l;return p===e.NTH&&i});for(const{selector:l}of a){const{children:i}=l;for(const{children:p}of i)t.has(p)&&t.delete(p)}}}}),{branches:[...t],info:Object.fromEntries(r)}},C=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.PS_ELEMENT_SELECTOR,e.BIT_01],[e.ID_SELECTOR,e.BIT_02],[e.CLASS_SELECTOR,e.BIT_04],[e.TYPE_SELECTOR,e.BIT_08],[e.ATTR_SELECTOR,e.BIT_16],[e.PS_CLASS_SELECTOR,e.BIT_32]]);t.sort((o,n)=>{const{type:c}=o,{type:f}=n,a=r.get(c),l=r.get(f);let i;return a===l?i=0:a>l?i=1:i=-1,i})}return t},D=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}};0&&(module.exports={generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
var E=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var L=(s,e)=>{for(var r in e)E(s,r,{get:e[r],enumerable:!0})},b=(s,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!_.call(s,n)&&n!==r&&E(s,n,{get:()=>e[n],enumerable:!(o=w(e,n))||o.enumerable});return s};var I=s=>b(E({},"__esModule",{value:!0}),s);var P={};L(P,{generateCSS:()=>T.generate,parseAstName:()=>D,parseSelector:()=>g,preprocess:()=>O,sortAST:()=>F,unescapeSelector:()=>A,walkAST:()=>C});module.exports=I(P);var h=require("css-tree"),m=require("./utility.js"),t=require("./constant.js"),T=require("css-tree");const x=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/,$=/(:(is|where)\(\s*\))/,S=/^part|slotted$/,u="\uFFFD",A=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const e=s.split("\\"),r=e.length;for(let o=1;o<r;o++){let n=e[o];if(n===""&&o===r-1)n=u;else{const c=/^([\da-f]{1,6}\s?)/i.exec(n);if(c){const[,f]=c;let a;try{const i=parseInt("D800",t.HEX),p=parseInt("DFFF",t.HEX),d=parseInt(f,t.HEX);d===0||d>=i&&d<=p?a=u:a=String.fromCodePoint(d)}catch{a=u}let l="";n.length>f.length&&(l=n.substring(f.length)),n=`${a}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}e[o]=n}s=e.join("")}return s},O=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[e]=s;if(typeof e=="string"){let r=0;for(;r>=0&&(r=e.indexOf("#",r),!(r<0));){const o=e.substring(0,r+1);let n=e.substring(r+1);if(/^\d$/.test(n.substring(0,1)))throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR);const c=n.codePointAt(0);if(c===t.HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR)}else if(c>t.BIT_FFFF){const f=`\\${c.toString(t.HEX)} `;n.length===t.DUO?n=f:n=`${f}${n.substring(t.DUO)}`}e=`${o}${n}`,r++}e=e.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,u)}else if(e==null)e=(0,m.getType)(e).toLowerCase();else if(Array.isArray(e))e=e.join(",");else if(Object.prototype.hasOwnProperty.call(e,"toString"))e=e.toString();else throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR);return e},g=s=>{if(s=O(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,t.SYNTAX_ERR);let e;try{const r=(0,h.parse)(s,{context:"selectorList",parseCustomProperty:!0});e=(0,h.toPlainObject)(r)}catch(r){const{message:o}=r;if(o==="Identifier is expected"&&x.test(s)){const[,n,c]=x.exec(s),f=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let a=n.replace(c,f);a===":lang()"&&(a=`:lang(${t.EMPTY})`),e=g(s.replace(n,a))}else if(/^(?:Identifier|Selector) is expected$/.test(o)&&$.test(s)){const[,n,c]=$.exec(s);e=g(s.replace(n,`:${c}(${t.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(o)&&!s.endsWith("]")){const n=s.lastIndexOf("["),c=s.substring(n);c.includes('"')?c.match(/"/g).length%2?e=g(`${s}"]`):e=g(`${s}]`):e=g(`${s}]`)}else if(o==='")" is expected'&&!s.endsWith(")"))e=g(`${s})`);else throw new DOMException(o,t.SYNTAX_ERR)}return e},C=(s={})=>{const e=new Set,r=new Map;return(0,h.walk)(s,{enter:n=>{switch(n.type){case t.SELECTOR:{e.add(n.children);break}case t.PS_CLASS_SELECTOR:{t.REG_LOGICAL.test(n.name)&&(r.set("hasNestedSelector",!0),r.set("hasLogicalPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0));break}case t.PS_ELEMENT_SELECTOR:{S.test(n.name)&&r.set("hasNestedSelector",!0);break}case t.NTH:{n.selector&&(r.set("hasNestedSelector",!0),r.set("hasNthChildOfSelector",!0));break}default:}}}),r.get("hasNestedSelector")&&(0,h.findAll)(s,(n,c,f)=>{if(f){if(n.type===t.PS_CLASS_SELECTOR&&t.REG_LOGICAL.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===t.PS_CLASS_SELECTOR&&t.REG_LOGICAL.test(i)});for(const{children:l}of a)for(const{children:i}of l)for(const{children:p}of i)e.has(p)&&e.delete(p)}else if(n.type===t.PS_ELEMENT_SELECTOR&&S.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===t.PS_ELEMENT_SELECTOR&&S.test(i)});for(const{children:l}of a)for(const{children:i}of l)e.has(i)&&e.delete(i)}else if(n.type===t.NTH&&n.selector){const a=f.filter(l=>{const{selector:i,type:p}=l;return p===t.NTH&&i});for(const{selector:l}of a){const{children:i}=l;for(const{children:p}of i)e.has(p)&&e.delete(p)}}}}),{branches:[...e],info:Object.fromEntries(r)}},F=s=>{const e=[...s];if(e.length>1){const r=new Map([[t.PS_ELEMENT_SELECTOR,t.BIT_01],[t.ID_SELECTOR,t.BIT_02],[t.CLASS_SELECTOR,t.BIT_04],[t.TYPE_SELECTOR,t.BIT_08],[t.ATTR_SELECTOR,t.BIT_16],[t.PS_CLASS_SELECTOR,t.BIT_32]]);e.sort((o,n)=>{const{type:c}=o,{type:f}=n,a=r.get(c),l=r.get(f);let i;return a===l?i=0:a>l?i=1:i=-1,i})}return e},D=s=>{let e,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[e,r]=s.split("|"):(e="*",r=s);else throw new DOMException(`Invalid selector ${s}`,t.SYNTAX_ERR);return{prefix:e,localName:r}};0&&(module.exports={generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
//# sourceMappingURL=parser.js.map |
@@ -63,3 +63,3 @@ { | ||
}, | ||
"version": "5.3.0" | ||
"version": "5.3.1" | ||
} |
@@ -6,3 +6,2 @@ /** | ||
/* string */ | ||
export const AN_PLUS_B = 'AnPlusB'; | ||
export const ATTR_SELECTOR = 'AttributeSelector'; | ||
@@ -18,6 +17,3 @@ export const CLASS_SELECTOR = 'ClassSelector'; | ||
export const PS_ELEMENT_SELECTOR = 'PseudoElementSelector'; | ||
export const RAW = 'Raw'; | ||
export const SELECTOR = 'Selector'; | ||
export const SELECTOR_LIST = 'SelectorList'; | ||
export const STRING = 'String'; | ||
export const SYNTAX_ERR = 'SyntaxError'; | ||
@@ -29,3 +25,2 @@ export const TARGET_ALL = 'all'; | ||
export const TYPE_SELECTOR = 'TypeSelector'; | ||
export const U_FFFD = '\uFFFD'; | ||
@@ -32,0 +27,0 @@ /* numeric */ |
@@ -13,3 +13,3 @@ /** | ||
CLASS_SELECTOR, DUO, EMPTY, HEX, HYPHEN, ID_SELECTOR, NTH, PS_CLASS_SELECTOR, | ||
PS_ELEMENT_SELECTOR, REG_LOGICAL, SELECTOR, SYNTAX_ERR, TYPE_SELECTOR, U_FFFD | ||
PS_ELEMENT_SELECTOR, REG_LOGICAL, SELECTOR, SYNTAX_ERR, TYPE_SELECTOR | ||
} from './constant.js'; | ||
@@ -19,2 +19,3 @@ const REG_LANG_QUOTED = /(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/; | ||
const REG_SHADOW_PSEUDO = /^part|slotted$/; | ||
const U_FFFD = '\uFFFD'; | ||
@@ -216,2 +217,3 @@ /** | ||
info.set('hasNestedSelector', true); | ||
info.set('hasNthChildOfSelector', true); | ||
} | ||
@@ -218,0 +220,0 @@ break; |
@@ -1,2 +0,1 @@ | ||
export const AN_PLUS_B: "AnPlusB"; | ||
export const ATTR_SELECTOR: "AttributeSelector"; | ||
@@ -12,6 +11,3 @@ export const CLASS_SELECTOR: "ClassSelector"; | ||
export const PS_ELEMENT_SELECTOR: "PseudoElementSelector"; | ||
export const RAW: "Raw"; | ||
export const SELECTOR: "Selector"; | ||
export const SELECTOR_LIST: "SelectorList"; | ||
export const STRING: "String"; | ||
export const SYNTAX_ERR: "SyntaxError"; | ||
@@ -23,3 +19,2 @@ export const TARGET_ALL: "all"; | ||
export const TYPE_SELECTOR: "TypeSelector"; | ||
export const U_FFFD: "�"; | ||
export const BIT_01: 1; | ||
@@ -26,0 +21,0 @@ export const BIT_02: 2; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
439748
4964