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 6.0.5 to 6.1.0

2

dist/cjs/js/constant.js

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

var x=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var a=(o,t)=>{for(var c in t)x(o,c,{get:t[c],enumerable:!0})},F=(o,t,c,C)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of i(t))!M.call(o,s)&&s!==c&&x(o,s,{get:()=>t[s],enumerable:!(C=R(t,s))||C.enumerable});return o};var U=o=>F(x({},"__esModule",{value:!0}),o);var Ut={};a(Ut,{ALPHA_NUM:()=>I,ANB:()=>A,ATTR_SELECTOR:()=>d,BIT_01:()=>k,BIT_02:()=>g,BIT_04:()=>Z,BIT_08:()=>v,BIT_16:()=>q,BIT_32:()=>J,BIT_FFFF:()=>Q,CHILD_IDX:()=>L,CLASS_SELECTOR:()=>Y,COMBINATOR:()=>G,COMBO:()=>p,COMPLEX:()=>_,COMPLEX_L:()=>S,COMPOUND:()=>n,COMPOUND_A:()=>O,COMPOUND_B:()=>N,COMPOUND_I:()=>$t,DESCEND:()=>Pt,DIGIT:()=>E,DOCUMENT_FRAGMENT_NODE:()=>Et,DOCUMENT_NODE:()=>ct,DOCUMENT_POSITION_CONTAINED_BY:()=>pt,DOCUMENT_POSITION_CONTAINS:()=>Tt,DOCUMENT_POSITION_PRECEDING:()=>xt,DUO:()=>V,ELEMENT_NODE:()=>rt,EMPTY:()=>b,HEX:()=>tt,HYPHEN:()=>ot,IDENT:()=>B,ID_SELECTOR:()=>f,KEY_FORM_FOCUS:()=>Rt,KEY_INPUT_BUTTON:()=>it,KEY_INPUT_DATE:()=>D,KEY_INPUT_EDIT:()=>Mt,KEY_INPUT_LTR:()=>at,KEY_INPUT_TEXT:()=>l,KEY_LOGICAL:()=>Ft,LANG_PART:()=>It,LOGICAL_COMPLEX:()=>Dt,LOGICAL_COMPOUND:()=>lt,NESTED_LOGICAL_A:()=>P,NESTED_LOGICAL_B:()=>$,NOT_SUPPORTED_ERR:()=>m,NTH:()=>u,N_TH:()=>At,PSEUDO_CLASS:()=>Lt,PS_CLASS_SELECTOR:()=>H,PS_ELEMENT_SELECTOR:()=>h,SELECTOR:()=>z,SHOW_ALL:()=>_t,SHOW_DOCUMENT:()=>Ot,SHOW_DOCUMENT_FRAGMENT:()=>Nt,SHOW_ELEMENT:()=>St,SUB_TYPE:()=>r,SYNTAX_ERR:()=>K,TAG_TYPE:()=>e,TAG_TYPE_I:()=>T,TARGET_ALL:()=>X,TARGET_FIRST:()=>j,TARGET_LINEAL:()=>y,TARGET_SELF:()=>w,TEXT_NODE:()=>nt,TYPE_FROM:()=>et,TYPE_SELECTOR:()=>W,TYPE_TO:()=>st,WALKER_FILTER:()=>Ct});module.exports=U(Ut);const d="AttributeSelector",Y="ClassSelector",G="Combinator",b="__EMPTY__",B="Identifier",f="IdSelector",m="NotSupportedError",u="Nth",H="PseudoClassSelector",h="PseudoElementSelector",z="Selector",K="SyntaxError",X="all",j="first",y="lineal",w="self",W="TypeSelector",k=1,g=2,Z=4,v=8,q=16,J=32,Q=65535,V=2,tt=16,ot=45,et=8,st=-1,rt=1,nt=3,ct=9,Et=11,xt=2,Tt=8,pt=16,_t=4294967295,Ot=256,Nt=1024,St=1,Ct=1281,I="[A-Z\\d]+",L="(?:first|last|only)-(?:child|of-type)",E="(?:0|[1-9]\\d*)",It=`(?:-${I})*`,Lt=`(?:any-)?link|${L}|checked|empty|indeterminate|root|target|visited`,A=`[+-]?(?:${E}n?|n)|(?:[+-]?${E})?n\\s*[+-]\\s*${E}`,At=`nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${A})\\s*\\)`,r="\\[[^|\\]]+\\]|[#.:][\\w-]+",e="\\*|[A-Za-z][\\w-]*",T="\\*|[A-Z][\\w-]*",n=`(?:${e}|(?:${e})?(?:${r})+)`,p="\\s?[\\s>~+]\\s?",_=`${n}(?:${p}${n})*`,Pt="\\s?[\\s>]\\s?",P=`:is\\(\\s*${n}(?:\\s*,\\s*${n})*\\s*\\)`,$=`:is\\(\\s*${_}(?:\\s*,\\s*${_})*\\s*\\)`,O=`(?:${e}|(?:${e})?(?:${r}|${P})+)`,N=`(?:${e}|(?:${e})?(?:${r}|${$})+)`,$t=`(?:${T}|(?:${T})?(?:${r})+)`,S=`${N}(?:${p}${N})*`,Dt=`(?:is|not)\\(\\s*${S}(?:\\s*,\\s*${S})*\\s*\\)`,lt=`(?:is|not)\\(\\s*${O}(?:\\s*,\\s*${O})*\\s*\\)`,Rt=Object.freeze(["button","input","select","textarea"]),it=Object.freeze(["button","reset","submit"]),D=Object.freeze(["date","datetime-local","month","time","week"]),l=Object.freeze(["email","password","search","tel","text","url"]),Mt=Object.freeze([...D,...l,"number"]),at=Object.freeze(["checkbox","color","date","image","number","range","radio","time"]),Ft=Object.freeze(["has","is","not","where"]);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_FORM_FOCUS,KEY_INPUT_BUTTON,KEY_INPUT_DATE,KEY_INPUT_EDIT,KEY_INPUT_LTR,KEY_INPUT_TEXT,KEY_LOGICAL,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,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});
var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var F=(o,t)=>{for(var n in t)p(o,n,{get:t[n],enumerable:!0})},M=(o,t,n,L)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of a(t))!i.call(o,s)&&s!==n&&p(o,s,{get:()=>t[s],enumerable:!(L=R(t,s))||L.enumerable});return o};var U=o=>M(p({},"__esModule",{value:!0}),o);var bt={};F(bt,{ALPHA_NUM:()=>I,ANB:()=>A,ATTR_SELECTOR:()=>d,BIT_01:()=>g,BIT_02:()=>Z,BIT_04:()=>v,BIT_08:()=>q,BIT_16:()=>J,BIT_32:()=>Q,BIT_FFFF:()=>V,CHILD_IDX:()=>C,CLASS_SELECTOR:()=>b,COMBINATOR:()=>G,COMBO:()=>T,COMPLEX:()=>_,COMPLEX_L:()=>S,COMPOUND:()=>c,COMPOUND_A:()=>O,COMPOUND_B:()=>N,COMPOUND_I:()=>Pt,DESCEND:()=>Dt,DIGIT:()=>E,DOCUMENT_FRAGMENT_NODE:()=>pt,DOCUMENT_NODE:()=>Et,DOCUMENT_POSITION_CONTAINED_BY:()=>_t,DOCUMENT_POSITION_CONTAINS:()=>Tt,DOCUMENT_POSITION_PRECEDING:()=>xt,DUO:()=>tt,ELEMENT_NODE:()=>ct,HEX:()=>ot,HYPHEN:()=>et,IDENT:()=>Y,ID_SELECTOR:()=>m,KEY_FORM_FOCUS:()=>at,KEY_INPUT_BUTTON:()=>it,KEY_INPUT_DATE:()=>P,KEY_INPUT_EDIT:()=>Ft,KEY_INPUT_LTR:()=>Mt,KEY_INPUT_TEXT:()=>$,KEY_LOGICAL:()=>Ut,KEY_MODIFIER:()=>dt,LANG_PART:()=>Ct,LOGICAL_COMPLEX:()=>$t,LOGICAL_COMPOUND:()=>Rt,NESTED_LOGICAL_A:()=>l,NESTED_LOGICAL_B:()=>D,NOT_SUPPORTED_ERR:()=>f,NTH:()=>B,N_TH:()=>lt,OPERATOR:()=>u,PSEUDO_CLASS:()=>At,PS_CLASS_SELECTOR:()=>h,PS_ELEMENT_SELECTOR:()=>H,SELECTOR:()=>y,SHOW_ALL:()=>Ot,SHOW_DOCUMENT:()=>Nt,SHOW_DOCUMENT_FRAGMENT:()=>St,SHOW_ELEMENT:()=>Lt,STRING:()=>k,SUB_TYPE:()=>r,SYNTAX_ERR:()=>z,TAG_TYPE:()=>e,TAG_TYPE_I:()=>x,TARGET_ALL:()=>K,TARGET_FIRST:()=>j,TARGET_LINEAL:()=>X,TARGET_SELF:()=>w,TEXT_NODE:()=>nt,TYPE_FROM:()=>st,TYPE_SELECTOR:()=>W,TYPE_TO:()=>rt,WALKER_FILTER:()=>It});module.exports=U(bt);const d="AttributeSelector",b="ClassSelector",G="Combinator",Y="Identifier",m="IdSelector",f="NotSupportedError",B="Nth",u="Operator",h="PseudoClassSelector",H="PseudoElementSelector",y="Selector",k="String",z="SyntaxError",K="all",j="first",X="lineal",w="self",W="TypeSelector",g=1,Z=2,v=4,q=8,J=16,Q=32,V=65535,tt=2,ot=16,et=45,st=8,rt=-1,ct=1,nt=3,Et=9,pt=11,xt=2,Tt=8,_t=16,Ot=4294967295,Nt=256,St=1024,Lt=1,It=1281,I="[A-Z\\d]+",C="(?:first|last|only)-(?:child|of-type)",E="(?:0|[1-9]\\d*)",Ct=`(?:-${I})*`,At=`(?:any-)?link|${C}|checked|empty|indeterminate|root|target|visited`,A=`[+-]?(?:${E}n?|n)|(?:[+-]?${E})?n\\s*[+-]\\s*${E}`,lt=`nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${A})\\s*\\)`,r="\\[[^|\\]]+\\]|[#.:][\\w-]+",e="\\*|[A-Za-z][\\w-]*",x="\\*|[A-Z][\\w-]*",c=`(?:${e}|(?:${e})?(?:${r})+)`,T="\\s?[\\s>~+]\\s?",_=`${c}(?:${T}${c})*`,Dt="\\s?[\\s>]\\s?",l=`:is\\(\\s*${c}(?:\\s*,\\s*${c})*\\s*\\)`,D=`:is\\(\\s*${_}(?:\\s*,\\s*${_})*\\s*\\)`,O=`(?:${e}|(?:${e})?(?:${r}|${l})+)`,N=`(?:${e}|(?:${e})?(?:${r}|${D})+)`,Pt=`(?:${x}|(?:${x})?(?:${r})+)`,S=`${N}(?:${T}${N})*`,$t=`(?:is|not)\\(\\s*${S}(?:\\s*,\\s*${S})*\\s*\\)`,Rt=`(?:is|not)\\(\\s*${O}(?:\\s*,\\s*${O})*\\s*\\)`,at=Object.freeze(["button","input","select","textarea"]),it=Object.freeze(["button","reset","submit"]),P=Object.freeze(["date","datetime-local","month","time","week"]),$=Object.freeze(["email","password","search","tel","text","url"]),Ft=Object.freeze([...P,...$,"number"]),Mt=Object.freeze(["checkbox","color","date","image","number","range","radio","time"]),Ut=Object.freeze(["has","is","not","where"]),dt=Object.freeze(["Alt","AltGraph","CapsLock","Control","Fn","FnLock","Hyper","Meta","NumLock","ScrollLock","Shift","Super","Symbol","SymbolLock"]);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,HEX,HYPHEN,IDENT,ID_SELECTOR,KEY_FORM_FOCUS,KEY_INPUT_BUTTON,KEY_INPUT_DATE,KEY_INPUT_EDIT,KEY_INPUT_LTR,KEY_INPUT_TEXT,KEY_LOGICAL,KEY_MODIFIER,LANG_PART,LOGICAL_COMPLEX,LOGICAL_COMPOUND,NESTED_LOGICAL_A,NESTED_LOGICAL_B,NOT_SUPPORTED_ERR,NTH,N_TH,OPERATOR,PSEUDO_CLASS,PS_CLASS_SELECTOR,PS_ELEMENT_SELECTOR,SELECTOR,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,WALKER_FILTER});
//# sourceMappingURL=constant.js.map

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

