@asamuzakjp/dom-selector 2.0.2 → 2.0.3-a.1
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 +2 -2
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/js/matcher.js +1 -1
- package/dist/cjs/js/matcher.js.map +3 -3
- package/package.json +4 -3
- package/src/index.js +66 -8
- package/src/js/matcher.js +236 -149
- package/types/index.d.ts +3 -0
- package/types/js/matcher.d.ts +5 -9
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
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
|
-
*/const
|
|
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
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -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/**\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)
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,
|
|
6
|
-
"names": ["src_exports", "__export", "closest", "matches", "querySelector", "querySelectorAll", "__toCommonJS", "import_matcher", "selector", "node", "opt"]
|
|
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
|
}
|
package/dist/cjs/js/matcher.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var W=Object.create;var R=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var F=(T,s)=>{for(var e in s)R(T,e,{get:s[e],enumerable:!0})},I=(T,s,e,f)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of B(s))!V.call(T,n)&&n!==e&&R(T,n,{get:()=>s[n],enumerable:!(f=z(s,n))||f.enumerable});return T};var H=(T,s,e)=>(e=T!=null?W(j(T)):{},I(s||!T||!T.__esModule?R(e,"default",{value:T,enumerable:!0}):e,T)),G=T=>I(R({},"__esModule",{value:!0}),T);var Y={};F(Y,{Matcher:()=>q});module.exports=G(Y);var U=H(require("is-potential-custom-element-name"),1),S=require("./dom-util.js"),v=require("./parser.js"),i=require("./constant.js");const C="next",O="prev",A="all",L="first",$="lineal",M="self";class q{#i;#h;#r;#s;#a;#e;#o;#t;#c;#f;#l;#n;constructor(s,e,f={}){const{warn:n}=f;this.#h=new Map([[i.SELECTOR_PSEUDO_ELEMENT,i.BIT_01],[i.SELECTOR_ID,i.BIT_02],[i.SELECTOR_CLASS,i.BIT_04],[i.SELECTOR_TYPE,i.BIT_08],[i.SELECTOR_ATTR,i.BIT_16],[i.SELECTOR_PSEUDO_CLASS,i.BIT_32]]),this.#r=new WeakMap,this.#e=e,[this.#n,this.#s,this.#t,this.#f]=this._setup(e),this.#c=(0,S.isInShadowTree)(e),[this.#i,this.#o]=this._correspond(s),this.#l=!!n}_onError(s){if((s instanceof DOMException||s instanceof this.#n.DOMException)&&s.name===i.NOT_SUPPORTED_ERR)this.#l&&console.warn(s.message);else throw s instanceof DOMException?new this.#n.DOMException(s.message,s.name):s instanceof TypeError?new this.#n.TypeError(s.message):s}_setup(s){let e,f;switch(s?.nodeType){case i.DOCUMENT_NODE:{e=s,f=s;break}case i.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,f=s;break}case i.ELEMENT_NODE:{if(s.ownerDocument.contains(s))e=s.ownerDocument,f=s.ownerDocument;else{let c=s;for(;c&&c.parentNode;)c=c.parentNode;e=c.ownerDocument,f=c}break}default:{let c;throw s?.nodeName?c=`Unexpected node ${s.nodeName}`:c=`Unexpected node ${Object.prototype.toString.call(s).slice(i.TYPE_FROM,i.TYPE_TO)}`,new TypeError(c)}}const n=i.SHOW_DOCUMENT|i.SHOW_DOCUMENT_FRAGMENT|i.SHOW_ELEMENT,l=e.createTreeWalker(f,n);return[e.defaultView,e,f,l]}_sortLeaves(s){const e=[...s];return e.length>1&&e.sort((f,n)=>{const{type:l}=f,{type:b}=n,c=this.#h.get(l),d=this.#h.get(b);let t;return c===d?t=0:c>d?t=1:t=-1,t}),e}_correspond(s){let e;try{e=(0,v.parseSelector)(s)}catch(c){this._onError(c)}const f=(0,v.walkAST)(e),n=[],l=[];let b=0;for(const[...c]of f){const d=[];let t=c.shift();if(t&&t.type!==i.COMBINATOR){const r=new Set;for(;t;){if(t.type===i.COMBINATOR){const[a]=c;if(a.type===i.COMBINATOR){const o=`Invalid combinator ${t.name}${a.name}`;throw new this.#n.DOMException(o,i.SYNTAX_ERR)}d.push({combo:t,leaves:this._sortLeaves(r)}),r.clear()}else t&&r.add(t);if(c.length)t=c.shift();else{d.push({combo:null,leaves:this._sortLeaves(r)}),r.clear();break}}}n.push({branch:d,dir:null,filtered:!1,find:!1}),l[b]=new Set,b++}return[n,l]}_traverse(s={},e=this.#f){let f,n=e.currentNode;if(s.nodeType===i.ELEMENT_NODE&&n===s)f=n;else{if(n!==e.root)for(;n&&!(n===e.root||s.nodeType===i.ELEMENT_NODE&&n===s);)n=e.parentNode();if(s.nodeType===i.ELEMENT_NODE)for(;n;){if(n===s){f=n;break}n=e.nextNode()}else f=n}return f??null}_collectNthChild(s,e){const{a:f,b:n,reverse:l,selector:b}=s,{parentNode:c}=e;let d=new Set,t;if(b&&(this.#r.has(b)?t=this.#r.get(b):(t=(0,v.walkAST)(b),this.#r.set(b,t))),c){const r=i.SHOW_DOCUMENT|i.SHOW_DOCUMENT_FRAGMENT|i.SHOW_ELEMENT,a=this.#s.createTreeWalker(c,r);let o=0,h=a.firstChild();for(;h;)o++,h=a.nextSibling();h=this._traverse(c,a);const m=new Set;if(t)for(h=this._traverse(c,a),h=a.firstChild();h;){let p;for(const g of t)if(p=this._matchLeaves(g,h),!p)break;p&&m.add(h),h=a.nextSibling()}if(f===0){if(n>0&&n<=o){if(m.size){let p=0;for(h=this._traverse(c,a),l?h=a.lastChild():h=a.firstChild();h;){if(m.has(h)){if(p===n-1){d.add(h);break}p++}l?h=a.previousSibling():h=a.nextSibling()}}else if(!b){let p=0;for(h=this._traverse(c,a),l?h=a.lastChild():h=a.firstChild();h;){if(p===n-1){d.add(h);break}l?h=a.previousSibling():h=a.nextSibling(),p++}}}}else{let p=n-1;if(f>0)for(;p<0;)p+=f;if(p>=0&&p<o){let g=0,N=f>0?0:n-1;for(h=this._traverse(c,a),l?h=a.lastChild():h=a.firstChild();h&&(h&&p>=0&&p<o);)m.size?m.has(h)&&(N===p&&(d.add(h),p+=f),f>0?N++:N--):g===p&&(b||d.add(h),p+=f),l?h=a.previousSibling():h=a.nextSibling(),g++}}if(l&&d.size>1){const p=[...d];d=new Set(p.reverse())}}else if(e===this.#t&&this.#t.nodeType===i.ELEMENT_NODE&&f+n===1)if(t){let r;for(const a of t)if(r=this._matchLeaves(a,e),r)break;r&&d.add(e)}else d.add(e);return d}_collectNthOfType(s,e){const{a:f,b:n,reverse:l}=s,{localName:b,parentNode:c,prefix:d}=e;let t=new Set;if(c){const r=i.SHOW_DOCUMENT|i.SHOW_DOCUMENT_FRAGMENT|i.SHOW_ELEMENT,a=this.#s.createTreeWalker(c,r);let o=0,h=a.firstChild();for(;h;)o++,h=a.nextSibling();if(f===0){if(n>0&&n<=o){let m=0;for(h=this._traverse(c,a),l?h=a.lastChild():h=a.firstChild();h;){const{localName:p,prefix:g}=h;if(p===b&&g===d){if(m===n-1){t.add(h);break}m++}l?h=a.previousSibling():h=a.nextSibling()}}}else{let m=n-1;if(f>0)for(;m<0;)m+=f;if(m>=0&&m<o){let p=f>0?0:n-1;for(h=this._traverse(c,a),l?h=a.lastChild():h=a.firstChild();h;){const{localName:g,prefix:N}=h;if(g===b&&N===d){if(p===m&&(t.add(h),m+=f),m<0||m>=o)break;f>0?p++:p--}l?h=a.previousSibling():h=a.nextSibling()}}}if(l&&t.size>1){const m=[...t];t=new Set(m.reverse())}}else e===this.#t&&this.#t.nodeType===i.ELEMENT_NODE&&f+n===1&&t.add(e);return t}_matchAnPlusB(s,e,f){const{nth:{a:n,b:l,name:b},selector:c}=s,d=(0,v.unescapeSelector)(b),t=new Map;d?(d==="even"?(t.set("a",2),t.set("b",0)):d==="odd"&&(t.set("a",2),t.set("b",1)),f.indexOf("last")>-1&&t.set("reverse",!0)):(typeof n=="string"&&/-?\d+/.test(n)?t.set("a",n*1):t.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?t.set("b",l*1):t.set("b",0),f.indexOf("last")>-1&&t.set("reverse",!0));let r=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(f)){c&&t.set("selector",c);const a=Object.fromEntries(t),o=this._collectNthChild(a,e);o.size&&(r=o)}else if(/^nth-(?:last-)?of-type$/.test(f)){const a=Object.fromEntries(t),o=this._collectNthOfType(a,e);o.size&&(r=o)}}return r}_matchPseudoElementSelector(s,e={}){const{forgive:f}=e;switch(s){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 n=`Unsupported pseudo-element ::${s}`;throw new DOMException(n,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(this.#l){const n=`Unsupported pseudo-element ::${s}()`;throw new DOMException(n,i.NOT_SUPPORTED_ERR)}break}default:if(s.startsWith("-webkit-")){if(this.#l){const n=`Unsupported pseudo-element ::${s}`;throw new DOMException(n,i.NOT_SUPPORTED_ERR)}}else if(!f){const n=`Unknown pseudo-element ::${s}`;throw new DOMException(n,i.SYNTAX_ERR)}}}_matchDirectionPseudoClass(s,e){const f=(0,v.unescapeSelector)(s.name),n=(0,S.getDirectionality)(e);let l;return f===n&&(l=e),l??null}_matchLanguagePseudoClass(s,e){const f=(0,v.unescapeSelector)(s.name);let n;if(f==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(n=e);else{let l=e.parentNode;for(;l&&l.nodeType===i.ELEMENT_NODE;){if(l.hasAttribute("lang")){l.getAttribute("lang")&&(n=e);break}l=l.parentNode}}else if(f){const l=`(?:-${i.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${i.ALPHA_NUM}${l}$`,"i").test(f)){let c;if(f.indexOf("-")>-1){const[d,t,...r]=f.split("-");let a;d==="*"?a=`${i.ALPHA_NUM}${l}`:a=`${d}${l}`;const o=`-${t}${l}`,h=r.length;let m="";if(h)for(let p=0;p<h;p++)m+=`-${r[p]}${l}`;c=new RegExp(`^${a}${o}${m}$`,"i")}else c=new RegExp(`^${f}${l}$`,"i");if(e.hasAttribute("lang"))c.test(e.getAttribute("lang"))&&(n=e);else{let d=e.parentNode;for(;d&&d.nodeType===i.ELEMENT_NODE;){if(d.hasAttribute("lang")){const t=d.getAttribute("lang");c.test(t)&&(n=e);break}d=d.parentNode}}}}return n??null}_matchHasPseudoFunc(s,e){let f;if(Array.isArray(s)&&s.length){const[n]=s,{type:l}=n;let b;l===i.COMBINATOR?b=s.shift():b={name:" ",type:i.COMBINATOR};const c=[];for(;s.length;){const[r]=s,{type:a}=r;if(a===i.COMBINATOR)break;c.push(s.shift())}const d={combo:b,leaves:c},t=this._matchCombinator(d,e,{dir:C});if(t.size)if(s.length){for(const r of t)if(f=this._matchHasPseudoFunc(Object.assign([],s),r),f)break}else f=!0}return!!f}_matchLogicalPseudoFunc(s,e){const{astName:f="",branches:n=[],selector:l="",twigBranches:b=[]}=s;let c;if(f==="has")if(l.includes(":has("))c=null;else{let d;for(const t of n)if(d=this._matchHasPseudoFunc(Object.assign([],t),e),d)break;d&&(c=e)}else{const d=/^(?:is|where)$/.test(f),t=b.length;let r;for(let a=0;a<t;a++){const o=b[a],h=o.length-1,{leaves:m}=o[h];if(r=this._matchLeaves(m,e,{forgive:d}),r&&h>0){let p=new Set([e]);for(let g=h-1;g>=0;g--){const N=o[g],u=[];for(const w of p){const k=this._matchCombinator(N,w,{forgive:d,dir:O});k.size&&u.push(...k)}if(u.length)g===0?r=!0:p=new Set(u);else{r=!1;break}}}if(r)break}f==="not"?r||(c=e):r&&(c=e)}return c??null}_matchPseudoClassSelector(s,e,f={}){const{children:n}=s,{localName:l,parentNode:b}=e,{forgive:c}=f,d=(0,v.unescapeSelector)(s.name);let t=new Set;if(i.REG_LOGICAL_PSEUDO.test(d)){let r;if(this.#r.has(s))r=this.#r.get(s);else{const o=(0,v.walkAST)(s),h=[],m=[];for(const[...p]of o){for(const w of p){const k=(0,v.generateCSS)(w);h.push(k)}const g=[],N=new Set;let u=p.shift();for(;u;)if(u.type===i.COMBINATOR?(g.push({combo:u,leaves:[...N]}),N.clear()):u&&N.add(u),p.length)u=p.shift();else{g.push({combo:null,leaves:[...N]}),N.clear();break}m.push(g)}r={astName:d,branches:o,twigBranches:m,selector:h.join(",")},this.#r.set(s,r)}const a=this._matchLogicalPseudoFunc(r,e);a&&t.add(a)}else if(Array.isArray(n)){const[r]=n;if(/^nth-(?:last-)?(?:child|of-type)$/.test(d)){const a=this._matchAnPlusB(r,e,d);a.size&&(t=a)}else if(d==="dir"){const a=this._matchDirectionPseudoClass(r,e);a&&t.add(a)}else if(d==="lang"){const a=this._matchLanguagePseudoClass(r,e);a&&t.add(a)}else switch(d){case"current":case"nth-col":case"nth-last-col":{if(this.#l){const a=`Unsupported pseudo-class :${d}()`;throw new DOMException(a,i.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!c){const a=`Unknown pseudo-class :${d}()`;throw new DOMException(a,i.SYNTAX_ERR)}}}else{const r=/^a(?:rea)?$/,a=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,o=/^(?:(?:inpu|selec)t|button|form|textarea)$/,h=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,p=/^(?:date(?:time-local)?|month|time|week)$/,g=/(?:(?: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":{r.test(l)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(r.test(l)&&e.hasAttribute("href")){const{href:u,origin:w,pathname:k}=new URL(this.#s.URL),y=new URL(e.getAttribute("href"),u);y.origin===w&&y.pathname===k&&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 k=this.#s.getElementById(w);for(;k;){if(k===e){t.add(e);break}k=k.parentNode}}break}case"scope":{this.#e.nodeType===i.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":{h.test(l)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{h.test(l)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(a.test(l)||(0,U.default)(l))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let u=b;for(;u&&u.localName!=="fieldset";)u=u.parentNode;u&&b.localName!=="legend"&&u.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(a.test(l)||(0,U.default)(l))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(l){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,S.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(l){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,S.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let u;l==="textarea"?u=e:l==="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&&l==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&l==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))t.add(e);else if(l==="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 k;const y=[].slice.call(w.getElementsByTagName("input"));for(const _ of y)if(_.getAttribute("type")==="radio"&&(u?_.getAttribute("name")===u&&(k=!!_.checked):_.hasAttribute("name")||(k=!!_.checked),k))break;k||t.add(e)}break}case"default":{const u=/^(?:button|reset)$/,w=/^(?:image|submit)$/;if(l==="button"&&!(e.hasAttribute("type")&&u.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))){let k=e.parentNode;for(;k&&k.localName!=="form";)k=k.parentNode;if(k){const y=this.#s.createTreeWalker(k,i.SHOW_ELEMENT);let _=y.firstChild();for(;_;){const x=_.localName;let E;if(x==="button"?E=!(_.hasAttribute("type")&&u.test(_.getAttribute("type"))):x==="input"&&(E=_.hasAttribute("type")&&w.test(_.getAttribute("type"))),E){_===e&&t.add(e);break}_=y.nextNode()}}}else if(l==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(l==="option"){let k=!1,y=b;for(;y&&y.localName!=="datalist";){if(y.localName==="select"){(y.multiple||y.hasAttribute("multiple"))&&(k=!0);break}y=y.parentNode}if(k)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const _=new Set,x=this.#s.createTreeWalker(b,i.SHOW_ELEMENT);let E=x.firstChild();for(;E;){if(E.selected||E.hasAttribute("selected")){_.add(E);break}E=x.nextSibling()}_.size&&_.has(e)&&t.add(e)}}break}case"valid":{if(o.test(l))e.checkValidity()&&t.add(e);else if(l==="fieldset"){let u;const w=this.#s.createTreeWalker(e,i.SHOW_ELEMENT);let k=w.firstChild();for(;k&&!(o.test(k.localName)&&(u=k.checkValidity(),!u));)k=w.nextNode();u&&t.add(e)}break}case"invalid":{if(o.test(l))e.checkValidity()||t.add(e);else if(l==="fieldset"){let u;const w=this.#s.createTreeWalker(e,i.SHOW_ELEMENT);let k=w.firstChild();for(;k&&!(o.test(k.localName)&&(u=k.checkValidity(),!u));)k=w.nextNode();u||t.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&g.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":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let u;if(/^(?:select|textarea)$/.test(l))u=e;else if(l==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||m.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(l))u=e;else if(l==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||m.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,i.SHOW_ALL);let k=w.firstChild();for(;k&&(u=k.nodeType!==i.ELEMENT_NODE&&k.nodeType!==i.TEXT_NODE,!!u);)k=w.nextSibling();u&&t.add(e)}else t.add(e);break}case"first-child":{(b&&e===b.firstElementChild||e===this.#t&&this.#t.nodeType===i.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(b&&e===b.lastElementChild||e===this.#t&&this.#t.nodeType===i.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(b&&e===b.firstElementChild&&e===b.lastElementChild||e===this.#t&&this.#t.nodeType===i.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(b){const[u]=this._collectNthOfType({a:0,b:1},e);u&&t.add(u)}else e===this.#t&&this.#t.nodeType===i.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(b){const[u]=this._collectNthOfType({a:0,b:1,reverse:!0},e);u&&t.add(u)}else e===this.#t&&this.#t.nodeType===i.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(b){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===i.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,i.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,i.NOT_SUPPORTED_ERR)}break}default:if(d.startsWith("-webkit-")){if(this.#l){const u=`Unsupported pseudo-class :${d}`;throw new DOMException(u,i.NOT_SUPPORTED_ERR)}}else if(!c){const u=`Unknown pseudo-class :${d}`;throw new DOMException(u,i.SYNTAX_ERR)}}}return t}_matchAttributeSelector(s,e){const{flags:f,matcher:n,name:l,value:b}=s;if(typeof f=="string"&&!/^[is]$/i.test(f)){const r=`Invalid selector ${(0,v.generateCSS)(s)}`;throw new DOMException(r,i.SYNTAX_ERR)}const{attributes:c}=e;let d;if(c&&c.length){let t;this.#s.contentType==="text/html"?typeof f=="string"&&/^s$/i.test(f)?t=!1:t=!0:typeof f=="string"&&/^i$/i.test(f)?t=!0:t=!1;let r=(0,v.unescapeSelector)(l.name);t&&(r=r.toLowerCase());const a=new Set;if(r.indexOf("|")>-1){const{prefix:o,tagName:h}=(0,S.selectorToNodeProps)(r);for(let{name:m,value:p}of c)switch(t&&(m=m.toLowerCase(),p=p.toLowerCase()),o){case"":{h===m&&a.add(p);break}case"*":{m.indexOf(":")>-1?m.endsWith(`:${h}`)&&a.add(p):h===m&&a.add(p);break}default:if(m.indexOf(":")>-1){const[g,N]=m.split(":");o===g&&h===N&&(0,S.isNamespaceDeclared)(o,e)&&a.add(p)}}}else for(let{name:o,value:h}of c)if(t&&(o=o.toLowerCase(),h=h.toLowerCase()),o.indexOf(":")>-1){const[m,p]=o.split(":");if(m==="xml"&&p==="lang")continue;r===p&&a.add(h)}else r===o&&a.add(h);if(a.size){const{name:o,value:h}=b||{};let m;switch(o?t?m=o.toLowerCase():m=o:h?t?m=h.toLowerCase():m=h:h===""&&(m=h),n){case"=":{typeof m=="string"&&a.has(m)&&(d=e);break}case"~=":{if(m&&typeof m=="string"){for(const p of a)if(new Set(p.split(/\s+/)).has(m)){d=e;break}}break}case"|=":{if(m&&typeof m=="string"){let p;for(const g of a)if(g===m||g.startsWith(`${m}-`)){p=g;break}p&&(d=e)}break}case"^=":{if(m&&typeof m=="string"){let p;for(const g of a)if(g.startsWith(`${m}`)){p=g;break}p&&(d=e)}break}case"$=":{if(m&&typeof m=="string"){let p;for(const g of a)if(g.endsWith(`${m}`)){p=g;break}p&&(d=e)}break}case"*=":{if(m&&typeof m=="string"){let p;for(const g of a)if(g.includes(`${m}`)){p=g;break}p&&(d=e)}break}case null:default:d=e}}}return d??null}_matchClassSelector(s,e){const f=(0,v.unescapeSelector)(s.name);let n;return e.classList.contains(f)&&(n=e),n??null}_matchIDSelector(s,e){const f=(0,v.unescapeSelector)(s.name),{id:n}=e;let l;return f===n&&(l=e),l??null}_matchTypeSelector(s,e,f={}){const n=(0,v.unescapeSelector)(s.name),{localName:l,prefix:b}=e,{forgive:c}=f;let{prefix:d,tagName:t}=(0,S.selectorToNodeProps)(n,e);this.#s.contentType==="text/html"&&(d=d.toLowerCase(),t=t.toLowerCase());let r,a;l.indexOf(":")>-1?[r,a]=l.split(":"):(r=b||"",a=l);let o;if(d===""&&r==="")e.namespaceURI===null&&(t==="*"||t===a)&&(o=e);else if(d==="*")(t==="*"||t===a)&&(o=e);else if(d===r){if((0,S.isNamespaceDeclared)(d,e))(t==="*"||t===a)&&(o=e);else if(!c){const h=`Undeclared namespace ${d}`;throw new DOMException(h,i.SYNTAX_ERR)}}else if(d&&!c&&!(0,S.isNamespaceDeclared)(d,e)){const h=`Undeclared namespace ${d}`;throw new DOMException(h,i.SYNTAX_ERR)}return o??null}_matchShadowHostPseudoClass(s,e){const{children:f}=s,n=(0,v.unescapeSelector)(s.name);let l;if(Array.isArray(f)){const[b]=(0,v.walkAST)(f[0]),[...c]=b,{host:d}=e;if(n==="host"){let t;for(const r of c){const{type:a}=r;if(a===i.COMBINATOR){const h=`Invalid selector ${(0,v.generateCSS)(s)}`;throw new DOMException(h,i.SYNTAX_ERR)}if(t=this._matchSelector(r,d).has(d),!t)break}t&&(l=e)}else if(n==="host-context"){let t,r=d;for(;r;){for(const a of c){const{type:o}=a;if(o===i.COMBINATOR){const m=`Invalid selector ${(0,v.generateCSS)(s)}`;throw new DOMException(m,i.SYNTAX_ERR)}if(t=this._matchSelector(a,r).has(r),!t)break}if(t)break;r=r.parentNode}t&&(l=e)}}else if(n==="host")l=e;else{const b=`Invalid selector :${n}`;throw new DOMException(b,i.SYNTAX_ERR)}return l??null}_matchSelector(s,e,f){const{type:n}=s,l=(0,v.unescapeSelector)(s.name);let b=new Set;if(e.nodeType===i.ELEMENT_NODE)switch(n){case i.SELECTOR_ATTR:{const c=this._matchAttributeSelector(s,e);c&&b.add(c);break}case i.SELECTOR_CLASS:{const c=this._matchClassSelector(s,e);c&&b.add(c);break}case i.SELECTOR_ID:{const c=this._matchIDSelector(s,e);c&&b.add(c);break}case i.SELECTOR_PSEUDO_CLASS:{const c=this._matchPseudoClassSelector(s,e,f);c.size&&(b=c);break}case i.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(l,f);break}case i.SELECTOR_TYPE:default:{const c=this._matchTypeSelector(s,e,f);c&&b.add(c)}}else if(this.#c&&n===i.SELECTOR_PSEUDO_CLASS&&e.nodeType===i.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&i.REG_LOGICAL_PSEUDO.test(l)){const c=this._matchPseudoClassSelector(s,e,f);c.size&&(b=c)}else if(i.REG_SHADOW_HOST.test(l)){const c=this._matchShadowHostPseudoClass(s,e);c&&b.add(c)}}return b}_matchLeaves(s,e,f){let n;for(const l of s)if(n=this._matchSelector(l,e,f).has(e),!n)break;return!!n}_findDescendantNodes(s,e){const[f,...n]=s,{type:l}=f,b=(0,v.unescapeSelector)(f.name),c=n.length>0;let d=new Set,t=!1;if(this.#c)t=!0;else switch(l){case i.SELECTOR_ID:{if(this.#t.nodeType===i.ELEMENT_NODE)t=!0;else{const r=this.#t.getElementById(b);r&&r!==e&&e.contains(r)&&(c?this._matchLeaves(n,r)&&d.add(r):d.add(r))}break}case i.SELECTOR_CLASS:{const r=[].slice.call(e.getElementsByClassName(b));if(r.length)if(c)for(const a of r)this._matchLeaves(n,a)&&d.add(a);else d=new Set(r);break}case i.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(b)){const r=[].slice.call(e.getElementsByTagName(b));if(r.length)if(c)for(const a of r)this._matchLeaves(n,a)&&d.add(a);else d=new Set(r)}else t=!0;break}case i.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(b);break}default:t=!0}return{nodes:d,pending:t}}_matchCombinator(s,e,f={}){const{combo:n,leaves:l}=s,{name:b}=n,{dir:c,forgive:d}=f;let t=new Set;if(c===C)switch(b){case"+":{const r=e.nextElementSibling;r&&this._matchLeaves(l,r,{forgive:d})&&t.add(r);break}case"~":{const{parentNode:r}=e;if(r){const a=this.#s.createTreeWalker(r,i.SHOW_ELEMENT);let o=this._traverse(e,a);for(o===e&&(o=a.nextSibling());o;)this._matchLeaves(l,o,{forgive:d})&&t.add(o),o=a.nextSibling()}break}case">":{const r=this.#s.createTreeWalker(e,i.SHOW_ELEMENT);let a=r.firstChild();for(;a;)this._matchLeaves(l,a,{forgive:d})&&t.add(a),a=r.nextSibling();break}case" ":default:{const{nodes:r,pending:a}=this._findDescendantNodes(l,e);if(r.size)t=r;else if(a){const o=this.#s.createTreeWalker(e,i.SHOW_ELEMENT);let h=o.nextNode();for(;h;)this._matchLeaves(l,h,{forgive:d})&&t.add(h),h=o.nextNode()}}}else switch(b){case"+":{const r=e.previousElementSibling;r&&this._matchLeaves(l,r,{forgive:d})&&t.add(r);break}case"~":{const r=this.#s.createTreeWalker(e.parentNode,i.SHOW_ELEMENT);let a=r.firstChild();for(;a&&a!==e;)this._matchLeaves(l,a,{forgive:d})&&t.add(a),a=r.nextSibling();break}case">":{const r=e.parentNode;r&&this._matchLeaves(l,r,{forgive:d})&&t.add(r);break}case" ":default:{const r=[];let a=e.parentNode;for(;a;)this._matchLeaves(l,a,{forgive:d})&&r.push(a),a=a.parentNode;r.length&&(t=new Set(r.reverse()))}}return t}_findNode(s,e={}){let{node:f,walker:n}=e;n||(n=this.#f);let l,b=this._traverse(f,n);if(b)for((b.nodeType!==i.ELEMENT_NODE||b===f&&b!==this.#t)&&(b=n.nextNode());b;){let c;if(this.#e.nodeType===i.ELEMENT_NODE?b===this.#e?c=!0:c=this.#e.contains(b):c=!0,c&&this._matchLeaves(s,b)){l=b;break}b=n.nextNode()}return l??null}_findEntryNodes(s,e){const{leaves:f}=s,[n,...l]=f,{type:b}=n,c=(0,v.unescapeSelector)(n.name),d=l.length>0;let t=new Set,r=!1,a=!1;switch(b){case i.SELECTOR_ID:{if(e===M)this._matchLeaves(f,this.#e)&&(t.add(this.#e),r=!0);else if(e===$){let o=this.#e;for(;o;)this._matchLeaves(f,o)&&(t.add(o),r=!0),o=o.parentNode}else if(e===A||this.#t.nodeType===i.ELEMENT_NODE)a=!0;else{const o=this.#t.getElementById(c);o&&(t.add(o),r=!0)}break}case i.SELECTOR_CLASS:{if(e===M)this.#e.nodeType===i.ELEMENT_NODE&&this.#e.classList.contains(c)&&t.add(this.#e);else if(e===$){let o=this.#e;for(;o&&o.nodeType===i.ELEMENT_NODE;)o.classList.contains(c)&&t.add(o),o=o.parentNode}else if(e===L){const o=this._findNode(f,{node:this.#e,walker:this.#a});if(o){t.add(o),r=!0;break}}else if(this.#t.nodeType===i.DOCUMENT_FRAGMENT_NODE||this.#t.nodeType===i.ELEMENT_NODE)a=!0;else{const o=[].slice.call(this.#t.getElementsByClassName(c));if(this.#e.nodeType===i.ELEMENT_NODE)for(const h of o)(h===this.#e||(0,S.isInclusive)(h,this.#e))&&t.add(h);else o.length&&(t=new Set(o))}break}case i.SELECTOR_TYPE:{if(e===M)this.#e.nodeType===i.ELEMENT_NODE&&this._matchLeaves(f,this.#e)&&(t.add(this.#e),r=!0);else if(e===$){let o=this.#e;for(;o&&o.nodeType===i.ELEMENT_NODE;)this._matchLeaves(f,o)&&(t.add(o),r=!0),o=o.parentNode}else if(e===L){const o=this._findNode(f,{node:this.#e,walker:this.#a});if(o){t.add(o),r=!0;break}}else if(this.#s.contentType!=="text/html"||/[*|]/.test(c)||this.#t.nodeType===i.DOCUMENT_FRAGMENT_NODE||this.#t.nodeType===i.ELEMENT_NODE)a=!0;else{const o=[].slice.call(this.#t.getElementsByTagName(c));if(this.#e.nodeType===i.ELEMENT_NODE)for(const h of o)(h===this.#e||(0,S.isInclusive)(h,this.#e))&&t.add(h);else o.length&&(t=new Set(o))}break}case i.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(c);break}default:if(e!==$&&i.REG_SHADOW_HOST.test(c)){if(this.#c&&this.#e.nodeType===i.DOCUMENT_FRAGMENT_NODE){const o=this._matchShadowHostPseudoClass(n,this.#e);o&&t.add(o)}}else if(e===M)this._matchLeaves(f,this.#e)&&(t.add(this.#e),r=!0);else if(e===$){let o=this.#e;for(;o;)this._matchLeaves(f,o)&&(t.add(o),r=!0),o=o.parentNode}else if(e===L){const o=this._findNode(f,{node:this.#e,walker:this.#a});if(o){t.add(o),r=!0;break}}else a=!0}return{compound:d,filtered:r,nodes:t,pending:a}}_getEntryTwig(s,e){const f=s.length,n=f>1,l=s[0];let b,c;if(n){const{combo:d,leaves:[{type:t}]}=l,r=s[f-1],{leaves:[{type:a}]}=r;if(a===i.SELECTOR_PSEUDO_ELEMENT||a===i.SELECTOR_ID)b=O,c=r;else if(t===i.SELECTOR_PSEUDO_ELEMENT||t===i.SELECTOR_ID)b=C,c=l;else if(e===A)if(f===2){const{name:o}=d;/^[+~]$/.test(o)?(b=O,c=r):(b=C,c=l)}else b=C,c=l;else{let o,h;for(const{combo:m,leaves:[p]}of s){const{type:g}=p,N=(0,v.unescapeSelector)(p.name);if(g===i.SELECTOR_PSEUDO_CLASS&&N==="dir"){o=!1;break}if(m&&!h){const{name:u}=m;/^[+~]$/.test(u)&&(o=!0,h=!0)}}o?(b=C,c=l):(b=O,c=r)}}else b=O,c=l;return{complex:n,dir:b,twig:c}}_collectNodes(s){const e=this.#i.values();if(s===A||s===L){const f=new Set;let n=0;for(const{branch:l}of e){const{dir:b,twig:c}=this._getEntryTwig(l,s),{compound:d,filtered:t,nodes:r,pending:a}=this._findEntryNodes(c,s);r.size?(this.#i[n].find=!0,this.#o[n]=r):a&&f.add(new Map([["index",n],["twig",c]])),this.#i[n].dir=b,this.#i[n].filtered=t||!d,n++}if(f.size){let l,b;this.#e!==this.#t&&this.#e.nodeType===i.ELEMENT_NODE?(l=this.#e,b=this.#a):(l=this.#t,b=this.#f);let c=this._traverse(l,b);for(;c;){let d=!1;if(this.#e.nodeType===i.ELEMENT_NODE?c===this.#e?d=!0:d=this.#e.contains(c):d=!0,d)for(const t of f){const{leaves:r}=t.get("twig");if(this._matchLeaves(r,c)){const o=t.get("index");this.#i[o].filtered=!0,this.#i[o].find=!0,this.#o[o].add(c)}}c=b.nextNode()}}}else{let f=0;for(const{branch:n}of e){const l=n[n.length-1],{compound:b,filtered:c,nodes:d}=this._findEntryNodes(l,s);d.size&&(this.#i[f].find=!0,this.#o[f]=d),this.#i[f].dir=O,this.#i[f].filtered=c||!b,f++}}return[this.#i,this.#o]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((f,n)=>{let l;return(0,S.isPreceding)(n,f)?l=1:l=-1,l}),e}_matchNodes(s){const[...e]=this.#i,f=e.length;let n=new Set;for(let l=0;l<f;l++){const{branch:b,dir:c,filtered:d,find:t}=e[l],r=b.length;if(r&&t){const a=this.#o[l],o=r-1;if(o===0){const{leaves:[,...h]}=b[0];if((s===A||s===L)&&this.#e.nodeType===i.ELEMENT_NODE){for(const m of a)if((d||this._matchLeaves(h,m))&&m!==this.#e&&this.#e.contains(m)&&(n.add(m),s!==A))break}else if(h.length){for(const m of a)if((d||this._matchLeaves(h,m))&&(n.add(m),s!==A))break}else if(s===A){const m=[...n];n=new Set([...m,...a])}else{const[m]=[...a];n.add(m)}}else if(c===C){let{combo:h,leaves:m}=b[0];const[,...p]=m;let g;for(const N of a){if(d||this._matchLeaves(p,N)){let w=new Set([N]);for(let k=1;k<r;k++){const{combo:y,leaves:_}=b[k],x=[];for(const E of w){const P={combo:h,leaves:_},D=this._matchCombinator(P,E,{dir:c});D.size&&x.push(...D)}if(x.length)if(k===o){if(s===A){const E=[...n];n=new Set([...E,...x])}else{const[E]=this._sortNodes(x);n.add(E)}g=!0}else h=y,w=new Set(x),g=!1;else{g=!1;break}}}else g=!1;if(g&&s!==A)break}if(!g&&s===L){const[N]=[...a];let u=this._findNode(m,{node:N,walker:this.#a});for(;u;){let w=new Set([u]);for(let k=1;k<r;k++){const{combo:y,leaves:_}=b[k],x=[];for(const E of w){const P={combo:h,leaves:_},D=this._matchCombinator(P,E,{dir:c});D.size&&x.push(...D)}if(x.length)if(k===o){const[E]=this._sortNodes(x);n.add(E),g=!0}else h=y,w=new Set(x),g=!1;else{g=!1;break}}if(g)break;u=this._findNode(m,{node:u,walker:this.#a}),w=new Set([u])}}}else{const{leaves:h}=b[o],[,...m]=h;let p;for(const g of a){if(d||this._matchLeaves(m,g)){let u=new Set([g]);for(let w=o-1;w>=0;w--){const k=b[w],y=[];for(const _ of u){const x=this._matchCombinator(k,_,{dir:c});x.size&&y.push(...x)}if(y.length)w===0?(n.add(g),p=!0):(u=new Set(y),p=!1);else{p=!1;break}}}if(p&&s!==A)break}if(!p&&s===L){const[g]=[...a];let N=this._findNode(h,{node:g,walker:this.#a});for(;N;){let u=new Set([N]);for(let w=o-1;w>=0;w--){const k=b[w],y=[];for(const _ of u){const x=this._matchCombinator(k,_,{dir:c});x.size&&y.push(...x)}if(y.length)w===0?(n.add(N),p=!0):(u=new Set(y),p=!1);else{p=!1;break}}if(p)break;N=this._findNode(h,{node:N,walker:this.#a}),u=new Set([N])}}}}}return n}_find(s){return(s===A||s===L)&&(this.#a=this.#s.createTreeWalker(this.#e,i.SHOW_ELEMENT)),this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==i.ELEMENT_NODE){const e=`Unexpected node ${this.#e.nodeName}`;this._onError(new TypeError(e))}let s;try{const e=this._find(M);e.size&&(s=e.has(this.#e))}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==i.ELEMENT_NODE){const e=`Unexpected node ${this.#e.nodeName}`;this._onError(new TypeError(e))}let s;try{const e=this._find($);let f=this.#e;for(;f;){if(e.has(f)){s=f;break}f=f.parentNode}}catch(e){this._onError(e)}return s??null}querySelector(){let s;try{const e=this._find(L);e.delete(this.#e),e.size&&([s]=this._sortNodes(e))}catch(e){this._onError(e)}return s??null}querySelectorAll(){let s;try{const e=this._find(A);e.delete(this.#e),e.size&&(s=this._sortNodes(e))}catch(e){this._onError(e)}return s??[]}}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
|