@asamuzakjp/dom-selector 1.1.9 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var F=Object.create;var P=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var W=(S,s)=>{for(var e in s)P(S,e,{get:s[e],enumerable:!0})},z=(S,s,e,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of j(s))!G.call(S,h)&&h!==e&&P(S,h,{get:()=>s[h],enumerable:!(n=V(s,h))||n.enumerable});return S};var q=(S,s,e)=>(e=S!=null?F(H(S)):{},z(s||!S||!S.__esModule?P(e,"default",{value:S,enumerable:!0}):e,S)),X=S=>z(P({},"__esModule",{value:!0}),S);var J={};W(J,{Matcher:()=>Y});module.exports=X(J);var B=q(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),y=require("./parser.js"),r=require("./constant.js");const R="next",M="prev",U="all",C="first",D="lineal",I="self";class Y{#i;#r;#a;#e;#l;#t;#o;#s;constructor(s,e,n={}){const{warn:h}=n;this.#r=new Map([[r.SELECTOR_PSEUDO_ELEMENT,r.BIT_01],[r.SELECTOR_ID,r.BIT_02],[r.SELECTOR_CLASS,r.BIT_04],[r.SELECTOR_TYPE,r.BIT_08],[r.SELECTOR_ATTR,r.BIT_16],[r.SELECTOR_PSEUDO_CLASS,r.BIT_32]]),this.#a=new WeakMap,this.#o=s,this.#e=e,this.#s=!!h,[this.#i,this.#l]=this._prepare(s),this.#t=this._getRoot(e)}_onError(s){if(s instanceof DOMException&&s.name===r.NOT_SUPPORTED_ERR)this.#s&&console.warn(s.message);else throw s}_getRoot(s=this.#e){let e,n;switch(s.nodeType){case r.DOCUMENT_NODE:{e=s,n=s;break}case r.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,n=s;break}case r.ELEMENT_NODE:{if((0,E.isSameOrDescendant)(s))e=s.ownerDocument,n=s.ownerDocument;else{let a=s;for(;a&&a.parentNode;)a=a.parentNode;e=a.ownerDocument,n=a}break}default:throw new TypeError(`Unexpected node ${s.nodeName}`)}const h=(0,E.isInShadowTree)(s);return{document:e,root:n,shadow:h}}_sortLeaves(s){const e=[...s];return e.length>1&&e.sort((n,h)=>{const{type:a}=n,{type:u}=h,m=this.#r.get(a),c=this.#r.get(u);let t;return m===c?t=0:m>c?t=1:t=-1,t}),e}_prepare(s=this.#o){const e=(0,y.parseSelector)(s),n=(0,y.walkAST)(e),h=[],a=[];let u=0;for(const[...m]of n){const c=[];let t=m.shift();if(t&&t.type!==r.COMBINATOR){const i=new Set;for(;t;){if(t.type===r.COMBINATOR){const[o]=m;if(o.type===r.COMBINATOR){const b=`Invalid combinator ${t.name}${o.name}`;throw new DOMException(b,r.SYNTAX_ERR)}c.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(m.length)t=m.shift();else{c.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}h.push({branch:c,find:null,skip:!1}),a[u]=new Set,u++}return[h,a]}_collectNthChild(s,e){const{a:n,b:h,reverse:a,selector:u}=s,{parentNode:m}=e,c=new Set;let t;if(u&&(this.#a.has(u)?t=this.#a.get(u):(t=(0,y.walkAST)(u),this.#a.set(u,t))),m){const i=[].slice.call(m.children),o=i.length;if(o){const b=new Set;if(t){const l=t.length;for(const f of i){let d;for(let p=0;p<l;p++){const N=t[p];if(d=this._matchLeaves(N,f),!d)break}d&&b.add(f)}}if(a&&i.reverse(),n===0){if(h>0&&h<=o){if(b.size)for(let l=0;l<o;l++){const f=i[l];if(b.has(f)){c.add(f);break}}else if(!u){const l=i[h-1];c.add(l)}}}else{let l=h-1;if(n>0)for(;l<0;)l+=n;if(l>=0&&l<o){let f=n>0?0:h-1;for(let d=0;d<o&&l>=0&&l<o;d++){const p=i[d];b.size?b.has(p)&&(f===l&&(c.add(p),l+=n),n>0?f++:f--):d===l&&(u||c.add(p),l+=n)}}}}}else{const{root:i}=this.#t;if(e===i&&i.nodeType===r.ELEMENT_NODE&&n+h===1)if(t){const o=t.length;let b;for(let l=0;l<o;l++){const f=t[l];if(b=this._matchLeaves(f,e),b)break}b&&c.add(e)}else c.add(e)}return c}_collectNthOfType(s,e){const{a:n,b:h,reverse:a}=s,{localName:u,parentNode:m,prefix:c}=e,t=new Set;if(m){const i=[].slice.call(m.children),o=i.length;if(o)if(a&&i.reverse(),n===0){if(h>0&&h<=o){let b=0;for(let l=0;l<o;l++){const f=i[l],{localName:d,prefix:p}=f;if(d===u&&p===c){if(b===h-1){t.add(f);break}b++}}}}else{let b=h-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<o){let l=n>0?0:h-1;for(let f=0;f<o;f++){const d=i[f],{localName:p,prefix:N}=d;if(p===u&&N===c){if(l===b&&(t.add(d),b+=n),b<0||b>=o)break;n>0?l++:l--}}}}}else{const{root:i}=this.#t;e===i&&i.nodeType===r.ELEMENT_NODE&&n+h===1&&t.add(e)}return t}_matchAnPlusB(s,e,n){const{nth:{a:h,b:a,name:u},selector:m}=s,c=(0,y.unescapeSelector)(u),t=new Map;c?(c==="even"?(t.set("a",2),t.set("b",0)):c==="odd"&&(t.set("a",2),t.set("b",1)),n.indexOf("last")>-1&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof a=="string"&&/-?\d+/.test(a)?t.set("b",a*1):t.set("b",0),n.indexOf("last")>-1&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(n)){m&&t.set("selector",m);const o=Object.fromEntries(t),b=this._collectNthChild(o,e);b.size&&(i=b)}else if(/^nth-(?:last-)?of-type$/.test(n)){const o=Object.fromEntries(t),b=this._collectNthOfType(o,e);b.size&&(i=b)}}return i}_matchPseudoElementSelector(s,e={}){const{forgive:n}=e;switch(s){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,r.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}()`,r.NOT_SUPPORTED_ERR);break}default:if(s.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,r.NOT_SUPPORTED_ERR)}else if(!n)throw new DOMException(`Unknown pseudo-element ::${s}`,r.SYNTAX_ERR)}}_matchDirectionPseudoClass(s,e){const n=(0,y.unescapeSelector)(s.name),h=(0,E.getDirectionality)(e);let a;return n===h&&(a=e),a??null}_matchLanguagePseudoClass(s,e){const n=(0,y.unescapeSelector)(s.name);let h;if(n)if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let a=e.parentNode;for(;a;){if(a.hasAttribute("lang")){a.getAttribute("lang")&&(h=e);break}a=a.parentNode}}else{const a=`(?:-${r.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${r.ALPHA_NUM}${a}$`,"i").test(n)){let m;if(n.indexOf("-")>-1){const[c,t,...i]=n.split("-");let o;c==="*"?o=`${r.ALPHA_NUM}${a}`:o=`${c}${a}`;const b=`-${t}${a}`,l=i.length;let f="";if(l)for(let d=0;d<l;d++)f+=`-${i[d]}${a}`;m=new RegExp(`^${o}${b}${f}$`,"i")}else m=new RegExp(`^${n}${a}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(h=e);else{let c=e.parentNode;for(;c;){if(c.hasAttribute("lang")){const t=c.getAttribute("lang");m.test(t)&&(h=e);break}c=c.parentNode}}}}return h??null}_matchHasPseudoFunc(s,e){let n;if(Array.isArray(s)&&s.length){const[h]=s,{type:a}=h;let u;a===r.COMBINATOR?u=s.shift():u={name:" ",type:r.COMBINATOR};const m=[];for(;s.length;){const[i]=s,{type:o}=i;if(o===r.COMBINATOR)break;m.push(s.shift())}const c={combo:u,leaves:m},t=this._matchCombinator(c,e,{find:R});if(t.size)if(s.length){for(const i of t)if(n=this._matchHasPseudoFunc(Object.assign([],s),i),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(s,e){const{astName:n="",branches:h=[],selector:a="",twigBranches:u=[]}=s;let m;if(n==="has")if(a.includes(":has("))m=null;else{const c=h.length;let t;for(let i=0;i<c;i++){const o=h[i];if(t=this._matchHasPseudoFunc(Object.assign([],o),e),t)break}t&&(m=e)}else{const c=/^(?:is|where)$/.test(n),t=u.length;let i;for(let o=0;o<t;o++){const b=u[o],l=b.length-1,{leaves:f}=b[l];if(i=this._matchLeaves(f,e,{forgive:c}),i&&l>0){let d=new Set([e]);for(let p=l-1;p>=0;p--){const N=b[p],k=[];for(const x of d){const L=this._matchCombinator(N,x,{forgive:c,find:M});L.size&&k.push(...L)}if(k.length)if(p===0){i=!0;break}else d=new Set(k);else{i=!1;break}}}if(i)break}n==="not"?i||(m=e):i&&(m=e)}return m??null}_matchPseudoClassSelector(s,e,n={}){const{children:h}=s,{localName:a,parentNode:u}=e,{forgive:m}=n,c=(0,y.unescapeSelector)(s.name);let t=new Set;if(r.REG_LOGICAL_PSEUDO.test(c)){let i;if(this.#a.has(s))i=this.#a.get(s);else{const b=(0,y.walkAST)(s),l=[],f=[];for(const[...d]of b){for(const x of d){const L=(0,y.generateCSS)(x);l.push(L)}const p=[],N=new Set;let k=d.shift();for(;k;)if(k.type===r.COMBINATOR?(p.push({combo:k,leaves:[...N]}),N.clear()):k&&N.add(k),d.length)k=d.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}f.push(p)}i={astName:c,branches:b,twigBranches:f,selector:l.join(",")},this.#a.set(s,i)}const o=this._matchLogicalPseudoFunc(i,e);o&&t.add(o)}else if(Array.isArray(h)){const[i]=h;if(/^nth-(?:last-)?(?:child|of-type)$/.test(c)){const o=this._matchAnPlusB(i,e,c);o.size&&(t=o)}else if(c==="dir"){const o=this._matchDirectionPseudoClass(i,e);o&&t.add(o)}else if(c==="lang"){const o=this._matchLanguagePseudoClass(i,e);o&&t.add(o)}else switch(c){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${c}()`,r.NOT_SUPPORTED_ERR);break}default:if(!m)throw new DOMException(`Unknown pseudo-class :${c}()`,r.SYNTAX_ERR)}}else{const{document:i,root:o}=this.#t,{documentElement:b}=i,l=new URL(i.URL),f=/^a(?:rea)?$/,d=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,p=/^(?:(?:inpu|selec)t|button|form|textarea)$/,N=/^d(?:etails|ialog)$/,k=/^(?:checkbox|radio)$/,x=/^(?:date(?:time-local)?|month|time|week)$/,L=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,O=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(c){case"any-link":case"link":{f.test(a)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(f.test(a)&&e.hasAttribute("href")){const g=new URL(e.getAttribute("href"),l.href);g.origin===l.origin&&g.pathname===l.pathname&&t.add(e)}break}case"visited":break;case"target":{e.id&&l.hash&&l.hash===`#${e.id}`&&(0,E.isSameOrDescendant)(e)&&t.add(e);break}case"target-within":{if(l.hash){const g=l.hash.replace(/^#/,"");let w=i.getElementById(g);for(;w;){if(w===e){t.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===r.ELEMENT_NODE?e===this.#e&&t.add(e):e===b&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let g=i.activeElement;for(;g;){if(g===e){t.add(e);break}g=g.parentNode}break}case"open":{N.test(a)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{N.test(a)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(d.test(a)||(0,B.default)(a))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let g=u;for(;g&&g.localName!=="fieldset";)g=g.parentNode;g&&u.localName!=="legend"&&g.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(d.test(a)||(0,B.default)(a))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(a){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||O.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(a){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||O.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let g;a==="textarea"?g=e:a==="input"&&(e.hasAttribute("type")?O.test(e.getAttribute("type"))&&(g=e):g=e),g&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&a==="input"&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))||e.selected&&a==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&a==="input"&&e.type==="checkbox"||a==="progress"&&!e.hasAttribute("value"))t.add(e);else if(a==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const g=e.name;let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;w||(w=b);const _=[].slice.call(w.getElementsByTagName("input"));let T;for(const A of _)if(A.getAttribute("type")==="radio"&&(g?A.getAttribute("name")===g&&(T=!!A.checked):A.hasAttribute("name")||(T=!!A.checked),T))break;T||t.add(e)}break}case"default":{const g=/^(?:button|reset)$/,w=/^(?:image|submit)$/;if(a==="button"&&!(e.hasAttribute("type")&&g.test(e.getAttribute("type")))||a==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))){let _=e.parentNode;for(;_&&_.localName!=="form";)_=_.parentNode;if(_){const T=i.createNodeIterator(_,r.SHOW_ELEMENT);let A=T.nextNode();for(;A;){const $=A.localName;let v;if($==="button"?v=!(A.hasAttribute("type")&&g.test(A.getAttribute("type"))):$==="input"&&(v=A.hasAttribute("type")&&w.test(A.getAttribute("type"))),v){A===e&&t.add(e);break}A=T.nextNode()}}}else if(a==="input"&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(a==="option"){let _=!1,T=u;for(;T&&T.localName!=="datalist";){if(T.localName==="select"){(T.multiple||T.hasAttribute("multiple"))&&(_=!0);break}T=T.parentNode}if(_)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const A=u.firstElementChild,$=new Set;let v=A;for(;v;){if(v.selected||v.hasAttribute("selected")){$.add(v);break}v=v.nextElementSibling}$.size||$.add(A),$.has(e)&&t.add(e)}}break}case"valid":{if(p.test(a))e.checkValidity()&&t.add(e);else if(a==="fieldset"){const g=i.createNodeIterator(e,r.SHOW_ELEMENT);let w=g.nextNode();w===e&&(w=g.nextNode());let _;for(;w&&!(p.test(w.localName)&&(_=w.checkValidity(),!_));)w=g.nextNode();_&&t.add(e)}break}case"invalid":{if(p.test(a))e.checkValidity()||t.add(e);else if(a==="fieldset"){const g=i.createNodeIterator(e,r.SHOW_ELEMENT);let w=g.nextNode();w===e&&(w=g.nextNode());let _;for(;w&&!(p.test(w.localName)&&(_=w.checkValidity(),!_));)w=g.nextNode();_||t.add(e)}break}case"in-range":{a==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{a==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let g;if(/^(?:select|textarea)$/.test(a))g=e;else if(a==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||k.test(w)||x.test(w)||O.test(w))&&(g=e)}else g=e;g&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let g;if(/^(?:select|textarea)$/.test(a))g=e;else if(a==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||k.test(w)||x.test(w)||O.test(w))&&(g=e)}else g=e;g&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===b&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const g=e.childNodes.values();let w;for(const _ of g)if(w=_.nodeType!==r.ELEMENT_NODE&&_.nodeType!==r.TEXT_NODE,!w)break;w&&t.add(e)}else t.add(e);break}case"first-child":{(u&&e===u.firstElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(u&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(u&&e===u.firstElementChild&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(u){const[g]=this._collectNthOfType({a:0,b:1},e);g&&t.add(g)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(u){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g&&t.add(g)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(u){const[g]=this._collectNthOfType({a:0,b:1},e);if(g===e){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w===e&&t.add(e)}}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${c}`,r.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${c}`,r.NOT_SUPPORTED_ERR);break}default:if(c.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${c}`,r.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${c}`,r.SYNTAX_ERR)}}return t}_matchAttributeSelector(s,e){const{flags:n,matcher:h,name:a,value:u}=s;if(typeof n=="string"&&!/^[is]$/i.test(n)){const t=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${t}`,r.SYNTAX_ERR)}const{attributes:m}=e;let c;if(m&&m.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof n=="string"&&/^s$/i.test(n)?i=!1:i=!0:typeof n=="string"&&/^i$/i.test(n)?i=!0:i=!1;let o=(0,y.unescapeSelector)(a.name);i&&(o=o.toLowerCase());const b=new Set;if(o.indexOf("|")>-1){const{prefix:l,tagName:f}=(0,E.selectorToNodeProps)(o);for(let{name:d,value:p}of m)switch(i&&(d=d.toLowerCase(),p=p.toLowerCase()),l){case"":{f===d&&b.add(p);break}case"*":{d.indexOf(":")>-1?d.endsWith(`:${f}`)&&b.add(p):f===d&&b.add(p);break}default:if(d.indexOf(":")>-1){const[N,k]=d.split(":");l===N&&f===k&&(0,E.isNamespaceDeclared)(l,e)&&b.add(p)}}}else for(let{name:l,value:f}of m)if(i&&(l=l.toLowerCase(),f=f.toLowerCase()),l.indexOf(":")>-1){const[d,p]=l.split(":");if(d==="xml"&&p==="lang")continue;o===p&&b.add(f)}else o===l&&b.add(f);if(b.size){const{name:l,value:f}=u||{};let d;switch(l?i?d=l.toLowerCase():d=l:f?i?d=f.toLowerCase():d=f:f===""&&(d=f),h){case"=":{typeof d=="string"&&b.has(d)&&(c=e);break}case"~=":{if(d&&typeof d=="string"){for(const p of b)if(new Set(p.split(/\s+/)).has(d)){c=e;break}}break}case"|=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N===d||N.startsWith(`${d}-`)){p=N;break}p&&(c=e)}break}case"^=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.startsWith(`${d}`)){p=N;break}p&&(c=e)}break}case"$=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.endsWith(`${d}`)){p=N;break}p&&(c=e)}break}case"*=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.includes(`${d}`)){p=N;break}p&&(c=e)}break}case null:default:c=e}}}return c??null}_matchClassSelector(s,e){const n=(0,y.unescapeSelector)(s.name);let h;return e.classList.contains(n)&&(h=e),h??null}_matchIDSelector(s,e){const n=(0,y.unescapeSelector)(s.name),{id:h}=e;let a;return n===h&&(a=e),a??null}_matchTypeSelector(s,e){const n=(0,y.unescapeSelector)(s.name),{localName:h,prefix:a}=e,{document:u}=this.#t;let{prefix:m,tagName:c}=(0,E.selectorToNodeProps)(n,e);u.contentType==="text/html"&&(m=m.toLowerCase(),c=c.toLowerCase());let t,i;h.indexOf(":")>-1?[t,i]=h.split(":"):(t=a||"",i=h);let o;if(m===""&&t==="")e.namespaceURI===null&&(c==="*"||c===i)&&(o=e);else if(m==="*")(c==="*"||c===i)&&(o=e);else if(m===t)if((0,E.isNamespaceDeclared)(m,e))(c==="*"||c===i)&&(o=e);else throw new DOMException(`Undeclared namespace ${m}`,r.SYNTAX_ERR);return o??null}_matchShadowHostPseudoClass(s,e){const{children:n}=s,h=(0,y.unescapeSelector)(s.name);let a;if(Array.isArray(n)){const[u]=(0,y.walkAST)(n[0]),[...m]=u,{host:c}=e;if(h==="host"){let t;for(const i of m){const{type:o}=i;if(o===r.COMBINATOR){const b=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${b}`,r.SYNTAX_ERR)}if(t=this._matchSelector(i,c).has(c),!t)break}t&&(a=e)}else if(h==="host-context"){let t=c,i;for(;t;){for(const o of m){const{type:b}=o;if(b===r.COMBINATOR){const l=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${l}`,r.SYNTAX_ERR)}if(i=this._matchSelector(o,t).has(t),!i)break}if(i)break;t=t.parentNode}i&&(a=e)}}else h==="host"&&(a=e);return a??null}_matchSelector(s,e,n){const{type:h}=s,a=(0,y.unescapeSelector)(s.name),{shadow:u}=this.#t;let m=new Set;if(e.nodeType===r.ELEMENT_NODE)switch(h){case r.SELECTOR_ATTR:{const c=this._matchAttributeSelector(s,e);c&&m.add(c);break}case r.SELECTOR_CLASS:{const c=this._matchClassSelector(s,e);c&&m.add(c);break}case r.SELECTOR_ID:{const c=this._matchIDSelector(s,e);c&&m.add(c);break}case r.SELECTOR_PSEUDO_CLASS:{const c=this._matchPseudoClassSelector(s,e,n);c.size&&(m=c);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(a,n);break}case r.SELECTOR_TYPE:default:{const c=this._matchTypeSelector(s,e);c&&m.add(c)}}else if(u&&h===r.SELECTOR_PSEUDO_CLASS&&e.nodeType===r.DOCUMENT_FRAGMENT_NODE){if(a!=="has"&&r.REG_LOGICAL_PSEUDO.test(a)){const c=this._matchPseudoClassSelector(s,e,n);c.size&&(m=c)}else if(r.REG_SHADOW_HOST.test(a)){const c=this._matchShadowHostPseudoClass(s,e);c&&m.add(c)}}return m}_matchLeaves(s,e,n){let h;for(const a of s)if(h=this._matchSelector(a,e,n).has(e),!h)break;return!!h}_findDescendantNodes(s,e){const[n,...h]=s,{type:a}=n,u=(0,y.unescapeSelector)(n.name),m=h.length>0,{document:c,root:t,shadow:i}=this.#t;let o=new Set,b=!1;if(i)b=!0;else switch(a){case r.SELECTOR_ID:{if(t.nodeType===r.ELEMENT_NODE)b=!0;else{const l=t.getElementById(u);if(l&&l!==e){const f=(0,E.isSameOrDescendant)(l,e);let d;f&&(d=l),d&&(m?this._matchLeaves(h,d)&&o.add(d):o.add(d))}}break}case r.SELECTOR_CLASS:{const l=[].slice.call(e.getElementsByClassName(u));if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&o.add(f);else o=new Set(l);break}case r.SELECTOR_TYPE:{if(c.contentType==="text/html"&&!/[*|]/.test(u)){const l=[].slice.call(e.getElementsByTagName(u));if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&o.add(f);else o=new Set(l)}else b=!0;break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:b=!0}return{nodes:o,pending:b}}_matchCombinator(s,e,n={}){const{combo:h,leaves:a}=s,{name:u}=h,{find:m,forgive:c}=n;let t=new Set;if(m===R)switch(u){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,{forgive:c})&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(a,i,{forgive:c})&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[].slice.call(e.children);for(const o of i)this._matchLeaves(a,o,{forgive:c})&&t.add(o);break}case" ":default:{const{nodes:i,pending:o}=this._findDescendantNodes(a,e);if(i.size)t=i;else if(o){const{document:b}=this.#t,l=b.createNodeIterator(e,r.SHOW_ELEMENT);let f=l.nextNode();for(f===e&&(f=l.nextNode());f;)this._matchLeaves(a,f,{forgive:c})&&t.add(f),f=l.nextNode()}}}else switch(u){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,{forgive:c})&&t.add(i);break}case"~":{const i=[];let o=e.previousElementSibling;for(;o;)this._matchLeaves(a,o,{forgive:c})&&i.push(o),o=o.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(a,i,{forgive:c})&&t.add(i);break}case" ":default:{const i=[];let o=e.parentNode;for(;o;)this._matchLeaves(a,o,{forgive:c})&&i.push(o),o=o.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(s,e){const{leaves:[n,...h]}=s,{type:a}=n,u=(0,y.unescapeSelector)(n.name),m=h.length>0,{document:c,root:t,shadow:i}=this.#t;let o=new Set,b=!1;switch(a){case r.SELECTOR_ID:{let l;if(e===I)this._matchLeaves([n],this.#e)&&(l=this.#e);else if(e===D){let f=this.#e;for(;f;){if(this._matchLeaves([n],f)){l=f;break}f=f.parentNode}}else t.nodeType===r.ELEMENT_NODE?b=!0:l=t.getElementById(u);l&&(m?this._matchLeaves(h,l)&&o.add(l):o.add(l));break}case r.SELECTOR_CLASS:{let l=[];if(e===I)this.#e.nodeType===r.ELEMENT_NODE&&this.#e.classList.contains(u)&&l.push(this.#e);else if(e===D){let f=this.#e;for(;f&&f.nodeType===r.ELEMENT_NODE;)f.classList.contains(u)&&l.push(f),f=f.parentNode}else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const f=[].slice.call(t.children);for(const d of f){d.classList.contains(u)&&l.push(d);const p=[].slice.call(d.getElementsByClassName(u));l.push(...p)}}else l=[].slice.call(t.getElementsByClassName(u));if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&o.add(f);else o=new Set(l);break}case r.SELECTOR_TYPE:{let l=[];if(e===I)this.#e.nodeType===r.ELEMENT_NODE&&this._matchLeaves([n],this.#e)&&l.push(this.#e);else if(e===D){let f=this.#e;for(;f&&f.nodeType===r.ELEMENT_NODE;)this._matchLeaves([n],f)&&l.push(f),f=f.parentNode}else if(c.contentType!=="text/html"||/[*|]/.test(u))b=!0;else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const f=u.toLowerCase(),d=[].slice.call(t.children);for(const p of d){p.localName===f&&l.push(p);const N=[].slice.call(p.getElementsByTagName(u));l.push(...N)}}else l=[].slice.call(t.getElementsByTagName(u));if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&o.add(f);else o=new Set(l);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:{const l=[];if(e!==D&&r.REG_SHADOW_HOST.test(u)){if(i&&this.#e.nodeType===r.DOCUMENT_FRAGMENT_NODE){const f=this._matchShadowHostPseudoClass(n,this.#e);f&&l.push(f)}}else if(e===I)this._matchLeaves([n],this.#e)&&l.push(this.#e);else if(e===D){let f=this.#e;for(;f;)this._matchLeaves([n],f)&&l.push(f),f=f.parentNode}else b=!0;if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&o.add(f);else o=new Set(l)}}return{nodes:o,pending:b}}_getFirstTwig(s){const e=s.length-1,n=s[0];let h,a;if(e){const u=s[e],{leaves:[{type:m}]}=u;m===r.SELECTOR_PSEUDO_ELEMENT||m===r.SELECTOR_ID?(h=M,a=u):(h=R,a=n)}else h=M,a=n;return{find:h,twig:a}}_collectNodes(s){const e=this.#i.values();if(s===U||s===C){const n=new Set;let h=0;for(const{branch:a}of e){const{find:u,twig:m}=this._getFirstTwig(a),{nodes:c,pending:t}=this._findNodes(m,s);c.size?this.#l[h]=c:t?n.add(new Map([["index",h],["twig",m]])):this.#i[h].skip=!0,this.#i[h].find=u,h++}if(n.size){const{document:a,root:u}=this.#t,m=a.createNodeIterator(u,r.SHOW_ELEMENT);let c=m.nextNode();for(;c;){let t=!1;if(this.#e.nodeType===r.ELEMENT_NODE?t=(0,E.isSameOrDescendant)(c,this.#e):t=!0,t)for(const i of n){const{leaves:o}=i.get("twig");if(this._matchLeaves(o,c)){const l=i.get("index");this.#l[l].add(c)}}c=m.nextNode()}}}else{let n=0;for(const{branch:h}of e){const a=h[h.length-1],{nodes:u}=this._findNodes(a,s);u.size?this.#l[n]=u:this.#i[n].skip=!0,this.#i[n].find=M,n++}}return[this.#i,this.#l]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((n,h)=>{const a=n.compareDocumentPosition(h);let u;return a&r.DOCUMENT_POSITION_PRECEDING||a&r.DOCUMENT_POSITION_CONTAINS?u=1:u=-1,u}),e}_matchNodes(s){const[...e]=this.#i,n=e.length;let h=new Set;for(let a=0;a<n;a++){const{branch:u,find:m,skip:c}=e[a],t=u.length;if(!c&&t){const i=this.#l[a],o=t-1;if(o===0)if((s===U||s===C)&&this.#e.nodeType===r.ELEMENT_NODE){for(const b of i)if(b!==this.#e&&(0,E.isSameOrDescendant)(b,this.#e)&&(h.add(b),s===C))break}else if(s===C){const[b]=this._sortNodes(i);h.add(b)}else{const b=[...h],l=[...i];h=new Set([...b,...l])}else if(m===R){let{combo:b}=u[0];for(const l of i){let f=new Set([l]);for(let d=1;d<t;d++){const{combo:p,leaves:N}=u[d],k=[];for(const x of f){const L={combo:b,leaves:N},O=this._matchCombinator(L,x,{find:m});O.size&&k.push(...O)}if(k.length)if(d===o){if(s===C){const[x]=this._sortNodes(k);h.add(x)}else{const x=[...h];h=new Set([...x,...k])}break}else b=p,f=new Set(k);else break}}}else for(const b of i){let l=new Set([b]),f;for(let d=o-1;d>=0;d--){const p=u[d],N=[];for(const k of l){const x=this._matchCombinator(p,k,{find:m});x.size&&N.push(...x)}if(N.length)if(f=!0,d===0){h.add(b);break}else l=new Set(N);else{f=!1;break}}if(f&&s!==U)break}}}return h}_find(s){return this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{s=this._find(I).has(this.#e)}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{const e=this._find(D);let n=this.#e;for(;n;){if(e.has(n)){s=n;break}n=n.parentNode}}catch(e){this._onError(e)}return s??null}querySelector(){let s;try{const e=this._find(C);e.delete(this.#e),e.size&&([s]=this._sortNodes(e))}catch(e){this._onError(e)}return s??null}querySelectorAll(){let s;try{const e=this._find(U);e.delete(this.#e),e.size&&(s=this._sortNodes(e))}catch(e){this._onError(e)}return s??[]}}0&&(module.exports={Matcher});
1
+ var F=Object.create;var M=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var W=(S,s)=>{for(var e in s)M(S,e,{get:s[e],enumerable:!0})},z=(S,s,e,c)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of j(s))!G.call(S,h)&&h!==e&&M(S,h,{get:()=>s[h],enumerable:!(c=V(s,h))||c.enumerable});return S};var q=(S,s,e)=>(e=S!=null?F(H(S)):{},z(s||!S||!S.__esModule?M(e,"default",{value:S,enumerable:!0}):e,S)),X=S=>z(M({},"__esModule",{value:!0}),S);var J={};W(J,{Matcher:()=>Y});module.exports=X(J);var B=q(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),k=require("./parser.js"),l=require("./constant.js");const R="next",U="prev",I="all",C="first",D="lineal",P="self";class Y{#i;#r;#a;#e;#l;#t;#o;#s;constructor(s,e,c={}){const{warn:h}=c;this.#r=new Map([[l.SELECTOR_PSEUDO_ELEMENT,l.BIT_01],[l.SELECTOR_ID,l.BIT_02],[l.SELECTOR_CLASS,l.BIT_04],[l.SELECTOR_TYPE,l.BIT_08],[l.SELECTOR_ATTR,l.BIT_16],[l.SELECTOR_PSEUDO_CLASS,l.BIT_32]]),this.#a=new WeakMap,this.#o=s,this.#e=e,this.#s=!!h,[this.#i,this.#l]=this._prepare(s),this.#t=this._getRoot(e)}_onError(s){if(s instanceof DOMException&&s.name===l.NOT_SUPPORTED_ERR)this.#s&&console.warn(s.message);else throw s}_getRoot(s=this.#e){let e,c;switch(s.nodeType){case l.DOCUMENT_NODE:{e=s,c=s;break}case l.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,c=s;break}case l.ELEMENT_NODE:{if((0,E.isSameOrDescendant)(s))e=s.ownerDocument,c=s.ownerDocument;else{let r=s;for(;r&&r.parentNode;)r=r.parentNode;e=r.ownerDocument,c=r}break}default:throw new TypeError(`Unexpected node ${s.nodeName}`)}const h=(0,E.isInShadowTree)(s);return{document:e,root:c,shadow:h}}_sortLeaves(s){const e=[...s];return e.length>1&&e.sort((c,h)=>{const{type:r}=c,{type:u}=h,m=this.#r.get(r),f=this.#r.get(u);let t;return m===f?t=0:m>f?t=1:t=-1,t}),e}_prepare(s=this.#o){const e=(0,k.parseSelector)(s),c=(0,k.walkAST)(e),h=[],r=[];let u=0;for(const[...m]of c){const f=[];let t=m.shift();if(t&&t.type!==l.COMBINATOR){const i=new Set;for(;t;){if(t.type===l.COMBINATOR){const[o]=m;if(o.type===l.COMBINATOR){const d=`Invalid combinator ${t.name}${o.name}`;throw new DOMException(d,l.SYNTAX_ERR)}f.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(m.length)t=m.shift();else{f.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}h.push({branch:f,find:null,skip:!1}),r[u]=new Set,u++}return[h,r]}_collectNthChild(s,e){const{a:c,b:h,reverse:r,selector:u}=s,{parentNode:m}=e,f=new Set;let t;if(u&&(this.#a.has(u)?t=this.#a.get(u):(t=(0,k.walkAST)(u),this.#a.set(u,t))),m){const i=[].slice.call(m.children),o=i.length;if(o){const d=new Set;if(t){const a=t.length;for(const n of i){let b;for(let p=0;p<a;p++){const N=t[p];if(b=this._matchLeaves(N,n),!b)break}b&&d.add(n)}}if(r&&i.reverse(),c===0){if(h>0&&h<=o){if(d.size)for(let a=0;a<o;a++){const n=i[a];if(d.has(n)){f.add(n);break}}else if(!u){const a=i[h-1];f.add(a)}}}else{let a=h-1;if(c>0)for(;a<0;)a+=c;if(a>=0&&a<o){let n=c>0?0:h-1;for(let b=0;b<o&&a>=0&&a<o;b++){const p=i[b];d.size?d.has(p)&&(n===a&&(f.add(p),a+=c),c>0?n++:n--):b===a&&(u||f.add(p),a+=c)}}}}}else{const{root:i}=this.#t;if(e===i&&i.nodeType===l.ELEMENT_NODE&&c+h===1)if(t){const o=t.length;let d;for(let a=0;a<o;a++){const n=t[a];if(d=this._matchLeaves(n,e),d)break}d&&f.add(e)}else f.add(e)}return f}_collectNthOfType(s,e){const{a:c,b:h,reverse:r}=s,{localName:u,parentNode:m,prefix:f}=e,t=new Set;if(m){const i=[].slice.call(m.children),o=i.length;if(o)if(r&&i.reverse(),c===0){if(h>0&&h<=o){let d=0;for(let a=0;a<o;a++){const n=i[a],{localName:b,prefix:p}=n;if(b===u&&p===f){if(d===h-1){t.add(n);break}d++}}}}else{let d=h-1;if(c>0)for(;d<0;)d+=c;if(d>=0&&d<o){let a=c>0?0:h-1;for(let n=0;n<o;n++){const b=i[n],{localName:p,prefix:N}=b;if(p===u&&N===f){if(a===d&&(t.add(b),d+=c),d<0||d>=o)break;c>0?a++:a--}}}}}else{const{root:i}=this.#t;e===i&&i.nodeType===l.ELEMENT_NODE&&c+h===1&&t.add(e)}return t}_matchAnPlusB(s,e,c){const{nth:{a:h,b:r,name:u},selector:m}=s,f=(0,k.unescapeSelector)(u),t=new Map;f?(f==="even"?(t.set("a",2),t.set("b",0)):f==="odd"&&(t.set("a",2),t.set("b",1)),c.indexOf("last")>-1&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?t.set("b",r*1):t.set("b",0),c.indexOf("last")>-1&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){m&&t.set("selector",m);const o=Object.fromEntries(t),d=this._collectNthChild(o,e);d.size&&(i=d)}else if(/^nth-(?:last-)?of-type$/.test(c)){const o=Object.fromEntries(t),d=this._collectNthOfType(o,e);d.size&&(i=d)}}return i}_matchPseudoElementSelector(s,e={}){const{forgive:c}=e;switch(s){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,l.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}()`,l.NOT_SUPPORTED_ERR);break}default:if(s.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,l.NOT_SUPPORTED_ERR)}else if(!c)throw new DOMException(`Unknown pseudo-element ::${s}`,l.SYNTAX_ERR)}}_matchDirectionPseudoClass(s,e){const c=(0,k.unescapeSelector)(s.name),h=(0,E.getDirectionality)(e);let r;return c===h&&(r=e),r??null}_matchLanguagePseudoClass(s,e){const c=(0,k.unescapeSelector)(s.name);let h;if(c)if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let r=e.parentNode;for(;r&&r.nodeType===l.ELEMENT_NODE;){if(r.hasAttribute("lang")){r.getAttribute("lang")&&(h=e);break}r=r.parentNode}}else{const r=`(?:-${l.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${l.ALPHA_NUM}${r}$`,"i").test(c)){let m;if(c.indexOf("-")>-1){const[f,t,...i]=c.split("-");let o;f==="*"?o=`${l.ALPHA_NUM}${r}`:o=`${f}${r}`;const d=`-${t}${r}`,a=i.length;let n="";if(a)for(let b=0;b<a;b++)n+=`-${i[b]}${r}`;m=new RegExp(`^${o}${d}${n}$`,"i")}else m=new RegExp(`^${c}${r}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(h=e);else{let f=e.parentNode;for(;f&&f.nodeType===l.ELEMENT_NODE;){if(f.hasAttribute("lang")){const t=f.getAttribute("lang");m.test(t)&&(h=e);break}f=f.parentNode}}}}return h??null}_matchHasPseudoFunc(s,e){let c;if(Array.isArray(s)&&s.length){const[h]=s,{type:r}=h;let u;r===l.COMBINATOR?u=s.shift():u={name:" ",type:l.COMBINATOR};const m=[];for(;s.length;){const[i]=s,{type:o}=i;if(o===l.COMBINATOR)break;m.push(s.shift())}const f={combo:u,leaves:m},t=this._matchCombinator(f,e,{find:R});if(t.size)if(s.length){for(const i of t)if(c=this._matchHasPseudoFunc(Object.assign([],s),i),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(s,e){const{astName:c="",branches:h=[],selector:r="",twigBranches:u=[]}=s;let m;if(c==="has")if(r.includes(":has("))m=null;else{const f=h.length;let t;for(let i=0;i<f;i++){const o=h[i];if(t=this._matchHasPseudoFunc(Object.assign([],o),e),t)break}t&&(m=e)}else{const f=/^(?:is|where)$/.test(c),t=u.length;let i;for(let o=0;o<t;o++){const d=u[o],a=d.length-1,{leaves:n}=d[a];if(i=this._matchLeaves(n,e,{forgive:f}),i&&a>0){let b=new Set([e]);for(let p=a-1;p>=0;p--){const N=d[p],y=[];for(const x of b){const L=this._matchCombinator(N,x,{forgive:f,find:U});L.size&&y.push(...L)}if(y.length)if(p===0){i=!0;break}else b=new Set(y);else{i=!1;break}}}if(i)break}c==="not"?i||(m=e):i&&(m=e)}return m??null}_matchPseudoClassSelector(s,e,c={}){const{children:h}=s,{localName:r,parentNode:u}=e,{forgive:m}=c,f=(0,k.unescapeSelector)(s.name);let t=new Set;if(l.REG_LOGICAL_PSEUDO.test(f)){let i;if(this.#a.has(s))i=this.#a.get(s);else{const d=(0,k.walkAST)(s),a=[],n=[];for(const[...b]of d){for(const x of b){const L=(0,k.generateCSS)(x);a.push(L)}const p=[],N=new Set;let y=b.shift();for(;y;)if(y.type===l.COMBINATOR?(p.push({combo:y,leaves:[...N]}),N.clear()):y&&N.add(y),b.length)y=b.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}n.push(p)}i={astName:f,branches:d,twigBranches:n,selector:a.join(",")},this.#a.set(s,i)}const o=this._matchLogicalPseudoFunc(i,e);o&&t.add(o)}else if(Array.isArray(h)){const[i]=h;if(/^nth-(?:last-)?(?:child|of-type)$/.test(f)){const o=this._matchAnPlusB(i,e,f);o.size&&(t=o)}else if(f==="dir"){const o=this._matchDirectionPseudoClass(i,e);o&&t.add(o)}else if(f==="lang"){const o=this._matchLanguagePseudoClass(i,e);o&&t.add(o)}else switch(f){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}()`,l.NOT_SUPPORTED_ERR);break}default:if(!m)throw new DOMException(`Unknown pseudo-class :${f}()`,l.SYNTAX_ERR)}}else{const{document:i,root:o}=this.#t,{documentElement:d}=i,a=new URL(i.URL),n=/^a(?:rea)?$/,b=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,p=/^(?:(?:inpu|selec)t|button|form|textarea)$/,N=/^d(?:etails|ialog)$/,y=/^(?:checkbox|radio)$/,x=/^(?:date(?:time-local)?|month|time|week)$/,L=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,O=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(f){case"any-link":case"link":{n.test(r)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(n.test(r)&&e.hasAttribute("href")){const w=new URL(e.getAttribute("href"),a.href);w.origin===a.origin&&w.pathname===a.pathname&&t.add(e)}break}case"visited":break;case"target":{e.id&&a.hash&&a.hash===`#${e.id}`&&(0,E.isSameOrDescendant)(e)&&t.add(e);break}case"target-within":{if(a.hash){const w=a.hash.replace(/^#/,"");let g=i.getElementById(w);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===l.ELEMENT_NODE?e===this.#e&&t.add(e):e===d&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let w=i.activeElement;for(;w;){if(w===e){t.add(e);break}w=w.parentNode}break}case"open":{N.test(r)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{N.test(r)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(b.test(r)||(0,B.default)(r))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let w=u;for(;w&&w.localName!=="fieldset";)w=w.parentNode;w&&u.localName!=="legend"&&w.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(b.test(r)||(0,B.default)(r))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(r){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||O.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||O.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let w;r==="textarea"?w=e:r==="input"&&(e.hasAttribute("type")?O.test(e.getAttribute("type"))&&(w=e):w=e),w&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&r==="input"&&e.hasAttribute("type")&&y.test(e.getAttribute("type"))||e.selected&&r==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&r==="input"&&e.type==="checkbox"||r==="progress"&&!e.hasAttribute("value"))t.add(e);else if(r==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const w=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=d);const _=[].slice.call(g.getElementsByTagName("input"));let T;for(const A of _)if(A.getAttribute("type")==="radio"&&(w?A.getAttribute("name")===w&&(T=!!A.checked):A.hasAttribute("name")||(T=!!A.checked),T))break;T||t.add(e)}break}case"default":{const w=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(r==="button"&&!(e.hasAttribute("type")&&w.test(e.getAttribute("type")))||r==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let _=e.parentNode;for(;_&&_.localName!=="form";)_=_.parentNode;if(_){const T=i.createNodeIterator(_,l.SHOW_ELEMENT);let A=T.nextNode();for(;A;){const $=A.localName;let v;if($==="button"?v=!(A.hasAttribute("type")&&w.test(A.getAttribute("type"))):$==="input"&&(v=A.hasAttribute("type")&&g.test(A.getAttribute("type"))),v){A===e&&t.add(e);break}A=T.nextNode()}}}else if(r==="input"&&e.hasAttribute("type")&&y.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(r==="option"){let _=!1,T=u;for(;T&&T.localName!=="datalist";){if(T.localName==="select"){(T.multiple||T.hasAttribute("multiple"))&&(_=!0);break}T=T.parentNode}if(_)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const A=u.firstElementChild,$=new Set;let v=A;for(;v;){if(v.selected||v.hasAttribute("selected")){$.add(v);break}v=v.nextElementSibling}$.size||$.add(A),$.has(e)&&t.add(e)}}break}case"valid":{if(p.test(r))e.checkValidity()&&t.add(e);else if(r==="fieldset"){const w=i.createNodeIterator(e,l.SHOW_ELEMENT);let g=w.nextNode();g===e&&(g=w.nextNode());let _;for(;g&&!(p.test(g.localName)&&(_=g.checkValidity(),!_));)g=w.nextNode();_&&t.add(e)}break}case"invalid":{if(p.test(r))e.checkValidity()||t.add(e);else if(r==="fieldset"){const w=i.createNodeIterator(e,l.SHOW_ELEMENT);let g=w.nextNode();g===e&&(g=w.nextNode());let _;for(;g&&!(p.test(g.localName)&&(_=g.checkValidity(),!_));)g=w.nextNode();_||t.add(e)}break}case"in-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let w;if(/^(?:select|textarea)$/.test(r))w=e;else if(r==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||y.test(g)||x.test(g)||O.test(g))&&(w=e)}else w=e;w&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let w;if(/^(?:select|textarea)$/.test(r))w=e;else if(r==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||y.test(g)||x.test(g)||O.test(g))&&(w=e)}else w=e;w&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===d&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const w=e.childNodes.values();let g;for(const _ of w)if(g=_.nodeType!==l.ELEMENT_NODE&&_.nodeType!==l.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(u&&e===u.firstElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(u&&e===u.lastElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(u&&e===u.firstElementChild&&e===u.lastElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1},e);w&&t.add(w)}else e===o&&o.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w&&t.add(w)}else e===o&&o.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1},e);if(w===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===o&&o.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${f}`,l.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,l.NOT_SUPPORTED_ERR);break}default:if(f.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,l.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${f}`,l.SYNTAX_ERR)}}return t}_matchAttributeSelector(s,e){const{flags:c,matcher:h,name:r,value:u}=s;if(typeof c=="string"&&!/^[is]$/i.test(c)){const t=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${t}`,l.SYNTAX_ERR)}const{attributes:m}=e;let f;if(m&&m.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof c=="string"&&/^s$/i.test(c)?i=!1:i=!0:typeof c=="string"&&/^i$/i.test(c)?i=!0:i=!1;let o=(0,k.unescapeSelector)(r.name);i&&(o=o.toLowerCase());const d=new Set;if(o.indexOf("|")>-1){const{prefix:a,tagName:n}=(0,E.selectorToNodeProps)(o);for(let{name:b,value:p}of m)switch(i&&(b=b.toLowerCase(),p=p.toLowerCase()),a){case"":{n===b&&d.add(p);break}case"*":{b.indexOf(":")>-1?b.endsWith(`:${n}`)&&d.add(p):n===b&&d.add(p);break}default:if(b.indexOf(":")>-1){const[N,y]=b.split(":");a===N&&n===y&&(0,E.isNamespaceDeclared)(a,e)&&d.add(p)}}}else for(let{name:a,value:n}of m)if(i&&(a=a.toLowerCase(),n=n.toLowerCase()),a.indexOf(":")>-1){const[b,p]=a.split(":");if(b==="xml"&&p==="lang")continue;o===p&&d.add(n)}else o===a&&d.add(n);if(d.size){const{name:a,value:n}=u||{};let b;switch(a?i?b=a.toLowerCase():b=a:n?i?b=n.toLowerCase():b=n:n===""&&(b=n),h){case"=":{typeof b=="string"&&d.has(b)&&(f=e);break}case"~=":{if(b&&typeof b=="string"){for(const p of d)if(new Set(p.split(/\s+/)).has(b)){f=e;break}}break}case"|=":{if(b&&typeof b=="string"){let p;for(const N of d)if(N===b||N.startsWith(`${b}-`)){p=N;break}p&&(f=e)}break}case"^=":{if(b&&typeof b=="string"){let p;for(const N of d)if(N.startsWith(`${b}`)){p=N;break}p&&(f=e)}break}case"$=":{if(b&&typeof b=="string"){let p;for(const N of d)if(N.endsWith(`${b}`)){p=N;break}p&&(f=e)}break}case"*=":{if(b&&typeof b=="string"){let p;for(const N of d)if(N.includes(`${b}`)){p=N;break}p&&(f=e)}break}case null:default:f=e}}}return f??null}_matchClassSelector(s,e){const c=(0,k.unescapeSelector)(s.name);let h;return e.classList.contains(c)&&(h=e),h??null}_matchIDSelector(s,e){const c=(0,k.unescapeSelector)(s.name),{id:h}=e;let r;return c===h&&(r=e),r??null}_matchTypeSelector(s,e,c={}){const h=(0,k.unescapeSelector)(s.name),{localName:r,prefix:u}=e,{forgive:m}=c,{document:f}=this.#t;let{prefix:t,tagName:i}=(0,E.selectorToNodeProps)(h,e);f.contentType==="text/html"&&(t=t.toLowerCase(),i=i.toLowerCase());let o,d;r.indexOf(":")>-1?[o,d]=r.split(":"):(o=u||"",d=r);let a;if(t===""&&o==="")e.namespaceURI===null&&(i==="*"||i===d)&&(a=e);else if(t==="*")(i==="*"||i===d)&&(a=e);else if(t===o){if((0,E.isNamespaceDeclared)(t,e))(i==="*"||i===d)&&(a=e);else if(!m)throw new DOMException(`Undeclared namespace ${t}`,l.SYNTAX_ERR)}else if(t&&!m&&!(0,E.isNamespaceDeclared)(t,e))throw new DOMException(`Undeclared namespace ${t}`,l.SYNTAX_ERR);return a??null}_matchShadowHostPseudoClass(s,e){const{children:c}=s,h=(0,k.unescapeSelector)(s.name);let r;if(Array.isArray(c)){const[u]=(0,k.walkAST)(c[0]),[...m]=u,{host:f}=e;if(h==="host"){let t;for(const i of m){const{type:o}=i;if(o===l.COMBINATOR){const d=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${d}`,l.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}t&&(r=e)}else if(h==="host-context"){let t=f,i;for(;t;){for(const o of m){const{type:d}=o;if(d===l.COMBINATOR){const a=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${a}`,l.SYNTAX_ERR)}if(i=this._matchSelector(o,t).has(t),!i)break}if(i)break;t=t.parentNode}i&&(r=e)}}else if(h==="host")r=e;else throw new DOMException(`Invalid selector :${h}`,l.SYNTAX_ERR);return r??null}_matchSelector(s,e,c){const{type:h}=s,r=(0,k.unescapeSelector)(s.name),{shadow:u}=this.#t;let m=new Set;if(e.nodeType===l.ELEMENT_NODE)switch(h){case l.SELECTOR_ATTR:{const f=this._matchAttributeSelector(s,e);f&&m.add(f);break}case l.SELECTOR_CLASS:{const f=this._matchClassSelector(s,e);f&&m.add(f);break}case l.SELECTOR_ID:{const f=this._matchIDSelector(s,e);f&&m.add(f);break}case l.SELECTOR_PSEUDO_CLASS:{const f=this._matchPseudoClassSelector(s,e,c);f.size&&(m=f);break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(r,c);break}case l.SELECTOR_TYPE:default:{const f=this._matchTypeSelector(s,e,c);f&&m.add(f)}}else if(u&&h===l.SELECTOR_PSEUDO_CLASS&&e.nodeType===l.DOCUMENT_FRAGMENT_NODE){if(r!=="has"&&l.REG_LOGICAL_PSEUDO.test(r)){const f=this._matchPseudoClassSelector(s,e,c);f.size&&(m=f)}else if(l.REG_SHADOW_HOST.test(r)){const f=this._matchShadowHostPseudoClass(s,e);f&&m.add(f)}}return m}_matchLeaves(s,e,c){let h;for(const r of s)if(h=this._matchSelector(r,e,c).has(e),!h)break;return!!h}_findDescendantNodes(s,e){const[c,...h]=s,{type:r}=c,u=(0,k.unescapeSelector)(c.name),m=h.length>0,{document:f,root:t,shadow:i}=this.#t;let o=new Set,d=!1;if(i)d=!0;else switch(r){case l.SELECTOR_ID:{if(t.nodeType===l.ELEMENT_NODE)d=!0;else{const a=t.getElementById(u);if(a&&a!==e){const n=(0,E.isSameOrDescendant)(a,e);let b;n&&(b=a),b&&(m?this._matchLeaves(h,b)&&o.add(b):o.add(b))}}break}case l.SELECTOR_CLASS:{const a=[].slice.call(e.getElementsByClassName(u));if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a);break}case l.SELECTOR_TYPE:{if(f.contentType==="text/html"&&!/[*|]/.test(u)){const a=[].slice.call(e.getElementsByTagName(u));if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a)}else d=!0;break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:d=!0}return{nodes:o,pending:d}}_matchCombinator(s,e,c={}){const{combo:h,leaves:r}=s,{name:u}=h,{find:m,forgive:f}=c;let t=new Set;if(m===R)switch(u){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(r,i,{forgive:f})&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[].slice.call(e.children);for(const o of i)this._matchLeaves(r,o,{forgive:f})&&t.add(o);break}case" ":default:{const{nodes:i,pending:o}=this._findDescendantNodes(r,e);if(i.size)t=i;else if(o){const{document:d}=this.#t,a=d.createNodeIterator(e,l.SHOW_ELEMENT);let n=a.nextNode();for(n===e&&(n=a.nextNode());n;)this._matchLeaves(r,n,{forgive:f})&&t.add(n),n=a.nextNode()}}}else switch(u){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case"~":{const i=[];let o=e.previousElementSibling;for(;o;)this._matchLeaves(r,o,{forgive:f})&&i.push(o),o=o.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case" ":default:{const i=[];let o=e.parentNode;for(;o;)this._matchLeaves(r,o,{forgive:f})&&i.push(o),o=o.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(s,e){const{leaves:[c,...h]}=s,{type:r}=c,u=(0,k.unescapeSelector)(c.name),m=h.length>0,{document:f,root:t,shadow:i}=this.#t;let o=new Set,d=!1;switch(r){case l.SELECTOR_ID:{let a;if(e===P)this._matchLeaves([c],this.#e)&&(a=this.#e);else if(e===D){let n=this.#e;for(;n;){if(this._matchLeaves([c],n)){a=n;break}n=n.parentNode}}else e===I||t.nodeType===l.ELEMENT_NODE?d=!0:a=t.getElementById(u);a&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a));break}case l.SELECTOR_CLASS:{let a=[];if(e===P)this.#e.nodeType===l.ELEMENT_NODE&&this.#e.classList.contains(u)&&a.push(this.#e);else if(e===D){let n=this.#e;for(;n&&n.nodeType===l.ELEMENT_NODE;)n.classList.contains(u)&&a.push(n),n=n.parentNode}else if(t.nodeType===l.DOCUMENT_FRAGMENT_NODE){const n=[].slice.call(t.children);for(const b of n){b.classList.contains(u)&&a.push(b);const p=[].slice.call(b.getElementsByClassName(u));a.push(...p)}}else a=[].slice.call(t.getElementsByClassName(u));if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a);break}case l.SELECTOR_TYPE:{let a=[];if(e===P)this.#e.nodeType===l.ELEMENT_NODE&&this._matchLeaves([c],this.#e)&&a.push(this.#e);else if(e===D){let n=this.#e;for(;n&&n.nodeType===l.ELEMENT_NODE;)this._matchLeaves([c],n)&&a.push(n),n=n.parentNode}else if(f.contentType!=="text/html"||/[*|]/.test(u))d=!0;else if(t.nodeType===l.DOCUMENT_FRAGMENT_NODE){const n=u.toLowerCase(),b=[].slice.call(t.children);for(const p of b){p.localName===n&&a.push(p);const N=[].slice.call(p.getElementsByTagName(u));a.push(...N)}}else a=[].slice.call(t.getElementsByTagName(u));if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a);break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:{const a=[];if(e!==D&&l.REG_SHADOW_HOST.test(u)){if(i&&this.#e.nodeType===l.DOCUMENT_FRAGMENT_NODE){const n=this._matchShadowHostPseudoClass(c,this.#e);n&&a.push(n)}}else if(e===P)this._matchLeaves([c],this.#e)&&a.push(this.#e);else if(e===D){let n=this.#e;for(;n;)this._matchLeaves([c],n)&&a.push(n),n=n.parentNode}else d=!0;if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a)}}if(m&&!d&&!o.size){const a=h[h.length-1],{type:n}=a;if(n===l.SELECTOR_PSEUDO_CLASS){let b;t.nodeType===l.ELEMENT_NODE?b=t:b=t.firstElementChild,this._matchPseudoClassSelector(a,b)}}return{nodes:o,pending:d}}_getFirstTwig(s){const e=s.length-1,c=s[0];let h,r;if(e){const u=s[e],{leaves:[{type:m}]}=u;m===l.SELECTOR_PSEUDO_ELEMENT||m===l.SELECTOR_ID?(h=U,r=u):(h=R,r=c)}else h=U,r=c;return{find:h,twig:r}}_collectNodes(s){const e=this.#i.values();if(s===I||s===C){const c=new Set;let h=0;for(const{branch:r}of e){const{find:u,twig:m}=this._getFirstTwig(r),{nodes:f,pending:t}=this._findNodes(m,s);f.size?this.#l[h]=f:t?c.add(new Map([["index",h],["twig",m]])):this.#i[h].skip=!0,this.#i[h].find=u,h++}if(c.size){const{document:r,root:u}=this.#t,m=r.createNodeIterator(u,l.SHOW_ELEMENT);let f=m.nextNode();for(;f;){let t=!1;if(this.#e.nodeType===l.ELEMENT_NODE?t=(0,E.isSameOrDescendant)(f,this.#e):t=!0,t)for(const i of c){const{leaves:o}=i.get("twig");if(this._matchLeaves(o,f)){const a=i.get("index");this.#l[a].add(f)}}f=m.nextNode()}}}else{let c=0;for(const{branch:h}of e){const r=h[h.length-1],{nodes:u}=this._findNodes(r,s);u.size?this.#l[c]=u:this.#i[c].skip=!0,this.#i[c].find=U,c++}}return[this.#i,this.#l]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((c,h)=>{const r=c.compareDocumentPosition(h);let u;return r&l.DOCUMENT_POSITION_PRECEDING||r&l.DOCUMENT_POSITION_CONTAINS?u=1:u=-1,u}),e}_matchNodes(s){const[...e]=this.#i,c=e.length;let h=new Set;for(let r=0;r<c;r++){const{branch:u,find:m,skip:f}=e[r],t=u.length;if(!f&&t){const i=this.#l[r],o=t-1;if(o===0)if((s===I||s===C)&&this.#e.nodeType===l.ELEMENT_NODE){for(const d of i)if(d!==this.#e&&(0,E.isSameOrDescendant)(d,this.#e)&&(h.add(d),s===C))break}else if(s===C){const[d]=this._sortNodes(i);h.add(d)}else{const d=[...h],a=[...i];h=new Set([...d,...a])}else if(m===R){let{combo:d}=u[0];for(const a of i){let n=new Set([a]);for(let b=1;b<t;b++){const{combo:p,leaves:N}=u[b],y=[];for(const x of n){const L={combo:d,leaves:N},O=this._matchCombinator(L,x,{find:m});O.size&&y.push(...O)}if(y.length)if(b===o){if(s===C){const[x]=this._sortNodes(y);h.add(x)}else{const x=[...h];h=new Set([...x,...y])}break}else d=p,n=new Set(y);else break}}}else for(const d of i){let a=new Set([d]),n;for(let b=o-1;b>=0;b--){const p=u[b],N=[];for(const y of a){const x=this._matchCombinator(p,y,{find:m});x.size&&N.push(...x)}if(N.length)if(n=!0,b===0){h.add(d);break}else a=new Set(N);else{n=!1;break}}if(n&&s!==I)break}}}return h}_find(s){return this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==l.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{s=this._find(P).has(this.#e)}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==l.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{const e=this._find(D);let c=this.#e;for(;c;){if(e.has(c)){s=c;break}c=c.parentNode}}catch(e){this._onError(e)}return s??null}querySelector(){let s;try{const e=this._find(C);e.delete(this.#e),e.size&&([s]=this._sortNodes(e))}catch(e){this._onError(e)}return s??null}querySelectorAll(){let s;try{const e=this._find(I);e.delete(this.#e),e.size&&(s=this._sortNodes(e))}catch(e){this._onError(e)}return s??[]}}0&&(module.exports={Matcher});
2
2
  //# sourceMappingURL=matcher.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/matcher.js"],
4
- "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isInShadowTree, isNamespaceDeclared,\n isSameOrDescendant, selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, COMBINATOR,\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, NOT_SUPPORTED_ERR,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_ATTR, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\nconst FIND_NEXT = 'next';\nconst FIND_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * }\n * ]\n * #nodes: [\n * Set([node{}, node{}]),\n * Set([node{}, node{}, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: AST leaf\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #bit;\n #cache;\n #node;\n #nodes;\n #root;\n #selector;\n #warn;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { warn } = opt;\n this.#bit = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#warn = !!warn;\n [this.#ast, this.#nodes] = this._prepare(selector);\n this.#root = this._getRoot(node);\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException && e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw e;\n }\n }\n\n /**\n * get root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - root object\n */\n _getRoot(node = this.#node) {\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (isSameOrDescendant(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n document = parent.ownerDocument;\n root = parent;\n }\n break;\n }\n default: {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n const shadow = isInShadowTree(node);\n return {\n document,\n root,\n shadow\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - collection of AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = this.#bit.get(typeA);\n const bitB = this.#bit.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * prepare ast and nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _prepare(selector = this.#selector) {\n const ast = parseSelector(selector);\n const branches = walkAST(ast);\n const tree = [];\n const nodes = [];\n let i = 0;\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid combinator ${item.name}${nextItem.name}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n tree.push({\n branch,\n find: null,\n skip: false\n });\n nodes[i] = new Set();\n i++;\n }\n return [\n tree,\n nodes\n ];\n }\n\n /**\n * collect nth child\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#cache.has(selector)) {\n selectorBranches = this.#cache.get(selector);\n } else {\n selectorBranches = walkAST(selector);\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const arr = [].slice.call(parentNode.children);\n const l = arr.length;\n if (l) {\n const selectorNodes = new Set();\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n for (const refNode of arr) {\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, refNode);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n }\n if (reverse) {\n arr.reverse();\n }\n // :first-child, :last-child, :nth-child(0 of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n if (selectorNodes.has(current)) {\n matched.add(current);\n break;\n }\n }\n } else if (!selector) {\n const current = arr[b - 1];\n matched.add(current);\n }\n }\n // :nth-child()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l && nth >= 0 && nth < l; i++) {\n const current = arr[i];\n if (selectorNodes.size) {\n if (selectorNodes.has(current)) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(current);\n }\n nth += a;\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (node === root && root.nodeType === ELEMENT_NODE && (a + b) === 1) {\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const arr = [].slice.call(parentNode.children);\n const l = arr.length;\n if (l) {\n if (reverse) {\n arr.reverse();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(current);\n break;\n }\n j++;\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (node === root && root.nodeType === ELEMENT_NODE && (a + b) === 1) {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'placeholder':\n case 'selection':\n case 'target-text': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName) {\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n }\n }\n } else {\n const langPart = `(?:-${ALPHA_NUM})*`;\n const regLang = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${langPart}$`, 'i');\n if (regLang.test(astName)) {\n let regExtendedLang;\n if (astName.indexOf('-') > -1) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${langPart}`;\n } else {\n extendedMain = `${langMain}${langPart}`;\n }\n const extendedSub = `-${langSub}${langPart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${langPart}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${langPart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (regExtendedLang.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (regExtendedLang.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n find: FIND_NEXT\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n const l = branches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const leaves = branches[i];\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, { forgive });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n find: FIND_PREV\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n const { document, root } = this.#root;\n const { documentElement } = document;\n const docURL = new URL(document.URL);\n /* regexp */\n const regAnchor = /^a(?:rea)?$/;\n const regFormCtrl =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\n const regFormValidity = /^(?:(?:inpu|selec)t|button|form|textarea)$/;\n const regInteract = /^d(?:etails|ialog)$/;\n const regTypeCheck = /^(?:checkbox|radio)$/;\n const regTypeDate = /^(?:date(?:time-local)?|month|time|week)$/;\n const regTypeRange =\n /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\n const regTypeText = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n const attrURL = new URL(node.getAttribute('href'), docURL.href);\n if (attrURL.origin === docURL.origin &&\n attrURL.pathname === docURL.pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n if (node.id && docURL.hash && docURL.hash === `#${node.id}` &&\n isSameOrDescendant(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n if (docURL.hash) {\n const hash = docURL.hash.replace(/^#/, '');\n let current = document.getElementById(hash);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (node === this.#node) {\n matched.add(node);\n }\n } else if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === document.activeElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (regInteract.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (regInteract.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (regFormCtrl.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parentNode.localName !== 'legend' &&\n parent.hasAttribute('disabled')) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((regFormCtrl.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (regTypeText.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '' &&\n node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length) {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = documentElement;\n }\n const nodes = [].slice.call(parent.getElementsByTagName('input'));\n let checked;\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n const regTypeReset = /^(?:button|reset)$/;\n const regTypeSubmit = /^(?:image|submit)$/;\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n regTypeReset.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n regTypeSubmit.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const iterator = document.createNodeIterator(form, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n regTypeReset.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n regTypeSubmit.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = iterator.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let isMultiple = false;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'datalist') {\n break;\n } else if (parent.localName === 'select') {\n if (parent.multiple || parent.hasAttribute('multiple')) {\n isMultiple = true;\n }\n break;\n }\n parent = parent.parentNode;\n }\n if (isMultiple) {\n if (node.selected || node.hasAttribute('selected')) {\n matched.add(node);\n }\n } else {\n const firstOpt = parentNode.firstElementChild;\n const defaultOpt = new Set();\n let opt = firstOpt;\n while (opt) {\n if (opt.selected || opt.hasAttribute('selected')) {\n defaultOpt.add(opt);\n break;\n }\n opt = opt.nextElementSibling;\n }\n if (!defaultOpt.size) {\n defaultOpt.add(firstOpt);\n }\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'valid': {\n if (regFormValidity.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (regFormValidity.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n regTypeRange.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n regTypeRange.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const nodes = node.childNodes.values();\n let bool;\n for (const refNode of nodes) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // should not match\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'focus-visible':\n case 'fullscreen':\n case 'future':\n case 'hover':\n case 'modal':\n case 'muted':\n case 'past':\n case 'paused':\n case 'picture-in-picture':\n case 'playing':\n case 'seeking':\n case 'stalled':\n case 'user-invalid':\n case 'user-valid':\n case 'volume-locked':\n case '-webkit-autofill': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const { document } = this.#root;\n let caseInsensitive;\n if (document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { id } = node;\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { document } = this.#root;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix) {\n if (isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n }\n return res ?? null;\n };\n\n /**\n * match shadow host pseudo class\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren } = ast;\n const astName = unescapeSelector(ast.name);\n let res;\n if (Array.isArray(astChildren)) {\n const [branch] = walkAST(astChildren[0]);\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n const { shadow } = this.#root;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_ATTR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_CLASS: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_ID: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n const res = this._matchTypeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} [opt] - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...items] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n if (shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_ID: {\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const elm = root.getElementById(leafName);\n if (elm && elm !== baseNode) {\n const bool = isSameOrDescendant(elm, baseNode);\n let node;\n if (bool) {\n node = elm;\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const arr = [].slice.call(baseNode.getElementsByClassName(leafName));\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (document.contentType === 'text/html' && !/[*|]/.test(leafName)) {\n const arr = [].slice.call(baseNode.getElementsByTagName(leafName));\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.find] - 'prev'|'next', which nodes to find\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { find, forgive } = opt;\n let matched = new Set();\n if (find === FIND_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n let refNode = node.nextElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [].slice.call(node.children);\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n matched = nodes;\n } else if (pending) {\n const { document } = this.#root;\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = iterator.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const arr = [];\n let refNode = node.previousElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.previousElementSibling;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - collection of nodes and pending state\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case SELECTOR_ID: {\n let node;\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n node = this.#node;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n node = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n node = root.getElementById(leafName);\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByClassName(leafName));\n arr.push(...a);\n }\n } else {\n arr = [].slice.call(root.getElementsByClassName(leafName));\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (document.contentType !== 'text/html' ||\n /[*|]/.test(leafName)) {\n pending = true;\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const tagName = leafName.toLowerCase();\n const childNodes = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByTagName(leafName));\n arr.push(...a);\n }\n } else {\n arr = [].slice.call(root.getElementsByTagName(leafName));\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (shadow && this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n arr.push(node);\n }\n }\n } else if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * get first twig\n * @param {Array.<object>} branch - AST branch\n * @returns {object} - find direction and twig\n */\n _getFirstTwig(branch) {\n const lastIndex = branch.length - 1;\n const firstTwig = branch[0];\n let find;\n let twig;\n if (lastIndex) {\n const lastTwig = branch[lastIndex];\n const { leaves: [{ type: lastType }] } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT || lastType === SELECTOR_ID) {\n find = FIND_PREV;\n twig = lastTwig;\n } else {\n find = FIND_NEXT;\n twig = firstTwig;\n }\n } else {\n find = FIND_PREV;\n twig = firstTwig;\n }\n return {\n find,\n twig\n };\n }\n\n /**\n * collect nodes\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const { find, twig } = this._getFirstTwig(branch);\n const { nodes, pending } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = find;\n i++;\n }\n if (pendingItems.size) {\n const { document, root } = this.#root;\n const iterator = document.createNodeIterator(root, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n bool = isSameOrDescendant(nextNode, this.#node);\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode);\n if (matched) {\n const index = pendingItem.get('index');\n this.#nodes[index].add(nextNode);\n }\n }\n }\n nextNode = iterator.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const { nodes } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = FIND_PREV;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const posBit = a.compareDocumentPosition(b);\n let res;\n if (posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, find, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const matched = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of matched) {\n if (node !== this.#node) {\n if (isSameOrDescendant(node, this.#node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(matched);\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matched];\n nodes = new Set([...n, ...m]);\n }\n } else if (find === FIND_NEXT) {\n let { combo } = branch[0];\n for (const node of matched) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const twig = {\n combo,\n leaves\n };\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(arr);\n nodes.add(node);\n } else {\n const n = [...nodes];\n nodes = new Set([...n, ...arr]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of matched) {\n let nextNodes = new Set([node]);\n let bool;\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n if (bool && targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType) {\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * matches\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_SELF);\n res = nodes.has(this.#node);\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @returns {?object} - matched node\n */\n closest() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL);\n let node = this.#node;\n while (node) {\n if (nodes.has(node)) {\n res = node;\n break;\n }\n node = node.parentNode;\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @returns {?object} - matched node\n */\n querySelector() {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll() {\n let res;\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n res = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAOO,yBACP,MAAMC,EAAY,OACZC,EAAY,OACZC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OA8Bb,MAAMX,CAAQ,CAEnBY,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GASA,YAAYC,EAAU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C,IAAIW,EAAO,KAAKN,GAChB,KAAOM,GAAM,CACX,GAAIoB,EAAM,IAAIpB,CAAI,EAAG,CACnBgB,EAAMhB,EACN,KACF,CACAA,EAAOA,EAAK,UACd,CACF,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOgB,GAAO,IAChB,CAMA,eAAgB,CACd,IAAIA,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAMhC,CAAY,EACrCgC,EAAM,OAAO,KAAK1B,EAAK,EACnB0B,EAAM,OACR,CAACJ,CAAG,EAAI,KAAK,WAAWI,CAAK,EAEjC,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,IAChB,CAOA,kBAAmB,CACjB,IAAIA,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAMjC,CAAU,EACnCiC,EAAM,OAAO,KAAK1B,EAAK,EACnB0B,EAAM,OACRJ,EAAM,KAAK,WAAWI,CAAK,EAE/B,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,CAAC,CACjB,CACF",
6
- "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "FIND_NEXT", "FIND_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#warn", "selector", "node", "opt", "warn", "e", "document", "root", "parent", "shadow", "leaves", "arr", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "ast", "branches", "tree", "nodes", "i", "items", "branch", "item", "nextItem", "msg", "anb", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "branchesLen", "refNode", "bool", "current", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "id", "astPrefix", "astNodeName", "nodePrefix", "host", "astType", "baseNode", "leafName", "matchItems", "pending", "elm", "comboName", "find", "childNodes", "targetType", "tagName", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "posBit", "skip", "branchLen", "n", "nextCombo"]
4
+ "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isInShadowTree, isNamespaceDeclared,\n isSameOrDescendant, selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, COMBINATOR,\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, NOT_SUPPORTED_ERR,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_ATTR, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\nconst FIND_NEXT = 'next';\nconst FIND_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * }\n * ]\n * #nodes: [\n * Set([node{}, node{}]),\n * Set([node{}, node{}, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: AST leaf\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #bit;\n #cache;\n #node;\n #nodes;\n #root;\n #selector;\n #warn;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { warn } = opt;\n this.#bit = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#warn = !!warn;\n [this.#ast, this.#nodes] = this._prepare(selector);\n this.#root = this._getRoot(node);\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException && e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw e;\n }\n }\n\n /**\n * get root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - root object\n */\n _getRoot(node = this.#node) {\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (isSameOrDescendant(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n document = parent.ownerDocument;\n root = parent;\n }\n break;\n }\n default: {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n const shadow = isInShadowTree(node);\n return {\n document,\n root,\n shadow\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - collection of AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = this.#bit.get(typeA);\n const bitB = this.#bit.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * prepare ast and nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _prepare(selector = this.#selector) {\n const ast = parseSelector(selector);\n const branches = walkAST(ast);\n const tree = [];\n const nodes = [];\n let i = 0;\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid combinator ${item.name}${nextItem.name}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n tree.push({\n branch,\n find: null,\n skip: false\n });\n nodes[i] = new Set();\n i++;\n }\n return [\n tree,\n nodes\n ];\n }\n\n /**\n * collect nth child\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#cache.has(selector)) {\n selectorBranches = this.#cache.get(selector);\n } else {\n selectorBranches = walkAST(selector);\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const arr = [].slice.call(parentNode.children);\n const l = arr.length;\n if (l) {\n const selectorNodes = new Set();\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n for (const refNode of arr) {\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, refNode);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n }\n if (reverse) {\n arr.reverse();\n }\n // :first-child, :last-child, :nth-child(0 of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n if (selectorNodes.has(current)) {\n matched.add(current);\n break;\n }\n }\n } else if (!selector) {\n const current = arr[b - 1];\n matched.add(current);\n }\n }\n // :nth-child()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l && nth >= 0 && nth < l; i++) {\n const current = arr[i];\n if (selectorNodes.size) {\n if (selectorNodes.has(current)) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(current);\n }\n nth += a;\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (node === root && root.nodeType === ELEMENT_NODE && (a + b) === 1) {\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const arr = [].slice.call(parentNode.children);\n const l = arr.length;\n if (l) {\n if (reverse) {\n arr.reverse();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(current);\n break;\n }\n j++;\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (node === root && root.nodeType === ELEMENT_NODE && (a + b) === 1) {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'placeholder':\n case 'selection':\n case 'target-text': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName) {\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n } else {\n const langPart = `(?:-${ALPHA_NUM})*`;\n const regLang = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${langPart}$`, 'i');\n if (regLang.test(astName)) {\n let regExtendedLang;\n if (astName.indexOf('-') > -1) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${langPart}`;\n } else {\n extendedMain = `${langMain}${langPart}`;\n }\n const extendedSub = `-${langSub}${langPart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${langPart}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${langPart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (regExtendedLang.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (regExtendedLang.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n find: FIND_NEXT\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n const l = branches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const leaves = branches[i];\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, { forgive });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n find: FIND_PREV\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n const { document, root } = this.#root;\n const { documentElement } = document;\n const docURL = new URL(document.URL);\n /* regexp */\n const regAnchor = /^a(?:rea)?$/;\n const regFormCtrl =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\n const regFormValidity = /^(?:(?:inpu|selec)t|button|form|textarea)$/;\n const regInteract = /^d(?:etails|ialog)$/;\n const regTypeCheck = /^(?:checkbox|radio)$/;\n const regTypeDate = /^(?:date(?:time-local)?|month|time|week)$/;\n const regTypeRange =\n /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\n const regTypeText = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n const attrURL = new URL(node.getAttribute('href'), docURL.href);\n if (attrURL.origin === docURL.origin &&\n attrURL.pathname === docURL.pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n if (node.id && docURL.hash && docURL.hash === `#${node.id}` &&\n isSameOrDescendant(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n if (docURL.hash) {\n const hash = docURL.hash.replace(/^#/, '');\n let current = document.getElementById(hash);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (node === this.#node) {\n matched.add(node);\n }\n } else if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === document.activeElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (regInteract.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (regInteract.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (regFormCtrl.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parentNode.localName !== 'legend' &&\n parent.hasAttribute('disabled')) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((regFormCtrl.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (regTypeText.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '' &&\n node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length) {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = documentElement;\n }\n const nodes = [].slice.call(parent.getElementsByTagName('input'));\n let checked;\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n const regTypeReset = /^(?:button|reset)$/;\n const regTypeSubmit = /^(?:image|submit)$/;\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n regTypeReset.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n regTypeSubmit.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const iterator = document.createNodeIterator(form, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n regTypeReset.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n regTypeSubmit.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = iterator.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let isMultiple = false;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'datalist') {\n break;\n } else if (parent.localName === 'select') {\n if (parent.multiple || parent.hasAttribute('multiple')) {\n isMultiple = true;\n }\n break;\n }\n parent = parent.parentNode;\n }\n if (isMultiple) {\n if (node.selected || node.hasAttribute('selected')) {\n matched.add(node);\n }\n } else {\n const firstOpt = parentNode.firstElementChild;\n const defaultOpt = new Set();\n let opt = firstOpt;\n while (opt) {\n if (opt.selected || opt.hasAttribute('selected')) {\n defaultOpt.add(opt);\n break;\n }\n opt = opt.nextElementSibling;\n }\n if (!defaultOpt.size) {\n defaultOpt.add(firstOpt);\n }\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'valid': {\n if (regFormValidity.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (regFormValidity.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n regTypeRange.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n regTypeRange.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const nodes = node.childNodes.values();\n let bool;\n for (const refNode of nodes) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // should not match\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'focus-visible':\n case 'fullscreen':\n case 'future':\n case 'hover':\n case 'modal':\n case 'muted':\n case 'past':\n case 'paused':\n case 'picture-in-picture':\n case 'playing':\n case 'seeking':\n case 'stalled':\n case 'user-invalid':\n case 'user-valid':\n case 'volume-locked':\n case '-webkit-autofill': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const { document } = this.#root;\n let caseInsensitive;\n if (document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { id } = node;\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { forgive } = opt;\n const { document } = this.#root;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix) {\n if (isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (!forgive) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n } else if (astPrefix && !forgive && !isNamespaceDeclared(astPrefix, node)) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n return res ?? null;\n };\n\n /**\n * match shadow host pseudo class\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren } = ast;\n const astName = unescapeSelector(ast.name);\n let res;\n if (Array.isArray(astChildren)) {\n const [branch] = walkAST(astChildren[0]);\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n throw new DOMException(`Invalid selector :${astName}`, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n const { shadow } = this.#root;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_ATTR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_CLASS: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_ID: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n const res = this._matchTypeSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} [opt] - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...items] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n if (shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_ID: {\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const elm = root.getElementById(leafName);\n if (elm && elm !== baseNode) {\n const bool = isSameOrDescendant(elm, baseNode);\n let node;\n if (bool) {\n node = elm;\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const arr = [].slice.call(baseNode.getElementsByClassName(leafName));\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (document.contentType === 'text/html' && !/[*|]/.test(leafName)) {\n const arr = [].slice.call(baseNode.getElementsByTagName(leafName));\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.find] - 'prev'|'next', which nodes to find\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { find, forgive } = opt;\n let matched = new Set();\n if (find === FIND_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n let refNode = node.nextElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [].slice.call(node.children);\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n matched = nodes;\n } else if (pending) {\n const { document } = this.#root;\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = iterator.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const arr = [];\n let refNode = node.previousElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.previousElementSibling;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - collection of nodes and pending state\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case SELECTOR_ID: {\n let node;\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n node = this.#node;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n node = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (targetType === TARGET_ALL ||\n root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n node = root.getElementById(leafName);\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByClassName(leafName));\n arr.push(...a);\n }\n } else {\n arr = [].slice.call(root.getElementsByClassName(leafName));\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (document.contentType !== 'text/html' ||\n /[*|]/.test(leafName)) {\n pending = true;\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const tagName = leafName.toLowerCase();\n const childNodes = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByTagName(leafName));\n arr.push(...a);\n }\n } else {\n arr = [].slice.call(root.getElementsByTagName(leafName));\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n // throws\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (shadow && this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n arr.push(node);\n }\n }\n } else if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n }\n if (matchItems && !pending && !nodes.size) {\n const lastLeaf = items[items.length - 1];\n const { type: lastLeafType } = lastLeaf;\n if (lastLeafType === SELECTOR_PSEUDO_CLASS) {\n let node;\n if (root.nodeType === ELEMENT_NODE) {\n node = root;\n } else {\n node = root.firstElementChild;\n }\n // throws if unknown pseudo-class\n this._matchPseudoClassSelector(lastLeaf, node);\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * get first twig\n * @param {Array.<object>} branch - AST branch\n * @returns {object} - find direction and twig\n */\n _getFirstTwig(branch) {\n const lastIndex = branch.length - 1;\n const firstTwig = branch[0];\n let find;\n let twig;\n if (lastIndex) {\n const lastTwig = branch[lastIndex];\n const { leaves: [{ type: lastType }] } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT || lastType === SELECTOR_ID) {\n find = FIND_PREV;\n twig = lastTwig;\n } else {\n find = FIND_NEXT;\n twig = firstTwig;\n }\n } else {\n find = FIND_PREV;\n twig = firstTwig;\n }\n return {\n find,\n twig\n };\n }\n\n /**\n * collect nodes\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const { find, twig } = this._getFirstTwig(branch);\n const { nodes, pending } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = find;\n i++;\n }\n if (pendingItems.size) {\n const { document, root } = this.#root;\n const iterator = document.createNodeIterator(root, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n bool = isSameOrDescendant(nextNode, this.#node);\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode);\n if (matched) {\n const index = pendingItem.get('index');\n this.#nodes[index].add(nextNode);\n }\n }\n }\n nextNode = iterator.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const { nodes } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = FIND_PREV;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const posBit = a.compareDocumentPosition(b);\n let res;\n if (posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, find, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const matched = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of matched) {\n if (node !== this.#node) {\n if (isSameOrDescendant(node, this.#node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(matched);\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matched];\n nodes = new Set([...n, ...m]);\n }\n } else if (find === FIND_NEXT) {\n let { combo } = branch[0];\n for (const node of matched) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const twig = {\n combo,\n leaves\n };\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(arr);\n nodes.add(node);\n } else {\n const n = [...nodes];\n nodes = new Set([...n, ...arr]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of matched) {\n let nextNodes = new Set([node]);\n let bool;\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n if (bool && targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType) {\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * matches\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_SELF);\n res = nodes.has(this.#node);\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @returns {?object} - matched node\n */\n closest() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL);\n let node = this.#node;\n while (node) {\n if (nodes.has(node)) {\n res = node;\n break;\n }\n node = node.parentNode;\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @returns {?object} - matched node\n */\n querySelector() {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll() {\n let res;\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n res = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAOO,yBACP,MAAMC,EAAY,OACZC,EAAY,OACZC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OA8Bb,MAAMX,CAAQ,CAEnBY,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GASA,YAAYC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CACpC,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CACF",
6
+ "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "FIND_NEXT", "FIND_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#warn", "selector", "node", "opt", "warn", "e", "document", "root", "parent", "shadow", "leaves", "arr", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "ast", "branches", "tree", "nodes", "i", "items", "branch", "item", "nextItem", "msg", "anb", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "branchesLen", "refNode", "bool", "current", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "id", "astPrefix", "astNodeName", "nodePrefix", "host", "astType", "baseNode", "leafName", "matchItems", "pending", "elm", "comboName", "find", "childNodes", "targetType", "tagName", "lastLeaf", "lastLeafType", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "posBit", "skip", "branchLen", "n", "nextCombo"]
7
7
  }
