@asamuzakjp/dom-selector 1.0.3 → 1.0.5

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
@@ -233,38 +233,38 @@ const dom = new JSDOM('', {
233
233
 
234
234
  |Method / Selector|Jsdom|Patched-jsdom|Result|
235
235
  |:----------------|:----------------|:----------------|:----------------|
236
- |matches('.container.box')|1,642,216 ops/sec ±3.43%|64,823 ops/sec ±8.74%|jsdom is 25.3 times faster. patched-jsdom took 0.015msec.|
237
- |matches('.container:not(.box)')|829,464 ops/sec ±3.61%|39,531 ops/sec ±4.15%|jsdom is 21.0 times faster. patched-jsdom took 0.025msec.|
238
- |matches('.box + .box')|1,598,580 ops/sec ±1.44%|66,518 ops/sec ±2.04%|jsdom is 24.0 times faster. patched-jsdom took 0.015msec.|
239
- |matches('.box ~ .box')|1,623,837 ops/sec ±1.21%|65,891 ops/sec ±0.94%|jsdom is 24.6 times faster. patched-jsdom took 0.015msec.|
240
- |matches('.box > .block')|1,621,883 ops/sec ±0.31%|63,556 ops/sec ±2.48%|jsdom is 25.5 times faster. patched-jsdom took 0.016msec.|
241
- |matches('.box .content')|244,534 ops/sec ±0.48%|36,005 ops/sec ±2.06%|jsdom is 6.8 times faster. patched-jsdom took 0.028msec.|
242
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|105,311 ops/sec ±3.69%|7,098 ops/sec ±2.10%|jsdom is 14.8 times faster. patched-jsdom took 0.141msec.|
243
- |matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|22,913 ops/sec ±1.68%|jsdom throws. patched-jsdom took 0.044msec.|
244
- |closest('.container.box')|319,262 ops/sec ±0.89%|30,493 ops/sec ±3.23%|jsdom is 10.5 times faster. patched-jsdom took 0.033msec.|
245
- |closest('.container:not(.box)')|179,788 ops/sec ±0.61%|20,566 ops/sec ±2.22%|jsdom is 8.7 times faster. patched-jsdom took 0.049msec.|
246
- |closest('.box + .box')|294,027 ops/sec ±0.79%|32,386 ops/sec ±1.67%|jsdom is 9.1 times faster. patched-jsdom took 0.031msec.|
247
- |closest('.box ~ .box')|101,510 ops/sec ±3.61%|20,699 ops/sec ±2.35%|jsdom is 4.9 times faster. patched-jsdom took 0.048msec.|
248
- |closest('.box > .block')|314,456 ops/sec ±1.27%|30,538 ops/sec ±1.37%|jsdom is 10.3 times faster. patched-jsdom took 0.033msec.|
249
- |closest('.box .content')|228,070 ops/sec ±0.68%|24,453 ops/sec ±1.96%|jsdom is 9.3 times faster. patched-jsdom took 0.041msec.|
250
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|99,675 ops/sec ±1.33%|6,632 ops/sec ±2.70%|jsdom is 15.0 times faster. patched-jsdom took 0.151msec.|
251
- |closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|5,411 ops/sec ±1.75%|jsdom throws. patched-jsdom took 0.185msec.|
252
- |querySelector('.container.box')|43,668 ops/sec ±2.03%|15,026 ops/sec ±3.43%|jsdom is 2.9 times faster. patched-jsdom took 0.067msec.|
253
- |querySelector('.container:not(.box)')|31,873 ops/sec ±2.43%|10,341 ops/sec ±1.99%|jsdom is 3.1 times faster. patched-jsdom took 0.097msec.|
254
- |querySelector('.box + .box')|29,090 ops/sec ±5.25%|10,685 ops/sec ±7.23%|jsdom is 2.7 times faster. patched-jsdom took 0.094msec.|
255
- |jsdom querySelector('.box ~ .box')|34,395 ops/sec ±2.16%|6,492 ops/sec ±1.80%|jsdom is 5.3 times faster. patched-jsdom took 0.154msec.|
256
- |querySelector('.box > .block')|707 ops/sec ±2.04%|2,037 ops/sec ±2.42%|patched-jsdom is 2.9 times faster. patched-jsdom took 0.491msec.|
257
- |querySelector('.box .content')|307 ops/sec ±2.88%|196 ops/sec ±1.99%|jsdom is 1.6 times faster. patched-jsdom took 5.110msec.|
258
- |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|138 ops/sec ±3.87%|323 ops/sec ±3.10%|patched-jsdom is 2.3 times faster. patched-jsdom took 3.100msec.|
259
- |querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A|260 ops/sec ±3.65%|jsdom throws. patched-jsdom took 3.846msec.|
260
- |querySelectorAll('.container.box')|62,222 ops/sec ±2.29%|15,138 ops/sec ±1.13%|jsdom is 4.1 times faster. patched-jsdom took 0.066msec.|
261
- |querySelectorAll('.container:not(.box)')|52,862 ops/sec ±1.82%|11,352 ops/sec ±1.30%|jsdom is 4.7 times faster. patched-jsdom took 0.088msec.|
262
- |querySelectorAll('.box + .box')|50,474 ops/sec ±2.32%|13,338 ops/sec ±1.24%|jsdom is 3.8 times faster. patched-jsdom took 0.075msec.|
263
- |querySelectorAll('.box ~ .box')|51,083 ops/sec ±0.69%|6,620 ops/sec ±0.92%|jsdom is 7.7 times faster. patched-jsdom took 0.151msec.|
264
- |jsdom querySelectorAll('.box > .block')|691 ops/sec ±1.53%|1,729 ops/sec ±2.07%|patched-jsdom is 2.5 times faster. patched-jsdom took 0.578msec.|
265
- |querySelectorAll('.box .content')|305 ops/sec ±2.24%|182 ops/sec ±2.36%|jsdom is 1.7 times faster. patched-jsdom took 5.502msec.|
266
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|145 ops/sec ±1.60%|333 ops/sec ±2.64%|patched-jsdom is 2.3 times faster. patched-jsdom took 2.999msec.|
267
- |querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(> .content)')|N/A| 267 ops/sec ±2.17%|jsdom throws. patched-jsdom took 3.738msec.|
236
+ |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.|
237
+ |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.|
238
+ |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.|
239
+ |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.|
240
+ |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.|
241
+ |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.|
242
+ |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.|
243
+ |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.|
244
+ |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.|
245
+ |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.|
246
+ |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.|
247
+ |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.|
248
+ |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.|
249
+ |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.|
250
+ |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.|
251
+ |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.|
252
+ |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.|
253
+ |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.|
254
+ |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.|
255
+ |jsdom 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.|
256
+ |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.|
257
+ |querySelector('.box .content')|492 ops/sec ±1.52%|259 ops/sec ±1.19%|jsdom is 1.9 times faster. patched-jsdom took 3.867msec.|
258
+ |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.|
259
+ |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.|
260
+ |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.|
261
+ |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.|
262
+ |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.|
263
+ |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.|
264
+ |jsdom 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.|
265
+ |querySelectorAll('.box .content')|480 ops/sec ±1.08%|240 ops/sec ±1.03%|jsdom is 2.0 times faster. patched-jsdom took 4.160msec.|
266
+ |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.|
267
+ |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.|
268
268
 
269
269
 
270
270
  ## Acknowledgments
@@ -275,6 +275,10 @@ The following resources have been of great help in the development of the DOM Se
275
275
  - [selery](https://github.com/danburzo/selery)
276
276
 
277
277
 
278
+ ---
279
+ Copyright (c) 2023 [asamuzaK (Kazz)](https://github.com/asamuzaK/)
280
+
281
+
278
282
  [1]: #matches
279
283
  [2]: #parameters
280
284
  [3]: #closest
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var l=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var q=(t,e)=>{for(var o in e)l(t,o,{get:e[o],enumerable:!0})},u=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!m.call(t,r)&&r!==o&&l(t,r,{get:()=>e[r],enumerable:!(s=n(e,r))||s.enumerable});return t};var w=t=>u(l({},"__esModule",{value:!0}),t);var h={};q(h,{closest:()=>y,matches:()=>x,querySelector:()=>S,querySelectorAll:()=>a});module.exports=w(h);var c=require("./js/matcher.js");/*!
2
- * DOM Selector - retrieve DOM node from the given CSS selector
2
+ * DOM Selector - Gets the DOM node that matches the CSS selector.
3
3
  * @license MIT
4
4
  * @copyright asamuzaK (Kazz)
5
5
  * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.js"],
4
- "sourcesContent": ["/*!\n * DOM Selector - retrieve DOM node from the given 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"],
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
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",
6
6
  "names": ["src_exports", "__export", "closest", "matches", "querySelector", "querySelectorAll", "__toCommonJS", "import_matcher", "selector", "node", "opt"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var x=(o,t)=>{for(var E in t)r(o,E,{get:t[E],enumerable:!0})},p=(o,t,E,T)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of s(t))!n.call(o,e)&&e!==E&&r(o,e,{get:()=>t[e],enumerable:!(T=c(t,e))||T.enumerable});return o};var S=o=>p(r({},"__esModule",{value:!0}),o);var k={};x(k,{AN_PLUS_B:()=>_,ATTRIBUTE_SELECTOR:()=>O,BIT_1:()=>d,BIT_10:()=>u,BIT_100:()=>Y,BIT_1000:()=>F,BIT_10000:()=>G,BIT_100000:()=>b,CLASS_SELECTOR:()=>N,COMBINATOR:()=>I,DOCUMENT_FRAGMENT_NODE:()=>f,DOCUMENT_NODE:()=>X,DOCUMENT_POSITION_CONTAINED_BY:()=>w,DOCUMENT_POSITION_CONTAINS:()=>h,DOCUMENT_POSITION_PRECEDING:()=>g,ELEMENT_NODE:()=>H,IDENTIFIER:()=>R,ID_SELECTOR:()=>C,NOT_SUPPORTED_ERR:()=>D,NTH:()=>L,PSEUDO_CLASS_SELECTOR:()=>P,PSEUDO_ELEMENT_SELECTOR:()=>l,RAW:()=>A,SELECTOR:()=>B,SELECTOR_LIST:()=>M,SHOW_ELEMENT:()=>j,STRING:()=>U,SYNTAX_ERR:()=>i,TEXT_NODE:()=>W,TYPE_FROM:()=>m,TYPE_SELECTOR:()=>a,TYPE_TO:()=>y});module.exports=S(k);const _="AnPlusB",O="AttributeSelector",N="ClassSelector",I="Combinator",C="IdSelector",R="Identifier",D="NotSupportedError",L="Nth",P="PseudoClassSelector",l="PseudoElementSelector",A="Raw",B="Selector",M="SelectorList",U="String",i="SyntaxError",a="TypeSelector",d=1,u=2,Y=4,F=8,G=16,b=32,m=8,y=-1,H=1,W=3,X=9,f=11,g=2,h=8,w=16,j=1;0&&(module.exports={AN_PLUS_B,ATTRIBUTE_SELECTOR,BIT_1,BIT_10,BIT_100,BIT_1000,BIT_10000,BIT_100000,CLASS_SELECTOR,COMBINATOR,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,ELEMENT_NODE,IDENTIFIER,ID_SELECTOR,NOT_SUPPORTED_ERR,NTH,PSEUDO_CLASS_SELECTOR,PSEUDO_ELEMENT_SELECTOR,RAW,SELECTOR,SELECTOR_LIST,SHOW_ELEMENT,STRING,SYNTAX_ERR,TEXT_NODE,TYPE_FROM,TYPE_SELECTOR,TYPE_TO});
1
+ var r=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var n=(o,t)=>{for(var E in t)r(o,E,{get:t[E],enumerable:!0})},p=(o,t,E,T)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of c(t))!s.call(o,e)&&e!==E&&r(o,e,{get:()=>t[e],enumerable:!(T=x(t,e))||T.enumerable});return o};var S=o=>p(r({},"__esModule",{value:!0}),o);var k={};n(k,{AN_PLUS_B:()=>_,ATTRIBUTE_SELECTOR:()=>O,BIT_1:()=>d,BIT_10:()=>u,BIT_100:()=>Y,BIT_1000:()=>F,BIT_10000:()=>G,BIT_100000:()=>b,CLASS_SELECTOR:()=>N,COMBINATOR:()=>I,DOCUMENT_FRAGMENT_NODE:()=>f,DOCUMENT_NODE:()=>X,DOCUMENT_POSITION_CONTAINED_BY:()=>w,DOCUMENT_POSITION_CONTAINS:()=>h,DOCUMENT_POSITION_PRECEDING:()=>g,ELEMENT_NODE:()=>H,IDENTIFIER:()=>R,ID_SELECTOR:()=>C,NOT_SUPPORTED_ERR:()=>D,NTH:()=>L,PSEUDO_CLASS_SELECTOR:()=>P,PSEUDO_ELEMENT_SELECTOR:()=>l,RAW:()=>A,SELECTOR:()=>B,SELECTOR_LIST:()=>M,SHOW_ELEMENT:()=>j,STRING:()=>U,SYNTAX_ERR:()=>i,TEXT_NODE:()=>W,TYPE_FROM:()=>m,TYPE_SELECTOR:()=>a,TYPE_TO:()=>y});module.exports=S(k);const _="AnPlusB",O="AttributeSelector",N="ClassSelector",I="Combinator",C="IdSelector",R="Identifier",D="NotSupportedError",L="Nth",P="PseudoClassSelector",l="PseudoElementSelector",A="Raw",B="Selector",M="SelectorList",U="String",i="SyntaxError",a="TypeSelector",d=1,u=2,Y=4,F=8,G=16,b=32,m=8,y=-1,H=1,W=3,X=9,f=11,g=2,h=8,w=16,j=1;0&&(module.exports={AN_PLUS_B,ATTRIBUTE_SELECTOR,BIT_1,BIT_10,BIT_100,BIT_1000,BIT_10000,BIT_100000,CLASS_SELECTOR,COMBINATOR,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,ELEMENT_NODE,IDENTIFIER,ID_SELECTOR,NOT_SUPPORTED_ERR,NTH,PSEUDO_CLASS_SELECTOR,PSEUDO_ELEMENT_SELECTOR,RAW,SELECTOR,SELECTOR_LIST,SHOW_ELEMENT,STRING,SYNTAX_ERR,TEXT_NODE,TYPE_FROM,TYPE_SELECTOR,TYPE_TO});
2
2
  //# sourceMappingURL=constant.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/constant.js"],
4
- "sourcesContent": ["/**\n * constant.js\n */\n\n/* string */\nexport const AN_PLUS_B = 'AnPlusB';\nexport const ATTRIBUTE_SELECTOR = 'AttributeSelector';\nexport const CLASS_SELECTOR = 'ClassSelector';\nexport const COMBINATOR = 'Combinator';\nexport const ID_SELECTOR = 'IdSelector';\nexport const IDENTIFIER = 'Identifier';\nexport const NOT_SUPPORTED_ERR = 'NotSupportedError';\nexport const NTH = 'Nth';\nexport const PSEUDO_CLASS_SELECTOR = 'PseudoClassSelector';\nexport const PSEUDO_ELEMENT_SELECTOR = 'PseudoElementSelector';\nexport const RAW = 'Raw';\nexport const SELECTOR = 'Selector';\nexport const SELECTOR_LIST = 'SelectorList';\nexport const STRING = 'String';\nexport const SYNTAX_ERR = 'SyntaxError';\nexport const TYPE_SELECTOR = 'TypeSelector';\n\n/* numeric */\nexport const BIT_1 = 1;\nexport const BIT_10 = 2;\nexport const BIT_100 = 4;\nexport const BIT_1000 = 8;\nexport const BIT_10000 = 16;\nexport const BIT_100000 = 32;\nexport const TYPE_FROM = 8;\nexport const TYPE_TO = -1;\n\n/* Node */\nexport const ELEMENT_NODE = 1;\nexport const TEXT_NODE = 3;\nexport const DOCUMENT_NODE = 9;\nexport const DOCUMENT_FRAGMENT_NODE = 11;\nexport const DOCUMENT_POSITION_PRECEDING = 0x02;\nexport const DOCUMENT_POSITION_CONTAINS = 0x08;\nexport const DOCUMENT_POSITION_CONTAINED_BY = 0x10;\n\n/* NodeFilter */\nexport const SHOW_ELEMENT = 0x00000001;\n"],
4
+ "sourcesContent": ["/**\n * constant.js\n */\n\n/* string */\nexport const AN_PLUS_B = 'AnPlusB';\nexport const ATTRIBUTE_SELECTOR = 'AttributeSelector';\nexport const CLASS_SELECTOR = 'ClassSelector';\nexport const COMBINATOR = 'Combinator';\nexport const ID_SELECTOR = 'IdSelector';\nexport const IDENTIFIER = 'Identifier';\nexport const NOT_SUPPORTED_ERR = 'NotSupportedError';\nexport const NTH = 'Nth';\nexport const PSEUDO_CLASS_SELECTOR = 'PseudoClassSelector';\nexport const PSEUDO_ELEMENT_SELECTOR = 'PseudoElementSelector';\nexport const RAW = 'Raw';\nexport const SELECTOR = 'Selector';\nexport const SELECTOR_LIST = 'SelectorList';\nexport const STRING = 'String';\nexport const SYNTAX_ERR = 'SyntaxError';\nexport const TYPE_SELECTOR = 'TypeSelector';\n\n/* numeric */\nexport const BIT_1 = 0x1;\nexport const BIT_10 = 0x2;\nexport const BIT_100 = 0x4;\nexport const BIT_1000 = 0x8;\nexport const BIT_10000 = 0x10;\nexport const BIT_100000 = 0x20;\nexport const TYPE_FROM = 8;\nexport const TYPE_TO = -1;\n\n/* Node */\nexport const ELEMENT_NODE = 1;\nexport const TEXT_NODE = 3;\nexport const DOCUMENT_NODE = 9;\nexport const DOCUMENT_FRAGMENT_NODE = 11;\nexport const DOCUMENT_POSITION_PRECEDING = 0x2;\nexport const DOCUMENT_POSITION_CONTAINS = 0x8;\nexport const DOCUMENT_POSITION_CONTAINED_BY = 0x10;\n\n/* NodeFilter */\nexport const SHOW_ELEMENT = 0x1;\n"],
5
5
  "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,uBAAAC,EAAA,UAAAC,EAAA,WAAAC,EAAA,YAAAC,EAAA,aAAAC,EAAA,cAAAC,EAAA,eAAAC,EAAA,mBAAAC,EAAA,eAAAC,EAAA,2BAAAC,EAAA,kBAAAC,EAAA,mCAAAC,EAAA,+BAAAC,EAAA,gCAAAC,EAAA,iBAAAC,EAAA,eAAAC,EAAA,gBAAAC,EAAA,sBAAAC,EAAA,QAAAC,EAAA,0BAAAC,EAAA,4BAAAC,EAAA,QAAAC,EAAA,aAAAC,EAAA,kBAAAC,EAAA,iBAAAC,EAAA,WAAAC,EAAA,eAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,kBAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAlC,GAKO,MAAME,EAAY,UACZC,EAAqB,oBACrBO,EAAiB,gBACjBC,EAAa,aACbQ,EAAc,aACdD,EAAa,aACbE,EAAoB,oBACpBC,EAAM,MACNC,EAAwB,sBACxBC,EAA0B,wBAC1BC,EAAM,MACNC,EAAW,WACXC,EAAgB,eAChBE,EAAS,SACTC,EAAa,cACbG,EAAgB,eAGhB5B,EAAQ,EACRC,EAAS,EACTC,EAAU,EACVC,EAAW,EACXC,EAAY,GACZC,EAAa,GACbsB,EAAY,EACZE,EAAU,GAGVhB,EAAe,EACfa,EAAY,EACZjB,EAAgB,EAChBD,EAAyB,GACzBI,EAA8B,EAC9BD,EAA6B,EAC7BD,EAAiC,GAGjCa,EAAe",
6
6
  "names": ["constant_exports", "__export", "AN_PLUS_B", "ATTRIBUTE_SELECTOR", "BIT_1", "BIT_10", "BIT_100", "BIT_1000", "BIT_10000", "BIT_100000", "CLASS_SELECTOR", "COMBINATOR", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_PRECEDING", "ELEMENT_NODE", "IDENTIFIER", "ID_SELECTOR", "NOT_SUPPORTED_ERR", "NTH", "PSEUDO_CLASS_SELECTOR", "PSEUDO_ELEMENT_SELECTOR", "RAW", "SELECTOR", "SELECTOR_LIST", "SHOW_ELEMENT", "STRING", "SYNTAX_ERR", "TEXT_NODE", "TYPE_FROM", "TYPE_SELECTOR", "TYPE_TO", "__toCommonJS"]
7
7
  }
@@ -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_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY,\n ELEMENT_NODE, SYNTAX_ERR\n} from './constant.js';\nconst LTR = 'ltr';\nconst RTL = 'rtl';\n\n/* regexp */\nconst INPUT_TYPE =\n /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/;\nconst SHADOW_MODE = /^(?:close|open)$/;\n\n/* bidi */\nconst bidi = bidiFactory();\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.nodeType === ELEMENT_NODE && node.localName === 'slot') {\n let parent = node.parentNode;\n let bool;\n while (parent) {\n const { host, mode, nodeType, parentNode } = parent;\n if (nodeType === DOCUMENT_FRAGMENT_NODE && host &&\n mode && SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n parent = parentNode;\n }\n if (bool) {\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 }\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} - result\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 || INPUT_TYPE.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 (/^(?:plaintext-only|true)$/.test(attr) || 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.nodeType === ELEMENT_NODE && node.ownerDocument) {\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, tagName;\n if (selector && typeof selector === 'string') {\n if (/\\|/.test(selector)) {\n [prefix, tagName] = selector.split('|');\n } else {\n prefix = '*';\n tagName = selector;\n }\n } else {\n throw new DOMException(`invalid selector ${selector}`, SYNTAX_ERR);\n }\n return {\n prefix,\n tagName\n };\n};\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,wBAAAC,EAAA,uBAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAR,GAKA,IAAAS,EAAwB,wBAGxBC,EAGO,yBACP,MAAMC,EAAM,MACNC,EAAM,MAGNC,EACJ,6EACIC,EAAc,mBAGdC,KAAO,EAAAC,SAAY,EAOZb,EAAwB,CAAC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G,CAC7BD,EAAM,GACN,KACF,CACAC,EAASA,EAAO,UAClB,CACF,CACF,EAEF,MAAO,CAAC,CAACD,CACX,EAQab,EAAsB,CAAC4B,EAAK,GAAIhB,EAAO,CAAC,IAAM,CACzD,IAAIC,EACJ,GAAIe,GAAM,OAAOA,GAAO,UAAYhB,EAAK,WAAa,eAAc,CAClE,MAAMe,EAAO,SAASC,CAAE,GAClBC,EAAOjB,EAAK,cAAc,gBAChC,IAAIE,EAASF,EACb,KAAOE,GAAQ,CACb,GAAI,OAAOA,EAAO,cAAiB,YAC/BA,EAAO,aAAaa,CAAI,EAAG,CAC7Bd,EAAM,GACN,KACF,SAAWC,IAAWe,EACpB,MAEFf,EAASA,EAAO,UAClB,CACF,CACA,MAAO,CAAC,CAACD,CACX,EAQaZ,EAAqB,CAACW,EAAO,CAAC,EAAGiB,EAAO,CAAC,IAAM,CAC1D,IAAIhB,EACJ,OAAID,EAAK,WAAa,gBAAgBA,EAAK,iBACrC,CAACiB,GAAQA,EAAK,WAAa,kBAC7BA,EAAOjB,EAAK,eAEVA,IAASiB,EACXhB,EAAM,GACGgB,IACThB,EAAMgB,EAAK,wBAAwBjB,CAAI,EAAI,mCAGxC,CAAC,CAACC,CACX,EAQaX,EAAsB,CAAC4B,EAAUlB,IAAS,CACrD,IAAImB,EAAQC,EACZ,GAAIF,GAAY,OAAOA,GAAa,SAC9B,KAAK,KAAKA,CAAQ,EACpB,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",
4
+ "sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY,\n ELEMENT_NODE, SYNTAX_ERR\n} from './constant.js';\nconst LTR = 'ltr';\nconst RTL = 'rtl';\n\n/* regexp */\nconst INPUT_TYPE =\n /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/;\nconst SHADOW_MODE = /^(?:close|open)$/;\n\n/* bidi */\nconst bidi = bidiFactory();\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.nodeType === ELEMENT_NODE && node.localName === 'slot') {\n let parent = node.parentNode;\n let bool;\n while (parent) {\n const { host, mode, nodeType, parentNode } = parent;\n if (nodeType === DOCUMENT_FRAGMENT_NODE && host &&\n mode && SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n parent = parentNode;\n }\n if (bool) {\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 }\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} - result\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 || INPUT_TYPE.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 (/^(?:plaintext-only|true)$/.test(attr) || 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.nodeType === ELEMENT_NODE && node.ownerDocument) {\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 (/\\|/.test(selector)) {\n [prefix, tagName] = selector.split('|');\n } else {\n prefix = '*';\n tagName = selector;\n }\n } else {\n throw new DOMException(`invalid selector ${selector}`, SYNTAX_ERR);\n }\n return {\n prefix,\n tagName\n };\n};\n"],
5
+ "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,wBAAAC,EAAA,uBAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAR,GAKA,IAAAS,EAAwB,wBAGxBC,EAGO,yBACP,MAAMC,EAAM,MACNC,EAAM,MAGNC,EACJ,6EACIC,EAAc,mBAGdC,KAAO,EAAAC,SAAY,EAOZb,EAAwB,CAACc,EAAO,CAAC,IAAM,CAClD,IAAIC,EACJ,GAAID,EAAK,WAAa,gBAAgBA,EAAK,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AAC,CAACD,CACX,EAQab,EAAsB,CAAC4B,EAAK,GAAIhB,EAAO,CAAC,IAAM,CACzD,IAAIC,EACJ,GAAIe,GAAM,OAAOA,GAAO,UAAYhB,EAAK,WAAa,eAAc,CAClE,MAAMe,EAAO,SAASC,CAAE,GAClBC,EAAOjB,EAAK,cAAc,gBAChC,IAAIE,EAASF,EACb,KAAOE,GAAQ,CACb,GAAI,OAAOA,EAAO,cAAiB,YAC/BA,EAAO,aAAaa,CAAI,EAAG,CAC7Bd,EAAM,GACN,KACF,SAAWC,IAAWe,EACpB,MAEFf,EAASA,EAAO,UAClB,CACF,CACA,MAAO,CAAC,CAACD,CACX,EAQaZ,EAAqB,CAACW,EAAO,CAAC,EAAGiB,EAAO,CAAC,IAAM,CAC1D,IAAIhB,EACJ,OAAID,EAAK,WAAa,gBAAgBA,EAAK,iBACrC,CAACiB,GAAQA,EAAK,WAAa,kBAC7BA,EAAOjB,EAAK,eAEVA,IAASiB,EACXhB,EAAM,GACGgB,IACThB,EAAMgB,EAAK,wBAAwBjB,CAAI,EAAI,mCAGxC,CAAC,CAACC,CACX,EAQaX,EAAsB,CAAC4B,EAAUlB,IAAS,CACrD,IAAImB,EACAC,EACJ,GAAIF,GAAY,OAAOA,GAAa,SAC9B,KAAK,KAAKA,CAAQ,EACpB,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", "isNamespaceDeclared", "isSameOrDescendant", "selectorToNodeProps", "__toCommonJS", "import_bidi_js", "import_constant", "LTR", "RTL", "INPUT_TYPE", "SHADOW_MODE", "bidi", "bidiFactory", "node", "res", "parent", "bool", "host", "mode", "nodeType", "parentNode", "nodes", "item", "nodeDir", "localName", "text", "level", "parentNodeType", "attr", "ns", "root", "selector", "prefix", "tagName"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var j=Object.create;var L=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var Y=(y,a)=>{for(var e in a)L(y,e,{get:a[e],enumerable:!0})},R=(y,a,e,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let h of W(a))!G.call(y,h)&&h!==e&&L(y,h,{get:()=>a[h],enumerable:!(o=H(a,h))||o.enumerable});return y};var X=(y,a,e)=>(e=y!=null?j(q(y)):{},R(a||!y||!y.__esModule?L(e,"default",{value:y,enumerable:!0}):e,y)),Z=y=>R(L({},"__esModule",{value:!0}),y);var ee={};Y(ee,{Matcher:()=>Q});module.exports=Z(ee);var D=X(require("is-potential-custom-element-name"),1),k=require("./dom-util.js"),g=require("./parser.js"),b=require("./constant.js");const $="all",T="first",v="lineal",S="self",U=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,C=/^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/,M=/^a(?:rea)?$/,B=/^d(?:etails|ialog)$/,O=/^(?:checkbox|radio)$/,x=/^(?:(?:emai|te|ur)l|number|password|search|text)$/,z=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,F=/^(?:button|reset)$/,V=/^(?:image|submit)$/,I=/^(?:date(?:time-local)?|month|time|week)$/,K=/^(?:(?:ha|i)s|not|where)$/,J=/^nth-(?:last-)?(?:child|of-type)$/;class Q{#s;#l;#a;#e;#r;#t;#o;#c;#i;constructor(a,e,o={}){const{sort:h,warn:c}=o;this.#l=new Map([[b.PSEUDO_ELEMENT_SELECTOR,b.BIT_1],[b.ID_SELECTOR,b.BIT_10],[b.CLASS_SELECTOR,b.BIT_100],[b.TYPE_SELECTOR,b.BIT_1000],[b.ATTRIBUTE_SELECTOR,b.BIT_10000],[b.PSEUDO_CLASS_SELECTOR,b.BIT_100000]]),this.#a=new WeakMap,this.#o=a,this.#e=e,this.#c=!!h,this.#i=!!c,[this.#s,this.#r]=this._prepare(a),this.#t=this._getRoot(e)}_onError(a){if(a instanceof DOMException&&a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw a}_getRoot(a=this.#e){let e,o;switch(a.nodeType){case b.DOCUMENT_NODE:{e=a,o=a;break}case b.DOCUMENT_FRAGMENT_NODE:{e=a.ownerDocument,o=a;break}case b.ELEMENT_NODE:{if((0,k.isSameOrDescendant)(a))e=a.ownerDocument,o=a.ownerDocument;else{let h=a;for(;h&&h.parentNode;)h=h.parentNode;e=h.ownerDocument,o=h}break}default:throw new TypeError(`Unexpected node ${a.nodeName}`)}return{document:e,root:o}}_sortLeaves(a){const e=[...a];return e.length>1&&e.sort((o,h)=>{const{type:c}=o,{type:d}=h,p=this.#l.get(c),u=this.#l.get(d);let t;return p===u?t=0:p>u?t=1:t=-1,t}),e}_prepare(a=this.#o){const e=(0,g.parseSelector)(a),o=(0,g.walkAST)(e),h=[],c=[];let d=0;for(const[...p]of o){const u=[];let t=p.shift();if(t&&t.type!==b.COMBINATOR){const l=new Set;for(;t;){if(t.type===b.COMBINATOR){const[n]=p;if(n.type===b.COMBINATOR){const f=`Invalid combinator ${t.name}${n.name}`;throw new DOMException(f,b.SYNTAX_ERR)}u.push({combo:t,leaves:this._sortLeaves(l)}),l.clear()}else t&&l.add(t);if(p.length)t=p.shift();else{u.push({combo:null,leaves:this._sortLeaves(l)}),l.clear();break}}}h.push({branch:u,find:null,skip:!1}),c[d]=new Set,d++}return[h,c]}_collectNthChild(a,e){const{a:o,b:h,reverse:c,selector:d}=a,{parentNode:p}=e,u=new Set;let t;if(d&&(this.#a.has(d)?t=this.#a.get(d):(t=(0,g.walkAST)(d),this.#a.set(d,t))),p){const l=[...p.children],n=l.length;if(n){const f=new Set;if(t){const r=t.length;for(const s of l){let i;for(let m=0;m<r;m++){const N=t[m];if(i=this._matchLeaves(N,s),!i)break}i&&f.add(s)}}if(c&&l.reverse(),o===0){if(h>0&&h<=n){if(f.size)for(let r=0;r<n;r++){const s=l[r];if(f.has(s)){u.add(s);break}}else if(!d){const r=l[h-1];u.add(r)}}}else{let r=h-1;if(o>0)for(;r<0;)r+=o;if(r>=0&&r<n){let s=o>0?0:h-1;for(let i=0;i<n&&r>=0&&r<n;i++){const m=l[i];f.size?f.has(m)&&(s===r&&(u.add(m),r+=o),o>0?s++:s--):i===r&&(d||u.add(m),r+=o)}}}}}else{const{root:l}=this.#t;if(l.nodeType===b.ELEMENT_NODE&&e===l&&o+h===1)if(t){const n=t.length;let f;for(let r=0;r<n;r++){const s=t[r];if(f=this._matchLeaves(s,e),f)break}f&&u.add(e)}else u.add(e)}return u}_collectNthOfType(a,e){const{a:o,b:h,reverse:c}=a,{localName:d,parentNode:p,prefix:u}=e,t=new Set;if(p){const l=[...p.children],n=l.length;if(n)if(c&&l.reverse(),o===0){if(h>0&&h<=n){let f=0;for(let r=0;r<n;r++){const s=l[r],{localName:i,prefix:m}=s;if(i===d&&m===u){if(f===h-1){t.add(s);break}f++}}}}else{let f=h-1;if(o>0)for(;f<0;)f+=o;if(f>=0&&f<n){let r=o>0?0:h-1;for(let s=0;s<n;s++){const i=l[s],{localName:m,prefix:N}=i;if(m===d&&N===u){if(r===f&&(t.add(i),f+=o),f<0||f>=n)break;o>0?r++:r--}}}}}else{const{root:l}=this.#t;l.nodeType===b.ELEMENT_NODE&&e===l&&o+h===1&&t.add(e)}return t}_matchAnPlusB(a,e,o){const{nth:{a:h,b:c,name:d},selector:p}=a,u=(0,g.unescapeSelector)(d),t=new Map;u?(u==="even"?(t.set("a",2),t.set("b",0)):u==="odd"&&(t.set("a",2),t.set("b",1)),/last/.test(o)&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof c=="string"&&/-?\d+/.test(c)?t.set("b",c*1):t.set("b",0),/last/.test(o)&&t.set("reverse",!0));let l=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(o)){p&&t.set("selector",p);const n=Object.fromEntries(t),f=this._collectNthChild(n,e);f.size&&(l=f)}else if(/^nth-(?:last-)?of-type$/.test(o)){const n=Object.fromEntries(t),f=this._collectNthOfType(n,e);f.size&&(l=f)}}return l}_matchPseudoElementSelector(a,e={}){const{forgive:o}=e;switch(a){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"part":case"placeholder":case"selection":case"slotted":case"target-text":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${a}`,b.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${a}`,b.NOT_SUPPORTED_ERR)}else if(!o)throw new DOMException(`Unknown pseudo-element ::${a}`,b.SYNTAX_ERR)}}_matchDirectionPseudoClass(a,e){const o=(0,g.unescapeSelector)(a.name),h=(0,k.getDirectionality)(e);let c;return o===h&&(c=e),c??null}_matchLanguagePseudoClass(a,e){const o=(0,g.unescapeSelector)(a.name);let h;if(o){if(o==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let c=e.parentNode;for(;c;){if(c.hasAttribute("lang")){c.getAttribute("lang")&&(h=e);break}c=c.parentNode}}else if(/[A-Z\d-]+/i.test(o)){const c="[A-Z\\d]+",d=`(?:-${c})*`;let p;if(/-/.test(o)){const[u,t,...l]=o.split("-");let n;u==="*"?n=`${c}${d}`:n=`${u}${d}`;const f=`-${t}${d}`,r=l.length;let s="";if(r)for(let i=0;i<r;i++)s+=`-${l[i]}${d}`;p=new RegExp(`^${n}${f}${s}$`,"i")}else p=new RegExp(`^${o}${d}$`,"i");if(e.hasAttribute("lang"))p.test(e.getAttribute("lang"))&&(h=e);else{let u=e.parentNode;for(;u;){if(u.hasAttribute("lang")){const t=u.getAttribute("lang");p.test(t)&&(h=e);break}u=u.parentNode}}}}return h??null}_matchHasPseudoFunc(a,e){let o;if(Array.isArray(a)&&a.length){const[h]=a,{type:c}=h;let d;c===b.COMBINATOR?d=a.shift():d={name:" ",type:b.COMBINATOR};const p=[];for(;a.length;){const[l]=a,{type:n}=l;if(n===b.COMBINATOR)break;p.push(a.shift())}const u={combo:d,leaves:p},t=this._matchCombinator(u,e,{find:"next"});if(t.size)if(a.length){for(const l of t)if(o=this._matchHasPseudoFunc(Object.assign([],a),l),o)break}else o=!0}return!!o}_matchLogicalPseudoFunc(a,e){const{astName:o="",branches:h=[],selector:c="",twigBranches:d=[]}=a;let p;if(o==="has")if(c.includes(":has("))p=null;else{let u;const t=h.length;for(let l=0;l<t;l++){const n=h[l];if(u=this._matchHasPseudoFunc(Object.assign([],n),e),u)break}u&&(p=e)}else{const u=/^(?:is|where)$/.test(o);let t;const l=d.length;for(let n=0;n<l;n++){const f=d[n],r=f.length-1,{leaves:s}=f[r];if(t=this._matchLeaves(s,e,{forgive:u}),t&&r>0){let i=new Set([e]);for(let m=r-1;m>=0;m--){const N=f[m],w=[];for(const _ of i){const A=this._matchCombinator(N,_,{forgive:u,find:"prev"});A.size&&w.push(...A)}const E=new Set(w);if(E.size)if(m===0){t=!0;break}else i=E;else{t=!1;break}}}if(t)break}o==="not"?t||(p=e):t&&(p=e)}return p??null}_matchPseudoClassSelector(a,e,o={}){const{children:h}=a,{localName:c,parentNode:d}=e,{forgive:p}=o,u=(0,g.unescapeSelector)(a.name);let t=new Set;if(K.test(u)){let l;if(this.#a.has(a))l=this.#a.get(a);else{const f=(0,g.walkAST)(a),r=[],s=[];for(const[...i]of f){for(const E of i){const _=(0,g.generateCSS)(E);r.push(_)}const m=[],N=new Set;let w=i.shift();for(;w;)if(w.type===b.COMBINATOR?(m.push({combo:w,leaves:[...N]}),N.clear()):w&&N.add(w),i.length)w=i.shift();else{m.push({combo:null,leaves:[...N]}),N.clear();break}s.push(m)}l={astName:u,branches:f,twigBranches:s,selector:r.join(",")},this.#a.set(a,l)}const n=this._matchLogicalPseudoFunc(l,e);n&&t.add(n)}else if(Array.isArray(h)){const[l]=h;if(J.test(u)){const n=this._matchAnPlusB(l,e,u);n.size&&(t=n)}else if(u==="dir"){const n=this._matchDirectionPseudoClass(l,e);n&&t.add(n)}else if(u==="lang"){const n=this._matchLanguagePseudoClass(l,e);n&&t.add(n)}else switch(u){case"current":case"nth-col":case"nth-last-col":{if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}()`,b.NOT_SUPPORTED_ERR);break}default:if(!p)throw new DOMException(`Unknown pseudo-class :${u}()`,b.SYNTAX_ERR)}}else{const{document:l,root:n}=this.#t,{documentElement:f}=l,r=new URL(l.URL);switch(u){case"any-link":case"link":{M.test(c)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(M.test(c)&&e.hasAttribute("href")){const s=new URL(e.getAttribute("href"),r.href);s.origin===r.origin&&s.pathname===r.pathname&&t.add(e)}break}case"visited":break;case"target":{(0,k.isSameOrDescendant)(e)&&r.hash&&e.id&&r.hash===`#${e.id}`&&t.add(e);break}case"target-within":{if(r.hash){const s=r.hash.replace(/^#/,"");let i=l.getElementById(s);for(;i;){if(i===e){t.add(e);break}i=i.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?e===this.#e&&t.add(e):e===f&&t.add(e);break}case"focus":{e===l.activeElement&&t.add(e);break}case"focus-within":{let s=l.activeElement;for(;s;){if(s===e){t.add(e);break}s=s.parentNode}break}case"open":{B.test(c)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{B.test(c)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(U.test(c)||(0,D.default)(c))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let s=d;for(;s&&s.localName!=="fieldset";)s=s.parentNode;s&&s.hasAttribute("disabled")&&d.localName!=="legend"&&t.add(e)}break}case"enabled":{(U.test(c)||(0,D.default)(c))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(c){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(c){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||I.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let s;c==="textarea"?s=e:c==="input"&&(e.hasAttribute("type")?x.test(e.getAttribute("type"))&&(s=e):s=e),s&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&e.value===""&&t.add(e);break}case"checked":{(c==="input"&&e.hasAttribute("type")&&O.test(e.getAttribute("type"))&&e.checked||c==="option"&&e.selected)&&t.add(e);break}case"indeterminate":{if(c==="input"&&e.type==="checkbox"&&e.indeterminate||c==="progress"&&!e.hasAttribute("value"))t.add(e);else if(c==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const s=e.name;let i=e.parentNode;for(;i&&i.localName!=="form";)i=i.parentNode;i||(i=f);const m=[...i.getElementsByTagName("input")];let N;for(const w of m)if(w.getAttribute("type")==="radio"&&(s?w.getAttribute("name")===s&&(N=!!w.checked):w.hasAttribute("name")||(N=!!w.checked),N))break;N||t.add(e)}break}case"default":{if(c==="button"&&!(e.hasAttribute("type")&&F.test(e.getAttribute("type")))||c==="input"&&e.hasAttribute("type")&&V.test(e.getAttribute("type"))){let s=e.parentNode;for(;s&&s.localName!=="form";)s=s.parentNode;if(s){const i=l.createNodeIterator(s,b.SHOW_ELEMENT);let m=i.nextNode();for(;m;){const N=m.localName;let w;if(N==="button"?w=!(m.hasAttribute("type")&&F.test(m.getAttribute("type"))):N==="input"&&(w=m.hasAttribute("type")&&V.test(m.getAttribute("type"))),w){m===e&&t.add(e);break}m=i.nextNode()}}}else if(c==="input"&&e.hasAttribute("type")&&O.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(c==="option"){let s=!1,i=d;for(;i&&i.localName!=="datalist";){if(i.localName==="select"){(i.multiple||i.hasAttribute("multiple"))&&(s=!0);break}i=i.parentNode}if(s)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const m=d.firstElementChild,N=new Set;let w=m;for(;w;){if(w.selected||w.hasAttribute("selected")){N.add(w);break}w=w.nextElementSibling}N.size||N.add(m),N.has(e)&&t.add(e)}}break}case"valid":{if(C.test(c))e.checkValidity()&&t.add(e);else if(/^fieldset$/.test(c)){const s=l.createNodeIterator(e,b.SHOW_ELEMENT);let i=s.nextNode();i===e&&(i=s.nextNode());let m;for(;i&&!(C.test(i.localName)&&(m=i.checkValidity(),!m));)i=s.nextNode();m&&t.add(e)}break}case"invalid":{if(C.test(c))e.checkValidity()||t.add(e);else if(/^fieldset$/.test(c)){const s=l.createNodeIterator(e,b.SHOW_ELEMENT);let i=s.nextNode();i===e&&(i=s.nextNode());let m;for(;i&&!(C.test(i.localName)&&(m=i.checkValidity(),!m));)i=s.nextNode();m||t.add(e)}break}case"in-range":{c==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&z.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{c==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&z.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let s;if(/^(?:select|textarea)$/.test(c))s=e;else if(c==="input")if(e.hasAttribute("type")){const i=e.getAttribute("type");(x.test(i)||O.test(i)||I.test(i)||i==="file")&&(s=e)}else s=e;s&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let s;if(/^(?:select|textarea)$/.test(c))s=e;else if(c==="input")if(e.hasAttribute("type")){const i=e.getAttribute("type");(x.test(i)||O.test(i)||I.test(i)||i==="file")&&(s=e)}else s=e;s&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===f&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const s=e.childNodes.values();let i;for(const m of s)if(i=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!i)break;i&&t.add(e)}else t.add(e);break}case"first-child":{(d&&e===d.firstElementChild||n.nodeType===b.ELEMENT_NODE&&e===n)&&t.add(e);break}case"last-child":{(d&&e===d.lastElementChild||n.nodeType===b.ELEMENT_NODE&&e===n)&&t.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||n.nodeType===b.ELEMENT_NODE&&e===n)&&t.add(e);break}case"first-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);s&&t.add(s)}else n.nodeType===b.ELEMENT_NODE&&e===n&&t.add(e);break}case"last-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1,reverse:!0},e);s&&t.add(s)}else n.nodeType===b.ELEMENT_NODE&&e===n&&t.add(e);break}case"only-of-type":{if(d){const[s]=this._collectNthOfType({a:0,b:1},e);if(s===e){const[i]=this._collectNthOfType({a:0,b:1,reverse:!0},e);i===e&&t.add(e)}}else n.nodeType===b.ELEMENT_NODE&&e===n&&t.add(e);break}case"after":case"before":case"first-letter":case"first-line":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${u}`,b.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.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR);break}default:if(u.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR)}else if(!p)throw new DOMException(`Unknown pseudo-class :${u}`,b.SYNTAX_ERR)}}return t}_matchAttributeSelector(a,e){const{flags:o,matcher:h,name:c,value:d}=a;if(typeof o=="string"&&!/^[is]$/i.test(o))throw new DOMException("Invalid attribute selector",b.SYNTAX_ERR);const{attributes:p}=e;let u;if(p&&p.length){const{document:t}=this.#t;let l;t.contentType==="text/html"?typeof o=="string"&&/^s$/i.test(o)?l=!1:l=!0:typeof o=="string"&&/^i$/i.test(o)?l=!0:l=!1;let{name:n}=c;n=(0,g.unescapeSelector)(n),l&&(n=n.toLowerCase());const f=new Set;if(/\|/.test(n)){const{prefix:r,tagName:s}=(0,k.selectorToNodeProps)(n);for(let{name:i,value:m}of p)switch(l&&(i=i.toLowerCase(),m=m.toLowerCase()),r){case"":{s===i&&f.add(m);break}case"*":{/:/.test(i)?i.endsWith(`:${s}`)&&f.add(m):s===i&&f.add(m);break}default:if(/:/.test(i)){const[N,w]=i.split(":");r===N&&s===w&&(0,k.isNamespaceDeclared)(r,e)&&f.add(m)}}}else for(let{name:r,value:s}of p)if(l&&(r=r.toLowerCase(),s=s.toLowerCase()),/:/.test(r)){const[i,m]=r.split(":");if(i==="xml"&&m==="lang")continue;n===m&&f.add(s)}else n===r&&f.add(s);if(f.size){const{name:r,value:s}=d||{};let i;switch(r?l?i=r.toLowerCase():i=r:s?l?i=s.toLowerCase():i=s:s===""&&(i=s),h){case"=":{typeof i=="string"&&f.has(i)&&(u=e);break}case"~=":{if(i&&typeof i=="string"){for(const m of f)if(new Set(m.split(/\s+/)).has(i)){u=e;break}}break}case"|=":{if(i&&typeof i=="string"){let m;for(const N of f)if(N===i||N.startsWith(`${i}-`)){m=N;break}m&&(u=e)}break}case"^=":{if(i&&typeof i=="string"){let m;for(const N of f)if(N.startsWith(`${i}`)){m=N;break}m&&(u=e)}break}case"$=":{if(i&&typeof i=="string"){let m;for(const N of f)if(N.endsWith(`${i}`)){m=N;break}m&&(u=e)}break}case"*=":{if(i&&typeof i=="string"){let m;for(const N of f)if(N.includes(`${i}`)){m=N;break}m&&(u=e)}break}case null:default:u=e}}}return u??null}_matchClassSelector(a,e){const o=(0,g.unescapeSelector)(a.name);let h;return e.classList.contains(o)&&(h=e),h??null}_matchIDSelector(a,e){const{id:o}=e,h=(0,g.unescapeSelector)(a.name);let c;return h===o&&(c=e),c??null}_matchTypeSelector(a,e){const o=(0,g.unescapeSelector)(a.name),{localName:h,prefix:c}=e,{document:d}=this.#t;let{prefix:p,tagName:u}=(0,k.selectorToNodeProps)(o,e);d.contentType==="text/html"&&(p=p.toLowerCase(),u=u.toLowerCase());let t,l;/:/.test(h)?[t,l]=h.split(":"):(t=c||"",l=h);let n;return p===""&&t===""?e.namespaceURI===null&&(u==="*"||u===l)&&(n=e):p==="*"?(u==="*"||u===l)&&(n=e):p===t&&(0,k.isNamespaceDeclared)(p,e)&&(u==="*"||u===l)&&(n=e),n??null}_matchSelector(a,e,o){const{type:h}=a;let c=new Set;if(e.nodeType===b.ELEMENT_NODE)switch(h){case b.ATTRIBUTE_SELECTOR:{const d=this._matchAttributeSelector(a,e);d&&c.add(d);break}case b.CLASS_SELECTOR:{const d=this._matchClassSelector(a,e);d&&c.add(d);break}case b.ID_SELECTOR:{const d=this._matchIDSelector(a,e);d&&c.add(d);break}case b.PSEUDO_CLASS_SELECTOR:{const d=this._matchPseudoClassSelector(a,e,o);d.size&&(c=d);break}case b.PSEUDO_ELEMENT_SELECTOR:{const d=(0,g.unescapeSelector)(a.name);this._matchPseudoElementSelector(d,o);break}case b.TYPE_SELECTOR:default:{const d=this._matchTypeSelector(a,e);d&&c.add(d)}}return c}_matchLeaves(a,e,o){let h;for(const c of a)if(h=this._matchSelector(c,e,o).has(e),!h)break;return!!h}_findDescendantNodes(a,e){const[o,...h]=a,{type:c}=o,d=(0,g.unescapeSelector)(o.name),p=h.length>0,u=new Set;let t=!1;switch(c){case b.ID_SELECTOR:{const{root:l}=this.#t;if(l.nodeType===b.ELEMENT_NODE)t=!0;else{const n=l.getElementById(d);if(n&&n!==e){const f=(0,k.isSameOrDescendant)(n,e);let r;f&&(r=n),r&&(p?this._matchLeaves(h,r)&&u.add(r):u.add(r))}}break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:t=!0}return{nodes:u,pending:t}}_matchCombinator(a,e,o={}){const{combo:h,leaves:c}=a,{name:d}=h,{find:p,forgive:u}=o;let t=new Set;if(p==="next")switch(d){case"+":{const l=e.nextElementSibling;l&&this._matchLeaves(c,l,{forgive:u})&&t.add(l);break}case"~":{let l=e.nextElementSibling;for(;l;)this._matchLeaves(c,l,{forgive:u})&&t.add(l),l=l.nextElementSibling;break}case">":{const l=[...e.children];for(const n of l)this._matchLeaves(c,n,{forgive:u})&&t.add(n);break}case" ":default:{const{nodes:l,pending:n}=this._findDescendantNodes(c,e);if(l.size)t=l;else if(n){const{document:f}=this.#t,r=f.createNodeIterator(e,b.SHOW_ELEMENT);let s=r.nextNode();for(s===e&&(s=r.nextNode());s;)this._matchLeaves(c,s,{forgive:u})&&t.add(s),s=r.nextNode()}}}else switch(d){case"+":{const l=e.previousElementSibling;l&&this._matchLeaves(c,l,{forgive:u})&&t.add(l);break}case"~":{const l=[];let n=e.previousElementSibling;for(;n;)this._matchLeaves(c,n,{forgive:u})&&l.push(n),n=n.previousElementSibling;l.length&&(t=new Set(l.reverse()));break}case">":{const l=e.parentNode;l&&this._matchLeaves(c,l,{forgive:u})&&t.add(l);break}case" ":default:{const l=[];let n=e.parentNode;for(;n;)this._matchLeaves(c,n,{forgive:u})&&l.push(n),n=n.parentNode;l.length&&(t=new Set(l.reverse()))}}return t}_findNodes(a,e){const{leaves:[o,...h]}=a,{type:c}=o,d=(0,g.unescapeSelector)(o.name),p=h.length>0,{document:u,root:t}=this.#t;let l=new Set,n=!1;switch(c){case b.ID_SELECTOR:{let f;if(e===S)this._matchLeaves([o],this.#e)&&(f=this.#e);else if(e===v){let r=this.#e;for(;r;){if(this._matchLeaves([o],r)){f=r;break}r=r.parentNode}}else t.nodeType===b.ELEMENT_NODE?n=!0:f=t.getElementById(d);f&&(p?this._matchLeaves(h,f)&&l.add(f):l.add(f));break}case b.CLASS_SELECTOR:{const f=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this.#e.classList.contains(d)&&f.push(this.#e);else if(e===v){let r=this.#e;for(;r&&r.nodeType===b.ELEMENT_NODE;)r.classList.contains(d)&&f.push(r),r=r.parentNode}else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const r=[...t.children];for(const s of r){s.classList.contains(d)&&f.push(s);const i=[...s.getElementsByClassName(d)];f.push(...i)}}else{const r=[...t.getElementsByClassName(d)];f.push(...r)}if(f.length)if(p)for(const r of f)this._matchLeaves(h,r)&&l.add(r);else l=new Set(f);break}case b.TYPE_SELECTOR:{const f=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this._matchLeaves([o],this.#e)&&f.push(this.#e);else if(e===v){let r=this.#e;for(;r&&r.nodeType===b.ELEMENT_NODE;)this._matchLeaves([o],r)&&f.push(r),r=r.parentNode}else if(u.contentType!=="text/html"||/[*|]/.test(d))n=!0;else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const r=d.toLowerCase(),s=[...t.children];for(const i of s){i.localName===r&&f.push(i);const m=[...i.getElementsByTagName(d)];f.push(...m)}}else{const r=[...t.getElementsByTagName(d)];f.push(...r)}if(f.length)if(p)for(const r of f)this._matchLeaves(h,r)&&l.add(r);else l=new Set(f);break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:{const f=[];if(e===S)this._matchLeaves([o],this.#e)&&f.push(this.#e);else if(e===v){let r=this.#e;for(;r;)this._matchLeaves([o],r)&&f.push(r),r=r.parentNode}else n=!0;if(f.length)if(p)for(const r of f)this._matchLeaves(h,r)&&l.add(r);else l=new Set(f)}}return{nodes:l,pending:n}}_getFirstTwig(a){const e=a.length-1,o=a[0];let h,c;if(e){const d=a[e],{leaves:[{type:p}]}=d;p===b.PSEUDO_ELEMENT_SELECTOR||p===b.ID_SELECTOR?(h="prev",c=d):(h="next",c=o)}else h="prev",c=o;return{find:h,twig:c}}_collectNodes(a){const e=this.#s.values();if(a===$||a===T){const o=new Set;let h=0;for(const{branch:c}of e){const{find:d,twig:p}=this._getFirstTwig(c),{nodes:u,pending:t}=this._findNodes(p,a);u.size?this.#r[h]=u:t?o.add(new Map([["index",h],["twig",p]])):this.#s[h].skip=!0,this.#s[h].find=d,h++}if(o.size){const{document:c,root:d}=this.#t,p=c.createNodeIterator(d,b.SHOW_ELEMENT);let u=p.nextNode();for(;u;){let t=!1;if(this.#e.nodeType===b.ELEMENT_NODE?t=(0,k.isSameOrDescendant)(u,this.#e):t=!0,t)for(const l of o){const{leaves:n}=l.get("twig");if(this._matchLeaves(n,u)){const r=l.get("index");this.#r[r].add(u)}}u=p.nextNode()}}}else{let o=0;for(const{branch:h}of e){const c=h[h.length-1],{nodes:d}=this._findNodes(c,a);d.size?this.#r[o]=d:this.#s[o].skip=!0,this.#s[o].find="prev",o++}}return[this.#s,this.#r]}_matchNodes(a){const[...e]=this.#s,o=e.length;let h=new Set;for(let c=0;c<o;c++){const{branch:d,find:p,skip:u}=e[c],t=d.length;if(!u&&t){const l=this.#r[c],n=t-1;if(n===0)if((a===$||a===T)&&this.#e.nodeType===b.ELEMENT_NODE){for(const f of l)if(f!==this.#e&&(0,k.isSameOrDescendant)(f,this.#e)&&(h.add(f),a===T))break}else if(a===T){const[f]=[...l];h.add(f)}else{const f=[...h],r=[...l];h=new Set([...f,...r])}else if(p==="next"){let{combo:f}=d[0];for(const r of l){let s=new Set([r]);for(let i=1;i<t;i++){const{combo:m,leaves:N}=d[i],w=[];for(const _ of s){const A={combo:f,leaves:N},P=this._matchCombinator(A,_,{find:p});P.size&&w.push(...P)}const E=new Set(w);if(E.size)if(i===n){if(a===T){const[_]=[...E];h.add(_)}else{const _=[...h],A=[...E];h=new Set([..._,...A])}break}else f=m,s=E;else break}}}else for(const f of l){let r=new Set([f]),s;for(let i=n-1;i>=0;i--){const m=d[i],N=[];for(const E of r){const _=this._matchCombinator(m,E,{find:p});_.size&&N.push(..._)}const w=new Set(N);if(w.size)if(s=!0,i===0){h.add(f);break}else r=w;else{s=!1;break}}if(s&&a!==$)break}}}return h}_find(a){return this._collectNodes(a),this._matchNodes(a)}_sortNodes(a){const e=[...a];return e.length>1&&e.sort((o,h)=>{let c;const d=o.compareDocumentPosition(h);return d&b.DOCUMENT_POSITION_PRECEDING||d&b.DOCUMENT_POSITION_CONTAINS?c=1:c=-1,c}),e}matches(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let a;try{a=this._find(S).has(this.#e)}catch(e){this._onError(e)}return!!a}closest(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let a;try{const e=this._find(v);let o=this.#e;for(;o;){if(e.has(o)){a=o;break}o=o.parentNode}}catch(e){this._onError(e)}return a??null}querySelector(){let a;try{const e=this._find(T);e.delete(this.#e),e.size>1?[a]=this._sortNodes(e):e.size&&([a]=[...e])}catch(e){this._onError(e)}return a??null}querySelectorAll(){const a=[];try{const e=this._find($);e.delete(this.#e),e.size>1&&this.#c?a.push(...this._sortNodes(e)):e.size&&a.push(...e)}catch(e){this._onError(e)}return a}}0&&(module.exports={Matcher});
1
+ var G=Object.create;var $=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var K=(_,r)=>{for(var e in r)$(_,e,{get:r[e],enumerable:!0})},U=(_,r,e,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let h of q(r))!X.call(_,h)&&h!==e&&$(_,h,{get:()=>r[h],enumerable:!(c=W(r,h))||c.enumerable});return _};var Z=(_,r,e)=>(e=_!=null?G(Y(_)):{},U(r||!_||!_.__esModule?$(e,"default",{value:_,enumerable:!0}):e,_)),J=_=>U($({},"__esModule",{value:!0}),_);var ie={};K(ie,{Matcher:()=>se});module.exports=J(ie);var R=Z(require("is-potential-custom-element-name"),1),k=require("./dom-util.js"),g=require("./parser.js"),b=require("./constant.js");const P="[A-Z\\d]+",T=`(?:-${P})*`,C="all",v="first",x="lineal",S="self",B=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,O=/^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/,z=/^a(?:rea)?$/,F=/^d(?:etails|ialog)$/,I=/^(?:checkbox|radio)$/,L=/^(?:(?:emai|te|ur)l|number|password|search|text)$/,V=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,j=/^(?:button|reset)$/,H=/^(?:image|submit)$/,D=/^(?:date(?:time-local)?|month|time|week)$/,Q=/^(?:(?:ha|i)s|not|where)$/,ee=/^nth-(?:last-)?(?:child|of-type)$/,te=new RegExp(`^(?:\\*-)?${P}${T}$`,"i");class se{#s;#l;#a;#e;#r;#t;#o;#c;#i;constructor(r,e,c={}){const{sort:h,warn:o}=c;this.#l=new Map([[b.PSEUDO_ELEMENT_SELECTOR,b.BIT_1],[b.ID_SELECTOR,b.BIT_10],[b.CLASS_SELECTOR,b.BIT_100],[b.TYPE_SELECTOR,b.BIT_1000],[b.ATTRIBUTE_SELECTOR,b.BIT_10000],[b.PSEUDO_CLASS_SELECTOR,b.BIT_100000]]),this.#a=new WeakMap,this.#o=r,this.#e=e,this.#c=!!h,this.#i=!!o,[this.#s,this.#r]=this._prepare(r),this.#t=this._getRoot(e)}_onError(r){if(r instanceof DOMException&&r.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw r}_getRoot(r=this.#e){let e,c;switch(r.nodeType){case b.DOCUMENT_NODE:{e=r,c=r;break}case b.DOCUMENT_FRAGMENT_NODE:{e=r.ownerDocument,c=r;break}case b.ELEMENT_NODE:{if((0,k.isSameOrDescendant)(r))e=r.ownerDocument,c=r.ownerDocument;else{let h=r;for(;h&&h.parentNode;)h=h.parentNode;e=h.ownerDocument,c=h}break}default:throw new TypeError(`Unexpected node ${r.nodeName}`)}return{document:e,root:c}}_sortLeaves(r){const e=[...r];return e.length>1&&e.sort((c,h)=>{const{type:o}=c,{type:d}=h,p=this.#l.get(o),u=this.#l.get(d);let t;return p===u?t=0:p>u?t=1:t=-1,t}),e}_prepare(r=this.#o){const e=(0,g.parseSelector)(r),c=(0,g.walkAST)(e),h=[],o=[];let d=0;for(const[...p]of c){const u=[];let t=p.shift();if(t&&t.type!==b.COMBINATOR){const s=new Set;for(;t;){if(t.type===b.COMBINATOR){const[f]=p;if(f.type===b.COMBINATOR){const n=`Invalid combinator ${t.name}${f.name}`;throw new DOMException(n,b.SYNTAX_ERR)}u.push({combo:t,leaves:this._sortLeaves(s)}),s.clear()}else t&&s.add(t);if(p.length)t=p.shift();else{u.push({combo:null,leaves:this._sortLeaves(s)}),s.clear();break}}}h.push({branch:u,find:null,skip:!1}),o[d]=new Set,d++}return[h,o]}_collectNthChild(r,e){const{a:c,b:h,reverse:o,selector:d}=r,{parentNode:p}=e,u=new Set;let t;if(d&&(this.#a.has(d)?t=this.#a.get(d):(t=(0,g.walkAST)(d),this.#a.set(d,t))),p){const s=[...p.children],f=s.length;if(f){const n=new Set;if(t){const i=t.length;for(const a of s){let l;for(let m=0;m<i;m++){const N=t[m];if(l=this._matchLeaves(N,a),!l)break}l&&n.add(a)}}if(o&&s.reverse(),c===0){if(h>0&&h<=f){if(n.size)for(let i=0;i<f;i++){const a=s[i];if(n.has(a)){u.add(a);break}}else if(!d){const i=s[h-1];u.add(i)}}}else{let i=h-1;if(c>0)for(;i<0;)i+=c;if(i>=0&&i<f){let a=c>0?0:h-1;for(let l=0;l<f&&i>=0&&i<f;l++){const m=s[l];n.size?n.has(m)&&(a===i&&(u.add(m),i+=c),c>0?a++:a--):l===i&&(d||u.add(m),i+=c)}}}}}else{const{root:s}=this.#t;if(s.nodeType===b.ELEMENT_NODE&&e===s&&c+h===1)if(t){const f=t.length;let n;for(let i=0;i<f;i++){const a=t[i];if(n=this._matchLeaves(a,e),n)break}n&&u.add(e)}else u.add(e)}return u}_collectNthOfType(r,e){const{a:c,b:h,reverse:o}=r,{localName:d,parentNode:p,prefix:u}=e,t=new Set;if(p){const s=[...p.children],f=s.length;if(f)if(o&&s.reverse(),c===0){if(h>0&&h<=f){let n=0;for(let i=0;i<f;i++){const a=s[i],{localName:l,prefix:m}=a;if(l===d&&m===u){if(n===h-1){t.add(a);break}n++}}}}else{let n=h-1;if(c>0)for(;n<0;)n+=c;if(n>=0&&n<f){let i=c>0?0:h-1;for(let a=0;a<f;a++){const l=s[a],{localName:m,prefix:N}=l;if(m===d&&N===u){if(i===n&&(t.add(l),n+=c),n<0||n>=f)break;c>0?i++:i--}}}}}else{const{root:s}=this.#t;s.nodeType===b.ELEMENT_NODE&&e===s&&c+h===1&&t.add(e)}return t}_matchAnPlusB(r,e,c){const{nth:{a:h,b:o,name:d},selector:p}=r,u=(0,g.unescapeSelector)(d),t=new Map;u?(u==="even"?(t.set("a",2),t.set("b",0)):u==="odd"&&(t.set("a",2),t.set("b",1)),/last/.test(c)&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?t.set("b",o*1):t.set("b",0),/last/.test(c)&&t.set("reverse",!0));let s=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){p&&t.set("selector",p);const f=Object.fromEntries(t),n=this._collectNthChild(f,e);n.size&&(s=n)}else if(/^nth-(?:last-)?of-type$/.test(c)){const f=Object.fromEntries(t),n=this._collectNthOfType(f,e);n.size&&(s=n)}}return s}_matchPseudoElementSelector(r,e={}){const{forgive:c}=e;switch(r){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"part":case"placeholder":case"selection":case"slotted":case"target-text":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${r}`,b.NOT_SUPPORTED_ERR);break}default:if(r.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${r}`,b.NOT_SUPPORTED_ERR)}else if(!c)throw new DOMException(`Unknown pseudo-element ::${r}`,b.SYNTAX_ERR)}}_matchDirectionPseudoClass(r,e){const c=(0,g.unescapeSelector)(r.name),h=(0,k.getDirectionality)(e);let o;return c===h&&(o=e),o??null}_matchLanguagePseudoClass(r,e){const c=(0,g.unescapeSelector)(r.name);let h;if(c){if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let o=e.parentNode;for(;o;){if(o.hasAttribute("lang")){o.getAttribute("lang")&&(h=e);break}o=o.parentNode}}else if(te.test(c)){let o;if(/-/.test(c)){const[d,p,...u]=c.split("-");let t;d==="*"?t=`${P}${T}`:t=`${d}${T}`;const s=`-${p}${T}`,f=u.length;let n="";if(f)for(let i=0;i<f;i++)n+=`-${u[i]}${T}`;o=new RegExp(`^${t}${s}${n}$`,"i")}else o=new RegExp(`^${c}${T}$`,"i");if(e.hasAttribute("lang"))o.test(e.getAttribute("lang"))&&(h=e);else{let d=e.parentNode;for(;d;){if(d.hasAttribute("lang")){const p=d.getAttribute("lang");o.test(p)&&(h=e);break}d=d.parentNode}}}}return h??null}_matchHasPseudoFunc(r,e){let c;if(Array.isArray(r)&&r.length){const[h]=r,{type:o}=h;let d;o===b.COMBINATOR?d=r.shift():d={name:" ",type:b.COMBINATOR};const p=[];for(;r.length;){const[s]=r,{type:f}=s;if(f===b.COMBINATOR)break;p.push(r.shift())}const u={combo:d,leaves:p},t=this._matchCombinator(u,e,{find:"next"});if(t.size)if(r.length){for(const s of t)if(c=this._matchHasPseudoFunc(Object.assign([],r),s),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(r,e){const{astName:c="",branches:h=[],selector:o="",twigBranches:d=[]}=r;let p;if(c==="has")if(o.includes(":has("))p=null;else{const u=h.length;let t;for(let s=0;s<u;s++){const f=h[s];if(t=this._matchHasPseudoFunc(Object.assign([],f),e),t)break}t&&(p=e)}else{const u=/^(?:is|where)$/.test(c),t=d.length;let s;for(let f=0;f<t;f++){const n=d[f],i=n.length-1,{leaves:a}=n[i];if(s=this._matchLeaves(a,e,{forgive:u}),s&&i>0){let l=new Set([e]);for(let m=i-1;m>=0;m--){const N=n[m],w=[];for(const y of l){const A=this._matchCombinator(N,y,{forgive:u,find:"prev"});A.size&&w.push(...A)}const E=new Set(w);if(E.size)if(m===0){s=!0;break}else l=E;else{s=!1;break}}}if(s)break}c==="not"?s||(p=e):s&&(p=e)}return p??null}_matchPseudoClassSelector(r,e,c={}){const{children:h}=r,{localName:o,parentNode:d}=e,{forgive:p}=c,u=(0,g.unescapeSelector)(r.name);let t=new Set;if(Q.test(u)){let s;if(this.#a.has(r))s=this.#a.get(r);else{const n=(0,g.walkAST)(r),i=[],a=[];for(const[...l]of n){for(const E of l){const y=(0,g.generateCSS)(E);i.push(y)}const m=[],N=new Set;let w=l.shift();for(;w;)if(w.type===b.COMBINATOR?(m.push({combo:w,leaves:[...N]}),N.clear()):w&&N.add(w),l.length)w=l.shift();else{m.push({combo:null,leaves:[...N]}),N.clear();break}a.push(m)}s={astName:u,branches:n,twigBranches:a,selector:i.join(",")},this.#a.set(r,s)}const f=this._matchLogicalPseudoFunc(s,e);f&&t.add(f)}else if(Array.isArray(h)){const[s]=h;if(ee.test(u)){const f=this._matchAnPlusB(s,e,u);f.size&&(t=f)}else if(u==="dir"){const f=this._matchDirectionPseudoClass(s,e);f&&t.add(f)}else if(u==="lang"){const f=this._matchLanguagePseudoClass(s,e);f&&t.add(f)}else switch(u){case"current":case"nth-col":case"nth-last-col":{if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}()`,b.NOT_SUPPORTED_ERR);break}default:if(!p)throw new DOMException(`Unknown pseudo-class :${u}()`,b.SYNTAX_ERR)}}else{const{document:s,root:f}=this.#t,{documentElement:n}=s,i=new URL(s.URL);switch(u){case"any-link":case"link":{z.test(o)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(z.test(o)&&e.hasAttribute("href")){const a=new URL(e.getAttribute("href"),i.href);a.origin===i.origin&&a.pathname===i.pathname&&t.add(e)}break}case"visited":break;case"target":{(0,k.isSameOrDescendant)(e)&&i.hash&&e.id&&i.hash===`#${e.id}`&&t.add(e);break}case"target-within":{if(i.hash){const a=i.hash.replace(/^#/,"");let l=s.getElementById(a);for(;l;){if(l===e){t.add(e);break}l=l.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?e===this.#e&&t.add(e):e===n&&t.add(e);break}case"focus":{e===s.activeElement&&t.add(e);break}case"focus-within":{let a=s.activeElement;for(;a;){if(a===e){t.add(e);break}a=a.parentNode}break}case"open":{F.test(o)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{F.test(o)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(B.test(o)||(0,R.default)(o))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let a=d;for(;a&&a.localName!=="fieldset";)a=a.parentNode;a&&a.hasAttribute("disabled")&&d.localName!=="legend"&&t.add(e)}break}case"enabled":{(B.test(o)||(0,R.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(o){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||L.test(e.type)||D.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(o){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||L.test(e.type)||D.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,k.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let a;o==="textarea"?a=e:o==="input"&&(e.hasAttribute("type")?L.test(e.getAttribute("type"))&&(a=e):a=e),a&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&e.value===""&&t.add(e);break}case"checked":{(o==="input"&&e.hasAttribute("type")&&I.test(e.getAttribute("type"))&&e.checked||o==="option"&&e.selected)&&t.add(e);break}case"indeterminate":{if(o==="input"&&e.type==="checkbox"&&e.indeterminate||o==="progress"&&!e.hasAttribute("value"))t.add(e);else if(o==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const a=e.name;let l=e.parentNode;for(;l&&l.localName!=="form";)l=l.parentNode;l||(l=n);const m=[...l.getElementsByTagName("input")];let N;for(const w of m)if(w.getAttribute("type")==="radio"&&(a?w.getAttribute("name")===a&&(N=!!w.checked):w.hasAttribute("name")||(N=!!w.checked),N))break;N||t.add(e)}break}case"default":{if(o==="button"&&!(e.hasAttribute("type")&&j.test(e.getAttribute("type")))||o==="input"&&e.hasAttribute("type")&&H.test(e.getAttribute("type"))){let a=e.parentNode;for(;a&&a.localName!=="form";)a=a.parentNode;if(a){const l=s.createNodeIterator(a,b.SHOW_ELEMENT);let m=l.nextNode();for(;m;){const N=m.localName;let w;if(N==="button"?w=!(m.hasAttribute("type")&&j.test(m.getAttribute("type"))):N==="input"&&(w=m.hasAttribute("type")&&H.test(m.getAttribute("type"))),w){m===e&&t.add(e);break}m=l.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&I.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(o==="option"){let a=!1,l=d;for(;l&&l.localName!=="datalist";){if(l.localName==="select"){(l.multiple||l.hasAttribute("multiple"))&&(a=!0);break}l=l.parentNode}if(a)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const m=d.firstElementChild,N=new Set;let w=m;for(;w;){if(w.selected||w.hasAttribute("selected")){N.add(w);break}w=w.nextElementSibling}N.size||N.add(m),N.has(e)&&t.add(e)}}break}case"valid":{if(O.test(o))e.checkValidity()&&t.add(e);else if(/^fieldset$/.test(o)){const a=s.createNodeIterator(e,b.SHOW_ELEMENT);let l=a.nextNode();l===e&&(l=a.nextNode());let m;for(;l&&!(O.test(l.localName)&&(m=l.checkValidity(),!m));)l=a.nextNode();m&&t.add(e)}break}case"invalid":{if(O.test(o))e.checkValidity()||t.add(e);else if(/^fieldset$/.test(o)){const a=s.createNodeIterator(e,b.SHOW_ELEMENT);let l=a.nextNode();l===e&&(l=a.nextNode());let m;for(;l&&!(O.test(l.localName)&&(m=l.checkValidity(),!m));)l=a.nextNode();m||t.add(e)}break}case"in-range":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&V.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":{o==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&V.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let a;if(/^(?:select|textarea)$/.test(o))a=e;else if(o==="input")if(e.hasAttribute("type")){const l=e.getAttribute("type");(L.test(l)||I.test(l)||D.test(l)||l==="file")&&(a=e)}else a=e;a&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let a;if(/^(?:select|textarea)$/.test(o))a=e;else if(o==="input")if(e.hasAttribute("type")){const l=e.getAttribute("type");(L.test(l)||I.test(l)||D.test(l)||l==="file")&&(a=e)}else a=e;a&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===n&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const a=e.childNodes.values();let l;for(const m of a)if(l=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!l)break;l&&t.add(e)}else t.add(e);break}case"first-child":{(d&&e===d.firstElementChild||f.nodeType===b.ELEMENT_NODE&&e===f)&&t.add(e);break}case"last-child":{(d&&e===d.lastElementChild||f.nodeType===b.ELEMENT_NODE&&e===f)&&t.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||f.nodeType===b.ELEMENT_NODE&&e===f)&&t.add(e);break}case"first-of-type":{if(d){const[a]=this._collectNthOfType({a:0,b:1},e);a&&t.add(a)}else f.nodeType===b.ELEMENT_NODE&&e===f&&t.add(e);break}case"last-of-type":{if(d){const[a]=this._collectNthOfType({a:0,b:1,reverse:!0},e);a&&t.add(a)}else f.nodeType===b.ELEMENT_NODE&&e===f&&t.add(e);break}case"only-of-type":{if(d){const[a]=this._collectNthOfType({a:0,b:1},e);if(a===e){const[l]=this._collectNthOfType({a:0,b:1,reverse:!0},e);l===e&&t.add(e)}}else f.nodeType===b.ELEMENT_NODE&&e===f&&t.add(e);break}case"after":case"before":case"first-letter":case"first-line":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${u}`,b.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.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR);break}default:if(u.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-class :${u}`,b.NOT_SUPPORTED_ERR)}else if(!p)throw new DOMException(`Unknown pseudo-class :${u}`,b.SYNTAX_ERR)}}return t}_matchAttributeSelector(r,e){const{flags:c,matcher:h,name:o,value:d}=r;if(typeof c=="string"&&!/^[is]$/i.test(c))throw new DOMException("Invalid attribute selector",b.SYNTAX_ERR);const{attributes:p}=e;let u;if(p&&p.length){const{document:t}=this.#t;let s;t.contentType==="text/html"?typeof c=="string"&&/^s$/i.test(c)?s=!1:s=!0:typeof c=="string"&&/^i$/i.test(c)?s=!0:s=!1;let{name:f}=o;f=(0,g.unescapeSelector)(f),s&&(f=f.toLowerCase());const n=new Set;if(/\|/.test(f)){const{prefix:i,tagName:a}=(0,k.selectorToNodeProps)(f);for(let{name:l,value:m}of p)switch(s&&(l=l.toLowerCase(),m=m.toLowerCase()),i){case"":{a===l&&n.add(m);break}case"*":{/:/.test(l)?l.endsWith(`:${a}`)&&n.add(m):a===l&&n.add(m);break}default:if(/:/.test(l)){const[N,w]=l.split(":");i===N&&a===w&&(0,k.isNamespaceDeclared)(i,e)&&n.add(m)}}}else for(let{name:i,value:a}of p)if(s&&(i=i.toLowerCase(),a=a.toLowerCase()),/:/.test(i)){const[l,m]=i.split(":");if(l==="xml"&&m==="lang")continue;f===m&&n.add(a)}else f===i&&n.add(a);if(n.size){const{name:i,value:a}=d||{};let l;switch(i?s?l=i.toLowerCase():l=i:a?s?l=a.toLowerCase():l=a:a===""&&(l=a),h){case"=":{typeof l=="string"&&n.has(l)&&(u=e);break}case"~=":{if(l&&typeof l=="string"){for(const m of n)if(new Set(m.split(/\s+/)).has(l)){u=e;break}}break}case"|=":{if(l&&typeof l=="string"){let m;for(const N of n)if(N===l||N.startsWith(`${l}-`)){m=N;break}m&&(u=e)}break}case"^=":{if(l&&typeof l=="string"){let m;for(const N of n)if(N.startsWith(`${l}`)){m=N;break}m&&(u=e)}break}case"$=":{if(l&&typeof l=="string"){let m;for(const N of n)if(N.endsWith(`${l}`)){m=N;break}m&&(u=e)}break}case"*=":{if(l&&typeof l=="string"){let m;for(const N of n)if(N.includes(`${l}`)){m=N;break}m&&(u=e)}break}case null:default:u=e}}}return u??null}_matchClassSelector(r,e){const c=(0,g.unescapeSelector)(r.name);let h;return e.classList.contains(c)&&(h=e),h??null}_matchIDSelector(r,e){const{id:c}=e,h=(0,g.unescapeSelector)(r.name);let o;return h===c&&(o=e),o??null}_matchTypeSelector(r,e){const c=(0,g.unescapeSelector)(r.name),{localName:h,prefix:o}=e,{document:d}=this.#t;let{prefix:p,tagName:u}=(0,k.selectorToNodeProps)(c,e);d.contentType==="text/html"&&(p=p.toLowerCase(),u=u.toLowerCase());let t,s;/:/.test(h)?[t,s]=h.split(":"):(t=o||"",s=h);let f;return p===""&&t===""?e.namespaceURI===null&&(u==="*"||u===s)&&(f=e):p==="*"?(u==="*"||u===s)&&(f=e):p===t&&(0,k.isNamespaceDeclared)(p,e)&&(u==="*"||u===s)&&(f=e),f??null}_matchSelector(r,e,c){const{type:h}=r;let o=new Set;if(e.nodeType===b.ELEMENT_NODE)switch(h){case b.ATTRIBUTE_SELECTOR:{const d=this._matchAttributeSelector(r,e);d&&o.add(d);break}case b.CLASS_SELECTOR:{const d=this._matchClassSelector(r,e);d&&o.add(d);break}case b.ID_SELECTOR:{const d=this._matchIDSelector(r,e);d&&o.add(d);break}case b.PSEUDO_CLASS_SELECTOR:{const d=this._matchPseudoClassSelector(r,e,c);d.size&&(o=d);break}case b.PSEUDO_ELEMENT_SELECTOR:{const d=(0,g.unescapeSelector)(r.name);this._matchPseudoElementSelector(d,c);break}case b.TYPE_SELECTOR:default:{const d=this._matchTypeSelector(r,e);d&&o.add(d)}}return o}_matchLeaves(r,e,c){let h;for(const o of r)if(h=this._matchSelector(o,e,c).has(e),!h)break;return!!h}_findDescendantNodes(r,e){const[c,...h]=r,{type:o}=c,d=(0,g.unescapeSelector)(c.name),p=h.length>0,u=new Set;let t=!1;switch(o){case b.ID_SELECTOR:{const{root:s}=this.#t;if(s.nodeType===b.ELEMENT_NODE)t=!0;else{const f=s.getElementById(d);if(f&&f!==e){const n=(0,k.isSameOrDescendant)(f,e);let i;n&&(i=f),i&&(p?this._matchLeaves(h,i)&&u.add(i):u.add(i))}}break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:t=!0}return{nodes:u,pending:t}}_matchCombinator(r,e,c={}){const{combo:h,leaves:o}=r,{name:d}=h,{find:p,forgive:u}=c;let t=new Set;if(p==="next")switch(d){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(o,s,{forgive:u})&&t.add(s);break}case"~":{let s=e.nextElementSibling;for(;s;)this._matchLeaves(o,s,{forgive:u})&&t.add(s),s=s.nextElementSibling;break}case">":{const s=[...e.children];for(const f of s)this._matchLeaves(o,f,{forgive:u})&&t.add(f);break}case" ":default:{const{nodes:s,pending:f}=this._findDescendantNodes(o,e);if(s.size)t=s;else if(f){const{document:n}=this.#t,i=n.createNodeIterator(e,b.SHOW_ELEMENT);let a=i.nextNode();for(a===e&&(a=i.nextNode());a;)this._matchLeaves(o,a,{forgive:u})&&t.add(a),a=i.nextNode()}}}else switch(d){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(o,s,{forgive:u})&&t.add(s);break}case"~":{const s=[];let f=e.previousElementSibling;for(;f;)this._matchLeaves(o,f,{forgive:u})&&s.push(f),f=f.previousElementSibling;s.length&&(t=new Set(s.reverse()));break}case">":{const s=e.parentNode;s&&this._matchLeaves(o,s,{forgive:u})&&t.add(s);break}case" ":default:{const s=[];let f=e.parentNode;for(;f;)this._matchLeaves(o,f,{forgive:u})&&s.push(f),f=f.parentNode;s.length&&(t=new Set(s.reverse()))}}return t}_findNodes(r,e){const{leaves:[c,...h]}=r,{type:o}=c,d=(0,g.unescapeSelector)(c.name),p=h.length>0,{document:u,root:t}=this.#t;let s=new Set,f=!1;switch(o){case b.ID_SELECTOR:{let n;if(e===S)this._matchLeaves([c],this.#e)&&(n=this.#e);else if(e===x){let i=this.#e;for(;i;){if(this._matchLeaves([c],i)){n=i;break}i=i.parentNode}}else t.nodeType===b.ELEMENT_NODE?f=!0:n=t.getElementById(d);n&&(p?this._matchLeaves(h,n)&&s.add(n):s.add(n));break}case b.CLASS_SELECTOR:{const n=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this.#e.classList.contains(d)&&n.push(this.#e);else if(e===x){let i=this.#e;for(;i&&i.nodeType===b.ELEMENT_NODE;)i.classList.contains(d)&&n.push(i),i=i.parentNode}else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const i=[...t.children];for(const a of i){a.classList.contains(d)&&n.push(a);const l=[...a.getElementsByClassName(d)];n.push(...l)}}else{const i=[...t.getElementsByClassName(d)];n.push(...i)}if(n.length)if(p)for(const i of n)this._matchLeaves(h,i)&&s.add(i);else s=new Set(n);break}case b.TYPE_SELECTOR:{const n=[];if(e===S)this.#e.nodeType===b.ELEMENT_NODE&&this._matchLeaves([c],this.#e)&&n.push(this.#e);else if(e===x){let i=this.#e;for(;i&&i.nodeType===b.ELEMENT_NODE;)this._matchLeaves([c],i)&&n.push(i),i=i.parentNode}else if(u.contentType!=="text/html"||/[*|]/.test(d))f=!0;else if(t.nodeType===b.DOCUMENT_FRAGMENT_NODE){const i=d.toLowerCase(),a=[...t.children];for(const l of a){l.localName===i&&n.push(l);const m=[...l.getElementsByTagName(d)];n.push(...m)}}else{const i=[...t.getElementsByTagName(d)];n.push(...i)}if(n.length)if(p)for(const i of n)this._matchLeaves(h,i)&&s.add(i);else s=new Set(n);break}case b.PSEUDO_ELEMENT_SELECTOR:{this._matchPseudoElementSelector(d);break}default:{const n=[];if(e===S)this._matchLeaves([c],this.#e)&&n.push(this.#e);else if(e===x){let i=this.#e;for(;i;)this._matchLeaves([c],i)&&n.push(i),i=i.parentNode}else f=!0;if(n.length)if(p)for(const i of n)this._matchLeaves(h,i)&&s.add(i);else s=new Set(n)}}return{nodes:s,pending:f}}_getFirstTwig(r){const e=r.length-1,c=r[0];let h,o;if(e){const d=r[e],{leaves:[{type:p}]}=d;p===b.PSEUDO_ELEMENT_SELECTOR||p===b.ID_SELECTOR?(h="prev",o=d):(h="next",o=c)}else h="prev",o=c;return{find:h,twig:o}}_collectNodes(r){const e=this.#s.values();if(r===C||r===v){const c=new Set;let h=0;for(const{branch:o}of e){const{find:d,twig:p}=this._getFirstTwig(o),{nodes:u,pending:t}=this._findNodes(p,r);u.size?this.#r[h]=u:t?c.add(new Map([["index",h],["twig",p]])):this.#s[h].skip=!0,this.#s[h].find=d,h++}if(c.size){const{document:o,root:d}=this.#t,p=o.createNodeIterator(d,b.SHOW_ELEMENT);let u=p.nextNode();for(;u;){let t=!1;if(this.#e.nodeType===b.ELEMENT_NODE?t=(0,k.isSameOrDescendant)(u,this.#e):t=!0,t)for(const s of c){const{leaves:f}=s.get("twig");if(this._matchLeaves(f,u)){const i=s.get("index");this.#r[i].add(u)}}u=p.nextNode()}}}else{let c=0;for(const{branch:h}of e){const o=h[h.length-1],{nodes:d}=this._findNodes(o,r);d.size?this.#r[c]=d:this.#s[c].skip=!0,this.#s[c].find="prev",c++}}return[this.#s,this.#r]}_sortNodes(r){const e=[...r];return e.length>1&&e.sort((c,h)=>{const o=c.compareDocumentPosition(h);let d;return o&b.DOCUMENT_POSITION_PRECEDING||o&b.DOCUMENT_POSITION_CONTAINS?d=1:d=-1,d}),e}_matchNodes(r){const[...e]=this.#s,c=e.length;let h=new Set;for(let o=0;o<c;o++){const{branch:d,find:p,skip:u}=e[o],t=d.length;if(!u&&t){const s=this.#r[o],f=t-1;if(f===0)if((r===C||r===v)&&this.#e.nodeType===b.ELEMENT_NODE){for(const n of s)if(n!==this.#e&&(0,k.isSameOrDescendant)(n,this.#e)&&(h.add(n),r===v))break}else if(r===v){const[n]=this._sortNodes(s);h.add(n)}else{const n=[...h],i=[...s];h=new Set([...n,...i])}else if(p==="next"){let{combo:n}=d[0];for(const i of s){let a=new Set([i]);for(let l=1;l<t;l++){const{combo:m,leaves:N}=d[l],w=[];for(const y of a){const A={combo:n,leaves:N},M=this._matchCombinator(A,y,{find:p});M.size&&w.push(...M)}const E=new Set(w);if(E.size)if(l===f){if(r===v){const[y]=this._sortNodes(E);h.add(y)}else{const y=[...h],A=[...E];h=new Set([...y,...A])}break}else n=m,a=E;else break}}}else for(const n of s){let i=new Set([n]),a;for(let l=f-1;l>=0;l--){const m=d[l],N=[];for(const E of i){const y=this._matchCombinator(m,E,{find:p});y.size&&N.push(...y)}const w=new Set(N);if(w.size)if(a=!0,l===0){h.add(n);break}else i=w;else{a=!1;break}}if(a&&r!==C)break}}}return h}_find(r){return this._collectNodes(r),this._matchNodes(r)}matches(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let r;try{r=this._find(S).has(this.#e)}catch(e){this._onError(e)}return!!r}closest(){if(this.#e.nodeType!==b.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let r;try{const e=this._find(x);let c=this.#e;for(;c;){if(e.has(c)){r=c;break}c=c.parentNode}}catch(e){this._onError(e)}return r??null}querySelector(){let r;try{const e=this._find(v);e.delete(this.#e),e.size>1?[r]=this._sortNodes(e):e.size&&([r]=[...e])}catch(e){this._onError(e)}return r??null}querySelectorAll(){const r=[];try{const e=this._find(C);e.delete(this.#e),e.size>1&&this.#c?r.push(...this._sortNodes(e)):e.size&&r.push(...e)}catch(e){this._onError(e)}return r}}0&&(module.exports={Matcher});
2
2
  //# sourceMappingURL=matcher.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/js/matcher.js"],
4
- "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isNamespaceDeclared, isSameOrDescendant,\n selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ATTRIBUTE_SELECTOR, BIT_1, BIT_10, BIT_100, BIT_1000, BIT_10000, BIT_100000,\n CLASS_SELECTOR, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,\n DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n ID_SELECTOR, NOT_SUPPORTED_ERR, PSEUDO_CLASS_SELECTOR,\n PSEUDO_ELEMENT_SELECTOR, SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE, TYPE_SELECTOR\n} from './constant.js';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/* regexp */\nconst FORM_PARTS =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\nconst FORM_VALIDITY = /^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/;\nconst HTML_ANCHOR = /^a(?:rea)?$/;\nconst HTML_INTERACT = /^d(?:etails|ialog)$/;\nconst INPUT_CHECK = /^(?:checkbox|radio)$/;\nconst INPUT_EDIT = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\nconst INPUT_RANGE = /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\nconst INPUT_RESET = /^(?:button|reset)$/;\nconst INPUT_SUBMIT = /^(?:image|submit)$/;\nconst INPUT_TIME = /^(?:date(?:time-local)?|month|time|week)$/;\nconst PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;\nconst PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * skip: boolean\n * }\n * ]\n * #nodes: [\n * Set([node{}, node{}]),\n * Set([node{}, node{}, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: AST leaf\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #bit;\n #cache;\n #node;\n #nodes;\n #root;\n #selector;\n #sort;\n #warn;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.sort] - sort results of querySelectorAll()\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { sort, warn } = opt;\n this.#bit = new Map([\n [PSEUDO_ELEMENT_SELECTOR, BIT_1],\n [ID_SELECTOR, BIT_10],\n [CLASS_SELECTOR, BIT_100],\n [TYPE_SELECTOR, BIT_1000],\n [ATTRIBUTE_SELECTOR, BIT_10000],\n [PSEUDO_CLASS_SELECTOR, BIT_100000]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#sort = !!sort;\n this.#warn = !!warn;\n [this.#ast, this.#nodes] = this._prepare(selector);\n this.#root = this._getRoot(node);\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException && e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw e;\n }\n }\n\n /**\n * get root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - root object\n */\n _getRoot(node = this.#node) {\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (isSameOrDescendant(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n document = parent.ownerDocument;\n root = parent;\n }\n break;\n }\n default: {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n return {\n document,\n root\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = this.#bit.get(typeA);\n const bitB = this.#bit.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * prepare ast and nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _prepare(selector = this.#selector) {\n const ast = parseSelector(selector);\n const branches = walkAST(ast);\n const tree = [];\n const nodes = [];\n let i = 0;\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid combinator ${item.name}${nextItem.name}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n tree.push({\n branch,\n find: null,\n skip: false\n });\n nodes[i] = new Set();\n i++;\n }\n return [\n tree,\n nodes\n ];\n }\n\n /**\n * collect nth child\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {object} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#cache.has(selector)) {\n selectorBranches = this.#cache.get(selector);\n } else {\n selectorBranches = walkAST(selector);\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const arr = [...parentNode.children];\n const l = arr.length;\n if (l) {\n const selectorNodes = new Set();\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n for (const refNode of arr) {\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, refNode);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n }\n if (reverse) {\n arr.reverse();\n }\n // :first-child, :last-child, :nth-child(0 of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n if (selectorNodes.has(current)) {\n matched.add(current);\n break;\n }\n }\n } else if (!selector) {\n const current = arr[b - 1];\n matched.add(current);\n }\n }\n // :nth-child()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l && nth >= 0 && nth < l; i++) {\n const current = arr[i];\n if (selectorNodes.size) {\n if (selectorNodes.has(current)) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(current);\n }\n nth += a;\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE && node === root && (a + b) === 1) {\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {object} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const arr = [...parentNode.children];\n const l = arr.length;\n if (l) {\n if (reverse) {\n arr.reverse();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(current);\n break;\n }\n j++;\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE && node === root && (a + b) === 1) {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {object} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (/last/.test(nthName)) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (/last/.test(nthName)) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'part':\n case 'placeholder':\n case 'selection':\n case 'slotted':\n case 'target-text': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName) {\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n }\n }\n } else if (/[A-Z\\d-]+/i.test(astName)) {\n const alphaNum = '[A-Z\\\\d]+';\n const codePart = `(?:-${alphaNum})*`;\n let reg;\n if (/-/.test(astName)) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${alphaNum}${codePart}`;\n } else {\n extendedMain = `${langMain}${codePart}`;\n }\n const extendedSub = `-${langSub}${codePart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${codePart}`;\n }\n }\n reg =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n reg = new RegExp(`^${astName}${codePart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (reg.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (reg.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n find: 'next'\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n let bool;\n const l = branches.length;\n for (let i = 0; i < l; i++) {\n const leaves = branches[i];\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n let bool;\n const l = twigBranches.length;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, {\n forgive\n });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n find: 'prev'\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = matchedNodes;\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {object} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (PSEUDO_FUNC.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (PSEUDO_NTH.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n const { document, root } = this.#root;\n const { documentElement } = document;\n const docURL = new URL(document.URL);\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const attrURL = new URL(node.getAttribute('href'), docURL.href);\n if (attrURL.origin === docURL.origin &&\n attrURL.pathname === docURL.pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n if (isSameOrDescendant(node) && docURL.hash &&\n node.id && docURL.hash === `#${node.id}`) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n if (docURL.hash) {\n const hash = docURL.hash.replace(/^#/, '');\n let current = document.getElementById(hash);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (node === this.#node) {\n matched.add(node);\n }\n } else if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === document.activeElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (HTML_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (HTML_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (FORM_PARTS.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parent.hasAttribute('disabled') &&\n parentNode.localName !== 'legend') {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((FORM_PARTS.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (INPUT_EDIT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length &&\n node.value === '') {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n node.checked) ||\n (localName === 'option' && node.selected)) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((localName === 'input' && node.type === 'checkbox' &&\n node.indeterminate) ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = documentElement;\n }\n const nodes = [...parent.getElementsByTagName('input')];\n let checked;\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n INPUT_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n INPUT_SUBMIT.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const iterator = document.createNodeIterator(form, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n INPUT_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n INPUT_SUBMIT.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = iterator.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let isMultiple = false;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'datalist') {\n break;\n } else if (parent.localName === 'select') {\n if (parent.multiple || parent.hasAttribute('multiple')) {\n isMultiple = true;\n }\n break;\n }\n parent = parent.parentNode;\n }\n if (isMultiple) {\n if (node.selected || node.hasAttribute('selected')) {\n matched.add(node);\n }\n } else {\n const firstOpt = parentNode.firstElementChild;\n const defaultOpt = new Set();\n let opt = firstOpt;\n while (opt) {\n if (opt.selected || opt.hasAttribute('selected')) {\n defaultOpt.add(opt);\n break;\n }\n opt = opt.nextElementSibling;\n }\n if (!defaultOpt.size) {\n defaultOpt.add(firstOpt);\n }\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'valid': {\n if (FORM_VALIDITY.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (FORM_VALIDITY.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (FORM_VALIDITY.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (FORM_VALIDITY.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n INPUT_RANGE.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n INPUT_RANGE.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const nodes = node.childNodes.values();\n let bool;\n for (const refNode of nodes) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'focus-visible':\n case 'fullscreen':\n case 'future':\n case 'hover':\n case 'modal':\n case 'muted':\n case 'past':\n case 'paused':\n case 'picture-in-picture':\n case 'playing':\n case 'seeking':\n case 'stalled':\n case 'user-invalid':\n case 'user-valid':\n case 'volume-locked':\n case '-webkit-autofill': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n throw new DOMException('Invalid attribute selector', SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const { document } = this.#root;\n let caseInsensitive;\n if (document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let { name: astAttrName } = astName;\n astAttrName = unescapeSelector(astAttrName);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (/\\|/.test(astAttrName)) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (/:/.test(itemName)) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (/:/.test(itemName)) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (/:/.test(itemName)) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const { id } = node;\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { document } = this.#root;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (/:/.test(localName)) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix &&\n isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n }\n return res ?? null;\n };\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {object} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type } = ast;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (type) {\n case ATTRIBUTE_SELECTOR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case CLASS_SELECTOR: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case ID_SELECTOR: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case PSEUDO_CLASS_SELECTOR: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n const astName = unescapeSelector(ast.name);\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case TYPE_SELECTOR:\n default: {\n const res = this._matchTypeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} [opt] - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - result\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...items] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const elm = root.getElementById(leafName);\n if (elm && elm !== baseNode) {\n const bool = isSameOrDescendant(elm, baseNode);\n let node;\n if (bool) {\n node = elm;\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.find] - 'prev'|'next', which nodes to find\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {object} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { find, forgive } = opt;\n let matched = new Set();\n if (find === 'next') {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n let refNode = node.nextElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [...node.children];\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n matched = nodes;\n } else if (pending) {\n const { document } = this.#root;\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = iterator.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const arr = [];\n let refNode = node.previousElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.previousElementSibling;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - collection of nodes and pending state\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\n let node;\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n node = this.#node;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n node = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n node = root.getElementById(leafName);\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n break;\n }\n case CLASS_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [...root.children];\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [...node.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case TYPE_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this.#node.nodeType === ELEMENT_NODE &&\n this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (document.contentType !== 'text/html' ||\n /[*|]/.test(leafName)) {\n pending = true;\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const tagName = leafName.toLowerCase();\n const childNodes = [...root.children];\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [...node.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * get first twig\n * @param {Array.<object>} branch - AST branch\n * @returns {object} - find direction and twig\n */\n _getFirstTwig(branch) {\n const lastIndex = branch.length - 1;\n const firstTwig = branch[0];\n let find;\n let twig;\n if (lastIndex) {\n const lastTwig = branch[lastIndex];\n const { leaves: [{ type: lastType }] } = lastTwig;\n if (lastType === PSEUDO_ELEMENT_SELECTOR || lastType === ID_SELECTOR) {\n find = 'prev';\n twig = lastTwig;\n } else {\n find = 'next';\n twig = firstTwig;\n }\n } else {\n find = 'prev';\n twig = firstTwig;\n }\n return {\n find,\n twig\n };\n }\n\n /**\n * collect nodes\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const { find, twig } = this._getFirstTwig(branch);\n const { nodes, pending } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = find;\n i++;\n }\n if (pendingItems.size) {\n const { document, root } = this.#root;\n const iterator = document.createNodeIterator(root, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n bool = isSameOrDescendant(nextNode, this.#node);\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode);\n if (matched) {\n const index = pendingItem.get('index');\n this.#nodes[index].add(nextNode);\n }\n }\n }\n nextNode = iterator.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const { nodes } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = 'prev';\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {object} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, find, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const matched = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of matched) {\n if (node !== this.#node) {\n if (isSameOrDescendant(node, this.#node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = [...matched];\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matched];\n nodes = new Set([...n, ...m]);\n }\n } else if (find === 'next') {\n let { combo } = branch[0];\n for (const node of matched) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const twig = {\n combo,\n leaves\n };\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = [...matchedNodes];\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matchedNodes];\n nodes = new Set([...n, ...m]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = matchedNodes;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of matched) {\n let nextNodes = new Set([node]);\n let bool;\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = matchedNodes;\n }\n } else {\n bool = false;\n break;\n }\n }\n if (bool && targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {object} - collection of matched nodes\n */\n _find(targetType) {\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * sort nodes\n * @param {object} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n const posBit = a.compareDocumentPosition(b);\n if (posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * matches\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_SELF);\n res = nodes.has(this.#node);\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @returns {?object} - matched node\n */\n closest() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL);\n let node = this.#node;\n while (node) {\n if (nodes.has(node)) {\n res = node;\n break;\n }\n node = node.parentNode;\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @returns {?object} - matched node\n */\n querySelector() {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size > 1) {\n [res] = this._sortNodes(nodes);\n } else if (nodes.size) {\n [res] = [...nodes];\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll() {\n const res = [];\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size > 1 && this.#sort) {\n res.push(...this._sortNodes(nodes));\n } else if (nodes.size) {\n res.push(...nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res;\n }\n};\n"],
5
- "mappings": "6iBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,IAAA,eAAAC,EAAAH,IAK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K,MAAM5C,CAAa,EACtC,IAAIwB,EAAO,KAAKP,GAChB,KAAOO,GAAM,CACX,GAAIoB,EAAM,IAAIpB,CAAI,EAAG,CACnBgB,EAAMhB,EACN,KACF,CACAA,EAAOA,EAAK,UACd,CACF,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOgB,GAAO,IAChB,CAMA,eAAgB,CACd,IAAIA,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM7C,CAAY,EACrC6C,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,EACf,CAACJ,CAAG,EAAI,KAAK,WAAWI,CAAK,EACpBA,EAAM,OACf,CAACJ,CAAG,EAAI,CAAC,GAAGI,CAAK,EAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,IAChB,CAOA,kBAAmB,CACjB,MAAMA,EAAM,CAAC,EACb,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM9C,CAAU,EACnC8C,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,GAAK,KAAKvB,GACzBmB,EAAI,KAAK,GAAG,KAAK,WAAWI,CAAK,CAAC,EACzBA,EAAM,MACfJ,EAAI,KAAK,GAAGI,CAAK,CAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,CACT,CACF",
6
- "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "FORM_PARTS", "FORM_VALIDITY", "HTML_ANCHOR", "HTML_INTERACT", "INPUT_CHECK", "INPUT_EDIT", "INPUT_RANGE", "INPUT_RESET", "INPUT_SUBMIT", "INPUT_TIME", "PSEUDO_FUNC", "PSEUDO_NTH", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#sort", "#warn", "selector", "node", "opt", "sort", "warn", "e", "document", "root", "parent", "leaves", "arr", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "ast", "branches", "tree", "nodes", "i", "items", "branch", "item", "nextItem", "msg", "anb", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "branchesLen", "refNode", "bool", "current", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "alphaNum", "codePart", "reg", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "matchedNodes", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "id", "astPrefix", "astNodeName", "nodePrefix", "type", "baseNode", "leafName", "matchItems", "pending", "elm", "comboName", "find", "childNodes", "targetType", "tagName", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "skip", "branchLen", "n", "nextCombo", "posBit"]
4
+ "sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isNamespaceDeclared, isSameOrDescendant,\n selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ATTRIBUTE_SELECTOR, BIT_1, BIT_10, BIT_100, BIT_1000, BIT_10000, BIT_100000,\n CLASS_SELECTOR, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,\n DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n ID_SELECTOR, NOT_SUPPORTED_ERR, PSEUDO_CLASS_SELECTOR,\n PSEUDO_ELEMENT_SELECTOR, SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE, TYPE_SELECTOR\n} from './constant.js';\nconst ALPHA_NUM = '[A-Z\\\\d]+';\nconst LANG_PART = `(?:-${ALPHA_NUM})*`;\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/* regexp */\nconst FORM_ITEM =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\nconst FORM_VALIDITY = /^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/;\nconst HTML_ANCHOR = /^a(?:rea)?$/;\nconst HTML_INTERACT = /^d(?:etails|ialog)$/;\nconst INPUT_CHECK = /^(?:checkbox|radio)$/;\nconst INPUT_EDIT = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\nconst INPUT_RANGE = /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\nconst INPUT_RESET = /^(?:button|reset)$/;\nconst INPUT_SUBMIT = /^(?:image|submit)$/;\nconst INPUT_TIME = /^(?:date(?:time-local)?|month|time|week)$/;\nconst PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;\nconst PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;\nconst LANG_CODE = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * skip: boolean\n * }\n * ]\n * #nodes: [\n * Set([node{}, node{}]),\n * Set([node{}, node{}, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: AST leaf\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #bit;\n #cache;\n #node;\n #nodes;\n #root;\n #selector;\n #sort;\n #warn;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.sort] - sort results of querySelectorAll()\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { sort, warn } = opt;\n this.#bit = new Map([\n [PSEUDO_ELEMENT_SELECTOR, BIT_1],\n [ID_SELECTOR, BIT_10],\n [CLASS_SELECTOR, BIT_100],\n [TYPE_SELECTOR, BIT_1000],\n [ATTRIBUTE_SELECTOR, BIT_10000],\n [PSEUDO_CLASS_SELECTOR, BIT_100000]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#sort = !!sort;\n this.#warn = !!warn;\n [this.#ast, this.#nodes] = this._prepare(selector);\n this.#root = this._getRoot(node);\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException && e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw e;\n }\n }\n\n /**\n * get root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - root object\n */\n _getRoot(node = this.#node) {\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (isSameOrDescendant(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n document = parent.ownerDocument;\n root = parent;\n }\n break;\n }\n default: {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n return {\n document,\n root\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = this.#bit.get(typeA);\n const bitB = this.#bit.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * prepare ast and nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _prepare(selector = this.#selector) {\n const ast = parseSelector(selector);\n const branches = walkAST(ast);\n const tree = [];\n const nodes = [];\n let i = 0;\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid combinator ${item.name}${nextItem.name}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n tree.push({\n branch,\n find: null,\n skip: false\n });\n nodes[i] = new Set();\n i++;\n }\n return [\n tree,\n nodes\n ];\n }\n\n /**\n * collect nth child\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {object} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#cache.has(selector)) {\n selectorBranches = this.#cache.get(selector);\n } else {\n selectorBranches = walkAST(selector);\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const arr = [...parentNode.children];\n const l = arr.length;\n if (l) {\n const selectorNodes = new Set();\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n for (const refNode of arr) {\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, refNode);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n }\n if (reverse) {\n arr.reverse();\n }\n // :first-child, :last-child, :nth-child(0 of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n if (selectorNodes.has(current)) {\n matched.add(current);\n break;\n }\n }\n } else if (!selector) {\n const current = arr[b - 1];\n matched.add(current);\n }\n }\n // :nth-child()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l && nth >= 0 && nth < l; i++) {\n const current = arr[i];\n if (selectorNodes.size) {\n if (selectorNodes.has(current)) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(current);\n }\n nth += a;\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE && node === root && (a + b) === 1) {\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {object} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const arr = [...parentNode.children];\n const l = arr.length;\n if (l) {\n if (reverse) {\n arr.reverse();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(current);\n break;\n }\n j++;\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE && node === root && (a + b) === 1) {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {object} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (/last/.test(nthName)) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (/last/.test(nthName)) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'part':\n case 'placeholder':\n case 'selection':\n case 'slotted':\n case 'target-text': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName) {\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n }\n }\n } else if (LANG_CODE.test(astName)) {\n let reg;\n if (/-/.test(astName)) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${LANG_PART}`;\n } else {\n extendedMain = `${langMain}${LANG_PART}`;\n }\n const extendedSub = `-${langSub}${LANG_PART}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${LANG_PART}`;\n }\n }\n reg =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n reg = new RegExp(`^${astName}${LANG_PART}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (reg.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (reg.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n find: 'next'\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n const l = branches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const leaves = branches[i];\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, {\n forgive\n });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n find: 'prev'\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = matchedNodes;\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {object} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (PSEUDO_FUNC.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (PSEUDO_NTH.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n const { document, root } = this.#root;\n const { documentElement } = document;\n const docURL = new URL(document.URL);\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (HTML_ANCHOR.test(localName) && node.hasAttribute('href')) {\n const attrURL = new URL(node.getAttribute('href'), docURL.href);\n if (attrURL.origin === docURL.origin &&\n attrURL.pathname === docURL.pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n if (isSameOrDescendant(node) && docURL.hash &&\n node.id && docURL.hash === `#${node.id}`) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n if (docURL.hash) {\n const hash = docURL.hash.replace(/^#/, '');\n let current = document.getElementById(hash);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (node === this.#node) {\n matched.add(node);\n }\n } else if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === document.activeElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (HTML_INTERACT.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (HTML_INTERACT.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (FORM_ITEM.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parent.hasAttribute('disabled') &&\n parentNode.localName !== 'legend') {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((FORM_ITEM.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type ||\n INPUT_EDIT.test(node.type) || INPUT_TIME.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (INPUT_EDIT.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length &&\n node.value === '') {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n node.checked) ||\n (localName === 'option' && node.selected)) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((localName === 'input' && node.type === 'checkbox' &&\n node.indeterminate) ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = documentElement;\n }\n const nodes = [...parent.getElementsByTagName('input')];\n let checked;\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n INPUT_RESET.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n INPUT_SUBMIT.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const iterator = document.createNodeIterator(form, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n INPUT_RESET.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n INPUT_SUBMIT.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = iterator.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n INPUT_CHECK.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let isMultiple = false;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'datalist') {\n break;\n } else if (parent.localName === 'select') {\n if (parent.multiple || parent.hasAttribute('multiple')) {\n isMultiple = true;\n }\n break;\n }\n parent = parent.parentNode;\n }\n if (isMultiple) {\n if (node.selected || node.hasAttribute('selected')) {\n matched.add(node);\n }\n } else {\n const firstOpt = parentNode.firstElementChild;\n const defaultOpt = new Set();\n let opt = firstOpt;\n while (opt) {\n if (opt.selected || opt.hasAttribute('selected')) {\n defaultOpt.add(opt);\n break;\n }\n opt = opt.nextElementSibling;\n }\n if (!defaultOpt.size) {\n defaultOpt.add(firstOpt);\n }\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'valid': {\n if (FORM_VALIDITY.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (FORM_VALIDITY.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (FORM_VALIDITY.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (/^fieldset$/.test(localName)) {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (FORM_VALIDITY.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n INPUT_RANGE.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n INPUT_RANGE.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (INPUT_EDIT.test(inputType) || INPUT_CHECK.test(inputType) ||\n INPUT_TIME.test(inputType) || inputType === 'file') {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const nodes = node.childNodes.values();\n let bool;\n for (const refNode of nodes) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (root.nodeType === ELEMENT_NODE && node === root)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (root.nodeType === ELEMENT_NODE && node === root) {\n matched.add(node);\n }\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'focus-visible':\n case 'fullscreen':\n case 'future':\n case 'hover':\n case 'modal':\n case 'muted':\n case 'past':\n case 'paused':\n case 'picture-in-picture':\n case 'playing':\n case 'seeking':\n case 'stalled':\n case 'user-invalid':\n case 'user-valid':\n case 'volume-locked':\n case '-webkit-autofill': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n throw new DOMException('Invalid attribute selector', SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const { document } = this.#root;\n let caseInsensitive;\n if (document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let { name: astAttrName } = astName;\n astAttrName = unescapeSelector(astAttrName);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (/\\|/.test(astAttrName)) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (/:/.test(itemName)) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (/:/.test(itemName)) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (/:/.test(itemName)) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const { id } = node;\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { document } = this.#root;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (/:/.test(localName)) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix &&\n isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n }\n return res ?? null;\n };\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {object} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type } = ast;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (type) {\n case ATTRIBUTE_SELECTOR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case CLASS_SELECTOR: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case ID_SELECTOR: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case PSEUDO_CLASS_SELECTOR: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n const astName = unescapeSelector(ast.name);\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case TYPE_SELECTOR:\n default: {\n const res = this._matchTypeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} [opt] - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - result\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...items] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\n const { root } = this.#root;\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const elm = root.getElementById(leafName);\n if (elm && elm !== baseNode) {\n const bool = isSameOrDescendant(elm, baseNode);\n let node;\n if (bool) {\n node = elm;\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.find] - 'prev'|'next', which nodes to find\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {object} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { find, forgive } = opt;\n let matched = new Set();\n if (find === 'next') {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n let refNode = node.nextElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [...node.children];\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n matched = nodes;\n } else if (pending) {\n const { document } = this.#root;\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = iterator.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const arr = [];\n let refNode = node.previousElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.previousElementSibling;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - collection of nodes and pending state\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case ID_SELECTOR: {\n let node;\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n node = this.#node;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n node = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n node = root.getElementById(leafName);\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n break;\n }\n case CLASS_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [...root.children];\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [...node.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByClassName(leafName)];\n arr.push(...a);\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case TYPE_SELECTOR: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this.#node.nodeType === ELEMENT_NODE &&\n this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (document.contentType !== 'text/html' ||\n /[*|]/.test(leafName)) {\n pending = true;\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const tagName = leafName.toLowerCase();\n const childNodes = [...root.children];\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [...node.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n } else {\n const a = [...root.getElementsByTagName(leafName)];\n arr.push(...a);\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case PSEUDO_ELEMENT_SELECTOR: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * get first twig\n * @param {Array.<object>} branch - AST branch\n * @returns {object} - find direction and twig\n */\n _getFirstTwig(branch) {\n const lastIndex = branch.length - 1;\n const firstTwig = branch[0];\n let find;\n let twig;\n if (lastIndex) {\n const lastTwig = branch[lastIndex];\n const { leaves: [{ type: lastType }] } = lastTwig;\n if (lastType === PSEUDO_ELEMENT_SELECTOR || lastType === ID_SELECTOR) {\n find = 'prev';\n twig = lastTwig;\n } else {\n find = 'next';\n twig = firstTwig;\n }\n } else {\n find = 'prev';\n twig = firstTwig;\n }\n return {\n find,\n twig\n };\n }\n\n /**\n * collect nodes\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const { find, twig } = this._getFirstTwig(branch);\n const { nodes, pending } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = find;\n i++;\n }\n if (pendingItems.size) {\n const { document, root } = this.#root;\n const iterator = document.createNodeIterator(root, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n bool = isSameOrDescendant(nextNode, this.#node);\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode);\n if (matched) {\n const index = pendingItem.get('index');\n this.#nodes[index].add(nextNode);\n }\n }\n }\n nextNode = iterator.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const { nodes } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = 'prev';\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * sort nodes\n * @param {object} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const posBit = a.compareDocumentPosition(b);\n let res;\n if (posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {object} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, find, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const matched = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of matched) {\n if (node !== this.#node) {\n if (isSameOrDescendant(node, this.#node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(matched);\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matched];\n nodes = new Set([...n, ...m]);\n }\n } else if (find === 'next') {\n let { combo } = branch[0];\n for (const node of matched) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const twig = {\n combo,\n leaves\n };\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(matchedNodes);\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matchedNodes];\n nodes = new Set([...n, ...m]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = matchedNodes;\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of matched) {\n let nextNodes = new Set([node]);\n let bool;\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n const matchedNodes = new Set(arr);\n if (matchedNodes.size) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = matchedNodes;\n }\n } else {\n bool = false;\n break;\n }\n }\n if (bool && targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {object} - collection of matched nodes\n */\n _find(targetType) {\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * matches\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_SELF);\n res = nodes.has(this.#node);\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @returns {?object} - matched node\n */\n closest() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL);\n let node = this.#node;\n while (node) {\n if (nodes.has(node)) {\n res = node;\n break;\n }\n node = node.parentNode;\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @returns {?object} - matched node\n */\n querySelector() {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size > 1) {\n [res] = this._sortNodes(nodes);\n } else if (nodes.size) {\n [res] = [...nodes];\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll() {\n const res = [];\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size > 1 && this.#sort) {\n res.push(...this._sortNodes(nodes));\n } else if (nodes.size) {\n res.push(...nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res;\n }\n};\n"],
5
+ "mappings": "6iBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,KAAA,eAAAC,EAAAH,IAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAMO,yBACP,MAAMC,EAAY,YACZC,EAAY,OAAOD,CAAS,KAC5BE,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OAGdC,EACJ,iEACIC,EAAgB,qDAChBC,EAAc,cACdC,EAAgB,sBAChBC,EAAc,uBACdC,EAAa,oDACbC,EAAc,2DACdC,EAAc,qBACdC,EAAe,qBACfC,EAAa,4CACbC,EAAc,4BACdC,GAAa,oCACbC,GAAY,IAAI,OAAO,aAAalB,CAAS,GAAGC,CAAS,IAAK,GAAG,EA4BhE,MAAMP,EAAQ,CAEnByB,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAUA,YAAYC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CACpC,KAAM,CAAE,KAAAC,EAAM,KAAAC,CAAK,EAAIF,EACvB,KAAKV,GAAO,IAAI,IAAI,CAClB,CAAC,0BAAyB,OAAK,EAC/B,CAAC,cAAa,QAAM,EACpB,CAAC,iBAAgB,SAAO,EACxB,CAAC,gBAAe,UAAQ,EACxB,CAAC,qBAAoB,WAAS,EAC9B,CAAC,wBAAuB,YAAU,CACpC,CAAC,EACD,KAAKC,GAAS,IAAI,QAClB,KAAKI,GAAYG,EACjB,KAAKN,GAAQO,EACb,KAAKH,GAAQ,CAAC,CAACK,EACf,KAAKJ,GAAQ,CAAC,CAACK,EACf,CAAC,KAAKb,GAAM,KAAKI,EAAM,EAAI,KAAK,SAASK,CAAQ,EACjD,KAAKJ,GAAQ,KAAK,SAASK,CAAI,CACjC,CAQA,SAASI,EAAG,CACV,GAAIA,aAA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,CAAW,EACxB,IAAI,KAAKiB,EAAK,CAC5B,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,MAAO,CAAC,CAACuB,CACX,CAMA,SAAU,CACR,GAAI,KAAKvB,GAAM,WAAa,eAC1B,MAAM,IAAI,UAAU,mBAAmB,KAAKA,GAAM,QAAQ,EAAE,EAE9D,IAAIuB,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM7C,CAAa,EACtC,IAAIyB,EAAO,KAAKP,GAChB,KAAOO,GAAM,CACX,GAAIoB,EAAM,IAAIpB,CAAI,EAAG,CACnBgB,EAAMhB,EACN,KACF,CACAA,EAAOA,EAAK,UACd,CACF,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOgB,GAAO,IAChB,CAMA,eAAgB,CACd,IAAIA,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM9C,CAAY,EACrC8C,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,EACf,CAACJ,CAAG,EAAI,KAAK,WAAWI,CAAK,EACpBA,EAAM,OACf,CAACJ,CAAG,EAAI,CAAC,GAAGI,CAAK,EAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,IAChB,CAOA,kBAAmB,CACjB,MAAMA,EAAM,CAAC,EACb,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAM/C,CAAU,EACnC+C,EAAM,OAAO,KAAK3B,EAAK,EACnB2B,EAAM,KAAO,GAAK,KAAKvB,GACzBmB,EAAI,KAAK,GAAG,KAAK,WAAWI,CAAK,CAAC,EACzBA,EAAM,MACfJ,EAAI,KAAK,GAAGI,CAAK,CAErB,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,CACT,CACF",
6
+ "names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "ALPHA_NUM", "LANG_PART", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "FORM_ITEM", "FORM_VALIDITY", "HTML_ANCHOR", "HTML_INTERACT", "INPUT_CHECK", "INPUT_EDIT", "INPUT_RANGE", "INPUT_RESET", "INPUT_SUBMIT", "INPUT_TIME", "PSEUDO_FUNC", "PSEUDO_NTH", "LANG_CODE", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#sort", "#warn", "selector", "node", "opt", "sort", "warn", "e", "document", "root", "parent", "leaves", "arr", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "ast", "branches", "tree", "nodes", "i", "items", "branch", "item", "nextItem", "msg", "anb", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "branchesLen", "refNode", "bool", "current", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "reg", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "matchedNodes", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "id", "astPrefix", "astNodeName", "nodePrefix", "type", "baseNode", "leafName", "matchItems", "pending", "elm", "comboName", "find", "childNodes", "targetType", "tagName", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "posBit", "skip", "branchLen", "nextCombo", "n"]
7
7
  }
