@asamuzakjp/dom-selector 4.4.1 → 4.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +2 -2
- package/src/js/constant.js +74 -1
- package/src/js/dom-util.js +4 -5
- package/src/js/finder.js +139 -113
- package/src/js/matcher.js +8 -10
- package/src/js/parser.js +47 -82
- package/types/js/constant.d.ts +51 -1
- package/types/js/finder.d.ts +1 -0
- package/types/js/parser.d.ts +1 -1
package/dist/cjs/js/constant.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var T=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var f=(s,t)=>{for(var p in t)T(s,p,{get:t[p],enumerable:!0})},X=(s,t,p,M)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of w(t))!H.call(s,n)&&n!==p&&T(s,n,{get:()=>t[n],enumerable:!(M=u(t,n))||M.enumerable});return s};var m=s=>X(T({},"__esModule",{value:!0}),s);var oo={};f(oo,{ALPHA_NUM:()=>R,ANB:()=>a,AN_PLUS_B:()=>g,BIT_01:()=>st,BIT_02:()=>Et,BIT_04:()=>rt,BIT_08:()=>nt,BIT_16:()=>_t,BIT_32:()=>xt,BIT_FFFF:()=>pt,BIT_HYPHEN:()=>ct,COMBINATOR:()=>h,COMBO_A:()=>O,COMBO_B:()=>$,COMPLEX_A:()=>L,COMPLEX_B:()=>A,COMPLEX_C:()=>P,COMPLEX_D:()=>D,COMPOUND:()=>E,COMPOUND_A:()=>N,COMPOUND_B:()=>G,COMPOUND_C:()=>I,COMPOUND_I:()=>S,DIGIT:()=>c,DOCUMENT_FRAGMENT_NODE:()=>Nt,DOCUMENT_NODE:()=>At,DOCUMENT_POSITION_CONTAINED_BY:()=>St,DOCUMENT_POSITION_CONTAINS:()=>It,DOCUMENT_POSITION_PRECEDING:()=>Gt,DUO:()=>Ot,ELEMENT_NODE:()=>Ct,EMPTY:()=>b,HEX:()=>$t,IDENTIFIER:()=>W,LANG_PART:()=>l,LOGICAL_COMPLEX_A:()=>d,LOGICAL_COMPLEX_B:()=>F,LOGICAL_COMPOUND:()=>Y,LOGICAL_KEY:()=>e,NESTED_LOGICAL_A:()=>i,NESTED_LOGICAL_B:()=>U,NESTED_LOGICAL_C:()=>B,NOT_SUPPORTED_ERR:()=>y,NTH:()=>K,N_ST:()=>_,N_TH:()=>x,RAW:()=>Z,REG_ANCHOR:()=>it,REG_CHILD_INDEXED:()=>Ut,REG_COMPLEX_A:()=>Bt,REG_COMPLEX_B:()=>dt,REG_DIR:()=>Ft,REG_FORM:()=>Yt,REG_FORM_CTRL:()=>ut,REG_FORM_VALID:()=>wt,REG_HEX:()=>Ht,REG_INTERACT:()=>ft,REG_INVALID_SELECTOR:()=>Xt,REG_LANG:()=>mt,REG_LANG_QUOTED:()=>gt,REG_LOGICAL_COMPLEX_A:()=>ht,REG_LOGICAL_COMPLEX_B:()=>bt,REG_LOGICAL_COMPOUND:()=>Wt,REG_LOGICAL_EMPTY:()=>yt,REG_LOGICAL_KEY:()=>Kt,REG_LOGICAL_PSEUDO:()=>Zt,REG_SHADOW_HOST:()=>kt,REG_SHADOW_MODE:()=>zt,REG_SHADOW_PSEUDO:()=>Vt,REG_TYPE_CHECK:()=>vt,REG_TYPE_DATE:()=>Qt,REG_TYPE_RANGE:()=>jt,REG_TYPE_RESET:()=>qt,REG_TYPE_SUBMIT:()=>Jt,REG_TYPE_TEXT:()=>to,SELECTOR:()=>k,SELECTOR_ATTR:()=>z,SELECTOR_CLASS:()=>V,SELECTOR_ID:()=>v,SELECTOR_LIST:()=>Q,SELECTOR_PSEUDO_CLASS:()=>j,SELECTOR_PSEUDO_ELEMENT:()=>q,SELECTOR_TYPE:()=>J,SHOW_ALL:()=>Pt,SHOW_DOCUMENT:()=>Dt,SHOW_DOCUMENT_FRAGMENT:()=>Mt,SHOW_ELEMENT:()=>lt,STRING:()=>tt,SUB_TYPE:()=>r,SYNTAX_ERR:()=>ot,TAG_TYPE:()=>o,TAG_TYPE_I:()=>C,TEXT_NODE:()=>Lt,TYPE_FROM:()=>Tt,TYPE_TO:()=>Rt,U_FFFD:()=>et,WALKER_FILTER:()=>at});module.exports=m(oo);const g="AnPlusB",h="Combinator",b="__EMPTY__",W="Identifier",y="NotSupportedError",K="Nth",Z="Raw",k="Selector",z="AttributeSelector",V="ClassSelector",v="IdSelector",Q="SelectorList",j="PseudoClassSelector",q="PseudoElementSelector",J="TypeSelector",tt="String",ot="SyntaxError",et="\uFFFD",st=1,Et=2,rt=4,nt=8,_t=16,xt=32,pt=65535,ct=45,Ot=2,$t=16,Tt=8,Rt=-1,Ct=1,Lt=3,At=9,Nt=11,Gt=2,It=8,St=16,Pt=4294967295,Dt=256,Mt=1024,lt=1,at=1281,R="[A-Z\\d]+",c="(?:0|[1-9]\\d*)",l=`(?:-${R})*`,_="(?:first|last|only)-(?:child|of-type)",a=`[+-]?(?:${c}n?|n)|(?:[+-]?${c})?n\\s*[+-]\\s*${c}`,x=`nth-(?:last-)?(?:child|of-type)\\(\\s*(?:even|odd|${a})\\s*\\)`,r="\\[[^\\]]+\\]|[#.:][\\w-]+",o="\\*|[A-Za-z][\\w-]*",C="\\*|[A-Z][\\w-]*",e="(?:is|not|where)",E=`(?:${o}|(?:${o})?(?:${r})+)`,O="\\s?[\\s>~+]\\s?",$="\\s?[~+]\\s?",L=`${E}(?:${O}${E})*`,A=`${E}(?:${$}${E})*`,i=`:${e}\\(\\s*${E}(?:\\s*,\\s*${E})*\\s*\\)`,U=`:${e}\\(\\s*${L}(?:\\s*,\\s*${L})*\\s*\\)`,B=`:${e}\\(\\s*${A}(?:\\s*,\\s*${A})*\\s*\\)`,N=`(?:${o}|(?:${o})?(?:${r}|${i})+)`,G=`(?:${o}|(?:${o})?(?:${r}|${U})+)`,I=`(?:${o}|(?:${o})?(?:${r}|${B})+)`,S=`(?:${C}|(?:${C})?(?:${r})+)`,P=`${G}(?:${O}${G})*`,D=`${I}(?:${$}${I})*`,d=`${e}\\(\\s*${P}(?:\\s*,\\s*${P})*\\s*\\)`,F=`${e}\\(\\s*${D}(?:\\s*,\\s*${D})*\\s*\\)`,Y=`${e}\\(\\s*${N}(?:\\s*,\\s*${N})*\\s*\\)`,it=/^a(?:rea)?$/,Ut=new RegExp(`:(?!${_}|${x})`),Bt=new RegExp(`${O}${S}`,"i"),dt=new RegExp(`${$}${S}`,"i"),Ft=/^(?:ltr|rtl)$/,Yt=/^(?:(?:fieldse|inpu|selec)t|button|form|textarea)$/,ut=/^(?:button|fieldset|input|optgroup|option|select|textarea)$/,wt=/^(?:button|form|input|select|textarea)$/,Ht=/^([\da-f]{1,6}\s?)/i,ft=/^(?:details|dialog)$/,Xt=/^$|^\s*>|,\s*$/,mt=new RegExp(`^(?:\\*-)?${R}${l}$`,"i"),gt=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/,ht=new RegExp(`:(?!${_}|${x}|${d})`),bt=new RegExp(`:(?!${_}|${x}|${F})`),Wt=new RegExp(`:(?!${_}|${x}|${Y})`),yt=/(:(is|where)\(\s*\))/,Kt=new RegExp(`:${e}\\(`),Zt=/^(?:has|is|not|where)$/,kt=/^host(?:-context)?$/,zt=/^(?:close|open)$/,Vt=/^part|slotted$/,vt=/^(?:checkbox|radio)$/,Qt=/^(?:date(?:time-local)?|month|time|week)$/,jt=/(?:date(?:time-local)?|month|number|range|time|week)$/,qt=/^(?:button|reset)$/,Jt=/^(?:image|submit)$/,to=/^(?: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,COMPOUND_A,COMPOUND_B,COMPOUND_C,COMPOUND_I,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_COMPLEX_A,REG_COMPLEX_B,REG_DIR,REG_FORM,REG_FORM_CTRL,REG_FORM_VALID,REG_HEX,REG_INTERACT,REG_INVALID_SELECTOR,REG_LANG,REG_LANG_QUOTED,REG_LOGICAL_COMPLEX_A,REG_LOGICAL_COMPLEX_B,REG_LOGICAL_COMPOUND,REG_LOGICAL_EMPTY,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,TAG_TYPE_I,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 DIGIT = '(?:0|[1-9]\\\\d*)';\nexport const LANG_PART = `(?:-${ALPHA_NUM})*`;\nexport const N_ST = '(?:first|last|only)-(?:child|of-type)';\nexport const ANB =\n `[+-]?(?:${DIGIT}n?|n)|(?:[+-]?${DIGIT})?n\\\\s*[+-]\\\\s*${DIGIT}`;\n// N_TH: 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// SUB_TYPE: attr, id, class, pseudo-class\nexport const SUB_TYPE = '\\\\[[^\\\\]]+\\\\]|[#.:][\\\\w-]+';\n// TAG_TYPE: *, tag\nexport const TAG_TYPE = '\\\\*|[A-Za-z][\\\\w-]*';\nexport const TAG_TYPE_I = '\\\\*|[A-Z][\\\\w-]*';\n// LOGICAL_KEY: excludes :has()\nexport const LOGICAL_KEY = '(?:is|not|where)';\nexport const COMPOUND = `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE})+)`;\nexport const COMBO_A = '\\\\s?[\\\\s>~+]\\\\s?';\nexport const COMBO_B = '\\\\s?[~+]\\\\s?';\nexport const COMPLEX_A = `${COMPOUND}(?:${COMBO_A}${COMPOUND})*`;\nexport const COMPLEX_B = `${COMPOUND}(?:${COMBO_B}${COMPOUND})*`;\nexport const NESTED_LOGICAL_A =\n `:${LOGICAL_KEY}\\\\(\\\\s*${COMPOUND}(?:\\\\s*,\\\\s*${COMPOUND})*\\\\s*\\\\)`;\nexport const NESTED_LOGICAL_B =\n `:${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_A}(?:\\\\s*,\\\\s*${COMPLEX_A})*\\\\s*\\\\)`;\nexport const NESTED_LOGICAL_C =\n `:${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_B}(?:\\\\s*,\\\\s*${COMPLEX_B})*\\\\s*\\\\)`;\nexport const COMPOUND_A =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_A})+)`;\nexport const COMPOUND_B =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_B})+)`;\nexport const COMPOUND_C =\n `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE}|${NESTED_LOGICAL_C})+)`;\nexport const COMPOUND_I =\n `(?:${TAG_TYPE_I}|(?:${TAG_TYPE_I})?(?:${SUB_TYPE})+)`;\nexport const COMPLEX_C = `${COMPOUND_B}(?:${COMBO_A}${COMPOUND_B})*`;\nexport const COMPLEX_D = `${COMPOUND_C}(?:${COMBO_B}${COMPOUND_C})*`;\nexport const LOGICAL_COMPLEX_A =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_C}(?:\\\\s*,\\\\s*${COMPLEX_C})*\\\\s*\\\\)`;\nexport const LOGICAL_COMPLEX_B =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPLEX_D}(?:\\\\s*,\\\\s*${COMPLEX_D})*\\\\s*\\\\)`;\nexport const LOGICAL_COMPOUND =\n `${LOGICAL_KEY}\\\\(\\\\s*${COMPOUND_A}(?:\\\\s*,\\\\s*${COMPOUND_A})*\\\\s*\\\\)`;\n\n/* regexp */\nexport const REG_ANCHOR = /^a(?:rea)?$/;\nexport const REG_CHILD_INDEXED = new RegExp(`:(?!${N_ST}|${N_TH})`);\nexport const REG_COMPLEX_A = new RegExp(`${COMBO_A}${COMPOUND_I}`, 'i');\nexport const REG_COMPLEX_B = new RegExp(`${COMBO_B}${COMPOUND_I}`, 'i');\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_HEX = /^([\\da-f]{1,6}\\s?)/i;\nexport const REG_INTERACT = /^(?:details|dialog)$/;\nexport const REG_INVALID_SELECTOR = /^$|^\\s*>|,\\s*$/;\nexport const REG_LANG = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');\nexport const REG_LANG_QUOTED = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]*\")\\s*\\))/;\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_EMPTY = /(:(is|where)\\(\\s*\\))/;\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,WAAAC,GAAA,aAAAC,GAAA,eAAAC,GAAA,eAAAC,EAAA,YAAAC,EAAA,YAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,cAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,UAAAC,EAAA,2BA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BIT_HYPHEN", "COMBINATOR", "COMBO_A", "COMBO_B", "COMPLEX_A", "COMPLEX_B", "COMPLEX_C", "COMPLEX_D", "COMPOUND", "COMPOUND_A", "COMPOUND_B", "COMPOUND_C", "COMPOUND_I", "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_COMPLEX_A", "REG_COMPLEX_B", "REG_DIR", "REG_FORM", "REG_FORM_CTRL", "REG_FORM_VALID", "REG_HEX", "REG_INTERACT", "REG_INVALID_SELECTOR", "REG_LANG", "REG_LANG_QUOTED", "REG_LOGICAL_COMPLEX_A", "REG_LOGICAL_COMPLEX_B", "REG_LOGICAL_COMPOUND", "REG_LOGICAL_EMPTY", "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", "TAG_TYPE_I", "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 });\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AAOO,GAAS,CACd,KAAM,CAAE,KAAAC,EAAM,KAAAC,EAAM,SAAAC,EAAU,WAAAC,CAAW,EAAIJ,EAC7C,GAAIC,GAAQC,GAAQC,IAAa,0BAC7B,kBAAgB,KAAKD,CAAI,EAAG,CAC9BH,EAAO,GACP,KACF,CACAC,EAAUI,CACZ,CACF,CACA,MAAO,CAAC,CAACL,CACX,EAOajB,EAAwB,CAACW,EAAO,CAAC,IAAM,CAClD,IAAIY,EACJ,GAAIZ,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,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ACX,EAQanB,EAAc,CAACyC,EAAQ,CAAC,EAAGC,EAAQ,CAAC,IAAM,CACrD,IAAIvB,EACJ,GAAIsB,EAAM,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDtB,EAAMwB,EAAS,+BACTA,EAAS,4BACjB,CACA,MAAO,CAAC,CAACxB,CACX,EAOajB,EAAY,CAACkB,EAAQ,CAAC,IAAM,CACvC,MAAMwB,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,!0);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 D=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(y,a)=>{for(var e in a)D(y,e,{get:a[e],enumerable:!0})},I=(y,a,e,f)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of j(a))!q.call(y,r)&&r!==e&&D(y,r,{get:()=>a[r],enumerable:!(f=B(a,r))||f.enumerable});return y};var U=(y,a,e)=>(e=y!=null?W(Y(y)):{},I(a||!y||!y.__esModule?D(e,"default",{value:y,enumerable:!0}):e,y)),X=y=>I(D({},"__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),E=require("./dom-util.js"),O=require("./matcher.js"),k=require("./parser.js"),c=require("./constant.js");const S="next",x="prev",L="all",g="first",C="lineal",R="self";class K{#l;#r;#s;#p;#o;#b;#e;#h;#w;#n;#f;#_;#t;#d;#u;#c;#m;#i;#a;constructor(a){this.#a=a,this.#o=a.document,this.#r=new WeakMap,this.#_=new WeakMap}_onError(a){if(!this.#w)if(a instanceof DOMException||a instanceof this.#a.DOMException)if(a.name===c.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw new this.#a.DOMException(a.message,a.name);else throw a}_setup(a,e,f={}){const{event:r,noexcept:l,warn:o}=f;return this.#w=!!l,this.#i=!!o,this.#b=this._setEvent(r),this.#e=e,[this.#s,this.#t,this.#c]=(0,E.resolveContent)(e),this.#d=(0,E.isInShadowTree)(e),[this.#l,this.#h]=this._correspond(a),this.#m=new WeakMap,e}_initNwsapi(a){return this.#n=(0,$.default)({DOMException:this.#a.DOMException,document:a}),this.#n.configure({LOGERRORS:!1}),this.#n}_setEvent(a){return a instanceof this.#a.MouseEvent||a instanceof this.#a.KeyboardEvent?a:null}_correspond(a){const e=[];this.#p=!1;let f;if(this.#s){const r=this.#r.get(this.#s);if(r&&r.has(`${a}`)){const l=r.get(`${a}`);this.#p=l.descendant,f=l.ast}}if(f){const r=f.length;for(let l=0;l<r;l++)f[l].collected=!1,f[l].dir=null,f[l].filtered=!1,f[l].find=!1,e[l]=[]}else{let r;try{r=(0,k.parseSelector)(a)}catch(u){this._onError(u)}const l=(0,k.walkAST)(r);let o=!1,n=0;f=[];for(const[...u]of l){const h=[];let s=u.shift();if(s&&s.type!==c.COMBINATOR){const t=new Set;for(;s;){if(s.type===c.COMBINATOR){const[i]=u;if(i.type===c.COMBINATOR){const m=`Invalid selector ${a}`;throw new DOMException(m,c.SYNTAX_ERR)}const d=s.name;/^[\s>]$/.test(d)&&(o=!0),h.push({combo:s,leaves:(0,k.sortAST)(t)}),t.clear()}else if(s){let{name:i}=s;i&&typeof i=="string"&&(i=(0,k.unescapeSelector)(i),typeof i=="string"&&i!==s.name&&(s.name=i),/[|:]/.test(i)&&(s.namespace=!0)),t.add(s)}if(u.length)s=u.shift();else{h.push({combo:null,leaves:(0,k.sortAST)(t)}),t.clear();break}}}f.push({branch:h,collected:!1,dir:null,filtered:!1,find:!1}),e[n]=[],n++}if(this.#s){let u;this.#r.has(this.#s)?u=this.#r.get(this.#s):u=new Map,u.set(`${a}`,{ast:f,descendant:o}),this.#r.set(this.#s,u)}this.#p=o}return[f,e]}_createTreeWalker(a){let e;return this.#m.has(a)?e=this.#m.get(a):(e=this.#o.createTreeWalker(a,c.WALKER_FILTER),this.#m.set(a,e)),e}_prepareQuerySelectorWalker(){return this.#f=this._createTreeWalker(this.#e),this.#u=!1,this.#f}_traverse(a,e=this.#c){let f=e.currentNode,r;if(f===a)r=f;else if(f.contains(a))for(f=e.nextNode();f;){if(f===a){r=f;break}f=e.nextNode()}else{if(f!==e.root)for(;f&&!(f===e.root||f===a);)f=e.parentNode();if(a?.nodeType===c.ELEMENT_NODE)for(;f;){if(f===a){r=f;break}f=e.nextNode()}else r=f}return r??null}_collectNthChild(a,e,f){const{a:r,b:l,reverse:o,selector:n}=a,{parentNode:u}=e,h=new Set;let s;if(n&&(this.#r.has(n)?s=this.#r.get(n):(s=(0,k.walkAST)(n),this.#r.set(n,s))),u){const t=this.#c;let i=this._traverse(u,t);i=t.firstChild();let d=0;for(;i;)d++,i=t.nextSibling();i=this._traverse(u,t);const m=new Set;if(s)for(i=t.firstChild();i;){let b;for(const p of s)if(b=this._matchLeaves(p,i,f),!b)break;b&&m.add(i),i=t.nextSibling()}if(r===0){if(l>0&&l<=d){if(m.size){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let b=0;for(;i;){if(m.has(i)){if(b===l-1){h.add(i);break}b++}o?i=t.previousSibling():i=t.nextSibling()}}else if(!n){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let b=0;for(;i;){if(b===l-1){h.add(i);break}o?i=t.previousSibling():i=t.nextSibling(),b++}}}}else{let b=l-1;if(r>0)for(;b<0;)b+=r;if(b>=0&&b<d){i=this._traverse(u,t),o?i=t.lastChild():i=t.firstChild();let p=0,_=r>0?0:l-1;for(;i&&(i&&b>=0&&b<d);)m.size?m.has(i)&&(_===b&&(h.add(i),b+=r),r>0?_++:_--):p===b&&(n||h.add(i),b+=r),o?i=t.previousSibling():i=t.nextSibling(),p++}}if(o&&h.size>1){const b=[...h];return new Set(b.reverse())}}else if(e===this.#t&&r+l===1)if(s){let t;for(const i of s)if(t=this._matchLeaves(i,e,f),t)break;t&&h.add(e)}else h.add(e);return h}_collectNthOfType(a,e){const{a:f,b:r,reverse:l}=a,{localName:o,parentNode:n,prefix:u}=e,h=new Set;if(n){const s=this.#c;let t=this._traverse(n,s);t=s.firstChild();let i=0;for(;t;)i++,t=s.nextSibling();if(f===0){if(r>0&&r<=i){t=this._traverse(n,s),l?t=s.lastChild():t=s.firstChild();let d=0;for(;t;){const{localName:m,prefix:b}=t;if(m===o&&b===u){if(d===r-1){h.add(t);break}d++}l?t=s.previousSibling():t=s.nextSibling()}}}else{let d=r-1;if(f>0)for(;d<0;)d+=f;if(d>=0&&d<i){t=this._traverse(n,s),l?t=s.lastChild():t=s.firstChild();let m=f>0?0:r-1;for(;t;){const{localName:b,prefix:p}=t;if(b===o&&p===u){if(m===d&&(h.add(t),d+=f),d<0||d>=i)break;f>0?m++:m--}l?t=s.previousSibling():t=s.nextSibling()}}}if(l&&h.size>1){const d=[...h];return new Set(d.reverse())}}else e===this.#t&&f+r===1&&h.add(e);return h}_matchAnPlusB(a,e,f,r){const{nth:{a:l,b:o,name:n},selector:u}=a,h=new Map;if(n?(n==="even"?(h.set("a",2),h.set("b",0)):n==="odd"&&(h.set("a",2),h.set("b",1)),f.indexOf("last")>-1&&h.set("reverse",!0)):(typeof l=="string"&&/-?\d+/.test(l)?h.set("a",l*1):h.set("a",0),typeof o=="string"&&/-?\d+/.test(o)?h.set("b",o*1):h.set("b",0),f.indexOf("last")>-1&&h.set("reverse",!0)),/^nth-(?:last-)?child$/.test(f)){u&&h.set("selector",u);const s=Object.fromEntries(h);return this._collectNthChild(s,e,r)}else if(/^nth-(?:last-)?of-type$/.test(f)){const s=Object.fromEntries(h);return this._collectNthOfType(s,e)}return new Set}_matchHasPseudoFunc(a,e,f={}){let r;if(Array.isArray(a)&&a.length){const[l]=a,{type:o}=l;let n;o===c.COMBINATOR?n=a.shift():n={name:" ",type:c.COMBINATOR};const u=[];for(;a.length;){const[t]=a,{type:i}=t;if(i===c.COMBINATOR)break;u.push(a.shift())}const h={combo:n,leaves:u};f.dir=S;const s=this._matchCombinator(h,e,f);if(s.size)if(a.length){for(const t of s)if(r=this._matchHasPseudoFunc(Object.assign([],a),t,f),r)break}else r=!0}return!!r}_matchLogicalPseudoFunc(a,e,f={}){const{astName:r="",branches:l=[],selector:o="",twigBranches:n=[]}=a;let u;if(r==="has")if(o.includes(":has("))u=null;else{let h;for(const s of l)if(h=this._matchHasPseudoFunc(Object.assign([],s),e,f),h)break;h&&(u=e)}else{const h=/^(?:is|where)$/.test(r);f.forgive=h;const s=n.length;let t;for(let i=0;i<s;i++){const d=n[i],m=d.length-1,{leaves:b}=d[m];if(t=this._matchLeaves(b,e,f),t&&m>0){let p=new Set([e]);for(let _=m-1;_>=0;_--){const w=d[_],N=[];f.dir=x;for(const A of p){const v=this._matchCombinator(w,A,f);v.size&&N.push(...v)}if(N.length)_===0?t=!0:p=new Set(N);else{t=!1;break}}}if(t)break}r==="not"?t||(u=e):t&&(u=e)}return u??null}_matchPseudoClassSelector(a,e,f={}){const{children:r,name:l}=a,{localName:o,parentNode:n}=e,{forgive:u,warn:h=this.#i}=f,s=new Set;if(c.REG_LOGICAL_PSEUDO.test(l)){let t;if(this.#r.has(a))t=this.#r.get(a);else{const d=(0,k.walkAST)(a),m=[],b=[];for(const[...p]of d){for(const A of p){const v=(0,k.generateCSS)(A);m.push(v)}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}b.push(_)}t={astName:l,branches:d,twigBranches:b,selector:m.join(",")},this.#r.set(a,t)}const i=this._matchLogicalPseudoFunc(t,e,f);i&&s.add(i)}else if(Array.isArray(r))if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const[t]=r;return this._matchAnPlusB(t,e,l,f)}else switch(l){case"dir":case"lang":{const t=O.matcher.matchSelector(a,e);t&&s.add(t);break}case"current":case"nth-col":case"nth-last-col":{if(h){const t=`Unsupported pseudo-class :${l}()`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!u){const t=`Unknown pseudo-class :${l}()`;throw new DOMException(t,c.SYNTAX_ERR)}}else switch(l){case"any-link":case"link":{c.REG_ANCHOR.test(o)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(c.REG_ANCHOR.test(o)&&e.hasAttribute("href")){const{href:t,origin:i,pathname:d}=new URL(this.#s.URL),m=new URL(e.getAttribute("href"),t);m.origin===i&&m.pathname===d&&s.add(e)}break}case"visited":break;case"hover":{const{target:t,type:i}=this.#b??{};(i==="mouseover"||i==="pointerover")&&e.contains(t)&&s.add(e);break}case"active":{const{buttons:t,target:i,type:d}=this.#b??{};(d==="mousedown"||d==="pointerdown")&&t&c.BIT_01&&e.contains(i)&&s.add(e);break}case"target":{const{hash:t}=new URL(this.#s.URL);e.id&&t===`#${e.id}`&&this.#s.contains(e)&&s.add(e);break}case"target-within":{const{hash:t}=new URL(this.#s.URL);if(t){const i=t.replace(/^#/,"");let d=this.#s.getElementById(i);for(;d;){if(d===e){s.add(e);break}d=d.parentNode}}break}case"scope":{this.#e.nodeType===c.ELEMENT_NODE?!this.#d&&e===this.#e&&s.add(e):e===this.#s.documentElement&&s.add(e);break}case"focus":case"focus-visible":{const{target:t,type:i}=this.#b??{};if(e===this.#s.activeElement&&e.tabIndex>=0&&(l==="focus"||i==="keydown"&&e.contains(t))){let d=e,m=!0;for(;d;){if(d.disabled||d.hasAttribute("disabled")||d.hidden||d.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(d);if(m=!(b==="none"||p==="hidden"),!m)break}if(d.parentNode&&d.parentNode.nodeType===c.ELEMENT_NODE)d=d.parentNode;else break}m&&s.add(e)}break}case"focus-within":{let t,i=this.#s.activeElement;if(i.tabIndex>=0)for(;i;){if(i===e){t=!0;break}i=i.parentNode}if(t){let d=e,m=!0;for(;d;){if(d.disabled||d.hasAttribute("disabled")||d.hidden||d.hasAttribute("hidden")){m=!1;break}else{const{display:b,visibility:p}=this.#a.getComputedStyle(d);if(m=!(b==="none"||p==="hidden"),!m)break}if(d.parentNode&&d.parentNode.nodeType===c.ELEMENT_NODE)d=d.parentNode;else break}m&&s.add(e)}break}case"open":{c.REG_INTERACT.test(o)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{c.REG_INTERACT.test(o)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let t=n;for(;t&&t.localName!=="fieldset";)t=t.parentNode;t&&n.localName!=="legend"&&t.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(c.REG_FORM_CTRL.test(o)||(0,M.default)(o))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(o){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,E.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(o){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,E.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let t;o==="textarea"?t=e:o==="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&&o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))||e.selected&&o==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&o==="input"&&e.type==="checkbox"||o==="progress"&&!e.hasAttribute("value"))s.add(e);else if(o==="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.#s.documentElement);const d=i.getElementsByTagName("input"),m=d.length;let b;for(let p=0;p<m;p++){const _=d[p];if(_.getAttribute("type")==="radio"&&(t?_.getAttribute("name")===t&&(b=!!_.checked):_.hasAttribute("name")||(b=!!_.checked),b))break}b||s.add(e)}break}case"default":{if(o==="button"&&!(e.hasAttribute("type")&&c.REG_TYPE_RESET.test(e.getAttribute("type")))||o==="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.#c;let d=this._traverse(t,i);for(d=i.firstChild();d&&t.contains(d);){const m=d.localName;let b;if(m==="button"?b=!(d.hasAttribute("type")&&c.REG_TYPE_RESET.test(d.getAttribute("type"))):m==="input"&&(b=d.hasAttribute("type")&&c.REG_TYPE_SUBMIT.test(d.getAttribute("type"))),b){d===e&&s.add(e);break}d=i.nextNode()}}}else if(o==="input"&&e.hasAttribute("type")&&c.REG_TYPE_CHECK.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))s.add(e);else if(o==="option"){let t=n,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 d=new Set,m=this.#c;let b=this._traverse(n,m);for(b=m.firstChild();b;){if(b.selected||b.hasAttribute("selected")){d.add(b);break}b=m.nextSibling()}d.size&&d.has(e)&&s.add(e)}}break}case"valid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()&&s.add(e);else if(o==="fieldset"){const t=this.#c;let i=this._traverse(e,t);i=t.firstChild();let d;for(;i&&e.contains(i)&&!(c.REG_FORM_VALID.test(i.localName)&&(d=i.checkValidity(),!d));)i=t.nextNode();d&&s.add(e)}break}case"invalid":{if(c.REG_FORM_VALID.test(o))e.checkValidity()||s.add(e);else if(o==="fieldset"){const t=this.#c;let i=this._traverse(e,t);i=t.firstChild();let d;for(;i&&e.contains(i)&&!(c.REG_FORM_VALID.test(i.localName)&&(d=i.checkValidity(),!d));)i=t.nextNode();d||s.add(e)}break}case"in-range":{o==="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":{o==="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(o))t=e;else if(o==="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(o))t=e;else if(o==="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.#s.documentElement&&s.add(e);break}case"empty":{if(e.hasChildNodes()){const t=this.#o.createTreeWalker(e,c.SHOW_ALL);let i=t.firstChild(),d;for(;i&&(d=i.nodeType!==c.ELEMENT_NODE&&i.nodeType!==c.TEXT_NODE,!!d);)i=t.nextSibling();d&&s.add(e)}else s.add(e);break}case"first-child":{(n&&e===n.firstElementChild||e===this.#t)&&s.add(e);break}case"last-child":{(n&&e===n.lastElementChild||e===this.#t)&&s.add(e);break}case"only-child":{(n&&e===n.firstElementChild&&e===n.lastElementChild||e===this.#t)&&s.add(e);break}case"first-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1},e);t&&s.add(t)}else e===this.#t&&s.add(e);break}case"last-of-type":{if(n){const[t]=this._collectNthOfType({a:0,b:1,reverse:!0},e);t&&s.add(t)}else e===this.#t&&s.add(e);break}case"only-of-type":{if(n){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.#t&&s.add(e);break}case"defined":{const t=e.getAttribute("is");t?(0,M.default)(t)&&this.#a.customElements.get(t)&&s.add(e):(0,M.default)(o)?this.#a.customElements.get(o)&&s.add(e):(e instanceof this.#a.HTMLElement||e instanceof this.#a.SVGElement)&&s.add(e);break}case"popover-open":{if(e.popover){const{display:t}=this.#a.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(h){const t=`Unsupported pseudo-element ::${l}`;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(h){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}break}default:if(l.startsWith("-webkit-")){if(h){const t=`Unsupported pseudo-class :${l}`;throw new DOMException(t,c.NOT_SUPPORTED_ERR)}}else if(!u){const t=`Unknown pseudo-class :${l}`;throw new DOMException(t,c.SYNTAX_ERR)}}return s}_matchShadowHostPseudoClass(a,e){const{children:f,name:r}=a;let l;if(Array.isArray(f)){const[o]=(0,k.walkAST)(f[0]),[...n]=o,{host:u}=e;if(r==="host"){let h;for(const s of n){const{type:t}=s;if(t===c.COMBINATOR){const d=`Invalid selector ${(0,k.generateCSS)(a)}`;throw new DOMException(d,c.SYNTAX_ERR)}if(h=this._matchSelector(s,u).has(u),!h)break}h&&(l=e)}else if(r==="host-context"){let h=u,s;for(;h;){for(const t of n){const{type:i}=t;if(i===c.COMBINATOR){const m=`Invalid selector ${(0,k.generateCSS)(a)}`;throw new DOMException(m,c.SYNTAX_ERR)}if(s=this._matchSelector(t,h).has(h),!s)break}if(s)break;h=h.parentNode}s&&(l=e)}}else if(r==="host")l=e;else{const o=`Invalid selector :${r}`;throw new DOMException(o,c.SYNTAX_ERR)}return l??null}_matchSelector(a,e,f){const{type:r}=a,l=new Set;if(a.name===c.EMPTY)return l;const o=(0,k.unescapeSelector)(a.name);if(typeof o=="string"&&o!==a.name&&(a.name=o),e.nodeType===c.ELEMENT_NODE)switch(r){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(o,f);break}case c.SELECTOR_ID:{e.id===o&&l.add(e);break}case c.SELECTOR_CLASS:{e.classList.contains(o)&&l.add(e);break}case c.SELECTOR_PSEUDO_CLASS:return this._matchPseudoClassSelector(a,e,f);default:{const n=O.matcher.matchSelector(a,e,f);n&&l.add(n)}}else if(this.#d&&r===c.SELECTOR_PSEUDO_CLASS&&e.nodeType===c.DOCUMENT_FRAGMENT_NODE){if(o!=="has"&&c.REG_LOGICAL_PSEUDO.test(o))return this._matchPseudoClassSelector(a,e,f);if(c.REG_SHADOW_HOST.test(o)){const n=this._matchShadowHostPseudoClass(a,e,f);n&&l.add(n)}}return l}_matchLeaves(a,e,f){const{attributes:r,localName:l,nodeType:o}=e;let n=this.#_.get(a),u;if(n&&n.has(e)){const{attr:h,matched:s}=n.get(e);r?.length===h&&(u=s)}if(typeof u!="boolean"){let h;o===c.ELEMENT_NODE&&c.REG_FORM.test(l)?h=!1:h=!0;for(const s of a){const{name:t,type:i}=s;if(i===c.SELECTOR_PSEUDO_CLASS&&t==="dir"&&(h=!1),u=this._matchSelector(s,e,f).has(e),!u)break}h&&(n||(n=new WeakMap),n.set(e,{attr:r?.length,matched:u}),this.#_.set(a,n))}return!!u}_matchHTMLCollection(a,e={}){const{compound:f,filterLeaves:r}=e,l=new Set,o=a.length;if(o)if(f)for(let n=0;n<o;n++){const u=a[n];this._matchLeaves(r,u,e)&&l.add(u)}else{const n=[].slice.call(a);return new Set(n)}return l}_findDescendantNodes(a,e,f){const[r,...l]=a,o=l.length>0,{type:n}=r,u=(0,k.unescapeSelector)(r.name);typeof u=="string"&&u!==r.name&&(r.name=u);let h=new Set,s=!1;if(this.#d)s=!0;else switch(n){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,f);break}case c.SELECTOR_ID:{if(this.#t.nodeType===c.ELEMENT_NODE)s=!0;else{const t=this.#t.getElementById(u);t&&t!==e&&e.contains(t)&&(o?this._matchLeaves(l,t,f)&&h.add(t):h.add(t))}break}case c.SELECTOR_CLASS:{const t=e.getElementsByClassName(u);h=this._matchHTMLCollection(t,{compound:o,filterLeaves:l});break}case c.SELECTOR_TYPE:{if(this.#s.contentType==="text/html"&&!/[*|]/.test(u)){const t=e.getElementsByTagName(u);h=this._matchHTMLCollection(t,{compound:o,filterLeaves:l})}else s=!0;break}default:s=!0}return{nodes:h,pending:s}}_matchCombinator(a,e,f={}){const{combo:r,leaves:l}=a,{name:o}=r,{parentNode:n}=e,{dir:u}=f,h=new Set;if(u===S)switch(o){case"+":{const s=e.nextElementSibling;s&&this._matchLeaves(l,s,f)&&h.add(s);break}case"~":{if(n){const s=this._createTreeWalker(n);let t=this._traverse(e,s);for(t=s.nextSibling();t;)this._matchLeaves(l,t,f)&&h.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(l,t,f)&&h.add(t),t=s.nextSibling();break}case" ":default:{const{nodes:s,pending:t}=this._findDescendantNodes(l,e);if(s.size)return s;if(t){const i=this._createTreeWalker(e);let d=this._traverse(e,i);for(d=i.nextNode();d&&e.contains(d);)this._matchLeaves(l,d,f)&&h.add(d),d=i.nextNode()}}}else switch(o){case"+":{const s=e.previousElementSibling;s&&this._matchLeaves(l,s,f)&&h.add(s);break}case"~":{if(n){const s=this._createTreeWalker(n);let t=this._traverse(n,s);for(t=s.firstChild();t&&t!==e;)this._matchLeaves(l,t,f)&&h.add(t),t=s.nextSibling()}break}case">":{n&&this._matchLeaves(l,n,f)&&h.add(n);break}case" ":default:{const s=[];let t=n;for(;t;)this._matchLeaves(l,t,f)&&s.push(t),t=t.parentNode;if(s.length)return new Set(s.reverse())}}return h}_findNode(a,e){const{node:f}=e;let r=this._traverse(f,this.#f),l;if(r)for(r.nodeType!==c.ELEMENT_NODE?r=this.#f.nextNode():r===f&&r!==this.#t&&(r=this.#f.nextNode());r;){if(this._matchLeaves(a,r,{warn:this.#i})){l=r;break}r=this.#f.nextNode()}return l??null}_matchSelf(a){const e=[],f=this._matchLeaves(a,this.#e,{warn:this.#i});let r=!1;return f&&(e.push(this.#e),r=!0),[e,r]}_findLineal(a,e={}){const{complex:f}=e,r=[];let l=this._matchLeaves(a,this.#e,{warn:this.#i}),o=!1;if(l&&(r.push(this.#e),o=!0),!l||f){let n=this.#e.parentNode;for(;n&&(l=this._matchLeaves(a,n,{warn:this.#i}),l&&(r.push(n),o=!0),n.parentNode);)n=n.parentNode}return[r,o]}_findFirst(a){const e=[],f=this._findNode(a,{node:this.#e});let r=!1;return f&&(e.push(f),r=!0),[e,r]}_findFromHTMLCollection(a,e={}){const{complex:f,compound:r,filterLeaves:l,targetType:o}=e;let n=[],u=!1,h=!1;const s=a.length;if(s)if(this.#e.nodeType===c.ELEMENT_NODE)for(let t=0;t<s;t++){const i=a[t];if(i!==this.#e&&(this.#e.contains(i)||i.contains(this.#e))){if(r){if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else if(n.push(i),u=!0,o===g)break}}else if(f)if(r)for(let t=0;t<s;t++){const i=a[t];if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else n=[].slice.call(a),u=!0,h=!0;else if(r)for(let t=0;t<s;t++){const i=a[t];if(this._matchLeaves(l,i,{warn:this.#i})&&(n.push(i),u=!0,o===g))break}else n=[].slice.call(a),u=!0,h=!0;return[n,u,h]}_findEntryNodes(a,e,f){const{leaves:r}=a,[l,...o]=r,n=o.length>0,{name:u,type:h}=l;let s=[],t=!1,i=!1,d=!1;switch(h){case c.SELECTOR_PSEUDO_ELEMENT:{O.matcher.matchPseudoElementSelector(u,{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:f});else if(e===g&&this.#t.nodeType!==c.ELEMENT_NODE){const m=this.#t.getElementById(u);m&&(n?this._matchLeaves(o,m,{warn:this.#i})&&(s.push(m),i=!0):(s.push(m),i=!0))}else e===g?[s,i]=this._findFirst(r):d=!0;break}case c.SELECTOR_CLASS:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:f});else if(this.#t.nodeType===c.DOCUMENT_NODE){const m=this.#t.getElementsByClassName(u);m.length&&([s,i,t]=this._findFromHTMLCollection(m,{complex:f,compound:n,filterLeaves:o,targetType:e}))}else e===g?[s,i]=this._findFirst(r):d=!0;break}case c.SELECTOR_TYPE:{if(e===R)[s,i]=this._matchSelf(r);else if(e===C)[s,i]=this._findLineal(r,{complex:f});else if(this.#s.contentType==="text/html"&&this.#t.nodeType===c.DOCUMENT_NODE&&!/[*|]/.test(u)){const m=this.#t.getElementsByTagName(u);m.length&&([s,i,t]=this._findFromHTMLCollection(m,{complex:f,compound:n,filterLeaves:o,targetType:e}))}else e===g?[s,i]=this._findFirst(r):d=!0;break}default:if(e!==C&&c.REG_SHADOW_HOST.test(u)){if(this.#d&&this.#e.nodeType===c.DOCUMENT_FRAGMENT_NODE){const m=this._matchShadowHostPseudoClass(l,this.#e);m&&(s.push(m),i=!0)}}else e===R?[s,i]=this._matchSelf(r):e===C?[s,i]=this._findLineal(r,{complex:f}):e===g?[s,i]=this._findFirst(r):d=!0}return{collected:t,compound:n,filtered:i,nodes:s,pending:d}}_collectNodes(a){const e=this.#l.values();if(a===L||a===g){const f=new Set;let r=0;for(const{branch:l}of e){const o=l.length,n=o>1,u=l[0];let h,s;if(n){const{combo:p,leaves:[{name:_,type:w}]}=u,N=l[o-1],{leaves:[{name:A,type:v}]}=N;if(v===c.SELECTOR_PSEUDO_ELEMENT||v===c.SELECTOR_ID)h=x,s=N;else if(w===c.SELECTOR_PSEUDO_ELEMENT||w===c.SELECTOR_ID)h=S,s=u;else if(a===L)if(_==="*"&&w===c.SELECTOR_TYPE)h=x,s=N;else if(A==="*"&&v===c.SELECTOR_TYPE)h=S,s=u;else if(o===2){const{name:T}=p;/^[+~]$/.test(T)?(h=x,s=N):(h=S,s=u)}else h=S,s=u;else if(A==="*"&&v===c.SELECTOR_TYPE)h=S,s=u;else if(_==="*"&&w===c.SELECTOR_TYPE)h=x,s=N;else{let T;for(const{combo:P,leaves:[G]}of l){const{name:z,type:F}=G;if(F===c.SELECTOR_PSEUDO_CLASS&&z==="dir"){T=!1;break}if(!T&&P){const{name:H}=P;/^[+~]$/.test(H)&&(T=!0)}}T?(h=S,s=u):(h=x,s=N)}}else h=x,s=u;const{collected:t,compound:i,filtered:d,nodes:m,pending:b}=this._findEntryNodes(s,a,n);m.length?(this.#l[r].find=!0,this.#h[r]=m):b&&f.add(new Map([["index",r],["twig",s]])),this.#l[r].collected=t,this.#l[r].dir=h,this.#l[r].filtered=d||!i,r++}if(f.size){let l,o;this.#e!==this.#t&&this.#e.nodeType===c.ELEMENT_NODE?(l=this.#e,o=this.#f):(l=this.#t,o=this.#c);let n=this._traverse(l,o);for(;n;){let u=!1;if(this.#e.nodeType===c.ELEMENT_NODE?n===this.#e?u=!0:u=this.#e.contains(n):u=!0,u)for(const h of f){const{leaves:s}=h.get("twig");if(this._matchLeaves(s,n,{warn:this.#i})){const i=h.get("index");this.#l[i].filtered=!0,this.#l[i].find=!0,this.#h[i].push(n)}}n!==o.currentNode&&(n=this._traverse(n,o)),n=o.nextNode()}}}else{let f=0;for(const{branch:r}of e){const l=r[r.length-1],o=r.length>1,{compound:n,filtered:u,nodes:h}=this._findEntryNodes(l,a,o);h.length&&(this.#l[f].find=!0,this.#h[f]=h),this.#l[f].dir=x,this.#l[f].filtered=u||!n,f++}}return[this.#l,this.#h]}_getCombinedNodes(a,e,f){const r=[];for(const l of e){const o=this._matchCombinator(a,l,{dir:f,warn:this.#i});o.size&&r.push(...o)}return r.length?new Set(r):new Set}_matchNodeNext(a,e,f){const{combo:r,index:l}=f,{combo:o,leaves:n}=a[l],u={combo:r,leaves:n},h=this._getCombinedNodes(u,e,S);let s;if(h.size)if(l===a.length-1){const[t]=(0,E.sortNodes)(h);s=t}else s=this._matchNodeNext(a,h,{combo:o,index:l+1});return s??null}_matchNodePrev(a,e,f){const{index:r}=f,l=a[r],o=new Set([e]),n=this._getCombinedNodes(l,o,x);let u;if(n.size){if(r===0)u=e;else for(const h of n)if(this._matchNodePrev(a,h,{index:r-1}))return e}return u??null}_find(a){(a===L||a===g)&&this._prepareQuerySelectorWalker();const[[...e],f]=this._collectNodes(a),r=e.length;let l=new Set;for(let o=0;o<r;o++){const{branch:n,collected:u,dir:h,find:s}=e[o],t=n.length;if(t&&s){const i=f[o],d=i.length,m=t-1;if(m===0)if((a===L||a===g)&&this.#e.nodeType===c.ELEMENT_NODE)for(let b=0;b<d;b++){const p=i[b];if(p!==this.#e&&this.#e.contains(p)&&(l.add(p),a!==L))break}else if(a===L)if(l.size){const b=[...l];l=new Set([...b,...i]),this.#u=!0}else l=new Set(i);else{const[b]=i;l.add(b)}else if(a===L)if(h===S){let{combo:b}=n[0];for(const p of i){let _=new Set([p]);for(let w=1;w<t;w++){const{combo:N,leaves:A}=n[w],v={combo:b,leaves:A};if(_=this._getCombinedNodes(v,_,h),_.size)if(w===m)if(l.size){const T=[...l];l=new Set([...T,..._]),this.#u=!0}else l=_;else b=N;else break}}}else for(const b of i){let p=new Set([b]);for(let _=m-1;_>=0;_--){const w=n[_];if(p=this._getCombinedNodes(w,p,h),p.size)_===0&&(l.add(b),t>1&&l.size>1&&(this.#u=!0));else break}}else if(a===g&&h===S){const{combo:b}=n[0];let p;for(const _ of i)if(p=this._matchNodeNext(n,new Set([_]),{combo:b,index:1}),p){l.add(p);break}if(!p&&!u){const{leaves:_}=n[0],[w]=i;let N=this._findNode(_,{node:w});for(;N;){if(p=this._matchNodeNext(n,new Set([N]),{combo:b,index:1}),p){l.add(p);break}N=this._findNode(_,{node:N})}}}else{let b;for(const p of i)if(b=this._matchNodePrev(n,p,{index:m-1}),b){l.add(p);break}if(!b&&!u&&a===g){const{leaves:p}=n[m],[_]=i;let w=this._findNode(p,{node:_});for(;w;){if(b=this._matchNodePrev(n,w,{index:m-1}),b){l.add(w);break}w=this._findNode(p,{node:w})}}}}}return l}matches(a,e,f){let r;try{if(e?.nodeType!==c.ELEMENT_NODE){const n=`Unexpected node ${e?.nodeName}`;throw new TypeError(n)}const l=e.ownerDocument;if(l===this.#o&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_A.test(a),descendant:!0}))return this.#n||this._initNwsapi(l),this.#n.match(a,e);this._setup(a,e,f),r=this._find(R).size}catch(l){this._onError(l)}return!!r}closest(a,e,f){let r;try{if(e?.nodeType!==c.ELEMENT_NODE){const n=`Unexpected node ${e?.nodeName}`;throw new TypeError(n)}const l=e.ownerDocument;if(l===this.#o&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_A.test(a),descendant:!0}))return this.#n||this._initNwsapi(l),this.#n.closest(a,e);this._setup(a,e,f);const o=this._find(C);if(o.size){let n=this.#e;for(;n;){if(o.has(n)){r=n;break}n=n.parentNode}}}catch(l){this._onError(l)}return r??null}querySelector(a,e,f){let r;try{(0,E.verifyNode)(e);let l;if(e.nodeType===c.DOCUMENT_NODE?l=e:l=e.ownerDocument,l===this.#o&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_B.test(a),descendant:!1}))return this.#n||this._initNwsapi(l),this.#n.first(a,e);this._setup(a,e,f);const o=this._find(g);o.delete(this.#e),o.size&&([r]=(0,E.sortNodes)(o))}catch(l){this._onError(l)}return r??null}querySelectorAll(a,e,f){let r;try{(0,E.verifyNode)(e);let l;if(e.nodeType===c.DOCUMENT_NODE?l=e:l=e.ownerDocument,l===this.#o&&l.contentType==="text/html"&&(0,k.filterSelector)(a,{complex:c.REG_COMPLEX_B.test(a),descendant:!1}))return this.#n||this._initNwsapi(l),this.#n.select(a,e);this._setup(a,e,f);const o=this._find(L);o.delete(this.#e),o.size&&(this.#u?r=(0,E.sortNodes)(o):r=[...o])}catch(l){this._onError(l)}return r??[]}}0&&(module.exports={Finder});
|
|
2
2
|
//# sourceMappingURL=finder.js.map
|