@asamuzakjp/dom-selector 1.2.2 → 1.2.3
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 +32 -32
- package/dist/cjs/js/constant.js +1 -1
- package/dist/cjs/js/constant.js.map +3 -3
- package/dist/cjs/js/matcher.js +1 -1
- package/dist/cjs/js/matcher.js.map +3 -3
- package/package.json +3 -3
- package/src/js/constant.js +2 -0
- package/src/js/matcher.js +390 -144
- package/types/js/constant.d.ts +2 -0
- package/types/js/matcher.d.ts +9 -3
package/README.md
CHANGED
|
@@ -231,38 +231,38 @@ const dom = new JSDOM('', {
|
|
|
231
231
|
|
|
232
232
|
|method('selector')|jsdom v23.0.1 (nwsapi)|patched-jsdom (dom-selector)|Result|
|
|
233
233
|
|:-----------------|:-----------------|:-----------------|:-----------------|
|
|
234
|
-
|matches('.content')|2,
|
|
235
|
-
|matches('div.container:not(.box)')|1,
|
|
236
|
-
|matches('.box + .box')|2,
|
|
237
|
-
|matches('.box ~ .box')|2,
|
|
238
|
-
|matches('.box > .block')|2,
|
|
239
|
-
|matches('.box .content')|
|
|
240
|
-
|matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|
|
|
241
|
-
|matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|
|
|
242
|
-
|closest('.content')|1,
|
|
243
|
-
|closest('div.container:not(.box)')|
|
|
244
|
-
|closest('.box + .box')|
|
|
245
|
-
|closest('.box ~ .box')|
|
|
246
|
-
|closest('.box > .block')|
|
|
247
|
-
|closest('.box .content')|
|
|
248
|
-
|closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|
|
|
249
|
-
|closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|12,
|
|
250
|
-
|querySelector('.content')|
|
|
251
|
-
|querySelector('div.container:not(.box)')|
|
|
252
|
-
|querySelector('.box + .box')|
|
|
253
|
-
|querySelector('.box ~ .box')|86,
|
|
254
|
-
|querySelector('.box > .block')|1,
|
|
255
|
-
|querySelector('.box .content')|
|
|
256
|
-
|querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|
|
|
257
|
-
|querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|
|
|
258
|
-
|querySelectorAll('.content')|
|
|
259
|
-
|querySelectorAll('div.container:not(.box)')|
|
|
260
|
-
|querySelectorAll('.box + .box')|
|
|
261
|
-
|querySelectorAll('.box ~ .box')|101,
|
|
262
|
-
|querySelectorAll('.box > .block')|1,
|
|
263
|
-
|querySelectorAll('.box .content')|
|
|
264
|
-
|querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|
|
|
265
|
-
|querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|
|
|
234
|
+
|matches('.content')|2,790,387 ops/sec ±0.56%|137,454 ops/sec ±0.73%|jsdom is 20.3 times faster than patched-jsdom. patched-jsdom took 0.007msec.|
|
|
235
|
+
|matches('div.container:not(.box)')|1,408,783 ops/sec ±1.28%|59,217 ops/sec ±1.37%|jsdom is 23.8 times faster than patched-jsdom. patched-jsdom took 0.017msec.|
|
|
236
|
+
|matches('.box + .box')|2,343,468 ops/sec ±1.28%|112,352 ops/sec ±1.81%|jsdom is 20.9 times faster than patched-jsdom. patched-jsdom took 0.009msec.|
|
|
237
|
+
|matches('.box ~ .box')|2,343,341 ops/sec ±1.96%|113,174 ops/sec ±1.63%|jsdom is 20.7 times faster than patched-jsdom. patched-jsdom took 0.009msec.|
|
|
238
|
+
|matches('.box > .block')|2,373,157 ops/sec ±1.68%|113,522 ops/sec ±1.53%|jsdom is 20.9 times faster than patched-jsdom. patched-jsdom took 0.009msec.|
|
|
239
|
+
|matches('.box .content')|395,436 ops/sec ±1.41%|62,201 ops/sec ±1.59%|jsdom is 6.4 times faster than patched-jsdom. patched-jsdom took 0.016msec.|
|
|
240
|
+
|matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|183,889 ops/sec ±1.55%|17,327 ops/sec ±1.86%|jsdom is 10.6 times faster than patched-jsdom. patched-jsdom took 0.058msec.|
|
|
241
|
+
|matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|25,581 ops/sec ±2.03%|jsdom throws. patched-jsdom took 0.039msec.|
|
|
242
|
+
|closest('.content')|1,797,866 ops/sec ±1.68%|72,823 ops/sec ±1.67%|jsdom is 24.7 times faster than patched-jsdom. patched-jsdom took 0.014msec.|
|
|
243
|
+
|closest('div.container:not(.box)')|277,238 ops/sec ±1.42%|36,770 ops/sec ±1.72%|jsdom is 7.5 times faster than patched-jsdom. patched-jsdom took 0.027msec.|
|
|
244
|
+
|closest('.box + .box')|453,371 ops/sec ±0.20%|56,315 ops/sec ±1.48%|jsdom is 8.1 times faster than patched-jsdom. patched-jsdom took 0.018msec.|
|
|
245
|
+
|closest('.box ~ .box')|178,393 ops/sec ±1.40%|36,132 ops/sec ±1.43%|jsdom is 4.9 times faster than patched-jsdom. patched-jsdom took 0.028msec.|
|
|
246
|
+
|closest('.box > .block')|474,044 ops/sec ±1.50%|53,002 ops/sec ±1.48%|jsdom is 8.9 times faster than patched-jsdom. patched-jsdom took 0.019msec.|
|
|
247
|
+
|closest('.box .content')|369,162 ops/sec ±1.49%|44,192 ops/sec ±1.44%|jsdom is 8.4 times faster than patched-jsdom. patched-jsdom took 0.023msec.|
|
|
248
|
+
|closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|177,932 ops/sec ±1.35%|15,526 ops/sec ±1.50%|jsdom is 11.5 times faster than patched-jsdom. patched-jsdom took 0.064msec.|
|
|
249
|
+
|closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|12,109 ops/sec ±1.60%|jsdom throws. patched-jsdom took 0.083msec.|
|
|
250
|
+
|querySelector('.content')|3,370 ops/sec ±1.29%|66,269 ops/sec ±1.55%|patched-jsdom is 19.7 times faster than jsdom. patched-jsdom took 0.015msec.|
|
|
251
|
+
|querySelector('div.container:not(.box)')|85,849 ops/sec ±1.47%|45,952 ops/sec ±1.76%|jsdom is 1.9 times faster than patched-jsdom. patched-jsdom took 0.022msec.|
|
|
252
|
+
|querySelector('.box + .box')|85,336 ops/sec ±0.65%|63,882 ops/sec ±1.76%|jsdom is 1.3 times faster than patched-jsdom. patched-jsdom took 0.016msec.|
|
|
253
|
+
|querySelector('.box ~ .box')|86,825 ops/sec ±0.33%|32,031 ops/sec ±1.65%|jsdom is 2.7 times faster than patched-jsdom. patched-jsdom took 0.031msec.|
|
|
254
|
+
|querySelector('.box > .block')|1,442 ops/sec ±1.17%|61,146 ops/sec ±0.16%|patched-jsdom is 42.4 times faster than jsdom. patched-jsdom took 0.016msec.|
|
|
255
|
+
|querySelector('.box .content')|729 ops/sec ±0.12%|41,451 ops/sec ±1.62%|patched-jsdom is 56.9 times faster than jsdom. patched-jsdom took 0.024msec.|
|
|
256
|
+
|querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|272 ops/sec ±1.15%|839 ops/sec ±1.20%|patched-jsdom is 3.1 times faster than jsdom. patched-jsdom took 1.192msec.|
|
|
257
|
+
|querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|667 ops/sec ±1.28%|jsdom throws. patched-jsdom took 1.498msec.|
|
|
258
|
+
|querySelectorAll('.content')|3,171 ops/sec ±1.16%|847 ops/sec ±1.43%|jsdom is 3.7 times faster than patched-jsdom. patched-jsdom took 1.181msec.|
|
|
259
|
+
|querySelectorAll('div.container:not(.box)')|99,610 ops/sec ±1.61%|23,436 ops/sec ±1.57%|jsdom is 4.3 times faster than patched-jsdom. patched-jsdom took 0.043msec.|
|
|
260
|
+
|querySelectorAll('.box + .box')|101,854 ops/sec ±1.38%|28,117 ops/sec ±1.77%|jsdom is 3.6 times faster than patched-jsdom. patched-jsdom took 0.036msec.|
|
|
261
|
+
|querySelectorAll('.box ~ .box')|101,097 ops/sec ±1.35%|12,068 ops/sec ±1.62%|jsdom is 8.4 times faster than patched-jsdom. patched-jsdom took 0.083msec.|
|
|
262
|
+
|querySelectorAll('.box > .block')|1,367 ops/sec ±1.18%|3,167 ops/sec ±1.59%|patched-jsdom is 2.3 times faster than jsdom. patched-jsdom took 0.316msec.|
|
|
263
|
+
|querySelectorAll('.box .content')|676 ops/sec ±1.29%|726 ops/sec ±0.40%|patched-jsdom is 1.1 times faster than jsdom. patched-jsdom took 1.378msec.|
|
|
264
|
+
|querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner > .content')|273 ops/sec ±0.23%|822 ops/sec ±1.48%|patched-jsdom is 3.0 times faster than jsdom. patched-jsdom took 1.217msec.|
|
|
265
|
+
|querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box .block.inner:has(>.content)')|N/A|655 ops/sec ±1.80% |jsdom throws. patched-jsdom took 1.527msec.|
|
|
266
266
|
|
|
267
267
|
|
|
268
268
|
## Acknowledgments
|
package/dist/cjs/js/constant.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var E=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var T=(o,t)=>{for(var r in t)E(o,r,{get:t[r],enumerable:!0})},_=(o,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of n(t))!x.call(o,e)&&e!==r&&E(o,e,{get:()=>t[e],enumerable:!(s=c(t,e))||s.enumerable});return o};var p=o=>_(E({},"__esModule",{value:!0}),o);var
|
|
1
|
+
var E=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var T=(o,t)=>{for(var r in t)E(o,r,{get:t[r],enumerable:!0})},_=(o,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of n(t))!x.call(o,e)&&e!==r&&E(o,e,{get:()=>t[e],enumerable:!(s=c(t,e))||s.enumerable});return o};var p=o=>_(E({},"__esModule",{value:!0}),o);var et={};T(et,{ALPHA_NUM:()=>O,AN_PLUS_B:()=>S,BIT_01:()=>d,BIT_02:()=>i,BIT_04:()=>W,BIT_08:()=>u,BIT_16:()=>Y,BIT_32:()=>h,BIT_HYPHEN:()=>X,COMBINATOR:()=>N,DOCUMENT_FRAGMENT_NODE:()=>j,DOCUMENT_NODE:()=>Z,DOCUMENT_POSITION_CONTAINED_BY:()=>v,DOCUMENT_POSITION_CONTAINS:()=>q,DOCUMENT_POSITION_PRECEDING:()=>k,DUO:()=>$,ELEMENT_NODE:()=>f,HEX:()=>b,IDENTIFIER:()=>D,MAX_BIT_16:()=>m,NOT_SUPPORTED_ERR:()=>I,NTH:()=>R,RAW:()=>C,REG_LOGICAL_PSEUDO:()=>Q,REG_SHADOW_HOST:()=>V,REG_SHADOW_MODE:()=>tt,REG_SHADOW_PSEUDO:()=>ot,SELECTOR:()=>A,SELECTOR_ATTR:()=>L,SELECTOR_CLASS:()=>P,SELECTOR_ID:()=>M,SELECTOR_LIST:()=>U,SELECTOR_PSEUDO_CLASS:()=>l,SELECTOR_PSEUDO_ELEMENT:()=>F,SELECTOR_TYPE:()=>B,SHOW_DOCUMENT:()=>z,SHOW_DOCUMENT_FRAGMENT:()=>J,SHOW_ELEMENT:()=>K,STRING:()=>H,SYNTAX_ERR:()=>G,TEXT_NODE:()=>g,TYPE_FROM:()=>w,TYPE_TO:()=>y,U_FFFD:()=>a});module.exports=p(et);const O="[A-Z\\d]+",S="AnPlusB",N="Combinator",D="Identifier",I="NotSupportedError",R="Nth",C="Raw",A="Selector",L="AttributeSelector",P="ClassSelector",M="IdSelector",U="SelectorList",l="PseudoClassSelector",F="PseudoElementSelector",B="TypeSelector",H="String",G="SyntaxError",a="\uFFFD",d=1,i=2,W=4,u=8,Y=16,h=32,X=45,$=2,b=16,m=65535,w=8,y=-1,f=1,g=3,Z=9,j=11,k=2,q=8,v=16,z=256,J=1024,K=1,Q=/^(?:(?:ha|i)s|not|where)$/,V=/^host(?:-context)?$/,tt=/^(?:close|open)$/,ot=/^part|slotted$/;0&&(module.exports={ALPHA_NUM,AN_PLUS_B,BIT_01,BIT_02,BIT_04,BIT_08,BIT_16,BIT_32,BIT_HYPHEN,COMBINATOR,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,DUO,ELEMENT_NODE,HEX,IDENTIFIER,MAX_BIT_16,NOT_SUPPORTED_ERR,NTH,RAW,REG_LOGICAL_PSEUDO,REG_SHADOW_HOST,REG_SHADOW_MODE,REG_SHADOW_PSEUDO,SELECTOR,SELECTOR_ATTR,SELECTOR_CLASS,SELECTOR_ID,SELECTOR_LIST,SELECTOR_PSEUDO_CLASS,SELECTOR_PSEUDO_ELEMENT,SELECTOR_TYPE,SHOW_DOCUMENT,SHOW_DOCUMENT_FRAGMENT,SHOW_ELEMENT,STRING,SYNTAX_ERR,TEXT_NODE,TYPE_FROM,TYPE_TO,U_FFFD});
|
|
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 ALPHA_NUM = '[A-Z\\\\d]+';\nexport const AN_PLUS_B = 'AnPlusB';\nexport const COMBINATOR = 'Combinator';\nexport const IDENTIFIER = 'Identifier';\nexport const NOT_SUPPORTED_ERR = 'NotSupportedError';\nexport const NTH = 'Nth';\nexport const RAW = 'Raw';\nexport const SELECTOR = 'Selector';\nexport const SELECTOR_ATTR = 'AttributeSelector';\nexport const SELECTOR_CLASS = 'ClassSelector';\nexport const SELECTOR_ID = 'IdSelector';\nexport const SELECTOR_LIST = 'SelectorList';\nexport const SELECTOR_PSEUDO_CLASS = 'PseudoClassSelector';\nexport const SELECTOR_PSEUDO_ELEMENT = 'PseudoElementSelector';\nexport const SELECTOR_TYPE = 'TypeSelector';\nexport const STRING = 'String';\nexport const SYNTAX_ERR = 'SyntaxError';\nexport const U_FFFD = '\\uFFFD';\n\n/* numeric */\nexport const BIT_01 = 1;\nexport const BIT_02 = 2;\nexport const BIT_04 = 4;\nexport const BIT_08 = 8;\nexport const BIT_16 = 0x10;\nexport const BIT_32 = 0x20;\nexport const BIT_HYPHEN = 0x2D;\nexport const DUO = 2;\nexport const HEX = 16;\nexport const MAX_BIT_16 = 0xFFFF;\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 = 2;\nexport const DOCUMENT_POSITION_CONTAINS = 8;\nexport const DOCUMENT_POSITION_CONTAINED_BY = 0x10;\n\n/* NodeFilter */\nexport const SHOW_ELEMENT = 1;\n\n/* regexp */\nexport const REG_LOGICAL_PSEUDO = /^(?:(?:ha|i)s|not|where)$/;\nexport const REG_SHADOW_HOST = /^host(?:-context)?$/;\nexport const REG_SHADOW_MODE = /^(?:close|open)$/;\nexport const REG_SHADOW_PSEUDO = /^part|slotted$/;\n"],
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,eAAAE,EAAA,cAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,2BAAAC,EAAA,kBAAAC,EAAA,mCAAAC,EAAA,+BAAAC,EAAA,gCAAAC,EAAA,QAAAC,EAAA,iBAAAC,EAAA,QAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,sBAAAC,EAAA,QAAAC,EAAA,QAAAC,EAAA,uBAAAC,EAAA,oBAAAC,EAAA,oBAAAC,
|
|
6
|
-
"names": ["constant_exports", "__export", "ALPHA_NUM", "AN_PLUS_B", "BIT_01", "BIT_02", "BIT_04", "BIT_08", "BIT_16", "BIT_32", "BIT_HYPHEN", "COMBINATOR", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_PRECEDING", "DUO", "ELEMENT_NODE", "HEX", "IDENTIFIER", "MAX_BIT_16", "NOT_SUPPORTED_ERR", "NTH", "RAW", "REG_LOGICAL_PSEUDO", "REG_SHADOW_HOST", "REG_SHADOW_MODE", "REG_SHADOW_PSEUDO", "SELECTOR", "SELECTOR_ATTR", "SELECTOR_CLASS", "SELECTOR_ID", "SELECTOR_LIST", "SELECTOR_PSEUDO_CLASS", "SELECTOR_PSEUDO_ELEMENT", "SELECTOR_TYPE", "SHOW_ELEMENT", "STRING", "SYNTAX_ERR", "TEXT_NODE", "TYPE_FROM", "TYPE_TO", "U_FFFD", "__toCommonJS"]
|
|
4
|
+
"sourcesContent": ["/**\n * constant.js\n */\n\n/* string */\nexport const ALPHA_NUM = '[A-Z\\\\d]+';\nexport const AN_PLUS_B = 'AnPlusB';\nexport const COMBINATOR = 'Combinator';\nexport const IDENTIFIER = 'Identifier';\nexport const NOT_SUPPORTED_ERR = 'NotSupportedError';\nexport const NTH = 'Nth';\nexport const RAW = 'Raw';\nexport const SELECTOR = 'Selector';\nexport const SELECTOR_ATTR = 'AttributeSelector';\nexport const SELECTOR_CLASS = 'ClassSelector';\nexport const SELECTOR_ID = 'IdSelector';\nexport const SELECTOR_LIST = 'SelectorList';\nexport const SELECTOR_PSEUDO_CLASS = 'PseudoClassSelector';\nexport const SELECTOR_PSEUDO_ELEMENT = 'PseudoElementSelector';\nexport const SELECTOR_TYPE = 'TypeSelector';\nexport const STRING = 'String';\nexport const SYNTAX_ERR = 'SyntaxError';\nexport const U_FFFD = '\\uFFFD';\n\n/* numeric */\nexport const BIT_01 = 1;\nexport const BIT_02 = 2;\nexport const BIT_04 = 4;\nexport const BIT_08 = 8;\nexport const BIT_16 = 0x10;\nexport const BIT_32 = 0x20;\nexport const BIT_HYPHEN = 0x2D;\nexport const DUO = 2;\nexport const HEX = 16;\nexport const MAX_BIT_16 = 0xFFFF;\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 = 2;\nexport const DOCUMENT_POSITION_CONTAINS = 8;\nexport const DOCUMENT_POSITION_CONTAINED_BY = 0x10;\n\n/* NodeFilter */\nexport const SHOW_DOCUMENT = 0x100;\nexport const SHOW_DOCUMENT_FRAGMENT = 0x400;\nexport const SHOW_ELEMENT = 1;\n\n/* regexp */\nexport const REG_LOGICAL_PSEUDO = /^(?:(?:ha|i)s|not|where)$/;\nexport const REG_SHADOW_HOST = /^host(?:-context)?$/;\nexport const REG_SHADOW_MODE = /^(?:close|open)$/;\nexport const REG_SHADOW_PSEUDO = /^part|slotted$/;\n"],
|
|
5
|
+
"mappings": "4ZAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,eAAAE,EAAA,cAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,WAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,2BAAAC,EAAA,kBAAAC,EAAA,mCAAAC,EAAA,+BAAAC,EAAA,gCAAAC,EAAA,QAAAC,EAAA,iBAAAC,EAAA,QAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,sBAAAC,EAAA,QAAAC,EAAA,QAAAC,EAAA,uBAAAC,EAAA,oBAAAC,EAAA,oBAAAC,GAAA,sBAAAC,GAAA,aAAAC,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,kBAAAC,EAAA,0BAAAC,EAAA,4BAAAC,EAAA,kBAAAC,EAAA,kBAAAC,EAAA,2BAAAC,EAAA,iBAAAC,EAAA,WAAAC,EAAA,eAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,YAAAC,EAAA,WAAAC,IAAA,eAAAC,EAAA9C,IAKO,MAAME,EAAY,YACZC,EAAY,UACZQ,EAAa,aACbS,EAAa,aACbE,EAAoB,oBACpBC,EAAM,MACNC,EAAM,MACNK,EAAW,WACXC,EAAgB,oBAChBC,EAAiB,gBACjBC,EAAc,aACdC,EAAgB,eAChBC,EAAwB,sBACxBC,EAA0B,wBAC1BC,EAAgB,eAChBI,EAAS,SACTC,EAAa,cACbI,EAAS,SAGTzC,EAAS,EACTC,EAAS,EACTC,EAAS,EACTC,EAAS,EACTC,EAAS,GACTC,EAAS,GACTC,EAAa,GACbO,EAAM,EACNE,EAAM,GACNE,EAAa,MACbsB,EAAY,EACZC,EAAU,GAGV1B,EAAe,EACfwB,EAAY,EACZ7B,EAAgB,EAChBD,EAAyB,GACzBI,EAA8B,EAC9BD,EAA6B,EAC7BD,EAAiC,GAGjCuB,EAAgB,IAChBC,EAAyB,KACzBC,EAAe,EAGfd,EAAqB,4BACrBC,EAAkB,sBAClBC,GAAkB,mBAClBC,GAAoB",
|
|
6
|
+
"names": ["constant_exports", "__export", "ALPHA_NUM", "AN_PLUS_B", "BIT_01", "BIT_02", "BIT_04", "BIT_08", "BIT_16", "BIT_32", "BIT_HYPHEN", "COMBINATOR", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_PRECEDING", "DUO", "ELEMENT_NODE", "HEX", "IDENTIFIER", "MAX_BIT_16", "NOT_SUPPORTED_ERR", "NTH", "RAW", "REG_LOGICAL_PSEUDO", "REG_SHADOW_HOST", "REG_SHADOW_MODE", "REG_SHADOW_PSEUDO", "SELECTOR", "SELECTOR_ATTR", "SELECTOR_CLASS", "SELECTOR_ID", "SELECTOR_LIST", "SELECTOR_PSEUDO_CLASS", "SELECTOR_PSEUDO_ELEMENT", "SELECTOR_TYPE", "SHOW_DOCUMENT", "SHOW_DOCUMENT_FRAGMENT", "SHOW_ELEMENT", "STRING", "SYNTAX_ERR", "TEXT_NODE", "TYPE_FROM", "TYPE_TO", "U_FFFD", "__toCommonJS"]
|
|
7
7
|
}
|
package/dist/cjs/js/matcher.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var B=Object.create;var R=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(S,a)=>{for(var e in a)R(S,e,{get:a[e],enumerable:!0})},U=(S,a,e,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of F(a))!j.call(S,f)&&f!==e&&R(S,f,{get:()=>a[f],enumerable:!(c=z(a,f))||c.enumerable});return S};var W=(S,a,e)=>(e=S!=null?B(V(S)):{},U(a||!S||!S.__esModule?R(e,"default",{value:S,enumerable:!0}):e,S)),G=S=>U(R({},"__esModule",{value:!0}),S);var X={};H(X,{Matcher:()=>q});module.exports=G(X);var M=W(require("is-potential-custom-element-name"),1),x=require("./dom-util.js"),k=require("./parser.js"),o=require("./constant.js");const C="next",D="prev",$="all",I="first",O="lineal",P="self";class q{#t;#r;#a;#e;#l;#s;#o;#i;constructor(a,e,c={}){const{warn:f}=c;this.#r=new Map([[o.SELECTOR_PSEUDO_ELEMENT,o.BIT_01],[o.SELECTOR_ID,o.BIT_02],[o.SELECTOR_CLASS,o.BIT_04],[o.SELECTOR_TYPE,o.BIT_08],[o.SELECTOR_ATTR,o.BIT_16],[o.SELECTOR_PSEUDO_CLASS,o.BIT_32]]),this.#a=new WeakMap,this.#o=a,this.#e=e,this.#i=!!f,[this.#t,this.#l]=this._prepare(a),this.#s=this._getRoot(e)}_onError(a){if(a instanceof DOMException&&a.name===o.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw a}_getRoot(a=this.#e){let e,c;switch(a.nodeType){case o.DOCUMENT_NODE:{e=a,c=a;break}case o.DOCUMENT_FRAGMENT_NODE:{e=a.ownerDocument,c=a;break}case o.ELEMENT_NODE:{if(a.ownerDocument.contains(a))e=a.ownerDocument,c=a.ownerDocument;else{let r=a;for(;r&&r.parentNode;)r=r.parentNode;e=r.ownerDocument,c=r}break}default:throw new TypeError(`Unexpected node ${a.nodeName}`)}const f=(0,x.isInShadowTree)(a);return{document:e,root:c,shadow:f}}_sortLeaves(a){const e=[...a];return e.length>1&&e.sort((c,f)=>{const{type:r}=c,{type:d}=f,m=this.#r.get(r),l=this.#r.get(d);let t;return m===l?t=0:m>l?t=1:t=-1,t}),e}_prepare(a=this.#o){const e=(0,k.parseSelector)(a),c=(0,k.walkAST)(e),f=[],r=[];let d=0;for(const[...m]of c){const l=[];let t=m.shift();if(t&&t.type!==o.COMBINATOR){const s=new Set;for(;t;){if(t.type===o.COMBINATOR){const[n]=m;if(n.type===o.COMBINATOR){const b=`Invalid combinator ${t.name}${n.name}`;throw new DOMException(b,o.SYNTAX_ERR)}l.push({combo:t,leaves:this._sortLeaves(s)}),s.clear()}else t&&s.add(t);if(m.length)t=m.shift();else{l.push({combo:null,leaves:this._sortLeaves(s)}),s.clear();break}}}f.push({branch:l,filtered:!1,find:null,skip:!1}),r[d]=new Set,d++}return[f,r]}_collectNthChild(a,e){const{a:c,b:f,reverse:r,selector:d}=a,{parentNode:m}=e,l=new Set;let t;if(d&&(this.#a.has(d)?t=this.#a.get(d):(t=(0,k.walkAST)(d),this.#a.set(d,t))),m){const s=[].slice.call(m.children),n=s.length;if(n){const b=new Set;if(t){const i=t.length;for(const h of s){let u;for(let w=0;w<i;w++){const N=t[w];if(u=this._matchLeaves(N,h),!u)break}u&&b.add(h)}}if(r&&s.reverse(),c===0){if(f>0&&f<=n){if(b.size)for(let i=0;i<n;i++){const h=s[i];if(b.has(h)){l.add(h);break}}else if(!d){const i=s[f-1];l.add(i)}}}else{let i=f-1;if(c>0)for(;i<0;)i+=c;if(i>=0&&i<n){let h=c>0?0:f-1;for(let u=0;u<n&&i>=0&&i<n;u++){const w=s[u];b.size?b.has(w)&&(h===i&&(l.add(w),i+=c),c>0?h++:h--):u===i&&(d||l.add(w),i+=c)}}}}}else{const{root:s}=this.#s;if(e===s&&s.nodeType===o.ELEMENT_NODE&&c+f===1)if(t){const n=t.length;let b;for(let i=0;i<n;i++){const h=t[i];if(b=this._matchLeaves(h,e),b)break}b&&l.add(e)}else l.add(e)}return l}_collectNthOfType(a,e){const{a:c,b:f,reverse:r}=a,{localName:d,parentNode:m,prefix:l}=e,t=new Set;if(m){const s=[].slice.call(m.children),n=s.length;if(n)if(r&&s.reverse(),c===0){if(f>0&&f<=n){let b=0;for(let i=0;i<n;i++){const h=s[i],{localName:u,prefix:w}=h;if(u===d&&w===l){if(b===f-1){t.add(h);break}b++}}}}else{let b=f-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b<n){let i=c>0?0:f-1;for(let h=0;h<n;h++){const u=s[h],{localName:w,prefix:N}=u;if(w===d&&N===l){if(i===b&&(t.add(u),b+=c),b<0||b>=n)break;c>0?i++:i--}}}}}else{const{root:s}=this.#s;e===s&&s.nodeType===o.ELEMENT_NODE&&c+f===1&&t.add(e)}return t}_matchAnPlusB(a,e,c){const{nth:{a:f,b:r,name:d},selector:m}=a,l=(0,k.unescapeSelector)(d),t=new Map;l?(l==="even"?(t.set("a",2),t.set("b",0)):l==="odd"&&(t.set("a",2),t.set("b",1)),c.indexOf("last")>-1&&t.set("reverse",!0)):(typeof f=="string"&&/-?\d+/.test(f)?t.set("a",f*1):t.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?t.set("b",r*1):t.set("b",0),c.indexOf("last")>-1&&t.set("reverse",!0));let s=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){m&&t.set("selector",m);const n=Object.fromEntries(t),b=this._collectNthChild(n,e);b.size&&(s=b)}else if(/^nth-(?:last-)?of-type$/.test(c)){const n=Object.fromEntries(t),b=this._collectNthOfType(n,e);b.size&&(s=b)}}return s}_matchPseudoElementSelector(a,e={}){const{forgive:c}=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"placeholder":case"selection":case"target-text":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${a}`,o.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${a}()`,o.NOT_SUPPORTED_ERR);break}default:if(a.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${a}`,o.NOT_SUPPORTED_ERR)}else if(!c)throw new DOMException(`Unknown pseudo-element ::${a}`,o.SYNTAX_ERR)}}_matchDirectionPseudoClass(a,e){const c=(0,k.unescapeSelector)(a.name),f=(0,x.getDirectionality)(e);let r;return c===f&&(r=e),r??null}_matchLanguagePseudoClass(a,e){const c=(0,k.unescapeSelector)(a.name);let f;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(f=e);else{let r=e.parentNode;for(;r&&r.nodeType===o.ELEMENT_NODE;){if(r.hasAttribute("lang")){r.getAttribute("lang")&&(f=e);break}r=r.parentNode}}else if(c){const r=`(?:-${o.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${o.ALPHA_NUM}${r}$`,"i").test(c)){let m;if(c.indexOf("-")>-1){const[l,t,...s]=c.split("-");let n;l==="*"?n=`${o.ALPHA_NUM}${r}`:n=`${l}${r}`;const b=`-${t}${r}`,i=s.length;let h="";if(i)for(let u=0;u<i;u++)h+=`-${s[u]}${r}`;m=new RegExp(`^${n}${b}${h}$`,"i")}else m=new RegExp(`^${c}${r}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(f=e);else{let l=e.parentNode;for(;l&&l.nodeType===o.ELEMENT_NODE;){if(l.hasAttribute("lang")){const t=l.getAttribute("lang");m.test(t)&&(f=e);break}l=l.parentNode}}}}return f??null}_matchHasPseudoFunc(a,e){let c;if(Array.isArray(a)&&a.length){const[f]=a,{type:r}=f;let d;r===o.COMBINATOR?d=a.shift():d={name:" ",type:o.COMBINATOR};const m=[];for(;a.length;){const[s]=a,{type:n}=s;if(n===o.COMBINATOR)break;m.push(a.shift())}const l={combo:d,leaves:m},t=this._matchCombinator(l,e,{find:C});if(t.size)if(a.length){for(const s of t)if(c=this._matchHasPseudoFunc(Object.assign([],a),s),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(a,e){const{astName:c="",branches:f=[],selector:r="",twigBranches:d=[]}=a;let m;if(c==="has")if(r.includes(":has("))m=null;else{const l=f.length;let t;for(let s=0;s<l;s++){const n=f[s];if(t=this._matchHasPseudoFunc(Object.assign([],n),e),t)break}t&&(m=e)}else{const l=/^(?:is|where)$/.test(c),t=d.length;let s;for(let n=0;n<t;n++){const b=d[n],i=b.length-1,{leaves:h}=b[i];if(s=this._matchLeaves(h,e,{forgive:l}),s&&i>0){let u=new Set([e]);for(let w=i-1;w>=0;w--){const N=b[w],E=[];for(const A of u){const p=this._matchCombinator(N,A,{forgive:l,find:D});p.size&&E.push(...p)}if(E.length)if(w===0){s=!0;break}else u=new Set(E);else{s=!1;break}}}if(s)break}c==="not"?s||(m=e):s&&(m=e)}return m??null}_matchPseudoClassSelector(a,e,c={}){const{children:f}=a,{localName:r,parentNode:d}=e,{forgive:m}=c,l=(0,k.unescapeSelector)(a.name);let t=new Set;if(o.REG_LOGICAL_PSEUDO.test(l)){let s;if(this.#a.has(a))s=this.#a.get(a);else{const b=(0,k.walkAST)(a),i=[],h=[];for(const[...u]of b){for(const A of u){const p=(0,k.generateCSS)(A);i.push(p)}const w=[],N=new Set;let E=u.shift();for(;E;)if(E.type===o.COMBINATOR?(w.push({combo:E,leaves:[...N]}),N.clear()):E&&N.add(E),u.length)E=u.shift();else{w.push({combo:null,leaves:[...N]}),N.clear();break}h.push(w)}s={astName:l,branches:b,twigBranches:h,selector:i.join(",")},this.#a.set(a,s)}const n=this._matchLogicalPseudoFunc(s,e);n&&t.add(n)}else if(Array.isArray(f)){const[s]=f;if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const n=this._matchAnPlusB(s,e,l);n.size&&(t=n)}else if(l==="dir"){const n=this._matchDirectionPseudoClass(s,e);n&&t.add(n)}else if(l==="lang"){const n=this._matchLanguagePseudoClass(s,e);n&&t.add(n)}else switch(l){case"current":case"nth-col":case"nth-last-col":{if(this.#i)throw new DOMException(`Unsupported pseudo-class :${l}()`,o.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;default:if(!m)throw new DOMException(`Unknown pseudo-class :${l}()`,o.SYNTAX_ERR)}}else{const{document:s,root:n}=this.#s,b=/^a(?:rea)?$/,i=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,h=/^(?:(?:inpu|selec)t|button|form|textarea)$/,u=/^d(?:etails|ialog)$/,w=/^(?:checkbox|radio)$/,N=/^(?:date(?:time-local)?|month|time|week)$/,E=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,A=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(l){case"any-link":case"link":{b.test(r)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(b.test(r)&&e.hasAttribute("href")){const{href:p,origin:g,pathname:y}=new URL(s.URL),_=new URL(e.getAttribute("href"),p);_.origin===g&&_.pathname===y&&t.add(e)}break}case"visited":break;case"target":{const{hash:p}=new URL(s.URL);e.id&&p===`#${e.id}`&&s.contains(e)&&t.add(e);break}case"target-within":{const{hash:p}=new URL(s.URL);if(p){const g=p.replace(/^#/,"");let y=s.getElementById(g);for(;y;){if(y===e){t.add(e);break}y=y.parentNode}}break}case"scope":{this.#e.nodeType===o.ELEMENT_NODE?e===this.#e&&t.add(e):e===s.documentElement&&t.add(e);break}case"focus":{e===s.activeElement&&t.add(e);break}case"focus-within":{let p=s.activeElement;for(;p;){if(p===e){t.add(e);break}p=p.parentNode}break}case"open":{u.test(r)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{u.test(r)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(i.test(r)||(0,M.default)(r))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let p=d;for(;p&&p.localName!=="fieldset";)p=p.parentNode;p&&d.localName!=="legend"&&p.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(i.test(r)||(0,M.default)(r))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(r){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||N.test(e.type)||A.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,x.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||N.test(e.type)||A.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,x.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let p;r==="textarea"?p=e:r==="input"&&(e.hasAttribute("type")?A.test(e.getAttribute("type"))&&(p=e):p=e),p&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&r==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))||e.selected&&r==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&r==="input"&&e.type==="checkbox"||r==="progress"&&!e.hasAttribute("value"))t.add(e);else if(r==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const p=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=s.documentElement);const y=[].slice.call(g.getElementsByTagName("input"));let _;for(const v of y)if(v.getAttribute("type")==="radio"&&(p?v.getAttribute("name")===p&&(_=!!v.checked):v.hasAttribute("name")||(_=!!v.checked),_))break;_||t.add(e)}break}case"default":{const p=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(r==="button"&&!(e.hasAttribute("type")&&p.test(e.getAttribute("type")))||r==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let y=e.parentNode;for(;y&&y.localName!=="form";)y=y.parentNode;if(y){const _=s.createNodeIterator(y,o.SHOW_ELEMENT);let v=_.nextNode();for(;v;){const T=v.localName;let L;if(T==="button"?L=!(v.hasAttribute("type")&&p.test(v.getAttribute("type"))):T==="input"&&(L=v.hasAttribute("type")&&g.test(v.getAttribute("type"))),L){v===e&&t.add(e);break}v=_.nextNode()}}}else if(r==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(r==="option"){let y=!1,_=d;for(;_&&_.localName!=="datalist";){if(_.localName==="select"){(_.multiple||_.hasAttribute("multiple"))&&(y=!0);break}_=_.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=d.firstElementChild,T=new Set;let L=v;for(;L;){if(L.selected||L.hasAttribute("selected")){T.add(L);break}L=L.nextElementSibling}T.size||T.add(v),T.has(e)&&t.add(e)}}break}case"valid":{if(h.test(r))e.checkValidity()&&t.add(e);else if(r==="fieldset"){const p=s.createNodeIterator(e,o.SHOW_ELEMENT);let g=p.nextNode();g===e&&(g=p.nextNode());let y;for(;g&&!(h.test(g.localName)&&(y=g.checkValidity(),!y));)g=p.nextNode();y&&t.add(e)}break}case"invalid":{if(h.test(r))e.checkValidity()||t.add(e);else if(r==="fieldset"){const p=s.createNodeIterator(e,o.SHOW_ELEMENT);let g=p.nextNode();g===e&&(g=p.nextNode());let y;for(;g&&!(h.test(g.localName)&&(y=g.checkValidity(),!y));)g=p.nextNode();y||t.add(e)}break}case"in-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&E.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":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&E.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let p;if(/^(?:select|textarea)$/.test(r))p=e;else if(r==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||w.test(g)||N.test(g)||A.test(g))&&(p=e)}else p=e;p&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let p;if(/^(?:select|textarea)$/.test(r))p=e;else if(r==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||w.test(g)||N.test(g)||A.test(g))&&(p=e)}else p=e;p&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===s.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const p=e.childNodes.values();let g;for(const y of p)if(g=y.nodeType!==o.ELEMENT_NODE&&y.nodeType!==o.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(d&&e===d.firstElementChild||e===n&&n.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(d&&e===d.lastElementChild||e===n&&n.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(d&&e===d.firstElementChild&&e===d.lastElementChild||e===n&&n.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(d){const[p]=this._collectNthOfType({a:0,b:1},e);p&&t.add(p)}else e===n&&n.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(d){const[p]=this._collectNthOfType({a:0,b:1,reverse:!0},e);p&&t.add(p)}else e===n&&n.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(d){const[p]=this._collectNthOfType({a:0,b:1},e);if(p===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===n&&n.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#i)throw new DOMException(`Unsupported pseudo-element ::${l}`,o.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(this.#i)throw new DOMException(`Unsupported pseudo-class :${l}`,o.NOT_SUPPORTED_ERR);break}default:if(l.startsWith("-webkit-")){if(this.#i)throw new DOMException(`Unsupported pseudo-class :${l}`,o.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${l}`,o.SYNTAX_ERR)}}return t}_matchAttributeSelector(a,e){const{flags:c,matcher:f,name:r,value:d}=a;if(typeof c=="string"&&!/^[is]$/i.test(c)){const t=(0,k.generateCSS)(a);throw new DOMException(`Invalid selector ${t}`,o.SYNTAX_ERR)}const{attributes:m}=e;let l;if(m&&m.length){const{document:t}=this.#s;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 n=(0,k.unescapeSelector)(r.name);s&&(n=n.toLowerCase());const b=new Set;if(n.indexOf("|")>-1){const{prefix:i,tagName:h}=(0,x.selectorToNodeProps)(n);for(let{name:u,value:w}of m)switch(s&&(u=u.toLowerCase(),w=w.toLowerCase()),i){case"":{h===u&&b.add(w);break}case"*":{u.indexOf(":")>-1?u.endsWith(`:${h}`)&&b.add(w):h===u&&b.add(w);break}default:if(u.indexOf(":")>-1){const[N,E]=u.split(":");i===N&&h===E&&(0,x.isNamespaceDeclared)(i,e)&&b.add(w)}}}else for(let{name:i,value:h}of m)if(s&&(i=i.toLowerCase(),h=h.toLowerCase()),i.indexOf(":")>-1){const[u,w]=i.split(":");if(u==="xml"&&w==="lang")continue;n===w&&b.add(h)}else n===i&&b.add(h);if(b.size){const{name:i,value:h}=d||{};let u;switch(i?s?u=i.toLowerCase():u=i:h?s?u=h.toLowerCase():u=h:h===""&&(u=h),f){case"=":{typeof u=="string"&&b.has(u)&&(l=e);break}case"~=":{if(u&&typeof u=="string"){for(const w of b)if(new Set(w.split(/\s+/)).has(u)){l=e;break}}break}case"|=":{if(u&&typeof u=="string"){let w;for(const N of b)if(N===u||N.startsWith(`${u}-`)){w=N;break}w&&(l=e)}break}case"^=":{if(u&&typeof u=="string"){let w;for(const N of b)if(N.startsWith(`${u}`)){w=N;break}w&&(l=e)}break}case"$=":{if(u&&typeof u=="string"){let w;for(const N of b)if(N.endsWith(`${u}`)){w=N;break}w&&(l=e)}break}case"*=":{if(u&&typeof u=="string"){let w;for(const N of b)if(N.includes(`${u}`)){w=N;break}w&&(l=e)}break}case null:default:l=e}}}return l??null}_matchClassSelector(a,e){const c=(0,k.unescapeSelector)(a.name);let f;return e.classList.contains(c)&&(f=e),f??null}_matchIDSelector(a,e){const c=(0,k.unescapeSelector)(a.name),{id:f}=e;let r;return c===f&&(r=e),r??null}_matchTypeSelector(a,e,c={}){const f=(0,k.unescapeSelector)(a.name),{localName:r,prefix:d}=e,{forgive:m}=c,{document:l}=this.#s;let{prefix:t,tagName:s}=(0,x.selectorToNodeProps)(f,e);l.contentType==="text/html"&&(t=t.toLowerCase(),s=s.toLowerCase());let n,b;r.indexOf(":")>-1?[n,b]=r.split(":"):(n=d||"",b=r);let i;if(t===""&&n==="")e.namespaceURI===null&&(s==="*"||s===b)&&(i=e);else if(t==="*")(s==="*"||s===b)&&(i=e);else if(t===n){if((0,x.isNamespaceDeclared)(t,e))(s==="*"||s===b)&&(i=e);else if(!m)throw new DOMException(`Undeclared namespace ${t}`,o.SYNTAX_ERR)}else if(t&&!m&&!(0,x.isNamespaceDeclared)(t,e))throw new DOMException(`Undeclared namespace ${t}`,o.SYNTAX_ERR);return i??null}_matchShadowHostPseudoClass(a,e){const{children:c}=a,f=(0,k.unescapeSelector)(a.name);let r;if(Array.isArray(c)){const[d]=(0,k.walkAST)(c[0]),[...m]=d,{host:l}=e;if(f==="host"){let t;for(const s of m){const{type:n}=s;if(n===o.COMBINATOR){const b=(0,k.generateCSS)(a);throw new DOMException(`Invalid selector ${b}`,o.SYNTAX_ERR)}if(t=this._matchSelector(s,l).has(l),!t)break}t&&(r=e)}else if(f==="host-context"){let t=l,s;for(;t;){for(const n of m){const{type:b}=n;if(b===o.COMBINATOR){const i=(0,k.generateCSS)(a);throw new DOMException(`Invalid selector ${i}`,o.SYNTAX_ERR)}if(s=this._matchSelector(n,t).has(t),!s)break}if(s)break;t=t.parentNode}s&&(r=e)}}else if(f==="host")r=e;else throw new DOMException(`Invalid selector :${f}`,o.SYNTAX_ERR);return r??null}_matchSelector(a,e,c){const{type:f}=a,r=(0,k.unescapeSelector)(a.name),{shadow:d}=this.#s;let m=new Set;if(e.nodeType===o.ELEMENT_NODE)switch(f){case o.SELECTOR_ATTR:{const l=this._matchAttributeSelector(a,e);l&&m.add(l);break}case o.SELECTOR_CLASS:{const l=this._matchClassSelector(a,e);l&&m.add(l);break}case o.SELECTOR_ID:{const l=this._matchIDSelector(a,e);l&&m.add(l);break}case o.SELECTOR_PSEUDO_CLASS:{const l=this._matchPseudoClassSelector(a,e,c);l.size&&(m=l);break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(r,c);break}case o.SELECTOR_TYPE:default:{const l=this._matchTypeSelector(a,e,c);l&&m.add(l)}}else if(d&&f===o.SELECTOR_PSEUDO_CLASS&&e.nodeType===o.DOCUMENT_FRAGMENT_NODE){if(r!=="has"&&o.REG_LOGICAL_PSEUDO.test(r)){const l=this._matchPseudoClassSelector(a,e,c);l.size&&(m=l)}else if(o.REG_SHADOW_HOST.test(r)){const l=this._matchShadowHostPseudoClass(a,e);l&&m.add(l)}}return m}_matchLeaves(a,e,c){let f;for(const r of a)if(f=this._matchSelector(r,e,c).has(e),!f)break;return!!f}_findDescendantNodes(a,e){const[c,...f]=a,{type:r}=c,d=(0,k.unescapeSelector)(c.name),m=f.length>0,{document:l,root:t,shadow:s}=this.#s;let n=new Set,b=!1;if(s)b=!0;else switch(r){case o.SELECTOR_ID:{if(t.nodeType===o.ELEMENT_NODE)b=!0;else{const i=t.getElementById(d);i&&i!==e&&e.contains(i)&&(m?this._matchLeaves(f,i)&&n.add(i):n.add(i))}break}case o.SELECTOR_CLASS:{const i=[].slice.call(e.getElementsByClassName(d));if(i.length)if(m)for(const h of i)this._matchLeaves(f,h)&&n.add(h);else n=new Set(i);break}case o.SELECTOR_TYPE:{if(l.contentType==="text/html"&&!/[*|]/.test(d)){const i=[].slice.call(e.getElementsByTagName(d));if(i.length)if(m)for(const h of i)this._matchLeaves(f,h)&&n.add(h);else n=new Set(i)}else b=!0;break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(d);break}default:b=!0}return{nodes:n,pending:b}}_matchCombinator(a,e,c={}){const{combo:f,leaves:r}=a,{name:d}=f,{find:m,forgive:l}=c;let t=new Set;if(m===C)switch(d){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(r,s,{forgive:l})&&t.add(s);break}case"~":{let s=e.nextElementSibling;for(;s;)this._matchLeaves(r,s,{forgive:l})&&t.add(s),s=s.nextElementSibling;break}case">":{const s=[].slice.call(e.children);for(const n of s)this._matchLeaves(r,n,{forgive:l})&&t.add(n);break}case" ":default:{const{nodes:s,pending:n}=this._findDescendantNodes(r,e);if(s.size)t=s;else if(n){const{document:b}=this.#s,i=b.createNodeIterator(e,o.SHOW_ELEMENT);let h=i.nextNode();for(h===e&&(h=i.nextNode());h;)this._matchLeaves(r,h,{forgive:l})&&t.add(h),h=i.nextNode()}}}else switch(d){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(r,s,{forgive:l})&&t.add(s);break}case"~":{const s=[];let n=e.previousElementSibling;for(;n;)this._matchLeaves(r,n,{forgive:l})&&s.push(n),n=n.previousElementSibling;s.length&&(t=new Set(s.reverse()));break}case">":{const s=e.parentNode;s&&this._matchLeaves(r,s,{forgive:l})&&t.add(s);break}case" ":default:{const s=[];let n=e.parentNode;for(;n;)this._matchLeaves(r,n,{forgive:l})&&s.push(n),n=n.parentNode;s.length&&(t=new Set(s.reverse()))}}return t}_findNodes(a,e){const{leaves:[c,...f]}=a,{type:r}=c,d=(0,k.unescapeSelector)(c.name),{document:m,root:l,shadow:t}=this.#s;let s=new Set,n=!1;switch(r){case o.SELECTOR_ID:{if(e===P)this._matchLeaves([c],this.#e)&&s.add(this.#e);else if(e===O){let i=this.#e;for(;i;){if(this._matchLeaves([c],i)){s.add(i);break}i=i.parentNode}}else if(e===$||l.nodeType===o.ELEMENT_NODE)n=!0;else{const i=l.getElementById(d);i&&s.add(i)}break}case o.SELECTOR_CLASS:{if(e===P)this.#e.nodeType===o.ELEMENT_NODE&&this.#e.classList.contains(d)&&s.add(this.#e);else if(e===O){let i=this.#e;for(;i&&i.nodeType===o.ELEMENT_NODE;)i.classList.contains(d)&&s.add(i),i=i.parentNode}else if(l.nodeType===o.DOCUMENT_FRAGMENT_NODE){const i=[].slice.call(l.children),h=[];for(const u of i){u.classList.contains(d)&&h.push(u);const w=[].slice.call(u.getElementsByClassName(d));h.push(...w)}h.length&&(s=new Set(h))}else{const i=[].slice.call(l.getElementsByClassName(d));if(this.#e.nodeType===o.ELEMENT_NODE)for(const h of i)(h===this.#e||(0,x.isInclusive)(h,this.#e))&&s.add(h);else i.length&&(s=new Set(i))}break}case o.SELECTOR_TYPE:{if(e===P)this.#e.nodeType===o.ELEMENT_NODE&&this._matchLeaves([c],this.#e)&&s.add(this.#e);else if(e===O){let i=this.#e;for(;i&&i.nodeType===o.ELEMENT_NODE;)this._matchLeaves([c],i)&&s.add(i),i=i.parentNode}else if(m.contentType!=="text/html"||/[*|]/.test(d))n=!0;else if(l.nodeType===o.DOCUMENT_FRAGMENT_NODE){const i=d.toLowerCase(),h=[].slice.call(l.children),u=[];for(const w of h){w.localName===i&&u.push(w);const N=[].slice.call(w.getElementsByTagName(d));u.push(...N)}u.length&&(s=new Set(u))}else{const i=[].slice.call(l.getElementsByTagName(d));if(this.#e.nodeType===o.ELEMENT_NODE)for(const h of i)(h===this.#e||(0,x.isInclusive)(h,this.#e))&&s.add(h);else i.length&&(s=new Set(i))}break}case o.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(d);break}default:if(e!==O&&o.REG_SHADOW_HOST.test(d)){if(t&&this.#e.nodeType===o.DOCUMENT_FRAGMENT_NODE){const i=this._matchShadowHostPseudoClass(c,this.#e);i&&s.add(i)}}else if(e===P)this._matchLeaves([c],this.#e)&&s.add(this.#e);else if(e===O){let i=this.#e;for(;i;)this._matchLeaves([c],i)&&s.add(i),i=i.parentNode}else n=!0}const b=f.length;if(!s.size&&!n&&b){const i=f[b-1],{type:h}=i;if(h===o.SELECTOR_PSEUDO_CLASS){let u;l.nodeType===o.ELEMENT_NODE?u=l:u=l.firstElementChild,this._matchPseudoClassSelector(i,u)}}return{compound:b>0,nodes:s,pending:n}}_getEntryTwig(a,e){const c=a.length,f=a[0];let r,d;if(c>1){const{leaves:[{type:m}]}=f,l=a[c-1],{leaves:[{type:t}]}=l;t===o.SELECTOR_PSEUDO_ELEMENT||t===o.SELECTOR_ID?(r=D,d=l):m===o.SELECTOR_PSEUDO_ELEMENT||m===o.SELECTOR_ID?(r=C,d=f):e===I&&c<o.BIT_04?(r=D,d=l):(r=C,d=f)}else r=D,d=f;return{find:r,twig:d}}_collectNodes(a){const e=this.#t.values();if(a===$||a===I){const c=new Set;let f=0;for(const{branch:r}of e){const{find:d,twig:m}=this._getEntryTwig(r,a),{compound:l,nodes:t,pending:s}=this._findNodes(m,a);t.size?this.#l[f]=t:s?c.add(new Map([["index",f],["twig",m]])):this.#t[f].skip=!0,this.#t[f].filtered=!l,this.#t[f].find=d,f++}if(c.size){const{document:r,root:d}=this.#s,m=r.createNodeIterator(d,o.SHOW_ELEMENT);let l=m.nextNode();for(;l;){let t=!1;if(this.#e.nodeType===o.ELEMENT_NODE?l===this.#e?t=!0:t=this.#e.contains(l):t=!0,t)for(const s of c){const{leaves:n}=s.get("twig");if(this._matchLeaves(n,l)){const i=s.get("index");this.#l[i].add(l),this.#t[i].filtered||(this.#t[i].filtered=!0)}}l=m.nextNode()}}}else{let c=0;for(const{branch:f}of e){const r=f[f.length-1],{compound:d,nodes:m}=this._findNodes(r,a);m.size?this.#l[c]=m:this.#t[c].skip=!0,this.#t[c].filtered=!d,this.#t[c].find=D,c++}}return[this.#t,this.#l]}_sortNodes(a){const e=[...a];return e.length>1&&e.sort((c,f)=>{let r;return(0,x.isPreceding)(f,c)?r=1:r=-1,r}),e}_matchNodes(a){const[...e]=this.#t,c=e.length;let f=new Set;for(let r=0;r<c;r++){const{branch:d,filtered:m,find:l,skip:t}=e[r],s=d.length;if(!t&&s){const n=this.#l[r],b=s-1;if(b===0){const{leaves:[,...i]}=d[0];if((a===$||a===I)&&this.#e.nodeType===o.ELEMENT_NODE){for(const h of n)if((m||this._matchLeaves(i,h))&&h!==this.#e&&this.#e.contains(h)&&(f.add(h),a!==$))break}else if(i.length){for(const h of n)if((m||this._matchLeaves(i,h))&&(f.add(h),a!==$))break}else if(a===$){const h=[...f];f=new Set([...h,...n])}else{const[h]=[...n];f.add(h)}}else if(l===C){let{combo:i,leaves:[,...h]}=d[0];for(const u of n){const w=m||this._matchLeaves(h,u);let N;if(w){let E=new Set([u]);for(let A=1;A<s;A++){const{combo:p,leaves:g}=d[A],y=[];for(const _ of E){const v={combo:i,leaves:g},T=this._matchCombinator(v,_,{find:l});T.size&&y.push(...T)}if(y.length)if(A===b){if(a===I){const[_]=this._sortNodes(y);f.add(_)}else{const _=[...f];f=new Set([..._,...y])}N=!0;break}else N=!1,i=p,E=new Set(y);else{N=!1;break}}}else N=!1;if(N&&a!==$)break}}else{const{leaves:[,...i]}=d[b];for(const h of n){const u=m||this._matchLeaves(i,h);let w;if(u){let N=new Set([h]);for(let E=b-1;E>=0;E--){const A=d[E],p=[];for(const g of N){const y=this._matchCombinator(A,g,{find:l});y.size&&p.push(...y)}if(p.length)if(E===0){f.add(h),w=!0;break}else w=!1,N=new Set(p);else{w=!1;break}}}else w=!1;if(w&&a!==$)break}}}}return f}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(){if(this.#e.nodeType!==o.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let a;try{const e=this._find(P);e.size&&(a=e.has(this.#e))}catch(e){this._onError(e)}return!!a}closest(){if(this.#e.nodeType!==o.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let a;try{const e=this._find(O);let c=this.#e;for(;c;){if(e.has(c)){a=c;break}c=c.parentNode}}catch(e){this._onError(e)}return a??null}querySelector(){let a;try{const e=this._find(I);e.delete(this.#e),e.size&&([a]=this._sortNodes(e))}catch(e){this._onError(e)}return a??null}querySelectorAll(){let a;try{const e=this._find($);e.delete(this.#e),e.size&&(a=this._sortNodes(e))}catch(e){this._onError(e)}return a??[]}}0&&(module.exports={Matcher});
|
|
1
|
+
var B=Object.create;var M=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var W=(A,s)=>{for(var e in s)M(A,e,{get:s[e],enumerable:!0})},U=(A,s,e,o)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of F(s))!V.call(A,c)&&c!==e&&M(A,c,{get:()=>s[c],enumerable:!(o=z(s,c))||o.enumerable});return A};var H=(A,s,e)=>(e=A!=null?B(j(A)):{},U(s||!A||!A.__esModule?M(e,"default",{value:A,enumerable:!0}):e,A)),G=A=>U(M({},"__esModule",{value:!0}),A);var X={};W(X,{Matcher:()=>q});module.exports=G(X);var I=H(require("is-potential-custom-element-name"),1),S=require("./dom-util.js"),_=require("./parser.js"),l=require("./constant.js");const C="next",D="prev",T="all",L="first",O="lineal",P="self";class q{#i;#f;#o;#s;#e;#c;#t;#n;#l;#a;#r;constructor(s,e,o={}){const{warn:c}=o;this.#f=new Map([[l.SELECTOR_PSEUDO_ELEMENT,l.BIT_01],[l.SELECTOR_ID,l.BIT_02],[l.SELECTOR_CLASS,l.BIT_04],[l.SELECTOR_TYPE,l.BIT_08],[l.SELECTOR_ATTR,l.BIT_16],[l.SELECTOR_PSEUDO_CLASS,l.BIT_32]]),this.#o=new WeakMap,[this.#i,this.#c]=this._prepare(s),this.#e=e,[this.#s,this.#t,this.#a]=this._setup(e),this.#n=(0,S.isInShadowTree)(e),this.#r=!!c}_onError(s){if(s instanceof DOMException&&s.name===l.NOT_SUPPORTED_ERR)this.#r&&console.warn(s.message);else throw s}_setup(s){let e,o;switch(s.nodeType){case l.DOCUMENT_NODE:{e=s,o=s;break}case l.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,o=s;break}case l.ELEMENT_NODE:{if(s.ownerDocument.contains(s))e=s.ownerDocument,o=s.ownerDocument;else{let h=s;for(;h&&h.parentNode;)h=h.parentNode;e=h.ownerDocument,o=h}break}default:throw new TypeError(`Unexpected node ${s.nodeName}`)}const c=l.SHOW_DOCUMENT|l.SHOW_DOCUMENT_FRAGMENT|l.SHOW_ELEMENT,r=e.createTreeWalker(o,c);return[e,o,r]}_sortLeaves(s){const e=[...s];return e.length>1&&e.sort((o,c)=>{const{type:r}=o,{type:h}=c,d=this.#f.get(r),f=this.#f.get(h);let t;return d===f?t=0:d>f?t=1:t=-1,t}),e}_prepare(s){const e=(0,_.parseSelector)(s),o=(0,_.walkAST)(e),c=[],r=[];let h=0;for(const[...d]of o){const f=[];let t=d.shift();if(t&&t.type!==l.COMBINATOR){const i=new Set;for(;t;){if(t.type===l.COMBINATOR){const[n]=d;if(n.type===l.COMBINATOR){const a=`Invalid combinator ${t.name}${n.name}`;throw new DOMException(a,l.SYNTAX_ERR)}f.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(d.length)t=d.shift();else{f.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}c.push({branch:f,filtered:!1,find:null,skip:!1}),r[h]=new Set,h++}return[c,r]}_traverse(s={},e=this.#a){let o,c=e.currentNode;if(s.nodeType===l.ELEMENT_NODE&&c===s)o=c;else{if(c!==e.root)for(;c&&!(c===e.root||s.nodeType===l.ELEMENT_NODE&&c===s);)c=e.parentNode();if(s.nodeType===l.ELEMENT_NODE)for(;c;){if(c===s){o=c;break}c=e.nextNode()}else o=c}return o??null}_collectNthChild(s,e){const{a:o,b:c,reverse:r,selector:h}=s,{parentNode:d}=e,f=new Set;let t;if(h&&(this.#o.has(h)?t=this.#o.get(h):(t=(0,_.walkAST)(h),this.#o.set(h,t))),d){const i=[].slice.call(d.childNodes).filter(a=>a.nodeType===l.ELEMENT_NODE),n=i.length;if(n){const a=new Set;if(t)for(const u of i){let b;for(const p of t)if(b=this._matchLeaves(p,u),!b)break;b&&a.add(u)}if(r&&i.reverse(),o===0){if(c>0&&c<=n){if(a.size){for(const u of i)if(a.has(u)){f.add(u);break}}else if(!h){const u=i[c-1];f.add(u)}}}else{let u=c-1;if(o>0)for(;u<0;)u+=o;if(u>=0&&u<n){let b=o>0?0:c-1;for(let p=0;p<n&&u>=0&&u<n;p++){const N=i[p];a.size?a.has(N)&&(b===u&&(f.add(N),u+=o),o>0?b++:b--):p===u&&(h||f.add(N),u+=o)}}}}}else if(e===this.#t&&this.#t.nodeType===l.ELEMENT_NODE&&o+c===1)if(t){let i;for(const n of t)if(i=this._matchLeaves(n,e),i)break;i&&f.add(e)}else f.add(e);return f}_collectNthOfType(s,e){const{a:o,b:c,reverse:r}=s,{localName:h,parentNode:d,prefix:f}=e,t=new Set;if(d){const i=[].slice.call(d.childNodes).filter(a=>a.nodeType===l.ELEMENT_NODE),n=i.length;if(n)if(r&&i.reverse(),o===0){if(c>0&&c<=n){let a=0;for(const u of i){const{localName:b,prefix:p}=u;if(b===h&&p===f){if(a===c-1){t.add(u);break}a++}}}}else{let a=c-1;if(o>0)for(;a<0;)a+=o;if(a>=0&&a<n){let u=o>0?0:c-1;for(const b of i){const{localName:p,prefix:N}=b;if(p===h&&N===f){if(u===a&&(t.add(b),a+=o),a<0||a>=n)break;o>0?u++:u--}}}}}else e===this.#t&&this.#t.nodeType===l.ELEMENT_NODE&&o+c===1&&t.add(e);return t}_matchAnPlusB(s,e,o){const{nth:{a:c,b:r,name:h},selector:d}=s,f=(0,_.unescapeSelector)(h),t=new Map;f?(f==="even"?(t.set("a",2),t.set("b",0)):f==="odd"&&(t.set("a",2),t.set("b",1)),o.indexOf("last")>-1&&t.set("reverse",!0)):(typeof c=="string"&&/-?\d+/.test(c)?t.set("a",c*1):t.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?t.set("b",r*1):t.set("b",0),o.indexOf("last")>-1&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(o)){d&&t.set("selector",d);const n=Object.fromEntries(t),a=this._collectNthChild(n,e);a.size&&(i=a)}else if(/^nth-(?:last-)?of-type$/.test(o)){const n=Object.fromEntries(t),a=this._collectNthOfType(n,e);a.size&&(i=a)}}return i}_matchPseudoElementSelector(s,e={}){const{forgive:o}=e;switch(s){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#r)throw new DOMException(`Unsupported pseudo-element ::${s}`,l.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#r)throw new DOMException(`Unsupported pseudo-element ::${s}()`,l.NOT_SUPPORTED_ERR);break}default:if(s.startsWith("-webkit-")){if(this.#r)throw new DOMException(`Unsupported pseudo-element ::${s}`,l.NOT_SUPPORTED_ERR)}else if(!o)throw new DOMException(`Unknown pseudo-element ::${s}`,l.SYNTAX_ERR)}}_matchDirectionPseudoClass(s,e){const o=(0,_.unescapeSelector)(s.name),c=(0,S.getDirectionality)(e);let r;return o===c&&(r=e),r??null}_matchLanguagePseudoClass(s,e){const o=(0,_.unescapeSelector)(s.name);let c;if(o==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(c=e);else{let r=e.parentNode;for(;r&&r.nodeType===l.ELEMENT_NODE;){if(r.hasAttribute("lang")){r.getAttribute("lang")&&(c=e);break}r=r.parentNode}}else if(o){const r=`(?:-${l.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${l.ALPHA_NUM}${r}$`,"i").test(o)){let d;if(o.indexOf("-")>-1){const[f,t,...i]=o.split("-");let n;f==="*"?n=`${l.ALPHA_NUM}${r}`:n=`${f}${r}`;const a=`-${t}${r}`,u=i.length;let b="";if(u)for(let p=0;p<u;p++)b+=`-${i[p]}${r}`;d=new RegExp(`^${n}${a}${b}$`,"i")}else d=new RegExp(`^${o}${r}$`,"i");if(e.hasAttribute("lang"))d.test(e.getAttribute("lang"))&&(c=e);else{let f=e.parentNode;for(;f&&f.nodeType===l.ELEMENT_NODE;){if(f.hasAttribute("lang")){const t=f.getAttribute("lang");d.test(t)&&(c=e);break}f=f.parentNode}}}}return c??null}_matchHasPseudoFunc(s,e){let o;if(Array.isArray(s)&&s.length){const[c]=s,{type:r}=c;let h;r===l.COMBINATOR?h=s.shift():h={name:" ",type:l.COMBINATOR};const d=[];for(;s.length;){const[i]=s,{type:n}=i;if(n===l.COMBINATOR)break;d.push(s.shift())}const f={combo:h,leaves:d},t=this._matchCombinator(f,e,{find:C});if(t.size)if(s.length){for(const i of t)if(o=this._matchHasPseudoFunc(Object.assign([],s),i),o)break}else o=!0}return!!o}_matchLogicalPseudoFunc(s,e){const{astName:o="",branches:c=[],selector:r="",twigBranches:h=[]}=s;let d;if(o==="has")if(r.includes(":has("))d=null;else{const f=c.length;let t;for(let i=0;i<f;i++){const n=c[i];if(t=this._matchHasPseudoFunc(Object.assign([],n),e),t)break}t&&(d=e)}else{const f=/^(?:is|where)$/.test(o),t=h.length;let i;for(let n=0;n<t;n++){const a=h[n],u=a.length-1,{leaves:b}=a[u];if(i=this._matchLeaves(b,e,{forgive:f}),i&&u>0){let p=new Set([e]);for(let N=u-1;N>=0;N--){const g=a[N],m=[];for(const w of p){const k=this._matchCombinator(g,w,{forgive:f,find:D});k.size&&m.push(...k)}if(m.length)if(N===0){i=!0;break}else p=new Set(m);else{i=!1;break}}}if(i)break}o==="not"?i||(d=e):i&&(d=e)}return d??null}_matchPseudoClassSelector(s,e,o={}){const{children:c}=s,{localName:r,parentNode:h}=e,{forgive:d}=o,f=(0,_.unescapeSelector)(s.name);let t=new Set;if(l.REG_LOGICAL_PSEUDO.test(f)){let i;if(this.#o.has(s))i=this.#o.get(s);else{const a=(0,_.walkAST)(s),u=[],b=[];for(const[...p]of a){for(const w of p){const k=(0,_.generateCSS)(w);u.push(k)}const N=[],g=new Set;let m=p.shift();for(;m;)if(m.type===l.COMBINATOR?(N.push({combo:m,leaves:[...g]}),g.clear()):m&&g.add(m),p.length)m=p.shift();else{N.push({combo:null,leaves:[...g]}),g.clear();break}b.push(N)}i={astName:f,branches:a,twigBranches:b,selector:u.join(",")},this.#o.set(s,i)}const n=this._matchLogicalPseudoFunc(i,e);n&&t.add(n)}else if(Array.isArray(c)){const[i]=c;if(/^nth-(?:last-)?(?:child|of-type)$/.test(f)){const n=this._matchAnPlusB(i,e,f);n.size&&(t=n)}else if(f==="dir"){const n=this._matchDirectionPseudoClass(i,e);n&&t.add(n)}else if(f==="lang"){const n=this._matchLanguagePseudoClass(i,e);n&&t.add(n)}else switch(f){case"current":case"nth-col":case"nth-last-col":{if(this.#r)throw new DOMException(`Unsupported pseudo-class :${f}()`,l.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;default:if(!d)throw new DOMException(`Unknown pseudo-class :${f}()`,l.SYNTAX_ERR)}}else{const i=/^a(?:rea)?$/,n=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,a=/^(?:(?:inpu|selec)t|button|form|textarea)$/,u=/^d(?:etails|ialog)$/,b=/^(?:checkbox|radio)$/,p=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,g=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(f){case"any-link":case"link":{i.test(r)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(i.test(r)&&e.hasAttribute("href")){const{href:m,origin:w,pathname:k}=new URL(this.#s.URL),y=new URL(e.getAttribute("href"),m);y.origin===w&&y.pathname===k&&t.add(e)}break}case"visited":break;case"target":{const{hash:m}=new URL(this.#s.URL);e.id&&m===`#${e.id}`&&this.#s.contains(e)&&t.add(e);break}case"target-within":{const{hash:m}=new URL(this.#s.URL);if(m){const w=m.replace(/^#/,"");let k=this.#s.getElementById(w);for(;k;){if(k===e){t.add(e);break}k=k.parentNode}}break}case"scope":{this.#e.nodeType===l.ELEMENT_NODE?e===this.#e&&t.add(e):e===this.#s.documentElement&&t.add(e);break}case"focus":{e===this.#s.activeElement&&t.add(e);break}case"focus-within":{let m=this.#s.activeElement;for(;m;){if(m===e){t.add(e);break}m=m.parentNode}break}case"open":{u.test(r)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{u.test(r)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(n.test(r)||(0,I.default)(r))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let m=h;for(;m&&m.localName!=="fieldset";)m=m.parentNode;m&&h.localName!=="legend"&&m.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(n.test(r)||(0,I.default)(r))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(r){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||p.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,S.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||p.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,S.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let m;r==="textarea"?m=e:r==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(m=e):m=e),m&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&r==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))||e.selected&&r==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&r==="input"&&e.type==="checkbox"||r==="progress"&&!e.hasAttribute("value"))t.add(e);else if(r==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const m=e.name;let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;w||(w=this.#s.documentElement);const k=[].slice.call(w.getElementsByTagName("input"));let y;for(const v of k)if(v.getAttribute("type")==="radio"&&(m?v.getAttribute("name")===m&&(y=!!v.checked):v.hasAttribute("name")||(y=!!v.checked),y))break;y||t.add(e)}break}case"default":{const m=/^(?:button|reset)$/,w=/^(?:image|submit)$/;if(r==="button"&&!(e.hasAttribute("type")&&m.test(e.getAttribute("type")))||r==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))){let k=e.parentNode;for(;k&&k.localName!=="form";)k=k.parentNode;if(k){const y=this.#s.createNodeIterator(k,l.SHOW_ELEMENT);let v=y.nextNode();for(;v;){const E=v.localName;let x;if(E==="button"?x=!(v.hasAttribute("type")&&m.test(v.getAttribute("type"))):E==="input"&&(x=v.hasAttribute("type")&&w.test(v.getAttribute("type"))),x){v===e&&t.add(e);break}v=y.nextNode()}}}else if(r==="input"&&e.hasAttribute("type")&&b.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(r==="option"){let k=!1,y=h;for(;y&&y.localName!=="datalist";){if(y.localName==="select"){(y.multiple||y.hasAttribute("multiple"))&&(k=!0);break}y=y.parentNode}if(k)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=h.firstElementChild,E=new Set;let x=v;for(;x;){if(x.selected||x.hasAttribute("selected")){E.add(x);break}x=x.nextElementSibling}E.size||E.add(v),E.has(e)&&t.add(e)}}break}case"valid":{if(a.test(r))e.checkValidity()&&t.add(e);else if(r==="fieldset"){let m=this._traverse(e);m===e&&(m=this.#a.nextNode());let w;for(;m&&!(a.test(m.localName)&&(w=m.checkValidity(),!w));)m=this.#a.nextNode();w&&t.add(e)}break}case"invalid":{if(a.test(r))e.checkValidity()||t.add(e);else if(r==="fieldset"){let m=this._traverse(e);m===e&&(m=this.#a.nextNode());let w;for(;m&&!(a.test(m.localName)&&(w=m.checkValidity(),!w));)m=this.#a.nextNode();w||t.add(e)}break}case"in-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.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":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&N.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let m;if(/^(?:select|textarea)$/.test(r))m=e;else if(r==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||p.test(w)||g.test(w))&&(m=e)}else m=e;m&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let m;if(/^(?:select|textarea)$/.test(r))m=e;else if(r==="input")if(e.hasAttribute("type")){const w=e.getAttribute("type");(w==="file"||b.test(w)||p.test(w)||g.test(w))&&(m=e)}else m=e;m&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#s.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const m=e.childNodes.values();let w;for(const k of m)if(w=k.nodeType!==l.ELEMENT_NODE&&k.nodeType!==l.TEXT_NODE,!w)break;w&&t.add(e)}else t.add(e);break}case"first-child":{(h&&e===h.firstElementChild||e===this.#t&&this.#t.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(h&&e===h.lastElementChild||e===this.#t&&this.#t.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(h&&e===h.firstElementChild&&e===h.lastElementChild||e===this.#t&&this.#t.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(h){const[m]=this._collectNthOfType({a:0,b:1},e);m&&t.add(m)}else e===this.#t&&this.#t.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(h){const[m]=this._collectNthOfType({a:0,b:1,reverse:!0},e);m&&t.add(m)}else e===this.#t&&this.#t.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(h){const[m]=this._collectNthOfType({a:0,b:1},e);if(m===e){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w===e&&t.add(e)}}else e===this.#t&&this.#t.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#r)throw new DOMException(`Unsupported pseudo-element ::${f}`,l.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(this.#r)throw new DOMException(`Unsupported pseudo-class :${f}`,l.NOT_SUPPORTED_ERR);break}default:if(f.startsWith("-webkit-")){if(this.#r)throw new DOMException(`Unsupported pseudo-class :${f}`,l.NOT_SUPPORTED_ERR)}else if(!d)throw new DOMException(`Unknown pseudo-class :${f}`,l.SYNTAX_ERR)}}return t}_matchAttributeSelector(s,e){const{flags:o,matcher:c,name:r,value:h}=s;if(typeof o=="string"&&!/^[is]$/i.test(o)){const t=(0,_.generateCSS)(s);throw new DOMException(`Invalid selector ${t}`,l.SYNTAX_ERR)}const{attributes:d}=e;let f;if(d&&d.length){let t;this.#s.contentType==="text/html"?typeof o=="string"&&/^s$/i.test(o)?t=!1:t=!0:typeof o=="string"&&/^i$/i.test(o)?t=!0:t=!1;let i=(0,_.unescapeSelector)(r.name);t&&(i=i.toLowerCase());const n=new Set;if(i.indexOf("|")>-1){const{prefix:a,tagName:u}=(0,S.selectorToNodeProps)(i);for(let{name:b,value:p}of d)switch(t&&(b=b.toLowerCase(),p=p.toLowerCase()),a){case"":{u===b&&n.add(p);break}case"*":{b.indexOf(":")>-1?b.endsWith(`:${u}`)&&n.add(p):u===b&&n.add(p);break}default:if(b.indexOf(":")>-1){const[N,g]=b.split(":");a===N&&u===g&&(0,S.isNamespaceDeclared)(a,e)&&n.add(p)}}}else for(let{name:a,value:u}of d)if(t&&(a=a.toLowerCase(),u=u.toLowerCase()),a.indexOf(":")>-1){const[b,p]=a.split(":");if(b==="xml"&&p==="lang")continue;i===p&&n.add(u)}else i===a&&n.add(u);if(n.size){const{name:a,value:u}=h||{};let b;switch(a?t?b=a.toLowerCase():b=a:u?t?b=u.toLowerCase():b=u:u===""&&(b=u),c){case"=":{typeof b=="string"&&n.has(b)&&(f=e);break}case"~=":{if(b&&typeof b=="string"){for(const p of n)if(new Set(p.split(/\s+/)).has(b)){f=e;break}}break}case"|=":{if(b&&typeof b=="string"){let p;for(const N of n)if(N===b||N.startsWith(`${b}-`)){p=N;break}p&&(f=e)}break}case"^=":{if(b&&typeof b=="string"){let p;for(const N of n)if(N.startsWith(`${b}`)){p=N;break}p&&(f=e)}break}case"$=":{if(b&&typeof b=="string"){let p;for(const N of n)if(N.endsWith(`${b}`)){p=N;break}p&&(f=e)}break}case"*=":{if(b&&typeof b=="string"){let p;for(const N of n)if(N.includes(`${b}`)){p=N;break}p&&(f=e)}break}case null:default:f=e}}}return f??null}_matchClassSelector(s,e){const o=(0,_.unescapeSelector)(s.name);let c;return e.classList.contains(o)&&(c=e),c??null}_matchIDSelector(s,e){const o=(0,_.unescapeSelector)(s.name),{id:c}=e;let r;return o===c&&(r=e),r??null}_matchTypeSelector(s,e,o={}){const c=(0,_.unescapeSelector)(s.name),{localName:r,prefix:h}=e,{forgive:d}=o;let{prefix:f,tagName:t}=(0,S.selectorToNodeProps)(c,e);this.#s.contentType==="text/html"&&(f=f.toLowerCase(),t=t.toLowerCase());let i,n;r.indexOf(":")>-1?[i,n]=r.split(":"):(i=h||"",n=r);let a;if(f===""&&i==="")e.namespaceURI===null&&(t==="*"||t===n)&&(a=e);else if(f==="*")(t==="*"||t===n)&&(a=e);else if(f===i){if((0,S.isNamespaceDeclared)(f,e))(t==="*"||t===n)&&(a=e);else if(!d)throw new DOMException(`Undeclared namespace ${f}`,l.SYNTAX_ERR)}else if(f&&!d&&!(0,S.isNamespaceDeclared)(f,e))throw new DOMException(`Undeclared namespace ${f}`,l.SYNTAX_ERR);return a??null}_matchShadowHostPseudoClass(s,e){const{children:o}=s,c=(0,_.unescapeSelector)(s.name);let r;if(Array.isArray(o)){const[h]=(0,_.walkAST)(o[0]),[...d]=h,{host:f}=e;if(c==="host"){let t;for(const i of d){const{type:n}=i;if(n===l.COMBINATOR){const a=(0,_.generateCSS)(s);throw new DOMException(`Invalid selector ${a}`,l.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}t&&(r=e)}else if(c==="host-context"){let t=f,i;for(;t;){for(const n of d){const{type:a}=n;if(a===l.COMBINATOR){const u=(0,_.generateCSS)(s);throw new DOMException(`Invalid selector ${u}`,l.SYNTAX_ERR)}if(i=this._matchSelector(n,t).has(t),!i)break}if(i)break;t=t.parentNode}i&&(r=e)}}else if(c==="host")r=e;else throw new DOMException(`Invalid selector :${c}`,l.SYNTAX_ERR);return r??null}_matchSelector(s,e,o){const{type:c}=s,r=(0,_.unescapeSelector)(s.name);let h=new Set;if(e.nodeType===l.ELEMENT_NODE)switch(c){case l.SELECTOR_ATTR:{const d=this._matchAttributeSelector(s,e);d&&h.add(d);break}case l.SELECTOR_CLASS:{const d=this._matchClassSelector(s,e);d&&h.add(d);break}case l.SELECTOR_ID:{const d=this._matchIDSelector(s,e);d&&h.add(d);break}case l.SELECTOR_PSEUDO_CLASS:{const d=this._matchPseudoClassSelector(s,e,o);d.size&&(h=d);break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(r,o);break}case l.SELECTOR_TYPE:default:{const d=this._matchTypeSelector(s,e,o);d&&h.add(d)}}else if(this.#n&&c===l.SELECTOR_PSEUDO_CLASS&&e.nodeType===l.DOCUMENT_FRAGMENT_NODE){if(r!=="has"&&l.REG_LOGICAL_PSEUDO.test(r)){const d=this._matchPseudoClassSelector(s,e,o);d.size&&(h=d)}else if(l.REG_SHADOW_HOST.test(r)){const d=this._matchShadowHostPseudoClass(s,e);d&&h.add(d)}}return h}_matchLeaves(s,e,o){let c;for(const r of s)if(c=this._matchSelector(r,e,o).has(e),!c)break;return!!c}_findDescendantNodes(s,e){const[o,...c]=s,{type:r}=o,h=(0,_.unescapeSelector)(o.name),d=c.length>0;let f=new Set,t=!1;if(this.#n)t=!0;else switch(r){case l.SELECTOR_ID:{if(this.#t.nodeType===l.ELEMENT_NODE)t=!0;else{const i=this.#t.getElementById(h);i&&i!==e&&e.contains(i)&&(d?this._matchLeaves(c,i)&&f.add(i):f.add(i))}break}case l.SELECTOR_CLASS:{const i=[].slice.call(e.getElementsByClassName(h));if(i.length)if(d)for(const n of i)this._matchLeaves(c,n)&&f.add(n);else f=new Set(i);break}case l.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(h)){const i=[].slice.call(e.getElementsByTagName(h));if(i.length)if(d)for(const n of i)this._matchLeaves(c,n)&&f.add(n);else f=new Set(i)}else t=!0;break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(h);break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(s,e,o={}){const{combo:c,leaves:r}=s,{name:h}=c,{find:d,forgive:f}=o;let t=new Set;if(d===C)switch(h){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(r,i,{forgive:f})&&t.add(i),i=i.nextElementSibling;break}case">":{const i=e.childNodes.values();for(const n of i)n.nodeType===l.ELEMENT_NODE&&this._matchLeaves(r,n,{forgive:f})&&t.add(n);break}case" ":default:{const{nodes:i,pending:n}=this._findDescendantNodes(r,e);if(i.size)t=i;else if(n){let a=this._traverse(e);for(a===e&&(a=this.#a.nextNode());a;)this._matchLeaves(r,a,{forgive:f})&&t.add(a),a=this.#a.nextNode()}}}else switch(h){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case"~":{const i=[];let n=e.previousElementSibling;for(;n;)this._matchLeaves(r,n,{forgive:f})&&i.push(n),n=n.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case" ":default:{const i=[];let n=e.parentNode;for(;n;)this._matchLeaves(r,n,{forgive:f})&&i.push(n),n=n.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNode(s,e={}){let{node:o,targetType:c,tree:r}=e;r||(r=this.#a);let h=this._traverse(o);(h.nodeType!==l.ELEMENT_NODE||h===o)&&(h=r.nextNode());let d;for(;h;){let f;if(this.#e.nodeType===l.ELEMENT_NODE?h===this.#e?f=!0:f=this.#e.contains(h):f=!0,f&&this._matchLeaves(s,h)){d=h;break}c===O?h=r.parentNode():h=r.nextNode()}return d??null}_findEntryNodes(s,e){const{leaves:o}=s,[c,...r]=o,{type:h}=c,d=(0,_.unescapeSelector)(c.name),f=r.length>0;let t=new Set,i=!1,n=!1;switch(h){case l.SELECTOR_ID:{if(e===P)this._matchLeaves(o,this.#e)&&(t.add(this.#e),i=!0);else if(e===O){let a=this.#e;for(;a;)this._matchLeaves(o,a)&&(t.add(a),i=!0),a=a.parentNode}else if(e===T||this.#t.nodeType===l.ELEMENT_NODE)n=!0;else{const a=this.#t.getElementById(d);a&&(t.add(a),i=!0)}break}case l.SELECTOR_CLASS:{if(e===P)this.#e.nodeType===l.ELEMENT_NODE&&this.#e.classList.contains(d)&&t.add(this.#e);else if(e===O){let a=this.#e;for(;a&&a.nodeType===l.ELEMENT_NODE;)a.classList.contains(d)&&t.add(a),a=a.parentNode}else if(e===L){const a=this._findNode(o,{node:this.#e,targetType:e,tree:this.#l});if(a){t.add(a),i=!0;break}}else if(this.#t.nodeType===l.DOCUMENT_FRAGMENT_NODE){const a=this.#t.childNodes.values(),u=[];for(const b of a)if(b.nodeType===l.ELEMENT_NODE){b.classList.contains(d)&&u.push(b);const p=[].slice.call(b.getElementsByClassName(d));u.push(...p)}u.length&&(t=new Set(u))}else{const a=[].slice.call(this.#t.getElementsByClassName(d));if(this.#e.nodeType===l.ELEMENT_NODE)for(const u of a)(u===this.#e||(0,S.isInclusive)(u,this.#e))&&t.add(u);else a.length&&(t=new Set(a))}break}case l.SELECTOR_TYPE:{if(e===P)this.#e.nodeType===l.ELEMENT_NODE&&this._matchLeaves(o,this.#e)&&(t.add(this.#e),i=!0);else if(e===O){let a=this.#e;for(;a&&a.nodeType===l.ELEMENT_NODE;)this._matchLeaves(o,a)&&(t.add(a),i=!0),a=a.parentNode}else if(e===L){const a=this._findNode(o,{node:this.#e,targetType:e,tree:this.#l});if(a){t.add(a),i=!0;break}}else if(this.#s.contentType!=="text/html"||/[*|]/.test(d))n=!0;else if(this.#t.nodeType===l.DOCUMENT_FRAGMENT_NODE){const a=d.toLowerCase(),u=this.#t.childNodes.values(),b=[];for(const p of u)if(p.nodeType===l.ELEMENT_NODE){p.localName===a&&b.push(p);const N=[].slice.call(p.getElementsByTagName(d));b.push(...N)}b.length&&(t=new Set(b))}else{const a=[].slice.call(this.#t.getElementsByTagName(d));if(this.#e.nodeType===l.ELEMENT_NODE)for(const u of a)(u===this.#e||(0,S.isInclusive)(u,this.#e))&&t.add(u);else a.length&&(t=new Set(a))}break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(d);break}default:if(e!==O&&l.REG_SHADOW_HOST.test(d)){if(this.#n&&this.#e.nodeType===l.DOCUMENT_FRAGMENT_NODE){const a=this._matchShadowHostPseudoClass(c,this.#e);a&&t.add(a)}}else if(e===P)this._matchLeaves(o,this.#e)&&(t.add(this.#e),i=!0);else if(e===O){let a=this.#e;for(;a;)this._matchLeaves(o,a)&&(t.add(a),i=!0),a=a.parentNode}else if(e===L){const a=this._findNode(o,{node:this.#e,targetType:e,tree:this.#l});if(a){t.add(a),i=!0;break}}else n=!0}if(!t.size&&!n&&f){const a=r[r.length-1],{type:u}=a;if(u===l.SELECTOR_PSEUDO_CLASS){let b;this.#t.nodeType===l.ELEMENT_NODE?b=this.#t:b=this.#t.firstElementChild,this._matchPseudoClassSelector(a,b)}}return{compound:f,filtered:i,nodes:t,pending:n}}_getEntryTwig(s,e){const o=s.length,c=o>1,r=s[0];let h,d;if(c){const{leaves:[{type:f}]}=r,t=s[o-1],{leaves:[{type:i}]}=t;if(i===l.SELECTOR_PSEUDO_ELEMENT||i===l.SELECTOR_ID)h=D,d=t;else if(f===l.SELECTOR_PSEUDO_ELEMENT||f===l.SELECTOR_ID)h=C,d=r;else{let n;for(const{combo:a,leaves:[u]}of s){const{type:b}=u,p=(0,_.unescapeSelector)(u.name);if(b===l.SELECTOR_PSEUDO_CLASS&&p==="dir"){n=!1;break}if(a){const{name:N}=a;(e===T||/^[+~]$/.test(N))&&(n=!0)}}n?(h=C,d=r):(h=D,d=t)}}else h=D,d=r;return{complex:c,find:h,twig:d}}_collectNodes(s){const e=this.#i.values();if(s===T||s===L){s===L&&(this.#e.nodeType===l.ELEMENT_NODE?this.#l=this.#s.createTreeWalker(this.#e,l.SHOW_ELEMENT):this.#l=this.#a);const o=new Set;let c=0;for(const{branch:r}of e){const{find:h,twig:d}=this._getEntryTwig(r,s),{compound:f,filtered:t,nodes:i,pending:n}=this._findEntryNodes(d,s);i.size?this.#c[c]=i:n?o.add(new Map([["index",c],["twig",d]])):this.#i[c].skip=!0,this.#i[c].filtered=t||!f,this.#i[c].find=h,c++}if(o.size){let r=this._traverse();for(;r;){let h=!1;if(this.#e.nodeType===l.ELEMENT_NODE?r===this.#e?h=!0:h=this.#e.contains(r):h=!0,h)for(const d of o){const{leaves:f}=d.get("twig");if(this._matchLeaves(f,r)){const i=d.get("index");this.#c[i].add(r),this.#i[i].filtered=!0}}r=this.#a.nextNode()}}}else{let o=0;for(const{branch:c}of e){const r=c[c.length-1],{compound:h,filtered:d,nodes:f}=this._findEntryNodes(r,s);f.size?this.#c[o]=f:this.#i[o].skip=!0,this.#i[o].filtered=d||!h,this.#i[o].find=D,o++}}return[this.#i,this.#c]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((o,c)=>{let r;return(0,S.isPreceding)(c,o)?r=1:r=-1,r}),e}_matchNodes(s){const[...e]=this.#i,o=e.length;let c=new Set;for(let r=0;r<o;r++){const{branch:h,filtered:d,find:f,skip:t}=e[r],i=h.length;if(!t&&i){const n=this.#c[r],a=i-1;if(a===0){const{leaves:[,...u]}=h[0];if((s===T||s===L)&&this.#e.nodeType===l.ELEMENT_NODE){for(const b of n)if((d||this._matchLeaves(u,b))&&b!==this.#e&&this.#e.contains(b)&&(c.add(b),s!==T))break}else if(u.length){for(const b of n)if((d||this._matchLeaves(u,b))&&(c.add(b),s!==T))break}else if(s===T){const b=[...c];c=new Set([...b,...n])}else{const[b]=[...n];c.add(b)}}else if(f===C){let{combo:u,leaves:b}=h[0];const[,...p]=b;let N;for(const g of n){if(d||this._matchLeaves(p,g)){let w=new Set([g]);for(let k=1;k<i;k++){const{combo:y,leaves:v}=h[k],E=[];for(const x of w){const R={combo:u,leaves:v},$=this._matchCombinator(R,x,{find:f});$.size&&E.push(...$)}if(E.length)if(k===a){if(s===L){const[x]=this._sortNodes(E);c.add(x)}else{const x=[...c];c=new Set([...x,...E])}N=!0;break}else N=!1,u=y,w=new Set(E);else{N=!1;break}}}else N=!1;if(N&&s!==T)break}if(!N&&s===L){const[g]=[...n];let m=this._findNode(b,{targetType:s,node:g,tree:this.#l});for(;m;){let w=new Set([m]);for(let k=1;k<i;k++){const{combo:y,leaves:v}=h[k],E=[];for(const x of w){const R={combo:u,leaves:v},$=this._matchCombinator(R,x,{find:f});$.size&&E.push(...$)}if(E.length)if(k===a){const[x]=this._sortNodes(E);c.add(x),N=!0;break}else N=!1,u=y,w=new Set(E);else{N=!1;break}}if(N)break;m=this._findNode(b,{targetType:s,node:m,tree:this.#l}),w=new Set([m])}}}else{const{leaves:u}=h[a],[,...b]=u;let p;for(const N of n){if(d||this._matchLeaves(b,N)){let m=new Set([N]);for(let w=a-1;w>=0;w--){const k=h[w],y=[];for(const v of m){const E=this._matchCombinator(k,v,{find:f});E.size&&y.push(...E)}if(y.length)if(w===0){c.add(N),p=!0;break}else p=!1,m=new Set(y);else{p=!1;break}}}if(p&&s!==T)break}if(!p&&s===L){const[N]=[...n];let g=this._findNode(u,{targetType:s,node:N,tree:this.#l});for(;g;){let m=new Set([g]);for(let w=a-1;w>=0;w--){const k=h[w],y=[];for(const v of m){const E=this._matchCombinator(k,v,{find:f});E.size&&y.push(...E)}if(y.length)if(w===0){c.add(g),p=!0;break}else p=!1,m=new Set(y);else{p=!1;break}}if(p)break;g=this._findNode(u,{targetType:s,node:g,tree:this.#l}),m=new Set([g])}}}}}return c}_find(s){return this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==l.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{const e=this._find(P);e.size&&(s=e.has(this.#e))}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==l.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{const e=this._find(O);let o=this.#e;for(;o;){if(e.has(o)){s=o;break}o=o.parentNode}}catch(e){this._onError(e)}return s??null}querySelector(){let s;try{const e=this._find(L);e.delete(this.#e),e.size&&([s]=this._sortNodes(e))}catch(e){this._onError(e)}return s??null}querySelectorAll(){let s;try{const e=this._find(T);e.delete(this.#e),e.size&&(s=this._sortNodes(e))}catch(e){this._onError(e)}return s??[]}}0&&(module.exports={Matcher});
|
|
2
2
|
//# sourceMappingURL=matcher.js.map
|