@asamuzakjp/dom-selector 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -109,7 +109,7 @@ Returns **[Array][62]<([object][60] \| [undefined][63])>** array of matched n
109
109
  |E\[foo*="bar"\]|✓| |
110
110
  |E\[foo\|="en"\]|✓| |
111
111
  |E:dir(ltr)|✓| |
112
- |E:lang(zh, "\*‑hant")|Partially supported|Quoted keys e.g. `:lang("*-Latn")` fails. It succeeds if escaped e.g. `:lang(\*-Latn)`.|
112
+ |E:lang(en)|Partially supported|Comma-separated list of language codes, e.g. `:lang(en, fr)`, is not yet supported.|
113
113
  |E:any‑link|✓| |
114
114
  |E:link|✓| |
115
115
  |E:visited|✓|Returns `false` or `null` to prevent fingerprinting.|
@@ -1,2 +1,2 @@
1
- var j=Object.create;var L=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var Y=(y,l)=>{for(var e in l)L(y,e,{get:l[e],enumerable:!0})},R=(y,l,e,f)=>{if(l&&typeof l=="object"||typeof l=="function")for(let c of W(l))!G.call(y,c)&&c!==e&&L(y,c,{get:()=>l[c],enumerable:!(f=H(l,c))||f.enumerable});return y};var X=(y,l,e)=>(e=y!=null?j(q(y)):{},R(l||!y||!y.__esModule?L(e,"default",{value:y,enumerable:!0}):e,y)),Z=y=>R(L({},"__esModule",{value:!0}),y);var ee={};Y(ee,{Matcher:()=>Q});module.exports=Z(ee);var D=X(require("is-potential-custom-element-name"),1),k=require("./dom-util.js"),g=require("./parser.js"),b=require("./constant.js");const C="all",A="first",v="lineal",S="self",U=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,O=/^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/,M=/^a(?:rea)?$/,B=/^d(?:etails|ialog)$/,$=/^(?:checkbox|radio)$/,x=/^(?:(?:emai|te|ur)l|number|password|search|text)$/,z=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,F=/^(?:button|reset)$/,V=/^(?:image|submit)$/,I=/^(?:date(?:time-local)?|month|time|week)$/,K=/^(?:(?:ha|i)s|not|where)$/,J=/^nth-(?:last-)?(?:child|of-type)$/;class Q{#s;#r;#a;#e;#l;#t;#o;#c;#i;constructor(l,e,f={}){const{sort:c,warn:n}=f;this.#r=new Map([[b.ATTRIBUTE_SELECTOR,b.BIT_10000],[b.CLASS_SELECTOR,b.BIT_100],[b.ID_SELECTOR,b.BIT_10],[b.PSEUDO_CLASS_SELECTOR,b.BIT_100000],[b.PSEUDO_ELEMENT_SELECTOR,b.BIT_1],[b.TYPE_SELECTOR,b.BIT_1000]]),this.#a=new WeakMap,this.#o=l,this.#e=e,this.#c=!!c,this.#i=!!n,[this.#s,this.#l]=this._prepare(l),this.#t=this._getRoot(e)}_onError(l){if(l instanceof DOMException&&l.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw l}_getRoot(l=this.#e){let e,f;switch(l.nodeType){case b.DOCUMENT_NODE:{e=l,f=l;break}case b.DOCUMENT_FRAGMENT_NODE:{e=l.ownerDocument,f=l;break}case b.ELEMENT_NODE:{if((0,k.isSameOrDescendant)(l))e=l.ownerDocument,f=l.ownerDocument;else{let c=l;for(;c&&c.parentNode;)c=c.parentNode;e=c.ownerDocument,f=c}break}default:throw new TypeError(`Unexpected node ${l.nodeName}`)}return{document:e,root:f}}_sortLeaves(l){const e=[...l];return e.length>1&&e.sort((f,c)=>{const{type:n}=f,{type:d}=c,p=this.#r.get(n),u=this.#r.get(d);let t;return p===u?t=0:p>u?t=1:t=-1,t}),e}_prepare(l=this.#o){const e=(0,g.parseSelector)(l),f=(0,g.walkAST)(e),c=[],n=[];let d=0;for(const[...p]of f){const u=[];let t=p.shift();if(t&&t.type!==b.COMBINATOR){const i=new Set;for(;t;){if(t.type===b.COMBINATOR){const[h]=p;if(h.type===b.COMBINATOR){const r=`Invalid combinator ${t.name}${h.name}`;throw new DOMException(r,b.SYNTAX_ERR)}u.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(p.length)t=p.shift();else{u.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}c.push({branch:u,find:null,skip:!1}),n[d]=new Set,d++}return[c,n]}_collectNthChild(l,e){const{a:f,b:c,reverse:n,selector:d}=l,{parentNode:p}=e,u=new Set;let t;if(d&&(this.#a.has(d)?t=this.#a.get(d):(t=(0,g.walkAST)(d),this.#a.set(d,t))),p){const i=[...p.children],h=i.length;if(h){const r=new Set;if(t){const o=t.length;for(const s of i){let a;for(let m=0;m<o;m++){const N=t[m];if(a=this._matchLeaves(N,s),!a)break}a&&r.add(s)}}if(n&&i.reverse(),f===0){if(c>0&&c<=h){if(r.size)for(let o=0;o<h;o++){const s=i[o];if(r.has(s)){u.add(s);break}}else if(!d){const o=i[c-1];u.add(o)}}}else{let o=0,s=c-1;if(f>0)for(;s<0;)s+=++o*f;if(s>=0&&s<h){let a=f>0?0:c-1;for(let m=0;m<h&&s>=0&&s<h;m++){const N=i[m];r.size?r.has(N)&&(a===s&&(u.add(N),s+=f),f>0?a++:a--):m===s&&(d||u.add(N),s+=f)}}}}}else{const{root:i}=this.#t;if(i.nodeType===b.ELEMENT_NODE&&e===i&&f+c===1)if(t){const h=t.length;let r;for(let o=0;o<h;o++){const s=t[o];if(r=this._matchLeaves(s,e),r)break}r&&u.add(e)}else u.add(e)}return u}_collectNthOfType(l,e){const{a:f,b:c,reverse:n}=l,{localName:d,parentNode:p,prefix:u}=e,t=new Set;if(p){const i=[...p.children],h=i.length;if(h)if(n&&i.reverse(),f===0){if(c>0&&c<=h){let r=0;for(let o=0;o<h;o++){const s=i[o],{localName:a,prefix:m}=s;if(a===d&&m===u){if(r===c-1){t.add(s);break}r++}}}}else{let r=c-1;if(f>0)for(;r<0;)r+=f;if(r>=0&&r<h){let o=f>0?0:c-1;for(let s=0;s<h;s++){const a=i[s],{localName:m,prefix:N}=a;if(m===d&&N===u){if(o===r&&(t.add(a),r+=f),r<0||r>=h)break;f>0?o++:o--}}}}}else{const{root:i}=this.#t;i.nodeType===b.ELEMENT_NODE&&e===i&&f+c===1&&t.add(e)}return t}_matchAnPlusB(l,e,f){const{nth:{a:c,b:n,name:d},selector:p}=l,u=(0,g.unescapeSelector)(d),t=new Map;u?(u==="even"?(t.set("a",2),t.set("b",0)):u==="odd"&&(t.set("a",2),t.set("b",1)),/last/.test(f)&&t.set("reverse",!0)):(typeof c=="string"&&/-?\d+/.test(c)?t.set("a",c*1):t.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?t.set("b",n*1):t.set("b",0),/last/.test(f)&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(f)){p&&t.set("selector",p);const h=Object.fromEntries(t),r=this._collectNthChild(h,e);r.size&&(i=r)}else if(/^nth-(?:last-)?of-type$/.test(f)){const h=Object.fromEntries(t),r=this._collectNthOfType(h,e);r.size&&(i=r)}}return i}_matchPseudoElementSelector(l,e={}){const{forgive:f}=e;switch(l){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"part":case"placeholder":case"selection":case"slotted":case"target-text":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${l}`,b.NOT_SUPPORTED_ERR);break}default:if(l.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${l}`,b.NOT_SUPPORTED_ERR)}else if(!f)throw new DOMException(`Unknown pseudo-element ::${l}`,b.SYNTAX_ERR)}}_matchDirectionPseudoClass(l,e){const f=(0,g.unescapeSelector)(l.name),c=(0,k.getDirectionality)(e);let n;return f===c&&(n=e),n??null}_matchLanguagePseudoClass(l,e){const{lang:f}=e,c=(0,g.unescapeSelector)(l.name);let n;if(c==="")e.getAttribute("lang")===""&&(n=e);else if(c==="*")e.hasAttribute("lang")||(n=e);else if(/[A-Z\d-]+/i.test(c)){const d="(?:-[A-Za-z\\d]+)?";let p;if(/-/.test(c)){const[u,t,...i]=c.split("-"),h=`${u}${d}`,r=`-${t}${d}`,o=i.length;let s="";if(o)for(let a=0;a<o;a++)s+=`-${i[a]}${d}`;p=new RegExp(`^${h}${r}${s}$`,"i")}else p=new RegExp(`^${c}${d}$`,"i");if(f)p.test(f)&&(n=e);else{let u=e;for(;u;){if(p.test(u.lang)){n=e;break}u=u.parentNode}}}return n??null}_matchHasPseudoFunc(l,e){let f;if(Array.isArray(l)&&l.length){const[c]=l,{type:n}=c;let d;n===b.COMBINATOR?d=l.shift():d={name:" ",type:b.COMBINATOR};const p=[];for(;l.length;){const[i]=l,{type:h}=i;if(h===b.COMBINATOR)break;p.push(l.shift())}const u={combo:d,leaves:p},t=this._matchCombinator(u,e,{find:"next"});if(t.size)if(l.length){for(const i of t)if(f=this._matchHasPseudoFunc(Object.assign([],l),i),f)break}else f=!0}return!!f}_matchLogicalPseudoFunc(l,e){const{astName:f="",branches:c=[],selector:n="",twigBranches:d=[]}=l;let p;if(f==="has")if(n.includes(":has("))p=null;else{let u;const t=c.length;for(let i=0;i<t;i++){const h=c[i];if(u=this._matchHasPseudoFunc(Object.assign([],h),e),u)break}u&&(p=e)}else{const u=/^(?:is|where)$/.test(f);let t;const i=d.length;for(let h=0;h<i;h++){const r=d[h],o=r.length-1,{leaves:s}=r[o];if(t=this._matchLeaves(s,e,{forgive:u}),t&&o>0){let a=new Set([e]);for(let m=o-1;m>=0;m--){const N=r[m],w=[];for(const _ of a){const T=this._matchCombinator(N,_,{forgive:u,find:"prev"});T.size&&w.push(...T)}const E=new Set(w);if(E.size)if(m===0){t=!0;break}else a=E;else{t=!1;break}}}if(t)break}f==="not"?t||(p=e):t&&(p=e)}return p??null}_matchPseudoClassSelector(l,e,f={}){const{children:c}=l,{localName:n,parentNode:d}=e,{forgive:p}=f,u=(0,g.unescapeSelector)(l.name);let t=new Set;if(K.test(u)){let i;if(this.#a.has(l))i=this.#a.get(l);else{const r=(0,g.walkAST)(l),o=[],s=[];for(const[...a]of r){for(const E of a){const _=(0,g.generateCSS)(E);o.push(_)}const m=[],N=new Set;let w=a.shift();for(;w;)if(w.type===b.COMBINATOR?(m.push({combo:w,leaves:[...N]}),N.clear()):w&&N.add(w),a.length)w=a.shift();else{m.push({combo:null,leaves:[...N]}),N.clear();break}s.push(m)}i={astName:u,branches:r,twigBranches:s,selector:o.join(",")},this.#a.set(l,i)}const h=this._matchLogicalPseudoFunc(i,e);h&&t.add(h)}else if(Array.isArray(c)){const[i]=c;if(J.test(u)){const h=this._matchAnPlusB(i,e,u);h.size&&(t=h)}else if(u==="dir"){const h=this._matchDirectionPseudoClass(i,e);h&&t.add(h)}else if(u==="lang"){const h=this._matchLanguagePseudoClass(i,e);h&&t.add(h)}else switch(u){case"current":case"nth-col":case"nth-last-col":{if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}()`,b.NOT_SUPPORTED_ERR);break}default:if(!p)throw new DOMException(`Unknown pseudo-class :${u}()`,b.SYNTAX_ERR)}}else{const{document:i,root:h}=this.#t,{documentElement:r}=i,o=new URL(i.URL);switch(u){case"any-link":case"link":{M.test(n)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(M.test(n)&&e.hasAttribute("href")){const s=new URL(e.getAttribute("href"),o.href);s.origin===o.origin&&s.pathname===o.pathname&&t.add(e)}break}case"visited":break;case"target":{(0,k.isSameOrDescendant)(e)&&o.hash&&e.id&&o.hash===`#${e.id}`&&t.add(e);break}case"target-within":{if(o.hash){const s=o.hash.replace(/^#/,"");let a=i.getElementById(s);for(;a;){if(a===e){t.add(e);break}a=a.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?e===this.#e&&t.add(e):e===r&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let s=i.activeElement;for(;s;){if(s===e){t.add(e);break}s=s.parentNode}break}case"open":{B.test(n)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{B.test(n)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(U.test(n)||(0,D.default)(n))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let s=d;for(;s&&s.localName!=="fieldset";)s=s.parentNode;s&&s.hasAttribute("disabled")&&d.localName!=="legend"&&t.add(e)}break}case"enabled":{(U.test(n)||(0,D.default)(n))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(n){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(n){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let s;n==="textarea"?s=e:n==="input"&&(e.hasAttribute("type")?x.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&e.value===""&&t.add(e);break}case"checked":{(n==="input"&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&e.checked||n==="option"&&e.selected)&&t.add(e);break}case"indeterminate":{if(n==="input"&&e.type==="checkbox"&&e.indeterminate||n==="progress"&&!e.hasAttribute("value"))t.add(e);else if(n==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let a=e.parentNode;for(;a&&a.localName!=="form";)a=a.parentNode;a||(a=r);const m=[...a.getElementsByTagName("input")];let N;for(const w of m)if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(N=!!w.checked):w.hasAttribute("name")||(N=!!w.checked),N))break;N||t.add(e)}break}case"default":{if(n==="button"&&!(e.hasAttribute("type")&&F.test(e.getAttribute("type")))||n==="input"&&e.hasAttribute("type")&&V.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const a=i.createNodeIterator(s,b.SHOW_ELEMENT);let m=a.nextNode();for(;m;){const N=m.localName;let w;if(N==="button"?w=!(m.hasAttribute("type")&&F.test(m.getAttribute("type"))):N==="input"&&(w=m.hasAttribute("type")&&V.test(m.getAttribute("type"))),w){m===e&&t.add(e);break}m=a.nextNode()}}}else if(n==="input"&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(n==="option"){let s=!1,a=d;for(;a&&a.localName!=="datalist";){if(a.localName==="select"){(a.multiple||a.hasAttribute("multiple"))&&(s=!0);break}a=a.parentNode}if(s)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const m=d.firstElementChild,N=new Set;let w=m;for(;w;){if(w.selected||w.hasAttribute("selected")){N.add(w);break}w=w.nextElementSibling}N.size||N.add(m),N.has(e)&&t.add(e)}}break}case"valid":{if(O.test(n))e.checkValidity()&&t.add(e);else if(/^fieldset$/.test(n)){const s=i.createNodeIterator(e,b.SHOW_ELEMENT);let a=s.nextNode();a===e&&(a=s.nextNode());let m;for(;a&&!(O.test(a.localName)&&(m=a.checkValidity(),!m));)a=s.nextNode();m&&t.add(e)}break}case"invalid":{if(O.test(n))e.checkValidity()||t.add(e);else if(/^fieldset$/.test(n)){const s=i.createNodeIterator(e,b.SHOW_ELEMENT);let a=s.nextNode();a===e&&(a=s.nextNode());let m;for(;a&&!(O.test(a.localName)&&(m=a.checkValidity(),!m));)a=s.nextNode();m||t.add(e)}break}case"in-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&z.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":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&z.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(n))s=e;else if(n==="input")if(e.hasAttribute("type")){const a=e.getAttribute("type");(x.test(a)||$.test(a)||I.test(a)||a==="file")&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(n))s=e;else if(n==="input")if(e.hasAttribute("type")){const a=e.getAttribute("type");(x.test(a)||$.test(a)||I.test(a)||a==="file")&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===r&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const s=e.childNodes.values();let a;for(const m of s)if(a=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!a)break;a&&t.add(e)}else t.add(e);break}case"first-child":{(d&&e===d.firstElementChild||h.nodeType===b.ELEMENT_NODE&&e===h)&&t.add(e);break}case"last-child":{(d&&e===d.lastElementChild||h.nodeType===b.ELEMENT_NODE&&e===h)&&t.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||h.nodeType===b.ELEMENT_NODE&&e===h)&&t.add(e);break}case"first-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);s&&t.add(s)}else h.nodeType===b.ELEMENT_NODE&&e===h&&t.add(e);break}case"last-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&t.add(s)}else h.nodeType===b.ELEMENT_NODE&&e===h&&t.add(e);break}case"only-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[a]=this._collectNthOfType({a:0,b:1,reverse:!0},e);a===e&&t.add(e)}}else h.nodeType===b.ELEMENT_NODE&&e===h&&t.add(e);break}case"after":case"before":case"first-letter":case"first-line":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${u}`,b.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.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR);break}default:if(u.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR)}else if(!p)throw new DOMException(`Unknown pseudo-class :${u}`,b.SYNTAX_ERR)}}return t}_matchAttributeSelector(l,e){const{flags:f,matcher:c,name:n,value:d}=l;if(typeof f=="string"&&!/^[is]$/i.test(f))throw new DOMException("Invalid attribute selector",b.SYNTAX_ERR);const{attributes:p}=e;let u;if(p&&p.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof f=="string"&&/^s$/i.test(f)?i=!1:i=!0:typeof f=="string"&&/^i$/i.test(f)?i=!0:i=!1;let{name:h}=n;h=(0,g.unescapeSelector)(h),i&&(h=h.toLowerCase());const r=new Set;if(/\|/.test(h)){const{prefix:o,tagName:s}=(0,k.selectorToNodeProps)(h);for(let{name:a,value:m}of p)switch(i&&(a=a.toLowerCase(),m=m.toLowerCase()),o){case"":{s===a&&r.add(m);break}case"*":{/:/.test(a)?a.endsWith(`:${s}`)&&r.add(m):s===a&&r.add(m);break}default:if(/:/.test(a)){const[N,w]=a.split(":");o===N&&s===w&&(0,k.isNamespaceDeclared)(o,e)&&r.add(m)}}}else for(let{name:o,value:s}of p)if(i&&(o=o.toLowerCase(),s=s.toLowerCase()),/:/.test(o)){const[,a]=o.split(":");h===a&&r.add(s)}else h===o&&r.add(s);if(r.size){const{name:o,value:s}=d||{};let a;switch(o?i?a=o.toLowerCase():a=o:s?i?a=s.toLowerCase():a=s:s===""&&(a=s),c){case"=":{typeof a=="string"&&r.has(a)&&(u=e);break}case"~=":{if(a&&typeof a=="string"){for(const m of r)if(new Set(m.split(/\s+/)).has(a)){u=e;break}}break}case"|=":{if(a&&typeof a=="string"){let m;for(const N of r)if(N===a||N.startsWith(`${a}-`)){m=N;break}m&&(u=e)}break}case"^=":{if(a&&typeof a=="string"){let m;for(const N of r)if(N.startsWith(`${a}`)){m=N;break}m&&(u=e)}break}case"$=":{if(a&&typeof a=="string"){let m;for(const N of r)if(N.endsWith(`${a}`)){m=N;break}m&&(u=e)}break}case"*=":{if(a&&typeof a=="string"){let m;for(const N of r)if(N.includes(`${a}`)){m=N;break}m&&(u=e)}break}case null:default:u=e}}}return u??null}_matchClassSelector(l,e){const f=(0,g.unescapeSelector)(l.name);let c;return e.classList.contains(f)&&(c=e),c??null}_matchIDSelector(l,e){const{id:f}=e,c=(0,g.unescapeSelector)(l.name);let n;return c===f&&(n=e),n??null}_matchTypeSelector(l,e){const f=(0,g.unescapeSelector)(l.name),{localName:c,prefix:n}=e,{document:d}=this.#t;let{prefix:p,tagName:u}=(0,k.selectorToNodeProps)(f,e);d.contentType==="text/html"&&(p=p.toLowerCase(),u=u.toLowerCase());let t,i;/:/.test(c)?[t,i]=c.split(":"):(t=n||"",i=c);let h;return p===""&&t===""?e.namespaceURI===null&&(u==="*"||u===i)&&(h=e):p==="*"?(u==="*"||u===i)&&(h=e):p===t&&(0,k.isNamespaceDeclared)(p,e)&&(u==="*"||u===i)&&(h=e),h??null}_matchSelector(l,e,f){const{type:c}=l;let n=new Set;if(e.nodeType===b.ELEMENT_NODE)switch(c){case b.ATTRIBUTE_SELECTOR:{const d=this._matchAttributeSelector(l,e);d&&n.add(d);break}case b.CLASS_SELECTOR:{const d=this._matchClassSelector(l,e);d&&n.add(d);break}case b.ID_SELECTOR:{const d=this._matchIDSelector(l,e);d&&n.add(d);break}case b.PSEUDO_CLASS_SELECTOR:{const d=this._matchPseudoClassSelector(l,e,f);d.size&&(n=d);break}case b.PSEUDO_ELEMENT_SELECTOR:{const d=(0,g.unescapeSelector)(l.name);this._matchPseudoElementSelector(d,f);break}case b.TYPE_SELECTOR:default:{const d=this._matchTypeSelector(l,e);d&&n.add(d)}}return n}_matchLeaves(l,e,f){let c;for(const n of l)if(c=this._matchSelector(n,e,f).has(e),!c)break;return!!c}_findDescendantNodes(l,e){const[f,...c]=l,{type:n}=f,d=(0,g.unescapeSelector)(f.name),p=c.length>0,{document:u,root:t}=this.#t;let i=new Set,h=!1;switch(n){case b.ID_SELECTOR:{if(t.nodeType===b.ELEMENT_NODE)h=!0;else{const r=t.getElementById(d);if(r&&r!==e){const o=(0,k.isSameOrDescendant)(r,e);let s;o&&(s=r),s&&(p?this._matchLeaves(c,s)&&i.add(s):i.add(s))}}break}case b.CLASS_SELECTOR:{const r=[...e.getElementsByClassName(d)];if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r);break}case b.TYPE_SELECTOR:{if(u.contentType!=="text/html"||/[*|]/.test(d))h=!0;else{const r=[...e.getElementsByTagName(d)];if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r)}break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:h=!0}return{nodes:i,pending:h}}_matchCombinator(l,e,f={}){const{combo:c,leaves:n}=l,{name:d}=c,{find:p,forgive:u}=f;let t=new Set;if(p==="next")switch(d){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(n,i)&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(n,i)&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[...e.children];for(const h of i)this._matchLeaves(n,h)&&t.add(h);break}case" ":default:{const{nodes:i,pending:h}=this._findDescendantNodes(n,e);if(i.size)t=i;else if(h){const{document:r}=this.#t,o=r.createNodeIterator(e,b.SHOW_ELEMENT);let s=o.nextNode();for(s===e&&(s=o.nextNode());s;)this._matchLeaves(n,s)&&t.add(s),s=o.nextNode()}}}else switch(d){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(n,i,{forgive:u})&&t.add(i);break}case"~":{const i=[];let h=e.previousElementSibling;for(;h;)this._matchLeaves(n,h,{forgive:u})&&i.push(h),h=h.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(n,i,{forgive:u})&&t.add(i);break}case" ":default:{const i=[];let h=e.parentNode;for(;h;)this._matchLeaves(n,h,{forgive:u})&&i.push(h),h=h.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(l,e){const{leaves:[f,...c]}=l,{type:n}=f,d=(0,g.unescapeSelector)(f.name),p=c.length>0,{document:u,root:t}=this.#t;let i=new Set,h=!1;switch(n){case b.ID_SELECTOR:{let r;if(e===S)this._matchLeaves([f],this.#e)&&(r=this.#e);else if(e===v){let o=this.#e;for(;o;){if(this._matchLeaves([f],o)){r=o;break}o=o.parentNode}}else t.nodeType===b.ELEMENT_NODE?h=!0:r=t.getElementById(d);r&&(p?this._matchLeaves(c,r)&&i.add(r):i.add(r));break}case b.CLASS_SELECTOR:{const r=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this.#e.classList.contains(d)&&r.push(this.#e);else if(e===v){let o=this.#e;for(;o&&o.nodeType===b.ELEMENT_NODE;)o.classList.contains(d)&&r.push(o),o=o.parentNode}else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const o=[...t.children];for(const s of o){s.classList.contains(d)&&r.push(s);const a=[...s.getElementsByClassName(d)];r.push(...a)}}else{const o=[...t.getElementsByClassName(d)];r.push(...o)}if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r);break}case b.TYPE_SELECTOR:{const r=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this._matchLeaves([f],this.#e)&&r.push(this.#e);else if(e===v){let o=this.#e;for(;o&&o.nodeType===b.ELEMENT_NODE;)this._matchLeaves([f],o)&&r.push(o),o=o.parentNode}else if(u.contentType!=="text/html"||/[*|]/.test(d))h=!0;else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const o=d.toLowerCase(),s=[...t.children];for(const a of s){a.localName===o&&r.push(a);const m=[...a.getElementsByTagName(d)];r.push(...m)}}else{const o=[...t.getElementsByTagName(d)];r.push(...o)}if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r);break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:{const r=[];if(e===S)this._matchLeaves([f],this.#e)&&r.push(this.#e);else if(e===v){let o=this.#e;for(;o;)this._matchLeaves([f],o)&&r.push(o),o=o.parentNode}else h=!0;if(r.length)if(p)for(const o of r)this._matchLeaves(c,o)&&i.add(o);else i=new Set(r)}}return{nodes:i,pending:h}}_getFirstTwig(l){const e=l.length-1,f=l[0];let c,n;if(e){const d=l[e],{leaves:[{type:p}]}=d;p===b.PSEUDO_ELEMENT_SELECTOR||p===b.ID_SELECTOR?(c="prev",n=d):(c="next",n=f)}else c="prev",n=f;return{find:c,twig:n}}_collectNodes(l){const e=this.#s.values();if(l===C||l===A){const f=new Set;let c=0;for(const{branch:n}of e){const{find:d,twig:p}=this._getFirstTwig(n),{nodes:u,pending:t}=this._findNodes(p,l);u.size?this.#l[c]=u:t?f.add(new Map([["index",c],["twig",p]])):this.#s[c].skip=!0,this.#s[c].find=d,c++}if(f.size){const{document:n,root:d}=this.#t,p=n.createNodeIterator(d,b.SHOW_ELEMENT);let u=p.nextNode();for(;u;){let t=!1;if(this.#e.nodeType===b.ELEMENT_NODE?t=(0,k.isSameOrDescendant)(u,this.#e):t=!0,t)for(const i of f){const{leaves:h}=i.get("twig");if(this._matchLeaves(h,u)){const o=i.get("index");this.#l[o].add(u)}}u=p.nextNode()}}}else{let f=0;for(const{branch:c}of e){const n=c[c.length-1],{nodes:d}=this._findNodes(n,l);d.size?this.#l[f]=d:this.#s[f].skip=!0,this.#s[f].find="prev",f++}}return[this.#s,this.#l]}_matchNodes(l){const[...e]=this.#s,f=e.length;let c=new Set;for(let n=0;n<f;n++){const{branch:d,find:p,skip:u}=e[n],t=d.length;if(!u&&t){const i=this.#l[n],h=t-1;if(h===0)if((l===C||l===A)&&this.#e.nodeType===b.ELEMENT_NODE){for(const r of i)if(r!==this.#e&&(0,k.isSameOrDescendant)(r,this.#e)&&(c.add(r),l===A))break}else if(l===A){const[r]=[...i];c.add(r)}else{const r=[...c],o=[...i];c=new Set([...r,...o])}else if(p==="next"){let{combo:r}=d[0];for(const o of i){let s=new Set([o]);for(let a=1;a<t;a++){const{combo:m,leaves:N}=d[a],w=[];for(const _ of s){const T={combo:r,leaves:N},P=this._matchCombinator(T,_,{find:p});P.size&&w.push(...P)}const E=new Set(w);if(E.size)if(a===h){if(l===A){const[_]=[...E];c.add(_)}else{const _=[...c],T=[...E];c=new Set([..._,...T])}break}else r=m,s=E;else break}}}else for(const r of i){let o=new Set([r]),s;for(let a=h-1;a>=0;a--){const m=d[a],N=[];for(const E of o){const _=this._matchCombinator(m,E,{find:p});_.size&&N.push(..._)}const w=new Set(N);if(w.size)if(s=!0,a===0){c.add(r);break}else o=w;else{s=!1;break}}if(s&&l!==C)break}}}return c}_find(l){return this._collectNodes(l),this._matchNodes(l)}_sortNodes(l){const e=[...l];return e.length>1&&e.sort((f,c)=>{let n;const d=f.compareDocumentPosition(c);return d&b.DOCUMENT_POSITION_PRECEDING||d&b.DOCUMENT_POSITION_CONTAINS?n=1:n=-1,n}),e}matches(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let l;try{l=this._find(S).has(this.#e)}catch(e){this._onError(e)}return!!l}closest(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let l;try{const e=this._find(v);let f=this.#e;for(;f;){if(e.has(f)){l=f;break}f=f.parentNode}}catch(e){this._onError(e)}return l??null}querySelector(){let l;try{const e=this._find(A);e.delete(this.#e),e.size>1?[l]=this._sortNodes(e):e.size&&([l]=[...e])}catch(e){this._onError(e)}return l??null}querySelectorAll(){const l=[];try{const e=this._find(C);e.delete(this.#e),e.size>1&&this.#c?l.push(...this._sortNodes(e)):e.size&&l.push(...e)}catch(e){this._onError(e)}return l}}0&&(module.exports={Matcher});
1
+ var j=Object.create;var L=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var Y=(y,r)=>{for(var e in r)L(y,e,{get:r[e],enumerable:!0})},R=(y,r,e,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let h of W(r))!G.call(y,h)&&h!==e&&L(y,h,{get:()=>r[h],enumerable:!(c=H(r,h))||c.enumerable});return y};var X=(y,r,e)=>(e=y!=null?j(q(y)):{},R(r||!y||!y.__esModule?L(e,"default",{value:y,enumerable:!0}):e,y)),Z=y=>R(L({},"__esModule",{value:!0}),y);var ee={};Y(ee,{Matcher:()=>Q});module.exports=Z(ee);var D=X(require("is-potential-custom-element-name"),1),k=require("./dom-util.js"),g=require("./parser.js"),b=require("./constant.js");const C="all",T="first",v="lineal",S="self",U=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,$=/^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/,M=/^a(?:rea)?$/,B=/^d(?:etails|ialog)$/,O=/^(?:checkbox|radio)$/,x=/^(?:(?:emai|te|ur)l|number|password|search|text)$/,z=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,F=/^(?:button|reset)$/,V=/^(?:image|submit)$/,I=/^(?:date(?:time-local)?|month|time|week)$/,K=/^(?:(?:ha|i)s|not|where)$/,J=/^nth-(?:last-)?(?:child|of-type)$/;class Q{#s;#r;#a;#e;#l;#t;#o;#c;#i;constructor(r,e,c={}){const{sort:h,warn:n}=c;this.#r=new Map([[b.PSEUDO_ELEMENT_SELECTOR,b.BIT_1],[b.ID_SELECTOR,b.BIT_10],[b.CLASS_SELECTOR,b.BIT_100],[b.TYPE_SELECTOR,b.BIT_1000],[b.ATTRIBUTE_SELECTOR,b.BIT_10000],[b.PSEUDO_CLASS_SELECTOR,b.BIT_100000]]),this.#a=new WeakMap,this.#o=r,this.#e=e,this.#c=!!h,this.#i=!!n,[this.#s,this.#l]=this._prepare(r),this.#t=this._getRoot(e)}_onError(r){if(r instanceof DOMException&&r.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw r}_getRoot(r=this.#e){let e,c;switch(r.nodeType){case b.DOCUMENT_NODE:{e=r,c=r;break}case b.DOCUMENT_FRAGMENT_NODE:{e=r.ownerDocument,c=r;break}case b.ELEMENT_NODE:{if((0,k.isSameOrDescendant)(r))e=r.ownerDocument,c=r.ownerDocument;else{let h=r;for(;h&&h.parentNode;)h=h.parentNode;e=h.ownerDocument,c=h}break}default:throw new TypeError(`Unexpected node ${r.nodeName}`)}return{document:e,root:c}}_sortLeaves(r){const e=[...r];return e.length>1&&e.sort((c,h)=>{const{type:n}=c,{type:d}=h,p=this.#r.get(n),u=this.#r.get(d);let t;return p===u?t=0:p>u?t=1:t=-1,t}),e}_prepare(r=this.#o){const e=(0,g.parseSelector)(r),c=(0,g.walkAST)(e),h=[],n=[];let d=0;for(const[...p]of c){const u=[];let t=p.shift();if(t&&t.type!==b.COMBINATOR){const i=new Set;for(;t;){if(t.type===b.COMBINATOR){const[f]=p;if(f.type===b.COMBINATOR){const o=`Invalid combinator ${t.name}${f.name}`;throw new DOMException(o,b.SYNTAX_ERR)}u.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(p.length)t=p.shift();else{u.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}h.push({branch:u,find:null,skip:!1}),n[d]=new Set,d++}return[h,n]}_collectNthChild(r,e){const{a:c,b:h,reverse:n,selector:d}=r,{parentNode:p}=e,u=new Set;let t;if(d&&(this.#a.has(d)?t=this.#a.get(d):(t=(0,g.walkAST)(d),this.#a.set(d,t))),p){const i=[...p.children],f=i.length;if(f){const o=new Set;if(t){const l=t.length;for(const s of i){let a;for(let m=0;m<l;m++){const N=t[m];if(a=this._matchLeaves(N,s),!a)break}a&&o.add(s)}}if(n&&i.reverse(),c===0){if(h>0&&h<=f){if(o.size)for(let l=0;l<f;l++){const s=i[l];if(o.has(s)){u.add(s);break}}else if(!d){const l=i[h-1];u.add(l)}}}else{let l=h-1;if(c>0)for(;l<0;)l+=c;if(l>=0&&l<f){let s=c>0?0:h-1;for(let a=0;a<f&&l>=0&&l<f;a++){const m=i[a];o.size?o.has(m)&&(s===l&&(u.add(m),l+=c),c>0?s++:s--):a===l&&(d||u.add(m),l+=c)}}}}}else{const{root:i}=this.#t;if(i.nodeType===b.ELEMENT_NODE&&e===i&&c+h===1)if(t){const f=t.length;let o;for(let l=0;l<f;l++){const s=t[l];if(o=this._matchLeaves(s,e),o)break}o&&u.add(e)}else u.add(e)}return u}_collectNthOfType(r,e){const{a:c,b:h,reverse:n}=r,{localName:d,parentNode:p,prefix:u}=e,t=new Set;if(p){const i=[...p.children],f=i.length;if(f)if(n&&i.reverse(),c===0){if(h>0&&h<=f){let o=0;for(let l=0;l<f;l++){const s=i[l],{localName:a,prefix:m}=s;if(a===d&&m===u){if(o===h-1){t.add(s);break}o++}}}}else{let o=h-1;if(c>0)for(;o<0;)o+=c;if(o>=0&&o<f){let l=c>0?0:h-1;for(let s=0;s<f;s++){const a=i[s],{localName:m,prefix:N}=a;if(m===d&&N===u){if(l===o&&(t.add(a),o+=c),o<0||o>=f)break;c>0?l++:l--}}}}}else{const{root:i}=this.#t;i.nodeType===b.ELEMENT_NODE&&e===i&&c+h===1&&t.add(e)}return t}_matchAnPlusB(r,e,c){const{nth:{a:h,b:n,name:d},selector:p}=r,u=(0,g.unescapeSelector)(d),t=new Map;u?(u==="even"?(t.set("a",2),t.set("b",0)):u==="odd"&&(t.set("a",2),t.set("b",1)),/last/.test(c)&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?t.set("b",n*1):t.set("b",0),/last/.test(c)&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){p&&t.set("selector",p);const f=Object.fromEntries(t),o=this._collectNthChild(f,e);o.size&&(i=o)}else if(/^nth-(?:last-)?of-type$/.test(c)){const f=Object.fromEntries(t),o=this._collectNthOfType(f,e);o.size&&(i=o)}}return i}_matchPseudoElementSelector(r,e={}){const{forgive:c}=e;switch(r){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"part":case"placeholder":case"selection":case"slotted":case"target-text":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${r}`,b.NOT_SUPPORTED_ERR);break}default:if(r.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${r}`,b.NOT_SUPPORTED_ERR)}else if(!c)throw new DOMException(`Unknown pseudo-element ::${r}`,b.SYNTAX_ERR)}}_matchDirectionPseudoClass(r,e){const c=(0,g.unescapeSelector)(r.name),h=(0,k.getDirectionality)(e);let n;return c===h&&(n=e),n??null}_matchLanguagePseudoClass(r,e){const c=(0,g.unescapeSelector)(r.name);let h;if(c){if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let n=e.parentNode;for(;n;){if(n.hasAttribute("lang")){n.getAttribute("lang")&&(h=e);break}n=n.parentNode}}else if(/[A-Z\d-]+/i.test(c)){const n="[A-Z\\d]+",d=`(?:-${n})*`;let p;if(/-/.test(c)){const[u,t,...i]=c.split("-");let f;u==="*"?f=`${n}${d}`:f=`${u}${d}`;const o=`-${t}${d}`,l=i.length;let s="";if(l)for(let a=0;a<l;a++)s+=`-${i[a]}${d}`;p=new RegExp(`^${f}${o}${s}$`,"i")}else p=new RegExp(`^${c}${d}$`,"i");if(e.hasAttribute("lang"))p.test(e.getAttribute("lang"))&&(h=e);else{let u=e.parentNode;for(;u;){if(u.hasAttribute("lang")){const t=u.getAttribute("lang");p.test(t)&&(h=e);break}u=u.parentNode}}}}return h??null}_matchHasPseudoFunc(r,e){let c;if(Array.isArray(r)&&r.length){const[h]=r,{type:n}=h;let d;n===b.COMBINATOR?d=r.shift():d={name:" ",type:b.COMBINATOR};const p=[];for(;r.length;){const[i]=r,{type:f}=i;if(f===b.COMBINATOR)break;p.push(r.shift())}const u={combo:d,leaves:p},t=this._matchCombinator(u,e,{find:"next"});if(t.size)if(r.length){for(const i of t)if(c=this._matchHasPseudoFunc(Object.assign([],r),i),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(r,e){const{astName:c="",branches:h=[],selector:n="",twigBranches:d=[]}=r;let p;if(c==="has")if(n.includes(":has("))p=null;else{let u;const t=h.length;for(let i=0;i<t;i++){const f=h[i];if(u=this._matchHasPseudoFunc(Object.assign([],f),e),u)break}u&&(p=e)}else{const u=/^(?:is|where)$/.test(c);let t;const i=d.length;for(let f=0;f<i;f++){const o=d[f],l=o.length-1,{leaves:s}=o[l];if(t=this._matchLeaves(s,e,{forgive:u}),t&&l>0){let a=new Set([e]);for(let m=l-1;m>=0;m--){const N=o[m],w=[];for(const _ of a){const A=this._matchCombinator(N,_,{forgive:u,find:"prev"});A.size&&w.push(...A)}const E=new Set(w);if(E.size)if(m===0){t=!0;break}else a=E;else{t=!1;break}}}if(t)break}c==="not"?t||(p=e):t&&(p=e)}return p??null}_matchPseudoClassSelector(r,e,c={}){const{children:h}=r,{localName:n,parentNode:d}=e,{forgive:p}=c,u=(0,g.unescapeSelector)(r.name);let t=new Set;if(K.test(u)){let i;if(this.#a.has(r))i=this.#a.get(r);else{const o=(0,g.walkAST)(r),l=[],s=[];for(const[...a]of o){for(const E of a){const _=(0,g.generateCSS)(E);l.push(_)}const m=[],N=new Set;let w=a.shift();for(;w;)if(w.type===b.COMBINATOR?(m.push({combo:w,leaves:[...N]}),N.clear()):w&&N.add(w),a.length)w=a.shift();else{m.push({combo:null,leaves:[...N]}),N.clear();break}s.push(m)}i={astName:u,branches:o,twigBranches:s,selector:l.join(",")},this.#a.set(r,i)}const f=this._matchLogicalPseudoFunc(i,e);f&&t.add(f)}else if(Array.isArray(h)){const[i]=h;if(J.test(u)){const f=this._matchAnPlusB(i,e,u);f.size&&(t=f)}else if(u==="dir"){const f=this._matchDirectionPseudoClass(i,e);f&&t.add(f)}else if(u==="lang"){const f=this._matchLanguagePseudoClass(i,e);f&&t.add(f)}else switch(u){case"current":case"nth-col":case"nth-last-col":{if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}()`,b.NOT_SUPPORTED_ERR);break}default:if(!p)throw new DOMException(`Unknown pseudo-class :${u}()`,b.SYNTAX_ERR)}}else{const{document:i,root:f}=this.#t,{documentElement:o}=i,l=new URL(i.URL);switch(u){case"any-link":case"link":{M.test(n)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(M.test(n)&&e.hasAttribute("href")){const s=new URL(e.getAttribute("href"),l.href);s.origin===l.origin&&s.pathname===l.pathname&&t.add(e)}break}case"visited":break;case"target":{(0,k.isSameOrDescendant)(e)&&l.hash&&e.id&&l.hash===`#${e.id}`&&t.add(e);break}case"target-within":{if(l.hash){const s=l.hash.replace(/^#/,"");let a=i.getElementById(s);for(;a;){if(a===e){t.add(e);break}a=a.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?e===this.#e&&t.add(e):e===o&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let s=i.activeElement;for(;s;){if(s===e){t.add(e);break}s=s.parentNode}break}case"open":{B.test(n)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{B.test(n)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(U.test(n)||(0,D.default)(n))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let s=d;for(;s&&s.localName!=="fieldset";)s=s.parentNode;s&&s.hasAttribute("disabled")&&d.localName!=="legend"&&t.add(e)}break}case"enabled":{(U.test(n)||(0,D.default)(n))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(n){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(n){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let s;n==="textarea"?s=e:n==="input"&&(e.hasAttribute("type")?x.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&e.value===""&&t.add(e);break}case"checked":{(n==="input"&&e.hasAttribute("type")&&O.test(e.getAttribute("type"))&&e.checked||n==="option"&&e.selected)&&t.add(e);break}case"indeterminate":{if(n==="input"&&e.type==="checkbox"&&e.indeterminate||n==="progress"&&!e.hasAttribute("value"))t.add(e);else if(n==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let a=e.parentNode;for(;a&&a.localName!=="form";)a=a.parentNode;a||(a=o);const m=[...a.getElementsByTagName("input")];let N;for(const w of m)if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(N=!!w.checked):w.hasAttribute("name")||(N=!!w.checked),N))break;N||t.add(e)}break}case"default":{if(n==="button"&&!(e.hasAttribute("type")&&F.test(e.getAttribute("type")))||n==="input"&&e.hasAttribute("type")&&V.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const a=i.createNodeIterator(s,b.SHOW_ELEMENT);let m=a.nextNode();for(;m;){const N=m.localName;let w;if(N==="button"?w=!(m.hasAttribute("type")&&F.test(m.getAttribute("type"))):N==="input"&&(w=m.hasAttribute("type")&&V.test(m.getAttribute("type"))),w){m===e&&t.add(e);break}m=a.nextNode()}}}else if(n==="input"&&e.hasAttribute("type")&&O.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(n==="option"){let s=!1,a=d;for(;a&&a.localName!=="datalist";){if(a.localName==="select"){(a.multiple||a.hasAttribute("multiple"))&&(s=!0);break}a=a.parentNode}if(s)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const m=d.firstElementChild,N=new Set;let w=m;for(;w;){if(w.selected||w.hasAttribute("selected")){N.add(w);break}w=w.nextElementSibling}N.size||N.add(m),N.has(e)&&t.add(e)}}break}case"valid":{if($.test(n))e.checkValidity()&&t.add(e);else if(/^fieldset$/.test(n)){const s=i.createNodeIterator(e,b.SHOW_ELEMENT);let a=s.nextNode();a===e&&(a=s.nextNode());let m;for(;a&&!($.test(a.localName)&&(m=a.checkValidity(),!m));)a=s.nextNode();m&&t.add(e)}break}case"invalid":{if($.test(n))e.checkValidity()||t.add(e);else if(/^fieldset$/.test(n)){const s=i.createNodeIterator(e,b.SHOW_ELEMENT);let a=s.nextNode();a===e&&(a=s.nextNode());let m;for(;a&&!($.test(a.localName)&&(m=a.checkValidity(),!m));)a=s.nextNode();m||t.add(e)}break}case"in-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&z.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":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&z.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(n))s=e;else if(n==="input")if(e.hasAttribute("type")){const a=e.getAttribute("type");(x.test(a)||O.test(a)||I.test(a)||a==="file")&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(n))s=e;else if(n==="input")if(e.hasAttribute("type")){const a=e.getAttribute("type");(x.test(a)||O.test(a)||I.test(a)||a==="file")&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===o&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const s=e.childNodes.values();let a;for(const m of s)if(a=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!a)break;a&&t.add(e)}else t.add(e);break}case"first-child":{(d&&e===d.firstElementChild||f.nodeType===b.ELEMENT_NODE&&e===f)&&t.add(e);break}case"last-child":{(d&&e===d.lastElementChild||f.nodeType===b.ELEMENT_NODE&&e===f)&&t.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||f.nodeType===b.ELEMENT_NODE&&e===f)&&t.add(e);break}case"first-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);s&&t.add(s)}else f.nodeType===b.ELEMENT_NODE&&e===f&&t.add(e);break}case"last-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&t.add(s)}else f.nodeType===b.ELEMENT_NODE&&e===f&&t.add(e);break}case"only-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[a]=this._collectNthOfType({a:0,b:1,reverse:!0},e);a===e&&t.add(e)}}else f.nodeType===b.ELEMENT_NODE&&e===f&&t.add(e);break}case"after":case"before":case"first-letter":case"first-line":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${u}`,b.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.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR);break}default:if(u.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR)}else if(!p)throw new DOMException(`Unknown pseudo-class :${u}`,b.SYNTAX_ERR)}}return t}_matchAttributeSelector(r,e){const{flags:c,matcher:h,name:n,value:d}=r;if(typeof c=="string"&&!/^[is]$/i.test(c))throw new DOMException("Invalid attribute selector",b.SYNTAX_ERR);const{attributes:p}=e;let u;if(p&&p.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{name:f}=n;f=(0,g.unescapeSelector)(f),i&&(f=f.toLowerCase());const o=new Set;if(/\|/.test(f)){const{prefix:l,tagName:s}=(0,k.selectorToNodeProps)(f);for(let{name:a,value:m}of p)switch(i&&(a=a.toLowerCase(),m=m.toLowerCase()),l){case"":{s===a&&o.add(m);break}case"*":{/:/.test(a)?a.endsWith(`:${s}`)&&o.add(m):s===a&&o.add(m);break}default:if(/:/.test(a)){const[N,w]=a.split(":");l===N&&s===w&&(0,k.isNamespaceDeclared)(l,e)&&o.add(m)}}}else for(let{name:l,value:s}of p)if(i&&(l=l.toLowerCase(),s=s.toLowerCase()),/:/.test(l)){const[a,m]=l.split(":");if(a==="xml"&&m==="lang")continue;f===m&&o.add(s)}else f===l&&o.add(s);if(o.size){const{name:l,value:s}=d||{};let a;switch(l?i?a=l.toLowerCase():a=l:s?i?a=s.toLowerCase():a=s:s===""&&(a=s),h){case"=":{typeof a=="string"&&o.has(a)&&(u=e);break}case"~=":{if(a&&typeof a=="string"){for(const m of o)if(new Set(m.split(/\s+/)).has(a)){u=e;break}}break}case"|=":{if(a&&typeof a=="string"){let m;for(const N of o)if(N===a||N.startsWith(`${a}-`)){m=N;break}m&&(u=e)}break}case"^=":{if(a&&typeof a=="string"){let m;for(const N of o)if(N.startsWith(`${a}`)){m=N;break}m&&(u=e)}break}case"$=":{if(a&&typeof a=="string"){let m;for(const N of o)if(N.endsWith(`${a}`)){m=N;break}m&&(u=e)}break}case"*=":{if(a&&typeof a=="string"){let m;for(const N of o)if(N.includes(`${a}`)){m=N;break}m&&(u=e)}break}case null:default:u=e}}}return u??null}_matchClassSelector(r,e){const c=(0,g.unescapeSelector)(r.name);let h;return e.classList.contains(c)&&(h=e),h??null}_matchIDSelector(r,e){const{id:c}=e,h=(0,g.unescapeSelector)(r.name);let n;return h===c&&(n=e),n??null}_matchTypeSelector(r,e){const c=(0,g.unescapeSelector)(r.name),{localName:h,prefix:n}=e,{document:d}=this.#t;let{prefix:p,tagName:u}=(0,k.selectorToNodeProps)(c,e);d.contentType==="text/html"&&(p=p.toLowerCase(),u=u.toLowerCase());let t,i;/:/.test(h)?[t,i]=h.split(":"):(t=n||"",i=h);let f;return p===""&&t===""?e.namespaceURI===null&&(u==="*"||u===i)&&(f=e):p==="*"?(u==="*"||u===i)&&(f=e):p===t&&(0,k.isNamespaceDeclared)(p,e)&&(u==="*"||u===i)&&(f=e),f??null}_matchSelector(r,e,c){const{type:h}=r;let n=new Set;if(e.nodeType===b.ELEMENT_NODE)switch(h){case b.ATTRIBUTE_SELECTOR:{const d=this._matchAttributeSelector(r,e);d&&n.add(d);break}case b.CLASS_SELECTOR:{const d=this._matchClassSelector(r,e);d&&n.add(d);break}case b.ID_SELECTOR:{const d=this._matchIDSelector(r,e);d&&n.add(d);break}case b.PSEUDO_CLASS_SELECTOR:{const d=this._matchPseudoClassSelector(r,e,c);d.size&&(n=d);break}case b.PSEUDO_ELEMENT_SELECTOR:{const d=(0,g.unescapeSelector)(r.name);this._matchPseudoElementSelector(d,c);break}case b.TYPE_SELECTOR:default:{const d=this._matchTypeSelector(r,e);d&&n.add(d)}}return n}_matchLeaves(r,e,c){let h;for(const n of r)if(h=this._matchSelector(n,e,c).has(e),!h)break;return!!h}_findDescendantNodes(r,e){const[c,...h]=r,{type:n}=c,d=(0,g.unescapeSelector)(c.name),p=h.length>0,{document:u,root:t}=this.#t;let i=new Set,f=!1;switch(n){case b.ID_SELECTOR:{if(t.nodeType===b.ELEMENT_NODE)f=!0;else{const o=t.getElementById(d);if(o&&o!==e){const l=(0,k.isSameOrDescendant)(o,e);let s;l&&(s=o),s&&(p?this._matchLeaves(h,s)&&i.add(s):i.add(s))}}break}case b.CLASS_SELECTOR:{const o=[...e.getElementsByClassName(d)];if(o.length)if(p)for(const l of o)this._matchLeaves(h,l)&&i.add(l);else i=new Set(o);break}case b.TYPE_SELECTOR:{if(u.contentType!=="text/html"||/[*|]/.test(d))f=!0;else{const o=[...e.getElementsByTagName(d)];if(o.length)if(p)for(const l of o)this._matchLeaves(h,l)&&i.add(l);else i=new Set(o)}break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:f=!0}return{nodes:i,pending:f}}_matchCombinator(r,e,c={}){const{combo:h,leaves:n}=r,{name:d}=h,{find:p,forgive:u}=c;let t=new Set;if(p==="next")switch(d){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(n,i)&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(n,i)&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[...e.children];for(const f of i)this._matchLeaves(n,f)&&t.add(f);break}case" ":default:{const{nodes:i,pending:f}=this._findDescendantNodes(n,e);if(i.size)t=i;else if(f){const{document:o}=this.#t,l=o.createNodeIterator(e,b.SHOW_ELEMENT);let s=l.nextNode();for(s===e&&(s=l.nextNode());s;)this._matchLeaves(n,s)&&t.add(s),s=l.nextNode()}}}else switch(d){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(n,i,{forgive:u})&&t.add(i);break}case"~":{const i=[];let f=e.previousElementSibling;for(;f;)this._matchLeaves(n,f,{forgive:u})&&i.push(f),f=f.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(n,i,{forgive:u})&&t.add(i);break}case" ":default:{const i=[];let f=e.parentNode;for(;f;)this._matchLeaves(n,f,{forgive:u})&&i.push(f),f=f.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(r,e){const{leaves:[c,...h]}=r,{type:n}=c,d=(0,g.unescapeSelector)(c.name),p=h.length>0,{document:u,root:t}=this.#t;let i=new Set,f=!1;switch(n){case b.ID_SELECTOR:{let o;if(e===S)this._matchLeaves([c],this.#e)&&(o=this.#e);else if(e===v){let l=this.#e;for(;l;){if(this._matchLeaves([c],l)){o=l;break}l=l.parentNode}}else t.nodeType===b.ELEMENT_NODE?f=!0:o=t.getElementById(d);o&&(p?this._matchLeaves(h,o)&&i.add(o):i.add(o));break}case b.CLASS_SELECTOR:{const o=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this.#e.classList.contains(d)&&o.push(this.#e);else if(e===v){let l=this.#e;for(;l&&l.nodeType===b.ELEMENT_NODE;)l.classList.contains(d)&&o.push(l),l=l.parentNode}else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const l=[...t.children];for(const s of l){s.classList.contains(d)&&o.push(s);const a=[...s.getElementsByClassName(d)];o.push(...a)}}else{const l=[...t.getElementsByClassName(d)];o.push(...l)}if(o.length)if(p)for(const l of o)this._matchLeaves(h,l)&&i.add(l);else i=new Set(o);break}case b.TYPE_SELECTOR:{const o=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this._matchLeaves([c],this.#e)&&o.push(this.#e);else if(e===v){let l=this.#e;for(;l&&l.nodeType===b.ELEMENT_NODE;)this._matchLeaves([c],l)&&o.push(l),l=l.parentNode}else if(u.contentType!=="text/html"||/[*|]/.test(d))f=!0;else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const l=d.toLowerCase(),s=[...t.children];for(const a of s){a.localName===l&&o.push(a);const m=[...a.getElementsByTagName(d)];o.push(...m)}}else{const l=[...t.getElementsByTagName(d)];o.push(...l)}if(o.length)if(p)for(const l of o)this._matchLeaves(h,l)&&i.add(l);else i=new Set(o);break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:{const o=[];if(e===S)this._matchLeaves([c],this.#e)&&o.push(this.#e);else if(e===v){let l=this.#e;for(;l;)this._matchLeaves([c],l)&&o.push(l),l=l.parentNode}else f=!0;if(o.length)if(p)for(const l of o)this._matchLeaves(h,l)&&i.add(l);else i=new Set(o)}}return{nodes:i,pending:f}}_getFirstTwig(r){const e=r.length-1,c=r[0];let h,n;if(e){const d=r[e],{leaves:[{type:p}]}=d;p===b.PSEUDO_ELEMENT_SELECTOR||p===b.ID_SELECTOR?(h="prev",n=d):(h="next",n=c)}else h="prev",n=c;return{find:h,twig:n}}_collectNodes(r){const e=this.#s.values();if(r===C||r===T){const c=new Set;let h=0;for(const{branch:n}of e){const{find:d,twig:p}=this._getFirstTwig(n),{nodes:u,pending:t}=this._findNodes(p,r);u.size?this.#l[h]=u:t?c.add(new Map([["index",h],["twig",p]])):this.#s[h].skip=!0,this.#s[h].find=d,h++}if(c.size){const{document:n,root:d}=this.#t,p=n.createNodeIterator(d,b.SHOW_ELEMENT);let u=p.nextNode();for(;u;){let t=!1;if(this.#e.nodeType===b.ELEMENT_NODE?t=(0,k.isSameOrDescendant)(u,this.#e):t=!0,t)for(const i of c){const{leaves:f}=i.get("twig");if(this._matchLeaves(f,u)){const l=i.get("index");this.#l[l].add(u)}}u=p.nextNode()}}}else{let c=0;for(const{branch:h}of e){const n=h[h.length-1],{nodes:d}=this._findNodes(n,r);d.size?this.#l[c]=d:this.#s[c].skip=!0,this.#s[c].find="prev",c++}}return[this.#s,this.#l]}_matchNodes(r){const[...e]=this.#s,c=e.length;let h=new Set;for(let n=0;n<c;n++){const{branch:d,find:p,skip:u}=e[n],t=d.length;if(!u&&t){const i=this.#l[n],f=t-1;if(f===0)if((r===C||r===T)&&this.#e.nodeType===b.ELEMENT_NODE){for(const o of i)if(o!==this.#e&&(0,k.isSameOrDescendant)(o,this.#e)&&(h.add(o),r===T))break}else if(r===T){const[o]=[...i];h.add(o)}else{const o=[...h],l=[...i];h=new Set([...o,...l])}else if(p==="next"){let{combo:o}=d[0];for(const l of i){let s=new Set([l]);for(let a=1;a<t;a++){const{combo:m,leaves:N}=d[a],w=[];for(const _ of s){const A={combo:o,leaves:N},P=this._matchCombinator(A,_,{find:p});P.size&&w.push(...P)}const E=new Set(w);if(E.size)if(a===f){if(r===T){const[_]=[...E];h.add(_)}else{const _=[...h],A=[...E];h=new Set([..._,...A])}break}else o=m,s=E;else break}}}else for(const o of i){let l=new Set([o]),s;for(let a=f-1;a>=0;a--){const m=d[a],N=[];for(const E of l){const _=this._matchCombinator(m,E,{find:p});_.size&&N.push(..._)}const w=new Set(N);if(w.size)if(s=!0,a===0){h.add(o);break}else l=w;else{s=!1;break}}if(s&&r!==C)break}}}return h}_find(r){return this._collectNodes(r),this._matchNodes(r)}_sortNodes(r){const e=[...r];return e.length>1&&e.sort((c,h)=>{let n;const d=c.compareDocumentPosition(h);return d&b.DOCUMENT_POSITION_PRECEDING||d&b.DOCUMENT_POSITION_CONTAINS?n=1:n=-1,n}),e}matches(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let r;try{r=this._find(S).has(this.#e)}catch(e){this._onError(e)}return!!r}closest(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let r;try{const e=this._find(v);let c=this.#e;for(;c;){if(e.has(c)){r=c;break}c=c.parentNode}}catch(e){this._onError(e)}return r??null}querySelector(){let r;try{const e=this._find(T);e.delete(this.#e),e.size>1?[r]=this._sortNodes(e):e.size&&([r]=[...e])}catch(e){this._onError(e)}return r??null}querySelectorAll(){const r=[];try{const e=this._find(C);e.delete(this.#e),e.size>1&&this.#c?r.push(...this._sortNodes(e)):e.size&&r.push(...e)}catch(e){this._onError(e)}return r}}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, isNamespaceDeclared, isSameOrDescendant,\n selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ATTRIBUTE_SELECTOR, BIT_1, BIT_10, BIT_100, BIT_1000, BIT_10000, BIT_100000,\n CLASS_SELECTOR, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,\n DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n ID_SELECTOR, NOT_SUPPORTED_ERR, PSEUDO_CLASS_SELECTOR,\n PSEUDO_ELEMENT_SELECTOR, SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE, TYPE_SELECTOR\n} from './constant.js';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/* regexp */\nconst FORM_PARTS =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\nconst FORM_VALIDITY = /^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/;\nconst HTML_ANCHOR = /^a(?:rea)?$/;\nconst HTML_INTERACT = /^d(?:etails|ialog)$/;\nconst INPUT_CHECK = /^(?:checkbox|radio)$/;\nconst INPUT_EDIT = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\nconst INPUT_RANGE = /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\nconst INPUT_RESET = /^(?:button|reset)$/;\nconst INPUT_SUBMIT = /^(?:image|submit)$/;\nconst INPUT_TIME = /^(?:date(?:time-local)?|month|time|week)$/;\nconst PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;\nconst PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * skip: boolean\n * },\n * {\n * branch: branch[],\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 #sort;\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.sort] - sort results of querySelectorAll()\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { sort, warn } = opt;\n this.#bit = new Map([\n [ATTRIBUTE_SELECTOR, BIT_10000],\n [CLASS_SELECTOR, BIT_100],\n [ID_SELECTOR, BIT_10],\n [PSEUDO_CLASS_SELECTOR, BIT_100000],\n [PSEUDO_ELEMENT_SELECTOR, BIT_1],\n [TYPE_SELECTOR, BIT_1000]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#sort = !!sort;\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 return {\n document,\n root\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - 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>>} - list and matrix\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 {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 = [...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 n = 0;\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += (++n * 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 (root.nodeType === ELEMENT_NODE && node === root && (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 {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 = [...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 (root.nodeType === ELEMENT_NODE && node === root && (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 {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 (/last/.test(nthName)) {\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 (/last/.test(nthName)) {\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 'part':\n case 'placeholder':\n case 'selection':\n case 'slotted':\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 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 { lang } = node;\n const astName = unescapeSelector(ast.name);\n let res;\n // TBD: what about xml:lang?\n if (astName === '') {\n if (node.getAttribute('lang') === '') {\n res = node;\n }\n } else if (astName === '*') {\n if (!node.hasAttribute('lang')) {\n res = node;\n }\n } else if (/[A-Z\\d-]+/i.test(astName)) {\n const codePart = '(?:-[A-Za-z\\\\d]+)?';\n let reg;\n if (/-/.test(astName)) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n const extendedMain = `${langMain}${codePart}`;\n const extendedSub = `-${langSub}${codePart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${codePart}`;\n }\n }\n reg = new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n reg = new RegExp(`^${astName}${codePart}$`, 'i');\n }\n if (lang) {\n if (reg.test(lang)) {\n res = node;\n }\n } else {\n let target = node;\n while (target) {\n if (reg.test(target.lang)) {\n res = node;\n break;\n }\n target = target.parentNode;\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: '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 let bool;\n const l = branches.length;\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 let bool;\n const l = twigBranches.length;\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, {\n forgive\n });\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: 'prev'\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = matchedNodes;\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 {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 (PSEUDO_FUNC.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 (PSEUDO_NTH.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 switch (astName) {\n case 'any-link':\n case 'link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (HTML_ANCHOR.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 (isSameOrDescendant(node) && docURL.hash &&\n node.id && docURL.hash === `#${node.id}`) {\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 (HTML_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (HTML_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (FORM_PARTS.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 && parent.hasAttribute('disabled') &&\n parentNode.localName !== 'legend') {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((FORM_PARTS.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 ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.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 ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.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 (INPUT_EDIT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length &&\n node.value === '') {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n node.checked) ||\n (localName === 'option' && node.selected)) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((localName === 'input' && node.type === 'checkbox' &&\n node.indeterminate) ||\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 = [...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 // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n INPUT_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n INPUT_SUBMIT.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 INPUT_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n INPUT_SUBMIT.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 INPUT_CHECK.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 (FORM_VALIDITY.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\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 (FORM_VALIDITY.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 (FORM_VALIDITY.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\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 (FORM_VALIDITY.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 INPUT_RANGE.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 INPUT_RANGE.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 (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\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 (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\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 (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\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 (root.nodeType === ELEMENT_NODE && node === root) {\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 (root.nodeType === ELEMENT_NODE && node === root) {\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 (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\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 throw new DOMException('Invalid attribute selector', 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 { name: astAttrName } = astName;\n astAttrName = unescapeSelector(astAttrName);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (/\\|/.test(astAttrName)) {\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 (/:/.test(itemName)) {\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 (/:/.test(itemName)) {\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 (/:/.test(itemName)) {\n const [, itemNameLocalName] = itemName.split(':');\n 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 { id } = node;\n const astName = unescapeSelector(ast.name);\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 (/:/.test(localName)) {\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 isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\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 {object} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type } = ast;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (type) {\n case ATTRIBUTE_SELECTOR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case CLASS_SELECTOR: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case ID_SELECTOR: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case PSEUDO_CLASS_SELECTOR: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n const astName = unescapeSelector(ast.name);\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case TYPE_SELECTOR:\n default: {\n const res = this._matchTypeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\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} - result\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 } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\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 CLASS_SELECTOR: {\n const arr = [...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 TYPE_SELECTOR: {\n if (document.contentType !== 'text/html' || /[*|]/.test(leafName)) {\n pending = true;\n } else {\n const arr = [...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 }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\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 {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 === 'next') {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\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);\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [...node.children];\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode);\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);\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, {\n forgive\n });\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, {\n forgive\n });\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, {\n forgive\n });\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, {\n forgive\n });\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} - result\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 } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\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 CLASS_SELECTOR: {\n const 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 = [...root.children];\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [...node.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByClassName(leafName)];\n arr.push(...a);\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 TYPE_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this.#node.nodeType === ELEMENT_NODE &&\n 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 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 = [...root.children];\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [...node.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByTagName(leafName)];\n arr.push(...a);\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 PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n 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} - result\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 === PSEUDO_ELEMENT_SELECTOR || lastType === ID_SELECTOR) {\n find = 'prev';\n twig = lastTwig;\n } else {\n find = 'next';\n twig = firstTwig;\n }\n } else {\n 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>>} - matrix\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 = 'prev';\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {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] = [...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 === '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 const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = [...matchedNodes];\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matchedNodes];\n nodes = new Set([...n, ...m]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = matchedNodes;\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 const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = matchedNodes;\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 {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 * sort nodes\n * @param {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 let res;\n const posBit = a.compareDocumentPosition(b);\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 * 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 > 1) {\n [res] = this._sortNodes(nodes);\n } else if (nodes.size) {\n [res] = [...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 const res = [];\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size > 1 && this.#sort) {\n res.push(...this._sortNodes(nodes));\n } else if (nodes.size) {\n res.push(...nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res;\n }\n};\n"],
5
- "mappings": "6iBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,IAAA,eAAAC,EAAAH,IAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAMO,yBACP,MAAMC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OAGdC,EACJ,iEACIC,EAAgB,qDAChBC,EAAc,cACdC,EAAgB,sBAChBC,EAAc,uBACdC,EAAa,oDACbC,EAAc,2DACdC,EAAc,qBACdC,EAAe,qBACfC,EAAa,4CACbC,EAAc,4BACdC,EAAa,oCA4BZ,MAAMrB,CAAQ,CAEnBsB,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAUA,YAAYC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CACpC,KAAM,CAAE,KAAAC,EAAM,KAAAC,C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,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,EACf,CAACJ,CAAG,EAAI,KAAK,WAAWI,CAAK,EACpBA,EAAM,OACf,CAACJ,CAAG,EAAI,CAAC,GAAGI,CAAK,EAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,IAChB,CAOA,kBAAmB,CACjB,MAAMA,EAAM,CAAC,EACb,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM9C,CAAU,EACnC8C,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,GAAK,KAAKvB,GACzBmB,EAAI,KAAK,GAAG,KAAK,WAAWI,CAAK,CAAC,EACzBA,EAAM,MACfJ,EAAI,KAAK,GAAGI,CAAK,CAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,CACT,CACF",
6
- "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "FORM_PARTS", "FORM_VALIDITY", "HTML_ANCHOR", "HTML_INTERACT", "INPUT_CHECK", "INPUT_EDIT", "INPUT_RANGE", "INPUT_RESET", "INPUT_SUBMIT", "INPUT_TIME", "PSEUDO_FUNC", "PSEUDO_NTH", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#sort", "#warn", "selector", "node", "opt", "sort", "warn", "e", "document", "root", "parent", "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", "n", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "lang", "codePart", "reg", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "target", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "matchedNodes", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "value", "id", "astPrefix", "astNodeName", "nodePrefix", "type", "baseNode", "leafName", "matchItems", "pending", "elm", "comboName", "find", "childNodes", "targetType", "tagName", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "skip", "branchLen", "nextCombo", "posBit"]
4
+ "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isNamespaceDeclared, isSameOrDescendant,\n selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ATTRIBUTE_SELECTOR, BIT_1, BIT_10, BIT_100, BIT_1000, BIT_10000, BIT_100000,\n CLASS_SELECTOR, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,\n DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n ID_SELECTOR, NOT_SUPPORTED_ERR, PSEUDO_CLASS_SELECTOR,\n PSEUDO_ELEMENT_SELECTOR, SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE, TYPE_SELECTOR\n} from './constant.js';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/* regexp */\nconst FORM_PARTS =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\nconst FORM_VALIDITY = /^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/;\nconst HTML_ANCHOR = /^a(?:rea)?$/;\nconst HTML_INTERACT = /^d(?:etails|ialog)$/;\nconst INPUT_CHECK = /^(?:checkbox|radio)$/;\nconst INPUT_EDIT = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\nconst INPUT_RANGE = /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\nconst INPUT_RESET = /^(?:button|reset)$/;\nconst INPUT_SUBMIT = /^(?:image|submit)$/;\nconst INPUT_TIME = /^(?:date(?:time-local)?|month|time|week)$/;\nconst PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;\nconst PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * skip: boolean\n * },\n * {\n * branch: branch[],\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 #sort;\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.sort] - sort results of querySelectorAll()\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { sort, warn } = opt;\n this.#bit = new Map([\n [PSEUDO_ELEMENT_SELECTOR, BIT_1],\n [ID_SELECTOR, BIT_10],\n [CLASS_SELECTOR, BIT_100],\n [TYPE_SELECTOR, BIT_1000],\n [ATTRIBUTE_SELECTOR, BIT_10000],\n [PSEUDO_CLASS_SELECTOR, BIT_100000]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#sort = !!sort;\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 return {\n document,\n root\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - 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 {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 = [...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 (root.nodeType === ELEMENT_NODE && node === root && (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 {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 = [...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 (root.nodeType === ELEMENT_NODE && node === root && (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 {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 (/last/.test(nthName)) {\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 (/last/.test(nthName)) {\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 'part':\n case 'placeholder':\n case 'selection':\n case 'slotted':\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 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 if (/[A-Z\\d-]+/i.test(astName)) {\n const alphaNum = '[A-Z\\\\d]+';\n const codePart = `(?:-${alphaNum})*`;\n let reg;\n if (/-/.test(astName)) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${alphaNum}${codePart}`;\n } else {\n extendedMain = `${langMain}${codePart}`;\n }\n const extendedSub = `-${langSub}${codePart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${codePart}`;\n }\n }\n reg =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n reg = new RegExp(`^${astName}${codePart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (reg.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 (reg.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\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: '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 let bool;\n const l = branches.length;\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 let bool;\n const l = twigBranches.length;\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, {\n forgive\n });\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: 'prev'\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = matchedNodes;\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 {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 (PSEUDO_FUNC.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 (PSEUDO_NTH.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 switch (astName) {\n case 'any-link':\n case 'link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (HTML_ANCHOR.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 (isSameOrDescendant(node) && docURL.hash &&\n node.id && docURL.hash === `#${node.id}`) {\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 (HTML_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (HTML_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (FORM_PARTS.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 && parent.hasAttribute('disabled') &&\n parentNode.localName !== 'legend') {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((FORM_PARTS.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 ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.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 ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.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 (INPUT_EDIT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length &&\n node.value === '') {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n node.checked) ||\n (localName === 'option' && node.selected)) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((localName === 'input' && node.type === 'checkbox' &&\n node.indeterminate) ||\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 = [...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 // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n INPUT_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n INPUT_SUBMIT.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 INPUT_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n INPUT_SUBMIT.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 INPUT_CHECK.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 (FORM_VALIDITY.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\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 (FORM_VALIDITY.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 (FORM_VALIDITY.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\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 (FORM_VALIDITY.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 INPUT_RANGE.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 INPUT_RANGE.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 (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\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 (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\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 (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\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 (root.nodeType === ELEMENT_NODE && node === root) {\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 (root.nodeType === ELEMENT_NODE && node === root) {\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 (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\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 throw new DOMException('Invalid attribute selector', 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 { name: astAttrName } = astName;\n astAttrName = unescapeSelector(astAttrName);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (/\\|/.test(astAttrName)) {\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 (/:/.test(itemName)) {\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 (/:/.test(itemName)) {\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 (/:/.test(itemName)) {\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 { id } = node;\n const astName = unescapeSelector(ast.name);\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 (/:/.test(localName)) {\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 isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\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 {object} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type } = ast;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (type) {\n case ATTRIBUTE_SELECTOR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case CLASS_SELECTOR: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case ID_SELECTOR: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case PSEUDO_CLASS_SELECTOR: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n const astName = unescapeSelector(ast.name);\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case TYPE_SELECTOR:\n default: {\n const res = this._matchTypeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\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} - result\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 } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\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 CLASS_SELECTOR: {\n const arr = [...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 TYPE_SELECTOR: {\n if (document.contentType !== 'text/html' || /[*|]/.test(leafName)) {\n pending = true;\n } else {\n const arr = [...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 }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\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 {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 === 'next') {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\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);\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [...node.children];\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode);\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);\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, {\n forgive\n });\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, {\n forgive\n });\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, {\n forgive\n });\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, {\n forgive\n });\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 } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\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 CLASS_SELECTOR: {\n const 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 = [...root.children];\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [...node.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByClassName(leafName)];\n arr.push(...a);\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 TYPE_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this.#node.nodeType === ELEMENT_NODE &&\n 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 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 = [...root.children];\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [...node.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByTagName(leafName)];\n arr.push(...a);\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 PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n 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 === PSEUDO_ELEMENT_SELECTOR || lastType === ID_SELECTOR) {\n find = 'prev';\n twig = lastTwig;\n } else {\n find = 'next';\n twig = firstTwig;\n }\n } else {\n 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 = 'prev';\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {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] = [...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 === '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 const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = [...matchedNodes];\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matchedNodes];\n nodes = new Set([...n, ...m]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = matchedNodes;\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 const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = matchedNodes;\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 {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 * sort nodes\n * @param {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 let res;\n const posBit = a.compareDocumentPosition(b);\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 * 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 > 1) {\n [res] = this._sortNodes(nodes);\n } else if (nodes.size) {\n [res] = [...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 const res = [];\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size > 1 && this.#sort) {\n res.push(...this._sortNodes(nodes));\n } else if (nodes.size) {\n res.push(...nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res;\n }\n};\n"],
5
+ "mappings": "6iBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,IAAA,eAAAC,EAAAH,IAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAMO,yBACP,MAAMC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OAGdC,EACJ,iEACIC,EAAgB,qDAChBC,EAAc,cACdC,EAAgB,sBAChBC,EAAc,uBACdC,EAAa,oDACbC,EAAc,2DACdC,EAAc,qBACdC,EAAe,qBACfC,EAAa,4CACbC,EAAc,4BACdC,EAAa,oCA4BZ,MAAMrB,CAAQ,CAEnBsB,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAUA,YAAYC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CACpC,KAAM,CAAE,KAAAC,EAAM,KAAAC,CAAK,EAAIF,EACvB,KAAKV,GAAO,IAAI,IAAI,CAClB,CAAC,0BAAyB,OAAK,EAC/B,CAAC,cAAa,QAAM,EACpB,CAAC,iBAAgB,SAAO,EACxB,CAAC,gBAAe,UAAQ,EACxB,CAAC,qBAAoB,WAAS,EAC9B,CAAC,wBAAuB,YAAU,CACpC,CAAC,EACD,KAAKC,GAAS,IAAI,QAClB,KAAKI,GAAYG,EACjB,KAAKN,GAAQO,EACb,KAAKH,GAAQ,CAAC,CAACK,EACf,KAAKJ,GAAQ,CAAC,CAACK,EACf,CAAC,KAAKb,GAAM,KAAKI,EAAM,EAAI,KAAK,SAASK,CAAQ,EACjD,KAAKJ,GAAQ,KAAK,SAASK,CAAI,CACjC,CAQA,SAASI,EAAG,CACV,GAAIA,aAAa,cAAgBA,EAAE,OAAS,oBACtC,KAAKN,IACP,QAAQ,KAAKM,EAAE,OAAO,MAGxB,OAAMA,CAEV,CAOA,SAASJ,EAAO,KA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b,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM9C,CAAU,EACnC8C,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,GAAK,KAAKvB,GACzBmB,EAAI,KAAK,GAAG,KAAK,WAAWI,CAAK,CAAC,EACzBA,EAAM,MACfJ,EAAI,KAAK,GAAGI,CAAK,CAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,CACT,CACF",
6
+ "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "FORM_PARTS", "FORM_VALIDITY", "HTML_ANCHOR", "HTML_INTERACT", "INPUT_CHECK", "INPUT_EDIT", "INPUT_RANGE", "INPUT_RESET", "INPUT_SUBMIT", "INPUT_TIME", "PSEUDO_FUNC", "PSEUDO_NTH", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#sort", "#warn", "selector", "node", "opt", "sort", "warn", "e", "document", "root", "parent", "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", "alphaNum", "codePart", "reg", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "matchedNodes", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "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", "type", "baseNode", "leafName", "matchItems", "pending", "elm", "comboName", "find", "childNodes", "targetType", "tagName", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "skip", "branchLen", "n", "nextCombo", "posBit"]
7
7
  }
