@asamuzakjp/dom-selector
Advanced tools
Comparing version 4.1.2 to 4.1.3
@@ -1,2 +0,2 @@ | ||
var E=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var T=(o,t)=>{for(var r in t)E(o,r,{get:t[r],enumerable:!0})},_=(o,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of c(t))!n.call(o,e)&&e!==r&&E(o,e,{get:()=>t[e],enumerable:!(s=x(t,e))||s.enumerable});return o};var p=o=>_(E({},"__esModule",{value:!0}),o);var Et={};T(Et,{ALPHA_NUM:()=>O,AN_PLUS_B:()=>S,BIT_01:()=>W,BIT_02:()=>a,BIT_04:()=>d,BIT_08:()=>i,BIT_16:()=>u,BIT_32:()=>Y,BIT_FFFF:()=>h,BIT_HYPHEN:()=>$,COMBINATOR:()=>N,DOCUMENT_FRAGMENT_NODE:()=>Z,DOCUMENT_NODE:()=>K,DOCUMENT_POSITION_CONTAINED_BY:()=>q,DOCUMENT_POSITION_CONTAINS:()=>k,DOCUMENT_POSITION_PRECEDING:()=>j,DUO:()=>X,ELEMENT_NODE:()=>y,HEX:()=>b,IDENTIFIER:()=>R,NOT_SUPPORTED_ERR:()=>D,NTH:()=>I,RAW:()=>C,REG_LOGICAL_PSEUDO:()=>tt,REG_SHADOW_HOST:()=>ot,REG_SHADOW_MODE:()=>et,REG_SHADOW_PSEUDO:()=>rt,SELECTOR:()=>L,SELECTOR_ATTR:()=>A,SELECTOR_CLASS:()=>F,SELECTOR_ID:()=>P,SELECTOR_LIST:()=>M,SELECTOR_PSEUDO_CLASS:()=>U,SELECTOR_PSEUDO_ELEMENT:()=>l,SELECTOR_TYPE:()=>H,SHOW_ALL:()=>v,SHOW_DOCUMENT:()=>z,SHOW_DOCUMENT_FRAGMENT:()=>J,SHOW_ELEMENT:()=>Q,STRING:()=>B,SYNTAX_ERR:()=>f,TEXT_NODE:()=>g,TYPE_FROM:()=>m,TYPE_TO:()=>w,U_FFFD:()=>G,WALKER_FILTER:()=>V});module.exports=p(Et);const O="[A-Z\\d]+",S="AnPlusB",N="Combinator",R="Identifier",D="NotSupportedError",I="Nth",C="Raw",L="Selector",A="AttributeSelector",F="ClassSelector",P="IdSelector",M="SelectorList",U="PseudoClassSelector",l="PseudoElementSelector",H="TypeSelector",B="String",f="SyntaxError",G="\uFFFD",W=1,a=2,d=4,i=8,u=16,Y=32,h=65535,$=45,X=2,b=16,m=8,w=-1,y=1,g=3,K=9,Z=11,j=2,k=8,q=16,v=4294967295,z=256,J=1024,Q=1,V=1281,tt=/^(?:(?:ha|i)s|not|where)$/,ot=/^host(?:-context)?$/,et=/^(?:close|open)$/,rt=/^part|slotted$/;0&&(module.exports={ALPHA_NUM,AN_PLUS_B,BIT_01,BIT_02,BIT_04,BIT_08,BIT_16,BIT_32,BIT_FFFF,BIT_HYPHEN,COMBINATOR,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,DUO,ELEMENT_NODE,HEX,IDENTIFIER,NOT_SUPPORTED_ERR,NTH,RAW,REG_LOGICAL_PSEUDO,REG_SHADOW_HOST,REG_SHADOW_MODE,REG_SHADOW_PSEUDO,SELECTOR,SELECTOR_ATTR,SELECTOR_CLASS,SELECTOR_ID,SELECTOR_LIST,SELECTOR_PSEUDO_CLASS,SELECTOR_PSEUDO_ELEMENT,SELECTOR_TYPE,SHOW_ALL,SHOW_DOCUMENT,SHOW_DOCUMENT_FRAGMENT,SHOW_ELEMENT,STRING,SYNTAX_ERR,TEXT_NODE,TYPE_FROM,TYPE_TO,U_FFFD,WALKER_FILTER}); | ||
var E=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var _=(o,t)=>{for(var r in t)E(o,r,{get:t[r],enumerable:!0})},T=(o,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of c(t))!n.call(o,e)&&e!==r&&E(o,e,{get:()=>t[e],enumerable:!(s=x(t,e))||s.enumerable});return o};var p=o=>T(E({},"__esModule",{value:!0}),o);var st={};_(st,{ALPHA_NUM:()=>O,AN_PLUS_B:()=>S,BIT_01:()=>Y,BIT_02:()=>a,BIT_04:()=>d,BIT_08:()=>i,BIT_16:()=>u,BIT_32:()=>h,BIT_FFFF:()=>$,BIT_HYPHEN:()=>X,COMBINATOR:()=>N,DOCUMENT_FRAGMENT_NODE:()=>j,DOCUMENT_NODE:()=>Z,DOCUMENT_POSITION_CONTAINED_BY:()=>v,DOCUMENT_POSITION_CONTAINS:()=>q,DOCUMENT_POSITION_PRECEDING:()=>k,DUO:()=>b,ELEMENT_NODE:()=>g,EMPTY:()=>R,HEX:()=>m,IDENTIFIER:()=>D,NOT_SUPPORTED_ERR:()=>I,NTH:()=>C,RAW:()=>L,REG_LOGICAL_PSEUDO:()=>ot,REG_SHADOW_HOST:()=>et,REG_SHADOW_MODE:()=>rt,REG_SHADOW_PSEUDO:()=>Et,SELECTOR:()=>A,SELECTOR_ATTR:()=>P,SELECTOR_CLASS:()=>F,SELECTOR_ID:()=>M,SELECTOR_LIST:()=>U,SELECTOR_PSEUDO_CLASS:()=>l,SELECTOR_PSEUDO_ELEMENT:()=>H,SELECTOR_TYPE:()=>B,SHOW_ALL:()=>z,SHOW_DOCUMENT:()=>J,SHOW_DOCUMENT_FRAGMENT:()=>Q,SHOW_ELEMENT:()=>V,STRING:()=>f,SYNTAX_ERR:()=>G,TEXT_NODE:()=>K,TYPE_FROM:()=>w,TYPE_TO:()=>y,U_FFFD:()=>W,WALKER_FILTER:()=>tt});module.exports=p(st);const O="[A-Z\\d]+",S="AnPlusB",N="Combinator",R="__EMPTY__",D="Identifier",I="NotSupportedError",C="Nth",L="Raw",A="Selector",P="AttributeSelector",F="ClassSelector",M="IdSelector",U="SelectorList",l="PseudoClassSelector",H="PseudoElementSelector",B="TypeSelector",f="String",G="SyntaxError",W="\uFFFD",Y=1,a=2,d=4,i=8,u=16,h=32,$=65535,X=45,b=2,m=16,w=8,y=-1,g=1,K=3,Z=9,j=11,k=2,q=8,v=16,z=4294967295,J=256,Q=1024,V=1,tt=1281,ot=/^(?:(?:ha|i)s|not|where)$/,et=/^host(?:-context)?$/,rt=/^(?:close|open)$/,Et=/^part|slotted$/;0&&(module.exports={ALPHA_NUM,AN_PLUS_B,BIT_01,BIT_02,BIT_04,BIT_08,BIT_16,BIT_32,BIT_FFFF,BIT_HYPHEN,COMBINATOR,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,DUO,ELEMENT_NODE,EMPTY,HEX,IDENTIFIER,NOT_SUPPORTED_ERR,NTH,RAW,REG_LOGICAL_PSEUDO,REG_SHADOW_HOST,REG_SHADOW_MODE,REG_SHADOW_PSEUDO,SELECTOR,SELECTOR_ATTR,SELECTOR_CLASS,SELECTOR_ID,SELECTOR_LIST,SELECTOR_PSEUDO_CLASS,SELECTOR_PSEUDO_ELEMENT,SELECTOR_TYPE,SHOW_ALL,SHOW_DOCUMENT,SHOW_DOCUMENT_FRAGMENT,SHOW_ELEMENT,STRING,SYNTAX_ERR,TEXT_NODE,TYPE_FROM,TYPE_TO,U_FFFD,WALKER_FILTER}); | ||
//# sourceMappingURL=constant.js.map |
@@ -1,2 +0,2 @@ | ||
var W=Object.create;var P=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(A,i)=>{for(var e in i)P(A,e,{get:i[e],enumerable:!0})},U=(A,i,e,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let a of B(i))!G.call(A,a)&&a!==e&&P(A,a,{get:()=>i[a],enumerable:!(r=H(i,a))||r.enumerable});return A};var z=(A,i,e)=>(e=A!=null?W(j(A)):{},U(i||!A||!A.__esModule?P(e,"default",{value:A,enumerable:!0}):e,A)),V=A=>U(P({},"__esModule",{value:!0}),A);var Q={};q(Q,{Finder:()=>X});module.exports=V(Q);var I=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),L=require("./dom-util.js"),M=require("./matcher.js"),y=require("./parser.js"),u=require("./constant.js");const C="next",O="prev",$="all",E="first",R="lineal",D="self";class X{#a;#l;#t;#o;#f;#e;#h;#w;#c;#n;#m;#s;#d;#u;#r;#b;#i;#p;constructor(i){this.#p=i,this.#f=i.document,this.#l=new WeakMap,this.#m=new WeakMap,this.#c=(0,F.default)({document:i.document,DOMException:i.DOMException}),this.#c.configure({LOGERRORS:!1})}_onError(i){if(!this.#w)if(i instanceof DOMException||i instanceof this.#p.DOMException)if(i.name===u.NOT_SUPPORTED_ERR)this.#i&&console.warn(i.message);else throw new this.#p.DOMException(i.message,i.name);else throw i}_setup(i,e,r={}){const{noexcept:a,warn:s}=r;return this.#w=!!a,this.#i=!!s,this.#e=e,[this.#t,this.#s,this.#r]=(0,L.resolveContent)(e),this.#d=(0,L.isInShadowTree)(e),[this.#a,this.#h]=this._correspond(i),this.#b=new WeakMap,e}_correspond(i){const e=[];this.#o=!1;let r;if(this.#t){const a=this.#l.get(this.#t);if(a&&a.has(`${i}`)){const s=a.get(`${i}`);this.#o=s.descendant,r=s.ast}}if(r){const a=r.length;for(let s=0;s<a;s++)r[s].collected=!1,r[s].dir=null,r[s].filtered=!1,r[s].find=!1,e[s]=[]}else{let a;try{a=(0,y.parseSelector)(i)}catch(h){this._onError(h)}const s=(0,y.walkAST)(a);let o=!1,n=0;r=[];for(const[...h]of s){const f=[];let t=h.shift();if(t&&t.type!==u.COMBINATOR){const l=new Set;for(;t;){if(t.type===u.COMBINATOR){const[c]=h;if(c.type===u.COMBINATOR){const p=`Invalid selector ${i}`;throw new DOMException(p,u.SYNTAX_ERR)}const m=t.name;/^[\s>]$/.test(m)&&(o=!0),f.push({combo:t,leaves:(0,y.sortAST)(l)}),l.clear()}else if(t){let{name:c}=t;c&&typeof c=="string"&&(c=(0,y.unescapeSelector)(c),t.name=c,/[|:]/.test(c)&&(t.namespace=!0)),l.add(t)}if(h.length)t=h.shift();else{f.push({combo:null,leaves:(0,y.sortAST)(l)}),l.clear();break}}}r.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#t){let h;this.#l.has(this.#t)?h=this.#l.get(this.#t):h=new Map,h.set(`${i}`,{ast:r,descendant:o}),this.#l.set(this.#t,h)}this.#o=o}return[r,e]}_createTreeWalker(i){let e;return this.#b.has(i)?e=this.#b.get(i):(e=this.#f.createTreeWalker(i,u.WALKER_FILTER),this.#b.set(i,e)),e}_prepareQuerySelectorWalker(){return this.#n=this._createTreeWalker(this.#e),this.#u=!1,this.#n}_traverse(i,e=this.#r){let r=e.currentNode,a;if(r===i)a=r;else if(r.contains(i))for(r=e.nextNode();r;){if(r===i){a=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===i);)r=e.parentNode();if(i?.nodeType===u.ELEMENT_NODE)for(;r;){if(r===i){a=r;break}r=e.nextNode()}else a=r}return a??null}_collectNthChild(i,e,r){const{a,b:s,reverse:o,selector:n}=i,{parentNode:h}=e,f=new Set;let t;if(n&&(this.#l.has(n)?t=this.#l.get(n):(t=(0,y.walkAST)(n),this.#l.set(n,t))),h){const l=this.#r;let c=this._traverse(h,l);c=l.firstChild();let m=0;for(;c;)m++,c=l.nextSibling();c=this._traverse(h,l);const p=new Set;if(t)for(c=l.firstChild();c;){let b;for(const _ of t)if(b=this._matchLeaves(_,c,r),!b)break;b&&p.add(c),c=l.nextSibling()}if(a===0){if(s>0&&s<=m){if(p.size){c=this._traverse(h,l),o?c=l.lastChild():c=l.firstChild();let b=0;for(;c;){if(p.has(c)){if(b===s-1){f.add(c);break}b++}o?c=l.previousSibling():c=l.nextSibling()}}else if(!n){c=this._traverse(h,l),o?c=l.lastChild():c=l.firstChild();let b=0;for(;c;){if(b===s-1){f.add(c);break}o?c=l.previousSibling():c=l.nextSibling(),b++}}}}else{let b=s-1;if(a>0)for(;b<0;)b+=a;if(b>=0&&b<m){c=this._traverse(h,l),o?c=l.lastChild():c=l.firstChild();let _=0,N=a>0?0:s-1;for(;c&&(c&&b>=0&&b<m);)p.size?p.has(c)&&(N===b&&(f.add(c),b+=a),a>0?N++:N--):_===b&&(n||f.add(c),b+=a),o?c=l.previousSibling():c=l.nextSibling(),_++}}if(o&&f.size>1){const b=[...f];return new Set(b.reverse())}}else if(e===this.#s&&a+s===1)if(t){let l;for(const c of t)if(l=this._matchLeaves(c,e,r),l)break;l&&f.add(e)}else f.add(e);return f}_collectNthOfType(i,e){const{a:r,b:a,reverse:s}=i,{localName:o,parentNode:n,prefix:h}=e,f=new Set;if(n){const t=this.#r;let l=this._traverse(n,t);l=t.firstChild();let c=0;for(;l;)c++,l=t.nextSibling();if(r===0){if(a>0&&a<=c){l=this._traverse(n,t),s?l=t.lastChild():l=t.firstChild();let m=0;for(;l;){const{localName:p,prefix:b}=l;if(p===o&&b===h){if(m===a-1){f.add(l);break}m++}s?l=t.previousSibling():l=t.nextSibling()}}}else{let m=a-1;if(r>0)for(;m<0;)m+=r;if(m>=0&&m<c){l=this._traverse(n,t),s?l=t.lastChild():l=t.firstChild();let p=r>0?0:a-1;for(;l;){const{localName:b,prefix:_}=l;if(b===o&&_===h){if(p===m&&(f.add(l),m+=r),m<0||m>=c)break;r>0?p++:p--}s?l=t.previousSibling():l=t.nextSibling()}}}if(s&&f.size>1){const m=[...f];return new Set(m.reverse())}}else e===this.#s&&r+a===1&&f.add(e);return f}_matchAnPlusB(i,e,r,a){const{nth:{a:s,b:o,name:n},selector:h}=i,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?f.set("b",o*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){h&&f.set("selector",h);const t=Object.fromEntries(f);return this._collectNthChild(t,e,a)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchDirectionPseudoClass(i,e){const r=(0,L.getDirectionality)(e);let a;return i.name===r&&(a=e),a??null}_matchLanguagePseudoClass(i,e){const r=(0,y.unescapeSelector)(i.name);i.name=r;let a;if(r==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(a=e);else{let s=e.parentNode;for(;s&&s.nodeType===u.ELEMENT_NODE;){if(s.hasAttribute("lang")){s.getAttribute("lang")&&(a=e);break}s=s.parentNode}}else if(r){const s=`(?:-${u.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${u.ALPHA_NUM}${s}$`,"i").test(r)){let n;if(r.indexOf("-")>-1){const[h,f,...t]=r.split("-");let l;h==="*"?l=`${u.ALPHA_NUM}${s}`:l=`${h}${s}`;const c=`-${f}${s}`,m=t.length;let p="";if(m)for(let b=0;b<m;b++)p+=`-${t[b]}${s}`;n=new RegExp(`^${l}${c}${p}$`,"i")}else n=new RegExp(`^${r}${s}$`,"i");if(e.hasAttribute("lang"))n.test(e.getAttribute("lang"))&&(a=e);else{let h=e.parentNode;for(;h&&h.nodeType===u.ELEMENT_NODE;){if(h.hasAttribute("lang")){const f=h.getAttribute("lang");n.test(f)&&(a=e);break}h=h.parentNode}}}}return a??null}_matchHasPseudoFunc(i,e,r={}){let a;if(Array.isArray(i)&&i.length){const[s]=i,{type:o}=s;let n;o===u.COMBINATOR?n=i.shift():n={name:" ",type:u.COMBINATOR};const h=[];for(;i.length;){const[l]=i,{type:c}=l;if(c===u.COMBINATOR)break;h.push(i.shift())}const f={combo:n,leaves:h};r.dir=C;const t=this._matchCombinator(f,e,r);if(t.size)if(i.length){for(const l of t)if(a=this._matchHasPseudoFunc(Object.assign([],i),l,r),a)break}else a=!0}return!!a}_matchLogicalPseudoFunc(i,e,r={}){const{astName:a="",branches:s=[],selector:o="",twigBranches:n=[]}=i;let h;if(a==="has")if(o.includes(":has("))h=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(h=e)}else{const f=/^(?:is|where)$/.test(a);r.forgive=f;const t=n.length;let l;for(let c=0;c<t;c++){const m=n[c],p=m.length-1,{leaves:b}=m[p];if(l=this._matchLeaves(b,e,r),l&&p>0){let _=new Set([e]);for(let N=p-1;N>=0;N--){const k=m[N],d=[];r.dir=O;for(const w of _){const g=this._matchCombinator(k,w,r);g.size&&d.push(...g)}if(d.length)N===0?l=!0:_=new Set(d);else{l=!1;break}}}if(l)break}a==="not"?l||(h=e):l&&(h=e)}return h??null}_matchPseudoClassSelector(i,e,r={}){const{children:a,name:s}=i,{localName:o,parentNode:n}=e,{forgive:h,warn:f=this.#i}=r,t=new Set;if(u.REG_LOGICAL_PSEUDO.test(s)){let l;if(this.#l.has(i))l=this.#l.get(i);else{const m=(0,y.walkAST)(i),p=[],b=[];for(const[..._]of m){for(const w of _){const g=(0,y.generateCSS)(w);p.push(g)}const N=[],k=new Set;let d=_.shift();for(;d;)if(d.type===u.COMBINATOR?(N.push({combo:d,leaves:[...k]}),k.clear()):d&&k.add(d),_.length)d=_.shift();else{N.push({combo:null,leaves:[...k]}),k.clear();break}b.push(N)}l={astName:s,branches:m,twigBranches:b,selector:p.join(",")},this.#l.set(i,l)}const c=this._matchLogicalPseudoFunc(l,e,r);c&&t.add(c)}else if(Array.isArray(a)){const[l]=a;if(/^nth-(?:last-)?(?:child|of-type)$/.test(s))return this._matchAnPlusB(l,e,s,r);if(s==="dir"){const c=this._matchDirectionPseudoClass(l,e);c&&t.add(c)}else if(s==="lang"){const c=this._matchLanguagePseudoClass(l,e);c&&t.add(c)}else switch(s){case"current":case"nth-col":case"nth-last-col":{if(f){const c=`Unsupported pseudo-class :${s}()`;throw new DOMException(c,u.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!h){const c=`Unknown pseudo-class :${s}()`;throw new DOMException(c,u.SYNTAX_ERR)}}}else{const l=/^a(?:rea)?$/,c=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,m=/^(?:(?:inpu|selec)t|button|form|textarea)$/,p=/^d(?:etails|ialog)$/,b=/^(?:checkbox|radio)$/,_=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,k=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(s){case"any-link":case"link":{l.test(o)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(l.test(o)&&e.hasAttribute("href")){const{href:d,origin:w,pathname:g}=new URL(this.#t.URL),x=new URL(e.getAttribute("href"),d);x.origin===w&&x.pathname===g&&t.add(e)}break}case"visited":break;case"target":{const{hash:d}=new URL(this.#t.URL);e.id&&d===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:d}=new URL(this.#t.URL);if(d){const w=d.replace(/^#/,"");let g=this.#t.getElementById(w);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===u.ELEMENT_NODE?!this.#d&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":{if(e===this.#t.activeElement){let d=e,w=!0;for(;d;){if(d.hasAttribute("hidden")){w=!1;break}else if(d.hasAttribute("style")){const{display:g,visibility:x}=d.style;if(w=!(g==="none"||x==="hidden"),!w)break}if(d.parentNode&&d.parentNode.nodeType===u.ELEMENT_NODE)d=d.parentNode;else break}w&&t.add(e)}break}case"focus-within":{let d=this.#t.activeElement,w;for(;d;){if(d===e){w=!0;break}d=d.parentNode}if(w){let g=e,x=!0;for(;g;){if(g.hasAttribute("hidden")){x=!1;break}else if(g.hasAttribute("style")){const{display:v,visibility:T}=g.style;if(x=!(v==="none"||T==="hidden"),!x)break}if(g.parentNode&&g.parentNode.nodeType===u.ELEMENT_NODE)g=g.parentNode;else break}x&&t.add(e)}break}case"open":{p.test(o)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{p.test(o)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(c.test(o)||(0,I.default)(o))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let d=n;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&n.localName!=="legend"&&d.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(c.test(o)||(0,I.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||_.test(e.type)||k.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,L.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||_.test(e.type)||k.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,L.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let d;o==="textarea"?d=e:o==="input"&&(e.hasAttribute("type")?k.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))||e.selected&&o==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))t.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;w||(w=this.#t.documentElement);const g=w.getElementsByTagName("input"),x=g.length;let v;for(let T=0;T<x;T++){const S=g[T];if(S.getAttribute("type")==="radio"&&(d?S.getAttribute("name")===d&&(v=!!S.checked):S.hasAttribute("name")||(v=!!S.checked),v))break}v||t.add(e)}break}case"default":{const d=/^(?:button|reset)$/,w=/^(?:image|submit)$/;if(o==="button"&&!(e.hasAttribute("type")&&d.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))){let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;if(g){const x=this.#r;let v=this._traverse(g,x);for(v=x.firstChild();v&&g.contains(v);){const T=v.localName;let S;if(T==="button"?S=!(v.hasAttribute("type")&&d.test(v.getAttribute("type"))):T==="input"&&(S=v.hasAttribute("type")&&w.test(v.getAttribute("type"))),S){v===e&&t.add(e);break}v=x.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(o==="option"){let g=n,x=!1;for(;g&&g.localName!=="datalist";){if(g.localName==="select"){(g.multiple||g.hasAttribute("multiple"))&&(x=!0);break}g=g.parentNode}if(x)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,T=this.#r;let S=this._traverse(n,T);for(S=T.firstChild();S;){if(S.selected||S.hasAttribute("selected")){v.add(S);break}S=T.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(m.test(o))e.checkValidity()&&t.add(e);else if(o==="fieldset"){const d=this.#r;let w=this._traverse(e,d);w=d.firstChild();let g;for(;w&&e.contains(w)&&!(m.test(w.localName)&&(g=w.checkValidity(),!g));)w=d.nextNode();g&&t.add(e)}break}case"invalid":{if(m.test(o))e.checkValidity()||t.add(e);else if(o==="fieldset"){const d=this.#r;let w=this._traverse(e,d);w=d.firstChild();let g;for(;w&&e.contains(w)&&!(m.test(w.localName)&&(g=w.checkValidity(),!g));)w=d.nextNode();g||t.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let d;if(/^(?:select|textarea)$/.test(o))d=e;else if(o==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||_.test(w)||k.test(w))&&(d=e)}else d=e;d&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let d;if(/^(?:select|textarea)$/.test(o))d=e;else if(o==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||_.test(w)||k.test(w))&&(d=e)}else d=e;d&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const d=this.#f.createTreeWalker(e,u.SHOW_ALL);let w=d.firstChild(),g;for(;w&&(g=w.nodeType!==u.ELEMENT_NODE&&w.nodeType!==u.TEXT_NODE,!!g);)w=d.nextSibling();g&&t.add(e)}else t.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);d&&t.add(d)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1,reverse:!0},e);d&&t.add(d)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);if(d===e){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const d=`Unsupported pseudo-element ::${s}`;throw new DOMException(d,u.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"defined":case"focus-visible":case"fullscreen":case"future":case"hover":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(f){const d=`Unsupported pseudo-class :${s}`;throw new DOMException(d,u.NOT_SUPPORTED_ERR)}break}default:if(s.startsWith("-webkit-")){if(f){const d=`Unsupported pseudo-class :${s}`;throw new DOMException(d,u.NOT_SUPPORTED_ERR)}}else if(!h){const d=`Unknown pseudo-class :${s}`;throw new DOMException(d,u.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(i,e){const{children:r,name:a}=i;let s;if(Array.isArray(r)){const[o]=(0,y.walkAST)(r[0]),[...n]=o,{host:h}=e;if(a==="host"){let f;for(const t of n){const{type:l}=t;if(l===u.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(i)}`;throw new DOMException(m,u.SYNTAX_ERR)}if(f=this._matchSelector(t,h).has(h),!f)break}f&&(s=e)}else if(a==="host-context"){let f=h,t;for(;f;){for(const l of n){const{type:c}=l;if(c===u.COMBINATOR){const p=`Invalid selector ${(0,y.generateCSS)(i)}`;throw new DOMException(p,u.SYNTAX_ERR)}if(t=this._matchSelector(l,f).has(f),!t)break}if(t)break;f=f.parentNode}t&&(s=e)}}else if(a==="host")s=e;else{const o=`Invalid selector :${a}`;throw new DOMException(o,u.SYNTAX_ERR)}return s??null}_matchSelector(i,e,r){const{type:a}=i,s=(0,y.unescapeSelector)(i.name);i.name=s;const o=new Set;if(e.nodeType===u.ELEMENT_NODE)switch(a){case u.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(s,r);break}case u.SELECTOR_ID:{e.id===s&&o.add(e);break}case u.SELECTOR_CLASS:{e.classList.contains(s)&&o.add(e);break}case u.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(i,e,r);default:{const n=(0,M.matchSelector)(i,e,r);n&&o.add(n)}}else if(this.#d&&a===u.SELECTOR_PSEUDO_CLASS&&e.nodeType===u.DOCUMENT_FRAGMENT_NODE){if(s!=="has"&&u.REG_LOGICAL_PSEUDO.test(s))return this._matchPseudoClassSelector(i,e,r);if(u.REG_SHADOW_HOST.test(s)){const n=this._matchShadowHostPseudoClass(i,e,r);n&&o.add(n)}}return o}_matchLeaves(i,e,r){const{attributes:a,localName:s,nodeType:o}=e;let n=this.#m.get(i),h;if(n&&n.has(e)){const{attr:f,matched:t}=n.get(e);a?.length===f&&(h=t)}if(typeof h!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;o===u.ELEMENT_NODE&&f.test(s)?t=!1:t=!0;for(const l of i){const{name:c,type:m}=l,p=(0,y.unescapeSelector)(c);if(l.name=p,m===u.SELECTOR_PSEUDO_CLASS&&p==="dir"&&(t=!1),h=this._matchSelector(l,e,r).has(e),!h)break}t&&(n||(n=new WeakMap),n.set(e,{attr:a?.length,matched:h}),this.#m.set(i,n))}return!!h}_matchHTMLCollection(i,e={}){const{compound:r,filterLeaves:a}=e,s=new Set,o=i.length;if(o)if(r)for(let n=0;n<o;n++){const h=i[n];this._matchLeaves(a,h,e)&&s.add(h)}else{const n=[].slice.call(i);return new Set(n)}return s}_findDescendantNodes(i,e,r){const[a,...s]=i,o=s.length>0,{type:n}=a,h=(0,y.unescapeSelector)(a.name);a.name=h;let f=new Set,t=!1;if(this.#d)t=!0;else switch(n){case u.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(h,r);break}case u.SELECTOR_ID:{if(this.#s.nodeType===u.ELEMENT_NODE)t=!0;else{const l=this.#s.getElementById(h);l&&l!==e&&e.contains(l)&&(o?this._matchLeaves(s,l,r)&&f.add(l):f.add(l))}break}case u.SELECTOR_CLASS:{const l=e.getElementsByClassName(h);f=this._matchHTMLCollection(l,{compound:o,filterLeaves:s});break}case u.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(h)){const l=e.getElementsByTagName(h);f=this._matchHTMLCollection(l,{compound:o,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(i,e,r={}){const{combo:a,leaves:s}=i,{name:o}=a,{parentNode:n}=e,{dir:h}=r,f=new Set;if(h===C)switch(o){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let l=this._traverse(e,t);for(l=t.nextSibling();l;)this._matchLeaves(s,l,r)&&f.add(l),l=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let l=this._traverse(e,t);for(l=t.firstChild();l;)this._matchLeaves(s,l,r)&&f.add(l),l=t.nextSibling();break}case" ":default:{const{nodes:t,pending:l}=this._findDescendantNodes(s,e);if(t.size)return t;if(l){const c=this._createTreeWalker(e);let m=this._traverse(e,c);for(m=c.nextNode();m&&e.contains(m);)this._matchLeaves(s,m,r)&&f.add(m),m=c.nextNode()}}}else switch(o){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let l=this._traverse(n,t);for(l=t.firstChild();l&&l!==e;)this._matchLeaves(s,l,r)&&f.add(l),l=t.nextSibling()}break}case">":{n&&this._matchLeaves(s,n,r)&&f.add(n);break}case" ":default:{const t=[];let l=n;for(;l;)this._matchLeaves(s,l,r)&&t.push(l),l=l.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(i,e){const{node:r}=e;let a=this._traverse(r,this.#n),s;if(a)for(a.nodeType!==u.ELEMENT_NODE?a=this.#n.nextNode():a===r&&a!==this.#s&&(a=this.#n.nextNode());a;){if(this._matchLeaves(i,a,{warn:this.#i})){s=a;break}a=this.#n.nextNode()}return s??null}_matchSelf(i){const e=[],r=this._matchLeaves(i,this.#e,{warn:this.#i});let a=!1;return r&&(e.push(this.#e),a=!0),[e,a]}_findLineal(i,e={}){const{complex:r}=e,a=[];let s=this._matchLeaves(i,this.#e,{warn:this.#i}),o=!1;if(s&&(a.push(this.#e),o=!0),!s||r){let n=this.#e.parentNode;for(;n&&(s=this._matchLeaves(i,n,{warn:this.#i}),s&&(a.push(n),o=!0),n.parentNode);)n=n.parentNode}return[a,o]}_findFirst(i){const e=[],r=this._findNode(i,{node:this.#e});let a=!1;return r&&(e.push(r),a=!0),[e,a]}_findFromHTMLCollection(i,e={}){const{complex:r,compound:a,filterLeaves:s,targetType:o}=e;let n=[],h=!1,f=!1;const t=i.length;if(t)if(this.#e.nodeType===u.ELEMENT_NODE)for(let l=0;l<t;l++){const c=i[l];if(c!==this.#e&&(this.#e.contains(c)||c.contains(this.#e))){if(a){if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),h=!0,o===E))break}else if(n.push(c),h=!0,o===E)break}}else if(r)if(a)for(let l=0;l<t;l++){const c=i[l];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),h=!0,o===E))break}else n=[].slice.call(i),h=!0,f=!0;else if(a)for(let l=0;l<t;l++){const c=i[l];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),h=!0,o===E))break}else n=[].slice.call(i),h=!0,f=!0;return[n,h,f]}_findEntryNodes(i,e,r){const{leaves:a}=i,[s,...o]=a,n=o.length>0,{type:h}=s,f=(0,y.unescapeSelector)(s.name);s.name=f;let t=[],l=!1,c=!1,m=!1;switch(h){case u.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(f,{warn:this.#i});break}case u.SELECTOR_ID:{if(e===D)[t,c]=this._matchSelf(a);else if(e===R)[t,c]=this._findLineal(a,{complex:r});else if(e===E&&this.#s.nodeType!==u.ELEMENT_NODE){const p=this.#s.getElementById(f);p&&(n?this._matchLeaves(o,p,{warn:this.#i})&&(t.push(p),c=!0):(t.push(p),c=!0))}else e===E?[t,c]=this._findFirst(a):m=!0;break}case u.SELECTOR_CLASS:{if(e===D)[t,c]=this._matchSelf(a);else if(e===R)[t,c]=this._findLineal(a,{complex:r});else if(this.#s.nodeType===u.DOCUMENT_NODE){const p=this.#s.getElementsByClassName(f);p.length&&([t,c,l]=this._findFromHTMLCollection(p,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===E?[t,c]=this._findFirst(a):m=!0;break}case u.SELECTOR_TYPE:{if(e===D)[t,c]=this._matchSelf(a);else if(e===R)[t,c]=this._findLineal(a,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===u.DOCUMENT_NODE&&!/[*|]/.test(f)){const p=this.#s.getElementsByTagName(f);p.length&&([t,c,l]=this._findFromHTMLCollection(p,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===E?[t,c]=this._findFirst(a):m=!0;break}default:if(e!==R&&u.REG_SHADOW_HOST.test(f)){if(this.#d&&this.#e.nodeType===u.DOCUMENT_FRAGMENT_NODE){const p=this._matchShadowHostPseudoClass(s,this.#e);p&&(t.push(p),c=!0)}}else e===D?[t,c]=this._matchSelf(a):e===R?[t,c]=this._findLineal(a,{complex:r}):e===E?[t,c]=this._findFirst(a):m=!0}return{collected:l,compound:n,filtered:c,nodes:t,pending:m}}_getEntryTwig(i,e){const r=i.length,a=r>1,s=i[0];let o,n;if(a){const{combo:h,leaves:[{name:f,type:t}]}=s,l=i[r-1],{leaves:[{name:c,type:m}]}=l;if(m===u.SELECTOR_PSEUDO_ELEMENT||m===u.SELECTOR_ID)o=O,n=l;else if(t===u.SELECTOR_PSEUDO_ELEMENT||t===u.SELECTOR_ID)o=C,n=s;else if(e===$)if(f==="*"&&t===u.SELECTOR_TYPE)o=O,n=l;else if(c==="*"&&m===u.SELECTOR_TYPE)o=C,n=s;else if(r===2){const{name:p}=h;/^[+~]$/.test(p)?(o=O,n=l):(o=C,n=s)}else o=C,n=s;else if(c==="*"&&m===u.SELECTOR_TYPE)o=C,n=s;else if(f==="*"&&t===u.SELECTOR_TYPE)o=O,n=l;else{let p;for(const{combo:b,leaves:[_]}of i){const{type:N}=_,k=(0,y.unescapeSelector)(_.name);if(_.name=k,N===u.SELECTOR_PSEUDO_CLASS&&k==="dir"){p=!1;break}if(!p&&b){const{name:d}=b;/^[+~]$/.test(d)&&(p=!0)}}p?(o=C,n=s):(o=O,n=l)}}else o=O,n=s;return{complex:a,dir:o,twig:n}}_collectNodes(i){const e=this.#a.values();if(i===$||i===E){const r=new Set;let a=0;for(const{branch:s}of e){const{complex:o,dir:n,twig:h}=this._getEntryTwig(s,i),{collected:f,compound:t,filtered:l,nodes:c,pending:m}=this._findEntryNodes(h,i,o);c.length?(this.#a[a].find=!0,this.#h[a]=c):m&&r.add(new Map([["index",a],["twig",h]])),this.#a[a].collected=f,this.#a[a].dir=n,this.#a[a].filtered=l||!t,a++}if(r.size){let s,o;this.#e!==this.#s&&this.#e.nodeType===u.ELEMENT_NODE?(s=this.#e,o=this.#n):(s=this.#s,o=this.#r);let n=this._traverse(s,o);for(;n;){let h=!1;if(this.#e.nodeType===u.ELEMENT_NODE?n===this.#e?h=!0:h=this.#e.contains(n):h=!0,h)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const c=f.get("index");this.#a[c].filtered=!0,this.#a[c].find=!0,this.#h[c].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let r=0;for(const{branch:a}of e){const s=a[a.length-1],o=a.length>1,{compound:n,filtered:h,nodes:f}=this._findEntryNodes(s,i,o);f.length&&(this.#a[r].find=!0,this.#h[r]=f),this.#a[r].dir=O,this.#a[r].filtered=h||!n,r++}}return[this.#a,this.#h]}_getCombinedNodes(i,e,r){const a=[];for(const s of e){const o=this._matchCombinator(i,s,{dir:r,warn:this.#i});o.size&&a.push(...o)}return a.length?new Set(a):new Set}_matchNodeNext(i,e,r){const{combo:a,index:s}=r,{combo:o,leaves:n}=i[s],h={combo:a,leaves:n},f=this._getCombinedNodes(h,e,C);let t;if(f.size)if(s===i.length-1){const[l]=(0,L.sortNodes)(f);t=l}else t=this._matchNodeNext(i,f,{combo:o,index:s+1});return t??null}_matchNodePrev(i,e,r){const{index:a}=r,s=i[a],o=new Set([e]),n=this._getCombinedNodes(s,o,O);let h;if(n.size){if(a===0)h=e;else for(const f of n)if(this._matchNodePrev(i,f,{index:a-1}))return e}return h??null}_matchNodes(i){const[[...e],r]=this._collectNodes(i),a=e.length;let s=new Set;for(let o=0;o<a;o++){const{branch:n,collected:h,dir:f,find:t}=e[o],l=n.length;if(l&&t){const c=r[o],m=c.length,p=l-1;if(p===0)if((i===$||i===E)&&this.#e.nodeType===u.ELEMENT_NODE)for(let b=0;b<m;b++){const _=c[b];if(_!==this.#e&&this.#e.contains(_)&&(s.add(_),i!==$))break}else if(i===$)if(s.size){const b=[...s];s=new Set([...b,...c]),this.#u=!0}else s=new Set(c);else{const[b]=c;s.add(b)}else if(i===$)if(f===C){let{combo:b}=n[0];for(const _ of c){let N=new Set([_]);for(let k=1;k<l;k++){const{combo:d,leaves:w}=n[k],g={combo:b,leaves:w};if(N=this._getCombinedNodes(g,N,f),N.size)if(k===p)if(s.size){const x=[...s];s=new Set([...x,...N]),this.#u=!0}else s=N;else b=d;else break}}}else for(const b of c){let _=new Set([b]);for(let N=p-1;N>=0;N--){const k=n[N];if(_=this._getCombinedNodes(k,_,f),_.size)N===0&&(s.add(b),l>1&&s.size>1&&(this.#u=!0));else break}}else if(i===E&&f===C){const{combo:b}=n[0];let _;for(const N of c)if(_=this._matchNodeNext(n,new Set([N]),{combo:b,index:1}),_){s.add(_);break}if(!_&&!h){const{leaves:N}=n[0],[k]=c;let d=this._findNode(N,{node:k});for(;d;){if(_=this._matchNodeNext(n,new Set([d]),{combo:b,index:1}),_){s.add(_);break}d=this._findNode(N,{node:d})}}}else{let b;for(const _ of c)if(b=this._matchNodePrev(n,_,{index:p-1}),b){s.add(_);break}if(!b&&!h&&i===E){const{leaves:_}=n[p],[N]=c;let k=this._findNode(_,{node:N});for(;k;){if(b=this._matchNodePrev(n,k,{index:p-1}),b){s.add(k);break}k=this._findNode(_,{node:k})}}}}}return s}_find(i){return(i===$||i===E)&&this._prepareQuerySelectorWalker(),this._matchNodes(i)}matches(i,e,r){let a;try{if(e?.nodeType!==u.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,y.filterSelector)(i)?a=this.#c.match(i,e):(this._setup(i,e,r),a=this._find(D).size)}catch(s){this._onError(s)}return!!a}closest(i,e,r){let a;try{if(e?.nodeType!==u.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,y.filterSelector)(i))a=this.#c.closest(i,e);else{this._setup(i,e,r);const s=this._find(R);if(s.size){let o=this.#e;for(;o;){if(s.has(o)){a=o;break}o=o.parentNode}}}}catch(s){this._onError(s)}return a??null}querySelector(i,e,r){let a;try{if(this._setup(i,e,r),this.#f===this.#t&&!this.#o&&(0,y.filterSelector)(i))a=this.#c.first(i,e);else{const s=this._find(E);s.delete(this.#e),s.size&&([a]=(0,L.sortNodes)(s))}}catch(s){this._onError(s)}return a??null}querySelectorAll(i,e,r){let a;try{if(this._setup(i,e,r),this.#f===this.#t&&!this.#o&&(0,y.filterSelector)(i))a=this.#c.select(i,e);else{const s=this._find($);s.delete(this.#e),s.size&&(this.#u?a=(0,L.sortNodes)(s):a=[...s])}}catch(s){this._onError(s)}return a??[]}}0&&(module.exports={Finder}); | ||
var W=Object.create;var P=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(E,i)=>{for(var e in i)P(E,e,{get:i[e],enumerable:!0})},U=(E,i,e,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let a of B(i))!G.call(E,a)&&a!==e&&P(E,a,{get:()=>i[a],enumerable:!(r=H(i,a))||r.enumerable});return E};var z=(E,i,e)=>(e=E!=null?W(j(E)):{},U(i||!E||!E.__esModule?P(e,"default",{value:E,enumerable:!0}):e,E)),V=E=>U(P({},"__esModule",{value:!0}),E);var Y={};q(Y,{Finder:()=>X});module.exports=V(Y);var I=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),L=require("./dom-util.js"),M=require("./matcher.js"),y=require("./parser.js"),u=require("./constant.js");const C="next",O="prev",$="all",A="first",R="lineal",D="self";class X{#a;#l;#t;#o;#f;#e;#h;#w;#c;#n;#m;#s;#d;#u;#r;#b;#i;#p;constructor(i){this.#p=i,this.#f=i.document,this.#l=new WeakMap,this.#m=new WeakMap,this.#c=(0,F.default)({document:i.document,DOMException:i.DOMException}),this.#c.configure({LOGERRORS:!1})}_onError(i){if(!this.#w)if(i instanceof DOMException||i instanceof this.#p.DOMException)if(i.name===u.NOT_SUPPORTED_ERR)this.#i&&console.warn(i.message);else throw new this.#p.DOMException(i.message,i.name);else throw i}_setup(i,e,r={}){const{noexcept:a,warn:s}=r;return this.#w=!!a,this.#i=!!s,this.#e=e,[this.#t,this.#s,this.#r]=(0,L.resolveContent)(e),this.#d=(0,L.isInShadowTree)(e),[this.#a,this.#h]=this._correspond(i),this.#b=new WeakMap,e}_correspond(i){const e=[];this.#o=!1;let r;if(this.#t){const a=this.#l.get(this.#t);if(a&&a.has(`${i}`)){const s=a.get(`${i}`);this.#o=s.descendant,r=s.ast}}if(r){const a=r.length;for(let s=0;s<a;s++)r[s].collected=!1,r[s].dir=null,r[s].filtered=!1,r[s].find=!1,e[s]=[]}else{let a;try{a=(0,y.parseSelector)(i)}catch(h){this._onError(h)}const s=(0,y.walkAST)(a);let o=!1,n=0;r=[];for(const[...h]of s){const f=[];let t=h.shift();if(t&&t.type!==u.COMBINATOR){const l=new Set;for(;t;){if(t.type===u.COMBINATOR){const[c]=h;if(c.type===u.COMBINATOR){const p=`Invalid selector ${i}`;throw new DOMException(p,u.SYNTAX_ERR)}const m=t.name;/^[\s>]$/.test(m)&&(o=!0),f.push({combo:t,leaves:(0,y.sortAST)(l)}),l.clear()}else if(t){let{name:c}=t;c&&typeof c=="string"&&(c=(0,y.unescapeSelector)(c),t.name=c,/[|:]/.test(c)&&(t.namespace=!0)),l.add(t)}if(h.length)t=h.shift();else{f.push({combo:null,leaves:(0,y.sortAST)(l)}),l.clear();break}}}r.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#t){let h;this.#l.has(this.#t)?h=this.#l.get(this.#t):h=new Map,h.set(`${i}`,{ast:r,descendant:o}),this.#l.set(this.#t,h)}this.#o=o}return[r,e]}_createTreeWalker(i){let e;return this.#b.has(i)?e=this.#b.get(i):(e=this.#f.createTreeWalker(i,u.WALKER_FILTER),this.#b.set(i,e)),e}_prepareQuerySelectorWalker(){return this.#n=this._createTreeWalker(this.#e),this.#u=!1,this.#n}_traverse(i,e=this.#r){let r=e.currentNode,a;if(r===i)a=r;else if(r.contains(i))for(r=e.nextNode();r;){if(r===i){a=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===i);)r=e.parentNode();if(i?.nodeType===u.ELEMENT_NODE)for(;r;){if(r===i){a=r;break}r=e.nextNode()}else a=r}return a??null}_collectNthChild(i,e,r){const{a,b:s,reverse:o,selector:n}=i,{parentNode:h}=e,f=new Set;let t;if(n&&(this.#l.has(n)?t=this.#l.get(n):(t=(0,y.walkAST)(n),this.#l.set(n,t))),h){const l=this.#r;let c=this._traverse(h,l);c=l.firstChild();let m=0;for(;c;)m++,c=l.nextSibling();c=this._traverse(h,l);const p=new Set;if(t)for(c=l.firstChild();c;){let b;for(const _ of t)if(b=this._matchLeaves(_,c,r),!b)break;b&&p.add(c),c=l.nextSibling()}if(a===0){if(s>0&&s<=m){if(p.size){c=this._traverse(h,l),o?c=l.lastChild():c=l.firstChild();let b=0;for(;c;){if(p.has(c)){if(b===s-1){f.add(c);break}b++}o?c=l.previousSibling():c=l.nextSibling()}}else if(!n){c=this._traverse(h,l),o?c=l.lastChild():c=l.firstChild();let b=0;for(;c;){if(b===s-1){f.add(c);break}o?c=l.previousSibling():c=l.nextSibling(),b++}}}}else{let b=s-1;if(a>0)for(;b<0;)b+=a;if(b>=0&&b<m){c=this._traverse(h,l),o?c=l.lastChild():c=l.firstChild();let _=0,N=a>0?0:s-1;for(;c&&(c&&b>=0&&b<m);)p.size?p.has(c)&&(N===b&&(f.add(c),b+=a),a>0?N++:N--):_===b&&(n||f.add(c),b+=a),o?c=l.previousSibling():c=l.nextSibling(),_++}}if(o&&f.size>1){const b=[...f];return new Set(b.reverse())}}else if(e===this.#s&&a+s===1)if(t){let l;for(const c of t)if(l=this._matchLeaves(c,e,r),l)break;l&&f.add(e)}else f.add(e);return f}_collectNthOfType(i,e){const{a:r,b:a,reverse:s}=i,{localName:o,parentNode:n,prefix:h}=e,f=new Set;if(n){const t=this.#r;let l=this._traverse(n,t);l=t.firstChild();let c=0;for(;l;)c++,l=t.nextSibling();if(r===0){if(a>0&&a<=c){l=this._traverse(n,t),s?l=t.lastChild():l=t.firstChild();let m=0;for(;l;){const{localName:p,prefix:b}=l;if(p===o&&b===h){if(m===a-1){f.add(l);break}m++}s?l=t.previousSibling():l=t.nextSibling()}}}else{let m=a-1;if(r>0)for(;m<0;)m+=r;if(m>=0&&m<c){l=this._traverse(n,t),s?l=t.lastChild():l=t.firstChild();let p=r>0?0:a-1;for(;l;){const{localName:b,prefix:_}=l;if(b===o&&_===h){if(p===m&&(f.add(l),m+=r),m<0||m>=c)break;r>0?p++:p--}s?l=t.previousSibling():l=t.nextSibling()}}}if(s&&f.size>1){const m=[...f];return new Set(m.reverse())}}else e===this.#s&&r+a===1&&f.add(e);return f}_matchAnPlusB(i,e,r,a){const{nth:{a:s,b:o,name:n},selector:h}=i,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?f.set("b",o*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){h&&f.set("selector",h);const t=Object.fromEntries(f);return this._collectNthChild(t,e,a)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchDirectionPseudoClass(i,e){const r=(0,L.getDirectionality)(e);let a;return i.name===r&&(a=e),a??null}_matchLanguagePseudoClass(i,e){if(i.name===u.EMPTY)return null;const r=(0,y.unescapeSelector)(i.name);i.name=r;let a;if(r==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(a=e);else{let s=e.parentNode;for(;s&&s.nodeType===u.ELEMENT_NODE;){if(s.hasAttribute("lang")){s.getAttribute("lang")&&(a=e);break}s=s.parentNode}}else if(r){const s=`(?:-${u.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${u.ALPHA_NUM}${s}$`,"i").test(r)){let n;if(r.indexOf("-")>-1){const[h,f,...t]=r.split("-");let l;h==="*"?l=`${u.ALPHA_NUM}${s}`:l=`${h}${s}`;const c=`-${f}${s}`,m=t.length;let p="";if(m)for(let b=0;b<m;b++)p+=`-${t[b]}${s}`;n=new RegExp(`^${l}${c}${p}$`,"i")}else n=new RegExp(`^${r}${s}$`,"i");if(e.hasAttribute("lang"))n.test(e.getAttribute("lang"))&&(a=e);else{let h=e.parentNode;for(;h&&h.nodeType===u.ELEMENT_NODE;){if(h.hasAttribute("lang")){const f=h.getAttribute("lang");n.test(f)&&(a=e);break}h=h.parentNode}}}}return a??null}_matchHasPseudoFunc(i,e,r={}){let a;if(Array.isArray(i)&&i.length){const[s]=i,{type:o}=s;let n;o===u.COMBINATOR?n=i.shift():n={name:" ",type:u.COMBINATOR};const h=[];for(;i.length;){const[l]=i,{type:c}=l;if(c===u.COMBINATOR)break;h.push(i.shift())}const f={combo:n,leaves:h};r.dir=C;const t=this._matchCombinator(f,e,r);if(t.size)if(i.length){for(const l of t)if(a=this._matchHasPseudoFunc(Object.assign([],i),l,r),a)break}else a=!0}return!!a}_matchLogicalPseudoFunc(i,e,r={}){const{astName:a="",branches:s=[],selector:o="",twigBranches:n=[]}=i;let h;if(a==="has")if(o.includes(":has("))h=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(h=e)}else{const f=/^(?:is|where)$/.test(a);r.forgive=f;const t=n.length;let l;for(let c=0;c<t;c++){const m=n[c],p=m.length-1,{leaves:b}=m[p];if(l=this._matchLeaves(b,e,r),l&&p>0){let _=new Set([e]);for(let N=p-1;N>=0;N--){const k=m[N],d=[];r.dir=O;for(const w of _){const g=this._matchCombinator(k,w,r);g.size&&d.push(...g)}if(d.length)N===0?l=!0:_=new Set(d);else{l=!1;break}}}if(l)break}a==="not"?l||(h=e):l&&(h=e)}return h??null}_matchPseudoClassSelector(i,e,r={}){const{children:a,name:s}=i,{localName:o,parentNode:n}=e,{forgive:h,warn:f=this.#i}=r,t=new Set;if(u.REG_LOGICAL_PSEUDO.test(s)){let l;if(this.#l.has(i))l=this.#l.get(i);else{const m=(0,y.walkAST)(i),p=[],b=[];for(const[..._]of m){for(const w of _){const g=(0,y.generateCSS)(w);p.push(g)}const N=[],k=new Set;let d=_.shift();for(;d;)if(d.type===u.COMBINATOR?(N.push({combo:d,leaves:[...k]}),k.clear()):d&&k.add(d),_.length)d=_.shift();else{N.push({combo:null,leaves:[...k]}),k.clear();break}b.push(N)}l={astName:s,branches:m,twigBranches:b,selector:p.join(",")},this.#l.set(i,l)}const c=this._matchLogicalPseudoFunc(l,e,r);c&&t.add(c)}else if(Array.isArray(a)){const[l]=a;if(/^nth-(?:last-)?(?:child|of-type)$/.test(s))return this._matchAnPlusB(l,e,s,r);if(s==="dir"){const c=this._matchDirectionPseudoClass(l,e);c&&t.add(c)}else if(s==="lang"){const c=this._matchLanguagePseudoClass(l,e);c&&t.add(c)}else switch(s){case"current":case"nth-col":case"nth-last-col":{if(f){const c=`Unsupported pseudo-class :${s}()`;throw new DOMException(c,u.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!h){const c=`Unknown pseudo-class :${s}()`;throw new DOMException(c,u.SYNTAX_ERR)}}}else{const l=/^a(?:rea)?$/,c=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,m=/^(?:(?:inpu|selec)t|button|form|textarea)$/,p=/^d(?:etails|ialog)$/,b=/^(?:checkbox|radio)$/,_=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,k=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(s){case"any-link":case"link":{l.test(o)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(l.test(o)&&e.hasAttribute("href")){const{href:d,origin:w,pathname:g}=new URL(this.#t.URL),x=new URL(e.getAttribute("href"),d);x.origin===w&&x.pathname===g&&t.add(e)}break}case"visited":break;case"target":{const{hash:d}=new URL(this.#t.URL);e.id&&d===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:d}=new URL(this.#t.URL);if(d){const w=d.replace(/^#/,"");let g=this.#t.getElementById(w);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===u.ELEMENT_NODE?!this.#d&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":{if(e===this.#t.activeElement){let d=e,w=!0;for(;d;){if(d.hasAttribute("hidden")){w=!1;break}else if(d.hasAttribute("style")){const{display:g,visibility:x}=d.style;if(w=!(g==="none"||x==="hidden"),!w)break}if(d.parentNode&&d.parentNode.nodeType===u.ELEMENT_NODE)d=d.parentNode;else break}w&&t.add(e)}break}case"focus-within":{let d=this.#t.activeElement,w;for(;d;){if(d===e){w=!0;break}d=d.parentNode}if(w){let g=e,x=!0;for(;g;){if(g.hasAttribute("hidden")){x=!1;break}else if(g.hasAttribute("style")){const{display:v,visibility:T}=g.style;if(x=!(v==="none"||T==="hidden"),!x)break}if(g.parentNode&&g.parentNode.nodeType===u.ELEMENT_NODE)g=g.parentNode;else break}x&&t.add(e)}break}case"open":{p.test(o)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{p.test(o)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(c.test(o)||(0,I.default)(o))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let d=n;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&n.localName!=="legend"&&d.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(c.test(o)||(0,I.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||_.test(e.type)||k.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,L.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||_.test(e.type)||k.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,L.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let d;o==="textarea"?d=e:o==="input"&&(e.hasAttribute("type")?k.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))||e.selected&&o==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))t.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;w||(w=this.#t.documentElement);const g=w.getElementsByTagName("input"),x=g.length;let v;for(let T=0;T<x;T++){const S=g[T];if(S.getAttribute("type")==="radio"&&(d?S.getAttribute("name")===d&&(v=!!S.checked):S.hasAttribute("name")||(v=!!S.checked),v))break}v||t.add(e)}break}case"default":{const d=/^(?:button|reset)$/,w=/^(?:image|submit)$/;if(o==="button"&&!(e.hasAttribute("type")&&d.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))){let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;if(g){const x=this.#r;let v=this._traverse(g,x);for(v=x.firstChild();v&&g.contains(v);){const T=v.localName;let S;if(T==="button"?S=!(v.hasAttribute("type")&&d.test(v.getAttribute("type"))):T==="input"&&(S=v.hasAttribute("type")&&w.test(v.getAttribute("type"))),S){v===e&&t.add(e);break}v=x.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(o==="option"){let g=n,x=!1;for(;g&&g.localName!=="datalist";){if(g.localName==="select"){(g.multiple||g.hasAttribute("multiple"))&&(x=!0);break}g=g.parentNode}if(x)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,T=this.#r;let S=this._traverse(n,T);for(S=T.firstChild();S;){if(S.selected||S.hasAttribute("selected")){v.add(S);break}S=T.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(m.test(o))e.checkValidity()&&t.add(e);else if(o==="fieldset"){const d=this.#r;let w=this._traverse(e,d);w=d.firstChild();let g;for(;w&&e.contains(w)&&!(m.test(w.localName)&&(g=w.checkValidity(),!g));)w=d.nextNode();g&&t.add(e)}break}case"invalid":{if(m.test(o))e.checkValidity()||t.add(e);else if(o==="fieldset"){const d=this.#r;let w=this._traverse(e,d);w=d.firstChild();let g;for(;w&&e.contains(w)&&!(m.test(w.localName)&&(g=w.checkValidity(),!g));)w=d.nextNode();g||t.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let d;if(/^(?:select|textarea)$/.test(o))d=e;else if(o==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||_.test(w)||k.test(w))&&(d=e)}else d=e;d&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let d;if(/^(?:select|textarea)$/.test(o))d=e;else if(o==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||_.test(w)||k.test(w))&&(d=e)}else d=e;d&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const d=this.#f.createTreeWalker(e,u.SHOW_ALL);let w=d.firstChild(),g;for(;w&&(g=w.nodeType!==u.ELEMENT_NODE&&w.nodeType!==u.TEXT_NODE,!!g);)w=d.nextSibling();g&&t.add(e)}else t.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);d&&t.add(d)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1,reverse:!0},e);d&&t.add(d)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);if(d===e){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const d=`Unsupported pseudo-element ::${s}`;throw new DOMException(d,u.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"defined":case"focus-visible":case"fullscreen":case"future":case"hover":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(f){const d=`Unsupported pseudo-class :${s}`;throw new DOMException(d,u.NOT_SUPPORTED_ERR)}break}default:if(s.startsWith("-webkit-")){if(f){const d=`Unsupported pseudo-class :${s}`;throw new DOMException(d,u.NOT_SUPPORTED_ERR)}}else if(!h){const d=`Unknown pseudo-class :${s}`;throw new DOMException(d,u.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(i,e){const{children:r,name:a}=i;let s;if(Array.isArray(r)){const[o]=(0,y.walkAST)(r[0]),[...n]=o,{host:h}=e;if(a==="host"){let f;for(const t of n){const{type:l}=t;if(l===u.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(i)}`;throw new DOMException(m,u.SYNTAX_ERR)}if(f=this._matchSelector(t,h).has(h),!f)break}f&&(s=e)}else if(a==="host-context"){let f=h,t;for(;f;){for(const l of n){const{type:c}=l;if(c===u.COMBINATOR){const p=`Invalid selector ${(0,y.generateCSS)(i)}`;throw new DOMException(p,u.SYNTAX_ERR)}if(t=this._matchSelector(l,f).has(f),!t)break}if(t)break;f=f.parentNode}t&&(s=e)}}else if(a==="host")s=e;else{const o=`Invalid selector :${a}`;throw new DOMException(o,u.SYNTAX_ERR)}return s??null}_matchSelector(i,e,r){const{type:a}=i,s=new Set;if(i.name===u.EMPTY)return s;const o=(0,y.unescapeSelector)(i.name);if(i.name=o,e.nodeType===u.ELEMENT_NODE)switch(a){case u.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(o,r);break}case u.SELECTOR_ID:{e.id===o&&s.add(e);break}case u.SELECTOR_CLASS:{e.classList.contains(o)&&s.add(e);break}case u.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(i,e,r);default:{const n=(0,M.matchSelector)(i,e,r);n&&s.add(n)}}else if(this.#d&&a===u.SELECTOR_PSEUDO_CLASS&&e.nodeType===u.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&u.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(i,e,r);if(u.REG_SHADOW_HOST.test(o)){const n=this._matchShadowHostPseudoClass(i,e,r);n&&s.add(n)}}return s}_matchLeaves(i,e,r){const{attributes:a,localName:s,nodeType:o}=e;let n=this.#m.get(i),h;if(n&&n.has(e)){const{attr:f,matched:t}=n.get(e);a?.length===f&&(h=t)}if(typeof h!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;o===u.ELEMENT_NODE&&f.test(s)?t=!1:t=!0;for(const l of i){const{name:c,type:m}=l,p=(0,y.unescapeSelector)(c);if(l.name=p,m===u.SELECTOR_PSEUDO_CLASS&&p==="dir"&&(t=!1),h=this._matchSelector(l,e,r).has(e),!h)break}t&&(n||(n=new WeakMap),n.set(e,{attr:a?.length,matched:h}),this.#m.set(i,n))}return!!h}_matchHTMLCollection(i,e={}){const{compound:r,filterLeaves:a}=e,s=new Set,o=i.length;if(o)if(r)for(let n=0;n<o;n++){const h=i[n];this._matchLeaves(a,h,e)&&s.add(h)}else{const n=[].slice.call(i);return new Set(n)}return s}_findDescendantNodes(i,e,r){const[a,...s]=i,o=s.length>0,{type:n}=a,h=(0,y.unescapeSelector)(a.name);a.name=h;let f=new Set,t=!1;if(this.#d)t=!0;else switch(n){case u.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(h,r);break}case u.SELECTOR_ID:{if(this.#s.nodeType===u.ELEMENT_NODE)t=!0;else{const l=this.#s.getElementById(h);l&&l!==e&&e.contains(l)&&(o?this._matchLeaves(s,l,r)&&f.add(l):f.add(l))}break}case u.SELECTOR_CLASS:{const l=e.getElementsByClassName(h);f=this._matchHTMLCollection(l,{compound:o,filterLeaves:s});break}case u.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(h)){const l=e.getElementsByTagName(h);f=this._matchHTMLCollection(l,{compound:o,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(i,e,r={}){const{combo:a,leaves:s}=i,{name:o}=a,{parentNode:n}=e,{dir:h}=r,f=new Set;if(h===C)switch(o){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let l=this._traverse(e,t);for(l=t.nextSibling();l;)this._matchLeaves(s,l,r)&&f.add(l),l=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let l=this._traverse(e,t);for(l=t.firstChild();l;)this._matchLeaves(s,l,r)&&f.add(l),l=t.nextSibling();break}case" ":default:{const{nodes:t,pending:l}=this._findDescendantNodes(s,e);if(t.size)return t;if(l){const c=this._createTreeWalker(e);let m=this._traverse(e,c);for(m=c.nextNode();m&&e.contains(m);)this._matchLeaves(s,m,r)&&f.add(m),m=c.nextNode()}}}else switch(o){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let l=this._traverse(n,t);for(l=t.firstChild();l&&l!==e;)this._matchLeaves(s,l,r)&&f.add(l),l=t.nextSibling()}break}case">":{n&&this._matchLeaves(s,n,r)&&f.add(n);break}case" ":default:{const t=[];let l=n;for(;l;)this._matchLeaves(s,l,r)&&t.push(l),l=l.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(i,e){const{node:r}=e;let a=this._traverse(r,this.#n),s;if(a)for(a.nodeType!==u.ELEMENT_NODE?a=this.#n.nextNode():a===r&&a!==this.#s&&(a=this.#n.nextNode());a;){if(this._matchLeaves(i,a,{warn:this.#i})){s=a;break}a=this.#n.nextNode()}return s??null}_matchSelf(i){const e=[],r=this._matchLeaves(i,this.#e,{warn:this.#i});let a=!1;return r&&(e.push(this.#e),a=!0),[e,a]}_findLineal(i,e={}){const{complex:r}=e,a=[];let s=this._matchLeaves(i,this.#e,{warn:this.#i}),o=!1;if(s&&(a.push(this.#e),o=!0),!s||r){let n=this.#e.parentNode;for(;n&&(s=this._matchLeaves(i,n,{warn:this.#i}),s&&(a.push(n),o=!0),n.parentNode);)n=n.parentNode}return[a,o]}_findFirst(i){const e=[],r=this._findNode(i,{node:this.#e});let a=!1;return r&&(e.push(r),a=!0),[e,a]}_findFromHTMLCollection(i,e={}){const{complex:r,compound:a,filterLeaves:s,targetType:o}=e;let n=[],h=!1,f=!1;const t=i.length;if(t)if(this.#e.nodeType===u.ELEMENT_NODE)for(let l=0;l<t;l++){const c=i[l];if(c!==this.#e&&(this.#e.contains(c)||c.contains(this.#e))){if(a){if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),h=!0,o===A))break}else if(n.push(c),h=!0,o===A)break}}else if(r)if(a)for(let l=0;l<t;l++){const c=i[l];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),h=!0,o===A))break}else n=[].slice.call(i),h=!0,f=!0;else if(a)for(let l=0;l<t;l++){const c=i[l];if(this._matchLeaves(s,c,{warn:this.#i})&&(n.push(c),h=!0,o===A))break}else n=[].slice.call(i),h=!0,f=!0;return[n,h,f]}_findEntryNodes(i,e,r){const{leaves:a}=i,[s,...o]=a,n=o.length>0,{type:h}=s,f=(0,y.unescapeSelector)(s.name);s.name=f;let t=[],l=!1,c=!1,m=!1;switch(h){case u.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(f,{warn:this.#i});break}case u.SELECTOR_ID:{if(e===D)[t,c]=this._matchSelf(a);else if(e===R)[t,c]=this._findLineal(a,{complex:r});else if(e===A&&this.#s.nodeType!==u.ELEMENT_NODE){const p=this.#s.getElementById(f);p&&(n?this._matchLeaves(o,p,{warn:this.#i})&&(t.push(p),c=!0):(t.push(p),c=!0))}else e===A?[t,c]=this._findFirst(a):m=!0;break}case u.SELECTOR_CLASS:{if(e===D)[t,c]=this._matchSelf(a);else if(e===R)[t,c]=this._findLineal(a,{complex:r});else if(this.#s.nodeType===u.DOCUMENT_NODE){const p=this.#s.getElementsByClassName(f);p.length&&([t,c,l]=this._findFromHTMLCollection(p,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(a):m=!0;break}case u.SELECTOR_TYPE:{if(e===D)[t,c]=this._matchSelf(a);else if(e===R)[t,c]=this._findLineal(a,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===u.DOCUMENT_NODE&&!/[*|]/.test(f)){const p=this.#s.getElementsByTagName(f);p.length&&([t,c,l]=this._findFromHTMLCollection(p,{complex:r,compound:n,filterLeaves:o,targetType:e}))}else e===A?[t,c]=this._findFirst(a):m=!0;break}default:if(e!==R&&u.REG_SHADOW_HOST.test(f)){if(this.#d&&this.#e.nodeType===u.DOCUMENT_FRAGMENT_NODE){const p=this._matchShadowHostPseudoClass(s,this.#e);p&&(t.push(p),c=!0)}}else e===D?[t,c]=this._matchSelf(a):e===R?[t,c]=this._findLineal(a,{complex:r}):e===A?[t,c]=this._findFirst(a):m=!0}return{collected:l,compound:n,filtered:c,nodes:t,pending:m}}_getEntryTwig(i,e){const r=i.length,a=r>1,s=i[0];let o,n;if(a){const{combo:h,leaves:[{name:f,type:t}]}=s,l=i[r-1],{leaves:[{name:c,type:m}]}=l;if(m===u.SELECTOR_PSEUDO_ELEMENT||m===u.SELECTOR_ID)o=O,n=l;else if(t===u.SELECTOR_PSEUDO_ELEMENT||t===u.SELECTOR_ID)o=C,n=s;else if(e===$)if(f==="*"&&t===u.SELECTOR_TYPE)o=O,n=l;else if(c==="*"&&m===u.SELECTOR_TYPE)o=C,n=s;else if(r===2){const{name:p}=h;/^[+~]$/.test(p)?(o=O,n=l):(o=C,n=s)}else o=C,n=s;else if(c==="*"&&m===u.SELECTOR_TYPE)o=C,n=s;else if(f==="*"&&t===u.SELECTOR_TYPE)o=O,n=l;else{let p;for(const{combo:b,leaves:[_]}of i){const{type:N}=_,k=(0,y.unescapeSelector)(_.name);if(_.name=k,N===u.SELECTOR_PSEUDO_CLASS&&k==="dir"){p=!1;break}if(!p&&b){const{name:d}=b;/^[+~]$/.test(d)&&(p=!0)}}p?(o=C,n=s):(o=O,n=l)}}else o=O,n=s;return{complex:a,dir:o,twig:n}}_collectNodes(i){const e=this.#a.values();if(i===$||i===A){const r=new Set;let a=0;for(const{branch:s}of e){const{complex:o,dir:n,twig:h}=this._getEntryTwig(s,i),{collected:f,compound:t,filtered:l,nodes:c,pending:m}=this._findEntryNodes(h,i,o);c.length?(this.#a[a].find=!0,this.#h[a]=c):m&&r.add(new Map([["index",a],["twig",h]])),this.#a[a].collected=f,this.#a[a].dir=n,this.#a[a].filtered=l||!t,a++}if(r.size){let s,o;this.#e!==this.#s&&this.#e.nodeType===u.ELEMENT_NODE?(s=this.#e,o=this.#n):(s=this.#s,o=this.#r);let n=this._traverse(s,o);for(;n;){let h=!1;if(this.#e.nodeType===u.ELEMENT_NODE?n===this.#e?h=!0:h=this.#e.contains(n):h=!0,h)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const c=f.get("index");this.#a[c].filtered=!0,this.#a[c].find=!0,this.#h[c].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let r=0;for(const{branch:a}of e){const s=a[a.length-1],o=a.length>1,{compound:n,filtered:h,nodes:f}=this._findEntryNodes(s,i,o);f.length&&(this.#a[r].find=!0,this.#h[r]=f),this.#a[r].dir=O,this.#a[r].filtered=h||!n,r++}}return[this.#a,this.#h]}_getCombinedNodes(i,e,r){const a=[];for(const s of e){const o=this._matchCombinator(i,s,{dir:r,warn:this.#i});o.size&&a.push(...o)}return a.length?new Set(a):new Set}_matchNodeNext(i,e,r){const{combo:a,index:s}=r,{combo:o,leaves:n}=i[s],h={combo:a,leaves:n},f=this._getCombinedNodes(h,e,C);let t;if(f.size)if(s===i.length-1){const[l]=(0,L.sortNodes)(f);t=l}else t=this._matchNodeNext(i,f,{combo:o,index:s+1});return t??null}_matchNodePrev(i,e,r){const{index:a}=r,s=i[a],o=new Set([e]),n=this._getCombinedNodes(s,o,O);let h;if(n.size){if(a===0)h=e;else for(const f of n)if(this._matchNodePrev(i,f,{index:a-1}))return e}return h??null}_matchNodes(i){const[[...e],r]=this._collectNodes(i),a=e.length;let s=new Set;for(let o=0;o<a;o++){const{branch:n,collected:h,dir:f,find:t}=e[o],l=n.length;if(l&&t){const c=r[o],m=c.length,p=l-1;if(p===0)if((i===$||i===A)&&this.#e.nodeType===u.ELEMENT_NODE)for(let b=0;b<m;b++){const _=c[b];if(_!==this.#e&&this.#e.contains(_)&&(s.add(_),i!==$))break}else if(i===$)if(s.size){const b=[...s];s=new Set([...b,...c]),this.#u=!0}else s=new Set(c);else{const[b]=c;s.add(b)}else if(i===$)if(f===C){let{combo:b}=n[0];for(const _ of c){let N=new Set([_]);for(let k=1;k<l;k++){const{combo:d,leaves:w}=n[k],g={combo:b,leaves:w};if(N=this._getCombinedNodes(g,N,f),N.size)if(k===p)if(s.size){const x=[...s];s=new Set([...x,...N]),this.#u=!0}else s=N;else b=d;else break}}}else for(const b of c){let _=new Set([b]);for(let N=p-1;N>=0;N--){const k=n[N];if(_=this._getCombinedNodes(k,_,f),_.size)N===0&&(s.add(b),l>1&&s.size>1&&(this.#u=!0));else break}}else if(i===A&&f===C){const{combo:b}=n[0];let _;for(const N of c)if(_=this._matchNodeNext(n,new Set([N]),{combo:b,index:1}),_){s.add(_);break}if(!_&&!h){const{leaves:N}=n[0],[k]=c;let d=this._findNode(N,{node:k});for(;d;){if(_=this._matchNodeNext(n,new Set([d]),{combo:b,index:1}),_){s.add(_);break}d=this._findNode(N,{node:d})}}}else{let b;for(const _ of c)if(b=this._matchNodePrev(n,_,{index:p-1}),b){s.add(_);break}if(!b&&!h&&i===A){const{leaves:_}=n[p],[N]=c;let k=this._findNode(_,{node:N});for(;k;){if(b=this._matchNodePrev(n,k,{index:p-1}),b){s.add(k);break}k=this._findNode(_,{node:k})}}}}}return s}_find(i){return(i===$||i===A)&&this._prepareQuerySelectorWalker(),this._matchNodes(i)}matches(i,e,r){let a;try{if(e?.nodeType!==u.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,y.filterSelector)(i)?a=this.#c.match(i,e):(this._setup(i,e,r),a=this._find(D).size)}catch(s){this._onError(s)}return!!a}closest(i,e,r){let a;try{if(e?.nodeType!==u.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,y.filterSelector)(i))a=this.#c.closest(i,e);else{this._setup(i,e,r);const s=this._find(R);if(s.size){let o=this.#e;for(;o;){if(s.has(o)){a=o;break}o=o.parentNode}}}}catch(s){this._onError(s)}return a??null}querySelector(i,e,r){let a;try{if(this._setup(i,e,r),this.#f===this.#t&&!this.#o&&(0,y.filterSelector)(i))a=this.#c.first(i,e);else{const s=this._find(A);s.delete(this.#e),s.size&&([a]=(0,L.sortNodes)(s))}}catch(s){this._onError(s)}return a??null}querySelectorAll(i,e,r){let a;try{if(this._setup(i,e,r),this.#f===this.#t&&!this.#o&&(0,y.filterSelector)(i))a=this.#c.select(i,e);else{const s=this._find($);s.delete(this.#e),s.size&&(this.#u?a=(0,L.sortNodes)(s):a=[...s])}}catch(s){this._onError(s)}return a??[]}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -1,3 +0,3 @@ | ||
var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var O=(s,t)=>{for(var r in t)g(s,r,{get:t[r],enumerable:!0})},x=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of A(t))!y.call(s,n)&&n!==r&&g(s,n,{get:()=>t[n],enumerable:!(i=S(t,n))||i.enumerable});return s};var T=s=>x(g({},"__esModule",{value:!0}),s);var C={};O(C,{filterSelector:()=>L,generateCSS:()=>u.generate,parseAstName:()=>I,parseSelector:()=>h,preprocess:()=>E,sortAST:()=>$,unescapeSelector:()=>m,walkAST:()=>_});module.exports=T(C);var w=require("css-tree"),e=require("./constant.js"),u=require("css-tree");const m=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let i=1;i<r;i++){let n=t[i];if(n===""&&i===r-1)n=e.U_FFFD;else{const c=/^([\da-f]{1,6}\s?)/i.exec(n);if(c){const[,a]=c;let l;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),d=parseInt(a,e.HEX);d===0||d>=o&&d<=p?l=e.U_FFFD:l=String.fromCodePoint(d)}catch{l=e.U_FFFD}let f="";n.length>a.length&&(f=n.substring(a.length)),n=`${l}${f}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},E=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let n=t.substring(r+1);const c=n.codePointAt(0);if(c===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(c>e.BIT_FFFF){const a=`\\${c.toString(e.HEX)} `;n.length===e.DUO?n=a:n=`${a}${n.substring(e.DUO)}`}t=`${i}${n}`,r++}t=t.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},h=s=>{if(s=E(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,w.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,w.toPlainObject)(r)}catch(r){const i=/(:lang\(\s*("[A-Za-z\d\-*]+")\s*\))/;if(r.message==="Identifier is expected"&&i.test(s)){const[,n,c]=i.exec(s),a=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,""),l=n.replace(c,a);t=h(s.replace(n,l))}else if(r.message==='"]" is expected'&&!s.endsWith("]"))t=h(`${s}]`);else if(r.message==='")" is expected'&&!s.endsWith(")"))t=h(`${s})`);else throw new DOMException(r.message,e.SYNTAX_ERR)}return t},_=(s={})=>{const t=new Set;let r;return(0,w.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)||n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,w.findAll)(s,(n,c,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const l=a.filter(f=>{const{name:o,type:p}=f;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:f}of l)for(const{children:o}of f)for(const{children:p}of o)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const l=a.filter(f=>{const{name:o,type:p}=f;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:f}of l)for(const{children:o}of f)t.has(o)&&t.delete(o)}}}),[...t]},$=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,n)=>{const{type:c}=i,{type:a}=n,l=r.get(c),f=r.get(a);let o;return l===f?o=0:l>f?o=1:o=-1,o})}return t},I=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},L=s=>!(!s||typeof s!="string"||/\||::|\[\s*[\w$*=^|~-]+(?:\s+[\w$*=^|~-]+)+\s*\]|\[\s*[\w$*=^|~-]+["'][\w$*=^|~\s-]+['"]+\s+[\w$*=^|~-]+\s*\]/.test(s)||s.includes(":")&&/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|n|[+-]?(?:0|[1-9]\d*)n?|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(s));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var A=(s,t)=>{for(var r in t)g(s,r,{get:t[r],enumerable:!0})},O=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!y.call(s,n)&&n!==r&&g(s,n,{get:()=>t[n],enumerable:!(i=S(t,n))||i.enumerable});return s};var T=s=>O(g({},"__esModule",{value:!0}),s);var C={};A(C,{filterSelector:()=>L,generateCSS:()=>u.generate,parseAstName:()=>I,parseSelector:()=>h,preprocess:()=>E,sortAST:()=>_,unescapeSelector:()=>$,walkAST:()=>m});module.exports=T(C);var d=require("css-tree"),e=require("./constant.js"),u=require("css-tree");const $=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let i=1;i<r;i++){let n=t[i];if(n===""&&i===r-1)n=e.U_FFFD;else{const f=/^([\da-f]{1,6}\s?)/i.exec(n);if(f){const[,a]=f;let c;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),w=parseInt(a,e.HEX);w===0||w>=o&&w<=p?c=e.U_FFFD:c=String.fromCodePoint(w)}catch{c=e.U_FFFD}let l="";n.length>a.length&&(l=n.substring(a.length)),n=`${c}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},E=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let n=t.substring(r+1);const f=n.codePointAt(0);if(f===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(f>e.BIT_FFFF){const a=`\\${f.toString(e.HEX)} `;n.length===e.DUO?n=a:n=`${a}${n.substring(e.DUO)}`}t=`${i}${n}`,r++}t=t.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},h=s=>{if(s=E(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,d.toPlainObject)(r)}catch(r){const{message:i}=r,n=/(:(is|where)\(\s*\))/,f=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;if(i==="Identifier is expected"&&f.test(s)){const[,a,c]=f.exec(s),l=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let o=a.replace(c,l);o===":lang()"&&(o=`:lang(${e.EMPTY})`),t=h(s.replace(a,o))}else if((i==="Identifier is expected"||i==="Selector is expected")&&n.test(s)){const[,a,c]=n.exec(s),l=`:${c}(${e.EMPTY})`;t=h(s.replace(a,l))}else if(i==='"]" is expected'&&!s.endsWith("]"))t=h(`${s}]`);else if(i==='")" is expected'&&!s.endsWith(")"))t=h(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set;let r;return(0,d.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)||n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,d.findAll)(s,(n,f,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)for(const{children:p}of o)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)t.has(o)&&t.delete(o)}}}),[...t]},_=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,n)=>{const{type:f}=i,{type:a}=n,c=r.get(f),l=r.get(a);let o;return c===l?o=0:c>l?o=1:o=-1,o})}return t},I=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},L=s=>!(!s||typeof s!="string"||/\||::|\[\s*[\w$*=^|~-]+(?:\s+[\w$*=^|~-]+)+\s*\]|\[\s*[\w$*=^|~-]+["'][\w$*=^|~\s-]+['"]+\s+[\w$*=^|~-]+\s*\]/.test(s)||s.includes(":")&&/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|n|[+-]?(?:0|[1-9]\d*)n?|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(s));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
//# sourceMappingURL=parser.js.map |
@@ -63,3 +63,3 @@ { | ||
}, | ||
"version": "4.1.2" | ||
"version": "4.1.3" | ||
} |
@@ -133,2 +133,3 @@ # DOM Selector | ||
|E:focus‑visible|Unsupported| | | ||
|E:open<br>E:closed|Partially supported|Matching on <select>, e.g. `select:open`, is not supported.| | ||
|E:enabled<br>E:disabled|✓| | | ||
@@ -178,5 +179,5 @@ |E:read‑write<br>E:read‑only|✓| | | ||
beforeParse: window => { | ||
const { | ||
closest, matches, querySelector, querySelectorAll | ||
} = new DOMSelector(window); | ||
const domSelector = new DOMSelector(window); | ||
const matches = domSelector.matches.bind(domSelector); | ||
window.Element.prototype.matches = function (...args) { | ||
@@ -189,2 +190,4 @@ if (!args.length) { | ||
}; | ||
const closest = domSelector.closest.bind(domSelector); | ||
window.Element.prototype.closest = function (...args) { | ||
@@ -197,2 +200,4 @@ if (!args.length) { | ||
}; | ||
const querySelector = domSelector.querySelector.bind(domSelector); | ||
window.Document.prototype.querySelector = function (...args) { | ||
@@ -219,2 +224,4 @@ if (!args.length) { | ||
}; | ||
const querySelectorAll = domSelector.querySelectorAll.bind(domSelector); | ||
window.Document.prototype.querySelectorAll = function (...args) { | ||
@@ -221,0 +228,0 @@ if (!args.length) { |
@@ -9,2 +9,3 @@ /** | ||
export const COMBINATOR = 'Combinator'; | ||
export const EMPTY = '__EMPTY__'; | ||
export const IDENTIFIER = 'Identifier'; | ||
@@ -11,0 +12,0 @@ export const NOT_SUPPORTED_ERR = 'NotSupportedError'; |
@@ -11,5 +11,5 @@ /** | ||
BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF, BIT_HYPHEN, | ||
DUO, HEX, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR, SELECTOR_ATTR, | ||
SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, | ||
SELECTOR_TYPE, SYNTAX_ERR, TYPE_FROM, TYPE_TO, U_FFFD | ||
DUO, EMPTY, HEX, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR, | ||
SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS, | ||
SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE, SYNTAX_ERR, TYPE_FROM, TYPE_TO, U_FFFD | ||
} from './constant.js'; | ||
@@ -137,17 +137,27 @@ | ||
} catch (e) { | ||
const { message } = e; | ||
const regEmptyIs = /(:(is|where)\(\s*\))/; | ||
// workaround for https://github.com/csstree/csstree/issues/265 | ||
// NOTE: still throws on `:lang("")`; | ||
const regLang = /(:lang\(\s*("[A-Za-z\d\-*]+")\s*\))/; | ||
if (e.message === 'Identifier is expected' && regLang.test(selector)) { | ||
const regLang = /(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/; | ||
if (message === 'Identifier is expected' && regLang.test(selector)) { | ||
const [, lang, range] = regLang.exec(selector); | ||
const escapedRange = | ||
range.replaceAll('*', '\\*').replace(/^"/, '').replace(/"$/, ''); | ||
const escapedLang = lang.replace(range, escapedRange); | ||
let escapedLang = lang.replace(range, escapedRange); | ||
if (escapedLang === ':lang()') { | ||
escapedLang = `:lang(${EMPTY})`; | ||
} | ||
res = parseSelector(selector.replace(lang, escapedLang)); | ||
} else if (e.message === '"]" is expected' && !selector.endsWith(']')) { | ||
} else if ((message === 'Identifier is expected' || | ||
message === 'Selector is expected') && | ||
regEmptyIs.test(selector)) { | ||
const [, logic, name] = regEmptyIs.exec(selector); | ||
const emptyIs = `:${name}(${EMPTY})`; | ||
res = parseSelector(selector.replace(logic, emptyIs)); | ||
} else if (message === '"]" is expected' && !selector.endsWith(']')) { | ||
res = parseSelector(`${selector}]`); | ||
} else if (e.message === '")" is expected' && !selector.endsWith(')')) { | ||
} else if (message === '")" is expected' && !selector.endsWith(')')) { | ||
res = parseSelector(`${selector})`); | ||
} else { | ||
throw new DOMException(e.message, SYNTAX_ERR); | ||
throw new DOMException(message, SYNTAX_ERR); | ||
} | ||
@@ -154,0 +164,0 @@ } |
export const ALPHA_NUM: "[A-Z\\d]+"; | ||
export const AN_PLUS_B: "AnPlusB"; | ||
export const COMBINATOR: "Combinator"; | ||
export const EMPTY: "__EMPTY__"; | ||
export const IDENTIFIER: "Identifier"; | ||
@@ -5,0 +6,0 @@ export const NOT_SUPPORTED_ERR: "NotSupportedError"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
380200
4363
322