@asamuzakjp/dom-selector
Advanced tools
Comparing version 4.6.4 to 4.6.5
@@ -1,2 +0,2 @@ | ||
var z=Object.create;var M=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var q=(g,l)=>{for(var e in l)M(g,e,{get:l[e],enumerable:!0})},P=(g,l,e,h)=>{if(l&&typeof l=="object"||typeof l=="function")for(let c of W(l))!j.call(g,c)&&c!==e&&M(g,c,{get:()=>l[c],enumerable:!(h=H(l,c))||h.enumerable});return g};var Y=(g,l,e)=>(e=g!=null?z(B(g)):{},P(l||!g||!g.__esModule?M(e,"default",{value:g,enumerable:!0}):e,g)),V=g=>P(M({},"__esModule",{value:!0}),g);var K={};q(K,{Finder:()=>X});module.exports=V(K);var I=Y(require("@asamuzakjp/nwsapi"),1),N=require("./dom-util.js"),O=require("./matcher.js"),y=require("./parser.js"),n=require("./constant.js");const x="next",S="prev",L="all",E="first",C="lineal",R="self";class X{#a;#c;#s;#o;#w;#n;#b;#e;#f;#k;#h;#m;#N;#t;#d;#u;#r;#p;#i;#l;constructor(l,e){this.#l=l,this.#n=e??l.document,this.#c=new WeakMap,this.#o=new WeakMap,this.#N=new WeakMap,this.#h=this._initNwsapi(l,e)}_onError(l){if(!this.#k)if(l instanceof DOMException||l instanceof this.#l.DOMException)if(l.name===n.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw new this.#l.DOMException(l.message,l.name);else throw l}_setup(l,e,h={}){const{event:c,noexcept:a,warn:o}=h;return this.#k=!!a,this.#i=!!o,this.#b=this._setEvent(c),this.#e=e,[this.#s,this.#t,this.#r]=(0,N.resolveContent)(e),this.#d=(0,N.isInShadowTree)(e),[this.#a,this.#f]=this._correspond(l),this.#p=new WeakMap,e}_initNwsapi(){const l=(0,I.default)({DOMException:this.#l.DOMException,document:this.#n});return l.configure({LOGERRORS:!1}),l}_setEvent(l){return l instanceof this.#l.KeyboardEvent||l instanceof this.#l.MouseEvent?l:null}_correspond(l){const e=[];this.#w=!1;let h;if(this.#o.has(this.#s)){const c=this.#o.get(this.#s);if(c&&c.has(`${l}`)){const a=c.get(`${l}`);this.#w=a.descendant,h=a.ast}}if(h){const c=h.length;for(let a=0;a<c;a++)h[a].collected=!1,h[a].dir=null,h[a].filtered=!1,h[a].find=!1,e[a]=[]}else{let c;try{c=(0,y.parseSelector)(l)}catch(f){this._onError(f)}const{branches:a,info:{hasDefinedPseudo:o,hasHasPseudoFunc:r,hasNthChildOfSelector:u,hasPseudoFunc:d}}=(0,y.walkAST)(c);let i;o||r||u&&d?i=!1:i=!0;let t=!1,s=0;h=[];for(const[...f]of a){const m=[];let b=f.shift();if(b&&b.type!==n.COMBINATOR){const p=new Set;for(;b;){if(b.type===n.COMBINATOR){const[w]=f;if(w.type===n.COMBINATOR){const _=`Invalid selector ${l}`;throw new DOMException(_,n.SYNTAX_ERR)}const k=b.name;/^[\s>]$/.test(k)&&(t=!0),m.push({combo:b,leaves:(0,y.sortAST)(p)}),p.clear()}else if(b){let{name:w}=b;w&&typeof w=="string"&&(w=(0,y.unescapeSelector)(w),typeof w=="string"&&w!==b.name&&(b.name=w),/[|:]/.test(w)&&(b.namespace=!0)),p.add(b)}if(f.length)b=f.shift();else{m.push({combo:null,leaves:(0,y.sortAST)(p)}),p.clear();break}}}h.push({branch:m,collected:!1,dir:null,filtered:!1,find:!1}),e[s]=[],s++}if(i){let f;this.#o.has(this.#s)?f=this.#o.get(this.#s):f=new Map,f.set(`${l}`,{ast:h,descendant:t}),this.#o.set(this.#s,f)}this.#w=t}return[h,e]}_createTreeWalker(l){let e;return this.#p.has(l)?e=this.#p.get(l):(e=this.#n.createTreeWalker(l,n.WALKER_FILTER),this.#p.set(l,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#u=!1,this.#m}_collectNthChild(l,e,h){const{a:c,b:a,reverse:o,selector:r}=l,{parentNode:u}=e,d=new Set;let i;if(r)if(this.#c.has(r))i=this.#c.get(r);else{const{branches:t}=(0,y.walkAST)(r);i=t,this.#c.set(r,i)}if(u){const t=this.#r;let s=(0,N.traverseNode)(u,t);s=t.firstChild();let f=0;for(;s;)f++,s=t.nextSibling();const m=new Set;if(i)for(s=(0,N.traverseNode)(u,t),s=t.firstChild();s;){const{display:b,visibility:p}=this.#l.getComputedStyle(s);if(b!=="none"&&p!=="hidden"){let w;for(const k of i)if(w=this._matchLeaves(k,s,h),!w)break;w&&m.add(s)}s=t.nextSibling()}if(c===0){if(a>0&&a<=f){if(m.size){s=(0,N.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(m.has(s)){if(b===a-1){d.add(s);break}b++}o?s=t.previousSibling():s=t.nextSibling()}}else if(!r){s=(0,N.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let b=0;for(;s;){if(b===a-1){d.add(s);break}o?s=t.previousSibling():s=t.nextSibling(),b++}}}}else{let b=a-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b<f){s=(0,N.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let p=0,w=c>0?0:a-1;for(;s&&(s&&b>=0&&b<f);)m.size?m.has(s)&&(w===b&&(d.add(s),b+=c),c>0?w++:w--):p===b&&(r||d.add(s),b+=c),o?s=t.previousSibling():s=t.nextSibling(),p++}}if(o&&d.size>1){const b=[...d];return new Set(b.reverse())}}else if(e===this.#t&&c+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(l,e){const{a:h,b:c,reverse:a}=l,{localName:o,parentNode:r,prefix:u}=e,d=new Set;if(r){const i=this.#r;let t=(0,N.traverseNode)(r,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(c>0&&c<=s){t=(0,N.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let f=0;for(;t;){const{localName:m,prefix:b}=t;if(m===o&&b===u){if(f===c-1){d.add(t);break}f++}a?t=i.previousSibling():t=i.nextSibling()}}}else{let f=c-1;if(h>0)for(;f<0;)f+=h;if(f>=0&&f<s){t=(0,N.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let m=h>0?0:c-1;for(;t;){const{localName:b,prefix:p}=t;if(b===o&&p===u){if(m===f&&(d.add(t),f+=h),f<0||f>=s)break;h>0?m++:m--}a?t=i.previousSibling():t=i.nextSibling()}}}if(a&&d.size>1){const f=[...d];return new Set(f.reverse())}}else e===this.#t&&h+c===1&&d.add(e);return d}_matchAnPlusB(l,e,h,c){const{nth:{a,b:o,name:r},selector:u}=l,d=new Map;if(r?(r==="even"?(d.set("a",2),d.set("b",0)):r==="odd"&&(d.set("a",2),d.set("b",1)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?d.set("b",o*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,c)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(l,e,h={}){let c;if(Array.isArray(l)&&l.length){const a=l.map(s=>s),[o]=a,{type:r}=o;let u;r===n.COMBINATOR?u=a.shift():u={name:" ",type:n.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:f}=s;if(f===n.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};h.dir=x;const t=this._matchCombinator(i,e,h);if(t.size)if(a.length){for(const s of t)if(c=this._matchHasPseudoFunc(a,s,h),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(l,e,h={}){const{astName:c="",branches:a=[],selector:o="",twigBranches:r=[]}=l;let u;if(c==="has")if(o.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(c);h.forgive=d;const i=r.length;let t;for(let s=0;s<i;s++){const f=r[s],m=f.length-1,{leaves:b}=f[m];if(t=this._matchLeaves(b,e,h),t&&m>0){let p=new Set([e]);for(let w=m-1;w>=0;w--){const k=f[w],_=[];h.dir=S;for(const A of p){const v=this._matchCombinator(k,A,h);v.size&&_.push(...v)}if(_.length)w===0?t=!0:p=new Set(_);else{t=!1;break}}}if(t)break}c==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(l,e,h={}){const{children:c,name:a}=l,{localName:o,parentNode:r}=e,{forgive:u,warn:d=this.#i}=h,i=new Set;if(n.REG_LOGICAL_PSEUDO.test(a)){let t;if(this.#c.has(l))t=this.#c.get(l);else{const{branches:f}=(0,y.walkAST)(l),m=[],b=[];for(const[...p]of f){for(const A of p){const v=(0,y.generateCSS)(A);m.push(v)}const w=[],k=new Set;let _=p.shift();for(;_;)if(_.type===n.COMBINATOR?(w.push({combo:_,leaves:[...k]}),k.clear()):_&&k.add(_),p.length)_=p.shift();else{w.push({combo:null,leaves:[...k]}),k.clear();break}b.push(w)}t={astName:a,branches:f,twigBranches:b,selector:m.join(",")},this.#c.set(l,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(c))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=c;return this._matchAnPlusB(t,e,a,h)}else switch(a){case"dir":case"lang":{const t=O.matcher.matchSelector(l,e);t&&i.add(t);break}case"state":{if((0,N.isCustomElement)(e)){const[{value:t}]=c;t&&e[t]&&i.add(e)}break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${a}()`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}break}default:if(!u){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,n.SYNTAX_ERR)}}else switch(a){case"any-link":case"link":{n.REG_ANCHOR.test(o)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(n.REG_ANCHOR.test(o)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:f}=new URL(this.#s.URL),m=new URL(e.getAttribute("href"),t);m.origin===s&&m.pathname===f&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#b??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:f}=this.#b??{};(f==="mousedown"||f==="pointerdown")&&t&n.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const s=t.replace(/^#/,"");let f=this.#s.getElementById(s);for(;f;){if(f===e){i.add(e);break}f=f.parentNode}}break}case"scope":{this.#e.nodeType===n.ELEMENT_NODE?!this.#d&&e===this.#e&&i.add(e):e===this.#s.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#b??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(a==="focus"||s==="keydown"&&e.contains(t))){let f=e,m=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#l.getComputedStyle(f);if(m=!(b==="none"||p==="hidden"),!m)break}if(f.parentNode&&f.parentNode.nodeType===n.ELEMENT_NODE)f=f.parentNode;else break}m&&i.add(e)}break}case"focus-within":{let t,s=this.#s.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}if(t){let f=e,m=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#l.getComputedStyle(f);if(m=!(b==="none"||p==="hidden"),!m)break}if(f.parentNode&&f.parentNode.nodeType===n.ELEMENT_NODE)f=f.parentNode;else break}m&&i.add(e)}break}case"open":{n.REG_INTERACT.test(o)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{n.REG_INTERACT.test(o)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(n.REG_FORM_CTRL.test(o)||(0,N.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")r.localName==="optgroup"&&(r.disabled||r.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let t,s=r;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const f=this.#r;let m=(0,N.traverseNode)(s,f);for(m=f.firstChild();m&&m.localName!=="legend";)m=f.nextSibling();m&&m.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===n.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t&&i.add(e)}}break}case"enabled":{if((n.REG_FORM_CTRL.test(o)||(0,N.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled"))){if(e.localName==="option")(r.localName!=="optgroup"||!(r.disabled||r.hasAttribute("disabled")))&&i.add(e);else if(e.localName!=="optgroup"){let t,s=r;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const f=this.#r;let m=(0,N.traverseNode)(s,f);for(m=f.firstChild();m&&m.localName!=="legend";)m=f.nextSibling();m&&m.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===n.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t||i.add(e)}}break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||n.REG_TYPE_DATE.test(e.type)||n.REG_TYPE_TEXT.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,N.isContentEditable)(e)||i.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||n.REG_TYPE_DATE.test(e.type)||n.REG_TYPE_TEXT.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}default:(0,N.isContentEditable)(e)&&i.add(e)}break}case"placeholder-shown":{let t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;o==="textarea"?s=e:o==="input"&&(e.hasAttribute("type")?n.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&n.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&o==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))i.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#s.documentElement);const f=s.getElementsByTagName("input"),m=f.length;let b;for(let p=0;p<m;p++){const w=f[p];if(w.getAttribute("type")==="radio"&&(t?w.getAttribute("name")===t&&(b=!!w.checked):w.hasAttribute("name")||(b=!!w.checked),b))break}b||i.add(e)}break}case"default":{if(o==="button"&&!(e.hasAttribute("type")&&n.REG_TYPE_RESET.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&n.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#r;let f=(0,N.traverseNode)(t,s);for(f=s.firstChild();f&&t.contains(f);){const m=f.localName;let b;if(m==="button"?b=!(f.hasAttribute("type")&&n.REG_TYPE_RESET.test(f.getAttribute("type"))):m==="input"&&(b=f.hasAttribute("type")&&n.REG_TYPE_SUBMIT.test(f.getAttribute("type"))),b){f===e&&i.add(e);break}f=s.nextNode()}}}else(o==="input"&&e.hasAttribute("type")&&n.REG_TYPE_CHECK.test(e.getAttribute("type"))&&e.hasAttribute("checked")||o==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(n.REG_FORM_VALID.test(o))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(o==="fieldset"){const t=this.#r;let s=(0,N.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(n.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f&&i.add(e)}break}case"invalid":{if(n.REG_FORM_VALID.test(o))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(o==="fieldset"){const t=this.#r;let s=(0,N.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(n.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f||i.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&n.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&n.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||n.REG_TYPE_CHECK.test(s)||n.REG_TYPE_DATE.test(s)||n.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||n.REG_TYPE_CHECK.test(s)||n.REG_TYPE_DATE.test(s)||n.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#s.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#n.createTreeWalker(e,n.SHOW_ALL);let s=t.firstChild(),f;for(;s&&(f=s.nodeType!==n.ELEMENT_NODE&&s.nodeType!==n.TEXT_NODE,!!f);)s=t.nextSibling();f&&i.add(e)}else i.add(e);break}case"first-child":{(r&&e===r.firstElementChild||e===this.#t)&&i.add(e);break}case"last-child":{(r&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"only-child":{(r&&e===r.firstElementChild&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"first-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"last-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"only-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#t&&i.add(e);break}case"defined":{e.hasAttribute("is")||o.includes("-")?(0,N.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#l.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${a}`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}break}default:if(a.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${a}`;throw new DOMException(t,n.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(l,e){const{children:h,name:c}=l;let a;if(Array.isArray(h)){const{branches:o}=(0,y.walkAST)(h[0]),[r]=o,[...u]=r,{host:d}=e;if(c==="host"){let i;for(const t of u){const{type:s}=t;if(s===n.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(m,n.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(a=e)}else if(c==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:f}=s;if(f===n.COMBINATOR){const b=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(b,n.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(a=e)}}else if(c==="host")a=e;else{const o=`Invalid selector :${c}`;throw new DOMException(o,n.SYNTAX_ERR)}return a??null}_matchSelector(l,e,h){const{type:c}=l,a=new Set;if(l.name===n.EMPTY)return a;const o=(0,y.unescapeSelector)(l.name);if(typeof o=="string"&&o!==l.name&&(l.name=o),e.nodeType===n.ELEMENT_NODE)switch(c){case n.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(o,h);break}case n.SELECTOR_ID:{e.id===o&&a.add(e);break}case n.SELECTOR_CLASS:{e.classList.contains(o)&&a.add(e);break}case n.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(l,e,h);default:{const r=O.matcher.matchSelector(l,e,h);r&&a.add(r)}}else if(this.#d&&c===n.SELECTOR_PSEUDO_CLASS&&e.nodeType===n.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&n.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(l,e,h);if(n.REG_SHADOW_HOST.test(o)){const r=this._matchShadowHostPseudoClass(l,e,h);r&&a.add(r)}}return a}_matchLeaves(l,e,h){const{attributes:c,localName:a,nodeType:o}=e;let r=this.#N.get(l),u;if(r&&r.has(e)){const{attr:d,matched:i}=r.get(e);c?.length===d&&(u=i)}if(typeof u!="boolean"){let d;o===n.ELEMENT_NODE&&n.REG_FORM.test(a)?d=!1:d=!0;for(const i of l){const{name:t,type:s}=i;if(s===n.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(d=!1),u=this._matchSelector(i,e,h).has(e),!u)break}d&&(r||(r=new WeakMap),r.set(e,{attr:c?.length,matched:u}),this.#N.set(l,r))}return!!u}_matchHTMLCollection(l,e={}){const{compound:h,filterLeaves:c}=e,a=new Set,o=l.length;if(o)if(h)for(let r=0;r<o;r++){const u=l[r];this._matchLeaves(c,u,e)&&a.add(u)}else{const r=[].slice.call(l);return new Set(r)}return a}_findDescendantNodes(l,e,h){const[c,...a]=l,o=a.length>0,{type:r}=c,u=(0,y.unescapeSelector)(c.name);typeof u=="string"&&u!==c.name&&(c.name=u);let d=new Set,i=!1;if(this.#d)i=!0;else switch(r){case n.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,h);break}case n.SELECTOR_ID:{if(this.#t.nodeType===n.ELEMENT_NODE)i=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(o?this._matchLeaves(a,t,h)&&d.add(t):d.add(t))}break}case n.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:o,filterLeaves:a});break}case n.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:o,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(l,e,h={}){const{combo:c,leaves:a}=l,{name:o}=c,{parentNode:r}=e,{dir:u}=h,d=new Set;if(u===x)switch(o){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,N.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,N.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let f=(0,N.traverseNode)(e,s);for(f=s.nextNode();f&&e.contains(f);)this._matchLeaves(a,f,h)&&d.add(f),f=s.nextNode()}}}else switch(o){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,N.traverseNode)(r,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{r&&this._matchLeaves(a,r,h)&&d.add(r);break}case" ":default:{const i=[];let t=r;for(;t;)this._matchLeaves(a,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(l,e){const{node:h}=e,c=this.#m;let a=(0,N.traverseNode)(h,c),o;if(a)for((a.nodeType!==n.ELEMENT_NODE||a===h&&a!==this.#t)&&(a=c.nextNode());a;){if(this._matchLeaves(l,a,{warn:this.#i})){o=a;break}a=c.nextNode()}return o??null}_matchSelf(l){const e=[],h=this._matchLeaves(l,this.#e,{warn:this.#i});let c=!1;return h&&(e.push(this.#e),c=!0),[e,c]}_findLineal(l,e={}){const{complex:h}=e,c=[];let a=this._matchLeaves(l,this.#e,{warn:this.#i}),o=!1;if(a&&(c.push(this.#e),o=!0),!a||h){let r=this.#e.parentNode;for(;r&&(a=this._matchLeaves(l,r,{warn:this.#i}),a&&(c.push(r),o=!0),r.parentNode);)r=r.parentNode}return[c,o]}_findFirst(l){const e=[],h=this._findNode(l,{node:this.#e});let c=!1;return h&&(e.push(h),c=!0),[e,c]}_findFromHTMLCollection(l,e={}){const{complex:h,compound:c,filterLeaves:a,targetType:o}=e;let r=[],u=!1,d=!1;const i=l.length;if(i)if(this.#e.nodeType===n.ELEMENT_NODE)for(let t=0;t<i;t++){const s=l[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(c){if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else if(r.push(s),u=!0,o===E)break}}else if(h)if(c)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else r=[].slice.call(l),u=!0,d=!0;else if(c)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else r=[].slice.call(l),u=!0,d=!0;return[r,u,d]}_findEntryNodes(l,e,h){const{leaves:c}=l,[a,...o]=c,r=o.length>0,{name:u,type:d}=a;let i=[],t=!1,s=!1,f=!1;switch(d){case n.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{warn:this.#i});break}case n.SELECTOR_ID:{if(e===R)[i,s]=this._matchSelf(c);else if(e===C)[i,s]=this._findLineal(c,{complex:h});else if(e===E&&this.#t.nodeType!==n.ELEMENT_NODE){const m=this.#t.getElementById(u);m&&(r?this._matchLeaves(o,m,{warn:this.#i})&&(i.push(m),s=!0):(i.push(m),s=!0))}else e===E?[i,s]=this._findFirst(c):f=!0;break}case n.SELECTOR_CLASS:{if(e===R)[i,s]=this._matchSelf(c);else if(e===C)[i,s]=this._findLineal(c,{complex:h});else if(this.#t.nodeType===n.DOCUMENT_NODE){const m=this.#t.getElementsByClassName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:r,filterLeaves:o,targetType:e}))}else e===E?[i,s]=this._findFirst(c):f=!0;break}case n.SELECTOR_TYPE:{if(e===R)[i,s]=this._matchSelf(c);else if(e===C)[i,s]=this._findLineal(c,{complex:h});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===n.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#t.getElementsByTagName(u);m.length&&([i,s,t]=this._findFromHTMLCollection(m,{complex:h,compound:r,filterLeaves:o,targetType:e}))}else e===E?[i,s]=this._findFirst(c):f=!0;break}default:if(e!==C&&n.REG_SHADOW_HOST.test(u)){if(this.#d&&this.#e.nodeType===n.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(a,this.#e);m&&(i.push(m),s=!0)}}else e===R?[i,s]=this._matchSelf(c):e===C?[i,s]=this._findLineal(c,{complex:h}):e===E?[i,s]=this._findFirst(c):f=!0}return{collected:t,compound:r,filtered:s,nodes:i,pending:f}}_collectNodes(l){const e=this.#a.values();if(l===L||l===E){const h=new Set;let c=0;for(const{branch:a}of e){const o=a.length,r=o>1,u=a[0];let d,i;if(r){const{combo:p,leaves:[{name:w,type:k}]}=u,_=a[o-1],{leaves:[{name:A,type:v}]}=_;if(v===n.SELECTOR_PSEUDO_ELEMENT||v===n.SELECTOR_ID)d=S,i=_;else if(k===n.SELECTOR_PSEUDO_ELEMENT||k===n.SELECTOR_ID)d=x,i=u;else if(l===L)if(w==="*"&&k===n.SELECTOR_TYPE)d=S,i=_;else if(A==="*"&&v===n.SELECTOR_TYPE)d=x,i=u;else if(o===2){const{name:T}=p;/^[+~]$/.test(T)?(d=S,i=_):(d=x,i=u)}else d=x,i=u;else if(A==="*"&&v===n.SELECTOR_TYPE)d=x,i=u;else if(w==="*"&&k===n.SELECTOR_TYPE)d=S,i=_;else{let T;for(const{combo:D,leaves:[U]}of a){const{name:$,type:F}=U;if(F===n.SELECTOR_PSEUDO_CLASS&&$==="dir"){T=!1;break}if(!T&&D){const{name:G}=D;/^[+~]$/.test(G)&&(T=!0)}}T?(d=x,i=u):(d=S,i=_)}}else d=S,i=u;const{collected:t,compound:s,filtered:f,nodes:m,pending:b}=this._findEntryNodes(i,l,r);m.length?(this.#a[c].find=!0,this.#f[c]=m):b&&h.add(new Map([["index",c],["twig",i]])),this.#a[c].collected=t,this.#a[c].dir=d,this.#a[c].filtered=f||!s,c++}if(h.size){let a,o;this.#e!==this.#t&&this.#e.nodeType===n.ELEMENT_NODE?(a=this.#e,o=this.#m):(a=this.#t,o=this.#r);let r=(0,N.traverseNode)(a,o);for(;r;){let u=!1;if(this.#e.nodeType===n.ELEMENT_NODE?r===this.#e?u=!0:u=this.#e.contains(r):u=!0,u)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,r,{warn:this.#i})){const s=d.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#f[s].push(r)}}r!==o.currentNode&&(r=(0,N.traverseNode)(r,o)),r=o.nextNode()}}}else{let h=0;for(const{branch:c}of e){const a=c[c.length-1],o=c.length>1,{compound:r,filtered:u,nodes:d}=this._findEntryNodes(a,l,o);d.length&&(this.#a[h].find=!0,this.#f[h]=d),this.#a[h].dir=S,this.#a[h].filtered=u||!r,h++}}return[this.#a,this.#f]}_getCombinedNodes(l,e,h){const c=[];for(const a of e){const o=this._matchCombinator(l,a,{dir:h,warn:this.#i});o.size&&c.push(...o)}return c.length?new Set(c):new Set}_matchNodeNext(l,e,h){const{combo:c,index:a}=h,{combo:o,leaves:r}=l[a],u={combo:c,leaves:r},d=this._getCombinedNodes(u,e,x);let i;if(d.size)if(a===l.length-1){const[t]=(0,N.sortNodes)(d);i=t}else i=this._matchNodeNext(l,d,{combo:o,index:a+1});return i??null}_matchNodePrev(l,e,h){const{index:c}=h,a=l[c],o=new Set([e]),r=this._getCombinedNodes(a,o,S);let u;if(r.size){if(c===0)u=e;else for(const d of r)if(this._matchNodePrev(l,d,{index:c-1}))return e}return u??null}_find(l){(l===L||l===E)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(l),c=e.length;let a=new Set;for(let o=0;o<c;o++){const{branch:r,collected:u,dir:d,find:i}=e[o],t=r.length;if(t&&i){const s=h[o],f=s.length,m=t-1;if(m===0)if((l===L||l===E)&&this.#e.nodeType===n.ELEMENT_NODE)for(let b=0;b<f;b++){const p=s[b];if(p!==this.#e&&this.#e.contains(p)&&(a.add(p),l!==L))break}else if(l===L)if(a.size){const b=[...a];a=new Set([...b,...s]),this.#u=!0}else a=new Set(s);else{const[b]=s;a.add(b)}else if(l===L)if(d===x){let{combo:b}=r[0];for(const p of s){let w=new Set([p]);for(let k=1;k<t;k++){const{combo:_,leaves:A}=r[k],v={combo:b,leaves:A};if(w=this._getCombinedNodes(v,w,d),w.size)if(k===m)if(a.size){const T=[...a];a=new Set([...T,...w]),this.#u=!0}else a=w;else b=_;else break}}}else for(const b of s){let p=new Set([b]);for(let w=m-1;w>=0;w--){const k=r[w];if(p=this._getCombinedNodes(k,p,d),p.size)w===0&&(a.add(b),t>1&&a.size>1&&(this.#u=!0));else break}}else if(l===E&&d===x){const{combo:b}=r[0];let p;for(const w of s)if(p=this._matchNodeNext(r,new Set([w]),{combo:b,index:1}),p){a.add(p);break}if(!p&&!u){const{leaves:w}=r[0],[k]=s;let _=this._findNode(w,{node:k});for(;_;){if(p=this._matchNodeNext(r,new Set([_]),{combo:b,index:1}),p){a.add(p);break}_=this._findNode(w,{node:_})}}}else{let b;for(const p of s)if(b=this._matchNodePrev(r,p,{index:m-1}),b){a.add(p);break}if(!b&&!u&&l===E){const{leaves:p}=r[m],[w]=s;let k=this._findNode(p,{node:w});for(;k;){if(b=this._matchNodePrev(r,k,{index:m-1}),b){a.add(k);break}k=this._findNode(p,{node:k})}}}}}return a}matches(l,e,h){let c;try{if(e?.nodeType!==n.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#n&&a.contentType==="text/html"){const r={complex:n.REG_COMPLEX.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#h.match(l,e)}this._setup(l,e,h),c=this._find(R).size}catch(a){this._onError(a)}return!!c}closest(l,e,h){let c;try{if(e?.nodeType!==n.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#n&&a.contentType==="text/html"){const r={complex:n.REG_COMPLEX.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#h.closest(l,e)}this._setup(l,e,h);const o=this._find(C);if(o.size){let r=this.#e;for(;r;){if(o.has(r)){c=r;break}r=r.parentNode}}}catch(a){this._onError(a)}return c??null}querySelector(l,e,h){let c;try{(0,N.verifyNode)(e);let a;if(e.nodeType===n.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#n&&a.contentType==="text/html"&&(0,y.filterSelector)(l,{complex:!1,descendant:!1}))return this.#h.first(l,e);this._setup(l,e,h);const o=this._find(E);o.delete(this.#e),o.size&&([c]=(0,N.sortNodes)(o))}catch(a){this._onError(a)}return c??null}querySelectorAll(l,e,h){let c;try{(0,N.verifyNode)(e);let a;if(e.nodeType===n.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#n&&a.contentType==="text/html"&&(0,y.filterSelector)(l,{complex:!1,descendant:!0,qsa:!0}))return this.#h.select(l,e);this._setup(l,e,h);const o=this._find(L);o.delete(this.#e),o.size&&(this.#u?c=(0,N.sortNodes)(o):c=[...o])}catch(a){this._onError(a)}return c??[]}}0&&(module.exports={Finder}); | ||
var z=Object.create;var M=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var q=(g,l)=>{for(var e in l)M(g,e,{get:l[e],enumerable:!0})},P=(g,l,e,h)=>{if(l&&typeof l=="object"||typeof l=="function")for(let c of W(l))!j.call(g,c)&&c!==e&&M(g,c,{get:()=>l[c],enumerable:!(h=H(l,c))||h.enumerable});return g};var Y=(g,l,e)=>(e=g!=null?z(B(g)):{},P(l||!g||!g.__esModule?M(e,"default",{value:g,enumerable:!0}):e,g)),V=g=>P(M({},"__esModule",{value:!0}),g);var K={};q(K,{Finder:()=>X});module.exports=V(K);var I=Y(require("@asamuzakjp/nwsapi"),1),k=require("./dom-util.js"),O=require("./matcher.js"),y=require("./parser.js"),n=require("./constant.js");const x="next",A="prev",L="all",E="first",C="lineal",R="self";class X{#a;#c;#s;#o;#w;#n;#b;#e;#f;#k;#h;#m;#N;#t;#d;#u;#r;#p;#i;#l;constructor(l,e){this.#l=l,this.#n=e??l.document,this.#c=new WeakMap,this.#o=new WeakMap,this.#N=new WeakMap,this.#h=this._initNwsapi(l,e)}_onError(l){if(!this.#k)if(l instanceof DOMException||l instanceof this.#l.DOMException)if(l.name===n.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw new this.#l.DOMException(l.message,l.name);else throw l}_setup(l,e,h={}){const{event:c,noexcept:a,warn:o}=h;return this.#k=!!a,this.#i=!!o,this.#b=this._setEvent(c),this.#e=e,[this.#s,this.#t,this.#r]=(0,k.resolveContent)(e),this.#d=(0,k.isInShadowTree)(e),[this.#a,this.#f]=this._correspond(l),this.#p=new WeakMap,e}_initNwsapi(){const l=(0,I.default)({DOMException:this.#l.DOMException,document:this.#n});return l.configure({LOGERRORS:!1}),l}_setEvent(l){return l instanceof this.#l.KeyboardEvent||l instanceof this.#l.MouseEvent?l:null}_correspond(l){const e=[];this.#w=!1;let h;if(this.#o.has(this.#s)){const c=this.#o.get(this.#s);if(c&&c.has(`${l}`)){const a=c.get(`${l}`);this.#w=a.descendant,h=a.ast}}if(h){const c=h.length;for(let a=0;a<c;a++)h[a].collected=!1,h[a].dir=null,h[a].filtered=!1,h[a].find=!1,e[a]=[]}else{let c;try{c=(0,y.parseSelector)(l)}catch(b){this._onError(b)}const{branches:a,info:{hasDefinedPseudo:o,hasHasPseudoFunc:r,hasHyphenSepAttr:u,hasNthChildOfSelector:d,hasPseudoFunc:i}}=(0,y.walkAST)(c);let t;o||r||u||d&&i?t=!1:t=!0;let s=!1,f=0;h=[];for(const[...b]of a){const m=[];let p=b.shift();if(p&&p.type!==n.COMBINATOR){const w=new Set;for(;p;){if(p.type===n.COMBINATOR){const[N]=b;if(N.type===n.COMBINATOR){const S=`Invalid selector ${l}`;throw new DOMException(S,n.SYNTAX_ERR)}const _=p.name;/^[\s>]$/.test(_)&&(s=!0),m.push({combo:p,leaves:(0,y.sortAST)(w)}),w.clear()}else if(p){let{name:N}=p;N&&typeof N=="string"&&(N=(0,y.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,y.sortAST)(w)}),w.clear();break}}}h.push({branch:m,collected:!1,dir:null,filtered:!1,find:!1}),e[f]=[],f++}if(t){let b;this.#o.has(this.#s)?b=this.#o.get(this.#s):b=new Map,b.set(`${l}`,{ast:h,descendant:s}),this.#o.set(this.#s,b)}this.#w=s}return[h,e]}_createTreeWalker(l){let e;return this.#p.has(l)?e=this.#p.get(l):(e=this.#n.createTreeWalker(l,n.WALKER_FILTER),this.#p.set(l,e)),e}_prepareQuerySelectorWalker(){return this.#m=this._createTreeWalker(this.#e),this.#u=!1,this.#m}_collectNthChild(l,e,h){const{a:c,b:a,reverse:o,selector:r}=l,{parentNode:u}=e,d=new Set;let i;if(r)if(this.#c.has(r))i=this.#c.get(r);else{const{branches:t}=(0,y.walkAST)(r);i=t,this.#c.set(r,i)}if(u){const t=this.#r;let s=(0,k.traverseNode)(u,t);s=t.firstChild();let f=0;for(;s;)f++,s=t.nextSibling();const b=new Set;if(i)for(s=(0,k.traverseNode)(u,t),s=t.firstChild();s;){const{display:m,visibility:p}=this.#l.getComputedStyle(s);if(m!=="none"&&p!=="hidden"){let w;for(const N of i)if(w=this._matchLeaves(N,s,h),!w)break;w&&b.add(s)}s=t.nextSibling()}if(c===0){if(a>0&&a<=f){if(b.size){s=(0,k.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(b.has(s)){if(m===a-1){d.add(s);break}m++}o?s=t.previousSibling():s=t.nextSibling()}}else if(!r){s=(0,k.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let m=0;for(;s;){if(m===a-1){d.add(s);break}o?s=t.previousSibling():s=t.nextSibling(),m++}}}}else{let m=a-1;if(c>0)for(;m<0;)m+=c;if(m>=0&&m<f){s=(0,k.traverseNode)(u,t),o?s=t.lastChild():s=t.firstChild();let p=0,w=c>0?0:a-1;for(;s&&(s&&m>=0&&m<f);)b.size?b.has(s)&&(w===m&&(d.add(s),m+=c),c>0?w++:w--):p===m&&(r||d.add(s),m+=c),o?s=t.previousSibling():s=t.nextSibling(),p++}}if(o&&d.size>1){const m=[...d];return new Set(m.reverse())}}else if(e===this.#t&&c+a===1)if(i){let t;for(const s of i)if(t=this._matchLeaves(s,e,h),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(l,e){const{a:h,b:c,reverse:a}=l,{localName:o,parentNode:r,prefix:u}=e,d=new Set;if(r){const i=this.#r;let t=(0,k.traverseNode)(r,i);t=i.firstChild();let s=0;for(;t;)s++,t=i.nextSibling();if(h===0){if(c>0&&c<=s){t=(0,k.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let f=0;for(;t;){const{localName:b,prefix:m}=t;if(b===o&&m===u){if(f===c-1){d.add(t);break}f++}a?t=i.previousSibling():t=i.nextSibling()}}}else{let f=c-1;if(h>0)for(;f<0;)f+=h;if(f>=0&&f<s){t=(0,k.traverseNode)(r,i),a?t=i.lastChild():t=i.firstChild();let b=h>0?0:c-1;for(;t;){const{localName:m,prefix:p}=t;if(m===o&&p===u){if(b===f&&(d.add(t),f+=h),f<0||f>=s)break;h>0?b++:b--}a?t=i.previousSibling():t=i.nextSibling()}}}if(a&&d.size>1){const f=[...d];return new Set(f.reverse())}}else e===this.#t&&h+c===1&&d.add(e);return d}_matchAnPlusB(l,e,h,c){const{nth:{a,b:o,name:r},selector:u}=l,d=new Map;if(r?(r==="even"?(d.set("a",2),d.set("b",0)):r==="odd"&&(d.set("a",2),d.set("b",1)),h.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?d.set("b",o*1):d.set("b",0),h.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(h)){u&&d.set("selector",u);const i=Object.fromEntries(d);return this._collectNthChild(i,e,c)}else if(/^nth-(?:last-)?of-type$/.test(h)){const i=Object.fromEntries(d);return this._collectNthOfType(i,e)}return new Set}_matchHasPseudoFunc(l,e,h={}){let c;if(Array.isArray(l)&&l.length){const a=l.map(s=>s),[o]=a,{type:r}=o;let u;r===n.COMBINATOR?u=a.shift():u={name:" ",type:n.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:f}=s;if(f===n.COMBINATOR)break;d.push(a.shift())}const i={combo:u,leaves:d};h.dir=x;const t=this._matchCombinator(i,e,h);if(t.size)if(a.length){for(const s of t)if(c=this._matchHasPseudoFunc(a,s,h),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(l,e,h={}){const{astName:c="",branches:a=[],selector:o="",twigBranches:r=[]}=l;let u;if(c==="has")if(o.includes(":has("))u=null;else{let d;for(const i of a)if(d=this._matchHasPseudoFunc(i,e,h),d)break;d&&(u=e)}else{const d=/^(?:is|where)$/.test(c);h.forgive=d;const i=r.length;let t;for(let s=0;s<i;s++){const f=r[s],b=f.length-1,{leaves:m}=f[b];if(t=this._matchLeaves(m,e,h),t&&b>0){let p=new Set([e]);for(let w=b-1;w>=0;w--){const N=f[w],_=[];h.dir=A;for(const S of p){const v=this._matchCombinator(N,S,h);v.size&&_.push(...v)}if(_.length)w===0?t=!0:p=new Set(_);else{t=!1;break}}}if(t)break}c==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(l,e,h={}){const{children:c,name:a}=l,{localName:o,parentNode:r}=e,{forgive:u,warn:d=this.#i}=h,i=new Set;if(n.REG_LOGICAL_PSEUDO.test(a)){let t;if(this.#c.has(l))t=this.#c.get(l);else{const{branches:f}=(0,y.walkAST)(l),b=[],m=[];for(const[...p]of f){for(const S of p){const v=(0,y.generateCSS)(S);b.push(v)}const w=[],N=new Set;let _=p.shift();for(;_;)if(_.type===n.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)}t={astName:a,branches:f,twigBranches:m,selector:b.join(",")},this.#c.set(l,t)}const s=this._matchLogicalPseudoFunc(t,e,h);s&&i.add(s)}else if(Array.isArray(c))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=c;return this._matchAnPlusB(t,e,a,h)}else switch(a){case"dir":case"lang":{const t=O.matcher.matchSelector(l,e);t&&i.add(t);break}case"state":{if((0,k.isCustomElement)(e)){const[{value:t}]=c;t&&e[t]&&i.add(e)}break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${a}()`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;case"contains":{if(d){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}break}default:if(!u){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,n.SYNTAX_ERR)}}else switch(a){case"any-link":case"link":{n.REG_ANCHOR.test(o)&&e.hasAttribute("href")&&i.add(e);break}case"local-link":{if(n.REG_ANCHOR.test(o)&&e.hasAttribute("href")){const{href:t,origin:s,pathname:f}=new URL(this.#s.URL),b=new URL(e.getAttribute("href"),t);b.origin===s&&b.pathname===f&&i.add(e)}break}case"visited":break;case"hover":{const{target:t,type:s}=this.#b??{};(s==="mouseover"||s==="pointerover")&&e.contains(t)&&i.add(e);break}case"active":{const{buttons:t,target:s,type:f}=this.#b??{};(f==="mousedown"||f==="pointerdown")&&t&n.BIT_01&&e.contains(s)&&i.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&i.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const s=t.replace(/^#/,"");let f=this.#s.getElementById(s);for(;f;){if(f===e){i.add(e);break}f=f.parentNode}}break}case"scope":{this.#e.nodeType===n.ELEMENT_NODE?!this.#d&&e===this.#e&&i.add(e):e===this.#s.documentElement&&i.add(e);break}case"focus":case"focus-visible":{const{target:t,type:s}=this.#b??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(a==="focus"||s==="keydown"&&e.contains(t))){let f=e,b=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){b=!1;break}else{const{display:m,visibility:p}=this.#l.getComputedStyle(f);if(b=!(m==="none"||p==="hidden"),!b)break}if(f.parentNode&&f.parentNode.nodeType===n.ELEMENT_NODE)f=f.parentNode;else break}b&&i.add(e)}break}case"focus-within":{let t,s=this.#s.activeElement;if(s.tabIndex>=0)for(;s;){if(s===e){t=!0;break}s=s.parentNode}if(t){let f=e,b=!0;for(;f;){if(f.disabled||f.hasAttribute("disabled")||f.hidden||f.hasAttribute("hidden")){b=!1;break}else{const{display:m,visibility:p}=this.#l.getComputedStyle(f);if(b=!(m==="none"||p==="hidden"),!b)break}if(f.parentNode&&f.parentNode.nodeType===n.ELEMENT_NODE)f=f.parentNode;else break}b&&i.add(e)}break}case"open":{n.REG_INTERACT.test(o)&&e.hasAttribute("open")&&i.add(e);break}case"closed":{n.REG_INTERACT.test(o)&&!e.hasAttribute("open")&&i.add(e);break}case"disabled":{if(n.REG_FORM_CTRL.test(o)||(0,k.isCustomElement)(e,{formAssociated:!0})){if(e.disabled||e.hasAttribute("disabled"))i.add(e);else if(e.localName==="option")r.localName==="optgroup"&&(r.disabled||r.hasAttribute("disabled"))&&i.add(e);else if(e.localName!=="optgroup"){let t,s=r;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const f=this.#r;let b=(0,k.traverseNode)(s,f);for(b=f.firstChild();b&&b.localName!=="legend";)b=f.nextSibling();b&&b.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===n.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t&&i.add(e)}}break}case"enabled":{if((n.REG_FORM_CTRL.test(o)||(0,k.isCustomElement)(e,{formAssociated:!0}))&&!(e.disabled&&e.hasAttribute("disabled")))if(e.localName==="optgroup")i.add(e);else if(e.localName==="option")(r.localName!=="optgroup"||!(r.disabled||r.hasAttribute("disabled")))&&i.add(e);else{let t,s=r;for(;s;)if(s.localName==="fieldset"&&(s.disabled||s.hasAttribute("disabled"))){const f=this.#r;let b=(0,k.traverseNode)(s,f);for(b=f.firstChild();b&&b.localName!=="legend";)b=f.nextSibling();b&&b.contains(e)||(t=!0);break}else{if(s.localName==="form")break;if(s.parentNode?.nodeType===n.ELEMENT_NODE){if(s.parentNode.localName==="form")break;s=s.parentNode}else break}t||i.add(e)}break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&i.add(e);break}case"input":{(!e.type||n.REG_TYPE_DATE.test(e.type)||n.REG_TYPE_TEXT.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(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||i.add(e);break}case"input":{(!e.type||n.REG_TYPE_DATE.test(e.type)||n.REG_TYPE_TEXT.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 t;if(e.placeholder?t=e.placeholder:e.hasAttribute("placeholder")&&(t=e.getAttribute("placeholder")),typeof t=="string"&&!/[\r\n]/.test(t)){let s;o==="textarea"?s=e:o==="input"&&(e.hasAttribute("type")?n.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.value===""&&i.add(e)}break}case"checked":{(e.checked&&o==="input"&&e.hasAttribute("type")&&n.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&o==="option")&&i.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))i.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;s||(s=this.#s.documentElement);const f=s.getElementsByTagName("input"),b=f.length;let m;for(let p=0;p<b;p++){const w=f[p];if(w.getAttribute("type")==="radio"&&(t?w.getAttribute("name")===t&&(m=!!w.checked):w.hasAttribute("name")||(m=!!w.checked),m))break}m||i.add(e)}break}case"default":{if(o==="button"&&!(e.hasAttribute("type")&&n.REG_TYPE_RESET.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&n.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const s=this.#r;let f=(0,k.traverseNode)(t,s);for(f=s.firstChild();f&&t.contains(f);){const b=f.localName;let m;if(b==="button"?m=!(f.hasAttribute("type")&&n.REG_TYPE_RESET.test(f.getAttribute("type"))):b==="input"&&(m=f.hasAttribute("type")&&n.REG_TYPE_SUBMIT.test(f.getAttribute("type"))),m){f===e&&i.add(e);break}f=s.nextNode()}}}else(o==="input"&&e.hasAttribute("type")&&n.REG_TYPE_CHECK.test(e.getAttribute("type"))&&e.hasAttribute("checked")||o==="option"&&e.hasAttribute("selected"))&&i.add(e);break}case"valid":{if(n.REG_FORM_VALID.test(o))e.checkValidity()&&(e.maxLength>=0?e.maxLength>=e.value.length&&i.add(e):i.add(e));else if(o==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(n.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f&&i.add(e)}break}case"invalid":{if(n.REG_FORM_VALID.test(o))e.checkValidity()?e.maxLength>=0&&e.maxLength<e.value.length&&i.add(e):i.add(e);else if(o==="fieldset"){const t=this.#r;let s=(0,k.traverseNode)(e,t);s=t.firstChild();let f;if(!s)f=!0;else for(;s&&e.contains(s)&&!(n.REG_FORM_VALID.test(s.localName)&&(s.checkValidity()?s.maxLength>=0?f=s.maxLength>=s.value.length:f=!0:f=!1,!f));)s=t.nextNode();f||i.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&n.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&i.add(e);break}case"out-of-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&n.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&i.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||n.REG_TYPE_CHECK.test(s)||n.REG_TYPE_DATE.test(s)||n.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&i.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(o))t=e;else if(o==="input")if(e.hasAttribute("type")){const s=e.getAttribute("type");(s==="file"||n.REG_TYPE_CHECK.test(s)||n.REG_TYPE_DATE.test(s)||n.REG_TYPE_TEXT.test(s))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&i.add(e);break}case"root":{e===this.#s.documentElement&&i.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#n.createTreeWalker(e,n.SHOW_ALL);let s=t.firstChild(),f;for(;s&&(f=s.nodeType!==n.ELEMENT_NODE&&s.nodeType!==n.TEXT_NODE,!!f);)s=t.nextSibling();f&&i.add(e)}else i.add(e);break}case"first-child":{(r&&e===r.firstElementChild||e===this.#t)&&i.add(e);break}case"last-child":{(r&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"only-child":{(r&&e===r.firstElementChild&&e===r.lastElementChild||e===this.#t)&&i.add(e);break}case"first-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"last-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&i.add(t)}else e===this.#t&&i.add(e);break}case"only-of-type":{if(r){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s===e&&i.add(e)}}else e===this.#t&&i.add(e);break}case"defined":{e.hasAttribute("is")||o.includes("-")?(0,k.isCustomElement)(e)&&i.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&i.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#l.getComputedStyle(e);t!=="none"&&i.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${a}`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}break}default:if(a.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,n.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${a}`;throw new DOMException(t,n.SYNTAX_ERR)}}return i}_matchShadowHostPseudoClass(l,e){const{children:h,name:c}=l;let a;if(Array.isArray(h)){const{branches:o}=(0,y.walkAST)(h[0]),[r]=o,[...u]=r,{host:d}=e;if(c==="host"){let i;for(const t of u){const{type:s}=t;if(s===n.COMBINATOR){const b=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(b,n.SYNTAX_ERR)}if(i=this._matchSelector(t,d).has(d),!i)break}i&&(a=e)}else if(c==="host-context"){let i=d,t;for(;i;){for(const s of u){const{type:f}=s;if(f===n.COMBINATOR){const m=`Invalid selector ${(0,y.generateCSS)(l)}`;throw new DOMException(m,n.SYNTAX_ERR)}if(t=this._matchSelector(s,i).has(i),!t)break}if(t)break;i=i.parentNode}t&&(a=e)}}else if(c==="host")a=e;else{const o=`Invalid selector :${c}`;throw new DOMException(o,n.SYNTAX_ERR)}return a??null}_matchSelector(l,e,h){const{type:c}=l,a=new Set;if(l.name===n.EMPTY)return a;const o=(0,y.unescapeSelector)(l.name);if(typeof o=="string"&&o!==l.name&&(l.name=o),e.nodeType===n.ELEMENT_NODE)switch(c){case n.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(o,h);break}case n.SELECTOR_ID:{e.id===o&&a.add(e);break}case n.SELECTOR_CLASS:{e.classList.contains(o)&&a.add(e);break}case n.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(l,e,h);default:{const r=O.matcher.matchSelector(l,e,h);r&&a.add(r)}}else if(this.#d&&c===n.SELECTOR_PSEUDO_CLASS&&e.nodeType===n.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&n.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(l,e,h);if(n.REG_SHADOW_HOST.test(o)){const r=this._matchShadowHostPseudoClass(l,e,h);r&&a.add(r)}}return a}_matchLeaves(l,e,h){const{attributes:c,localName:a,nodeType:o}=e;let r=this.#N.get(l),u;if(r&&r.has(e)){const{attr:d,matched:i}=r.get(e);c?.length===d&&(u=i)}if(typeof u!="boolean"){let d;o===n.ELEMENT_NODE&&n.REG_FORM.test(a)?d=!1:d=!0;for(const i of l){const{name:t,type:s}=i;if(s===n.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(d=!1),u=this._matchSelector(i,e,h).has(e),!u)break}d&&(r||(r=new WeakMap),r.set(e,{attr:c?.length,matched:u}),this.#N.set(l,r))}return!!u}_matchHTMLCollection(l,e={}){const{compound:h,filterLeaves:c}=e,a=new Set,o=l.length;if(o)if(h)for(let r=0;r<o;r++){const u=l[r];this._matchLeaves(c,u,e)&&a.add(u)}else{const r=[].slice.call(l);return new Set(r)}return a}_findDescendantNodes(l,e,h){const[c,...a]=l,o=a.length>0,{type:r}=c,u=(0,y.unescapeSelector)(c.name);typeof u=="string"&&u!==c.name&&(c.name=u);let d=new Set,i=!1;if(this.#d)i=!0;else switch(r){case n.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,h);break}case n.SELECTOR_ID:{if(this.#t.nodeType===n.ELEMENT_NODE)i=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(o?this._matchLeaves(a,t,h)&&d.add(t):d.add(t))}break}case n.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);d=this._matchHTMLCollection(t,{compound:o,filterLeaves:a});break}case n.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);d=this._matchHTMLCollection(t,{compound:o,filterLeaves:a})}else i=!0;break}default:i=!0}return{nodes:d,pending:i}}_matchCombinator(l,e,h={}){const{combo:c,leaves:a}=l,{name:o}=c,{parentNode:r}=e,{dir:u}=h,d=new Set;if(u===x)switch(o){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,k.traverseNode)(e,i);for(t=i.nextSibling();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{const i=this._createTreeWalker(e);let t=(0,k.traverseNode)(e,i);for(t=i.firstChild();t;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling();break}case" ":default:{const{nodes:i,pending:t}=this._findDescendantNodes(a,e);if(i.size)return i;if(t){const s=this._createTreeWalker(e);let f=(0,k.traverseNode)(e,s);for(f=s.nextNode();f&&e.contains(f);)this._matchLeaves(a,f,h)&&d.add(f),f=s.nextNode()}}}else switch(o){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,h)&&d.add(i);break}case"~":{if(r){const i=this._createTreeWalker(r);let t=(0,k.traverseNode)(r,i);for(t=i.firstChild();t&&t!==e;)this._matchLeaves(a,t,h)&&d.add(t),t=i.nextSibling()}break}case">":{r&&this._matchLeaves(a,r,h)&&d.add(r);break}case" ":default:{const i=[];let t=r;for(;t;)this._matchLeaves(a,t,h)&&i.push(t),t=t.parentNode;if(i.length)return new Set(i.reverse())}}return d}_findNode(l,e){const{node:h}=e,c=this.#m;let a=(0,k.traverseNode)(h,c),o;if(a)for((a.nodeType!==n.ELEMENT_NODE||a===h&&a!==this.#t)&&(a=c.nextNode());a;){if(this._matchLeaves(l,a,{warn:this.#i})){o=a;break}a=c.nextNode()}return o??null}_matchSelf(l){const e=[],h=this._matchLeaves(l,this.#e,{warn:this.#i});let c=!1;return h&&(e.push(this.#e),c=!0),[e,c]}_findLineal(l,e={}){const{complex:h}=e,c=[];let a=this._matchLeaves(l,this.#e,{warn:this.#i}),o=!1;if(a&&(c.push(this.#e),o=!0),!a||h){let r=this.#e.parentNode;for(;r&&(a=this._matchLeaves(l,r,{warn:this.#i}),a&&(c.push(r),o=!0),r.parentNode);)r=r.parentNode}return[c,o]}_findFirst(l){const e=[],h=this._findNode(l,{node:this.#e});let c=!1;return h&&(e.push(h),c=!0),[e,c]}_findFromHTMLCollection(l,e={}){const{complex:h,compound:c,filterLeaves:a,targetType:o}=e;let r=[],u=!1,d=!1;const i=l.length;if(i)if(this.#e.nodeType===n.ELEMENT_NODE)for(let t=0;t<i;t++){const s=l[t];if(s!==this.#e&&(this.#e.contains(s)||s.contains(this.#e))){if(c){if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else if(r.push(s),u=!0,o===E)break}}else if(h)if(c)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else r=[].slice.call(l),u=!0,d=!0;else if(c)for(let t=0;t<i;t++){const s=l[t];if(this._matchLeaves(a,s,{warn:this.#i})&&(r.push(s),u=!0,o===E))break}else r=[].slice.call(l),u=!0,d=!0;return[r,u,d]}_findEntryNodes(l,e,h){const{leaves:c}=l,[a,...o]=c,r=o.length>0,{name:u,type:d}=a;let i=[],t=!1,s=!1,f=!1;switch(d){case n.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{warn:this.#i});break}case n.SELECTOR_ID:{if(e===R)[i,s]=this._matchSelf(c);else if(e===C)[i,s]=this._findLineal(c,{complex:h});else if(e===E&&this.#t.nodeType!==n.ELEMENT_NODE){const b=this.#t.getElementById(u);b&&(r?this._matchLeaves(o,b,{warn:this.#i})&&(i.push(b),s=!0):(i.push(b),s=!0))}else e===E?[i,s]=this._findFirst(c):f=!0;break}case n.SELECTOR_CLASS:{if(e===R)[i,s]=this._matchSelf(c);else if(e===C)[i,s]=this._findLineal(c,{complex:h});else if(this.#t.nodeType===n.DOCUMENT_NODE){const b=this.#t.getElementsByClassName(u);b.length&&([i,s,t]=this._findFromHTMLCollection(b,{complex:h,compound:r,filterLeaves:o,targetType:e}))}else e===E?[i,s]=this._findFirst(c):f=!0;break}case n.SELECTOR_TYPE:{if(e===R)[i,s]=this._matchSelf(c);else if(e===C)[i,s]=this._findLineal(c,{complex:h});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===n.DOCUMENT_NODE&&!/[*|]/.test(u)){const b=this.#t.getElementsByTagName(u);b.length&&([i,s,t]=this._findFromHTMLCollection(b,{complex:h,compound:r,filterLeaves:o,targetType:e}))}else e===E?[i,s]=this._findFirst(c):f=!0;break}default:if(e!==C&&n.REG_SHADOW_HOST.test(u)){if(this.#d&&this.#e.nodeType===n.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(a,this.#e);b&&(i.push(b),s=!0)}}else e===R?[i,s]=this._matchSelf(c):e===C?[i,s]=this._findLineal(c,{complex:h}):e===E?[i,s]=this._findFirst(c):f=!0}return{collected:t,compound:r,filtered:s,nodes:i,pending:f}}_collectNodes(l){const e=this.#a.values();if(l===L||l===E){const h=new Set;let c=0;for(const{branch:a}of e){const o=a.length,r=o>1,u=a[0];let d,i;if(r){const{combo:p,leaves:[{name:w,type:N}]}=u,_=a[o-1],{leaves:[{name:S,type:v}]}=_;if(v===n.SELECTOR_PSEUDO_ELEMENT||v===n.SELECTOR_ID)d=A,i=_;else if(N===n.SELECTOR_PSEUDO_ELEMENT||N===n.SELECTOR_ID)d=x,i=u;else if(l===L)if(w==="*"&&N===n.SELECTOR_TYPE)d=A,i=_;else if(S==="*"&&v===n.SELECTOR_TYPE)d=x,i=u;else if(o===2){const{name:T}=p;/^[+~]$/.test(T)?(d=A,i=_):(d=x,i=u)}else d=x,i=u;else if(S==="*"&&v===n.SELECTOR_TYPE)d=x,i=u;else if(w==="*"&&N===n.SELECTOR_TYPE)d=A,i=_;else{let T;for(const{combo:D,leaves:[U]}of a){const{name:$,type:F}=U;if(F===n.SELECTOR_PSEUDO_CLASS&&$==="dir"){T=!1;break}if(!T&&D){const{name:G}=D;/^[+~]$/.test(G)&&(T=!0)}}T?(d=x,i=u):(d=A,i=_)}}else d=A,i=u;const{collected:t,compound:s,filtered:f,nodes:b,pending:m}=this._findEntryNodes(i,l,r);b.length?(this.#a[c].find=!0,this.#f[c]=b):m&&h.add(new Map([["index",c],["twig",i]])),this.#a[c].collected=t,this.#a[c].dir=d,this.#a[c].filtered=f||!s,c++}if(h.size){let a,o;this.#e!==this.#t&&this.#e.nodeType===n.ELEMENT_NODE?(a=this.#e,o=this.#m):(a=this.#t,o=this.#r);let r=(0,k.traverseNode)(a,o);for(;r;){let u=!1;if(this.#e.nodeType===n.ELEMENT_NODE?r===this.#e?u=!0:u=this.#e.contains(r):u=!0,u)for(const d of h){const{leaves:i}=d.get("twig");if(this._matchLeaves(i,r,{warn:this.#i})){const s=d.get("index");this.#a[s].filtered=!0,this.#a[s].find=!0,this.#f[s].push(r)}}r!==o.currentNode&&(r=(0,k.traverseNode)(r,o)),r=o.nextNode()}}}else{let h=0;for(const{branch:c}of e){const a=c[c.length-1],o=c.length>1,{compound:r,filtered:u,nodes:d}=this._findEntryNodes(a,l,o);d.length&&(this.#a[h].find=!0,this.#f[h]=d),this.#a[h].dir=A,this.#a[h].filtered=u||!r,h++}}return[this.#a,this.#f]}_getCombinedNodes(l,e,h){const c=[];for(const a of e){const o=this._matchCombinator(l,a,{dir:h,warn:this.#i});o.size&&c.push(...o)}return c.length?new Set(c):new Set}_matchNodeNext(l,e,h){const{combo:c,index:a}=h,{combo:o,leaves:r}=l[a],u={combo:c,leaves:r},d=this._getCombinedNodes(u,e,x);let i;if(d.size)if(a===l.length-1){const[t]=(0,k.sortNodes)(d);i=t}else i=this._matchNodeNext(l,d,{combo:o,index:a+1});return i??null}_matchNodePrev(l,e,h){const{index:c}=h,a=l[c],o=new Set([e]),r=this._getCombinedNodes(a,o,A);let u;if(r.size){if(c===0)u=e;else for(const d of r)if(this._matchNodePrev(l,d,{index:c-1}))return e}return u??null}_find(l){(l===L||l===E)&&this._prepareQuerySelectorWalker();const[[...e],h]=this._collectNodes(l),c=e.length;let a=new Set;for(let o=0;o<c;o++){const{branch:r,collected:u,dir:d,find:i}=e[o],t=r.length;if(t&&i){const s=h[o],f=s.length,b=t-1;if(b===0)if((l===L||l===E)&&this.#e.nodeType===n.ELEMENT_NODE)for(let m=0;m<f;m++){const p=s[m];if(p!==this.#e&&this.#e.contains(p)&&(a.add(p),l!==L))break}else if(l===L)if(a.size){const m=[...a];a=new Set([...m,...s]),this.#u=!0}else a=new Set(s);else{const[m]=s;a.add(m)}else if(l===L)if(d===x){let{combo:m}=r[0];for(const p of s){let w=new Set([p]);for(let N=1;N<t;N++){const{combo:_,leaves:S}=r[N],v={combo:m,leaves:S};if(w=this._getCombinedNodes(v,w,d),w.size)if(N===b)if(a.size){const T=[...a];a=new Set([...T,...w]),this.#u=!0}else a=w;else m=_;else break}}}else for(const m of s){let p=new Set([m]);for(let w=b-1;w>=0;w--){const N=r[w];if(p=this._getCombinedNodes(N,p,d),p.size)w===0&&(a.add(m),t>1&&a.size>1&&(this.#u=!0));else break}}else if(l===E&&d===x){const{combo:m}=r[0];let p;for(const w of s)if(p=this._matchNodeNext(r,new Set([w]),{combo:m,index:1}),p){a.add(p);break}if(!p&&!u){const{leaves:w}=r[0],[N]=s;let _=this._findNode(w,{node:N});for(;_;){if(p=this._matchNodeNext(r,new Set([_]),{combo:m,index:1}),p){a.add(p);break}_=this._findNode(w,{node:_})}}}else{let m;for(const p of s)if(m=this._matchNodePrev(r,p,{index:b-1}),m){a.add(p);break}if(!m&&!u&&l===E){const{leaves:p}=r[b],[w]=s;let N=this._findNode(p,{node:w});for(;N;){if(m=this._matchNodePrev(r,N,{index:b-1}),m){a.add(N);break}N=this._findNode(p,{node:N})}}}}}return a}matches(l,e,h){let c;try{if(e?.nodeType!==n.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#n&&a.contentType==="text/html"){const r={complex:n.REG_COMPLEX.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#h.match(l,e)}this._setup(l,e,h),c=this._find(R).size}catch(a){this._onError(a)}return!!c}closest(l,e,h){let c;try{if(e?.nodeType!==n.ELEMENT_NODE){const r=`Unexpected node ${e?.nodeName}`;throw new TypeError(r)}const a=e.ownerDocument;if(a===this.#n&&a.contentType==="text/html"){const r={complex:n.REG_COMPLEX.test(l),descendant:!0};if((0,y.filterSelector)(l,r))return this.#h.closest(l,e)}this._setup(l,e,h);const o=this._find(C);if(o.size){let r=this.#e;for(;r;){if(o.has(r)){c=r;break}r=r.parentNode}}}catch(a){this._onError(a)}return c??null}querySelector(l,e,h){let c;try{(0,k.verifyNode)(e);let a;if(e.nodeType===n.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#n&&a.contentType==="text/html"&&(0,y.filterSelector)(l,{complex:!1,descendant:!1}))return this.#h.first(l,e);this._setup(l,e,h);const o=this._find(E);o.delete(this.#e),o.size&&([c]=(0,k.sortNodes)(o))}catch(a){this._onError(a)}return c??null}querySelectorAll(l,e,h){let c;try{(0,k.verifyNode)(e);let a;if(e.nodeType===n.DOCUMENT_NODE?a=e:a=e.ownerDocument,a===this.#n&&a.contentType==="text/html"&&(0,y.filterSelector)(l,{complex:!1,descendant:!0,qsa:!0}))return this.#h.select(l,e);this._setup(l,e,h);const o=this._find(L);o.delete(this.#e),o.size&&(this.#u?c=(0,k.sortNodes)(o):c=[...o])}catch(a){this._onError(a)}return c??[]}}0&&(module.exports={Finder}); | ||
//# sourceMappingURL=finder.js.map |
@@ -1,3 +0,3 @@ | ||
var h=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var I=(s,t)=>{for(var r in t)h(s,r,{get:t[r],enumerable:!0})},L=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!S.call(s,n)&&n!==r&&h(s,n,{get:()=>t[n],enumerable:!(i=_(t,n))||i.enumerable});return s};var T=s=>L(h({},"__esModule",{value:!0}),s);var D={};I(D,{filterSelector:()=>C,generateCSS:()=>O.generate,parseAstName:()=>w,parseSelector:()=>u,preprocess:()=>g,sortAST:()=>y,unescapeSelector:()=>$,walkAST:()=>m});module.exports=T(D);var d=require("css-tree"),e=require("./constant.js"),O=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=e.REG_HEX.exec(n);if(f){const[,a]=f;let l;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),E=parseInt(a,e.HEX);E===0||E>=o&&E<=p?l=e.U_FFFD:l=String.fromCodePoint(E)}catch{l=e.U_FFFD}let c="";n.length>a.length&&(c=n.substring(a.length)),n=`${l}${c}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},g=(...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},u=s=>{if(s=g(s),e.REG_INVALID_SELECTOR.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;if(i==="Identifier is expected"&&e.REG_LANG_QUOTED.test(s)){const[,n,f]=e.REG_LANG_QUOTED.exec(s),a=f.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let l=n.replace(f,a);l===":lang()"&&(l=`:lang(${e.EMPTY})`),t=u(s.replace(n,l))}else if(/^(?:Identifier|Selector) is expected$/.test(i)&&e.REG_LOGICAL_EMPTY.test(s)){const[,n,f]=e.REG_LOGICAL_EMPTY.exec(s);t=u(s.replace(n,`:${f}(${e.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(i)&&!s.endsWith("]")){const n=s.lastIndexOf("["),f=s.substring(n);f.includes('"')?f.match(/"/g).length%2?t=u(`${s}"]`):t=u(`${s}]`):t=u(`${s}]`)}else if(i==='")" is expected'&&!s.endsWith(")"))t=u(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set,r=new Map;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)?(r.set("hasPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0)):n.name==="defined"&&r.set("hasDefinedPseudo",!0):n.type===e.SELECTOR_PSEUDO_ELEMENT?e.REG_SHADOW_PSEUDO.test(n.name)&&r.set("hasPseudoFunc",!0):n.type===e.NTH&&n.selector&&r.set("hasNthChildOfSelector",!0)}}),r.get("hasPseudoFunc")&&(0,d.findAll)(s,(n,f,a)=>{if(a){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const l=a.filter(c=>{const{name:o,type:p}=c;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:c}of l)for(const{children:o}of c)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 l=a.filter(c=>{const{name:o,type:p}=c;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:c}of l)for(const{children:o}of c)t.has(o)&&t.delete(o)}else if(n.type===e.NTH&&n.selector){const l=a.filter(c=>{const{selector:o,type:p}=c;return p===e.NTH&&o});for(const{selector:c}of l){const{children:o}=c;for(const{children:p}of o)t.has(p)&&t.delete(p)}}}}),{branches:[...t],info:Object.fromEntries(r)}},y=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,l=r.get(f),c=r.get(a);let o;return l===c?o=0:l>c?o=1:o=-1,o})}return t},w=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}},C=(s,t={})=>{if(!s||typeof s!="string")return!1;if(s.includes("[")){const r=s.lastIndexOf("[");if(s.substring(r).lastIndexOf("]")<0)return!1}if(/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(s))return!1;if(s.includes(":")){let r;if(e.REG_LOGICAL_KEY.test(s)){if(e.REG_LOGICAL_EMPTY.test(s))return!1;const{complex:i,descendant:n,qsa:f}=t;i&&n||f?r=e.REG_LOGICAL_COMPLEX:r=e.REG_LOGICAL_COMPOUND}else r=e.REG_CHILD_INDEXED;if(r.test(s))return!1}return!0};0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
var E=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var I=(s,t)=>{for(var r in t)E(s,r,{get:t[r],enumerable:!0})},L=(s,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!S.call(s,n)&&n!==r&&E(s,n,{get:()=>t[n],enumerable:!(i=_(t,n))||i.enumerable});return s};var T=s=>L(E({},"__esModule",{value:!0}),s);var D={};I(D,{filterSelector:()=>y,generateCSS:()=>O.generate,parseAstName:()=>C,parseSelector:()=>u,preprocess:()=>g,sortAST:()=>w,unescapeSelector:()=>$,walkAST:()=>m});module.exports=T(D);var d=require("css-tree"),e=require("./constant.js"),O=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 a=e.REG_HEX.exec(n);if(a){const[,l]=a;let f;try{const o=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),h=parseInt(l,e.HEX);h===0||h>=o&&h<=p?f=e.U_FFFD:f=String.fromCodePoint(h)}catch{f=e.U_FFFD}let c="";n.length>l.length&&(c=n.substring(l.length)),n=`${f}${c}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[i]=n}s=t.join("")}return s},g=(...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 a=n.codePointAt(0);if(a===e.BIT_HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(a>e.BIT_FFFF){const l=`\\${a.toString(e.HEX)} `;n.length===e.DUO?n=l:n=`${l}${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},u=s=>{if(s=g(s),e.REG_INVALID_SELECTOR.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;if(i==="Identifier is expected"&&e.REG_LANG_QUOTED.test(s)){const[,n,a]=e.REG_LANG_QUOTED.exec(s),l=a.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let f=n.replace(a,l);f===":lang()"&&(f=`:lang(${e.EMPTY})`),t=u(s.replace(n,f))}else if(/^(?:Identifier|Selector) is expected$/.test(i)&&e.REG_LOGICAL_EMPTY.test(s)){const[,n,a]=e.REG_LOGICAL_EMPTY.exec(s);t=u(s.replace(n,`:${a}(${e.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(i)&&!s.endsWith("]")){const n=s.lastIndexOf("["),a=s.substring(n);a.includes('"')?a.match(/"/g).length%2?t=u(`${s}"]`):t=u(`${s}]`):t=u(`${s}]`)}else if(i==='")" is expected'&&!s.endsWith(")"))t=u(`${s})`);else throw new DOMException(i,e.SYNTAX_ERR)}return t},m=(s={})=>{const t=new Set,r=new Map;return(0,d.walk)(s,{enter:n=>{switch(n.type){case e.SELECTOR:{t.add(n.children);break}case e.SELECTOR_PSEUDO_CLASS:{e.REG_LOGICAL_PSEUDO.test(n.name)?(r.set("hasPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0)):n.name==="defined"&&r.set("hasDefinedPseudo",!0);break}case e.SELECTOR_PSEUDO_ELEMENT:{e.REG_SHADOW_PSEUDO.test(n.name)&&r.set("hasPseudoFunc",!0);break}case e.SELECTOR_ATTR:{n.matcher==="|="&&r.set("hasHyphenSepAttr",!0);break}case e.NTH:{n.selector&&r.set("hasNthChildOfSelector",!0);break}default:}}}),r.get("hasPseudoFunc")&&(0,d.findAll)(s,(n,a,l)=>{if(l){if(n.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(n.name)){const f=l.filter(c=>{const{name:o,type:p}=c;return p===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:c}of f)for(const{children:o}of c)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 f=l.filter(c=>{const{name:o,type:p}=c;return p===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:c}of f)for(const{children:o}of c)t.has(o)&&t.delete(o)}else if(n.type===e.NTH&&n.selector){const f=l.filter(c=>{const{selector:o,type:p}=c;return p===e.NTH&&o});for(const{selector:c}of f){const{children:o}=c;for(const{children:p}of o)t.has(p)&&t.delete(p)}}}}),{branches:[...t],info:Object.fromEntries(r)}},w=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:a}=i,{type:l}=n,f=r.get(a),c=r.get(l);let o;return f===c?o=0:f>c?o=1:o=-1,o})}return t},C=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}},y=(s,t={})=>{if(!s||typeof s!="string")return!1;if(s.includes("[")){const r=s.lastIndexOf("[");if(s.substring(r).lastIndexOf("]")<0)return!1}if(/\||::|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]/.test(s))return!1;if(s.includes(":")){let r;if(e.REG_LOGICAL_KEY.test(s)){if(e.REG_LOGICAL_EMPTY.test(s))return!1;const{complex:i,descendant:n,qsa:a}=t;i&&n||a?r=e.REG_LOGICAL_COMPLEX:r=e.REG_LOGICAL_COMPOUND}else r=e.REG_CHILD_INDEXED;if(r.test(s))return!1}return!0};0&&(module.exports={filterSelector,generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST}); | ||
//# sourceMappingURL=parser.js.map |
@@ -63,3 +63,3 @@ { | ||
}, | ||
"version": "4.6.4" | ||
"version": "4.6.5" | ||
} |
@@ -190,19 +190,37 @@ /** | ||
enter: node => { | ||
if (node.type === SELECTOR) { | ||
branches.add(node.children); | ||
} else if (node.type === SELECTOR_PSEUDO_CLASS) { | ||
if (REG_LOGICAL_PSEUDO.test(node.name)) { | ||
info.set('hasPseudoFunc', true); | ||
if (node.name === 'has') { | ||
info.set('hasHasPseudoFunc', true); | ||
switch (node.type) { | ||
case SELECTOR: { | ||
branches.add(node.children); | ||
break; | ||
} | ||
case SELECTOR_PSEUDO_CLASS: { | ||
if (REG_LOGICAL_PSEUDO.test(node.name)) { | ||
info.set('hasPseudoFunc', true); | ||
if (node.name === 'has') { | ||
info.set('hasHasPseudoFunc', true); | ||
} | ||
} else if (node.name === 'defined') { | ||
info.set('hasDefinedPseudo', true); | ||
} | ||
} else if (node.name === 'defined') { | ||
info.set('hasDefinedPseudo', true); | ||
break; | ||
} | ||
} else if (node.type === SELECTOR_PSEUDO_ELEMENT) { | ||
if (REG_SHADOW_PSEUDO.test(node.name)) { | ||
info.set('hasPseudoFunc', true); | ||
case SELECTOR_PSEUDO_ELEMENT: { | ||
if (REG_SHADOW_PSEUDO.test(node.name)) { | ||
info.set('hasPseudoFunc', true); | ||
} | ||
break; | ||
} | ||
} else if (node.type === NTH && node.selector) { | ||
info.set('hasNthChildOfSelector', true); | ||
case SELECTOR_ATTR: { | ||
if (node.matcher === '|=') { | ||
info.set('hasHyphenSepAttr', true); | ||
} | ||
break; | ||
} | ||
case NTH: { | ||
if (node.selector) { | ||
info.set('hasNthChildOfSelector', true); | ||
} | ||
break; | ||
} | ||
default: | ||
} | ||
@@ -209,0 +227,0 @@ } |
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
432832
4849