@@ -1,3 +1,3 @@
1
- var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var $=(n,e)=>{for(var s in e)u(n,s,{get:e[s],enumerable:!0})},D=(n,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of w(e))!O.call(n,t)&&t!==s&&u(n,t,{get:()=>e[t],enumerable:!(o=m(e,t))||o.enumerable});return n};var P=n=>D(u({},"__esModule",{value:!0}),n);var A={};$(A,{generateCSS:()=>S.generate,parseSelector:()=>F,preprocess:()=>x,unescapeSelector:()=>b,walkAST:()=>_});module.exports=P(A);var c=require("css-tree"),r=require("./constant.js"),S=require("css-tree");const C=parseInt("10000",16),y=16,E=2,T=/^([\da-f]{1,6}\s?)/i,g=/^(?:(?:ha|i)s|not|where)$/,I=/^[\n\r\f]/,b=(n="")=>{if(typeof n=="string"&&n.indexOf("\\",0)>=0){const e=n.split("\\"),s=e.length;for(let o=1;o<s;o++){let t=e[o];if(o===s-1&&t==="")t="\uFFFD";else{const l=T.exec(t);if(l){const[,i]=l;let a;try{const p=parseInt("D800",16),h=parseInt("DFFF",16),d=parseInt(i,16);d===0||d>=p&&d<=h?a="\uFFFD":a=String.fromCodePoint(d)}catch{a="\uFFFD"}let f="";t.length>i.length&&(f=t.substring(i.length)),t=`${a}${f}`}else I.test(t)&&(t="\\"+t)}e[o]=t}n=e.join("")}return n},x=(...n)=>{if(!n.length)throw new TypeError("1 argument required, but only 0 present.");let[e]=n;if(typeof e=="string"){let s=0;for(;s>=0&&(s=e.indexOf("#",s),!(s<0));){const o=e.substring(0,s+1);let t=e.substring(s+1);const l=t.codePointAt(0);if(l>=C){const i=`\\${l.toString(y)} `;t.length===E?t=i:t=`${i}${t.substring(E)}`}e=`${o}${t}`,s++}e=e.replace(/\f|\r\n?/g,`
2
- `).replace(/[\0\uD800-\uDFFF]|\\$/g,"\uFFFD")}else if(e==null)e=Object.prototype.toString.call(e).slice(r.TYPE_FROM,r.TYPE_TO).toLowerCase();else throw new DOMException(`Invalid selector ${e}`,r.SYNTAX_ERR);return e},F=n=>{if(n=x(n),/^$|^\s*>|,\s*$/.test(n))throw new DOMException(`Invalid selector ${n}`,r.SYNTAX_ERR);let e;try{const s=(0,c.parse)(n,{context:"selectorList",parseCustomProperty:!0});e=(0,c.toPlainObject)(s)}catch(s){if(s.message==='"]" is expected'&&!n.endsWith("]"))e=F(`${n}]`);else if(s.message==='")" is expected'&&!n.endsWith(")"))e=F(`${n})`);else throw new DOMException(s.message,r.SYNTAX_ERR)}return e},_=(n={})=>{const e=new Set;let s;return(0,c.walk)(n,{enter:t=>{t.type===r.SELECTOR?e.add(t.children):t.type===r.PSEUDO_CLASS_SELECTOR&&g.test(t.name)&&(s=!0)}}),s&&(0,c.findAll)(n,(t,l,i)=>{if(t.type===r.PSEUDO_CLASS_SELECTOR&&g.test(t.name)&&i){const a=i.filter(f=>{const{name:p,type:h}=f;return h===r.PSEUDO_CLASS_SELECTOR&&g.test(p)});for(const{children:f}of a)for(const{children:p}of f)for(const{children:h}of p)e.has(h)&&e.delete(h)}}),[...e]};0&&(module.exports={generateCSS,parseSelector,preprocess,unescapeSelector,walkAST});
1
+ var u=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var D=(n,e)=>{for(var s in e)u(n,s,{get:e[s],enumerable:!0})},P=(n,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of $(e))!w.call(n,t)&&t!==s&&u(n,t,{get:()=>e[t],enumerable:!(r=O(e,t))||r.enumerable});return n};var C=n=>P(u({},"__esModule",{value:!0}),n);var L={};D(L,{generateCSS:()=>S.generate,parseSelector:()=>d,preprocess:()=>m,unescapeSelector:()=>_,walkAST:()=>b});module.exports=C(L);var a=require("css-tree"),i=require("./constant.js"),S=require("css-tree");const T=parseInt("10000",16),y=16,F=2,I=/^([\da-f]{1,6}\s?)/i,E=/^(?:(?:ha|i)s|not|where)$/,x=/(:lang\(\s*("[A-Z\d\-*]+")\s*\))/i,A=/^[\n\r\f]/,_=(n="")=>{if(typeof n=="string"&&n.indexOf("\\",0)>=0){const e=n.split("\\"),s=e.length;for(let r=1;r<s;r++){let t=e[r];if(r===s-1&&t==="")t="\uFFFD";else{const c=I.exec(t);if(c){const[,o]=c;let l;try{const f=parseInt("D800",16),g=parseInt("DFFF",16),h=parseInt(o,16);h===0||h>=f&&h<=g?l="\uFFFD":l=String.fromCodePoint(h)}catch{l="\uFFFD"}let p="";t.length>o.length&&(p=t.substring(o.length)),t=`${l}${p}`}else A.test(t)&&(t="\\"+t)}e[r]=t}n=e.join("")}return n},m=(...n)=>{if(!n.length)throw new TypeError("1 argument required, but only 0 present.");let[e]=n;if(typeof e=="string"){let s=0;for(;s>=0&&(s=e.indexOf("#",s),!(s<0));){const r=e.substring(0,s+1);let t=e.substring(s+1);const c=t.codePointAt(0);if(c>=T){const o=`\\${c.toString(y)} `;t.length===F?t=o:t=`${o}${t.substring(F)}`}e=`${r}${t}`,s++}e=e.replace(/\f|\r\n?/g,`
2
+ `).replace(/[\0\uD800-\uDFFF]|\\$/g,"\uFFFD")}else if(e==null)e=Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO).toLowerCase();else throw new DOMException(`Invalid selector ${e}`,i.SYNTAX_ERR);return e},d=n=>{if(n=m(n),/^$|^\s*>|,\s*$/.test(n))throw new DOMException(`Invalid selector ${n}`,i.SYNTAX_ERR);let e;try{const s=(0,a.parse)(n,{context:"selectorList",parseCustomProperty:!0});e=(0,a.toPlainObject)(s)}catch(s){if(s.message==="Identifier is expected"&&x.test(n)){const[,r,t]=x.exec(n),c=t.replace(/\s*\*/g,"\\*").replace(/^"/,"").replace(/"$/,""),o=r.replace(t,c);e=d(n.replace(r,o))}else if(s.message==='"]" is expected'&&!n.endsWith("]"))e=d(`${n}]`);else if(s.message==='")" is expected'&&!n.endsWith(")"))e=d(`${n})`);else throw new DOMException(s.message,i.SYNTAX_ERR)}return e},b=(n={})=>{const e=new Set;let s;return(0,a.walk)(n,{enter:t=>{t.type===i.SELECTOR?e.add(t.children):t.type===i.PSEUDO_CLASS_SELECTOR&&E.test(t.name)&&(s=!0)}}),s&&(0,a.findAll)(n,(t,c,o)=>{if(t.type===i.PSEUDO_CLASS_SELECTOR&&E.test(t.name)&&o){const l=o.filter(p=>{const{name:f,type:g}=p;return g===i.PSEUDO_CLASS_SELECTOR&&E.test(f)});for(const{children:p}of l)for(const{children:f}of p)for(const{children:g}of f)e.has(g)&&e.delete(g)}}),[...e]};0&&(module.exports={generateCSS,parseSelector,preprocess,unescapeSelector,walkAST});
3
3
  //# sourceMappingURL=parser.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/parser.js"],