var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var F=(x,c)=>{for(var e in c)C(x,e,{get:c[e],enumerable:!0})},W=(x,c,e,o)=>{if(c&&typeof c=="object"||typeof c=="function")for(let n of D(c))!U.call(x,n)&&n!==e&&C(x,n,{get:()=>c[n],enumerable:!(o=P(c,n))||o.enumerable});return x};var z=x=>W(C({},"__esModule",{value:!0}),x);var H={};F(H,{Finder:()=>$});module.exports=z(H);var O=require("./matcher.js"),y=require("./parser.js"),N=require("./utility.js"),r=require("./constant.js");const v="next",E="prev";class ${#a;#r;#N;#t;#h;#c;#m;#o;#p;#n;#d;#e;#u;#g;#w;#_;#s;#b;#y;#f;#k;#i;#l;constructor(c){this.#l=c,this.#d=new O.Matcher,this.#r=new WeakMap,this.#h=new WeakMap,this.#p=new WeakMap,this.#_=new WeakMap,this.#c=null,this.#m=null,this.#n=null,this._registerEventListeners()}onError(c,e){if(!(e?.noexcept??this.#g))if(c instanceof DOMException||c instanceof this.#l.DOMException)if(c.name===r.NOT_SUPPORTED_ERR)this.#i&&console.warn(c.message);else throw new this.#l.DOMException(c.message,c.name);else throw c.name in this.#l?new this.#l[c.name](c.message):c}setup(c,e,o={}){const{noexcept:n,warn:a}=o;return this.#g=!!n,this.#i=!!a,this.#e=e,[this.#t,this.#s,this.#f]=(0,N.resolveContent)(e),this.#b=(0,N.isInShadowTree)(e),[this.#a,this.#u]=this._correspond(c),this.#p=new WeakMap,this.#k=new WeakMap,this.#y=null,this}_registerEventListeners(){const c={capture:!0,passive:!0},e=[],o=["click","mouseover","mousedown","mouseup","mouseout"];for(const l of o)e.push(this.#l.addEventListener(l,f=>{this.#c=f},c));const n=["keydown","keyup"];for(const l of n)e.push(this.#l.addEventListener(l,f=>{const{key:u}=f;["Alt","AltGraph","CapsLock","Control","Dead","Fn","FnLock","Hyper","Meta","NumLock","ScrollLock","Shift","Super","Symbol","SymbolLock","Unidentified"].includes(u)||(this.#c=f)},c));const a=["focus","focusin"];for(const l of a)e.push(this.#l.addEventListener(l,f=>{this.#m=f},c));return e}_correspond(c){const e=[];this.#N=!1,this.#o=!1;let o;if(this.#h.has(this.#t)){const n=this.#h.get(this.#t);if(n&&n.has(`${c}`)){const a=n.get(`${c}`);o=a.ast,this.#N=a.descendant,this.#o=a.invalidate}}if(o){const n=o.length;for(let a=0;a<n;a++)o[a].collected=!1,o[a].dir=null,o[a].filtered=!1,o[a].find=!1,e[a]=[]}else{let n;try{n=(0,y.parseSelector)(c)}catch(m){this.onError(m)}const{branches:a,info:l}=(0,y.walkAST)(n),{hasHasPseudoFunc:f,hasLogicalPseudoFunc:u,hasNthChildOfSelector:d}=l;let i=f||!!(u&&d),t=!1,s=0;o=[];for(const[...m]of a){const b=[];let p=m.shift();if(p&&p.type!==r.COMBINATOR){const w=new Set;for(;p;){let k=p.name;if(p.type===r.COMBINATOR){const[_]=m;if(_.type===r.COMBINATOR)throw new DOMException(`Invalid selector ${c}`,r.SYNTAX_ERR);k==="+"||k==="~"?i=!0:t=!0,b.push({combo:p,leaves:(0,y.sortAST)(w)}),w.clear()}else p&&(k&&typeof k=="string"&&(k=(0,y.unescapeSelector)(k),typeof k=="string"&&k!==p.name&&(p.name=k),/[|:]/.test(k)&&(p.namespace=!0)),w.add(p));if(m.length)p=m.shift();else{b.push({combo:null,leaves:(0,y.sortAST)(w)}),w.clear();break}}}o.push({branch:b,collected:!1,dir:null,filtered:!1,find:!1}),e[s]=[],s++}let h;this.#h.has(this.#t)?h=this.#h.get(this.#t):h=new Map,h.set(`${c}`,{ast:o,descendant:t,invalidate:i}),this.#h.set(this.#t,h),this.#N=t,this.#o=i}return[o,e]}_createTreeWalker(c){let e;return this.#k.has(c)?e=this.#k.get(c):(e=this.#t.createTreeWalker(c,r.WALKER_FILTER),this.#k.set(c,e)),e}_prepareQuerySelectorWalker(){return this.#w=this._createTreeWalker(this.#e),this.#w}_collectNthChild(c,e,o){const{a:n,b:a,reverse:l,selector:f}=c,{parentNode:u}=e,d=new Set;let i;if(f){if(this.#r.has(f))i=this.#r.get(f);else{const{branches:s}=(0,y.walkAST)(f);i=s,this.#o||this.#r.set(f,i)}const{branches:t}=(0,y.walkAST)(f);i=t}if(u){const t=this.#f;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let h=0;for(;s;)h++,s=t.nextSibling();const m=new Set;if(i)for(s=(0,N.traverseNode)(u,t),s=t.firstChild();s;){if((0,N.isVisible)(s)){let b;for(const p of i)if(b=this._matchLeaves(p,s,o),!b)break;b&&m.add(s)}s=t.nextSibling()}if(n===0){if(a>0&&a<=h){if(m.size){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(m.has(s)){if(b===a-1){d.add(s);break}b++}l?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(b===a-1){d.add(s);break}l?s=t.previousSibling():s=t.nextSibling(),b++}}}}else{let b=a-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<h){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let p=0,w=n>0?0:a-1;for(;s&&(s&&b>=0&&b<h);)m.size?m.has(s)&&(w===b&&(d.add(s),b+=n),n>0?w++:w--):p===b&&(f||d.add(s),b+=n),l?s=t.previousSibling():s=t.nextSibling(),p++}}if(l&&d.size>1){const b=[...d];return new Set(b.reverse())}}else if(e===this.#s&&n+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,o),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(c,e){const{a:o,b:n,reverse:a}=c,{localName:l,namespaceURI:f,parentNode:u,prefix:d}=e,i=new Set;if(u){const t=this.#f;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let h=0;for(;s;)h++,s=t.nextSibling();if(o===0){if(n>0&&n<=h){s=(0,N.traverseNode)(u,t),a?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){const{localName:b,namespaceURI:p,prefix:w}=s;if(b===l&&w===d&&p===f){if(m===n-1){i.add(s);break}m++}a?s=t.previousSibling():s=t.nextSibling()}}}else{let m=n-1;if(o>0)for(;m<0;)m+=o;if(m>=0&&m<h){s=(0,N.traverseNode)(u,t),a?s=t.lastChild():s=t.firstChild();let b=o>0?0:n-1;for(;s;){const{localName:p,namespaceURI:w,prefix:k}=s;if(p===l&&k===d&&w===f){if(b===m&&(i.add(s),m+=o),m<0||m>=h)break;o>0?b++:b--}a?s=t.previousSibling():s=t.nextSibling()}}}if(a&&i.size>1){const m=[...i];return new Set(m.reverse())}}else e===this.#s&&o+n===1&&i.add(e);return i}_matchAnPlusB(c,e,o,n){const{nth:{a,b:l,name:f},selector:u}=c,d=new Map;if(f?(f==="even"?(d.set("a",2),d.set("b",0)):f==="odd"&&(d.set("a",2),d.set("b",1)),o.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),o.indexOf("last")>-1&&d.set("reverse",!0)),o==="nth-child"||o==="nth-last-child"){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(o==="nth-of-type"||o==="nth-last-of-type"){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(c,e,o){let n;if(Array.isArray(c)&&c.length){const a=[...c],[l]=a,{type:f}=l;let u;f===r.COMBINATOR?u=a.shift():u={name:" ",type:r.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:h}=s;if(h===r.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};o.dir=v;const t=this._matchCombinator(i,e,o);if(t.size)if(a.length){for(const s of t)if(n=this._matchHasPseudoFunc(a,s,o),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(c,e,o){const{astName:n,branches:a,twigBranches:l}=c,{isShadowRoot:f}=o;let u;if(n==="has"){let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,o),d)break;if(d)if(f){if(this.#y)return e}else return e}else{if(f){for(const t of a)if(t.length>1)return null}o.forgive=n==="is"||n==="where";const d=l.length;let i;for(let t=0;t<d;t++){const s=l[t],h=s.length-1,{leaves:m}=s[h];if(i=this._matchLeaves(m,e,o),i&&h>0){let b=new Set([e]);for(let p=h-1;p>=0;p--){const w=s[p],k=[];o.dir=E;for(const _ of b){const g=this._matchCombinator(w,_,o);g.size&&k.push(...g)}if(k.length)p===0?i=!0:b=new Set(k);else{i=!1;break}}}if(i)break}if(n==="not"){if(!i)return e}else if(i)return e}return u??null}_matchPseudoClassSelector(c,e,o){const{children:n,name:a}=c,{localName:l,parentNode:f}=e,{forgive:u,warn:d=this.#i}=o,i=new Set;if(r.KEY_LOGICAL.includes(a)){let t;if(this.#r.has(c))t=this.#r.get(c);else{const{branches:h}=(0,y.walkAST)(c);if(a==="has"){for(const m of n){const b=(0,y.findAST)(m,p=>r.KEY_LOGICAL.includes(p.name)&&(0,y.findAST)(p,w=>w.name==="has")?p:null);if(b){const p=b.name;if(p==="is"||p==="where")return i;{const w=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${w}`,r.SYNTAX_ERR)}}}t={astName:a,branches:h}}else{const m=[];for(const[...b]of h){const p=[],w=new Set;let k=b.shift();for(;k;)if(k.type===r.COMBINATOR?(p.push({combo:k,leaves:[...w]}),w.clear()):k&&w.add(k),b.length)k=b.shift();else{p.push({combo:null,leaves:[...w]}),w.clear();break}m.push(p)}t={astName:a,branches:h,twigBranches:m},this.#o||this.#r.set(c,t)}}const s=this._matchLogicalPseudoFunc(t,e,o);s&&i.add(s)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=n;return this._matchAnPlusB(t,e,a,o)}else switch(a){case"dir":case"lang":{const t=this.#d.matchSelector(c,e,o,!0);t&&i.add(t);break}case"state":{if((0,N.isCustomElement)(e)){const[{value:t}]=n;if(t)if(e[t])i.add(e);else for(const s in e){const h=e[s];if(h instanceof this.#l.ElementInternals){h?.states?.has(t)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,r.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,r.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,r.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{(l==="a"||l==="area")&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if((l==="a"||l==="area")&&e.hasAttribute("href")){const{href:t,origin:s,pathname:h}=new URL(this.#t.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#c??{};/^(?:click|mouse(?:down|over|up))$/.test(s)&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:h}=this.#c??{};h==="mousedown"&&t&r.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#t.URL);e.id&&t===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#t.URL);if(t){const s=t.replace(/^#/,"");let h=this.#t.getElementById(s);for(;h;){if(h===e){i.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===r.ELEMENT_NODE?!this.#b&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&(0,N.isFocusableArea)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&(0,N.isFocusableArea)(e)){let t;if((0,N.isFocusVisible)(e))t=!0;else if(this.#m){const{relatedTarget:s,target:h}=this.#m;if(h===e)if((0,N.isFocusVisible)(s))t=!0;else if(this.#c){const{key:m,target:b,type:p}=this.#c;b===s?(this.#n===null||h===this.#n)&&(t=!0):m==="Tab"?(p==="keydown"&&b!==e||p==="keyup"&&b===e)&&(b===h?(this.#n===null||b===this.#n&&s===null)&&(t=!0):t=!0):m&&(p==="keydown"||p==="keyup")&&b===e&&(t=!0)}else(s===null||s===this.#n)&&(t=!0)}t?(this.#n=e,i.add(e)):this.#n===e&&(this.#n=null)}break}case"focus-within":{let t,s=this.#t.activeElement;if((0,N.isFocusableArea)(s))for(;s;){if(s===e){t=!0;break}s=s.parentNode}t&&i.add(e);break}case"open":case"closed":{(l==="details"||l==="dialog")&&(e.hasAttribute("open")?a==="open"&&i.add(e):a==="closed"&&i.add(e));break}case"disabled":case"enabled":{if([...r.KEY_FORM_FOCUS,"fieldset","optgroup","option"].includes(l)||(0,N.isCustomElement)(e,{formAssociated:!0})){let s;if(e.disabled||e.hasAttribute("disabled"))s=!0;else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&(s=!0);else if(e.localName!=="optgroup"){let h=f;for(;h;)if(h.localName==="fieldset"&&(h.disabled||h.hasAttribute("disabled"))){const m=this.#f;let b=(0,N.traverseNode)(h,m);for(b=m.firstChild();b&&b.localName!=="legend";)b=m.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(h.localName==="form")break;if(h.parentNode?.nodeType===r.ELEMENT_NODE){if(h.parentNode.localName==="form")break;h=h.parentNode}else break}}s?a==="disabled"&&i.add(e):a==="enabled"&&i.add(e)}break}case"read-only":case"read-write":{let t,s;switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0;break}case"input":{(!e.type||r.KEY_INPUT_EDIT.includes(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0);break}default:(0,N.isContentEditable)(e)?s=!0:t=!0}t?a==="read-only"&&i.add(e):a==="read-write"&&s&&i.add(e);break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;l==="textarea"?s=e:l==="input"&&(e.hasAttribute("type")?[...r.KEY_INPUT_TEXT,"number"].includes(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{const t=e.getAttribute("type");(e.checked&&l==="input"&&(t==="checkbox"||t==="radio")||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#t.documentElement);const h=s.getElementsByTagName("input"),m=h.length;let b;for(let p=0;p<m;p++){const w=h[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":{const t=["checkbox","radio"],s=["button","reset"],h=["image","submit"],m=e.getAttribute("type");if(l==="button"&&!(e.hasAttribute("type")&&s.includes(m))||l==="input"&&e.hasAttribute("type")&&h.includes(m)){let b=e.parentNode;for(;b&&b.localName!=="form";)b=b.parentNode;if(b){const p=this.#f;let w=(0,N.traverseNode)(b,p);for(w=p.firstChild();w&&b.contains(w);){const k=w.localName,_=w.getAttribute("type");let g;if(k==="button"?g=!(w.hasAttribute("type")&&s.includes(_)):k==="input"&&(g=w.hasAttribute("type")&&h.includes(_)),g){w===e&&i.add(e);break}w=p.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&t.includes(m)&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":case"invalid":{const t=[...r.KEY_FORM_FOCUS,"form"];if(t.includes(l)){let s;e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&(s=!0):s=!0),s?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}else if(l==="fieldset"){const s=this.#f;let h=(0,N.traverseNode)(e,s);h=s.firstChild();let m;if(!h)m=!0;else for(;h&&e.contains(h)&&!(t.includes(h.localName)&&(h.checkValidity()?h.maxLength>=0?m=h.maxLength>=h.value.length:m=!0:m=!1,!m));)h=s.nextNode();m?a==="valid"&&i.add(e):a==="invalid"&&i.add(e)}break}case"in-range":case"out-of-range":{const t=[...r.KEY_INPUT_DATE,"number","range"],s=e.getAttribute("type");if(l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&t.includes(s)){const h=e.validity.rangeUnderflow||e.validity.rangeOverflow;(a==="out-of-range"&&h||a==="in-range"&&!h&&(e.hasAttribute("min")||e.hasAttribute("max")||s==="range"))&&i.add(e)}break}case"required":case"optional":{let t;if(l==="select"||l==="textarea")t=e;else if(l==="input")if(e.hasAttribute("type")){const s=[...r.KEY_INPUT_EDIT,"checkbox","file","radio"],h=e.getAttribute("type");s.includes(h)&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required")?a==="required"&&i.add(e):a==="optional"&&i.add(e));break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#t.createTreeWalker(e,r.SHOW_ALL);let s=t.firstChild(),h;for(;s&&(h=s.nodeType!==r.ELEMENT_NODE&&s.nodeType!==r.TEXT_NODE,!!h);)s=t.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,N.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,N.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}`,r.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}`,r.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,r.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,r.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(c,e){const{children:o,name:n}=c;let a;if(Array.isArray(o)){const{branches:l}=(0,y.walkAST)(o[0]),[f]=l,[...u]=f,{host:d}=e;if(n==="host"){let i;for(const t of u){const{type:s}=t;if(s===r.COMBINATOR){const h=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${h}`,r.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}if(i)return e}else if(n==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:h}=s;if(h===r.COMBINATOR){const m=(0,y.generateCSS)(c);throw new DOMException(`Invalid selector ${m}`,r.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}if(t)return e}}else{if(n==="host")return e;throw new DOMException(`Invalid selector :${n}`,r.SYNTAX_ERR)}return a??null}_matchSelector(c,e,o={}){const{type:n}=c,a=new Set;if(c.name===r.EMPTY)return a;const l=(0,y.unescapeSelector)(c.name);if(typeof l=="string"&&l!==c.name&&(c.name=l),e.nodeType===r.ELEMENT_NODE)switch(n){case r.PS_ELEMENT_SELECTOR:{this.#d.matchPseudoElementSelector(l,o);break}case r.ID_SELECTOR:{e.id===l&&a.add(e);break}case r.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case r.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(c,e,o);default:{const f=this.#d.matchSelector(c,e,o,!0);f&&a.add(f)}}else if(this.#b&&n===r.PS_CLASS_SELECTOR&&e.nodeType===r.DOCUMENT_FRAGMENT_NODE){if(r.KEY_LOGICAL.includes(l))return o.isShadowRoot=!0,this._matchPseudoClassSelector(c,e,o);if(l==="host"||l==="host-context"){const f=this._matchShadowHostPseudoClass(c,e,o);f&&(this.#y=!0,a.add(f))}}return a}_matchLeaves(c,e,o){let n,a;if(this.#o?a=this.#p.get(c):a=this.#_.get(c),a&&a.has(e)){const{matched:l}=a.get(e);n=l}if(typeof n!="boolean"){let l=!0;const f=[...r.KEY_FORM_FOCUS,"fieldset","form"],u=["any-link","defined","dir","link"];e.nodeType===r.ELEMENT_NODE&&f.includes(e.localName)&&(l=!1);for(const d of c){switch(d.type){case r.ATTR_SELECTOR:case r.ID_SELECTOR:{l=!1;break}case r.PS_CLASS_SELECTOR:{u.includes(d.name)&&(l=!1);break}default:}if(n=this._matchSelector(d,e,o).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#o?this.#p.set(c,a):this.#_.set(c,a))}return!!n}_matchHTMLCollection(c,e){const{compound:o,filterLeaves:n}=e,a=new Set,l=c.length;if(l)if(o)for(let f=0;f<l;f++){const u=c[f];this._matchLeaves(n,u,e)&&a.add(u)}else{const f=[].slice.call(c);return new Set(f)}return a}_findDescendantNodes(c,e,o){const[n,...a]=c,l=a.length>0,{type:f}=n,u=(0,y.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(f){case r.PS_ELEMENT_SELECTOR:{this.#d.matchPseudoElementSelector(u,o);break}case r.ID_SELECTOR:{if(this.#s.nodeType===r.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(u);t&&t!==e&&e.contains(t)&&(l?this._matchLeaves(a,t,o)&&d.add(t):d.add(t))}break}case r.CLASS_SELECTOR:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:l,filterLeaves:a});break}case r.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(c,e,o){const{combo:n,leaves:a}=c,{name:l}=n,{parentNode:f}=e,{dir:u}=o,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,o)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,N.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let h=(0,N.traverseNode)(e,s);for(h=s.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,o)&&d.add(h),h=s.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,o)&&d.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,o)&&d.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(a,f,o)&&d.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(a,t,o)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(c,e){const o=this.#w;let n=(0,N.traverseNode)(e,o),a;if(n)for((n.nodeType!==r.ELEMENT_NODE||n===e&&n!==this.#s)&&(n=o.nextNode());n;){if(this._matchLeaves(c,n,{warn:this.#i})){a=n;break}n=o.nextNode()}return a??null}_matchSelf(c){const e=[],o=this._matchLeaves(c,this.#e,{warn:this.#i});let n=!1;return o&&(e.push(this.#e),n=!0),[e,n]}_findLineal(c,e){const{complex:o}=e,n=[];let a=this._matchLeaves(c,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||o){let f=this.#e.parentNode;for(;f&&(a=this._matchLeaves(c,f,{warn:this.#i}),a&&(n.push(f),l=!0),f.parentNode);)f=f.parentNode}return[n,l]}_findFirst(c){const e=[],o=this._findNode(c,this.#e);let n=!1;return o&&(e.push(o),n=!0),[e,n]}_findFromHTMLCollection(c,e){const{complex:o,compound:n,filterLeaves:a,targetType:l}=e;let f=[],u=!1,d=!1;const i=c.length;if(i)if(this.#e.nodeType===r.ELEMENT_NODE)for(let t=0;t<i;t++){const s=c[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(n){if(this._matchLeaves(a,s,{warn:this.#i})&&(f.push(s),u=!0,l===r.TARGET_FIRST))break}else if(f.push(s),u=!0,l===r.TARGET_FIRST)break}}else if(o)if(n)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(f.push(s),u=!0,l===r.TARGET_FIRST))break}else f=[].slice.call(c),u=!0,d=!0;else if(n)for(let t=0;t<i;t++){const s=c[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(f.push(s),u=!0,l===r.TARGET_FIRST))break}else f=[].slice.call(c),u=!0,d=!0;return[f,u,d]}_findEntryNodes(c,e,o){const{leaves:n}=c,[a,...l]=n,f=l.length>0,{name:u,type:d}=a;let i=[],t=!1,s=!1,h=!1;switch(d){case r.PS_ELEMENT_SELECTOR:{this.#d.matchPseudoElementSelector(u,{warn:this.#i});break}case r.ID_SELECTOR:{if(e===r.TARGET_SELF)[i,s]=this._matchSelf(n);else if(e===r.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(e===r.TARGET_FIRST&&this.#s.nodeType!==r.ELEMENT_NODE){const m=this.#s.getElementById(u);m&&(f?this._matchLeaves(l,m,{warn:this.#i})&&(i.push(m),s=!0):(i.push(m),s=!0))}else e===r.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}case r.CLASS_SELECTOR:{if(e===r.TARGET_SELF)[i,s]=this._matchSelf(n);else if(e===r.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(this.#s.nodeType===r.DOCUMENT_NODE){const m=this.#s.getElementsByClassName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:o,compound:f,filterLeaves:l,targetType:e}))}else e===r.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}case r.TYPE_SELECTOR:{if(e===r.TARGET_SELF)[i,s]=this._matchSelf(n);else if(e===r.TARGET_LINEAL)[i,s]=this._findLineal(n,{complex:o});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===r.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#s.getElementsByTagName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:o,compound:f,filterLeaves:l,targetType:e}))}else e===r.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0;break}default:if(e!==r.TARGET_LINEAL&&(u==="host"||u==="host-context")){if(this.#b&&this.#e.nodeType===r.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(a,this.#e);m&&(i.push(m),s=!0)}}else e===r.TARGET_SELF?[i,s]=this._matchSelf(n):e===r.TARGET_LINEAL?[i,s]=this._findLineal(n,{complex:o}):e===r.TARGET_FIRST?[i,s]=this._findFirst(n):h=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:h}}_collectNodes(c){const e=this.#a.values();if(c===r.TARGET_ALL||c===r.TARGET_FIRST){const o=new Set;let n=0;for(const{branch:a}of e){const l=a.length,f=l>1,u=a[0];let d,i;if(f){const{combo:p,leaves:[{name:w,type:k}]}=u,_=a[l-1],{leaves:[{name:g,type:L}]}=_;if(L===r.PS_ELEMENT_SELECTOR||L===r.ID_SELECTOR)d=E,i=_;else if(k===r.PS_ELEMENT_SELECTOR||k===r.ID_SELECTOR)d=v,i=u;else if(c===r.TARGET_ALL)if(w==="*"&&k===r.TYPE_SELECTOR)d=E,i=_;else if(g==="*"&&L===r.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:S}=p;S==="+"||S==="~"?(d=E,i=_):(d=v,i=u)}else d=v,i=u;else if(w==="*"&&k===r.TYPE_SELECTOR)d=E,i=_;else if(g==="*"&&L===r.TYPE_SELECTOR)d=v,i=u;else{let S;for(const{combo:T,leaves:[M]}of a){const{name:R,type:I}=M;if(I===r.PS_CLASS_SELECTOR&&R==="dir"){S=!1;break}if(!S&&T){const{name:A}=T;(A==="+"||A==="~")&&(S=!0)}}S?(d=v,i=u):(d=E,i=_)}}else d=E,i=u;const{collected:t,compound:s,filtered:h,nodes:m,pending:b}=this._findEntryNodes(i,c,f);m.length?(this.#a[n].find=!0,this.#u[n]=m):b&&o.add(new Map([["index",n],["twig",i]])),this.#a[n].collected=t,this.#a[n].dir=d,this.#a[n].filtered=h||!s,n++}if(o.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===r.ELEMENT_NODE?(a=this.#e,l=this.#w):(a=this.#s,l=this.#f);let f=(0,N.traverseNode)(a,l);for(;f;){let u=!1;if(this.#e.nodeType===r.ELEMENT_NODE?f===this.#e?u=!0:u=this.#e.contains(f):u=!0,u)for(const d of o){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=d.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#u[s].push(f)}}f!==l.currentNode&&(f=(0,N.traverseNode)(f,l)),f=l.nextNode()}}}else{let o=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:f,filtered:u,nodes:d}=this._findEntryNodes(a,c,l);d.length&&(this.#a[o].find=!0,this.#u[o]=d),this.#a[o].dir=E,this.#a[o].filtered=u||!f,o++}}return[this.#a,this.#u]}_getCombinedNodes(c,e,o){const n=[];for(const a of e){const l=this._matchCombinator(c,a,{dir:o,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(c,e,o){const{combo:n,index:a}=o,{combo:l,leaves:f}=c[a],u={combo:n,leaves:f},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===c.length-1){const[t]=(0,N.sortNodes)(d);i=t}else i=this._matchNodeNext(c,d,{combo:l,index:a+1});return i??null}_matchNodePrev(c,e,o){const{index:n}=o,a=c[n],l=new Set([e]),f=this._getCombinedNodes(a,l,E);let u;if(f.size){if(n===0)u=e;else for(const d of f)if(this._matchNodePrev(c,d,{index:n-1}))return e}return u??null}find(c){(c===r.TARGET_ALL||c===r.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],o]=this._collectNodes(c),n=e.length;let a,l=new Set;for(let f=0;f<n;f++){const{branch:u,collected:d,dir:i,find:t}=e[f],s=u.length;if(s&&t){const h=o[f],m=h.length,b=s-1;if(b===0)if((c===r.TARGET_ALL||c===r.TARGET_FIRST)&&this.#e.nodeType===r.ELEMENT_NODE)for(let p=0;p<m;p++){const w=h[p];if(w!==this.#e&&this.#e.contains(w)&&(l.add(w),c===r.TARGET_FIRST))break}else if(c===r.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(c===r.TARGET_ALL)if(i===v){let{combo:p}=u[0];for(const w of h){let k=new Set([w]);for(let _=1;_<s;_++){const{combo:g,leaves:L}=u[_],S={combo:p,leaves:L};if(k=this._getCombinedNodes(S,k,i),k.size)if(_===b)if(l.size){const T=[...l];l=new Set([...T,...k]),a=!0}else l=k;else p=g;else break}}}else for(const p of h){let w=new Set([p]);for(let k=b-1;k>=0;k--){const _=u[k];if(w=this._getCombinedNodes(_,w,i),w.size)k===0&&(l.add(p),s>1&&l.size>1&&(a=!0));else break}}else if(c===r.TARGET_FIRST&&i===v){const{combo:p}=u[0];let w;for(const k of h)if(w=this._matchNodeNext(u,new Set([k]),{combo:p,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:k}=u[0],[_]=h;let g=this._findNode(k,_);for(;g;){if(w=this._matchNodeNext(u,new Set([g]),{combo:p,index:1}),w){l.add(w);break}g=this._findNode(k,g)}}}else{let p;for(const w of h)if(p=this._matchNodePrev(u,w,{index:b-1}),p){l.add(w);break}if(!p&&!d&&c===r.TARGET_FIRST){const{leaves:w}=u[b],[k]=h;let _=this._findNode(w,k);for(;_;){if(p=this._matchNodePrev(u,_,{index:b-1}),p){l.add(_);break}_=this._findNode(w,_)}}}}}return c===r.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,N.sortNodes)(l)))):c===r.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,N.sortNodes)(l)))),l}}0&&(module.exports={Finder});
var A=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var F=(L,c)=>{for(var e in c)A(L,e,{get:c[e],enumerable:!0})},$=(L,c,e,o)=>{if(c&&typeof c=="object"||typeof c=="function")for(let a of P(c))!U.call(L,a)&&a!==e&&A(L,a,{get:()=>c[a],enumerable:!(o=D(c,a))||o.enumerable});return L};var W=L=>$(A({},"__esModule",{value:!0}),L);var H={};F(H,{Finder:()=>z});module.exports=W(H);var v=require("./matcher.js"),g=require("./parser.js"),N=require("./utility.js"),n=require("./constant.js");const E="next",S="prev";class z{#a;#r;#k;#t;#h;#c;#b;#o;#m;#n;#e;#d;#g;#p;#N;#s;#u;#_;#f;#w;#i;#l;constructor(c){this.#l=c,this.#r=new WeakMap,this.#h=new WeakMap,this.#m=new WeakMap,this.#N=new WeakMap,this.#c=null,this.#b=null,this.#n=null,this._registerEventListeners()}onError(c,e){if(!(e?.noexcept??this.#g))if(c instanceof DOMException||c instanceof this.#l.DOMException)if(c.name===n.NOT_SUPPORTED_ERR)this.#i&&console.warn(c.message);else throw new this.#l.DOMException(c.message,c.name);else throw c.name in this.#l?new this.#l[c.name](c.message):c}setup(c,e,o={}){const{noexcept:a,warn:l}=o;return this.#g=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#f]=(0,N.resolveContent)(e),this.#u=(0,N.isInShadowTree)(e),[this.#a,this.#d]=this._correspond(c),this.#m=new WeakMap,this.#w=new WeakMap,this.#_=null,this}_registerEventListeners(){const c={capture:!0,passive:!0},e=[],o=["focus","focusin"];for(const r of o)e.push(this.#l.addEventListener(r,f=>{this.#b=f},c));const a=["keydown","keyup"];for(const r of a)e.push(this.#l.addEventListener(r,f=>{const{key:u}=f;n.KEY_MODIFIER.includes(u)||(this.#c=f)},c));const l=["mouseover","mousedown","mouseup","click","mouseout"];for(const r of l)e.push(this.#l.addEventListener(r,f=>{this.#c=f},c));return e}_correspond(c){const e=[];this.#k=!1,this.#o=!1;let o;if(this.#h.has(this.#t)){const a=this.#h.get(this.#t);if(a&&a.has(`${c}`)){const l=a.get(`${c}`);o=l.ast,this.#k=l.descendant,this.#o=l.invalidate}}if(o){const a=o.length;for(let l=0;l<a;l++)o[l].collected=!1,o[l].dir=null,o[l].filtered=!1,o[l].find=!1,e[l]=[]}else{let a;try{a=(0,g.parseSelector)(c)}catch(m){this.onError(m)}const{branches:l,info:r}=(0,g.walkAST)(a),{hasHasPseudoFunc:f,hasLogicalPseudoFunc:u,hasNthChildOfSelector:h}=r;let i=f||!!(u&&h),t=!1,s=0;o=[];for(const[...m]of l){const b=[];let p=m.shift();if(p&&p.type!==n.COMBINATOR){const w=new Set;for(;p;){let k=p.name;if(p.type===n.COMBINATOR){const[_]=m;if(_.type===n.COMBINATOR)throw new DOMException(`Invalid selector ${c}`,n.SYNTAX_ERR);k==="+"||k==="~"?i=!0:t=!0,b.push({combo:p,leaves:(0,g.sortAST)(w)}),w.clear()}else p&&(k&&typeof k=="string"&&(k=(0,g.unescapeSelector)(k),typeof k=="string"&&k!==p.name&&(p.name=k),/[|:]/.test(k)&&(p.namespace=!0)),w.add(p));if(m.length)p=m.shift();else{b.push({combo:null,leaves:(0,g.sortAST)(w)}),w.clear();break}}}o.push({branch:b,collected:!1,dir:null,filtered:!1,find:!1}),e[s]=[],s++}let d;this.#h.has(this.#t)?d=this.#h.get(this.#t):d=new Map,d.set(`${c}`,{ast:o,descendant:t,invalidate:i}),this.#h.set(this.#t,d),this.#k=t,this.#o=i}return[o,e]}_createTreeWalker(c){let e;return this.#w.has(c)?e=this.#w.get(c):(e=this.#t.createTreeWalker(c,n.WALKER_FILTER),this.#w.set(c,e)),e}_prepareQuerySelectorWalker(){return this.#p=this._createTreeWalker(this.#e),this.#p}_collectNthChild(c,e,o){const{a,b:l,reverse:r,selector:f}=c,{parentNode:u}=e,h=new Set;let i;if(f){if(this.#r.has(f))i=this.#r.get(f);else{const{branches:s}=(0,g.walkAST)(f);i=s,this.#o||this.#r.set(f,i)}const{branches:t}=(0,g.walkAST)(f);i=t}if(u){const t=this.#f;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let d=0;for(;s;)d++,s=t.nextSibling();const m=new Set;if(i)for(s=(0,N.traverseNode)(u,t),s=t.firstChild();s;){if((0,N.isVisible)(s)){let b;for(const p of i)if(b=this._matchLeaves(p,s,o),!b)break;b&&m.add(s)}s=t.nextSibling()}if(a===0){if(l>0&&l<=d){if(m.size){s=(0,N.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(m.has(s)){if(b===l-1){h.add(s);break}b++}r?s=t.previousSibling():s=t.nextSibling()}}else if(!f){s=(0,N.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(b===l-1){h.add(s);break}r?s=t.previousSibling():s=t.nextSibling(),b++}}}}else{let b=l-1;if(a>0)for(;b<0;)b+=a;if(b>=0&&b<d){s=(0,N.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let p=0,w=a>0?0:l-1;for(;s&&(s&&b>=0&&b<d);)m.size?m.has(s)&&(w===b&&(h.add(s),b+=a),a>0?w++:w--):p===b&&(f||h.add(s),b+=a),r?s=t.previousSibling():s=t.nextSibling(),p++}}if(r&&h.size>1){const b=[...h];return new Set(b.reverse())}}else if(e===this.#s&&a+l===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,o),t)break;t&&h.add(e)}else h.add(e);return h}_collectNthOfType(c,e){const{a:o,b:a,reverse:l}=c,{localName:r,namespaceURI:f,parentNode:u,prefix:h}=e,i=new Set;if(u){const t=this.#f;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let d=0;for(;s;)d++,s=t.nextSibling();if(o===0){if(a>0&&a<=d){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){const{localName:b,namespaceURI:p,prefix:w}=s;if(b===r&&w===h&&p===f){if(m===a-1){i.add(s);break}m++}l?s=t.previousSibling():s=t.nextSibling()}}}else{let m=a-1;if(o>0)for(;m<0;)m+=o;if(m>=0&&m<d){s=(0,N.traverseNode)(u,t),l?s=t.lastChild():s=t.firstChild();let b=o>0?0:a-1;for(;s;){const{localName:p,namespaceURI:w,prefix:k}=s;if(p===r&&k===h&&w===f){if(b===m&&(i.add(s),m+=o),m<0||m>=d)break;o>0?b++:b--}l?s=t.previousSibling():s=t.nextSibling()}}}if(l&&i.size>1){const m=[...i];return new Set(m.reverse())}}else e===this.#s&&o+a===1&&i.add(e);return i}_matchAnPlusB(c,e,o,a){const{nth:{a:l,b:r,name:f},selector:u}=c,h=new Map;if(f?(f==="even"?(h.set("a",2),h.set("b",0)):f==="odd"&&(h.set("a",2),h.set("b",1)),o.indexOf("last")>-1&&h.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?h.set("a",l*1):h.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?h.set("b",r*1):h.set("b",0),o.indexOf("last")>-1&&h.set("reverse",!0)),o==="nth-child"||o==="nth-last-child"){u&&h.set("selector",u);const i=Object.fromEntries(h);return this._collectNthChild(i,e,a)}else if(o==="nth-of-type"||o==="nth-last-of-type"){const i=Object.fromEntries(h);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(c,e,o){if(Array.isArray(c)&&c.length){const a=[...c],[l]=a,{type:r}=l;let f;r===n.COMBINATOR?f=a.shift():f={name:" ",type:n.COMBINATOR};const u=[];for(;a.length;){const[t]=a,{type:s}=t;if(s===n.COMBINATOR)break;u.push(a.shift())}const h={combo:f,leaves:u};o.dir=E;const i=this._matchCombinator(h,e,o);if(i.size){if(a.length){let t;for(const s of i)if(t=this._matchHasPseudoFunc(a,s,o),t)break;return!!t}return!0}return!1}return!1}_matchLogicalPseudoFunc(c,e,o){const{astName:a,branches:l,twigBranches:r}=c,{isShadowRoot:f}=o;if(a==="has"){let u;for(const h of l)if(u=this._matchHasPseudoFunc(h,e,o),u)break;return u?f?this.#_?e:null:e:null}else{if(f){for(const i of l)if(i.length>1)return null}o.forgive=a==="is"||a==="where";const u=r.length;let h;for(let i=0;i<u;i++){const t=r[i],s=t.length-1,{leaves:d}=t[s];if(h=this._matchLeaves(d,e,o),h&&s>0){let m=new Set([e]);for(let b=s-1;b>=0;b--){const p=t[b],w=[];o.dir=S;for(const k of m){const _=this._matchCombinator(p,k,o);_.size&&w.push(..._)}if(w.length)b===0?h=!0:m=new Set(w);else{h=!1;break}}}if(h)break}return a==="not"?h?null:e:h?e:null}}_matchPseudoClassSelector(c,e,o){const{children:a,name:l}=c,{localName:r,parentNode:f}=e,{forgive:u,warn:h=this.#i}=o,i=new Set;if(Array.isArray(a)&&n.KEY_LOGICAL.includes(l)){if(!a.length&&l!=="is"&&l!=="where"){const d=(0,g.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}let t;if(this.#r.has(c))t=this.#r.get(c);else{const{branches:d}=(0,g.walkAST)(c);if(l==="has"){for(const m of a){const b=(0,g.findAST)(m,p=>n.KEY_LOGICAL.includes(p.name)&&(0,g.findAST)(p,w=>w.name==="has")?p:null);if(b){const p=b.name;if(p==="is"||p==="where")return i;{const w=(0,g.generateCSS)(c);throw new DOMException(`Invalid selector ${w}`,n.SYNTAX_ERR)}}}t={astName:l,branches:d}}else{const m=[];for(const[...b]of d){const p=[],w=new Set;let k=b.shift();for(;k;)if(k.type===n.COMBINATOR?(p.push({combo:k,leaves:[...w]}),w.clear()):k&&w.add(k),b.length)k=b.shift();else{p.push({combo:null,leaves:[...w]}),w.clear();break}m.push(p)}t={astName:l,branches:d,twigBranches:m},this.#o||this.#r.set(c,t)}}const s=this._matchLogicalPseudoFunc(t,e,o);s&&i.add(s)}else if(Array.isArray(a))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){if(a.length!==1){const d=(0,g.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}const[t]=a;return this._matchAnPlusB(t,e,l,o)}else switch(l){case"dir":{if(a.length!==1){const d=(0,g.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}const[t]=a;(0,v.matchDirectionPseudoClass)(t,e)&&i.add(e);break}case"lang":{if(!a.length){const s=(0,g.generateCSS)(c);throw new DOMException(`Invalid selector ${s}`,n.SYNTAX_ERR)}let t;for(const s of a)if(t=(0,v.matchLanguagePseudoClass)(s,e),t)break;t&&i.add(e);break}case"state":{if((0,N.isCustomElement)(e)){const[{value:t}]=a;if(t)if(e[t])i.add(e);else for(const s in e){const d=e[s];if(d instanceof this.#l.ElementInternals){d?.states?.has(t)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(h)throw new DOMException(`Unsupported pseudo-class :${l}()`,n.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(h)throw new DOMException(`Unknown pseudo-class :${l}()`,n.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${l}()`,n.SYNTAX_ERR)}else switch(l){case"any-link":case"link":{(r==="a"||r==="area")&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if((r==="a"||r==="area")&&e.hasAttribute("href")){const{href:t,origin:s,pathname:d}=new URL(this.#t.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===d&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#c??{};/^(?:click|mouse(?:down|over|up))$/.test(s)&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:d}=this.#c??{};d==="mousedown"&&t&n.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#t.URL);e.id&&t===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#t.URL);if(t){const s=t.replace(/^#/,"");let d=this.#t.getElementById(s);for(;d;){if(d===e){i.add(e);break}d=d.parentNode}}break}case"scope":{this.#e.nodeType===n.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&(0,N.isFocusableArea)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&(0,N.isFocusableArea)(e)){let t;if((0,N.isFocusVisible)(e))t=!0;else if(this.#b){const{relatedTarget:s,target:d}=this.#b;if(d===e)if((0,N.isFocusVisible)(s))t=!0;else if(this.#c){const{key:m,target:b,type:p}=this.#c;b===s?(this.#n===null||d===this.#n)&&(t=!0):m==="Tab"?(p==="keydown"&&b!==e||p==="keyup"&&b===e)&&(b===d?(this.#n===null||b===this.#n&&s===null)&&(t=!0):t=!0):m&&(p==="keydown"||p==="keyup")&&b===e&&(t=!0)}else(s===null||s===this.#n)&&(t=!0)}t?(this.#n=e,i.add(e)):this.#n===e&&(this.#n=null)}break}case"focus-within":{let t,s=this.#t.activeElement;if((0,N.isFocusableArea)(s))for(;s;){if(s===e){t=!0;break}s=s.parentNode}t&&i.add(e);break}case"open":case"closed":{(r==="details"||r==="dialog")&&(e.hasAttribute("open")?l==="open"&&i.add(e):l==="closed"&&i.add(e));break}case"disabled":case"enabled":{if([...n.KEY_FORM_FOCUS,"fieldset","optgroup","option"].includes(r)||(0,N.isCustomElement)(e,{formAssociated:!0})){let s;if(e.disabled||e.hasAttribute("disabled"))s=!0;else if(e.localName==="option")f.localName==="optgroup"&&(f.disabled||f.hasAttribute("disabled"))&&(s=!0);else if(e.localName!=="optgroup"){let d=f;for(;d;)if(d.localName==="fieldset"&&(d.disabled||d.hasAttribute("disabled"))){const m=this.#f;let b=(0,N.traverseNode)(d,m);for(b=m.firstChild();b&&b.localName!=="legend";)b=m.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(d.localName==="form")break;if(d.parentNode?.nodeType===n.ELEMENT_NODE){if(d.parentNode.localName==="form")break;d=d.parentNode}else break}}s?l==="disabled"&&i.add(e):l==="enabled"&&i.add(e)}break}case"read-only":case"read-write":{let t,s;switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0;break}case"input":{(!e.type||n.KEY_INPUT_EDIT.includes(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")?t=!0:s=!0);break}default:(0,N.isContentEditable)(e)?s=!0:t=!0}t?l==="read-only"&&i.add(e):l==="read-write"&&s&&i.add(e);break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;r==="textarea"?s=e:r==="input"&&(e.hasAttribute("type")?[...n.KEY_INPUT_TEXT,"number"].includes(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{const t=e.getAttribute("type");(e.checked&&r==="input"&&(t==="checkbox"||t==="radio")||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.#t.documentElement);const d=s.getElementsByTagName("input"),m=d.length;let b;for(let p=0;p<m;p++){const w=d[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":{const t=["checkbox","radio"],s=["button","reset"],d=["image","submit"],m=e.getAttribute("type");if(r==="button"&&!(e.hasAttribute("type")&&s.includes(m))||r==="input"&&e.hasAttribute("type")&&d.includes(m)){let b=e.parentNode;for(;b&&b.localName!=="form";)b=b.parentNode;if(b){const p=this.#f;let w=(0,N.traverseNode)(b,p);for(w=p.firstChild();w&&b.contains(w);){const k=w.localName,_=w.getAttribute("type");let y;if(k==="button"?y=!(w.hasAttribute("type")&&s.includes(_)):k==="input"&&(y=w.hasAttribute("type")&&d.includes(_)),y){w===e&&i.add(e);break}w=p.nextNode()}}}else(r==="input"&&e.hasAttribute("type")&&t.includes(m)&&e.hasAttribute("checked")||r==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":case"invalid":{const t=[...n.KEY_FORM_FOCUS,"form"];if(t.includes(r)){let s;e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&(s=!0):s=!0),s?l==="valid"&&i.add(e):l==="invalid"&&i.add(e)}else if(r==="fieldset"){const s=this.#f;let d=(0,N.traverseNode)(e,s);d=s.firstChild();let m;if(!d)m=!0;else for(;d&&e.contains(d)&&!(t.includes(d.localName)&&(d.checkValidity()?d.maxLength>=0?m=d.maxLength>=d.value.length:m=!0:m=!1,!m));)d=s.nextNode();m?l==="valid"&&i.add(e):l==="invalid"&&i.add(e)}break}case"in-range":case"out-of-range":{const t=[...n.KEY_INPUT_DATE,"number","range"],s=e.getAttribute("type");if(r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&t.includes(s)){const d=e.validity.rangeUnderflow||e.validity.rangeOverflow;(l==="out-of-range"&&d||l==="in-range"&&!d&&(e.hasAttribute("min")||e.hasAttribute("max")||s==="range"))&&i.add(e)}break}case"required":case"optional":{let t;if(r==="select"||r==="textarea")t=e;else if(r==="input")if(e.hasAttribute("type")){const s=[...n.KEY_INPUT_EDIT,"checkbox","file","radio"],d=e.getAttribute("type");s.includes(d)&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required")?l==="required"&&i.add(e):l==="optional"&&i.add(e));break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#t.createTreeWalker(e,n.SHOW_ALL);let s=t.firstChild(),d;for(;s&&(d=s.nodeType!==n.ELEMENT_NODE&&s.nodeType!==n.TEXT_NODE,!!d);)s=t.nextSibling();d&&i.add(e)}else i.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(f){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||r.includes("-")?(0,N.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,N.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(h)throw new DOMException(`Unsupported pseudo-element ::${l}`,n.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(h)throw new DOMException(`Unsupported pseudo-class :${l}`,n.NOT_SUPPORTED_ERR);break}default:if(l.startsWith("-webkit-")){if(h)throw new DOMException(`Unsupported pseudo-class :${l}`,n.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${l}`,n.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(c,e){const{children:o,name:a}=c;if(Array.isArray(o)){if(o.length!==1){const h=(0,g.generateCSS)(c);throw new DOMException(`Invalid selector ${h}`,n.SYNTAX_ERR)}const{branches:l}=(0,g.walkAST)(o[0]),[r]=l,[...f]=r,{host:u}=e;if(a==="host"){let h;for(const i of f){const{type:t}=i;if(t===n.COMBINATOR){const s=(0,g.generateCSS)(c);throw new DOMException(`Invalid selector ${s}`,n.SYNTAX_ERR)}if(h=this._matchSelector(i,u).has(u),!h)break}return h?e:null}else if(a==="host-context"){let h=u,i;for(;h;){for(const t of f){const{type:s}=t;if(s===n.COMBINATOR){const d=(0,g.generateCSS)(c);throw new DOMException(`Invalid selector ${d}`,n.SYNTAX_ERR)}if(i=this._matchSelector(t,h).has(h),!i)break}if(i)break;h=h.parentNode}return i?e:null}throw new DOMException(`Invalid selector :${a}`,n.SYNTAX_ERR)}else{if(a==="host")return e;throw new DOMException(`Invalid selector :${a}`,n.SYNTAX_ERR)}}_matchSelector(c,e,o={}){const{type:a}=c,l=(0,g.unescapeSelector)(c.name),r=new Set;if(e.nodeType===n.ELEMENT_NODE)switch(a){case n.ATTR_SELECTOR:{(0,v.matchAttributeSelector)(c,e)&&r.add(e);break}case n.ID_SELECTOR:{e.id===l&&r.add(e);break}case n.CLASS_SELECTOR:{e.classList.contains(l)&&r.add(e);break}case n.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(c,e,o);case n.TYPE_SELECTOR:{(0,v.matchTypeSelector)(c,e,o)&&r.add(e);break}case n.PS_ELEMENT_SELECTOR:default:(0,v.matchPseudoElementSelector)(l,a,o)}else if(this.#u&&a===n.PS_CLASS_SELECTOR&&e.nodeType===n.DOCUMENT_FRAGMENT_NODE){if(n.KEY_LOGICAL.includes(l))return o.isShadowRoot=!0,this._matchPseudoClassSelector(c,e,o);if(l==="host"||l==="host-context"){const f=this._matchShadowHostPseudoClass(c,e,o);f&&(this.#_=!0,r.add(f))}}return r}_matchLeaves(c,e,o){let a;if(this.#o?a=this.#m.get(c):a=this.#N.get(c),a&&a.has(e)){const{matched:l}=a.get(e);return l}else{let l=!0;const r=[...n.KEY_FORM_FOCUS,"fieldset","form"],f=["any-link","defined","dir","link"];e.nodeType===n.ELEMENT_NODE&&r.includes(e.localName)&&(l=!1);let u;for(const h of c){switch(h.type){case n.ATTR_SELECTOR:case n.ID_SELECTOR:{l=!1;break}case n.PS_CLASS_SELECTOR:{f.includes(h.name)&&(l=!1);break}default:}if(u=this._matchSelector(h,e,o).has(e),!u)break}return l&&(a||(a=new WeakMap),a.set(e,{matched:u}),this.#o?this.#m.set(c,a):this.#N.set(c,a)),u}}_matchHTMLCollection(c,e){if(c.length){const{compound:o,filterLeaves:a}=e;if(o){const l=new Set;for(const r of c)this._matchLeaves(a,r,e)&&l.add(r);return l}else{const l=[].slice.call(c);return new Set(l)}}return new Set}_findDescendantNodes(c,e,o){const[a,...l]=c,r=l.length>0,{type:f}=a,u=(0,g.unescapeSelector)(a.name);let h=new Set,i=!1;if(this.#u)i=!0;else switch(f){case n.PS_ELEMENT_SELECTOR:{(0,v.matchPseudoElementSelector)(u,f,o);break}case n.ID_SELECTOR:{if(this.#s.nodeType===n.ELEMENT_NODE)i=!0;else{const t=this.#s.getElementById(u);t&&t!==e&&e.contains(t)&&(r?this._matchLeaves(l,t,o)&&h.add(t):h.add(t))}break}case n.CLASS_SELECTOR:{const t=e.getElementsByClassName(u);h=this._matchHTMLCollection(t,{compound:r,filterLeaves:l});break}case n.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);h=this._matchHTMLCollection(t,{compound:r,filterLeaves:l})}else i=!0;break}default:i=!0}return{nodes:h,pending:i}}_matchCombinator(c,e,o){const{combo:a,leaves:l}=c,{name:r}=a,{parentNode:f}=e,{dir:u}=o,h=new Set;if(u===E)switch(r){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(l,i,o)&&h.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(l,t,o)&&h.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,N.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(l,t,o)&&h.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(l,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let d=(0,N.traverseNode)(e,s);for(d=s.nextNode();d&&e.contains(d);)this._matchLeaves(l,d,o)&&h.add(d),d=s.nextNode()}}}else switch(r){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(l,i,o)&&h.add(i);break}case"~":{if(f){const i=this._createTreeWalker(f);let t=(0,N.traverseNode)(f,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(l,t,o)&&h.add(t),t=i.nextSibling()}break}case">":{f&&this._matchLeaves(l,f,o)&&h.add(f);break}case" ":default:{const i=[];let t=f;for(;t;)this._matchLeaves(l,t,o)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return h}_findNode(c,e){const o=this.#p;let a=(0,N.traverseNode)(e,o),l;if(a)for((a.nodeType!==n.ELEMENT_NODE||a===e&&a!==this.#s)&&(a=o.nextNode());a;){if(this._matchLeaves(c,a,{warn:this.#i})){l=a;break}a=o.nextNode()}return l??null}_matchSelf(c){const e=[];let o=!1;return this._matchLeaves(c,this.#e,{warn:this.#i})&&(e.push(this.#e),o=!0),[e,o]}_findLineal(c,e){const{complex:o}=e,a=[];let l=!1,r=this._matchLeaves(c,this.#e,{warn:this.#i});if(r&&(a.push(this.#e),l=!0),!r||o){let f=this.#e.parentNode;for(;f&&(r=this._matchLeaves(c,f,{warn:this.#i}),r&&(a.push(f),l=!0),f.parentNode);)f=f.parentNode}return[a,l]}_findFirst(c){const e=[];let o=!1;const a=this._findNode(c,this.#e);return a&&(e.push(a),o=!0),[e,o]}_findFromHTMLCollection(c,e){const{complex:o,compound:a,filterLeaves:l,targetType:r}=e;let f=[],u=!1,h=!1;if(c.length)if(this.#e.nodeType===n.ELEMENT_NODE){for(const i of c)if(i!==this.#e&&(this.#e.contains(i)||i.contains(this.#e))){if(a){if(this._matchLeaves(l,i,{warn:this.#i})&&(f.push(i),u=!0,r===n.TARGET_FIRST))break}else if(f.push(i),u=!0,r===n.TARGET_FIRST)break}}else if(o)if(a){for(const i of c)if(this._matchLeaves(l,i,{warn:this.#i})&&(f.push(i),u=!0,r===n.TARGET_FIRST))break}else f=[].slice.call(c),u=!0,h=!0;else if(a){for(const i of c)if(this._matchLeaves(l,i,{warn:this.#i})&&(f.push(i),u=!0,r===n.TARGET_FIRST))break}else f=[].slice.call(c),u=!0,h=!0;return[f,u,h]}_findEntryNodes(c,e,o){const{leaves:a}=c,[l,...r]=a,f=r.length>0,{name:u,type:h}=l;let i=[],t=!1,s=!1,d=!1;switch(h){case n.PS_ELEMENT_SELECTOR:{(0,v.matchPseudoElementSelector)(u,h,{warn:this.#i});break}case n.ID_SELECTOR:{if(e===n.TARGET_SELF)[i,s]=this._matchSelf(a);else if(e===n.TARGET_LINEAL)[i,s]=this._findLineal(a,{complex:o});else if(e===n.TARGET_FIRST&&this.#s.nodeType!==n.ELEMENT_NODE){const m=this.#s.getElementById(u);m&&(f?this._matchLeaves(r,m,{warn:this.#i})&&(i.push(m),s=!0):(i.push(m),s=!0))}else e===n.TARGET_FIRST?[i,s]=this._findFirst(a):d=!0;break}case n.CLASS_SELECTOR:{if(e===n.TARGET_SELF)[i,s]=this._matchSelf(a);else if(e===n.TARGET_LINEAL)[i,s]=this._findLineal(a,{complex:o});else if(this.#s.nodeType===n.DOCUMENT_NODE){const m=this.#s.getElementsByClassName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:o,compound:f,filterLeaves:r,targetType:e}))}else e===n.TARGET_FIRST?[i,s]=this._findFirst(a):d=!0;break}case n.TYPE_SELECTOR:{if(e===n.TARGET_SELF)[i,s]=this._matchSelf(a);else if(e===n.TARGET_LINEAL)[i,s]=this._findLineal(a,{complex:o});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===n.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#s.getElementsByTagName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:o,compound:f,filterLeaves:r,targetType:e}))}else e===n.TARGET_FIRST?[i,s]=this._findFirst(a):d=!0;break}default:if(e!==n.TARGET_LINEAL&&(u==="host"||u==="host-context")){if(this.#u&&this.#e.nodeType===n.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(l,this.#e);m&&(i.push(m),s=!0)}}else e===n.TARGET_SELF?[i,s]=this._matchSelf(a):e===n.TARGET_LINEAL?[i,s]=this._findLineal(a,{complex:o}):e===n.TARGET_FIRST?[i,s]=this._findFirst(a):d=!0}return{collected:t,compound:f,filtered:s,nodes:i,pending:d}}_collectNodes(c){const e=this.#a.values();if(c===n.TARGET_ALL||c===n.TARGET_FIRST){const o=new Set;let a=0;for(const{branch:l}of e){const r=l.length,f=r>1,u=l[0];let h,i;if(f){const{combo:p,leaves:[{name:w,type:k}]}=u,_=l[r-1],{leaves:[{name:y,type:T}]}=_;if(T===n.PS_ELEMENT_SELECTOR||T===n.ID_SELECTOR)h=S,i=_;else if(k===n.PS_ELEMENT_SELECTOR||k===n.ID_SELECTOR)h=E,i=u;else if(c===n.TARGET_ALL)if(w==="*"&&k===n.TYPE_SELECTOR)h=S,i=_;else if(y==="*"&&T===n.TYPE_SELECTOR)h=E,i=u;else if(r===2){const{name:x}=p;x==="+"||x==="~"?(h=S,i=_):(h=E,i=u)}else h=E,i=u;else if(w==="*"&&k===n.TYPE_SELECTOR)h=S,i=_;else if(y==="*"&&T===n.TYPE_SELECTOR)h=E,i=u;else{let x;for(const{combo:C,leaves:[M]}of l){const{name:I,type:R}=M;if(R===n.PS_CLASS_SELECTOR&&I==="dir"){x=!1;break}if(!x&&C){const{name:O}=C;(O==="+"||O==="~")&&(x=!0)}}x?(h=E,i=u):(h=S,i=_)}}else h=S,i=u;const{collected:t,compound:s,filtered:d,nodes:m,pending:b}=this._findEntryNodes(i,c,f);m.length?(this.#a[a].find=!0,this.#d[a]=m):b&&o.add(new Map([["index",a],["twig",i]])),this.#a[a].collected=t,this.#a[a].dir=h,this.#a[a].filtered=d||!s,a++}if(o.size){let l,r;this.#e!==this.#s&&this.#e.nodeType===n.ELEMENT_NODE?(l=this.#e,r=this.#p):(l=this.#s,r=this.#f);let f=(0,N.traverseNode)(l,r);for(;f;){let u=!1;if(this.#e.nodeType===n.ELEMENT_NODE?f===this.#e?u=!0:u=this.#e.contains(f):u=!0,u)for(const h of o){const{leaves:i}=h.get("twig");if(this._matchLeaves(i,f,{warn:this.#i})){const s=h.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#d[s].push(f)}}f!==r.currentNode&&(f=(0,N.traverseNode)(f,r)),f=r.nextNode()}}}else{let o=0;for(const{branch:a}of e){const l=a[a.length-1],r=a.length>1,{compound:f,filtered:u,nodes:h}=this._findEntryNodes(l,c,r);h.length&&(this.#a[o].find=!0,this.#d[o]=h),this.#a[o].dir=S,this.#a[o].filtered=u||!f,o++}}return[this.#a,this.#d]}_getCombinedNodes(c,e,o){const a=[];for(const l of e){const r=this._matchCombinator(c,l,{dir:o,warn:this.#i});r.size&&a.push(...r)}return a.length?new Set(a):new Set}_matchNodeNext(c,e,o){const{combo:a,index:l}=o,{combo:r,leaves:f}=c[l],u={combo:a,leaves:f},h=this._getCombinedNodes(u,e,E);if(h.size)if(l===c.length-1){const[i]=(0,N.sortNodes)(h);return i}else return this._matchNodeNext(c,h,{combo:r,index:l+1});return null}_matchNodePrev(c,e,o){const{index:a}=o,l=c[a],r=new Set([e]),f=this._getCombinedNodes(l,r,S);if(f.size){if(a===0)return e;{let u;for(const h of f)if(u=this._matchNodePrev(c,h,{index:a-1}),u)break;return u?e:null}}return null}find(c){(c===n.TARGET_ALL||c===n.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],o]=this._collectNodes(c),a=e.length;let l,r=new Set;for(let f=0;f<a;f++){const{branch:u,collected:h,dir:i,find:t}=e[f],s=u.length;if(s&&t){const d=o[f],m=d.length,b=s-1;if(b===0)if((c===n.TARGET_ALL||c===n.TARGET_FIRST)&&this.#e.nodeType===n.ELEMENT_NODE)for(let p=0;p<m;p++){const w=d[p];if(w!==this.#e&&this.#e.contains(w)&&(r.add(w),c===n.TARGET_FIRST))break}else if(c===n.TARGET_ALL)if(r.size){const p=[...r];r=new Set([...p,...d]),l=!0}else r=new Set(d);else{const[p]=d;r.add(p)}else if(c===n.TARGET_ALL)if(i===E){let{combo:p}=u[0];for(const w of d){let k=new Set([w]);for(let _=1;_<s;_++){const{combo:y,leaves:T}=u[_],x={combo:p,leaves:T};if(k=this._getCombinedNodes(x,k,i),k.size)if(_===b)if(r.size){const C=[...r];r=new Set([...C,...k]),l=!0}else r=k;else p=y;else break}}}else for(const p of d){let w=new Set([p]);for(let k=b-1;k>=0;k--){const _=u[k];if(w=this._getCombinedNodes(_,w,i),w.size)k===0&&(r.add(p),s>1&&r.size>1&&(l=!0));else break}}else if(c===n.TARGET_FIRST&&i===E){const{combo:p}=u[0];let w;for(const k of d)if(w=this._matchNodeNext(u,new Set([k]),{combo:p,index:1}),w){r.add(w);break}if(!w&&!h){const{leaves:k}=u[0],[_]=d;let y=this._findNode(k,_);for(;y;){if(w=this._matchNodeNext(u,new Set([y]),{combo:p,index:1}),w){r.add(w);break}y=this._findNode(k,y)}}}else{let p;for(const w of d)if(p=this._matchNodePrev(u,w,{index:b-1}),p){r.add(w);break}if(!p&&!h&&c===n.TARGET_FIRST){const{leaves:w}=u[b],[k]=d;let _=this._findNode(w,k);for(;_;){if(p=this._matchNodePrev(u,_,{index:b-1}),p){r.add(_);break}_=this._findNode(w,_)}}}}}return c===n.TARGET_FIRST?(r.delete(this.#e),r.size>1&&(r=new Set((0,N.sortNodes)(r)))):c===n.TARGET_ALL&&(r.delete(this.#e),l&&r.size>1&&(r=new Set((0,N.sortNodes)(r)))),r}}0&&(module.exports={Finder});
//# sourceMappingURL=finder.js.map

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

var y=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var S=(x,t)=>{for(var e in t)y(x,e,{get:t[e],enumerable:!0})},A=(x,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of N(t))!L.call(x,l)&&l!==e&&y(x,l,{get:()=>t[l],enumerable:!(s=T(t,l))||s.enumerable});return x};var O=x=>A(y({},"__esModule",{value:!0}),x);var C={};S(C,{Matcher:()=>R});module.exports=O(C);var b=require("./parser.js"),$=require("./utility.js"),i=require("./constant.js");class R{matchPseudoElementSelector(t,e={}){if(!t||typeof t!="string")throw new TypeError(`Unexpected type ${(0,$.getType)(t)}`);const{forgive:s,warn:l}=e;switch(t){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(l)throw new DOMException(`Unsupported pseudo-element ::${t}`,i.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(l)throw new DOMException(`Unsupported pseudo-element ::${t}()`,i.NOT_SUPPORTED_ERR);break}default:if(t.startsWith("-webkit-")){if(l)throw new DOMException(`Unsupported pseudo-element ::${t}`,i.NOT_SUPPORTED_ERR)}else if(!s)throw new DOMException(`Unknown pseudo-element ::${t}`,i.SYNTAX_ERR)}}_matchAttributeSelector(t,e){const{flags:s,matcher:l,name:p,value:d}=t;if(typeof s=="string"&&!/^[is]$/i.test(s)){const w=(0,b.generateCSS)(t);throw new DOMException(`Invalid selector ${w}`,i.SYNTAX_ERR)}const{attributes:m}=e;let h;if(m&&m.length){const w=e.ownerDocument.contentType;let n;w==="text/html"?typeof s=="string"&&/^s$/i.test(s)?n=!1:n=!0:typeof s=="string"&&/^i$/i.test(s)?n=!0:n=!1;let g=(0,b.unescapeSelector)(p.name);n&&(g=g.toLowerCase());const f=new Set;if(g.indexOf("|")>-1){const{prefix:o,localName:c}=(0,b.parseAstName)(g);for(const a of m){let{name:r,value:u}=a;switch(n&&(r=r.toLowerCase(),u=u.toLowerCase()),o){case"":{c===r&&f.add(u);break}case"*":{r.indexOf(":")>-1?r.endsWith(`:${c}`)&&f.add(u):c===r&&f.add(u);break}default:if(r.indexOf(":")>-1){const[k,E]=r.split(":");if(k==="xml"&&E==="lang")continue;o===k&&c===E&&(0,$.isNamespaceDeclared)(o,e)&&f.add(u)}}}}else for(let{name:o,value:c}of m)if(n&&(o=o.toLowerCase(),c=c.toLowerCase()),o.indexOf(":")>-1){const[a,r]=o.split(":");if(a==="xml"&&r==="lang")continue;g===r&&f.add(c)}else g===o&&f.add(c);if(f.size){const{name:o,value:c}=d??{};let a;switch(o?n?a=o.toLowerCase():a=o:c?n?a=c.toLowerCase():a=c:c===""&&(a=c),l){case"=":{typeof a=="string"&&f.has(a)&&(h=e);break}case"~=":{if(a&&typeof a=="string"){for(const r of f)if(new Set(r.split(/\s+/)).has(a)){h=e;break}}break}case"|=":{if(a&&typeof a=="string"){let r;for(const u of f)if(u===a||u.startsWith(`${a}-`)){r=u;break}r&&(h=e)}break}case"^=":{if(a&&typeof a=="string"){let r;for(const u of f)if(u.startsWith(`${a}`)){r=u;break}r&&(h=e)}break}case"$=":{if(a&&typeof a=="string"){let r;for(const u of f)if(u.endsWith(`${a}`)){r=u;break}r&&(h=e)}break}case"*=":{if(a&&typeof a=="string"){let r;for(const u of f)if(u.includes(`${a}`)){r=u;break}r&&(h=e)}break}case null:default:h=e}}}return h??null}_matchTypeSelector(t,e,s={}){const l=(0,b.unescapeSelector)(t.name),{localName:p,namespaceURI:d,prefix:m}=e,{forgive:h}=s;let{prefix:w,localName:n}=(0,b.parseAstName)(l,e);e.ownerDocument.contentType==="text/html"&&/[A-Z][\\w-]*/i.test(p)&&(w=w.toLowerCase(),n=n.toLowerCase());let g,f;p.indexOf(":")>-1?[g,f]=p.split(":"):(g=m||"",f=p);let o;switch(w){case"":{!g&&!d&&(n==="*"||n===f)&&(o=e);break}case"*":{(n==="*"||n===f)&&(o=e);break}default:{const c=e.lookupNamespaceURI(w),a=e.lookupNamespaceURI(g);if(c===a&&w===g)(n==="*"||n===f)&&(o=e);else if(!h&&!c)throw new DOMException(`Undeclared namespace ${w}`,i.SYNTAX_ERR)}}return o??null}_matchDirectionPseudoClass(t,e){const s=(0,$.getDirectionality)(e);let l;return t.name===s&&(l=e),l??null}_matchLanguagePseudoClass(t,e){if(t.name===i.EMPTY)return null;const s=(0,b.unescapeSelector)(t.name);typeof s=="string"&&s!==t.name&&(t.name=s);let l;if(s==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(l=e);else{let p=e.parentNode;for(;p&&p.nodeType===i.ELEMENT_NODE;){if(p.hasAttribute("lang")){p.getAttribute("lang")&&(l=e);break}p=p.parentNode}}else if(s&&new RegExp(`^(?:\\*-)?${i.ALPHA_NUM}${i.LANG_PART}$`,"i").test(s)){let d;if(s.indexOf("-")>-1){const[m,h,...w]=s.split("-");let n;m==="*"?n=`${i.ALPHA_NUM}${i.LANG_PART}`:n=`${m}${i.LANG_PART}`;const g=`-${h}${i.LANG_PART}`,f=w.length;let o="";if(f)for(let c=0;c<f;c++)o+=`-${w[c]}${i.LANG_PART}`;d=new RegExp(`^${n}${g}${o}$`,"i")}else d=new RegExp(`^${s}${i.LANG_PART}$`,"i");if(e.hasAttribute("lang"))d.test(e.getAttribute("lang"))&&(l=e);else{let m=e.parentNode;for(;m&&m.nodeType===i.ELEMENT_NODE;){if(m.hasAttribute("lang")){const h=m.getAttribute("lang");d.test(h)&&(l=e);break}m=m.parentNode}}}return l??null}matchSelector(t,e,s={},l=!1){if(!l){if(!t||!t.type)throw new TypeError(`Unexpected ast type ${(0,$.getType)(t)}`);if(!e||!e.nodeType)throw new TypeError(`Unexpected node type ${(0,$.getType)(e)}`);if(e.nodeType!==i.ELEMENT_NODE)throw new TypeError(`Unexpected node ${e.nodeName}`)}let p;switch(t.type){case i.ATTR_SELECTOR:{p=this._matchAttributeSelector(t,e);break}case i.TYPE_SELECTOR:{p=this._matchTypeSelector(t,e,s??{});break}default:{const{children:[d],name:m}=t;m==="dir"?p=this._matchDirectionPseudoClass(d,e):m==="lang"&&(p=this._matchLanguagePseudoClass(d,e))}}return p}}0&&(module.exports={Matcher});
var b=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var k=(i,t)=>{for(var l in t)b(i,l,{get:t[l],enumerable:!0})},S=(i,t,l,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!L.call(i,o)&&o!==l&&b(i,o,{get:()=>t[o],enumerable:!(d=E(t,o))||d.enumerable});return i};var A=i=>S(b({},"__esModule",{value:!0}),i);var C={};k(C,{matchAttributeSelector:()=>R,matchDirectionPseudoClass:()=>D,matchLanguagePseudoClass:()=>O,matchPseudoElementSelector:()=>T,matchTypeSelector:()=>v});module.exports=A(C);var x=require("./parser.js"),h=require("./utility.js"),s=require("./constant.js");const T=(i,t,l={})=>{const{forgive:d,warn:o}=l;if(t===s.PS_ELEMENT_SELECTOR)switch(i){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(o)throw new DOMException(`Unsupported pseudo-element ::${i}`,s.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(o)throw new DOMException(`Unsupported pseudo-element ::${i}()`,s.NOT_SUPPORTED_ERR);break}default:if(i.startsWith("-webkit-")){if(o)throw new DOMException(`Unsupported pseudo-element ::${i}`,s.NOT_SUPPORTED_ERR)}else if(!d)throw new DOMException(`Unknown pseudo-element ::${i}`,s.SYNTAX_ERR)}else throw new TypeError(`Unexpected ast type ${(0,h.getType)(t)}`)},D=(i,t)=>{const{name:l}=i;if(!l){let o;throw l===""?o="(empty String)":o=(0,h.getType)(l),new TypeError(`Unexpected ast type ${o}`)}const d=(0,h.getDirectionality)(t);return l===d},O=(i,t)=>{const{name:l,type:d,value:o}=i;let w;if(d===s.STRING&&o?w=o:d===s.IDENT&&l&&(w=(0,x.unescapeSelector)(l)),w==="*"){if(t.hasAttribute("lang"))return!!t.getAttribute("lang");{let m=t.parentNode,g;for(;m&&m.nodeType===s.ELEMENT_NODE;){if(m.hasAttribute("lang")){m.getAttribute("lang")&&(g=!0);break}m=m.parentNode}return!!g}}else if(w){if(new RegExp(`^(?:\\*-)?${s.ALPHA_NUM}${s.LANG_PART}$`,"i").test(w)){let g;if(w.indexOf("-")>-1){const[a,u,...c]=w.split("-");let f;a==="*"?f=`${s.ALPHA_NUM}${s.LANG_PART}`:f=`${a}${s.LANG_PART}`;const p=`-${u}${s.LANG_PART}`,e=c.length;let r="";if(e)for(let n=0;n<e;n++)r+=`-${c[n]}${s.LANG_PART}`;g=new RegExp(`^${f}${p}${r}$`,"i")}else g=new RegExp(`^${w}${s.LANG_PART}$`,"i");if(t.hasAttribute("lang"))return g.test(t.getAttribute("lang"));{let a=t.parentNode,u;for(;a&&a.nodeType===s.ELEMENT_NODE;){if(a.hasAttribute("lang")){u=g.test(a.getAttribute("lang"));break}a=a.parentNode}return!!u}}return!1}return!1},R=(i,t)=>{const{flags:l,matcher:d,name:o,value:w}=i;if(typeof l=="string"&&!/^[is]$/i.test(l)){const g=(0,x.generateCSS)(i);throw new DOMException(`Invalid selector ${g}`,s.SYNTAX_ERR)}const{attributes:m}=t;if(m&&m.length){const g=t.ownerDocument.contentType;let a;g==="text/html"?typeof l=="string"&&/^s$/i.test(l)?a=!1:a=!0:typeof l=="string"&&/^i$/i.test(l)?a=!0:a=!1;let u=(0,x.unescapeSelector)(o.name);a&&(u=u.toLowerCase());const c=new Set;if(u.indexOf("|")>-1){const{prefix:f,localName:p}=(0,x.parseAstName)(u);for(const e of m){let{name:r,value:n}=e;switch(a&&(r=r.toLowerCase(),n=n.toLowerCase()),f){case"":{p===r&&c.add(n);break}case"*":{r.indexOf(":")>-1?r.endsWith(`:${p}`)&&c.add(n):p===r&&c.add(n);break}default:if(r.indexOf(":")>-1){const[$,N]=r.split(":");if($==="xml"&&N==="lang")continue;f===$&&p===N&&(0,h.isNamespaceDeclared)(f,t)&&c.add(n)}}}}else for(let{name:f,value:p}of m)if(a&&(f=f.toLowerCase(),p=p.toLowerCase()),f.indexOf(":")>-1){const[e,r]=f.split(":");if(e==="xml"&&r==="lang")continue;u===r&&c.add(p)}else u===f&&c.add(p);if(c.size){const{name:f,value:p}=w??{};let e;switch(f?a?e=f.toLowerCase():e=f:p?a?e=p.toLowerCase():e=p:p===""&&(e=p),d){case"=":return typeof e=="string"&&c.has(e);case"~=":{if(e&&typeof e=="string"){let r;for(const n of c)if(new Set(n.split(/\s+/)).has(e)){r=!0;break}return!!r}return!1}case"|=":{if(e&&typeof e=="string"){let r;for(const n of c)if(n===e||n.startsWith(`${e}-`)){r=n;break}return!!r}return!1}case"^=":{if(e&&typeof e=="string"){let r;for(const n of c)if(n.startsWith(`${e}`)){r=n;break}return!!r}return!1}case"$=":{if(e&&typeof e=="string"){let r;for(const n of c)if(n.endsWith(`${e}`)){r=n;break}return!!r}return!1}case"*=":{if(e&&typeof e=="string"){let r;for(const n of c)if(n.includes(`${e}`)){r=n;break}return!!r}return!1}case null:default:return!0}}return!1}return!1},v=(i,t,l={})=>{const d=(0,x.unescapeSelector)(i.name),{localName:o,namespaceURI:w,prefix:m}=t,{forgive:g}=l;let{prefix:a,localName:u}=(0,x.parseAstName)(d,t);t.ownerDocument.contentType==="text/html"&&/[A-Z][\\w-]*/i.test(o)&&(a=a.toLowerCase(),u=u.toLowerCase());let c,f;switch(o.indexOf(":")>-1?[c,f]=o.split(":"):(c=m||"",f=o),a){case"":return!c&&!w&&(u==="*"||u===f);case"*":return u==="*"||u===f;default:{const p=t.lookupNamespaceURI(a),e=t.lookupNamespaceURI(c);if(p===e&&a===c)return u==="*"||u===f;if(!g&&!p)throw new DOMException(`Undeclared namespace ${a}`,s.SYNTAX_ERR);return!1}}};0&&(module.exports={matchAttributeSelector,matchDirectionPseudoClass,matchLanguagePseudoClass,matchPseudoElementSelector,matchTypeSelector});
//# sourceMappingURL=matcher.js.map

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

var S=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var L=(s,e)=>{for(var r in e)S(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&&S(s,n,{get:()=>e[n],enumerable:!(o=w(e,n))||o.enumerable});return s};var A=s=>b(S({},"__esModule",{value:!0}),s);var P={};L(P,{findAST:()=>E.find,generateCSS:()=>E.generate,parseAstName:()=>D,parseSelector:()=>h,preprocess:()=>T,sortAST:()=>F,unescapeSelector:()=>I,walkAST:()=>C});module.exports=A(P);var d=require("css-tree"),O=require("./utility.js"),t=require("./constant.js"),E=require("css-tree");const $=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/,m=/(:(is|where)\(\s*\))/,x=/^part|slotted$/,g="\uFFFD",I=(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=g;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),u=parseInt(f,t.HEX);u===0||u>=i&&u<=p?a=g:a=String.fromCodePoint(u)}catch{a=g}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},T=(...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,g)}else if(e==null)e=(0,O.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},h=s=>{if(s=T(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,t.SYNTAX_ERR);let e;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});e=(0,d.toPlainObject)(r)}catch(r){const{message:o}=r;if(o==="Identifier is expected"&&$.test(s)){const[,n,c]=$.exec(s),f=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let a=n.replace(c,f);a===":lang()"&&(a=`:lang(${t.EMPTY})`),e=h(s.replace(n,a))}else if(/^(?:Identifier|Selector) is expected$/.test(o)&&m.test(s)){const[,n,c]=m.exec(s);e=h(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=h(`${s}"]`):e=h(`${s}]`):e=h(`${s}]`)}else if(o==='")" is expected'&&!s.endsWith(")"))e=h(`${s})`);else throw new DOMException(o,t.SYNTAX_ERR)}return e},C=(s={})=>{const e=new Set,r=new Map;return(0,d.walk)(s,{enter:n=>{switch(n.type){case t.SELECTOR:{e.add(n.children);break}case t.PS_CLASS_SELECTOR:{t.KEY_LOGICAL.includes(n.name)&&(r.set("hasNestedSelector",!0),r.set("hasLogicalPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0));break}case t.PS_ELEMENT_SELECTOR:{x.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,d.findAll)(s,(n,c,f)=>{if(f){if(n.type===t.PS_CLASS_SELECTOR&&t.KEY_LOGICAL.includes(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===t.PS_CLASS_SELECTOR&&t.KEY_LOGICAL.includes(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&&x.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===t.PS_ELEMENT_SELECTOR&&x.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={findAST,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
var S=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var _=(s,e)=>{for(var r in e)S(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&&S(s,n,{get:()=>e[n],enumerable:!(o=T(e,n))||o.enumerable});return s};var C=s=>b(S({},"__esModule",{value:!0}),s);var D={};_(D,{findAST:()=>E.find,generateCSS:()=>E.generate,parseAstName:()=>I,parseSelector:()=>u,preprocess:()=>O,sortAST:()=>A,unescapeSelector:()=>F,walkAST:()=>L});module.exports=C(D);var h=require("css-tree"),w=require("./utility.js"),t=require("./constant.js"),E=require("css-tree");const m=/(?<=:(?:dir|has|host(?:-context)?|is|lang|not|nth-(?:last-)?(?:child|of-type)|where)\()\s+\)/g,x=/^part|slotted$/,g="\uFFFD",F=(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=g;else{const p=/^([\da-f]{1,6}\s?)/i.exec(n);if(p){const[,l]=p;let a;try{const i=parseInt("D800",t.HEX),f=parseInt("DFFF",t.HEX),d=parseInt(l,t.HEX);d===0||d>=i&&d<=f?a=g:a=String.fromCodePoint(d)}catch{a=g}let c="";n.length>l.length&&(c=n.substring(l.length)),n=`${a}${c}`}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 p=n.codePointAt(0);if(p===t.HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR)}else if(p>t.BIT_FFFF){const l=`\\${p.toString(t.HEX)} `;n.length===t.DUO?n=l:n=`${l}${n.substring(t.DUO)}`}e=`${o}${n}`,r++}e=e.replace(/\f|\r\n?/g,`
`).replace(/[\0\uD800-\uDFFF]|\\$/g,g)}else if(e==null)e=(0,w.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},u=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(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(o)&&!s.endsWith("]")){const n=s.lastIndexOf("["),p=s.substring(n);p.includes('"')?p.match(/"/g).length%2?e=u(`${s}"]`):e=u(`${s}]`):e=u(`${s}]`)}else if(o==='")" is expected')if(m.test(s))e=u(`${s.replaceAll(m,")")}`);else if(!s.endsWith(")"))e=u(`${s})`);else throw new DOMException(o,t.SYNTAX_ERR);else throw new DOMException(o,t.SYNTAX_ERR)}return e},L=(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.KEY_LOGICAL.includes(n.name)&&(r.set("hasNestedSelector",!0),r.set("hasLogicalPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0));break}case t.PS_ELEMENT_SELECTOR:{x.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,p,l)=>{if(l){if(n.type===t.PS_CLASS_SELECTOR&&t.KEY_LOGICAL.includes(n.name)){const a=l.filter(c=>{const{name:i,type:f}=c;return f===t.PS_CLASS_SELECTOR&&t.KEY_LOGICAL.includes(i)});for(const{children:c}of a)for(const{children:i}of c)for(const{children:f}of i)e.has(f)&&e.delete(f)}else if(n.type===t.PS_ELEMENT_SELECTOR&&x.test(n.name)){const a=l.filter(c=>{const{name:i,type:f}=c;return f===t.PS_ELEMENT_SELECTOR&&x.test(i)});for(const{children:c}of a)for(const{children:i}of c)e.has(i)&&e.delete(i)}else if(n.type===t.NTH&&n.selector){const a=l.filter(c=>{const{selector:i,type:f}=c;return f===t.NTH&&i});for(const{selector:c}of a){const{children:i}=c;for(const{children:f}of i)e.has(f)&&e.delete(f)}}}}),{branches:[...e],info:Object.fromEntries(r)}},A=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:p}=o,{type:l}=n,a=r.get(p),c=r.get(l);let i;return a===c?i=0:a>c?i=1:i=-1,i})}return e},I=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={findAST,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
//# sourceMappingURL=parser.js.map

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

var U=Object.create;var f=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var i in t)f(e,i,{get:t[i],enumerable:!0})},E=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of I(t))!k.call(e,n)&&n!==i&&f(e,n,{get:()=>t[n],enumerable:!(r=_(t,n))||r.enumerable});return e};var T=(e,t,i)=>(i=e!=null?U($(e)):{},E(t||!e||!e.__esModule?f(i,"default",{value:e,enumerable:!0}):i,e)),L=e=>E(f({},"__esModule",{value:!0}),e);var q={};A(q,{filterSelector:()=>H,getDirectionality:()=>N,getNamespaceURI:()=>C,getSlottedTextContent:()=>p,getType:()=>c,initNwsapi:()=>j,isContentEditable:()=>y,isCustomElement:()=>G,isFocusVisible:()=>V,isFocusable:()=>Y,isFocusableArea:()=>K,isInShadowTree:()=>O,isNamespaceDeclared:()=>X,isPreceding:()=>D,isVisible:()=>F,resolveContent:()=>P,sortNodes:()=>W,traverseNode:()=>v});module.exports=L(q);var h=T(require("@asamuzakjp/nwsapi"),1),g=T(require("bidi-js"),1),d=T(require("is-potential-custom-element-name"),1),s=require("./constant.js");const R=new RegExp(`:(?!${s.PSEUDO_CLASS}|${s.N_TH}|${s.LOGICAL_COMPLEX})`),S=new RegExp(`:(?!${s.PSEUDO_CLASS}|${s.N_TH}|${s.LOGICAL_COMPOUND})`),M=new RegExp(`:(?!${s.PSEUDO_CLASS}|${s.N_TH})`),c=e=>Object.prototype.toString.call(e).slice(s.TYPE_FROM,s.TYPE_TO),P=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${c(e)}`);let t,i;switch(e.nodeType){case s.DOCUMENT_NODE:{t=e,i=e;break}case s.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,i=e;break}case s.ELEMENT_NODE:{t=e.ownerDocument;let n=e;for(;n&&n.parentNode;)n=n.parentNode;i=n;break}default:throw new TypeError(`Unexpected node ${e.nodeName}`)}const r=t.createTreeWalker(i,s.WALKER_FILTER);return[t,i,r]},v=(e,t)=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${c(e)}`);let i;if(t?.currentNode){let r=t.currentNode;if(r===e)return r;if(r.contains(e))for(r=t.nextNode();r;){if(r===e)return r;r=t.nextNode()}else{if(r!==t.root)for(;r&&!(r===t.root||r===e);)r=t.parentNode();if(e.nodeType===s.ELEMENT_NODE)for(;r;){if(r===e)return r;r=t.nextNode()}else i=r}}return i??null},G=(e,t={})=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${c(e)}`);let i;if(e.nodeType===s.ELEMENT_NODE){const{localName:r,ownerDocument:n}=e,{formAssociated:a}=t,l=n.defaultView;let o;const u=e.getAttribute("is");u?o=(0,d.default)(u)&&l.customElements.get(u):o=(0,d.default)(r)&&l.customElements.get(r),o&&(a?i=o.formAssociated:i=!0)}return!!i},O=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${c(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:r,mode:n,nodeType:a,parentNode:l}=i;if(r&&n&&a===s.DOCUMENT_FRAGMENT_NODE&&(n==="close"||n==="open")){t=!0;break}i=l}}return!!t},p=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${c(e)}`);let t;if(e.localName==="slot"&&O(e)){const i=e.assignedNodes();if(i.length){for(const r of i)if(t=r.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},N=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${c(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE){const{dir:i,localName:r,parentNode:n}=e,{getEmbeddingLevels:a}=(0,g.default)();if(i==="ltr"||i==="rtl")return i;if(i==="auto"){let l;switch(r){case"input":{const o=[...s.KEY_INPUT_BUTTON,...s.KEY_INPUT_TEXT,"hidden"];if(!e.type||o.includes(e.type))l=e.value;else if(["checkbox","color","date","image","number","range","radio","time"].includes(e.type))return"ltr";break}case"slot":{l=p(e);break}case"textarea":{l=e.value;break}default:{const o=[].slice.call(e.childNodes);for(const u of o){const{dir:m,localName:b,nodeType:w,textContent:x}=u;if(w===s.TEXT_NODE?l=x.trim():w===s.ELEMENT_NODE&&!["bdi","script","style","textarea"].includes(b)&&(!m||m!=="ltr"&&m!=="rtl")&&(b==="slot"?l=p(u):l=x.trim()),l)break}}}if(l){const{paragraphs:[{level:o}]}=a(l);return o%2===1?"rtl":"ltr"}if(!t)if(n){const{nodeType:o}=n;if(o===s.ELEMENT_NODE)return N(n);if(o===s.DOCUMENT_NODE||o===s.DOCUMENT_FRAGMENT_NODE)return"ltr"}else return"ltr"}else if(r==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:o}]}=a(l);return o%2===1?"rtl":"ltr"}if(!(t||n))return"ltr"}else{if(r==="input"&&e.type==="tel")return"ltr";if(n){if(r==="slot"){const l=p(e);if(l){const{paragraphs:[{level:o}]}=a(l);return o%2===1?"rtl":"ltr"}}if(!t){const{nodeType:l}=n;if(l===s.ELEMENT_NODE)return N(n);if(l===s.DOCUMENT_NODE||l===s.DOCUMENT_FRAGMENT_NODE)return"ltr"}}else return"ltr"}}return t??null},y=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${c(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")return e.isContentEditable;if(e.ownerDocument.designMode==="on")return!0;if(e.hasAttribute("contenteditable"))switch(e.getAttribute("contenteditable")){case"":case"true":return!0;case"plaintext-only":return!0;case"false":return!1;default:{let r=e.parentNode;for(;r;){if(y(r))return!0;r=r.parentNode}break}}}return!!t},F=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const i=e.ownerDocument.defaultView,{display:r,visibility:n}=i.getComputedStyle(e);if(r!=="none"&&n==="visible")return!0}return!!t},V=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const{localName:i,type:r}=e;switch(i){case"input":{if(!r||s.KEY_INPUT_EDIT.includes(r))return!0;break}case"textarea":return!0;default:return y(e)}}return!!t},K=e=>{if(e?.nodeType===s.ELEMENT_NODE){if(!e.isConnected)return!1;const t=e.ownerDocument.defaultView;if(e instanceof t.HTMLElement){if(Number.isInteger(parseInt(e.getAttribute("tabindex")))||y(e))return!0;const{localName:i,parentNode:r}=e;switch(i){case"a":return!!(e.href||e.hasAttribute("href"));case"iframe":return!0;case"input":return!(e.disabled||e.hasAttribute("disabled")||e.hidden||e.hasAttribute("hidden"));case"summary":{if(r.localName==="details"){let n=r.firstElementChild;for(;n;){if(n.localName==="summary")return e===n;n=n.nextElementSibling}}return!1}default:return!!(new Set(["button","select","textarea"]).has(i)&&!(e.disabled||e.hasAttribute("disabled")))}}else if(e instanceof t.SVGElement){if(Number.isInteger(parseInt(e.getAttributeNS(null,"tabindex")))){const i=new Set(["clipPath","defs","desc","linearGradient","marker","mask","metadata","pattern","radialGradient","script","style","symbol","title"]),r="http://www.w3.org/2000/svg";let n,a=e;for(;a.namespaceURI===r&&(n=i.has(a.localName),!n);)if(a?.parentNode?.namespaceURI===r)a=a.parentNode;else break;return!n}if(e.localName==="a"&&(e.href||e.hasAttributeNS(null,"href")))return!0}}return!1},Y=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const i=e.ownerDocument.defaultView;let r=e;for(t=!0;r;){if(r.disabled||r.hasAttribute("disabled"))return!1;(r.hidden||r.hasAttribute("hidden"))&&(t=!1);const{contentVisibility:n,display:a,visibility:l}=i.getComputedStyle(r);if(a==="none"||l!=="visible"||n==="hidden"&&r!==e?t=!1:t=!0,t&&r?.parentNode?.nodeType===s.ELEMENT_NODE)r=r.parentNode;else break}}return!!t},C=(e,t)=>{if(typeof e!="string")throw new TypeError(`Unexpected type ${c(e)}`);if(!t?.nodeType)throw new TypeError(`Unexpected type ${c(t)}`);let i;if(e&&t.nodeType===s.ELEMENT_NODE){const{attributes:r}=t;for(const n of r){const{name:a,namespaceURI:l,prefix:o,value:u}=n;if(a===`xmlns:${e}`)return u;if(o===e)return l}}return i??null},X=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===s.ELEMENT_NODE&&(i=t.lookupNamespaceURI(e),!i)){const r=t.ownerDocument.documentElement;let n=t;for(;n&&(i=C(e,n),!(i||n===r));)n=n.parentNode}return!!i},D=(e,t)=>{if(e?.nodeType){if(!t?.nodeType)throw new TypeError(`Unexpected type ${c(t)}`)}else throw new TypeError(`Unexpected type ${c(e)}`);let i;if(e.nodeType===s.ELEMENT_NODE&&t.nodeType===s.ELEMENT_NODE){const r=t.compareDocumentPosition(e);i=r&s.DOCUMENT_POSITION_PRECEDING||r&s.DOCUMENT_POSITION_CONTAINS}return!!i},W=(e=[])=>{const t=[...e];return t.length>1&&t.sort((i,r)=>{let n;return D(r,i)?n=1:n=-1,n}),t},j=(e,t)=>{if(!e?.DOMException)throw new TypeError(`Unexpected global object ${c(e)}`);t?.nodeType!==s.DOCUMENT_NODE&&(t=e.document);const i=(0,h.default)({document:t,DOMException:e.DOMException});return i.configure({LOGERRORS:!1}),i},H=(e,t={})=>{if(!e||typeof e!="string")return!1;if(e.includes("[")){const i=e.lastIndexOf("[");if(e.substring(i).indexOf("]")<0)return!1}if(/[|\\]|::|[^\u0021-\u007F\s]|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]|:(?:is|where)\(\s*\)/.test(e))return!1;if(e.includes(":")){const{complex:i,descend:r}=t;return/:(?:is|not)\(/.test(e)?i?!R.test(e):!S.test(e):r?!1:!M.test(e)}return!0};0&&(module.exports={filterSelector,getDirectionality,getNamespaceURI,getSlottedTextContent,getType,initNwsapi,isContentEditable,isCustomElement,isFocusVisible,isFocusable,isFocusableArea,isInShadowTree,isNamespaceDeclared,isPreceding,isVisible,resolveContent,sortNodes,traverseNode});
var D=Object.create;var c=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var k=(e,r)=>{for(var t in r)c(e,t,{get:r[t],enumerable:!0})},x=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of _(r))!$.call(e,s)&&s!==t&&c(e,s,{get:()=>r[s],enumerable:!(i=U(r,s))||i.enumerable});return e};var m=(e,r,t)=>(t=e!=null?D(I(e)):{},x(r||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),A=e=>x(c({},"__esModule",{value:!0}),e);var H={};k(H,{filterSelector:()=>j,getDirectionality:()=>b,getNamespaceURI:()=>O,getSlottedTextContent:()=>p,getType:()=>o,initNwsapi:()=>W,isContentEditable:()=>y,isCustomElement:()=>v,isFocusVisible:()=>F,isFocusable:()=>K,isFocusableArea:()=>V,isInShadowTree:()=>g,isNamespaceDeclared:()=>Y,isPreceding:()=>C,isVisible:()=>G,resolveContent:()=>M,sortNodes:()=>X,traverseNode:()=>P});module.exports=A(H);var E=m(require("@asamuzakjp/nwsapi"),1),h=m(require("bidi-js"),1),T=m(require("is-potential-custom-element-name"),1),n=require("./constant.js");const L=new RegExp(`:(?!${n.PSEUDO_CLASS}|${n.N_TH}|${n.LOGICAL_COMPLEX})`),R=new RegExp(`:(?!${n.PSEUDO_CLASS}|${n.N_TH}|${n.LOGICAL_COMPOUND})`),S=new RegExp(`:(?!${n.PSEUDO_CLASS}|${n.N_TH})`),o=e=>Object.prototype.toString.call(e).slice(n.TYPE_FROM,n.TYPE_TO),M=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${o(e)}`);let r,t;switch(e.nodeType){case n.DOCUMENT_NODE:{r=e,t=e;break}case n.DOCUMENT_FRAGMENT_NODE:{r=e.ownerDocument,t=e;break}case n.ELEMENT_NODE:{r=e.ownerDocument;let s=e;for(;s&&s.parentNode;)s=s.parentNode;t=s;break}default:throw new TypeError(`Unexpected node ${e.nodeName}`)}const i=r.createTreeWalker(t,n.WALKER_FILTER);return[r,t,i]},P=(e,r)=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${o(e)}`);if(!r)return null;let t=r.currentNode;if(t===e)return t;if(t.contains(e)){for(t=r.nextNode();t&&t!==e;)t=r.nextNode();return t}else{if(t!==r.root)for(;t&&!(t===r.root||t===e);)t=r.parentNode();if(e.nodeType===n.ELEMENT_NODE){let i;for(;t;){if(t===e){i=!0;break}t=r.nextNode()}return i?t:null}else return t}},v=(e,r={})=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${o(e)}`);if(e.nodeType!==n.ELEMENT_NODE)return!1;const{localName:t,ownerDocument:i}=e,{formAssociated:s}=r,l=i.defaultView;let a;const u=e.getAttribute("is");return u?a=(0,T.default)(u)&&l.customElements.get(u):a=(0,T.default)(t)&&l.customElements.get(t),a?s?!!a.formAssociated:!0:!1},g=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${o(e)}`);if(e.nodeType!==n.ELEMENT_NODE&&e.nodeType!==n.DOCUMENT_FRAGMENT_NODE)return!1;let r=e,t=!1;for(;r;){const{host:i,mode:s,nodeType:l,parentNode:a}=r;if(i&&s&&l===n.DOCUMENT_FRAGMENT_NODE&&(s==="close"||s==="open")){t=!0;break}r=a}return t},p=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${o(e)}`);if(e.localName!=="slot"||!g(e))return null;const r=e.assignedNodes();if(r.length){let t;for(const i of r)if(t=i.textContent.trim(),t)break;return t}return e.textContent.trim()},b=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${o(e)}`);if(e.nodeType!==n.ELEMENT_NODE)return null;const{dir:r,localName:t,parentNode:i}=e,{getEmbeddingLevels:s}=(0,h.default)();if(r==="ltr"||r==="rtl")return r;if(r==="auto"){let l;switch(t){case"input":{const a=[...n.KEY_INPUT_BUTTON,...n.KEY_INPUT_TEXT,"hidden"];if(!e.type||a.includes(e.type))l=e.value;else if(["checkbox","color","date","image","number","range","radio","time"].includes(e.type))return"ltr";break}case"slot":{l=p(e);break}case"textarea":{l=e.value;break}default:{const a=[].slice.call(e.childNodes);for(const u of a){const{dir:f,localName:d,nodeType:N,textContent:w}=u;if(N===n.TEXT_NODE?l=w.trim():N===n.ELEMENT_NODE&&!["bdi","script","style","textarea"].includes(d)&&(!f||f!=="ltr"&&f!=="rtl")&&(d==="slot"?l=p(u):l=w.trim()),l)break}}}if(l){const{paragraphs:[{level:a}]}=s(l);return a%2===1?"rtl":"ltr"}else if(i){const{nodeType:a}=i;return a===n.ELEMENT_NODE?b(i):"ltr"}return"ltr"}else if(t==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:a}]}=s(l);return a%2===1?"rtl":"ltr"}return"ltr"}else{if(t==="input"&&e.type==="tel")return"ltr";if(i){if(t==="slot"){const a=p(e);if(a){const{paragraphs:[{level:u}]}=s(a);return u%2===1?"rtl":"ltr"}}const{nodeType:l}=i;return l===n.ELEMENT_NODE?b(i):"ltr"}}return"ltr"},y=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${o(e)}`);if(e.nodeType!==n.ELEMENT_NODE)return!1;if(typeof e.isContentEditable=="boolean")return e.isContentEditable;if(e.ownerDocument.designMode==="on")return!0;if(e.hasAttribute("contenteditable"))switch(e.getAttribute("contenteditable")){case"":case"true":return!0;case"plaintext-only":return!0;case"false":return!1;default:{let t=e.parentNode,i=!1;for(;t;){if(y(t)){i=!0;break}t=t.parentNode}return i}}return!1},G=e=>{if(e?.nodeType!==n.ELEMENT_NODE)return!1;const r=e.ownerDocument.defaultView,{display:t,visibility:i}=r.getComputedStyle(e);return t!=="none"&&i==="visible"},F=e=>{if(e?.nodeType!==n.ELEMENT_NODE)return!1;const{localName:r,type:t}=e;switch(r){case"input":return!!(!t||n.KEY_INPUT_EDIT.includes(t));case"textarea":return!0;default:return y(e)}},V=e=>{if(e?.nodeType!==n.ELEMENT_NODE||!e.isConnected)return!1;const r=e.ownerDocument.defaultView;if(e instanceof r.HTMLElement){if(Number.isInteger(parseInt(e.getAttribute("tabindex")))||y(e))return!0;const{localName:t,parentNode:i}=e;switch(t){case"a":return!!(e.href||e.hasAttribute("href"));case"iframe":return!0;case"input":return!(e.disabled||e.hasAttribute("disabled")||e.hidden||e.hasAttribute("hidden"));case"summary":{if(i.localName==="details"){let s=i.firstElementChild;for(;s;){if(s.localName==="summary")return e===s;s=s.nextElementSibling}}return!1}default:return!!(["button","select","textarea"].includes(t)&&!(e.disabled||e.hasAttribute("disabled")))}}else if(e instanceof r.SVGElement){if(Number.isInteger(parseInt(e.getAttributeNS(null,"tabindex")))){const t=["clipPath","defs","desc","linearGradient","marker","mask","metadata","pattern","radialGradient","script","style","symbol","title"],i="http://www.w3.org/2000/svg";let s,l=e;for(;l.namespaceURI===i&&(s=t.includes(l.localName),!s);)if(l?.parentNode?.namespaceURI===i)l=l.parentNode;else break;return!s}return!!(e.localName==="a"&&(e.href||e.hasAttributeNS(null,"href")))}return!1},K=e=>{if(e?.nodeType!==n.ELEMENT_NODE)return!1;const r=e.ownerDocument.defaultView;let t=e,i=!0;for(;t;){if(t.disabled||t.hasAttribute("disabled")){i=!1;break}(t.hidden||t.hasAttribute("hidden"))&&(i=!1);const{contentVisibility:s,display:l,visibility:a}=r.getComputedStyle(t);if(l==="none"||a!=="visible"||s==="hidden"&&t!==e?i=!1:i=!0,i&&t?.parentNode?.nodeType===n.ELEMENT_NODE)t=t.parentNode;else break}return i},O=(e,r)=>{if(typeof e!="string")throw new TypeError(`Unexpected type ${o(e)}`);if(!r?.nodeType)throw new TypeError(`Unexpected type ${o(r)}`);if(!e||r.nodeType!==n.ELEMENT_NODE)return null;const{attributes:t}=r;let i;for(const s of t){const{name:l,namespaceURI:a,prefix:u,value:f}=s;if(l===`xmlns:${e}`?i=f:u===e&&(i=a),i)break}return i??null},Y=(e="",r={})=>{if(!e||typeof e!="string"||r?.nodeType!==n.ELEMENT_NODE)return!1;if(r.lookupNamespaceURI(e))return!0;const t=r.ownerDocument.documentElement;let i=r,s;for(;i&&(s=O(e,i),!(s||i===t));)i=i.parentNode;return!!s},C=(e,r)=>{if(e?.nodeType){if(!r?.nodeType)throw new TypeError(`Unexpected type ${o(r)}`)}else throw new TypeError(`Unexpected type ${o(e)}`);if(e.nodeType!==n.ELEMENT_NODE||r.nodeType!==n.ELEMENT_NODE)return!1;const t=r.compareDocumentPosition(e);return!!(t&n.DOCUMENT_POSITION_PRECEDING||t&n.DOCUMENT_POSITION_CONTAINS)},X=(e=[])=>{const r=[...e];return r.length>1&&r.sort((t,i)=>{let s;return C(i,t)?s=1:s=-1,s}),r},W=(e,r)=>{if(!e?.DOMException)throw new TypeError(`Unexpected global object ${o(e)}`);r?.nodeType!==n.DOCUMENT_NODE&&(r=e.document);const t=(0,E.default)({document:r,DOMException:e.DOMException});return t.configure({LOGERRORS:!1}),t},j=(e,r={})=>{if(!e||typeof e!="string")return!1;if(e.includes("[")){const t=e.lastIndexOf("[");if(e.substring(t).indexOf("]")<0)return!1}if(/[|\\]|::|[^\u0021-\u007F\s]|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]|:(?:is|where)\(\s*\)/.test(e))return!1;if(e.includes(":")){const{complex:t,descend:i}=r;return/:(?:is|not)\(/.test(e)?t?!L.test(e):!R.test(e):i?!1:!S.test(e)}return!0};0&&(module.exports={filterSelector,getDirectionality,getNamespaceURI,getSlottedTextContent,getType,initNwsapi,isContentEditable,isCustomElement,isFocusVisible,isFocusable,isFocusableArea,isInShadowTree,isNamespaceDeclared,isPreceding,isVisible,resolveContent,sortNodes,traverseNode});
//# sourceMappingURL=utility.js.map