package/package.json CHANGED
@@ -57,5 +57,5 @@
57
57
  "update": "npm-run-all -s update-*",
58
58
  "update-wpt": "git submodule update --init --recursive --remote"
59
59
  },
60
- "version": "1.0.3"
60
+ "version": "1.0.5"
61
61
  }
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * DOM Selector - retrieve DOM node from the given CSS selector
2
+ * DOM Selector - Gets the DOM node that matches the CSS selector.
3
3
  * @license MIT
4
4
  * @copyright asamuzaK (Kazz)
5
5
  * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}
@@ -21,12 +21,12 @@ export const SYNTAX_ERR = 'SyntaxError';
21
21
  export const TYPE_SELECTOR = 'TypeSelector';
22
22
 
23
23
  /* numeric */
24
- export const BIT_1 = 1;
25
- export const BIT_10 = 2;
26
- export const BIT_100 = 4;
27
- export const BIT_1000 = 8;
28
- export const BIT_10000 = 16;
29
- export const BIT_100000 = 32;
24
+ export const BIT_1 = 0x1;
25
+ export const BIT_10 = 0x2;
26
+ export const BIT_100 = 0x4;
27
+ export const BIT_1000 = 0x8;
28
+ export const BIT_10000 = 0x10;
29
+ export const BIT_100000 = 0x20;
30
30
  export const TYPE_FROM = 8;