package/package.json CHANGED
@@ -61,5 +61,5 @@
61
61
  "update": "npm-run-all -s update-*",
62
62
  "update-wpt": "git submodule update --init --recursive --remote"
63
63
  },
64
- "version": "1.1.9"
64
+ "version": "1.1.11"
65
65
  }
package/src/js/matcher.js CHANGED
@@ -589,13 +589,17 @@ export class Matcher {
589
589
  } else {
590
590
  let parent = node.parentNode;
591
591
  while (parent) {
592
- if (parent.hasAttribute('lang')) {
593
- if (parent.getAttribute('lang')) {
594
- res = node;
592
+ if (parent.nodeType === ELEMENT_NODE) {
593
+ if (parent.hasAttribute('lang')) {
594
+ if (parent.getAttribute('lang')) {
595
+ res = node;
596
+ }
597
+ break;
595
598
  }
599
+ parent = parent.parentNode;
600
+ } else {
596
601
  break;
597
602
  }
598
- parent = parent.parentNode;
599
603
  }
600
604
  }
601
605
  } else {
@@ -631,14 +635,18 @@ export class Matcher {
631
635
  } else {
632
636
  let parent = node.parentNode;
633
637
  while (parent) {
634
- if (parent.hasAttribute('lang')) {
635
- const value = parent.getAttribute('lang');
636
- if (regExtendedLang.test(value)) {
637
- res = node;
638
+ if (parent.nodeType === ELEMENT_NODE) {
639
+ if (parent.hasAttribute('lang')) {
640
+ const value = parent.getAttribute('lang');
641
+ if (regExtendedLang.test(value)) {
642
+ res = node;
643
+ }
644
+ break;
638
645
  }
646
+ parent = parent.parentNode;
647
+ } else {
639
648
  break;
640
649
  }
641
- parent = parent.parentNode;
642
650
  }
643
651
  }
644
652
  }
@@ -1729,11 +1737,14 @@ export class Matcher {
1729
1737
  * match type selector
1730
1738
  * @param {object} ast - AST
1731
1739
  * @param {object} node - Element node
1740
+ * @param {object} [opt] - options
1741
+ * @param {boolean} [opt.forgive] - is forgiving selector list
1732
1742
  * @returns {?object} - matched node
1733
1743
  */
1734
- _matchTypeSelector(ast, node) {
1744
+ _matchTypeSelector(ast, node, opt = {}) {
1735
1745
  const astName = unescapeSelector(ast.name);
1736
1746
  const { localName, prefix } = node;
1747
+ const { forgive } = opt;
1737
1748
  const { document } = this.#root;
1738
1749
  let {
1739
1750
  prefix: astPrefix, tagName: astNodeName
@@ -1766,9 +1777,11 @@ export class Matcher {
1766
1777
  if (astNodeName === '*' || astNodeName === nodeName) {
1767
1778
  res = node;
1768
1779
  }
1769
- } else {
1780
+ } else if (!forgive) {
1770
1781
  throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);
1771
1782
  }
1783
+ } else if (astPrefix && !forgive && !isNamespaceDeclared(astPrefix, node)) {
1784
+ throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);
1772
1785
  }
1773
1786
  return res ?? null;
1774
1787
  };
@@ -1830,6 +1843,8 @@ export class Matcher {
1830
1843
  }
1831
1844
  } else if (astName === 'host') {
1832
1845
  res = node;
1846
+ } else {
1847
+ throw new DOMException(`Invalid selector :${astName}`, SYNTAX_ERR);
1833
1848
  }
1834
1849
  return res ?? null;
1835
1850
  }
@@ -1882,7 +1897,7 @@ export class Matcher {
1882
1897
  }
1883
1898
  case SELECTOR_TYPE:
1884
1899
  default: {
1885
- const res = this._matchTypeSelector(ast, node);
1900
+ const res = this._matchTypeSelector(ast, node, opt);
1886
1901
  if (res) {
1887
1902
  matched.add(res);
1888
1903
  }
@@ -2175,7 +2190,8 @@ export class Matcher {
2175
2190
  }
2176
2191
  refNode = refNode.parentNode;
2177
2192
  }
2178
- } else if (root.nodeType === ELEMENT_NODE) {
2193
+ } else if (targetType === TARGET_ALL ||
2194
+ root.nodeType === ELEMENT_NODE) {
2179
2195
  pending = true;
2180
2196
  } else {
2181
2197
  node = root.getElementById(leafName);
@@ -2290,6 +2306,7 @@ export class Matcher {
2290
2306
  break;
2291
2307
  }
2292
2308
  case SELECTOR_PSEUDO_ELEMENT: {
2309
+ // throws
2293
2310
  this._matchPseudoElementSelector(leafName);
2294
2311
  break;
2295
2312
  }
@@ -2333,6 +2350,20 @@ export class Matcher {
2333
2350
  }
2334
2351
  }
