@asamuzakjp/dom-selector 1.1.11 → 1.1.13
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/dom-util.js +1 -1
- package/dist/cjs/js/dom-util.js.map +3 -3
- package/dist/cjs/js/matcher.js +1 -1
- package/dist/cjs/js/matcher.js.map +3 -3
- package/package.json +5 -5
- package/src/js/dom-util.js +68 -26
- package/src/js/matcher.js +48 -33
- package/types/js/dom-util.d.ts +2 -1
package/dist/cjs/js/dom-util.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var O=Object.create;var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},E=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of h(t))!_.call(e,l)&&l!==i&&p(e,l,{get:()=>t[l],enumerable:!(s=g(t,l))||s.enumerable});return e};var v=(e,t,i)=>(i=e!=null?O(C(e)):{},E(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),w=e=>E(p({},"__esModule",{value:!0}),e);var A={};I(A,{getDirectionality:()=>N,getSlottedTextContent:()=>f,isContentEditable:()=>D,isInShadowTree:()=>x,isInclusive:()=>k,isNamespaceDeclared:()=>M,isPreceding:()=>P,selectorToNodeProps:()=>S});module.exports=w(A);var y=v(require("bidi-js"),1),r=require("./constant.js");const c=(0,y.default)(),x=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE||e.nodeType===r.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:s,mode:l,nodeType:n,parentNode:o}=i;if(s&&l&&n===r.DOCUMENT_FRAGMENT_NODE&&r.REG_SHADOW_MODE.test(l)){t=!0;break}i=o}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&x(e)){const i=e.assignedNodes();if(i.length){for(const s of i)if(t=s.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},N=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE){const{dir:i,localName:s,parentNode:l}=e,n=/^(?:ltr|rtl)$/;if(n.test(i))t=i;else if(i==="auto"){let o;switch(s){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(o=e.value);break}case"slot":{o=f(e);break}case"textarea":{o=e.value;break}default:{const a=[].slice.call(e.childNodes);for(const m of a){const{dir:u,localName:T,nodeType:d,textContent:b}=m;if(d===r.TEXT_NODE?o=b.trim():d===r.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(T)&&(!u||!n.test(u))&&(T==="slot"?o=f(m):o=b.trim()),o)break}}}if(o){const{paragraphs:[{level:a}]}=c.getEmbeddingLevels(o);a%2===1?t="rtl":t="ltr"}if(!t)if(l){const{nodeType:a}=l;a===r.ELEMENT_NODE?t=N(l):(a===r.DOCUMENT_NODE||a===r.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(s==="bdi"){const o=e.textContent.trim();if(o){const{paragraphs:[{level:a}]}=c.getEmbeddingLevels(o);a%2===1?t="rtl":t="ltr"}t||l||(t="ltr")}else if(s==="input"&&e.type==="tel")t="ltr";else if(l){if(s==="slot"){const o=f(e);if(o){const{paragraphs:[{level:a}]}=c.getEmbeddingLevels(o);a%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:o}=l;o===r.ELEMENT_NODE?t=N(l):(o===r.DOCUMENT_NODE||o===r.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},D=(e={})=>{let t;if(e.nodeType===r.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const i=e.getAttribute("contenteditable");if(i===""||/^(?:plaintext-only|true)$/.test(i))t=!0;else if(i==="inherit"){let s=e.parentNode;for(;s;){if(D(s)){t=!0;break}s=s.parentNode}}}}return!!t},M=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===r.ELEMENT_NODE){const s=`xmlns:${e}`,l=t.ownerDocument.documentElement;let n=t;for(;n;){if(typeof n.hasAttribute=="function"&&n.hasAttribute(s)){i=!0;break}else if(n===l)break;n=n.parentNode}}return!!i},k=(e={},t={})=>{let i;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE){const s=t.compareDocumentPosition(e);i=s&r.DOCUMENT_POSITION_CONTAINS||s&r.DOCUMENT_POSITION_CONTAINED_BY}return!!i},P=(e={},t={})=>{let i;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE){const s=t.compareDocumentPosition(e);i=s&r.DOCUMENT_POSITION_PRECEDING||s&r.DOCUMENT_POSITION_CONTAINS}return!!i},S=(e,t)=>{let i,s;if(e&&typeof e=="string")e.indexOf("|")>-1?[i,s]=e.split("|"):(i="*",s=e);else throw new DOMException(`Invalid selector ${e}`,r.SYNTAX_ERR);return{prefix:i,tagName:s}};0&&(module.exports={getDirectionality,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,selectorToNodeProps});
|
|
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,
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,
|
|
6
|
-
"names": ["dom_util_exports", "__export", "getDirectionality", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isNamespaceDeclared", "
|
|
4
|
+
"sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n REG_SHADOW_MODE, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\n\n/* bidi */\nconst bidi = bidiFactory();\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 regDir = /^(?:ltr|rtl)$/;\n if (regDir.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type)) {\n text = node.value;\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(itemLocalName) &&\n (!itemDir || !regDir.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = bidi.getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = bidi.getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = bidi.getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n const attr = `xmlns:${ns}`;\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n if (typeof parent.hasAttribute === 'function' &&\n parent.hasAttribute(attr)) {\n res = true;\n break;\n } else if (parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n return !!res;\n};\n\n/**\n * is inclusive - nodeA and nodeB are in inclusive relation\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isInclusive = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_CONTAINS ||\n posBit & DOCUMENT_POSITION_CONTAINED_BY;\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * selector to node properties - e.g. ns|E -> { prefix: ns, tagName: E }\n * @param {string} selector - type selector\n * @param {object} [node] - Element node\n * @returns {object} - node properties\n */\nexport const selectorToNodeProps = (selector, node) => {\n let prefix;\n let tagName;\n if (selector && typeof selector === 'string') {\n if (selector.indexOf('|') > -1) {\n [prefix, tagName] = selector.split('|');\n } else {\n prefix = '*';\n tagName = selector;\n }\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return {\n prefix,\n tagName\n };\n};\n"],
|
|
5
|
+
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAV,GAKA,IAAAW,EAAwB,wBAGxBC,EAIO,yBAGP,MAAMC,KAAO,EAAAC,SAAY,EAOZT,EAAiB,CAACU,EAAO,CAAC,IAAM,CAC3C,IAAIC,EACJ,GAAID,EAAK,WAAa,gBAClBA,EAAK,WAAa,yBAAwB,CAC5C,IAAIE,EAAUF,EACd,KAAOE,GAAS,CACd,KAAM,CAAE,KAAAC,EAAM,KAAAC,EAAM,SAAAC,EAAU,WAAAC,CAAW,EAAIJ,EAC7C,GAAIC,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D,EAAM,wBAAwBD,CAAK,EAClDlB,EAAMoB,EAAS,+BACTA,EAAS,4BACjB,CACA,MAAO,CAAC,CAACpB,CACX,EAQab,EAAsB,CAACkC,EAAU5B,IAAS,CACrD,IAAI6B,EACAC,EACJ,GAAIF,GAAY,OAAOA,GAAa,SAC9BA,EAAS,QAAQ,GAAG,EAAI,GAC1B,CAACC,EAAQC,CAAO,EAAIF,EAAS,MAAM,GAAG,GAEtCC,EAAS,IACTC,EAAUF,OAGZ,OAAM,IAAI,aAAa,oBAAoBA,CAAQ,GAAI,YAAU,EAEnE,MAAO,CACL,OAAAC,EACA,QAAAC,CACF,CACF",
|
|
6
|
+
"names": ["dom_util_exports", "__export", "getDirectionality", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isInclusive", "isNamespaceDeclared", "isPreceding", "selectorToNodeProps", "__toCommonJS", "import_bidi_js", "import_constant", "bidi", "bidiFactory", "node", "bool", "refNode", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "regDir", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "attr", "parent", "ns", "root", "nodeA", "nodeB", "posBit", "selector", "prefix", "tagName"]
|
|
7
7
|
}
|
package/dist/cjs/js/matcher.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var F=Object.create;var M=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var W=(S,s)=>{for(var e in s)M(S,e,{get:s[e],enumerable:!0})},z=(S,s,e,c)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of j(s))!G.call(S,h)&&h!==e&&M(S,h,{get:()=>s[h],enumerable:!(c=V(s,h))||c.enumerable});return S};var q=(S,s,e)=>(e=S!=null?F(H(S)):{},z(s||!S||!S.__esModule?M(e,"default",{value:S,enumerable:!0}):e,S)),X=S=>z(M({},"__esModule",{value:!0}),S);var J={};W(J,{Matcher:()=>Y});module.exports=X(J);var B=q(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),k=require("./parser.js"),l=require("./constant.js");const R="next",U="prev",I="all",C="first",D="lineal",P="self";class Y{#i;#r;#a;#e;#l;#t;#o;#s;constructor(s,e,c={}){const{warn:h}=c;this.#r=new Map([[l.SELECTOR_PSEUDO_ELEMENT,l.BIT_01],[l.SELECTOR_ID,l.BIT_02],[l.SELECTOR_CLASS,l.BIT_04],[l.SELECTOR_TYPE,l.BIT_08],[l.SELECTOR_ATTR,l.BIT_16],[l.SELECTOR_PSEUDO_CLASS,l.BIT_32]]),this.#a=new WeakMap,this.#o=s,this.#e=e,this.#s=!!h,[this.#i,this.#l]=this._prepare(s),this.#t=this._getRoot(e)}_onError(s){if(s instanceof DOMException&&s.name===l.NOT_SUPPORTED_ERR)this.#s&&console.warn(s.message);else throw s}_getRoot(s=this.#e){let e,c;switch(s.nodeType){case l.DOCUMENT_NODE:{e=s,c=s;break}case l.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,c=s;break}case l.ELEMENT_NODE:{if((0,E.isSameOrDescendant)(s))e=s.ownerDocument,c=s.ownerDocument;else{let r=s;for(;r&&r.parentNode;)r=r.parentNode;e=r.ownerDocument,c=r}break}default:throw new TypeError(`Unexpected node ${s.nodeName}`)}const h=(0,E.isInShadowTree)(s);return{document:e,root:c,shadow:h}}_sortLeaves(s){const e=[...s];return e.length>1&&e.sort((c,h)=>{const{type:r}=c,{type:u}=h,m=this.#r.get(r),f=this.#r.get(u);let t;return m===f?t=0:m>f?t=1:t=-1,t}),e}_prepare(s=this.#o){const e=(0,k.parseSelector)(s),c=(0,k.walkAST)(e),h=[],r=[];let u=0;for(const[...m]of c){const f=[];let t=m.shift();if(t&&t.type!==l.COMBINATOR){const i=new Set;for(;t;){if(t.type===l.COMBINATOR){const[o]=m;if(o.type===l.COMBINATOR){const d=`Invalid combinator ${t.name}${o.name}`;throw new DOMException(d,l.SYNTAX_ERR)}f.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(m.length)t=m.shift();else{f.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}h.push({branch:f,find:null,skip:!1}),r[u]=new Set,u++}return[h,r]}_collectNthChild(s,e){const{a:c,b:h,reverse:r,selector:u}=s,{parentNode:m}=e,f=new Set;let t;if(u&&(this.#a.has(u)?t=this.#a.get(u):(t=(0,k.walkAST)(u),this.#a.set(u,t))),m){const i=[].slice.call(m.children),o=i.length;if(o){const d=new Set;if(t){const a=t.length;for(const n of i){let b;for(let p=0;p<a;p++){const N=t[p];if(b=this._matchLeaves(N,n),!b)break}b&&d.add(n)}}if(r&&i.reverse(),c===0){if(h>0&&h<=o){if(d.size)for(let a=0;a<o;a++){const n=i[a];if(d.has(n)){f.add(n);break}}else if(!u){const a=i[h-1];f.add(a)}}}else{let a=h-1;if(c>0)for(;a<0;)a+=c;if(a>=0&&a<o){let n=c>0?0:h-1;for(let b=0;b<o&&a>=0&&a<o;b++){const p=i[b];d.size?d.has(p)&&(n===a&&(f.add(p),a+=c),c>0?n++:n--):b===a&&(u||f.add(p),a+=c)}}}}}else{const{root:i}=this.#t;if(e===i&&i.nodeType===l.ELEMENT_NODE&&c+h===1)if(t){const o=t.length;let d;for(let a=0;a<o;a++){const n=t[a];if(d=this._matchLeaves(n,e),d)break}d&&f.add(e)}else f.add(e)}return f}_collectNthOfType(s,e){const{a:c,b:h,reverse:r}=s,{localName:u,parentNode:m,prefix:f}=e,t=new Set;if(m){const i=[].slice.call(m.children),o=i.length;if(o)if(r&&i.reverse(),c===0){if(h>0&&h<=o){let d=0;for(let a=0;a<o;a++){const n=i[a],{localName:b,prefix:p}=n;if(b===u&&p===f){if(d===h-1){t.add(n);break}d++}}}}else{let d=h-1;if(c>0)for(;d<0;)d+=c;if(d>=0&&d<o){let a=c>0?0:h-1;for(let n=0;n<o;n++){const b=i[n],{localName:p,prefix:N}=b;if(p===u&&N===f){if(a===d&&(t.add(b),d+=c),d<0||d>=o)break;c>0?a++:a--}}}}}else{const{root:i}=this.#t;e===i&&i.nodeType===l.ELEMENT_NODE&&c+h===1&&t.add(e)}return t}_matchAnPlusB(s,e,c){const{nth:{a:h,b:r,name:u},selector:m}=s,f=(0,k.unescapeSelector)(u),t=new Map;f?(f==="even"?(t.set("a",2),t.set("b",0)):f==="odd"&&(t.set("a",2),t.set("b",1)),c.indexOf("last")>-1&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof r=="string"&&/-?\d+/.test(r)?t.set("b",r*1):t.set("b",0),c.indexOf("last")>-1&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(c)){m&&t.set("selector",m);const o=Object.fromEntries(t),d=this._collectNthChild(o,e);d.size&&(i=d)}else if(/^nth-(?:last-)?of-type$/.test(c)){const o=Object.fromEntries(t),d=this._collectNthOfType(o,e);d.size&&(i=d)}}return i}_matchPseudoElementSelector(s,e={}){const{forgive:c}=e;switch(s){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,l.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}()`,l.NOT_SUPPORTED_ERR);break}default:if(s.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,l.NOT_SUPPORTED_ERR)}else if(!c)throw new DOMException(`Unknown pseudo-element ::${s}`,l.SYNTAX_ERR)}}_matchDirectionPseudoClass(s,e){const c=(0,k.unescapeSelector)(s.name),h=(0,E.getDirectionality)(e);let r;return c===h&&(r=e),r??null}_matchLanguagePseudoClass(s,e){const c=(0,k.unescapeSelector)(s.name);let h;if(c)if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let r=e.parentNode;for(;r&&r.nodeType===l.ELEMENT_NODE;){if(r.hasAttribute("lang")){r.getAttribute("lang")&&(h=e);break}r=r.parentNode}}else{const r=`(?:-${l.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${l.ALPHA_NUM}${r}$`,"i").test(c)){let m;if(c.indexOf("-")>-1){const[f,t,...i]=c.split("-");let o;f==="*"?o=`${l.ALPHA_NUM}${r}`:o=`${f}${r}`;const d=`-${t}${r}`,a=i.length;let n="";if(a)for(let b=0;b<a;b++)n+=`-${i[b]}${r}`;m=new RegExp(`^${o}${d}${n}$`,"i")}else m=new RegExp(`^${c}${r}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(h=e);else{let f=e.parentNode;for(;f&&f.nodeType===l.ELEMENT_NODE;){if(f.hasAttribute("lang")){const t=f.getAttribute("lang");m.test(t)&&(h=e);break}f=f.parentNode}}}}return h??null}_matchHasPseudoFunc(s,e){let c;if(Array.isArray(s)&&s.length){const[h]=s,{type:r}=h;let u;r===l.COMBINATOR?u=s.shift():u={name:" ",type:l.COMBINATOR};const m=[];for(;s.length;){const[i]=s,{type:o}=i;if(o===l.COMBINATOR)break;m.push(s.shift())}const f={combo:u,leaves:m},t=this._matchCombinator(f,e,{find:R});if(t.size)if(s.length){for(const i of t)if(c=this._matchHasPseudoFunc(Object.assign([],s),i),c)break}else c=!0}return!!c}_matchLogicalPseudoFunc(s,e){const{astName:c="",branches:h=[],selector:r="",twigBranches:u=[]}=s;let m;if(c==="has")if(r.includes(":has("))m=null;else{const f=h.length;let t;for(let i=0;i<f;i++){const o=h[i];if(t=this._matchHasPseudoFunc(Object.assign([],o),e),t)break}t&&(m=e)}else{const f=/^(?:is|where)$/.test(c),t=u.length;let i;for(let o=0;o<t;o++){const d=u[o],a=d.length-1,{leaves:n}=d[a];if(i=this._matchLeaves(n,e,{forgive:f}),i&&a>0){let b=new Set([e]);for(let p=a-1;p>=0;p--){const N=d[p],y=[];for(const x of b){const L=this._matchCombinator(N,x,{forgive:f,find:U});L.size&&y.push(...L)}if(y.length)if(p===0){i=!0;break}else b=new Set(y);else{i=!1;break}}}if(i)break}c==="not"?i||(m=e):i&&(m=e)}return m??null}_matchPseudoClassSelector(s,e,c={}){const{children:h}=s,{localName:r,parentNode:u}=e,{forgive:m}=c,f=(0,k.unescapeSelector)(s.name);let t=new Set;if(l.REG_LOGICAL_PSEUDO.test(f)){let i;if(this.#a.has(s))i=this.#a.get(s);else{const d=(0,k.walkAST)(s),a=[],n=[];for(const[...b]of d){for(const x of b){const L=(0,k.generateCSS)(x);a.push(L)}const p=[],N=new Set;let y=b.shift();for(;y;)if(y.type===l.COMBINATOR?(p.push({combo:y,leaves:[...N]}),N.clear()):y&&N.add(y),b.length)y=b.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}n.push(p)}i={astName:f,branches:d,twigBranches:n,selector:a.join(",")},this.#a.set(s,i)}const o=this._matchLogicalPseudoFunc(i,e);o&&t.add(o)}else if(Array.isArray(h)){const[i]=h;if(/^nth-(?:last-)?(?:child|of-type)$/.test(f)){const o=this._matchAnPlusB(i,e,f);o.size&&(t=o)}else if(f==="dir"){const o=this._matchDirectionPseudoClass(i,e);o&&t.add(o)}else if(f==="lang"){const o=this._matchLanguagePseudoClass(i,e);o&&t.add(o)}else switch(f){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}()`,l.NOT_SUPPORTED_ERR);break}default:if(!m)throw new DOMException(`Unknown pseudo-class :${f}()`,l.SYNTAX_ERR)}}else{const{document:i,root:o}=this.#t,{documentElement:d}=i,a=new URL(i.URL),n=/^a(?:rea)?$/,b=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,p=/^(?:(?:inpu|selec)t|button|form|textarea)$/,N=/^d(?:etails|ialog)$/,y=/^(?:checkbox|radio)$/,x=/^(?:date(?:time-local)?|month|time|week)$/,L=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,O=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(f){case"any-link":case"link":{n.test(r)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(n.test(r)&&e.hasAttribute("href")){const w=new URL(e.getAttribute("href"),a.href);w.origin===a.origin&&w.pathname===a.pathname&&t.add(e)}break}case"visited":break;case"target":{e.id&&a.hash&&a.hash===`#${e.id}`&&(0,E.isSameOrDescendant)(e)&&t.add(e);break}case"target-within":{if(a.hash){const w=a.hash.replace(/^#/,"");let g=i.getElementById(w);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===l.ELEMENT_NODE?e===this.#e&&t.add(e):e===d&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let w=i.activeElement;for(;w;){if(w===e){t.add(e);break}w=w.parentNode}break}case"open":{N.test(r)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{N.test(r)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(b.test(r)||(0,B.default)(r))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let w=u;for(;w&&w.localName!=="fieldset";)w=w.parentNode;w&&u.localName!=="legend"&&w.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(b.test(r)||(0,B.default)(r))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(r){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||O.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(r){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||O.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let w;r==="textarea"?w=e:r==="input"&&(e.hasAttribute("type")?O.test(e.getAttribute("type"))&&(w=e):w=e),w&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&r==="input"&&e.hasAttribute("type")&&y.test(e.getAttribute("type"))||e.selected&&r==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&r==="input"&&e.type==="checkbox"||r==="progress"&&!e.hasAttribute("value"))t.add(e);else if(r==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const w=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=d);const _=[].slice.call(g.getElementsByTagName("input"));let T;for(const A of _)if(A.getAttribute("type")==="radio"&&(w?A.getAttribute("name")===w&&(T=!!A.checked):A.hasAttribute("name")||(T=!!A.checked),T))break;T||t.add(e)}break}case"default":{const w=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(r==="button"&&!(e.hasAttribute("type")&&w.test(e.getAttribute("type")))||r==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let _=e.parentNode;for(;_&&_.localName!=="form";)_=_.parentNode;if(_){const T=i.createNodeIterator(_,l.SHOW_ELEMENT);let A=T.nextNode();for(;A;){const $=A.localName;let v;if($==="button"?v=!(A.hasAttribute("type")&&w.test(A.getAttribute("type"))):$==="input"&&(v=A.hasAttribute("type")&&g.test(A.getAttribute("type"))),v){A===e&&t.add(e);break}A=T.nextNode()}}}else if(r==="input"&&e.hasAttribute("type")&&y.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(r==="option"){let _=!1,T=u;for(;T&&T.localName!=="datalist";){if(T.localName==="select"){(T.multiple||T.hasAttribute("multiple"))&&(_=!0);break}T=T.parentNode}if(_)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const A=u.firstElementChild,$=new Set;let v=A;for(;v;){if(v.selected||v.hasAttribute("selected")){$.add(v);break}v=v.nextElementSibling}$.size||$.add(A),$.has(e)&&t.add(e)}}break}case"valid":{if(p.test(r))e.checkValidity()&&t.add(e);else if(r==="fieldset"){const w=i.createNodeIterator(e,l.SHOW_ELEMENT);let g=w.nextNode();g===e&&(g=w.nextNode());let _;for(;g&&!(p.test(g.localName)&&(_=g.checkValidity(),!_));)g=w.nextNode();_&&t.add(e)}break}case"invalid":{if(p.test(r))e.checkValidity()||t.add(e);else if(r==="fieldset"){const w=i.createNodeIterator(e,l.SHOW_ELEMENT);let g=w.nextNode();g===e&&(g=w.nextNode());let _;for(;g&&!(p.test(g.localName)&&(_=g.checkValidity(),!_));)g=w.nextNode();_||t.add(e)}break}case"in-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&!(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&(e.hasAttribute("min")||e.hasAttribute("max")||e.getAttribute("type")==="range")&&t.add(e);break}case"out-of-range":{r==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let w;if(/^(?:select|textarea)$/.test(r))w=e;else if(r==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||y.test(g)||x.test(g)||O.test(g))&&(w=e)}else w=e;w&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let w;if(/^(?:select|textarea)$/.test(r))w=e;else if(r==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||y.test(g)||x.test(g)||O.test(g))&&(w=e)}else w=e;w&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===d&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const w=e.childNodes.values();let g;for(const _ of w)if(g=_.nodeType!==l.ELEMENT_NODE&&_.nodeType!==l.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(u&&e===u.firstElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(u&&e===u.lastElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(u&&e===u.firstElementChild&&e===u.lastElementChild||e===o&&o.nodeType===l.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1},e);w&&t.add(w)}else e===o&&o.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w&&t.add(w)}else e===o&&o.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1},e);if(w===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===o&&o.nodeType===l.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${f}`,l.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,l.NOT_SUPPORTED_ERR);break}default:if(f.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,l.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${f}`,l.SYNTAX_ERR)}}return t}_matchAttributeSelector(s,e){const{flags:c,matcher:h,name:r,value:u}=s;if(typeof c=="string"&&!/^[is]$/i.test(c)){const t=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${t}`,l.SYNTAX_ERR)}const{attributes:m}=e;let f;if(m&&m.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof c=="string"&&/^s$/i.test(c)?i=!1:i=!0:typeof c=="string"&&/^i$/i.test(c)?i=!0:i=!1;let o=(0,k.unescapeSelector)(r.name);i&&(o=o.toLowerCase());const d=new Set;if(o.indexOf("|")>-1){const{prefix:a,tagName:n}=(0,E.selectorToNodeProps)(o);for(let{name:b,value:p}of m)switch(i&&(b=b.toLowerCase(),p=p.toLowerCase()),a){case"":{n===b&&d.add(p);break}case"*":{b.indexOf(":")>-1?b.endsWith(`:${n}`)&&d.add(p):n===b&&d.add(p);break}default:if(b.indexOf(":")>-1){const[N,y]=b.split(":");a===N&&n===y&&(0,E.isNamespaceDeclared)(a,e)&&d.add(p)}}}else for(let{name:a,value:n}of m)if(i&&(a=a.toLowerCase(),n=n.toLowerCase()),a.indexOf(":")>-1){const[b,p]=a.split(":");if(b==="xml"&&p==="lang")continue;o===p&&d.add(n)}else o===a&&d.add(n);if(d.size){const{name:a,value:n}=u||{};let b;switch(a?i?b=a.toLowerCase():b=a:n?i?b=n.toLowerCase():b=n:n===""&&(b=n),h){case"=":{typeof b=="string"&&d.has(b)&&(f=e);break}case"~=":{if(b&&typeof b=="string"){for(const p of d)if(new Set(p.split(/\s+/)).has(b)){f=e;break}}break}case"|=":{if(b&&typeof b=="string"){let p;for(const N of d)if(N===b||N.startsWith(`${b}-`)){p=N;break}p&&(f=e)}break}case"^=":{if(b&&typeof b=="string"){let p;for(const N of d)if(N.startsWith(`${b}`)){p=N;break}p&&(f=e)}break}case"$=":{if(b&&typeof b=="string"){let p;for(const N of d)if(N.endsWith(`${b}`)){p=N;break}p&&(f=e)}break}case"*=":{if(b&&typeof b=="string"){let p;for(const N of d)if(N.includes(`${b}`)){p=N;break}p&&(f=e)}break}case null:default:f=e}}}return f??null}_matchClassSelector(s,e){const c=(0,k.unescapeSelector)(s.name);let h;return e.classList.contains(c)&&(h=e),h??null}_matchIDSelector(s,e){const c=(0,k.unescapeSelector)(s.name),{id:h}=e;let r;return c===h&&(r=e),r??null}_matchTypeSelector(s,e,c={}){const h=(0,k.unescapeSelector)(s.name),{localName:r,prefix:u}=e,{forgive:m}=c,{document:f}=this.#t;let{prefix:t,tagName:i}=(0,E.selectorToNodeProps)(h,e);f.contentType==="text/html"&&(t=t.toLowerCase(),i=i.toLowerCase());let o,d;r.indexOf(":")>-1?[o,d]=r.split(":"):(o=u||"",d=r);let a;if(t===""&&o==="")e.namespaceURI===null&&(i==="*"||i===d)&&(a=e);else if(t==="*")(i==="*"||i===d)&&(a=e);else if(t===o){if((0,E.isNamespaceDeclared)(t,e))(i==="*"||i===d)&&(a=e);else if(!m)throw new DOMException(`Undeclared namespace ${t}`,l.SYNTAX_ERR)}else if(t&&!m&&!(0,E.isNamespaceDeclared)(t,e))throw new DOMException(`Undeclared namespace ${t}`,l.SYNTAX_ERR);return a??null}_matchShadowHostPseudoClass(s,e){const{children:c}=s,h=(0,k.unescapeSelector)(s.name);let r;if(Array.isArray(c)){const[u]=(0,k.walkAST)(c[0]),[...m]=u,{host:f}=e;if(h==="host"){let t;for(const i of m){const{type:o}=i;if(o===l.COMBINATOR){const d=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${d}`,l.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}t&&(r=e)}else if(h==="host-context"){let t=f,i;for(;t;){for(const o of m){const{type:d}=o;if(d===l.COMBINATOR){const a=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${a}`,l.SYNTAX_ERR)}if(i=this._matchSelector(o,t).has(t),!i)break}if(i)break;t=t.parentNode}i&&(r=e)}}else if(h==="host")r=e;else throw new DOMException(`Invalid selector :${h}`,l.SYNTAX_ERR);return r??null}_matchSelector(s,e,c){const{type:h}=s,r=(0,k.unescapeSelector)(s.name),{shadow:u}=this.#t;let m=new Set;if(e.nodeType===l.ELEMENT_NODE)switch(h){case l.SELECTOR_ATTR:{const f=this._matchAttributeSelector(s,e);f&&m.add(f);break}case l.SELECTOR_CLASS:{const f=this._matchClassSelector(s,e);f&&m.add(f);break}case l.SELECTOR_ID:{const f=this._matchIDSelector(s,e);f&&m.add(f);break}case l.SELECTOR_PSEUDO_CLASS:{const f=this._matchPseudoClassSelector(s,e,c);f.size&&(m=f);break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(r,c);break}case l.SELECTOR_TYPE:default:{const f=this._matchTypeSelector(s,e,c);f&&m.add(f)}}else if(u&&h===l.SELECTOR_PSEUDO_CLASS&&e.nodeType===l.DOCUMENT_FRAGMENT_NODE){if(r!=="has"&&l.REG_LOGICAL_PSEUDO.test(r)){const f=this._matchPseudoClassSelector(s,e,c);f.size&&(m=f)}else if(l.REG_SHADOW_HOST.test(r)){const f=this._matchShadowHostPseudoClass(s,e);f&&m.add(f)}}return m}_matchLeaves(s,e,c){let h;for(const r of s)if(h=this._matchSelector(r,e,c).has(e),!h)break;return!!h}_findDescendantNodes(s,e){const[c,...h]=s,{type:r}=c,u=(0,k.unescapeSelector)(c.name),m=h.length>0,{document:f,root:t,shadow:i}=this.#t;let o=new Set,d=!1;if(i)d=!0;else switch(r){case l.SELECTOR_ID:{if(t.nodeType===l.ELEMENT_NODE)d=!0;else{const a=t.getElementById(u);if(a&&a!==e){const n=(0,E.isSameOrDescendant)(a,e);let b;n&&(b=a),b&&(m?this._matchLeaves(h,b)&&o.add(b):o.add(b))}}break}case l.SELECTOR_CLASS:{const a=[].slice.call(e.getElementsByClassName(u));if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a);break}case l.SELECTOR_TYPE:{if(f.contentType==="text/html"&&!/[*|]/.test(u)){const a=[].slice.call(e.getElementsByTagName(u));if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a)}else d=!0;break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:d=!0}return{nodes:o,pending:d}}_matchCombinator(s,e,c={}){const{combo:h,leaves:r}=s,{name:u}=h,{find:m,forgive:f}=c;let t=new Set;if(m===R)switch(u){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(r,i,{forgive:f})&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[].slice.call(e.children);for(const o of i)this._matchLeaves(r,o,{forgive:f})&&t.add(o);break}case" ":default:{const{nodes:i,pending:o}=this._findDescendantNodes(r,e);if(i.size)t=i;else if(o){const{document:d}=this.#t,a=d.createNodeIterator(e,l.SHOW_ELEMENT);let n=a.nextNode();for(n===e&&(n=a.nextNode());n;)this._matchLeaves(r,n,{forgive:f})&&t.add(n),n=a.nextNode()}}}else switch(u){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case"~":{const i=[];let o=e.previousElementSibling;for(;o;)this._matchLeaves(r,o,{forgive:f})&&i.push(o),o=o.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(r,i,{forgive:f})&&t.add(i);break}case" ":default:{const i=[];let o=e.parentNode;for(;o;)this._matchLeaves(r,o,{forgive:f})&&i.push(o),o=o.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(s,e){const{leaves:[c,...h]}=s,{type:r}=c,u=(0,k.unescapeSelector)(c.name),m=h.length>0,{document:f,root:t,shadow:i}=this.#t;let o=new Set,d=!1;switch(r){case l.SELECTOR_ID:{let a;if(e===P)this._matchLeaves([c],this.#e)&&(a=this.#e);else if(e===D){let n=this.#e;for(;n;){if(this._matchLeaves([c],n)){a=n;break}n=n.parentNode}}else e===I||t.nodeType===l.ELEMENT_NODE?d=!0:a=t.getElementById(u);a&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a));break}case l.SELECTOR_CLASS:{let a=[];if(e===P)this.#e.nodeType===l.ELEMENT_NODE&&this.#e.classList.contains(u)&&a.push(this.#e);else if(e===D){let n=this.#e;for(;n&&n.nodeType===l.ELEMENT_NODE;)n.classList.contains(u)&&a.push(n),n=n.parentNode}else if(t.nodeType===l.DOCUMENT_FRAGMENT_NODE){const n=[].slice.call(t.children);for(const b of n){b.classList.contains(u)&&a.push(b);const p=[].slice.call(b.getElementsByClassName(u));a.push(...p)}}else a=[].slice.call(t.getElementsByClassName(u));if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a);break}case l.SELECTOR_TYPE:{let a=[];if(e===P)this.#e.nodeType===l.ELEMENT_NODE&&this._matchLeaves([c],this.#e)&&a.push(this.#e);else if(e===D){let n=this.#e;for(;n&&n.nodeType===l.ELEMENT_NODE;)this._matchLeaves([c],n)&&a.push(n),n=n.parentNode}else if(f.contentType!=="text/html"||/[*|]/.test(u))d=!0;else if(t.nodeType===l.DOCUMENT_FRAGMENT_NODE){const n=u.toLowerCase(),b=[].slice.call(t.children);for(const p of b){p.localName===n&&a.push(p);const N=[].slice.call(p.getElementsByTagName(u));a.push(...N)}}else a=[].slice.call(t.getElementsByTagName(u));if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a);break}case l.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:{const a=[];if(e!==D&&l.REG_SHADOW_HOST.test(u)){if(i&&this.#e.nodeType===l.DOCUMENT_FRAGMENT_NODE){const n=this._matchShadowHostPseudoClass(c,this.#e);n&&a.push(n)}}else if(e===P)this._matchLeaves([c],this.#e)&&a.push(this.#e);else if(e===D){let n=this.#e;for(;n;)this._matchLeaves([c],n)&&a.push(n),n=n.parentNode}else d=!0;if(a.length)if(m)for(const n of a)this._matchLeaves(h,n)&&o.add(n);else o=new Set(a)}}if(m&&!d&&!o.size){const a=h[h.length-1],{type:n}=a;if(n===l.SELECTOR_PSEUDO_CLASS){let b;t.nodeType===l.ELEMENT_NODE?b=t:b=t.firstElementChild,this._matchPseudoClassSelector(a,b)}}return{nodes:o,pending:d}}_getFirstTwig(s){const e=s.length-1,c=s[0];let h,r;if(e){const u=s[e],{leaves:[{type:m}]}=u;m===l.SELECTOR_PSEUDO_ELEMENT||m===l.SELECTOR_ID?(h=U,r=u):(h=R,r=c)}else h=U,r=c;return{find:h,twig:r}}_collectNodes(s){const e=this.#i.values();if(s===I||s===C){const c=new Set;let h=0;for(const{branch:r}of e){const{find:u,twig:m}=this._getFirstTwig(r),{nodes:f,pending:t}=this._findNodes(m,s);f.size?this.#l[h]=f:t?c.add(new Map([["index",h],["twig",m]])):this.#i[h].skip=!0,this.#i[h].find=u,h++}if(c.size){const{document:r,root:u}=this.#t,m=r.createNodeIterator(u,l.SHOW_ELEMENT);let f=m.nextNode();for(;f;){let t=!1;if(this.#e.nodeType===l.ELEMENT_NODE?t=(0,E.isSameOrDescendant)(f,this.#e):t=!0,t)for(const i of c){const{leaves:o}=i.get("twig");if(this._matchLeaves(o,f)){const a=i.get("index");this.#l[a].add(f)}}f=m.nextNode()}}}else{let c=0;for(const{branch:h}of e){const r=h[h.length-1],{nodes:u}=this._findNodes(r,s);u.size?this.#l[c]=u:this.#i[c].skip=!0,this.#i[c].find=U,c++}}return[this.#i,this.#l]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((c,h)=>{const r=c.compareDocumentPosition(h);let u;return r&l.DOCUMENT_POSITION_PRECEDING||r&l.DOCUMENT_POSITION_CONTAINS?u=1:u=-1,u}),e}_matchNodes(s){const[...e]=this.#i,c=e.length;let h=new Set;for(let r=0;r<c;r++){const{branch:u,find:m,skip:f}=e[r],t=u.length;if(!f&&t){const i=this.#l[r],o=t-1;if(o===0)if((s===I||s===C)&&this.#e.nodeType===l.ELEMENT_NODE){for(const d of i)if(d!==this.#e&&(0,E.isSameOrDescendant)(d,this.#e)&&(h.add(d),s===C))break}else if(s===C){const[d]=this._sortNodes(i);h.add(d)}else{const d=[...h],a=[...i];h=new Set([...d,...a])}else if(m===R){let{combo:d}=u[0];for(const a of i){let n=new Set([a]);for(let b=1;b<t;b++){const{combo:p,leaves:N}=u[b],y=[];for(const x of n){const L={combo:d,leaves:N},O=this._matchCombinator(L,x,{find:m});O.size&&y.push(...O)}if(y.length)if(b===o){if(s===C){const[x]=this._sortNodes(y);h.add(x)}else{const x=[...h];h=new Set([...x,...y])}break}else d=p,n=new Set(y);else break}}}else for(const d of i){let a=new Set([d]),n;for(let b=o-1;b>=0;b--){const p=u[b],N=[];for(const y of a){const x=this._matchCombinator(p,y,{find:m});x.size&&N.push(...x)}if(N.length)if(n=!0,b===0){h.add(d);break}else a=new Set(N);else{n=!1;break}}if(n&&s!==I)break}}}return h}_find(s){return this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==l.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{s=this._find(P).has(this.#e)}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==l.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{const e=this._find(D);let c=this.#e;for(;c;){if(e.has(c)){s=c;break}c=c.parentNode}}catch(e){this._onError(e)}return s??null}querySelector(){let s;try{const e=this._find(C);e.delete(this.#e),e.size&&([s]=this._sortNodes(e))}catch(e){this._onError(e)}return s??null}querySelectorAll(){let s;try{const e=this._find(I);e.delete(this.#e),e.size&&(s=this._sortNodes(e))}catch(e){this._onError(e)}return s??[]}}0&&(module.exports={Matcher});
|
|
1
|
+
var F=Object.create;var R=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var G=(v,s)=>{for(var e in s)R(v,e,{get:s[e],enumerable:!0})},z=(v,s,e,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of j(s))!W.call(v,h)&&h!==e&&R(v,h,{get:()=>s[h],enumerable:!(n=V(s,h))||n.enumerable});return v};var q=(v,s,e)=>(e=v!=null?F(H(v)):{},z(s||!v||!v.__esModule?R(e,"default",{value:v,enumerable:!0}):e,v)),X=v=>z(R({},"__esModule",{value:!0}),v);var J={};G(J,{Matcher:()=>Y});module.exports=X(J);var B=q(require("is-potential-custom-element-name"),1),E=require("./dom-util.js"),k=require("./parser.js"),r=require("./constant.js");const M="next",U="prev",I="all",C="first",D="lineal",P="self";class Y{#i;#r;#a;#e;#l;#t;#o;#s;constructor(s,e,n={}){const{warn:h}=n;this.#r=new Map([[r.SELECTOR_PSEUDO_ELEMENT,r.BIT_01],[r.SELECTOR_ID,r.BIT_02],[r.SELECTOR_CLASS,r.BIT_04],[r.SELECTOR_TYPE,r.BIT_08],[r.SELECTOR_ATTR,r.BIT_16],[r.SELECTOR_PSEUDO_CLASS,r.BIT_32]]),this.#a=new WeakMap,this.#o=s,this.#e=e,this.#s=!!h,[this.#i,this.#l]=this._prepare(s),this.#t=this._getRoot(e)}_onError(s){if(s instanceof DOMException&&s.name===r.NOT_SUPPORTED_ERR)this.#s&&console.warn(s.message);else throw s}_getRoot(s=this.#e){let e,n;switch(s.nodeType){case r.DOCUMENT_NODE:{e=s,n=s;break}case r.DOCUMENT_FRAGMENT_NODE:{e=s.ownerDocument,n=s;break}case r.ELEMENT_NODE:{if(s.ownerDocument.contains(s))e=s.ownerDocument,n=s.ownerDocument;else{let l=s;for(;l&&l.parentNode;)l=l.parentNode;e=l.ownerDocument,n=l}break}default:throw new TypeError(`Unexpected node ${s.nodeName}`)}const h=(0,E.isInShadowTree)(s);return{document:e,root:n,shadow:h}}_sortLeaves(s){const e=[...s];return e.length>1&&e.sort((n,h)=>{const{type:l}=n,{type:u}=h,m=this.#r.get(l),f=this.#r.get(u);let t;return m===f?t=0:m>f?t=1:t=-1,t}),e}_prepare(s=this.#o){const e=(0,k.parseSelector)(s),n=(0,k.walkAST)(e),h=[],l=[];let u=0;for(const[...m]of n){const f=[];let t=m.shift();if(t&&t.type!==r.COMBINATOR){const i=new Set;for(;t;){if(t.type===r.COMBINATOR){const[o]=m;if(o.type===r.COMBINATOR){const b=`Invalid combinator ${t.name}${o.name}`;throw new DOMException(b,r.SYNTAX_ERR)}f.push({combo:t,leaves:this._sortLeaves(i)}),i.clear()}else t&&i.add(t);if(m.length)t=m.shift();else{f.push({combo:null,leaves:this._sortLeaves(i)}),i.clear();break}}}h.push({branch:f,find:null,skip:!1}),l[u]=new Set,u++}return[h,l]}_collectNthChild(s,e){const{a:n,b:h,reverse:l,selector:u}=s,{parentNode:m}=e,f=new Set;let t;if(u&&(this.#a.has(u)?t=this.#a.get(u):(t=(0,k.walkAST)(u),this.#a.set(u,t))),m){const i=[].slice.call(m.children),o=i.length;if(o){const b=new Set;if(t){const a=t.length;for(const c of i){let d;for(let p=0;p<a;p++){const N=t[p];if(d=this._matchLeaves(N,c),!d)break}d&&b.add(c)}}if(l&&i.reverse(),n===0){if(h>0&&h<=o){if(b.size)for(let a=0;a<o;a++){const c=i[a];if(b.has(c)){f.add(c);break}}else if(!u){const a=i[h-1];f.add(a)}}}else{let a=h-1;if(n>0)for(;a<0;)a+=n;if(a>=0&&a<o){let c=n>0?0:h-1;for(let d=0;d<o&&a>=0&&a<o;d++){const p=i[d];b.size?b.has(p)&&(c===a&&(f.add(p),a+=n),n>0?c++:c--):d===a&&(u||f.add(p),a+=n)}}}}}else{const{root:i}=this.#t;if(e===i&&i.nodeType===r.ELEMENT_NODE&&n+h===1)if(t){const o=t.length;let b;for(let a=0;a<o;a++){const c=t[a];if(b=this._matchLeaves(c,e),b)break}b&&f.add(e)}else f.add(e)}return f}_collectNthOfType(s,e){const{a:n,b:h,reverse:l}=s,{localName:u,parentNode:m,prefix:f}=e,t=new Set;if(m){const i=[].slice.call(m.children),o=i.length;if(o)if(l&&i.reverse(),n===0){if(h>0&&h<=o){let b=0;for(let a=0;a<o;a++){const c=i[a],{localName:d,prefix:p}=c;if(d===u&&p===f){if(b===h-1){t.add(c);break}b++}}}}else{let b=h-1;if(n>0)for(;b<0;)b+=n;if(b>=0&&b<o){let a=n>0?0:h-1;for(let c=0;c<o;c++){const d=i[c],{localName:p,prefix:N}=d;if(p===u&&N===f){if(a===b&&(t.add(d),b+=n),b<0||b>=o)break;n>0?a++:a--}}}}}else{const{root:i}=this.#t;e===i&&i.nodeType===r.ELEMENT_NODE&&n+h===1&&t.add(e)}return t}_matchAnPlusB(s,e,n){const{nth:{a:h,b:l,name:u},selector:m}=s,f=(0,k.unescapeSelector)(u),t=new Map;f?(f==="even"?(t.set("a",2),t.set("b",0)):f==="odd"&&(t.set("a",2),t.set("b",1)),n.indexOf("last")>-1&&t.set("reverse",!0)):(typeof h=="string"&&/-?\d+/.test(h)?t.set("a",h*1):t.set("a",0),typeof l=="string"&&/-?\d+/.test(l)?t.set("b",l*1):t.set("b",0),n.indexOf("last")>-1&&t.set("reverse",!0));let i=new Set;if(t.has("a")&&t.has("b")){if(/^nth-(?:last-)?child$/.test(n)){m&&t.set("selector",m);const o=Object.fromEntries(t),b=this._collectNthChild(o,e);b.size&&(i=b)}else if(/^nth-(?:last-)?of-type$/.test(n)){const o=Object.fromEntries(t),b=this._collectNthOfType(o,e);b.size&&(i=b)}}return i}_matchPseudoElementSelector(s,e={}){const{forgive:n}=e;switch(s){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,r.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}()`,r.NOT_SUPPORTED_ERR);break}default:if(s.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${s}`,r.NOT_SUPPORTED_ERR)}else if(!n)throw new DOMException(`Unknown pseudo-element ::${s}`,r.SYNTAX_ERR)}}_matchDirectionPseudoClass(s,e){const n=(0,k.unescapeSelector)(s.name),h=(0,E.getDirectionality)(e);let l;return n===h&&(l=e),l??null}_matchLanguagePseudoClass(s,e){const n=(0,k.unescapeSelector)(s.name);let h;if(n)if(n==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(h=e);else{let l=e.parentNode;for(;l&&l.nodeType===r.ELEMENT_NODE;){if(l.hasAttribute("lang")){l.getAttribute("lang")&&(h=e);break}l=l.parentNode}}else{const l=`(?:-${r.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${r.ALPHA_NUM}${l}$`,"i").test(n)){let m;if(n.indexOf("-")>-1){const[f,t,...i]=n.split("-");let o;f==="*"?o=`${r.ALPHA_NUM}${l}`:o=`${f}${l}`;const b=`-${t}${l}`,a=i.length;let c="";if(a)for(let d=0;d<a;d++)c+=`-${i[d]}${l}`;m=new RegExp(`^${o}${b}${c}$`,"i")}else m=new RegExp(`^${n}${l}$`,"i");if(e.hasAttribute("lang"))m.test(e.getAttribute("lang"))&&(h=e);else{let f=e.parentNode;for(;f&&f.nodeType===r.ELEMENT_NODE;){if(f.hasAttribute("lang")){const t=f.getAttribute("lang");m.test(t)&&(h=e);break}f=f.parentNode}}}}return h??null}_matchHasPseudoFunc(s,e){let n;if(Array.isArray(s)&&s.length){const[h]=s,{type:l}=h;let u;l===r.COMBINATOR?u=s.shift():u={name:" ",type:r.COMBINATOR};const m=[];for(;s.length;){const[i]=s,{type:o}=i;if(o===r.COMBINATOR)break;m.push(s.shift())}const f={combo:u,leaves:m},t=this._matchCombinator(f,e,{find:M});if(t.size)if(s.length){for(const i of t)if(n=this._matchHasPseudoFunc(Object.assign([],s),i),n)break}else n=!0}return!!n}_matchLogicalPseudoFunc(s,e){const{astName:n="",branches:h=[],selector:l="",twigBranches:u=[]}=s;let m;if(n==="has")if(l.includes(":has("))m=null;else{const f=h.length;let t;for(let i=0;i<f;i++){const o=h[i];if(t=this._matchHasPseudoFunc(Object.assign([],o),e),t)break}t&&(m=e)}else{const f=/^(?:is|where)$/.test(n),t=u.length;let i;for(let o=0;o<t;o++){const b=u[o],a=b.length-1,{leaves:c}=b[a];if(i=this._matchLeaves(c,e,{forgive:f}),i&&a>0){let d=new Set([e]);for(let p=a-1;p>=0;p--){const N=b[p],y=[];for(const x of d){const L=this._matchCombinator(N,x,{forgive:f,find:U});L.size&&y.push(...L)}if(y.length)if(p===0){i=!0;break}else d=new Set(y);else{i=!1;break}}}if(i)break}n==="not"?i||(m=e):i&&(m=e)}return m??null}_matchPseudoClassSelector(s,e,n={}){const{children:h}=s,{localName:l,parentNode:u}=e,{forgive:m}=n,f=(0,k.unescapeSelector)(s.name);let t=new Set;if(r.REG_LOGICAL_PSEUDO.test(f)){let i;if(this.#a.has(s))i=this.#a.get(s);else{const b=(0,k.walkAST)(s),a=[],c=[];for(const[...d]of b){for(const x of d){const L=(0,k.generateCSS)(x);a.push(L)}const p=[],N=new Set;let y=d.shift();for(;y;)if(y.type===r.COMBINATOR?(p.push({combo:y,leaves:[...N]}),N.clear()):y&&N.add(y),d.length)y=d.shift();else{p.push({combo:null,leaves:[...N]}),N.clear();break}c.push(p)}i={astName:f,branches:b,twigBranches:c,selector:a.join(",")},this.#a.set(s,i)}const o=this._matchLogicalPseudoFunc(i,e);o&&t.add(o)}else if(Array.isArray(h)){const[i]=h;if(/^nth-(?:last-)?(?:child|of-type)$/.test(f)){const o=this._matchAnPlusB(i,e,f);o.size&&(t=o)}else if(f==="dir"){const o=this._matchDirectionPseudoClass(i,e);o&&t.add(o)}else if(f==="lang"){const o=this._matchLanguagePseudoClass(i,e);o&&t.add(o)}else switch(f){case"current":case"nth-col":case"nth-last-col":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}()`,r.NOT_SUPPORTED_ERR);break}case"host":case"host-context":break;default:if(!m)throw new DOMException(`Unknown pseudo-class :${f}()`,r.SYNTAX_ERR)}}else{const{document:i,root:o}=this.#t,{documentElement:b}=i,a=new URL(i.URL),c=/^a(?:rea)?$/,d=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,p=/^(?:(?:inpu|selec)t|button|form|textarea)$/,N=/^d(?:etails|ialog)$/,y=/^(?:checkbox|radio)$/,x=/^(?:date(?:time-local)?|month|time|week)$/,L=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,$=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(f){case"any-link":case"link":{c.test(l)&&e.hasAttribute("href")&&t.add(e);break}case"local-link":{if(c.test(l)&&e.hasAttribute("href")){const w=new URL(e.getAttribute("href"),a.href);w.origin===a.origin&&w.pathname===a.pathname&&t.add(e)}break}case"visited":break;case"target":{e.id&&a.hash&&a.hash===`#${e.id}`&&i.contains(e)&&t.add(e);break}case"target-within":{if(a.hash){const w=a.hash.replace(/^#/,"");let g=i.getElementById(w);for(;g;){if(g===e){t.add(e);break}g=g.parentNode}}break}case"scope":{this.#e.nodeType===r.ELEMENT_NODE?e===this.#e&&t.add(e):e===b&&t.add(e);break}case"focus":{e===i.activeElement&&t.add(e);break}case"focus-within":{let w=i.activeElement;for(;w;){if(w===e){t.add(e);break}w=w.parentNode}break}case"open":{N.test(l)&&e.hasAttribute("open")&&t.add(e);break}case"closed":{N.test(l)&&!e.hasAttribute("open")&&t.add(e);break}case"disabled":{if(d.test(l)||(0,B.default)(l))if(e.disabled||e.hasAttribute("disabled"))t.add(e);else{let w=u;for(;w&&w.localName!=="fieldset";)w=w.parentNode;w&&u.localName!=="legend"&&w.hasAttribute("disabled")&&t.add(e)}break}case"enabled":{(d.test(l)||(0,B.default)(l))&&!(e.disabled&&e.hasAttribute("disabled"))&&t.add(e);break}case"read-only":{switch(l){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}case"input":{(!e.type||x.test(e.type)||$.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)||t.add(e)}break}case"read-write":{switch(l){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||t.add(e);break}case"input":{(!e.type||x.test(e.type)||$.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&t.add(e);break}default:(0,E.isContentEditable)(e)&&t.add(e)}break}case"placeholder-shown":{let w;l==="textarea"?w=e:l==="input"&&(e.hasAttribute("type")?$.test(e.getAttribute("type"))&&(w=e):w=e),w&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&t.add(e);break}case"checked":{(e.checked&&l==="input"&&e.hasAttribute("type")&&y.test(e.getAttribute("type"))||e.selected&&l==="option")&&t.add(e);break}case"indeterminate":{if(e.indeterminate&&l==="input"&&e.type==="checkbox"||l==="progress"&&!e.hasAttribute("value"))t.add(e);else if(l==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const w=e.name;let g=e.parentNode;for(;g&&g.localName!=="form";)g=g.parentNode;g||(g=b);const _=[].slice.call(g.getElementsByTagName("input"));let T;for(const A of _)if(A.getAttribute("type")==="radio"&&(w?A.getAttribute("name")===w&&(T=!!A.checked):A.hasAttribute("name")||(T=!!A.checked),T))break;T||t.add(e)}break}case"default":{const w=/^(?:button|reset)$/,g=/^(?:image|submit)$/;if(l==="button"&&!(e.hasAttribute("type")&&w.test(e.getAttribute("type")))||l==="input"&&e.hasAttribute("type")&&g.test(e.getAttribute("type"))){let _=e.parentNode;for(;_&&_.localName!=="form";)_=_.parentNode;if(_){const T=i.createNodeIterator(_,r.SHOW_ELEMENT);let A=T.nextNode();for(;A;){const O=A.localName;let S;if(O==="button"?S=!(A.hasAttribute("type")&&w.test(A.getAttribute("type"))):O==="input"&&(S=A.hasAttribute("type")&&g.test(A.getAttribute("type"))),S){A===e&&t.add(e);break}A=T.nextNode()}}}else if(l==="input"&&e.hasAttribute("type")&&y.test(e.getAttribute("type"))&&(e.checked||e.hasAttribute("checked")))t.add(e);else if(l==="option"){let _=!1,T=u;for(;T&&T.localName!=="datalist";){if(T.localName==="select"){(T.multiple||T.hasAttribute("multiple"))&&(_=!0);break}T=T.parentNode}if(_)(e.selected||e.hasAttribute("selected"))&&t.add(e);else{const A=u.firstElementChild,O=new Set;let S=A;for(;S;){if(S.selected||S.hasAttribute("selected")){O.add(S);break}S=S.nextElementSibling}O.size||O.add(A),O.has(e)&&t.add(e)}}break}case"valid":{if(p.test(l))e.checkValidity()&&t.add(e);else if(l==="fieldset"){const w=i.createNodeIterator(e,r.SHOW_ELEMENT);let g=w.nextNode();g===e&&(g=w.nextNode());let _;for(;g&&!(p.test(g.localName)&&(_=g.checkValidity(),!_));)g=w.nextNode();_&&t.add(e)}break}case"invalid":{if(p.test(l))e.checkValidity()||t.add(e);else if(l==="fieldset"){const w=i.createNodeIterator(e,r.SHOW_ELEMENT);let g=w.nextNode();g===e&&(g=w.nextNode());let _;for(;g&&!(p.test(g.localName)&&(_=g.checkValidity(),!_));)g=w.nextNode();_||t.add(e)}break}case"in-range":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.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":{l==="input"&&!(e.readonly||e.hasAttribute("readonly"))&&!(e.disabled||e.hasAttribute("disabled"))&&e.hasAttribute("type")&&L.test(e.getAttribute("type"))&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)&&t.add(e);break}case"required":{let w;if(/^(?:select|textarea)$/.test(l))w=e;else if(l==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||y.test(g)||x.test(g)||$.test(g))&&(w=e)}else w=e;w&&(e.required||e.hasAttribute("required"))&&t.add(e);break}case"optional":{let w;if(/^(?:select|textarea)$/.test(l))w=e;else if(l==="input")if(e.hasAttribute("type")){const g=e.getAttribute("type");(g==="file"||y.test(g)||x.test(g)||$.test(g))&&(w=e)}else w=e;w&&!(e.required||e.hasAttribute("required"))&&t.add(e);break}case"root":{e===b&&t.add(e);break}case"empty":{if(e.hasChildNodes()){const w=e.childNodes.values();let g;for(const _ of w)if(g=_.nodeType!==r.ELEMENT_NODE&&_.nodeType!==r.TEXT_NODE,!g)break;g&&t.add(e)}else t.add(e);break}case"first-child":{(u&&e===u.firstElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"last-child":{(u&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"only-child":{(u&&e===u.firstElementChild&&e===u.lastElementChild||e===o&&o.nodeType===r.ELEMENT_NODE)&&t.add(e);break}case"first-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1},e);w&&t.add(w)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"last-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1,reverse:!0},e);w&&t.add(w)}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"only-of-type":{if(u){const[w]=this._collectNthOfType({a:0,b:1},e);if(w===e){const[g]=this._collectNthOfType({a:0,b:1,reverse:!0},e);g===e&&t.add(e)}}else e===o&&o.nodeType===r.ELEMENT_NODE&&t.add(e);break}case"host":case"host-context":break;case"after":case"before":case"first-letter":case"first-line":{if(this.#s)throw new DOMException(`Unsupported pseudo-element ::${f}`,r.NOT_SUPPORTED_ERR);break}case"active":case"autofill":case"blank":case"buffering":case"current":case"focus-visible":case"fullscreen":case"future":case"hover":case"modal":case"muted":case"past":case"paused":case"picture-in-picture":case"playing":case"seeking":case"stalled":case"user-invalid":case"user-valid":case"volume-locked":case"-webkit-autofill":{if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,r.NOT_SUPPORTED_ERR);break}default:if(f.startsWith("-webkit-")){if(this.#s)throw new DOMException(`Unsupported pseudo-class :${f}`,r.NOT_SUPPORTED_ERR)}else if(!m)throw new DOMException(`Unknown pseudo-class :${f}`,r.SYNTAX_ERR)}}return t}_matchAttributeSelector(s,e){const{flags:n,matcher:h,name:l,value:u}=s;if(typeof n=="string"&&!/^[is]$/i.test(n)){const t=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${t}`,r.SYNTAX_ERR)}const{attributes:m}=e;let f;if(m&&m.length){const{document:t}=this.#t;let i;t.contentType==="text/html"?typeof n=="string"&&/^s$/i.test(n)?i=!1:i=!0:typeof n=="string"&&/^i$/i.test(n)?i=!0:i=!1;let o=(0,k.unescapeSelector)(l.name);i&&(o=o.toLowerCase());const b=new Set;if(o.indexOf("|")>-1){const{prefix:a,tagName:c}=(0,E.selectorToNodeProps)(o);for(let{name:d,value:p}of m)switch(i&&(d=d.toLowerCase(),p=p.toLowerCase()),a){case"":{c===d&&b.add(p);break}case"*":{d.indexOf(":")>-1?d.endsWith(`:${c}`)&&b.add(p):c===d&&b.add(p);break}default:if(d.indexOf(":")>-1){const[N,y]=d.split(":");a===N&&c===y&&(0,E.isNamespaceDeclared)(a,e)&&b.add(p)}}}else for(let{name:a,value:c}of m)if(i&&(a=a.toLowerCase(),c=c.toLowerCase()),a.indexOf(":")>-1){const[d,p]=a.split(":");if(d==="xml"&&p==="lang")continue;o===p&&b.add(c)}else o===a&&b.add(c);if(b.size){const{name:a,value:c}=u||{};let d;switch(a?i?d=a.toLowerCase():d=a:c?i?d=c.toLowerCase():d=c:c===""&&(d=c),h){case"=":{typeof d=="string"&&b.has(d)&&(f=e);break}case"~=":{if(d&&typeof d=="string"){for(const p of b)if(new Set(p.split(/\s+/)).has(d)){f=e;break}}break}case"|=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N===d||N.startsWith(`${d}-`)){p=N;break}p&&(f=e)}break}case"^=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.startsWith(`${d}`)){p=N;break}p&&(f=e)}break}case"$=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.endsWith(`${d}`)){p=N;break}p&&(f=e)}break}case"*=":{if(d&&typeof d=="string"){let p;for(const N of b)if(N.includes(`${d}`)){p=N;break}p&&(f=e)}break}case null:default:f=e}}}return f??null}_matchClassSelector(s,e){const n=(0,k.unescapeSelector)(s.name);let h;return e.classList.contains(n)&&(h=e),h??null}_matchIDSelector(s,e){const n=(0,k.unescapeSelector)(s.name),{id:h}=e;let l;return n===h&&(l=e),l??null}_matchTypeSelector(s,e,n={}){const h=(0,k.unescapeSelector)(s.name),{localName:l,prefix:u}=e,{forgive:m}=n,{document:f}=this.#t;let{prefix:t,tagName:i}=(0,E.selectorToNodeProps)(h,e);f.contentType==="text/html"&&(t=t.toLowerCase(),i=i.toLowerCase());let o,b;l.indexOf(":")>-1?[o,b]=l.split(":"):(o=u||"",b=l);let a;if(t===""&&o==="")e.namespaceURI===null&&(i==="*"||i===b)&&(a=e);else if(t==="*")(i==="*"||i===b)&&(a=e);else if(t===o){if((0,E.isNamespaceDeclared)(t,e))(i==="*"||i===b)&&(a=e);else if(!m)throw new DOMException(`Undeclared namespace ${t}`,r.SYNTAX_ERR)}else if(t&&!m&&!(0,E.isNamespaceDeclared)(t,e))throw new DOMException(`Undeclared namespace ${t}`,r.SYNTAX_ERR);return a??null}_matchShadowHostPseudoClass(s,e){const{children:n}=s,h=(0,k.unescapeSelector)(s.name);let l;if(Array.isArray(n)){const[u]=(0,k.walkAST)(n[0]),[...m]=u,{host:f}=e;if(h==="host"){let t;for(const i of m){const{type:o}=i;if(o===r.COMBINATOR){const b=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${b}`,r.SYNTAX_ERR)}if(t=this._matchSelector(i,f).has(f),!t)break}t&&(l=e)}else if(h==="host-context"){let t=f,i;for(;t;){for(const o of m){const{type:b}=o;if(b===r.COMBINATOR){const a=(0,k.generateCSS)(s);throw new DOMException(`Invalid selector ${a}`,r.SYNTAX_ERR)}if(i=this._matchSelector(o,t).has(t),!i)break}if(i)break;t=t.parentNode}i&&(l=e)}}else if(h==="host")l=e;else throw new DOMException(`Invalid selector :${h}`,r.SYNTAX_ERR);return l??null}_matchSelector(s,e,n){const{type:h}=s,l=(0,k.unescapeSelector)(s.name),{shadow:u}=this.#t;let m=new Set;if(e.nodeType===r.ELEMENT_NODE)switch(h){case r.SELECTOR_ATTR:{const f=this._matchAttributeSelector(s,e);f&&m.add(f);break}case r.SELECTOR_CLASS:{const f=this._matchClassSelector(s,e);f&&m.add(f);break}case r.SELECTOR_ID:{const f=this._matchIDSelector(s,e);f&&m.add(f);break}case r.SELECTOR_PSEUDO_CLASS:{const f=this._matchPseudoClassSelector(s,e,n);f.size&&(m=f);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(l,n);break}case r.SELECTOR_TYPE:default:{const f=this._matchTypeSelector(s,e,n);f&&m.add(f)}}else if(u&&h===r.SELECTOR_PSEUDO_CLASS&&e.nodeType===r.DOCUMENT_FRAGMENT_NODE){if(l!=="has"&&r.REG_LOGICAL_PSEUDO.test(l)){const f=this._matchPseudoClassSelector(s,e,n);f.size&&(m=f)}else if(r.REG_SHADOW_HOST.test(l)){const f=this._matchShadowHostPseudoClass(s,e);f&&m.add(f)}}return m}_matchLeaves(s,e,n){let h;for(const l of s)if(h=this._matchSelector(l,e,n).has(e),!h)break;return!!h}_findDescendantNodes(s,e){const[n,...h]=s,{type:l}=n,u=(0,k.unescapeSelector)(n.name),m=h.length>0,{document:f,root:t,shadow:i}=this.#t;let o=new Set,b=!1;if(i)b=!0;else switch(l){case r.SELECTOR_ID:{if(t.nodeType===r.ELEMENT_NODE)b=!0;else{const a=t.getElementById(u);a&&a!==e&&e.contains(a)&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a))}break}case r.SELECTOR_CLASS:{const a=[].slice.call(e.getElementsByClassName(u));if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_TYPE:{if(f.contentType==="text/html"&&!/[*|]/.test(u)){const a=[].slice.call(e.getElementsByTagName(u));if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a)}else b=!0;break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:b=!0}return{nodes:o,pending:b}}_matchCombinator(s,e,n={}){const{combo:h,leaves:l}=s,{name:u}=h,{find:m,forgive:f}=n;let t=new Set;if(m===M)switch(u){case"+":{const i=e.nextElementSibling;i&&this._matchLeaves(l,i,{forgive:f})&&t.add(i);break}case"~":{let i=e.nextElementSibling;for(;i;)this._matchLeaves(l,i,{forgive:f})&&t.add(i),i=i.nextElementSibling;break}case">":{const i=[].slice.call(e.children);for(const o of i)this._matchLeaves(l,o,{forgive:f})&&t.add(o);break}case" ":default:{const{nodes:i,pending:o}=this._findDescendantNodes(l,e);if(i.size)t=i;else if(o){const{document:b}=this.#t,a=b.createNodeIterator(e,r.SHOW_ELEMENT);let c=a.nextNode();for(c===e&&(c=a.nextNode());c;)this._matchLeaves(l,c,{forgive:f})&&t.add(c),c=a.nextNode()}}}else switch(u){case"+":{const i=e.previousElementSibling;i&&this._matchLeaves(l,i,{forgive:f})&&t.add(i);break}case"~":{const i=[];let o=e.previousElementSibling;for(;o;)this._matchLeaves(l,o,{forgive:f})&&i.push(o),o=o.previousElementSibling;i.length&&(t=new Set(i.reverse()));break}case">":{const i=e.parentNode;i&&this._matchLeaves(l,i,{forgive:f})&&t.add(i);break}case" ":default:{const i=[];let o=e.parentNode;for(;o;)this._matchLeaves(l,o,{forgive:f})&&i.push(o),o=o.parentNode;i.length&&(t=new Set(i.reverse()))}}return t}_findNodes(s,e){const{leaves:[n,...h]}=s,{type:l}=n,u=(0,k.unescapeSelector)(n.name),m=h.length>0,{document:f,root:t,shadow:i}=this.#t;let o=new Set,b=!1;switch(l){case r.SELECTOR_ID:{let a;if(e===P)this._matchLeaves([n],this.#e)&&(a=this.#e);else if(e===D){let c=this.#e;for(;c;){if(this._matchLeaves([n],c)){a=c;break}c=c.parentNode}}else e===I||t.nodeType===r.ELEMENT_NODE?b=!0:a=t.getElementById(u);a&&(m?this._matchLeaves(h,a)&&o.add(a):o.add(a));break}case r.SELECTOR_CLASS:{let a=[];if(e===P)this.#e.nodeType===r.ELEMENT_NODE&&this.#e.classList.contains(u)&&a.push(this.#e);else if(e===D){let c=this.#e;for(;c&&c.nodeType===r.ELEMENT_NODE;)c.classList.contains(u)&&a.push(c),c=c.parentNode}else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=[].slice.call(t.children);for(const d of c){d.classList.contains(u)&&a.push(d);const p=[].slice.call(d.getElementsByClassName(u));a.push(...p)}}else{const c=[].slice.call(t.getElementsByClassName(u));if(this.#e.nodeType===r.ELEMENT_NODE)for(const d of c)(d===this.#e||(0,E.isInclusive)(d,this.#e))&&a.push(d);else a=c}if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_TYPE:{let a=[];if(e===P)this.#e.nodeType===r.ELEMENT_NODE&&this._matchLeaves([n],this.#e)&&a.push(this.#e);else if(e===D){let c=this.#e;for(;c&&c.nodeType===r.ELEMENT_NODE;)this._matchLeaves([n],c)&&a.push(c),c=c.parentNode}else if(f.contentType!=="text/html"||/[*|]/.test(u))b=!0;else if(t.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=u.toLowerCase(),d=[].slice.call(t.children);for(const p of d){p.localName===c&&a.push(p);const N=[].slice.call(p.getElementsByTagName(u));a.push(...N)}}else{const c=[].slice.call(t.getElementsByTagName(u));if(this.#e.nodeType===r.ELEMENT_NODE)for(const d of c)(d===this.#e||(0,E.isInclusive)(d,this.#e))&&a.push(d);else a=c}if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a);break}case r.SELECTOR_PSEUDO_ELEMENT:{this._matchPseudoElementSelector(u);break}default:{const a=[];if(e!==D&&r.REG_SHADOW_HOST.test(u)){if(i&&this.#e.nodeType===r.DOCUMENT_FRAGMENT_NODE){const c=this._matchShadowHostPseudoClass(n,this.#e);c&&a.push(c)}}else if(e===P)this._matchLeaves([n],this.#e)&&a.push(this.#e);else if(e===D){let c=this.#e;for(;c;)this._matchLeaves([n],c)&&a.push(c),c=c.parentNode}else b=!0;if(a.length)if(m)for(const c of a)this._matchLeaves(h,c)&&o.add(c);else o=new Set(a)}}if(m&&!b&&!o.size){const a=h[h.length-1],{type:c}=a;if(c===r.SELECTOR_PSEUDO_CLASS){let d;t.nodeType===r.ELEMENT_NODE?d=t:d=t.firstElementChild,this._matchPseudoClassSelector(a,d)}}return{nodes:o,pending:b}}_getFirstTwig(s){const e=s.length-1,n=s[0];let h,l;if(e){const u=s[e],{leaves:[{type:m}]}=u;m===r.SELECTOR_PSEUDO_ELEMENT||m===r.SELECTOR_ID?(h=U,l=u):(h=M,l=n)}else h=U,l=n;return{find:h,twig:l}}_collectNodes(s){const e=this.#i.values();if(s===I||s===C){const n=new Set;let h=0;for(const{branch:l}of e){const{find:u,twig:m}=this._getFirstTwig(l),{nodes:f,pending:t}=this._findNodes(m,s);f.size?this.#l[h]=f:t?n.add(new Map([["index",h],["twig",m]])):this.#i[h].skip=!0,this.#i[h].find=u,h++}if(n.size){const{document:l,root:u}=this.#t,m=l.createNodeIterator(u,r.SHOW_ELEMENT);let f=m.nextNode();for(;f;){let t=!1;if(this.#e.nodeType===r.ELEMENT_NODE?f===this.#e?t=!0:t=this.#e.contains(f):t=!0,t)for(const i of n){const{leaves:o}=i.get("twig");if(this._matchLeaves(o,f)){const a=i.get("index");this.#l[a].add(f)}}f=m.nextNode()}}}else{let n=0;for(const{branch:h}of e){const l=h[h.length-1],{nodes:u}=this._findNodes(l,s);u.size?this.#l[n]=u:this.#i[n].skip=!0,this.#i[n].find=U,n++}}return[this.#i,this.#l]}_sortNodes(s){const e=[...s];return e.length>1&&e.sort((n,h)=>{let l;return(0,E.isPreceding)(h,n)?l=1:l=-1,l}),e}_matchNodes(s){const[...e]=this.#i,n=e.length;let h=new Set;for(let l=0;l<n;l++){const{branch:u,find:m,skip:f}=e[l],t=u.length;if(!f&&t){const i=this.#l[l],o=t-1;if(o===0)if((s===I||s===C)&&this.#e.nodeType===r.ELEMENT_NODE){for(const b of i)if(b!==this.#e&&this.#e.contains(b)&&(h.add(b),s===C))break}else if(s===C){const[b]=this._sortNodes(i);h.add(b)}else{const b=[...h],a=[...i];h=new Set([...b,...a])}else if(m===M){let{combo:b}=u[0];for(const a of i){let c=new Set([a]);for(let d=1;d<t;d++){const{combo:p,leaves:N}=u[d],y=[];for(const x of c){const L={combo:b,leaves:N},$=this._matchCombinator(L,x,{find:m});$.size&&y.push(...$)}if(y.length)if(d===o){if(s===C){const[x]=this._sortNodes(y);h.add(x)}else{const x=[...h];h=new Set([...x,...y])}break}else b=p,c=new Set(y);else break}}}else for(const b of i){let a=new Set([b]),c;for(let d=o-1;d>=0;d--){const p=u[d],N=[];for(const y of a){const x=this._matchCombinator(p,y,{find:m});x.size&&N.push(...x)}if(N.length)if(c=!0,d===0){h.add(b);break}else a=new Set(N);else{c=!1;break}}if(c&&s!==I)break}}}return h}_find(s){return this._collectNodes(s),this._matchNodes(s)}matches(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{s=this._find(P).has(this.#e)}catch(e){this._onError(e)}return!!s}closest(){if(this.#e.nodeType!==r.ELEMENT_NODE)throw new TypeError(`Unexpected node ${this.#e.nodeName}`);let s;try{const e=this._find(D);let n=this.#e;for(;n;){if(e.has(n)){s=n;break}n=n.parentNode}}catch(e){this._onError(e)}return s??null}querySelector(){let s;try{const e=this._find(C);e.delete(this.#e),e.size&&([s]=this._sortNodes(e))}catch(e){this._onError(e)}return s??null}querySelectorAll(){let s;try{const e=this._find(I);e.delete(this.#e),e.size&&(s=this._sortNodes(e))}catch(e){this._onError(e)}return s??[]}}0&&(module.exports={Matcher});
|
|
2
2
|
//# sourceMappingURL=matcher.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/matcher.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isInShadowTree, isNamespaceDeclared,\n isSameOrDescendant, selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, COMBINATOR,\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, NOT_SUPPORTED_ERR,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_ATTR, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\nconst FIND_NEXT = 'next';\nconst FIND_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * }\n * ]\n * #nodes: [\n * Set([node{}, node{}]),\n * Set([node{}, node{}, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: AST leaf\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #bit;\n #cache;\n #node;\n #nodes;\n #root;\n #selector;\n #warn;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { warn } = opt;\n this.#bit = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#warn = !!warn;\n [this.#ast, this.#nodes] = this._prepare(selector);\n this.#root = this._getRoot(node);\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException && e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw e;\n }\n }\n\n /**\n * get root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - root object\n */\n _getRoot(node = this.#node) {\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (isSameOrDescendant(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n document = parent.ownerDocument;\n root = parent;\n }\n break;\n }\n default: {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n const shadow = isInShadowTree(node);\n return {\n document,\n root,\n shadow\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - collection of AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = this.#bit.get(typeA);\n const bitB = this.#bit.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * prepare ast and nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _prepare(selector = this.#selector) {\n const ast = parseSelector(selector);\n const branches = walkAST(ast);\n const tree = [];\n const nodes = [];\n let i = 0;\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid combinator ${item.name}${nextItem.name}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n tree.push({\n branch,\n find: null,\n skip: false\n });\n nodes[i] = new Set();\n i++;\n }\n return [\n tree,\n nodes\n ];\n }\n\n /**\n * collect nth child\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#cache.has(selector)) {\n selectorBranches = this.#cache.get(selector);\n } else {\n selectorBranches = walkAST(selector);\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const arr = [].slice.call(parentNode.children);\n const l = arr.length;\n if (l) {\n const selectorNodes = new Set();\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n for (const refNode of arr) {\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, refNode);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n }\n if (reverse) {\n arr.reverse();\n }\n // :first-child, :last-child, :nth-child(0 of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n if (selectorNodes.has(current)) {\n matched.add(current);\n break;\n }\n }\n } else if (!selector) {\n const current = arr[b - 1];\n matched.add(current);\n }\n }\n // :nth-child()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l && nth >= 0 && nth < l; i++) {\n const current = arr[i];\n if (selectorNodes.size) {\n if (selectorNodes.has(current)) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(current);\n }\n nth += a;\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (node === root && root.nodeType === ELEMENT_NODE && (a + b) === 1) {\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const arr = [].slice.call(parentNode.children);\n const l = arr.length;\n if (l) {\n if (reverse) {\n arr.reverse();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(current);\n break;\n }\n j++;\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (node === root && root.nodeType === ELEMENT_NODE && (a + b) === 1) {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'placeholder':\n case 'selection':\n case 'target-text': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName) {\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n } else {\n const langPart = `(?:-${ALPHA_NUM})*`;\n const regLang = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${langPart}$`, 'i');\n if (regLang.test(astName)) {\n let regExtendedLang;\n if (astName.indexOf('-') > -1) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${langPart}`;\n } else {\n extendedMain = `${langMain}${langPart}`;\n }\n const extendedSub = `-${langSub}${langPart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${langPart}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${langPart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (regExtendedLang.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (regExtendedLang.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n find: FIND_NEXT\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n const l = branches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const leaves = branches[i];\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, { forgive });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n find: FIND_PREV\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n const { document, root } = this.#root;\n const { documentElement } = document;\n const docURL = new URL(document.URL);\n /* regexp */\n const regAnchor = /^a(?:rea)?$/;\n const regFormCtrl =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\n const regFormValidity = /^(?:(?:inpu|selec)t|button|form|textarea)$/;\n const regInteract = /^d(?:etails|ialog)$/;\n const regTypeCheck = /^(?:checkbox|radio)$/;\n const regTypeDate = /^(?:date(?:time-local)?|month|time|week)$/;\n const regTypeRange =\n /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\n const regTypeText = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n const attrURL = new URL(node.getAttribute('href'), docURL.href);\n if (attrURL.origin === docURL.origin &&\n attrURL.pathname === docURL.pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n if (node.id && docURL.hash && docURL.hash === `#${node.id}` &&\n isSameOrDescendant(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n if (docURL.hash) {\n const hash = docURL.hash.replace(/^#/, '');\n let current = document.getElementById(hash);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (node === this.#node) {\n matched.add(node);\n }\n } else if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === document.activeElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (regInteract.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (regInteract.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (regFormCtrl.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parentNode.localName !== 'legend' &&\n parent.hasAttribute('disabled')) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((regFormCtrl.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (regTypeText.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '' &&\n node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length) {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = documentElement;\n }\n const nodes = [].slice.call(parent.getElementsByTagName('input'));\n let checked;\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n const regTypeReset = /^(?:button|reset)$/;\n const regTypeSubmit = /^(?:image|submit)$/;\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n regTypeReset.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n regTypeSubmit.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const iterator = document.createNodeIterator(form, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n regTypeReset.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n regTypeSubmit.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = iterator.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let isMultiple = false;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'datalist') {\n break;\n } else if (parent.localName === 'select') {\n if (parent.multiple || parent.hasAttribute('multiple')) {\n isMultiple = true;\n }\n break;\n }\n parent = parent.parentNode;\n }\n if (isMultiple) {\n if (node.selected || node.hasAttribute('selected')) {\n matched.add(node);\n }\n } else {\n const firstOpt = parentNode.firstElementChild;\n const defaultOpt = new Set();\n let opt = firstOpt;\n while (opt) {\n if (opt.selected || opt.hasAttribute('selected')) {\n defaultOpt.add(opt);\n break;\n }\n opt = opt.nextElementSibling;\n }\n if (!defaultOpt.size) {\n defaultOpt.add(firstOpt);\n }\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'valid': {\n if (regFormValidity.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (regFormValidity.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n regTypeRange.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n regTypeRange.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const nodes = node.childNodes.values();\n let bool;\n for (const refNode of nodes) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // should not match\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'focus-visible':\n case 'fullscreen':\n case 'future':\n case 'hover':\n case 'modal':\n case 'muted':\n case 'past':\n case 'paused':\n case 'picture-in-picture':\n case 'playing':\n case 'seeking':\n case 'stalled':\n case 'user-invalid':\n case 'user-valid':\n case 'volume-locked':\n case '-webkit-autofill': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const { document } = this.#root;\n let caseInsensitive;\n if (document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { id } = node;\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { forgive } = opt;\n const { document } = this.#root;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix) {\n if (isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (!forgive) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n } else if (astPrefix && !forgive && !isNamespaceDeclared(astPrefix, node)) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n return res ?? null;\n };\n\n /**\n * match shadow host pseudo class\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren } = ast;\n const astName = unescapeSelector(ast.name);\n let res;\n if (Array.isArray(astChildren)) {\n const [branch] = walkAST(astChildren[0]);\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n throw new DOMException(`Invalid selector :${astName}`, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n const { shadow } = this.#root;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_ATTR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_CLASS: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_ID: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n const res = this._matchTypeSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} [opt] - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...items] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n if (shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_ID: {\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const elm = root.getElementById(leafName);\n if (elm && elm !== baseNode) {\n const bool = isSameOrDescendant(elm, baseNode);\n let node;\n if (bool) {\n node = elm;\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const arr = [].slice.call(baseNode.getElementsByClassName(leafName));\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (document.contentType === 'text/html' && !/[*|]/.test(leafName)) {\n const arr = [].slice.call(baseNode.getElementsByTagName(leafName));\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.find] - 'prev'|'next', which nodes to find\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { find, forgive } = opt;\n let matched = new Set();\n if (find === FIND_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n let refNode = node.nextElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [].slice.call(node.children);\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n matched = nodes;\n } else if (pending) {\n const { document } = this.#root;\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = iterator.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const arr = [];\n let refNode = node.previousElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.previousElementSibling;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - collection of nodes and pending state\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case SELECTOR_ID: {\n let node;\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n node = this.#node;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n node = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (targetType === TARGET_ALL ||\n root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n node = root.getElementById(leafName);\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByClassName(leafName));\n arr.push(...a);\n }\n } else {\n arr = [].slice.call(root.getElementsByClassName(leafName));\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (document.contentType !== 'text/html' ||\n /[*|]/.test(leafName)) {\n pending = true;\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const tagName = leafName.toLowerCase();\n const childNodes = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByTagName(leafName));\n arr.push(...a);\n }\n } else {\n arr = [].slice.call(root.getElementsByTagName(leafName));\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n // throws\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (shadow && this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n arr.push(node);\n }\n }\n } else if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n }\n if (matchItems && !pending && !nodes.size) {\n const lastLeaf = items[items.length - 1];\n const { type: lastLeafType } = lastLeaf;\n if (lastLeafType === SELECTOR_PSEUDO_CLASS) {\n let node;\n if (root.nodeType === ELEMENT_NODE) {\n node = root;\n } else {\n node = root.firstElementChild;\n }\n // throws if unknown pseudo-class\n this._matchPseudoClassSelector(lastLeaf, node);\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * get first twig\n * @param {Array.<object>} branch - AST branch\n * @returns {object} - find direction and twig\n */\n _getFirstTwig(branch) {\n const lastIndex = branch.length - 1;\n const firstTwig = branch[0];\n let find;\n let twig;\n if (lastIndex) {\n const lastTwig = branch[lastIndex];\n const { leaves: [{ type: lastType }] } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT || lastType === SELECTOR_ID) {\n find = FIND_PREV;\n twig = lastTwig;\n } else {\n find = FIND_NEXT;\n twig = firstTwig;\n }\n } else {\n find = FIND_PREV;\n twig = firstTwig;\n }\n return {\n find,\n twig\n };\n }\n\n /**\n * collect nodes\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const { find, twig } = this._getFirstTwig(branch);\n const { nodes, pending } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = find;\n i++;\n }\n if (pendingItems.size) {\n const { document, root } = this.#root;\n const iterator = document.createNodeIterator(root, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n bool = isSameOrDescendant(nextNode, this.#node);\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode);\n if (matched) {\n const index = pendingItem.get('index');\n this.#nodes[index].add(nextNode);\n }\n }\n }\n nextNode = iterator.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const { nodes } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = FIND_PREV;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\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 */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const posBit = a.compareDocumentPosition(b);\n let res;\n if (posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, find, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const matched = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of matched) {\n if (node !== this.#node) {\n if (isSameOrDescendant(node, this.#node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(matched);\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matched];\n nodes = new Set([...n, ...m]);\n }\n } else if (find === FIND_NEXT) {\n let { combo } = branch[0];\n for (const node of matched) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const twig = {\n combo,\n leaves\n };\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(arr);\n nodes.add(node);\n } else {\n const n = [...nodes];\n nodes = new Set([...n, ...arr]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of matched) {\n let nextNodes = new Set([node]);\n let bool;\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n if (bool && targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType) {\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * matches\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_SELF);\n res = nodes.has(this.#node);\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @returns {?object} - matched node\n */\n closest() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL);\n let node = this.#node;\n while (node) {\n if (nodes.has(node)) {\n res = node;\n break;\n }\n node = node.parentNode;\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @returns {?object} - matched node\n */\n querySelector() {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll() {\n let res;\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n res = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAOO,yBACP,MAAMC,EAAY,OACZC,EAAY,OACZC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OA8Bb,MAAMX,CAAQ,CAEnBY,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GASA,YAAYC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CACpC,KAAM,CAAE,KAAAC,CAAK,EAAID,EACjB,KAAKT,GAAO,IAAI,IAAI,CAClB,CAAC,0BAAyB,QAAM,EAChC,CAAC,cAAa,QAAM,EACpB,CAAC,iBAAgB,QAAM,EACvB,CAAC,gBAAe,QAAM,EACtB,CAAC,gBAAe,QAAM,EACtB,CAAC,wBAAuB,QAAM,CAChC,CAAC,EACD,KAAKC,GAAS,IAAI,QAClB,KAAKI,GAAYE,EACjB,KAAKL,GAAQM,EACb,KAAKF,GAAQ,CAAC,CAACI,EACf,CAAC,KAAKX,GAAM,KAAKI,EAAM,EAAI,KAAK,SAASI,CAAQ,EACjD,KAAKH,GAAQ,KAAK,SAASI,CAAI,CACjC,CAQA,SAASG,EAAG,CACV,GAAIA,aAAa,cAAgBA,EAAE,OAAS,oBACtC,KAAKL,IACP,QAAQ,KAAKK,EAAE,OAAO,MAGxB,OAAMA,CAEV,CAOA,SAASH,EAAO,KAAKN,GAAO,CAC1B,IAAIU,EACAC,EACJ,OAAQL,EAAK,SAAU,CACrB,KAAK,gBAAe,CAClBI,EAAWJ,EACXK,EAAOL,EACP,KACF,CACA,KAAK,yBAAw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AAS,CAAC,CACjB,CACA,OAAOgB,GAAO,IAChB,CAMA,eAAgB,CACd,IAAIA,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAMhC,CAAY,EACrCgC,EAAM,OAAO,KAAK1B,EAAK,EACnB0B,EAAM,OACR,CAACJ,CAAG,EAAI,KAAK,WAAWI,CAAK,EAEjC,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,IAChB,CAOA,kBAAmB,CACjB,IAAIA,EACJ,GAAI,CACF,MAAMI,EAAQ,KAAK,MAAMjC,CAAU,EACnCiC,EAAM,OAAO,KAAK1B,EAAK,EACnB0B,EAAM,OACRJ,EAAM,KAAK,WAAWI,CAAK,EAE/B,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,CAAC,CACjB,CACF",
|
|
6
|
-
"names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "FIND_NEXT", "FIND_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#warn", "selector", "node", "opt", "warn", "e", "document", "root", "parent", "shadow", "leaves", "arr", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "ast", "branches", "tree", "nodes", "i", "items", "branch", "item", "nextItem", "msg", "anb", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "branchesLen", "refNode", "bool", "current", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "id", "astPrefix", "astNodeName", "nodePrefix", "host", "astType", "baseNode", "leafName", "matchItems", "pending", "
|
|
4
|
+
"sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isInclusive, isInShadowTree,\n isNamespaceDeclared, isPreceding, selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, COMBINATOR,\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, NOT_SUPPORTED_ERR,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_ATTR, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE\n} from './constant.js';\nconst FIND_NEXT = 'next';\nconst FIND_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\n\n/**\n * Matcher\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * },\n * {\n * branch: branch[],\n * find: string\n * skip: boolean\n * }\n * ]\n * #nodes: [\n * Set([node{}, node{}]),\n * Set([node{}, node{}, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: AST leaf\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #bit;\n #cache;\n #node;\n #nodes;\n #root;\n #selector;\n #warn;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { warn } = opt;\n this.#bit = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n this.#cache = new WeakMap();\n this.#selector = selector;\n this.#node = node;\n this.#warn = !!warn;\n [this.#ast, this.#nodes] = this._prepare(selector);\n this.#root = this._getRoot(node);\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException && e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else {\n throw e;\n }\n }\n\n /**\n * get root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {object} - root object\n */\n _getRoot(node = this.#node) {\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (node.ownerDocument.contains(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n document = parent.ownerDocument;\n root = parent;\n }\n break;\n }\n default: {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n const shadow = isInShadowTree(node);\n return {\n document,\n root,\n shadow\n };\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - collection of AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = this.#bit.get(typeA);\n const bitB = this.#bit.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * prepare ast and nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - array of ast and nodes\n */\n _prepare(selector = this.#selector) {\n const ast = parseSelector(selector);\n const branches = walkAST(ast);\n const tree = [];\n const nodes = [];\n let i = 0;\n for (const [...items] of branches) {\n const branch = [];\n let item = items.shift();\n if (item && item.type !== COMBINATOR) {\n const leaves = new Set();\n while (item) {\n if (item.type === COMBINATOR) {\n const [nextItem] = items;\n if (nextItem.type === COMBINATOR) {\n const msg = `Invalid combinator ${item.name}${nextItem.name}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n tree.push({\n branch,\n find: null,\n skip: false\n });\n nodes[i] = new Set();\n i++;\n }\n return [\n tree,\n nodes\n ];\n }\n\n /**\n * collect nth child\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n const matched = new Set();\n let selectorBranches;\n if (selector) {\n if (this.#cache.has(selector)) {\n selectorBranches = this.#cache.get(selector);\n } else {\n selectorBranches = walkAST(selector);\n this.#cache.set(selector, selectorBranches);\n }\n }\n if (parentNode) {\n const arr = [].slice.call(parentNode.children);\n const l = arr.length;\n if (l) {\n const selectorNodes = new Set();\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n for (const refNode of arr) {\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, refNode);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n }\n }\n if (reverse) {\n arr.reverse();\n }\n // :first-child, :last-child, :nth-child(0 of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n if (selectorNodes.has(current)) {\n matched.add(current);\n break;\n }\n }\n } else if (!selector) {\n const current = arr[b - 1];\n matched.add(current);\n }\n }\n // :nth-child()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l && nth >= 0 && nth < l; i++) {\n const current = arr[i];\n if (selectorNodes.size) {\n if (selectorNodes.has(current)) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n } else if (i === nth) {\n if (!selector) {\n matched.add(current);\n }\n nth += a;\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (node === root && root.nodeType === ELEMENT_NODE && (a + b) === 1) {\n if (selectorBranches) {\n const branchesLen = selectorBranches.length;\n let bool;\n for (let i = 0; i < branchesLen; i++) {\n const leaves = selectorBranches[i];\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n const matched = new Set();\n if (parentNode) {\n const arr = [].slice.call(parentNode.children);\n const l = arr.length;\n if (l) {\n if (reverse) {\n arr.reverse();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(current);\n break;\n }\n j++;\n }\n }\n }\n // :nth-of-type()\n } else {\n let nth = b - 1;\n if (a > 0) {\n while (nth < 0) {\n nth += a;\n }\n }\n if (nth >= 0 && nth < l) {\n let j = a > 0 ? 0 : b - 1;\n for (let i = 0; i < l; i++) {\n const current = arr[i];\n const { localName: itemLocalName, prefix: itemPrefix } = current;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(current);\n nth += a;\n }\n if (nth < 0 || nth >= l) {\n break;\n } else if (a > 0) {\n j++;\n } else {\n j--;\n }\n }\n }\n }\n }\n }\n } else {\n const { root } = this.#root;\n if (node === root && root.nodeType === ELEMENT_NODE && (a + b) === 1) {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'placeholder':\n case 'selection':\n case 'target-text': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName) {\n if (astName === '*') {\n if (node.hasAttribute('lang')) {\n if (node.getAttribute('lang')) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n if (parent.getAttribute('lang')) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n } else {\n const langPart = `(?:-${ALPHA_NUM})*`;\n const regLang = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${langPart}$`, 'i');\n if (regLang.test(astName)) {\n let regExtendedLang;\n if (astName.indexOf('-') > -1) {\n const [langMain, langSub, ...langRest] = astName.split('-');\n let extendedMain;\n if (langMain === '*') {\n extendedMain = `${ALPHA_NUM}${langPart}`;\n } else {\n extendedMain = `${langMain}${langPart}`;\n }\n const extendedSub = `-${langSub}${langPart}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${langPart}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${langPart}$`, 'i');\n }\n if (node.hasAttribute('lang')) {\n if (regExtendedLang.test(node.getAttribute('lang'))) {\n res = node;\n }\n } else {\n let parent = node.parentNode;\n while (parent) {\n if (parent.nodeType === ELEMENT_NODE) {\n if (parent.hasAttribute('lang')) {\n const value = parent.getAttribute('lang');\n if (regExtendedLang.test(value)) {\n res = node;\n }\n break;\n }\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n find: FIND_NEXT\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n const l = branches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const leaves = branches[i];\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, { forgive });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n find: FIND_PREV\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\n break;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n }\n if (bool) {\n break;\n }\n }\n if (astName === 'not') {\n if (!bool) {\n res = node;\n }\n } else if (bool) {\n res = node;\n }\n }\n return res ?? null;\n }\n\n /**\n * match pseudo-class selector\n * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n default: {\n if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}()`,\n SYNTAX_ERR);\n }\n }\n }\n }\n } else {\n const { document, root } = this.#root;\n const { documentElement } = document;\n const docURL = new URL(document.URL);\n /* regexp */\n const regAnchor = /^a(?:rea)?$/;\n const regFormCtrl =\n /^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/;\n const regFormValidity = /^(?:(?:inpu|selec)t|button|form|textarea)$/;\n const regInteract = /^d(?:etails|ialog)$/;\n const regTypeCheck = /^(?:checkbox|radio)$/;\n const regTypeDate = /^(?:date(?:time-local)?|month|time|week)$/;\n const regTypeRange =\n /(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/;\n const regTypeText = /^(?:(?:emai|te|ur)l|number|password|search|text)$/;\n switch (astName) {\n case 'any-link':\n case 'link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n matched.add(node);\n }\n break;\n }\n case 'local-link': {\n if (regAnchor.test(localName) && node.hasAttribute('href')) {\n const attrURL = new URL(node.getAttribute('href'), docURL.href);\n if (attrURL.origin === docURL.origin &&\n attrURL.pathname === docURL.pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n if (node.id && docURL.hash && docURL.hash === `#${node.id}` &&\n document.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n if (docURL.hash) {\n const hash = docURL.hash.replace(/^#/, '');\n let current = document.getElementById(hash);\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n }\n break;\n }\n case 'scope': {\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (node === this.#node) {\n matched.add(node);\n }\n } else if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === document.activeElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (regInteract.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (regInteract.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (regFormCtrl.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parentNode.localName !== 'legend' &&\n parent.hasAttribute('disabled')) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((regFormCtrl.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (regTypeText.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '' &&\n node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length) {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = documentElement;\n }\n const nodes = [].slice.call(parent.getElementsByTagName('input'));\n let checked;\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n const regTypeReset = /^(?:button|reset)$/;\n const regTypeSubmit = /^(?:image|submit)$/;\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n regTypeReset.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n regTypeSubmit.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const iterator = document.createNodeIterator(form, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n const nodeName = nextNode.localName;\n let m;\n if (nodeName === 'button') {\n m = !(nextNode.hasAttribute('type') &&\n regTypeReset.test(nextNode.getAttribute('type')));\n } else if (nodeName === 'input') {\n m = nextNode.hasAttribute('type') &&\n regTypeSubmit.test(nextNode.getAttribute('type'));\n }\n if (m) {\n if (nextNode === node) {\n matched.add(node);\n }\n break;\n }\n nextNode = iterator.nextNode();\n }\n }\n // input[type=\"checkbox\"], input[type=\"radio\"]\n } else if (localName === 'input' && node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type')) &&\n (node.checked || node.hasAttribute('checked'))) {\n matched.add(node);\n // option\n } else if (localName === 'option') {\n let isMultiple = false;\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'datalist') {\n break;\n } else if (parent.localName === 'select') {\n if (parent.multiple || parent.hasAttribute('multiple')) {\n isMultiple = true;\n }\n break;\n }\n parent = parent.parentNode;\n }\n if (isMultiple) {\n if (node.selected || node.hasAttribute('selected')) {\n matched.add(node);\n }\n } else {\n const firstOpt = parentNode.firstElementChild;\n const defaultOpt = new Set();\n let opt = firstOpt;\n while (opt) {\n if (opt.selected || opt.hasAttribute('selected')) {\n defaultOpt.add(opt);\n break;\n }\n opt = opt.nextElementSibling;\n }\n if (!defaultOpt.size) {\n defaultOpt.add(firstOpt);\n }\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'valid': {\n if (regFormValidity.test(localName)) {\n if (node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'invalid': {\n if (regFormValidity.test(localName)) {\n if (!node.checkValidity()) {\n matched.add(node);\n }\n } else if (localName === 'fieldset') {\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n let bool;\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = iterator.nextNode();\n }\n if (!bool) {\n matched.add(node);\n }\n }\n break;\n }\n case 'in-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n regTypeRange.test(node.getAttribute('type')) &&\n !(node.validity.rangeUnderflow ||\n node.validity.rangeOverflow) &&\n (node.hasAttribute('min') || node.hasAttribute('max') ||\n node.getAttribute('type') === 'range')) {\n matched.add(node);\n }\n break;\n }\n case 'out-of-range': {\n if (localName === 'input' &&\n !(node.readonly || node.hasAttribute('readonly')) &&\n !(node.disabled || node.hasAttribute('disabled')) &&\n node.hasAttribute('type') &&\n regTypeRange.test(node.getAttribute('type')) &&\n (node.validity.rangeUnderflow || node.validity.rangeOverflow)) {\n matched.add(node);\n }\n break;\n }\n case 'required': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n (node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'optional': {\n let targetNode;\n if (/^(?:select|textarea)$/.test(localName)) {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n const inputType = node.getAttribute('type');\n if (inputType === 'file' || regTypeCheck.test(inputType) ||\n regTypeDate.test(inputType) || regTypeText.test(inputType)) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode &&\n !(node.required || node.hasAttribute('required'))) {\n matched.add(node);\n }\n break;\n }\n case 'root': {\n if (node === documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n const nodes = node.childNodes.values();\n let bool;\n for (const refNode of nodes) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n break;\n }\n case 'first-child': {\n if ((parentNode && node === parentNode.firstElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (node === root && root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === root && root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'focus-visible':\n case 'fullscreen':\n case 'future':\n case 'hover':\n case 'modal':\n case 'muted':\n case 'past':\n case 'paused':\n case 'picture-in-picture':\n case 'playing':\n case 'seeking':\n case 'stalled':\n case 'user-invalid':\n case 'user-valid':\n case 'volume-locked':\n case '-webkit-autofill': {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (this.#warn) {\n throw new DOMException(`Unsupported pseudo-class :${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-class :${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const { document } = this.#root;\n let caseInsensitive;\n if (document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { id } = node;\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { forgive } = opt;\n const { document } = this.#root;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix) {\n if (isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (!forgive) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n } else if (astPrefix && !forgive && !isNamespaceDeclared(astPrefix, node)) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`, SYNTAX_ERR);\n }\n return res ?? null;\n };\n\n /**\n * match shadow host pseudo class\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren } = ast;\n const astName = unescapeSelector(ast.name);\n let res;\n if (Array.isArray(astChildren)) {\n const [branch] = walkAST(astChildren[0]);\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, host).has(host);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n } else if (astName === 'host-context') {\n let parent = host;\n let bool;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n bool = this._matchSelector(leaf, parent).has(parent);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n break;\n } else {\n parent = parent.parentNode;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else if (astName === 'host') {\n res = node;\n } else {\n throw new DOMException(`Invalid selector :${astName}`, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n const { shadow } = this.#root;\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_ATTR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_CLASS: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_ID: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n const res = this._matchTypeSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (shadow && astType === SELECTOR_PSEUDO_CLASS &&\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n if (astName !== 'has' && REG_LOGICAL_PSEUDO.test(astName)) {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (REG_SHADOW_HOST.test(astName)) {\n const res = this._matchShadowHostPseudoClass(ast, node);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} [opt] - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...items] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n if (shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_ID: {\n if (root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const arr = [].slice.call(baseNode.getElementsByClassName(leafName));\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (document.contentType === 'text/html' && !/[*|]/.test(leafName)) {\n const arr = [].slice.call(baseNode.getElementsByTagName(leafName));\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.find] - 'prev'|'next', which nodes to find\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { find, forgive } = opt;\n let matched = new Set();\n if (find === FIND_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n let refNode = node.nextElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = refNode.nextElementSibling;\n }\n break;\n }\n case '>': {\n const childNodes = [].slice.call(node.children);\n for (const refNode of childNodes) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const { nodes, pending } = this._findDescendantNodes(leaves, node);\n if (nodes.size) {\n matched = nodes;\n } else if (pending) {\n const { document } = this.#root;\n const iterator = document.createNodeIterator(node, SHOW_ELEMENT);\n let refNode = iterator.nextNode();\n if (refNode === node) {\n refNode = iterator.nextNode();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n refNode = iterator.nextNode();\n }\n }\n }\n }\n } else {\n switch (comboName) {\n case '+': {\n const refNode = node.previousElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const arr = [];\n let refNode = node.previousElementSibling;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.previousElementSibling;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - collection of nodes and pending state\n */\n _findNodes(twig, targetType) {\n const { leaves: [leaf, ...items] } = twig;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const matchItems = items.length > 0;\n const { document, root, shadow } = this.#root;\n let nodes = new Set();\n let pending = false;\n switch (leafType) {\n case SELECTOR_ID: {\n let node;\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n node = this.#node;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n node = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n } else if (targetType === TARGET_ALL ||\n root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n node = root.getElementById(leafName);\n }\n if (node) {\n if (matchItems) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const childNodes = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.classList.contains(leafName)) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByClassName(leafName));\n arr.push(...a);\n }\n } else {\n const a = [].slice.call(root.getElementsByClassName(leafName));\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (const node of a) {\n if (node === this.#node || isInclusive(node, this.#node)) {\n arr.push(node);\n }\n }\n } else {\n arr = a;\n }\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n let arr = [];\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (document.contentType !== 'text/html' ||\n /[*|]/.test(leafName)) {\n pending = true;\n } else if (root.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const tagName = leafName.toLowerCase();\n const childNodes = [].slice.call(root.children);\n for (const node of childNodes) {\n if (node.localName === tagName) {\n arr.push(node);\n }\n const a = [].slice.call(node.getElementsByTagName(leafName));\n arr.push(...a);\n }\n } else {\n const a = [].slice.call(root.getElementsByTagName(leafName));\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (const node of a) {\n if (node === this.#node || isInclusive(node, this.#node)) {\n arr.push(node);\n }\n }\n } else {\n arr = a;\n }\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n // throws\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n const arr = [];\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (shadow && this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n arr.push(node);\n }\n }\n } else if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves([leaf], this.#node);\n if (bool) {\n arr.push(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n } else {\n pending = true;\n }\n if (arr.length) {\n if (matchItems) {\n for (const node of arr) {\n const bool = this._matchLeaves(items, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n }\n }\n if (matchItems && !pending && !nodes.size) {\n const lastLeaf = items[items.length - 1];\n const { type: lastLeafType } = lastLeaf;\n if (lastLeafType === SELECTOR_PSEUDO_CLASS) {\n let node;\n if (root.nodeType === ELEMENT_NODE) {\n node = root;\n } else {\n node = root.firstElementChild;\n }\n // throws if unknown pseudo-class\n this._matchPseudoClassSelector(lastLeaf, node);\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * get first twig\n * @param {Array.<object>} branch - AST branch\n * @returns {object} - find direction and twig\n */\n _getFirstTwig(branch) {\n const lastIndex = branch.length - 1;\n const firstTwig = branch[0];\n let find;\n let twig;\n if (lastIndex) {\n const lastTwig = branch[lastIndex];\n const { leaves: [{ type: lastType }] } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT || lastType === SELECTOR_ID) {\n find = FIND_PREV;\n twig = lastTwig;\n } else {\n find = FIND_NEXT;\n twig = firstTwig;\n }\n } else {\n find = FIND_PREV;\n twig = firstTwig;\n }\n return {\n find,\n twig\n };\n }\n\n /**\n * collect nodes\n * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const { find, twig } = this._getFirstTwig(branch);\n const { nodes, pending } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = find;\n i++;\n }\n if (pendingItems.size) {\n const { document, root } = this.#root;\n const iterator = document.createNodeIterator(root, SHOW_ELEMENT);\n let nextNode = iterator.nextNode();\n while (nextNode) {\n let bool = false;\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (nextNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(nextNode);\n }\n } else {\n bool = true;\n }\n if (bool) {\n for (const pendingItem of pendingItems) {\n const { leaves } = pendingItem.get('twig');\n const matched = this._matchLeaves(leaves, nextNode);\n if (matched) {\n const index = pendingItem.get('index');\n this.#nodes[index].add(nextNode);\n }\n }\n }\n nextNode = iterator.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const { nodes } = this._findNodes(twig, targetType);\n if (nodes.size) {\n this.#nodes[i] = nodes;\n } else {\n this.#ast[i].skip = true;\n }\n this.#ast[i].find = FIND_PREV;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\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 */\n _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\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, find, skip } = branches[i];\n const branchLen = branch.length;\n if (skip) {\n continue;\n } else if (branchLen) {\n const matched = this.#nodes[i];\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (const node of matched) {\n if (node !== this.#node && this.#node.contains(node)) {\n nodes.add(node);\n if (targetType === TARGET_FIRST) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(matched);\n nodes.add(node);\n } else {\n const n = [...nodes];\n const m = [...matched];\n nodes = new Set([...n, ...m]);\n }\n } else if (find === FIND_NEXT) {\n let { combo } = branch[0];\n for (const node of matched) {\n let nextNodes = new Set([node]);\n for (let j = 1; j < branchLen; j++) {\n const { combo: nextCombo, leaves } = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const twig = {\n combo,\n leaves\n };\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n if (targetType === TARGET_FIRST) {\n const [node] = this._sortNodes(arr);\n nodes.add(node);\n } else {\n const n = [...nodes];\n nodes = new Set([...n, ...arr]);\n }\n break;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\n }\n } else {\n break;\n }\n }\n }\n } else {\n for (const node of matched) {\n let nextNodes = new Set([node]);\n let bool;\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, { find });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n bool = true;\n if (j === 0) {\n nodes.add(node);\n break;\n } else {\n nextNodes = new Set(arr);\n }\n } else {\n bool = false;\n break;\n }\n }\n if (bool && targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType) {\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * matches\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_SELF);\n res = nodes.has(this.#node);\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @returns {?object} - matched node\n */\n closest() {\n if (this.#node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${this.#node.nodeName}`);\n }\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL);\n let node = this.#node;\n while (node) {\n if (nodes.has(node)) {\n res = node;\n break;\n }\n node = node.parentNode;\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @returns {?object} - matched node\n */\n querySelector() {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll() {\n let res;\n try {\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n res = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
|
|
5
|
+
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAEO,uBAGPC,EAMO,yBACP,MAAMC,EAAY,OACZC,EAAY,OACZC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OA8Bb,MAAMX,CAAQ,CAEnBY,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GASA,YAAYC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CACpC,KAAM,CAAE,KAAAC,CAAK,EAAID,EACjB,KAAKT,GAAO,IAAI,IAAI,CAClB,CAAC,0BAAyB,QAAM,EAChC,CAAC,cAAa,QAAM,EACpB,CAAC,iBAAgB,QAAM,EACvB,CAAC,gBAAe,QAA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,EAAM,KAAK,WAAWI,CAAK,EAE/B,OAAS,EAAG,CACV,KAAK,SAAS,CAAC,CACjB,CACA,OAAOJ,GAAO,CAAC,CACjB,CACF",
|
|
6
|
+
"names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "FIND_NEXT", "FIND_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#bit", "#cache", "#node", "#nodes", "#root", "#selector", "#warn", "selector", "node", "opt", "warn", "e", "document", "root", "parent", "shadow", "leaves", "arr", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "ast", "branches", "tree", "nodes", "i", "items", "branch", "item", "nextItem", "msg", "anb", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "branchesLen", "refNode", "bool", "current", "nth", "j", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "m", "astChildren", "selectors", "css", "leavesSet", "documentElement", "docURL", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "attrURL", "hash", "isCustomElementName", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "iterator", "isMultiple", "firstOpt", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "id", "astPrefix", "astNodeName", "nodePrefix", "host", "astType", "baseNode", "leafName", "matchItems", "pending", "comboName", "find", "childNodes", "targetType", "tagName", "lastLeaf", "lastLeafType", "firstTwig", "lastTwig", "lastType", "pendingItems", "pendingItem", "index", "skip", "branchLen", "n", "nextCombo"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
"c8": "^8.0.1",
|
|
35
35
|
"chai": "^4.3.10",
|
|
36
36
|
"commander": "^11.1.0",
|
|
37
|
-
"esbuild": "^0.19.
|
|
38
|
-
"eslint": "^8.
|
|
37
|
+
"esbuild": "^0.19.9",
|
|
38
|
+
"eslint": "^8.55.0",
|
|
39
39
|
"eslint-config-standard": "^17.1.0",
|
|
40
40
|
"eslint-plugin-import": "^2.29.0",
|
|
41
41
|
"eslint-plugin-jsdoc": "^46.9.0",
|
|
42
|
-
"eslint-plugin-regexp": "^2.1.
|
|
42
|
+
"eslint-plugin-regexp": "^2.1.2",
|
|
43
43
|
"eslint-plugin-unicorn": "^49.0.0",
|
|
44
44
|
"jsdom": "^23.0.1",
|
|
45
45
|
"mocha": "^10.2.0",
|
|
46
46
|
"npm-run-all": "^4.1.5",
|
|
47
47
|
"sinon": "^17.0.1",
|
|
48
|
-
"typescript": "^5.3.
|
|
48
|
+
"typescript": "^5.3.3",
|
|
49
49
|
"wpt-runner": "^5.0.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"update": "npm-run-all -s update-*",
|
|
62
62
|
"update-wpt": "git submodule update --init --recursive --remote"
|
|
63
63
|
},
|
|
64
|
-
"version": "1.1.
|
|
64
|
+
"version": "1.1.13"
|
|
65
65
|
}
|
package/src/js/dom-util.js
CHANGED
|
@@ -7,8 +7,9 @@ import bidiFactory from 'bidi-js';
|
|
|
7
7
|
|
|
8
8
|
/* constants */
|
|
9
9
|
import {
|
|
10
|
-
DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,
|
|
11
|
-
|
|
10
|
+
DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,
|
|
11
|
+
DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,
|
|
12
|
+
REG_SHADOW_MODE, SYNTAX_ERR, TEXT_NODE
|
|
12
13
|
} from './constant.js';
|
|
13
14
|
|
|
14
15
|
/* bidi */
|
|
@@ -70,20 +71,50 @@ export const getDirectionality = (node = {}) => {
|
|
|
70
71
|
let res;
|
|
71
72
|
if (node.nodeType === ELEMENT_NODE) {
|
|
72
73
|
const { dir: nodeDir, localName, parentNode } = node;
|
|
73
|
-
|
|
74
|
+
const regDir = /^(?:ltr|rtl)$/;
|
|
75
|
+
if (regDir.test(nodeDir)) {
|
|
74
76
|
res = nodeDir;
|
|
75
77
|
} else if (nodeDir === 'auto') {
|
|
76
78
|
let text;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
switch (localName) {
|
|
80
|
+
case 'input': {
|
|
81
|
+
if (!node.type || /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type)) {
|
|
82
|
+
text = node.value;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'slot': {
|
|
87
|
+
text = getSlottedTextContent(node);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 'textarea': {
|
|
91
|
+
text = node.value;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
default: {
|
|
95
|
+
const items = [].slice.call(node.childNodes);
|
|
96
|
+
for (const item of items) {
|
|
97
|
+
const {
|
|
98
|
+
dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,
|
|
99
|
+
textContent: itemTextContent
|
|
100
|
+
} = item;
|
|
101
|
+
if (itemNodeType === TEXT_NODE) {
|
|
102
|
+
text = itemTextContent.trim();
|
|
103
|
+
} else if (itemNodeType === ELEMENT_NODE) {
|
|
104
|
+
if (!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(itemLocalName) &&
|
|
105
|
+
(!itemDir || !regDir.test(itemDir))) {
|
|
106
|
+
if (itemLocalName === 'slot') {
|
|
107
|
+
text = getSlottedTextContent(item);
|
|
108
|
+
} else {
|
|
109
|
+
text = itemTextContent.trim();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (text) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
87
118
|
}
|
|
88
119
|
if (text) {
|
|
89
120
|
const { paragraphs: [{ level }] } = bidi.getEmbeddingLevels(text);
|
|
@@ -208,22 +239,33 @@ export const isNamespaceDeclared = (ns = '', node = {}) => {
|
|
|
208
239
|
};
|
|
209
240
|
|
|
210
241
|
/**
|
|
211
|
-
* is
|
|
212
|
-
* @param {object}
|
|
213
|
-
* @param {object}
|
|
242
|
+
* is inclusive - nodeA and nodeB are in inclusive relation
|
|
243
|
+
* @param {object} nodeA - Element node
|
|
244
|
+
* @param {object} nodeB - Element node
|
|
214
245
|
* @returns {boolean} - result
|
|
215
246
|
*/
|
|
216
|
-
export const
|
|
247
|
+
export const isInclusive = (nodeA = {}, nodeB = {}) => {
|
|
217
248
|
let res;
|
|
218
|
-
if (
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
249
|
+
if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {
|
|
250
|
+
const posBit = nodeB.compareDocumentPosition(nodeA);
|
|
251
|
+
res = posBit & DOCUMENT_POSITION_CONTAINS ||
|
|
252
|
+
posBit & DOCUMENT_POSITION_CONTAINED_BY;
|
|
253
|
+
}
|
|
254
|
+
return !!res;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* is preceding - nodeA precedes and/or contains nodeB
|
|
259
|
+
* @param {object} nodeA - Element node
|
|
260
|
+
* @param {object} nodeB - Element node
|
|
261
|
+
* @returns {boolean} - result
|
|
262
|
+
*/
|
|
263
|
+
export const isPreceding = (nodeA = {}, nodeB = {}) => {
|
|
264
|
+
let res;
|
|
265
|
+
if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {
|
|
266
|
+
const posBit = nodeB.compareDocumentPosition(nodeA);
|
|
267
|
+
res = posBit & DOCUMENT_POSITION_PRECEDING ||
|
|
268
|
+
posBit & DOCUMENT_POSITION_CONTAINS;
|
|
227
269
|
}
|
|
228
270
|
return !!res;
|
|
229
271
|
};
|
package/src/js/matcher.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/* import */
|
|
6
6
|
import isCustomElementName from 'is-potential-custom-element-name';
|
|
7
7
|
import {
|
|
8
|
-
getDirectionality, isContentEditable,
|
|
9
|
-
|
|
8
|
+
getDirectionality, isContentEditable, isInclusive, isInShadowTree,
|
|
9
|
+
isNamespaceDeclared, isPreceding, selectorToNodeProps
|
|
10
10
|
} from './dom-util.js';
|
|
11
11
|
import {
|
|
12
12
|
generateCSS, parseSelector, unescapeSelector, walkAST
|
|
@@ -15,8 +15,7 @@ import {
|
|
|
15
15
|
/* constants */
|
|
16
16
|
import {
|
|
17
17
|
ALPHA_NUM, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, COMBINATOR,
|
|
18
|
-
DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE,
|
|
19
|
-
DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, NOT_SUPPORTED_ERR,
|
|
18
|
+
DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, NOT_SUPPORTED_ERR,
|
|
20
19
|
REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_ATTR, SELECTOR_CLASS,
|
|
21
20
|
SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,
|
|
22
21
|
SHOW_ELEMENT, SYNTAX_ERR, TEXT_NODE
|
|
@@ -128,7 +127,7 @@ export class Matcher {
|
|
|
128
127
|
break;
|
|
129
128
|
}
|
|
130
129
|
case ELEMENT_NODE: {
|
|
131
|
-
if (
|
|
130
|
+
if (node.ownerDocument.contains(node)) {
|
|
132
131
|
document = node.ownerDocument;
|
|
133
132
|
root = node.ownerDocument;
|
|
134
133
|
} else {
|
|
@@ -886,6 +885,11 @@ export class Matcher {
|
|
|
886
885
|
}
|
|
887
886
|
break;
|
|
888
887
|
}
|
|
888
|
+
case 'host':
|
|
889
|
+
case 'host-context': {
|
|
890
|
+
// ignore
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
889
893
|
default: {
|
|
890
894
|
if (!forgive) {
|
|
891
895
|
throw new DOMException(`Unknown pseudo-class :${astName}()`,
|
|
@@ -933,7 +937,7 @@ export class Matcher {
|
|
|
933
937
|
}
|
|
934
938
|
case 'target': {
|
|
935
939
|
if (node.id && docURL.hash && docURL.hash === `#${node.id}` &&
|
|
936
|
-
|
|
940
|
+
document.contains(node)) {
|
|
937
941
|
matched.add(node);
|
|
938
942
|
}
|
|
939
943
|
break;
|
|
@@ -1443,7 +1447,7 @@ export class Matcher {
|
|
|
1443
1447
|
}
|
|
1444
1448
|
case 'host':
|
|
1445
1449
|
case 'host-context': {
|
|
1446
|
-
//
|
|
1450
|
+
// ignore
|
|
1447
1451
|
break;
|
|
1448
1452
|
}
|
|
1449
1453
|
// legacy pseudo-elements
|
|
@@ -1960,22 +1964,15 @@ export class Matcher {
|
|
|
1960
1964
|
if (root.nodeType === ELEMENT_NODE) {
|
|
1961
1965
|
pending = true;
|
|
1962
1966
|
} else {
|
|
1963
|
-
const
|
|
1964
|
-
if (
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
node = elm;
|
|
1969
|
-
}
|
|
1970
|
-
if (node) {
|
|
1971
|
-
if (matchItems) {
|
|
1972
|
-
const bool = this._matchLeaves(items, node);
|
|
1973
|
-
if (bool) {
|
|
1974
|
-
nodes.add(node);
|
|
1975
|
-
}
|
|
1976
|
-
} else {
|
|
1967
|
+
const node = root.getElementById(leafName);
|
|
1968
|
+
if (node && node !== baseNode && baseNode.contains(node)) {
|
|
1969
|
+
if (matchItems) {
|
|
1970
|
+
const bool = this._matchLeaves(items, node);
|
|
1971
|
+
if (bool) {
|
|
1977
1972
|
nodes.add(node);
|
|
1978
1973
|
}
|
|
1974
|
+
} else {
|
|
1975
|
+
nodes.add(node);
|
|
1979
1976
|
}
|
|
1980
1977
|
}
|
|
1981
1978
|
}
|
|
@@ -2237,7 +2234,16 @@ export class Matcher {
|
|
|
2237
2234
|
arr.push(...a);
|
|
2238
2235
|
}
|
|
2239
2236
|
} else {
|
|
2240
|
-
|
|
2237
|
+
const a = [].slice.call(root.getElementsByClassName(leafName));
|
|
2238
|
+
if (this.#node.nodeType === ELEMENT_NODE) {
|
|
2239
|
+
for (const node of a) {
|
|
2240
|
+
if (node === this.#node || isInclusive(node, this.#node)) {
|
|
2241
|
+
arr.push(node);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
} else {
|
|
2245
|
+
arr = a;
|
|
2246
|
+
}
|
|
2241
2247
|
}
|
|
2242
2248
|
if (arr.length) {
|
|
2243
2249
|
if (matchItems) {
|
|
@@ -2289,7 +2295,16 @@ export class Matcher {
|
|
|
2289
2295
|
arr.push(...a);
|
|
2290
2296
|
}
|
|
2291
2297
|
} else {
|
|
2292
|
-
|
|
2298
|
+
const a = [].slice.call(root.getElementsByTagName(leafName));
|
|
2299
|
+
if (this.#node.nodeType === ELEMENT_NODE) {
|
|
2300
|
+
for (const node of a) {
|
|
2301
|
+
if (node === this.#node || isInclusive(node, this.#node)) {
|
|
2302
|
+
arr.push(node);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
} else {
|
|
2306
|
+
arr = a;
|
|
2307
|
+
}
|
|
2293
2308
|
}
|
|
2294
2309
|
if (arr.length) {
|
|
2295
2310
|
if (matchItems) {
|
|
@@ -2433,7 +2448,11 @@ export class Matcher {
|
|
|
2433
2448
|
while (nextNode) {
|
|
2434
2449
|
let bool = false;
|
|
2435
2450
|
if (this.#node.nodeType === ELEMENT_NODE) {
|
|
2436
|
-
|
|
2451
|
+
if (nextNode === this.#node) {
|
|
2452
|
+
bool = true;
|
|
2453
|
+
} else {
|
|
2454
|
+
bool = this.#node.contains(nextNode);
|
|
2455
|
+
}
|
|
2437
2456
|
} else {
|
|
2438
2457
|
bool = true;
|
|
2439
2458
|
}
|
|
@@ -2479,10 +2498,8 @@ export class Matcher {
|
|
|
2479
2498
|
const arr = [...nodes];
|
|
2480
2499
|
if (arr.length > 1) {
|
|
2481
2500
|
arr.sort((a, b) => {
|
|
2482
|
-
const posBit = a.compareDocumentPosition(b);
|
|
2483
2501
|
let res;
|
|
2484
|
-
if (
|
|
2485
|
-
posBit & DOCUMENT_POSITION_CONTAINS) {
|
|
2502
|
+
if (isPreceding(b, a)) {
|
|
2486
2503
|
res = 1;
|
|
2487
2504
|
} else {
|
|
2488
2505
|
res = -1;
|
|
@@ -2514,12 +2531,10 @@ export class Matcher {
|
|
|
2514
2531
|
if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&
|
|
2515
2532
|
this.#node.nodeType === ELEMENT_NODE) {
|
|
2516
2533
|
for (const node of matched) {
|
|
2517
|
-
if (node !== this.#node) {
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
break;
|
|
2522
|
-
}
|
|
2534
|
+
if (node !== this.#node && this.#node.contains(node)) {
|
|
2535
|
+
nodes.add(node);
|
|
2536
|
+
if (targetType === TARGET_FIRST) {
|
|
2537
|
+
break;
|
|
2523
2538
|
}
|
|
2524
2539
|
}
|
|
2525
2540
|
}
|
package/types/js/dom-util.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export function getSlottedTextContent(node?: object): string | null;
|
|
|
3
3
|
export function getDirectionality(node?: object): string | null;
|
|
4
4
|
export function isContentEditable(node?: object): boolean;
|
|
5
5
|
export function isNamespaceDeclared(ns?: string, node?: object): boolean;
|
|
6
|
-
export function
|
|
6
|
+
export function isInclusive(nodeA?: object, nodeB?: object): boolean;
|
|
7
|
+
export function isPreceding(nodeA?: object, nodeB?: object): boolean;
|
|
7
8
|
export function selectorToNodeProps(selector: string, node?: object): object;
|