@asamuzakjp/dom-selector
Advanced tools
Comparing version 5.3.3 to 5.3.4
@@ -1,2 +0,2 @@ | ||
var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var Y=(S,r)=>{for(var e in r)R(S,e,{get:r[e],enumerable:!0})},q=(S,r,e,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of j(r))!V.call(S,n)&&n!==e&&R(S,n,{get:()=>r[n],enumerable:!(f=B(r,n))||f.enumerable});return S};var K=S=>q(R({},"__esModule",{value:!0}),S);var Z={};Y(Z,{Finder:()=>J});module.exports=K(Z);var F=require("./matcher.js"),g=require("./parser.js"),k=require("./utility.js"),c=require("./constant.js");const v="next",x="prev",X="Tab",O=/^a(?:rea)?$/,M=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,T=/^(?:button|form|input|select|textarea)$/,I=/^(?:details|dialog)$/,P=/^host(?:-context)?$/,C=/^(?:checkbox|radio)$/,$=/^(?:date(?:time-local)?|month|number|range|time|week)$/,D=/^(?:button|reset)$/,U=/^(?:image|submit)$/,Q=/^(?:email|number|password|search|tel|text|url)$/;class J{#l;#c;#w;#t;#f;#n;#k;#o;#b;#h;#e;#d;#_;#m;#N;#s;#u;#r;#p;#i;#a;constructor(r){this.#a=r,this.#h=new F.Matcher,this.#c=new WeakMap,this.#f=new WeakMap,this.#b=new WeakMap,this.#N=new WeakMap,this.#n=null,this.#k=null,this._registerEventListeners()}onError(r,e={}){if(!(e.noexcept??this.#_))if(r instanceof DOMException||r instanceof this.#a.DOMException)if(r.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw new this.#a.DOMException(r.message,r.name);else throw r.name in this.#a?new this.#a[r.name](r.message):r}setup(r,e,f={}){const{event:n,noexcept:a,warn:l}=f;return this.#_=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#u=(0,k.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(r),this.#b=new WeakMap,this.#p=new WeakMap,this._setEvent(n),e}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],f=["mouseover","mousedown","mouseup","mouseout"];for(const a of f)e.push(this.#a.addEventListener(a,l=>{this.#n=l},r));const n=["keydown","keyup"];for(const a of n)e.push(this.#a.addEventListener(a,l=>{l.key===X&&(this.#n=l)},r));return e.push(this.#a.addEventListener("focusin",a=>{this.#k=a},r)),e}_setEvent(r){return(r instanceof this.#a.KeyboardEvent||r instanceof this.#a.MouseEvent)&&(this.#n=r),this.#n}_correspond(r){const e=[];this.#w=!1,this.#o=!1;let f;if(this.#f.has(this.#t)){const n=this.#f.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);f=a.ast,this.#w=a.descendant,this.#o=a.invalidate}}if(f){const n=f.length;for(let a=0;a<n;a++)f[a].collected=!1,f[a].dir=null,f[a].filtered=!1,f[a].find=!1,e[a]=[]}else{let n;try{n=(0,g.parseSelector)(r)}catch(b){this.onError(b)}const{branches:a,info:l}=(0,g.walkAST)(n),{hasHasPseudoFunc:o,hasLogicalPseudoFunc:u,hasNthChildOfSelector:d}=l;let i=o||!!(u&&d),s=!1,t=0;f=[];for(const[...b]of a){const m=[];let p=b.shift();if(p&&p.type!==c.COMBINATOR){const w=new Set;for(;p;){if(p.type===c.COMBINATOR){const[N]=b;if(N.type===c.COMBINATOR)throw new DOMException(`Invalid selector ${r}`,c.SYNTAX_ERR);const _=p.name;/^[\s>]$/.test(_)?s=!0:i=!0,m.push({combo:p,leaves:(0,g.sortAST)(w)}),w.clear()}else if(p){let{name:N}=p;N&&typeof N=="string"&&(N=(0,g.unescapeSelector)(N),typeof N=="string"&&N!==p.name&&(p.name=N),/[|:]/.test(N)&&(p.namespace=!0)),w.add(p)}if(b.length)p=b.shift();else{m.push({combo:null,leaves:(0,g.sortAST)(w)}),w.clear();break}}}f.push({branch:m,collected:!1,dir:null,filtered:!1,find:!1}),e[t]=[],t++}let h;this.#f.has(this.#t)?h=this.#f.get(this.#t):h=new Map,h.set(`${r}`,{ast:f,descendant:s,invalidate:i}),this.#f.set(this.#t,h),this.#w=s,this.#o=i}return[f,e]}_createTreeWalker(r){let e;return this.#p.has(r)?e=this.#p.get(r):(e=this.#t.createTreeWalker(r,c.WALKER_FILTER),this.#p.set(r,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(r,e,f){const{a:n,b:a,reverse:l,selector:o}=r,{parentNode:u}=e,d=new Set;let i;if(o){if(this.#c.has(o))i=this.#c.get(o);else{const{branches:t}=(0,g.walkAST)(o);i=t,this.#o||this.#c.set(o,i)}const{branches:s}=(0,g.walkAST)(o);i=s}if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();const b=new Set;if(i)for(t=(0,k.traverseNode)(u,s),t=s.firstChild();t;){if((0,k.isVisible)(t)){let m;for(const p of i)if(m=this._matchLeaves(p,t,f),!m)break;m&&b.add(t)}t=s.nextSibling()}if(n===0){if(a>0&&a<=h){if(b.size){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(b.has(t)){if(m===a-1){d.add(t);break}m++}l?t=s.previousSibling():t=s.nextSibling()}}else if(!o){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0;for(;t;){if(m===a-1){d.add(t);break}l?t=s.previousSibling():t=s.nextSibling(),m++}}}}else{let m=a-1;if(n>0)for(;m<0;)m+=n;if(m>=0&&m<h){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let p=0,w=n>0?0:a-1;for(;t&&(t&&m>=0&&m<h);)b.size?b.has(t)&&(w===m&&(d.add(t),m+=n),n>0?w++:w--):p===m&&(o||d.add(t),m+=n),l?t=s.previousSibling():t=s.nextSibling(),p++}}if(l&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#s&&n+a===1)if(i){let s;for(const t of i)if(s=this._matchLeaves(t,e,f),s)break;s&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:f,b:n,reverse:a}=r,{localName:l,namespaceURI:o,parentNode:u,prefix:d}=e,i=new Set;if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();if(f===0){if(n>0&&n<=h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let b=0;for(;t;){const{localName:m,namespaceURI:p,prefix:w}=t;if(m===l&&w===d&&p===o){if(b===n-1){i.add(t);break}b++}a?t=s.previousSibling():t=s.nextSibling()}}}else{let b=n-1;if(f>0)for(;b<0;)b+=f;if(b>=0&&b<h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let m=f>0?0:n-1;for(;t;){const{localName:p,namespaceURI:w,prefix:N}=t;if(p===l&&N===d&&w===o){if(m===b&&(i.add(t),b+=f),b<0||b>=h)break;f>0?m++:m--}a?t=s.previousSibling():t=s.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&f+n===1&&i.add(e);return i}_matchAnPlusB(r,e,f,n){const{nth:{a,b:l,name:o},selector:u}=r,d=new Map;if(o?(o==="even"?(d.set("a",2),d.set("b",0)):o==="odd"&&(d.set("a",2),d.set("b",1)),f.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),f.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(f)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,f={}){let n;if(Array.isArray(r)&&r.length){const a=r.map(t=>t),[l]=a,{type:o}=l;let u;o===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[t]=a,{type:h}=t;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};f.dir=v;const s=this._matchCombinator(i,e,f);if(s.size)if(a.length){for(const t of s)if(n=this._matchHasPseudoFunc(a,t,f),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,f={}){const{astName:n="",branches:a=[],selector:l="",twigBranches:o=[]}=r;let u;if(n==="has")if(l.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,f),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(n);f.forgive=d;const i=o.length;let s;for(let t=0;t<i;t++){const h=o[t],b=h.length-1,{leaves:m}=h[b];if(s=this._matchLeaves(m,e,f),s&&b>0){let p=new Set([e]);for(let w=b-1;w>=0;w--){const N=h[w],_=[];f.dir=x;for(const y of p){const E=this._matchCombinator(N,y,f);E.size&&_.push(...E)}if(_.length)w===0?s=!0:p=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(u=e):s&&(u=e)}return u??null}_matchPseudoClassSelector(r,e,f={}){const{children:n,name:a}=r,{localName:l,parentNode:o}=e,{forgive:u,warn:d=this.#i}=f,i=new Set;if(c.REG_LOGICAL.test(a)){let s;if(this.#c.has(r))s=this.#c.get(r);else{const{branches:h}=(0,g.walkAST)(r),b=[],m=[];for(const[...p]of h){for(const y of p){const E=(0,g.generateCSS)(y);b.push(E)}const w=[],N=new Set;let _=p.shift();for(;_;)if(_.type===c.COMBINATOR?(w.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),p.length)_=p.shift();else{w.push({combo:null,leaves:[...N]}),N.clear();break}m.push(w)}s={astName:a,branches:h,twigBranches:m,selector:b.join(",")},this.#o||this.#c.set(r,s)}const t=this._matchLogicalPseudoFunc(s,e,f);t&&i.add(t)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[s]=n;return this._matchAnPlusB(s,e,a,f)}else switch(a){case"dir":case"lang":{const s=this.#h.matchSelector(r,e,f,!0);s&&i.add(s);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:s}]=n;if(s)if(e[s])i.add(e);else for(const t in e){const h=e[t];if(h instanceof this.#a.ElementInternals){h?.states?.has(s)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,c.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{O.test(l)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(O.test(l)&&e.hasAttribute("href")){const{href:s,origin:t,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),s);b.origin===t&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:s,type:t}=this.#n??{};/^(?:mouse|pointer)(?:down|over|up)$/.test(t)&&e.contains(s)&&i.add(e);break}case"active":{const{buttons:s,target:t,type:h}=this.#n??{};/(?:mouse|pointer)down/.test(h)&&s&c.BIT_01&&e.contains(t)&&i.add(e);break}case"target":{const{hash:s}=new URL(this.#t.URL);e.id&&s===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:s}=new URL(this.#t.URL);if(s){const t=s.replace(/^#/,"");let h=this.#t.getElementById(t);for(;h;){if(h===e){i.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&e.tabIndex>=0&&(0,k.isFocusable)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&e.tabIndex>=0){let s;if((0,k.isFocusVisible)(e))s=!0;else{const{target:t,type:h}=this.#n??{},{target:b,relatedTarget:m}=this.#k??{};(/^key(?:down|up)$/.test(h)&&e.contains(t)||m&&(0,k.isFocusVisible)(m)&&e.contains(b))&&(s=!0)}s&&(0,k.isFocusable)(e)&&i.add(e)}break}case"focus-within":{let s,t=this.#t.activeElement;if(t.tabIndex>=0)for(;t;){if(t===e){s=!0;break}t=t.parentNode}s&&(0,k.isFocusable)(e)&&i.add(e);break}case"open":{I.test(l)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{I.test(l)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")o.localName==="optgroup"&&(o.disabled||o.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s&&i.add(e)}}break}case"enabled":{if((M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(o.localName!=="optgroup"||!(o.disabled||o.hasAttribute("disabled")))&&i.add(e);else{let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s||i.add(e)}break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let s;if(e.placeholder?s=e.placeholder:e.hasAttribute("placeholder")&&(s=e.getAttribute("placeholder")),typeof s=="string"&&!/[\r\n]/.test(s)){let t;l==="textarea"?t=e:l==="input"&&(e.hasAttribute("type")?Q.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;t||(t=this.#t.documentElement);const h=t.getElementsByTagName("input"),b=h.length;let m;for(let p=0;p<b;p++){const w=h[p];if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(m=!!w.checked):w.hasAttribute("name")||(m=!!w.checked),m))break}m||i.add(e)}break}case"default":{if(l==="button"&&!(e.hasAttribute("type")&&D.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&U.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const t=this.#r;let h=(0,k.traverseNode)(s,t);for(h=t.firstChild();h&&s.contains(h);){const b=h.localName;let m;if(b==="button"?m=!(h.hasAttribute("type")&&D.test(h.getAttribute("type"))):b==="input"&&(m=h.hasAttribute("type")&&U.test(h.getAttribute("type"))),m){h===e&&i.add(e);break}h=t.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(T.test(l))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h&&i.add(e)}break}case"invalid":{if(T.test(l))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h||i.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&$.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":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&$.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const s=this.#t.createTreeWalker(e,c.SHOW_ALL);let t=s.firstChild(),h;for(;t&&(h=t.nodeType!==c.ELEMENT_NODE&&t.nodeType!==c.TEXT_NODE,!!h);)t=s.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(o&&e===o.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(o&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(o&&e===o.firstElementChild&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,k.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d)throw new DOMException(`Unsupported pseudo-element ::${a}`,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)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,c.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(r,e){const{children:f,name:n}=r;let a;if(Array.isArray(f)){const{branches:l}=(0,g.walkAST)(f[0]),[o]=l,[...u]=o,{host:d}=e;if(n==="host"){let i;for(const s of u){const{type:t}=s;if(t===c.COMBINATOR){const h=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(s,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,s;for(;i;){for(const t of u){const{type:h}=t;if(h===c.COMBINATOR){const b=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(s=this._matchSelector(t,i).has(i),!s)break}if(s)break;i=i.parentNode}s&&(a=e)}}else if(n==="host")a=e;else throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR);return a??null}_matchSelector(r,e,f){const{type:n}=r,a=new Set;if(r.name===c.EMPTY)return a;const l=(0,g.unescapeSelector)(r.name);if(typeof l=="string"&&l!==r.name&&(r.name=l),e.nodeType===c.ELEMENT_NODE)switch(n){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(l,f);break}case c.ID_SELECTOR:{e.id===l&&a.add(e);break}case c.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case c.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(r,e,f);default:{const o=this.#h.matchSelector(r,e,f,!0);o&&a.add(o)}}else if(this.#u&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&c.REG_LOGICAL.test(l))return this._matchPseudoClassSelector(r,e,f);if(P.test(l)){const o=this._matchShadowHostPseudoClass(r,e,f);o&&a.add(o)}}return a}_matchLeaves(r,e,f){let n,a;if(this.#o?a=this.#b.get(r):a=this.#N.get(r),a&&a.has(e)){const{matched:l}=a.get(e);n=l}if(typeof n!="boolean"){let l=!0;e.nodeType===c.ELEMENT_NODE&&/^(?:button|fieldset|form|input|select|textarea)$/.test(e.localName)&&(l=!1);for(const o of r){switch(o.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{/^(?:(?:any-)?link|defined|dir)$/.test(o.name)&&(l=!1);break}default:}if(n=this._matchSelector(o,e,f).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#o?this.#b.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e={}){const{compound:f,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(f)for(let o=0;o<l;o++){const u=r[o];this._matchLeaves(n,u,e)&&a.add(u)}else{const o=[].slice.call(r);return new Set(o)}return a}_findDescendantNodes(r,e,f){const[n,...a]=r,l=a.length>0,{type:o}=n,u=(0,g.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(o){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,f);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const s=this.#s.getElementById(u);s&&s!==e&&e.contains(s)&&(l?this._matchLeaves(a,s,f)&&d.add(s):d.add(s))}break}case c.CLASS_SELECTOR:{const s=e.getElementsByClassName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const s=e.getElementsByTagName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,f={}){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:o}=e,{dir:u}=f,d=new Set;if(u===v)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(e,i);for(s=i.nextSibling();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let s=(0,k.traverseNode)(e,i);for(s=i.firstChild();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling();break}case" ":default:{const{nodes:i,pending:s}=this._findDescendantNodes(a,e);if(i.size)return i;if(s){const t=this._createTreeWalker(e);let h=(0,k.traverseNode)(e,t);for(h=t.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,f)&&d.add(h),h=t.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(o,i);for(s=i.firstChild();s&&s!==e;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{o&&this._matchLeaves(a,o,f)&&d.add(o);break}case" ":default:{const i=[];let s=o;for(;s;)this._matchLeaves(a,s,f)&&i.push(s),s=s.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const{node:f}=e,n=this.#m;let a=(0,k.traverseNode)(f,n),l;if(a)for((a.nodeType!==c.ELEMENT_NODE||a===f&&a!==this.#s)&&(a=n.nextNode());a;){if(this._matchLeaves(r,a,{warn:this.#i})){l=a;break}a=n.nextNode()}return l??null}_matchSelf(r){const e=[],f=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return f&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e={}){const{complex:f}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||f){let o=this.#e.parentNode;for(;o&&(a=this._matchLeaves(r,o,{warn:this.#i}),a&&(n.push(o),l=!0),o.parentNode);)o=o.parentNode}return[n,l]}_findFirst(r){const e=[],f=this._findNode(r,{node:this.#e});let n=!1;return f&&(e.push(f),n=!0),[e,n]}_findFromHTMLCollection(r,e={}){const{complex:f,compound:n,filterLeaves:a,targetType:l}=e;let o=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let s=0;s<i;s++){const t=r[s];if(t!==this.#e&&(this.#e.contains(t)||t.contains(this.#e))){if(n){if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else if(o.push(t),u=!0,l===c.TARGET_FIRST)break}}else if(f)if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;else if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;return[o,u,d]}_findEntryNodes(r,e,f){const{leaves:n}=r,[a,...l]=n,o=l.length>0,{name:u,type:d}=a;let i=[],s=!1,t=!1,h=!1;switch(d){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,{warn:this.#i});break}case c.ID_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(o?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),t=!0):(i.push(b),t=!0))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}default:if(e!==c.TARGET_LINEAL&&P.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),t=!0)}}else e===c.TARGET_SELF?[i,t]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,t]=this._findLineal(n,{complex:f}):e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0}return{collected:s,compound:o,filtered:t,nodes:i,pending:h}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const f=new Set;let n=0;for(const{branch:a}of e){const l=a.length,o=l>1,u=a[0];let d,i;if(o){const{combo:p,leaves:[{name:w,type:N}]}=u,_=a[l-1],{leaves:[{name:y,type:E}]}=_;if(E===c.PS_ELEMENT_SELECTOR||E===c.ID_SELECTOR)d=x,i=_;else if(N===c.PS_ELEMENT_SELECTOR||N===c.ID_SELECTOR)d=v,i=u;else if(r===c.TARGET_ALL)if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(l===2){const{name:A}=p;/^[+~]$/.test(A)?(d=x,i=_):(d=v,i=u)}else d=v,i=u;else if(y==="*"&&E===c.TYPE_SELECTOR)d=v,i=u;else if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else{let A;for(const{combo:L,leaves:[W]}of a){const{name:G,type:H}=W;if(H===c.PS_CLASS_SELECTOR&&G==="dir"){A=!1;break}if(!A&&L){const{name:z}=L;/^[+~]$/.test(z)&&(A=!0)}}A?(d=v,i=u):(d=x,i=_)}}else d=x,i=u;const{collected:s,compound:t,filtered:h,nodes:b,pending:m}=this._findEntryNodes(i,r,o);b.length?(this.#l[n].find=!0,this.#d[n]=b):m&&f.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=s,this.#l[n].dir=d,this.#l[n].filtered=h||!t,n++}if(f.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,l=this.#m):(a=this.#s,l=this.#r);let o=(0,k.traverseNode)(a,l);for(;o;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?o===this.#e?u=!0:u=this.#e.contains(o):u=!0,u)for(const d of f){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,o,{warn:this.#i})){const t=d.get("index");this.#l[t].filtered=!0,this.#l[t].find=!0,this.#d[t].push(o)}}o!==l.currentNode&&(o=(0,k.traverseNode)(o,l)),o=l.nextNode()}}}else{let f=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:o,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[f].find=!0,this.#d[f]=d),this.#l[f].dir=x,this.#l[f].filtered=u||!o,f++}}return[this.#l,this.#d]}_getCombinedNodes(r,e,f){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:f,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,f){const{combo:n,index:a}=f,{combo:l,leaves:o}=r[a],u={combo:n,leaves:o},d=this._getCombinedNodes(u,e,v);let i;if(d.size)if(a===r.length-1){const[s]=(0,k.sortNodes)(d);i=s}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,f){const{index:n}=f,a=r[n],l=new Set([e]),o=this._getCombinedNodes(a,l,x);let u;if(o.size){if(n===0)u=e;else for(const d of o)if(this._matchNodePrev(r,d,{index:n-1}))return e}return u??null}find(r){(r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let o=0;o<n;o++){const{branch:u,collected:d,dir:i,find:s}=e[o],t=u.length;if(t&&s){const h=f[o],b=h.length,m=t-1;if(m===0)if((r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this.#e.nodeType===c.ELEMENT_NODE)for(let p=0;p<b;p++){const w=h[p];if(w!==this.#e&&this.#e.contains(w)&&(l.add(w),r!==c.TARGET_ALL))break}else if(r===c.TARGET_ALL)if(l.size){const p=[...l];l=new Set([...p,...h]),a=!0}else l=new Set(h);else{const[p]=h;l.add(p)}else if(r===c.TARGET_ALL)if(i===v){let{combo:p}=u[0];for(const w of h){let N=new Set([w]);for(let _=1;_<t;_++){const{combo:y,leaves:E}=u[_],A={combo:p,leaves:E};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===m)if(l.size){const L=[...l];l=new Set([...L,...N]),a=!0}else l=N;else p=y;else break}}}else for(const p of h){let w=new Set([p]);for(let N=m-1;N>=0;N--){const _=u[N];if(w=this._getCombinedNodes(_,w,i),w.size)N===0&&(l.add(p),t>1&&l.size>1&&(a=!0));else break}}else if(r===c.TARGET_FIRST&&i===v){const{combo:p}=u[0];let w;for(const N of h)if(w=this._matchNodeNext(u,new Set([N]),{combo:p,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:N}=u[0],[_]=h;let y=this._findNode(N,{node:_});for(;y;){if(w=this._matchNodeNext(u,new Set([y]),{combo:p,index:1}),w){l.add(w);break}y=this._findNode(N,{node:y})}}}else{let p;for(const w of h)if(p=this._matchNodePrev(u,w,{index:m-1}),p){l.add(w);break}if(!p&&!d&&r===c.TARGET_FIRST){const{leaves:w}=u[m],[N]=h;let _=this._findNode(w,{node:N});for(;_;){if(p=this._matchNodePrev(u,_,{index:m-1}),p){l.add(_);break}_=this._findNode(w,{node:_})}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,k.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,k.sortNodes)(l)))),l}}0&&(module.exports={Finder}); | ||
var R=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var j=(S,r)=>{for(var e in r)R(S,e,{get:r[e],enumerable:!0})},q=(S,r,e,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of V(r))!Y.call(S,n)&&n!==e&&R(S,n,{get:()=>r[n],enumerable:!(f=B(r,n))||f.enumerable});return S};var K=S=>q(R({},"__esModule",{value:!0}),S);var Z={};j(Z,{Finder:()=>J});module.exports=K(Z);var F=require("./matcher.js"),g=require("./parser.js"),k=require("./utility.js"),c=require("./constant.js");const E="next",x="prev",X="Tab",O=/^a(?:rea)?$/,M=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,T=/^(?:button|form|input|select|textarea)$/,$=/^(?:details|dialog)$/,I=/^host(?:-context)?$/,C=/^(?:checkbox|radio)$/,P=/^(?:date(?:time-local)?|month|number|range|time|week)$/,D=/^(?:button|reset)$/,U=/^(?:image|submit)$/,Q=/^(?:email|number|password|search|tel|text|url)$/;class J{#l;#c;#w;#t;#f;#n;#k;#o;#b;#h;#e;#d;#g;#m;#N;#s;#u;#_;#r;#p;#i;#a;constructor(r){this.#a=r,this.#h=new F.Matcher,this.#c=new WeakMap,this.#f=new WeakMap,this.#b=new WeakMap,this.#N=new WeakMap,this.#n=null,this.#k=null,this._registerEventListeners()}onError(r,e={}){if(!(e.noexcept??this.#g))if(r instanceof DOMException||r instanceof this.#a.DOMException)if(r.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw new this.#a.DOMException(r.message,r.name);else throw r.name in this.#a?new this.#a[r.name](r.message):r}setup(r,e,f={}){const{event:n,noexcept:a,warn:l}=f;return this.#g=!!a,this.#i=!!l,this.#e=e,[this.#t,this.#s,this.#r]=(0,k.resolveContent)(e),this.#u=(0,k.isInShadowTree)(e),[this.#l,this.#d]=this._correspond(r),this.#b=new WeakMap,this.#p=new WeakMap,this.#_=null,this._setEvent(n),e}_registerEventListeners(){const r={capture:!0,passive:!0},e=[],f=["mouseover","mousedown","mouseup","mouseout"];for(const a of f)e.push(this.#a.addEventListener(a,l=>{this.#n=l},r));const n=["keydown","keyup"];for(const a of n)e.push(this.#a.addEventListener(a,l=>{l.key===X&&(this.#n=l)},r));return e.push(this.#a.addEventListener("focusin",a=>{this.#k=a},r)),e}_setEvent(r){return(r instanceof this.#a.KeyboardEvent||r instanceof this.#a.MouseEvent)&&(this.#n=r),this.#n}_correspond(r){const e=[];this.#w=!1,this.#o=!1;let f;if(this.#f.has(this.#t)){const n=this.#f.get(this.#t);if(n&&n.has(`${r}`)){const a=n.get(`${r}`);f=a.ast,this.#w=a.descendant,this.#o=a.invalidate}}if(f){const n=f.length;for(let a=0;a<n;a++)f[a].collected=!1,f[a].dir=null,f[a].filtered=!1,f[a].find=!1,e[a]=[]}else{let n;try{n=(0,g.parseSelector)(r)}catch(b){this.onError(b)}const{branches:a,info:l}=(0,g.walkAST)(n),{hasHasPseudoFunc:o,hasLogicalPseudoFunc:u,hasNthChildOfSelector:d}=l;let i=o||!!(u&&d),s=!1,t=0;f=[];for(const[...b]of a){const p=[];let m=b.shift();if(m&&m.type!==c.COMBINATOR){const w=new Set;for(;m;){if(m.type===c.COMBINATOR){const[N]=b;if(N.type===c.COMBINATOR)throw new DOMException(`Invalid selector ${r}`,c.SYNTAX_ERR);const _=m.name;/^[\s>]$/.test(_)?s=!0:i=!0,p.push({combo:m,leaves:(0,g.sortAST)(w)}),w.clear()}else if(m){let{name:N}=m;N&&typeof N=="string"&&(N=(0,g.unescapeSelector)(N),typeof N=="string"&&N!==m.name&&(m.name=N),/[|:]/.test(N)&&(m.namespace=!0)),w.add(m)}if(b.length)m=b.shift();else{p.push({combo:null,leaves:(0,g.sortAST)(w)}),w.clear();break}}}f.push({branch:p,collected:!1,dir:null,filtered:!1,find:!1}),e[t]=[],t++}let h;this.#f.has(this.#t)?h=this.#f.get(this.#t):h=new Map,h.set(`${r}`,{ast:f,descendant:s,invalidate:i}),this.#f.set(this.#t,h),this.#w=s,this.#o=i}return[f,e]}_createTreeWalker(r){let e;return this.#p.has(r)?e=this.#p.get(r):(e=this.#t.createTreeWalker(r,c.WALKER_FILTER),this.#p.set(r,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#m}_collectNthChild(r,e,f){const{a:n,b:a,reverse:l,selector:o}=r,{parentNode:u}=e,d=new Set;let i;if(o){if(this.#c.has(o))i=this.#c.get(o);else{const{branches:t}=(0,g.walkAST)(o);i=t,this.#o||this.#c.set(o,i)}const{branches:s}=(0,g.walkAST)(o);i=s}if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();const b=new Set;if(i)for(t=(0,k.traverseNode)(u,s),t=s.firstChild();t;){if((0,k.isVisible)(t)){let p;for(const m of i)if(p=this._matchLeaves(m,t,f),!p)break;p&&b.add(t)}t=s.nextSibling()}if(n===0){if(a>0&&a<=h){if(b.size){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let p=0;for(;t;){if(b.has(t)){if(p===a-1){d.add(t);break}p++}l?t=s.previousSibling():t=s.nextSibling()}}else if(!o){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let p=0;for(;t;){if(p===a-1){d.add(t);break}l?t=s.previousSibling():t=s.nextSibling(),p++}}}}else{let p=a-1;if(n>0)for(;p<0;)p+=n;if(p>=0&&p<h){t=(0,k.traverseNode)(u,s),l?t=s.lastChild():t=s.firstChild();let m=0,w=n>0?0:a-1;for(;t&&(t&&p>=0&&p<h);)b.size?b.has(t)&&(w===p&&(d.add(t),p+=n),n>0?w++:w--):m===p&&(o||d.add(t),p+=n),l?t=s.previousSibling():t=s.nextSibling(),m++}}if(l&&d.size>1){const p=[...d];return new Set(p.reverse())}}else if(e===this.#s&&n+a===1)if(i){let s;for(const t of i)if(s=this._matchLeaves(t,e,f),s)break;s&&d.add(e)}else d.add(e);return d}_collectNthOfType(r,e){const{a:f,b:n,reverse:a}=r,{localName:l,namespaceURI:o,parentNode:u,prefix:d}=e,i=new Set;if(u){const s=this.#r;let t=(0,k.traverseNode)(u,s);t=s.firstChild();let h=0;for(;t;)h++,t=s.nextSibling();if(f===0){if(n>0&&n<=h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let b=0;for(;t;){const{localName:p,namespaceURI:m,prefix:w}=t;if(p===l&&w===d&&m===o){if(b===n-1){i.add(t);break}b++}a?t=s.previousSibling():t=s.nextSibling()}}}else{let b=n-1;if(f>0)for(;b<0;)b+=f;if(b>=0&&b<h){t=(0,k.traverseNode)(u,s),a?t=s.lastChild():t=s.firstChild();let p=f>0?0:n-1;for(;t;){const{localName:m,namespaceURI:w,prefix:N}=t;if(m===l&&N===d&&w===o){if(p===b&&(i.add(t),b+=f),b<0||b>=h)break;f>0?p++:p--}a?t=s.previousSibling():t=s.nextSibling()}}}if(a&&i.size>1){const b=[...i];return new Set(b.reverse())}}else e===this.#s&&f+n===1&&i.add(e);return i}_matchAnPlusB(r,e,f,n){const{nth:{a,b:l,name:o},selector:u}=r,d=new Map;if(o?(o==="even"?(d.set("a",2),d.set("b",0)):o==="odd"&&(d.set("a",2),d.set("b",1)),f.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?d.set("b",l*1):d.set("b",0),f.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,n)}else if(/^nth-(?:last-)?of-type$/.test(f)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(r,e,f={}){let n;if(Array.isArray(r)&&r.length){const a=r.map(t=>t),[l]=a,{type:o}=l;let u;o===c.COMBINATOR?u=a.shift():u={name:" ",type:c.COMBINATOR};const d=[];for(;a.length;){const[t]=a,{type:h}=t;if(h===c.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};f.dir=E;const s=this._matchCombinator(i,e,f);if(s.size)if(a.length){for(const t of s)if(n=this._matchHasPseudoFunc(a,t,f),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(r,e,f={}){const{astName:n,branches:a,twigBranches:l}=r,{isShadowRoot:o}=f;let u;if(n==="has"){let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,f),d)break;d&&(o?this.#_&&(u=e):u=e)}else{if(o){for(const t of a)if(t.length>1)return null}const d=/^(?:is|where)$/.test(n);f.forgive=d;const i=l.length;let s;for(let t=0;t<i;t++){const h=l[t],b=h.length-1,{leaves:p}=h[b];if(s=this._matchLeaves(p,e,f),s&&b>0){let m=new Set([e]);for(let w=b-1;w>=0;w--){const N=h[w],_=[];f.dir=x;for(const y of m){const v=this._matchCombinator(N,y,f);v.size&&_.push(...v)}if(_.length)w===0?s=!0:m=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(u=e):s&&(u=e)}return u??null}_matchPseudoClassSelector(r,e,f={}){const{children:n,name:a}=r,{localName:l,parentNode:o}=e,{forgive:u,warn:d=this.#i}=f,i=new Set;if(c.REG_LOGICAL.test(a)){let s;if(this.#c.has(r))s=this.#c.get(r);else{const{branches:h}=(0,g.walkAST)(r);if(a==="has"){for(const b of n){const p=(0,g.findAST)(b,m=>c.REG_LOGICAL.test(m.name)&&(0,g.findAST)(m,w=>w.name==="has")?m:null);if(p){if(/^(?:is|where)$/.test(p.name))return i;{const m=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${m}`,c.SYNTAX_ERR)}}}s={astName:a,branches:h}}else{const b=[];for(const[...p]of h){const m=[],w=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(m.push({combo:N,leaves:[...w]}),w.clear()):N&&w.add(N),p.length)N=p.shift();else{m.push({combo:null,leaves:[...w]}),w.clear();break}b.push(m)}s={astName:a,branches:h,twigBranches:b},this.#o||this.#c.set(r,s)}}const t=this._matchLogicalPseudoFunc(s,e,f);t&&i.add(t)}else if(Array.isArray(n))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[s]=n;return this._matchAnPlusB(s,e,a,f)}else switch(a){case"dir":case"lang":{const s=this.#h.matchSelector(r,e,f,!0);s&&i.add(s);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:s}]=n;if(s)if(e[s])i.add(e);else for(const t in e){const h=e[t];if(h instanceof this.#a.ElementInternals){h?.states?.has(s)&&i.add(e);break}}}break}case"current":case"nth-col":case"nth-last-col":{if(d)throw new DOMException(`Unsupported pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;case"contains":{if(d)throw new DOMException(`Unknown pseudo-class :${a}()`,c.NOT_SUPPORTED_ERR);break}default:if(!u)throw new DOMException(`Unknown pseudo-class :${a}()`,c.SYNTAX_ERR)}else switch(a){case"any-link":case"link":{O.test(l)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(O.test(l)&&e.hasAttribute("href")){const{href:s,origin:t,pathname:h}=new URL(this.#t.URL),b=new URL(e.getAttribute("href"),s);b.origin===t&&b.pathname===h&&i.add(e)}break}case"visited":break;case"hover":{const{target:s,type:t}=this.#n??{};/^(?:mouse|pointer)(?:down|over|up)$/.test(t)&&e.contains(s)&&i.add(e);break}case"active":{const{buttons:s,target:t,type:h}=this.#n??{};/(?:mouse|pointer)down/.test(h)&&s&c.BIT_01&&e.contains(t)&&i.add(e);break}case"target":{const{hash:s}=new URL(this.#t.URL);e.id&&s===`#${e.id}`&&this.#t.contains(e)&&i.add(e);break}case"target-within":{const{hash:s}=new URL(this.#t.URL);if(s){const t=s.replace(/^#/,"");let h=this.#t.getElementById(t);for(;h;){if(h===e){i.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&i.add(e):e===this.#t.documentElement&&i.add(e);break}case"focus":{e===this.#t.activeElement&&e.tabIndex>=0&&(0,k.isFocusable)(e)&&i.add(e);break}case"focus-visible":{if(e===this.#t.activeElement&&e.tabIndex>=0){let s;if((0,k.isFocusVisible)(e))s=!0;else{const{target:t,type:h}=this.#n??{},{target:b,relatedTarget:p}=this.#k??{};(/^key(?:down|up)$/.test(h)&&e.contains(t)||p&&(0,k.isFocusVisible)(p)&&e.contains(b))&&(s=!0)}s&&(0,k.isFocusable)(e)&&i.add(e)}break}case"focus-within":{let s,t=this.#t.activeElement;if(t.tabIndex>=0)for(;t;){if(t===e){s=!0;break}t=t.parentNode}s&&(0,k.isFocusable)(e)&&i.add(e);break}case"open":{$.test(l)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{$.test(l)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")o.localName==="optgroup"&&(o.disabled||o.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s&&i.add(e)}}break}case"enabled":{if((M.test(l)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(o.localName!=="optgroup"||!(o.disabled||o.hasAttribute("disabled")))&&i.add(e);else{let s,t=o;for(;t;)if(t.localName==="fieldset"&&(t.disabled||t.hasAttribute("disabled"))){const h=this.#r;let b=(0,k.traverseNode)(t,h);for(b=h.firstChild();b&&b.localName!=="legend";)b=h.nextSibling();b&&b.contains(e)||(s=!0);break}else{if(t.localName==="form")break;if(t.parentNode?.nodeType===c.ELEMENT_NODE){if(t.parentNode.localName==="form")break;t=t.parentNode}else break}s||i.add(e)}break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||c.REG_INPUT_TYPE.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,k.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let s;if(e.placeholder?s=e.placeholder:e.hasAttribute("placeholder")&&(s=e.getAttribute("placeholder")),typeof s=="string"&&!/[\r\n]/.test(s)){let t;l==="textarea"?t=e:l==="input"&&(e.hasAttribute("type")?Q.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))||e.selected&&l==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))i.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;t||(t=this.#t.documentElement);const h=t.getElementsByTagName("input"),b=h.length;let p;for(let m=0;m<b;m++){const w=h[m];if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(p=!!w.checked):w.hasAttribute("name")||(p=!!w.checked),p))break}p||i.add(e)}break}case"default":{if(l==="button"&&!(e.hasAttribute("type")&&D.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&U.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const t=this.#r;let h=(0,k.traverseNode)(s,t);for(h=t.firstChild();h&&s.contains(h);){const b=h.localName;let p;if(b==="button"?p=!(h.hasAttribute("type")&&D.test(h.getAttribute("type"))):b==="input"&&(p=h.hasAttribute("type")&&U.test(h.getAttribute("type"))),p){h===e&&i.add(e);break}h=t.nextNode()}}}else(l==="input"&&e.hasAttribute("type")&&C.test(e.getAttribute("type"))&&e.hasAttribute("checked")||l==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(T.test(l))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h&&i.add(e)}break}case"invalid":{if(T.test(l))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(l==="fieldset"){const s=this.#r;let t=(0,k.traverseNode)(e,s);t=s.firstChild();let h;if(!t)h=!0;else for(;t&&e.contains(t)&&!(T.test(t.localName)&&(t.checkValidity()?t.maxLength>=0?h=t.maxLength>=t.value.length:h=!0:h=!1,!h));)t=s.nextNode();h||i.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&P.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":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&P.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(l))s=e;else if(l==="input")if(e.hasAttribute("type")){const t=e.getAttribute("type");(t==="file"||C.test(t)||c.REG_INPUT_TYPE.test(t))&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#t.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const s=this.#t.createTreeWalker(e,c.SHOW_ALL);let t=s.firstChild(),h;for(;t&&(h=t.nodeType!==c.ELEMENT_NODE&&t.nodeType!==c.TEXT_NODE,!!h);)t=s.nextSibling();h&&i.add(e)}else i.add(e);break}case"first-child":{(o&&e===o.firstElementChild||e===this.#s)&&i.add(e);break}case"last-child":{(o&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"only-child":{(o&&e===o.firstElementChild&&e===o.lastElementChild||e===this.#s)&&i.add(e);break}case"first-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"last-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&i.add(s)}else e===this.#s&&i.add(e);break}case"only-of-type":{if(o){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t===e&&i.add(e)}}else e===this.#s&&i.add(e);break}case"defined":{e.hasAttribute("is")||l.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&i.add(e);break}case"popover-open":{e.popover&&(0,k.isVisible)(e)&&i.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d)throw new DOMException(`Unsupported pseudo-element ::${a}`,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)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(d)throw new DOMException(`Unsupported pseudo-class :${a}`,c.NOT_SUPPORTED_ERR)}else if(!u)throw new DOMException(`Unknown pseudo-class :${a}`,c.SYNTAX_ERR)}return i}_matchShadowHostPseudoClass(r,e){const{children:f,name:n}=r;let a;if(Array.isArray(f)){const{branches:l}=(0,g.walkAST)(f[0]),[o]=l,[...u]=o,{host:d}=e;if(n==="host"){let i;for(const s of u){const{type:t}=s;if(t===c.COMBINATOR){const h=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${h}`,c.SYNTAX_ERR)}if(i=this._matchSelector(s,d).has(d),!i)break}i&&(a=e)}else if(n==="host-context"){let i=d,s;for(;i;){for(const t of u){const{type:h}=t;if(h===c.COMBINATOR){const b=(0,g.generateCSS)(r);throw new DOMException(`Invalid selector ${b}`,c.SYNTAX_ERR)}if(s=this._matchSelector(t,i).has(i),!s)break}if(s)break;i=i.parentNode}s&&(a=e)}}else if(n==="host")a=e;else throw new DOMException(`Invalid selector :${n}`,c.SYNTAX_ERR);return a??null}_matchSelector(r,e,f={}){const{type:n}=r,a=new Set;if(r.name===c.EMPTY)return a;const l=(0,g.unescapeSelector)(r.name);if(typeof l=="string"&&l!==r.name&&(r.name=l),e.nodeType===c.ELEMENT_NODE)switch(n){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(l,f);break}case c.ID_SELECTOR:{e.id===l&&a.add(e);break}case c.CLASS_SELECTOR:{e.classList.contains(l)&&a.add(e);break}case c.PS_CLASS_SELECTOR:return this._matchPseudoClassSelector(r,e,f);default:{const o=this.#h.matchSelector(r,e,f,!0);o&&a.add(o)}}else if(this.#u&&n===c.PS_CLASS_SELECTOR&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(c.REG_LOGICAL.test(l))return f.isShadowRoot=!0,this._matchPseudoClassSelector(r,e,f);if(I.test(l)){const o=this._matchShadowHostPseudoClass(r,e,f);o&&(this.#_=!0,a.add(o))}}return a}_matchLeaves(r,e,f){let n,a;if(this.#o?a=this.#b.get(r):a=this.#N.get(r),a&&a.has(e)){const{matched:l}=a.get(e);n=l}if(typeof n!="boolean"){let l=!0;e.nodeType===c.ELEMENT_NODE&&/^(?:button|fieldset|form|input|select|textarea)$/.test(e.localName)&&(l=!1);for(const o of r){switch(o.type){case c.ATTR_SELECTOR:case c.ID_SELECTOR:{l=!1;break}case c.PS_CLASS_SELECTOR:{/^(?:(?:any-)?link|defined|dir)$/.test(o.name)&&(l=!1);break}default:}if(n=this._matchSelector(o,e,f).has(e),!n)break}l&&(a||(a=new WeakMap),a.set(e,{matched:n}),this.#o?this.#b.set(r,a):this.#N.set(r,a))}return!!n}_matchHTMLCollection(r,e={}){const{compound:f,filterLeaves:n}=e,a=new Set,l=r.length;if(l)if(f)for(let o=0;o<l;o++){const u=r[o];this._matchLeaves(n,u,e)&&a.add(u)}else{const o=[].slice.call(r);return new Set(o)}return a}_findDescendantNodes(r,e,f){const[n,...a]=r,l=a.length>0,{type:o}=n,u=(0,g.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(o){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,f);break}case c.ID_SELECTOR:{if(this.#s.nodeType===c.ELEMENT_NODE)i=!0;else{const s=this.#s.getElementById(u);s&&s!==e&&e.contains(s)&&(l?this._matchLeaves(a,s,f)&&d.add(s):d.add(s))}break}case c.CLASS_SELECTOR:{const s=e.getElementsByClassName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a});break}case c.TYPE_SELECTOR:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(u)){const s=e.getElementsByTagName(u);d=this._matchHTMLCollection(s,{compound:l,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(r,e,f={}){const{combo:n,leaves:a}=r,{name:l}=n,{parentNode:o}=e,{dir:u}=f,d=new Set;if(u===E)switch(l){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(e,i);for(s=i.nextSibling();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let s=(0,k.traverseNode)(e,i);for(s=i.firstChild();s;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling();break}case" ":default:{const{nodes:i,pending:s}=this._findDescendantNodes(a,e);if(i.size)return i;if(s){const t=this._createTreeWalker(e);let h=(0,k.traverseNode)(e,t);for(h=t.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,f)&&d.add(h),h=t.nextNode()}}}else switch(l){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,f)&&d.add(i);break}case"~":{if(o){const i=this._createTreeWalker(o);let s=(0,k.traverseNode)(o,i);for(s=i.firstChild();s&&s!==e;)this._matchLeaves(a,s,f)&&d.add(s),s=i.nextSibling()}break}case">":{o&&this._matchLeaves(a,o,f)&&d.add(o);break}case" ":default:{const i=[];let s=o;for(;s;)this._matchLeaves(a,s,f)&&i.push(s),s=s.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(r,e){const{node:f}=e,n=this.#m;let a=(0,k.traverseNode)(f,n),l;if(a)for((a.nodeType!==c.ELEMENT_NODE||a===f&&a!==this.#s)&&(a=n.nextNode());a;){if(this._matchLeaves(r,a,{warn:this.#i})){l=a;break}a=n.nextNode()}return l??null}_matchSelf(r){const e=[],f=this._matchLeaves(r,this.#e,{warn:this.#i});let n=!1;return f&&(e.push(this.#e),n=!0),[e,n]}_findLineal(r,e={}){const{complex:f}=e,n=[];let a=this._matchLeaves(r,this.#e,{warn:this.#i}),l=!1;if(a&&(n.push(this.#e),l=!0),!a||f){let o=this.#e.parentNode;for(;o&&(a=this._matchLeaves(r,o,{warn:this.#i}),a&&(n.push(o),l=!0),o.parentNode);)o=o.parentNode}return[n,l]}_findFirst(r){const e=[],f=this._findNode(r,{node:this.#e});let n=!1;return f&&(e.push(f),n=!0),[e,n]}_findFromHTMLCollection(r,e={}){const{complex:f,compound:n,filterLeaves:a,targetType:l}=e;let o=[],u=!1,d=!1;const i=r.length;if(i)if(this.#e.nodeType===c.ELEMENT_NODE)for(let s=0;s<i;s++){const t=r[s];if(t!==this.#e&&(this.#e.contains(t)||t.contains(this.#e))){if(n){if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else if(o.push(t),u=!0,l===c.TARGET_FIRST)break}}else if(f)if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;else if(n)for(let s=0;s<i;s++){const t=r[s];if(this._matchLeaves(a,t,{warn:this.#i})&&(o.push(t),u=!0,l===c.TARGET_FIRST))break}else o=[].slice.call(r),u=!0,d=!0;return[o,u,d]}_findEntryNodes(r,e,f){const{leaves:n}=r,[a,...l]=n,o=l.length>0,{name:u,type:d}=a;let i=[],s=!1,t=!1,h=!1;switch(d){case c.PS_ELEMENT_SELECTOR:{this.#h.matchPseudoElementSelector(u,{warn:this.#i});break}case c.ID_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(e===c.TARGET_FIRST&&this.#s.nodeType!==c.ELEMENT_NODE){const b=this.#s.getElementById(u);b&&(o?this._matchLeaves(l,b,{warn:this.#i})&&(i.push(b),t=!0):(i.push(b),t=!0))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.CLASS_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#s.nodeType===c.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}case c.TYPE_SELECTOR:{if(e===c.TARGET_SELF)[i,t]=this._matchSelf(n);else if(e===c.TARGET_LINEAL)[i,t]=this._findLineal(n,{complex:f});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#s.getElementsByTagName(u);b.length&&([i,t,s]=this._findFromHTMLCollection(b,{complex:f,compound:o,filterLeaves:l,targetType:e}))}else e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0;break}default:if(e!==c.TARGET_LINEAL&&I.test(u)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),t=!0)}}else e===c.TARGET_SELF?[i,t]=this._matchSelf(n):e===c.TARGET_LINEAL?[i,t]=this._findLineal(n,{complex:f}):e===c.TARGET_FIRST?[i,t]=this._findFirst(n):h=!0}return{collected:s,compound:o,filtered:t,nodes:i,pending:h}}_collectNodes(r){const e=this.#l.values();if(r===c.TARGET_ALL||r===c.TARGET_FIRST){const f=new Set;let n=0;for(const{branch:a}of e){const l=a.length,o=l>1,u=a[0];let d,i;if(o){const{combo:m,leaves:[{name:w,type:N}]}=u,_=a[l-1],{leaves:[{name:y,type:v}]}=_;if(v===c.PS_ELEMENT_SELECTOR||v===c.ID_SELECTOR)d=x,i=_;else if(N===c.PS_ELEMENT_SELECTOR||N===c.ID_SELECTOR)d=E,i=u;else if(r===c.TARGET_ALL)if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else if(y==="*"&&v===c.TYPE_SELECTOR)d=E,i=u;else if(l===2){const{name:A}=m;/^[+~]$/.test(A)?(d=x,i=_):(d=E,i=u)}else d=E,i=u;else if(y==="*"&&v===c.TYPE_SELECTOR)d=E,i=u;else if(w==="*"&&N===c.TYPE_SELECTOR)d=x,i=_;else{let A;for(const{combo:L,leaves:[W]}of a){const{name:G,type:H}=W;if(H===c.PS_CLASS_SELECTOR&&G==="dir"){A=!1;break}if(!A&&L){const{name:z}=L;/^[+~]$/.test(z)&&(A=!0)}}A?(d=E,i=u):(d=x,i=_)}}else d=x,i=u;const{collected:s,compound:t,filtered:h,nodes:b,pending:p}=this._findEntryNodes(i,r,o);b.length?(this.#l[n].find=!0,this.#d[n]=b):p&&f.add(new Map([["index",n],["twig",i]])),this.#l[n].collected=s,this.#l[n].dir=d,this.#l[n].filtered=h||!t,n++}if(f.size){let a,l;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,l=this.#m):(a=this.#s,l=this.#r);let o=(0,k.traverseNode)(a,l);for(;o;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?o===this.#e?u=!0:u=this.#e.contains(o):u=!0,u)for(const d of f){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,o,{warn:this.#i})){const t=d.get("index");this.#l[t].filtered=!0,this.#l[t].find=!0,this.#d[t].push(o)}}o!==l.currentNode&&(o=(0,k.traverseNode)(o,l)),o=l.nextNode()}}}else{let f=0;for(const{branch:n}of e){const a=n[n.length-1],l=n.length>1,{compound:o,filtered:u,nodes:d}=this._findEntryNodes(a,r,l);d.length&&(this.#l[f].find=!0,this.#d[f]=d),this.#l[f].dir=x,this.#l[f].filtered=u||!o,f++}}return[this.#l,this.#d]}_getCombinedNodes(r,e,f){const n=[];for(const a of e){const l=this._matchCombinator(r,a,{dir:f,warn:this.#i});l.size&&n.push(...l)}return n.length?new Set(n):new Set}_matchNodeNext(r,e,f){const{combo:n,index:a}=f,{combo:l,leaves:o}=r[a],u={combo:n,leaves:o},d=this._getCombinedNodes(u,e,E);let i;if(d.size)if(a===r.length-1){const[s]=(0,k.sortNodes)(d);i=s}else i=this._matchNodeNext(r,d,{combo:l,index:a+1});return i??null}_matchNodePrev(r,e,f){const{index:n}=f,a=r[n],l=new Set([e]),o=this._getCombinedNodes(a,l,x);let u;if(o.size){if(n===0)u=e;else for(const d of o)if(this._matchNodePrev(r,d,{index:n-1}))return e}return u??null}find(r){(r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(r),n=e.length;let a,l=new Set;for(let o=0;o<n;o++){const{branch:u,collected:d,dir:i,find:s}=e[o],t=u.length;if(t&&s){const h=f[o],b=h.length,p=t-1;if(p===0)if((r===c.TARGET_ALL||r===c.TARGET_FIRST)&&this.#e.nodeType===c.ELEMENT_NODE)for(let m=0;m<b;m++){const w=h[m];if(w!==this.#e&&this.#e.contains(w)&&(l.add(w),r!==c.TARGET_ALL))break}else if(r===c.TARGET_ALL)if(l.size){const m=[...l];l=new Set([...m,...h]),a=!0}else l=new Set(h);else{const[m]=h;l.add(m)}else if(r===c.TARGET_ALL)if(i===E){let{combo:m}=u[0];for(const w of h){let N=new Set([w]);for(let _=1;_<t;_++){const{combo:y,leaves:v}=u[_],A={combo:m,leaves:v};if(N=this._getCombinedNodes(A,N,i),N.size)if(_===p)if(l.size){const L=[...l];l=new Set([...L,...N]),a=!0}else l=N;else m=y;else break}}}else for(const m of h){let w=new Set([m]);for(let N=p-1;N>=0;N--){const _=u[N];if(w=this._getCombinedNodes(_,w,i),w.size)N===0&&(l.add(m),t>1&&l.size>1&&(a=!0));else break}}else if(r===c.TARGET_FIRST&&i===E){const{combo:m}=u[0];let w;for(const N of h)if(w=this._matchNodeNext(u,new Set([N]),{combo:m,index:1}),w){l.add(w);break}if(!w&&!d){const{leaves:N}=u[0],[_]=h;let y=this._findNode(N,{node:_});for(;y;){if(w=this._matchNodeNext(u,new Set([y]),{combo:m,index:1}),w){l.add(w);break}y=this._findNode(N,{node:y})}}}else{let m;for(const w of h)if(m=this._matchNodePrev(u,w,{index:p-1}),m){l.add(w);break}if(!m&&!d&&r===c.TARGET_FIRST){const{leaves:w}=u[p],[N]=h;let _=this._findNode(w,{node:N});for(;_;){if(m=this._matchNodePrev(u,_,{index:p-1}),m){l.add(_);break}_=this._findNode(w,{node:_})}}}}}return r===c.TARGET_FIRST?(l.delete(this.#e),l.size>1&&(l=new Set((0,k.sortNodes)(l)))):r===c.TARGET_ALL&&(l.delete(this.#e),a&&l.size>1&&(l=new Set((0,k.sortNodes)(l)))),l}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -1,3 +0,3 @@ | ||
var E=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var L=(s,e)=>{for(var r in e)E(s,r,{get:e[r],enumerable:!0})},b=(s,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!_.call(s,n)&&n!==r&&E(s,n,{get:()=>e[n],enumerable:!(o=w(e,n))||o.enumerable});return s};var I=s=>b(E({},"__esModule",{value:!0}),s);var P={};L(P,{generateCSS:()=>T.generate,parseAstName:()=>D,parseSelector:()=>g,preprocess:()=>O,sortAST:()=>F,unescapeSelector:()=>A,walkAST:()=>C});module.exports=I(P);var h=require("css-tree"),m=require("./utility.js"),t=require("./constant.js"),T=require("css-tree");const x=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/,$=/(:(is|where)\(\s*\))/,S=/^part|slotted$/,u="\uFFFD",A=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const e=s.split("\\"),r=e.length;for(let o=1;o<r;o++){let n=e[o];if(n===""&&o===r-1)n=u;else{const c=/^([\da-f]{1,6}\s?)/i.exec(n);if(c){const[,f]=c;let a;try{const i=parseInt("D800",t.HEX),p=parseInt("DFFF",t.HEX),d=parseInt(f,t.HEX);d===0||d>=i&&d<=p?a=u:a=String.fromCodePoint(d)}catch{a=u}let l="";n.length>f.length&&(l=n.substring(f.length)),n=`${a}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}e[o]=n}s=e.join("")}return s},O=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[e]=s;if(typeof e=="string"){let r=0;for(;r>=0&&(r=e.indexOf("#",r),!(r<0));){const o=e.substring(0,r+1);let n=e.substring(r+1);if(/^\d$/.test(n.substring(0,1)))throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR);const c=n.codePointAt(0);if(c===t.HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR)}else if(c>t.BIT_FFFF){const f=`\\${c.toString(t.HEX)} `;n.length===t.DUO?n=f:n=`${f}${n.substring(t.DUO)}`}e=`${o}${n}`,r++}e=e.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,u)}else if(e==null)e=(0,m.getType)(e).toLowerCase();else if(Array.isArray(e))e=e.join(",");else if(Object.prototype.hasOwnProperty.call(e,"toString"))e=e.toString();else throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR);return e},g=s=>{if(s=O(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,t.SYNTAX_ERR);let e;try{const r=(0,h.parse)(s,{context:"selectorList",parseCustomProperty:!0});e=(0,h.toPlainObject)(r)}catch(r){const{message:o}=r;if(o==="Identifier is expected"&&x.test(s)){const[,n,c]=x.exec(s),f=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let a=n.replace(c,f);a===":lang()"&&(a=`:lang(${t.EMPTY})`),e=g(s.replace(n,a))}else if(/^(?:Identifier|Selector) is expected$/.test(o)&&$.test(s)){const[,n,c]=$.exec(s);e=g(s.replace(n,`:${c}(${t.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(o)&&!s.endsWith("]")){const n=s.lastIndexOf("["),c=s.substring(n);c.includes('"')?c.match(/"/g).length%2?e=g(`${s}"]`):e=g(`${s}]`):e=g(`${s}]`)}else if(o==='")" is expected'&&!s.endsWith(")"))e=g(`${s})`);else throw new DOMException(o,t.SYNTAX_ERR)}return e},C=(s={})=>{const e=new Set,r=new Map;return(0,h.walk)(s,{enter:n=>{switch(n.type){case t.SELECTOR:{e.add(n.children);break}case t.PS_CLASS_SELECTOR:{t.REG_LOGICAL.test(n.name)&&(r.set("hasNestedSelector",!0),r.set("hasLogicalPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0));break}case t.PS_ELEMENT_SELECTOR:{S.test(n.name)&&r.set("hasNestedSelector",!0);break}case t.NTH:{n.selector&&(r.set("hasNestedSelector",!0),r.set("hasNthChildOfSelector",!0));break}default:}}}),r.get("hasNestedSelector")&&(0,h.findAll)(s,(n,c,f)=>{if(f){if(n.type===t.PS_CLASS_SELECTOR&&t.REG_LOGICAL.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===t.PS_CLASS_SELECTOR&&t.REG_LOGICAL.test(i)});for(const{children:l}of a)for(const{children:i}of l)for(const{children:p}of i)e.has(p)&&e.delete(p)}else if(n.type===t.PS_ELEMENT_SELECTOR&&S.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===t.PS_ELEMENT_SELECTOR&&S.test(i)});for(const{children:l}of a)for(const{children:i}of l)e.has(i)&&e.delete(i)}else if(n.type===t.NTH&&n.selector){const a=f.filter(l=>{const{selector:i,type:p}=l;return p===t.NTH&&i});for(const{selector:l}of a){const{children:i}=l;for(const{children:p}of i)e.has(p)&&e.delete(p)}}}}),{branches:[...e],info:Object.fromEntries(r)}},F=s=>{const e=[...s];if(e.length>1){const r=new Map([[t.PS_ELEMENT_SELECTOR,t.BIT_01],[t.ID_SELECTOR,t.BIT_02],[t.CLASS_SELECTOR,t.BIT_04],[t.TYPE_SELECTOR,t.BIT_08],[t.ATTR_SELECTOR,t.BIT_16],[t.PS_CLASS_SELECTOR,t.BIT_32]]);e.sort((o,n)=>{const{type:c}=o,{type:f}=n,a=r.get(c),l=r.get(f);let i;return a===l?i=0:a>l?i=1:i=-1,i})}return e},D=s=>{let e,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[e,r]=s.split("|"):(e="*",r=s);else throw new DOMException(`Invalid selector ${s}`,t.SYNTAX_ERR);return{prefix:e,localName:r}};0&&(module.exports={generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
var S=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var L=(s,e)=>{for(var r in e)S(s,r,{get:e[r],enumerable:!0})},b=(s,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!_.call(s,n)&&n!==r&&S(s,n,{get:()=>e[n],enumerable:!(o=w(e,n))||o.enumerable});return s};var A=s=>b(S({},"__esModule",{value:!0}),s);var P={};L(P,{findAST:()=>E.find,generateCSS:()=>E.generate,parseAstName:()=>D,parseSelector:()=>g,preprocess:()=>T,sortAST:()=>F,unescapeSelector:()=>I,walkAST:()=>C});module.exports=A(P);var d=require("css-tree"),O=require("./utility.js"),t=require("./constant.js"),E=require("css-tree");const $=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/,m=/(:(is|where)\(\s*\))/,x=/^part|slotted$/,u="\uFFFD",I=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const e=s.split("\\"),r=e.length;for(let o=1;o<r;o++){let n=e[o];if(n===""&&o===r-1)n=u;else{const c=/^([\da-f]{1,6}\s?)/i.exec(n);if(c){const[,f]=c;let a;try{const i=parseInt("D800",t.HEX),p=parseInt("DFFF",t.HEX),h=parseInt(f,t.HEX);h===0||h>=i&&h<=p?a=u:a=String.fromCodePoint(h)}catch{a=u}let l="";n.length>f.length&&(l=n.substring(f.length)),n=`${a}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}e[o]=n}s=e.join("")}return s},T=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[e]=s;if(typeof e=="string"){let r=0;for(;r>=0&&(r=e.indexOf("#",r),!(r<0));){const o=e.substring(0,r+1);let n=e.substring(r+1);if(/^\d$/.test(n.substring(0,1)))throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR);const c=n.codePointAt(0);if(c===t.HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR)}else if(c>t.BIT_FFFF){const f=`\\${c.toString(t.HEX)} `;n.length===t.DUO?n=f:n=`${f}${n.substring(t.DUO)}`}e=`${o}${n}`,r++}e=e.replace(/\f|\r\n?/g,` | ||
`).replace(/[\0\uD800-\uDFFF]|\\$/g,u)}else if(e==null)e=(0,O.getType)(e).toLowerCase();else if(Array.isArray(e))e=e.join(",");else if(Object.prototype.hasOwnProperty.call(e,"toString"))e=e.toString();else throw new DOMException(`Invalid selector ${e}`,t.SYNTAX_ERR);return e},g=s=>{if(s=T(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,t.SYNTAX_ERR);let e;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});e=(0,d.toPlainObject)(r)}catch(r){const{message:o}=r;if(o==="Identifier is expected"&&$.test(s)){const[,n,c]=$.exec(s),f=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let a=n.replace(c,f);a===":lang()"&&(a=`:lang(${t.EMPTY})`),e=g(s.replace(n,a))}else if(/^(?:Identifier|Selector) is expected$/.test(o)&&m.test(s)){const[,n,c]=m.exec(s);e=g(s.replace(n,`:${c}(${t.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(o)&&!s.endsWith("]")){const n=s.lastIndexOf("["),c=s.substring(n);c.includes('"')?c.match(/"/g).length%2?e=g(`${s}"]`):e=g(`${s}]`):e=g(`${s}]`)}else if(o==='")" is expected'&&!s.endsWith(")"))e=g(`${s})`);else throw new DOMException(o,t.SYNTAX_ERR)}return e},C=(s={})=>{const e=new Set,r=new Map;return(0,d.walk)(s,{enter:n=>{switch(n.type){case t.SELECTOR:{e.add(n.children);break}case t.PS_CLASS_SELECTOR:{t.REG_LOGICAL.test(n.name)&&(r.set("hasNestedSelector",!0),r.set("hasLogicalPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0));break}case t.PS_ELEMENT_SELECTOR:{x.test(n.name)&&r.set("hasNestedSelector",!0);break}case t.NTH:{n.selector&&(r.set("hasNestedSelector",!0),r.set("hasNthChildOfSelector",!0));break}default:}}}),r.get("hasNestedSelector")&&(0,d.findAll)(s,(n,c,f)=>{if(f){if(n.type===t.PS_CLASS_SELECTOR&&t.REG_LOGICAL.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===t.PS_CLASS_SELECTOR&&t.REG_LOGICAL.test(i)});for(const{children:l}of a)for(const{children:i}of l)for(const{children:p}of i)e.has(p)&&e.delete(p)}else if(n.type===t.PS_ELEMENT_SELECTOR&&x.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===t.PS_ELEMENT_SELECTOR&&x.test(i)});for(const{children:l}of a)for(const{children:i}of l)e.has(i)&&e.delete(i)}else if(n.type===t.NTH&&n.selector){const a=f.filter(l=>{const{selector:i,type:p}=l;return p===t.NTH&&i});for(const{selector:l}of a){const{children:i}=l;for(const{children:p}of i)e.has(p)&&e.delete(p)}}}}),{branches:[...e],info:Object.fromEntries(r)}},F=s=>{const e=[...s];if(e.length>1){const r=new Map([[t.PS_ELEMENT_SELECTOR,t.BIT_01],[t.ID_SELECTOR,t.BIT_02],[t.CLASS_SELECTOR,t.BIT_04],[t.TYPE_SELECTOR,t.BIT_08],[t.ATTR_SELECTOR,t.BIT_16],[t.PS_CLASS_SELECTOR,t.BIT_32]]);e.sort((o,n)=>{const{type:c}=o,{type:f}=n,a=r.get(c),l=r.get(f);let i;return a===l?i=0:a>l?i=1:i=-1,i})}return e},D=s=>{let e,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[e,r]=s.split("|"):(e="*",r=s);else throw new DOMException(`Invalid selector ${s}`,t.SYNTAX_ERR);return{prefix:e,localName:r}};0&&(module.exports={findAST,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
//# sourceMappingURL=parser.js.map |
@@ -44,3 +44,3 @@ { | ||
"eslint-plugin-unicorn": "^55.0.0", | ||
"happy-dom": "^15.3.1", | ||
"happy-dom": "^15.7.0", | ||
"jsdom": "^25.0.0", | ||
@@ -53,2 +53,5 @@ "linkedom": "^0.18.4", | ||
}, | ||
"overrides": { | ||
"jsdom": "^25.0.0" | ||
}, | ||
"scripts": { | ||
@@ -65,3 +68,3 @@ "bench": "node benchmark/bench.js", | ||
}, | ||
"version": "5.3.3" | ||
"version": "5.3.4" | ||
} |
@@ -230,4 +230,3 @@ /** | ||
const { name, type } = i; | ||
const res = | ||
type === PS_CLASS_SELECTOR && REG_LOGICAL.test(name); | ||
const res = type === PS_CLASS_SELECTOR && REG_LOGICAL.test(name); | ||
return res; | ||
@@ -347,2 +346,2 @@ }); | ||
/* export */ | ||
export { generate as generateCSS } from 'css-tree'; | ||
export { find as findAST, generate as generateCSS } from 'css-tree'; |
@@ -7,2 +7,2 @@ export function unescapeSelector(selector?: string): string | null; | ||
export function parseAstName(selector: string): object; | ||
export { generate as generateCSS } from "css-tree"; | ||
export { find as findAST, 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
442954
4999