@asamuzakjp/dom-selector
Advanced tools
Comparing version 4.4.3 to 4.4.4
@@ -1,2 +0,2 @@ | ||
var W=Object.create;var D=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(y,a)=>{for(var e in a)D(y,e,{get:a[e],enumerable:!0})},I=(y,a,e,f)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of j(a))!q.call(y,r)&&r!==e&&D(y,r,{get:()=>a[r],enumerable:!(f=B(a,r))||f.enumerable});return y};var U=(y,a,e)=>(e=y!=null?W(Y(y)):{},I(a||!y||!y.__esModule?D(e,"default",{value:y,enumerable:!0}):e,y)),X=y=>I(D({},"__esModule",{value:!0}),y);var Q={};V(Q,{Finder:()=>K});module.exports=X(Q);var M=U(require("is-potential-custom-element-name"),1),$=U(require("@asamuzakjp/nwsapi"),1),E=require("./dom-util.js"),O=require("./matcher.js"),k=require("./parser.js"),c=require("./constant.js");const S="next",x="prev",L="all",g="first",C="lineal",R="self";class K{#l;#r;#s;#p;#o;#b;#e;#h;#w;#n;#f;#_;#t;#d;#u;#c;#m;#i;#a;constructor(a){this.#a=a,this.#o=a.document,this.#r=new WeakMap,this.#_=new WeakMap}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#a.DOMException)if(a.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#a.DOMException(a.message,a.name);else throw a}_setup(a,e,f={}){const{event:r,noexcept:l,warn:o}=f;return this.#w=!!l,this.#i=!!o,this.#b=this._setEvent(r),this.#e=e,[this.#s,this.#t,this.#c]=(0,E.resolveContent)(e),this.#d=(0,E.isInShadowTree)(e),[this.#l,this.#h]=this._correspond(a),this.#m=new WeakMap,e}_initNwsapi(a){return this.#n=(0,$.default)({DOMException:this.#a.DOMException,document:a}),this.#n.configure({LOGERRORS:!1}),this.#n}_setEvent(a){return a instanceof this.#a.MouseEvent||a instanceof this.#a.KeyboardEvent?a:null}_correspond(a){const e=[];this.#p=!1;let f;if(this.#s){const r=this.#r.get(this.#s);if(r&&r.has(`${a}`)){const l=r.get(`${a}`);this.#p=l.descendant,f=l.ast}}if(f){const r=f.length;for(let l=0;l<r;l++)f[l].collected=!1,f[l].dir=null,f[l].filtered=!1,f[l].find=!1,e[l]=[]}else{let r;try{r=(0,k.parseSelector)(a)}catch(u){this._onError(u)}const l=(0,k.walkAST)(r);let o=!1,n=0;f=[];for(const[...u]of l){const h=[];let s=u.shift();if(s&&s.type!==c.COMBINATOR){const t=new Set;for(;s;){if(s.type===c.COMBINATOR){const[i]=u;if(i.type===c.COMBINATOR){const m=`Invalid selector ${a}`;throw new DOMException(m,c.SYNTAX_ERR)}const d=s.name;/^[\s>]$/.test(d)&&(o=!0),h.push({combo:s,leaves:(0,k.sortAST)(t)}),t.clear()}else if(s){let{name:i}=s;i&&typeof i=="string"&&(i=(0,k.unescapeSelector)(i),typeof i=="string"&&i!==s.name&&(s.name=i),/[|:]/.test(i)&&(s.namespace=!0)),t.add(s)}if(u.length)s=u.shift();else{h.push({combo:null,leaves:(0,k.sortAST)(t)}),t.clear();break}}}f.push({branch:h,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#s){let u;this.#r.has(this.#s)?u=this.#r.get(this.#s):u=new Map,u.set(`${a}`,{ast:f,descendant:o}),this.#r.set(this.#s,u)}this.#p=o}return[f,e]}_createTreeWalker(a){let e;return this.#m.has(a)?e=this.#m.get(a):(e=this.#o.createTreeWalker(a,c.WALKER_FILTER),this.#m.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#f=this._createTreeWalker(this.#e),this.#u=!1,this.#f}_traverse(a,e=this.#c){let f=e.currentNode,r;if(f===a)r=f;else if(f.contains(a))for(f=e.nextNode();f;){if(f===a){r=f;break}f=e.nextNode()}else{if(f!==e.root)for(;f&&!(f===e.root||f===a);)f=e.parentNode();if(a?.nodeType===c.ELEMENT_NODE)for(;f;){if(f===a){r=f;break}f=e.nextNode()}else r=f}return r??null}_collectNthChild(a,e,f){const{a:r,b:l,reverse:o,selector:n}=a,{parentNode:u}=e,h=new Set;let s;if(n&&(this.#r.has(n)?s=this.#r.get(n):(s=(0,k.walkAST)(n),this.#r.set(n,s))),u){const t=this.#c;let i=this._traverse(u,t);i=t.firstChild();let d=0;for(;i;)d++,i=t.nextSibling();i=this._traverse(u,t);const m=new Set;if(s)for(i=t.firstChild();i;){let b;for(const p of s)if(b=this._matchLeaves(p,i,f),!b)break;b&&m.add(i),i=t.nextSibling()}if(r===0){if(l>0&&l<=d){if(m.size){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let b=0;for(;i;){if(m.has(i)){if(b===l-1){h.add(i);break}b++}o?i=t.previousSibling():i=t.nextSibling()}}else if(!n){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let b=0;for(;i;){if(b===l-1){h.add(i);break}o?i=t.previousSibling():i=t.nextSibling(),b++}}}}else{let b=l-1;if(r>0)for(;b<0;)b+=r;if(b>=0&&b<d){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let p=0,_=r>0?0:l-1;for(;i&&(i&&b>=0&&b<d);)m.size?m.has(i)&&(_===b&&(h.add(i),b+=r),r>0?_++:_--):p===b&&(n||h.add(i),b+=r),o?i=t.previousSibling():i=t.nextSibling(),p++}}if(o&&h.size>1){const b=[...h];return new Set(b.reverse())}}else if(e===this.#t&&r+l===1)if(s){let t;for(const i of s)if(t=this._matchLeaves(i,e,f),t)break;t&&h.add(e)}else h.add(e);return h}_collectNthOfType(a,e){const{a:f,b:r,reverse:l}=a,{localName:o,parentNode:n,prefix:u}=e,h=new Set;if(n){const s=this.#c;let t=this._traverse(n,s);t=s.firstChild();let i=0;for(;t;)i++,t=s.nextSibling();if(f===0){if(r>0&&r<=i){t=this._traverse(n,s),l?t=s.lastChild():t=s.firstChild();let d=0;for(;t;){const{localName:m,prefix:b}=t;if(m===o&&b===u){if(d===r-1){h.add(t);break}d++}l?t=s.previousSibling():t=s.nextSibling()}}}else{let d=r-1;if(f>0)for(;d<0;)d+=f;if(d>=0&&d<i){t=this._traverse(n,s),l?t=s.lastChild():t=s.firstChild();let m=f>0?0:r-1;for(;t;){const{localName:b,prefix:p}=t;if(b===o&&p===u){if(m===d&&(h.add(t),d+=f),d<0||d>=i)break;f>0?m++:m--}l?t=s.previousSibling():t=s.nextSibling()}}}if(l&&h.size>1){const d=[...h];return new Set(d.reverse())}}else e===this.#t&&f+r===1&&h.add(e);return h}_matchAnPlusB(a,e,f,r){const{nth:{a:l,b:o,name:n},selector:u}=a,h=new Map;if(n?(n==="even"?(h.set("a",2),h.set("b",0)):n==="odd"&&(h.set("a",2),h.set("b",1)),f.indexOf("last")>-1&&h.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?h.set("a",l*1):h.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?h.set("b",o*1):h.set("b",0),f.indexOf("last")>-1&&h.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&h.set("selector",u);const s=Object.fromEntries(h);return this._collectNthChild(s,e,r)}else if(/^nth-(?:last-)?of-type$/.test(f)){const s=Object.fromEntries(h);return this._collectNthOfType(s,e)}return new Set}_matchHasPseudoFunc(a,e,f={}){let r;if(Array.isArray(a)&&a.length){const[l]=a,{type:o}=l;let n;o===c.COMBINATOR?n=a.shift():n={name:" ",type:c.COMBINATOR};const u=[];for(;a.length;){const[t]=a,{type:i}=t;if(i===c.COMBINATOR)break;u.push(a.shift())}const h={combo:n,leaves:u};f.dir=S;const s=this._matchCombinator(h,e,f);if(s.size)if(a.length){for(const t of s)if(r=this._matchHasPseudoFunc(Object.assign([],a),t,f),r)break}else r=!0}return!!r}_matchLogicalPseudoFunc(a,e,f={}){const{astName:r="",branches:l=[],selector:o="",twigBranches:n=[]}=a;let u;if(r==="has")if(o.includes(":has("))u=null;else{let h;for(const s of l)if(h=this._matchHasPseudoFunc(Object.assign([],s),e,f),h)break;h&&(u=e)}else{const h=/^(?:is|where)$/.test(r);f.forgive=h;const s=n.length;let t;for(let i=0;i<s;i++){const d=n[i],m=d.length-1,{leaves:b}=d[m];if(t=this._matchLeaves(b,e,f),t&&m>0){let p=new Set([e]);for(let _=m-1;_>=0;_--){const w=d[_],N=[];f.dir=x;for(const A of p){const v=this._matchCombinator(w,A,f);v.size&&N.push(...v)}if(N.length)_===0?t=!0:p=new Set(N);else{t=!1;break}}}if(t)break}r==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(a,e,f={}){const{children:r,name:l}=a,{localName:o,parentNode:n}=e,{forgive:u,warn:h=this.#i}=f,s=new Set;if(c.REG_LOGICAL_PSEUDO.test(l)){let t;if(this.#r.has(a))t=this.#r.get(a);else{const d=(0,k.walkAST)(a),m=[],b=[];for(const[...p]of d){for(const A of p){const v=(0,k.generateCSS)(A);m.push(v)}const _=[],w=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(_.push({combo:N,leaves:[...w]}),w.clear()):N&&w.add(N),p.length)N=p.shift();else{_.push({combo:null,leaves:[...w]}),w.clear();break}b.push(_)}t={astName:l,branches:d,twigBranches:b,selector:m.join(",")},this.#r.set(a,t)}const i=this._matchLogicalPseudoFunc(t,e,f);i&&s.add(i)}else if(Array.isArray(r))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const[t]=r;return this._matchAnPlusB(t,e,l,f)}else switch(l){case"dir":case"lang":{const t=O.matcher.matchSelector(a,e);t&&s.add(t);break}case"current":case"nth-col":case"nth-last-col":{if(h){const t=`Unsupported pseudo-class :${l}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!u){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,c.SYNTAX_ERR)}}else switch(l){case"any-link":case"link":{c.REG_ANCHOR.test(o)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(c.REG_ANCHOR.test(o)&&e.hasAttribute("href")){const{href:t,origin:i,pathname:d}=new URL(this.#s.URL),m=new URL(e.getAttribute("href"),t);m.origin===i&&m.pathname===d&&s.add(e)}break}case"visited":break;case"hover":{const{target:t,type:i}=this.#b??{};(i==="mouseover"||i==="pointerover")&&e.contains(t)&&s.add(e);break}case"active":{const{buttons:t,target:i,type:d}=this.#b??{};(d==="mousedown"||d==="pointerdown")&&t&c.BIT_01&&e.contains(i)&&s.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&s.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const i=t.replace(/^#/,"");let d=this.#s.getElementById(i);for(;d;){if(d===e){s.add(e);break}d=d.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#d&&e===this.#e&&s.add(e):e===this.#s.documentElement&&s.add(e);break}case"focus":case"focus-visible":{const{target:t,type:i}=this.#b??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(l==="focus"||i==="keydown"&&e.contains(t))){let d=e,m=!0;for(;d;){if(d.disabled||d.hasAttribute("disabled")||d.hidden||d.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(d);if(m=!(b==="none"||p==="hidden"),!m)break}if(d.parentNode&&d.parentNode.nodeType===c.ELEMENT_NODE)d=d.parentNode;else break}m&&s.add(e)}break}case"focus-within":{let t,i=this.#s.activeElement;if(i.tabIndex>=0)for(;i;){if(i===e){t=!0;break}i=i.parentNode}if(t){let d=e,m=!0;for(;d;){if(d.disabled||d.hasAttribute("disabled")||d.hidden||d.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(d);if(m=!(b==="none"||p==="hidden"),!m)break}if(d.parentNode&&d.parentNode.nodeType===c.ELEMENT_NODE)d=d.parentNode;else break}m&&s.add(e)}break}case"open":{c.REG_INTERACT.test(o)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{c.REG_INTERACT.test(o)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let t=n;for(;t&&t.localName!=="fieldset";)t=t.parentNode;t&&n.localName!=="legend"&&t.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.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(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.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 t;o==="textarea"?t=e:o==="input"&&(e.hasAttribute("type")?c.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&o==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))s.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let i=e.parentNode;for(;i&&i.localName!=="form";)i=i.parentNode;i||(i=this.#s.documentElement);const d=i.getElementsByTagName("input"),m=d.length;let b;for(let p=0;p<m;p++){const _=d[p];if(_.getAttribute("type")==="radio"&&(t?_.getAttribute("name")===t&&(b=!!_.checked):_.hasAttribute("name")||(b=!!_.checked),b))break}b||s.add(e)}break}case"default":{if(o==="button"&&!(e.hasAttribute("type")&&c.REG_TYPE_RESET.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const i=this.#c;let d=this._traverse(t,i);for(d=i.firstChild();d&&t.contains(d);){const m=d.localName;let b;if(m==="button"?b=!(d.hasAttribute("type")&&c.REG_TYPE_RESET.test(d.getAttribute("type"))):m==="input"&&(b=d.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(d.getAttribute("type"))),b){d===e&&s.add(e);break}d=i.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(o==="option"){let t=n,i=!1;for(;t&&t.localName!=="datalist";){if(t.localName==="select"){(t.multiple||t.hasAttribute("multiple"))&&(i=!0);break}t=t.parentNode}if(i)(e.selected||e.hasAttribute("selected"))&&s.add(e);else{const d=new Set,m=this.#c;let b=this._traverse(n,m);for(b=m.firstChild();b;){if(b.selected||b.hasAttribute("selected")){d.add(b);break}b=m.nextSibling()}d.size&&d.has(e)&&s.add(e)}}break}case"valid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()&&s.add(e);else if(o==="fieldset"){const t=this.#c;let i=this._traverse(e,t);i=t.firstChild();let d;for(;i&&e.contains(i)&&!(c.REG_FORM_VALID.test(i.localName)&&(d=i.checkValidity(),!d));)i=t.nextNode();d&&s.add(e)}break}case"invalid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()||s.add(e);else if(o==="fieldset"){const t=this.#c;let i=this._traverse(e,t);i=t.firstChild();let d;for(;i&&e.contains(i)&&!(c.REG_FORM_VALID.test(i.localName)&&(d=i.checkValidity(),!d));)i=t.nextNode();d||s.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.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":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&s.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const i=e.getAttribute("type");(i==="file"||c.REG_TYPE_CHECK.test(i)||c.REG_TYPE_DATE.test(i)||c.REG_TYPE_TEXT.test(i))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&s.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const i=e.getAttribute("type");(i==="file"||c.REG_TYPE_CHECK.test(i)||c.REG_TYPE_DATE.test(i)||c.REG_TYPE_TEXT.test(i))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&s.add(e);break}case"root":{e===this.#s.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#o.createTreeWalker(e,c.SHOW_ALL);let i=t.firstChild(),d;for(;i&&(d=i.nodeType!==c.ELEMENT_NODE&&i.nodeType!==c.TEXT_NODE,!!d);)i=t.nextSibling();d&&s.add(e)}else s.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#t)&&s.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#t)&&s.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#t)&&s.add(e);break}case"first-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1},e);t&&s.add(t)}else e===this.#t&&s.add(e);break}case"last-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&s.add(t)}else e===this.#t&&s.add(e);break}case"only-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[i]=this._collectNthOfType({a:0,b:1,reverse:!0},e);i===e&&s.add(e)}}else e===this.#t&&s.add(e);break}case"defined":{const t=e.getAttribute("is");t?(0,M.default)(t)&&this.#a.customElements.get(t)&&s.add(e):(0,M.default)(o)?this.#a.customElements.get(o)&&s.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&s.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#a.getComputedStyle(e);t!=="none"&&s.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(h){const t=`Unsupported pseudo-element ::${l}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(h){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(h){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${l}`;throw new DOMException(t,c.SYNTAX_ERR)}}return s}_matchShadowHostPseudoClass(a,e){const{children:f,name:r}=a;let l;if(Array.isArray(f)){const[o]=(0,k.walkAST)(f[0]),[...n]=o,{host:u}=e;if(r==="host"){let h;for(const s of n){const{type:t}=s;if(t===c.COMBINATOR){const d=`Invalid selector ${(0,k.generateCSS)(a)}`;throw new DOMException(d,c.SYNTAX_ERR)}if(h=this._matchSelector(s,u).has(u),!h)break}h&&(l=e)}else if(r==="host-context"){let h=u,s;for(;h;){for(const t of n){const{type:i}=t;if(i===c.COMBINATOR){const m=`Invalid selector ${(0,k.generateCSS)(a)}`;throw new DOMException(m,c.SYNTAX_ERR)}if(s=this._matchSelector(t,h).has(h),!s)break}if(s)break;h=h.parentNode}s&&(l=e)}}else if(r==="host")l=e;else{const o=`Invalid selector :${r}`;throw new DOMException(o,c.SYNTAX_ERR)}return l??null}_matchSelector(a,e,f){const{type:r}=a,l=new Set;if(a.name===c.EMPTY)return l;const o=(0,k.unescapeSelector)(a.name);if(typeof o=="string"&&o!==a.name&&(a.name=o),e.nodeType===c.ELEMENT_NODE)switch(r){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(o,f);break}case c.SELECTOR_ID:{e.id===o&&l.add(e);break}case c.SELECTOR_CLASS:{e.classList.contains(o)&&l.add(e);break}case c.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,f);default:{const n=O.matcher.matchSelector(a,e,f);n&&l.add(n)}}else if(this.#d&&r===c.SELECTOR_PSEUDO_CLASS&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&c.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(a,e,f);if(c.REG_SHADOW_HOST.test(o)){const n=this._matchShadowHostPseudoClass(a,e,f);n&&l.add(n)}}return l}_matchLeaves(a,e,f){const{attributes:r,localName:l,nodeType:o}=e;let n=this.#_.get(a),u;if(n&&n.has(e)){const{attr:h,matched:s}=n.get(e);r?.length===h&&(u=s)}if(typeof u!="boolean"){let h;o===c.ELEMENT_NODE&&c.REG_FORM.test(l)?h=!1:h=!0;for(const s of a){const{name:t,type:i}=s;if(i===c.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(h=!1),u=this._matchSelector(s,e,f).has(e),!u)break}h&&(n||(n=new WeakMap),n.set(e,{attr:r?.length,matched:u}),this.#_.set(a,n))}return!!u}_matchHTMLCollection(a,e={}){const{compound:f,filterLeaves:r}=e,l=new Set,o=a.length;if(o)if(f)for(let n=0;n<o;n++){const u=a[n];this._matchLeaves(r,u,e)&&l.add(u)}else{const n=[].slice.call(a);return new Set(n)}return l}_findDescendantNodes(a,e,f){const[r,...l]=a,o=l.length>0,{type:n}=r,u=(0,k.unescapeSelector)(r.name);typeof u=="string"&&u!==r.name&&(r.name=u);let h=new Set,s=!1;if(this.#d)s=!0;else switch(n){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,f);break}case c.SELECTOR_ID:{if(this.#t.nodeType===c.ELEMENT_NODE)s=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(o?this._matchLeaves(l,t,f)&&h.add(t):h.add(t))}break}case c.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);h=this._matchHTMLCollection(t,{compound:o,filterLeaves:l});break}case c.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);h=this._matchHTMLCollection(t,{compound:o,filterLeaves:l})}else s=!0;break}default:s=!0}return{nodes:h,pending:s}}_matchCombinator(a,e,f={}){const{combo:r,leaves:l}=a,{name:o}=r,{parentNode:n}=e,{dir:u}=f,h=new Set;if(u===S)switch(o){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(l,s,f)&&h.add(s);break}case"~":{if(n){const s=this._createTreeWalker(n);let t=this._traverse(e,s);for(t=s.nextSibling();t;)this._matchLeaves(l,t,f)&&h.add(t),t=s.nextSibling()}break}case">":{const s=this._createTreeWalker(e);let t=this._traverse(e,s);for(t=s.firstChild();t;)this._matchLeaves(l,t,f)&&h.add(t),t=s.nextSibling();break}case" ":default:{const{nodes:s,pending:t}=this._findDescendantNodes(l,e);if(s.size)return s;if(t){const i=this._createTreeWalker(e);let d=this._traverse(e,i);for(d=i.nextNode();d&&e.contains(d);)this._matchLeaves(l,d,f)&&h.add(d),d=i.nextNode()}}}else switch(o){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(l,s,f)&&h.add(s);break}case"~":{if(n){const s=this._createTreeWalker(n);let t=this._traverse(n,s);for(t=s.firstChild();t&&t!==e;)this._matchLeaves(l,t,f)&&h.add(t),t=s.nextSibling()}break}case">":{n&&this._matchLeaves(l,n,f)&&h.add(n);break}case" ":default:{const s=[];let t=n;for(;t;)this._matchLeaves(l,t,f)&&s.push(t),t=t.parentNode;if(s.length)return new Set(s.reverse())}}return h}_findNode(a,e){const{node:f}=e;let r=this._traverse(f,this.#f),l;if(r)for(r.nodeType!==c.ELEMENT_NODE?r=this.#f.nextNode():r===f&&r!==this.#t&&(r=this.#f.nextNode());r;){if(this._matchLeaves(a,r,{warn:this.#i})){l=r;break}r=this.#f.nextNode()}return l??null}_matchSelf(a){const e=[],f=this._matchLeaves(a,this.#e,{warn:this.#i});let r=!1;return f&&(e.push(this.#e),r=!0),[e,r]}_findLineal(a,e={}){const{complex:f}=e,r=[];let l=this._matchLeaves(a,this.#e,{warn:this.#i}),o=!1;if(l&&(r.push(this.#e),o=!0),!l||f){let n=this.#e.parentNode;for(;n&&(l=this._matchLeaves(a,n,{warn:this.#i}),l&&(r.push(n),o=!0),n.parentNode);)n=n.parentNode}return[r,o]}_findFirst(a){const e=[],f=this._findNode(a,{node:this.#e});let r=!1;return f&&(e.push(f),r=!0),[e,r]}_findFromHTMLCollection(a,e={}){const{complex:f,compound:r,filterLeaves:l,targetType:o}=e;let n=[],u=!1,h=!1;const s=a.length;if(s)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<s;t++){const i=a[t];if(i!==this.#e&&(this.#e.contains(i)||i.contains(this.#e))){if(r){if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else if(n.push(i),u=!0,o===g)break}}else if(f)if(r)for(let t=0;t<s;t++){const i=a[t];if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else n=[].slice.call(a),u=!0,h=!0;else if(r)for(let t=0;t<s;t++){const i=a[t];if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else n=[].slice.call(a),u=!0,h=!0;return[n,u,h]}_findEntryNodes(a,e,f){const{leaves:r}=a,[l,...o]=r,n=o.length>0,{name:u,type:h}=l;let s=[],t=!1,i=!1,d=!1;switch(h){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{warn:this.#i});break}case c.SELECTOR_ID:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:f});else if(e===g&&this.#t.nodeType!==c.ELEMENT_NODE){const m=this.#t.getElementById(u);m&&(n?this._matchLeaves(o,m,{warn:this.#i})&&(s.push(m),i=!0):(s.push(m),i=!0))}else e===g?[s,i]=this._findFirst(r):d=!0;break}case c.SELECTOR_CLASS:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:f});else if(this.#t.nodeType===c.DOCUMENT_NODE){const m=this.#t.getElementsByClassName(u);m.length&&([s,i,t]=this._findFromHTMLCollection(m,{complex:f,compound:n,filterLeaves:o,targetType:e}))}else e===g?[s,i]=this._findFirst(r):d=!0;break}case c.SELECTOR_TYPE:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:f});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#t.getElementsByTagName(u);m.length&&([s,i,t]=this._findFromHTMLCollection(m,{complex:f,compound:n,filterLeaves:o,targetType:e}))}else e===g?[s,i]=this._findFirst(r):d=!0;break}default:if(e!==C&&c.REG_SHADOW_HOST.test(u)){if(this.#d&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(l,this.#e);m&&(s.push(m),i=!0)}}else e===R?[s,i]=this._matchSelf(r):e===C?[s,i]=this._findLineal(r,{complex:f}):e===g?[s,i]=this._findFirst(r):d=!0}return{collected:t,compound:n,filtered:i,nodes:s,pending:d}}_collectNodes(a){const e=this.#l.values();if(a===L||a===g){const f=new Set;let r=0;for(const{branch:l}of e){const o=l.length,n=o>1,u=l[0];let h,s;if(n){const{combo:p,leaves:[{name:_,type:w}]}=u,N=l[o-1],{leaves:[{name:A,type:v}]}=N;if(v===c.SELECTOR_PSEUDO_ELEMENT||v===c.SELECTOR_ID)h=x,s=N;else if(w===c.SELECTOR_PSEUDO_ELEMENT||w===c.SELECTOR_ID)h=S,s=u;else if(a===L)if(_==="*"&&w===c.SELECTOR_TYPE)h=x,s=N;else if(A==="*"&&v===c.SELECTOR_TYPE)h=S,s=u;else if(o===2){const{name:T}=p;/^[+~]$/.test(T)?(h=x,s=N):(h=S,s=u)}else h=S,s=u;else if(A==="*"&&v===c.SELECTOR_TYPE)h=S,s=u;else if(_==="*"&&w===c.SELECTOR_TYPE)h=x,s=N;else{let T;for(const{combo:P,leaves:[G]}of l){const{name:z,type:F}=G;if(F===c.SELECTOR_PSEUDO_CLASS&&z==="dir"){T=!1;break}if(!T&&P){const{name:H}=P;/^[+~]$/.test(H)&&(T=!0)}}T?(h=S,s=u):(h=x,s=N)}}else h=x,s=u;const{collected:t,compound:i,filtered:d,nodes:m,pending:b}=this._findEntryNodes(s,a,n);m.length?(this.#l[r].find=!0,this.#h[r]=m):b&&f.add(new Map([["index",r],["twig",s]])),this.#l[r].collected=t,this.#l[r].dir=h,this.#l[r].filtered=d||!i,r++}if(f.size){let l,o;this.#e!==this.#t&&this.#e.nodeType===c.ELEMENT_NODE?(l=this.#e,o=this.#f):(l=this.#t,o=this.#c);let n=this._traverse(l,o);for(;n;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?n===this.#e?u=!0:u=this.#e.contains(n):u=!0,u)for(const h of f){const{leaves:s}=h.get("twig");if(this._matchLeaves(s,n,{warn:this.#i})){const i=h.get("index");this.#l[i].filtered=!0,this.#l[i].find=!0,this.#h[i].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let f=0;for(const{branch:r}of e){const l=r[r.length-1],o=r.length>1,{compound:n,filtered:u,nodes:h}=this._findEntryNodes(l,a,o);h.length&&(this.#l[f].find=!0,this.#h[f]=h),this.#l[f].dir=x,this.#l[f].filtered=u||!n,f++}}return[this.#l,this.#h]}_getCombinedNodes(a,e,f){const r=[];for(const l of e){const o=this._matchCombinator(a,l,{dir:f,warn:this.#i});o.size&&r.push(...o)}return r.length?new Set(r):new Set}_matchNodeNext(a,e,f){const{combo:r,index:l}=f,{combo:o,leaves:n}=a[l],u={combo:r,leaves:n},h=this._getCombinedNodes(u,e,S);let s;if(h.size)if(l===a.length-1){const[t]=(0,E.sortNodes)(h);s=t}else s=this._matchNodeNext(a,h,{combo:o,index:l+1});return s??null}_matchNodePrev(a,e,f){const{index:r}=f,l=a[r],o=new Set([e]),n=this._getCombinedNodes(l,o,x);let u;if(n.size){if(r===0)u=e;else for(const h of n)if(this._matchNodePrev(a,h,{index:r-1}))return e}return u??null}_find(a){(a===L||a===g)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(a),r=e.length;let l=new Set;for(let o=0;o<r;o++){const{branch:n,collected:u,dir:h,find:s}=e[o],t=n.length;if(t&&s){const i=f[o],d=i.length,m=t-1;if(m===0)if((a===L||a===g)&&this.#e.nodeType===c.ELEMENT_NODE)for(let b=0;b<d;b++){const p=i[b];if(p!==this.#e&&this.#e.contains(p)&&(l.add(p),a!==L))break}else if(a===L)if(l.size){const b=[...l];l=new Set([...b,...i]),this.#u=!0}else l=new Set(i);else{const[b]=i;l.add(b)}else if(a===L)if(h===S){let{combo:b}=n[0];for(const p of i){let _=new Set([p]);for(let w=1;w<t;w++){const{combo:N,leaves:A}=n[w],v={combo:b,leaves:A};if(_=this._getCombinedNodes(v,_,h),_.size)if(w===m)if(l.size){const T=[...l];l=new Set([...T,..._]),this.#u=!0}else l=_;else b=N;else break}}}else for(const b of i){let p=new Set([b]);for(let _=m-1;_>=0;_--){const w=n[_];if(p=this._getCombinedNodes(w,p,h),p.size)_===0&&(l.add(b),t>1&&l.size>1&&(this.#u=!0));else break}}else if(a===g&&h===S){const{combo:b}=n[0];let p;for(const _ of i)if(p=this._matchNodeNext(n,new Set([_]),{combo:b,index:1}),p){l.add(p);break}if(!p&&!u){const{leaves:_}=n[0],[w]=i;let N=this._findNode(_,{node:w});for(;N;){if(p=this._matchNodeNext(n,new Set([N]),{combo:b,index:1}),p){l.add(p);break}N=this._findNode(_,{node:N})}}}else{let b;for(const p of i)if(b=this._matchNodePrev(n,p,{index:m-1}),b){l.add(p);break}if(!b&&!u&&a===g){const{leaves:p}=n[m],[_]=i;let w=this._findNode(p,{node:_});for(;w;){if(b=this._matchNodePrev(n,w,{index:m-1}),b){l.add(w);break}w=this._findNode(p,{node:w})}}}}}return l}matches(a,e,f){let r;try{if(e?.nodeType!==c.ELEMENT_NODE){const n=`Unexpected node ${e?.nodeName}`;throw new TypeError(n)}const l=e.ownerDocument;if(l===this.#o&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_A.test(a),descendant:!0}))return this.#n||this._initNwsapi(l),this.#n.match(a,e);this._setup(a,e,f),r=this._find(R).size}catch(l){this._onError(l)}return!!r}closest(a,e,f){let r;try{if(e?.nodeType!==c.ELEMENT_NODE){const n=`Unexpected node ${e?.nodeName}`;throw new TypeError(n)}const l=e.ownerDocument;if(l===this.#o&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_A.test(a),descendant:!0}))return this.#n||this._initNwsapi(l),this.#n.closest(a,e);this._setup(a,e,f);const o=this._find(C);if(o.size){let n=this.#e;for(;n;){if(o.has(n)){r=n;break}n=n.parentNode}}}catch(l){this._onError(l)}return r??null}querySelector(a,e,f){let r;try{(0,E.verifyNode)(e);let l;if(e.nodeType===c.DOCUMENT_NODE?l=e:l=e.ownerDocument,l===this.#o&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_B.test(a),descendant:!1}))return this.#n||this._initNwsapi(l),this.#n.first(a,e);this._setup(a,e,f);const o=this._find(g);o.delete(this.#e),o.size&&([r]=(0,E.sortNodes)(o))}catch(l){this._onError(l)}return r??null}querySelectorAll(a,e,f){let r;try{(0,E.verifyNode)(e);let l;if(e.nodeType===c.DOCUMENT_NODE?l=e:l=e.ownerDocument,l===this.#o&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_B.test(a),descendant:!1}))return this.#n||this._initNwsapi(l),this.#n.select(a,e);this._setup(a,e,f);const o=this._find(L);o.delete(this.#e),o.size&&(this.#u?r=(0,E.sortNodes)(o):r=[...o])}catch(l){this._onError(l)}return r??[]}}0&&(module.exports={Finder}); | ||
var W=Object.create;var D=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(y,a)=>{for(var e in a)D(y,e,{get:a[e],enumerable:!0})},I=(y,a,e,f)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of j(a))!q.call(y,r)&&r!==e&&D(y,r,{get:()=>a[r],enumerable:!(f=B(a,r))||f.enumerable});return y};var U=(y,a,e)=>(e=y!=null?W(Y(y)):{},I(a||!y||!y.__esModule?D(e,"default",{value:y,enumerable:!0}):e,y)),X=y=>I(D({},"__esModule",{value:!0}),y);var Q={};V(Q,{Finder:()=>K});module.exports=X(Q);var M=U(require("is-potential-custom-element-name"),1),$=U(require("@asamuzakjp/nwsapi"),1),E=require("./dom-util.js"),O=require("./matcher.js"),k=require("./parser.js"),c=require("./constant.js");const S="next",x="prev",L="all",g="first",C="lineal",R="self";class K{#l;#r;#s;#p;#c;#b;#e;#h;#w;#o;#f;#_;#t;#d;#u;#n;#m;#i;#a;constructor(a,e){this.#a=a,this.#c=e??a.document,this.#r=new WeakMap,this.#_=new WeakMap,this._initNwsapi()}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#a.DOMException)if(a.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#a.DOMException(a.message,a.name);else throw a}_setup(a,e,f={}){const{event:r,noexcept:l,warn:o}=f;return this.#w=!!l,this.#i=!!o,this.#b=this._setEvent(r),this.#e=e,[this.#s,this.#t,this.#n]=(0,E.resolveContent)(e),this.#d=(0,E.isInShadowTree)(e),[this.#l,this.#h]=this._correspond(a),this.#m=new WeakMap,e}_initNwsapi(){return this.#o=(0,$.default)({DOMException:this.#a.DOMException,document:this.#c}),this.#o.configure({LOGERRORS:!1}),this.#o}_setEvent(a){return a instanceof this.#a.MouseEvent||a instanceof this.#a.KeyboardEvent?a:null}_correspond(a){const e=[];this.#p=!1;let f;if(this.#s){const r=this.#r.get(this.#s);if(r&&r.has(`${a}`)){const l=r.get(`${a}`);this.#p=l.descendant,f=l.ast}}if(f){const r=f.length;for(let l=0;l<r;l++)f[l].collected=!1,f[l].dir=null,f[l].filtered=!1,f[l].find=!1,e[l]=[]}else{let r;try{r=(0,k.parseSelector)(a)}catch(u){this._onError(u)}const l=(0,k.walkAST)(r);let o=!1,n=0;f=[];for(const[...u]of l){const h=[];let s=u.shift();if(s&&s.type!==c.COMBINATOR){const t=new Set;for(;s;){if(s.type===c.COMBINATOR){const[i]=u;if(i.type===c.COMBINATOR){const m=`Invalid selector ${a}`;throw new DOMException(m,c.SYNTAX_ERR)}const d=s.name;/^[\s>]$/.test(d)&&(o=!0),h.push({combo:s,leaves:(0,k.sortAST)(t)}),t.clear()}else if(s){let{name:i}=s;i&&typeof i=="string"&&(i=(0,k.unescapeSelector)(i),typeof i=="string"&&i!==s.name&&(s.name=i),/[|:]/.test(i)&&(s.namespace=!0)),t.add(s)}if(u.length)s=u.shift();else{h.push({combo:null,leaves:(0,k.sortAST)(t)}),t.clear();break}}}f.push({branch:h,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#s){let u;this.#r.has(this.#s)?u=this.#r.get(this.#s):u=new Map,u.set(`${a}`,{ast:f,descendant:o}),this.#r.set(this.#s,u)}this.#p=o}return[f,e]}_createTreeWalker(a){let e;return this.#m.has(a)?e=this.#m.get(a):(e=this.#c.createTreeWalker(a,c.WALKER_FILTER),this.#m.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#f=this._createTreeWalker(this.#e),this.#u=!1,this.#f}_traverse(a,e=this.#n){let f=e.currentNode,r;if(f===a)r=f;else if(f.contains(a))for(f=e.nextNode();f;){if(f===a){r=f;break}f=e.nextNode()}else{if(f!==e.root)for(;f&&!(f===e.root||f===a);)f=e.parentNode();if(a?.nodeType===c.ELEMENT_NODE)for(;f;){if(f===a){r=f;break}f=e.nextNode()}else r=f}return r??null}_collectNthChild(a,e,f){const{a:r,b:l,reverse:o,selector:n}=a,{parentNode:u}=e,h=new Set;let s;if(n&&(this.#r.has(n)?s=this.#r.get(n):(s=(0,k.walkAST)(n),this.#r.set(n,s))),u){const t=this.#n;let i=this._traverse(u,t);i=t.firstChild();let d=0;for(;i;)d++,i=t.nextSibling();i=this._traverse(u,t);const m=new Set;if(s)for(i=t.firstChild();i;){let b;for(const p of s)if(b=this._matchLeaves(p,i,f),!b)break;b&&m.add(i),i=t.nextSibling()}if(r===0){if(l>0&&l<=d){if(m.size){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let b=0;for(;i;){if(m.has(i)){if(b===l-1){h.add(i);break}b++}o?i=t.previousSibling():i=t.nextSibling()}}else if(!n){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let b=0;for(;i;){if(b===l-1){h.add(i);break}o?i=t.previousSibling():i=t.nextSibling(),b++}}}}else{let b=l-1;if(r>0)for(;b<0;)b+=r;if(b>=0&&b<d){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let p=0,_=r>0?0:l-1;for(;i&&(i&&b>=0&&b<d);)m.size?m.has(i)&&(_===b&&(h.add(i),b+=r),r>0?_++:_--):p===b&&(n||h.add(i),b+=r),o?i=t.previousSibling():i=t.nextSibling(),p++}}if(o&&h.size>1){const b=[...h];return new Set(b.reverse())}}else if(e===this.#t&&r+l===1)if(s){let t;for(const i of s)if(t=this._matchLeaves(i,e,f),t)break;t&&h.add(e)}else h.add(e);return h}_collectNthOfType(a,e){const{a:f,b:r,reverse:l}=a,{localName:o,parentNode:n,prefix:u}=e,h=new Set;if(n){const s=this.#n;let t=this._traverse(n,s);t=s.firstChild();let i=0;for(;t;)i++,t=s.nextSibling();if(f===0){if(r>0&&r<=i){t=this._traverse(n,s),l?t=s.lastChild():t=s.firstChild();let d=0;for(;t;){const{localName:m,prefix:b}=t;if(m===o&&b===u){if(d===r-1){h.add(t);break}d++}l?t=s.previousSibling():t=s.nextSibling()}}}else{let d=r-1;if(f>0)for(;d<0;)d+=f;if(d>=0&&d<i){t=this._traverse(n,s),l?t=s.lastChild():t=s.firstChild();let m=f>0?0:r-1;for(;t;){const{localName:b,prefix:p}=t;if(b===o&&p===u){if(m===d&&(h.add(t),d+=f),d<0||d>=i)break;f>0?m++:m--}l?t=s.previousSibling():t=s.nextSibling()}}}if(l&&h.size>1){const d=[...h];return new Set(d.reverse())}}else e===this.#t&&f+r===1&&h.add(e);return h}_matchAnPlusB(a,e,f,r){const{nth:{a:l,b:o,name:n},selector:u}=a,h=new Map;if(n?(n==="even"?(h.set("a",2),h.set("b",0)):n==="odd"&&(h.set("a",2),h.set("b",1)),f.indexOf("last")>-1&&h.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?h.set("a",l*1):h.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?h.set("b",o*1):h.set("b",0),f.indexOf("last")>-1&&h.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&h.set("selector",u);const s=Object.fromEntries(h);return this._collectNthChild(s,e,r)}else if(/^nth-(?:last-)?of-type$/.test(f)){const s=Object.fromEntries(h);return this._collectNthOfType(s,e)}return new Set}_matchHasPseudoFunc(a,e,f={}){let r;if(Array.isArray(a)&&a.length){const[l]=a,{type:o}=l;let n;o===c.COMBINATOR?n=a.shift():n={name:" ",type:c.COMBINATOR};const u=[];for(;a.length;){const[t]=a,{type:i}=t;if(i===c.COMBINATOR)break;u.push(a.shift())}const h={combo:n,leaves:u};f.dir=S;const s=this._matchCombinator(h,e,f);if(s.size)if(a.length){for(const t of s)if(r=this._matchHasPseudoFunc(Object.assign([],a),t,f),r)break}else r=!0}return!!r}_matchLogicalPseudoFunc(a,e,f={}){const{astName:r="",branches:l=[],selector:o="",twigBranches:n=[]}=a;let u;if(r==="has")if(o.includes(":has("))u=null;else{let h;for(const s of l)if(h=this._matchHasPseudoFunc(Object.assign([],s),e,f),h)break;h&&(u=e)}else{const h=/^(?:is|where)$/.test(r);f.forgive=h;const s=n.length;let t;for(let i=0;i<s;i++){const d=n[i],m=d.length-1,{leaves:b}=d[m];if(t=this._matchLeaves(b,e,f),t&&m>0){let p=new Set([e]);for(let _=m-1;_>=0;_--){const w=d[_],N=[];f.dir=x;for(const A of p){const v=this._matchCombinator(w,A,f);v.size&&N.push(...v)}if(N.length)_===0?t=!0:p=new Set(N);else{t=!1;break}}}if(t)break}r==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(a,e,f={}){const{children:r,name:l}=a,{localName:o,parentNode:n}=e,{forgive:u,warn:h=this.#i}=f,s=new Set;if(c.REG_LOGICAL_PSEUDO.test(l)){let t;if(this.#r.has(a))t=this.#r.get(a);else{const d=(0,k.walkAST)(a),m=[],b=[];for(const[...p]of d){for(const A of p){const v=(0,k.generateCSS)(A);m.push(v)}const _=[],w=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(_.push({combo:N,leaves:[...w]}),w.clear()):N&&w.add(N),p.length)N=p.shift();else{_.push({combo:null,leaves:[...w]}),w.clear();break}b.push(_)}t={astName:l,branches:d,twigBranches:b,selector:m.join(",")},this.#r.set(a,t)}const i=this._matchLogicalPseudoFunc(t,e,f);i&&s.add(i)}else if(Array.isArray(r))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const[t]=r;return this._matchAnPlusB(t,e,l,f)}else switch(l){case"dir":case"lang":{const t=O.matcher.matchSelector(a,e);t&&s.add(t);break}case"current":case"nth-col":case"nth-last-col":{if(h){const t=`Unsupported pseudo-class :${l}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!u){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,c.SYNTAX_ERR)}}else switch(l){case"any-link":case"link":{c.REG_ANCHOR.test(o)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(c.REG_ANCHOR.test(o)&&e.hasAttribute("href")){const{href:t,origin:i,pathname:d}=new URL(this.#s.URL),m=new URL(e.getAttribute("href"),t);m.origin===i&&m.pathname===d&&s.add(e)}break}case"visited":break;case"hover":{const{target:t,type:i}=this.#b??{};(i==="mouseover"||i==="pointerover")&&e.contains(t)&&s.add(e);break}case"active":{const{buttons:t,target:i,type:d}=this.#b??{};(d==="mousedown"||d==="pointerdown")&&t&c.BIT_01&&e.contains(i)&&s.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&s.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const i=t.replace(/^#/,"");let d=this.#s.getElementById(i);for(;d;){if(d===e){s.add(e);break}d=d.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#d&&e===this.#e&&s.add(e):e===this.#s.documentElement&&s.add(e);break}case"focus":case"focus-visible":{const{target:t,type:i}=this.#b??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(l==="focus"||i==="keydown"&&e.contains(t))){let d=e,m=!0;for(;d;){if(d.disabled||d.hasAttribute("disabled")||d.hidden||d.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(d);if(m=!(b==="none"||p==="hidden"),!m)break}if(d.parentNode&&d.parentNode.nodeType===c.ELEMENT_NODE)d=d.parentNode;else break}m&&s.add(e)}break}case"focus-within":{let t,i=this.#s.activeElement;if(i.tabIndex>=0)for(;i;){if(i===e){t=!0;break}i=i.parentNode}if(t){let d=e,m=!0;for(;d;){if(d.disabled||d.hasAttribute("disabled")||d.hidden||d.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(d);if(m=!(b==="none"||p==="hidden"),!m)break}if(d.parentNode&&d.parentNode.nodeType===c.ELEMENT_NODE)d=d.parentNode;else break}m&&s.add(e)}break}case"open":{c.REG_INTERACT.test(o)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{c.REG_INTERACT.test(o)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let t=n;for(;t&&t.localName!=="fieldset";)t=t.parentNode;t&&n.localName!=="legend"&&t.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.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(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.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 t;o==="textarea"?t=e:o==="input"&&(e.hasAttribute("type")?c.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&o==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))s.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let i=e.parentNode;for(;i&&i.localName!=="form";)i=i.parentNode;i||(i=this.#s.documentElement);const d=i.getElementsByTagName("input"),m=d.length;let b;for(let p=0;p<m;p++){const _=d[p];if(_.getAttribute("type")==="radio"&&(t?_.getAttribute("name")===t&&(b=!!_.checked):_.hasAttribute("name")||(b=!!_.checked),b))break}b||s.add(e)}break}case"default":{if(o==="button"&&!(e.hasAttribute("type")&&c.REG_TYPE_RESET.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const i=this.#n;let d=this._traverse(t,i);for(d=i.firstChild();d&&t.contains(d);){const m=d.localName;let b;if(m==="button"?b=!(d.hasAttribute("type")&&c.REG_TYPE_RESET.test(d.getAttribute("type"))):m==="input"&&(b=d.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(d.getAttribute("type"))),b){d===e&&s.add(e);break}d=i.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(o==="option"){let t=n,i=!1;for(;t&&t.localName!=="datalist";){if(t.localName==="select"){(t.multiple||t.hasAttribute("multiple"))&&(i=!0);break}t=t.parentNode}if(i)(e.selected||e.hasAttribute("selected"))&&s.add(e);else{const d=new Set,m=this.#n;let b=this._traverse(n,m);for(b=m.firstChild();b;){if(b.selected||b.hasAttribute("selected")){d.add(b);break}b=m.nextSibling()}d.size&&d.has(e)&&s.add(e)}}break}case"valid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()&&s.add(e);else if(o==="fieldset"){const t=this.#n;let i=this._traverse(e,t);i=t.firstChild();let d;for(;i&&e.contains(i)&&!(c.REG_FORM_VALID.test(i.localName)&&(d=i.checkValidity(),!d));)i=t.nextNode();d&&s.add(e)}break}case"invalid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()||s.add(e);else if(o==="fieldset"){const t=this.#n;let i=this._traverse(e,t);i=t.firstChild();let d;for(;i&&e.contains(i)&&!(c.REG_FORM_VALID.test(i.localName)&&(d=i.checkValidity(),!d));)i=t.nextNode();d||s.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.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":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&s.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const i=e.getAttribute("type");(i==="file"||c.REG_TYPE_CHECK.test(i)||c.REG_TYPE_DATE.test(i)||c.REG_TYPE_TEXT.test(i))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&s.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const i=e.getAttribute("type");(i==="file"||c.REG_TYPE_CHECK.test(i)||c.REG_TYPE_DATE.test(i)||c.REG_TYPE_TEXT.test(i))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&s.add(e);break}case"root":{e===this.#s.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#c.createTreeWalker(e,c.SHOW_ALL);let i=t.firstChild(),d;for(;i&&(d=i.nodeType!==c.ELEMENT_NODE&&i.nodeType!==c.TEXT_NODE,!!d);)i=t.nextSibling();d&&s.add(e)}else s.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#t)&&s.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#t)&&s.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#t)&&s.add(e);break}case"first-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1},e);t&&s.add(t)}else e===this.#t&&s.add(e);break}case"last-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&s.add(t)}else e===this.#t&&s.add(e);break}case"only-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[i]=this._collectNthOfType({a:0,b:1,reverse:!0},e);i===e&&s.add(e)}}else e===this.#t&&s.add(e);break}case"defined":{const t=e.getAttribute("is");t?(0,M.default)(t)&&this.#a.customElements.get(t)&&s.add(e):(0,M.default)(o)?this.#a.customElements.get(o)&&s.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&s.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#a.getComputedStyle(e);t!=="none"&&s.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(h){const t=`Unsupported pseudo-element ::${l}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(h){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(h){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${l}`;throw new DOMException(t,c.SYNTAX_ERR)}}return s}_matchShadowHostPseudoClass(a,e){const{children:f,name:r}=a;let l;if(Array.isArray(f)){const[o]=(0,k.walkAST)(f[0]),[...n]=o,{host:u}=e;if(r==="host"){let h;for(const s of n){const{type:t}=s;if(t===c.COMBINATOR){const d=`Invalid selector ${(0,k.generateCSS)(a)}`;throw new DOMException(d,c.SYNTAX_ERR)}if(h=this._matchSelector(s,u).has(u),!h)break}h&&(l=e)}else if(r==="host-context"){let h=u,s;for(;h;){for(const t of n){const{type:i}=t;if(i===c.COMBINATOR){const m=`Invalid selector ${(0,k.generateCSS)(a)}`;throw new DOMException(m,c.SYNTAX_ERR)}if(s=this._matchSelector(t,h).has(h),!s)break}if(s)break;h=h.parentNode}s&&(l=e)}}else if(r==="host")l=e;else{const o=`Invalid selector :${r}`;throw new DOMException(o,c.SYNTAX_ERR)}return l??null}_matchSelector(a,e,f){const{type:r}=a,l=new Set;if(a.name===c.EMPTY)return l;const o=(0,k.unescapeSelector)(a.name);if(typeof o=="string"&&o!==a.name&&(a.name=o),e.nodeType===c.ELEMENT_NODE)switch(r){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(o,f);break}case c.SELECTOR_ID:{e.id===o&&l.add(e);break}case c.SELECTOR_CLASS:{e.classList.contains(o)&&l.add(e);break}case c.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,f);default:{const n=O.matcher.matchSelector(a,e,f);n&&l.add(n)}}else if(this.#d&&r===c.SELECTOR_PSEUDO_CLASS&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&c.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(a,e,f);if(c.REG_SHADOW_HOST.test(o)){const n=this._matchShadowHostPseudoClass(a,e,f);n&&l.add(n)}}return l}_matchLeaves(a,e,f){const{attributes:r,localName:l,nodeType:o}=e;let n=this.#_.get(a),u;if(n&&n.has(e)){const{attr:h,matched:s}=n.get(e);r?.length===h&&(u=s)}if(typeof u!="boolean"){let h;o===c.ELEMENT_NODE&&c.REG_FORM.test(l)?h=!1:h=!0;for(const s of a){const{name:t,type:i}=s;if(i===c.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(h=!1),u=this._matchSelector(s,e,f).has(e),!u)break}h&&(n||(n=new WeakMap),n.set(e,{attr:r?.length,matched:u}),this.#_.set(a,n))}return!!u}_matchHTMLCollection(a,e={}){const{compound:f,filterLeaves:r}=e,l=new Set,o=a.length;if(o)if(f)for(let n=0;n<o;n++){const u=a[n];this._matchLeaves(r,u,e)&&l.add(u)}else{const n=[].slice.call(a);return new Set(n)}return l}_findDescendantNodes(a,e,f){const[r,...l]=a,o=l.length>0,{type:n}=r,u=(0,k.unescapeSelector)(r.name);typeof u=="string"&&u!==r.name&&(r.name=u);let h=new Set,s=!1;if(this.#d)s=!0;else switch(n){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,f);break}case c.SELECTOR_ID:{if(this.#t.nodeType===c.ELEMENT_NODE)s=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(o?this._matchLeaves(l,t,f)&&h.add(t):h.add(t))}break}case c.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);h=this._matchHTMLCollection(t,{compound:o,filterLeaves:l});break}case c.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);h=this._matchHTMLCollection(t,{compound:o,filterLeaves:l})}else s=!0;break}default:s=!0}return{nodes:h,pending:s}}_matchCombinator(a,e,f={}){const{combo:r,leaves:l}=a,{name:o}=r,{parentNode:n}=e,{dir:u}=f,h=new Set;if(u===S)switch(o){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(l,s,f)&&h.add(s);break}case"~":{if(n){const s=this._createTreeWalker(n);let t=this._traverse(e,s);for(t=s.nextSibling();t;)this._matchLeaves(l,t,f)&&h.add(t),t=s.nextSibling()}break}case">":{const s=this._createTreeWalker(e);let t=this._traverse(e,s);for(t=s.firstChild();t;)this._matchLeaves(l,t,f)&&h.add(t),t=s.nextSibling();break}case" ":default:{const{nodes:s,pending:t}=this._findDescendantNodes(l,e);if(s.size)return s;if(t){const i=this._createTreeWalker(e);let d=this._traverse(e,i);for(d=i.nextNode();d&&e.contains(d);)this._matchLeaves(l,d,f)&&h.add(d),d=i.nextNode()}}}else switch(o){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(l,s,f)&&h.add(s);break}case"~":{if(n){const s=this._createTreeWalker(n);let t=this._traverse(n,s);for(t=s.firstChild();t&&t!==e;)this._matchLeaves(l,t,f)&&h.add(t),t=s.nextSibling()}break}case">":{n&&this._matchLeaves(l,n,f)&&h.add(n);break}case" ":default:{const s=[];let t=n;for(;t;)this._matchLeaves(l,t,f)&&s.push(t),t=t.parentNode;if(s.length)return new Set(s.reverse())}}return h}_findNode(a,e){const{node:f}=e;let r=this._traverse(f,this.#f),l;if(r)for(r.nodeType!==c.ELEMENT_NODE?r=this.#f.nextNode():r===f&&r!==this.#t&&(r=this.#f.nextNode());r;){if(this._matchLeaves(a,r,{warn:this.#i})){l=r;break}r=this.#f.nextNode()}return l??null}_matchSelf(a){const e=[],f=this._matchLeaves(a,this.#e,{warn:this.#i});let r=!1;return f&&(e.push(this.#e),r=!0),[e,r]}_findLineal(a,e={}){const{complex:f}=e,r=[];let l=this._matchLeaves(a,this.#e,{warn:this.#i}),o=!1;if(l&&(r.push(this.#e),o=!0),!l||f){let n=this.#e.parentNode;for(;n&&(l=this._matchLeaves(a,n,{warn:this.#i}),l&&(r.push(n),o=!0),n.parentNode);)n=n.parentNode}return[r,o]}_findFirst(a){const e=[],f=this._findNode(a,{node:this.#e});let r=!1;return f&&(e.push(f),r=!0),[e,r]}_findFromHTMLCollection(a,e={}){const{complex:f,compound:r,filterLeaves:l,targetType:o}=e;let n=[],u=!1,h=!1;const s=a.length;if(s)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<s;t++){const i=a[t];if(i!==this.#e&&(this.#e.contains(i)||i.contains(this.#e))){if(r){if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else if(n.push(i),u=!0,o===g)break}}else if(f)if(r)for(let t=0;t<s;t++){const i=a[t];if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else n=[].slice.call(a),u=!0,h=!0;else if(r)for(let t=0;t<s;t++){const i=a[t];if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else n=[].slice.call(a),u=!0,h=!0;return[n,u,h]}_findEntryNodes(a,e,f){const{leaves:r}=a,[l,...o]=r,n=o.length>0,{name:u,type:h}=l;let s=[],t=!1,i=!1,d=!1;switch(h){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{warn:this.#i});break}case c.SELECTOR_ID:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:f});else if(e===g&&this.#t.nodeType!==c.ELEMENT_NODE){const m=this.#t.getElementById(u);m&&(n?this._matchLeaves(o,m,{warn:this.#i})&&(s.push(m),i=!0):(s.push(m),i=!0))}else e===g?[s,i]=this._findFirst(r):d=!0;break}case c.SELECTOR_CLASS:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:f});else if(this.#t.nodeType===c.DOCUMENT_NODE){const m=this.#t.getElementsByClassName(u);m.length&&([s,i,t]=this._findFromHTMLCollection(m,{complex:f,compound:n,filterLeaves:o,targetType:e}))}else e===g?[s,i]=this._findFirst(r):d=!0;break}case c.SELECTOR_TYPE:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:f});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#t.getElementsByTagName(u);m.length&&([s,i,t]=this._findFromHTMLCollection(m,{complex:f,compound:n,filterLeaves:o,targetType:e}))}else e===g?[s,i]=this._findFirst(r):d=!0;break}default:if(e!==C&&c.REG_SHADOW_HOST.test(u)){if(this.#d&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(l,this.#e);m&&(s.push(m),i=!0)}}else e===R?[s,i]=this._matchSelf(r):e===C?[s,i]=this._findLineal(r,{complex:f}):e===g?[s,i]=this._findFirst(r):d=!0}return{collected:t,compound:n,filtered:i,nodes:s,pending:d}}_collectNodes(a){const e=this.#l.values();if(a===L||a===g){const f=new Set;let r=0;for(const{branch:l}of e){const o=l.length,n=o>1,u=l[0];let h,s;if(n){const{combo:p,leaves:[{name:_,type:w}]}=u,N=l[o-1],{leaves:[{name:A,type:v}]}=N;if(v===c.SELECTOR_PSEUDO_ELEMENT||v===c.SELECTOR_ID)h=x,s=N;else if(w===c.SELECTOR_PSEUDO_ELEMENT||w===c.SELECTOR_ID)h=S,s=u;else if(a===L)if(_==="*"&&w===c.SELECTOR_TYPE)h=x,s=N;else if(A==="*"&&v===c.SELECTOR_TYPE)h=S,s=u;else if(o===2){const{name:T}=p;/^[+~]$/.test(T)?(h=x,s=N):(h=S,s=u)}else h=S,s=u;else if(A==="*"&&v===c.SELECTOR_TYPE)h=S,s=u;else if(_==="*"&&w===c.SELECTOR_TYPE)h=x,s=N;else{let T;for(const{combo:P,leaves:[G]}of l){const{name:z,type:F}=G;if(F===c.SELECTOR_PSEUDO_CLASS&&z==="dir"){T=!1;break}if(!T&&P){const{name:H}=P;/^[+~]$/.test(H)&&(T=!0)}}T?(h=S,s=u):(h=x,s=N)}}else h=x,s=u;const{collected:t,compound:i,filtered:d,nodes:m,pending:b}=this._findEntryNodes(s,a,n);m.length?(this.#l[r].find=!0,this.#h[r]=m):b&&f.add(new Map([["index",r],["twig",s]])),this.#l[r].collected=t,this.#l[r].dir=h,this.#l[r].filtered=d||!i,r++}if(f.size){let l,o;this.#e!==this.#t&&this.#e.nodeType===c.ELEMENT_NODE?(l=this.#e,o=this.#f):(l=this.#t,o=this.#n);let n=this._traverse(l,o);for(;n;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?n===this.#e?u=!0:u=this.#e.contains(n):u=!0,u)for(const h of f){const{leaves:s}=h.get("twig");if(this._matchLeaves(s,n,{warn:this.#i})){const i=h.get("index");this.#l[i].filtered=!0,this.#l[i].find=!0,this.#h[i].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let f=0;for(const{branch:r}of e){const l=r[r.length-1],o=r.length>1,{compound:n,filtered:u,nodes:h}=this._findEntryNodes(l,a,o);h.length&&(this.#l[f].find=!0,this.#h[f]=h),this.#l[f].dir=x,this.#l[f].filtered=u||!n,f++}}return[this.#l,this.#h]}_getCombinedNodes(a,e,f){const r=[];for(const l of e){const o=this._matchCombinator(a,l,{dir:f,warn:this.#i});o.size&&r.push(...o)}return r.length?new Set(r):new Set}_matchNodeNext(a,e,f){const{combo:r,index:l}=f,{combo:o,leaves:n}=a[l],u={combo:r,leaves:n},h=this._getCombinedNodes(u,e,S);let s;if(h.size)if(l===a.length-1){const[t]=(0,E.sortNodes)(h);s=t}else s=this._matchNodeNext(a,h,{combo:o,index:l+1});return s??null}_matchNodePrev(a,e,f){const{index:r}=f,l=a[r],o=new Set([e]),n=this._getCombinedNodes(l,o,x);let u;if(n.size){if(r===0)u=e;else for(const h of n)if(this._matchNodePrev(a,h,{index:r-1}))return e}return u??null}_find(a){(a===L||a===g)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(a),r=e.length;let l=new Set;for(let o=0;o<r;o++){const{branch:n,collected:u,dir:h,find:s}=e[o],t=n.length;if(t&&s){const i=f[o],d=i.length,m=t-1;if(m===0)if((a===L||a===g)&&this.#e.nodeType===c.ELEMENT_NODE)for(let b=0;b<d;b++){const p=i[b];if(p!==this.#e&&this.#e.contains(p)&&(l.add(p),a!==L))break}else if(a===L)if(l.size){const b=[...l];l=new Set([...b,...i]),this.#u=!0}else l=new Set(i);else{const[b]=i;l.add(b)}else if(a===L)if(h===S){let{combo:b}=n[0];for(const p of i){let _=new Set([p]);for(let w=1;w<t;w++){const{combo:N,leaves:A}=n[w],v={combo:b,leaves:A};if(_=this._getCombinedNodes(v,_,h),_.size)if(w===m)if(l.size){const T=[...l];l=new Set([...T,..._]),this.#u=!0}else l=_;else b=N;else break}}}else for(const b of i){let p=new Set([b]);for(let _=m-1;_>=0;_--){const w=n[_];if(p=this._getCombinedNodes(w,p,h),p.size)_===0&&(l.add(b),t>1&&l.size>1&&(this.#u=!0));else break}}else if(a===g&&h===S){const{combo:b}=n[0];let p;for(const _ of i)if(p=this._matchNodeNext(n,new Set([_]),{combo:b,index:1}),p){l.add(p);break}if(!p&&!u){const{leaves:_}=n[0],[w]=i;let N=this._findNode(_,{node:w});for(;N;){if(p=this._matchNodeNext(n,new Set([N]),{combo:b,index:1}),p){l.add(p);break}N=this._findNode(_,{node:N})}}}else{let b;for(const p of i)if(b=this._matchNodePrev(n,p,{index:m-1}),b){l.add(p);break}if(!b&&!u&&a===g){const{leaves:p}=n[m],[_]=i;let w=this._findNode(p,{node:_});for(;w;){if(b=this._matchNodePrev(n,w,{index:m-1}),b){l.add(w);break}w=this._findNode(p,{node:w})}}}}}return l}matches(a,e,f){let r;try{if(e?.nodeType!==c.ELEMENT_NODE){const n=`Unexpected node ${e?.nodeName}`;throw new TypeError(n)}const l=e.ownerDocument;if(l===this.#c&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_A.test(a),descendant:!0}))return this.#o.match(a,e);this._setup(a,e,f),r=this._find(R).size}catch(l){this._onError(l)}return!!r}closest(a,e,f){let r;try{if(e?.nodeType!==c.ELEMENT_NODE){const n=`Unexpected node ${e?.nodeName}`;throw new TypeError(n)}const l=e.ownerDocument;if(l===this.#c&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_A.test(a),descendant:!0}))return this.#o.closest(a,e);this._setup(a,e,f);const o=this._find(C);if(o.size){let n=this.#e;for(;n;){if(o.has(n)){r=n;break}n=n.parentNode}}}catch(l){this._onError(l)}return r??null}querySelector(a,e,f){let r;try{(0,E.verifyNode)(e);let l;if(e.nodeType===c.DOCUMENT_NODE?l=e:l=e.ownerDocument,l===this.#c&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_B.test(a),descendant:!1}))return this.#o.first(a,e);this._setup(a,e,f);const o=this._find(g);o.delete(this.#e),o.size&&([r]=(0,E.sortNodes)(o))}catch(l){this._onError(l)}return r??null}querySelectorAll(a,e,f){let r;try{(0,E.verifyNode)(e);let l;if(e.nodeType===c.DOCUMENT_NODE?l=e:l=e.ownerDocument,l===this.#c&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_B.test(a),descendant:!1}))return this.#o.select(a,e);this._setup(a,e,f);const o=this._find(L);o.delete(this.#e),o.size&&(this.#u?r=(0,E.sortNodes)(o):r=[...o])}catch(l){this._onError(l)}return r??[]}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -63,3 +63,3 @@ { | ||
}, | ||
"version": "4.4.3" | ||
"version": "4.4.4" | ||
} |
export class Finder { | ||
constructor(window: object); | ||
constructor(window: object, document: object); | ||
private _onError; | ||
@@ -4,0 +4,0 @@ private _setup; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
417217
4629