4
- "sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\n\n/* constants */\nimport {\n PSEUDO_CLASS_SELECTOR, SELECTOR, SYNTAX_ERR, TYPE_FROM, TYPE_TO\n} from './constant.js';\nconst CODE_POINT_UNIT = parseInt('10000', 16);\nconst HEX = 16;\nconst PAIR = 2;\n\n/* regexp */\nconst HEX_CAPTURE = /^([\\da-f]{1,6}\\s?)/i;\nconst PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;\nconst WHITESPACE = /^[\\n\\r\\f]/;\n\n/**\n * unescape selector\n * @param {string} selector - CSS selector\n * @returns {?string} - unescaped selector\n */\nexport const unescapeSelector = (selector = '') => {\n if (typeof selector === 'string' && selector.indexOf('\\\\', 0) >= 0) {\n const arr = selector.split('\\\\');\n const l = arr.length;\n for (let i = 1; i < l; i++) {\n let item = arr[i];\n if (i === l - 1 && item === '') {\n item = '\\uFFFD';\n } else {\n const hexExists = HEX_CAPTURE.exec(item);\n if (hexExists) {\n const [, hex] = hexExists;\n let str;\n try {\n const low = parseInt('D800', 16);\n const high = parseInt('DFFF', 16);\n const deci = parseInt(hex, 16);\n if (deci === 0 || (deci >= low && deci <= high)) {\n str = '\\uFFFD';\n } else {\n str = String.fromCodePoint(deci);\n }\n } catch (e) {\n str = '\\uFFFD';\n }\n let postStr = '';\n if (item.length > hex.length) {\n postStr = item.substring(hex.length);\n }\n item = `${str}${postStr}`;\n } else if (WHITESPACE.test(item)) {\n item = '\\\\' + item;\n }\n }\n arr[i] = item;\n }\n selector = arr.join('');\n }\n return selector;\n};\n\n/**\n * preprocess\n * @see https://drafts.csswg.org/css-syntax-3/#input-preprocessing\n * @param {...*} args - arguments\n * @returns {string} - filtered selector string\n */\nexport const preprocess = (...args) => {\n if (!args.length) {\n throw new TypeError('1 argument required, but only 0 present.');\n }\n let [selector] = args;\n if (typeof selector === 'string') {\n let index = 0;\n while (index >= 0) {\n index = selector.indexOf('#', index);\n if (index < 0) {\n break;\n }\n const preHash = selector.substring(0, index + 1);\n let postHash = selector.substring(index + 1);\n const codePoint = postHash.codePointAt(0);\n if (codePoint >= CODE_POINT_UNIT) {\n const str = `\\\\${codePoint.toString(HEX)} `;\n if (postHash.length === PAIR) {\n postHash = str;\n } else {\n postHash = `${str}${postHash.substring(PAIR)}`;\n }\n }\n selector = `${preHash}${postHash}`;\n index++;\n }\n selector = selector.replace(/\\f|\\r\\n?/g, '\\n')\n .replace(/[\\0\\uD800-\\uDFFF]|\\\\$/g, '\\uFFFD');\n } else if (selector === undefined || selector === null) {\n selector = Object.prototype.toString.call(selector)\n .slice(TYPE_FROM, TYPE_TO).toLowerCase();\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return selector;\n};\n\n/**\n * create AST from CSS selector\n * @param {string} selector - CSS selector\n * @returns {object} - AST\n */\nexport const parseSelector = selector => {\n selector = preprocess(selector);\n // invalid selectors\n if (/^$|^\\s*>|,\\s*$/.test(selector)) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n let res;\n try {\n const ast = parse(selector, {\n context: 'selectorList',\n parseCustomProperty: true\n });\n res = toPlainObject(ast);\n } catch (e) {\n if (e.message === '\"]\" is expected' && !selector.endsWith(']')) {\n res = parseSelector(`${selector}]`);\n } else if (e.message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(e.message, SYNTAX_ERR);\n }\n }\n return res;\n};\n\n/**\n * walk AST\n * @param {object} ast - AST\n * @returns {Array.<object|undefined>} - collection of AST branches\n */\nexport const walkAST = (ast = {}) => {\n const branches = new Set();\n let hasPseudoFunc;\n const opt = {\n enter: node => {\n if (node.type === SELECTOR) {\n branches.add(node.children);\n } else if (node.type === PSEUDO_CLASS_SELECTOR &&\n PSEUDO_FUNC.test(node.name)) {\n hasPseudoFunc = true;\n }\n }\n };\n walk(ast, opt);\n if (hasPseudoFunc) {\n findAll(ast, (node, item, list) => {\n if (node.type === PSEUDO_CLASS_SELECTOR && PSEUDO_FUNC.test(node.name) &&\n list) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n return type === PSEUDO_CLASS_SELECTOR && PSEUDO_FUNC.test(name);\n });\n for (const { children } of itemList) {\n // SelectorList\n for (const { children: grandChildren } of children) {\n // Selector\n for (const { children: greatGrandChildren } of grandChildren) {\n if (branches.has(greatGrandChildren)) {\n branches.delete(greatGrandChildren);\n }\n }\n }\n }\n }\n });\n }\n return [...branches];\n};\n\n/* export */\nexport { generate as generateCSS } from 'css-tree';\n"],
5
- "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA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AG,EAClEiB,EAAM9B,EAAc,GAAGa,CAAQ,GAAG,MAElC,OAAM,IAAI,aAAamB,EAAE,QAAS,YAAU,CAEhD,CACA,OAAOF,CACT,EAOa3B,EAAU,CAAC4B,EAAM,CAAC,IAAM,CACnC,MAAME,EAAW,IAAI,IACrB,IAAIC,EAWJ,iBAAKH,EAVO,CACV,MAAOI,GAAQ,CACTA,EAAK,OAAS,WAChBF,EAAS,IAAIE,EAAK,QAAQ,EACjBA,EAAK,OAAS,yBACdxB,EAAY,KAAKwB,EAAK,IAAI,IACnCD,EAAgB,GAEpB,CACF,CACa,EACTA,MACF,WAAQH,EAAK,CAACI,EAAMlB,EAAMmB,IAAS,CACjC,GAAID,EAAK,OAAS,yBAAyBxB,EAAY,KAAKwB,EAAK,IAAI,GACjEC,EAAM,CACR,MAAMC,EAAWD,EAAK,OAAOpB,GAAK,CAChC,KAAM,CAAE,KAAAsB,EAAM,KAAAC,CAAK,EAAIvB,EACvB,OAAOuB,IAAS,yBAAyB5B,EAAY,KAAK2B,CAAI,CAChE,CAAC,EACD,SAAW,CAAE,SAAAE,CAAS,IAAKH,EAEzB,SAAW,CAAE,SAAUI,CAAc,IAAKD,EAExC,SAAW,CAAE,SAAUE,CAAmB,IAAKD,EACzCR,EAAS,IAAIS,CAAkB,GACjCT,EAAS,OAAOS,CAAkB,CAK5C,CACF,CAAC,EAEI,CAAC,GAAGT,CAAQ,CACrB",
6
- "names": ["parser_exports", "__export", "parseSelector", "preprocess", "unescapeSelector", "walkAST", "__toCommonJS", "import_css_tree", "import_constant", "CODE_POINT_UNIT", "HEX", "PAIR", "HEX_CAPTURE", "PSEUDO_FUNC", "WHITESPACE", "selector", "arr", "l", "i", "item", "hexExists", "hex", "str", "low", "high", "deci", "postStr", "args", "index", "preHash", "postHash", "codePoint", "res", "ast", "e", "branches", "hasPseudoFunc", "node", "list", "itemList", "name", "type", "children", "grandChildren", "greatGrandChildren"]
4
+ "sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\n\n/* constants */\nimport {\n PSEUDO_CLASS_SELECTOR, SELECTOR, SYNTAX_ERR, TYPE_FROM, TYPE_TO\n} from './constant.js';\nconst CODE_POINT_UNIT = parseInt('10000', 16);\nconst HEX = 16;\nconst PAIR = 2;\n\n/* regexp */\nconst HEX_CAPTURE = /^([\\da-f]{1,6}\\s?)/i;\nconst PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;\nconst QUOTED_LANG = /(:lang\\(\\s*(\"[A-Z\\d\\-*]+\")\\s*\\))/i;\nconst WHITESPACE = /^[\\n\\r\\f]/;\n\n/**\n * unescape selector\n * @param {string} selector - CSS selector\n * @returns {?string} - unescaped selector\n */\nexport const unescapeSelector = (selector = '') => {\n if (typeof selector === 'string' && selector.indexOf('\\\\', 0) >= 0) {\n const arr = selector.split('\\\\');\n const l = arr.length;\n for (let i = 1; i < l; i++) {\n let item = arr[i];\n if (i === l - 1 && item === '') {\n item = '\\uFFFD';\n } else {\n const hexExists = HEX_CAPTURE.exec(item);\n if (hexExists) {\n const [, hex] = hexExists;\n let str;\n try {\n const low = parseInt('D800', 16);\n const high = parseInt('DFFF', 16);\n const deci = parseInt(hex, 16);\n if (deci === 0 || (deci >= low && deci <= high)) {\n str = '\\uFFFD';\n } else {\n str = String.fromCodePoint(deci);\n }\n } catch (e) {\n str = '\\uFFFD';\n }\n let postStr = '';\n if (item.length > hex.length) {\n postStr = item.substring(hex.length);\n }\n item = `${str}${postStr}`;\n } else if (WHITESPACE.test(item)) {\n item = '\\\\' + item;\n }\n }\n arr[i] = item;\n }\n selector = arr.join('');\n }\n return selector;\n};\n\n/**\n * preprocess\n * @see https://drafts.csswg.org/css-syntax-3/#input-preprocessing\n * @param {...*} args - arguments\n * @returns {string} - filtered selector string\n */\nexport const preprocess = (...args) => {\n if (!args.length) {\n throw new TypeError('1 argument required, but only 0 present.');\n }\n let [selector] = args;\n if (typeof selector === 'string') {\n let index = 0;\n while (index >= 0) {\n index = selector.indexOf('#', index);\n if (index < 0) {\n break;\n }\n const preHash = selector.substring(0, index + 1);\n let postHash = selector.substring(index + 1);\n const codePoint = postHash.codePointAt(0);\n if (codePoint >= CODE_POINT_UNIT) {\n const str = `\\\\${codePoint.toString(HEX)} `;\n if (postHash.length === PAIR) {\n postHash = str;\n } else {\n postHash = `${str}${postHash.substring(PAIR)}`;\n }\n }\n selector = `${preHash}${postHash}`;\n index++;\n }\n selector = selector.replace(/\\f|\\r\\n?/g, '\\n')\n .replace(/[\\0\\uD800-\\uDFFF]|\\\\$/g, '\\uFFFD');\n } else if (selector === undefined || selector === null) {\n selector = Object.prototype.toString.call(selector)\n .slice(TYPE_FROM, TYPE_TO).toLowerCase();\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return selector;\n};\n\n/**\n * create AST from CSS selector\n * @param {string} selector - CSS selector\n * @returns {object} - AST\n */\nexport const parseSelector = selector => {\n selector = preprocess(selector);\n // invalid selectors\n if (/^$|^\\s*>|,\\s*$/.test(selector)) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n let res;\n try {\n const ast = parse(selector, {\n context: 'selectorList',\n parseCustomProperty: true\n });\n res = toPlainObject(ast);\n } catch (e) {\n // workaround for https://github.com/csstree/csstree/issues/265\n // NOTE: still throws on `:lang(\"\")`;\n if (e.message === 'Identifier is expected' && QUOTED_LANG.test(selector)) {\n const [, lang, range] = QUOTED_LANG.exec(selector);\n const escapedRange =\n range.replace(/\\s*\\*/g, '\\\\*').replace(/^\"/, '').replace(/\"$/, '');\n const escapedLang = lang.replace(range, escapedRange);\n res = parseSelector(selector.replace(lang, escapedLang));\n } else if (e.message === '\"]\" is expected' && !selector.endsWith(']')) {\n res = parseSelector(`${selector}]`);\n } else if (e.message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(e.message, SYNTAX_ERR);\n }\n }\n return res;\n};\n\n/**\n * walk AST\n * @param {object} ast - AST\n * @returns {Array.<object|undefined>} - collection of AST branches\n */\nexport const walkAST = (ast = {}) => {\n const branches = new Set();\n let hasPseudoFunc;\n const opt = {\n enter: node => {\n if (node.type === SELECTOR) {\n branches.add(node.children);\n } else if (node.type === PSEUDO_CLASS_SELECTOR &&\n PSEUDO_FUNC.test(node.name)) {\n hasPseudoFunc = true;\n }\n }\n };\n walk(ast, opt);\n if (hasPseudoFunc) {\n findAll(ast, (node, item, list) => {\n if (node.type === PSEUDO_CLASS_SELECTOR && PSEUDO_FUNC.test(node.name) &&\n list) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n return type === PSEUDO_CLASS_SELECTOR && PSEUDO_FUNC.test(name);\n });\n for (const { children } of itemList) {\n // SelectorList\n for (const { children: grandChildren } of children) {\n // Selector\n for (const { children: greatGrandChildren } of grandChildren) {\n if (branches.has(greatGrandChildren)) {\n branches.delete(greatGrandChildren);\n }\n }\n }\n }\n }\n });\n }\n return [...branches];\n};\n\n/* export */\nexport { generate as generateCSS } from 'css-tree';\n"],
5
+ "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8CAAAE,EAAA,eAAAC,EAAA,qBAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAN,GAKA,IAAAO,EAAoD,oBAGpDC,EAEO,yBAuLPD,EAAwC,oBAtLxC,MAAME,EAAkB,SAAS,QAAS,EAAE,EACtCC,EAAM,GACNC,EAAO,EAGPC,EAAc,sBACdC,EAAc,4BACdC,EAAc,oCACdC,EAAa,YAONX,EAAmB,CAACY,EAAW,KAAO,CACjD,GAAI,OAAOA,GAAa,UAAYA,EAAS,QAAQ,KAAM,CAAC,GAAK,EAAG,CAClE,MAAMC,EAAMD,EAAS,MAAM,IAAI,EACzBE,EAAID,EAAI,OACd,QAASE,EAAI,EAAGA,EAAID,EAAGC,IAAK,CAC1B,IAAIC,EAAOH,EAAIE,CAAC,EAChB,GAAIA,IAAMD,EAAI,GAAKE,IAAS,GAC1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C,EAWJ,iBAAKP,EAVO,CACV,MAAOQ,GAAQ,CACTA,EAAK,OAAS,WAChBF,EAAS,IAAIE,EAAK,QAAQ,EACjBA,EAAK,OAAS,yBACd7B,EAAY,KAAK6B,EAAK,IAAI,IACnCD,EAAgB,GAEpB,CACF,CACa,EACTA,MACF,WAAQP,EAAK,CAACQ,EAAMtB,EAAMuB,IAAS,CACjC,GAAID,EAAK,OAAS,yBAAyB7B,EAAY,KAAK6B,EAAK,IAAI,GACjEC,EAAM,CACR,MAAMC,EAAWD,EAAK,OAAOxB,GAAK,CAChC,KAAM,CAAE,KAAA0B,EAAM,KAAAC,CAAK,EAAI3B,EACvB,OAAO2B,IAAS,yBAAyBjC,EAAY,KAAKgC,CAAI,CAChE,CAAC,EACD,SAAW,CAAE,SAAAE,CAAS,IAAKH,EAEzB,SAAW,CAAE,SAAUI,CAAc,IAAKD,EAExC,SAAW,CAAE,SAAUE,CAAmB,IAAKD,EACzCR,EAAS,IAAIS,CAAkB,GACjCT,EAAS,OAAOS,CAAkB,CAK5C,CACF,CAAC,EAEI,CAAC,GAAGT,CAAQ,CACrB",
6
+ "names": ["parser_exports", "__export", "parseSelector", "preprocess", "unescapeSelector", "walkAST", "__toCommonJS", "import_css_tree", "import_constant", "CODE_POINT_UNIT", "HEX", "PAIR", "HEX_CAPTURE", "PSEUDO_FUNC", "QUOTED_LANG", "WHITESPACE", "selector", "arr", "l", "i", "item", "hexExists", "hex", "str", "low", "high", "deci", "postStr", "args", "index", "preHash", "postHash", "codePoint", "res", "ast", "e", "lang", "range", "escapedRange", "escapedLang", "branches", "hasPseudoFunc", "node", "list", "itemList", "name", "type", "children", "grandChildren", "greatGrandChildren"]
7
7
  }
