@asamuzakjp/dom-selector 1.1.13 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -229,40 +229,40 @@ const dom = new JSDOM('', {
229
229
 
230
230
  ### Performance
231
231
 
232
- |Method / Selector|Jsdom v22.1.0 (nwsapi)|Patched-jsdom|Result|
233
- |:----------------|:----------------|:----------------|:----------------|
234
- |matches('p.content')|2,530,952 ops/sec ±1.00%|124,265 ops/sec ±0.29%|jsdom is 20.4 times faster. patched-jsdom took 0.008msec.|
235
- |matches('div.container:not(.box)')|1,428,470 ops/sec ±0.21%|84,209 ops/sec ±0.22%|jsdom is 17.0 times faster. patched-jsdom took 0.012msec.|
236
- |matches('.box + .box')|2,399,888 ops/sec ±0.40%|122,387 ops/sec ±0.89%|jsdom is 19.6 times faster. patched-jsdom took 0.008msec.|
237
- |matches('.box ~ .box')|2,413,472 ops/sec ±0.31%|123,989 ops/sec ±0.37%|jsdom is 19.5 times faster. patched-jsdom took 0.008msec.|
238
- |matches('.box > .block')|2,384,863 ops/sec ±0.86%|123,216 ops/sec ±0.22%|jsdom is 19.4 times faster. patched-jsdom took 0.008msec.|
239
- |matches('.box .content')|389,279 ops/sec ±0.41%|66,503 ops/sec ±0.22%|jsdom is 5.9 times faster. patched-jsdom took 0.015msec.|
240
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|176,289 ops/sec ±0.17%|14,955 ops/sec ±0.40%|jsdom is 11.8 times faster. patched-jsdom took 0.067msec.|
241
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|43,314 ops/sec ±0.63%|jsdom throws. patched-jsdom took 0.023msec.|
242
- |closest('p.content')|1,915,236 ops/sec ±0.48%|69,618 ops/sec ±0.22%|jsdom is 27.5 times faster. patched-jsdom took 0.014msec.|
243
- |closest('div.container:not(.box)')|274,786 ops/sec ±2.84%|37,163 ops/sec ±2.76%|jsdom is 7.4 times faster. patched-jsdom took 0.027msec.|
244
- |closest('.box + .box')|469,139 ops/sec ±1.66%|59,225 ops/sec ±1.11%|jsdom is 7.9 times faster. patched-jsdom took 0.017msec.|
245
- |closest('.box ~ .box')|175,439 ops/sec ±1.08%|36,372 ops/sec ±1.05%|jsdom is 4.8 times faster. patched-jsdom took 0.027msec.|
246
- |closest('.box > .block')|498,391 ops/sec ±1.06%|55,288 ops/sec ±1.38%|jsdom is 9.0 times faster. patched-jsdom took 0.018msec.|
247
- |closest('.box .content')|385,329 ops/sec ±1.39%|45,563 ops/sec ±0.11%|jsdom is 8.5 times faster. patched-jsdom took 0.022msec.|
248
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|168,574 ops/sec ±1.16%|13,326 ops/sec ±1.33%|jsdom is 12.6 times faster. patched-jsdom took 0.075msec.|
249
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|10,586 ops/sec ±1.66%|jsdom throws. patched-jsdom took 0.094msec.|
250
- |querySelector('p.content')|3,099 ops/sec ±0.78%|715 ops/sec ±1.11%|jsdom is 4.3 times faster. patched-jsdom took 1.398msec.|
251
- |querySelector('div.container:not(.box)')|84,572 ops/sec ±1.48%|24,515 ops/sec ±1.76%|jsdom is 3.4 times faster. patched-jsdom took 0.041msec.|
252
- |querySelector('.box + .box')|84,372 ops/sec ±1.18%|31,613 ops/sec ±1.67%|jsdom is 2.7 times faster. patched-jsdom took 0.032msec.|
253
- |querySelector('.box ~ .box')|86,031 ops/sec ±1.16%|10,133 ops/sec ±1.00%|jsdom is 8.5 times faster. patched-jsdom took 0.099msec.|
254
- |querySelector('.box > .block')|1,412 ops/sec ±1.69%|4,304 ops/sec ±1.19%|patched-jsdom is 3.0 times faster. patched-jsdom took 0.232msec.|
255
- |querySelector('.box .content')|716 ops/sec ±1.18%|901 ops/sec ±1.25%|patched-jsdom is 1.3 times faster. patched-jsdom took 1.109msec.|
256
- |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|272 ops/sec ±0.92%|845 ops/sec ±1.01%|patched-jsdom is 3.1 times faster. patched-jsdom took 1.183msec.|
257
- |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|679 ops/sec ±1.03%|jsdom throws. patched-jsdom took 1.472msec.|
258
- |querySelectorAll('p.content')|2,728 ops/sec ±0.92%|700 ops/sec ±1.07%|jsdom is 3.9 times faster. patched-jsdom took 1.428msec.|
259
- |querySelectorAll('div.container:not(.box)')|109,883 ops/sec ±1.08%|24,902 ops/sec ±0.18%|jsdom is 4.4 times faster. patched-jsdom took 0.040msec.|
260
- |querySelectorAll('.box + .box')|107,937 ops/sec ±1.10%|29,518 ops/sec ±1.90%|jsdom is 3.7 times faster. patched-jsdom took 0.034msec.|
261
- |querySelectorAll('.box ~ .box')|109,307 ops/sec ±1.13%|12,126 ops/sec ±1.29%|jsdom is 9.0 times faster. patched-jsdom took 0.082msec.|
262
- |querySelectorAll('.box > .block')|1,392 ops/sec ±0.92%|4,022 ops/sec ±1.55%|patched-jsdom is 2.9 times faster. patched-jsdom took 0.249msec.|
263
- |querySelectorAll('.box .content')|685 ops/sec ±1.06%|762 ops/sec ±1.28%|patched-jsdom is 1.1 times faster. patched-jsdom took 1.313msec.|
264
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|273 ops/sec ±0.78%|834 ops/sec ±1.46%|patched-jsdom is 3.1 times faster. patched-jsdom took 1.199msec.|
265
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|676 ops/sec ±0.90%|jsdom throws. patched-jsdom took 1.479msec.|
232
+ |method('selector')|jsdom v23.0.1 (nwsapi)|patched-jsdom (dom-selector)|Result|
233
+ |:-----------------|:-----------------|:-----------------|:-----------------|
234
+ |matches('p.content')|2,488,583 ops/sec ±0.53%|116,167 ops/sec ±0.45%|jsdom is 21.4 times faster. patched-jsdom took 0.009msec.|
235
+ |matches('div.container:not(.box)')|1,434,984 ops/sec ±0.81%|65,530 ops/sec ±0.32%|jsdom is 21.9 times faster. patched-jsdom took 0.015msec.|
236
+ |matches('.box + .box')|2,356,896 ops/sec ±0.35%|123,992 ops/sec ±1.80%|jsdom is 19.0 times faster. patched-jsdom took 0.008msec.|
237
+ |matches('.box ~ .box')|2,383,794 ops/sec ±1.66%|126,361 ops/sec ±1.71%|jsdom is 18.9 times faster. patched-jsdom took 0.008msec.|
238
+ |matches('.box > .block')|2,375,732 ops/sec ±1.72%|125,569 ops/sec ±1.60%|jsdom is 18.9 times faster. patched-jsdom took 0.008msec.|
239
+ |matches('.box .content')|392,589 ops/sec ±1.38%|66,923 ops/sec ±1.46%|jsdom is 5.9 times faster. patched-jsdom took 0.015msec.|
240
+ |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|180,656 ops/sec ±1.32%|18,095 ops/sec ±1.63%|jsdom is 10.0 times faster. patched-jsdom took 0.055msec.|
241
+ |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|27,379 ops/sec ±1.63%|jsdom throws. patched-jsdom took 0.037msec.|
242
+ |closest('p.content')|1,762,604 ops/sec ±1.66%|66,973 ops/sec ±1.39%|jsdom is 26.3 times faster. patched-jsdom took 0.015msec.|
243
+ |closest('div.container:not(.box)')|274,748 ops/sec ±2.04%|36,550 ops/sec ±2.18%|jsdom is 7.5 times faster. patched-jsdom took 0.027msec.|
244
+ |closest('.box + .box')|451,724 ops/sec ±0.23%|60,899 ops/sec ±1.59%|jsdom is 7.4 times faster. patched-jsdom took 0.016msec.|
245
+ |closest('.box ~ .box')|182,663 ops/sec ±1.45%|38,159 ops/sec ±1.49%|jsdom is 4.8 times faster. patched-jsdom took 0.026msec.|
246
+ |closest('.box > .block')|485,172 ops/sec ±1.46%|57,094 ops/sec ±1.52%|jsdom is 8.5 times faster. patched-jsdom took 0.018msec.|
247
+ |closest('.box .content')|369,453 ops/sec ±1.48%|47,294 ops/sec ±1.46%|jsdom is 7.8 times faster. patched-jsdom took 0.021msec.|
248
+ |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|174,341 ops/sec ±1.38%|16,067 ops/sec ±1.53%|jsdom is 10.9 times faster. patched-jsdom took 0.062msec.|
249
+ |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|12,062 ops/sec ±2.23%|jsdom throws. patched-jsdom took 0.083msec.|
250
+ |querySelector('p.content')|2,694 ops/sec ±0.92%|2,809 ops/sec ±0.94%|patched-jsdom is 1.0 times faster. patched-jsdom took 0.356msec.|
251
+ |querySelector('div.container:not(.box)')|83,924 ops/sec ±1.53%|45,590 ops/sec ±1.95%|jsdom is 1.8 times faster. patched-jsdom took 0.022msec.|
252
+ |querySelector('.box + .box')|87,433 ops/sec ±1.52%|77,785 ops/sec ±1.73%|jsdom is 1.1 times faster. patched-jsdom took 0.013msec.|
253
+ |querySelector('.box ~ .box')|88,269 ops/sec ±1.48%|76,784 ops/sec ±0.18%|jsdom is 1.1 times faster. patched-jsdom took 0.013msec.|
254
+ |querySelector('.box > .block')|1,360 ops/sec ±0.44%|2,493 ops/sec ±1.12%|patched-jsdom is 1.8 times faster. patched-jsdom took 0.401msec.|
255
+ |querySelector('.box .content')|709 ops/sec ±1.44%|2,719 ops/sec ±1.04%|patched-jsdom is 3.8 times faster. patched-jsdom took 0.368msec.|
256
+ |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|272 ops/sec ±1.61%|842 ops/sec ±1.17%|patched-jsdom is 3.1 times faster. patched-jsdom took 1.188msec.|
257
+ |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|675 ops/sec ±1.27%|jsdom throws. patched-jsdom took 1.481msec.|
258
+ |querySelectorAll('p.content')|2,441 ops/sec ±0.93%|375 ops/sec ±0.21%|jsdom is 6.5 times faster. patched-jsdom took 2.665msec.|
259
+ |querySelectorAll('div.container:not(.box)')|101,494 ops/sec ±0.25%|19,038 ops/sec ±1.59%|jsdom is 5.3 times faster. patched-jsdom took 0.053msec.|
260
+ |querySelectorAll('.box + .box')|101,742 ops/sec ±1.55%|29,586 ops/sec ±1.92%|jsdom is 3.4 times faster. patched-jsdom took 0.034msec.|
261
+ |querySelectorAll('.box ~ .box')|102,009 ops/sec ±1.39%|12,332 ops/sec ±1.68%|jsdom is 8.3 times faster. patched-jsdom took 0.081msec.|
262
+ |querySelectorAll('.box > .block')|1,314 ops/sec ±0.17%|3,817 ops/sec ±1.61%|patched-jsdom is 2.9 times faster. patched-jsdom took 0.262msec.|
263
+ |querySelectorAll('.box .content')|659 ops/sec ±0.94%|689 ops/sec ±1.54%|patched-jsdom is 1.0 times faster. patched-jsdom took 1.451msec.|
264
+ |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|275 ops/sec ±1.21%|827 ops/sec ±1.13%|patched-jsdom is 3.0 times faster. patched-jsdom took 1.210msec.|
265
+ |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|671 ops/sec ±0.17%|jsdom throws. patched-jsdom took 1.491msec.|
266
266
 
267
267
 
268
268
  ## Acknowledgments
@@ -1,2 +1,2 @@
1
- var O=Object.create;var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},E=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of h(t))!_.call(e,l)&&l!==i&&p(e,l,{get:()=>t[l],enumerable:!(s=g(t,l))||s.enumerable});return e};var v=(e,t,i)=>(i=e!=null?O(C(e)):{},E(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),w=e=>E(p({},"__esModule",{value:!0}),e);var A={};I(A,{getDirectionality:()=>N,getSlottedTextContent:()=>f,isContentEditable:()=>D,isInShadowTree:()=>x,isInclusive:()=>k,isNamespaceDeclared:()=>M,isPreceding:()=>P,selectorToNodeProps:()=>S});module.exports=w(A);var y=v(require("bidi-js"),1),r=require("./constant.js");const c=(0,y.default)(),x=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE||e.nodeType===r.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:s,mode:l,nodeType:n,parentNode:o}=i;if(s&&l&&n===r.DOCUMENT_FRAGMENT_NODE&&r.REG_SHADOW_MODE.test(l)){t=!0;break}i=o}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&x(e)){const i=e.assignedNodes();if(i.length){for(const s of i)if(t=s.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},N=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE){const{dir:i,localName:s,parentNode:l}=e,n=/^(?:ltr|rtl)$/;if(n.test(i))t=i;else if(i==="auto"){let o;switch(s){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(o=e.value);break}case"slot":{o=f(e);break}case"textarea":{o=e.value;break}default:{const a=[].slice.call(e.childNodes);for(const m of a){const{dir:u,localName:T,nodeType:d,textContent:b}=m;if(d===r.TEXT_NODE?o=b.trim():d===r.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(T)&&(!u||!n.test(u))&&(T==="slot"?o=f(m):o=b.trim()),o)break}}}if(o){const{paragraphs:[{level:a}]}=c.getEmbeddingLevels(o);a%2===1?t="rtl":t="ltr"}if(!t)if(l){const{nodeType:a}=l;a===r.ELEMENT_NODE?t=N(l):(a===r.DOCUMENT_NODE||a===r.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(s==="bdi"){const o=e.textContent.trim();if(o){const{paragraphs:[{level:a}]}=c.getEmbeddingLevels(o);a%2===1?t="rtl":t="ltr"}t||l||(t="ltr")}else if(s==="input"&&e.type==="tel")t="ltr";else if(l){if(s==="slot"){const o=f(e);if(o){const{paragraphs:[{level:a}]}=c.getEmbeddingLevels(o);a%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:o}=l;o===r.ELEMENT_NODE?t=N(l):(o===r.DOCUMENT_NODE||o===r.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},D=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const i=e.getAttribute("contenteditable");if(i===""||/^(?:plaintext-only|true)$/.test(i))t=!0;else if(i==="inherit"){let s=e.parentNode;for(;s;){if(D(s)){t=!0;break}s=s.parentNode}}}}return!!t},M=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===r.ELEMENT_NODE){const s=`xmlns:${e}`,l=t.ownerDocument.documentElement;let n=t;for(;n;){if(typeof n.hasAttribute=="function"&&n.hasAttribute(s)){i=!0;break}else if(n===l)break;n=n.parentNode}}return!!i},k=(e={},t={})=>{let i;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE){const s=t.compareDocumentPosition(e);i=s&r.DOCUMENT_POSITION_CONTAINS||s&r.DOCUMENT_POSITION_CONTAINED_BY}return!!i},P=(e={},t={})=>{let i;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE){const s=t.compareDocumentPosition(e);i=s&r.DOCUMENT_POSITION_PRECEDING||s&r.DOCUMENT_POSITION_CONTAINS}return!!i},S=(e,t)=>{let i,s;if(e&&typeof e=="string")e.indexOf("|")>-1?[i,s]=e.split("|"):(i="*",s=e);else throw new DOMException(`Invalid selector ${e}`,r.SYNTAX_ERR);return{prefix:i,tagName:s}};0&&(module.exports={getDirectionality,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,selectorToNodeProps});
1
+ var O=Object.create;var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var i in t)f(e,i,{get:t[i],enumerable:!0})},b=(e,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of C(t))!_.call(e,l)&&l!==i&&f(e,l,{get:()=>t[l],enumerable:!(o=h(t,l))||o.enumerable});return e};var w=(e,t,i)=>(i=e!=null?O(g(e)):{},b(t||!e||!e.__esModule?f(i,"default",{value:e,enumerable:!0}):i,e)),M=e=>b(f({},"__esModule",{value:!0}),e);var A={};I(A,{getDirectionality:()=>N,getSlottedTextContent:()=>c,isContentEditable:()=>D,isInShadowTree:()=>x,isInclusive:()=>v,isNamespaceDeclared:()=>k,isPreceding:()=>P,selectorToNodeProps:()=>S});module.exports=M(A);var E=w(require("bidi-js"),1),r=require("./constant.js");const x=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE||e.nodeType===r.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:o,mode:l,nodeType:n,parentNode:p}=i;if(o&&l&&n===r.DOCUMENT_FRAGMENT_NODE&&r.REG_SHADOW_MODE.test(l)){t=!0;break}i=p}}return!!t},c=(e={})=>{let t;if(e.localName==="slot"&&x(e)){const i=e.assignedNodes();if(i.length){for(const o of i)if(t=o.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},N=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE){const{dir:i,localName:o,parentNode:l}=e,{getEmbeddingLevels:n}=(0,E.default)(),p=/^(?:ltr|rtl)$/;if(p.test(i))t=i;else if(i==="auto"){let s;switch(o){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(s=e.value);break}case"slot":{s=c(e);break}case"textarea":{s=e.value;break}default:{const a=[].slice.call(e.childNodes);for(const u of a){const{dir:m,localName:T,nodeType:d,textContent:y}=u;if(d===r.TEXT_NODE?s=y.trim():d===r.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(T)&&(!m||!p.test(m))&&(T==="slot"?s=c(u):s=y.trim()),s)break}}}if(s){const{paragraphs:[{level:a}]}=n(s);a%2===1?t="rtl":t="ltr"}if(!t)if(l){const{nodeType:a}=l;a===r.ELEMENT_NODE?t=N(l):(a===r.DOCUMENT_NODE||a===r.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(o==="bdi"){const s=e.textContent.trim();if(s){const{paragraphs:[{level:a}]}=n(s);a%2===1?t="rtl":t="ltr"}t||l||(t="ltr")}else if(o==="input"&&e.type==="tel")t="ltr";else if(l){if(o==="slot"){const s=c(e);if(s){const{paragraphs:[{level:a}]}=n(s);a%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:s}=l;s===r.ELEMENT_NODE?t=N(l):(s===r.DOCUMENT_NODE||s===r.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},D=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const i=e.getAttribute("contenteditable");if(i===""||/^(?:plaintext-only|true)$/.test(i))t=!0;else if(i==="inherit"){let o=e.parentNode;for(;o;){if(D(o)){t=!0;break}o=o.parentNode}}}}return!!t},k=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===r.ELEMENT_NODE){const o=`xmlns:${e}`,l=t.ownerDocument.documentElement;let n=t;for(;n;){if(typeof n.hasAttribute=="function"&&n.hasAttribute(o)){i=!0;break}else if(n===l)break;n=n.parentNode}}return!!i},v=(e={},t={})=>{let i;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE){const o=t.compareDocumentPosition(e);i=o&r.DOCUMENT_POSITION_CONTAINS||o&r.DOCUMENT_POSITION_CONTAINED_BY}return!!i},P=(e={},t={})=>{let i;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE){const o=t.compareDocumentPosition(e);i=o&r.DOCUMENT_POSITION_PRECEDING||o&r.DOCUMENT_POSITION_CONTAINS}return!!i},S=(e,t)=>{let i,o;if(e&&typeof e=="string")e.indexOf("|")>-1?[i,o]=e.split("|"):(i="*",o=e);else throw new DOMException(`Invalid selector ${e}`,r.SYNTAX_ERR);return{prefix:i,tagName:o}};0&&(module.exports={getDirectionality,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,selectorToNodeProps});
2
2
  //# sourceMappingURL=dom-util.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/dom-util.js"],
