@asamuzakjp/dom-selector
Advanced tools
Comparing version 3.0.4 to 3.0.5
@@ -1,2 +0,2 @@ | ||
var h=Object.create;var c=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},d=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!I.call(e,o)&&o!==r&&c(e,o,{get:()=>t[o],enumerable:!(s=C(t,o))||s.enumerable});return e};var v=(e,t,r)=>(r=e!=null?h(k(e)):{},d(t||!e||!e.__esModule?c(r,"default",{value:e,enumerable:!0}):r,e)),P=e=>d(c({},"__esModule",{value:!0}),e);var A={};M(A,{getDirectionality:()=>m,getNamespaceURI:()=>w,getSlottedTextContent:()=>f,isContentEditable:()=>O,isInShadowTree:()=>D,isInclusive:()=>$,isNamespaceDeclared:()=>S,isPreceding:()=>g,prepareDOMObjects:()=>U,sortNodes:()=>R,verifyNode:()=>E});module.exports=P(A);var x=v(require("bidi-js"),1),i=require("./constant.js");const E=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===i.DOCUMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE||e.nodeType===i.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},U=e=>{e=E(e);let t,r;switch(e.nodeType){case i.DOCUMENT_NODE:{t=e,r=e;break}case i.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case i.ELEMENT_NODE:default:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;r=o;break}}return[t.defaultView,t,r]},D=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:s,mode:o,nodeType:a,parentNode:p}=r;if(s&&o&&a===i.DOCUMENT_FRAGMENT_NODE&&i.REG_SHADOW_MODE.test(o)){t=!0;break}r=p}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&D(e)){const r=e.assignedNodes();if(r.length){for(const s of r)if(t=s.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){const{dir:r,localName:s,parentNode:o}=e,{getEmbeddingLevels:a}=(0,x.default)(),p=/^(?:ltr|rtl)$/;if(p.test(r))t=r;else if(r==="auto"){let l;switch(s){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(l=e.value);break}case"slot":{l=f(e);break}case"textarea":{l=e.value;break}default:{const n=[].slice.call(e.childNodes);for(const u of n){const{dir:T,localName:N,nodeType:y,textContent:b}=u;if(y===i.TEXT_NODE?l=b.trim():y===i.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(N)&&(!T||!p.test(T))&&(N==="slot"?l=f(u):l=b.trim()),l)break}}}if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:n}=o;n===i.ELEMENT_NODE?t=m(o):(n===i.DOCUMENT_NODE||n===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(s==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(s==="input"&&e.type==="tel")t="ltr";else if(o){if(s==="slot"){const l=f(e);if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=o;l===i.ELEMENT_NODE?t=m(o):(l===i.DOCUMENT_NODE||l===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},O=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let s=e.parentNode;for(;s;){if(O(s)){t=!0;break}s=s.parentNode}}}}return!!t},w=(e,t)=>{let r;if(e&&typeof e=="string"&&t?.nodeType===i.ELEMENT_NODE){const{attributes:s}=t;for(const o of s){const{name:a,namespaceURI:p,prefix:l,value:n}=o;if(a===`xmlns:${e}`){r=n;break}else if(l===e){r=p;break}}}return r??null},S=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===i.ELEMENT_NODE){const s=t.ownerDocument.documentElement;let o=t;for(;o&&(r=w(e,o),!(r||o===s));)o=o.parentNode}return!!r},$=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_CONTAINS||s&i.DOCUMENT_POSITION_CONTAINED_BY}return!!r},g=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_PRECEDING||s&i.DOCUMENT_POSITION_CONTAINS}return!!r},R=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,s)=>{let o;return g(s,r)?o=1:o=-1,o}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,prepareDOMObjects,sortNodes,verifyNode}); | ||
var h=Object.create;var c=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},x=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!I.call(e,o)&&o!==r&&c(e,o,{get:()=>t[o],enumerable:!(s=C(t,o))||s.enumerable});return e};var U=(e,t,r)=>(r=e!=null?h(k(e)):{},x(t||!e||!e.__esModule?c(r,"default",{value:e,enumerable:!0}):r,e)),v=e=>x(c({},"__esModule",{value:!0}),e);var A={};M(A,{getDirectionality:()=>m,getNamespaceURI:()=>w,getSlottedTextContent:()=>f,isContentEditable:()=>O,isInShadowTree:()=>D,isInclusive:()=>R,isNamespaceDeclared:()=>S,isPreceding:()=>g,prepareDOMObjects:()=>P,sortNodes:()=>$,verifyNode:()=>d});module.exports=v(A);var E=U(require("bidi-js"),1),i=require("./constant.js");const d=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===i.DOCUMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE||e.nodeType===i.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},P=e=>{e=d(e);let t,r;switch(e.nodeType){case i.DOCUMENT_NODE:{t=e,r=e;break}case i.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case i.ELEMENT_NODE:default:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;r=o;break}}return[t.defaultView,t,r]},D=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:s,mode:o,nodeType:a,parentNode:p}=r;if(s&&o&&a===i.DOCUMENT_FRAGMENT_NODE&&i.REG_SHADOW_MODE.test(o)){t=!0;break}r=p}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&D(e)){const r=e.assignedNodes();if(r.length){for(const s of r)if(t=s.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){const{dir:r,localName:s,parentNode:o}=e,{getEmbeddingLevels:a}=(0,E.default)(),p=/^(?:ltr|rtl)$/;if(p.test(r))t=r;else if(r==="auto"){let l;switch(s){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(l=e.value);break}case"slot":{l=f(e);break}case"textarea":{l=e.value;break}default:{const n=[].slice.call(e.childNodes);for(const u of n){const{dir:T,localName:N,nodeType:y,textContent:b}=u;if(y===i.TEXT_NODE?l=b.trim():y===i.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(N)&&(!T||!p.test(T))&&(N==="slot"?l=f(u):l=b.trim()),l)break}}}if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:n}=o;n===i.ELEMENT_NODE?t=m(o):(n===i.DOCUMENT_NODE||n===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(s==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(s==="input"&&e.type==="tel")t="ltr";else if(o){if(s==="slot"){const l=f(e);if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=o;l===i.ELEMENT_NODE?t=m(o):(l===i.DOCUMENT_NODE||l===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},O=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let s=e.parentNode;for(;s;){if(O(s)){t=!0;break}s=s.parentNode}}}}return!!t},w=(e,t)=>{let r;if(e&&typeof e=="string"&&t?.nodeType===i.ELEMENT_NODE){const{attributes:s}=t;for(const o of s){const{name:a,namespaceURI:p,prefix:l,value:n}=o;if(a===`xmlns:${e}`){r=n;break}else if(l===e){r=p;break}}}return r??null},S=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===i.ELEMENT_NODE&&(r=t.lookupNamespaceURI(e),!r)){const s=t.ownerDocument.documentElement;let o=t;for(;o&&(r=w(e,o),!(r||o===s));)o=o.parentNode}return!!r},R=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_CONTAINS||s&i.DOCUMENT_POSITION_CONTAINED_BY}return!!r},g=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_PRECEDING||s&i.DOCUMENT_POSITION_CONTAINS}return!!r},$=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,s)=>{let o;return g(s,r)?o=1:o=-1,o}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,prepareDOMObjects,sortNodes,verifyNode}); | ||
//# sourceMappingURL=dom-util.js.map |
@@ -1,2 +0,2 @@ | ||
var j=Object.create;var U=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(T,a)=>{for(var e in a)U(T,e,{get:a[e],enumerable:!0})},I=(T,a,e,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of H(a))!G.call(T,i)&&i!==e&&U(T,i,{get:()=>a[i],enumerable:!(c=F(a,i))||c.enumerable});return T};var V=(T,a,e)=>(e=T!=null?j(B(T)):{},I(a||!T||!T.__esModule?U(e,"default",{value:T,enumerable:!0}):e,T)),X=T=>I(U({},"__esModule",{value:!0}),T);var K={};q(K,{Finder:()=>Y});module.exports=X(K);var z=V(require("is-potential-custom-element-name"),1),x=require("./dom-util.js"),R=require("./matcher.js"),v=require("./parser.js"),f=require("./constant.js");const C="next",O="prev",L="all",$="first",M="lineal",P="self",W=f.SHOW_DOCUMENT|f.SHOW_DOCUMENT_FRAGMENT|f.SHOW_ELEMENT;class Y{#a;#l;#t;#r;#e;#n;#b;#c;#s;#h;#o;#d;#i;#f;constructor(){this.#l=new WeakMap}_onError(a){if(!this.#b)if(a instanceof DOMException||this.#f&&a instanceof this.#f.DOMException)if(a.name===f.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw this.#f?new this.#f.DOMException(a.message,a.name):a;else throw a}_setup(a,e,c={}){const{noexcept:i,warn:t}=c;return this.#b=!!i,this.#i=!!t,this.#e=e,[this.#f,this.#t,this.#s]=(0,x.prepareDOMObjects)(e),this.#h=(0,x.isInShadowTree)(e),[this.#a,this.#n]=this._correspond(a),this.#c=new WeakMap,e}_correspond(a){const e=[];let c,i=this.#t&&this.#l.get(this.#t);if(i&&i.has(`${a}`)&&(c=i.get(a)),c){const t=c.length;for(let n=0;n<t;n++)c[n].dir=null,c[n].filtered=!1,c[n].find=!1,e[n]=[]}else{let t;try{t=(0,v.parseSelector)(a)}catch(h){this._onError(h)}const n=(0,v.walkAST)(t);c=[];let o=0;for(const[...h]of n){const l=[];let s=h.shift();if(s&&s.type!==f.COMBINATOR){const r=new Set;for(;s;){if(s.type===f.COMBINATOR){const[u]=h;if(u.type===f.COMBINATOR){const b=`Invalid selector ${a}`;throw new DOMException(b,f.SYNTAX_ERR)}l.push({combo:s,leaves:(0,v.sortAST)(r)}),r.clear()}else if(s){let{name:u}=s;u&&(Object.prototype.hasOwnProperty.call(u,"name")?(u=(0,v.unescapeSelector)(u.name),/[|:]/.test(u)&&(s.namespace=!0)):typeof u=="string"&&(u=(0,v.unescapeSelector)(u),/[|:]/.test(u)&&(s.namespace=!0))),r.add(s)}if(h.length)s=h.shift();else{l.push({combo:null,leaves:(0,v.sortAST)(r)}),r.clear();break}}}c.push({branch:l,dir:null,filtered:!1,find:!1}),e[o]=[],o++}this.#t&&(i||(i=new Map),i.set(`${a}`,c),this.#l.set(this.#t,i))}return[c,e]}_prepareTreeWalkers(a){return this.#d=this.#t.createTreeWalker(this.#s,W),this.#r=this.#t.createTreeWalker(a,W),this.#o=!1,[this.#d,this.#r]}_traverse(a={},e=this.#d){let c,i=e.currentNode;if(a.nodeType===f.ELEMENT_NODE&&i===a)c=i;else{if(i!==e.root)for(;i&&!(i===e.root||a.nodeType===f.ELEMENT_NODE&&i===a);)i=e.parentNode();if(a.nodeType===f.ELEMENT_NODE)for(;i;){if(i===a){c=i;break}i=e.nextNode()}else c=i}return c??null}_collectNthChild(a,e,c){const{a:i,b:t,reverse:n,selector:o}=a,{parentNode:h}=e;let l=new Set,s;if(o&&(this.#l.has(o)?s=this.#l.get(o):(s=(0,v.walkAST)(o),this.#l.set(o,s))),h){const r=this.#t.createTreeWalker(h,W);let u=0,b=r.firstChild();for(;b;)u++,b=r.nextSibling();b=this._traverse(h,r);const k=new Set;if(s)for(b=this._traverse(h,r),b=r.firstChild();b;){let p;for(const g of s)if(p=this._matchLeaves(g,b,c),!p)break;p&&k.add(b),b=r.nextSibling()}if(i===0){if(t>0&&t<=u){if(k.size){let p=0;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b;){if(k.has(b)){if(p===t-1){l.add(b);break}p++}n?b=r.previousSibling():b=r.nextSibling()}}else if(!o){let p=0;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b;){if(p===t-1){l.add(b);break}n?b=r.previousSibling():b=r.nextSibling(),p++}}}}else{let p=t-1;if(i>0)for(;p<0;)p+=i;if(p>=0&&p<u){let g=0,N=i>0?0:t-1;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b&&(b&&p>=0&&p<u);)k.size?k.has(b)&&(N===p&&(l.add(b),p+=i),i>0?N++:N--):g===p&&(o||l.add(b),p+=i),n?b=r.previousSibling():b=r.nextSibling(),g++}}if(n&&l.size>1){const p=[...l];l=new Set(p.reverse())}}else if(e===this.#s&&i+t===1)if(s){let r;for(const u of s)if(r=this._matchLeaves(u,e,c),r)break;r&&l.add(e)}else l.add(e);return l}_collectNthOfType(a,e){const{a:c,b:i,reverse:t}=a,{localName:n,parentNode:o,prefix:h}=e;let l=new Set;if(o){const s=this.#t.createTreeWalker(o,W);let r=0,u=s.firstChild();for(;u;)r++,u=s.nextSibling();if(c===0){if(i>0&&i<=r){let b=0;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:k,prefix:p}=u;if(k===n&&p===h){if(b===i-1){l.add(u);break}b++}t?u=s.previousSibling():u=s.nextSibling()}}}else{let b=i-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b<r){let k=c>0?0:i-1;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:p,prefix:g}=u;if(p===n&&g===h){if(k===b&&(l.add(u),b+=c),b<0||b>=r)break;c>0?k++:k--}t?u=s.previousSibling():u=s.nextSibling()}}}if(t&&l.size>1){const b=[...l];l=new Set(b.reverse())}}else e===this.#s&&c+i===1&&l.add(e);return l}_matchAnPlusB(a,e,c,i){const{nth:{a:t,b:n,name:o},selector:h}=a,l=(0,v.unescapeSelector)(o),s=new Map;l?(l==="even"?(s.set("a",2),s.set("b",0)):l==="odd"&&(s.set("a",2),s.set("b",1)),c.indexOf("last")>-1&&s.set("reverse",!0)):(typeof t=="string"&&/-?\d+/.test(t)?s.set("a",t*1):s.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?s.set("b",n*1):s.set("b",0),c.indexOf("last")>-1&&s.set("reverse",!0));let r=new Set;if(s.has("a")&&s.has("b")){if(/^nth-(?:last-)?child$/.test(c)){h&&s.set("selector",h);const u=Object.fromEntries(s),b=this._collectNthChild(u,e,i);b.size&&(r=b)}else if(/^nth-(?:last-)?of-type$/.test(c)){const u=Object.fromEntries(s),b=this._collectNthOfType(u,e);b.size&&(r=b)}}return r}_matchDirectionPseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name),i=(0,x.getDirectionality)(e);let t;return c===i&&(t=e),t??null}_matchLanguagePseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name);let i;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(i=e);else{let t=e.parentNode;for(;t&&t.nodeType===f.ELEMENT_NODE;){if(t.hasAttribute("lang")){t.getAttribute("lang")&&(i=e);break}t=t.parentNode}}else if(c){const t=`(?:-${f.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${f.ALPHA_NUM}${t}$`,"i").test(c)){let o;if(c.indexOf("-")>-1){const[h,l,...s]=c.split("-");let r;h==="*"?r=`${f.ALPHA_NUM}${t}`:r=`${h}${t}`;const u=`-${l}${t}`,b=s.length;let k="";if(b)for(let p=0;p<b;p++)k+=`-${s[p]}${t}`;o=new RegExp(`^${r}${u}${k}$`,"i")}else o=new RegExp(`^${c}${t}$`,"i");if(e.hasAttribute("lang"))o.test(e.getAttribute("lang"))&&(i=e);else{let h=e.parentNode;for(;h&&h.nodeType===f.ELEMENT_NODE;){if(h.hasAttribute("lang")){const l=h.getAttribute("lang");o.test(l)&&(i=e);break}h=h.parentNode}}}}return i??null}_matchHasPseudoFunc(a,e,c={}){let i;if(Array.isArray(a)&&a.length){const[t]=a,{type:n}=t;let o;n===f.COMBINATOR?o=a.shift():o={name:" ",type:f.COMBINATOR};const h=[];for(;a.length;){const[r]=a,{type:u}=r;if(u===f.COMBINATOR)break;h.push(a.shift())}const l={combo:o,leaves:h};c.dir=C;const s=this._matchCombinator(l,e,c);if(s.size)if(a.length){for(const r of s)if(i=this._matchHasPseudoFunc(Object.assign([],a),r,c),i)break}else i=!0}return!!i}_matchLogicalPseudoFunc(a,e,c={}){const{astName:i="",branches:t=[],selector:n="",twigBranches:o=[]}=a;let h;if(i==="has")if(n.includes(":has("))h=null;else{let l;for(const s of t)if(l=this._matchHasPseudoFunc(Object.assign([],s),e,c),l)break;l&&(h=e)}else{const l=/^(?:is|where)$/.test(i);c.forgive=l;const s=o.length;let r;for(let u=0;u<s;u++){const b=o[u],k=b.length-1,{leaves:p}=b[k];if(r=this._matchLeaves(p,e,c),r&&k>0){let g=new Set([e]);for(let N=k-1;N>=0;N--){const S=b[N],d=[];c.dir=O;for(const m of g){const w=this._matchCombinator(S,m,c);w.size&&d.push(...w)}if(d.length)N===0?r=!0:g=new Set(d);else{r=!1;break}}}if(r)break}i==="not"?r||(h=e):r&&(h=e)}return h??null}_matchPseudoClassSelector(a,e,c={}){const{children:i}=a,{localName:t,parentNode:n}=e,{forgive:o,warn:h=this.#i}=c,l=(0,v.unescapeSelector)(a.name);let s=new Set;if(f.REG_LOGICAL_PSEUDO.test(l)){let r;if(this.#l.has(a))r=this.#l.get(a);else{const b=(0,v.walkAST)(a),k=[],p=[];for(const[...g]of b){for(const m of g){const w=(0,v.generateCSS)(m);k.push(w)}const N=[],S=new Set;let d=g.shift();for(;d;)if(d.type===f.COMBINATOR?(N.push({combo:d,leaves:[...S]}),S.clear()):d&&S.add(d),g.length)d=g.shift();else{N.push({combo:null,leaves:[...S]}),S.clear();break}p.push(N)}r={astName:l,branches:b,twigBranches:p,selector:k.join(",")},this.#l.set(a,r)}const u=this._matchLogicalPseudoFunc(r,e,c);u&&s.add(u)}else if(Array.isArray(i)){const[r]=i;if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const u=this._matchAnPlusB(r,e,l,c);u.size&&(s=u)}else if(l==="dir"){const u=this._matchDirectionPseudoClass(r,e);u&&s.add(u)}else if(l==="lang"){const u=this._matchLanguagePseudoClass(r,e);u&&s.add(u)}else switch(l){case"current":case"nth-col":case"nth-last-col":{if(h){const u=`Unsupported pseudo-class :${l}()`;throw new DOMException(u,f.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!o){const u=`Unknown pseudo-class :${l}()`;throw new DOMException(u,f.SYNTAX_ERR)}}}else{const r=/^a(?:rea)?$/,u=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,b=/^(?:(?:inpu|selec)t|button|form|textarea)$/,k=/^d(?:etails|ialog)$/,p=/^(?:checkbox|radio)$/,g=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,S=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(l){case"any-link":case"link":{r.test(t)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(r.test(t)&&e.hasAttribute("href")){const{href:d,origin:m,pathname:w}=new URL(this.#t.URL),_=new URL(e.getAttribute("href"),d);_.origin===m&&_.pathname===w&&s.add(e)}break}case"visited":break;case"target":{const{hash:d}=new URL(this.#t.URL);e.id&&d===`#${e.id}`&&this.#t.contains(e)&&s.add(e);break}case"target-within":{const{hash:d}=new URL(this.#t.URL);if(d){const m=d.replace(/^#/,"");let w=this.#t.getElementById(m);for(;w;){if(w===e){s.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===f.ELEMENT_NODE?e===this.#e&&s.add(e):e===this.#t.documentElement&&s.add(e);break}case"focus":{if(e===this.#t.activeElement){let d=!0,m=e;for(;m;){if(m.hasAttribute("hidden")){d=!1;break}else if(m.hasAttribute("style")){const{display:w,visibility:_}=m.style;if(d=!(w==="none"||_==="hidden"),!d)break}if(m.parentNode&&m.parentNode.nodeType===f.ELEMENT_NODE)m=m.parentNode;else break}d&&s.add(e)}break}case"focus-within":{let d,m=this.#t.activeElement;for(;m;){if(m===e){d=!0;break}m=m.parentNode}if(d){let w=!0,_=e;for(;_;){if(_.hasAttribute("hidden")){w=!1;break}else if(_.hasAttribute("style")){const{display:y,visibility:E}=_.style;if(w=!(y==="none"||E==="hidden"),!w)break}if(_.parentNode&&_.parentNode.nodeType===f.ELEMENT_NODE)_=_.parentNode;else break}w&&s.add(e)}break}case"open":{k.test(t)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{k.test(t)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(u.test(t)||(0,z.default)(t))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let d=n;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&n.localName!=="legend"&&d.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(u.test(t)||(0,z.default)(t))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(t){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(t){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let d;t==="textarea"?d=e:t==="input"&&(e.hasAttribute("type")?S.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))||e.selected&&t==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&t==="input"&&e.type==="checkbox"||t==="progress"&&!e.hasAttribute("value"))s.add(e);else if(t==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let m=e.parentNode;for(;m&&m.localName!=="form";)m=m.parentNode;m||(m=this.#t.documentElement);let w;const _=m.getElementsByTagName("input"),y=_.length;if(y)for(let E=0;E<y;E++){const A=_[E];if(A.getAttribute("type")==="radio"&&(d?A.getAttribute("name")===d&&(w=!!A.checked):A.hasAttribute("name")||(w=!!A.checked),w))break}w||s.add(e)}break}case"default":{const d=/^(?:button|reset)$/,m=/^(?:image|submit)$/;if(t==="button"&&!(e.hasAttribute("type")&&d.test(e.getAttribute("type")))||t==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))){let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;if(w){const _=this.#t.createTreeWalker(w,f.SHOW_ELEMENT);let y=_.firstChild();for(;y;){const E=y.localName;let A;if(E==="button"?A=!(y.hasAttribute("type")&&d.test(y.getAttribute("type"))):E==="input"&&(A=y.hasAttribute("type")&&m.test(y.getAttribute("type"))),A){y===e&&s.add(e);break}y=_.nextNode()}}}else if(t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(t==="option"){let w=!1,_=n;for(;_&&_.localName!=="datalist";){if(_.localName==="select"){(_.multiple||_.hasAttribute("multiple"))&&(w=!0);break}_=_.parentNode}if(w)(e.selected||e.hasAttribute("selected"))&&s.add(e);else{const y=new Set,E=this.#t.createTreeWalker(n,f.SHOW_ELEMENT);let A=E.firstChild();for(;A;){if(A.selected||A.hasAttribute("selected")){y.add(A);break}A=E.nextSibling()}y.size&&y.has(e)&&s.add(e)}}break}case"valid":{if(b.test(t))e.checkValidity()&&s.add(e);else if(t==="fieldset"){let d;const m=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let w=m.firstChild();for(;w&&!(b.test(w.localName)&&(d=w.checkValidity(),!d));)w=m.nextNode();d&&s.add(e)}break}case"invalid":{if(b.test(t))e.checkValidity()||s.add(e);else if(t==="fieldset"){let d;const m=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let w=m.firstChild();for(;w&&!(b.test(w.localName)&&(d=w.checkValidity(),!d));)w=m.nextNode();d||s.add(e)}break}case"in-range":{t==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&s.add(e);break}case"out-of-range":{t==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&s.add(e);break}case"required":{let d;if(/^(?:select|textarea)$/.test(t))d=e;else if(t==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||p.test(m)||g.test(m)||S.test(m))&&(d=e)}else d=e;d&&(e.required||e.hasAttribute("required"))&&s.add(e);break}case"optional":{let d;if(/^(?:select|textarea)$/.test(t))d=e;else if(t==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||p.test(m)||g.test(m)||S.test(m))&&(d=e)}else d=e;d&&!(e.required||e.hasAttribute("required"))&&s.add(e);break}case"root":{e===this.#t.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){let d;const m=this.#t.createTreeWalker(e,f.SHOW_ALL);let w=m.firstChild();for(;w&&(d=w.nodeType!==f.ELEMENT_NODE&&w.nodeType!==f.TEXT_NODE,!!d);)w=m.nextSibling();d&&s.add(e)}else s.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&s.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&s.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&s.add(e);break}case"first-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);d&&s.add(d)}else e===this.#s&&s.add(e);break}case"last-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1,reverse:!0},e);d&&s.add(d)}else e===this.#s&&s.add(e);break}case"only-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);if(d===e){const[m]=this._collectNthOfType({a:0,b:1,reverse:!0},e);m===e&&s.add(e)}}else e===this.#s&&s.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(h){const d=`Unsupported pseudo-element ::${l}`;throw new DOMException(d,f.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"defined":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(h){const d=`Unsupported pseudo-class :${l}`;throw new DOMException(d,f.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(h){const d=`Unsupported pseudo-class :${l}`;throw new DOMException(d,f.NOT_SUPPORTED_ERR)}}else if(!o){const d=`Unknown pseudo-class :${l}`;throw new DOMException(d,f.SYNTAX_ERR)}}}return s}_matchShadowHostPseudoClass(a,e){const{children:c}=a,i=(0,v.unescapeSelector)(a.name);let t;if(Array.isArray(c)){const[n]=(0,v.walkAST)(c[0]),[...o]=n,{host:h}=e;if(i==="host"){let l;for(const s of o){const{type:r}=s;if(r===f.COMBINATOR){const b=`Invalid selector ${(0,v.generateCSS)(a)}`;throw new DOMException(b,f.SYNTAX_ERR)}if(l=this._matchSelector(s,h).has(h),!l)break}l&&(t=e)}else if(i==="host-context"){let l,s=h;for(;s;){for(const r of o){const{type:u}=r;if(u===f.COMBINATOR){const k=`Invalid selector ${(0,v.generateCSS)(a)}`;throw new DOMException(k,f.SYNTAX_ERR)}if(l=this._matchSelector(r,s).has(s),!l)break}if(l)break;s=s.parentNode}l&&(t=e)}}else if(i==="host")t=e;else{const n=`Invalid selector :${i}`;throw new DOMException(n,f.SYNTAX_ERR)}return t??null}_matchSelector(a,e,c){const{type:i}=a,t=(0,v.unescapeSelector)(a.name);let n=new Set;if(e.nodeType===f.ELEMENT_NODE)switch(i){case f.SELECTOR_CLASS:{e.classList.contains(t)&&n.add(e);break}case f.SELECTOR_ID:{t===e.id&&n.add(e);break}case f.SELECTOR_PSEUDO_CLASS:{const o=this._matchPseudoClassSelector(a,e,c);o.size&&(n=o);break}case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(t,c);break}default:{const o=(0,R.matchSelector)(a,e,c);o&&n.add(o)}}else if(this.#h&&i===f.SELECTOR_PSEUDO_CLASS&&e.nodeType===f.DOCUMENT_FRAGMENT_NODE){if(t!=="has"&&f.REG_LOGICAL_PSEUDO.test(t)){const o=this._matchPseudoClassSelector(a,e,c);o.size&&(n=o)}else if(f.REG_SHADOW_HOST.test(t)){const o=this._matchShadowHostPseudoClass(a,e,c);o&&n.add(o)}}return n}_matchLeaves(a,e,c){let i;if(this.#c.has(a)){const t=this.#c.get(a);if(t.has(e))i=t.get(e);else{for(const n of a)if(i=this._matchSelector(n,e,c).has(e),!i)break;t.set(e,i),this.#c.set(a,t)}}else{for(const n of a)if(i=this._matchSelector(n,e,c).has(e),!i)break;const t=new WeakMap;t.set(e,i),this.#c.set(a,t)}return!!i}_matchHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=new Set;const n=a.length;if(n)if(c)for(let o=0;o<n;o++){const h=a[o];this._matchLeaves(i,h,e)&&t.add(h)}else{const o=[].slice.call(a);t=new Set(o)}return t}_findDescendantNodes(a,e,c){const[i,...t]=a,{type:n}=i,o=(0,v.unescapeSelector)(i.name),h=t.length>0;let l=new Set,s=!1;if(this.#h)s=!0;else switch(n){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(o,c);break}case f.SELECTOR_ID:{if(this.#s.nodeType===f.ELEMENT_NODE)s=!0;else{const r=this.#s.getElementById(o);r&&r!==e&&e.contains(r)&&(h?this._matchLeaves(t,r,c)&&l.add(r):l.add(r))}break}case f.SELECTOR_CLASS:{const r=e.getElementsByClassName(o);l=this._matchHTMLCollection(r,{compound:h,filterLeaves:t});break}case f.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(o)){const r=e.getElementsByTagName(o);l=this._matchHTMLCollection(r,{compound:h,filterLeaves:t})}else s=!0;break}default:s=!0}return{nodes:l,pending:s}}_matchCombinator(a,e,c={}){const{combo:i,leaves:t}=a,{name:n}=i,{dir:o}=c;let h=new Set;if(o===C)switch(n){case"+":{const l=e.nextElementSibling;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case"~":{const{parentNode:l}=e;if(l){const s=this.#t.createTreeWalker(l,f.SHOW_ELEMENT);let r=this._traverse(e,s);for(r===e&&(r=s.nextSibling());r;)this._matchLeaves(t,r,c)&&h.add(r),r=s.nextSibling()}break}case">":{const l=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let s=l.firstChild();for(;s;)this._matchLeaves(t,s,c)&&h.add(s),s=l.nextSibling();break}case" ":default:{const{nodes:l,pending:s}=this._findDescendantNodes(t,e);if(l.size)h=l;else if(s){const r=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let u=r.nextNode();for(;u;)this._matchLeaves(t,u,c)&&h.add(u),u=r.nextNode()}}}else switch(n){case"+":{const l=e.previousElementSibling;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case"~":{const l=this.#t.createTreeWalker(e.parentNode,f.SHOW_ELEMENT);let s=l.firstChild();for(;s&&s!==e;)this._matchLeaves(t,s,c)&&h.add(s),s=l.nextSibling();break}case">":{const l=e.parentNode;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case" ":default:{const l=[];let s=e.parentNode;for(;s;)this._matchLeaves(t,s,c)&&l.push(s),s=s.parentNode;l.length&&(h=new Set(l.reverse()))}}return h}_findNode(a,e={}){const{node:c}=e;let i,t=this._traverse(c,this.#r);if(t)for(t.nodeType!==f.ELEMENT_NODE?t=this.#r.nextNode():t===c&&t!==this.#s&&(t=this.#r.nextNode());t;){let n;if(this.#e.nodeType===f.ELEMENT_NODE?t===this.#e?n=!0:n=this.#e.contains(t):n=!0,n&&this._matchLeaves(a,t,{warn:this.#i})){i=t;break}t=this.#r.nextNode()}return i??null}_matchSelf(a){const e=[];let c=!1;return this._matchLeaves(a,this.#e)&&(e.push(this.#e),c=!0),[e,c]}_findLineal(a,e={}){const{complex:c,compound:i,filterLeaves:t}=e,n=[];let o=!1,h=this._matchLeaves([a],this.#e);if(h&&!c&&(i?(h=this._matchLeaves(t,this.#e),h&&(n.push(this.#e),o=!0)):(n.push(this.#e),o=!0)),!h||c){h&&(n.push(this.#e),i||(o=!0));let l=this.#e.parentNode;for(;l&&(h=this._matchLeaves([a],l),h&&(n.push(l),i||(o=!0)),l.parentNode);)l=l.parentNode}return[n,o]}_findFirst(a){const e=[];let c=!1;const i=this._findNode(a,{node:this.#e});return i&&(e.push(i),c=!0),[e,c]}_findFromHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=[],n=!1;const o=a.length;if(o)if(this.#e.nodeType===f.ELEMENT_NODE)for(let h=0;h<o;h++){const l=a[h];(l===this.#e||(0,x.isInclusive)(l,this.#e))&&(c?this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),n=!0):(t.push(l),n=!0))}else if(c)for(let h=0;h<o;h++){const l=a[h];this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),n=!0)}else t=[].slice.call(a),n=!0;return[t,n]}_findEntryNodes(a,e,c){const{leaves:i}=a,[t,...n]=i,{type:o}=t,h=(0,v.unescapeSelector)(t.name),l=n.length>0;let s=[],r=!1,u=!1;switch(o){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(h,{warn:this.#i});break}case f.SELECTOR_ID:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$&&this.#s.nodeType!==f.ELEMENT_NODE){const b=this.#s.getElementById(h);b&&(l?this._matchLeaves(n,b,{warn:this.#i})&&(s.push(b),r=!0):(s.push(b),r=!0))}else u=!0;break}case f.SELECTOR_CLASS:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$)[s,r]=this._findFirst(i);else if(this.#s.nodeType===f.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(h);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}case f.SELECTOR_TYPE:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===f.DOCUMENT_NODE&&!/[*|]/.test(h)){const b=this.#s.getElementsByTagName(h);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}default:if(e!==M&&f.REG_SHADOW_HOST.test(h)){if(this.#h&&this.#e.nodeType===f.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(t,this.#e);b&&(s.push(b),r=!0)}}else e===P?[s,r]=this._matchSelf(i):e===M?[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n}):e===$?[s,r]=this._findFirst(i):u=!0}return{compound:l,filtered:r,nodes:s,pending:u}}_getEntryTwig(a,e){const c=a.length,i=c>1,t=a[0];let n,o;if(i){const{combo:h,leaves:[{name:l,type:s}]}=t,r=a[c-1],{leaves:[{name:u,type:b}]}=r;if(b===f.SELECTOR_PSEUDO_ELEMENT||b===f.SELECTOR_ID)n=O,o=r;else if(s===f.SELECTOR_PSEUDO_ELEMENT||s===f.SELECTOR_ID)n=C,o=t;else if(e===L)if(l==="*"&&s===f.SELECTOR_TYPE)n=O,o=r;else if(u==="*"&&b===f.SELECTOR_TYPE)n=C,o=t;else if(c===2){const{name:k}=h;/^[+~]$/.test(k)?(n=O,o=r):(n=C,o=t)}else n=C,o=t;else if(u==="*"&&b===f.SELECTOR_TYPE)n=C,o=t;else if(l==="*"&&s===f.SELECTOR_TYPE)n=O,o=r;else{let k,p;for(const{combo:g,leaves:[N]}of a){const{type:S}=N,d=(0,v.unescapeSelector)(N.name);if(S===f.SELECTOR_PSEUDO_CLASS&&d==="dir"){k=!1;break}if(g&&!p){const{name:m}=g;/^[+~]$/.test(m)&&(k=!0,p=!0)}}k?(n=C,o=t):(n=O,o=r)}}else n=O,o=t;return{complex:i,dir:n,twig:o}}_collectNodes(a){const e=this.#a.values();if(a===L||a===$){const c=new Set;let i=0;for(const{branch:t}of e){const{complex:n,dir:o,twig:h}=this._getEntryTwig(t,a),{compound:l,filtered:s,nodes:r,pending:u}=this._findEntryNodes(h,a,n);r.length?(this.#a[i].find=!0,this.#n[i]=r):u&&c.add(new Map([["index",i],["twig",h]])),this.#a[i].dir=o,this.#a[i].filtered=s||!l,i++}if(c.size){let t,n;this.#e!==this.#s&&this.#e.nodeType===f.ELEMENT_NODE?(t=this.#e,n=this.#r):(t=this.#s,n=this.#d);let o=this._traverse(t,n);for(;o;){let h=!1;if(this.#e.nodeType===f.ELEMENT_NODE?o===this.#e?h=!0:h=this.#e.contains(o):h=!0,h)for(const l of c){const{leaves:s}=l.get("twig");if(this._matchLeaves(s,o,{warn:this.#i})){const u=l.get("index");this.#a[u].filtered=!0,this.#a[u].find=!0,this.#n[u].push(o)}}o=n.nextNode()}}}else{let c=0;for(const{branch:i}of e){const t=i[i.length-1],n=i.length>1,{compound:o,filtered:h,nodes:l}=this._findEntryNodes(t,a,n);l.length&&(this.#a[c].find=!0,this.#n[c]=l),this.#a[c].dir=O,this.#a[c].filtered=h||!o,c++}}return[this.#a,this.#n]}_matchNodes(a){const[...e]=this.#a,c=e.length;let i=new Set;for(let t=0;t<c;t++){const{branch:n,dir:o,filtered:h,find:l}=e[t],s=n.length;if(s&&l){const r=this.#n[t],u=r.length,b=s-1;if(b===0){const{leaves:[,...k]}=n[0];if((a===L||a===$)&&this.#e.nodeType===f.ELEMENT_NODE)for(let p=0;p<u;p++){const g=r[p];if(g!==this.#e&&this.#e.contains(g)&&(i.add(g),a!==L))break}else if(k.length)for(let p=0;p<u;p++){const g=r[p];if((h||this._matchLeaves(k,g,{warn:this.#i}))&&(i.add(g),a!==L))break}else if(a===L)if(i.size){const p=[...i];i=new Set([...p,...r]),this.#o=!0}else i=new Set([...r]);else{const[p]=[...r];i.add(p)}}else if(o===C){let{combo:k,leaves:p}=n[0],g;for(let N=0;N<u;N++){const S=r[N];let d=new Set([S]);for(let m=1;m<s;m++){const{combo:w,leaves:_}=n[m],y=[];for(const E of d){const A={combo:k,leaves:_},D=this._matchCombinator(A,E,{dir:o,warn:this.#i});D.size&&y.push(...D)}if(y.length)if(m===b){if(a===L){if(i.size){const E=[...i];i=new Set([...E,...y])}else i=new Set([...y]);this.#o=!0}else{const[E]=(0,x.sortNodes)(y);i.add(E)}g=!0}else k=w,d=new Set(y),g=!1;else{g=!1;break}}if(g&&a!==L)break}if(!g&&a===$){const[N]=[...r];let S=this._findNode(p,{node:N});for(;S;){let d=new Set([S]);for(let m=1;m<s;m++){const{combo:w,leaves:_}=n[m],y=[];for(const E of d){const A={combo:k,leaves:_},D=this._matchCombinator(A,E,{dir:o,warn:this.#i});D.size&&y.push(...D)}if(y.length)if(m===b){const[E]=(0,x.sortNodes)(y);i.add(E),g=!0}else k=w,d=new Set(y),g=!1;else{g=!1;break}}if(g)break;S=this._findNode(p,{node:S}),d=new Set([S])}}}else{const{leaves:k}=n[b];let p;for(let g=0;g<u;g++){const N=r[g];let S=new Set([N]);for(let d=b-1;d>=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0,a===L&&s>1&&i.size>1&&(this.#o=!0)):(S=new Set(w),p=!1);else{p=!1;break}}if(p&&a!==L)break}if(!p&&a===$){const[g]=[...r];let N=this._findNode(k,{node:g});for(;N;){let S=new Set([N]);for(let d=b-1;d>=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0):(S=new Set(w),p=!1);else{p=!1;break}}if(p)break;N=this._findNode(k,{node:N}),S=new Set([N])}}}}}return i}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==f.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}i=this._find(P).size}catch(t){this._onError(t)}return!!i}closest(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==f.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}const t=this._find(M);if(t.size){let n=this.#e;for(;n;){if(t.has(n)){i=n;break}n=n.parentNode}}}catch(t){this._onError(t)}return i??null}querySelector(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find($);t.delete(this.#e),t.size&&([i]=(0,x.sortNodes)(t))}catch(t){this._onError(t)}return i??null}querySelectorAll(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find(L);t.delete(this.#e),t.size&&(this.#o?i=(0,x.sortNodes)(t):i=[...t])}catch(t){this._onError(t)}return i??[]}}0&&(module.exports={Finder}); | ||
var j=Object.create;var U=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(T,a)=>{for(var e in a)U(T,e,{get:a[e],enumerable:!0})},I=(T,a,e,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of H(a))!G.call(T,i)&&i!==e&&U(T,i,{get:()=>a[i],enumerable:!(c=F(a,i))||c.enumerable});return T};var V=(T,a,e)=>(e=T!=null?j(B(T)):{},I(a||!T||!T.__esModule?U(e,"default",{value:T,enumerable:!0}):e,T)),X=T=>I(U({},"__esModule",{value:!0}),T);var K={};q(K,{Finder:()=>Y});module.exports=X(K);var z=V(require("is-potential-custom-element-name"),1),x=require("./dom-util.js"),R=require("./matcher.js"),v=require("./parser.js"),f=require("./constant.js");const C="next",O="prev",L="all",$="first",M="lineal",P="self",W=f.SHOW_DOCUMENT|f.SHOW_DOCUMENT_FRAGMENT|f.SHOW_ELEMENT;class Y{#a;#l;#t;#r;#e;#n;#b;#c;#s;#h;#o;#d;#i;#f;constructor(){this.#l=new WeakMap}_onError(a){if(!this.#b)if(a instanceof DOMException||this.#f&&a instanceof this.#f.DOMException)if(a.name===f.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw this.#f?new this.#f.DOMException(a.message,a.name):a;else throw a}_setup(a,e,c={}){const{noexcept:i,warn:t}=c;return this.#b=!!i,this.#i=!!t,this.#e=e,[this.#f,this.#t,this.#s]=(0,x.prepareDOMObjects)(e),this.#h=(0,x.isInShadowTree)(e),[this.#a,this.#n]=this._correspond(a),this.#c=new WeakMap,e}_correspond(a){const e=[];let c,i=this.#t&&this.#l.get(this.#t);if(i&&i.has(`${a}`)&&(c=i.get(a)),c){const t=c.length;for(let n=0;n<t;n++)c[n].dir=null,c[n].filtered=!1,c[n].find=!1,e[n]=[]}else{let t;try{t=(0,v.parseSelector)(a)}catch(h){this._onError(h)}const n=(0,v.walkAST)(t);c=[];let o=0;for(const[...h]of n){const l=[];let s=h.shift();if(s&&s.type!==f.COMBINATOR){const r=new Set;for(;s;){if(s.type===f.COMBINATOR){const[u]=h;if(u.type===f.COMBINATOR){const b=`Invalid selector ${a}`;throw new DOMException(b,f.SYNTAX_ERR)}l.push({combo:s,leaves:(0,v.sortAST)(r)}),r.clear()}else if(s){let{name:u}=s;u&&(Object.prototype.hasOwnProperty.call(u,"name")?(u=(0,v.unescapeSelector)(u.name),/[|:]/.test(u)&&(s.namespace=!0)):typeof u=="string"&&(u=(0,v.unescapeSelector)(u),/[|:]/.test(u)&&(s.namespace=!0))),r.add(s)}if(h.length)s=h.shift();else{l.push({combo:null,leaves:(0,v.sortAST)(r)}),r.clear();break}}}c.push({branch:l,dir:null,filtered:!1,find:!1}),e[o]=[],o++}this.#t&&(i||(i=new Map),i.set(`${a}`,c),this.#l.set(this.#t,i))}return[c,e]}_prepareTreeWalkers(a){return this.#d=this.#t.createTreeWalker(this.#s,W),this.#r=this.#t.createTreeWalker(a,W),this.#o=!1,[this.#d,this.#r]}_traverse(a={},e=this.#d){let c,i=e.currentNode;if(a.nodeType===f.ELEMENT_NODE&&i===a)c=i;else{if(i!==e.root)for(;i&&!(i===e.root||a.nodeType===f.ELEMENT_NODE&&i===a);)i=e.parentNode();if(a.nodeType===f.ELEMENT_NODE)for(;i;){if(i===a){c=i;break}i=e.nextNode()}else c=i}return c??null}_collectNthChild(a,e,c){const{a:i,b:t,reverse:n,selector:o}=a,{parentNode:h}=e;let l=new Set,s;if(o&&(this.#l.has(o)?s=this.#l.get(o):(s=(0,v.walkAST)(o),this.#l.set(o,s))),h){const r=this.#t.createTreeWalker(h,W);let u=0,b=r.firstChild();for(;b;)u++,b=r.nextSibling();b=this._traverse(h,r);const k=new Set;if(s)for(b=this._traverse(h,r),b=r.firstChild();b;){let p;for(const g of s)if(p=this._matchLeaves(g,b,c),!p)break;p&&k.add(b),b=r.nextSibling()}if(i===0){if(t>0&&t<=u){if(k.size){let p=0;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b;){if(k.has(b)){if(p===t-1){l.add(b);break}p++}n?b=r.previousSibling():b=r.nextSibling()}}else if(!o){let p=0;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b;){if(p===t-1){l.add(b);break}n?b=r.previousSibling():b=r.nextSibling(),p++}}}}else{let p=t-1;if(i>0)for(;p<0;)p+=i;if(p>=0&&p<u){let g=0,N=i>0?0:t-1;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b&&(b&&p>=0&&p<u);)k.size?k.has(b)&&(N===p&&(l.add(b),p+=i),i>0?N++:N--):g===p&&(o||l.add(b),p+=i),n?b=r.previousSibling():b=r.nextSibling(),g++}}if(n&&l.size>1){const p=[...l];l=new Set(p.reverse())}}else if(e===this.#s&&i+t===1)if(s){let r;for(const u of s)if(r=this._matchLeaves(u,e,c),r)break;r&&l.add(e)}else l.add(e);return l}_collectNthOfType(a,e){const{a:c,b:i,reverse:t}=a,{localName:n,parentNode:o,prefix:h}=e;let l=new Set;if(o){const s=this.#t.createTreeWalker(o,W);let r=0,u=s.firstChild();for(;u;)r++,u=s.nextSibling();if(c===0){if(i>0&&i<=r){let b=0;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:k,prefix:p}=u;if(k===n&&p===h){if(b===i-1){l.add(u);break}b++}t?u=s.previousSibling():u=s.nextSibling()}}}else{let b=i-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b<r){let k=c>0?0:i-1;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:p,prefix:g}=u;if(p===n&&g===h){if(k===b&&(l.add(u),b+=c),b<0||b>=r)break;c>0?k++:k--}t?u=s.previousSibling():u=s.nextSibling()}}}if(t&&l.size>1){const b=[...l];l=new Set(b.reverse())}}else e===this.#s&&c+i===1&&l.add(e);return l}_matchAnPlusB(a,e,c,i){const{nth:{a:t,b:n,name:o},selector:h}=a,l=(0,v.unescapeSelector)(o),s=new Map;l?(l==="even"?(s.set("a",2),s.set("b",0)):l==="odd"&&(s.set("a",2),s.set("b",1)),c.indexOf("last")>-1&&s.set("reverse",!0)):(typeof t=="string"&&/-?\d+/.test(t)?s.set("a",t*1):s.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?s.set("b",n*1):s.set("b",0),c.indexOf("last")>-1&&s.set("reverse",!0));let r=new Set;if(s.has("a")&&s.has("b")){if(/^nth-(?:last-)?child$/.test(c)){h&&s.set("selector",h);const u=Object.fromEntries(s),b=this._collectNthChild(u,e,i);b.size&&(r=b)}else if(/^nth-(?:last-)?of-type$/.test(c)){const u=Object.fromEntries(s),b=this._collectNthOfType(u,e);b.size&&(r=b)}}return r}_matchDirectionPseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name),i=(0,x.getDirectionality)(e);let t;return c===i&&(t=e),t??null}_matchLanguagePseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name);let i;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(i=e);else{let t=e.parentNode;for(;t&&t.nodeType===f.ELEMENT_NODE;){if(t.hasAttribute("lang")){t.getAttribute("lang")&&(i=e);break}t=t.parentNode}}else if(c){const t=`(?:-${f.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${f.ALPHA_NUM}${t}$`,"i").test(c)){let o;if(c.indexOf("-")>-1){const[h,l,...s]=c.split("-");let r;h==="*"?r=`${f.ALPHA_NUM}${t}`:r=`${h}${t}`;const u=`-${l}${t}`,b=s.length;let k="";if(b)for(let p=0;p<b;p++)k+=`-${s[p]}${t}`;o=new RegExp(`^${r}${u}${k}$`,"i")}else o=new RegExp(`^${c}${t}$`,"i");if(e.hasAttribute("lang"))o.test(e.getAttribute("lang"))&&(i=e);else{let h=e.parentNode;for(;h&&h.nodeType===f.ELEMENT_NODE;){if(h.hasAttribute("lang")){const l=h.getAttribute("lang");o.test(l)&&(i=e);break}h=h.parentNode}}}}return i??null}_matchHasPseudoFunc(a,e,c={}){let i;if(Array.isArray(a)&&a.length){const[t]=a,{type:n}=t;let o;n===f.COMBINATOR?o=a.shift():o={name:" ",type:f.COMBINATOR};const h=[];for(;a.length;){const[r]=a,{type:u}=r;if(u===f.COMBINATOR)break;h.push(a.shift())}const l={combo:o,leaves:h};c.dir=C;const s=this._matchCombinator(l,e,c);if(s.size)if(a.length){for(const r of s)if(i=this._matchHasPseudoFunc(Object.assign([],a),r,c),i)break}else i=!0}return!!i}_matchLogicalPseudoFunc(a,e,c={}){const{astName:i="",branches:t=[],selector:n="",twigBranches:o=[]}=a;let h;if(i==="has")if(n.includes(":has("))h=null;else{let l;for(const s of t)if(l=this._matchHasPseudoFunc(Object.assign([],s),e,c),l)break;l&&(h=e)}else{const l=/^(?:is|where)$/.test(i);c.forgive=l;const s=o.length;let r;for(let u=0;u<s;u++){const b=o[u],k=b.length-1,{leaves:p}=b[k];if(r=this._matchLeaves(p,e,c),r&&k>0){let g=new Set([e]);for(let N=k-1;N>=0;N--){const S=b[N],d=[];c.dir=O;for(const m of g){const w=this._matchCombinator(S,m,c);w.size&&d.push(...w)}if(d.length)N===0?r=!0:g=new Set(d);else{r=!1;break}}}if(r)break}i==="not"?r||(h=e):r&&(h=e)}return h??null}_matchPseudoClassSelector(a,e,c={}){const{children:i}=a,{localName:t,parentNode:n}=e,{forgive:o,warn:h=this.#i}=c,l=(0,v.unescapeSelector)(a.name);let s=new Set;if(f.REG_LOGICAL_PSEUDO.test(l)){let r;if(this.#l.has(a))r=this.#l.get(a);else{const b=(0,v.walkAST)(a),k=[],p=[];for(const[...g]of b){for(const m of g){const w=(0,v.generateCSS)(m);k.push(w)}const N=[],S=new Set;let d=g.shift();for(;d;)if(d.type===f.COMBINATOR?(N.push({combo:d,leaves:[...S]}),S.clear()):d&&S.add(d),g.length)d=g.shift();else{N.push({combo:null,leaves:[...S]}),S.clear();break}p.push(N)}r={astName:l,branches:b,twigBranches:p,selector:k.join(",")},this.#l.set(a,r)}const u=this._matchLogicalPseudoFunc(r,e,c);u&&s.add(u)}else if(Array.isArray(i)){const[r]=i;if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const u=this._matchAnPlusB(r,e,l,c);u.size&&(s=u)}else if(l==="dir"){const u=this._matchDirectionPseudoClass(r,e);u&&s.add(u)}else if(l==="lang"){const u=this._matchLanguagePseudoClass(r,e);u&&s.add(u)}else switch(l){case"current":case"nth-col":case"nth-last-col":{if(h){const u=`Unsupported pseudo-class :${l}()`;throw new DOMException(u,f.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!o){const u=`Unknown pseudo-class :${l}()`;throw new DOMException(u,f.SYNTAX_ERR)}}}else{const r=/^a(?:rea)?$/,u=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,b=/^(?:(?:inpu|selec)t|button|form|textarea)$/,k=/^d(?:etails|ialog)$/,p=/^(?:checkbox|radio)$/,g=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,S=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(l){case"any-link":case"link":{r.test(t)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(r.test(t)&&e.hasAttribute("href")){const{href:d,origin:m,pathname:w}=new URL(this.#t.URL),_=new URL(e.getAttribute("href"),d);_.origin===m&&_.pathname===w&&s.add(e)}break}case"visited":break;case"target":{const{hash:d}=new URL(this.#t.URL);e.id&&d===`#${e.id}`&&this.#t.contains(e)&&s.add(e);break}case"target-within":{const{hash:d}=new URL(this.#t.URL);if(d){const m=d.replace(/^#/,"");let w=this.#t.getElementById(m);for(;w;){if(w===e){s.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===f.ELEMENT_NODE?e===this.#e&&s.add(e):e===this.#t.documentElement&&s.add(e);break}case"focus":{if(e===this.#t.activeElement){let d=!0,m=e;for(;m;){if(m.hasAttribute("hidden")){d=!1;break}else if(m.hasAttribute("style")){const{display:w,visibility:_}=m.style;if(d=!(w==="none"||_==="hidden"),!d)break}if(m.parentNode&&m.parentNode.nodeType===f.ELEMENT_NODE)m=m.parentNode;else break}d&&s.add(e)}break}case"focus-within":{let d,m=this.#t.activeElement;for(;m;){if(m===e){d=!0;break}m=m.parentNode}if(d){let w=!0,_=e;for(;_;){if(_.hasAttribute("hidden")){w=!1;break}else if(_.hasAttribute("style")){const{display:y,visibility:E}=_.style;if(w=!(y==="none"||E==="hidden"),!w)break}if(_.parentNode&&_.parentNode.nodeType===f.ELEMENT_NODE)_=_.parentNode;else break}w&&s.add(e)}break}case"open":{k.test(t)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{k.test(t)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(u.test(t)||(0,z.default)(t))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let d=n;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&n.localName!=="legend"&&d.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(u.test(t)||(0,z.default)(t))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(t){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(t){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let d;t==="textarea"?d=e:t==="input"&&(e.hasAttribute("type")?S.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))||e.selected&&t==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&t==="input"&&e.type==="checkbox"||t==="progress"&&!e.hasAttribute("value"))s.add(e);else if(t==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let m=e.parentNode;for(;m&&m.localName!=="form";)m=m.parentNode;m||(m=this.#t.documentElement);let w;const _=m.getElementsByTagName("input"),y=_.length;if(y)for(let E=0;E<y;E++){const A=_[E];if(A.getAttribute("type")==="radio"&&(d?A.getAttribute("name")===d&&(w=!!A.checked):A.hasAttribute("name")||(w=!!A.checked),w))break}w||s.add(e)}break}case"default":{const d=/^(?:button|reset)$/,m=/^(?:image|submit)$/;if(t==="button"&&!(e.hasAttribute("type")&&d.test(e.getAttribute("type")))||t==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))){let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;if(w){const _=this.#t.createTreeWalker(w,f.SHOW_ELEMENT);let y=_.firstChild();for(;y;){const E=y.localName;let A;if(E==="button"?A=!(y.hasAttribute("type")&&d.test(y.getAttribute("type"))):E==="input"&&(A=y.hasAttribute("type")&&m.test(y.getAttribute("type"))),A){y===e&&s.add(e);break}y=_.nextNode()}}}else if(t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(t==="option"){let w=!1,_=n;for(;_&&_.localName!=="datalist";){if(_.localName==="select"){(_.multiple||_.hasAttribute("multiple"))&&(w=!0);break}_=_.parentNode}if(w)(e.selected||e.hasAttribute("selected"))&&s.add(e);else{const y=new Set,E=this.#t.createTreeWalker(n,f.SHOW_ELEMENT);let A=E.firstChild();for(;A;){if(A.selected||A.hasAttribute("selected")){y.add(A);break}A=E.nextSibling()}y.size&&y.has(e)&&s.add(e)}}break}case"valid":{if(b.test(t))e.checkValidity()&&s.add(e);else if(t==="fieldset"){let d;const m=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let w=m.firstChild();for(;w&&!(b.test(w.localName)&&(d=w.checkValidity(),!d));)w=m.nextNode();d&&s.add(e)}break}case"invalid":{if(b.test(t))e.checkValidity()||s.add(e);else if(t==="fieldset"){let d;const m=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let w=m.firstChild();for(;w&&!(b.test(w.localName)&&(d=w.checkValidity(),!d));)w=m.nextNode();d||s.add(e)}break}case"in-range":{t==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&s.add(e);break}case"out-of-range":{t==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&s.add(e);break}case"required":{let d;if(/^(?:select|textarea)$/.test(t))d=e;else if(t==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||p.test(m)||g.test(m)||S.test(m))&&(d=e)}else d=e;d&&(e.required||e.hasAttribute("required"))&&s.add(e);break}case"optional":{let d;if(/^(?:select|textarea)$/.test(t))d=e;else if(t==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||p.test(m)||g.test(m)||S.test(m))&&(d=e)}else d=e;d&&!(e.required||e.hasAttribute("required"))&&s.add(e);break}case"root":{e===this.#t.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){let d;const m=this.#t.createTreeWalker(e,f.SHOW_ALL);let w=m.firstChild();for(;w&&(d=w.nodeType!==f.ELEMENT_NODE&&w.nodeType!==f.TEXT_NODE,!!d);)w=m.nextSibling();d&&s.add(e)}else s.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&s.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&s.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&s.add(e);break}case"first-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);d&&s.add(d)}else e===this.#s&&s.add(e);break}case"last-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1,reverse:!0},e);d&&s.add(d)}else e===this.#s&&s.add(e);break}case"only-of-type":{if(n){const[d]=this._collectNthOfType({a:0,b:1},e);if(d===e){const[m]=this._collectNthOfType({a:0,b:1,reverse:!0},e);m===e&&s.add(e)}}else e===this.#s&&s.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(h){const d=`Unsupported pseudo-element ::${l}`;throw new DOMException(d,f.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"defined":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(h){const d=`Unsupported pseudo-class :${l}`;throw new DOMException(d,f.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(h){const d=`Unsupported pseudo-class :${l}`;throw new DOMException(d,f.NOT_SUPPORTED_ERR)}}else if(!o){const d=`Unknown pseudo-class :${l}`;throw new DOMException(d,f.SYNTAX_ERR)}}}return s}_matchShadowHostPseudoClass(a,e){const{children:c}=a,i=(0,v.unescapeSelector)(a.name);let t;if(Array.isArray(c)){const[n]=(0,v.walkAST)(c[0]),[...o]=n,{host:h}=e;if(i==="host"){let l;for(const s of o){const{type:r}=s;if(r===f.COMBINATOR){const b=`Invalid selector ${(0,v.generateCSS)(a)}`;throw new DOMException(b,f.SYNTAX_ERR)}if(l=this._matchSelector(s,h).has(h),!l)break}l&&(t=e)}else if(i==="host-context"){let l,s=h;for(;s;){for(const r of o){const{type:u}=r;if(u===f.COMBINATOR){const k=`Invalid selector ${(0,v.generateCSS)(a)}`;throw new DOMException(k,f.SYNTAX_ERR)}if(l=this._matchSelector(r,s).has(s),!l)break}if(l)break;s=s.parentNode}l&&(t=e)}}else if(i==="host")t=e;else{const n=`Invalid selector :${i}`;throw new DOMException(n,f.SYNTAX_ERR)}return t??null}_matchSelector(a,e,c){const{type:i}=a,t=(0,v.unescapeSelector)(a.name);let n=new Set;if(e.nodeType===f.ELEMENT_NODE)switch(i){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(t,c);break}case f.SELECTOR_ID:{e.id===t&&n.add(e);break}case f.SELECTOR_CLASS:{e.classList.contains(t)&&n.add(e);break}case f.SELECTOR_PSEUDO_CLASS:{const o=this._matchPseudoClassSelector(a,e,c);o.size&&(n=o);break}default:{const o=(0,R.matchSelector)(a,e,c);o&&n.add(o)}}else if(this.#h&&i===f.SELECTOR_PSEUDO_CLASS&&e.nodeType===f.DOCUMENT_FRAGMENT_NODE){if(t!=="has"&&f.REG_LOGICAL_PSEUDO.test(t)){const o=this._matchPseudoClassSelector(a,e,c);o.size&&(n=o)}else if(f.REG_SHADOW_HOST.test(t)){const o=this._matchShadowHostPseudoClass(a,e,c);o&&n.add(o)}}return n}_matchLeaves(a,e,c){let i;if(this.#c.has(a)){const t=this.#c.get(a);if(t.has(e))i=t.get(e);else{for(const n of a)if(i=this._matchSelector(n,e,c).has(e),!i)break;t.set(e,i),this.#c.set(a,t)}}else{for(const n of a)if(i=this._matchSelector(n,e,c).has(e),!i)break;const t=new WeakMap;t.set(e,i),this.#c.set(a,t)}return!!i}_matchHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=new Set;const n=a.length;if(n)if(c)for(let o=0;o<n;o++){const h=a[o];this._matchLeaves(i,h,e)&&t.add(h)}else{const o=[].slice.call(a);t=new Set(o)}return t}_findDescendantNodes(a,e,c){const[i,...t]=a,{type:n}=i,o=(0,v.unescapeSelector)(i.name),h=t.length>0;let l=new Set,s=!1;if(this.#h)s=!0;else switch(n){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(o,c);break}case f.SELECTOR_ID:{if(this.#s.nodeType===f.ELEMENT_NODE)s=!0;else{const r=this.#s.getElementById(o);r&&r!==e&&e.contains(r)&&(h?this._matchLeaves(t,r,c)&&l.add(r):l.add(r))}break}case f.SELECTOR_CLASS:{const r=e.getElementsByClassName(o);l=this._matchHTMLCollection(r,{compound:h,filterLeaves:t});break}case f.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(o)){const r=e.getElementsByTagName(o);l=this._matchHTMLCollection(r,{compound:h,filterLeaves:t})}else s=!0;break}default:s=!0}return{nodes:l,pending:s}}_matchCombinator(a,e,c={}){const{combo:i,leaves:t}=a,{name:n}=i,{dir:o}=c;let h=new Set;if(o===C)switch(n){case"+":{const l=e.nextElementSibling;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case"~":{const{parentNode:l}=e;if(l){const s=this.#t.createTreeWalker(l,f.SHOW_ELEMENT);let r=this._traverse(e,s);for(r===e&&(r=s.nextSibling());r;)this._matchLeaves(t,r,c)&&h.add(r),r=s.nextSibling()}break}case">":{const l=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let s=l.firstChild();for(;s;)this._matchLeaves(t,s,c)&&h.add(s),s=l.nextSibling();break}case" ":default:{const{nodes:l,pending:s}=this._findDescendantNodes(t,e);if(l.size)h=l;else if(s){const r=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let u=r.nextNode();for(;u;)this._matchLeaves(t,u,c)&&h.add(u),u=r.nextNode()}}}else switch(n){case"+":{const l=e.previousElementSibling;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case"~":{const l=this.#t.createTreeWalker(e.parentNode,f.SHOW_ELEMENT);let s=l.firstChild();for(;s&&s!==e;)this._matchLeaves(t,s,c)&&h.add(s),s=l.nextSibling();break}case">":{const l=e.parentNode;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case" ":default:{const l=[];let s=e.parentNode;for(;s;)this._matchLeaves(t,s,c)&&l.push(s),s=s.parentNode;l.length&&(h=new Set(l.reverse()))}}return h}_findNode(a,e={}){const{node:c}=e;let i,t=this._traverse(c,this.#r);if(t)for(t.nodeType!==f.ELEMENT_NODE?t=this.#r.nextNode():t===c&&t!==this.#s&&(t=this.#r.nextNode());t;){let n;if(this.#e.nodeType===f.ELEMENT_NODE?t===this.#e?n=!0:n=this.#e.contains(t):n=!0,n&&this._matchLeaves(a,t,{warn:this.#i})){i=t;break}t=this.#r.nextNode()}return i??null}_matchSelf(a){const e=[];let c=!1;return this._matchLeaves(a,this.#e)&&(e.push(this.#e),c=!0),[e,c]}_findLineal(a,e={}){const{complex:c,compound:i,filterLeaves:t}=e,n=[];let o=!1,h=this._matchLeaves([a],this.#e);if(h&&!c&&(i?(h=this._matchLeaves(t,this.#e),h&&(n.push(this.#e),o=!0)):(n.push(this.#e),o=!0)),!h||c){h&&(n.push(this.#e),i||(o=!0));let l=this.#e.parentNode;for(;l&&(h=this._matchLeaves([a],l),h&&(n.push(l),i||(o=!0)),l.parentNode);)l=l.parentNode}return[n,o]}_findFirst(a){const e=[];let c=!1;const i=this._findNode(a,{node:this.#e});return i&&(e.push(i),c=!0),[e,c]}_findFromHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=[],n=!1;const o=a.length;if(o)if(this.#e.nodeType===f.ELEMENT_NODE)for(let h=0;h<o;h++){const l=a[h];(l===this.#e||(0,x.isInclusive)(l,this.#e))&&(c?this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),n=!0):(t.push(l),n=!0))}else if(c)for(let h=0;h<o;h++){const l=a[h];this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),n=!0)}else t=[].slice.call(a),n=!0;return[t,n]}_findEntryNodes(a,e,c){const{leaves:i}=a,[t,...n]=i,{type:o}=t,h=(0,v.unescapeSelector)(t.name),l=n.length>0;let s=[],r=!1,u=!1;switch(o){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(h,{warn:this.#i});break}case f.SELECTOR_ID:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$&&this.#s.nodeType!==f.ELEMENT_NODE){const b=this.#s.getElementById(h);b&&(l?this._matchLeaves(n,b,{warn:this.#i})&&(s.push(b),r=!0):(s.push(b),r=!0))}else u=!0;break}case f.SELECTOR_CLASS:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$)[s,r]=this._findFirst(i);else if(this.#s.nodeType===f.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(h);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}case f.SELECTOR_TYPE:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===f.DOCUMENT_NODE&&!/[*|]/.test(h)){const b=this.#s.getElementsByTagName(h);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}default:if(e!==M&&f.REG_SHADOW_HOST.test(h)){if(this.#h&&this.#e.nodeType===f.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(t,this.#e);b&&(s.push(b),r=!0)}}else e===P?[s,r]=this._matchSelf(i):e===M?[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n}):e===$?[s,r]=this._findFirst(i):u=!0}return{compound:l,filtered:r,nodes:s,pending:u}}_getEntryTwig(a,e){const c=a.length,i=c>1,t=a[0];let n,o;if(i){const{combo:h,leaves:[{name:l,type:s}]}=t,r=a[c-1],{leaves:[{name:u,type:b}]}=r;if(b===f.SELECTOR_PSEUDO_ELEMENT||b===f.SELECTOR_ID)n=O,o=r;else if(s===f.SELECTOR_PSEUDO_ELEMENT||s===f.SELECTOR_ID)n=C,o=t;else if(e===L)if(l==="*"&&s===f.SELECTOR_TYPE)n=O,o=r;else if(u==="*"&&b===f.SELECTOR_TYPE)n=C,o=t;else if(c===2){const{name:k}=h;/^[+~]$/.test(k)?(n=O,o=r):(n=C,o=t)}else n=C,o=t;else if(u==="*"&&b===f.SELECTOR_TYPE)n=C,o=t;else if(l==="*"&&s===f.SELECTOR_TYPE)n=O,o=r;else{let k,p;for(const{combo:g,leaves:[N]}of a){const{type:S}=N,d=(0,v.unescapeSelector)(N.name);if(S===f.SELECTOR_PSEUDO_CLASS&&d==="dir"){k=!1;break}if(g&&!p){const{name:m}=g;/^[+~]$/.test(m)&&(k=!0,p=!0)}}k?(n=C,o=t):(n=O,o=r)}}else n=O,o=t;return{complex:i,dir:n,twig:o}}_collectNodes(a){const e=this.#a.values();if(a===L||a===$){const c=new Set;let i=0;for(const{branch:t}of e){const{complex:n,dir:o,twig:h}=this._getEntryTwig(t,a),{compound:l,filtered:s,nodes:r,pending:u}=this._findEntryNodes(h,a,n);r.length?(this.#a[i].find=!0,this.#n[i]=r):u&&c.add(new Map([["index",i],["twig",h]])),this.#a[i].dir=o,this.#a[i].filtered=s||!l,i++}if(c.size){let t,n;this.#e!==this.#s&&this.#e.nodeType===f.ELEMENT_NODE?(t=this.#e,n=this.#r):(t=this.#s,n=this.#d);let o=this._traverse(t,n);for(;o;){let h=!1;if(this.#e.nodeType===f.ELEMENT_NODE?o===this.#e?h=!0:h=this.#e.contains(o):h=!0,h)for(const l of c){const{leaves:s}=l.get("twig");if(this._matchLeaves(s,o,{warn:this.#i})){const u=l.get("index");this.#a[u].filtered=!0,this.#a[u].find=!0,this.#n[u].push(o)}}o=n.nextNode()}}}else{let c=0;for(const{branch:i}of e){const t=i[i.length-1],n=i.length>1,{compound:o,filtered:h,nodes:l}=this._findEntryNodes(t,a,n);l.length&&(this.#a[c].find=!0,this.#n[c]=l),this.#a[c].dir=O,this.#a[c].filtered=h||!o,c++}}return[this.#a,this.#n]}_matchNodes(a){const[...e]=this.#a,c=e.length;let i=new Set;for(let t=0;t<c;t++){const{branch:n,dir:o,filtered:h,find:l}=e[t],s=n.length;if(s&&l){const r=this.#n[t],u=r.length,b=s-1;if(b===0){const{leaves:[,...k]}=n[0];if((a===L||a===$)&&this.#e.nodeType===f.ELEMENT_NODE)for(let p=0;p<u;p++){const g=r[p];if(g!==this.#e&&this.#e.contains(g)&&(i.add(g),a!==L))break}else if(k.length)for(let p=0;p<u;p++){const g=r[p];if((h||this._matchLeaves(k,g,{warn:this.#i}))&&(i.add(g),a!==L))break}else if(a===L)if(i.size){const p=[...i];i=new Set([...p,...r]),this.#o=!0}else i=new Set([...r]);else{const[p]=[...r];i.add(p)}}else if(o===C){let{combo:k,leaves:p}=n[0],g;for(let N=0;N<u;N++){const S=r[N];let d=new Set([S]);for(let m=1;m<s;m++){const{combo:w,leaves:_}=n[m],y=[];for(const E of d){const A={combo:k,leaves:_},D=this._matchCombinator(A,E,{dir:o,warn:this.#i});D.size&&y.push(...D)}if(y.length)if(m===b){if(a===L){if(i.size){const E=[...i];i=new Set([...E,...y])}else i=new Set([...y]);this.#o=!0}else{const[E]=(0,x.sortNodes)(y);i.add(E)}g=!0}else k=w,d=new Set(y),g=!1;else{g=!1;break}}if(g&&a!==L)break}if(!g&&a===$){const[N]=[...r];let S=this._findNode(p,{node:N});for(;S;){let d=new Set([S]);for(let m=1;m<s;m++){const{combo:w,leaves:_}=n[m],y=[];for(const E of d){const A={combo:k,leaves:_},D=this._matchCombinator(A,E,{dir:o,warn:this.#i});D.size&&y.push(...D)}if(y.length)if(m===b){const[E]=(0,x.sortNodes)(y);i.add(E),g=!0}else k=w,d=new Set(y),g=!1;else{g=!1;break}}if(g)break;S=this._findNode(p,{node:S}),d=new Set([S])}}}else{const{leaves:k}=n[b];let p;for(let g=0;g<u;g++){const N=r[g];let S=new Set([N]);for(let d=b-1;d>=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0,a===L&&s>1&&i.size>1&&(this.#o=!0)):(S=new Set(w),p=!1);else{p=!1;break}}if(p&&a!==L)break}if(!p&&a===$){const[g]=[...r];let N=this._findNode(k,{node:g});for(;N;){let S=new Set([N]);for(let d=b-1;d>=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0):(S=new Set(w),p=!1);else{p=!1;break}}if(p)break;N=this._findNode(k,{node:N}),S=new Set([N])}}}}}return i}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==f.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}i=this._find(P).size}catch(t){this._onError(t)}return!!i}closest(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==f.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}const t=this._find(M);if(t.size){let n=this.#e;for(;n;){if(t.has(n)){i=n;break}n=n.parentNode}}}catch(t){this._onError(t)}return i??null}querySelector(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find($);t.delete(this.#e),t.size&&([i]=(0,x.sortNodes)(t))}catch(t){this._onError(t)}return i??null}querySelectorAll(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find(L);t.delete(this.#e),t.size&&(this.#o?i=(0,x.sortNodes)(t):i=[...t])}catch(t){this._onError(t)}return i??[]}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -1,2 +0,2 @@ | ||
var y=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var f in e)y(t,f,{get:e[f],enumerable:!0})},v=(t,e,f,m)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of L(e))!S.call(t,o)&&o!==f&&y(t,o,{get:()=>e[o],enumerable:!(m=$(e,o))||m.enumerable});return t};var C=t=>v(y({},"__esModule",{value:!0}),t);var U={};D(U,{_matchAttributeSelector:()=>k,_matchTypeSelector:()=>O,matchPseudoElementSelector:()=>P,matchSelector:()=>N});module.exports=C(U);var T=require("./dom-util.js"),h=require("./parser.js"),i=require("./constant.js");const k=(t,e)=>{const{flags:f,matcher:m,name:o,value:w}=t;if(typeof f=="string"&&!/^[is]$/i.test(f)){const r=`Invalid selector ${(0,h.generateCSS)(t)}`;throw new DOMException(r,i.SYNTAX_ERR)}const{attributes:x}=e;let d;if(x&&x.length){const g=e.ownerDocument.contentType;let r;g==="text/html"?typeof f=="string"&&/^s$/i.test(f)?r=!1:r=!0:typeof f=="string"&&/^i$/i.test(f)?r=!0:r=!1;let u=(0,h.unescapeSelector)(o.name);r&&(u=u.toLowerCase());const n=new Set;if(u.indexOf("|")>-1){const{prefix:l,localName:p}=(0,h.parseAstName)(u);for(const s of x){let{name:a,value:c}=s;switch(r&&(a=a.toLowerCase(),c=c.toLowerCase()),l){case"":{p===a&&n.add(c);break}case"*":{a.indexOf(":")>-1?a.endsWith(`:${p}`)&&n.add(c):p===a&&n.add(c);break}default:if(a.indexOf(":")>-1){const[b,E]=a.split(":");if(b==="xml"&&E==="lang")continue;l===b&&p===E&&(0,T.isNamespaceDeclared)(l,e)&&n.add(c)}}}}else for(let{name:l,value:p}of x)if(r&&(l=l.toLowerCase(),p=p.toLowerCase()),l.indexOf(":")>-1){const[s,a]=l.split(":");if(s==="xml"&&a==="lang")continue;u===a&&n.add(p)}else u===l&&n.add(p);if(n.size){const{name:l,value:p}=w??{};let s;switch(l?r?s=l.toLowerCase():s=l:p?r?s=p.toLowerCase():s=p:p===""&&(s=p),m){case"=":{typeof s=="string"&&n.has(s)&&(d=e);break}case"~=":{if(s&&typeof s=="string"){for(const a of n)if(new Set(a.split(/\s+/)).has(s)){d=e;break}}break}case"|=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c===s||c.startsWith(`${s}-`)){a=c;break}a&&(d=e)}break}case"^=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.startsWith(`${s}`)){a=c;break}a&&(d=e)}break}case"$=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.endsWith(`${s}`)){a=c;break}a&&(d=e)}break}case"*=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.includes(`${s}`)){a=c;break}a&&(d=e)}break}case null:default:d=e}}}return d??null},O=(t,e,f={})=>{const m=(0,h.unescapeSelector)(t.name),{localName:o,namespaceURI:w,prefix:x}=e,{forgive:d}=f;let{prefix:g,localName:r}=(0,h.parseAstName)(m,e);e.ownerDocument.contentType==="text/html"&&(g=g.toLowerCase(),r=r.toLowerCase());let u,n;o.indexOf(":")>-1?[u,n]=o.split(":"):(u=x||"",n=o);let l;switch(g){case"":{u===""&&w===null&&(r==="*"||r===n)&&(l=e);break}case"*":{(r==="*"||r===n)&&(l=e);break}default:if((0,T.isNamespaceDeclared)(g,e))g===u&&(r==="*"||r===n)&&(l=e);else if(!d){const s=`Undeclared namespace ${g}`;throw new DOMException(s,i.SYNTAX_ERR)}}return l??null},N=(t,e,f)=>{if(!t||!t.type){const w=`Unexpected node ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}else if(!e||!e.nodeType){const w=`Unexpected node ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}else if(e.nodeType!==i.ELEMENT_NODE){const o=`Unexpected node ${e.nodeName}`;throw new TypeError(o)}let m;switch(t.type){case i.SELECTOR_ATTR:{m=k(t,e);break}case i.SELECTOR_TYPE:default:m=O(t,e,f)}return m},P=(t,e={})=>{if(!t||typeof t!="string"){const w=`Unexpected type ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}const{forgive:f,warn:m}=e;switch(t){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(m){const o=`Unsupported pseudo-element ::${t}`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(m){const o=`Unsupported pseudo-element ::${t}()`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}break}default:if(t.startsWith("-webkit-")){if(m){const o=`Unsupported pseudo-element ::${t}`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}}else if(!f){const o=`Unknown pseudo-element ::${t}`;throw new DOMException(o,i.SYNTAX_ERR)}}};0&&(module.exports={_matchAttributeSelector,_matchTypeSelector,matchPseudoElementSelector,matchSelector}); | ||
var y=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var f in e)y(t,f,{get:e[f],enumerable:!0})},v=(t,e,f,m)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of L(e))!S.call(t,o)&&o!==f&&y(t,o,{get:()=>e[o],enumerable:!(m=$(e,o))||m.enumerable});return t};var C=t=>v(y({},"__esModule",{value:!0}),t);var U={};D(U,{_matchAttributeSelector:()=>k,_matchTypeSelector:()=>O,matchPseudoElementSelector:()=>P,matchSelector:()=>N});module.exports=C(U);var T=require("./dom-util.js"),h=require("./parser.js"),i=require("./constant.js");const k=(t,e)=>{const{flags:f,matcher:m,name:o,value:w}=t;if(typeof f=="string"&&!/^[is]$/i.test(f)){const r=`Invalid selector ${(0,h.generateCSS)(t)}`;throw new DOMException(r,i.SYNTAX_ERR)}const{attributes:x}=e;let d;if(x&&x.length){const g=e.ownerDocument.contentType;let r;g==="text/html"?typeof f=="string"&&/^s$/i.test(f)?r=!1:r=!0:typeof f=="string"&&/^i$/i.test(f)?r=!0:r=!1;let u=(0,h.unescapeSelector)(o.name);r&&(u=u.toLowerCase());const n=new Set;if(u.indexOf("|")>-1){const{prefix:l,localName:p}=(0,h.parseAstName)(u);for(const s of x){let{name:a,value:c}=s;switch(r&&(a=a.toLowerCase(),c=c.toLowerCase()),l){case"":{p===a&&n.add(c);break}case"*":{a.indexOf(":")>-1?a.endsWith(`:${p}`)&&n.add(c):p===a&&n.add(c);break}default:if(a.indexOf(":")>-1){const[b,E]=a.split(":");if(b==="xml"&&E==="lang")continue;l===b&&p===E&&(0,T.isNamespaceDeclared)(l,e)&&n.add(c)}}}}else for(let{name:l,value:p}of x)if(r&&(l=l.toLowerCase(),p=p.toLowerCase()),l.indexOf(":")>-1){const[s,a]=l.split(":");if(s==="xml"&&a==="lang")continue;u===a&&n.add(p)}else u===l&&n.add(p);if(n.size){const{name:l,value:p}=w??{};let s;switch(l?r?s=l.toLowerCase():s=l:p?r?s=p.toLowerCase():s=p:p===""&&(s=p),m){case"=":{typeof s=="string"&&n.has(s)&&(d=e);break}case"~=":{if(s&&typeof s=="string"){for(const a of n)if(new Set(a.split(/\s+/)).has(s)){d=e;break}}break}case"|=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c===s||c.startsWith(`${s}-`)){a=c;break}a&&(d=e)}break}case"^=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.startsWith(`${s}`)){a=c;break}a&&(d=e)}break}case"$=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.endsWith(`${s}`)){a=c;break}a&&(d=e)}break}case"*=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.includes(`${s}`)){a=c;break}a&&(d=e)}break}case null:default:d=e}}}return d??null},O=(t,e,f={})=>{const m=(0,h.unescapeSelector)(t.name),{localName:o,namespaceURI:w,prefix:x}=e,{forgive:d}=f;let{prefix:g,localName:r}=(0,h.parseAstName)(m,e);e.ownerDocument.contentType==="text/html"&&(g=g.toLowerCase(),r=r.toLowerCase());let u,n;o.indexOf(":")>-1?[u,n]=o.split(":"):(u=x||"",n=o);let l;switch(g){case"":{!u&&!w&&(r==="*"||r===n)&&(l=e);break}case"*":{(r==="*"||r===n)&&(l=e);break}default:if(g===u){if((0,T.isNamespaceDeclared)(g,e))(r==="*"||r===n)&&(l=e);else if(!d){const s=`Undeclared namespace ${g}`;throw new DOMException(s,i.SYNTAX_ERR)}}}return l??null},N=(t,e,f)=>{if(!t||!t.type){const w=`Unexpected node ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}else if(!e||!e.nodeType){const w=`Unexpected node ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}else if(e.nodeType!==i.ELEMENT_NODE){const o=`Unexpected node ${e.nodeName}`;throw new TypeError(o)}let m;switch(t.type){case i.SELECTOR_ATTR:{m=k(t,e);break}case i.SELECTOR_TYPE:default:m=O(t,e,f)}return m},P=(t,e={})=>{if(!t||typeof t!="string"){const w=`Unexpected type ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}const{forgive:f,warn:m}=e;switch(t){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(m){const o=`Unsupported pseudo-element ::${t}`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(m){const o=`Unsupported pseudo-element ::${t}()`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}break}default:if(t.startsWith("-webkit-")){if(m){const o=`Unsupported pseudo-element ::${t}`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}}else if(!f){const o=`Unknown pseudo-element ::${t}`;throw new DOMException(o,i.SYNTAX_ERR)}}};0&&(module.exports={_matchAttributeSelector,_matchTypeSelector,matchPseudoElementSelector,matchSelector}); | ||
//# sourceMappingURL=matcher.js.map |
@@ -35,3 +35,3 @@ { | ||
"chai": "^5.0.3", | ||
"commander": "^11.1.0", | ||
"commander": "^12.0.0", | ||
"esbuild": "^0.20.0", | ||
@@ -63,3 +63,3 @@ "eslint": "^8.56.0", | ||
}, | ||
"version": "3.0.4" | ||
"version": "3.0.5" | ||
} |
@@ -310,10 +310,13 @@ /** | ||
if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) { | ||
const root = node.ownerDocument.documentElement; | ||
let parent = node; | ||
while (parent) { | ||
res = getNamespaceURI(ns, parent); | ||
if (res || parent === root) { | ||
break; | ||
res = node.lookupNamespaceURI(ns); | ||
if (!res) { | ||
const root = node.ownerDocument.documentElement; | ||
let parent = node; | ||
while (parent) { | ||
res = getNamespaceURI(ns, parent); | ||
if (res || parent === root) { | ||
break; | ||
} | ||
parent = parent.parentNode; | ||
} | ||
parent = parent.parentNode; | ||
} | ||
@@ -320,0 +323,0 @@ } |
@@ -258,3 +258,3 @@ /** | ||
case '': { | ||
if (nodePrefix === '' && namespaceURI === null && | ||
if (!nodePrefix && !namespaceURI && | ||
(astLocalName === '*' || astLocalName === nodeLocalName)) { | ||
@@ -272,11 +272,12 @@ res = node; | ||
default: { | ||
const namespaceDeclared = isNamespaceDeclared(astPrefix, node); | ||
if (namespaceDeclared) { | ||
if (astPrefix === nodePrefix && | ||
(astLocalName === '*' || astLocalName === nodeLocalName)) { | ||
res = node; | ||
if (astPrefix === nodePrefix) { | ||
const namespaceDeclared = isNamespaceDeclared(astPrefix, node); | ||
if (namespaceDeclared) { | ||
if (astLocalName === '*' || astLocalName === nodeLocalName) { | ||
res = node; | ||
} | ||
} else if (!forgive) { | ||
const msg = `Undeclared namespace ${astPrefix}`; | ||
throw new DOMException(msg, SYNTAX_ERR); | ||
} | ||
} else if (!forgive) { | ||
const msg = `Undeclared namespace ${astPrefix}`; | ||
throw new DOMException(msg, SYNTAX_ERR); | ||
} | ||
@@ -283,0 +284,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
373539
4342