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