31
31
  export const TYPE_TO = -1;
32
32
 
@@ -35,9 +35,9 @@ export const ELEMENT_NODE = 1;
35
35
  export const TEXT_NODE = 3;
36
36
  export const DOCUMENT_NODE = 9;
37
37
  export const DOCUMENT_FRAGMENT_NODE = 11;
38
- export const DOCUMENT_POSITION_PRECEDING = 0x02;
39
- export const DOCUMENT_POSITION_CONTAINS = 0x08;
38
+ export const DOCUMENT_POSITION_PRECEDING = 0x2;
39
+ export const DOCUMENT_POSITION_CONTAINS = 0x8;
40
40
  export const DOCUMENT_POSITION_CONTAINED_BY = 0x10;
41
41
 
42
42
  /* NodeFilter */
43
- export const SHOW_ELEMENT = 0x00000001;
43
+ export const SHOW_ELEMENT = 0x1;
@@ -231,7 +231,8 @@ export const isSameOrDescendant = (node = {}, root = {}) => {
231
231
  * @returns {object} - node properties
232
232
  */
233
233
  export const selectorToNodeProps = (selector, node) => {
234
- let prefix, tagName;
234
+ let prefix;
235
+ let tagName;
235
236
  if (selector && typeof selector === 'string') {
236
237
  if (/\|/.test(selector)) {
237
238
  [prefix, tagName] = selector.split('|');
package/src/js/matcher.js CHANGED
@@ -20,13 +20,15 @@ import {
20
20
  ID_SELECTOR, NOT_SUPPORTED_ERR, PSEUDO_CLASS_SELECTOR,
21
21
  PSEUDO_ELEMENT_SELECTOR, SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE, TYPE_SELECTOR
22
22
  } from './constant.js';
23
+ const ALPHA_NUM = '[A-Z\\d]+';
24
+ const LANG_PART = `(?:-${ALPHA_NUM})*`;
23
25
  const TARGET_ALL = 'all';
24
26
  const TARGET_FIRST = 'first';
25
27
  const TARGET_LINEAL = 'lineal';
26
28
  const TARGET_SELF = 'self';
27
29
 
28
30
  /* regexp */
29
- const FORM_PARTS =
31
+ const FORM_ITEM =
30
32
  /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;
31
33
  const FORM_VALIDITY = /^(?:(?:(?:in|out)pu|selec)t|button|form|textarea)$/;
32
34
  const HTML_ANCHOR = /^a(?:rea)?$/;
@@ -39,6 +41,7 @@ const INPUT_SUBMIT = /^(?:image|submit)$/;
39
41
  const INPUT_TIME = /^(?:date(?:time-local)?|month|time|week)$/;
40
42
  const PSEUDO_FUNC = /^(?:(?:ha|i)s|not|where)$/;
41
43
  const PSEUDO_NTH = /^nth-(?:last-)?(?:child|of-type)$/;
44
+ const LANG_CODE = new RegExp(`^(?:\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');
42
45
 
43
46
  /**
44
47
  * Matcher
@@ -603,30 +606,28 @@ export class Matcher {
603
606
  parent = parent.parentNode;
604
607
  }
605
608
  }
606
- } else if (/[A-Z\d-]+/i.test(astName)) {
607
- const alphaNum = '[A-Z\\d]+';
608
- const codePart = `(?:-${alphaNum})*`;
609
+ } else if (LANG_CODE.test(astName)) {
609
610
  let reg;
610
611
  if (/-/.test(astName)) {
611
612
  const [langMain, langSub, ...langRest] = astName.split('-');
612
613
  let extendedMain;
613
614
  if (langMain === '*') {
614
- extendedMain = `${alphaNum}${codePart}`;
615
+ extendedMain = `${ALPHA_NUM}${LANG_PART}`;
615
616
  } else {
616
- extendedMain = `${langMain}${codePart}`;
617
+ extendedMain = `${langMain}${LANG_PART}`;
617
618
  }
618
- const extendedSub = `-${langSub}${codePart}`;
619
+ const extendedSub = `-${langSub}${LANG_PART}`;
619
620
  const len = langRest.length;
620
621
  let extendedRest = '';
621
622
  if (len) {
622
623
  for (let i = 0; i < len; i++) {
623
- extendedRest += `-${langRest[i]}${codePart}`;
624
+ extendedRest += `-${langRest[i]}${LANG_PART}`;
624
625
  }
625
626
  }
626
627
  reg =
627
628
  new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');
628
629
  } else {
629
- reg = new RegExp(`^${astName}${codePart}$`, 'i');
630
+ reg = new RegExp(`^${astName}${LANG_PART}$`, 'i');
630
631
  }
631
632
  if (node.hasAttribute('lang')) {
632
633
  if (reg.test(node.getAttribute('lang'))) {
@@ -719,8 +720,8 @@ export class Matcher {
719
720
  if (selector.includes(':has(')) {
720
721
  res = null;
721
722
  } else {
722
- let bool;
723
723
  const l = branches.length;
724
+ let bool;
724
725
  for (let i = 0; i < l; i++) {
725
726
  const leaves = branches[i];
726
727
  bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);
@@ -734,8 +735,8 @@ export class Matcher {
734
735
  }
735
736
  } else {
736
737
  const forgive = /^(?:is|where)$/.test(astName);
737
- let bool;
738
738
  const l = twigBranches.length;
739
+ let bool;
739
740
  for (let i = 0; i < l; i++) {
740
741
  const branch = twigBranches[i];
741
742
  const lastIndex = branch.length - 1;
@@ -979,7 +980,7 @@ export class Matcher {
979
980
  break;
980
981
  }
981
982
  case 'disabled': {
982
- if (FORM_PARTS.test(localName) || isCustomElementName(localName)) {
983
+ if (FORM_ITEM.test(localName) || isCustomElementName(localName)) {
983
984
  if (node.disabled || node.hasAttribute('disabled')) {
984
985
  matched.add(node);
985
986
  } else {
@@ -999,7 +1000,7 @@ export class Matcher {
999
1000
  break;
1000
1001
  }
1001
1002
  case 'enabled': {
1002
- if ((FORM_PARTS.test(localName) || isCustomElementName(localName)) &&
1003
+ if ((FORM_ITEM.test(localName) || isCustomElementName(localName)) &&
1003
1004
  !(node.disabled && node.hasAttribute('disabled'))) {
1004
1005
  matched.add(node);
1005
1006
  }
@@ -2303,6 +2304,29 @@ export class Matcher {
2303
2304
  ];
2304
2305
  }
2305
2306
 
2307
+ /**
2308
+ * sort nodes
2309
+ * @param {object} nodes - collection of nodes
2310
+ * @returns {Array.<object|undefined>} - collection of sorted nodes
2311
+ */
2312
+ _sortNodes(nodes) {
2313
+ const arr = [...nodes];
2314
+ if (arr.length > 1) {
2315
+ arr.sort((a, b) => {
2316
+ const posBit = a.compareDocumentPosition(b);
2317
+ let res;
2318
+ if (posBit & DOCUMENT_POSITION_PRECEDING ||
2319
+ posBit & DOCUMENT_POSITION_CONTAINS) {
2320
+ res = 1;
2321
+ } else {
2322
+ res = -1;
2323
+ }
2324
+ return res;
2325
+ });
2326
+ }
2327
+ return arr;
2328
+ }
2329
+
2306
2330
  /**
2307
2331
  * match nodes
2308
2332
  * @param {string} targetType - target type
@@ -2334,7 +2358,7 @@ export class Matcher {
2334
2358
  }
2335
2359
  }
2336
2360
  } else if (targetType === TARGET_FIRST) {
2337
- const [node] = [...matched];
2361
+ const [node] = this._sortNodes(matched);
2338
2362
  nodes.add(node);
2339
2363
  } else {
2340
2364
  const n = [...nodes];
@@ -2362,7 +2386,7 @@ export class Matcher {
2362
2386
  if (matchedNodes.size) {
2363
2387
  if (j === lastIndex) {
2364
2388
  if (targetType === TARGET_FIRST) {
2365
- const [node] = [...matchedNodes];
2389
+ const [node] = this._sortNodes(matchedNodes);
2366
2390
  nodes.add(node);
2367
2391
  } else {
2368
2392
  const n = [...nodes];
@@ -2427,29 +2451,6 @@ export class Matcher {
2427
2451
  return nodes;
2428
2452
  }
2429
2453
 
2430
- /**
2431
- * sort nodes
2432
- * @param {object} nodes - collection of nodes
2433
- * @returns {Array.<object|undefined>} - collection of sorted nodes
2434
- */
2435
- _sortNodes(nodes) {
2436
- const arr = [...nodes];
2437
- if (arr.length > 1) {
2438
- arr.sort((a, b) => {
2439
- let res;
2440
- const posBit = a.compareDocumentPosition(b);
2441
- if (posBit & DOCUMENT_POSITION_PRECEDING ||
2442
- posBit & DOCUMENT_POSITION_CONTAINS) {
2443
- res = 1;
2444
- } else {
2445
- res = -1;
2446
- }
2447
- return res;
2448
- });
2449
- }
2450
- return arr;
2451
- }
2452
-
2453
2454
  /**
2454
2455
  * matches
2455
2456
  * @returns {boolean} - `true` if matched `false` otherwise
@@ -43,9 +43,9 @@ export class Matcher {
43
43
  _findNodes(twig: object, targetType: string): object;
44
44
  _getFirstTwig(branch: Array<object>): object;
45
45
  _collectNodes(targetType: string): Array<Array<object | undefined>>;
46
+ _sortNodes(nodes: object): Array<object | undefined>;
46
47
  _matchNodes(targetType: string): object;
47
48
  _find(targetType: string): object;
48
- _sortNodes(nodes: object): Array<object | undefined>;
49
49
  matches(): boolean;
50
50
  closest(): object | null;
51
51
  querySelector(): object | null;