@@ -28,3 +28,3 @@ {

"bidi-js": "^1.0.3",
"css-tree": "^2.3.1",
"css-tree": "^3.0.0",
"is-potential-custom-element-name": "^1.0.1"

@@ -42,10 +42,10 @@ },

"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jsdoc": "^50.2.2",
"eslint-plugin-jsdoc": "^50.2.3",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-unicorn": "^55.0.0",
"happy-dom": "^15.7.3",
"happy-dom": "^15.7.4",
"jsdom": "^25.0.0",
"linkedom": "^0.18.4",
"mocha": "^10.7.3",
"sinon": "^18.0.1",
"sinon": "^19.0.2",
"typescript": "^5.6.2",

@@ -68,3 +68,3 @@ "wpt-runner": "^5.0.0"

},
"version": "6.0.5"
"version": "6.1.0"
}

@@ -90,2 +90,82 @@ # DOM Selector

## Monkey patch jsdom
``` javascript
import { DOMSelector } from '@asamuzakjp/dom-selector';
import { JSDOM } from 'jsdom';
const dom = new JSDOM('', {
runScripts: 'dangerously',
url: 'http://localhost/',
beforeParse: window => {
const domSelector = new DOMSelector(window);
const matches = domSelector.matches.bind(domSelector);
window.Element.prototype.matches = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return matches(selector, this);
};
const closest = domSelector.closest.bind(domSelector);
window.Element.prototype.closest = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return closest(selector, this);
};
const querySelector = domSelector.querySelector.bind(domSelector);
window.Document.prototype.querySelector = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelector(selector, this);
};
window.DocumentFragment.prototype.querySelector = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelector(selector, this);
};
window.Element.prototype.querySelector = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelector(selector, this);
};
const querySelectorAll = domSelector.querySelectorAll.bind(domSelector);
window.Document.prototype.querySelectorAll = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelectorAll(selector, this);
};
window.DocumentFragment.prototype.querySelectorAll = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelectorAll(selector, this);
};
window.Element.prototype.querySelectorAll = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelectorAll(selector, this);
};
}
});
```
## Supported CSS selectors

