New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@asamuzakjp/dom-selector

Package Overview
Dependencies
Maintainers
1
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asamuzakjp/dom-selector - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

2

dist/cjs/js/constant.js

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

var E=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var x=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 x(t))!n.call(o,e)&&e!==r&&E(o,e,{get:()=>t[e],enumerable:!(s=c(t,e))||s.enumerable});return o};var p=o=>_(E({},"__esModule",{value:!0}),o);var rt={};T(rt,{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:()=>j,DOCUMENT_NODE:()=>Z,DOCUMENT_POSITION_CONTAINED_BY:()=>v,DOCUMENT_POSITION_CONTAINS:()=>q,DOCUMENT_POSITION_PRECEDING:()=>k,DUO:()=>X,ELEMENT_NODE:()=>y,HEX:()=>b,IDENTIFIER:()=>D,NOT_SUPPORTED_ERR:()=>I,NTH:()=>R,RAW:()=>C,REG_LOGICAL_PSEUDO:()=>V,REG_SHADOW_HOST:()=>tt,REG_SHADOW_MODE:()=>ot,REG_SHADOW_PSEUDO:()=>et,SELECTOR:()=>A,SELECTOR_ATTR:()=>L,SELECTOR_CLASS:()=>P,SELECTOR_ID:()=>F,SELECTOR_LIST:()=>M,SELECTOR_PSEUDO_CLASS:()=>U,SELECTOR_PSEUDO_ELEMENT:()=>l,SELECTOR_TYPE:()=>H,SHOW_ALL:()=>z,SHOW_DOCUMENT:()=>J,SHOW_DOCUMENT_FRAGMENT:()=>K,SHOW_ELEMENT:()=>Q,STRING:()=>B,SYNTAX_ERR:()=>f,TEXT_NODE:()=>g,TYPE_FROM:()=>m,TYPE_TO:()=>w,U_FFFD:()=>G});module.exports=p(rt);const O="[A-Z\\d]+",S="AnPlusB",N="Combinator",D="Identifier",I="NotSupportedError",R="Nth",C="Raw",A="Selector",L="AttributeSelector",P="ClassSelector",F="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,Z=9,j=11,k=2,q=8,v=16,z=4294967295,J=256,K=1024,Q=1,V=/^(?:(?:ha|i)s|not|where)$/,tt=/^host(?:-context)?$/,ot=/^(?: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,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});
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});
//# sourceMappingURL=constant.js.map

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

var C=Object.create;var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},x=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of _(t))!I.call(e,s)&&s!==r&&c(e,s,{get:()=>t[s],enumerable:!(i=w(t,s))||i.enumerable});return e};var M=(e,t,r)=>(r=e!=null?C(k(e)):{},x(t||!e||!e.__esModule?c(r,"default",{value:e,enumerable:!0}):r,e)),U=e=>x(c({},"__esModule",{value:!0}),e);var A={};v(A,{getDirectionality:()=>m,getNamespaceURI:()=>g,getSlottedTextContent:()=>f,isContentEditable:()=>O,isInShadowTree:()=>D,isInclusive:()=>R,isNamespaceDeclared:()=>S,isPreceding:()=>h,resolveContent:()=>P,sortNodes:()=>$,verifyNode:()=>d});module.exports=U(A);var E=M(require("bidi-js"),1),o=require("./constant.js");const d=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(o.TYPE_FROM,o.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===o.DOCUMENT_NODE||e.nodeType===o.DOCUMENT_FRAGMENT_NODE||e.nodeType===o.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},P=e=>{e=d(e);let t,r;switch(e.nodeType){case o.DOCUMENT_NODE:{t=e,r=e;break}case o.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case o.ELEMENT_NODE:default:{t=e.ownerDocument;let i=e;for(;i&&i.parentNode;)i=i.parentNode;r=i;break}}return[t,r]},D=(e={})=>{let t;if(e.nodeType===o.ELEMENT_NODE||e.nodeType===o.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:i,mode:s,nodeType:a,parentNode:p}=r;if(i&&s&&a===o.DOCUMENT_FRAGMENT_NODE&&o.REG_SHADOW_MODE.test(s)){t=!0;break}r=p}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&D(e)){const r=e.assignedNodes();if(r.length){for(const i of r)if(t=i.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=(e={})=>{let t;if(e.nodeType===o.ELEMENT_NODE){const{dir:r,localName:i,parentNode:s}=e,{getEmbeddingLevels:a}=(0,E.default)(),p=/^(?:ltr|rtl)$/;if(p.test(r))t=r;else if(r==="auto"){let l;switch(i){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(l=e.value);break}case"slot":{l=f(e);break}case"textarea":{l=e.value;break}default:{const n=[].slice.call(e.childNodes);for(const u of n){const{dir:T,localName:N,nodeType:y,textContent:b}=u;if(y===o.TEXT_NODE?l=b.trim():y===o.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(N)&&(!T||!p.test(T))&&(N==="slot"?l=f(u):l=b.trim()),l)break}}}if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}if(!t)if(s){const{nodeType:n}=s;n===o.ELEMENT_NODE?t=m(s):(n===o.DOCUMENT_NODE||n===o.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(i==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}t||s||(t="ltr")}else if(i==="input"&&e.type==="tel")t="ltr";else if(s){if(i==="slot"){const l=f(e);if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=s;l===o.ELEMENT_NODE?t=m(s):(l===o.DOCUMENT_NODE||l===o.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},O=(e={})=>{let t;if(e.nodeType===o.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let i=e.parentNode;for(;i;){if(O(i)){t=!0;break}i=i.parentNode}}}}return!!t},g=(e,t)=>{let r;if(e&&typeof e=="string"&&t?.nodeType===o.ELEMENT_NODE){const{attributes:i}=t;for(const s of i){const{name:a,namespaceURI:p,prefix:l,value:n}=s;if(a===`xmlns:${e}`){r=n;break}else if(l===e){r=p;break}}}return r??null},S=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===o.ELEMENT_NODE&&(r=t.lookupNamespaceURI(e),!r)){const i=t.ownerDocument.documentElement;let s=t;for(;s&&(r=g(e,s),!(r||s===i));)s=s.parentNode}return!!r},R=(e={},t={})=>{let r;if(e.nodeType===o.ELEMENT_NODE&&t.nodeType===o.ELEMENT_NODE){const i=t.compareDocumentPosition(e);r=i&o.DOCUMENT_POSITION_CONTAINS||i&o.DOCUMENT_POSITION_CONTAINED_BY}return!!r},h=(e={},t={})=>{let r;if(e.nodeType===o.ELEMENT_NODE&&t.nodeType===o.ELEMENT_NODE){const i=t.compareDocumentPosition(e);r=i&o.DOCUMENT_POSITION_PRECEDING||i&o.DOCUMENT_POSITION_CONTAINS}return!!r},$=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,i)=>{let s;return h(i,r)?s=1:s=-1,s}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,resolveContent,sortNodes,verifyNode});
var k=Object.create;var p=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var r in t)p(e,r,{get:t[r],enumerable:!0})},E=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!I.call(e,o)&&o!==r&&p(e,o,{get:()=>t[o],enumerable:!(s=w(t,o))||s.enumerable});return e};var M=(e,t,r)=>(r=e!=null?k(_(e)):{},E(t||!e||!e.__esModule?p(r,"default",{value:e,enumerable:!0}):r,e)),R=e=>E(p({},"__esModule",{value:!0}),e);var $={};v($,{getDirectionality:()=>m,getNamespaceURI:()=>h,getSlottedTextContent:()=>f,isContentEditable:()=>g,isInShadowTree:()=>D,isNamespaceDeclared:()=>P,isPreceding:()=>O,resolveContent:()=>U,sortNodes:()=>S,verifyNode:()=>d});module.exports=R($);var x=M(require("bidi-js"),1),i=require("./constant.js");const d=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===i.DOCUMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE||e.nodeType===i.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},U=e=>{e=d(e);let t,r;switch(e.nodeType){case i.DOCUMENT_NODE:{t=e,r=e;break}case i.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case i.ELEMENT_NODE:default:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;r=o;break}}const s=t.createTreeWalker(r,i.WALKER_FILTER);return[t,r,s]},D=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:s,mode:o,nodeType:a,parentNode:c}=r;if(s&&o&&a===i.DOCUMENT_FRAGMENT_NODE&&i.REG_SHADOW_MODE.test(o)){t=!0;break}r=c}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&D(e)){const r=e.assignedNodes();if(r.length){for(const s of r)if(t=s.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){const{dir:r,localName:s,parentNode:o}=e,{getEmbeddingLevels:a}=(0,x.default)(),c=/^(?:ltr|rtl)$/;if(c.test(r))t=r;else if(r==="auto"){let l;switch(s){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(l=e.value);break}case"slot":{l=f(e);break}case"textarea":{l=e.value;break}default:{const n=[].slice.call(e.childNodes);for(const u of n){const{dir:T,localName:N,nodeType:y,textContent:b}=u;if(y===i.TEXT_NODE?l=b.trim():y===i.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(N)&&(!T||!c.test(T))&&(N==="slot"?l=f(u):l=b.trim()),l)break}}}if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:n}=o;n===i.ELEMENT_NODE?t=m(o):(n===i.DOCUMENT_NODE||n===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(s==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(s==="input"&&e.type==="tel")t="ltr";else if(o){if(s==="slot"){const l=f(e);if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=o;l===i.ELEMENT_NODE?t=m(o):(l===i.DOCUMENT_NODE||l===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},g=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let s=e.parentNode;for(;s;){if(g(s)){t=!0;break}s=s.parentNode}}}}return!!t},h=(e,t)=>{let r;if(e&&typeof e=="string"&&t?.nodeType===i.ELEMENT_NODE){const{attributes:s}=t;for(const o of s){const{name:a,namespaceURI:c,prefix:l,value:n}=o;if(a===`xmlns:${e}`){r=n;break}else if(l===e){r=c;break}}}return r??null},P=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===i.ELEMENT_NODE&&(r=t.lookupNamespaceURI(e),!r)){const s=t.ownerDocument.documentElement;let o=t;for(;o&&(r=h(e,o),!(r||o===s));)o=o.parentNode}return!!r},O=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_PRECEDING||s&i.DOCUMENT_POSITION_CONTAINS}return!!r},S=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,s)=>{let o;return O(s,r)?o=1:o=-1,o}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isInShadowTree,isNamespaceDeclared,isPreceding,resolveContent,sortNodes,verifyNode});
//# sourceMappingURL=dom-util.js.map

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

