@asamuzakjp/dom-selector 2.0.2-a.1 → 2.0.2-a.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1,7 +1,7 @@
1
- var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var a=(r,e)=>{for(var o in e)s(r,o,{get:e[o],enumerable:!0})},y=(r,e,o,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of u(e))!w.call(r,c)&&c!==o&&s(r,c,{get:()=>e[c],enumerable:!(l=h(e,c))||l.enumerable});return r};var f=r=>y(s({},"__esModule",{value:!0}),r);var x={};a(x,{closest:()=>m,matches:()=>i,querySelector:()=>p,querySelectorAll:()=>q});module.exports=f(x);var n=require("./js/matcher.js");/*!
1
+ var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var f=(o,t)=>{for(var n in t)s(o,n,{get:t[n],enumerable:!0})},u=(o,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of i(t))!h.call(o,e)&&e!==n&&s(o,e,{get:()=>t[e],enumerable:!(l=a(t,e))||l.enumerable});return o};var w=o=>u(s({},"__esModule",{value:!0}),o);var q={};f(q,{Matcher:()=>c.Matcher,closest:()=>y,matcher:()=>r,matches:()=>m,querySelector:()=>p,querySelectorAll:()=>x});module.exports=w(q);var c=require("./js/matcher.js");/*!
2
2
  * DOM Selector - A CSS selector engine.
3
3
  * @license MIT
4
4
  * @copyright asamuzaK (Kazz)
5
5
  * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}
6
- */let t=new n.Matcher;const i=(r,e,o)=>{let l;try{t||(t=new n.Matcher),l=t.matches(e,r,o)}catch(c){throw t=null,c}return l},m=(r,e,o)=>{let l;try{t||(t=new n.Matcher),l=t.closest(e,r,o)}catch(c){throw t=null,c}return l},p=(r,e,o)=>{let l;try{t||(t=new n.Matcher),l=t.querySelector(e,r,o)}catch(c){throw t=null,c}return l},q=(r,e,o)=>{let l;try{t||(t=new n.Matcher),l=t.querySelectorAll(e,r,o)}catch(c){throw t=null,c}return l};0&&(module.exports={closest,matches,querySelector,querySelectorAll});
6
+ */let r=new c.Matcher;const m=(o,t,n)=>{let l;try{r||(r=new c.Matcher),l=r.matches(t,o,n)}catch(e){throw e instanceof Error&&(r=null),e}return l},y=(o,t,n)=>{let l;try{r||(r=new c.Matcher),l=r.closest(t,o,n)}catch(e){throw e instanceof globalThis[e.name]&&(r=null),e}return l},p=(o,t,n)=>{let l;try{r||(r=new c.Matcher),l=r.querySelector(t,o,n)}catch(e){throw e instanceof globalThis[e.name]&&(r=null),e}return l},x=(o,t,n)=>{let l;try{r||(r=new c.Matcher),l=r.querySelectorAll(t,o,n)}catch(e){throw e instanceof globalThis[e.name]&&(r=null),e}return l};0&&(module.exports={Matcher,closest,matcher,matches,querySelector,querySelectorAll});
7
7
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.js"],
4
- "sourcesContent": ["/*!\n * DOM Selector - A CSS selector engine.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Matcher } from './js/matcher.js';\n\n/* instance */\nlet matcher = new Matcher();\n\n/**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {boolean} - `true` if matched, `false` otherwise\n */\nexport const matches = (selector, node, opt) => {\n let res;\n try {\n if (!matcher) {\n matcher = new Matcher();\n }\n res = matcher.matches(node, selector, opt);\n } catch (e) {\n matcher = null;\n throw e;\n }\n return res;\n};\n\n/**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {?object} - matched node\n */\nexport const closest = (selector, node, opt) => {\n let res;\n try {\n if (!matcher) {\n matcher = new Matcher();\n }\n res = matcher.closest(node, selector, opt);\n } catch (e) {\n matcher = null;\n throw e;\n }\n return res;\n};\n\n/**\n * querySelector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {?object} - matched node\n */\nexport const querySelector = (selector, node, opt) => {\n let res;\n try {\n if (!matcher) {\n matcher = new Matcher();\n }\n res = matcher.querySelector(node, selector, opt);\n } catch (e) {\n matcher = null;\n throw e;\n }\n return res;\n};\n\n/**\n * querySelectorAll\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {Array.<object|undefined>} - array of matched nodes\n */\nexport const querySelectorAll = (selector, node, opt) => {\n let res;\n try {\n if (!matcher) {\n matcher = new Matcher();\n }\n res = matcher.querySelectorAll(node, selector, opt);\n } catch (e) {\n matcher = null;\n throw e;\n }\n return res;\n};\n"],
5
- "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,EAAA,kBAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAN,GAQA,IAAAO,EAAwB,2BARxB;AAAA;AAAA;AAAA;AAAA;AAAA,GAWA,IAAIC,EAAU,IAAI,UAUX,MAAML,EAAU,CAACM,EAAUC,EAAMC,IAAQ,CAC9C,IAAIC,EACJ,GAAI,CACGJ,IACHA,EAAU,IAAI,WAEhBI,EAAMJ,EAAQ,QAAQE,EAAMD,EAAUE,CAAG,CAC3C,OAASE,EAAG,CACV,MAAAL,EAAU,KACJK,CACR,CACA,OAAOD,CACT,EAUaV,EAAU,CAACO,EAAUC,EAAMC,IAAQ,CAC9C,IAAIC,EACJ,GAAI,CACGJ,IACHA,EAAU,IAAI,WAEhBI,EAAMJ,EAAQ,QAAQE,EAAMD,EAAUE,CAAG,CAC3C,OAASE,EAAG,CACV,MAAAL,EAAU,KACJK,CACR,CACA,OAAOD,CACT,EAUaR,EAAgB,CAACK,EAAUC,EAAMC,IAAQ,CACpD,IAAIC,EACJ,GAAI,CACGJ,IACHA,EAAU,IAAI,WAEhBI,EAAMJ,EAAQ,cAAcE,EAAMD,EAAUE,CAAG,CACjD,OAASE,EAAG,CACV,MAAAL,EAAU,KACJK,CACR,CACA,OAAOD,CACT,EAWaP,EAAmB,CAACI,EAAUC,EAAMC,IAAQ,CACvD,IAAIC,EACJ,GAAI,CACGJ,IACHA,EAAU,IAAI,WAEhBI,EAAMJ,EAAQ,iBAAiBE,EAAMD,EAAUE,CAAG,CACpD,OAASE,EAAG,CACV,MAAAL,EAAU,KACJK,CACR,CACA,OAAOD,CACT",
6
- "names": ["src_exports", "__export", "closest", "matches", "querySelector", "querySelectorAll", "__toCommonJS", "import_matcher", "matcher", "selector", "node", "opt", "res", "e"]
4
+ "sourcesContent": ["/*!\n * DOM Selector - A CSS selector engine.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Matcher } from './js/matcher.js';\n\n/* export for test */\nexport { Matcher };\n\n/* instance, export for test */\nexport let matcher = new Matcher();\n\n/**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {boolean} - `true` if matched, `false` otherwise\n */\nexport const matches = (selector, node, opt) => {\n let res;\n try {\n if (!matcher) {\n matcher = new Matcher();\n }\n res = matcher.matches(node, selector, opt);\n } catch (e) {\n if (e instanceof Error) {\n matcher = null;\n }\n throw e;\n }\n return res;\n};\n\n/**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {?object} - matched node\n */\nexport const closest = (selector, node, opt) => {\n let res;\n try {\n if (!matcher) {\n matcher = new Matcher();\n }\n res = matcher.closest(node, selector, opt);\n } catch (e) {\n if (e instanceof globalThis[e.name]) {\n matcher = null;\n }\n throw e;\n }\n return res;\n};\n\n/**\n * querySelector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {?object} - matched node\n */\nexport const querySelector = (selector, node, opt) => {\n let res;\n try {\n if (!matcher) {\n matcher = new Matcher();\n }\n res = matcher.querySelector(node, selector, opt);\n } catch (e) {\n if (e instanceof globalThis[e.name]) {\n matcher = null;\n }\n throw e;\n }\n return res;\n};\n\n/**\n * querySelectorAll\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {Array.<object|undefined>} - array of matched nodes\n */\nexport const querySelectorAll = (selector, node, opt) => {\n let res;\n try {\n if (!matcher) {\n matcher = new Matcher();\n }\n res = matcher.querySelectorAll(node, selector, opt);\n } catch (e) {\n if (e instanceof globalThis[e.name]) {\n matcher = null;\n }\n throw e;\n }\n return res;\n};\n"],
5
+ "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,EAAA,YAAAC,EAAA,YAAAC,EAAA,kBAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAP,GAQA,IAAAQ,EAAwB,2BARxB;AAAA;AAAA;AAAA;AAAA;AAAA,GAcO,IAAIL,EAAU,IAAI,UAUlB,MAAMC,EAAU,CAACK,EAAUC,EAAMC,IAAQ,CAC9C,IAAIC,EACJ,GAAI,CACGT,IACHA,EAAU,IAAI,WAEhBS,EAAMT,EAAQ,QAAQO,EAAMD,EAAUE,CAAG,CAC3C,OAAS,EAAG,CACV,MAAI,aAAa,QACfR,EAAU,MAEN,CACR,CACA,OAAOS,CACT,EAUaV,EAAU,CAACO,EAAUC,EAAMC,IAAQ,CAC9C,IAAIC,EACJ,GAAI,CACGT,IACHA,EAAU,IAAI,WAEhBS,EAAMT,EAAQ,QAAQO,EAAMD,EAAUE,CAAG,CAC3C,OAAS,EAAG,CACV,MAAI,aAAa,WAAW,EAAE,IAAI,IAChCR,EAAU,MAEN,CACR,CACA,OAAOS,CACT,EAUaP,EAAgB,CAACI,EAAUC,EAAMC,IAAQ,CACpD,IAAIC,EACJ,GAAI,CACGT,IACHA,EAAU,IAAI,WAEhBS,EAAMT,EAAQ,cAAcO,EAAMD,EAAUE,CAAG,CACjD,OAAS,EAAG,CACV,MAAI,aAAa,WAAW,EAAE,IAAI,IAChCR,EAAU,MAEN,CACR,CACA,OAAOS,CACT,EAWaN,EAAmB,CAACG,EAAUC,EAAMC,IAAQ,CACvD,IAAIC,EACJ,GAAI,CACGT,IACHA,EAAU,IAAI,WAEhBS,EAAMT,EAAQ,iBAAiBO,EAAMD,EAAUE,CAAG,CACpD,OAAS,EAAG,CACV,MAAI,aAAa,WAAW,EAAE,IAAI,IAChCR,EAAU,MAEN,CACR,CACA,OAAOS,CACT",
6
+ "names": ["src_exports", "__export", "closest", "matcher", "matches", "querySelector", "querySelectorAll", "__toCommonJS", "import_matcher", "selector", "node", "opt", "res"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var z=Object.create;var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var H=(T,l)=>{for(var e in l)R(T,e,{get:l[e],enumerable:!0})},W=(T,l,e,c)=>{if(l&&typeof l=="object"||typeof l=="function")for(let o of j(l))!V.call(T,o)&&o!==e&&R(T,o,{get:()=>l[o],enumerable:!(c=B(l,o))||c.enumerable});return T};var G=(T,l,e)=>(e=T!=null?z(F(T)):{},W(l||!T||!T.__esModule?R(e,"default",{value:T,enumerable:!0}):e,T)),q=T=>W(R({},"__esModule",{value:!0}),T);var X={};H(X,{Matcher:()=>Y});module.exports=q(X);var I=G(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),v=require("./parser.js"),r=require("./constant.js");const C="next",$="prev",A="all",L="first",O="lineal",D="self",U=r.SHOW_DOCUMENT|r.SHOW_DOCUMENT_FRAGMENT|r.SHOW_ELEMENT;class Y{#i;#d;#r;#s;#a;#e;#o;#t;#b;#n;#f;#h;#l;#c;constructor(){this.#d=new Map([[r.SELECTOR_PSEUDO_ELEMENT,r.BIT_01],[r.SELECTOR_ID,r.BIT_02],[r.SELECTOR_CLASS,r.BIT_04],[r.SELECTOR_TYPE,r.BIT_08],[r.SELECTOR_ATTR,r.BIT_16],[r.SELECTOR_PSEUDO_CLASS,r.BIT_32]]),this.#r=new WeakMap}_onError(l){if(l instanceof DOMException||this.#c&&l instanceof this.#c.DOMException)if(l.name===r.NOT_SUPPORTED_ERR)this.#l&&console.warn(l.message);else throw this.#c?new this.#c.DOMException(l.message,l.name):new DOMException(l.message,l.name);else throw l}_setup(l){let e,c;switch(l?.nodeType){case r.DOCUMENT_NODE:{e=l,c=l;break}case r.DOCUMENT_FRAGMENT_NODE:{e=l.ownerDocument,c=l;break}case r.ELEMENT_NODE:{if(l.ownerDocument.contains(l))e=l.ownerDocument,c=l.ownerDocument;else{let f=l;for(;f&&f.parentNode;)f=f.parentNode;e=f.ownerDocument,c=f}break}default:{let f;throw l?.nodeName?f=`Unexpected node ${l.nodeName}`:f=`Unexpected node ${Object.prototype.toString.call(l).slice(r.TYPE_FROM,r.TYPE_TO)}`,new TypeError(f)}}const o=e.createTreeWalker(c,U);return[e.defaultView,e,c,o]}_sortLeaves(l){const e=[...l];return e.length>1&&e.sort((c,o)=>{const{type:a}=c,{type:f}=o,n=this.#d.get(a),d=this.#d.get(f);let t;return n===d?t=0:n>d?t=1:t=-1,t}),e}_correspond(l){let e;try{e=(0,v.parseSelector)(l)}catch(n){this._onError(n)}const c=(0,v.walkAST)(e),o=[],a=[];let f=0;for(const[...n]of c){const d=[];let t=n.shift();if(t&&t.type!==r.COMBINATOR){const i=new Set;for(;t;){if(t.type===r.COMBINATOR){const[h]=n;if(h.type===r.COMBINATOR){const s=`Invalid combinator ${t.name}${h.name}`;throw new this.#c.DOMException(s,r.SYNTAX_ERR)}d.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(n.length)t=n.shift();else{d.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}o.push({branch:d,dir:null,filtered:!1,find:!1}),a[f]=new Set,f++}return[o,a]}_traverse(l={},e=this.#h){let c,o=e.currentNode;if(l.nodeType===r.ELEMENT_NODE&&o===l)c=o;else{if(o!==e.root)for(;o&&!(o===e.root||l.nodeType===r.ELEMENT_NODE&&o===l);)o=e.parentNode();if(l.nodeType===r.ELEMENT_NODE)for(;o;){if(o===l){c=o;break}o=e.nextNode()}else c=o}return c??null}_collectNthChild(l,e){const{a:c,b:o,reverse:a,selector:f}=l,{parentNode:n}=e;let d=new Set,t;if(f&&(this.#r.has(f)?t=this.#r.get(f):(t=(0,v.walkAST)(f),this.#r.set(f,t))),n){const i=this.#s.createTreeWalker(n,U);let h=0,s=i.firstChild();for(;s;)h++,s=i.nextSibling();s=this._traverse(n,i);const m=new Set;if(t)for(s=this._traverse(n,i),s=i.firstChild();s;){let b;for(const p of t)if(b=this._matchLeaves(p,s),!b)break;b&&m.add(s),s=i.nextSibling()}if(c===0){if(o>0&&o<=h){if(m.size){let b=0;for(s=this._traverse(n,i),a?s=i.lastChild():s=i.firstChild();s;){if(m.has(s)){if(b===o-1){d.add(s);break}b++}a?s=i.previousSibling():s=i.nextSibling()}}else if(!f){let b=0;for(s=this._traverse(n,i),a?s=i.lastChild():s=i.firstChild();s;){if(b===o-1){d.add(s);break}a?s=i.previousSibling():s=i.nextSibling(),b++}}}}else{let b=o-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b<h){let p=0,k=c>0?0:o-1;for(s=this._traverse(n,i),a?s=i.lastChild():s=i.firstChild();s&&(s&&b>=0&&b<h);)m.size?m.has(s)&&(k===b&&(d.add(s),b+=c),c>0?k++:k--):p===b&&(f||d.add(s),b+=c),a?s=i.previousSibling():s=i.nextSibling(),p++}}if(a&&d.size>1){const b=[...d];d=new Set(b.reverse())}}else if(e===this.#t&&this.#t.nodeType===r.ELEMENT_NODE&&c+o===1)if(t){let i;for(const h of t)if(i=this._matchLeaves(h,e),i)break;i&&d.add(e)}else d.add(e);return d}_collectNthOfType(l,e){const{a:c,b:o,reverse:a}=l,{localName:f,parentNode:n,prefix:d}=e;let t=new Set;if(n){const i=this.#s.createTreeWalker(n,U);let h=0,s=i.firstChild();for(;s;)h++,s=i.nextSibling();if(c===0){if(o>0&&o<=h){let m=0;for(s=this._traverse(n,i),a?s=i.lastChild():s=i.firstChild();s;){const{localName:b,prefix:p}=s;if(b===f&&p===d){if(m===o-1){t.add(s);break}m++}a?s=i.previousSibling():s=i.nextSibling()}}}else{let m=o-1;if(c>0)for(;m<0;)m+=c;if(m>=0&&m<h){let b=c>0?0:o-1;for(s=this._traverse(n,i),a?s=i.lastChild():s=i.firstChild();s;){const{localName:p,prefix:k}=s;if(p===f&&k===d){if(b===m&&(t.add(s),m+=c),m<0||m>=h)break;c>0?b++:b--}a?s=i.previousSibling():s=i.nextSibling()}}}if(a&&t.size>1){const m=[...t];t=new Set(m.reverse())}}else e===this.#t&&this.#t.nodeType===r.ELEMENT_NODE&&c+o===1&&t.add(e);return t}_matchAnPlusB(l,e,c){const{nth:{a:o,b:a,name:f},selector:n}=l,d=(0,v.unescapeSelector)(f),t=new Map;d?(d==="even"?(t.set("a",2),t.set("b",0)):d==="odd"&&(t.set("a",2),t.set("b",1)),c.indexOf("last")>-1&&t.set("reverse",!0)):(typeof o=="string"&&/-?\d+/.test(o)?t.set("a",o*1):t.set("a",0),typeof a=="string"&&/-?\d+/.test(a)?t.set("b",a*1):t.set("b",0),c.indexOf("last")>-1&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){n&&t.set("selector",n);const h=Object.fromEntries(t),s=this._collectNthChild(h,e);s.size&&(i=s)}else if(/^nth-(?:last-)?of-type$/.test(c)){const h=Object.fromEntries(t),s=this._collectNthOfType(h,e);s.size&&(i=s)}}return i}_matchPseudoElementSelector(l,e={}){const{forgive:c}=e;switch(l){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#l){const o=`Unsupported pseudo-element ::${l}`;throw new DOMException(o,r.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(this.#l){const o=`Unsupported pseudo-element ::${l}()`;throw new DOMException(o,r.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(this.#l){const o=`Unsupported pseudo-element ::${l}`;throw new DOMException(o,r.NOT_SUPPORTED_ERR)}}else if(!c){const o=`Unknown pseudo-element ::${l}`;throw new DOMException(o,r.SYNTAX_ERR)}}}_matchDirectionPseudoClass(l,e){const c=(0,v.unescapeSelector)(l.name),o=(0,E.getDirectionality)(e);let a;return c===o&&(a=e),a??null}_matchLanguagePseudoClass(l,e){const c=(0,v.unescapeSelector)(l.name);let o;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(o=e);else{let a=e.parentNode;for(;a&&a.nodeType===r.ELEMENT_NODE;){if(a.hasAttribute("lang")){a.getAttribute("lang")&&(o=e);break}a=a.parentNode}}else if(c){const a=`(?:-${r.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${r.ALPHA_NUM}${a}$`,"i").test(c)){let n;if(c.indexOf("-")>-1){const[d,t,...i]=c.split("-");let h;d==="*"?h=`${r.ALPHA_NUM}${a}`:h=`${d}${a}`;const s=`-${t}${a}`,m=i.length;let b="";if(m)for(let p=0;p<m;p++)b+=`-${i[p]}${a}`;n=new RegExp(`^${h}${s}${b}$`,"i")}else n=new RegExp(`^${c}${a}$`,"i");if(e.hasAttribute("lang"))n.test(e.getAttribute("lang"))&&(o=e);else{let d=e.parentNode;for(;d&&d.nodeType===r.ELEMENT_NODE;){if(d.hasAttribute("lang")){const t=d.getAttribute("lang");n.test(t)&&(o=e);break}d=d.parentNode}}}}return o??null}_matchHasPseudoFunc(l,e){let c;if(Array.isArray(l)&&l.length){const[o]=l,{type:a}=o;let f;a===r.COMBINATOR?f=l.shift():f={name:" ",type:r.COMBINATOR};const n=[];for(;l.length;){const[i]=l,{type:h}=i;if(h===r.COMBINATOR)break;n.push(l.shift())}const d={combo:f,leaves:n},t=this._matchCombinator(d,e,{dir:C});if(t.size)if(l.length){for(const i of t)if(c=this._matchHasPseudoFunc(Object.assign([],l),i),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(l,e){const{astName:c="",branches:o=[],selector:a="",twigBranches:f=[]}=l;let n;if(c==="has")if(a.includes(":has("))n=null;else{let d;for(const t of o)if(d=this._matchHasPseudoFunc(Object.assign([],t),e),d)break;d&&(n=e)}else{const d=/^(?:is|where)$/.test(c),t=f.length;let i;for(let h=0;h<t;h++){const s=f[h],m=s.length-1,{leaves:b}=s[m];if(i=this._matchLeaves(b,e,{forgive:d}),i&&m>0){let p=new Set([e]);for(let k=m-1;k>=0;k--){const N=s[k],u=[];for(const w of p){const g=this._matchCombinator(N,w,{forgive:d,dir:$});g.size&&u.push(...g)}if(u.length)k===0?i=!0:p=new Set(u);else{i=!1;break}}}if(i)break}c==="not"?i||(n=e):i&&(n=e)}return n??null}_matchPseudoClassSelector(l,e,c={}){const{children:o}=l,{localName:a,parentNode:f}=e,{forgive:n}=c,d=(0,v.unescapeSelector)(l.name);let t=new Set;if(r.REG_LOGICAL_PSEUDO.test(d)){let i;if(this.#r.has(l))i=this.#r.get(l);else{const s=(0,v.walkAST)(l),m=[],b=[];for(const[...p]of s){for(const w of p){const g=(0,v.generateCSS)(w);m.push(g)}const k=[],N=new Set;let u=p.shift();for(;u;)if(u.type===r.COMBINATOR?(k.push({combo:u,leaves:[...N]}),N.clear()):u&&N.add(u),p.length)u=p.shift();else{k.push({combo:null,leaves:[...N]}),N.clear();break}b.push(k)}i={astName:d,branches:s,twigBranches:b,selector:m.join(",")},this.#r.set(l,i)}const h=this._matchLogicalPseudoFunc(i,e);h&&t.add(h)}else if(Array.isArray(o)){const[i]=o;if(/^nth-(?:last-)?(?:child|of-type)$/.test(d)){const h=this._matchAnPlusB(i,e,d);h.size&&(t=h)}else if(d==="dir"){const h=this._matchDirectionPseudoClass(i,e);h&&t.add(h)}else if(d==="lang"){const h=this._matchLanguagePseudoClass(i,e);h&&t.add(h)}else switch(d){case"current":case"nth-col":case"nth-last-col":{if(this.#l){const h=`Unsupported pseudo-class :${d}()`;throw new DOMException(h,r.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!n){const h=`Unknown pseudo-class :${d}()`;throw new DOMException(h,r.SYNTAX_ERR)}}}else{const i=/^a(?:rea)?$/,h=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,s=/^(?:(?:inpu|selec)t|button|form|textarea)$/,m=/^d(?:etails|ialog)$/,b=/^(?:checkbox|radio)$/,p=/^(?:date(?:time-local)?|month|time|week)$/,k=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,N=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(d){case"any-link":case"link":{i.test(a)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(a)&&e.hasAttribute("href")){const{href:u,origin:w,pathname:g}=new URL(this.#s.URL),y=new URL(e.getAttribute("href"),u);y.origin===w&&y.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 w=u.replace(/^#/,"");let g=this.#s.getElementById(w);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===r.ELEMENT_NODE?e===this.#e&&t.add(e):e===this.#s.documentElement&&t.add(e);break}case"focus":{e===this.#s.activeElement&&t.add(e);break}case"focus-within":{let u=this.#s.activeElement;for(;u;){if(u===e){t.add(e);break}u=u.parentNode}break}case"open":{m.test(a)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{m.test(a)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(h.test(a)||(0,I.default)(a))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let u=f;for(;u&&u.localName!=="fieldset";)u=u.parentNode;u&&f.localName!=="legend"&&u.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(h.test(a)||(0,I.default)(a))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(a){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||p.test(e.type)||N.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(a){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||p.test(e.type)||N.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let u;a==="textarea"?u=e:a==="input"&&(e.hasAttribute("type")?N.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&&a==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))||e.selected&&a==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&a==="input"&&e.type==="checkbox"||a==="progress"&&!e.hasAttribute("value"))t.add(e);else if(a==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const u=e.name;let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;w||(w=this.#s.documentElement);let g;const y=[].slice.call(w.getElementsByTagName("input"));for(const _ of y)if(_.getAttribute("type")==="radio"&&(u?_.getAttribute("name")===u&&(g=!!_.checked):_.hasAttribute("name")||(g=!!_.checked),g))break;g||t.add(e)}break}case"default":{const u=/^(?:button|reset)$/,w=/^(?:image|submit)$/;if(a==="button"&&!(e.hasAttribute("type")&&u.test(e.getAttribute("type")))||a==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))){let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;if(g){const y=this.#s.createTreeWalker(g,r.SHOW_ELEMENT);let _=y.firstChild();for(;_;){const x=_.localName;let S;if(x==="button"?S=!(_.hasAttribute("type")&&u.test(_.getAttribute("type"))):x==="input"&&(S=_.hasAttribute("type")&&w.test(_.getAttribute("type"))),S){_===e&&t.add(e);break}_=y.nextNode()}}}else if(a==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(a==="option"){let g=!1,y=f;for(;y&&y.localName!=="datalist";){if(y.localName==="select"){(y.multiple||y.hasAttribute("multiple"))&&(g=!0);break}y=y.parentNode}if(g)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const _=new Set,x=this.#s.createTreeWalker(f,r.SHOW_ELEMENT);let S=x.firstChild();for(;S;){if(S.selected||S.hasAttribute("selected")){_.add(S);break}S=x.nextSibling()}_.size&&_.has(e)&&t.add(e)}}break}case"valid":{if(s.test(a))e.checkValidity()&&t.add(e);else if(a==="fieldset"){let u;const w=this.#s.createTreeWalker(e,r.SHOW_ELEMENT);let g=w.firstChild();for(;g&&!(s.test(g.localName)&&(u=g.checkValidity(),!u));)g=w.nextNode();u&&t.add(e)}break}case"invalid":{if(s.test(a))e.checkValidity()||t.add(e);else if(a==="fieldset"){let u;const w=this.#s.createTreeWalker(e,r.SHOW_ELEMENT);let g=w.firstChild();for(;g&&!(s.test(g.localName)&&(u=g.checkValidity(),!u));)g=w.nextNode();u||t.add(e)}break}case"in-range":{a==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.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":{a==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let u;if(/^(?:select|textarea)$/.test(a))u=e;else if(a==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||p.test(w)||N.test(w))&&(u=e)}else u=e;u&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let u;if(/^(?:select|textarea)$/.test(a))u=e;else if(a==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||p.test(w)||N.test(w))&&(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 w=this.#s.createTreeWalker(e,r.SHOW_ALL);let g=w.firstChild();for(;g&&(u=g.nodeType!==r.ELEMENT_NODE&&g.nodeType!==r.TEXT_NODE,!!u);)g=w.nextSibling();u&&t.add(e)}else t.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#t&&this.#t.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#t&&this.#t.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#t&&this.#t.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(f){const[u]=this._collectNthOfType({a:0,b:1},e);u&&t.add(u)}else e===this.#t&&this.#t.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(f){const[u]=this._collectNthOfType({a:0,b:1,reverse:!0},e);u&&t.add(u)}else e===this.#t&&this.#t.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(f){const[u]=this._collectNthOfType({a:0,b:1},e);if(u===e){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w===e&&t.add(e)}}else e===this.#t&&this.#t.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#l){const u=`Unsupported pseudo-element ::${d}`;throw new DOMException(u,r.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(this.#l){const u=`Unsupported pseudo-class :${d}`;throw new DOMException(u,r.NOT_SUPPORTED_ERR)}break}default:if(d.startsWith("-webkit-")){if(this.#l){const u=`Unsupported pseudo-class :${d}`;throw new DOMException(u,r.NOT_SUPPORTED_ERR)}}else if(!n){const u=`Unknown pseudo-class :${d}`;throw new DOMException(u,r.SYNTAX_ERR)}}}return t}_matchAttributeSelector(l,e){const{flags:c,matcher:o,name:a,value:f}=l;if(typeof c=="string"&&!/^[is]$/i.test(c)){const i=`Invalid selector ${(0,v.generateCSS)(l)}`;throw new DOMException(i,r.SYNTAX_ERR)}const{attributes:n}=e;let d;if(n&&n.length){let t;this.#s.contentType==="text/html"?typeof c=="string"&&/^s$/i.test(c)?t=!1:t=!0:typeof c=="string"&&/^i$/i.test(c)?t=!0:t=!1;let i=(0,v.unescapeSelector)(a.name);t&&(i=i.toLowerCase());const h=new Set;if(i.indexOf("|")>-1){const{prefix:s,tagName:m}=(0,E.selectorToNodeProps)(i);for(let{name:b,value:p}of n)switch(t&&(b=b.toLowerCase(),p=p.toLowerCase()),s){case"":{m===b&&h.add(p);break}case"*":{b.indexOf(":")>-1?b.endsWith(`:${m}`)&&h.add(p):m===b&&h.add(p);break}default:if(b.indexOf(":")>-1){const[k,N]=b.split(":");s===k&&m===N&&(0,E.isNamespaceDeclared)(s,e)&&h.add(p)}}}else for(let{name:s,value:m}of n)if(t&&(s=s.toLowerCase(),m=m.toLowerCase()),s.indexOf(":")>-1){const[b,p]=s.split(":");if(b==="xml"&&p==="lang")continue;i===p&&h.add(m)}else i===s&&h.add(m);if(h.size){const{name:s,value:m}=f||{};let b;switch(s?t?b=s.toLowerCase():b=s:m?t?b=m.toLowerCase():b=m:m===""&&(b=m),o){case"=":{typeof b=="string"&&h.has(b)&&(d=e);break}case"~=":{if(b&&typeof b=="string"){for(const p of h)if(new Set(p.split(/\s+/)).has(b)){d=e;break}}break}case"|=":{if(b&&typeof b=="string"){let p;for(const k of h)if(k===b||k.startsWith(`${b}-`)){p=k;break}p&&(d=e)}break}case"^=":{if(b&&typeof b=="string"){let p;for(const k of h)if(k.startsWith(`${b}`)){p=k;break}p&&(d=e)}break}case"$=":{if(b&&typeof b=="string"){let p;for(const k of h)if(k.endsWith(`${b}`)){p=k;break}p&&(d=e)}break}case"*=":{if(b&&typeof b=="string"){let p;for(const k of h)if(k.includes(`${b}`)){p=k;break}p&&(d=e)}break}case null:default:d=e}}}return d??null}_matchClassSelector(l,e){const c=(0,v.unescapeSelector)(l.name);let o;return e.classList.contains(c)&&(o=e),o??null}_matchIDSelector(l,e){const c=(0,v.unescapeSelector)(l.name),{id:o}=e;let a;return c===o&&(a=e),a??null}_matchTypeSelector(l,e,c={}){const o=(0,v.unescapeSelector)(l.name),{localName:a,prefix:f}=e,{forgive:n}=c;let{prefix:d,tagName:t}=(0,E.selectorToNodeProps)(o,e);this.#s.contentType==="text/html"&&(d=d.toLowerCase(),t=t.toLowerCase());let i,h;a.indexOf(":")>-1?[i,h]=a.split(":"):(i=f||"",h=a);let s;if(d===""&&i==="")e.namespaceURI===null&&(t==="*"||t===h)&&(s=e);else if(d==="*")(t==="*"||t===h)&&(s=e);else if(d===i){if((0,E.isNamespaceDeclared)(d,e))(t==="*"||t===h)&&(s=e);else if(!n){const m=`Undeclared namespace ${d}`;throw new DOMException(m,r.SYNTAX_ERR)}}else if(d&&!n&&!(0,E.isNamespaceDeclared)(d,e)){const m=`Undeclared namespace ${d}`;throw new DOMException(m,r.SYNTAX_ERR)}return s??null}_matchShadowHostPseudoClass(l,e){const{children:c}=l,o=(0,v.unescapeSelector)(l.name);let a;if(Array.isArray(c)){const[f]=(0,v.walkAST)(c[0]),[...n]=f,{host:d}=e;if(o==="host"){let t;for(const i of n){const{type:h}=i;if(h===r.COMBINATOR){const m=`Invalid selector ${(0,v.generateCSS)(l)}`;throw new DOMException(m,r.SYNTAX_ERR)}if(t=this._matchSelector(i,d).has(d),!t)break}t&&(a=e)}else if(o==="host-context"){let t,i=d;for(;i;){for(const h of n){const{type:s}=h;if(s===r.COMBINATOR){const b=`Invalid selector ${(0,v.generateCSS)(l)}`;throw new DOMException(b,r.SYNTAX_ERR)}if(t=this._matchSelector(h,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(a=e)}}else if(o==="host")a=e;else{const f=`Invalid selector :${o}`;throw new DOMException(f,r.SYNTAX_ERR)}return a??null}_matchSelector(l,e,c){const{type:o}=l,a=(0,v.unescapeSelector)(l.name);let f=new Set;if(e.nodeType===r.ELEMENT_NODE)switch(o){case r.SELECTOR_ATTR:{const n=this._matchAttributeSelector(l,e);n&&f.add(n);break}case r.SELECTOR_CLASS:{const n=this._matchClassSelector(l,e);n&&f.add(n);break}case r.SELECTOR_ID:{const n=this._matchIDSelector(l,e);n&&f.add(n);break}case r.SELECTOR_PSEUDO_CLASS:{const n=this._matchPseudoClassSelector(l,e,c);n.size&&(f=n);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(a,c);break}case r.SELECTOR_TYPE:default:{const n=this._matchTypeSelector(l,e,c);n&&f.add(n)}}else if(this.#n&&o===r.SELECTOR_PSEUDO_CLASS&&e.nodeType===r.DOCUMENT_FRAGMENT_NODE){if(a!=="has"&&r.REG_LOGICAL_PSEUDO.test(a)){const n=this._matchPseudoClassSelector(l,e,c);n.size&&(f=n)}else if(r.REG_SHADOW_HOST.test(a)){const n=this._matchShadowHostPseudoClass(l,e);n&&f.add(n)}}return f}_matchLeaves(l,e,c){let o;for(const a of l)if(o=this._matchSelector(a,e,c).has(e),!o)break;return!!o}_findDescendantNodes(l,e){const[c,...o]=l,{type:a}=c,f=(0,v.unescapeSelector)(c.name),n=o.length>0;let d=new Set,t=!1;if(this.#n)t=!0;else switch(a){case r.SELECTOR_ID:{if(this.#t.nodeType===r.ELEMENT_NODE)t=!0;else{const i=this.#t.getElementById(f);i&&i!==e&&e.contains(i)&&(n?this._matchLeaves(o,i)&&d.add(i):d.add(i))}break}case r.SELECTOR_CLASS:{const i=[].slice.call(e.getElementsByClassName(f));if(i.length)if(n)for(const h of i)this._matchLeaves(o,h)&&d.add(h);else d=new Set(i);break}case r.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(f)){const i=[].slice.call(e.getElementsByTagName(f));if(i.length)if(n)for(const h of i)this._matchLeaves(o,h)&&d.add(h);else d=new Set(i)}else t=!0;break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(f);break}default:t=!0}return{nodes:d,pending:t}}_matchCombinator(l,e,c={}){const{combo:o,leaves:a}=l,{name:f}=o,{dir:n,forgive:d}=c;let t=new Set;if(n===C)switch(f){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,{forgive:d})&&t.add(i);break}case"~":{const{parentNode:i}=e;if(i){const h=this.#s.createTreeWalker(i,r.SHOW_ELEMENT);let s=this._traverse(e,h);for(s===e&&(s=h.nextSibling());s;)this._matchLeaves(a,s,{forgive:d})&&t.add(s),s=h.nextSibling()}break}case">":{const i=this.#s.createTreeWalker(e,r.SHOW_ELEMENT);let h=i.firstChild();for(;h;)this._matchLeaves(a,h,{forgive:d})&&t.add(h),h=i.nextSibling();break}case" ":default:{const{nodes:i,pending:h}=this._findDescendantNodes(a,e);if(i.size)t=i;else if(h){const s=this.#s.createTreeWalker(e,r.SHOW_ELEMENT);let m=s.nextNode();for(;m;)this._matchLeaves(a,m,{forgive:d})&&t.add(m),m=s.nextNode()}}}else switch(f){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,{forgive:d})&&t.add(i);break}case"~":{const i=this.#s.createTreeWalker(e.parentNode,r.SHOW_ELEMENT);let h=i.firstChild();for(;h&&h!==e;)this._matchLeaves(a,h,{forgive:d})&&t.add(h),h=i.nextSibling();break}case">":{const i=e.parentNode;i&&this._matchLeaves(a,i,{forgive:d})&&t.add(i);break}case" ":default:{const i=[];let h=e.parentNode;for(;h;)this._matchLeaves(a,h,{forgive:d})&&i.push(h),h=h.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNode(l,e={}){let{node:c,walker:o}=e;o||(o=this.#h);let a,f=this._traverse(c,o);if(f)for((f.nodeType!==r.ELEMENT_NODE||f===c&&f!==this.#t)&&(f=o.nextNode());f;){let n;if(this.#e.nodeType===r.ELEMENT_NODE?f===this.#e?n=!0:n=this.#e.contains(f):n=!0,n&&this._matchLeaves(l,f)){a=f;break}f=o.nextNode()}return a??null}_findEntryNodes(l,e){const{leaves:c}=l,[o,...a]=c,{type:f}=o,n=(0,v.unescapeSelector)(o.name),d=a.length>0;let t=new Set,i=!1,h=!1;switch(f){case r.SELECTOR_ID:{if(e===D)this._matchLeaves(c,this.#e)&&(t.add(this.#e),i=!0);else if(e===O){let s=this.#e;for(;s;)this._matchLeaves(c,s)&&(t.add(s),i=!0),s=s.parentNode}else if(e===A||this.#t.nodeType===r.ELEMENT_NODE)h=!0;else{const s=this.#t.getElementById(n);s&&(t.add(s),i=!0)}break}case r.SELECTOR_CLASS:{if(e===D)this.#e.nodeType===r.ELEMENT_NODE&&this.#e.classList.contains(n)&&t.add(this.#e);else if(e===O){let s=this.#e;for(;s&&s.nodeType===r.ELEMENT_NODE;)s.classList.contains(n)&&t.add(s),s=s.parentNode}else if(e===L){const s=this._findNode(c,{node:this.#e,walker:this.#a});s&&(t.add(s),i=!0)}else if(this.#t.nodeType===r.DOCUMENT_FRAGMENT_NODE||this.#t.nodeType===r.ELEMENT_NODE)h=!0;else{const s=[].slice.call(this.#t.getElementsByClassName(n));if(this.#e.nodeType===r.ELEMENT_NODE)for(const m of s)(m===this.#e||(0,E.isInclusive)(m,this.#e))&&t.add(m);else s.length&&(t=new Set(s))}break}case r.SELECTOR_TYPE:{if(e===D)this.#e.nodeType===r.ELEMENT_NODE&&this._matchLeaves(c,this.#e)&&(t.add(this.#e),i=!0);else if(e===O){let s=this.#e;for(;s&&s.nodeType===r.ELEMENT_NODE;)this._matchLeaves(c,s)&&(t.add(s),i=!0),s=s.parentNode}else if(e===L){const s=this._findNode(c,{node:this.#e,walker:this.#a});s&&(t.add(s),i=!0)}else if(this.#s.contentType!=="text/html"||/[*|]/.test(n)||this.#t.nodeType===r.DOCUMENT_FRAGMENT_NODE||this.#t.nodeType===r.ELEMENT_NODE)h=!0;else{const s=[].slice.call(this.#t.getElementsByTagName(n));if(this.#e.nodeType===r.ELEMENT_NODE)for(const m of s)(m===this.#e||(0,E.isInclusive)(m,this.#e))&&t.add(m);else s.length&&(t=new Set(s))}break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(n);break}default:if(e!==O&&r.REG_SHADOW_HOST.test(n)){if(this.#n&&this.#e.nodeType===r.DOCUMENT_FRAGMENT_NODE){const s=this._matchShadowHostPseudoClass(o,this.#e);s&&t.add(s)}}else if(e===D)this._matchLeaves(c,this.#e)&&(t.add(this.#e),i=!0);else if(e===O){let s=this.#e;for(;s;)this._matchLeaves(c,s)&&(t.add(s),i=!0),s=s.parentNode}else if(e===L){const s=this._findNode(c,{node:this.#e,walker:this.#a});s&&(t.add(s),i=!0)}else h=!0}return{compound:d,filtered:i,nodes:t,pending:h}}_getEntryTwig(l,e){const c=l.length,o=c>1,a=l[0];let f,n;if(o){const{combo:d,leaves:[{type:t}]}=a,i=l[c-1],{leaves:[{type:h}]}=i;if(h===r.SELECTOR_PSEUDO_ELEMENT||h===r.SELECTOR_ID)f=$,n=i;else if(t===r.SELECTOR_PSEUDO_ELEMENT||t===r.SELECTOR_ID)f=C,n=a;else if(e===A)if(c===2){const{name:s}=d;/^[+~]$/.test(s)?(f=$,n=i):(f=C,n=a)}else f=C,n=a;else{let s,m;for(const{combo:b,leaves:[p]}of l){const{type:k}=p,N=(0,v.unescapeSelector)(p.name);if(k===r.SELECTOR_PSEUDO_CLASS&&N==="dir"){s=!1;break}if(b&&!m){const{name:u}=b;/^[+~]$/.test(u)&&(s=!0,m=!0)}}s?(f=C,n=a):(f=$,n=i)}}else f=$,n=a;return{complex:o,dir:f,twig:n}}_collectNodes(l){const e=this.#i.values();if(l===A||l===L){const c=new Set;let o=0;for(const{branch:a}of e){const{dir:f,twig:n}=this._getEntryTwig(a,l),{compound:d,filtered:t,nodes:i,pending:h}=this._findEntryNodes(n,l);i.size?(this.#i[o].find=!0,this.#o[o]=i):h&&c.add(new Map([["index",o],["twig",n]])),this.#i[o].dir=f,this.#i[o].filtered=t||!d,o++}if(c.size){let a,f;this.#e!==this.#t&&this.#e.nodeType===r.ELEMENT_NODE?(a=this.#e,f=this.#a):(a=this.#t,f=this.#h);let n=this._traverse(a,f);for(;n;){let d=!1;if(this.#e.nodeType===r.ELEMENT_NODE?n===this.#e?d=!0:d=this.#e.contains(n):d=!0,d)for(const t of c){const{leaves:i}=t.get("twig");if(this._matchLeaves(i,n)){const s=t.get("index");this.#i[s].filtered=!0,this.#i[s].find=!0,this.#o[s].add(n)}}n=f.nextNode()}}}else{let c=0;for(const{branch:o}of e){const a=o[o.length-1],{compound:f,filtered:n,nodes:d}=this._findEntryNodes(a,l);d.size&&(this.#i[c].find=!0,this.#o[c]=d),this.#i[c].dir=$,this.#i[c].filtered=n||!f,c++}}return[this.#i,this.#o]}_sortNodes(l){const e=[...l];return e.length>1&&e.sort((c,o)=>{let a;return(0,E.isPreceding)(o,c)?a=1:a=-1,a}),e}_matchNodes(l){const[...e]=this.#i,c=e.length;let o=new Set;for(let a=0;a<c;a++){const{branch:f,dir:n,filtered:d,find:t}=e[a],i=f.length;if(i&&t){const h=this.#o[a],s=i-1;if(s===0){const{leaves:[,...m]}=f[0];if((l===A||l===L)&&this.#e.nodeType===r.ELEMENT_NODE){for(const b of h)if((d||this._matchLeaves(m,b))&&b!==this.#e&&this.#e.contains(b)&&(o.add(b),l!==A))break}else if(m.length){for(const b of h)if((d||this._matchLeaves(m,b))&&(o.add(b),l!==A))break}else if(l===A)if(o.size){const b=[...o];o=new Set([...b,...h]),this.#f=!0}else o=new Set([...h]);else{const[b]=[...h];o.add(b)}}else if(n===C){let{combo:m,leaves:b}=f[0];const[,...p]=b;let k;for(const N of h){if(d||this._matchLeaves(p,N)){let w=new Set([N]);for(let g=1;g<i;g++){const{combo:y,leaves:_}=f[g],x=[];for(const S of w){const P={combo:m,leaves:_},M=this._matchCombinator(P,S,{dir:n});M.size&&x.push(...M)}if(x.length)if(g===s){if(l===A)if(o.size){const S=[...o];o=new Set([...S,...x]),this.#f=!0}else o=new Set([...x]);else{const[S]=this._sortNodes(x);o.add(S)}k=!0}else m=y,w=new Set(x),k=!1;else{k=!1;break}}}else k=!1;if(k&&l!==A)break}if(!k&&l===L){const[N]=[...h];let u=this._findNode(b,{node:N,walker:this.#a});for(;u;){let w=new Set([u]);for(let g=1;g<i;g++){const{combo:y,leaves:_}=f[g],x=[];for(const S of w){const P={combo:m,leaves:_},M=this._matchCombinator(P,S,{dir:n});M.size&&x.push(...M)}if(x.length)if(g===s){const[S]=this._sortNodes(x);o.add(S),k=!0}else m=y,w=new Set(x),k=!1;else{k=!1;break}}if(k)break;u=this._findNode(b,{node:u,walker:this.#a}),w=new Set([u])}}}else{const{leaves:m}=f[s],[,...b]=m;let p;for(const k of h){if(d||this._matchLeaves(b,k)){let u=new Set([k]);for(let w=s-1;w>=0;w--){const g=f[w],y=[];for(const _ of u){const x=this._matchCombinator(g,_,{dir:n});x.size&&y.push(...x)}if(y.length)w===0?(o.add(k),p=!0):(u=new Set(y),p=!1);else{p=!1;break}}}if(p&&l!==A)break}if(!p&&l===L){const[k]=[...h];let N=this._findNode(m,{node:k,walker:this.#a});for(;N;){let u=new Set([N]);for(let w=s-1;w>=0;w--){const g=f[w],y=[];for(const _ of u){const x=this._matchCombinator(g,_,{dir:n});x.size&&y.push(...x)}if(y.length)w===0?(o.add(N),p=!0):(u=new Set(y),p=!1);else{p=!1;break}}if(p)break;N=this._findNode(m,{node:N,walker:this.#a}),u=new Set([N])}}}}}return o}_find(l,e,c,o={}){const{warn:a}=o;if(this.#l=!!a,e){if(e.nodeType!==r.DOCUMENT_NODE&&e.nodeType!==r.DOCUMENT_FRAGMENT_NODE&&e.nodeType!==r.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}else if((l===D||l===O)&&e.nodeType!==r.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}}else{const d=`Unexpected node ${Object.prototype.toString.call(e).slice(r.TYPE_FROM,r.TYPE_TO)}`;throw new TypeError(d)}if(this.#r=new WeakMap,this.#e=e,[this.#c,this.#s,this.#t,this.#h]=this._setup(e),this.#n=(0,E.isInShadowTree)(e),c&&c===this.#b)for(const n of this.#o)n.clear();else this.#b=c,[this.#i,this.#o]=this._correspond(c);return(l===A||l===L)&&(this.#a=this.#s.createTreeWalker(this.#e,r.SHOW_ELEMENT),this.#f=!1),this._collectNodes(l),this._matchNodes(l)}matches(l,e,c){let o;try{const a=this._find(D,l,e,c);a.size&&(o=a.has(this.#e))}catch(a){this._onError(a)}return!!o}closest(l,e,c){let o;try{const a=this._find(O,l,e,c);let f=this.#e;for(;f;){if(a.has(f)){o=f;break}f=f.parentNode}}catch(a){this._onError(a)}return o??null}querySelector(l,e,c){let o;try{const a=this._find(L,l,e,c);a.delete(this.#e),a.size&&([o]=this._sortNodes(a))}catch(a){this._onError(a)}return o??null}querySelectorAll(l,e,c){let o;try{const a=this._find(A,l,e,c);a.delete(this.#e),a.size&&(this.#f?o=this._sortNodes(a):o=[...a])}catch(a){this._onError(a)}return o??[]}}0&&(module.exports={Matcher});
1
+ var W=Object.create;var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var H=(T,r)=>{for(var e in r)R(T,e,{get:r[e],enumerable:!0})},z=(T,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of j(r))!V.call(T,l)&&l!==e&&R(T,l,{get:()=>r[l],enumerable:!(n=B(r,l))||n.enumerable});return T};var G=(T,r,e)=>(e=T!=null?W(F(T)):{},z(r||!T||!T.__esModule?R(e,"default",{value:T,enumerable:!0}):e,T)),q=T=>z(R({},"__esModule",{value:!0}),T);var X={};H(X,{Matcher:()=>Y});module.exports=q(X);var U=G(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),v=require("./parser.js"),o=require("./constant.js");const C="next",O="prev",A="all",L="first",$="lineal",D="self",I=o.SHOW_DOCUMENT|o.SHOW_DOCUMENT_FRAGMENT|o.SHOW_ELEMENT;class Y{#i;#h;#a;#t;#r;#e;#o;#s;#b;#f;#n;#d;#l;#c;constructor(){this.#h=new Map([[o.SELECTOR_PSEUDO_ELEMENT,o.BIT_01],[o.SELECTOR_ID,o.BIT_02],[o.SELECTOR_CLASS,o.BIT_04],[o.SELECTOR_TYPE,o.BIT_08],[o.SELECTOR_ATTR,o.BIT_16],[o.SELECTOR_PSEUDO_CLASS,o.BIT_32]]),this.#a=new WeakMap}_onError(r){if(r instanceof DOMException||this.#c&&r instanceof this.#c.DOMException)if(r.name===o.NOT_SUPPORTED_ERR)this.#l&&console.warn(r.message);else throw this.#c?new this.#c.DOMException(r.message,r.name):r;else throw r}_setup(r){let e,n;switch(r?.nodeType){case o.DOCUMENT_NODE:{e=r,n=r;break}case o.DOCUMENT_FRAGMENT_NODE:{e=r.ownerDocument,n=r;break}case o.ELEMENT_NODE:{if(r.ownerDocument.contains(r))e=r.ownerDocument,n=r.ownerDocument;else{let t=r;for(;t&&t.parentNode;)t=t.parentNode;t.nodeType===o.DOCUMENT_NODE?e=t:e=t.ownerDocument,n=t}break}default:{let t;throw r?.nodeName?t=`Unexpected node ${r.nodeName}`:t=`Unexpected node ${Object.prototype.toString.call(r).slice(o.TYPE_FROM,o.TYPE_TO)}`,new TypeError(t)}}return[e.defaultView,e,n]}_sortLeaves(r){const e=[...r];return e.length>1&&e.sort((n,l)=>{const{type:t}=n,{type:d}=l,h=this.#h.get(t),f=this.#h.get(d);let s;return h===f?s=0:h>f?s=1:s=-1,s}),e}_correspond(r){const e=[];let n,l=this.#t&&this.#a.get(this.#t);if(l&&l.has(`${r}`)&&(n=l.get(r),typeof n=="string"))throw new DOMException(n,o.SYNTAX_ERR);if(n){const t=n.length;for(let d=0;d<t;d++)n[d].dir=null,n[d].filtered=!1,n[d].find=!1,e[d]=new Set}else{let t;try{t=(0,v.parseSelector)(r)}catch(f){this.#t&&(l||(l=new Map),l.set(`${r}`,f.message),this.#a.set(this.#t,l)),this._onError(f)}const d=(0,v.walkAST)(t);n=[];let h=0;for(const[...f]of d){const s=[];let a=f.shift();if(a&&a.type!==o.COMBINATOR){const c=new Set;for(;a;){if(a.type===o.COMBINATOR){const[i]=f;if(i.type===o.COMBINATOR){const m=`Invalid selector ${r}`;throw this.#t&&(l||(l=new Map),l.set(`${r}`,m),this.#a.set(this.#t,l)),new DOMException(m,o.SYNTAX_ERR)}s.push({combo:a,leaves:this._sortLeaves(c)}),c.clear()}else a&&c.add(a);if(f.length)a=f.shift();else{s.push({combo:null,leaves:this._sortLeaves(c)}),c.clear();break}}}n.push({branch:s,dir:null,filtered:!1,find:!1}),e[h]=new Set,h++}this.#t&&(l||(l=new Map),l.set(`${r}`,n),this.#a.set(this.#t,l))}return[n,e]}_traverse(r={},e=this.#d){let n,l=e.currentNode;if(r.nodeType===o.ELEMENT_NODE&&l===r)n=l;else{if(l!==e.root)for(;l&&!(l===e.root||r.nodeType===o.ELEMENT_NODE&&l===r);)l=e.parentNode();if(r.nodeType===o.ELEMENT_NODE)for(;l;){if(l===r){n=l;break}l=e.nextNode()}else n=l}return n??null}_collectNthChild(r,e){const{a:n,b:l,reverse:t,selector:d}=r,{parentNode:h}=e;let f=new Set,s;if(d&&(this.#a.has(d)?s=this.#a.get(d):(s=(0,v.walkAST)(d),this.#a.set(d,s))),h){const a=this.#t.createTreeWalker(h,I);let c=0,i=a.firstChild();for(;i;)c++,i=a.nextSibling();i=this._traverse(h,a);const m=new Set;if(s)for(i=this._traverse(h,a),i=a.firstChild();i;){let b;for(const p of s)if(b=this._matchLeaves(p,i),!b)break;b&&m.add(i),i=a.nextSibling()}if(n===0){if(l>0&&l<=c){if(m.size){let b=0;for(i=this._traverse(h,a),t?i=a.lastChild():i=a.firstChild();i;){if(m.has(i)){if(b===l-1){f.add(i);break}b++}t?i=a.previousSibling():i=a.nextSibling()}}else if(!d){let b=0;for(i=this._traverse(h,a),t?i=a.lastChild():i=a.firstChild();i;){if(b===l-1){f.add(i);break}t?i=a.previousSibling():i=a.nextSibling(),b++}}}}else{let b=l-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<c){let p=0,N=n>0?0:l-1;for(i=this._traverse(h,a),t?i=a.lastChild():i=a.firstChild();i&&(i&&b>=0&&b<c);)m.size?m.has(i)&&(N===b&&(f.add(i),b+=n),n>0?N++:N--):p===b&&(d||f.add(i),b+=n),t?i=a.previousSibling():i=a.nextSibling(),p++}}if(t&&f.size>1){const b=[...f];f=new Set(b.reverse())}}else if(e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&n+l===1)if(s){let a;for(const c of s)if(a=this._matchLeaves(c,e),a)break;a&&f.add(e)}else f.add(e);return f}_collectNthOfType(r,e){const{a:n,b:l,reverse:t}=r,{localName:d,parentNode:h,prefix:f}=e;let s=new Set;if(h){const a=this.#t.createTreeWalker(h,I);let c=0,i=a.firstChild();for(;i;)c++,i=a.nextSibling();if(n===0){if(l>0&&l<=c){let m=0;for(i=this._traverse(h,a),t?i=a.lastChild():i=a.firstChild();i;){const{localName:b,prefix:p}=i;if(b===d&&p===f){if(m===l-1){s.add(i);break}m++}t?i=a.previousSibling():i=a.nextSibling()}}}else{let m=l-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m<c){let b=n>0?0:l-1;for(i=this._traverse(h,a),t?i=a.lastChild():i=a.firstChild();i;){const{localName:p,prefix:N}=i;if(p===d&&N===f){if(b===m&&(s.add(i),m+=n),m<0||m>=c)break;n>0?b++:b--}t?i=a.previousSibling():i=a.nextSibling()}}}if(t&&s.size>1){const m=[...s];s=new Set(m.reverse())}}else e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&n+l===1&&s.add(e);return s}_matchAnPlusB(r,e,n){const{nth:{a:l,b:t,name:d},selector:h}=r,f=(0,v.unescapeSelector)(d),s=new Map;f?(f==="even"?(s.set("a",2),s.set("b",0)):f==="odd"&&(s.set("a",2),s.set("b",1)),n.indexOf("last")>-1&&s.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?s.set("a",l*1):s.set("a",0),typeof t=="string"&&/-?\d+/.test(t)?s.set("b",t*1):s.set("b",0),n.indexOf("last")>-1&&s.set("reverse",!0));let a=new Set;if(s.has("a")&&s.has("b")){if(/^nth-(?:last-)?child$/.test(n)){h&&s.set("selector",h);const c=Object.fromEntries(s),i=this._collectNthChild(c,e);i.size&&(a=i)}else if(/^nth-(?:last-)?of-type$/.test(n)){const c=Object.fromEntries(s),i=this._collectNthOfType(c,e);i.size&&(a=i)}}return a}_matchPseudoElementSelector(r,e={}){const{forgive:n}=e;switch(r){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#l){const l=`Unsupported pseudo-element ::${r}`;throw new DOMException(l,o.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(this.#l){const l=`Unsupported pseudo-element ::${r}()`;throw new DOMException(l,o.NOT_SUPPORTED_ERR)}break}default:if(r.startsWith("-webkit-")){if(this.#l){const l=`Unsupported pseudo-element ::${r}`;throw new DOMException(l,o.NOT_SUPPORTED_ERR)}}else if(!n){const l=`Unknown pseudo-element ::${r}`;throw new DOMException(l,o.SYNTAX_ERR)}}}_matchDirectionPseudoClass(r,e){const n=(0,v.unescapeSelector)(r.name),l=(0,E.getDirectionality)(e);let t;return n===l&&(t=e),t??null}_matchLanguagePseudoClass(r,e){const n=(0,v.unescapeSelector)(r.name);let l;if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(l=e);else{let t=e.parentNode;for(;t&&t.nodeType===o.ELEMENT_NODE;){if(t.hasAttribute("lang")){t.getAttribute("lang")&&(l=e);break}t=t.parentNode}}else if(n){const t=`(?:-${o.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${o.ALPHA_NUM}${t}$`,"i").test(n)){let h;if(n.indexOf("-")>-1){const[f,s,...a]=n.split("-");let c;f==="*"?c=`${o.ALPHA_NUM}${t}`:c=`${f}${t}`;const i=`-${s}${t}`,m=a.length;let b="";if(m)for(let p=0;p<m;p++)b+=`-${a[p]}${t}`;h=new RegExp(`^${c}${i}${b}$`,"i")}else h=new RegExp(`^${n}${t}$`,"i");if(e.hasAttribute("lang"))h.test(e.getAttribute("lang"))&&(l=e);else{let f=e.parentNode;for(;f&&f.nodeType===o.ELEMENT_NODE;){if(f.hasAttribute("lang")){const s=f.getAttribute("lang");h.test(s)&&(l=e);break}f=f.parentNode}}}}return l??null}_matchHasPseudoFunc(r,e){let n;if(Array.isArray(r)&&r.length){const[l]=r,{type:t}=l;let d;t===o.COMBINATOR?d=r.shift():d={name:" ",type:o.COMBINATOR};const h=[];for(;r.length;){const[a]=r,{type:c}=a;if(c===o.COMBINATOR)break;h.push(r.shift())}const f={combo:d,leaves:h},s=this._matchCombinator(f,e,{dir:C});if(s.size)if(r.length){for(const a of s)if(n=this._matchHasPseudoFunc(Object.assign([],r),a),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e){const{astName:n="",branches:l=[],selector:t="",twigBranches:d=[]}=r;let h;if(n==="has")if(t.includes(":has("))h=null;else{let f;for(const s of l)if(f=this._matchHasPseudoFunc(Object.assign([],s),e),f)break;f&&(h=e)}else{const f=/^(?:is|where)$/.test(n),s=d.length;let a;for(let c=0;c<s;c++){const i=d[c],m=i.length-1,{leaves:b}=i[m];if(a=this._matchLeaves(b,e,{forgive:f}),a&&m>0){let p=new Set([e]);for(let N=m-1;N>=0;N--){const k=i[N],u=[];for(const w of p){const g=this._matchCombinator(k,w,{forgive:f,dir:O});g.size&&u.push(...g)}if(u.length)N===0?a=!0:p=new Set(u);else{a=!1;break}}}if(a)break}n==="not"?a||(h=e):a&&(h=e)}return h??null}_matchPseudoClassSelector(r,e,n={}){const{children:l}=r,{localName:t,parentNode:d}=e,{forgive:h}=n,f=(0,v.unescapeSelector)(r.name);let s=new Set;if(o.REG_LOGICAL_PSEUDO.test(f)){let a;if(this.#a.has(r))a=this.#a.get(r);else{const i=(0,v.walkAST)(r),m=[],b=[];for(const[...p]of i){for(const w of p){const g=(0,v.generateCSS)(w);m.push(g)}const N=[],k=new Set;let u=p.shift();for(;u;)if(u.type===o.COMBINATOR?(N.push({combo:u,leaves:[...k]}),k.clear()):u&&k.add(u),p.length)u=p.shift();else{N.push({combo:null,leaves:[...k]}),k.clear();break}b.push(N)}a={astName:f,branches:i,twigBranches:b,selector:m.join(",")},this.#a.set(r,a)}const c=this._matchLogicalPseudoFunc(a,e);c&&s.add(c)}else if(Array.isArray(l)){const[a]=l;if(/^nth-(?:last-)?(?:child|of-type)$/.test(f)){const c=this._matchAnPlusB(a,e,f);c.size&&(s=c)}else if(f==="dir"){const c=this._matchDirectionPseudoClass(a,e);c&&s.add(c)}else if(f==="lang"){const c=this._matchLanguagePseudoClass(a,e);c&&s.add(c)}else switch(f){case"current":case"nth-col":case"nth-last-col":{if(this.#l){const c=`Unsupported pseudo-class :${f}()`;throw new DOMException(c,o.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!h){const c=`Unknown pseudo-class :${f}()`;throw new DOMException(c,o.SYNTAX_ERR)}}}else{const a=/^a(?:rea)?$/,c=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,i=/^(?:(?:inpu|selec)t|button|form|textarea)$/,m=/^d(?:etails|ialog)$/,b=/^(?:checkbox|radio)$/,p=/^(?: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(f){case"any-link":case"link":{a.test(t)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(a.test(t)&&e.hasAttribute("href")){const{href:u,origin:w,pathname:g}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),u);y.origin===w&&y.pathname===g&&s.add(e)}break}case"visited":break;case"target":{const{hash:u}=new URL(this.#t.URL);e.id&&u===`#${e.id}`&&this.#t.contains(e)&&s.add(e);break}case"target-within":{const{hash:u}=new URL(this.#t.URL);if(u){const w=u.replace(/^#/,"");let g=this.#t.getElementById(w);for(;g;){if(g===e){s.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===o.ELEMENT_NODE?e===this.#e&&s.add(e):e===this.#t.documentElement&&s.add(e);break}case"focus":{e===this.#t.activeElement&&s.add(e);break}case"focus-within":{let u=this.#t.activeElement;for(;u;){if(u===e){s.add(e);break}u=u.parentNode}break}case"open":{m.test(t)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{m.test(t)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(c.test(t)||(0,U.default)(t))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let u=d;for(;u&&u.localName!=="fieldset";)u=u.parentNode;u&&d.localName!=="legend"&&u.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(c.test(t)||(0,U.default)(t))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(t){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||p.test(e.type)||k.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,E.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(t){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||p.test(e.type)||k.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,E.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let u;t==="textarea"?u=e:t==="input"&&(e.hasAttribute("type")?k.test(e.getAttribute("type"))&&(u=e):u=e),u&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&t==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))||e.selected&&t==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&t==="input"&&e.type==="checkbox"||t==="progress"&&!e.hasAttribute("value"))s.add(e);else if(t==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const u=e.name;let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;w||(w=this.#t.documentElement);let g;const y=[].slice.call(w.getElementsByTagName("input"));for(const _ of y)if(_.getAttribute("type")==="radio"&&(u?_.getAttribute("name")===u&&(g=!!_.checked):_.hasAttribute("name")||(g=!!_.checked),g))break;g||s.add(e)}break}case"default":{const u=/^(?:button|reset)$/,w=/^(?:image|submit)$/;if(t==="button"&&!(e.hasAttribute("type")&&u.test(e.getAttribute("type")))||t==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))){let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;if(g){const y=this.#t.createTreeWalker(g,o.SHOW_ELEMENT);let _=y.firstChild();for(;_;){const x=_.localName;let S;if(x==="button"?S=!(_.hasAttribute("type")&&u.test(_.getAttribute("type"))):x==="input"&&(S=_.hasAttribute("type")&&w.test(_.getAttribute("type"))),S){_===e&&s.add(e);break}_=y.nextNode()}}}else if(t==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(t==="option"){let g=!1,y=d;for(;y&&y.localName!=="datalist";){if(y.localName==="select"){(y.multiple||y.hasAttribute("multiple"))&&(g=!0);break}y=y.parentNode}if(g)(e.selected||e.hasAttribute("selected"))&&s.add(e);else{const _=new Set,x=this.#t.createTreeWalker(d,o.SHOW_ELEMENT);let S=x.firstChild();for(;S;){if(S.selected||S.hasAttribute("selected")){_.add(S);break}S=x.nextSibling()}_.size&&_.has(e)&&s.add(e)}}break}case"valid":{if(i.test(t))e.checkValidity()&&s.add(e);else if(t==="fieldset"){let u;const w=this.#t.createTreeWalker(e,o.SHOW_ELEMENT);let g=w.firstChild();for(;g&&!(i.test(g.localName)&&(u=g.checkValidity(),!u));)g=w.nextNode();u&&s.add(e)}break}case"invalid":{if(i.test(t))e.checkValidity()||s.add(e);else if(t==="fieldset"){let u;const w=this.#t.createTreeWalker(e,o.SHOW_ELEMENT);let g=w.firstChild();for(;g&&!(i.test(g.localName)&&(u=g.checkValidity(),!u));)g=w.nextNode();u||s.add(e)}break}case"in-range":{t==="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")&&s.add(e);break}case"out-of-range":{t==="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)&&s.add(e);break}case"required":{let u;if(/^(?:select|textarea)$/.test(t))u=e;else if(t==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||p.test(w)||k.test(w))&&(u=e)}else u=e;u&&(e.required||e.hasAttribute("required"))&&s.add(e);break}case"optional":{let u;if(/^(?:select|textarea)$/.test(t))u=e;else if(t==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||p.test(w)||k.test(w))&&(u=e)}else u=e;u&&!(e.required||e.hasAttribute("required"))&&s.add(e);break}case"root":{e===this.#t.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){let u;const w=this.#t.createTreeWalker(e,o.SHOW_ALL);let g=w.firstChild();for(;g&&(u=g.nodeType!==o.ELEMENT_NODE&&g.nodeType!==o.TEXT_NODE,!!u);)g=w.nextSibling();u&&s.add(e)}else s.add(e);break}case"first-child":{(d&&e===d.firstElementChild||e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE)&&s.add(e);break}case"last-child":{(d&&e===d.lastElementChild||e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE)&&s.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE)&&s.add(e);break}case"first-of-type":{if(d){const[u]=this._collectNthOfType({a:0,b:1},e);u&&s.add(u)}else e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&s.add(e);break}case"last-of-type":{if(d){const[u]=this._collectNthOfType({a:0,b:1,reverse:!0},e);u&&s.add(u)}else e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&s.add(e);break}case"only-of-type":{if(d){const[u]=this._collectNthOfType({a:0,b:1},e);if(u===e){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w===e&&s.add(e)}}else e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&s.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#l){const u=`Unsupported pseudo-element ::${f}`;throw new DOMException(u,o.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(this.#l){const u=`Unsupported pseudo-class :${f}`;throw new DOMException(u,o.NOT_SUPPORTED_ERR)}break}default:if(f.startsWith("-webkit-")){if(this.#l){const u=`Unsupported pseudo-class :${f}`;throw new DOMException(u,o.NOT_SUPPORTED_ERR)}}else if(!h){const u=`Unknown pseudo-class :${f}`;throw new DOMException(u,o.SYNTAX_ERR)}}}return s}_matchAttributeSelector(r,e){const{flags:n,matcher:l,name:t,value:d}=r;if(typeof n=="string"&&!/^[is]$/i.test(n)){const a=`Invalid selector ${(0,v.generateCSS)(r)}`;throw new DOMException(a,o.SYNTAX_ERR)}const{attributes:h}=e;let f;if(h&&h.length){let s;this.#t.contentType==="text/html"?typeof n=="string"&&/^s$/i.test(n)?s=!1:s=!0:typeof n=="string"&&/^i$/i.test(n)?s=!0:s=!1;let a=(0,v.unescapeSelector)(t.name);s&&(a=a.toLowerCase());const c=new Set;if(a.indexOf("|")>-1){const{prefix:i,tagName:m}=(0,E.selectorToNodeProps)(a);for(let{name:b,value:p}of h)switch(s&&(b=b.toLowerCase(),p=p.toLowerCase()),i){case"":{m===b&&c.add(p);break}case"*":{b.indexOf(":")>-1?b.endsWith(`:${m}`)&&c.add(p):m===b&&c.add(p);break}default:if(b.indexOf(":")>-1){const[N,k]=b.split(":");i===N&&m===k&&(0,E.isNamespaceDeclared)(i,e)&&c.add(p)}}}else for(let{name:i,value:m}of h)if(s&&(i=i.toLowerCase(),m=m.toLowerCase()),i.indexOf(":")>-1){const[b,p]=i.split(":");if(b==="xml"&&p==="lang")continue;a===p&&c.add(m)}else a===i&&c.add(m);if(c.size){const{name:i,value:m}=d||{};let b;switch(i?s?b=i.toLowerCase():b=i:m?s?b=m.toLowerCase():b=m:m===""&&(b=m),l){case"=":{typeof b=="string"&&c.has(b)&&(f=e);break}case"~=":{if(b&&typeof b=="string"){for(const p of c)if(new Set(p.split(/\s+/)).has(b)){f=e;break}}break}case"|=":{if(b&&typeof b=="string"){let p;for(const N of c)if(N===b||N.startsWith(`${b}-`)){p=N;break}p&&(f=e)}break}case"^=":{if(b&&typeof b=="string"){let p;for(const N of c)if(N.startsWith(`${b}`)){p=N;break}p&&(f=e)}break}case"$=":{if(b&&typeof b=="string"){let p;for(const N of c)if(N.endsWith(`${b}`)){p=N;break}p&&(f=e)}break}case"*=":{if(b&&typeof b=="string"){let p;for(const N of c)if(N.includes(`${b}`)){p=N;break}p&&(f=e)}break}case null:default:f=e}}}return f??null}_matchClassSelector(r,e){const n=(0,v.unescapeSelector)(r.name);let l;return e.classList.contains(n)&&(l=e),l??null}_matchIDSelector(r,e){const n=(0,v.unescapeSelector)(r.name),{id:l}=e;let t;return n===l&&(t=e),t??null}_matchTypeSelector(r,e,n={}){const l=(0,v.unescapeSelector)(r.name),{localName:t,prefix:d}=e,{forgive:h}=n;let{prefix:f,tagName:s}=(0,E.selectorToNodeProps)(l,e);this.#t.contentType==="text/html"&&(f=f.toLowerCase(),s=s.toLowerCase());let a,c;t.indexOf(":")>-1?[a,c]=t.split(":"):(a=d||"",c=t);let i;if(f===""&&a==="")e.namespaceURI===null&&(s==="*"||s===c)&&(i=e);else if(f==="*")(s==="*"||s===c)&&(i=e);else if(f===a){if((0,E.isNamespaceDeclared)(f,e))(s==="*"||s===c)&&(i=e);else if(!h){const m=`Undeclared namespace ${f}`;throw new DOMException(m,o.SYNTAX_ERR)}}else if(f&&!h&&!(0,E.isNamespaceDeclared)(f,e)){const m=`Undeclared namespace ${f}`;throw new DOMException(m,o.SYNTAX_ERR)}return i??null}_matchShadowHostPseudoClass(r,e){const{children:n}=r,l=(0,v.unescapeSelector)(r.name);let t;if(Array.isArray(n)){const[d]=(0,v.walkAST)(n[0]),[...h]=d,{host:f}=e;if(l==="host"){let s;for(const a of h){const{type:c}=a;if(c===o.COMBINATOR){const m=`Invalid selector ${(0,v.generateCSS)(r)}`;throw new DOMException(m,o.SYNTAX_ERR)}if(s=this._matchSelector(a,f).has(f),!s)break}s&&(t=e)}else if(l==="host-context"){let s,a=f;for(;a;){for(const c of h){const{type:i}=c;if(i===o.COMBINATOR){const b=`Invalid selector ${(0,v.generateCSS)(r)}`;throw new DOMException(b,o.SYNTAX_ERR)}if(s=this._matchSelector(c,a).has(a),!s)break}if(s)break;a=a.parentNode}s&&(t=e)}}else if(l==="host")t=e;else{const d=`Invalid selector :${l}`;throw new DOMException(d,o.SYNTAX_ERR)}return t??null}_matchSelector(r,e,n){const{type:l}=r,t=(0,v.unescapeSelector)(r.name);let d=new Set;if(e.nodeType===o.ELEMENT_NODE)switch(l){case o.SELECTOR_ATTR:{const h=this._matchAttributeSelector(r,e);h&&d.add(h);break}case o.SELECTOR_CLASS:{const h=this._matchClassSelector(r,e);h&&d.add(h);break}case o.SELECTOR_ID:{const h=this._matchIDSelector(r,e);h&&d.add(h);break}case o.SELECTOR_PSEUDO_CLASS:{const h=this._matchPseudoClassSelector(r,e,n);h.size&&(d=h);break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(t,n);break}case o.SELECTOR_TYPE:default:{const h=this._matchTypeSelector(r,e,n);h&&d.add(h)}}else if(this.#f&&l===o.SELECTOR_PSEUDO_CLASS&&e.nodeType===o.DOCUMENT_FRAGMENT_NODE){if(t!=="has"&&o.REG_LOGICAL_PSEUDO.test(t)){const h=this._matchPseudoClassSelector(r,e,n);h.size&&(d=h)}else if(o.REG_SHADOW_HOST.test(t)){const h=this._matchShadowHostPseudoClass(r,e);h&&d.add(h)}}return d}_matchLeaves(r,e,n){let l;for(const t of r)if(l=this._matchSelector(t,e,n).has(e),!l)break;return!!l}_findDescendantNodes(r,e){const[n,...l]=r,{type:t}=n,d=(0,v.unescapeSelector)(n.name),h=l.length>0;let f=new Set,s=!1;if(this.#f)s=!0;else switch(t){case o.SELECTOR_ID:{if(this.#s.nodeType===o.ELEMENT_NODE)s=!0;else{const a=this.#s.getElementById(d);a&&a!==e&&e.contains(a)&&(h?this._matchLeaves(l,a)&&f.add(a):f.add(a))}break}case o.SELECTOR_CLASS:{const a=[].slice.call(e.getElementsByClassName(d));if(a.length)if(h)for(const c of a)this._matchLeaves(l,c)&&f.add(c);else f=new Set(a);break}case o.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const a=[].slice.call(e.getElementsByTagName(d));if(a.length)if(h)for(const c of a)this._matchLeaves(l,c)&&f.add(c);else f=new Set(a)}else s=!0;break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(d);break}default:s=!0}return{nodes:f,pending:s}}_matchCombinator(r,e,n={}){const{combo:l,leaves:t}=r,{name:d}=l,{dir:h,forgive:f}=n;let s=new Set;if(h===C)switch(d){case"+":{const a=e.nextElementSibling;a&&this._matchLeaves(t,a,{forgive:f})&&s.add(a);break}case"~":{const{parentNode:a}=e;if(a){const c=this.#t.createTreeWalker(a,o.SHOW_ELEMENT);let i=this._traverse(e,c);for(i===e&&(i=c.nextSibling());i;)this._matchLeaves(t,i,{forgive:f})&&s.add(i),i=c.nextSibling()}break}case">":{const a=this.#t.createTreeWalker(e,o.SHOW_ELEMENT);let c=a.firstChild();for(;c;)this._matchLeaves(t,c,{forgive:f})&&s.add(c),c=a.nextSibling();break}case" ":default:{const{nodes:a,pending:c}=this._findDescendantNodes(t,e);if(a.size)s=a;else if(c){const i=this.#t.createTreeWalker(e,o.SHOW_ELEMENT);let m=i.nextNode();for(;m;)this._matchLeaves(t,m,{forgive:f})&&s.add(m),m=i.nextNode()}}}else switch(d){case"+":{const a=e.previousElementSibling;a&&this._matchLeaves(t,a,{forgive:f})&&s.add(a);break}case"~":{const a=this.#t.createTreeWalker(e.parentNode,o.SHOW_ELEMENT);let c=a.firstChild();for(;c&&c!==e;)this._matchLeaves(t,c,{forgive:f})&&s.add(c),c=a.nextSibling();break}case">":{const a=e.parentNode;a&&this._matchLeaves(t,a,{forgive:f})&&s.add(a);break}case" ":default:{const a=[];let c=e.parentNode;for(;c;)this._matchLeaves(t,c,{forgive:f})&&a.push(c),c=c.parentNode;a.length&&(s=new Set(a.reverse()))}}return s}_findNode(r,e={}){const{node:n}=e;let l,t=this._traverse(n,this.#r);if(t)for(t.nodeType!==o.ELEMENT_NODE?t=this.#r.nextNode():t===n&&t!==this.#s&&(t=this.#r.nextNode());t;){let d;if(this.#e.nodeType===o.ELEMENT_NODE?t===this.#e?d=!0:d=this.#e.contains(t):d=!0,d&&this._matchLeaves(r,t)){l=t;break}t=this.#r.nextNode()}return l??null}_findEntryNodes(r,e){const{leaves:n}=r,[l,...t]=n,{type:d}=l,h=(0,v.unescapeSelector)(l.name),f=t.length>0;let s=new Set,a=!1,c=!1;switch(d){case o.SELECTOR_ID:{if(e===D)this._matchLeaves(n,this.#e)&&(s.add(this.#e),a=!0);else if(e===$){let i=this.#e;for(;i;)this._matchLeaves(n,i)&&(s.add(i),a=!0),i=i.parentNode}else if(e===L&&this.#s.nodeType!==o.ELEMENT_NODE){const i=this.#s.getElementById(h);i&&s.add(i)}else c=!0;break}case o.SELECTOR_CLASS:{if(e===D)this.#e.nodeType===o.ELEMENT_NODE&&this.#e.classList.contains(h)&&s.add(this.#e);else if(e===$){let i=this.#e;for(;i&&i.nodeType===o.ELEMENT_NODE;)i.classList.contains(h)&&s.add(i),i=i.parentNode}else if(e===L){const i=this._findNode(n,{node:this.#e});i&&(s.add(i),a=!0)}else if(this.#s.nodeType===o.DOCUMENT_NODE){const i=[].slice.call(this.#s.getElementsByClassName(h));if(this.#e.nodeType===o.ELEMENT_NODE)for(const m of i)(m===this.#e||(0,E.isInclusive)(m,this.#e))&&s.add(m);else i.length&&(s=new Set(i))}else c=!0;break}case o.SELECTOR_TYPE:{if(e===D)this.#e.nodeType===o.ELEMENT_NODE&&this._matchLeaves(n,this.#e)&&(s.add(this.#e),a=!0);else if(e===$){let i=this.#e;for(;i&&i.nodeType===o.ELEMENT_NODE;)this._matchLeaves(n,i)&&(s.add(i),a=!0),i=i.parentNode}else if(e===L){const i=this._findNode(n,{node:this.#e});i&&(s.add(i),a=!0)}else if(this.#t.contentType==="text/html"&&this.#s.nodeType===o.DOCUMENT_NODE&&!/[*|]/.test(h)){const i=[].slice.call(this.#s.getElementsByTagName(h));if(this.#e.nodeType===o.ELEMENT_NODE)for(const m of i)(m===this.#e||(0,E.isInclusive)(m,this.#e))&&s.add(m);else i.length&&(s=new Set(i))}else c=!0;break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(h);break}default:if(e!==$&&o.REG_SHADOW_HOST.test(h)){if(this.#f&&this.#e.nodeType===o.DOCUMENT_FRAGMENT_NODE){const i=this._matchShadowHostPseudoClass(l,this.#e);i&&s.add(i)}}else if(e===D)this._matchLeaves(n,this.#e)&&(s.add(this.#e),a=!0);else if(e===$){let i=this.#e;for(;i;)this._matchLeaves(n,i)&&(s.add(i),a=!0),i=i.parentNode}else if(e===L){const i=this._findNode(n,{node:this.#e});i&&(s.add(i),a=!0)}else c=!0}return{compound:f,filtered:a,nodes:s,pending:c}}_getEntryTwig(r,e){const n=r.length,l=n>1,t=r[0];let d,h;if(l){const{combo:f,leaves:[{name:s,type:a}]}=t,c=r[n-1],{leaves:[{name:i,type:m}]}=c;if(m===o.SELECTOR_PSEUDO_ELEMENT||m===o.SELECTOR_ID)d=O,h=c;else if(a===o.SELECTOR_PSEUDO_ELEMENT||a===o.SELECTOR_ID)d=C,h=t;else if(e===A)if(s==="*"&&a===o.SELECTOR_TYPE)d=O,h=c;else if(i==="*"&&m===o.SELECTOR_TYPE)d=C,h=t;else if(n===2){const{name:b}=f;/^[+~]$/.test(b)?(d=O,h=c):(d=C,h=t)}else d=C,h=t;else if(i==="*"&&m===o.SELECTOR_TYPE)d=C,h=t;else if(s==="*"&&a===o.SELECTOR_TYPE)d=O,h=c;else{let b,p;for(const{combo:N,leaves:[k]}of r){const{type:u}=k,w=(0,v.unescapeSelector)(k.name);if(u===o.SELECTOR_PSEUDO_CLASS&&w==="dir"){b=!1;break}if(N&&!p){const{name:g}=N;/^[+~]$/.test(g)&&(b=!0,p=!0)}}b?(d=C,h=t):(d=O,h=c)}}else d=O,h=t;return{complex:l,dir:d,twig:h}}_collectNodes(r){const e=this.#i.values();if(r===A||r===L){const n=new Set;let l=0;for(const{branch:t}of e){const{dir:d,twig:h}=this._getEntryTwig(t,r),{compound:f,filtered:s,nodes:a,pending:c}=this._findEntryNodes(h,r);a.size?(this.#i[l].find=!0,this.#o[l]=a):c&&n.add(new Map([["index",l],["twig",h]])),this.#i[l].dir=d,this.#i[l].filtered=s||!f,l++}if(n.size){let t,d;this.#e!==this.#s&&this.#e.nodeType===o.ELEMENT_NODE?(t=this.#e,d=this.#r):(t=this.#s,d=this.#d);let h=this._traverse(t,d);for(;h;){let f=!1;if(this.#e.nodeType===o.ELEMENT_NODE?h===this.#e?f=!0:f=this.#e.contains(h):f=!0,f)for(const s of n){const{leaves:a}=s.get("twig");if(this._matchLeaves(a,h)){const i=s.get("index");this.#i[i].filtered=!0,this.#i[i].find=!0,this.#o[i].add(h)}}h=d.nextNode()}}}else{let n=0;for(const{branch:l}of e){const t=l[l.length-1],{compound:d,filtered:h,nodes:f}=this._findEntryNodes(t,r);f.size&&(this.#i[n].find=!0,this.#o[n]=f),this.#i[n].dir=O,this.#i[n].filtered=h||!d,n++}}return[this.#i,this.#o]}_sortNodes(r){const e=[...r];return e.length>1&&e.sort((n,l)=>{let t;return(0,E.isPreceding)(l,n)?t=1:t=-1,t}),e}_matchNodes(r){const[...e]=this.#i,n=e.length;let l=new Set;for(let t=0;t<n;t++){const{branch:d,dir:h,filtered:f,find:s}=e[t],a=d.length;if(a&&s){const c=this.#o[t],i=a-1;if(i===0){const{leaves:[,...m]}=d[0];if((r===A||r===L)&&this.#e.nodeType===o.ELEMENT_NODE){for(const b of c)if((f||this._matchLeaves(m,b))&&b!==this.#e&&this.#e.contains(b)&&(l.add(b),r!==A))break}else if(m.length){for(const b of c)if((f||this._matchLeaves(m,b))&&(l.add(b),r!==A))break}else if(r===A)if(l.size){const b=[...l];l=new Set([...b,...c]),this.#n=!0}else l=new Set([...c]);else{const[b]=[...c];l.add(b)}}else if(h===C){let{combo:m,leaves:b}=d[0];const[,...p]=b;let N;for(const k of c){if(f||this._matchLeaves(p,k)){let w=new Set([k]);for(let g=1;g<a;g++){const{combo:y,leaves:_}=d[g],x=[];for(const S of w){const P={combo:m,leaves:_},M=this._matchCombinator(P,S,{dir:h});M.size&&x.push(...M)}if(x.length)if(g===i){if(r===A){if(l.size){const S=[...l];l=new Set([...S,...x])}else l=new Set([...x]);this.#n=!0}else{const[S]=this._sortNodes(x);l.add(S)}N=!0}else m=y,w=new Set(x),N=!1;else{N=!1;break}}}else N=!1;if(N&&r!==A)break}if(!N&&r===L){const[k]=[...c];let u=this._findNode(b,{node:k});for(;u;){let w=new Set([u]);for(let g=1;g<a;g++){const{combo:y,leaves:_}=d[g],x=[];for(const S of w){const P={combo:m,leaves:_},M=this._matchCombinator(P,S,{dir:h});M.size&&x.push(...M)}if(x.length)if(g===i){const[S]=this._sortNodes(x);l.add(S),N=!0}else m=y,w=new Set(x),N=!1;else{N=!1;break}}if(N)break;u=this._findNode(b,{node:u}),w=new Set([u])}}}else{const{leaves:m}=d[i],[,...b]=m;let p;for(const N of c){if(f||this._matchLeaves(b,N)){let u=new Set([N]);for(let w=i-1;w>=0;w--){const g=d[w],y=[];for(const _ of u){const x=this._matchCombinator(g,_,{dir:h});x.size&&y.push(...x)}if(y.length)w===0?(l.add(N),p=!0,r===A&&a>1&&l.size>1&&(this.#n=!0)):(u=new Set(y),p=!1);else{p=!1;break}}}if(p&&r!==A)break}if(!p&&r===L){const[N]=[...c];let k=this._findNode(m,{node:N});for(;k;){let u=new Set([k]);for(let w=i-1;w>=0;w--){const g=d[w],y=[];for(const _ of u){const x=this._matchCombinator(g,_,{dir:h});x.size&&y.push(...x)}if(y.length)w===0?(l.add(k),p=!0):(u=new Set(y),p=!1);else{p=!1;break}}if(p)break;k=this._findNode(m,{node:k}),u=new Set([k])}}}}}return l}_find(r,e,n,l={}){const{warn:t}=l;if(this.#l=!!t,e){if(e.nodeType!==o.DOCUMENT_NODE&&e.nodeType!==o.DOCUMENT_FRAGMENT_NODE&&e.nodeType!==o.ELEMENT_NODE){const h=`Unexpected node ${e.nodeName}`;throw new TypeError(h)}else if((r===D||r===$)&&e.nodeType!==o.ELEMENT_NODE){const h=`Unexpected node ${e.nodeName}`;throw new TypeError(h)}}else{const f=`Unexpected node ${Object.prototype.toString.call(e).slice(o.TYPE_FROM,o.TYPE_TO)}`;throw new TypeError(f)}return this.#e=e,[this.#c,this.#t,this.#s]=this._setup(e),this.#f=(0,E.isInShadowTree)(e),this.#b=n,[this.#i,this.#o]=this._correspond(n),(r===A||r===L)&&(this.#d=this.#t.createTreeWalker(this.#s,I),this.#r=this.#t.createTreeWalker(this.#e,o.SHOW_ELEMENT),this.#n=!1),this._collectNodes(r),this._matchNodes(r)}matches(r,e,n){let l;try{const t=this._find(D,r,e,n);t.size&&(l=t.has(this.#e))}catch(t){this._onError(t)}return!!l}closest(r,e,n){let l;try{const t=this._find($,r,e,n);let d=this.#e;for(;d;){if(t.has(d)){l=d;break}d=d.parentNode}}catch(t){this._onError(t)}return l??null}querySelector(r,e,n){let l;try{const t=this._find(L,r,e,n);t.delete(this.#e),t.size&&([l]=this._sortNodes(t))}catch(t){this._onError(t)}return l??null}querySelectorAll(r,e,n){let l;try{const t=this._find(A,r,e,n);t.delete(this.#e),t.size&&(this.#n?l=this._sortNodes(t):l=[...t])}catch(t){this._onError(t)}return l??[]}}0&&(module.exports={Matcher});
2
2
  //# sourceMappingURL=matcher.js.map