@@ -117,3 +197,3 @@

|E:dir(ltr)|✓| |
|E:lang(en)|Partially supported|Comma-separated list of language codes, e.g. `:lang(en, fr)`, is not yet supported.|
|E:lang(en)|✓| |
|E:any&#8209;link|✓| |

@@ -203,82 +283,2 @@ |E:link|✓| |

## Monkey patch jsdom
``` javascript
import { DOMSelector } from '@asamuzakjp/dom-selector';
import { JSDOM } from 'jsdom';
const dom = new JSDOM('', {
runScripts: 'dangerously',
url: 'http://localhost/',
beforeParse: window => {
const domSelector = new DOMSelector(window);
const matches = domSelector.matches.bind(domSelector);
window.Element.prototype.matches = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return matches(selector, this);
};
const closest = domSelector.closest.bind(domSelector);
window.Element.prototype.closest = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return closest(selector, this);
};
const querySelector = domSelector.querySelector.bind(domSelector);
window.Document.prototype.querySelector = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelector(selector, this);
};
window.DocumentFragment.prototype.querySelector = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelector(selector, this);
};
window.Element.prototype.querySelector = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelector(selector, this);
};
const querySelectorAll = domSelector.querySelectorAll.bind(domSelector);
window.Document.prototype.querySelectorAll = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelectorAll(selector, this);
};
window.DocumentFragment.prototype.querySelectorAll = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelectorAll(selector, this);
};
window.Element.prototype.querySelectorAll = function (...args) {
if (!args.length) {
throw new window.TypeError('1 argument required, but only 0 present.');
}
const [selector] = args;
return querySelectorAll(selector, this);
};
}
});
```
## Performance