var H=Object.create;var P=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(x,a)=>{for(var e in a)P(x,e,{get:a[e],enumerable:!0})},I=(x,a,e,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of B(a))!q.call(x,i)&&i!==e&&P(x,i,{get:()=>a[i],enumerable:!(r=j(a,i))||r.enumerable});return x};var z=(x,a,e)=>(e=x!=null?H(G(x)):{},I(a||!x||!x.__esModule?P(e,"default",{value:x,enumerable:!0}):e,x)),X=x=>I(P({},"__esModule",{value:!0}),x);var K={};V(K,{Finder:()=>Y});module.exports=X(K);var W=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),A=require("./dom-util.js"),M=require("./matcher.js"),S=require("./parser.js"),f=require("./constant.js");const C="next",O="prev",L="all",$="first",R="lineal",D="self",U=f.SHOW_DOCUMENT|f.SHOW_DOCUMENT_FRAGMENT|f.SHOW_ELEMENT;class Y{#l;#r;#s;#f;#i;#n;#e;#c;#w;#o;#m;#t;#h;#u;#d;#b;#a;#p;constructor(a){this.#p=a,this.#i=a.document,this.#r=new WeakMap,this.#m=new WeakMap,this.#o=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#o.configure({LOGERRORS:!1})}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#p.DOMException)if(a.name===f.NOT_SUPPORTED_ERR)this.#a&&console.warn(a.message);else throw new this.#p.DOMException(a.message,a.name);else throw a}_setup(a,e,r={}){const{noexcept:i,warn:s}=r;return this.#w=!!i,this.#a=!!s,this.#e=e,[this.#s,this.#t]=(0,A.resolveContent)(e),this.#h=(0,A.isInShadowTree)(e),this._correspond(a),e}_correspond(a){const e=[];let r,i=this.#s&&this.#r.get(this.#s);if(this.#f=!1,this.#u=!1,i&&i.has(`${a}`)){const s=i.get(`${a}`);r=s.ast,this.#f=s.descendant,this.#u=s.sibling}if(r){const s=r.length;for(let c=0;c<s;c++)r[c].dir=null,r[c].filtered=!1,r[c].find=!1,e[c]=[]}else{let s;try{s=(0,S.parseSelector)(a)}catch(t){this._onError(t)}const c=(0,S.walkAST)(s);r=[];let o=!1,b=!1,n=0;for(const[...t]of c){const l=[];let h=t.shift();if(h&&h.type!==f.COMBINATOR){const d=new Set;for(;h;){if(h.type===f.COMBINATOR){const[w]=t;if(w.type===f.COMBINATOR){const k=`Invalid selector ${a}`;throw new DOMException(k,f.SYNTAX_ERR)}const m=(0,S.unescapeSelector)(h.name);m==="~"?b=!0:/^[\s>]$/.test(m)&&(o=!0),l.push({combo:h,leaves:(0,S.sortAST)(d)}),d.clear()}else if(h){let{name:w}=h;w&&typeof w=="string"&&(w=(0,S.unescapeSelector)(w),/[|:]/.test(w)&&(h.namespace=!0)),d.add(h)}if(t.length)h=t.shift();else{l.push({combo:null,leaves:(0,S.sortAST)(d)}),d.clear();break}}}r.push({branch:l,dir:null,filtered:!1,find:!1}),e[n]=[],n++}this.#s&&(i||(i=new Map),i.set(`${a}`,{ast:r,descendant:o,sibling:b}),this.#r.set(this.#s,i)),this.#f=o,this.#u=b}return this.#l=r,this.#c=e,[r,e]}_prepareTreeWalkers(a){return this.#b=this.#i.createTreeWalker(this.#t,U),this.#n=this.#i.createTreeWalker(a,U),this.#d=!1,[this.#b,this.#n]}_traverse(a={},e=this.#b){let r,i=e.currentNode;if(a.nodeType===f.ELEMENT_NODE&&i===a)r=i;else{if(i!==e.root)for(;i&&!(i===e.root||a.nodeType===f.ELEMENT_NODE&&i===a);)i=e.parentNode();if(a.nodeType===f.ELEMENT_NODE)for(;i;){if(i===a){r=i;break}i=e.nextNode()}else r=i}return r??null}_collectNthChild(a,e,r){const{a:i,b:s,reverse:c,selector:o}=a,{parentNode:b}=e,n=new Set;let t;if(o&&(this.#r.has(o)?t=this.#r.get(o):(t=(0,S.walkAST)(o),this.#r.set(o,t))),b){const l=this.#i.createTreeWalker(b,U);let h=0,d=l.firstChild();for(;d;)h++,d=l.nextSibling();d=this._traverse(b,l);const w=new Set;if(t)for(d=this._traverse(b,l),d=l.firstChild();d;){let m;for(const k of t)if(m=this._matchLeaves(k,d,r),!m)break;m&&w.add(d),d=l.nextSibling()}if(i===0){if(s>0&&s<=h){if(w.size){let m=0;for(d=this._traverse(b,l),c?d=l.lastChild():d=l.firstChild();d;){if(w.has(d)){if(m===s-1){n.add(d);break}m++}c?d=l.previousSibling():d=l.nextSibling()}}else if(!o){let m=0;for(d=this._traverse(b,l),c?d=l.lastChild():d=l.firstChild();d;){if(m===s-1){n.add(d);break}c?d=l.previousSibling():d=l.nextSibling(),m++}}}}else{let m=s-1;if(i>0)for(;m<0;)m+=i;if(m>=0&&m<h){let k=0,_=i>0?0:s-1;for(d=this._traverse(b,l),c?d=l.lastChild():d=l.firstChild();d&&(d&&m>=0&&m<h);)w.size?w.has(d)&&(_===m&&(n.add(d),m+=i),i>0?_++:_--):k===m&&(o||n.add(d),m+=i),c?d=l.previousSibling():d=l.nextSibling(),k++}}if(c&&n.size>1){const m=[...n];return new Set(m.reverse())}}else if(e===this.#t&&i+s===1)if(t){let l;for(const h of t)if(l=this._matchLeaves(h,e,r),l)break;l&&n.add(e)}else n.add(e);return n}_collectNthOfType(a,e){const{a:r,b:i,reverse:s}=a,{localName:c,parentNode:o,prefix:b}=e,n=new Set;if(o){const t=this.#i.createTreeWalker(o,U);let l=0,h=t.firstChild();for(;h;)l++,h=t.nextSibling();if(r===0){if(i>0&&i<=l){let d=0;for(h=this._traverse(o,t),s?h=t.lastChild():h=t.firstChild();h;){const{localName:w,prefix:m}=h;if(w===c&&m===b){if(d===i-1){n.add(h);break}d++}s?h=t.previousSibling():h=t.nextSibling()}}}else{let d=i-1;if(r>0)for(;d<0;)d+=r;if(d>=0&&d<l){let w=r>0?0:i-1;for(h=this._traverse(o,t),s?h=t.lastChild():h=t.firstChild();h;){const{localName:m,prefix:k}=h;if(m===c&&k===b){if(w===d&&(n.add(h),d+=r),d<0||d>=l)break;r>0?w++:w--}s?h=t.previousSibling():h=t.nextSibling()}}}if(s&&n.size>1){const d=[...n];return new Set(d.reverse())}}else e===this.#t&&r+i===1&&n.add(e);return n}_matchAnPlusB(a,e,r,i){const{nth:{a:s,b:c,name:o},selector:b}=a,n=(0,S.unescapeSelector)(o),t=new Map;if(n?(n==="even"?(t.set("a",2),t.set("b",0)):n==="odd"&&(t.set("a",2),t.set("b",1)),r.indexOf("last")>-1&&t.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?t.set("a",s*1):t.set("a",0),typeof c=="string"&&/-?\d+/.test(c)?t.set("b",c*1):t.set("b",0),r.indexOf("last")>-1&&t.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){b&&t.set("selector",b);const l=Object.fromEntries(t);return this._collectNthChild(l,e,i)}else if(/^nth-(?:last-)?of-type$/.test(r)){const l=Object.fromEntries(t);return this._collectNthOfType(l,e)}return new Set}_matchDirectionPseudoClass(a,e){const r=(0,S.unescapeSelector)(a.name),i=(0,A.getDirectionality)(e);let s;return r===i&&(s=e),s??null}_matchLanguagePseudoClass(a,e){const r=(0,S.unescapeSelector)(a.name);let i;if(r==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(i=e);else{let s=e.parentNode;for(;s&&s.nodeType===f.ELEMENT_NODE;){if(s.hasAttribute("lang")){s.getAttribute("lang")&&(i=e);break}s=s.parentNode}}else if(r){const s=`(?:-${f.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${f.ALPHA_NUM}${s}$`,"i").test(r)){let o;if(r.indexOf("-")>-1){const[b,n,...t]=r.split("-");let l;b==="*"?l=`${f.ALPHA_NUM}${s}`:l=`${b}${s}`;const h=`-${n}${s}`,d=t.length;let w="";if(d)for(let m=0;m<d;m++)w+=`-${t[m]}${s}`;o=new RegExp(`^${l}${h}${w}$`,"i")}else o=new RegExp(`^${r}${s}$`,"i");if(e.hasAttribute("lang"))o.test(e.getAttribute("lang"))&&(i=e);else{let b=e.parentNode;for(;b&&b.nodeType===f.ELEMENT_NODE;){if(b.hasAttribute("lang")){const n=b.getAttribute("lang");o.test(n)&&(i=e);break}b=b.parentNode}}}}return i??null}_matchHasPseudoFunc(a,e,r={}){let i;if(Array.isArray(a)&&a.length){const[s]=a,{type:c}=s;let o;c===f.COMBINATOR?o=a.shift():o={name:" ",type:f.COMBINATOR};const b=[];for(;a.length;){const[l]=a,{type:h}=l;if(h===f.COMBINATOR)break;b.push(a.shift())}const n={combo:o,leaves:b};r.dir=C;const t=this._matchCombinator(n,e,r);if(t.size)if(a.length){for(const l of t)if(i=this._matchHasPseudoFunc(Object.assign([],a),l,r),i)break}else i=!0}return!!i}_matchLogicalPseudoFunc(a,e,r={}){const{astName:i="",branches:s=[],selector:c="",twigBranches:o=[]}=a;let b;if(i==="has")if(c.includes(":has("))b=null;else{let n;for(const t of s)if(n=this._matchHasPseudoFunc(Object.assign([],t),e,r),n)break;n&&(b=e)}else{const n=/^(?:is|where)$/.test(i);r.forgive=n;const t=o.length;let l;for(let h=0;h<t;h++){const d=o[h],w=d.length-1,{leaves:m}=d[w];if(l=this._matchLeaves(m,e,r),l&&w>0){let k=new Set([e]);for(let _=w-1;_>=0;_--){const y=d[_],u=[];r.dir=O;for(const p of k){const g=this._matchCombinator(y,p,r);g.size&&u.push(...g)}if(u.length)_===0?l=!0:k=new Set(u);else{l=!1;break}}}if(l)break}i==="not"?l||(b=e):l&&(b=e)}return b??null}_matchPseudoClassSelector(a,e,r={}){const{children:i}=a,{localName:s,parentNode:c}=e,{forgive:o,warn:b=this.#a}=r,n=(0,S.unescapeSelector)(a.name),t=new Set;if(f.REG_LOGICAL_PSEUDO.test(n)){let l;if(this.#r.has(a))l=this.#r.get(a);else{const d=(0,S.walkAST)(a),w=[],m=[];for(const[...k]of d){for(const p of k){const g=(0,S.generateCSS)(p);w.push(g)}const _=[],y=new Set;let u=k.shift();for(;u;)if(u.type===f.COMBINATOR?(_.push({combo:u,leaves:[...y]}),y.clear()):u&&y.add(u),k.length)u=k.shift();else{_.push({combo:null,leaves:[...y]}),y.clear();break}m.push(_)}l={astName:n,branches:d,twigBranches:m,selector:w.join(",")},this.#r.set(a,l)}const h=this._matchLogicalPseudoFunc(l,e,r);h&&t.add(h)}else if(Array.isArray(i)){const[l]=i;if(/^nth-(?:last-)?(?:child|of-type)$/.test(n))return this._matchAnPlusB(l,e,n,r);if(n==="dir"){const h=this._matchDirectionPseudoClass(l,e);h&&t.add(h)}else if(n==="lang"){const h=this._matchLanguagePseudoClass(l,e);h&&t.add(h)}else switch(n){case"current":case"nth-col":case"nth-last-col":{if(b){const h=`Unsupported pseudo-class :${n}()`;throw new DOMException(h,f.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!o){const h=`Unknown pseudo-class :${n}()`;throw new DOMException(h,f.SYNTAX_ERR)}}}else{const l=/^a(?:rea)?$/,h=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,d=/^(?:(?:inpu|selec)t|button|form|textarea)$/,w=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,k=/^(?:date(?:time-local)?|month|time|week)$/,_=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,y=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(n){case"any-link":case"link":{l.test(s)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(l.test(s)&&e.hasAttribute("href")){const{href:u,origin:p,pathname:g}=new URL(this.#s.URL),N=new URL(e.getAttribute("href"),u);N.origin===p&&N.pathname===g&&t.add(e)}break}case"visited":break;case"target":{const{hash:u}=new URL(this.#s.URL);e.id&&u===`#${e.id}`&&this.#s.contains(e)&&t.add(e);break}case"target-within":{const{hash:u}=new URL(this.#s.URL);if(u){const p=u.replace(/^#/,"");let g=this.#s.getElementById(p);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===f.ELEMENT_NODE?!this.#h&&e===this.#e&&t.add(e):e===this.#s.documentElement&&t.add(e);break}case"focus":{if(e===this.#s.activeElement){let u=!0,p=e;for(;p;){if(p.hasAttribute("hidden")){u=!1;break}else if(p.hasAttribute("style")){const{display:g,visibility:N}=p.style;if(u=!(g==="none"||N==="hidden"),!u)break}if(p.parentNode&&p.parentNode.nodeType===f.ELEMENT_NODE)p=p.parentNode;else break}u&&t.add(e)}break}case"focus-within":{let u,p=this.#s.activeElement;for(;p;){if(p===e){u=!0;break}p=p.parentNode}if(u){let g=!0,N=e;for(;N;){if(N.hasAttribute("hidden")){g=!1;break}else if(N.hasAttribute("style")){const{display:E,visibility:T}=N.style;if(g=!(E==="none"||T==="hidden"),!g)break}if(N.parentNode&&N.parentNode.nodeType===f.ELEMENT_NODE)N=N.parentNode;else break}g&&t.add(e)}break}case"open":{w.test(s)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{w.test(s)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(h.test(s)||(0,W.default)(s))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let u=c;for(;u&&u.localName!=="fieldset";)u=u.parentNode;u&&c.localName!=="legend"&&u.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(h.test(s)||(0,W.default)(s))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(s){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||k.test(e.type)||y.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,A.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(s){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||k.test(e.type)||y.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,A.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let u;s==="textarea"?u=e:s==="input"&&(e.hasAttribute("type")?y.test(e.getAttribute("type"))&&(u=e):u=e),u&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&s==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&s==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&s==="input"&&e.type==="checkbox"||s==="progress"&&!e.hasAttribute("value"))t.add(e);else if(s==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const u=e.name;let p=e.parentNode;for(;p&&p.localName!=="form";)p=p.parentNode;p||(p=this.#s.documentElement);let g;const N=p.getElementsByTagName("input"),E=N.length;if(E)for(let T=0;T<E;T++){const v=N[T];if(v.getAttribute("type")==="radio"&&(u?v.getAttribute("name")===u&&(g=!!v.checked):v.hasAttribute("name")||(g=!!v.checked),g))break}g||t.add(e)}break}case"default":{const u=/^(?:button|reset)$/,p=/^(?:image|submit)$/;if(s==="button"&&!(e.hasAttribute("type")&&u.test(e.getAttribute("type")))||s==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))){let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;if(g){const N=this.#i.createTreeWalker(g,f.SHOW_ELEMENT);let E=N.firstChild();for(;E;){const T=E.localName;let v;if(T==="button"?v=!(E.hasAttribute("type")&&u.test(E.getAttribute("type"))):T==="input"&&(v=E.hasAttribute("type")&&p.test(E.getAttribute("type"))),v){E===e&&t.add(e);break}E=N.nextNode()}}}else if(s==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(s==="option"){let g=!1,N=c;for(;N&&N.localName!=="datalist";){if(N.localName==="select"){(N.multiple||N.hasAttribute("multiple"))&&(g=!0);break}N=N.parentNode}if(g)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const E=new Set,T=this.#i.createTreeWalker(c,f.SHOW_ELEMENT);let v=T.firstChild();for(;v;){if(v.selected||v.hasAttribute("selected")){E.add(v);break}v=T.nextSibling()}E.size&&E.has(e)&&t.add(e)}}break}case"valid":{if(d.test(s))e.checkValidity()&&t.add(e);else if(s==="fieldset"){let u;const p=this.#i.createTreeWalker(e,f.SHOW_ELEMENT);let g=p.firstChild();for(;g&&!(d.test(g.localName)&&(u=g.checkValidity(),!u));)g=p.nextNode();u&&t.add(e)}break}case"invalid":{if(d.test(s))e.checkValidity()||t.add(e);else if(s==="fieldset"){let u;const p=this.#i.createTreeWalker(e,f.SHOW_ELEMENT);let g=p.firstChild();for(;g&&!(d.test(g.localName)&&(u=g.checkValidity(),!u));)g=p.nextNode();u||t.add(e)}break}case"in-range":{s==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&_.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{s==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&_.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let u;if(/^(?:select|textarea)$/.test(s))u=e;else if(s==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||m.test(p)||k.test(p)||y.test(p))&&(u=e)}else u=e;u&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let u;if(/^(?:select|textarea)$/.test(s))u=e;else if(s==="input")if(e.hasAttribute("type")){const p=e.getAttribute("type");(p==="file"||m.test(p)||k.test(p)||y.test(p))&&(u=e)}else u=e;u&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#s.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){let u;const p=this.#i.createTreeWalker(e,f.SHOW_ALL);let g=p.firstChild();for(;g&&(u=g.nodeType!==f.ELEMENT_NODE&&g.nodeType!==f.TEXT_NODE,!!u);)g=p.nextSibling();u&&t.add(e)}else t.add(e);break}case"first-child":{(c&&e===c.firstElementChild||e===this.#t)&&t.add(e);break}case"last-child":{(c&&e===c.lastElementChild||e===this.#t)&&t.add(e);break}case"only-child":{(c&&e===c.firstElementChild&&e===c.lastElementChild||e===this.#t)&&t.add(e);break}case"first-of-type":{if(c){const[u]=this._collectNthOfType({a:0,b:1},e);u&&t.add(u)}else e===this.#t&&t.add(e);break}case"last-of-type":{if(c){const[u]=this._collectNthOfType({a:0,b:1,reverse:!0},e);u&&t.add(u)}else e===this.#t&&t.add(e);break}case"only-of-type":{if(c){const[u]=this._collectNthOfType({a:0,b:1},e);if(u===e){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p===e&&t.add(e)}}else e===this.#t&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(b){const u=`Unsupported pseudo-element ::${n}`;throw new DOMException(u,f.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(b){const u=`Unsupported pseudo-class :${n}`;throw new DOMException(u,f.NOT_SUPPORTED_ERR)}break}default:if(n.startsWith("-webkit-")){if(b){const u=`Unsupported pseudo-class :${n}`;throw new DOMException(u,f.NOT_SUPPORTED_ERR)}}else if(!o){const u=`Unknown pseudo-class :${n}`;throw new DOMException(u,f.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(a,e){const{children:r}=a,i=(0,S.unescapeSelector)(a.name);let s;if(Array.isArray(r)){const[c]=(0,S.walkAST)(r[0]),[...o]=c,{host:b}=e;if(i==="host"){let n;for(const t of o){const{type:l}=t;if(l===f.COMBINATOR){const d=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(d,f.SYNTAX_ERR)}if(n=this._matchSelector(t,b).has(b),!n)break}n&&(s=e)}else if(i==="host-context"){let n,t=b;for(;t;){for(const l of o){const{type:h}=l;if(h===f.COMBINATOR){const w=`Invalid selector ${(0,S.generateCSS)(a)}`;throw new DOMException(w,f.SYNTAX_ERR)}if(n=this._matchSelector(l,t).has(t),!n)break}if(n)break;t=t.parentNode}n&&(s=e)}}else if(i==="host")s=e;else{const c=`Invalid selector :${i}`;throw new DOMException(c,f.SYNTAX_ERR)}return s??null}_matchSelector(a,e,r){const{type:i}=a,s=(0,S.unescapeSelector)(a.name),c=new Set;if(e.nodeType===f.ELEMENT_NODE)switch(i){case f.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(s,r);break}case f.SELECTOR_ID:{e.id===s&&c.add(e);break}case f.SELECTOR_CLASS:{e.classList.contains(s)&&c.add(e);break}case f.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,r);default:{const o=(0,M.matchSelector)(a,e,r);o&&c.add(o)}}else if(this.#h&&i===f.SELECTOR_PSEUDO_CLASS&&e.nodeType===f.DOCUMENT_FRAGMENT_NODE){if(s!=="has"&&f.REG_LOGICAL_PSEUDO.test(s))return this._matchPseudoClassSelector(a,e,r);if(f.REG_SHADOW_HOST.test(s)){const o=this._matchShadowHostPseudoClass(a,e,r);o&&c.add(o)}}return c}_matchLeaves(a,e,r){const{attributes:i,localName:s,nodeType:c}=e;let o,b=this.#m.get(a);if(b&&b.has(e)){const{attr:n,matched:t}=b.get(e);i?.length===n&&(o=t)}if(typeof o!="boolean"){const n=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;c===f.ELEMENT_NODE&&n.test(s)?t=!1:t=!0;for(const l of a){const{name:h,type:d}=l,w=(0,S.unescapeSelector)(h);if(d===f.SELECTOR_PSEUDO_CLASS&&w==="dir"&&(t=!1),o=this._matchSelector(l,e,r).has(e),!o)break}t&&(b||(b=new WeakMap),b.set(e,{attr:i?.length,matched:o}),this.#m.set(a,b))}return!!o}_matchHTMLCollection(a,e={}){const{compound:r,filterLeaves:i}=e,s=new Set,c=a.length;if(c)if(r)for(let o=0;o<c;o++){const b=a[o];this._matchLeaves(i,b,e)&&s.add(b)}else{const o=[].slice.call(a);return new Set(o)}return s}_findDescendantNodes(a,e,r){const[i,...s]=a,{type:c}=i,o=(0,S.unescapeSelector)(i.name),b=s.length>0;let n=new Set,t=!1;if(this.#h)t=!0;else switch(c){case f.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(o,r);break}case f.SELECTOR_ID:{if(this.#t.nodeType===f.ELEMENT_NODE)t=!0;else{const l=this.#t.getElementById(o);l&&l!==e&&e.contains(l)&&(b?this._matchLeaves(s,l,r)&&n.add(l):n.add(l))}break}case f.SELECTOR_CLASS:{const l=e.getElementsByClassName(o);n=this._matchHTMLCollection(l,{compound:b,filterLeaves:s});break}case f.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(o)){const l=e.getElementsByTagName(o);n=this._matchHTMLCollection(l,{compound:b,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:n,pending:t}}_matchCombinator(a,e,r={}){const{combo:i,leaves:s}=a,{name:c}=i,{dir:o}=r,b=new Set;if(o===C)switch(c){case"+":{const n=e.nextElementSibling;n&&this._matchLeaves(s,n,r)&&b.add(n);break}case"~":{const{parentNode:n}=e;if(n){const t=this.#i.createTreeWalker(n,f.SHOW_ELEMENT);let l=this._traverse(e,t);for(l===e&&(l=t.nextSibling());l;)this._matchLeaves(s,l,r)&&b.add(l),l=t.nextSibling()}break}case">":{const n=this.#i.createTreeWalker(e,f.SHOW_ELEMENT);let t=n.firstChild();for(;t;)this._matchLeaves(s,t,r)&&b.add(t),t=n.nextSibling();break}case" ":default:{const{nodes:n,pending:t}=this._findDescendantNodes(s,e);if(n.size)return n;if(t){const l=this.#i.createTreeWalker(e,f.SHOW_ELEMENT);let h=l.nextNode();for(;h;)this._matchLeaves(s,h,r)&&b.add(h),h=l.nextNode()}}}else switch(c){case"+":{const n=e.previousElementSibling;n&&this._matchLeaves(s,n,r)&&b.add(n);break}case"~":{const n=this.#i.createTreeWalker(e.parentNode,f.SHOW_ELEMENT);let t=n.firstChild();for(;t&&t!==e;)this._matchLeaves(s,t,r)&&b.add(t),t=n.nextSibling();break}case">":{const n=e.parentNode;n&&this._matchLeaves(s,n,r)&&b.add(n);break}case" ":default:{const n=[];let t=e.parentNode;for(;t;)this._matchLeaves(s,t,r)&&n.push(t),t=t.parentNode;if(n.length)return new Set(n.reverse())}}return b}_findNode(a,e={}){const{node:r}=e;let i,s=this._traverse(r,this.#n);if(s)for(s.nodeType!==f.ELEMENT_NODE?s=this.#n.nextNode():s===r&&s!==this.#t&&(s=this.#n.nextNode());s;){let c;if(this.#e.nodeType===f.ELEMENT_NODE?s===this.#e?c=!0:c=this.#e.contains(s):c=!0,c&&this._matchLeaves(a,s,{warn:this.#a})){i=s;break}s=this.#n.nextNode()}return i??null}_matchSelf(a){const e=[];let r=!1;return this._matchLeaves(a,this.#e,{warn:this.#a})&&(e.push(this.#e),r=!0),[e,r]}_findLineal(a,e={}){const{complex:r}=e,i=[];let s=!1,c=this._matchLeaves(a,this.#e,{warn:this.#a});if(c&&(i.push(this.#e),s=!0),!c||r){let o=this.#e.parentNode;for(;o&&(c=this._matchLeaves(a,o,{warn:this.#a}),c&&(i.push(o),s=!0),o.parentNode);)o=o.parentNode}return[i,s]}_findFirst(a){const e=[];let r=!1;const i=this._findNode(a,{node:this.#e});return i&&(e.push(i),r=!0),[e,r]}_findFromHTMLCollection(a,e={}){const{complex:r,compound:i,filterLeaves:s}=e;let c=[],o=!1,b=!1;const n=a.length;if(n)if(this.#e.nodeType===f.ELEMENT_NODE)for(let t=0;t<n;t++){const l=a[t];(l===this.#e||(0,A.isInclusive)(l,this.#e))&&(i?this._matchLeaves(s,l,{warn:this.#a})&&(c.push(l),o=!0):(c.push(l),o=!0))}else if(r)if(i)for(let t=0;t<n;t++){const l=a[t];this._matchLeaves(s,l,{warn:this.#a})&&(c.push(l),o=!0)}else c=[].slice.call(a),o=!0;else i?b=!0:(c=[].slice.call(a),o=!0);return[c,o,b]}_findEntryNodes(a,e,r){const{leaves:i}=a,[s,...c]=i,{type:o}=s,b=(0,S.unescapeSelector)(s.name),n=c.length>0;let t=[],l=!1,h=!1;switch(o){case f.SELECTOR_PSEUDO_ELEMENT:{(0,M.matchPseudoElementSelector)(b,{warn:this.#a});break}case f.SELECTOR_ID:{if(e===D)[t,l]=this._matchSelf(i);else if(e===R)[t,l]=this._findLineal(i,{complex:r});else if(e===$&&this.#t.nodeType!==f.ELEMENT_NODE){const d=this.#t.getElementById(b);d&&(n?this._matchLeaves(c,d,{warn:this.#a})&&(t.push(d),l=!0):(t.push(d),l=!0))}else h=!0;break}case f.SELECTOR_CLASS:{if(e===D)[t,l]=this._matchSelf(i);else if(e===R)[t,l]=this._findLineal(i,{complex:r});else if(e===$)[t,l]=this._findFirst(i);else if(this.#t.nodeType===f.DOCUMENT_NODE){const d=this.#t.getElementsByClassName(b);[t,l,h]=this._findFromHTMLCollection(d,{complex:r,compound:n,filterLeaves:c})}else h=!0;break}case f.SELECTOR_TYPE:{if(e===D)[t,l]=this._matchSelf(i);else if(e===R)[t,l]=this._findLineal(i,{complex:r});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===f.DOCUMENT_NODE&&!/[*|]/.test(b)){const d=this.#t.getElementsByTagName(b);[t,l,h]=this._findFromHTMLCollection(d,{complex:r,compound:n,filterLeaves:c})}else h=!0;break}default:if(e!==R&&f.REG_SHADOW_HOST.test(b)){if(this.#h&&this.#e.nodeType===f.DOCUMENT_FRAGMENT_NODE){const d=this._matchShadowHostPseudoClass(s,this.#e);d&&(t.push(d),l=!0)}}else e===D?[t,l]=this._matchSelf(i):e===R?[t,l]=this._findLineal(i,{complex:r}):e===$?[t,l]=this._findFirst(i):h=!0}return{compound:n,filtered:l,nodes:t,pending:h}}_getEntryTwig(a,e){const r=a.length,i=r>1,s=a[0];let c,o;if(i){const{combo:b,leaves:[{name:n,type:t}]}=s,l=a[r-1],{leaves:[{name:h,type:d}]}=l;if(d===f.SELECTOR_PSEUDO_ELEMENT||d===f.SELECTOR_ID)c=O,o=l;else if(t===f.SELECTOR_PSEUDO_ELEMENT||t===f.SELECTOR_ID)c=C,o=s;else if(e===L)if(n==="*"&&t===f.SELECTOR_TYPE)c=O,o=l;else if(h==="*"&&d===f.SELECTOR_TYPE)c=C,o=s;else if(r===2){const{name:w}=b;/^[+~]$/.test(w)?(c=O,o=l):(c=C,o=s)}else c=C,o=s;else if(h==="*"&&d===f.SELECTOR_TYPE)c=C,o=s;else if(n==="*"&&t===f.SELECTOR_TYPE)c=O,o=l;else{let w,m;for(const{combo:k,leaves:[_]}of a){const{type:y}=_,u=(0,S.unescapeSelector)(_.name);if(y===f.SELECTOR_PSEUDO_CLASS&&u==="dir"){w=!1;break}if(k&&!m){const{name:p}=k;/^[+~]$/.test(p)&&(w=!0,m=!0)}}w?(c=C,o=s):(c=O,o=l)}}else c=O,o=s;return{complex:i,dir:c,twig:o}}_collectNodes(a){const e=this.#l.values();if(a===L||a===$){const r=new Set;let i=0;for(const{branch:s}of e){const{complex:c,dir:o,twig:b}=this._getEntryTwig(s,a),{compound:n,filtered:t,nodes:l,pending:h}=this._findEntryNodes(b,a,c);l.length?(this.#l[i].find=!0,this.#c[i]=l):h&&r.add(new Map([["index",i],["twig",b]])),this.#l[i].dir=o,this.#l[i].filtered=t||!n,i++}if(r.size){let s,c;this.#e!==this.#t&&this.#e.nodeType===f.ELEMENT_NODE?(s=this.#e,c=this.#n):(s=this.#t,c=this.#b);let o=this._traverse(s,c);for(;o;){let b=!1;if(this.#e.nodeType===f.ELEMENT_NODE?o===this.#e?b=!0:b=this.#e.contains(o):b=!0,b)for(const n of r){const{leaves:t}=n.get("twig");if(this._matchLeaves(t,o,{warn:this.#a})){const h=n.get("index");this.#l[h].filtered=!0,this.#l[h].find=!0,this.#c[h].push(o)}}o=c.nextNode()}}}else{let r=0;for(const{branch:i}of e){const s=i[i.length-1],c=i.length>1,{compound:o,filtered:b,nodes:n}=this._findEntryNodes(s,a,c);n.length&&(this.#l[r].find=!0,this.#c[r]=n),this.#l[r].dir=O,this.#l[r].filtered=b||!o,r++}}return[this.#l,this.#c]}_matchNodes(a){const[...e]=this.#l,r=e.length;let i=new Set;for(let s=0;s<r;s++){const{branch:c,dir:o,find:b}=e[s],n=c.length;if(n&&b){const t=this.#c[s],l=t.length,h=n-1;if(h===0){const{leaves:d}=c[0],w=d.length>1;if((a===L||a===$)&&this.#e.nodeType===f.ELEMENT_NODE)for(let m=0;m<l;m++){const k=t[m];if(k!==this.#e&&this.#e.contains(k)&&(i.add(k),a!==L))break}else if(w)for(let m=0;m<l;m++){const k=t[m];if(i.add(k),a!==L)break}else if(a===L)if(i.size){const m=[...i];i=new Set([...m,...t]),this.#d=!0}else i=new Set([...t]);else{const[m]=[...t];i.add(m)}}else if(o===C){let{combo:d,leaves:w}=c[0],m;for(let k=0;k<l;k++){const _=t[k];let y=new Set([_]);for(let u=1;u<n;u++){const{combo:p,leaves:g}=c[u],N=[];for(const E of y){const T={combo:d,leaves:g},v=this._matchCombinator(T,E,{dir:o,warn:this.#a});v.size&&N.push(...v)}if(N.length)if(u===h){if(a===L){if(i.size){const E=[...i];i=new Set([...E,...N])}else i=new Set([...N]);this.#d=!0}else{const[E]=(0,A.sortNodes)(N);i.add(E)}m=!0}else d=p,y=new Set(N),m=!1;else{m=!1;break}}if(m&&a!==L)break}if(!m&&a===$){const[k]=[...t];let _=this._findNode(w,{node:k});for(;_;){let y=new Set([_]);for(let u=1;u<n;u++){const{combo:p,leaves:g}=c[u],N=[];for(const E of y){const T={combo:d,leaves:g},v=this._matchCombinator(T,E,{dir:o,warn:this.#a});v.size&&N.push(...v)}if(N.length)if(u===h){const[E]=(0,A.sortNodes)(N);i.add(E),m=!0}else d=p,y=new Set(N),m=!1;else{m=!1;break}}if(m)break;_=this._findNode(w,{node:_}),y=new Set([_])}}}else{const{leaves:d}=c[h];let w;for(let m=0;m<l;m++){const k=t[m];let _=new Set([k]);for(let y=h-1;y>=0;y--){const u=c[y],p=[];for(const g of _){const N=this._matchCombinator(u,g,{dir:o,warn:this.#a});N.size&&p.push(...N)}if(p.length)y===0?(i.add(k),w=!0,a===L&&n>1&&i.size>1&&(this.#d=!0)):(_=new Set(p),w=!1);else{w=!1;break}}if(w&&a!==L)break}if(!w&&a===$){const[m]=[...t];let k=this._findNode(d,{node:m});for(;k;){let _=new Set([k]);for(let y=h-1;y>=0;y--){const u=c[y],p=[];for(const g of _){const N=this._matchCombinator(u,g,{dir:o,warn:this.#a});N.size&&p.push(...N)}if(p.length)y===0?(i.add(k),w=!0):(_=new Set(p),w=!1);else{w=!1;break}}if(w)break;k=this._findNode(d,{node:k}),_=new Set([k])}}}}}return i}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(a,e,r){let i;try{if(e.nodeType!==f.ELEMENT_NODE){const s=`Unexpected node ${e.nodeName}`;throw new TypeError(s)}(0,S.filterSelector)(a)?i=this.#o.match(a,e):(this.#e=this._setup(a,e,r),i=this._find(D).size)}catch(s){this._onError(s)}return!!i}closest(a,e,r){let i;try{if(e.nodeType!==f.ELEMENT_NODE){const s=`Unexpected node ${e.nodeName}`;throw new TypeError(s)}if((0,S.filterSelector)(a))i=this.#o.closest(a,e);else{this.#e=this._setup(a,e,r);const s=this._find(R);if(s.size){let c=this.#e;for(;c;){if(s.has(c)){i=c;break}c=c.parentNode}}}}catch(s){this._onError(s)}return i??null}querySelector(a,e,r){let i;try{if(this.#e=this._setup(a,e,r),this.#i===this.#s&&this.#u&&!this.#f&&(0,S.filterSelector)(a))i=this.#o.first(a,e);else{this._prepareTreeWalkers(e);const s=this._find($);s.delete(this.#e),s.size&&([i]=(0,A.sortNodes)(s))}}catch(s){this._onError(s)}return i??null}querySelectorAll(a,e,r){let i;try{if(this.#e=this._setup(a,e,r),this.#i===this.#s&&!this.#f&&(0,S.filterSelector)(a))i=this.#o.select(a,e);else{this._prepareTreeWalkers(e);const s=this._find(L);s.delete(this.#e),s.size&&(this.#d?i=(0,A.sortNodes)(s):i=[...s])}}catch(s){this._onError(s)}return i??[]}}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=(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});
//# sourceMappingURL=finder.js.map

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

var u=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var w=(n,t)=>{for(var r in t)u(n,r,{get:t[r],enumerable:!0})},T=(n,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of x(t))!y.call(n,s)&&s!==r&&u(n,s,{get:()=>t[s],enumerable:!(i=O(t,s))||i.enumerable});return n};var m=n=>T(u({},"__esModule",{value:!0}),n);var C={};w(C,{filterSelector:()=>A,generateCSS:()=>S.generate,parseAstName:()=>$,parseSelector:()=>g,preprocess:()=>E,sortAST:()=>L,unescapeSelector:()=>_,walkAST:()=>I});module.exports=m(C);var h=require("css-tree"),e=require("./constant.js"),S=require("css-tree");const _=(n="")=>{if(typeof n=="string"&&n.indexOf("\\",0)>=0){const t=n.split("\\"),r=t.length;for(let i=1;i<r;i++){let s=t[i];if(s===""&&i===r-1)s=e.U_FFFD;else{const c=/^([\da-f]{1,6}\s?)/i.exec(s);if(c){const[,a]=c;let f;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),d=parseInt(a,e.HEX);d===0||d>=o&&d<=p?f=e.U_FFFD:f=String.fromCodePoint(d)}catch{f=e.U_FFFD}let l="";s.length>a.length&&(l=s.substring(a.length)),s=`${f}${l}`}else/^[\n\r\f]/.test(s)&&(s="\\"+s)}t[i]=s}n=t.join("")}return n},E=(...n)=>{if(!n.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=n;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let s=t.substring(r+1);const c=s.codePointAt(0);if(c===e.BIT_HYPHEN){if(/^\d$/.test(s.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(c>e.BIT_FFFF){const a=`\\${c.toString(e.HEX)} `;s.length===e.DUO?s=a:s=`${a}${s.substring(e.DUO)}`}t=`${i}${s}`,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},g=n=>{if(n=E(n),/^$|^\s*>|,\s*$/.test(n))throw new DOMException(`Invalid selector ${n}`,e.SYNTAX_ERR);let t;try{const r=(0,h.parse)(n,{context:"selectorList",parseCustomProperty:!0});t=(0,h.toPlainObject)(r)}catch(r){const i=/(:lang\(\s*("[A-Za-z\d\-*]+")\s*\))/;if(r.message==="Identifier is expected"&&i.test(n)){const[,s,c]=i.exec(n),a=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,""),f=s.replace(c,a);t=g(n.replace(s,f))}else if(r.message==='"]" is expected'&&!n.endsWith("]"))t=g(`${n}]`);else if(r.message==='")" is expected'&&!n.endsWith(")"))t=g(`${n})`);else throw new DOMException(r.message,e.SYNTAX_ERR)}return t},I=(n={})=>{const t=new Set;let r;return(0,h.walk)(n,{enter:s=>{s.type===e.SELECTOR?t.add(s.children):(s.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(s.name)||s.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(s.name))&&(r=!0)}}),r&&(0,h.findAll)(n,(s,c,a)=>{if(a){if(s.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(s.name)){const f=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 f)for(const{children:o}of l)for(const{children:p}of o)t.has(p)&&t.delete(p)}else if(s.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(s.name)){const f=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 f)for(const{children:o}of l)t.has(o)&&t.delete(o)}}}),[...t]},L=n=>{const t=[...n];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,s)=>{const{type:c}=i,{type:a}=s,f=r.get(c),l=r.get(a);let o;return f===l?o=0:f>l?o=1:o=-1,o})}return t},$=n=>{let t,r;if(n&&typeof n=="string")n.indexOf("|")>-1?[t,r]=n.split("|"):(t="*",r=n);else throw new DOMException(`Invalid selector ${n}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},A=n=>!(!n||typeof n!="string"||/\||::|\s[is]\s*\]/i.test(n)||n.includes(":")&&(/:(?!(?:nth(?:-last)?|first|last|only)-(?:of-type|child)|not)/.test(n)||n.includes(":nth")&&/:nth-(?:last-)?child\(.{1,255}\sof.{1,255}\)/.test(n)||n.includes(":not")&&!/:not\(\s*(?:\*|[\w-]{1,255}|(?:\*|[\w-]{1,255})?(?:\[.{1,255}\]|[.#:][\w-]{1,255}){1,255})(?:\s*,\s*(?:\*|[\w-]{1,255}|(?:\*|[\w-]{1,255})?(?:\[.{1,255}\]|[.#:][\w-]{1,255}){1,255})){0,255}\s*\)/.test(n)));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
var E=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var y=(s,t)=>{for(var r in t)E(s,r,{get:t[r],enumerable:!0})},T=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of O(t))!x.call(s,n)&&n!==r&&E(s,n,{get:()=>t[n],enumerable:!(i=S(t,n))||i.enumerable});return s};var m=s=>T(E({},"__esModule",{value:!0}),s);var C={};y(C,{filterSelector:()=>L,generateCSS:()=>w.generate,parseAstName:()=>I,parseSelector:()=>d,preprocess:()=>u,sortAST:()=>A,unescapeSelector:()=>_,walkAST:()=>$});module.exports=m(C);var h=require("css-tree"),e=require("./constant.js"),w=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 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),g=parseInt(a,e.HEX);g===0||g>=o&&g<=p?l=e.U_FFFD:l=String.fromCodePoint(g)}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},u=(...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},d=s=>{if(s=u(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,h.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,h.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=d(s.replace(n,l))}else if(r.message==='"]" is expected'&&!s.endsWith("]"))t=d(`${s}]`);else if(r.message==='")" is expected'&&!s.endsWith(")"))t=d(`${s})`);else throw new DOMException(r.message,e.SYNTAX_ERR)}return t},$=(s={})=>{const t=new Set;let r;return(0,h.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,h.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]},A=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(":")&&/:(?: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*\))|:nth-(?:last-)?child\([^()]{1,255}\sof[^()]{1,255}\)|:(?!(?:nth(?:-last)?|first|last|only)-(?:of-type|child)|is|not|where)/.test(s));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
//# sourceMappingURL=parser.js.map

@@ -32,6 +32,6 @@ {

"devDependencies": {
"@types/css-tree": "^2.3.5",
"@types/css-tree": "^2.3.6",
"benchmark": "^2.1.4",
"c8": "^9.1.0",
"chai": "^5.0.3",
"chai": "^5.1.0",
"commander": "^12.0.0",

@@ -42,3 +42,3 @@ "esbuild": "^0.20.0",

"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.0.6",
"eslint-plugin-jsdoc": "^48.1.0",
"eslint-plugin-regexp": "^2.2.0",

@@ -65,3 +65,3 @@ "eslint-plugin-unicorn": "^51.0.1",

},
"version": "4.0.1"
"version": "4.1.0"
}

@@ -246,5 +246,7 @@ # DOM Selector

|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
|simple selector:<br>`matches('.content')`|2,645,575 ops/sec ±1.15%|1,643,332 ops/sec ±0.97%|646,061 ops/sec ±0.95%|2,374,666 ops/sec ±0.85%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|compound selector:<br>`matches('p.content[id]:only-child')`|1,197,421 ops/sec ±0.20%|443,001 ops/sec ±0.39%|300,277 ops/sec ±0.26%|952,967 ops/sec ±0.91%|jsdom is the fastest and 1.3 times faster than patched-jsdom.|
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|162,015 ops/sec ±0.29%|N/A|73,881 ops/sec ±0.13%|143,422 ops/sec ±0.26%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|simple selector:<br>`matches('.content')`|1,069,929 ops/sec ±0.34%|7,126 ops/sec ±0.88%|8,555 ops/sec ±0.70%|946,961 ops/sec ±0.15%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|601,355 ops/sec ±0.33%|7,016 ops/sec ±1.12%|8,644 ops/sec ±0.51%|508,012 ops/sec ±0.24%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|N/A|7,082 ops/sec ±0.21%|N/A|153,958 ops/sec ±0.96%|patched-jsdom is the fastest.|
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|167,052 ops/sec ±0.19%|N/A|7,700 ops/sec ±0.45%|146,612 ops/sec ±0.22%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|N/A|N/A|7,573 ops/sec ±0.47%|44,413 ops/sec ±0.66%|patched-jsdom is the fastest.|

@@ -255,5 +257,6 @@ ### closest()

|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
|simple selector:<br>`closest('.container')`|541,108 ops/sec ±0.68%|352,175 ops/sec ±1.94%|388,746 ops/sec ±2.30%|533,387 ops/sec ±1.68%|jsdom is the fastest and 1.0 times faster than patched-jsdom.|
|compound selector:<br>`closest('div.container[id]:not(.box)')`|211,165 ops/sec ±1.27%|77,934 ops/sec ±1.84%|163,773 ops/sec ±2.17%|195,860 ops/sec ±1.43%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|153,514 ops/sec ±1.41%|N/A|72,422 ops/sec ±0.29%|139,221 ops/sec ±0.43%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|simple selector:<br>`closest('.container')`|387,330 ops/sec ±1.52%|7,076 ops/sec ±0.91%|8,491 ops/sec ±0.53%|375,594 ops/sec ±1.31%|jsdom is the fastest and 1.0 times faster than patched-jsdom.|
|compound selector:<br>`closest('div.container[id]:not(.box)')`|180,638 ops/sec ±1.58%|6,492 ops/sec ±1.00%|8,198 ops/sec ±0.71%|173,121 ops/sec ±0.10%|jsdom is the fastest and 1.0 times faster than patched-jsdom.|
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|152,683 ops/sec ±0.08%|N/A|7,548 ops/sec ±0.85%|137,912 ops/sec ±1.40%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|N/A|N/A|7,469 ops/sec ±0.65%|30,497 ops/sec ±0.84%|patched-jsdom is the fastest.|

@@ -264,5 +267,6 @@ ### querySelector()

|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
|simple selector:<br>`querySelector('.content')`|3,482 ops/sec ±0.97%|360,089 ops/sec ±1.32%|321,631 ops/sec ±1.54%|75,390 ops/sec ±0.99%|happydom is the fastest and 4.8 times faster than patched-jsdom.<br>patched-jsdom is 21.6 times faster than jsdom.|
|compound selector:<br>`querySelector('p.content[id]:only-child')`|1,297 ops/sec ±1.22%|365,512 ops/sec ±2.03%|253,436 ops/sec ±1.82%|75,888 ops/sec ±0.81%|happydom is the fastest and 4.8 times faster than patched-jsdom.<br>patched-jsdom is 58.5 times faster than jsdom.|
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|216 ops/sec ±1.94%|N/A|1,315 ops/sec ±1.46%|770 ops/sec ±1.69%|linkedom is the fastest and 1.7 times faster than patched-jsdom.<br>patched-jsdom is 3.6 times faster than jsdom.|
|simple selector:<br>`querySelector('.content')`|35,135 ops/sec ±1.63%|8,473 ops/sec ±0.72%|9,958 ops/sec ±0.90%|28,201 ops/sec ±2.12%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|10,717 ops/sec ±1.39%|8,378 ops/sec ±0.70%|9,366 ops/sec ±0.27%|9,348 ops/sec ±1.76%|jsdom is the fastest and 1.1 times faster than patched-jsdom.|
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|233 ops/sec ±0.71%|N/A|1,298 ops/sec ±0.40%|689 ops/sec ±1.14%|linkedom is the fastest and 1.9 times faster than patched-jsdom. patched-jsdom is 3.0 times faster than jsdom.|
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|N/A|N/A|1,569 ops/sec ±0.29%|464 ops/sec ±1.73%|linkedom is the fastest and 3.4 times faster than patched-jsdom.|

@@ -273,5 +277,6 @@ ### querySelectorAll()

|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|
|simple selector:<br>`querySelectorAll('.content')`|3,250 ops/sec ±0.43%|752 ops/sec ±1.85%|1,175 ops/sec ±1.45%|3,391 ops/sec ±1.02%|patched-jsdom is the fastest.<br>patched-jsdom is 1.0 times faster than jsdom.|
|compound selector:<br>`querySelectorAll('p.content[id]:only-child')`|1,252 ops/sec ±1.46%|913 ops/sec ±1.60%|1,027 ops/sec ±1.08%|1,223 ops/sec ±1.12%|jsdom is the fastest and 1.0 times faster than patched-jsdom.|
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|227 ops/sec ±1.35%|N/A|434 ops/sec ±1.37%|754 ops/sec ±1.86%|patched-jsdom is the fastest.<br>patched-jsdom is 3.3 times faster than jsdom.|
|simple selector:<br>`querySelectorAll('.content')`|2,839 ops/sec ±1.01%|822 ops/sec ±1.68%|1,215 ops/sec ±1.37%|3,398 ops/sec ±0.33%|patched-jsdom is the fastest. patched-jsdom is 1.2 times faster than jsdom.|
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|1,003 ops/sec ±1.20%|987 ops/sec ±1.66%|1,195 ops/sec ±1.07%|1,059 ops/sec ±1.09%|linkedom is the fastest and 1.1 times faster than patched-jsdom. patched-jsdom is 1.1 times faster than jsdom.|
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|230 ops/sec ±0.84%|N/A|426 ops/sec ±0.18%|781 ops/sec ±1.34%|patched-jsdom is the fastest. patched-jsdom is 3.4 times faster than jsdom.|
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|N/A|N/A|463 ops/sec ±0.25%|492 ops/sec ±2.09%|patched-jsdom is the fastest.|

@@ -278,0 +283,0 @@

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

export const SHOW_ELEMENT = 1;
export const WALKER_FILTER = 0x501;

@@ -55,0 +56,0 @@ /* regexp */

@@ -11,4 +11,4 @@ /**

DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,
DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,
REG_SHADOW_MODE, TEXT_NODE, TYPE_FROM, TYPE_TO
DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, REG_SHADOW_MODE, TEXT_NODE,
TYPE_FROM, TYPE_TO, WALKER_FILTER
} from './constant.js';

@@ -37,5 +37,5 @@

/**
* resolve content document and root node
* resolve content document, root node and tree walker
* @param {object} node - Document, DocumentFragment, Element node
* @returns {Array.<object>} - array of document, root node
* @returns {Array.<object>} - array of document, root node, tree walker
*/

@@ -72,5 +72,7 @@ export const resolveContent = node => {

}
const tree = document.createTreeWalker(root, WALKER_FILTER);
return [
document,
root
root,
tree
];

@@ -327,18 +329,2 @@ };

/**
* is inclusive - nodeA and nodeB are in inclusive relation
* @param {object} nodeA - Element node
* @param {object} nodeB - Element node
* @returns {boolean} - result
*/
export const isInclusive = (nodeA = {}, nodeB = {}) => {
let res;
if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {
const posBit = nodeB.compareDocumentPosition(nodeA);
res = posBit & DOCUMENT_POSITION_CONTAINS ||
posBit & DOCUMENT_POSITION_CONTAINED_BY;
}
return !!res;
};
/**
* is preceding - nodeA precedes and/or contains nodeB

@@ -345,0 +331,0 @@ * @param {object} nodeA - Element node

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

* parse AST name - e.g. ns|E -> { prefix: ns, localName: E }
* @private
* @param {string} selector - type selector

@@ -285,3 +284,2 @@ * @returns {object} - node properties

* filter selector (for nwsapi)
* @private
* @param {string} selector - selector

@@ -296,3 +294,3 @@ * @returns {boolean} - result

// and attribute selectors with case flag, i.e. [attr i], [attr s]
if (/\||::|\s[is]\s*\]/i.test(selector)) {
if (/\||::|\[\s*[\w=~|^$*-]+(?:\s+[\w=~|^$*-]+)+\s*\]|\[\s*[\w=~|^$*-]+["'][\w=~|^$*\s-]+['"]+\s+[\w=~|^$*-]+\s*\]/.test(selector)) {
return false;

@@ -302,22 +300,15 @@ }

if (selector.includes(':')) {
// filter pseudos other than child-indexed, e.g. :nth-child(), and :not()
if (/:(?!(?:nth(?:-last)?|first|last|only)-(?:of-type|child)|not)/.test(selector)) {
return false;
}
// filter :nth-child(an+b of selector), :nth-last-child(an+b of selector)
if (selector.includes(':nth') &&
/:nth-(?:last-)?child\(.{1,255}\sof.{1,255}\)/.test(selector)) {
return false;
}
// filter :not(complex selector)
// filter logical combinations with complex selector, e.g. :is(.foo > .bar):
// :(?:is|not|where)(?!\(\s*(?:${compound}(?:\s*,\s*${compound})*)\s*\))
// compound selector:
// (?:${type}|(?:${type})?(?:${subclass})+)
// type selector: *, tag
// \*|[\w-]{1,255}
// \*|[A-Za-z][\w-]*
// subclass selector: attr, class, id, pseudo-class
// \[.{1,255}\]|[.#:][\w-]{1,255}
// compound selector:
// (?:\*|[\w-]{1,255}|(?:\*|[\w-]{1,255})?(?:\[.{1,255}\]|[.#:][\w-]{1,255}){1,255})
// :not() that only contains compound selectors:
// :not\(\s*(?:${compound}(?:\s*,\s*${compound})*)\s*\)
if (selector.includes(':not') &&
!/:not\(\s*(?:\*|[\w-]{1,255}|(?:\*|[\w-]{1,255})?(?:\[.{1,255}\]|[.#:][\w-]{1,255}){1,255})(?:\s*,\s*(?:\*|[\w-]{1,255}|(?:\*|[\w-]{1,255})?(?:\[.{1,255}\]|[.#:][\w-]{1,255}){1,255})){0,255}\s*\)/.test(selector)) {
// \[[^\]]+\]|[.#:][\w-]+
// filter An+B with selector list e.g. :nth-child(an+b of .foo):
// :nth-(?:last-)?child\([^()]{1,255}\sof[^()]{1,255}\)
// filter pseudos other than child-indexed and logical combination pseudos:
// :(?!(?:nth(?:-last)?|first|last|only)-(?:of-type|child)|is|not|where)
if (/:(?: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*\))|:nth-(?:last-)?child\([^()]{1,255}\sof[^()]{1,255}\)|:(?!(?:nth(?:-last)?|first|last|only)-(?:of-type|child)|is|not|where)/.test(selector)) {
return false;

@@ -324,0 +315,0 @@ }

@@ -42,2 +42,3 @@ export const ALPHA_NUM: "[A-Z\\d]+";

export const SHOW_ELEMENT: 1;
export const WALKER_FILTER: 1281;
export const REG_LOGICAL_PSEUDO: RegExp;

@@ -44,0 +45,0 @@ export const REG_SHADOW_HOST: RegExp;

@@ -9,4 +9,3 @@ export function verifyNode(node: any): object;

export function isNamespaceDeclared(ns?: string, node?: object): boolean;
export function isInclusive(nodeA?: object, nodeB?: object): boolean;
export function isPreceding(nodeA?: object, nodeB?: object): boolean;
export function sortNodes(nodes?: Array<object> | Set<object>): Array<object | undefined>;

@@ -6,3 +6,4 @@ export class Finder {

private _correspond;
private _prepareTreeWalkers;
private _createTreeWalker;
private _prepareQuerySelectorWalker;
private _traverse;

@@ -31,2 +32,5 @@ private _collectNthChild;

private _collectNodes;
private _getCombinedNodes;
private _matchNodeNext;
private _matchNodePrev;
private _matchNodes;

@@ -33,0 +37,0 @@ private _find;

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