@asamuzakjp/dom-selector 4.4.0 → 4.4.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/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 +1 -1
- package/dist/cjs/js/finder.js.map +3 -3
- 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 +6 -2
- package/src/js/constant.js +65 -1
- package/src/js/dom-util.js +4 -5
- package/src/js/finder.js +37 -45
- package/src/js/matcher.js +8 -10
- package/src/js/parser.js +34 -58
- package/types/js/constant.d.ts +43 -1
- package/types/js/parser.d.ts +1 -1
package/dist/cjs/js/constant.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var O=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var H=(s,t)=>{for(var c in t)O(s,c,{get:t[c],enumerable:!0})},f=(s,t,c,P)=>{if(t&&typeof t=="object"||typeof t=="function")for(let E of u(t))!Y.call(s,E)&&E!==c&&O(s,E,{get:()=>t[E],enumerable:!(P=d(t,E))||P.enumerable});return s};var m=s=>f(O({},"__esModule",{value:!0}),s);var vt={};H(vt,{ALPHA_NUM:()=>$,ANB:()=>M,AN_PLUS_B:()=>w,BIT_01:()=>ot,BIT_02:()=>et,BIT_04:()=>st,BIT_08:()=>rt,BIT_16:()=>Et,BIT_32:()=>nt,BIT_FFFF:()=>_t,BIT_HYPHEN:()=>xt,COMBINATOR:()=>X,COMBO_A:()=>R,COMBO_B:()=>S,COMPLEX_A:()=>C,COMPLEX_B:()=>A,COMPLEX_C:()=>N,COMPLEX_D:()=>D,COMPOUND_A:()=>r,COMPOUND_B:()=>T,COMPOUND_C:()=>L,COMPOUND_D:()=>I,DIGIT:()=>p,DOCUMENT_FRAGMENT_NODE:()=>Lt,DOCUMENT_NODE:()=>Ct,DOCUMENT_POSITION_CONTAINED_BY:()=>At,DOCUMENT_POSITION_CONTAINS:()=>St,DOCUMENT_POSITION_PRECEDING:()=>Nt,DUO:()=>ct,ELEMENT_NODE:()=>Tt,EMPTY:()=>h,HEX:()=>pt,IDENTIFIER:()=>g,LANG_PART:()=>G,LOGICAL_COMPLEX_A:()=>U,LOGICAL_COMPLEX_B:()=>F,LOGICAL_COMPOUND:()=>a,LOGICAL_KEY:()=>e,NESTED_LOGICAL_A:()=>l,NESTED_LOGICAL_B:()=>i,NESTED_LOGICAL_C:()=>B,NOT_SUPPORTED_ERR:()=>b,NTH:()=>W,N_ST:()=>n,N_TH:()=>_,RAW:()=>y,REG_ANCHOR:()=>lt,REG_CHILD_INDEXED:()=>at,REG_DIR:()=>it,REG_FORM:()=>Ut,REG_FORM_CTRL:()=>Bt,REG_FORM_VALID:()=>Ft,REG_INTERACT:()=>dt,REG_LANG:()=>ut,REG_LOGICAL_COMPLEX_A:()=>Yt,REG_LOGICAL_COMPLEX_B:()=>Ht,REG_LOGICAL_COMPOUND:()=>ft,REG_LOGICAL_KEY:()=>mt,REG_LOGICAL_PSEUDO:()=>wt,REG_SHADOW_HOST:()=>Xt,REG_SHADOW_MODE:()=>ht,REG_SHADOW_PSEUDO:()=>gt,REG_TYPE_CHECK:()=>bt,REG_TYPE_DATE:()=>Wt,REG_TYPE_RANGE:()=>yt,REG_TYPE_RESET:()=>Kt,REG_TYPE_SUBMIT:()=>kt,REG_TYPE_TEXT:()=>Zt,SELECTOR:()=>K,SELECTOR_ATTR:()=>k,SELECTOR_CLASS:()=>Z,SELECTOR_ID:()=>v,SELECTOR_LIST:()=>z,SELECTOR_PSEUDO_CLASS:()=>V,SELECTOR_PSEUDO_ELEMENT:()=>j,SELECTOR_TYPE:()=>q,SHOW_ALL:()=>It,SHOW_DOCUMENT:()=>Dt,SHOW_DOCUMENT_FRAGMENT:()=>Pt,SHOW_ELEMENT:()=>Gt,STRING:()=>J,SUB_TYPE:()=>x,SYNTAX_ERR:()=>Q,TAG_TYPE:()=>o,TEXT_NODE:()=>Rt,TYPE_FROM:()=>Ot,TYPE_TO:()=>$t,U_FFFD:()=>tt,WALKER_FILTER:()=>Mt});module.exports=m(vt);const w="AnPlusB",X="Combinator",h="__EMPTY__",g="Identifier",b="NotSupportedError",W="Nth",y="Raw",K="Selector",k="AttributeSelector",Z="ClassSelector",v="IdSelector",z="SelectorList",V="PseudoClassSelector",j="PseudoElementSelector",q="TypeSelector",J="String",Q="SyntaxError",tt="\uFFFD",ot=1,et=2,st=4,rt=8,Et=16,nt=32,_t=65535,xt=45,ct=2,pt=16,Ot=8,$t=-1,Tt=1,Rt=3,Ct=9,Lt=11,Nt=2,St=8,At=16,It=4294967295,Dt=256,Pt=1024,Gt=1,Mt=1281,$="[A-Z\\d]+",G=`(?:-${$})*`,n="(?:first|last|only)-(?:child|of-type)",p="(?:0|[1-9]\\d*)",M=`[+-]?(?:${p}n?|n)|(?:[+-]?${p})?n\\s*[+-]\\s*${p}`,_=`nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${M})\\s*\\)`,e="(?:is|not|where)",x="\\[[^\\]]+\\]|[#.:][\\w-]+",o="\\*|[A-Za-z][\\w-]*",r=`(?:${o}|(?:${o})?(?:${x})+)`,l=`:${e}\\(\\s*${r}(?:\\s*,\\s*${r})*\\s*\\)`,T=`(?:${o}|(?:${o})?(?:${x}|${l})+)`,a=`${e}\\(\\s*${T}(?:\\s*,\\s*${T})*\\s*\\)`,R="\\s?[\\s>~+]\\s?",C=`${r}(?:${R}${r})*`,i=`:${e}\\(\\s*${C}(?:\\s*,\\s*${C})*\\s*\\)`,L=`(?:${o}|(?:${o})?(?:${x}|${i})+)`,N=`${L}(?:${R}${L})*`,U=`${e}\\(\\s*${N}(?:\\s*,\\s*${N})*\\s*\\)`,S="\\s?[~+]\\s?",A=`${r}(?:${S}${r})*`,B=`:${e}\\(\\s*${A}(?:\\s*,\\s*${A})*\\s*\\)`,I=`(?:${o}|(?:${o})?(?:${x}|${B})+)`,D=`${I}(?:${S}${I})*`,F=`${e}\\(\\s*${D}(?:\\s*,\\s*${D})*\\s*\\)`,lt=/^a(?:rea)?$/,at=new RegExp(`:(?!${n}|${_})`),it=/^(?:ltr|rtl)$/,Ut=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/,Bt=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,Ft=/^(?:button|form|input|select|textarea)$/,dt=/^(?:details|dialog)$/,ut=new RegExp(`^(?:\\*-)?${$}${G}$`,"i"),Yt=new RegExp(`:(?!${n}|${_}|${U})`),Ht=new RegExp(`:(?!${n}|${_}|${F})`),ft=new RegExp(`:(?!${n}|${_}|${a})`),mt=new RegExp(`:${e}\\(`),wt=/^(?:has|is|not|where)$/,Xt=/^host(?:-context)?$/,ht=/^(?:close|open)$/,gt=/^part|slotted$/,bt=/^(?:checkbox|radio)$/,Wt=/^(?:date(?:time-local)?|month|time|week)$/,yt=/(?:date(?:time-local)?|month|number|range|time|week)$/,Kt=/^(?:button|reset)$/,kt=/^(?:image|submit)$/,Zt=/^(?:email|number|password|search|tel|text|url)$/;0&&(module.exports={ALPHA_NUM,ANB,AN_PLUS_B,BIT_01,BIT_02,BIT_04,BIT_08,BIT_16,BIT_32,BIT_FFFF,BIT_HYPHEN,COMBINATOR,COMBO_A,COMBO_B,COMPLEX_A,COMPLEX_B,COMPLEX_C,COMPLEX_D,COMPOUND_A,COMPOUND_B,COMPOUND_C,COMPOUND_D,DIGIT,DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_PRECEDING,DUO,ELEMENT_NODE,EMPTY,HEX,IDENTIFIER,LANG_PART,LOGICAL_COMPLEX_A,LOGICAL_COMPLEX_B,LOGICAL_COMPOUND,LOGICAL_KEY,NESTED_LOGICAL_A,NESTED_LOGICAL_B,NESTED_LOGICAL_C,NOT_SUPPORTED_ERR,NTH,N_ST,N_TH,RAW,REG_ANCHOR,REG_CHILD_INDEXED,REG_DIR,REG_FORM,REG_FORM_CTRL,REG_FORM_VALID,REG_INTERACT,REG_LANG,REG_LOGICAL_COMPLEX_A,REG_LOGICAL_COMPLEX_B,REG_LOGICAL_COMPOUND,REG_LOGICAL_KEY,REG_LOGICAL_PSEUDO,REG_SHADOW_HOST,REG_SHADOW_MODE,REG_SHADOW_PSEUDO,REG_TYPE_CHECK,REG_TYPE_DATE,REG_TYPE_RANGE,REG_TYPE_RESET,REG_TYPE_SUBMIT,REG_TYPE_TEXT,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,SUB_TYPE,SYNTAX_ERR,TAG_TYPE,TEXT_NODE,TYPE_FROM,TYPE_TO,U_FFFD,WALKER_FILTER});
|
|
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
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,eAAAE,EAAA,cAAAC,EAAA,WAAAC,
|
|
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", "EMPTY", "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", "WALKER_FILTER", "__toCommonJS"]
|
|
4
|
+
"sourcesContent": ["/**\n * constant.js\n */\n\n/* string */\nexport const AN_PLUS_B = 'AnPlusB';\nexport const COMBINATOR = 'Combinator';\nexport const EMPTY = '__EMPTY__';\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;\nexport const WALKER_FILTER = 0x501;\n\n/* selectors */\nexport const ALPHA_NUM = '[A-Z\\\\d]+';\nexport const LANG_PART = `(?:-${ALPHA_NUM})*`;\nexport const N_ST = '(?:first|last|only)-(?:child|of-type)';\nexport const DIGIT = '(?:0|[1-9]\\\\d*)';\nexport const ANB =\n `[+-]?(?:${DIGIT}n?|n)|(?:[+-]?${DIGIT})?n\\\\s*[+-]\\\\s*${DIGIT}`;\n// excludes An+B with selector list, e.g. :nth-child(2n+1 of .foo)\nexport const N_TH =\n `nth-(?:last-)?(?:child|of-type)\\\\(\\\\s*(?:even|odd|${ANB})\\\\s*\\\\)`;\n// excludes :has()\nexport const LOGICAL_KEY = '(?:is|not|where)';\n// attr, id, class, pseudo-class\nexport const SUB_TYPE = '\\\\[[^\\\\]]+\\\\]|[#.:][\\\\w-]+';\n// *, tag\nexport const TAG_TYPE = '\\\\*|[A-Za-z][\\\\w-]*';\nexport const COMPOUND_A = `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE})+)`;\nexport const NESTED_LOGICAL_A =\n `:${LOGICAL_KEY}\\\\(\\\\s*${COMPOUND_A}(?:\\\\s*,\\\\s*${COMPOUND_A})*\\\\s*\\\\)`;\nexport const COMPOUND_B =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_A})+)`;\nexport const LOGICAL_COMPOUND =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPOUND_B}(?:\\\\s*,\\\\s*${COMPOUND_B})*\\\\s*\\\\)`;\nexport const COMBO_A = '\\\\s?[\\\\s>~+]\\\\s?';\nexport const COMPLEX_A = `${COMPOUND_A}(?:${COMBO_A}${COMPOUND_A})*`;\nexport const NESTED_LOGICAL_B =\n `:${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_A}(?:\\\\s*,\\\\s*${COMPLEX_A})*\\\\s*\\\\)`;\nexport const COMPOUND_C =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_B})+)`;\nexport const COMPLEX_C = `${COMPOUND_C}(?:${COMBO_A}${COMPOUND_C})*`;\nexport const LOGICAL_COMPLEX_A =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_C}(?:\\\\s*,\\\\s*${COMPLEX_C})*\\\\s*\\\\)`;\nexport const COMBO_B = '\\\\s?[~+]\\\\s?';\nexport const COMPLEX_B = `${COMPOUND_A}(?:${COMBO_B}${COMPOUND_A})*`;\nexport const NESTED_LOGICAL_C =\n `:${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_B}(?:\\\\s*,\\\\s*${COMPLEX_B})*\\\\s*\\\\)`;\nexport const COMPOUND_D =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_C})+)`;\nexport const COMPLEX_D = `${COMPOUND_D}(?:${COMBO_B}${COMPOUND_D})*`;\nexport const LOGICAL_COMPLEX_B =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_D}(?:\\\\s*,\\\\s*${COMPLEX_D})*\\\\s*\\\\)`;\n\n/* regexp */\nexport const REG_ANCHOR = /^a(?:rea)?$/;\nexport const REG_CHILD_INDEXED = new RegExp(`:(?!${N_ST}|${N_TH})`);\nexport const REG_DIR = /^(?:ltr|rtl)$/;\nexport const REG_FORM = /^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;\nexport const REG_FORM_CTRL =\n /^(?:button|fieldset|input|optgroup|option|select|textarea)$/;\nexport const REG_FORM_VALID = /^(?:button|form|input|select|textarea)$/;\nexport const REG_INTERACT = /^(?:details|dialog)$/;\nexport const REG_LANG = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');\nexport const REG_LOGICAL_COMPLEX_A =\n new RegExp(`:(?!${N_ST}|${N_TH}|${LOGICAL_COMPLEX_A})`);\nexport const REG_LOGICAL_COMPLEX_B =\n new RegExp(`:(?!${N_ST}|${N_TH}|${LOGICAL_COMPLEX_B})`);\nexport const REG_LOGICAL_COMPOUND =\n new RegExp(`:(?!${N_ST}|${N_TH}|${LOGICAL_COMPOUND})`);\nexport const REG_LOGICAL_KEY = new RegExp(`:${LOGICAL_KEY}\\\\(`);\nexport const REG_LOGICAL_PSEUDO = /^(?:has|is|not|where)$/;\nexport const REG_SHADOW_HOST = /^host(?:-context)?$/;\nexport const REG_SHADOW_MODE = /^(?:close|open)$/;\nexport const REG_SHADOW_PSEUDO = /^part|slotted$/;\nexport const REG_TYPE_CHECK = /^(?:checkbox|radio)$/;\nexport const REG_TYPE_DATE = /^(?:date(?:time-local)?|month|time|week)$/;\nexport const REG_TYPE_RANGE =\n /(?:date(?:time-local)?|month|number|range|time|week)$/;\nexport const REG_TYPE_RESET = /^(?:button|reset)$/;\nexport const REG_TYPE_SUBMIT = /^(?:image|submit)$/;\nexport const REG_TYPE_TEXT = /^(?:email|number|password|search|tel|text|url)$/;\n"],
|
|
5
|
+
"mappings": "4ZAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,eAAAE,EAAA,QAAAC,EAAA,cAAAC,EAAA,WAAAC,GAAA,WAAAC,GAAA,WAAAC,GAAA,WAAAC,GAAA,WAAAC,GAAA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YAC9CH,EAAU,eACVE,EAAY,GAAGG,CAAU,MAAML,CAAO,GAAGK,CAAU,KACnDsB,EACX,IAAIH,CAAW,UAAUtB,CAAS,eAAeA,CAAS,YAC/CM,EACX,MAAM8D,CAAQ,OAAOA,CAAQ,QAAQF,CAAQ,IAAIzC,CAAgB,MACtDvB,EAAY,GAAGI,CAAU,MAAMR,CAAO,GAAGQ,CAAU,KACnDc,EACX,GAAGE,CAAW,UAAUpB,CAAS,eAAeA,CAAS,YAG9C6B,GAAa,cACbC,GAAoB,IAAI,OAAO,OAAOJ,CAAI,IAAIC,CAAI,GAAG,EACrDI,GAAU,gBACVC,GAAW,qDACXC,GACX,8DACWC,GAAiB,0CACjBC,GAAe,uBACfC,GAAW,IAAI,OAAO,aAAarD,CAAS,GAAGiC,CAAS,IAAK,GAAG,EAChEqB,GACX,IAAI,OAAO,OAAOX,CAAI,IAAIC,CAAI,IAAIV,CAAiB,GAAG,EAC3CqB,GACX,IAAI,OAAO,OAAOZ,CAAI,IAAIC,CAAI,IAAIT,CAAiB,GAAG,EAC3CqB,GACX,IAAI,OAAO,OAAOb,CAAI,IAAIC,CAAI,IAAIR,CAAgB,GAAG,EAC1CqB,GAAkB,IAAI,OAAO,IAAIpB,CAAW,KAAK,EACjDqB,GAAqB,yBACrBC,GAAkB,sBAClBC,GAAkB,mBAClBC,GAAoB,iBACpBC,GAAiB,uBACjBC,GAAgB,4CAChBC,GACX,wDACWC,GAAiB,qBACjBC,GAAkB,qBAClBC,GAAgB",
|
|
6
|
+
"names": ["constant_exports", "__export", "ALPHA_NUM", "ANB", "AN_PLUS_B", "BIT_01", "BIT_02", "BIT_04", "BIT_08", "BIT_16", "BIT_32", "BIT_FFFF", "BIT_HYPHEN", "COMBINATOR", "COMBO_A", "COMBO_B", "COMPLEX_A", "COMPLEX_B", "COMPLEX_C", "COMPLEX_D", "COMPOUND_A", "COMPOUND_B", "COMPOUND_C", "COMPOUND_D", "DIGIT", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_PRECEDING", "DUO", "ELEMENT_NODE", "EMPTY", "HEX", "IDENTIFIER", "LANG_PART", "LOGICAL_COMPLEX_A", "LOGICAL_COMPLEX_B", "LOGICAL_COMPOUND", "LOGICAL_KEY", "NESTED_LOGICAL_A", "NESTED_LOGICAL_B", "NESTED_LOGICAL_C", "NOT_SUPPORTED_ERR", "NTH", "N_ST", "N_TH", "RAW", "REG_ANCHOR", "REG_CHILD_INDEXED", "REG_DIR", "REG_FORM", "REG_FORM_CTRL", "REG_FORM_VALID", "REG_INTERACT", "REG_LANG", "REG_LOGICAL_COMPLEX_A", "REG_LOGICAL_COMPLEX_B", "REG_LOGICAL_COMPOUND", "REG_LOGICAL_KEY", "REG_LOGICAL_PSEUDO", "REG_SHADOW_HOST", "REG_SHADOW_MODE", "REG_SHADOW_PSEUDO", "REG_TYPE_CHECK", "REG_TYPE_DATE", "REG_TYPE_RANGE", "REG_TYPE_RESET", "REG_TYPE_SUBMIT", "REG_TYPE_TEXT", "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", "SUB_TYPE", "SYNTAX_ERR", "TAG_TYPE", "TEXT_NODE", "TYPE_FROM", "TYPE_TO", "U_FFFD", "WALKER_FILTER", "__toCommonJS"]
|
|
7
7
|
}
|
package/dist/cjs/js/dom-util.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var O=Object.create;var p=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var r in t)p(e,r,{get:t[r],enumerable:!0})},b=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of w(t))!_.call(e,o)&&o!==r&&p(e,o,{get:()=>t[o],enumerable:!(s=k(t,o))||s.enumerable});return e};var R=(e,t,r)=>(r=e!=null?O(C(e)):{},b(t||!e||!e.__esModule?p(r,"default",{value:e,enumerable:!0}):r,e)),v=e=>b(p({},"__esModule",{value:!0}),e);var S={};I(S,{getDirectionality:()=>m,getNamespaceURI:()=>h,getSlottedTextContent:()=>f,isContentEditable:()=>g,isInShadowTree:()=>d,isNamespaceDeclared:()=>U,isPreceding:()=>D,resolveContent:()=>M,sortNodes:()=>P,verifyNode:()=>x});module.exports=v(S);var E=R(require("bidi-js"),1),i=require("./constant.js");const x=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===i.DOCUMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE||e.nodeType===i.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},M=e=>{e=x(e);let t,r;switch(e.nodeType){case i.DOCUMENT_NODE:{t=e,r=e;break}case i.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case i.ELEMENT_NODE:default:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;r=o;break}}const s=t.createTreeWalker(r,i.WALKER_FILTER);return[t,r,s]},d=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:s,mode:o,nodeType:a,parentNode:l}=r;if(s&&o&&a===i.DOCUMENT_FRAGMENT_NODE&&i.REG_SHADOW_MODE.test(o)){t=!0;break}r=l}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&d(e)){const r=e.assignedNodes();if(r.length){for(const s of r)if(t=s.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){const{dir:r,localName:s,parentNode:o}=e,{getEmbeddingLevels:a}=(0,E.default)();if(i.REG_DIR.test(r))t=r;else if(r==="auto"){let l;switch(s){case"input":{!e.type||/^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(e.type)?l=e.value:/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(e.type)&&(t="ltr");break}case"slot":{l=f(e);break}case"textarea":{l=e.value;break}default:{const n=[].slice.call(e.childNodes);for(const c of n){const{dir:u,localName:T,nodeType:N,textContent:y}=c;if(N===i.TEXT_NODE?l=y.trim():N===i.ELEMENT_NODE&&!/^(?:bdi|script|style|textarea)$/.test(T)&&(!u||!i.REG_DIR.test(u))&&(T==="slot"?l=f(c):l=y.trim()),l)break}}}if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:n}=o;n===i.ELEMENT_NODE?t=m(o):(n===i.DOCUMENT_NODE||n===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(s==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(s==="input"&&e.type==="tel")t="ltr";else if(o){if(s==="slot"){const l=f(e);if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=o;l===i.ELEMENT_NODE?t=m(o):(l===i.DOCUMENT_NODE||l===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},g=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let s=e.parentNode;for(;s;){if(g(s)){t=!0;break}s=s.parentNode}}}}return!!t},h=(e,t)=>{let r;if(e&&typeof e=="string"&&t?.nodeType===i.ELEMENT_NODE){const{attributes:s}=t;for(const o of s){const{name:a,namespaceURI:l,prefix:n,value:c}=o;if(a===`xmlns:${e}`){r=c;break}else if(n===e){r=l;break}}}return r??null},U=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===i.ELEMENT_NODE&&(r=t.lookupNamespaceURI(e),!r)){const s=t.ownerDocument.documentElement;let o=t;for(;o&&(r=h(e,o),!(r||o===s));)o=o.parentNode}return!!r},D=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_PRECEDING||s&i.DOCUMENT_POSITION_CONTAINS}return!!r},P=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,s)=>{let o;return D(s,r)?o=1:o=-1,o}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isInShadowTree,isNamespaceDeclared,isPreceding,resolveContent,sortNodes,verifyNode});
|
|
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_PRECEDING, ELEMENT_NODE, REG_SHADOW_MODE, TEXT_NODE,\n TYPE_FROM, TYPE_TO, WALKER_FILTER\n} from './constant.js';\n\n/**\n * verify node\n * @param {*} node - node\n * @throws\n * @returns {object} - Document, DocumentFragment, Element node\n */\nexport const verifyNode = node => {\n if (!node || !node.nodeType || !node.nodeName) {\n const type = 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 return node;\n};\n\n/**\n * resolve content document, root node and tree walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of document, root node, tree walker\n */\nexport const resolveContent = node => {\n node = verifyNode(node);\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE:\n 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 const tree = document.createTreeWalker(root, WALKER_FILTER);\n return [\n document,\n root,\n tree\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 || /^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(node.type)) {\n text = node.value;\n } else if (/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(node.type)) {\n res = 'ltr';\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|script|style|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 * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n let res;\n if (ns && typeof ns === 'string' && node?.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\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 res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\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)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n"],
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,oBAAAC,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,cAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAZ,GAKA,IAAAa,EAAwB,wBAGxBC,EAIO,yBAQA,MAAMH,EAAaI,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AAIZ,EAAK,YAAc,QAAUT,EAAeS,CAAI,EAAG,CACrD,MAAMa,EAAQb,EAAK,cAAc,EACjC,GAAIa,EAAM,QACR,UAAWC,KAAQD,EAEjB,GADAD,EAAME,EAAK,YAAY,KAAK,EACxBF,EACF,WAIJA,EAAMZ,EAAK,YAAY,KAAK,CAEhC,CACA,OAAOY,GAAO,IAChB,EAQazB,EAAoB,CAACa,EAAO,CAAC,IAAM,CAC9C,IAAIY,EACJ,GAAIZ,EAAK,WAAa,eAAc,CAClC,KAAM,CAAE,IAAKe,EAAS,UAAAC,EAAW,WAAAL,CAAW,EAAIX,EAC1C,CAAE,mBAAAiB,CAAmB,KAAI,EAAAC,SAAY,
|
|
6
|
-
"names": ["dom_util_exports", "__export", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isNamespaceDeclared", "isPreceding", "resolveContent", "sortNodes", "verifyNode", "__toCommonJS", "import_bidi_js", "import_constant", "node", "msg", "document", "root", "parent", "tree", "bool", "refNode", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "getEmbeddingLevels", "bidiFactory", "
|
|
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_PRECEDING, ELEMENT_NODE, REG_DIR, REG_SHADOW_MODE,\n TEXT_NODE, TYPE_FROM, TYPE_TO, WALKER_FILTER\n} from './constant.js';\n\n/**\n * verify node\n * @param {*} node - node\n * @throws\n * @returns {object} - Document, DocumentFragment, Element node\n */\nexport const verifyNode = node => {\n if (!node || !node.nodeType || !node.nodeName) {\n const type = 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 return node;\n};\n\n/**\n * resolve content document, root node and tree walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of document, root node, tree walker\n */\nexport const resolveContent = node => {\n node = verifyNode(node);\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE:\n 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 const tree = document.createTreeWalker(root, WALKER_FILTER);\n return [\n document,\n root,\n tree\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 if (REG_DIR.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(node.type)) {\n text = node.value;\n } else if (/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(node.type)) {\n res = 'ltr';\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|script|style|textarea)$/.test(itemLocalName) &&\n (!itemDir || !REG_DIR.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 * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n let res;\n if (ns && typeof ns === 'string' && node?.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\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 res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\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)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n"],
|
|
5
|
+
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,oBAAAC,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,cAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAZ,GAKA,IAAAa,EAAwB,wBAGxBC,EAIO,yBAQA,MAAMH,EAAaI,GAAQ,CAChC,GAAI,CAACA,GAAQ,CAACA,EAAK,UAAY,CAACA,EAAK,SAAU,CAE7C,MAAMC,EAAM,mBADC,OAAO,UAAU,SAAS,KAAKD,CAAI,EAAE,MAAM,YAAW,SAAO,CACvC,GACnC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wB,EAAM,CAAC,GAAGxB,CAAK,EACrB,OAAIwB,EAAI,OAAS,GACfA,EAAI,KAAK,CAACC,EAAGC,IAAM,CACjB,IAAI3B,EACJ,OAAInB,EAAY8C,EAAGD,CAAC,EAClB1B,EAAM,EAENA,EAAM,GAEDA,CACT,CAAC,EAEIyB,CACT",
|
|
6
|
+
"names": ["dom_util_exports", "__export", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isNamespaceDeclared", "isPreceding", "resolveContent", "sortNodes", "verifyNode", "__toCommonJS", "import_bidi_js", "import_constant", "node", "msg", "document", "root", "parent", "tree", "bool", "refNode", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "getEmbeddingLevels", "bidiFactory", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "attr", "ns", "attributes", "name", "namespaceURI", "prefix", "value", "nodeA", "nodeB", "posBit", "arr", "a", "b"]
|
|
7
7
|
}
|
package/dist/cjs/js/finder.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var B=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(A,a)=>{for(var e in a)I(A,e,{get:a[e],enumerable:!0})},U=(A,a,e,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of G(a))!V.call(A,l)&&l!==e&&I(A,l,{get:()=>a[l],enumerable:!(r=j(a,l))||r.enumerable});return A};var z=(A,a,e)=>(e=A!=null?B(q(A)):{},U(a||!A||!A.__esModule?I(e,"default",{value:A,enumerable:!0}):e,A)),Y=A=>U(I({},"__esModule",{value:!0}),A);var Q={};X(Q,{Finder:()=>K});module.exports=Y(Q);var P=z(require("is-potential-custom-element-name"),1),F=z(require("@asamuzakjp/nwsapi"),1),C=require("./dom-util.js"),$=require("./matcher.js"),x=require("./parser.js"),b=require("./constant.js");const T="next",O="prev",M="all",L="first",R="lineal",D="self";class K{#a;#r;#c;#t;#h;#d;#p;#e;#b;#k;#f;#o;#_;#s;#u;#m;#n;#w;#i;#l;constructor(a){this.#l=a,this.#d=a.document,this.#r=new WeakMap,this.#_=new WeakMap,this.#f=(0,F.default)({document:a.document,DOMException:a.DOMException}),this.#f.configure({LOGERRORS:!1})}_onError(a){if(!this.#k)if(a instanceof DOMException||a instanceof this.#l.DOMException)if(a.name===b.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#l.DOMException(a.message,a.name);else throw a}_setup(a,e,r={}){const{event:l,noexcept:i,warn:c}=r;return this.#k=!!i,this.#i=!!c,this.#p=this._setEvent(l),this.#e=e,[this.#t,this.#s,this.#n]=(0,C.resolveContent)(e),this.#u=(0,C.isInShadowTree)(e),[this.#a,this.#b]=this._correspond(a),this.#w=new WeakMap,e}_setEvent(a){return a instanceof this.#l.MouseEvent||a instanceof this.#l.KeyboardEvent?a:null}_correspond(a){const e=[];this.#c=!1,this.#h=!1;let r;if(this.#t){const l=this.#r.get(this.#t);if(l&&l.has(`${a}`)){const i=l.get(`${a}`);this.#c=i.complex,this.#h=i.descendant,r=i.ast}}if(r){const l=r.length;for(let i=0;i<l;i++)r[i].collected=!1,r[i].dir=null,r[i].filtered=!1,r[i].find=!1,e[i]=[]}else{let l;try{l=(0,x.parseSelector)(a)}catch(f){this._onError(f)}const{branches:i,complex:c}=(0,x.walkAST)(l);let n=!1,d=0;r=[];for(const[...f]of i){const t=[];let s=f.shift();if(s&&s.type!==b.COMBINATOR){const o=new Set;for(;s;){if(s.type===b.COMBINATOR){const[p]=f;if(p.type===b.COMBINATOR){const w=`Invalid selector ${a}`;throw new DOMException(w,b.SYNTAX_ERR)}const _=s.name;/^[\s>]$/.test(_)&&(n=!0),t.push({combo:s,leaves:(0,x.sortAST)(o)}),o.clear()}else if(s){let{name:p}=s;p&&typeof p=="string"&&(p=(0,x.unescapeSelector)(p),typeof p=="string"&&p!==s.name&&(s.name=p),/[|:]/.test(p)&&(s.namespace=!0)),o.add(s)}if(f.length)s=f.shift();else{t.push({combo:null,leaves:(0,x.sortAST)(o)}),o.clear();break}}}r.push({branch:t,collected:!1,dir:null,filtered:!1,find:!1}),e[d]=[],d++}if(this.#t){let f;this.#r.has(this.#t)?f=this.#r.get(this.#t):f=new Map,f.set(`${a}`,{ast:r,complex:c,descendant:n}),this.#r.set(this.#t,f)}this.#c=c,this.#h=n}return[r,e]}_createTreeWalker(a){let e;return this.#w.has(a)?e=this.#w.get(a):(e=this.#d.createTreeWalker(a,b.WALKER_FILTER),this.#w.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#o=this._createTreeWalker(this.#e),this.#m=!1,this.#o}_traverse(a,e=this.#n){let r=e.currentNode,l;if(r===a)l=r;else if(r.contains(a))for(r=e.nextNode();r;){if(r===a){l=r;break}r=e.nextNode()}else{if(r!==e.root)for(;r&&!(r===e.root||r===a);)r=e.parentNode();if(a?.nodeType===b.ELEMENT_NODE)for(;r;){if(r===a){l=r;break}r=e.nextNode()}else l=r}return l??null}_collectNthChild(a,e,r){const{a:l,b:i,reverse:c,selector:n}=a,{parentNode:d}=e,f=new Set;let t;if(n)if(this.#r.has(n))t=this.#r.get(n);else{const{branches:s}=(0,x.walkAST)(n);t=s,this.#r.set(n,t)}if(d){const s=this.#n;let o=this._traverse(d,s);o=s.firstChild();let p=0;for(;o;)p++,o=s.nextSibling();o=this._traverse(d,s);const _=new Set;if(t)for(o=s.firstChild();o;){let w;for(const k of t)if(w=this._matchLeaves(k,o,r),!w)break;w&&_.add(o),o=s.nextSibling()}if(l===0){if(i>0&&i<=p){if(_.size){o=this._traverse(d,s),c?o=s.lastChild():o=s.firstChild();let w=0;for(;o;){if(_.has(o)){if(w===i-1){f.add(o);break}w++}c?o=s.previousSibling():o=s.nextSibling()}}else if(!n){o=this._traverse(d,s),c?o=s.lastChild():o=s.firstChild();let w=0;for(;o;){if(w===i-1){f.add(o);break}c?o=s.previousSibling():o=s.nextSibling(),w++}}}}else{let w=i-1;if(l>0)for(;w<0;)w+=l;if(w>=0&&w<p){o=this._traverse(d,s),c?o=s.lastChild():o=s.firstChild();let k=0,N=l>0?0:i-1;for(;o&&(o&&w>=0&&w<p);)_.size?_.has(o)&&(N===w&&(f.add(o),w+=l),l>0?N++:N--):k===w&&(n||f.add(o),w+=l),c?o=s.previousSibling():o=s.nextSibling(),k++}}if(c&&f.size>1){const w=[...f];return new Set(w.reverse())}}else if(e===this.#s&&l+i===1)if(t){let s;for(const o of t)if(s=this._matchLeaves(o,e,r),s)break;s&&f.add(e)}else f.add(e);return f}_collectNthOfType(a,e){const{a:r,b:l,reverse:i}=a,{localName:c,parentNode:n,prefix:d}=e,f=new Set;if(n){const t=this.#n;let s=this._traverse(n,t);s=t.firstChild();let o=0;for(;s;)o++,s=t.nextSibling();if(r===0){if(l>0&&l<=o){s=this._traverse(n,t),i?s=t.lastChild():s=t.firstChild();let p=0;for(;s;){const{localName:_,prefix:w}=s;if(_===c&&w===d){if(p===l-1){f.add(s);break}p++}i?s=t.previousSibling():s=t.nextSibling()}}}else{let p=l-1;if(r>0)for(;p<0;)p+=r;if(p>=0&&p<o){s=this._traverse(n,t),i?s=t.lastChild():s=t.firstChild();let _=r>0?0:l-1;for(;s;){const{localName:w,prefix:k}=s;if(w===c&&k===d){if(_===p&&(f.add(s),p+=r),p<0||p>=o)break;r>0?_++:_--}i?s=t.previousSibling():s=t.nextSibling()}}}if(i&&f.size>1){const p=[...f];return new Set(p.reverse())}}else e===this.#s&&r+l===1&&f.add(e);return f}_matchAnPlusB(a,e,r,l){const{nth:{a:i,b:c,name:n},selector:d}=a,f=new Map;if(n?(n==="even"?(f.set("a",2),f.set("b",0)):n==="odd"&&(f.set("a",2),f.set("b",1)),r.indexOf("last")>-1&&f.set("reverse",!0)):(typeof i=="string"&&/-?\d+/.test(i)?f.set("a",i*1):f.set("a",0),typeof c=="string"&&/-?\d+/.test(c)?f.set("b",c*1):f.set("b",0),r.indexOf("last")>-1&&f.set("reverse",!0)),/^nth-(?:last-)?child$/.test(r)){d&&f.set("selector",d);const t=Object.fromEntries(f);return this._collectNthChild(t,e,l)}else if(/^nth-(?:last-)?of-type$/.test(r)){const t=Object.fromEntries(f);return this._collectNthOfType(t,e)}return new Set}_matchHasPseudoFunc(a,e,r={}){let l;if(Array.isArray(a)&&a.length){const[i]=a,{type:c}=i;let n;c===b.COMBINATOR?n=a.shift():n={name:" ",type:b.COMBINATOR};const d=[];for(;a.length;){const[s]=a,{type:o}=s;if(o===b.COMBINATOR)break;d.push(a.shift())}const f={combo:n,leaves:d};r.dir=T;const t=this._matchCombinator(f,e,r);if(t.size)if(a.length){for(const s of t)if(l=this._matchHasPseudoFunc(Object.assign([],a),s,r),l)break}else l=!0}return!!l}_matchLogicalPseudoFunc(a,e,r={}){const{astName:l="",branches:i=[],selector:c="",twigBranches:n=[]}=a;let d;if(l==="has")if(c.includes(":has("))d=null;else{let f;for(const t of i)if(f=this._matchHasPseudoFunc(Object.assign([],t),e,r),f)break;f&&(d=e)}else{const f=/^(?:is|where)$/.test(l);r.forgive=f;const t=n.length;let s;for(let o=0;o<t;o++){const p=n[o],_=p.length-1,{leaves:w}=p[_];if(s=this._matchLeaves(w,e,r),s&&_>0){let k=new Set([e]);for(let N=_-1;N>=0;N--){const g=p[N],h=[];r.dir=O;for(const m of k){const u=this._matchCombinator(g,m,r);u.size&&h.push(...u)}if(h.length)N===0?s=!0:k=new Set(h);else{s=!1;break}}}if(s)break}l==="not"?s||(d=e):s&&(d=e)}return d??null}_matchPseudoClassSelector(a,e,r={}){const{children:l,name:i}=a,{localName:c,parentNode:n}=e,{forgive:d,warn:f=this.#i}=r,t=new Set;if(b.REG_LOGICAL_PSEUDO.test(i)){let s;if(this.#r.has(a))s=this.#r.get(a);else{const{branches:p}=(0,x.walkAST)(a),_=[],w=[];for(const[...k]of p){for(const m of k){const u=(0,x.generateCSS)(m);_.push(u)}const N=[],g=new Set;let h=k.shift();for(;h;)if(h.type===b.COMBINATOR?(N.push({combo:h,leaves:[...g]}),g.clear()):h&&g.add(h),k.length)h=k.shift();else{N.push({combo:null,leaves:[...g]}),g.clear();break}w.push(N)}s={astName:i,branches:p,twigBranches:w,selector:_.join(",")},this.#r.set(a,s)}const o=this._matchLogicalPseudoFunc(s,e,r);o&&t.add(o)}else if(Array.isArray(l))if(/^nth-(?:last-)?(?:child|of-type)$/.test(i)){const[s]=l;return this._matchAnPlusB(s,e,i,r)}else switch(i){case"dir":case"lang":{const s=$.matcher.matchSelector(a,e);s&&t.add(s);break}case"current":case"nth-col":case"nth-last-col":{if(f){const s=`Unsupported pseudo-class :${i}()`;throw new DOMException(s,b.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!d){const s=`Unknown pseudo-class :${i}()`;throw new DOMException(s,b.SYNTAX_ERR)}}else{const s=/^a(?:rea)?$/,o=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,p=/^(?:button|form|input|select|textarea)$/,_=/^(?:details|dialog)$/,w=/^(?:checkbox|radio)$/,k=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:date(?:time-local)?|month|number|range|time|week)$/,g=/^(?:email|number|password|search|tel|text|url)$/;switch(i){case"any-link":case"link":{s.test(c)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(s.test(c)&&e.hasAttribute("href")){const{href:h,origin:m,pathname:u}=new URL(this.#t.URL),y=new URL(e.getAttribute("href"),h);y.origin===m&&y.pathname===u&&t.add(e)}break}case"visited":break;case"hover":{const{target:h,type:m}=this.#p??{};(m==="mouseover"||m==="pointerover")&&e.contains(h)&&t.add(e);break}case"active":{const{buttons:h,target:m,type:u}=this.#p??{};(u==="mousedown"||u==="pointerdown")&&h&b.BIT_01&&e.contains(m)&&t.add(e);break}case"target":{const{hash:h}=new URL(this.#t.URL);e.id&&h===`#${e.id}`&&this.#t.contains(e)&&t.add(e);break}case"target-within":{const{hash:h}=new URL(this.#t.URL);if(h){const m=h.replace(/^#/,"");let u=this.#t.getElementById(m);for(;u;){if(u===e){t.add(e);break}u=u.parentNode}}break}case"scope":{this.#e.nodeType===b.ELEMENT_NODE?!this.#u&&e===this.#e&&t.add(e):e===this.#t.documentElement&&t.add(e);break}case"focus":case"focus-visible":{const{target:h,type:m}=this.#p??{};if(e===this.#t.activeElement&&e.tabIndex>=0&&(i==="focus"||m==="keydown"&&e.contains(h))){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else{const{display:v,visibility:E}=this.#l.getComputedStyle(u);if(y=!(v==="none"||E==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"focus-within":{let h,m=this.#t.activeElement;if(m.tabIndex>=0)for(;m;){if(m===e){h=!0;break}m=m.parentNode}if(h){let u=e,y=!0;for(;u;){if(u.disabled||u.hasAttribute("disabled")||u.hidden||u.hasAttribute("hidden")){y=!1;break}else{const{display:v,visibility:E}=this.#l.getComputedStyle(u);if(y=!(v==="none"||E==="hidden"),!y)break}if(u.parentNode&&u.parentNode.nodeType===b.ELEMENT_NODE)u=u.parentNode;else break}y&&t.add(e)}break}case"open":{_.test(c)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{_.test(c)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(o.test(c)||(0,P.default)(c))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let h=n;for(;h&&h.localName!=="fieldset";)h=h.parentNode;h&&n.localName!=="legend"&&h.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(o.test(c)||(0,P.default)(c))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(c){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||k.test(e.type)||g.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(c){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||k.test(e.type)||g.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,C.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let h;c==="textarea"?h=e:c==="input"&&(e.hasAttribute("type")?g.test(e.getAttribute("type"))&&(h=e):h=e),h&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&c==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))||e.selected&&c==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&c==="input"&&e.type==="checkbox"||c==="progress"&&!e.hasAttribute("value"))t.add(e);else if(c==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const h=e.name;let m=e.parentNode;for(;m&&m.localName!=="form";)m=m.parentNode;m||(m=this.#t.documentElement);const u=m.getElementsByTagName("input"),y=u.length;let v;for(let E=0;E<y;E++){const S=u[E];if(S.getAttribute("type")==="radio"&&(h?S.getAttribute("name")===h&&(v=!!S.checked):S.hasAttribute("name")||(v=!!S.checked),v))break}v||t.add(e)}break}case"default":{const h=/^(?:button|reset)$/,m=/^(?:image|submit)$/;if(c==="button"&&!(e.hasAttribute("type")&&h.test(e.getAttribute("type")))||c==="input"&&e.hasAttribute("type")&&m.test(e.getAttribute("type"))){let u=e.parentNode;for(;u&&u.localName!=="form";)u=u.parentNode;if(u){const y=this.#n;let v=this._traverse(u,y);for(v=y.firstChild();v&&u.contains(v);){const E=v.localName;let S;if(E==="button"?S=!(v.hasAttribute("type")&&h.test(v.getAttribute("type"))):E==="input"&&(S=v.hasAttribute("type")&&m.test(v.getAttribute("type"))),S){v===e&&t.add(e);break}v=y.nextNode()}}}else if(c==="input"&&e.hasAttribute("type")&&w.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(c==="option"){let u=n,y=!1;for(;u&&u.localName!=="datalist";){if(u.localName==="select"){(u.multiple||u.hasAttribute("multiple"))&&(y=!0);break}u=u.parentNode}if(y)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const v=new Set,E=this.#n;let S=this._traverse(n,E);for(S=E.firstChild();S;){if(S.selected||S.hasAttribute("selected")){v.add(S);break}S=E.nextSibling()}v.size&&v.has(e)&&t.add(e)}}break}case"valid":{if(p.test(c))e.checkValidity()&&t.add(e);else if(c==="fieldset"){const h=this.#n;let m=this._traverse(e,h);m=h.firstChild();let u;for(;m&&e.contains(m)&&!(p.test(m.localName)&&(u=m.checkValidity(),!u));)m=h.nextNode();u&&t.add(e)}break}case"invalid":{if(p.test(c))e.checkValidity()||t.add(e);else if(c==="fieldset"){const h=this.#n;let m=this._traverse(e,h);m=h.firstChild();let u;for(;m&&e.contains(m)&&!(p.test(m.localName)&&(u=m.checkValidity(),!u));)m=h.nextNode();u||t.add(e)}break}case"in-range":{c==="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":{c==="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 h;if(/^(?:select|textarea)$/.test(c))h=e;else if(c==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||w.test(m)||k.test(m)||g.test(m))&&(h=e)}else h=e;h&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let h;if(/^(?:select|textarea)$/.test(c))h=e;else if(c==="input")if(e.hasAttribute("type")){const m=e.getAttribute("type");(m==="file"||w.test(m)||k.test(m)||g.test(m))&&(h=e)}else h=e;h&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===this.#t.documentElement&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const h=this.#d.createTreeWalker(e,b.SHOW_ALL);let m=h.firstChild(),u;for(;m&&(u=m.nodeType!==b.ELEMENT_NODE&&m.nodeType!==b.TEXT_NODE,!!u);)m=h.nextSibling();u&&t.add(e)}else t.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#s)&&t.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#s)&&t.add(e);break}case"first-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"last-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1,reverse:!0},e);h&&t.add(h)}else e===this.#s&&t.add(e);break}case"only-of-type":{if(n){const[h]=this._collectNthOfType({a:0,b:1},e);if(h===e){const[m]=this._collectNthOfType({a:0,b:1,reverse:!0},e);m===e&&t.add(e)}}else e===this.#s&&t.add(e);break}case"defined":{const h=e.getAttribute("is");h?(0,P.default)(h)&&this.#l.customElements.get(h)&&t.add(e):(0,P.default)(c)?this.#l.customElements.get(c)&&t.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&t.add(e);break}case"popover-open":{if(e.popover){const{display:h}=this.#l.getComputedStyle(e);h!=="none"&&t.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(f){const h=`Unsupported pseudo-element ::${i}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":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(f){const h=`Unsupported pseudo-class :${i}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}break}default:if(i.startsWith("-webkit-")){if(f){const h=`Unsupported pseudo-class :${i}`;throw new DOMException(h,b.NOT_SUPPORTED_ERR)}}else if(!d){const h=`Unknown pseudo-class :${i}`;throw new DOMException(h,b.SYNTAX_ERR)}}}return t}_matchShadowHostPseudoClass(a,e){const{children:r,name:l}=a;let i;if(Array.isArray(r)){const{branches:c}=(0,x.walkAST)(r[0]),[n]=c,[...d]=n,{host:f}=e;if(l==="host"){let t;for(const s of d){const{type:o}=s;if(o===b.COMBINATOR){const _=`Invalid selector ${(0,x.generateCSS)(a)}`;throw new DOMException(_,b.SYNTAX_ERR)}if(t=this._matchSelector(s,f).has(f),!t)break}t&&(i=e)}else if(l==="host-context"){let t=f,s;for(;t;){for(const o of d){const{type:p}=o;if(p===b.COMBINATOR){const w=`Invalid selector ${(0,x.generateCSS)(a)}`;throw new DOMException(w,b.SYNTAX_ERR)}if(s=this._matchSelector(o,t).has(t),!s)break}if(s)break;t=t.parentNode}s&&(i=e)}}else if(l==="host")i=e;else{const c=`Invalid selector :${l}`;throw new DOMException(c,b.SYNTAX_ERR)}return i??null}_matchSelector(a,e,r){const{type:l}=a,i=new Set;if(a.name===b.EMPTY)return i;const c=(0,x.unescapeSelector)(a.name);if(typeof c=="string"&&c!==a.name&&(a.name=c),e.nodeType===b.ELEMENT_NODE)switch(l){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(c,r);break}case b.SELECTOR_ID:{e.id===c&&i.add(e);break}case b.SELECTOR_CLASS:{e.classList.contains(c)&&i.add(e);break}case b.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,r);default:{const n=$.matcher.matchSelector(a,e,r);n&&i.add(n)}}else if(this.#u&&l===b.SELECTOR_PSEUDO_CLASS&&e.nodeType===b.DOCUMENT_FRAGMENT_NODE){if(c!=="has"&&b.REG_LOGICAL_PSEUDO.test(c))return this._matchPseudoClassSelector(a,e,r);if(b.REG_SHADOW_HOST.test(c)){const n=this._matchShadowHostPseudoClass(a,e,r);n&&i.add(n)}}return i}_matchLeaves(a,e,r){const{attributes:l,localName:i,nodeType:c}=e;let n=this.#_.get(a),d;if(n&&n.has(e)){const{attr:f,matched:t}=n.get(e);l?.length===f&&(d=t)}if(typeof d!="boolean"){const f=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/;let t;c===b.ELEMENT_NODE&&f.test(i)?t=!1:t=!0;for(const s of a){const{name:o,type:p}=s;if(p===b.SELECTOR_PSEUDO_CLASS&&o==="dir"&&(t=!1),d=this._matchSelector(s,e,r).has(e),!d)break}t&&(n||(n=new WeakMap),n.set(e,{attr:l?.length,matched:d}),this.#_.set(a,n))}return!!d}_matchHTMLCollection(a,e={}){const{compound:r,filterLeaves:l}=e,i=new Set,c=a.length;if(c)if(r)for(let n=0;n<c;n++){const d=a[n];this._matchLeaves(l,d,e)&&i.add(d)}else{const n=[].slice.call(a);return new Set(n)}return i}_findDescendantNodes(a,e,r){const[l,...i]=a,c=i.length>0,{type:n}=l,d=(0,x.unescapeSelector)(l.name);typeof d=="string"&&d!==l.name&&(l.name=d);let f=new Set,t=!1;if(this.#u)t=!0;else switch(n){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,r);break}case b.SELECTOR_ID:{if(this.#s.nodeType===b.ELEMENT_NODE)t=!0;else{const s=this.#s.getElementById(d);s&&s!==e&&e.contains(s)&&(c?this._matchLeaves(i,s,r)&&f.add(s):f.add(s))}break}case b.SELECTOR_CLASS:{const s=e.getElementsByClassName(d);f=this._matchHTMLCollection(s,{compound:c,filterLeaves:i});break}case b.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(d)){const s=e.getElementsByTagName(d);f=this._matchHTMLCollection(s,{compound:c,filterLeaves:i})}else t=!0;break}default:t=!0}return{nodes:f,pending:t}}_matchCombinator(a,e,r={}){const{combo:l,leaves:i}=a,{name:c}=l,{parentNode:n}=e,{dir:d}=r,f=new Set;if(d===T)switch(c){case"+":{const t=e.nextElementSibling;t&&this._matchLeaves(i,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let s=this._traverse(e,t);for(s=t.nextSibling();s;)this._matchLeaves(i,s,r)&&f.add(s),s=t.nextSibling()}break}case">":{const t=this._createTreeWalker(e);let s=this._traverse(e,t);for(s=t.firstChild();s;)this._matchLeaves(i,s,r)&&f.add(s),s=t.nextSibling();break}case" ":default:{const{nodes:t,pending:s}=this._findDescendantNodes(i,e);if(t.size)return t;if(s){const o=this._createTreeWalker(e);let p=this._traverse(e,o);for(p=o.nextNode();p&&e.contains(p);)this._matchLeaves(i,p,r)&&f.add(p),p=o.nextNode()}}}else switch(c){case"+":{const t=e.previousElementSibling;t&&this._matchLeaves(i,t,r)&&f.add(t);break}case"~":{if(n){const t=this._createTreeWalker(n);let s=this._traverse(n,t);for(s=t.firstChild();s&&s!==e;)this._matchLeaves(i,s,r)&&f.add(s),s=t.nextSibling()}break}case">":{n&&this._matchLeaves(i,n,r)&&f.add(n);break}case" ":default:{const t=[];let s=n;for(;s;)this._matchLeaves(i,s,r)&&t.push(s),s=s.parentNode;if(t.length)return new Set(t.reverse())}}return f}_findNode(a,e){const{node:r}=e;let l=this._traverse(r,this.#o),i;if(l)for(l.nodeType!==b.ELEMENT_NODE?l=this.#o.nextNode():l===r&&l!==this.#s&&(l=this.#o.nextNode());l;){if(this._matchLeaves(a,l,{warn:this.#i})){i=l;break}l=this.#o.nextNode()}return i??null}_matchSelf(a){const e=[],r=this._matchLeaves(a,this.#e,{warn:this.#i});let l=!1;return r&&(e.push(this.#e),l=!0),[e,l]}_findLineal(a,e={}){const{complex:r}=e,l=[];let i=this._matchLeaves(a,this.#e,{warn:this.#i}),c=!1;if(i&&(l.push(this.#e),c=!0),!i||r){let n=this.#e.parentNode;for(;n&&(i=this._matchLeaves(a,n,{warn:this.#i}),i&&(l.push(n),c=!0),n.parentNode);)n=n.parentNode}return[l,c]}_findFirst(a){const e=[],r=this._findNode(a,{node:this.#e});let l=!1;return r&&(e.push(r),l=!0),[e,l]}_findFromHTMLCollection(a,e={}){const{complex:r,compound:l,filterLeaves:i,targetType:c}=e;let n=[],d=!1,f=!1;const t=a.length;if(t)if(this.#e.nodeType===b.ELEMENT_NODE)for(let s=0;s<t;s++){const o=a[s];if(o!==this.#e&&(this.#e.contains(o)||o.contains(this.#e))){if(l){if(this._matchLeaves(i,o,{warn:this.#i})&&(n.push(o),d=!0,c===L))break}else if(n.push(o),d=!0,c===L)break}}else if(r)if(l)for(let s=0;s<t;s++){const o=a[s];if(this._matchLeaves(i,o,{warn:this.#i})&&(n.push(o),d=!0,c===L))break}else n=[].slice.call(a),d=!0,f=!0;else if(l)for(let s=0;s<t;s++){const o=a[s];if(this._matchLeaves(i,o,{warn:this.#i})&&(n.push(o),d=!0,c===L))break}else n=[].slice.call(a),d=!0,f=!0;return[n,d,f]}_findEntryNodes(a,e,r){const{leaves:l}=a,[i,...c]=l,n=c.length>0,{name:d,type:f}=i;let t=[],s=!1,o=!1,p=!1;switch(f){case b.SELECTOR_PSEUDO_ELEMENT:{$.matcher.matchPseudoElementSelector(d,{warn:this.#i});break}case b.SELECTOR_ID:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(e===L&&this.#s.nodeType!==b.ELEMENT_NODE){const _=this.#s.getElementById(d);_&&(n?this._matchLeaves(c,_,{warn:this.#i})&&(t.push(_),o=!0):(t.push(_),o=!0))}else e===L?[t,o]=this._findFirst(l):p=!0;break}case b.SELECTOR_CLASS:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(this.#s.nodeType===b.DOCUMENT_NODE){const _=this.#s.getElementsByClassName(d);_.length&&([t,o,s]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:c,targetType:e}))}else e===L?[t,o]=this._findFirst(l):p=!0;break}case b.SELECTOR_TYPE:{if(e===D)[t,o]=this._matchSelf(l);else if(e===R)[t,o]=this._findLineal(l,{complex:r});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===b.DOCUMENT_NODE&&!/[*|]/.test(d)){const _=this.#s.getElementsByTagName(d);_.length&&([t,o,s]=this._findFromHTMLCollection(_,{complex:r,compound:n,filterLeaves:c,targetType:e}))}else e===L?[t,o]=this._findFirst(l):p=!0;break}default:if(e!==R&&b.REG_SHADOW_HOST.test(d)){if(this.#u&&this.#e.nodeType===b.DOCUMENT_FRAGMENT_NODE){const _=this._matchShadowHostPseudoClass(i,this.#e);_&&(t.push(_),o=!0)}}else e===D?[t,o]=this._matchSelf(l):e===R?[t,o]=this._findLineal(l,{complex:r}):e===L?[t,o]=this._findFirst(l):p=!0}return{collected:s,compound:n,filtered:o,nodes:t,pending:p}}_collectNodes(a){const e=this.#a.values();if(a===M||a===L){const r=new Set;let l=0;for(const{branch:i}of e){const c=i.length,n=c>1,d=i[0];let f,t;if(n){const{combo:k,leaves:[{name:N,type:g}]}=d,h=i[c-1],{leaves:[{name:m,type:u}]}=h;if(u===b.SELECTOR_PSEUDO_ELEMENT||u===b.SELECTOR_ID)f=O,t=h;else if(g===b.SELECTOR_PSEUDO_ELEMENT||g===b.SELECTOR_ID)f=T,t=d;else if(a===M)if(N==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else if(m==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(c===2){const{name:y}=k;/^[+~]$/.test(y)?(f=O,t=h):(f=T,t=d)}else f=T,t=d;else if(m==="*"&&u===b.SELECTOR_TYPE)f=T,t=d;else if(N==="*"&&g===b.SELECTOR_TYPE)f=O,t=h;else{let y;for(const{combo:v,leaves:[E]}of i){const{name:S,type:W}=E;if(W===b.SELECTOR_PSEUDO_CLASS&&S==="dir"){y=!1;break}if(!y&&v){const{name:H}=v;/^[+~]$/.test(H)&&(y=!0)}}y?(f=T,t=d):(f=O,t=h)}}else f=O,t=d;const{collected:s,compound:o,filtered:p,nodes:_,pending:w}=this._findEntryNodes(t,a,n);_.length?(this.#a[l].find=!0,this.#b[l]=_):w&&r.add(new Map([["index",l],["twig",t]])),this.#a[l].collected=s,this.#a[l].dir=f,this.#a[l].filtered=p||!o,l++}if(r.size){let i,c;this.#e!==this.#s&&this.#e.nodeType===b.ELEMENT_NODE?(i=this.#e,c=this.#o):(i=this.#s,c=this.#n);let n=this._traverse(i,c);for(;n;){let d=!1;if(this.#e.nodeType===b.ELEMENT_NODE?n===this.#e?d=!0:d=this.#e.contains(n):d=!0,d)for(const f of r){const{leaves:t}=f.get("twig");if(this._matchLeaves(t,n,{warn:this.#i})){const o=f.get("index");this.#a[o].filtered=!0,this.#a[o].find=!0,this.#b[o].push(n)}}n!==c.currentNode&&(n=this._traverse(n,c)),n=c.nextNode()}}}else{let r=0;for(const{branch:l}of e){const i=l[l.length-1],c=l.length>1,{compound:n,filtered:d,nodes:f}=this._findEntryNodes(i,a,c);f.length&&(this.#a[r].find=!0,this.#b[r]=f),this.#a[r].dir=O,this.#a[r].filtered=d||!n,r++}}return[this.#a,this.#b]}_getCombinedNodes(a,e,r){const l=[];for(const i of e){const c=this._matchCombinator(a,i,{dir:r,warn:this.#i});c.size&&l.push(...c)}return l.length?new Set(l):new Set}_matchNodeNext(a,e,r){const{combo:l,index:i}=r,{combo:c,leaves:n}=a[i],d={combo:l,leaves:n},f=this._getCombinedNodes(d,e,T);let t;if(f.size)if(i===a.length-1){const[s]=(0,C.sortNodes)(f);t=s}else t=this._matchNodeNext(a,f,{combo:c,index:i+1});return t??null}_matchNodePrev(a,e,r){const{index:l}=r,i=a[l],c=new Set([e]),n=this._getCombinedNodes(i,c,O);let d;if(n.size){if(l===0)d=e;else for(const f of n)if(this._matchNodePrev(a,f,{index:l-1}))return e}return d??null}_find(a){(a===M||a===L)&&this._prepareQuerySelectorWalker();const[[...e],r]=this._collectNodes(a),l=e.length;let i=new Set;for(let c=0;c<l;c++){const{branch:n,collected:d,dir:f,find:t}=e[c],s=n.length;if(s&&t){const o=r[c],p=o.length,_=s-1;if(_===0)if((a===M||a===L)&&this.#e.nodeType===b.ELEMENT_NODE)for(let w=0;w<p;w++){const k=o[w];if(k!==this.#e&&this.#e.contains(k)&&(i.add(k),a!==M))break}else if(a===M)if(i.size){const w=[...i];i=new Set([...w,...o]),this.#m=!0}else i=new Set(o);else{const[w]=o;i.add(w)}else if(a===M)if(f===T){let{combo:w}=n[0];for(const k of o){let N=new Set([k]);for(let g=1;g<s;g++){const{combo:h,leaves:m}=n[g],u={combo:w,leaves:m};if(N=this._getCombinedNodes(u,N,f),N.size)if(g===_)if(i.size){const y=[...i];i=new Set([...y,...N]),this.#m=!0}else i=N;else w=h;else break}}}else for(const w of o){let k=new Set([w]);for(let N=_-1;N>=0;N--){const g=n[N];if(k=this._getCombinedNodes(g,k,f),k.size)N===0&&(i.add(w),s>1&&i.size>1&&(this.#m=!0));else break}}else if(a===L&&f===T){const{combo:w}=n[0];let k;for(const N of o)if(k=this._matchNodeNext(n,new Set([N]),{combo:w,index:1}),k){i.add(k);break}if(!k&&!d){const{leaves:N}=n[0],[g]=o;let h=this._findNode(N,{node:g});for(;h;){if(k=this._matchNodeNext(n,new Set([h]),{combo:w,index:1}),k){i.add(k);break}h=this._findNode(N,{node:h})}}}else{let w;for(const k of o)if(w=this._matchNodePrev(n,k,{index:_-1}),w){i.add(k);break}if(!w&&!d&&a===L){const{leaves:k}=n[_],[N]=o;let g=this._findNode(k,{node:N});for(;g;){if(w=this._matchNodePrev(n,g,{index:_-1}),w){i.add(g);break}g=this._findNode(k,{node:g})}}}}}return i}matches(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const i=`Unexpected node ${e?.nodeName}`;throw new TypeError(i)}(0,x.filterSelector)(a,{complex:this.#c,descendant:!0})?l=this.#f.match(a,e):(this._setup(a,e,r),l=this._find(D).size)}catch(i){this._onError(i)}return!!l}closest(a,e,r){let l;try{if(e?.nodeType!==b.ELEMENT_NODE){const i=`Unexpected node ${e?.nodeName}`;throw new TypeError(i)}if((0,x.filterSelector)(a,{complex:this.#c,descendant:!0}))l=this.#f.closest(a,e);else{this._setup(a,e,r);const i=this._find(R);if(i.size){let c=this.#e;for(;c;){if(i.has(c)){l=c;break}c=c.parentNode}}}}catch(i){this._onError(i)}return l??null}querySelector(a,e,r){let l;try{if(this._setup(a,e,r),this.#d===this.#t&&!this.#h&&(0,x.filterSelector)(a,{complex:this.#c,descendant:!1}))l=this.#f.first(a,e);else{const i=this._find(L);i.delete(this.#e),i.size&&([l]=(0,C.sortNodes)(i))}}catch(i){this._onError(i)}return l??null}querySelectorAll(a,e,r){let l;try{if(this._setup(a,e,r),this.#d===this.#t&&!this.#h&&(0,x.filterSelector)(a,{complex:this.#c,descendant:!1}))l=this.#f.select(a,e);else{const i=this._find(M);i.delete(this.#e),i.size&&(this.#m?l=(0,C.sortNodes)(i):l=[...i])}}catch(i){this._onError(i)}return l??[]}}0&&(module.exports={Finder});
|
|
1
|
+
var W=Object.create;var P=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(y,l)=>{for(var e in l)P(y,e,{get:l[e],enumerable:!0})},I=(y,l,e,n)=>{if(l&&typeof l=="object"||typeof l=="function")for(let r of j(l))!q.call(y,r)&&r!==e&&P(y,r,{get:()=>l[r],enumerable:!(n=B(l,r))||n.enumerable});return y};var U=(y,l,e)=>(e=y!=null?W(Y(y)):{},I(l||!y||!y.__esModule?P(e,"default",{value:y,enumerable:!0}):e,y)),X=y=>I(P({},"__esModule",{value:!0}),y);var Q={};V(Q,{Finder:()=>K});module.exports=X(Q);var M=U(require("is-potential-custom-element-name"),1),$=U(require("@asamuzakjp/nwsapi"),1),S=require("./dom-util.js"),O=require("./matcher.js"),k=require("./parser.js"),c=require("./constant.js");const v="next",x="prev",L="all",g="first",C="lineal",R="self";class K{#a;#r;#c;#t;#h;#d;#p;#e;#b;#N;#f;#o;#w;#s;#u;#m;#n;#_;#i;#l;constructor(l){this.#l=l,this.#d=l.document,this.#r=new WeakMap,this.#w=new WeakMap,this.#f=(0,$.default)({document:l.document,DOMException:l.DOMException}),this.#f.configure({LOGERRORS:!1})}_onError(l){if(!this.#N)if(l instanceof DOMException||l instanceof this.#l.DOMException)if(l.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(l.message);else throw new this.#l.DOMException(l.message,l.name);else throw l}_setup(l,e,n={}){const{event:r,noexcept:a,warn:f}=n;return this.#N=!!a,this.#i=!!f,this.#p=this._setEvent(r),this.#e=e,[this.#t,this.#s,this.#n]=(0,S.resolveContent)(e),this.#u=(0,S.isInShadowTree)(e),[this.#a,this.#b]=this._correspond(l),this.#_=new WeakMap,e}_setEvent(l){return l instanceof this.#l.MouseEvent||l instanceof this.#l.KeyboardEvent?l:null}_correspond(l){const e=[];this.#c=!1,this.#h=!1;let n;if(this.#t){const r=this.#r.get(this.#t);if(r&&r.has(`${l}`)){const a=r.get(`${l}`);this.#c=a.complex,this.#h=a.descendant,n=a.ast}}if(n){const r=n.length;for(let a=0;a<r;a++)n[a].collected=!1,n[a].dir=null,n[a].filtered=!1,n[a].find=!1,e[a]=[]}else{let r;try{r=(0,k.parseSelector)(l)}catch(d){this._onError(d)}const{branches:a,complex:f}=(0,k.walkAST)(r,!0);let o=!1,b=0;n=[];for(const[...d]of a){const s=[];let t=d.shift();if(t&&t.type!==c.COMBINATOR){const i=new Set;for(;t;){if(t.type===c.COMBINATOR){const[h]=d;if(h.type===c.COMBINATOR){const u=`Invalid selector ${l}`;throw new DOMException(u,c.SYNTAX_ERR)}const m=t.name;/^[\s>]$/.test(m)&&(o=!0),s.push({combo:t,leaves:(0,k.sortAST)(i)}),i.clear()}else if(t){let{name:h}=t;h&&typeof h=="string"&&(h=(0,k.unescapeSelector)(h),typeof h=="string"&&h!==t.name&&(t.name=h),/[|:]/.test(h)&&(t.namespace=!0)),i.add(t)}if(d.length)t=d.shift();else{s.push({combo:null,leaves:(0,k.sortAST)(i)}),i.clear();break}}}n.push({branch:s,collected:!1,dir:null,filtered:!1,find:!1}),e[b]=[],b++}if(this.#t){let d;this.#r.has(this.#t)?d=this.#r.get(this.#t):d=new Map,d.set(`${l}`,{ast:n,complex:f,descendant:o}),this.#r.set(this.#t,d)}this.#c=f,this.#h=o}return[n,e]}_createTreeWalker(l){let e;return this.#_.has(l)?e=this.#_.get(l):(e=this.#d.createTreeWalker(l,c.WALKER_FILTER),this.#_.set(l,e)),e}_prepareQuerySelectorWalker(){return this.#o=this._createTreeWalker(this.#e),this.#m=!1,this.#o}_traverse(l,e=this.#n){let n=e.currentNode,r;if(n===l)r=n;else if(n.contains(l))for(n=e.nextNode();n;){if(n===l){r=n;break}n=e.nextNode()}else{if(n!==e.root)for(;n&&!(n===e.root||n===l);)n=e.parentNode();if(l?.nodeType===c.ELEMENT_NODE)for(;n;){if(n===l){r=n;break}n=e.nextNode()}else r=n}return r??null}_collectNthChild(l,e,n){const{a:r,b:a,reverse:f,selector:o}=l,{parentNode:b}=e,d=new Set;let s;if(o)if(this.#r.has(o))s=this.#r.get(o);else{const{branches:t}=(0,k.walkAST)(o);s=t,this.#r.set(o,s)}if(b){const t=this.#n;let i=this._traverse(b,t);i=t.firstChild();let h=0;for(;i;)h++,i=t.nextSibling();i=this._traverse(b,t);const m=new Set;if(s)for(i=t.firstChild();i;){let u;for(const p of s)if(u=this._matchLeaves(p,i,n),!u)break;u&&m.add(i),i=t.nextSibling()}if(r===0){if(a>0&&a<=h){if(m.size){i=this._traverse(b,t),f?i=t.lastChild():i=t.firstChild();let u=0;for(;i;){if(m.has(i)){if(u===a-1){d.add(i);break}u++}f?i=t.previousSibling():i=t.nextSibling()}}else if(!o){i=this._traverse(b,t),f?i=t.lastChild():i=t.firstChild();let u=0;for(;i;){if(u===a-1){d.add(i);break}f?i=t.previousSibling():i=t.nextSibling(),u++}}}}else{let u=a-1;if(r>0)for(;u<0;)u+=r;if(u>=0&&u<h){i=this._traverse(b,t),f?i=t.lastChild():i=t.firstChild();let p=0,_=r>0?0:a-1;for(;i&&(i&&u>=0&&u<h);)m.size?m.has(i)&&(_===u&&(d.add(i),u+=r),r>0?_++:_--):p===u&&(o||d.add(i),u+=r),f?i=t.previousSibling():i=t.nextSibling(),p++}}if(f&&d.size>1){const u=[...d];return new Set(u.reverse())}}else if(e===this.#s&&r+a===1)if(s){let t;for(const i of s)if(t=this._matchLeaves(i,e,n),t)break;t&&d.add(e)}else d.add(e);return d}_collectNthOfType(l,e){const{a:n,b:r,reverse:a}=l,{localName:f,parentNode:o,prefix:b}=e,d=new Set;if(o){const s=this.#n;let t=this._traverse(o,s);t=s.firstChild();let i=0;for(;t;)i++,t=s.nextSibling();if(n===0){if(r>0&&r<=i){t=this._traverse(o,s),a?t=s.lastChild():t=s.firstChild();let h=0;for(;t;){const{localName:m,prefix:u}=t;if(m===f&&u===b){if(h===r-1){d.add(t);break}h++}a?t=s.previousSibling():t=s.nextSibling()}}}else{let h=r-1;if(n>0)for(;h<0;)h+=n;if(h>=0&&h<i){t=this._traverse(o,s),a?t=s.lastChild():t=s.firstChild();let m=n>0?0:r-1;for(;t;){const{localName:u,prefix:p}=t;if(u===f&&p===b){if(m===h&&(d.add(t),h+=n),h<0||h>=i)break;n>0?m++:m--}a?t=s.previousSibling():t=s.nextSibling()}}}if(a&&d.size>1){const h=[...d];return new Set(h.reverse())}}else e===this.#s&&n+r===1&&d.add(e);return d}_matchAnPlusB(l,e,n,r){const{nth:{a,b:f,name:o},selector:b}=l,d=new Map;if(o?(o==="even"?(d.set("a",2),d.set("b",0)):o==="odd"&&(d.set("a",2),d.set("b",1)),n.indexOf("last")>-1&&d.set("reverse",!0)):(typeof a=="string"&&/-?\d+/.test(a)?d.set("a",a*1):d.set("a",0),typeof f=="string"&&/-?\d+/.test(f)?d.set("b",f*1):d.set("b",0),n.indexOf("last")>-1&&d.set("reverse",!0)),/^nth-(?:last-)?child$/.test(n)){b&&d.set("selector",b);const s=Object.fromEntries(d);return this._collectNthChild(s,e,r)}else if(/^nth-(?:last-)?of-type$/.test(n)){const s=Object.fromEntries(d);return this._collectNthOfType(s,e)}return new Set}_matchHasPseudoFunc(l,e,n={}){let r;if(Array.isArray(l)&&l.length){const[a]=l,{type:f}=a;let o;f===c.COMBINATOR?o=l.shift():o={name:" ",type:c.COMBINATOR};const b=[];for(;l.length;){const[t]=l,{type:i}=t;if(i===c.COMBINATOR)break;b.push(l.shift())}const d={combo:o,leaves:b};n.dir=v;const s=this._matchCombinator(d,e,n);if(s.size)if(l.length){for(const t of s)if(r=this._matchHasPseudoFunc(Object.assign([],l),t,n),r)break}else r=!0}return!!r}_matchLogicalPseudoFunc(l,e,n={}){const{astName:r="",branches:a=[],selector:f="",twigBranches:o=[]}=l;let b;if(r==="has")if(f.includes(":has("))b=null;else{let d;for(const s of a)if(d=this._matchHasPseudoFunc(Object.assign([],s),e,n),d)break;d&&(b=e)}else{const d=/^(?:is|where)$/.test(r);n.forgive=d;const s=o.length;let t;for(let i=0;i<s;i++){const h=o[i],m=h.length-1,{leaves:u}=h[m];if(t=this._matchLeaves(u,e,n),t&&m>0){let p=new Set([e]);for(let _=m-1;_>=0;_--){const w=h[_],N=[];n.dir=x;for(const A of p){const E=this._matchCombinator(w,A,n);E.size&&N.push(...E)}if(N.length)_===0?t=!0:p=new Set(N);else{t=!1;break}}}if(t)break}r==="not"?t||(b=e):t&&(b=e)}return b??null}_matchPseudoClassSelector(l,e,n={}){const{children:r,name:a}=l,{localName:f,parentNode:o}=e,{forgive:b,warn:d=this.#i}=n,s=new Set;if(c.REG_LOGICAL_PSEUDO.test(a)){let t;if(this.#r.has(l))t=this.#r.get(l);else{const{branches:h}=(0,k.walkAST)(l),m=[],u=[];for(const[...p]of h){for(const A of p){const E=(0,k.generateCSS)(A);m.push(E)}const _=[],w=new Set;let N=p.shift();for(;N;)if(N.type===c.COMBINATOR?(_.push({combo:N,leaves:[...w]}),w.clear()):N&&w.add(N),p.length)N=p.shift();else{_.push({combo:null,leaves:[...w]}),w.clear();break}u.push(_)}t={astName:a,branches:h,twigBranches:u,selector:m.join(",")},this.#r.set(l,t)}const i=this._matchLogicalPseudoFunc(t,e,n);i&&s.add(i)}else if(Array.isArray(r))if(/^nth-(?:last-)?(?:child|of-type)$/.test(a)){const[t]=r;return this._matchAnPlusB(t,e,a,n)}else switch(a){case"dir":case"lang":{const t=O.matcher.matchSelector(l,e);t&&s.add(t);break}case"current":case"nth-col":case"nth-last-col":{if(d){const t=`Unsupported pseudo-class :${a}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!b){const t=`Unknown pseudo-class :${a}()`;throw new DOMException(t,c.SYNTAX_ERR)}}else switch(a){case"any-link":case"link":{c.REG_ANCHOR.test(f)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(c.REG_ANCHOR.test(f)&&e.hasAttribute("href")){const{href:t,origin:i,pathname:h}=new URL(this.#t.URL),m=new URL(e.getAttribute("href"),t);m.origin===i&&m.pathname===h&&s.add(e)}break}case"visited":break;case"hover":{const{target:t,type:i}=this.#p??{};(i==="mouseover"||i==="pointerover")&&e.contains(t)&&s.add(e);break}case"active":{const{buttons:t,target:i,type:h}=this.#p??{};(h==="mousedown"||h==="pointerdown")&&t&c.BIT_01&&e.contains(i)&&s.add(e);break}case"target":{const{hash:t}=new URL(this.#t.URL);e.id&&t===`#${e.id}`&&this.#t.contains(e)&&s.add(e);break}case"target-within":{const{hash:t}=new URL(this.#t.URL);if(t){const i=t.replace(/^#/,"");let h=this.#t.getElementById(i);for(;h;){if(h===e){s.add(e);break}h=h.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#u&&e===this.#e&&s.add(e):e===this.#t.documentElement&&s.add(e);break}case"focus":case"focus-visible":{const{target:t,type:i}=this.#p??{};if(e===this.#t.activeElement&&e.tabIndex>=0&&(a==="focus"||i==="keydown"&&e.contains(t))){let h=e,m=!0;for(;h;){if(h.disabled||h.hasAttribute("disabled")||h.hidden||h.hasAttribute("hidden")){m=!1;break}else{const{display:u,visibility:p}=this.#l.getComputedStyle(h);if(m=!(u==="none"||p==="hidden"),!m)break}if(h.parentNode&&h.parentNode.nodeType===c.ELEMENT_NODE)h=h.parentNode;else break}m&&s.add(e)}break}case"focus-within":{let t,i=this.#t.activeElement;if(i.tabIndex>=0)for(;i;){if(i===e){t=!0;break}i=i.parentNode}if(t){let h=e,m=!0;for(;h;){if(h.disabled||h.hasAttribute("disabled")||h.hidden||h.hasAttribute("hidden")){m=!1;break}else{const{display:u,visibility:p}=this.#l.getComputedStyle(h);if(m=!(u==="none"||p==="hidden"),!m)break}if(h.parentNode&&h.parentNode.nodeType===c.ELEMENT_NODE)h=h.parentNode;else break}m&&s.add(e)}break}case"open":{c.REG_INTERACT.test(f)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{c.REG_INTERACT.test(f)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(c.REG_FORM_CTRL.test(f)||(0,M.default)(f))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let t=o;for(;t&&t.localName!=="fieldset";)t=t.parentNode;t&&o.localName!=="legend"&&t.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(c.REG_FORM_CTRL.test(f)||(0,M.default)(f))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(f){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,S.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(f){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||c.REG_TYPE_DATE.test(e.type)||c.REG_TYPE_TEXT.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,S.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let t;f==="textarea"?t=e:f==="input"&&(e.hasAttribute("type")?c.REG_TYPE_TEXT.test(e.getAttribute("type"))&&(t=e):t=e),t&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&f==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&f==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&f==="input"&&e.type==="checkbox"||f==="progress"&&!e.hasAttribute("value"))s.add(e);else if(f==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const t=e.name;let i=e.parentNode;for(;i&&i.localName!=="form";)i=i.parentNode;i||(i=this.#t.documentElement);const h=i.getElementsByTagName("input"),m=h.length;let u;for(let p=0;p<m;p++){const _=h[p];if(_.getAttribute("type")==="radio"&&(t?_.getAttribute("name")===t&&(u=!!_.checked):_.hasAttribute("name")||(u=!!_.checked),u))break}u||s.add(e)}break}case"default":{if(f==="button"&&!(e.hasAttribute("type")&&c.REG_TYPE_RESET.test(e.getAttribute("type")))||f==="input"&&e.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(e.getAttribute("type"))){let t=e.parentNode;for(;t&&t.localName!=="form";)t=t.parentNode;if(t){const i=this.#n;let h=this._traverse(t,i);for(h=i.firstChild();h&&t.contains(h);){const m=h.localName;let u;if(m==="button"?u=!(h.hasAttribute("type")&&c.REG_TYPE_RESET.test(h.getAttribute("type"))):m==="input"&&(u=h.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(h.getAttribute("type"))),u){h===e&&s.add(e);break}h=i.nextNode()}}}else if(f==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(f==="option"){let t=o,i=!1;for(;t&&t.localName!=="datalist";){if(t.localName==="select"){(t.multiple||t.hasAttribute("multiple"))&&(i=!0);break}t=t.parentNode}if(i)(e.selected||e.hasAttribute("selected"))&&s.add(e);else{const h=new Set,m=this.#n;let u=this._traverse(o,m);for(u=m.firstChild();u;){if(u.selected||u.hasAttribute("selected")){h.add(u);break}u=m.nextSibling()}h.size&&h.has(e)&&s.add(e)}}break}case"valid":{if(c.REG_FORM_VALID.test(f))e.checkValidity()&&s.add(e);else if(f==="fieldset"){const t=this.#n;let i=this._traverse(e,t);i=t.firstChild();let h;for(;i&&e.contains(i)&&!(c.REG_FORM_VALID.test(i.localName)&&(h=i.checkValidity(),!h));)i=t.nextNode();h&&s.add(e)}break}case"invalid":{if(c.REG_FORM_VALID.test(f))e.checkValidity()||s.add(e);else if(f==="fieldset"){const t=this.#n;let i=this._traverse(e,t);i=t.firstChild();let h;for(;i&&e.contains(i)&&!(c.REG_FORM_VALID.test(i.localName)&&(h=i.checkValidity(),!h));)i=t.nextNode();h||s.add(e)}break}case"in-range":{f==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&s.add(e);break}case"out-of-range":{f==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&c.REG_TYPE_RANGE.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&s.add(e);break}case"required":{let t;if(/^(?:select|textarea)$/.test(f))t=e;else if(f==="input")if(e.hasAttribute("type")){const i=e.getAttribute("type");(i==="file"||c.REG_TYPE_CHECK.test(i)||c.REG_TYPE_DATE.test(i)||c.REG_TYPE_TEXT.test(i))&&(t=e)}else t=e;t&&(e.required||e.hasAttribute("required"))&&s.add(e);break}case"optional":{let t;if(/^(?:select|textarea)$/.test(f))t=e;else if(f==="input")if(e.hasAttribute("type")){const i=e.getAttribute("type");(i==="file"||c.REG_TYPE_CHECK.test(i)||c.REG_TYPE_DATE.test(i)||c.REG_TYPE_TEXT.test(i))&&(t=e)}else t=e;t&&!(e.required||e.hasAttribute("required"))&&s.add(e);break}case"root":{e===this.#t.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#d.createTreeWalker(e,c.SHOW_ALL);let i=t.firstChild(),h;for(;i&&(h=i.nodeType!==c.ELEMENT_NODE&&i.nodeType!==c.TEXT_NODE,!!h);)i=t.nextSibling();h&&s.add(e)}else s.add(e);break}case"first-child":{(o&&e===o.firstElementChild||e===this.#s)&&s.add(e);break}case"last-child":{(o&&e===o.lastElementChild||e===this.#s)&&s.add(e);break}case"only-child":{(o&&e===o.firstElementChild&&e===o.lastElementChild||e===this.#s)&&s.add(e);break}case"first-of-type":{if(o){const[t]=this._collectNthOfType({a:0,b:1},e);t&&s.add(t)}else e===this.#s&&s.add(e);break}case"last-of-type":{if(o){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&s.add(t)}else e===this.#s&&s.add(e);break}case"only-of-type":{if(o){const[t]=this._collectNthOfType({a:0,b:1},e);if(t===e){const[i]=this._collectNthOfType({a:0,b:1,reverse:!0},e);i===e&&s.add(e)}}else e===this.#s&&s.add(e);break}case"defined":{const t=e.getAttribute("is");t?(0,M.default)(t)&&this.#l.customElements.get(t)&&s.add(e):(0,M.default)(f)?this.#l.customElements.get(f)&&s.add(e):(e instanceof this.#l.HTMLElement||e instanceof this.#l.SVGElement)&&s.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#l.getComputedStyle(e);t!=="none"&&s.add(e)}break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(d){const t=`Unsupported pseudo-element ::${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"autofill":case"blank":case"buffering":case"current":case"fullscreen":case"future":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(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(a.startsWith("-webkit-")){if(d){const t=`Unsupported pseudo-class :${a}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}}else if(!b){const t=`Unknown pseudo-class :${a}`;throw new DOMException(t,c.SYNTAX_ERR)}}return s}_matchShadowHostPseudoClass(l,e){const{children:n,name:r}=l;let a;if(Array.isArray(n)){const{branches:f}=(0,k.walkAST)(n[0]),[o]=f,[...b]=o,{host:d}=e;if(r==="host"){let s;for(const t of b){const{type:i}=t;if(i===c.COMBINATOR){const m=`Invalid selector ${(0,k.generateCSS)(l)}`;throw new DOMException(m,c.SYNTAX_ERR)}if(s=this._matchSelector(t,d).has(d),!s)break}s&&(a=e)}else if(r==="host-context"){let s=d,t;for(;s;){for(const i of b){const{type:h}=i;if(h===c.COMBINATOR){const u=`Invalid selector ${(0,k.generateCSS)(l)}`;throw new DOMException(u,c.SYNTAX_ERR)}if(t=this._matchSelector(i,s).has(s),!t)break}if(t)break;s=s.parentNode}t&&(a=e)}}else if(r==="host")a=e;else{const f=`Invalid selector :${r}`;throw new DOMException(f,c.SYNTAX_ERR)}return a??null}_matchSelector(l,e,n){const{type:r}=l,a=new Set;if(l.name===c.EMPTY)return a;const f=(0,k.unescapeSelector)(l.name);if(typeof f=="string"&&f!==l.name&&(l.name=f),e.nodeType===c.ELEMENT_NODE)switch(r){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(f,n);break}case c.SELECTOR_ID:{e.id===f&&a.add(e);break}case c.SELECTOR_CLASS:{e.classList.contains(f)&&a.add(e);break}case c.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(l,e,n);default:{const o=O.matcher.matchSelector(l,e,n);o&&a.add(o)}}else if(this.#u&&r===c.SELECTOR_PSEUDO_CLASS&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(f!=="has"&&c.REG_LOGICAL_PSEUDO.test(f))return this._matchPseudoClassSelector(l,e,n);if(c.REG_SHADOW_HOST.test(f)){const o=this._matchShadowHostPseudoClass(l,e,n);o&&a.add(o)}}return a}_matchLeaves(l,e,n){const{attributes:r,localName:a,nodeType:f}=e;let o=this.#w.get(l),b;if(o&&o.has(e)){const{attr:d,matched:s}=o.get(e);r?.length===d&&(b=s)}if(typeof b!="boolean"){let d;f===c.ELEMENT_NODE&&c.REG_FORM.test(a)?d=!1:d=!0;for(const s of l){const{name:t,type:i}=s;if(i===c.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(d=!1),b=this._matchSelector(s,e,n).has(e),!b)break}d&&(o||(o=new WeakMap),o.set(e,{attr:r?.length,matched:b}),this.#w.set(l,o))}return!!b}_matchHTMLCollection(l,e={}){const{compound:n,filterLeaves:r}=e,a=new Set,f=l.length;if(f)if(n)for(let o=0;o<f;o++){const b=l[o];this._matchLeaves(r,b,e)&&a.add(b)}else{const o=[].slice.call(l);return new Set(o)}return a}_findDescendantNodes(l,e,n){const[r,...a]=l,f=a.length>0,{type:o}=r,b=(0,k.unescapeSelector)(r.name);typeof b=="string"&&b!==r.name&&(r.name=b);let d=new Set,s=!1;if(this.#u)s=!0;else switch(o){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(b,n);break}case c.SELECTOR_ID:{if(this.#s.nodeType===c.ELEMENT_NODE)s=!0;else{const t=this.#s.getElementById(b);t&&t!==e&&e.contains(t)&&(f?this._matchLeaves(a,t,n)&&d.add(t):d.add(t))}break}case c.SELECTOR_CLASS:{const t=e.getElementsByClassName(b);d=this._matchHTMLCollection(t,{compound:f,filterLeaves:a});break}case c.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(b)){const t=e.getElementsByTagName(b);d=this._matchHTMLCollection(t,{compound:f,filterLeaves:a})}else s=!0;break}default:s=!0}return{nodes:d,pending:s}}_matchCombinator(l,e,n={}){const{combo:r,leaves:a}=l,{name:f}=r,{parentNode:o}=e,{dir:b}=n,d=new Set;if(b===v)switch(f){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(a,s,n)&&d.add(s);break}case"~":{if(o){const s=this._createTreeWalker(o);let t=this._traverse(e,s);for(t=s.nextSibling();t;)this._matchLeaves(a,t,n)&&d.add(t),t=s.nextSibling()}break}case">":{const s=this._createTreeWalker(e);let t=this._traverse(e,s);for(t=s.firstChild();t;)this._matchLeaves(a,t,n)&&d.add(t),t=s.nextSibling();break}case" ":default:{const{nodes:s,pending:t}=this._findDescendantNodes(a,e);if(s.size)return s;if(t){const i=this._createTreeWalker(e);let h=this._traverse(e,i);for(h=i.nextNode();h&&e.contains(h);)this._matchLeaves(a,h,n)&&d.add(h),h=i.nextNode()}}}else switch(f){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(a,s,n)&&d.add(s);break}case"~":{if(o){const s=this._createTreeWalker(o);let t=this._traverse(o,s);for(t=s.firstChild();t&&t!==e;)this._matchLeaves(a,t,n)&&d.add(t),t=s.nextSibling()}break}case">":{o&&this._matchLeaves(a,o,n)&&d.add(o);break}case" ":default:{const s=[];let t=o;for(;t;)this._matchLeaves(a,t,n)&&s.push(t),t=t.parentNode;if(s.length)return new Set(s.reverse())}}return d}_findNode(l,e){const{node:n}=e;let r=this._traverse(n,this.#o),a;if(r)for(r.nodeType!==c.ELEMENT_NODE?r=this.#o.nextNode():r===n&&r!==this.#s&&(r=this.#o.nextNode());r;){if(this._matchLeaves(l,r,{warn:this.#i})){a=r;break}r=this.#o.nextNode()}return a??null}_matchSelf(l){const e=[],n=this._matchLeaves(l,this.#e,{warn:this.#i});let r=!1;return n&&(e.push(this.#e),r=!0),[e,r]}_findLineal(l,e={}){const{complex:n}=e,r=[];let a=this._matchLeaves(l,this.#e,{warn:this.#i}),f=!1;if(a&&(r.push(this.#e),f=!0),!a||n){let o=this.#e.parentNode;for(;o&&(a=this._matchLeaves(l,o,{warn:this.#i}),a&&(r.push(o),f=!0),o.parentNode);)o=o.parentNode}return[r,f]}_findFirst(l){const e=[],n=this._findNode(l,{node:this.#e});let r=!1;return n&&(e.push(n),r=!0),[e,r]}_findFromHTMLCollection(l,e={}){const{complex:n,compound:r,filterLeaves:a,targetType:f}=e;let o=[],b=!1,d=!1;const s=l.length;if(s)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<s;t++){const i=l[t];if(i!==this.#e&&(this.#e.contains(i)||i.contains(this.#e))){if(r){if(this._matchLeaves(a,i,{warn:this.#i})&&(o.push(i),b=!0,f===g))break}else if(o.push(i),b=!0,f===g)break}}else if(n)if(r)for(let t=0;t<s;t++){const i=l[t];if(this._matchLeaves(a,i,{warn:this.#i})&&(o.push(i),b=!0,f===g))break}else o=[].slice.call(l),b=!0,d=!0;else if(r)for(let t=0;t<s;t++){const i=l[t];if(this._matchLeaves(a,i,{warn:this.#i})&&(o.push(i),b=!0,f===g))break}else o=[].slice.call(l),b=!0,d=!0;return[o,b,d]}_findEntryNodes(l,e,n){const{leaves:r}=l,[a,...f]=r,o=f.length>0,{name:b,type:d}=a;let s=[],t=!1,i=!1,h=!1;switch(d){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(b,{warn:this.#i});break}case c.SELECTOR_ID:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:n});else if(e===g&&this.#s.nodeType!==c.ELEMENT_NODE){const m=this.#s.getElementById(b);m&&(o?this._matchLeaves(f,m,{warn:this.#i})&&(s.push(m),i=!0):(s.push(m),i=!0))}else e===g?[s,i]=this._findFirst(r):h=!0;break}case c.SELECTOR_CLASS:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:n});else if(this.#s.nodeType===c.DOCUMENT_NODE){const m=this.#s.getElementsByClassName(b);m.length&&([s,i,t]=this._findFromHTMLCollection(m,{complex:n,compound:o,filterLeaves:f,targetType:e}))}else e===g?[s,i]=this._findFirst(r):h=!0;break}case c.SELECTOR_TYPE:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(b)){const m=this.#s.getElementsByTagName(b);m.length&&([s,i,t]=this._findFromHTMLCollection(m,{complex:n,compound:o,filterLeaves:f,targetType:e}))}else e===g?[s,i]=this._findFirst(r):h=!0;break}default:if(e!==C&&c.REG_SHADOW_HOST.test(b)){if(this.#u&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(a,this.#e);m&&(s.push(m),i=!0)}}else e===R?[s,i]=this._matchSelf(r):e===C?[s,i]=this._findLineal(r,{complex:n}):e===g?[s,i]=this._findFirst(r):h=!0}return{collected:t,compound:o,filtered:i,nodes:s,pending:h}}_collectNodes(l){const e=this.#a.values();if(l===L||l===g){const n=new Set;let r=0;for(const{branch:a}of e){const f=a.length,o=f>1,b=a[0];let d,s;if(o){const{combo:p,leaves:[{name:_,type:w}]}=b,N=a[f-1],{leaves:[{name:A,type:E}]}=N;if(E===c.SELECTOR_PSEUDO_ELEMENT||E===c.SELECTOR_ID)d=x,s=N;else if(w===c.SELECTOR_PSEUDO_ELEMENT||w===c.SELECTOR_ID)d=v,s=b;else if(l===L)if(_==="*"&&w===c.SELECTOR_TYPE)d=x,s=N;else if(A==="*"&&E===c.SELECTOR_TYPE)d=v,s=b;else if(f===2){const{name:T}=p;/^[+~]$/.test(T)?(d=x,s=N):(d=v,s=b)}else d=v,s=b;else if(A==="*"&&E===c.SELECTOR_TYPE)d=v,s=b;else if(_==="*"&&w===c.SELECTOR_TYPE)d=x,s=N;else{let T;for(const{combo:D,leaves:[G]}of a){const{name:z,type:F}=G;if(F===c.SELECTOR_PSEUDO_CLASS&&z==="dir"){T=!1;break}if(!T&&D){const{name:H}=D;/^[+~]$/.test(H)&&(T=!0)}}T?(d=v,s=b):(d=x,s=N)}}else d=x,s=b;const{collected:t,compound:i,filtered:h,nodes:m,pending:u}=this._findEntryNodes(s,l,o);m.length?(this.#a[r].find=!0,this.#b[r]=m):u&&n.add(new Map([["index",r],["twig",s]])),this.#a[r].collected=t,this.#a[r].dir=d,this.#a[r].filtered=h||!i,r++}if(n.size){let a,f;this.#e!==this.#s&&this.#e.nodeType===c.ELEMENT_NODE?(a=this.#e,f=this.#o):(a=this.#s,f=this.#n);let o=this._traverse(a,f);for(;o;){let b=!1;if(this.#e.nodeType===c.ELEMENT_NODE?o===this.#e?b=!0:b=this.#e.contains(o):b=!0,b)for(const d of n){const{leaves:s}=d.get("twig");if(this._matchLeaves(s,o,{warn:this.#i})){const i=d.get("index");this.#a[i].filtered=!0,this.#a[i].find=!0,this.#b[i].push(o)}}o!==f.currentNode&&(o=this._traverse(o,f)),o=f.nextNode()}}}else{let n=0;for(const{branch:r}of e){const a=r[r.length-1],f=r.length>1,{compound:o,filtered:b,nodes:d}=this._findEntryNodes(a,l,f);d.length&&(this.#a[n].find=!0,this.#b[n]=d),this.#a[n].dir=x,this.#a[n].filtered=b||!o,n++}}return[this.#a,this.#b]}_getCombinedNodes(l,e,n){const r=[];for(const a of e){const f=this._matchCombinator(l,a,{dir:n,warn:this.#i});f.size&&r.push(...f)}return r.length?new Set(r):new Set}_matchNodeNext(l,e,n){const{combo:r,index:a}=n,{combo:f,leaves:o}=l[a],b={combo:r,leaves:o},d=this._getCombinedNodes(b,e,v);let s;if(d.size)if(a===l.length-1){const[t]=(0,S.sortNodes)(d);s=t}else s=this._matchNodeNext(l,d,{combo:f,index:a+1});return s??null}_matchNodePrev(l,e,n){const{index:r}=n,a=l[r],f=new Set([e]),o=this._getCombinedNodes(a,f,x);let b;if(o.size){if(r===0)b=e;else for(const d of o)if(this._matchNodePrev(l,d,{index:r-1}))return e}return b??null}_find(l){(l===L||l===g)&&this._prepareQuerySelectorWalker();const[[...e],n]=this._collectNodes(l),r=e.length;let a=new Set;for(let f=0;f<r;f++){const{branch:o,collected:b,dir:d,find:s}=e[f],t=o.length;if(t&&s){const i=n[f],h=i.length,m=t-1;if(m===0)if((l===L||l===g)&&this.#e.nodeType===c.ELEMENT_NODE)for(let u=0;u<h;u++){const p=i[u];if(p!==this.#e&&this.#e.contains(p)&&(a.add(p),l!==L))break}else if(l===L)if(a.size){const u=[...a];a=new Set([...u,...i]),this.#m=!0}else a=new Set(i);else{const[u]=i;a.add(u)}else if(l===L)if(d===v){let{combo:u}=o[0];for(const p of i){let _=new Set([p]);for(let w=1;w<t;w++){const{combo:N,leaves:A}=o[w],E={combo:u,leaves:A};if(_=this._getCombinedNodes(E,_,d),_.size)if(w===m)if(a.size){const T=[...a];a=new Set([...T,..._]),this.#m=!0}else a=_;else u=N;else break}}}else for(const u of i){let p=new Set([u]);for(let _=m-1;_>=0;_--){const w=o[_];if(p=this._getCombinedNodes(w,p,d),p.size)_===0&&(a.add(u),t>1&&a.size>1&&(this.#m=!0));else break}}else if(l===g&&d===v){const{combo:u}=o[0];let p;for(const _ of i)if(p=this._matchNodeNext(o,new Set([_]),{combo:u,index:1}),p){a.add(p);break}if(!p&&!b){const{leaves:_}=o[0],[w]=i;let N=this._findNode(_,{node:w});for(;N;){if(p=this._matchNodeNext(o,new Set([N]),{combo:u,index:1}),p){a.add(p);break}N=this._findNode(_,{node:N})}}}else{let u;for(const p of i)if(u=this._matchNodePrev(o,p,{index:m-1}),u){a.add(p);break}if(!u&&!b&&l===g){const{leaves:p}=o[m],[_]=i;let w=this._findNode(p,{node:_});for(;w;){if(u=this._matchNodePrev(o,w,{index:m-1}),u){a.add(w);break}w=this._findNode(p,{node:w})}}}}}return a}matches(l,e,n){let r;try{if(e?.nodeType!==c.ELEMENT_NODE){const a=`Unexpected node ${e?.nodeName}`;throw new TypeError(a)}(0,k.filterSelector)(l,{complex:this.#c,descendant:!0})?r=this.#f.match(l,e):(this._setup(l,e,n),r=this._find(R).size)}catch(a){this._onError(a)}return!!r}closest(l,e,n){let r;try{if(e?.nodeType!==c.ELEMENT_NODE){const a=`Unexpected node ${e?.nodeName}`;throw new TypeError(a)}if((0,k.filterSelector)(l,{complex:this.#c,descendant:!0}))r=this.#f.closest(l,e);else{this._setup(l,e,n);const a=this._find(C);if(a.size){let f=this.#e;for(;f;){if(a.has(f)){r=f;break}f=f.parentNode}}}}catch(a){this._onError(a)}return r??null}querySelector(l,e,n){let r;try{if(this._setup(l,e,n),this.#d===this.#t&&!this.#h&&(0,k.filterSelector)(l,{complex:this.#c,descendant:!1}))r=this.#f.first(l,e);else{const a=this._find(g);a.delete(this.#e),a.size&&([r]=(0,S.sortNodes)(a))}}catch(a){this._onError(a)}return r??null}querySelectorAll(l,e,n){let r;try{if(this._setup(l,e,n),this.#d===this.#t&&!this.#h&&(0,k.filterSelector)(l,{complex:this.#c,descendant:!1}))r=this.#f.select(l,e);else{const a=this._find(L);a.delete(this.#e),a.size&&(this.#m?r=(0,S.sortNodes)(a):r=[...a])}}catch(a){this._onError(a)}return r??[]}}0&&(module.exports={Finder});
|
|
2
2
|
//# sourceMappingURL=finder.js.map
|