@@ -285,0 +285,0 @@

@@ -9,3 +9,2 @@ /**

export const COMBINATOR = 'Combinator';
export const EMPTY = '__EMPTY__';
export const IDENT = 'Identifier';

@@ -15,5 +14,7 @@ export const ID_SELECTOR = 'IdSelector';

export const NTH = 'Nth';
export const OPERATOR = 'Operator';
export const PS_CLASS_SELECTOR = 'PseudoClassSelector';
export const PS_ELEMENT_SELECTOR = 'PseudoElementSelector';
export const SELECTOR = 'Selector';
export const STRING = 'String';
export const SYNTAX_ERR = 'SyntaxError';

@@ -107,1 +108,5 @@ export const TARGET_ALL = 'all';

export const KEY_LOGICAL = Object.freeze(['has', 'is', 'not', 'where']);
export const KEY_MODIFIER = Object.freeze([
'Alt', 'AltGraph', 'CapsLock', 'Control', 'Fn', 'FnLock', 'Hyper', 'Meta',
'NumLock', 'ScrollLock', 'Shift', 'Super', 'Symbol', 'SymbolLock'
]);

@@ -11,22 +11,19 @@ /**

import {
ALPHA_NUM, ATTR_SELECTOR, ELEMENT_NODE, EMPTY, LANG_PART, NOT_SUPPORTED_ERR,
SYNTAX_ERR, TYPE_SELECTOR
ALPHA_NUM, ELEMENT_NODE, IDENT, LANG_PART, NOT_SUPPORTED_ERR,
PS_ELEMENT_SELECTOR, STRING, SYNTAX_ERR
} from './constant.js';
/* Matcher */
export class Matcher {
/**
* match pseudo-element selector
* @param {string} astName - AST name
* @param {object} opt - options
* @param {boolean} [opt.forgive] - forgive unknown pseudo-element
* @param {boolean} [opt.warn] - warn unsupported pseudo-element
* @throws {DOMException}
* @returns {void}
*/
matchPseudoElementSelector(astName, opt = {}) {
if (!astName || typeof astName !== 'string') {
throw new TypeError(`Unexpected type ${getType(astName)}`);
}
const { forgive, warn } = opt;
/**
* match pseudo-element selector
* @param {string} astName - AST name
* @param {string} astType - AST type
* @param {object} opt - options
* @param {boolean} [opt.forgive] - forgive unknown pseudo-element
* @param {boolean} [opt.warn] - warn unsupported pseudo-element
* @throws {DOMException}
* @returns {void}
*/
export const matchPseudoElementSelector = (astName, astType, opt = {}) => {
const { forgive, warn } = opt;
if (astType === PS_ELEMENT_SELECTOR) {
switch (astName) {

@@ -71,417 +68,383 @@ case 'after':

}
} else {
throw new TypeError(`Unexpected ast type ${getType(astType)}`);
}
};
/**
* match attribute selector
* @private
* @param {object} ast - AST
* @param {object} node - Element node
* @returns {?object} - matched node
*/
_matchAttributeSelector(ast, node) {
const {
flags: astFlags, matcher: astMatcher, name: astName, value: astValue
} = ast;
if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {
const css = generateCSS(ast);
throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);
/**
* match directionality pseudo-class - :dir()
* @param {object} ast - AST
* @param {object} node - Element node
* @returns {boolean} - result
*/
export const matchDirectionPseudoClass = (ast, node) => {
const { name } = ast;
if (!name) {
let type;
if (name === '') {
type = '(empty String)';
} else {
type = getType(name);
}
const { attributes } = node;
let res;
if (attributes && attributes.length) {
const contentType = node.ownerDocument.contentType;
let caseInsensitive;
if (contentType === 'text/html') {
if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {
caseInsensitive = false;
throw new TypeError(`Unexpected ast type ${type}`);
}
const dir = getDirectionality(node);
return name === dir;
};
/**
* match language pseudo-class - :lang()
* @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1
* @param {object} ast - AST
* @param {object} node - Element node
* @returns {boolean} - result
*/
export const matchLanguagePseudoClass = (ast, node) => {
const { name, type, value } = ast;
let astName;
if (type === STRING && value) {
astName = value;
} else if (type === IDENT && name) {
astName = unescapeSelector(name);
}
if (astName === '*') {
if (node.hasAttribute('lang')) {
if (node.getAttribute('lang')) {
return true;
}
return false;
} else {
let parent = node.parentNode;
let res;
while (parent) {
if (parent.nodeType === ELEMENT_NODE) {
if (parent.hasAttribute('lang')) {
if (parent.getAttribute('lang')) {
res = true;
}
break;
}
parent = parent.parentNode;
} else {
caseInsensitive = true;
break;
}
} else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {
caseInsensitive = true;
} else {
caseInsensitive = false;
}
let astAttrName = unescapeSelector(astName.name);
if (caseInsensitive) {
astAttrName = astAttrName.toLowerCase();
}
const attrValues = new Set();
// namespaced
if (astAttrName.indexOf('|') > -1) {
const {
prefix: astPrefix, localName: astLocalName
} = parseAstName(astAttrName);
for (const item of attributes) {
let { name: itemName, value: itemValue } = item;
if (caseInsensitive) {
itemName = itemName.toLowerCase();
itemValue = itemValue.toLowerCase();
return !!res;
}
} else if (astName) {
const reg = new RegExp(`^(?:\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');
if (reg.test(astName)) {
let regExtendedLang;
if (astName.indexOf('-') > -1) {
const [langMain, langSub, ...langRest] = astName.split('-');
let extendedMain;
if (langMain === '*') {
extendedMain = `${ALPHA_NUM}${LANG_PART}`;
} else {
extendedMain = `${langMain}${LANG_PART}`;
}
const extendedSub = `-${langSub}${LANG_PART}`;
const len = langRest.length;
let extendedRest = '';
if (len) {
for (let i = 0; i < len; i++) {
extendedRest += `-${langRest[i]}${LANG_PART}`;
}
switch (astPrefix) {
case '': {
if (astLocalName === itemName) {
attrValues.add(itemValue);
}
break;
}
case '*': {
if (itemName.indexOf(':') > -1) {
if (itemName.endsWith(`:${astLocalName}`)) {
attrValues.add(itemValue);
}
} else if (astLocalName === itemName) {
attrValues.add(itemValue);
}
break;
}
default: {
if (itemName.indexOf(':') > -1) {
const [itemPrefix, itemLocalName] = itemName.split(':');
// ignore xml:lang
if (itemPrefix === 'xml' && itemLocalName === 'lang') {
continue;
} else if (astPrefix === itemPrefix &&
astLocalName === itemLocalName) {
const namespaceDeclared =
isNamespaceDeclared(astPrefix, node);
if (namespaceDeclared) {
attrValues.add(itemValue);
}
}
}
}
}
}
regExtendedLang =
new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');
} else {
for (let { name: itemName, value: itemValue } of attributes) {
if (caseInsensitive) {
itemName = itemName.toLowerCase();
itemValue = itemValue.toLowerCase();
}
if (itemName.indexOf(':') > -1) {
const [itemPrefix, itemLocalName] = itemName.split(':');
// ignore xml:lang
if (itemPrefix === 'xml' && itemLocalName === 'lang') {
continue;
} else if (astAttrName === itemLocalName) {
attrValues.add(itemValue);
regExtendedLang = new RegExp(`^${astName}${LANG_PART}$`, 'i');
}
if (node.hasAttribute('lang')) {
return regExtendedLang.test(node.getAttribute('lang'));
} else {
let parent = node.parentNode;
let res;
while (parent) {
if (parent.nodeType === ELEMENT_NODE) {
if (parent.hasAttribute('lang')) {
res = regExtendedLang.test(parent.getAttribute('lang'));
break;
}
} else if (astAttrName === itemName) {
attrValues.add(itemValue);
parent = parent.parentNode;
} else {
break;
}
}
return !!res;
}
if (attrValues.size) {
const { name: astIdentValue, value: astStringValue } = astValue ?? {};
let attrValue;
if (astIdentValue) {
if (caseInsensitive) {
attrValue = astIdentValue.toLowerCase();
} else {
attrValue = astIdentValue;
}
} else if (astStringValue) {
if (caseInsensitive) {
attrValue = astStringValue.toLowerCase();
} else {
attrValue = astStringValue;
}
} else if (astStringValue === '') {
attrValue = astStringValue;
}
return false;
}
return false;
};
/**
* match attribute selector
* @param {object} ast - AST
* @param {object} node - Element node
* @returns {boolean} - result
*/
export const matchAttributeSelector = (ast, node) => {
const {
flags: astFlags, matcher: astMatcher, name: astName, value: astValue
} = ast;
if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {
const css = generateCSS(ast);
throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);
}
const { attributes } = node;
if (attributes && attributes.length) {
const contentType = node.ownerDocument.contentType;
let caseInsensitive;
if (contentType === 'text/html') {
if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {
caseInsensitive = false;
} else {
caseInsensitive = true;
}
} else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {
caseInsensitive = true;
} else {
caseInsensitive = false;
}
let astAttrName = unescapeSelector(astName.name);
if (caseInsensitive) {
astAttrName = astAttrName.toLowerCase();
}
const attrValues = new Set();
// namespaced
if (astAttrName.indexOf('|') > -1) {
const {
prefix: astPrefix, localName: astLocalName
} = parseAstName(astAttrName);
for (const item of attributes) {
let { name: itemName, value: itemValue } = item;
if (caseInsensitive) {
itemName = itemName.toLowerCase();
itemValue = itemValue.toLowerCase();
}
switch (astMatcher) {
case '=': {
if (typeof attrValue === 'string' && attrValues.has(attrValue)) {
res = node;
switch (astPrefix) {
case '': {
if (astLocalName === itemName) {
attrValues.add(itemValue);
}
break;
}
case '~=': {
if (attrValue && typeof attrValue === 'string') {
for (const value of attrValues) {
const item = new Set(value.split(/\s+/));
if (item.has(attrValue)) {
res = node;
break;
}
case '*': {
if (itemName.indexOf(':') > -1) {
if (itemName.endsWith(`:${astLocalName}`)) {
attrValues.add(itemValue);
}
} else if (astLocalName === itemName) {
attrValues.add(itemValue);
}
break;
}
case '|=': {
if (attrValue && typeof attrValue === 'string') {
let item;
for (const value of attrValues) {
if (value === attrValue || value.startsWith(`${attrValue}-`)) {
item = value;
break;
default: {
if (itemName.indexOf(':') > -1) {
const [itemPrefix, itemLocalName] = itemName.split(':');
// ignore xml:lang
if (itemPrefix === 'xml' && itemLocalName === 'lang') {
continue;
} else if (astPrefix === itemPrefix &&
astLocalName === itemLocalName) {
const namespaceDeclared =
isNamespaceDeclared(astPrefix, node);
if (namespaceDeclared) {
attrValues.add(itemValue);
}
}
if (item) {
res = node;
}
}
break;
}
case '^=': {
if (attrValue && typeof attrValue === 'string') {
let item;
for (const value of attrValues) {
if (value.startsWith(`${attrValue}`)) {
item = value;
break;
}
}
if (item) {
res = node;
}
}
break;
}
case '$=': {
if (attrValue && typeof attrValue === 'string') {
let item;
for (const value of attrValues) {
if (value.endsWith(`${attrValue}`)) {
item = value;
break;
}
}
if (item) {
res = node;
}
}
break;
}
case '*=': {
if (attrValue && typeof attrValue === 'string') {
let item;
for (const value of attrValues) {
if (value.includes(`${attrValue}`)) {
item = value;
break;
}
}
if (item) {
res = node;
}
}
break;
}
case null:
default: {
res = node;
}
}
}
}
return res ?? null;
}
/**
* match type selector
* @private
* @param {object} ast - AST
* @param {object} node - Element node
* @param {object} opt - options
* @param {boolean} [opt.forgive] - forgive undeclared namespace
* @returns {?object} - matched node
*/
_matchTypeSelector(ast, node, opt = {}) {
const astName = unescapeSelector(ast.name);
const { localName, namespaceURI, prefix } = node;
const { forgive } = opt;
let {
prefix: astPrefix, localName: astLocalName
} = parseAstName(astName, node);
if (node.ownerDocument.contentType === 'text/html' &&
/[A-Z][\\w-]*/i.test(localName)) {
astPrefix = astPrefix.toLowerCase();
astLocalName = astLocalName.toLowerCase();
}
let nodePrefix;
let nodeLocalName;
// just in case that the namespaced content is parsed as text/html
if (localName.indexOf(':') > -1) {
[nodePrefix, nodeLocalName] = localName.split(':');
} else {
nodePrefix = prefix || '';
nodeLocalName = localName;
}
let res;
switch (astPrefix) {
case '': {
if (!nodePrefix && !namespaceURI &&
(astLocalName === '*' || astLocalName === nodeLocalName)) {
res = node;
for (let { name: itemName, value: itemValue } of attributes) {
if (caseInsensitive) {
itemName = itemName.toLowerCase();
itemValue = itemValue.toLowerCase();
}
break;
}
case '*': {
if (astLocalName === '*' || astLocalName === nodeLocalName) {
res = node;
}
break;
}
default: {
const astNS = node.lookupNamespaceURI(astPrefix);
const nodeNS = node.lookupNamespaceURI(nodePrefix);
if (astNS === nodeNS && astPrefix === nodePrefix) {
if (astLocalName === '*' || astLocalName === nodeLocalName) {
res = node;
if (itemName.indexOf(':') > -1) {
const [itemPrefix, itemLocalName] = itemName.split(':');
// ignore xml:lang
if (itemPrefix === 'xml' && itemLocalName === 'lang') {
continue;
} else if (astAttrName === itemLocalName) {
attrValues.add(itemValue);
}
} else if (!forgive && !astNS) {
throw new DOMException(`Undeclared namespace ${astPrefix}`,
SYNTAX_ERR);
} else if (astAttrName === itemName) {
attrValues.add(itemValue);
}
}
}
return res ?? null;
};
/**
* match directionality pseudo-class - :dir()
* @private
* @param {object} ast - AST
* @param {object} node - Element node
* @returns {?object} - matched node
*/
_matchDirectionPseudoClass(ast, node) {
const dir = getDirectionality(node);
let res;
if (ast.name === dir) {
res = node;
}
return res ?? null;
}
/**
* match language pseudo-class - :lang()
* @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1
* @private
* @param {object} ast - AST
* @param {object} node - Element node
* @returns {?object} - matched node
*/
_matchLanguagePseudoClass(ast, node) {
if (ast.name === EMPTY) {
return null;
}
const astName = unescapeSelector(ast.name);
if (typeof astName === 'string' && astName !== ast.name) {
ast.name = astName;
}
let res;
if (astName === '*') {
if (node.hasAttribute('lang')) {
if (node.getAttribute('lang')) {
res = node;
if (attrValues.size) {
const { name: astIdentValue, value: astStringValue } = astValue ?? {};
let attrValue;
if (astIdentValue) {
if (caseInsensitive) {
attrValue = astIdentValue.toLowerCase();
} else {
attrValue = astIdentValue;
}
} else {
let parent = node.parentNode;
while (parent) {
if (parent.nodeType === ELEMENT_NODE) {
if (parent.hasAttribute('lang')) {
if (parent.getAttribute('lang')) {
res = node;
} else if (astStringValue) {
if (caseInsensitive) {
attrValue = astStringValue.toLowerCase();
} else {
attrValue = astStringValue;
}
} else if (astStringValue === '') {
attrValue = astStringValue;
}
switch (astMatcher) {
case '=': {
return typeof attrValue === 'string' && attrValues.has(attrValue);
}
case '~=': {
if (attrValue && typeof attrValue === 'string') {
let res;
for (const value of attrValues) {
const item = new Set(value.split(/\s+/));
if (item.has(attrValue)) {
res = true;
break;
}
break;
}
parent = parent.parentNode;
} else {
break;
return !!res;
}
return false;
}
}
} else if (astName) {
const reg = new RegExp(`^(?:\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');
if (reg.test(astName)) {
let regExtendedLang;
if (astName.indexOf('-') > -1) {
const [langMain, langSub, ...langRest] = astName.split('-');
let extendedMain;
if (langMain === '*') {
extendedMain = `${ALPHA_NUM}${LANG_PART}`;
} else {
extendedMain = `${langMain}${LANG_PART}`;
case '|=': {
if (attrValue && typeof attrValue === 'string') {
let item;
for (const value of attrValues) {
if (value === attrValue || value.startsWith(`${attrValue}-`)) {
item = value;
break;
}
}
if (item) {
return true;
}
return false;
}
const extendedSub = `-${langSub}${LANG_PART}`;
const len = langRest.length;
let extendedRest = '';
if (len) {
for (let i = 0; i < len; i++) {
extendedRest += `-${langRest[i]}${LANG_PART}`;
return false;
}
case '^=': {
if (attrValue && typeof attrValue === 'string') {
let item;
for (const value of attrValues) {
if (value.startsWith(`${attrValue}`)) {
item = value;
break;
}
}
if (item) {
return true;
}
return false;
}
regExtendedLang =
new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');
} else {
regExtendedLang = new RegExp(`^${astName}${LANG_PART}$`, 'i');
return false;
}
if (node.hasAttribute('lang')) {
if (regExtendedLang.test(node.getAttribute('lang'))) {
res = node;
case '$=': {
if (attrValue && typeof attrValue === 'string') {
let item;
for (const value of attrValues) {
if (value.endsWith(`${attrValue}`)) {
item = value;
break;
}
}
if (item) {
return true;
}
return false;
}
} else {
let parent = node.parentNode;
while (parent) {
if (parent.nodeType === ELEMENT_NODE) {
if (parent.hasAttribute('lang')) {
const value = parent.getAttribute('lang');
if (regExtendedLang.test(value)) {
res = node;
}
return false;
}
case '*=': {
if (attrValue && typeof attrValue === 'string') {
let item;
for (const value of attrValues) {
if (value.includes(`${attrValue}`)) {
item = value;
break;
}
parent = parent.parentNode;
} else {
break;
}
if (item) {
return true;
}
return false;
}
return false;
}
case null:
default: {
return true;
}
}
}
return res ?? null;
return false;
}
return false;
};
/**
* match selector
* @param {object} ast - AST
* @param {object} node - Element node
* @param {object} opt - options
* @param {boolean} validated - args are validated
* @returns {?object} - matched node
*/
matchSelector(ast, node, opt = {}, validated = false) {
if (!validated) {
if (!ast || !ast.type) {
throw new TypeError(`Unexpected ast type ${getType(ast)}`);
} else if (!node || !node.nodeType) {
throw new TypeError(`Unexpected node type ${getType(node)}`);
} else if (node.nodeType !== ELEMENT_NODE) {
throw new TypeError(`Unexpected node ${node.nodeName}`);
/**
* match type selector
* @param {object} ast - AST
* @param {object} node - Element node
* @param {object} opt - options
* @param {boolean} [opt.forgive] - forgive undeclared namespace
* @returns {boolean} - result
*/
export const matchTypeSelector = (ast, node, opt = {}) => {
const astName = unescapeSelector(ast.name);
const { localName, namespaceURI, prefix } = node;
const { forgive } = opt;
let {
prefix: astPrefix, localName: astLocalName
} = parseAstName(astName, node);
if (node.ownerDocument.contentType === 'text/html' &&
/[A-Z][\\w-]*/i.test(localName)) {
astPrefix = astPrefix.toLowerCase();
astLocalName = astLocalName.toLowerCase();
}
let nodePrefix;
let nodeLocalName;
// just in case that the namespaced content is parsed as text/html
if (localName.indexOf(':') > -1) {
[nodePrefix, nodeLocalName] = localName.split(':');
} else {
nodePrefix = prefix || '';
nodeLocalName = localName;
}
switch (astPrefix) {
case '': {
if (!nodePrefix && !namespaceURI &&
(astLocalName === '*' || astLocalName === nodeLocalName)) {
return true;
}
return false;
}
let matched;
switch (ast.type) {
case ATTR_SELECTOR: {
matched = this._matchAttributeSelector(ast, node);
break;
case '*': {
if (astLocalName === '*' || astLocalName === nodeLocalName) {
return true;
}
case TYPE_SELECTOR: {
matched = this._matchTypeSelector(ast, node, opt ?? {});
break;
}
default: {
const { children: [child], name: astName } = ast;
if (astName === 'dir') {
matched = this._matchDirectionPseudoClass(child, node);
} else if (astName === 'lang') {
matched = this._matchLanguagePseudoClass(child, node);
return false;
}
default: {
const astNS = node.lookupNamespaceURI(astPrefix);
const nodeNS = node.lookupNamespaceURI(nodePrefix);
if (astNS === nodeNS && astPrefix === nodePrefix) {
if (astLocalName === '*' || astLocalName === nodeLocalName) {
return true;
}
return false;
} else if (!forgive && !astNS) {
throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);
}
return false;
}
return matched;
}
}
};

@@ -12,8 +12,7 @@ /**

ATTR_SELECTOR, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF,
CLASS_SELECTOR, DUO, EMPTY, HEX, HYPHEN, ID_SELECTOR, KEY_LOGICAL, NTH,
CLASS_SELECTOR, DUO, HEX, HYPHEN, ID_SELECTOR, KEY_LOGICAL, NTH,
PS_CLASS_SELECTOR, PS_ELEMENT_SELECTOR, SELECTOR, SYNTAX_ERR, TYPE_SELECTOR
} from './constant.js';
const REG_LANG_QUOTED = /(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;
const REG_LOGICAL_EMPTY = /(:(is|where)\(\s*\))/;
const REG_SHADOW_PSEUDO = /^part|slotted$/;
const REG_EMPTY_PSEUDO_FUNC = /(?<=:(?:dir|has|host(?:-context)?|is|lang|not|nth-(?:last-)?(?:child|of-type)|where)\()\s+\)/g;
const REG_SHADOW_PS_ELEMENT = /^part|slotted$/;
const U_FFFD = '\uFFFD';

@@ -144,19 +143,4 @@

const { message } = e;
// workaround for https://github.com/csstree/csstree/issues/265
if (message === 'Identifier is expected' &&
REG_LANG_QUOTED.test(selector)) {
const [, lang, range] = REG_LANG_QUOTED.exec(selector);
const escapedRange =
range.replaceAll('*', '\\*').replace(/^"/, '').replace(/"$/, '');
let escapedLang = lang.replace(range, escapedRange);
if (escapedLang === ':lang()') {
escapedLang = `:lang(${EMPTY})`;
}
res = parseSelector(selector.replace(lang, escapedLang));
} else if (/^(?:Identifier|Selector) is expected$/.test(message) &&
REG_LOGICAL_EMPTY.test(selector)) {
const [, sel, name] = REG_LOGICAL_EMPTY.exec(selector);
res = parseSelector(selector.replace(sel, `:${name}(${EMPTY})`));
} else if (/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(message) &&
!selector.endsWith(']')) {
if (/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(message) &&
!selector.endsWith(']')) {
const index = selector.lastIndexOf('[');

@@ -174,4 +158,12 @@ const sel = selector.substring(index);

}
} else if (message === '")" is expected' && !selector.endsWith(')')) {
res = parseSelector(`${selector})`);
} else if (message === '")" is expected') {
// workaround for https://github.com/csstree/csstree/issues/283
if (REG_EMPTY_PSEUDO_FUNC.test(selector)) {
res =
parseSelector(`${selector.replaceAll(REG_EMPTY_PSEUDO_FUNC, ')')}`);
} else if (!selector.endsWith(')')) {
res = parseSelector(`${selector})`);
} else {
throw new DOMException(message, SYNTAX_ERR);
}
} else {

@@ -210,3 +202,3 @@ throw new DOMException(message, SYNTAX_ERR);

case PS_ELEMENT_SELECTOR: {
if (REG_SHADOW_PSEUDO.test(node.name)) {
if (REG_SHADOW_PS_ELEMENT.test(node.name)) {
info.set('hasNestedSelector', true);

@@ -249,7 +241,7 @@ }

} else if (node.type === PS_ELEMENT_SELECTOR &&
REG_SHADOW_PSEUDO.test(node.name)) {
REG_SHADOW_PS_ELEMENT.test(node.name)) {
const itemList = list.filter(i => {
const { name, type } = i;
const res =
type === PS_ELEMENT_SELECTOR && REG_SHADOW_PSEUDO.test(name);
type === PS_ELEMENT_SELECTOR && REG_SHADOW_PS_ELEMENT.test(name);
return res;

@@ -256,0 +248,0 @@ });

@@ -89,37 +89,43 @@ /**

}
let current;
if (walker?.currentNode) {
let refNode = walker.currentNode;
if (refNode === node) {
return refNode;
} else if (refNode.contains(node)) {
if (!walker) {
return null;
}
let refNode = walker.currentNode;
if (refNode === node) {
return refNode;
} else if (refNode.contains(node)) {
refNode = walker.nextNode();
while (refNode) {
if (refNode === node) {
break;
}
refNode = walker.nextNode();
}
return refNode;
} else {
if (refNode !== walker.root) {
while (refNode) {
if (refNode === walker.root || refNode === node) {
break;
}
refNode = walker.parentNode();
}
}
if (node.nodeType === ELEMENT_NODE) {
let bool;
while (refNode) {
if (refNode === node) {
return refNode;
bool = true;
break;
}
refNode = walker.nextNode();
}
if (bool) {
return refNode;
}
return null;
} else {
if (refNode !== walker.root) {
while (refNode) {
if (refNode === walker.root || refNode === node) {
break;
}
refNode = walker.parentNode();
}
}
if (node.nodeType === ELEMENT_NODE) {
while (refNode) {
if (refNode === node) {
return refNode;
}
refNode = walker.nextNode();
}
} else {
current = refNode;
}
return refNode;
}
}
return current ?? null;
};

@@ -137,25 +143,24 @@

}
let bool;
if (node.nodeType === ELEMENT_NODE) {
const { localName, ownerDocument } = node;
const { formAssociated } = opt;
const window = ownerDocument.defaultView;
let elmConstructor;
const attr = node.getAttribute('is');
if (attr) {
elmConstructor =
isCustomElementName(attr) && window.customElements.get(attr);
} else {
elmConstructor =
isCustomElementName(localName) && window.customElements.get(localName);
if (node.nodeType !== ELEMENT_NODE) {
return false;
}
const { localName, ownerDocument } = node;
const { formAssociated } = opt;
const window = ownerDocument.defaultView;
let elmConstructor;
const attr = node.getAttribute('is');
if (attr) {
elmConstructor =
isCustomElementName(attr) && window.customElements.get(attr);
} else {
elmConstructor =
isCustomElementName(localName) && window.customElements.get(localName);
}
if (elmConstructor) {
if (formAssociated) {
return !!elmConstructor.formAssociated;
}
if (elmConstructor) {
if (formAssociated) {
bool = elmConstructor.formAssociated;
} else {
bool = true;
}
}
return true;
}
return !!bool;
return false;
};

@@ -172,17 +177,18 @@

}
let bool;
if (node.nodeType === ELEMENT_NODE ||
node.nodeType === DOCUMENT_FRAGMENT_NODE) {
let refNode = node;
while (refNode) {
const { host, mode, nodeType, parentNode } = refNode;
if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&
(mode === 'close' || mode === 'open')) {
bool = true;
break;
}
refNode = parentNode;
if (node.nodeType !== ELEMENT_NODE &&
node.nodeType !== DOCUMENT_FRAGMENT_NODE) {
return false;
}
let refNode = node;
let bool = false;
while (refNode) {
const { host, mode, nodeType, parentNode } = refNode;
if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&
(mode === 'close' || mode === 'open')) {
bool = true;
break;
}
refNode = parentNode;
}
return !!bool;
return bool;
};

@@ -199,17 +205,17 @@

}
let res;
if (node.localName === 'slot' && isInShadowTree(node)) {
const nodes = node.assignedNodes();
if (nodes.length) {
for (const item of nodes) {
res = item.textContent.trim();
if (res) {
break;
}
if (node.localName !== 'slot' || !isInShadowTree(node)) {
return null;
}
const nodes = node.assignedNodes();
if (nodes.length) {
let text;
for (const item of nodes) {
text = item.textContent.trim();
if (text) {
break;
}
} else {
res = node.textContent.trim();
}
return text;
}
return res ?? null;
return node.textContent.trim();
};

@@ -227,82 +233,90 @@

}
let res;
if (node.nodeType === ELEMENT_NODE) {
const { dir: nodeDir, localName, parentNode } = node;
const { getEmbeddingLevels } = bidiFactory();
if (nodeDir === 'ltr' || nodeDir === 'rtl') {
return nodeDir;
} else if (nodeDir === 'auto') {
let text;
switch (localName) {
case 'input': {
const valueKeys = [...KEY_INPUT_BUTTON, ...KEY_INPUT_TEXT, 'hidden'];
if (!node.type || valueKeys.includes(node.type)) {
text = node.value;
} else {
const ltrKeys = [
'checkbox', 'color', 'date', 'image', 'number', 'range', 'radio',
'time'
];
if (ltrKeys.includes(node.type)) {
return 'ltr';
}
if (node.nodeType !== ELEMENT_NODE) {
return null;
}
const { dir: nodeDir, localName, parentNode } = node;
const { getEmbeddingLevels } = bidiFactory();
if (nodeDir === 'ltr' || nodeDir === 'rtl') {
return nodeDir;
} else if (nodeDir === 'auto') {
let text;
switch (localName) {
case 'input': {
const valueKeys = [...KEY_INPUT_BUTTON, ...KEY_INPUT_TEXT, 'hidden'];
if (!node.type || valueKeys.includes(node.type)) {
text = node.value;
} else {
const ltrKeys = [
'checkbox', 'color', 'date', 'image', 'number', 'range', 'radio',
'time'
];
if (ltrKeys.includes(node.type)) {
return 'ltr';
}
break;
}
case 'slot': {
text = getSlottedTextContent(node);
break;
}
case 'textarea': {
text = node.value;
break;
}
default: {
const items = [].slice.call(node.childNodes);
for (const item of items) {
const {
dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,
textContent: itemTextContent
} = item;
if (itemNodeType === TEXT_NODE) {
text = itemTextContent.trim();
} else if (itemNodeType === ELEMENT_NODE) {
const keys = ['bdi', 'script', 'style', 'textarea'];
if (!keys.includes(itemLocalName) &&
(!itemDir || (itemDir !== 'ltr' && itemDir !== 'rtl'))) {
if (itemLocalName === 'slot') {
text = getSlottedTextContent(item);
} else {
text = itemTextContent.trim();
}
break;
}
case 'slot': {
text = getSlottedTextContent(node);
break;
}
case 'textarea': {
text = node.value;
break;
}
default: {
const items = [].slice.call(node.childNodes);
for (const item of items) {
const {
dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,
textContent: itemTextContent
} = item;
if (itemNodeType === TEXT_NODE) {
text = itemTextContent.trim();
} else if (itemNodeType === ELEMENT_NODE) {
const keys = ['bdi', 'script', 'style', 'textarea'];
if (!keys.includes(itemLocalName) &&
(!itemDir || (itemDir !== 'ltr' && itemDir !== 'rtl'))) {
if (itemLocalName === 'slot') {
text = getSlottedTextContent(item);
} else {
text = itemTextContent.trim();
}
}
if (text) {
break;
}
}
if (text) {
break;
}
}
}
if (text) {
const { paragraphs: [{ level }] } = getEmbeddingLevels(text);
if (level % 2 === 1) {
return 'rtl';
}
return 'ltr';
}
if (text) {
const { paragraphs: [{ level }] } = getEmbeddingLevels(text);
if (level % 2 === 1) {
return 'rtl';
}
if (!res) {
if (parentNode) {
const { nodeType: parentNodeType } = parentNode;
if (parentNodeType === ELEMENT_NODE) {
return getDirectionality(parentNode);
} else if (parentNodeType === DOCUMENT_NODE ||
parentNodeType === DOCUMENT_FRAGMENT_NODE) {
return 'ltr';
}
} else {
return 'ltr';
}
return 'ltr';
} else if (parentNode) {
const { nodeType: parentNodeType } = parentNode;
if (parentNodeType === ELEMENT_NODE) {
return getDirectionality(parentNode);
}
} else if (localName === 'bdi') {
const text = node.textContent.trim();
return 'ltr';
}
return 'ltr';
} else if (localName === 'bdi') {
const text = node.textContent.trim();
if (text) {
const { paragraphs: [{ level }] } = getEmbeddingLevels(text);
if (level % 2 === 1) {
return 'rtl';
}
return 'ltr';
}
return 'ltr';
} else if (localName === 'input' && node.type === 'tel') {
return 'ltr';
} else if (parentNode) {
if (localName === 'slot') {
const text = getSlottedTextContent(node);
if (text) {

@@ -315,32 +329,10 @@ const { paragraphs: [{ level }] } = getEmbeddingLevels(text);

}
if (!(res || parentNode)) {
return 'ltr';
}
} else if (localName === 'input' && node.type === 'tel') {
return 'ltr';
} else if (parentNode) {
if (localName === 'slot') {
const text = getSlottedTextContent(node);
if (text) {
const { paragraphs: [{ level }] } = getEmbeddingLevels(text);
if (level % 2 === 1) {
return 'rtl';
}
return 'ltr';
}
}
if (!res) {
const { nodeType: parentNodeType } = parentNode;
if (parentNodeType === ELEMENT_NODE) {
return getDirectionality(parentNode);
} else if (parentNodeType === DOCUMENT_NODE ||
parentNodeType === DOCUMENT_FRAGMENT_NODE) {
return 'ltr';
}
}
} else {
return 'ltr';
}
const { nodeType: parentNodeType } = parentNode;
if (parentNodeType === ELEMENT_NODE) {
return getDirectionality(parentNode);
}
return 'ltr';
}
return res ?? null;
return 'ltr';
};

@@ -358,37 +350,39 @@

}
let res;
if (node.nodeType === ELEMENT_NODE) {
if (typeof node.isContentEditable === 'boolean') {
return node.isContentEditable;
} else if (node.ownerDocument.designMode === 'on') {
return true;
} else if (node.hasAttribute('contenteditable')) {
const attr = node.getAttribute('contenteditable');
switch (attr) {
case '':
case 'true': {
return true;
}
case 'plaintext-only': {
// FIXME: the element's raw text is editable,
// but rich text formatting is disabled
return true;
}
case 'false': {
return false;
}
default: {
let parent = node.parentNode;
while (parent) {
if (isContentEditable(parent)) {
return true;
}
parent = parent.parentNode;
if (node.nodeType !== ELEMENT_NODE) {
return false;
}
if (typeof node.isContentEditable === 'boolean') {
return node.isContentEditable;
} else if (node.ownerDocument.designMode === 'on') {
return true;
} else if (node.hasAttribute('contenteditable')) {
const attr = node.getAttribute('contenteditable');
switch (attr) {
case '':
case 'true': {
return true;
}
case 'plaintext-only': {
// FIXME: the element's raw text is editable,
// but rich text formatting is disabled
return true;
}
case 'false': {
return false;
}
default: {
let parent = node.parentNode;
let bool = false;
while (parent) {
if (isContentEditable(parent)) {
bool = true;
break;
}
break;
parent = parent.parentNode;
}
return bool;
}
}
}
return !!res;
return false;
};

@@ -402,11 +396,11 @@

export const isVisible = node => {
let res;
if (node?.nodeType === ELEMENT_NODE) {
const window = node.ownerDocument.defaultView;
const { display, visibility } = window.getComputedStyle(node);
if (display !== 'none' && visibility === 'visible') {
return true;
}
if (node?.nodeType !== ELEMENT_NODE) {
return false;
}
return !!res;
const window = node.ownerDocument.defaultView;
const { display, visibility } = window.getComputedStyle(node);
if (display !== 'none' && visibility === 'visible') {
return true;
}
return false;
};

@@ -420,21 +414,20 @@

export const isFocusVisible = node => {
let res;
if (node?.nodeType === ELEMENT_NODE) {
const { localName, type } = node;
switch (localName) {
case 'input': {
if (!type || KEY_INPUT_EDIT.includes(type)) {
return true;
}
break;
}
case 'textarea': {
if (node?.nodeType !== ELEMENT_NODE) {
return false;
}
const { localName, type } = node;
switch (localName) {
case 'input': {
if (!type || KEY_INPUT_EDIT.includes(type)) {
return true;
}
default: {
return isContentEditable(node);
}
return false;
}
case 'textarea': {
return true;
}
default: {
return isContentEditable(node);
}
}
return !!res;
};

@@ -448,84 +441,86 @@

export const isFocusableArea = node => {
if (node?.nodeType === ELEMENT_NODE) {
if (!node.isConnected) {
return false;
if (node?.nodeType !== ELEMENT_NODE) {
return false;
}
if (!node.isConnected) {
return false;
}
const window = node.ownerDocument.defaultView;
if (node instanceof window.HTMLElement) {
if (Number.isInteger(parseInt(node.getAttribute('tabindex')))) {
return true;
}
const window = node.ownerDocument.defaultView;
if (node instanceof window.HTMLElement) {
if (Number.isInteger(parseInt(node.getAttribute('tabindex')))) {
return true;
if (isContentEditable(node)) {
return true;
}
const { localName, parentNode } = node;
switch (localName) {
case 'a': {
if (node.href || node.hasAttribute('href')) {
return true;
}
return false;
}
if (isContentEditable(node)) {
case 'iframe': {
return true;
}
const { localName, parentNode } = node;
switch (localName) {
case 'a': {
if (node.href || node.hasAttribute('href')) {
return true;
}
case 'input': {
if (node.disabled || node.hasAttribute('disabled') ||
node.hidden || node.hasAttribute('hidden')) {
return false;
}
case 'iframe': {
return true;
}
case 'input': {
if (node.disabled || node.hasAttribute('disabled') ||
node.hidden || node.hasAttribute('hidden')) {
return false;
}
return true;
}
case 'summary': {
if (parentNode.localName === 'details') {
let child = parentNode.firstElementChild;
while (child) {
if (child.localName === 'summary') {
return node === child;
}
child = child.nextElementSibling;
return true;
}
case 'summary': {
if (parentNode.localName === 'details') {
let child = parentNode.firstElementChild;
while (child) {
if (child.localName === 'summary') {
return node === child;
}
child = child.nextElementSibling;
}
return false;
}
default: {
const keys = new Set(['button', 'select', 'textarea']);
if (keys.has(localName) &&
!(node.disabled || node.hasAttribute('disabled'))) {
return true;
}
return false;
return false;
}
default: {
const keys = ['button', 'select', 'textarea'];
if (keys.includes(localName) &&
!(node.disabled || node.hasAttribute('disabled'))) {
return true;
}
return false;
}
} else if (node instanceof window.SVGElement) {
if (Number.isInteger(parseInt(node.getAttributeNS(null, 'tabindex')))) {
const keys = new Set([
'clipPath', 'defs', 'desc', 'linearGradient', 'marker', 'mask',
'metadata', 'pattern', 'radialGradient', 'script', 'style', 'symbol',
'title'
]);
const ns = 'http://www.w3.org/2000/svg';
let bool;
let refNode = node;
while (refNode.namespaceURI === ns) {
bool = keys.has(refNode.localName);
if (bool) {
break;
}
if (refNode?.parentNode?.namespaceURI === ns) {
refNode = refNode.parentNode;
} else {
break;
}
}
}
} else if (node instanceof window.SVGElement) {
if (Number.isInteger(parseInt(node.getAttributeNS(null, 'tabindex')))) {
const keys = [
'clipPath', 'defs', 'desc', 'linearGradient', 'marker', 'mask',
'metadata', 'pattern', 'radialGradient', 'script', 'style', 'symbol',
'title'
];
const ns = 'http://www.w3.org/2000/svg';
let bool;
let refNode = node;
while (refNode.namespaceURI === ns) {
bool = keys.includes(refNode.localName);
if (bool) {
return false;
break;
}
return true;
if (refNode?.parentNode?.namespaceURI === ns) {
refNode = refNode.parentNode;
} else {
break;
}
}
if (node.localName === 'a' &&
(node.href || node.hasAttributeNS(null, 'href'))) {
return true;
if (bool) {
return false;
}
return true;
}
if (node.localName === 'a' &&
(node.href || node.hasAttributeNS(null, 'href'))) {
return true;
}
return false;
}

@@ -546,31 +541,32 @@ return false;

export const isFocusable = node => {
let res;
if (node?.nodeType === ELEMENT_NODE) {
const window = node.ownerDocument.defaultView;
let refNode = node;
res = true;
while (refNode) {
if (refNode.disabled || refNode.hasAttribute('disabled')) {
return false;
}
if (refNode.hidden || refNode.hasAttribute('hidden')) {
res = false;
}
const {
contentVisibility, display, visibility
} = window.getComputedStyle(refNode);
if (display === 'none' || visibility !== 'visible' ||
(contentVisibility === 'hidden' && refNode !== node)) {
res = false;
} else {
res = true;
}
if (res && refNode?.parentNode?.nodeType === ELEMENT_NODE) {
refNode = refNode.parentNode;
} else {
break;
}
if (node?.nodeType !== ELEMENT_NODE) {
return false;
}
const window = node.ownerDocument.defaultView;
let refNode = node;
let res = true;
while (refNode) {
if (refNode.disabled || refNode.hasAttribute('disabled')) {
res = false;
break;
}
if (refNode.hidden || refNode.hasAttribute('hidden')) {
res = false;
}
const {
contentVisibility, display, visibility
} = window.getComputedStyle(refNode);
if (display === 'none' || visibility !== 'visible' ||
(contentVisibility === 'hidden' && refNode !== node)) {
res = false;
} else {
res = true;
}
if (res && refNode?.parentNode?.nodeType === ELEMENT_NODE) {
refNode = refNode.parentNode;
} else {
break;
}
}
return !!res;
return res;
};

@@ -590,14 +586,17 @@

}
if (!ns || node.nodeType !== ELEMENT_NODE) {
return null;
}
const { attributes } = node;
let res;
if (ns && node.nodeType === ELEMENT_NODE) {
const { attributes } = node;
for (const attr of attributes) {
const { name, namespaceURI, prefix, value } = attr;
if (name === `xmlns:${ns}`) {
return value;
}
if (prefix === ns) {
return namespaceURI;
}
for (const attr of attributes) {
const { name, namespaceURI, prefix, value } = attr;
if (name === `xmlns:${ns}`) {
res = value;
} else if (prefix === ns) {
res = namespaceURI;
}
if (res) {
break;
}
}

@@ -614,16 +613,17 @@ return res ?? null;

export const isNamespaceDeclared = (ns = '', node = {}) => {
if (!ns || typeof ns !== 'string' || node?.nodeType !== ELEMENT_NODE) {
return false;
}
if (node.lookupNamespaceURI(ns)) {
return true;
}
const root = node.ownerDocument.documentElement;
let parent = node;
let res;
if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {
res = node.lookupNamespaceURI(ns);
if (!res) {
const root = node.ownerDocument.documentElement;
let parent = node;
while (parent) {
res = getNamespaceURI(ns, parent);
if (res || parent === root) {
break;
}
parent = parent.parentNode;
}
while (parent) {
res = getNamespaceURI(ns, parent);
if (res || parent === root) {
break;
}
parent = parent.parentNode;
}

@@ -645,8 +645,8 @@ return !!res;

}
let res;
if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {
const posBit = nodeB.compareDocumentPosition(nodeA);
res = posBit & DOCUMENT_POSITION_PRECEDING ||
posBit & DOCUMENT_POSITION_CONTAINS;
if (nodeA.nodeType !== ELEMENT_NODE || nodeB.nodeType !== ELEMENT_NODE) {
return false;
}
const posBit = nodeB.compareDocumentPosition(nodeA);
const res = posBit & DOCUMENT_POSITION_PRECEDING ||
posBit & DOCUMENT_POSITION_CONTAINS;
return !!res;

@@ -653,0 +653,0 @@ };

export const ATTR_SELECTOR: "AttributeSelector";
export const CLASS_SELECTOR: "ClassSelector";
export const COMBINATOR: "Combinator";
export const EMPTY: "__EMPTY__";
export const IDENT: "Identifier";

@@ -9,5 +8,7 @@ export const ID_SELECTOR: "IdSelector";

export const NTH: "Nth";
export const OPERATOR: "Operator";
export const PS_CLASS_SELECTOR: "PseudoClassSelector";
export const PS_ELEMENT_SELECTOR: "PseudoElementSelector";
export const SELECTOR: "Selector";
export const STRING: "String";
export const SYNTAX_ERR: "SyntaxError";

@@ -72,1 +73,2 @@ export const TARGET_ALL: "all";

export const KEY_LOGICAL: readonly string[];
export const KEY_MODIFIER: readonly string[];

@@ -1,11 +0,10 @@

export class Matcher {
matchPseudoElementSelector(astName: string, opt?: {
forgive?: boolean;
warn?: boolean;
}): void;
private _matchAttributeSelector;
private _matchTypeSelector;
private _matchDirectionPseudoClass;
private _matchLanguagePseudoClass;
matchSelector(ast: object, node: object, opt?: object, validated?: boolean): object | null;
}
export function matchPseudoElementSelector(astName: string, astType: string, opt?: {
forgive?: boolean;
warn?: boolean;
}): void;
export function matchDirectionPseudoClass(ast: object, node: object): boolean;
export function matchLanguagePseudoClass(ast: object, node: object): boolean;
export function matchAttributeSelector(ast: object, node: object): boolean;
export function matchTypeSelector(ast: object, node: object, opt?: {
forgive?: boolean;
}): boolean;

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 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