4
- "sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n REG_SHADOW_MODE, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\n\n/* bidi */\nconst bidi = bidiFactory();\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = (node = {}) => {\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = (node = {}) => {\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const regDir = /^(?:ltr|rtl)$/;\n if (regDir.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type)) {\n text = node.value;\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(itemLocalName) &&\n (!itemDir || !regDir.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = bidi.getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = bidi.getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = bidi.getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n const attr = `xmlns:${ns}`;\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n if (typeof parent.hasAttribute === 'function' &&\n parent.hasAttribute(attr)) {\n res = true;\n break;\n } else if (parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n return !!res;\n};\n\n/**\n * is inclusive - nodeA and nodeB are in inclusive relation\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isInclusive = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_CONTAINS ||\n posBit & DOCUMENT_POSITION_CONTAINED_BY;\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * selector to node properties - e.g. ns|E -> { prefix: ns, tagName: E }\n * @param {string} selector - type selector\n * @param {object} [node] - Element node\n * @returns {object} - node properties\n */\nexport const selectorToNodeProps = (selector, node) => {\n let prefix;\n let tagName;\n if (selector && typeof selector === 'string') {\n if (selector.indexOf('|') > -1) {\n [prefix, tagName] = selector.split('|');\n } else {\n prefix = '*';\n tagName = selector;\n }\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return {\n prefix,\n tagName\n };\n};\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAA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AAWE,EACpB,MAEFF,EAASA,EAAO,UAClB,CACF,CACA,MAAO,CAAC,CAACf,CACX,EAQahB,EAAc,CAACkC,EAAQ,CAAC,EAAGC,EAAQ,CAAC,IAAM,CACrD,IAAInB,EACJ,GAAIkB,EAAM,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDlB,EAAMoB,EAAS,8BACTA,EAAS,gCACjB,CACA,MAAO,CAAC,CAACpB,CACX,EAQad,EAAc,CAACgC,EAAQ,CAAC,EAAGC,EAAQ,CAAC,IAAM,CACrD,IAAInB,EACJ,GAAIkB,EAAM,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDlB,EAAMoB,EAAS,+BACTA,EAAS,4BACjB,CACA,MAAO,CAAC,CAACpB,CACX,EAQab,EAAsB,CAACkC,EAAU5B,IAAS,CACrD,IAAI6B,EACAC,EACJ,GAAIF,GAAY,OAAOA,GAAa,SAC9BA,EAAS,QAAQ,GAAG,EAAI,GAC1B,CAACC,EAAQC,CAAO,EAAIF,EAAS,MAAM,GAAG,GAEtCC,EAAS,IACTC,EAAUF,OAGZ,OAAM,IAAI,aAAa,oBAAoBA,CAAQ,GAAI,YAAU,EAEnE,MAAO,CACL,OAAAC,EACA,QAAAC,CACF,CACF",
6
- "names": ["dom_util_exports", "__export", "getDirectionality", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isInclusive", "isNamespaceDeclared", "isPreceding", "selectorToNodeProps", "__toCommonJS", "import_bidi_js", "import_constant", "bidi", "bidiFactory", "node", "bool", "refNode", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "regDir", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "attr", "parent", "ns", "root", "nodeA", "nodeB", "posBit", "selector", "prefix", "tagName"]
4
+ "sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n REG_SHADOW_MODE, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = (node = {}) => {\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = (node = {}) => {\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n const regDir = /^(?:ltr|rtl)$/;\n if (regDir.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type)) {\n text = node.value;\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(itemLocalName) &&\n (!itemDir || !regDir.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n const attr = `xmlns:${ns}`;\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n if (typeof parent.hasAttribute === 'function' &&\n parent.hasAttribute(attr)) {\n res = true;\n break;\n } else if (parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n return !!res;\n};\n\n/**\n * is inclusive - nodeA and nodeB are in inclusive relation\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isInclusive = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_CONTAINS ||\n posBit & DOCUMENT_POSITION_CONTAINED_BY;\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * selector to node properties - e.g. ns|E -> { prefix: ns, tagName: E }\n * @param {string} selector - type selector\n * @param {object} [node] - Element node\n * @returns {object} - node properties\n */\nexport const selectorToNodeProps = (selector, node) => {\n let prefix;\n let tagName;\n if (selector && typeof selector === 'string') {\n if (selector.indexOf('|') > -1) {\n [prefix, tagName] = selector.split('|');\n } else {\n prefix = '*';\n tagName = selector;\n }\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return {\n prefix,\n tagName\n };\n};\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAV,GAKA,IAAAW,EAAwB,wBAGxBC,EAIO,yBAOA,MAAMP,EAAiB,CAACQ,EAAO,CAAC,IAAM,CAC3C,IAAIC,EACJ,GAAID,EAAK,WAAa,gBAClBA,EAAK,WAAa,yBAAwB,CAC5C,IAAIE,EAAUF,EACd,KAAOE,GAAS,CACd,KAAM,CAAE,KAAAC,EAAM,KAAAC,EAAM,SAAAC,EAAU,WAAAC,CAAW,EAAIJ,EAC7C,GAAIC,GAAQC,GAAQC,IAAa,0BAC7B,kBAAgB,KAAKD,CAAI,EAAG,CAC9BH,EAAO,GACP,KACF,CACAC,EAAUI,CACZ,CACF,CACA,MAAO,CAAC,CAACL,CACX,EAOaX,EAAwB,CAACU,EAAO,CAAC,IAAM,CAClD,IAAIO,E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I+B,EACAC,EACJ,GAAIF,GAAY,OAAOA,GAAa,SAC9BA,EAAS,QAAQ,GAAG,EAAI,GAC1B,CAACC,EAAQC,CAAO,EAAIF,EAAS,MAAM,GAAG,GAEtCC,EAAS,IACTC,EAAUF,OAGZ,OAAM,IAAI,aAAa,oBAAoBA,CAAQ,GAAI,YAAU,EAEnE,MAAO,CACL,OAAAC,EACA,QAAAC,CACF,CACF",
6
+ "names": ["dom_util_exports", "__export", "getDirectionality", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isInclusive", "isNamespaceDeclared", "isPreceding", "selectorToNodeProps", "__toCommonJS", "import_bidi_js", "import_constant", "node", "bool", "refNode", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "getEmbeddingLevels", "bidiFactory", "regDir", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "attr", "parent", "ns", "root", "nodeA", "nodeB", "posBit", "selector", "prefix", "tagName"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var F=Object.create;var R=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var G=(v,s)=>{for(var e in s)R(v,e,{get:s[e],enumerable:!0})},z=(v,s,e,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of j(s))!W.call(v,h)&&h!==e&&R(v,h,{get:()=>s[h],enumerable:!(n=V(s,h))||n.enumerable});return v};var q=(v,s,e)=>(e=v!=null?F(H(v)):{},z(s||!v||!v.__esModule?R(e,"default",{value:v,enumerable:!0}):e,v)),X=v=>z(R({},"__esModule",{value:!0}),v);var J={};G(J,{Matcher:()=>Y});module.exports=X(J);var B=q(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),k=require("./parser.js"),r=require("./constant.js");const M="next",U="prev",I="all",C="first",D="lineal",P="self";class Y{#i;#r;#a;#e;#l;#t;#o;#s;constructor(s,e,n={}){const{warn:h}=n;this.#r=new Map([[r.SELECTOR_PSEUDO_ELEMENT,r.BIT_01],[r.SELECTOR_ID,r.BIT_02],[r.SELECTOR_CLASS,r.BIT_04],[r.SELECTOR_TYPE,r.BIT_08],[r.SELECTOR_ATTR,r.BIT_16],[r.SELECTOR_PSEUDO_CLASS,r.BIT_32]]),this.#a=new WeakMap,this.#o=s,this.#e=e,this.#s=!!h,[this.#i,this.#l]=this._prepare(s),this.#t=this._getRoot(e)}_onError(s){if(s instanceof DOMException&&s.name===r.NOT_SUPPORTED_ERR)this.#s&&console.warn(s.message);else throw s}_getRoot(s=this.#e){let e,n;switch(s.nodeType){case r.DOCUMENT_NODE:{e=s,n=s;break}case r.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,n=s;break}case r.ELEMENT_NODE:{if(s.ownerDocument.contains(s))e=s.ownerDocument,n=s.ownerDocument;else{let l=s;for(;l&&l.parentNode;)l=l.parentNode;e=l.ownerDocument,n=l}break}default:throw new TypeError(`Unexpected node ${s.nodeName}`)}const h=(0,E.isInShadowTree)(s);return{document:e,root:n,shadow:h}}_sortLeaves(s){const e=[...s];return e.length>1&&e.sort((n,h)=>{const{type:l}=n,{type:u}=h,m=this.#r.get(l),f=this.#r.get(u);let t;return m===f?t=0:m>f?t=1:t=-1,t}),e}_prepare(s=this.#o){const e=(0,k.parseSelector)(s),n=(0,k.walkAST)(e),h=[],l=[];let u=0;for(const[...m]of n){const f=[];let t=m.shift();if(t&&t.type!==r.COMBINATOR){const i=new Set;for(;t;){if(t.type===r.COMBINATOR){const[o]=m;if(o.type===r.COMBINATOR){const b=`Invalid combinator ${t.name}${o.name}`;throw new DOMException(b,r.SYNTAX_ERR)}f.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(m.length)t=m.shift();else{f.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}h.push({branch:f,find:null,skip:!1}),l[u]=new Set,u++}return[h,l]}_collectNthChild(s,e){const{a:n,b:h,reverse:l,selector:u}=s,{parentNode:m}=e,f=new Set;let t;if(u&&(this.#a.has(u)?t=this.#a.get(u):(t=(0,k.walkAST)(u),this.#a.set(u,t))),m){const i=[].slice.call(m.children),o=i.length;if(o){const b=new Set;if(t){const a=t.length;for(const c of i){let d;for(let p=0;p<a;p++){const N=t[p];if(d=this._matchLeaves(N,c),!d)break}d&&b.add(c)}}if(l&&i.reverse(),n===0){if(h>0&&h<=o){if(b.size)for(let a=0;a<o;a++){const c=i[a];if(b.has(c)){f.add(c);break}}else if(!u){const a=i[h-1];f.add(a)}}}else{let a=h-1;if(n>0)for(;a<0;)a+=n;if(a>=0&&a<o){let c=n>0?0:h-1;for(let d=0;d<o&&a>=0&&a<o;d++){const p=i[d];b.size?b.has(p)&&(c===a&&(f.add(p),a+=n),n>0?c++:c--):d===a&&(u||f.add(p),a+=n)}}}}}else{const{root:i}=this.#t;if(e===i&&i.nodeType===r.ELEMENT_NODE&&n+h===1)if(t){const o=t.length;let b;for(let a=0;a<o;a++){const c=t[a];if(b=this._matchLeaves(c,e),b)break}b&&f.add(e)}else f.add(e)}return f}_collectNthOfType(s,e){const{a:n,b:h,reverse:l}=s,{localName:u,parentNode:m,prefix:f}=e,t=new Set;if(m){const i=[].slice.call(m.children),o=i.length;if(o)if(l&&i.reverse(),n===0){if(h>0&&h<=o){let b=0;for(let a=0;a<o;a++){const c=i[a],{localName:d,prefix:p}=c;if(d===u&&p===f){if(b===h-1){t.add(c);break}b++}}}}else{let b=h-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<o){let a=n>0?0:h-1;for(let c=0;c<o;c++){const d=i[c],{localName:p,prefix:N}=d;if(p===u&&N===f){if(a===b&&(t.add(d),b+=n),b<0||b>=o)break;n>0?a++:a--}}}}}else{const{root:i}=this.#t;e===i&&i.nodeType===r.ELEMENT_NODE&&n+h===1&&t.add(e)}return t}_matchAnPlusB(s,e,n){const{nth:{a:h,b:l,name:u},selector:m}=s,f=(0,k.unescapeSelector)(u),t=new Map;f?(f==="even"?(t.set("a",2),t.set("b",0)):f==="odd"&&(t.set("a",2),t.set("b",1)),n.indexOf("last")>-1&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?t.set("b",l*1):t.set("b",0),n.indexOf("last")>-1&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(n)){m&&t.set("selector",m);const o=Object.fromEntries(t),b=this._collectNthChild(o,e);b.size&&(i=b)}else if(/^nth-(?:last-)?of-type$/.test(n)){const o=Object.fromEntries(t),b=this._collectNthOfType(o,e);b.size&&(i=b)}}return i}_matchPseudoElementSelector(s,e={}){const{forgive:n}=e;switch(s){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,r.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}()`,r.NOT_SUPPORTED_ERR);break}default:if(s.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,r.NOT_SUPPORTED_ERR)}else if(!n)throw new DOMException(`Unknown pseudo-element ::${s}`,r.SYNTAX_ERR)}}_matchDirectionPseudoClass(s,e){const n=(0,k.unescapeSelector)(s.name),h=(0,E.getDirectionality)(e);let l;return n===h&&(l=e),l??null}_matchLanguagePseudoClass(s,e){const n=(0,k.unescapeSelector)(s.name);let h;if(n)if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let l=e.parentNode;for(;l&&l.nodeType===r.ELEMENT_NODE;){if(l.hasAttribute("lang")){l.getAttribute("lang")&&(h=e);break}l=l.parentNode}}else{const l=`(?:-${r.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${r.ALPHA_NUM}${l}$`,"i").test(n)){let m;if(n.indexOf("-")>-1){const[f,t,...i]=n.split("-");let o;f==="*"?o=`${r.ALPHA_NUM}${l}`:o=`${f}${l}`;const b=`-${t}${l}`,a=i.length;let c="";if(a)for(let d=0;d<a;d++)c+=`-${i[d]}${l}`;m=new RegExp(`^${o}${b}${c}$`,"i")}else m=new RegExp(`^${n}${l}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(h=e);else{let f=e.parentNode;for(;f&&f.nodeType===r.ELEMENT_NODE;){if(f.hasAttribute("lang")){const t=f.getAttribute("lang");m.test(t)&&(h=e);break}f=f.parentNode}}}}return h??null}_matchHasPseudoFunc(s,e){let n;if(Array.isArray(s)&&s.length){const[h]=s,{type:l}=h;let u;l===r.COMBINATOR?u=s.shift():u={name:" ",type:r.COMBINATOR};const m=[];for(;s.length;){const[i]=s,{type:o}=i;if(o===r.COMBINATOR)break;m.push(s.shift())}const f={combo:u,leaves:m},t=this._matchCombinator(f,e,{find:M});if(t.size)if(s.length){for(const i of t)if(n=this._matchHasPseudoFunc(Object.assign([],s),i),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(s,e){const{astName:n="",branches:h=[],selector:l="",twigBranches:u=[]}=s;let m;if(n==="has")if(l.includes(":has("))m=null;else{const f=h.length;let t;for(let i=0;i<f;i++){const o=h[i];if(t=this._matchHasPseudoFunc(Object.assign([],o),e),t)break}t&&(m=e)}else{const f=/^(?:is|where)$/.test(n),t=u.length;let i;for(let o=0;o<t;o++){const b=u[o],a=b.length-1,{leaves:c}=b[a];if(i=this._matchLeaves(c,e,{forgive:f}),i&&a>0){let d=new Set([e]);for(let p=a-1;p>=0;p--){const N=b[p],y=[];for(const x of d){const L=this._matchCombinator(N,x,{forgive:f,find:U});L.size&&y.push(...L)}if(y.length)if(p===0){i=!0;break}else d=new Set(y);else{i=!1;break}}}if(i)break}n==="not"?i||(m=e):i&&(m=e)}return m??null}_matchPseudoClassSelector(s,e,n={}){const{children:h}=s,{localName:l,parentNode:u}=e,{forgive:m}=n,f=(0,k.unescapeSelector)(s.name);let t=new Set;if(r.REG_LOGICAL_PSEUDO.test(f)){let i;if(this.#a.has(s))i=this.#a.get(s);else{const b=(0,k.walkAST)(s),a=[],c=[];for(const[...d]of b){for(const x of d){const L=(0,k.generateCSS)(x);a.push(L)}const p=[],N=new Set;let y=d.shift();for(;y;)if(y.type===r.COMBINATOR?(p.push({combo:y,leaves:[...N]}),N.clear()):y&&N.add(y),d.length)y=d.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}c.push(p)}i={astName:f,branches:b,twigBranches:c,selector:a.join(",")},this.#a.set(s,i)}const o=this._matchLogicalPseudoFunc(i,e);o&&t.add(o)}else if(Array.isArray(h)){const[i]=h;if(/^nth-(?:last-)?(?:child|of-type)$/.test(f)){const o=this._matchAnPlusB(i,e,f);o.size&&(t=o)}else if(f==="dir"){const o=this._matchDirectionPseudoClass(i,e);o&&t.add(o)}else if(f==="lang"){const o=this._matchLanguagePseudoClass(i,e);o&&t.add(o)}else switch(f){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}()`,r.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;default:if(!m)throw new DOMException(`Unknown pseudo-class :${f}()`,r.SYNTAX_ERR)}}else{const{document:i,root:o}=this.#t,{documentElement:b}=i,a=new URL(i.URL),c=/^a(?:rea)?$/,d=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,p=/^(?:(?:inpu|selec)t|button|form|textarea)$/,N=/^d(?:etails|ialog)$/,y=/^(?:checkbox|radio)$/,x=/^(?:date(?:time-local)?|month|time|week)$/,L=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,$=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(f){case"any-link":case"link":{c.test(l)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(c.test(l)&&e.hasAttribute("href")){const w=new URL(e.getAttribute("href"),a.href);w.origin===a.origin&&w.pathname===a.pathname&&t.add(e)}break}case"visited":break;case"target":{e.id&&a.hash&&a.hash===`#${e.id}`&&i.contains(e)&&t.add(e);break}case"target-within":{if(a.hash){const w=a.hash.replace(/^#/,"");let g=i.getElementById(w);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===r.ELEMENT_NODE?e===this.#e&&t.add(e):e===b&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let w=i.activeElement;for(;w;){if(w===e){t.add(e);break}w=w.parentNode}break}case"open":{N.test(l)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{N.test(l)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(d.test(l)||(0,B.default)(l))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let w=u;for(;w&&w.localName!=="fieldset";)w=w.parentNode;w&&u.localName!=="legend"&&w.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(d.test(l)||(0,B.default)(l))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||$.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||$.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let w;l==="textarea"?w=e:l==="input"&&(e.hasAttribute("type")?$.test(e.getAttribute("type"))&&(w=e):w=e),w&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&y.test(e.getAttribute("type"))||e.selected&&l==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))t.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const w=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=b);const _=[].slice.call(g.getElementsByTagName("input"));let T;for(const A of _)if(A.getAttribute("type")==="radio"&&(w?A.getAttribute("name")===w&&(T=!!A.checked):A.hasAttribute("name")||(T=!!A.checked),T))break;T||t.add(e)}break}case"default":{const w=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(l==="button"&&!(e.hasAttribute("type")&&w.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let _=e.parentNode;for(;_&&_.localName!=="form";)_=_.parentNode;if(_){const T=i.createNodeIterator(_,r.SHOW_ELEMENT);let A=T.nextNode();for(;A;){const O=A.localName;let S;if(O==="button"?S=!(A.hasAttribute("type")&&w.test(A.getAttribute("type"))):O==="input"&&(S=A.hasAttribute("type")&&g.test(A.getAttribute("type"))),S){A===e&&t.add(e);break}A=T.nextNode()}}}else if(l==="input"&&e.hasAttribute("type")&&y.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(l==="option"){let _=!1,T=u;for(;T&&T.localName!=="datalist";){if(T.localName==="select"){(T.multiple||T.hasAttribute("multiple"))&&(_=!0);break}T=T.parentNode}if(_)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const A=u.firstElementChild,O=new Set;let S=A;for(;S;){if(S.selected||S.hasAttribute("selected")){O.add(S);break}S=S.nextElementSibling}O.size||O.add(A),O.has(e)&&t.add(e)}}break}case"valid":{if(p.test(l))e.checkValidity()&&t.add(e);else if(l==="fieldset"){const w=i.createNodeIterator(e,r.SHOW_ELEMENT);let g=w.nextNode();g===e&&(g=w.nextNode());let _;for(;g&&!(p.test(g.localName)&&(_=g.checkValidity(),!_));)g=w.nextNode();_&&t.add(e)}break}case"invalid":{if(p.test(l))e.checkValidity()||t.add(e);else if(l==="fieldset"){const w=i.createNodeIterator(e,r.SHOW_ELEMENT);let g=w.nextNode();g===e&&(g=w.nextNode());let _;for(;g&&!(p.test(g.localName)&&(_=g.checkValidity(),!_));)g=w.nextNode();_||t.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let w;if(/^(?:select|textarea)$/.test(l))w=e;else if(l==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||y.test(g)||x.test(g)||$.test(g))&&(w=e)}else w=e;w&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let w;if(/^(?:select|textarea)$/.test(l))w=e;else if(l==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||y.test(g)||x.test(g)||$.test(g))&&(w=e)}else w=e;w&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===b&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const w=e.childNodes.values();let g;for(const _ of w)if(g=_.nodeType!==r.ELEMENT_NODE&&_.nodeType!==r.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(u&&e===u.firstElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(u&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(u&&e===u.firstElementChild&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1},e);w&&t.add(w)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w&&t.add(w)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1},e);if(w===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${f}`,r.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,r.NOT_SUPPORTED_ERR);break}default:if(f.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,r.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${f}`,r.SYNTAX_ERR)}}return t}_matchAttributeSelector(s,e){const{flags:n,matcher:h,name:l,value:u}=s;if(typeof n=="string"&&!/^[is]$/i.test(n)){const t=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${t}`,r.SYNTAX_ERR)}const{attributes:m}=e;let f;if(m&&m.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof n=="string"&&/^s$/i.test(n)?i=!1:i=!0:typeof n=="string"&&/^i$/i.test(n)?i=!0:i=!1;let o=(0,k.unescapeSelector)(l.name);i&&(o=o.toLowerCase());const b=new Set;if(o.indexOf("|")>-1){const{prefix:a,tagName:c}=(0,E.selectorToNodeProps)(o);for(let{name:d,value:p}of m)switch(i&&(d=d.toLowerCase(),p=p.toLowerCase()),a){case"":{c===d&&b.add(p);break}case"*":{d.indexOf(":")>-1?d.endsWith(`:${c}`)&&b.add(p):c===d&&b.add(p);break}default:if(d.indexOf(":")>-1){const[N,y]=d.split(":");a===N&&c===y&&(0,E.isNamespaceDeclared)(a,e)&&b.add(p)}}}else for(let{name:a,value:c}of m)if(i&&(a=a.toLowerCase(),c=c.toLowerCase()),a.indexOf(":")>-1){const[d,p]=a.split(":");if(d==="xml"&&p==="lang")continue;o===p&&b.add(c)}else o===a&&b.add(c);if(b.size){const{name:a,value:c}=u||{};let d;switch(a?i?d=a.toLowerCase():d=a:c?i?d=c.toLowerCase():d=c:c===""&&(d=c),h){case"=":{typeof d=="string"&&b.has(d)&&(f=e);break}case"~=":{if(d&&typeof d=="string"){for(const p of b)if(new Set(p.split(/\s+/)).has(d)){f=e;break}}break}case"|=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N===d||N.startsWith(`${d}-`)){p=N;break}p&&(f=e)}break}case"^=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.startsWith(`${d}`)){p=N;break}p&&(f=e)}break}case"$=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.endsWith(`${d}`)){p=N;break}p&&(f=e)}break}case"*=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.includes(`${d}`)){p=N;break}p&&(f=e)}break}case null:default:f=e}}}return f??null}_matchClassSelector(s,e){const n=(0,k.unescapeSelector)(s.name);let h;return e.classList.contains(n)&&(h=e),h??null}_matchIDSelector(s,e){const n=(0,k.unescapeSelector)(s.name),{id:h}=e;let l;return n===h&&(l=e),l??null}_matchTypeSelector(s,e,n={}){const h=(0,k.unescapeSelector)(s.name),{localName:l,prefix:u}=e,{forgive:m}=n,{document:f}=this.#t;let{prefix:t,tagName:i}=(0,E.selectorToNodeProps)(h,e);f.contentType==="text/html"&&(t=t.toLowerCase(),i=i.toLowerCase());let o,b;l.indexOf(":")>-1?[o,b]=l.split(":"):(o=u||"",b=l);let a;if(t===""&&o==="")e.namespaceURI===null&&(i==="*"||i===b)&&(a=e);else if(t==="*")(i==="*"||i===b)&&(a=e);else if(t===o){if((0,E.isNamespaceDeclared)(t,e))(i==="*"||i===b)&&(a=e);else if(!m)throw new DOMException(`Undeclared namespace ${t}`,r.SYNTAX_ERR)}else if(t&&!m&&!(0,E.isNamespaceDeclared)(t,e))throw new DOMException(`Undeclared namespace ${t}`,r.SYNTAX_ERR);return a??null}_matchShadowHostPseudoClass(s,e){const{children:n}=s,h=(0,k.unescapeSelector)(s.name);let l;if(Array.isArray(n)){const[u]=(0,k.walkAST)(n[0]),[...m]=u,{host:f}=e;if(h==="host"){let t;for(const i of m){const{type:o}=i;if(o===r.COMBINATOR){const b=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${b}`,r.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}t&&(l=e)}else if(h==="host-context"){let t=f,i;for(;t;){for(const o of m){const{type:b}=o;if(b===r.COMBINATOR){const a=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${a}`,r.SYNTAX_ERR)}if(i=this._matchSelector(o,t).has(t),!i)break}if(i)break;t=t.parentNode}i&&(l=e)}}else if(h==="host")l=e;else throw new DOMException(`Invalid selector :${h}`,r.SYNTAX_ERR);return l??null}_matchSelector(s,e,n){const{type:h}=s,l=(0,k.unescapeSelector)(s.name),{shadow:u}=this.#t;let m=new Set;if(e.nodeType===r.ELEMENT_NODE)switch(h){case r.SELECTOR_ATTR:{const f=this._matchAttributeSelector(s,e);f&&m.add(f);break}case r.SELECTOR_CLASS:{const f=this._matchClassSelector(s,e);f&&m.add(f);break}case r.SELECTOR_ID:{const f=this._matchIDSelector(s,e);f&&m.add(f);break}case r.SELECTOR_PSEUDO_CLASS:{const f=this._matchPseudoClassSelector(s,e,n);f.size&&(m=f);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(l,n);break}case r.SELECTOR_TYPE:default:{const f=this._matchTypeSelector(s,e,n);f&&m.add(f)}}else if(u&&h===r.SELECTOR_PSEUDO_CLASS&&e.nodeType===r.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&r.REG_LOGICAL_PSEUDO.test(l)){const f=this._matchPseudoClassSelector(s,e,n);f.size&&(m=f)}else if(r.REG_SHADOW_HOST.test(l)){const f=this._matchShadowHostPseudoClass(s,e);f&&m.add(f)}}return m}_matchLeaves(s,e,n){let h;for(const l of s)if(h=this._matchSelector(l,e,n).has(e),!h)break;return!!h}_findDescendantNodes(s,e){const[n,...h]=s,{type:l}=n,u=(0,k.unescapeSelector)(n.name),m=h.length>0,{document:f,root:t,shadow:i}=this.#t;let o=new Set,b=!1;if(i)b=!0;else switch(l){case r.SELECTOR_ID:{if(t.nodeType===r.ELEMENT_NODE)b=!0;else{const a=t.getElementById(u);a&&a!==e&&e.contains(a)&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a))}break}case r.SELECTOR_CLASS:{const a=[].slice.call(e.getElementsByClassName(u));if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_TYPE:{if(f.contentType==="text/html"&&!/[*|]/.test(u)){const a=[].slice.call(e.getElementsByTagName(u));if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a)}else b=!0;break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:b=!0}return{nodes:o,pending:b}}_matchCombinator(s,e,n={}){const{combo:h,leaves:l}=s,{name:u}=h,{find:m,forgive:f}=n;let t=new Set;if(m===M)switch(u){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(l,i,{forgive:f})&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(l,i,{forgive:f})&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[].slice.call(e.children);for(const o of i)this._matchLeaves(l,o,{forgive:f})&&t.add(o);break}case" ":default:{const{nodes:i,pending:o}=this._findDescendantNodes(l,e);if(i.size)t=i;else if(o){const{document:b}=this.#t,a=b.createNodeIterator(e,r.SHOW_ELEMENT);let c=a.nextNode();for(c===e&&(c=a.nextNode());c;)this._matchLeaves(l,c,{forgive:f})&&t.add(c),c=a.nextNode()}}}else switch(u){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(l,i,{forgive:f})&&t.add(i);break}case"~":{const i=[];let o=e.previousElementSibling;for(;o;)this._matchLeaves(l,o,{forgive:f})&&i.push(o),o=o.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(l,i,{forgive:f})&&t.add(i);break}case" ":default:{const i=[];let o=e.parentNode;for(;o;)this._matchLeaves(l,o,{forgive:f})&&i.push(o),o=o.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(s,e){const{leaves:[n,...h]}=s,{type:l}=n,u=(0,k.unescapeSelector)(n.name),m=h.length>0,{document:f,root:t,shadow:i}=this.#t;let o=new Set,b=!1;switch(l){case r.SELECTOR_ID:{let a;if(e===P)this._matchLeaves([n],this.#e)&&(a=this.#e);else if(e===D){let c=this.#e;for(;c;){if(this._matchLeaves([n],c)){a=c;break}c=c.parentNode}}else e===I||t.nodeType===r.ELEMENT_NODE?b=!0:a=t.getElementById(u);a&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a));break}case r.SELECTOR_CLASS:{let a=[];if(e===P)this.#e.nodeType===r.ELEMENT_NODE&&this.#e.classList.contains(u)&&a.push(this.#e);else if(e===D){let c=this.#e;for(;c&&c.nodeType===r.ELEMENT_NODE;)c.classList.contains(u)&&a.push(c),c=c.parentNode}else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=[].slice.call(t.children);for(const d of c){d.classList.contains(u)&&a.push(d);const p=[].slice.call(d.getElementsByClassName(u));a.push(...p)}}else{const c=[].slice.call(t.getElementsByClassName(u));if(this.#e.nodeType===r.ELEMENT_NODE)for(const d of c)(d===this.#e||(0,E.isInclusive)(d,this.#e))&&a.push(d);else a=c}if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_TYPE:{let a=[];if(e===P)this.#e.nodeType===r.ELEMENT_NODE&&this._matchLeaves([n],this.#e)&&a.push(this.#e);else if(e===D){let c=this.#e;for(;c&&c.nodeType===r.ELEMENT_NODE;)this._matchLeaves([n],c)&&a.push(c),c=c.parentNode}else if(f.contentType!=="text/html"||/[*|]/.test(u))b=!0;else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=u.toLowerCase(),d=[].slice.call(t.children);for(const p of d){p.localName===c&&a.push(p);const N=[].slice.call(p.getElementsByTagName(u));a.push(...N)}}else{const c=[].slice.call(t.getElementsByTagName(u));if(this.#e.nodeType===r.ELEMENT_NODE)for(const d of c)(d===this.#e||(0,E.isInclusive)(d,this.#e))&&a.push(d);else a=c}if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:{const a=[];if(e!==D&&r.REG_SHADOW_HOST.test(u)){if(i&&this.#e.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=this._matchShadowHostPseudoClass(n,this.#e);c&&a.push(c)}}else if(e===P)this._matchLeaves([n],this.#e)&&a.push(this.#e);else if(e===D){let c=this.#e;for(;c;)this._matchLeaves([n],c)&&a.push(c),c=c.parentNode}else b=!0;if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a)}}if(m&&!b&&!o.size){const a=h[h.length-1],{type:c}=a;if(c===r.SELECTOR_PSEUDO_CLASS){let d;t.nodeType===r.ELEMENT_NODE?d=t:d=t.firstElementChild,this._matchPseudoClassSelector(a,d)}}return{nodes:o,pending:b}}_getFirstTwig(s){const e=s.length-1,n=s[0];let h,l;if(e){const u=s[e],{leaves:[{type:m}]}=u;m===r.SELECTOR_PSEUDO_ELEMENT||m===r.SELECTOR_ID?(h=U,l=u):(h=M,l=n)}else h=U,l=n;return{find:h,twig:l}}_collectNodes(s){const e=this.#i.values();if(s===I||s===C){const n=new Set;let h=0;for(const{branch:l}of e){const{find:u,twig:m}=this._getFirstTwig(l),{nodes:f,pending:t}=this._findNodes(m,s);f.size?this.#l[h]=f:t?n.add(new Map([["index",h],["twig",m]])):this.#i[h].skip=!0,this.#i[h].find=u,h++}if(n.size){const{document:l,root:u}=this.#t,m=l.createNodeIterator(u,r.SHOW_ELEMENT);let f=m.nextNode();for(;f;){let t=!1;if(this.#e.nodeType===r.ELEMENT_NODE?f===this.#e?t=!0:t=this.#e.contains(f):t=!0,t)for(const i of n){const{leaves:o}=i.get("twig");if(this._matchLeaves(o,f)){const a=i.get("index");this.#l[a].add(f)}}f=m.nextNode()}}}else{let n=0;for(const{branch:h}of e){const l=h[h.length-1],{nodes:u}=this._findNodes(l,s);u.size?this.#l[n]=u:this.#i[n].skip=!0,this.#i[n].find=U,n++}}return[this.#i,this.#l]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((n,h)=>{let l;return(0,E.isPreceding)(h,n)?l=1:l=-1,l}),e}_matchNodes(s){const[...e]=this.#i,n=e.length;let h=new Set;for(let l=0;l<n;l++){const{branch:u,find:m,skip:f}=e[l],t=u.length;if(!f&&t){const i=this.#l[l],o=t-1;if(o===0)if((s===I||s===C)&&this.#e.nodeType===r.ELEMENT_NODE){for(const b of i)if(b!==this.#e&&this.#e.contains(b)&&(h.add(b),s===C))break}else if(s===C){const[b]=this._sortNodes(i);h.add(b)}else{const b=[...h],a=[...i];h=new Set([...b,...a])}else if(m===M){let{combo:b}=u[0];for(const a of i){let c=new Set([a]);for(let d=1;d<t;d++){const{combo:p,leaves:N}=u[d],y=[];for(const x of c){const L={combo:b,leaves:N},$=this._matchCombinator(L,x,{find:m});$.size&&y.push(...$)}if(y.length)if(d===o){if(s===C){const[x]=this._sortNodes(y);h.add(x)}else{const x=[...h];h=new Set([...x,...y])}break}else b=p,c=new Set(y);else break}}}else for(const b of i){let a=new Set([b]),c;for(let d=o-1;d>=0;d--){const p=u[d],N=[];for(const y of a){const x=this._matchCombinator(p,y,{find:m});x.size&&N.push(...x)}if(N.length)if(c=!0,d===0){h.add(b);break}else a=new Set(N);else{c=!1;break}}if(c&&s!==I)break}}}return h}_find(s){return this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{s=this._find(P).has(this.#e)}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{const e=this._find(D);let n=this.#e;for(;n;){if(e.has(n)){s=n;break}n=n.parentNode}}catch(e){this._onError(e)}return s??null}querySelector(){let s;try{const e=this._find(C);e.delete(this.#e),e.size&&([s]=this._sortNodes(e))}catch(e){this._onError(e)}return s??null}querySelectorAll(){let s;try{const e=this._find(I);e.delete(this.#e),e.size&&(s=this._sortNodes(e))}catch(e){this._onError(e)}return s??[]}}0&&(module.exports={Matcher});
1
+ var B=Object.create;var I=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(T,i)=>{for(var e in i)I(T,e,{get:i[e],enumerable:!0})},U=(T,i,e,n)=>{if(i&&typeof i=="object"||typeof i=="function")for(let h of F(i))!j.call(T,h)&&h!==e&&I(T,h,{get:()=>i[h],enumerable:!(n=z(i,h))||n.enumerable});return T};var W=(T,i,e)=>(e=T!=null?B(V(T)):{},U(i||!T||!T.__esModule?I(e,"default",{value:T,enumerable:!0}):e,T)),G=T=>U(I({},"__esModule",{value:!0}),T);var X={};H(X,{Matcher:()=>q});module.exports=G(X);var M=W(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),k=require("./parser.js"),r=require("./constant.js");const P="next",R="prev",C="all",$="first",O="lineal",D="self";class q{#i;#r;#a;#e;#l;#t;#o;#s;constructor(i,e,n={}){const{warn:h}=n;this.#r=new Map([[r.SELECTOR_PSEUDO_ELEMENT,r.BIT_01],[r.SELECTOR_ID,r.BIT_02],[r.SELECTOR_CLASS,r.BIT_04],[r.SELECTOR_TYPE,r.BIT_08],[r.SELECTOR_ATTR,r.BIT_16],[r.SELECTOR_PSEUDO_CLASS,r.BIT_32]]),this.#a=new WeakMap,this.#o=i,this.#e=e,this.#s=!!h,[this.#i,this.#l]=this._prepare(i),this.#t=this._getRoot(e)}_onError(i){if(i instanceof DOMException&&i.name===r.NOT_SUPPORTED_ERR)this.#s&&console.warn(i.message);else throw i}_getRoot(i=this.#e){let e,n;switch(i.nodeType){case r.DOCUMENT_NODE:{e=i,n=i;break}case r.DOCUMENT_FRAGMENT_NODE:{e=i.ownerDocument,n=i;break}case r.ELEMENT_NODE:{if(i.ownerDocument.contains(i))e=i.ownerDocument,n=i.ownerDocument;else{let l=i;for(;l&&l.parentNode;)l=l.parentNode;e=l.ownerDocument,n=l}break}default:throw new TypeError(`Unexpected node ${i.nodeName}`)}const h=(0,E.isInShadowTree)(i);return{document:e,root:n,shadow:h}}_sortLeaves(i){const e=[...i];return e.length>1&&e.sort((n,h)=>{const{type:l}=n,{type:u}=h,m=this.#r.get(l),f=this.#r.get(u);let t;return m===f?t=0:m>f?t=1:t=-1,t}),e}_prepare(i=this.#o){const e=(0,k.parseSelector)(i),n=(0,k.walkAST)(e),h=[],l=[];let u=0;for(const[...m]of n){const f=[];let t=m.shift();if(t&&t.type!==r.COMBINATOR){const s=new Set;for(;t;){if(t.type===r.COMBINATOR){const[o]=m;if(o.type===r.COMBINATOR){const b=`Invalid combinator ${t.name}${o.name}`;throw new DOMException(b,r.SYNTAX_ERR)}f.push({combo:t,leaves:this._sortLeaves(s)}),s.clear()}else t&&s.add(t);if(m.length)t=m.shift();else{f.push({combo:null,leaves:this._sortLeaves(s)}),s.clear();break}}}h.push({branch:f,find:null,skip:!1}),l[u]=new Set,u++}return[h,l]}_collectNthChild(i,e){const{a:n,b:h,reverse:l,selector:u}=i,{parentNode:m}=e,f=new Set;let t;if(u&&(this.#a.has(u)?t=this.#a.get(u):(t=(0,k.walkAST)(u),this.#a.set(u,t))),m){const s=[].slice.call(m.children),o=s.length;if(o){const b=new Set;if(t){const a=t.length;for(const c of s){let d;for(let w=0;w<a;w++){const N=t[w];if(d=this._matchLeaves(N,c),!d)break}d&&b.add(c)}}if(l&&s.reverse(),n===0){if(h>0&&h<=o){if(b.size)for(let a=0;a<o;a++){const c=s[a];if(b.has(c)){f.add(c);break}}else if(!u){const a=s[h-1];f.add(a)}}}else{let a=h-1;if(n>0)for(;a<0;)a+=n;if(a>=0&&a<o){let c=n>0?0:h-1;for(let d=0;d<o&&a>=0&&a<o;d++){const w=s[d];b.size?b.has(w)&&(c===a&&(f.add(w),a+=n),n>0?c++:c--):d===a&&(u||f.add(w),a+=n)}}}}}else{const{root:s}=this.#t;if(e===s&&s.nodeType===r.ELEMENT_NODE&&n+h===1)if(t){const o=t.length;let b;for(let a=0;a<o;a++){const c=t[a];if(b=this._matchLeaves(c,e),b)break}b&&f.add(e)}else f.add(e)}return f}_collectNthOfType(i,e){const{a:n,b:h,reverse:l}=i,{localName:u,parentNode:m,prefix:f}=e,t=new Set;if(m){const s=[].slice.call(m.children),o=s.length;if(o)if(l&&s.reverse(),n===0){if(h>0&&h<=o){let b=0;for(let a=0;a<o;a++){const c=s[a],{localName:d,prefix:w}=c;if(d===u&&w===f){if(b===h-1){t.add(c);break}b++}}}}else{let b=h-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<o){let a=n>0?0:h-1;for(let c=0;c<o;c++){const d=s[c],{localName:w,prefix:N}=d;if(w===u&&N===f){if(a===b&&(t.add(d),b+=n),b<0||b>=o)break;n>0?a++:a--}}}}}else{const{root:s}=this.#t;e===s&&s.nodeType===r.ELEMENT_NODE&&n+h===1&&t.add(e)}return t}_matchAnPlusB(i,e,n){const{nth:{a:h,b:l,name:u},selector:m}=i,f=(0,k.unescapeSelector)(u),t=new Map;f?(f==="even"?(t.set("a",2),t.set("b",0)):f==="odd"&&(t.set("a",2),t.set("b",1)),n.indexOf("last")>-1&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?t.set("b",l*1):t.set("b",0),n.indexOf("last")>-1&&t.set("reverse",!0));let s=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(n)){m&&t.set("selector",m);const o=Object.fromEntries(t),b=this._collectNthChild(o,e);b.size&&(s=b)}else if(/^nth-(?:last-)?of-type$/.test(n)){const o=Object.fromEntries(t),b=this._collectNthOfType(o,e);b.size&&(s=b)}}return s}_matchPseudoElementSelector(i,e={}){const{forgive:n}=e;switch(i){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${i}`,r.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${i}()`,r.NOT_SUPPORTED_ERR);break}default:if(i.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${i}`,r.NOT_SUPPORTED_ERR)}else if(!n)throw new DOMException(`Unknown pseudo-element ::${i}`,r.SYNTAX_ERR)}}_matchDirectionPseudoClass(i,e){const n=(0,k.unescapeSelector)(i.name),h=(0,E.getDirectionality)(e);let l;return n===h&&(l=e),l??null}_matchLanguagePseudoClass(i,e){const n=(0,k.unescapeSelector)(i.name);let h;if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let l=e.parentNode;for(;l&&l.nodeType===r.ELEMENT_NODE;){if(l.hasAttribute("lang")){l.getAttribute("lang")&&(h=e);break}l=l.parentNode}}else if(n){const l=`(?:-${r.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${r.ALPHA_NUM}${l}$`,"i").test(n)){let m;if(n.indexOf("-")>-1){const[f,t,...s]=n.split("-");let o;f==="*"?o=`${r.ALPHA_NUM}${l}`:o=`${f}${l}`;const b=`-${t}${l}`,a=s.length;let c="";if(a)for(let d=0;d<a;d++)c+=`-${s[d]}${l}`;m=new RegExp(`^${o}${b}${c}$`,"i")}else m=new RegExp(`^${n}${l}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(h=e);else{let f=e.parentNode;for(;f&&f.nodeType===r.ELEMENT_NODE;){if(f.hasAttribute("lang")){const t=f.getAttribute("lang");m.test(t)&&(h=e);break}f=f.parentNode}}}}return h??null}_matchHasPseudoFunc(i,e){let n;if(Array.isArray(i)&&i.length){const[h]=i,{type:l}=h;let u;l===r.COMBINATOR?u=i.shift():u={name:" ",type:r.COMBINATOR};const m=[];for(;i.length;){const[s]=i,{type:o}=s;if(o===r.COMBINATOR)break;m.push(i.shift())}const f={combo:u,leaves:m},t=this._matchCombinator(f,e,{find:P});if(t.size)if(i.length){for(const s of t)if(n=this._matchHasPseudoFunc(Object.assign([],i),s),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(i,e){const{astName:n="",branches:h=[],selector:l="",twigBranches:u=[]}=i;let m;if(n==="has")if(l.includes(":has("))m=null;else{const f=h.length;let t;for(let s=0;s<f;s++){const o=h[s];if(t=this._matchHasPseudoFunc(Object.assign([],o),e),t)break}t&&(m=e)}else{const f=/^(?:is|where)$/.test(n),t=u.length;let s;for(let o=0;o<t;o++){const b=u[o],a=b.length-1,{leaves:c}=b[a];if(s=this._matchLeaves(c,e,{forgive:f}),s&&a>0){let d=new Set([e]);for(let w=a-1;w>=0;w--){const N=b[w],_=[];for(const x of d){const p=this._matchCombinator(N,x,{forgive:f,find:R});p.size&&_.push(...p)}if(_.length)if(w===0){s=!0;break}else d=new Set(_);else{s=!1;break}}}if(s)break}n==="not"?s||(m=e):s&&(m=e)}return m??null}_matchPseudoClassSelector(i,e,n={}){const{children:h}=i,{localName:l,parentNode:u}=e,{forgive:m}=n,f=(0,k.unescapeSelector)(i.name);let t=new Set;if(r.REG_LOGICAL_PSEUDO.test(f)){let s;if(this.#a.has(i))s=this.#a.get(i);else{const b=(0,k.walkAST)(i),a=[],c=[];for(const[...d]of b){for(const x of d){const p=(0,k.generateCSS)(x);a.push(p)}const w=[],N=new Set;let _=d.shift();for(;_;)if(_.type===r.COMBINATOR?(w.push({combo:_,leaves:[...N]}),N.clear()):_&&N.add(_),d.length)_=d.shift();else{w.push({combo:null,leaves:[...N]}),N.clear();break}c.push(w)}s={astName:f,branches:b,twigBranches:c,selector:a.join(",")},this.#a.set(i,s)}const o=this._matchLogicalPseudoFunc(s,e);o&&t.add(o)}else if(Array.isArray(h)){const[s]=h;if(/^nth-(?:last-)?(?:child|of-type)$/.test(f)){const o=this._matchAnPlusB(s,e,f);o.size&&(t=o)}else if(f==="dir"){const o=this._matchDirectionPseudoClass(s,e);o&&t.add(o)}else if(f==="lang"){const o=this._matchLanguagePseudoClass(s,e);o&&t.add(o)}else switch(f){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}()`,r.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;default:if(!m)throw new DOMException(`Unknown pseudo-class :${f}()`,r.SYNTAX_ERR)}}else{const{document:s,root:o}=this.#t,b=/^a(?:rea)?$/,a=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,c=/^(?:(?:inpu|selec)t|button|form|textarea)$/,d=/^d(?:etails|ialog)$/,w=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,_=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,x=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(f){case"any-link":case"link":{b.test(l)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(b.test(l)&&e.hasAttribute("href")){const{href:p,origin:g,pathname:y}=new URL(s.URL),A=new URL(e.getAttribute("href"),p);A.origin===g&&A.pathname===y&&t.add(e)}break}case"visited":break;case"target":{const{hash:p}=new URL(s.URL);e.id&&p===`#${e.id}`&&s.contains(e)&&t.add(e);break}case"target-within":{const{hash:p}=new URL(s.URL);if(p){const g=p.replace(/^#/,"");let y=s.getElementById(g);for(;y;){if(y===e){t.add(e);break}y=y.parentNode}}break}case"scope":{this.#e.nodeType===r.ELEMENT_NODE?e===this.#e&&t.add(e):e===s.documentElement&&t.add(e);break}case"focus":{e===s.activeElement&&t.add(e);break}case"focus-within":{let p=s.activeElement;for(;p;){if(p===e){t.add(e);break}p=p.parentNode}break}case"open":{d.test(l)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{d.test(l)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(a.test(l)||(0,M.default)(l))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let p=u;for(;p&&p.localName!=="fieldset";)p=p.parentNode;p&&u.localName!=="legend"&&p.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(a.test(l)||(0,M.default)(l))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||x.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||x.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let p;l==="textarea"?p=e:l==="input"&&(e.hasAttribute("type")?x.test(e.getAttribute("type"))&&(p=e):p=e),p&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))||e.selected&&l==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))t.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const p=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=s.documentElement);const y=[].slice.call(g.getElementsByTagName("input"));let A;for(const v of y)if(v.getAttribute("type")==="radio"&&(p?v.getAttribute("name")===p&&(A=!!v.checked):v.hasAttribute("name")||(A=!!v.checked),A))break;A||t.add(e)}break}case"default":{const p=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(l==="button"&&!(e.hasAttribute("type")&&p.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let y=e.parentNode;for(;y&&y.localName!=="form";)y=y.parentNode;if(y){const A=s.createNodeIterator(y,r.SHOW_ELEMENT);let v=A.nextNode();for(;v;){const L=v.localName;let S;if(L==="button"?S=!(v.hasAttribute("type")&&p.test(v.getAttribute("type"))):L==="input"&&(S=v.hasAttribute("type")&&g.test(v.getAttribute("type"))),S){v===e&&t.add(e);break}v=A.nextNode()}}}else if(l==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(l==="option"){let y=!1,A=u;for(;A&&A.localName!=="datalist";){if(A.localName==="select"){(A.multiple||A.hasAttribute("multiple"))&&(y=!0);break}A=A.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=u.firstElementChild,L=new Set;let S=v;for(;S;){if(S.selected||S.hasAttribute("selected")){L.add(S);break}S=S.nextElementSibling}L.size||L.add(v),L.has(e)&&t.add(e)}}break}case"valid":{if(c.test(l))e.checkValidity()&&t.add(e);else if(l==="fieldset"){const p=s.createNodeIterator(e,r.SHOW_ELEMENT);let g=p.nextNode();g===e&&(g=p.nextNode());let y;for(;g&&!(c.test(g.localName)&&(y=g.checkValidity(),!y));)g=p.nextNode();y&&t.add(e)}break}case"invalid":{if(c.test(l))e.checkValidity()||t.add(e);else if(l==="fieldset"){const p=s.createNodeIterator(e,r.SHOW_ELEMENT);let g=p.nextNode();g===e&&(g=p.nextNode());let y;for(;g&&!(c.test(g.localName)&&(y=g.checkValidity(),!y));)g=p.nextNode();y||t.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")&&t.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)&&t.add(e);break}case"required":{let p;if(/^(?:select|textarea)$/.test(l))p=e;else if(l==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||w.test(g)||N.test(g)||x.test(g))&&(p=e)}else p=e;p&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let p;if(/^(?:select|textarea)$/.test(l))p=e;else if(l==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||w.test(g)||N.test(g)||x.test(g))&&(p=e)}else p=e;p&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===s.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const p=e.childNodes.values();let g;for(const y of p)if(g=y.nodeType!==r.ELEMENT_NODE&&y.nodeType!==r.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(u&&e===u.firstElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(u&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(u&&e===u.firstElementChild&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(u){const[p]=this._collectNthOfType({a:0,b:1},e);p&&t.add(p)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(u){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p&&t.add(p)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(u){const[p]=this._collectNthOfType({a:0,b:1},e);if(p===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${f}`,r.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,r.NOT_SUPPORTED_ERR);break}default:if(f.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,r.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${f}`,r.SYNTAX_ERR)}}return t}_matchAttributeSelector(i,e){const{flags:n,matcher:h,name:l,value:u}=i;if(typeof n=="string"&&!/^[is]$/i.test(n)){const t=(0,k.generateCSS)(i);throw new DOMException(`Invalid selector ${t}`,r.SYNTAX_ERR)}const{attributes:m}=e;let f;if(m&&m.length){const{document:t}=this.#t;let s;t.contentType==="text/html"?typeof n=="string"&&/^s$/i.test(n)?s=!1:s=!0:typeof n=="string"&&/^i$/i.test(n)?s=!0:s=!1;let o=(0,k.unescapeSelector)(l.name);s&&(o=o.toLowerCase());const b=new Set;if(o.indexOf("|")>-1){const{prefix:a,tagName:c}=(0,E.selectorToNodeProps)(o);for(let{name:d,value:w}of m)switch(s&&(d=d.toLowerCase(),w=w.toLowerCase()),a){case"":{c===d&&b.add(w);break}case"*":{d.indexOf(":")>-1?d.endsWith(`:${c}`)&&b.add(w):c===d&&b.add(w);break}default:if(d.indexOf(":")>-1){const[N,_]=d.split(":");a===N&&c===_&&(0,E.isNamespaceDeclared)(a,e)&&b.add(w)}}}else for(let{name:a,value:c}of m)if(s&&(a=a.toLowerCase(),c=c.toLowerCase()),a.indexOf(":")>-1){const[d,w]=a.split(":");if(d==="xml"&&w==="lang")continue;o===w&&b.add(c)}else o===a&&b.add(c);if(b.size){const{name:a,value:c}=u||{};let d;switch(a?s?d=a.toLowerCase():d=a:c?s?d=c.toLowerCase():d=c:c===""&&(d=c),h){case"=":{typeof d=="string"&&b.has(d)&&(f=e);break}case"~=":{if(d&&typeof d=="string"){for(const w of b)if(new Set(w.split(/\s+/)).has(d)){f=e;break}}break}case"|=":{if(d&&typeof d=="string"){let w;for(const N of b)if(N===d||N.startsWith(`${d}-`)){w=N;break}w&&(f=e)}break}case"^=":{if(d&&typeof d=="string"){let w;for(const N of b)if(N.startsWith(`${d}`)){w=N;break}w&&(f=e)}break}case"$=":{if(d&&typeof d=="string"){let w;for(const N of b)if(N.endsWith(`${d}`)){w=N;break}w&&(f=e)}break}case"*=":{if(d&&typeof d=="string"){let w;for(const N of b)if(N.includes(`${d}`)){w=N;break}w&&(f=e)}break}case null:default:f=e}}}return f??null}_matchClassSelector(i,e){const n=(0,k.unescapeSelector)(i.name);let h;return e.classList.contains(n)&&(h=e),h??null}_matchIDSelector(i,e){const n=(0,k.unescapeSelector)(i.name),{id:h}=e;let l;return n===h&&(l=e),l??null}_matchTypeSelector(i,e,n={}){const h=(0,k.unescapeSelector)(i.name),{localName:l,prefix:u}=e,{forgive:m}=n,{document:f}=this.#t;let{prefix:t,tagName:s}=(0,E.selectorToNodeProps)(h,e);f.contentType==="text/html"&&(t=t.toLowerCase(),s=s.toLowerCase());let o,b;l.indexOf(":")>-1?[o,b]=l.split(":"):(o=u||"",b=l);let a;if(t===""&&o==="")e.namespaceURI===null&&(s==="*"||s===b)&&(a=e);else if(t==="*")(s==="*"||s===b)&&(a=e);else if(t===o){if((0,E.isNamespaceDeclared)(t,e))(s==="*"||s===b)&&(a=e);else if(!m)throw new DOMException(`Undeclared namespace ${t}`,r.SYNTAX_ERR)}else if(t&&!m&&!(0,E.isNamespaceDeclared)(t,e))throw new DOMException(`Undeclared namespace ${t}`,r.SYNTAX_ERR);return a??null}_matchShadowHostPseudoClass(i,e){const{children:n}=i,h=(0,k.unescapeSelector)(i.name);let l;if(Array.isArray(n)){const[u]=(0,k.walkAST)(n[0]),[...m]=u,{host:f}=e;if(h==="host"){let t;for(const s of m){const{type:o}=s;if(o===r.COMBINATOR){const b=(0,k.generateCSS)(i);throw new DOMException(`Invalid selector ${b}`,r.SYNTAX_ERR)}if(t=this._matchSelector(s,f).has(f),!t)break}t&&(l=e)}else if(h==="host-context"){let t=f,s;for(;t;){for(const o of m){const{type:b}=o;if(b===r.COMBINATOR){const a=(0,k.generateCSS)(i);throw new DOMException(`Invalid selector ${a}`,r.SYNTAX_ERR)}if(s=this._matchSelector(o,t).has(t),!s)break}if(s)break;t=t.parentNode}s&&(l=e)}}else if(h==="host")l=e;else throw new DOMException(`Invalid selector :${h}`,r.SYNTAX_ERR);return l??null}_matchSelector(i,e,n){const{type:h}=i,l=(0,k.unescapeSelector)(i.name),{shadow:u}=this.#t;let m=new Set;if(e.nodeType===r.ELEMENT_NODE)switch(h){case r.SELECTOR_ATTR:{const f=this._matchAttributeSelector(i,e);f&&m.add(f);break}case r.SELECTOR_CLASS:{const f=this._matchClassSelector(i,e);f&&m.add(f);break}case r.SELECTOR_ID:{const f=this._matchIDSelector(i,e);f&&m.add(f);break}case r.SELECTOR_PSEUDO_CLASS:{const f=this._matchPseudoClassSelector(i,e,n);f.size&&(m=f);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(l,n);break}case r.SELECTOR_TYPE:default:{const f=this._matchTypeSelector(i,e,n);f&&m.add(f)}}else if(u&&h===r.SELECTOR_PSEUDO_CLASS&&e.nodeType===r.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&r.REG_LOGICAL_PSEUDO.test(l)){const f=this._matchPseudoClassSelector(i,e,n);f.size&&(m=f)}else if(r.REG_SHADOW_HOST.test(l)){const f=this._matchShadowHostPseudoClass(i,e);f&&m.add(f)}}return m}_matchLeaves(i,e,n){let h;for(const l of i)if(h=this._matchSelector(l,e,n).has(e),!h)break;return!!h}_findDescendantNodes(i,e){const[n,...h]=i,{type:l}=n,u=(0,k.unescapeSelector)(n.name),m=h.length>0,{document:f,root:t,shadow:s}=this.#t;let o=new Set,b=!1;if(s)b=!0;else switch(l){case r.SELECTOR_ID:{if(t.nodeType===r.ELEMENT_NODE)b=!0;else{const a=t.getElementById(u);a&&a!==e&&e.contains(a)&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a))}break}case r.SELECTOR_CLASS:{const a=[].slice.call(e.getElementsByClassName(u));if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_TYPE:{if(f.contentType==="text/html"&&!/[*|]/.test(u)){const a=[].slice.call(e.getElementsByTagName(u));if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a)}else b=!0;break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:b=!0}return{nodes:o,pending:b}}_matchCombinator(i,e,n={}){const{combo:h,leaves:l}=i,{name:u}=h,{find:m,forgive:f}=n;let t=new Set;if(m===P)switch(u){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(l,s,{forgive:f})&&t.add(s);break}case"~":{let s=e.nextElementSibling;for(;s;)this._matchLeaves(l,s,{forgive:f})&&t.add(s),s=s.nextElementSibling;break}case">":{const s=[].slice.call(e.children);for(const o of s)this._matchLeaves(l,o,{forgive:f})&&t.add(o);break}case" ":default:{const{nodes:s,pending:o}=this._findDescendantNodes(l,e);if(s.size)t=s;else if(o){const{document:b}=this.#t,a=b.createNodeIterator(e,r.SHOW_ELEMENT);let c=a.nextNode();for(c===e&&(c=a.nextNode());c;)this._matchLeaves(l,c,{forgive:f})&&t.add(c),c=a.nextNode()}}}else switch(u){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(l,s,{forgive:f})&&t.add(s);break}case"~":{const s=[];let o=e.previousElementSibling;for(;o;)this._matchLeaves(l,o,{forgive:f})&&s.push(o),o=o.previousElementSibling;s.length&&(t=new Set(s.reverse()));break}case">":{const s=e.parentNode;s&&this._matchLeaves(l,s,{forgive:f})&&t.add(s);break}case" ":default:{const s=[];let o=e.parentNode;for(;o;)this._matchLeaves(l,o,{forgive:f})&&s.push(o),o=o.parentNode;s.length&&(t=new Set(s.reverse()))}}return t}_findNodes(i,e){const{leaves:[n,...h]}=i,{type:l}=n,u=(0,k.unescapeSelector)(n.name),m=h.length>0,{document:f,root:t,shadow:s}=this.#t;let o=new Set,b=!1;switch(l){case r.SELECTOR_ID:{let a;if(e===D)this._matchLeaves([n],this.#e)&&(a=this.#e);else if(e===O){let c=this.#e;for(;c;){if(this._matchLeaves([n],c)){a=c;break}c=c.parentNode}}else e===C||t.nodeType===r.ELEMENT_NODE?b=!0:a=t.getElementById(u);a&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a));break}case r.SELECTOR_CLASS:{let a=[];if(e===D)this.#e.nodeType===r.ELEMENT_NODE&&this.#e.classList.contains(u)&&a.push(this.#e);else if(e===O){let c=this.#e;for(;c&&c.nodeType===r.ELEMENT_NODE;)c.classList.contains(u)&&a.push(c),c=c.parentNode}else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=[].slice.call(t.children);for(const d of c){d.classList.contains(u)&&a.push(d);const w=[].slice.call(d.getElementsByClassName(u));a.push(...w)}}else{const c=[].slice.call(t.getElementsByClassName(u));if(this.#e.nodeType===r.ELEMENT_NODE)for(const d of c)(d===this.#e||(0,E.isInclusive)(d,this.#e))&&a.push(d);else a=c}if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_TYPE:{let a=[];if(e===D)this.#e.nodeType===r.ELEMENT_NODE&&this._matchLeaves([n],this.#e)&&a.push(this.#e);else if(e===O){let c=this.#e;for(;c&&c.nodeType===r.ELEMENT_NODE;)this._matchLeaves([n],c)&&a.push(c),c=c.parentNode}else if(f.contentType!=="text/html"||/[*|]/.test(u))b=!0;else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=u.toLowerCase(),d=[].slice.call(t.children);for(const w of d){w.localName===c&&a.push(w);const N=[].slice.call(w.getElementsByTagName(u));a.push(...N)}}else{const c=[].slice.call(t.getElementsByTagName(u));if(this.#e.nodeType===r.ELEMENT_NODE)for(const d of c)(d===this.#e||(0,E.isInclusive)(d,this.#e))&&a.push(d);else a=c}if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:{const a=[];if(e!==O&&r.REG_SHADOW_HOST.test(u)){if(s&&this.#e.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=this._matchShadowHostPseudoClass(n,this.#e);c&&a.push(c)}}else if(e===D)this._matchLeaves([n],this.#e)&&a.push(this.#e);else if(e===O){let c=this.#e;for(;c;)this._matchLeaves([n],c)&&a.push(c),c=c.parentNode}else b=!0;if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a)}}if(m&&!b&&!o.size){const a=h[h.length-1],{type:c}=a;if(c===r.SELECTOR_PSEUDO_CLASS){let d;t.nodeType===r.ELEMENT_NODE?d=t:d=t.firstElementChild,this._matchPseudoClassSelector(a,d)}}return{nodes:o,pending:b}}_getFirstTwig(i){const e=i.length-1,n=i[0];let h,l;if(e){const u=i[e],{leaves:[{type:m}]}=u;m===r.SELECTOR_PSEUDO_ELEMENT||m===r.SELECTOR_ID?(h=R,l=u):(h=P,l=n)}else h=R,l=n;return{find:h,twig:l}}_collectNodes(i){const e=this.#i.values();if(i===C||i===$){const n=new Set;let h=0;for(const{branch:l}of e){const{find:u,twig:m}=this._getFirstTwig(l),{nodes:f,pending:t}=this._findNodes(m,i);f.size?this.#l[h]=f:t?n.add(new Map([["index",h],["twig",m]])):this.#i[h].skip=!0,this.#i[h].find=u,h++}if(n.size){const{document:l,root:u}=this.#t,m=l.createNodeIterator(u,r.SHOW_ELEMENT);let f=m.nextNode();for(;f;){let t=!1;if(this.#e.nodeType===r.ELEMENT_NODE?f===this.#e?t=!0:t=this.#e.contains(f):t=!0,t)for(const s of n){const{leaves:o}=s.get("twig");if(this._matchLeaves(o,f)){const a=s.get("index");this.#l[a].add(f)}}f=m.nextNode()}}}else{let n=0;for(const{branch:h}of e){const l=h[h.length-1],{nodes:u}=this._findNodes(l,i);u.size?this.#l[n]=u:this.#i[n].skip=!0,this.#i[n].find=R,n++}}return[this.#i,this.#l]}_sortNodes(i){const e=[...i];return e.length>1&&e.sort((n,h)=>{let l;return(0,E.isPreceding)(h,n)?l=1:l=-1,l}),e}_matchNodes(i){const[...e]=this.#i,n=e.length;let h=new Set;for(let l=0;l<n;l++){const{branch:u,find:m,skip:f}=e[l],t=u.length;if(!f&&t){const s=this.#l[l],o=t-1;if(o===0)if((i===C||i===$)&&this.#e.nodeType===r.ELEMENT_NODE){for(const b of s)if(b!==this.#e&&this.#e.contains(b)&&(h.add(b),i===$))break}else if(i===$){const[b]=this._sortNodes(s);h.add(b)}else{const b=[...h],a=[...s];h=new Set([...b,...a])}else if(m===P){let{combo:b}=u[0];for(const a of s){let c=new Set([a]);for(let d=1;d<t;d++){const{combo:w,leaves:N}=u[d],_=[];for(const x of c){const p={combo:b,leaves:N},g=this._matchCombinator(p,x,{find:m});g.size&&_.push(...g)}if(_.length)if(d===o){if(i===$){const[x]=this._sortNodes(_);h.add(x)}else{const x=[...h];h=new Set([...x,..._])}break}else b=w,c=new Set(_);else break}}}else for(const b of s){let a=new Set([b]),c;for(let d=o-1;d>=0;d--){const w=u[d],N=[];for(const _ of a){const x=this._matchCombinator(w,_,{find:m});x.size&&N.push(...x)}if(N.length)if(c=!0,d===0){h.add(b);break}else a=new Set(N);else{c=!1;break}}if(c&&i!==C)break}}}return h}_find(i){return this._collectNodes(i),this._matchNodes(i)}matches(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let i;try{i=this._find(D).has(this.#e)}catch(e){this._onError(e)}return!!i}closest(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let i;try{const e=this._find(O);let n=this.#e;for(;n;){if(e.has(n)){i=n;break}n=n.parentNode}}catch(e){this._onError(e)}return i??null}querySelector(){let i;try{const e=this._find($);e.delete(this.#e),e.size&&([i]=this._sortNodes(e))}catch(e){this._onError(e)}return i??null}querySelectorAll(){let i;try{const e=this._find(C);e.delete(this.#e),e.size&&(i=this._sortNodes(e))}catch(e){this._onError(e)}return i??[]}}0&&(module.exports={Matcher});
2
2
  //# sourceMappingURL=matcher.js.map