package/package.json CHANGED
@@ -57,5 +57,5 @@
57
57
  "update": "npm-run-all -s update-*",
58
58
  "update-wpt": "git submodule update --init --recursive --remote"
59
59
  },
60
- "version": "1.0.1"
60
+ "version": "1.0.2"
61
61
  }
package/src/js/matcher.js CHANGED
@@ -55,7 +55,7 @@ const PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;
55
55
  * ]
56
56
  * #nodes: [
57
57
  * Set([node{}, node{}]),
58
- * Set([node{}, node, node{}])
58
+ * Set([node{}, node{}, node{}])
59
59
  * ]
60
60
  * branch[]: [twig{}, twig{}]
61
61
  * twig{}: {
@@ -89,12 +89,12 @@ export class Matcher {
89
89
  constructor(selector, node, opt = {}) {
90
90
  const { sort, warn } = opt;
91
91
  this.#bit = new Map([
92
- [ATTRIBUTE_SELECTOR, BIT_10000],
93
- [CLASS_SELECTOR, BIT_100],
94
- [ID_SELECTOR, BIT_10],
95
- [PSEUDO_CLASS_SELECTOR, BIT_100000],
96
92
  [PSEUDO_ELEMENT_SELECTOR, BIT_1],
97
- [TYPE_SELECTOR, BIT_1000]
93
+ [ID_SELECTOR, BIT_10],
94
+ [CLASS_SELECTOR, BIT_100],
95
+ [TYPE_SELECTOR, BIT_1000],
96
+ [ATTRIBUTE_SELECTOR, BIT_10000],
97
+ [PSEUDO_CLASS_SELECTOR, BIT_100000]
98
98
  ]);
99
99
  this.#cache = new WeakMap();
100
100
  this.#selector = selector;
@@ -198,7 +198,7 @@ export class Matcher {
198
198
  /**
199
199
  * prepare ast and nodes
200
200
  * @param {string} selector - CSS selector
201
- * @returns {Array.<Array.<object|undefined>>} - list and matrix
201
+ * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes
202
202
  */
203
203
  _prepare(selector = this.#selector) {
204
204
  const ast = parseSelector(selector);
@@ -317,11 +317,10 @@ export class Matcher {
317
317
  }
318
318
  // :nth-child()
319
319
  } else {
320
- let n = 0;
321
320
  let nth = b - 1;
322
321
  if (a > 0) {
323
322
  while (nth < 0) {
324
- nth += (++n * a);
323
+ nth += a;
325
324
  }
326
325
  }
327
326
  if (nth >= 0 && nth < l) {
@@ -584,48 +583,67 @@ export class Matcher {
584
583
  * @returns {?object} - matched node
585
584
  */
586
585
  _matchLanguagePseudoClass(ast, node) {
587
- const { lang } = node;
588
586
  const astName = unescapeSelector(ast.name);
589
587
  let res;
590
- // TBD: what about xml:lang?
591
- if (astName === '') {
592
- if (node.getAttribute('lang') === '') {
593
- res = node;
594
- }
595
- } else if (astName === '*') {
596
- if (!node.hasAttribute('lang')) {
597
- res = node;
598
- }
599
- } else if (/[A-Z\d-]+/i.test(astName)) {
600
- const codePart = '(?:-[A-Za-z\\d]+)?';
601
- let reg;
602
- if (/-/.test(astName)) {
603
- const [langMain, langSub, ...langRest] = astName.split('-');
604
- const extendedMain = `${langMain}${codePart}`;
605
- const extendedSub = `-${langSub}${codePart}`;
606
- const len = langRest.length;
607
- let extendedRest = '';
608
- if (len) {
609
- for (let i = 0; i < len; i++) {
610
- extendedRest += `-${langRest[i]}${codePart}`;
611
- }
612
- }
613
- reg = new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');
614
- } else {
615
- reg = new RegExp(`^${astName}${codePart}$`, 'i');
616
- }
617
- if (lang) {
618
- if (reg.test(lang)) {
619
- res = node;
588
+ if (astName) {
589
+ if (astName === '*') {
590
+ if (node.hasAttribute('lang')) {
591
+ if (node.getAttribute('lang')) {
592
+ res = node;
593
+ }
594
+ } else {
595
+ let parent = node.parentNode;
596
+ while (parent) {
597
+ if (parent.hasAttribute('lang')) {
598
+ if (parent.getAttribute('lang')) {
599
+ res = node;
600
+ }
601
+ break;
602
+ }
603
+ parent = parent.parentNode;
604
+ }
620
605
  }
621
- } else {
622
- let target = node;
623
- while (target) {
624
- if (reg.test(target.lang)) {
606
+ } else if (/[A-Z\d-]+/i.test(astName)) {
607
+ const alphaNum = '[A-Z\\d]+';
608
+ const codePart = `(?:-${alphaNum})*`;
609
+ let reg;
610
+ if (/-/.test(astName)) {
611
+ const [langMain, langSub, ...langRest] = astName.split('-');
612
+ let extendedMain;
613
+ if (langMain === '*') {
614
+ extendedMain = `${alphaNum}${codePart}`;
615
+ } else {
616
+ extendedMain = `${langMain}${codePart}`;
617
+ }
618
+ const extendedSub = `-${langSub}${codePart}`;
619
+ const len = langRest.length;
620
+ let extendedRest = '';
621
+ if (len) {
622
+ for (let i = 0; i < len; i++) {
623
+ extendedRest += `-${langRest[i]}${codePart}`;
624
+ }
625
+ }
626
+ reg =
627
+ new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');
628
+ } else {
629
+ reg = new RegExp(`^${astName}${codePart}$`, 'i');
630
+ }
631
+ if (node.hasAttribute('lang')) {
632
+ if (reg.test(node.getAttribute('lang'))) {
625
633
  res = node;
626
- break;
627
634
  }
628
- target = target.parentNode;
635
+ } else {
636
+ let parent = node.parentNode;
637
+ while (parent) {
638
+ if (parent.hasAttribute('lang')) {
639
+ const value = parent.getAttribute('lang');
640
+ if (reg.test(value)) {
641
+ res = node;
642
+ }
643
+ break;
644
+ }
645
+ parent = parent.parentNode;
646
+ }
629
647
  }
630
648
  }
631
649
  }
@@ -1543,8 +1561,11 @@ export class Matcher {
1543
1561
  itemValue = itemValue.toLowerCase();
1544
1562
  }
1545
1563
  if (/:/.test(itemName)) {
1546
- const [, itemNameLocalName] = itemName.split(':');
1547
- if (astAttrName === itemNameLocalName) {
1564
+ const [itemNamePrefix, itemNameLocalName] = itemName.split(':');
1565
+ // ignore xml:lang
1566
+ if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {
1567
+ continue;
1568
+ } else if (astAttrName === itemNameLocalName) {
1548
1569
  attrValues.add(itemValue);
1549
1570
  }
1550
1571
  } else if (astAttrName === itemName) {
@@ -2040,7 +2061,7 @@ export class Matcher {
2040
2061
  * find nodes
2041
2062
  * @param {object} twig - twig
2042
2063
  * @param {string} targetType - target type
2043
- * @returns {object} - result
2064
+ * @returns {object} - collection of nodes and pending state
2044
2065
  */
2045
2066
  _findNodes(twig, targetType) {
2046
2067
  const { leaves: [leaf, ...items] } = twig;
@@ -2229,7 +2250,7 @@ export class Matcher {
2229
2250
  /**
2230
2251
  * get first twig
2231
2252
  * @param {Array.<object>} branch - AST branch
2232
- * @returns {object} - result
2253
+ * @returns {object} - find direction and twig
2233
2254
  */
2234
2255
  _getFirstTwig(branch) {
2235
2256
  const lastIndex = branch.length - 1;
@@ -2259,7 +2280,7 @@ export class Matcher {
2259
2280
  /**
2260
2281
  * collect nodes
2261
2282
  * @param {string} targetType - target type
2262
- * @returns {Array.<Array.<object|undefined>>} - matrix
2283
+ * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes
2263
2284
  */
2264
2285
  _collectNodes(targetType) {
2265
2286
  const ast = this.#ast.values();
package/src/js/parser.js CHANGED
@@ -16,6 +16,7 @@ const PAIR = 2;
16
16
  /* regexp */
17
17
  const HEX_CAPTURE = /^([\da-f]{1,6}\s?)/i;
18
18
  const PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;
19
+ const QUOTED_LANG = /(:lang\(\s*("[A-Z\d\-*]+")\s*\))/i;
19
20
  const WHITESPACE = /^[\n\r\f]/;
20
21
 
21
22
  /**
@@ -126,7 +127,15 @@ export const parseSelector = selector => {
126
127
  });
127
128
  res = toPlainObject(ast);
128
129
  } catch (e) {
129
- if (e.message === '"]" is expected' && !selector.endsWith(']')) {
130
+ // workaround for https://github.com/csstree/csstree/issues/265
131
+ // NOTE: still throws on `:lang("")`;
132
+ if (e.message === 'Identifier is expected' && QUOTED_LANG.test(selector)) {
133
+ const [, lang, range] = QUOTED_LANG.exec(selector);
134
+ const escapedRange =
135
+ range.replace(/\s*\*/g, '\\*').replace(/^"/, '').replace(/"$/, '');
136
+ const escapedLang = lang.replace(range, escapedRange);
137
+ res = parseSelector(selector.replace(lang, escapedLang));
138
+ } else if (e.message === '"]" is expected' && !selector.endsWith(']')) {
130
139
  res = parseSelector(`${selector}]`);
131
140
  } else if (e.message === '")" is expected' && !selector.endsWith(')')) {
132
141
  res = parseSelector(`${selector})`);