@asamuzakjp/dom-selector
Advanced tools
Comparing version 4.3.0 to 4.4.0
@@ -1,2 +0,2 @@ | ||
var B=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(A,i)=>{for(var e in i)I(A,e,{get:i[e],enumerable:!0})},U=(A,i,e,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let l of G(i))!V.call(A,l)&&l!==e&&I(A,l,{get:()=>i[l],enumerable:!(r=j(i,l))||r.enumerable});return A};var z=(A,i,e)=>(e=A!=null?B(q(A)):{},U(i||!A||!A.__esModule?I(e,"default",{value:A,enumerable:!0}):e,A)),Y=A=>U(I({},"__esModule",{value:!0}),A);var Q={};X(Q,{Finder:()=>K});module.exports=Y(Q);var P=z(require("is-potential-custom-element-name"),1),F=z(require("nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),S=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",L="first",R="lineal",D="self";class K{#a;#l;#t;#f;#h;#m;#e;#d;#_;#o;#c;#w;#s;#b;#u;#n;#p;#i;#r;constructor(i){this.#r=i,this.#h=i.document,this.#l=new WeakMap,this.#w=new WeakMap,this.#o=(0,F.default)({document:i.document,DOMException:i.DOMException}),this.#o.configure({LOGERRORS:!1})}_onError(i){if(!this.#_)if(i instanceof DOMException||i instanceof this.#r.DOMException)if(i.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(i.message);else throw new this.#r.DOMException(i.message,i.name);else throw i}_setup(i,e,r={}){const{event:l,noexcept:s,warn:n}=r;return this.#_=!!s,this.#i=!!n,this.#m=this._setEvent(l),this.#e=e,[this.#t,this.#s,this.#n]=(0,C.resolveContent)(e),this.#b=(0,C.isInShadowTree)(e),[this.#a,this.#d]=this._correspond(i),this.#p=new WeakMap,e}_setEvent(i){return i instanceof this.#r.MouseEvent||i instanceof this.#r.KeyboardEvent?i:null}_correspond(i){const e=[];this.#f=!1;let r;if(this.#t){const l=this.#l.get(this.#t);if(l&&l.has(`${i}`)){const s=l.get(`${i}`);this.#f=s.descendant,r=s.ast}}if(r){const l=r.length;for(let s=0;s<l;s++)r[s].collected=!1,r[s].dir=null,r[s].filtered=!1,r[s].find=!1,e[s]=[]}else{let l;try{l=(0,S.parseSelector)(i)}catch(h){this._onError(h)}const s=(0,S.walkAST)(l);let n=!1,c=0;r=[];for(const[...h]of s){const f=[];let t=h.shift();if(t&&t.type!==b.COMBINATOR){const a=new Set;for(;t;){if(t.type===b.COMBINATOR){const[o]=h;if(o.type===b.COMBINATOR){const _=`Invalid selector ${i}`;throw new DOMException(_,b.SYNTAX_ERR)}const w=t.name;/^[\s>]$/.test(w)&&(n=!0),f.push({combo:t,leaves:(0,S.sortAST)(a)}),a.clear()}else if(t){let{name:o}=t;o&&typeof o=="string"&&(o=(0,S.unescapeSelector)(o),typeof o=="string"&&o!==t.name&&(t.name=o),/[|:]/.test(o)&&(t.namespace=!0)),a.add(t)}if(h.length)t=h.shift();else{f.push({combo:null,leaves:(0,S.sortAST)(a)}),a.clear();break}}}r.push({branch:f,collected:!1,dir:null,filtered:!1,find:!1}),e[c]=[],c++}if(this.#t){let h;this.#l.has(this.#t)?h=this.#l.get(this.#t):h=new Map,h.set(`${i}`,{ast:r,descendant:n}),this.#l.set(this.#t,h)}this.#f=n}return[r,e]}_createTreeWalker(i){let e;return this.#p.has(i)?e=this.#p.get(i):(e=this.#h.createTreeWalker(i,b.WALKER_FILTER),this.#p.set(i,e)),e}_prepareQuerySelectorWalker(){return this.#c=this._createTreeWalker(this.#e),this.#u=!1,this.#c}_traverse(i,e=this.#n){let r=e.currentNode,l;if(r===i)l=r;else if(r.contains(i))for(r=e.nextNode();r;){if(r===i){l=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===i);)r=e.parentNode();if(i?.nodeType===b.ELEMENT_NODE)for(;r;){if(r===i){l=r;break}r=e.nextNode()}else l=r}return l??null}_collectNthChild(i,e,r){const{a:l,b:s,reverse:n,selector:c}=i,{parentNode:h}=e,f=new Set;let t;if(c&&(this.#l.has(c)?t=this.#l.get(c):(t=(0,S.walkAST)(c),this.#l.set(c,t))),h){const a=this.#n;let o=this._traverse(h,a);o=a.firstChild();let w=0;for(;o;)w++,o=a.nextSibling();o=this._traverse(h,a);const _=new Set;if(t)for(o=a.firstChild();o;){let p;for(const k of t)if(p=this._matchLeaves(k,o,r),!p)break;p&&_.add(o),o=a.nextSibling()}if(l===0){if(s>0&&s<=w){if(_.size){o=this._traverse(h,a),n?o=a.lastChild():o=a.firstChild();let p=0;for(;o;){if(_.has(o)){if(p===s-1){f.add(o);break}p++}n?o=a.previousSibling():o=a.nextSibling()}}else if(!c){o=this._traverse(h,a),n?o=a.lastChild():o=a.firstChild();let p=0;for(;o;){if(p===s-1){f.add(o);break}n?o=a.previousSibling():o=a.nextSibling(),p++}}}}else{let p=s-1;if(l>0)for(;p<0;)p+=l;if(p>=0&&p<w){o=this._traverse(h,a),n?o=a.lastChild():o=a.firstChild();let k=0,N=l>0?0:s-1;for(;o&&(o&&p>=0&&p<w);)_.size?_.has(o)&&(N===p&&(f.add(o),p+=l),l>0?N++:N--):k===p&&(c||f.add(o),p+=l),n?o=a.previousSibling():o=a.nextSibling(),k++}}if(n&&f.size>1){const p=[...f];return new Set(p.reverse())}}else if(e===this.#s&&l+s===1)if(t){let a;for(const o of t)if(a=this._matchLeaves(o,e,r),a)break;a&&f.add(e)}else f.add(e);return f}_collectNthOfType(i,e){const{a:r,b:l,reverse:s}=i,{localName:n,parentNode:c,prefix:h}=e,f=new Set;if(c){const t=this.#n;let a=this._traverse(c,t);a=t.firstChild();let o=0;for(;a;)o++,a=t.nextSibling();if(r===0){if(l>0&&l<=o){a=this._traverse(c,t),s?a=t.lastChild():a=t.firstChild();let w=0;for(;a;){const{localName:_,prefix:p}=a;if(_===n&&p===h){if(w===l-1){f.add(a);break}w++}s?a=t.previousSibling():a=t.nextSibling()}}}else{let w=l-1;if(r>0)for(;w<0;)w+=r;if(w>=0&&w<o){a=this._traverse(c,t),s?a=t.lastChild():a=t.firstChild();let _=r>0?0:l-1;for(;a;){const{localName:p,prefix:k}=a;if(p===n&&k===h){if(_===w&&(f.add(a),w+=r),w<0||w>=o)break;r>0?_++:_--}s?a=t.previousSibling():a=t.nextSibling()}}}if(s&&f.size>1){const w=[...f];return new Set(w.reverse())}}else e===this.#s&&r+l===1&&f.add(e);return f}_matchAnPlusB(i,e,r,l){const{nth:{a:s,b:n,name:c},selector:h}=i,f=new Map;if(c?(c==="even"?(f.set("a",2),f.set("b",0)):c==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?f.set("a",s*1):f.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?f.set("b",n*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){h&&f.set("selector",h);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(i,e,r={}){let l;if(Array.isArray(i)&&i.length){const[s]=i,{type:n}=s;let c;n===b.COMBINATOR?c=i.shift():c={name:" ",type:b.COMBINATOR};const h=[];for(;i.length;){const[a]=i,{type:o}=a;if(o===b.COMBINATOR)break;h.push(i.shift())}const f={combo:c,leaves:h};r.dir=T;const t=this._matchCombinator(f,e,r);if(t.size)if(i.length){for(const a of t)if(l=this._matchHasPseudoFunc(Object.assign([],i),a,r),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(i,e,r={}){const{astName:l="",branches:s=[],selector:n="",twigBranches:c=[]}=i;let h;if(l==="has")if(n.includes(":has("))h=null;else{let f;for(const t of s)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(h=e)}else{const f=/^(?:is|where)$/.test(l);r.forgive=f;const t=c.length;let a;for(let o=0;o<t;o++){const w=c[o],_=w.length-1,{leaves:p}=w[_];if(a=this._matchLeaves(p,e,r),a&&_>0){let k=new Set([e]);for(let N=_-1;N>=0;N--){const g=w[N],d=[];r.dir=O;for(const m of k){const u=this._matchCombinator(g,m,r);u.size&&d.push(...u)}if(d.length)N===0?a=!0:k=new Set(d);else{a=!1;break}}}if(a)break}l==="not"?a||(h=e):a&&(h=e)}return h??null}_matchPseudoClassSelector(i,e,r={}){const{children:l,name:s}=i,{localName:n,parentNode:c}=e,{forgive:h,warn:f=this.#i}=r,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(s)){let a;if(this.#l.has(i))a=this.#l.get(i);else{const w=(0,S.walkAST)(i),_=[],p=[];for(const[...k]of w){for(const m of k){const u=(0,S.generateCSS)(m);_.push(u)}const N=[],g=new Set;let d=k.shift();for(;d;)if(d.type===b.COMBINATOR?(N.push({combo:d,leaves:[...g]}),g.clear()):d&&g.add(d),k.length)d=k.shift();else{N.push({combo:null,leaves:[...g]}),g.clear();break}p.push(N)}a={astName:s,branches:w,twigBranches:p,selector:_.join(",")},this.#l.set(i,a)}const o=this._matchLogicalPseudoFunc(a,e,r);o&&t.add(o)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(s)){const[a]=l;return this._matchAnPlusB(a,e,s,r)}else switch(s){case"dir":case"lang":{const a=$.matcher.matchSelector(i,e);a&&t.add(a);break}case"current":case"nth-col":case"nth-last-col":{if(f){const a=`Unsupported pseudo-class :${s}()`;throw new DOMException(a,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!h){const a=`Unknown pseudo-class :${s}()`;throw new DOMException(a,b.SYNTAX_ERR)}}else{const a=/^a(?:rea)?$/,o=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,w=/^(?:button|form|input|select|textarea)$/,_=/^(?:details|dialog)$/,p=/^(?:checkbox|radio)$/,k=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:date(?:time-local)?|month|number|range|time|week)$/,g=/^(?:email|number|password|search|tel|text|url)$/;switch(s){case"any-link":case"link":{a.test(n)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(a.test(n)&&e.hasAttribute("href")){const{href:d,origin:m,pathname:u}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),d);y.origin===m&&y.pathname===u&&t.add(e)}break}case"visited":break;case"hover":{const{target:d,type:m}=this.#m??{};(m==="mouseover"||m==="pointerover")&&e.contains(d)&&t.add(e);break}case"active":{const{buttons:d,target:m,type:u}=this.#m??{};(u==="mousedown"||u==="pointerdown")&&d&b.BIT_01&&e.contains(m)&&t.add(e);break}case"target":{const{hash:d}=new URL(this.#t.URL);e.id&&d===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:d}=new URL(this.#t.URL);if(d){const m=d.replace(/^#/,"");let u=this.#t.getElementById(m);for(;u;){if(u===e){t.add(e);break}u=u.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#b&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":case"focus-visible":{const{target:d,type:m}=this.#m??{};if(e===this.#t.activeElement&&e.tabIndex>=0&&(s==="focus"||m==="keydown"&&e.contains(d))){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else{const{display:v,visibility:E}=this.#r.getComputedStyle(u);if(y=!(v==="none"||E==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"focus-within":{let d,m=this.#t.activeElement;if(m.tabIndex>=0)for(;m;){if(m===e){d=!0;break}m=m.parentNode}if(d){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else{const{display:v,visibility:E}=this.#r.getComputedStyle(u);if(y=!(v==="none"||E==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"open":{_.test(n)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(n)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(o.test(n)||(0,P.default)(n))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let d=c;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&c.localName!=="legend"&&d.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(o.test(n)||(0,P.default)(n))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(n){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||k.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(n){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||k.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let d;n==="textarea"?d=e:n==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&n==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))||e.selected&&n==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&n==="input"&&e.type==="checkbox"||n==="progress"&&!e.hasAttribute("value"))t.add(e);else if(n==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let m=e.parentNode;for(;m&&m.localName!=="form";)m=m.parentNode;m||(m=this.#t.documentElement);const u=m.getElementsByTagName("input"),y=u.length;let v;for(let E=0;E<y;E++){const x=u[E];if(x.getAttribute("type")==="radio"&&(d?x.getAttribute("name")===d&&(v=!!x.checked):x.hasAttribute("name")||(v=!!x.checked),v))break}v||t.add(e)}break}case"default":{const d=/^(?:button|reset)$/,m=/^(?:image|submit)$/;if(n==="button"&&!(e.hasAttribute("type")&&d.test(e.getAttribute("type")))||n==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))){let u=e.parentNode;for(;u&&u.localName!=="form";)u=u.parentNode;if(u){const y=this.#n;let v=this._traverse(u,y);for(v=y.firstChild();v&&u.contains(v);){const E=v.localName;let x;if(E==="button"?x=!(v.hasAttribute("type")&&d.test(v.getAttribute("type"))):E==="input"&&(x=v.hasAttribute("type")&&m.test(v.getAttribute("type"))),x){v===e&&t.add(e);break}v=y.nextNode()}}}else if(n==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(n==="option"){let u=c,y=!1;for(;u&&u.localName!=="datalist";){if(u.localName==="select"){(u.multiple||u.hasAttribute("multiple"))&&(y=!0);break}u=u.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,E=this.#n;let x=this._traverse(c,E);for(x=E.firstChild();x;){if(x.selected||x.hasAttribute("selected")){v.add(x);break}x=E.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(w.test(n))e.checkValidity()&&t.add(e);else if(n==="fieldset"){const d=this.#n;let m=this._traverse(e,d);m=d.firstChild();let u;for(;m&&e.contains(m)&&!(w.test(m.localName)&&(u=m.checkValidity(),!u));)m=d.nextNode();u&&t.add(e)}break}case"invalid":{if(w.test(n))e.checkValidity()||t.add(e);else if(n==="fieldset"){const d=this.#n;let m=this._traverse(e,d);m=d.firstChild();let u;for(;m&&e.contains(m)&&!(w.test(m.localName)&&(u=m.checkValidity(),!u));)m=d.nextNode();u||t.add(e)}break}case"in-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{n==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let d;if(/^(?:select|textarea)$/.test(n))d=e;else if(n==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||p.test(m)||k.test(m)||g.test(m))&&(d=e)}else d=e;d&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let d;if(/^(?:select|textarea)$/.test(n))d=e;else if(n==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||p.test(m)||k.test(m)||g.test(m))&&(d=e)}else d=e;d&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const d=this.#h.createTreeWalker(e,b.SHOW_ALL);let m=d.firstChild(),u;for(;m&&(u=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!!u);)m=d.nextSibling();u&&t.add(e)}else t.add(e);break}case"first-child":{(c&&e===c.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(c&&e===c.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(c&&e===c.firstElementChild&&e===c.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(c){const[d]=this._collectNthOfType({a:0,b:1},e);d&&t.add(d)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(c){const[d]=this._collectNthOfType({a:0,b:1,reverse:!0},e);d&&t.add(d)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(c){const[d]=this._collectNthOfType({a:0,b:1},e);if(d===e){const[m]=this._collectNthOfType({a:0,b:1,reverse:!0},e);m===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"defined":{const d=e.getAttribute("is");d?(0,P.default)(d)&&this.#r.customElements.get(d)&&t.add(e):(0,P.default)(n)?this.#r.customElements.get(n)&&t.add(e):(e instanceof this.#r.HTMLElement||e instanceof this.#r.SVGElement)&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const d=`Unsupported pseudo-element ::${s}`;throw new DOMException(d,b.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(f){const d=`Unsupported pseudo-class :${s}`;throw new DOMException(d,b.NOT_SUPPORTED_ERR)}break}default:if(s.startsWith("-webkit-")){if(f){const d=`Unsupported pseudo-class :${s}`;throw new DOMException(d,b.NOT_SUPPORTED_ERR)}}else if(!h){const d=`Unknown pseudo-class :${s}`;throw new DOMException(d,b.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(i,e){const{children:r,name:l}=i;let s;if(Array.isArray(r)){const[n]=(0,S.walkAST)(r[0]),[...c]=n,{host:h}=e;if(l==="host"){let f;for(const t of c){const{type:a}=t;if(a===b.COMBINATOR){const w=`Invalid selector ${(0,S.generateCSS)(i)}`;throw new DOMException(w,b.SYNTAX_ERR)}if(f=this._matchSelector(t,h).has(h),!f)break}f&&(s=e)}else if(l==="host-context"){let f=h,t;for(;f;){for(const a of c){const{type:o}=a;if(o===b.COMBINATOR){const _=`Invalid selector ${(0,S.generateCSS)(i)}`;throw new DOMException(_,b.SYNTAX_ERR)}if(t=this._matchSelector(a,f).has(f),!t)break}if(t)break;f=f.parentNode}t&&(s=e)}}else if(l==="host")s=e;else{const n=`Invalid selector :${l}`;throw new DOMException(n,b.SYNTAX_ERR)}return s??null}_matchSelector(i,e,r){const{type:l}=i,s=new Set;if(i.name===b.EMPTY)return s;const n=(0,S.unescapeSelector)(i.name);if(typeof n=="string"&&n!==i.name&&(i.name=n),e.nodeType===b.ELEMENT_NODE)switch(l){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(n,r);break}case b.SELECTOR_ID:{e.id===n&&s.add(e);break}case b.SELECTOR_CLASS:{e.classList.contains(n)&&s.add(e);break}case b.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(i,e,r);default:{const c=$.matcher.matchSelector(i,e,r);c&&s.add(c)}}else if(this.#b&&l===b.SELECTOR_PSEUDO_CLASS&&e.nodeType===b.DOCUMENT_FRAGMENT_NODE){if(n!=="has"&&b.REG_LOGICAL_PSEUDO.test(n))return this._matchPseudoClassSelector(i,e,r);if(b.REG_SHADOW_HOST.test(n)){const c=this._matchShadowHostPseudoClass(i,e,r);c&&s.add(c)}}return s}_matchLeaves(i,e,r){const{attributes:l,localName:s,nodeType:n}=e;let c=this.#w.get(i),h;if(c&&c.has(e)){const{attr:f,matched:t}=c.get(e);l?.length===f&&(h=t)}if(typeof h!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;n===b.ELEMENT_NODE&&f.test(s)?t=!1:t=!0;for(const a of i){const{name:o,type:w}=a;if(w===b.SELECTOR_PSEUDO_CLASS&&o==="dir"&&(t=!1),h=this._matchSelector(a,e,r).has(e),!h)break}t&&(c||(c=new WeakMap),c.set(e,{attr:l?.length,matched:h}),this.#w.set(i,c))}return!!h}_matchHTMLCollection(i,e={}){const{compound:r,filterLeaves:l}=e,s=new Set,n=i.length;if(n)if(r)for(let c=0;c<n;c++){const h=i[c];this._matchLeaves(l,h,e)&&s.add(h)}else{const c=[].slice.call(i);return new Set(c)}return s}_findDescendantNodes(i,e,r){const[l,...s]=i,n=s.length>0,{type:c}=l,h=(0,S.unescapeSelector)(l.name);typeof h=="string"&&h!==l.name&&(l.name=h);let f=new Set,t=!1;if(this.#b)t=!0;else switch(c){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(h,r);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const a=this.#s.getElementById(h);a&&a!==e&&e.contains(a)&&(n?this._matchLeaves(s,a,r)&&f.add(a):f.add(a))}break}case b.SELECTOR_CLASS:{const a=e.getElementsByClassName(h);f=this._matchHTMLCollection(a,{compound:n,filterLeaves:s});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(h)){const a=e.getElementsByTagName(h);f=this._matchHTMLCollection(a,{compound:n,filterLeaves:s})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(i,e,r={}){const{combo:l,leaves:s}=i,{name:n}=l,{parentNode:c}=e,{dir:h}=r,f=new Set;if(h===T)switch(n){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(c){const t=this._createTreeWalker(c);let a=this._traverse(e,t);for(a=t.nextSibling();a;)this._matchLeaves(s,a,r)&&f.add(a),a=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let a=this._traverse(e,t);for(a=t.firstChild();a;)this._matchLeaves(s,a,r)&&f.add(a),a=t.nextSibling();break}case" ":default:{const{nodes:t,pending:a}=this._findDescendantNodes(s,e);if(t.size)return t;if(a){const o=this._createTreeWalker(e);let w=this._traverse(e,o);for(w=o.nextNode();w&&e.contains(w);)this._matchLeaves(s,w,r)&&f.add(w),w=o.nextNode()}}}else switch(n){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(s,t,r)&&f.add(t);break}case"~":{if(c){const t=this._createTreeWalker(c);let a=this._traverse(c,t);for(a=t.firstChild();a&&a!==e;)this._matchLeaves(s,a,r)&&f.add(a),a=t.nextSibling()}break}case">":{c&&this._matchLeaves(s,c,r)&&f.add(c);break}case" ":default:{const t=[];let a=c;for(;a;)this._matchLeaves(s,a,r)&&t.push(a),a=a.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(i,e){const{node:r}=e;let l=this._traverse(r,this.#c),s;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#c.nextNode():l===r&&l!==this.#s&&(l=this.#c.nextNode());l;){if(this._matchLeaves(i,l,{warn:this.#i})){s=l;break}l=this.#c.nextNode()}return s??null}_matchSelf(i){const e=[],r=this._matchLeaves(i,this.#e,{warn:this.#i});let l=!1;return r&&(e.push(this.#e),l=!0),[e,l]}_findLineal(i,e={}){const{complex:r}=e,l=[];let s=this._matchLeaves(i,this.#e,{warn:this.#i}),n=!1;if(s&&(l.push(this.#e),n=!0),!s||r){let c=this.#e.parentNode;for(;c&&(s=this._matchLeaves(i,c,{warn:this.#i}),s&&(l.push(c),n=!0),c.parentNode);)c=c.parentNode}return[l,n]}_findFirst(i){const e=[],r=this._findNode(i,{node:this.#e});let l=!1;return r&&(e.push(r),l=!0),[e,l]}_findFromHTMLCollection(i,e={}){const{complex:r,compound:l,filterLeaves:s,targetType:n}=e;let c=[],h=!1,f=!1;const t=i.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let a=0;a<t;a++){const o=i[a];if(o!==this.#e&&(this.#e.contains(o)||o.contains(this.#e))){if(l){if(this._matchLeaves(s,o,{warn:this.#i})&&(c.push(o),h=!0,n===L))break}else if(c.push(o),h=!0,n===L)break}}else if(r)if(l)for(let a=0;a<t;a++){const o=i[a];if(this._matchLeaves(s,o,{warn:this.#i})&&(c.push(o),h=!0,n===L))break}else c=[].slice.call(i),h=!0,f=!0;else if(l)for(let a=0;a<t;a++){const o=i[a];if(this._matchLeaves(s,o,{warn:this.#i})&&(c.push(o),h=!0,n===L))break}else c=[].slice.call(i),h=!0,f=!0;return[c,h,f]}_findEntryNodes(i,e,r){const{leaves:l}=i,[s,...n]=l,c=n.length>0,{name:h,type:f}=s;let t=[],a=!1,o=!1,w=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(h,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(e===L&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(h);_&&(c?this._matchLeaves(n,_,{warn:this.#i})&&(t.push(_),o=!0):(t.push(_),o=!0))}else e===L?[t,o]=this._findFirst(l):w=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(h);_.length&&([t,o,a]=this._findFromHTMLCollection(_,{complex:r,compound:c,filterLeaves:n,targetType:e}))}else e===L?[t,o]=this._findFirst(l):w=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(h)){const _=this.#s.getElementsByTagName(h);_.length&&([t,o,a]=this._findFromHTMLCollection(_,{complex:r,compound:c,filterLeaves:n,targetType:e}))}else e===L?[t,o]=this._findFirst(l):w=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(h)){if(this.#b&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(s,this.#e);_&&(t.push(_),o=!0)}}else e===D?[t,o]=this._matchSelf(l):e===R?[t,o]=this._findLineal(l,{complex:r}):e===L?[t,o]=this._findFirst(l):w=!0}return{collected:a,compound:c,filtered:o,nodes:t,pending:w}}_collectNodes(i){const e=this.#a.values();if(i===M||i===L){const r=new Set;let l=0;for(const{branch:s}of e){const n=s.length,c=n>1,h=s[0];let f,t;if(c){const{combo:k,leaves:[{name:N,type:g}]}=h,d=s[n-1],{leaves:[{name:m,type:u}]}=d;if(u===b.SELECTOR_PSEUDO_ELEMENT||u===b.SELECTOR_ID)f=O,t=d;else if(g===b.SELECTOR_PSEUDO_ELEMENT||g===b.SELECTOR_ID)f=T,t=h;else if(i===M)if(N==="*"&&g===b.SELECTOR_TYPE)f=O,t=d;else if(m==="*"&&u===b.SELECTOR_TYPE)f=T,t=h;else if(n===2){const{name:y}=k;/^[+~]$/.test(y)?(f=O,t=d):(f=T,t=h)}else f=T,t=h;else if(m==="*"&&u===b.SELECTOR_TYPE)f=T,t=h;else if(N==="*"&&g===b.SELECTOR_TYPE)f=O,t=d;else{let y;for(const{combo:v,leaves:[E]}of s){const{name:x,type:W}=E;if(W===b.SELECTOR_PSEUDO_CLASS&&x==="dir"){y=!1;break}if(!y&&v){const{name:H}=v;/^[+~]$/.test(H)&&(y=!0)}}y?(f=T,t=h):(f=O,t=d)}}else f=O,t=h;const{collected:a,compound:o,filtered:w,nodes:_,pending:p}=this._findEntryNodes(t,i,c);_.length?(this.#a[l].find=!0,this.#d[l]=_):p&&r.add(new Map([["index",l],["twig",t]])),this.#a[l].collected=a,this.#a[l].dir=f,this.#a[l].filtered=w||!o,l++}if(r.size){let s,n;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(s=this.#e,n=this.#c):(s=this.#s,n=this.#n);let c=this._traverse(s,n);for(;c;){let h=!1;if(this.#e.nodeType===b.ELEMENT_NODE?c===this.#e?h=!0:h=this.#e.contains(c):h=!0,h)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,c,{warn:this.#i})){const o=f.get("index");this.#a[o].filtered=!0,this.#a[o].find=!0,this.#d[o].push(c)}}c!==n.currentNode&&(c=this._traverse(c,n)),c=n.nextNode()}}}else{let r=0;for(const{branch:l}of e){const s=l[l.length-1],n=l.length>1,{compound:c,filtered:h,nodes:f}=this._findEntryNodes(s,i,n);f.length&&(this.#a[r].find=!0,this.#d[r]=f),this.#a[r].dir=O,this.#a[r].filtered=h||!c,r++}}return[this.#a,this.#d]}_getCombinedNodes(i,e,r){const l=[];for(const s of e){const n=this._matchCombinator(i,s,{dir:r,warn:this.#i});n.size&&l.push(...n)}return l.length?new Set(l):new Set}_matchNodeNext(i,e,r){const{combo:l,index:s}=r,{combo:n,leaves:c}=i[s],h={combo:l,leaves:c},f=this._getCombinedNodes(h,e,T);let t;if(f.size)if(s===i.length-1){const[a]=(0,C.sortNodes)(f);t=a}else t=this._matchNodeNext(i,f,{combo:n,index:s+1});return t??null}_matchNodePrev(i,e,r){const{index:l}=r,s=i[l],n=new Set([e]),c=this._getCombinedNodes(s,n,O);let h;if(c.size){if(l===0)h=e;else for(const f of c)if(this._matchNodePrev(i,f,{index:l-1}))return e}return h??null}_find(i){(i===M||i===L)&&this._prepareQuerySelectorWalker();const[[...e],r]=this._collectNodes(i),l=e.length;let s=new Set;for(let n=0;n<l;n++){const{branch:c,collected:h,dir:f,find:t}=e[n],a=c.length;if(a&&t){const o=r[n],w=o.length,_=a-1;if(_===0)if((i===M||i===L)&&this.#e.nodeType===b.ELEMENT_NODE)for(let p=0;p<w;p++){const k=o[p];if(k!==this.#e&&this.#e.contains(k)&&(s.add(k),i!==M))break}else if(i===M)if(s.size){const p=[...s];s=new Set([...p,...o]),this.#u=!0}else s=new Set(o);else{const[p]=o;s.add(p)}else if(i===M)if(f===T){let{combo:p}=c[0];for(const k of o){let N=new Set([k]);for(let g=1;g<a;g++){const{combo:d,leaves:m}=c[g],u={combo:p,leaves:m};if(N=this._getCombinedNodes(u,N,f),N.size)if(g===_)if(s.size){const y=[...s];s=new Set([...y,...N]),this.#u=!0}else s=N;else p=d;else break}}}else for(const p of o){let k=new Set([p]);for(let N=_-1;N>=0;N--){const g=c[N];if(k=this._getCombinedNodes(g,k,f),k.size)N===0&&(s.add(p),a>1&&s.size>1&&(this.#u=!0));else break}}else if(i===L&&f===T){const{combo:p}=c[0];let k;for(const N of o)if(k=this._matchNodeNext(c,new Set([N]),{combo:p,index:1}),k){s.add(k);break}if(!k&&!h){const{leaves:N}=c[0],[g]=o;let d=this._findNode(N,{node:g});for(;d;){if(k=this._matchNodeNext(c,new Set([d]),{combo:p,index:1}),k){s.add(k);break}d=this._findNode(N,{node:d})}}}else{let p;for(const k of o)if(p=this._matchNodePrev(c,k,{index:_-1}),p){s.add(k);break}if(!p&&!h&&i===L){const{leaves:k}=c[_],[N]=o;let g=this._findNode(k,{node:N});for(;g;){if(p=this._matchNodePrev(c,g,{index:_-1}),p){s.add(g);break}g=this._findNode(k,{node:g})}}}}}return s}matches(i,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}(0,S.filterSelector)(i)?l=this.#o.match(i,e):(this._setup(i,e,r),l=this._find(D).size)}catch(s){this._onError(s)}return!!l}closest(i,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const s=`Unexpected node ${e?.nodeName}`;throw new TypeError(s)}if((0,S.filterSelector)(i))l=this.#o.closest(i,e);else{this._setup(i,e,r);const s=this._find(R);if(s.size){let n=this.#e;for(;n;){if(s.has(n)){l=n;break}n=n.parentNode}}}}catch(s){this._onError(s)}return l??null}querySelector(i,e,r){let l;try{if(this._setup(i,e,r),this.#h===this.#t&&!this.#f&&(0,S.filterSelector)(i))l=this.#o.first(i,e);else{const s=this._find(L);s.delete(this.#e),s.size&&([l]=(0,C.sortNodes)(s))}}catch(s){this._onError(s)}return l??null}querySelectorAll(i,e,r){let l;try{if(this._setup(i,e,r),this.#h===this.#t&&!this.#f&&(0,S.filterSelector)(i))l=this.#o.select(i,e);else{const s=this._find(M);s.delete(this.#e),s.size&&(this.#u?l=(0,C.sortNodes)(s):l=[...s])}}catch(s){this._onError(s)}return l??[]}}0&&(module.exports={Finder}); | ||
var B=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(A,a)=>{for(var e in a)I(A,e,{get:a[e],enumerable:!0})},U=(A,a,e,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of G(a))!V.call(A,l)&&l!==e&&I(A,l,{get:()=>a[l],enumerable:!(r=j(a,l))||r.enumerable});return A};var z=(A,a,e)=>(e=A!=null?B(q(A)):{},U(a||!A||!A.__esModule?I(e,"default",{value:A,enumerable:!0}):e,A)),Y=A=>U(I({},"__esModule",{value:!0}),A);var Q={};X(Q,{Finder:()=>K});module.exports=Y(Q);var P=z(require("is-potential-custom-element-name"),1),F=z(require("@asamuzakjp/nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),x=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",L="first",R="lineal",D="self";class K{#a;#r;#c;#t;#h;#d;#p;#e;#b;#k;#f;#o;#_;#s;#u;#m;#n;#w;#i;#l;constructor(a){this.#l=a,this.#d=a.document,this.#r=new WeakMap,this.#_=new WeakMap,this.#f=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#f.configure({LOGERRORS:!1})}_onError(a){if(!this.#k)if(a instanceof DOMException||a instanceof this.#l.DOMException)if(a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#l.DOMException(a.message,a.name);else throw a}_setup(a,e,r={}){const{event:l,noexcept:i,warn:c}=r;return this.#k=!!i,this.#i=!!c,this.#p=this._setEvent(l),this.#e=e,[this.#t,this.#s,this.#n]=(0,C.resolveContent)(e),this.#u=(0,C.isInShadowTree)(e),[this.#a,this.#b]=this._correspond(a),this.#w=new WeakMap,e}_setEvent(a){return a instanceof this.#l.MouseEvent||a instanceof this.#l.KeyboardEvent?a:null}_correspond(a){const e=[];this.#c=!1,this.#h=!1;let r;if(this.#t){const l=this.#r.get(this.#t);if(l&&l.has(`${a}`)){const i=l.get(`${a}`);this.#c=i.complex,this.#h=i.descendant,r=i.ast}}if(r){const l=r.length;for(let i=0;i<l;i++)r[i].collected=!1,r[i].dir=null,r[i].filtered=!1,r[i].find=!1,e[i]=[]}else{let l;try{l=(0,x.parseSelector)(a)}catch(f){this._onError(f)}const{branches:i,complex:c}=(0,x.walkAST)(l);let n=!1,d=0;r=[];for(const[...f]of i){const t=[];let s=f.shift();if(s&&s.type!==b.COMBINATOR){const o=new Set;for(;s;){if(s.type===b.COMBINATOR){const[p]=f;if(p.type===b.COMBINATOR){const w=`Invalid selector ${a}`;throw new DOMException(w,b.SYNTAX_ERR)}const _=s.name;/^[\s>]$/.test(_)&&(n=!0),t.push({combo:s,leaves:(0,x.sortAST)(o)}),o.clear()}else if(s){let{name:p}=s;p&&typeof p=="string"&&(p=(0,x.unescapeSelector)(p),typeof p=="string"&&p!==s.name&&(s.name=p),/[|:]/.test(p)&&(s.namespace=!0)),o.add(s)}if(f.length)s=f.shift();else{t.push({combo:null,leaves:(0,x.sortAST)(o)}),o.clear();break}}}r.push({branch:t,collected:!1,dir:null,filtered:!1,find:!1}),e[d]=[],d++}if(this.#t){let f;this.#r.has(this.#t)?f=this.#r.get(this.#t):f=new Map,f.set(`${a}`,{ast:r,complex:c,descendant:n}),this.#r.set(this.#t,f)}this.#c=c,this.#h=n}return[r,e]}_createTreeWalker(a){let e;return this.#w.has(a)?e=this.#w.get(a):(e=this.#d.createTreeWalker(a,b.WALKER_FILTER),this.#w.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#o=this._createTreeWalker(this.#e),this.#m=!1,this.#o}_traverse(a,e=this.#n){let r=e.currentNode,l;if(r===a)l=r;else if(r.contains(a))for(r=e.nextNode();r;){if(r===a){l=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===a);)r=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;r;){if(r===a){l=r;break}r=e.nextNode()}else l=r}return l??null}_collectNthChild(a,e,r){const{a:l,b:i,reverse:c,selector:n}=a,{parentNode:d}=e,f=new Set;let t;if(n)if(this.#r.has(n))t=this.#r.get(n);else{const{branches:s}=(0,x.walkAST)(n);t=s,this.#r.set(n,t)}if(d){const s=this.#n;let o=this._traverse(d,s);o=s.firstChild();let p=0;for(;o;)p++,o=s.nextSibling();o=this._traverse(d,s);const _=new Set;if(t)for(o=s.firstChild();o;){let w;for(const k of t)if(w=this._matchLeaves(k,o,r),!w)break;w&&_.add(o),o=s.nextSibling()}if(l===0){if(i>0&&i<=p){if(_.size){o=this._traverse(d,s),c?o=s.lastChild():o=s.firstChild();let w=0;for(;o;){if(_.has(o)){if(w===i-1){f.add(o);break}w++}c?o=s.previousSibling():o=s.nextSibling()}}else if(!n){o=this._traverse(d,s),c?o=s.lastChild():o=s.firstChild();let w=0;for(;o;){if(w===i-1){f.add(o);break}c?o=s.previousSibling():o=s.nextSibling(),w++}}}}else{let w=i-1;if(l>0)for(;w<0;)w+=l;if(w>=0&&w<p){o=this._traverse(d,s),c?o=s.lastChild():o=s.firstChild();let k=0,N=l>0?0:i-1;for(;o&&(o&&w>=0&&w<p);)_.size?_.has(o)&&(N===w&&(f.add(o),w+=l),l>0?N++:N--):k===w&&(n||f.add(o),w+=l),c?o=s.previousSibling():o=s.nextSibling(),k++}}if(c&&f.size>1){const w=[...f];return new Set(w.reverse())}}else if(e===this.#s&&l+i===1)if(t){let s;for(const o of t)if(s=this._matchLeaves(o,e,r),s)break;s&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:r,b:l,reverse:i}=a,{localName:c,parentNode:n,prefix:d}=e,f=new Set;if(n){const t=this.#n;let s=this._traverse(n,t);s=t.firstChild();let o=0;for(;s;)o++,s=t.nextSibling();if(r===0){if(l>0&&l<=o){s=this._traverse(n,t),i?s=t.lastChild():s=t.firstChild();let p=0;for(;s;){const{localName:_,prefix:w}=s;if(_===c&&w===d){if(p===l-1){f.add(s);break}p++}i?s=t.previousSibling():s=t.nextSibling()}}}else{let p=l-1;if(r>0)for(;p<0;)p+=r;if(p>=0&&p<o){s=this._traverse(n,t),i?s=t.lastChild():s=t.firstChild();let _=r>0?0:l-1;for(;s;){const{localName:w,prefix:k}=s;if(w===c&&k===d){if(_===p&&(f.add(s),p+=r),p<0||p>=o)break;r>0?_++:_--}i?s=t.previousSibling():s=t.nextSibling()}}}if(i&&f.size>1){const p=[...f];return new Set(p.reverse())}}else e===this.#s&&r+l===1&&f.add(e);return f}_matchAnPlusB(a,e,r,l){const{nth:{a:i,b:c,name:n},selector:d}=a,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof i=="string"&&/-?\d+/.test(i)?f.set("a",i*1):f.set("a",0),typeof c=="string"&&/-?\d+/.test(c)?f.set("b",c*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,r={}){let l;if(Array.isArray(a)&&a.length){const[i]=a,{type:c}=i;let n;c===b.COMBINATOR?n=a.shift():n={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:o}=s;if(o===b.COMBINATOR)break;d.push(a.shift())}const f={combo:n,leaves:d};r.dir=T;const t=this._matchCombinator(f,e,r);if(t.size)if(a.length){for(const s of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),s,r),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,r={}){const{astName:l="",branches:i=[],selector:c="",twigBranches:n=[]}=a;let d;if(l==="has")if(c.includes(":has("))d=null;else{let f;for(const t of i)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);r.forgive=f;const t=n.length;let s;for(let o=0;o<t;o++){const p=n[o],_=p.length-1,{leaves:w}=p[_];if(s=this._matchLeaves(w,e,r),s&&_>0){let k=new Set([e]);for(let N=_-1;N>=0;N--){const g=p[N],h=[];r.dir=O;for(const m of k){const u=this._matchCombinator(g,m,r);u.size&&h.push(...u)}if(h.length)N===0?s=!0:k=new Set(h);else{s=!1;break}}}if(s)break}l==="not"?s||(d=e):s&&(d=e)}return d??null}_matchPseudoClassSelector(a,e,r={}){const{children:l,name:i}=a,{localName:c,parentNode:n}=e,{forgive:d,warn:f=this.#i}=r,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(i)){let s;if(this.#r.has(a))s=this.#r.get(a);else{const{branches:p}=(0,x.walkAST)(a),_=[],w=[];for(const[...k]of p){for(const m of k){const u=(0,x.generateCSS)(m);_.push(u)}const N=[],g=new Set;let h=k.shift();for(;h;)if(h.type===b.COMBINATOR?(N.push({combo:h,leaves:[...g]}),g.clear()):h&&g.add(h),k.length)h=k.shift();else{N.push({combo:null,leaves:[...g]}),g.clear();break}w.push(N)}s={astName:i,branches:p,twigBranches:w,selector:_.join(",")},this.#r.set(a,s)}const o=this._matchLogicalPseudoFunc(s,e,r);o&&t.add(o)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(i)){const[s]=l;return this._matchAnPlusB(s,e,i,r)}else switch(i){case"dir":case"lang":{const s=$.matcher.matchSelector(a,e);s&&t.add(s);break}case"current":case"nth-col":case"nth-last-col":{if(f){const s=`Unsupported pseudo-class :${i}()`;throw new DOMException(s,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!d){const s=`Unknown pseudo-class :${i}()`;throw new DOMException(s,b.SYNTAX_ERR)}}else{const s=/^a(?:rea)?$/,o=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,p=/^(?:button|form|input|select|textarea)$/,_=/^(?:details|dialog)$/,w=/^(?:checkbox|radio)$/,k=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:date(?:time-local)?|month|number|range|time|week)$/,g=/^(?:email|number|password|search|tel|text|url)$/;switch(i){case"any-link":case"link":{s.test(c)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(s.test(c)&&e.hasAttribute("href")){const{href:h,origin:m,pathname:u}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),h);y.origin===m&&y.pathname===u&&t.add(e)}break}case"visited":break;case"hover":{const{target:h,type:m}=this.#p??{};(m==="mouseover"||m==="pointerover")&&e.contains(h)&&t.add(e);break}case"active":{const{buttons:h,target:m,type:u}=this.#p??{};(u==="mousedown"||u==="pointerdown")&&h&b.BIT_01&&e.contains(m)&&t.add(e);break}case"target":{const{hash:h}=new URL(this.#t.URL);e.id&&h===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:h}=new URL(this.#t.URL);if(h){const m=h.replace(/^#/,"");let u=this.#t.getElementById(m);for(;u;){if(u===e){t.add(e);break}u=u.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#u&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":case"focus-visible":{const{target:h,type:m}=this.#p??{};if(e===this.#t.activeElement&&e.tabIndex>=0&&(i==="focus"||m==="keydown"&&e.contains(h))){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else{const{display:v,visibility:E}=this.#l.getComputedStyle(u);if(y=!(v==="none"||E==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"focus-within":{let h,m=this.#t.activeElement;if(m.tabIndex>=0)for(;m;){if(m===e){h=!0;break}m=m.parentNode}if(h){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else{const{display:v,visibility:E}=this.#l.getComputedStyle(u);if(y=!(v==="none"||E==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"open":{_.test(c)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(c)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(o.test(c)||(0,P.default)(c))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=n;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&n.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(o.test(c)||(0,P.default)(c))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(c){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||k.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(c){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||k.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let h;c==="textarea"?h=e:c==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(h=e):h=e),h&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&c==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))||e.selected&&c==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&c==="input"&&e.type==="checkbox"||c==="progress"&&!e.hasAttribute("value"))t.add(e);else if(c==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const h=e.name;let m=e.parentNode;for(;m&&m.localName!=="form";)m=m.parentNode;m||(m=this.#t.documentElement);const u=m.getElementsByTagName("input"),y=u.length;let v;for(let E=0;E<y;E++){const S=u[E];if(S.getAttribute("type")==="radio"&&(h?S.getAttribute("name")===h&&(v=!!S.checked):S.hasAttribute("name")||(v=!!S.checked),v))break}v||t.add(e)}break}case"default":{const h=/^(?:button|reset)$/,m=/^(?:image|submit)$/;if(c==="button"&&!(e.hasAttribute("type")&&h.test(e.getAttribute("type")))||c==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))){let u=e.parentNode;for(;u&&u.localName!=="form";)u=u.parentNode;if(u){const y=this.#n;let v=this._traverse(u,y);for(v=y.firstChild();v&&u.contains(v);){const E=v.localName;let S;if(E==="button"?S=!(v.hasAttribute("type")&&h.test(v.getAttribute("type"))):E==="input"&&(S=v.hasAttribute("type")&&m.test(v.getAttribute("type"))),S){v===e&&t.add(e);break}v=y.nextNode()}}}else if(c==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(c==="option"){let u=n,y=!1;for(;u&&u.localName!=="datalist";){if(u.localName==="select"){(u.multiple||u.hasAttribute("multiple"))&&(y=!0);break}u=u.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,E=this.#n;let S=this._traverse(n,E);for(S=E.firstChild();S;){if(S.selected||S.hasAttribute("selected")){v.add(S);break}S=E.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(p.test(c))e.checkValidity()&&t.add(e);else if(c==="fieldset"){const h=this.#n;let m=this._traverse(e,h);m=h.firstChild();let u;for(;m&&e.contains(m)&&!(p.test(m.localName)&&(u=m.checkValidity(),!u));)m=h.nextNode();u&&t.add(e)}break}case"invalid":{if(p.test(c))e.checkValidity()||t.add(e);else if(c==="fieldset"){const h=this.#n;let m=this._traverse(e,h);m=h.firstChild();let u;for(;m&&e.contains(m)&&!(p.test(m.localName)&&(u=m.checkValidity(),!u));)m=h.nextNode();u||t.add(e)}break}case"in-range":{c==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{c==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let h;if(/^(?:select|textarea)$/.test(c))h=e;else if(c==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||w.test(m)||k.test(m)||g.test(m))&&(h=e)}else h=e;h&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let h;if(/^(?:select|textarea)$/.test(c))h=e;else if(c==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||w.test(m)||k.test(m)||g.test(m))&&(h=e)}else h=e;h&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const h=this.#d.createTreeWalker(e,b.SHOW_ALL);let m=h.firstChild(),u;for(;m&&(u=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!!u);)m=h.nextSibling();u&&t.add(e)}else t.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1,reverse:!0},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);if(h===e){const[m]=this._collectNthOfType({a:0,b:1,reverse:!0},e);m===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"defined":{const h=e.getAttribute("is");h?(0,P.default)(h)&&this.#l.customElements.get(h)&&t.add(e):(0,P.default)(c)?this.#l.customElements.get(c)&&t.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&t.add(e);break}case"popover-open":{if(e.popover){const{display:h}=this.#l.getComputedStyle(e);h!=="none"&&t.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const h=`Unsupported pseudo-element ::${i}`;throw new DOMException(h,b.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(f){const h=`Unsupported pseudo-class :${i}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}default:if(i.startsWith("-webkit-")){if(f){const h=`Unsupported pseudo-class :${i}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}}else if(!d){const h=`Unknown pseudo-class :${i}`;throw new DOMException(h,b.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(a,e){const{children:r,name:l}=a;let i;if(Array.isArray(r)){const{branches:c}=(0,x.walkAST)(r[0]),[n]=c,[...d]=n,{host:f}=e;if(l==="host"){let t;for(const s of d){const{type:o}=s;if(o===b.COMBINATOR){const _=`Invalid selector ${(0,x.generateCSS)(a)}`;throw new DOMException(_,b.SYNTAX_ERR)}if(t=this._matchSelector(s,f).has(f),!t)break}t&&(i=e)}else if(l==="host-context"){let t=f,s;for(;t;){for(const o of d){const{type:p}=o;if(p===b.COMBINATOR){const w=`Invalid selector ${(0,x.generateCSS)(a)}`;throw new DOMException(w,b.SYNTAX_ERR)}if(s=this._matchSelector(o,t).has(t),!s)break}if(s)break;t=t.parentNode}s&&(i=e)}}else if(l==="host")i=e;else{const c=`Invalid selector :${l}`;throw new DOMException(c,b.SYNTAX_ERR)}return i??null}_matchSelector(a,e,r){const{type:l}=a,i=new Set;if(a.name===b.EMPTY)return i;const c=(0,x.unescapeSelector)(a.name);if(typeof c=="string"&&c!==a.name&&(a.name=c),e.nodeType===b.ELEMENT_NODE)switch(l){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(c,r);break}case b.SELECTOR_ID:{e.id===c&&i.add(e);break}case b.SELECTOR_CLASS:{e.classList.contains(c)&&i.add(e);break}case b.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,r);default:{const n=$.matcher.matchSelector(a,e,r);n&&i.add(n)}}else if(this.#u&&l===b.SELECTOR_PSEUDO_CLASS&&e.nodeType===b.DOCUMENT_FRAGMENT_NODE){if(c!=="has"&&b.REG_LOGICAL_PSEUDO.test(c))return this._matchPseudoClassSelector(a,e,r);if(b.REG_SHADOW_HOST.test(c)){const n=this._matchShadowHostPseudoClass(a,e,r);n&&i.add(n)}}return i}_matchLeaves(a,e,r){const{attributes:l,localName:i,nodeType:c}=e;let n=this.#_.get(a),d;if(n&&n.has(e)){const{attr:f,matched:t}=n.get(e);l?.length===f&&(d=t)}if(typeof d!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;c===b.ELEMENT_NODE&&f.test(i)?t=!1:t=!0;for(const s of a){const{name:o,type:p}=s;if(p===b.SELECTOR_PSEUDO_CLASS&&o==="dir"&&(t=!1),d=this._matchSelector(s,e,r).has(e),!d)break}t&&(n||(n=new WeakMap),n.set(e,{attr:l?.length,matched:d}),this.#_.set(a,n))}return!!d}_matchHTMLCollection(a,e={}){const{compound:r,filterLeaves:l}=e,i=new Set,c=a.length;if(c)if(r)for(let n=0;n<c;n++){const d=a[n];this._matchLeaves(l,d,e)&&i.add(d)}else{const n=[].slice.call(a);return new Set(n)}return i}_findDescendantNodes(a,e,r){const[l,...i]=a,c=i.length>0,{type:n}=l,d=(0,x.unescapeSelector)(l.name);typeof d=="string"&&d!==l.name&&(l.name=d);let f=new Set,t=!1;if(this.#u)t=!0;else switch(n){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,r);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const s=this.#s.getElementById(d);s&&s!==e&&e.contains(s)&&(c?this._matchLeaves(i,s,r)&&f.add(s):f.add(s))}break}case b.SELECTOR_CLASS:{const s=e.getElementsByClassName(d);f=this._matchHTMLCollection(s,{compound:c,filterLeaves:i});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const s=e.getElementsByTagName(d);f=this._matchHTMLCollection(s,{compound:c,filterLeaves:i})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,r={}){const{combo:l,leaves:i}=a,{name:c}=l,{parentNode:n}=e,{dir:d}=r,f=new Set;if(d===T)switch(c){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(i,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let s=this._traverse(e,t);for(s=t.nextSibling();s;)this._matchLeaves(i,s,r)&&f.add(s),s=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let s=this._traverse(e,t);for(s=t.firstChild();s;)this._matchLeaves(i,s,r)&&f.add(s),s=t.nextSibling();break}case" ":default:{const{nodes:t,pending:s}=this._findDescendantNodes(i,e);if(t.size)return t;if(s){const o=this._createTreeWalker(e);let p=this._traverse(e,o);for(p=o.nextNode();p&&e.contains(p);)this._matchLeaves(i,p,r)&&f.add(p),p=o.nextNode()}}}else switch(c){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(i,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let s=this._traverse(n,t);for(s=t.firstChild();s&&s!==e;)this._matchLeaves(i,s,r)&&f.add(s),s=t.nextSibling()}break}case">":{n&&this._matchLeaves(i,n,r)&&f.add(n);break}case" ":default:{const t=[];let s=n;for(;s;)this._matchLeaves(i,s,r)&&t.push(s),s=s.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:r}=e;let l=this._traverse(r,this.#o),i;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#o.nextNode():l===r&&l!==this.#s&&(l=this.#o.nextNode());l;){if(this._matchLeaves(a,l,{warn:this.#i})){i=l;break}l=this.#o.nextNode()}return i??null}_matchSelf(a){const e=[],r=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return r&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:r}=e,l=[];let i=this._matchLeaves(a,this.#e,{warn:this.#i}),c=!1;if(i&&(l.push(this.#e),c=!0),!i||r){let n=this.#e.parentNode;for(;n&&(i=this._matchLeaves(a,n,{warn:this.#i}),i&&(l.push(n),c=!0),n.parentNode);)n=n.parentNode}return[l,c]}_findFirst(a){const e=[],r=this._findNode(a,{node:this.#e});let l=!1;return r&&(e.push(r),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:r,compound:l,filterLeaves:i,targetType:c}=e;let n=[],d=!1,f=!1;const t=a.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let s=0;s<t;s++){const o=a[s];if(o!==this.#e&&(this.#e.contains(o)||o.contains(this.#e))){if(l){if(this._matchLeaves(i,o,{warn:this.#i})&&(n.push(o),d=!0,c===L))break}else if(n.push(o),d=!0,c===L)break}}else if(r)if(l)for(let s=0;s<t;s++){const o=a[s];if(this._matchLeaves(i,o,{warn:this.#i})&&(n.push(o),d=!0,c===L))break}else n=[].slice.call(a),d=!0,f=!0;else if(l)for(let s=0;s<t;s++){const o=a[s];if(this._matchLeaves(i,o,{warn:this.#i})&&(n.push(o),d=!0,c===L))break}else n=[].slice.call(a),d=!0,f=!0;return[n,d,f]}_findEntryNodes(a,e,r){const{leaves:l}=a,[i,...c]=l,n=c.length>0,{name:d,type:f}=i;let t=[],s=!1,o=!1,p=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(e===L&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(n?this._matchLeaves(c,_,{warn:this.#i})&&(t.push(_),o=!0):(t.push(_),o=!0))}else e===L?[t,o]=this._findFirst(l):p=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,o,s]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:c,targetType:e}))}else e===L?[t,o]=this._findFirst(l):p=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,o,s]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:c,targetType:e}))}else e===L?[t,o]=this._findFirst(l):p=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(d)){if(this.#u&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(i,this.#e);_&&(t.push(_),o=!0)}}else e===D?[t,o]=this._matchSelf(l):e===R?[t,o]=this._findLineal(l,{complex:r}):e===L?[t,o]=this._findFirst(l):p=!0}return{collected:s,compound:n,filtered:o,nodes:t,pending:p}}_collectNodes(a){const e=this.#a.values();if(a===M||a===L){const r=new Set;let l=0;for(const{branch:i}of e){const c=i.length,n=c>1,d=i[0];let f,t;if(n){const{combo:k,leaves:[{name:N,type:g}]}=d,h=i[c-1],{leaves:[{name:m,type:u}]}=h;if(u===b.SELECTOR_PSEUDO_ELEMENT||u===b.SELECTOR_ID)f=O,t=h;else if(g===b.SELECTOR_PSEUDO_ELEMENT||g===b.SELECTOR_ID)f=T,t=d;else if(a===M)if(N==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else if(m==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(c===2){const{name:y}=k;/^[+~]$/.test(y)?(f=O,t=h):(f=T,t=d)}else f=T,t=d;else if(m==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(N==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else{let y;for(const{combo:v,leaves:[E]}of i){const{name:S,type:W}=E;if(W===b.SELECTOR_PSEUDO_CLASS&&S==="dir"){y=!1;break}if(!y&&v){const{name:H}=v;/^[+~]$/.test(H)&&(y=!0)}}y?(f=T,t=d):(f=O,t=h)}}else f=O,t=d;const{collected:s,compound:o,filtered:p,nodes:_,pending:w}=this._findEntryNodes(t,a,n);_.length?(this.#a[l].find=!0,this.#b[l]=_):w&&r.add(new Map([["index",l],["twig",t]])),this.#a[l].collected=s,this.#a[l].dir=f,this.#a[l].filtered=p||!o,l++}if(r.size){let i,c;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(i=this.#e,c=this.#o):(i=this.#s,c=this.#n);let n=this._traverse(i,c);for(;n;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?n===this.#e?d=!0:d=this.#e.contains(n):d=!0,d)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const o=f.get("index");this.#a[o].filtered=!0,this.#a[o].find=!0,this.#b[o].push(n)}}n!==c.currentNode&&(n=this._traverse(n,c)),n=c.nextNode()}}}else{let r=0;for(const{branch:l}of e){const i=l[l.length-1],c=l.length>1,{compound:n,filtered:d,nodes:f}=this._findEntryNodes(i,a,c);f.length&&(this.#a[r].find=!0,this.#b[r]=f),this.#a[r].dir=O,this.#a[r].filtered=d||!n,r++}}return[this.#a,this.#b]}_getCombinedNodes(a,e,r){const l=[];for(const i of e){const c=this._matchCombinator(a,i,{dir:r,warn:this.#i});c.size&&l.push(...c)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,r){const{combo:l,index:i}=r,{combo:c,leaves:n}=a[i],d={combo:l,leaves:n},f=this._getCombinedNodes(d,e,T);let t;if(f.size)if(i===a.length-1){const[s]=(0,C.sortNodes)(f);t=s}else t=this._matchNodeNext(a,f,{combo:c,index:i+1});return t??null}_matchNodePrev(a,e,r){const{index:l}=r,i=a[l],c=new Set([e]),n=this._getCombinedNodes(i,c,O);let d;if(n.size){if(l===0)d=e;else for(const f of n)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_find(a){(a===M||a===L)&&this._prepareQuerySelectorWalker();const[[...e],r]=this._collectNodes(a),l=e.length;let i=new Set;for(let c=0;c<l;c++){const{branch:n,collected:d,dir:f,find:t}=e[c],s=n.length;if(s&&t){const o=r[c],p=o.length,_=s-1;if(_===0)if((a===M||a===L)&&this.#e.nodeType===b.ELEMENT_NODE)for(let w=0;w<p;w++){const k=o[w];if(k!==this.#e&&this.#e.contains(k)&&(i.add(k),a!==M))break}else if(a===M)if(i.size){const w=[...i];i=new Set([...w,...o]),this.#m=!0}else i=new Set(o);else{const[w]=o;i.add(w)}else if(a===M)if(f===T){let{combo:w}=n[0];for(const k of o){let N=new Set([k]);for(let g=1;g<s;g++){const{combo:h,leaves:m}=n[g],u={combo:w,leaves:m};if(N=this._getCombinedNodes(u,N,f),N.size)if(g===_)if(i.size){const y=[...i];i=new Set([...y,...N]),this.#m=!0}else i=N;else w=h;else break}}}else for(const w of o){let k=new Set([w]);for(let N=_-1;N>=0;N--){const g=n[N];if(k=this._getCombinedNodes(g,k,f),k.size)N===0&&(i.add(w),s>1&&i.size>1&&(this.#m=!0));else break}}else if(a===L&&f===T){const{combo:w}=n[0];let k;for(const N of o)if(k=this._matchNodeNext(n,new Set([N]),{combo:w,index:1}),k){i.add(k);break}if(!k&&!d){const{leaves:N}=n[0],[g]=o;let h=this._findNode(N,{node:g});for(;h;){if(k=this._matchNodeNext(n,new Set([h]),{combo:w,index:1}),k){i.add(k);break}h=this._findNode(N,{node:h})}}}else{let w;for(const k of o)if(w=this._matchNodePrev(n,k,{index:_-1}),w){i.add(k);break}if(!w&&!d&&a===L){const{leaves:k}=n[_],[N]=o;let g=this._findNode(k,{node:N});for(;g;){if(w=this._matchNodePrev(n,g,{index:_-1}),w){i.add(g);break}g=this._findNode(k,{node:g})}}}}}return i}matches(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const i=`Unexpected node ${e?.nodeName}`;throw new TypeError(i)}(0,x.filterSelector)(a,{complex:this.#c,descendant:!0})?l=this.#f.match(a,e):(this._setup(a,e,r),l=this._find(D).size)}catch(i){this._onError(i)}return!!l}closest(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const i=`Unexpected node ${e?.nodeName}`;throw new TypeError(i)}if((0,x.filterSelector)(a,{complex:this.#c,descendant:!0}))l=this.#f.closest(a,e);else{this._setup(a,e,r);const i=this._find(R);if(i.size){let c=this.#e;for(;c;){if(i.has(c)){l=c;break}c=c.parentNode}}}}catch(i){this._onError(i)}return l??null}querySelector(a,e,r){let l;try{if(this._setup(a,e,r),this.#d===this.#t&&!this.#h&&(0,x.filterSelector)(a,{complex:this.#c,descendant:!1}))l=this.#f.first(a,e);else{const i=this._find(L);i.delete(this.#e),i.size&&([l]=(0,C.sortNodes)(i))}}catch(i){this._onError(i)}return l??null}querySelectorAll(a,e,r){let l;try{if(this._setup(a,e,r),this.#d===this.#t&&!this.#h&&(0,x.filterSelector)(a,{complex:this.#c,descendant:!1}))l=this.#f.select(a,e);else{const i=this._find(M);i.delete(this.#e),i.size&&(this.#m?l=(0,C.sortNodes)(i):l=[...i])}}catch(i){this._onError(i)}return l??[]}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -1,3 +0,3 @@ | ||
var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var A=(s,t)=>{for(var r in t)g(s,r,{get:t[r],enumerable:!0})},O=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!y.call(s,n)&&n!==r&&g(s,n,{get:()=>t[n],enumerable:!(i=S(t,n))||i.enumerable});return s};var T=s=>O(g({},"__esModule",{value:!0}),s);var L={};A(L,{filterSelector:()=>D,generateCSS:()=>u.generate,parseAstName:()=>I,parseSelector:()=>h,preprocess:()=>E,sortAST:()=>_,unescapeSelector:()=>$,walkAST:()=>m});module.exports=T(L);var d=require("css-tree"),e=require("./constant.js"),u=require("css-tree");const $=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let i=1;i<r;i++){let n=t[i];if(n===""&&i===r-1)n=e.U_FFFD;else{const f=/^([\da-f]{1,6}\s?)/i.exec(n);if(f){const[,a]=f;let c;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),w=parseInt(a,e.HEX);w===0||w>=o&&w<=p?c=e.U_FFFD:c=String.fromCodePoint(w)}catch{c=e.U_FFFD}let l="";n.length>a.length&&(l=n.substring(a.length)),n=`${c}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},E=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let n=t.substring(r+1);if(/^\d$/.test(n.substring(0,1)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);const f=n.codePointAt(0);if(f===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(f>e.BIT_FFFF){const a=`\\${f.toString(e.HEX)} `;n.length===e.DUO?n=a:n=`${a}${n.substring(e.DUO)}`}t=`${i}${n}`,r++}t=t.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},h=s=>{if(s=E(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,d.toPlainObject)(r)}catch(r){const{message:i}=r,n=/(:(is|where)\(\s*\))/,f=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;if(i==="Identifier is expected"&&f.test(s)){const[,a,c]=f.exec(s),l=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let o=a.replace(c,l);o===":lang()"&&(o=`:lang(${e.EMPTY})`),t=h(s.replace(a,o))}else if((i==="Identifier is expected"||i==="Selector is expected")&&n.test(s)){const[,a,c]=n.exec(s),l=`:${c}(${e.EMPTY})`;t=h(s.replace(a,l))}else if(i==='"]" is expected'&&!s.endsWith("]"))t=h(`${s}]`);else if(i==='")" is expected'&&!s.endsWith(")"))t=h(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set;let r;return(0,d.walk)(s,{enter:n=>{n.type===e.SELECTOR?t.add(n.children):(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)||n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name))&&(r=!0)}}),r&&(0,d.findAll)(s,(n,f,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)for(const{children:p}of o)t.has(p)&&t.delete(p)}else if(n.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(n.name)){const c=a.filter(l=>{const{name:o,type:p}=l;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:l}of c)for(const{children:o}of l)t.has(o)&&t.delete(o)}}}),[...t]},_=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,n)=>{const{type:f}=i,{type:a}=n,c=r.get(f),l=r.get(a);let o;return c===l?o=0:c>l?o=1:o=-1,o})}return t},I=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:r}},D=s=>!(!s||typeof s!="string"||/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(s)||s.includes(":")&&/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\d*)n?|n)|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(s));0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
var x=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var U=(s,t)=>{for(var n in t)x(s,n,{get:t[n],enumerable:!0})},X=(s,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of b(t))!F.call(s,r)&&r!==n&&x(s,r,{get:()=>t[r],enumerable:!(o=N(t,r))||o.enumerable});return s};var Y=s=>X(x({},"__esModule",{value:!0}),s);var oe={};U(oe,{filterSelector:()=>re,generateCSS:()=>B.generate,parseAstName:()=>k,parseSelector:()=>g,preprocess:()=>R,sortAST:()=>j,unescapeSelector:()=>H,walkAST:()=>v});module.exports=Y(oe);var O=require("css-tree"),e=require("./constant.js"),B=require("css-tree");const H=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),n=t.length;for(let o=1;o<n;o++){let r=t[o];if(r===""&&o===n-1)r=e.U_FFFD;else{const i=/^([\da-f]{1,6}\s?)/i.exec(r);if(i){const[,$]=i;let l;try{const c=parseInt("D800",e.HEX),f=parseInt("DFFF",e.HEX),p=parseInt($,e.HEX);p===0||p>=c&&p<=f?l=e.U_FFFD:l=String.fromCodePoint(p)}catch{l=e.U_FFFD}let a="";r.length>$.length&&(a=r.substring($.length)),r=`${l}${a}`}else/^[\n\r\f]/.test(r)&&(r="\\"+r)}t[o]=r}s=t.join("")}return s},R=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let n=0;for(;n>=0&&(n=t.indexOf("#",n),!(n<0));){const o=t.substring(0,n+1);let r=t.substring(n+1);if(/^\d$/.test(r.substring(0,1)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);const i=r.codePointAt(0);if(i===e.BIT_HYPHEN){if(/^\d$/.test(r.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(i>e.BIT_FFFF){const $=`\\${i.toString(e.HEX)} `;r.length===e.DUO?r=$:r=`${$}${r.substring(e.DUO)}`}t=`${o}${r}`,n++}t=t.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},g=s=>{if(s=R(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const n=(0,O.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,O.toPlainObject)(n)}catch(n){const{message:o}=n,r=/(:(is|where)\(\s*\))/,i=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/;if(o==="Identifier is expected"&&i.test(s)){const[,$,l]=i.exec(s),a=l.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let c=$.replace(l,a);c===":lang()"&&(c=`:lang(${e.EMPTY})`),t=g(s.replace($,c))}else if((o==="Identifier is expected"||o==="Selector is expected")&&r.test(s)){const[,$,l]=r.exec(s),a=`:${l}(${e.EMPTY})`;t=g(s.replace($,a))}else if(o==='"]" is expected'&&!s.endsWith("]"))t=g(`${s}]`);else if(o==='")" is expected'&&!s.endsWith(")"))t=g(`${s})`);else throw new DOMException(o,e.SYNTAX_ERR)}return t},v=(s={})=>{const t=new Set;let n,o;return(0,O.walk)(s,{enter:i=>{i.type===e.SELECTOR?t.add(i.children):(i.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(i.name)||i.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(i.name))&&(n=!0)}}),n&&(0,O.findAll)(s,(i,$,l)=>{if(l){if(i.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(i.name)){const a=l.filter(c=>{const{name:f,type:p}=c;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(f)});for(const{children:c}of a)for(const{children:f}of c)for(const{children:p}of f)if(t.has(p)){for(const S of p){const{type:G}=S;if(G===e.COMBINATOR){o=!0;break}}t.delete(p)}}else if(i.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(i.name)){const a=l.filter(c=>{const{name:f,type:p}=c;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(f)});for(const{children:c}of a)for(const{children:f}of c)t.has(f)&&t.delete(f)}}}),{branches:[...t],complex:!!o}},j=s=>{const t=[...s];if(t.length>1){const n=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((o,r)=>{const{type:i}=o,{type:$}=r,l=n.get(i),a=n.get($);let c;return l===a?c=0:l>a?c=1:c=-1,c})}return t},k=s=>{let t,n;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,n]=s.split("|"):(t="*",n=s);else throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);return{prefix:t,localName:n}},C="(?:first|last|only)-(?:child|of-type)",T="(?:0|[1-9]\\d*)",W=`[+-]?(?:${T}n?|n)|(?:[+-]?${T})?n\\s*[+-]\\s*${T}`,h=`nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${W})\\s*\\)`,E="\\*|[A-Za-z][\\w-]*",L="\\[[^\\]]+\\]|[#.:][\\w-]+",_="(?:is|not|where)",A="\\s?[\\s>~+]\\s?",u="\\s?[~+]\\s?",d=`(?:${E}|(?:${E})?(?:${L})+)`,w=`${d}(?:${A}${d})*`,I=`${d}(?:${u}${d})*`,z=`:${_}\\(\\s*${d}(?:\\s*,\\s*${d})*\\s*\\)`,K=`:${_}\\(\\s*${w}(?:\\s*,\\s*${w})*\\s*\\)`,Z=`:${_}\\(\\s*${I}(?:\\s*,\\s*${I})*\\s*\\)`,D=`(?:${E}|(?:${E})?(?:${L}|${z})+)`,y=`(?:${E}|(?:${E})?(?:${L}|${K})+)`,P=`(?:${E}|(?:${E})?(?:${L}|${Z})+)`,m=`${y}(?:${A}${y})*`,M=`${P}(?:${u}${P})*`,q=`${_}\\(\\s*${D}(?:\\s*,\\s*${D})*\\s*\\)`,J=`${_}\\(\\s*${m}(?:\\s*,\\s*${m})*\\s*\\)`,Q=`${_}\\(\\s*${M}(?:\\s*,\\s*${M})*\\s*\\)`,V=new RegExp(`:${_}\\(`),ee=new RegExp(`:(?!${C}|${h}|${J})`),te=new RegExp(`:(?!${C}|${h}|${Q})`),se=new RegExp(`:(?!${C}|${h}|${q})`),ne=new RegExp(`:(?!${C}|${h})`),re=(s,t={})=>{if(!s||typeof s!="string"||/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(s))return!1;if(s.includes(":")){let n;if(V.test(s)){const{complex:o,descendant:r}=t;o&&r?n=ee:o?n=te:n=se}else n=ne;if(n.test(s))return!1}return!0};0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
//# sourceMappingURL=parser.js.map |
@@ -26,6 +26,6 @@ { | ||
"dependencies": { | ||
"@asamuzakjp/nwsapi": "^2.2.2", | ||
"bidi-js": "^1.0.3", | ||
"css-tree": "^2.3.1", | ||
"is-potential-custom-element-name": "^1.0.1", | ||
"nwsapi": "2.2.2" | ||
"is-potential-custom-element-name": "^1.0.1" | ||
}, | ||
@@ -37,15 +37,15 @@ "devDependencies": { | ||
"chai": "^5.1.1", | ||
"commander": "^12.0.0", | ||
"esbuild": "^0.21.1", | ||
"commander": "^12.1.0", | ||
"esbuild": "^0.21.4", | ||
"eslint": "^8.57.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-jsdoc": "^48.2.4", | ||
"eslint-plugin-regexp": "^2.5.0", | ||
"eslint-plugin-jsdoc": "^48.2.7", | ||
"eslint-plugin-regexp": "^2.6.0", | ||
"eslint-plugin-unicorn": "^53.0.0", | ||
"happy-dom": "^14.10.1", | ||
"jsdom": "^24.0.0", | ||
"linkedom": "^0.16.11", | ||
"happy-dom": "^14.12.0", | ||
"jsdom": "^24.1.0", | ||
"linkedom": "^0.18.0", | ||
"mocha": "^10.4.0", | ||
"sinon": "^17.0.2", | ||
"sinon": "^18.0.0", | ||
"typescript": "^5.4.5", | ||
@@ -65,3 +65,3 @@ "wpt-runner": "^5.0.0" | ||
}, | ||
"version": "4.3.0" | ||
"version": "4.4.0" | ||
} |
@@ -167,2 +167,3 @@ # DOM Selector | ||
|E:nth‑last‑col(n)|Unsupported| | | ||
|E:popover-open|✓| | | ||
|E:host|✓| | | ||
@@ -260,41 +261,41 @@ |E:host(s)|✓| | | ||
|Selector|jsdom v24.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|Selector|jsdom v24.1.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`matches('.content')`|993,434 ops/sec ±0.92%|7,738 ops/sec ±0.82%|9,388 ops/sec ±0.63%|934,402 ops/sec ±1.24%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|593,746 ops/sec ±0.24%|7,510 ops/sec ±0.73%|9,048 ops/sec ±1.11%|510,470 ops/sec ±0.17%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|7,532 ops/sec ±0.64%|F|148,751 ops/sec ±1.43%|patched-jsdom is the fastest.| | ||
|compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|478,481 ops/sec ±0.32%|7,437 ops/sec ±0.57%|8,922 ops/sec ±0.47%|406,300 ops/sec ±0.32%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|151,608 ops/sec ±0.24%|F|5,749 ops/sec ±0.57%|136,036 ops/sec ±0.46%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,654 ops/sec ±0.57%|40,774 ops/sec ±0.59%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|F|F|6,243 ops/sec ±0.45%|146,879 ops/sec ±1.92%|patched-jsdom is the fastest.| | ||
|simple selector:<br>`matches('.content')`|989,361 ops/sec ±0.27%|7,447 ops/sec ±1.10%|9,037 ops/sec ±1.74%|947,094 ops/sec ±0.24%|jsdom is the fastest and 1.0 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:last-child, :only-child)')`|581,187 ops/sec ±0.21%|7,137 ops/sec ±0.82%|8,808 ops/sec ±1.24%|492,756 ops/sec ±0.25%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|compound selector:<br>`matches('p.content[id]:is(:invalid-nth-child, :only-child)')`|F|7,144 ops/sec ±0.51%|F|145,203 ops/sec ±0.94%|patched-jsdom is the fastest.| | ||
|compound selector:<br>`matches('p.content[id]:not(:is(.foo, .bar))')`|472,261 ops/sec ±1.64%|7,199 ops/sec ±0.58%|8,612 ops/sec ±0.51%|403,920 ops/sec ±0.29%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|152,011 ops/sec ±0.66%|F|5,737 ops/sec ±0.43%|135,540 ops/sec ±0.41%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,767 ops/sec ±0.47%|39,996 ops/sec ±0.79%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`matches(':is(.box > .content, .block > .content)')`|416,215 ops/sec ±0.49%|F|6,105 ops/sec ±0.29%|358,945 ops/sec ±0.29%|jsdom is the fastest and 1.2 times faster than patched-jsdom.| | ||
### closest() | ||
|Selector|jsdom v24.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|Selector|jsdom v24.1.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`closest('.container')`|362,505 ops/sec ±0.41%|7,607 ops/sec ±0.62%|9,365 ops/sec ±0.59%|362,275 ops/sec ±0.39%|jsdom is the fastest and 1.0 times faster than patched-jsdom.| | ||
|compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|137,678 ops/sec ±0.32%|F|8,749 ops/sec ±0.67%|129,174 ops/sec ±0.30%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|139,504 ops/sec ±0.43%|F|5,774 ops/sec ±0.51%|126,287 ops/sec ±0.32%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,710 ops/sec ±0.36%|29,552 ops/sec ±0.90%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|F|4,754 ops/sec ±0.73%|5,935 ops/sec ±0.32%|64,421 ops/sec ±0.98%|patched-jsdom is the fastest.| | ||
|simple selector:<br>`closest('.container')`|367,877 ops/sec ±1.14%|7,218 ops/sec ±0.76%|9,181 ops/sec ±0.64%|356,762 ops/sec ±1.02%|jsdom is the fastest and 1.0 times faster than patched-jsdom.| | ||
|compound selector:<br>`closest('div.container[id]:not(.foo, .box)')`|134,650 ops/sec ±0.32%|F|8,549 ops/sec ±0.62%|125,888 ops/sec ±3.16%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|134,654 ops/sec ±2.02%|F|5,751 ops/sec ±1.01%|119,709 ops/sec ±2.00%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|5,596 ops/sec ±0.81%|28,732 ops/sec ±1.13%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`closest(':is(.container > .content, .container > .box)')`|192,885 ops/sec ±1.15%|4,685 ops/sec ±1.30%|5,927 ops/sec ±0.64%|181,927 ops/sec ±1.39%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
### querySelector() | ||
|Selector|jsdom v24.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|Selector|jsdom v24.1.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`querySelector('.content')`|28,406 ops/sec ±0.62%|9,286 ops/sec ±0.63%|10,750 ops/sec ±0.59%|25,303 ops/sec ±1.00%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|9,564 ops/sec ±0.33%|8,884 ops/sec ±0.59%|10,834 ops/sec ±0.60%|8,809 ops/sec ±0.53%|linkedom is the fastest and 1.2 times faster than patched-jsdom. jsdom is 1.1 times faster than patched-jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|228 ops/sec ±0.41%|F|1,390 ops/sec ±0.61%|713 ops/sec ±2.32%|linkedom is the fastest and 1.9 times faster than patched-jsdom. patched-jsdom is 3.1 times faster than jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|1,523 ops/sec ±1.72%|494 ops/sec ±1.97%|linkedom is the fastest and 3.1 times faster than patched-jsdom.| | ||
|complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|F|F|9,987 ops/sec ±0.59%|101,461 ops/sec ±1.56%|patched-jsdom is the fastest.| | ||
|simple selector:<br>`querySelector('.content')`|27,400 ops/sec ±0.96%|9,042 ops/sec ±1.19%|10,550 ops/sec ±0.69%|25,885 ops/sec ±1.48%|jsdom is the fastest and 1.1 times faster than patched-jsdom.| | ||
|compound selector:<br>`querySelector('p.content[id]:is(:last-child, :only-child)')`|8,685 ops/sec ±1.47%|8,723 ops/sec ±1.20%|9,836 ops/sec ±0.69%|8,418 ops/sec ±1.41%|linkedom is the fastest and 1.2 times faster than patched-jsdom. jsdom is 1.0 times faster than patched-jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|206 ops/sec ±1.48%|F|1,289 ops/sec ±0.42%|709 ops/sec ±1.75%|linkedom is the fastest and 1.8 times faster than patched-jsdom. patched-jsdom is 3.4 times faster than jsdom.| | ||
|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|1,598 ops/sec ±0.35%|476 ops/sec ±1.94%|linkedom is the fastest and 3.4 times faster than patched-jsdom.| | ||
|complex selector within logical pseudo-class:<br>`querySelector(':is(.box > .content, .block > .content)')`|2,921 ops/sec ±1.78%|F|9,782 ops/sec ±0.52%|97,513 ops/sec ±1.46%|patched-jsdom is the fastest. patched-jsdom is 33.4 times faster than jsdom.| | ||
### querySelectorAll() | ||
|Selector|jsdom v24.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|Selector|jsdom v24.1.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result| | ||
|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| | ||
|simple selector:<br>`querySelectorAll('.content')`|2,713 ops/sec ±1.04%|729 ops/sec ±0.29%|1,187 ops/sec ±0.40%|2,988 ops/sec ±0.19%|patched-jsdom is the fastest. patched-jsdom is 1.1 times faster than jsdom.| | ||
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|946 ops/sec ±0.26%|724 ops/sec ±0.35%|1,194 ops/sec ±0.25%|971 ops/sec ±0.25%|linkedom is the fastest and 1.2 times faster than patched-jsdom. patched-jsdom is 1.0 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|225 ops/sec ±1.41%|F|416 ops/sec ±1.46%|818 ops/sec ±1.67%|patched-jsdom is the fastest. patched-jsdom is 3.6 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|443 ops/sec ±1.47%|530 ops/sec ±1.87%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|F|F|525 ops/sec ±0.27%|255 ops/sec ±1.13%|linkedom is the fastest and 2.1 times faster than patched-jsdom.| | ||
|simple selector:<br>`querySelectorAll('.content')`|2,549 ops/sec ±0.55%|729 ops/sec ±0.48%|1,188 ops/sec ±1.57%|3,153 ops/sec ±0.95%|patched-jsdom is the fastest. patched-jsdom is 1.2 times faster than jsdom.| | ||
|compound selector:<br>`querySelectorAll('p.content[id]:is(:last-child, :only-child)')`|880 ops/sec ±1.32%|706 ops/sec ±1.55%|1,156 ops/sec ±0.93%|938 ops/sec ±1.27%|linkedom is the fastest and 1.2 times faster than patched-jsdom. patched-jsdom is 1.1 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|196 ops/sec ±0.73%|F|414 ops/sec ±0.24%|797 ops/sec ±1.66%|patched-jsdom is the fastest. patched-jsdom is 4.1 times faster than jsdom.| | ||
|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')`|F|F|451 ops/sec ±0.36%|504 ops/sec ±1.88%|patched-jsdom is the fastest.| | ||
|complex selector within logical pseudo-class:<br>`querySelectorAll(':is(.box > .content, .block > .content)')`|273 ops/sec ±0.89%|F|498 ops/sec ±1.38%|236 ops/sec ±2.36%|linkedom is the fastest and 2.1 times faster than patched-jsdom. jsdom is 1.2 times faster than patched-jsdom.| | ||
@@ -301,0 +302,0 @@ |
@@ -11,3 +11,3 @@ /** | ||
BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF, BIT_HYPHEN, | ||
DUO, EMPTY, HEX, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR, | ||
COMBINATOR, DUO, EMPTY, HEX, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR, | ||
SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS, | ||
@@ -173,3 +173,3 @@ SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE, SYNTAX_ERR, TYPE_FROM, TYPE_TO, U_FFFD | ||
* @param {object} ast - AST | ||
* @returns {Array.<object|undefined>} - collection of AST branches | ||
* @returns {object} - branches and complex | ||
*/ | ||
@@ -179,2 +179,3 @@ export const walkAST = (ast = {}) => { | ||
let hasPseudoFunc; | ||
let hasComplexSelector; | ||
const opt = { | ||
@@ -210,2 +211,9 @@ enter: node => { | ||
if (branches.has(greatGrandChildren)) { | ||
for (const greatGrandChild of greatGrandChildren) { | ||
const { type: greatGrandChildType } = greatGrandChild; | ||
if (greatGrandChildType === COMBINATOR) { | ||
hasComplexSelector = true; | ||
break; | ||
} | ||
} | ||
branches.delete(greatGrandChildren); | ||
@@ -236,3 +244,6 @@ } | ||
} | ||
return [...branches]; | ||
return { | ||
branches: [...branches], | ||
complex: !!hasComplexSelector | ||
}; | ||
}; | ||
@@ -299,8 +310,52 @@ | ||
/* filter selector constants */ | ||
// :first-child, :last-child etc. | ||
const N_ST = '(?:first|last|only)-(?:child|of-type)'; | ||
const DIGIT = '(?:0|[1-9]\\d*)'; | ||
const ANB = `[+-]?(?:${DIGIT}n?|n)|(?:[+-]?${DIGIT})?n\\s*[+-]\\s*${DIGIT}`; | ||
// exclude An+B with selector list, e.g. :nth-child(2n+1 of .foo) | ||
const N_TH = `nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${ANB})\\s*\\)`; | ||
// *, tag | ||
const TAG_TYPE = '\\*|[A-Za-z][\\w-]*'; | ||
// attr, id, class, pseudo-class | ||
const SUB_CLASS = '\\[[^\\]]+\\]|[#.:][\\w-]+'; | ||
const LOGICAL_KEY = '(?:is|not|where)'; | ||
const COMBO_A = '\\s?[\\s>~+]\\s?'; | ||
const COMBO_B = '\\s?[~+]\\s?'; | ||
const COMPOUND_A = `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_CLASS})+)`; | ||
const COMPLEX_A = `${COMPOUND_A}(?:${COMBO_A}${COMPOUND_A})*`; | ||
const COMPLEX_B = `${COMPOUND_A}(?:${COMBO_B}${COMPOUND_A})*`; | ||
const NESTED_LOGICAL_A = | ||
`:${LOGICAL_KEY}\\(\\s*${COMPOUND_A}(?:\\s*,\\s*${COMPOUND_A})*\\s*\\)`; | ||
const NESTED_LOGICAL_B = | ||
`:${LOGICAL_KEY}\\(\\s*${COMPLEX_A}(?:\\s*,\\s*${COMPLEX_A})*\\s*\\)`; | ||
const NESTED_LOGICAL_C = | ||
`:${LOGICAL_KEY}\\(\\s*${COMPLEX_B}(?:\\s*,\\s*${COMPLEX_B})*\\s*\\)`; | ||
const COMPOUND_B = | ||
`(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_CLASS}|${NESTED_LOGICAL_A})+)`; | ||
const COMPOUND_C = | ||
`(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_CLASS}|${NESTED_LOGICAL_B})+)`; | ||
const COMPOUND_D = | ||
`(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_CLASS}|${NESTED_LOGICAL_C})+)`; | ||
const COMPLEX_C = `${COMPOUND_C}(?:${COMBO_A}${COMPOUND_C})*`; | ||
const COMPLEX_D = `${COMPOUND_D}(?:${COMBO_B}${COMPOUND_D})*`; | ||
const LOGICAL_COMPOUND = | ||
`${LOGICAL_KEY}\\(\\s*${COMPOUND_B}(?:\\s*,\\s*${COMPOUND_B})*\\s*\\)`; | ||
const LOGICAL_COMPLEX_A = | ||
`${LOGICAL_KEY}\\(\\s*${COMPLEX_C}(?:\\s*,\\s*${COMPLEX_C})*\\s*\\)`; | ||
const LOGICAL_COMPLEX_B = | ||
`${LOGICAL_KEY}\\(\\s*${COMPLEX_D}(?:\\s*,\\s*${COMPLEX_D})*\\s*\\)`; | ||
const REG_LOGICAL_KEY = new RegExp(`:${LOGICAL_KEY}\\(`); | ||
const REG_COMPLEX_A = new RegExp(`:(?!${N_ST}|${N_TH}|${LOGICAL_COMPLEX_A})`); | ||
const REG_COMPLEX_B = new RegExp(`:(?!${N_ST}|${N_TH}|${LOGICAL_COMPLEX_B})`); | ||
const REG_COMPOUND = new RegExp(`:(?!${N_ST}|${N_TH}|${LOGICAL_COMPOUND})`); | ||
const REG_CHILD_INDEXED = new RegExp(`:(?!${N_ST}|${N_TH})`); | ||
/** | ||
* filter selector (for nwsapi) | ||
* @param {string} selector - selector | ||
* @param {object} opt - options | ||
* @returns {boolean} - result | ||
*/ | ||
export const filterSelector = selector => { | ||
export const filterSelector = (selector, opt = {}) => { | ||
if (!selector || typeof selector !== 'string') { | ||
@@ -314,27 +369,18 @@ return false; | ||
} | ||
// filter pseudo-class selectors | ||
// filter pseudo-classes other than child-indexed and logical combination | ||
if (selector.includes(':')) { | ||
// digit: | ||
// `(?:0|[1-9]\d*)` | ||
// anb: | ||
// `[+-]?(?:${digit}n?|n)|(?:[+-]?${digit})?n\s*[+-]\s*${digit}` | ||
// type: *, tag | ||
// `\*|[A-Za-z][\w-]*` | ||
// subclass: attr, id, class, pseudo-class (nst) | ||
// `\[[^\]]+\]|[#.:][\w-]+` | ||
// compound: | ||
// `(?:${type}|(?:${type})?(?:${subclass})+)` | ||
// nested logical: | ||
// `:(?:is|not|where)\(\s*${compound}(?:\s*,\s*${compound})*\s*\)` | ||
// compoundB: | ||
// `(?:${type}|(?:${type})?(?:${subclass}|${nestedLogical})+)` | ||
// nst: | ||
// `(?:first|last|only)-(?:child|of-type)` | ||
// nth: exclude An+B with selector list, e.g. :nth-child(2n+1 of .foo) | ||
// `nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|${anb})\s*\)` | ||
// logical: exclude complex selector, e.g. :is(.foo > .bar) | ||
// `(?:is|not|where)\(\s*${compoundB}(?:\s*,\s*${compoundB})*\s*\)` | ||
// filter pseudos other than child-indexed and logical combination pseudos | ||
// `:(?!${nst}|${nth}|${logical})` | ||
if (/:(?!(?:first|last|only)-(?:child|of-type)|nth-(?:last-)?(?:child|of-type)\(\s*(?:even|odd|[+-]?(?:(?:0|[1-9]\d*)n?|n)|(?:[+-]?(?:0|[1-9]\d*))?n\s*[+-]\s*(?:0|[1-9]\d*))\s*\)|(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+|:(?:is|not|where)\(\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+)(?:\s*,\s*(?:\*|[A-Za-z][\w-]*|(?:\*|[A-Za-z][\w-]*)?(?:\[[^\]]+\]|[#.:][\w-]+)+))*\s*\))+))*\s*\))/.test(selector)) { | ||
let reg; | ||
if (REG_LOGICAL_KEY.test(selector)) { | ||
const { complex, descendant } = opt; | ||
if (complex && descendant) { | ||
reg = REG_COMPLEX_A; | ||
} else if (complex) { | ||
reg = REG_COMPLEX_B; | ||
} else { | ||
reg = REG_COMPOUND; | ||
} | ||
} else { | ||
reg = REG_CHILD_INDEXED; | ||
} | ||
if (reg.test(selector)) { | ||
return false; | ||
@@ -341,0 +387,0 @@ } |
export function unescapeSelector(selector?: string): string | null; | ||
export function preprocess(...args: any[]): string; | ||
export function parseSelector(selector: string): object; | ||
export function walkAST(ast?: object): Array<object | undefined>; | ||
export function walkAST(ast?: object): object; | ||
export function sortAST(asts: Array<object>): Array<object>; | ||
export function parseAstName(selector: string): object; | ||
export function filterSelector(selector: string): boolean; | ||
export function filterSelector(selector: string, opt?: object): boolean; | ||
export { generate as generateCSS } from "css-tree"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
397478
4485
335
+ Added@asamuzakjp/nwsapi@^2.2.2
+ Added@asamuzakjp/nwsapi@2.2.24(transitive)
- Removednwsapi@2.2.2
- Removednwsapi@2.2.2(transitive)