@asamuzakjp/dom-selector 4.5.0-b.6 → 4.5.0
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/dist/cjs/js/finder.js +1 -1
- package/dist/cjs/js/finder.js.map +3 -3
- package/package.json +7 -7
- package/src/js/finder.js +2 -16
package/dist/cjs/js/finder.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var W=Object.create;var P=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(g,l)=>{for(var e in l)P(g,e,{get:l[e],enumerable:!0})},I=(g,l,e,h)=>{if(l&&typeof l=="object"||typeof l=="function")for(let o of j(l))!q.call(g,o)&&o!==e&&P(g,o,{get:()=>l[o],enumerable:!(h=B(l,o))||h.enumerable});return g};var U=(g,l,e)=>(e=g!=null?W(Y(g)):{},I(l||!g||!g.__esModule?P(e,"default",{value:g,enumerable:!0}):e,g)),X=g=>I(P({},"__esModule",{value:!0}),g);var Q={};V(Q,{Finder:()=>K});module.exports=X(Q);var M=U(require("is-potential-custom-element-name"),1),G=U(require("@asamuzakjp/nwsapi"),1),_=require("./dom-util.js"),O=require("./matcher.js"),y=require("./parser.js"),c=require("./constant.js");const x="next",S="prev",L="all",E="first",C="lineal",R="self";class K{#l;#c;#s;#h;#w;#r;#m;#e;#d;#k;#o;#f;#_;#t;#u;#b;#n;#p;#i;#a;constructor(l,e){this.#a=l,this.#r=e??l.document,this.#c=new WeakMap,this.#h=new WeakMap,this.#_=new WeakMap,this._initNwsapi()}_onError(l){if(!this.#k)if(l instanceof DOMException||l instanceof this.#a.DOMException)if(l.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw new this.#a.DOMException(l.message,l.name);else throw l}_setup(l,e,h={}){const{event:o,noexcept:a,warn:r}=h;return this.#k=!!a,this.#i=!!r,this.#m=this._setEvent(o),this.#e=e,[this.#s,this.#t,this.#n]=(0,_.resolveContent)(e),this.#u=(0,_.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(l),this.#p=new WeakMap,e}_initNwsapi(){return this.#o=(0,G.default)({DOMException:this.#a.DOMException,document:this.#r}),this.#o.configure({LOGERRORS:!1}),this.#o}_setEvent(l){return l instanceof this.#a.KeyboardEvent||l instanceof this.#a.MouseEvent?l:null}_correspond(l){const e=[];this.#w=!1;let h,o;if(this.#h.has(this.#s)){const a=this.#h.get(this.#s);if(a&&a.has(`${l}`)){const r=a.get(`${l}`);this.#w=r.descendant,h=r.ast,o=r.cacheable}}if(h){const a=h.length;for(let r=0;r<a;r++)h[r].collected=!1,h[r].dir=null,h[r].filtered=!1,h[r].find=!1,e[r]=[]}else{let a;try{a=(0,y.parseSelector)(l)}catch(t){this._onError(t)}const{branches:r,info:{hasHasPseudoFunc:n,hasHyphenSepAttr:u}}=(0,y.walkAST)(a);n||u?o=!1:o=!0;let d=!1,i=0;h=[];for(const[...t]of r){const s=[];let f=t.shift();if(f&&f.type!==c.COMBINATOR){const m=new Set;for(;f;){if(f.type===c.COMBINATOR){const[b]=t;if(b.type===c.COMBINATOR){const w=`Invalid selector ${l}`;throw new DOMException(w,c.SYNTAX_ERR)}const p=f.name;/^[\s>]$/.test(p)&&(d=!0),s.push({combo:f,leaves:(0,y.sortAST)(m)}),m.clear()}else if(f){let{name:b}=f;b&&typeof b=="string"&&(b=(0,y.unescapeSelector)(b),typeof b=="string"&&b!==f.name&&(f.name=b),/[|:]/.test(b)&&(f.namespace=!0)),m.add(f)}if(t.length)f=t.shift();else{s.push({combo:null,leaves:(0,y.sortAST)(m)}),m.clear();break}}}h.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[i]=[],i++}if(o){let t;this.#h.has(this.#s)?t=this.#h.get(this.#s):t=new Map,t.set(`${l}`,{ast:h,cacheable:o,descendant:d}),this.#h.set(this.#s,t)}this.#w=d}return[h,e]}_createTreeWalker(l){let e;return this.#p.has(l)?e=this.#p.get(l):(e=this.#r.createTreeWalker(l,c.WALKER_FILTER),this.#p.set(l,e)),e}_prepareQuerySelectorWalker(){return this.#f=this._createTreeWalker(this.#e),this.#b=!1,this.#f}_collectNthChild(l,e,h){const{a:o,b:a,reverse:r,selector:n}=l,{parentNode:u}=e,d=new Set;let i;if(n)if(this.#c.has(n))i=this.#c.get(n);else{const{branches:t}=(0,y.walkAST)(n);i=t,this.#c.set(n,i)}if(u){const t=this.#n;let s=(0,_.traverseNode)(u,t);s=t.firstChild();let f=0;for(;s;)f++,s=t.nextSibling();s=(0,_.traverseNode)(u,t);const m=new Set;if(i)for(s=t.firstChild();s;){let b;for(const p of i)if(b=this._matchLeaves(p,s,h),!b)break;b&&m.add(s),s=t.nextSibling()}if(o===0){if(a>0&&a<=f){if(m.size){s=(0,_.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(m.has(s)){if(b===a-1){d.add(s);break}b++}r?s=t.previousSibling():s=t.nextSibling()}}else if(!n){s=(0,_.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(b===a-1){d.add(s);break}r?s=t.previousSibling():s=t.nextSibling(),b++}}}}else{let b=a-1;if(o>0)for(;b<0;)b+=o;if(b>=0&&b<f){s=(0,_.traverseNode)(u,t),r?s=t.lastChild():s=t.firstChild();let p=0,w=o>0?0:a-1;for(;s&&(s&&b>=0&&b<f);)m.size?m.has(s)&&(w===b&&(d.add(s),b+=o),o>0?w++:w--):p===b&&(n||d.add(s),b+=o),r?s=t.previousSibling():s=t.nextSibling(),p++}}if(r&&d.size>1){const b=[...d];return new Set(b.reverse())}}else if(e===this.#t&&o+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(l,e){const{a:h,b:o,reverse:a}=l,{localName:r,parentNode:n,prefix:u}=e,d=new Set;if(n){const i=this.#n;let t=(0,_.traverseNode)(n,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(o>0&&o<=s){t=(0,_.traverseNode)(n,i),a?t=i.lastChild():t=i.firstChild();let f=0;for(;t;){const{localName:m,prefix:b}=t;if(m===r&&b===u){if(f===o-1){d.add(t);break}f++}a?t=i.previousSibling():t=i.nextSibling()}}}else{let f=o-1;if(h>0)for(;f<0;)f+=h;if(f>=0&&f<s){t=(0,_.traverseNode)(n,i),a?t=i.lastChild():t=i.firstChild();let m=h>0?0:o-1;for(;t;){const{localName:b,prefix:p}=t;if(b===r&&p===u){if(m===f&&(d.add(t),f+=h),f<0||f>=s)break;h>0?m++:m--}a?t=i.previousSibling():t=i.nextSibling()}}}if(a&&d.size>1){const f=[...d];return new Set(f.reverse())}}else e===this.#t&&h+o===1&&d.add(e);return d}_matchAnPlusB(l,e,h,o){const{nth:{a,b:r,name:n},selector:u}=l,d=new Map;if(n?(n==="even"?(d.set("a",2),d.set("b",0)):n==="odd"&&(d.set("a",2),d.set("b",1)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?d.set("b",r*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,o)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(l,e,h={}){let o;if(Array.isArray(l)&&l.length){const a=l.map(s=>s),[r]=a,{type:n}=r;let u;n===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:f}=s;if(f===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};h.dir=x;const t=this._matchCombinator(i,e,h);if(t.size)if(a.length){for(const s of t)if(o=this._matchHasPseudoFunc(a,s,h),o)break}else o=!0}return!!o}_matchLogicalPseudoFunc(l,e,h={}){const{astName:o="",branches:a=[],selector:r="",twigBranches:n=[]}=l;let u;if(o==="has")if(r.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(o);h.forgive=d;const i=n.length;let t;for(let s=0;s<i;s++){const f=n[s],m=f.length-1,{leaves:b}=f[m];if(t=this._matchLeaves(b,e,h),t&&m>0){let p=new Set([e]);for(let w=m-1;w>=0;w--){const k=f[w],N=[];h.dir=S;for(const A of p){const v=this._matchCombinator(k,A,h);v.size&&N.push(...v)}if(N.length)w===0?t=!0:p=new Set(N);else{t=!1;break}}}if(t)break}o==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(l,e,h={}){const{children:o,name:a}=l,{localName:r,parentNode:n}=e,{forgive:u,warn:d=this.#i}=h,i=new Set;if(c.REG_LOGICAL_PSEUDO.test(a)){let t;if(this.#c.has(l))t=this.#c.get(l);else{const{branches:f}=(0,y.walkAST)(l),m=[],b=[];for(const[...p]of f){for(const A of p){const v=(0,y.generateCSS)(A);m.push(v)}const w=[],k=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(w.push({combo:N,leaves:[...k]}),k.clear()):N&&k.add(N),p.length)N=p.shift();else{w.push({combo:null,leaves:[...k]}),k.clear();break}b.push(w)}t={astName:a,branches:f,twigBranches:b,selector:m.join(",")},this.#c.set(l,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(o))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=o;return this._matchAnPlusB(t,e,a,h)}else switch(a){case"dir":case"lang":{const t=O.matcher.matchSelector(l,e);t&&i.add(t);break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(!u){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.SYNTAX_ERR)}}else switch(a){case"any-link":case"link":{c.REG_ANCHOR.test(r)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(c.REG_ANCHOR.test(r)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:f}=new URL(this.#s.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===f&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#m??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:f}=this.#m??{};(f==="mousedown"||f==="pointerdown")&&t&c.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const s=t.replace(/^#/,"");let f=this.#s.getElementById(s);for(;f;){if(f===e){i.add(e);break}f=f.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#s.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#m??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(a==="focus"||s==="keydown"&&e.contains(t))){let f=e,m=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(f);if(m=!(b==="none"||p==="hidden"),!m)break}if(f.parentNode&&f.parentNode.nodeType===c.ELEMENT_NODE)f=f.parentNode;else break}m&&i.add(e)}break}case"focus-within":{let t,s=this.#s.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}if(t){let f=e,m=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(f);if(m=!(b==="none"||p==="hidden"),!m)break}if(f.parentNode&&f.parentNode.nodeType===c.ELEMENT_NODE)f=f.parentNode;else break}m&&i.add(e)}break}case"open":{c.REG_INTERACT.test(r)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{c.REG_INTERACT.test(r)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(c.REG_FORM_CTRL.test(r)||(0,M.default)(r))if(e.disabled||e.hasAttribute("disabled"))i.add(e);else{let t=n;for(;t;){if(c.REG_FORM_GROUP.test(t.localName))if(t.localName==="fieldset"){if(t.disabled&&t.hasAttribute("disabled"))break}else break;t=t.parentNode}t&&n.localName!=="legend"&&(t.disabled||t.hasAttribute("disabled"))&&i.add(e)}break}case"enabled":{(c.REG_FORM_CTRL.test(r)||(0,M.default)(r))&&!(e.disabled&&e.hasAttribute("disabled"))&&i.add(e);break}case"read-only":{switch(r){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,_.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,_.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;r==="textarea"?s=e:r==="input"&&(e.hasAttribute("type")?c.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&r==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&r==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&r==="input"&&e.type==="checkbox"||r==="progress"&&!e.hasAttribute("value"))i.add(e);else if(r==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#s.documentElement);const f=s.getElementsByTagName("input"),m=f.length;let b;for(let p=0;p<m;p++){const w=f[p];if(w.getAttribute("type")==="radio"&&(t?w.getAttribute("name")===t&&(b=!!w.checked):w.hasAttribute("name")||(b=!!w.checked),b))break}b||i.add(e)}break}case"default":{if(r==="button"&&!(e.hasAttribute("type")&&c.REG_TYPE_RESET.test(e.getAttribute("type")))||r==="input"&&e.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#n;let f=(0,_.traverseNode)(t,s);for(f=s.firstChild();f&&t.contains(f);){const m=f.localName;let b;if(m==="button"?b=!(f.hasAttribute("type")&&c.REG_TYPE_RESET.test(f.getAttribute("type"))):m==="input"&&(b=f.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(f.getAttribute("type"))),b){f===e&&i.add(e);break}f=s.nextNode()}}}else if(r==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))i.add(e);else if(r==="option"){let t=n,s=!1;for(;t&&t.localName!=="datalist";){if(t.localName==="select"){(t.multiple||t.hasAttribute("multiple"))&&(s=!0);break}t=t.parentNode}if(s)(e.selected||e.hasAttribute("selected"))&&i.add(e);else{const f=new Set,m=this.#n;let b=(0,_.traverseNode)(n,m);for(b=m.firstChild();b;){if(b.selected||b.hasAttribute("selected")){f.add(b);break}b=m.nextSibling()}f.size&&f.has(e)&&i.add(e)}}break}case"valid":{if(c.REG_FORM_VALID.test(r))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(r==="fieldset"){const t=this.#n;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(c.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f&&i.add(e)}break}case"invalid":{if(c.REG_FORM_VALID.test(r))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(r==="fieldset"){const t=this.#n;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(c.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f||i.add(e)}break}case"in-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(r))t=e;else if(r==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||c.REG_TYPE_CHECK.test(s)||c.REG_TYPE_DATE.test(s)||c.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(r))t=e;else if(r==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||c.REG_TYPE_CHECK.test(s)||c.REG_TYPE_DATE.test(s)||c.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#s.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#r.createTreeWalker(e,c.SHOW_ALL);let s=t.firstChild(),f;for(;s&&(f=s.nodeType!==c.ELEMENT_NODE&&s.nodeType!==c.TEXT_NODE,!!f);)s=t.nextSibling();f&&i.add(e)}else i.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#t)&&i.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#t)&&i.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#t)&&i.add(e);break}case"first-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"last-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"only-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#t&&i.add(e);break}case"defined":{const t=e.getAttribute("is");t?(0,M.default)(t)&&this.#a.customElements.get(t)&&i.add(e):(0,M.default)(r)?this.#a.customElements.get(r)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#a.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(a.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${a}`;throw new DOMException(t,c.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(l,e){const{children:h,name:o}=l;let a;if(Array.isArray(h)){const{branches:r}=(0,y.walkAST)(h[0]),[n]=r,[...u]=n,{host:d}=e;if(o==="host"){let i;for(const t of u){const{type:s}=t;if(s===c.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(m,c.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(a=e)}else if(o==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:f}=s;if(f===c.COMBINATOR){const b=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(b,c.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(a=e)}}else if(o==="host")a=e;else{const r=`Invalid selector :${o}`;throw new DOMException(r,c.SYNTAX_ERR)}return a??null}_matchSelector(l,e,h){const{type:o}=l,a=new Set;if(l.name===c.EMPTY)return a;const r=(0,y.unescapeSelector)(l.name);if(typeof r=="string"&&r!==l.name&&(l.name=r),e.nodeType===c.ELEMENT_NODE)switch(o){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(r,h);break}case c.SELECTOR_ID:{e.id===r&&a.add(e);break}case c.SELECTOR_CLASS:{e.classList.contains(r)&&a.add(e);break}case c.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(l,e,h);default:{const n=O.matcher.matchSelector(l,e,h);n&&a.add(n)}}else if(this.#u&&o===c.SELECTOR_PSEUDO_CLASS&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(r!=="has"&&c.REG_LOGICAL_PSEUDO.test(r))return this._matchPseudoClassSelector(l,e,h);if(c.REG_SHADOW_HOST.test(r)){const n=this._matchShadowHostPseudoClass(l,e,h);n&&a.add(n)}}return a}_matchLeaves(l,e,h){const{attributes:o,localName:a,nodeType:r}=e;let n=this.#_.get(l),u;if(n&&n.has(e)){const{attr:d,matched:i}=n.get(e);o?.length===d&&(u=i)}if(typeof u!="boolean"){let d;r===c.ELEMENT_NODE&&c.REG_FORM.test(a)?d=!1:d=!0;for(const i of l){const{name:t,type:s}=i;if(s===c.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(d=!1),u=this._matchSelector(i,e,h).has(e),!u)break}d&&(n||(n=new WeakMap),n.set(e,{attr:o?.length,matched:u}),this.#_.set(l,n))}return!!u}_matchHTMLCollection(l,e={}){const{compound:h,filterLeaves:o}=e,a=new Set,r=l.length;if(r)if(h)for(let n=0;n<r;n++){const u=l[n];this._matchLeaves(o,u,e)&&a.add(u)}else{const n=[].slice.call(l);return new Set(n)}return a}_findDescendantNodes(l,e,h){const[o,...a]=l,r=a.length>0,{type:n}=o,u=(0,y.unescapeSelector)(o.name);typeof u=="string"&&u!==o.name&&(o.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(n){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,h);break}case c.SELECTOR_ID:{if(this.#t.nodeType===c.ELEMENT_NODE)i=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(r?this._matchLeaves(a,t,h)&&d.add(t):d.add(t))}break}case c.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:r,filterLeaves:a});break}case c.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:r,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(l,e,h={}){const{combo:o,leaves:a}=l,{name:r}=o,{parentNode:n}=e,{dir:u}=h,d=new Set;if(u===x)switch(r){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(n){const i=this._createTreeWalker(n);let t=(0,_.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,_.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let f=(0,_.traverseNode)(e,s);for(f=s.nextNode();f&&e.contains(f);)this._matchLeaves(a,f,h)&&d.add(f),f=s.nextNode()}}}else switch(r){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(n){const i=this._createTreeWalker(n);let t=(0,_.traverseNode)(n,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{n&&this._matchLeaves(a,n,h)&&d.add(n);break}case" ":default:{const i=[];let t=n;for(;t;)this._matchLeaves(a,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(l,e){const{node:h}=e;let o=(0,_.traverseNode)(h,this.#f),a;if(o)for(o.nodeType!==c.ELEMENT_NODE?o=this.#f.nextNode():o===h&&o!==this.#t&&(o=this.#f.nextNode());o;){if(this._matchLeaves(l,o,{warn:this.#i})){a=o;break}o=this.#f.nextNode()}return a??null}_matchSelf(l){const e=[],h=this._matchLeaves(l,this.#e,{warn:this.#i});let o=!1;return h&&(e.push(this.#e),o=!0),[e,o]}_findLineal(l,e={}){const{complex:h}=e,o=[];let a=this._matchLeaves(l,this.#e,{warn:this.#i}),r=!1;if(a&&(o.push(this.#e),r=!0),!a||h){let n=this.#e.parentNode;for(;n&&(a=this._matchLeaves(l,n,{warn:this.#i}),a&&(o.push(n),r=!0),n.parentNode);)n=n.parentNode}return[o,r]}_findFirst(l){const e=[],h=this._findNode(l,{node:this.#e});let o=!1;return h&&(e.push(h),o=!0),[e,o]}_findFromHTMLCollection(l,e={}){const{complex:h,compound:o,filterLeaves:a,targetType:r}=e;let n=[],u=!1,d=!1;const i=l.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<i;t++){const s=l[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(o){if(this._matchLeaves(a,s,{warn:this.#i})&&(n.push(s),u=!0,r===E))break}else if(n.push(s),u=!0,r===E)break}}else if(h)if(o)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(n.push(s),u=!0,r===E))break}else n=[].slice.call(l),u=!0,d=!0;else if(o)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(n.push(s),u=!0,r===E))break}else n=[].slice.call(l),u=!0,d=!0;return[n,u,d]}_findEntryNodes(l,e,h){const{leaves:o}=l,[a,...r]=o,n=r.length>0,{name:u,type:d}=a;let i=[],t=!1,s=!1,f=!1;switch(d){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{warn:this.#i});break}case c.SELECTOR_ID:{if(e===R)[i,s]=this._matchSelf(o);else if(e===C)[i,s]=this._findLineal(o,{complex:h});else if(e===E&&this.#t.nodeType!==c.ELEMENT_NODE){const m=this.#t.getElementById(u);m&&(n?this._matchLeaves(r,m,{warn:this.#i})&&(i.push(m),s=!0):(i.push(m),s=!0))}else e===E?[i,s]=this._findFirst(o):f=!0;break}case c.SELECTOR_CLASS:{if(e===R)[i,s]=this._matchSelf(o);else if(e===C)[i,s]=this._findLineal(o,{complex:h});else if(this.#t.nodeType===c.DOCUMENT_NODE){const m=this.#t.getElementsByClassName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:n,filterLeaves:r,targetType:e}))}else e===E?[i,s]=this._findFirst(o):f=!0;break}case c.SELECTOR_TYPE:{if(e===R)[i,s]=this._matchSelf(o);else if(e===C)[i,s]=this._findLineal(o,{complex:h});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#t.getElementsByTagName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:n,filterLeaves:r,targetType:e}))}else e===E?[i,s]=this._findFirst(o):f=!0;break}default:if(e!==C&&c.REG_SHADOW_HOST.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(a,this.#e);m&&(i.push(m),s=!0)}}else e===R?[i,s]=this._matchSelf(o):e===C?[i,s]=this._findLineal(o,{complex:h}):e===E?[i,s]=this._findFirst(o):f=!0}return{collected:t,compound:n,filtered:s,nodes:i,pending:f}}_collectNodes(l){const e=this.#l.values();if(l===L||l===E){const h=new Set;let o=0;for(const{branch:a}of e){const r=a.length,n=r>1,u=a[0];let d,i;if(n){const{combo:p,leaves:[{name:w,type:k}]}=u,N=a[r-1],{leaves:[{name:A,type:v}]}=N;if(v===c.SELECTOR_PSEUDO_ELEMENT||v===c.SELECTOR_ID)d=S,i=N;else if(k===c.SELECTOR_PSEUDO_ELEMENT||k===c.SELECTOR_ID)d=x,i=u;else if(l===L)if(w==="*"&&k===c.SELECTOR_TYPE)d=S,i=N;else if(A==="*"&&v===c.SELECTOR_TYPE)d=x,i=u;else if(r===2){const{name:T}=p;/^[+~]$/.test(T)?(d=S,i=N):(d=x,i=u)}else d=x,i=u;else if(A==="*"&&v===c.SELECTOR_TYPE)d=x,i=u;else if(w==="*"&&k===c.SELECTOR_TYPE)d=S,i=N;else{let T;for(const{combo:D,leaves:[$]}of a){const{name:F,type:z}=$;if(z===c.SELECTOR_PSEUDO_CLASS&&F==="dir"){T=!1;break}if(!T&&D){const{name:H}=D;/^[+~]$/.test(H)&&(T=!0)}}T?(d=x,i=u):(d=S,i=N)}}else d=S,i=u;const{collected:t,compound:s,filtered:f,nodes:m,pending:b}=this._findEntryNodes(i,l,n);m.length?(this.#l[o].find=!0,this.#d[o]=m):b&&h.add(new Map([["index",o],["twig",i]])),this.#l[o].collected=t,this.#l[o].dir=d,this.#l[o].filtered=f||!s,o++}if(h.size){let a,r;this.#e!==this.#t&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,r=this.#f):(a=this.#t,r=this.#n);let n=(0,_.traverseNode)(a,r);for(;n;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?n===this.#e?u=!0:u=this.#e.contains(n):u=!0,u)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,n,{warn:this.#i})){const s=d.get("index");this.#l[s].filtered=!0,this.#l[s].find=!0,this.#d[s].push(n)}}n!==r.currentNode&&(n=(0,_.traverseNode)(n,r)),n=r.nextNode()}}}else{let h=0;for(const{branch:o}of e){const a=o[o.length-1],r=o.length>1,{compound:n,filtered:u,nodes:d}=this._findEntryNodes(a,l,r);d.length&&(this.#l[h].find=!0,this.#d[h]=d),this.#l[h].dir=S,this.#l[h].filtered=u||!n,h++}}return[this.#l,this.#d]}_getCombinedNodes(l,e,h){const o=[];for(const a of e){const r=this._matchCombinator(l,a,{dir:h,warn:this.#i});r.size&&o.push(...r)}return o.length?new Set(o):new Set}_matchNodeNext(l,e,h){const{combo:o,index:a}=h,{combo:r,leaves:n}=l[a],u={combo:o,leaves:n},d=this._getCombinedNodes(u,e,x);let i;if(d.size)if(a===l.length-1){const[t]=(0,_.sortNodes)(d);i=t}else i=this._matchNodeNext(l,d,{combo:r,index:a+1});return i??null}_matchNodePrev(l,e,h){const{index:o}=h,a=l[o],r=new Set([e]),n=this._getCombinedNodes(a,r,S);let u;if(n.size){if(o===0)u=e;else for(const d of n)if(this._matchNodePrev(l,d,{index:o-1}))return e}return u??null}_find(l){(l===L||l===E)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(l),o=e.length;let a=new Set;for(let r=0;r<o;r++){const{branch:n,collected:u,dir:d,find:i}=e[r],t=n.length;if(t&&i){const s=h[r],f=s.length,m=t-1;if(m===0)if((l===L||l===E)&&this.#e.nodeType===c.ELEMENT_NODE)for(let b=0;b<f;b++){const p=s[b];if(p!==this.#e&&this.#e.contains(p)&&(a.add(p),l!==L))break}else if(l===L)if(a.size){const b=[...a];a=new Set([...b,...s]),this.#b=!0}else a=new Set(s);else{const[b]=s;a.add(b)}else if(l===L)if(d===x){let{combo:b}=n[0];for(const p of s){let w=new Set([p]);for(let k=1;k<t;k++){const{combo:N,leaves:A}=n[k],v={combo:b,leaves:A};if(w=this._getCombinedNodes(v,w,d),w.size)if(k===m)if(a.size){const T=[...a];a=new Set([...T,...w]),this.#b=!0}else a=w;else b=N;else break}}}else for(const b of s){let p=new Set([b]);for(let w=m-1;w>=0;w--){const k=n[w];if(p=this._getCombinedNodes(k,p,d),p.size)w===0&&(a.add(b),t>1&&a.size>1&&(this.#b=!0));else break}}else if(l===E&&d===x){const{combo:b}=n[0];let p;for(const w of s)if(p=this._matchNodeNext(n,new Set([w]),{combo:b,index:1}),p){a.add(p);break}if(!p&&!u){const{leaves:w}=n[0],[k]=s;let N=this._findNode(w,{node:k});for(;N;){if(p=this._matchNodeNext(n,new Set([N]),{combo:b,index:1}),p){a.add(p);break}N=this._findNode(w,{node:N})}}}else{let b;for(const p of s)if(b=this._matchNodePrev(n,p,{index:m-1}),b){a.add(p);break}if(!b&&!u&&l===E){const{leaves:p}=n[m],[w]=s;let k=this._findNode(p,{node:w});for(;k;){if(b=this._matchNodePrev(n,k,{index:m-1}),b){a.add(k);break}k=this._findNode(p,{node:k})}}}}}return a}matches(l,e,h){let o;try{if(e?.nodeType!==c.ELEMENT_NODE){const n=`Unexpected node ${e?.nodeName}`;throw new TypeError(n)}const a=e.ownerDocument;if(a===this.#r&&a.contentType==="text/html"){const n={complex:c.REG_COMPLEX_A.test(l),descendant:!0};if((0,y.filterSelector)(l,n))return this.#o.match(l,e)}this._setup(l,e,h),o=this._find(R).size}catch(a){this._onError(a)}return!!o}closest(l,e,h){let o;try{if(e?.nodeType!==c.ELEMENT_NODE){const n=`Unexpected node ${e?.nodeName}`;throw new TypeError(n)}const a=e.ownerDocument;if(a===this.#r&&a.contentType==="text/html"){const n={complex:c.REG_COMPLEX_A.test(l),descendant:!0};if((0,y.filterSelector)(l,n))return this.#o.closest(l,e)}this._setup(l,e,h);const r=this._find(C);if(r.size){let n=this.#e;for(;n;){if(r.has(n)){o=n;break}n=n.parentNode}}}catch(a){this._onError(a)}return o??null}querySelector(l,e,h){let o;try{(0,_.verifyNode)(e);let a;if(e.nodeType===c.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#r&&a.contentType==="text/html"){const n={complex:c.REG_COMPLEX_B.test(l),descendant:!1};if((0,y.filterSelector)(l,n))return this.#o.first(l,e)}this._setup(l,e,h);const r=this._find(E);r.delete(this.#e),r.size&&([o]=(0,_.sortNodes)(r))}catch(a){this._onError(a)}return o??null}querySelectorAll(l,e,h){let o;try{(0,_.verifyNode)(e);let a;if(e.nodeType===c.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#r&&a.contentType==="text/html"){const n={complex:c.REG_COMPLEX_B.test(l),descendant:!0};if((0,y.filterSelector)(l,n))return this.#o.select(l,e)}this._setup(l,e,h);const r=this._find(L);r.delete(this.#e),r.size&&(this.#b?o=(0,_.sortNodes)(r):o=[...r])}catch(a){this._onError(a)}return o??[]}}0&&(module.exports={Finder});
|
|
1
|
+
var W=Object.create;var P=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(g,l)=>{for(var e in l)P(g,e,{get:l[e],enumerable:!0})},I=(g,l,e,h)=>{if(l&&typeof l=="object"||typeof l=="function")for(let n of j(l))!q.call(g,n)&&n!==e&&P(g,n,{get:()=>l[n],enumerable:!(h=B(l,n))||h.enumerable});return g};var U=(g,l,e)=>(e=g!=null?W(Y(g)):{},I(l||!g||!g.__esModule?P(e,"default",{value:g,enumerable:!0}):e,g)),X=g=>I(P({},"__esModule",{value:!0}),g);var Q={};V(Q,{Finder:()=>K});module.exports=X(Q);var M=U(require("is-potential-custom-element-name"),1),G=U(require("@asamuzakjp/nwsapi"),1),_=require("./dom-util.js"),O=require("./matcher.js"),y=require("./parser.js"),c=require("./constant.js");const x="next",S="prev",L="all",E="first",C="lineal",R="self";class K{#l;#c;#s;#h;#w;#r;#m;#e;#d;#k;#o;#f;#_;#t;#u;#b;#n;#p;#i;#a;constructor(l,e){this.#a=l,this.#r=e??l.document,this.#c=new WeakMap,this.#h=new WeakMap,this.#_=new WeakMap,this._initNwsapi()}_onError(l){if(!this.#k)if(l instanceof DOMException||l instanceof this.#a.DOMException)if(l.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw new this.#a.DOMException(l.message,l.name);else throw l}_setup(l,e,h={}){const{event:n,noexcept:a,warn:o}=h;return this.#k=!!a,this.#i=!!o,this.#m=this._setEvent(n),this.#e=e,[this.#s,this.#t,this.#n]=(0,_.resolveContent)(e),this.#u=(0,_.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(l),this.#p=new WeakMap,e}_initNwsapi(){return this.#o=(0,G.default)({DOMException:this.#a.DOMException,document:this.#r}),this.#o.configure({LOGERRORS:!1}),this.#o}_setEvent(l){return l instanceof this.#a.KeyboardEvent||l instanceof this.#a.MouseEvent?l:null}_correspond(l){const e=[];this.#w=!1;let h;if(this.#h.has(this.#s)){const n=this.#h.get(this.#s);if(n&&n.has(`${l}`)){const a=n.get(`${l}`);this.#w=a.descendant,h=a.ast}}if(h){const n=h.length;for(let a=0;a<n;a++)h[a].collected=!1,h[a].dir=null,h[a].filtered=!1,h[a].find=!1,e[a]=[]}else{let n;try{n=(0,y.parseSelector)(l)}catch(t){this._onError(t)}const{branches:a,info:{hasHasPseudoFunc:o,hasHyphenSepAttr:r}}=(0,y.walkAST)(n);let u;o||r?u=!1:u=!0;let d=!1,i=0;h=[];for(const[...t]of a){const s=[];let f=t.shift();if(f&&f.type!==c.COMBINATOR){const m=new Set;for(;f;){if(f.type===c.COMBINATOR){const[b]=t;if(b.type===c.COMBINATOR){const w=`Invalid selector ${l}`;throw new DOMException(w,c.SYNTAX_ERR)}const p=f.name;/^[\s>]$/.test(p)&&(d=!0),s.push({combo:f,leaves:(0,y.sortAST)(m)}),m.clear()}else if(f){let{name:b}=f;b&&typeof b=="string"&&(b=(0,y.unescapeSelector)(b),typeof b=="string"&&b!==f.name&&(f.name=b),/[|:]/.test(b)&&(f.namespace=!0)),m.add(f)}if(t.length)f=t.shift();else{s.push({combo:null,leaves:(0,y.sortAST)(m)}),m.clear();break}}}h.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[i]=[],i++}if(u){let t;this.#h.has(this.#s)?t=this.#h.get(this.#s):t=new Map,t.set(`${l}`,{ast:h,descendant:d}),this.#h.set(this.#s,t)}this.#w=d}return[h,e]}_createTreeWalker(l){let e;return this.#p.has(l)?e=this.#p.get(l):(e=this.#r.createTreeWalker(l,c.WALKER_FILTER),this.#p.set(l,e)),e}_prepareQuerySelectorWalker(){return this.#f=this._createTreeWalker(this.#e),this.#b=!1,this.#f}_collectNthChild(l,e,h){const{a:n,b:a,reverse:o,selector:r}=l,{parentNode:u}=e,d=new Set;let i;if(r)if(this.#c.has(r))i=this.#c.get(r);else{const{branches:t}=(0,y.walkAST)(r);i=t,this.#c.set(r,i)}if(u){const t=this.#n;let s=(0,_.traverseNode)(u,t);s=t.firstChild();let f=0;for(;s;)f++,s=t.nextSibling();s=(0,_.traverseNode)(u,t);const m=new Set;if(i)for(s=t.firstChild();s;){let b;for(const p of i)if(b=this._matchLeaves(p,s,h),!b)break;b&&m.add(s),s=t.nextSibling()}if(n===0){if(a>0&&a<=f){if(m.size){s=(0,_.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(m.has(s)){if(b===a-1){d.add(s);break}b++}o?s=t.previousSibling():s=t.nextSibling()}}else if(!r){s=(0,_.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(b===a-1){d.add(s);break}o?s=t.previousSibling():s=t.nextSibling(),b++}}}}else{let b=a-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<f){s=(0,_.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let p=0,w=n>0?0:a-1;for(;s&&(s&&b>=0&&b<f);)m.size?m.has(s)&&(w===b&&(d.add(s),b+=n),n>0?w++:w--):p===b&&(r||d.add(s),b+=n),o?s=t.previousSibling():s=t.nextSibling(),p++}}if(o&&d.size>1){const b=[...d];return new Set(b.reverse())}}else if(e===this.#t&&n+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(l,e){const{a:h,b:n,reverse:a}=l,{localName:o,parentNode:r,prefix:u}=e,d=new Set;if(r){const i=this.#n;let t=(0,_.traverseNode)(r,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(n>0&&n<=s){t=(0,_.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let f=0;for(;t;){const{localName:m,prefix:b}=t;if(m===o&&b===u){if(f===n-1){d.add(t);break}f++}a?t=i.previousSibling():t=i.nextSibling()}}}else{let f=n-1;if(h>0)for(;f<0;)f+=h;if(f>=0&&f<s){t=(0,_.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let m=h>0?0:n-1;for(;t;){const{localName:b,prefix:p}=t;if(b===o&&p===u){if(m===f&&(d.add(t),f+=h),f<0||f>=s)break;h>0?m++:m--}a?t=i.previousSibling():t=i.nextSibling()}}}if(a&&d.size>1){const f=[...d];return new Set(f.reverse())}}else e===this.#t&&h+n===1&&d.add(e);return d}_matchAnPlusB(l,e,h,n){const{nth:{a,b:o,name:r},selector:u}=l,d=new Map;if(r?(r==="even"?(d.set("a",2),d.set("b",0)):r==="odd"&&(d.set("a",2),d.set("b",1)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?d.set("b",o*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(l,e,h={}){let n;if(Array.isArray(l)&&l.length){const a=l.map(s=>s),[o]=a,{type:r}=o;let u;r===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:f}=s;if(f===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};h.dir=x;const t=this._matchCombinator(i,e,h);if(t.size)if(a.length){for(const s of t)if(n=this._matchHasPseudoFunc(a,s,h),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(l,e,h={}){const{astName:n="",branches:a=[],selector:o="",twigBranches:r=[]}=l;let u;if(n==="has")if(o.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(n);h.forgive=d;const i=r.length;let t;for(let s=0;s<i;s++){const f=r[s],m=f.length-1,{leaves:b}=f[m];if(t=this._matchLeaves(b,e,h),t&&m>0){let p=new Set([e]);for(let w=m-1;w>=0;w--){const k=f[w],N=[];h.dir=S;for(const A of p){const v=this._matchCombinator(k,A,h);v.size&&N.push(...v)}if(N.length)w===0?t=!0:p=new Set(N);else{t=!1;break}}}if(t)break}n==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(l,e,h={}){const{children:n,name:a}=l,{localName:o,parentNode:r}=e,{forgive:u,warn:d=this.#i}=h,i=new Set;if(c.REG_LOGICAL_PSEUDO.test(a)){let t;if(this.#c.has(l))t=this.#c.get(l);else{const{branches:f}=(0,y.walkAST)(l),m=[],b=[];for(const[...p]of f){for(const A of p){const v=(0,y.generateCSS)(A);m.push(v)}const w=[],k=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(w.push({combo:N,leaves:[...k]}),k.clear()):N&&k.add(N),p.length)N=p.shift();else{w.push({combo:null,leaves:[...k]}),k.clear();break}b.push(w)}t={astName:a,branches:f,twigBranches:b,selector:m.join(",")},this.#c.set(l,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=n;return this._matchAnPlusB(t,e,a,h)}else switch(a){case"dir":case"lang":{const t=O.matcher.matchSelector(l,e);t&&i.add(t);break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(!u){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.SYNTAX_ERR)}}else switch(a){case"any-link":case"link":{c.REG_ANCHOR.test(o)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(c.REG_ANCHOR.test(o)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:f}=new URL(this.#s.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===f&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#m??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:f}=this.#m??{};(f==="mousedown"||f==="pointerdown")&&t&c.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const s=t.replace(/^#/,"");let f=this.#s.getElementById(s);for(;f;){if(f===e){i.add(e);break}f=f.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#s.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#m??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(a==="focus"||s==="keydown"&&e.contains(t))){let f=e,m=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(f);if(m=!(b==="none"||p==="hidden"),!m)break}if(f.parentNode&&f.parentNode.nodeType===c.ELEMENT_NODE)f=f.parentNode;else break}m&&i.add(e)}break}case"focus-within":{let t,s=this.#s.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}if(t){let f=e,m=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(f);if(m=!(b==="none"||p==="hidden"),!m)break}if(f.parentNode&&f.parentNode.nodeType===c.ELEMENT_NODE)f=f.parentNode;else break}m&&i.add(e)}break}case"open":{c.REG_INTERACT.test(o)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{c.REG_INTERACT.test(o)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))if(e.disabled||e.hasAttribute("disabled"))i.add(e);else{let t=r;for(;t;){if(c.REG_FORM_GROUP.test(t.localName))if(t.localName==="fieldset"){if(t.disabled&&t.hasAttribute("disabled"))break}else break;t=t.parentNode}t&&r.localName!=="legend"&&(t.disabled||t.hasAttribute("disabled"))&&i.add(e)}break}case"enabled":{(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&i.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,_.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,_.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;o==="textarea"?s=e:o==="input"&&(e.hasAttribute("type")?c.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&o==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))i.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#s.documentElement);const f=s.getElementsByTagName("input"),m=f.length;let b;for(let p=0;p<m;p++){const w=f[p];if(w.getAttribute("type")==="radio"&&(t?w.getAttribute("name")===t&&(b=!!w.checked):w.hasAttribute("name")||(b=!!w.checked),b))break}b||i.add(e)}break}case"default":{if(o==="button"&&!(e.hasAttribute("type")&&c.REG_TYPE_RESET.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#n;let f=(0,_.traverseNode)(t,s);for(f=s.firstChild();f&&t.contains(f);){const m=f.localName;let b;if(m==="button"?b=!(f.hasAttribute("type")&&c.REG_TYPE_RESET.test(f.getAttribute("type"))):m==="input"&&(b=f.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(f.getAttribute("type"))),b){f===e&&i.add(e);break}f=s.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))i.add(e);else if(o==="option"){let t=r,s=!1;for(;t&&t.localName!=="datalist";){if(t.localName==="select"){(t.multiple||t.hasAttribute("multiple"))&&(s=!0);break}t=t.parentNode}if(s)(e.selected||e.hasAttribute("selected"))&&i.add(e);else{const f=new Set,m=this.#n;let b=(0,_.traverseNode)(r,m);for(b=m.firstChild();b;){if(b.selected||b.hasAttribute("selected")){f.add(b);break}b=m.nextSibling()}f.size&&f.has(e)&&i.add(e)}}break}case"valid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(o==="fieldset"){const t=this.#n;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(c.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f&&i.add(e)}break}case"invalid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(o==="fieldset"){const t=this.#n;let s=(0,_.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(c.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f||i.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||c.REG_TYPE_CHECK.test(s)||c.REG_TYPE_DATE.test(s)||c.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||c.REG_TYPE_CHECK.test(s)||c.REG_TYPE_DATE.test(s)||c.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#s.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#r.createTreeWalker(e,c.SHOW_ALL);let s=t.firstChild(),f;for(;s&&(f=s.nodeType!==c.ELEMENT_NODE&&s.nodeType!==c.TEXT_NODE,!!f);)s=t.nextSibling();f&&i.add(e)}else i.add(e);break}case"first-child":{(r&&e===r.firstElementChild||e===this.#t)&&i.add(e);break}case"last-child":{(r&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"only-child":{(r&&e===r.firstElementChild&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"first-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"last-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"only-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#t&&i.add(e);break}case"defined":{const t=e.getAttribute("is");t?(0,M.default)(t)&&this.#a.customElements.get(t)&&i.add(e):(0,M.default)(o)?this.#a.customElements.get(o)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#a.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(a.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${a}`;throw new DOMException(t,c.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(l,e){const{children:h,name:n}=l;let a;if(Array.isArray(h)){const{branches:o}=(0,y.walkAST)(h[0]),[r]=o,[...u]=r,{host:d}=e;if(n==="host"){let i;for(const t of u){const{type:s}=t;if(s===c.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(m,c.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:f}=s;if(f===c.COMBINATOR){const b=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(b,c.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(a=e)}}else if(n==="host")a=e;else{const o=`Invalid selector :${n}`;throw new DOMException(o,c.SYNTAX_ERR)}return a??null}_matchSelector(l,e,h){const{type:n}=l,a=new Set;if(l.name===c.EMPTY)return a;const o=(0,y.unescapeSelector)(l.name);if(typeof o=="string"&&o!==l.name&&(l.name=o),e.nodeType===c.ELEMENT_NODE)switch(n){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(o,h);break}case c.SELECTOR_ID:{e.id===o&&a.add(e);break}case c.SELECTOR_CLASS:{e.classList.contains(o)&&a.add(e);break}case c.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(l,e,h);default:{const r=O.matcher.matchSelector(l,e,h);r&&a.add(r)}}else if(this.#u&&n===c.SELECTOR_PSEUDO_CLASS&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&c.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(l,e,h);if(c.REG_SHADOW_HOST.test(o)){const r=this._matchShadowHostPseudoClass(l,e,h);r&&a.add(r)}}return a}_matchLeaves(l,e,h){const{attributes:n,localName:a,nodeType:o}=e;let r=this.#_.get(l),u;if(r&&r.has(e)){const{attr:d,matched:i}=r.get(e);n?.length===d&&(u=i)}if(typeof u!="boolean"){let d;o===c.ELEMENT_NODE&&c.REG_FORM.test(a)?d=!1:d=!0;for(const i of l){const{name:t,type:s}=i;if(s===c.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(d=!1),u=this._matchSelector(i,e,h).has(e),!u)break}d&&(r||(r=new WeakMap),r.set(e,{attr:n?.length,matched:u}),this.#_.set(l,r))}return!!u}_matchHTMLCollection(l,e={}){const{compound:h,filterLeaves:n}=e,a=new Set,o=l.length;if(o)if(h)for(let r=0;r<o;r++){const u=l[r];this._matchLeaves(n,u,e)&&a.add(u)}else{const r=[].slice.call(l);return new Set(r)}return a}_findDescendantNodes(l,e,h){const[n,...a]=l,o=a.length>0,{type:r}=n,u=(0,y.unescapeSelector)(n.name);typeof u=="string"&&u!==n.name&&(n.name=u);let d=new Set,i=!1;if(this.#u)i=!0;else switch(r){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,h);break}case c.SELECTOR_ID:{if(this.#t.nodeType===c.ELEMENT_NODE)i=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(o?this._matchLeaves(a,t,h)&&d.add(t):d.add(t))}break}case c.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:o,filterLeaves:a});break}case c.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:o,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(l,e,h={}){const{combo:n,leaves:a}=l,{name:o}=n,{parentNode:r}=e,{dir:u}=h,d=new Set;if(u===x)switch(o){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,_.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,_.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let f=(0,_.traverseNode)(e,s);for(f=s.nextNode();f&&e.contains(f);)this._matchLeaves(a,f,h)&&d.add(f),f=s.nextNode()}}}else switch(o){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,_.traverseNode)(r,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{r&&this._matchLeaves(a,r,h)&&d.add(r);break}case" ":default:{const i=[];let t=r;for(;t;)this._matchLeaves(a,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(l,e){const{node:h}=e;let n=(0,_.traverseNode)(h,this.#f),a;if(n)for(n.nodeType!==c.ELEMENT_NODE?n=this.#f.nextNode():n===h&&n!==this.#t&&(n=this.#f.nextNode());n;){if(this._matchLeaves(l,n,{warn:this.#i})){a=n;break}n=this.#f.nextNode()}return a??null}_matchSelf(l){const e=[],h=this._matchLeaves(l,this.#e,{warn:this.#i});let n=!1;return h&&(e.push(this.#e),n=!0),[e,n]}_findLineal(l,e={}){const{complex:h}=e,n=[];let a=this._matchLeaves(l,this.#e,{warn:this.#i}),o=!1;if(a&&(n.push(this.#e),o=!0),!a||h){let r=this.#e.parentNode;for(;r&&(a=this._matchLeaves(l,r,{warn:this.#i}),a&&(n.push(r),o=!0),r.parentNode);)r=r.parentNode}return[n,o]}_findFirst(l){const e=[],h=this._findNode(l,{node:this.#e});let n=!1;return h&&(e.push(h),n=!0),[e,n]}_findFromHTMLCollection(l,e={}){const{complex:h,compound:n,filterLeaves:a,targetType:o}=e;let r=[],u=!1,d=!1;const i=l.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<i;t++){const s=l[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(n){if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else if(r.push(s),u=!0,o===E)break}}else if(h)if(n)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else r=[].slice.call(l),u=!0,d=!0;else if(n)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else r=[].slice.call(l),u=!0,d=!0;return[r,u,d]}_findEntryNodes(l,e,h){const{leaves:n}=l,[a,...o]=n,r=o.length>0,{name:u,type:d}=a;let i=[],t=!1,s=!1,f=!1;switch(d){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{warn:this.#i});break}case c.SELECTOR_ID:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(e===E&&this.#t.nodeType!==c.ELEMENT_NODE){const m=this.#t.getElementById(u);m&&(r?this._matchLeaves(o,m,{warn:this.#i})&&(i.push(m),s=!0):(i.push(m),s=!0))}else e===E?[i,s]=this._findFirst(n):f=!0;break}case c.SELECTOR_CLASS:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(this.#t.nodeType===c.DOCUMENT_NODE){const m=this.#t.getElementsByClassName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:r,filterLeaves:o,targetType:e}))}else e===E?[i,s]=this._findFirst(n):f=!0;break}case c.SELECTOR_TYPE:{if(e===R)[i,s]=this._matchSelf(n);else if(e===C)[i,s]=this._findLineal(n,{complex:h});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#t.getElementsByTagName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:r,filterLeaves:o,targetType:e}))}else e===E?[i,s]=this._findFirst(n):f=!0;break}default:if(e!==C&&c.REG_SHADOW_HOST.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(a,this.#e);m&&(i.push(m),s=!0)}}else e===R?[i,s]=this._matchSelf(n):e===C?[i,s]=this._findLineal(n,{complex:h}):e===E?[i,s]=this._findFirst(n):f=!0}return{collected:t,compound:r,filtered:s,nodes:i,pending:f}}_collectNodes(l){const e=this.#l.values();if(l===L||l===E){const h=new Set;let n=0;for(const{branch:a}of e){const o=a.length,r=o>1,u=a[0];let d,i;if(r){const{combo:p,leaves:[{name:w,type:k}]}=u,N=a[o-1],{leaves:[{name:A,type:v}]}=N;if(v===c.SELECTOR_PSEUDO_ELEMENT||v===c.SELECTOR_ID)d=S,i=N;else if(k===c.SELECTOR_PSEUDO_ELEMENT||k===c.SELECTOR_ID)d=x,i=u;else if(l===L)if(w==="*"&&k===c.SELECTOR_TYPE)d=S,i=N;else if(A==="*"&&v===c.SELECTOR_TYPE)d=x,i=u;else if(o===2){const{name:T}=p;/^[+~]$/.test(T)?(d=S,i=N):(d=x,i=u)}else d=x,i=u;else if(A==="*"&&v===c.SELECTOR_TYPE)d=x,i=u;else if(w==="*"&&k===c.SELECTOR_TYPE)d=S,i=N;else{let T;for(const{combo:D,leaves:[$]}of a){const{name:F,type:z}=$;if(z===c.SELECTOR_PSEUDO_CLASS&&F==="dir"){T=!1;break}if(!T&&D){const{name:H}=D;/^[+~]$/.test(H)&&(T=!0)}}T?(d=x,i=u):(d=S,i=N)}}else d=S,i=u;const{collected:t,compound:s,filtered:f,nodes:m,pending:b}=this._findEntryNodes(i,l,r);m.length?(this.#l[n].find=!0,this.#d[n]=m):b&&h.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=t,this.#l[n].dir=d,this.#l[n].filtered=f||!s,n++}if(h.size){let a,o;this.#e!==this.#t&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,o=this.#f):(a=this.#t,o=this.#n);let r=(0,_.traverseNode)(a,o);for(;r;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?r===this.#e?u=!0:u=this.#e.contains(r):u=!0,u)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,r,{warn:this.#i})){const s=d.get("index");this.#l[s].filtered=!0,this.#l[s].find=!0,this.#d[s].push(r)}}r!==o.currentNode&&(r=(0,_.traverseNode)(r,o)),r=o.nextNode()}}}else{let h=0;for(const{branch:n}of e){const a=n[n.length-1],o=n.length>1,{compound:r,filtered:u,nodes:d}=this._findEntryNodes(a,l,o);d.length&&(this.#l[h].find=!0,this.#d[h]=d),this.#l[h].dir=S,this.#l[h].filtered=u||!r,h++}}return[this.#l,this.#d]}_getCombinedNodes(l,e,h){const n=[];for(const a of e){const o=this._matchCombinator(l,a,{dir:h,warn:this.#i});o.size&&n.push(...o)}return n.length?new Set(n):new Set}_matchNodeNext(l,e,h){const{combo:n,index:a}=h,{combo:o,leaves:r}=l[a],u={combo:n,leaves:r},d=this._getCombinedNodes(u,e,x);let i;if(d.size)if(a===l.length-1){const[t]=(0,_.sortNodes)(d);i=t}else i=this._matchNodeNext(l,d,{combo:o,index:a+1});return i??null}_matchNodePrev(l,e,h){const{index:n}=h,a=l[n],o=new Set([e]),r=this._getCombinedNodes(a,o,S);let u;if(r.size){if(n===0)u=e;else for(const d of r)if(this._matchNodePrev(l,d,{index:n-1}))return e}return u??null}_find(l){(l===L||l===E)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(l),n=e.length;let a=new Set;for(let o=0;o<n;o++){const{branch:r,collected:u,dir:d,find:i}=e[o],t=r.length;if(t&&i){const s=h[o],f=s.length,m=t-1;if(m===0)if((l===L||l===E)&&this.#e.nodeType===c.ELEMENT_NODE)for(let b=0;b<f;b++){const p=s[b];if(p!==this.#e&&this.#e.contains(p)&&(a.add(p),l!==L))break}else if(l===L)if(a.size){const b=[...a];a=new Set([...b,...s]),this.#b=!0}else a=new Set(s);else{const[b]=s;a.add(b)}else if(l===L)if(d===x){let{combo:b}=r[0];for(const p of s){let w=new Set([p]);for(let k=1;k<t;k++){const{combo:N,leaves:A}=r[k],v={combo:b,leaves:A};if(w=this._getCombinedNodes(v,w,d),w.size)if(k===m)if(a.size){const T=[...a];a=new Set([...T,...w]),this.#b=!0}else a=w;else b=N;else break}}}else for(const b of s){let p=new Set([b]);for(let w=m-1;w>=0;w--){const k=r[w];if(p=this._getCombinedNodes(k,p,d),p.size)w===0&&(a.add(b),t>1&&a.size>1&&(this.#b=!0));else break}}else if(l===E&&d===x){const{combo:b}=r[0];let p;for(const w of s)if(p=this._matchNodeNext(r,new Set([w]),{combo:b,index:1}),p){a.add(p);break}if(!p&&!u){const{leaves:w}=r[0],[k]=s;let N=this._findNode(w,{node:k});for(;N;){if(p=this._matchNodeNext(r,new Set([N]),{combo:b,index:1}),p){a.add(p);break}N=this._findNode(w,{node:N})}}}else{let b;for(const p of s)if(b=this._matchNodePrev(r,p,{index:m-1}),b){a.add(p);break}if(!b&&!u&&l===E){const{leaves:p}=r[m],[w]=s;let k=this._findNode(p,{node:w});for(;k;){if(b=this._matchNodePrev(r,k,{index:m-1}),b){a.add(k);break}k=this._findNode(p,{node:k})}}}}}return a}matches(l,e,h){let n;try{if(e?.nodeType!==c.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_A.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#o.match(l,e)}this._setup(l,e,h),n=this._find(R).size}catch(a){this._onError(a)}return!!n}closest(l,e,h){let n;try{if(e?.nodeType!==c.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_A.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#o.closest(l,e)}this._setup(l,e,h);const o=this._find(C);if(o.size){let r=this.#e;for(;r;){if(o.has(r)){n=r;break}r=r.parentNode}}}catch(a){this._onError(a)}return n??null}querySelector(l,e,h){let n;try{(0,_.verifyNode)(e);let a;if(e.nodeType===c.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_B.test(l),descendant:!1};if((0,y.filterSelector)(l,r))return this.#o.first(l,e)}this._setup(l,e,h);const o=this._find(E);o.delete(this.#e),o.size&&([n]=(0,_.sortNodes)(o))}catch(a){this._onError(a)}return n??null}querySelectorAll(l,e,h){let n;try{(0,_.verifyNode)(e);let a;if(e.nodeType===c.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#r&&a.contentType==="text/html"){const r={complex:c.REG_COMPLEX_B.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#o.select(l,e)}this._setup(l,e,h);const o=this._find(L);o.delete(this.#e),o.size&&(this.#b?n=(0,_.sortNodes)(o):n=[...o])}catch(a){this._onError(a)}return n??[]}}0&&(module.exports={Finder});
|
|
2
2
|
//# sourceMappingURL=finder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/finder.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport nwsapi from '@asamuzakjp/nwsapi';\nimport {\n isContentEditable, isInShadowTree, resolveContent, sortNodes, traverseNode,\n verifyNode\n} from './dom-util.js';\nimport { matcher } from './matcher.js';\nimport {\n filterSelector, generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n BIT_01, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE,\n EMPTY, NOT_SUPPORTED_ERR, REG_ANCHOR, REG_COMPLEX_A, REG_COMPLEX_B,\n REG_FORM, REG_FORM_CTRL, REG_FORM_GROUP, REG_FORM_VALID, REG_INTERACT,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, REG_TYPE_CHECK, REG_TYPE_DATE,\n REG_TYPE_RANGE, REG_TYPE_RESET, REG_TYPE_SUBMIT, REG_TYPE_TEXT,\n SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT,\n SELECTOR_TYPE, SHOW_ALL, SYNTAX_ERR, TEXT_NODE, WALKER_FILTER\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: Array<Ast | undefined>\n * #nodes: Array<Nodes>\n * Ast: {\n * branch: Array<Branch | undefined>,\n * collected: boolean,\n * dir: string | null,\n * filtered: boolean,\n * find: boolean\n * }\n * Branch: Array<Twig>\n * Twig: {\n * combo: Leaf | null,\n * leaves: Array<Leaf>\n * }\n * Leaf: {\n * children: Array<Leaf | undefined> | null,\n * loc: null,\n * type: string\n * }\n * Nodes: Array<HTMLElement | undefined>\n */\nexport class Finder {\n /* private fields */\n #ast;\n #cache;\n #content;\n #contentCache;\n #descendant;\n #document;\n #event;\n #node;\n #nodes;\n #noexcept;\n #nwsapi;\n #qswalker;\n #results;\n #root;\n #shadow;\n #sort;\n #walker;\n #walkers;\n #warn;\n #window;\n\n /**\n * construct\n * @param {object} window - window\n * @param {object} document - document\n */\n constructor(window, document) {\n this.#window = window;\n this.#document = document ?? window.document;\n this.#cache = new WeakMap();\n this.#contentCache = new WeakMap();\n this.#results = new WeakMap();\n this._initNwsapi();\n }\n\n /**\n * handle error\n * @private\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (!this.#noexcept) {\n if (e instanceof DOMException ||\n e instanceof this.#window.DOMException) {\n if (e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw new this.#window.DOMException(e.message, e.name);\n }\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @private\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {object} [opt.event] - MouseEvent, KeyboardEvent\n * @param {boolean} [opt.invalidate] - invalidate (for jsdom)\n * @param {boolean} [opt.noexcept] - no exception\n * @param {boolean} [opt.warn] - console warn\n * @returns {object} - node\n */\n _setup(selector, node, opt = {}) {\n const { event, /* invalidate, */ noexcept, warn } = opt;\n // clear cache in jsdom internal process\n /*\n if (invalidate && node.nodeType === ELEMENT_NODE) {\n this.#cache = new WeakMap();\n }\n */\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#event = this._setEvent(event);\n this.#node = node;\n [this.#content, this.#root, this.#walker] = resolveContent(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#walkers = new WeakMap();\n return node;\n }\n\n /**\n * init nwsapi\n * @private\n * @returns {object} - nwsapi\n */\n _initNwsapi() {\n this.#nwsapi = nwsapi({\n DOMException: this.#window.DOMException,\n document: this.#document\n });\n this.#nwsapi.configure({\n LOGERRORS: false\n });\n return this.#nwsapi;\n };\n\n /**\n * set event\n * @private\n * @param {object} event - instance of KeyboardEvent, MouseEvent\n * @returns {object} - result\n */\n _setEvent(event) {\n // NOTE: PointerEvent not implemented in jsdom\n return (event instanceof this.#window.KeyboardEvent ||\n event instanceof this.#window.MouseEvent)\n ? event\n : null;\n }\n\n /**\n * correspond ast and nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _correspond(selector) {\n const nodes = [];\n this.#descendant = false;\n let ast;\n let cacheable;\n if (this.#contentCache.has(this.#content)) {\n const cachedItem = this.#contentCache.get(this.#content);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n const item = cachedItem.get(`${selector}`);\n this.#descendant = item.descendant;\n ast = item.ast;\n cacheable = item.cacheable;\n }\n }\n if (ast) {\n const l = ast.length;\n for (let i = 0; i < l; i++) {\n ast[i].collected = false;\n ast[i].dir = null;\n ast[i].filtered = false;\n ast[i].find = false;\n nodes[i] = [];\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n this._onError(e);\n }\n const {\n branches,\n info: {\n hasHasPseudoFunc,\n hasHyphenSepAttr\n }\n } = walkAST(cssAst);\n if (hasHasPseudoFunc || hasHyphenSepAttr) {\n cacheable = false;\n } else {\n cacheable = true;\n }\n let descendant = false;\n let i = 0;\n ast = [];\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 selector ${selector}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const itemName = item.name;\n if (/^[\\s>]$/.test(itemName)) {\n descendant = true;\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (item) {\n let { name: itemName } = item;\n if (itemName && typeof itemName === 'string') {\n itemName = unescapeSelector(itemName);\n if (typeof itemName === 'string' && itemName !== item.name) {\n item.name = itemName;\n }\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n }\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n collected: false,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = [];\n i++;\n }\n if (cacheable) {\n let cachedItem;\n if (this.#contentCache.has(this.#content)) {\n cachedItem = this.#contentCache.get(this.#content);\n } else {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, {\n ast,\n cacheable,\n descendant\n });\n this.#contentCache.set(this.#content, cachedItem);\n }\n this.#descendant = descendant;\n }\n /*\n if (!cacheable) {\n this.#cache = new WeakMap();\n }\n */\n return [\n ast,\n nodes\n ];\n }\n\n /**\n * create tree walker\n * @private\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - tree walker\n */\n _createTreeWalker(node) {\n let walker;\n if (this.#walkers.has(node)) {\n walker = this.#walkers.get(node);\n } else {\n walker = this.#document.createTreeWalker(node, WALKER_FILTER);\n this.#walkers.set(node, walker);\n }\n return walker;\n }\n\n /**\n * prepare querySelector walker\n * @private\n * @returns {object} - tree walker\n */\n _prepareQuerySelectorWalker() {\n this.#qswalker = this._createTreeWalker(this.#node);\n this.#sort = false;\n return this.#qswalker;\n }\n\n /**\n * collect nth child\n * @private\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 * @param {object} opt - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node, opt) {\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 const { branches } = walkAST(selector);\n selectorBranches = branches;\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const walker = this.#walker;\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n refNode = traverseNode(parentNode, walker);\n const selectorNodes = new Set();\n if (selectorBranches) {\n refNode = walker.firstChild();\n while (refNode) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, refNode, opt);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n // :first-child, :last-child, :nth-child(b of S), :nth-last-child(b of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (selectorNodes.has(refNode)) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n i++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n } else if (!selector) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n }\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 refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n if (refNode && nth >= 0 && nth < l) {\n if (selectorNodes.size) {\n if (selectorNodes.has(refNode)) {\n if (j === nth) {\n matched.add(refNode);\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(refNode);\n }\n nth += a;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n } else {\n break;\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @private\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const walker = this.#walker;\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let j = 0;\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(refNode);\n break;\n }\n j++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\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 refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(refNode);\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 if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @param {object} opt - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName, opt) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const anbMap = new Map();\n if (nthIdentName) {\n if (nthIdentName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (nthIdentName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n 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, opt);\n return nodes;\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n return nodes;\n }\n return new Set();\n }\n\n /**\n * match :has() pseudo-class function\n * @private\n * @param {Array.<object>} astLeaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(astLeaves, node, opt = {}) {\n let bool;\n if (Array.isArray(astLeaves) && astLeaves.length) {\n const leaves = astLeaves.map(i => i);\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 opt.dir = DIR_NEXT;\n const nodes = this._matchCombinator(twig, node, opt);\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool = this._matchHasPseudoFunc(leaves, nextNode, opt);\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 * @private\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node, opt = {}) {\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 for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(leaves, node, opt);\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 opt.forgive = forgive;\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, opt);\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 opt.dir = DIR_PREV;\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, opt);\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @private\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] - forgive unknown pseudo-class\n * @param {boolean} [opt.warn] - warn unsupported pseudo-class\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren, name: astName } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = opt;\n const matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const { branches } = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node, opt);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const [branch] = astChildren;\n const nodes = this._matchAnPlusB(branch, node, astName, opt);\n return nodes;\n } else {\n switch (astName) {\n // :dir(), :lang()\n case 'dir':\n case 'lang': {\n const res = matcher.matchSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // dropped from CSS Selectors 3\n case 'contains': {\n if (warn) {\n const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const { href, origin, pathname } = new URL(this.#content.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'hover': {\n const { target, type } = this.#event ?? {};\n if ((type === 'mouseover' || type === 'pointerover') &&\n node.contains(target)) {\n matched.add(node);\n }\n break;\n }\n case 'active': {\n const { buttons, target, type } = this.#event ?? {};\n if ((type === 'mousedown' || type === 'pointerdown') &&\n buttons & BIT_01 && node.contains(target)) {\n matched.add(node);\n }\n break;\n }\n case 'target': {\n const { hash } = new URL(this.#content.URL);\n if (node.id && hash === `#${node.id}` &&\n this.#content.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(this.#content.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = this.#content.getElementById(id);\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 (!this.#shadow && node === this.#node) {\n matched.add(node);\n }\n } else if (node === this.#content.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus':\n case 'focus-visible': {\n const { target, type } = this.#event ?? {};\n if (node === this.#content.activeElement && node.tabIndex >= 0 &&\n (astName === 'focus' ||\n (type === 'keydown' && node.contains(target)))) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else {\n const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let active;\n let current = this.#content.activeElement;\n if (current.tabIndex >= 0) {\n while (current) {\n if (current === node) {\n active = true;\n break;\n }\n current = current.parentNode;\n }\n }\n if (active) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else {\n const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'open': {\n if (REG_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (REG_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (REG_FORM_CTRL.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 (REG_FORM_GROUP.test(parent.localName)) {\n if (parent.localName === 'fieldset') {\n if (parent.disabled && parent.hasAttribute('disabled')) {\n break;\n }\n } else {\n break;\n }\n }\n parent = parent.parentNode;\n }\n if (parent && parentNode.localName !== 'legend' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((REG_FORM_CTRL.test(localName) ||\n 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 || REG_TYPE_DATE.test(node.type) ||\n REG_TYPE_TEXT.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 || REG_TYPE_DATE.test(node.type) ||\n REG_TYPE_TEXT.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 placeholder;\n if (node.placeholder) {\n placeholder = node.placeholder;\n } else if (node.hasAttribute('placeholder')) {\n placeholder = node.getAttribute('placeholder');\n }\n if (typeof placeholder === 'string' && !/[\\r\\n]/.test(placeholder)) {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (REG_TYPE_TEXT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '') {\n matched.add(node);\n }\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n REG_TYPE_CHECK.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = this.#content.documentElement;\n }\n const items = parent.getElementsByTagName('input');\n const l = items.length;\n let checked;\n for (let i = 0; i < l; i++) {\n const item = items[i];\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 REG_TYPE_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_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 walker = this.#walker;\n let nextNode = traverseNode(form, walker);\n nextNode = walker.firstChild();\n while (nextNode && form.contains(nextNode)) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n REG_TYPE_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n REG_TYPE_SUBMIT.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = walker.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_CHECK.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let parent = parentNode;\n let isMultiple = false;\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 defaultOpt = new Set();\n const walker = this.#walker;\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.selected || refNode.hasAttribute('selected')) {\n defaultOpt.add(refNode);\n break;\n }\n refNode = walker.nextSibling();\n }\n if (defaultOpt.size) {\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n }\n break;\n }\n case 'valid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0) {\n if (node.maxLength >= node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0 && node.maxLength < node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\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 REG_TYPE_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 REG_TYPE_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 (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_TYPE_DATE.test(inputType) ||\n REG_TYPE_TEXT.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_TYPE_DATE.test(inputType) ||\n REG_TYPE_TEXT.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === this.#content.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n let bool;\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#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 (node === this.#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 (node === this.#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 (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'defined': {\n const attr = node.getAttribute('is');\n if (attr) {\n if (isCustomElementName(attr) &&\n this.#window.customElements.get(attr)) {\n matched.add(node);\n }\n } else if (isCustomElementName(localName)) {\n if (this.#window.customElements.get(localName)) {\n matched.add(node);\n }\n // NOTE: MathMLElement not implemented in jsdom\n } else if (node instanceof this.#window.HTMLElement ||\n node instanceof this.#window.SVGElement) {\n matched.add(node);\n }\n break;\n }\n case 'popover-open': {\n if (node.popover) {\n const { display } = this.#window.getComputedStyle(node);\n if (display !== 'none') {\n matched.add(node);\n }\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n // not supported\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'fullscreen':\n case 'future':\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 (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match shadow host pseudo class\n * @private\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren, name: astName } = ast;\n let res;\n if (Array.isArray(astChildren)) {\n const { branches } = walkAST(astChildren[0]);\n const [branch] = branches;\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n const msg = `Invalid selector :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const matched = new Set();\n if (ast.name === EMPTY) {\n return matched;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n }\n default: {\n const res = matcher.matchSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\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 const { attributes, localName, nodeType } = node;\n let result = this.#results.get(leaves);\n let bool;\n if (result && result.has(node)) {\n const { attr, matched } = result.get(node);\n if (attributes?.length === attr) {\n bool = matched;\n }\n }\n if (typeof bool !== 'boolean') {\n let save;\n if (nodeType === ELEMENT_NODE && REG_FORM.test(localName)) {\n save = false;\n } else {\n save = true;\n }\n for (const leaf of leaves) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n save = false;\n }\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n if (save) {\n if (!result) {\n result = new WeakMap();\n }\n result.set(node, {\n attr: attributes?.length,\n matched: bool\n });\n this.#results.set(leaves, result);\n }\n }\n return !!bool;\n }\n\n /**\n * match HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @returns {Set.<object>} - matched nodes\n */\n _matchHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n const nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n return new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (typeof leafName === 'string' && leafName !== leaf.name) {\n leaf.name = leafName;\n }\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (this.#root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = this.#root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, opt);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#content.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const items = baseNode.getElementsByTagName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @private\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} opt - option\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { parentNode } = node;\n const { dir } = opt;\n const matched = new Set();\n if (dir === DIR_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = traverseNode(node, walker);\n refNode = walker.nextSibling();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n const walker = this._createTreeWalker(node);\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n return nodes;\n }\n if (pending) {\n const walker = this._createTreeWalker(node);\n let refNode = traverseNode(node, walker);\n refNode = walker.nextNode();\n while (refNode && node.contains(refNode)) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.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, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode === node) {\n break;\n } else {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n if (parentNode) {\n const bool = this._matchLeaves(leaves, parentNode, opt);\n if (bool) {\n matched.add(parentNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n return new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find matched node from #qswalker\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} [opt] - options\n * @param {object} [opt.node] - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, opt) {\n const { node } = opt;\n let refNode = traverseNode(node, this.#qswalker);\n let matchedNode;\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = this.#qswalker.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = this.#qswalker.nextNode();\n }\n }\n while (refNode) {\n const matched = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (matched) {\n matchedNode = refNode;\n break;\n }\n refNode = this.#qswalker.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * match self\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _matchSelf(leaves) {\n const nodes = [];\n const bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find lineal\n * @private\n * @param {Array} leaves - AST leaves\n * @param {object} opt - options\n * @returns {Array} - [nodes, filtered]\n */\n _findLineal(leaves, opt = {}) {\n const { complex } = opt;\n const nodes = [];\n let bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n if (!bool || complex) {\n let refNode = this.#node.parentNode;\n while (refNode) {\n bool = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(refNode);\n filtered = true;\n }\n if (refNode.parentNode) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find first\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFirst(leaves) {\n const nodes = [];\n const node = this._findNode(leaves, {\n node: this.#node\n });\n let filtered = false;\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find from HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @param {boolean} [opt.compound] - compound selector\n * @param {Array} [opt.filterLeaves] - filter leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFromHTMLCollection(items, opt = {}) {\n const { complex, compound, filterLeaves, targetType } = opt;\n let nodes = [];\n let filtered = false;\n let collected = false;\n const l = items.length;\n if (l) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n if (node !== this.#node &&\n (this.#node.contains(node) || node.contains(this.#node))) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n } else {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (complex) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n } else if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n }\n return [nodes, filtered, collected];\n }\n\n /**\n * find entry nodes\n * @private\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @param {boolean} complex - complex selector\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType, complex) {\n const { leaves } = twig;\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { name: leafName, type: leafType } = leaf;\n let nodes = [];\n let collected = false;\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const items = this.#root.getElementsByClassName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#content.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\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 branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT ||\n lastType === SELECTOR_ID) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (branchLen === 2) {\n const { name: comboName } = firstCombo;\n if (/^[+~]$/.test(comboName)) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n let bool;\n for (const { combo, leaves: [leaf] } of branch) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n bool = false;\n break;\n }\n if (!bool && combo) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n const {\n collected, compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].collected = collected;\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#qswalker;\n } else {\n node = this.#root;\n walker = this.#walker;\n }\n let nextNode = traverseNode(node, walker);\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (nextNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(nextNode);\n }\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 warn: this.#warn\n });\n if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].push(nextNode);\n }\n }\n }\n if (nextNode !== walker.currentNode) {\n nextNode = traverseNode(nextNode, walker);\n }\n nextNode = walker.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const complex = branch.length > 1;\n const {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n }\n this.#ast[i].dir = DIR_PREV;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * get combined nodes\n * @private\n * @param {object} twig - twig\n * @param {object} nodes - collection of nodes\n * @param {string} dir - direction\n * @returns {Array.<object>} - collection of matched nodes\n */\n _getCombinedNodes(twig, nodes, dir) {\n const arr = [];\n for (const node of nodes) {\n const matched = this._matchCombinator(twig, node, {\n dir,\n warn: this.#warn\n });\n if (matched.size) {\n arr.push(...matched);\n }\n }\n if (arr.length) {\n return new Set(arr);\n }\n return new Set();\n }\n\n /**\n * match node to next direction\n * @private\n * @param {Array} branch - branch\n * @param {Set.<object>} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], nodes] = this._collectNodes(targetType);\n const l = branches.length;\n let res = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, collected, dir, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = nodes[i];\n const entryNodesLen = entryNodes.length;\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 (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n if (node !== this.#node && this.#node.contains(node)) {\n res.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (res.size) {\n const n = [...res];\n res = new Set([...n, ...entryNodes]);\n this.#sort = true;\n } else {\n res = new Set(entryNodes);\n }\n } else {\n const [node] = entryNodes;\n res.add(node);\n }\n } else if (targetType === TARGET_ALL) {\n if (dir === DIR_NEXT) {\n let { combo } = branch[0];\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const twig = {\n combo,\n leaves\n };\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === lastIndex) {\n if (res.size) {\n const n = [...res];\n res = new Set([...n, ...nextNodes]);\n this.#sort = true;\n } else {\n res = nextNodes;\n }\n } else {\n combo = nextCombo;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === 0) {\n res.add(node);\n if (branchLen > 1 && res.size > 1) {\n this.#sort = true;\n }\n }\n } else {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST && dir === DIR_NEXT) {\n const { combo: entryCombo } = branch[0];\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodeNext(branch, new Set([node]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n res.add(matched);\n break;\n }\n }\n if (!matched && !collected) {\n const { leaves: entryLeaves } = branch[0];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodeNext(branch, new Set([refNode]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n res.add(matched);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n } else {\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodePrev(branch, node, {\n index: lastIndex - 1\n });\n if (matched) {\n res.add(node);\n break;\n }\n }\n if (!matched && !collected && targetType === TARGET_FIRST) {\n const { leaves: entryLeaves } = branch[lastIndex];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodePrev(branch, refNode, {\n index: lastIndex - 1\n });\n if (matched) {\n res.add(refNode);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n }\n }\n }\n return res;\n }\n\n /**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n let res;\n try {\n if (node?.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node?.nodeName}`;\n throw new TypeError(msg);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX_A.test(selector),\n descendant: true\n };\n if (filterSelector(selector, filterOpt)) {\n return this.#nwsapi.match(selector, node);\n }\n }\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_SELF);\n res = nodes.size;\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n let res;\n try {\n if (node?.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node?.nodeName}`;\n throw new TypeError(msg);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX_A.test(selector),\n descendant: true\n };\n if (filterSelector(selector, filterOpt)) {\n return this.#nwsapi.closest(selector, node);\n }\n }\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = this.#node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n let res;\n try {\n verifyNode(node);\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX_B.test(selector),\n descendant: false\n };\n if (filterSelector(selector, filterOpt)) {\n return this.#nwsapi.first(selector, node);\n }\n }\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n let res;\n try {\n verifyNode(node);\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX_B.test(selector),\n descendant: true\n };\n if (filterSelector(selector, filterOpt)) {\n return this.#nwsapi.select(selector, node);\n }\n }\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n if (this.#sort) {\n res = sortNodes(nodes);\n } else {\n res = [...nodes];\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAAmB,mCACnBC,EAGO,yBACPC,EAAwB,wBACxBC,EAEO,uBAGPC,EAQO,yBACP,MAAMC,EAAW,OACXC,EAAW,OACXC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OA0Bb,MAAMb,CAAO,CAElBc,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAOA,YAAYC,EAAQC,EAAU,CAC5B,KAAKF,GAAUC,EACf,KA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AAC,CACjB,CACA,OAAO0D,GAAO,CAAC,CACjB,CACF",
|
|
6
|
-
"names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_is_potential_custom_element_name", "import_nwsapi", "import_dom_util", "import_matcher", "import_parser", "import_constant", "DIR_NEXT", "DIR_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#cache", "#content", "#contentCache", "#descendant", "#document", "#event", "#node", "#nodes", "#noexcept", "#nwsapi", "#qswalker", "#results", "#root", "#shadow", "#sort", "#walker", "#walkers", "#warn", "#window", "window", "document", "e", "selector", "node", "opt", "event", "noexcept", "warn", "nwsapi", "nodes", "ast", "
|
|
4
|
+
"sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport nwsapi from '@asamuzakjp/nwsapi';\nimport {\n isContentEditable, isInShadowTree, resolveContent, sortNodes, traverseNode,\n verifyNode\n} from './dom-util.js';\nimport { matcher } from './matcher.js';\nimport {\n filterSelector, generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n BIT_01, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE,\n EMPTY, NOT_SUPPORTED_ERR, REG_ANCHOR, REG_COMPLEX_A, REG_COMPLEX_B,\n REG_FORM, REG_FORM_CTRL, REG_FORM_GROUP, REG_FORM_VALID, REG_INTERACT,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, REG_TYPE_CHECK, REG_TYPE_DATE,\n REG_TYPE_RANGE, REG_TYPE_RESET, REG_TYPE_SUBMIT, REG_TYPE_TEXT,\n SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT,\n SELECTOR_TYPE, SHOW_ALL, SYNTAX_ERR, TEXT_NODE, WALKER_FILTER\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: Array<Ast | undefined>\n * #nodes: Array<Nodes>\n * Ast: {\n * branch: Array<Branch | undefined>,\n * collected: boolean,\n * dir: string | null,\n * filtered: boolean,\n * find: boolean\n * }\n * Branch: Array<Twig>\n * Twig: {\n * combo: Leaf | null,\n * leaves: Array<Leaf>\n * }\n * Leaf: {\n * children: Array<Leaf | undefined> | null,\n * loc: null,\n * type: string\n * }\n * Nodes: Array<HTMLElement | undefined>\n */\nexport class Finder {\n /* private fields */\n #ast;\n #cache;\n #content;\n #contentCache;\n #descendant;\n #document;\n #event;\n #node;\n #nodes;\n #noexcept;\n #nwsapi;\n #qswalker;\n #results;\n #root;\n #shadow;\n #sort;\n #walker;\n #walkers;\n #warn;\n #window;\n\n /**\n * construct\n * @param {object} window - window\n * @param {object} document - document\n */\n constructor(window, document) {\n this.#window = window;\n this.#document = document ?? window.document;\n this.#cache = new WeakMap();\n this.#contentCache = new WeakMap();\n this.#results = new WeakMap();\n this._initNwsapi();\n }\n\n /**\n * handle error\n * @private\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (!this.#noexcept) {\n if (e instanceof DOMException ||\n e instanceof this.#window.DOMException) {\n if (e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw new this.#window.DOMException(e.message, e.name);\n }\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @private\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {object} [opt.event] - MouseEvent, KeyboardEvent\n * @param {boolean} [opt.noexcept] - no exception\n * @param {boolean} [opt.warn] - console warn\n * @returns {object} - node\n */\n _setup(selector, node, opt = {}) {\n const { event, noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#event = this._setEvent(event);\n this.#node = node;\n [this.#content, this.#root, this.#walker] = resolveContent(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#walkers = new WeakMap();\n return node;\n }\n\n /**\n * init nwsapi\n * @private\n * @returns {object} - nwsapi\n */\n _initNwsapi() {\n this.#nwsapi = nwsapi({\n DOMException: this.#window.DOMException,\n document: this.#document\n });\n this.#nwsapi.configure({\n LOGERRORS: false\n });\n return this.#nwsapi;\n };\n\n /**\n * set event\n * @private\n * @param {object} event - instance of KeyboardEvent, MouseEvent\n * @returns {object} - result\n */\n _setEvent(event) {\n // NOTE: PointerEvent not implemented in jsdom\n return (event instanceof this.#window.KeyboardEvent ||\n event instanceof this.#window.MouseEvent)\n ? event\n : null;\n }\n\n /**\n * correspond ast and nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _correspond(selector) {\n const nodes = [];\n this.#descendant = false;\n let ast;\n if (this.#contentCache.has(this.#content)) {\n const cachedItem = this.#contentCache.get(this.#content);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n const item = cachedItem.get(`${selector}`);\n this.#descendant = item.descendant;\n ast = item.ast;\n }\n }\n if (ast) {\n const l = ast.length;\n for (let i = 0; i < l; i++) {\n ast[i].collected = false;\n ast[i].dir = null;\n ast[i].filtered = false;\n ast[i].find = false;\n nodes[i] = [];\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n this._onError(e);\n }\n const {\n branches,\n info: {\n hasHasPseudoFunc,\n hasHyphenSepAttr\n }\n } = walkAST(cssAst);\n let cacheable;\n if (hasHasPseudoFunc || hasHyphenSepAttr) {\n cacheable = false;\n } else {\n cacheable = true;\n }\n let descendant = false;\n let i = 0;\n ast = [];\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 selector ${selector}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const itemName = item.name;\n if (/^[\\s>]$/.test(itemName)) {\n descendant = true;\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (item) {\n let { name: itemName } = item;\n if (itemName && typeof itemName === 'string') {\n itemName = unescapeSelector(itemName);\n if (typeof itemName === 'string' && itemName !== item.name) {\n item.name = itemName;\n }\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n }\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n collected: false,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = [];\n i++;\n }\n if (cacheable) {\n let cachedItem;\n if (this.#contentCache.has(this.#content)) {\n cachedItem = this.#contentCache.get(this.#content);\n } else {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, {\n ast,\n descendant\n });\n this.#contentCache.set(this.#content, cachedItem);\n }\n this.#descendant = descendant;\n }\n return [\n ast,\n nodes\n ];\n }\n\n /**\n * create tree walker\n * @private\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - tree walker\n */\n _createTreeWalker(node) {\n let walker;\n if (this.#walkers.has(node)) {\n walker = this.#walkers.get(node);\n } else {\n walker = this.#document.createTreeWalker(node, WALKER_FILTER);\n this.#walkers.set(node, walker);\n }\n return walker;\n }\n\n /**\n * prepare querySelector walker\n * @private\n * @returns {object} - tree walker\n */\n _prepareQuerySelectorWalker() {\n this.#qswalker = this._createTreeWalker(this.#node);\n this.#sort = false;\n return this.#qswalker;\n }\n\n /**\n * collect nth child\n * @private\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 * @param {object} opt - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node, opt) {\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 const { branches } = walkAST(selector);\n selectorBranches = branches;\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const walker = this.#walker;\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n refNode = traverseNode(parentNode, walker);\n const selectorNodes = new Set();\n if (selectorBranches) {\n refNode = walker.firstChild();\n while (refNode) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, refNode, opt);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n // :first-child, :last-child, :nth-child(b of S), :nth-last-child(b of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (selectorNodes.has(refNode)) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n i++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n } else if (!selector) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n while (refNode) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n }\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 refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let i = 0;\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n if (refNode && nth >= 0 && nth < l) {\n if (selectorNodes.size) {\n if (selectorNodes.has(refNode)) {\n if (j === nth) {\n matched.add(refNode);\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(refNode);\n }\n nth += a;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n } else {\n break;\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @private\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const walker = this.#walker;\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n let l = 0;\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let j = 0;\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(refNode);\n break;\n }\n j++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\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 refNode = traverseNode(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n let j = a > 0 ? 0 : b - 1;\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(refNode);\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 if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n return new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @param {object} opt - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName, opt) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const anbMap = new Map();\n if (nthIdentName) {\n if (nthIdentName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (nthIdentName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n 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, opt);\n return nodes;\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n return nodes;\n }\n return new Set();\n }\n\n /**\n * match :has() pseudo-class function\n * @private\n * @param {Array.<object>} astLeaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(astLeaves, node, opt = {}) {\n let bool;\n if (Array.isArray(astLeaves) && astLeaves.length) {\n const leaves = astLeaves.map(i => i);\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 opt.dir = DIR_NEXT;\n const nodes = this._matchCombinator(twig, node, opt);\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool = this._matchHasPseudoFunc(leaves, nextNode, opt);\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 * @private\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node, opt = {}) {\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 for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(leaves, node, opt);\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 opt.forgive = forgive;\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, opt);\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 opt.dir = DIR_PREV;\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, opt);\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @private\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] - forgive unknown pseudo-class\n * @param {boolean} [opt.warn] - warn unsupported pseudo-class\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren, name: astName } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = opt;\n const matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const { branches } = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node, opt);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const [branch] = astChildren;\n const nodes = this._matchAnPlusB(branch, node, astName, opt);\n return nodes;\n } else {\n switch (astName) {\n // :dir(), :lang()\n case 'dir':\n case 'lang': {\n const res = matcher.matchSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // dropped from CSS Selectors 3\n case 'contains': {\n if (warn) {\n const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (REG_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const { href, origin, pathname } = new URL(this.#content.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'hover': {\n const { target, type } = this.#event ?? {};\n if ((type === 'mouseover' || type === 'pointerover') &&\n node.contains(target)) {\n matched.add(node);\n }\n break;\n }\n case 'active': {\n const { buttons, target, type } = this.#event ?? {};\n if ((type === 'mousedown' || type === 'pointerdown') &&\n buttons & BIT_01 && node.contains(target)) {\n matched.add(node);\n }\n break;\n }\n case 'target': {\n const { hash } = new URL(this.#content.URL);\n if (node.id && hash === `#${node.id}` &&\n this.#content.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(this.#content.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = this.#content.getElementById(id);\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 (!this.#shadow && node === this.#node) {\n matched.add(node);\n }\n } else if (node === this.#content.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus':\n case 'focus-visible': {\n const { target, type } = this.#event ?? {};\n if (node === this.#content.activeElement && node.tabIndex >= 0 &&\n (astName === 'focus' ||\n (type === 'keydown' && node.contains(target)))) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else {\n const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let active;\n let current = this.#content.activeElement;\n if (current.tabIndex >= 0) {\n while (current) {\n if (current === node) {\n active = true;\n break;\n }\n current = current.parentNode;\n }\n }\n if (active) {\n let refNode = node;\n let focus = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled') ||\n refNode.hidden || refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else {\n const { display, visibility } =\n this.#window.getComputedStyle(refNode);\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'open': {\n if (REG_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (REG_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (REG_FORM_CTRL.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 (REG_FORM_GROUP.test(parent.localName)) {\n if (parent.localName === 'fieldset') {\n if (parent.disabled && parent.hasAttribute('disabled')) {\n break;\n }\n } else {\n break;\n }\n }\n parent = parent.parentNode;\n }\n if (parent && parentNode.localName !== 'legend' &&\n (parent.disabled || parent.hasAttribute('disabled'))) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((REG_FORM_CTRL.test(localName) ||\n 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 || REG_TYPE_DATE.test(node.type) ||\n REG_TYPE_TEXT.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 || REG_TYPE_DATE.test(node.type) ||\n REG_TYPE_TEXT.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 placeholder;\n if (node.placeholder) {\n placeholder = node.placeholder;\n } else if (node.hasAttribute('placeholder')) {\n placeholder = node.getAttribute('placeholder');\n }\n if (typeof placeholder === 'string' && !/[\\r\\n]/.test(placeholder)) {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (REG_TYPE_TEXT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '') {\n matched.add(node);\n }\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n REG_TYPE_CHECK.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = this.#content.documentElement;\n }\n const items = parent.getElementsByTagName('input');\n const l = items.length;\n let checked;\n for (let i = 0; i < l; i++) {\n const item = items[i];\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 REG_TYPE_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_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 walker = this.#walker;\n let nextNode = traverseNode(form, walker);\n nextNode = walker.firstChild();\n while (nextNode && form.contains(nextNode)) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n REG_TYPE_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n REG_TYPE_SUBMIT.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = walker.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n REG_TYPE_CHECK.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let parent = parentNode;\n let isMultiple = false;\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 defaultOpt = new Set();\n const walker = this.#walker;\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode.selected || refNode.hasAttribute('selected')) {\n defaultOpt.add(refNode);\n break;\n }\n refNode = walker.nextSibling();\n }\n if (defaultOpt.size) {\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n }\n break;\n }\n case 'valid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0) {\n if (node.maxLength >= node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (REG_FORM_VALID.test(localName)) {\n if (node.checkValidity()) {\n if (node.maxLength >= 0 && node.maxLength < node.value.length) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const walker = this.#walker;\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n let bool;\n if (!refNode) {\n bool = true;\n } else {\n while (refNode && node.contains(refNode)) {\n if (REG_FORM_VALID.test(refNode.localName)) {\n if (refNode.checkValidity()) {\n if (refNode.maxLength >= 0) {\n bool = refNode.maxLength >= refNode.value.length;\n } else {\n bool = true;\n }\n } else {\n bool = false;\n }\n if (!bool) {\n break;\n }\n }\n refNode = walker.nextNode();\n }\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 REG_TYPE_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 REG_TYPE_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 (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_TYPE_DATE.test(inputType) ||\n REG_TYPE_TEXT.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || REG_TYPE_CHECK.test(inputType) ||\n REG_TYPE_DATE.test(inputType) ||\n REG_TYPE_TEXT.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === this.#content.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n let bool;\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#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 (node === this.#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 (node === this.#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 (node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'defined': {\n const attr = node.getAttribute('is');\n if (attr) {\n if (isCustomElementName(attr) &&\n this.#window.customElements.get(attr)) {\n matched.add(node);\n }\n } else if (isCustomElementName(localName)) {\n if (this.#window.customElements.get(localName)) {\n matched.add(node);\n }\n // NOTE: MathMLElement not implemented in jsdom\n } else if (node instanceof this.#window.HTMLElement ||\n node instanceof this.#window.SVGElement) {\n matched.add(node);\n }\n break;\n }\n case 'popover-open': {\n if (node.popover) {\n const { display } = this.#window.getComputedStyle(node);\n if (display !== 'none') {\n matched.add(node);\n }\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n // not supported\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'fullscreen':\n case 'future':\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 (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match shadow host pseudo class\n * @private\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren, name: astName } = ast;\n let res;\n if (Array.isArray(astChildren)) {\n const { branches } = walkAST(astChildren[0]);\n const [branch] = branches;\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n const msg = `Invalid selector :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const matched = new Set();\n if (ast.name === EMPTY) {\n return matched;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n }\n default: {\n const res = matcher.matchSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n return nodes;\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\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 const { attributes, localName, nodeType } = node;\n let result = this.#results.get(leaves);\n let bool;\n if (result && result.has(node)) {\n const { attr, matched } = result.get(node);\n if (attributes?.length === attr) {\n bool = matched;\n }\n }\n if (typeof bool !== 'boolean') {\n let save;\n if (nodeType === ELEMENT_NODE && REG_FORM.test(localName)) {\n save = false;\n } else {\n save = true;\n }\n for (const leaf of leaves) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n save = false;\n }\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n if (save) {\n if (!result) {\n result = new WeakMap();\n }\n result.set(node, {\n attr: attributes?.length,\n matched: bool\n });\n this.#results.set(leaves, result);\n }\n }\n return !!bool;\n }\n\n /**\n * match HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @returns {Set.<object>} - matched nodes\n */\n _matchHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n const nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n return new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (typeof leafName === 'string' && leafName !== leaf.name) {\n leaf.name = leafName;\n }\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (this.#root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = this.#root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, opt);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#content.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const items = baseNode.getElementsByTagName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @private\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} opt - option\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { parentNode } = node;\n const { dir } = opt;\n const matched = new Set();\n if (dir === DIR_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = traverseNode(node, walker);\n refNode = walker.nextSibling();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n const walker = this._createTreeWalker(node);\n let refNode = traverseNode(node, walker);\n refNode = walker.firstChild();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n return nodes;\n }\n if (pending) {\n const walker = this._createTreeWalker(node);\n let refNode = traverseNode(node, walker);\n refNode = walker.nextNode();\n while (refNode && node.contains(refNode)) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.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, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n if (parentNode) {\n const walker = this._createTreeWalker(parentNode);\n let refNode = traverseNode(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n if (refNode === node) {\n break;\n } else {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n if (parentNode) {\n const bool = this._matchLeaves(leaves, parentNode, opt);\n if (bool) {\n matched.add(parentNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n return new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find matched node from #qswalker\n * @private\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} [opt] - options\n * @param {object} [opt.node] - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, opt) {\n const { node } = opt;\n let refNode = traverseNode(node, this.#qswalker);\n let matchedNode;\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = this.#qswalker.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = this.#qswalker.nextNode();\n }\n }\n while (refNode) {\n const matched = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (matched) {\n matchedNode = refNode;\n break;\n }\n refNode = this.#qswalker.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * match self\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _matchSelf(leaves) {\n const nodes = [];\n const bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find lineal\n * @private\n * @param {Array} leaves - AST leaves\n * @param {object} opt - options\n * @returns {Array} - [nodes, filtered]\n */\n _findLineal(leaves, opt = {}) {\n const { complex } = opt;\n const nodes = [];\n let bool = this._matchLeaves(leaves, this.#node, {\n warn: this.#warn\n });\n let filtered = false;\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n if (!bool || complex) {\n let refNode = this.#node.parentNode;\n while (refNode) {\n bool = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(refNode);\n filtered = true;\n }\n if (refNode.parentNode) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find first\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFirst(leaves) {\n const nodes = [];\n const node = this._findNode(leaves, {\n node: this.#node\n });\n let filtered = false;\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find from HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @param {boolean} [opt.compound] - compound selector\n * @param {Array} [opt.filterLeaves] - filter leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFromHTMLCollection(items, opt = {}) {\n const { complex, compound, filterLeaves, targetType } = opt;\n let nodes = [];\n let filtered = false;\n let collected = false;\n const l = items.length;\n if (l) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n if (node !== this.#node &&\n (this.#node.contains(node) || node.contains(this.#node))) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n } else {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (complex) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n } else if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n collected = true;\n }\n }\n return [nodes, filtered, collected];\n }\n\n /**\n * find entry nodes\n * @private\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @param {boolean} complex - complex selector\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType, complex) {\n const { leaves } = twig;\n const [leaf, ...filterLeaves] = leaves;\n const compound = filterLeaves.length > 0;\n const { name: leafName, type: leafType } = leaf;\n let nodes = [];\n let collected = false;\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matcher.matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const items = this.#root.getElementsByClassName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (this.#content.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n if (items.length) {\n [nodes, filtered, collected] = this._findFromHTMLCollection(items, {\n complex,\n compound,\n filterLeaves,\n targetType\n });\n }\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaves, {\n complex\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n collected,\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * collect nodes\n * @private\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 branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT ||\n lastType === SELECTOR_ID) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (branchLen === 2) {\n const { name: comboName } = firstCombo;\n if (/^[+~]$/.test(comboName)) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n let bool;\n for (const { combo, leaves: [leaf] } of branch) {\n const { name: leafName, type: leafType } = leaf;\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n bool = false;\n break;\n }\n if (!bool && combo) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n const {\n collected, compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].collected = collected;\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#qswalker;\n } else {\n node = this.#root;\n walker = this.#walker;\n }\n let nextNode = traverseNode(node, walker);\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (nextNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(nextNode);\n }\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 warn: this.#warn\n });\n if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].push(nextNode);\n }\n }\n }\n if (nextNode !== walker.currentNode) {\n nextNode = traverseNode(nextNode, walker);\n }\n nextNode = walker.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const complex = branch.length > 1;\n const {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n }\n this.#ast[i].dir = DIR_PREV;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * get combined nodes\n * @private\n * @param {object} twig - twig\n * @param {object} nodes - collection of nodes\n * @param {string} dir - direction\n * @returns {Array.<object>} - collection of matched nodes\n */\n _getCombinedNodes(twig, nodes, dir) {\n const arr = [];\n for (const node of nodes) {\n const matched = this._matchCombinator(twig, node, {\n dir,\n warn: this.#warn\n });\n if (matched.size) {\n arr.push(...matched);\n }\n }\n if (arr.length) {\n return new Set(arr);\n }\n return new Set();\n }\n\n /**\n * match node to next direction\n * @private\n * @param {Array} branch - branch\n * @param {Set.<object>} nodes - collection of Element node\n * @param {object} opt - option\n * @param {object} opt.combo - combo\n * @returns {?object} - matched node\n */\n _matchNodeNext(branch, nodes, opt) {\n const { combo, index } = opt;\n const { combo: nextCombo, leaves } = branch[index];\n const twig = {\n combo,\n leaves\n };\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_NEXT);\n let res;\n if (nextNodes.size) {\n if (index === branch.length - 1) {\n const [nextNode] = sortNodes(nextNodes);\n res = nextNode;\n } else {\n res = this._matchNodeNext(branch, nextNodes, {\n combo: nextCombo,\n index: index + 1\n });\n }\n }\n return res ?? null;\n }\n\n /**\n * match node to previous direction\n * @private\n * @param {Array} branch - branch\n * @param {object} node - Element node\n * @param {object} opt - option\n * @param {number} opt.index - index\n * @returns {?object} - node\n */\n _matchNodePrev(branch, node, opt) {\n const { index } = opt;\n const twig = branch[index];\n const nodes = new Set([node]);\n const nextNodes = this._getCombinedNodes(twig, nodes, DIR_PREV);\n let res;\n if (nextNodes.size) {\n if (index === 0) {\n res = node;\n } else {\n for (const nextNode of nextNodes) {\n const matched = this._matchNodePrev(branch, nextNode, {\n index: index - 1\n });\n if (matched) {\n return node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * find matched nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType) {\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this._prepareQuerySelectorWalker();\n }\n const [[...branches], nodes] = this._collectNodes(targetType);\n const l = branches.length;\n let res = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, collected, dir, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = nodes[i];\n const entryNodesLen = entryNodes.length;\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 (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n if (node !== this.#node && this.#node.contains(node)) {\n res.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (res.size) {\n const n = [...res];\n res = new Set([...n, ...entryNodes]);\n this.#sort = true;\n } else {\n res = new Set(entryNodes);\n }\n } else {\n const [node] = entryNodes;\n res.add(node);\n }\n } else if (targetType === TARGET_ALL) {\n if (dir === DIR_NEXT) {\n let { combo } = branch[0];\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const twig = {\n combo,\n leaves\n };\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === lastIndex) {\n if (res.size) {\n const n = [...res];\n res = new Set([...n, ...nextNodes]);\n this.#sort = true;\n } else {\n res = nextNodes;\n }\n } else {\n combo = nextCombo;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of entryNodes) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n nextNodes = this._getCombinedNodes(twig, nextNodes, dir);\n if (nextNodes.size) {\n if (j === 0) {\n res.add(node);\n if (branchLen > 1 && res.size > 1) {\n this.#sort = true;\n }\n }\n } else {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST && dir === DIR_NEXT) {\n const { combo: entryCombo } = branch[0];\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodeNext(branch, new Set([node]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n res.add(matched);\n break;\n }\n }\n if (!matched && !collected) {\n const { leaves: entryLeaves } = branch[0];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodeNext(branch, new Set([refNode]), {\n combo: entryCombo,\n index: 1\n });\n if (matched) {\n res.add(matched);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n } else {\n let matched;\n for (const node of entryNodes) {\n matched = this._matchNodePrev(branch, node, {\n index: lastIndex - 1\n });\n if (matched) {\n res.add(node);\n break;\n }\n }\n if (!matched && !collected && targetType === TARGET_FIRST) {\n const { leaves: entryLeaves } = branch[lastIndex];\n const [entryNode] = entryNodes;\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n matched = this._matchNodePrev(branch, refNode, {\n index: lastIndex - 1\n });\n if (matched) {\n res.add(refNode);\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n }\n }\n }\n }\n }\n return res;\n }\n\n /**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n let res;\n try {\n if (node?.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node?.nodeName}`;\n throw new TypeError(msg);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX_A.test(selector),\n descendant: true\n };\n if (filterSelector(selector, filterOpt)) {\n return this.#nwsapi.match(selector, node);\n }\n }\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_SELF);\n res = nodes.size;\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n let res;\n try {\n if (node?.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node?.nodeName}`;\n throw new TypeError(msg);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX_A.test(selector),\n descendant: true\n };\n if (filterSelector(selector, filterOpt)) {\n return this.#nwsapi.closest(selector, node);\n }\n }\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = this.#node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n let res;\n try {\n verifyNode(node);\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX_B.test(selector),\n descendant: false\n };\n if (filterSelector(selector, filterOpt)) {\n return this.#nwsapi.first(selector, node);\n }\n }\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n let res;\n try {\n verifyNode(node);\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX_B.test(selector),\n descendant: true\n };\n if (filterSelector(selector, filterOpt)) {\n return this.#nwsapi.select(selector, node);\n }\n }\n this._setup(selector, node, opt);\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n if (this.#sort) {\n res = sortNodes(nodes);\n } else {\n res = [...nodes];\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
|
|
5
|
+
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAAmB,mCACnBC,EAGO,yBACPC,EAAwB,wBACxBC,EAEO,uBAGPC,EAQO,yBACP,MAAMC,EAAW,OACXC,EAAW,OACXC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OA0Bb,MAAMb,CAAO,CAElBc,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAOA,YAAYC,EAAQC,EAAU,CAC5B,KAAKF,GAAUC,EACf,KAAKf,GAAYgB,GAAYD,EAAO,SACpC,KAAKnB,GAAS,IAAI,QAClB,KAAKE,GAAgB,IAAI,QACzB,KAAKS,GAAW,IAAI,QACpB,KAAK,YAAY,CACnB,CASA,SAASU,EAAG,CACV,GAAI,CAAC,KAAKb,GACR,GAAIa,aAAa,cACbA,aAAa,KAAKH,GAAQ,aAC5B,GAAIG,EAAE,OAAS,oBACT,KAAKJ,IACP,QAAQ,KAAKI,EAAE,OAAO,MAGxB,OAAM,IAAI,KAAKH,GAAQ,aAAaG,EAAE,QAASA,EAAE,IAAI,MAGvD,OAAMA,CAGZ,CAaA,OAAOC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CAC/B,KAAM,CA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OAAO,KAAKvB,EAAK,EACnBuB,EAAM,OACR,CAACkD,CAAG,KAAI,aAAUlD,CAAK,EAE3B,OAASR,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAO0D,GAAO,IAChB,CAUA,iBAAiBzD,EAAUC,EAAMC,EAAK,CACpC,IAAIuD,EACJ,GAAI,IACF,cAAWxD,CAAI,EACf,IAAIH,EAMJ,GALIG,EAAK,WAAa,gBACpBH,EAAWG,EAEXH,EAAWG,EAAK,cAEdH,IAAa,KAAKhB,IAAagB,EAAS,cAAgB,YAAa,CACvE,MAAMoI,EAAY,CAChB,QAAS,gBAAc,KAAKlI,CAAQ,EACpC,WAAY,EACd,EACA,MAAI,kBAAeA,EAAUkI,CAAS,EACpC,OAAO,KAAK/I,GAAQ,OAAOa,EAAUC,CAAI,CAE7C,CACA,KAAK,OAAOD,EAAUC,EAAMC,CAAG,EAC/B,MAAMK,EAAQ,KAAK,MAAMlC,CAAU,EACnCkC,EAAM,OAAO,KAAKvB,EAAK,EACnBuB,EAAM,OACJ,KAAKf,GACPiE,KAAM,aAAUlD,CAAK,EAErBkD,EAAM,CAAC,GAAGlD,CAAK,EAGrB,OAASR,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAO0D,GAAO,CAAC,CACjB,CACF",
|
|
6
|
+
"names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_is_potential_custom_element_name", "import_nwsapi", "import_dom_util", "import_matcher", "import_parser", "import_constant", "DIR_NEXT", "DIR_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#cache", "#content", "#contentCache", "#descendant", "#document", "#event", "#node", "#nodes", "#noexcept", "#nwsapi", "#qswalker", "#results", "#root", "#shadow", "#sort", "#walker", "#walkers", "#warn", "#window", "window", "document", "e", "selector", "node", "opt", "event", "noexcept", "warn", "nwsapi", "nodes", "ast", "cachedItem", "item", "l", "i", "cssAst", "branches", "hasHasPseudoFunc", "hasHyphenSepAttr", "cacheable", "descendant", "items", "branch", "leaves", "nextItem", "msg", "itemName", "walker", "anb", "a", "b", "reverse", "parentNode", "matched", "selectorBranches", "refNode", "selectorNodes", "bool", "nth", "j", "m", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "anbMap", "astLeaves", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "astName", "twigBranches", "res", "forgive", "lastIndex", "nextNodes", "arr", "astChildren", "selectors", "css", "leavesSet", "href", "origin", "pathname", "attrURL", "target", "type", "buttons", "hash", "id", "current", "focus", "display", "visibility", "active", "isCustomElementName", "parent", "placeholder", "targetNode", "nodeName", "checked", "form", "isMultiple", "defaultOpt", "inputType", "node1", "node2", "attr", "host", "astType", "attributes", "nodeType", "result", "save", "leafName", "compound", "filterLeaves", "baseNode", "pending", "comboName", "dir", "matchedNode", "filtered", "complex", "targetType", "collected", "pendingItems", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "pendingItem", "index", "nextCombo", "find", "entryNodes", "entryNodesLen", "n", "entryCombo", "entryLeaves", "entryNode", "filterOpt"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
"c8": "^10.1.2",
|
|
35
35
|
"chai": "^5.1.1",
|
|
36
36
|
"commander": "^12.1.0",
|
|
37
|
-
"esbuild": "^0.
|
|
37
|
+
"esbuild": "^0.23.0",
|
|
38
38
|
"eslint": "^8.57.0",
|
|
39
39
|
"eslint-config-standard": "^17.1.0",
|
|
40
40
|
"eslint-plugin-import": "^2.29.1",
|
|
41
|
-
"eslint-plugin-jsdoc": "^48.
|
|
41
|
+
"eslint-plugin-jsdoc": "^48.5.0",
|
|
42
42
|
"eslint-plugin-regexp": "^2.6.0",
|
|
43
43
|
"eslint-plugin-unicorn": "^54.0.0",
|
|
44
|
-
"happy-dom": "^14.12.
|
|
44
|
+
"happy-dom": "^14.12.3",
|
|
45
45
|
"jsdom": "^24.1.0",
|
|
46
|
-
"linkedom": "^0.18.
|
|
47
|
-
"mocha": "^10.
|
|
46
|
+
"linkedom": "^0.18.4",
|
|
47
|
+
"mocha": "^10.6.0",
|
|
48
48
|
"sinon": "^18.0.0",
|
|
49
|
-
"typescript": "^5.
|
|
49
|
+
"typescript": "^5.5.3",
|
|
50
50
|
"wpt-runner": "^5.0.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"tsc": "node scripts/index clean --dir=types -i && npx tsc",
|
|
61
61
|
"update-wpt": "git submodule update --init --recursive --remote"
|
|
62
62
|
},
|
|
63
|
-
"version": "4.5.0
|
|
63
|
+
"version": "4.5.0"
|
|
64
64
|
}
|
package/src/js/finder.js
CHANGED
|
@@ -123,19 +123,12 @@ export class Finder {
|
|
|
123
123
|
* @param {object} node - Document, DocumentFragment, Element node
|
|
124
124
|
* @param {object} opt - options
|
|
125
125
|
* @param {object} [opt.event] - MouseEvent, KeyboardEvent
|
|
126
|
-
* @param {boolean} [opt.invalidate] - invalidate (for jsdom)
|
|
127
126
|
* @param {boolean} [opt.noexcept] - no exception
|
|
128
127
|
* @param {boolean} [opt.warn] - console warn
|
|
129
128
|
* @returns {object} - node
|
|
130
129
|
*/
|
|
131
130
|
_setup(selector, node, opt = {}) {
|
|
132
|
-
const { event,
|
|
133
|
-
// clear cache in jsdom internal process
|
|
134
|
-
/*
|
|
135
|
-
if (invalidate && node.nodeType === ELEMENT_NODE) {
|
|
136
|
-
this.#cache = new WeakMap();
|
|
137
|
-
}
|
|
138
|
-
*/
|
|
131
|
+
const { event, noexcept, warn } = opt;
|
|
139
132
|
this.#noexcept = !!noexcept;
|
|
140
133
|
this.#warn = !!warn;
|
|
141
134
|
this.#event = this._setEvent(event);
|
|
@@ -187,14 +180,12 @@ export class Finder {
|
|
|
187
180
|
const nodes = [];
|
|
188
181
|
this.#descendant = false;
|
|
189
182
|
let ast;
|
|
190
|
-
let cacheable;
|
|
191
183
|
if (this.#contentCache.has(this.#content)) {
|
|
192
184
|
const cachedItem = this.#contentCache.get(this.#content);
|
|
193
185
|
if (cachedItem && cachedItem.has(`${selector}`)) {
|
|
194
186
|
const item = cachedItem.get(`${selector}`);
|
|
195
187
|
this.#descendant = item.descendant;
|
|
196
188
|
ast = item.ast;
|
|
197
|
-
cacheable = item.cacheable;
|
|
198
189
|
}
|
|
199
190
|
}
|
|
200
191
|
if (ast) {
|
|
@@ -220,6 +211,7 @@ export class Finder {
|
|
|
220
211
|
hasHyphenSepAttr
|
|
221
212
|
}
|
|
222
213
|
} = walkAST(cssAst);
|
|
214
|
+
let cacheable;
|
|
223
215
|
if (hasHasPseudoFunc || hasHyphenSepAttr) {
|
|
224
216
|
cacheable = false;
|
|
225
217
|
} else {
|
|
@@ -293,18 +285,12 @@ export class Finder {
|
|
|
293
285
|
}
|
|
294
286
|
cachedItem.set(`${selector}`, {
|
|
295
287
|
ast,
|
|
296
|
-
cacheable,
|
|
297
288
|
descendant
|
|
298
289
|
});
|
|
299
290
|
this.#contentCache.set(this.#content, cachedItem);
|
|
300
291
|
}
|
|
301
292
|
this.#descendant = descendant;
|
|
302
293
|
}
|
|
303
|
-
/*
|
|
304
|
-
if (!cacheable) {
|
|
305
|
-
this.#cache = new WeakMap();
|
|
306
|
-
}
|
|
307
|
-
*/
|
|
308
294
|
return [
|
|
309
295
|
ast,
|
|
310
296
|
nodes
|