@asamuzakjp/dom-selector 2.0.2 → 2.0.3-a.2
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/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/js/constant.js +1 -1
- package/dist/cjs/js/constant.js.map +3 -3
- package/dist/cjs/js/dom-util.js +1 -1
- package/dist/cjs/js/dom-util.js.map +3 -3
- package/dist/cjs/js/finder.js +2 -0
- package/dist/cjs/js/finder.js.map +7 -0
- package/dist/cjs/js/matcher.js +1 -1
- package/dist/cjs/js/matcher.js.map +3 -3
- package/dist/cjs/js/parser.js +2 -2
- package/dist/cjs/js/parser.js.map +3 -3
- package/package.json +4 -3
- package/src/index.js +67 -9
- package/src/js/constant.js +1 -1
- package/src/js/dom-util.js +71 -21
- package/src/js/finder.js +2722 -0
- package/src/js/matcher.js +343 -2972
- package/src/js/parser.js +65 -4
- package/types/index.d.ts +3 -0
- package/types/js/constant.d.ts +1 -1
- package/types/js/dom-util.d.ts +2 -1
- package/types/js/finder.d.ts +30 -0
- package/types/js/matcher.d.ts +11 -61
- package/types/js/parser.d.ts +2 -0
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var h=(n,t)=>{for(var l in t)s(n,l,{get:t[l],enumerable:!0})},u=(n,t,l,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of a(t))!f.call(n,e)&&e!==l&&s(n,e,{get:()=>t[e],enumerable:!(o=i(t,e))||o.enumerable});return n};var w=n=>u(s({},"__esModule",{value:!0}),n);var q={};h(q,{Finder:()=>c.Finder,closest:()=>m,finder:()=>r,matches:()=>y,querySelector:()=>p,querySelectorAll:()=>x});module.exports=w(q);var c=require("./js/finder.js");/*!
|
|
2
2
|
* DOM Selector - A CSS selector engine.
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @copyright asamuzaK (Kazz)
|
|
5
5
|
* @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}
|
|
6
|
-
*/const
|
|
6
|
+
*/let r=new c.Finder;const y=(n,t,l)=>{let o;try{r||(r=new c.Finder),o=r.matches(t,n,l)}catch(e){throw e instanceof Error&&(r=null),e}return o},m=(n,t,l)=>{let o;try{r||(r=new c.Finder),o=r.closest(t,n,l)}catch(e){throw e instanceof globalThis[e.name]&&(r=null),e}return o},p=(n,t,l)=>{let o;try{r||(r=new c.Finder),o=r.querySelector(t,n,l)}catch(e){throw e instanceof globalThis[e.name]&&(r=null),e}return o},x=(n,t,l)=>{let o;try{r||(r=new c.Finder),o=r.querySelectorAll(t,n,l)}catch(e){throw e instanceof globalThis[e.name]&&(r=null),e}return o};0&&(module.exports={Finder,closest,finder,matches,querySelector,querySelectorAll});
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.js"],
|
|
4
|
-
"sourcesContent": ["/*!\n * DOM Selector - A CSS selector engine.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport {
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,
|
|
6
|
-
"names": ["src_exports", "__export", "closest", "matches", "querySelector", "querySelectorAll", "__toCommonJS", "
|
|
4
|
+
"sourcesContent": ["/*!\n * DOM Selector - A CSS selector engine.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Finder } from './js/finder.js';\n\n/* export for test */\nexport { Finder };\n\n/* instance, export for test */\nexport let finder = new Finder();\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 let res;\n try {\n if (!finder) {\n finder = new Finder();\n }\n res = finder.matches(node, selector, opt);\n } catch (e) {\n if (e instanceof Error) {\n finder = null;\n }\n throw e;\n }\n return res;\n};\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 let res;\n try {\n if (!finder) {\n finder = new Finder();\n }\n res = finder.closest(node, selector, opt);\n } catch (e) {\n if (e instanceof globalThis[e.name]) {\n finder = null;\n }\n throw e;\n }\n return res;\n};\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 let res;\n try {\n if (!finder) {\n finder = new Finder();\n }\n res = finder.querySelector(node, selector, opt);\n } catch (e) {\n if (e instanceof globalThis[e.name]) {\n finder = null;\n }\n throw e;\n }\n return res;\n};\n\n/**\n * querySelectorAll\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment or Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn e.g. unsupported pseudo-class\n * @returns {Array.<object|undefined>} - array of matched nodes\n */\nexport const querySelectorAll = (selector, node, opt) => {\n let res;\n try {\n if (!finder) {\n finder = new Finder();\n }\n res = finder.querySelectorAll(node, selector, opt);\n } catch (e) {\n if (e instanceof globalThis[e.name]) {\n finder = null;\n }\n throw e;\n }\n return res;\n};\n"],
|
|
5
|
+
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,EAAA,WAAAC,EAAA,YAAAC,EAAA,kBAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAP,GAQA,IAAAQ,EAAuB,0BARvB;AAAA;AAAA;AAAA;AAAA;AAAA,GAcO,IAAIL,EAAS,IAAI,SAUjB,MAAMC,EAAU,CAACK,EAAUC,EAAMC,IAAQ,CAC9C,IAAIC,EACJ,GAAI,CACGT,IACHA,EAAS,IAAI,UAEfS,EAAMT,EAAO,QAAQO,EAAMD,EAAUE,CAAG,CAC1C,OAAS,EAAG,CACV,MAAI,aAAa,QACfR,EAAS,MAEL,CACR,CACA,OAAOS,CACT,EAUaV,EAAU,CAACO,EAAUC,EAAMC,IAAQ,CAC9C,IAAIC,EACJ,GAAI,CACGT,IACHA,EAAS,IAAI,UAEfS,EAAMT,EAAO,QAAQO,EAAMD,EAAUE,CAAG,CAC1C,OAAS,EAAG,CACV,MAAI,aAAa,WAAW,EAAE,IAAI,IAChCR,EAAS,MAEL,CACR,CACA,OAAOS,CACT,EAUaP,EAAgB,CAACI,EAAUC,EAAMC,IAAQ,CACpD,IAAIC,EACJ,GAAI,CACGT,IACHA,EAAS,IAAI,UAEfS,EAAMT,EAAO,cAAcO,EAAMD,EAAUE,CAAG,CAChD,OAAS,EAAG,CACV,MAAI,aAAa,WAAW,EAAE,IAAI,IAChCR,EAAS,MAEL,CACR,CACA,OAAOS,CACT,EAWaN,EAAmB,CAACG,EAAUC,EAAMC,IAAQ,CACvD,IAAIC,EACJ,GAAI,CACGT,IACHA,EAAS,IAAI,UAEfS,EAAMT,EAAO,iBAAiBO,EAAMD,EAAUE,CAAG,CACnD,OAAS,EAAG,CACV,MAAI,aAAa,WAAW,EAAE,IAAI,IAChCR,EAAS,MAEL,CACR,CACA,OAAOS,CACT",
|
|
6
|
+
"names": ["src_exports", "__export", "closest", "finder", "matches", "querySelector", "querySelectorAll", "__toCommonJS", "import_finder", "selector", "node", "opt", "res"]
|
|
7
7
|
}
|
package/dist/cjs/js/constant.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var E=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var
|
|
1
|
+
var E=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var n=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 x(t))!n.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 rt={};T(rt,{ALPHA_NUM:()=>O,AN_PLUS_B:()=>S,BIT_01:()=>W,BIT_02:()=>a,BIT_04:()=>d,BIT_08:()=>i,BIT_16:()=>u,BIT_32:()=>Y,BIT_FFFF:()=>h,BIT_HYPHEN:()=>$,COMBINATOR:()=>N,DOCUMENT_FRAGMENT_NODE:()=>j,DOCUMENT_NODE:()=>Z,DOCUMENT_POSITION_CONTAINED_BY:()=>v,DOCUMENT_POSITION_CONTAINS:()=>q,DOCUMENT_POSITION_PRECEDING:()=>k,DUO:()=>X,ELEMENT_NODE:()=>y,HEX:()=>b,IDENTIFIER:()=>D,NOT_SUPPORTED_ERR:()=>I,NTH:()=>R,RAW:()=>C,REG_LOGICAL_PSEUDO:()=>V,REG_SHADOW_HOST:()=>tt,REG_SHADOW_MODE:()=>ot,REG_SHADOW_PSEUDO:()=>et,SELECTOR:()=>A,SELECTOR_ATTR:()=>L,SELECTOR_CLASS:()=>P,SELECTOR_ID:()=>F,SELECTOR_LIST:()=>M,SELECTOR_PSEUDO_CLASS:()=>U,SELECTOR_PSEUDO_ELEMENT:()=>l,SELECTOR_TYPE:()=>H,SHOW_ALL:()=>z,SHOW_DOCUMENT:()=>J,SHOW_DOCUMENT_FRAGMENT:()=>K,SHOW_ELEMENT:()=>Q,STRING:()=>B,SYNTAX_ERR:()=>f,TEXT_NODE:()=>g,TYPE_FROM:()=>m,TYPE_TO:()=>w,U_FFFD:()=>G});module.exports=p(rt);const O="[A-Z\\d]+",S="AnPlusB",N="Combinator",D="Identifier",I="NotSupportedError",R="Nth",C="Raw",A="Selector",L="AttributeSelector",P="ClassSelector",F="IdSelector",M="SelectorList",U="PseudoClassSelector",l="PseudoElementSelector",H="TypeSelector",B="String",f="SyntaxError",G="\uFFFD",W=1,a=2,d=4,i=8,u=16,Y=32,h=65535,$=45,X=2,b=16,m=8,w=-1,y=1,g=3,Z=9,j=11,k=2,q=8,v=16,z=4294967295,J=256,K=1024,Q=1,V=/^(?:(?:ha|i)s|not|where)$/,tt=/^host(?:-context)?$/,ot=/^(?:close|open)$/,et=/^part|slotted$/;0&&(module.exports={ALPHA_NUM,AN_PLUS_B,BIT_01,BIT_02,BIT_04,BIT_08,BIT_16,BIT_32,BIT_FFFF,BIT_HYPHEN,COMBINATOR,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,DUO,ELEMENT_NODE,HEX,IDENTIFIER,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_ALL,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
|
|
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,
|
|
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", "
|
|
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_FFFF = 0xFFFF;\nexport const BIT_HYPHEN = 0x2D;\nexport const DUO = 2;\nexport const HEX = 16;\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_ALL = 0xffffffff;\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,aAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,2BAAAC,EAAA,kBAAAC,EAAA,mCAAAC,EAAA,+BAAAC,EAAA,gCAAAC,EAAA,QAAAC,EAAA,iBAAAC,EAAA,QAAAC,EAAA,eAAAC,EAAA,sBAAAC,EAAA,QAAAC,EAAA,QAAAC,EAAA,uBAAAC,EAAA,oBAAAC,GAAA,oBAAAC,GAAA,sBAAAC,GAAA,aAAAC,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,kBAAAC,EAAA,0BAAAC,EAAA,4BAAAC,EAAA,kBAAAC,EAAA,aAAAC,EAAA,kBAAAC,EAAA,2BAAAC,EAAA,iBAAAC,EAAA,WAAAC,EAAA,eAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,YAAAC,EAAA,WAAAC,IAAA,eAAAC,EAAA/C,IAKO,MAAME,EAAY,YACZC,EAAY,UACZS,EAAa,aACbS,EAAa,aACbC,EAAoB,oBACpBC,EAAM,MACNC,EAAM,MACNK,EAAW,WACXC,EAAgB,oBAChBC,EAAiB,gBACjBC,EAAc,aACdC,EAAgB,eAChBC,EAAwB,sBACxBC,EAA0B,wBAC1BC,EAAgB,eAChBK,EAAS,SACTC,EAAa,cACbI,EAAS,SAGT1C,EAAS,EACTC,EAAS,EACTC,EAAS,EACTC,EAAS,EACTC,EAAS,GACTC,EAAS,GACTC,EAAW,MACXC,EAAa,GACbO,EAAM,EACNE,EAAM,GACNwB,EAAY,EACZC,EAAU,GAGV1B,EAAe,EACfwB,EAAY,EACZ7B,EAAgB,EAChBD,EAAyB,GACzBI,EAA8B,EAC9BD,EAA6B,EAC7BD,EAAiC,GAGjCsB,EAAW,WACXC,EAAgB,IAChBC,EAAyB,KACzBC,EAAe,EAGff,EAAqB,4BACrBC,GAAkB,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_FFFF", "BIT_HYPHEN", "COMBINATOR", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_PRECEDING", "DUO", "ELEMENT_NODE", "HEX", "IDENTIFIER", "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_ALL", "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/dom-util.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=Object.create;var p=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},d=(e,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!_.call(e,s)&&s!==i&&p(e,s,{get:()=>t[s],enumerable:!(o=w(t,s))||o.enumerable});return e};var I=(e,t,i)=>(i=e!=null?h(C(e)):{},d(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),M=e=>d(p({},"__esModule",{value:!0}),e);var $={};k($,{getDirectionality:()=>u,getSlottedTextContent:()=>f,isContentEditable:()=>D,isInShadowTree:()=>x,isInclusive:()=>v,isNamespaceDeclared:()=>S,isPreceding:()=>O,prepareDOMObjects:()=>P,sortNodes:()=>U});module.exports=M($);var E=I(require("bidi-js"),1),r=require("./constant.js");const P=e=>{if(!e||!e.nodeType||!e.nodeName){const n=`Unexpected type ${Object.prototype.toString.call(e).slice(r.TYPE_FROM,r.TYPE_TO)}`;throw new TypeError(n)}else if(e.nodeType!==r.DOCUMENT_NODE&&e.nodeType!==r.DOCUMENT_FRAGMENT_NODE&&e.nodeType!==r.ELEMENT_NODE){const s=`Unexpected node ${e.nodeName}`;throw new TypeError(s)}let t,i;switch(e.nodeType){case r.DOCUMENT_NODE:{t=e,i=e;break}case r.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,i=e;break}case r.ELEMENT_NODE:default:{t=e.ownerDocument;let s=e;for(;s&&s.parentNode;)s=s.parentNode;i=s;break}}return[t.defaultView,t,i]},x=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE||e.nodeType===r.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:o,mode:s,nodeType:n,parentNode:c}=i;if(o&&s&&n===r.DOCUMENT_FRAGMENT_NODE&&r.REG_SHADOW_MODE.test(s)){t=!0;break}i=c}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&x(e)){const i=e.assignedNodes();if(i.length){for(const o of i)if(t=o.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},u=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE){const{dir:i,localName:o,parentNode:s}=e,{getEmbeddingLevels:n}=(0,E.default)(),c=/^(?:ltr|rtl)$/;if(c.test(i))t=i;else if(i==="auto"){let l;switch(o){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(l=e.value);break}case"slot":{l=f(e);break}case"textarea":{l=e.value;break}default:{const a=[].slice.call(e.childNodes);for(const T of a){const{dir:m,localName:N,nodeType:y,textContent:b}=T;if(y===r.TEXT_NODE?l=b.trim():y===r.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(N)&&(!m||!c.test(m))&&(N==="slot"?l=f(T):l=b.trim()),l)break}}}if(l){const{paragraphs:[{level:a}]}=n(l);a%2===1?t="rtl":t="ltr"}if(!t)if(s){const{nodeType:a}=s;a===r.ELEMENT_NODE?t=u(s):(a===r.DOCUMENT_NODE||a===r.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(o==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:a}]}=n(l);a%2===1?t="rtl":t="ltr"}t||s||(t="ltr")}else if(o==="input"&&e.type==="tel")t="ltr";else if(s){if(o==="slot"){const l=f(e);if(l){const{paragraphs:[{level:a}]}=n(l);a%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=s;l===r.ELEMENT_NODE?t=u(s):(l===r.DOCUMENT_NODE||l===r.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},D=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const i=e.getAttribute("contenteditable");if(i===""||/^(?:plaintext-only|true)$/.test(i))t=!0;else if(i==="inherit"){let o=e.parentNode;for(;o;){if(D(o)){t=!0;break}o=o.parentNode}}}}return!!t},S=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===r.ELEMENT_NODE){const o=`xmlns:${e}`,s=t.ownerDocument.documentElement;let n=t;for(;n;){if(typeof n.hasAttribute=="function"&&n.hasAttribute(o)){i=!0;break}else if(n===s)break;n=n.parentNode}}return!!i},v=(e={},t={})=>{let i;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE){const o=t.compareDocumentPosition(e);i=o&r.DOCUMENT_POSITION_CONTAINS||o&r.DOCUMENT_POSITION_CONTAINED_BY}return!!i},O=(e={},t={})=>{let i;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE){const o=t.compareDocumentPosition(e);i=o&r.DOCUMENT_POSITION_PRECEDING||o&r.DOCUMENT_POSITION_CONTAINS}return!!i},U=(e=[])=>{const t=[...e];return t.length>1&&t.sort((i,o)=>{let s;return O(o,i)?s=1:s=-1,s}),t};0&&(module.exports={getDirectionality,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,prepareDOMObjects,sortNodes});
|
|
2
2
|
//# sourceMappingURL=dom-util.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/dom-util.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n REG_SHADOW_MODE,
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,
|
|
6
|
-
"names": ["dom_util_exports", "__export", "getDirectionality", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isInclusive", "isNamespaceDeclared", "isPreceding", "
|
|
4
|
+
"sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n REG_SHADOW_MODE, TEXT_NODE, TYPE_FROM, TYPE_TO\n} from './constant.js';\n\n/**\n * prepare window, document, root node\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of window, document, root node\n */\nexport const prepareDOMObjects = node => {\n if (!node || !node.nodeType || !node.nodeName) {\n const type =\n Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${type}`;\n throw new TypeError(msg);\n } else if (node.nodeType !== DOCUMENT_NODE &&\n node.nodeType !== DOCUMENT_FRAGMENT_NODE &&\n node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\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 default: {\n document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n }\n // NOTE: nullable\n const window = document.defaultView;\n return [\n window,\n document,\n root\n ];\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = (node = {}) => {\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = (node = {}) => {\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n const regDir = /^(?:ltr|rtl)$/;\n if (regDir.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type)) {\n text = node.value;\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(itemLocalName) &&\n (!itemDir || !regDir.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n const attr = `xmlns:${ns}`;\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n if (typeof parent.hasAttribute === 'function' &&\n parent.hasAttribute(attr)) {\n res = true;\n break;\n } else if (parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n return !!res;\n};\n\n/**\n * is inclusive - nodeA and nodeB are in inclusive relation\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isInclusive = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_CONTAINS ||\n posBit & DOCUMENT_POSITION_CONTAINED_BY;\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a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M,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDlB,EAAMoB,EAAS,+BACTA,EAAS,4BACjB,CACA,MAAO,CAAC,CAACpB,CACX,EAOaf,EAAY,CAACgB,EAAQ,CAAC,IAAM,CACvC,MAAMoB,EAAM,CAAC,GAAGpB,CAAK,EACrB,OAAIoB,EAAI,OAAS,GACfA,EAAI,KAAK,CAACC,EAAGC,IAAM,CACjB,IAAIvB,EACJ,OAAIjB,EAAYwC,EAAGD,CAAC,EAClBtB,EAAM,EAENA,EAAM,GAEDA,CACT,CAAC,EAEIqB,CACT",
|
|
6
|
+
"names": ["dom_util_exports", "__export", "getDirectionality", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isInclusive", "isNamespaceDeclared", "isPreceding", "prepareDOMObjects", "sortNodes", "__toCommonJS", "import_bidi_js", "import_constant", "node", "msg", "document", "root", "parent", "bool", "refNode", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "getEmbeddingLevels", "bidiFactory", "regDir", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "attr", "ns", "nodeA", "nodeB", "posBit", "arr", "a", "b"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var F=Object.create;var P=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(T,r)=>{for(var e in r)P(T,e,{get:r[e],enumerable:!0})},W=(T,r,e,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of G(r))!V.call(T,i)&&i!==e&&P(T,i,{get:()=>r[i],enumerable:!(c=H(r,i))||c.enumerable});return T};var Y=(T,r,e)=>(e=T!=null?F(q(T)):{},W(r||!T||!T.__esModule?P(e,"default",{value:T,enumerable:!0}):e,T)),K=T=>W(P({},"__esModule",{value:!0}),T);var Q={};X(Q,{Finder:()=>J});module.exports=K(Q);var I=Y(require("is-potential-custom-element-name"),1),A=require("./dom-util.js"),D=require("./matcher.js"),S=require("./parser.js"),o=require("./constant.js");const O="next",$="prev",L="all",C="first",j="lineal",B="self",U=o.SHOW_DOCUMENT|o.SHOW_DOCUMENT_FRAGMENT|o.SHOW_ELEMENT;class J{#a;#l;#d;#e;#r;#t;#n;#s;#b;#f;#c;#h;#i;#o;constructor(){this.#l=new WeakMap}_onError(r){if(r instanceof DOMException||this.#o&&r instanceof this.#o.DOMException)if(r.name===o.NOT_SUPPORTED_ERR)this.#i&&console.warn(r.message);else throw this.#o?new this.#o.DOMException(r.message,r.name):r;else throw r}_setup(r,e,c={}){const{warn:i}=c;this.#i=!!i,[this.#o,this.#e,this.#s]=(0,A.prepareDOMObjects)(r),this.#t=r,this.#f=(0,A.isInShadowTree)(r),this.#b=e,[this.#a,this.#n]=this._correspond(e),this.#d=new WeakMap}_correspond(r){const e=[];let c,i=this.#e&&this.#l.get(this.#e);if(i&&i.has(`${r}`)&&(c=i.get(r),typeof c=="string"))throw new DOMException(c,o.SYNTAX_ERR);if(c){const s=c.length;for(let f=0;f<s;f++)c[f].dir=null,c[f].filtered=!1,c[f].find=!1,e[f]=[]}else{let s;try{s=(0,S.parseSelector)(r)}catch(u){this.#e&&(i||(i=new Map),i.set(`${r}`,u.message),this.#l.set(this.#e,i)),this._onError(u)}const f=(0,S.walkAST)(s);c=[];let b=0;for(const[...u]of f){const n=[];let t=u.shift();if(t&&t.type!==o.COMBINATOR){const a=new Set;for(;t;){if(t.type===o.COMBINATOR){const[h]=u;if(h.type===o.COMBINATOR){const l=`Invalid selector ${r}`;throw this.#e&&(i||(i=new Map),i.set(`${r}`,l),this.#l.set(this.#e,i)),new DOMException(l,o.SYNTAX_ERR)}n.push({combo:t,leaves:(0,S.sortAST)(a)}),a.clear()}else t&&a.add(t);if(u.length)t=u.shift();else{n.push({combo:null,leaves:(0,S.sortAST)(a)}),a.clear();break}}}c.push({branch:n,dir:null,filtered:!1,find:!1}),e[b]=[],b++}this.#e&&(i||(i=new Map),i.set(`${r}`,c),this.#l.set(this.#e,i))}return[c,e]}_traverse(r={},e=this.#h){let c,i=e.currentNode;if(r.nodeType===o.ELEMENT_NODE&&i===r)c=i;else{if(i!==e.root)for(;i&&!(i===e.root||r.nodeType===o.ELEMENT_NODE&&i===r);)i=e.parentNode();if(r.nodeType===o.ELEMENT_NODE)for(;i;){if(i===r){c=i;break}i=e.nextNode()}else c=i}return c??null}_collectNthChild(r,e,c){const{a:i,b:s,reverse:f,selector:b}=r,{parentNode:u}=e;let n=new Set,t;if(b&&(this.#l.has(b)?t=this.#l.get(b):(t=(0,S.walkAST)(b),this.#l.set(b,t))),u){const a=this.#e.createTreeWalker(u,U);let h=0,l=a.firstChild();for(;l;)h++,l=a.nextSibling();l=this._traverse(u,a);const p=new Set;if(t)for(l=this._traverse(u,a),l=a.firstChild();l;){let m;for(const g of t)if(m=this._matchLeaves(g,l,c),!m)break;m&&p.add(l),l=a.nextSibling()}if(i===0){if(s>0&&s<=h){if(p.size){let m=0;for(l=this._traverse(u,a),f?l=a.lastChild():l=a.firstChild();l;){if(p.has(l)){if(m===s-1){n.add(l);break}m++}f?l=a.previousSibling():l=a.nextSibling()}}else if(!b){let m=0;for(l=this._traverse(u,a),f?l=a.lastChild():l=a.firstChild();l;){if(m===s-1){n.add(l);break}f?l=a.previousSibling():l=a.nextSibling(),m++}}}}else{let m=s-1;if(i>0)for(;m<0;)m+=i;if(m>=0&&m<h){let g=0,N=i>0?0:s-1;for(l=this._traverse(u,a),f?l=a.lastChild():l=a.firstChild();l&&(l&&m>=0&&m<h);)p.size?p.has(l)&&(N===m&&(n.add(l),m+=i),i>0?N++:N--):g===m&&(b||n.add(l),m+=i),f?l=a.previousSibling():l=a.nextSibling(),g++}}if(f&&n.size>1){const m=[...n];n=new Set(m.reverse())}}else if(e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&i+s===1)if(t){let a;for(const h of t)if(a=this._matchLeaves(h,e,c),a)break;a&&n.add(e)}else n.add(e);return n}_collectNthOfType(r,e){const{a:c,b:i,reverse:s}=r,{localName:f,parentNode:b,prefix:u}=e;let n=new Set;if(b){const t=this.#e.createTreeWalker(b,U);let a=0,h=t.firstChild();for(;h;)a++,h=t.nextSibling();if(c===0){if(i>0&&i<=a){let l=0;for(h=this._traverse(b,t),s?h=t.lastChild():h=t.firstChild();h;){const{localName:p,prefix:m}=h;if(p===f&&m===u){if(l===i-1){n.add(h);break}l++}s?h=t.previousSibling():h=t.nextSibling()}}}else{let l=i-1;if(c>0)for(;l<0;)l+=c;if(l>=0&&l<a){let p=c>0?0:i-1;for(h=this._traverse(b,t),s?h=t.lastChild():h=t.firstChild();h;){const{localName:m,prefix:g}=h;if(m===f&&g===u){if(p===l&&(n.add(h),l+=c),l<0||l>=a)break;c>0?p++:p--}s?h=t.previousSibling():h=t.nextSibling()}}}if(s&&n.size>1){const l=[...n];n=new Set(l.reverse())}}else e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&c+i===1&&n.add(e);return n}_matchAnPlusB(r,e,c,i){const{nth:{a:s,b:f,name:b},selector:u}=r,n=(0,S.unescapeSelector)(b),t=new Map;n?(n==="even"?(t.set("a",2),t.set("b",0)):n==="odd"&&(t.set("a",2),t.set("b",1)),c.indexOf("last")>-1&&t.set("reverse",!0)):(typeof s=="string"&&/-?\d+/.test(s)?t.set("a",s*1):t.set("a",0),typeof f=="string"&&/-?\d+/.test(f)?t.set("b",f*1):t.set("b",0),c.indexOf("last")>-1&&t.set("reverse",!0));let a=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){u&&t.set("selector",u);const h=Object.fromEntries(t),l=this._collectNthChild(h,e,i);l.size&&(a=l)}else if(/^nth-(?:last-)?of-type$/.test(c)){const h=Object.fromEntries(t),l=this._collectNthOfType(h,e);l.size&&(a=l)}}return a}_matchDirectionPseudoClass(r,e){const c=(0,S.unescapeSelector)(r.name),i=(0,A.getDirectionality)(e);let s;return c===i&&(s=e),s??null}_matchLanguagePseudoClass(r,e){const c=(0,S.unescapeSelector)(r.name);let i;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(i=e);else{let s=e.parentNode;for(;s&&s.nodeType===o.ELEMENT_NODE;){if(s.hasAttribute("lang")){s.getAttribute("lang")&&(i=e);break}s=s.parentNode}}else if(c){const s=`(?:-${o.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${o.ALPHA_NUM}${s}$`,"i").test(c)){let b;if(c.indexOf("-")>-1){const[u,n,...t]=c.split("-");let a;u==="*"?a=`${o.ALPHA_NUM}${s}`:a=`${u}${s}`;const h=`-${n}${s}`,l=t.length;let p="";if(l)for(let m=0;m<l;m++)p+=`-${t[m]}${s}`;b=new RegExp(`^${a}${h}${p}$`,"i")}else b=new RegExp(`^${c}${s}$`,"i");if(e.hasAttribute("lang"))b.test(e.getAttribute("lang"))&&(i=e);else{let u=e.parentNode;for(;u&&u.nodeType===o.ELEMENT_NODE;){if(u.hasAttribute("lang")){const n=u.getAttribute("lang");b.test(n)&&(i=e);break}u=u.parentNode}}}}return i??null}_matchHasPseudoFunc(r,e,c={}){let i;if(Array.isArray(r)&&r.length){const[s]=r,{type:f}=s;let b;f===o.COMBINATOR?b=r.shift():b={name:" ",type:o.COMBINATOR};const u=[];for(;r.length;){const[a]=r,{type:h}=a;if(h===o.COMBINATOR)break;u.push(r.shift())}const n={combo:b,leaves:u};c.dir=O;const t=this._matchCombinator(n,e,c);if(t.size)if(r.length){for(const a of t)if(i=this._matchHasPseudoFunc(Object.assign([],r),a,c),i)break}else i=!0}return!!i}_matchLogicalPseudoFunc(r,e,c={}){const{astName:i="",branches:s=[],selector:f="",twigBranches:b=[]}=r;let u;if(i==="has")if(f.includes(":has("))u=null;else{let n;for(const t of s)if(n=this._matchHasPseudoFunc(Object.assign([],t),e,c),n)break;n&&(u=e)}else{const n=/^(?:is|where)$/.test(i);c.forgive=n;const t=b.length;let a;for(let h=0;h<t;h++){const l=b[h],p=l.length-1,{leaves:m}=l[p];if(a=this._matchLeaves(m,e,c),a&&p>0){let g=new Set([e]);for(let N=p-1;N>=0;N--){const y=l[N],d=[];c.dir=$;for(const k of g){const w=this._matchCombinator(y,k,c);w.size&&d.push(...w)}if(d.length)N===0?a=!0:g=new Set(d);else{a=!1;break}}}if(a)break}i==="not"?a||(u=e):a&&(u=e)}return u??null}_matchPseudoClassSelector(r,e,c={}){const{children:i}=r,{localName:s,parentNode:f}=e,{forgive:b,warn:u}=c,n=(0,S.unescapeSelector)(r.name);let t=new Set;if(o.REG_LOGICAL_PSEUDO.test(n)){let a;if(this.#l.has(r))a=this.#l.get(r);else{const l=(0,S.walkAST)(r),p=[],m=[];for(const[...g]of l){for(const k of g){const w=(0,S.generateCSS)(k);p.push(w)}const N=[],y=new Set;let d=g.shift();for(;d;)if(d.type===o.COMBINATOR?(N.push({combo:d,leaves:[...y]}),y.clear()):d&&y.add(d),g.length)d=g.shift();else{N.push({combo:null,leaves:[...y]}),y.clear();break}m.push(N)}a={astName:n,branches:l,twigBranches:m,selector:p.join(",")},this.#l.set(r,a)}const h=this._matchLogicalPseudoFunc(a,e,c);h&&t.add(h)}else if(Array.isArray(i)){const[a]=i;if(/^nth-(?:last-)?(?:child|of-type)$/.test(n)){const h=this._matchAnPlusB(a,e,n,c);h.size&&(t=h)}else if(n==="dir"){const h=this._matchDirectionPseudoClass(a,e);h&&t.add(h)}else if(n==="lang"){const h=this._matchLanguagePseudoClass(a,e);h&&t.add(h)}else switch(n){case"current":case"nth-col":case"nth-last-col":{if(u){const h=`Unsupported pseudo-class :${n}()`;throw new DOMException(h,o.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!b){const h=`Unknown pseudo-class :${n}()`;throw new DOMException(h,o.SYNTAX_ERR)}}}else{const a=/^a(?:rea)?$/,h=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,l=/^(?:(?:inpu|selec)t|button|form|textarea)$/,p=/^d(?:etails|ialog)$/,m=/^(?:checkbox|radio)$/,g=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,y=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(n){case"any-link":case"link":{a.test(s)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(a.test(s)&&e.hasAttribute("href")){const{href:d,origin:k,pathname:w}=new URL(this.#e.URL),_=new URL(e.getAttribute("href"),d);_.origin===k&&_.pathname===w&&t.add(e)}break}case"visited":break;case"target":{const{hash:d}=new URL(this.#e.URL);e.id&&d===`#${e.id}`&&this.#e.contains(e)&&t.add(e);break}case"target-within":{const{hash:d}=new URL(this.#e.URL);if(d){const k=d.replace(/^#/,"");let w=this.#e.getElementById(k);for(;w;){if(w===e){t.add(e);break}w=w.parentNode}}break}case"scope":{this.#t.nodeType===o.ELEMENT_NODE?e===this.#t&&t.add(e):e===this.#e.documentElement&&t.add(e);break}case"focus":{e===this.#e.activeElement&&t.add(e);break}case"focus-within":{let d=this.#e.activeElement;for(;d;){if(d===e){t.add(e);break}d=d.parentNode}break}case"open":{p.test(s)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{p.test(s)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(h.test(s)||(0,I.default)(s))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let d=f;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&f.localName!=="legend"&&d.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(h.test(s)||(0,I.default)(s))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(s){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||g.test(e.type)||y.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,A.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(s){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||g.test(e.type)||y.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,A.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let d;s==="textarea"?d=e:s==="input"&&(e.hasAttribute("type")?y.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&s==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))||e.selected&&s==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&s==="input"&&e.type==="checkbox"||s==="progress"&&!e.hasAttribute("value"))t.add(e);else if(s==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let k=e.parentNode;for(;k&&k.localName!=="form";)k=k.parentNode;k||(k=this.#e.documentElement);let w;const _=k.getElementsByTagName("input"),E=_.length;if(E)for(let x=0;x<E;x++){const v=_[x];if(v.getAttribute("type")==="radio"&&(d?v.getAttribute("name")===d&&(w=!!v.checked):v.hasAttribute("name")||(w=!!v.checked),w))break}w||t.add(e)}break}case"default":{const d=/^(?:button|reset)$/,k=/^(?:image|submit)$/;if(s==="button"&&!(e.hasAttribute("type")&&d.test(e.getAttribute("type")))||s==="input"&&e.hasAttribute("type")&&k.test(e.getAttribute("type"))){let w=e.parentNode;for(;w&&w.localName!=="form";)w=w.parentNode;if(w){const _=this.#e.createTreeWalker(w,o.SHOW_ELEMENT);let E=_.firstChild();for(;E;){const x=E.localName;let v;if(x==="button"?v=!(E.hasAttribute("type")&&d.test(E.getAttribute("type"))):x==="input"&&(v=E.hasAttribute("type")&&k.test(E.getAttribute("type"))),v){E===e&&t.add(e);break}E=_.nextNode()}}}else if(s==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(s==="option"){let w=!1,_=f;for(;_&&_.localName!=="datalist";){if(_.localName==="select"){(_.multiple||_.hasAttribute("multiple"))&&(w=!0);break}_=_.parentNode}if(w)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const E=new Set,x=this.#e.createTreeWalker(f,o.SHOW_ELEMENT);let v=x.firstChild();for(;v;){if(v.selected||v.hasAttribute("selected")){E.add(v);break}v=x.nextSibling()}E.size&&E.has(e)&&t.add(e)}}break}case"valid":{if(l.test(s))e.checkValidity()&&t.add(e);else if(s==="fieldset"){let d;const k=this.#e.createTreeWalker(e,o.SHOW_ELEMENT);let w=k.firstChild();for(;w&&!(l.test(w.localName)&&(d=w.checkValidity(),!d));)w=k.nextNode();d&&t.add(e)}break}case"invalid":{if(l.test(s))e.checkValidity()||t.add(e);else if(s==="fieldset"){let d;const k=this.#e.createTreeWalker(e,o.SHOW_ELEMENT);let w=k.firstChild();for(;w&&!(l.test(w.localName)&&(d=w.checkValidity(),!d));)w=k.nextNode();d||t.add(e)}break}case"in-range":{s==="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":{s==="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 d;if(/^(?:select|textarea)$/.test(s))d=e;else if(s==="input")if(e.hasAttribute("type")){const k=e.getAttribute("type");(k==="file"||m.test(k)||g.test(k)||y.test(k))&&(d=e)}else d=e;d&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let d;if(/^(?:select|textarea)$/.test(s))d=e;else if(s==="input")if(e.hasAttribute("type")){const k=e.getAttribute("type");(k==="file"||m.test(k)||g.test(k)||y.test(k))&&(d=e)}else d=e;d&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#e.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){let d;const k=this.#e.createTreeWalker(e,o.SHOW_ALL);let w=k.firstChild();for(;w&&(d=w.nodeType!==o.ELEMENT_NODE&&w.nodeType!==o.TEXT_NODE,!!d);)w=k.nextSibling();d&&t.add(e)}else t.add(e);break}case"first-child":{(f&&e===f.firstElementChild||e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(f&&e===f.lastElementChild||e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(f&&e===f.firstElementChild&&e===f.lastElementChild||e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(f){const[d]=this._collectNthOfType({a:0,b:1},e);d&&t.add(d)}else e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(f){const[d]=this._collectNthOfType({a:0,b:1,reverse:!0},e);d&&t.add(d)}else e===this.#s&&this.#s.nodeType===o.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(f){const[d]=this._collectNthOfType({a:0,b:1},e);if(d===e){const[k]=this._collectNthOfType({a:0,b:1,reverse:!0},e);k===e&&t.add(e)}}else e===this.#s&&this.#s.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(u){const d=`Unsupported pseudo-element ::${n}`;throw new DOMException(d,o.NOT_SUPPORTED_ERR)}break}case"active":case"autofill":case"blank":case"buffering":case"current":case"defined":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(u){const d=`Unsupported pseudo-class :${n}`;throw new DOMException(d,o.NOT_SUPPORTED_ERR)}break}default:if(n.startsWith("-webkit-")){if(u){const d=`Unsupported pseudo-class :${n}`;throw new DOMException(d,o.NOT_SUPPORTED_ERR)}}else if(!b){const d=`Unknown pseudo-class :${n}`;throw new DOMException(d,o.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(r,e){const{children:c}=r,i=(0,S.unescapeSelector)(r.name);let s;if(Array.isArray(c)){const[f]=(0,S.walkAST)(c[0]),[...b]=f,{host:u}=e;if(i==="host"){let n;for(const t of b){const{type:a}=t;if(a===o.COMBINATOR){const l=`Invalid selector ${(0,S.generateCSS)(r)}`;throw new DOMException(l,o.SYNTAX_ERR)}if(n=this._matchSelector(t,u).has(u),!n)break}n&&(s=e)}else if(i==="host-context"){let n,t=u;for(;t;){for(const a of b){const{type:h}=a;if(h===o.COMBINATOR){const p=`Invalid selector ${(0,S.generateCSS)(r)}`;throw new DOMException(p,o.SYNTAX_ERR)}if(n=this._matchSelector(a,t).has(t),!n)break}if(n)break;t=t.parentNode}n&&(s=e)}}else if(i==="host")s=e;else{const f=`Invalid selector :${i}`;throw new DOMException(f,o.SYNTAX_ERR)}return s??null}_matchSelector(r,e,c){const{type:i}=r,s=(0,S.unescapeSelector)(r.name);let f=new Set;if(e.nodeType===o.ELEMENT_NODE)switch(i){case o.SELECTOR_PSEUDO_CLASS:{const b=this._matchPseudoClassSelector(r,e,c);b.size&&(f=b);break}case o.SELECTOR_PSEUDO_ELEMENT:{(0,D.matchPseudoElementSelector)(s,c);break}default:{const b=(0,D.matchSelector)(r,e,c);b&&f.add(b)}}else if(this.#f&&i===o.SELECTOR_PSEUDO_CLASS&&e.nodeType===o.DOCUMENT_FRAGMENT_NODE){if(s!=="has"&&o.REG_LOGICAL_PSEUDO.test(s)){const b=this._matchPseudoClassSelector(r,e,c);b.size&&(f=b)}else if(o.REG_SHADOW_HOST.test(s)){const b=this._matchShadowHostPseudoClass(r,e,c);b&&f.add(b)}}return f}_matchLeaves(r,e,c){let i;for(const s of r)if(i=this._matchSelector(s,e,c).has(e),!i)break;return!!i}_findDescendantNodes(r,e,c){const[i,...s]=r,{type:f}=i,b=(0,S.unescapeSelector)(i.name),u=s.length>0;let n=new Set,t=!1;if(this.#f)t=!0;else switch(f){case o.SELECTOR_ID:{if(this.#s.nodeType===o.ELEMENT_NODE)t=!0;else{const a=this.#s.getElementById(b);a&&a!==e&&e.contains(a)&&(u?this._matchLeaves(s,a,c)&&n.add(a):n.add(a))}break}case o.SELECTOR_CLASS:{const a=e.getElementsByClassName(b),h=a.length;if(h)if(u)for(let l=0;l<h;l++){const p=a[l];this._matchLeaves(s,p,c)&&n.add(p)}else{const l=[].slice.call(a);n=new Set(l)}break}case o.SELECTOR_TYPE:{if(this.#e.contentType==="text/html"&&!/[*|]/.test(b)){const a=e.getElementsByTagName(b),h=a.length;if(h)if(u)for(let l=0;l<h;l++){const p=a[l];this._matchLeaves(s,p,c)&&n.add(p)}else{const l=[].slice.call(a);n=new Set(l)}}else t=!0;break}case o.SELECTOR_PSEUDO_ELEMENT:{(0,D.matchPseudoElementSelector)(b,c);break}default:t=!0}return{nodes:n,pending:t}}_matchCombinator(r,e,c={}){const{combo:i,leaves:s}=r,{name:f}=i,{dir:b}=c;let u=new Set;if(b===O)switch(f){case"+":{const n=e.nextElementSibling;n&&this._matchLeaves(s,n,c)&&u.add(n);break}case"~":{const{parentNode:n}=e;if(n){const t=this.#e.createTreeWalker(n,o.SHOW_ELEMENT);let a=this._traverse(e,t);for(a===e&&(a=t.nextSibling());a;)this._matchLeaves(s,a,c)&&u.add(a),a=t.nextSibling()}break}case">":{const n=this.#e.createTreeWalker(e,o.SHOW_ELEMENT);let t=n.firstChild();for(;t;)this._matchLeaves(s,t,c)&&u.add(t),t=n.nextSibling();break}case" ":default:{const{nodes:n,pending:t}=this._findDescendantNodes(s,e);if(n.size)u=n;else if(t){const a=this.#e.createTreeWalker(e,o.SHOW_ELEMENT);let h=a.nextNode();for(;h;)this._matchLeaves(s,h,c)&&u.add(h),h=a.nextNode()}}}else switch(f){case"+":{const n=e.previousElementSibling;n&&this._matchLeaves(s,n,c)&&u.add(n);break}case"~":{const n=this.#e.createTreeWalker(e.parentNode,o.SHOW_ELEMENT);let t=n.firstChild();for(;t&&t!==e;)this._matchLeaves(s,t,c)&&u.add(t),t=n.nextSibling();break}case">":{const n=e.parentNode;n&&this._matchLeaves(s,n,c)&&u.add(n);break}case" ":default:{const n=[];let t=e.parentNode;for(;t;)this._matchLeaves(s,t,c)&&n.push(t),t=t.parentNode;n.length&&(u=new Set(n.reverse()))}}return u}_findNode(r,e={}){const{node:c}=e;let i,s=this._traverse(c,this.#r);if(s)for(s.nodeType!==o.ELEMENT_NODE?s=this.#r.nextNode():s===c&&s!==this.#s&&(s=this.#r.nextNode());s;){let f;if(this.#t.nodeType===o.ELEMENT_NODE?s===this.#t?f=!0:f=this.#t.contains(s):f=!0,f&&this._matchLeaves(r,s,{warn:this.#i})){i=s;break}s=this.#r.nextNode()}return i??null}_findEntryNodes(r,e,c){const{leaves:i}=r,[s,...f]=i,{type:b}=s,u=(0,S.unescapeSelector)(s.name),n=f.length>0;let t=[],a=!1,h=!1;if(e===B)this._matchLeaves(i,this.#t,{warn:this.#i})&&(t.push(this.#t),a=!0);else if(e===j){let l=this.#t;for(;l&&!(this._matchLeaves(i,l,{warn:this.#i})&&(t.push(l),a=!0,!c));)l=l.parentNode}else switch(b){case o.SELECTOR_PSEUDO_ELEMENT:{(0,D.matchPseudoElementSelector)(u,{warn:this.#i});break}case o.SELECTOR_ID:{if(e===C&&this.#s.nodeType!==o.ELEMENT_NODE){const l=this.#s.getElementById(u);l&&(n?this._matchLeaves(f,l,{warn:this.#i})&&t.push(l):t.push(l),a=!0)}else h=!0;break}case o.SELECTOR_CLASS:{if(e===C){const l=this._findNode(i,{node:this.#t});l&&(t.push(l),a=!0)}else if(this.#s.nodeType===o.DOCUMENT_NODE){const l=this.#s.getElementsByClassName(u),p=l.length;if(p)if(this.#t.nodeType===o.ELEMENT_NODE)for(let m=0;m<p;m++){const g=l[m];(g===this.#t||(0,A.isInclusive)(g,this.#t))&&(n?this._matchLeaves(f,g,{warn:this.#i})&&(t.push(g),a=!0):(t.push(g),a=!0))}else t=[].slice.call(l),n||(a=!0)}else h=!0;break}case o.SELECTOR_TYPE:{if(e===C){const l=this._findNode(i,{node:this.#t});l&&(t.push(l),a=!0)}else if(this.#e.contentType==="text/html"&&this.#s.nodeType===o.DOCUMENT_NODE&&!/[*|]/.test(u)){const l=this.#s.getElementsByTagName(u),p=l.length;if(p)if(this.#t.nodeType===o.ELEMENT_NODE)for(let m=0;m<p;m++){const g=l[m];(g===this.#t||(0,A.isInclusive)(g,this.#t))&&(n?this._matchLeaves(f,g,{warn:this.#i})&&(t.push(g),a=!0):(t.push(g),a=!0))}else t=[].slice.call(l),n||(a=!0)}else h=!0;break}default:if(o.REG_SHADOW_HOST.test(u)){if(this.#f&&this.#t.nodeType===o.DOCUMENT_FRAGMENT_NODE){const l=this._matchShadowHostPseudoClass(s,this.#t);l&&t.push(l)}}else if(e===C){const l=this._findNode(i,{node:this.#t});l&&(t.push(l),a=!0)}else h=!0}return{compound:n,filtered:a,nodes:t,pending:h}}_getEntryTwig(r,e){const c=r.length,i=c>1,s=r[0];let f,b;if(i){const{combo:u,leaves:[{name:n,type:t}]}=s,a=r[c-1],{leaves:[{name:h,type:l}]}=a;if(l===o.SELECTOR_PSEUDO_ELEMENT||l===o.SELECTOR_ID)f=$,b=a;else if(t===o.SELECTOR_PSEUDO_ELEMENT||t===o.SELECTOR_ID)f=O,b=s;else if(e===L)if(n==="*"&&t===o.SELECTOR_TYPE)f=$,b=a;else if(h==="*"&&l===o.SELECTOR_TYPE)f=O,b=s;else if(c===2){const{name:p}=u;/^[+~]$/.test(p)?(f=$,b=a):(f=O,b=s)}else f=O,b=s;else if(h==="*"&&l===o.SELECTOR_TYPE)f=O,b=s;else if(n==="*"&&t===o.SELECTOR_TYPE)f=$,b=a;else{let p,m;for(const{combo:g,leaves:[N]}of r){const{type:y}=N,d=(0,S.unescapeSelector)(N.name);if(y===o.SELECTOR_PSEUDO_CLASS&&d==="dir"){p=!1;break}if(g&&!m){const{name:k}=g;/^[+~]$/.test(k)&&(p=!0,m=!0)}}p?(f=O,b=s):(f=$,b=a)}}else f=$,b=s;return{complex:i,dir:f,twig:b}}_collectNodes(r){const e=this.#a.values();if(r===L||r===C){const c=new Set;let i=0;for(const{branch:s}of e){const{complex:f,dir:b,twig:u}=this._getEntryTwig(s,r),{compound:n,filtered:t,nodes:a,pending:h}=this._findEntryNodes(u,r,f);a.length?(this.#a[i].find=!0,this.#n[i]=a):h&&c.add(new Map([["index",i],["twig",u]])),this.#a[i].dir=b,this.#a[i].filtered=t||!n,i++}if(c.size){let s,f;this.#t!==this.#s&&this.#t.nodeType===o.ELEMENT_NODE?(s=this.#t,f=this.#r):(s=this.#s,f=this.#h);let b=this._traverse(s,f);for(;b;){let u=!1;if(this.#t.nodeType===o.ELEMENT_NODE?b===this.#t?u=!0:u=this.#t.contains(b):u=!0,u)for(const n of c){const{leaves:t}=n.get("twig");if(this._matchLeaves(t,b,{warn:this.#i})){const h=n.get("index");this.#a[h].filtered=!0,this.#a[h].find=!0,this.#n[h].push(b)}}b=f.nextNode()}}}else{let c=0;for(const{branch:i}of e){const s=i[i.length-1],f=i.length>1,{compound:b,filtered:u,nodes:n}=this._findEntryNodes(s,r,f);n.length&&(this.#a[c].find=!0,this.#n[c]=n),this.#a[c].dir=$,this.#a[c].filtered=u||!b,c++}}return[this.#a,this.#n]}_matchNodes(r){const[...e]=this.#a,c=e.length;let i=new Set;for(let s=0;s<c;s++){const{branch:f,dir:b,filtered:u,find:n}=e[s],t=f.length;if(t&&n){const a=this.#n[s],h=a.length,l=t-1;if(l===0){const{leaves:[,...p]}=f[0];if((r===L||r===C)&&this.#t.nodeType===o.ELEMENT_NODE)for(let m=0;m<h;m++){const g=a[m];if((u||this._matchLeaves(p,g,{warn:this.#i}))&&g!==this.#t&&this.#t.contains(g)&&(i.add(g),r!==L))break}else if(p.length)for(let m=0;m<h;m++){const g=a[m];if((u||this._matchLeaves(p,g,{warn:this.#i}))&&(i.add(g),r!==L))break}else if(r===L)if(i.size){const m=[...i];i=new Set([...m,...a]),this.#c=!0}else i=new Set([...a]);else{const[m]=[...a];i.add(m)}}else if(b===O){let{combo:p,leaves:m}=f[0];const[,...g]=m;let N;for(let y=0;y<h;y++){const d=a[y];if(u||this._matchLeaves(g,d,{warn:this.#i})){let w=new Set([d]);for(let _=1;_<t;_++){const{combo:E,leaves:x}=f[_],v=[];for(const R of w){const M={combo:p,leaves:x},z=this._matchCombinator(M,R,{dir:b,warn:this.#i});z.size&&v.push(...z)}if(v.length)if(_===l){if(r===L){if(i.size){const R=[...i];i=new Set([...R,...v])}else i=new Set([...v]);this.#c=!0}else{const[R]=(0,A.sortNodes)(v);i.add(R)}N=!0}else p=E,w=new Set(v),N=!1;else{N=!1;break}}}else N=!1;if(N&&r!==L)break}if(!N&&r===C){const[y]=[...a];let d=this._findNode(m,{node:y});for(;d;){let k=new Set([d]);for(let w=1;w<t;w++){const{combo:_,leaves:E}=f[w],x=[];for(const v of k){const R={combo:p,leaves:E},M=this._matchCombinator(R,v,{dir:b,warn:this.#i});M.size&&x.push(...M)}if(x.length)if(w===l){const[v]=(0,A.sortNodes)(x);i.add(v),N=!0}else p=_,k=new Set(x),N=!1;else{N=!1;break}}if(N)break;d=this._findNode(m,{node:d}),k=new Set([d])}}}else{const{leaves:p}=f[l],[,...m]=p;let g;for(let N=0;N<h;N++){const y=a[N];if(u||this._matchLeaves(m,y,{warn:this.#i})){let k=new Set([y]);for(let w=l-1;w>=0;w--){const _=f[w],E=[];for(const x of k){const v=this._matchCombinator(_,x,{dir:b,warn:this.#i});v.size&&E.push(...v)}if(E.length)w===0?(i.add(y),g=!0,r===L&&t>1&&i.size>1&&(this.#c=!0)):(k=new Set(E),g=!1);else{g=!1;break}}}if(g&&r!==L)break}if(!g&&r===C){const[N]=[...a];let y=this._findNode(p,{node:N});for(;y;){let d=new Set([y]);for(let k=l-1;k>=0;k--){const w=f[k],_=[];for(const E of d){const x=this._matchCombinator(w,E,{dir:b,warn:this.#i});x.size&&_.push(...x)}if(_.length)k===0?(i.add(y),g=!0):(d=new Set(_),g=!1);else{g=!1;break}}if(g)break;y=this._findNode(p,{node:y}),d=new Set([y])}}}}}return i}_find(r,e,c,i){if(this._setup(e,c,i),r===L||r===C)this.#h=this.#e.createTreeWalker(this.#s,U),this.#r=this.#e.createTreeWalker(this.#t,U),this.#c=!1;else if(e.nodeType!==o.ELEMENT_NODE){const f=`Unexpected node ${e.nodeName}`;throw new TypeError(f)}return this._collectNodes(r),this._matchNodes(r)}matches(r,e,c){let i;try{const s=this._find(B,r,e,c);s.size&&(i=s.has(this.#t))}catch(s){this._onError(s)}return!!i}closest(r,e,c){let i;try{const s=this._find(j,r,e,c);let f=this.#t;for(;f;){if(s.has(f)){i=f;break}f=f.parentNode}}catch(s){this._onError(s)}return i??null}querySelector(r,e,c){let i;try{const s=this._find(C,r,e,c);s.delete(this.#t),s.size&&([i]=(0,A.sortNodes)(s))}catch(s){this._onError(s)}return i??null}querySelectorAll(r,e,c){let i;try{const s=this._find(L,r,e,c);s.delete(this.#t),s.size&&(this.#c?i=(0,A.sortNodes)(s):i=[...s])}catch(s){this._onError(s)}return i??[]}}0&&(module.exports={Finder});
|
|
2
|
+
//# sourceMappingURL=finder.js.map
|