@asamuzakjp/dom-selector 1.1.4 → 1.1.6

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
@@ -78,7 +78,6 @@ querySelectorAll - same functionality as [Document.querySelectorAll()][69], [Doc
78
78
  - `selector` **[string][59]** CSS selector
79
79
  - `node` **[object][60]** Document, DocumentFragment or Element node
80
80
  - `opt` **[object][60]?** options
81
- - `opt.sort` **[boolean][61]?** sort matched nodes
82
81
  - `opt.warn` **[boolean][61]?** console warn e.g. unsupported pseudo-class
83
82
 
84
83
  Returns **[Array][62]<([object][60] \| [undefined][63])>** array of matched nodes
@@ -236,38 +235,38 @@ const dom = new JSDOM('', {
236
235
 
237
236
  |Method / Selector|Jsdom v22.1.0 (nwsapi)|Patched-jsdom|Result|
238
237
  |:----------------|:----------------|:----------------|:----------------|
239
- |matches('.container.box')|2,103,531 ops/sec ±16.53%|113,370 ops/sec ±9.63%|jsdom is 18.6 times faster. patched-jsdom took 0.009msec.|
240
- |matches('.container:not(.box)')|1,103,421 ops/sec ±0.13%|75,746 ops/sec ±0.14%|jsdom is 14.6 times faster. patched-jsdom took 0.013msec.|
241
- |matches('.box + .box')|2,023,891 ops/sec ±0.36%|106,495 ops/sec ±1.39%|jsdom is 19.0 times faster. patched-jsdom took 0.009msec.|
242
- |matches('.box ~ .box')|2,013,003 ops/sec ±0.21%|110,622 ops/sec ±0.14%|jsdom is 18.2 times faster. patched-jsdom took 0.009msec.|
243
- |matches('.box > .block')|1,969,215 ops/sec ±0.28%|110,591 ops/sec ±0.13%|jsdom is 17.8 times faster. patched-jsdom took 0.009msec.|
244
- |matches('.box .content')|300,820 ops/sec ±0.23%|53,400 ops/sec ±1.03%|jsdom is 5.6 times faster. patched-jsdom took 0.019msec.|
245
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|132,861 ops/sec ±0.18%|10,889 ops/sec ±3.40%|jsdom is 12.2 times faster. patched-jsdom took 0.092msec.|
246
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|35,323 ops/sec ±0.22%|jsdom throws. patched-jsdom took 0.028msec.|
247
- |closest('.container.box')|393,527 ops/sec ±0.13%|51,058 ops/sec ±0.14%|jsdom is 7.7 times faster. patched-jsdom took 0.020msec.|
248
- |closest('.container:not(.box)')|217,890 ops/sec ±4.31%|32,496 ops/sec ±6.77%|jsdom is 6.7 times faster. patched-jsdom took 0.031msec.|
249
- |closest('.box + .box')|346,812 ops/sec ±2.50%|50,913 ops/sec ±0.13%|jsdom is 6.8 times faster. patched-jsdom took 0.020msec.|
250
- |closest('.box ~ .box')|141,015 ops/sec ±0.14%|29,432 ops/sec ±0.14%|jsdom is 4.8 times faster. patched-jsdom took 0.034msec.|
251
- |closest('.box > .block')|390,585 ops/sec ±0.12%|47,152 ops/sec ±1.52%|jsdom is 8.3 times faster. patched-jsdom took 0.021msec.|
252
- |closest('.box .content')|292,276 ops/sec ±1.48%|37,460 ops/sec ±1.93%|jsdom is 7.8 times faster. patched-jsdom took 0.027msec.|
253
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|121,479 ops/sec ±1.97%|9,877 ops/sec ±1.68%|jsdom is 12.3 times faster. patched-jsdom took 0.101msec.|
254
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|8,379 ops/sec ±0.65%|jsdom throws. patched-jsdom took 0.119msec.|
255
- |querySelector('.container.box')|80,132 ops/sec ±1.31%|23,699 ops/sec ±1.43%|jsdom is 3.4 times faster. patched-jsdom took 0.042msec.|
256
- |querySelector('.container:not(.box)')|69,928 ops/sec ±1.42%|17,739 ops/sec ±1.21%|jsdom is 3.9 times faster. patched-jsdom took 0.056msec.|
257
- |querySelector('.box + .box')|65,958 ops/sec ±1.35%|18,716 ops/sec ±1.41%|jsdom is 3.5 times faster. patched-jsdom took 0.053msec.|
258
- |querySelector('.box ~ .box')|67,535 ops/sec ±1.53%|8,419 ops/sec ±1.24%|jsdom is 8.0 times faster. patched-jsdom took 0.119msec.|
259
- |querySelector('.box > .block')|1,039 ops/sec ±1.61%|2,782 ops/sec ±0.84%|patched-jsdom is 2.7 times faster. patched-jsdom took 0.359msec.|
260
- |querySelector('.box .content')|492 ops/sec ±1.52%|259 ops/sec ±1.19%|jsdom is 1.9 times faster. patched-jsdom took 3.867msec.|
261
- |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|202 ops/sec ±1.21%|430 ops/sec ±0.86%|patched-jsdom is 2.1 times faster. patched-jsdom took 2.323msec.|
262
- |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|366 ops/sec ±1.41%|jsdom throws. patched-jsdom took 2.730msec.|
263
- |querySelectorAll('.container.box')|92,026 ops/sec ±0.12%|20,885 ops/sec ±0.15%|jsdom is 4.4 times faster. patched-jsdom took 0.048msec.|
264
- |querySelectorAll('.container:not(.box)')|81,439 ops/sec ±1.22%|16,083 ops/sec ±1.86%|jsdom is 5.1 times faster. patched-jsdom took 0.062msec.|
265
- |querySelectorAll('.box + .box')|80,091 ops/sec ±1.29%|18,897 ops/sec ±0.09%|jsdom is 4.2 times faster. patched-jsdom took 0.053msec.|
266
- |querySelectorAll('.box ~ .box')|80,555 ops/sec ±0.11%|8,200 ops/sec ±1.90%|jsdom is 9.8 times faster. patched-jsdom took 0.122msec.|
267
- |querySelectorAll('.box > .block')|937 ops/sec ±1.40%|2,378 ops/sec ±0.97%|patched-jsdom is 2.5 times faster. patched-jsdom took 0.421msec.|
268
- |querySelectorAll('.box .content')|480 ops/sec ±1.08%|240 ops/sec ±1.03%|jsdom is 2.0 times faster. patched-jsdom took 4.160msec.|
269
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|202 ops/sec ±1.25%|427 ops/sec ±0.86%|patched-jsdom is 2.1 times faster. patched-jsdom took 2.342msec.|
270
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|365 ops/sec ±0.81%|jsdom throws. patched-jsdom took 2.737msec.|
238
+ |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.|
239
+ |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.|
240
+ |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.|
241
+ |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.|
242
+ |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.|
243
+ |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.|
244
+ |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.|
245
+ |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.|
246
+ |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.|
247
+ |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.|
248
+ |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.|
249
+ |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.|
250
+ |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.|
251
+ |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.|
252
+ |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.|
253
+ |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.|
254
+ |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.|
255
+ |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.|
256
+ |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.|
257
+ |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.|
258
+ |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.|
259
+ |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.|
260
+ |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.|
261
+ |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.|
262
+ |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.|
263
+ |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.|
264
+ |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.|
265
+ |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.|
266
+ |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.|
267
+ |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.|
268
+ |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.|
269
+ |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.|
271
270
 
272
271
 
273
272
  ## Acknowledgments
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.js"],
4
- "sourcesContent": ["/*!\n * DOM Selector - Gets the DOM node that matches the CSS selector.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Matcher } from './js/matcher.js';\n\n/**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {boolean} - `true` if matched `false` otherwise\n */\nexport const matches = (selector, node, opt) =>\n new Matcher(selector, node, opt).matches();\n\n/**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {?object} - matched node\n */\nexport const closest = (selector, node, opt) =>\n new Matcher(selector, node, opt).closest();\n\n/**\n * querySelector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {?object} - matched node\n */\nexport const querySelector = (selector, node, opt) =>\n new Matcher(selector, node, opt).querySelector();\n\n/**\n * querySelectorAll\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.sort] - sort matched nodes\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {Array.<object|undefined>} - array of matched nodes\n */\nexport const querySelectorAll = (selector, node, opt) =>\n new Matcher(selector, node, opt).querySelectorAll();\n"],
5
- "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,EAAA,kBAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAN,GAQA,IAAAO,EAAwB,2BARxB;AAAA;AAAA;AAAA;AAAA;AAAA,GAkBO,MAAMJ,EAAU,CAACK,EAAUC,EAAMC,IACtC,IAAI,UAAQF,EAAUC,EAAMC,CAAG,EAAE,QAAQ,EAU9BR,EAAU,CAACM,EAAUC,EAAMC,IACtC,IAAI,UAAQF,EAAUC,EAAMC,CAAG,EAAE,QAAQ,EAU9BN,EAAgB,CAACI,EAAUC,EAAMC,IAC5C,IAAI,UAAQF,EAAUC,EAAMC,CAAG,EAAE,cAAc,EAYpCL,EAAmB,CAACG,EAAUC,EAAMC,IAC/C,IAAI,UAAQF,EAAUC,EAAMC,CAAG,EAAE,iBAAiB",
4
+ "sourcesContent": ["/*!\n * DOM Selector - Gets the DOM node that matches the CSS selector.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Matcher } from './js/matcher.js';\n\n/**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {boolean} - `true` if matched, `false` otherwise\n */\nexport const matches = (selector, node, opt) =>\n new Matcher(selector, node, opt).matches();\n\n/**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {?object} - matched node\n */\nexport const closest = (selector, node, opt) =>\n new Matcher(selector, node, opt).closest();\n\n/**\n * querySelector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {?object} - matched node\n */\nexport const querySelector = (selector, node, opt) =>\n new Matcher(selector, node, opt).querySelector();\n\n/**\n * querySelectorAll\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {Array.<object|undefined>} - array of matched nodes\n */\nexport const querySelectorAll = (selector, node, opt) =>\n new Matcher(selector, node, opt).querySelectorAll();\n"],
5
+ "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,EAAA,kBAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAN,GAQA,IAAAO,EAAwB,2BARxB;AAAA;AAAA;AAAA;AAAA;AAAA,GAkBO,MAAMJ,EAAU,CAACK,EAAUC,EAAMC,IACtC,IAAI,UAAQF,EAAUC,EAAMC,CAAG,EAAE,QAAQ,EAU9BR,EAAU,CAACM,EAAUC,EAAMC,IACtC,IAAI,UAAQF,EAAUC,EAAMC,CAAG,EAAE,QAAQ,EAU9BN,EAAgB,CAACI,EAAUC,EAAMC,IAC5C,IAAI,UAAQF,EAAUC,EAAMC,CAAG,EAAE,cAAc,EAWpCL,EAAmB,CAACG,EAAUC,EAAMC,IAC/C,IAAI,UAAQF,EAAUC,EAAMC,CAAG,EAAE,iBAAiB",
6
6
  "names": ["src_exports", "__export", "closest", "matches", "querySelector", "querySelectorAll", "__toCommonJS", "import_matcher", "selector", "node", "opt"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var b=Object.create;var a=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var i in t)a(e,i,{get:t[i],enumerable:!0})},u=(e,t,i,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!E.call(e,n)&&n!==i&&a(e,n,{get:()=>t[n],enumerable:!(l=T(t,n))||l.enumerable});return e};var g=(e,t,i)=>(i=e!=null?b(y(e)):{},u(t||!e||!e.__esModule?a(i,"default",{value:e,enumerable:!0}):i,e)),h=e=>u(a({},"__esModule",{value:!0}),e);var _={};D(_,{getDirectionality:()=>c,getSlottedTextContent:()=>p,isContentEditable:()=>d,isInShadowTree:()=>N,isNamespaceDeclared:()=>O,isSameOrDescendant:()=>C,selectorToNodeProps:()=>w});module.exports=h(_);var m=g(require("bidi-js"),1),s=require("./constant.js");const f=(0,m.default)(),N=(e={})=>{let t;if(e.nodeType===s.ELEMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:l,mode:n,nodeType:r,parentNode:o}=i;if(l&&n&&r===s.DOCUMENT_FRAGMENT_NODE&&s.REG_SHADOW_MODE.test(n)){t=!0;break}i=o}}return!!t},p=(e={})=>{let t;if(e.localName==="slot"&&N(e)){const i=e.assignedNodes();if(i.length){for(const l of i)if(t=l.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},c=(e={})=>{let t;if(e.nodeType===s.ELEMENT_NODE){const{dir:i,localName:l,parentNode:n}=e;if(/^(?:ltr|rtl)$/.test(i))t=i;else if(i==="auto"){let r;if(l==="textarea"||l==="input"&&(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))?r=e.value:l==="slot"?r=p(e):r=e.textContent.trim(),r){const{paragraphs:[{level:o}]}=f.getEmbeddingLevels(r);o%2===1?t="rtl":t="ltr"}if(!t)if(n){const{nodeType:o}=n;o===s.ELEMENT_NODE?t=c(n):(o===s.DOCUMENT_NODE||o===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(l==="bdi"){const r=e.textContent.trim();if(r){const{paragraphs:[{level:o}]}=f.getEmbeddingLevels(r);o%2===1?t="rtl":t="ltr"}t||n||(t="ltr")}else if(l==="input"&&e.type==="tel")t="ltr";else if(n){if(l==="slot"){const r=p(e);if(r){const{paragraphs:[{level:o}]}=f.getEmbeddingLevels(r);o%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:r}=n;r===s.ELEMENT_NODE?t=c(n):(r===s.DOCUMENT_NODE||r===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},d=(e={})=>{let t;if(e.nodeType===s.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 l=e.parentNode;for(;l;){if(d(l)){t=!0;break}l=l.parentNode}}}}return!!t},O=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===s.ELEMENT_NODE){const l=`xmlns:${e}`,n=t.ownerDocument.documentElement;let r=t;for(;r;){if(typeof r.hasAttribute=="function"&&r.hasAttribute(l)){i=!0;break}else if(r===n)break;r=r.parentNode}}return!!i},C=(e={},t={})=>{let i;return e.ownerDocument&&e.nodeType===s.ELEMENT_NODE&&((!t||t.nodeType!==s.ELEMENT_NODE)&&(t=e.ownerDocument),e===t?i=!0:t&&(i=t.compareDocumentPosition(e)&s.DOCUMENT_POSITION_CONTAINED_BY)),!!i},w=(e,t)=>{let i,l;if(e&&typeof e=="string")e.indexOf("|")>-1?[i,l]=e.split("|"):(i="*",l=e);else throw new DOMException(`invalid selector ${e}`,s.SYNTAX_ERR);return{prefix:i,tagName:l}};0&&(module.exports={getDirectionality,getSlottedTextContent,isContentEditable,isInShadowTree,isNamespaceDeclared,isSameOrDescendant,selectorToNodeProps});
1
+ var b=Object.create;var a=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var i in t)a(e,i,{get:t[i],enumerable:!0})},u=(e,t,i,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!E.call(e,n)&&n!==i&&a(e,n,{get:()=>t[n],enumerable:!(l=T(t,n))||l.enumerable});return e};var g=(e,t,i)=>(i=e!=null?b(y(e)):{},u(t||!e||!e.__esModule?a(i,"default",{value:e,enumerable:!0}):i,e)),h=e=>u(a({},"__esModule",{value:!0}),e);var _={};D(_,{getDirectionality:()=>c,getSlottedTextContent:()=>p,isContentEditable:()=>d,isInShadowTree:()=>N,isNamespaceDeclared:()=>O,isSameOrDescendant:()=>C,selectorToNodeProps:()=>w});module.exports=h(_);var m=g(require("bidi-js"),1),s=require("./constant.js");const f=(0,m.default)(),N=(e={})=>{let t;if(e.nodeType===s.ELEMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:l,mode:n,nodeType:r,parentNode:o}=i;if(l&&n&&r===s.DOCUMENT_FRAGMENT_NODE&&s.REG_SHADOW_MODE.test(n)){t=!0;break}i=o}}return!!t},p=(e={})=>{let t;if(e.localName==="slot"&&N(e)){const i=e.assignedNodes();if(i.length){for(const l of i)if(t=l.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},c=(e={})=>{let t;if(e.nodeType===s.ELEMENT_NODE){const{dir:i,localName:l,parentNode:n}=e;if(/^(?:ltr|rtl)$/.test(i))t=i;else if(i==="auto"){let r;if(l==="textarea"||l==="input"&&(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))?r=e.value:l==="slot"?r=p(e):r=e.textContent.trim(),r){const{paragraphs:[{level:o}]}=f.getEmbeddingLevels(r);o%2===1?t="rtl":t="ltr"}if(!t)if(n){const{nodeType:o}=n;o===s.ELEMENT_NODE?t=c(n):(o===s.DOCUMENT_NODE||o===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(l==="bdi"){const r=e.textContent.trim();if(r){const{paragraphs:[{level:o}]}=f.getEmbeddingLevels(r);o%2===1?t="rtl":t="ltr"}t||n||(t="ltr")}else if(l==="input"&&e.type==="tel")t="ltr";else if(n){if(l==="slot"){const r=p(e);if(r){const{paragraphs:[{level:o}]}=f.getEmbeddingLevels(r);o%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:r}=n;r===s.ELEMENT_NODE?t=c(n):(r===s.DOCUMENT_NODE||r===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},d=(e={})=>{let t;if(e.nodeType===s.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 l=e.parentNode;for(;l;){if(d(l)){t=!0;break}l=l.parentNode}}}}return!!t},O=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===s.ELEMENT_NODE){const l=`xmlns:${e}`,n=t.ownerDocument.documentElement;let r=t;for(;r;){if(typeof r.hasAttribute=="function"&&r.hasAttribute(l)){i=!0;break}else if(r===n)break;r=r.parentNode}}return!!i},C=(e={},t={})=>{let i;return e.ownerDocument&&e.nodeType===s.ELEMENT_NODE&&((!t||t.nodeType!==s.ELEMENT_NODE)&&(t=e.ownerDocument),e===t?i=!0:t&&(i=t.compareDocumentPosition(e)&s.DOCUMENT_POSITION_CONTAINED_BY)),!!i},w=(e,t)=>{let i,l;if(e&&typeof e=="string")e.indexOf("|")>-1?[i,l]=e.split("|"):(i="*",l=e);else throw new DOMException(`Invalid selector ${e}`,s.SYNTAX_ERR);return{prefix:i,tagName:l}};0&&(module.exports={getDirectionality,getSlottedTextContent,isContentEditable,isInShadowTree,isNamespaceDeclared,isSameOrDescendant,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_CONTAINED_BY,\n ELEMENT_NODE, REG_SHADOW_MODE, SYNTAX_ERR\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 if (/^(?:ltr|rtl)$/.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n if (localName === 'textarea') {\n text = node.value;\n } else if (localName === 'input' &&\n (!node.type ||\n /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type))) {\n text = node.value;\n } else if (localName === 'slot') {\n text = getSlottedTextContent(node);\n } else {\n text = node.textContent.trim();\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 node same or descendant of the root node\n * @param {object} node - Element node\n * @param {object} root - Document, DocumentFragment, Element node\n * @returns {boolean} - result\n */\nexport const isSameOrDescendant = (node = {}, root = {}) => {\n let res;\n if (node.ownerDocument && node.nodeType === ELEMENT_NODE) {\n if (!root || root.nodeType !== ELEMENT_NODE) {\n root = node.ownerDocument;\n }\n if (node === root) {\n res = true;\n } else if (root) {\n res = root.compareDocumentPosition(node) & DOCUMENT_POSITION_CONTAINED_BY;\n }\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"],
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_CONTAINED_BY,\n ELEMENT_NODE, REG_SHADOW_MODE, SYNTAX_ERR\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 if (/^(?:ltr|rtl)$/.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n if (localName === 'textarea') {\n text = node.value;\n } else if (localName === 'input' &&\n (!node.type ||\n /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type))) {\n text = node.value;\n } else if (localName === 'slot') {\n text = getSlottedTextContent(node);\n } else {\n text = node.textContent.trim();\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 node same or descendant of the root node\n * @param {object} node - Element node\n * @param {object} root - Document, DocumentFragment, Element node\n * @returns {boolean} - result\n */\nexport const isSameOrDescendant = (node = {}, root = {}) => {\n let res;\n if (node.ownerDocument && node.nodeType === ELEMENT_NODE) {\n if (!root || root.nodeType !== ELEMENT_NODE) {\n root = node.ownerDocument;\n }\n if (node === root) {\n res = true;\n } else if (root) {\n res = root.compareDocumentPosition(node) & DOCUMENT_POSITION_CONTAINED_BY;\n }\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
5
  "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,uBAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAT,GAKA,IAAAU,EAAwB,wBAGxBC,EAGO,yBAGP,MAAMC,KAAO,EAAAC,SAAY,EAOZR,EAAiB,CAACS,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,EAOaZ,EAAwB,CAACW,EAAO,CAAC,IAAM,CAClD,IAAIO,EACJ,GAAIP,EAAK,YAAc,QAAUT,EAAeS,CAAI,EAAG,CACrD,MAAMQ,EAAQR,EAAK,cAAc,EACjC,GAAIQ,EAAM,QACR,UAAWC,KAAQD,EAEjB,GADAD,EAAME,EAAK,YAAY,KAAK,EACxBF,EACF,WAIJA,EAAMP,EAAK,YAAY,KAAK,CAEhC,CACA,OAAOO,GAAO,IAChB,EAQanB,EAAoB,CAACY,EAAO,CAAC,IAAM,CAC9C,IAAIO,EACJ,GAAIP,EAAK,WAAa,eAAc,CAClC,KAAM,CAAE,IAAKU,EAAS,UAAAC,EAAW,WAAAL,CAAW,EAAIN,EAChD,GAAI,gBAAgB,KAAKU,CAAO,EAC9BH,EAAMG,UACGA,IAAY,OAAQ,CAC7B,IAAIE,EAYJ,GAXID,IAAc,YAEPA,IAAc,UACb,CAACX,EAAK,MACN,6EAA6E,KAAKA,EAAK,IAAI,GAHrGY,EAAOZ,EAAK,MAKHW,IAAc,OACvBC,EAAOvB,EAAsBW,CAAI,EAEjCY,EAAOZ,EAAK,YAAY,KAAK,EAE3BY,EAAM,CACR,KAAM,CAAE,WAAY,CAAC,CAAE,MAAAC,CAAM,CAAC,CAAE,EAAIf,EAAK,mBAAmBc,CAAI,EAC5DC,EAAQ,IAAM,EAChBN,EAAM,MAENA,EAAM,KAEV,CACA,GAAI,CAACA,EACH,GAAID,EAAY,CACd,KAAM,CAAE,SAAUQ,CAAe,EAAIR,EACjCQ,IAAmB,eACrBP,EAAMnB,EAAkBkB,CAAU,GACzBQ,IAAmB,iBACnBA,IAAmB,4BAC5BP,EAAM,MAEV,MACEA,EAAM,KAGZ,SAAWI,IAAc,MAAO,CAC9B,MAAMC,EAAOZ,EAAK,YAAY,KAAK,EACnC,GAAIY,EAAM,CACR,KAAM,CAAE,WAAY,CAAC,CAAE,MAAAC,CAAM,CAAC,CAAE,EAAIf,EAAK,mBAAmBc,CAAI,EAC5DC,EAAQ,IAAM,EAChBN,EAAM,MAENA,EAAM,KAEV,CACMA,GAAOD,IACXC,EAAM,MAEV,SAAWI,IAAc,SAAWX,EAAK,OAAS,MAChDO,EAAM,cACGD,EAAY,CACrB,GAAIK,IAAc,OAAQ,CACxB,MAAMC,EAAOvB,EAAsBW,CAAI,EACvC,GAAIY,EAAM,CACR,KAAM,CAAE,WAAY,CAAC,CAAE,MAAAC,CAAM,CAAC,CAAE,EAAIf,EAAK,mBAAmBc,CAAI,EAC5DC,EAAQ,IAAM,EAChBN,EAAM,MAENA,EAAM,KAEV,CACF,CACA,GAAI,CAACA,EAAK,CACR,KAAM,CAAE,SAAUO,CAAe,EAAIR,EACjCQ,IAAmB,eACrBP,EAAMnB,EAAkBkB,CAAU,GACzBQ,IAAmB,iBACnBA,IAAmB,4BAC5BP,EAAM,MAEV,CACF,MACEA,EAAM,KAEV,CACA,OAAOA,GAAO,IAChB,EAQajB,EAAoB,CAACU,EAAO,CAAC,IAAM,CAC9C,IAAIO,EACJ,GAAIP,EAAK,WAAa,gBACpB,GAAI,OAAOA,EAAK,mBAAsB,UACpCO,EAAMP,EAAK,0BACFA,EAAK,cAAc,aAAe,KAC3CO,EAAM,WACGP,EAAK,aAAa,iBAAiB,EAAG,CAC/C,MAAMe,EAAOf,EAAK,aAAa,iBAAiB,EAChD,GAAIe,IAAS,IAAM,4BAA4B,KAAKA,CAAI,EACtDR,EAAM,WACGQ,IAAS,UAAW,CAC7B,IAAIC,EAAShB,EAAK,WAClB,KAAOgB,GAAQ,CACb,GAAI1B,EAAkB0B,CAAM,EAAG,CAC7BT,EAAM,GACN,KACF,CACAS,EAASA,EAAO,UAClB,CACF,CACF,EAEF,MAAO,CAAC,CAACT,CACX,EAQaf,EAAsB,CAACyB,EAAK,GAAIjB,EAAO,CAAC,IAAM,CACzD,IAAIO,EACJ,GAAIU,GAAM,OAAOA,GAAO,UAAYjB,EAAK,WAAa,eAAc,CAClE,MAAMe,EAAO,SAASE,CAAE,GAClBC,EAAOlB,EAAK,cAAc,gBAChC,IAAIgB,EAAShB,EACb,KAAOgB,GAAQ,CACb,GAAI,OAAOA,EAAO,cAAiB,YAC/BA,EAAO,aAAaD,CAAI,EAAG,CAC7BR,EAAM,GACN,KACF,SAAWS,IAAWE,EACpB,MAEFF,EAASA,EAAO,UAClB,CACF,CACA,MAAO,CAAC,CAACT,CACX,EAQad,EAAqB,CAACO,EAAO,CAAC,EAAGkB,EAAO,CAAC,IAAM,CAC1D,IAAIX,EACJ,OAAIP,EAAK,eAAiBA,EAAK,WAAa,kBACtC,CAACkB,GAAQA,EAAK,WAAa,kBAC7BA,EAAOlB,EAAK,eAEVA,IAASkB,EACXX,EAAM,GACGW,IACTX,EAAMW,EAAK,wBAAwBlB,CAAI,EAAI,mCAGxC,CAAC,CAACO,CACX,EAQab,EAAsB,CAACyB,EAAUnB,IAAS,CACrD,IAAIoB,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
6
  "names": ["dom_util_exports", "__export", "getDirectionality", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isNamespaceDeclared", "isSameOrDescendant", "selectorToNodeProps", "__toCommonJS", "import_bidi_js", "import_constant", "bidi", "bidiFactory", "node", "bool", "refNode", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "text", "level", "parentNodeType", "attr", "parent", "ns", "root", "selector", "prefix", "tagName"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var F=Object.create;var P=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var W=(S,s)=>{for(var e in s)P(S,e,{get:s[e],enumerable:!0})},z=(S,s,e,c)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of j(s))!G.call(S,h)&&h!==e&&P(S,h,{get:()=>s[h],enumerable:!(c=V(s,h))||c.enumerable});return S};var q=(S,s,e)=>(e=S!=null?F(H(S)):{},z(s||!S||!S.__esModule?P(e,"default",{value:S,enumerable:!0}):e,S)),X=S=>z(P({},"__esModule",{value:!0}),S);var J={};W(J,{Matcher:()=>Y});module.exports=X(J);var B=q(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),y=require("./parser.js"),l=require("./constant.js");const R="next",M="prev",U="all",C="first",D="lineal",I="self";class Y{#i;#l;#a;#e;#r;#t;#o;#c;#s;constructor(s,e,c={}){const{sort:h,warn:a}=c;this.#l=new Map([[l.SELECTOR_PSEUDO_ELEMENT,l.BIT_01],[l.SELECTOR_ID,l.BIT_02],[l.SELECTOR_CLASS,l.BIT_04],[l.SELECTOR_TYPE,l.BIT_08],[l.SELECTOR_ATTR,l.BIT_16],[l.SELECTOR_PSEUDO_CLASS,l.BIT_32]]),this.#a=new WeakMap,this.#o=s,this.#e=e,this.#c=!!h,this.#s=!!a,[this.#i,this.#r]=this._prepare(s),this.#t=this._getRoot(e)}_onError(s){if(s instanceof DOMException&&s.name===l.NOT_SUPPORTED_ERR)this.#s&&console.warn(s.message);else throw s}_getRoot(s=this.#e){let e,c;switch(s.nodeType){case l.DOCUMENT_NODE:{e=s,c=s;break}case l.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,c=s;break}case l.ELEMENT_NODE:{if((0,E.isSameOrDescendant)(s))e=s.ownerDocument,c=s.ownerDocument;else{let a=s;for(;a&&a.parentNode;)a=a.parentNode;e=a.ownerDocument,c=a}break}default:throw new TypeError(`Unexpected node ${s.nodeName}`)}const h=(0,E.isInShadowTree)(s);return{document:e,root:c,shadow:h}}_sortLeaves(s){const e=[...s];return e.length>1&&e.sort((c,h)=>{const{type:a}=c,{type:b}=h,p=this.#l.get(a),r=this.#l.get(b);let t;return p===r?t=0:p>r?t=1:t=-1,t}),e}_prepare(s=this.#o){const e=(0,y.parseSelector)(s),c=(0,y.walkAST)(e),h=[],a=[];let b=0;for(const[...p]of c){const r=[];let t=p.shift();if(t&&t.type!==l.COMBINATOR){const i=new Set;for(;t;){if(t.type===l.COMBINATOR){const[o]=p;if(o.type===l.COMBINATOR){const d=`Invalid combinator ${t.name}${o.name}`;throw new DOMException(d,l.SYNTAX_ERR)}r.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(p.length)t=p.shift();else{r.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}h.push({branch:r,find:null,skip:!1}),a[b]=new Set,b++}return[h,a]}_collectNthChild(s,e){const{a:c,b:h,reverse:a,selector:b}=s,{parentNode:p}=e,r=new Set;let t;if(b&&(this.#a.has(b)?t=this.#a.get(b):(t=(0,y.walkAST)(b),this.#a.set(b,t))),p){const i=[...p.children],o=i.length;if(o){const d=new Set;if(t){const n=t.length;for(const f of i){let u;for(let m=0;m<n;m++){const w=t[m];if(u=this._matchLeaves(w,f),!u)break}u&&d.add(f)}}if(a&&i.reverse(),c===0){if(h>0&&h<=o){if(d.size)for(let n=0;n<o;n++){const f=i[n];if(d.has(f)){r.add(f);break}}else if(!b){const n=i[h-1];r.add(n)}}}else{let n=h-1;if(c>0)for(;n<0;)n+=c;if(n>=0&&n<o){let f=c>0?0:h-1;for(let u=0;u<o&&n>=0&&n<o;u++){const m=i[u];d.size?d.has(m)&&(f===n&&(r.add(m),n+=c),c>0?f++:f--):u===n&&(b||r.add(m),n+=c)}}}}}else{const{root:i}=this.#t;if(e===i&&i.nodeType===l.ELEMENT_NODE&&c+h===1)if(t){const o=t.length;let d;for(let n=0;n<o;n++){const f=t[n];if(d=this._matchLeaves(f,e),d)break}d&&r.add(e)}else r.add(e)}return r}_collectNthOfType(s,e){const{a:c,b:h,reverse:a}=s,{localName:b,parentNode:p,prefix:r}=e,t=new Set;if(p){const i=[...p.children],o=i.length;if(o)if(a&&i.reverse(),c===0){if(h>0&&h<=o){let d=0;for(let n=0;n<o;n++){const f=i[n],{localName:u,prefix:m}=f;if(u===b&&m===r){if(d===h-1){t.add(f);break}d++}}}}else{let d=h-1;if(c>0)for(;d<0;)d+=c;if(d>=0&&d<o){let n=c>0?0:h-1;for(let f=0;f<o;f++){const u=i[f],{localName:m,prefix:w}=u;if(m===b&&w===r){if(n===d&&(t.add(u),d+=c),d<0||d>=o)break;c>0?n++:n--}}}}}else{const{root:i}=this.#t;e===i&&i.nodeType===l.ELEMENT_NODE&&c+h===1&&t.add(e)}return t}_matchAnPlusB(s,e,c){const{nth:{a:h,b:a,name:b},selector:p}=s,r=(0,y.unescapeSelector)(b),t=new Map;r?(r==="even"?(t.set("a",2),t.set("b",0)):r==="odd"&&(t.set("a",2),t.set("b",1)),c.indexOf("last")>-1&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof a=="string"&&/-?\d+/.test(a)?t.set("b",a*1):t.set("b",0),c.indexOf("last")>-1&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){p&&t.set("selector",p);const o=Object.fromEntries(t),d=this._collectNthChild(o,e);d.size&&(i=d)}else if(/^nth-(?:last-)?of-type$/.test(c)){const o=Object.fromEntries(t),d=this._collectNthOfType(o,e);d.size&&(i=d)}}return i}_matchPseudoElementSelector(s,e={}){const{forgive:c}=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}`,l.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}()`,l.NOT_SUPPORTED_ERR);break}default:if(s.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,l.NOT_SUPPORTED_ERR)}else if(!c)throw new DOMException(`Unknown pseudo-element ::${s}`,l.SYNTAX_ERR)}}_matchDirectionPseudoClass(s,e){const c=(0,y.unescapeSelector)(s.name),h=(0,E.getDirectionality)(e);let a;return c===h&&(a=e),a??null}_matchLanguagePseudoClass(s,e){const c=(0,y.unescapeSelector)(s.name);let h;if(c)if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let a=e.parentNode;for(;a;){if(a.hasAttribute("lang")){a.getAttribute("lang")&&(h=e);break}a=a.parentNode}}else{const a=`(?:-${l.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${l.ALPHA_NUM}${a}$`,"i").test(c)){let p;if(c.indexOf("-")>-1){const[r,t,...i]=c.split("-");let o;r==="*"?o=`${l.ALPHA_NUM}${a}`:o=`${r}${a}`;const d=`-${t}${a}`,n=i.length;let f="";if(n)for(let u=0;u<n;u++)f+=`-${i[u]}${a}`;p=new RegExp(`^${o}${d}${f}$`,"i")}else p=new RegExp(`^${c}${a}$`,"i");if(e.hasAttribute("lang"))p.test(e.getAttribute("lang"))&&(h=e);else{let r=e.parentNode;for(;r;){if(r.hasAttribute("lang")){const t=r.getAttribute("lang");p.test(t)&&(h=e);break}r=r.parentNode}}}}return h??null}_matchHasPseudoFunc(s,e){let c;if(Array.isArray(s)&&s.length){const[h]=s,{type:a}=h;let b;a===l.COMBINATOR?b=s.shift():b={name:" ",type:l.COMBINATOR};const p=[];for(;s.length;){const[i]=s,{type:o}=i;if(o===l.COMBINATOR)break;p.push(s.shift())}const r={combo:b,leaves:p},t=this._matchCombinator(r,e,{find:R});if(t.size)if(s.length){for(const i of t)if(c=this._matchHasPseudoFunc(Object.assign([],s),i),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(s,e){const{astName:c="",branches:h=[],selector:a="",twigBranches:b=[]}=s;let p;if(c==="has")if(a.includes(":has("))p=null;else{const r=h.length;let t;for(let i=0;i<r;i++){const o=h[i];if(t=this._matchHasPseudoFunc(Object.assign([],o),e),t)break}t&&(p=e)}else{const r=/^(?:is|where)$/.test(c),t=b.length;let i;for(let o=0;o<t;o++){const d=b[o],n=d.length-1,{leaves:f}=d[n];if(i=this._matchLeaves(f,e,{forgive:r}),i&&n>0){let u=new Set([e]);for(let m=n-1;m>=0;m--){const w=d[m],k=[];for(const A of u){const L=this._matchCombinator(w,A,{forgive:r,find:M});L.size&&k.push(...L)}if(k.length)if(m===0){i=!0;break}else u=new Set(k);else{i=!1;break}}}if(i)break}c==="not"?i||(p=e):i&&(p=e)}return p??null}_matchPseudoClassSelector(s,e,c={}){const{children:h}=s,{localName:a,parentNode:b}=e,{forgive:p}=c,r=(0,y.unescapeSelector)(s.name);let t=new Set;if(l.REG_LOGICAL_PSEUDO.test(r)){let i;if(this.#a.has(s))i=this.#a.get(s);else{const d=(0,y.walkAST)(s),n=[],f=[];for(const[...u]of d){for(const A of u){const L=(0,y.generateCSS)(A);n.push(L)}const m=[],w=new Set;let k=u.shift();for(;k;)if(k.type===l.COMBINATOR?(m.push({combo:k,leaves:[...w]}),w.clear()):k&&w.add(k),u.length)k=u.shift();else{m.push({combo:null,leaves:[...w]}),w.clear();break}f.push(m)}i={astName:r,branches:d,twigBranches:f,selector:n.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(r)){const o=this._matchAnPlusB(i,e,r);o.size&&(t=o)}else if(r==="dir"){const o=this._matchDirectionPseudoClass(i,e);o&&t.add(o)}else if(r==="lang"){const o=this._matchLanguagePseudoClass(i,e);o&&t.add(o)}else switch(r){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${r}()`,l.NOT_SUPPORTED_ERR);break}default:if(!p)throw new DOMException(`Unknown pseudo-class :${r}()`,l.SYNTAX_ERR)}}else{const{document:i,root:o}=this.#t,{documentElement:d}=i,n=new URL(i.URL),f=/^a(?:rea)?$/,u=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,m=/^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/,w=/^d(?:etails|ialog)$/,k=/^(?:checkbox|radio)$/,A=/^(?:date(?:time-local)?|month|time|week)$/,L=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,O=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(r){case"any-link":case"link":{f.test(a)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(f.test(a)&&e.hasAttribute("href")){const N=new URL(e.getAttribute("href"),n.href);N.origin===n.origin&&N.pathname===n.pathname&&t.add(e)}break}case"visited":break;case"target":{e.id&&n.hash&&n.hash===`#${e.id}`&&(0,E.isSameOrDescendant)(e)&&t.add(e);break}case"target-within":{if(n.hash){const N=n.hash.replace(/^#/,"");let g=i.getElementById(N);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===l.ELEMENT_NODE?e===this.#e&&t.add(e):e===d&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let N=i.activeElement;for(;N;){if(N===e){t.add(e);break}N=N.parentNode}break}case"open":{w.test(a)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{w.test(a)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(u.test(a)||(0,B.default)(a))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let N=b;for(;N&&N.localName!=="fieldset";)N=N.parentNode;N&&b.localName!=="legend"&&N.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(u.test(a)||(0,B.default)(a))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(a){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||A.test(e.type)||O.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(a){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||A.test(e.type)||O.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 N;a==="textarea"?N=e:a==="input"&&(e.hasAttribute("type")?O.test(e.getAttribute("type"))&&(N=e):N=e),N&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&a==="input"&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))||e.selected&&a==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&a==="input"&&e.type==="checkbox"||a==="progress"&&!e.hasAttribute("value"))t.add(e);else if(a==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const N=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=d);const _=[...g.getElementsByTagName("input")];let T;for(const x of _)if(x.getAttribute("type")==="radio"&&(N?x.getAttribute("name")===N&&(T=!!x.checked):x.hasAttribute("name")||(T=!!x.checked),T))break;T||t.add(e)}break}case"default":{const N=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(a==="button"&&!(e.hasAttribute("type")&&N.test(e.getAttribute("type")))||a==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let _=e.parentNode;for(;_&&_.localName!=="form";)_=_.parentNode;if(_){const T=i.createNodeIterator(_,l.SHOW_ELEMENT);let x=T.nextNode();for(;x;){const $=x.localName;let v;if($==="button"?v=!(x.hasAttribute("type")&&N.test(x.getAttribute("type"))):$==="input"&&(v=x.hasAttribute("type")&&g.test(x.getAttribute("type"))),v){x===e&&t.add(e);break}x=T.nextNode()}}}else if(a==="input"&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(a==="option"){let _=!1,T=b;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 x=b.firstElementChild,$=new Set;let v=x;for(;v;){if(v.selected||v.hasAttribute("selected")){$.add(v);break}v=v.nextElementSibling}$.size||$.add(x),$.has(e)&&t.add(e)}}break}case"valid":{if(m.test(a))e.checkValidity()&&t.add(e);else if(a==="fieldset"){const N=i.createNodeIterator(e,l.SHOW_ELEMENT);let g=N.nextNode();g===e&&(g=N.nextNode());let _;for(;g&&!(m.test(g.localName)&&(_=g.checkValidity(),!_));)g=N.nextNode();_&&t.add(e)}break}case"invalid":{if(m.test(a))e.checkValidity()||t.add(e);else if(a==="fieldset"){const N=i.createNodeIterator(e,l.SHOW_ELEMENT);let g=N.nextNode();g===e&&(g=N.nextNode());let _;for(;g&&!(m.test(g.localName)&&(_=g.checkValidity(),!_));)g=N.nextNode();_||t.add(e)}break}case"in-range":{a==="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":{a==="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 N;if(/^(?:select|textarea)$/.test(a))N=e;else if(a==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||k.test(g)||A.test(g)||O.test(g))&&(N=e)}else N=e;N&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let N;if(/^(?:select|textarea)$/.test(a))N=e;else if(a==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||k.test(g)||A.test(g)||O.test(g))&&(N=e)}else N=e;N&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===d&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const N=e.childNodes.values();let g;for(const _ of N)if(g=_.nodeType!==l.ELEMENT_NODE&&_.nodeType!==l.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(b&&e===b.firstElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(b&&e===b.lastElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(b&&e===b.firstElementChild&&e===b.lastElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(b){const[N]=this._collectNthOfType({a:0,b:1},e);N&&t.add(N)}else e===o&&o.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(b){const[N]=this._collectNthOfType({a:0,b:1,reverse:!0},e);N&&t.add(N)}else e===o&&o.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(b){const[N]=this._collectNthOfType({a:0,b:1},e);if(N===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===o&&o.nodeType===l.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 ::${r}`,l.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 :${r}`,l.NOT_SUPPORTED_ERR);break}default:if(r.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${r}`,l.NOT_SUPPORTED_ERR)}else if(!p)throw new DOMException(`Unknown pseudo-class :${r}`,l.SYNTAX_ERR)}}return t}_matchAttributeSelector(s,e){const{flags:c,matcher:h,name:a,value:b}=s;if(typeof c=="string"&&!/^[is]$/i.test(c)){const t=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${t}`,l.SYNTAX_ERR)}const{attributes:p}=e;let r;if(p&&p.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof c=="string"&&/^s$/i.test(c)?i=!1:i=!0:typeof c=="string"&&/^i$/i.test(c)?i=!0:i=!1;let o=(0,y.unescapeSelector)(a.name);i&&(o=o.toLowerCase());const d=new Set;if(o.indexOf("|")>-1){const{prefix:n,tagName:f}=(0,E.selectorToNodeProps)(o);for(let{name:u,value:m}of p)switch(i&&(u=u.toLowerCase(),m=m.toLowerCase()),n){case"":{f===u&&d.add(m);break}case"*":{u.indexOf(":")>-1?u.endsWith(`:${f}`)&&d.add(m):f===u&&d.add(m);break}default:if(u.indexOf(":")>-1){const[w,k]=u.split(":");n===w&&f===k&&(0,E.isNamespaceDeclared)(n,e)&&d.add(m)}}}else for(let{name:n,value:f}of p)if(i&&(n=n.toLowerCase(),f=f.toLowerCase()),n.indexOf(":")>-1){const[u,m]=n.split(":");if(u==="xml"&&m==="lang")continue;o===m&&d.add(f)}else o===n&&d.add(f);if(d.size){const{name:n,value:f}=b||{};let u;switch(n?i?u=n.toLowerCase():u=n:f?i?u=f.toLowerCase():u=f:f===""&&(u=f),h){case"=":{typeof u=="string"&&d.has(u)&&(r=e);break}case"~=":{if(u&&typeof u=="string"){for(const m of d)if(new Set(m.split(/\s+/)).has(u)){r=e;break}}break}case"|=":{if(u&&typeof u=="string"){let m;for(const w of d)if(w===u||w.startsWith(`${u}-`)){m=w;break}m&&(r=e)}break}case"^=":{if(u&&typeof u=="string"){let m;for(const w of d)if(w.startsWith(`${u}`)){m=w;break}m&&(r=e)}break}case"$=":{if(u&&typeof u=="string"){let m;for(const w of d)if(w.endsWith(`${u}`)){m=w;break}m&&(r=e)}break}case"*=":{if(u&&typeof u=="string"){let m;for(const w of d)if(w.includes(`${u}`)){m=w;break}m&&(r=e)}break}case null:default:r=e}}}return r??null}_matchClassSelector(s,e){const c=(0,y.unescapeSelector)(s.name);let h;return e.classList.contains(c)&&(h=e),h??null}_matchIDSelector(s,e){const c=(0,y.unescapeSelector)(s.name),{id:h}=e;let a;return c===h&&(a=e),a??null}_matchTypeSelector(s,e){const c=(0,y.unescapeSelector)(s.name),{localName:h,prefix:a}=e,{document:b}=this.#t;let{prefix:p,tagName:r}=(0,E.selectorToNodeProps)(c,e);b.contentType==="text/html"&&(p=p.toLowerCase(),r=r.toLowerCase());let t,i;h.indexOf(":")>-1?[t,i]=h.split(":"):(t=a||"",i=h);let o;return p===""&&t===""?e.namespaceURI===null&&(r==="*"||r===i)&&(o=e):p==="*"?(r==="*"||r===i)&&(o=e):p===t&&(0,E.isNamespaceDeclared)(p,e)&&(r==="*"||r===i)&&(o=e),o??null}_matchShadowHostPseudoClass(s,e){const{children:c}=s,h=(0,y.unescapeSelector)(s.name);let a;if(Array.isArray(c)){const[b]=(0,y.walkAST)(c[0]),[...p]=b,{host:r}=e;if(h==="host"){let t;for(const i of p){const{type:o}=i;if(o===l.COMBINATOR){const d=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${d}`,l.SYNTAX_ERR)}if(t=this._matchSelector(i,r).has(r),!t)break}t&&(a=e)}else if(h==="host-context"){let t=r,i;for(;t;){for(const o of p){const{type:d}=o;if(d===l.COMBINATOR){const n=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${n}`,l.SYNTAX_ERR)}if(i=this._matchSelector(o,t).has(t),!i)break}if(i)break;t=t.parentNode}i&&(a=e)}}else h==="host"&&(a=e);return a??null}_matchSelector(s,e,c){const{type:h}=s,a=(0,y.unescapeSelector)(s.name),{shadow:b}=this.#t;let p=new Set;if(e.nodeType===l.ELEMENT_NODE)switch(h){case l.SELECTOR_ATTR:{const r=this._matchAttributeSelector(s,e);r&&p.add(r);break}case l.SELECTOR_CLASS:{const r=this._matchClassSelector(s,e);r&&p.add(r);break}case l.SELECTOR_ID:{const r=this._matchIDSelector(s,e);r&&p.add(r);break}case l.SELECTOR_PSEUDO_CLASS:{const r=this._matchPseudoClassSelector(s,e,c);r.size&&(p=r);break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(a,c);break}case l.SELECTOR_TYPE:default:{const r=this._matchTypeSelector(s,e);r&&p.add(r)}}else if(b&&h===l.SELECTOR_PSEUDO_CLASS&&e.nodeType===l.DOCUMENT_FRAGMENT_NODE){if(a!=="has"&&l.REG_LOGICAL_PSEUDO.test(a)){const r=this._matchPseudoClassSelector(s,e,c);r.size&&(p=r)}else if(l.REG_SHADOW_HOST.test(a)){const r=this._matchShadowHostPseudoClass(s,e);r&&p.add(r)}}return p}_matchLeaves(s,e,c){let h;for(const a of s)if(h=this._matchSelector(a,e,c).has(e),!h)break;return!!h}_findDescendantNodes(s,e){const[c,...h]=s,{type:a}=c,b=(0,y.unescapeSelector)(c.name),p=h.length>0,r=new Set;let t=!1;switch(a){case l.SELECTOR_ID:{const{root:i}=this.#t;if(i.nodeType===l.ELEMENT_NODE)t=!0;else{const o=i.getElementById(b);if(o&&o!==e){const d=(0,E.isSameOrDescendant)(o,e);let n;d&&(n=o),n&&(p?this._matchLeaves(h,n)&&r.add(n):r.add(n))}}break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(b);break}default:t=!0}return{nodes:r,pending:t}}_matchCombinator(s,e,c={}){const{combo:h,leaves:a}=s,{name:b}=h,{find:p,forgive:r}=c;let t=new Set;if(p===R)switch(b){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,{forgive:r})&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(a,i,{forgive:r})&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[...e.children];for(const o of i)this._matchLeaves(a,o,{forgive:r})&&t.add(o);break}case" ":default:{const{nodes:i,pending:o}=this._findDescendantNodes(a,e);if(i.size)t=i;else if(o){const{document:d}=this.#t,n=d.createNodeIterator(e,l.SHOW_ELEMENT);let f=n.nextNode();for(f===e&&(f=n.nextNode());f;)this._matchLeaves(a,f,{forgive:r})&&t.add(f),f=n.nextNode()}}}else switch(b){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,{forgive:r})&&t.add(i);break}case"~":{const i=[];let o=e.previousElementSibling;for(;o;)this._matchLeaves(a,o,{forgive:r})&&i.push(o),o=o.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(a,i,{forgive:r})&&t.add(i);break}case" ":default:{const i=[];let o=e.parentNode;for(;o;)this._matchLeaves(a,o,{forgive:r})&&i.push(o),o=o.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(s,e){const{leaves:[c,...h]}=s,{type:a}=c,b=(0,y.unescapeSelector)(c.name),p=h.length>0,{document:r,root:t,shadow:i}=this.#t;let o=new Set,d=!1;switch(a){case l.SELECTOR_ID:{let n;if(e===I)this._matchLeaves([c],this.#e)&&(n=this.#e);else if(e===D){let f=this.#e;for(;f;){if(this._matchLeaves([c],f)){n=f;break}f=f.parentNode}}else t.nodeType===l.ELEMENT_NODE?d=!0:n=t.getElementById(b);n&&(p?this._matchLeaves(h,n)&&o.add(n):o.add(n));break}case l.SELECTOR_CLASS:{const n=[];if(e===I)this.#e.nodeType===l.ELEMENT_NODE&&this.#e.classList.contains(b)&&n.push(this.#e);else if(e===D){let f=this.#e;for(;f&&f.nodeType===l.ELEMENT_NODE;)f.classList.contains(b)&&n.push(f),f=f.parentNode}else if(t.nodeType===l.DOCUMENT_FRAGMENT_NODE){const f=[...t.children];for(const u of f){u.classList.contains(b)&&n.push(u);const m=[...u.getElementsByClassName(b)];n.push(...m)}}else{const f=[...t.getElementsByClassName(b)];n.push(...f)}if(n.length)if(p)for(const f of n)this._matchLeaves(h,f)&&o.add(f);else o=new Set(n);break}case l.SELECTOR_TYPE:{const n=[];if(e===I)this.#e.nodeType===l.ELEMENT_NODE&&this._matchLeaves([c],this.#e)&&n.push(this.#e);else if(e===D){let f=this.#e;for(;f&&f.nodeType===l.ELEMENT_NODE;)this._matchLeaves([c],f)&&n.push(f),f=f.parentNode}else if(r.contentType!=="text/html"||/[*|]/.test(b))d=!0;else if(t.nodeType===l.DOCUMENT_FRAGMENT_NODE){const f=b.toLowerCase(),u=[...t.children];for(const m of u){m.localName===f&&n.push(m);const w=[...m.getElementsByTagName(b)];n.push(...w)}}else{const f=[...t.getElementsByTagName(b)];n.push(...f)}if(n.length)if(p)for(const f of n)this._matchLeaves(h,f)&&o.add(f);else o=new Set(n);break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(b);break}default:{const n=[];if(e!==D&&l.REG_SHADOW_HOST.test(b)){if(i&&this.#e.nodeType===l.DOCUMENT_FRAGMENT_NODE){const f=this._matchShadowHostPseudoClass(c,this.#e);f&&n.push(f)}}else if(e===I)this._matchLeaves([c],this.#e)&&n.push(this.#e);else if(e===D){let f=this.#e;for(;f;)this._matchLeaves([c],f)&&n.push(f),f=f.parentNode}else d=!0;if(n.length)if(p)for(const f of n)this._matchLeaves(h,f)&&o.add(f);else o=new Set(n)}}return{nodes:o,pending:d}}_getFirstTwig(s){const e=s.length-1,c=s[0];let h,a;if(e){const b=s[e],{leaves:[{type:p}]}=b;p===l.SELECTOR_PSEUDO_ELEMENT||p===l.SELECTOR_ID?(h=M,a=b):(h=R,a=c)}else h=M,a=c;return{find:h,twig:a}}_collectNodes(s){const e=this.#i.values();if(s===U||s===C){const c=new Set;let h=0;for(const{branch:a}of e){const{find:b,twig:p}=this._getFirstTwig(a),{nodes:r,pending:t}=this._findNodes(p,s);r.size?this.#r[h]=r:t?c.add(new Map([["index",h],["twig",p]])):this.#i[h].skip=!0,this.#i[h].find=b,h++}if(c.size){const{document:a,root:b}=this.#t,p=a.createNodeIterator(b,l.SHOW_ELEMENT);let r=p.nextNode();for(;r;){let t=!1;if(this.#e.nodeType===l.ELEMENT_NODE?t=(0,E.isSameOrDescendant)(r,this.#e):t=!0,t)for(const i of c){const{leaves:o}=i.get("twig");if(this._matchLeaves(o,r)){const n=i.get("index");this.#r[n].add(r)}}r=p.nextNode()}}}else{let c=0;for(const{branch:h}of e){const a=h[h.length-1],{nodes:b}=this._findNodes(a,s);b.size?this.#r[c]=b:this.#i[c].skip=!0,this.#i[c].find=M,c++}}return[this.#i,this.#r]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((c,h)=>{const a=c.compareDocumentPosition(h);let b;return a&l.DOCUMENT_POSITION_PRECEDING||a&l.DOCUMENT_POSITION_CONTAINS?b=1:b=-1,b}),e}_matchNodes(s){const[...e]=this.#i,c=e.length;let h=new Set;for(let a=0;a<c;a++){const{branch:b,find:p,skip:r}=e[a],t=b.length;if(!r&&t){const i=this.#r[a],o=t-1;if(o===0)if((s===U||s===C)&&this.#e.nodeType===l.ELEMENT_NODE){for(const d of i)if(d!==this.#e&&(0,E.isSameOrDescendant)(d,this.#e)&&(h.add(d),s===C))break}else if(s===C){const[d]=this._sortNodes(i);h.add(d)}else{const d=[...h],n=[...i];h=new Set([...d,...n])}else if(p===R){let{combo:d}=b[0];for(const n of i){let f=new Set([n]);for(let u=1;u<t;u++){const{combo:m,leaves:w}=b[u],k=[];for(const A of f){const L={combo:d,leaves:w},O=this._matchCombinator(L,A,{find:p});O.size&&k.push(...O)}if(k.length)if(u===o){if(s===C){const[A]=this._sortNodes(k);h.add(A)}else{const A=[...h];h=new Set([...A,...k])}break}else d=m,f=new Set(k);else break}}}else for(const d of i){let n=new Set([d]),f;for(let u=o-1;u>=0;u--){const m=b[u],w=[];for(const k of n){const A=this._matchCombinator(m,k,{find:p});A.size&&w.push(...A)}if(w.length)if(f=!0,u===0){h.add(d);break}else n=new Set(w);else{f=!1;break}}if(f&&s!==U)break}}}return h}_find(s){return this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==l.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{s=this._find(I).has(this.#e)}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==l.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{const e=this._find(D);let c=this.#e;for(;c;){if(e.has(c)){s=c;break}c=c.parentNode}}catch(e){this._onError(e)}return s??null}querySelector(){let s;try{const e=this._find(C);e.delete(this.#e),e.size>1?[s]=this._sortNodes(e):e.size&&([s]=[...e])}catch(e){this._onError(e)}return s??null}querySelectorAll(){const s=[];try{const e=this._find(U);e.delete(this.#e),e.size>1&&this.#c?s.push(...this._sortNodes(e)):e.size&&s.push(...e)}catch(e){this._onError(e)}return s}}0&&(module.exports={Matcher});
1
+ var F=Object.create;var P=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var W=(S,s)=>{for(var e in s)P(S,e,{get:s[e],enumerable:!0})},z=(S,s,e,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of j(s))!G.call(S,h)&&h!==e&&P(S,h,{get:()=>s[h],enumerable:!(n=V(s,h))||n.enumerable});return S};var q=(S,s,e)=>(e=S!=null?F(H(S)):{},z(s||!S||!S.__esModule?P(e,"default",{value:S,enumerable:!0}):e,S)),X=S=>z(P({},"__esModule",{value:!0}),S);var J={};W(J,{Matcher:()=>Y});module.exports=X(J);var B=q(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),y=require("./parser.js"),o=require("./constant.js");const R="next",M="prev",U="all",C="first",D="lineal",I="self";class Y{#i;#r;#a;#e;#l;#t;#o;#s;constructor(s,e,n={}){const{warn:h}=n;this.#r=new Map([[o.SELECTOR_PSEUDO_ELEMENT,o.BIT_01],[o.SELECTOR_ID,o.BIT_02],[o.SELECTOR_CLASS,o.BIT_04],[o.SELECTOR_TYPE,o.BIT_08],[o.SELECTOR_ATTR,o.BIT_16],[o.SELECTOR_PSEUDO_CLASS,o.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===o.NOT_SUPPORTED_ERR)this.#s&&console.warn(s.message);else throw s}_getRoot(s=this.#e){let e,n;switch(s.nodeType){case o.DOCUMENT_NODE:{e=s,n=s;break}case o.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,n=s;break}case o.ELEMENT_NODE:{if((0,E.isSameOrDescendant)(s))e=s.ownerDocument,n=s.ownerDocument;else{let a=s;for(;a&&a.parentNode;)a=a.parentNode;e=a.ownerDocument,n=a}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:a}=n,{type:u}=h,m=this.#r.get(a),c=this.#r.get(u);let t;return m===c?t=0:m>c?t=1:t=-1,t}),e}_prepare(s=this.#o){const e=(0,y.parseSelector)(s),n=(0,y.walkAST)(e),h=[],a=[];let u=0;for(const[...m]of n){const c=[];let t=m.shift();if(t&&t.type!==o.COMBINATOR){const i=new Set;for(;t;){if(t.type===o.COMBINATOR){const[r]=m;if(r.type===o.COMBINATOR){const b=`Invalid combinator ${t.name}${r.name}`;throw new DOMException(b,o.SYNTAX_ERR)}c.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(m.length)t=m.shift();else{c.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}h.push({branch:c,find:null,skip:!1}),a[u]=new Set,u++}return[h,a]}_collectNthChild(s,e){const{a:n,b:h,reverse:a,selector:u}=s,{parentNode:m}=e,c=new Set;let t;if(u&&(this.#a.has(u)?t=this.#a.get(u):(t=(0,y.walkAST)(u),this.#a.set(u,t))),m){const i=[].slice.call(m.children),r=i.length;if(r){const b=new Set;if(t){const l=t.length;for(const f of i){let d;for(let p=0;p<l;p++){const N=t[p];if(d=this._matchLeaves(N,f),!d)break}d&&b.add(f)}}if(a&&i.reverse(),n===0){if(h>0&&h<=r){if(b.size)for(let l=0;l<r;l++){const f=i[l];if(b.has(f)){c.add(f);break}}else if(!u){const l=i[h-1];c.add(l)}}}else{let l=h-1;if(n>0)for(;l<0;)l+=n;if(l>=0&&l<r){let f=n>0?0:h-1;for(let d=0;d<r&&l>=0&&l<r;d++){const p=i[d];b.size?b.has(p)&&(f===l&&(c.add(p),l+=n),n>0?f++:f--):d===l&&(u||c.add(p),l+=n)}}}}}else{const{root:i}=this.#t;if(e===i&&i.nodeType===o.ELEMENT_NODE&&n+h===1)if(t){const r=t.length;let b;for(let l=0;l<r;l++){const f=t[l];if(b=this._matchLeaves(f,e),b)break}b&&c.add(e)}else c.add(e)}return c}_collectNthOfType(s,e){const{a:n,b:h,reverse:a}=s,{localName:u,parentNode:m,prefix:c}=e,t=new Set;if(m){const i=[].slice.call(m.children),r=i.length;if(r)if(a&&i.reverse(),n===0){if(h>0&&h<=r){let b=0;for(let l=0;l<r;l++){const f=i[l],{localName:d,prefix:p}=f;if(d===u&&p===c){if(b===h-1){t.add(f);break}b++}}}}else{let b=h-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<r){let l=n>0?0:h-1;for(let f=0;f<r;f++){const d=i[f],{localName:p,prefix:N}=d;if(p===u&&N===c){if(l===b&&(t.add(d),b+=n),b<0||b>=r)break;n>0?l++:l--}}}}}else{const{root:i}=this.#t;e===i&&i.nodeType===o.ELEMENT_NODE&&n+h===1&&t.add(e)}return t}_matchAnPlusB(s,e,n){const{nth:{a:h,b:a,name:u},selector:m}=s,c=(0,y.unescapeSelector)(u),t=new Map;c?(c==="even"?(t.set("a",2),t.set("b",0)):c==="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 a=="string"&&/-?\d+/.test(a)?t.set("b",a*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 r=Object.fromEntries(t),b=this._collectNthChild(r,e);b.size&&(i=b)}else if(/^nth-(?:last-)?of-type$/.test(n)){const r=Object.fromEntries(t),b=this._collectNthOfType(r,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}`,o.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}()`,o.NOT_SUPPORTED_ERR);break}default:if(s.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,o.NOT_SUPPORTED_ERR)}else if(!n)throw new DOMException(`Unknown pseudo-element ::${s}`,o.SYNTAX_ERR)}}_matchDirectionPseudoClass(s,e){const n=(0,y.unescapeSelector)(s.name),h=(0,E.getDirectionality)(e);let a;return n===h&&(a=e),a??null}_matchLanguagePseudoClass(s,e){const n=(0,y.unescapeSelector)(s.name);let h;if(n)if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let a=e.parentNode;for(;a;){if(a.hasAttribute("lang")){a.getAttribute("lang")&&(h=e);break}a=a.parentNode}}else{const a=`(?:-${o.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${o.ALPHA_NUM}${a}$`,"i").test(n)){let m;if(n.indexOf("-")>-1){const[c,t,...i]=n.split("-");let r;c==="*"?r=`${o.ALPHA_NUM}${a}`:r=`${c}${a}`;const b=`-${t}${a}`,l=i.length;let f="";if(l)for(let d=0;d<l;d++)f+=`-${i[d]}${a}`;m=new RegExp(`^${r}${b}${f}$`,"i")}else m=new RegExp(`^${n}${a}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(h=e);else{let c=e.parentNode;for(;c;){if(c.hasAttribute("lang")){const t=c.getAttribute("lang");m.test(t)&&(h=e);break}c=c.parentNode}}}}return h??null}_matchHasPseudoFunc(s,e){let n;if(Array.isArray(s)&&s.length){const[h]=s,{type:a}=h;let u;a===o.COMBINATOR?u=s.shift():u={name:" ",type:o.COMBINATOR};const m=[];for(;s.length;){const[i]=s,{type:r}=i;if(r===o.COMBINATOR)break;m.push(s.shift())}const c={combo:u,leaves:m},t=this._matchCombinator(c,e,{find:R});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:a="",twigBranches:u=[]}=s;let m;if(n==="has")if(a.includes(":has("))m=null;else{const c=h.length;let t;for(let i=0;i<c;i++){const r=h[i];if(t=this._matchHasPseudoFunc(Object.assign([],r),e),t)break}t&&(m=e)}else{const c=/^(?:is|where)$/.test(n),t=u.length;let i;for(let r=0;r<t;r++){const b=u[r],l=b.length-1,{leaves:f}=b[l];if(i=this._matchLeaves(f,e,{forgive:c}),i&&l>0){let d=new Set([e]);for(let p=l-1;p>=0;p--){const N=b[p],k=[];for(const A of d){const L=this._matchCombinator(N,A,{forgive:c,find:M});L.size&&k.push(...L)}if(k.length)if(p===0){i=!0;break}else d=new Set(k);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:a,parentNode:u}=e,{forgive:m}=n,c=(0,y.unescapeSelector)(s.name);let t=new Set;if(o.REG_LOGICAL_PSEUDO.test(c)){let i;if(this.#a.has(s))i=this.#a.get(s);else{const b=(0,y.walkAST)(s),l=[],f=[];for(const[...d]of b){for(const A of d){const L=(0,y.generateCSS)(A);l.push(L)}const p=[],N=new Set;let k=d.shift();for(;k;)if(k.type===o.COMBINATOR?(p.push({combo:k,leaves:[...N]}),N.clear()):k&&N.add(k),d.length)k=d.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}f.push(p)}i={astName:c,branches:b,twigBranches:f,selector:l.join(",")},this.#a.set(s,i)}const r=this._matchLogicalPseudoFunc(i,e);r&&t.add(r)}else if(Array.isArray(h)){const[i]=h;if(/^nth-(?:last-)?(?:child|of-type)$/.test(c)){const r=this._matchAnPlusB(i,e,c);r.size&&(t=r)}else if(c==="dir"){const r=this._matchDirectionPseudoClass(i,e);r&&t.add(r)}else if(c==="lang"){const r=this._matchLanguagePseudoClass(i,e);r&&t.add(r)}else switch(c){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${c}()`,o.NOT_SUPPORTED_ERR);break}default:if(!m)throw new DOMException(`Unknown pseudo-class :${c}()`,o.SYNTAX_ERR)}}else{const{document:i,root:r}=this.#t,{documentElement:b}=i,l=new URL(i.URL),f=/^a(?:rea)?$/,d=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,p=/^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/,N=/^d(?:etails|ialog)$/,k=/^(?:checkbox|radio)$/,A=/^(?:date(?:time-local)?|month|time|week)$/,L=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,O=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(c){case"any-link":case"link":{f.test(a)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(f.test(a)&&e.hasAttribute("href")){const g=new URL(e.getAttribute("href"),l.href);g.origin===l.origin&&g.pathname===l.pathname&&t.add(e)}break}case"visited":break;case"target":{e.id&&l.hash&&l.hash===`#${e.id}`&&(0,E.isSameOrDescendant)(e)&&t.add(e);break}case"target-within":{if(l.hash){const g=l.hash.replace(/^#/,"");let w=i.getElementById(g);for(;w;){if(w===e){t.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===o.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 g=i.activeElement;for(;g;){if(g===e){t.add(e);break}g=g.parentNode}break}case"open":{N.test(a)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{N.test(a)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(d.test(a)||(0,B.default)(a))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let g=u;for(;g&&g.localName!=="fieldset";)g=g.parentNode;g&&u.localName!=="legend"&&g.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(d.test(a)||(0,B.default)(a))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(a){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||A.test(e.type)||O.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(a){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||A.test(e.type)||O.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 g;a==="textarea"?g=e:a==="input"&&(e.hasAttribute("type")?O.test(e.getAttribute("type"))&&(g=e):g=e),g&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&a==="input"&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))||e.selected&&a==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&a==="input"&&e.type==="checkbox"||a==="progress"&&!e.hasAttribute("value"))t.add(e);else if(a==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const g=e.name;let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;w||(w=b);const _=[].slice.call(w.getElementsByTagName("input"));let T;for(const x of _)if(x.getAttribute("type")==="radio"&&(g?x.getAttribute("name")===g&&(T=!!x.checked):x.hasAttribute("name")||(T=!!x.checked),T))break;T||t.add(e)}break}case"default":{const g=/^(?:button|reset)$/,w=/^(?:image|submit)$/;if(a==="button"&&!(e.hasAttribute("type")&&g.test(e.getAttribute("type")))||a==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))){let _=e.parentNode;for(;_&&_.localName!=="form";)_=_.parentNode;if(_){const T=i.createNodeIterator(_,o.SHOW_ELEMENT);let x=T.nextNode();for(;x;){const $=x.localName;let v;if($==="button"?v=!(x.hasAttribute("type")&&g.test(x.getAttribute("type"))):$==="input"&&(v=x.hasAttribute("type")&&w.test(x.getAttribute("type"))),v){x===e&&t.add(e);break}x=T.nextNode()}}}else if(a==="input"&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(a==="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 x=u.firstElementChild,$=new Set;let v=x;for(;v;){if(v.selected||v.hasAttribute("selected")){$.add(v);break}v=v.nextElementSibling}$.size||$.add(x),$.has(e)&&t.add(e)}}break}case"valid":{if(p.test(a))e.checkValidity()&&t.add(e);else if(a==="fieldset"){const g=i.createNodeIterator(e,o.SHOW_ELEMENT);let w=g.nextNode();w===e&&(w=g.nextNode());let _;for(;w&&!(p.test(w.localName)&&(_=w.checkValidity(),!_));)w=g.nextNode();_&&t.add(e)}break}case"invalid":{if(p.test(a))e.checkValidity()||t.add(e);else if(a==="fieldset"){const g=i.createNodeIterator(e,o.SHOW_ELEMENT);let w=g.nextNode();w===e&&(w=g.nextNode());let _;for(;w&&!(p.test(w.localName)&&(_=w.checkValidity(),!_));)w=g.nextNode();_||t.add(e)}break}case"in-range":{a==="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":{a==="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 g;if(/^(?:select|textarea)$/.test(a))g=e;else if(a==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||k.test(w)||A.test(w)||O.test(w))&&(g=e)}else g=e;g&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let g;if(/^(?:select|textarea)$/.test(a))g=e;else if(a==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||k.test(w)||A.test(w)||O.test(w))&&(g=e)}else g=e;g&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===b&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const g=e.childNodes.values();let w;for(const _ of g)if(w=_.nodeType!==o.ELEMENT_NODE&&_.nodeType!==o.TEXT_NODE,!w)break;w&&t.add(e)}else t.add(e);break}case"first-child":{(u&&e===u.firstElementChild||e===r&&r.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(u&&e===u.lastElementChild||e===r&&r.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(u&&e===u.firstElementChild&&e===u.lastElementChild||e===r&&r.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(u){const[g]=this._collectNthOfType({a:0,b:1},e);g&&t.add(g)}else e===r&&r.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(u){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g&&t.add(g)}else e===r&&r.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(u){const[g]=this._collectNthOfType({a:0,b:1},e);if(g===e){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w===e&&t.add(e)}}else e===r&&r.nodeType===o.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 ::${c}`,o.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 :${c}`,o.NOT_SUPPORTED_ERR);break}default:if(c.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${c}`,o.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${c}`,o.SYNTAX_ERR)}}return t}_matchAttributeSelector(s,e){const{flags:n,matcher:h,name:a,value:u}=s;if(typeof n=="string"&&!/^[is]$/i.test(n)){const t=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${t}`,o.SYNTAX_ERR)}const{attributes:m}=e;let c;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 r=(0,y.unescapeSelector)(a.name);i&&(r=r.toLowerCase());const b=new Set;if(r.indexOf("|")>-1){const{prefix:l,tagName:f}=(0,E.selectorToNodeProps)(r);for(let{name:d,value:p}of m)switch(i&&(d=d.toLowerCase(),p=p.toLowerCase()),l){case"":{f===d&&b.add(p);break}case"*":{d.indexOf(":")>-1?d.endsWith(`:${f}`)&&b.add(p):f===d&&b.add(p);break}default:if(d.indexOf(":")>-1){const[N,k]=d.split(":");l===N&&f===k&&(0,E.isNamespaceDeclared)(l,e)&&b.add(p)}}}else for(let{name:l,value:f}of m)if(i&&(l=l.toLowerCase(),f=f.toLowerCase()),l.indexOf(":")>-1){const[d,p]=l.split(":");if(d==="xml"&&p==="lang")continue;r===p&&b.add(f)}else r===l&&b.add(f);if(b.size){const{name:l,value:f}=u||{};let d;switch(l?i?d=l.toLowerCase():d=l:f?i?d=f.toLowerCase():d=f:f===""&&(d=f),h){case"=":{typeof d=="string"&&b.has(d)&&(c=e);break}case"~=":{if(d&&typeof d=="string"){for(const p of b)if(new Set(p.split(/\s+/)).has(d)){c=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&&(c=e)}break}case"^=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.startsWith(`${d}`)){p=N;break}p&&(c=e)}break}case"$=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.endsWith(`${d}`)){p=N;break}p&&(c=e)}break}case"*=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.includes(`${d}`)){p=N;break}p&&(c=e)}break}case null:default:c=e}}}return c??null}_matchClassSelector(s,e){const n=(0,y.unescapeSelector)(s.name);let h;return e.classList.contains(n)&&(h=e),h??null}_matchIDSelector(s,e){const n=(0,y.unescapeSelector)(s.name),{id:h}=e;let a;return n===h&&(a=e),a??null}_matchTypeSelector(s,e){const n=(0,y.unescapeSelector)(s.name),{localName:h,prefix:a}=e,{document:u}=this.#t;let{prefix:m,tagName:c}=(0,E.selectorToNodeProps)(n,e);u.contentType==="text/html"&&(m=m.toLowerCase(),c=c.toLowerCase());let t,i;h.indexOf(":")>-1?[t,i]=h.split(":"):(t=a||"",i=h);let r;return m===""&&t===""?e.namespaceURI===null&&(c==="*"||c===i)&&(r=e):m==="*"?(c==="*"||c===i)&&(r=e):m===t&&(0,E.isNamespaceDeclared)(m,e)&&(c==="*"||c===i)&&(r=e),r??null}_matchShadowHostPseudoClass(s,e){const{children:n}=s,h=(0,y.unescapeSelector)(s.name);let a;if(Array.isArray(n)){const[u]=(0,y.walkAST)(n[0]),[...m]=u,{host:c}=e;if(h==="host"){let t;for(const i of m){const{type:r}=i;if(r===o.COMBINATOR){const b=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${b}`,o.SYNTAX_ERR)}if(t=this._matchSelector(i,c).has(c),!t)break}t&&(a=e)}else if(h==="host-context"){let t=c,i;for(;t;){for(const r of m){const{type:b}=r;if(b===o.COMBINATOR){const l=(0,y.generateCSS)(s);throw new DOMException(`Invalid selector ${l}`,o.SYNTAX_ERR)}if(i=this._matchSelector(r,t).has(t),!i)break}if(i)break;t=t.parentNode}i&&(a=e)}}else h==="host"&&(a=e);return a??null}_matchSelector(s,e,n){const{type:h}=s,a=(0,y.unescapeSelector)(s.name),{shadow:u}=this.#t;let m=new Set;if(e.nodeType===o.ELEMENT_NODE)switch(h){case o.SELECTOR_ATTR:{const c=this._matchAttributeSelector(s,e);c&&m.add(c);break}case o.SELECTOR_CLASS:{const c=this._matchClassSelector(s,e);c&&m.add(c);break}case o.SELECTOR_ID:{const c=this._matchIDSelector(s,e);c&&m.add(c);break}case o.SELECTOR_PSEUDO_CLASS:{const c=this._matchPseudoClassSelector(s,e,n);c.size&&(m=c);break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(a,n);break}case o.SELECTOR_TYPE:default:{const c=this._matchTypeSelector(s,e);c&&m.add(c)}}else if(u&&h===o.SELECTOR_PSEUDO_CLASS&&e.nodeType===o.DOCUMENT_FRAGMENT_NODE){if(a!=="has"&&o.REG_LOGICAL_PSEUDO.test(a)){const c=this._matchPseudoClassSelector(s,e,n);c.size&&(m=c)}else if(o.REG_SHADOW_HOST.test(a)){const c=this._matchShadowHostPseudoClass(s,e);c&&m.add(c)}}return m}_matchLeaves(s,e,n){let h;for(const a of s)if(h=this._matchSelector(a,e,n).has(e),!h)break;return!!h}_findDescendantNodes(s,e){const[n,...h]=s,{type:a}=n,u=(0,y.unescapeSelector)(n.name),m=h.length>0,{document:c,root:t,shadow:i}=this.#t;let r=new Set,b=!1;if(i)b=!0;else switch(a){case o.SELECTOR_ID:{if(t.nodeType===o.ELEMENT_NODE)b=!0;else{const l=t.getElementById(u);if(l&&l!==e){const f=(0,E.isSameOrDescendant)(l,e);let d;f&&(d=l),d&&(m?this._matchLeaves(h,d)&&r.add(d):r.add(d))}}break}case o.SELECTOR_CLASS:{const l=[].slice.call(e.getElementsByClassName(u));if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&r.add(f);else r=new Set(l);break}case o.SELECTOR_TYPE:{if(c.contentType==="text/html"&&!/[*|]/.test(u)){const l=[].slice.call(e.getElementsByTagName(u));if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&r.add(f);else r=new Set(l)}else b=!0;break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:b=!0}return{nodes:r,pending:b}}_matchCombinator(s,e,n={}){const{combo:h,leaves:a}=s,{name:u}=h,{find:m,forgive:c}=n;let t=new Set;if(m===R)switch(u){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(a,i,{forgive:c})&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(a,i,{forgive:c})&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[].slice.call(e.children);for(const r of i)this._matchLeaves(a,r,{forgive:c})&&t.add(r);break}case" ":default:{const{nodes:i,pending:r}=this._findDescendantNodes(a,e);if(i.size)t=i;else if(r){const{document:b}=this.#t,l=b.createNodeIterator(e,o.SHOW_ELEMENT);let f=l.nextNode();for(f===e&&(f=l.nextNode());f;)this._matchLeaves(a,f,{forgive:c})&&t.add(f),f=l.nextNode()}}}else switch(u){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(a,i,{forgive:c})&&t.add(i);break}case"~":{const i=[];let r=e.previousElementSibling;for(;r;)this._matchLeaves(a,r,{forgive:c})&&i.push(r),r=r.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(a,i,{forgive:c})&&t.add(i);break}case" ":default:{const i=[];let r=e.parentNode;for(;r;)this._matchLeaves(a,r,{forgive:c})&&i.push(r),r=r.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(s,e){const{leaves:[n,...h]}=s,{type:a}=n,u=(0,y.unescapeSelector)(n.name),m=h.length>0,{document:c,root:t,shadow:i}=this.#t;let r=new Set,b=!1;switch(a){case o.SELECTOR_ID:{let l;if(e===I)this._matchLeaves([n],this.#e)&&(l=this.#e);else if(e===D){let f=this.#e;for(;f;){if(this._matchLeaves([n],f)){l=f;break}f=f.parentNode}}else t.nodeType===o.ELEMENT_NODE?b=!0:l=t.getElementById(u);l&&(m?this._matchLeaves(h,l)&&r.add(l):r.add(l));break}case o.SELECTOR_CLASS:{let l=[];if(e===I)this.#e.nodeType===o.ELEMENT_NODE&&this.#e.classList.contains(u)&&l.push(this.#e);else if(e===D){let f=this.#e;for(;f&&f.nodeType===o.ELEMENT_NODE;)f.classList.contains(u)&&l.push(f),f=f.parentNode}else if(t.nodeType===o.DOCUMENT_FRAGMENT_NODE){const f=[].slice.call(t.children);for(const d of f){d.classList.contains(u)&&l.push(d);const p=[].slice.call(d.getElementsByClassName(u));l.push(...p)}}else l=[].slice.call(t.getElementsByClassName(u));if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&r.add(f);else r=new Set(l);break}case o.SELECTOR_TYPE:{let l=[];if(e===I)this.#e.nodeType===o.ELEMENT_NODE&&this._matchLeaves([n],this.#e)&&l.push(this.#e);else if(e===D){let f=this.#e;for(;f&&f.nodeType===o.ELEMENT_NODE;)this._matchLeaves([n],f)&&l.push(f),f=f.parentNode}else if(c.contentType!=="text/html"||/[*|]/.test(u))b=!0;else if(t.nodeType===o.DOCUMENT_FRAGMENT_NODE){const f=u.toLowerCase(),d=[].slice.call(t.children);for(const p of d){p.localName===f&&l.push(p);const N=[].slice.call(p.getElementsByTagName(u));l.push(...N)}}else l=[].slice.call(t.getElementsByTagName(u));if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&r.add(f);else r=new Set(l);break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:{const l=[];if(e!==D&&o.REG_SHADOW_HOST.test(u)){if(i&&this.#e.nodeType===o.DOCUMENT_FRAGMENT_NODE){const f=this._matchShadowHostPseudoClass(n,this.#e);f&&l.push(f)}}else if(e===I)this._matchLeaves([n],this.#e)&&l.push(this.#e);else if(e===D){let f=this.#e;for(;f;)this._matchLeaves([n],f)&&l.push(f),f=f.parentNode}else b=!0;if(l.length)if(m)for(const f of l)this._matchLeaves(h,f)&&r.add(f);else r=new Set(l)}}return{nodes:r,pending:b}}_getFirstTwig(s){const e=s.length-1,n=s[0];let h,a;if(e){const u=s[e],{leaves:[{type:m}]}=u;m===o.SELECTOR_PSEUDO_ELEMENT||m===o.SELECTOR_ID?(h=M,a=u):(h=R,a=n)}else h=M,a=n;return{find:h,twig:a}}_collectNodes(s){const e=this.#i.values();if(s===U||s===C){const n=new Set;let h=0;for(const{branch:a}of e){const{find:u,twig:m}=this._getFirstTwig(a),{nodes:c,pending:t}=this._findNodes(m,s);c.size?this.#l[h]=c: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:a,root:u}=this.#t,m=a.createNodeIterator(u,o.SHOW_ELEMENT);let c=m.nextNode();for(;c;){let t=!1;if(this.#e.nodeType===o.ELEMENT_NODE?t=(0,E.isSameOrDescendant)(c,this.#e):t=!0,t)for(const i of n){const{leaves:r}=i.get("twig");if(this._matchLeaves(r,c)){const l=i.get("index");this.#l[l].add(c)}}c=m.nextNode()}}}else{let n=0;for(const{branch:h}of e){const a=h[h.length-1],{nodes:u}=this._findNodes(a,s);u.size?this.#l[n]=u:this.#i[n].skip=!0,this.#i[n].find=M,n++}}return[this.#i,this.#l]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((n,h)=>{const a=n.compareDocumentPosition(h);let u;return a&o.DOCUMENT_POSITION_PRECEDING||a&o.DOCUMENT_POSITION_CONTAINS?u=1:u=-1,u}),e}_matchNodes(s){const[...e]=this.#i,n=e.length;let h=new Set;for(let a=0;a<n;a++){const{branch:u,find:m,skip:c}=e[a],t=u.length;if(!c&&t){const i=this.#l[a],r=t-1;if(r===0)if((s===U||s===C)&&this.#e.nodeType===o.ELEMENT_NODE){for(const b of i)if(b!==this.#e&&(0,E.isSameOrDescendant)(b,this.#e)&&(h.add(b),s===C))break}else if(s===C){const[b]=this._sortNodes(i);h.add(b)}else{const b=[...h],l=[...i];h=new Set([...b,...l])}else if(m===R){let{combo:b}=u[0];for(const l of i){let f=new Set([l]);for(let d=1;d<t;d++){const{combo:p,leaves:N}=u[d],k=[];for(const A of f){const L={combo:b,leaves:N},O=this._matchCombinator(L,A,{find:m});O.size&&k.push(...O)}if(k.length)if(d===r){if(s===C){const[A]=this._sortNodes(k);h.add(A)}else{const A=[...h];h=new Set([...A,...k])}break}else b=p,f=new Set(k);else break}}}else for(const b of i){let l=new Set([b]),f;for(let d=r-1;d>=0;d--){const p=u[d],N=[];for(const k of l){const A=this._matchCombinator(p,k,{find:m});A.size&&N.push(...A)}if(N.length)if(f=!0,d===0){h.add(b);break}else l=new Set(N);else{f=!1;break}}if(f&&s!==U)break}}}return h}_find(s){return this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==o.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{s=this._find(I).has(this.#e)}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==o.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(U);e.delete(this.#e),e.size&&(s=this._sortNodes(e))}catch(e){this._onError(e)}return s??[]}}0&&(module.exports={Matcher});
2
2
  //# sourceMappingURL=matcher.js.map