2335
2352
  }
2353
+ if (matchItems && !pending && !nodes.size) {
2354
+ const lastLeaf = items[items.length - 1];
2355
+ const { type: lastLeafType } = lastLeaf;
2356
+ if (lastLeafType === SELECTOR_PSEUDO_CLASS) {
2357
+ let node;
2358
+ if (root.nodeType === ELEMENT_NODE) {
2359
+ node = root;
2360
+ } else {
2361
+ node = root.firstElementChild;
2362
+ }
2363
+ // throws if unknown pseudo-class
2364
+ this._matchPseudoClassSelector(lastLeaf, node);
2365
+ }
2366
+ }
2336
2367
  return {
2337
2368
  nodes,
2338
2369
  pending
@@ -31,7 +31,9 @@ export class Matcher {
31
31
  _matchAttributeSelector(ast: object, node: object): object | null;
32
32
  _matchClassSelector(ast: object, node: object): object | null;
33
33
  _matchIDSelector(ast: object, node: object): object | null;
34
- _matchTypeSelector(ast: object, node: object): object | null;
34
+ _matchTypeSelector(ast: object, node: object, opt?: {
35
+ forgive?: boolean;
36
+ }): object | null;
35
37
  _matchShadowHostPseudoClass(ast: object, node: object): object | null;
36
38
  _matchSelector(ast: object, node: object, opt?: object): Set<object>;
37
39
  _matchLeaves(leaves: Array<object>, node: object, opt?: object): boolean;